3
$\begingroup$

This question already has an answer here:

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!

$\endgroup$

marked as duplicate by Daniel Lichtblau, MarcoB, Mr.Wizard May 28 '17 at 6:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ Check the FullForm. The 1 is not displayed, but it is in fact there. $\endgroup$ – Szabolcs May 27 '17 at 14:32
  • $\begingroup$ Nope~ It's not there. Once you evaluate it, it's not there: HoldComplete[a 2 1 2] // FullForm returns HoldComplete[Times[a, 2, 1, 2]] while do the same to the evaluation result of HoldComplete[a 2 1 2] would give HoldComplete[Times[a, 2, 2]] $\endgroup$ – Wjx May 27 '17 at 14:36
  • $\begingroup$ I think this makes things even wierder...... $\endgroup$ – Wjx May 27 '17 at 14:38
  • 2
    $\begingroup$ You are not applying FullForm to the actual evaluation result. You are applying it to some text in the output cell. That is not the same thing. Assign the result to a variable. $\endgroup$ – Szabolcs May 27 '17 at 14:40
  • $\begingroup$ Oh, good point! But how can I let it display just like the way I entered? $\endgroup$ – Wjx May 27 '17 at 14:43
6
$\begingroup$

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:

$\endgroup$
  • $\begingroup$ What is "stdout"? I've never seen that before. $\endgroup$ – QuantumDot May 27 '17 at 16:32
  • 2
    $\begingroup$ @QuantumDot It's the name of the standard output stream. By default $Output lists it as OutputStream["stdout", 1]. But it is possible to refer to it directly as to "stdout". $\endgroup$ – Alexey Popkov May 27 '17 at 16:45
  • $\begingroup$ +1 nice explanation! $\endgroup$ – Ali Hashmi May 27 '17 at 17:10
  • $\begingroup$ Nice explanation! Thanks~ $\endgroup$ – Wjx May 28 '17 at 1:21

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