[R] some questions about sympy (that is, rSymPy)

Kjetil Halvorsen kjetilbrinchmannhalvorsen at gmail.com
Tue Apr 17 22:00:20 CEST 2012


see below!

On Sat, Apr 14, 2012 at 4:05 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> On Fri, Apr 13, 2012 at 9:50 PM, Kjetil Halvorsen
> <kjetilbrinchmannhalvorsen at gmail.com> wrote:
>> I am experimenting with rSymPy, and it seems to work nice.
>>
>>
>> However, I dislike the need to wrap all sympy expressions within
>> quotes, it leads to ugly calls like
>> library(rSymPy)
>> Var("x,y,z")
>> sympy("(x+y)**2")
>> and so on.
>
> Suggest you review the rSymPy home page which illustrates how to use
> the Sym interface, e.g.
>
>> library(rSymPy)
>> x <- Var("x")
>> y <- Var("y")
>> (x+y)*(x+y)
> [1] "(x + y)**2"

Thanks!

But there seems to be errors in that interface. First:

> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=C                 LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] rSymPy_0.2-1.1 rJython_0.0-2  rjson_0.2.8    rJava_0.9-3    pnmath_0.0-3
[6] MASS_7.3-17

loaded via a namespace (and not attached):
[1] compiler_2.15.0 fortunes_1.5-0  tools_2.15.0
>

> x <- Var('x')
> y <- x*x
> deriv(y, x, 2)
[1] "2"
> z <- exp(-x)
Error in match(.Generic, transtab[, 1], nomatch = 0) :
  object 'transtab' not found
> Math.Sym
function (x, ...)
{
    idx <- match(.Generic, transtab[, 1], nomatch = 0)
    fn <- if (idx > 0)
        transtab[idx, 3]
    else .Generic
    Sym(fn, "(", x, ")")
}
<bytecode: 0x31a42b0>
<environment: namespace:rSymPy>
>

Kjetil

>
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com



More information about the R-help mailing list