# Applying a function to successive overlapping list elements?

I have a list of elements and I would like to create a new list by applying a function to successive overlapping pairs from the original list.

Specifically, I am trying compute the Pythagorean sum of each pair. So, if the original list is {$$a,b,c,d,...$$} I want {$$\sqrt{a^2+b^2},\sqrt{b^2+c^2},\sqrt{c^2+d^2},...$$}

Since this is similar to the built-in Differences function, (which turns the original list into {$$b-a,c-b,d-c,...$$}), I expected to find a built-in function along the lines of BuiltIn[f,{a,b,c,d,...},options] where f is defined by the user. But alas, my search has been fruitless...

-----------EDIT-----------

Right after posting this, I came up with

Sqrt[#1^2 + #2^2] & @@@ Subsequences[#, {2}] &@{a, b, c, d}


which does the trick. I was going to update that here, but you all already came through with your own answers, so I'll try those as well. Thanks!

• Norm /@ Partition[yourList, 2, 1]? – MarcoB Apr 22 at 18:11
• Perhaps something like Sqrt[#1^2 + #2^2] & @@@ Partition[list, 2, 1]? – J. M.'s discontentment Apr 22 at 18:11
• Relevant answers here, in particular PartitionMap. – b.gates.you.know.what Apr 22 at 18:12

You can use BlockMap + Norm

BlockMap[Norm, {a, b, c, d, e}, 2, 1]

{Sqrt[Abs[a]^2 + Abs[b]^2], Sqrt[Abs[b]^2 + Abs[c]^2],
Sqrt[Abs[c]^2 + Abs[d]^2], Sqrt[Abs[d]^2 + Abs[e]^2]}

TeXForm @ Simplify[%, Thread[{a, b, c, d, e} >= 0]]


$$\left\{\sqrt{a^2+b^2},\sqrt{b^2+c^2},\sqrt{c^2+d^2},\sqrt{d^2+e^2}\right\}$$

• Beautiful. Thanks! – Aaron Eiben Apr 22 at 18:28
• @AaronEiben, my pleasure. Thank you for the accept. – kglr Apr 22 at 18:35