Download data/lean/OAI/Computability/BinPacking/Inventory/PhysicalPoolLift.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 9.05 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/BinPacking/Inventory/PhysicalPoolLift.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/BinPacking/Inventory/PhysicalPoolLift.lean
-
curl -L -o PhysicalPoolLift.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/BinPacking/Inventory/PhysicalPoolLift.lean
9.05 kB
| import Mathlib.Data.Fintype.BigOperators | |
| import Mathlib.Tactic.FieldSimp | |
| import Mathlib.Tactic.Ring | |
| import OAI.Computability.BinPacking.Configurations.ConfigurationLP | |
| namespace OAI | |
| noncomputable section | |
| open scoped BigOperators | |
| namespace BinPackingGap | |
| structure PoolTemplates (I : Instance) (T U F : Type*) where | |
| base : T β Finset I.Item | |
| globalPool : U β Finset I.Item | |
| flagPool : F β Finset I.Item | |
| globalSpecies : T β U | |
| flagSpecies : T β F | |
| global_nonempty : β t, (globalPool (globalSpecies t)).Nonempty | |
| flag_nonempty : β t, (flagPool (flagSpecies t)).Nonempty | |
| base_global : β t, Disjoint (base t) (globalPool (globalSpecies t)) | |
| base_flag : β t, Disjoint (base t) (flagPool (flagSpecies t)) | |
| global_flag : β t, | |
| Disjoint (globalPool (globalSpecies t)) (flagPool (flagSpecies t)) | |
| capacity : β t (u : {i // i β globalPool (globalSpecies t)}) | |
| (f : {i // i β flagPool (flagSpecies t)}), | |
| (β i β base t βͺ {u.val, f.val}, I.size i) β€ 1 | |
| namespace PoolTemplates | |
| variable {I : Instance} {T U F : Type*} [Fintype T] | |
| variable (D : PoolTemplates I T U F) | |
| abbrev Globals (t : T) := {i // i β D.globalPool (D.globalSpecies t)} | |
| abbrev Flags (t : T) := {i // i β D.flagPool (D.flagSpecies t)} | |
| abbrev Sample := (t : T) Γ (D.Globals t Γ D.Flags t) | |
| def column (t : T) (u : D.Globals t) (f : D.Flags t) : IndividualConfiguration I := | |
| β¨D.base t βͺ {u.val, f.val}, D.capacity t u fβ© | |
| def sampleColumn (s : D.Sample) : IndividualConfiguration I := | |
| D.column s.1 s.2.1 s.2.2 | |
| def templateMass (t : T) : β := | |
| 1 / (2 * ((D.globalPool (D.globalSpecies t)).card : β) * | |
| ((D.flagPool (D.flagSpecies t)).card : β)) | |
| def sampleMass (s : D.Sample) : β := D.templateMass s.1 | |
| def weights : IndividualConfiguration I β β := | |
| FractionalCover.pushforward D.sampleColumn D.sampleMass | |
| omit [Fintype T] in | |
| theorem templateMass_nonneg (t : T) : 0 β€ D.templateMass t := by | |
| unfold templateMass | |
| positivity | |
| omit [Fintype T] in | |
| theorem global_card_ne_zero (t : T) : | |
| ((D.globalPool (D.globalSpecies t)).card : β) β 0 := by | |
| exact_mod_cast (Finset.card_pos.mpr (D.global_nonempty t)).ne' | |
| omit [Fintype T] in | |
| theorem flag_card_ne_zero (t : T) : | |
| ((D.flagPool (D.flagSpecies t)).card : β) β 0 := by | |
| exact_mod_cast (Finset.card_pos.mpr (D.flag_nonempty t)).ne' | |
| omit [Fintype T] in | |
| theorem sum_templateMass (t : T) : | |
| (β _u : D.Globals t, β _f : D.Flags t, D.templateMass t) = (1 / 2 : β) := by | |
| have hu := D.global_card_ne_zero t | |
| have hf := D.flag_card_ne_zero t | |
| simp only [Finset.sum_const, Finset.card_univ, Fintype.card_coe, nsmul_eq_mul] | |
| unfold templateMass | |
| field_simp [hu, hf] | |
| theorem objective_weights : | |
| FractionalCover.objective D.weights = (Fintype.card T : β) / 2 := by | |
| rw [weights, FractionalCover.objective_pushforward] | |
| unfold FractionalCover.objective sampleMass | |
| rw [Fintype.sum_sigma] | |
| simp only [Fintype.sum_prod_type, sum_templateMass] | |
| simp [div_eq_mul_inv] | |
| theorem sum_pool_eq (S : Finset I.Item) (i : I.Item) (a : β) : | |
| (β u : {j // j β S}, if i = u.val then a else 0) = | |
| if i β S then a else 0 := by | |
| classical | |
| by_cases hi : i β S | |
| Β· have he : β u : {j // j β S}, i = u.val β u = β¨i, hiβ© := by | |
| intro u | |
| constructor | |
| Β· intro h | |
| exact Subtype.ext h.symm | |
| Β· intro h | |
| exact (congrArg Subtype.val h).symm | |
| simp only [he] | |
| simp [hi] | |
| Β· have he : β u : {j // j β S}, i β u.val := by | |
| intro u h | |
| exact hi (h.symm βΈ u.property) | |
| simp [he, hi] | |
| omit [Fintype T] in | |
| theorem template_coverage (t : T) (i : I.Item) : | |
| (β u : D.Globals t, β f : D.Flags t, | |
| (if i β (D.column t u f).val then (1 : β) else 0) * D.templateMass t) = | |
| (if i β D.base t then (1 / 2 : β) else 0) + | |
| (if i β D.globalPool (D.globalSpecies t) then | |
| 1 / (2 * ((D.globalPool (D.globalSpecies t)).card : β)) else 0) + | |
| (if i β D.flagPool (D.flagSpecies t) then | |
| 1 / (2 * ((D.flagPool (D.flagSpecies t)).card : β)) else 0) := by | |
| classical | |
| have hu := D.global_card_ne_zero t | |
| have hf := D.flag_card_ne_zero t | |
| by_cases hb : i β D.base t | |
| Β· have hgu : i β D.globalPool (D.globalSpecies t) := | |
| fun h => Finset.disjoint_left.mp (D.base_global t) hb h | |
| have hfl : i β D.flagPool (D.flagSpecies t) := | |
| fun h => Finset.disjoint_left.mp (D.base_flag t) hb h | |
| simpa [column, hb, hgu, hfl] using D.sum_templateMass t | |
| Β· by_cases hg : i β D.globalPool (D.globalSpecies t) | |
| Β· have hfl : i β D.flagPool (D.flagSpecies t) := | |
| fun h => Finset.disjoint_left.mp (D.global_flag t) hg h | |
| have hcol : β u : D.Globals t, β f : D.Flags t, | |
| i β (D.column t u f).val β i = u.val := by | |
| intro u f | |
| have hn : i β f.val := fun h => hfl (h.symm βΈ f.property) | |
| simp [column, hb, hn] | |
| simp only [hcol, ite_mul, one_mul, zero_mul] | |
| rw [Finset.sum_comm] | |
| simp_rw [sum_pool_eq] | |
| simp only [hb, hg, hfl, ite_false, ite_true, zero_add, add_zero, | |
| Finset.sum_const, Finset.card_univ, Fintype.card_coe, nsmul_eq_mul] | |
| unfold templateMass | |
| field_simp [hu, hf] | |
| Β· by_cases hfl : i β D.flagPool (D.flagSpecies t) | |
| Β· have hcol : β u : D.Globals t, β f : D.Flags t, | |
| i β (D.column t u f).val β i = f.val := by | |
| intro u f | |
| have hn : i β u.val := fun h => hg (h.symm βΈ u.property) | |
| simp [column, hb, hn] | |
| simp only [hcol, ite_mul, one_mul, zero_mul] | |
| simp_rw [sum_pool_eq] | |
| simp only [hb, hg, hfl, ite_false, ite_true, zero_add, | |
| Finset.sum_const, Finset.card_univ, Fintype.card_coe, nsmul_eq_mul] | |
| unfold templateMass | |
| field_simp [hu, hf] | |
| Β· have hcol : β u : D.Globals t, β f : D.Flags t, | |
| i β (D.column t u f).val := by | |
| intro u f | |
| have hnu : i β u.val := fun h => hg (h.symm βΈ u.property) | |
| have hnf : i β f.val := fun h => hfl (h.symm βΈ f.property) | |
| simp [column, hb, hnu, hnf] | |
| simp [hcol, hb, hg, hfl] | |
| theorem sum_by_species {S : Type*} [Fintype S] [DecidableEq S] | |
| (species : T β S) (a : S β β) : | |
| (β t, a (species t)) = | |
| β s, ((Finset.univ.filter (fun t => species t = s)).card : β) * a s := by | |
| classical | |
| calc | |
| (β t, a (species t)) = β t, β s, if species t = s then a s else 0 := by simp | |
| _ = β s, β t, if species t = s then a s else 0 := Finset.sum_comm | |
| _ = _ := by | |
| apply Finset.sum_congr rfl | |
| intro s _ | |
| rw [β Finset.sum_filter] | |
| simp | |
| theorem sum_pool_demands {S : Type*} [Fintype S] [DecidableEq S] | |
| (species : T β S) (pool : S β Finset I.Item) | |
| (hdemand : β s, (Finset.univ.filter (fun t => species t = s)).card = | |
| 2 * (pool s).card) (i : I.Item) : | |
| (β t, if i β pool (species t) then | |
| 1 / (2 * ((pool (species t)).card : β)) else 0) = | |
| β s, if i β pool s then (1 : β) else 0 := by | |
| classical | |
| rw [sum_by_species species (fun s => | |
| if i β pool s then 1 / (2 * ((pool s).card : β)) else 0)] | |
| apply Finset.sum_congr rfl | |
| intro s _ | |
| rw [hdemand s] | |
| by_cases hi : i β pool s | |
| Β· have hs : ((pool s).card : β) β 0 := by | |
| exact_mod_cast (Finset.card_pos.mpr β¨i, hiβ©).ne' | |
| simp only [hi, ite_true, Nat.cast_mul, Nat.cast_ofNat] | |
| field_simp [hs] | |
| Β· simp [hi] | |
| variable [Fintype U] [Fintype F] [DecidableEq U] [DecidableEq F] | |
| theorem weights_feasible | |
| (labeled : Finset I.Item) | |
| (hbase : β i, (Finset.univ.filter (fun t => i β D.base t)).card = | |
| if i β labeled then 2 else 0) | |
| (hglobal : β u, (Finset.univ.filter (fun t => D.globalSpecies t = u)).card = | |
| 2 * (D.globalPool u).card) | |
| (hflag : β f, (Finset.univ.filter (fun t => D.flagSpecies t = f)).card = | |
| 2 * (D.flagPool f).card) | |
| (hpartition : β i, | |
| (if i β labeled then (1 : β) else 0) + | |
| (β u, if i β D.globalPool u then (1 : β) else 0) + | |
| (β f, if i β D.flagPool f then (1 : β) else 0) = 1) : | |
| IndividualFeasible I D.weights := by | |
| classical | |
| refine β¨FractionalCover.pushforward_nonneg D.sampleColumn | |
| (fun s => D.templateMass_nonneg s.1), ?_β© | |
| intro i | |
| change 1 β€ β H, individualMatrix I H i * D.weights H | |
| rw [weights, FractionalCover.coverage_pushforward] | |
| change 1 β€ β s : D.Sample, | |
| (if i β (D.column s.1 s.2.1 s.2.2).val then (1 : β) else 0) * D.templateMass s.1 | |
| rw [Fintype.sum_sigma] | |
| simp only [Fintype.sum_prod_type, template_coverage, Finset.sum_add_distrib] | |
| rw [sum_pool_demands D.globalSpecies D.globalPool hglobal, | |
| sum_pool_demands D.flagSpecies D.flagPool hflag] | |
| have hb : (β t, if i β D.base t then (1 / 2 : β) else 0) = | |
| if i β labeled then (1 : β) else 0 := by | |
| rw [β Finset.sum_filter] | |
| simp only [Finset.sum_const, nsmul_eq_mul, hbase] | |
| split_ifs <;> norm_num | |
| simpa only [hb, hpartition i] using (le_refl (1 : β)) | |
| end PoolTemplates | |
| end BinPackingGap | |
| end | |
| end OAI | |