X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;ds=sidebyside;f=ginac%2Fncmul.cpp;h=a5969f317d035bb48db1ce491c12491d491d3f60;hb=ef06261c6354bea6d35e8bcdb89806056d4cccb9;hp=eeadf4e7feb4fa6acf7b48db84062b049e502526;hpb=0633ed8082961673eedc092689e06fa39d6bc322;p=ginac.git diff --git a/ginac/ncmul.cpp b/ginac/ncmul.cpp index eeadf4e7..a5969f31 100644 --- a/ginac/ncmul.cpp +++ b/ginac/ncmul.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's non-commutative products of expressions. */ /* - * GiNaC Copyright (C) 1999-2005 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +28,7 @@ #include "ex.h" #include "add.h" #include "mul.h" +#include "clifford.h" #include "matrix.h" #include "archive.h" #include "indexed.h" @@ -48,7 +49,7 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(ncmul, exprseq, ncmul::ncmul() { - tinfo_key = TINFO_ncmul; + tinfo_key = &ncmul::tinfo_static; } ////////// @@ -59,40 +60,40 @@ ncmul::ncmul() ncmul::ncmul(const ex & lh, const ex & rh) : inherited(lh,rh) { - tinfo_key = TINFO_ncmul; + tinfo_key = &ncmul::tinfo_static; } ncmul::ncmul(const ex & f1, const ex & f2, const ex & f3) : inherited(f1,f2,f3) { - tinfo_key = TINFO_ncmul; + tinfo_key = &ncmul::tinfo_static; } ncmul::ncmul(const ex & f1, const ex & f2, const ex & f3, const ex & f4) : inherited(f1,f2,f3,f4) { - tinfo_key = TINFO_ncmul; + tinfo_key = &ncmul::tinfo_static; } ncmul::ncmul(const ex & f1, const ex & f2, const ex & f3, const ex & f4, const ex & f5) : inherited(f1,f2,f3,f4,f5) { - tinfo_key = TINFO_ncmul; + tinfo_key = &ncmul::tinfo_static; } ncmul::ncmul(const ex & f1, const ex & f2, const ex & f3, const ex & f4, const ex & f5, const ex & f6) : inherited(f1,f2,f3,f4,f5,f6) { - tinfo_key = TINFO_ncmul; + tinfo_key = &ncmul::tinfo_static; } ncmul::ncmul(const exvector & v, bool discardable) : inherited(v,discardable) { - tinfo_key = TINFO_ncmul; + tinfo_key = &ncmul::tinfo_static; } ncmul::ncmul(std::auto_ptr vp) : inherited(vp) { - tinfo_key = TINFO_ncmul; + tinfo_key = &ncmul::tinfo_static; } ////////// @@ -123,7 +124,7 @@ bool ncmul::info(unsigned inf) const return inherited::info(inf); } -typedef std::vector intvector; +typedef std::vector uintvector; ex ncmul::expand(unsigned options) const { @@ -133,8 +134,8 @@ ex ncmul::expand(unsigned options) const // Now, look for all the factors that are sums and remember their // position and number of terms. - intvector positions_of_adds(expanded_seq.size()); - intvector number_of_add_operands(expanded_seq.size()); + uintvector positions_of_adds(expanded_seq.size()); + uintvector number_of_add_operands(expanded_seq.size()); size_t number_of_adds = 0; size_t number_of_expanded_terms = 1; @@ -166,25 +167,26 @@ ex ncmul::expand(unsigned options) const exvector distrseq; distrseq.reserve(number_of_expanded_terms); - intvector k(number_of_adds); + uintvector k(number_of_adds); /* Rename indices in the static members of the product */ exvector expanded_seq_mod; size_t j = 0; - size_t i; - for (i=0; i @@ -333,12 +335,15 @@ ex ncmul::eval(int level) const exvector assocseq; assocseq.reserve(factors); cit = evaledseq.begin(); + make_flat_inserter mf(evaledseq, true); while (cit != citend) - append_factors(assocseq, *cit++); + { ex factor = mf.handle_factor(*(cit++), 1); + append_factors(assocseq, factor); + } // ncmul(x) -> x if (assocseq.size()==1) return *(seq.begin()); - + // ncmul() -> 1 if (assocseq.empty()) return _ex1; @@ -396,17 +401,17 @@ ex ncmul::eval(int level) const size_t assoc_num = assocseq.size(); exvectorvector evv; - unsignedvector rttinfos; + std::vector rttinfos; evv.reserve(assoc_num); rttinfos.reserve(assoc_num); cit = assocseq.begin(), citend = assocseq.end(); while (cit != citend) { - unsigned ti = cit->return_type_tinfo(); + tinfo_t ti = cit->return_type_tinfo(); size_t rtt_num = rttinfos.size(); // search type in vector of known types for (i=0; isetflag(status_flags::dynallocated).eval(); } +ex ncmul::real_part() const +{ + return basic::real_part(); +} + +ex ncmul::imag_part() const +{ + return basic::imag_part(); +} + // protected /** Implementation of ex::diff() for a non-commutative product. It applies @@ -552,10 +568,8 @@ unsigned ncmul::return_type() const } if ((rt == return_types::noncommutative) && (!all_commutative)) { // another nc element found, compare type_infos - if (noncommutative_element->return_type_tinfo() != i->return_type_tinfo()) { - // diffent types -> mul is ncc - return return_types::noncommutative_composite; - } + if(noncommutative_element->return_type_tinfo() != i->return_type_tinfo()) + return return_types::noncommutative_composite; } ++i; } @@ -564,10 +578,10 @@ unsigned ncmul::return_type() const return all_commutative ? return_types::commutative : return_types::noncommutative; } -unsigned ncmul::return_type_tinfo() const +tinfo_t ncmul::return_type_tinfo() const { if (seq.empty()) - return tinfo_key; + return this; // return type_info of first noncommutative element exvector::const_iterator i = seq.begin(), end = seq.end(); @@ -578,7 +592,7 @@ unsigned ncmul::return_type_tinfo() const } // no noncommutative element found, should not happen - return tinfo_key; + return this; } //////////