I am unable to replace dot by *.
Replace[a.a, .-> *]
Is there any solution to get this done?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.Sign up to join this community
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
foo -> bar is the same thing as
Rule[foo,bar] and the same thing as
The second argument
.-> * is not a valid syntax
When parsing this input, the interpreter expects
* 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:
It effectivly reads:
(~Dot~) (~ReplaceAll~) (~Times~)
which can not be interpreted, as left and right operands are missing.
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:
In:= Replace[Dot, Dot -> Times] Replace[Dot[a.a], Dot -> Times] Replace[Dot[a.a], Dot[a.a] -> Times[a a]] Out= Times Out= a.a Out= a^2
Either use more general replacement rule:
In:= Replace[a.b, (f_).(g_) :> (f*g)] Out= a b
or instead of
Replace use a
/.) , which tries to apply the pattern also to subexpressions:
In:= FullForm[a.b] ReplaceAll[a.b, Dot -> Times] FullForm[%] Out//FullForm= Dot[a,b] Out= a b Out//FullForm= Times[a, b]