lecopivo / EigenLean

Lean 4 interface to Eigen

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lean 4 interface to Eigen

Proof of concept for interfacing Eigen’s linear solvers in Lean 4.

To compile and build examples:

lake build dense sparse

Example of solving simple 2x2 system with LDLT:

def main : IO Unit := do
  let A : Matrix 2 2 := ⟨FloatArray.mk #[2,1,1,2], by native_decide⟩
  let b : Matrix 2 1 := ⟨FloatArray.mk #[1,1], by native_decide⟩
  IO.println A
  IO.println b
  IO.println (A.ldlt.solve b)

To run the example ./build/bin/dense.

Example of initializing sparse matrix:

def main : IO Unit := do
  let entries : Array (Triplet 2 2) := (#[(0,0,1.0), (1,1,-1.0), (0,1, 2.0)] : Array (Nat×Nat×Float))
  let B := SparseMatrix.mk entries
  IO.println B.toDense

To run the example ./build/bin/sparse.

About

Lean 4 interface to Eigen


Languages

Language:C++ 52.0%Language:Lean 43.0%Language:C 2.9%Language:CMake 2.1%