How to resolve the algorithm Hickerson series of almost integers step by step in the Forth programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Hickerson series of almost integers step by step in the Forth programming language

Table of Contents

Problem Statement

The following function,   due to D. Hickerson,   is said to generate "Almost integers" by the "Almost Integer" page of Wolfram MathWorld,   (December 31 2013).   (See formula numbered   51.)

The function is:

h ( n )

n !

2 ( ln ⁡

2

)

n + 1

{\displaystyle h(n)={\operatorname {n} ! \over 2(\ln {2})^{n+1}}}

It is said to produce "almost integers" for   n   between   1   and   17.
The purpose of the task is to verify this assertion. Assume that an "almost integer" has either a nine or a zero as its first digit after the decimal point of its decimal string representation

Calculate all values of the function checking and stating which are "almost integers". Note: Use extended/arbitrary precision numbers in your calculation if necessary to ensure you have adequate precision of results as for example:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Hickerson series of almost integers step by step in the Forth programming language

Source code in the forth programming language

[UNDEFINED] ANS [IF]
include lib/fp1.4th                    \ Zen float version
include lib/zenfprox.4th               \ for F~
include lib/zenround.4th               \ for FROUND
include lib/zenfln.4th                 \ for FLN
include lib/zenfpow.4th                \ for FPOW
[ELSE]
include lib/fp3.4th                    \ ANS float version
include lib/flnflog.4th                \ for FLN
include lib/fpow.4th                   \ for FPOW           
[THEN]

include lib/fast-fac.4th               \ for FACTORIAL

fclear                                 \ initialize floating point
float array ln2 2 s>f fln latest f!    \ precalculate ln(2)
                                       \ integer exponentiation
: hickerson dup >r factorial s>f ln2 f@ r> 1+ fpow fdup f+ f/ ;
: integer? if ." TRUE " else ." FALSE" then space ;
                                       \ is it an integer?
: first17
  18 1 do                              \ test hickerson 1-17
    i hickerson i 2 .r space fdup fdup fround
    s" 1e-1" s>float f~ integer? f. cr
  loop                                 \ within 0.1 absolute error
;

first17


  

You may also check:How to resolve the algorithm Fraction reduction step by step in the C programming language
You may also check:How to resolve the algorithm Gray code step by step in the zkl programming language
You may also check:How to resolve the algorithm Shoelace formula for polygonal area step by step in the Ruby programming language
You may also check:How to resolve the algorithm Call an object method step by step in the Delphi programming language
You may also check:How to resolve the algorithm CSV to HTML translation step by step in the Julia programming language