feat: introduce matrix layer with end-to-end harness#40
Merged
Conversation
Adds a separate matrix e-graph (MatrixExpr / MatrixOp / MatrixPipeline) with constructors var_matrix, const_matrix, matmul, transpose and one rewrite rule (transpose∘transpose → x). Lowering unrolls a matrix expression into the ArithExpr for a chosen output cell, allocating scalar input slots row-major per var_matrix occurrence (shared base across repeated indices), which lets the existing scalar pipeline emit and link without a separate matrix runtime. trzk gains --matrix; matrix specs declare `def spec : MatrixExpr` and `def out : Nat × Nat`. Three integration ops exercise the pipeline end-to-end against frozen unseeded vectors and fuzz: matrix_matmul, matrix_matmul_const, matrix_transpose_matmul (the last verifies the rewrite rule fires during saturation). run.sh and CI standardise on <family>_<suffix> op naming (arith_add0, matrix_matmul, …). Other matrix ops named in the umbrella plan (hadamard, pointwise_scalar, reshape, permute) are deferred to the sub-changes whose harness will exercise each; nothing speculative lands here.
Matrix specs previously lowered a single chosen output cell, leaving the other m*n-1 cells untested. This adds `emitMatrixFunction` to Emit.lean which emits `-> [u32; N]` returning all cells row-major, updates Compile.lean to lower and saturate every cell, and wires the harness, verifier, generator, and test vectors through the change. The three matrix integration ops now verify the complete 2×2 output (4 values) on every vector instead of one cell.
Collaborator
|
All checks pass, good step by step approach. |
manuelpuebla
approved these changes
May 28, 2026
manuelpuebla
left a comment
Collaborator
There was a problem hiding this comment.
Good step by step tactics for maximal clarity of development. Couldn't agree more.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MatrixExpr/MatrixOp/MatrixPipeline) with constructorsvar_matrix,const_matrix,matmul,transpose, plus one rewrite ruletranspose∘transpose → xso the saturation path is non-trivially exercised.MatrixLower(unrolls a matrix expression into a dense grid ofArithExprcells, allocating scalar input slots row-major pervar_matrixoccurrence with a shared base for repeated indices) and atrzk --matrixCLI flag that drives the matrix pipeline through to scalar codegen — no separate Rust matrix runtime. The pipeline lowers all output cells and emits a single function returning[u32; N]row-major.matrix_matmul,matrix_matmul_const,matrix_transpose_matmul(the last verifies the rewrite rule fires during saturation). Each op verifies the complete output matrix (all 4 cells for 2×2), not a single chosen cell.run.shand CI on<family>_<suffix>op naming (arith_add0,matrix_matmul, …); CI gainsarith_mul_chain(was missing) and all three matrix ops.Test plan
lake buildcleantranspose∘transpose → xrule actually fires by inspecting the post-saturation matrix expression artifact (transposes gone)