Replacing dot by *?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite
1












I am unable to replace dot by *.



Replace[a.a, .-> *]


Is there any solution to get this done?










share|improve this question

















  • 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 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




    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, 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















up vote
4
down vote

favorite
1












I am unable to replace dot by *.



Replace[a.a, .-> *]


Is there any solution to get this done?










share|improve this question

















  • 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 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




    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, 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













up vote
4
down vote

favorite
1









up vote
4
down vote

favorite
1






1





I am unable to replace dot by *.



Replace[a.a, .-> *]


Is there any solution to get this done?










share|improve this question













I am unable to replace dot by *.



Replace[a.a, .-> *]


Is there any solution to get this done?







replacement built-in-symbols






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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




    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, 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













  • 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 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




    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, 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








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











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







share|improve this answer



























    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:



    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:



    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]





    share|improve this answer






















      Your Answer




      StackExchange.ifUsing("editor", function ()
      return StackExchange.using("mathjaxEditing", function ()
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
      );
      );
      , "mathjax-editing");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "387"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      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






























      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







      share|improve this answer
























        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







        share|improve this answer






















          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







          share|improve this answer












          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








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 19 at 8:09









          kglr

          163k8188387




          163k8188387




















              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:



              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:



              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]





              share|improve this answer


























                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:



                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:



                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]





                share|improve this answer
























                  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:



                  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:



                  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]





                  share|improve this answer














                  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:



                  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]






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Sep 19 at 16:08

























                  answered Sep 19 at 9:45









                  Johu

                  3,5831037




                  3,5831037



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      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













































































                      Popular posts from this blog

                      Peggy Mitchell

                      The Forum (Inglewood, California)

                      Palaiologos