SymPy to CSymPy

66 views
Skip to first unread message

F. B.

unread,
Jun 11, 2014, 1:49:24 PM6/11/14
to sy...@googlegroups.com
I was pondering about a possible way to create a C++ code generator from SymPy.

The latest C++ standard (C++11) introduced some kinds of features that could make the code generation easier, especially lambda functions and auto variables. The boost C++ library also offers a great range of tools to simulate Python's capabilities in C++.

It looks to me like CSymPy is going to keep some work off SymPy. I don't think though that a code generator to C++ is a too hard task, compared to rewriting and maintaining the same project in another language.

SymPy has an extensive test coverage, and most objects inherit from Basic. A possible idea is to add __getattr__ and __setattr__ to Basic in a special testing mode, these two methods would simply record:
  • which variables are added to the objects through monkey patching and their types
  • the types of variables passed to methods.
  • the types of variables returned by methods.

Python has the native ast module to parse its own code, which can be used to create an AST walker to print the generated C++ code.

This is just an idea, but I think that if this were ever realized, it would solve the issues of forking SymPy and CSymPy development, and at the same time allow to review SymPy's code by examine how the parser interprets it.

Ondřej Čertík

unread,
Jun 13, 2014, 1:13:45 PM6/13/14
to sympy
Hi Francesco,
If you want to give it a try, please do. Personally, given our limited
resources, I just concentrate on having a small performing C++
library, and thin wrappers to Python, Julia and other languages. I see
it as a complement to SymPy, not a fork. Only with a performing
library like csympy, the SymPy ecosystem is complete. To perhaps get a
sense of what kind of issues affect performance, here is a recent PR:

https://github.com/sympy/csympy/pull/192

In my experience, one just has to take the tool, C++ in this case, and
think hard how to get the most performing code. I don't want to worry
about other levels of complexity, like Cython or Python or some
automatic translation code. Also it's worth noting that there are
quite a few very fast open source libraries out there for some
specialized problems, for example polynomials, trigonometric series,
matrices over integers or rationals, and those we just plan to use.

The bottom line is that CSymPy fixes the problem and it sets the bar.
And then if let's say Julia or some other language/tool becomes a
better solution, somebody can create even a better library. I see it
as an iterative process, and one just has to do a first iteration,
which is CSymPy.

Ondrej
Reply all
Reply to author
Forward
0 new messages