FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

add fmpz_is_square by roos-j · Pull Request #172 · flintlib/python-flint · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (1) .py  (1) .pyx  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 3 additions & 1 deletion README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL