2
$\begingroup$

I have a confusion with the Apply function. The Apply function replaces the head of an expression at the desired level. For example:

In[124]:= Apply[Superscript, {{2, 3}}, {1}]

Out[124]= {Superscript[2,3]}

On the other hand the operator @@@ is equivalent to Apply acting at level {1} :

In[125]:= Superscript @@@ {{2, 3}}

Out[125]= {Superscript[2,3]}

However the level {1} of the expression is not an argument for Superscript:

In[126]:= Level[{{2, 3}}, {1}]

Out[126]= {{2, 3}}

In[127]:= FullForm[%]

Out[127]=List[List[2,3]]

Since :

In[131]:= Superscript[List[2, 3]]

Out[131]= Superscript[{2, 3}]

So it is as if the operator @@@ is acting at level {2}

In[129]:= Level[{{2, 3}}, {2}]

Out[129]= {2, 3}

In[130]:= FullForm[%]

Out[130]=List[2,3]

and so replacing the head in the last expression is the same as :

In[132]:= Superscript[2, 3]

Out[132]= Superscript[2,3]

What is happening here?

$\endgroup$
4
  • 3
    $\begingroup$ Level returns a list. Try Level[x[{1, 2}], {1}] to understand. $\endgroup$
    – Szabolcs
    Feb 17, 2018 at 20:33
  • 3
    $\begingroup$ "Apply replaces heads in parts of expr specified by levelspec" not "replaces the head of an expression". So it relaces heads in each of expressions in Level[{{2, 3}}, {1}] as it returns a list by default. Perhaps using different heads will be clearer $\endgroup$
    – Kuba
    Feb 17, 2018 at 20:34
  • 2
    $\begingroup$ @Szabolcs: Thankx!, I now understand my confusion: I was not interpreting correctly the output of Level, which is always a list. $\endgroup$
    – Gluoncito
    Feb 17, 2018 at 20:43
  • $\begingroup$ @Kuba: thankx ! $\endgroup$
    – Gluoncito
    Feb 17, 2018 at 20:43

0

Browse other questions tagged or ask your own question.