Source

pynac-patches / match.patch

# HG changeset patch
# Parent 59bed356b15b076543ec14dbb50a15a85b2f7818
diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp
--- a/ginac/expairseq.cpp
+++ b/ginac/expairseq.cpp
@@ -415,12 +415,12 @@
 		exvector ops;
 		ops.reserve(nops());
 		for (size_t i=0; i<nops(); i++)
-			ops.push_back(op(i));
+			ops.push_back(stable_op(i));
 
 		// Now, for every term of the pattern, look for a matching term in
 		// the expression and remove the match
 		for (size_t i=0; i<pattern.nops(); i++) {
-			ex p = pattern.op(i);
+			ex p = ex_to<expairseq>(pattern).stable_op(i);
 			if (has_global_wildcard && p.is_equal(global_wildcard))
 				continue;
 			exvector::iterator it = ops.begin(), itend = ops.end();
diff --git a/ginac/mul.cpp b/ginac/mul.cpp
--- a/ginac/mul.cpp
+++ b/ginac/mul.cpp
@@ -974,7 +974,8 @@
 			continue;
 		lst newrepls = repls;
 		int newnummatches = nummatches;
-		if (tryfactsubs(e.op(i), pat.op(factor), newnummatches, newrepls)) {
+		if (tryfactsubs(e.op(i), pat.op(factor),
+					newnummatches, newrepls)) {
 			matched[i] = true;
 			if (algebraic_match_mul_with_mul(e, pat, newrepls, factor+1,
 					newnummatches, subsed, matched)) {
diff --git a/ginac/order.cpp b/ginac/order.cpp
--- a/ginac/order.cpp
+++ b/ginac/order.cpp
@@ -91,6 +91,11 @@
 	return id;
 }
 
+const tinfo_t & print_order::wildcard_id() const
+{
+	static tinfo_t id = find_tinfo_key("wildcard");
+	return id;
+}
 
 
 /** What Sage does for printing:
@@ -193,11 +198,17 @@
 	else if (typeid_rh == numeric_id())
 	 	//print numerics before anything else
 		return -1;
+	else if (typeid_lh == wildcard_id())
+	 	//print wildcards before anything else (but numerics)
+		return 1;
+	else if (typeid_rh == wildcard_id())
+	 	//print wildcards before anything else (but numerics)
+		return -1;
 	else if (typeid_lh == constant_id())
-	 	//print constants before anything else (but numerics)
+	 	//print constants before anything else (but numerics, wildcards)
 		return 1;
 	else if (typeid_rh == constant_id())
-	 	//print constants before anything else (but numerics)
+	 	//print constants before anything else (but numerics, wildcards)
 		return -1;
 	else if (typeid_lh == fderivative_id())
 		//print fderivatives after everything else
diff --git a/ginac/order.h b/ginac/order.h
--- a/ginac/order.h
+++ b/ginac/order.h
@@ -45,6 +45,7 @@
 	const tinfo_t& add_id() const;
 	const tinfo_t& numeric_id() const;
 	const tinfo_t& constant_id() const;
+	const tinfo_t& wildcard_id() const;
 
 public:
 	bool operator() (const ex &lh, const ex &rh) const;