Unary coding: Difference between revisions

Content deleted Content added
unnecessarily confusing by squeezing too much into the first sentence, so split off code length to become second sentence, and make thermometer coding be its own sentence later with a bit of explanation. To hard to give example of 5 because have two definitions, so just introduced the table a little better. Move more technical stump on prefix-free code and a self-synchronizing code to be its own paragraph at end.
try again to introduce the "Alternative".
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. Some representations use ''n'' or ''n''&nbsp;&minus;&nbsp;1 zeros followed by a one. A unary code is sometimes called a '''thermometer code''', because a unary code written vertically behaves like mercury in a [[thermometer]] that gets taller or shorter as ''n'' gets bigger or smaller.<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 formatrepresentation uses ''n'' or ''n''&nbsp;&minus;&nbsp;1 zeros followed by a one, effectively swapsswapping the ones and zeros, [[without loss of generality]]. For example, the first ten unary codes are:
{| class="wikitable"
! Unary code !! Alternative