GiNaC is Not a Computer Algebra System
Chris Dams∗
September 1, 2006
∗[email protected] A bit of history
Around 1998 the XLOOPs project had problems with their use the Maple CAS.
Maple was not very suitable to support large projects.
Major rewrites were necessary every new Maple version. Use a standardized language
Use C++ and implement algebraic capabilities within it. • No need to invent your own language. • A mainstream language has good tools available. • There is a standard library with good data structures. • Support for modern programming techniques. • Use it seamlessly with any other C/C++-library. • Operator overloading. GiNaCs classes
ex basic symbol expairseq constant exprseq pseries power numeric wildcard structure relational matrix lst idx function ncmul add indexed mul abstract class class template tensor
varidx container class atomic class
fderivative A basic clifford tensdelta color is derived wraps ...... from B ex Example code: integrating delta functions
The Dirac-delta function is a “function” that has the properties • δ(x) is zero for x 6= 0; • δ(x − x ) dx = 1; Z 0 • think of it as the mass density of a point particle.
For an integral containing a delta function we have
f(x)δ(x − x ) dx = f(x ). Z 0 0 More generally f(x ) f(x)δ(g(x)) dx = i . ′ Z X |g (xi)| g(xi)=0 Main program int main() { symbol x("x"); ex e = integ(x,1)*delta(2*x-1)*exp(x); cout << "The expression " << e << endl; cout << "can be simplified into " << trydeltaintegrals(e) << endl; return 0; }
The output is: The expression delta(-1+2*x)*exp(x)*integ(x,1) can be simplified into 1/2*exp(1/2) The function that makes it possible
DECLARE_FUNCTION_2P(integ); REGISTER_FUNCTION(integ, dummy());
DECLARE_FUNCTION_1P(delta); REGISTER_FUNCTION(delta, dummy()); ex trydeltaintegrals(const ex &x) { if (is_a
for (int i=0; i ex delta_arg = x.op(j).op(0); if (!delta_arg.is_polynomial(integ_var)) continue; if (delta_arg.degree(integ_var) != 1) continue; ex a = delta_arg.coeff(integ_var, 1); ex b = delta_arg.coeff(integ_var, 0); ex result = x/x.op(i)/x.op(j); result = result.subs( integ_var == -b/a ); result = result * power(abs(a), -x.op(i).op(1)); result = trydeltaintegrals(result); return result; Features • Arbitrary precision arithmetic for integers, fractions and reals; • data structures: lst, exvector, exmap, exhashmap; • linear algebra: Linear systems, matrix operations; • algebraic substitution: apbqarbs → ap+rbq+s by using the method .subs( power(wild(0),wild(1)) * power(wild(0),wild(2)) == power(wild(0), wild(1)+wild(2)), subs_options::algebraic ); • polynomial arithmetic: expanding, collecting, division, GCD, LCM, resultant, square-free decomposition; • analysis: Symbolic differentiation/Series expansion; • HEF: Indexed objects, clifford algebra, lie algebras of SU(2) and SU(3); • automatic dummy index renaming: 2 f .subs(f == x_i*y_i) → xiyixjyj; • generic clifford algebras; • taking real and imaginary parts of expressions; • numeric integration; • series expansion of symbolic integrals. Fundamental concepts • Reference counting for memory management; • most copies are shallow; • automatic evaluation: – x + x → 2x; – ex::ex(const basic &other) for conversion; – calls virtual basic::eval() methods; – only operations that are of complexity N log(N)p; ptr Also included in most Linux distributions. Authors/contributors • Founding fathers: Christian Bauer, Alexander Frink, Richard Kreckel; • contributers: Roberto Bagnara, Jonathan Brandmeyer, Matti Peltom¨aki, Do Hoang Son, Bernard Parisse, Pearu Peterson, Ben Sapp, Stefan Weinzierl, Oliver Welzel • active developers: Christian Bauer, Chris Dams, Vladimir Kisil, Richard Kreckel, Alexei Sheplyakov, Jens Vollinga.