Be more careful before converting to indexed.
Vladimir V. Kisil [Thu, 23 Jun 2011 14:20:59 +0000 (16:20 +0200)]
This patch makes GiNaC pass it's test suite when compiled with
-DDO_GINAC_ASSERT.

check/exam_clifford.cpp
ginac/clifford.cpp

index f504cd0..9503f16 100644 (file)
@@ -504,7 +504,8 @@ static unsigned clifford_check7(const ex & G, const symbol & dim)
        result += check_equal(e, pow(scalar*(dim-2), 2).expand() * clifford_unit(mu, G));
 
        // canonicalize_clifford() checks, only for symmetric metrics
-       if (ex_to<symmetry>(ex_to<indexed>(ex_to<clifford>(clifford_unit(mu, G)).get_metric()).get_symmetry()).has_symmetry()) {
+       if (is_a<indexed>(ex_to<clifford>(clifford_unit(mu, G)).get_metric()) &&
+           ex_to<symmetry>(ex_to<indexed>(ex_to<clifford>(clifford_unit(mu, G)).get_metric()).get_symmetry()).has_symmetry()) {
                e = clifford_unit(mu, G) * clifford_unit(nu, G) + clifford_unit(nu, G) * clifford_unit(mu, G);
                result += check_equal(canonicalize_clifford(e), 2*dirac_ONE()*unit.get_metric(nu, mu));
                
index 6725006..5b937c4 100644 (file)
@@ -1228,8 +1228,7 @@ static ex get_clifford_comp(const ex & e, const ex & c)
                        if (is_a<clifford>(e.op(j)) && ex_to<clifford>(c).same_metric(e.op(j))) {
                                if (ind > e.nops()) {
                                        ind = j;
-                               }
-                               else {
+                               } else {
                                        throw(std::invalid_argument("get_clifford_comp(): expression is a Clifford multi-vector"));
                                }
                        }
@@ -1240,13 +1239,16 @@ static ex get_clifford_comp(const ex & e, const ex & c)
                        same_value_index = ( ex_to<idx>(e.op(ind).op(1)).is_numeric()
                                                                 &&  (ival == ex_to<numeric>(ex_to<idx>(e.op(ind).op(1)).get_value()).to_int()) );
                        found_dummy = same_value_index;
+                       // Run through the expression collecting all non-clifford factors
                        for (size_t j=0; j < e.nops(); j++) {
                                if (j != ind) {
                                        if (same_value_index) {
                                                S = S * e.op(j);
-                                       }
-                                       else {
-                                               exvector ind_vec = ex_to<indexed>(e.op(j)).get_dummy_indices(ex_to<indexed>(e.op(ind)));
+                                       } else {
+                                               exvector ind_vec;
+                                               if (is_a<indexed>(e.op(j)))
+                                                       ind_vec = ex_to<indexed>(e.op(j)).get_dummy_indices(ex_to<indexed>(e.op(ind)));
+                                               
                                                if (ind_vec.size() > 0) {
                                                        found_dummy = true;
                                                        exvector::const_iterator it = ind_vec.begin(), itend = ind_vec.end();