Skip to content
Back to formatted view

Raw Message

Message-ID: <BDDA6995-B77A-4490-ADC9-84D6B1F7AC1B@comcast.net>
Date: 2009-05-01T23:31:45Z
From: David Winsemius
Subject: Double summation limits
In-Reply-To: <c8298d460905011245g7a581c09x2898bc997993cd59@mail.gmail.com>

Perhaps:

SSCxy <- function(z) {tail(sapply(0:z, function (x) sum(sapply(0:x,  
function(y) sum(choose(x+y, y))))), 1) }

 > SSCxy(5)
[1] 462

See also:
http://www.research.att.com/~njas/sequences/?q=1%2C3%2C10%2C35%2C126%2C462&sort=0&fmt=0&language=english&go=Search


On May 1, 2009, at 3:45 PM, Orestis Chrysafis wrote:

> Dear R experts
> I need to write a function that incorporates double summation, the  
> problem
> being that the upper limit of the second summation is the index of  
> the first
> summation, i.e:
>
> sum_{j=0}^{x} sum_{i=0}^{j} choose(i+j, i)
>
> where x variable or constant, doesn't matter.
> The following code obviously doesn't work:
>
> f=function(x) {j=0:x; i=0:j; sum( choose(i+j,i) )  }
>
> Can you help?
> Thanks in advance,
>
> Orestis Chrysafis
> School of Mathematics
> University of Sheffield

David Winsemius, MD
Heritage Laboratories
West Hartford, CT