* Implementation of GiNaC's non-commutative products of expressions. */
/*
- * GiNaC Copyright (C) 1999-2006 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
#include "add.h"
#include "mul.h"
#include "clifford.h"
-#include "color.h"
#include "matrix.h"
#include "archive.h"
#include "indexed.h"
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());
size_t assoc_num = assocseq.size();
exvectorvector evv;
- std::vector<const basic*> rttinfos;
+ std::vector<return_type_t> rttinfos;
evv.reserve(assoc_num);
rttinfos.reserve(assoc_num);
cit = assocseq.begin(), citend = assocseq.end();
while (cit != citend) {
- const basic* 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) {
- tinfo_t tinf = ti->tinfo();
- if (tinf == rttinfos[i]->tinfo()) {
- if (tinf == &clifford::tinfo_static) {
- if (((clifford*)ti)->get_representation_label() == ((clifford*)rttinfos[i])->get_representation_label()) {
- evv[i].push_back(*cit);
- break;
- }
- } else if (tinf == &color::tinfo_static) {
- if (((color*)ti)->get_representation_label() == ((color*)rttinfos[i])->get_representation_label()) {
- evv[i].push_back(*cit);
- break;
- }
- } else {
- evv[i].push_back(*cit);
- break;
- }
+ if(ti == rttinfos[i]) {
+ evv[i].push_back(*cit);
+ break;
}
}
if (i >= rtt_num) {
return exprseq::conjugate();
}
- if (return_type_tinfo()->tinfo() != &clifford::tinfo_static) {
+ if (!is_clifford_tinfo(return_type_tinfo())) {
return exprseq::conjugate();
}
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
}
if ((rt == return_types::noncommutative) && (!all_commutative)) {
// another nc element found, compare type_infos
- if (noncommutative_element->return_type_tinfo()->tinfo() == &clifford::tinfo_static) {
- if (i->return_type_tinfo()->tinfo() != &clifford::tinfo_static ||
- ((clifford*)(noncommutative_element->return_type_tinfo()))->get_representation_label() !=
- ((clifford*)(i->return_type_tinfo()))->get_representation_label()) {
- // diffent types -> mul is ncc
- return return_types::noncommutative_composite;
- }
- } else if (noncommutative_element->return_type_tinfo()->tinfo() == &color::tinfo_static) {
- if (i->return_type_tinfo()->tinfo() != &color::tinfo_static ||
- ((color*)(noncommutative_element->return_type_tinfo()))->get_representation_label() !=
- ((color*)(i->return_type_tinfo()))->get_representation_label()) {
- // diffent types -> mul is ncc
+ if(noncommutative_element->return_type_tinfo() != i->return_type_tinfo())
return return_types::noncommutative_composite;
- }
- } else if (noncommutative_element->return_type_tinfo()->tinfo() != i->return_type_tinfo()->tinfo()) {
- return return_types::noncommutative_composite;
- }
}
++i;
}
return all_commutative ? return_types::commutative : return_types::noncommutative;
}
-const basic* 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>();
}
//////////