Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

conditional summation notation

292 views
Skip to first unread message

duncan smith

unread,
Jun 11, 2011, 10:15:58 PM6/11/11
to
Hello,
Just looking for some advice on notation when I'm summing over
elements subject to a condition.

e.g. I might have sample counts and corresponding population counts and
want to sum over the ratios where the population frequency is non-zero.
e.g. Using Python syntax; assume the sample and population counts are in
the lists f and F respectively,


res = sum([f[i] / F[i] for i in range(len(F)) if F[i]!=0])


I'm just seeking a clean mathematical notation for this. Also, in some
cases I want e.g. the number of sample counts equal to 2,


res = sum([1 for freq in f if freq==2])


At the moment I'm using a form of syntax I've seen before. But I'm
beginning to think it might be an abuse of the indicator function. e.g.
for the first example,


sum from {i} {f_i over F_i} I(F_i <> 0)


I'd be grateful for any hints. TIA.

Duncan

Butch Malahide

unread,
Jun 12, 2011, 2:50:42 AM6/12/11
to
On Jun 11, 9:15 pm, duncan smith <buzz...@urubu.freeserve.co.uk>
wrote:

>        Just looking for some advice on notation when I'm summing over
> elements subject to a condition.

This is discussed by Knuth in the Amer. Math. Monthly article cited
here:
http://en.wikipedia.org/wiki/Iverson_bracket

William Elliot

unread,
Jun 12, 2011, 2:51:51 AM6/12/11
to
On Sun, 12 Jun 2011, duncan smith wrote:

> Hello,
> Just looking for some advice on notation when I'm summing over elements
> subject to a condition.
>
> e.g. I might have sample counts and corresponding population counts and
> want to sum over the ratios where the population frequency is non-zero.
> e.g. Using Python syntax; assume the sample and population counts are in
> the lists f and F respectively,
>
> res = sum([f[i] / F[i] for i in range(len(F)) if F[i]!=0])
>

sum(i in range(len F) & F(i) /= 0) f(i)/F(i)

sum[i in range(len F) & F(i) /= 0] f(i)/F(i)

> I'm just seeking a clean mathematical notation for this. Also, in some
> cases I want e.g. the number of sample counts equal to 2,
>
> res = sum([1 for freq in f if freq==2])
>

= 1 if freq = 2 in f
= 0 otherwise

> At the moment I'm using a form of syntax I've seen before. But I'm
> beginning to think it might be an abuse of the indicator function. e.g.
> for the first example,
>
> sum from {i} {f_i over F_i} I(F_i <> 0)
>

Is that an infinite sum?

duncan smith

unread,
Jun 12, 2011, 12:19:05 PM6/12/11
to

No, a sum over a finite number of categories indexed i = 1, ..., N. I
forgot to make that clear. It looks like I might go with Knuth's
notation suggested by Butch, which isn't that far from what I was using.
The idea of "strong" zeroes also gets round the issue of division by
zero. e.g. (0/0)[false] = 0. Thus the 2 examples become (in OpenOffice
syntax),

sum from {i} {f_i over F_i} [F_i <> 0]

sum from {i} [f_i = 2]

Thanks.

Duncan

duncan smith

unread,
Jun 12, 2011, 12:20:25 PM6/12/11
to

Excellent! I thought there must be a neat way of doing it. Love the
strong zeroes.

Duncan

0 new messages