# elworthy-diff

[![crates.io](https://img.shields.io/crates/v/elworthy-diff.svg)](https://crates.io/crates/elworthy-diff)
[![docs.rs](https://docs.rs/elworthy-diff/badge.svg)](https://docs.rs/elworthy-diff)

Symbolic differentiation over `elworthy_expr::Expr`.

Part of the [**elworthy**](https://github.com/alejandro-soto-franco/elworthy) workspace: a Rust JIT compiler that specialises Bismut-Elworthy-Li formulas into SIMD kernels for unbiased Monte Carlo Greeks on non-stationary SDEs.

## What it provides

- `diff(expr, wrt)`: partial derivative of a symbolic expression with respect to any `Var`.
- Coverage: constants, variables, sums, products, integer powers, and all transcendentals in `Fun` (`exp`, `log`, `sin`, `cos`, `sqrt`).

## Design notes

The output is an unsimplified `Expr` tree. Downstream stages call `elworthy_expr::simplify` for constant folding and identity reduction before lowering. This separation keeps differentiation rules local and testable.

Higher derivatives are obtained by composition:

```rust
let ddf = diff(&diff(&f, &Var::State(0)), &Var::State(0));
```

## Correctness

Unit tests verify the differentiation of the canonical SDE coefficients used by the first milestone (geometric Brownian motion, Heston, CIR). Property-based tests in `elworthy-codegen` cross-check the symbolic derivative against a finite-difference evaluation of the original expression.

## Licence

Apache-2.0.
