library(Ryacas0)
Ryacas
makes the yacas
computer algebra
system available from within R
. The name yacas
is short for “Yet Another Computer Algebra System”. The
yacas
program is developed by Ayal Pinkhuis (who is also
the maintainer) and others, and is available at http://www.yacas.org/ for
various platforms. There is a comprehensive documentation (300+ pages)
of yacas
(also available at http://www.yacas.org/) and the documentation contains
many examples.
<- "x^2 + 4 + 2*x + 2*x"
eq yacas(eq)
## yacas_expression(x^2 + 2 * x + 2 * x + 4)
yacas(paste0("Simplify(", eq, ")"))
## yacas_expression(x^2 + 4 * x + 4)
yacas(paste0("Factor(", eq, ")"))
## yacas_expression((x + 2)^2)
Or by using the corresponding R
functions directly:
Simplify(yacas(eq))
## yacas_expression(x^2 + 4 * x + 4)
Factor(yacas(eq))
## yacas_expression((x + 2)^2)
Or course the result can be saved before calling the helper
R
functions:
<- yacas(eq)
yeq Simplify(yeq)
## yacas_expression(x^2 + 4 * x + 4)
Factor(yeq)
## yacas_expression((x + 2)^2)
And getting results out:
<- Factor(yeq)
res as.character(res)
## [1] "(x + 2)^2"
TeXForm(res)
## [1] "\\left( x + 2\\right) ^{2}"
To include inline, e.g. \(x ^{2} + 2 x + 2 x + 4 = \left( x + 2\right) ^{2}\).
Sym()
<- Sym("x")
xs <- xs^2 + 4 + 2*xs + 2*xs
eqs Simplify(eqs)
## yacas_expression(x^2 + 4 * x + 4)
Factor(eqs)
## yacas_expression((x + 2)^2)
<- Factor(eqs)
res as.character(res)
## [1] "(x + 2)^2"
TeXForm(res)
## [1] "\\left( x + 2\\right) ^{2}"
Sym()
yacas("p := x^2 + 4 + 2*x + 2*x")
## yacas_expression(x^2 + 2 * x + 2 * x + 4)
<- Sym("p")
ps ps
## yacas_expression(x^2 + 2 * x + 2 * x + 4)
TeXForm(Simplify(ps))
## [1] "x ^{2} + 4 x + 4"