Skip to content

Commit 2d6a526

Browse files
Merge pull request #172 from roos-j/fmpz_is_square
add fmpz_is_square
2 parents 591f900 + dfc20da commit 2d6a526

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ CHANGELOG
133133

134134
Next release:
135135

136+
- [gh-172](https://github.com/flintlib/python-flint/pull/161)
137+
Add `fmpz_is_square`.
136138
- [gh-161](https://github.com/flintlib/python-flint/pull/161)
137139
Add `acb.lerch_phi` to compute the Lerch transcendent.
138140
- [gh-132](https://github.com/flintlib/python-flint/pull/132)
@@ -146,7 +148,7 @@ Next release:
146148
- [gh-148](https://github.com/flintlib/python-flint/pull/148)
147149
Remove debug symbols to make smaller Linux binaries.
148150
- [gh-144](https://github.com/flintlib/python-flint/pull/144)
149-
Add `rel_one_ccuracy_bits` to `arb` and `acb`.
151+
Add `rel_one_accuracy_bits` to `arb` and `acb`.
150152
- [gh-142](https://github.com/flintlib/python-flint/pull/142)
151153
Add `acb_theta` module for the numerical evaluation of [theta
152154
functions](https://flintlib.org/doc/acb_theta.html) (only available for

src/flint/test/test_all.py

+2
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ def test_fmpz_functions():
294294
[0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0]),
295295
(lambda n: flint.fmpz(n).is_perfect_power(),
296296
[T, T, T, F, F, T, F, F, F, T, T, F]),
297+
(lambda n: flint.fmpz(n).is_square(),
298+
[F, T, T, F, F, T, F, F, F, F, T, F]),
297299
(lambda n: flint.fmpz(n).partitions_p(),
298300
[0, 1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42]),
299301
(lambda n: flint.fmpz(n).moebius_mu(),

src/flint/types/fmpz.pyx

+20
Original file line numberDiff line numberDiff line change
@@ -683,11 +683,31 @@ cdef class fmpz(flint_scalar):
683683
return fmpz_is_probabprime(self.val)
684684

685685
def is_perfect_power(self):
686+
r"""
687+
Return True if this integer is of the form `r^k` with `k>1`, False otherwise.
688+
`0, 1, -1` are considered perfect powers.
689+
690+
>>> fmpz(81).is_perfect_power()
691+
True
692+
>>> fmpz(1234).is_perfect_power()
693+
False
694+
"""
686695
cdef int k
687696
cdef fmpz v = fmpz()
688697
k = fmpz_is_perfect_power(v.val, self.val)
689698
return k != 0
690699

700+
def is_square(self):
701+
r"""
702+
Return True if perfect square and False otherwise.
703+
704+
>>> fmpz(25).is_square()
705+
True
706+
>>> fmpz(101).is_square()
707+
False
708+
"""
709+
return fmpz_is_square(self.val) != 0
710+
691711
def partitions_p(n):
692712
r"""
693713
Returns `p(n)`, the number of partitions of `n`, as an *fmpz*.

0 commit comments

Comments
 (0)