redcas-package: An Interface to the Computer Algebra System 'REDUCE'

redcas-packageR Documentation

An Interface to the Computer Algebra System 'REDUCE'

Description

'REDUCE' is a portable general-purpose computer algebra system supporting scalar, vector, matrix and tensor algebra, symbolic differential and integral calculus, arbitrary precision numerical calculations and output in 'LaTeX' format. 'REDUCE' is based on 'Lisp' and is available on the two dialects 'Portable Standard Lisp' ('PSL') and 'Codemist Standard Lisp' ('CSL'). The 'redcas' package provides an interface for executing arbitrary 'REDUCE' code interactively from 'R', returning output as character vectors. 'R' code and 'REDUCE' code can be interspersed. It also provides a specialized function for calling the 'REDUCE' feature for solving systems of equations, returning the output as an 'R' object designed for the purpose. A further specialized function uses 'REDUCE' features to generate 'LaTeX' output and post-processes this for direct use in 'LaTeX' documents, e.g. using 'Sweave'.

Details

The package allows you to start a REDUCE session (redStart), send one or more vectors of REDUCE commands to the session for execution and retrieve the output (redExec), render output as LaTeX (asltx), and shut down the session and optionally return the entire output file (redClose). Output is returned as a list of character vectors containing the command output, the commands and the combined comands and output. redcas can also directly call the REDUCE operator for solving algebraic equations (redSolve), returning a redcas.solve object.

Several other functions are available: redExpand is called by redExec for checking and preparing the input vector while redDropOut and redSplitOut are called by redExec to format the output. All three can be called independently of redExec.

REDUCE uses a different terminology to R. Some translations:

REDUCE R
command: statement
log: transcript
operator (prefix): function
operator (infix): operator
procedure: function
switch: (global) option

Author(s)

Martin Gregory [aut, cre]

Maintainer: Martin Gregory <mairtin.macghreagoir@gmail.com>

References

Details of the REDUCE system including extensive documentation is available at the REDUCE web site.

Examples

## start a session
id <- redStart()

## can only run code if session was successfully started
if (is.numeric(id)) {
   ## define vectors of REDUCE code for submission
   x1 <- "solve((x+1)^2, x);"
   x2 <- "b:=factorize(45056);"
   x3 <- c("operator v; ",
	   "la:=-m/(v(2)^2 + v(3)^2)^(1/2) ;")

   ## execute x1 and display on the output of the commands
   y1 <- redExec(id, x1)
   writeLines(y1$out)

   ## execute x2 and display first the output and then the commands
   y2 <- redExec(id, x2)
   writeLines(c(y2$out, y2$cmd))

   ## execute x3 and display the log (commands and output interspersed)
   writeLines(y3 <- redExec(id, x3, split=FALSE))

   ## close the session
   redClose(id)
   }

redcas documentation built on April 12, 2025, 1:40 a.m.