Download data/lean/OAI/Computability/Scheduling/GlobalBoundaries.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 25.8 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/Scheduling/GlobalBoundaries.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/Scheduling/GlobalBoundaries.lean
-
curl -L -o GlobalBoundaries.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/Scheduling/GlobalBoundaries.lean
25.8 kB
| import OAI.Computability.Scheduling.SeparatorWalk | |
| namespace OAI | |
| section | |
| namespace ThreeMachine.Structure | |
| def GlobalUpset {J : Type} (r : J β J β Prop) (A : Set J) : Prop := | |
| β β¦x yβ¦, r x y β x β A β y β A | |
| def GlobalDownset {J : Type} (r : J β J β Prop) (A : Set J) : Prop := | |
| β β¦x yβ¦, r x y β y β A β x β A | |
| theorem GlobalUpset.inter {J : Type} {r : J β J β Prop} {A B : Set J} | |
| (hA : GlobalUpset r A) (hB : GlobalUpset r B) : GlobalUpset r (A β© B) := by | |
| intro x y hxy hx | |
| exact β¨hA hxy hx.1, hB hxy hx.2β© | |
| theorem GlobalUpset.union {J : Type} {r : J β J β Prop} {A B : Set J} | |
| (hA : GlobalUpset r A) (hB : GlobalUpset r B) : GlobalUpset r (A βͺ B) := by | |
| intro x y hxy hx | |
| exact hx.elim (fun h => Or.inl (hA hxy h)) (fun h => Or.inr (hB hxy h)) | |
| theorem GlobalDownset.compl {J : Type} {r : J β J β Prop} {A : Set J} | |
| (hA : GlobalDownset r A) : GlobalUpset r AαΆ := by | |
| intro x y hxy hx hy | |
| exact hx (hA hxy hy) | |
| structure GlobalList (J : Type) where | |
| indices : Finset β | |
| entry : β β Set J | |
| namespace GlobalList | |
| variable {J : Type} | |
| def Qual (K : GlobalList J) : Set J := {x | β i β K.indices, x β K.entry i} | |
| def Upsets (K : GlobalList J) (r : J β J β Prop) : Prop := | |
| β i β K.indices, GlobalUpset r (K.entry i) | |
| noncomputable def memberships (K : GlobalList J) (x : J) : Finset β := by | |
| classical | |
| exact K.indices.filter (fun i => x β K.entry i) | |
| noncomputable def lastIndex (K : GlobalList J) (x : J) : β := | |
| (K.memberships x).sup id | |
| def KeyLT (K : GlobalList J) (rank : J β β) (x y : J) : Prop := | |
| K.lastIndex x < K.lastIndex y β¨ | |
| K.lastIndex x = K.lastIndex y β§ rank x < rank y | |
| @[simp] theorem mem_memberships (K : GlobalList J) (x : J) (i : β) : | |
| i β K.memberships x β i β K.indices β§ x β K.entry i := by | |
| classical | |
| simp [memberships] | |
| theorem le_lastIndex {K : GlobalList J} {x : J} {i : β} | |
| (hi : i β K.indices) (hx : x β K.entry i) : i β€ K.lastIndex x := by | |
| exact Finset.le_sup (f := id) ((mem_memberships K x i).mpr β¨hi, hxβ©) | |
| theorem lastIndex_mem {K : GlobalList J} {x : J} (hx : x β K.Qual) : | |
| K.lastIndex x β K.indices β§ x β K.entry (K.lastIndex x) := by | |
| obtain β¨i, hi, hxiβ© := hx | |
| have hne : (K.memberships x).Nonempty := β¨i, (mem_memberships K x i).mpr β¨hi, hxiβ©β© | |
| have := Finset.sup_mem_of_nonempty (f := id) hne | |
| obtain β¨j, hj, eβ© := this | |
| change j = K.lastIndex x at e | |
| apply (mem_memberships K x (K.lastIndex x)).mp | |
| rw [β e] | |
| exact hj | |
| theorem qual_upset {K : GlobalList J} {r : J β J β Prop} | |
| (hK : K.Upsets r) : GlobalUpset r K.Qual := by | |
| rintro x y hxy β¨i, hi, hxβ© | |
| exact β¨i, hi, hK i hi hxy hxβ© | |
| theorem key_extends {K : GlobalList J} {r : J β J β Prop} {rank : J β β} | |
| (hK : K.Upsets r) (hrank : β x y, r x y β rank x < rank y) | |
| {x y : J} (hx : x β K.Qual) (hxy : r x y) : K.KeyLT rank x y := by | |
| obtain β¨hi, hxlastβ© := lastIndex_mem hx | |
| have hle : K.lastIndex x β€ K.lastIndex y := le_lastIndex hi (hK _ hi hxy hxlast) | |
| rcases hle.lt_or_eq with h | h | |
| Β· exact Or.inl h | |
| Β· exact Or.inr β¨h, hrank x y hxyβ© | |
| noncomputable def carry (K : GlobalList J) (rank : J β β) (d r : β) : GlobalList J := by | |
| classical | |
| exact β¨K.indices.filter (d β€ Β·), fun i => | |
| if i = d then K.entry i β© {x | r β€ rank x} else K.entry iβ© | |
| theorem carry_membership (K : GlobalList J) (rank : J β β) (d r i : β) (x : J) : | |
| i β (K.carry rank d r).memberships x β | |
| i β K.indices β§ d β€ i β§ x β K.entry i β§ (i = d β r β€ rank x) := by | |
| classical | |
| rw [mem_memberships] | |
| change (i β K.indices.filter (d β€ Β·) β§ | |
| x β (if i = d then K.entry i β© {x | r β€ rank x} else K.entry i)) β _ | |
| rw [Finset.mem_filter] | |
| by_cases hi : i = d <;> simp [hi, and_assoc] | |
| theorem carry_selection (K : GlobalList J) (rank : J β β) (d r : β) (x : J) : | |
| x β (K.carry rank d r).Qual β x β K.Qual β§ | |
| (d < K.lastIndex x β¨ K.lastIndex x = d β§ r β€ rank x) := by | |
| constructor | |
| Β· rintro β¨i, hi, hxβ© | |
| have hc := (carry_membership K rank d r i x).mp | |
| ((mem_memberships _ _ _).mpr β¨hi, hxβ©) | |
| refine β¨β¨i, hc.1, hc.2.2.1β©, ?_β© | |
| have hle := le_lastIndex hc.1 hc.2.2.1 | |
| by_cases h : d < K.lastIndex x | |
| Β· exact Or.inl h | |
| Β· have hid : i = d := by omega | |
| exact Or.inr β¨by omega, hc.2.2.2 hidβ© | |
| Β· rintro β¨hq, hmaxβ© | |
| obtain β¨hi, hxβ© := lastIndex_mem hq | |
| refine β¨K.lastIndex x, ?_β© | |
| apply (mem_memberships _ _ _).mp | |
| apply (carry_membership K rank d r _ x).mpr | |
| refine β¨hi, ?_, hx, ?_β© | |
| Β· rcases hmax with h | β¨h, _β© <;> omega | |
| Β· intro e | |
| rcases hmax with h | β¨_, hrβ© | |
| Β· omega | |
| Β· exact hr | |
| theorem carry_lastIndex {K : GlobalList J} {rank : J β β} {d r : β} {x : J} | |
| (hx : x β (K.carry rank d r).Qual) : | |
| (K.carry rank d r).lastIndex x = K.lastIndex x := by | |
| have hsel := (carry_selection K rank d r x).mp hx | |
| apply le_antisymm | |
| Β· apply Finset.sup_le | |
| intro i hi | |
| have hm := (carry_membership K rank d r i x).mp hi | |
| exact le_lastIndex hm.1 hm.2.2.1 | |
| Β· obtain β¨hi, hxiβ© := lastIndex_mem hsel.1 | |
| apply Finset.le_sup (f := id) (b := K.lastIndex x) | |
| apply (carry_membership K rank d r (K.lastIndex x) x).mpr | |
| refine β¨hi, ?_, hxi, ?_β© | |
| Β· rcases hsel.2 with h | β¨h, _β© <;> omega | |
| Β· intro e | |
| rcases hsel.2 with h | β¨_, hrβ© | |
| Β· omega | |
| Β· exact hr | |
| theorem carry_key {K : GlobalList J} {rank : J β β} {d r : β} {x y : J} | |
| (hx : x β (K.carry rank d r).Qual) (hy : y β (K.carry rank d r).Qual) : | |
| (K.carry rank d r).KeyLT rank x y β K.KeyLT rank x y := by | |
| simp only [KeyLT, carry_lastIndex hx, carry_lastIndex hy] | |
| theorem carry_upsets {K : GlobalList J} {rank : J β β} {d t : β} | |
| {r : J β J β Prop} (hK : K.Upsets r) | |
| (hrank : β x y, r x y β rank x < rank y) : (K.carry rank d t).Upsets r := by | |
| classical | |
| intro i hi x y hxy hx | |
| have hi' : i β K.indices β§ d β€ i := by simpa [carry] using hi | |
| by_cases hid : i = d | |
| Β· have hx' : x β K.entry i β§ t β€ rank x := by simpa [carry, hid] using hx | |
| have hrankxy := hrank x y hxy | |
| have hy : y β K.entry i := hK i hi'.1 hxy hx'.1 | |
| simpa [carry, hid] using And.intro hy (show t β€ rank y by omega) | |
| Β· have hx' : x β K.entry i := by simpa [carry, hid] using hx | |
| simpa [carry, hid] using hK i hi'.1 hxy hx' | |
| noncomputable def prune (K : GlobalList J) (W : Set J) : GlobalList J := by | |
| classical | |
| exact β¨K.indices.filter (fun i => (K.entry i β© W).Nonempty), K.entryβ© | |
| theorem prune_membership (K : GlobalList J) (W : Set J) (i : β) (x : J) : | |
| i β (K.prune W).memberships x β | |
| i β K.indices β§ (K.entry i β© W).Nonempty β§ x β K.entry i := by | |
| classical | |
| rw [mem_memberships] | |
| change (i β K.indices.filter (fun j => (K.entry j β© W).Nonempty) β§ | |
| x β K.entry i) β _ | |
| rw [Finset.mem_filter] | |
| exact and_assoc | |
| theorem prune_qual_subset (K : GlobalList J) (W : Set J) : (K.prune W).Qual β K.Qual := by | |
| rintro x β¨i, hi, hxβ© | |
| have hm := (prune_membership K W i x).mp ((mem_memberships _ _ _).mpr β¨hi, hxβ©) | |
| exact β¨i, hm.1, hm.2.2β© | |
| theorem prune_qual (K : GlobalList J) {W : Set J} {x : J} (hx : x β W) : | |
| x β (K.prune W).Qual β x β K.Qual := by | |
| refine β¨fun h => prune_qual_subset K W h, ?_β© | |
| rintro β¨i, hi, hxiβ© | |
| refine β¨i, ?_β© | |
| apply (mem_memberships _ _ _).mp | |
| exact (prune_membership K W i x).mpr β¨hi, β¨x, hxi, hxβ©, hxiβ© | |
| theorem prune_lastIndex_le (K : GlobalList J) (W : Set J) (x : J) : | |
| (K.prune W).lastIndex x β€ K.lastIndex x := by | |
| apply Finset.sup_le | |
| intro i hi | |
| have hm := (prune_membership K W i x).mp hi | |
| exact le_lastIndex hm.1 hm.2.2 | |
| theorem prune_lastIndex (K : GlobalList J) {W : Set J} {x : J} (hx : x β W) : | |
| (K.prune W).lastIndex x = K.lastIndex x := by | |
| apply le_antisymm (prune_lastIndex_le K W x) | |
| apply Finset.sup_le | |
| intro i hi | |
| have hm := (mem_memberships K x i).mp hi | |
| apply Finset.le_sup (f := id) | |
| exact (prune_membership K W i x).mpr β¨hm.1, β¨x, hm.2, hxβ©, hm.2β© | |
| theorem prune_key {K : GlobalList J} {W : Set J} {rank : J β β} {x y : J} | |
| (hx : x β W) (hkey : (K.prune W).KeyLT rank x y) : K.KeyLT rank x y := by | |
| have heq := prune_lastIndex K hx | |
| have hle := prune_lastIndex_le K W y | |
| rcases hkey with h | β¨h, hrβ© | |
| Β· exact Or.inl (by omega) | |
| Β· by_cases hlt : K.lastIndex x < K.lastIndex y | |
| Β· exact Or.inl hlt | |
| Β· exact Or.inr β¨by omega, hrβ© | |
| theorem prune_upsets {K : GlobalList J} {W : Set J} {r : J β J β Prop} | |
| (hK : K.Upsets r) : (K.prune W).Upsets r := by | |
| classical | |
| intro i hi | |
| have hi' : i β K.indices β§ (K.entry i β© W).Nonempty := by simpa [prune] using hi | |
| exact hK i hi'.1 | |
| end GlobalList | |
| end ThreeMachine.Structure | |
| namespace ThreeMachine.Structure | |
| section IntervalNormalization | |
| variable {J : Type} [Fintype J] | |
| def Layout.FixedOutside (p q : Layout J) (W : Set J) : Prop := | |
| β x, x β W β q x = p x | |
| theorem Layout.FixedOutside.refl (p : Layout J) (W : Set J) : p.FixedOutside p W := | |
| fun _ _ => rfl | |
| theorem Layout.FixedOutside.trans {p q u : Layout J} {W : Set J} | |
| (hpq : p.FixedOutside q W) (hqu : q.FixedOutside u W) : p.FixedOutside u W := | |
| fun x hx => (hqu x hx).trans (hpq x hx) | |
| theorem Layout.FixedOutside.mono {p q : Layout J} {W U : Set J} | |
| (h : p.FixedOutside q W) (hWU : W β U) : p.FixedOutside q U := | |
| fun x hx => h x (fun hW => hx (hWU hW)) | |
| theorem Layout.FixedOutside.time {p q : Layout J} {W : Set J} | |
| (h : p.FixedOutside q W) {x : J} (hx : x β W) : q.time x = p.time x := by | |
| simp [Layout.time, h x hx] | |
| theorem Layout.FixedOutside.symm_position {p q : Layout J} {W : Set J} | |
| (h : p.FixedOutside q W) (i : Fin (Fintype.card J)) (hi : p.symm i β W) : | |
| q.symm i = p.symm i := by | |
| apply q.injective | |
| rw [q.apply_symm_apply, h _ hi, p.apply_symm_apply] | |
| theorem Layout.FixedOutside.position_mem {p q : Layout J} {W : Set J} | |
| (h : p.FixedOutside q W) {x : J} (hx : x β W) : p.symm (q x) β W := by | |
| by_contra hn | |
| have he : q (p.symm (q x)) = q x := by rw [h _ hn, p.apply_symm_apply] | |
| apply hn | |
| rw [q.injective he] | |
| exact hx | |
| theorem Layout.FixedOutside.time_range {p q : Layout J} {W : Set J} {a b : β} | |
| (h : p.FixedOutside q W) (hW : β x β W, a < p.time x β§ p.time x < b) | |
| {x : J} (hx : x β W) : a < q.time x β§ q.time x < b := by | |
| have hr := hW _ (h.position_mem hx) | |
| simpa [Layout.time] using hr | |
| theorem reorder_respects {p q : Layout J} {W : Set J} {a b : β} | |
| {r : J β J β Prop} (hp : p.Respects r) (hfix : p.FixedOutside q W) | |
| (hW : β x, x β W β a < p.time x β§ p.time x < b) | |
| (hq : β x β W, β y β W, r x y β q.time x < q.time y) : q.Respects r := by | |
| intro x y hxy | |
| have ht := hp x y hxy | |
| by_cases hx : x β W | |
| Β· by_cases hy : y β W | |
| Β· exact hq x hx y hy hxy | |
| Β· have hxt := hfix.time_range (fun z hz => (hW z).mp hz) hx | |
| have hxp := (hW x).mp hx | |
| have hyp : Β¬(a < p.time y β§ p.time y < b) := fun h => hy ((hW y).mpr h) | |
| rw [hfix.time hy] | |
| omega | |
| Β· rw [hfix.time hx] | |
| by_cases hy : y β W | |
| Β· have hyt := hfix.time_range (fun z hz => (hW z).mp hz) hy | |
| have hyp := (hW y).mp hy | |
| have hxp : Β¬(a < p.time x β§ p.time x < b) := fun h => hx ((hW x).mpr h) | |
| omega | |
| Β· rw [hfix.time hy] | |
| exact ht | |
| def Layout.NormalizedOn (p : Layout J) (W : Set J) | |
| (r : J β J β Prop) (priority : J β β) : Prop := | |
| p.Respects r β§ β q : Layout J, q.Respects r β p.FixedOutside q W β | |
| p.signature priority β€ q.signature priority | |
| theorem exists_normalizedOn (p : Layout J) (W : Set J) (r : J β J β Prop) | |
| (priority : J β β) (hp : p.Respects r) : | |
| β q : Layout J, p.FixedOutside q W β§ q.NormalizedOn W r priority := by | |
| classical | |
| let candidates : Finset (Layout J) := Finset.univ.filter | |
| (fun q => q.Respects r β§ p.FixedOutside q W) | |
| have hne : candidates.Nonempty := β¨p, by simp [candidates, hp, Layout.FixedOutside.refl]β© | |
| obtain β¨q, hq, hminβ© := candidates.exists_min_image (fun q => q.signature priority) hne | |
| have hq' : q.Respects r β§ p.FixedOutside q W := by simpa [candidates] using hq | |
| refine β¨q, hq'.2, hq'.1, ?_β© | |
| intro u hu hqu | |
| exact hmin u (by simp [candidates, hu, hq'.2.trans hqu]) | |
| theorem normalizedOn_no_improvement {p q : Layout J} {W : Set J} | |
| {r : J β J β Prop} {priority : J β β} (hp : p.NormalizedOn W r priority) | |
| (hq : q.Respects r) (hfix : p.FixedOutside q W) | |
| (i : Fin (Fintype.card J)) | |
| (hbefore : β j, j < i β priority (q.symm j) = priority (p.symm j)) | |
| (hi : priority (q.symm i) < priority (p.symm i)) : False := by | |
| have hlt : q.signature priority < p.signature priority := | |
| ofFn_lt_of_first_difference _ _ i hbefore hi | |
| exact (not_lt_of_ge (hp.2 q hq hfix)) hlt | |
| theorem exchange_fixedOutside [DecidableEq J] {p : Layout J} {W : Set J} | |
| {x y : J} (hx : x β W) (hy : y β W) : p.FixedOutside (p.exchange x y) W := by | |
| intro z hz | |
| have hzx : z β x := fun e => hz (e βΈ hx) | |
| have hzy : z β y := fun e => hz (e βΈ hy) | |
| simp [Layout.exchange, Equiv.swap_apply_of_ne_of_ne hzx hzy] | |
| theorem normalizedOn_prefix_no_exchange [DecidableEq J] | |
| {p q : Layout J} {W : Set J} {r : J β J β Prop} {priority : J β β} | |
| (hp : p.NormalizedOn W r priority) (hfix : p.FixedOutside q W) | |
| {x y : J} (hx : x β W) (hy : y β W) | |
| (hprefix : β j, j β€ p y β q.symm j = p.symm j) | |
| (ht : q.time y < q.time x) (hbetter : priority x < priority y) | |
| (hswap : (q.exchange x y).Respects r) : False := by | |
| have hqy : q y = p y := by | |
| have he := hprefix (p y) le_rfl | |
| simp only [p.symm_apply_apply] at he | |
| exact (congrArg q he).symm.trans (q.apply_symm_apply _) | |
| have hpos : p y < q x := by | |
| change (p y).val < (q x).val | |
| dsimp [Layout.time] at ht | |
| rw [hqy] at ht | |
| omega | |
| apply normalizedOn_no_improvement hp hswap | |
| (hfix.trans (exchange_fixedOutside hx hy)) (p y) | |
| Β· intro j hj | |
| have hpy := hprefix j hj.le | |
| have hny : q.symm j β y := by | |
| intro e | |
| have he : j = p y := by simpa [hqy] using congrArg q e | |
| exact (ne_of_lt hj) he | |
| have hnx : q.symm j β x := by | |
| intro e | |
| have he : j = q x := by simpa using congrArg q e | |
| rw [he] at hj | |
| exact (not_lt_of_ge hpos.le) hj | |
| change priority ((Equiv.swap x y) (q.symm j)) = priority (p.symm j) | |
| rw [Equiv.swap_apply_of_ne_of_ne hnx hny, hpy] | |
| Β· have hpy := hprefix (p y) le_rfl | |
| simp only [p.symm_apply_apply] at hpy | |
| simpa [Layout.exchange, hpy] using hbetter | |
| theorem normalizedOn_local_obstruction {p : Layout J} {W : Finset J} | |
| {a b : β} {r : J β J β Prop} {priority : J β β} | |
| (hp : p.NormalizedOn (W : Set J) r priority) | |
| (hW : β z, z β W β a < p.time z β§ p.time z < b) : | |
| LocalObstruction W r p.time priority := by | |
| classical | |
| intro x hx y hy htyx hbetter hpred | |
| by_contra hn | |
| have hsucc : β v, r y v β p.time x < p.time v := by | |
| intro v hyv | |
| have hyvTime := hp.1 y v hyv | |
| by_cases hv : v β W | |
| Β· by_contra h | |
| exact hn β¨v, hv, hyv, by omegaβ© | |
| Β· have hnt : Β¬(a < p.time v β§ p.time v < b) := fun h => hv ((hW v).mpr h) | |
| have hxt := (hW x).mp hx | |
| have hyt := (hW y).mp hy | |
| omega | |
| have hready : β u, r u x β p.time u < p.time y := by | |
| intro u hux | |
| by_cases hu : u β W | |
| Β· exact hpred u hu hux | |
| Β· have huxTime := hp.1 u x hux | |
| have hnt : Β¬(a < p.time u β§ p.time u < b) := fun h => hu ((hW u).mpr h) | |
| have hxt := (hW x).mp hx | |
| have hyt := (hW y).mp hy | |
| omega | |
| exact normalizedOn_prefix_no_exchange hp (Layout.FixedOutside.refl p _) | |
| hx hy (fun _ _ => rfl) htyx hbetter (respects_exchange hp.1 x y htyx hready hsucc) | |
| end IntervalNormalization | |
| end ThreeMachine.Structure | |
| namespace ThreeMachine.Structure | |
| abbrev Triple (J : Type) := {Z : Finset J // Z.card = 3} | |
| inductive Boundary (J : Type) | |
| | left | |
| | actual (Z : Triple J) | |
| | right | |
| namespace Boundary | |
| variable {J : Type} | |
| def pred (r : J β J β Prop) : Boundary J β Set J | |
| | .left => β | |
| | .actual Z => {x | β y β Z.val, r x y} | |
| | .right => Set.univ | |
| def desc (r : J β J β Prop) : Boundary J β Set J | |
| | .left => Set.univ | |
| | .actual Z => {x | β y β Z.val, r y x} | |
| | .right => β | |
| def weakPred (r : J β J β Prop) : Boundary J β Set J | |
| | .left => β | |
| | .actual Z => pred r (.actual Z) βͺ (Z.val : Set J) | |
| | .right => Set.univ | |
| def weakDesc (r : J β J β Prop) : Boundary J β Set J | |
| | .left => Set.univ | |
| | .actual Z => desc r (.actual Z) βͺ (Z.val : Set J) | |
| | .right => β | |
| def reverse : Boundary J β Boundary J | |
| | .left => .right | |
| | .actual Z => .actual Z | |
| | .right => .left | |
| @[simp] theorem reverse_reverse (B : Boundary J) : B.reverse.reverse = B := by cases B <;> rfl | |
| @[simp] theorem pred_reverse (r : J β J β Prop) (B : Boundary J) : | |
| B.reverse.pred (fun x y => r y x) = B.desc r := by cases B <;> rfl | |
| @[simp] theorem desc_reverse (r : J β J β Prop) (B : Boundary J) : | |
| B.reverse.desc (fun x y => r y x) = B.pred r := by cases B <;> rfl | |
| @[simp] theorem weakPred_reverse (r : J β J β Prop) (B : Boundary J) : | |
| B.reverse.weakPred (fun x y => r y x) = B.weakDesc r := by cases B <;> rfl | |
| @[simp] theorem weakDesc_reverse (r : J β J β Prop) (B : Boundary J) : | |
| B.reverse.weakDesc (fun x y => r y x) = B.weakPred r := by cases B <;> rfl | |
| theorem pred_downset {r : J β J β Prop} | |
| (htrans : β β¦a b cβ¦, r a b β r b c β r a c) (B : Boundary J) : | |
| GlobalDownset r (B.pred r) := by | |
| intro x y hxy hy | |
| cases B with | |
| | left => exact hy.elim | |
| | right => trivial | |
| | actual Z => | |
| obtain β¨z, hz, hyzβ© := hy | |
| exact β¨z, hz, htrans hxy hyzβ© | |
| theorem desc_upset {r : J β J β Prop} | |
| (htrans : β β¦a b cβ¦, r a b β r b c β r a c) (B : Boundary J) : | |
| GlobalUpset r (B.desc r) := by | |
| intro x y hxy hx | |
| cases B with | |
| | left => trivial | |
| | right => exact hx.elim | |
| | actual Z => | |
| obtain β¨z, hz, hzxβ© := hx | |
| exact β¨z, hz, htrans hzx hxyβ© | |
| theorem weakPred_downset {r : J β J β Prop} | |
| (htrans : β β¦a b cβ¦, r a b β r b c β r a c) (B : Boundary J) : | |
| GlobalDownset r (B.weakPred r) := by | |
| intro x y hxy hy | |
| cases B with | |
| | left => exact hy.elim | |
| | right => trivial | |
| | actual Z => | |
| rcases hy with h | h | |
| Β· exact Or.inl (pred_downset htrans (.actual Z) hxy h) | |
| Β· exact Or.inl β¨y, h, hxyβ© | |
| theorem weakDesc_upset {r : J β J β Prop} | |
| (htrans : β β¦a b cβ¦, r a b β r b c β r a c) (B : Boundary J) : | |
| GlobalUpset r (B.weakDesc r) := by | |
| intro x y hxy hx | |
| cases B with | |
| | left => trivial | |
| | right => exact hx.elim | |
| | actual Z => | |
| rcases hx with h | h | |
| Β· exact Or.inl (desc_upset htrans (.actual Z) hxy h) | |
| Β· exact Or.inl β¨x, h, hxyβ© | |
| def At (time : J β β) (T : β) : Boundary J β β β Prop | |
| | .left, s => s = 0 | |
| | .actual Z, s => 1 β€ s β§ s β€ T β§ β x, x β Z.val β time x = s | |
| | .right, s => s = T + 1 | |
| theorem pred_time {r : J β J β Prop} {time : J β β} {T s : β} {B : Boundary J} | |
| (hrespect : β u v, r u v β time u < time v) | |
| (hbound : β x, 1 β€ time x β§ time x β€ T) (hB : B.At time T s) | |
| {x : J} (hx : x β B.pred r) : time x < s := by | |
| cases B with | |
| | left => exact hx.elim | |
| | right => have := (hbound x).2; dsimp [At] at hB; omega | |
| | actual Z => | |
| obtain β¨y, hy, hxyβ© := hx | |
| have he := (hB.2.2 y).mp hy | |
| have := hrespect x y hxy | |
| omega | |
| theorem desc_time {r : J β J β Prop} {time : J β β} {T s : β} {B : Boundary J} | |
| (hrespect : β u v, r u v β time u < time v) | |
| (hbound : β x, 1 β€ time x β§ time x β€ T) (hB : B.At time T s) | |
| {x : J} (hx : x β B.desc r) : s < time x := by | |
| cases B with | |
| | left => have := (hbound x).1; dsimp [At] at hB; omega | |
| | right => exact hx.elim | |
| | actual Z => | |
| obtain β¨y, hy, hyxβ© := hx | |
| have he := (hB.2.2 y).mp hy | |
| have := hrespect y x hyx | |
| omega | |
| theorem weakPred_time {r : J β J β Prop} {time : J β β} {T s : β} {B : Boundary J} | |
| (hrespect : β u v, r u v β time u < time v) | |
| (hbound : β x, 1 β€ time x β§ time x β€ T) (hB : B.At time T s) | |
| {x : J} (hx : x β B.weakPred r) : time x β€ s := by | |
| cases B with | |
| | left => exact hx.elim | |
| | right => have := (hbound x).2; dsimp [At] at hB; omega | |
| | actual Z => | |
| rcases hx with h | h | |
| Β· exact (pred_time hrespect hbound hB h).le | |
| Β· exact ((hB.2.2 x).mp h).le | |
| theorem weakDesc_time {r : J β J β Prop} {time : J β β} {T s : β} {B : Boundary J} | |
| (hrespect : β u v, r u v β time u < time v) | |
| (hbound : β x, 1 β€ time x β§ time x β€ T) (hB : B.At time T s) | |
| {x : J} (hx : x β B.weakDesc r) : s β€ time x := by | |
| cases B with | |
| | left => dsimp [At] at hB; omega | |
| | right => exact hx.elim | |
| | actual Z => | |
| rcases hx with h | h | |
| Β· exact (desc_time hrespect hbound hB h).le | |
| Β· exact ((hB.2.2 x).mp h).ge | |
| theorem mem_weak_at_time {r : J β J β Prop} {time : J β β} {T s : β} {B : Boundary J} | |
| (hbound : β x, 1 β€ time x β§ time x β€ T) (hB : B.At time T s) | |
| {x : J} (hx : time x = s) : x β B.weakPred r β§ x β B.weakDesc r := by | |
| cases B with | |
| | left => have := (hbound x).1; dsimp [At] at hB; omega | |
| | right => have := (hbound x).2; dsimp [At] at hB; omega | |
| | actual Z => exact β¨Or.inr ((hB.2.2 x).mpr hx), Or.inr ((hB.2.2 x).mpr hx)β© | |
| theorem actual_pred_eq {r : J β J β Prop} {time : J β β} {T s : β} {Z : Triple J} | |
| (hZ : (Boundary.actual Z).At time T s) : | |
| (Boundary.actual Z).pred r = PredAt r time s := by | |
| ext x | |
| simp only [pred, PredAt, Set.mem_ofPred_eq, hZ.2.2] | |
| theorem actual_desc_eq {r : J β J β Prop} {time : J β β} {T s : β} {Z : Triple J} | |
| (hZ : (Boundary.actual Z).At time T s) : | |
| (Boundary.actual Z).desc r = DescAt r time s := by | |
| ext x | |
| simp only [desc, DescAt, Set.mem_ofPred_eq, hZ.2.2] | |
| end Boundary | |
| inductive Formula (A : Type) | |
| | leaf (atom : A) (negative : Bool) | |
| | conj (p q : Formula A) | |
| | disj (p q : Formula A) | |
| namespace Formula | |
| variable {A J : Type} | |
| def leaves : Formula A β β | |
| | .leaf _ _ => 1 | |
| | .conj p q | .disj p q => p.leaves + q.leaves | |
| def eval (atoms : A β Set J) : Formula A β Set J | |
| | .leaf a false => atoms a | |
| | .leaf a true => (atoms a)αΆ | |
| | .conj p q => p.eval atoms β© q.eval atoms | |
| | .disj p q => p.eval atoms βͺ q.eval atoms | |
| def negate : Formula A β Formula A | |
| | .leaf a b => .leaf a (!b) | |
| | .conj p q => .disj p.negate q.negate | |
| | .disj p q => .conj p.negate q.negate | |
| @[simp] theorem leaves_negate (p : Formula A) : p.negate.leaves = p.leaves := by | |
| induction p with | |
| | leaf a b => cases b <;> rfl | |
| | conj p q hp hq | disj p q hp hq => simp [negate, leaves, hp, hq] | |
| @[simp] theorem eval_negate (atoms : A β Set J) (p : Formula A) : | |
| p.negate.eval atoms = (p.eval atoms)αΆ := by | |
| induction p with | |
| | leaf a b => cases b <;> simp [negate, eval] | |
| | conj p q hp hq => | |
| ext x | |
| simp only [negate, eval, hp, hq, Set.mem_union, Set.mem_compl_iff, Set.mem_inter_iff] | |
| tauto | |
| | disj p q hp hq => simp [negate, eval, hp, hq] | |
| theorem leaves_pos (p : Formula A) : 0 < p.leaves := by | |
| induction p with | |
| | leaf => exact Nat.zero_lt_one | |
| | conj p q hp hq | disj p q hp hq => dsimp [leaves]; omega | |
| end Formula | |
| def Described {A J : Type} (atoms : A β Set J) (W : Set J) (k : β) : Prop := | |
| β p : Formula A, p.eval atoms = W β§ p.leaves β€ k | |
| namespace Described | |
| variable {A J : Type} {atoms : A β Set J} {W U : Set J} {k l : β} | |
| theorem mono (h : Described atoms W k) (hkl : k β€ l) : Described atoms W l := by | |
| obtain β¨p, hp, hkβ© := h | |
| exact β¨p, hp, hk.trans hklβ© | |
| theorem atom (a : A) : Described atoms (atoms a) 1 := β¨.leaf a false, rfl, le_rflβ© | |
| theorem compl (h : Described atoms W k) : Described atoms WαΆ k := by | |
| obtain β¨p, hp, hkβ© := h | |
| exact β¨p.negate, by simp [hp], by simpa using hkβ© | |
| theorem inter (hW : Described atoms W k) (hU : Described atoms U l) : | |
| Described atoms (W β© U) (k + l) := by | |
| obtain β¨p, hp, hkβ© := hW | |
| obtain β¨q, hq, hlβ© := hU | |
| exact β¨.conj p q, by simp [Formula.eval, hp, hq], Nat.add_le_add hk hlβ© | |
| theorem union (hW : Described atoms W k) (hU : Described atoms U l) : | |
| Described atoms (W βͺ U) (k + l) := by | |
| obtain β¨p, hp, hkβ© := hW | |
| obtain β¨q, hq, hlβ© := hU | |
| exact β¨.disj p q, by simp [Formula.eval, hp, hq], Nat.add_le_add hk hlβ© | |
| theorem diff (hW : Described atoms W k) (hU : Described atoms U l) : | |
| Described atoms (W \ U) (k + l) := hW.inter hU.compl | |
| theorem finite_union {ΞΉ : Type} (s : Finset ΞΉ) (E : ΞΉ β Set J) (b : ΞΉ β β) | |
| (hne : s.Nonempty) (hE : β i β s, Described atoms (E i) (b i)) : | |
| Described atoms {x | β i β s, x β E i} (β i β s, b i) := by | |
| classical | |
| induction s using Finset.induction_on with | |
| | empty => exact (Finset.not_nonempty_empty hne).elim | |
| | @insert i s hi ih => | |
| by_cases hs : s.Nonempty | |
| Β· have hrest := ih hs (fun j hj => hE j (Finset.mem_insert_of_mem hj)) | |
| have hfirst := hE i (Finset.mem_insert_self _ _) | |
| have he : {x | β j β insert i s, x β E j} = E i βͺ {x | β j β s, x β E j} := by | |
| ext x | |
| simp only [Set.mem_ofPred_eq, Finset.mem_insert, Set.mem_union] | |
| aesop | |
| rw [he, Finset.sum_insert hi] | |
| exact hfirst.union hrest | |
| Β· have es : s = β := Finset.not_nonempty_iff_eq_empty.mp hs | |
| subst s | |
| simpa using hE i (Finset.mem_insert_self i β ) | |
| end Described | |
| end ThreeMachine.Structure | |
| end | |
| end OAI | |