COBOL and Julia comparison

If you just want to reproduce the python example there, you can do:

module Muller

using FixedPointDecimals

muller(y, z) = 108 - (815 - 1500 / z) / y

function recur(T, n)
    v = zeros(T, n)
    v[1:2] .= T[4, 4.25]

    for i = 3:n
        v[i] = muller(v[i - 1], v[i - 2])
    end

   return  v
end

end # module

and then you’ll get

julia> using FixedPointDecimals

julia> Muller.recur(FixedDecimal{BigInt,25}, 20)
20-element Array{FixedDecimal{BigInt,25},1}:
 FixedDecimal{BigInt,25}(4.0000000000000000000000000)
 FixedDecimal{BigInt,25}(4.2500000000000000000000000)
 FixedDecimal{BigInt,25}(4.4705882352941176470588235)
 FixedDecimal{BigInt,25}(4.6447368421052631578947362)
 FixedDecimal{BigInt,25}(4.7705382436260623229461618)
 FixedDecimal{BigInt,25}(4.8557007125890736342039857)
 FixedDecimal{BigInt,25}(4.9108474990827932004342938)
 FixedDecimal{BigInt,25}(4.9455374041239167246519529)
 FixedDecimal{BigInt,25}(4.9669625817627005962571288)
 FixedDecimal{BigInt,25}(4.9800457013556311118526582)
 FixedDecimal{BigInt,25}(4.9879794484783912679439415)
 FixedDecimal{BigInt,25}(4.9927702880620482067468253)
 FixedDecimal{BigInt,25}(4.9956558915062356478184985)
 FixedDecimal{BigInt,25}(4.9973912683733697540253088)
 FixedDecimal{BigInt,25}(4.9984339437852482376781601)
 FixedDecimal{BigInt,25}(4.9990600687785413938424188)
 FixedDecimal{BigInt,25}(4.9994358732880376990501184)
 FixedDecimal{BigInt,25}(4.9996602467866575821700634)
 FixedDecimal{BigInt,25}(4.9997713526716167817979714)
 FixedDecimal{BigInt,25}(4.9993671517118171375788238)

which is the exact same list of values in the article, so I suspect that the Decimal type in python is probably equivalent to FixedDecimal{BigInt,25}.

As others have said that article is misleading, but if you just want to show you can recreate the sequence with a fixed-point Julia type, there you have it.

11 Likes