Download data/lean/OAI/Combinatorics/EditApproximation/Binary/BinaryBandInputs.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 7.97 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Binary/BinaryBandInputs.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditApproximation/Binary/BinaryBandInputs.lean
-
curl -L -o BinaryBandInputs.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Binary/BinaryBandInputs.lean
7.97 kB
| import OAI.Combinatorics.EditApproximation.Binary.BinaryOptimizerWork | |
| import OAI.Combinatorics.EditApproximation.Geometry.BandNumericalBits | |
| import OAI.Combinatorics.EditApproximation.Definitions | |
| namespace OAI | |
| /-! Actual Boolean construction of the normalized band vertices. | |
| The input masses are stored fractions; their sum and divisions use the | |
| counted routines and no reduced-rational conversion is performed. -/ | |
| namespace EditApproximation | |
| namespace BinaryFraction | |
| open Finset | |
| theorem value_abs_le_pow_width (a : BinaryFraction) : |a.value| β€ (2 : β) ^ a.width := by | |
| have hn := (bitWordValue_lt_pow_length a.numerator.bits).le | |
| have hw : a.numerator.bits.length β€ a.width := le_max_left _ _ | |
| have hn' : bitWordValue a.numerator.bits β€ 2 ^ a.width := | |
| hn.trans (Nat.pow_le_pow_right (by decide) hw) | |
| have hden : (1 : β) β€ bitWordValue a.denominator := by exact_mod_cast a.denominator_pos | |
| have habs : |(a.numerator.value : β)| = bitWordValue a.numerator.bits := by | |
| cases h : a.numerator.negative <;> simp [SignedBinary.value, signedMagnitude, h] | |
| unfold value | |
| rw [abs_div, habs, abs_of_pos (lt_of_lt_of_le (by norm_num : (0 : β) < 1) hden)] | |
| apply (div_le_iffβ (lt_of_lt_of_le (by norm_num : (0 : β) < 1) hden)).mpr | |
| have hnQ : (bitWordValue a.numerator.bits : β) β€ (2 : β) ^ a.width := by exact_mod_cast hn' | |
| exact hnQ.trans (le_mul_of_one_le_right (by positivity) hden) | |
| theorem bandMassTotalWithWork_value {M : β} (mass : Vector BinaryFraction M) : | |
| (bandMassTotalWithWork mass).1.value = β i, (mass.get i).value := by | |
| rw [bandMassTotalWithWork, β representation_value, dotWithWork_representation, | |
| UnreducedRational.dot_value] | |
| simp [one_representation] | |
| def bandMassTotalStorageBudget (M B : β) : β := | |
| Nat.size M + B + 2 * (1 + M * (B + 1)) + 2 | |
| theorem bandMassTotalWithWork_storage {M : β} (mass : Vector BinaryFraction M) | |
| (B : β) (hmass : β i, (mass.get i).width β€ B) : | |
| (bandMassTotalWithWork mass).1.representation.storageBits β€ bandMassTotalStorageBudget M B := by | |
| have hvalue (i : Fin M) : |(mass.get i).value| β€ ((2 ^ B : β) : β) := by | |
| have h := (value_abs_le_pow_width (mass.get i)).trans | |
| (pow_le_pow_rightβ (by norm_num : (1 : β) β€ 2) (hmass i)) | |
| simpa only [Nat.cast_pow, Nat.cast_ofNat] using h | |
| have h := UnreducedRational.dotList_storageBits | |
| (mass.map representation) ((Vector.replicate M one).map representation) | |
| (List.finRange M) B 1 (2 ^ B) 1 | |
| (by intro i _; simpa only [vector_map_get] using (representation_den_bits_le_width (mass.get i)).trans (hmass i)) | |
| (by intro i _; simp [one_representation, UnreducedRational.one, UnreducedRational.ofRat]) | |
| (by intro i _; simpa only [vector_map_get, representation_value] using hvalue i) | |
| (by intro i _; simp [one_representation]) | |
| simp only [List.length_finRange, Nat.mul_one] at h | |
| have hsize := (natural_product_bit_length M (2 ^ B)).trans | |
| (Nat.add_le_add_left (by rw [Nat.size_pow] : Nat.size (2 ^ B) β€ B + 1) M.size) | |
| rw [bandMassTotalWithWork, dotWithWork_representation] | |
| change (UnreducedRational.dotList (mass.map representation) | |
| ((Vector.replicate M one).map representation) (List.finRange M)).storageBits β€ _ | |
| unfold bandMassTotalStorageBudget | |
| omega | |
| def bandVertexWordBudget (M B : β) : β := 2 * B + bandMassTotalStorageBudget M B + 3 | |
| def bandCoordinateWithWork {M : β} {Ο : Type*} [DecidableEq Ο] | |
| (mass : Vector BinaryFraction M) (total : BinaryFraction) | |
| (action : Fin M β Ο) (coordinate : Fin M Γ Ο) : BinaryFraction Γ β := | |
| if coordinate.2 = action coordinate.1 then divWithWork (mass.get coordinate.1) total else (zero, 1) | |
| theorem bandCoordinateWithWork_value {M : β} {Ο : Type*} [DecidableEq Ο] | |
| (mass : Vector BinaryFraction M) (action : Fin M β Ο) (coordinate : Fin M Γ Ο) : | |
| (bandCoordinateWithWork mass (bandMassTotalWithWork mass).1 action coordinate).1.value = | |
| actionVector (fun i => (mass.get i).value) action coordinate := by | |
| unfold bandCoordinateWithWork actionVector | |
| split_ifs | |
| Β· rw [β representation_value, divWithWork_representation, | |
| UnreducedRational.value_div, representation_value, representation_value, | |
| bandMassTotalWithWork_value] | |
| Β· simp [zero, value, SignedBinary.value, signedMagnitude, bitWordValue] | |
| theorem bandCoordinateWithWork_bounds {M : β} {Ο : Type*} [DecidableEq Ο] | |
| (mass : Vector BinaryFraction M) (action : Fin M β Ο) (coordinate : Fin M Γ Ο) | |
| (B : β) (hmass : β i, (mass.get i).width β€ B) (hpos : β i, 0 < (mass.get i).value) : | |
| let output := (bandCoordinateWithWork mass (bandMassTotalWithWork mass).1 action coordinate).1 | |
| output.width β€ output.representation.storageBits β§ | |
| (0 β€ output.value β§ output.value β€ 1) β§ | |
| output.representation.storageBits β€ bandVertexWordBudget M B := by | |
| dsimp only | |
| have hvalues := actionVector_zero_one (fun i => (mass.get i).value) action coordinate hpos | |
| rw [β bandCoordinateWithWork_value mass action coordinate] at hvalues | |
| refine β¨?_, hvalues, ?_β© | |
| Β· unfold bandCoordinateWithWork | |
| split_ifs | |
| Β· exact divWithWork_self_width _ _ | |
| Β· exact zero_width_le_storageBits | |
| Β· have ht := bandMassTotalWithWork_storage mass B hmass | |
| have hm := representation_storageBits_le (mass.get coordinate.1) | |
| have hi := hmass coordinate.1 | |
| unfold bandCoordinateWithWork | |
| split_ifs | |
| Β· rw [divWithWork_representation] | |
| have hd := UnreducedRational.storageBits_div (mass.get coordinate.1).representation | |
| (bandMassTotalWithWork mass).1.representation | |
| unfold bandVertexWordBudget | |
| omega | |
| Β· change UnreducedRational.zero.storageBits β€ _ | |
| rw [UnreducedRational.storageBits_zero] | |
| unfold bandVertexWordBudget | |
| omega | |
| def bandVerticesWithWork {M d : β} {Ο : Type*} [DecidableEq Ο] | |
| (coordinates : Vector (Fin M Γ Ο) d) (mass : Vector BinaryFraction M) | |
| (band : List (Fin M β Ο)) : List (Vector BinaryFraction d) Γ β := | |
| let total := bandMassTotalWithWork mass | |
| let vertices := band.map fun action => vectorMapWithWork d fun i => | |
| bandCoordinateWithWork mass total.1 action (coordinates.get i) | |
| (vertices.map Prod.fst, total.2 + (vertices.map Prod.snd).sum + 6 * band.length) | |
| theorem bandVerticesWithWork_values {M d : β} {Ο : Type*} [DecidableEq Ο] | |
| (coordinates : Vector (Fin M Γ Ο) d) (mass : Vector BinaryFraction M) | |
| (band : List (Fin M β Ο)) : | |
| (bandVerticesWithWork coordinates mass band).1.map (fun v i => (v.get i).value) = | |
| band.map (fun action i => actionVector (fun i => (mass.get i).value) action (coordinates.get i)) := by | |
| simp only [bandVerticesWithWork, List.map_map, Function.comp_def] | |
| apply List.map_congr_left | |
| intro action _ | |
| funext i | |
| simp only [vectorMapWithWork_value, bandCoordinateWithWork_value] | |
| theorem bandVerticesWithWork_input_bounds {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) (hpos : β i, 0 < (mass.get i).value) | |
| (v : Vector BinaryFraction d) (hv : v β (bandVerticesWithWork coordinates mass band).1) | |
| (i : Fin d) : | |
| (v.get i).width β€ (v.get i).representation.storageBits β§ | |
| (0 β€ (v.get i).value β§ (v.get i).value β€ 1) β§ | |
| Nat.size (v.get i).representation.den β€ bandVertexWordBudget M B β§ | |
| (v.get i).width β€ bandVertexWordBudget M B := by | |
| simp only [bandVerticesWithWork, List.map_map, Function.comp_def] at hv | |
| obtain β¨action, _, rflβ© := List.mem_map.mp hv | |
| simp only [vectorMapWithWork_value] | |
| have h := bandCoordinateWithWork_bounds mass action (coordinates.get i) B hmass hpos | |
| dsimp only at h | |
| refine β¨h.1, h.2.1, ?_, h.1.trans h.2.2β© | |
| apply le_trans ?_ h.2.2 | |
| unfold UnreducedRational.storageBits | |
| omega | |
| end BinaryFraction | |
| end EditApproximation | |
| end OAI | |