I am trying to get some experience with using Lean 4 and write some functional programs that I can use for my daily work. One feature I'd like to have is to interface Lean 4 with external C/C++ code to do heavy computations such as matrix multiplication. Note: I just need the computation, not the theorem proving capabilities of lean for this exercise.
Lean 4's FFI documentation said that is unstable upfront:
NOTE: The current interface was designed for internal use in Lean and should be considered unstable. It will be refined and extended in the future.
But it's already 12 versions since Lean 4' initial release, and I guess it's not a good idea to wait until the FFI is eventually stable. And I don't mind refining my program later on when the FFI is refined/extended. Hence the question here.
Can the Lean4 FFI (as of 4.12) be used to interface with external C++ code for matrix operations? In particular, does it support passing dense or sparse matrices/arrays between Lean and C++?
Are there examples/tutorials for doing this kind of work?
Real
even via FFI. You can compute with arrays of machine types likeFloat
,Int64
,UInt64
and easily do FFI.Nat
andInt
may be more subtle since they are unbounded numbers. $\endgroup$Float
. The goal is to just to do some regular programming using Lean as a upgraded FP language (as a learning exercise). Hopefully, this will be enough motivation for exploring lean programming and the new things with dependent types. $\endgroup$