Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Unary coding
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Entropy encoding}} '''Unary coding''',<ref group="nb" name="NB1"/> or the [[unary numeral system]], is an [[entropy encoding]] that represents a [[natural number]], ''n'', with ''n'' ones followed by a zero (if the term ''natural number'' is understood as ''non-negative integer'') or with ''n'' − 1 ones followed by a zero (if the term ''natural number'' is understood as ''strictly positive integer''). A unary number's code length would thus be ''n'' + 1 with that first definition, or ''n'' with that second definition. Unary code when vertical behaves like mercury in a [[thermometer]] that gets taller or shorter as ''n'' gets bigger or smaller, and so is sometimes called '''thermometer code'''.<ref>{{Cite web |title=University of Alberta Dictionary of Cognitive Science: Thermometer Code |url=http://www.bcp.psych.ualberta.ca/~mike/Pearl_Street/Dictionary/contents/T/thermcode.html |access-date=2025-05-31 |website=www.bcp.psych.ualberta.ca}}</ref> An alternative representation uses ''n'' or ''n'' − 1 zeros followed by a one, effectively swapping the ones and zeros, [[without loss of generality]]. For example, the first ten unary codes are: {| class="wikitable" ! Unary code !! Alternative !n (non-negative) !n (strictly positive) |- | 0 || 1 |0 |1 |- | 10 || 01 |1 |2 |- | 110 || 001 |2 |3 |- | 1110 || 0001 |3 |4 |- | 11110 || 00001 |4 |5 |- | 111110 || 000001 |5 |6 |- | 1111110 || 0000001 |6 |7 |- | 11111110 || 00000001 |7 |8 |- | 111111110 || 000000001 |8 |9 |- | 1111111110 || 0000000001 |9 |10 |} Unary coding is an ''optimally efficient''{{Clarify|reason=This term needs some introduction.|date=May 2025}} encoding for the following discrete [[probability distribution]]{{Citation needed|date=May 2025|reason=Citation needed for this strong claim and to explain this term "optimally efficient".}} :<math>\operatorname{P}(n) = 2^{-n}\,</math> for <math>n=1,2,3,...</math>. In symbol-by-symbol coding, it is optimal for any [[geometric distribution]] :<math>\operatorname{P}(n) = (k-1)k^{-n}\,</math> for which ''k'' ≥ φ = 1.61803398879..., the [[golden ratio]], or, more generally, for any discrete distribution for which :<math>\operatorname{P}(n) \ge \operatorname{P}(n+1) + \operatorname{P}(n+2)\, </math> for <math>n=1,2,3,...</math>. Although it is the optimal symbol-by-symbol coding for such probability distributions, [[Golomb coding]] achieves better compression capability for the geometric distribution because it does not consider input symbols independently, but rather implicitly groups the inputs. For the same reason, [[arithmetic encoding]] performs better for general probability distributions, as in the last case above. Unary coding is both a [[prefix-free code]] and a [[self-synchronizing code]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)