Deduction Library¶
STDLIB_DEDUCTIONS holds ready-made DeductionSystem instances for standard
weighted deduction tasks: categorial grammar
recognition, type checking, Datalog closure, shortest
paths, hidden Markov models, and edit distance. A DSL parse(NAME) expression looks NAME up
there before any deduction the module declares. Each system fixes its semiring, so reachability, a
path cost, and a log weight are different outputs.
stdlib
¶
Pre-registered library of weighted deduction systems.
Ships agenda-engine DeductionSystem instances for standard
specializations from the semiring-parsing and agenda-driven-deduction
literature (Shieber, Schabes, and Pereira 1995; Goodman 1999; Klein and
Manning 2001; Nederhof 2003; Eisner and Blatz 2007).
Each entry is a DeductionSystem: a rule set, a semiring, an axiom
injector, a goal predicate, and an agenda factory (the item algebra is
implicit in the rules' patterns, and the chart is the default hash
chart). Users invoke them as
.. code-block:: python
from quivers.stochastic.stdlib import CCG, AB, MLTT, Datalog
view = CCG(lexical_axioms)
weight = view.goal_weight()
A system maps its axioms to a chart: the weight of each derivable item, the semiring sum over the item's derivations of the product of their weights.
CCG
module-attribute
¶
CCG = DeductionSystem(rules=tuple(_ccg_rules()), semiring=LOG_PROB, axiom_injector=_copy_axioms, goal=_is_sentence, agenda_factory=cky_agenda)
Combinatory categorial grammar: application and harmonic composition over ("span", i, j, category) items, log-probability semiring, CKY agenda; the goal is S over the whole input.
AB
module-attribute
¶
AB = DeductionSystem(rules=tuple(_application_rules()), semiring=LOG_PROB, axiom_injector=_copy_axioms, goal=_is_sentence, agenda_factory=cky_agenda)
AB (Ajdukiewicz-Bar-Hillel) categorial grammar: forward and backward application only, over ("span", i, j, category) items, log-probability semiring, CKY agenda; the goal is S over the whole input.
STLC
module-attribute
¶
STLC = DeductionSystem(rules=tuple(_stlc_rules()), semiring=BOOLEAN, axiom_injector=_copy_axioms, goal=lambda item: isinstance(item, tuple) and item[0] in ('synth', 'check'), agenda_factory=depth_first_agenda)
Bidirectional type checking for the simply-typed lambda calculus, Boolean semiring.
MLTT
module-attribute
¶
MLTT = DeductionSystem(rules=tuple(_mltt_rules()), semiring=BOOLEAN, axiom_injector=_copy_axioms, goal=lambda item: isinstance(item, tuple) and item[0] == 'judges', agenda_factory=depth_first_agenda, max_iterations=10000)
Bidirectional type checking for a fragment of Martin-Löf dependent type theory, Boolean semiring, with a bound on term depth.
Datalog
module-attribute
¶
Datalog = DeductionSystem(rules=tuple(_datalog_transitive_closure_rules()), semiring=BOOLEAN, axiom_injector=_copy_axioms, goal=lambda item: isinstance(item, tuple) and item[0] == 'reach', agenda_factory=semi_naive_agenda)
Transitive closure of an edge relation by semi-naive Datalog evaluation, Boolean semiring.
Dijkstra
module-attribute
¶
Dijkstra = DeductionSystem(rules=tuple(_dijkstra_rules()), semiring=VITERBI, axiom_injector=_copy_axioms, goal=lambda item: isinstance(item, tuple) and item[0] == 'dist', agenda_factory=knuth_agenda)
Single-source shortest paths by Knuth's generalization of Dijkstra's algorithm, Viterbi semiring.
HMM
module-attribute
¶
HMM = DeductionSystem(rules=tuple(_hmm_forward_rules()), semiring=LOG_PROB, axiom_injector=_copy_axioms, goal=lambda item: isinstance(item, tuple) and item[0] == 'alpha', agenda_factory=cky_agenda)
The hidden Markov model forward algorithm over alpha items, log-probability semiring.
ViterbiHMM
module-attribute
¶
ViterbiHMM = DeductionSystem(rules=tuple(_hmm_forward_rules()), semiring=VITERBI, axiom_injector=_copy_axioms, goal=lambda item: isinstance(item, tuple) and item[0] == 'alpha', agenda_factory=cky_agenda)
The hidden Markov model Viterbi algorithm: the HMM rules under the Viterbi semiring.
EditDistance
module-attribute
¶
EditDistance = DeductionSystem(rules=tuple(_edit_distance_rules()), semiring=VITERBI, axiom_injector=_copy_axioms, goal=lambda item: isinstance(item, tuple) and item[0] == 'dist', agenda_factory=cky_agenda)
Levenshtein edit distance over dist alignment items, Viterbi semiring.
STDLIB_DEDUCTIONS
module-attribute
¶
STDLIB_DEDUCTIONS: dict[str, DeductionSystem] = {'CCG': CCG, 'AB': AB, 'STLC': STLC, 'MLTT': MLTT, 'Datalog': Datalog, 'Dijkstra': Dijkstra, 'HMM': HMM, 'ViterbiHMM': ViterbiHMM, 'EditDistance': EditDistance}
Mapping from name to pre-registered deduction system.
Compilation of a parse(NAME) expression in the DSL, or a
direct call from Python, resolves the name against this dict
first, then against any user-declared deductions in the
compiler's environment.