* Implementation of GiNaC's non-commutative products of expressions. */
/*
- * GiNaC Copyright (C) 1999-2006 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2010 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <algorithm>
-#include <iostream>
-#include <stdexcept>
-
#include "ncmul.h"
#include "ex.h"
#include "add.h"
#include "indexed.h"
#include "utils.h"
+#include <algorithm>
+#include <iostream>
+#include <stdexcept>
+
namespace GiNaC {
GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(ncmul, exprseq,
ncmul::ncmul()
{
- tinfo_key = &ncmul::tinfo_static;
}
//////////
ncmul::ncmul(const ex & lh, const ex & rh) : inherited(lh,rh)
{
- tinfo_key = &ncmul::tinfo_static;
}
ncmul::ncmul(const ex & f1, const ex & f2, const ex & f3) : inherited(f1,f2,f3)
{
- 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 = &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 = &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 = &ncmul::tinfo_static;
}
ncmul::ncmul(const exvector & v, bool discardable) : inherited(v,discardable)
{
- tinfo_key = &ncmul::tinfo_static;
}
ncmul::ncmul(std::auto_ptr<exvector> vp) : inherited(vp)
{
- tinfo_key = &ncmul::tinfo_static;
}
//////////
// archiving
//////////
-DEFAULT_ARCHIVING(ncmul)
-
+
//////////
// functions overriding virtual functions from base classes
//////////
return inherited::info(inf);
}
-typedef std::vector<int> intvector;
+typedef std::vector<std::size_t> uintvector;
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;
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;
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());
if (assocseq.empty()) return _ex1;
// determine return types
- unsignedvector rettypes;
- rettypes.reserve(assocseq.size());
+ unsignedvector rettypes(assocseq.size());
size_t i = 0;
size_t count_commutative=0;
size_t count_noncommutative=0;
size_t count_noncommutative_composite=0;
cit = assocseq.begin(); citend = assocseq.end();
while (cit != citend) {
- switch (rettypes[i] = cit->return_type()) {
+ rettypes[i] = cit->return_type();
+ switch (rettypes[i]) {
case return_types::commutative:
count_commutative++;
break;
size_t assoc_num = assocseq.size();
exvectorvector evv;
- std::vector<tinfo_t> rttinfos;
+ std::vector<return_type_t> rttinfos;
evv.reserve(assoc_num);
rttinfos.reserve(assoc_num);
cit = assocseq.begin(), citend = assocseq.end();
while (cit != citend) {
- tinfo_t ti = cit->return_type_tinfo();
+ return_type_t ti = cit->return_type_tinfo();
size_t rtt_num = rttinfos.size();
// search type in vector of known types
for (i=0; i<rtt_num; ++i) {
return (new ncmul(ev, true))->setflag(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
return all_commutative ? return_types::commutative : return_types::noncommutative;
}
-tinfo_t ncmul::return_type_tinfo() const
+return_type_t ncmul::return_type_tinfo() const
{
if (seq.empty())
- return this;
+ return make_return_type_t<ncmul>();
// return type_info of first noncommutative element
exvector::const_iterator i = seq.begin(), end = seq.end();
}
// no noncommutative element found, should not happen
- return this;
+ return make_return_type_t<ncmul>();
}
//////////
status_flags::evaluated);
}
+GINAC_BIND_UNARCHIVER(ncmul);
+
} // namespace GiNaC