#include "mul.h"
#include "add.h"
-#include "color.h"
-#include "clifford.h"
#include "power.h"
#include "operators.h"
#include "matrix.h"
return mul(s, overall_coeff.evalf(level));
}
+void mul::find_real_imag(ex & rp, ex & ip) const
+{
+ rp = overall_coeff.real_part();
+ ip = overall_coeff.imag_part();
+ for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+ ex factor = recombine_pair_to_ex(*i);
+ ex new_rp = factor.real_part();
+ ex new_ip = factor.imag_part();
+ if(new_ip.is_zero()) {
+ rp *= new_rp;
+ ip *= new_rp;
+ } else {
+ ex temp = rp*new_rp - ip*new_ip;
+ ip = ip*new_rp + rp*new_ip;
+ rp = temp;
+ }
+ }
+ rp = rp.expand();
+ ip = ip.expand();
+}
+
+ex mul::real_part() const
+{
+ ex rp, ip;
+ find_real_imag(rp, ip);
+ return rp;
+}
+
+ex mul::imag_part() const
+{
+ ex rp, ip;
+ find_real_imag(rp, ip);
+ return ip;
+}
+
ex mul::evalm() const
{
// numeric*matrix
}
if ((rt == return_types::noncommutative) && (!all_commutative)) {
// another nc element found, compare type_infos
- if (noncommutative_element->rest.return_type_tinfo()->tinfo() == &clifford::tinfo_static) {
- if (i->rest.return_type_tinfo()->tinfo() != &clifford::tinfo_static ||
- ((clifford*)(noncommutative_element->rest.return_type_tinfo()))->get_representation_label() !=
- ((clifford*)(i->rest.return_type_tinfo()))->get_representation_label()) {
- // diffent types -> mul is ncc
- return return_types::noncommutative_composite;
- }
- } else if (noncommutative_element->rest.return_type_tinfo()->tinfo() == &color::tinfo_static) {
- if (i->rest.return_type_tinfo()->tinfo() != &color::tinfo_static ||
- ((color*)(noncommutative_element->rest.return_type_tinfo()))->get_representation_label() !=
- ((color*)(i->rest.return_type_tinfo()))->get_representation_label()) {
- // diffent types -> mul is ncc
- return return_types::noncommutative_composite;
- }
- } else if (noncommutative_element->rest.return_type_tinfo()->tinfo() != i->rest.return_type_tinfo()->tinfo()) {
+ if (noncommutative_element->rest.return_type_tinfo() != i->rest.return_type_tinfo()) {
+ // different types -> mul is ncc
return return_types::noncommutative_composite;
}
}
return all_commutative ? return_types::commutative : return_types::noncommutative;
}
-const basic* mul::return_type_tinfo() const
+tinfo_t mul::return_type_tinfo() const
{
if (seq.empty())
return this; // mul without factors: should not happen