Skip to content

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_diagram computes the colimit of a diagram of theories, with the helpers compose_span, compose_by_name, compose_discrete, and extend_theory;
  • views: check_view checks that a proposed theory morphism is one, and reports each domain equation as a discharged, derivable, assumed, or refused obligation;
  • rewriting: rewrite_system_report and normalize;
  • models: verify_model, reduct_model (the reduct along a morphism), sigma_model (its left adjoint, the free extension), and pi_model (its right adjoint, where it exists);
  • change: classify_change compares two versions of a theory.

Refusals are raised as quivers.gat.errors exceptions with typed detail.

Json

Json = str | int | float | bool | None | list[Json] | dict[str, Json]

A JSON value as panproto's serde shapes arrive in Python.

PyValue

PyValue = bool | int | str | None | list[PyValue] | dict[str, PyValue] | Constructor

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 ({"Var": ...}, {"App": {"op", "args"}}, {"Hole": {"name"}}, {"Let": {"name", "bound", "body"}}, or {"Case": {"scrutinee", "branches"}}).

TYPE: Json

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
def render_term(term: Json) -> str:
    """Render a serialized GAT term in the theory-DSL term syntax.

    Parameters
    ----------
    term : Json
        A term in panproto's serde shape (``{"Var": ...}``,
        ``{"App": {"op", "args"}}``, ``{"Hole": {"name"}}``,
        ``{"Let": {"name", "bound", "body"}}``, or
        ``{"Case": {"scrutinee", "branches"}}``).

    Returns
    -------
    str
        The term's text, as panproto renders it.

    Raises
    ------
    ValueError
        If the value is not a serialized term.
    """
    tag, payload = _variant(term, "term")
    if tag == "Var":
        return _str(payload, "variable")
    if tag == "App":
        op = _str(_field(payload, "op", "application"), "operation")
        args = _list(_field(payload, "args", "application"), "arguments")
        return f"{op}({', '.join(render_term(arg) for arg in args)})"
    if tag == "Hole":
        name = _field(payload, "name", "hole")
        return "?" if name is None else f"?{_str(name, 'hole name')}"
    if tag == "Let":
        name = _str(_field(payload, "name", "let"), "let binder")
        bound = render_term(_field(payload, "bound", "let"))
        body = render_term(_field(payload, "body", "let"))
        return f"let {name} = {bound} in {body}"
    if tag == "Case":
        scrutinee = render_term(_field(payload, "scrutinee", "case"))
        branches = []
        for branch in _list(_field(payload, "branches", "case"), "branches"):
            constructor = _str(_field(branch, "constructor", "branch"), "constructor")
            binders = [
                _str(b, "binder")
                for b in _list(_field(branch, "binders", "branch"), "binders")
            ]
            body = render_term(_field(branch, "body", "branch"))
            branches.append(f"{constructor}({', '.join(binders)}) => {body}")
        return f"case {scrutinee} of {' | '.join(branches)} end"
    raise ValueError(f"not a term variant: {tag!r}")

morphism_to_panproto

morphism_to_panproto(record: MorphismRecord) -> TheoryMorphism

Build panproto's morphism from a record.

PARAMETER DESCRIPTION
record

The morphism.

TYPE: MorphismRecord

RETURNS DESCRIPTION
TheoryMorphism

The native morphism.

Source code in src/quivers/gat/engine.py
def morphism_to_panproto(record: MorphismRecord) -> panproto.TheoryMorphism:
    """Build panproto's morphism from a record.

    Parameters
    ----------
    record : MorphismRecord
        The morphism.

    Returns
    -------
    panproto.TheoryMorphism
        The native morphism.
    """
    return panproto.TheoryMorphism(
        record.name,
        record.domain,
        record.codomain,
        record.sort_map,
        op_map=record.op_renames,
        term_map=record.derived_terms,
    )

morphism_record

morphism_record(morphism: TheoryMorphism) -> MorphismRecord

Read panproto's morphism into a record.

PARAMETER DESCRIPTION
morphism

The native morphism.

TYPE: TheoryMorphism

RETURNS DESCRIPTION
MorphismRecord

The record.

Source code in src/quivers/gat/engine.py
def morphism_record(morphism: panproto.TheoryMorphism) -> MorphismRecord:
    """Read panproto's morphism into a record.

    Parameters
    ----------
    morphism : panproto.TheoryMorphism
        The native morphism.

    Returns
    -------
    MorphismRecord
        The record.
    """
    return MorphismRecord(
        name=morphism.name,
        domain=morphism.domain,
        codomain=morphism.codomain,
        sort_map=dict(morphism.sort_map),
        op_renames=dict(morphism.op_map),
        derived_terms=dict(morphism.term_map),
    )

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: Theory

target_name

The name of the including theory.

TYPE: str

name

The morphism's name.

TYPE: str

RETURNS DESCRIPTION
MorphismRecord

The inclusion.

Source code in src/quivers/gat/engine.py
def inclusion_by_names(
    source: panproto.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``.

    Parameters
    ----------
    source : panproto.Theory
        The included theory.
    target_name : str
        The name of the including theory.
    name : str
        The morphism's name.

    Returns
    -------
    MorphismRecord
        The inclusion.
    """
    sorts = {_str(_field(s, "name", "sort"), "sort name") for s in source.sorts}
    ops = {_str(_field(o, "name", "op"), "op name") for o in source.ops}
    return MorphismRecord(
        name=name,
        domain=source.name,
        codomain=target_name,
        sort_map={s: s for s in sorts},
        op_renames={o: o for o in ops},
    )

witness_record

witness_record(witness: EqWitness) -> Witness

Read panproto's equality witness into a record.

PARAMETER DESCRIPTION
witness

The native witness.

TYPE: EqWitness

RETURNS DESCRIPTION
Witness

The record, with its premises read recursively.

Source code in src/quivers/gat/engine.py
def witness_record(witness: panproto.EqWitness) -> Witness:
    """Read panproto's equality witness into a record.

    Parameters
    ----------
    witness : panproto.EqWitness
        The native witness.

    Returns
    -------
    Witness
        The record, with its premises read recursively.
    """
    return Witness(
        lhs=witness.lhs,
        rhs=witness.rhs,
        witness_kind=_witness_kind(witness.kind),
        axiom=witness.axiom,
        op=witness.op,
        description=witness.description,
        premises=tuple(witness_record(p) for p in witness.premises),
    )

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 domain to codomain.

TYPE: MorphismRecord

domain

The domain theory.

TYPE: Theory

codomain

The codomain theory.

TYPE: Theory

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
def check_view(
    view: MorphismRecord, domain: panproto.Theory, codomain: panproto.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.

    Parameters
    ----------
    view : MorphismRecord
        The proposed morphism from ``domain`` to ``codomain``.
    domain : panproto.Theory
        The domain theory.
    codomain : panproto.Theory
        The codomain theory.

    Returns
    -------
    ViewCheck
        The view and one obligation per domain equation, in declaration
        order.

    Raises
    ------
    ViewRefused
        If the view's signature is not a theory morphism.
    """
    native = morphism_to_panproto(view)
    try:
        panproto.check_morphism(native, _without_equations(domain), codomain)
    except panproto.MorphismError as error:
        raise ViewRefused(_kind(error), str(error)) from error
    obligations: list[Obligation] = []
    for equation in domain.eqs:
        obligations.append(_obligation(native, domain, codomain, equation))
    return ViewCheck(morphism=view, obligations=tuple(obligations))

compose_morphisms

compose_morphisms(first: MorphismRecord, second: MorphismRecord, middle: Theory) -> MorphismRecord

The composite second . first of two morphisms.

PARAMETER DESCRIPTION
first

A morphism A -> B.

TYPE: MorphismRecord

second

A morphism B -> C.

TYPE: MorphismRecord

middle

The theory B.

TYPE: Theory

RETURNS DESCRIPTION
MorphismRecord

The composite A -> C.

RAISES DESCRIPTION
ViewRefused

If the morphisms do not compose.

Source code in src/quivers/gat/engine.py
def compose_morphisms(
    first: MorphismRecord, second: MorphismRecord, middle: panproto.Theory
) -> MorphismRecord:
    """The composite ``second . first`` of two morphisms.

    Parameters
    ----------
    first : MorphismRecord
        A morphism ``A -> B``.
    second : MorphismRecord
        A morphism ``B -> C``.
    middle : panproto.Theory
        The theory ``B``.

    Returns
    -------
    MorphismRecord
        The composite ``A -> C``.

    Raises
    ------
    ViewRefused
        If the morphisms do not compose.
    """
    try:
        composite = morphism_to_panproto(first).compose(
            morphism_to_panproto(second), middle
        )
    except panproto.MorphismError as error:
        raise ViewRefused(_kind(error), str(error)) from error
    return morphism_record(composite)

report_record

report_record(report: CompositionReport) -> CompositionReport

Read panproto's composition report into a record.

PARAMETER DESCRIPTION
report

The native report.

TYPE: CompositionReport

RETURNS DESCRIPTION
CompositionReport

The record.

Source code in src/quivers/gat/engine.py
def report_record(report: panproto.CompositionReport) -> CompositionReport:
    """Read panproto's composition report into a record.

    Parameters
    ----------
    report : panproto.CompositionReport
        The native report.

    Returns
    -------
    CompositionReport
        The record.
    """
    checks = tuple(
        CheckRecord(
            check=_str(_field(record, "check", "check record"), "check"),
            subject=_subject(_field(record, "subject", "check record")),
            outcome=_outcome(_field(record, "outcome", "check record")),
        )
        for record in report.checks
    )
    freshened = tuple(
        Freshening(
            symbol_kind=_symbol_kind(_field(entry, "kind", "freshening")),
            members=tuple(
                _symbol(m)
                for m in _list(_field(entry, "members", "freshening"), "members")
            ),
            candidate=_str(_field(entry, "candidate", "freshening"), "candidate"),
            result=_str(_field(entry, "result", "freshening"), "result"),
        )
        for entry in report.freshened
    )
    return CompositionReport(
        mode=_mode(report.mode),
        status=_check_status(report.status),
        name_clash_free=report.name_clash_free,
        checks=checks,
        freshened=freshened,
    )

provenance_record

provenance_record(provenance: Provenance) -> Provenance

Read panproto's provenance into a record.

PARAMETER DESCRIPTION
provenance

The native provenance.

TYPE: Provenance

RETURNS DESCRIPTION
Provenance

The record, entries ascending by kind, node, name.

Source code in src/quivers/gat/engine.py
def provenance_record(provenance: panproto.Provenance) -> Provenance:
    """Read panproto's provenance into a record.

    Parameters
    ----------
    provenance : panproto.Provenance
        The native provenance.

    Returns
    -------
    Provenance
        The record, entries ascending by kind, node, name.
    """
    entries = tuple(
        ProvenanceEntry(
            symbol_kind=kind, source=SymbolRef(node=node, name=name), image=image
        )
        for kind in SYMBOL_KINDS
        for node, name, image in provenance.entries(kind)
    )
    added = tuple(
        AddedEquation(name=name, edge=edge, op=SymbolRef(node=node, name=op))
        for name, (edge, node, op) in sorted(provenance.added_equations.items())
    )
    return Provenance(entries=entries, added_equations=added)

composed_record

composed_record(composition: Composition, labels: Sequence[str]) -> ComposedTheory

Read panproto's composition into a record.

PARAMETER DESCRIPTION
composition

The native composition.

TYPE: Composition

labels

The diagram's node labels, in node order.

TYPE: sequence of str

RETURNS DESCRIPTION
ComposedTheory

The record.

Source code in src/quivers/gat/engine.py
def composed_record(
    composition: panproto.Composition, labels: Sequence[str]
) -> ComposedTheory:
    """Read panproto's composition into a record.

    Parameters
    ----------
    composition : panproto.Composition
        The native composition.
    labels : sequence of str
        The diagram's node labels, in node order.

    Returns
    -------
    ComposedTheory
        The record.
    """
    theory = composition.theory
    return ComposedTheory(
        name=theory.name,
        theory_json=theory.to_json(),
        inclusions=tuple(
            NodeInclusion(label=label, morphism=morphism_record(inclusion))
            for label, inclusion in zip(labels, composition.inclusions, strict=True)
        ),
        provenance=provenance_record(composition.provenance),
        report=report_record(composition.report),
        sort_names=_names(theory.sorts),
        op_names=_names(theory.ops),
        equation_names=_names(theory.eqs),
    )

composed_theory

composed_theory(composed: ComposedTheory) -> Theory

The composed theory of a composition record, as panproto's theory.

PARAMETER DESCRIPTION
composed

The composition.

TYPE: ComposedTheory

RETURNS DESCRIPTION
Theory

Its theory.

Source code in src/quivers/gat/engine.py
def composed_theory(composed: ComposedTheory) -> panproto.Theory:
    """The composed theory of a composition record, as panproto's theory.

    Parameters
    ----------
    composed : ComposedTheory
        The composition.

    Returns
    -------
    panproto.Theory
        Its theory.
    """
    return panproto.Theory.from_dict_json(composed.theory_json)

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: str

detail

The variant's fields.

TYPE: Json

RETURNS DESCRIPTION
CompositionConflict

The conflict.

RAISES DESCRIPTION
ValueError

If the variant is not a composition refusal.

Source code in src/quivers/gat/engine.py
def conflict_record(kind: str, detail: Json) -> CompositionConflict:
    """Read one of panproto's composition refusals into a typed conflict.

    Parameters
    ----------
    kind : str
        The refusal's variant name.
    detail : Json
        The variant's fields.

    Returns
    -------
    CompositionConflict
        The conflict.

    Raises
    ------
    ValueError
        If the variant is not a composition refusal.
    """
    if kind == "duplicate_node_label":
        return DuplicateNodeLabel(label=_str(_field(detail, "label", kind), "label"))
    if kind == "invalid_node_label":
        return InvalidNodeLabel(label=_str(_field(detail, "label", kind), "label"))
    if kind == "unknown_node_label":
        return UnknownNodeLabel(label=_str(_field(detail, "label", kind), "label"))
    if kind == "invalid_node":
        return InvalidNode(
            label=_str(_field(detail, "label", kind), "label"),
            defects=_defects(_field(detail, "defects", kind)),
        )
    if kind == "invalid_leg":
        return InvalidLeg(
            edge=_int(_field(detail, "edge", kind), "edge"),
            detail=_str(_field(detail, "detail", kind), "detail"),
        )
    if kind == "sort_signature_mismatch":
        mismatch, body = _variant(_field(detail, "detail", kind), "sort mismatch")
        return SortSignatureMismatch(
            first=_symbol(_field(detail, "first", kind)),
            second=_symbol(_field(detail, "second", kind)),
            mismatch=mismatch,
            detail=_canonical(body if body is not None else {}),
        )
    if kind == "op_signature_mismatch":
        return OpSignatureMismatch(
            first=_symbol(_field(detail, "first", kind)),
            second=_symbol(_field(detail, "second", kind)),
        )
    if kind == "quotient_not_representable":
        reason, _ = _variant(_field(detail, "reason", kind), "representability reason")
        return QuotientNotRepresentable(
            first=_symbol(_field(detail, "first", kind)),
            second=_symbol(_field(detail, "second", kind)),
            reason=reason,
        )
    if kind == "name_conflict":
        return NameConflict(
            symbol_kind=_symbol_kind(_field(detail, "kind", kind)),
            name=_str(_field(detail, "name", kind), "name"),
            first=_symbol(_field(detail, "first", kind)),
            second=_symbol(_field(detail, "second", kind)),
        )
    if kind == "name_clash":
        classes = _list(_field(detail, "classes", kind), "classes")
        return NameClash(
            symbol_kind=_symbol_kind(_field(detail, "kind", kind)),
            name=_str(_field(detail, "name", kind), "name"),
            classes=tuple(
                tuple(_symbol(m) for m in _list(c, "class")) for c in classes
            ),
        )
    if kind == "ill_typed_transport":
        return IllTypedTransport(
            source=_symbol(_field(detail, "source", kind)),
            detail=_str(_field(detail, "detail", kind), "detail"),
        )
    if kind == "ill_typed_result":
        return IllTypedResult(defects=_defects(_field(detail, "defects", kind)))
    if kind == "not_a_cocone":
        members = _list(_field(detail, "class", kind), "class")
        return NotACocone(members=tuple(_symbol(m) for m in members))
    raise ValueError(f"not a composition refusal: {kind!r}")

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 . nor #.

TYPE: mapping of str to panproto.Theory

edges

Theory morphisms between nodes.

TYPE: sequence of DiagramEdge DEFAULT: ()

result_name

The composed theory's name.

TYPE: str

mode

Which symbols to identify.

TYPE: CompositionMode DEFAULT: 'explicit_identity'

clash

What to do when two classes would share a name.

TYPE: ClashPolicy DEFAULT: 'reject'

rewrite_budget

The rewrite steps one equality check may spend.

TYPE: int DEFAULT: 512

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
def compose_diagram(
    nodes: Mapping[str, panproto.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.

    Parameters
    ----------
    nodes : mapping of str to panproto.Theory
        The nodes by label. Labels are non-empty and contain neither
        ``.`` nor ``#``.
    edges : sequence of DiagramEdge
        Theory morphisms between nodes.
    result_name : str
        The composed theory's name.
    mode : CompositionMode
        Which symbols to identify.
    clash : ClashPolicy
        What to do when two classes would share a name.
    rewrite_budget : int
        The rewrite steps one equality check may spend.

    Returns
    -------
    ComposedTheory
        The colimit with its cocone, provenance, and report.

    Raises
    ------
    CompositionRefused
        If panproto refuses the diagram; the conflict names both sources.
    """
    return _compose(
        _diagram(nodes, edges),
        result_name=result_name,
        mode=mode,
        clash=clash,
        rewrite_budget=rewrite_budget,
    )

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: tuple of str and panproto.Theory

left

The left theory, labeled.

TYPE: tuple of str and panproto.Theory

right

The right theory, labeled.

TYPE: tuple of str and panproto.Theory

i1

The leg shared -> left.

TYPE: MorphismRecord

i2

The leg shared -> right.

TYPE: MorphismRecord

result_name

The composed theory's name.

TYPE: str

mode

Which symbols to identify.

TYPE: CompositionMode DEFAULT: 'explicit_identity'

clash

What to do when two classes would share a name.

TYPE: ClashPolicy DEFAULT: 'reject'

rewrite_budget

The rewrite steps one equality check may spend.

TYPE: int DEFAULT: 512

RETURNS DESCRIPTION
ComposedTheory

The pushout.

RAISES DESCRIPTION
CompositionRefused

If panproto refuses the span.

Source code in src/quivers/gat/engine.py
def compose_span(
    shared: tuple[str, panproto.Theory],
    left: tuple[str, panproto.Theory],
    right: tuple[str, panproto.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``.

    Parameters
    ----------
    shared : tuple of str and panproto.Theory
        The apex, labeled.
    left : tuple of str and panproto.Theory
        The left theory, labeled.
    right : tuple of str and panproto.Theory
        The right theory, labeled.
    i1 : MorphismRecord
        The leg ``shared -> left``.
    i2 : MorphismRecord
        The leg ``shared -> right``.
    result_name : str
        The composed theory's name.
    mode : CompositionMode
        Which symbols to identify.
    clash : ClashPolicy
        What to do when two classes would share a name.
    rewrite_budget : int
        The rewrite steps one equality check may spend.

    Returns
    -------
    ComposedTheory
        The pushout.

    Raises
    ------
    CompositionRefused
        If panproto refuses the span.
    """
    return _compose(
        panproto.TheoryDiagram.span(
            shared, left, right, morphism_to_panproto(i1), morphism_to_panproto(i2)
        ),
        result_name=result_name,
        mode=mode,
        clash=clash,
        rewrite_budget=rewrite_budget,
    )

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: tuple of str and panproto.Theory

left

The left theory, labeled.

TYPE: tuple of str and panproto.Theory

right

The right theory, labeled.

TYPE: tuple of str and panproto.Theory

result_name

The composed theory's name.

TYPE: str

mode

Which symbols to identify.

TYPE: CompositionMode DEFAULT: 'explicit_identity'

clash

What to do when two classes would share a name.

TYPE: ClashPolicy DEFAULT: 'reject'

rewrite_budget

The rewrite steps one equality check may spend.

TYPE: int DEFAULT: 512

RETURNS DESCRIPTION
ComposedTheory

The pushout.

RAISES DESCRIPTION
CompositionRefused

If panproto refuses the span.

ViewRefused

If a symbol of shared is missing from either side.

Source code in src/quivers/gat/engine.py
def compose_by_name(
    shared: tuple[str, panproto.Theory],
    left: tuple[str, panproto.Theory],
    right: tuple[str, panproto.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.

    Parameters
    ----------
    shared : tuple of str and panproto.Theory
        The apex, labeled.
    left : tuple of str and panproto.Theory
        The left theory, labeled.
    right : tuple of str and panproto.Theory
        The right theory, labeled.
    result_name : str
        The composed theory's name.
    mode : CompositionMode
        Which symbols to identify.
    clash : ClashPolicy
        What to do when two classes would share a name.
    rewrite_budget : int
        The rewrite steps one equality check may spend.

    Returns
    -------
    ComposedTheory
        The pushout.

    Raises
    ------
    CompositionRefused
        If panproto refuses the span.
    ViewRefused
        If a symbol of ``shared`` is missing from either side.
    """
    try:
        diagram = panproto.TheoryDiagram.by_name(shared, left, right)
    except panproto.GatError as error:
        raise ViewRefused("missing_mapping", str(error)) from error
    return _compose(
        diagram,
        result_name=result_name,
        mode=mode,
        clash=clash,
        rewrite_budget=rewrite_budget,
    )

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: mapping of str to panproto.Theory

result_name

The composed theory's name.

TYPE: str

mode

Which symbols to identify.

TYPE: CompositionMode DEFAULT: 'explicit_identity'

clash

What to do when two classes would share a name.

TYPE: ClashPolicy DEFAULT: 'reject'

rewrite_budget

The rewrite steps one equality check may spend.

TYPE: int DEFAULT: 512

RETURNS DESCRIPTION
ComposedTheory

The coproduct.

RAISES DESCRIPTION
CompositionRefused

If panproto refuses the diagram.

Source code in src/quivers/gat/engine.py
def compose_discrete(
    nodes: Mapping[str, panproto.Theory],
    *,
    result_name: str,
    mode: CompositionMode = "explicit_identity",
    clash: ClashPolicy = "reject",
    rewrite_budget: int = 512,
) -> ComposedTheory:
    """Compute the coproduct of theories.

    Parameters
    ----------
    nodes : mapping of str to panproto.Theory
        The theories by label.
    result_name : str
        The composed theory's name.
    mode : CompositionMode
        Which symbols to identify.
    clash : ClashPolicy
        What to do when two classes would share a name.
    rewrite_budget : int
        The rewrite steps one equality check may spend.

    Returns
    -------
    ComposedTheory
        The coproduct.

    Raises
    ------
    CompositionRefused
        If panproto refuses the diagram.
    """
    return _compose(
        panproto.TheoryDiagram.discrete(dict(nodes)),
        result_name=result_name,
        mode=mode,
        clash=clash,
        rewrite_budget=rewrite_budget,
    )

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: tuple of str and panproto.Theory

local

The local declarations over the parent's signature, labeled.

TYPE: tuple of str and panproto.Theory

result_name

The extended theory's name.

TYPE: str

rewrite_budget

The rewrite steps one equality check may spend.

TYPE: int DEFAULT: 512

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
def extend_theory(
    parent: tuple[str, panproto.Theory],
    local: tuple[str, panproto.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.

    Parameters
    ----------
    parent : tuple of str and panproto.Theory
        The parent theory, labeled.
    local : tuple of str and panproto.Theory
        The local declarations over the parent's signature, labeled.
    result_name : str
        The extended theory's name.
    rewrite_budget : int
        The rewrite steps one equality check may spend.

    Returns
    -------
    ComposedTheory
        The extension.

    Raises
    ------
    CompositionRefused
        If panproto refuses the extension, for instance because a local
        declaration redeclares a parent symbol with another signature.
    """
    parent_label, parent_theory = parent
    local_label, local_theory = local
    inclusion = inclusion_by_names(
        parent_theory, local_theory.name, f"incl_{parent_label}_{local_label}"
    )
    return compose_diagram(
        {parent_label: parent_theory, local_label: local_theory},
        (DiagramEdge(source=parent_label, target=local_label, morphism=inclusion),),
        result_name=result_name,
        mode="explicit_identity",
        clash="reject",
        rewrite_budget=rewrite_budget,
    )

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: Theory

RETURNS DESCRIPTION
RewriteSystemReport

Every critical pair and every termination violation.

Source code in src/quivers/gat/engine.py
def rewrite_system_report(theory: panproto.Theory) -> RewriteSystemReport:
    """Check local confluence and LPO termination of a theory's directed equations.

    Parameters
    ----------
    theory : panproto.Theory
        The theory.

    Returns
    -------
    RewriteSystemReport
        Every critical pair and every termination violation.
    """
    report = panproto.validate_rewrite_system(theory)
    return RewriteSystemReport(
        critical_pairs=tuple(
            CriticalPair(
                rule_a=p.rule_a,
                rule_b=p.rule_b,
                left=p.left,
                right=p.right,
                joins=p.joins,
            )
            for p in report.critical_pairs
        ),
        termination_violations=tuple(
            RuleViolation(rule=v.rule, reason=v.reason)
            for v in report.termination_violations
        ),
        warnings=tuple(report.warnings),
    )

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: Theory

term

The term, in the theory-DSL term syntax.

TYPE: str

max_steps

The rewrite step budget.

TYPE: int DEFAULT: 512

RETURNS DESCRIPTION
NormalForm

The term reached and whether the budget ran out.

Source code in src/quivers/gat/engine.py
def normalize(theory: panproto.Theory, term: str, max_steps: int = 512) -> NormalForm:
    """Rewrite a term by a theory's directed equations.

    Parameters
    ----------
    theory : panproto.Theory
        The theory whose directed equations rewrite.
    term : str
        The term, in the theory-DSL term syntax.
    max_steps : int
        The rewrite step budget.

    Returns
    -------
    NormalForm
        The term reached and whether the budget ran out.
    """
    reached, exhausted = panproto.normalize_term(theory, term, max_steps)
    return NormalForm(term=reached, exhausted=exhausted)

value_record

value_record(value: PyValue) -> Value

Read a panproto model value into a record.

PARAMETER DESCRIPTION
value

The value.

TYPE: PyValue

RETURNS DESCRIPTION
Value

The record.

Source code in src/quivers/gat/engine.py
def value_record(value: PyValue) -> Value:
    """Read a panproto model value into a record.

    Parameters
    ----------
    value : PyValue
        The value.

    Returns
    -------
    Value
        The record.
    """
    if isinstance(value, bool):
        return BoolValue(value=value)
    if isinstance(value, int):
        return IntValue(value=value)
    if isinstance(value, str):
        return StrValue(value=value)
    if value is None:
        return NullValue()
    if isinstance(value, list):
        return ListValue(items=tuple(value_record(v) for v in value))
    if isinstance(value, dict):
        return MapValue(
            entries=tuple(
                MapEntry(key=k, value=value_record(value[k])) for k in sorted(value)
            )
        )
    return ConstructorValue(
        tag=value.tag, args=tuple(value_record(a) for a in value.args)
    )

value_native

value_native(value: Value) -> PyValue

Write a value record as a panproto model value.

PARAMETER DESCRIPTION
value

The record.

TYPE: Value

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
def value_native(value: Value) -> PyValue:
    """Write a value record as a panproto model value.

    Parameters
    ----------
    value : Value
        The record.

    Returns
    -------
    PyValue
        The native value.

    Raises
    ------
    TypeError
        If the record is not a value variant.
    """
    if isinstance(value, BoolValue | IntValue | StrValue):
        return value.value
    if isinstance(value, NullValue):
        return None
    if isinstance(value, ListValue):
        return [value_native(v) for v in value.items]
    if isinstance(value, MapValue):
        return {entry.key: value_native(entry.value) for entry in value.entries}
    if isinstance(value, ConstructorValue):
        return panproto.Constructor(value.tag, [value_native(a) for a in value.args])
    raise TypeError(f"not a model value: {value!r}")

model_native

model_native(model: FiniteModel) -> Model

Build panproto's model from a finite model record.

PARAMETER DESCRIPTION
model

The model.

TYPE: FiniteModel

RETURNS DESCRIPTION
Model

The native model, its operations interpreted by table lookup.

Source code in src/quivers/gat/engine.py
def model_native(model: FiniteModel) -> panproto.Model:
    """Build panproto's model from a finite model record.

    Parameters
    ----------
    model : FiniteModel
        The model.

    Returns
    -------
    panproto.Model
        The native model, its operations interpreted by table lookup.
    """
    return panproto.Model(
        model.theory,
        {c.sort: [value_native(v) for v in c.elements] for c in model.carriers},
        {t.op: _table_function(t) for t in model.tables},
    )

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: Model

theory

The theory it interprets, which gives each operation's input sorts.

TYPE: Theory

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
def model_record(model: panproto.Model, theory: panproto.Theory) -> FiniteModel:
    """Read panproto's model into a finite model record.

    Parameters
    ----------
    model : panproto.Model
        The native model.
    theory : panproto.Theory
        The theory it interprets, which gives each operation's input sorts.

    Returns
    -------
    FiniteModel
        Its carriers and the tables of its operations over the product of
        their input carriers, carriers and tables ascending by name.

    Raises
    ------
    ModelRefused
        If evaluating an operation fails.
    ValueError
        If the model interprets an operation the theory does not declare.
    """
    carriers = model.carriers
    tables: list[OperationTable] = []
    signatures = {
        _str(_field(op, "name", "op"), "op name"): _list(
            _field(op, "inputs", "op"), "inputs"
        )
        for op in theory.ops
    }
    try:
        for op in sorted(model.op_names):
            if op not in signatures:
                raise ValueError(
                    f"model interprets {op!r}, which theory {theory.name!r} lacks"
                )
            domains = [carriers[_input_sort_head(i)] for i in signatures[op]]
            entries = tuple(
                TableEntry(
                    args=tuple(value_record(a) for a in args),
                    result=value_record(model.eval(op, list(args))),
                )
                for args in itertools.product(*domains)
            )
            tables.append(OperationTable(op=op, entries=entries))
    except panproto.ModelError as error:
        raise ModelRefused(_kind(error), str(error)) from error
    return FiniteModel(
        theory=model.theory_name,
        carriers=tuple(
            Carrier(sort=sort, elements=tuple(value_record(v) for v in carriers[sort]))
            for sort in sorted(carriers)
        ),
        tables=tuple(tables),
    )

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: FiniteModel

theory

The theory.

TYPE: Theory

max_assignments

The largest number of variable assignments to enumerate before the check stops as incomplete.

TYPE: int DEFAULT: 1000000

RETURNS DESCRIPTION
ModelVerification

"passed" only when every equation was checked exhaustively; each counterexample found otherwise.

Source code in src/quivers/gat/engine.py
def verify_model(
    model: FiniteModel, theory: panproto.Theory, max_assignments: int = 1_000_000
) -> ModelVerification:
    """Check every equation of a theory in a finite model.

    Parameters
    ----------
    model : FiniteModel
        The model.
    theory : panproto.Theory
        The theory.
    max_assignments : int
        The largest number of variable assignments to enumerate before
        the check stops as incomplete.

    Returns
    -------
    ModelVerification
        ``"passed"`` only when every equation was checked exhaustively;
        each counterexample found otherwise.
    """
    result = panproto.verify_model(model_native(model), theory, max_assignments)
    return ModelVerification(
        status=_check_status(result.status),
        violations=tuple(
            EquationViolation(
                equation=v.equation,
                assignment=tuple(
                    MapEntry(key=k, value=value_record(v.assignment[k]))
                    for k in sorted(v.assignment)
                ),
                lhs_value=value_record(v.lhs_value),
                rhs_value=value_record(v.rhs_value),
            )
            for v in result.violations
        ),
        incomplete=result.incomplete,
    )

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 domain to the theory model interprets.

TYPE: MorphismRecord

domain

The domain theory.

TYPE: Theory

model

A model of the codomain.

TYPE: FiniteModel

RETURNS DESCRIPTION
FiniteModel

The reduct, a model of domain.

RAISES DESCRIPTION
ModelRefused

If a carrier or interpretation the reduct needs is missing.

Source code in src/quivers/gat/engine.py
def reduct_model(
    morphism: MorphismRecord, domain: panproto.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.

    Parameters
    ----------
    morphism : MorphismRecord
        A morphism from ``domain`` to the theory ``model`` interprets.
    domain : panproto.Theory
        The domain theory.
    model : FiniteModel
        A model of the codomain.

    Returns
    -------
    FiniteModel
        The reduct, a model of ``domain``.

    Raises
    ------
    ModelRefused
        If a carrier or interpretation the reduct needs is missing.
    """
    try:
        reduct = panproto.reduct_model(
            morphism_to_panproto(morphism), domain, model_native(model)
        )
    except panproto.ModelError as error:
        raise ModelRefused(_kind(error), str(error)) from error
    return model_record(reduct, domain)

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 domain to codomain.

TYPE: MorphismRecord

domain

The domain theory.

TYPE: Theory

codomain

The codomain theory.

TYPE: Theory

model

A model of the domain.

TYPE: FiniteModel

max_elements

The largest number of elements the construction may build before it stops.

TYPE: int DEFAULT: 10000

RETURNS DESCRIPTION
SigmaExtension

The free extension and its unit.

RAISES DESCRIPTION
ModelRefused

With reason "model_budget_exhausted" when the construction does not close within max_elements, or "model_construction_unsupported" when a theory has dependent sorts or terms the construction cannot evaluate.

Source code in src/quivers/gat/engine.py
def sigma_model(
    morphism: MorphismRecord,
    domain: panproto.Theory,
    codomain: panproto.Theory,
    model: FiniteModel,
    max_elements: int = 10_000,
) -> 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.

    Parameters
    ----------
    morphism : MorphismRecord
        A morphism from ``domain`` to ``codomain``.
    domain : panproto.Theory
        The domain theory.
    codomain : panproto.Theory
        The codomain theory.
    model : FiniteModel
        A model of the domain.
    max_elements : int
        The largest number of elements the construction may build before
        it stops.

    Returns
    -------
    SigmaExtension
        The free extension and its unit.

    Raises
    ------
    ModelRefused
        With reason ``"model_budget_exhausted"`` when the construction does
        not close within ``max_elements``, or
        ``"model_construction_unsupported"`` when a
        theory has dependent sorts or terms the construction cannot
        evaluate.
    """
    try:
        result = panproto.sigma_model(
            morphism_to_panproto(morphism),
            domain,
            codomain,
            model_native(model),
            max_elements,
        )
    except panproto.ModelError as error:
        raise ModelRefused(_kind(error), str(error)) from error
    return SigmaExtension(
        model=model_record(result.model, codomain),
        unit=tuple(
            UnitPair(
                sort=sort, element=value_record(element), image=value_record(image)
            )
            for sort in sorted(result.unit)
            for element, image in result.unit[sort]
        ),
    )

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 domain to codomain.

TYPE: MorphismRecord

domain

The domain theory.

TYPE: Theory

codomain

The codomain theory.

TYPE: Theory

model

A model of the domain.

TYPE: FiniteModel

max_elements

The largest number of elements the construction may build.

TYPE: int DEFAULT: 10000

RETURNS DESCRIPTION
FiniteModel

The model of codomain.

RAISES DESCRIPTION
ModelRefused

With reason "model_construction_unsupported" naming a non-unary operation, or "model_budget_exhausted".

Source code in src/quivers/gat/engine.py
def pi_model(
    morphism: MorphismRecord,
    domain: panproto.Theory,
    codomain: panproto.Theory,
    model: FiniteModel,
    max_elements: int = 10_000,
) -> 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.

    Parameters
    ----------
    morphism : MorphismRecord
        A morphism from ``domain`` to ``codomain``.
    domain : panproto.Theory
        The domain theory.
    codomain : panproto.Theory
        The codomain theory.
    model : FiniteModel
        A model of the domain.
    max_elements : int
        The largest number of elements the construction may build.

    Returns
    -------
    FiniteModel
        The model of ``codomain``.

    Raises
    ------
    ModelRefused
        With reason ``"model_construction_unsupported"`` naming a
        non-unary operation, or ``"model_budget_exhausted"``.
    """
    try:
        result = panproto.pi_model(
            morphism_to_panproto(morphism),
            domain,
            codomain,
            model_native(model),
            max_elements,
        )
    except panproto.ModelError as error:
        raise ModelRefused(_kind(error), str(error)) from error
    return model_record(result, codomain)

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: Theory

new

The new version.

TYPE: Theory

RETURNS DESCRIPTION
TheoryChangeReport

The classification, the two inclusion checks, and every change.

Source code in src/quivers/gat/engine.py
def classify_change(old: panproto.Theory, new: panproto.Theory) -> TheoryChangeReport:
    """Classify the change from one version of a theory to the next.

    Parameters
    ----------
    old : panproto.Theory
        The old version.
    new : panproto.Theory
        The new version.

    Returns
    -------
    TheoryChangeReport
        The classification, the two inclusion checks, and every change.
    """
    report = panproto.classify_theory_change(old, new)
    classifications: tuple[ChangeClassification, ...] = (
        "fully-compatible",
        "backward-compatible",
        "breaking",
    )
    return TheoryChangeReport(
        classification=_choose(
            report.classification, classifications, "change classification"
        ),
        clients=_check_status(report.clients),
        models=_check_status(report.models),
        changes=tuple(
            TheoryChange(
                change=_choose(
                    _field(c, "kind", "change"), CHANGE_KINDS, "change kind"
                ),
                name=_str(_field(c, "name", "change"), "change name"),
                breaks_clients=_bool(
                    _field(c, "breaks_clients", "change"), "breaks_clients"
                ),
                breaks_models=_bool(
                    _field(c, "breaks_models", "change"), "breaks_models"
                ),
            )
            for c in report.changes
        ),
        client_error=report.client_error,
        model_error=report.model_error,
    )

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.