Automatic differentiation for nonsmooth functions —
abs,max,min,floordone right.
Standard AD gives garbage at kinks. Clarke-AD uses Clarke generalized
gradients — convex hulls of subgradients — to handle abs/max/min/floor/ceil/signum
honestly.
standard AD: d/dx |x| at x=0 → 0 (wrong!)
clarke-ad: ∂|x| at x=0 → [-1, 1] (correct subgradient set)
curl -sSf https://clarke.jesed.dev/install.sh | shTry it live → clarke.jesed.dev
For a Lipschitz function f, the Clarke subgradient at x₀ is:
∂f(x₀) = conv{lim ∇f(xᵢ) : xᵢ → x₀, xᵢ ∉ Ωf}
At smooth points, this is just the derivative. At kinks (abs, max, floor),
it's a convex set — the subgradient interval.
| Domain | Application |
|---|---|
| Robotics | Contact/impact mechanics (sign function) |
| Control | Saturation, thresholds, argmin compositions |
| Optimization | Nonsmooth objectives, subgradient methods |
| Simulation | Piecewise-constant systems, switched dynamics |
| Machine learning | ReLU networks, hinge loss, quantization |
clarke-ad/
├── crates/
│ ├── clarke-core/ # dual numbers, forward AD
│ ├── clarke-nonsmooth/ # Clarke subgradients, kink detection
│ ├── clarke-opt/ # subgradient, proximal methods
│ └── clarke-wasm/ # browser bridge
├── docs/math.md # the theory
└── scripts/ # regression scripts
cargo test # unit tests
cargo build --release # optimized binary
cd ui && npm install && npm run dev # local dev server- Rust — core AD engine with dual numbers
- Clarke subgradients — convex hull of subgradients at kinks
- wasm-bindgen — browser bridge
- Vite — frontend build
- Clarke, "Optimization and Nonsmooth Analysis" (1983).
- Rockafellar, "Convex Analysis" (1970).
- Shor, "Minimization Methods for Non-Differentiable Functions" (1985).
MIT — see LICENSE.