Arithmetic coding/As a generalized change of radix: Difference between revisions

m
J: rearrange code slightly for minor efficiency gain and cohesive presentation
m (J: rearrange code slightly for minor efficiency gain and cohesive presentation)
Line 194:
<lang J>aek=:3 :0
b=. x:#y NB. numeric base
iu=. (~.i.])y NB. indices into NB. unique list of characters
i=. u i.y NB. character indices into uniques
n=. #/.~y NB. frequencies of uniques
o=. /:~.yu NB. indices to sort uniques alphabetically
f=. i{n NB. frequencies of characters
c=. i{(+/\0,}:o{n)/:o NB. cumulative frequencies of characters
f=. i{n NB. frequencies of characters
L=. b #. c**/\1,}:f NB. lower bound
p=. */f NB. product of frequencies of characters
6,962

edits