Post Reply 
(34C) (11C) Summation of Infinite Alternating Series
02-10-2021, 06:04 PM (This post was last modified: 02-13-2021 05:22 PM by Valentin Albillo.)
Post: #1
(34C) (11C) Summation of Infinite Alternating Series
 
Extracts from HP Program VA342 - HP-34C Summation of Alternating Series
    Abstract
     
      SUMALT is a program written in 1979 for the HP-34C programmable calculator to quickly and accurately find the sum of infinite alternating series, even divergent ones (Euler sum). Three worked examples are included.

      Keywords: sum, infinite alternating series, Euler Transformation, Euler sum, differences, programmable calculator, RPN, HP-34C

    Introduction
     
      SUMALT is a short (84 steps) RPN program that I wrote in 1979 for the HP-34C calculator (will also run as-is or with minor modifications in many RPN models, such as the HP-11C) which, given an infinite alternating series (i.e.: consecutive terms alternate signs) whose general term is defined by the user, it will compute its sum very quickly using the Euler Transformation up to 7th-order differences. [...]

Link to PDF: HP Program VA342 - HP-34C Summation of Alternating Series.pdf

V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
02-12-2021, 03:04 PM
Post: #2
RE: (34C) Summation of Infinite Alternating Series
The code is amazing !
I did spot a few typos in the pdf, however.

S = Σ((-1)^i * y(i), i = 0 .. inf) = y(0)/2 - Δ(y(0))/4 + Δ²(y(0))/8 - ...

S is splitted to 2 parts: S = S' + S''

S' = Σ((-1)^i * y(i), i = 0 .. n)
S'' = y(n+1)/2 - Δ(y(n+1))/4 + Δ²(y(n+1))/8 - ...

There are 2 issues with this.

1. S' actually summed n+1 terms, not n terms, as stated in the pdf
2. if n is even, S = S' - S'', not S' + S''

With these corrections, I was able to confirm example 1, S = 1 - 1/2 + 1/3 - 1/4 + ...
Code:
function euler_transform(t) -- S = t[1] - t[2] + t[3] - t[4] + ...
    local n, k = #t, 0.5
    for i = 2,n do          -- {1, D, D^2, ...} of t[1]
        for j = n,i,-1 do t[j] = t[j] - t[j-1] end
    end
    for i = 1,n do t[i] = t[i]*k; k = -0.5*k; end
end                         -- S = t[1] + t[2] + t[3] + t[4] + ...

lua> n, d, t = 10, 7, {}
lua> for i=n+1,n+d+1 do t[i-n] = 1/(i+1) end -- terms to estimate s2
lua> euler_transform(t)
lua> table.foreachi(t, print)
1      0.041666666666666664
2      0.0016025641025641003
3      0.00011446886446886233
4      1.1446886446884671e-005
5      1.4308608058594997e-006
6      2.1042070674336805e-007
7      3.50701177901638e-008
8      6.4602848558431396e-009

lua> s1, s2 = 0, 0
lua> for i=0,n do s1 = s1 + (-1)^i/(i+1) end -- n+1 terms
lua> for i=1,d+1 do s2 = s2 + t[i] end          -- d+1 terms
lua> s1, s2
0.7365440115440116       0.043396829332061765
lua> s1 - s2       -- n is even, thus the minus sign
0.6931471822119498

We may apply Aitken Extrapolation, to slight improve estimate of s2

lua> s1 - (s2 - t[d+1]^2/(t[d+1] - t[d]))
0.6931471807531758
lua> log(2)
0.6931471805599453
Find all posts by this user
Quote this message in a reply
02-13-2021, 05:51 PM
Post: #3
RE: (34C) (11C) Summation of Infinite Alternating Series
 
Hi, Albert Chan:

(02-12-2021 03:04 PM)Albert Chan Wrote:   
The code is amazing !

Thank you for your kind words, much appreciated.

Quote:I did spot a few typos in the pdf, however.

Nah, not exactly typos as in "I typed something incorrectly" but simply that I was being somewhat informal (originally it was a "Long Live"-Series article, not a formal math paper), not counting term 0 or caring to specify the precise alternating sign for the correction terms. However, rest assured that the RPN program code of course does take these details into account and is perfectly correct, as you may check if you run the examples featured or any others of your own.

Thanks again and keep your eyes peeled for my next post tomorrow 14th, to commemorate my worldwide-known saint patron's festivity. I'll welcome any inputs from you but please, no Lua, no Xcas, I know you'll be itching to use them but please refrain from doing so. If you want to contribute something, I'd appreciate it if you would please post code or results for some HP calc using some HP-calc language and we'll remain in good terms, Ok ?  Smile

Regards
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
02-13-2021, 06:15 PM
Post: #4
RE: (34C) (11C) Summation of Infinite Alternating Series
(02-13-2021 05:51 PM)Valentin Albillo Wrote:  Thanks again and keep your eyes peeled for my next post tomorrow 14th, to commemorate my worldwide-known saint patron's festivity.

Looking forward to it Smile

Quote: I'll welcome any inputs from you but please, no Lua, no Xcas ...

Noted.

I just wanted to show how Euler transformation converted slowly convering sum, into a fast one.
I should have just post the Euler transformed partial sum table ...
Find all posts by this user
Quote this message in a reply
02-13-2021, 10:34 PM
Post: #5
RE: (34C) (11C) Summation of Infinite Alternating Series
I have worked through this nice paper and algorithm too, many thanks Valentin!

(02-12-2021 03:04 PM)Albert Chan Wrote:  We may apply Aitken Extrapolation, to slight improve estimate of s2

lua> s1 - (s2 - t[d+1]^2/(t[d+1] - t[d]))
0.6931471807531758
lua> log(2)
0.6931471805599453

Very clever to think of that. I have one question. I would think that t[d+1]^2/(t[d+1] - t[d]) and (x[n+1]-x[n])^2/((x[n+1]-x[n])-(x[n]-x[n-1])) are related if terms x[] are extrapolated, but that is not the case? Shouldn't the formula be (t[d]+t[d+1])^2/(t[d+1]) since when d=2 for example t[2]=x[n+2]-x[n+1] and t[3]=x[n+3]-2x[n+2]+x[n+1]? How did you derive your formula?

- Rob

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
02-13-2021, 11:30 PM
Post: #6
RE: (34C) (11C) Summation of Infinite Alternating Series
Hi, robve

Let the last 3 cumulative sum of s2 be a, b, c

a + t[d] = b
b + t[d+1] = c = s2

Aitken(a,b,c) = c - (c-b)^2/((c-b)-(b-a)) = s2 - t[d+1]^2 / (t[d+1] - t[d])

Or, Secant's method, from 2 points: (x1, y1) = (b, t[d]), (x2, y2) = (c, t[d+1])
Extrapolate for (x, t[∞] = 0). Both methods are equivalent.

x = x2 - y2 * (x2-x1)/(y2-y1) = s2 - t[d+1]^2 / (t[d+1] - t[d])
Find all posts by this user
Quote this message in a reply
02-14-2021, 11:30 AM
Post: #7
RE: (34C) (11C) Summation of Infinite Alternating Series
(02-13-2021 11:30 PM)Albert Chan Wrote:  Or, Secant's method, from 2 points: (x1, y1) = (b, t[d]), (x2, y2) = (c, t[d+1])

Selection of points is arbitrary, as long as it is consistent.
Example, we can use mean of 2 cumulative sum for x's, estimated error gap for y's

(x1, y1) = ((b+a)/2, (b-a)/2)
(x2, y2) = ((c+b)/2, (c-b)/2)

Again, Secant's method, extrapolate for (x, 0)

x = (c+b)/2    - (c-b)/2 * ((c+b)/2 - (b+a)/2) / ((c-b)/2 - (b-a)/2)
  = c - (c-b)/2 - (c-b)/2 * (c-a) / (c-2b+a)
  = c - (c-b)/2 * ((c-2b+a) + (c-a)) / (c-2b+a)
  = c - (c-b)^2 / (c-2b+a)
  = Aitken(a, b, c)
Find all posts by this user
Quote this message in a reply
02-16-2021, 01:57 AM
Post: #8
RE: (34C) (11C) Summation of Infinite Alternating Series
(02-14-2021 11:30 AM)Albert Chan Wrote:  Again, Secant's method, extrapolate for (x, 0)

x = (c+b)/2    - (c-b)/2 * ((c+b)/2 - (b+a)/2) / ((c-b)/2 - (b-a)/2)
  = c - (c-b)/2 - (c-b)/2 * (c-a) / (c-2b+a)
  = c - (c-b)/2 * ((c-2b+a) + (c-a)) / (c-2b+a)
  = c - (c-b)^2 / (c-2b+a)
  = Aitken(a, b, c)

Thanks, that explains it. I misunderstood the extrapolation was for S2, not the infinite alternating series (which couldn't be much of an improvement).

Note that in general one should run the summation loop for S2 in Euler_transform backwards to accumulate fewer roundoff errors because the summand terms t[i] diminish quickly. Though I can't see how it really improves the final S that is already an approximation.

- Rob

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
03-02-2022, 03:17 PM
Post: #9
RE: (34C) (11C) Summation of Infinite Alternating Series
This has been here for a while: (11C) Summation of infinite, alternating series
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 3 Guest(s)