Talk:Rice coding

From Rosetta Code

No examples?

It's difficult to tell whether the current implementation here is correct.

Ricde coding is apparently a compression technique, but inspecting the encode implementation, I see ($n mod $d).polymod(2 xx $k - 1).reverse which probably means that the encoded number would have at least as many bits as the value of the number being encoded. --Rdm (talk) 12:03, 21 September 2023 (UTC)

The quoted raku code creates bits, where is the power to which two is raised to make the divisor. Rice coding does involve a unary coding of the quotient, as mentioned in the Wikipedia article, but this is not the relevant raku code for that, as polymod is used to encode the remainder.--Grondilu (talk) 19:40, 21 September 2023 (UTC)
The technique is useful if you are transmitting bits in a continuous stream. If you simply use binary representation the each number has to take a fixed number of bits, say 32 or 64. This coding allows you to use a variable number of bits for each number while still knowing where each number starts and stops. The number of bits used depends on the value of m chosen. As you note the original post came with no examples, so different submissions have used different values with different results. F# uses m=16, probably better if all solutions used the same m or ms.--Nigel Galloway (talk) 14:05, 21 September 2023 (UTC)
Using the Wikipedia instructions (as I read them at least ) with an M that is a exact exponent of 2 results in padding the remainder with one extra zero. I have changed this in the Julia example, which decreases the bit length of results by one. Numbers well over the M used are still going to use more bits than the ordinary bit representation, since each multiple of M contained in the number adds another bit to the front of the bits used.--Wherrera (talk) 17:54, 21 September 2023 (UTC)
As I wrote that ..q+k remark it dawned on me that a much more thorough test might be to bolt the encode results together and show that can be properly decoded. --Petelomax (talk) 02:28, 22 September 2023 (UTC)