Skip to content

Commit

Permalink
Merge pull request flintlib#172 from roos-j/fmpz_is_square
Browse files Browse the repository at this point in the history
add fmpz_is_square
  • Loading branch information
oscarbenjamin authored Jul 29, 2024
2 parents 591f900 + dfc20da commit 2d6a526
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
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

0 comments on commit 2d6a526

Please sign in to comment.