[GiNaC-list] user defined functions and constants

Gunnar Birke gunnar.birke at online.de
Sat Sep 21 20:07:12 CEST 2013


Hello guys,

I'm working on a CAS for school mathematics in C++ and want to use GiNaC 
as a backend.
In a CAS, the user has the option to define constants and functions, for 
example

def a = 5
def f(x) = 2 * x + 3
def g(x, y) = x + 2y

and then use these definitions like this

f(3) + a * 4 - g(4, 5)

Implement this for constants is pretty straight forward in GiNaC with 
the subs() method and an exmap which contains all defined constants.
For the example above, it would be enough to insert a symbol with the 
value a together with the expression 5 into the map, then call subs() 
with it.
Enable the same support for functions however seems very difficult, as 
functions can only defined at compile time with a macro.
And using subs() seems a bit silly with functions:

GiNaC::ex ex(f(2));
ex.subs(f(2) == f(2)); //what?

This problem seems pretty common to me and I really wondered why GiNaC 
has no options to archive this. Did I miss something?



More information about the GiNaC-list mailing list