<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ashutosh Mehra's Blog &#187; TAOCP</title>
	<atom:link href="http://ashutoshmehra.net/blog/category/taocp/feed/" rel="self" type="application/rss+xml" />
	<link>http://ashutoshmehra.net/blog</link>
	<description>Notes on Math, Computer Science &#38; Programming</description>
	<lastBuildDate>Sat, 27 Feb 2010 14:22:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>On Asymptotic Methods in Analysis: Prof. de Bruijn&#8217;s beautiful little book</title>
		<link>http://ashutoshmehra.net/blog/2009/05/asymptotic-methods-in-analysis/</link>
		<comments>http://ashutoshmehra.net/blog/2009/05/asymptotic-methods-in-analysis/#comments</comments>
		<pubDate>Fri, 08 May 2009 23:44:33 +0000</pubDate>
		<dc:creator>Ashutosh</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[TAOCP]]></category>

		<guid isPermaLink="false">http://ashutoshmehra.net/blog/?p=441</guid>
		<description><![CDATA[

For the past several days, I&#8217;ve been working my way through Prof. N.G. de Bruijn&#8217;s book Asymptotic Methods in Analysis; and I want to share some of the fun I&#8217;ve had reading it.
This post is not a review or anything (here&#8217;s an image of the back cover with some reviews). Below are just fragments of [...]]]></description>
			<content:encoded><![CDATA[<div class="alignright" style="margin-left: 5px"><a href="http://www.amazon.com/gp/product/0486642216?ie=UTF8&#038;tag=ashmehblo-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0486642216"><img border="0" src="http://ashutoshmehra.net/images/books/amia/de_Bruijn_asymptotic_methods_in_analysis_back_small.png" width="75px"></a><img src="http://www.assoc-amazon.com/e/ir?t=ashmehblo-20&#038;l=as2&#038;o=1&#038;a=0486642216" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></div>
<div class="alignright" style="margin-left: 5px"><a href="http://www.amazon.com/gp/product/0486642216?ie=UTF8&#038;tag=ashmehblo-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0486642216"><img border="0" src="http://ashutoshmehra.net/images/books/amia/de_Bruijn_asymptotic_methods_in_analysis_front_small.jpg" width="75px"></a><img src="http://www.assoc-amazon.com/e/ir?t=ashmehblo-20&#038;l=as2&#038;o=1&#038;a=0486642216" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></div>
<p>For the past several days, I&#8217;ve been working my way through <a href="http://www.win.tue.nl/~wsdwnb/">Prof. N.G. de Bruijn&#8217;s</a> book <a href="http://www.amazon.com/gp/product/0486642216?ie=UTF8&#038;tag=ashmehblo-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0486642216">Asymptotic Methods in Analysis</a>; and I want to share some of the fun I&#8217;ve had reading it.</p>
<p>This post is not a review or anything (here&#8217;s an <a href="http://ashutoshmehra.net/images/books/amia/de_Bruijn_asymptotic_methods_in_analysis_back_big.png">image of the back cover</a> with some reviews). Below are just fragments of what I&#8217;ve read so far and found fascinating. <span id="more-441"></span> You could also consider this my attempt at trying to persuade you to get a copy of this beautiful little book! Sadly, new copies appear <i>not</i> to be available at most online bookstores, so it might be hard to get one.</p>
<h4>Prof. de Bruijn, his cycles, and average height of trees</h4>
<div class="alignleft" style="margin-right: 5px"><img src="http://ashutoshmehra.net/images/books/amia/de_bruijn_cycle_color.png" width="150px" alt="A de Bruijn cycle"></div>
<p>This book is by the same Prof. de Bruijn well-known, among other things, for his <a href="http://en.wikipedia.org/wiki/De_Bruijn_sequence">cycles</a>, which are defined as following: An <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_39b54fb569800b4de76f3a22735c0ec5.png" title="m" style="vertical-align:-20%;" class="tex" alt="m" />-ary <i>de Bruijn cycle</i> is a sequence of <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_90223c6cfe2c22939b91052bf5096d05.png" title="m^n" style="vertical-align:-20%;" class="tex" alt="m^n" /> radix-<img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_39b54fb569800b4de76f3a22735c0ec5.png" title="m" style="vertical-align:-20%;" class="tex" alt="m" /> digits such that every combinations of <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_23e517569a067209bf264db2132df9e1.png" title="n" style="vertical-align:-20%;" class="tex" alt="n" /> digits occurs consecutively in the cycle. For example, one possible binary de Bruijn cycle of length <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_2eb0518083e46aef997ecb32a917459c.png" title="2^4" style="vertical-align:-20%;" class="tex" alt="2^4" /> is:<br />
<center><tt>0 0 0 1 1 1 1 0 1 0 1 1 0 0 1 0</tt>.</center></p>
<p>Treating this sequence as a cycle, notice that each of the 16 possible 4-bit patterns (<tt>0000</tt> &#8230; <tt>1111</tt>) appear exactly once in it. Knuth describes at least <i>three</i> interesting algorithms for generating such cycles in TAOCP Section 7.2.1.1 (printed in <a href="http://www.amazon.com/gp/product/0201853930?ie=UTF8&#038;tag=ashmehblo-20&#038;link_code=as3&#038;camp=211189&#038;creative=373489&#038;creativeASIN=0201853930">Volume 4, Fascicle 2</a> and downloadable as <a href="http://www-cs-faculty.stanford.edu/~knuth/fasc2a.ps.gz">pre-fascicle 2a</a>).</p>
<div class="alignright" style="margin-left: 5px"><a href="http://owpdb.mfo.de/person_detail?id=539"><img src="http://ashutoshmehra.net/images/books/amia/de_Bruijn_(196x)_1_Oberwolfach_Collection.jpg" width="100px" alt="Prof. de Bruijn; From the Oberwolfach Collection"></a></div>
<p>There&#8217;s surely lots to say about Prof. de Bruijn&#8217;s work (including his cycles), but I&#8217;ll reserve them for future posts. Take a look, for example, at the index of TAOCP Vol I (perhaps also in other volumes) and you&#8217;ll see references to many of his results, sometimes framed as exercises. And if you enjoy asymptotic calculations and analyses of algorithms, you would find it interesting to read his co-authored paper (with Knuth and Rice) where it is shown that <i>the average height of planted plane trees</i> is:<br />
<center><img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_c99c19546a80f8e17954618ea271dcac.png" title="\sqrt{\pi n} - {1\over2} + O(n^{-1/2})" style="vertical-align:-20%;" class="tex" alt="\sqrt{\pi n} - {1\over2} + O(n^{-1/2})" />.</center><br />
This is also TAOCP Ex. 2.3.1&#8211;11, where the question is posed in terms of the average value of the maximum stack size consumed while running the usual in-order binary tree traversal, assuming all binary trees with n nodes are equally probable.</p>
<p>As an interesting note, Knuth in his <a href="http://scpd.stanford.edu/knuth/index.jsp">musings</a> on <i>The Joy of Asymptotics</i> (30 May 2000) said:</p>
<blockquote>
<div class="alignleft" style="margin-right: 5px"><a href="http://www.amazon.com/gp/product/1575862123?ie=UTF8&#038;tag=ashmehblo-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1575862123"><img border="0" src="http://ashutoshmehra.net/images/books/amia/knuth_papers_on_analysis_of_algorithms_front_small.jpg" width="75px"></a><img src="http://www.assoc-amazon.com/e/ir?t=ashmehblo-20&#038;l=as2&#038;o=1&#038;a=1575862123" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></div>
<p>I&#8217;ve dedicated this book [<a href="http://www-cs-faculty.stanford.edu/~knuth/aa.html">Selected Papers on Analysis of Algorithms</a>] to Prof. de Bruijn &#8230; in the Netherlands because he has been my <i>guru</i> &#8230; Ever since I got my PhD, I considered him my post-graduate doctoral advisor. Every time I had a problem that I got stuck on, I would write to him, and he would write me back a letter that would help me get unstuck. And that&#8217;s been going on for over fourty years now. So I dedicated this book to him. And what I want to talk to you about today is one of the things <i>he</i> has spent most of <i>his</i> life on &#8212; asymptotic methods.</p></blockquote>
<p>By the way, that paper deriving the cool formula for the height of trees is included in these <i>Selected Papers</i> (Ch. 15).</p>
<h4>The Book: A Pragmatic Exposition</h4>
<p>I had got myself a copy of this book several years ago after first reading about it in the section on asymptotic calculations in TAOCP (Sec 1.2.11.3). But unfortunately, the book suffered the same fate as countless others &#8212; it just kept resting on my bookshelf. But a few days ago, I decided to give it a try.</p>
<p><i>A brief history</i>. As described in its preface, this book grew out of lectures given in 1954&#8211;55 and was first published in 1958. The Dover edition I have is a reprint of the third edition from 1970.</p>
<p>Most computer programmers are familiar with the <a href="http://en.wikipedia.org/wiki/Big_O_notation">Big-O notation</a>, or the Bachmann-Landau notation, for analyzing space/time-complexity of an algorithm. Among other things, this book talks of the tricks involved in getting precise asymptotic bounds once we have reduced the problem at hand to, say, a sum or an integral.</p>
<p>This is a <i>pragmatic</i> book &#8212; its focus is on demonstrating general techniques by working out several examples in detail (sometimes in more than one way) rather than expounding highly generalized theories of analysis. In this context, I found these lines from the preface reassuring:</p>
<blockquote><p>Usually in mathematics one has to choose between saying more and more about less and less on the one hand, and saying less and less about more and more on the other. In a practical subject like this, however, the proper attitude should be to say as much as possible in a given situation.</p></blockquote>
<p>From my reading, at certain places it, of necessity, assumes a basic knowledge of analysis and complex variable theory. Other than that, it is a fairly elementary treatment. (Note: as Feynman made a quip in <a href="http://www.amazon.com/gp/product/0393039188?ie=UTF8&#038;tag=ashmehblo-20&#038;link_code=as3&#038;camp=211189&#038;creative=373489&#038;creativeASIN=0393039188">one of his lectures</a>, <i>&#8220;Elementary&#8221; means that very little is required to know ahead of time in order to understand it, except to have an infinite amount of intelligence.&#8221;</i>)</p>
<p>It&#8217;s a small book (200 pages) with very few exercises and so can be read in about two weeks, if you read an hour a day. And since there are lots of cliff-hanging moments (well, to the extent a book on analysis can have!) and the reader is left wondering how a tricky sum/integral would be tamed, your might be compelled to finish it even sooner!</p>
<p>de Bruijn has a good sense of humor too. At the start of the first chapter, when trying to answer the question <i>&#8220;What is Asymptotics?&#8221;</i>, he says:</p>
<blockquote><p>The safest and not the vaguest definition is the following one: Asymptotics is that part of analysis which considers problems of the type dealt with in this book.</p></blockquote>
<p>Didn&#8217;t see that one coming! </p>
<p>And while the book is tiny, it covers lots of tricks &amp; techniques. So, to give my interested readers a taste, I&#8217;ve picked a couple of my favorite from the first chapter. All examples are de Bruijn&#8217;s. </p>
<h4>Uniform Estimates</h4>
<p><i>Uniformity of estimates</i> is this little thing that keeps popping up every so often when analyzing the asymptotics of some characteristic of an algorithm. But it is rarely explained what it means or why uniformity is crucial to the application at hand. Grown up boys and girls are supposed to know what uniformity is, I suppose.</p>
<p>Before looking at uniformity, let&#8217;s recap the definition of the <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_2f55e2f764c899f5c8dabb45cd9338d8.png" title="O" style="vertical-align:-20%;" class="tex" alt="O" />-notation. We say:<br />
<center><img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_62bc6f0b98d5560f041b8bc6c43f9135.png" title="f(x)=O(\phi(x))\qquad(x\rightarrow\infty)" style="vertical-align:-20%;" class="tex" alt="f(x)=O(\phi(x))\qquad(x\rightarrow\infty)" /></center><br />
to mean the existence of numbers <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_51271a2c86027496c0237a713770db43.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" /> and <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_abdfb1ee5ca8eaf34770b230fed37ffd.png" title="A" style="vertical-align:-20%;" class="tex" alt="A" /> such that:<br />
<center><img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_c85fe500fc2a4584b5cbc6b4167a79d2.png" title="|f(x)|\leq A|\phi(x)|\qquad\text{whenever}\quad x\,\textgreater\,a" style="vertical-align:-20%;" class="tex" alt="|f(x)|\leq A|\phi(x)|\qquad\text{whenever}\quad x\,\textgreater\,a" />.</center><br />
The thing to note in this definition is that <i>the <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_2f55e2f764c899f5c8dabb45cd9338d8.png" title="O" style="vertical-align:-20%;" class="tex" alt="O" />-notation implies two implicit constants</i>, <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_abdfb1ee5ca8eaf34770b230fed37ffd.png" title="A" style="vertical-align:-20%;" class="tex" alt="A" /> and <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_51271a2c86027496c0237a713770db43.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" />.</p>
<p>Returning to the question of uniformity, suppose <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_1536fd5a256e8ae0bf1cd5a9c828392e.png" title="k" style="vertical-align:-20%;" class="tex" alt="k" /> is a positive integer and <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_57a3db9b14bded9c06fc0922f156537d.png" title="f(x)" style="vertical-align:-20%;" class="tex" alt="f(x)" /> and <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_ce53f5d0df72577c4cd72dad85303234.png" title="g(x)" style="vertical-align:-20%;" class="tex" alt="g(x)" /> are arbitrary functions. Then:<br />
<center><img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_5a545d3ddd3d049250ff49fe425f31c4.png" title="( f(x) + g(x) )^k = O( ( f(x) )^k + ( g(x) )^k)" style="vertical-align:-20%;" class="tex" alt="( f(x) + g(x) )^k = O( ( f(x) )^k + ( g(x) )^k)" />, because,</center><br />
<center><img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_e575fac57bcde5edb2e9993ba6e89396.png" title="|(f+g)^k|\leq (|f|+|g|)^k\leq (2\max(|f|, |g|))^k\leq 2^k(|f|^k + |g|^k)" style="vertical-align:-20%;" class="tex" alt="|(f+g)^k|\leq (|f|+|g|)^k\leq (2\max(|f|, |g|))^k\leq 2^k(|f|^k + |g|^k)" /></center><br />
Rewriting the last line as: <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_017c3150b4a36dc7f99f888efbd23ac1.png" title="(f(x) + g(x))^k\leq A|f(x)|^k + B|g(x)|^k" style="vertical-align:-20%;" class="tex" alt="(f(x) + g(x))^k\leq A|f(x)|^k + B|g(x)|^k" />, we see that <i>the implicit &#8220;constants&#8221; <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_abdfb1ee5ca8eaf34770b230fed37ffd.png" title="A" style="vertical-align:-20%;" class="tex" alt="A" /> and <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_ed6558df25ce694119274d78624a4df9.png" title="B" style="vertical-align:-20%;" class="tex" alt="B" /> depend on the parameter <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_1536fd5a256e8ae0bf1cd5a9c828392e.png" title="k" style="vertical-align:-20%;" class="tex" alt="k" /></i>. We call such an estimate <i>non-uniform</i>.</p>
<p></p>
<p>On the other hand, in the asymptotic relation (with <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_1536fd5a256e8ae0bf1cd5a9c828392e.png" title="k" style="vertical-align:-20%;" class="tex" alt="k" /> again being a positive integer):<br />
<center><img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_93f8c949fcda792fe4e9cbb767d13b41.png" title="({k\over{x^2+k^2}})^k=O({1\over{x^k}})\qquad (x \,\textgreater\, 1)" style="vertical-align:-20%;" class="tex" alt="({k\over{x^2+k^2}})^k=O({1\over{x^k}})\qquad (x \,\textgreater\, 1)" /></center><br />
the implicit constant in the <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_2f55e2f764c899f5c8dabb45cd9338d8.png" title="O" style="vertical-align:-20%;" class="tex" alt="O" />-notation is independent of k, since we have<br />
<center><img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_18a183079c6b8cf7e8f05501e347d5cf.png" title="({k\over{x^2+k^2}})^k\leq ({k\over{2kx}})^k\leq {1\over{x^k}}" style="vertical-align:-20%;" class="tex" alt="({k\over{x^2+k^2}})^k\leq ({k\over{2kx}})^k\leq {1\over{x^k}}" />.</center></p>
<p>Hence if we write <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_150fb51734afc97fdbf930e24a5972a1.png" title="({k\over{x^2+k^2}})^k\leq {A\over{x^k}}" style="vertical-align:-20%;" class="tex" alt="({k\over{x^2+k^2}})^k\leq {A\over{x^k}}" />, with <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_521d1468fd87987f5107a61b41c12251.png" title="x \,\textgreater\,1" style="vertical-align:-20%;" class="tex" alt="x \,\textgreater\,1" />, we can choose <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_abdfb1ee5ca8eaf34770b230fed37ffd.png" title="A" style="vertical-align:-20%;" class="tex" alt="A" /> to be 1. In such a case &#8212; when the hidden constants in the <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_2f55e2f764c899f5c8dabb45cd9338d8.png" title="O" style="vertical-align:-20%;" class="tex" alt="O" />-notation do not depend on the parameter <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_1536fd5a256e8ae0bf1cd5a9c828392e.png" title="k" style="vertical-align:-20%;" class="tex" alt="k" /> &#8212; the estimate is called <i>uniform</i>. This requirement is much like that of <a href="http://en.wikipedia.org/wiki/Uniform_convergence">uniform convergence</a> or <a href="http://en.wikipedia.org/wiki/Uniform_continuity">uniform continuity</a> in analysis.</p>
<p>So why trouble oneself with uniformity? Here&#8217;s one case where uniform estimates prove helpful: In &#8220;balancing&#8221; the asymptotic terms of a sum evenly to achieve a tight bound.</p>
<p>For instance, if we have somehow shown that <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_d73c4c3b4ed0a9491e5a5db2e61e7611.png" title="f(x) = O(x^2t) + O(x^4t^{-2})" style="vertical-align:-20%;" class="tex" alt="f(x) = O(x^2t) + O(x^4t^{-2})" /> with <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_6424a0e9bc3f3fce99cca400465275c5.png" title="x, t \,\textgreater\, 1" style="vertical-align:-20%;" class="tex" alt="x, t \,\textgreater\, 1" /> and where <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_7719e254cdcddde73868082c03747973.png" title="t" style="vertical-align:-20%;" class="tex" alt="t" /> is a parameter. If the formula holds uniformly, we can get a tight bound by reasoning as follows: When <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_7719e254cdcddde73868082c03747973.png" title="t" style="vertical-align:-20%;" class="tex" alt="t" /> is small, the first part, <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_845054021567cb9b8967fc193af6ee05.png" title="O(x^2t)" style="vertical-align:-20%;" class="tex" alt="O(x^2t)" />, is small, but the second part, <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_40f19fc474d7c6d7d6dc67fbb530880e.png" title="O(x^4t^{-2})" style="vertical-align:-20%;" class="tex" alt="O(x^4t^{-2})" />, is large; the reverse holds if <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_7719e254cdcddde73868082c03747973.png" title="t" style="vertical-align:-20%;" class="tex" alt="t" /> is large. Hence we wish to find a &#8220;balance&#8221; that minimizes the sum of the <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_23cf3a439d9492818690c93067ded298.png" title="O(\cdot)" style="vertical-align:-20%;" class="tex" alt="O(\cdot)" /> terms. And this happens when both the terms are asymptotically equivalent. So to achieve such a balance, we simply equate the two expressions <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_f3d3544bb21c11888c1b9f9236600434.png" title="x^2t = x^4t^{-2}" style="vertical-align:-20%;" class="tex" alt="x^2t = x^4t^{-2}" />, giving <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_6ded7e8506cf9c320a56fc69e8d5f04e.png" title="t=x^{2/3}" style="vertical-align:-20%;" class="tex" alt="t=x^{2/3}" />, and we finally get <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_59516dcbc0d883e23593df6c74bb6a58.png" title="f(x) = O(x^{8/3})" style="vertical-align:-20%;" class="tex" alt="f(x) = O(x^{8/3})" />.</p>
<p>Notice that because of uniformity, the four hidden constants (<img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_91d90b51ee8342c289278378741b884b.png" title="A_1" style="vertical-align:-20%;" class="tex" alt="A_1" />, <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_5b9b5c199983fd0b6465db77e6cda44a.png" title="a_1" style="vertical-align:-20%;" class="tex" alt="a_1" />, <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_d01f353275520948daf9d74cf8e70dbf.png" title="A_2" style="vertical-align:-20%;" class="tex" alt="A_2" />, <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_3da18de36bc90bc95a74c746ac13e605.png" title="a_2" style="vertical-align:-20%;" class="tex" alt="a_2" />) of the two <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_23cf3a439d9492818690c93067ded298.png" title="O(\cdot)" style="vertical-align:-20%;" class="tex" alt="O(\cdot)" /> do not vary when we vary the parameter <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_7719e254cdcddde73868082c03747973.png" title="t" style="vertical-align:-20%;" class="tex" alt="t" />. If the two original <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_23cf3a439d9492818690c93067ded298.png" title="O(\cdot)" style="vertical-align:-20%;" class="tex" alt="O(\cdot)" /> estimates had not been uniform; that is, had their hidden constants (implied by the <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_2f55e2f764c899f5c8dabb45cd9338d8.png" title="O" style="vertical-align:-20%;" class="tex" alt="O" />-notation) varied with <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_7719e254cdcddde73868082c03747973.png" title="t" style="vertical-align:-20%;" class="tex" alt="t" />, we wouldn&#8217;t have been able to apply this simplistic &#8220;balancing&#8221; idea. For instance, while for small <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_7719e254cdcddde73868082c03747973.png" title="t" style="vertical-align:-20%;" class="tex" alt="t" />, the <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_085cbcc5243900a13a760673f18bc0e0.png" title="x^2t" style="vertical-align:-20%;" class="tex" alt="x^2t" /> term might have been small, the hidden constant <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_91d90b51ee8342c289278378741b884b.png" title="A_1" style="vertical-align:-20%;" class="tex" alt="A_1" /> in <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_845054021567cb9b8967fc193af6ee05.png" title="O(x^2t)" style="vertical-align:-20%;" class="tex" alt="O(x^2t)" /> might have grown, leading to unpredictable overall behavior.</p>
<p>The good thing about uniform estimates is that they are sometimes more useful; but proving uniformity might require a more careful analysis. </p>
<h4>Asymptotic Series and Convergence: Some Curious Facts</h4>
<p>An <i>asymptotic series</i> or <a href="http://en.wikipedia.org/wiki/Asymptotic_expansion"><i>asymptotic expansion</i></a> for a function <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_57a3db9b14bded9c06fc0922f156537d.png" title="f(x)" style="vertical-align:-20%;" class="tex" alt="f(x)" /> is a formula like:<br />
<center><img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_ad7f5a1fbecc853bd4486d8a6bca0780.png" title="f(x) \approx c_0\phi_0(x) + c_1\phi_1(x) + c_2\phi_2(x) + \ldots \qquad (x\rightarrow\infty)" style="vertical-align:-20%;" class="tex" alt="f(x) \approx c_0\phi_0(x) + c_1\phi_1(x) + c_2\phi_2(x) + \ldots \qquad (x\rightarrow\infty)" /></center><br />
where, as <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_0f1aa60bf517a5bbf13780fa564b5e69.png" title="x\rightarrow\infty" style="vertical-align:-20%;" class="tex" alt="x\rightarrow\infty" />,<br />
<center><img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_e68d7586867d3ea3ba4723b3ee3f264e.png" title="\phi_{j+1}(x)=o(\phi_j(x))\qquad j\geq 0" style="vertical-align:-20%;" class="tex" alt="\phi_{j+1}(x)=o(\phi_j(x))\qquad j\geq 0" />, and,</center><br />
<center><img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_dbb4ba230b58aefd99ec2256eedc3218.png" title="f(x) = c_0\phi_0(x) + c_1\phi_1(x) + \cdots + c_{n-1}\phi_{n-1}(x) + O(\phi_n(x))\qquad (n\geq 0)" style="vertical-align:-20%;" class="tex" alt="f(x) = c_0\phi_0(x) + c_1\phi_1(x) + \cdots + c_{n-1}\phi_{n-1}(x) + O(\phi_n(x))\qquad (n\geq 0)" />.</center><br />
That is, the asymptotic expansion for <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_57a3db9b14bded9c06fc0922f156537d.png" title="f(x)" style="vertical-align:-20%;" class="tex" alt="f(x)" /> is a series of functions such that if we truncate the series at the <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_23e517569a067209bf264db2132df9e1.png" title="n" style="vertical-align:-20%;" class="tex" alt="n" /><sup>th</sup> term, the partial series provides an approximation to <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_57a3db9b14bded9c06fc0922f156537d.png" title="f(x)" style="vertical-align:-20%;" class="tex" alt="f(x)" /> (as <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_0f1aa60bf517a5bbf13780fa564b5e69.png" title="x\rightarrow\infty" style="vertical-align:-20%;" class="tex" alt="x\rightarrow\infty" />) with the error term asymptotically bound by the first truncated function. The <a href="http://en.wikipedia.org/wiki/Euler%27s_summation_formula#Asymptotic_expansion_of_sums">Euler-Maclaurin formula</a> is one way to get such an expansion. de Bruijn mentions other techniques in the book.</p>
<p>A large class of examples of asymptotic expansions are convergent power series, like:<br />
<center><img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_fe74febed2281589c514d7e406215d4b.png" title="\exp(z) = 1 + z + {z^2\over2!} + {z^3\over3!} + \cdots\qquad (|z|\rightarrow0)" style="vertical-align:-20%;" class="tex" alt="\exp(z) = 1 + z + {z^2\over2!} + {z^3\over3!} + \cdots\qquad (|z|\rightarrow0)" />.</center></p>
<p>But there could be asymptotic expansions that are not convergent power series. And with such asymptotic expansions, some curious things can happen:</p>
<ul>
<li>The series of the asymptotic expansion need not be convergent.</li>
<li>If the series does converge, its sum need not be equal to <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_57a3db9b14bded9c06fc0922f156537d.png" title="f(x)" style="vertical-align:-20%;" class="tex" alt="f(x)" /></li>
<li>It is even possible to have <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_57a3db9b14bded9c06fc0922f156537d.png" title="f(x)" style="vertical-align:-20%;" class="tex" alt="f(x)" /> and <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_696b622b47435feb569472b2e73b8e19.png" title="\phi_j(x)" style="vertical-align:-20%;" class="tex" alt="\phi_j(x)" />&#8217;s such that the sum of the series does not have the series as its own asymptotic expansion!</li>
</ul>
<p>The essential reason for these seemingly strange facts, as de Bruijn explains, is:</p>
<blockquote style="background-color: #ffffff"><p>&#8230; that convergence means something for some fixed <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_84a8809ce4927565dc0a056edf52ea49.png" title="x_0" style="vertical-align:-20%;" class="tex" alt="x_0" /> whereas the <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_2f55e2f764c899f5c8dabb45cd9338d8.png" title="O" style="vertical-align:-20%;" class="tex" alt="O" />-formulas are not concerned with <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_f1fdb243b0d5a9002b1f871e10aae976.png" title="x=x_0" style="vertical-align:-20%;" class="tex" alt="x=x_0" />, but with <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_0f1aa60bf517a5bbf13780fa564b5e69.png" title="x\rightarrow\infty" style="vertical-align:-20%;" class="tex" alt="x\rightarrow\infty" />. Convergence of the series, for all <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_32394b39aa8100258d9cd1b74aa703e2.png" title="x \,\textgreater\, 0" style="vertical-align:-20%;" class="tex" alt="x \,\textgreater\, 0" />, say, means that for every individual <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_6f2ba5df4f650911e133231e13279a3a.png" title="x" style="vertical-align:-20%;" class="tex" alt="x" /> there is a statement about the case <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_cf518ba638f8d0c256339ca4a611de68.png" title="n\rightarrow\infty" style="vertical-align:-20%;" class="tex" alt="n\rightarrow\infty" />. On the other hand, the statement that the series is the asymptotic expansion of <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_57a3db9b14bded9c06fc0922f156537d.png" title="f(x)" style="vertical-align:-20%;" class="tex" alt="f(x)" /> means that for every individual <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_23e517569a067209bf264db2132df9e1.png" title="n" style="vertical-align:-20%;" class="tex" alt="n" /> there is a statement about the case <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_0f1aa60bf517a5bbf13780fa564b5e69.png" title="x\rightarrow\infty" style="vertical-align:-20%;" class="tex" alt="x\rightarrow\infty" />.</p></blockquote>
<p>For example, when <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_04313d2ebdcb2accb5180a12e91c213c.png" title="f(x) = \int_1^x{e^t\over t}dt" style="vertical-align:-20%;" class="tex" alt="f(x) = \int_1^x{e^t\over t}dt" />, the asymptotic expansion of <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_154897c44af75233feafb0566b226f74.png" title="e^{-x}f(x)" style="vertical-align:-20%;" class="tex" alt="e^{-x}f(x)" /> is:<br />
<center><img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_c0e321dbedda903bc13a33f6cefd4323.png" title="{1\over x} + {1!\over x^2}+ {2!\over x^3} + {3!\over x^4} + \ldots \qquad (x\rightarrow\infty)" style="vertical-align:-20%;" class="tex" alt="{1\over x} + {1!\over x^2}+ {2!\over x^3} + {3!\over x^4} + \ldots \qquad (x\rightarrow\infty)" />,</center><br />
but the series converges for no value of <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_6f2ba5df4f650911e133231e13279a3a.png" title="x" style="vertical-align:-20%;" class="tex" alt="x" />.</p>
<h4>So&#8230;</h4>
<p>The book covers lots of useful stuff. In particular, It talks about <a href="http://en.wikipedia.org/wiki/Lagrange_inversion_theorem">Lagrange&#8217;s inversion formula</a> (using which we can solve for the <a href="http://en.wikipedia.org/wiki/Lambert_W_function">&#8220;tree function&#8221;</a>), it has a especially thorough treatment of <a href="http://en.wikipedia.org/wiki/Method_of_steepest_descent">the saddle-point method</a>. And much much more.</p>
]]></content:encoded>
			<wfw:commentRss>http://ashutoshmehra.net/blog/2009/05/asymptotic-methods-in-analysis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Solving Project Euler Problems 161 (Trominoes Tiling) and 185 (Number Mind) with ZDDs</title>
		<link>http://ashutoshmehra.net/blog/2009/03/solving-project-euler-problems-with-zdds/</link>
		<comments>http://ashutoshmehra.net/blog/2009/03/solving-project-euler-problems-with-zdds/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 14:16:47 +0000</pubDate>
		<dc:creator>Ashutosh</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Project Euler]]></category>
		<category><![CDATA[TAOCP]]></category>

		<guid isPermaLink="false">http://ashutoshmehra.net/blog/?p=157</guid>
		<description><![CDATA[Some months ago, I was re-introduced to Project Euler (PE) through the blogosphere. I had visited that site before, but had been left unmotivated by the first dozen or so problem statements that I read &#8212; neither the programming nor the math involved anything new or challenging. Only in the past few months, when I [...]]]></description>
			<content:encoded><![CDATA[<p>Some months ago, I was re-introduced to <a href="http://projecteuler.net/">Project Euler</a> (PE) through the blogosphere. I had visited that site before, but had been left unmotivated by the first dozen or so problem statements that I read &#8212; neither the programming nor the math involved anything new or challenging. Only in the past few months, when I attempted to crack some of the harder nuts, did I realize how interesting many PE problems could be &#8212; requiring a neat algorithm (or invoking a crucial theorem) for an efficient solution. <span id="more-157"></span></p>
<h4>My experience with Project Euler Problems</h4>
<p>As I attempted to solve more and more problems, I found a disproportionately large number of them centered around the theory of numbers. These involved important ideas of number sieves, congruences, continued fractions, the Farey series, solving <a href="http://en.wikipedia.org/wiki/Pell%27s_equation">Pell&#8217;s equation</a>, implementing <a href="http://en.wikipedia.org/wiki/Shanks-Tonelli_algorithm">Shanks Tonelli algorithm</a> etc., and had me sifting through Hardy and Wright&#8217;s book every so often. But after a while they weren&#8217;t so much fun. I did, however, find enough problems of my interest to get me hooked &#8212; enumeration and dynamic programming (<a href="http://projecteuler.net/index.php?section=problems&#038;id=208">208</a>, <a href="http://projecteuler.net/index.php?section=problems&#038;id=161">161</a>, <a href="http://projecteuler.net/index.php?section=problems&#038;id=209">209</a>, <a href="http://projecteuler.net/index.php?section=problems&#038;id=172">172</a>, <a href="http://projecteuler.net/index.php?section=problems&#038;id=169">169</a>, <a href="http://projecteuler.net/index.php?section=problems&#038;id=215">215</a>, <a href="http://projecteuler.net/index.php?section=problems&#038;id=219">219</a>), probability (<a href="http://projecteuler.net/index.php?section=problems&#038;id=227">227</a>, <a href="http://projecteuler.net/index.php?section=problems&#038;id=213">213</a>) and those occasionally unique ones like <a href="http://projecteuler.net/index.php?section=problems&#038;id=197">197</a> (concerning the &#8220;steady-state&#8221; behavior of a certain sequence). Working through these problems made me realize what a treasure PE was. Kudos to Colin &#8220;Euler&#8221; Hughes and the PE-team for their effort in running this great site!</p>
<p>In addition to having the fun of solving the problems myself, I could study the solutions worked out by other members in the forum. Seeing the elegance, efficiency and analyses of some of their solutions was a rewarding (even if a bit humbling) experience. A case in point is the solution to <a href="http://projecteuler.net/index.php?section=problems&#038;id=208">Robot Walks (208)</a> by <tt>sajninredoc</tt> and <tt>stijn263</tt> (among others), where they reduce the enumeration problem to a single summation. And then there were those APL/J programmers with their cute one-liners!</p>
<p>In this entry, I shall outline my solutions (and their performance characteristics) to the <a href="http://projecteuler.net/index.php?section=problems&#038;id=161">Trominoes Tiling (161)</a> and <a href="http://projecteuler.net/index.php?section=problems&#038;id=185">Number Mind (185)</a> problems. To solve these problems, I used the <a href="http://en.wikipedia.org/wiki/Zero_suppressed_decision_diagram">ZDD</a> techniques I had just studied in Knuth&#8217;s <a href="http://www-cs-faculty.stanford.edu/~uno/fasc1b.ps.gz">pre-fascicle 1B</a> (now in print as <a href="http://www.amazon.com/Art-Computer-Programming-Fascicle-Techniques/dp/0321580508">Vol 4 Fascicle 1</a>). I had <a href="http://ashutoshmehra.net/blog/2008/12/notes-on-zdds/trackback/">blogged earlier</a> on <a href="http://www-cs-faculty.stanford.edu/~knuth/musings.html">Knuth&#8217;s Fun with ZDDs musing</a>.</p>
<h4>Trominoes Tiling (161): Enumerating Exact Covers using ZDDs</h4>
<p>Trominoes Tiling (<a href="http://projecteuler.net/index.php?section=problems&#038;id=161">161</a>) is almost the tiling problem of TAOCP 7.1.4 &#8212; (130) with the difference that only trominoes are allowed (no monominoes or dominoes) and the grid-size is slightly larger (<tt>9x12</tt> instead of <tt>8x8</tt>). I reuseed, with the obvious changes, the ZDD routines that I had coded while working out that section. Since Knuth has already explained the ideas involved so beautifully (see the text around 7.1.4 &#8212; (129)), I shall only briefly sketch the ZDD construction before giving some performance statistics.</p>
<p>To begin, we first model the tiling problem as an <a href="http://en.wikipedia.org/wiki/Exact_cover">Exact Cover</a>. This involves creating a boolean matrix <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_dc7ce529b32ce1c71aa499962a871b74.png" title="(a_{ij})" style="vertical-align:-20%;" class="tex" alt="(a_{ij})" /> of <tt>9x12</tt> = <tt>108</tt> columns (corresponding to cells of the board) and <tt>526</tt> rows (corresponding to the ways of placing the <tt>L</tt> and <tt>I</tt> trominoes in all possible orientations on a <tt>9x12</tt> grid). We have <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_1c9980b7224f0d30f9fca908a5d28d32.png" title="a_{ij} = 1" style="vertical-align:-20%;" class="tex" alt="a_{ij} = 1" /> iff tromino placement <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_b2d5fbf99790e9a8f89f51d876bf7d45.png" title="i" style="vertical-align:-20%;" class="tex" alt="i" /> occupies cell <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_17205bd7356afc72c6e1cad22749dbb0.png" title="j" style="vertical-align:-20%;" class="tex" alt="j" />. The strategy for placement numbering I used is shown below for the simpler <tt>4x4</tt> case (the cells are numbered in the usual row-major order). Since the placement strategy decides the variable-ordering of the ZDD and hence its size (unless, of course, we choose to sift/reorder variables later on), it is important to pick a placement strategy that is not too inefficient.<br/></p>
<p><center><div id="attachment_210" class="wp-caption aligncenter" style="width: 498px"><a href="http://ashutoshmehra.net/blog/wp-content/uploads/2009/03/tiling.png"><img src="http://ashutoshmehra.net/blog/wp-content/uploads/2009/03/tiling.png" alt="Tromino Placement Numbering" title="Tromino Placement Numbering" width="488" height="394" class="size-full wp-image-210" /></a><p class="wp-caption-text">Tromino Placement Numbering for a 4x4 grid (also used for the rows of the exact cover matrix and ZDD variable ordering)</p></div></center><br/></p>
<p><center><div id="attachment_235" class="wp-caption aligncenter" style="width: 371px"><a href="http://ashutoshmehra.net/blog/wp-content/uploads/2009/03/exactcovermatrix.png"><img src="http://ashutoshmehra.net/blog/wp-content/uploads/2009/03/exactcovermatrix.png" alt="Exact Cover Matrix (for the simplified 4x4 case)" title="Exact Cover Matrix" width="361" height="180" class="size-full wp-image-235" /></a><p class="wp-caption-text">Exact Cover Matrix (for the simplified 4x4 case)</p></div></center><br/></p>
<p>Having constructed the boolean matrix, to enumerate the tilings, we find the number of ways to select some rows of the matrix such that if we inspect any column, precisely one of the selected rows contains a <tt>1</tt> in that column. Hence the name &#8220;exact&#8221; cover &#8212; we neither want to leave any cell uncovered, nor do we want parts of two or more trominoes to overlap.</p>
<p>Exact covers can be enumerated using Knuth&#8217;s <a href="http://en.wikipedia.org/wiki/Knuth%27s_Algorithm_X">Algorithm X</a> &#8212; an efficient backtracking technique implemented using an idea Knuth calls <a href="http://en.wikipedia.org/wiki/Dancing_Links">Dancing Links</a> (<a href="http://www-cs-faculty.stanford.edu/~knuth/programs/dance.w">DANCE program</a>, <a href="http://lanl.arxiv.org/pdf/cs/0011047">paper at arXiv</a>, <a href="http://stanford-online.stanford.edu/seminars/knuth/000222-knuth-100.asx">Computer Musing video</a>, ASL Implementations for <a href="http://stlab.adobe.com:8080/@md=d&#038;cd=//adobe_source_libraries/adobe/&#038;cdf=//adobe_source_libraries/adobe/dancing_links.hpp&#038;c=unH@//adobe_source_libraries/adobe/dancing_links.hpp">dancing_links</a> and <a href="http://stlab.adobe.com:8080/@md=d&#038;cd=//adobe_source_libraries/adobe/&#038;cdf=//adobe_source_libraries/adobe/dancing_links.hpp&#038;c=unH@//adobe_source_libraries/adobe/implementation/toroid.hpp">toroid_node_t</a>). Algorithm X not only <i>enumerates</i> the solution, it in fact <i>generates</i> them all!</p>
<p>To enumerate exact covers using ZDDs, using the <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_fe9bb6d8a0edbab4f541d976501129da.png" title="m\times n" style="vertical-align:-20%;" class="tex" alt="m\times n" /> matrix <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_dc7ce529b32ce1c71aa499962a871b74.png" title="(a_{ij})" style="vertical-align:-20%;" class="tex" alt="(a_{ij})" /> produced in the step above, we construct the boolean function (Eq. 7.1.4 &#8212; (129)):<br />
<center><img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_25f8b1b2356d5a5530d3bf454b1bc8ef.png" title="f(x_1,\ldots,x_m) = \bigwedge_{j=1}^n S_1(X_j)" style="vertical-align:-20%;" class="tex" alt="f(x_1,\ldots,x_m) = \bigwedge_{j=1}^n S_1(X_j)" /></center><br />
where boolean variable <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_6934f2728bd2faf498c0e5f163f0a6b5.png" title="x_i" style="vertical-align:-20%;" class="tex" alt="x_i" /> indicates selection of row <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_b2d5fbf99790e9a8f89f51d876bf7d45.png" title="i" style="vertical-align:-20%;" class="tex" alt="i" /> of the matrix (that is, placement a tromino in the orientation <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_b2d5fbf99790e9a8f89f51d876bf7d45.png" title="i" style="vertical-align:-20%;" class="tex" alt="i" />), <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_861ea1f62f4123c9fd82e1e3352ac180.png" title="X_j" style="vertical-align:-20%;" class="tex" alt="X_j" /> = <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_272031c949db9f3a7a6bc656df4314a2.png" title="\{x_i | a_{ij} = 1\}" style="vertical-align:-20%;" class="tex" alt="\{x_i | a_{ij} = 1\}" /> is the set of rows <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_b2d5fbf99790e9a8f89f51d876bf7d45.png" title="i" style="vertical-align:-20%;" class="tex" alt="i" /> that have a <tt>1</tt> in column <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_17205bd7356afc72c6e1cad22749dbb0.png" title="j" style="vertical-align:-20%;" class="tex" alt="j" />, and <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_569d1d4fd0a693fbd6651ca3238a06ce.png" title="S_1" style="vertical-align:-20%;" class="tex" alt="S_1" /> is the <i>Symmetric Boolean Function</i> that is true if exactly one of its inputs are true. The function <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_8cb65257e3377e4035d06ddf990b6657.png" title="f" style="vertical-align:-20%;" class="tex" alt="f" /> will be true iff for each column <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_17205bd7356afc72c6e1cad22749dbb0.png" title="j" style="vertical-align:-20%;" class="tex" alt="j" />, exactly one of the selected row <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_b2d5fbf99790e9a8f89f51d876bf7d45.png" title="i" style="vertical-align:-20%;" class="tex" alt="i" /> has <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_02ad58c6e982b858ab5d2594c9363554.png" title="a_{ij}" style="vertical-align:-20%;" class="tex" alt="a_{ij}" /> = 1 &#8212; this is just the condition for exact cover!<br/></p>
<p>For various ways to efficiently construct the above ZDD, see Exercise 7.1.4 &#8212; 212. The function <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_569d1d4fd0a693fbd6651ca3238a06ce.png" title="S_1" style="vertical-align:-20%;" class="tex" alt="S_1" /> can itself be implemented using Exercise 207&#8217;s &#8220;Symmetrizing&#8221; operation.<br/></p>
<p>Once we have the ZDD for the boolean function <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_8cb65257e3377e4035d06ddf990b6657.png" title="f" style="vertical-align:-20%;" class="tex" alt="f" /> above, the <i>number of solutions</i>, i.e., the number of vectors <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_48928d13ced42d8a72b7bc5b9c4d194a.png" title="(x_1,\ldots,x_m)" style="vertical-align:-20%;" class="tex" alt="(x_1,\ldots,x_m)" /> that make <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_8cb65257e3377e4035d06ddf990b6657.png" title="f" style="vertical-align:-20%;" class="tex" alt="f" /> true (which are precisely the vectors representing exact covers) can be readily found using the ZDD-analog of Algorithm 7.1.4C.<br/></p>
<p><i>Runtime performance of the solution</i>: The resulting ZDD involved 526 variables and had a size of <tt>7893743</tt> zeads. Without invoking any garbage collection, the peak memory usage was <tt>~600MB</tt>  (where each zead in my implementation was a <tt>20</tt>-byte node); time taken was <tt>34s</tt> (user) and <tt>85s</tt> (elapsed). Given that my memos weren&#8217;t very optimized (I had used GCC&#8217;s <tt>std::map</tt>) and neither had I tried doing any variable reordering, the performance seemed reasonable.<br/></p>
<p>A dynamic programming approach (like one I later used for <a href="http://projecteuler.net/index.php?section=problems&#038;id=215">Crack-free Walls (215)</a>),  should have been able to give the results in about a second (this was confirmed by posts on the forum). Nevertheless, the ZDD solution was fast enough to keep my conscience clear of any violations of <a href="http://projecteuler.net/index.php?section=about">Project Euler&#8217;s one-minute-rule</a>.<br/></p>
<p><i>Aside</i>: The <a href="http://projecteuler.net/index.php?section=problems&#038;id=215">Crack-free Walls (215)</a> problem is kind of like TAOCP Exercise 7.1.4 &#8212; 214 (Knuth calls it &#8220;faultfree&#8221;) and should be amenable to the ZDD attack. There, however, appears to be a danger of hitting space-out since the grid-size <tt>10x32</tt> is somewhat large. I&#8217;ve not tried this approach.<br/></p>
<h4>Number Mind (185): Using ZDDs to satisfy an ad-hoc set of constraints</h4>
<p><a href="http://projecteuler.net/index.php?section=problems&#038;id=185">Number Mind (185)</a> was the other PE problem that I solved with ZDDs. In this problem we&#8217;re to uncover a 16-digit number given a set of &#8220;guesses&#8221; of the form:<br />
<tt><br />
5616185650518293 ;2 correct<br />
3847439647293047 ;1 correct<br />
5855462940810587 ;3 correct<br />
. . .<br />
</tt></p>
<p>The guesses along with the &#8220;hit-rates&#8221; provide partial information about the secret number. Our aim is to find the &#8220;secret&#8221; number corresponding to the set of guesses.</p>
<p>To solve this problem, we create variables <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_6880c20b2ca196156a42d330b95f3113.png" title="x_{i,j}" style="vertical-align:-20%;" class="tex" alt="x_{i,j}" /> representing the condition that <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_b2d5fbf99790e9a8f89f51d876bf7d45.png" title="i" style="vertical-align:-20%;" class="tex" alt="i" /><sup>th</sup> digit (<img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_2afff0691791fbd2606dc4117a512d56.png" title="1\leq i\leq 16" style="vertical-align:-20%;" class="tex" alt="1\leq i\leq 16" />) is <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_17205bd7356afc72c6e1cad22749dbb0.png" title="j" style="vertical-align:-20%;" class="tex" alt="j" /> (<img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_731d15f2e46cf9802cf5a7d84f821fe4.png" title="0\leq j\leq 9" style="vertical-align:-20%;" class="tex" alt="0\leq j\leq 9" />). We then have the following constraints: </p>
<ul>
<li>Since each position <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_b2d5fbf99790e9a8f89f51d876bf7d45.png" title="i" style="vertical-align:-20%;" class="tex" alt="i" /> can hold just one digit, for each <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_b2d5fbf99790e9a8f89f51d876bf7d45.png" title="i" style="vertical-align:-20%;" class="tex" alt="i" /> exactly one of <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_6880c20b2ca196156a42d330b95f3113.png" title="x_{i,j}" style="vertical-align:-20%;" class="tex" alt="x_{i,j}" /> can be true. Constraints of this kind correspond to terms like <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_33048833db55c02df3be7c605eb7c54f.png" title="S_1(x_{i0},\ldots,x_{i9})" style="vertical-align:-20%;" class="tex" alt="S_1(x_{i0},\ldots,x_{i9})" />, where <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_569d1d4fd0a693fbd6651ca3238a06ce.png" title="S_1" style="vertical-align:-20%;" class="tex" alt="S_1" /> is again our friend, the symmetric boolean function.</li>
<li>Each of the given guess &#8220;hit-rates&#8221; must be satisfied. As an example, the third constraint &#8220;<tt>5855462940810587 (3 correct)</tt>&#8221; is represented as:<br />
<center><img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_a60bfd11aef715abf28cbc57cace0534.png" title="S_3(x_{15},x_{28},x_{35},x_{45},x_{54},x_{66},x_{72},x_{89}, x_{94},x_{A0},x_{B8},x_{C1},x_{D0},x_{E5},x_{F8},x_{G7})" style="vertical-align:-20%;" class="tex" alt="S_3(x_{15},x_{28},x_{35},x_{45},x_{54},x_{66},x_{72},x_{89}, x_{94},x_{A0},x_{B8},x_{C1},x_{D0},x_{E5},x_{F8},x_{G7})" /></center>
</li>
</ul>
<p>Using the symmetrizing operator from Exercise 7.1.4 &#8212; 207, both the above kinds of constraints are easily represented. Finally, we compute the <tt>AND</tt> (or, <tt>INTERSECT</tt>, if one prefers family-of-subsets point-of-view) of the individual constraints &#8212; and we&#8217;re left with the final ZDD representing the family of feasible solutions (in our case, the solution in fact turns out to be unique).</p>
<p><i>Runtime performance of the solution</i>: The ZDD had <tt>160</tt> variables <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_6880c20b2ca196156a42d330b95f3113.png" title="x_{i,j}" style="vertical-align:-20%;" class="tex" alt="x_{i,j}" />, program execution had a peak memory usage of <tt>~1GB</tt> without any garbage collection or reordering (zead-size <tt>20</tt>-bytes), size of the largest partial function was <tt>4665450</tt> zeads. The running time was <tt>~16s</tt> (both user and elapsed).</p>
<h4>Conclusion</h4>
<p>Comparing the ZDD solutions to the two PE problems, I think it was the kind of &#8220;unstructured&#8221; problem like Number Mind where the ZDD technique really shined.</p>
]]></content:encoded>
			<wfw:commentRss>http://ashutoshmehra.net/blog/2009/03/solving-project-euler-problems-with-zdds/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
<enclosure url="http://stanford-online.stanford.edu/seminars/knuth/000222-knuth-100.asx" length="75" type="video/x-ms-asf" />
		</item>
		<item>
		<title>Fun with ZDDs: Notes from Knuth&#8217;s 14th Annual Christmas Tree Lecture</title>
		<link>http://ashutoshmehra.net/blog/2008/12/notes-on-zdds/</link>
		<comments>http://ashutoshmehra.net/blog/2008/12/notes-on-zdds/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 09:29:05 +0000</pubDate>
		<dc:creator>Ashutosh</dc:creator>
				<category><![CDATA[TAOCP]]></category>

		<guid isPermaLink="false">http://ashutoshmehra.net/blog/?p=51</guid>
		<description><![CDATA[
In this entry, I&#8217;ll attempt to record the important ideas Knuth presented in his 14th Annual Christmas Tree Lecture, part of his regular Computer Musings. 
While I wasn&#8217;t fortunate enough to attend the lecture in person, I did go through the recording that, thankfully, was quite well done. Like all other &#8220;musings&#8221;, this one included [...]]]></description>
			<content:encoded><![CDATA[<div class="alignright" style="margin-left: 5px"><a href="http://scpd.stanford.edu/knuth/index.jsp"><img src="http://ashutoshmehra.net/images/posts/funzdd/don_knuth_scpd_small.jpg" alt="Don Knuth"></a></div>
<p>In this entry, I&#8217;ll attempt to record the important ideas Knuth presented in his <a href="http://scpd.stanford.edu/knuth/index.jsp">14<sup>th</sup> Annual Christmas Tree Lecture</a>, part of his regular <a href="http://www-cs-faculty.stanford.edu/~knuth/musings.html">Computer Musings</a>. </p>
<p>While I wasn&#8217;t fortunate enough to attend the lecture in person, I did go through the <a href="http://scpd.stanford.edu/knuth/index.jsp">recording</a> that, thankfully, was quite well done. Like all other &#8220;musings&#8221;, this one included some fascinating anecdotal bits (no pun intended) and Knuth&#8217;s good sense of humor was sprinkled throughout; but most noticeable was his infectious enthusiasm for the topics he spoke about. <span id="more-51"></span> The preface to Volume 4 (printed in Fascicle 0) begins with:</p>
<blockquote><p>The title of Volume 4 is <i>Combinatorial Algorithms</i>, and when I proposed it, I was strongly inclined to add a subtitle: <i>The Kind of Programming I Like Best</i>.</p></blockquote>
<p>His excitement for these topics clearly showed in the lecture. It is a must-watch for anyone interested in The Art of Computer Programming (especially Volume 4 on Combinatorial Algorithms), or interested in learning a very useful data structure for combinatorial applications &#8212; ZDDs. </p>
<p><a href="http://en.wikipedia.org/wiki/Zero_Suppressed_Decision_Diagram">ZDDs</a> (Zero-suppressed Binary Decision Diagrams) were introduced by <a href="http://www-alg.ist.hokudai.ac.jp/~minato/">Shin-Ichi Minato</a> in <a href="http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=1600231">1993</a>, about 7 years after <a href="http://en.wikipedia.org/wiki/Randal_Bryant">Randal Bryant</a> introduced <a href="http://www.cs.cmu.edu/~bryant/pubdir/ieeetc86.ps">his key ideas</a> of the <a href="http://en.wikipedia.org/wiki/Binary_decision_diagram">BDD data structure</a>; one of which was that keeping the BDD both <i>reduced</i> and <i>ordered</i> is important in practice. In his &#8220;Fun with BDDs&#8221; musing (this June), Knuth mentioned that this 1986 paper of Bryant&#8217;s took computer science almost by storm; remaining the most-cited paper in the field for many years (see <a href="http://citeseer.ist.psu.edu/source.html">here</a>).</p>
<p>Minato&#8217;s idea (of zero-suppression in BDDs) was motivated by his observation that when working with combinatorial objects, very often tests in BDDs have to be made just to ensure a potentially large number of variables are FALSE. So, in ZDDs, we just &#8220;skip over&#8221; any node whose <tt>HI</tt> pointer leads to <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_9d9a6507e830e8b593d1ed70e98f833e.png" title="\bot" style="vertical-align:-20%;" class="tex" alt="\bot" /> (the FALSE sink) &#8212; if having <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_a24b216b266c2b3073a06a61ed351cfb.png" title="x_j" style="vertical-align:-20%;" class="tex" alt="x_j" /> TRUE results in the subfunction rooted at <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_a24b216b266c2b3073a06a61ed351cfb.png" title="x_j" style="vertical-align:-20%;" class="tex" alt="x_j" /> to become FALSE, then we skip testing <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_a24b216b266c2b3073a06a61ed351cfb.png" title="x_j" style="vertical-align:-20%;" class="tex" alt="x_j" /> altogether. That&#8217;s the basic difference between BDDs and ZDDs. And while ZDD theory is much like the BDD theory, it differs sufficiently in the sense of requiring a different &#8220;mind-set&#8221;.</p>
<p>The <i>pre-fascicle 1B</i> that discusses BDDs and ZDDs is available from <a href="http://www-cs-faculty.stanford.edu/~knuth/news.html">Knuth&#8217;s News page</a> (<a href="http://www-cs-faculty.stanford.edu/~knuth/fasc1b.ps.gz">direct link</a>). Interested readers can download it (but Knuth cautions against printing it out just yet, since he&#8217;ll be putting up an updated version in a couple of weeks). That pre-fascicle is a 140-odd page booklet with more than 260 exciting exercises! It will be published as part of fascicle 1 (Knuth said it&#8217;ll go to printing around the end of January 2009); fascicle 1 would in turn form part of Volume 4A (along with the already published fascicles 0, 2, 3 and 4).</p>
<hr />
<b><i>Update (May 2009): Volume 4, Fascicle 1, is here!</i></b><br/></p>
<div class="alignleft" style="margin-right: 5px;"><a href="http://www.amazon.com/gp/product/0321580508?ie=UTF8&#038;tag=ashmehblo-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0321580508"><img border="0" src="/images/books/zdd/knuth_vol4_fascicle_1_small.jpg"></a><img src="http://www.assoc-amazon.com/e/ir?t=ashmehblo-20&#038;l=as2&#038;o=1&#038;a=0321580508" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></div>
<div class="alignright"> <a href="http://www.amazon.com/gp/product/0321637135?ie=UTF8&#038;tag=ashmehblo-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0321637135"><img border="0" src="/images/books/bundle0_4/taocp_vol4_fascicles0to4_bundle_small.jpg"></a><img src="http://www.assoc-amazon.com/e/ir?t=ashmehblo-20&#038;l=as2&#038;o=1&#038;a=0321637135" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></div>
<p>The Fascicle 1 of Volume 4 of The Art of Computer Programming is <a href="http://www.amazon.com/gp/product/0321580508?ie=UTF8&#038;tag=ashmehblo-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0321580508">now in print</a>. In addition to the material on BDD and ZDD techniques (described in this post), it includes a subsection on bitwise tricks and techniques, including broadword computing (formerly known as &#8220;Platologic computing&#8221;). In <a href="http://www-cs-faculty.stanford.edu/~knuth/news09.html">Knuth&#8217;s own words</a>, it is <i>&#8220;cram-packed with lots of new stuff among nearly 500 exercises and answers to exercises.&#8221;</i> <br/></p>
<p>There&#8217;s also a bundle of <a href="http://www.amazon.com/gp/product/0321637135?ie=UTF8&#038;tag=ashmehblo-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0321637135">Volume 4, Fascicles 0-4</a> available at a discounted price.</p>
<p><i>Get your copies today!</i><br />
<hr /><br/></p>
<h4>Families of subsets and their ZDD representation</h4>
<p>BDD is a data structure for (representing, manipulating, working with) boolean functions. ZDD, on the other hand, is a data-structure for what Knuth calls <i>Families of Sets</i> &#8212; a large number of combinatorial problems are based on studying families of sets (which are just <a href="http://en.wikipedia.org/wiki/Hypergraph">Hypergraphs</a>). Families of sets are another way of looking at boolean functions since there&#8217;s a natural one-to-one correspondence between the two &#8212; the <i>solutions of a boolean function</i> (the set of n-tuples of boolean values <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_362c33a0c2a82633a46a79521a7c0376.png" title="x=(x_1,\ldots,x_n)" style="vertical-align:-20%;" class="tex" alt="x=(x_1,\ldots,x_n)" /> such that <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_57a3db9b14bded9c06fc0922f156537d.png" title="f(x)" style="vertical-align:-20%;" class="tex" alt="f(x)" /> is TRUE) correspond to family of subsets, with each solution corresponding to a subset where <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_17205bd7356afc72c6e1cad22749dbb0.png" title="j" style="vertical-align:-20%;" class="tex" alt="j" /> belong to the subset iff <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_7cc29b9fb1d9d77e9b6c8839cc745eeb.png" title="x_j=1" style="vertical-align:-20%;" class="tex" alt="x_j=1" /> [see TAOCP Exercise 7.1.4 -- 203(b)]. But even though the families of sets can be encoded as boolean functions, it is sometimes better to think of them directly as families of sets, rather than in boolean sense. This is the thinking cap we&#8217;ll put on when working with ZDDs.</p>
<p>Families of subsets are taken from a well-ordered universe <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_9ad2a0bf52569b8d8ebfdaa076d52a7d.png" title="U" style="vertical-align:-20%;" class="tex" alt="U" />. We use the following rules to represent those using ZDDs [again, see TAOCP Exercise 7.1.4 -- 203]:</p>
<ul>
<li><i>The Empty Family</i>, <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_7fc8c0e997f25c275cd61a6add8b0517.png" title="\phi" style="vertical-align:-20%;" class="tex" alt="\phi" />, is represented by <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_9d9a6507e830e8b593d1ed70e98f833e.png" title="\bot" style="vertical-align:-20%;" class="tex" alt="\bot" /> (the FALSE sink node).</li>
<li><i>The Unit Family</i> (the set comprising just the empty set), <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_06d58e07d22069e3966ded0c097c13ea.png" title="\{\phi\} = \epsilon" style="vertical-align:-20%;" class="tex" alt="\{\phi\} = \epsilon" />, is represented by <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_c13311766e7f63959b9ccbeef9c93407.png" title="\top" style="vertical-align:-20%;" class="tex" alt="\top" /> (the TRUE sink node).
<li>If <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_8cb65257e3377e4035d06ddf990b6657.png" title="f" style="vertical-align:-20%;" class="tex" alt="f" /> is any other family (besides empty and unit), we know that it is nonempty, and that at least one of its members is in turn nonempty. In that case, let <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_0eef60d6c8cf58fd2d6a7f5b43e675fb.png" title="v" style="vertical-align:-20%;" class="tex" alt="v" /> be the <i>least</i> element of universe <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_9ad2a0bf52569b8d8ebfdaa076d52a7d.png" title="U" style="vertical-align:-20%;" class="tex" alt="U" /> that <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_8cb65257e3377e4035d06ddf990b6657.png" title="f" style="vertical-align:-20%;" class="tex" alt="f" /> <i>supports</i> &#8212; that <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_0eef60d6c8cf58fd2d6a7f5b43e675fb.png" title="v" style="vertical-align:-20%;" class="tex" alt="v" /> appears in at least one set in <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_8cb65257e3377e4035d06ddf990b6657.png" title="f" style="vertical-align:-20%;" class="tex" alt="f" />. [see answer to TAOCP Exercise 7.1.4 -- 197 for the definition of supports]. Then define sub-families <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_ea593d4a16d608ae79b67db74d6e6618.png" title="f_0" style="vertical-align:-20%;" class="tex" alt="f_0" /> and <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_ed9375129f95fe69105a13aea771bdbe.png" title="f_1" style="vertical-align:-20%;" class="tex" alt="f_1" /> of <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_8cb65257e3377e4035d06ddf990b6657.png" title="f" style="vertical-align:-20%;" class="tex" alt="f" /> with <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_0cfbfa49a3294a7219790ecb80763deb.png" title="f_0=\{\alpha | \alpha\in f\ \mbox{and}\ v\notin\alpha\}" style="vertical-align:-20%;" class="tex" alt="f_0=\{\alpha | \alpha\in f\ \mbox{and}\ v\notin\alpha\}" /> and <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_5e39bc3e7d60eea465611135c0ca1fd7.png" title="f_1=\{\alpha | \alpha\cup\{v\}\in f\ \mbox{and}\ v\notin\alpha\}" style="vertical-align:-20%;" class="tex" alt="f_1=\{\alpha | \alpha\cup\{v\}\in f\ \mbox{and}\ v\notin\alpha\}" />. These sub-families correspond to those sets that don&#8217;t and do contain <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_0eef60d6c8cf58fd2d6a7f5b43e675fb.png" title="v" style="vertical-align:-20%;" class="tex" alt="v" />. Then, inside the computer, the family <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_8cb65257e3377e4035d06ddf990b6657.png" title="f" style="vertical-align:-20%;" class="tex" alt="f" /> corresponds to a <i>zead</i> (ZDD-node) labeled <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_0eef60d6c8cf58fd2d6a7f5b43e675fb.png" title="v" style="vertical-align:-20%;" class="tex" alt="v" /> with <tt>LO</tt> and <tt>HI</tt> branches going to the ZDD representations of <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_ea593d4a16d608ae79b67db74d6e6618.png" title="f_0" style="vertical-align:-20%;" class="tex" alt="f_0" /> and <img src="http://ashutoshmehra.net/blog/wp-content/plugins/easy-latex/cache/tex_ed9375129f95fe69105a13aea771bdbe.png" title="f_1" style="vertical-align:-20%;" class="tex" alt="f_1" /> respectively. Notice the recursive definition (see Knuth&#8217;s diagram below).</li>
</ul>
<div id="attachment_59" class="wp-caption alignleft" style="width: 310px"><a href="http://ashutoshmehra.net/blog/wp-content/uploads/2008/12/zeads-in-zdd-attime-19-00.png"><img src="http://ashutoshmehra.net/blog/wp-content/uploads/2008/12/zeads-in-zdd-attime-19-00-300x225.png" alt="Defining a ZDD recursively (@19m)" width="300" height="225" class="size-medium wp-image-59"/></a><p class="wp-caption-text">Defining a ZDD recursively (@19m)</p></div>
<div id="attachment_56" class="wp-caption alignright" style="width: 310px"><a href="http://ashutoshmehra.net/blog/wp-content/uploads/2008/12/example-1-zdd-of-symmetric-2-function-attime-24-00.png"><img src="http://ashutoshmehra.net/blog/wp-content/uploads/2008/12/example-1-zdd-of-symmetric-2-function-attime-24-00-300x216.png" alt="Ex. 1: ZDD of a function (@24m)" width="300" height="225" class="size-medium wp-image-56" /></a><p class="wp-caption-text">Ex. 1: ZDD of a function (@24m)</p></div>
<p>Throughout the talk, Knuth took up various problems, and worked them out in real-time for everyone to follow, rather than putting up a bunch of slides with everything already worked out. This is one of the beauties of his musing lectures &#8212; it&#8217;s interactive. While Knuth works his way through the problems, the audience can work with him or with their own pencil and paper. And it&#8217;s even more convenient when watching the recorded session over net, where one can pause, work the problem out, and then play to see if they got it right, and go back etc.). Knuth also joked about how he sometimes had to sit through presentations where the speaker doing PowerPoint would whiz through the slides a bit too fast. So, anyway, the most instructive (and most enjoyable) way to understand these examples, I think, would be to just watch the video and work them out yourself (possibly after going through the relevant material in the pre-fascicle).</p>
]]></content:encoded>
			<wfw:commentRss>http://ashutoshmehra.net/blog/2008/12/notes-on-zdds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
