Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fmpz_is_square #172

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ CHANGELOG

Next release:

- [gh-172](https://github.com/flintlib/python-flint/pull/161)
Add `fmpz_is_square`.
- [gh-161](https://github.com/flintlib/python-flint/pull/161)
Add `acb.lerch_phi` to compute the Lerch transcendent.
- [gh-132](https://github.com/flintlib/python-flint/pull/132)
Expand All @@ -146,7 +148,7 @@ Next release:
- [gh-148](https://github.com/flintlib/python-flint/pull/148)
Remove debug symbols to make smaller Linux binaries.
- [gh-144](https://github.com/flintlib/python-flint/pull/144)
Add `rel_one_ccuracy_bits` to `arb` and `acb`.
Add `rel_one_accuracy_bits` to `arb` and `acb`.
- [gh-142](https://github.com/flintlib/python-flint/pull/142)
Add `acb_theta` module for the numerical evaluation of [theta
functions](https://flintlib.org/doc/acb_theta.html) (only available for
Expand Down
2 changes: 2 additions & 0 deletions src/flint/test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ def test_fmpz_functions():
[0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0]),
(lambda n: flint.fmpz(n).is_perfect_power(),
[T, T, T, F, F, T, F, F, F, T, T, F]),
(lambda n: flint.fmpz(n).is_square(),
[F, T, T, F, F, T, F, F, F, F, T, F]),
(lambda n: flint.fmpz(n).partitions_p(),
[0, 1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42]),
(lambda n: flint.fmpz(n).moebius_mu(),
Expand Down
20 changes: 20 additions & 0 deletions src/flint/types/fmpz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -683,11 +683,31 @@ cdef class fmpz(flint_scalar):
return fmpz_is_probabprime(self.val)

def is_perfect_power(self):
r"""
Return True if this integer is of the form `r^k` with `k>1`, False otherwise.
`0, 1, -1` are considered perfect powers.

>>> fmpz(81).is_perfect_power()
True
>>> fmpz(1234).is_perfect_power()
False
"""
cdef int k
cdef fmpz v = fmpz()
k = fmpz_is_perfect_power(v.val, self.val)
return k != 0

def is_square(self):
r"""
Return True if perfect square and False otherwise.

>>> fmpz(25).is_square()
True
>>> fmpz(101).is_square()
False
"""
return fmpz_is_square(self.val) != 0

def partitions_p(n):
r"""
Returns `p(n)`, the number of partitions of `n`, as an *fmpz*.
Expand Down
Loading