]> www.ginac.de Git - ginac.git/blobdiff - ginac/mul.cpp
Added methods for taking real and imaginary parts.
[ginac.git] / ginac / mul.cpp
index 3385bcae2b072a65bf56db5aca883205bf294875..d2dd675cfa08b9af4265a599e8011b99c06e14d8 100644 (file)
@@ -27,8 +27,6 @@
 
 #include "mul.h"
 #include "add.h"
-#include "color.h"
-#include "clifford.h"
 #include "power.h"
 #include "operators.h"
 #include "matrix.h"
@@ -463,6 +461,41 @@ ex mul::evalf(int level) const
        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
@@ -732,21 +765,8 @@ unsigned mul::return_type() const
                }
                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;
                        }
                }
@@ -756,7 +776,7 @@ unsigned mul::return_type() const
        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