Next: Solving linear systems of equations, Previous: Multiple polylogarithms, Up: Methods and functions
For dealing with complex expressions there are the methods
ex ex::conjugate();
ex ex::real_part();
ex ex::imag_part();
that return respectively the complex conjugate, the real part and the
imaginary part of an expression. Complex conjugation works as expected
for all built-in functions and objects. Taking real and imaginary
parts has not yet been implemented for all built-in functions. In cases where
it is not known how to conjugate or take a real/imaginary part one
of the functions conjugate, real_part or imag_part
is returned. For instance, in case of a complex symbol x
(symbols are complex by default), one could not simplify
conjugate(x). In the case of strings of gamma matrices,
the conjugate method takes the Dirac conjugate.
For example,
{
varidx a(symbol("a"), 4), b(symbol("b"), 4);
symbol x("x");
realsymbol y("y");
cout << (3*I*x*y + sin(2*Pi*I*y)).conjugate() << endl;
// -> -3*I*conjugate(x)*y+sin(-2*I*Pi*y)
cout << (dirac_gamma(a)*dirac_gamma(b)*dirac_gamma5()).conjugate() << endl;
// -> -gamma5*gamma~b*gamma~a
}
If you declare your own GiNaC functions and you want to conjugate them, you
will have to supply a specialized conjugation method for them (see
Symbolic functions and the GiNaC source-code for abs as an
example). GiNaC does not automatically conjugate user-supplied functions
by conjugating their arguments because this would be incorrect on branch
cuts. Also, specialized methods can be provided to take real and imaginary
parts of user-defined functions.