views:

1428

answers:

4
+6  Q: 

Symbolic math lib

I have a planned project that will need to manipulate symbolic expressions like:

a * b = c^2 + sin(d)

I'm wondering what libs are out there for this kind of thing.

Two that I found a while ago are openaxiom and FriCAS. neither of these seem like a good fit. An ideal lib would be a light as possible. At a minimum it must be able to define expressions as some type of data structure and, once values are assigned to the variables, evaluate expressions. I would prefer that it have as many of the following as possible:

  • tools to transform expressions and ensure that the transformations are algebraically valid.
  • tools to perform differentiation
  • tools to parse expressions from text
  • have some form of re-wright rule engine
  • be able to "compile" expressions for fast execution
  • emit C code that equates to execution
  • emit ASM for the same

C linkage is a major boon but C++ would do, other options (C#,lisp) might work but are way less desirable

A: 

Checkout the AXIOM library, I don't know that it is exactly what you want... but it looks reasonable.

ceretullis
I think that is the impetus for OpenAXIOM. It's also kind of heavy (likely to heavy) for what I need.
BCS
+2  A: 

I know you're looking for C, but...

Sympy is a truly amazing Python library. One of the great things about it is how effortless it is: operator overloading automatically changes normal operators and functions into symbolic computations. It's got a very active user community, a lot of features, and Python is really easy to interface with from C.

Dan
How hard is it to use Python libs from C without needing to install python? I'm thinking including python as part of the executable and including the .py's inside as well. A totally transparent wrapping?
BCS
There are ways to wrap up the whole Python exec and libs, though I am not familiar with them personally. But embedding Python is *surprisingly* easy in general, and you get a nice scripting language to boot. I suggest looking at the code for Pidgin, which embeds Python, as an example!
Dan
+4  A: 

In the spirit of earlier posters you could look at Wikipedia's Comparison of computer algebra systems, though there is no information on the page just now about programatic interfaces and/or bindings.


I take it back. Some of the notes are useful this way. It seem that GiNaC is a C++ library. A bunch of them are in the form of Java or Python libraries.

dmckee
I remember that page from my last go around at this... I starting to think there might just not be what I want.
BCS
A: 

Maybe this is helpful:

The Spirit framework enables a target grammar to be written exclusively in C++. Inline EBNF grammar specifications can mix freely with other C++ code and, thanks to the generative power of C++ templates, are immediately executable.

As introduction example they build a basic calculator. Seems quite the thing you are looking for.

dummy
Hm... I saw that and didn't like the 1.4MB of code, so I wrote my own version: 1.6 kLOC. -> http://www.dsource.org/projects/scrapple/browser/trunk/dparser
BCS