Download data/lean/OAI/LinearAlgebra/MatrixFields/Arithmetic/ArithmeticComplexity.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 4.11 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Arithmetic/ArithmeticComplexity.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixFields/Arithmetic/ArithmeticComplexity.lean
-
curl -L -o ArithmeticComplexity.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Arithmetic/ArithmeticComplexity.lean
4.11 kB
| import Mathlib | |
| import OAI.LinearAlgebra.MatrixFields.Model | |
| namespace OAI | |
| namespace MatrixAllFields | |
| open scoped BigOperators Topology Polynomial | |
| section | |
| noncomputable section | |
| open scoped BigOperators | |
| namespace MatrixMultiplication.Arithmetic | |
| namespace Gate | |
| variable {F Input Register : Type*} | |
| end Gate | |
| namespace Program | |
| variable {F Input : Type*} | |
| @[simp] theorem eval_step_zero [Field F] {r : β} (p : Program F Input r) | |
| (g : Gate F Input (Fin r)) (inputs : Input β F) : | |
| (p.step g).eval inputs 0 = g.eval inputs (p.eval inputs) := rfl | |
| @[simp] theorem eval_step_succ [Field F] {r : β} (p : Program F Input r) | |
| (g : Gate F Input (Fin r)) (inputs : Input β F) (i : Fin r) : | |
| (p.step g).eval inputs i.succ = p.eval inputs i := rfl | |
| @[simp] theorem cost_step {r : β} (p : Program F Input r) | |
| (g : Gate F Input (Fin r)) : (p.step g).cost = p.cost + g.cost := rfl | |
| end Program | |
| namespace MatrixAlgorithm | |
| variable {F : Type*} [Field F] {a b c : β} | |
| theorem correct_iff_entries (P : MatrixAlgorithm F a b c) : | |
| P.Correct β β (A : Matrix (Fin a) (Fin b) F) (B : Matrix (Fin b) (Fin c) F) | |
| (i : Fin a) (k : Fin c), | |
| P.program.eval (matrixInputs A B) (P.output i k) = β j, A i j * B j k := by | |
| constructor | |
| Β· intro h A B i k | |
| exact congrFun (congrFun (h A B) i) k | |
| Β· intro h A B | |
| funext i k | |
| exact h A B i k | |
| end MatrixAlgorithm | |
| def scalarAlgorithm (F : Type*) [Field F] : MatrixAlgorithm F 1 1 1 where | |
| registers := 3 | |
| program := ((Program.nil.step (.input (.inl (0, 0)))).step | |
| (.input (.inr (0, 0)))).step (.mul 1 0) | |
| output := fun _ _ => 0 | |
| theorem scalarAlgorithm_correct (F : Type*) [Field F] : (scalarAlgorithm F).Correct := by | |
| intro A B | |
| funext i k | |
| have hi : i = 0 := Subsingleton.elim _ _ | |
| have hk : k = 0 := Subsingleton.elim _ _ | |
| subst i | |
| subst k | |
| change A 0 0 * B 0 0 = (A * B) 0 0 | |
| simp [Matrix.mul_apply] | |
| @[simp] theorem scalarAlgorithm_cost (F : Type*) [Field F] : (scalarAlgorithm F).cost = 1 := rfl | |
| def innerSize (n : β) (k : β) : β := β(n : β) ^ kββ | |
| theorem one_le_innerSize {n : β} (hn : 1 β€ n) (k : β) : 1 β€ innerSize n k := by | |
| apply Nat.one_le_ceil_iff.mpr | |
| exact Real.rpow_pos_of_pos (by exact_mod_cast (lt_of_lt_of_le Nat.zero_lt_one hn)) k | |
| @[simp] theorem innerSize_zero (n : β) : innerSize n 0 = 1 := by | |
| simp [innerSize] | |
| @[simp] theorem innerSize_one (n : β) : innerSize n 1 = n := by | |
| simp [innerSize] | |
| theorem innerSize_mono {n : β} (hn : 1 β€ n) {k l : β} (hkl : k β€ l) : | |
| innerSize n k β€ innerSize n l := by | |
| exact Nat.ceil_mono (Real.rpow_le_rpow_of_exponent_le (by exact_mod_cast hn) hkl) | |
| theorem innerSize_le_pow {a b n t : β} {k : β} (hk : 0 β€ k) | |
| (hn : n β€ a ^ t) (hab : (a : β) ^ k β€ b) : innerSize n k β€ b ^ t := by | |
| apply Nat.ceil_le.mpr | |
| calc | |
| (n : β) ^ k β€ ((a ^ t : β) : β) ^ k := | |
| Real.rpow_le_rpow (Nat.cast_nonneg n) (by exact_mod_cast hn) hk | |
| _ = ((a : β) ^ k) ^ t := by | |
| rw [Nat.cast_pow, β Real.rpow_pow_comm (Nat.cast_nonneg a)] | |
| _ β€ (b : β) ^ t := pow_le_pow_leftβ (Real.rpow_nonneg (Nat.cast_nonneg a) k) hab t | |
| _ = ((b ^ t : β) : β) := by rw [Nat.cast_pow] | |
| theorem innerSize_cast_le {n : β} (hn : 1 β€ n) {k : β} (hk : 0 β€ k) : | |
| (innerSize n k : β) β€ 2 * (n : β) ^ k := by | |
| have hpow : 1 β€ (n : β) ^ k := Real.one_le_rpow (by exact_mod_cast hn) hk | |
| have hceil := (Nat.ceil_lt_add_one (Real.rpow_nonneg (Nat.cast_nonneg n) k)).le | |
| change (β(n : β) ^ kββ : β) β€ _ | |
| linarith | |
| def RectangularAdmissibleExponent (F : Type*) [Field F] (k Ο : β) : Prop := | |
| β Ξ΅ : β, 0 < Ξ΅ β β C : β, 0 < C β§ | |
| β n : β, 1 β€ n β β P : MatrixAlgorithm F n (innerSize n k) n, | |
| P.Correct β§ (P.cost : β) β€ C * (n : β) ^ (Ο + Ξ΅) | |
| def rectangularOmega (F : Type*) [Field F] (k : β) : β := | |
| sInf {Ο : β | RectangularAdmissibleExponent F k Ο} | |
| def complexAlpha : β := | |
| sSup {k : β | k β Set.Icc 0 1 β§ rectangularOmega β k = 2} | |
| end MatrixMultiplication.Arithmetic | |
| end | |
| end | |
| end MatrixAllFields | |
| end OAI | |