interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / omc / tests / longnames / LongNames.lean

64 lines · 2979 bytes Raw Blame History
1/-
2LongNames.lean: the packed-word argument of omc's long names (docs/one_layer/OMEGESE.md 9.2), as a model.
3
4omc compares names by a 64-bit packed word: the first 8 bytes of the word, little-endian. tok2 gives a
5name of 9..63 bytes the packed word 1 + 256 * k instead, k its index in the intern table. The claims:
6
7 1. a packed word's low byte is the word's first byte, which is 33..255 (tok2 ends a word at a byte
8 of 32 or less, and tok refuses a byte below 32 with error 16);
9 2. so no packed word of a real word (any name of 8 bytes or fewer, any keyword, or the first 8 bytes
10 of a longer word) equals an interned word, whose low byte is 1;
11 3. distinct table indices give distinct interned words.
12
13Model scope: bytes are natural numbers, a packed word is `pack` of at most 8 of them, and the 64-bit
14width is not modelled (8 bytes fit in 64 bits; an index below 4096 keeps 1 + 256 k below 2^20). The
15intern table itself (one index per spelling) and its hash probing are not modelled here; they are
16exercised by long_alias.om, long_63.om and long_names.om beside this file and by the interning
17mutants and capacity check of seed/omc/gate-longnames.sh.
18
19Status: written for Lean 4 core, no Mathlib. CHECKED 2026-11-08 on the Spark (AArch64) with
20leanprover/lean4:v4.35.0: `lean seed/omc/tests/longnames/LongNames.lean` printed nothing and exited 0, and
21`#print axioms` for each of interned_low, pack_low, pack_ne_interned, pack_take8_ne_interned and
22interned_inj lists only [propext, Quot.sound], no `sorryAx`. To recheck: the same two steps.
23-/
24
25/-- The packed word of a byte list, least significant byte first. -/
26def pack : List Nat → Nat
27 | [] => 0
28 | b :: rest => b + 256 * pack rest
29
30/-- The packed word tok2 gives the long name at table index k. -/
31def interned (k : Nat) : Nat := 1 + 256 * k
32
33theorem interned_low (k : Nat) : interned k % 256 = 1 := by
34 unfold interned
35 omega
36
37theorem pack_low (b : Nat) (rest : List Nat) (hb : b < 256) :
38 pack (b :: rest) % 256 = b := by
39 simp only [pack]
40 omega
41
42/-- Claim 2 for a word with first byte b: its packed word is never an interned word. -/
43theorem pack_ne_interned (b : Nat) (rest : List Nat) (k : Nat)
44 (hlo : 33 ≤ b) (hhi : b < 256) : pack (b :: rest) ≠ interned k := by
45 intro h
46 have h1 := pack_low b rest hhi
47 have h2 := interned_low k
48 rw [h] at h1
49 omega
50
51/-- Claim 2 for any nonempty word of bytes 33..255: omc packs its first 8 bytes. -/
52theorem pack_take8_ne_interned (w : List Nat) (k : Nat) (hne : w ≠ [])
53 (hbytes : ∀ b, b ∈ w → 33 ≤ b ∧ b < 256) : pack (w.take 8) ≠ interned k := by
54 cases w with
55 | nil => exact absurd rfl hne
56 | cons b rest =>
57 have hb := hbytes b (by simp)
58 show pack (b :: rest.take 7) ≠ interned k
59 exact pack_ne_interned b (rest.take 7) k hb.1 hb.2
60
61/-- Claim 3: distinct indices, distinct interned words. -/
62theorem interned_inj (j k : Nat) (h : interned j = interned k) : j = k := by
63 unfold interned at h
64 omega