# How do I sum up p items in a sequence?

I have the following sequence

list = {p1, p2, p3, p4 ....}

I am summing up the p items as follows:

p1 + p2 + 2*sqrt (p21*p2) = p12

p12 + p3 + 2*sqrt (p12*p3) = p123

p123 + p4 + 2*sqrt (p123*p4) = p1234

How do I get the end result to be an addition of p12 + p123 + p1234 ?

-
Have a look at NestList. –  b.gatessucks Jun 24 '14 at 8:42

## 2 Answers

Fold[#1 + #2 + 2*Sqrt[#1*#2] &, First[list], Rest[list]]

-
I have done this step for step with Symbols a, b, c, d., and I get another result. Also, I think you have to sum up the terms (p12 + p123 + p1234): –  eldo Jun 24 '14 at 9:05
sorry mistake was on my part (typo) –  eldo Jun 24 '14 at 10:50

Perhaps I misread your intent, but I think what you're after is:

Total@Rest@FoldList[#1 + #2 + 2*Sqrt[1 ##] &, First[list], Rest[list]]

-