Skip to content

Denotational semantics of QVR

QVR is the modeling language of quivers. Its denotational semantics assigns each phrase a mathematical object, its denotation, so that the denotation of a compound phrase is determined by the denotations of its parts (Moggi, 1991). The semantics determines when two QVR programs denote the same Markov kernel or weighted relation, which rewrites a compiler may apply without changing a program's meaning, and which runtime operations each phrase must implement.

Category theory and measure theory enter through the definitions on Setting and notation, which the other pages link to. On the grammar pages, a syntactic category is a grammatical type such as NP or S/NP, and "category" alone means a category in the sense of category theory.

Every executable QVR declaration elaborates to a term of the Quivers Indexed Effect Core (QIEC), the typed core language of quivers, which has indexed families, effect rows, and effect handlers.

Pages

The pages are grouped into chapters. Setting and notation comes first, since every other page uses its definitions.

Foundations

  1. Semirings, t-norms, and change of base: the operations that weight composition, the built-in instances of Algebra, and maps between them.
  2. Composition rules: the levels of laws a composition rule may claim, rules declared in QVR, einsum contractions, and morphism transformations.
  3. Types and spaces: finite sets and standard Borel spaces as the denotations of object and space expressions.
  4. Morphisms: weighted relations, stochastic matrices, and Markov kernels, with their composition, tensor product, and marginalization.
  5. Expressions: the expression combinators (>>, @, .marginalize, fan, repeat, stack, scan, the parser combinators, and others).
  6. Programs as kernels: static and runtime parameter telescopes, program blocks and their steps (sample, observe, let, score, marginalize, return) as kernels into probability and s-finite measures.
  7. Effects and type classes: the type classes of quivers.monadic, algebraic effects and handlers, and how a parser lifts rules into a type class.
  8. Rows and functions: records, variants, row polymorphism, function values, and their elimination before code generation.
  9. Finite axes: tensors indexed by finite types, tabulation, selection, and reduction.
  10. Typing and checking: the source checker and the QIEC checker, with the judgments each enforces.
  11. The program-shape protocol: the panproto schema extracted from a compiled module, and what equality of such schemas does and does not show.

Deduction

  1. Weighted deduction: deduction declarations as weighted deduction systems, their chart denotation, and the conditions under which agenda evaluation computes it.
  2. Categorial types, rules, schemas, and bundles: syntactic categories, rule declarations, rule schemata, and bundles of rules.
  3. Composable deductions and rule schemata: a deduction composed from signatures and lexicon modules as the colimit of its parts by origin, schema instantiation, shared weights, generic code over the items of any extension, copaired folds and their naturality, and the classification of an extension.
  4. Lexicons: polymorphic entries, category sets, lazy instantiation, typed meanings, lexical rules, and refinements as ornaments.

Object languages

  1. Object languages: how a binding signature, its equational theory, its judgments, its notations, and its derived instances form one object language, and where each layer runs.
  2. Tree and graph autoencoders: syntax declarations as second-order binding signatures, encoders as folds over terms, decoders as kernels into terms, and losses.
  3. Equations and normalization: the equational theory of a syntax, checked rewriting with its termination and confluence checks, normalization by evaluation, and equality saturation.
  4. Judgments: moded relations over a syntax's terms, as checkers, inferencers, charts, and static checks of a lexicon.
  5. Notation and quotation: productions, reading against a precedence graph, hygiene, printing, and code quotations.
  6. The meta phase and deriving: the phase distinction, static assertions, splices, and derived instances computed from family descriptions.

The module calculus

  1. The module calculus: the module layer as a calculus interpreted away before code generation: identities, elaboration with existentials, applicative and generative application, sealing, static interpretation, and composition by origin.
  2. Modules and static interpretation: module identities, interfaces, scopes, and the flat program.
  3. Signatures, functors, and their static interpretation: signatures as existentials, matching as a coercion, the checking and run-time programs, and their soundness.
  4. Linking and sites: package holes, linked identities, well-founded recursive links, site addresses and identities, sharing, and the injective target spelling.
  5. Packages and dependency lenses: builds by minimal version selection, what a lockfile pins, the version an interface change requires, and dependency lenses.
  6. Content identity: the alpha-invariant content hash of every checked declaration, and what it keys.

Theories

  1. Theories, views, and models: presentations composed by colimit over theories shared by origin, views and their obligations, models with their reducts and free extensions, the satisfaction condition, dependent sorts, and the classification of an inclusion.
  2. Semirings as theory parameters: the semiring theories, instances and their laws, deductions generic over an instance, convergence, and the free instance.

Tests, holes, and experiments

  1. Tests and exact evaluation: what a test, property, or example means, the exact rational number domain of the reference machine, generation and shrinking, and what a mutation run establishes.
  2. Typed holes: the core hole term and its typing rule, evaluation around holes, fill and resume, and why every export path refuses a module with holes.
  3. Experiments: resolution, point hashes, data integrity, caching, provenance, and reference checks.
  4. Literate modules: tangling, examples, prose references, and woven results.

Implementation

  1. Implementation correspondence and limits: which equations the runtime realizes directly, which tests exercise them, and where the implementation is approximate.
  2. Transpilation architecture: the pipeline from a compiled module to source text for another probabilistic programming language.
  3. Transpilation correctness: the correctness criterion for each target and the evidence for it, with one page per target: Stan, NumPyro, Pyro, PyMC, Edward2, Turing.jl, Gen.jl, Church, WebPPL, BUGS, and JAGS.

Declaration syntax

Most categorical and probabilistic declarations share one shape:

KIND NAME : SIGNATURE [k = v, ...] [~ INIT] [BODY]
  • KIND is one of composition, category, object, morphism, bundle, program, contraction, export, deduction, syntax, judgment, encoder, decoder, loss, schema, or rule. A define declaration introduces a QIEC computation or names an expression such as a parser or a composed morphism. let binds a deterministic value inside a computation or a program body.
  • SIGNATURE follows the colon: an object value for object, a dom -> cod arrow for a declaration that denotes a morphism, and an inputs / codomain shape for contraction.
  • [k = v, ...] is the option block. Each declaration and each step accepts a fixed set of keys and rejects any other key.
  • ~ INIT is the optional initializer. A ~ Family(args) initializer gives a parametric family, and a ~ expr initializer gives a deterministic value. Which forms a morphism accepts depends on its role option (QVR reference).
  • BODY is an optional indented block: a rule list for composition, deduction, or judgment, the sorts, constructors, and equations of a syntax, a step list for program, and the body the grammar fixes for each other kind.

The QIEC declarations index, family with its constructors, effect with its operations, instance, handler, and define have their own forms, given in Typing and checking and in the grammar.

A pragma is an attribute statement. The outer form #[k = v, ...] decorates the next declaration, and the inner form #![k = v, ...] decorates the enclosing module. Lexicon entries and rule lines in a deduction take a trailing #[k = v, ...] that sets options for that entry or rule, such as learnable, bounded, parent, and weight = expr (Weighted deduction).

Notation

Symbol Meaning
\(\mathcal{V} = (V, \otimes, \bigoplus, \mathbf{1})\) A set \(V\) of weights with a product \(\otimes\), a reduction \(\bigoplus\), and a unit \(\mathbf 1\) (Setting §1)
\(\mathbf{FinSet}\) Finite sets and functions
\(\mathbf{SBor}\) Standard Borel spaces and measurable maps
\(\mathbf{Mat}(\mathcal{V})\) Finite sets and \(\mathcal V\)-matrices (Setting §2)
\(\mathbf{FinStoch}\) Finite sets and stochastic matrices
\(\mathbf{BorelStoch}\) Standard Borel spaces and Markov kernels
\(\mathcal{D}\), \(\mathcal{G}\) The distribution monad on finite sets and the Giry monad on standard Borel spaces
\(\llbracket \phi \rrbracket_\rho\) The denotation of the phrase \(\phi\) in the environment \(\rho\)
\(\Gamma \vdash \phi : \tau\) In the typing context \(\Gamma\), the phrase \(\phi\) has type \(\tau\)

In the categorical part of the language, a type denotes a finite set and a space denotes a standard Borel space. QIEC also has a Type kind for primitive types, products, distributions, and indexed families, which Typing and checking keeps separate from the first sense. We write \(|X|\) for the cardinality of a finite set \(X\) and \(\dim(S)\) for the dimension of a continuous space \(S\).

Cited sources

Eugenio Moggi. Notions of Computation and Monads. Information and Computation, 93(1):55–92, 1991. URL: https://www.sciencedirect.com/science/article/pii/0890540191900524, doi:10.1016/0890-5401(91)90052-4.