diff --git a/README.md b/README.md index d4cbc3a7..31c229b3 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/src/flint/test/test_all.py b/src/flint/test/test_all.py index 2601dc9e..aca7668e 100644 --- a/src/flint/test/test_all.py +++ b/src/flint/test/test_all.py @@ -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(), diff --git a/src/flint/types/fmpz.pyx b/src/flint/types/fmpz.pyx index 4f01eb80..0b163750 100644 --- a/src/flint/types/fmpz.pyx +++ b/src/flint/types/fmpz.pyx @@ -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*.