top band

Generating Fast and Correct Code with SymPy

Jim Crist

Audience level:


Have you ever derived some math on paper, only to mistype it into your code? With the code-generation tools provided by SymPy, these errors are a thing of the past! Learn about how SymPy can help ensure your equations are correct, and also generate native code for fast evaluation. This poster session will cover how code-generation works under-the-hood, as well as demonstrate the features provided.


[SymPy]( is a computer algebra system written in pure python. It allows the user to create and solve complicated math quickly and easily. As an added bonus, having software that knows about math allows for easy [code generation]( This takes an equation and compiles it down to C, Fortran, or any other language to allow for fast evaluation. Because the equation was already derived by SymPy, there's no danger of typing errors in converting it to another language. SymPy handles that for you! This poster session will cover the why and how of SymPy's code generation utilities. Topics covered include: - SymPy "expression trees" (very similar to how Python represents code as [abstract syntax trees]( - Code printing with the [visitor pattern]( - Wrapping C or Fortran code with Python - How Codegen can improve your workflow
bottom band background