]> www.ginac.de Git - ginac.git/blobdiff - ginac/clifford.cpp
* Improved lsolve() of systems containing non-numeric coefficients.
[ginac.git] / ginac / clifford.cpp
index 4e601ab4209e28e8d2133774cbb60244e0bfa4e8..c93e6466d092b06a9cd3aeb7aeb95b70c9bc0fc7 100644 (file)
@@ -265,8 +265,21 @@ void clifford::do_print_dflt(const print_dflt & c, unsigned level) const
        if (is_dirac_slash(seq[0])) {
                seq[0].print(c, precedence());
                c.s << "\\";
-       } else
-               this->print_dispatch<inherited>(c, level);
+       } else { // We do not print representation label if it is 0
+               if (representation_label == 0) {
+                       this->print_dispatch<inherited>(c, level);
+               } else { // otherwise we put it before indices in square brackets; the code is borrowed from indexed.cpp 
+                       if (precedence() <= level) {
+                               c.s << '(';
+                       }
+                       seq[0].print(c, precedence());
+                       c.s << '[' << int(representation_label) << ']';
+                       printindices(c, level);
+                       if (precedence() <= level) {
+                               c.s << ')';
+                       }
+               }
+       }
 }
 
 void clifford::do_print_latex(const print_latex & c, unsigned level) const
@@ -1170,13 +1183,20 @@ ex lst_to_clifford(const ex & v, const ex & e) {
                        if (min == 1) {
                                if (dim == max)
                                        return indexed(v, mu_toggle) * e;
-                               else
+                               else if (max - dim == 1) {
+                                       if (ex_to<matrix>(v).cols() > ex_to<matrix>(v).rows())
+                                               return v.op(0) * dirac_ONE(ex_to<clifford>(e).get_representation_label()) + indexed(sub_matrix(ex_to<matrix>(v), 0, 1, 1, dim), mu_toggle) * e;
+                                       else 
+                                               return v.op(0) * dirac_ONE(ex_to<clifford>(e).get_representation_label()) + indexed(sub_matrix(ex_to<matrix>(v), 1, dim, 0, 1), mu_toggle) * e;
+                               } else
                                        throw(std::invalid_argument("lst_to_clifford(): dimensions of vector and clifford unit mismatch"));
                        } else
                                throw(std::invalid_argument("lst_to_clifford(): first argument should be a vector (nx1 or 1xn matrix)"));
                } else if (v.info(info_flags::list)) {
                        if (dim == ex_to<lst>(v).nops())
                                return indexed(matrix(dim, 1, ex_to<lst>(v)), mu_toggle) * e;
+                       else if (ex_to<lst>(v).nops() - dim == 1)
+                               return v.op(0) * dirac_ONE(ex_to<clifford>(e).get_representation_label()) + indexed(sub_matrix(matrix(dim+1, 1, ex_to<lst>(v)), 1, dim, 0, 1), mu_toggle) * e;
                        else
                                throw(std::invalid_argument("lst_to_clifford(): list length and dimension of clifford unit mismatch"));
                } else
@@ -1261,19 +1281,28 @@ lst clifford_to_lst(const ex & e, const ex & c, bool algebraic)
                                or (not is_a<numeric>(pow(c.subs(mu == i, subs_options::no_pattern), 2))))
                                algebraic = false;
        lst V; 
+       ex v0 = remove_dirac_ONE(canonicalize_clifford(e+clifford_prime(e)).normal())/2;
+       if (not v0.is_zero())
+               V.append(v0);
+       ex e1 = canonicalize_clifford(e - v0 * dirac_ONE(ex_to<clifford>(c).get_representation_label())); 
        if (algebraic) {
                for (unsigned int i = 0; i < D; i++) 
                        V.append(remove_dirac_ONE(
-                                               simplify_indexed(canonicalize_clifford(e * c.subs(mu == i, subs_options::no_pattern) +  c.subs(mu == i, subs_options::no_pattern) * e))
+                                               simplify_indexed(canonicalize_clifford(e1 * c.subs(mu == i, subs_options::no_pattern) +  c.subs(mu == i, subs_options::no_pattern) * e1))
                                                / (2*pow(c.subs(mu == i, subs_options::no_pattern), 2))));
        } else {
-               ex e1 = canonicalize_clifford(e);
                try {
                        for (unsigned int i = 0; i < D; i++) 
                                V.append(get_clifford_comp(e1, c.subs(c.op(1) == i, subs_options::no_pattern)));
                } catch  (std::exception &p) {
                        /* Try to expand dummy summations to simplify the expression*/
-                       e1 = canonicalize_clifford(expand_dummy_sum(e1, true));
+                       e1 = canonicalize_clifford(expand_dummy_sum(e, true));
+                       V.remove_all();
+                       v0 = remove_dirac_ONE(canonicalize_clifford(e1+clifford_prime(e1)).normal())/2;
+                       if (not v0.is_zero()) {
+                               V.append(v0);
+                               e1 = canonicalize_clifford(e1 - v0 * dirac_ONE(ex_to<clifford>(c).get_representation_label())); 
+                       }
                        for (unsigned int i = 0; i < D; i++) 
                                V.append(get_clifford_comp(e1, c.subs(c.op(1) == i, subs_options::no_pattern)));
                }
@@ -1311,11 +1340,10 @@ ex clifford_moebius_map(const ex & a, const ex & b, const ex & c, const ex & d,
 
 ex clifford_moebius_map(const ex & M, const ex & v, const ex & G, unsigned char rl)
 {
-       if (is_a<matrix>(M)) 
-               return clifford_moebius_map(ex_to<matrix>(M)(0,0), ex_to<matrix>(M)(0,1),
-                                           ex_to<matrix>(M)(1,0), ex_to<matrix>(M)(1,1), v, G, rl);
+       if (is_a<matrix>(M) && (ex_to<matrix>(M).rows() == 2) && (ex_to<matrix>(M).cols() == 2)) 
+               return clifford_moebius_map(M.op(0), M.op(1), M.op(2), M.op(3), v, G, rl);
        else
-               throw(std::invalid_argument("clifford_moebius_map(): parameter M should be a matrix"));
+               throw(std::invalid_argument("clifford_moebius_map(): parameter M should be a 2x2 matrix"));
 }
 
 } // namespace GiNaC