I am unable to replace dot by *.

Replace[a.a, .-> *]

Is there any solution to get this done?

  • 3
    $\begingroup$ a.a /. Dot -> Times? $\endgroup$
    – kglr
    Sep 19, 2018 at 8:03
  • 3
    $\begingroup$ Please read through this tutorial in full: reference.wolfram.com/language/tutorial/… and also check the Replace documentation (it operates at level 0 by default). Reaplce effectively works on the FullForm of expressions, not code strings. $\endgroup$
    – Szabolcs
    Sep 19, 2018 at 8:04
  • 2
    $\begingroup$ I voted to leave it open, as it is possible, that more people are confused about the same aspect @Szabolcs pointed out.. $\endgroup$
    – Johu
    Sep 19, 2018 at 9:20
  • 2
    $\begingroup$ In Wolfram, the inner structure of an expression is highly possible not what it looks like. For using rules for substitution, FullForm is useful to check what an expression really is. $\endgroup$ Sep 19, 2018 at 9:23
  • $\begingroup$ @Johu Could you include the links to the relevant tutorials, so this can be used as a target for duplicates in the future? It seemed to me that the main reason for the misunderstanding was not being aware of the expression structure ("full form"). The Replace thing is important to get it working, but it is really just a practical detail, not a conceptual point. $\endgroup$
    – Szabolcs
    Sep 19, 2018 at 13:52

2 Answers 2


You can use ReplaceAll (/.):

a.a /. Dot -> Times


Alternatively, you can temporarily redefine Dot as Times using Block:

Block[{Dot = Times}, a.a]



I think there are several reasonons pointed out by Szabolcs in the comments why the approach failed, and they are not all supper basic by my standard. I would like to point them out.

First the basics

Everything is an expression.

foo -> bar is the same thing as Rule[foo,bar] and the same thing as foo~Rule~bar.

This underlying expression is often hidden and not important, but checking the underlying description is very helpful when debugging. Check out FullForm and TreeForm.

The second argument .-> * is not a valid syntax

When parsing this input, the interpreter expects ., -> and * to be infix operators. Having two or more infix operators next to each other can not be interpreted and it is indicated by codehighlighting of the cell:

enter image description here

It effectivly reads:

(~Dot~) (~ReplaceAll~) (~Times~)

which can not be interpreted, as left and right operands are missing.

Also ToExpression[".->*"] returns a message

ToExpression::sntx: Invalid syntax in or before ".->*".

Repalce checks only the top level

Repalce will not replace a part of an expression. Compare:

Replace[Dot, Dot -> Times]
Replace[Dot[a.a], Dot -> Times]
Replace[Dot[a.a], Dot[a.a] -> Times[a a]]

Out[1953]= Times

Out[1954]= a.a

Out[1955]= a^2

Working solutions

Either use more general replacement rule:

In[1939]:= Replace[a.b, (f_).(g_) :> (f*g)]

Out[1939]= a b

or instead of Replace use a ReplaceAll (/.) , which tries to apply the pattern also to subexpressions:

ReplaceAll[a.b, Dot -> Times]


a b

Times[a, b]

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.