Download data/lean/OAI/Combinatorics/EditApproximation/Numerics/OptimizerWorkspace.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 4.16 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Numerics/OptimizerWorkspace.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditApproximation/Numerics/OptimizerWorkspace.lean
-
curl -L -o OptimizerWorkspace.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Numerics/OptimizerWorkspace.lean
4.16 kB
| import OAI.Combinatorics.EditApproximation.Numerics.OptimizerBits | |
| namespace OAI | |
| /-! Bit storage of the concrete materialized iterates. The history bound | |
| allows every previous iterate to remain live; it does not rely on a garbage | |
| collector reclaiming old vector allocations. -/ | |
| namespace EditApproximation | |
| open Finset | |
| def rationalVectorStorageBits {d : β} (values : Vector β d) : β := | |
| β i : Fin d, rationalEncodingBits (values.get i) | |
| def optimizerStoredHistory {d : β} (vertices : List (Vector β d)) | |
| (linear : Vector β d) (G K : β) : List (Vector β d) := | |
| (List.range (K + 1)).map fun j => (materializedOptimizerWithWork vertices linear G j).1 | |
| def rationalVectorListStorageBits {d : β} (values : List (Vector β d)) : β := | |
| (values.map rationalVectorStorageBits).sum | |
| theorem rationalVectorStorageBits_le {d : β} (values : Vector β d) (B : β) | |
| (hB : β i, rationalEncodingBits (values.get i) β€ B) : | |
| rationalVectorStorageBits values β€ d * B := by | |
| calc | |
| _ β€ β _i : Fin d, B := Finset.sum_le_sum (fun i _ => hB i) | |
| _ = _ := by simp | |
| theorem rationalVectorListStorageBits_le {d : β} (values : List (Vector β d)) (B : β) | |
| (hB : β value β values, rationalVectorStorageBits value β€ B) : | |
| rationalVectorListStorageBits values β€ values.length * B := by | |
| unfold rationalVectorListStorageBits | |
| induction values with | |
| | nil => simp | |
| | cons value rest ih => | |
| have hv := hB value List.mem_cons_self | |
| have hr := ih (fun v hv => hB v (List.mem_cons_of_mem _ hv)) | |
| simp only [List.map_cons, List.sum_cons, List.length_cons, Nat.add_mul, Nat.one_mul] | |
| omega | |
| theorem materializedOptimizerWithWork_uniform_encoding {d : β} | |
| (vertices : List (Vector β d)) (linear : Vector β d) (G K B j : β) | |
| (hvertices : vertices β []) (hj : j β€ K) (i : Fin d) | |
| (hinput : β vertex β vertices, | |
| (0 β€ vertex.get i β§ vertex.get i β€ 1) β§ Nat.size (vertex.get i).den β€ B) : | |
| rationalEncodingBits ((materializedOptimizerWithWork vertices linear G j).1.get i) β€ | |
| 2 * ((K + 1) * (2 * Nat.size (K + 1) + 2 + B) + 1) + 1 := by | |
| by_cases hjzero : j = 0 | |
| Β· subst j | |
| cases vertices with | |
| | nil => exact False.elim (hvertices rfl) | |
| | cons vertex rest => | |
| have hcoord := hinput vertex List.mem_cons_self | |
| have hnum := Nat.size_le_size (rational_numerator_bound (vertex.get i) 1 (by | |
| rw [abs_of_nonneg hcoord.1.1] | |
| exact hcoord.1.2)) | |
| simp only [Nat.one_mul] at hnum | |
| change rationalEncodingBits (vertex.get i) β€ _ | |
| unfold rationalEncodingBits | |
| have hK : 1 β€ K + 1 := by omega | |
| have hpositive : B β€ 2 * Nat.size (K + 1) + 2 + B := by omega | |
| have hproduct := Nat.mul_le_mul hK hpositive | |
| omega | |
| Β· have hbound := materializedOptimizerWithWork_encoding vertices linear G j B | |
| hvertices (by omega) i hinput | |
| have hsize := Nat.size_le_size (by omega : j β€ K + 1) | |
| have hproduct := Nat.mul_le_mul (by omega : j β€ K + 1) | |
| (by omega : 2 * Nat.size j + 2 + B β€ 2 * Nat.size (K + 1) + 2 + B) | |
| omega | |
| theorem optimizerStoredHistory_storage_le {d : β} | |
| (vertices : List (Vector β d)) (linear : Vector β d) (G K B : β) | |
| (hvertices : vertices β []) | |
| (hinput : β vertex β vertices, β i, | |
| (0 β€ vertex.get i β§ vertex.get i β€ 1) β§ Nat.size (vertex.get i).den β€ B) : | |
| rationalVectorListStorageBits (optimizerStoredHistory vertices linear G K) β€ | |
| (K + 1) * (d * (2 * ((K + 1) * (2 * Nat.size (K + 1) + 2 + B) + 1) + 1)) := by | |
| have hstorage := rationalVectorListStorageBits_le (optimizerStoredHistory vertices linear G K) | |
| (d * (2 * ((K + 1) * (2 * Nat.size (K + 1) + 2 + B) + 1) + 1)) (by | |
| intro value hv | |
| obtain β¨j, hj, rflβ© := List.mem_map.mp hv | |
| apply rationalVectorStorageBits_le | |
| intro i | |
| exact materializedOptimizerWithWork_uniform_encoding vertices linear G K B j hvertices | |
| (by have := List.mem_range.mp hj; omega) i (fun vertex hv => hinput vertex hv i)) | |
| simpa only [optimizerStoredHistory, List.length_map, List.length_range] using hstorage | |
| end EditApproximation | |
| end OAI | |