3

HoldComplete[2 3 3] will return HoldComplete[2 3 3]. HoldComplete[b a] will return HoldComplete[b a].

Everything works fine here, no replacement rules called, no evaluation done, the Flat attribute didn't apply.

but things get weird when we evaluate HoldComplete[a 2 1 2]:

The desired result shall be HoldComplete[a 2 1 2] as no modification should be done here, however, the result is HoldComplete[a 2 2], it seems that the 1 is magically omitted as it's not important here in multiplication!

How could this happen? Is this a bug? How can I solve this problem?

Thanks!

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
Wjx
  • 9,558
  • 1
  • 34
  • 70

1 Answers1

6

What you see in the output cell is just a visualization of the actual result of the evaluation. When working with the FrontEnd the default FormatType of the output stream is StandardForm what means that FormatValues rules for StandardForm will automatically be applied to the actual output before sending it to the FrontEnd (in order to produce a typeset expression):

Options["stdout", FormatType]
{FormatType -> StandardForm}
MakeBoxes[HoldComplete[a 2 1 2], StandardForm]    
RowBox[{"HoldComplete", "[", 
  RowBox[{"a", " ", "2", " ", "2"}], "]"}]

You can switch to purely textual InputForm display mode by wrapping your input by InputForm:

In[3]:=
HoldComplete[a 2 1 2]//InputForm    

Out[3]//InputForm=
HoldComplete[a*2*1*2]

You can also check the actual result of the evaluation by requesting it from the history:

In[4]:= HoldComplete[a 2 1 2];

In[5]:= % // FullForm

Out[5]//FullForm= 
HoldComplete[Times[a,2,1,2]]

Related:

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368