Handling big numbers?

Messages in english

Modérateur : xcasadmin

niccolo
Messages : 26
Inscription : dim. mars 02, 2014 2:13 pm

Handling big numbers?

Message par niccolo » jeu. oct. 27, 2022 11:17 am

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?

niccolo
Messages : 26
Inscription : dim. mars 02, 2014 2:13 pm

Re: Handling big numbers?

Message par niccolo » 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.)

frederic han
Messages : 1137
Inscription : dim. mai 20, 2007 7:09 am
Localisation : Paris
Contact :

Re: Handling big numbers?

Message par frederic han » ven. oct. 28, 2022 1:02 pm

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

belanger
Messages : 59
Inscription : jeu. juil. 27, 2017 3:26 pm

Re: Handling big numbers?

Message par belanger » ven. oct. 28, 2022 7:26 pm

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)

parisse
Messages : 5743
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: Handling big numbers?

Message par parisse » dim. oct. 30, 2022 6:58 am

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

niccolo
Messages : 26
Inscription : dim. mars 02, 2014 2:13 pm

Re: Handling big numbers?

Message par niccolo » lun. oct. 31, 2022 10:29 am

Thank you all!

Répondre