Substitue a variable by a value : subst

### 2.12.16 Substitue a variable by a value : `subst`

`subst` takes two or three arguments :

- an expression depending on a variable, an equality (variable=value of substitution) or a list of equalities.
- an expression depending on a variable, a variable or a list of variables, a value or a list of values for substitution.

`subst` returns the expression with the substitution done. Note that `subst` does not quote it’s argument, hence in a normal evaluation process, the substitution variable should be purged otherwise it will be replaced by it’s assigned value before substitution is done.
Input :

`subst(a```^```2+1,a=2)`

or :

`subst(a```^```2+1,a,2)`

Output (if the variable `a` is purged else first input `purge(a)`) :

`5`

Input :

`subst(a```^```2+b,[a,b],[2,1])`

Or :

`subst(a```^```2+b,[a=2,b=1])`

Output (if the variables `a` and `b` are purged else first input `purge(a,b)`) :

`2```^```2+1`

`subst` may also be used to make a change of variable in an integral. In this case the `integrate` command should be quoted (otherwise, the integral would be computed before substitution) or the inert form `Int` should be used. In both cases, the name of the integration variable must be given as argument of `Int` or `integrate` even you are integrating with respect to `x`.
Input :

`subst(’integrate(sin(x```^```2)*x,x,0,pi/2)’,x=sqrt(t))`

Or :

`subst(Int(sin(x```^```2)*x,x,0,pi/2),x=sqrt(t))`

Output

`integrate(sin(t)*sqrt(t)*1/2*1/t*sqrt(t),t,0,(pi/2)```^```2)`

Input :

`subst(’integrate(sin(x```^```2)*x,x)’,x=sqrt(t))`

Or :

`subst(Int(sin(x```^```2)*x,x),x=sqrt(t))`

Output

`integrate(sin(t)*sqrt(t)*1/2*1/t*sqrt(t),t)`