Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
k.k.k //. {k.k -> k}

works perfectly, so the output is just k.

But, when I use Esc.Esc (center dot, CenterDot[k,k]) instead of . (comma),

k Esc.Esc k Esc.Esc k //. {k Esc.Esc k -> k}

does not work while

k Esc.Esc k //. {k Esc.Esc k -> k}


How can I fix this problem?

share|improve this question
up vote 5 down vote accepted

That's because Dot has the atrribute Flat while CenterDot doesn't:

{Dot, CenterDot} // Attributes
{{Flat, OneIdentity, Protected}, {}}

As the document said,

In pattern matching, Flat allows sequences of elements to be replaced:

 SetAttributes[f, Flat]
 f[a, b, c, d, e] /. f[b, c, d] -> x
f[a, x, e]

So, to fix your problem, just set Flat attribute to CenterDot:

SetAttributes[CenterDot, Flat]
k·k·k //. k·k -> k
share|improve this answer
It works but how about this situation? (I set CenterDot to be flat) CenterDot[a, b] //. CenterDot[x_, b] -> x This code returns not a, but CenterDot[a]. I don't know why this happened. – Analysis Aug 6 '14 at 10:05
@Analysis You need another attribute OneIdentity added. See here for more details. – xzczd Aug 6 '14 at 10:19
Thanks! It works! – Analysis Aug 6 '14 at 10:31
k Esc.Esc k Esc.Esc k /. CenterDot[k, ___] -> k

gives the desired result

share|improve this answer
For a more general rule, you can use //.{CenterDot[a___,x_,x_,b___]:>CenterDot[a,x,b],CenterDot[x_]:>x}. For example, try evaluating k\[CenterDot]k\[CenterDot]k\[CenterDot]g\[CenterDot]g\[CenterDot]k\[CenterDot]h‌​//.{CenterDot[a___,x_,x_,b___]:>CenterDot[a,x,b],CenterDot[x_]:>x} – seismatica Aug 6 '14 at 8:35

It's not answer but comment


k Esc.Esc k Esc.Esc k //. {k Esc.Esc k -> k}

does not work becouse

FullForm[k Esc.Esc k Esc.Esc k]

and you try replace CenterDot[k,k] (that is missing on the left side) by k

Finally write it in more programatic style

CenterDot[k,k,k] //. CenterDot[k,k] -> k

And you last working example

CenterDot[k,k] //. CenterDot[k,k] -> k
share|improve this answer
Well, not quite correct because if you check the FullForm of k.k.k what you'll see is Dot[k, k, k], the true cause lies in the Attributes. – xzczd Aug 6 '14 at 8:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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