# When does Mathematica insert parenthesis into expression?

expr//HoldForm usually returns identical expressions as input, but sometimes parenthesis are inserted. I tried to interpret this behavior as an attempt to eliminate ambiguity, but some observation shows that it does not seem to be the real purpose.

For some long expressions (that is not trivial to see the real evaluation order), it does not add any parenthesis at all, and removes parenthesis which is unnecessary.

For this case:

0 ..


(0) ..

It could relate to this issue:https://github.com/halirutan/Mathematica-IntelliJ-Plugin/issues/31

a .. a //HoldForm


(a..) a

Adds parenthesis which doesn't seem to be able to cause any ambiguity without them. Even if they are, as long as the input is valid, it is not necessary.

My question is: Is there some rule Mathematica will insert/remove parenthesis in an expression? And what is the purpose of doing so?

Remember that the internal form of an expression is often not the same as what you type as input or is displayed as output. For example the input 0.. is interpreted as Repeated[0] and Repeated[0] is displayed in output as (0)..
Hold and HoldForm prevent evaluation but do not prevent parsing of input and formatting of output, so it is no surprise that HoldForm can produce an output which is not identical to the input. For example HoldForm[Factorial[5]] will output 5!
• Just for clarity I think, so that first period doesn't get confused as part of the real number 0. – Simon Woods May 8 '16 at 10:42