Simplify {lazy.symbolic}R Documentation

Simplify Symbolic Expressions (very primitive version)

Description

Simplify Symbolic Expressions (very primitive version)

Usage

Simplify(exp, all = 0, method = 1:3, markso = 1, verify = 1, debug = 0)

Arguments

exp

Expression (vector or matrix)

all

= 1 to apply Simplify repeatedly a and b are not numeric.

method

How to simplify: default method is 1:4.
= 1 : varname*num -> num*varname
= 2 : processing 1s and 0s, a/a -> 1, etc w/o using find_terms = 3 : a-a or -a+a -> 0 or 0*func(x) -> 0
= 4 : ???

markso

= 0 not to mark the special opeartors

verify

= 0 not to check the result by is_valid

debug

= 1 to print details

Details

This is a very primitive version.
This function applies some mathematical rules such as
0*a -> 0 or a\*1 -> a described as regular expressions to an input expression.

In method=1 and 2, gsub function is used to replace the patterns such as 0*a or -((a)) with their simplified mathematically equivalent forms.
In method=3, input expression is decomposed into terms and the patterns such as func(a)*0 or X%*%inv(X) will be simplified.
Can handle fully symbolic matrix expressions.

Repeated use of this function may simplify the result further.
Simplify may work better if you Expand the expression prior to submission.
See the examples below where lv() returns .Last.value .
When called from remove_paren, use method=1:3. ()

Value

Simplified expression

Examples

expr="-((a))-b/b+0*c+d*0+1*e-e*2+f-3*f+0/(g+h) - (x-y)*(((z+1)))"
Simplify( expr, all=1 )
Expand(.Last.value, all=1)
Expand(expr, all=1)

matTimes( demomat(2,2,root="a"), demomat(2,1), simplify=0 )
Simplify(lv())

Simplify(c("1*b","1*(b)","1*f(b)"))
Simplify(lv())
Simplify(c("0*b","0*(b)","0*f(b)"))

dd <- Det(demomat(2,2,root="a"))
Simplify(Expand(dd))

expr1=c("-(X+A)%*%inv(X+A)%*%(X+A)%*%inv(X+A)"
      , "-(X+A1)%*%inv(X+A)%*%(X+A)%*%inv(X+A)")
Simplify(expr1)
Simplify(expr1, all=1)

Simplify( "a+b+2*a+2*b-3*a+3*b" )
Simplify( "a*c - b*c" )

A=demomat(2,2,root="a")
AinvA=matTimes( A, Inv(A) )
Simplify( AinvA, all=1 )
Simplify( Expand(AinvA, all=1), all=1 )
# Sorry, cannot simplify \code{AinvA[2,1]} and \code{AinvA[2,2]}.


[Package lazy.symbolic version 0.1.3 Index]