ginac is not a computer algebra system
play

GiNaC is Not a Computer Algebra System Chris Dams September 1, 2006 - PowerPoint PPT Presentation

GiNaC is Not a Computer Algebra System Chris Dams September 1, 2006 Chris.Dams@mi.infn.it 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.


  1. GiNaC is Not a Computer Algebra System Chris Dams ∗ September 1, 2006 ∗ Chris.Dams@mi.infn.it

  2. 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.

  3. 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.

  4. wraps class template basic atomic class ex symbol container class derived constant abstract class from is A B numeric wildcard structure matrix ... relational tensor tensdelta varidx basic idx ... lst clifford indexed exprseq color GiNaCs classes function fderivative pseries ncmul power mul expairseq add ex

  5. Example code: integrating delta functions The Dirac-delta function is a “function” that has the properties • δ ( x ) is zero for x � = 0; � • δ ( x − x 0 ) dx = 1; • think of it as the mass density of a point particle. For an integral containing a delta function we have � f ( x ) δ ( x − x 0 ) dx = f ( x 0 ) . More generally f ( x i ) � � f ( x ) δ ( g ( x )) dx = | g ′ ( x i ) | . g ( x i )=0

  6. 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)

  7. 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<mul>(x)) ... code for handling multiplications ... if (is_a<add>(x)) return x.map(trydeltaintegrals); return x; }

  8. The code for handling multiplications for (int i=0; i<x.nops(); ++i) { if (!is_ex_the_function(x.op(i), integ)) continue; ex integ_var = x.op(i).op(0); for (int j=0; j<x.nops(); ++j) { if (!is_ex_the_function(x.op(j), delta)) continue; ... more checks and returning result ... } } return x;

  9. More checks and returning result 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;

  10. Features • Arbitrary precision arithmetic for integers, fractions and reals; • data structures: lst, exvector, exmap, exhashmap; • linear algebra: Linear systems, matrix operations; • algebraic substitution: a p b q a r b s → a p + r b q + 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 );

  11. • 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: f 2 . subs(f == x_i*y_i) → x i y i x j y j ; • generic clifford algebras; • taking real and imaginary parts of expressions; • numeric integration; • series expansion of symbolic integrals.

  12. Fundamental concepts • Reference counting for memory management; • most copies are shallow; • automatic evaluation: – x + x → 2 x ; – ex::ex(const basic &other) for conversion; – calls virtual basic::eval() methods; – only operations that are of complexity N log( N ) p ;

  13. ptr<basic> ex::construct_from_basic(const basic & other) { if (!(other.flags & status_flags::evaluated)) { const ex & tmpex = other.eval(1); if ((other.get_refcount() == 0) && (other.flags & status_flags::dynallocated)) delete &other; return tmpex.bp; } else { if (other.flags & status_flags::dynallocated) { return ptr<basic>(const_cast<basic &>(other)); } else { basic *bp = other.duplicate(); bp->setflag(status_flags::dynallocated); return bp; } } }

  14. Fundamental Concept (continued) • built-in methods use virtual functions (extendable!); • map functions & type switch; • hashing (Fibonacci hash) for fast comparison.

  15. Projects using GiNaC • Feelfem (finite element method (FEM) code generator); • gTybalt (combines GiNaC with TeXmacs and Root into an interactive computer algebra system); • Nested sums (supports for some kind of transcendental functions); • PURRS (C++ library for solving recurrence relations); • PyGiNaC (Python interface to GiNaC); • Swiginac (Python interface to GiNaC); • Antipodes (computes divergent terms arising in HEF-computations); • Ecco (simulation of (electro)chemical reaction kinetics); • ORSA (Orbit Reconstruction, Simulation and Analysis); • SyFi (finite element method).

  16. Get it from http://www.ginac.de 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.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend