Paul Smith
2006-Nov-23 18:46 UTC
[R] Ryacas and fractions with simultaenously very large numerators and denominators
Dear All I am doing the following:> x <- yacas("3/2") > for (i in 2:400)+ x <- yacas(paste(x,"*",x))> xexpression(Inf^1.260864167e+117/Inf^6.304320836e+116)> Eval(x)[1] NaN No luck this way. However, I am successful with> y <- yacas("(3/2)^400") > yexpression(7.05507910865533e+190/2.58224987808691e+120)> Eval(y)[1] 2.732144e+70 If Ryacas/Yacas cannot multiply fractions with simultaenously very large numerators and denominators, what else should I use? Thanks in advnace, Paul
Peter Dalgaard
2006-Nov-23 19:17 UTC
[R] Ryacas and fractions with simultaenously very large numerators and denominators
"Paul Smith" <phhs80 at gmail.com> writes:> Dear All > > I am doing the following: > > > x <- yacas("3/2") > > for (i in 2:400) > + x <- yacas(paste(x,"*",x)) > > x > expression(Inf^1.260864167e+117/Inf^6.304320836e+116) > > Eval(x) > [1] NaN > > No luck this way. However, I am successful with > > > y <- yacas("(3/2)^400") > > y > expression(7.05507910865533e+190/2.58224987808691e+120) > > Eval(y) > [1] 2.732144e+70 > > If Ryacas/Yacas cannot multiply fractions with simultaenously very > large numerators and denominators, what else should I use?I don't think they are the same: the latter example has 400 terms, the other about 2^400 terms.... -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Gabor Grothendieck
2006-Nov-23 19:23 UTC
[R] Ryacas and fractions with simultaenously very large numerators and denominators
There is likely some limitation in the Ryacas interface that needs to be addressed by the Ryacas developers. yacas itself can support very large numbers so just use yacas directly. Aside from that I, as mentioned previously in this thread, yacas returns a "yacas" object and that is a complex structure for which it makes no sense to try to use "paste". This works:> x <- Sym("3/2") > for(i in 2:5) x <- as.Sym(yacas(x*x)) > xexpression(43046721/65536) but quickly comes up against some limits in Ryacas (not in yacas) if you go past 5. This also works and is even easier but may quickly generate enormous strings that might overflow the interface:> x <- Sym("3/2") > for(i in 2:5) x <- x*x > dput(x)structure("( ( ( ( 3/2 * 3/2 ) * ( 3/2 * 3/2 ) ) * ( ( 3/2 * 3/2 ) * ( 3/2 * 3/2 ) ) ) * ( ( ( 3/2 * 3/2 ) * ( 3/2 * 3/2 ) ) * ( ( 3/2 * 3/2 ) * ( 3/2 * 3/2 ) ) ) )", class = c("Sym", "character"))> xexpression(43046721/65536) Using yacas directly: yacas ... In> x := 3/2 Out> 3/2 In> x := 3/2 Out> 3/2 In> x := x*x Out> 9/4 In> x := x*x Out> 81/16 In> x := x*x Out> 6561/256 In> x := x*x Out> 43046721/65536 In> x := x*x Out> 1853020188851841/4294967296 In> x := x*x Out> 3433683820292512484657849089281/18446744073709551616 In> x := x*x Out> 11790184577738583171520872861412518665678211592275841109096961/340282366920 938463463374607431768211456 In> x := x*x Out> 139008452377144732764939786789661303114218850808529137991604824430036072629 766435941001769154109609521811665540548899435521/1157920892373161954235709850086 87907853269984665640564039457584007913129639936 On 11/23/06, Paul Smith <phhs80 at gmail.com> wrote:> Dear All > > I am doing the following: > > > x <- yacas("3/2") > > for (i in 2:400) > + x <- yacas(paste(x,"*",x)) > > x > expression(Inf^1.260864167e+117/Inf^6.304320836e+116) > > Eval(x) > [1] NaN > > No luck this way. However, I am successful with > > > y <- yacas("(3/2)^400") > > y > expression(7.05507910865533e+190/2.58224987808691e+120) > > Eval(y) > [1] 2.732144e+70 > > If Ryacas/Yacas cannot multiply fractions with simultaenously very > large numerators and denominators, what else should I use? > > Thanks in advnace, > > Paul > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Detlef Steuer
2006-Nov-23 19:59 UTC
[R] Ryacas and fractions with simultaenously very large numerators and denominators
> > > > If Ryacas/Yacas cannot multiply fractions with simultaenously very > > large numerators and denominators, what else should I use?Did you try package gmp ? Hth Detlef> > > > Thanks in advnace, > > > > Paul > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- "Keinen Gedanken zweimal denken, au?er er ist sch?n." Unbekannte Quelle
Gabor Grothendieck
2006-Nov-23 23:58 UTC
[R] Ryacas and fractions with simultaenously very large numerators and denominators
Also just to be clear this does not mean that you cannot use very large numbers. It means that you need to keep them on the yacas side and move them over right at the end and at that point they must not be so large that R itself cannot handle them. For example, this works because all the calculations are done on the yacas side:> x <- Sym("x") > Set(x, "2/3")expression(2/3)> for(i in 1:400) Set(x, x * "2/3") > N(x)expression(2.440085918e-71) On 11/23/06, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:> There is likely some limitation in the Ryacas interface that needs to > be addressed by the Ryacas developers. yacas itself can support very large > numbers so just use yacas directly. > > Aside from that I, as mentioned previously in this thread, yacas returns a > "yacas" object and that is a complex structure for which it makes no sense > to try to use "paste". > > This works: > > > x <- Sym("3/2") > > for(i in 2:5) x <- as.Sym(yacas(x*x)) > > x > expression(43046721/65536) > > but quickly comes up against some limits in Ryacas (not in yacas) > if you go past 5. > > This also works and is even easier but may quickly generate enormous strings > that might overflow the interface: > > > x <- Sym("3/2") > > for(i in 2:5) x <- x*x > > dput(x) > structure("( ( ( ( 3/2 * 3/2 ) * ( 3/2 * 3/2 ) ) * ( ( 3/2 * 3/2 ) * ( > 3/2 * 3/2 ) ) ) * ( ( ( 3/2 * 3/2 ) * ( 3/2 * 3/2 ) ) * ( ( 3/2 * 3/2 > ) * ( 3/2 * 3/2 ) ) ) )", class = c("Sym", > "character")) > > x > expression(43046721/65536) > > > Using yacas directly: > > yacas > ... > In> x := 3/2 > Out> 3/2 > In> x := 3/2 > Out> 3/2 > In> x := x*x > Out> 9/4 > In> x := x*x > Out> 81/16 > In> x := x*x > Out> 6561/256 > In> x := x*x > Out> 43046721/65536 > In> x := x*x > Out> 1853020188851841/4294967296 > In> x := x*x > Out> 3433683820292512484657849089281/18446744073709551616 > In> x := x*x > Out> 11790184577738583171520872861412518665678211592275841109096961/340282366920 > 938463463374607431768211456 > In> x := x*x > Out> 139008452377144732764939786789661303114218850808529137991604824430036072629 > 766435941001769154109609521811665540548899435521/1157920892373161954235709850086 > 87907853269984665640564039457584007913129639936 > > > > On 11/23/06, Paul Smith <phhs80 at gmail.com> wrote: > > Dear All > > > > I am doing the following: > > > > > x <- yacas("3/2") > > > for (i in 2:400) > > + x <- yacas(paste(x,"*",x)) > > > x > > expression(Inf^1.260864167e+117/Inf^6.304320836e+116) > > > Eval(x) > > [1] NaN > > > > No luck this way. However, I am successful with > > > > > y <- yacas("(3/2)^400") > > > y > > expression(7.05507910865533e+190/2.58224987808691e+120) > > > Eval(y) > > [1] 2.732144e+70 > > > > If Ryacas/Yacas cannot multiply fractions with simultaenously very > > large numerators and denominators, what else should I use? > > > > Thanks in advnace, > > > > Paul > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > >