16
$\begingroup$

While looking for an answer to a different problem, I came across the following example:

In[1]:= Array[Plus[##] &, {2,2}] 
Out[1]= {{2,3},{3,4}}

Having read through the documentation on Slot and SlotSequence, I understand the above example. If we think of it as a matrix $M_{ij}$, it takes the two indices and adds them up, $M_{ij}=i+j$. I also understand that it is equivalent to Array[Plus[#1,#2] &, {2, 2}].

I tried making the expression slightly more complicated:

In[2]:= Array[Plus[##,#] &, {2,2}] 
Out[2]= {{3,4},{5,6}}

which acts as $M_{ij}=(i+j)+i$, or if we replace the last # with #2, $M_{ij}=(i+j)+j$.

Now, I am really stuck on interpreting:

In[3]:= Array[Plus[## #] &, {2,2}]
Out[3]= {{1,2},{4,8}}

What is the corresponding expression for $M_{ij}$?

$\endgroup$
  • 1
    $\begingroup$ FullForm[## #] $\endgroup$ – Kuba Dec 7 '18 at 13:30
  • $\begingroup$ Thank you, as a beginner in Mathematica, I don't use FullForm as often as I should... $\endgroup$ – Jakub Kryś Dec 7 '18 at 14:02
  • 4
    $\begingroup$ Hmm, I think I need to find a place to use ######& in my code. (It's perhaps less obvious what this is here than in the frontend...) $\endgroup$ – Brett Champion Dec 7 '18 at 14:42
16
$\begingroup$

Plus[## #] & is the same as Plus[Times[##, #1]], which always computes to the same as the simpler Times[##, #1] (because Plus[x] is just x).

Thus this computes the same as

Table[i^2 * j, {i, 2}, {j, 2}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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