Terms¶
Stable value and computation terms.
terms
¶
Stable value and computation terms for QIEC.
Terms contain no Python callables. Runtime values and handler bodies cross the boundary only through stable attachment and handler identifiers.
SCALE_FLOOR
module-attribute
¶
The floor an exponentiated scale head of an :class:AffineMap or
:class:TableMap is clamped at, which every backend applies alike.
LiteralData
¶
LiteralData = None | bool | int | float | str | bytes | tuple[LiteralData, ...]
The host data a literal carries: a scalar, bytes, or a tuple of literal data.
ReductionOperator
¶
The reductions of a whole tensor to one number.
RowwiseOperator
¶
The operations along a tensor's last axis that keep its shape.
Value
¶
Value = Var | LiteralValue | ConstructorValue | EvidenceValue | AttachmentRef | TransportValue | PrimitiveApplication | TupleValue | TensorValue | Projection | DistributionValue | LogDensity | SiteValue | Gather | WeightSum | SegmentSum | KernelMatrix | AffineMap | TableMap | Reduction | Rowwise | Comprehension
A value term: every pure, effect-free term a computation may mention.
Computation
¶
A computation term: every term that may perform effects or control flow.
Local
dataclass
¶
Local(name: str, type: TypeExpr)
A typed binder for a runtime value.
Locals are compared by identity of name and type together, so two binders of the same name at different types are distinct.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The binder's display name.
TYPE:
|
type
|
The type of every value bound to it.
TYPE:
|
Var
dataclass
¶
Var(local: Local, tag: Literal['var'] = 'var')
Reference to a bound local.
| PARAMETER | DESCRIPTION |
|---|---|
local
|
The binder being referenced.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
LiteralValue
dataclass
¶
LiteralValue(value: LiteralData, type: TypeExpr, tag: Literal['literal'] = 'literal')
A literal host value at a primitive or tuple type.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The literal's data:
TYPE:
|
type
|
The literal's type.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
ConstructorValue
dataclass
¶
ConstructorValue(constructor: ConstructorId, static_arguments: tuple[StaticArgument, ...], fields: tuple[Value, ...], result_type: TypeExpr, tag: Literal['constructor'] = 'constructor')
Application of a declared constructor to static and value arguments.
| PARAMETER | DESCRIPTION |
|---|---|
constructor
|
The stable identity of the constructor applied.
TYPE:
|
static_arguments
|
The constructor's telescope instantiation, in binder order.
TYPE:
|
fields
|
The field values, in declaration order.
TYPE:
|
result_type
|
The indexed family type the application inhabits.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
EvidenceValue
dataclass
¶
EvidenceValue(evidence: EqualityEvidence, tag: Literal['evidence'] = 'evidence')
Kernel-checked equality evidence used as a value.
| PARAMETER | DESCRIPTION |
|---|---|
evidence
|
The evidence term.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
AttachmentRef
dataclass
¶
AttachmentRef(attachment: AttachmentId, type: TypeExpr, tag: Literal['attachment'] = 'attachment')
A stable reference to a runtime-owned host value.
| PARAMETER | DESCRIPTION |
|---|---|
attachment
|
The identity under which a runtime provider binds the host value.
TYPE:
|
type
|
The type the bound value must inhabit.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
TransportValue
dataclass
¶
TransportValue(evidence: EqualityEvidence, value: Value, target_type: TypeExpr, tag: Literal['transport'] = 'transport')
Transport a value along kernel-checked equality evidence.
| PARAMETER | DESCRIPTION |
|---|---|
evidence
|
The equality the value is carried across.
TYPE:
|
value
|
The value at the equality's left type.
TYPE:
|
target_type
|
The type the transported value inhabits, which the equality's right side determines.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
PrimitiveApplication
dataclass
¶
PrimitiveApplication(primitive: PrimitiveId, name: str, arguments: tuple[Value, ...], result_type: TypeExpr, origin: SourceOrigin, tag: Literal['primitive'] = 'primitive')
Application of a pure primitive from the closed registry.
The primitive is named nominally and its signature is fixed, so the checker validates the arguments against the registry and a backend renders the name it knows or refuses the capability; nothing is resolved by inspecting a runtime value.
| PARAMETER | DESCRIPTION |
|---|---|
primitive
|
The stable identity of the primitive applied.
TYPE:
|
name
|
The primitive's nominal name, as the registry spells it.
TYPE:
|
arguments
|
The value arguments, one per parameter.
TYPE:
|
result_type
|
The primitive's result type.
TYPE:
|
origin
|
The application's source location.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
TupleValue
dataclass
¶
TensorValue
dataclass
¶
Construction of a tensor from its entries along the outermost axis.
A rank-one tensor lists its elements; a tensor of higher rank lists the tensors one rank lower that are its slices, all of one shape, so a matrix literal is a tensor of row tensors.
| PARAMETER | DESCRIPTION |
|---|---|
items
|
The entries along the outermost axis, in order.
TYPE:
|
result_type
|
The
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
Projection
dataclass
¶
Projection(value: Value, position: int, result_type: TypeExpr, tag: Literal['projection'] = 'projection')
Selection of one component of a finite product.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The product value projected from.
TYPE:
|
position
|
The zero-based component selected.
TYPE:
|
result_type
|
The selected component's type.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
PlateAxis
dataclass
¶
PlateAxis(name: str, size: IndexTerm, tag: Literal['plate_axis'] = 'plate_axis')
One axis of a plated distribution.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The axis's source name, the object it ranges over.
TYPE:
|
size
|
The axis's extent, an index term of the nat sort.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
PlateShape
dataclass
¶
PlateShape(batch: tuple[PlateAxis, ...] = (), event: tuple[PlateAxis, ...] = (), tag: Literal['plate_shape'] = 'plate_shape')
The plate a distribution is constructed over.
Batch axes replicate the distribution independently, one draw per position, each scored on its own; event axes join the draws along them into one event, scored together. The trailing event axes are the family's own event dimensions when it has any; any leading ones extend a scalar family's event.
| PARAMETER | DESCRIPTION |
|---|---|
batch
|
The independent replication axes, outermost first.
TYPE:
|
event
|
The joint axes, outermost first.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
empty
property
¶
Whether the plate has no axes at all.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
DistributionValue
dataclass
¶
DistributionValue(family: DistributionId, name: str, arguments: tuple[tuple[str, Value], ...], result_type: TypeExpr, origin: SourceOrigin, plate: PlateShape = PlateShape(), tag: Literal['distribution'] = 'distribution')
Construction of a distribution from a family of the semantic registry.
The family is named nominally and its parameters are supplied by name, so the term records which parameterization the source used and a backend renders the spelling it knows without inspecting values. A plate replicates the family over batch axes and joins draws along event axes; a parameter may then be a tensor whose leading dimensions follow a suffix of the plate's axes and broadcast over the rest.
| PARAMETER | DESCRIPTION |
|---|---|
family
|
The stable identity of the family applied.
TYPE:
|
name
|
The family's source name, as the registry spells it.
TYPE:
|
arguments
|
The parameters supplied, each named, in source order.
TYPE:
|
result_type
|
The
TYPE:
|
origin
|
The construction's source location.
TYPE:
|
plate
|
The plate the distribution is constructed over; empty for one draw of the family.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
Gather
dataclass
¶
Selection along the outermost axis of a tensor.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The tensor selected from.
TYPE:
|
index
|
An
TYPE:
|
result_type
|
The selection's type: the slice type for an integer index, or a tensor of slices shaped like the index tensor.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
WeightSum
dataclass
¶
WeightSum(value: Value, tag: Literal['weight_sum'] = 'weight_sum')
The total of a tensor of log weights.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
A
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
SegmentSum
dataclass
¶
SegmentSum(value: Value, index: Value, groups: IndexTerm, result_type: TypeExpr, tag: Literal['segment_sum'] = 'segment_sum')
Per-group totals of a vector of log weights.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
A
TYPE:
|
index
|
A
TYPE:
|
groups
|
The number of groups, an index term of the nat sort.
TYPE:
|
result_type
|
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
KernelMatrix
dataclass
¶
KernelMatrix(inputs: Value, kernel: str, length_scale: float, jitter: float, result_type: TypeExpr, tag: Literal['kernel_matrix'] = 'kernel_matrix')
A positive-definite covariance over input locations.
| PARAMETER | DESCRIPTION |
|---|---|
inputs
|
A
TYPE:
|
kernel
|
The kernel's name;
TYPE:
|
length_scale
|
The kernel's length scale.
TYPE:
|
jitter
|
The diagonal added for numerical positive definiteness.
TYPE:
|
result_type
|
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
Reduction
dataclass
¶
Reduction(operator: ReductionOperator, value: Value, result_type: TypeExpr, tag: Literal['reduction'] = 'reduction')
A number summarizing every entry of a tensor.
| PARAMETER | DESCRIPTION |
|---|---|
operator
|
The reduction.
TYPE:
|
value
|
A tensor of reals, or of integers for
TYPE:
|
result_type
|
The element type.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
Rowwise
dataclass
¶
Rowwise(operator: RowwiseOperator, value: Value, result_type: TypeExpr, tag: Literal['rowwise'] = 'rowwise')
An operation along a tensor's last axis keeping its shape.
| PARAMETER | DESCRIPTION |
|---|---|
operator
|
The operation.
TYPE:
|
value
|
A tensor of reals.
TYPE:
|
result_type
|
The tensor's own type.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
Comprehension
dataclass
¶
Comprehension(binder: Local, extent: IndexTerm, body: Value, result_type: TypeExpr, tag: Literal['comprehension'] = 'comprehension')
A tensor built by evaluating a body at every index of an axis.
| PARAMETER | DESCRIPTION |
|---|---|
binder
|
The
TYPE:
|
extent
|
The axis's extent, an index term of the nat sort.
TYPE:
|
body
|
The entry at each index.
TYPE:
|
result_type
|
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
AffineMap
dataclass
¶
AffineMap(weight: Value, bias: Value, sources: tuple[Value, ...], row_offset: int, rows: int, transform: Literal['identity', 'exp', 'exp_floor'], result_type: TypeExpr, tag: Literal['affine_map'] = 'affine_map')
One head of an affine parameter map, W x + b on a row block.
For i below rows the head's coordinate i is the sum over
j of weight[row_offset + i, j] * x[j] plus
bias[row_offset + i], where x concatenates the sources in
order; exp exponentiates every coordinate afterwards, and
exp_floor exponentiates and clamps each at the scale floor.
| PARAMETER | DESCRIPTION |
|---|---|
weight
|
A
TYPE:
|
bias
|
A
TYPE:
|
sources
|
The conditioning row's factors in order, each a
TYPE:
|
row_offset
|
The first row of the head's block.
TYPE:
|
rows
|
The block's height.
TYPE:
|
transform
|
TYPE:
|
result_type
|
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
TableMap
dataclass
¶
TableMap(table: Value, index: Value, row_offset: int, rows: int, transform: Literal['identity', 'exp', 'exp_floor'], result_type: TypeExpr, tag: Literal['table_map'] = 'table_map')
One head of a table-indexed parameter map, a row block of T[i].
A kernel over a finite domain reads its parameters from a table
with one row per element of the domain: for i below rows
the head's coordinate i is table[index, row_offset + i],
with exp exponentiating every coordinate afterwards and
exp_floor exponentiating and clamping each at the scale floor.
| PARAMETER | DESCRIPTION |
|---|---|
table
|
A
TYPE:
|
index
|
An
TYPE:
|
row_offset
|
The first column of the head's block.
TYPE:
|
rows
|
The block's width.
TYPE:
|
transform
|
TYPE:
|
result_type
|
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
SiteValue
dataclass
¶
SiteValue(label: str, result_type: TypeExpr, tag: Literal['site'] = 'site')
A named sample site.
A site is the address a probabilistic step is observed and traced under. Its label is the source name of the step, which is stable data; the dynamic address a run adds comes from the request that carries it.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
The site's source name.
TYPE:
|
result_type
|
The
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
LogDensity
dataclass
¶
LogDensity(sampleable: Value, value: Value, origin: SourceOrigin, batch: tuple[PlateAxis, ...] = (), tag: Literal['log_density'] = 'log_density')
Evaluation of a distribution's log density at a value.
| PARAMETER | DESCRIPTION |
|---|---|
sampleable
|
The distribution, of type
TYPE:
|
value
|
The point evaluated, of type
TYPE:
|
origin
|
The evaluation's source location.
TYPE:
|
batch
|
The batch axes the density is kept apart over: empty for one
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
Return
dataclass
¶
Return(value: Value, tag: Literal['return'] = 'return')
Return a value with no effects.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value produced.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
Bind
dataclass
¶
Bind(binder: Local, first: Computation, then: Computation, tag: Literal['bind'] = 'bind')
Sequence two computations, binding the first's result in the second.
| PARAMETER | DESCRIPTION |
|---|---|
binder
|
The local the first computation's result is bound to.
TYPE:
|
first
|
The computation run first.
TYPE:
|
then
|
The computation run second, with
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
Perform
dataclass
¶
Perform(request: EffectRequest, tag: Literal['perform'] = 'perform')
Perform one effect operation.
| PARAMETER | DESCRIPTION |
|---|---|
request
|
The operation, its instance, static arguments, value arguments, and result type.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
Handle
dataclass
¶
Handle(instance: EffectInstanceId, handler: HandlerId, computation: Computation, static_arguments: tuple[StaticArgument, ...] = (), tag: Literal['handle'] = 'handle')
Run a computation under a handler installed for one effect instance.
| PARAMETER | DESCRIPTION |
|---|---|
instance
|
The effect instance whose operations the handler intercepts.
TYPE:
|
handler
|
The stable identity of the handler installed.
TYPE:
|
computation
|
The handled computation.
TYPE:
|
static_arguments
|
The handler's telescope instantiation, in binder order.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
CaseMotive
dataclass
¶
CaseBranch
dataclass
¶
CaseBranch(constructor: ConstructorId, static_arguments: tuple[StaticArgument, ...], fields: tuple[Local, ...], body: Computation, scope: StaticScopeId)
One stable GADT branch with no host-language closure.
| PARAMETER | DESCRIPTION |
|---|---|
constructor
|
The constructor this branch matches.
TYPE:
|
static_arguments
|
The constructor's static arguments as bound by the pattern, in binder order.
TYPE:
|
fields
|
The locals binding the constructor's fields, in declaration order.
TYPE:
|
body
|
The computation run when the branch is selected.
TYPE:
|
scope
|
The static scope identity under which the branch's skolems and equality evidence are minted.
TYPE:
|
Case
dataclass
¶
Case(scrutinee: Value, motive: CaseMotive, branches: tuple[CaseBranch, ...], tag: Literal['case'] = 'case')
Case analysis over an indexed family value.
| PARAMETER | DESCRIPTION |
|---|---|
scrutinee
|
The value analyzed.
TYPE:
|
motive
|
The result family, over the scrutinee's indices.
TYPE:
|
branches
|
One branch per constructor considered; coverage is checked against the exact applied family.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
Call
dataclass
¶
Call(callee: ComputationId, name: str, static_arguments: tuple[StaticArgument, ...], arguments: tuple[Value, ...], result_type: TypeExpr, effects: EffectRow, origin: SourceOrigin, tag: Literal['call'] = 'call')
Application of a named computation.
The callee is a stable identifier rather than an inlined body, which is what lets a recursive or mutually recursive call graph serialize as a finite tree.
| PARAMETER | DESCRIPTION |
|---|---|
callee
|
The stable identity of the computation called.
TYPE:
|
name
|
The callee's display name, for diagnostics and traces.
TYPE:
|
static_arguments
|
The callee's telescope instantiation, in binder order.
TYPE:
|
arguments
|
The value arguments, one per callee parameter.
TYPE:
|
result_type
|
The callee's result type under the instantiation.
TYPE:
|
effects
|
The callee's effect row under the instantiation.
TYPE:
|
origin
|
The call site's source location.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
Resume
dataclass
¶
Resume(value: Value, origin: SourceOrigin, tag: Literal['resume'] = 'resume')
Invocation of the enclosing handler clause's continuation.
The resumption is not a value and cannot be stored, so it is a term of its own rather than a call to a bound name. That is what makes a clause's grade checkable by counting invocations along the paths through its body.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value returned to the suspended computation as the operation's result.
TYPE:
|
origin
|
The resumption's source location.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
NewInstance
dataclass
¶
NewInstance(instance: EffectInstanceId, effect: EffectRef, body: Computation, origin: SourceOrigin, tag: Literal['new_instance'] = 'new_instance')
Lexically scoped allocation of an effect instance.
The identity is derived from the module, the enclosing computation, the lexical path, and the applied interface, so the same allocation site yields the same instance on every run while two sites of the same interface stay distinct.
| PARAMETER | DESCRIPTION |
|---|---|
instance
|
The scope-derived stable identity of the allocated instance.
TYPE:
|
effect
|
The applied interface the instance provides.
TYPE:
|
body
|
The computation within which the instance is in scope.
TYPE:
|
origin
|
The allocation's source location.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
If
dataclass
¶
If(condition: Value, then: Computation, otherwise: Computation, tag: Literal['if'] = 'if')
Branch on a Boolean value.
Both branches must produce the same type; the row of the whole is the union of the branches' rows. This is what lets a recursive computation stop, since a value-level select would evaluate both branches and never terminate.
| PARAMETER | DESCRIPTION |
|---|---|
condition
|
The Boolean value branched on.
TYPE:
|
then
|
The computation run when the condition holds.
TYPE:
|
otherwise
|
The computation run when it does not.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|