[GiNaC-list] Substitution troubles

Jeremy Jay dinkumator at gmail.com
Mon Feb 23 18:37:39 CET 2009

Hello all, I'm new to GiNaC, but so far I've been very impressed by its
power. But, I seem to be having a problem with the substitutions, can
anyone tell me what I'm doing wrong?  A short example is the following


#include <iostream>
#include <ginac/ginac.h>

using namespace std;
using namespace GiNaC;


// delta( c_i, c_j ) = 1 if c_i==c_j otherwise 0
REGISTER_FUNCTION(delta, dummy());


int main(int argc, char **argv) {
	symbol q("q"), c0("c0"), c1("c1"), c2("c2");

	ex poly( (1-delta(c0,c1))*(1-delta(c0,c2)) );

	cout << "START             : " << poly << endl;

	poly = poly.subs( 1 == q );
	cout << "sub 1 => q        : " << poly << endl;
	return 0;


which gives the output:


START             : 1-delta(c0,c2)-delta(c0,c1)+delta(c0,c2)*delta(c0,c1)
sub 1 => q        : 1-delta(c0,c2)-delta(c0,c1)+delta(c0,c2)*delta(c0,c1)


which is not what I would expect. I've also tried using the 'numeric'
type instead of the literal 1's, but get the same effect. Am I missing
something?  BTW, for anyone interesed in the point of this, I'm trying
to implement the algorithm in this paper:

Thanks in advance!


More information about the GiNaC-list mailing list