Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence.

Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task.

For this task, use:

 




S

n


=

∑

k
=
1


n




1

k

2






{\displaystyle S_{n}=\sum _{k=1}^{n}{\frac {1}{k^{2}}}}




 and compute   




S

1000




{\displaystyle S_{1000}}




This approximates the   zeta function   for   S=2,   whose exact value

 



ζ
(
2
)
=



π

2


6




{\displaystyle \zeta (2)={\pi ^{2} \over 6}}


is the solution of the Basel problem.




 
 [Sum of a series, Rosetta Code website.
  EDSAC program, Initial Orders 2.]
            ..PZ  [blank tape and terminator]
 
 [Library subroutine D6 - Division, accurate, fast.
  36 locations, working positons 6D and 8D.
  C(0D) := C(0D)/C(4D), where C(4D) <> 0, -1.]
            T56K
  GKA3FT34@S4DE13@T4DSDTDE2@T4DADLDTDA4DLDE8@RDU4DLDA35@
  T6DE25@U8DN8DA6DT6DH6DS6DN4DA4DYFG21@SDVDTDEFW1526D
 
 [Library subroutine P1 - Print positive number, no formatting or round-off.
  Prints number in 0D to n places of decimals, where n is specified by 'P n F'
  pseudo-order after subroutine call.  21 locations.]
            T92K
  GKA18@U17@S20@T5@H19@PFT5@VDUFOFFFSFL4FTDA5@A2FG6@EFU3FJFM1F
 
 [Custom subroutine to calculate 1/k^2 for a 17-bit integer k > 1.
  Input:  0F = k (with the usual scaling; actually k/(2^16).
  Output: 0D = 1/k^2.]
            T120K  GK
            A3F  T11@   [set up return to caller as usual]
            HF          [multiply register := k/(2^16)]
            VF          [acc := k/(2^16) squared]
   [At this point acc =(k^2)/(2^32). Now we switch to 35-bit
    arithmetic, in which integers are scaled by 2^(-34)]
            R1F         [shift acc 2 right to adjust scaling]
            T4D         [4D := k^2]
            TD          [set 0D := 0; clears "sandwich bit" between 0F and 1F]
            A12@  TF    [set 0D := 1 by setting 0F := 1]
            A9@  G56F   [call EDSAC library subroutine for division]
     [11]   ZF          [overwritten by jump back to caller]
     [12]   PD          [short constant 1]
 
 [Main program]
            T200K  GK   [load at even address because of long variable at 0]
      [0]   PF  PF      [build sum here]
      [2]   PD          [short constant 1]
      [3]   P500F       [short constant 1000]
      [4]   K2048F  #F  !F  @F  &F  [letters, figures, space, CR, LF]
      [9]   HF  IF  LF  [letters H, I, L (in letters mode)]
     [12]   QF  MF      [digit 1, dot (in figures mode)]
     [14]   PF          [variable k]
 
     [15]   T#@  A2@ T14@            [sum := 0, k := 1]
     [18]   TF  A14@  A2@  U14@  TF  [inc k; pass new k to function in 0F]
            A23@  G120F              [call function; places 1/k^2 at 0D]
            AD  A#@  T#@             [add 1/k^2 into sum]
            A14@  S3@  G18@          [test for k = maximum, loop back if not]
            O4@  O11@  O89@  O6@  O15@  O89@  O6@  O9@  O10@  O6@  [print 'LO TO HI ']
            O5@  O12@  O13@          [print '1.']
            A#@  TD  A46@  G92F      [call subroutine to print decimal part]
            P10F                     [parameter for print subroutine; 10 decimal places]
            O7@  O8@                 [print CR, LF]
 
       [Sum in reverse order to confirm that the result is identical on EDSAC.
        Not much different from the above, so given in condensed form.]
            TFT#@A3@T14@TFA14@TFA58@G120FADA#@T#@A14@S2@U14@S2FE55@TDA#@TD
            O4@O9@O10@O6@O15@O89@O6@O11@O89@O6@O5@O12@O13@A84@G92FP10FO7@O8@
 
     [89]   O5@  ZF                  [flush teleprinter buffer; stop]
            E15Z  PF                 [define entry point; enter with acc = 0]
 