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
is_square gives incorrect answers #17044
Comments
I see perfect power does not give False even if the candidates are given.
|
or return integer_nthroot( n, 2 )[1] |
|
You have a very good point. I ran a test of three different solutions, and which is the fastest depends on the size of n. In place of "if perfect_power(n, [2]): return True" in the current version Solution a: if perfect_power(n, [2], factor=False): return True Offset 1 Offset 2^100 Offset 2^10000 Offset 2^1000000 (done with a smaller sample size) Of course very large n would probably benefit significantly from trailing(n) as "if 1 == trailing(n)%2: return False" and tests involving largeMod as posted earlier. Here is the program I used for timing.
|
from sympy.ntheory.primetest import is_square
from math import sqrt
print( 216000, "is square:", is_square( 216000 ) )
print( "sqrt( 216000 ) is:", sqrt( 216000 ))
related:
from sympy.ntheory import perfect_power
print( perfect_power( 216000, [2] ))
print( perfect_power( 216000, [2], factor = False ))
The text was updated successfully, but these errors were encountered: