Batch 4 of expansion-v2. All deterministic/offline/std-only (Rust) or
graceful-absence (Python), with honest boundary specs.
crates/lawsynth-jacobian (new): symbolic analytic Jacobian J[i][j]=∂f_i/∂x_j
from a discovered vector field's expression trees, for stiff integration and
local stability. Exact sum/product/quotient/chain/power rules over the expr IR;
a non-differentiable node is a typed error, never a silent zero (its power rule
also fixes a NaN the expr crate's naive log-based rule hits on negative bases).
Symbolic result cross-checked against lawsynth-differentiate finite differences
to <=1e-6. 24 tests.
crates/lawsynth-control (new): SINDYc controlled discovery for forced systems
ẋ=f(x,u). Augmented library Θ(x,u) via lawsynth-features (control-only and
state×control cross terms); targets from differentiating a state-only
sub-dataset so controls are never differentiated and never predicted. Recovers
a forced oscillator to ~1e-5; a states-only refit leaves control variance
unmodelled (~8e6x worse RSS), and a constant control is honestly unidentifiable
(persistent-excitation limit). 25 tests.
crates/lawsynth-discovery template priors: declarative grammar constraints
(max degree, allowed variables/kinds, forbid interactions, max active terms,
require a kind) applied as a deterministic hard filter over candidate terms
before the sparse solve, with a full drop report. Default None is byte-identical
to prior behavior; a prior that excludes the truth yields an honest zero law,
never fabricated structure. 29 tests.
python/lawsynth tracking.py (new): MLflow / W&B experiment-tracking interop.
Dep-free deterministic RunRecord anchor (sorted-key JSON, byte-stable) plus
log_to_mlflow/log_to_wandb that lazily import the backend and raise
MissingDependencyError (subclasses ImportError) when absent. Only logs metrics
that genuinely exist on the result — no fabricated mdl/seed/timing; callers pass
measured values via extra_metrics. 21 tests + 2 honest skips; SDK suite 94 pass.
specs/{analytic-jacobian,controlled-discovery,template-priors}: boundary specs.
Template priors boundary (v2-A)
This directory specifies grammar-constrained candidate libraries — the
declarative template priors implemented in crates/lawsynth-discovery
(template.rs, wired through execute.rs). It is a boundary specification in
the house style: it states what a conforming implementation MUST do, and —
crucially — what a prior is and is not allowed to claim.
Motivation
Sparse regression (SINDy) and symbolic search recover a law by selecting terms
from a fixed candidate library Θ(X). The larger and less structured that
library, the harder identification becomes: irrelevant columns invite spurious
selections, inflate variance, and blur the Pareto frontier. Symbolic-regression
tools (e.g. PySR) let a user impose templates / constraints — "the law is a
rational function", "no cross terms", "these variables only" — that shrink the
search space using a physical or domain prior.
LawSynth encodes the same idea as a template prior: a declarative, immutable description of which candidate terms are admissible. It is applied as a deterministic hard filter to the materialised feature library before the sparse solve, so the solver only ever sees terms the prior permits.
What a prior IS
A template prior is a HARD admissibility filter over candidate TERMS. The contract is:
- It restricts the candidate library, nothing more. A term the filter drops can never appear in a discovered law. A term the filter keeps is merely offered to the solver — the sparse solve may still zero its coefficient.
- It is not a soft penalty. There is no weight, temperature, or score nudge. A term is either admissible or it is not.
- It is not a proof about the truth. A prior expresses the user's stated assumption about the law's form. If the prior excludes a term the true law needs, discovery cannot recover that law — that non-recovery is the honest, enforced consequence of the assumption, not a bug.
- Every drop is recorded. Applying a prior produces a
TemplateFilterReportlisting every dropped term and the single reason it was dropped. A prior MUST NOT silently narrow the search; the report makes every application auditable.
Requirements
- Determinism & offline. The filter is a pure function of
(candidate terms, prior). It reads no clock, draws no randomness, and iterates only in stable slice order (never hashmap iteration order). Identical inputs MUST yield a bit-identical admissible set and report. The crate is std-only with internal path dependencies;net.offline = true. - Per-term rules, fixed evaluation order. Each candidate term is tested against the enabled rules in the order: total degree, allowed variables, allowed kinds, forbid-interactions. The first violated rule is the recorded drop reason, so reports are deterministic and never double-count a term.
- Total-degree definition. Total degree is defined recursively: a constant is
0, a variable is1, a product adds the degrees of its factors, a sum or quotient takes the max of its sides, an integer power multiplies, and a transcendental (sin,cos,exp,log, negate) takes the degree of its argument. Thusx·yand the bounded rationalx/(1+x²)both have degree2, andsin(x)has degree1. The capmax_total_degree(d)admits only terms of degree≤ d. - Kind classification is total and priority-ordered. Every term maps to
exactly one
TermKind:Rationalif it contains any division, elseTrigonometricif it contains a sine/cosine, elseExponentialif it contains an exp/log, elseConstantif it has no variables, elsePolynomial.allowed_kinds(K)admits only terms whose kind is inK. - Interactions. An interaction (cross) term is any term referencing two or
more distinct variables.
forbid_interactionsdrops exactly those, keeping single-variable and constant terms. - Active-term cap.
max_active_terms(n)retains the firstnotherwise admissible terms in the library's own deterministic order (which for the standard polynomial library is ascending degree — the simplest terms) and drops the rest asMaxActiveExceeded. Because a discovered law's active terms are a subset of the candidates, this bounds the law to at mostnactive terms. The cap is applied after the per-term rules so it counts only admissible terms. - Required kinds are checked against the final admitted set.
required_kindsasserts that the admitted candidate set contains at least one term of each required kind. If it does not — because the base library had none, or every one was dropped by another rule or the active-term cap — the prior is unsatisfiable and the filter fails withTemplateError::UnsatisfiableRequiredKind. This is checked last, so conflicts with any other rule surface honestly rather than silently. - Backward compatibility. The prior is opt-in via
DiscoveryConfig::template_prior: Option<TemplatePrior>. The defaultNoneadmits every candidate term; discovery is then byte-identical to the pre-template pipeline. SupplyingTemplatePrior::unconstrained()is equivalent in output (the discovered world matches the no-prior run) but additionally emits a report recording zero drops.
Where the filter applies
The prior is applied once, in run_discovery, immediately after the feature
library is materialised (polynomial + optional trigonometric + optional rational)
and evaluated, and before any per-state sparse fit. The admitted column set is
intersected, per state, with the (independent) dimensional-pruning admissibility
so the two filters compose without either overriding the other. The resulting
TemplateFilterReport is surfaced on DiscoveryResult::template_filter (None
on the default path).
Honest scope & limits
- A prior can only exclude the truth, never supply it. If the true law
requires a term the prior forbids, the constrained fit returns whatever best
fits within the admitted set — and when the admitted set is empty for a state,
the implementation emits an honest zero law (
0) rather than fabricating structure. Recovery of an excluded law is impossible by construction. required_kindsconstrains the candidate set, not the selection. Requiring a kind guarantees the solver is offered such a term; it does not guarantee the final law retains one (the sparse threshold may still zero it). This is the strongest guarantee a pre-solve candidate filter can honestly make; the implementation MUST NOT claim the selected law contains the required kind.max_active_termstruncates by library order. It bounds active-term count by dropping later-ordered candidates. If the true term falls outside the firstn, it is dropped (and recorded) and cannot be recovered — the cap is a simplicity prior, not a guarantee that the bestnterms are kept.
Non-goals
- No soft/penalised constraints, no learned or data-adaptive templates, no automatic prior inference — a prior is supplied by the user as data.
- No new candidate families: the filter only removes terms from the existing library; it never synthesises terms the base library did not generate.
- No network or platform service; the filter is a pure in-process function.