Problem with incorrect use of the Dot command in Mma

In[1]:= SameQ[Dot[1, 2], 1.2] TrueQ[Dot[1, 2] == 1.2] a = 1; b = 2; SameQ[Dot[a, b], ab] TrueQ[Dot[a, b] == ab] Out[1]= False Out[2]= False Out[4]= True Out[5]= True 

I know this uses the Dot command incorrectly. Can anyone give me a clear resonance for the above different results?

thanks!

+4
source share
3 answers

ab interpreted as Dot[a,b] , and then the variables a and b are replaced, which means Dot[1,2] and, therefore, equality holds. This is not the same as 1.2 , where the dot denotes the decimal separator, and not for the built-in Dot operator.

+9
source

enter image description here

When you write 1.2 , Mma understands the number (aka 6/5), but if you write {1, 1}.{2, 2} or ab , Mma understands the scalar product , as usual, in any book using vectors.

NTN!

+3
source

It may be informative to consider an expression under Hold and FullForm :

 a = 1; b = 2; SameQ[Dot[a, b], ab]] //Hold //FullForm 
  Hold [SameQ [Dot [a, b], Dot [a, b]]] 

Using this combination of commands, Mathematica parses, but does not evaluate, the expression ( Hold ), and then displays the long pseudo-internal form of the expression ( FullForm ).

In this case, you can see that the second term ab parsed as Dot[a, b] before any evaluation occurs.

When . appears with numbers, as in 1.2 , it is interpreted specifically as a decimal point. This is similar to other numerical record formats, such as: 1*^6 , which is recognized directly as 1000000 :

 1*^6 //Hold //FullForm 

Compare the input attempt:

 a = 1; a*^6 
+2
source

All Articles