testeq
Check the mathematical equivalence of expressions
MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
testeq(ex1
,options
) testeq(ex1
,ex2
,options
)
testeq(ex1, ex2)
checks whether the expressions ex1
and ex2
are
mathematically equivalent.
testeq(ex1, ex2)
returns TRUE
if
the difference ex1  ex2
can be simplified to zero.
testeq
returns FALSE
if ex1
and ex2
attain
different values for at least one choice of variables contained in
them.
By default, testeq
performs five random tests.
If randomly chosen values of the variables are inconsistent with the
assumptions on these variables or the test returns the value undefined
, the testeq
function
performs an additional test. The number of additional tests cannot
exceed the number of initial tests. By default, the maximal total
number of tests is 10. See Example 4.
If the equivalence of ex1
and ex2
cannot
be decided, testeq
returns UNKNOWN
.
If only one expression is passed to testeq
,
it is checked whether this expression is equivalent to zero.
testeq
uses Simplify(ex1  ex2)
and is(ex1
 ex2 = 0)
to determine its result. The result UNKNOWN
can
be caused by weaknesses of Simplify
and is
.
Using the options, the simplification process can be made stronger at the cost of increased run time.
Check the mathematical equivalence of expressions:
testeq(sin(x)^2, 1  cos(x)^2)
testeq(sin(2*x), 2*sin(x)*cos(x))
testeq((cos(a) + sin(a))^2, 2*(cos(PI/4  a)^2))
In order to be equivalent, two expressions must be equivalent
for all values their variables can attain. For certain values of the
parameter a
the following two expressions are equivalent,
but for other values they are not; therefore, they are not equivalent:
testeq((cos(a) + sin(a))^2, 3*(cos(PI/4  a)^2))
Applying expand
and rewrite
to an expression
always produces an equivalent expression. However, with the default
setting of 100
steps for the internal simplification
procedure, the equivalence is not recognized in the following example:
f:= exp(arcsin(I*sin(x))): g:= rewrite(expand(f), ln): testeq(f, g)
After 1000
steps, however, the expressions
are recognized as being equivalent:
testeq(f, g, Steps = 1000); delete f, g:
When trying to prove the equivalence of two expressions, the testeq
command
runs random tests before applying IgnoreAnalyticConstraints
.
If tests for random values of identifiers show that expressions are
not equivalent, testeq
disregards the IgnoreAnalyticConstraints
option
and returns FALSE:
testeq(x^(ln(a))*x^(ln(b)) = x^(ln(a*b)), IgnoreAnalyticConstraints)
If, for a given number of attempts, random tests do not find
the inequality between expressions, testeq
applies
the IgnoreAnalyticConstraints
option:
testeq(ln(a) + ln(b) = ln(a*b), IgnoreAnalyticConstraints)
By default, random tests check the equality of expressions for five random sets of values of identifiers. Increasing the number of attempts can prove inequality:
testeq(ln(a) + ln(b) = ln(a*b), NumberOfRandomTests = 10, IgnoreAnalyticConstraints)
When testeq
performs tests, it takes into
account the assumptions on variables that you specify:
testeq(x, abs(x)) assuming x > 0
If testeq
chooses values of the variables
that are inconsistent with the assumptions on these variables, it
performs an additional test. The number of tests cannot exceed 2n
,
where n
is the original number of tests defined
by the NumberOfRandomTests
option. If testeq
performs 2n
tests
and all values of the variables are inconsistent with the assumptions
on the variables, testeq
returns UNKNOWN
:
testeq(x, abs(x)) assuming x^2 + x + 7 = x^13 + 11
For this particular assumption, MuPAD^{®} cannot find a closedform
expression to substitute for x
:
solve(x^2 + x + 7 = x^13 + 11, x)
Therefore, increasing the number of tests does not help testeq
decide
if the expressions are equivalent:
testeq(x, abs(x), NumberOfRandomTests = 100) assuming x^2 + x + 7 = x^13 + 11

Any MuPAD expressions 

Option, specified as This option is directly passed to 

Option, specified as This option is directly passed to 

Option, specified as This option is directly passed to The default value of The advanced user can specify her own rule base (see 

Option, specified as This option determines the number of times The default value of 

This option applies purely algebraic simplifications to expressions Note that random tests have higher priority than 
TRUE
, FALSE
, or UNKNOWN