Expand description
ddx-core — engine-neutral symbolic differentiation of SQL scalar
expressions. The v1 core of ddx:
write calculus directly in SQL and let the engine evaluate the derivative
per row, the relational equivalent of jax.vmap(jax.grad(f)).
SELECT i, grad(x * y, x) AS dfdx, grad(x * y, y) AS dfdy FROM ggrad/jvp are markers, not row functions: they carry a
differentiation request through parsing and are always rewritten away
before execution. Ddx::rewrite_sql is the whole path — find every
marker, differentiate what it wraps, splice the derivative back by source
span, return plain SQL.
The engine differentiates sqlparser::ast::Expr directly — there is no
bespoke IR and no adapter layer; the AST is the IR (design.md §3.2). The
single load-bearing dependency is sqlparser, which is re-exported
(see below) so downstream adapters cannot accidentally link a mismatched
version.
§What v1 supports
+ - * /; the unary chain rule for the trig / inverse-trig / exp / log /
hyperbolic set plus abs; power with a constant base or exponent;
higher-order via nesting; through-aggregate via linearity
(AVG(grad(loss, theta))). Anything else is a typed DiffError, never a
silently-wrong number (design principle 5).
Scalar vjp is deliberately not part of the surface: the name is
reserved for the query-level reverse-mode operation in
ddx-ad (design.md §3.6, §4, decision Q7).
§sqlparser version policy
ddx-core’s public API takes and returns sqlparser::ast::Expr, so a
sqlparser bump is a breaking release of ddx-core. The version is pinned
exactly (see Cargo.toml) and re-exported here as crate::sqlparser:
always reach for sqlparser types through this re-export so your build
links the same version the engine was compiled against (design.md §6, G2).
Re-exports§
pub use sqlparser;
Modules§
- build
- Smart constructors for building derivative expressions — useful when writing
a custom
Rule, which returnsf'(u)as ansqlparser::ast::Expr.
Structs§
- ColRef
- A column reference: an optional qualifier and a name, taken straight off the
AST. Stores
sqlparserIdents (which keep quote-style) and compares with dialect-aware folding, never raw-string equality. - Ddx
- The ddx v1 differentiation engine.
- Explain
Step - One marker and the derivative SQL it rewrites to (part of an
Explanation). - Explanation
- A human-inspectable account of what
crate::Ddx::rewrite_sqlwould do to a statement, produced bycrate::Ddx::explain— so a user can see the derivative SQL before running anything. Inspect the fields directly, or print the whole thing (Display) for a readable summary. - Rule
Registry - A registry of differentiation rules, keyed by (lower-cased) function name.
Enums§
- Diff
Error - An error produced while differentiating or rewriting SQL.
- Ident
Casing - How a dialect folds identifiers for case-insensitive comparison.
- Match
- Whether a column occurrence is the differentiation variable, and if its
identity relative to
wrtcould be established syntactically at all.