Simplify {lazy.symbolic} | R Documentation |
Simplify Symbolic Expressions (very primitive version)
Simplify(exp, all = 0, method = 1:3, markso = 1, verify = 1, debug = 0)
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. |
markso |
= 0 not to mark the special opeartors |
verify |
= 0 not to check the result by |
debug |
= 1 to print 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. ()
Simplified expression
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]}.