http://www.perlmonks.org?node_id=380259

BioGeek has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to implement the following recursive formula in Perl:
''''''''''''''''''''''''''''''''''''n
P(r1,r2,...,rn) = Σ(rn-i+1 - rn-i)P(r1,r2,...,rn-i,rn-i+2,...,rn)
'''''''''''''''''''''''''''''''''''i=1

(if this doesn't render well, it is the second formula on this page),
where r0=0 and the recursive call to P supplies all of the original arguments except the (n‑i+1)th argument.
I've looked at Math::Sequence and Math::Series, but the examples given there are only for simple cases like
x(n+1) = 1 / (xn + 1)
and I'm a bit lost on how to implement this formula.

As sample data you can use:
r1 0,11 0,43 0,93 0,91 0,52
r2 0,07 0,31 0,78 0,12 0,18
r3 0,19 0,37 0,82 0,15 0,32

(which should give 5 P(r1,r2,...,rn)-values)


Update: I've tried to work out a litlle example of the algorithm myself (but correct me If I'm doing something wrong).
P(r1,r2,r3)= (r3 - r2)P(r1,r2) + (r2 - r1)P(r1,r3) + (r1 - r0)P(r2,r3)

Now the iteration comes into play, because to calculate the P-values in the rigth hand side of the formula, we use our original formula again.
P(r1,r2) = (r2 - r1)P(r1) + (r1 - r0)P(r2)
P(r1,r3) = (r3 - r1)P(r1) + (r1 - r0)P(r3)
P(r2,r3) = (r3 - r2)P(r2) + (r2 - r0)P(r3)

Update: the r-values are scores, and P is a probability:
so P(r1) is the chance of having score r1,
P(r1,r2) is the chance of both having score r1 and score r2,
and so on.