Theory Engine¶
quivers.gat is the one place quivers calls panproto's engine for
generalized algebraic theories
(Cartmell, 1986). It composes theories by
colimit over a declared diagram, checks that a proposed
theory morphism (a view) is one and reports
every domain equation as a proof obligation, rewrites terms by a theory's directed equations, and
works with finite models: it checks their equations, takes the
reduct of a model along a morphism, and builds the free
extension (the reduct's left adjoint) and, for theories whose operations are all unary, the reduct's
right adjoint.
Composition never identifies symbols by coincidence of names. In the default
"explicit_identity" mode two symbols are one only when the diagram's morphisms relate them, and two
unrelated symbols with one name are refused with both sources. The "amalgamate" mode also
identifies same-name symbols.
gat
¶
Generalized algebraic theories through panproto's theory engine.
quivers composes theories, checks views, rewrites terms, and works with
models of theories through panproto's engine. This package is the one
place that calls it: quivers.gat.engine makes the
requests, quivers.gat.records types every answer,
and quivers.gat.errors types every refusal.
Composition is by colimit over a
declared diagram, never by coincidence of names: in the default
"explicit_identity" mode two symbols are identified only when the
diagram's morphisms relate them, and a same-name clash is refused with
both sources.
engine
¶
Calls into panproto's theory engine, returning typed records.
Each function here makes one request of panproto's generalized algebraic
theory engine and returns the answer as records from
quivers.gat.records:
- composition:
compose_diagramcomputes the colimit of a diagram of theories, with the helperscompose_span,compose_by_name,compose_discrete, andextend_theory; - views:
check_viewchecks that a proposed theory morphism is one, and reports each domain equation as a discharged, derivable, assumed, or refused obligation; - rewriting:
rewrite_system_reportandnormalize; - models:
verify_model,reduct_model(the reduct along a morphism),sigma_model(its left adjoint, the free extension), andpi_model(its right adjoint, where it exists); - change:
classify_changecompares two versions of a theory.
Refusals are raised as quivers.gat.errors
exceptions with typed detail.
Json
¶
A JSON value as panproto's serde shapes arrive in Python.
PyValue
¶
A model value as panproto's Python surface represents it.
render_term
¶
render_term(term: Json) -> str
Render a serialized GAT term in the theory-DSL term syntax.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
A term in panproto's serde shape (
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The term's text, as panproto renders it. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the value is not a serialized term. |
Source code in src/quivers/gat/engine.py
morphism_to_panproto
¶
morphism_to_panproto(record: MorphismRecord) -> TheoryMorphism
Build panproto's morphism from a record.
| PARAMETER | DESCRIPTION |
|---|---|
record
|
The morphism.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TheoryMorphism
|
The native morphism. |
Source code in src/quivers/gat/engine.py
morphism_record
¶
morphism_record(morphism: TheoryMorphism) -> MorphismRecord
Read panproto's morphism into a record.
| PARAMETER | DESCRIPTION |
|---|---|
morphism
|
The native morphism.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MorphismRecord
|
The record. |
Source code in src/quivers/gat/engine.py
inclusion_by_names
¶
inclusion_by_names(source: Theory, target_name: str, name: str) -> MorphismRecord
The morphism sending every sort and operation of source to itself.
This is the inclusion of a theory into one that was built to
contain its signature, such as a local extension built on top of
it. It states an identity of origin, not a coincidence of names:
call it only for a target constructed from source.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The included theory.
TYPE:
|
target_name
|
The name of the including theory.
TYPE:
|
name
|
The morphism's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MorphismRecord
|
The inclusion. |
Source code in src/quivers/gat/engine.py
witness_record
¶
witness_record(witness: EqWitness) -> Witness
Read panproto's equality witness into a record.
| PARAMETER | DESCRIPTION |
|---|---|
witness
|
The native witness.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Witness
|
The record, with its premises read recursively. |
Source code in src/quivers/gat/engine.py
check_view
¶
check_view(view: MorphismRecord, domain: Theory, codomain: Theory) -> ViewCheck
Check a view and report each domain equation as an obligation.
The view's signature is checked first: every sort and operation
mapped, every image of the right sort, every derived term well
typed, every directed equation preserved. Each domain equation is
then checked on its own, so that one undecided equation does not
hide the status of the others. An equation is Discharged when
panproto derives its image from the codomain's axioms, Derivable
when the derivation uses a trusted congruence-closure step,
Assumed when the check was inconclusive, and Refused when the
image does not hold.
| PARAMETER | DESCRIPTION |
|---|---|
view
|
The proposed morphism from
TYPE:
|
domain
|
The domain theory.
TYPE:
|
codomain
|
The codomain theory.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ViewCheck
|
The view and one obligation per domain equation, in declaration order. |
| RAISES | DESCRIPTION |
|---|---|
ViewRefused
|
If the view's signature is not a theory morphism. |
Source code in src/quivers/gat/engine.py
compose_morphisms
¶
compose_morphisms(first: MorphismRecord, second: MorphismRecord, middle: Theory) -> MorphismRecord
The composite second . first of two morphisms.
| PARAMETER | DESCRIPTION |
|---|---|
first
|
A morphism
TYPE:
|
second
|
A morphism
TYPE:
|
middle
|
The theory
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MorphismRecord
|
The composite |
| RAISES | DESCRIPTION |
|---|---|
ViewRefused
|
If the morphisms do not compose. |
Source code in src/quivers/gat/engine.py
report_record
¶
report_record(report: CompositionReport) -> CompositionReport
Read panproto's composition report into a record.
| PARAMETER | DESCRIPTION |
|---|---|
report
|
The native report.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompositionReport
|
The record. |
Source code in src/quivers/gat/engine.py
provenance_record
¶
provenance_record(provenance: Provenance) -> Provenance
Read panproto's provenance into a record.
| PARAMETER | DESCRIPTION |
|---|---|
provenance
|
The native provenance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Provenance
|
The record, entries ascending by kind, node, name. |
Source code in src/quivers/gat/engine.py
composed_record
¶
composed_record(composition: Composition, labels: Sequence[str]) -> ComposedTheory
Read panproto's composition into a record.
| PARAMETER | DESCRIPTION |
|---|---|
composition
|
The native composition.
TYPE:
|
labels
|
The diagram's node labels, in node order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ComposedTheory
|
The record. |
Source code in src/quivers/gat/engine.py
composed_theory
¶
composed_theory(composed: ComposedTheory) -> Theory
The composed theory of a composition record, as panproto's theory.
| PARAMETER | DESCRIPTION |
|---|---|
composed
|
The composition.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Theory
|
Its theory. |
Source code in src/quivers/gat/engine.py
conflict_record
¶
conflict_record(kind: str, detail: Json) -> CompositionConflict
Read one of panproto's composition refusals into a typed conflict.
| PARAMETER | DESCRIPTION |
|---|---|
kind
|
The refusal's variant name.
TYPE:
|
detail
|
The variant's fields.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompositionConflict
|
The conflict. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the variant is not a composition refusal. |
Source code in src/quivers/gat/engine.py
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 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 | |
compose_diagram
¶
compose_diagram(nodes: Mapping[str, Theory], edges: Sequence[DiagramEdge] = (), *, result_name: str, mode: CompositionMode = 'explicit_identity', clash: ClashPolicy = 'reject', rewrite_budget: int = 512) -> ComposedTheory
Compute the colimit of a diagram of theories.
In "explicit_identity" mode exactly the symbols the edges relate
are identified; same-name symbols the edges do not relate stay
distinct and are named by clash. In "amalgamate" mode
same-name symbols are identified as well.
| PARAMETER | DESCRIPTION |
|---|---|
nodes
|
The nodes by label. Labels are non-empty and contain neither
TYPE:
|
edges
|
Theory morphisms between nodes.
TYPE:
|
result_name
|
The composed theory's name.
TYPE:
|
mode
|
Which symbols to identify.
TYPE:
|
clash
|
What to do when two classes would share a name.
TYPE:
|
rewrite_budget
|
The rewrite steps one equality check may spend.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ComposedTheory
|
The colimit with its cocone, provenance, and report. |
| RAISES | DESCRIPTION |
|---|---|
CompositionRefused
|
If panproto refuses the diagram; the conflict names both sources. |
Source code in src/quivers/gat/engine.py
compose_span
¶
compose_span(shared: tuple[str, Theory], left: tuple[str, Theory], right: tuple[str, Theory], i1: MorphismRecord, i2: MorphismRecord, *, result_name: str, mode: CompositionMode = 'explicit_identity', clash: ClashPolicy = 'reject', rewrite_budget: int = 512) -> ComposedTheory
Compute the pushout of a span left <- shared -> right.
| PARAMETER | DESCRIPTION |
|---|---|
shared
|
The apex, labeled.
TYPE:
|
left
|
The left theory, labeled.
TYPE:
|
right
|
The right theory, labeled.
TYPE:
|
i1
|
The leg
TYPE:
|
i2
|
The leg
TYPE:
|
result_name
|
The composed theory's name.
TYPE:
|
mode
|
Which symbols to identify.
TYPE:
|
clash
|
What to do when two classes would share a name.
TYPE:
|
rewrite_budget
|
The rewrite steps one equality check may spend.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ComposedTheory
|
The pushout. |
| RAISES | DESCRIPTION |
|---|---|
CompositionRefused
|
If panproto refuses the span. |
Source code in src/quivers/gat/engine.py
compose_by_name
¶
compose_by_name(shared: tuple[str, Theory], left: tuple[str, Theory], right: tuple[str, Theory], *, result_name: str, mode: CompositionMode = 'explicit_identity', clash: ClashPolicy = 'reject', rewrite_budget: int = 512) -> ComposedTheory
Compute the pushout of a span whose legs send shared symbols to their namesakes.
The legs relate exactly the symbols shared declares; other
same-name symbols of left and right are not related, and in
"explicit_identity" mode they clash.
| PARAMETER | DESCRIPTION |
|---|---|
shared
|
The apex, labeled.
TYPE:
|
left
|
The left theory, labeled.
TYPE:
|
right
|
The right theory, labeled.
TYPE:
|
result_name
|
The composed theory's name.
TYPE:
|
mode
|
Which symbols to identify.
TYPE:
|
clash
|
What to do when two classes would share a name.
TYPE:
|
rewrite_budget
|
The rewrite steps one equality check may spend.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ComposedTheory
|
The pushout. |
| RAISES | DESCRIPTION |
|---|---|
CompositionRefused
|
If panproto refuses the span. |
ViewRefused
|
If a symbol of |
Source code in src/quivers/gat/engine.py
compose_discrete
¶
compose_discrete(nodes: Mapping[str, Theory], *, result_name: str, mode: CompositionMode = 'explicit_identity', clash: ClashPolicy = 'reject', rewrite_budget: int = 512) -> ComposedTheory
Compute the coproduct of theories.
| PARAMETER | DESCRIPTION |
|---|---|
nodes
|
The theories by label.
TYPE:
|
result_name
|
The composed theory's name.
TYPE:
|
mode
|
Which symbols to identify.
TYPE:
|
clash
|
What to do when two classes would share a name.
TYPE:
|
rewrite_budget
|
The rewrite steps one equality check may spend.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ComposedTheory
|
The coproduct. |
| RAISES | DESCRIPTION |
|---|---|
CompositionRefused
|
If panproto refuses the diagram. |
Source code in src/quivers/gat/engine.py
extend_theory
¶
extend_theory(parent: tuple[str, Theory], local: tuple[str, Theory], *, result_name: str, rewrite_budget: int = 512) -> ComposedTheory
Extend a theory by local declarations, keeping the parent's identity of origin.
local must be built on the parent's signature: it declares every
sort and operation of the parent (under the same names) together
with its own sorts, operations, and equations, and none of the
parent's equations. The extension is the colimit of the single edge
parent -> local, so the result carries the parent's equations
and the local ones, and its provenance records which node each
symbol and law came from.
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
The parent theory, labeled.
TYPE:
|
local
|
The local declarations over the parent's signature, labeled.
TYPE:
|
result_name
|
The extended theory's name.
TYPE:
|
rewrite_budget
|
The rewrite steps one equality check may spend.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ComposedTheory
|
The extension. |
| RAISES | DESCRIPTION |
|---|---|
CompositionRefused
|
If panproto refuses the extension, for instance because a local declaration redeclares a parent symbol with another signature. |
Source code in src/quivers/gat/engine.py
rewrite_system_report
¶
rewrite_system_report(theory: Theory) -> RewriteSystemReport
Check local confluence and LPO termination of a theory's directed equations.
| PARAMETER | DESCRIPTION |
|---|---|
theory
|
The theory.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RewriteSystemReport
|
Every critical pair and every termination violation. |
Source code in src/quivers/gat/engine.py
normalize
¶
normalize(theory: Theory, term: str, max_steps: int = 512) -> NormalForm
Rewrite a term by a theory's directed equations.
| PARAMETER | DESCRIPTION |
|---|---|
theory
|
The theory whose directed equations rewrite.
TYPE:
|
term
|
The term, in the theory-DSL term syntax.
TYPE:
|
max_steps
|
The rewrite step budget.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NormalForm
|
The term reached and whether the budget ran out. |
Source code in src/quivers/gat/engine.py
value_record
¶
Read a panproto model value into a record.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Value
|
The record. |
Source code in src/quivers/gat/engine.py
value_native
¶
Write a value record as a panproto model value.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The record.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PyValue
|
The native value. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the record is not a value variant. |
Source code in src/quivers/gat/engine.py
model_native
¶
model_native(model: FiniteModel) -> Model
Build panproto's model from a finite model record.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Model
|
The native model, its operations interpreted by table lookup. |
Source code in src/quivers/gat/engine.py
model_record
¶
model_record(model: Model, theory: Theory) -> FiniteModel
Read panproto's model into a finite model record.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The native model.
TYPE:
|
theory
|
The theory it interprets, which gives each operation's input sorts.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FiniteModel
|
Its carriers and the tables of its operations over the product of their input carriers, carriers and tables ascending by name. |
| RAISES | DESCRIPTION |
|---|---|
ModelRefused
|
If evaluating an operation fails. |
ValueError
|
If the model interprets an operation the theory does not declare. |
Source code in src/quivers/gat/engine.py
verify_model
¶
verify_model(model: FiniteModel, theory: Theory, max_assignments: int = 1000000) -> ModelVerification
Check every equation of a theory in a finite model.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The model.
TYPE:
|
theory
|
The theory.
TYPE:
|
max_assignments
|
The largest number of variable assignments to enumerate before the check stops as incomplete.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ModelVerification
|
|
Source code in src/quivers/gat/engine.py
reduct_model
¶
reduct_model(morphism: MorphismRecord, domain: Theory, model: FiniteModel) -> FiniteModel
The reduct of a codomain model along a morphism.
Each domain sort is interpreted by the carrier of its image, each domain operation by its image, a derived term evaluated in the model.
| PARAMETER | DESCRIPTION |
|---|---|
morphism
|
A morphism from
TYPE:
|
domain
|
The domain theory.
TYPE:
|
model
|
A model of the codomain.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FiniteModel
|
The reduct, a model of |
| RAISES | DESCRIPTION |
|---|---|
ModelRefused
|
If a carrier or interpretation the reduct needs is missing. |
Source code in src/quivers/gat/engine.py
sigma_model
¶
sigma_model(morphism: MorphismRecord, domain: Theory, codomain: Theory, model: FiniteModel, max_elements: int = 10000) -> SigmaExtension
The free extension of a domain model along a morphism.
The left adjoint of the reduct: the codomain model generated by the
elements of model, subject to the codomain's equations and to the
relations model's operations impose.
| PARAMETER | DESCRIPTION |
|---|---|
morphism
|
A morphism from
TYPE:
|
domain
|
The domain theory.
TYPE:
|
codomain
|
The codomain theory.
TYPE:
|
model
|
A model of the domain.
TYPE:
|
max_elements
|
The largest number of elements the construction may build before it stops.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SigmaExtension
|
The free extension and its unit. |
| RAISES | DESCRIPTION |
|---|---|
ModelRefused
|
With reason |
Source code in src/quivers/gat/engine.py
1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 | |
pi_model
¶
pi_model(morphism: MorphismRecord, domain: Theory, codomain: Theory, model: FiniteModel, max_elements: int = 10000) -> FiniteModel
The right adjoint of the reduct, applied to a domain model.
Defined when every operation of both theories is unary, so that models are copresheaves and the right adjoint is the right Kan extension.
| PARAMETER | DESCRIPTION |
|---|---|
morphism
|
A morphism from
TYPE:
|
domain
|
The domain theory.
TYPE:
|
codomain
|
The codomain theory.
TYPE:
|
model
|
A model of the domain.
TYPE:
|
max_elements
|
The largest number of elements the construction may build.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FiniteModel
|
The model of |
| RAISES | DESCRIPTION |
|---|---|
ModelRefused
|
With reason |
Source code in src/quivers/gat/engine.py
classify_change
¶
classify_change(old: Theory, new: Theory) -> TheoryChangeReport
Classify the change from one version of a theory to the next.
| PARAMETER | DESCRIPTION |
|---|---|
old
|
The old version.
TYPE:
|
new
|
The new version.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TheoryChangeReport
|
The classification, the two inclusion checks, and every change. |
Source code in src/quivers/gat/engine.py
Cited sources¶
John Cartmell. Generalised Algebraic Theories and Contextual Categories. Annals of Pure and Applied Logic, 32:209–243, 1986. doi:10.1016/0168-0072(86)90053-9.