Unary coding: Difference between revisions

Content deleted Content added
Canonical unary codes: lots of clarification needed in this section.
shorten wording on thermometer code.
 
Line 1:
{{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''&nbsp;&minus;&nbsp;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''&nbsp;+&nbsp;1 with that first definition, or ''n'' with that second definition. A unary code is sometimes called a '''thermometer code''', because a unaryUnary code writtenwhen verticallyvertical 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''&nbsp;&minus;&nbsp;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