openAI-math-dataset / lean /OAI /LinearAlgebra /MatrixFields /Construction /ComplexExpressionFamily.lean
Download lean/OAI/LinearAlgebra/MatrixFields/Construction/ComplexExpressionFamily.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.35 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/LinearAlgebra/MatrixFields/Construction/ComplexExpressionFamily.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/LinearAlgebra/MatrixFields/Construction/ComplexExpressionFamily.lean
-
curl -L -o ComplexExpressionFamily.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/LinearAlgebra/MatrixFields/Construction/ComplexExpressionFamily.lean
2.35 kB
| import Mathlib | |
| import OAI.LinearAlgebra.MatrixFields.Arithmetic.ComplexArithmeticLowerBound | |
| namespace OAI | |
| namespace MatrixAllFields | |
| open scoped BigOperators Topology Polynomial | |
| noncomputable section | |
| open scoped BigOperators | |
| namespace MatrixMultiplication.Foundation.Arithmetic.Expression | |
| variable {Input Output : Type*} | |
| structure CompiledFamily [Fintype Output] (expressions : Output → Expression Input) where | |
| registers : ℕ | |
| program : Program Input registers | |
| output : Output → Fin registers | |
| correct : ∀ inputs i, program.eval inputs (output i) = (expressions i).eval inputs | |
| cost_eq : program.cost = ∑ i, (expressions i).cost | |
| def compileFinFamily : (n : ℕ) → (expressions : Fin n → Expression Input) → | |
| CompiledFamily expressions | |
| | 0, _ => | |
| { registers := 0 | |
| program := Program.nil | |
| output := Fin.elim0 | |
| correct := by | |
| intro inputs i | |
| exact Fin.elim0 i | |
| cost_eq := by simp [Program.cost] } | |
| | n + 1, expressions => | |
| let p := compile (expressions 0) | |
| let q := compileFinFamily n (fun i => expressions i.succ) | |
| { registers := p.registers + q.registers | |
| program := p.program.append q.program | |
| output := Fin.cases (Program.oldIndex _ _ p.output) | |
| (fun i => Program.newIndex _ _ (q.output i)) | |
| correct := by | |
| intro inputs i | |
| refine Fin.cases ?_ (fun j => ?_) i | |
| · exact (Program.eval_append_old p.program q.program inputs p.output).trans | |
| (p.correct inputs) | |
| · exact (Program.eval_append_new p.program q.program inputs (q.output j)).trans | |
| (q.correct inputs j) | |
| cost_eq := by | |
| rw [Program.cost_append, p.cost_eq, q.cost_eq, Fin.sum_univ_succ] } | |
| def compileFamily [Fintype Output] (expressions : Output → Expression Input) : | |
| CompiledFamily expressions := | |
| let e := Fintype.equivFin Output | |
| let p := compileFinFamily (Fintype.card Output) (fun i => expressions (e.symm i)) | |
| { registers := p.registers | |
| program := p.program | |
| output := fun i => p.output (e i) | |
| correct := by | |
| intro inputs i | |
| simpa only [Equiv.symm_apply_apply] using p.correct inputs (e i) | |
| cost_eq := by | |
| rw [p.cost_eq] | |
| exact e.symm.sum_comp (fun i => (expressions i).cost) } | |
| end MatrixMultiplication.Foundation.Arithmetic.Expression | |
| end | |
| end MatrixAllFields | |
| end OAI | |