Download data/lean/OAI/Probability/SKGap/Matrix/ClosedErrorTrace.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 13 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/SKGap/Matrix/ClosedErrorTrace.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/SKGap/Matrix/ClosedErrorTrace.lean
-
curl -L -o ClosedErrorTrace.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/SKGap/Matrix/ClosedErrorTrace.lean
13 kB
| import Mathlib | |
| import OAI.Probability.SKGap.Matrix.PrimitiveTrace | |
| import OAI.Probability.SKGap.Matrix.ClosedTrace | |
| namespace OAI | |
| section | |
| noncomputable section | |
| open scoped BigOperators | |
| namespace SKGapCutoff.Recipe | |
| open Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Diagram | |
| variable {n : β} | |
| theorem finite_graph_trace_tested (J : Interaction n) (E F Es Ef : ββInteraction n) | |
| (p : (a : β)βFin aβFin nββ) (r : (a : β)βFin aββ) | |
| (hE : βa,E a=(βb:Fin a,Matrix.diagonal (p a b)*F b)+Es a) | |
| (hF : βa,F a=J*E a-(βb:Fin a,r a b β’ E b)+Ef a) | |
| {A R M : β} {Cs Cf : βββ} {N L : β} | |
| (_ : 0β€R) (_ : 0β€M) | |
| (hp : βaβ€N,βb i,|p a b i|β€A) (hr : βaβ€N,βb,|r a b|β€R) | |
| (hsn : βaβ€N,0β€Cs a) (hfn : βaβ€N,0β€Cf a) | |
| (hs : βaβ€N,βw:OrdinaryWord n,w.lengthβ€LβwordBounded A wβ | |
| |trace (matrixWord J w*Es a)|β€Cs a*M) | |
| (hf : βaβ€N,βw:OrdinaryWord n,w.lengthβ€LβwordBounded A wβ | |
| |trace (matrixWord J w*Ef a)|β€Cf a*M) : | |
| βaβ€N, | |
| (βw:OrdinaryWord n,w.length+2*a+1β€LβwordBounded A wβ | |
| |trace (matrixWord J w*E a)|β€(errorBudget R Cs Cf a).1*M) β§ | |
| (βw:OrdinaryWord n,w.length+2*a+2β€LβwordBounded A wβ | |
| |trace (matrixWord J w*F a)|β€(errorBudget R Cs Cf a).2*M) := by | |
| intro a | |
| induction a using Nat.strong_induction_on with | |
| | h a ih => | |
| intro ha | |
| have hsβ : 0β€Cs a := hsn a ha | |
| have hfβ : 0β€Cf a := hfn a ha | |
| have hprev (b : Fin a) := ih b b.isLt (b.isLt.le.trans ha) | |
| have hCs (w : OrdinaryWord n) (hlen : w.lengthβ€L) (hwb : wordBounded A w) : | |
| |trace (matrixWord J w*Es a)|β€Cs a*M := | |
| hs a ha w hlen hwb | |
| have hCf (w : OrdinaryWord n) (hlen : w.lengthβ€L) (hwb : wordBounded A w) : | |
| |trace (matrixWord J w*Ef a)|β€Cf a*M := | |
| hf a ha w hlen hwb | |
| have hsource : βw:OrdinaryWord n,w.length+2*a+1β€LβwordBounded A wβ | |
| |trace (matrixWord J w*E a)|β€(errorBudget R Cs Cf a).1*M := by | |
| intro w hlen hwb | |
| have hterms (b : Fin a) : |trace (matrixWord J w*(Matrix.diagonal (p a b)*F b))|β€ | |
| (errorBudget R Cs Cf b).2*M := by | |
| have H:=(hprev b).2 (w++[.diag (p a b)]) (by simp only [List.length_append,List.length_singleton]; omega) | |
| (wordBounded_diag hwb _ (hp a ha b)) | |
| simpa only [matrixWord_append,matrixWord,List.map_cons,List.map_nil,List.prod_cons,List.prod_nil, | |
| matrixLetter,List.map_append,List.prod_append,mul_one,mul_assoc] using H | |
| rw [hE a,mul_add,trace_add,errorBudget] | |
| dsimp only | |
| have H:=(Finset.abs_sum_le_sum_abs (s:=Finset.univ) (f:=fun b:Fin a=>trace (matrixWord J w*(Matrix.diagonal (p a b)*F b)))).trans | |
| (Finset.sum_le_sum fun b _=>hterms b) | |
| rw [βtrace_sum,βMatrix.mul_sum,βFinset.sum_mul] at H | |
| exact ((abs_add_le _ _).trans (add_le_add H (hCs w (by omega) hwb))).trans_eq (by ring) | |
| refine β¨hsource,?_β© | |
| intro w hlen hwb | |
| have hsnew:=hsource (w++[.noise]) (by simp only [List.length_append,List.length_singleton]; omega) | |
| (wordBounded_noise hwb) | |
| have Hs : |trace (matrixWord J w*(J*E a))|β€(errorBudget R Cs Cf a).1*M := by | |
| simpa only [matrixWord_append,matrixWord,List.map_cons,List.map_nil,List.prod_cons,List.prod_nil, | |
| matrixLetter,List.map_append,List.prod_append,mul_one,mul_assoc] using hsnew | |
| have hterms (b : Fin a) : |trace (matrixWord J w*(r a b β’ E b))|β€ | |
| R*(errorBudget R Cs Cf b).1*M := by | |
| have H:=(hprev b).1 w (by omega) hwb | |
| have hB : 0β€(errorBudget R Cs Cf b).1*M := (abs_nonneg _).trans H | |
| rw [Matrix.mul_smul,trace_smul,smul_eq_mul,abs_mul] | |
| exact ((mul_le_mul_of_nonneg_left H (abs_nonneg _)).trans | |
| (mul_le_mul_of_nonneg_right (hr a ha b) hB)).trans_eq (by ring) | |
| have H:=(Finset.abs_sum_le_sum_abs (s:=Finset.univ) (f:=fun b:Fin a=>trace (matrixWord J w*(r a b β’ E b)))).trans | |
| (Finset.sum_le_sum fun b _=>hterms b) | |
| rw [βtrace_sum,βMatrix.mul_sum] at H | |
| rw [hF a,mul_add,mul_sub,trace_add,trace_sub] | |
| apply ((abs_add_le _ _).trans (add_le_add ((abs_sub _ _).trans (add_le_add Hs H)) | |
| (hCf w (by omega) hwb))).trans_eq | |
| rw [errorBudget] | |
| dsimp only | |
| rw [βFinset.sum_mul,βFinset.mul_sum] | |
| ring | |
| def closedWordBounded (A : β) (w : List (WordLetter (Fin n))) : Prop := | |
| βlβw,match l with | .diag p=>βi,|p i|β€A | .noise=>True | .inverse=>True | |
| def ClosedWordTestBound (j : β) (a : Fin nββ) (J : Interaction n) | |
| (A M : β) (L : β) : Prop := | |
| βw:List (WordLetter (Fin n)),w.lengthβ€LβinverseCount wβ€1βclosedWordBounded A wβ | |
| testSize (exactWord j a w J)β€M | |
| lemma closedWordBounded_append {A : β} {P Q : List (WordLetter (Fin n))} | |
| (hP : closedWordBounded A P) (hQ : closedWordBounded A Q) : closedWordBounded A (P++Q) := by | |
| intro l hl;rcases List.mem_append.mp hl with hl|hl | |
| Β· exact hP l hl | |
| Β· exact hQ l hl | |
| lemma closedWordBounded_lift {A : β} {w : OrdinaryWord n} (hw : wordBounded A w) : | |
| closedWordBounded A (liftWord w) := by | |
| intro l hl | |
| obtain β¨q,hq,rflβ©:=List.mem_map.mp hl | |
| cases q with | |
| | diag p=>exact hw _ hq | |
| | noise=>trivial | |
| lemma implicit_error_elimination (A J K E F Es Ef : Interaction n) (q : β) | |
| (hK : K*(1-A*(J-q β’ 1))=1) | |
| (hE : E=A*F+Es) (hF : F=(J-q β’ 1)*E+Ef) : | |
| E=K*(Es+A*Ef) := by | |
| have he : (1-A*(J-q β’ 1))*E=Es+A*Ef := by | |
| rw [sub_mul,one_mul,mul_assoc] | |
| rw [hF,mul_add] at hE | |
| nth_rw 1 [hE] | |
| abel | |
| have hk:=congrArg (fun P:Interaction n=>K*P) he | |
| rw [βmul_assoc,hK,one_mul] at hk | |
| exact hk | |
| theorem implicit_trace_bound (j : β) (a : Fin nββ) (J Es Ef : Interaction n) | |
| {C D A M : β} {L : β} (hs : TraceControl Es C) (hf : TraceControl Ef D) | |
| (ha : βi,|a i|β€A) (hw : ClosedWordTestBound j a J A M L) | |
| (w : OrdinaryWord n) (hlen : w.length+2β€L) (hwb : wordBounded A w) : | |
| |trace (matrixWord J w*((WordLetter.inverse.exactEval j a J)*(Es+Matrix.diagonal a*Ef)))| | |
| β€(C+D)*M := by | |
| have hbβ : closedWordBounded (n:=n) A [WordLetter.inverse] := by | |
| intro l hl;have hlβ:=List.mem_singleton.mp hl;subst l;trivial | |
| have hbβ : closedWordBounded A [WordLetter.inverse,.diag a] := by | |
| intro l hl;simp only [List.mem_cons,List.not_mem_nil,or_false] at hl | |
| rcases hl with rfl|rfl | |
| Β· trivial | |
| Β· exact ha | |
| have hβ := hw (liftWord w++[.inverse]) | |
| (by simpa only [liftWord,List.length_map,List.length_append,List.length_singleton] using (show w.length+1β€L by omega)) | |
| (by rw [inverseCount_append,inverseCount_lift];simp [inverseCount]) (closedWordBounded_append (closedWordBounded_lift hwb) hbβ) | |
| have hβ := hw (liftWord w++[.inverse,.diag a]) | |
| (by simpa only [liftWord,List.length_map,List.length_append,List.length_cons,List.length_nil] using hlen) | |
| (by rw [inverseCount_append,inverseCount_lift];simp [inverseCount]) (closedWordBounded_append (closedWordBounded_lift hwb) hbβ) | |
| rw [exactWord_append,exactWord_lift] at hβ hβ | |
| simp only [exactWord,matrixFactorProduct,List.map_cons,List.map_nil, | |
| List.prod_cons,List.prod_nil,mul_one,WordLetter.exactEval] at hβ hβ | |
| have Hβ:=(hs.bound (matrixWord J w*WordLetter.inverse.exactEval j a J)).trans | |
| (mul_le_mul_of_nonneg_left hβ hs.nonneg) | |
| have Hβ:=(hf.bound (matrixWord J w*WordLetter.inverse.exactEval j a J*Matrix.diagonal a)).trans | |
| (mul_le_mul_of_nonneg_left (by simpa only [mul_assoc,WordLetter.exactEval] using hβ) hf.nonneg) | |
| rw [mul_add,mul_add,trace_add] | |
| exact ((abs_add_le _ _).trans (add_le_add | |
| (by simpa only [mul_assoc] using Hβ) (by simpa only [mul_assoc] using Hβ))).trans_eq (by ring) | |
| theorem implicit_source_field_trace (j : β) (a : Fin nββ) (J E F Es Ef : Interaction n) (q : β) | |
| (hE : E=WordLetter.inverse.exactEval j a J*(Es+Matrix.diagonal a*Ef)) | |
| (hF : F=(J-q β’ 1)*E+Ef) | |
| {C D A M : β} {L : β} (hs : TraceControl Es C) (hf : TraceControl Ef D) | |
| (ha : βi,|a i|β€A) (hw : ClosedWordTestBound j a J A M L) | |
| (w : OrdinaryWord n) (hlen : w.length+3β€L) (hwb : wordBounded A w) : | |
| |trace (matrixWord J w*E)|β€(C+D)*M β§ | |
| |trace (matrixWord J w*F)|β€((1+|q|)*(C+D)+D)*M := by | |
| have HE : |trace (matrixWord J w*E)|β€(C+D)*M := by | |
| rw [hE];exact implicit_trace_bound j a J Es Ef hs hf ha hw w (by omega) hwb | |
| have HJ : |trace (matrixWord J w*(J*E))|β€(C+D)*M := by | |
| have H:=implicit_trace_bound j a J Es Ef hs hf ha hw (w++[.noise]) | |
| (by simp only [List.length_append,List.length_singleton];omega) (wordBounded_noise hwb) | |
| simpa only [βhE,matrixWord_append,matrixWord,List.map_cons,List.map_nil,List.prod_cons, | |
| List.prod_nil,List.map_append,List.prod_append,matrixLetter,mul_one,mul_assoc] using H | |
| have Hf : |trace (matrixWord J w*Ef)|β€D*M := by | |
| have H:=hw (liftWord w) (by simp only [liftWord,List.length_map];omega) | |
| (by simp) (closedWordBounded_lift hwb) | |
| rw [exactWord_lift] at H | |
| exact (hf.bound _).trans (mul_le_mul_of_nonneg_left H hf.nonneg) | |
| refine β¨HE,?_β© | |
| rw [hF,sub_mul,smul_mul_assoc,one_mul,mul_add,mul_sub,Matrix.mul_smul, | |
| trace_add,trace_sub,trace_smul,smul_eq_mul] | |
| have HQ : |q*trace (matrixWord J w*E)|β€|q| *((C+D)*M) := by | |
| rw [abs_mul];exact mul_le_mul_of_nonneg_left HE (abs_nonneg _) | |
| exact ((abs_add_le _ _).trans (add_le_add ((abs_sub _ _).trans (add_le_add HJ HQ)) Hf)).trans_eq (by ring) | |
| lemma ClosedWordTestBound.ordinary {j : β} {a : Fin nββ} {J : Interaction n} | |
| {A M : β} {L : β} (h : ClosedWordTestBound j a J A M L) : WordTestBound J A M L := by | |
| intro w hw hb | |
| have H:=h (liftWord w) (by simpa only [liftWord,List.length_map] using hw) | |
| (by simp) (closedWordBounded_lift hb) | |
| simpa only [exactWord_lift] using H | |
| theorem closed_finite_graph_trace (j : β) (aβ : Fin nββ) (J : Interaction n) | |
| (E F Es Ef : ββInteraction n) (P Q : Interaction n) (q : β) | |
| (p : (a : β)βFin aβFin nββ) (r : (a : β)βFin aββ) | |
| (hE : βa,E a=(βb:Fin a,Matrix.diagonal (p a b)*F b)+Es a) | |
| (hF : βa,F a=J*E a-(βb:Fin a,r a b β’ E b)+Ef a) | |
| (hEs : Es 0=WordLetter.inverse.exactEval j aβ J*(P+Matrix.diagonal aβ*Q)) | |
| (hEf : Ef 0=(-q) β’ Es 0+Q) | |
| {C D A R M : β} {Cs Cf : βββ} {N L : β} | |
| (hP : TraceControl P C) (hQ : TraceControl Q D) | |
| (hR : 0β€R) (hM : 0β€M) (ha : βi,|aβ i|β€A) | |
| (hp : βaβ€N,βb i,|p a b i|β€A) (hr : βaβ€N,βb,|r a b|β€R) | |
| (hs : βaβ€N,0<aβTraceControl (Es a) (Cs a)) | |
| (hf : βaβ€N,0<aβTraceControl (Ef a) (Cf a)) | |
| (hw : ClosedWordTestBound j aβ J A M (L+2)) : | |
| let Bs:=fun a=>if a=0 then C+D else Cs a | |
| let Bf:=fun a=>if a=0 then |q| *(C+D)+D else Cf a | |
| βaβ€N, | |
| (βw:OrdinaryWord n,w.length+2*a+1β€LβwordBounded A wβ | |
| |trace (matrixWord J w*E a)|β€(errorBudget R Bs Bf a).1*M) β§ | |
| (βw:OrdinaryWord n,w.length+2*a+2β€LβwordBounded A wβ | |
| |trace (matrixWord J w*F a)|β€(errorBudget R Bs Bf a).2*M) := by | |
| dsimp only | |
| have hsource (w : OrdinaryWord n) (hlen : w.lengthβ€L) (hwb : wordBounded A w) : | |
| |trace (matrixWord J w*Es 0)|β€(C+D)*M := by | |
| rw [hEs] | |
| exact implicit_trace_bound j aβ J P Q hP hQ ha hw w (by omega) hwb | |
| have hfield (w : OrdinaryWord n) (hlen : w.lengthβ€L) (hwb : wordBounded A w) : | |
| |trace (matrixWord J w*Ef 0)|β€(|q| *(C+D)+D)*M := by | |
| have Hβ:=hsource w hlen hwb | |
| have Hβ:=(hQ.bound (matrixWord J w)).trans (mul_le_mul_of_nonneg_left | |
| (hw.ordinary w (by omega) hwb) hQ.nonneg) | |
| rw [hEf,mul_add,Matrix.mul_smul,trace_add,trace_smul,smul_eq_mul] | |
| have Hβ : |(-q)*trace (matrixWord J w*Es 0)|β€|q| *((C+D)*M) := by | |
| rw [abs_mul,abs_neg];exact mul_le_mul_of_nonneg_left Hβ (abs_nonneg q) | |
| exact ((abs_add_le _ _).trans (add_le_add Hβ Hβ)).trans_eq (by ring) | |
| apply finite_graph_trace_tested J E F Es Ef p r hE hF hR hM hp hr | |
| Β· intro a haN;split_ifs with h | |
| Β· exact add_nonneg hP.nonneg hQ.nonneg | |
| Β· exact (hs a haN (Nat.pos_of_ne_zero h)).nonneg | |
| Β· intro a haN;split_ifs with h | |
| Β· exact add_nonneg (mul_nonneg (abs_nonneg _) (add_nonneg hP.nonneg hQ.nonneg)) hQ.nonneg | |
| Β· exact (hf a haN (Nat.pos_of_ne_zero h)).nonneg | |
| Β· intro a haN w hlen hwb | |
| by_cases ha0 : a=0 | |
| Β· subst a;simpa only [ite_true] using hsource w hlen hwb | |
| Β· simpa only [ite_eq_right ha0] using (hs a haN (Nat.pos_of_ne_zero ha0)).bound (matrixWord J w) |>.trans | |
| (mul_le_mul_of_nonneg_left (hw.ordinary w (by omega) hwb) (hs a haN (Nat.pos_of_ne_zero ha0)).nonneg) | |
| Β· intro a haN w hlen hwb | |
| by_cases ha0 : a=0 | |
| Β· subst a;simpa only [ite_true] using hfield w hlen hwb | |
| Β· simpa only [ite_eq_right ha0] using (hf a haN (Nat.pos_of_ne_zero ha0)).bound (matrixWord J w) |>.trans | |
| (mul_le_mul_of_nonneg_left (hw.ordinary w (by omega) hwb) (hf a haN (Nat.pos_of_ne_zero ha0)).nonneg) | |
| end SKGapCutoff.Recipe | |
| end | |
| end | |
| end OAI | |