Eulerian number or Euler triangle

Hi all,
as I could not find an implementation for the Eulerian number / Eulerian triangle I developed it briefly.

There exists an recursive algorithm and an explicit formula. More infos could be found on Wikipedia:

My recursive algorithm

function euler_rec(n::Int64, k::Int64)
    if n==0 
        if k==0
            return 1
            return 0

    return (n-k) * big(euler_rec(n-1,k-1)) + (k+1)*big(euler_rec(n-1,k))

and my explicit (direct) formula is

function euler_dir(n::Int64, k::Int64)
    igrid = 0 : 1 : k
    a_int(i) = (-1)^(i) * big(binomial(n+1,i))*(big(k+1-i))^n
    return mapreduce( i -> a_int(i), +, igrid)

I need to use BigInt with big(...) as return values because the return values increase dramatically.

Please feel free to improve or extend my code :slight_smile:

1 Like