Summation bug? (HP-49G, 50g) - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: Summation bug? (HP-49G, 50g) (/thread-2852.html) Summation bug? (HP-49G, 50g) - Gerson W. Barbosa - 01-13-2015 07:06 PM The HP-49G and HP-50g give wrong answers or error messages depending on the setting of flag -22 (infinite result) when the argument is zero. The HP-48g returns 1 as expected ( cos(0) = 1 ). When x = 0 the summation evaluates to 1.13518518518E498 on the HP-49G/50g, instead of zero. Am I missing something here? Thanks! HP-50g: Code:  %%HP: T(3)A(R)F(.); \<< RCLF -17. SF SWAP \-> x 'COS(\v/3./3.*(x+x^9./(32.*9.!)-\GS(k=2.,4.,x^(2.*k-1.)/(5.*(2.^k-1.)*(2.*k-1.)!))))' EVAL SWAP STOF \>> HP-48: Code:  %%HP: T(3)A(D)F(.); \<< RCLF -17 SF SWAP \-> x 'COS(\v/3/3*(x+x^ 9/(32*9!)-\GS(k=2,4,x ^(2*k-1)/(5*(2^k-1) *(2*k-1)!))))' EVAL SWAP STOF \>> RE: Summation bug? (HP-49G, 50g) - Thomas Klemm - 01-13-2015 09:25 PM Is this the expression you want to calculate? $\cos(\frac{\sqrt{3}}{3}(x+\frac{x^9}{32\cdot9!}-\sum_{k=2}^{4}\frac{x^{2k-1}}{5(2^k-1)(2k-1)!}))$ (01-13-2015 07:06 PM)Gerson W. Barbosa Wrote:  The HP-48g returns 1 as expected ( cos(0) = 1 ). That should be the correct result. I have no idea what happens when using the HP-50g. Cheers Thomas RE: Summation bug? (HP-49G, 50g) - Claudio L. - 01-13-2015 09:40 PM It seems the term x^(2*k-1) is evaluated by the sum function as x^(2*k)*x^(-1). This can be seen if you enter the summation alone, leave x undefined and press EVAL. You end up with terms x^M/(C*x). After that, numeric evaluation will attempt to do a division by zero, hence your infinite result. Perhaps if you try a round of symbolic simplification before attempting to do the numeric EVALuation. RE: Summation bug? (HP-49G, 50g) - Claudio L. - 01-13-2015 09:54 PM Apparently, the summation is done in "approx" mode even with the calculator in exact mode, so the exponents of x as well as the constants after the summation are real numbers, then the CAS is unable to simplify x^N/x. Manually editing the result of SUM to change all reals into integers then EVAL in exact mode will finally get rid of the spurious x in the denominator. I don't know if SUM is supposed to do this or not, but it's certainly an unexpected behavior, not very user-friendly. Claudio RE: Summation bug? (HP-49G, 50g) - Gerson W. Barbosa - 01-13-2015 10:13 PM (01-13-2015 09:25 PM)Thomas Klemm Wrote:  Is this the expression you want to calculate? $\cos(\frac{\sqrt{3}}{3}(x+\frac{x^9}{32\cdot9!}-\sum_{k=2}^{4}\frac{x^{2k-1}}{5(2^k-1)(2k-1)!}))$ (01-13-2015 07:06 PM)Gerson W. Barbosa Wrote:  The HP-48g returns 1 as expected ( cos(0) = 1 ). That should be the correct result. I have no idea what happens when using the HP-50g. Cheers Thomas Yes. This is a remarkable approximation of the sinc function, albeit in a limited range: http://www.wolframalpha.com/input/?i=plot+cos%28sqrt%283%29%2F3*%28x-x%5E3%2F90+-x%5E5%2F4200-x%5E7%2F378000%2Bx%5E9%2F%2832*9%21%29%29%29+-+sinc%28x%29%2C+x%3D-sqrt%283%29%2F3%3Asqrt%283%29%2F3 I have no idea why this works, however. Apparently the first four terms are correct. The last term was chosen somewhat arbitrarily to adjust the results to their correct 12 digits. Interestingly the HP-50g, unlike the HP-48, doesn't handle that summation when x = 0. Cheers, Gerson. RE: Summation bug? (HP-49G, 50g) - Gerson W. Barbosa - 01-13-2015 10:26 PM (01-13-2015 09:54 PM)Claudio L. Wrote:  Apparently, the summation is done in "approx" mode even with the calculator in exact mode, so the exponents of x as well as the constants after the summation are real numbers, then the CAS is unable to simplify x^N/x. Manually editing the result of SUM to change all reals into integers then EVAL in exact mode will finally get rid of the spurious x in the denominator. I don't know if SUM is supposed to do this or not, but it's certainly an unexpected behavior, not very user-friendly. Claudio Thanks you very much for your analysis of the problem. I've tried both exact and approximate modes and a combination of flag settings to no avail. This is not the first time I had trouble with summation on the 50g, problems the HP-48 didn't have. The last one was indeed a bug and has already been fixed. Regards, Gerson. RE: Summation bug? (HP-49G, 50g) - Thomas Klemm - 01-15-2015 01:28 AM (01-13-2015 10:13 PM)Gerson W. Barbosa Wrote:  I have no idea why this works, however. Apparently the first four terms are correct. The last term was chosen somewhat arbitrarily to adjust the results to their correct 12 digits. This is the Taylor-Series of $$\arccos(sinc(x))$$: $\frac{1}{\sqrt{3}}(x-\frac{x^3}{90}-\frac{x^5}{4200}-\frac{x^7}{378000}+\frac{533 x^9}{6286896000}+\frac{2599 x^{11}}{454053600000}+\frac{75799 x^{13}}{572107536000000})+O(x^{14})$ The correct value is $$\frac{6,286,896,000}{533}=\frac{17,325\cdot9!}{533}\approx11,795,302.0638$$ instead of $$32\cdot9! = 11,612,160$$. Thus instead of 32 the factor is $$\frac{17,325}{533}\approx32.5047$$. Quote:This is a remarkable approximation of the sinc function Now I hope it's clear why. Cheers Thomas RE: Summation bug? (HP-49G, 50g) - Gerson W. Barbosa - 01-15-2015 09:37 AM (01-15-2015 01:28 AM)Thomas Klemm Wrote:   (01-13-2015 10:13 PM)Gerson W. Barbosa Wrote:  I have no idea why this works, however. Apparently the first four terms are correct. The last term was chosen somewhat arbitrarily to adjust the results to their correct 12 digits. This is the Taylor-Series of $$\arccos(sinc(x))$$: $\frac{1}{\sqrt{3}}(x-\frac{x^3}{90}-\frac{x^5}{4200}-\frac{x^7}{378000}+\frac{533 x^9}{6286896000}+\frac{2599 x^{11}}{454053600000}+\frac{75799 x^{13}}{572107536000000})+O(x^{14})$ The correct value is $$\frac{6,286,896,000}{533}=\frac{17,325\cdot9!}{533}\approx11,795,302.0638$$ instead of $$32\cdot9! = 11,612,160$$. Thus instead of 32 the factor is $$\frac{17,325}{533}\approx32.5047$$. Quote:This is a remarkable approximation of the sinc function Now I hope it's clear why. It is crystal clear now! Thank you very much! Gerson.