Expand description
Ordered n-ary rule-pattern layer for exact induction.
Generalizes the four fixed 2-body binary topologies to rule patterns over
heads of arity >= 1 with bodies of up to max_body_atoms atoms, where
every body-atom position binds either a head argument position or a
bounded, canonically-numbered existential join variable. The shipped
binary engine’s templates are exactly four members of this space at
head_arity = 2, two body atoms and one join variable — see
canonical_binary_pattern, which is the parity surface the general
enumeration is tested against.
This module is deliberately pure host-side: pattern types, canonical-form
validation and deterministic enumeration. Scoring the patterns on device
is a separate stage that consumes NaryRulePattern values as its rule
templates.
Three laws are enforced here rather than documented elsewhere:
-
Canonical form (join-variable naming). Join variables are numbered densely in first-appearance order across the body read left to right, so the ENUMERATOR never emits two patterns differing only by join-variable renaming — it does not need to filter them.
Note the exact scope: canonicality is a property of what
enumerate_patternsEMITS, not of the type.NaryRulePatternhas public fields, so a caller can hand-build a non-canonical alpha-twin, and the public flatten/score path will score it identically to its canonical form. That is safe (the score is the same), but it means alpha-duplicates are avoided by construction of the generator and REJECTED byNaryRulePattern::validate— not made unrepresentable by the type. Callers assembling patterns by hand own that obligation. -
Canonical form does NOT quotient atom order or multiplicity.
H :- A(x),B(x)andH :- B(x),A(x)are distinct members, as areH :- A(x)andH :- A(x),A(x). Semantically identical bodies score identically, tie perfectly in the reduction, can co-occupy top-K, and inflatetotal_scored. This matches the shipped binary engine, whose ordered(topology, L, R)grid likewise scores both orderings; a sorted-body canonical form would be a behavior change, not a bug fix. -
No silent truncation. The enumeration refuses with a typed error when the pattern space exceeds
max_patterns, and when the SEARCH exceedsmax_traversal_nodes; it never quietly caps. The two bounds are separate because the first bounds output and the second bounds work — a search that keeps nothing can still be enormous.
Structs§
- Body
Atom Pattern - One body atom: a candidate-relation slot plus its ordered bindings.
- Nary
Enumeration Config - Enumeration bounds for one n-ary induction request.
- Nary
Rule Pattern - A canonical n-ary rule pattern:
H(h0..h{a-1}) :- body....
Enums§
- Pattern
Var - A variable slot inside a body-atom binding pattern.
Functions§
- canonical_
binary_ pattern - The four shipped binary topologies expressed as n-ary patterns.
- enumerate_
patterns - Deterministically enumerate every well-formed canonical pattern.