Download data/lean/OAI/Combinatorics/MatchingCount/Algorithm/RationalScale.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 5.01 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/MatchingCount/Algorithm/RationalScale.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/MatchingCount/Algorithm/RationalScale.lean
-
curl -L -o RationalScale.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/MatchingCount/Algorithm/RationalScale.lean
5.01 kB
| import Mathlib | |
| import OAI.Combinatorics.MatchingCount.Sampling.Endpoints | |
| import OAI.Combinatorics.MatchingCount.Tapes.RunBits | |
| namespace OAI | |
| namespace MatchingFPRAS.Counting | |
| open Finset | |
| variable {n : β} | |
| lemma rowMaximum_cast (hn : 2β€n) (G : Fin n β Fin n β β) (v : Fin n β β) (i : Fin n) : | |
| (rowMaximum hn G v i:β)=RealStage.rowMaximum hn (fun i j=>(G i j:β)) (fun i=>(v i:β)) i := by | |
| unfold rowMaximum RealStage.rowMaximum | |
| rw [Finset.apply_sup'_eq_sup'_comp _ (fun q : β=>(q:β)) (by intro a b; exact Rat.cast_max a b)] | |
| simp only [Function.comp_apply,Rat.cast_div] | |
| lemma scaleUpdate_cast (hn : 2β€n) (G : Fin n β Fin n β β) (v : Fin n β β) (i j : Fin n) : | |
| (scaleUpdate hn G v i j:β)=RealStage.scaleUpdate hn (fun i j=>(G i j:β)) (fun i=>(v i:β)) i j := by | |
| by_cases h : j=i | |
| Β· subst j | |
| simp only [scaleUpdate,RealStage.scaleUpdate,Function.update_self,rowMaximum_cast] | |
| Β· simp only [scaleUpdate,RealStage.scaleUpdate,Function.update_of_ne h] | |
| lemma scalingTrace_cast (hn : 2β€n) (G : Fin n β Fin n β β) (k : β) (i : Fin n) : | |
| (scalingTrace hn G k i:β)=RealStage.scalingTrace hn (fun i j=>(G i j:β)) k i := by | |
| induction k generalizing i with | |
| | zero => norm_num [scalingTrace,RealStage.scalingTrace] | |
| | succ k ih => | |
| simp only [scalingTrace,RealStage.scalingTrace] | |
| split_ifs with h | |
| Β· rw [scaleUpdate_cast] | |
| have hi : (fun j=>(Counting.scalingTrace hn G k j:β))=RealStage.scalingTrace hn (fun i j=>(G i j:β)) k := by | |
| funext j | |
| exact ih j | |
| rw [hi] | |
| Β· exact ih i | |
| lemma ratioEstimate_cast (a d : β) : | |
| (ratioEstimate a d:β)=RealStage.ratioEstimate a d := by | |
| simp only [ratioEstimate,RealStage.ratioEstimate] | |
| have hp : (0:β)<a β (0:β)<a := by exact_mod_cast Iff.rfl | |
| simp only [hp] | |
| split_ifs <;> push_cast <;> rfl | |
| lemma upperEstimate_cast (D : β) (d z : β) : | |
| (upperEstimate D d z:β)=RealStage.upperEstimate D d z := by | |
| simp only [upperEstimate,RealStage.upperEstimate] | |
| have hp : (0:β)<d β (0:β)<d := by exact_mod_cast Iff.rfl | |
| simp only [hp] | |
| split_ifs <;> push_cast <;> norm_num [alpha,RealStage.alpha] | |
| lemma sigma_cast (D K : β) (e : β) : (sigma D K e:β)=RealStage.sigma D K e := by | |
| simp only [sigma,RealStage.sigma,alpha,RealStage.alpha] | |
| push_cast | |
| rfl | |
| end MatchingFPRAS.Counting | |
| namespace MatchingFPRAS.FiniteTrial | |
| open Finset | |
| def cooling (n : β) : β := (1+1/(n:β))β»ΒΉ | |
| lemma cooling_cast (n : β) : (cooling n:β)=Trial.cooling n := by | |
| simp [cooling,Trial.cooling] | |
| def raw (G : GraphInput) (j : β) (a b : Fin G.n) : β := | |
| if (min a b,max a b)βG.edges then 1 else cooling G.n^j | |
| lemma raw_cast (G : GraphInput) (j : β) (a b : Fin G.n) : | |
| (raw G j a b:β)=Trial.raw G j a b := by | |
| unfold raw Trial.raw GraphBridge.rawActivity | |
| split_ifs <;> simp [cooling_cast] | |
| structure ScaleState (G : GraphInput) (j : β) where | |
| scale : Fin G.n β β | |
| positive : β i,0<scale i | |
| upper : β i,scale iβ€2^j | |
| def ScaleState.toReal {G : GraphInput} {j : β} (s : ScaleState G j) : Trial.ScaleState G j where | |
| scale i:=(s.scale i:β) | |
| positive i:=by exact_mod_cast s.positive i | |
| upper i:=by exact_mod_cast s.upper i | |
| def ScaleState.activity {G : GraphInput} {j : β} (s : ScaleState G j) : Fin G.n β Fin G.n β β := | |
| fun a b=>raw G j a b*s.scale a*s.scale b | |
| def ScaleState.nextActivity {G : GraphInput} {j : β} (s : ScaleState G j) : Fin G.n β Fin G.n β β := | |
| fun a b=>raw G (j+1) a b*s.scale a*s.scale b | |
| lemma ScaleState.activity_cast {G : GraphInput} {j : β} (s : ScaleState G j) : | |
| (fun a b=>(s.activity a b:β))=s.toReal.activity := by | |
| funext a b | |
| simp only [ScaleState.activity,Trial.ScaleState.activity,Rat.cast_mul,raw_cast,ScaleState.toReal] | |
| lemma ScaleState.nextActivity_cast {G : GraphInput} {j : β} (s : ScaleState G j) : | |
| (fun a b=>(s.nextActivity a b:β))=s.toReal.nextActivity := by | |
| funext a b | |
| simp only [ScaleState.nextActivity,Trial.ScaleState.nextActivity,Rat.cast_mul,raw_cast,ScaleState.toReal] | |
| lemma ScaleState.activity_pos {G : GraphInput} {j : β} (s : ScaleState G j) (a b : Fin G.n) : | |
| 0<s.activity a b := by | |
| have h:=s.toReal.activity_pos a b | |
| rw [βs.activity_cast] at h | |
| dsimp only at h | |
| exact_mod_cast h | |
| lemma ScaleState.nextActivity_pos {G : GraphInput} {j : β} (s : ScaleState G j) (a b : Fin G.n) : | |
| 0<s.nextActivity a b := by | |
| have h:=s.toReal.nextActivity_pos a b | |
| rw [βs.nextActivity_cast] at h | |
| dsimp only at h | |
| exact_mod_cast h | |
| def initialScaleState (G : GraphInput) (hn : 2β€G.n) : ScaleState G 0 where | |
| scale _:=Initializer.initialScale G.n | |
| positive _:=Initializer.initialScale_pos G.n hn | |
| upper i:=by | |
| have h:=(Trial.initialScaleState G hn).upper i | |
| change (Initializer.initialScale G.n:β)β€2^0 at h | |
| exact_mod_cast h | |
| lemma initialScaleState_cast (G : GraphInput) (hn : 2β€G.n) : | |
| (initialScaleState G hn).toReal=Trial.initialScaleState G hn := rfl | |
| end MatchingFPRAS.FiniteTrial | |
| end OAI | |