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

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