From fd08ee94a34e0a54eeb106b030fad874e2de276c Mon Sep 17 00:00:00 2001 From: roos-j Date: Sun, 28 Jul 2024 20:44:51 -0400 Subject: [PATCH 1/6] add is_square --- src/flint/types/fmpz.pyx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/flint/types/fmpz.pyx b/src/flint/types/fmpz.pyx index 4f01eb80..352f119f 100644 --- a/src/flint/types/fmpz.pyx +++ b/src/flint/types/fmpz.pyx @@ -688,6 +688,17 @@ cdef class fmpz(flint_scalar): 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*. From 228f0af19ab0f3f3fbbb5a528b6a64ffce731397 Mon Sep 17 00:00:00 2001 From: roos-j Date: Sun, 28 Jul 2024 20:45:26 -0400 Subject: [PATCH 2/6] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d4cbc3a7..31ffd843 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,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 From d1a87580857ce37053997c9bd068c47dd0afd4a2 Mon Sep 17 00:00:00 2001 From: roos-j Date: Sun, 28 Jul 2024 20:48:11 -0400 Subject: [PATCH 3/6] add gh-172 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 31ffd843..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) From c42fa0a68a5dfc85d82149b7aec27145db5e131f Mon Sep 17 00:00:00 2001 From: roos-j Date: Sun, 28 Jul 2024 20:57:57 -0400 Subject: [PATCH 4/6] add docstring for is_perfect_power --- src/flint/types/fmpz.pyx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/flint/types/fmpz.pyx b/src/flint/types/fmpz.pyx index 352f119f..43c628f7 100644 --- a/src/flint/types/fmpz.pyx +++ b/src/flint/types/fmpz.pyx @@ -683,6 +683,14 @@ 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`, False otherwise. + + >>> 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) From c2f873dc57633abeac84b0066cb0626ad84226db Mon Sep 17 00:00:00 2001 From: roos-j Date: Mon, 29 Jul 2024 07:21:30 -0400 Subject: [PATCH 5/6] update docstring --- src/flint/types/fmpz.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/flint/types/fmpz.pyx b/src/flint/types/fmpz.pyx index 43c628f7..0b163750 100644 --- a/src/flint/types/fmpz.pyx +++ b/src/flint/types/fmpz.pyx @@ -684,7 +684,8 @@ cdef class fmpz(flint_scalar): def is_perfect_power(self): r""" - Return True if this integer is of the form `r^k`, False otherwise. + 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 From dfc20da41b93091292711d2508346b4afb66c2e3 Mon Sep 17 00:00:00 2001 From: roos-j Date: Mon, 29 Jul 2024 08:21:26 -0400 Subject: [PATCH 6/6] test is_square --- src/flint/test/test_all.py | 2 ++ 1 file changed, 2 insertions(+) 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(),