Download data/lean/OAI/Computability/Scheduling/EncodingCosts.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.97 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/Scheduling/EncodingCosts.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/Scheduling/EncodingCosts.lean
-
curl -L -o EncodingCosts.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/Scheduling/EncodingCosts.lean
8.97 kB
| import OAI.Computability.Scheduling.BinaryCosts | |
| namespace OAI | |
| universe u1 | |
| section | |
| namespace ThreeMachine.StackCompiler.Binary | |
| variable {Ξ± : Type u1} | |
| theorem readStep_prefix {encode : Ξ± β List Bool} {reader : List Bool β Ξ± Γ List Bool} | |
| (hr : β a rest, reader (encode a ++ rest) = (a,rest)) | |
| (xs : List Ξ±) (rest : List Bool) (acc : List Ξ±) (k : β) (hk : k β€ xs.length) : | |
| (readStep reader)^[k] (xs.flatMap encode ++ rest,acc) = | |
| ((xs.drop k).flatMap encode ++ rest,(xs.take k).reverse ++ acc) := by | |
| have h := readStep_iterate hr (xs.take k) ((xs.drop k).flatMap encode ++ rest) acc | |
| rw [List.length_take,Nat.min_eq_left hk] at h | |
| rw [β List.append_assoc,β List.flatMap_append,List.take_append_drop] at h | |
| exact h | |
| theorem readNat_rest_length (bs : List Bool) : (readNat bs).2.length β€ bs.length := by | |
| exact (List.drop_sublist _ _).length_le.trans (List.drop_sublist _ _).length_le | |
| theorem readEdge_rest_length (bs : List Bool) : (readEdge bs).2.length β€ bs.length := | |
| (readNat_rest_length _).trans (readNat_rest_length _) | |
| theorem increment_length (bs : List Bool) : (increment bs).length β€ bs.length+1 := by | |
| induction bs with | |
| | nil => simp [increment] | |
| | cons b bs ih => cases b <;> simp only [increment,List.length_cons] <;> omega | |
| theorem encodeNat_length (n : β) : (Computability.encodeNat n).length β€ n := by | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => rw [β increment_encodeNat]; exact (increment_length _).trans (Nat.add_le_add_right ih 1) | |
| theorem encodeNat_length_le (n : β) : (ThreeMachine.encodeNat n).length β€ 2*n+1 := by | |
| have h := encodeNat_length n | |
| simp only [ThreeMachine.encodeNat,List.length_append,List.length_replicate,List.length_cons] | |
| omega | |
| end ThreeMachine.StackCompiler.Binary | |
| end | |
| section | |
| namespace ThreeMachine.StackCompiler.Costs | |
| variable {I J : Type} (s : J β β) (idx : J β I) | |
| theorem binaryIncrement (bs : J β List Bool) (hl : Poly s (fun j => (bs j).length) 1) : | |
| Poly s (fun j => (Uniform.binaryIncrement (I := I)).time (idx j) (bs j)) 3 := by | |
| have ht := binaryLeading s idx bs hl | |
| have hk : Poly s (fun j => Binary.leading (bs j)) 1 := Poly.of_le (fun j => Binary.leading_le _) hl | |
| poly_auto | |
| theorem rawEncodeNat (k : J β β) (hk : Poly s k 1) : | |
| Poly s (fun j => (Uniform.rawEncodeNat (I := I)).time (idx j) (k j)) 4 := by | |
| have hp : Poly (fun p : Poly.IterPool k => s p.1) (fun p => p.2.1) 1 := | |
| Poly.of_le (fun p => Nat.le_of_lt_succ p.2.2) (hk.precomp Sigma.fst) | |
| have hlen : Poly (fun p : Poly.IterPool k => s p.1) | |
| (fun p => (Binary.increment^[p.2.1] []).length) 1 := by | |
| simp only [Binary.iterate_increment] | |
| exact Poly.of_le (fun p => Binary.encodeNat_length p.2.1) hp | |
| have ht := binaryIncrement (fun p : Poly.IterPool k => s p.1) (fun p => idx p.1) | |
| (fun p => Binary.increment^[p.2.1] []) hlen | |
| have hv : Poly (fun p : Poly.IterPool k => s p.1) | |
| (fun p => volume (Binary.increment^[p.2.1] [])) 1 := by poly_auto | |
| have hiter := Poly.iterateTime (Uniform.binaryIncrement (I := I)) idx k (fun _ => []) hk ht hv | |
| poly_auto | |
| theorem binaryEncodeNat (k : J β β) (hk : Poly s k 1) : | |
| Poly s (fun j => (Uniform.binaryEncodeNat (I := I)).time (idx j) (k j)) 4 := by | |
| have ht := rawEncodeNat s idx k hk | |
| have hl : Poly s (fun j => (Computability.encodeNat (k j)).length) 1 := | |
| Poly.of_le (fun j => Binary.encodeNat_length _) hk | |
| poly_auto | |
| end ThreeMachine.StackCompiler.Costs | |
| end | |
| section | |
| namespace ThreeMachine.StackCompiler.Poly | |
| variable {J : Type} {s : J β β} {Ξ± : J β Type} [β j, Coding (Ξ± j)] {l v : β} | |
| theorem volumeListOfPool (xs : β j, List (Ξ± j)) | |
| (hl : Poly s (fun j => (xs j).length) l) | |
| (hv : Poly (fun p : ListPool xs => s p.1) (fun p => volume p.2.1) v) : | |
| Poly s (fun j => volume (xs j)) (l+v) := by | |
| obtain β¨C,hCβ© := hv | |
| apply volumeList hl (powerBase s C v) | |
| intro j a ha | |
| exact hC β¨j,β¨a,haβ©β© | |
| end ThreeMachine.StackCompiler.Poly | |
| end | |
| section | |
| namespace ThreeMachine.StackCompiler.Costs | |
| variable {I J : Type} (s : J β β) (idx : J β I) | |
| theorem binaryEncodeNatMap (xs : J β List β) (hl : Poly s (fun j => (xs j).length) 1) | |
| (hk : Poly (fun p : Poly.ListPool xs => s p.1) (fun p => p.2.1) 1) : | |
| Poly s (fun j => (Uniform.binaryEncodeNat (I := I)).mapList.time (idx j) (xs j)) 5 := by | |
| have ht := binaryEncodeNat (fun p : Poly.ListPool xs => s p.1) (fun p => idx p.1) | |
| (fun p => p.2.1) hk | |
| have vxp : Poly (fun p : Poly.ListPool xs => s p.1) (fun p => volume p.2.1) 1 := by poly_auto | |
| have vx := Poly.volumeListOfPool xs hl vxp | |
| have hendlen : Poly (fun p : Poly.ListPool xs => s p.1) | |
| (fun p => (ThreeMachine.encodeNat p.2.1).length) 1 := by | |
| apply Poly.of_le (fun p : Poly.ListPool xs => Binary.encodeNat_length_le p.2.1) | |
| poly_auto | |
| have hendvol : Poly (fun p : Poly.ListPool xs => s p.1) | |
| (fun p => volume (ThreeMachine.encodeNat p.2.1)) 1 := by poly_auto | |
| poly_auto | |
| theorem volumeEncodeNatList (xs : J β List β) (hl : Poly s (fun j => (xs j).length) 1) | |
| (hk : Poly (fun p : Poly.ListPool xs => s p.1) (fun p => p.2.1) 1) : | |
| Poly s (fun j => volume ((xs j).map ThreeMachine.encodeNat)) 2 := by | |
| have hb : Poly (fun p : Poly.ListPool xs => s p.1) | |
| (fun p => (ThreeMachine.encodeNat p.2.1).length) 1 := by | |
| apply Poly.of_le (fun p : Poly.ListPool xs => Binary.encodeNat_length_le p.2.1) | |
| poly_auto | |
| have hv : Poly (fun p : Poly.ListPool xs => s p.1) | |
| (fun p => volume (ThreeMachine.encodeNat p.2.1)) 1 := by poly_auto | |
| exact Poly.volumeMap _root_.id xs (fun _ => ()) (f := fun _ (x : β Γ Unit) => ThreeMachine.encodeNat x.1) hl hv | |
| theorem binaryEncodeList (xs : J β List β) (hl : Poly s (fun j => (xs j).length) 1) | |
| (hk : Poly (fun p : Poly.ListPool xs => s p.1) (fun p => p.2.1) 1) : | |
| Poly s (fun j => (Uniform.binaryEncodeList (I := I)).time (idx j) (xs j)) 5 := by | |
| have hMap := binaryEncodeNatMap s idx xs hl hk | |
| have hMV := volumeEncodeNatList s xs hl hk | |
| have hfv : Poly s (fun j => volume (((xs j).map ThreeMachine.encodeNat).flatten)) 2 := | |
| Poly.of_le (fun j : J => by rw [volume_flatten]; omega) hMV | |
| have hfl := Poly.lengthVolume _ hfv | |
| have hFlat : Poly s (fun j => (Uniform.flatten (I := I) (Ξ± := fun _ => Bool)).time | |
| (idx j) ((xs j).map ThreeMachine.encodeNat)) 4 := by | |
| apply Poly.of_le (fun j : J => Uniform.time_flatten (Ξ± := fun _ : I => Bool) (idx j) ((xs j).map ThreeMachine.encodeNat)) | |
| have hlm : Poly s (fun j => ((xs j).map ThreeMachine.encodeNat).length) 1 := by | |
| simpa only [List.length_map] using hl | |
| poly_auto | |
| have hc := binaryEncodeNat s idx (fun j => (xs j).length) hl | |
| have vxp : Poly (fun p : Poly.ListPool xs => s p.1) (fun p => volume p.2.1) 1 := by poly_auto | |
| have vx := Poly.volumeListOfPool xs hl vxp | |
| have hlenhead : Poly s (fun j => (ThreeMachine.encodeNat (xs j).length).length) 1 := by | |
| apply Poly.of_le (fun j => Binary.encodeNat_length_le _) | |
| poly_auto | |
| poly_auto | |
| end ThreeMachine.StackCompiler.Costs | |
| end | |
| section | |
| namespace ThreeMachine.StackCompiler | |
| theorem volume_option_le_getD {Ξ± : Type} [Coding Ξ±] (o : Option Ξ±) (a : Ξ±) : | |
| volume o β€ volume (o.getD a)+2 := by | |
| cases o <;> simp only [Option.getD_none,Option.getD_some,volume_none,volume_some] <;> omega | |
| end ThreeMachine.StackCompiler | |
| namespace ThreeMachine.StackCompiler.Costs | |
| variable {I J : Type} (s : J β β) (idx : J β I) | |
| theorem lengthEncodeNatList (xs : J β List β) (hl : Poly s (fun j => (xs j).length) 1) | |
| (hk : Poly (fun p : Poly.ListPool xs => s p.1) (fun p => p.2.1) 1) : | |
| Poly s (fun j => (ThreeMachine.encodeList ThreeMachine.encodeNat (xs j)).length) 2 := by | |
| have hMV := volumeEncodeNatList s xs hl hk | |
| have hfv : Poly s (fun j => volume (((xs j).map ThreeMachine.encodeNat).flatten)) 2 := | |
| Poly.of_le (fun j : J => by rw [volume_flatten]; omega) hMV | |
| have hfl := Poly.lengthVolume _ hfv | |
| have hhead : Poly s (fun j => (ThreeMachine.encodeNat (xs j).length).length) 1 := by | |
| apply Poly.of_le (fun j : J => Binary.encodeNat_length_le _) | |
| poly_auto | |
| simp only [ThreeMachine.encodeList,List.length_append,List.flatMap_def] | |
| poly_auto | |
| theorem binaryEncodeAnswer (o : J β Option (List β)) | |
| (hl : Poly s (fun j => ((o j).getD []).length) 1) | |
| (hk : Poly (fun p : Poly.ListPool (fun j => (o j).getD []) => s p.1) (fun p => p.2.1) 1) : | |
| Poly s (fun j => (Uniform.binaryEncodeAnswer (I := I)).time (idx j) (o j)) 5 := by | |
| have hE := binaryEncodeList s idx (fun j => (o j).getD []) hl hk | |
| have hitem : Poly (fun p : Poly.ListPool (fun j => (o j).getD []) => s p.1) | |
| (fun p => volume p.2.1) 1 := by poly_auto | |
| have hL := Poly.volumeListOfPool (fun j => (o j).getD []) hl hitem | |
| have hO : Poly s (fun j => volume (o j)) 2 := by | |
| apply Poly.of_le (fun j : J => volume_option_le_getD (o j) []) | |
| poly_bound | |
| have hEncoded := lengthEncodeNatList s (fun j => (o j).getD []) hl hk | |
| poly_auto | |
| end ThreeMachine.StackCompiler.Costs | |
| end | |
| end OAI | |