sympy: sympy

Description Usage Arguments Details Value Note References Examples

View source: R/sympy.R

Description

Interface to the sympy computer algebra system.

Usage

1
sympy(..., retclass = c("character", "Sym", "NULL"), debug = FALSE)

Arguments

...

Character strings which are pasted together with space separators. The resulting string is passed to sympy.

retclass

Character string representing the class of the output or the string "NULL" to mean no output.

debug

Logical. If TRUE then additional debugging info is shown.

Details

The sympy function passes an input string to SymPy and returns the output. The first time sympy is invokved in a session it also starts up SymPy by invoking sympyStart (which sets the appropriate paths, calls jythonStart and then imports sympy). As a result the first invocation of sympy can be expected to much slower than subsequent ones. jythonStart creates a variable .Jython which is stored in the global environment holding the connection information to the SymPy/Jython session.

Internally if the argument output=TRUE, the default, input character string is prefaced with __Rsympy= so if such preface would cause an error then ensure that the argument output=FALSE.

Note that error messages from SymPy appear on the shell/batch console, not on the R console. In the case of an error message the returned value may be wrong.

Value

The character string produced from SymPy.

Note

SymPy is run under Jython, the Java version of Python.

References

http://code.google.com/p/sympy/, http://www.jython.org/Project/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Not run: 
# These examples are mostly from: http://wiki.sympy.org/wiki/Tutorial

# create a SymPy variable called x
sympy("var('x')")
sympy("y = x*x")
sympy("y")

sympy("limit(1/x, x, oo)")

# the next line fails under jython even without R
# and seems to corrupt the rest of the session
# sympy("(1/cos(x)).series(x, 0, 10)")

sympy("diff(sin(2*x), x, 1)")
sympy("diff(sin(2*x), x, 2)")

sympy("integrate(exp(-x), (x, 0, oo))")

sympy("xr = Symbol('xr', real=True)")
sympy("exp(I*xr).expand(complex=True)")

# Matrices are stored row by row (unlike R matrices)
cat(sympy("A = Matrix([[1,x], [y,1]])"), "\n")
cat(sympy("A**2"), "\n")



## End(Not run)

rSymPy documentation built on May 2, 2019, 6:01 a.m.

Related to sympy in rSymPy...