Symbolic differentiation is one of MathCore’s core capabilities. Rather than approximating derivatives numerically, MathCore traverses the expression tree and applies analytic differentiation rules — producing an exact symbolic result you can inspect, simplify, or evaluate further. Whether you’re computing the slope of a polynomial, applying the chain rule to a composed trigonometric function, or differentiating a multivariate expression with respect to one of its variables, the same unified API handles it all.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Nonanti/mathcore/llms.txt
Use this file to discover all available pages before exploring further.
MathCore::differentiate
The top-level entry point parses a string expression and returns the symbolic derivative as an Expr.
Parameters
| Parameter | Type | Description |
|---|---|---|
expression | &str | A string representation of the expression to differentiate. |
var | &str | The variable with respect to which the derivative is taken. |
Return value
ReturnsOk(Expr) containing the simplified symbolic derivative, or Err(MathError) if the expression cannot be parsed or differentiated.
MathCore::differentiate is a static (associated) function — you do not need to construct a MathCore instance to call it.Basic examples
Differentiation rules supported
MathCore applies standard calculus rules by structural pattern-matching on theExpr tree:
| Rule | Trigger | Result |
|---|---|---|
| Constant | Any Number or non-matching Symbol | 0 |
| Identity | Symbol matching var | 1 |
| Sum / Difference | f ± g | f' ± g' |
| Product rule | f * g | f' * g + f * g' |
| Quotient rule | f / g | (f' * g - f * g') / g^2 |
| Power rule | f^n (constant exponent) | n * f^(n-1) * f' |
Chain rule — sin | sin(u) | cos(u) * u' |
Chain rule — cos | cos(u) | -sin(u) * u' |
Chain rule — tan | tan(u) | sec(u)^2 * u' |
Chain rule — sec | sec(u) | sec(u) * tan(u) * u' |
Chain rule — ln | ln(u) | (1/u) * u' |
Chain rule — exp | exp(u) | exp(u) * u' |
Chain rule — sqrt | sqrt(u) | (1 / (2 * sqrt(u))) * u' |
| Negation | -f | -f' |
| Abs | |f| | (f / |f|) * f' |
Product and chain rule examples
Using Calculus::differentiate directly
If you have already parsed or constructed an Expr value, you can call the lower-level Calculus::differentiate directly and skip the parsing step:
simplify_basic before being returned — e.g. 1 * x becomes x, 0 + f becomes f.
Partial derivatives (multivariate expressions)
For expressions in more than one variable, differentiate with respect to each variable in turn using the same API:Higher-order derivatives
Passing the result of one call back intodifferentiate gives higher-order derivatives:
Unsupported operations
When MathCore encounters a function it does not have a built-in derivative rule for (anything outside the table above), it returns a symbolicDerivative node rather than erroring out:
