# Why does Times evaluate within Hold when doing replacement?

Hold @ t[t[1,1],2]/.t-> Times
Hold @ t[t[1,2],2]/.t-> Times

Hold[(1 1) 2]
Hold[2 2]


Why doesn't the second one give Hold[(1 2) 2]? It seems to have to do with 1 appearing in there.

Hold @ t[t[2,2],2]/.t-> Times gives Hold[(2 2) 2] but

Hold @ t[t[2,2],1]/.t-> Times gives Hold[2 2]

The result is the same if I do the replacement with :> or //. or using With or a global replacement rule (function).

Maybe the default value of Times, 1, is being used in these replacements? Can anyone explain this?

This is a specific case of a more general topic: Understanding evaluation and typesetting

It is not a bug, nothing is evaluated. Why then Times' "special" formatting is recognized for nested t[t[1,2],2] as it would have been evaluated?

It is because of special formatting rules defined for Times (any symbol in general). Also certain Attributes affect pattern-matching which is performed during formatting/typesetting (Format/MakeBoxes).

ClearAll[h];

SetAttributes[h, Orderless]
Format[h[1, x__]] := Row[{x}]

Hold @ t[t[2, 1], 2] /. t -> h

% // FullForm

Hold[h[2,2]]

Hold[h[h[2,1],2]]


Of course for Times more rules are defined, it is only a small example to show the point.

Flatis an attribute that can be assigned to a symbol f to indicate that all expressions involving nested functions f should be flattened out. This property is accounted for in pattern matching.

Orderless [...]. This property is accounted for in pattern matching.

This is purely a formatting "issue":

• Can we consider this a bug still? – masterxilo Sep 22 '16 at 1:14
• Isn't the FullForm unsurprisingly correct? That's what I go to, when the typeset form seems to vary from my expectation. – Michael E2 Sep 22 '16 at 1:37
• @masterxilo. No – m_goldberg Sep 22 '16 at 3:33