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?
Handling big numbers?
Modérateur : xcasadmin
Re: Handling big numbers?
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 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.)
-
- Messages : 1137
- Inscription : dim. mai 20, 2007 7:09 am
- Localisation : Paris
- Contact :
Re: Handling big numbers?
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?
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?
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
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?
Thank you all!