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.




 
bundle Default {
  class SumSeries {
    function : Main(args : String[]) ~ Nil {
      DoSumSeries();
    }
 
    function : native : DoSumSeries() ~ Nil {
      start := 1;
      end := 1000;
 
      sum := 0.0;
 
      for(x : Float := start; x <= end; x += 1;) {
        sum += f(x);
      };
 
      IO.Console->GetInstance()->Print("Sum of f(x) from ")->Print(start)->Print(" to ")->Print(end)->Print(" is ")->PrintLine(sum);
    }
 
    function : native : f(x : Float) ~ Float {
      return 1.0 / (x * x);
    }
  }
}
 