Simplify {lazy.symbolic} | R Documentation |
Simplify Symbolic Expressions (very primitive version)
Simplify(
expr,
all = 0,
method = 1:3,
func_level = 0,
expandfuncarg = 1,
markso = 1,
verify = 1,
debug = 0
)
expr |
Expression (vector or matrix) |
all |
= 1 to apply Simplify repeatedly. |
method |
How to simplify: default method is 1:3. |
func_level |
Level of function argument simplification |
expandfuncarg |
= 0 not to expand the function argument. |
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.
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)
( res <- matTimes( demomat(2,2,root="a"), demomat(2,1), simplify=0 ) )
Simplify(res)
Simplify(c("1*b","1*(b)","1*f(b)"))
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)
( res <- Simplify( "a+b+2*a+2*b-3*a+3*b" ) )
Simplify(res)
# Sorry.
# semi symbolic matrix
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]}.
# fully symbolic matrix
A=demomat(2,2,root="A", fullsymb=1)
A1=matSweep(A,1)
A11=matSweep(A1,1)
A11s=Simplify(A11)
Expand(A11s)