crockeea

10 Reputation

0 Badges

9 years, 193 days

MaplePrimes Activity


These are questions asked by crockeea


In the following code, the evalf prints -32.16... 

restart; S := 8;

sigma := 8/sqrt(2*Pi);

iprec := 151;

evalf(log[2](-(sum(log(round(2^iprec*exp(-j^2/(2*sigma^2)))/2^iprec*exp(-j^2/(2*sigma^2))))*round(2^iprec*exp(-j^2/(2*sigma^2)))/2^iprec, j = 0 .. 7))));

 

Change the last line to evalf[20](log[2](....)), and re-run *just that line*. It now prints -66.67...

Change the last line to evalf[200](log[2](...)) and re-run *just that line* again. It now prints -151.24... (I have strong evidence to support that the true value is near -151, so I believe this answer.)

Now remove the precision indicator from the command completely and re-run just the last line. It *still* prints -151.24...!

 

My two questions are: why do I need evalf[200] to get the first three digits of the answer to be correct? and why does setting the evalf precision and then removing it cause the previous precision to persist?


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

In the following worksheet, I can evaluate S(32), but not S(31). As a result, I can't use any value that depends on S(31) (or any i<31), for example, the graph is incomplete. How can I get Maple to evaluate S(31)?

restart

sigma := 167:

t := proc (i) options operator, arrow; exp(-(1/2)*i^2/sigma^2) end proc:

S := proc (l) options operator, arrow; 1+2*(sum(t(i), i = l .. infinity)) end proc:

evalf(S(32))

356.9784188

(1)

evalf(S(31))

1.+2.*(sum(exp(-(1/55778)*i^2), i = 31 .. infinity))

(2)

Expected result of evalf(S(31)):

evalf(S(32)+2*t(31))

358.9442559

(3)

plot(S(y), y = 20 .. 50)

 

``


All told, S(i) fails for i in [0..31], i = 115,116, and 221. S(i) succeeds for all other i < 3500.

Download test.mw

 

Page 1 of 1