jacopy.ExpansionEngine¶
- class jacopy.ExpansionEngine(definitions=None, *, mode='efficient')¶
Bases:
objectApply registered
Definitionrules bottom-up to fix-point.On each iteration
expand_once()finds the leftmost-innermost matching site and rewrites it, recording aProofStep.expand()loops until no definition fires. Amax_stepsguard protects against a misbehaving rule that produces an ever-growing expression.The engine’s
modecontrols how theorem-classified definitions are recorded:"efficient", theorems fire like axioms; the resulting step is tagged"theorem"but carries no sub-proof, matching the “property taken as given” mode of the plan."foundational", theorems fire and theirDefinition.theorem_proof_builder()is invoked; the resulting sub-proof is attached under the step as children, exposing the derivation down to axioms.
- Parameters:
definitions (Optional[List[Definition]])
mode (str)
- __init__(definitions=None, *, mode='efficient')¶
- Parameters:
definitions (List[Definition] | None)
mode (str)
- Return type:
None
Methods
__init__([definitions, mode])expand(expr, *[, max_steps])Apply definitions repeatedly until no rule fires.
expand_once(expr)Apply a single rewrite at the leftmost-innermost matching site.
register(definition)Append
definitionto the rule list (and dispatch index).with_mode(mode)Return a new engine with the same definitions but a different mode.
Attributes
assembly_reportdefinitionsmode{tree-visible name: structure}for the owned rules of this engine.Registration counter (changes whenever a rule is added).
- register(definition)¶
Append
definitionto the rule list (and dispatch index).- Parameters:
definition (Definition)
- Return type:
None
- with_mode(mode)¶
Return a new engine with the same definitions but a different mode.
- Parameters:
mode (str)
- Return type:
- expand_once(expr)¶
Apply a single rewrite at the leftmost-innermost matching site.
Children are visited first, so the rule that fires is the one closest to the leaves. Returns the (possibly unchanged) expression and the
ProofStepproduced by the fired rule, orNonewhen no definition matches anywhere.Slot protocol: operator-like atoms that carry expressions in private slots (an algebroid bracket’s sections, a mapped section’s argument, …) may expose them via a
rewritable_slotstuple plus awith_slots(*subs)rebuilder. The engine recurses into those slots exactly like children, so rules fire inside opaque atoms — the structural fix for the slot-opacity limitation that would otherwise need targeted pre-passes.
- expand(expr, *, max_steps=1024)¶
Apply definitions repeatedly until no rule fires.
Returns the fully expanded expression and the list of steps taken. Raises
RuntimeErrorif the fix-point isn’t reached withinmax_stepsiterations, that would indicate a cyclic or divergent rule set. (The default is 1024: ad²Palais double-expansion of a 5-form on 7 slots legitimately exceeds 256 rewrites; a true cycle still trips the bound, just later.)