Download data/lean/OAI/Combinatorics/MatchingCount/Algorithm/OutputLengthBound.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 41.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/MatchingCount/Algorithm/OutputLengthBound.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/MatchingCount/Algorithm/OutputLengthBound.lean
-
curl -L -o OutputLengthBound.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/MatchingCount/Algorithm/OutputLengthBound.lean
41.7 kB
| import Mathlib | |
| import OAI.Combinatorics.MatchingCount.Algorithm.FiniteStage | |
| import OAI.Combinatorics.MatchingCount.Algorithm.RationalStart | |
| import OAI.Combinatorics.MatchingCount.Algorithm.RationalCounts | |
| import OAI.Combinatorics.MatchingCount.Algorithm.EmpiricalDenom | |
| namespace OAI | |
| namespace MatchingFPRAS | |
| open Finset | |
| lemma Perfect.vertices_le_twice_edges {G : GraphInput} {M : Finset (Fin G.n Γ Fin G.n)} | |
| (h : Perfect G M) : G.nβ€2*G.edges.card := by | |
| classical | |
| have hs : (univ : Finset (Fin G.n)) β G.edges.image Prod.fst βͺ G.edges.image Prod.snd := by | |
| intro v _ | |
| obtain β¨e,β¨he,hiβ©,_β©:=h.2 v | |
| rcases hi with hi|hi | |
| Β· exact mem_union_left _ (mem_image.mpr β¨e,h.1 he,hiβ©) | |
| Β· exact mem_union_right _ (mem_image.mpr β¨e,h.1 he,hiβ©) | |
| calc | |
| G.n = (univ : Finset (Fin G.n)).card := by simp | |
| _ β€ (G.edges.image Prod.fst βͺ G.edges.image Prod.snd).card := card_le_card hs | |
| _ β€ (G.edges.image Prod.fst).card+(G.edges.image Prod.snd).card := card_union_le _ _ | |
| _ β€ G.edges.card+G.edges.card := Nat.add_le_add (card_image_le) (card_image_le) | |
| _ = _ := by omega | |
| lemma positive_count_vertices (G : GraphInput) (hZ : 0<Z G) : G.nβ€2*G.edges.card := by | |
| classical | |
| obtain β¨M,hMβ©:=card_pos.mp hZ | |
| exact ((mem_perfectMatchings G M).mp hM).vertices_le_twice_edges | |
| lemma sparse_reject_zero (G : GraphInput) (h : 2*G.edges.card<G.n) : Z G=0 := by | |
| by_contra hz | |
| have hh:=positive_count_vertices G (Nat.pos_of_ne_zero hz) | |
| omega | |
| lemma encodeNat_length_pos (n : β) : 0<(encodeNat n).length := by simp [encodeNat] | |
| lemma flatMap_length_ge {Ξ± Ξ² : Type*} (f : Ξ± β List Ξ²) (hf : β a,0<(f a).length) | |
| (L : List Ξ±) : L.lengthβ€(L.flatMap f).length := by | |
| induction L with | |
| | nil => simp | |
| | cons a L ih => | |
| have ha:=hf a | |
| simp only [List.length_cons,List.flatMap_cons,List.length_append] | |
| omega | |
| lemma edges_le_input_length (G : GraphInput) (e d : β) : G.edges.cardβ€(encodeInput G e d).length := by | |
| classical | |
| let L := (G.edges.map toLex.toEmbedding).sort (Β· β€ Β·) | |
| let f := fun a : Lex (Fin G.n Γ Fin G.n)=>encodeNat (ofLex a).1.val ++ encodeNat (ofLex a).2.val | |
| have hf : β a,0<(f a).length := by | |
| intro a | |
| have hh:=encodeNat_length_pos (ofLex a).1.val | |
| simpa only [f,List.length_append] using (lt_of_lt_of_le hh (Nat.le_add_right _ _)) | |
| have hh:=flatMap_length_ge f hf L | |
| have hL : L.length=G.edges.card := by simp [L] | |
| rw [hL] at hh | |
| unfold encodeInput | |
| change G.edges.cardβ€(encodeNat G.n ++ encodeNat G.edges.card ++ L.flatMap f ++ encodeRat e ++ encodeRat d).length | |
| simp only [List.length_append] | |
| omega | |
| lemma nonzero_vertices_le_input_twice (G : GraphInput) (e d : β) (h : 2*G.edges.cardβ₯G.n) : | |
| G.nβ€2*(encodeInput G e d).length := | |
| h.trans (Nat.mul_le_mul_left 2 (edges_le_input_length G e d)) | |
| end MatchingFPRAS | |
| namespace MatchingFPRAS.Counting | |
| lemma sigma_inv_polynomial (D K : β) (e : β) (he : 0<e) : | |
| (sigma D K e)β»ΒΉ β€ 10000000*D+1000*K*(βeβ»ΒΉββ:β) := by | |
| have hec : eβ»ΒΉβ€(βeβ»ΒΉββ:β) := Nat.le_ceil _ | |
| unfold sigma | |
| rw [min_def] | |
| split_ifs | |
| Β· have hh : (alpha/(100*(D:β)))β»ΒΉ=10000000*D := by norm_num [alpha,div_eq_mul_inv,mul_inv_rev]; ring | |
| rw [hh] | |
| exact le_add_of_nonneg_right (by positivity) | |
| Β· rw [inv_div] | |
| calc | |
| (1000*(K:β))/e = 1000*K*eβ»ΒΉ := by rw [div_eq_mul_inv] | |
| _ β€ 1000*K*(βeβ»ΒΉββ:β) := mul_le_mul_of_nonneg_left hec (by positivity) | |
| _ β€ _ := le_add_of_nonneg_left (by positivity) | |
| end MatchingFPRAS.Counting | |
| namespace MatchingFPRAS.Trial | |
| open Enlargement | |
| lemma Parameters.N_polynomial {G : GraphInput} (p : Parameters G) : | |
| p.Nβ€G.n+G.n^2*(4*(2*p.K+2)) := by | |
| have h := Fintype.card_subtype_le (fun a : Fin G.n Γ Fin G.n=>a.1<a.2) | |
| change Fintype.card (LogicalEdge (Fin G.n))β€Fintype.card (Fin G.n Γ Fin G.n) at h | |
| simp only [Fintype.card_prod,Fintype.card_fin] at h | |
| simp only [Parameters.N,SourceVertex,RealGeometry.Vertex,Fintype.card_sum,Fintype.card_prod,Fintype.card_fin] | |
| simpa only [pow_two] using Nat.add_le_add_left (Nat.mul_le_mul_right (4*(2*p.K+2)) h) G.n | |
| lemma Parameters.D_polynomial {G : GraphInput} (p : Parameters G) : | |
| p.D=100*p.N^2*(100000000*(G.n+1)^4) := by | |
| simp only [Parameters.D,sourceD,Parameters.N,Fintype.card_fin] | |
| lemma Parameters.S_polynomial {G : GraphInput} [Nontrivial (Fin G.n)] (p : Parameters G) : | |
| p.Sβ€10*(10000000*p.D+1000*p.K*βp.epsilonβ»ΒΉββ)^2*(G.n+p.K+1) := by | |
| rw [βFiniteTrial.sampleCount_eq p] | |
| unfold FiniteTrial.sampleCount | |
| apply Nat.ceil_le.mpr | |
| have hh:=Counting.sigma_inv_polynomial p.D p.K p.epsilon p.epsilon_pos | |
| have heq : FiniteTrial.sourceD (G:=G) p.K=p.D := FiniteTrial.sourceD_eq (G:=G) p.K | |
| rw [βheq] at hh | |
| have hh0 : 0β€(Counting.sigma (FiniteTrial.sourceD (G:=G) p.K) p.K p.epsilon)β»ΒΉ := | |
| inv_nonneg.mpr (Counting.sigma_nonneg _ _ _ p.epsilon_pos.le) | |
| push_cast | |
| gcongr | |
| simpa only [heq] using hh | |
| end MatchingFPRAS.Trial | |
| namespace MatchingFPRAS.BitArithmetic | |
| lemma size_add_le (a b : β) : (a+b).sizeβ€a.size+b.size+1 := by | |
| apply Nat.size_le.mpr | |
| have ha:=Nat.lt_size_self a | |
| have hb:=Nat.lt_size_self b | |
| have hβ : (2:β)^a.sizeβ€2^(a.size+b.size) := Nat.pow_le_pow_right (by decide) (by omega) | |
| have hβ : (2:β)^b.sizeβ€2^(a.size+b.size) := Nat.pow_le_pow_right (by decide) (by omega) | |
| rw [pow_succ] | |
| omega | |
| lemma complete_count_size (n : β) : (Z (completeGraph n)+1).sizeβ€(n/2)*n.size+3 := by | |
| have hb : Z (completeGraph n)β€n^(n/2) := by | |
| rw [GraphBridge.complete_count] | |
| exact UnitRefresh.pairingCount_le_half_power n | |
| have hh:=size_add_le (Z (completeGraph n)) 1 | |
| have hs:=Nat.size_le_size hb | |
| have hp:=size_pow_le n (n/2) | |
| have h1 : (1:β).size=1 := by decide | |
| omega | |
| end MatchingFPRAS.BitArithmetic | |
| namespace MatchingFPRAS.Amplification | |
| lemma median_mem {k : β} (out : Fin (2*k+1) β β) : β i,median out=out i := by | |
| unfold median sortedValue | |
| have hp:=List.mergeSort_perm (List.ofFn out) (Β· β€ Β·) | |
| have hx : (sortedList out)[k]'(by rw [sortedList_length]; omega)βList.ofFn out := | |
| hp.mem_iff.mp (List.getElem_mem _) | |
| obtain β¨i,hiβ©:=List.mem_ofFn.mp hx | |
| exact β¨i,hi.symmβ© | |
| end MatchingFPRAS.Amplification | |
| namespace MatchingFPRAS.FiniteTrial | |
| open BitArithmetic | |
| variable {G : GraphInput} [Nontrivial (Fin G.n)] | |
| noncomputable def outputLengthBound (p : Trial.Parameters G) : β := | |
| 2*((G.n/2)*G.n.size+3+p.K*(2*p.empiricalBound.size+1)+1)+3 | |
| lemma output_encode_length (p : Trial.Parameters G) (x : (layers p p.K le_rfl).Ξ©) : | |
| (encodeRat (output p x)).lengthβ€outputLengthBound p := by | |
| have hβ:=(output_bits p x).encode_length | |
| have hβ:=size_mul_le (Z (completeGraph G.n)+1) ((p.empiricalBound^2)^p.K) | |
| have hβ:=complete_count_size G.n | |
| have hβ:=size_pow_le (p.empiricalBound^2) p.K | |
| have hβ :=size_pow_le p.empiricalBound 2 | |
| have hb : ((Z (completeGraph G.n)+1)*(p.empiricalBound^2)^p.K).sizeβ€ | |
| (G.n/2)*G.n.size+3+p.K*(2*p.empiricalBound.size+1)+1 := by | |
| calc | |
| _ β€ (Z (completeGraph G.n)+1).size+((p.empiricalBound^2)^p.K).size := hβ | |
| _ β€ (G.n/2)*G.n.size+3+(p.K*(p.empiricalBound^2).size+1) := Nat.add_le_add hβ hβ | |
| _ β€ _ := by have hh:=Nat.mul_le_mul_left p.K hβ ; omega | |
| unfold outputLengthBound | |
| omega | |
| lemma amplifiedOutput_encode_length (p : Trial.Parameters G) (Ξ΄ : β) | |
| (x : Fin (2*Amplification.halfRepetitions Ξ΄+1) β (layers p p.K le_rfl).Ξ©) : | |
| (encodeRat (amplifiedOutput p Ξ΄ x)).lengthβ€outputLengthBound p := by | |
| obtain β¨i,hiβ©:=Amplification.median_mem (fun i=>output p (x i)) | |
| change (encodeRat (Amplification.median (fun i=>output p (x i)))).lengthβ€_ | |
| rw [hi] | |
| exact output_encode_length p (x i) | |
| end MatchingFPRAS.FiniteTrial | |
| namespace MatchingFPRAS.Transport | |
| open Finset | |
| lemma clog_two_le_self (m : β) : Nat.clog 2 m β€ m := | |
| Nat.clog_le_of_le_pow (Nat.lt_two_pow_self (n:=m)).le | |
| lemma bitPrecision_le (R : β) (Ξ· : β) : bitPrecision R Ξ· β€ R*βΞ·β»ΒΉββ := | |
| clog_two_le_self _ | |
| lemma sym2_card_le_square (V : Type*) [Fintype V] : Fintype.card (Sym2 V) β€ (Fintype.card V)^2 := by | |
| simpa only [Fintype.card_prod,pow_two] using Fintype.card_le_of_surjective _ (Sym2.mk_surjective (Ξ±:=V)) | |
| lemma bagEdge_card_le {V L : Type*} [Fintype V] [DecidableEq V] [Fintype L] [DecidableEq L] | |
| (bags : V β Finset L) [Fintype (BagEdge bags)] : | |
| Fintype.card (BagEdge bags) β€ (Fintype.card V)^2*Fintype.card L := by | |
| classical | |
| have hi : Function.Injective (fun e : BagEdge bags=>e.val.val) := | |
| Subtype.val_injective.comp Subtype.val_injective | |
| exact (Fintype.card_le_of_injective _ hi).trans (by | |
| rw [Fintype.card_prod] | |
| exact Nat.mul_le_mul_right _ (sym2_card_le_square V)) | |
| def tierPolynomial (N D K : β) := N^2*(D+2*K+2) | |
| def lambdaPolynomial (N D K T : β) := 10*N*ladderQ N D*(T+1)*(K+(N*D+2)+1) | |
| def stepsPolynomial (N D K m : β) := | |
| 20*ladderL N D*ladderM N D (tierPolynomial N D K)* | |
| (lambdaPolynomial N D K (tierPolynomial N D K)+m+1) | |
| def edgePolynomial (N K : β) := N^2*((2*K+1)*N) | |
| def scanErrorPolynomial (N D K : β) := | |
| 2*(1+ladderM N D (tierPolynomial N D K))+ | |
| 4*(8*(edgePolynomial N K)^2+4*edgePolynomial N K+3)+2*N^2*((2*K+1)*N) | |
| def totalBitsPolynomial (N D K m H : β) := | |
| let t:=stepsPolynomial N D K m | |
| let R:=scanErrorPolynomial N D K | |
| t*((t*R*H)+(t*R*H+N*(t*R*H)))+edgePolynomial N K*(6*edgePolynomial N K*H) | |
| lemma endpoint_le_polynomial (N D K : β) (hN : 0<N) : endpoint N D K hN β€ tierPolynomial N D K := by | |
| rw [endpoint_eq] | |
| apply (ladderTier_le N D K hN).trans | |
| unfold tierBound tierPolynomial | |
| gcongr | |
| exact clog_two_le_self D | |
| lemma lambda_le_polynomial (N D K T : β) : ladderLambda N D K T β€ lambdaPolynomial N D K T := by | |
| unfold ladderLambda lambdaPolynomial | |
| gcongr | |
| exact clog_two_le_self _ | |
| lemma discreteSteps_le_polynomial (N D K T m : β) (hT : T β€ tierPolynomial N D K) : | |
| discreteLadderSteps N D K T m β€ stepsPolynomial N D K m := by | |
| have hl : ladderLambda N D K T β€ lambdaPolynomial N D K (tierPolynomial N D K) := | |
| (lambda_le_polynomial N D K T).trans (by unfold lambdaPolynomial; gcongr) | |
| have hm : ladderM N D T β€ ladderM N D (tierPolynomial N D K) := by unfold ladderM; gcongr | |
| unfold discreteLadderSteps stepsPolynomial | |
| gcongr | |
| exact clog_two_le_self m | |
| end MatchingFPRAS.Transport | |
| namespace MatchingFPRAS.RationalSource | |
| open Transport Enlargement | |
| variable {V : Type*} [Fintype V] [LinearOrder V] [Nontrivial V] | |
| attribute [local instance] NumberedHierarchy.labelOrder sym2Order bagEdgeOrder bagEdgeFintype | |
| lemma edge_card_polynomial (w : V β V β β) (K : β) : | |
| Fintype.card (BagEdge (bags w K)) β€ edgePolynomial (Fintype.card (SourceVertex V K)) K := by | |
| apply (bagEdge_card_le (bags w K)).trans | |
| unfold edgePolynomial | |
| exact Nat.mul_le_mul_left _ (label_card w K) | |
| lemma scan_error_polynomial (w : V β V β β) (K D T : β) | |
| (hT : T β€ tierPolynomial (Fintype.card (SourceVertex V K)) D K) : | |
| scanErrorNumerator (SourceVertex V K) (Label w K) (bags w K) T | |
| (ladderQ (Fintype.card (SourceVertex V K)) D) β€ scanErrorPolynomial (Fintype.card (SourceVertex V K)) D K := by | |
| have he:=edge_card_polynomial w K | |
| have hl:=label_card w K | |
| unfold scanErrorNumerator scanErrorPolynomial ladderM | |
| gcongr | |
| open Transport Enlargement | |
| variable {V : Type*} [Fintype V] [LinearOrder V] [Nontrivial V] | |
| attribute [local instance] NumberedHierarchy.labelOrder sym2Order bagEdgeOrder bagEdgeFintype | |
| def samplerBitCount (w : V β V β β) (K D m : β) (hN : 0<Fintype.card (SourceVertex V K)) (Ξ· : β) : β := | |
| let N:=Fintype.card (SourceVertex V K) | |
| let T:=endpoint N D K hN | |
| let t:=discreteLadderSteps N D K T m | |
| t*scanBitCount N (bitPrecision (t*scanErrorNumerator (SourceVertex V K) (Label w K) (bags w K) T (ladderQ N D)) Ξ·)+ | |
| Fintype.card (BagEdge (bags w K))*bitPrecision (6*Fintype.card (BagEdge (bags w K))) Ξ· | |
| lemma samplerBitCount_le (w : V β V β β) (K D m : β) (hN : 0<Fintype.card (SourceVertex V K)) (Ξ· : β) : | |
| samplerBitCount w K D m hN Ξ· β€ totalBitsPolynomial (Fintype.card (SourceVertex V K)) D K m βΞ·β»ΒΉββ := by | |
| let N:=Fintype.card (SourceVertex V K) | |
| let T:=endpoint N D K hN | |
| let t:=discreteLadderSteps N D K T m | |
| let R:=scanErrorNumerator (SourceVertex V K) (Label w K) (bags w K) T (ladderQ N D) | |
| have hT : T β€ tierPolynomial N D K := endpoint_le_polynomial N D K hN | |
| have ht : t β€ stepsPolynomial N D K m := discreteSteps_le_polynomial N D K T m hT | |
| have hR : R β€ scanErrorPolynomial N D K := scan_error_polynomial w K D T hT | |
| have hE:=edge_card_polynomial w K | |
| have hk : bitPrecision (t*R) Ξ· β€ stepsPolynomial N D K m*scanErrorPolynomial N D K*βΞ·β»ΒΉββ := | |
| (bitPrecision_le _ _).trans (by gcongr) | |
| have hm : bitPrecision (6*Fintype.card (BagEdge (bags w K))) Ξ· β€ 6*edgePolynomial N K*βΞ·β»ΒΉββ := | |
| (bitPrecision_le _ _).trans (by gcongr) | |
| change t*scanBitCount N (bitPrecision (t*R) Ξ·)+Fintype.card (BagEdge (bags w K))*bitPrecision (6*Fintype.card (BagEdge (bags w K))) Ξ· β€ _ | |
| dsimp only [totalBitsPolynomial,scanBitCount] | |
| gcongr | |
| end MatchingFPRAS.RationalSource | |
| namespace MatchingFPRAS.Variation | |
| open Transport | |
| variable {A B C : Type*} [Fintype A] [Fintype B] [Fintype C] | |
| omit [Fintype C] in | |
| lemma imageLaw_ignore_right [Nonempty B] (f : A β C) : | |
| imageLaw (fun x : AΓB=>f x.1)=imageLaw f := by | |
| have hh:=imageLaw_comp_equiv (Equiv.prodComm A B) (fun x : BΓA=>f x.2) | |
| exact hh.trans (imageLaw_ignore f) | |
| def paddedBits {k B : β} (h : kβ€B) : | |
| (Fin B β Bool) β ((Fin k β Bool) Γ (Fin (B-k) β Bool)) := | |
| (Equiv.arrowCongr (finCongr (Nat.add_sub_of_le h).symm) (Equiv.refl Bool)).trans (pairBitsEquiv k (B-k)) | |
| def padSampler {k B : β} (h : kβ€B) (f : (Fin k β Bool) β A) : (Fin B β Bool) β A := | |
| fun bits=>f ((paddedBits h bits).1) | |
| omit [Fintype A] in | |
| lemma padSampler_law {k B : β} (h : kβ€B) (f : (Fin k β Bool) β A) : | |
| imageLaw (padSampler h f)=imageLaw f := | |
| (imageLaw_comp_equiv (paddedBits h) (fun x=>f x.1)).trans (imageLaw_ignore_right f) | |
| noncomputable def markedBitsEquiv (E : Type*) [Fintype E] (t k : β) : | |
| (Fin (t+Fintype.card E*k) β Bool) β ((Fin t β Bool) Γ (E β Fin k β Bool)) := | |
| (pairBitsEquiv t (Fintype.card E*k)).trans (Equiv.prodCongr (Equiv.refl _) | |
| ((matrixBitsEquiv (Fintype.card E) k).trans | |
| (Equiv.arrowCongr (Fintype.equivFin E).symm (Equiv.refl _)))) | |
| end MatchingFPRAS.Variation | |
| namespace MatchingFPRAS.RationalSource | |
| open Transport Enlargement Variation | |
| variable {V : Type*} [Fintype V] [LinearOrder V] [Nontrivial V] | |
| attribute [local instance] NumberedHierarchy.labelOrder sym2Order bagEdgeOrder bagEdgeFintype | |
| attribute [local instance] UnitRefresh.Computable.allowedDec prodOrder sumOrder | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| DecidableEq (SourceLabel (fun x y=>(w x y:β)) K) := Classical.decEq _ | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| Fintype (BagEdge (sourceBags (fun x y=>(w x y:β)) K)) := Fintype.ofFinite _ | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| DecidableEq (BagPM (bags w K)) := Classical.decEq _ | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| Fintype (BagPM (bags w K)) := Fintype.ofFinite _ | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| Fintype (Marked w K) := Fintype.ofFinite _ | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| Fintype (SourceMarked (fun x y=>(w x y:β)) K) := Fintype.ofFinite _ | |
| noncomputable local instance (w : V β V β β) (K t k : β) : | |
| Fintype ((Fin t β Bool) Γ (BagEdge (bags w K) β Fin k β Bool)) := Fintype.ofFinite _ | |
| noncomputable def bitSampler (w : V β V β β) (hw : β x y,0<w x y) (K D m : β) | |
| (hD : 0<D) (hN : 0<Fintype.card (SourceVertex V K)) | |
| (h : β x y,xβ y β BottleneckAlgorithm.edge w x yβ€(4:β)^K) | |
| (hq : 0<ladderQ (Fintype.card (SourceVertex V K)) D) (M : BagPM (bags w K)) (Ξ· : β) : | |
| (Fin (samplerBitCount w K D m hN Ξ·) β Bool) β SourceMarked (fun x y=>(w x y:β)) K := | |
| (sourceMarkedEquiv w K).symm β markedSampler w hw K D m hD hN h hq M Ξ· β | |
| markedBitsEquiv (BagEdge (bags w K)) _ _ | |
| lemma bitSampler_law (w : V β V β β) (hw : β x y,0<w x y) (K D m : β) | |
| (hD : 0<D) (hN : 0<Fintype.card (SourceVertex V K)) | |
| (h : β x y,xβ y β BottleneckAlgorithm.edge w x yβ€(4:β)^K) | |
| (hq : 0<ladderQ (Fintype.card (SourceVertex V K)) D) (M : BagPM (bags w K)) (Ξ· : β) : | |
| imageLaw (bitSampler w hw K D m hD hN h hq M Ξ·)=finiteSourceLaw w hw K D m hD hN h hq M Ξ· := by | |
| dsimp only [bitSampler,samplerBitCount] | |
| erw [βFunction.comp_assoc,imageLaw_comp_equiv,imageLaw_output_equiv] | |
| rfl | |
| noncomputable def fixedSampler (w : V β V β β) (hw : β x y,0<w x y) (K D m : β) | |
| (hD : 0<D) (hN : 0<Fintype.card (SourceVertex V K)) | |
| (h : β x y,xβ y β BottleneckAlgorithm.edge w x yβ€(4:β)^K) | |
| (hq : 0<ladderQ (Fintype.card (SourceVertex V K)) D) (M : BagPM (bags w K)) (Ξ· : β) : | |
| (Fin (totalBitsPolynomial (Fintype.card (SourceVertex V K)) D K m βΞ·β»ΒΉββ) β Bool) β | |
| SourceMarked (fun x y=>(w x y:β)) K := | |
| padSampler (samplerBitCount_le w K D m hN Ξ·) (bitSampler w hw K D m hD hN h hq M Ξ·) | |
| lemma fixedSampler_law (w : V β V β β) (hw : β x y,0<w x y) (K D m : β) | |
| (hD : 0<D) (hN : 0<Fintype.card (SourceVertex V K)) | |
| (h : β x y,xβ y β BottleneckAlgorithm.edge w x yβ€(4:β)^K) | |
| (hq : 0<ladderQ (Fintype.card (SourceVertex V K)) D) (M : BagPM (bags w K)) (Ξ· : β) : | |
| imageLaw (fixedSampler w hw K D m hD hN h hq M Ξ·)=finiteSourceLaw w hw K D m hD hN h hq M Ξ· := by | |
| rw [fixedSampler,padSampler_law,bitSampler_law] | |
| end MatchingFPRAS.RationalSource | |
| namespace MatchingFPRAS.Variation | |
| open Finset | |
| open scoped Classical | |
| variable {A B X Y : Type*} [Fintype A] [Fintype B] [Fintype X] | |
| variable {E : X β Type*} [β x,Fintype (E x)] | |
| omit [β x,Fintype (E x)] in | |
| lemma imageLaw_sigma_pair (f : A β X) (g : β x,B β E x) : | |
| imageLaw (fun z : AΓB=>(β¨f z.1,g (f z.1) z.2β© : Sigma E))= | |
| sigmaLift (imageLaw f) (fun x=>imageLaw (g x)) := by | |
| rw [imageLaw_adaptive_pair f (fun x b=>(β¨x,g x bβ© : Sigma E))] | |
| funext β¨x,yβ© | |
| unfold bind sigmaLift | |
| dsimp only | |
| have he : imageLaw (fun b=>(β¨x,g x bβ© : Sigma E)) β¨x,yβ©=imageLaw (g x) y := by | |
| unfold imageLaw push | |
| simp only [Sigma.mk.inj_iff,heq_eq_eq,true_and] | |
| rw [βhe] | |
| apply sum_eq_single x | |
| Β· intro a _ ha | |
| have hz : imageLaw (fun b=>(β¨a,g a bβ© : Sigma E)) β¨x,yβ©=0 := by | |
| unfold imageLaw push | |
| apply sum_eq_zero | |
| intro b _ | |
| exact ite_eq_right (fun hh=>ha (congrArg Sigma.fst hh)) | |
| rw [hz,mul_zero] | |
| Β· simp | |
| end MatchingFPRAS.Variation | |
| namespace MatchingFPRAS.FiniteTrial | |
| open Transport Enlargement Variation Adaptive | |
| variable {G : GraphInput} [Nontrivial (Fin G.n)] | |
| attribute [local instance] NumberedHierarchy.labelOrder sym2Order bagEdgeOrder bagEdgeFintype | |
| attribute [local instance] UnitRefresh.Computable.allowedDec prodOrder sumOrder | |
| noncomputable local instance (w : Fin G.n β Fin G.n β β) (K : β) : | |
| DecidableEq (SourceLabel (fun x y=>(w x y:β)) K) := Classical.decEq _ | |
| noncomputable local instance (w : Fin G.n β Fin G.n β β) (K : β) : | |
| Fintype (BagEdge (sourceBags (fun x y=>(w x y:β)) K)) := Fintype.ofFinite _ | |
| noncomputable local instance (w : Fin G.n β Fin G.n β β) (K : β) : | |
| Fintype (SourceMarked (fun x y=>(w x y:β)) K) := Fintype.ofFinite _ | |
| noncomputable def oneBits (p : Trial.Parameters G) : β := | |
| totalBitsPolynomial p.N p.D p.K (1000*p.K*p.S) β(1/(1000*p.K*p.S):β)β»ΒΉββ | |
| omit [Nontrivial (Fin G.n)] in | |
| lemma oneBits_eq (p : Trial.Parameters G) : oneBits p=totalBitsPolynomial p.N p.D p.K (1000*p.K*p.S) (1000*p.K*p.S) := by | |
| unfold oneBits | |
| congr 1 | |
| rw [one_div,inv_inv] | |
| simpa only [Nat.cast_mul,Nat.cast_ofNat] using (Nat.ceil_natCast (R:=β) (1000*p.K*p.S)) | |
| noncomputable def ScaleState.drawOne (p : Trial.Parameters G) {j : β} (hj : jβ€p.K) (s : ScaleState G j) : | |
| (Fin (oneBits p) β Bool) β SourceMarked (fun a b=>(s.activity a b:β)) p.K := | |
| RationalSource.fixedSampler s.activity s.activity_pos p.K | |
| (Enlargement.sourceD (V:=Fin G.n) p.K) (1000*p.K*p.S) | |
| (sourceD_one p.K) Fintype.card_pos (s.cap hj) p.q_pos | |
| (RationalSource.startMatching s.activity p.K p.even) (1/(1000*p.K*p.S)) | |
| lemma ScaleState.drawOne_law (p : Trial.Parameters G) {j : β} (hj : jβ€p.K) (s : ScaleState G j) : | |
| imageLaw (s.drawOne p hj)=(s.runLaw p hj).mass := by | |
| exact RationalSource.fixedSampler_law _ _ _ _ _ _ _ _ _ _ _ | |
| noncomputable def stageBits (p : Trial.Parameters G) : β := p.S*oneBits p | |
| noncomputable def ScaleState.drawStage (p : Trial.Parameters G) {j : β} (hj : jβ€p.K) (s : ScaleState G j) : | |
| (Fin (stageBits p) β Bool) β Fin p.S β SourceMarked (fun a b=>(s.activity a b:β)) p.K := | |
| (fun b i=>s.drawOne p hj (b i)) β matrixBitsEquiv p.S (oneBits p) | |
| lemma ScaleState.drawStage_law (p : Trial.Parameters G) {j : β} (hj : jβ€p.K) (s : ScaleState G j) : | |
| imageLaw (s.drawStage p hj)=(s.sampleLaw p hj).mass := by | |
| unfold ScaleState.drawStage | |
| erw [imageLaw_comp_equiv,imageLaw_componentwise] | |
| rw [ScaleState.drawOne_law] | |
| rfl | |
| open Transport Enlargement Variation Adaptive | |
| variable {G : GraphInput} [Nontrivial (Fin G.n)] | |
| attribute [local instance] NumberedHierarchy.labelOrder sym2Order bagEdgeOrder bagEdgeFintype | |
| attribute [local instance] UnitRefresh.Computable.allowedDec prodOrder sumOrder | |
| noncomputable local instance (w : Fin G.n β Fin G.n β β) (K : β) : | |
| DecidableEq (SourceLabel (fun x y=>(w x y:β)) K) := Classical.decEq _ | |
| noncomputable local instance (w : Fin G.n β Fin G.n β β) (K : β) : | |
| Fintype (BagEdge (sourceBags (fun x y=>(w x y:β)) K)) := Fintype.ofFinite _ | |
| noncomputable local instance (w : Fin G.n β Fin G.n β β) (K : β) : | |
| Fintype (SourceMarked (fun x y=>(w x y:β)) K) := Fintype.ofFinite _ | |
| noncomputable def Layer.drawAppend (p : Trial.Parameters G) {j : β} (hj : jβ€p.K) | |
| (L : Layer p j) {a : β} (f : (Fin a β Bool) β L.Ξ©) : | |
| (Fin (a+stageBits p) β Bool) β (L.append p hj).Ξ© := | |
| fun b => | |
| let c : (Fin a β Bool) Γ (Fin (stageBits p) β Bool) := pairBitsEquiv a (stageBits p) b | |
| (β¨f c.1,(L.state (f c.1)).drawStage p hj c.2β© : | |
| Ξ£ x : L.Ξ©, Fin p.S β SourceMarked (fun v w=>((L.state x).activity v w:β)) p.K) | |
| lemma Layer.drawAppend_law (p : Trial.Parameters G) {j : β} (hj : jβ€p.K) | |
| (L : Layer p j) {a : β} (f : (Fin a β Bool) β L.Ξ©) (hf : imageLaw f=L.law.mass) : | |
| imageLaw (L.drawAppend p hj f)=(L.append p hj).law.mass := by | |
| change imageLaw ((fun b : (Fin a β Bool) Γ (Fin (stageBits p) β Bool) => | |
| (β¨f b.1,(L.state (f b.1)).drawStage p hj b.2β© : | |
| Ξ£ x : L.Ξ©, Fin p.S β SourceMarked (fun v w=>((L.state x).activity v w:β)) p.K)) β | |
| pairBitsEquiv a (stageBits p)) = _ | |
| erw [imageLaw_comp_equiv] | |
| change imageLaw _ = sigmaLift L.law.mass (fun x=>(L.state x).sampleLaw p hj |>.mass) | |
| rw [imageLaw_sigma_pair f (fun x=>(L.state x).drawStage p hj)] | |
| simp_rw [ScaleState.drawStage_law] | |
| rw [hf] | |
| def successorBitsEquiv (j B : β) : (Fin ((j+1)*B) β Bool) β (Fin (j*B+B) β Bool) := | |
| Equiv.arrowCongr (finCongr (Nat.succ_mul j B)) (Equiv.refl Bool) | |
| noncomputable def drawLayer (p : Trial.Parameters G) : (j : β) β (hj : jβ€p.K) β | |
| (Fin (j*stageBits p) β Bool) β (layers p j hj).Ξ© | |
| | 0,_ => fun _=>PUnit.unit | |
| | j+1,hj => (layers p j (by omega)).drawAppend p (by omega) (drawLayer p j (by omega)) β successorBitsEquiv j (stageBits p) | |
| lemma drawLayer_law (p : Trial.Parameters G) (j : β) (hj : jβ€p.K) : | |
| imageLaw (drawLayer p j hj)=(layers p j hj).law.mass := by | |
| induction j with | |
| | zero => | |
| change imageLaw (fun _ : Fin (0*stageBits p) β Bool=>PUnit.unit)=(firstLayer p).law.mass | |
| rw [imageLaw_subsingleton] | |
| funext x | |
| simp [uniform,firstLayer] | |
| | succ j ih => | |
| unfold drawLayer | |
| erw [imageLaw_comp_equiv] | |
| exact Layer.drawAppend_law p (by omega) (layers p j (by omega)) _ (ih (by omega)) | |
| noncomputable def bitOutput (p : Trial.Parameters G) : (Fin (p.K*stageBits p) β Bool) β β := | |
| output p β drawLayer p p.K le_rfl | |
| lemma bitOutput_nonneg (p : Trial.Parameters G) (b : Fin (p.K*stageBits p) β Bool) : | |
| 0β€bitOutput p b := output_nonneg p _ | |
| end MatchingFPRAS.FiniteTrial | |
| namespace MatchingFPRAS.Variation | |
| open Finset | |
| open scoped Classical | |
| variable {A B : Type*} [Fintype A] [Fintype B] | |
| lemma event_push (p : A β β) (f : A β B) (P : B β Prop) : | |
| event (push p f) P=event p (fun x=>P (f x)) := by | |
| unfold event push | |
| have h : (β y,if P y then β x,if f x=y then p x else 0 else 0)= | |
| β y,β x,if f x=y then (if P y then p x else 0) else 0 := by | |
| apply sum_congr rfl | |
| intro y _ | |
| by_cases hy:P y <;> simp [hy] | |
| rw [h,sum_comm] | |
| simp | |
| lemma event_imageLaw (f : A β B) (P : B β Prop) : | |
| event (imageLaw f) P=((univ.filter (fun x=>P (f x))).card:β)/Fintype.card A := by | |
| rw [imageLaw,event_push] | |
| unfold event uniform | |
| rw [show (β x,if P (f x) then (1:β)/Fintype.card A else 0)= | |
| (β x,if P (f x) then (1:β) else 0)/Fintype.card A by | |
| simp only [sum_div,ite_div,zero_div]] | |
| simp | |
| lemma event_complement (p : A β β) (P : A β Prop) : | |
| event p P+event p (fun x=>Β¬P x)=β x,p x := by | |
| unfold event | |
| rw [βsum_add_distrib] | |
| apply sum_congr rfl | |
| intro x _ | |
| by_cases hx:P x <;> simp [hx] | |
| end MatchingFPRAS.Variation | |
| namespace MatchingFPRAS.FiniteTrial | |
| open Variation Adaptive Amplification Finset Transport | |
| open scoped Classical | |
| variable {G : GraphInput} [Nontrivial (Fin G.n)] | |
| noncomputable def amplifiedBits (p : Trial.Parameters G) (Ξ΄ : β) : β := | |
| (2*halfRepetitions Ξ΄+1)*(p.K*stageBits p) | |
| noncomputable def drawTrials (p : Trial.Parameters G) (Ξ΄ : β) : | |
| (Fin (amplifiedBits p Ξ΄) β Bool) β Fin (2*halfRepetitions Ξ΄+1) β (layers p p.K le_rfl).Ξ© := | |
| (fun bits i=>drawLayer p p.K le_rfl (bits i)) β matrixBitsEquiv (2*halfRepetitions Ξ΄+1) (p.K*stageBits p) | |
| lemma drawTrials_law (p : Trial.Parameters G) (Ξ΄ : β) : | |
| imageLaw (drawTrials p Ξ΄)=((layers p p.K le_rfl).law.iid (2*halfRepetitions Ξ΄+1)).mass := by | |
| unfold drawTrials | |
| erw [imageLaw_comp_equiv,imageLaw_componentwise] | |
| rw [drawLayer_law] | |
| rfl | |
| noncomputable def amplifiedBitOutput (p : Trial.Parameters G) (Ξ΄ : β) : | |
| (Fin (amplifiedBits p Ξ΄) β Bool) β β := amplifiedOutput p Ξ΄ β drawTrials p Ξ΄ | |
| lemma amplifiedBitOutput_nonneg (p : Trial.Parameters G) (Ξ΄ : β) | |
| (b : Fin (amplifiedBits p Ξ΄) β Bool) : 0β€amplifiedBitOutput p Ξ΄ b := | |
| amplifiedOutput_nonneg p Ξ΄ _ | |
| noncomputable def accurateBits (p : Trial.Parameters G) (Ξ΄ : β) : Finset (Fin (amplifiedBits p Ξ΄) β Bool) := | |
| univ.filter fun b=>Accurate p (amplifiedBitOutput p Ξ΄ b) | |
| theorem amplifiedBitOutput_success (p : Trial.Parameters G) (hZ : 0<Z G) (Ξ΄ : β) (hΞ΄ : 0<Ξ΄) : | |
| ((accurateBits p Ξ΄).card:β)/(2:β)^(amplifiedBits p Ξ΄)β₯1-Ξ΄ := by | |
| have hf:=actual_finite_amplified_failure p hZ Ξ΄ hΞ΄ | |
| have hc:=event_complement ((layers p p.K le_rfl).law.iid (2*halfRepetitions Ξ΄+1)).mass | |
| (fun x=>Accurate p (amplifiedOutput p Ξ΄ x)) | |
| rw [Law.total] at hc | |
| have hh : 1-(Ξ΄:β) β€ event ((layers p p.K le_rfl).law.iid (2*halfRepetitions Ξ΄+1)).mass | |
| (fun x=>Accurate p (amplifiedOutput p Ξ΄ x)) := by | |
| change event _ (fun x=>Β¬Accurate p (amplifiedOutput p Ξ΄ x))β€(Ξ΄:β) at hf | |
| linarith only [hc,hf] | |
| rw [βdrawTrials_law,event_imageLaw] at hh | |
| have he : Fintype.card (Fin (amplifiedBits p Ξ΄) β Bool)=2^(amplifiedBits p Ξ΄) := by simp | |
| rw [he] at hh | |
| change 1-(Ξ΄:β) β€ ((accurateBits p Ξ΄).card:β)/(2^(amplifiedBits p Ξ΄):β) at hh | |
| have hr : ((1-Ξ΄:β):β) β€ (((((accurateBits p Ξ΄).card:β)/(2:β)^(amplifiedBits p Ξ΄)):β):β) := by | |
| push_cast | |
| simpa only [Nat.cast_pow,Nat.cast_ofNat] using hh | |
| exact Rat.cast_le.mp hr | |
| end MatchingFPRAS.FiniteTrial | |
| namespace MatchingFPRAS.BitComplexity | |
| def PolynomiallyBounded (f : β β β) : Prop := β C d : β, β x,1β€x β f xβ€C*x^d | |
| lemma PolynomiallyBounded.const (c : β) : PolynomiallyBounded (fun _=>c) := by | |
| exact β¨c,0,fun _ _=>by simpβ© | |
| lemma PolynomiallyBounded.id : PolynomiallyBounded (fun x=>x) := by | |
| exact β¨1,1,fun _ _=>by simpβ© | |
| lemma PolynomiallyBounded.add {f g : β β β} (hf : PolynomiallyBounded f) (hg : PolynomiallyBounded g) : | |
| PolynomiallyBounded (fun x=>f x+g x) := by | |
| obtain β¨C,d,hfβ©:=hf | |
| obtain β¨E,k,hgβ©:=hg | |
| refine β¨C+E,d+k,fun x hx=>?_β© | |
| have hβ : x^dβ€x^(d+k) := Nat.pow_le_pow_right hx (by omega) | |
| have hβ : x^kβ€x^(d+k) := Nat.pow_le_pow_right hx (by omega) | |
| calc | |
| _ β€ C*x^d+E*x^k := Nat.add_le_add (hf x hx) (hg x hx) | |
| _ β€ C*x^(d+k)+E*x^(d+k) := Nat.add_le_add (Nat.mul_le_mul_left C hβ) (Nat.mul_le_mul_left E hβ) | |
| _ = _ := (Nat.add_mul _ _ _).symm | |
| lemma PolynomiallyBounded.mul {f g : β β β} (hf : PolynomiallyBounded f) (hg : PolynomiallyBounded g) : | |
| PolynomiallyBounded (fun x=>f x*g x) := by | |
| obtain β¨C,d,hfβ©:=hf | |
| obtain β¨E,k,hgβ©:=hg | |
| refine β¨C*E,d+k,fun x hx=>?_β© | |
| calc | |
| _ β€ (C*x^d)*(E*x^k) := Nat.mul_le_mul (hf x hx) (hg x hx) | |
| _ = _ := by rw [pow_add]; ac_rfl | |
| lemma PolynomiallyBounded.pow {f : β β β} (hf : PolynomiallyBounded f) (k : β) : | |
| PolynomiallyBounded (fun x=>(f x)^k) := by | |
| obtain β¨C,d,hfβ©:=hf | |
| refine β¨C^k,d*k,fun x hx=>?_β© | |
| calc | |
| _ β€ (C*x^d)^k := Nat.pow_le_pow_left (hf x hx) k | |
| _ = _ := by rw [mul_pow,pow_mul] | |
| def boundK (x : β) : β := (2*x)*((2*x)*(2*x)+32*x) | |
| def boundN (x : β) : β := 2*x+(2*x)^2*(4*(2*boundK x+2)) | |
| def boundD (x : β) : β := 100*(boundN x)^2*(100000000*(2*x+1)^4) | |
| def boundS (x : β) : β := 10*(10000000*boundD x+1000*boundK x*x)^2*(2*x+boundK x+1) | |
| def boundBits (x : β) : β := (10*(x+1)+1)*(boundK x*(boundS x* | |
| Transport.totalBitsPolynomial (boundN x) (boundD x) (boundK x) (1000*boundK x*boundS x) (1000*boundK x*boundS x))) | |
| private lemma c (n : β) : PolynomiallyBounded (fun _=>n) := PolynomiallyBounded.const n | |
| private lemma X : PolynomiallyBounded (fun n=>n) := PolynomiallyBounded.id | |
| lemma boundK_polynomial : PolynomiallyBounded boundK := by | |
| exact ((c 2).mul X).mul ((((c 2).mul X).mul ((c 2).mul X)).add ((c 32).mul X)) | |
| lemma boundN_polynomial : PolynomiallyBounded boundN := by | |
| exact ((c 2).mul X).add (((((c 2).mul X).pow 2)).mul ((c 4).mul (((c 2).mul boundK_polynomial).add (c 2)))) | |
| lemma boundD_polynomial : PolynomiallyBounded boundD := by | |
| exact ((c 100).mul (boundN_polynomial.pow 2)).mul ((c 100000000).mul ((((c 2).mul X).add (c 1)).pow 4)) | |
| lemma boundS_polynomial : PolynomiallyBounded boundS := by | |
| exact ((c 10).mul ((((c 10000000).mul boundD_polynomial).add (((c 1000).mul boundK_polynomial).mul X)).pow 2)).mul ((((c 2).mul X).add boundK_polynomial).add (c 1)) | |
| open Transport | |
| lemma ladderL_polynomial {f g : β β β} (hf : PolynomiallyBounded f) (hg : PolynomiallyBounded g) : | |
| PolynomiallyBounded (fun x=>ladderL (f x) (g x)) := by | |
| exact (((c (10^4)).mul hf).mul hg).pow 100 | |
| lemma ladderQ_polynomial {f g : β β β} (hf : PolynomiallyBounded f) (hg : PolynomiallyBounded g) : | |
| PolynomiallyBounded (fun x=>ladderQ (f x) (g x)) := by | |
| exact (c 32).mul (ladderL_polynomial hf hg) | |
| lemma ladderM_polynomial {f g h : β β β} (hf : PolynomiallyBounded f) (hg : PolynomiallyBounded g) | |
| (hh : PolynomiallyBounded h) : PolynomiallyBounded (fun x=>ladderM (f x) (g x) (h x)) := by | |
| exact (hh.mul ((ladderQ_polynomial hf hg).pow 2)).add (ladderQ_polynomial hf hg) | |
| lemma tier_polynomial {f g h : β β β} (hf : PolynomiallyBounded f) (hg : PolynomiallyBounded g) | |
| (hh : PolynomiallyBounded h) : PolynomiallyBounded (fun x=>tierPolynomial (f x) (g x) (h x)) := by | |
| exact (hf.pow 2).mul ((hg.add ((c 2).mul hh)).add (c 2)) | |
| lemma edge_polynomial {f h : β β β} (hf : PolynomiallyBounded f) (hh : PolynomiallyBounded h) : | |
| PolynomiallyBounded (fun x=>edgePolynomial (f x) (h x)) := by | |
| exact (hf.pow 2).mul ((((c 2).mul hh).add (c 1)).mul hf) | |
| lemma lambda_polynomial {f g h t : β β β} (hf : PolynomiallyBounded f) (hg : PolynomiallyBounded g) | |
| (hh : PolynomiallyBounded h) (ht : PolynomiallyBounded t) : | |
| PolynomiallyBounded (fun x=>lambdaPolynomial (f x) (g x) (h x) (t x)) := by | |
| exact ((((c 10).mul hf).mul (ladderQ_polynomial hf hg)).mul (ht.add (c 1))).mul | |
| ((hh.add ((hf.mul hg).add (c 2))).add (c 1)) | |
| lemma steps_polynomial {f g h m : β β β} (hf : PolynomiallyBounded f) (hg : PolynomiallyBounded g) | |
| (hh : PolynomiallyBounded h) (hm : PolynomiallyBounded m) : | |
| PolynomiallyBounded (fun x=>stepsPolynomial (f x) (g x) (h x) (m x)) := by | |
| have ht:=tier_polynomial hf hg hh | |
| exact (((c 20).mul (ladderL_polynomial hf hg)).mul (ladderM_polynomial hf hg ht)).mul | |
| (((lambda_polynomial hf hg hh ht).add hm).add (c 1)) | |
| lemma scan_polynomial {f g h : β β β} (hf : PolynomiallyBounded f) (hg : PolynomiallyBounded g) | |
| (hh : PolynomiallyBounded h) : PolynomiallyBounded (fun x=>scanErrorPolynomial (f x) (g x) (h x)) := by | |
| have ht:=tier_polynomial hf hg hh | |
| have he:=edge_polynomial hf hh | |
| exact (((c 2).mul ((c 1).add (ladderM_polynomial hf hg ht))).add | |
| ((c 4).mul (((((c 8).mul (he.pow 2)).add ((c 4).mul he))).add (c 3)))).add | |
| (((c 2).mul (hf.pow 2)).mul ((((c 2).mul hh).add (c 1)).mul hf)) | |
| lemma total_polynomial {f g h m H : β β β} (hf : PolynomiallyBounded f) (hg : PolynomiallyBounded g) | |
| (hh : PolynomiallyBounded h) (hm : PolynomiallyBounded m) (hH : PolynomiallyBounded H) : | |
| PolynomiallyBounded (fun x=>totalBitsPolynomial (f x) (g x) (h x) (m x) (H x)) := by | |
| have ht:=steps_polynomial hf hg hh hm | |
| have hR:=scan_polynomial hf hg hh | |
| have he:=edge_polynomial hf hh | |
| have ha:=(ht.mul hR).mul hH | |
| exact (ht.mul (ha.add (ha.add (hf.mul ha)))).add (he.mul (((c 6).mul he).mul hH)) | |
| lemma boundBits_polynomial : PolynomiallyBounded boundBits := by | |
| have hm:=((c 1000).mul boundK_polynomial).mul boundS_polynomial | |
| exact (((c 10).mul (X.add (c 1))).add (c 1)).mul (boundK_polynomial.mul | |
| (boundS_polynomial.mul (total_polynomial boundN_polynomial boundD_polynomial boundK_polynomial hm hm))) | |
| end MatchingFPRAS.BitComplexity | |
| namespace MatchingFPRAS.Transport | |
| lemma totalBitsPolynomial_mono {N N' D D' K K' m m' H H' : β} | |
| (hN : N β€ N') (hD : D β€ D') (hK : K β€ K') (hm : m β€ m') (hH : H β€ H') : | |
| totalBitsPolynomial N D K m H β€ totalBitsPolynomial N' D' K' m' H' := by | |
| unfold totalBitsPolynomial stepsPolynomial scanErrorPolynomial lambdaPolynomial tierPolynomial | |
| edgePolynomial ladderM ladderQ ladderL | |
| dsimp only | |
| gcongr | |
| end MatchingFPRAS.Transport | |
| namespace MatchingFPRAS.BitComplexity | |
| open FiniteTrial Trial Transport Amplification | |
| lemma parameters_K_le {G : GraphInput} (hn : 2 β€ G.n) (heven : Even G.n) | |
| (e : β) (he : 0<e) (he1 : e<1) (x : β) (hnx : G.n β€ 2*x) (hex : βeβ»ΒΉββ β€ x) : | |
| (parameters G hn heven e he he1).K β€ boundK x := by | |
| apply (Counting.leastSchedule_polynomial G.n hn e he he1).trans | |
| unfold Counting.schedulePolynomial boundK | |
| gcongr | |
| lemma parameters_N_le {G : GraphInput} (p : Parameters G) | |
| (x : β) (hnx : G.n β€ 2*x) (hk : p.K β€ boundK x) : p.N β€ boundN x := by | |
| apply p.N_polynomial.trans | |
| unfold boundN | |
| gcongr | |
| lemma parameters_D_le {G : GraphInput} (p : Parameters G) | |
| (x : β) (hnx : G.n β€ 2*x) (hN : p.N β€ boundN x) : p.D β€ boundD x := by | |
| rw [p.D_polynomial] | |
| unfold boundD | |
| gcongr | |
| lemma parameters_S_le {G : GraphInput} [Nontrivial (Fin G.n)] (p : Parameters G) | |
| (x : β) (hnx : G.n β€ 2*x) (hk : p.K β€ boundK x) (hD : p.D β€ boundD x) (he : βp.epsilonβ»ΒΉββ β€ x) : | |
| p.S β€ boundS x := by | |
| apply p.S_polynomial.trans | |
| unfold boundS | |
| gcongr | |
| lemma amplifiedBits_le_bound {G : GraphInput} [Nontrivial (Fin G.n)] (p : Parameters G) (Ξ΄ : β) | |
| (x : β) (hnx : G.n β€ 2*x) (hk : p.K β€ boundK x) (he : βp.epsilonβ»ΒΉββ β€ x) | |
| (hd : Nat.clog 2 βΞ΄β»ΒΉββ β€ x) : amplifiedBits p Ξ΄ β€ boundBits x := by | |
| have hN:=parameters_N_le p x hnx hk | |
| have hD:=parameters_D_le p x hnx hN | |
| have hS:=parameters_S_le p x hnx hk hD he | |
| have hm : 1000*p.K*p.S β€ 1000*boundK x*boundS x := by gcongr | |
| unfold amplifiedBits stageBits | |
| rw [oneBits_eq,repetitions_source] | |
| unfold boundBits | |
| exact Nat.mul_le_mul (by gcongr) (Nat.mul_le_mul hk (Nat.mul_le_mul hS (totalBitsPolynomial_mono hN hD hk hm hm))) | |
| def inputSize (G : GraphInput) (e d : β) : β := | |
| (encodeInput G e d).length+βeβ»ΒΉββ+Nat.clog 2 βdβ»ΒΉββ+1 | |
| lemma inputSize_pos (G : GraphInput) (e d : β) : 1 β€ inputSize G e d := by unfold inputSize; omega | |
| lemma scheduledBits_le {G : GraphInput} [Nontrivial (Fin G.n)] (hn : 2 β€ G.n) (hev : Even G.n) | |
| (e d : β) (he : 0<e) (he1 : e<1) (hsparse : G.n β€ 2*G.edges.card) : | |
| amplifiedBits (parameters G hn hev e he he1) d β€ boundBits (inputSize G e d) := by | |
| have hnx : G.n β€ 2*inputSize G e d := by | |
| have hh:=nonzero_vertices_le_input_twice G e d hsparse | |
| unfold inputSize | |
| omega | |
| have hex : βeβ»ΒΉββ β€ inputSize G e d := by unfold inputSize; omega | |
| exact amplifiedBits_le_bound _ d _ hnx (parameters_K_le hn hev e he he1 _ hnx hex) hex (by unfold inputSize; omega) | |
| theorem polynomial_fair_bits : β C d : β, β (G : GraphInput) [Nontrivial (Fin G.n)] | |
| (hn : 2 β€ G.n) (hev : Even G.n) (e Ξ΄ : β) (he : 0<e) (he1 : e<1), G.n β€ 2*G.edges.card β | |
| amplifiedBits (parameters G hn hev e he he1) Ξ΄ β€ timeBound C d G e Ξ΄ := by | |
| obtain β¨C,d,hβ©:=boundBits_polynomial | |
| refine β¨C,d,fun G _ hn hev e Ξ΄ he he1 hs=>?_β© | |
| exact (scheduledBits_le hn hev e Ξ΄ he he1 hs).trans (h _ (inputSize_pos G e Ξ΄)) | |
| end MatchingFPRAS.BitComplexity | |
| namespace MatchingFPRAS.UnitRefresh | |
| lemma pairingCount_pos_even (n : β) : 0<pairingCount n β Even n := by | |
| induction n using Nat.twoStepInduction with | |
| | zero => intro _; decide | |
| | one => simp | |
| | more n ih _ => | |
| intro hh | |
| rw [pairingCount_add_two] at hh | |
| have hp:0<pairingCount n := Nat.pos_of_mul_pos_left hh | |
| exact (ih hp).add (by decide : Even 2) | |
| end MatchingFPRAS.UnitRefresh | |
| namespace MatchingFPRAS | |
| open Finset | |
| lemma count_le_complete (G : GraphInput) : Z Gβ€Z (completeGraph G.n) := by | |
| classical | |
| apply card_le_card | |
| intro M hM | |
| apply (mem_perfectMatchings _ _).mpr | |
| have h:=(mem_perfectMatchings _ _).mp hM | |
| refine β¨?_,h.2β© | |
| intro e he | |
| exact mem_filter.mpr β¨mem_univ _,G.increasing e (h.1 he)β© | |
| lemma positive_count_even (G : GraphInput) (hZ : 0<Z G) : Even G.n := by | |
| have hh:=lt_of_lt_of_le hZ (count_le_complete G) | |
| rw [GraphBridge.complete_count] at hh | |
| exact UnitRefresh.pairingCount_pos_even _ hh | |
| lemma positive_nonempty_two (G : GraphInput) (hZ : 0<Z G) (hn : G.nβ 0) : 2β€G.n := by | |
| obtain β¨k,hkβ©:=positive_count_even G hZ | |
| omega | |
| lemma empty_count_one (G : GraphInput) (hn : G.n=0) : Z G=1 := by | |
| classical | |
| have hE : G.edges=β := by | |
| apply eq_empty_iff_forall_notMem.mpr | |
| intro e he | |
| have hh:=e.1.isLt | |
| omega | |
| have hm : perfectMatchings G={β } := by | |
| ext M | |
| simp only [mem_perfectMatchings,mem_singleton] | |
| constructor | |
| Β· intro h | |
| simpa only [hE,subset_empty] using h.1 | |
| Β· intro h | |
| subst M | |
| refine β¨empty_subset _,?_β© | |
| intro v | |
| have hh:=v.isLt | |
| omega | |
| unfold Z | |
| rw [hm,card_singleton] | |
| end MatchingFPRAS | |
| namespace MatchingFPRAS.Variation | |
| open Finset | |
| open scoped Classical | |
| lemma padSampler_success {A : Type*} {k B : β} (h : kβ€B) (f : (Fin k β Bool) β A) (P : A β Prop) : | |
| ((univ.filter (fun b=>P (padSampler h f b))).card:β)/(2:β)^B = | |
| ((univ.filter (fun b=>P (f b))).card:β)/(2:β)^k := by | |
| have hh:=congrArg (fun p=>event p (fun b=>P (f b))) (padSampler_law h (id : (Fin k β Bool) β (Fin k β Bool))) | |
| rw [event_imageLaw,event_imageLaw] at hh | |
| simp only [id_eq,Fintype.card_fun,Fintype.card_bool,Fintype.card_fin,Nat.cast_pow,Nat.cast_ofNat] at hh | |
| apply Rat.cast_injective (Ξ±:=β) | |
| push_cast | |
| exact hh | |
| end MatchingFPRAS.Variation | |
| namespace MatchingFPRAS.FiniteTrial | |
| open BitComplexity Variation Finset | |
| open scoped Classical | |
| lemma padded_amplified_success {G : GraphInput} [Nontrivial (Fin G.n)] | |
| (p : Trial.Parameters G) (Ξ΄ : β) (B : β) (ht : amplifiedBits p Ξ΄β€B) | |
| (hz : 0<Z G) (hd : 0<Ξ΄) : | |
| ((univ.filter (fun b=>Accurate p (padSampler ht (amplifiedBitOutput p Ξ΄) b))).card:β)/ | |
| (2:β)^Bβ₯1-Ξ΄ := by | |
| rw [padSampler_success] | |
| exact amplifiedBitOutput_success p hz Ξ΄ hd | |
| theorem scheduled_fair_tapes : β C d : β, 0<C β§ | |
| β (G : GraphInput) [Nontrivial (Fin G.n)] (_hn : 2β€G.n) (_hev : Even G.n) | |
| (e Ξ΄ : β) (_he : 0<e) (_he1 : e<1), G.nβ€2*G.edges.card β | |
| β f : (Fin (timeBound C d G e Ξ΄) β Bool) β β, | |
| (β b,0β€f b) β§ (0<Z G β 0<Ξ΄ β | |
| ((univ.filter (fun b=>(1-e)*(Z G:β)β€f b β§ f bβ€(1+e)*(Z G:β))).card:β) / | |
| (2:β)^(timeBound C d G e Ξ΄)β₯1-Ξ΄) := by | |
| obtain β¨C,d,hβ©:=polynomial_fair_bits | |
| refine β¨C+1,d,by omega,fun G _ hn hev e Ξ΄ he he1 hs=>?_β© | |
| let p:=parameters G hn hev e he he1 | |
| have ht : amplifiedBits p Ξ΄ β€ timeBound (C+1) d G e Ξ΄ := by | |
| exact (h G hn hev e Ξ΄ he he1 hs).trans (Nat.mul_le_mul_right _ (by omega)) | |
| let f:=padSampler ht (amplifiedBitOutput p Ξ΄) | |
| refine β¨f,fun b=>amplifiedBitOutput_nonneg p Ξ΄ _,fun hz hd=>?_β© | |
| convert padded_amplified_success p Ξ΄ _ ht hz hd using 3 | |
| congr 1 | |
| ext b | |
| simp only [mem_filter,mem_univ,true_and] | |
| rfl | |
| end MatchingFPRAS.FiniteTrial | |
| end OAI | |