Skip to content

Commit

Permalink
sagemathgh-38592: Add is_integral method to algebraic numbers
Browse files Browse the repository at this point in the history
    
For symmetry with existing methods e.g. `QQ(1).is_integral` or such
method on elements of number fields.

Implementation pretty much copied from `NumberFieldElement`.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.
    
URL: sagemath#38592
Reported by: user202729
Reviewer(s): Kwankyu Lee, user202729
  • Loading branch information
Release Manager committed Sep 8, 2024
2 parents 15a293f + 480bd93 commit fb47750
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/sage/rings/qqbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Check if this 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.
Expand Down

0 comments on commit fb47750

Please sign in to comment.