This entry is documented with its primary interface. Open the documentation →
diff
diff(x: ExpressionInput, variable?: ExpressionInput, n?: number | Expression): ExpressionDifferentiates an expression symbolically. The chain, product, sum, and power rules are applied recursively, together with the built-in derivative table for recognized functions. An omitted variable is inferred as the first variable in the expression. Existing Expression input is reused during normalization.
n requests a repeated derivative, and order zero returns the input. A negative
or non-integer order, a non-variable differentiation target, or an unsupported
derivative is preserved as an unevaluated diff(...) expression. Negative orders
are reserved for antiderivatives. Constants and expressions independent of the
selected variable differentiate to zero.
core!UnsupportedOperationError If variable is numeric.
Parameters
| Name | Type | Description |
|---|---|---|
x | ExpressionInput | Expression to differentiate. |
variable | ExpressionInput | Variable with respect to which the derivative is taken. |
n | number | Expression | Non-negative integer derivative order. Defaults to the first derivative. |
Returns
Expression — The symbolic derivative, or an unevaluated diff(...) call when the
requested operation cannot be resolved.
Examples
diff('sin(x^2)', 'x').text();
diff('x^4', 'x', 2).text();