In[1] := Hold[a.b] // FullForm
Out[1] := Hold[Dot[a,b]]

So far so good.

 In[2] := Hold[a_.b_] // FullForm
Out[2] := Hold[Times[Optional[Pattern[a,Blank[]]],Pattern[b,Blank[]]]]

Why does the Dot become Times? I have a feeling it has something to do with the Optional that also appears, but I can't find anything that explains what's going on in the documentation.


See the documentation for Optional:

The special form s_. is equivalent to Optional[s_] and can be used to represent function arguments which, if omitted, should be replaced by default values globally specified for the functions in which they occur.

This explains the result your are receiving.

Thus, it seems you have a precedence problem, and a possible workaround is:

Hold[(a_).(b_)] // FullForm

and get

Hold[Dot[Pattern[a, Blank[]], Pattern[b, Blank[]]]
  • $\begingroup$ Even FullForm[Hold[(a_).b_]] is enough since now there are no special forms related to . in the expression. +1. $\endgroup$ – Kuba Jan 14 '14 at 9:04
  • $\begingroup$ I have never seen an application of Optional... $\endgroup$ – Murta Jan 14 '14 at 10:31
  • $\begingroup$ Don't know how I missed that in the docs! Thanks. $\endgroup$ – Dan Jan 14 '14 at 16:51
  • $\begingroup$ A single space will also work: Hold[a_ .b_] // FullForm. @Murta Optional is quite useful. A few examples from my own answers: (17498), (20715), (29366), (30591), (30919), (47844), (51670). $\endgroup$ – Mr.Wizard Oct 25 '14 at 1:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.