From 94b7d4a477223d5a7a461363044d2d3bc62cb50d Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Sat, 31 Aug 2024 00:26:25 +0700 Subject: [PATCH 1/2] Add is_integral method to algebraic numbers --- src/sage/rings/qqbar.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index 5d2f2ca2216..a02d921ecb1 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -4485,6 +4485,26 @@ def as_number_field_element(self, minimal=False, embedded=False, prec=53): """ return number_field_elements_from_algebraics(self, minimal=minimal, embedded=embedded, prec=prec) + def is_integral(self): + r""" + Determine if a number is an algebraic integer. + + EXAMPLES:: + + sage: QQbar(sqrt(-23)).is_integral() + True + sage: AA(sqrt(23/2)).is_integral() + False + + TESTS: + + Method should return the same value as :meth:`NumberFieldElement.is_integral`:: + + sage: for a in [QQbar(2^(1/3)), AA(2^(1/3)), QQbar(sqrt(1/2)), AA(1/2), AA(2), QQbar(1/2)]: + ....: assert a.as_number_field_element()[1].is_integral() == a.is_integral() + """ + return all(a in ZZ for a in self.minpoly()) + def exactify(self): """ Compute an exact representation for this number. From 480bd938770a58f7287880c34798a74c9e7d4765 Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:15:15 +0700 Subject: [PATCH 2/2] Apply suggested change --- src/sage/rings/qqbar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index a02d921ecb1..074cf983b27 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -4487,7 +4487,7 @@ def as_number_field_element(self, minimal=False, embedded=False, prec=53): def is_integral(self): r""" - Determine if a number is an algebraic integer. + Check if this number is an algebraic integer. EXAMPLES::