Skip to content

Formal semantics

github-actions[bot] edited this page Nov 25, 2026 · 1 revision

The formal model

The concrete rules and the abstract domains as a Lean 4 model, with a soundness theorem that ties them together under named hypotheses. The model is core Lean, no mathlib, and lake build passes with no sorry. It states what TeX does and what satex computes in place of it. It does not check the Rust. The mapping says where the two differ.

AI assistance. The Lean model (Core, Concrete, Abstract, Soundness), its mapping to the Rust code and the primitive table were written with AI assistance from Claude Code (Claude Opus 5.5, the build fixes with Claude Sonnet 5.5), directed and reviewed by the author. The global theorem is conditional. It proves the induction over the run, the budget and the effects of assignment and grouping. It assumes two coverings: the abstract reading of commands (hread) and the families without a transfer (hother). Both are free in the statement, so hother alone may carry the whole obligation. See PROOF-STATUS.md.

Every Lean file is shown as code on this site. Each name links to its definition. Hovering a name shows its type and doc comment. Section numbers (§ 207) link to the line of tex.web that defines them.

The files

  • Core.lean: characters, category codes, tokens, meanings, the state TeX computes with. Shared by the rest.
  • Concrete.lean: TeX itself as inductive rules, one Exec rule per primitive. This is the concrete semantics in code.
  • Abstract.lean: the abstract values, joins and widenings of the domains, and the abstract state.
  • Soundness.lean: the theorems. If the abstract reading and the families without a transfer are covered, every concrete trace of a document is covered by an abstract path up to the budget cut. Every abstract run ends within its budget, one counter for the whole run. Past the cut nothing is claimed.
  • Axioms.lean: a check that the main theorems use only Lean's standard axioms.

The theorems that are proven and the ones that are not yet are listed in PROOF-STATUS. Findings of the last review are in REVIEW-2.

Lean and Rust

Primitives

One row per primitive the engines define. The rule is the Exec rule of Concrete.lean that gives it meaning. A primitive is exact when the rule is TeX's own, over-approximated when the rule states a superset of what TeX does, and has no rule yet when satex follows the manual but the model is silent. The Rust column is where builtins.rs names it.

Next: Primitive coverage, what each primitive does in the interpreter.

Clone this wiki locally