Question: Broken Summation Notation


Below is a Maple ws describing the problem. I have some fixed values pr0 and pr1, and a four variations of a function "pdf". The problem is that when I use the function in a sum (either the "sum" function or the sigma notation), the result is different than if I write out the sum explicitly. It's very puzzling as to why they woudl be different in the first place, but even more strange is that the different versions have *different* deltas. Even version 3, with a delta of 10^-100 is too much for my application (moreover the delta gets larger when I sum over more terms).

 

In the worksheet below, I compare "sum(f(x),x=3..3)" to "f(3)". I expect this should always be identically 0, but that is not true for any of the four versions of my function. (The same is true for "Sum(f(x),x=3..3)".) However, "sum(f(3),x=3..3)" *is* (blessedly) identically "f(3)". What gives?

restart

pr[0] := .499999999999999999999852096538403821434745813543502066245832554193147476551830440227306019620687012523264913799181385911651886999607086181640625:

pr[1] := .43394228095117646589504674154844928036961264935215813494922283329725383492977635163048065719014507668417797436877236805230495519936084747314453125:

pr0 := .499999999999999999999852096538403821434745813543502066245832554193147476551830440227306019620687012523264913799181385911651886999607086181640625:

pr1 := .43394228095117646589504674154844928036961264935215813494922283329725383492977635163048065719014507668417797436877236805230495519936084747314453125:

pdf1 := proc (x) local j, prob, y; prob := 1; y := x; for j from 0 to 1 do if `mod`(y, 2) = 1 then prob := prob*pr[j] else prob := prob*(1-pr[j]) end if; y := floor((1/2)*y) end do; return prob end proc:

Maple doesn't always like subscripted variables. Is that the problem?

pdf2 := proc (x) local prob, y; prob := 1; y := x; if `mod`(y, 2) = 1 then prob := prob*pr0 else prob := prob*(1-pr0) end if; y := floor((1/2)*y); if `mod`(y, 2) = 1 then prob := prob*pr1 else prob := prob*(1-pr1) end if; return prob end proc:

Maybe it's the binary expansion that's the issue

pdf3 := proc (arr) options operator, arrow; product(arr[2-j]*pr[j]+(1-arr[2-j])*(1-pr[j]), j = 0 .. 1) end proc:

No procedures, no arrays

pdf4 := proc (x) options operator, arrow; (`mod`(x, 2))*pr0+(1-(`mod`(x, 2)))*(1-pr0)+(`mod`(floor((1/2)*x), 2))*pr1+(1-(`mod`(floor((1/2)*x), 2)))*(1-pr1) end proc:

evalf[100](sum(pdf1(i), i = 3 .. 3)-pdf1(3));

0.660577190488235341051011619131468981956415371043397988049446125095986885183932081422133231891679108e-1

 

0.660577190488235341051011619131468981956415371043397988049446125095986885183932081422133231891679108e-1

 

0.

(1)

``

evalf[100](sum(pdf2(i), i = 3 .. 3)-pdf2(3));

0.660577190488235341051011619131468981956415371043397988049446125095986885183932081422133231891679108e-1

 

0.

(2)

evalf[100](sum(sum(pdf3([i1, i2]), i2 = 1 .. 1), i1 = 1 .. 1)-pdf3([1, 1]));

0.1e-99

 

0.

(3)

evalf[100](sum(pdf4(i), i = 3 .. 3)-pdf4(3));

-0.5916138463847142610167458259917350166697832274100937926782390907759215172519498e-21

 

0.

(4)

``

``

``

``

 

Download maple_bug.mw

Please Wait...