The universal interpreter and the five-input circuit
Programs are numbered by \(e+1=2^w(2D+1)\), with four base-\(2^w\) digits of \(D\) per state; decoding is total. A valid primitive program has a code whose machine halts exactly when the program does.
DefinitionThe universal program numbering#✓
Decoding. Every \(e\in\mathbb N\) is uniquely \(e+1=2^w(2D+1)\) with \(w,D\in\mathbb N\). The machine \(\mu_e\) numbered by \(e\) is: if \(w=0\), \(\mu_e(i)=\mathrm{halt}\) for every \(i\). Otherwise, with \(\beta=2^w\) and \(d_t=\lfloor D/\beta^t\rfloor\bmod\beta\) the base-\(\beta\) digits of \(D\) (zero beyond its length), state \(i\) reads \((o,j,x,y)=(d_{4i},d_{4i+1},d_{4i+2},d_{4i+3})\) and $\(\mu_e(i)=\mathrm{inc}(j,x)\text{ if }o=1,\qquad\mu_e(i)=\mathrm{dec}(j,x,y)\text{ if }o=2,\qquad \mu_e(i)=\mathrm{halt}\text{ otherwise}.\)$ Decoding is total. The program numbered \(e\) halts on input \(n\), written \(\operatorname{halts}(e,n)\), if the run of \(\mu_e\) from state \(0\) with \(n\) in register \(0\) and all other registers zero halts.
Encoding. For a primitive program \(p=(p_0,\dots,p_{m-1})\) valid for \(r\) registers, let \(w(p)\) be the least \(w\ge2\) such that every register index and every target of \(p\) is below \(2^w\), let the fields of an instruction be \((1,j,x,0)\) for \(\mathrm{inc}(j,x)\), \((2,j,x,y)\) for \(\mathrm{dec}(j,x,y)\) and \((0,0,0,0)\) for the final halt, and put $\(D(p)=\sum_{i<m}\sum_{t<4}f_{i,t}\,2^{w(p)(4i+t)},\qquad \operatorname{code}(p)=2^{w(p)}\bigl(2D(p)+1\bigr)-1,\)$ where \(f_{i,0},\dots,f_{i,3}\) are the fields of \(p_i\).
This is a definition. The interpreter's numbering is the one specified by the universal interpreter of the manuscript; the encoding is the canonical choice of \(w\) (the manuscript only requires \(w\) large enough for all fields).
def split2 (e : ℕ) : ℕ × ℕ :=
(padicValNat 2 (e + 1), ((e + 1) / 2 ^ padicValNat 2 (e + 1)) / 2)
def decodeInstr (o j x y : ℕ) : Instr :=
if o = 1 then .inc j x else if o = 2 then .dec j x y else .halt
def decodeMachine (e : ℕ) : Machine := fun i =>
if (split2 e).1 = 0 then .halt else
decodeInstr (digit (split2 e).1 (split2 e).2 (4 * i))
(digit (split2 e).1 (split2 e).2 (4 * i + 1))
(digit (split2 e).1 (split2 e).2 (4 * i + 2))
(digit (split2 e).1 (split2 e).2 (4 * i + 3))
inductive Instr
/-- Increment register `j` and go to state `x`. -/
| inc (j x : ℕ)
/-- If register `j` is positive, decrement it and go to `x`; otherwise go to `y`. -/
| dec (j x y : ℕ)
/-- Stop. -/
| halt
deriving DecidableEq, Repr
ZInQKernel/Compiler/Circuits/RegisterMachine.lean:23
abbrev Machine : Type := ℕ → Instr
ZInQKernel/Compiler/Circuits/RegisterMachine.lean:33
def split2 (e : ℕ) : ℕ × ℕ :=
(padicValNat 2 (e + 1), ((e + 1) / 2 ^ padicValNat 2 (e + 1)) / 2)
ZInQKernel/Compiler/Interpreter/Numbering.lean:25
def decodeInstr (o j x y : ℕ) : Instr :=
if o = 1 then .inc j x else if o = 2 then .dec j x y else .halt
ZInQKernel/Compiler/Interpreter/Numbering.lean:32
def digit (w D t : ℕ) : ℕ := D / 2 ^ (w * t) % 2 ^ w
ZInQKernel/Compiler/Interpreter/Numbering.lean:29
Uses 1 · Used by 7
TheoremCodes of primitive programs#✓
Let \(p\) be a primitive program with \(m\) instructions, valid for \(r\) registers. Then \(\mu_{\operatorname{code}(p)}(i)=p_i\) for every \(i<m\) and \(\mu_{\operatorname{code}(p)}(i)=\mathrm{halt}\) for \(i\ge m\). Consequently, for every \(n\in\mathbb N\), $\(\operatorname{halts}(\operatorname{code}(p),n)\iff p\text{ halts on the one input }n .\)$ Moreover \(\operatorname{code}(p)<2^{w(p)(4m+1)+1}\), and if \(m\ge2\) then \(\operatorname{code}(p)+1\ge2^{w(p)(4m-7)+1}\).
Proof sketch. \(\operatorname{code}(p)+1=2^{w}(2D+1)\) with \(2D+1\) odd, so decoding recovers \(w=w(p)\ge2\) and \(D=D(p)\). All fields are below \(2^w\), so the base-\(2^w\) digits of \(D\) are exactly the fields, and digits beyond position \(4m\) are zero. The opcode fields \(1,2,0\) decode to \(\mathrm{inc}\), \(\mathrm{dec}\), \(\mathrm{halt}\) with the same register and targets (note \(2<2^w\) as \(w\ge2\)). Hence the two machines agree, and since every target of \(p\) is below \(m\) the runs agree and halt at the same time (only at state \(m-1\)). The bounds: \(D<2^{4wm}\), and for \(m\ge2\) the instruction \(p_{m-2}\) is not a halt, so its opcode digit at position \(4(m-2)\) is at least \(1\) and \(D\ge2^{4w(m-2)}\).
theorem decodeMachine_code (p : Program) : decodeMachine (code p) = p.toMachine
theorem halts_code_iff (p : Program) (r : ℕ) (hp : p.Valid r) (n : ℕ) :
halts (code p) n ↔ p.HaltsOn ![n]
theorem code_lt (p : Program) : code p < 2 ^ (width p * (4 * p.length + 1) + 1)
abbrev Program : Type := List Instr
ZInQKernel/Compiler/Circuits/RegisterMachine.lean:60
def decodeMachine (e : ℕ) : Machine := fun i =>
if (split2 e).1 = 0 then .halt else
decodeInstr (digit (split2 e).1 (split2 e).2 (4 * i))
(digit (split2 e).1 (split2 e).2 (4 * i + 1))
(digit (split2 e).1 (split2 e).2 (4 * i + 2))
(digit (split2 e).1 (split2 e).2 (4 * i + 3))
ZInQKernel/Compiler/Interpreter/Numbering.lean:36
def code (p : Program) : ℕ := 2 ^ width p * (2 * codeD p + 1) - 1
ZInQKernel/Compiler/Interpreter/Numbering.lean:102
def halts (e n : ℕ) : Prop := RM.Halts (decodeMachine e) (initFile ![n])
ZInQKernel/Compiler/Interpreter/Numbering.lean:45
def width (p : Program) : ℕ := max 2 (Nat.size (maxField p))
ZInQKernel/Compiler/Interpreter/Numbering.lean:93
Uses 2 · Used by 2
The interpreter keeps the simulated registers in a tape list \(\operatorname{cons}(h,t)=2^h(2t+1)\) and is assembled from arithmetic and list blocks. One loop iteration executes one decoded instruction, and its all-zero halt is equivalent to virtual halting.
TheoremTape lists#✓
Code finite lists of naturals by \(\operatorname{nil}=0\) and \(\operatorname{cons}(h,t)=2^h(2t+1)\). Then:
- \(\operatorname{cons}\) is a bijection from \(\mathbb N^2\) onto the positive naturals; for \(x>0\) the head \(h\) is the number of halvings of \(x\) until it is odd and the tail is \(t=(x/2^h-1)/2\); moreover \(t<x\) and \(h<x\);
- every natural number codes exactly one finite list;
- for a list code \(L\) and \(i\in\mathbb N\), \(\operatorname{get}(L,i)\) (the \(i\)-th entry, or \(0\) if the list is shorter) and \(\operatorname{set}(L,i,v)\) (the list with entry \(i\) replaced by \(v\), padded with zeros if it is shorter) are well defined, with \(\operatorname{get}(\operatorname{set}(L,i,v),i)=v\) and \(\operatorname{get}(\operatorname{set}(L,i,v),i')=\operatorname{get}(L,i')\) for \(i'\ne i\).
A register file \(\rho\) is represented by a list code \(L\) when \(\rho(i)=\operatorname{get}(L,i)\) for every \(i\); absent entries are zero, so a file has many representing codes.
Proof sketch. Unique factorization \(x=2^h\cdot\mathrm{odd}\) gives the bijection; \(2^h(2t+1)\ge2t+1>t\) and \(2^h>h\). Lists are coded by recursion on length, and the decoding terminates because tails decrease. The get/set equations are by induction on \(i\).
def cons (h t : ℕ) : ℕ := 2 ^ h * (2 * t + 1)
def uncons (x : ℕ) : ℕ × ℕ := (padicValNat 2 x, (x / 2 ^ padicValNat 2 x - 1) / 2)
def listCode : List ℕ → ℕ
| [] => 0
| h :: t => cons h (listCode t)
def cons (h t : ℕ) : ℕ := 2 ^ h * (2 * t + 1)
ZInQKernel/Compiler/Interpreter/TapeLists.lean:17
TheoremArithmetic blocks of the interpreter#✓
The universal interpreter is assembled from primitive-program blocks, each with an entry state, exit states, argument and result registers, and private scratch registers, using a reserved jump register \(J\) (register \(2\) in the interpreter) that is zero at every block boundary. Each block clears its scratch registers before using them. For each of the following blocks, entered with \(J=0\) and arbitrary scratch values, the run reaches an exit after finitely many steps with the stated effect on its result registers and \(J=0\) again; every register other than its results and scratch registers is unchanged, and the scratch registers may be left nonzero:
- clear \(x\): \(x\leftarrow0\);
- preserving zero test of \(x\): exits to the zero or nonzero exit according to \(x\), with \(x\) unchanged (decrement and restore);
- copy \(x\leftarrow y\) (\(x\ne y\)): \(y\) is restored through a scratch counter;
- addInto \(x\leftarrow x+y\), also when \(x\) and \(y\) are the same register (the operand is snapshot before \(x\) is overwritten);
- ifLt \(y<z\): a comparison loop that consumes both registers and exits according to whether \(y<z\), leaving \(y=0\), \(z=z-y-1\) if \(y<z\) and \(y=y-z\), \(z=0\) otherwise (callers compare private copies);
- divmod with divisor \(z\ge1\): \(q\leftarrow\lfloor y/z\rfloor\), \(r\leftarrow y\bmod z\), by repeated subtraction from a private remainder maintaining \(y=qz+r\), subtracting only when \(r\ge z\) (the interpreter's divisors are at least \(2\));
- divmod2 of \(y\) into \((q,r)\): \(q\leftarrow q+\lfloor y/2\rfloor\), \(r\leftarrow y\bmod2\) and \(y\leftarrow0\) (halving with parity, consuming \(y\) in pairs; callers clear \(q\) first).
Proof sketch. Each block is a fixed short program; its correctness is a loop invariant (the sum of the moved register and the counter is constant for copies and additions; \(y=qz+r\) for division) and termination by a decreasing register.
theorem runs_clear (x : ℕ) (ρ : Regs) : Runs (clear x) ρ (Function.update ρ x 0)
theorem compile_correct_in {μ : Machine} {s : Stmt} {ρ : Regs} {o : Outcome}
(hexec : Exec s ρ o) :
∀ {L ls le ex : ℕ}, CodeAt μ L (s.compile L ls le ex) → ρ J = 0 →
ReachesIn μ (s.Range L) ⟨L, ρ⟩ ⟨o.target (L + s.size) ls le ex, o.regs⟩
theorem runs_copyBlock {x y t : ℕ} (hxy : x ≠ y) (hxt : x ≠ t) (hyt : y ≠ t) (hx : x ≠ J)
(ht : t ≠ J) (ρ : Regs) (hJ : ρ J = 0) :
Runs (copyBlock x y t) ρ (Function.update (Function.update ρ x (ρ y)) t 0)
abbrev Regs : Type := ℕ → ℕ
ZInQKernel/Compiler/Interpreter/Structured.lean:29
def Runs (s : Stmt) (ρ ρ' : Regs) : Prop := Exec s ρ (.normal ρ')
ZInQKernel/Compiler/Interpreter/Blocks.lean:22
abbrev Machine : Type := ℕ → Instr
ZInQKernel/Compiler/Circuits/RegisterMachine.lean:33
inductive Stmt
| skip
| clear (x : ℕ)
| inc (x : ℕ)
| pred (x : ℕ)
| seq (s t : Stmt)
| whileDec (x : ℕ) (body : Stmt)
| ifNZ (x : ℕ) (s t : Stmt)
| ifLt (a b : ℕ) (s t : Stmt)
| divmod2 (y q r : ℕ)
| loop (body : Stmt)
| brk
⋯
ZInQKernel/Compiler/Interpreter/Structured.lean:32
inductive Outcome
| normal (ρ : Regs)
| brk (ρ : Regs)
| cont (ρ : Regs)
| exit (ρ : Regs)
ZInQKernel/Compiler/Interpreter/Structured.lean:136
inductive Exec : Stmt → Regs → Outcome → Prop
| skip (ρ) : Exec .skip ρ (.normal ρ)
| clear (x ρ) : Exec (.clear x) ρ (.normal (Function.update ρ x 0))
| inc (x ρ) (hx : x ≠ J) : Exec (.inc x) ρ (.normal (Function.update ρ x (ρ x + 1)))
| pred (x ρ) : Exec (.pred x) ρ (.normal (Function.update ρ x (ρ x - 1)))
| seq_normal {s t ρ ρ' o} : Exec s ρ (.normal ρ') → Exec t ρ' o → Exec (.seq s t) ρ o
| seq_abnormal {s t ρ o} : Exec s ρ o → o.IsAbnormal → Exec (.seq s t) ρ o
| while_zero {x b ρ} : ρ x = 0 → Exec (.whileDec x b) ρ (.normal ρ)
| while_normal {x b ρ ρ' o} : ρ x ≠ 0 →
Exec b (Function.update ρ x (ρ x - 1)) (.normal ρ') → Exec (.whileDec x b) ρ' o →
Exec (.whileDec x b) ρ o
| while_abnormal {x b ρ o} : ρ x ≠ 0 →
⋯
ZInQKernel/Compiler/Interpreter/Structured.lean:168
def CodeAt (μ : Machine) (L : ℕ) (cd : List Instr) : Prop :=
∀ k (h : k < cd.length), μ (L + k) = cd[k]
ZInQKernel/Compiler/Interpreter/Structured.lean:344
abbrev J : ℕ := 2
ZInQKernel/Compiler/Interpreter/Structured.lean:26
def ReachesIn (μ : Machine) (S : ℕ → Prop) (c c' : Config) : Prop :=
∃ t, stepN μ t c = some c' ∧ ∀ t' < t, ∃ d, stepN μ t' c = some d ∧ S d.state
ZInQKernel/Compiler/Interpreter/Structured.lean:313
def copyBlock (x y t : ℕ) : Stmt :=
seqs [clear x, clear t, whileDec y (seqs [inc x, inc t]), whileDec t (inc y)]
ZInQKernel/Compiler/Interpreter/Program.lean:32
Uses 1 · Used by 3
TheoremList blocks of the interpreter#✓
With the conventions of the arithmetic blocks, the interpreter has blocks with the following effects, each terminating after finitely many steps:
- uncons \(x\mapsto(h,t)\): if \(x=\operatorname{cons}(h,t)\) then \((h,t)\), and \((0,0)\) for \(x=\operatorname{nil}\); it copies its input first and halves a positive even value until it is odd, each halving strictly decreasing that value;
- cons \((h,t)\mapsto\operatorname{cons}(h,t)\), copying both inputs before the final write, so that aliased arguments are safe;
- getList \((L,i)\mapsto\operatorname{get}(L,i)\), following \(i\) links (reading past the end gives \(0\));
- setList \((L,i,v)\mapsto\operatorname{set}(L,i,v)\): save the traversed prefix in reverse, replace the selected entry (padding with zeros past the end), then restore the prefix; the saved list strictly decreases during restoration.
Proof sketch. Compositions of the arithmetic blocks with loops whose measures are the halved value, the remaining index and the saved reversed prefix; the effect is computed with the tape-list equations.
theorem runs_unconsBlock {x h t b : ℕ} (hxb : x < b ∨ b + 8 ≤ x) (hhb : h < b ∨ b + 8 ≤ h)
(htb : t < b ∨ b + 8 ≤ t) (hJb : J < b) (hht : h ≠ t) (hhJ : h ≠ J) (htJ : t ≠ J)
(hxh : x ≠ h) (hxt : x ≠ t) (ρ : Regs) (hJ : ρ J = 0) :
∃ ρ', Runs (unconsBlock x h t b) ρ ρ' ∧ ρ' h = (uncons (ρ x)).1 ∧
ρ' t = (uncons (ρ x)).2 ∧ Frame (fun k => k = h ∨ k = t ∨ Scratch b 8 k) ρ ρ'
theorem runs_consBlock {h t out b : ℕ} (hhb : h < b ∨ b + 11 ≤ h) (htb : t < b ∨ b + 11 ≤ t)
(houtb : out < b ∨ b + 11 ≤ out) (hJb : J < b) (houtJ : out ≠ J) (ρ : Regs)
(hJ : ρ J = 0) :
∃ ρ', Runs (consBlock h t out b) ρ ρ' ∧ ρ' out = cons (ρ h) (ρ t) ∧
Frame (fun k => k = out ∨ Scratch b 11 k) ρ ρ'
theorem runs_getStmt (σ : Regs) (hJ : σ J = 0) :
∃ σ', Runs getStmt σ σ' ∧ σ' 8 = listGet (σ 7) (σ 12) ∧
Frame (fun k => k = 8 ∨ (109 ≤ k ∧ k ≤ 131)) σ σ'
abbrev J : ℕ := 2
ZInQKernel/Compiler/Interpreter/Structured.lean:26
abbrev Regs : Type := ℕ → ℕ
ZInQKernel/Compiler/Interpreter/Structured.lean:29
def Runs (s : Stmt) (ρ ρ' : Regs) : Prop := Exec s ρ (.normal ρ')
ZInQKernel/Compiler/Interpreter/Blocks.lean:22
def unconsBlock (x h t b : ℕ) : Stmt :=
seqs [copyBlock b x (b + 3), clear h,
ifNZ b
(loop (seqs [copyBlock (b + 4) b (b + 5), clear (b + 1), divmod2 (b + 4) (b + 1) (b + 2),
ifNZ (b + 2) (seqs [copyBlock t (b + 1) (b + 6), brk])
(seqs [inc h, copyBlock b (b + 1) (b + 7), cont])]))
(clear t)]
ZInQKernel/Compiler/Interpreter/Program.lean:55
def uncons (x : ℕ) : ℕ × ℕ := (padicValNat 2 x, (x / 2 ^ padicValNat 2 x - 1) / 2)
ZInQKernel/Compiler/Interpreter/TapeLists.lean:21
def Frame (S : ℕ → Prop) (ρ ρ' : Regs) : Prop := ∀ k, ¬ S k → ρ' k = ρ k
ZInQKernel/Compiler/Interpreter/Blocks.lean:25
def Scratch (b n k : ℕ) : Prop := b ≤ k ∧ k < b + n
ZInQKernel/Compiler/Interpreter/Blocks.lean:236
def consBlock (h t out b : ℕ) : Stmt :=
seqs [copyBlock b t (b + 2), doubleBlock b (b + 3) (b + 4) (b + 5), inc b,
copyBlock (b + 1) h (b + 6), whileDec (b + 1) (doubleBlock b (b + 7) (b + 8) (b + 9)),
copyBlock out b (b + 10)]
ZInQKernel/Compiler/Interpreter/Program.lean:64
def cons (h t : ℕ) : ℕ := 2 ^ h * (2 * t + 1)
ZInQKernel/Compiler/Interpreter/TapeLists.lean:17
def getStmt : Stmt :=
seqs [copyBlock 109 7 113, copyBlock 110 12 114,
whileDec 110 (seqs [unconsBlock 109 111 112 115, copyBlock 109 112 123]),
unconsBlock 109 8 112 124]
ZInQKernel/Compiler/Interpreter/Program.lean:99
def listGet (L : ℕ) : ℕ → ℕ
| 0 => (uncons L).1
| i + 1 => listGet (uncons L).2 i
ZInQKernel/Compiler/Interpreter/TapeLists.lean:117
Uses 3 · Used by 2
DefinitionThe universal interpreter#✓
The universal interpreter \(\mathcal U\) is a primitive program with \(2\) inputs (\(e\) in register \(0\), \(n\) in register \(1\)), reserved jump register \(2\), valid for \(204\) registers, assembled from the arithmetic and list blocks. It performs:
- Decode the number. Compute \(w\) and \(D\) with \(e+1=2^w(2D+1)\) by repeated halving of \(e+1\). If \(w=0\), go to cleanup. Otherwise set \(\beta=2^w\).
- Initialize. Set the tape to \(\operatorname{cons}(n,\operatorname{nil})\) (the virtual file with \(n\) in register \(0\)) and the virtual state \(\mathrm{pc}=0\).
- Main loop. Extract the base-\(\beta\) digits \(o,j,x,y\) of \(D\) at positions \(4\mathrm{pc},\dots,4\mathrm{pc}+3\) by repeated division. If \(o=1\): replace entry \(j\) of the tape by its successor and set \(\mathrm{pc}=x\). If \(o=2\): read \(v=\operatorname{get}(\text{tape},j)\); if \(v>0\) write \(v-1\) and set \(\mathrm{pc}=x\), else write \(v=0\) back and set \(\mathrm{pc}=y\) (the entry is always written with setList, which may pad the tape with zeros). Otherwise leave the loop (a simulated halt). Return to the start of the loop.
- Cleanup. Clear all \(204\) registers and reach the final halt.
Its shape, recorded in the interpreter-shape statement, is \(1{,}399\) instructions (\(1{,}022\) sub instructions, \(376\) add instructions and the final halt) over \(204\) registers. The manuscript's interpreter is pinned only through its compiled polynomial; its program is recoverable from the saved universal circuit (state and register histories carry their indices), and the Lean definition is required to reproduce it exactly, so that the counts of the compiled circuit are those of the specification.
This is a definition.
ZInQ.Compiler.Universal.interpreter · 281 lines
def interpreter : Program := [
/- 0 -/ .dec 17 0 1, .dec 19 1 2, .dec 0 3 6, .inc 17 4, .inc 19 5,
/- 5 -/ .dec 2 2 2, .dec 19 7 9, .inc 0 8, .dec 2 6 6, .inc 17 10,
/- 10 -/ .dec 20 10 11, .dec 23 11 12, .dec 17 13 16, .inc 20 14, .inc 23 15,
/- 15 -/ .dec 2 12 12, .dec 23 17 19, .inc 17 18, .dec 2 16 16, .dec 3 19 20,
/- 20 -/ .dec 20 21 65, .inc 20 22, .dec 24 22 23, .dec 25 23 24, .dec 20 25 28,
/- 25 -/ .inc 24 26, .inc 25 27, .dec 2 24 24, .dec 25 29 31, .inc 20 30,
/- 30 -/ .dec 2 28 28, .dec 21 31 32, .dec 24 33 36, .dec 24 34 38, .inc 21 35,
/- 35 -/ .dec 2 32 32, .dec 22 36 37, .dec 2 40 40, .dec 22 38 39, .inc 22 40,
/- 40 -/ .dec 22 41 53, .inc 22 42, .dec 4 42 43, .dec 26 43 44, .dec 21 45 48,
/- 45 -/ .inc 4 46, .inc 26 47, .dec 2 44 44, .dec 26 49 51, .inc 21 50,
/- 50 -/ .dec 2 48 48, .dec 2 64 64, .dec 2 64 64, .inc 3 54, .dec 20 54 55,
/- 55 -/ .dec 27 55 56, .dec 21 57 60, .inc 20 58, .inc 27 59, .dec 2 56 56,
/- 60 -/ .dec 27 61 63, .inc 21 62, .dec 2 60 60, .dec 2 22 22, .dec 2 66 66,
/- 65 -/ .dec 4 65 66, .dec 3 67 69, .inc 3 68, .dec 2 70 70, .dec 2 1194 1194,
/- 70 -/ .dec 5 70 71, .inc 5 72, .dec 10 72 73, .dec 28 73 74, .dec 3 75 78,
/- 75 -/ .inc 10 76, .inc 28 77, .dec 2 74 74, .dec 28 79 81, .inc 3 80,
/- 80 -/ .dec 2 78 78, .dec 10 82 100, .dec 29 82 83, .dec 30 83 84, .dec 5 85 88,
/- 85 -/ .inc 29 86, .inc 30 87, .dec 2 84 84, .dec 30 89 91, .inc 5 90,
/- 90 -/ .dec 2 88 88, .dec 31 91 92, .dec 29 93 96, .inc 5 94, .inc 31 95,
/- 95 -/ .dec 2 92 92, .dec 31 97 99, .inc 29 98, .dec 2 96 96, .dec 2 81 81,
/- 100 -/ .dec 6 100 101, .dec 32 101 102, .dec 34 102 103, .dec 2 104 107, .inc 32 105,
/- 105 -/ .inc 34 106, .dec 2 103 103, .dec 34 108 110, .inc 2 109, .dec 2 107 107,
/- 110 -/ .dec 35 110 111, .dec 36 111 112, .dec 32 113 116, .inc 35 114, .inc 36 115,
/- 115 -/ .dec 2 112 112, .dec 36 117 119, .inc 32 118, .dec 2 116 116, .dec 37 119 120,
/- 120 -/ .dec 35 121 124, .inc 32 122, .inc 37 123, .dec 2 120 120, .dec 37 125 127,
/- 125 -/ .inc 35 126, .dec 2 124 124, .inc 32 128, .dec 33 128 129, .dec 38 129 130,
/- 130 -/ .dec 1 131 134, .inc 33 132, .inc 38 133, .dec 2 130 130, .dec 38 135 137,
/- 135 -/ .inc 1 136, .dec 2 134 134, .dec 33 138 156, .dec 39 138 139, .dec 40 139 140,
/- 140 -/ .dec 32 141 144, .inc 39 142, .inc 40 143, .dec 2 140 140, .dec 40 145 147,
/- 145 -/ .inc 32 146, .dec 2 144 144, .dec 41 147 148, .dec 39 149 152, .inc 32 150,
/- 150 -/ .inc 41 151, .dec 2 148 148, .dec 41 153 155, .inc 39 154, .dec 2 152 152,
/- 155 -/ .dec 2 137 137, .dec 7 156 157, .dec 42 157 158, .dec 32 159 162, .inc 7 160,
/- 160 -/ .inc 42 161, .dec 2 158 158, .dec 42 163 165, .inc 32 164, .dec 2 162 162,
/- 165 -/ .dec 9 165 166, .dec 43 166 167, .dec 4 168 171, .inc 9 169, .inc 43 170,
/- 170 -/ .dec 2 167 167, .dec 43 172 174, .inc 4 173, .dec 2 171 171, .dec 10 174 175,
/- 175 -/ .dec 44 175 176, .dec 6 177 180, .inc 10 178, .inc 44 179, .dec 2 176 176,
/- 180 -/ .dec 44 181 183, .inc 6 182, .dec 2 180 180, .dec 45 183 184, .dec 6 185 188,
/- 185 -/ .inc 10 186, .inc 45 187, .dec 2 184 184, .dec 45 189 191, .inc 6 190,
/- 190 -/ .dec 2 188 188, .dec 46 191 192, .dec 6 193 196, .inc 10 194, .inc 46 195,
/- 195 -/ .dec 2 192 192, .dec 46 197 199, .inc 6 198, .dec 2 196 196, .dec 47 199 200,
/- 200 -/ .dec 6 201 204, .inc 10 202, .inc 47 203, .dec 2 200 200, .dec 47 205 207,
/- 205 -/ .inc 6 206, .dec 2 204 204, .dec 10 208 282, .dec 48 208 209, .dec 51 209 210,
/- 210 -/ .dec 9 211 214, .inc 48 212, .inc 51 213, .dec 2 210 210, .dec 51 215 217,
/- 215 -/ .inc 9 216, .dec 2 214 214, .dec 49 217 218, .dec 52 218 219, .dec 54 219 220,
/- 220 -/ .dec 48 221 224, .inc 52 222, .inc 54 223, .dec 2 220 220, .dec 54 225 227,
/- 225 -/ .inc 48 226, .dec 2 224 224, .dec 53 227 228, .dec 55 228 229, .dec 5 230 233,
/- 230 -/ .inc 53 231, .inc 55 232, .dec 2 229 229, .dec 55 234 236, .inc 5 235,
/- 235 -/ .dec 2 233 233, .dec 53 237 240, .dec 52 236 238, .dec 2 254 254, .dec 2 254 254,
/- 240 -/ .dec 50 240 241, .dec 56 241 242, .dec 5 243 246, .inc 50 244, .inc 56 245,
/- 245 -/ .dec 2 242 242, .dec 56 247 249, .inc 5 248, .dec 2 246 246, .dec 50 250 252,
/- 250 -/ .dec 48 251 251, .dec 2 249 249, .inc 49 253, .dec 2 218 218, .dec 15 254 255,
/- 255 -/ .dec 57 255 256, .dec 49 257 260, .inc 15 258, .inc 57 259, .dec 2 256 256,
/- 260 -/ .dec 57 261 263, .inc 49 262, .dec 2 260 260, .dec 16 263 264, .dec 58 264 265,
/- 265 -/ .dec 48 266 269, .inc 16 267, .inc 58 268, .dec 2 265 265, .dec 58 270 272,
/- 270 -/ .inc 48 271, .dec 2 269 269, .dec 9 272 273, .dec 59 273 274, .dec 15 275 278,
/- 275 -/ .inc 9 276, .inc 59 277, .dec 2 274 274, .dec 59 279 281, .inc 15 280,
/- 280 -/ .dec 2 278 278, .dec 2 207 207, .dec 60 282 283, .dec 63 283 284, .dec 9 285 288,
/- 285 -/ .inc 60 286, .inc 63 287, .dec 2 284 284, .dec 63 289 291, .inc 9 290,
/- 290 -/ .dec 2 288 288, .dec 61 291 292, .dec 64 292 293, .dec 66 293 294, .dec 60 295 298,
/- 295 -/ .inc 64 296, .inc 66 297, .dec 2 294 294, .dec 66 299 301, .inc 60 300,
/- 300 -/ .dec 2 298 298, .dec 65 301 302, .dec 67 302 303, .dec 5 304 307, .inc 65 305,
/- 305 -/ .inc 67 306, .dec 2 303 303, .dec 67 308 310, .inc 5 309, .dec 2 307 307,
/- 310 -/ .dec 65 311 314, .dec 64 310 312, .dec 2 328 328, .dec 2 328 328, .dec 62 314 315,
/- 315 -/ .dec 68 315 316, .dec 5 317 320, .inc 62 318, .inc 68 319, .dec 2 316 316,
/- 320 -/ .dec 68 321 323, .inc 5 322, .dec 2 320 320, .dec 62 324 326, .dec 60 325 325,
/- 325 -/ .dec 2 323 323, .inc 61 327, .dec 2 292 292, .dec 15 328 329, .dec 69 329 330,
/- 330 -/ .dec 61 331 334, .inc 15 332, .inc 69 333, .dec 2 330 330, .dec 69 335 337,
/- 335 -/ .inc 61 336, .dec 2 334 334, .dec 11 337 338, .dec 70 338 339, .dec 60 340 343,
/- 340 -/ .inc 11 341, .inc 70 342, .dec 2 339 339, .dec 70 344 346, .inc 60 345,
/- 345 -/ .dec 2 343 343, .dec 9 346 347, .dec 71 347 348, .dec 15 349 352, .inc 9 350,
/- 350 -/ .inc 71 351, .dec 2 348 348, .dec 71 353 355, .inc 15 354, .dec 2 352 352,
/- 355 -/ .dec 72 355 356, .dec 75 356 357, .dec 9 358 361, .inc 72 359, .inc 75 360,
/- 360 -/ .dec 2 357 357, .dec 75 362 364, .inc 9 363, .dec 2 361 361, .dec 73 364 365,
/- 365 -/ .dec 76 365 366, .dec 78 366 367, .dec 72 368 371, .inc 76 369, .inc 78 370,
/- 370 -/ .dec 2 367 367, .dec 78 372 374, .inc 72 373, .dec 2 371 371, .dec 77 374 375,
/- 375 -/ .dec 79 375 376, .dec 5 377 380, .inc 77 378, .inc 79 379, .dec 2 376 376,
/- 380 -/ .dec 79 381 383, .inc 5 382, .dec 2 380 380, .dec 77 384 387, .dec 76 383 385,
/- 385 -/ .dec 2 401 401, .dec 2 401 401, .dec 74 387 388, .dec 80 388 389, .dec 5 390 393,
/- 390 -/ .inc 74 391, .inc 80 392, .dec 2 389 389, .dec 80 394 396, .inc 5 395,
/- 395 -/ .dec 2 393 393, .dec 74 397 399, .dec 72 398 398, .dec 2 396 396, .inc 73 400,
/- 400 -/ .dec 2 365 365, .dec 15 401 402, .dec 81 402 403, .dec 73 404 407, .inc 15 405,
/- 405 -/ .inc 81 406, .dec 2 403 403, .dec 81 408 410, .inc 73 409, .dec 2 407 407,
/- 410 -/ .dec 12 410 411, .dec 82 411 412, .dec 72 413 416, .inc 12 414, .inc 82 415,
/- 415 -/ .dec 2 412 412, .dec 82 417 419, .inc 72 418, .dec 2 416 416, .dec 9 419 420,
/- 420 -/ .dec 83 420 421, .dec 15 422 425, .inc 9 423, .inc 83 424, .dec 2 421 421,
/- 425 -/ .dec 83 426 428, .inc 15 427, .dec 2 425 425, .dec 84 428 429, .dec 87 429 430,
/- 430 -/ .dec 9 431 434, .inc 84 432, .inc 87 433, .dec 2 430 430, .dec 87 435 437,
/- 435 -/ .inc 9 436, .dec 2 434 434, .dec 85 437 438, .dec 88 438 439, .dec 90 439 440,
/- 440 -/ .dec 84 441 444, .inc 88 442, .inc 90 443, .dec 2 440 440, .dec 90 445 447,
/- 445 -/ .inc 84 446, .dec 2 444 444, .dec 89 447 448, .dec 91 448 449, .dec 5 450 453,
/- 450 -/ .inc 89 451, .inc 91 452, .dec 2 449 449, .dec 91 454 456, .inc 5 455,
/- 455 -/ .dec 2 453 453, .dec 89 457 460, .dec 88 456 458, .dec 2 474 474, .dec 2 474 474,
/- 460 -/ .dec 86 460 461, .dec 92 461 462, .dec 5 463 466, .inc 86 464, .inc 92 465,
/- 465 -/ .dec 2 462 462, .dec 92 467 469, .inc 5 468, .dec 2 466 466, .dec 86 470 472,
/- 470 -/ .dec 84 471 471, .dec 2 469 469, .inc 85 473, .dec 2 438 438, .dec 15 474 475,
/- 475 -/ .dec 93 475 476, .dec 85 477 480, .inc 15 478, .inc 93 479, .dec 2 476 476,
/- 480 -/ .dec 93 481 483, .inc 85 482, .dec 2 480 480, .dec 13 483 484, .dec 94 484 485,
/- 485 -/ .dec 84 486 489, .inc 13 487, .inc 94 488, .dec 2 485 485, .dec 94 490 492,
/- 490 -/ .inc 84 491, .dec 2 489 489, .dec 9 492 493, .dec 95 493 494, .dec 15 495 498,
/- 495 -/ .inc 9 496, .inc 95 497, .dec 2 494 494, .dec 95 499 501, .inc 15 500,
/- 500 -/ .dec 2 498 498, .dec 96 501 502, .dec 99 502 503, .dec 9 504 507, .inc 96 505,
/- 505 -/ .inc 99 506, .dec 2 503 503, .dec 99 508 510, .inc 9 509, .dec 2 507 507,
/- 510 -/ .dec 97 510 511, .dec 100 511 512, .dec 102 512 513, .dec 96 514 517, .inc 100 515,
/- 515 -/ .inc 102 516, .dec 2 513 513, .dec 102 518 520, .inc 96 519, .dec 2 517 517,
/- 520 -/ .dec 101 520 521, .dec 103 521 522, .dec 5 523 526, .inc 101 524, .inc 103 525,
/- 525 -/ .dec 2 522 522, .dec 103 527 529, .inc 5 528, .dec 2 526 526, .dec 101 530 533,
/- 530 -/ .dec 100 529 531, .dec 2 547 547, .dec 2 547 547, .dec 98 533 534, .dec 104 534 535,
/- 535 -/ .dec 5 536 539, .inc 98 537, .inc 104 538, .dec 2 535 535, .dec 104 540 542,
/- 540 -/ .inc 5 541, .dec 2 539 539, .dec 98 543 545, .dec 96 544 544, .dec 2 542 542,
/- 545 -/ .inc 97 546, .dec 2 511 511, .dec 15 547 548, .dec 105 548 549, .dec 97 550 553,
/- 550 -/ .inc 15 551, .inc 105 552, .dec 2 549 549, .dec 105 554 556, .inc 97 555,
/- 555 -/ .dec 2 553 553, .dec 14 556 557, .dec 106 557 558, .dec 96 559 562, .inc 14 560,
/- 560 -/ .inc 106 561, .dec 2 558 558, .dec 106 563 565, .inc 96 564, .dec 2 562 562,
/- 565 -/ .dec 9 565 566, .dec 107 566 567, .dec 15 568 571, .inc 9 569, .inc 107 570,
/- 570 -/ .dec 2 567 567, .dec 107 572 574, .inc 15 573, .dec 2 571 571, .dec 18 574 575,
/- 575 -/ .dec 108 575 576, .dec 11 577 580, .inc 18 578, .inc 108 579, .dec 2 576 576,
/- 580 -/ .dec 108 581 583, .inc 11 582, .dec 2 580 580, .dec 18 584 587, .inc 18 585,
/- 585 -/ .dec 18 586 586, .dec 2 588 588, .dec 2 1194 1194, .dec 18 589 596, .inc 18 590,
/- 590 -/ .dec 18 591 591, .dec 18 592 595, .inc 18 593, .dec 2 1194 1194, .dec 2 595 595,
/- 595 -/ .dec 2 596 596, .dec 109 596 597, .dec 113 597 598, .dec 7 599 602, .inc 109 600,
/- 600 -/ .inc 113 601, .dec 2 598 598, .dec 113 603 605, .inc 7 604, .dec 2 602 602,
/- 605 -/ .dec 110 605 606, .dec 114 606 607, .dec 12 608 611, .inc 110 609, .inc 114 610,
/- 610 -/ .dec 2 607 607, .dec 114 612 614, .inc 12 613, .dec 2 611 611, .dec 110 615 681,
/- 615 -/ .dec 115 615 616, .dec 118 616 617, .dec 109 618 621, .inc 115 619, .inc 118 620,
/- 620 -/ .dec 2 617 617, .dec 118 622 624, .inc 109 623, .dec 2 621 621, .dec 111 624 625,
/- 625 -/ .dec 115 626 670, .inc 115 627, .dec 119 627 628, .dec 120 628 629, .dec 115 630 633,
/- 630 -/ .inc 119 631, .inc 120 632, .dec 2 629 629, .dec 120 634 636, .inc 115 635,
/- 635 -/ .dec 2 633 633, .dec 116 636 637, .dec 119 638 641, .dec 119 639 643, .inc 116 640,
/- 640 -/ .dec 2 637 637, .dec 117 641 642, .dec 2 645 645, .dec 117 643 644, .inc 117 645,
/- 645 -/ .dec 117 646 658, .inc 117 647, .dec 112 647 648, .dec 121 648 649, .dec 116 650 653,
/- 650 -/ .inc 112 651, .inc 121 652, .dec 2 649 649, .dec 121 654 656, .inc 116 655,
/- 655 -/ .dec 2 653 653, .dec 2 669 669, .dec 2 669 669, .inc 111 659, .dec 115 659 660,
/- 660 -/ .dec 122 660 661, .dec 116 662 665, .inc 115 663, .inc 122 664, .dec 2 661 661,
/- 665 -/ .dec 122 666 668, .inc 116 667, .dec 2 665 665, .dec 2 627 627, .dec 2 671 671,
/- 670 -/ .dec 112 670 671, .dec 109 671 672, .dec 123 672 673, .dec 112 674 677, .inc 109 675,
/- 675 -/ .inc 123 676, .dec 2 673 673, .dec 123 678 680, .inc 112 679, .dec 2 677 677,
/- 680 -/ .dec 2 614 614, .dec 124 681 682, .dec 127 682 683, .dec 109 684 687, .inc 124 685,
/- 685 -/ .inc 127 686, .dec 2 683 683, .dec 127 688 690, .inc 109 689, .dec 2 687 687,
/- 690 -/ .dec 8 690 691, .dec 124 692 736, .inc 124 693, .dec 128 693 694, .dec 129 694 695,
/- 695 -/ .dec 124 696 699, .inc 128 697, .inc 129 698, .dec 2 695 695, .dec 129 700 702,
/- 700 -/ .inc 124 701, .dec 2 699 699, .dec 125 702 703, .dec 128 704 707, .dec 128 705 709,
/- 705 -/ .inc 125 706, .dec 2 703 703, .dec 126 707 708, .dec 2 711 711, .dec 126 709 710,
/- 710 -/ .inc 126 711, .dec 126 712 724, .inc 126 713, .dec 112 713 714, .dec 130 714 715,
/- 715 -/ .dec 125 716 719, .inc 112 717, .inc 130 718, .dec 2 715 715, .dec 130 720 722,
/- 720 -/ .inc 125 721, .dec 2 719 719, .dec 2 735 735, .dec 2 735 735, .inc 8 725,
/- 725 -/ .dec 124 725 726, .dec 131 726 727, .dec 125 728 731, .inc 124 729, .inc 131 730,
/- 730 -/ .dec 2 727 727, .dec 131 732 734, .inc 125 733, .dec 2 731 731, .dec 2 693 693,
/- 735 -/ .dec 2 737 737, .dec 112 736 737, .dec 18 737 738, .dec 132 738 739, .dec 11 740 743,
/- 740 -/ .inc 18 741, .inc 132 742, .dec 2 739 739, .dec 132 744 746, .inc 11 745,
/- 745 -/ .dec 2 743 743, .dec 18 747 747, .dec 18 748 772, .inc 18 749, .dec 8 750 762,
/- 750 -/ .inc 8 751, .dec 8 752 752, .dec 6 752 753, .dec 133 753 754, .dec 13 755 758,
/- 755 -/ .inc 6 756, .inc 133 757, .dec 2 754 754, .dec 133 759 761, .inc 13 760,
/- 760 -/ .dec 2 758 758, .dec 2 771 771, .dec 6 762 763, .dec 134 763 764, .dec 14 765 768,
/- 765 -/ .inc 6 766, .inc 134 767, .dec 2 764 764, .dec 134 769 771, .inc 14 770,
/- 770 -/ .dec 2 768 768, .dec 2 782 782, .inc 8 773, .dec 6 773 774, .dec 135 774 775,
/- 775 -/ .dec 13 776 779, .inc 6 777, .inc 135 778, .dec 2 775 775, .dec 135 780 782,
/- 780 -/ .inc 13 781, .dec 2 779 779, .dec 136 782 783, .dec 142 783 784, .dec 7 785 788,
/- 785 -/ .inc 136 786, .inc 142 787, .dec 2 784 784, .dec 142 789 791, .inc 7 790,
/- 790 -/ .dec 2 788 788, .dec 137 791 792, .dec 143 792 793, .dec 12 794 797, .inc 137 795,
/- 795 -/ .inc 143 796, .dec 2 793 793, .dec 143 798 800, .inc 12 799, .dec 2 797 797,
/- 800 -/ .dec 138 800 801, .dec 137 802 932, .dec 144 802 803, .dec 147 803 804, .dec 136 805 808,
/- 805 -/ .inc 144 806, .inc 147 807, .dec 2 804 804, .dec 147 809 811, .inc 136 810,
/- 810 -/ .dec 2 808 808, .dec 139 811 812, .dec 144 813 857, .inc 144 814, .dec 148 814 815,
/- 815 -/ .dec 149 815 816, .dec 144 817 820, .inc 148 818, .inc 149 819, .dec 2 816 816,
/- 820 -/ .dec 149 821 823, .inc 144 822, .dec 2 820 820, .dec 145 823 824, .dec 148 825 828,
/- 825 -/ .dec 148 826 830, .inc 145 827, .dec 2 824 824, .dec 146 828 829, .dec 2 832 832,
/- 830 -/ .dec 146 830 831, .inc 146 832, .dec 146 833 845, .inc 146 834, .dec 140 834 835,
/- 835 -/ .dec 150 835 836, .dec 145 837 840, .inc 140 838, .inc 150 839, .dec 2 836 836,
/- 840 -/ .dec 150 841 843, .inc 145 842, .dec 2 840 840, .dec 2 856 856, .dec 2 856 856,
/- 845 -/ .inc 139 846, .dec 144 846 847, .dec 151 847 848, .dec 145 849 852, .inc 144 850,
/- 850 -/ .inc 151 851, .dec 2 848 848, .dec 151 853 855, .inc 145 854, .dec 2 852 852,
/- 855 -/ .dec 2 814 814, .dec 2 858 858, .dec 140 857 858, .dec 152 858 859, .dec 154 859 860,
/- 860 -/ .dec 138 861 864, .inc 152 862, .inc 154 863, .dec 2 860 860, .dec 154 865 867,
/- 865 -/ .inc 138 866, .dec 2 864 864, .dec 155 867 868, .dec 156 868 869, .dec 152 870 873,
/- 870 -/ .inc 155 871, .inc 156 872, .dec 2 869 869, .dec 156 874 876, .inc 152 875,
/- 875 -/ .dec 2 873 873, .dec 157 876 877, .dec 155 878 881, .inc 152 879, .inc 157 880,
/- 880 -/ .dec 2 877 877, .dec 157 882 884, .inc 155 883, .dec 2 881 881, .inc 152 885,
/- 885 -/ .dec 153 885 886, .dec 158 886 887, .dec 139 888 891, .inc 153 889, .inc 158 890,
/- 890 -/ .dec 2 887 887, .dec 158 892 894, .inc 139 893, .dec 2 891 891, .dec 153 895 913,
/- 895 -/ .dec 159 895 896, .dec 160 896 897, .dec 152 898 901, .inc 159 899, .inc 160 900,
/- 900 -/ .dec 2 897 897, .dec 160 902 904, .inc 152 903, .dec 2 901 901, .dec 161 904 905,
/- 905 -/ .dec 159 906 909, .inc 152 907, .inc 161 908, .dec 2 905 905, .dec 161 910 912,
/- 910 -/ .inc 159 911, .dec 2 909 909, .dec 2 894 894, .dec 138 913 914, .dec 162 914 915,
/- 915 -/ .dec 152 916 919, .inc 138 917, .inc 162 918, .dec 2 915 915, .dec 162 920 922,
/- 920 -/ .inc 152 921, .dec 2 919 919, .dec 136 922 923, .dec 163 923 924, .dec 140 925 928,
/- 925 -/ .inc 136 926, .inc 163 927, .dec 2 924 924, .dec 163 929 931, .inc 140 930,
/- 930 -/ .dec 2 928 928, .dec 2 801 801, .dec 164 932 933, .dec 167 933 934, .dec 136 935 938,
/- 935 -/ .inc 164 936, .inc 167 937, .dec 2 934 934, .dec 167 939 941, .inc 136 940,
/- 940 -/ .dec 2 938 938, .dec 139 941 942, .dec 164 943 987, .inc 164 944, .dec 168 944 945,
/- 945 -/ .dec 169 945 946, .dec 164 947 950, .inc 168 948, .inc 169 949, .dec 2 946 946,
/- 950 -/ .dec 169 951 953, .inc 164 952, .dec 2 950 950, .dec 165 953 954, .dec 168 955 958,
/- 955 -/ .dec 168 956 960, .inc 165 957, .dec 2 954 954, .dec 166 958 959, .dec 2 962 962,
/- 960 -/ .dec 166 960 961, .inc 166 962, .dec 166 963 975, .inc 166 964, .dec 140 964 965,
/- 965 -/ .dec 170 965 966, .dec 165 967 970, .inc 140 968, .inc 170 969, .dec 2 966 966,
/- 970 -/ .dec 170 971 973, .inc 165 972, .dec 2 970 970, .dec 2 986 986, .dec 2 986 986,
/- 975 -/ .inc 139 976, .dec 164 976 977, .dec 171 977 978, .dec 165 979 982, .inc 164 980,
/- 980 -/ .inc 171 981, .dec 2 978 978, .dec 171 983 985, .inc 165 984, .dec 2 982 982,
/- 985 -/ .dec 2 944 944, .dec 2 988 988, .dec 140 987 988, .dec 172 988 989, .dec 174 989 990,
/- 990 -/ .dec 140 991 994, .inc 172 992, .inc 174 993, .dec 2 990 990, .dec 174 995 997,
/- 995 -/ .inc 140 996, .dec 2 994 994, .dec 175 997 998, .dec 176 998 999, .dec 172 1000 1003,
/- 1000 -/ .inc 175 1001, .inc 176 1002, .dec 2 999 999, .dec 176 1004 1006, .inc 172 1005,
/- 1005 -/ .dec 2 1003 1003, .dec 177 1006 1007, .dec 175 1008 1011, .inc 172 1009, .inc 177 1010,
/- 1010 -/ .dec 2 1007 1007, .dec 177 1012 1014, .inc 175 1013, .dec 2 1011 1011, .inc 172 1015,
/- 1015 -/ .dec 173 1015 1016, .dec 178 1016 1017, .dec 8 1018 1021, .inc 173 1019, .inc 178 1020,
/- 1020 -/ .dec 2 1017 1017, .dec 178 1022 1024, .inc 8 1023, .dec 2 1021 1021, .dec 173 1025 1043,
/- 1025 -/ .dec 179 1025 1026, .dec 180 1026 1027, .dec 172 1028 1031, .inc 179 1029, .inc 180 1030,
/- 1030 -/ .dec 2 1027 1027, .dec 180 1032 1034, .inc 172 1033, .dec 2 1031 1031, .dec 181 1034 1035,
/- 1035 -/ .dec 179 1036 1039, .inc 172 1037, .inc 181 1038, .dec 2 1035 1035, .dec 181 1040 1042,
/- 1040 -/ .inc 179 1041, .dec 2 1039 1039, .dec 2 1024 1024, .dec 141 1043 1044, .dec 182 1044 1045,
/- 1045 -/ .dec 172 1046 1049, .inc 141 1047, .inc 182 1048, .dec 2 1045 1045, .dec 182 1050 1052,
/- 1050 -/ .inc 172 1051, .dec 2 1049 1049, .dec 138 1053 1184, .inc 138 1054, .dec 183 1054 1055,
/- 1055 -/ .dec 186 1055 1056, .dec 138 1057 1060, .inc 183 1058, .inc 186 1059, .dec 2 1056 1056,
/- 1060 -/ .dec 186 1061 1063, .inc 138 1062, .dec 2 1060 1060, .dec 139 1063 1064, .dec 183 1065 1109,
/- 1065 -/ .inc 183 1066, .dec 187 1066 1067, .dec 188 1067 1068, .dec 183 1069 1072, .inc 187 1070,
/- 1070 -/ .inc 188 1071, .dec 2 1068 1068, .dec 188 1073 1075, .inc 183 1074, .dec 2 1072 1072,
/- 1075 -/ .dec 184 1075 1076, .dec 187 1077 1080, .dec 187 1078 1082, .inc 184 1079, .dec 2 1076 1076,
/- 1080 -/ .dec 185 1080 1081, .dec 2 1084 1084, .dec 185 1082 1083, .inc 185 1084, .dec 185 1085 1097,
/- 1085 -/ .inc 185 1086, .dec 140 1086 1087, .dec 189 1087 1088, .dec 184 1089 1092, .inc 140 1090,
/- 1090 -/ .inc 189 1091, .dec 2 1088 1088, .dec 189 1093 1095, .inc 184 1094, .dec 2 1092 1092,
/- 1095 -/ .dec 2 1108 1108, .dec 2 1108 1108, .inc 139 1098, .dec 183 1098 1099, .dec 190 1099 1100,
/- 1100 -/ .dec 184 1101 1104, .inc 183 1102, .inc 190 1103, .dec 2 1100 1100, .dec 190 1105 1107,
/- 1105 -/ .inc 184 1106, .dec 2 1104 1104, .dec 2 1066 1066, .dec 2 1110 1110, .dec 140 1109 1110,
/- 1110 -/ .dec 191 1110 1111, .dec 193 1111 1112, .dec 141 1113 1116, .inc 191 1114, .inc 193 1115,
/- 1115 -/ .dec 2 1112 1112, .dec 193 1117 1119, .inc 141 1118, .dec 2 1116 1116, .dec 194 1119 1120,
/- 1120 -/ .dec 195 1120 1121, .dec 191 1122 1125, .inc 194 1123, .inc 195 1124, .dec 2 1121 1121,
/- 1125 -/ .dec 195 1126 1128, .inc 191 1127, .dec 2 1125 1125, .dec 196 1128 1129, .dec 194 1130 1133,
/- 1130 -/ .inc 191 1131, .inc 196 1132, .dec 2 1129 1129, .dec 196 1134 1136, .inc 194 1135,
/- 1135 -/ .dec 2 1133 1133, .inc 191 1137, .dec 192 1137 1138, .dec 197 1138 1139, .dec 139 1140 1143,
/- 1140 -/ .inc 192 1141, .inc 197 1142, .dec 2 1139 1139, .dec 197 1144 1146, .inc 139 1145,
/- 1145 -/ .dec 2 1143 1143, .dec 192 1147 1165, .dec 198 1147 1148, .dec 199 1148 1149, .dec 191 1150 1153,
/- 1150 -/ .inc 198 1151, .inc 199 1152, .dec 2 1149 1149, .dec 199 1154 1156, .inc 191 1155,
/- 1155 -/ .dec 2 1153 1153, .dec 200 1156 1157, .dec 198 1158 1161, .inc 191 1159, .inc 200 1160,
/- 1160 -/ .dec 2 1157 1157, .dec 200 1162 1164, .inc 198 1163, .dec 2 1161 1161, .dec 2 1146 1146,
/- 1165 -/ .dec 141 1165 1166, .dec 201 1166 1167, .dec 191 1168 1171, .inc 141 1169, .inc 201 1170,
/- 1170 -/ .dec 2 1167 1167, .dec 201 1172 1174, .inc 191 1173, .dec 2 1171 1171, .dec 138 1174 1175,
/- 1175 -/ .dec 202 1175 1176, .dec 140 1177 1180, .inc 138 1178, .inc 202 1179, .dec 2 1176 1176,
/- 1180 -/ .dec 202 1181 1183, .inc 140 1182, .dec 2 1180 1180, .dec 2 1052 1052, .dec 7 1184 1185,
/- 1185 -/ .dec 203 1185 1186, .dec 141 1187 1190, .inc 7 1188, .inc 203 1189, .dec 2 1186 1186,
/- 1190 -/ .dec 203 1191 1193, .inc 141 1192, .dec 2 1190 1190, .dec 2 165 165, .dec 0 1194 1195,
/- 1195 -/ .dec 1 1195 1196, .dec 2 1196 1197, .dec 3 1197 1198, .dec 4 1198 1199, .dec 5 1199 1200,
/- 1200 -/ .dec 6 1200 1201, .dec 7 1201 1202, .dec 8 1202 1203, .dec 9 1203 1204, .dec 10 1204 1205,
/- 1205 -/ .dec 11 1205 1206, .dec 12 1206 1207, .dec 13 1207 1208, .dec 14 1208 1209, .dec 15 1209 1210,
/- 1210 -/ .dec 16 1210 1211, .dec 17 1211 1212, .dec 18 1212 1213, .dec 19 1213 1214, .dec 20 1214 1215,
/- 1215 -/ .dec 21 1215 1216, .dec 22 1216 1217, .dec 23 1217 1218, .dec 24 1218 1219, .dec 25 1219 1220,
/- 1220 -/ .dec 26 1220 1221, .dec 27 1221 1222, .dec 28 1222 1223, .dec 29 1223 1224, .dec 30 1224 1225,
/- 1225 -/ .dec 31 1225 1226, .dec 32 1226 1227, .dec 33 1227 1228, .dec 34 1228 1229, .dec 35 1229 1230,
/- 1230 -/ .dec 36 1230 1231, .dec 37 1231 1232, .dec 38 1232 1233, .dec 39 1233 1234, .dec 40 1234 1235,
/- 1235 -/ .dec 41 1235 1236, .dec 42 1236 1237, .dec 43 1237 1238, .dec 44 1238 1239, .dec 45 1239 1240,
/- 1240 -/ .dec 46 1240 1241, .dec 47 1241 1242, .dec 48 1242 1243, .dec 49 1243 1244, .dec 50 1244 1245,
/- 1245 -/ .dec 51 1245 1246, .dec 52 1246 1247, .dec 53 1247 1248, .dec 54 1248 1249, .dec 55 1249 1250,
/- 1250 -/ .dec 56 1250 1251, .dec 57 1251 1252, .dec 58 1252 1253, .dec 59 1253 1254, .dec 60 1254 1255,
/- 1255 -/ .dec 61 1255 1256, .dec 62 1256 1257, .dec 63 1257 1258, .dec 64 1258 1259, .dec 65 1259 1260,
/- 1260 -/ .dec 66 1260 1261, .dec 67 1261 1262, .dec 68 1262 1263, .dec 69 1263 1264, .dec 70 1264 1265,
/- 1265 -/ .dec 71 1265 1266, .dec 72 1266 1267, .dec 73 1267 1268, .dec 74 1268 1269, .dec 75 1269 1270,
/- 1270 -/ .dec 76 1270 1271, .dec 77 1271 1272, .dec 78 1272 1273, .dec 79 1273 1274, .dec 80 1274 1275,
/- 1275 -/ .dec 81 1275 1276, .dec 82 1276 1277, .dec 83 1277 1278, .dec 84 1278 1279, .dec 85 1279 1280,
/- 1280 -/ .dec 86 1280 1281, .dec 87 1281 1282, .dec 88 1282 1283, .dec 89 1283 1284, .dec 90 1284 1285,
/- 1285 -/ .dec 91 1285 1286, .dec 92 1286 1287, .dec 93 1287 1288, .dec 94 1288 1289, .dec 95 1289 1290,
/- 1290 -/ .dec 96 1290 1291, .dec 97 1291 1292, .dec 98 1292 1293, .dec 99 1293 1294, .dec 100 1294 1295,
/- 1295 -/ .dec 101 1295 1296, .dec 102 1296 1297, .dec 103 1297 1298, .dec 104 1298 1299, .dec 105 1299 1300,
/- 1300 -/ .dec 106 1300 1301, .dec 107 1301 1302, .dec 108 1302 1303, .dec 109 1303 1304, .dec 110 1304 1305,
/- 1305 -/ .dec 111 1305 1306, .dec 112 1306 1307, .dec 113 1307 1308, .dec 114 1308 1309, .dec 115 1309 1310,
/- 1310 -/ .dec 116 1310 1311, .dec 117 1311 1312, .dec 118 1312 1313, .dec 119 1313 1314, .dec 120 1314 1315,
/- 1315 -/ .dec 121 1315 1316, .dec 122 1316 1317, .dec 123 1317 1318, .dec 124 1318 1319, .dec 125 1319 1320,
/- 1320 -/ .dec 126 1320 1321, .dec 127 1321 1322, .dec 128 1322 1323, .dec 129 1323 1324, .dec 130 1324 1325,
/- 1325 -/ .dec 131 1325 1326, .dec 132 1326 1327, .dec 133 1327 1328, .dec 134 1328 1329, .dec 135 1329 1330,
/- 1330 -/ .dec 136 1330 1331, .dec 137 1331 1332, .dec 138 1332 1333, .dec 139 1333 1334, .dec 140 1334 1335,
/- 1335 -/ .dec 141 1335 1336, .dec 142 1336 1337, .dec 143 1337 1338, .dec 144 1338 1339, .dec 145 1339 1340,
/- 1340 -/ .dec 146 1340 1341, .dec 147 1341 1342, .dec 148 1342 1343, .dec 149 1343 1344, .dec 150 1344 1345,
/- 1345 -/ .dec 151 1345 1346, .dec 152 1346 1347, .dec 153 1347 1348, .dec 154 1348 1349, .dec 155 1349 1350,
/- 1350 -/ .dec 156 1350 1351, .dec 157 1351 1352, .dec 158 1352 1353, .dec 159 1353 1354, .dec 160 1354 1355,
/- 1355 -/ .dec 161 1355 1356, .dec 162 1356 1357, .dec 163 1357 1358, .dec 164 1358 1359, .dec 165 1359 1360,
/- 1360 -/ .dec 166 1360 1361, .dec 167 1361 1362, .dec 168 1362 1363, .dec 169 1363 1364, .dec 170 1364 1365,
/- 1365 -/ .dec 171 1365 1366, .dec 172 1366 1367, .dec 173 1367 1368, .dec 174 1368 1369, .dec 175 1369 1370,
/- 1370 -/ .dec 176 1370 1371, .dec 177 1371 1372, .dec 178 1372 1373, .dec 179 1373 1374, .dec 180 1374 1375,
/- 1375 -/ .dec 181 1375 1376, .dec 182 1376 1377, .dec 183 1377 1378, .dec 184 1378 1379, .dec 185 1379 1380,
/- 1380 -/ .dec 186 1380 1381, .dec 187 1381 1382, .dec 188 1382 1383, .dec 189 1383 1384, .dec 190 1384 1385,
/- 1385 -/ .dec 191 1385 1386, .dec 192 1386 1387, .dec 193 1387 1388, .dec 194 1388 1389, .dec 195 1389 1390,
/- 1390 -/ .dec 196 1390 1391, .dec 197 1391 1392, .dec 198 1392 1393, .dec 199 1393 1394, .dec 200 1394 1395,
/- 1395 -/ .dec 201 1395 1396, .dec 202 1396 1397, .dec 203 1397 1398, .halt]
abbrev Program : Type := List Instr
ZInQKernel/Compiler/Circuits/RegisterMachine.lean:60
Uses 3 · Used by 4
TheoremOne interpreter loop simulates one instruction#✓
Call a configuration of \(\mathcal U\) coherent with a virtual configuration \((i,\rho)\) of \(\mu_e\) when it is at the entry of the main loop, registers hold \(w\ge1\), \(D\) and \(\beta=2^w\) of \(e\), the virtual state register holds \(\mathrm{pc}=i\), the tape register holds a list code representing \(\rho\), the jump register is zero, and every register from \(204\) on is zero; the scratch registers below \(204\) are arbitrary. From a coherent configuration:
- if \(\mu_e(i)=\mathrm{halt}\), the run of \(\mathcal U\) reaches the cleanup entry after finitely many steps;
- otherwise it returns, after at least one and finitely many steps and without passing through cleanup (every configuration on the way is at a state of the main loop, from \(165\) to \(1193\)), to a configuration coherent with the successor of \((i,\rho)\) under \(\mu_e\).
Proof sketch. Compose the block contracts: digit extraction by repeated division yields exactly \(d_{4i},\dots,d_{4i+3}\) (missing digits are zero); the opcode test admits exactly \(1\) and \(2\); getList and setList realize the read and the update of entry \(j\); copies restore their sources, the jump register stays zero, and no block writes a register from \(204\) on, so the invariant registers are preserved. Every block terminates, so one loop iteration executes exactly one decoded instruction with finite work.
theorem interpreter_step {e : ℕ} {vc σ : Config} (h : Coherent e vc σ) :
(decodeMachine e vc.state = .halt →
∃ ρ', Reaches interpreter.toMachine σ ⟨cleanupEntry, ρ'⟩ ∧ ρ' J = 0 ∧
∀ k, 204 ≤ k → ρ' k = 0) ∧
(∀ vc', step (decodeMachine e) vc = some vc' →
∃ t σ', stepN interpreter.toMachine (t + 1) σ = some σ' ∧ Coherent e vc' σ' ∧
∀ t' ≤ t, ∃ d, stepN interpreter.toMachine t' σ = some d ∧
loopStart ≤ d.state ∧ d.state < cleanupEntry)
theorem exec_stepStmt {e : ℕ} {vc : Config} {ρ : Regs} (h : CoherentRegs e vc ρ) :
(decodeMachine e vc.state = .halt → ∃ ρ', Exec stepStmt ρ (.exit ρ')) ∧
(∀ vc', step (decodeMachine e) vc = some vc' →
∃ ρ', Runs stepStmt ρ ρ' ∧ CoherentRegs e vc' ρ')
structure Config where
/-- The current state. -/
state : ℕ
/-- The register file. -/
regs : ℕ → ℕ
ZInQKernel/Compiler/Circuits/RegisterMachine.lean:36
def Coherent (e : ℕ) (vc σ : Config) : Prop := σ.state = loopStart ∧ CoherentRegs e vc σ.regs
ZInQKernel/Compiler/Interpreter/Step.lean:38
def decodeMachine (e : ℕ) : Machine := fun i =>
if (split2 e).1 = 0 then .halt else
decodeInstr (digit (split2 e).1 (split2 e).2 (4 * i))
(digit (split2 e).1 (split2 e).2 (4 * i + 1))
(digit (split2 e).1 (split2 e).2 (4 * i + 2))
(digit (split2 e).1 (split2 e).2 (4 * i + 3))
ZInQKernel/Compiler/Interpreter/Numbering.lean:36
def Reaches (μ : Machine) (c c' : Config) : Prop := ∃ t, stepN μ t c = some c'
ZInQKernel/Compiler/Interpreter/Structured.lean:298
def interpreter : Program := [
/- 0 -/ .dec 17 0 1, .dec 19 1 2, .dec 0 3 6, .inc 17 4, .inc 19 5,
/- 5 -/ .dec 2 2 2, .dec 19 7 9, .inc 0 8, .dec 2 6 6, .inc 17 10,
/- 10 -/ .dec 20 10 11, .dec 23 11 12, .dec 17 13 16, .inc 20 14, .inc 23 15,
/- 15 -/ .dec 2 12 12, .dec 23 17 19, .inc 17 18, .dec 2 16 16, .dec 3 19 20,
/- 20 -/ .dec 20 21 65, .inc 20 22, .dec 24 22 23, .dec 25 23 24, .dec 20 25 28,
/- 25 -/ .inc 24 26, .inc 25 27, .dec 2 24 24, .dec 25 29 31, .inc 20 30,
/- 30 -/ .dec 2 28 28, .dec 21 31 32, .dec 24 33 36, .dec 24 34 38, .inc 21 35,
/- 35 -/ .dec 2 32 32, .dec 22 36 37, .dec 2 40 40, .dec 22 38 39, .inc 22 40,
/- 40 -/ .dec 22 41 53, .inc 22 42, .dec 4 42 43, .dec 26 43 44, .dec 21 45 48,
/- 45 -/ .inc 4 46, .inc 26 47, .dec 2 44 44, .dec 26 49 51, .inc 21 50,
/- 50 -/ .dec 2 48 48, .dec 2 64 64, .dec 2 64 64, .inc 3 54, .dec 20 54 55,
⋯
ZInQKernel/Compiler/Universal/Interpreter.lean:34
abbrev cleanupEntry : ℕ := 1194
ZInQKernel/Compiler/Interpreter/Program.lean:134
abbrev J : ℕ := 2
ZInQKernel/Compiler/Interpreter/Structured.lean:26
def step (μ : Machine) (c : Config) : Option Config :=
match μ c.state with
| .inc j x => some ⟨x, Function.update c.regs j (c.regs j + 1)⟩
| .dec j x y =>
if c.regs j = 0 then some ⟨y, c.regs⟩ else some ⟨x, Function.update c.regs j (c.regs j - 1)⟩
| .halt => none
ZInQKernel/Compiler/Circuits/RegisterMachine.lean:43
def stepN (μ : Machine) : ℕ → Config → Option Config
| 0, c => some c
| n + 1, c => (step μ c).bind (stepN μ n)
ZInQKernel/Compiler/Circuits/RegisterMachine.lean:51
abbrev loopStart : ℕ := 165
ZInQKernel/Compiler/Interpreter/Step.lean:23
abbrev Regs : Type := ℕ → ℕ
ZInQKernel/Compiler/Interpreter/Structured.lean:29
structure CoherentRegs (e : ℕ) (vc : Config) (ρ : Regs) : Prop where
w_pos : (split2 e).1 ≠ 0
w : ρ 3 = (split2 e).1
D : ρ 4 = (split2 e).2
β : ρ 5 = 2 ^ (split2 e).1
pc : ρ 6 = vc.state
tape : Represents vc.regs (ρ 7)
J : ρ J = 0
high : ∀ k, 204 ≤ k → ρ k = 0
ZInQKernel/Compiler/Interpreter/Step.lean:27
inductive Exec : Stmt → Regs → Outcome → Prop
| skip (ρ) : Exec .skip ρ (.normal ρ)
| clear (x ρ) : Exec (.clear x) ρ (.normal (Function.update ρ x 0))
| inc (x ρ) (hx : x ≠ J) : Exec (.inc x) ρ (.normal (Function.update ρ x (ρ x + 1)))
| pred (x ρ) : Exec (.pred x) ρ (.normal (Function.update ρ x (ρ x - 1)))
| seq_normal {s t ρ ρ' o} : Exec s ρ (.normal ρ') → Exec t ρ' o → Exec (.seq s t) ρ o
| seq_abnormal {s t ρ o} : Exec s ρ o → o.IsAbnormal → Exec (.seq s t) ρ o
| while_zero {x b ρ} : ρ x = 0 → Exec (.whileDec x b) ρ (.normal ρ)
| while_normal {x b ρ ρ' o} : ρ x ≠ 0 →
Exec b (Function.update ρ x (ρ x - 1)) (.normal ρ') → Exec (.whileDec x b) ρ' o →
Exec (.whileDec x b) ρ o
| while_abnormal {x b ρ o} : ρ x ≠ 0 →
⋯
ZInQKernel/Compiler/Interpreter/Structured.lean:168
def stepStmt : Stmt := seqs [fetchStmt, opcodeStmt, getStmt, execStmt, setStmt]
ZInQKernel/Compiler/Interpreter/Program.lean:122
def Runs (s : Stmt) (ρ ρ' : Regs) : Prop := Exec s ρ (.normal ρ')
ZInQKernel/Compiler/Interpreter/Blocks.lean:22
Uses 5 · Used by 1
TheoremCorrectness of the universal interpreter#✓
For all \(e,n\in\mathbb N\): $\(\mathcal U\text{ accepts }(e,n)\iff\operatorname{halts}(e,n).\)$ That is, the interpreter reaches its final halt with all \(204\) registers zero exactly when the program numbered \(e\) halts on \(n\); the virtual final tape need not be zero.
Proof sketch. If \(w=0\), both sides hold (the decoding step goes to cleanup; \(\mu_e\) halts at once). Let \(w\ge1\). After decoding and initialization, the run is coherent with the initial virtual configuration. (\(\Leftarrow\)) If the virtual run halts after \(t\) steps, \(t\) applications of the step statement reach a configuration coherent with a halting virtual state, from which cleanup is reached; cleanup clears every register and halts. (\(\Rightarrow\)) The machine is deterministic. If the virtual run never halts, the step statement gives configurations coherent with it at arbitrarily late times, each loop iteration taking at least one step, so the interpreter never stops. Hence acceptance implies virtual halting.
theorem interpreter_accepts_iff (e n : ℕ) : interpreter.Accepts ![e, n] ↔ halts e n
def interpreter : Program := [
/- 0 -/ .dec 17 0 1, .dec 19 1 2, .dec 0 3 6, .inc 17 4, .inc 19 5,
/- 5 -/ .dec 2 2 2, .dec 19 7 9, .inc 0 8, .dec 2 6 6, .inc 17 10,
/- 10 -/ .dec 20 10 11, .dec 23 11 12, .dec 17 13 16, .inc 20 14, .inc 23 15,
/- 15 -/ .dec 2 12 12, .dec 23 17 19, .inc 17 18, .dec 2 16 16, .dec 3 19 20,
/- 20 -/ .dec 20 21 65, .inc 20 22, .dec 24 22 23, .dec 25 23 24, .dec 20 25 28,
/- 25 -/ .inc 24 26, .inc 25 27, .dec 2 24 24, .dec 25 29 31, .inc 20 30,
/- 30 -/ .dec 2 28 28, .dec 21 31 32, .dec 24 33 36, .dec 24 34 38, .inc 21 35,
/- 35 -/ .dec 2 32 32, .dec 22 36 37, .dec 2 40 40, .dec 22 38 39, .inc 22 40,
/- 40 -/ .dec 22 41 53, .inc 22 42, .dec 4 42 43, .dec 26 43 44, .dec 21 45 48,
/- 45 -/ .inc 4 46, .inc 26 47, .dec 2 44 44, .dec 26 49 51, .inc 21 50,
/- 50 -/ .dec 2 48 48, .dec 2 64 64, .dec 2 64 64, .inc 3 54, .dec 20 54 55,
⋯
ZInQKernel/Compiler/Universal/Interpreter.lean:34
def halts (e n : ℕ) : Prop := RM.Halts (decodeMachine e) (initFile ![n])
ZInQKernel/Compiler/Interpreter/Numbering.lean:45
Uses 7 · Used by 1
The shape of the explicit interpreter, including the structure of its cleanup stage, is a finite check.
TheoremShape of the universal interpreter#✓
The universal interpreter \(\mathcal U\) satisfies the following closed decidable statements:
- it is valid for \(204\) registers: it has \(m=1{,}399\) instructions, its final instruction (state \(1398\)) is its only halt, every register index is below \(204\) and every target is below \(1{,}399\);
- it has \(s=1{,}022\) sub instructions and \(376\) add instructions;
- its cleanup stage is the block of states \(1194,\dots,1398\): for \(0\le j<204\) the instruction at state \(1194+j\) is \(\mathrm{dec}(j,\,1194+j,\,1195+j)\), and state \(1398\) is the final halt;
- the states below \(1194\) having a target at least \(1194\) are exactly \(69\), \(587\) and \(593\), and each of them is \(\mathrm{dec}(2,1194,1194)\) (an unconditional jump to the first cleanup state through the jump register \(2\)).
In the structured definition of \(\mathcal U\), state \(69\) is the exit of the decoding step on \(w=0\) and states \(587\), \(593\) are the exits of the main loop on a simulated halt; items 3 and 4 are what the correctness proof uses to say that the final halt is reached only through cleanup. The numbers are those of the manuscript's interpreter, recovered from the saved universal circuit (its state and register histories carry their indices); the Lean definition is required to reproduce them.
This is a finite computation on the explicit \(1{,}399\)-instruction program.
theorem interpreter_shape :
interpreter.Valid 204 ∧ interpreter.length = 1399 ∧ interpreter[1398]? = some .halt ∧
interpreter.subCount = 1022 ∧ interpreter.addCount = 376 ∧
(∀ j < 204, interpreter[1194 + j]? = some (.dec j (1194 + j) (1195 + j))) ∧
(∀ i < 1194, ∀ ins, interpreter[i]? = some ins →
((∃ t ∈ instrTargets ins, 1194 ≤ t) ↔ i = 69 ∨ i = 587 ∨ i = 593)) ∧
(∀ i, i = 69 ∨ i = 587 ∨ i = 593 → interpreter[i]? = some (.dec 2 1194 1194))
def interpreter : Program := [
/- 0 -/ .dec 17 0 1, .dec 19 1 2, .dec 0 3 6, .inc 17 4, .inc 19 5,
/- 5 -/ .dec 2 2 2, .dec 19 7 9, .inc 0 8, .dec 2 6 6, .inc 17 10,
/- 10 -/ .dec 20 10 11, .dec 23 11 12, .dec 17 13 16, .inc 20 14, .inc 23 15,
/- 15 -/ .dec 2 12 12, .dec 23 17 19, .inc 17 18, .dec 2 16 16, .dec 3 19 20,
/- 20 -/ .dec 20 21 65, .inc 20 22, .dec 24 22 23, .dec 25 23 24, .dec 20 25 28,
/- 25 -/ .inc 24 26, .inc 25 27, .dec 2 24 24, .dec 25 29 31, .inc 20 30,
/- 30 -/ .dec 2 28 28, .dec 21 31 32, .dec 24 33 36, .dec 24 34 38, .inc 21 35,
/- 35 -/ .dec 2 32 32, .dec 22 36 37, .dec 2 40 40, .dec 22 38 39, .inc 22 40,
/- 40 -/ .dec 22 41 53, .inc 22 42, .dec 4 42 43, .dec 26 43 44, .dec 21 45 48,
/- 45 -/ .inc 4 46, .inc 26 47, .dec 2 44 44, .dec 26 49 51, .inc 21 50,
/- 50 -/ .dec 2 48 48, .dec 2 64 64, .dec 2 64 64, .inc 3 54, .dec 20 54 55,
⋯
ZInQKernel/Compiler/Universal/Interpreter.lean:34
def instrTargets : Instr → List ℕ
| .inc _ x => [x]
| .dec _ x y => [x, y]
| .halt => []
ZInQKernel/Compiler/Universal/Shape.lean:28
Uses 2 · Used by 3
Compiling the interpreter gives the universal halting circuit, with natural zeros exactly at the halting pairs. Its numbers of variables and calls follow from the shape by the counting statement of the packed construction; its node statistics, and those of the power template, are a finite check on the two explicit constructions.
DefinitionThe universal halting circuit#✓
The universal halting circuit \(\mathcal H\) is the compiled circuit \(\mathcal C_{\mathcal U,2}\) of the packed-history construction of the universal interpreter with \(r=204\) registers and \(k=2\) inputs \(e=X_0\), \(n=X_1\): a natural circuit whose explicit variables are the inputs \(X_0,X_1\) followed by the fresh variables of the construction, whose call nodes are the power calls of the construction with their private blocks of \(79\) variables, and whose root is the encoding of the conjunction of the construction. Its node list begins with the variable nodes of \(e\) and \(n\); the program literal of the interpreter does not occur in it (the interpreter is compiled, the interpreted program is an input). Its numbers of variables, calls and nodes are recorded in the counting statement and the node-statistics check.
This is a definition.
def haltingCircuit : NatCircuit := compiled interpreter 204 2
structure NatCircuit where
/-- The number `k` of inputs. -/
inputCount : ℕ
/-- The explicit variables (index and kind), the inputs first. -/
explicitVars : List (ℕ × VarKind)
/-- The node list. -/
nodes : List NatNode
/-- The root node. -/
root : ℕ
/-- The variable count `V`. -/
varCount : ℕ
ZInQKernel/Compiler/Circuits/Circuit.lean:33
def compiled (p : Program) (r k : ℕ) : NatCircuit := (construction p r k).toCircuit k
ZInQKernel/Compiler/Circuits/Packed/Construction.lean:184
def interpreter : Program := [
/- 0 -/ .dec 17 0 1, .dec 19 1 2, .dec 0 3 6, .inc 17 4, .inc 19 5,
/- 5 -/ .dec 2 2 2, .dec 19 7 9, .inc 0 8, .dec 2 6 6, .inc 17 10,
/- 10 -/ .dec 20 10 11, .dec 23 11 12, .dec 17 13 16, .inc 20 14, .inc 23 15,
/- 15 -/ .dec 2 12 12, .dec 23 17 19, .inc 17 18, .dec 2 16 16, .dec 3 19 20,
/- 20 -/ .dec 20 21 65, .inc 20 22, .dec 24 22 23, .dec 25 23 24, .dec 20 25 28,
/- 25 -/ .inc 24 26, .inc 25 27, .dec 2 24 24, .dec 25 29 31, .inc 20 30,
/- 30 -/ .dec 2 28 28, .dec 21 31 32, .dec 24 33 36, .dec 24 34 38, .inc 21 35,
/- 35 -/ .dec 2 32 32, .dec 22 36 37, .dec 2 40 40, .dec 22 38 39, .inc 22 40,
/- 40 -/ .dec 22 41 53, .inc 22 42, .dec 4 42 43, .dec 26 43 44, .dec 21 45 48,
/- 45 -/ .inc 4 46, .inc 26 47, .dec 2 44 44, .dec 26 49 51, .inc 21 50,
/- 50 -/ .dec 2 48 48, .dec 2 64 64, .dec 2 64 64, .inc 3 54, .dec 20 54 55,
⋯
ZInQKernel/Compiler/Universal/Interpreter.lean:34
Sources
Uses 2 · Used by 5
TheoremCounts of the universal halting circuit#✓
The universal halting circuit \(\mathcal H\) has \(54{,}049\) explicit variables (the two inputs \(X_0,X_1\) and \(54{,}047\) witnesses), \(15{,}845\) calls of the power template with private blocks of \(79\) variables, and variable count $\(54{,}049+79\cdot15{,}845=1{,}305{,}804,\)$ so a natural zero with inputs \((e,n)\) has \(1{,}305{,}802\) witness coordinates. Its construction contains \(1{,}603\) mask macros, \(1{,}226\) bitAnd macros, \(3{,}678\) orthogonal macros, \(5{,}281\) binomial macros and \(10{,}770\) strict-inequality gadgets. Moreover \(\mathcal H\) is well scoped.
Proof sketch. The counting statement of the packed construction with \(k=2\), \(r=204\), \(m=1{,}399\), \(s=1{,}022\) (the shape check): explicit variables \(2k+9+41r+10m+31s=4+9+8364+13990+31682=54{,}049\); calls \(2+3(m+4r+3s)=2+3\cdot5281=15{,}845\); masks \(m+r=1603\); bitAnd \(r+s=1226\); orthogonal \(3(r+s)=3678\); binomial \(m+4r+3s=5281\); strict inequalities \(2+k+r+2\cdot5281=10{,}770\). Well-scopedness is item 1 of the statement on hierarchical constructions, all macro arguments of the packed construction being polynomials in earlier variables.
theorem haltingCircuit_counts :
haltingCircuit.inputCount = 2 ∧ haltingCircuit.explicitVars.length = 54049 ∧
haltingCircuit.blocks.length = 15845 ∧
haltingCircuit.nodes.countP NatNode.isCall = 15845 ∧
haltingCircuit.varCount = 1305804 ∧ haltingCircuit.WellScoped
theorem haltingCircuit_witnessCount :
haltingCircuit.varCount - haltingCircuit.inputCount = 1305802
theorem haltingCircuit_macroCounts :
let L := (construction interpreter 204 2 (State.init 2)).2.log
L.count .mask = 1603 ∧ L.count .bitAnd = 1226 ∧ L.count .orthogonal = 3678 ∧
L.count .binomial = 5281 ∧ L.count .odd = 5281 ∧ L.count .lt = 10770 ∧
L.count .power = 15845
def haltingCircuit : NatCircuit := compiled interpreter 204 2
ZInQKernel/Compiler/Universal/Halting.lean:32
def NatNode.isCall : NatNode → Bool
| .call _ _ _ _ => true
| _ => false
ZInQKernel/Compiler/Circuits/Counts.lean:22
def construction (p : Program) (r k : ℕ) : NM NForm := do
let a := inputs k
let zero ← constant 0
let one ← constant 1
let q ← fresh
let c ← fresh
let K ← fresh
let B ← fresh
let T ← fresh
let F ← fresh
let D ← fresh
let R ← freshN r
⋯
ZInQKernel/Compiler/Circuits/Packed/Construction.lean:165
def interpreter : Program := [
/- 0 -/ .dec 17 0 1, .dec 19 1 2, .dec 0 3 6, .inc 17 4, .inc 19 5,
/- 5 -/ .dec 2 2 2, .dec 19 7 9, .inc 0 8, .dec 2 6 6, .inc 17 10,
/- 10 -/ .dec 20 10 11, .dec 23 11 12, .dec 17 13 16, .inc 20 14, .inc 23 15,
/- 15 -/ .dec 2 12 12, .dec 23 17 19, .inc 17 18, .dec 2 16 16, .dec 3 19 20,
/- 20 -/ .dec 20 21 65, .inc 20 22, .dec 24 22 23, .dec 25 23 24, .dec 20 25 28,
/- 25 -/ .inc 24 26, .inc 25 27, .dec 2 24 24, .dec 25 29 31, .inc 20 30,
/- 30 -/ .dec 2 28 28, .dec 21 31 32, .dec 24 33 36, .dec 24 34 38, .inc 21 35,
/- 35 -/ .dec 2 32 32, .dec 22 36 37, .dec 2 40 40, .dec 22 38 39, .inc 22 40,
/- 40 -/ .dec 22 41 53, .inc 22 42, .dec 4 42 43, .dec 26 43 44, .dec 21 45 48,
/- 45 -/ .inc 4 46, .inc 26 47, .dec 2 44 44, .dec 26 49 51, .inc 21 50,
/- 50 -/ .dec 2 48 48, .dec 2 64 64, .dec 2 64 64, .inc 3 54, .dec 20 54 55,
⋯
ZInQKernel/Compiler/Universal/Interpreter.lean:34
def State.init (k : ℕ) : State :=
⟨k, (List.range k).map fun i => (i, .input), (List.range k).map .var, [], []⟩
ZInQKernel/Compiler/Circuits/Circuit.lean:100
Uses 5 · Used by 3
TheoremNode statistics of the halting circuit and the power template#✓
- The node list of the universal halting circuit \(\mathcal H\) has at most \(125{,}307\) additions and at most \(98{,}361\) multiplications, \(54{,}049\) variable nodes, \(6\) constant nodes with values \(0,1,2,4,1399,-1\) in node order, and \(15{,}845\) calls. Its first two nodes are the variable nodes of \(X_0\) and \(X_1\).
- The node list of the power template \(\mathcal P\) has \(474\) nodes: \(82\) variable nodes, \(6\) constant nodes with values \(0,1,4,2,3,-1\) in node order, \(196\) additions, \(190\) multiplications and no calls.
Neither item involves \(c_3\) or any astronomically large constant.
Proof sketch. Item 2 is a closed computation on the \(474\) nodes of the flat power macro. Item 1 is proved without evaluating the construction. The variable nodes are the explicit variables; the constants are \(0,1,2\) (the only ones the gadgets and macros request), \(4\) and the program size \(1399\) (requested by the first item of the packed construction) and \(-1\) (requested by the encoding), first occurring in this order; the calls are counted by the compiler. For the two bounds, count the addition and multiplication nodes the construction requests, \(129{,}408\) and \(98{,}727\), and subtract the requests whose node is already present: the re-sum \(z+a\) inside every bit conjunction (\(2{,}452\) additions), the re-sum \(N+1\) in every mask binomial after the first (\(1{,}601\) additions), the product \(K\cdot F\) in every register mask after the first (\(204\) multiplications), repeats in the state equations of the halting step (\(48\) additions and \(151\) multiplications) and \(11\) repeated products of the encoding. That a node is present depends only on how it was requested earlier, so no statement about the other nodes is needed.
def HaltingAddMulBound : Prop :=
countKind .add haltingCircuit.nodes ≤ 125307 ∧ countKind .mul haltingCircuit.nodes ≤ 98361
theorem haltingAddMulBound : HaltingAddMulBound
theorem haltingCircuit_varNodes : countKind .var haltingCircuit.nodes = 54049
def countKind (κ : NodeKind) (l : List NatNode) : ℕ := l.countP fun n => nodeKind n = κ
ZInQKernel/Compiler/Universal/NodeCheck.lean:49
def haltingCircuit : NatCircuit := compiled interpreter 204 2
ZInQKernel/Compiler/Universal/Halting.lean:32
def HaltingAddMulBound : Prop :=
countKind .add haltingCircuit.nodes ≤ 125307 ∧ countKind .mul haltingCircuit.nodes ≤ 98361
ZInQKernel/Compiler/NodeBound/Defs.lean:19
Uses 2 · Used by 7 · Informal links 1
TheoremExact node statistics of the halting circuit#✓
The node list of the universal halting circuit \(\mathcal H\) has exactly \(125{,}307\) additions and \(98{,}361\) multiplications, hence \(293{,}568\) nodes in all.
So the bounds of the node statistics are attained. Apart from a form of the main theorem that takes it as a hypothesis, no other statement uses the equality.
Proof sketch. A closed computation: run the construction with its hash-consing table and count the node kinds. The bounds give one inequality; the other needs every request not counted as a repeat to create a new node. The run is checked in \(89\) consecutive pieces by a builder without a table: pinned data says, for each request, whether its node already exists and where, and the builder confirms each claimed new node by comparing it with recent nodes or with sorted lists of older ones. A simulation argument shows that this builder makes the same requests and creates the same nodes as the hash-consing one.
def HaltingAddMulCheck : Prop :=
countKind .add haltingCircuit.nodes = 125307 ∧ countKind .mul haltingCircuit.nodes = 98361
theorem haltingAddMulCheck : HaltingAddMulCheck
def HaltingNodeCheck : Prop :=
countKind .var haltingCircuit.nodes = 54049 ∧ countKind .const haltingCircuit.nodes = 6 ∧
countKind .add haltingCircuit.nodes = 125307 ∧ countKind .mul haltingCircuit.nodes = 98361 ∧
constList haltingCircuit.nodes = [0, 1, 2, 4, 1399, -1]
def countKind (κ : NodeKind) (l : List NatNode) : ℕ := l.countP fun n => nodeKind n = κ
ZInQKernel/Compiler/Universal/NodeCheck.lean:49
def haltingCircuit : NatCircuit := compiled interpreter 204 2
ZInQKernel/Compiler/Universal/Halting.lean:32
def HaltingAddMulCheck : Prop :=
countKind .add haltingCircuit.nodes = 125307 ∧ countKind .mul haltingCircuit.nodes = 98361
ZInQKernel/Compiler/NodeCheck/Reduced.lean:21
def constList (l : List NatNode) : List ℤ := l.filterMap constOf
ZInQKernel/Compiler/Universal/NodeCheck.lean:57
Uses 2 · Used by 1
TheoremSemantics of the universal halting circuit#✓
For all \(e,n\in\mathbb N\): $\(Z_{\mathcal H}(e,n)\iff\operatorname{halts}(e,n),\)$ that is, \([\![\mathcal H]\!](e,n,v)=0\) for some \(v\in\mathbb N^{1305802}\) exactly when the program numbered \(e\) halts on \(n\). Replacing \(\mathbb N\) by \(\mathbb Q\) here is not justified.
Proof sketch. The compiled-circuit statement for the valid program \(\mathcal U\) gives \(Z_{\mathcal H}(e,n)\iff\mathcal U\) accepts \((e,n)\), and the interpreter's correctness gives \(\iff\operatorname{halts}(e,n)\). Validity comes from the interpreter-shape check and the count \(1{,}305{,}802=1{,}305{,}804-2\) from the counting statement.
theorem haltingCircuit_natRel_iff (e n : ℕ) :
haltingCircuit.NatRel powerTemplate ![e, n] ↔ halts e n
theorem haltingCircuit_natRel_iff_accepts (e n : ℕ) :
haltingCircuit.NatRel powerTemplate ![e, n] ↔ interpreter.Accepts ![e, n]
def haltingCircuit : NatCircuit := compiled interpreter 204 2
ZInQKernel/Compiler/Universal/Halting.lean:32
def powerTemplate : ExPoly := ⟨3, 79, powerTemplatePoly⟩
ZInQKernel/Compiler/Circuits/PowerTemplate.lean:40
def halts (e n : ℕ) : Prop := RM.Halts (decodeMachine e) (initFile ![n])
ZInQKernel/Compiler/Interpreter/Numbering.lean:45
def interpreter : Program := [
/- 0 -/ .dec 17 0 1, .dec 19 1 2, .dec 0 3 6, .inc 17 4, .inc 19 5,
/- 5 -/ .dec 2 2 2, .dec 19 7 9, .inc 0 8, .dec 2 6 6, .inc 17 10,
/- 10 -/ .dec 20 10 11, .dec 23 11 12, .dec 17 13 16, .inc 20 14, .inc 23 15,
/- 15 -/ .dec 2 12 12, .dec 23 17 19, .inc 17 18, .dec 2 16 16, .dec 3 19 20,
/- 20 -/ .dec 20 21 65, .inc 20 22, .dec 24 22 23, .dec 25 23 24, .dec 20 25 28,
/- 25 -/ .inc 24 26, .inc 25 27, .dec 2 24 24, .dec 25 29 31, .inc 20 30,
/- 30 -/ .dec 2 28 28, .dec 21 31 32, .dec 24 33 36, .dec 24 34 38, .inc 21 35,
/- 35 -/ .dec 2 32 32, .dec 22 36 37, .dec 2 40 40, .dec 22 38 39, .inc 22 40,
/- 40 -/ .dec 22 41 53, .inc 22 42, .dec 4 42 43, .dec 26 43 44, .dec 21 45 48,
/- 45 -/ .inc 4 46, .inc 26 47, .dec 2 44 44, .dec 26 49 51, .inc 21 50,
/- 50 -/ .dec 2 48 48, .dec 2 64 64, .dec 2 64 64, .inc 3 54, .dec 20 54 55,
⋯
ZInQKernel/Compiler/Universal/Interpreter.lean:34
Uses 7 · Used by 1
The five-input circuit fixes the program input to the wrapper's code, moves the packed input to variable five, shifts the other variables by seven, and adds the four squared pairing equations. The program literal is bounded, from a finite check on the size of the wrapper, without being evaluated; the shape of the five-input circuit then follows.
TheoremSize of the wrapper#✓
The wrapper \(\mathcal W\) has \(m_{\mathcal W}\) instructions with $\(3\le m_{\mathcal W}\le200{,}000,\)$ and every register index and every target occurring in its instructions is below \(2^{18}\).
This is a closed decidable statement about the explicit wrapper program, a finite computation. For comparison, the manuscript's wrapper has \(146{,}780\) instructions (the final halt included), \(23{,}633\) registers and encoding width \(18\), so it satisfies these bounds; the wrapper of this formalization is built from a precision program written afresh, and the bounds are a requirement on it.
theorem wrapper_small : SmallProgram wrapper
theorem wrapper_valid : wrapper.Valid (2 ^ 18)
theorem wrapper_length : wrapper.length =
unpairProgram.body.len + (precisionProgram.body.len + precisionProgram.bound + 9)
def SmallProgram (p : Program) : Prop :=
3 ≤ p.length ∧ p.length ≤ 200000 ∧ ∀ ins ∈ p, instrMaxField ins < 2 ^ 18
ZInQKernel/Compiler/Universal/CodeSize.lean:29
def wrapper : RM.Program := wrapperPrefix ++ precisionMachine.map (relocate wrapperPrefix.length)
ZInQKernel/Compiler/Programs/Wrapper.lean:60
def unpairProgram : Program where
body := unpairBody precRegs
bound := precRegs + 3
inputs := 1
ZInQKernel/Compiler/Programs/Wrapper.lean:45
def precisionProgram : Program where
body := decodeInputs precRegT ;; precisionZ.compile precOff precRegT
bound := precRegT + precisionZ.temps + 8
inputs := 5
ZInQKernel/Compiler/Programs/PrecisionIR.lean:110
Uses 1 · Used by 1
TheoremSize of the program literal#✓
Let \(c_3=\operatorname{code}(\mathcal W)\) be the code of the wrapper. Then $\(1399<c_3<2^{14400019}<2^{2^{24}}.\)$ The value of \(c_3\) is never computed; only these bounds are used: by the size chapter, which needs every literal constant of the specification, \(c_3\) included, to be far below the cutoff (it uses \(|c_3|<2^{2^{24}}\)), and by the shape of the natural precision circuit, which needs \(c_3\notin\{0,1,-1,2,4,1399\}\).
Proof sketch. By the size check, every field of every instruction of \(\mathcal W\) (opcode \(0,1,2\), register index, targets) is below \(2^{18}\), so the encoding width satisfies \(2\le w(\mathcal W)\le18\). By the bounds for codes of primitive programs, \(c_3<2^{w(4m_{\mathcal W}+1)+1}\le2^{18(4\cdot200000+1)+1}=2^{14400019}\), and \(14400019<16777216=2^{24}\). Since \(m_{\mathcal W}\ge3\ge2\) and \(w\ge2\), \(c_3+1\ge2^{w(4m_{\mathcal W}-7)+1}\ge2^{2\cdot5+1}=2048\), so \(c_3>1399\).
The manuscript's own literal has \(10{,}568{,}107\) bits (\(3{,}181{,}317\) decimal digits); since the precision program of this formalization is written afresh, its literal differs, and no statement depends on its digits.
irreducible_def c3 : ℕ := code wrapper
theorem c3_lt : c3 < 2 ^ 14400019
theorem c3_gt : 1399 < c3
def code (p : Program) : ℕ := 2 ^ width p * (2 * codeD p + 1) - 1
ZInQKernel/Compiler/Interpreter/Numbering.lean:102
def wrapper : RM.Program := wrapperPrefix ++ precisionMachine.map (relocate wrapperPrefix.length)
ZInQKernel/Compiler/Programs/Wrapper.lean:60
irreducible_def c3 : ℕ := code wrapper
ZInQKernel/Compiler/Universal/WrapperCode.lean:27
Uses 4 · Used by 3
DefinitionThe five-input natural precision circuit#✓
Let \(c_3=\operatorname{code}(\mathcal W)\). The natural precision circuit \(\mathcal N\) is the natural circuit with \(5\) inputs obtained from the universal halting circuit \(\mathcal H\) as follows.
- Variables. Inputs \(X_0,\dots,X_4\) (the codes \(c_0,\dots,c_4\)); pairing variables \(X_5,\dots,X_8\) (\(t_0,\dots,t_3\)); every variable \(X_i\) of \(\mathcal H\) with \(i\ge2\) becomes \(X_{i+7}\), and every block start \(w\) of \(\mathcal H\) becomes \(w+7\). The explicit variables are listed as \(0,\dots,8\) followed by the shifted explicit witnesses of \(\mathcal H\), and the variable count is that of \(\mathcal H\) plus \(7\).
- Nodes. The node list of \(\mathcal H\), in order, with the variable node of \(X_0\) (\(e\)) replaced by the constant node \(c_3\), the variable node of \(X_1\) (\(n\)) replaced by the variable node of \(X_5\), every other variable node and every call block start shifted by \(7\); followed by the variable nodes of \(X_0,\dots,X_4\) and \(X_6,X_7,X_8\), the constant nodes \(1,2,-1\), and, for \(i=0,1,2,3\) with \(t_4=X_4\) and \(c_i=X_i\), the eight nodes of $\(\pi_i=2t_i+(-1)\cdot\bigl((c_i+t_{i+1})(c_i+t_{i+1}+1)+2t_{i+1}\bigr)\)$ (no hash-consing in this appended part); finally the left-nested sum of squares \(\rho^2+\pi_0^2+\pi_1^2+\pi_2^2+\pi_3^2\), where \(\rho\) is the root of \(\mathcal H\), as root.
- Power template. The calls refer to the power template \(\mathcal P\).
This is the pinned five-input natural polynomial of input \(\mathsf C\), defined by construction; the saved file is a cross-check of its shape. Its counts (\(54{,}056\) explicit variables, \(15{,}845\) private blocks, variable count \(1{,}305{,}811\), \(293{,}620\) nodes) are proved in the shape statement.
This is a definition.
def specialize (H : NatCircuit) (code : ℤ) : NatCircuit where
inputCount := 5
explicitVars := (List.range 9).map (fun i => (i, if i < 5 then .input else .witness)) ++
(H.explicitVars.drop 2).map fun v => (v.1 + 7, v.2)
nodes := H.nodes.map (renameNode code) ++ appendedNodes H.nodes.length H.root
root := H.nodes.length + 51
varCount := H.varCount + 7
def precisionCircuitOf (code : ℤ) : NatCircuit := specialize haltingCircuit code
def precisionCircuit : NatCircuit := precisionCircuitOf c3
structure NatCircuit where
/-- The number `k` of inputs. -/
inputCount : ℕ
/-- The explicit variables (index and kind), the inputs first. -/
explicitVars : List (ℕ × VarKind)
/-- The node list. -/
nodes : List NatNode
/-- The root node. -/
root : ℕ
/-- The variable count `V`. -/
varCount : ℕ
ZInQKernel/Compiler/Circuits/Circuit.lean:33
def renameNode (code : ℤ) : NatNode → NatNode
| .var 0 => .const code
| .var 1 => .var 5
| .var (i + 2) => .var (i + 9)
| .const c => .const c
| .add j k => .add j k
| .mul j k => .mul j k
| .call a b c w => .call a b c (w + 7)
ZInQKernel/Compiler/Universal/Specialize.lean:36
def appendedNodes (L ρ : ℕ) : List NatNode :=
[.var 0, .var 1, .var 2, .var 3, .var 4, .var 6, .var 7, .var 8,
.const 1, .const 2, .const (-1)] ++
pairingBlock (L + 11) (L + 8) (L + 9) (L + 10) L (L + 5) 1 ++
pairingBlock (L + 19) (L + 8) (L + 9) (L + 10) (L + 1) (L + 6) (L + 5) ++
pairingBlock (L + 27) (L + 8) (L + 9) (L + 10) (L + 2) (L + 7) (L + 6) ++
pairingBlock (L + 35) (L + 8) (L + 9) (L + 10) (L + 3) (L + 4) (L + 7) ++
[.mul ρ ρ, .mul (L + 18) (L + 18), .add (L + 43) (L + 44), .mul (L + 26) (L + 26),
.add (L + 45) (L + 46), .mul (L + 34) (L + 34), .add (L + 47) (L + 48),
.mul (L + 42) (L + 42), .add (L + 49) (L + 50)]
ZInQKernel/Compiler/Universal/Specialize.lean:53
def specialize (H : NatCircuit) (code : ℤ) : NatCircuit where
inputCount := 5
explicitVars := (List.range 9).map (fun i => (i, if i < 5 then .input else .witness)) ++
(H.explicitVars.drop 2).map fun v => (v.1 + 7, v.2)
nodes := H.nodes.map (renameNode code) ++ appendedNodes H.nodes.length H.root
root := H.nodes.length + 51
varCount := H.varCount + 7
ZInQKernel/Compiler/Universal/Specialize.lean:66
def haltingCircuit : NatCircuit := compiled interpreter 204 2
ZInQKernel/Compiler/Universal/Halting.lean:32
def precisionCircuitOf (code : ℤ) : NatCircuit := specialize haltingCircuit code
ZInQKernel/Compiler/Universal/PrecisionCircuit.lean:33
irreducible_def c3 : ℕ := code wrapper
ZInQKernel/Compiler/Universal/WrapperCode.lean:27
Sources
Uses 5 · Used by 4
TheoremThe precision circuit is a specialization#✓
Let \(\theta\) be the substitution \(X_0\mapsto c_3\), \(X_1\mapsto X_5\), \(X_i\mapsto X_{i+7}\) for \(i\ge2\). Then $\([\![\mathcal N]\!]=\theta\bigl([\![\mathcal H]\!]\bigr)^2+\sum_{i=0}^3\Bigl(2X_{5+i}-(X_i+t_{i+1})(X_i+t_{i+1}+1)-2t_{i+1}\Bigr)^2,\)$ with \(t_{i+1}=X_{6+i}\) for \(i<3\) and \(t_4=X_4\). Consequently, for every \(c\in\mathbb N^5\), $\(Z_{\mathcal N}(c)\iff Z_{\mathcal H}(c_3,\operatorname{enc}_5(c)).\)$ Moreover \(\mathcal N\) is well scoped: the pairing variables \(X_5,\dots,X_8\) are disjoint from the inputs and from the shifted variables and blocks of \(\mathcal H\), the shifted blocks are pairwise disjoint and disjoint from the explicit variables, and no variable node of \(\mathcal N\) refers to a block variable. In particular no parent variable node accesses a private coordinate of a power call.
Proof sketch. Node by node, the denotation of each modified node of \(\mathcal H\) is \(\theta\) applied to the original denotation: variable nodes by definition, constants unchanged, additions and multiplications by the homomorphism property, and calls because shifting the block start by \(7\) commutes with \(\theta\) on the callee's witness variables. The appended nodes denote the four pairing polynomials and the sum of squares. For the relation: a natural zero makes every square vanish (integers), so the pairing equations hold and, by unique Cantor unpairing, \(t_0=\operatorname{enc}_5(c)\); then \(\theta([\![\mathcal H]\!])=0\) is a natural zero of \(\mathcal H\) at \((c_3,\operatorname{enc}_5(c))\) after renaming. Conversely take \(t_i\) the Cantor values and the witnesses of \(\mathcal H\) shifted by \(7\). Well-scopedness: \(\mathcal H\) is well scoped (its counting statement), its variables and blocks lie in \([2,1{,}305{,}804)\), so after the shift they lie in \([9,1{,}305{,}811)\), disjoint from the new explicit variables \(0,\dots,8\); the shift is injective, so disjointness and the absence of variable nodes inside blocks are preserved, and the appended nodes refer only to \(X_0,\dots,X_8\).
theorem precisionCircuit_poly (T : Syntax.ExPoly) :
precisionCircuit.poly T =
MvPolynomial.bind₁ (theta c3) (haltingCircuit.poly T) ^ 2 + ∑ i : Fin 4, pairPoly i ^ 2
theorem precisionCircuit_natRel_iff (T : Syntax.ExPoly) (c : Fin 5 → ℕ) :
precisionCircuit.NatRel T c ↔
haltingCircuit.NatRel T ![c3, CantorDecoder.encode5 (c 0) (c 1) (c 2) (c 3) (c 4)]
theorem precisionCircuit_wellScoped : precisionCircuit.WellScoped
structure ExPoly where
/-- The parameter count `p`; the parameters are `X_0, …, X_{p-1}`. -/
params : ℕ
/-- The witness count `m`; the witnesses are `X_p, …, X_{p+m-1}`. -/
witnesses : ℕ
/-- The polynomial. -/
poly : Poly
ZInQKernel/Syntax/Language/Basic.lean:172
def precisionCircuit : NatCircuit := precisionCircuitOf c3
ZInQKernel/Compiler/Universal/WrapperCode.lean:42
def theta (code : ℤ) : ℕ → Poly
| 0 => C code
| 1 => X 5
| i + 2 => X (i + 9)
ZInQKernel/Compiler/Universal/Specialize.lean:77
irreducible_def c3 : ℕ := code wrapper
ZInQKernel/Compiler/Universal/WrapperCode.lean:27
def haltingCircuit : NatCircuit := compiled interpreter 204 2
ZInQKernel/Compiler/Universal/Halting.lean:32
def pairPoly (i : ℕ) : Poly :=
2 * tVar i - (X i + tVar (i + 1)) * (X i + tVar (i + 1) + 1) - 2 * tVar (i + 1)
ZInQKernel/Compiler/Universal/Specialize.lean:86
@[expose] def encode5 (a b c d e : Nat) : Nat :=
pair a (pair b (pair c (pair d e)))
lean/ZInQ/CantorDecoder.lean:32
Uses 6 · Used by 2
TheoremShape of the natural precision circuit#✓
The five-input natural precision circuit \(\mathcal N\) has:
- \(5\) inputs and \(54{,}056\) explicit variables, namely \(0,\dots,8\) followed by the explicit witnesses of \(\mathcal H\) shifted by \(7\) (so \(54{,}051\) explicit witnesses);
- \(15{,}845\) calls of the power template, with private blocks of \(79\) variables, and variable count \(54{,}056+79\cdot15{,}845=1{,}305{,}811\), so a natural zero with inputs \(c\in\mathbb N^5\) has \(1{,}305{,}806\) witness coordinates;
- at most \(125{,}327\) additions and at most \(98{,}382\) multiplications, and \(15{,}845\) calls;
- constants among \(0,1,-1,c_3,2,4,1399\), where \(c_3,2,4,1399\) are distinct.
The specification chapter's witness accounting uses items 2 to 4 for the recipe translation; this statement proves them from the node statistics of \(\mathcal H\) and the size of the program literal. The constant \(c_3\) is never evaluated.
Proof sketch. From the definition of \(\mathcal N\) and the counts of \(\mathcal H\): the explicit variables are the \(9\) new ones and the \(54{,}047\) shifted witnesses of \(\mathcal H\); the calls are those of \(\mathcal H\) with shifted blocks. The modified copy of the node list of \(\mathcal H\) has the same additions and multiplications; the appended part has four pairing polynomials (\(4\) additions and \(4\) multiplications each) and the sum of five squares (\(5\) multiplications and \(4\) additions), that is \(20\) additions and \(21\) multiplications, so the bounds of \(\mathcal H\) give item 3. The constants of \(\mathcal H\) are among \(0,1,2,4,-1,1399\); the copy replaces the variable node of \(X_0\) by the constant node \(c_3\), and the appended part adds \(1,2,-1\). Item 4 needs only \(c_3>1399\), from the size of the program literal.
theorem precisionCircuit_counts :
precisionCircuit.inputCount = 5 ∧ precisionCircuit.explicitVars.length = 54056 ∧
precisionCircuit.blocks.length = 15845 ∧ precisionCircuit.varCount = 1305811 ∧
precisionCircuit.varCount - precisionCircuit.inputCount = 1305806
theorem precisionCircuitOf_explicitVars (code : ℤ) :
∃ rest, haltingCircuit.explicitVars = (0, .input) :: (1, .input) :: rest ∧
(∀ v ∈ rest, v.2 = .witness) ∧
(precisionCircuitOf code).explicitVars =
[(0, .input), (1, .input), (2, .input), (3, .input), (4, .input), (5, .witness),
(6, .witness), (7, .witness), (8, .witness)] ++ rest.map fun v => (v.1 + 7, v.2)
theorem precisionCircuit_addMulBound (hB : NodeCheck.HaltingAddMulBound) :
countKind .add precisionCircuit.nodes ≤ 125327 ∧
countKind .mul precisionCircuit.nodes ≤ 98382
def precisionCircuit : NatCircuit := precisionCircuitOf c3
ZInQKernel/Compiler/Universal/WrapperCode.lean:42
def haltingCircuit : NatCircuit := compiled interpreter 204 2
ZInQKernel/Compiler/Universal/Halting.lean:32
def precisionCircuitOf (code : ℤ) : NatCircuit := specialize haltingCircuit code
ZInQKernel/Compiler/Universal/PrecisionCircuit.lean:33
def HaltingAddMulBound : Prop :=
countKind .add haltingCircuit.nodes ≤ 125307 ∧ countKind .mul haltingCircuit.nodes ≤ 98361
ZInQKernel/Compiler/NodeBound/Defs.lean:19
def countKind (κ : NodeKind) (l : List NatNode) : ℕ := l.countP fun n => nodeKind n = κ
ZInQKernel/Compiler/Universal/NodeCheck.lean:49
Uses 5 · Used by 5 · Informal links 1
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.