lemmaReading.eval_map {n : ℕ} (m : Fin n →FiniteTable.Address q)
(w : Wire n) (v : FiniteTable.Address q →Bool) :
Reading.eval (w.map id m) v=w.eval (v ∘ m) :=by cases w <;> rfl
defClause.compile (C : Clause q) : FiniteTable.Clause q where
body · 6
lines
address i :=matchC.wires i with
| .inl _ => .certificate 0
| .inr a => a
truth r :=C.truth (fun i =>matchC.wires i with
| .inl b => b
| .inr _ => unbit (r i))
lemmaClause.compile_holds (C : Clause q) (v : FiniteTable.Address q →Bool) :
(C.compile.truth fun i => bit (v (C.compile.address i)))=true↔C.Holds v :=by
proof · 10
lines
havehe : (fun i =>matchC.wires i with
| .inl b => b
| .inr _ => unbit (bit (v (C.compile.address i)))) = fun i => (C.wires i).eval v :=by
funext i
cases hi : C.wires i <;> simp [compile,Reading.eval,hi]
change (C.truth (fun i =>matchC.wires i with
| .inl b => b
| .inr _ => unbit (bit (v (C.compile.address i)))))=true↔C.Holds v
rw [he]
rfl
definitial (a : Reading q) : InputBit q →Fin2→Clause q
body · 5
lines
| .fixed b,_ => unit a b
| .input p neg,i =>
⟨![a,.inr (dataAddress p),a], fun v =>let x :=if neg then !v 1else v 1if i.val=0then !v 0 || x else v 0 || !x⟩
lemmaofCircuitClause_holds {n : ℕ} (m : Fin n →FiniteTable.Address q)
(C : Tableau.Circuit.Clause n) (v : FiniteTable.Address q →Bool) :
(ofCircuitClause m C).Holds v ↔C.Holds (v ∘ m) :=by
proof · 6
lines
havehe : (fun i =>Reading.eval ((C.wires i).map id m) v) =
fun i => (C.wires i).eval (v ∘ m) :=by
funext i
cases C.wires i <;> rfl
change (C.truth fun i =>Reading.eval ((C.wires i).map id m) v)=true↔C.truth _=true
rw [he]
lemmalocalClause_holds (c : Circuit (3*β) g) (output : Fin β →Wire (3*β+g))
(t : Fin (T-1)) (j : Fin (W-2)) (v : FiniteTable.Address q →Bool) :
(∀ i, (L.localClause c output t j i).Holds v) ↔
c.Satisfies (v ∘L.localRead t j) ∧∀ r, v (L.x (nextTime t) (interior j) r) =
(output r).eval (v ∘L.localRead t j) :=by
proof · 26
lines
constructor
· intro h
constructor
· apply (c.clauses_iff (v ∘L.localRead t j)).mp
intro C hc
obtain ⟨i,hi,rfl⟩ :=List.mem_iff_getElem.mp hc
havehi' : i<3*g :=by simpa only [c.clauses_length] using hi
have hv := h (Fin.castAdd (2*β) ⟨i,hi'⟩)
rw [L.localClause_gate] at hv
exact (ofCircuitClause_holds ..).mp hv
· intro r
have he := (equal_holds (.inr (L.x (nextTime t) (interior j) r))
((output r).map id (L.localRead t j)) v).mp (fun k =>byhave hk := h (outputIndex r k)
rwa [L.localClause_output] at hk)
change v (L.x (nextTime t) (interior j) r)=_ at he
simpa only [Reading.eval_map] using he
· rintro ⟨hc,ho⟩ i
unfold localClause
split_ifs with hi
· apply (ofCircuitClause_holds ..).mpr
exact (c.clauses_iff (v ∘L.localRead t j)).mpr hc _ (List.getElem_mem _)
· apply (equal_holds _ _ v).mpr
change v (L.x (nextTime t) (interior j) _)=_
have he := ho ⟨(i.val-3*g)/2,byhave:= i.isLt; omega⟩
simpa only [Reading.eval_map] using he
lemmaclauseAt_holds_iff (c : Circuit (3*β) g) (output : Fin β →Wire (3*β+g))
(init : FinW→Fin β →InputBit q) (blank accept : Fin β →Bool)
(v : FiniteTable.Address q →Bool) :
(∀ i, (L.clauseAt c output init blank accept i).Holds v) ↔L.FiniteValid c output init blank accept v :=by
proof · 23
lines
rw [L.all_clauses_iff]
constructor
· intro h
refine ⟨?_,?_,?_,?_,?_⟩
· intro j r
exact (initial_holds _ _ v).mp (fun k => h (.inl (.inl (.inl ((j,r),k)))))
· intro t k r
exact (unit_holds _ _ v).mp (h (.inl (.inl (.inr ((t,k),r)))))
· intro t j
exact ((L.localClause_holds c output t j v).mp (fun i => h (.inl (.inr ((t,j),i))))).1
· intro t j r
exact ((L.localClause_holds c output t j v).mp (fun i => h (.inl (.inr ((t,j),i))))).2 r
· intro r
exact (unit_holds _ _ v).mp (h (.inr r))
· rintro ⟨hi,hb,hg,ho,ha⟩ i
rcases i with ((i|i)|i)|i
· rcases i with ⟨⟨j,r⟩,k⟩
exact (initial_holds (.inr (L.x ⟨0,L.time_pos⟩ j r)) (init j r) v).mpr (hi j r) k
· rcases i with ⟨⟨t,k⟩,r⟩
exact (unit_holds _ _ v).mpr (hb t k r)
· rcases i with ⟨⟨t,j⟩,k⟩
exact (L.localClause_holds c output t j v).mpr ⟨hg t j,ho t j⟩ k
· exact (unit_holds _ _ v).mpr (ha i)
lemmalocalRead_rows (v : FiniteTable.Address q →Bool) (t : Fin (T-1)) (j : Fin (W-2)) :
v ∘L.localRead t j =
Rectangle.assignment (L.rows v t.val) j.val (L.gates v t.val j.val) :=by
proof · 11
lines
funext i
refine Fin.addCases (fun k => ?_) (fun k => ?_) i
· simp only [Function.comp_apply,localRead,Fin.addCases_left,Rectangle.assignment,
Rectangle.neighborhood]
exact (L.rows_at v (show t.val<Tbyhave:= t.isLt; omega)
(show j.val+(finProdFinEquiv.symm k : Fin3×Fin β).1.val<Wbyhave:= j.isLt
have:= (finProdFinEquiv.symm k : Fin3×Fin β).1.isLt
omega) _).symm
· simp only [Function.comp_apply,localRead,Fin.addCases_right,Rectangle.assignment]
exact (L.gates_at v t.isLt j.isLt k).symm
lemmarectangle_of_finiteValid (c : Circuit (3*β) g) (output : Fin β →Wire (3*β+g))
(init : FinW→Fin β →InputBit q) (blank accept : Fin β →Bool)
(v : FiniteTable.Address q →Bool) (hv : L.FiniteValid c output init blank accept v) :
Rectangle.Valid c output TW blank (L.inputRow init v) (L.rows v) (L.gates v) ∧L.rows v (T-1) L.origin.val=accept :=by
proof · 32
lines
constructor
· refine ⟨?_,?_,?_,?_⟩
· intro j hj
funext r
rw [L.rows_at v L.time_pos hj,L.inputRow_at init v hj]
exact hv.1 _ _
· intro t ht j hj hjb
haveht' : t<T-1:=by omega
funext r
rw [L.rows_at v ht hj]
rcases hjb with rfl|he
· have hb := hv.2.1 ⟨t,ht'⟩ 0 r
simpa only [nextTime,boundary,Fin.val_zero,ite_true] using hb
· have hb := hv.2.1 ⟨t,ht'⟩ 1 r
havehj' : j=W-1:=by omega
subst j
simpa only [nextTime,boundary,Fin.val_one,show¬(1:ℕ)=0by omega,ite_false] using hb
· intro t ht j hj
haveht' : t<T-1:=by omega
havehj' : j<W-2:=by omega
have hc := hv.2.2.1 ⟨t,ht'⟩ ⟨j,hj'⟩
rwa [L.localRead_rows] at hc
· intro t ht j hj r
haveht' : t<T-1:=by omega
havehj' : j<W-2:=by omega
have hc := hv.2.2.2.1 ⟨t,ht'⟩ ⟨j,hj'⟩ r
rw [L.localRead_rows] at hc
rw [L.rows_at v ht (show j+1<Wby omega)]
exact hc
· funext r
rw [L.rows_at v (byhave:=L.time_pos; omega) L.origin.isLt]
exact hv.2.2.2.2 r
lemmalocalRead_rect (data : DataAddress q →Bool)
(X : ℕ→Rectangle.Row β) (Y : ℕ→ℕ→Fin g →Bool)
(t : Fin (T-1)) (j : Fin (W-2)) :
L.payload data (rectCertificate XY) ∘L.localRead t j =
Rectangle.assignment (X t.val) j.val (Y t.val j.val) :=by
proof · 6
lines
funext i
refine Fin.addCases (fun k => ?_) (fun k => ?_) i
· simp only [Function.comp_apply,localRead,Fin.addCases_left,payload_x,rectCertificate,
currentTime,Rectangle.assignment,Rectangle.neighborhood]
· simp only [Function.comp_apply,localRead,Fin.addCases_right,payload_y,rectCertificate,
Rectangle.assignment]
theoremcertificate_iff (c : Circuit (3*β) g) (output : Fin β →Wire (3*β+g))
(init : FinW→Fin β →InputBit q) (blank accept : Fin β →Bool)
(data : DataAddress q →Bool) :
(∃cert : Fin q →Bool, ∀ i,
(L.clauseAt c output init blank accept i).Holds (assemble data cert)) ↔Rectangle.run c output W blank (L.inputRow init (assemble data (fun _ =>false)))
(T-1) L.origin.val=accept :=by
proof · 13
lines
constructor
· rintro ⟨cert,hc⟩
have hh :=L.clause_sound c output init blank accept (assemble data cert) hc
rwa [L.inputRow_assemble init data cert (fun _ =>false)] at hh
· intro ha
letX:=Rectangle.run c output W blank (L.inputRow init (assemble data (fun _ =>false)))
letY:=fun t j v => c.evaluate (Rectangle.neighborhood (X t) j) (Fin.natAdd (3*β) v)
refine ⟨L.certificate (rectCertificate XY),?_⟩
change ∀ i, (L.clauseAt c output init blank accept i).Holds
(L.payload data (rectCertificate XY))
exact (L.clauseAt_holds_iff c output init blank accept _).mpr
(L.finiteValid_of_rectangle c output init blank accept data XY
(Rectangle.run_valid c output TW blank _) ha)
theoremphysical_clauses_iff (L : Layout q β g TW)
(c : Circuit (3*β) g) (output : Fin β →Wire (3*β+g))
(init : Task→FinW→Fin β →InputBit q) (blank accept : Fin β →Bool)
(R : FiniteTable.Region q d) :
(∀ i, (R.plan (L.schedule c output init blank accept)).Holds i) ↔∀ i, (L.clauseAt c output (init R.task) blank accept i).Holds (physicalBits R) :=by
proof · 9
lines
letS:=L.schedule c output init blank accept
have he (i : Fin (Tableau.Layout.clauseCount β g TW)) :
(R.plan S).Holds i ↔ (L.clauseAt c output (init R.task) blank accept i).Holds (physicalBits R) :=by
rw [R.holds_iff S i]
havehi : R.clauseIndex S i=Fin.castLE L.clause_fit i :=by rfl
rw [hi,L.schedule_clause]
have hh :=Clause.compile_holds (L.clauseAt c output (init R.task) blank accept i) (physicalBits R)
simpa only [physicalBits,bit_unbit] using hh
exact forall_congr' he
theoremreached_success_accepts (L : Layout q β g TW)
(c : Circuit (3*β) g) (output : Fin β →Wire (3*β+g))
(init : Task→FinW→Fin β →InputBit q) (blank accept : Fin β →Bool)
(v : List (Cell q)) (f : FinN→Cell q) (i : FinN)
(hv : Syntax (L.schedule c output init blank accept) d v)
(hi : ∀ a ∈ v, a.marker=.idle)
(hr : Reach (L.schedule c output init blank accept) d v (List.ofFn f))
(hh : (f i).marker=.full) (hp : (f i).head.phase=.success) :
let hs := reach_syntax hr hv
proof · 8
lines
letR:=Component.region f i hs hh
Rectangle.run c output W blank (L.inputRow (init R.task) (physicalBits R))
(T-1) L.origin.val=accept :=by
intro hs R
apply physical_accepts L c output init blank accept R
apply Component.region_holds f i hs hh _ hp
have hg :=Verification.reach_clean_good (L.schedule c output init blank accept) hv hi hr
exact ((Verification.wordGood_ofFn (L.schedule c output init blank accept) f).mp hg) i hh