Interface to the yacas computer algebra system.
yacas(x, ...)
# S3 method for character
yacas(x, verbose = FALSE, method,
retclass = c("expression", "character", "unquote"),
addSemi = TRUE, ...)
A yacas character string or an R expression without terminating semicolon to be processed by yacas.
Additional arguments ultimately passed down to
yacas.character
.
A logical value indicating verbosity of output or
"input"
to only show input to yacas but not output from yacas or
"output"
to only show output from yacas but not input to yacas.
method used to communicate with yacas. If "socket"
is
specified then the same yacas session is used on a sequence of calls. If
"system"
is specified then a new instance of yacas is used just for
the period of that call. "system"
does not require that the system be
configured to support telnet/sockets and so may be useful in some instances.
If no value is specified the default is taken from
getOption("yacas.method")
and if that is not specified "socket" is
used. "socket"
and "system"
may be abbreviated.
If TRUE
a semicolon is added to the character string
sent to yacas. This can be set to FALSE
if its known that the
character string already has a trailing semicolon. It is ignored if
retclass="expression"
.
The class of the first component of the yacas structure. It
defaults to "expression"
but may be specified as "character"
or "unquote"
. "unquote"
is the same as "character"
except that if the character string returned would have otherwise had quotes
in the first and and last positions then they are stripped.
An R object of class "yacas"
is returned. If
PrettyPrinter("OMForm")
is in effect, which it is by default, then
the first component is an R expression and the OMForm
component
contains OpenMath XML code. In other cases the first component is NULL and
the YacasForm
or PrettyForm
components have display
information.
Generally an expression. Refer to details.
The user supplies an R expression, an R function name corresponding to a function with a single line body, a formula or a yacas input string. In the case of a formula it is regarded as an expression represented by the right hand side of the formula while the left hand side, if any, is ignored.
Note the silent version syacas()
.
Windows Installation. On Windows one can install Ryacas
by
issuing the commands:
install.packages("Ryacas", dep = TRUE) |
library(Ryacas) |
yacasInstall() |
or by using the Packages | Install package(s)
menu in place of the
first command. The second command downloads scripts.dat
and
yacas.exe
from the internet and installs them into
R_HOME/library/Ryacas/yacdir
where R_HOME
is the location of
your R
installation.
Normally the default locations of yacas, its initialization file and the
scripts file are sufficient but, if necessary, they can be overridden via
the environment variables: YACAS_HOME
, YACAS_INIT
and
YACAS_SCRIPTS
. The YACAS_INVOKE_STRING
environment variable
discussed in the next section overrides all three of these.
All OS Installation. The YACAS_INVOKE_STRING
environment variable
can be used to override the invocation string for yacas. Normally it is not
used. If it does need to be used then a typical use might be:
library(Ryacas) |
# only need to do the file.copy
command once |
file.copy(system.file("yacdir/R.ys", package =
"Ryacas"), "~/.yacsrc") |
# this needs to be done once per
session |
Sys.setenv(YACAS_INVOKE_STRING = "yacas -pc --server
9734") |
demo(Ryacas) # test it out |
yacmode. There is also a utility yacmode which is called without arguments and just turns R into a terminal into yacas until one quits out of it (and back to R) by entering stop, end, quit, exit or e.
Startup. yacas
starts up when yacasStart()
is called or the
first time yacas
is called. yacas is shut down when
yacasStop()
is called or when the package is detached using the
detach()
R command. On Windows, when yacas is shut down, the yacas
process is terminated on Windows XP Pro but not on other versions of
Windows. In those cases there will be a dangling process that the user must
terminate manually.
Translation. The translation process occurs in several steps. If the input
to the yacas
function is an expression then it is translated to a
valid yacas character string (otherwise, it is sent to yacas unprocessed).
Yacas then processes the string and if retclass="expression"
it is
translated back to an R expression (otherwise it is sent back unprocessed).
Examples of translations are:
R | yacas |
sin(x) | Sin(x) |
deriv(sin, x) | Deriv(x)Sin(x) |
log(x) | Ln(x) |
yacas(expression(Factor(x^2-1)))
#> yacas_expression((x + 1) * (x - 1))
exp1 <- expression(x^2 + 2 * x^2)
exp2 <- expression(2 * exp0)
exp3 <- expression(6 * pi * x)
exp4 <- expression((exp1 * (1 - sin(exp3))) / exp2)
print(yacas(exp4))
#> yacas_expression(exp1 * (1 - sin(exp3))/exp2)
print(yacas("Version()")) # yacas version
#> [1] "1.6.1"
# see demo("Ryacas-Function")