How to resolve the algorithm Sum of a series step by step in the LFE programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sum of a series step by step in the LFE programming language

Table of Contents

Problem Statement

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:

This approximates the   zeta function   for   S=2,   whose exact value is the solution of the Basel problem.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sum of a series step by step in the LFE programming language

Source code in the lfe programming language

(defun sum-series (nums)
  (lists:foldl
    #'+/2
    0
    (lists:map
      (lambda (x) (/ 1 x x))
      nums)))


(defun sum-series (nums)
  (lists:sum
    (lists:map
      (lambda (x) (/ 1 x x))
      nums)))


> (sum-series (lists:seq 1 100000))
1.6449240668982423


  

You may also check:How to resolve the algorithm One-dimensional cellular automata step by step in the Picat programming language
You may also check:How to resolve the algorithm Sum digits of an integer step by step in the Go programming language
You may also check:How to resolve the algorithm Cut a rectangle step by step in the Haskell programming language
You may also check:How to resolve the algorithm Closest-pair problem step by step in the Python programming language
You may also check:How to resolve the algorithm Cheryl's birthday step by step in the VBA programming language