Documentation

CslibFrontier.Computability.Circuit.Arithmetic.Separation.Uni.EvalCore

The universal machine evaluates formulas: the frame of the proof #

The universal machine keeps trees in its heap (Uni.Represents). To evaluate the formula coded by the tree at register 1 at the tree at register 2 (Uni.EvalReady), it reads the opcode of the code, evaluates the subformulas, and returns the value to the frame whose address is in register 3 (Uni.Returns). Uni.EvalsTo θ supp c x l says that this is correct for the code c at x if l is the list of the accepting runs of the formula: the sum of the weights of the runs of the machine is the sum over the runs r in l without named constants of the weight of r times the sum after the return of the value of r (Uni.plainValue), and one step of the formula costs at most Uni.codeCost supp steps of the machine.

All steps but the guesses are forced (Uni.sumTo_rule). Uni.InMode.sumTo_step is the one form of a forced step that the proofs use: the rule is found by unification from the mode and the loaded record, and the state after the step is Uni.step, whose mode, registers and heap are computed by rfl.

This file has the constructs whose evaluation uses no subformula (quote, id, guess, fail, and mul, at which the machine stops).

Main definitions #

Main results #

References #

The address a represents the tree in the heap H.

theorem Cslib.Circuits.Arithmetic.Separation.Uni.Represents.step {A : Type} [CommRing A] {θ : List Bool → A} {supp : Finset (List Bool)} {σ : Config supp} {a : ℕ} {t : Interpreter.Tree} (h : Represents σ.heap a t) {r : Rule supp} {p q s : ℕ} :
Represents (Uni.step θ σ r p q s).heap a t
theorem Cslib.Circuits.Arithmetic.Separation.Uni.Represents.load {supp : Finset (List Bool)} {σ : Config supp} (hσ : WellFormed σ) {a : ℕ} {t : Interpreter.Tree} (h : Represents σ.heap a t) :
∃ (p : ℕ) (q : ℕ) (s : ℕ), (consOrNil (decide (t ≠ Interpreter.Tree.nil)), ![a, p, q, s]) ∈ σ.heap ∧ Represents σ.heap p t.hd ∧ Represents σ.heap q t.tl

The record at an address that represents a tree.

structure Cslib.Circuits.Arithmetic.Separation.Uni.InMode {supp : Finset (List Bool)} (σ : Config supp) (md : Mode (Name supp)) (H : List (Rec RecKind)) (inp : List Bool) :

The state σ is well formed and in the mode md, its heap contains H, and its input is inp.

theorem Cslib.Circuits.Arithmetic.Separation.Uni.InMode.mono {supp : Finset (List Bool)} {σ : Config supp} {md : Mode (Name supp)} {H H' : List (Rec RecKind)} {inp : List Bool} (h : InMode σ md H inp) (hH : H' ⊆ H) :
InMode σ md H' inp
theorem Cslib.Circuits.Arithmetic.Separation.Uni.InMode.self {supp : Finset (List Bool)} {σ : Config supp} {md : Mode (Name supp)} {H : List (Rec RecKind)} {inp : List Bool} (h : InMode σ md H inp) :
InMode σ md σ.heap inp
theorem Cslib.Circuits.Arithmetic.Separation.Uni.InMode.mem_of_eq {supp : Finset (List Bool)} {σ : Config supp} {md : Mode (Name supp)} {H : List (Rec RecKind)} {inp : List Bool} {κ : RecKind} (h : InMode σ md H inp) {k k' f₀ f₁ f₂ : ℕ} (hm : (κ, ![k', f₀, f₁, f₂]) ∈ H) (hk : k = k') :
(κ, ![k, f₀, f₁, f₂]) ∈ σ.heap

A record of H is in the heap; its address may be given by an equation.

theorem Cslib.Circuits.Arithmetic.Separation.Uni.InMode.frame_mem {A : Type} [CommRing A] {θ : List Bool → A} {supp : Finset (List Bool)} {σ σ' : Config supp} {md : Mode (Name supp)} {inp : List Bool} {p q s : ℕ} {r : Rule supp} (h : InMode σ' md (step θ σ r p q s).heap inp) {k : ℕ} (hk : k = σ.n + 1) :
((rule θ supp r).ak, ![k, env σ p q s ((rule θ supp r).af 0), env σ p q s ((rule θ supp r).af 1), env σ p q s ((rule θ supp r).af 2)]) ∈ σ'.heap

The record that a step allocated, at its address.

theorem Cslib.Circuits.Arithmetic.Separation.Uni.InMode.sumTo_rule {A : Type} [CommRing A] {θ : List Bool → A} {supp : Finset (List Bool)} {σ : Config supp} {md : Mode (Name supp)} {H : List (Rec RecKind)} {inp : List Bool} {κ : RecKind} {p q s : ℕ} {r : Rule supp} {S : A} {B : ℤ} (hσ : InMode σ md H inp) (hrec : (κ, ![σ.regs (loadReg md), p, q, s]) ∈ σ.heap) (hr : nextRule supp md κ = some r) (h : InMode (step θ σ r p q s) (rule θ supp r).dst H inp → (universalMachine θ supp).SumTo (step θ σ r p q s) S (B - 1)) (hs : (rule θ supp r).src = md := by rfl) (hk : (rule θ supp r).lk = κ := by rfl) (hrd : (rule θ supp r).rd = none := by rfl) :
(universalMachine θ supp).SumTo σ ((rule θ supp r).wt * S) B

A forced step: in the mode md with the record of kind κ loaded, the run sum is the weight of the rule nextRule supp md κ times the run sum after the step.

theorem Cslib.Circuits.Arithmetic.Separation.Uni.InMode.sumTo_step {A : Type} [CommRing A] {θ : List Bool → A} {supp : Finset (List Bool)} {σ : Config supp} {md : Mode (Name supp)} {H : List (Rec RecKind)} {inp : List Bool} {κ : RecKind} {p q s : ℕ} {r : Rule supp} {S : A} {B : ℤ} (hσ : InMode σ md H inp) (hrec : (κ, ![σ.regs (loadReg md), p, q, s]) ∈ σ.heap) (hr : nextRule supp md κ = some r) (h : InMode (step θ σ r p q s) (rule θ supp r).dst H inp → (universalMachine θ supp).SumTo (step θ σ r p q s) S (B - 1)) (hs : (rule θ supp r).src = md := by rfl) (hk : (rule θ supp r).lk = κ := by rfl) (hrd : (rule θ supp r).rd = none := by rfl) (hw : (rule θ supp r).wt = 1 := by rfl) :
(universalMachine θ supp).SumTo σ S B

A forced step with a rule of weight 1.

theorem Cslib.Circuits.Arithmetic.Separation.Uni.InMode.sumTo_zero {A : Type} [CommRing A] {θ : List Bool → A} {supp : Finset (List Bool)} {σ : Config supp} {md : Mode (Name supp)} {H : List (Rec RecKind)} {inp : List Bool} {κ : RecKind} {p q s : ℕ} (hσ : InMode σ md H inp) (hrec : (κ, ![σ.regs (loadReg md), p, q, s]) ∈ σ.heap) (hr : nextRule supp md κ = none) (B : ℤ) (hP : md ≠ Mode.parse := by rintro ⟨⟩) (hD : md ≠ Mode.decode 7 := by rintro ⟨⟩) (hz : md ≠ Mode.halt := by rintro ⟨⟩) :
(universalMachine θ supp).SumTo σ 0 B

No rule applies.

def Cslib.Circuits.Arithmetic.Separation.Uni.Returns {A : Type} [CommRing A] (θ : List Bool → A) (supp : Finset (List Bool)) (H : List (Rec RecKind)) (k : ℕ) (inp : List Bool) (o : Interpreter.Tree) (S : A) (B : ℤ) :

What happens when the value o is returned to the frame at the address k: the run sum is S, within B steps.

The bound for the lengths of names.

The number of steps of the machine for one step of the evaluation.

theorem Cslib.Circuits.Arithmetic.Separation.Uni.sumTo_readName {A : Type} [CommRing A] {θ : List Bool → A} {supp : Finset (List Bool)} {H : List (Rec RecKind)} {k : ℕ} {inp : List Bool} {S : A} {B : ℤ} (hθ : ∀ q ∉ supp, θ q = 0) (w : Interpreter.Tree) (p : Name supp) (σ : Config supp) :
InMode σ (Mode.thetaHead p) H inp → Represents σ.heap (σ.regs 1) w → σ.regs 2 = k → Returns θ supp H k inp Interpreter.Tree.nil S B → (universalMachine θ supp).SumTo σ (θ (↑p ++ w.path) * S) (B + 1 + 2 * ↑(nameLength supp - (↑p).length))

Reading a name: from the mode thetaHead p with the rest w of the name at register 1, the machine multiplies by θ (p ++ w.path) and returns nil to the frame at register 2.

The weight of a run that names no constants; the other runs count 0.

The sum, over the runs r without named constants, of the weight of r times m r.

theorem Cslib.Circuits.Arithmetic.Separation.Uni.plainValue_seq {A : Type} [CommRing A] (m : Interpreter.Run A → A) (la : List (Interpreter.Run A)) (L : Interpreter.Run A → List (Interpreter.Run A)) (f : Interpreter.Run A → Interpreter.Run A → Interpreter.Tree) :
plainValue m (List.flatMap (fun (r : Interpreter.Run A) => List.map (fun (s : Interpreter.Run A) => (r.seq s).tick (f r s)) (L r)) la) = plainValue (fun (r : Interpreter.Run A) => plainValue (fun (s : Interpreter.Run A) => m ((r.seq s).tick (f r s))) (L r)) la

One run after the other.

theorem Cslib.Circuits.Arithmetic.Separation.Uni.plainValue_seq₃ {A : Type} [CommRing A] (m : Interpreter.Run A → A) (la lb : List (Interpreter.Run A)) (L : Interpreter.Run A → Interpreter.Run A → List (Interpreter.Run A)) :
plainValue m (List.flatMap (fun (r : Interpreter.Run A) => List.flatMap (fun (s : Interpreter.Run A) => List.map (fun (t : Interpreter.Run A) => ((r.seq s).seq t).tick t.out) (L r s)) lb) la) = plainValue (fun (r : Interpreter.Run A) => plainValue (fun (s : Interpreter.Run A) => plainValue (fun (t : Interpreter.Run A) => m (((r.seq s).seq t).tick t.out)) (L r s)) lb) la

Three runs, one after the other.

The machine is about to evaluate the formula with the code c at the tree x, to return the value to the frame at k.

theorem Cslib.Circuits.Arithmetic.Separation.Uni.EvalReady.sumTo_decode {A : Type} [CommRing A] {θ : List Bool → A} {supp : Finset (List Bool)} {σ : Config supp} {H : List (Rec RecKind)} {k : ℕ} {inp : List Bool} {o a x : Interpreter.Tree} {S : A} {B : ℤ} (hσ : EvalReady σ (o.cons a) x H k inp) (j : Fin 11) (ho : o.len = ↑j) {r : Rule supp} (hr : nextRule supp (Mode.decode j) RecKind.nil = some r) (h : ∀ (σ' : Config supp), Represents σ'.heap (σ'.regs 2) a → Represents σ'.heap (σ'.regs 3) x → σ'.regs 4 = k → InMode (step θ σ' r 0 0 0) (rule θ supp r).dst H inp → (universalMachine θ supp).SumTo (step θ σ' r 0 0 0) S B) (hs : (rule θ supp r).src = Mode.decode j := by rfl) (hk : (rule θ supp r).lk = RecKind.nil := by rfl) (hrd : (rule θ supp r).rd = none := by rfl) (hw : (rule θ supp r).wt = 1 := by rfl) :
(universalMachine θ supp).SumTo σ S (B + 12)

Reading the opcode j and the step after it, by the rule for the mode decode j.

The machine evaluates the code c at x correctly, if l is the list of the accepting runs: from a state that is ready, the run sum is plainValue m l within B steps, if for every run r in l without named constants the run sum after the return of the value of r is m r within B - codeCost supp * r.cost steps.

theorem Cslib.Circuits.Arithmetic.Separation.Uni.EvalsTo.id {A : Type} [CommRing A] {θ : List Bool → A} {supp : Finset (List Bool)} {o a x : Interpreter.Tree} (ho : o.len = 1) :
EvalsTo θ supp (o.cons a) x [Interpreter.Run.det 1 x]
theorem Cslib.Circuits.Arithmetic.Separation.Uni.EvalsTo.fail {A : Type} [CommRing A] {θ : List Bool → A} {supp : Finset (List Bool)} {o a x : Interpreter.Tree} (ho : o.len = 8 ∨ 11 ≤ o.len) :
EvalsTo θ supp (o.cons a) x []
theorem Cslib.Circuits.Arithmetic.Separation.Uni.EvalsTo.mul {A : Type} [CommRing A] {θ : List Bool → A} {supp : Finset (List Bool)} {o a x : Interpreter.Tree} (ho : o.len = 10) (l : List (Interpreter.Run A)) :
EvalsTo θ supp (o.cons a) x (List.map (fun (r : Interpreter.Run A) => { cost := r.cost + 1, th := r.th, bill := r.bill ++ [r.out.path], out := Interpreter.Tree.nil }) l)

Naming a constant stops the machine: such runs do not count.