Download data/lean/OAI/Computability/BinPacking/Inventory/LabelConservation.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 13.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/BinPacking/Inventory/LabelConservation.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/BinPacking/Inventory/LabelConservation.lean
-
curl -L -o LabelConservation.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/BinPacking/Inventory/LabelConservation.lean
13.7 kB
| import Lean.Elab.Tactic.Omega | |
| import Mathlib.Algebra.BigOperators.Group.Finset.Basic | |
| import Mathlib.Data.Finset.Card | |
| import Mathlib.Data.Fintype.Basic | |
| namespace OAI | |
| namespace BinPackingGap | |
| namespace FinitePrefixConservation | |
| variable {Ξ± Ξ² : Type*} [DecidableEq Ξ±] [DecidableEq Ξ²] | |
| theorem remaining_eq_bad (keys good : Finset Ξ±) (resources : Finset Ξ²) | |
| (f : Ξ± β Ξ²) (hgood : good β keys) | |
| (hmap : β x β good, f x β resources) | |
| (hinj : Set.InjOn f (good : Set Ξ±)) | |
| (hcard : resources.card = keys.card) : | |
| (resources \ good.image f).card = (keys \ good).card := by | |
| have himage : good.image f β resources := Finset.image_subset_iff.mpr hmap | |
| rw [Finset.card_sdiff_of_subset himage, Finset.card_sdiff_of_subset hgood, | |
| Finset.card_image_of_injOn hinj, hcard] | |
| theorem remaining_le_bad (keys good : Finset Ξ±) (resources remaining : Finset Ξ²) | |
| (f : Ξ± β Ξ²) (hgood : good β keys) | |
| (hmap : β x β good, f x β resources) | |
| (hinj : Set.InjOn f (good : Set Ξ±)) | |
| (hcard : resources.card = keys.card) | |
| (hremaining : remaining β resources \ good.image f) : | |
| remaining.card β€ (keys \ good).card := by | |
| calc | |
| remaining.card β€ (resources \ good.image f).card := Finset.card_le_card hremaining | |
| _ = (keys \ good).card := remaining_eq_bad keys good resources f hgood hmap hinj hcard | |
| end FinitePrefixConservation | |
| namespace LabelConservation | |
| open scoped BigOperators | |
| variable {n : β} | |
| variable {T A R D : Type*} | |
| variable [Fintype T] [Fintype A] [Fintype R] [Fintype D] | |
| variable [DecidableEq A] [DecidableEq R] [DecidableEq D] | |
| def outsideItems (f : T β A) : Finset A := Finset.univ \ Finset.univ.image f | |
| def prefixItems (label : A β Fin n) (h : β) : Finset A := | |
| Finset.univ.filter fun x => (label x).val < h | |
| def prefixOutside (label : A β Fin n) (f : T β A) (h : β) : Finset A := | |
| (outsideItems f).filter fun x => (label x).val < h | |
| def exports (labelA : A β Fin n) (labelR : R β Fin n) | |
| (anchor : T β A) (role : T β R) (h : β) : Finset T := | |
| Finset.univ.filter fun t => | |
| (labelR (role t)).val < h β§ Β¬ (labelA (anchor t)).val < h | |
| def labelDefects (labelA : A β Fin n) (labelR : R β Fin n) | |
| (anchor : T β A) (role : T β R) (v : Fin n) : Finset T := | |
| Finset.univ.filter fun t => labelA (anchor t) = v β§ labelR (role t) β v | |
| omit [DecidableEq A] in | |
| @[simp] theorem prefixItems_zero (label : A β Fin n) : prefixItems label 0 = β := by | |
| simp [prefixItems] | |
| @[simp] theorem prefixOutside_zero (label : A β Fin n) (f : T β A) : | |
| prefixOutside label f 0 = β := by | |
| simp [prefixOutside] | |
| omit [Fintype A] [Fintype R] [DecidableEq A] [DecidableEq R] in | |
| @[simp] theorem exports_zero (labelA : A β Fin n) (labelR : R β Fin n) | |
| (anchor : T β A) (role : T β R) : exports labelA labelR anchor role 0 = β := by | |
| simp [exports] | |
| omit [DecidableEq A] [DecidableEq R] in | |
| theorem prefix_inventory_eq (labelA : A β Fin n) (labelR : R β Fin n) | |
| (hInv : β v, (Finset.univ.filter fun a => labelA a = v).card = | |
| (Finset.univ.filter fun r => labelR r = v).card) (h : β) : | |
| (prefixItems labelA h).card = (prefixItems labelR h).card := by | |
| let labels : Finset (Fin n) := Finset.univ.filter fun v => v.val < h | |
| have hA := Finset.sum_card_fiberwise_eq_card_filter (Finset.univ : Finset A) | |
| labels labelA | |
| have hR := Finset.sum_card_fiberwise_eq_card_filter (Finset.univ : Finset R) | |
| labels labelR | |
| have hsum : (β v β labels, (Finset.univ.filter fun a => labelA a = v).card) = | |
| β v β labels, (Finset.univ.filter fun r => labelR r = v).card := by | |
| exact Finset.sum_congr rfl fun v _ => hInv v | |
| simpa only [labels, Finset.mem_filter, Finset.mem_univ, true_and, prefixItems] | |
| using hA.symm.trans (hsum.trans hR) | |
| theorem outside_add_selected_eq (label : A β Fin n) (f : T β A) | |
| (hf : Function.Injective f) (h : β) : | |
| (prefixOutside label f h).card + (prefixItems (label β f) h).card = | |
| (prefixItems label h).card := by | |
| have hsplit := Finset.card_sdiff_add_card_inter | |
| (prefixItems label h) (Finset.univ.image f) | |
| have hout : prefixItems label h \ Finset.univ.image f = prefixOutside label f h := by | |
| ext x | |
| simp [prefixItems, prefixOutside, outsideItems, and_comm] | |
| have hin : prefixItems label h β© Finset.univ.image f = | |
| (Finset.univ.image f).filter (fun x => (label x).val < h) := by | |
| ext x | |
| simp [prefixItems, and_comm] | |
| rw [hout, hin, Finset.filter_image, Finset.card_image_of_injective _ hf] at hsplit | |
| simpa only [prefixItems, Function.comp_apply] using hsplit | |
| omit [Fintype A] [Fintype R] [DecidableEq A] [DecidableEq R] in | |
| theorem selected_add_exports_eq (labelA : A β Fin n) (labelR : R β Fin n) | |
| (anchor : T β A) (role : T β R) | |
| (hle : β t, (labelR (role t)).val β€ (labelA (anchor t)).val) (h : β) : | |
| (prefixItems (labelA β anchor) h).card + (exports labelA labelR anchor role h).card = | |
| (prefixItems (labelR β role) h).card := by | |
| have hsplit := Finset.card_filter_add_card_filter_not | |
| (s := prefixItems (labelR β role) h) (fun t => (labelA (anchor t)).val < h) | |
| have hin : (prefixItems (labelR β role) h).filter | |
| (fun t => (labelA (anchor t)).val < h) = prefixItems (labelA β anchor) h := by | |
| ext t | |
| simp only [Finset.mem_filter, prefixItems, Finset.mem_univ, true_and, | |
| Function.comp_apply] | |
| exact β¨fun ht => ht.2, fun ht => β¨lt_of_le_of_lt (hle t) ht, htβ©β© | |
| have hout : (prefixItems (labelR β role) h).filter | |
| (fun t => Β¬ (labelA (anchor t)).val < h) = exports labelA labelR anchor role h := by | |
| ext t | |
| simp [prefixItems, exports] | |
| rw [hin, hout] at hsplit | |
| exact hsplit | |
| theorem exports_add_outsideRole_eq_outsideAnchor | |
| (labelA : A β Fin n) (labelR : R β Fin n) | |
| (anchor : T β A) (role : T β R) | |
| (hAnchor : Function.Injective anchor) (hRole : Function.Injective role) | |
| (hle : β t, (labelR (role t)).val β€ (labelA (anchor t)).val) | |
| (hInv : β v, (Finset.univ.filter fun a => labelA a = v).card = | |
| (Finset.univ.filter fun r => labelR r = v).card) (h : β) : | |
| (exports labelA labelR anchor role h).card + (prefixOutside labelR role h).card = | |
| (prefixOutside labelA anchor h).card := by | |
| have hA := outside_add_selected_eq labelA anchor hAnchor h | |
| have hR := outside_add_selected_eq labelR role hRole h | |
| have hE := selected_add_exports_eq labelA labelR anchor role hle h | |
| have hI := prefix_inventory_eq labelA labelR hInv h | |
| omega | |
| theorem exports_eq_outside_sub | |
| (labelA : A β Fin n) (labelR : R β Fin n) | |
| (anchor : T β A) (role : T β R) | |
| (hAnchor : Function.Injective anchor) (hRole : Function.Injective role) | |
| (hle : β t, (labelR (role t)).val β€ (labelA (anchor t)).val) | |
| (hInv : β v, (Finset.univ.filter fun a => labelA a = v).card = | |
| (Finset.univ.filter fun r => labelR r = v).card) (h : β) : | |
| ((exports labelA labelR anchor role h).card : β€) = | |
| (prefixOutside labelA anchor h).card - (prefixOutside labelR role h).card := by | |
| have hcon := exports_add_outsideRole_eq_outsideAnchor | |
| labelA labelR anchor role hAnchor hRole hle hInv h | |
| omega | |
| theorem exports_card_le_outside | |
| (labelA : A β Fin n) (labelR : R β Fin n) | |
| (anchor : T β A) (role : T β R) | |
| (hAnchor : Function.Injective anchor) (hRole : Function.Injective role) | |
| (hle : β t, (labelR (role t)).val β€ (labelA (anchor t)).val) | |
| (hInv : β v, (Finset.univ.filter fun a => labelA a = v).card = | |
| (Finset.univ.filter fun r => labelR r = v).card) (h : β) : | |
| (exports labelA labelR anchor role h).card β€ (outsideItems anchor).card := by | |
| have hcon := exports_add_outsideRole_eq_outsideAnchor | |
| labelA labelR anchor role hAnchor hRole hle hInv h | |
| have hout : (prefixOutside labelA anchor h).card β€ (outsideItems anchor).card := | |
| Finset.card_le_card (Finset.filter_subset _ _) | |
| omega | |
| omit [Fintype A] [Fintype R] [DecidableEq A] [DecidableEq R] in | |
| theorem labelDefects_subset_exports | |
| (labelA : A β Fin n) (labelR : R β Fin n) | |
| (anchor : T β A) (role : T β R) | |
| (hle : β t, (labelR (role t)).val β€ (labelA (anchor t)).val) (v : Fin n) : | |
| labelDefects labelA labelR anchor role v β exports labelA labelR anchor role v.val := by | |
| intro t ht | |
| obtain β¨ha, hrβ© := (Finset.mem_filter.mp ht).2 | |
| have hl := hle t | |
| rw [ha] at hl | |
| have hn : (labelR (role t)).val β v.val := fun he => hr (Fin.ext he) | |
| apply Finset.mem_filter.mpr | |
| refine β¨Finset.mem_univ _, ?_, ?_β© | |
| Β· omega | |
| Β· simp [ha] | |
| theorem labelDefects_card_le_outside | |
| (labelA : A β Fin n) (labelR : R β Fin n) | |
| (anchor : T β A) (role : T β R) | |
| (hAnchor : Function.Injective anchor) (hRole : Function.Injective role) | |
| (hle : β t, (labelR (role t)).val β€ (labelA (anchor t)).val) | |
| (hInv : β v, (Finset.univ.filter fun a => labelA a = v).card = | |
| (Finset.univ.filter fun r => labelR r = v).card) (v : Fin n) : | |
| (labelDefects labelA labelR anchor role v).card β€ (outsideItems anchor).card := by | |
| exact (Finset.card_le_card (labelDefects_subset_exports labelA labelR anchor role hle v)).trans | |
| (exports_card_le_outside labelA labelR anchor role hAnchor hRole hle hInv v.val) | |
| def badAnchors (labelA : A β Fin n) (labelR : R β Fin n) (labelD : D β Fin n) | |
| (anchor : T β A) (role : T β R) (localRole : T β D) (v : Fin n) : Finset A := | |
| ((outsideItems anchor).filter fun a => labelA a = v) βͺ | |
| (labelDefects labelA labelR anchor role v).image anchor βͺ | |
| (labelDefects labelA labelD anchor localRole v).image anchor | |
| omit [Fintype R] [Fintype D] [DecidableEq R] [DecidableEq D] in | |
| theorem mem_badAnchors_iff | |
| (labelA : A β Fin n) (labelR : R β Fin n) (labelD : D β Fin n) | |
| (anchor : T β A) (role : T β R) (localRole : T β D) | |
| (hAnchor : Function.Injective anchor) (v : Fin n) (a : A) : | |
| a β badAnchors labelA labelR labelD anchor role localRole v β | |
| labelA a = v β§ | |
| Β¬ β t, anchor t = a β§ labelR (role t) = v β§ labelD (localRole t) = v := by | |
| constructor | |
| Β· intro hbad | |
| rcases Finset.mem_union.mp hbad with hleft | hd | |
| Β· rcases Finset.mem_union.mp hleft with ho | hr | |
| Β· obtain β¨hoa, hvβ© := Finset.mem_filter.mp ho | |
| refine β¨hv, ?_β© | |
| rintro β¨t, hat, _, _β© | |
| exact (Finset.mem_sdiff.mp hoa).2 | |
| (Finset.mem_image.mpr β¨t, Finset.mem_univ _, hatβ©) | |
| Β· obtain β¨t, ht, hatβ© := Finset.mem_image.mp hr | |
| obtain β¨hva, hvrβ© := (Finset.mem_filter.mp ht).2 | |
| refine β¨by simpa only [hat] using hva, ?_β© | |
| rintro β¨u, hua, hur, _β© | |
| have htu : t = u := hAnchor (hat.trans hua.symm) | |
| exact hvr (by simpa only [htu] using hur) | |
| Β· obtain β¨t, ht, hatβ© := Finset.mem_image.mp hd | |
| obtain β¨hva, hvdβ© := (Finset.mem_filter.mp ht).2 | |
| refine β¨by simpa only [hat] using hva, ?_β© | |
| rintro β¨u, hua, _, hudβ© | |
| have htu : t = u := hAnchor (hat.trans hua.symm) | |
| exact hvd (by simpa only [htu] using hud) | |
| Β· rintro β¨hv, hnotβ© | |
| by_cases ha : a β Finset.univ.image anchor | |
| Β· obtain β¨t, _, hatβ© := Finset.mem_image.mp ha | |
| have htv : labelA (anchor t) = v := by simpa only [hat] using hv | |
| by_cases hr : labelR (role t) = v | |
| Β· have hd : labelD (localRole t) β v := fun hd => hnot β¨t, hat, hr, hdβ© | |
| apply Finset.mem_union_right | |
| exact Finset.mem_image.mpr β¨t, Finset.mem_filter.mpr | |
| β¨Finset.mem_univ _, htv, hdβ©, hatβ© | |
| Β· apply Finset.mem_union_left | |
| apply Finset.mem_union_right | |
| exact Finset.mem_image.mpr β¨t, Finset.mem_filter.mpr | |
| β¨Finset.mem_univ _, htv, hrβ©, hatβ© | |
| Β· apply Finset.mem_union_left | |
| apply Finset.mem_union_left | |
| exact Finset.mem_filter.mpr | |
| β¨Finset.mem_sdiff.mpr β¨Finset.mem_univ _, haβ©, hvβ© | |
| theorem badAnchors_card_le_three_mul | |
| (labelA : A β Fin n) (labelR : R β Fin n) (labelD : D β Fin n) | |
| (anchor : T β A) (role : T β R) (localRole : T β D) | |
| (hAnchor : Function.Injective anchor) (hRole : Function.Injective role) | |
| (hLocal : Function.Injective localRole) | |
| (hleR : β t, (labelR (role t)).val β€ (labelA (anchor t)).val) | |
| (hleD : β t, (labelD (localRole t)).val β€ (labelA (anchor t)).val) | |
| (hInvR : β v, (Finset.univ.filter fun a => labelA a = v).card = | |
| (Finset.univ.filter fun r => labelR r = v).card) | |
| (hInvD : β v, (Finset.univ.filter fun a => labelA a = v).card = | |
| (Finset.univ.filter fun d => labelD d = v).card) | |
| (K : β) (hOutside : (outsideItems anchor).card β€ K) (v : Fin n) : | |
| (badAnchors labelA labelR labelD anchor role localRole v).card β€ 3 * K := by | |
| have hR := labelDefects_card_le_outside labelA labelR anchor role hAnchor hRole hleR hInvR v | |
| have hD := labelDefects_card_le_outside labelA labelD anchor localRole | |
| hAnchor hLocal hleD hInvD v | |
| have hO : ((outsideItems anchor).filter fun a => labelA a = v).card β€ | |
| (outsideItems anchor).card := Finset.card_le_card (Finset.filter_subset _ _) | |
| have hRi := Finset.card_image_le (s := labelDefects labelA labelR anchor role v) (f := anchor) | |
| have hDi := Finset.card_image_le (s := labelDefects labelA labelD anchor localRole v) | |
| (f := anchor) | |
| have hU := Finset.card_union_le | |
| ((outsideItems anchor).filter fun a => labelA a = v) | |
| ((labelDefects labelA labelR anchor role v).image anchor) | |
| have hV := Finset.card_union_le | |
| (((outsideItems anchor).filter fun a => labelA a = v) βͺ | |
| (labelDefects labelA labelR anchor role v).image anchor) | |
| ((labelDefects labelA labelD anchor localRole v).image anchor) | |
| unfold badAnchors | |
| omega | |
| end LabelConservation | |
| end BinPackingGap | |
| end OAI | |