Source

pynac-patches / mul_to_power.patch

Full commit
# HG changeset patch
# Parent 80207ab3349a69aa07aac64e410312955c8dfbf1
diff --git a/ginac/mul.cpp b/ginac/mul.cpp
--- a/ginac/mul.cpp
+++ b/ginac/mul.cpp
@@ -659,7 +659,8 @@
 		return recombine_pair_to_ex(*(seq.begin()));
 	} else if ((seq_size==1) &&
 	           is_exactly_a<add>((*seq.begin()).rest) &&
-	           ex_to<numeric>((*seq.begin()).coeff).is_equal(*_num1_p)) {
+	           (ex_to<numeric>((*seq.begin()).coeff).is_equal(*_num1_p) ||
+		    ex_to<numeric>((*seq.begin()).coeff).is_equal(*_num_1_p))) {
 		// *(+(x,y,...);c) -> +(*(x,c),*(y,c),...) (c numeric(), no powers of +())
 		const add & addref = ex_to<add>((*seq.begin()).rest);
 		std::auto_ptr<epvector> distrseq(new epvector);
@@ -669,10 +670,14 @@
 			distrseq->push_back(addref.combine_pair_with_coeff_to_pair(*i, overall_coeff));
 			++i;
 		}
-		return (new add(distrseq,
+		ex res = (new add(distrseq,
 		                ex_to<numeric>(addref.overall_coeff).
 		                mul_dyn(ex_to<numeric>(overall_coeff)))
 		       )->setflag(status_flags::dynallocated | status_flags::evaluated);
+		if (ex_to<numeric>((*seq.begin()).coeff).is_equal(*_num_1_p)) {
+			return (new power(res, _ex_1))->setflag(status_flags::dynallocated | status_flags::evaluated);
+		}
+		return res;
 	} else if ((seq_size >= 2) && (! (flags & status_flags::expanded))) {
 		// Strip the content and the unit part from each term. Thus
 		// things like (-x+a)*(3*x-3*a) automagically turn into - 3*(x-a)2