# Substituting a variable by a value (Maple and Mupad compatibility): subs

### 5.12.20 Substituting a variable by a value (Maple and Mupad compatibility): subs

In Maple and in Mupad, you would use the subs command to substitute a variable by a value in an expression. But the order of the arguments differ between Maple and Mupad. Therefore, to achieve compatibility, in Xcas, the subs command arguments order depends on the mode (see Section 2.5.2).

In Maple mode:

- subs takes two arguments:
  - eq, an equality or list of equalities of the form var=value.
  - expr, an expression.
- subs(eq,expr) returns the expression with the variables replaced by their given values.

#### Examples.

- Input in Maple mode (if the variable a is purged, otherwise first enter purge(a)):
  subs(a=2,a^2+1)
  Output:

  5

- Input in Maple mode (if the variables a and b are purged, otherwise first enter purge(a,b)):
  subs([a=2,b=1],a^2+b)
  Output:

  5

In Mupad or Xcas or TI modes, subs behaves like subst (see Section 5.12.18).

- subst takes two or three arguments.
  - expr, an expression.
  - eqs, an equality of the form var=value or a list of such equalities, or
    vars,vals, a variable or list of variables followed by a value or a list of values for substitution.
- subs(expr,eqs) or subs(expr,vars,vals) returns the expression with the variables replaced by their given values.

#### Examples.

- Input in Mupad or Xcas or TI modes (if the variable a is purged, otherwise first enter purge(a)):
  subs(a^2+1,a=2)
  or:
  subs(a^2+1,a,2)
  Output:

  5

- Input in Mupad or Xcas or TI modes (if the variables a and b are purged, otherwise first enter purge(a,b) first):
  subs(a^2+b,[a=2,b=1])
  or:
  subs(a^2+b,[a,b],[2,1])
  Output:

  5

Note that subs does not quote its argument, hence in a normal evaluation process, the substitution variable should be purged otherwise it will be replaced by its assigned value before substitution is done.