Download data/lean/OAI/Computability/BinPacking/Packing/K4Graph.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 21.4 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/BinPacking/Packing/K4Graph.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/BinPacking/Packing/K4Graph.lean
-
curl -L -o K4Graph.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/BinPacking/Packing/K4Graph.lean
21.4 kB
| import Lean.Elab.Tactic.Omega | |
| import Mathlib.Algebra.BigOperators.Ring.Finset | |
| import Mathlib.Algebra.Order.Archimedean.Real.Basic | |
| import Mathlib.Algebra.Order.BigOperators.Group.Finset | |
| import Mathlib.Algebra.Order.Floor.Ring | |
| import Mathlib.Data.Finset.Card | |
| import Mathlib.Data.Fintype.BigOperators | |
| import Mathlib.Data.Fintype.Fin | |
| import Mathlib.Basic.Real.Basic | |
| import Mathlib.Logic.Equiv.Sum | |
| import Mathlib.Tactic.FieldSimp | |
| import Mathlib.Tactic.FinCases | |
| import Mathlib.Tactic.Linarith | |
| import Mathlib.Tactic.NormNum | |
| import Mathlib.Tactic.Positivity | |
| import Mathlib.Tactic.Ring | |
| namespace OAI | |
| noncomputable section | |
| namespace BinPackingGap | |
| def primaryScoreBound : β := 100 ^ 11 | |
| def lossAllowance (c : β) : β := 25 * (c + 1) * (1 + 5 * primaryScoreBound) | |
| def depthDemand (c : β) (Ο : β) : β := | |
| Nat.ceil (max (72 * (lossAllowance c : β)) (120 * (lossAllowance c : β) / Ο)) | |
| def repetitions (P n K : β) : β := 100 * (P + n * K + 1) | |
| theorem primaryScoreBound_pos : 0 < primaryScoreBound := by | |
| unfold primaryScoreBound | |
| positivity | |
| theorem lossAllowance_pos (c : β) : 0 < lossAllowance c := by | |
| unfold lossAllowance | |
| positivity | |
| theorem primary_loss_lt_lossAllowance (c : β) : | |
| 25 * c * (1 + 5 * primaryScoreBound) < lossAllowance c := by | |
| unfold lossAllowance | |
| apply mul_lt_mul_of_pos_right _ (by positivity) | |
| exact mul_lt_mul_of_pos_left (Nat.lt_succ_self c) (by norm_num) | |
| theorem depthDemand_ge_72_real (c : β) (Ο : β) : | |
| 72 * (lossAllowance c : β) β€ (depthDemand c Ο : β) := by | |
| exact (le_max_left _ _).trans (Nat.le_ceil _) | |
| theorem depthDemand_ge_72 (c : β) (Ο : β) : | |
| 72 * lossAllowance c β€ depthDemand c Ο := by | |
| exact_mod_cast depthDemand_ge_72_real c Ο | |
| theorem depthDemand_ge_120_div (c : β) (Ο : β) : | |
| 120 * (lossAllowance c : β) / Ο β€ (depthDemand c Ο : β) := by | |
| exact (le_max_right _ _).trans (Nat.le_ceil _) | |
| theorem depthDemand_pos (c : β) (Ο : β) : 0 < depthDemand c Ο := | |
| lt_of_lt_of_le (Nat.mul_pos (by norm_num) (lossAllowance_pos c)) | |
| (depthDemand_ge_72 c Ο) | |
| theorem depthDemand_one_le (c : β) (Ο : β) : 1 β€ depthDemand c Ο := | |
| Nat.succ_le_of_lt (depthDemand_pos c Ο) | |
| theorem depthDemand_ge_12 (c : β) (Ο : β) : | |
| 12 * lossAllowance c β€ depthDemand c Ο := by | |
| exact (Nat.mul_le_mul_right (lossAllowance c) (by norm_num : 12 β€ 72)).trans | |
| (depthDemand_ge_72 c Ο) | |
| theorem depthDemand_spec (c : β) (Ο : β) : | |
| 1 β€ depthDemand c Ο β§ | |
| max (72 * (lossAllowance c : β)) (120 * (lossAllowance c : β) / Ο) β€ | |
| (depthDemand c Ο : β) := | |
| β¨depthDemand_one_le c Ο, Nat.le_ceil _β© | |
| theorem threshold_gap {d K : β} (hd : 0 < d) (h72 : 72 * K β€ d) : | |
| d / 8 < d - 6 * K := by | |
| linarith | |
| theorem three_quarter_lower {d K x L : β} (h72 : 72 * K β€ d) | |
| (hx : x β€ d / 8) (hL : d - x - 9 * K β€ L) : 3 * d / 4 β€ L := by | |
| linarith | |
| theorem depthDemand_threshold_gap (c : β) (Ο : β) : | |
| (depthDemand c Ο : β) / 8 < (depthDemand c Ο : β) - 6 * (lossAllowance c : β) := | |
| threshold_gap (Nat.cast_pos.mpr (depthDemand_pos c Ο)) (depthDemand_ge_72_real c Ο) | |
| theorem repetitions_pos (P n K : β) : 0 < repetitions P n K := by | |
| unfold repetitions | |
| positivity | |
| theorem repetitions_gt_P (P n K : β) : P < repetitions P n K := by | |
| have hnK : 0 β€ n * K := Nat.zero_le _ | |
| unfold repetitions | |
| nlinarith | |
| theorem repetitions_cast (P n K : β) : | |
| (repetitions P n K : β) = 100 * ((P : β) + (n : β) * K + 1) := by | |
| simp [repetitions] | |
| theorem edge_demand_exceeds_capacity_real {P n K d : β} | |
| (hP : 0 β€ P) (hn : 0 β€ n) (hK : 0 β€ K) (hd : 1 β€ d) : | |
| d * (100 * (P + n * K + 1)) + 3 * n * K < | |
| 2 * (100 * (P + n * K + 1) - P) * (3 * d / 4) := by | |
| have hd0 : 0 β€ d := le_trans zero_le_one hd | |
| have hdP : 0 β€ d * P := mul_nonneg hd0 hP | |
| have hnK : 0 β€ n * K := mul_nonneg hn hK | |
| have hrest : 0 β€ (50 * d - 3) * (n * K) := | |
| mul_nonneg (by linarith) hnK | |
| nlinarith | |
| theorem edge_demand_exceeds_capacity (P n K d : β) (hd : 1 β€ d) : | |
| (d : β) * (repetitions P n K : β) + 3 * (n : β) * K < | |
| 2 * ((repetitions P n K : β) - P) * (3 * (d : β) / 4) := by | |
| rw [repetitions_cast] | |
| exact edge_demand_exceeds_capacity_real (Nat.cast_nonneg P) (Nat.cast_nonneg n) | |
| (Nat.cast_nonneg K) (by exact_mod_cast hd) | |
| theorem sixty_loss_div_le {Ο d K n : β} (hΟ : 0 < Ο) (hd : 0 < d) | |
| (hK : 0 β€ K) (hn : 0 β€ n) (h120 : 120 * K / Ο β€ d) : | |
| 60 * K * n / d β€ Ο * n := by | |
| have hmul := (div_le_iffβ hΟ).mp h120 | |
| have h60 : 60 * K β€ Ο * d := by nlinarith | |
| apply (div_le_iffβ hd).mpr | |
| calc | |
| 60 * K * n β€ (Ο * d) * n := mul_le_mul_of_nonneg_right h60 hn | |
| _ = (Ο * n) * d := by ring | |
| theorem depthDemand_sixty_loss_div_le (c n : β) {Ο : β} (hΟ : 0 < Ο) : | |
| 60 * (lossAllowance c : β) * (n : β) / (depthDemand c Ο : β) β€ Ο * n := | |
| sixty_loss_div_le hΟ (Nat.cast_pos.mpr (depthDemand_pos c Ο)) | |
| (Nat.cast_nonneg _) (Nat.cast_nonneg _) (depthDemand_ge_120_div c Ο) | |
| structure GraphInput where | |
| n : β | |
| edges : List (Fin n Γ Fin n) | |
| ordered : β e β edges, e.1 < e.2 | |
| distinct : edges.Nodup | |
| namespace GraphInput | |
| abbrev Vertex (G : GraphInput) := Fin G.n | |
| abbrev Edge (G : GraphInput) := Fin G.edges.length | |
| def left (G : GraphInput) (e : G.Edge) : G.Vertex := (G.edges[e]).1 | |
| def right (G : GraphInput) (e : G.Edge) : G.Vertex := (G.edges[e]).2 | |
| def IsCover (G : GraphInput) (C : Finset G.Vertex) : Prop := | |
| β e β G.edges, e.1 β C β¨ e.2 β C | |
| def CoverAtMost (G : GraphInput) (k : β) : Prop := | |
| β C : Finset G.Vertex, G.IsCover C β§ C.card β€ k | |
| end GraphInput | |
| open scoped BigOperators | |
| namespace GraphInput | |
| def endpoint (G : GraphInput) (e : G.Edge) (s : Fin 2) : G.Vertex := | |
| if s = 0 then G.left e else G.right e | |
| @[simp] theorem endpoint_zero (G : GraphInput) (e : G.Edge) : | |
| G.endpoint e 0 = G.left e := by simp [endpoint] | |
| @[simp] theorem endpoint_one (G : GraphInput) (e : G.Edge) : | |
| G.endpoint e 1 = G.right e := by simp [endpoint] | |
| theorem left_lt_right (G : GraphInput) (e : G.Edge) : G.left e < G.right e := | |
| G.ordered _ (List.getElem_mem e.isLt) | |
| theorem left_ne_right (G : GraphInput) (e : G.Edge) : G.left e β G.right e := | |
| (G.left_lt_right e).ne | |
| theorem endpoint_injective (G : GraphInput) (e : G.Edge) : | |
| Function.Injective (G.endpoint e) := by | |
| intro s t h | |
| have hs : s = 0 β¨ s = 1 := by omega | |
| have ht : t = 0 β¨ t = 1 := by omega | |
| rcases hs with rfl | rfl <;> rcases ht with rfl | rfl | |
| Β· rfl | |
| Β· exact False.elim (G.left_ne_right e (by simpa using h)) | |
| Β· exact False.elim (G.left_ne_right e (by simpa using h.symm)) | |
| Β· rfl | |
| abbrev Incidence (G : GraphInput) (v : G.Vertex) := | |
| {es : G.Edge Γ Fin 2 // G.endpoint es.1 es.2 = v} | |
| def incidenceEquiv (G : GraphInput) : | |
| (Ξ£ v : G.Vertex, G.Incidence v) β G.Edge Γ Fin 2 := | |
| Equiv.sigmaFiberEquiv (fun es : G.Edge Γ Fin 2 => G.endpoint es.1 es.2) | |
| def degree (G : GraphInput) (v : G.Vertex) : β := | |
| Fintype.card (G.Incidence v) | |
| theorem sum_degree (G : GraphInput) : | |
| (β v : G.Vertex, G.degree v) = 2 * G.edges.length := by | |
| have h := Fintype.card_congr (G.incidenceEquiv) | |
| simpa [degree, Fintype.card_sigma, Fintype.card_prod, Nat.mul_comm] using h | |
| abbrev IncidencePosition (G : GraphInput) (R : β) (v : G.Vertex) := | |
| G.Incidence v Γ Fin R | |
| abbrev JobCopy (G : GraphInput) (R d : β) (v : G.Vertex) := | |
| G.IncidencePosition R v Γ Fin d | |
| theorem card_incidencePosition (G : GraphInput) (R : β) (v : G.Vertex) : | |
| Fintype.card (G.IncidencePosition R v) = R * G.degree v := by | |
| simp [IncidencePosition, degree, Nat.mul_comm] | |
| theorem card_jobCopy (G : GraphInput) (R d : β) (v : G.Vertex) : | |
| Fintype.card (G.JobCopy R d v) = d * R * G.degree v := by | |
| simp [JobCopy, IncidencePosition, degree, Nat.mul_comm, Nat.mul_left_comm, | |
| Nat.mul_assoc] | |
| theorem sum_card_jobCopy (G : GraphInput) (R d : β) : | |
| (β v : G.Vertex, Fintype.card (G.JobCopy R d v)) = | |
| 2 * d * G.edges.length * R := by | |
| simp_rw [card_jobCopy] | |
| rw [β Finset.mul_sum, sum_degree] | |
| ac_rfl | |
| end GraphInput | |
| end BinPackingGap | |
| section | |
| open scoped BigOperators | |
| namespace BinPackingGap | |
| variable {V : Type*} [Fintype V] [DecidableEq V] | |
| def thresholdCover (d : β) (xplus : V β β) : Finset V := by | |
| classical | |
| exact Finset.univ.filter fun v => (d : β) / 8 < (xplus v : β) | |
| def largePlus (d K : β) (xplus : V β β) : Finset V := by | |
| classical | |
| exact Finset.univ.filter fun v => (d : β) - 6 * K β€ (xplus v : β) | |
| theorem residual_plus_le {d K : β} (xplus xminus : V β β) | |
| (htotal : (β v, (xplus v + xminus v)) β€ d * Fintype.card V) | |
| (hside : β v, d β€ xplus v + 6 * K β¨ d β€ xminus v + 6 * K) : | |
| (β v, if v β largePlus d K xplus then (0 : β) else (xplus v : β)) β€ | |
| 6 * (K : β) * Fintype.card V := by | |
| classical | |
| let charge : V β β := fun v => | |
| if v β largePlus d K xplus then (xplus v : β) else (xminus v : β) | |
| let rest : V β β := fun v => | |
| if v β largePlus d K xplus then 0 else (xplus v : β) | |
| have hcharge : β v, (d : β) - 6 * K β€ charge v := by | |
| intro v | |
| by_cases hv : v β largePlus d K xplus | |
| Β· simpa only [charge, ite_eq_left hv] using (Finset.mem_filter.mp hv).2 | |
| Β· have hnot : Β¬ ((d : β) - 6 * K β€ (xplus v : β)) := by | |
| simpa [largePlus] using hv | |
| rcases hside v with hp | hm | |
| Β· have hp' : (d : β) β€ (xplus v : β) + 6 * K := by exact_mod_cast hp | |
| exact (hnot (by linarith)).elim | |
| Β· have hm' : (d : β) β€ (xminus v : β) + 6 * K := by exact_mod_cast hm | |
| simp only [charge, ite_eq_right hv] | |
| linarith | |
| have hcharged : (Fintype.card V : β) * ((d : β) - 6 * K) β€ β v, charge v := by | |
| calc | |
| _ = β _v : V, ((d : β) - 6 * K) := by | |
| simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] | |
| _ β€ β v, charge v := Finset.sum_le_sum fun v _ => hcharge v | |
| have hpoint : β v, charge v + rest v β€ (xplus v : β) + xminus v := by | |
| intro v | |
| dsimp only [charge, rest] | |
| split_ifs <;> nlinarith [show (0 : β) β€ xplus v from Nat.cast_nonneg _, | |
| show (0 : β) β€ xminus v from Nat.cast_nonneg _] | |
| have hsum : (β v, charge v) + (β v, rest v) β€ | |
| (d : β) * Fintype.card V := by | |
| calc | |
| _ = β v, (charge v + rest v) := (Finset.sum_add_distrib).symm | |
| _ β€ β v, ((xplus v : β) + xminus v) := Finset.sum_le_sum fun v _ => hpoint v | |
| _ β€ (d : β) * Fintype.card V := by exact_mod_cast htotal | |
| change (β v, rest v) β€ _ | |
| nlinarith | |
| theorem thresholdCover_card_le_fractions {d K k : β} (xplus xminus : V β β) | |
| (hd : 0 < d) (h72 : 72 * K β€ d) | |
| (hplus : (β v, xplus v) β€ d * k) | |
| (htotal : (β v, (xplus v + xminus v)) β€ d * Fintype.card V) | |
| (hside : β v, d β€ xplus v + 6 * K β¨ d β€ xminus v + 6 * K) : | |
| ((thresholdCover d xplus).card : β) β€ | |
| (d : β) * k / ((d : β) - 6 * K) + 48 * (K : β) * Fintype.card V / d := by | |
| classical | |
| let A := largePlus d K xplus | |
| let C := thresholdCover d xplus | |
| let B := C \ A | |
| have hd0 : (0 : β) < d := by exact_mod_cast hd | |
| have h72' : 72 * (K : β) β€ d := by exact_mod_cast h72 | |
| have hgap := threshold_gap hd0 h72' | |
| have hden : 0 < (d : β) - 6 * K := lt_trans (by positivity) hgap | |
| have hAC : A β C := by | |
| intro v hv | |
| have hv' : (d : β) - 6 * K β€ (xplus v : β) := (Finset.mem_filter.mp hv).2 | |
| exact Finset.mem_filter.mpr β¨Finset.mem_univ v, hgap.trans_le hv'β© | |
| have hAlower : (A.card : β) * ((d : β) - 6 * K) β€ β v, (xplus v : β) := by | |
| calc | |
| _ = β _v β A, ((d : β) - 6 * K) := by | |
| simp only [Finset.sum_const, nsmul_eq_mul] | |
| _ β€ β v β A, (xplus v : β) := | |
| Finset.sum_le_sum fun v hv => (Finset.mem_filter.mp hv).2 | |
| _ β€ β v, (xplus v : β) := | |
| Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (by intros; positivity) | |
| have hA : (A.card : β) β€ (d : β) * k / ((d : β) - 6 * K) := by | |
| apply (le_div_iffβ hden).mpr | |
| exact hAlower.trans (by exact_mod_cast hplus) | |
| let rest : V β β := fun v => if v β A then 0 else (xplus v : β) | |
| have hrest : (β v, rest v) β€ 6 * (K : β) * Fintype.card V := | |
| residual_plus_le xplus xminus htotal hside | |
| have hBlower : (B.card : β) * ((d : β) / 8) β€ β v, rest v := by | |
| calc | |
| _ = β _v β B, ((d : β) / 8) := by simp | |
| _ β€ β v β B, rest v := by | |
| apply Finset.sum_le_sum | |
| intro v hv | |
| obtain β¨hvC, hvAβ© := Finset.mem_sdiff.mp hv | |
| have hv' : (d : β) / 8 < (xplus v : β) := (Finset.mem_filter.mp hvC).2 | |
| simpa only [rest, ite_eq_right hvA] using hv'.le | |
| _ β€ β v, rest v := by | |
| apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) | |
| intro v _ _ | |
| dsimp only [rest] | |
| split_ifs <;> positivity | |
| have hB : (B.card : β) β€ 48 * (K : β) * Fintype.card V / d := by | |
| apply (le_div_iffβ hd0).mpr | |
| nlinarith | |
| have hcard : (C.card : β) = (A.card : β) + B.card := by | |
| have hh := Finset.card_sdiff_add_card_eq_card hAC | |
| dsimp only [B] | |
| exact_mod_cast hh.symm.trans (Nat.add_comm _ _) | |
| change (C.card : β) β€ _ | |
| rw [hcard] | |
| exact add_le_add hA hB | |
| theorem cover_fraction_bound {d K k n : β} (hd : 0 < d) (hK : 0 β€ K) | |
| (hk0 : 0 β€ k) (hkn : k β€ n) (h12 : 12 * K β€ d) : | |
| d * k / (d - 6 * K) + 48 * K * n / d β€ k + 60 * K * n / d := by | |
| have hn : 0 β€ n := hk0.trans hkn | |
| have hden : 0 < d - 6 * K := by linarith | |
| have hmult := mul_le_mul_of_nonneg_left hkn (show 0 β€ 6 * K * d by positivity) | |
| have hslack := mul_nonneg (show 0 β€ 6 * K * n by positivity) (sub_nonneg.mpr h12) | |
| have hfrac : 6 * K * k / (d - 6 * K) β€ 12 * K * n / d := by | |
| apply (div_le_div_iffβ hden hd).mpr | |
| nlinarith | |
| have hid : d * k / (d - 6 * K) = k + 6 * K * k / (d - 6 * K) := by | |
| field_simp [hden.ne']; ring | |
| rw [hid] | |
| have hsplit : 60 * K * n / d = 12 * K * n / d + 48 * K * n / d := by ring | |
| rw [hsplit] | |
| linarith | |
| theorem thresholdCover_card_le {d K k : β} {Ο : β} (xplus xminus : V β β) | |
| (hd : 0 < d) (h72 : 72 * K β€ d) (hk : k β€ Fintype.card V) | |
| (hΟ : 0 < Ο) (h120 : 120 * (K : β) / Ο β€ d) | |
| (hplus : (β v, xplus v) β€ d * k) | |
| (htotal : (β v, (xplus v + xminus v)) β€ d * Fintype.card V) | |
| (hside : β v, d β€ xplus v + 6 * K β¨ d β€ xminus v + 6 * K) : | |
| ((thresholdCover d xplus).card : β) β€ (k : β) + Ο * Fintype.card V := by | |
| have hd0 : (0 : β) < d := by exact_mod_cast hd | |
| have h72' : 72 * (K : β) β€ d := by exact_mod_cast h72 | |
| calc | |
| _ β€ (d : β) * k / ((d : β) - 6 * K) + 48 * (K : β) * Fintype.card V / d := | |
| thresholdCover_card_le_fractions xplus xminus hd h72 hplus htotal hside | |
| _ β€ (k : β) + 60 * (K : β) * Fintype.card V / d := | |
| cover_fraction_bound hd0 (Nat.cast_nonneg K) (Nat.cast_nonneg k) | |
| (by exact_mod_cast hk) (by linarith) | |
| _ β€ (k : β) + Ο * Fintype.card V := | |
| add_le_add (le_refl (k : β)) (sixty_loss_div_le hΟ hd0 (Nat.cast_nonneg K) | |
| (Nat.cast_nonneg _) h120) | |
| theorem longMatch_sum_lower {R P : β} (S : Finset (Fin R)) (L : Fin R β β) | |
| {a : β} (ha : 0 β€ a) (hS : (R : β) - P β€ (S.card : β)) | |
| (hL : β j β S, a β€ (L j : β)) : | |
| ((R : β) - P) * a β€ β j, (L j : β) := by | |
| calc | |
| _ β€ (S.card : β) * a := mul_le_mul_of_nonneg_right hS ha | |
| _ = β _j β S, a := by simp | |
| _ β€ β j β S, (L j : β) := Finset.sum_le_sum hL | |
| _ β€ β j, (L j : β) := | |
| Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (by intros; positivity) | |
| theorem thresholdCover_isCover (G : GraphInput) {d K P R : β} | |
| (xplus : G.Vertex β β) | |
| (Sleft Sright : G.Edge β Finset (Fin R)) | |
| (Lleft Lright : G.Edge β Fin R β β) | |
| (hd : 1 β€ d) (h72 : 72 * K β€ d) (hR : R = repetitions P G.n K) | |
| (hSleft : β e, (R : β) - P β€ ((Sleft e).card : β)) | |
| (hSright : β e, (R : β) - P β€ ((Sright e).card : β)) | |
| (hLleft : β e j, j β Sleft e β d β€ Lleft e j + xplus (G.left e) + 9 * K) | |
| (hLright : β e j, j β Sright e β d β€ Lright e j + xplus (G.right e) + 9 * K) | |
| (hcapacity : β e, (β j, Lleft e j) + (β j, Lright e j) β€ | |
| d * R + 3 * G.n * K) : | |
| G.IsCover (thresholdCover d xplus) := by | |
| classical | |
| let C := thresholdCover d xplus | |
| have hd0 : (0 : β) < d := by exact_mod_cast (Nat.lt_of_lt_of_le Nat.zero_lt_one hd) | |
| have h72' : 72 * (K : β) β€ d := by exact_mod_cast h72 | |
| have hstrict : (d : β) * R + 3 * (G.n : β) * K < | |
| 2 * ((R : β) - P) * (3 * (d : β) / 4) := by | |
| rw [hR] | |
| exact edge_demand_exceeds_capacity P G.n K d hd | |
| have hindex : β e : G.Edge, G.left e β C β¨ G.right e β C := by | |
| intro e | |
| by_cases hv : G.left e β C | |
| Β· exact Or.inl hv | |
| right | |
| by_contra hw | |
| have hxleft : (xplus (G.left e) : β) β€ (d : β) / 8 := by | |
| apply le_of_not_gt | |
| simpa [C, thresholdCover] using hv | |
| have hxright : (xplus (G.right e) : β) β€ (d : β) / 8 := by | |
| apply le_of_not_gt | |
| simpa [C, thresholdCover] using hw | |
| have hleft : ((R : β) - P) * (3 * (d : β) / 4) β€ | |
| β j, (Lleft e j : β) := by | |
| apply longMatch_sum_lower _ _ (by positivity) (hSleft e) | |
| intro j hj | |
| have hmatch : (d : β) β€ (Lleft e j : β) + xplus (G.left e) + 9 * K := by | |
| exact_mod_cast hLleft e j hj | |
| exact three_quarter_lower h72' hxleft (by linarith) | |
| have hright : ((R : β) - P) * (3 * (d : β) / 4) β€ | |
| β j, (Lright e j : β) := by | |
| apply longMatch_sum_lower _ _ (by positivity) (hSright e) | |
| intro j hj | |
| have hmatch : (d : β) β€ (Lright e j : β) + xplus (G.right e) + 9 * K := by | |
| exact_mod_cast hLright e j hj | |
| exact three_quarter_lower h72' hxright (by linarith) | |
| have hcap : (β j, (Lleft e j : β)) + (β j, (Lright e j : β)) β€ | |
| (d : β) * R + 3 * (G.n : β) * K := by exact_mod_cast hcapacity e | |
| linarith | |
| intro e he | |
| obtain β¨i, hi, heqβ© := List.mem_iff_getElem.mp he | |
| have h := hindex β¨i, hiβ© | |
| change (G.edges[i]).1 β C β¨ (G.edges[i]).2 β C at h | |
| rw [heq] at h | |
| exact h | |
| theorem thresholdCover_card_le_graph (G : GraphInput) {d K k : β} {Ο : β} | |
| (xplus xminus : G.Vertex β β) | |
| (hd : 0 < d) (h72 : 72 * K β€ d) (hk : k β€ G.n) | |
| (hΟ : 0 < Ο) (h120 : 120 * (K : β) / Ο β€ d) | |
| (hplus : (β v, xplus v) β€ d * k) | |
| (htotal : (β v, (xplus v + xminus v)) β€ d * G.n) | |
| (hside : β v, d β€ xplus v + 6 * K β¨ d β€ xminus v + 6 * K) : | |
| ((thresholdCover d xplus).card : β) β€ (k : β) + Ο * G.n := by | |
| simpa only [Fintype.card_fin] using | |
| thresholdCover_card_le xplus xminus hd h72 | |
| (by simpa only [Fintype.card_fin] using hk) hΟ h120 hplus | |
| (by simpa only [Fintype.card_fin] using htotal) hside | |
| end BinPackingGap | |
| end | |
| namespace BinPackingGap | |
| def completeFourGraph : GraphInput where | |
| n := 4 | |
| edges := [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)] | |
| ordered := by decide | |
| distinct := by decide | |
| theorem completeFourGraph_edge_pos : 0 < completeFourGraph.edges.length := by decide | |
| theorem completeFourGraph_cover_card {C : Finset completeFourGraph.Vertex} | |
| (hC : completeFourGraph.IsCover C) : 3 β€ C.card := by | |
| classical | |
| change Finset (Fin 4) at C | |
| change 3 β€ C.card | |
| change β e : Fin 4 Γ Fin 4, | |
| e β [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)] β | |
| e.1 β C β¨ e.2 β C at hC | |
| have h01 : (0 : Fin 4) β C β¨ (1 : Fin 4) β C := | |
| hC ((0 : Fin 4), (1 : Fin 4)) (by decide) | |
| have h02 : (0 : Fin 4) β C β¨ (2 : Fin 4) β C := | |
| hC ((0 : Fin 4), (2 : Fin 4)) (by decide) | |
| have h03 : (0 : Fin 4) β C β¨ (3 : Fin 4) β C := | |
| hC ((0 : Fin 4), (3 : Fin 4)) (by decide) | |
| have h12 : (1 : Fin 4) β C β¨ (2 : Fin 4) β C := | |
| hC ((1 : Fin 4), (2 : Fin 4)) (by decide) | |
| have h13 : (1 : Fin 4) β C β¨ (3 : Fin 4) β C := | |
| hC ((1 : Fin 4), (3 : Fin 4)) (by decide) | |
| have h23 : (2 : Fin 4) β C β¨ (3 : Fin 4) β C := | |
| hC ((2 : Fin 4), (3 : Fin 4)) (by decide) | |
| have hsmall : (Finset.univ \ C).card β€ 1 := by | |
| apply Finset.card_le_one.mpr | |
| intro x hx y hy | |
| have hxC : x β C := (Finset.mem_sdiff.mp hx).2 | |
| have hyC : y β C := (Finset.mem_sdiff.mp hy).2 | |
| fin_cases x <;> fin_cases y <;> simp_all | |
| have htotal : (Finset.univ \ C).card + C.card = 4 := by | |
| simpa only [Finset.card_univ, Fintype.card_fin, completeFourGraph] using | |
| Finset.card_sdiff_add_card_eq_card (Finset.subset_univ C) | |
| omega | |
| theorem completeFourGraph_cover_three : completeFourGraph.CoverAtMost 3 := by | |
| change β C : Finset (Fin 4), | |
| (β e : Fin 4 Γ Fin 4, | |
| e β [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)] β | |
| e.1 β C β¨ e.2 β C) β§ C.card β€ 3 | |
| exact β¨{0, 1, 2}, by decide, by decideβ© | |
| theorem completeFourGraph_no_small_cover : | |
| Β¬ β C : Finset completeFourGraph.Vertex, | |
| completeFourGraph.IsCover C β§ | |
| (C.card : β) β€ 2 + (1 / 8 : β) * completeFourGraph.n := by | |
| rintro β¨C, hC, hcardβ© | |
| have hthree : (3 : β) β€ C.card := by exact_mod_cast completeFourGraph_cover_card hC | |
| norm_num [completeFourGraph] at hcard | |
| linarith | |
| end BinPackingGap | |
| end | |
| end OAI | |