Semirings¶
Semiring instances, the semiring a deduction runs in, the check that a cyclic deduction has a
fixpoint, and the free instance of a deduction with its specializations.
check_instance checks an instance against its theory,
free_chart computes a deduction's chart in the free
commutative semiring, and specialize evaluates it along a
homomorphism. The semirings reference describes the surface,
and the semantics states the constructions and guarantees.
semirings
¶
Semirings as theory parameters of deductions.
std.semiring declares the semiring theories (Semiring,
ClosedSemiring, OmegaContinuousSemiring) and the shipped
instances. A semiring declaration names an instance realized by an
algebra of quivers.core.algebras, checked against its theory's laws
(check_instance); a deduction header names the instance it runs in, or
the theory it is generic over (deduction_semiring); a deduction whose
rules may derive an item from itself needs a semiring whose theory
guarantees the fixpoint (require_convergence). The free instance of a
deduction is its derivation forest, computed once and specialized to any
instance along the unique homomorphism (free_chart, specialize).
STOP_OPTION
module-attribute
¶
The option that declares how a deduction's iteration stops.
MAX_MONOMIALS
module-attribute
¶
The most monomials a polynomial is expanded to.
ALGEBRAS
module-attribute
¶
ALGEBRAS: Mapping[str, Semiring] = MappingProxyType({member.name: member for member in KERNEL_ALGEBRAS.values()})
The shipped algebras an instance may be realized by, by their names.
CARRIERS
module-attribute
¶
CARRIERS: Mapping[str, TypeExpr] = MappingProxyType({render_static(carrier): carrier for carrier in KERNEL_CARRIERS})
The kernel types an instance's elements may live in, by their names.
CUT_OPTION
module-attribute
¶
The option key a deduction's semiring is no longer given by.
LOG_SEMIRING
module-attribute
¶
LOG_SEMIRING = KernelSemiring.of(LOG_PROB, LOG_WEIGHT)
The semiring a deduction without a semiring parameter runs in.
CATALOGUE
module-attribute
¶
CATALOGUE: Mapping[tuple[str, str], Law] = {(SEMIRING_THEORY, 'plus_assoc'): PLUS_ASSOCIATIVE, (SEMIRING_THEORY, 'plus_comm'): PLUS_COMMUTATIVE, (SEMIRING_THEORY, 'plus_unit'): PLUS_UNIT, (SEMIRING_THEORY, 'times_assoc'): TIMES_ASSOCIATIVE, (SEMIRING_THEORY, 'times_comm'): TIMES_COMMUTATIVE, (SEMIRING_THEORY, 'times_unit'): TIMES_UNIT, (SEMIRING_THEORY, 'distrib'): DISTRIBUTIVE, (SEMIRING_THEORY, 'annihilate'): ZERO_ANNIHILATES, (CLOSED_THEORY, 'star_unfold'): STAR_LEAST_SOLUTION}
Each law of std.semiring by its origin and name, and its counterpart
in the law catalogue whose claim by an algebra establishes it.
CLOSED_THEORY
module-attribute
¶
CLOSED_THEORY = flat_name(STANDARD_MODULE, 'ClosedSemiring')
The theory whose instances have a closure.
CONVERGENT_THEORIES
module-attribute
¶
CONVERGENT_THEORIES: frozenset[str] = frozenset({CLOSED_THEORY, OMEGA_CONTINUOUS_THEORY})
The theories whose instances guarantee the fixpoint of a cyclic deduction.
MAX_ASSIGNMENTS
module-attribute
¶
The most assignments a law is evaluated at.
OMEGA_CONTINUOUS_THEORY
module-attribute
¶
OMEGA_CONTINUOUS_THEORY = flat_name(STANDARD_MODULE, 'OmegaContinuousSemiring')
The theory whose instances are ω-continuous.
SEMIRING_THEORY
module-attribute
¶
SEMIRING_THEORY = flat_name(STANDARD_MODULE, 'Semiring')
The theory every semiring instance's theory includes.
SPREAD
module-attribute
¶
The elements, besides the units, a law is evaluated at on an infinite carrier, each kept only when the algebra and the carrier hold it.
STANDARD_MODULE
module-attribute
¶
STANDARD_MODULE = SourceModule(path=('std', 'semiring'))
The module that declares the semiring theories.
Monomial
¶
A product of generators, each with its exponent, sorted.
Polynomial
¶
Polynomial = dict[Monomial, int]
An element of the free commutative semiring: monomials and coefficients.
RulePattern
didactic-model
¶
RulePattern(*, name: str, premises: tuple[Pattern, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), conclusion: Pattern = field(opaque=True, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
A rule's premises and conclusion as patterns over the deduction's items.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The rule's name.
TYPE:
|
premises
|
Its premises.
TYPE:
|
conclusion
|
Its conclusion.
TYPE:
|
AlgebraHomomorphism
¶
AlgebraHomomorphism(semiring: ChartSemiring, system: DeductionSystem | None = None, *, convergent: bool = False, name: str = '')
Bases: Homomorphism[Tensor]
The homomorphism into a chart semiring a deduction's run defines.
A rule instance goes to the rule's own weight in the semiring, which is what the deduction's compiled rule multiplies into every conclusion; an input occurrence goes to its weight, which is a log weight in a semiring whose elements are log weights and the unit in any other, as the deduction's lexicon reads it. Specializing a free chart along it therefore equals running the deduction in the semiring.
| PARAMETER | DESCRIPTION |
|---|---|
semiring
|
The target.
TYPE:
|
system
|
The deduction whose weights the generators go to; the chart's own
deduction when
TYPE:
|
convergent
|
Whether the target's theory guarantees the fixpoint of a cycle.
TYPE:
|
name
|
How diagnostics name the target.
TYPE:
|
Source code in src/quivers/dsl/semirings/free.py
plus
¶
times
¶
image
¶
The generator's weight in the deduction's run in the algebra.
| PARAMETER | DESCRIPTION |
|---|---|
generator
|
The generator.
TYPE:
|
chart
|
The chart.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Its weight. |
| RAISES | DESCRIPTION |
|---|---|
SemiringError
|
If an occurrence must be read as a log weight and the chart's deduction runs in a semiring whose elements are not. |
Source code in src/quivers/dsl/semirings/free.py
FreeChart
didactic-model
¶
FreeChart(*, deduction: str, system: DeductionSystem = field(opaque=True, extras=OPAQUE_BY_IDENTITY), items: tuple[Item, ...] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), edges: dict[Item, tuple[FreeEdge, ...]] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), goals: tuple[Item, ...] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), order: tuple[Item, ...] | None = field(default=None, opaque=True, extras=OPAQUE_BY_IDENTITY), axiom_weights: tuple[Tensor, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_IDENTITY), input: HeldValue = field(default=None, opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: ValueModel
A deduction's chart in the free instance: its derivation hypergraph.
| PARAMETER | DESCRIPTION |
|---|---|
deduction
|
The deduction's name.
TYPE:
|
system
|
The compiled deduction the chart was computed from.
TYPE:
|
items
|
Every derived item, in the order found.
TYPE:
|
edges
|
The edges concluding each item.
TYPE:
|
goals
|
The goal items.
TYPE:
|
order
|
The items with every premise before its conclusions, or
TYPE:
|
axiom_weights
|
The weight of each input occurrence in the deduction's own semiring, in input order.
TYPE:
|
input
|
The input the chart was computed from.
TYPE:
|
acyclic
property
¶
Whether every item has finitely many derivations.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when the hypergraph has no cycle. |
FreeEdge
didactic-model
¶
FreeEdge(*, generator: Generator = field(opaque=True, extras=OPAQUE_BY_VALUE), premises: tuple[Item, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: ValueModel
One way an item is derived: a generator and the premises it combines.
| PARAMETER | DESCRIPTION |
|---|---|
generator
|
The input occurrence or rule instance.
TYPE:
|
premises
|
The premise items in premise order; none for an occurrence.
TYPE:
|
FreeHomomorphism
¶
FreeHomomorphism(limit: int = MAX_MONOMIALS)
Bases: Homomorphism[Polynomial]
The identity on the free instance: values are polynomials.
| PARAMETER | DESCRIPTION |
|---|---|
limit
|
The most monomials a value may have.
TYPE:
|
Source code in src/quivers/dsl/semirings/free.py
zero
¶
zero() -> Polynomial
plus
¶
plus(left: Polynomial, right: Polynomial) -> Polynomial
The sum of two polynomials.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The polynomials.
TYPE:
|
right
|
The polynomials.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Polynomial
|
Their sum. |
Source code in src/quivers/dsl/semirings/free.py
times
¶
times(left: Polynomial, right: Polynomial) -> Polynomial
The product of two polynomials.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The polynomials.
TYPE:
|
right
|
The polynomials.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Polynomial
|
Their product. |
Source code in src/quivers/dsl/semirings/free.py
image
¶
image(generator: Generator, chart: FreeChart) -> Polynomial
The generator as a polynomial.
| PARAMETER | DESCRIPTION |
|---|---|
generator
|
The generator.
TYPE:
|
chart
|
The chart.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Polynomial
|
The monomial of the generator. |
Source code in src/quivers/dsl/semirings/free.py
same
¶
same(left: Polynomial, right: Polynomial) -> bool
Equality of polynomials.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The polynomials.
TYPE:
|
right
|
The polynomials.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether they have the same monomials and coefficients. |
Source code in src/quivers/dsl/semirings/free.py
Generator
didactic-model
¶
Generator(*, kind: Literal['axiom', 'rule'], index: int, rule: str = '', bindings: Bindings = field(default=(), opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: ValueModel
A variable of the free semiring: an input occurrence or a rule instance.
| PARAMETER | DESCRIPTION |
|---|---|
kind
|
TYPE:
|
index
|
The occurrence's position among the run's inputs, or the rule's position among the deduction's rules.
TYPE:
|
rule
|
The rule's name; empty for an occurrence.
TYPE:
|
bindings
|
The rule instance's variables; empty for an occurrence.
TYPE:
|
key
property
¶
What tells one variable from another.
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
The kind, the index, and the bindings. |
Homomorphism
¶
Bases: ABC
A semiring and where each generator of a free chart goes in it.
The values are of any type V; an algebra of
quivers.core.algebras holds tensors, a finite model its elements.
convergent
class-attribute
instance-attribute
¶
Whether the target's theory guarantees the fixpoint of a cycle.
zero
abstractmethod
¶
plus
abstractmethod
¶
The sum of two values.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The values.
TYPE:
|
right
|
The values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
V
|
|
times
abstractmethod
¶
The product of two values.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The values.
TYPE:
|
right
|
The values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
V
|
|
image
abstractmethod
¶
same
abstractmethod
¶
Whether two values are equal, which decides when iteration stops.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The values.
TYPE:
|
right
|
The values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Their equality. |
Source code in src/quivers/dsl/semirings/free.py
ModelHomomorphism
¶
ModelHomomorphism(model: CheckedModel, images: Callable[[Generator], Value], *, convergent: bool = False)
Bases: Homomorphism[Value]
The homomorphism into a finite model of a semiring theory.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
A model of a theory that includes
TYPE:
|
images
|
Where each generator goes, an element of the model's carrier.
TYPE:
|
convergent
|
Whether the model's theory guarantees the fixpoint of a cycle.
TYPE:
|
Source code in src/quivers/dsl/semirings/free.py
plus
¶
times
¶
image
¶
ProductHomomorphism
¶
ProductHomomorphism(left: Homomorphism[A], right: Homomorphism[B])
Bases: Homomorphism[tuple[A, B]]
The pairing of two homomorphisms: a homomorphism into the product.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The first component.
TYPE:
|
right
|
The second component.
TYPE:
|
Source code in src/quivers/dsl/semirings/free.py
zero
¶
plus
¶
The componentwise sum.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The pairs.
TYPE:
|
right
|
The pairs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
The pair of sums. |
Source code in src/quivers/dsl/semirings/free.py
times
¶
The componentwise product.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The pairs.
TYPE:
|
right
|
The pairs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
The pair of products. |
Source code in src/quivers/dsl/semirings/free.py
image
¶
The pair of images.
| PARAMETER | DESCRIPTION |
|---|---|
generator
|
The generator.
TYPE:
|
chart
|
The chart.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
Each component's image. |
Source code in src/quivers/dsl/semirings/free.py
same
¶
Componentwise equality.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The pairs.
TYPE:
|
right
|
The pairs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether both components are equal. |
Source code in src/quivers/dsl/semirings/free.py
DeductionSemiringChoice
didactic-model
¶
DeductionSemiringChoice(*, instance: str | None = None, kernel: KernelSemiring | None = field(default=None, opaque=True, extras=OPAQUE_BY_VALUE), theory: str | None = None)
Bases: ValueModel
What a deduction's semiring parameter resolves to.
| PARAMETER | DESCRIPTION |
|---|---|
instance
|
The flat name of the instance the deduction runs in,
TYPE:
|
kernel
|
The kernel record of that instance, or of the log semiring;
TYPE:
|
theory
|
For a generic deduction, the flat name of the theory its instances range over.
TYPE:
|
generic
property
¶
Whether the deduction ranges over the instances of a theory.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True for |
SemiringError
¶
Bases: ValueError
A semiring instance or parameter the checker refuses.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
What is wrong, naming the instance, theory, or law.
TYPE:
|
line
|
The source position of the offending declaration or parameter.
TYPE:
|
col
|
The source position of the offending declaration or parameter.
TYPE:
|
Source code in src/quivers/dsl/semirings/instances.py
CheckedSemiring
didactic-model
¶
CheckedSemiring(*, name: str, theory: str, closure: tuple[str, ...], kernel: KernelSemiring = field(opaque=True, extras=OPAQUE_BY_VALUE), laws: tuple[LawRecord, ...] = ())
Bases: ValueModel
A semiring instance and what is known of its theory's laws.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The instance's flat name.
TYPE:
|
theory
|
The flat name of its theory.
TYPE:
|
closure
|
Every theory its theory includes, and the theory itself.
TYPE:
|
kernel
|
Its algebra on its carrier.
TYPE:
|
laws
|
One record per law of the theory.
TYPE:
|
convergent
property
¶
Whether the theory guarantees the fixpoint of a cyclic deduction.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when it includes |
LawRecord
didactic-model
¶
Bases: Model
What is known of one law of an instance's theory.
| PARAMETER | DESCRIPTION |
|---|---|
law
|
The law's flat name,
TYPE:
|
status
|
TYPE:
|
evidence
|
Why: decided on the finite carrier, proved by the algebra's claim, or assumed by the declaration after the samples it held at.
TYPE:
|
cycle_reason
¶
cycle_reason(rules: Sequence[RulePattern], slots: PositionSlots, lexical: bool) -> str | None
Why a deduction's rules may derive an item from itself, if they may.
| PARAMETER | DESCRIPTION |
|---|---|
rules
|
The rules.
TYPE:
|
slots
|
Which slots of each symbol hold positions.
TYPE:
|
lexical
|
Whether the items are read off a sentence.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str or None
|
The rules of a cycle no measure rules out, or |
Source code in src/quivers/dsl/semirings/convergence.py
require_convergence
¶
require_convergence(decl: DeductionDecl, slots: PositionSlots, *, convergent: bool, semiring: str) -> None
Refuse a cyclic deduction whose semiring guarantees no fixpoint.
| PARAMETER | DESCRIPTION |
|---|---|
decl
|
The deduction.
TYPE:
|
slots
|
Which slots of each symbol hold positions.
TYPE:
|
convergent
|
Whether its semiring's theory includes
TYPE:
|
semiring
|
The instance or theory, for the diagnostic.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
SemiringError
|
If the rules may derive an item from itself, the semiring does not
guarantee the fixpoint, and no |
Source code in src/quivers/dsl/semirings/convergence.py
rule_patterns
¶
rule_patterns(decl: DeductionDecl) -> tuple[RulePattern, ...]
A deduction's rules as patterns, read from the declaration.
| PARAMETER | DESCRIPTION |
|---|---|
decl
|
The deduction.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of RulePattern
|
One per rule, in order. |
Source code in src/quivers/dsl/semirings/convergence.py
unifiable
¶
Whether two patterns have a common instance.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The patterns.
TYPE:
|
right
|
The patterns.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when they unify with their variables renamed apart. |
Source code in src/quivers/dsl/semirings/convergence.py
chart_inputs
¶
chart_inputs(system: DeductionSystem, chart: FreeChart) -> tuple[Tensor, ...]
A deduction's weights of a free chart's input occurrences.
| PARAMETER | DESCRIPTION |
|---|---|
system
|
The deduction, with the same rules and inputs as the chart's.
TYPE:
|
chart
|
The chart.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of torch.Tensor
|
The weight of each occurrence in the deduction's semiring. |
Source code in src/quivers/dsl/semirings/free.py
evaluate
¶
evaluate(value: Polynomial, chart: FreeChart, target: Homomorphism[V]) -> V
Apply a homomorphism to a polynomial.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
An element of the free semiring of a chart's generators.
TYPE:
|
chart
|
The chart whose generators it is over.
TYPE:
|
target
|
The homomorphism.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
V
|
The sum over monomials of their coefficient times the product of their generators' images. |
Source code in src/quivers/dsl/semirings/free.py
free_chart
¶
free_chart(system: DeductionSystem, input_value: HeldValue, *, name: str = '') -> FreeChart
Compute a deduction's chart in the free instance.
| PARAMETER | DESCRIPTION |
|---|---|
system
|
The compiled deduction (
TYPE:
|
input_value
|
Its input: the tokens of a sentence, or its axioms.
TYPE:
|
name
|
The deduction's name, for diagnostics; the system's by default.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FreeChart
|
The derivation hypergraph, its goals, and the input occurrences' weights in the deduction's own semiring. |
Source code in src/quivers/dsl/semirings/free.py
goal_value
¶
goal_value(chart: FreeChart, target: Homomorphism[V], *, height: int | None = None) -> V
The goal's value along a homomorphism: the sum over the goal items.
| PARAMETER | DESCRIPTION |
|---|---|
chart
|
The chart.
TYPE:
|
target
|
The target.
TYPE:
|
height
|
A bound on the height of derivations, as
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
V
|
The sum of the goal items' values, the zero without one. |
Source code in src/quivers/dsl/semirings/free.py
homomorphism
¶
homomorphism(target: CheckedSemiring | ChartSemiring, system: DeductionSystem | None = None) -> AlgebraHomomorphism
The homomorphism into an instance that a deduction's run defines.
| PARAMETER | DESCRIPTION |
|---|---|
target
|
A checked instance (from
TYPE:
|
system
|
The deduction whose weights the generators go to; the chart's own
deduction when
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AlgebraHomomorphism
|
The homomorphism. |
Source code in src/quivers/dsl/semirings/free.py
joint
¶
joint(left: tuple[DeductionSystem, CheckedSemiring | ChartSemiring], right: tuple[DeductionSystem, CheckedSemiring | ChartSemiring], input_value: HeldValue, *, height: int | None = None) -> tuple[Tensor, Tensor]
Run two deductions over one input in one pass, in the product of their semirings.
The two deductions must have the same rules and read the same input occurrences off the input, so they share one derivation hypergraph; each component is weighed by its own deduction, in its own instance.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
Each deduction's compiled system and the instance it runs in.
TYPE:
|
right
|
Each deduction's compiled system and the instance it runs in.
TYPE:
|
input_value
|
The input.
TYPE:
|
height
|
A bound on the height of derivations, as
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of torch.Tensor
|
The goal's value in each deduction's instance. |
| RAISES | DESCRIPTION |
|---|---|
SemiringError
|
If the deductions do not share a derivation hypergraph. |
Source code in src/quivers/dsl/semirings/free.py
polynomial
¶
polynomial(chart: FreeChart, item: Item, *, limit: int = MAX_MONOMIALS) -> Polynomial
An item's value in the free commutative semiring.
| PARAMETER | DESCRIPTION |
|---|---|
chart
|
An acyclic chart.
TYPE:
|
item
|
The item.
TYPE:
|
limit
|
The most monomials the polynomial may have.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Polynomial
|
Each monomial (a derivation's generators with their multiplicities) with the number of derivations that have it. |
| RAISES | DESCRIPTION |
|---|---|
SemiringError
|
If the chart has a cycle or the polynomial is larger than the limit. |
Source code in src/quivers/dsl/semirings/free.py
product
¶
product(left: Homomorphism[A], right: Homomorphism[B]) -> ProductHomomorphism[A, B]
The homomorphism into the product of two targets.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The components.
TYPE:
|
right
|
The components.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ProductHomomorphism
|
Their pairing. |
Source code in src/quivers/dsl/semirings/free.py
same_rules
¶
same_rules(left: DeductionSystem, right: DeductionSystem) -> str | None
Why two deductions do not share one derivation hypergraph, if they do not.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The compiled deductions.
TYPE:
|
right
|
The compiled deductions.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str or None
|
The first rule they differ at, or |
Source code in src/quivers/dsl/semirings/free.py
specialize
¶
specialize(chart: FreeChart, target: Homomorphism[V], *, height: int | None = None) -> dict[Item, V]
Evaluate a free chart along a homomorphism.
| PARAMETER | DESCRIPTION |
|---|---|
chart
|
The chart in the free instance.
TYPE:
|
target
|
Where each generator goes, and the semiring it goes to.
TYPE:
|
height
|
A bound on the height of the derivations summed, an input having height one; required for a cyclic chart in a target whose theory does not guarantee the fixpoint.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict of Item to V
|
Every item's value. |
| RAISES | DESCRIPTION |
|---|---|
SemiringError
|
If the chart has a cycle, the target guarantees no fixpoint, and no height is given; or the iteration to the fixpoint does not settle within as many rounds as the chart has items. |
Source code in src/quivers/dsl/semirings/free.py
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | |
declared_instances
¶
declared_instances(statements: Sequence[object]) -> dict[str, SemiringDecl]
Every semiring instance a flat program declares, by its flat name.
| PARAMETER | DESCRIPTION |
|---|---|
statements
|
The program's statements.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict of str to SemiringDecl
|
The instances. |
Source code in src/quivers/dsl/semirings/instances.py
deduction_semiring
¶
deduction_semiring(decl: DeductionDecl, instances: Mapping[str, SemiringDecl]) -> DeductionSemiringChoice
Resolve a deduction's semiring parameter.
| PARAMETER | DESCRIPTION |
|---|---|
decl
|
The deduction, from the flat program.
TYPE:
|
instances
|
The flat program's instances, by flat name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DeductionSemiringChoice
|
The instance and its kernel record, the theory of a generic deduction, or the log semiring without a parameter. |
| RAISES | DESCRIPTION |
|---|---|
SemiringError
|
If the deduction still gives its semiring as an option, or its parameter names no declared instance; the message lists the instances in scope. |
Source code in src/quivers/dsl/semirings/instances.py
kernel_of
¶
kernel_of(decl: SemiringDecl) -> KernelSemiring
The kernel record of an instance's algebra on its carrier.
| PARAMETER | DESCRIPTION |
|---|---|
decl
|
The instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
KernelSemiring
|
The record its deductions' handlers carry. |
| RAISES | DESCRIPTION |
|---|---|
SemiringError
|
If the algebra or the carrier is not a shipped one, or the algebra's zero and unit have no element of the carrier. |
Source code in src/quivers/dsl/semirings/instances.py
refuse_option
¶
refuse_option(decl: DeductionDecl) -> None
Refuse the semiring option, which no longer chooses a semiring.
| PARAMETER | DESCRIPTION |
|---|---|
decl
|
The deduction.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
SemiringError
|
If the option block holds a |
Source code in src/quivers/dsl/semirings/instances.py
check_instance
¶
check_instance(decl: SemiringDecl, theory: TheoryValue) -> CheckedSemiring
Check a semiring instance against every law of its theory.
| PARAMETER | DESCRIPTION |
|---|---|
decl
|
The instance, from the flat program.
TYPE:
|
theory
|
Its theory, from the theory layer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CheckedSemiring
|
The instance with a record per law. |
| RAISES | DESCRIPTION |
|---|---|
SemiringError
|
If the theory does not include |
Source code in src/quivers/dsl/semirings/laws.py
convergent
¶
convergent(value: TheoryValue) -> bool
Whether a theory guarantees the fixpoint of a cyclic deduction.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The theory.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when it is or includes |