Download data/lean/OAI/Combinatorics/EditApproximation/Binary/BinaryBandInputWork.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 4.88 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Binary/BinaryBandInputWork.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditApproximation/Binary/BinaryBandInputWork.lean
-
curl -L -o BinaryBandInputWork.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Binary/BinaryBandInputWork.lean
4.88 kB
| import OAI.Combinatorics.EditApproximation.Binary.BinaryBandInputs | |
| namespace OAI | |
| /-! Bit-operation costs for preparing the actual stored band vertices. The | |
| large numerical values in the generic dot-product bound occur only inside | |
| `Nat.size`; the resulting bound is polynomial in the stored word width. -/ | |
| namespace EditApproximation | |
| namespace BinaryFraction | |
| def storedSumWordBudget (n B : β) : β := | |
| (B + 1) + Nat.size n + 2 * (B + 2) + 2 * (1 + n * ((B + 1) + (B + 1))) + 1 | |
| def storedSumBitBudget (n B : β) : β := | |
| 1 + n * (100000 * (storedSumWordBudget n B + 1) ^ 2) | |
| theorem bandMassTotalWithWork_cost {M : β} (mass : Vector BinaryFraction M) | |
| (B : β) (hmass : β i, (mass.get i).width β€ B) : | |
| (bandMassTotalWithWork mass).2 β€ storedSumBitBudget M B := by | |
| have hvalue (i : Fin M) : |(mass.get i).value| β€ ((2 ^ (B + 1) : β) : β) := by | |
| have h := (value_abs_le_pow_width (mass.get i)).trans | |
| (pow_le_pow_rightβ (by norm_num : (1 : β) β€ 2) | |
| (show (mass.get i).width β€ B + 1 by have := hmass i; omega)) | |
| simpa only [Nat.cast_pow, Nat.cast_ofNat] using h | |
| have honew : one.width β€ B + 1 := by | |
| change 1 β€ B + 1 | |
| omega | |
| have hone : |one.value| β€ ((2 ^ (B + 1) : β) : β) := by | |
| have hp : 1 β€ 2 ^ (B + 1) := Nat.one_le_pow _ _ (by decide) | |
| rw [β representation_value one, one_representation, UnreducedRational.value_one, abs_one] | |
| exact_mod_cast hp | |
| have h := dotListWithWork_cost_in mass (Vector.replicate M one) | |
| (List.finRange M) M (B + 1) (2 ^ (B + 1)) (by simp) | |
| (by intro i _; have := hmass i; omega) | |
| (by intro i _; simpa using honew) | |
| (by intro i _; exact hvalue i) | |
| (by intro i _; simpa using hone) | |
| have hs1 := natural_product_bit_length (M * 2 ^ (B + 1)) (2 ^ (B + 1)) | |
| have hs2 := natural_product_bit_length M (2 ^ (B + 1)) | |
| have hp : Nat.size (2 ^ (B + 1)) = B + 2 := by rw [Nat.size_pow] | |
| have hword : dotWordBudget M (B + 1) (2 ^ (B + 1)) β€ storedSumWordBudget M B := by | |
| unfold dotWordBudget storedSumWordBudget | |
| omega | |
| change (dotListWithWork mass (Vector.replicate M one) (List.finRange M)).2 β€ _ | |
| simp only [List.length_finRange] at h | |
| exact h.trans (Nat.add_le_add_left (Nat.mul_le_mul_left M | |
| (Nat.mul_le_mul_left 100000 (Nat.pow_le_pow_left (by omega) 2))) 1) | |
| def bandCoordinateBitBudget (M B : β) : β := | |
| 2100 * (B + bandMassTotalStorageBudget M B + 2) ^ 2 | |
| theorem bandCoordinateWithWork_cost {M : β} {Ο : Type*} [DecidableEq Ο] | |
| (mass : Vector BinaryFraction M) (action : Fin M β Ο) (coordinate : Fin M Γ Ο) | |
| (B : β) (hmass : β i, (mass.get i).width β€ B) : | |
| (bandCoordinateWithWork mass (bandMassTotalWithWork mass).1 action coordinate).2 β€ | |
| bandCoordinateBitBudget M B := by | |
| have ht := (dotListWithWork_width_le_storageBits mass (Vector.replicate M one) | |
| (List.finRange M)).trans (bandMassTotalWithWork_storage mass B hmass) | |
| change (bandMassTotalWithWork mass).1.width β€ bandMassTotalStorageBudget M B at ht | |
| unfold bandCoordinateWithWork | |
| split_ifs | |
| Β· exact divWithWork_cost _ _ (B + bandMassTotalStorageBudget M B) | |
| ((hmass coordinate.1).trans (Nat.le_add_right _ _)) (by omega) | |
| Β· unfold bandCoordinateBitBudget | |
| have hp : 1 β€ (B + bandMassTotalStorageBudget M B + 2) ^ 2 := by | |
| exact Nat.one_le_pow _ _ (by omega) | |
| omega | |
| def bandPreparationBitBudget (M d vertices B : β) : β := | |
| storedSumBitBudget M B + vertices * (d * (bandCoordinateBitBudget M B + 6)) + 6 * vertices | |
| theorem bandVerticesWithWork_cost {M d : β} {Ο : Type*} [DecidableEq Ο] | |
| (coordinates : Vector (Fin M Γ Ο) d) (mass : Vector BinaryFraction M) | |
| (band : List (Fin M β Ο)) (B : β) (hmass : β i, (mass.get i).width β€ B) : | |
| (bandVerticesWithWork coordinates mass band).2 β€ | |
| bandPreparationBitBudget M d band.length B := by | |
| have hc (action : Fin M β Ο) : | |
| (vectorMapWithWork d (fun i => bandCoordinateWithWork mass | |
| (bandMassTotalWithWork mass).1 action (coordinates.get i))).2 β€ | |
| d * (bandCoordinateBitBudget M B + 6) := | |
| vectorMapWithWork_cost_le d _ _ (fun i => | |
| bandCoordinateWithWork_cost mass action (coordinates.get i) B hmass) | |
| have hs : ((band.map fun action => vectorMapWithWork d fun i => | |
| bandCoordinateWithWork mass (bandMassTotalWithWork mass).1 action | |
| (coordinates.get i)).map Prod.snd).sum β€ | |
| band.length * (d * (bandCoordinateBitBudget M B + 6)) := by | |
| induction band with | |
| | nil => simp | |
| | cons action band ih => | |
| simp only [List.map_cons, List.sum_cons, List.length_cons] | |
| have ha := hc action | |
| rw [Nat.add_mul, Nat.one_mul] | |
| omega | |
| have ht := bandMassTotalWithWork_cost mass B hmass | |
| change (bandMassTotalWithWork mass).2 + _ + 6 * band.length β€ _ | |
| unfold bandPreparationBitBudget | |
| omega | |
| end BinaryFraction | |
| end EditApproximation | |
| end OAI | |