The   Fibonacci Word   may be created in a manner analogous to the   Fibonacci Sequence   as described here:

    Define   F_Word1   as   1
    Define   F_Word2   as   0
    Form     F_Word3   as   F_Word2     concatenated with   F_Word1    i.e.:   01
    Form     F_Wordn   as   F_Wordn-1   concatenated with   F_wordn-2



Task

Perform the above steps for     n = 37.

You may display the first few but not the larger values of   n.

{Doing so will get the task's author into trouble with them what be (again!).} 

Instead, create a table for   F_Words   1   to   37   which shows:

   The number of characters in the word
   The word's Entropy


Related tasks
 
   Fibonacci word/fractal
   Entropy
   Entropy/Narcissist


% NOTE: when compiling with Portable CLU,
% this program needs to be merged with 'useful.lib' to get log()
%
% pclu -merge $CLUHOME/lib/useful.lib -compile fib_words.clu
 
% Yield pairs of (zeroes, ones) for each Fibonacci word
% We don't generate the whole words, as that would take too much
% memory. 
fib_words = iter () yields (int,int)
    az: int := 0    ao: int := 1
    bz: int := 1    bo: int := 0
 
    while true do
        yield(az, ao)        
        az, ao, bz, bo := bz, bo, az+bz, ao+bo
    end
end fib_words
 
fib_entropy = proc (zeroes, ones: int) returns (real)
    rsize: real := real$i2r(zeroes + ones)
    zeroes_frac: real := real$i2r(zeroes)/rsize
    ones_frac: real := real$i2r(ones)/rsize
 
    return(-zeroes_frac*log(zeroes_frac)/log(2.0)
           -ones_frac*log(ones_frac)/log(2.0))
    except when undefined: return(0.0) end       
end fib_entropy
 
start_up = proc ()
    max = 37
 
    po: stream := stream$primary_output()
    stream$putl(po, " #    Length   Entropy")
 
    num: int := 0
    for zeroes, ones: int in fib_words() do
        num := num + 1
        stream$putright(po, int$unparse(num), 2)
        stream$putright(po, int$unparse(zeroes+ones), 10)
        stream$putright(po, f_form(fib_entropy(zeroes, ones), 1, 6), 10)
        stream$putl(po, "")
        if num=max then break end
    end
end start_up 