deflocalAddress (β g : ℕ) (TWt j : Formula ι) : Fin (3*β+g) →AddressFormula.Expr (ι:=ι) :=
body · 3
lines
Fin.addCases (fun i =>let p := finProdFinEquiv.symm i
x β W t (.add j (.constant p.1.val)) (.constant p.2.val))
(fun r => y β g TW t j (.constant r.val))
defclauseIndex (β g : ℕ) (TWi : Formula ι) : Fin4→Formula ι :=
body · 13
lines
letA:= .mul (.constant (2*β)) WletB:= .mul (.constant (2*β)) (.sub T (.constant 1))
letC:= .mul (.mul (.constant (3*g+2*β)) (.sub W (.constant 2))) (.sub T (.constant 1))
let p := .sub i Alet r := .sub p Blet c := .constant (3*g+2*β)
chooseIndex (less i A)
![.constant 0,.div (.div i (.constant 2)) (.constant β),.mod (.div i (.constant 2)) (.constant β),.mod i (.constant 2)]
(chooseIndex (less i (.add AB))
![.constant 1,.div (.div p (.constant β)) (.constant 2),.mod (.div p (.constant β)) (.constant 2),.mod p (.constant β)]
(chooseIndex (less i (.add (.add AB) C))
![.constant 2,.div (.div r c) (.sub W (.constant 2)),.mod (.div r c) (.sub W (.constant 2)),.mod r c]
![.constant 3,.constant 0,.constant 0,.sub r C]))
lemmainitialFamily_exact {q β g TW : ℕ} [NeZero q] (L : Addressable.Layout q β g TW)
{init : Formula ι →Fin β →InitialFormula.Expr (ι:=ι)} {Init : FinW→Fin β →Addressable.InputBit q}
{w j r k : Formula ι} {v : ι →ℕ} (J : FinW) (R : Fin β) (K : Fin2)
(hw : w.eval v=W) (hj : j.eval v=J.val) (hr : r.eval v=R.val) (hk : k.eval v=K.val)
(hi : InitialFormula.Represents (init j R) v (InitJR)) :
ClauseFormula.Represents (initialFamily β init w j r k) v
(Addressable.initial (.inr (L.x ⟨0,L.time_pos⟩ JR)) (InitJR) K).compile :=by
proof · 5
lines
apply lookup_ofFn_exact R hr
apply InitialFormula.clauses_exact K
· exact ClauseFormula.addressReading_exact (x_exact L ⟨0,L.time_pos⟩ JR hw rfl hj rfl)
· exact hi
· exact hk
deffinalFamily (β : ℕ) (accept : Fin β →Bool) (TWOr : Formula ι) : ClauseFormula.Expr (ι:=ι) :=
body · 2
lines
ClauseFormula.lookup r fallback 0 (List.ofFn (funs : Fin β =>ClauseFormula.unit
(ClauseFormula.addressReading (x β W (.sub T (.constant 1)) O (.constant s.val))) (.constant (boolean (accept s)))))
deffamilyClause (β g : ℕ) (c : Tableau.Circuit (3*β) g) (output : Fin β →Tableau.Wire (3*β+g))
(init : Formula ι →Fin β →InitialFormula.Expr (ι:=ι)) (blank accept : Fin β →Bool)
(TWO : Formula ι) (e : Fin4→Formula ι) : ClauseFormula.Expr (ι:=ι) :=
body · 4
lines
ClauseFormula.choose (equal (e 0) (.constant 0)) (initialFamily β init W (e 1) (e 2) (e 3))
(ClauseFormula.choose (equal (e 0) (.constant 1)) (boundaryFamily β blank W (e 1) (e 2) (e 3))
(ClauseFormula.choose (equal (e 0) (.constant 2)) (localClause β g c output TW (e 1) (e 2) (e 3))
(finalFamily β accept TWO (e 3))))
lemmaclauseAt_exact {q β g TW : ℕ} [NeZero q] (L : Addressable.Layout q β g TW)
(c : Tableau.Circuit (3*β) g) (output : Fin β →Tableau.Wire (3*β+g))
{init : Formula ι →Fin β →InitialFormula.Expr (ι:=ι)} {Init : FinW→Fin β →Addressable.InputBit q}
(blank accept : Fin β →Bool) {T' w Oi : Formula ι} {v : ι →ℕ}
(hT : T'.eval v=T) (hw : w.eval v=W) (hO : O.eval v=L.origin.val)
(hi : ∀j J, j.eval v=J.val →∀r, InitialFormula.Represents (init j r) v (InitJ r))
(K : Fin (Tableau.Layout.clauseCount β g TW)) (hK : i.eval v=K.val) :
ClauseFormula.Represents (clauseAt β g c output init blank accept T' w O i) v
(L.clauseAt c output Init blank accept K).compile :=by
proof · 3
lines
apply familyClause_exact L c output blank accept _ hT hw hO hi (Addressable.Layout.clauseEquiv.symm K)
rw [clauseIndex_exact,hT,hw,hK]
exact Addressable.Layout.clause_index_lookup K
defunaryMove (a b : Expr (ι:=ι)) (count truth : Formula ι) : Formula ι :=
body · 13
lines
any [
all [first b,equalCells a (idle b (side b)),equalCells b (boundary b (side b))],
all [last b,equalCells a (boundary b (side b)),equalCells b (full b (side b) (.constant 0) .acquisition zeroReg)],
all [last b,equalCells a (full b (side b) (clause b) .acquisition (register b)),equalCells b (full b (side b) (clause b) .readLeft (register b))],
all [first b,equalCells a (full b (side b) (clause b) .readLeft (register b)),equalCells b (full b (side b) (clause b) .readRight (register b))],
all [last b,equalCells a (full b (side b) (clause b) .readRight (register b)),equalCells b (full b (side b) (clause b) .beforeGate (register b))],
all [last b,equalCells a (full b (side b) (clause b) .beforeGate (register b)),equalCells b (full b (side b) (clause b) .afterGate (register b)),equal truth (.constant 1)],
all [last b,equalCells a (full b (side b) (clause b) .afterGate (register b)),equalCells b (full b (side b) (clause b) .undoLeft (register b))],
all [first b,equalCells a (full b (side b) (clause b) .undoLeft (register b)),equalCells b (full b (side b) (clause b) .undoRight (register b))],
all [last b,equalCells a (full b (side b) (clause b) .undoRight (register b)),equalCells b (full b (side b) (clause b) .finish (register b))],
all [last b,equalCells a (full b (side b) (clause a) .finish zeroReg),equalCells b (full b (side b) (clause b) .acquisition zeroReg),equal (.add (clause a) (.constant 1)) (clause b)],
all [last b,equalCells a (full b (side b) (clause a) .finish zeroReg),equalCells b (full b (side b) (.constant 0) .success zeroReg),equal (.add (clause a) (.constant 1)) count],
all [last b,equalCells a (full b (neg (side b)) (.constant 0) .success zeroReg),equalCells b (full b (side b) (.constant 0) .success zeroReg),equal (b.20) (.constant 0)]]
defacquireMove (a b a' b' : Expr (ι:=ι)) (Q : Formula ι) : Formula ι := all
body · 3
lines
[skeletonPair (wing a .left) (wing b' .boundary) Q,
equalCells a (boundary a (side a)),equalCells b (idle b' (side a)),
equalCells a' (wing a .left),equalCells b' (boundary b' (side a))]
defreadLeftMove (a b a' b' : Expr (ι:=ι)) (Q : Formula ι) (delta : Fin3→Formula ι) : Formula ι := all
body · 3
lines
[skeletonPair (wing a .full) (wing b .right) Q,
equalCells a (wing a .left),equalCells b (full b (side b) (clause b) .readLeft (register b)),
equalCells a' (full a (side b) (clause b) .readLeft (addReg (register b) delta)),equalCells b' (wing b .right)]
defreadRightMove (a b a' b' : Expr (ι:=ι)) (Q : Formula ι) : Formula ι := all
body · 3
lines
[skeletonPair (wing a .full) (wing b .right) Q,
equalCells a (full a (side a) (clause a) .readRight (register a)),equalCells b (wing b .right),
equalCells a' (wing a .left),equalCells b' (full b (side a) (clause a) .readRight (register a))]
defundoLeftMove (a b a' b' : Expr (ι:=ι)) (Q : Formula ι) : Formula ι := all
body · 3
lines
[skeletonPair (wing a .full) (wing b .right) Q,
equalCells a (wing a .left),equalCells b (full b (side b) (clause b) .undoLeft (register b)),
equalCells a' (full a (side b) (clause b) .undoLeft (register b)),equalCells b' (wing b .right)]
defundoRightMove (a b a' b' : Expr (ι:=ι)) (Q : Formula ι) (delta : Fin3→Formula ι) : Formula ι := all
body · 3
lines
[skeletonPair (wing a .full) (wing b .right) Q,
equalCells a (full a (side a) (clause a) .undoRight (register a)),equalCells b (wing b .right),
equalCells a' (wing a .left),equalCells b' (full b (side a) (clause a) .undoRight (addReg (register a) delta))]
defbinaryMove (a b a' b' : Expr (ι:=ι)) (Q : Formula ι) (readDelta undoDelta : Fin3→Formula ι) : Formula ι := any
body · 3
lines
[acquireMove a b a' b' Q,readLeftMove a b a' b' Q readDelta,readRightMove a b a' b' Q,
undoLeftMove a b a' b' Q,undoRightMove a b a' b' Q undoDelta,checkerCreateMove a b a' b' Q,
checkerAdvanceMove a b a' b',swapMove a b a' b']
lemmareadLeftMove_exact (S : Schedule (2^h)) (delta : Fin3→Formula ι)
(hd : ∀i,(delta i).eval v=boolean (bit (c.delta (S.clause c.metadata.task d.head.clause) i))) :
(readLeftMove a b a' b' Q delta).eval v≠0↔Recognizer.ReadLeftTestS c d c' d' :=by
lemmaundoRightMove_exact (S : Schedule (2^h)) (delta : Fin3→Formula ι)
(hd : ∀i,(delta i).eval v=boolean (bit (c.delta (S.clause c.metadata.task c.head.clause) i))) :
(undoRightMove a b a' b' Q delta).eval v≠0↔Recognizer.UndoRightTestS c d c' d' :=by
lemmabinaryMove_exact (S : Schedule (2^h)) (rd ud : Fin3→Formula ι)
(hrd : ∀i,(rd i).eval v=boolean (bit (c.delta (S.clause c.metadata.task d.head.clause) i)))
(hud : ∀i,(ud i).eval v=boolean (bit (c.delta (S.clause c.metadata.task c.head.clause) i))) :
(binaryMove a b a' b' Q rd ud).eval v≠0↔BinaryS c d c' d' :=by
proof · 7
lines
rw [showBinaryS c d c' d' ↔Recognizer.BinaryTestS c d c' d' from
⟨Recognizer.binary_test,Recognizer.binary_of_test⟩]
simp only [binaryMove,Formula.any_ne_zero,List.mem_cons,List.not_mem_nil,or_false,exists_eq_or_imp,exists_eq_left,
acquireMove_exact hh ha hb ha' hb' Q hQ,readLeftMove_exact hh ha hb ha' hb' Q hQ S rd hrd,
readRightMove_exact hh ha hb ha' hb' Q hQ,undoLeftMove_exact hh ha hb ha' hb' Q hQ,
undoRightMove_exact hh ha hb ha' hb' Q hQ S ud hud,checkerCreateMove_exact hh ha hb ha' hb' Q hQ,
checkerAdvanceMove_exact hh ha hb ha' hb',swapMove_exact hh ha hb ha' hb',Recognizer.BinaryTest]
defbinaryRep (P : Table (ι:=ι)) (size Q : Formula ι) (a b a' b' : CellFormula.Expr (ι:=ι)) : Formula ι :=
body · 3
lines
all [formats a size (P.count a),formats b size (P.count b),formats a' size (P.count a'),formats b' size (P.count b'),
or (binaryMove a b a' b' Q (P.delta a b) (P.delta a a))
(binaryMove a' b' a b Q (P.delta a' b') (P.delta a' a'))]
lemmaunaryRep_exact {h n : ℕ} (hh : 4≤h) (P : Table (ι:=ι)) {v : ι →ℕ} {S : Schedule (2^h)}
(hP : P.Represents v S) {size : Formula ι} (hs : size.eval v=n)
{a b : CellFormula.Expr (ι:=ι)} {c d : Cell (2^h)}
(ha : CellFormula.evaluate a v=cellRecord c) (hb : CellFormula.evaluate b v=cellRecord d) :
(unaryRep P size a b).eval v≠0↔ReplacementS n [c] [d] :=by
proof · 6
lines
rw [←Recognizer.replacementTest_iff]
simp only [unaryRep,Formula.all_ne_zero,List.mem_cons,List.not_mem_nil,or_false,forall_eq_or_imp,forall_eq,
Formula.or_ne_zero,formats_exact ha S size (P.count a) n hs (hP a c ha).1,
formats_exact hb S size (P.count b) n hs (hP b d hb).1,
unaryMove_exact hh ha hb S (P.count b) (P.truth b) (hP b d hb).1 (P.truth_exact hP hb),
unaryMove_exact hh hb ha S (P.count a) (P.truth a) (hP a c ha).1 (P.truth_exact hP ha),Recognizer.ReplacementTest]
lemmabinaryRep_exact {h n : ℕ} (hh : 4≤h) (P : Table (ι:=ι)) {v : ι →ℕ} {S : Schedule (2^h)}
(hP : P.Represents v S) {size Q : Formula ι} (hs : size.eval v=n) (hQ : Q.eval v=2^h)
{a b a' b' : CellFormula.Expr (ι:=ι)} {c d c' d' : Cell (2^h)}
(ha : CellFormula.evaluate a v=cellRecord c) (hb : CellFormula.evaluate b v=cellRecord d)
(ha' : CellFormula.evaluate a' v=cellRecord c') (hb' : CellFormula.evaluate b' v=cellRecord d') :
(binaryRep P size Q a b a' b').eval v≠0↔ReplacementS n [c,d] [c',d'] :=by
proof · 9
lines
rw [←Recognizer.replacementTest_iff]
simp only [binaryRep,Formula.all_ne_zero,List.mem_cons,List.not_mem_nil,or_false,forall_eq_or_imp,forall_eq,
Formula.or_ne_zero,formats_exact ha S size (P.count a) n hs (hP a c ha).1,
formats_exact hb S size (P.count b) n hs (hP b d hb).1,
formats_exact ha' S size (P.count a') n hs (hP a' c' ha').1,
formats_exact hb' S size (P.count b') n hs (hP b' d' hb').1,
binaryMove_exact hh ha hb ha' hb' Q hQ S (P.delta a b) (P.delta a a) (P.delta_exact hP ha hb) (P.delta_exact hP ha ha),
binaryMove_exact hh ha' hb' ha hb Q hQ S (P.delta a' b') (P.delta a' a') (P.delta_exact hP ha' hb') (P.delta_exact hP ha' ha'),
Recognizer.ReplacementTest]
lemmaphysical_exact {q β g TWH : ℕ} [NeZero q] (L : Addressable.Layout q β g TW)
(c : Tableau.Circuit (3*β) g) (output : Fin β →Tableau.Wire (3*β+g))
(blank origin accept : Fin β →Bool) (encoding : Bool→Fin β →Bool)
(code : ListBool) (hd : 0<10000*H) (hdq : 10000*H≤q)
{T'W'OCNH' : Formula ι} {v : ι →ℕ}
(hT : T'.eval v=T) (hW : W'.eval v=W) (hO : O.eval v=L.origin.val)
(hC : C.eval v=binaryValue code) (hN : N.eval v=code.length) (hH : H'.eval v=H) :
(physical β g c output blank origin accept encoding T'W'OCNH').Represents v
(L.schedule c output (initial L blank origin encoding code H hd hdq) blank accept) :=by
proof · 18
lines
intro a A ha
havehcount : (clauseCount β g T'W').eval v=Tableau.Layout.clauseCount β g TW:=by
rw [clauseCount_exact,hT,hW]
refine ⟨hcount,?_⟩
intro j J hj
change ClauseFormula.Represents (ClauseFormula.choose _ _ _) v _
by_cases hJ : J.val<Tableau.Layout.clauseCount β g TW
· simp only [Addressable.Layout.schedule,dite_eq_left hJ]
apply ClauseFormula.choose_true (by simp [hj,hcount,hJ])
apply PhysicalFormula.clauseAt_exact L c output blank accept hT hW hO _ ⟨J.val,hJ⟩ hj
intro p P hp r
apply InitialFormula.cell_exact blank origin encoding P r hO hp
apply InitialFormula.inputPiece_exact code A.metadata.zeroTask hd hdq _ _ hC hN hH
· simp [eval,CellFormula.represent_int ha,cellRecord,integers,Meta.task]
· simp [CellFormula.represent_flag ha,cellRecord,flags]
· simp only [Addressable.Layout.schedule,dite_eq_right hJ]
apply ClauseFormula.choose_false (by simp [less_eval,hj,hcount,hJ])
exact ClauseFormula.unit_exact (ClauseFormula.fixedReading_exact (by rfl)) rfl
| .read i => f i
| .constant a => .constant a
| .add x y => .add (x.bind f) (y.bind f)
| .sub x y => .sub (x.bind f) (y.bind f)
| .mul x y => .mul (x.bind f) (y.bind f)
| .div x y => .div (x.bind f) (y.bind f)
| .mod x y => .mod (x.bind f) (y.bind f)
| .le x y => .le (x.bind f) (y.bind f)
| .powTwo x => .powTwo (x.bind f)
| .bitLength x => .bitLength (x.bind f)
| .branch c a b => .branch (c.bind f) (a.bind f) (b.bind f)
havehv : (funi : Fin2=> (![H,W] i).eval v)=RawFormula.inputs h (natCode w) :=by
funext i;fin_cases i <;> simp [RawFormula.inputs,hH,hW]
rw [valid,bind_eval,hv]
have hb :=RawFormula.valid_boolean h (natCode w)
have he :=RawFormula.accepts_iff_decode hh w
cases hd : decode hh w with
| none => simp only [hd,Option.isSome_none,Bool.false_eq_true,iff_false] at he; simpa [hd,boolean] using (showRawFormula.valid.eval (RawFormula.inputs h (natCode w))=0by omega)
| some c => simp only [hd,Option.isSome_some] at he;simpa [hd,boolean] using he.mpr trivial
lemmarawUnaryZero_exact {h n : ℕ} (hh : 4≤h) (P : Table (ι:=ι)) {v : ι →ℕ} {S : Schedule (2^h)}
(hP : P.Represents v S) {H size W : Formula ι} (w : Raw h)
(hH : H.eval v=h) (hs : size.eval v=n) (hW : W.eval v=natCode w) :
(rawUnaryZero PH size W).eval v≠0↔Codec.unaryZero (by omega) S n w :=by
proof · 7
lines
have hv := valid_value (show0<h by omega) w hH hW
cases hd : decode (show0<h by omega) w with
| none => simp [rawUnaryZero,branch_value,hv,hd,Codec.unaryZero]
| some c =>have hc := rawRepresents hh w hd hH hW
simpa only [rawUnaryZero,branch_value,hv,hd,Option.isSome_some,boolean_true,Nat.one_ne_zero,ite_false,Codec.unaryZero] using
(unaryZero_exact hc S size (P.count (ofRaw HW)) (P.truth (ofRaw HW)) n hs (hP _ c hc).1 (P.truth_exact hP hc))
lemmarawBinaryZero_exact {h : ℕ} (hh : 4≤h) {v : ι →ℕ} {HQWZ : Formula ι} (w z : Raw h)
(hH : H.eval v=h) (hQ : Q.eval v=2^h) (hW : W.eval v=natCode w) (hZ : Z.eval v=natCode z) :
(rawBinaryZero HQWZ).eval v≠0↔Codec.binaryZero (by omega) w z :=by
proof · 9
lines
have hw := valid_value (show0<h by omega) w hH hW
have hz := valid_value (show0<h by omega) z hH hZ
cases hdw : decode (show0<h by omega) w <;> cases hdz : decode (show0<h by omega) z
all_goals try simp [rawBinaryZero,branch_value,and_eval,hw,hz,hdw,hdz,Codec.binaryZero]
rename_i c d
have hc := rawRepresents hh w hdw hH hW
have hd := rawRepresents hh z hdz hH hZ
simpa only [rawBinaryZero,branch_value,and_eval,hw,hz,hdw,hdz,Option.isSome_some,boolean_true,Nat.one_ne_zero,ite_false,Codec.binaryZero] using
(binaryZero_exact hc hd Q hQ)
lemmarawUnaryRep_exact {h n : ℕ} (hh : 4≤h) (P : Table (ι:=ι)) {v : ι →ℕ} {S : Schedule (2^h)}
(hP : P.Represents v S) {H size WZ : Formula ι} (w z : Raw h)
(hH : H.eval v=h) (hs : size.eval v=n) (hW : W.eval v=natCode w) (hZ : Z.eval v=natCode z) :
(rawUnaryRep PH size WZ).eval v≠0↔Codec.replacement (by omega) S n [w] [z] :=by
proof · 10
lines
have hw := valid_value (show0<h by omega) w hH hW
have hz := valid_value (show0<h by omega) z hH hZ
cases hdw : decode (show0<h by omega) w <;> cases hdz : decode (show0<h by omega) z
all_goals try simp [rawUnaryRep,branch_value,and_eval,hw,hz,hdw,hdz,Codec.replacement,decodeWord]
rename_i c d
have hc := rawRepresents hh w hdw hH hW
have hd := rawRepresents hh z hdz hH hZ
simpa only [rawUnaryRep,branch_value,and_eval,hw,hz,hdw,hdz,Option.isSome_some,boolean_true,Nat.one_ne_zero,ite_false,
Codec.replacement,decodeWord,Option.bind_some,Option.some.injEq] using
(unaryRep_exact hh P hP hs hc hd)