Download lean/OAI/LinearAlgebra/MatrixFields/Arithmetic/ArithmeticComplexity.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 4.11 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/LinearAlgebra/MatrixFields/Arithmetic/ArithmeticComplexity.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/LinearAlgebra/MatrixFields/Arithmetic/ArithmeticComplexity.lean
-
curl -L -o ArithmeticComplexity.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/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 | |