# I keep writing functions like this one: subtract[{a_, b_}] := Subtract[a, b] [duplicate]

(Edited to provide an example)

Recently I have found myself writing silly functions like the following, which is just a new arity of Subtract in which the arguments are inside a list.

subtract[{a_, b_}] := Subtract[a, b]

If I were adding that variant to one of my own functions, I would use the same name, and would feel more comfortable about it.

I feel sure I should not need to do this for system functions, yet these variants are very convenient when I am working with lists.

There is probably some elementary principle of Mathematica coding that I have failed to absorb. What could it be?

Example:

pairsOfPositions = {{{a, b, c}, {d, e, f}}, {{g, h, i}, {j, k, l}}, {{m, n, o}, {p, q, r}}}; differences = Map[subtract, pairsOfPositions, {1}];

where the desired result for differences is  { {a - d, b - e, c - f}, {g - j, h - k, i - l}, {m - p, n - q, o - r} }

• Aug 3, 2015 at 1:22
• Proposed duplicates: (10833), (46238) Aug 3, 2015 at 2:10
• My question is supposed to be about items embedded in a list. Maybe Apply would help, but I don't yet understand how. Aug 3, 2015 at 2:28
• @RalphDratman does not Subtract @@@ pairsOfPositions give the output you want? If so you just need to take the time to understand Apply. If this is not the result you want or you chose a narrow example please edit the question to explain. Aug 3, 2015 at 2:30
• Yes, thank you Sir Wizard, Subtract @@@ pairsOfPositions does work. Thank you so much. I will as you suggested look more deeply into Apply. Aug 3, 2015 at 2:55

Subtract @@ {a, b}