jacopy.ExpansionEngine

class jacopy.ExpansionEngine(definitions=None, *, mode='efficient')

Bases: object

Apply registered Definition rules bottom-up to fix-point.

On each iteration expand_once() finds the leftmost-innermost matching site and rewrites it, recording a ProofStep. expand() loops until no definition fires. A max_steps guard protects against a misbehaving rule that produces an ever-growing expression.

The engine’s mode controls 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 their Definition.theorem_proof_builder() is invoked; the resulting sub-proof is attached under the step as children, exposing the derivation down to axioms.

Parameters:
__init__(definitions=None, *, mode='efficient')
Parameters:
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 definition to the rule list (and dispatch index).

with_mode(mode)

Return a new engine with the same definitions but a different mode.

Attributes

assembly_report

definitions

mode

owners

{tree-visible name: structure} for the owned rules of this engine.

version

Registration counter (changes whenever a rule is added).

register(definition)

Append definition to the rule list (and dispatch index).

Parameters:

definition (Definition)

Return type:

None

property version: int

Registration counter (changes whenever a rule is added).

property owners: dict

{tree-visible name: structure} for the owned rules of this engine.

with_mode(mode)

Return a new engine with the same definitions but a different mode.

Parameters:

mode (str)

Return type:

ExpansionEngine

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 ProofStep produced by the fired rule, or None when 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_slots tuple plus a with_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.

Parameters:

expr (Expr)

Return type:

Tuple[Expr, ProofStep | None]

expand(expr, *, max_steps=1024)

Apply definitions repeatedly until no rule fires.

Returns the fully expanded expression and the list of steps taken. Raises RuntimeError if the fix-point isn’t reached within max_steps iterations, that would indicate a cyclic or divergent rule set. (The default is 1024: a d² Palais double-expansion of a 5-form on 7 slots legitimately exceeds 256 rewrites; a true cycle still trips the bound, just later.)

Parameters:
Return type:

Tuple[Expr, List[ProofStep]]