[GiNaC-list] using an "undefined" function

Alexei Sheplyakov alexei.sheplyakov at gmail.com
Thu Sep 9 18:54:53 CEST 2010


Hello,

On Thu, Sep 9, 2010 at 4:48 PM, Jose Antonio Garcia Peiro
<jgpeiro at gmail.com> wrote:

> I try to use an undefined function, such as f(x), instead of
> f(x)=3*x+... I know that the function depends on variable x, but not
> in what form.
> With SymbolicC++, if I define Symbolic x("x"), f[x] and g[x], the
> operation diff( f+g ,x ) returns diff(f,x)+diff(g,x). (the
> differentiation rule of sum operator)
> It is possible to make this with GiNaC?

You might want to try this:

#include <iostream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;

DECLARE_FUNCTION_1P(f)
DECLARE_FUNCTION_1P(g)
REGISTER_FUNCTION(f, dummy())
REGISTER_FUNCTION(g, dummy())

int main(int argc, char** argv)
{
       symbol x("x");
       ex e = f(x) + g(x);
       ex e_prime = e.diff(x);
       cout << "d/dx(" << e << ") = " << e_prime << endl;
       return 0;
}

Best regards,
        Alexei


More information about the GiNaC-list mailing list