Download data/lean/OAI/Computability/MaxCut/Arithmetic/GridWeight.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 5.37 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MaxCut/Arithmetic/GridWeight.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/MaxCut/Arithmetic/GridWeight.lean
-
curl -L -o GridWeight.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MaxCut/Arithmetic/GridWeight.lean
5.37 kB
| import Mathlib | |
| import OAI.Computability.MaxCut.Estimates.Dictator | |
| namespace OAI | |
| noncomputable section | |
| namespace OptimalMaxCut.LongCode | |
| open scoped BigOperators | |
| open Finset OptimalMaxCut.Unweighted | |
| namespace Law | |
| variable {I : Type} [Fintype I] | |
| /-- Downward rounding is performed BEFORE aggregation. Thus every output mass | |
| has the same polynomially sized integer denominator; no product of all input | |
| vertex degrees has to be represented as a unary integer. -/ | |
| noncomputable def gridWeight (P : β) (a : β) : β := (β(P : β) * aββ : β) / P | |
| theorem gridWeight_nonneg (P : β) (a : β) : 0 β€ gridWeight P a := by | |
| unfold gridWeight; positivity | |
| theorem gridWeight_le (P : β) (hP : 0 < P) (a : β) (ha : 0 β€ a) : | |
| gridWeight P a β€ a := by | |
| have hPr : (0 : β) < P := by exact_mod_cast hP | |
| rw [gridWeight, div_le_iffβ hPr] | |
| simpa [mul_comm] using Nat.floor_le (mul_nonneg hPr.le ha) | |
| theorem gridWeight_error (P : β) (hP : 0 < P) (a : β) : | |
| a - gridWeight P a β€ 1 / (P : β) := by | |
| have hPr : (0 : β) < P := by exact_mod_cast hP | |
| have h := Nat.lt_floor_add_one ((P : β) * a) | |
| unfold gridWeight | |
| apply (le_div_iffβ hPr).mpr | |
| rw [sub_mul, div_mul_cancelβ _ (ne_of_gt hPr)] | |
| nlinarith | |
| noncomputable def grid (p : Law I) (P : β) (hP : 0 < P) : Law (Option I) where | |
| weight | |
| | none => 1 - β i, gridWeight P (p.weight i) | |
| | some i => gridWeight P (p.weight i) | |
| nonneg | |
| | none => by | |
| have h := sum_le_sum (fun i (_ : i β (univ : Finset I)) => | |
| gridWeight_le P hP (p.weight i) (p.nonneg i)) | |
| rw [p.total] at h | |
| linarith | |
| | some i => gridWeight_nonneg _ _ | |
| total := by simp [Fintype.sum_option] | |
| theorem grid_average (p : Law I) (P : β) (hP : 0 < P) (f : Option I β β) | |
| (hzero : f none = 0) : | |
| (p.grid P hP).avg f = β i, (gridWeight P (p.weight i) : β) * f (some i) := by | |
| simp only [avg, Fintype.sum_option, grid, hzero, mul_zero, zero_add] | |
| theorem grid_average_bounds (p : Law I) (P : β) (hP : 0 < P) (f : I β β) | |
| (hf0 : β i, 0 β€ f i) (hf1 : β i, f i β€ 1) : | |
| let rounded := β i, (gridWeight P (p.weight i) : β) * f i | |
| rounded β€ p.avg f β§ p.avg f - rounded β€ Fintype.card I / (P : β) := by | |
| dsimp only | |
| have hw (i : I) : (gridWeight P (p.weight i) : β) β€ (p.weight i : β) := by | |
| exact_mod_cast gridWeight_le P hP _ (p.nonneg i) | |
| have he (i : I) : (p.weight i : β) - (gridWeight P (p.weight i) : β) β€ 1 / (P : β) := by | |
| have hh : ((p.weight i - gridWeight P (p.weight i) : β) : β) β€ | |
| ((1 / (P : β) : β) : β) := by exact_mod_cast gridWeight_error P hP (p.weight i) | |
| simpa only [Rat.cast_sub, Rat.cast_div, Rat.cast_one, Rat.cast_natCast] using hh | |
| constructor | |
| Β· exact sum_le_sum (fun i _ => mul_le_mul_of_nonneg_right (hw i) (hf0 i)) | |
| Β· rw [avg, β sum_sub_distrib] | |
| calc | |
| _ β€ β _ : I, 1 / (P : β) := sum_le_sum (fun i _ => by | |
| have h := mul_le_of_le_one_right (sub_nonneg.mpr (hw i)) (hf1 i) | |
| nlinarith [he i]) | |
| _ = _ := by simp [div_eq_mul_inv] | |
| end Law | |
| /-- Lost mass becomes a loop, which is deleted by exactly the original | |
| aggregation. It is never renormalized into non-loop edges. -/ | |
| noncomputable def roundedWeights {I : Type} [Fintype I] {N : β} | |
| (p : Law I) (endpoints : I β Fin N Γ Fin N) (v0 : Fin N) | |
| (P : β) (hP : 0 < P) : Fin N β Fin N β β := | |
| aggregate ((p.grid P hP).push (fun | |
| | none => (v0,v0) | |
| | some i => endpoints i)) | |
| theorem roundedWeights_cut_error {I : Type} [Fintype I] {N : β} | |
| (p : Law I) (query : I β Fin N Γ Fin N) (v0 : Fin N) | |
| (P : β) (hP : 0 < P) (Ο : Fin N β Bool) : | |
| let w := aggregate (p.push query) | |
| let w' := roundedWeights p query v0 P hP | |
| weightedCut (fun u v => (w' u v : β)) Ο β€ weightedCut (fun u v => (w u v : β)) Ο β§ | |
| weightedCut (fun u v => (w u v : β)) Ο - | |
| weightedCut (fun u v => (w' u v : β)) Ο β€ Fintype.card I / (P : β) := by | |
| dsimp only | |
| rw [aggregate_cut, Law.push_average, roundedWeights, aggregate_cut, Law.push_average, | |
| Law.grid_average _ _ _ _ (by simp)] | |
| exact Law.grid_average_bounds p P hP (fun i => if Ο (query i).1 β Ο (query i).2 then 1 else 0) | |
| (fun i => by split_ifs <;> norm_num) (fun i => by split_ifs <;> norm_num) | |
| theorem roundedWeights_max_error {I : Type} [Fintype I] {N : β} | |
| (p : Law I) (query : I β Fin N Γ Fin N) (v0 : Fin N) | |
| (P : β) (hP : 0 < P) : | |
| let w := aggregate (p.push query) | |
| let w' := roundedWeights p query v0 P hP | |
| weightedMax (fun u v => (w' u v : β)) β€ weightedMax (fun u v => (w u v : β)) β§ | |
| weightedMax (fun u v => (w u v : β)) - | |
| weightedMax (fun u v => (w' u v : β)) β€ Fintype.card I / (P : β) := by | |
| dsimp only | |
| obtain β¨Ο, hΟβ© := weightedMax_attained (fun u v => | |
| (roundedWeights p query v0 P hP u v : β)) | |
| obtain β¨Ο, hΟβ© := weightedMax_attained (fun u v => (aggregate (p.push query) u v : β)) | |
| constructor | |
| Β· have h := (roundedWeights_cut_error p query v0 P hP Ο).1 | |
| exact hΟ.symm.trans_le (h.trans (weightedCut_le_max _ _)) | |
| Β· have h := (roundedWeights_cut_error p query v0 P hP Ο).2 | |
| have h' := weightedCut_le_max (fun u v => (roundedWeights p query v0 P hP u v : β)) Ο | |
| rw [hΟ] at h | |
| linarith | |
| end OptimalMaxCut.LongCode | |
| end | |
| end OAI | |