Signatures¶
Multi-sorted algebra signatures with constructors, typed binders, and
optional vertex and edge kinds for graph-shaped signatures. These
objects are the runtime carriers of signature { … } DSL declarations.
The de Bruijn discipline is enforced structurally: a
BoundVar(i) term carries an integer index; binders push
a fresh ContextEntry(var_sort, embedding, type_term) onto
an implicit context Γ tracked by the encoder / decoder
runtime. Binder variables may carry an annotation sort:
the variable's type is stored alongside its embedding in Γ.
signature
¶
Signatures: typed multi-sorted algebras with binders.
A Signature is the runtime form of a signature { … } DSL
declaration. It carries the sort table, constructor table, binder
table, and (for graph-shaped signatures) vertex / edge kind tables.
Terms over a signature are first-class Python values
(Term instances): each carries the constructor / binder
name and its positional arguments. The framework's encoder and
decoder runtimes walk these records uniformly.
The de-Bruijn discipline is enforced structurally: a BoundVar
term carries an integer index; binders push a fresh entry onto an
implicit context Γ tracked by the encoder / decoder runtime.
All structured value types in this module are didactic
didactic.api.Model records, matching the quivers
convention for schema-bearing data; the only fields held opaque
are runtime-only artefacts that don't round-trip (torch tensors,
arbitrary Python data leaves).
SortVocabEntry
didactic-model
¶
SortVocabEntry(*, kind: Literal['string', 'integer', 'float'], value: DataLeaf)
Bases: Model
One closed-vocabulary entry on a data sort.
Each entry is a tagged Python value: kind is the leaf
type ("string" | "integer" | "float"), value is the
decoded Python value (str, int, or float).
Sort
didactic-model
¶
Sort(*, name: str, kind: SortKind, dim: int | None = None, vocab: tuple[SortVocabEntry, ...] = ())
Bases: Model
A sort declaration: name, kind, optional dim, optional closed vocabulary.
A data sort may carry a vocab tuple of
SortVocabEntry records. Object / index sorts must
have an empty vocab (the framework checks at runtime).
Constructor
didactic-model
¶
Bases: Model
A typed constructor symbol.
BinderVarSpec
didactic-model
¶
Bases: Model
A scoped variable introduced by a binder.
sort is the variable's own sort. annot_sort is the sort
of an optional type annotation, a sibling argument in the
enclosing Term that travels alongside the variable's embedding
in Γ. Used to track per-variable type information.
BinderArgSpec
didactic-model
¶
Bases: Model
A scoped argument of a binder.
Binder
didactic-model
¶
Binder(*, name: str, binds: tuple[BinderVarSpec, ...] = (), scoped: tuple[BinderArgSpec, ...] = (), codomain: str = '')
Bases: Model
A binder constructor: introduces variables of given sorts into the scope of given arguments.
arity
property
¶
The number of positional arguments of the binder in a Term.
Each annotated bound variable contributes one annotation argument, and each scoped argument contributes one more.
domain
¶
Positional sort sequence of the binder's arguments in the
enclosing Term: type-annotations for each annotated
bound variable (in declaration order, outer-context-evaluated),
followed by the scoped arguments (extended-context-evaluated).
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The sort name of each positional argument. |
Source code in src/quivers/structural/signature.py
VertexKind
didactic-model
¶
VertexKind(*, name: str, kind: SortKind, dim: int | None = None)
Bases: Model
A vertex kind in a graph-shaped signature.
EdgeKind
didactic-model
¶
Bases: Model
An edge kind in a graph-shaped signature.
Signature
didactic-model
¶
Signature(*, name: str, params: tuple[str, ...] = (), sorts_t: tuple[Sort, ...] = (), constructors_t: tuple[Constructor, ...] = (), binders_t: tuple[Binder, ...] = (), vertex_kinds_t: tuple[VertexKind, ...] = (), edge_kinds_t: tuple[EdgeKind, ...] = ())
Bases: Model
A multi-sorted algebra signature with optional binders / graph structure.
Sort, constructor, binder, vertex_kind and edge_kind tables are
represented as tuples of records (rather than dicts) so the
enclosing dx.Model keeps a schema-bearing layout. The
runtime exposes O(1) name-keyed lookup methods (sort(name),
constructor(name), etc.) on top of those tuples.
constructors
property
¶
constructors: dict[str, Constructor]
The constructor declarations keyed by constructor name.
vertex_kinds
property
¶
vertex_kinds: dict[str, VertexKind]
The graph vertex kinds keyed by kind name.
is_inductive
¶
Whether the signature declares any constructor or binder.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
Source code in src/quivers/structural/signature.py
is_graph
¶
Whether the signature declares both vertex and edge kinds.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
Source code in src/quivers/structural/signature.py
all_ops
¶
Iterate over every operation name of the signature.
| YIELDS | DESCRIPTION |
|---|---|
str
|
Each constructor name in declaration order, then each binder name in declaration order. |
Source code in src/quivers/structural/signature.py
codomain_of
¶
Return the codomain sort of a constructor or binder.
| PARAMETER | DESCRIPTION |
|---|---|
op
|
The constructor or binder name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The name of the sort the operation produces. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If |
Source code in src/quivers/structural/signature.py
domain_of
¶
Return the positional argument sorts of a constructor or binder.
| PARAMETER | DESCRIPTION |
|---|---|
op
|
The constructor or binder name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The sort of each positional argument; for a binder, as
given by |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If |
Source code in src/quivers/structural/signature.py
is_binder
¶
Whether an operation name is a binder of the signature.
| PARAMETER | DESCRIPTION |
|---|---|
op
|
The operation name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
Source code in src/quivers/structural/signature.py
sort_dim
¶
Return the declared embedding dimension of a sort or vertex kind.
| PARAMETER | DESCRIPTION |
|---|---|
sort
|
The sort or vertex-kind name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int or None
|
The declared dimension, or |
Source code in src/quivers/structural/signature.py
Term
didactic-model
¶
Bases: Model
A closed term over a signature.
op is the constructor name, the binder name, or the
framework-reserved "BoundVar" for a de-Bruijn variable
reference.
args are positional children. Object positions carry a
Term; data positions carry a DataLeaf raw
value; index positions carry a non-negative int. args
is held opaque (its element type is the open union
TermArg); the encoder / decoder enforce sort
agreement structurally at use time.
No wrapping such as Term("Data", …) is used at any
position; raw values appear directly at data positions.
to_tuple
¶
A serialisable form matching the agenda's item-tuple
convention: (op, *args_serialised). Children that are
Terms are recursively serialised; data leaves and
indices pass through.
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
The nested tuple |
Source code in src/quivers/structural/signature.py
ContextEntry
dataclass
¶
One scope entry on the binder stack.
embedding is a runtime tensor; type_term is the binder's
annotation term captured at scope-extension time.
Context
dataclass
¶
Context(entries: tuple[ContextEntry, ...] = ())
The de-Bruijn scope context threaded through encoder and decoder runtimes.
Position 0 is the most recently bound variable; lookup var(i)
returns the i-th entry from the top.
push
¶
Return the context extended by one innermost bound variable.
| PARAMETER | DESCRIPTION |
|---|---|
var_sort
|
The sort of the new variable.
TYPE:
|
embedding
|
The variable's embedding.
TYPE:
|
type_term
|
The binder's annotation term for the variable, if any.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Context
|
A new context whose index 0 is the new variable; |
Source code in src/quivers/structural/signature.py
var
¶
var(index: int) -> Tensor
Return the embedding of a bound variable.
| PARAMETER | DESCRIPTION |
|---|---|
index
|
The de-Bruijn index, counted from the innermost variable.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The variable's embedding. |
| RAISES | DESCRIPTION |
|---|---|
IndexError
|
If |
Source code in src/quivers/structural/signature.py
type_of
¶
type_of(index: int) -> Term | None
Return the annotation term of a bound variable.
| PARAMETER | DESCRIPTION |
|---|---|
index
|
The de-Bruijn index, counted from the innermost variable.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term or None
|
The annotation captured when the variable was bound, or
|
Source code in src/quivers/structural/signature.py
depth
¶
Return the number of variables in scope.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The context depth. |
by_sort
¶
by_sort(sort: str) -> list[tuple[int, ContextEntry]]
All entries whose var_sort matches; returned as
(depth-index, entry) pairs for the decoder's
categorical-over-in-scope-variables.
| PARAMETER | DESCRIPTION |
|---|---|
sort
|
The variable sort to select.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[tuple[int, ContextEntry]]
|
The matching entries with their de-Bruijn indices, innermost first. |
Source code in src/quivers/structural/signature.py
bound_var
¶
bound_var(index: int) -> Term
A de-Bruijn variable reference.
| PARAMETER | DESCRIPTION |
|---|---|
index
|
The de-Bruijn index: 0 refers to the innermost bound variable.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The term |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Source code in src/quivers/structural/signature.py
make_term
¶
make_term(op: str, *args) -> Term
Construct a term over a signature.
Each arg must be a Term, a DataLeaf raw
value, or a non-negative int (for index-sorted positions). The
encoder / decoder runtime validate sort agreement at use
time.
| PARAMETER | DESCRIPTION |
|---|---|
op
|
The constructor or binder name.
TYPE:
|
*args
|
The positional children.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The term |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Source code in src/quivers/structural/signature.py
Type aliases and constants¶
Structural compression: signatures, encoders, decoders, losses.
Runtime substrate for QVR signatures, encoders, decoders, and attached losses: a uniform algebraic interface for compressing structured objects to fixed-length vectors and decoding them under a learned distribution.