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

J: add some comments
(J: clean up noise from mis-reading of wikipedia description)
(J: add some comments)
Line 193:
 
<lang J>aek=:3 :0
b=. x:#y NB. numeric base
i=. (~.i.])y NB. indices into unique list of characters
n=. #/.~y NB. frequencies of uniques
o=. /:~.y NB. indices to sort uniques alphabetically
o=. /:~.y
f=. i{n NB. frequencies of characters
f=. i{n
c=. i{(+/\0,}:o{n)/:o NB. cumulative frequencies of characters
L=. b #. c**/\1,}:f NB. lower bound
p=. */f NB. product of frequencies of characters
p=. */f
e=. x:<.10^.p NB. number of decimal positions to drop
e,~<.(L+p)%10^e NB. convenient result with trailing zeros count
)</lang>
 
6,962

edits