Equational theories¶
A SignatureTheory holds the checked equations of a
syntax declaration and decides them with rewriting, normalization by evaluation, and equality
saturation (Equations and normalization §7).
Program.theories maps each syntax with equations to its theory.
theory
¶
The equational theory of a signature, decided by three backends.
A signature's equations block declares oriented rules l ~> r and
laws l = r. SignatureTheory sends each to the backend that decides
it:
- oriented rules to the checked rewrite system of
quivers.structural.rewriting, whose termination and confluence are established or recorded as assumed; - laws that make up a type-directed structure (functions with beta and
eta, products with surjective pairing, a monad) to normalization by
evaluation over the typing judgment,
quivers.structural.theories.nbe; - every other law to equality saturation with the declared extraction
cost,
quivers.structural.egraph.
SignatureTheory.normalize applies the backends in that order until the
term no longer changes, each step an equality of the theory, and
SignatureTheory.equal_modulo compares normal forms; a theory with
saturation laws compares by saturating both terms together.
SignatureTheory
¶
SignatureTheory(signature: Signature, equations: Sequence[Equation], *, assume_terminating: bool = False, strategy: Strategy = INNERMOST, cost: CostModel | None = None, typing: str | None = None)
The checked equations of a signature with their decision procedures.
| PARAMETER | DESCRIPTION |
|---|---|
signature
|
The signature.
TYPE:
|
equations
|
Its rules and laws, checked by
TYPE:
|
assume_terminating
|
Whether termination of the rules is a recorded assumption.
TYPE:
|
strategy
|
The rewriting strategy.
TYPE:
|
cost
|
The extraction cost of the saturation backend; required when some law goes to it.
TYPE:
|
typing
|
The typing judgment normalization by evaluation reads.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
RewriteError
|
If the rules fail their termination or confluence check, a law needs the saturation backend and no cost is declared, or a type-directed structure has no typing judgment named. |
Source code in src/quivers/structural/theories/theory.py
normalizer
property
¶
normalizer: Normalizer | None
The normalizer by evaluation, once the judgment is attached.
| RETURNS | DESCRIPTION |
|---|---|
Normalizer or None
|
It, or |
| RAISES | DESCRIPTION |
|---|---|
RewriteError
|
If the theory has type-directed laws and no judgment is bound. |
attach_judgments
¶
attach_judgments(judgments: Mapping[str, JudgmentSystem]) -> None
Bind the typing judgment of the type-directed structures.
| PARAMETER | DESCRIPTION |
|---|---|
judgments
|
The module's judgments.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
RewriteError
|
If the named judgment is not declared. |
Source code in src/quivers/structural/theories/theory.py
normalize
¶
A normal form of a term in the theory.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
context
|
The types of its free variables, for normalization by evaluation.
TYPE:
|
max_rounds
|
The rounds of the three backends allowed.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The normal form. |
| RAISES | DESCRIPTION |
|---|---|
RewriteError
|
If the backends do not reach a common fixed point in time. |
Source code in src/quivers/structural/theories/theory.py
equal_modulo
¶
Whether two terms are equal in the theory.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The terms.
TYPE:
|
right
|
The terms.
TYPE:
|
context
|
The types of their free variables.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Equality of their normal forms; with saturation laws, of their classes after saturating both. |