Arithmetic coding/As a generalized change of radix: Difference between revisions
Content added Content deleted
m (→{{header|J}}) |
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 |
||
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=. /: |
o=. /:u NB. indices to sort uniques alphabetically |
||
⚫ | |||
c=. i{(+/\0,}:o{n)/:o NB. cumulative frequencies of characters |
c=. i{(+/\0,}:o{n)/:o NB. cumulative 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 |