Page 1 sur 1

Handling big numbers?

Publié : jeu. oct. 27, 2022 11:17 am
par niccolo
If I calculate the fourth root of 142241757136172119140621, I wrongly get the impression it's integer, because

approx( 142241757136172119140621**(1/4) )

gives me "614125.0".

When I calculate this in WolframAlpha, I get a more exact result ("614124.9999999999999999956825266197....").

Ok, I get it that floats aren't represented accurately in the computer, but I'd like to get more info:

(1) is xcas using the native computer's representation of a float?
(2) is there any free software that uses a more accurate representation?

Re: Handling big numbers?

Publié : ven. oct. 28, 2022 2:44 am
par niccolo
Another question:

I want to know if the square root (or, if possible, any n'th root) of a large integer is an integer, how do I do this?

(in other words, I'm not interested in the root itself, only in knowing whether it's integer.)

Re: Handling big numbers?

Publié : ven. oct. 28, 2022 1:02 pm
par frederic han
Xcas is using multiprecision, so you can just add more digits with approx:

Code : Tout sélectionner

0>> approx(142241757136172119140621**(1/4),100)
0.6141249999999999999999956825266197177211437726331508510678082924170094825905327701786189803105782071e6

Re: Handling big numbers?

Publié : ven. oct. 28, 2022 7:26 pm
par belanger
niccolo a écrit :
ven. oct. 28, 2022 2:44 am
Another question:

I want to know if the square root (or, if possible, any n'th root) of a large integer is an integer, how do I do this?

(in other words, I'm not interested in the root itself, only in knowing whether it's integer.)
I'm sure there's a good reason this isn't a good solution, but the first thing that occured to me was

isintegerroot(x,n):=(floor(x^(1/n))^n - x==0)

Re: Handling big numbers?

Publié : dim. oct. 30, 2022 6:58 am
par parisse
This is a good idea, but it will probably not work for very large integers for accuracy reasons. You need to control the number of digits for approx root extraction and take care of numbers rounded just below an integer. For example
N:=142241757136172119140621; n:=4;
d:=floor(log10(evalf(N,30)))+5; // add a few guard digits
r:=floor(evalf(N^(1/n),d));
r^n==N or (r+1)^n==N; // final check

Re: Handling big numbers?

Publié : lun. oct. 31, 2022 10:29 am
par niccolo
Thank you all!