Download data/lean/OAI/LinearAlgebra/MatrixFields/Arithmetic/ComplexArithmeticGrowth.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 24.9 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Arithmetic/ComplexArithmeticGrowth.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixFields/Arithmetic/ComplexArithmeticGrowth.lean
-
curl -L -o ComplexArithmeticGrowth.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Arithmetic/ComplexArithmeticGrowth.lean
24.9 kB
| import Mathlib | |
| import OAI.LinearAlgebra.MatrixFields.Construction.ComplexExpressionFamily | |
| import OAI.LinearAlgebra.MatrixFields.Tensors.TerminalRelabel | |
| namespace OAI | |
| namespace MatrixAllFields | |
| open scoped BigOperators Topology Polynomial | |
| noncomputable section | |
| open scoped BigOperators | |
| namespace MatrixMultiplication.Foundation.Arithmetic.RecursiveBlock | |
| namespace LinearExpression | |
| variable {Input : Type*} | |
| def sumFin : (n : β) β (Fin n β Expression Input) β Expression Input | |
| | 0, _ => .constant 0 | |
| | n + 1, f => .add (f 0) (sumFin n (fun i => f i.succ)) | |
| theorem eval_sumFin (n : β) (f : Fin n β Expression Input) (inputs : Input β β) : | |
| (sumFin n f).eval inputs = β i, (f i).eval inputs := by | |
| induction n with | |
| | zero => simp [sumFin, Expression.eval] | |
| | succ n ih => | |
| simp only [sumFin, Expression.eval, ih, Fin.sum_univ_succ] | |
| theorem cost_sumFin (n : β) (f : Fin n β Expression Input) : | |
| (sumFin n f).cost = (β i, (f i).cost) + n := by | |
| induction n with | |
| | zero => simp [sumFin, Expression.cost] | |
| | succ n ih => | |
| simp only [sumFin, Expression.cost, ih, Fin.sum_univ_succ] | |
| omega | |
| def linear {Term : Type*} [Fintype Term] (a : Term β β) (wire : Term β Input) : | |
| Expression Input := | |
| sumFin (Fintype.card Term) (fun i => | |
| .mul (.constant (a ((Fintype.equivFin Term).symm i))) | |
| (.input (wire ((Fintype.equivFin Term).symm i)))) | |
| theorem eval_linear {Term : Type*} [Fintype Term] | |
| (a : Term β β) (wire : Term β Input) (inputs : Input β β) : | |
| (linear a wire).eval inputs = β i, a i * inputs (wire i) := by | |
| rw [linear, eval_sumFin] | |
| exact (Fintype.equivFin Term).symm.sum_comp (fun i => a i * inputs (wire i)) | |
| theorem cost_linear {Term : Type*} [Fintype Term] | |
| (a : Term β β) (wire : Term β Input) : | |
| (linear a wire).cost = 2 * Fintype.card Term := by | |
| simp [linear, cost_sumFin, Expression.cost, two_mul] | |
| end LinearExpression | |
| structure Family (Input Output : Type*) where | |
| registers : β | |
| program : Program Input registers | |
| output : Output β Fin registers | |
| namespace Family | |
| variable {Input Mid Output : Type*} | |
| def eval (p : Family Input Output) (inputs : Input β β) (o : Output) : β := | |
| p.program.eval inputs (p.output o) | |
| def cost (p : Family Input Output) : β := p.program.cost | |
| def expressions [Fintype Output] (e : Output β Expression Input) : Family Input Output := | |
| let p := Expression.compileFamily e | |
| β¨p.registers, p.program, p.outputβ© | |
| theorem eval_expressions [Fintype Output] (e : Output β Expression Input) | |
| (inputs : Input β β) (o : Output) : | |
| (expressions e).eval inputs o = (e o).eval inputs := | |
| (Expression.compileFamily e).correct inputs o | |
| theorem cost_expressions [Fintype Output] (e : Output β Expression Input) : | |
| (expressions e).cost = β o, (e o).cost := | |
| (Expression.compileFamily e).cost_eq | |
| def compose (p : Family Input Mid) (q : Family Mid Output) : Family Input Output := | |
| let s := p.program.substitute q.program p.output | |
| β¨s.registers, s.program, fun o => s.output (q.output o)β© | |
| theorem eval_compose (p : Family Input Mid) (q : Family Mid Output) | |
| (inputs : Input β β) (o : Output) : | |
| (compose p q).eval inputs o = q.eval (p.eval inputs) o := | |
| (p.program.substitute q.program p.output).correct inputs (q.output o) | |
| theorem cost_compose (p : Family Input Mid) (q : Family Mid Output) : | |
| (compose p q).cost = p.cost + q.cost := | |
| (p.program.substitute q.program p.output).cost_eq | |
| def mapInputs {NewInput : Type*} (f : Input β NewInput) (p : Family Input Output) : | |
| Family NewInput Output := | |
| β¨p.registers, p.program.mapInput f, p.outputβ© | |
| theorem eval_mapInputs {NewInput : Type*} (f : Input β NewInput) | |
| (p : Family Input Output) (inputs : NewInput β β) (o : Output) : | |
| (p.mapInputs f).eval inputs o = p.eval (fun i => inputs (f i)) o := by | |
| exact Program.eval_mapInput f p.program inputs (p.output o) | |
| theorem cost_mapInputs {NewInput : Type*} (f : Input β NewInput) | |
| (p : Family Input Output) : (p.mapInputs f).cost = p.cost := by | |
| exact Program.cost_mapInput f p.program | |
| def parallel : (r : β) β (Fin r β Family Input Output) β Family Input (Fin r Γ Output) | |
| | 0, _ => β¨0, Program.nil, fun o => Fin.elim0 o.1β© | |
| | r + 1, p => | |
| let head := p 0 | |
| let tail := parallel r (fun i => p i.succ) | |
| { registers := head.registers + tail.registers | |
| program := head.program.append tail.program | |
| output := fun o => Fin.cases | |
| (Program.oldIndex _ _ (head.output o.2)) | |
| (fun i => Program.newIndex _ _ (tail.output (i, o.2))) o.1 } | |
| theorem eval_parallel (r : β) (p : Fin r β Family Input Output) | |
| (inputs : Input β β) (o : Fin r Γ Output) : | |
| (parallel r p).eval inputs o = (p o.1).eval inputs o.2 := by | |
| induction r with | |
| | zero => exact Fin.elim0 o.1 | |
| | succ r ih => | |
| rcases o with β¨i, oβ© | |
| refine Fin.cases ?_ (fun j => ?_) i | |
| Β· exact Program.eval_append_old _ _ inputs _ | |
| Β· exact (Program.eval_append_new _ _ inputs _).trans | |
| (ih (fun j => p j.succ) (j, o)) | |
| theorem cost_parallel (r : β) (p : Fin r β Family Input Output) : | |
| (parallel r p).cost = β i, (p i).cost := by | |
| induction r with | |
| | zero => simp [parallel, cost, Program.cost] | |
| | succ r ih => | |
| change ((p 0).program.append (parallel r (fun i => p i.succ)).program).cost = _ | |
| rw [Program.cost_append] | |
| change (p 0).cost + (parallel r (fun i => p i.succ)).cost = _ | |
| rw [ih, Fin.sum_univ_succ] | |
| def copies (r : β) (p : Family Input Output) : | |
| Family (Fin r Γ Input) (Fin r Γ Output) := | |
| parallel r (fun i => p.mapInputs (fun x => (i, x))) | |
| theorem eval_copies (r : β) (p : Family Input Output) | |
| (inputs : Fin r Γ Input β β) (o : Fin r Γ Output) : | |
| (copies r p).eval inputs o = p.eval (fun x => inputs (o.1, x)) o.2 := by | |
| rw [copies, eval_parallel, eval_mapInputs] | |
| theorem cost_copies (r : β) (p : Family Input Output) : | |
| (copies r p).cost = r * p.cost := by | |
| simp [copies, cost_parallel, cost_mapInputs] | |
| def ofMatrix {m : β} (p : MatrixAlgorithm m) : | |
| Family (MatrixInput m) (Fin m Γ Fin m) := | |
| β¨p.registers, p.program, fun o => p.output o.1 o.2β© | |
| @[simp] theorem cost_ofMatrix {m : β} (p : MatrixAlgorithm m) : | |
| (ofMatrix p).cost = p.cost := rfl | |
| theorem eval_ofMatrix {m : β} (p : MatrixAlgorithm m) (hp : p.Correct) | |
| (inputs : MatrixInput m β β) (o : Fin m Γ Fin m) : | |
| (ofMatrix p).eval inputs o = | |
| β j, inputs (.inl (o.1, j)) * inputs (.inr (j, o.2)) := by | |
| have h := (MatrixAlgorithm.correct_iff_entries p).mp hp | |
| (fun i j => inputs (.inl (i, j))) (fun j k => inputs (.inr (j, k))) o.1 o.2 | |
| have hi : matrixInputs (fun i j => inputs (.inl (i, j))) | |
| (fun j k => inputs (.inr (j, k))) = inputs := by | |
| funext x | |
| cases x <;> rfl | |
| rw [hi] at h | |
| exact h | |
| end Family | |
| section BlockIdentities | |
| variable {n r m : β} | |
| def join (i : Fin n) (j : Fin m) : Fin (n * m) := finProdFinEquiv (i, j) | |
| theorem rank_bilinear_identity | |
| (a b c : Fin r β Fin n Γ Fin n β β) | |
| (h : Tensor.matrixMultiplication n n n = | |
| fun x y z => β q, Tensor.rankOne (a q) (b q) (c q) x y z) | |
| (left right : Fin n Γ Fin n β β) (i k : Fin n) : | |
| (β q, c q (k, i) * (β x, a q x * left x) * (β y, b q y * right y)) = | |
| β j, left (i, j) * right (j, k) := by | |
| rw [β Tensor.contract_matrixCoefficients left right i k] | |
| change _ = Tensor.contract (Tensor.matrixMultiplication n n n) left right (k, i) | |
| rw [h] | |
| simp only [Tensor.contract, Tensor.rankOne, Finset.sum_mul, Finset.mul_sum] | |
| calc | |
| (β q, β y, β x, c q (k, i) * (a q x * left x) * (b q y * right y)) = | |
| β q, β x, β y, c q (k, i) * (a q x * left x) * (b q y * right y) := by | |
| apply Finset.sum_congr rfl | |
| intro q hq | |
| exact Finset.sum_comm | |
| _ = | |
| β x, β q, β y, c q (k, i) * (a q x * left x) * (b q y * right y) := | |
| Finset.sum_comm | |
| _ = β x, β y, β q, a q x * b q y * c q (k, i) * left x * right y := by | |
| apply Finset.sum_congr rfl | |
| intro x hx | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro y hy | |
| apply Finset.sum_congr rfl | |
| intro q hq | |
| ring | |
| def leftBlock (a : Fin r β Fin n Γ Fin n β β) | |
| (A : Matrix (Fin (n * m)) (Fin (n * m)) β) (q : Fin r) : | |
| Matrix (Fin m) (Fin m) β := | |
| fun s t => β x, a q x * A (join x.1 s) (join x.2 t) | |
| def rightBlock (b : Fin r β Fin n Γ Fin n β β) | |
| (B : Matrix (Fin (n * m)) (Fin (n * m)) β) (q : Fin r) : | |
| Matrix (Fin m) (Fin m) β := | |
| fun t u => β y, b q y * B (join y.1 t) (join y.2 u) | |
| theorem block_identity | |
| (a b c : Fin r β Fin n Γ Fin n β β) | |
| (h : Tensor.matrixMultiplication n n n = | |
| fun x y z => β q, Tensor.rankOne (a q) (b q) (c q) x y z) | |
| (A B : Matrix (Fin (n * m)) (Fin (n * m)) β) | |
| (i k : Fin n) (s u : Fin m) : | |
| (β q, c q (k, i) * ((leftBlock a A q) * (rightBlock b B q)) s u) = | |
| (A * B) (join i s) (join k u) := by | |
| simp only [Matrix.mul_apply, Finset.mul_sum] | |
| rw [Finset.sum_comm] | |
| have hlocal (t : Fin m) := rank_bilinear_identity a b c h | |
| (fun x => A (join x.1 s) (join x.2 t)) | |
| (fun y => B (join y.1 t) (join y.2 u)) i k | |
| simp only [leftBlock, rightBlock] | |
| simp_rw [β mul_assoc, hlocal] | |
| rw [Finset.sum_comm] | |
| exact (Fintype.sum_prod_type _).symm.trans | |
| (finProdFinEquiv.sum_comp (fun j => A (join i s) j * B j (join k u))) | |
| end BlockIdentities | |
| variable {n r m : β} | |
| def inputExpressions (a b : Fin r β Fin n Γ Fin n β β) : | |
| Fin r Γ MatrixInput m β Expression (MatrixInput (n * m)) | |
| | (q, .inl (s, t)) => LinearExpression.linear (a q) | |
| (fun x => .inl (join x.1 s, join x.2 t)) | |
| | (q, .inr (t, u)) => LinearExpression.linear (b q) | |
| (fun y => .inr (join y.1 t, join y.2 u)) | |
| def inputFamily (a b : Fin r β Fin n Γ Fin n β β) : | |
| Family (MatrixInput (n * m)) (Fin r Γ MatrixInput m) := | |
| Family.expressions (inputExpressions a b) | |
| theorem inputFamily_eval (a b : Fin r β Fin n Γ Fin n β β) | |
| (A B : Matrix (Fin (n * m)) (Fin (n * m)) β) (q : Fin r) (x : MatrixInput m) : | |
| (inputFamily a b).eval (matrixInputs A B) (q, x) = | |
| matrixInputs (leftBlock a A q) (rightBlock b B q) x := by | |
| cases x with | |
| | inl x => | |
| simp only [inputFamily, Family.eval_expressions, inputExpressions, | |
| LinearExpression.eval_linear, matrixInputs, leftBlock] | |
| | inr x => | |
| simp only [inputFamily, Family.eval_expressions, inputExpressions, | |
| LinearExpression.eval_linear, matrixInputs, rightBlock] | |
| theorem inputFamily_cost (a b : Fin r β Fin n Γ Fin n β β) : | |
| (inputFamily (m := m) a b).cost = 4 * r * n ^ 2 * m ^ 2 := by | |
| rw [inputFamily, Family.cost_expressions] | |
| have hc (o : Fin r Γ MatrixInput m) : (inputExpressions a b o).cost = 2 * n ^ 2 := by | |
| rcases o with β¨q, oβ© | |
| cases o <;> simp [inputExpressions, LinearExpression.cost_linear, pow_two] | |
| simp_rw [hc] | |
| simp only [Finset.sum_const, Finset.card_univ, Fintype.card_prod, | |
| Fintype.card_fin, Fintype.card_sum, smul_eq_mul] | |
| ring | |
| def recursiveProducts (a b : Fin r β Fin n Γ Fin n β β) (p : MatrixAlgorithm m) : | |
| Family (MatrixInput (n * m)) (Fin r Γ (Fin m Γ Fin m)) := | |
| (inputFamily a b).compose (Family.copies r (Family.ofMatrix p)) | |
| theorem recursiveProducts_eval (a b : Fin r β Fin n Γ Fin n β β) | |
| (p : MatrixAlgorithm m) (hp : p.Correct) | |
| (A B : Matrix (Fin (n * m)) (Fin (n * m)) β) (q : Fin r) (s u : Fin m) : | |
| (recursiveProducts a b p).eval (matrixInputs A B) (q, (s, u)) = | |
| ((leftBlock a A q) * (rightBlock b B q)) s u := by | |
| rw [recursiveProducts, Family.eval_compose, Family.eval_copies, | |
| Family.eval_ofMatrix _ hp] | |
| simp only [inputFamily_eval, matrixInputs, Matrix.mul_apply] | |
| theorem recursiveProducts_cost (a b : Fin r β Fin n Γ Fin n β β) | |
| (p : MatrixAlgorithm m) : | |
| (recursiveProducts a b p).cost = 4 * r * n ^ 2 * m ^ 2 + r * p.cost := by | |
| rw [recursiveProducts, Family.cost_compose, inputFamily_cost, | |
| Family.cost_copies, Family.cost_ofMatrix] | |
| def outputExpressions (c : Fin r β Fin n Γ Fin n β β) : | |
| Fin (n * m) Γ Fin (n * m) β Expression (Fin r Γ (Fin m Γ Fin m)) := | |
| fun o => LinearExpression.linear | |
| (fun q => c q ((finProdFinEquiv.symm o.2).1, (finProdFinEquiv.symm o.1).1)) | |
| (fun q => (q, ((finProdFinEquiv.symm o.1).2, (finProdFinEquiv.symm o.2).2))) | |
| def outputFamily (c : Fin r β Fin n Γ Fin n β β) : | |
| Family (Fin r Γ (Fin m Γ Fin m)) (Fin (n * m) Γ Fin (n * m)) := | |
| Family.expressions (outputExpressions c) | |
| theorem outputFamily_eval (c : Fin r β Fin n Γ Fin n β β) | |
| (inputs : Fin r Γ (Fin m Γ Fin m) β β) (i k : Fin n) (s u : Fin m) : | |
| (outputFamily c).eval inputs (join i s, join k u) = | |
| β q, c q (k, i) * inputs (q, (s, u)) := by | |
| simp only [outputFamily, Family.eval_expressions, outputExpressions, | |
| LinearExpression.eval_linear, join, Equiv.symm_apply_apply] | |
| theorem outputFamily_cost (c : Fin r β Fin n Γ Fin n β β) : | |
| (outputFamily (m := m) c).cost = 2 * r * n ^ 2 * m ^ 2 := by | |
| simp only [outputFamily, Family.cost_expressions, outputExpressions, | |
| LinearExpression.cost_linear, Fintype.card_fin, Finset.sum_const, | |
| Finset.card_univ, Fintype.card_prod, smul_eq_mul] | |
| ring | |
| def algorithm (a b c : Fin r β Fin n Γ Fin n β β) (p : MatrixAlgorithm m) : | |
| MatrixAlgorithm (n * m) := | |
| let f := (recursiveProducts a b p).compose (outputFamily c) | |
| β¨f.registers, f.program, fun i k => f.output (i, k)β© | |
| theorem algorithm_correct | |
| (a b c : Fin r β Fin n Γ Fin n β β) | |
| (h : Tensor.matrixMultiplication n n n = | |
| fun x y z => β q, Tensor.rankOne (a q) (b q) (c q) x y z) | |
| (p : MatrixAlgorithm m) (hp : p.Correct) : (algorithm a b c p).Correct := by | |
| intro A B | |
| funext i k | |
| obtain β¨β¨i, sβ©, rflβ© := finProdFinEquiv.surjective i | |
| obtain β¨β¨k, uβ©, rflβ© := finProdFinEquiv.surjective k | |
| change ((recursiveProducts a b p).compose (outputFamily c)).eval | |
| (matrixInputs A B) (join i s, join k u) = _ | |
| rw [Family.eval_compose, outputFamily_eval] | |
| simp_rw [recursiveProducts_eval a b p hp A B] | |
| exact block_identity a b c h A B i k s u | |
| theorem algorithm_cost (a b c : Fin r β Fin n Γ Fin n β β) | |
| (p : MatrixAlgorithm m) : | |
| (algorithm a b c p).cost = r * p.cost + (6 * r * n ^ 2) * m ^ 2 := by | |
| change ((recursiveProducts a b p).compose (outputFamily c)).cost = _ | |
| rw [Family.cost_compose, recursiveProducts_cost, outputFamily_cost] | |
| ring | |
| theorem rank_block_step (h : Tensor.RankAtMost (Tensor.matrixMultiplication n n n) r) | |
| (p : MatrixAlgorithm m) (hp : p.Correct) : | |
| β q : MatrixAlgorithm (n * m), q.Correct β§ | |
| q.cost = r * p.cost + (6 * r * n ^ 2) * m ^ 2 := by | |
| rcases h with β¨a, b, c, hβ© | |
| exact β¨algorithm a b c p, algorithm_correct a b c h p hp, algorithm_cost a b c pβ© | |
| end MatrixMultiplication.Foundation.Arithmetic.RecursiveBlock | |
| end | |
| noncomputable section | |
| namespace MatrixMultiplication.Foundation.Arithmetic | |
| theorem exists_power_cover {b n : β} (hb : 2 β€ b) (hn : 1 β€ n) : | |
| β k : β, n β€ b ^ k β§ b ^ k β€ b * n := by | |
| refine β¨Nat.log b n + 1, (Nat.lt_pow_succ_log_self (by omega) n).le, ?_β© | |
| rw [pow_succ'] | |
| exact Nat.mul_le_mul_left b (Nat.pow_log_le_self b (by omega)) | |
| theorem geometric_cost_recurrence_bound (x : β β β) (a b d q : β) | |
| (hx : 0 β€ x 0) (ha : 0 β€ a) (hb : 0 β€ b) (hd : 0 β€ d) | |
| (haq : a < q) (hdq : d β€ q) | |
| (hstep : β k, x (k + 1) β€ a * x k + b * d ^ k) : | |
| β C : β, 0 < C β§ β k, x k β€ C * q ^ k := by | |
| let C := x 0 + b / (q - a) + 1 | |
| have hgap : 0 < q - a := sub_pos.mpr haq | |
| have hfrac : 0 β€ b / (q - a) := div_nonneg hb hgap.le | |
| have hC : 0 < C := by dsimp [C]; linarith | |
| have hcancel : (q - a) * (b / (q - a)) = b := by | |
| field_simp [ne_of_gt hgap] | |
| have hCfrac : b / (q - a) β€ C := by dsimp [C]; linarith | |
| have hcoeff : a * C + b β€ C * q := by | |
| have hmul := mul_le_mul_of_nonneg_left hCfrac hgap.le | |
| rw [hcancel] at hmul | |
| calc | |
| a * C + b β€ a * C + (q - a) * C := add_le_add (le_refl _) hmul | |
| _ = C * q := by ring | |
| refine β¨C, hC, ?_β© | |
| intro k | |
| induction k with | |
| | zero => simp only [pow_zero, mul_one]; dsimp [C]; linarith | |
| | succ k ih => | |
| calc | |
| x (k + 1) β€ a * x k + b * d ^ k := hstep k | |
| _ β€ a * (C * q ^ k) + b * q ^ k := | |
| add_le_add (mul_le_mul_of_nonneg_left ih ha) | |
| (mul_le_mul_of_nonneg_left (pow_le_pow_leftβ hd hdq k) hb) | |
| _ = (a * C + b) * q ^ k := by ring | |
| _ β€ (C * q) * q ^ k := | |
| mul_le_mul_of_nonneg_right hcoeff (pow_nonneg (hd.trans hdq) k) | |
| _ = C * q ^ (k + 1) := by rw [pow_succ]; ring | |
| theorem power_cost_padding_bound | |
| (hpad : β {n m : β}, n β€ m β β P : MatrixAlgorithm m, P.Correct β | |
| β Q : MatrixAlgorithm n, Q.Correct β§ Q.cost β€ P.cost) | |
| {b : β} (hb : 2 β€ b) {s C : β} (hs : 0 β€ s) (hC : 0 < C) | |
| (hpower : β k : β, β P : MatrixAlgorithm (b ^ k), | |
| P.Correct β§ (P.cost : β) β€ C * ((b : β) ^ s) ^ k) : | |
| β D : β, 0 < D β§ β n : β, 1 β€ n β β P : MatrixAlgorithm n, | |
| P.Correct β§ (P.cost : β) β€ D * (n : β) ^ s := by | |
| have hbpos : 0 < (b : β) := by exact_mod_cast (by omega : 0 < b) | |
| refine β¨C * (b : β) ^ s, mul_pos hC (Real.rpow_pos_of_pos hbpos s), ?_β© | |
| intro n hn | |
| obtain β¨k, hnk, hknβ© := exists_power_cover hb hn | |
| obtain β¨P, hP, hcostβ© := hpower k | |
| obtain β¨Q, hQ, hQPβ© := hpad hnk P hP | |
| refine β¨Q, hQ, ?_β© | |
| calc | |
| (Q.cost : β) β€ (P.cost : β) := by exact_mod_cast hQP | |
| _ β€ C * ((b : β) ^ s) ^ k := hcost | |
| _ = C * ((b ^ k : β) : β) ^ s := by | |
| rw [Real.rpow_pow_comm hbpos.le, Nat.cast_pow] | |
| _ β€ C * ((b : β) * (n : β)) ^ s := | |
| mul_le_mul_of_nonneg_left | |
| (Real.rpow_le_rpow (Nat.cast_nonneg _) (by exact_mod_cast hkn) hs) hC.le | |
| _ = (C * (b : β) ^ s) * (n : β) ^ s := by | |
| rw [Real.mul_rpow hbpos.le (Nat.cast_nonneg n)] | |
| ring | |
| theorem admissibleExponent_of_uniform_power_costs | |
| (hpad : β {n m : β}, n β€ m β β P : MatrixAlgorithm m, P.Correct β | |
| β Q : MatrixAlgorithm n, Q.Correct β§ Q.cost β€ P.cost) | |
| {b : β} (hb : 2 β€ b) {Ο C : β} (hΟ : 0 β€ Ο) (hC : 0 < C) | |
| (hpower : β k : β, β P : MatrixAlgorithm (b ^ k), | |
| P.Correct β§ (P.cost : β) β€ C * ((b : β) ^ Ο) ^ k) : | |
| AdmissibleExponent Ο := by | |
| obtain β¨D, hD, hallβ© := power_cost_padding_bound hpad hb hΟ hC hpower | |
| intro Ξ΅ hΞ΅ | |
| refine β¨D, hD, ?_β© | |
| intro n hn | |
| obtain β¨P, hP, hcostβ© := hall n hn | |
| refine β¨P, hP, hcost.trans ?_β© | |
| exact mul_le_mul_of_nonneg_left | |
| (Real.rpow_le_rpow_of_exponent_le (by exact_mod_cast hn) (by linarith)) hD.le | |
| theorem admissibleExponent_of_power_costs | |
| (hpad : β {n m : β}, n β€ m β β P : MatrixAlgorithm m, P.Correct β | |
| β Q : MatrixAlgorithm n, Q.Correct β§ Q.cost β€ P.cost) | |
| {b : β} (hb : 2 β€ b) {Ο : β} (hΟ : 0 β€ Ο) | |
| (hpower : β Ξ΅ : β, 0 < Ξ΅ β β C : β, 0 < C β§ | |
| β k : β, β P : MatrixAlgorithm (b ^ k), | |
| P.Correct β§ (P.cost : β) β€ C * ((b : β) ^ (Ο + Ξ΅)) ^ k) : | |
| AdmissibleExponent Ο := by | |
| intro Ξ΅ hΞ΅ | |
| obtain β¨C, hC, hcostβ© := hpower Ξ΅ hΞ΅ | |
| exact power_cost_padding_bound hpad hb (by linarith) hC hcost | |
| theorem admissibleExponent_of_recursive_costs | |
| (hpad : β {n m : β}, n β€ m β β P : MatrixAlgorithm m, P.Correct β | |
| β Q : MatrixAlgorithm n, Q.Correct β§ Q.cost β€ P.cost) | |
| {b R K : β} (hb : 2 β€ b) {Ο : β} (hΟ : 2 β€ Ο) | |
| (hR : (R : β) β€ (b : β) ^ Ο) | |
| (P : β k : β, MatrixAlgorithm (b ^ k)) | |
| (hP : β k, (P k).Correct) | |
| (hstep : β k, (P (k + 1)).cost β€ R * (P k).cost + K * (b ^ k) ^ 2) : | |
| AdmissibleExponent Ο := by | |
| apply admissibleExponent_of_power_costs hpad hb (by linarith) | |
| intro Ξ΅ hΞ΅ | |
| have hbpos : 0 < (b : β) := by exact_mod_cast (by omega : 0 < b) | |
| have hbone : 1 < (b : β) := by exact_mod_cast (by omega : 1 < b) | |
| have hrate : (R : β) < (b : β) ^ (Ο + Ξ΅) := | |
| hR.trans_lt (Real.rpow_lt_rpow_of_exponent_lt hbone (by linarith)) | |
| have hquad : (b : β) ^ (2 : β) β€ (b : β) ^ (Ο + Ξ΅) := by | |
| rw [β Real.rpow_natCast] | |
| change (b : β) ^ (2 : β) β€ (b : β) ^ (Ο + Ξ΅) | |
| exact Real.rpow_le_rpow_of_exponent_le hbone.le (by linarith) | |
| obtain β¨C, hC, hboundβ© := geometric_cost_recurrence_bound | |
| (fun k => ((P k).cost : β)) (R : β) (K : β) ((b : β) ^ (2 : β)) | |
| ((b : β) ^ (Ο + Ξ΅)) (Nat.cast_nonneg _) (Nat.cast_nonneg _) | |
| (Nat.cast_nonneg _) (sq_nonneg _) hrate hquad (fun k => by | |
| have h := hstep k | |
| have hcast : ((P (k + 1)).cost : β) β€ | |
| (R : β) * ((P k).cost : β) + (K : β) * ((b : β) ^ k) ^ 2 := by | |
| exact_mod_cast h | |
| simpa only [β pow_mul, Nat.mul_comm k 2] using hcast) | |
| exact β¨C, hC, fun k => β¨P k, hP k, hbound kβ©β© | |
| def blockRecurrenceCost (b R K : β) : β β β | |
| | 0 => 1 | |
| | k + 1 => R * blockRecurrenceCost b R K k + K * (b ^ k) ^ 2 | |
| @[simp] theorem blockRecurrenceCost_zero (b R K : β) : | |
| blockRecurrenceCost b R K 0 = 1 := rfl | |
| @[simp] theorem blockRecurrenceCost_succ (b R K k : β) : | |
| blockRecurrenceCost b R K (k + 1) = | |
| R * blockRecurrenceCost b R K k + K * (b ^ k) ^ 2 := rfl | |
| theorem power_programs_of_block_step {b R K : β} | |
| (hstep : β m : β, β P : MatrixAlgorithm m, P.Correct β | |
| β Q : MatrixAlgorithm (b * m), Q.Correct β§ | |
| Q.cost β€ R * P.cost + K * m ^ 2) : | |
| β k : β, β P : MatrixAlgorithm (b ^ k), P.Correct β§ | |
| P.cost β€ blockRecurrenceCost b R K k := by | |
| intro k | |
| induction k with | |
| | zero => | |
| exact β¨scalarAlgorithm, scalarAlgorithm_correct, by simpβ© | |
| | succ k ih => | |
| obtain β¨P, hP, hcostβ© := ih | |
| obtain β¨Q, hQ, hQcostβ© := hstep (b ^ k) P hP | |
| have hbound : Q.cost β€ blockRecurrenceCost b R K (k + 1) := by | |
| exact hQcost.trans (Nat.add_le_add_right (Nat.mul_le_mul_left R hcost) _) | |
| have hresult : β Q : MatrixAlgorithm (b * b ^ k), Q.Correct β§ | |
| Q.cost β€ blockRecurrenceCost b R K (k + 1) := β¨Q, hQ, hboundβ© | |
| exact (pow_succ' b k).symm βΈ hresult | |
| theorem admissibleExponent_of_block_step_of_padding | |
| (hpad : β {n m : β}, n β€ m β β P : MatrixAlgorithm m, P.Correct β | |
| β Q : MatrixAlgorithm n, Q.Correct β§ Q.cost β€ P.cost) | |
| {b R K : β} (hb : 2 β€ b) {Ο : β} (hΟ : 2 β€ Ο) | |
| (hR : (R : β) β€ (b : β) ^ Ο) | |
| (hstep : β m : β, β P : MatrixAlgorithm m, P.Correct β | |
| β Q : MatrixAlgorithm (b * m), Q.Correct β§ | |
| Q.cost β€ R * P.cost + K * m ^ 2) : | |
| AdmissibleExponent Ο := by | |
| apply admissibleExponent_of_power_costs hpad hb (by linarith) | |
| intro Ξ΅ hΞ΅ | |
| have hbone : 1 < (b : β) := by exact_mod_cast (by omega : 1 < b) | |
| have hrate : (R : β) < (b : β) ^ (Ο + Ξ΅) := | |
| hR.trans_lt (Real.rpow_lt_rpow_of_exponent_lt hbone (by linarith)) | |
| have hquad : (b : β) ^ (2 : β) β€ (b : β) ^ (Ο + Ξ΅) := by | |
| rw [β Real.rpow_natCast] | |
| change (b : β) ^ (2 : β) β€ (b : β) ^ (Ο + Ξ΅) | |
| exact Real.rpow_le_rpow_of_exponent_le hbone.le (by linarith) | |
| obtain β¨C, hC, hboundβ© := geometric_cost_recurrence_bound | |
| (fun k => (blockRecurrenceCost b R K k : β)) | |
| (R : β) (K : β) ((b : β) ^ (2 : β)) ((b : β) ^ (Ο + Ξ΅)) | |
| (Nat.cast_nonneg _) (Nat.cast_nonneg _) (Nat.cast_nonneg _) | |
| (sq_nonneg _) hrate hquad (fun k => by | |
| simp only [blockRecurrenceCost_succ, Nat.cast_add, Nat.cast_mul, Nat.cast_pow] | |
| rw [β pow_mul, β pow_mul, Nat.mul_comm k 2]) | |
| refine β¨C, hC, ?_β© | |
| intro k | |
| obtain β¨P, hP, hcostβ© := power_programs_of_block_step hstep k | |
| exact β¨P, hP, (by exact_mod_cast hcost : (P.cost : β) β€ | |
| (blockRecurrenceCost b R K k : β)).trans (hbound k)β© | |
| theorem admissibleExponent_of_block_step | |
| {b R K : β} (hb : 2 β€ b) {Ο : β} (hΟ : 2 β€ Ο) | |
| (hR : (R : β) β€ (b : β) ^ Ο) | |
| (hstep : β m : β, β P : MatrixAlgorithm m, P.Correct β | |
| β Q : MatrixAlgorithm (b * m), Q.Correct β§ | |
| Q.cost β€ R * P.cost + K * m ^ 2) : | |
| AdmissibleExponent Ο := | |
| admissibleExponent_of_block_step_of_padding | |
| (fun h P hP => MatrixAlgorithm.exists_restrict h P hP) hb hΟ hR hstep | |
| theorem admissibleExponent_of_rankAtMost {n R : β} (hn : 2 β€ n) | |
| (hRank : Tensor.RankAtMost (Tensor.matrixMultiplication n n n) R) | |
| {Ο : β} (hΟ : 2 β€ Ο) (hR : (R : β) β€ (n : β) ^ Ο) : | |
| AdmissibleExponent Ο := by | |
| apply admissibleExponent_of_block_step (K := 6 * R * n ^ 2) hn hΟ hR | |
| intro m P hP | |
| obtain β¨Q, hQ, hcostβ© := RecursiveBlock.rank_block_step hRank P hP | |
| exact β¨Q, hQ, hcost.leβ© | |
| end MatrixMultiplication.Foundation.Arithmetic | |
| end | |
| end MatrixAllFields | |
| end OAI | |