Issue #3006: A formal semantics in Nikaia, as a proof of concept: the rules for *, while and match, run against Part I’s examples

Open and answer this issue on GitHub.

ready · opened 2026-11-30 · updated 2026-11-30 · 0 comments

Part of #796

Goal

A proof of concept of a formal semantics written in Nikaia, covering three constructs only: * with its stop on overflow (Part I 2.2), while (Part I 3.3) and match with else (Part I 3.4). It answers two questions, nothing more: does writing the meaning as executable rules find gaps in the prose, and what does one rule cost to write and keep?

Decision (owner, 2026-11-30, on #796)

Starting point

docs/formal-semantics.md, sections The same three constructs, three ways (the three constructs as prose and as big-step rules, and the two gaps they found at once: the order operands are evaluated in is not stated, and the stop message comes from Rust) and How a rule becomes provable (a sketch of means_mul returning Outcome::Value(i64) or Outcome::Stop).

To build

  1. A package packages/semantics (nikaia.toml, src/, tests/, like packages/logic). In src/: a small syntax of the three constructs and what they need (integer literals, names, *, a comparison, an assignment, a block, while, match over integers with literal arms and else), a store from names to i64, and one function per rule, means_*, each returning an outcome: a value and the store, or a stop. Each function’s doc comment quotes the Part I sentence it states. The builder chooses the representation.
  2. Tests in packages/semantics/tests/, one .nika with .stdout per construct. Each takes every example of its Part I section (2.2, 3.3, 3.4) that uses only these constructs, writes it as a value of the syntax by hand, and prints the outcome the rules give. The .stdout is what the example prints when Nikaia runs it, checked by running it.
  3. A findings note in the report, one Found: line each: every place where writing a rule needed something the prose does not say (as the operand order did), and the cost (lines per rule, and the time the work took).

Done when

nikaia test in packages/semantics is green with the three tests, each rule cites its section, and the report lists the findings and the cost per rule; the commit that adds the last test carries Fixes #3006, and the report gives a Found: line per finding.

Files: only packages/semantics/ (new) and docs/formal-semantics.md (a line pointing at the package). No compiler, std or lowered file changes.


Generated by Claude Code

Back to Open Issues