Learn R Programming

simplr (version 0.1-1)

simplify: Basic Symbolic Expression Simplification

Description

simplify simplifies sexp by applying basic algebraic simplification rules. simplifyq quotes its argument, i.e. simplifyq(X) is equivalent to simplify(quote(X)).

Usage

simplify(sexp)
simplifyq(sexp)
"simplify"(sexp)
"simplify"(sexp)
"simplify"(sexp)
"simplify"(sexp)
"simplify"(sexp)

Arguments

sexp
An R object to simplify. See details.

Value

The simplified expression.

Details

simplify is a S3 generic method with support for objects of class numeric, integer, name, call, and function. SimplR uses code from the Ev3 computer algebra system to implement expression simplification. The following simplification steps are performed:
  • consolidate product coefficients
  • distribute coefficients over sums
  • convert differences to sums
  • simplify constants
  • simplify products
  • compact linear parts
  • simplify trigonometrics

See Also

http://www.lix.polytechnique.fr/~liberti/Ev3.pdf

Examples

Run this code
simplifyq(3*2+1)              #=> 7

simplifyq(1 * x)              #=> x
simplifyq(x / x)              #=> 1
simplifyq(x - x)              #=> 0
simplifyq(x + 1 - 1)          #=> x

simplifyq(f(x) + f(x) + y)    #=> y + 2 * f(x)
simplifyq(sin(x)^2+cos(x)^2)  #=> 1

simplify(function(a,b) a + a + 3 * f(b) * 5 / f(b))
#=> function(a, b) 15 + 2 * a

Run the code above in your browser using DataLab