Bug introduced in 10.1 and fixed in 11.0.1

Confirmed, as bug, by WRI: [CASE:3402234]

I am trying to combine terms of the type term+Transpose[term]. I have done the following:

ReplaceAll[a.b.c.d + a.ss.e.g.r + Transpose[a.b.c.d], {
  Plus[front___, term__, middle___, Transpose[term__], end___] :> 
   Plus[front, middle, end, 2*term]

However this gives back:

Out= a.b.c.d + a.ss.e.g.r + Transpose[a.b.c.d]

How come I am not getting back 2 a.b.c.d+a.ss.e.g.r? Thanks!

  • $\begingroup$ I get 2 a.b.c.d+a.ss.e.g.r $\endgroup$ Aug 12, 2015 at 5:05
  • $\begingroup$ Whaaaaat? I have Mathematica 10.2... $\endgroup$ Aug 12, 2015 at 5:07
  • 1
    $\begingroup$ @space_voyager You might try wrapping Trace around your expression, carefully read the details of the help page for Trace and then study the output from your expression. That can sometimes help you find why a pattern isn't matching. With that I found that a pattern of term_+Transpose[term_]:>2*term seems like it might be sufficient and might avoid some of the matching problems. See what you can make of this. $\endgroup$
    – Bill
    Aug 12, 2015 at 5:42
  • 1
    $\begingroup$ Mma v9 here !Mathematica graphics $\endgroup$ Aug 12, 2015 at 5:46
  • 2
    $\begingroup$ Why do you do this to me, Wolfram?? $\endgroup$ Aug 12, 2015 at 5:49

2 Answers 2


To fix this problem on Mma 10.1 on OS X 10.10.4 I took off one of the blanks on term, i.e.

ReplaceAll[a.b.c.d + a.ss.e.g.r + Transpose[a.b.c.d],
 {Plus[front___, term__, middle___, Transpose[term__], end___] :>
   Plus[front, middle, end, 2*term]}]

a.b.c.d + a.ss.e.g.r + Transpose[a.b.c.d]

ReplaceAll[a.b.c.d + a.ss.e.g.r + Transpose[a.b.c.d],
 {Plus[front___, term_, middle___, Transpose[term_], end___] :>
   Plus[front, middle, end, 2*term]}]

2 a.b.c.d + a.ss.e.g.r

  • $\begingroup$ Thanks, this is the solution that worked for me :) $\endgroup$ Aug 12, 2015 at 17:50

I think you've found a bug in pattern matcher.

This problem can be reduced to matching sequence of length one with named BlankSequence patterns in Orderless functions, it stopped working in v10.1. In previous versions your replacement rule works (as noted by belisarius).

Minimal example of this behavior is:

ClearAll[f, a]
SetAttributes[f, {Orderless}]

MatchQ[{f[a], a}, {f[x__], x__}]

In different versions I get:

"8.0 for Linux x86 (64-bit) (November 7, 2010)"


"9.0 for Linux x86 (64-bit) (February 7, 2013)"


"10.0 for Linux x86 (64-bit) (December 4, 2014)"


"10.1.0 for Linux x86 (64-bit) (March 24, 2015)"


"10.2.0 for Linux x86 (64-bit) (July 6, 2015)"


If we use Blank instead of BlankSequence, remove name from one of patterns or use non-Orderless function, then pattern matches in all versions:

MatchQ[{f[a], a}, {f[x_], x_}]
MatchQ[{f[a], a}, {f[x__], __}]
MatchQ[{g[a], a}, {g[x__], x__}]
(* True
   True *)

As to your original replacement, as noted by Bill due to Flat, OneIdentity and Orderless attributes of Plus you can use:

a.b.c.d + a.ss.e.g.r + Transpose[a.b.c.d] /. term_ + Transpose[term_] :> 2*term
(* 2 a.b.c.d + a.ss.e.g.r *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.