Arithmetic coding/As a generalized change of radix: Difference between revisions
Arithmetic coding/As a generalized change of radix (view source)
Revision as of 07:24, 1 February 2016
, 8 years agoJ: 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
f=. i{n NB. frequencies of characters
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
e=. x:<.10^.p NB. number of decimal positions to drop
e,~<.(L+p)%10^e NB. convenient result with trailing zeros count
)</lang>
|