Derivative and partial derivative

### 2.17.5 Derivative and partial derivative

`diff` or `derive` may have one or two arguments to compute a first order derivative (or first order partial derivative) of an expression or of a list of expressions, or several arguments to compute the n-th partial derivative of an expression or list of expressions.

#### Derivative and first order partial derivative : `diff derive deriver`

`diff` (or `derive`) takes two arguments : an expression and a variable (resp a vector of the variable name) (see several variable functions in 2.50). If only one argument is provided, the derivative is taken with respect to `x`
`diff` (or `derive`) returns the derivative (resp a vector of derivative) of the expression with respect to the variable (resp with respect to each variable) given as second argument.
Examples :

- Compute :

  ∂ (x.y2.z3+x.y.z)
  ∂ z

  Input :
  `diff(x*y` ``^```2*z```^```3+x*y*z,z)`
  Output :
  `x*y```^```2*3*z```^```2+x*y`
- Compute the 3 first order partial derivatives of x*y2*z3+x*y*z.
  Input :
  `diff(x*y```^```2*z```^```3+x*y,[x,y,z])`
  Output :
  `[y```^```2*z```^```3+y*z, x*2*y*z```^```3+x*z, x*y```^```2*3*z```^```2+x*y]`

#### Derivative and n-th order partial derivative : `diff derive deriver`

`derive` (or `diff`) may take more than two arguments : an expression and the names of the derivation variables (each variable may be followed by $n to indicate the number n of derivations).
`diff` returns the partial derivative of the expression with respect to the variables given after the first argument.

The notation $ is usefull if you want to derive k times with respect to the same variable, instead of entering k times the same variable name, one enters the variable name followed by `$k`, for example `x$3` instead of `(x,x,x)`. Each variable may be followed by a $, for example `diff(exp(x*y),x$3,y$2,z)` is the same as `diff(exp(x*y),x,x,x,y,y,z)`
Examples

- Compute :

  ∂2 (x.y2.z3+x.y.z)
  ∂ x∂ z

  Input :
  `diff(x*y` ``^```2*z```^```3+x*y*z,x,z)`
  Output :
  `y```^```2*3*z```^```2+y`
- Compute :

  ∂3 (x.y2.z3+x.y.z)
  ∂ x∂2 z

  Input :
  `diff(x*y` ``^```2*z```^```3+x*y*z,x,z,z)`
  Or input :
  `diff(x*y` ``^```2*z```^```3+x*y*z,x,z$2)`
  Output :
  `y```^```2*3*2*z`
- Compute the third derivative of :

  1
  x2+2

  Input :
  `normal(diff((1)/(x```^```2+2),x,x,x))`
  Or :
  `normal(diff((1)/(x```^```2+2),x$3))`
  Output :
  `(-24*x```^```3+48*x)/(x```^```8+8*x```^```6+24*x```^```4+32*x```^```2+16)`

Remark

- Note the difference between `diff(f,x,y)` and `diff(f,[x,y])` :
  `diff`(f,x,y) returns ∂2(f)/∂ x∂ y and
  `diff`(f,[x,y]) returns [∂(f)/∂ x,∂ (f)/∂ y]
- Never define a derivative function with `f1(x):=diff(f(x),x)`. Indeed, `x` would mean two different things Xcas is unable to deal with: the variable name to define the f1 function and the differentiation variable. The right way to define a derivative is either with `function_diff` or:
  `f1:=unapply(diff(f(x),x),x)`