Hello Dear all

I tried understand :

import math
n=115792089237316195423570985008687907852837564279074904382605163141518161494337
d= math.sqrt(n)
print(d)
print(d==2**128)
print(d*d==n)
u=d*d
print(u)
print(n-u)


result: how it is possibility that sqrt(n) *sqrt(n) is equal n if it is not?:)

edit retag close merge delete

Sort by » oldest newest most voted

Your n is not the square of 2^128:

sage: n=115792089237316195423570985008687907852837564279074904382605163141518161494337
sage: (2^128)^2 - n
432420386565659656852420866394968145599


But, if you use float, then the precision of floats (53 bits of precision) is not enough to see a difference:

sage: float((2^128)^2) - float(n)
0.0


So, don't use float and don't use math.sqrt which returns float to compute such equalities or differences:

sage: type(math.sqrt(n))
<class 'float'>

more

so how to take sqrt from n?

( 2021-07-12 14:11:23 +0200 )edit

sqrt(n) or sqrt(n).numerical_approx() or its shorcut sqrt(n).n() or sqrt(n).n(digits=10000) for more precision

( 2021-07-12 15:25:33 +0200 )edit

o thank you

( 2021-07-12 16:12:14 +0200 )edit