# complex conjugation

chrisd at sci.kun.nl chrisd at sci.kun.nl
Sun Nov 23 00:46:18 CET 2003

```Hi,

On Sat, 22 Nov 2003, Andrius Kurtinaitis wrote:

> it appears that the GiNaC expressions do not support the complex
> conjugation... :-(

That's funny. Actually I was just implementing this. At the moment I am
mostly getting segmentation faults though, but perhaps if you (and I) are
lucky it will appear in GiNaC within not to much time.

> I need it, but I do not know yet how to implement it.
> Has anybody tried to do this?

You could write a costum conjugation function suited for you application.
This may look like

struct Complexconj : public GiNaC::map_function
{  public:
GiNaC::ex operator()(const GiNaC::ex&);
};

Complexconj complexconj;

ex Complexconj::operator()(const ex&x)
{  if(is_a<numeric>(x))
return ex_to<numeric>(x).real()-I*ex_to<numeric>(x).imag();
else if(x.match(vs(wild())))
return vsbar(x.op(0));
else if(x.match(vsbar(wild())))
return vs(x.op(0));
else if(x.match(us(wild())))
return usbar(x.op(0));
else if(x.match(usbar(wild())))
return us(x.op(0));
else if(x==pr)
return pl;
else if(x==pl)
return pr;
else if(is_a<power>(x))
return power(operator()(x.op(0)),x.op(1));
else if(is_a<lst>(x))
{  lst result;
for(int i=x.nops()-1;i>=0;--i)
result.append(operator()(x.op(i)));
return result;
}
return x.map(*this);
return x;
}

depending on the application you have. Note that the above will not
compile unless you have some more definitions around.

> Clearly conjugation is a function ;-)

Well, it is not a GiNaC::function. It is a C++ function.

> Ok, i'll try to read the tutorial. Let's see if I get this working...

Good luck,
Chris Dams

```