math / data /lean /OAI /Combinatorics /MatchingCount /Algorithm /OutputLengthBound.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
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