<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.formulasearchengine.com/w/index.php?action=history&amp;feed=atom&amp;title=Guided_ray</id>
	<title>Guided ray - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://en.formulasearchengine.com/w/index.php?action=history&amp;feed=atom&amp;title=Guided_ray"/>
	<link rel="alternate" type="text/html" href="https://en.formulasearchengine.com/w/index.php?title=Guided_ray&amp;action=history"/>
	<updated>2026-08-28T02:55:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.47.0-wmf.7</generator>
	<entry>
		<id>https://en.formulasearchengine.com/w/index.php?title=Guided_ray&amp;diff=1282&amp;oldid=prev</id>
		<title>en&gt;DynamoDegsy at 10:48, 24 December 2010</title>
		<link rel="alternate" type="text/html" href="https://en.formulasearchengine.com/w/index.php?title=Guided_ray&amp;diff=1282&amp;oldid=prev"/>
		<updated>2010-12-24T10:48:04Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{| align=&amp;quot;right&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| [[Image:Hamming distance 3 bit binary.svg|thumb|140px|3-bit binary [[cube]] for finding Hamming distance]]&lt;br /&gt;
| [[Image:Hamming distance 3 bit binary example.svg|thumb|140px|Two example distances: 100→011 has distance 3 (red path); 010→111 has distance 2 (blue path)]]&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2 | [[Image:Hamming distance 4 bit binary.svg|thumb|280px|4-bit binary [[tesseract]] for finding Hamming distance]]&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2 | [[Image:Hamming distance 4 bit binary example.svg|thumb|280px|Two example distances: 0100→1001 has distance 3 (red path); 0110→1110 has distance 1 (blue path)]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In [[information theory]], the &amp;#039;&amp;#039;&amp;#039;Hamming distance&amp;#039;&amp;#039;&amp;#039; between two [[String (computer science)|string]]s of equal length is the number of positions at which the corresponding symbols are different. In another way, it measures the minimum number of &amp;#039;&amp;#039;substitutions&amp;#039;&amp;#039; required to change one string into the other, or the minimum number of &amp;#039;&amp;#039;errors&amp;#039;&amp;#039; that could have transformed one string into the other.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
The Hamming distance between:&lt;br /&gt;
* &amp;quot;&amp;#039;&amp;#039;&amp;#039;&amp;lt;span style=&amp;quot;color:#0082ff&amp;quot;&amp;gt;t&amp;lt;/span&amp;gt;o&amp;lt;span style=&amp;quot;color:#0082ff&amp;quot;&amp;gt;n&amp;lt;/span&amp;gt;e&amp;lt;span style=&amp;quot;color:#0082ff&amp;quot;&amp;gt;d&amp;lt;/span&amp;gt;&amp;#039;&amp;#039;&amp;#039;&amp;quot; and &amp;quot;&amp;#039;&amp;#039;&amp;#039;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;r&amp;lt;/span&amp;gt;o&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;s&amp;lt;/span&amp;gt;e&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;s&amp;lt;/span&amp;gt;&amp;#039;&amp;#039;&amp;#039;&amp;quot; is 3.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;10&amp;lt;span style=&amp;quot;color:#0082ff&amp;quot;&amp;gt;1&amp;lt;/span&amp;gt;1&amp;lt;span style=&amp;quot;color:#0082ff&amp;quot;&amp;gt;1&amp;lt;/span&amp;gt;01&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;10&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;0&amp;lt;/span&amp;gt;1&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;0&amp;lt;/span&amp;gt;01&amp;#039;&amp;#039;&amp;#039; is 2.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;2&amp;lt;span style=&amp;quot;color:#0082ff&amp;quot;&amp;gt;17&amp;lt;/span&amp;gt;3&amp;lt;span style=&amp;quot;color:#0082ff&amp;quot;&amp;gt;8&amp;lt;/span&amp;gt;96&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;2&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;23&amp;lt;/span&amp;gt;3&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;7&amp;lt;/span&amp;gt;96&amp;#039;&amp;#039;&amp;#039; is 3.&lt;br /&gt;
&lt;br /&gt;
==Special properties==&lt;br /&gt;
For a fixed length &amp;#039;&amp;#039;n&amp;#039;&amp;#039;, the Hamming distance is a [[Metric (mathematics)|metric]] on the vector space of the words of length n, as it fulfills the conditions of non-negativity, identity of indiscernibles and symmetry, and it can be shown by [[complete induction]] that it satisfies the [[triangle inequality]] as well. The Hamming distance between two words &amp;#039;&amp;#039;a&amp;#039;&amp;#039; and &amp;#039;&amp;#039;b&amp;#039;&amp;#039; can also be seen as the [[Hamming weight]] of &amp;#039;&amp;#039;a&amp;#039;&amp;#039;&amp;amp;minus;&amp;#039;&amp;#039;b&amp;#039;&amp;#039; for an appropriate choice of the &amp;amp;minus; operator.&lt;br /&gt;
&lt;br /&gt;
For &amp;#039;&amp;#039;&amp;#039;binary strings&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;a&amp;#039;&amp;#039; and &amp;#039;&amp;#039;b&amp;#039;&amp;#039; the Hamming distance is equal to the number of ones ([[Hamming weight|population count]]) in &amp;#039;&amp;#039;a&amp;#039;&amp;#039; [[Exclusive or|XOR]] &amp;#039;&amp;#039;b&amp;#039;&amp;#039;. The metric space of length-&amp;#039;&amp;#039;n&amp;#039;&amp;#039; binary strings, with the Hamming distance, is known as the &amp;#039;&amp;#039;Hamming cube&amp;#039;&amp;#039;; it is equivalent as a metric space to the set of distances between vertices in a [[hypercube graph]]. One can also view a binary string of length &amp;#039;&amp;#039;n&amp;#039;&amp;#039; as a vector in &amp;lt;math&amp;gt;R^n&amp;lt;/math&amp;gt; by treating each symbol in the string as a real coordinate; with this embedding, the strings form the vertices of an &amp;#039;&amp;#039;n&amp;#039;&amp;#039;-dimensional [[hypercube]], and the Hamming distance of the strings is equivalent to the [[Manhattan distance]] between the vertices.&lt;br /&gt;
&lt;br /&gt;
==History and applications==&lt;br /&gt;
&lt;br /&gt;
The Hamming distance is named after [[Richard Hamming]], who introduced it in his fundamental paper on [[Hamming code]]s &amp;#039;&amp;#039;Error detecting and error correcting codes&amp;#039;&amp;#039; in 1950.&amp;lt;ref&amp;gt;{{harvtxt|Hamming|1950}}.&amp;lt;/ref&amp;gt; It is used in [[telecommunication]] to count the number of flipped bits in a fixed-length binary word as an estimate of error, and therefore is sometimes called the &amp;#039;&amp;#039;&amp;#039;signal distance&amp;#039;&amp;#039;&amp;#039;. Hamming weight analysis of bits is used in several disciplines including [[information theory]], [[coding theory]], and [[cryptography]]. However, for comparing strings of different lengths, or strings where not just substitutions but also insertions or deletions have to be expected, a more sophisticated metric like the [[Levenshtein distance]] is more appropriate.&lt;br /&gt;
For &amp;#039;&amp;#039;q&amp;#039;&amp;#039;-ary strings over an [[alphabet]] of size &amp;#039;&amp;#039;q&amp;#039;&amp;#039;&amp;amp;nbsp;≥&amp;amp;nbsp;2 the Hamming distance is applied in case of orthogonal [[modulation]], while the [[Lee distance]] is used for phase modulation. If &amp;#039;&amp;#039;q&amp;#039;&amp;#039;&amp;amp;nbsp;=&amp;amp;nbsp;2 or &amp;#039;&amp;#039;q&amp;#039;&amp;#039;&amp;amp;nbsp;=&amp;amp;nbsp;3 both distances coincide.&lt;br /&gt;
&lt;br /&gt;
The Hamming distance is also used in [[systematics]] as a measure of genetic distance.&amp;lt;ref name=&amp;quot;pmid18351799&amp;quot;&amp;gt;{{harvtxt|Pilcher|Wong|Pillai|2008}}.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On a grid such as a chessboard, the Hamming distance is the minimum number of moves it would take a rook to move from one cell to the other.&lt;br /&gt;
&lt;br /&gt;
== Algorithm example ==&lt;br /&gt;
The [[Python (programming language)|Python]] function &amp;lt;code&amp;gt;hamming_distance()&amp;lt;/code&amp;gt; computes the Hamming distance between&lt;br /&gt;
two strings (or other [[Iterator|iterable]] objects) of equal length, by creating a sequence of Boolean values indicating mismatches and matches between corresponding positions in the two inputs, and then summing the sequence with False and True values being interpreted as zero and one.&lt;br /&gt;
{{-}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hamming_distance(s1, s2):&lt;br /&gt;
    &amp;quot;Return the Hamming distance between equal-length sequences.&amp;quot;&lt;br /&gt;
    if len(s1) != len(s2):&lt;br /&gt;
        raise ValueError(&amp;quot;Undefined for sequences of unequal length&amp;quot;)&lt;br /&gt;
    return sum(ch1 != ch2 for ch1, ch2 in zip(s1, s2))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following [[C (programming language)|C]] function will compute the Hamming distance of two integers (considered as binary values, that is, as sequences of bits). The running time of this procedure is proportional to the Hamming distance rather than to the number of bits in the inputs. It computes the [[bitwise operation|bitwise]] [[exclusive or]] of the two inputs, and then finds the [[Hamming weight]] of the result (the number of nonzero bits) using an algorithm of {{harvtxt|Wegner|1960}} that repeatedly finds and clears the lowest-order nonzero bit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
unsigned hamdist(unsigned x, unsigned y)&lt;br /&gt;
{&lt;br /&gt;
  unsigned dist = 0, val = x ^ y; // XOR&lt;br /&gt;
&lt;br /&gt;
  // Count the number of set bits&lt;br /&gt;
  while(val)&lt;br /&gt;
  {&lt;br /&gt;
    ++dist; &lt;br /&gt;
    val &amp;amp;= val - 1;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  return dist;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
{{Portal|Mathematics}}&lt;br /&gt;
* [[Closest string]]&lt;br /&gt;
* [[Damerau–Levenshtein distance]]&lt;br /&gt;
* [[Euclidean distance]]&lt;br /&gt;
* [[Jaccard index]]&lt;br /&gt;
* [[String metric]]&lt;br /&gt;
* [[Sørensen similarity index]]&lt;br /&gt;
* [[Word ladder]]&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*{{FS1037C}}&lt;br /&gt;
*{{citation&lt;br /&gt;
 | last = Hamming | first = Richard W. | author-link = Richard W. Hamming&lt;br /&gt;
 | mr = 0035935&lt;br /&gt;
 | issue = 2&lt;br /&gt;
 | journal = [[Bell System Technical Journal]]&lt;br /&gt;
 | pages = 147–160&lt;br /&gt;
 | title = Error detecting and error correcting codes&lt;br /&gt;
 | url = http://wayback.archive.org/web/20060525060427/http://www.caip.rutgers.edu/~bushnell/dsdwebsite/hamming.pdf&lt;br /&gt;
 | volume = 29&lt;br /&gt;
 | year = 1950}}.&lt;br /&gt;
*{{citation&lt;br /&gt;
 | last1 = Pilcher | first1 = C. D.&lt;br /&gt;
 | last2 = Wong | first2 = J. K.&lt;br /&gt;
 | last3 = Pillai | first3 = S. K.&lt;br /&gt;
 | date = March 2008&lt;br /&gt;
 | doi = 10.1371/journal.pmed.0050069&lt;br /&gt;
 | issue = 3&lt;br /&gt;
 | journal = PLoS Med.&lt;br /&gt;
 | page = e69&lt;br /&gt;
 | pmid = 18351799&lt;br /&gt;
 | title = Inferring HIV transmission dynamics from phylogenetic sequence relationships&lt;br /&gt;
 | volume = 5&lt;br /&gt;
 | pmc = 2267810}}.&lt;br /&gt;
*{{citation&lt;br /&gt;
 | last = Wegner | first = Peter | author-link = Peter Wegner&lt;br /&gt;
 | doi = 10.1145/367236.367286&lt;br /&gt;
 | issue = 5&lt;br /&gt;
 | journal = [[Communications of the ACM]]&lt;br /&gt;
 | page = 322&lt;br /&gt;
 | title = A technique for counting ones in a binary computer&lt;br /&gt;
 | volume = 3&lt;br /&gt;
 | year = 1960}}.&lt;br /&gt;
&lt;br /&gt;
[[Category:String similarity measures]]&lt;br /&gt;
[[Category:Coding theory]]&lt;br /&gt;
[[Category:Articles with example Python code]]&lt;br /&gt;
[[Category:Articles with example C++ code]]&lt;br /&gt;
[[Category:Metric geometry]]&lt;br /&gt;
[[Category:Cubes]]&lt;/div&gt;</summary>
		<author><name>en&gt;DynamoDegsy</name></author>
	</entry>
</feed>