-
Notifications
You must be signed in to change notification settings - Fork 35
add fmpz_is_square #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add fmpz_is_square #172
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -683,11 +683,30 @@ 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) | ||
| return k != 0 | ||
|
Comment on lines
685
to
698
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can have both methods but more useful than In [1]: perfect_power(81)
Out[1]: (3, 4)
In [2]: perfect_power(80)
Out[2]: FalseI'm not sure what is best to return if it is not a perfect power. Returning False is perhaps a bit strange... Alternatives:
Maybe returning
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or perhaps it can just be: >>> perfect_power(80)
(80, 1)So >>> perfect_power(1)
(1, 1)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I missed the fact that the function was already there. I guess it is better not to change it then. We could add a separate
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that would be good. The issue is though that
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, okay. I suppose we could just call Maybe returning a result with non-maximal This seems like the sort of situation where what is best in python-flint might be a bit different from what Flint itself does. I'm not sure what the performance implications would be though of calling |
||
|
|
||
| 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*. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.