Semirings as theory parameters¶
This page states what a deduction's semiring means, what an instance owes its theory, when a cyclic deduction is admitted, and why one chart in the free instance gives every other instance's answer. The surface is in the semirings reference.
1. The theories¶
std.semiring declares three theories over one sort W. Semiring has the
constants zero and one and the operations plus and times. Its laws make (W, plus, zero)
and (W, times, one) commutative monoids, make times distribute over plus, and make zero
annihilate. These are the laws a chart relies on (Goodman, 1999). The sum over a set of
derivations is independent of the order of enumeration because plus is associative and
commutative. The weight of a derivation is the product of its rule and input weights, independent
of how the derivation is split, because times is associative and commutative. And the chart may
multiply a shared sub-derivation's total into each use of it because times distributes over
plus.
ClosedSemiring adds an operation star with star(x) = one + x star(x): star(x) solves the
linear equation of a single repeated step. OmegaContinuousSemiring adds the Conway identities
which hold in every ω-continuous semiring, whose ω-chains have least upper bounds that the operations preserve. ω-continuity itself is not equational. The theory states the equational consequences that an instance can be checked against, and the property is part of the instance's evidence.
2. Instances and their laws¶
An instance semiring I : T = algebra A on C interprets W by the kernel carrier C and
interprets the operations by the shipped algebra A. Its star is A's closure of a
one-by-one matrix. Each law l = r of T with variables \(x_1, \dots, x_n\) is evaluated at
every assignment drawn from a finite set \(E\) of elements of C:
- for a finite carrier, \(E\) is the whole carrier, so the evaluation decides the law;
- for an infinite carrier, \(E\) is the algebra's units together with a fixed spread of elements that the carrier and the algebra hold.
A failure at any assignment refutes the instance, and the assignment is reported. A law that holds on \(E\) is established in two cases:
- \(E\) is the carrier;
- the law is a law of
std.semiringwhose counterpart in the law catalogue ofquivers.core.lawsthe algebra claims with a proof.
| Theory law | Catalogue law |
|---|---|
associativity, commutativity, and unit of plus and of times |
PLUS_ASSOCIATIVE, PLUS_COMMUTATIVE, PLUS_UNIT, TIMES_ASSOCIATIVE, TIMES_COMMUTATIVE, TIMES_UNIT |
distrib |
DISTRIBUTIVE |
annihilate |
ZERO_ANNIHILATES |
star_unfold |
STAR_LEAST_SOLUTION |
Any other law that holds on \(E\) is only tested, and the instance must assume it. Nothing tested
on a sample is recorded as established. A closure that has no value at an element of \(E\), such as
the log semiring's closure of a weight that is not below zero, refutes the closure laws. So
LogProb, Viterbi, and Counting are instances of Semiring only, while Boolean, decided
on its two elements, is an instance of OmegaContinuousSemiring.
3. A deduction in an instance¶
A deduction in the instance \(I\) elaborates to the computations described for
deductions. Their search,
collection, and settlement handlers carry \(I\)'s algebra and carrier as a
KernelSemiring. The answer is the inside weight of the
goal in \(I\): the sum, over the goal's derivations, of the product of their weights.
A weight written in the source, or learned, is a log weight. An instance whose carrier holds log
weights reads it as an element. Any other instance reads it as its unit, because a log weight
names no element of its carrier. So the answer in Boolean is derivability and the answer in
Counting is the number of derivations.
4. Convergence¶
When the rules can derive an item from itself, the item has infinitely many derivations, and its
value is the least fixpoint of the rules, if one exists (Abo Khamis et al., 2022). A closed or
ω-continuous semiring guarantees that fixpoint. A semiring like Counting or LogProb may not
have one, since a cycle of weight one counts or sums without bound. The checker therefore refuses
a deduction that may cycle unless its instance's theory includes ClosedSemiring or
OmegaContinuousSemiring, it is generic over such a theory, or it declares a stopping rule with
tolerance. A run with a declared stopping rule reports whether its stop certifies the value, as
described for deductions.
The test is a termination argument on the rules. Every pair (rule, premise) is a step from the premise to the conclusion, and one step can follow another when the first's conclusion unifies with the second's premise. A cycle of items is a cycle of steps.
The checker considers each strongly connected set of steps under a lexicographic measure of items:
- first, for a deduction that reads its items off a sentence, the input an item covers. A premise of a rule with several premises covers strictly less than the conclusion, since every item covers some input. A premise with the conclusion's positions covers the same.
- then, the item's size. A conclusion that contains each variable of the premise at least as often, and has more constructors, is larger.
In each set, a step that strictly grows a measure that no step in the set shrinks lies on no cycle and is dropped. When every step keeps the measure, the next measure decides. A set that is left with a cycle, whose steps both grow and shrink a measure or change it in ways the reading cannot compare, may cycle, and its rules are named. The argument is sound: any cycle of items survives every drop. It is incomplete, because a cycle among the remaining steps may be ruled out by the input alone.
5. The free instance¶
Read each rule instance and each input occurrence as a variable. The polynomials with natural coefficients over those variables form the free commutative semiring \(\mathbb N[X]\) (Green et al., 2007). An item's element of it is the sum, over its derivations, of the monomial of the variables the derivation uses, counted with multiplicity. Two facts follow:
- the coefficient sum of that element is the number of derivations;
- for every commutative semiring \(K\) and every assignment \(h : X \to K\), there is exactly one semiring homomorphism \(\hat h : \mathbb N[X] \to K\) extending \(h\).
Because the chart's answer in \(K\) is the same sum of products with each variable replaced by its weight, the answer in \(K\) is \(\hat h\) applied to the free element. One chart in the free instance therefore gives the answer in every instance.
A FreeChart is that element in packed form: the derivation
hypergraph, in which each item has the edges that derive it. It is found once, with the Boolean
semiring, in which every item enters the chart once and every rule instance fires once.
specialize computes \(\hat h\) by dynamic programming in
premise order, so its cost is linear in the hypergraph. The specialization equals running the
deduction in an instance when \(h\) sends each variable to that variable's weight in the deduction's
own run in the instance, which homomorphism does.
The pairing of two homomorphisms is a homomorphism into the product semiring. So two deductions with the same rules, each weighed in its own instance, are computed together in one pass, as a product of weighted logic programs (Cohen et al., 2011).
A cyclic hypergraph's elements are formal power series, not polynomials. Its specialization iterates to the fixpoint in an instance whose theory guarantees one. In any other instance it sums only the derivations below a given height.
Cited sources¶
Joshua Goodman. Semiring Parsing. Computational Linguistics, 25(4):573–606, 1999. URL: https://aclanthology.org/J99-4004/.
Mahmoud Abo Khamis, Hung Q. Ngo, Reinhard Pichler, Dan Suciu, and Yisu Remy Wang. Convergence of Datalog over (Pre-) Semirings. In Proceedings of the 41st ACM SIGMOD-SIGACT-SIGAI Symposium on Principles of Database Systems, 105–117. 2022. URL: https://doi.org/10.1145/3517804.3524140, doi:10.1145/3517804.3524140.
Todd J. Green, Grigoris Karvounarakis, and Val Tannen. Provenance Semirings. In Proceedings of the Twenty-Sixth ACM SIGMOD-SIGACT-SIGART Symposium on Principles of Database Systems, 31–40. 2007. URL: https://doi.org/10.1145/1265530.1265535, doi:10.1145/1265530.1265535.
Shay B. Cohen, Robert J. Simmons, and Noah A. Smith. Products of Weighted Logic Programs. Theory and Practice of Logic Programming, 11(2-3):263–296, 2011. URL: https://doi.org/10.1017/S1471068410000529, doi:10.1017/S1471068410000529.