{"id":13830918,"url":"https://github.com/lecopivo/EigenLean","last_synced_at":"2025-07-09T13:30:37.876Z","repository":{"id":53933715,"uuid":"485067517","full_name":"lecopivo/EigenLean","owner":"lecopivo","description":"Lean 4 interface to Eigen","archived":false,"fork":false,"pushed_at":"2024-12-13T21:27:45.000Z","size":38,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T08:55:35.758Z","etag":null,"topics":["eigen3","lean4"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lecopivo.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-04-24T15:38:07.000Z","updated_at":"2024-12-13T21:27:49.000Z","dependencies_parsed_at":"2024-05-28T17:05:06.003Z","dependency_job_id":"d825fb19-3fe2-4867-abe2-40e3ede08bb0","html_url":"https://github.com/lecopivo/EigenLean","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lecopivo/EigenLean","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lecopivo%2FEigenLean","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lecopivo%2FEigenLean/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lecopivo%2FEigenLean/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lecopivo%2FEigenLean/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lecopivo","download_url":"https://codeload.github.com/lecopivo/EigenLean/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lecopivo%2FEigenLean/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264467893,"owners_count":23612996,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eigen3","lean4"],"created_at":"2024-08-04T10:01:12.407Z","updated_at":"2025-07-09T13:30:37.870Z","avatar_url":"https://github.com/lecopivo.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# Lean 4 interface to Eigen\n\nProof of concept for interfacing Eigen's linear solvers in Lean 4.\n\n# Installation\n\nTo compile and build examples:\n```\nlake build dense sparse\n```\n\nIt is required that you have `cmake` and `eigen3` installed on your system. For example on Ubuntu you can install these with:\n```\nsudo apt-get install libeigen3-dev cmake\n```\n\n\n# Dense Matrix\n\nAn example of solving simple 2x2 system with LDLT:\n```\ndef main : IO Unit := do\n  let A : Matrix 2 2 := ⟨FloatArray.mk #[2,1,1,2], by native_decide⟩\n  let b ← Matrix.rand 2 1\n  let x := A.ldlt.solve b\n  let b' := A.matmul x\n\n  IO.println s!\"A = {A}\"\n  IO.println s!\"b = {b}\"\n  IO.println s!\"x = A⁻¹*b = {x}\"\n  IO.println s!\"A*x = {b'}\"\n```\nRunning this produces\n```\n$ ./.lake/build/bin/dense\n\nA = [2.000000, 1.000000, 1.000000, 2.000000]\nb = [0.541198, 0.432483]\nx = A⁻¹*b = [0.216638, 0.107922]\nA*x = [0.541198, 0.432483]\n```\n\n# Sparse Matrix\n\n```\ndef main : IO Unit := do\n  let entries : Array (Triplet 2 2) := (#[(0,0,2.0), (1,0,1.0), (1,1,2.0), (0,1, 1.0)] : Array (Nat×Nat×Float))\n  let A := SparseMatrix.mk entries\n  let b ← Matrix.rand 2 1\n  let x := A.simplicialLLT.solve b\n  let b' := A.densemul x\n\n  IO.println s!\"A  = {A.toDense}\"\n  IO.println s!\"b  = {b}\"\n  IO.println s!\"x = A⁻¹*b = {x}\"\n  IO.println s!\"A*x = {b'}\"\n```\nRunning this produces\n```\n$ ./.lake/build/bin/sparse\n\nA  = [2.000000, 1.000000, 1.000000, 2.000000]\nb  = [0.604736, 0.884092]\nx = A⁻¹*b = [0.108460, 0.387816]\nA*x = [0.604736, 0.884092]\n```\n\n\n# Contributing\n\nTesting this library on Windows and Mac would be highly appreciated and setting up CI for all platforms.\n\nWritting more bindings for basic operations. This usuall consists of two parts:\n\n1. Declare Lean function\n```\n@[extern \"eigenlean_matrix_matmul\"]\nopaque Matrix.matmul {n m k : USize} (A : @\u0026 Matrix n m) (x : @\u0026 Matrix m k) : Matrix n k\n```\n\n2. Provide C/C++ implementation\n```\nextern \"C\" LEAN_EXPORT lean_obj_res eigenlean_matrix_matmul(size_t n, size_t m, size_t k, b_lean_obj_arg _A, b_lean_obj_arg _x){\n\n  auto const\u0026 A = to_eigenMatrix(_A, n, m);\n  auto const\u0026 x = to_eigenMatrix(_x, m, k);\n\n  lean_object * result = lean_alloc_sarray(sizeof(double), n*k, 1);\n\n  auto y = Eigen::Map\u003cEigen::MatrixXd\u003e(lean_float_array_cptr(result), n, k);\n\n  y = A*x;\n\n  return eigenlean_array_to_matrix(result, m, 1, nullptr);\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flecopivo%2FEigenLean","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flecopivo%2FEigenLean","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flecopivo%2FEigenLean/lists"}