Mathematical optimization has vast applications, e.g., image processing, machine learning. It has a huge impact on the current state of computer science and software engineers.
Solving optimization problems involves many challenges. First, we need to build and encode the models correctly. Second, almost all useful models are computationally expensive and we need to speed them up. Finally, we need to be able to feed the model to optimization solvers to get the final numerical results.
Fortunately, we find that Haskell, with its powerful type system and abstraction power, is perfect for this type of problem.
We introduce HashedExpression, a Haskell-embedded domain-specific language that allows us to build and solve optimization problems. It provides users with a type-safe, correct-by-construction interface that uses Haskell type-level programming to express constraints on correctness which the compiler uses to flag many modeling errors as type errors (at compile time).
The library implements symbolic expressions with the "hash consing" technique to achieve common subexpression elimination. We will show how using monadic type class instances help us abstract away details of the underlying lookup table and implement symbolic reverse-mode differentiation on top of it.
For high-performance purposes, we generate low-level C/C++ code for symbolic expressions and provide bindings to open-source optimization solvers such as Ipopt or L-BFGS-B.