Agenda-based Deduction¶
The concrete chart implementation used for DSL-compiled weighted
deductions. DeductionSystem combines an axiom injector, a rule
system, a semiring, and an agenda schedule in an nn.Module.
DeductionSystem.__call__ returns the differentiable ChartView
presheaf.
For fitting, sampling, and the NUTS wrapper, see
api/stochastic/deduction.
Item algebra¶
Items, patterns, and bindings are plain tuples and dictionaries; these aliases name their roles in the signatures below.
Stochastic morphisms: Markov kernels over finite sets.
This module provides the probabilistic layer for quivers, implementing the category FinStoch of finite sets and stochastic maps (Markov kernels). This is the Kleisli category of the Giry monad restricted to finite sets, where:
- Objects are finite sets (same as the base category).
- Morphisms A -> B are stochastic matrices: tensors of shape (|A|, |B|) whose rows sum to 1.
- Composition is standard matrix multiplication.
- Identity is the Kronecker delta.
The package also re-exports MarkovAlgebra and its singleton
MARKOV from quivers.core.algebras, the algebra these morphisms
compose under.
Submodules
morphisms : StochasticMorphism, CategoricalMorphism families : Discretized distribution families transforms : condition, mix, factor, normalize queries : prob, marginal_prob, expectation giry : GiryMonad, FinStoch categories : Category types including atoms, slashes, products, unit, modals semiring : Chart semiring abstractions (LogProb, Viterbi, Boolean, Counting) schema : Composable rule schemas (functors CategorySystem -> RuleSystem) rules : Rule systems and the CCG / Lambek presets span : Span-based CKY components (LexicalAxiom, BinarySpanDeduction, etc.) parsers, ccg, lambek : Chart parsers inside : The inside algorithm over a rule system agenda : The agenda-driven weighted-deduction engine effect_lifts : Effect-lifted rule schemas for deduction systems deduction : Abstract weighted deductive system framework and its operations stdlib : Pre-registered deduction systems
Item
module-attribute
¶
An item is a tuple of (constructor_name, *arguments).
The constructor name disambiguates item shapes; the remaining
slots are the item's payload. Arguments may be other items
(structural), strings (atoms), integers (positions / cardinals),
or Wildcard placeholders in patterns.
Pattern
module-attribute
¶
A pattern is an item-shaped tuple that may contain Wildcard
positions. A pattern matches an item if (a) the constructor name
matches, (b) the arities match, (c) each non-wildcard slot is
structurally equal to the corresponding item slot, and (d) all
wildcards with the same name bind to equal values.
Bindings
module-attribute
¶
A bindings environment maps wildcard variable names to the values they captured during pattern-matching.
agenda
¶
Agenda-based weighted-deduction engine.
A general framework for evaluating weighted deductive systems by
agenda-driven semi-naïve enumeration. Subsumes CKY, Earley,
Viterbi, A* parsing, Knuth's algorithm, semi-naïve Datalog
evaluation, and bidirectional MLTT type-checking under one
runtime, parameterized by an Item algebra, a list of
arity-n InferenceRule hyperedges, a ChartSemiring,
an Agenda data structure, a priority function, and a
goal predicate.
Categorical denotation: the chart is the least pre-fixed point of the rule-system functor
.. math::
F : \mathbf{Set}^{I^{\mathrm{op}}}_{K} \to \mathbf{Set}^{I^{\mathrm{op}}}_{K}
in the :math:K-enriched lattice of charts (Tarski-Knaster). The
chart is the :math:K-presheaf :math:I^{\mathrm{op}} \to K
assigning the aggregate inside weight to each item. The agenda is
an operational realisation of the fixed-point computation; the
strategy-independence theorem (Goodman 1999 §3) guarantees that
the chart's final value is independent of the agenda discipline
when the semiring is idempotent.
References
- Shieber, Schabes & Pereira (1995) "Principles and Implementation of Deductive Parsing." Journal of Logic Programming 24(1-2):3-36. doi:10.1016/0743-1066(95)00035-I
- Pereira & Warren (1983) "Parsing as Deduction." Proceedings of the 21st Annual Meeting of the ACL, pp. 137-144. doi:10.3115/981311.981338
- Knuth (1977) "A Generalization of Dijkstra's Algorithm." Information Processing Letters 6(1):1-5. doi:10.1016/0020-0190(77)90002-3
- Goodman (1999) "Semiring Parsing." Computational Linguistics 25(4):573-605. https://aclanthology.org/J99-4004/
- Klein & Manning (2001) "Parsing and Hypergraphs." Proceedings of IWPT, pp. 123-134. doi:10.1007/1-4020-2295-6_18
- McAllester (2002) "On the Complexity Analysis of Static Analyses." Journal of the ACM 49(4):512-537. doi:10.1145/581771.581774
- Nederhof (2003) "Weighted Deductive Parsing and Knuth's Algorithm." Computational Linguistics 29(1):135-143. doi:10.1162/089120103321337467
- Eisner, Goldlust & Smith (2005) "Compiling Comp Ling: Practical Weighted Dynamic Programming and the Dyna Language." Proceedings of HLT-EMNLP, pp. 281-290. https://aclanthology.org/H05-1036/
- Eisner & Blatz (2007) "Program Transformations for Optimization of Parsing Algorithms and other Weighted Logic Programs." Proceedings of the 11th Conference on Formal Grammar.
Wildcard
dataclass
¶
Pattern-position wildcard.
A wildcard matches any value in the corresponding slot and
binds it to name for use in the conclusion. Two wildcards
with the same name in a single rule's premise list must
bind to equal values (variable-sharing).
InferenceRule
dataclass
¶
InferenceRule(name: str, premises: tuple[Pattern, ...], conclusion: Pattern, weight_fn: Callable[[Bindings, tuple, ChartSemiring], Any] | None = None, side_condition: Callable[[Bindings], bool] | None = None)
A weighted inference rule, that is, an arity-n hyperedge.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Rule identifier (used for diagnostics and provenance).
TYPE:
|
premises
|
Patterns the rule's antecedents must match.
TYPE:
|
conclusion
|
Pattern of the item the rule produces. Wildcards must appear in the premises (so they are bound by the time the conclusion is constructed).
TYPE:
|
weight_fn
|
Function
TYPE:
|
side_condition
|
Predicate
TYPE:
|
Chart
¶
Bases: ABC
A K-valued presheaf on the item algebra.
Categorically, a chart is the K-presheaf
:math:C : I^{\mathrm{op}} \to K produced by the deduction
system on an input. The chart is the least pre-fixed point of
the rule-system functor; operationally, the agenda engine
populates it bottom-up.
Concrete subclasses choose a storage strategy: dense tensor-indexed (for CKY-style spans), sparse hash-indexed (for Datalog atoms), or term-structural (for MLTT judgments).
lookup
abstractmethod
¶
Enumerate (item, weight) pairs matching a pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
The pattern to match stored items against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Iterable of (Item, torch.Tensor)
|
The matching items with their weights. |
Source code in src/quivers/stochastic/agenda.py
insert_or_aggregate
abstractmethod
¶
insert_or_aggregate(item: Item, weight: Tensor, semiring: ChartSemiring) -> bool
Insert or aggregate an item's weight.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
The item to store.
TYPE:
|
weight
|
The weight to insert, or to aggregate with the stored
weight under
TYPE:
|
semiring
|
The semiring whose
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
Source code in src/quivers/stochastic/agenda.py
get
abstractmethod
¶
items
abstractmethod
¶
Enumerate all (item, weight) pairs in the chart.
| RETURNS | DESCRIPTION |
|---|---|
Iterable of (Item, torch.Tensor)
|
Every stored item with its weight. |
Source code in src/quivers/stochastic/agenda.py
HashChart
¶
Bases: Chart
Dictionary-backed chart for arbitrary item algebras.
Stores items as keys in a Python dict; supports linear-scan
pattern matching. Suitable for Datalog atoms, MLTT
judgments, and any deduction whose items don't have a dense
integer encoding. Falls back to O(|chart| · |pattern|) match
cost per lookup; faster specializations should override
lookup with an indexed structure.
Weights are stored as torch.Tensor values; autograd
flows through insert_or_aggregate's
semiring.plus(torch.stack([…])) reduction, so the chart's
final values carry gradients with respect to any
requires_grad=True rule-weight parameters that fed into
the agenda.
| PARAMETER | DESCRIPTION |
|---|---|
tolerance
|
The smallest change in an item's weight that counts as an
update;
TYPE:
|
Source code in src/quivers/stochastic/agenda.py
lookup
¶
Scan the stored items for those matching a pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
The pattern to match stored items against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Iterable of (Item, torch.Tensor)
|
The matching items with their weights. |
Source code in src/quivers/stochastic/agenda.py
insert_or_aggregate
¶
insert_or_aggregate(item: Item, weight: Tensor, semiring: ChartSemiring) -> bool
Aggregate weight into the chart at item.
For non-idempotent semirings (LogProb, Counting, Inside)
with cyclic rule graphs, every re-derivation of an item via
a new path increases its weight via semiring.plus,
even when the item itself is already in the chart. With an
unconstrained cycle weight, this sequence is unbounded:
either the cycle is contractive (cycle log-weight :math:<
0), in which case the chart's weight converges to a
finite Kleene-star limit; or the cycle is non-contractive
(:math:\ge 0), in which case the chart total is :math:+
\infty and the model is mathematically ill-posed.
The chart makes this distinction observable by terminating
the agenda when the per-item update falls below the
tolerance. The default tolerance 0.0 treats any change
as an update; positive tolerances expose convergent cyclic
fixed points while still routing divergent systems through
the agenda's max_iterations safety net.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
The item to store.
TYPE:
|
weight
|
The weight to insert or aggregate.
TYPE:
|
semiring
|
The semiring whose
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
Source code in src/quivers/stochastic/agenda.py
get
¶
items
¶
Enumerate all stored (item, weight) pairs.
| RETURNS | DESCRIPTION |
|---|---|
Iterable of (Item, torch.Tensor)
|
Every stored item with its weight. |
ChartView
¶
A first-class, differentiable view onto a chart.
Wraps a Chart produced by an agenda run and exposes
the user-facing presheaf-evaluation operations:
weight: query the aggregated weight at a single ground item; returns a differentiabletorch.Tensor.enumerate: enumerate items matching a pattern with their weights.derivations: extract the derivation forest at an item (under the derivation semiring; for the basic Boolean / LOG_PROB / Viterbi semirings, returns the flat list of matched derivations as a placeholder).goal_weight: return the weight at the goal items identified at run time.
Categorically, the chart is the K-presheaf
:math:I^{\mathrm{op}} \to K produced by the deduction
system; ChartView's methods are presheaf evaluations.
Gradients flow through these operations because the
underlying tensors carry requires_grad from the rule
weights.
| PARAMETER | DESCRIPTION |
|---|---|
result
|
The agenda run to view.
TYPE:
|
Source code in src/quivers/stochastic/agenda.py
attached_loss
property
¶
attached_loss: Tensor | None
The sum of rule-attached and chart-attached loss values
fired during this deduction's run, or None if no losses
were declared at those sites.
goal_items
property
¶
List of (item, weight) pairs matching the goal predicate.
weight
¶
Return the aggregated weight at a concrete item.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
A ground item.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The item's differentiable weight. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the item was never derived. |
Source code in src/quivers/stochastic/agenda.py
try_weight
¶
Return the weight at item, or a fallback if it is absent.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
A ground item.
TYPE:
|
default
|
The value to return for an absent item;
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The item's weight, |
Source code in src/quivers/stochastic/agenda.py
enumerate
¶
Enumerate (item, weight) pairs matching pattern.
Wildcards in pattern (instances of Wildcard)
match any slot value.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
The pattern to match.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list of (Item, torch.Tensor)
|
The matching items with their differentiable weights. |
Source code in src/quivers/stochastic/agenda.py
embedding
¶
Return the vector embedding of item under the deduction's
attached encoder.
Requires the originating DeductionSystem to carry an
_item_encoder attribute (set by the DSL compiler when
the deduction's body declares encoder C). Items are
converted to quivers.structural.Term form on the fly.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
The item to embed.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The encoder's embedding of the item. |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the run carries no encoder. |
Source code in src/quivers/stochastic/agenda.py
derivations
¶
Return the items of the chart in which item was derived.
The chart records only the aggregate weight at each item,
so this returns the chart's item set as a flat enumeration
when item is in the chart. The full derivation forest
(a tree-structured object whose leaves are axioms and whose
internal nodes are rule firings) is recoverable by running
the agenda with a derivation semiring.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
The item whose derivations to return.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list of Item
|
Every item in the chart, or an empty list when |
Source code in src/quivers/stochastic/agenda.py
goal_weight
¶
goal_weight() -> Tensor
Aggregate weight over all goal items.
If a single goal item was identified, returns its weight
directly; otherwise aggregates via the semiring's
plus reduction (the standard parse-as-marginal
computation).
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The aggregated goal weight, or the semiring's zero when no goal item was derived. |
Source code in src/quivers/stochastic/agenda.py
Agenda
¶
Bases: ABC
A queue of items pending further inference.
The agenda discipline (FIFO / LIFO / priority) determines the evaluation order; correctness is independent of discipline for idempotent semirings (Goodman 1999 §3) but efficiency depends on it (McAllester 2002).
push
abstractmethod
¶
pop
abstractmethod
¶
Remove and return the next item under this discipline.
| RETURNS | DESCRIPTION |
|---|---|
tuple of (Item, torch.Tensor)
|
The next item and its pending weight. |
empty
abstractmethod
¶
Whether no items are pending.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
bind_semiring
¶
bind_semiring(semiring: ChartSemiring) -> None
Give the agenda access to the engine's semiring.
run_agenda calls this once, before pushing the axioms.
Disciplines that can exploit the binding override it; for
instance, FIFOAgenda merges pending contributions
to the same item via semiring.plus. The default ignores
the binding.
| PARAMETER | DESCRIPTION |
|---|---|
semiring
|
The engine's semiring.
TYPE:
|
Source code in src/quivers/stochastic/agenda.py
FIFOAgenda
¶
Bases: Agenda
First-in-first-out agenda (semi-naïve Datalog discipline).
The agenda processes items in the order they were derived. Correct for any monotone semiring; the canonical choice for Datalog and Earley parsing.
Once a semiring is bound (bind_semiring, which the engine does
on entry), a contribution pushed for an item that is already
pending merges into that item's single queue entry via
semiring.plus. Semiring distributivity makes the merge exact:
firing a rule once on the merged contribution pushes the same
total mass downstream as firing it once per contribution. Without
merging, a cyclic rule graph re-enqueues every contribution
separately, and the number of pending entries grows geometrically
with derivation depth even when the weighted fixed point
converges.
Source code in src/quivers/stochastic/agenda.py
bind_semiring
¶
bind_semiring(semiring: ChartSemiring) -> None
Bind the semiring that merges pending contributions.
| PARAMETER | DESCRIPTION |
|---|---|
semiring
|
The engine's semiring.
TYPE:
|
push
¶
Add an item and its weight to the agenda.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
The derived item.
TYPE:
|
weight
|
The weight contributed by this derivation.
TYPE:
|
Source code in src/quivers/stochastic/agenda.py
pop
¶
Remove and return the next item under this discipline.
| RETURNS | DESCRIPTION |
|---|---|
tuple of (Item, torch.Tensor)
|
The next item and its pending weight. |
Source code in src/quivers/stochastic/agenda.py
empty
¶
Whether no items are pending.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
LIFOAgenda
¶
Bases: Agenda
Last-in-first-out agenda (depth-first proof-search discipline).
The agenda processes items in reverse-derivation order. Suitable for goal-directed search like Agda elaboration and Twelf-style MLTT type-checking, where depth-first proof construction is the natural strategy.
Source code in src/quivers/stochastic/agenda.py
push
¶
pop
¶
Remove and return the next item under this discipline.
| RETURNS | DESCRIPTION |
|---|---|
tuple of (Item, torch.Tensor)
|
The next item and its pending weight. |
empty
¶
Whether no items are pending.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
PriorityQueueAgenda
¶
Bases: Agenda
Priority-queue agenda parameterized by a priority function.
Items are processed in decreasing priority order. Used by Knuth's algorithm (priority = current best score), A* parsing (priority = g + h with admissible h), and any best-first chart algorithm.
| PARAMETER | DESCRIPTION |
|---|---|
priority_fn
|
TYPE:
|
Source code in src/quivers/stochastic/agenda.py
push
¶
Add an item and its weight to the agenda.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
The derived item.
TYPE:
|
weight
|
The weight contributed by this derivation.
TYPE:
|
Source code in src/quivers/stochastic/agenda.py
pop
¶
Remove and return the next item under this discipline.
| RETURNS | DESCRIPTION |
|---|---|
tuple of (Item, torch.Tensor)
|
The next item and its pending weight. |
Source code in src/quivers/stochastic/agenda.py
empty
¶
Whether no items are pending.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
AgendaResult
dataclass
¶
AgendaResult(chart: Chart, semiring: ChartSemiring, goal_items: list[tuple[Item, Tensor]] = list(), iterations: int = 0, encoder: Encoder | None = None, attached_loss: Tensor | None = None)
The chart produced by an agenda-driven deduction.
| ATTRIBUTE | DESCRIPTION |
|---|---|
chart |
The final K-presheaf on the item algebra.
TYPE:
|
semiring |
The semiring used for weight aggregation.
TYPE:
|
goal_items |
Items in the chart matching the goal predicate, with their final aggregated weights.
TYPE:
|
iterations |
Number of agenda steps consumed (diagnostic).
TYPE:
|
DeductionSystem
dataclass
¶
DeductionSystem(rules: tuple[InferenceRule, ...], semiring: ChartSemiring, axiom_injector: Callable[[Any], list[tuple[Item, Tensor]]], goal: Callable[[Item], bool], agenda_factory: Callable[[], Agenda] = FIFOAgenda, chart_factory: Callable[[], Chart] = HashChart, max_iterations: int = 100000, tolerance: float = 0.0)
A weighted deductive system parameterized over its components.
The system is parameterized by:
- An item algebra (implicit in the patterns the rules use).
- A list of arity-n
InferenceRulehyperedges. - A
ChartSemiringfor weight aggregation. - An axiom injector
In -> [(Item, Weight)]producing the input's lexical / boundary items. - A goal predicate
Item -> boolselecting the result items. - (Optional) a chart constructor and an agenda strategy.
The same data structure subsumes CKY (FIFO agenda, span items, Boolean / inside semiring), Viterbi (priority agenda with the current weight as priority, max-times semiring), A* parsing (priority agenda with an admissible heuristic, tropical semiring), MLTT type-checking (LIFO agenda, judgment items, Boolean semiring), and weighted Datalog (FIFO, atoms, any naturally-ordered semiring).
run
¶
run(input_value: Any) -> AgendaResult
Run the deduction system on an input value.
Injects the input's axioms, runs the agenda to fixed point, attaches the item encoder when one is set, and sums any rule-attached and chart-attached losses.
| PARAMETER | DESCRIPTION |
|---|---|
input_value
|
The input the axiom injector reads.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AgendaResult
|
The completed chart, its goal items, and any attached loss. |
Source code in src/quivers/stochastic/agenda.py
1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 | |
parameters
¶
Yield every learnable parameter owned by this system.
Walks the optional _axiom_module (lexicon log-weights)
and _rule_module (per-rule, per-binding log-weights)
submodules attached by the compiler. The recurse flag
is the standard torch.nn.Module.parameters signature
so user code can pass a DeductionSystem anywhere a
nn.Module parameter iterator is expected.
| PARAMETER | DESCRIPTION |
|---|---|
recurse
|
Whether to include parameters of nested submodules.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Iterable of torch.nn.Parameter
|
The learnable parameters. |
Source code in src/quivers/stochastic/agenda.py
named_parameters
¶
Yield (name, parameter) pairs over all learnable parameters.
| PARAMETER | DESCRIPTION |
|---|---|
prefix
|
A prefix prepended to every parameter name.
TYPE:
|
recurse
|
Whether to include parameters of nested submodules.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Iterable of (str, torch.nn.Parameter)
|
The named learnable parameters. |
Source code in src/quivers/stochastic/agenda.py
make_wildcard
¶
make_wildcard(name: str) -> Wildcard
Build a fresh wildcard with the given variable name.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The pattern variable the wildcard binds.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Wildcard
|
The wildcard. |
Source code in src/quivers/stochastic/agenda.py
instantiate
¶
Substitute wildcards in a pattern with their bound values.
The pattern may be a bare Wildcard (treated as "the
entire item is the wildcard"), a structural tuple, or a leaf
value (returned unchanged). Recursion runs over tuple
children.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
The pattern to instantiate.
TYPE:
|
bindings
|
Values for the pattern's wildcards.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Item
|
A concrete item with no wildcards. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If a wildcard in the pattern has no binding. |
Source code in src/quivers/stochastic/agenda.py
match
¶
Match an item against a pattern.
Wildcards bind the values at their positions; a wildcard
already bound in bindings (or earlier in the pattern) must
see an equal value. Tuples match slot by slot when their
lengths agree, and other values match by equality.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
The pattern to match.
TYPE:
|
item
|
The item to match against.
TYPE:
|
bindings
|
Bindings to extend;
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Bindings or None
|
The extended bindings, or |
Source code in src/quivers/stochastic/agenda.py
run_agenda
¶
run_agenda(axioms: Iterable[tuple[Item, Tensor]], rules: Iterable[InferenceRule], semiring: ChartSemiring | None = None, agenda: Agenda | None = None, goal: Callable[[Item], bool] | None = None, max_iterations: int = 100000, chart: Chart | None = None, rule_callback: Callable[[str, list[tuple[Item, Tensor]], Item, Tensor], None] | None = None) -> AgendaResult
Run the agenda-driven deduction engine to fixed point.
Categorical denotation: returns the least pre-fixed point of
the rule-system functor on the input axioms. The
strategy-independence theorem (Goodman 1999) guarantees that
the chart's final value is independent of the agenda
discipline when semiring is idempotent.
Algorithm (Shieber-Schabes-Pereira 1995, Fig. 2 with semiring-weighted aggregation per Goodman 1999):
- Push every axiom onto the agenda.
- While the agenda is non-empty:
a. Pop an item.
b. Insert-or-aggregate into the chart.
c. If the chart's weight changed, fire every rule for which
the popped item is a premise: scan the chart for matching
siblings, compute the conclusion's weight via the rule's
weight_fn, and push the conclusion onto the agenda. - Return the chart with all items that match
goal.
| PARAMETER | DESCRIPTION |
|---|---|
axioms
|
Initial items with their input-derived weights.
TYPE:
|
rules
|
The deduction system's hyperedges.
TYPE:
|
semiring
|
Weight aggregation. Defaults to log-prob.
TYPE:
|
agenda
|
Evaluation strategy. Defaults to FIFO (semi-naïve).
TYPE:
|
goal
|
Predicate selecting result items. Defaults to "every item".
TYPE:
|
max_iterations
|
Safety bound on agenda steps; raises if exceeded.
TYPE:
|
chart
|
Initial chart (defaults to empty
TYPE:
|
rule_callback
|
Called as
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AgendaResult
|
The final chart, the goal items, and the step count. |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the agenda runs for more than |
Source code in src/quivers/stochastic/agenda.py
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 | |
cky_agenda
¶
cky_agenda() -> Agenda
The CKY (bottom-up sweep) agenda: semi-naïve FIFO.
For context-free + Boolean / inside semirings, FIFO order
suffices to reach the chart's fixed point in
:math:O(n^3 \cdot |R|) time (McAllester 2002).
| RETURNS | DESCRIPTION |
|---|---|
Agenda
|
A fresh |
Source code in src/quivers/stochastic/agenda.py
earley_agenda
¶
earley_agenda() -> Agenda
The Earley (predict / scan / complete) agenda: FIFO.
Earley's algorithm is identical to FIFO agenda-driven deduction over the predict / scan / complete items (Pereira & Warren 1983).
| RETURNS | DESCRIPTION |
|---|---|
Agenda
|
A fresh |
Source code in src/quivers/stochastic/agenda.py
viterbi_agenda
¶
Viterbi-style best-first agenda.
Priorities are the current best weight in the
:math:(\max, \times) semiring; the agenda is a priority
queue. Equivalent to Knuth's algorithm when the semiring is
superior (Nederhof 2003).
| PARAMETER | DESCRIPTION |
|---|---|
priority_fn
|
The priority of an item given its weight; higher pops first. |
| RETURNS | DESCRIPTION |
|---|---|
Agenda
|
A |
Source code in src/quivers/stochastic/agenda.py
astar_agenda
¶
A* parsing agenda (Klein & Manning 2003).
Priority is :math:g + h where :math:g is the current
accumulated cost and :math:h is an admissible heuristic on
the remaining cost. With an admissible :math:h, the agenda
enumerates items in optimal order (Knuth 1977).
| PARAMETER | DESCRIPTION |
|---|---|
g_plus_h
|
The priority |
| RETURNS | DESCRIPTION |
|---|---|
Agenda
|
A |
Source code in src/quivers/stochastic/agenda.py
knuth_agenda
¶
knuth_agenda() -> Agenda
Knuth's best-first hyperpath search.
Priority is the current chart weight (the item's best-so-far score). For a superior semiring, this is Dijkstra's algorithm on AND-OR hypergraphs (Knuth 1977; Nederhof 2003).
| RETURNS | DESCRIPTION |
|---|---|
Agenda
|
A |
Source code in src/quivers/stochastic/agenda.py
depth_first_agenda
¶
depth_first_agenda() -> Agenda
LIFO agenda: depth-first proof search (Agda / Twelf style).
| RETURNS | DESCRIPTION |
|---|---|
Agenda
|
A fresh |