Overriding the behavior of Dot

I would like to override the behavior of Dot, so that Dot[u,v] will return a scalar instead of a 1x1 matrix in the case that the result is 1x1. The behavior I want is given by CircleDot defined below.

CircleDot[u_, v_] := u.v /. {{{a_}} -> a};


I have tried experimenting with SetOptions and I have studied here. Any help you could provide would be most welcome.

As an example, consider

{{1,2,3}}.Transpose[{{1,2,3}}]


The result is {{14}}. Whereas

CircleDot[{{1,2,3}},Transpose[{{1,2,3}]]


Gives 14

I want to work with row and column vectors i.e. 1xn and nx1 matrices.

• I'm confused. If I do Dot[{1}, {2}], MMA returns 2. – march Aug 25 '15 at 15:59
• Unprotect[Dot] redefine Dot Protect[Dot]? Please provide an example of the vectors. – rhermans Aug 25 '15 at 15:59
• I have to think a simple example would help clarify this question. – chuy Aug 25 '15 at 16:02
• John, if I write your example as Dot[{1, 2, 3}, {1, 2, 3}], it works fine, and the result is already 14. "Because of the way the Wolfram Language uses lists to represent vectors and matrices, you never have to distinguish between "row" and "column" vectors." (link to docs). Wouldn't that be acceptable in your case? – MarcoB Aug 25 '15 at 16:35
• I understand that Mathematica treats lists a vectors. I want to work with standard notation using row and column vectors for in-class examples. – John McGee Aug 25 '15 at 16:41

If you want to do the Unprotect thing, take care to restrict your mod to the specific case:

Unprotect[Dot];
Dot[a_List, b_List] /;
Dimensions[a][[1]] == 1 &&
Dimensions[a] == Reverse@Dimensions[b] :=