<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Fabulous Adventures In Coding : Benford's Law</title><link>http://blogs.msdn.com/ericlippert/archive/tags/Benford_2700_s+Law/default.aspx</link><description>Tags: Benford's Law</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Floating Point And Benford's Law, Part Two</title><link>http://blogs.msdn.com/ericlippert/archive/2005/01/13/floating-point-and-benford-s-law-part-two.aspx</link><pubDate>Thu, 13 Jan 2005 17:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:352284</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/352284.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=352284</wfw:commentRss><description>&lt;font face="lucida sans unicode"&gt;&lt;font color="#800080" size="2"&gt; &lt;p&gt;A number of readers asked for an explanation of my offhand comment that Benford's Law can be used to show that binary is the best base for doing floating point math. &lt;/p&gt; &lt;p&gt;One of the desired properties of a floating point system is that the "representation error" is as small as possible. For example, suppose we want to express "one third", in ten-place fixed point decimal notation. The closest we can get is "0.3333333333", which has a representation error of 0.0000000000333333… &lt;/p&gt; &lt;p&gt;A useful way to get a handle on representation error is to look at the &lt;b&gt;granularity&lt;/b&gt; of the system. By granularity I mean the smallest difference we can make between two values. For ten-place fixed point decimal notation, the smallest nonzero difference between any two numbers is 10&lt;sup&gt;-10&lt;/sup&gt;. In a floating point system, the granularity changes as the exponent changes. Really large numbers have large granularity; the difference between two successive floats might be millions or billions. And really small numbers have tiny granularity. &lt;b&gt;The maximum possible representation error is half the granularity&lt;/b&gt;. Since there is a clear relationship between granularity and representation error, I’m just going to talk about granularity from now on. Small granularity = small representation error = goodness.&lt;/p&gt; &lt;p&gt;Let's consider two similar systems, one which uses a binary mantissa and one which uses a hexadecimal mantissa. I’m going to continue my convention of showing binary numbers in blue, and we’ll do hex in green.&lt;/p&gt; &lt;p&gt;Suppose we've got on the one hand, 32 bit IEEE floats, aka "singles". That is, we've got one sign bit, nine bits of exponent biased by -255 (so exponents can be from -255 to 256), a 22 bit mantissa, and an implicit leading "1." So a number like &lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;(0, 100000011, 1100000000000000000000)&lt;/font&gt;&lt;font color="#800080" size="2"&gt; would be +&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;1.1100&lt;/font&gt;&lt;font color="#800080" size="2"&gt; x 2&lt;sup&gt;4&lt;/sup&gt; = 28&lt;/p&gt; &lt;p&gt;I’m getting sick of spelling out the exponents in non-biased binary. From now on, I’m just going to give them in decimal. And I’m going to give the sign bit by plus and minus, not zero and one.&lt;/p&gt; &lt;p&gt;We now want a hex system with roughly similar range that doesn't take up more storage. Suppose we've got one sign bit, seven bits of exponent biased by -63, and six hex digits for the mantissa. We don't get a leading "1." because not every hex number can be so expressed, so we'll have to use a leading 0. That system has roughly the same range, and if we were to "behind the scenes" express this thing as bits, we'd still be using 32 bits. One for the sign, seven for the exponent, and 24 for the mantissa.&lt;/p&gt; &lt;p&gt;In this system, &lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;(+, &lt;font color="#800080"&gt;2&lt;/font&gt;, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;A00000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;)&lt;/font&gt;&lt;font color="#800080" size="2"&gt; would be +&lt;/font&gt;&lt;font color="#008000" size="2"&gt;0.A00000&lt;/font&gt;&lt;font color="#800080" size="2"&gt; x 16&lt;sup&gt;2&lt;/sup&gt; = 160&lt;/p&gt; &lt;p&gt;An immediate disadvantage of this system is that numbers have multiple representations. &lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;(+, &lt;font color="#800080"&gt;2&lt;/font&gt;, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;A00000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) &lt;/font&gt;&lt;font color="#800080" size="2"&gt;and &lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;(+, &lt;font color="#800080"&gt;3&lt;/font&gt;, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;0A0000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) &lt;/font&gt;&lt;font color="#800080" size="2"&gt;are the same number. Let’s ignore that for now. We’ll ignore all hex mantissas with leading zeros. (And besides, the binary IEEE system wastes lots of cases for denormals and NaNs too, so it's not clear that this is any worse.)&lt;/p&gt; &lt;p&gt;What's the granularity of the hex system when, say, the exponent is 2? Well, consider a number like &lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;(+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;A00000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;)&lt;/font&gt;&lt;font color="#800080" size="2"&gt; – the smallest possible number higher than this is &lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;(+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;A00001&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) &lt;/font&gt;&lt;font color="#800080" size="2"&gt;which is 2&lt;sup&gt;-16&lt;/sup&gt; larger. Clearly, 2&lt;sup&gt;-16&lt;/sup&gt; is the granularity for all values with an exponent of 2. More generally, if the exponent is N then the granularity is 2&lt;sup&gt;4N-24&lt;/sup&gt;.&lt;/p&gt; &lt;p&gt;How would we represent &lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;(+, &lt;font color="#800080"&gt;2&lt;/font&gt;, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;A00000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;)&lt;/font&gt;&lt;font color="#800080" size="2"&gt; in our binary system? That would be &lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;(+, &lt;font color="#800080"&gt;7&lt;/font&gt;, 0100000000000000000000) &lt;/font&gt;&lt;font color="#800080" size="2"&gt;= +&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;1.01&lt;/font&gt;&lt;font color="#800080" size="2"&gt; x 2&lt;sup&gt;7&lt;/sup&gt; = 160. The next largest number that can be represented in our system is &lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;(+, &lt;font color="#800080"&gt;7&lt;/font&gt;, 0100000000000000000001)&lt;/font&gt;&lt;font color="#800080" size="2"&gt; which is 2&lt;sup&gt;-15&lt;/sup&gt; larger. So the hex system has smaller granularity and hence smaller representation error, and is therefore the better system, right?&lt;/p&gt; &lt;p&gt;Not so fast. Let’s make a chart.&lt;/p&gt;&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt; &lt;p&gt;Decimal&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Hex&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Binary&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Binary Granularity Exponent&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;16&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, &lt;font color="#000080"&gt;2&lt;/font&gt;,&amp;nbsp;&lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;100000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 4, 0000000000000000000000) -18&lt;br /&gt;&amp;nbsp;&amp;nbsp;32&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;200000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 5, 0000000000000000000000) -17&lt;br /&gt;&amp;nbsp;&amp;nbsp;48&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;300000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 5, 1000000000000000000000) -17&lt;br /&gt;&amp;nbsp;&amp;nbsp;64&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;400000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 6, 0000000000000000000000) -16&lt;br /&gt;&amp;nbsp;&amp;nbsp;80&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;500000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 6, 0100000000000000000000) -16&lt;br /&gt;&amp;nbsp;&amp;nbsp;96&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;600000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 6, 1000000000000000000000) -16&lt;br /&gt;&amp;nbsp;112&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;700000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 6, 1100000000000000000000) -16&lt;br /&gt;&amp;nbsp;128&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;800000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 7, 0000000000000000000000) -15&lt;br /&gt;&amp;nbsp;144&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;900000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 7, 0010000000000000000000) -15&lt;br /&gt;&amp;nbsp;160&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;A00000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 7, 0100000000000000000000) -15&lt;br /&gt;&amp;nbsp;176&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;B00000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 7, 0110000000000000000000) -15&lt;br /&gt;&amp;nbsp;192&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;C00000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 7, 1000000000000000000000) -15&lt;br /&gt;&amp;nbsp;208&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;D00000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 7, 1010000000000000000000) -15&lt;br /&gt;&amp;nbsp;224&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;E00000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 7, 1100000000000000000000) -15&lt;br /&gt;&amp;nbsp;240&amp;nbsp;&amp;nbsp;&amp;nbsp; (+, 2, &lt;/font&gt;&lt;font face="Lucida Console" color="#008000" size="2"&gt;F00000&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt;) (+, 7, 1110000000000000000000) -15&lt;/p&gt;&lt;/font&gt;&lt;font color="#800080" size="2"&gt; &lt;p&gt;The hex system always has a granularity exponent of -16.&amp;nbsp; In 8/15ths of the cases, the binary system has worse granularity than the hex system. In 4/15ths of the cases, they have the same granularity, and in only 3/15ths of the cases, the binary system has better granularity. Therefore the hex system is clearly the same or better most of the time.&amp;nbsp; We should use this system instead of binary floats.&lt;/p&gt; &lt;p&gt;Not so fast! We’ve forgotten Benford’s Law! That's true if any number is as likely as any other, but that's not realistic. &lt;/p&gt; &lt;p&gt;Suppose the numbers that we are manipulating obey Benford’s Law. In that case, we would expect that fully a quarter of them would begin with &lt;font color="#006400"&gt;1&lt;/font&gt; when encoded in hex. We’d expect another quarter of them to begin with &lt;font color="#006400"&gt;2&lt;/font&gt; or &lt;font color="#006400"&gt;3&lt;/font&gt;, another quarter to begin with &lt;font color="#006400"&gt;4&lt;/font&gt;, &lt;font color="#006400"&gt;5&lt;/font&gt;, &lt;font color="#006400"&gt;6&lt;/font&gt; or &lt;font color="#006400"&gt;7&lt;/font&gt;, and the remaining quarter to begin with &lt;font color="#006400"&gt;8&lt;/font&gt;, &lt;font color="#006400"&gt;9&lt;/font&gt;, &lt;font color="#006400"&gt;A&lt;/font&gt;, &lt;font color="#006400"&gt;B&lt;/font&gt;, &lt;font color="#006400"&gt;C&lt;/font&gt;, &lt;font color="#006400"&gt;D&lt;/font&gt;, &lt;font color="#006400"&gt;E&lt;/font&gt; and &lt;font color="#006400"&gt;F&lt;/font&gt;. If we make that assumption then we must conclude that the binary system is better half the time, equal a quarter of the time, and worse a quarter of the time.&lt;/p&gt; &lt;p&gt;Clearly this isn't the case just for the exponent 2. For any hex exponent N, the hex system will have a granularity exponent of 4N-24. For numbers in the range expressible by the hex system with that exponent, a quarter of the time, the binary system will have a granularity exponent of 4N-26, a quarter of the time it'll be 4N-25, a quarter of the time it'll be 4N-24, and the remaining quarter it'll be 4N-23, so three-quarters of the time it'll be as good or better. &lt;b&gt;On average, the binary system is considerably better if data are distributed according to Benford's Law. &lt;/b&gt;&lt;/p&gt; &lt;p&gt;This is just one example, not&amp;nbsp;a proof.&amp;nbsp;But we could generalize this example and show that for any system with a given number of bits, binary mantissas yield smaller representation errors on average than mantissas in any other base.&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=352284" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Rarefied+Heights/default.aspx">Rarefied Heights</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Floating+Point+Arithmetic/default.aspx">Floating Point Arithmetic</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Benford_2700_s+Law/default.aspx">Benford's Law</category></item><item><title>Benford's Law</title><link>http://blogs.msdn.com/ericlippert/archive/2005/01/12/benford-s-law.aspx</link><pubDate>Wed, 12 Jan 2005 20:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:351693</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>25</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/351693.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=351693</wfw:commentRss><description>&lt;font face="Lucida sans unicode"&gt;&lt;font color="#800080" size="2"&gt; &lt;p&gt;While I was poking through my old numeric analysis textbooks to refresh my memory for this series on floating point arithmetic, I came across one of my favourite weird facts about math. &lt;/p&gt; &lt;p&gt;A nonzero base-ten integer starts with some digit other than zero. You might naively expect that given a bunch of "random" numbers, you'd see every digit from 1 to 9 about equally often. You'd see as many 2's as 9's. You'd see each digit as the leading digit about 11% of the time.&amp;nbsp; For example, consider a random integer between 100000 and 999999. One ninth begin with 1, one ninth begin with 2, etc.&lt;/p&gt; &lt;p&gt;But in real-life datasets, that's not the case at all. If you just start grabbing thousands or millions of "random" numbers from newspapers and magazines and books, you soon see that about 30% of the numbers begin with 1, and it falls off rapidly from there. About 18% begin with 2, all the way down to less than 5% for 9.&lt;/p&gt; &lt;p&gt;This oddity was discovered by Newcomb in 1881, and then rediscovered by Frank Benford, a physicist, in 1937. As often is the case, the fact became associated with the second discoverer and is now known as Benford's Law.&lt;/p&gt; &lt;p&gt;Benford's Law has lots of practical applications. For instance, people who just make up numbers wholesale on their tax returns tend to pick "average seeming" numbers, and to humans, "average seeming" means "starts with a five". People think, I want something between $1000 and $10000, let's say, $5624. The IRS routinely scans tax returns to find unusually high percentages of leading 5's and examines those more carefully.&lt;/p&gt; &lt;p&gt;Benford's result was carefully studied by many statisticians and other mathematicians, and we now have a multi-base form of the law. Given a bunch of numbers in base B, we'd expect to see leading digit n approximately &lt;font color="#000080"&gt;ln (1 + 1/n) / ln B&lt;/font&gt; of the time. &lt;/p&gt; &lt;p&gt;But what could possibly explain Benford's Law? &lt;/p&gt; &lt;p&gt;Multiplication. Most numbers we see every day are not random quantities in of themselves. They're usually computed qualities with some aspect of multiplication to them. &lt;/p&gt; &lt;p&gt;Consider, for example, any property which grows on a percentage basis. Like, say, the Dow Jones Industrial Average. It typically grows a few percent a year. Suppose, just to pick a rate, that on average the DJIA grows at 7% a year. At that rate, it doubles about every ten years. Suppose that&amp;nbsp;the DJIA is 10000. After ten years of having 1 as the leading digit, it finally gets to 20000. Ten years go by again, but in that ten years, it doubles to 40000, not 30000. Therefore, those ten years were spent about half starting with 2, and about half starting with 3.&amp;nbsp;Ten more years go by, and it doubles again to 80000. Now ten years have 4, 5, 6 and 7 as the leading digits in only ten years. Eventually we get up to 100000, and spend another ten years starting with 1.&amp;nbsp; Pick a random date and you'd expect that the DJIA on that day would be twice as likely to start with 1 as 2, and four times as likely to start with 1 as 5.&lt;/p&gt; &lt;p&gt;We can easily write a program that demonstrates Benford's Law. As we multiply more and more numbers together, they tend to clump based on Benford's Law:&lt;/p&gt;&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt; &lt;p&gt;var counters = [&lt;br /&gt;[0,0,0,0,0,0,0,0,0,0],&lt;br /&gt;[0,0,0,0,0,0,0,0,0,0],&lt;br /&gt;[0,0,0,0,0,0,0,0,0,0],&lt;br /&gt;[0,0,0,0,0,0,0,0,0,0] ];&lt;/p&gt; &lt;p&gt;for (var multiplications = 0 ; multiplications &amp;lt;= 3; ++multiplications)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; for (var trial = 0 ; trial &amp;lt; 10000 ; ++trial)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var num = 1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for (var mult = 0 ; mult &amp;lt;= multiplications; ++mult)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; num = num * (Math.floor(Math.random() * 1000) + 1);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var lead = num.toString().substr(0,1);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; counters[multiplications][lead] ++;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;print(counters.join("\n"));&lt;/p&gt;&lt;/font&gt;&lt;font color="#800080" size="2"&gt; &lt;p&gt;A typical run produces data from which we can draw this table:&lt;/p&gt;&lt;/font&gt;&lt;font face="Lucida Console" color="#000080" size="2"&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Leading Digit&lt;br /&gt;Mults&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp; &amp;nbsp;5&amp;nbsp;&amp;nbsp; &amp;nbsp;6&amp;nbsp;&amp;nbsp; &amp;nbsp;7&amp;nbsp;&amp;nbsp; &amp;nbsp;8&amp;nbsp;&amp;nbsp; &amp;nbsp;9&lt;br /&gt;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1102 1069 1085 1125 1167 1107 1083 1124 1138&lt;br /&gt;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2416 1752 1443 1162 1019&amp;nbsp; 756&amp;nbsp; 643&amp;nbsp; 453&amp;nbsp; 356&lt;br /&gt;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3046 1854 1265&amp;nbsp; 979&amp;nbsp; 778&amp;nbsp; 632&amp;nbsp; 551&amp;nbsp; 468&amp;nbsp; 427 &lt;br /&gt;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3090 1814 1197&amp;nbsp; 924&amp;nbsp; 779&amp;nbsp; 661&amp;nbsp; 582&amp;nbsp; 491&amp;nbsp; 462&lt;br /&gt;predicted 3010 1761 1249&amp;nbsp; 969&amp;nbsp; 792&amp;nbsp; 669&amp;nbsp; 580&amp;nbsp; 511&amp;nbsp; 458&lt;/p&gt;&lt;/font&gt;&lt;font color="#800080" size="2"&gt; &lt;p&gt;As you can see, with no multiplications, the distribution is a flat 11% for each. But by the time we get up to two or three multiplications, we're almost exactly at the distribution predicted by Benford's Law.&lt;/p&gt; &lt;p&gt;What does this have to do with floating point math? Well, we could conceivably design chips that did decimal or hexadecimal floating-point arithmetic. Would such chips yield more accurate results? Well, recall that last time, we used the fact that you can stuff a leading 1 onto a bit field to define a number. Binary is the only system in which every number except 0 begins with a leading 1! You can make a statistical argument which shows that for bases other than binary, in which you cannot always assume a leading digit, have on average a larger representation error. The argument is somewhat subtle, so I'm not going to actually go through the details of it, but suffice to say that we can show that for typical uses, binary is the least error-producing system we can come up with given that we'll almost always be working with data which follow Benford's Law.&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=351693" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Rarefied+Heights/default.aspx">Rarefied Heights</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Floating+Point+Arithmetic/default.aspx">Floating Point Arithmetic</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Benford_2700_s+Law/default.aspx">Benford's Law</category></item></channel></rss>