Ask Your Question

jbeatz's profile - activity

2019-09-20 11:42:17 +0100 received badge  Famous Question (source)
2018-03-14 17:35:25 +0100 received badge  Popular Question (source)
2018-03-14 17:35:25 +0100 received badge  Notable Question (source)
2016-08-11 12:49:58 +0100 commented answer Testing if a result n is an Integer, for large n.

I am working on SageMath Online for the purposes of this demonstration n = 2^160 n1 = (2^ 160) +0.5

print n in ZZ print n1 in ZZ

True True

When clearly the second case shouldn't be! Looks like it can be fixed by changing 0.5 to 1/2 etc..

2016-08-11 12:48:23 +0100 commented answer Testing if a result n is an Integer, for large n.

Yup looks like this fixes the problem! Thank you!

2016-08-10 14:47:08 +0100 received badge  Student (source)
2016-08-10 14:43:43 +0100 asked a question Testing if a result n is an Integer, for large n.

I have a number x of size 2^160, and I perform the operation n = x*(x+1.5) and want to test if the result is an integer.

In python I would normally try, n.is_integer() or use an isinstance(), but this doesn't work in sage, I assume due to the fact sage integers are set up quite differently.

Upon scouring this site, I found someone recommend n is in ZZ, but this doesn't work (sage seems to loose accuracy at this level) Example:

n = 2^160

n in ZZ

Result: False

The only (terribly inefficient) way I can get this to work is to call n.divisors() and if I get the error "AttributeError: 'sage.rings.real_mpfr.RealNumber' object has no attribute 'divisors' " I know it was indeed not an integer.

There must be a better way?