[R] Ryacas and fractions with simultaenously very large numerators and denominators
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Nov 24 00:58:47 CET 2006
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.
> >
>
More information about the R-help
mailing list