Download data/lean/OAI/LinearAlgebra/MatrixFields/Model.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 2.96 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Model.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixFields/Model.lean
-
curl -L -o Model.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Model.lean
2.96 kB
| import Mathlib | |
| namespace OAI | |
| open scoped BigOperators Topology Polynomial | |
| namespace MatrixAllFields | |
| noncomputable section | |
| open scoped BigOperators | |
| namespace MatrixMultiplication.Arithmetic | |
| inductive Gate (F Input Register : Type*) where | |
| | constant : F β Gate F Input Register | |
| | input : Input β Gate F Input Register | |
| | add : Register β Register β Gate F Input Register | |
| | sub : Register β Register β Gate F Input Register | |
| | mul : Register β Register β Gate F Input Register | |
| namespace Gate | |
| variable {F Input Register : Type*} | |
| def eval [Field F] (inputs : Input β F) (registers : Register β F) : | |
| Gate F Input Register β F | |
| | .constant z => z | |
| | .input i => inputs i | |
| | .add i j => registers i + registers j | |
| | .sub i j => registers i - registers j | |
| | .mul i j => registers i * registers j | |
| def cost : Gate F Input Register β β | |
| | .constant _ => 0 | |
| | .input _ => 0 | |
| | .add _ _ => 1 | |
| | .sub _ _ => 1 | |
| | .mul _ _ => 1 | |
| end Gate | |
| inductive Program (F Input : Type*) : β β Type _ where | |
| | nil : Program F Input 0 | |
| | step {r : β} : Program F Input r β Gate F Input (Fin r) β Program F Input (r + 1) | |
| namespace Program | |
| variable {F Input : Type*} | |
| def eval [Field F] : {r : β} β Program F Input r β (Input β F) β Fin r β F | |
| | 0, .nil, _ => Fin.elim0 | |
| | _ + 1, .step p g, inputs => | |
| Fin.cases (g.eval inputs (p.eval inputs)) (p.eval inputs) | |
| def cost : {r : β} β Program F Input r β β | |
| | 0, .nil => 0 | |
| | _ + 1, .step p g => p.cost + g.cost | |
| end Program | |
| abbrev MatrixInput (a b c : β) := (Fin a Γ Fin b) β (Fin b Γ Fin c) | |
| def matrixInputs {F : Type*} {a b c : β} | |
| (A : Matrix (Fin a) (Fin b) F) (B : Matrix (Fin b) (Fin c) F) : | |
| MatrixInput a b c β F | |
| | .inl (i, j) => A i j | |
| | .inr (j, k) => B j k | |
| structure MatrixAlgorithm (F : Type*) (a b c : β) where | |
| registers : β | |
| program : Program F (MatrixInput a b c) registers | |
| output : Fin a β Fin c β Fin registers | |
| namespace MatrixAlgorithm | |
| variable {F : Type*} [Field F] {a b c : β} | |
| def eval (P : MatrixAlgorithm F a b c) | |
| (A : Matrix (Fin a) (Fin b) F) (B : Matrix (Fin b) (Fin c) F) : | |
| Matrix (Fin a) (Fin c) F := | |
| fun i k => P.program.eval (matrixInputs A B) (P.output i k) | |
| def Correct (P : MatrixAlgorithm F a b c) : Prop := | |
| β (A : Matrix (Fin a) (Fin b) F) (B : Matrix (Fin b) (Fin c) F), P.eval A B = A * B | |
| def cost (P : MatrixAlgorithm F a b c) : β := P.program.cost | |
| end MatrixAlgorithm | |
| /-- Positive slack, one uniform constant, and a correct program at every size. -/ | |
| def AdmissibleExponent (F : Type*) [Field F] (Ο : β) : Prop := | |
| β Ξ΅ : β, 0 < Ξ΅ β β C : β, 0 < C β§ | |
| β n : β, 1 β€ n β β P : MatrixAlgorithm F n n n, | |
| P.Correct β§ (P.cost : β) β€ C * (n : β) ^ (Ο + Ξ΅) | |
| def omega (F : Type*) [Field F] : β := sInf {Ο : β | AdmissibleExponent F Ο} | |
| end MatrixMultiplication.Arithmetic | |
| end | |
| end MatrixAllFields | |
| end OAI | |