How to resolve the algorithm Bernoulli numbers step by step in the Icon and Unicon programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Bernoulli numbers step by step in the Icon and Unicon programming language

Table of Contents

Problem Statement

Bernoulli numbers are used in some series expansions of several functions   (trigonometric, hyperbolic, gamma, etc.),   and are extremely important in number theory and analysis. Note that there are two definitions of Bernoulli numbers;   this task will be using the modern usage   (as per   The National Institute of Standards and Technology convention). The   nth   Bernoulli number is expressed as   Bn.

The Akiyama–Tanigawa algorithm for the "second Bernoulli numbers" as taken from wikipedia is as follows:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Bernoulli numbers step by step in the Icon and Unicon programming language

Source code in the icon programming language

link "rational"

procedure main(args)
    limit := integer(!args) | 60
    every b := bernoulli(i := 0 to limit) do
        if b.numer > 0 then write(right(i,3),": ",align(rat2str(b),60))
end

procedure bernoulli(n)
    (A := table(0))[0] := rational(1,1,1)
    every m := 1 to n do {
        A[m] := rational(1,m+1,1)
        every j := m to 1 by -1 do A[j-1] := mpyrat(rational(j,1,1), subrat(A[j-1],A[j]))
        }
    return A[0]
end

procedure align(r,n)
    return repl(" ",n-find("/",r))||r
end


  

You may also check:How to resolve the algorithm Dice game probabilities step by step in the J programming language
You may also check:How to resolve the algorithm Conditional structures step by step in the Julia programming language
You may also check:How to resolve the algorithm Greatest element of a list step by step in the Ela programming language
You may also check:How to resolve the algorithm Magnanimous numbers step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Isqrt (integer square root) of X step by step in the jq programming language