AST Nodes

Abstract syntax tree node definitions for the QVR DSL.

ast_nodes

AST node definitions for the quivers DSL.

The AST is a direct representation of the parsed .qvr source. Each node carries source-location info for error reporting. Recursive sums use dx.TaggedUnion with a kind discriminator: variants subclass their sum's root and pin kind to a Literal[...] value.

TypeExpr

Bases: TaggedUnion

Sum of type-expression node kinds.

TypeName

Bases: TypeExpr

A named type reference (identifier or integer literal).

TypeProduct

Bases: TypeExpr

Product type: A * B.

TypeCoproduct

Bases: TypeExpr

Coproduct type: A + B.

CatPattern

Bases: TaggedUnion

Sum of category-pattern node kinds.

CatPatternName

Bases: CatPattern

A named category pattern element (variable or atom).

CatPatternSlash

Bases: CatPattern

A slash category pattern: result/argument or result\argument.

CatPatternProduct

Bases: CatPattern

A product category pattern: left * right.

SpaceExpr

Bases: TaggedUnion

Sum of space-expression node kinds.

SpaceName

Bases: SpaceExpr

A bare identifier referencing a previously declared space.

SpaceConstructor

Bases: SpaceExpr

Space constructor call: Euclidean(3) or Euclidean(2, low=0.0, high=1.0).

SpaceProduct

Bases: SpaceExpr

Product space: A * B.

Expr

Bases: TaggedUnion

Sum of value-expression node kinds (morphism computations).

ExprIdent

Bases: Expr

Reference to a named morphism or binding.

ExprIdentity

Bases: Expr

Identity morphism: identity(A).

ExprCompose

Bases: Expr

Sequential composition: left >> right.

ExprTensorProduct

Bases: Expr

Parallel product: left @ right.

ExprMarginalize

Bases: Expr

Marginalization: expr.marginalize(A, B, ...).

ExprFan

Bases: Expr

Fan-out (diagonal) composition: fan(f, g, ...).

ExprRepeat

Bases: Expr

Iterated composition: repeat(f, n) or repeat(f).

ExprStack

Bases: Expr

Independent multi-layer composition: stack(f, n).

ExprScan

Bases: Expr

Temporal scan: scan(cell) or scan(cell, init=learned).

ExprParser

Bases: Expr

Deductive parser assembled from rules.

LetExprNode

Bases: TaggedUnion

Sum of let-step arithmetic expression nodes.

LetExprBinOp

Bases: LetExprNode

Binary arithmetic operation in a let expression.

LetExprUnaryOp

Bases: LetExprNode

Unary negation in a let expression.

LetExprCall

Bases: LetExprNode

Built-in function call in a let expression.

LetExprLiteral

Bases: LetExprNode

Numeric literal in a let expression.

LetExprVar

Bases: LetExprNode

Variable reference in a let expression.

ProgramStep

Bases: TaggedUnion

Sum of program-block step node kinds.

DrawStep

Bases: ProgramStep

A single draw or observe step inside a program block.

LetStep

Bases: ProgramStep

A deterministic let binding inside a program block.

The value field always holds a :class:LetExprNode — bare floats and bare identifier aliases are wrapped in :class:LetExprLiteral and :class:LetExprVar respectively at parse time.

Statement

Bases: TaggedUnion

Sum of top-level statement kinds.

QuantaleDecl

Bases: Statement

Quantale selection: quantale <name>.

CategoryDecl

Bases: Statement

Category atom declaration: category <name>.

RuleDecl

Bases: Statement

Rule-of-inference declaration.

ObjectDecl

Bases: Statement

Object declaration: object <name> : <type_expr>.

MorphismDecl

Bases: Statement

Morphism declaration: latent|observed <name> : <dom> -> <cod>.

morphism_kind distinguishes "latent" from "observed"; kind is the dx.TaggedUnion discriminator and is fixed for this variant.

SpaceDecl

Bases: Statement

Space declaration: space <name> : <space_expr>.

ContinuousMorphismDecl

Bases: Statement

Continuous morphism declaration.

StochasticMorphismDecl

Bases: Statement

Stochastic morphism declaration.

DiscretizeDecl

Bases: Statement

Discretize boundary: discretize <name> : <space> -> <n_bins>.

EmbedDecl

Bases: Statement

Embed boundary: embed <name> : <finset> -> <space>.

ProgramDecl

Bases: Statement

Monadic program block with optional named params and tuple returns.

LetDecl

Bases: Statement

Let binding: let <name> = <expr> [where let_decl+].

The optional where clause carries nested :class:LetDecl statements; the field is typed as tuple[Statement, ...] (the union root) because didactic does not yet accept self-referential forward refs in field annotations. The parser only ever writes :class:LetDecl instances into the tuple.

OutputDecl

Bases: Statement

Output declaration: output <expr>.

Module

Bases: Model

A complete .qvr program (sequence of statements).