Accelerating the pace of engineering and science

# simplify

Algebraic simplification

## Description

example

simplify(S) performs algebraic simplification of S. If S is a symbolic vector or matrix, this function simplifies each element of S.

example

simplify(S,Name,Value) performs algebraic simplification of S using additional options specified by one or more Name,Value pair arguments.

## Examples

### Simplify Expressions

Simplify these symbolic expressions:

```syms x a b c
simplify(sin(x)^2 + cos(x)^2)
simplify(exp(c*log(sqrt(a+b))))```
```ans =
1

ans =
(a + b)^(c/2)```

### Simplify Elements of a Symbolic Matrix

Call simplify for this symbolic matrix. When the input argument is a vector or matrix, simplify tries to find a simpler form of each element of the vector or matrix.

```syms x
simplify([(x^2 + 5*x + 6)/(x + 2),...
sin(x)*sin(2*x) + cos(x)*cos(2*x);
(exp(-x*i)*i)/2 - (exp(x*i)*i)/2, sqrt(16)])```
```ans =
[  x + 3, cos(x)]
[ sin(x),      4]```

### Get Simpler Results Using IgnoreAnalyticConstraints

Try to simplify this expression. By default, simplify does not combine powers and logarithms because combining them is not valid for generic complex values.

```syms x
s = (log(x^2 + 2*x + 1) - log(x + 1))*sqrt(x^2);
simplify(s)```
```ans =
-(log(x + 1) - log((x + 1)^2))*(x^2)^(1/2)```

To apply the simplification rules that let the simplify function combine powers and logarithms, set IgnoreAnalyticConstraints to true:

`simplify(s, 'IgnoreAnalyticConstraints', true)`
```ans =
x*log(x + 1)```

### Get Simpler Results Using Steps

Simplify this expression:

```syms x
f = ((exp(-x*i)*i)/2 - (exp(x*i)*i)/2)/(exp(-x*i)/2 + ...
exp(x*i)/2);
simplify(f)```
```ans =
-(exp(x*2*i)*i - i)/(exp(x*2*i) + 1)```

By default, simplify uses one internal simplification step. You can get different, often shorter, simplification results by increasing the number of simplification steps:

```simplify(f, 'Steps', 10)
simplify(f, 'Steps', 30)
simplify(f, 'Steps', 50)```
```ans =
(2*i)/(exp(x*2*i) + 1) - i

ans =
((cos(x) - sin(x)*i)*i)/cos(x) - i

ans =
tan(x)```

### Simplify Favoring Real Numbers

To force simplify favor real values over complex values, set the value of Criterion to preferReal:

```syms x
f = (exp(x + exp(-x*i)/2 - exp(x*i)/2)*i)/2 -...
(exp(- x - exp(-x*i)/2 + exp(x*i)/2)*i)/2;
simplify(f, 'Criterion','preferReal', 'Steps', 100)```
```ans =
cos(sin(x))*sinh(x)*i + sin(sin(x))*cosh(x)```

If x is a real value, then this form of expression explicitly shows the real and imaginary parts.

Although the result returned by simplify with the default setting for Criterion is shorter, here the complex value is a parameter of the sine function:

`simplify(f, 'Steps', 100)`
```ans =
sin(x*i + sin(x))```

When you set Criterion to preferReal, the simplifier disfavors expression forms where complex values appear inside subexpressions. In case of nested subexpressions, the deeper the complex value appears inside an expression, the least preference this form of an expression gets.

### Simplify Expressions with Complex Arguments in Exponents

Setting Criterion to preferReal helps you avoid complex arguments in exponents.

Simplify these symbolic expressions:

```simplify(sym(i)^i, 'Steps', 100)
simplify(sym(i)^(i+1), 'Steps', 100)```
```ans =
exp(-pi/2)

ans =
(-1)^(1/2 + i/2)```

Now, simplify the second expression with the Criterion set to preferReal:

`simplify(sym(i)^(i+1), 'Criterion', 'preferReal', 'Steps', 100)`
```ans =
exp(-pi/2)*i```

## Input Arguments

expand all

### S — Input expressionsymbolic expression | symbolic function | symbolic vector | symbolic matrix

Input expression, specified as a symbolic expression, function, vector, or matrix.

### Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Seconds',60 limits the simplification process to 60 seconds.

### 'Criterion' — Simplification criterion'default' (default) | 'preferReal'

Simplification criterion, specified as the comma-separated pair consisting of 'Criterion' and one of these strings.

 'default' Use the default (internal) simplification criteria. 'preferReal' Favor the forms of S containing real values over the forms containing complex values. If any form of S contains complex values, the simplifier disfavors the forms where complex values appear inside subexpressions. In case of nested subexpressions, the deeper the complex value appears inside an expression, the least preference this form of an expression gets.

### 'IgnoreAnalyticConstraints' — Simplification rulesfalse (default) | true

Simplification rules, specified as the comma-separated pair consisting of 'IgnoreAnalyticConstraints' and one of these values.

 false Use strict simplification rules. simplify always returns results equivalent to the initial expression. true Apply purely algebraic simplifications to an expression. simplify can return simpler results for expressions for which it would return more complicated results otherwise. Setting IgnoreAnalyticConstraints to true can lead to results that are not equivalent to the initial expression.

### 'Seconds' — Time limit for the simplification processInf (default) | positive number

Time limit for the simplification process, specified as the comma-separated pair consisting of 'Seconds' and a positive value that denotes the maximal time in seconds.

### 'Steps' — Number of simplification steps1 (default) | positive number

Number of simplification steps, specified as the comma-separated pair consisting of 'Steps' and a positive value that denotes the maximal number of internal simplification steps. Note that increasing the number of simplification steps can slow down your computations.

simplify(S,'Steps',n) is equivalent to simplify(S,n), where n is the number of simplification steps.

## Alternative Functionality

Besides the general simplification function (simplify), the toolbox provides a set of functions for transforming mathematical expressions to particular forms. For example, you can use particular functions to expand or factor expressions, collect terms with the same powers, find a nested (Horner) representation of an expression, or quickly simplify fractions. If the problem that you want to solve requires a particular form of an expression, the best approach is to choose the appropriate simplification function. These simplification functions are often faster than simplify.

expand all

### Tips

• Simplification of mathematical expression is not a clearly defined subject. There is no universal idea as to which form of an expression is simplest. The form of a mathematical expression that is simplest for one problem might be complicated or even unsuitable for another problem.

### Algorithms

When you use IgnoreAnalyticConstraints, simplify follows these rules:

• log(a) + log(b) = log(a·b) for all values of a and b. In particular, the following equality is valid for all values of a, b, and c:

(a·b)c = ac·bc.

• log(ab) = b·log(a) for all values of a and b. In particular, the following equality is valid for all values of a, b, and c:

(ab)c = ab·c.

• If f and g are standard mathematical functions and f(g(x)) = x for all small positive numbers, f(g(x)) = x is assumed to be valid for all complex values of x. In particular:

• log(ex) = x

• asin(sin(x)) = x, acos(cos(x)) = x, atan(tan(x)) = x

• asinh(sinh(x)) = x, acosh(cosh(x)) = x, atanh(tanh(x)) = x

• Wk(x·ex) = x for all values of k