Accelerating the pace of engineering and science

# testeq

Check the mathematical equivalence of expressions

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

```testeq(ex1, options)
testeq(ex1, ex2, options)
```

## Description

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.

## Examples

### Example 1

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))`

### Example 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:```

### Example 3

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)```

### Example 4

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 closed-form 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```

## Options

 Steps Option, specified as Steps = n This option is directly passed to Simplify and determines the maximum number of steps allowed for the internal simplification process. The default value of n is 100. Increasing the number of steps can give you a simpler result, often at the costs of increased runtime. For details, see the Simplify help page. Seconds Option, specified as Seconds = t This option is directly passed to Simplify and sets a time limit t in seconds for the internal simplification process. The default setting is infinity, i.e., the simplification process will not terminate due to a time limitation, but due to other internal stopping criteria. See the documentation of Simplify for details. RuleBase Option, specified as RuleBase = base This option is directly passed to Simplify and determines the rule base that is used for the internal simplification process. See the documentation of Simplify for details. The default value of base is Simplify. The advanced user can specify her own rule base (see Simplify). This allows the construction of specialized and fast tests for special classes of expressions. NumberOfRandomTests Option, specified as NumberOfRandomTests = n This option determines the number of times testeq tries to disprove the equivalence of ex1 and ex2 by plugging in some random values for all identifiers. The default value of n is 5. 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 total number of tests does not exceed 2n. See Example 4. IgnoreAnalyticConstraints This option applies purely algebraic simplifications to expressions ex1 and ex2. For the list of rules, see the documentation of Simplify. These simplification rules are not generally valid. Note that random tests have higher priority than IgnoreAnalyticConstraints. When trying to prove the equivalence of two expressions, the testeq command runs random tests before applying the IgnoreAnalyticConstraints option. If random tests prove the expressions are not equivalent, testeq returns the value FALSE. See Example 3.

## Return Values

TRUE, FALSE, or UNKNOWN