Replacing dot by *?

Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
I am unable to replace dot by *.
Replace[a.a, .-> *]
Is there any solution to get this done?
replacement built-in-symbols
add a comment |Â
up vote
4
down vote
favorite
I am unable to replace dot by *.
Replace[a.a, .-> *]
Is there any solution to get this done?
replacement built-in-symbols
3
a.a /. Dot -> Times?
â kglr
Sep 19 at 8:03
3
Please read through this tutorial in full: reference.wolfram.com/language/tutorial/⦠and also check theReplacedocumentation (it operates at level 0 by default).Reaplceeffectively works on theFullFormof expressions, not code strings.
â Szabolcs
Sep 19 at 8:04
2
I voted to leave it open, as it is possible, that more people are confused about the same aspect @Szabolcs pointed out..
â Johu
Sep 19 at 9:20
2
In Wolfram, the inner structure of an expression is highly possible not what it looks like. For using rules for substitution,FullFormis useful to check what an expression really is.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
Sep 19 at 9:23
@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"). TheReplacething is important to get it working, but it is really just a practical detail, not a conceptual point.
â Szabolcs
Sep 19 at 13:52
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I am unable to replace dot by *.
Replace[a.a, .-> *]
Is there any solution to get this done?
replacement built-in-symbols
I am unable to replace dot by *.
Replace[a.a, .-> *]
Is there any solution to get this done?
replacement built-in-symbols
replacement built-in-symbols
asked Sep 19 at 8:00
Chandan Sharma
795
795
3
a.a /. Dot -> Times?
â kglr
Sep 19 at 8:03
3
Please read through this tutorial in full: reference.wolfram.com/language/tutorial/⦠and also check theReplacedocumentation (it operates at level 0 by default).Reaplceeffectively works on theFullFormof expressions, not code strings.
â Szabolcs
Sep 19 at 8:04
2
I voted to leave it open, as it is possible, that more people are confused about the same aspect @Szabolcs pointed out..
â Johu
Sep 19 at 9:20
2
In Wolfram, the inner structure of an expression is highly possible not what it looks like. For using rules for substitution,FullFormis useful to check what an expression really is.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
Sep 19 at 9:23
@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"). TheReplacething is important to get it working, but it is really just a practical detail, not a conceptual point.
â Szabolcs
Sep 19 at 13:52
add a comment |Â
3
a.a /. Dot -> Times?
â kglr
Sep 19 at 8:03
3
Please read through this tutorial in full: reference.wolfram.com/language/tutorial/⦠and also check theReplacedocumentation (it operates at level 0 by default).Reaplceeffectively works on theFullFormof expressions, not code strings.
â Szabolcs
Sep 19 at 8:04
2
I voted to leave it open, as it is possible, that more people are confused about the same aspect @Szabolcs pointed out..
â Johu
Sep 19 at 9:20
2
In Wolfram, the inner structure of an expression is highly possible not what it looks like. For using rules for substitution,FullFormis useful to check what an expression really is.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
Sep 19 at 9:23
@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"). TheReplacething is important to get it working, but it is really just a practical detail, not a conceptual point.
â Szabolcs
Sep 19 at 13:52
3
3
a.a /. Dot -> Times?â kglr
Sep 19 at 8:03
a.a /. Dot -> Times?â kglr
Sep 19 at 8:03
3
3
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.â Szabolcs
Sep 19 at 8:04
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.â Szabolcs
Sep 19 at 8:04
2
2
I voted to leave it open, as it is possible, that more people are confused about the same aspect @Szabolcs pointed out..
â Johu
Sep 19 at 9:20
I voted to leave it open, as it is possible, that more people are confused about the same aspect @Szabolcs pointed out..
â Johu
Sep 19 at 9:20
2
2
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.â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
Sep 19 at 9:23
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.â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
Sep 19 at 9:23
@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.â Szabolcs
Sep 19 at 13:52
@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.â Szabolcs
Sep 19 at 13:52
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
8
down vote
You can use ReplaceAll (/.):
a.a /. Dot -> Times
a^2
Alternatively, you can temporarily redefine Dot as Times using Block:
Block[Dot = Times, a.a]
a^2
add a comment |Â
up vote
7
down vote
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:

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:
In[1953]:=
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:
In[1943]:=
FullForm[a.b]
ReplaceAll[a.b, Dot -> Times]
FullForm[%]
Out[1943]//FullForm=
Dot[a,b]
Out[1944]=
a b
Out[1950]//FullForm=
Times[a, b]
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
You can use ReplaceAll (/.):
a.a /. Dot -> Times
a^2
Alternatively, you can temporarily redefine Dot as Times using Block:
Block[Dot = Times, a.a]
a^2
add a comment |Â
up vote
8
down vote
You can use ReplaceAll (/.):
a.a /. Dot -> Times
a^2
Alternatively, you can temporarily redefine Dot as Times using Block:
Block[Dot = Times, a.a]
a^2
add a comment |Â
up vote
8
down vote
up vote
8
down vote
You can use ReplaceAll (/.):
a.a /. Dot -> Times
a^2
Alternatively, you can temporarily redefine Dot as Times using Block:
Block[Dot = Times, a.a]
a^2
You can use ReplaceAll (/.):
a.a /. Dot -> Times
a^2
Alternatively, you can temporarily redefine Dot as Times using Block:
Block[Dot = Times, a.a]
a^2
answered Sep 19 at 8:09
kglr
163k8188387
163k8188387
add a comment |Â
add a comment |Â
up vote
7
down vote
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:

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:
In[1953]:=
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:
In[1943]:=
FullForm[a.b]
ReplaceAll[a.b, Dot -> Times]
FullForm[%]
Out[1943]//FullForm=
Dot[a,b]
Out[1944]=
a b
Out[1950]//FullForm=
Times[a, b]
add a comment |Â
up vote
7
down vote
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:

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:
In[1953]:=
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:
In[1943]:=
FullForm[a.b]
ReplaceAll[a.b, Dot -> Times]
FullForm[%]
Out[1943]//FullForm=
Dot[a,b]
Out[1944]=
a b
Out[1950]//FullForm=
Times[a, b]
add a comment |Â
up vote
7
down vote
up vote
7
down vote
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:

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:
In[1953]:=
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:
In[1943]:=
FullForm[a.b]
ReplaceAll[a.b, Dot -> Times]
FullForm[%]
Out[1943]//FullForm=
Dot[a,b]
Out[1944]=
a b
Out[1950]//FullForm=
Times[a, b]
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:

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:
In[1953]:=
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:
In[1943]:=
FullForm[a.b]
ReplaceAll[a.b, Dot -> Times]
FullForm[%]
Out[1943]//FullForm=
Dot[a,b]
Out[1944]=
a b
Out[1950]//FullForm=
Times[a, b]
edited Sep 19 at 16:08
answered Sep 19 at 9:45
Johu
3,5831037
3,5831037
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f182152%2freplacing-dot-by%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
3
a.a /. Dot -> Times?â kglr
Sep 19 at 8:03
3
Please read through this tutorial in full: reference.wolfram.com/language/tutorial/⦠and also check the
Replacedocumentation (it operates at level 0 by default).Reaplceeffectively works on theFullFormof expressions, not code strings.â Szabolcs
Sep 19 at 8:04
2
I voted to leave it open, as it is possible, that more people are confused about the same aspect @Szabolcs pointed out..
â Johu
Sep 19 at 9:20
2
In Wolfram, the inner structure of an expression is highly possible not what it looks like. For using rules for substitution,
FullFormis useful to check what an expression really is.â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
Sep 19 at 9:23
@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
Replacething is important to get it working, but it is really just a practical detail, not a conceptual point.â Szabolcs
Sep 19 at 13:52