Download data/lean/OAI/Computability/Scheduling/StateBounds.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 14.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/Scheduling/StateBounds.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/Scheduling/StateBounds.lean
-
curl -L -o StateBounds.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/Scheduling/StateBounds.lean
14.7 kB
| import OAI.Computability.Scheduling.StateCosts | |
| namespace OAI | |
| universe u1 u2 u3 u4 u5 u6 u7 u8 | |
| section | |
| namespace ThreeMachine.Algorithm | |
| theorem tableOf_length {K V : Type} (ks : List K) (f : K β Option V) : | |
| (tableOf ks f).length β€ ks.length := List.length_filterMap_le _ _ | |
| theorem states_length {J : Type} [Fintype J] [DecidableEq J] | |
| (r : J β J β Prop) [DecidableRel r] (fs zs : List (Finset J)) (W : Finset J) : | |
| (states r fs zs W).length β€ fs.length*zs.length := by | |
| calc | |
| _ β€ (fs.flatMap (fun F => zs.map (State.candidate W F))).length := List.length_filter_le _ _ | |
| _ = _ := by simp [List.length_flatMap] | |
| theorem markings_length {J : Type} [DecidableEq J] | |
| (tab : List (Finset J Γ Block J)) (sts : List (State J)) (k : β) : | |
| (markings tab sts k).length β€ sts.length := by | |
| cases k <;> exact tableOf_length _ _ | |
| theorem layers_length {J : Type} [Fintype J] [DecidableEq J] | |
| (r : J β J β Prop) [DecidableRel r] (fs zs : List (Finset J)) (k : β) : | |
| (layers r fs zs k).length β€ fs.length+1 := by | |
| cases k with | |
| | zero => simp [layers] | |
| | succ k => exact (tableOf_length _ _).trans (Nat.le_add_right _ _) | |
| end ThreeMachine.Algorithm | |
| namespace ThreeMachine.StackCompiler | |
| open ThreeMachine.Algorithm | |
| def BlockSmall {n : β} (b : Algorithm.Block (Fin n)) : Prop := | |
| b.length β€ n β§ β v, b.time v β€ n | |
| def TableSmall {n : β} (tab : Table n) : Prop := β W b, (W,b) β tab β BlockSmall b | |
| def MarksSmall {n : β} (marks : Marks n) : Prop := β u b, (u,b) β marks β BlockSmall b | |
| theorem blockSmall_of_good {n : β} {r : Fin n β Fin n β Prop} {W : Finset (Fin n)} | |
| {b : Algorithm.Block (Fin n)} (hg : b.Valid r W) (hb : b.Bounded) : BlockSmall b := | |
| β¨hg.length_le,fun v => (hb v).trans hg.length_leβ© | |
| theorem layers_small {n : β} (r : Fin n β Fin n β Prop) [DecidableRel r] | |
| (fs zs : List (Finset (Fin n))) (k : β) : TableSmall (Algorithm.layers r fs zs k) := | |
| fun W b h => blockSmall_of_good (Algorithm.layers_good r fs zs k W b h) | |
| (Algorithm.layers_bounded r fs zs k W b h) | |
| theorem markings_small {n : β} (r : Fin n β Fin n β Prop) [DecidableRel r] | |
| {tab : Table n} {sts : List (Algorithm.State (Fin n))} {W : Finset (Fin n)} | |
| (ht : Algorithm.TableGood r tab) (hb : Algorithm.TableBounded tab) | |
| (hs : β u β sts, u.Compatible r W) (k : β) : MarksSmall (Algorithm.markings tab sts k) := | |
| fun u b h => blockSmall_of_good ((Algorithm.markings_good r ht hs k u b h).2) | |
| (Algorithm.markings_bounded hb k u b h) | |
| theorem volume_table_le {n : β} (tab : Table n) (ht : TableSmall tab) : | |
| volume tab β€ 1+tab.length*(30*(n+1)^2+1) := by | |
| have h := volume_list_le tab (30*(n+1)^2) (by | |
| rintro β¨W,bβ© h | |
| have hW := volume_finset_le W | |
| have hb := volume_block_le b (ht W b h).1 (ht W b h).2 | |
| rw [volume_pair] | |
| have hp : 1 β€ (n+1)^2 := Nat.one_le_pow _ _ (by omega) | |
| omega) | |
| omega | |
| theorem volume_marks_le {n : β} (ms : Marks n) (ht : MarksSmall ms) : | |
| volume ms β€ 1+ms.length*(30*(n+1)^2+1) := by | |
| have h := volume_list_le ms (30*(n+1)^2) (by | |
| rintro β¨u,bβ© h | |
| have hW := volume_state_le u | |
| have hb := volume_block_le b (ht u b h).1 (ht u b h).2 | |
| rw [volume_pair] | |
| have hp : 1 β€ (n+1)^2 := Nat.one_le_pow _ _ (by omega) | |
| omega) | |
| omega | |
| namespace Poly | |
| variable {J : Type} {s n : J β β} {d l : β} | |
| theorem volumeTable (tab : β j, Table (n j)) (hn : Poly s n d) | |
| (hl : Poly s (fun j => (tab j).length) l) (ht : β j, TableSmall (tab j)) : | |
| Poly s (fun j => volume (tab j)) (l+2*d) := by | |
| apply of_le (fun j => volume_table_le (tab j) (ht j)) | |
| poly_bound | |
| theorem volumeMarks (ms : β j, Marks (n j)) (hn : Poly s n d) | |
| (hl : Poly s (fun j => (ms j).length) l) (ht : β j, MarksSmall (ms j)) : | |
| Poly s (fun j => volume (ms j)) (l+2*d) := by | |
| apply of_le (fun j => volume_marks_le (ms j) (ht j)) | |
| poly_bound | |
| theorem lengthTriples (hn : Poly s n d) : | |
| Poly s (fun j => (Structure.tripleList (List.finRange (n j))).length) (3*d) := by | |
| apply of_le (fun j => Structure.tripleList_length (List.finRange (n j))) | |
| simp only [List.length_finRange] | |
| poly_bound | |
| theorem lengthAlphabet (hn : Poly s n d) : | |
| Poly s (fun j => (Structure.Atomic.alphabet (List.finRange (n j))).length) (3*d) := by | |
| apply of_le (fun j => Structure.Atomic.alphabet_length (List.finRange (n j))) | |
| simp only [Fintype.card_fin,List.length_finRange] | |
| poly_bound | |
| theorem lengthFamily (M : β j, Matrix (n j)) (K : β) (hn : Poly s n d) : | |
| Poly s (fun j => (Structure.effectiveFamily (matrixRel (M j)) | |
| (Structure.jobRank (matrixRel (M j))) (Structure.reverseJobRank (matrixRel (M j))) | |
| (List.finRange (n j)) K).length) (3*K*d) := by | |
| simp only [Structure.effectiveFamily_length] | |
| have h := (lengthAlphabet hn).pow K | |
| convert h.mul (const s (Structure.Formula.templates K).length) using 1; ring | |
| end Poly | |
| end ThreeMachine.StackCompiler | |
| end | |
| section | |
| namespace ThreeMachine.StackCompiler | |
| open Algorithm | |
| theorem volume_block_bound {n : β} (b : Block (Fin n)) (B : β) | |
| (hl : b.length β€ B) (ht : β v, b.time v β€ B) : | |
| volume b β€ 4*(n+1)*(B+1) := by | |
| have h := volume_function_le b.time (2*B+1) (by intro v; rw [volume_nat]; have := ht v; omega) | |
| rw [volume_block,volume_nat] | |
| nlinarith | |
| theorem volume_advance_le {n : β} (v : Algorithm.State (Fin n)) (b c : Block (Fin n)) | |
| (hb : BlockSmall b) (hc : BlockSmall c) : | |
| volume (v.advance b c) β€ 100*(n+2)^2 := by | |
| have hl : (v.advance b c).length β€ 2*n+1 := by | |
| change b.length+1+c.length β€ _ | |
| have := hb.1; have := hc.1; omega | |
| have ht (a : Fin n) : (v.advance b c).time a β€ 2*n+1 := by | |
| simp only [Algorithm.State.advance,Block.append,Block.triple] | |
| have := hb.1; have := hb.2 a; have := hc.2 a | |
| split_ifs <;> omega | |
| have h := volume_block_bound (v.advance b c) (2*n+1) hl ht | |
| nlinarith | |
| namespace Poly | |
| variable {J : Type} {s n : J β β} {d : β} | |
| theorem volumeSmallBlock (b : β j, Block (Fin (n j))) (hn : Poly s n d) | |
| (hb : β j, BlockSmall (b j)) : Poly s (fun j => volume (b j)) (2*d) := by | |
| apply of_le (fun j => volume_block_le (b j) (hb j).1 (hb j).2) | |
| poly_bound | |
| theorem volumeSmallLookup {K : J β Type} [β j, Coding (K j)] [β j, DecidableEq (K j)] | |
| (xs : β j, List (K j Γ Block (Fin (n j)))) (k : β j, K j) | |
| (hn : Poly s n d) (hb : β j a b, (a,b) β xs j β BlockSmall b) : | |
| Poly s (fun j => volume (Algorithm.lookup (xs j) (k j))) (2*d) := by | |
| apply volumeOption _ (show Poly s (fun j => 10*(n j+1)^2) (2*d) from by poly_bound) | |
| intro j b h | |
| exact volume_block_le b (hb j (k j) b (Algorithm.lookup_mem h)).1 | |
| (hb j (k j) b (Algorithm.lookup_mem h)).2 | |
| theorem volumeAdvance (v : β j, Algorithm.State (Fin (n j))) (b c : β j, Block (Fin (n j))) | |
| (hn : Poly s n d) (hb : β j, BlockSmall (b j)) (hc : β j, BlockSmall (c j)) : | |
| Poly s (fun j => volume ((v j).advance (b j) (c j))) (2*d) := by | |
| apply of_le (fun j => volume_advance_le (v j) (b j) (c j) (hb j) (hc j)) | |
| poly_bound | |
| theorem volumeTryAdvance (tab : β j, Table (n j)) (u : β j, Algorithm.State (Fin (n j)) Γ Block (Fin (n j))) | |
| (v : β j, Algorithm.State (Fin (n j))) (hn : Poly s n d) | |
| (ht : β j, TableSmall (tab j)) (hb : β j, BlockSmall (u j).2) : | |
| Poly s (fun j => volume (Algorithm.tryAdvance (tab j) (u j) (v j))) (2*d) := by | |
| apply volumeOption _ (show Poly s (fun j => 100*(n j+2)^2) (2*d) from by poly_bound) | |
| intro j b h | |
| simp only [Algorithm.tryAdvance] at h | |
| split_ifs at h with hp | |
| Β· cases hc : Algorithm.lookup (tab j) ((v j).left \ (u j).1.upto) with | |
| | none => simp [hc] at h | |
| | some c => | |
| have he : (u j).1.advance (u j).2 c = b := by simpa [hc] using h | |
| subst b | |
| exact volume_advance_le _ _ _ (hb j) (ht j _ c (Algorithm.lookup_mem hc)) | |
| Β· simp at h | |
| end Poly | |
| end ThreeMachine.StackCompiler | |
| end | |
| section | |
| namespace ThreeMachine.StackCompiler | |
| namespace Uniform | |
| variable {I : Type u1} {Ξ± : I β Type u2} [β i, Coding (Ξ± i)] | |
| theorem time_append_le (i : I) (xs ys : List (Ξ± i)) : | |
| append.time i (xs,ys) β€ 100000*(xs.length+1)*(volume xs+volume ys+1) := by | |
| have h := time_consFold i xs.reverse ys | |
| have hr := time_reverse i xs | |
| simp only [List.length_reverse,volume_reverse] at h | |
| simp only [append,time_congr,time_comp,time_pair,time_fst,time_snd,volume_prod,Function.comp_apply,volume_reverse] | |
| nlinarith [volume_pos xs,volume_pos ys] | |
| end Uniform | |
| namespace Realizer | |
| variable {Ξ± : Type u3} [Coding Ξ±] | |
| theorem time_zero (x : Ξ±) : (zero : Realizer (fun _ : Ξ± => (0 : β))).time x = 2 := rfl | |
| theorem time_nil (x : Ξ±) : (nil : Realizer (fun _ : Ξ± => ([] : List Ξ±))).time x = 2 := rfl | |
| theorem time_cons (x : Ξ± Γ List Ξ±) : cons.time x = volume x+2 := rfl | |
| theorem time_reverse_le (xs : List Ξ±) : | |
| reverse.time xs β€ 200*(xs.length+1)*(volume xs+1) := | |
| Uniform.time_reverse (I := Unit) (Ξ± := fun _ => Ξ±) () xs | |
| theorem volume_range_le (n : β) : volume (List.range n) β€ 10*(n+1)^2 := by | |
| have h := volume_list_le (List.range n) (2*n+1) (by | |
| intro a ha | |
| rw [volume_nat] | |
| have := List.mem_range.mp ha | |
| omega) | |
| simp only [List.length_range] at h | |
| nlinarith | |
| theorem time_rangeStep_le (j n : β) (hj : j β€ n) : | |
| rangeStep.time (j,(List.range j).reverse) β€ 100000*(n+1)^2 := by | |
| have hv := volume_range_le j | |
| have ht := time_succ_le j | |
| simp only [rangeStep,time_pair,time_comp,time_fst,time_cons,volume_prod,volume_nat, | |
| Function.comp_apply,volume_cons,volume_nat,volume_reverse] | |
| nlinarith | |
| theorem time_range_le (n : β) : range.time n β€ 100000000000*(n+1)^3 := by | |
| have ht := time_iterate_le rangeStep n (0,[]) (100000*(n+1)^2) (20*(n+1)^2) | |
| (fun j hj => by rw [rangeStep_iterate]; exact time_rangeStep_le j n (by omega)) | |
| (fun j hj => by | |
| rw [rangeStep_iterate,volume_prod,volume_nat,volume_reverse] | |
| have := volume_range_le j | |
| nlinarith) | |
| have hr := time_reverse_le (List.range n).reverse | |
| have hv := volume_range_le n | |
| simp only [List.length_reverse,List.length_range,volume_reverse] at hr | |
| simp only [range,time_congr,time_comp,time_pair,time_id,time_zero,time_snd, | |
| Function.comp_apply,rangeStep_iterate,volume_prod,volume_nat,volume_nil,volume_reverse,id_eq] | |
| have hz : (nil : Realizer (fun _ : β => ([] : List β))).time n = 2 := rfl | |
| rw [hz] | |
| nlinarith | |
| end Realizer | |
| namespace Uniform | |
| variable {I : Type u4} {Ξ± : I β Type u5} [β i, Coding (Ξ± i)] | |
| theorem time_orD_le {p q : β i, Ξ± i β Prop} | |
| [β i, DecidablePred (p i)] [β i, DecidablePred (q i)] | |
| (P : Uniform (fun i x => decide (p i x))) (Q : Uniform (fun i x => decide (q i x))) | |
| (i : I) (x : Ξ± i) : (P.orD Q).time i x β€ P.time i x+Q.time i x+20*volume x+11000 := by | |
| rw [orD,time_congr,time_comp,time_pair,time_uniform] | |
| have h := Realizer.time_or_le (decide (p i x),decide (q i x)) | |
| have hp := volume_bool (decide (p i x)); have hq := volume_bool (decide (q i x)) | |
| simp only [volume_pair] at * | |
| omega | |
| end Uniform | |
| end ThreeMachine.StackCompiler | |
| end | |
| section | |
| namespace ThreeMachine.StackCompiler.Poly | |
| variable {I : Type u6} {J : Type u7} {s : J β β} {Ξ± : I β Type u8} [β i, Coding (Ξ± i)] | |
| abbrev IterPool (m : J β β) := Ξ£ j, Fin (m j+1) | |
| theorem iterateTime {f : β i, Ξ± i β Ξ± i} (R : Uniform f) | |
| (idx : J β I) (m : J β β) (a : β j, Ξ± (idx j)) {l t v : β} | |
| (hm : Poly s m l) | |
| (ht : Poly (fun p : IterPool m => s p.1) | |
| (fun p => R.time (idx p.1) ((f (idx p.1))^[p.2.1] (a p.1))) t) | |
| (hv : Poly (fun p : IterPool m => s p.1) | |
| (fun p => volume ((f (idx p.1))^[p.2.1] (a p.1))) v) : | |
| Poly s (fun j => R.iterate.time (idx j) (m j,a j)) (l+Max.max t (Max.max v l)) := by | |
| obtain β¨C,hCβ© := ht | |
| obtain β¨D,hDβ© := hv | |
| have hT := powerBase s C t | |
| have hV := powerBase s D v | |
| apply of_le (fun j => Uniform.time_iterate_le R (idx j) (m j) (a j) | |
| (C*(s j+2)^t) (D*(s j+2)^v) | |
| (fun k hk => hC β¨j,β¨k,by omegaβ©β©) (fun k hk => hD β¨j,β¨k,by omegaβ©β©)) | |
| poly_bound | |
| end ThreeMachine.StackCompiler.Poly | |
| end | |
| section | |
| namespace ThreeMachine.StackCompiler.Poly | |
| variable {J : Type} {s : J β β} {d e : β} {Ξ± Ξ² : J β Type} | |
| variable [β j, Coding (Ξ± j)] [β j, Coding (Ξ² j)] | |
| omit [β j, Coding (Ξ± j)] in | |
| theorem volumeFirstResult (xs : β j, List (Ξ± j)) (f : β j, Ξ± j β Option (Ξ² j)) | |
| (hv : Poly (fun p : ListPool xs => s p.1) (fun p => volume (f p.1 p.2.1)) d) : | |
| Poly s (fun j => volume (Algorithm.firstResult (f j) (xs j))) d := by | |
| obtain β¨C,hCβ© := hv | |
| apply volumeOption _ (powerBase s C d) | |
| intro j b hb | |
| obtain β¨a,ha,hβ© := Algorithm.firstResult_some hb | |
| have ht := hC β¨j,β¨a,haβ©β© | |
| dsimp only at ht | |
| rw [h,volume_some] at ht | |
| omega | |
| omit [β j, Coding (Ξ² j)] in | |
| theorem volumeOptionOr (a b : β j, Option (Ξ± j)) | |
| (ha : Poly s (fun j => volume (a j)) d) (hb : Poly s (fun j => volume (b j)) e) : | |
| Poly s (fun j => volume ((a j).or (b j))) (Max.max d e) := by | |
| apply of_le (g := fun j => Max.max (volume (a j)) (volume (b j))) _ (ha.max hb) | |
| intro j | |
| cases a j <;> simp | |
| end ThreeMachine.StackCompiler.Poly | |
| end | |
| section | |
| namespace ThreeMachine.StackCompiler.Poly | |
| open Algorithm | |
| variable {J : Type} {s n : J β β} {d l : β} | |
| theorem volumeStateList (sts : β j, List (Algorithm.State (Fin (n j)))) | |
| (hn : Poly s n d) (hl : Poly s (fun j => (sts j).length) l) : | |
| Poly s (fun j => volume (sts j)) (l+2*d) := by | |
| apply volumeList hl (show Poly s (fun j => 12*(n j+1)^2) (2*d) from by poly_bound) | |
| intro j a _ha | |
| exact volume_state_le a | |
| theorem volumeSetList (xs : β j, List (Finset (Fin (n j)))) | |
| (hn : Poly s n d) (hl : Poly s (fun j => (xs j).length) l) : | |
| Poly s (fun j => volume (xs j)) (l+2*d) := by | |
| apply volumeList hl (show Poly s (fun j => 3*(n j+1)^2) (2*d) from by poly_bound) | |
| intro j a _ha | |
| exact volume_finset_le a | |
| theorem volumeExpandBody (tab : β j, Table (n j)) (ms : β j, Marks (n j)) | |
| (v : β j, Algorithm.State (Fin (n j))) (hn : Poly s n d) | |
| (ht : β j, TableSmall (tab j)) (hm : β j, MarksSmall (ms j)) : | |
| Poly s (fun j => volume ((Algorithm.lookup (ms j) (v j)).or | |
| (Algorithm.firstResult (fun u => Algorithm.tryAdvance (tab j) u (v j)) (ms j)))) (2*d) := by | |
| have hβ := volumeSmallLookup ms v hn hm | |
| have hβ : Poly s (fun j => volume (Algorithm.firstResult (fun u => Algorithm.tryAdvance (tab j) u (v j)) (ms j))) (2*d) := by | |
| apply volumeFirstResult | |
| exact volumeTryAdvance (fun p : ListPool ms => tab p.1) (fun p => p.2.1) (fun p => v p.1) | |
| (hn.precomp (fun p : ListPool ms => p.1)) (fun p => ht p.1) | |
| (fun p => hm p.1 _ _ p.2.2) | |
| simpa only [Nat.max_self] using volumeOptionOr _ _ hβ hβ | |
| end ThreeMachine.StackCompiler.Poly | |
| end | |
| end OAI | |