<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>João Ferreira</title>
	
	<link>http://www.joaoff.com</link>
	<description>Programming, Algorithms, and Mathematics</description>
	<pubDate>Sat, 04 Oct 2008 14:00:03 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/jff" type="application/rss+xml" /><feedburner:emailServiceId>552637</feedburner:emailServiceId><feedburner:feedburnerHostname>http://www.feedburner.com</feedburner:feedburnerHostname><feedburner:browserFriendly></feedburner:browserFriendly><item>
		<title>Multiples in the Fibonacci series</title>
		<link>http://www.joaoff.com/2008/05/09/multiples-in-the-fibonacci-series/</link>
		<comments>http://www.joaoff.com/2008/05/09/multiples-in-the-fibonacci-series/#comments</comments>
		<pubDate>Fri, 09 May 2008 16:18:30 +0000</pubDate>
		<dc:creator>jff</dc:creator>
		
		<category><![CDATA[Mathematics]]></category>

		<category><![CDATA[Methodology]]></category>

		<category><![CDATA[calculational]]></category>

		<category><![CDATA[distributivity]]></category>

		<category><![CDATA[fibonacci]]></category>

		<category><![CDATA[proof]]></category>

		<category><![CDATA[puzzles]]></category>

		<guid isPermaLink="false">http://www.joaoff.com/?p=64</guid>
		<description><![CDATA[I found the following problem on K. Rustan M. Leino&#8217;s puzzles page:

[Carroll Morgan told me this puzzle.]
Prove that for any positive K, every Kth number in the Fibonacci sequence is a multiple of the Kth number in the Fibonacci sequence.
More formally, for any natural number n, let F(n) denote Fibonacci number n. That is, F(0) [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6.1&#38;publisher=20c4d785-787c-484d-934d-0efe9b064130&#38;title=Multiples+in+the+Fibonacci+series&#38;url=http%3A%2F%2Fwww.joaoff.com%2F2008%2F05%2F09%2Fmultiples-in-the-fibonacci-series%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>I found the following problem on <a href="http://research.microsoft.com/~leino/puzzles.html#Multiples%20in%20the%20Fibonacci%20series" title="K. Rustan M. Leino's puzzles page">K. Rustan M. Leino&#8217;s puzzles page</a>:</p>
<blockquote><p>
[Carroll Morgan told me this puzzle.]</p>
<p>Prove that for any positive K, every Kth number in the Fibonacci sequence is a multiple of the Kth number in the Fibonacci sequence.</p>
<p>More formally, for any natural number n, let F(n) denote Fibonacci number n. That is, F(0) = 0, F(1) = 1, and F(n+2) = F(n+1) + F(n).  Prove that for any positive K and natural n, F(n*K) is a multiple of F(K).
</p></blockquote>
<p>This problem caught my attention, because it looks like a good example for using a result that I have derived last year. My result gives a <a href="http://www.joaoff.com/publications/JFFs/JFF0" title="JFF0: Distributivity and the greatest common divisor">reasonable sufficient condition for showing that a function distributes over the greatest common divisor</a> and shows that the Fibonacci function satisfies the condition.</p>
<p>In fact, using the property that the Fibonacci function distributes over the greatest common divisor, we can solve this problem very easily. Using <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/5bd9fcfb08d175f1ee80d815885549fb.png' title='\setms{0.1em}$\mathit{fib\/}{.}n$' alt='\setms{0.1em}$\mathit{fib\/}{.}n$' /> to denote the Fibonacci number <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/55a049b8f161ae7cfeb0197d75aff967.png' title='$n$' alt='$n$' />, <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/67f8900bb348ad7405c6997613c56dab.png' title='$m {\raisebox{0.5mm}{\ensuremath{\bigtriangledown}}} n$' alt='$m {\raisebox{0.5mm}{\ensuremath{\bigtriangledown}}} n$' /> to denote the greatest common divisor of <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/0e51a2dede42189d77627c4d742822c3.png' title='$m$' alt='$m$' /> and <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/55a049b8f161ae7cfeb0197d75aff967.png' title='$n$' alt='$n$' />, and <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/1df00dc7bb553d90756ea6002bd9fbb3.png' title='$\setminus$' alt='$\setminus$' /> to denote the division relation, a possible proof is:</p>
<div class="latex-margin">
<img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/ee86026bd72cb024a4ace884b6116f7f.png' title='\begin{mpdisplay}{0.1em}{6.5mm}{2mm}{3}$\mathit{fib\/}{.}(n{\times}k)$ is a multiple of $\mathit{fib\/}{.}k$\push\-\\$=$ \&gt;  \&gt;$\{$  \&gt;\+\+\+definition\-\-$~~~ \}$\pop\\$\mathit{fib\/}{.}k\ms{1}{\setminus}\ms{1}\mathit{fib\/}{.}(n{\times}k)$\push\-\\$=$ \&gt;  \&gt;$\{$  \&gt;\+\+\+$\mathit{fib\/}{.}k$ divides $\mathit{fib\/}{.}(n{\times}k)$\-\-$~~~ \}$\pop\\$\mathit{fib\/}{.}k\ms{0}{\raisebox{0.5mm}{\ensuremath{\bigtriangledown}}} \ms{1}\mathit{fib\/}{.}(n{\times}k)\ms{1}{=}\ms{1}\mathit{fib\/}{.}k$\push\-\\$=$ \&gt;  \&gt;$\{$  \&gt;\+\+\+$\mathit{fib\/}$ distributes over $\raisebox{0.8mm}{\ensuremath{\bigtriangledown}}$\-\-$~~~ \}$\pop\\$\mathit{fib\/}{.}(k\ms{0}\raisebox{0.8mm}{\ensuremath{\bigtriangledown}} \ms{1}(n{\times}k))\ms{1}{=}\ms{1}\mathit{fib\/}{.}k$\push\-\\$=$ \&gt;  \&gt;$\{$  \&gt;\+\+\+$k\ms{0}\raisebox{0.8mm}{\ensuremath{\bigtriangledown}} \ms{1}(n{\times}k)\ms{1}{=}\ms{1}k$\-\-$~~~ \}$\pop\\$\mathit{fib\/}{.}k\ms{1}{=}\ms{1}\mathit{fib\/}{.}k$\push\-\\$=$ \&gt;  \&gt;$\{$  \&gt;\+\+\+reflexivity\-\-$~~~ \}$\pop\\$\mathit{true\/}~~.$\end{mpdisplay}' alt='\begin{mpdisplay}{0.1em}{6.5mm}{2mm}{3}$\mathit{fib\/}{.}(n{\times}k)$ is a multiple of $\mathit{fib\/}{.}k$\push\-\\$=$ \&gt;  \&gt;$\{$  \&gt;\+\+\+definition\-\-$~~~ \}$\pop\\$\mathit{fib\/}{.}k\ms{1}{\setminus}\ms{1}\mathit{fib\/}{.}(n{\times}k)$\push\-\\$=$ \&gt;  \&gt;$\{$  \&gt;\+\+\+$\mathit{fib\/}{.}k$ divides $\mathit{fib\/}{.}(n{\times}k)$\-\-$~~~ \}$\pop\\$\mathit{fib\/}{.}k\ms{0}{\raisebox{0.5mm}{\ensuremath{\bigtriangledown}}} \ms{1}\mathit{fib\/}{.}(n{\times}k)\ms{1}{=}\ms{1}\mathit{fib\/}{.}k$\push\-\\$=$ \&gt;  \&gt;$\{$  \&gt;\+\+\+$\mathit{fib\/}$ distributes over $\raisebox{0.8mm}{\ensuremath{\bigtriangledown}}$\-\-$~~~ \}$\pop\\$\mathit{fib\/}{.}(k\ms{0}\raisebox{0.8mm}{\ensuremath{\bigtriangledown}} \ms{1}(n{\times}k))\ms{1}{=}\ms{1}\mathit{fib\/}{.}k$\push\-\\$=$ \&gt;  \&gt;$\{$  \&gt;\+\+\+$k\ms{0}\raisebox{0.8mm}{\ensuremath{\bigtriangledown}} \ms{1}(n{\times}k)\ms{1}{=}\ms{1}k$\-\-$~~~ \}$\pop\\$\mathit{fib\/}{.}k\ms{1}{=}\ms{1}\mathit{fib\/}{.}k$\push\-\\$=$ \&gt;  \&gt;$\{$  \&gt;\+\+\+reflexivity\-\-$~~~ \}$\pop\\$\mathit{true\/}~~.$\end{mpdisplay}' />
</div>
<p>The crucial step is clearly the one where we apply the distributivity property. Distributivity properties are very important, because they allow us to rewrite expressions in a way that prioritizes the function that has the most relevant properties. In the example above we could not simplify <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/76f243059e8bb3a9cacdc63b2f968769.png' title='$fib.k$' alt='$fib.k$' /> nor <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/7b2ebadea81fc6279c1af91202d106e8.png' title='$fib.(n \times k)$' alt='$fib.(n \times k)$' />, but applying the distributivity property prioritised the <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/ce98e3d3fbb19473820b37950cb2ca99.png' title='$\bigtriangledown$' alt='$\bigtriangledown$' /> operator &#8212; and we know how to simplify <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/d13fe68318d5bf8d74cc8c1d92cb7d03.png' title='$k\ms{0}\raisebox{0.8mm}{\ensuremath{\bigtriangledown}} \ms{1}(n{\times}k)$' alt='$k\ms{0}\raisebox{0.8mm}{\ensuremath{\bigtriangledown}} \ms{1}(n{\times}k)$' />. Furthermore, in practice, distributivity properties reduce to simple syntactic manipulations, thus reducing the introduction of error and simplifying the verification of our arguments.</p>
<p>(Now that I think about it, perhaps it would be a good idea to write a note on distributivity properties, summarizing their importance and their relation with symbol dynamics.)</p>
<p>If you have any corrections, questions, or alternative proofs, please leave a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joaoff.com/2008/05/09/multiples-in-the-fibonacci-series/feed/</wfw:commentRss>
		</item>
		<item>
		<title>New domain name (joaoff.com)</title>
		<link>http://www.joaoff.com/2008/02/25/new-domain-name-joaoffcom/</link>
		<comments>http://www.joaoff.com/2008/02/25/new-domain-name-joaoffcom/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 20:21:58 +0000</pubDate>
		<dc:creator>jff</dc:creator>
		
		<category><![CDATA[Personal]]></category>

		<category><![CDATA[blog]]></category>

		<category><![CDATA[domain]]></category>

		<category><![CDATA[joaoff.com]]></category>

		<guid isPermaLink="false">http://www.joaoff.com/2008/02/25/new-domain-name-joaoffcom/</guid>
		<description><![CDATA[Some people were complaining about the domain joaoferreira.org, because it was a bit long and they never got the number of r&#8217;s in Ferreira right. From today, they can&#8217;t complain anymore! 
The new and official URL of this website is now shorter and r&#8217;s-free: joaoff.com .
If you don&#8217;t like it and prefer the old one, [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6.1&#38;publisher=20c4d785-787c-484d-934d-0efe9b064130&#38;title=New+domain+name+%28joaoff.com%29&#38;url=http%3A%2F%2Fwww.joaoff.com%2F2008%2F02%2F25%2Fnew-domain-name-joaoffcom%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>Some people were complaining about the domain <a href="http://joaoferreira.org" title="Joao's website">joaoferreira.org</a>, because it was a bit long and they never got the number of r&#8217;s in Ferreira right. From today, they can&#8217;t complain anymore! </p>
<p>The new and official URL of this website is now shorter and r&#8217;s-free: <b><a href="http://joaoff.com" title="Joao's website">joaoff.com</a></b> .</p>
<p>If you don&#8217;t like it and prefer the old one, please let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joaoff.com/2008/02/25/new-domain-name-joaoffcom/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A reward check from Donald Knuth</title>
		<link>http://www.joaoff.com/2008/02/25/a-reward-check-from-donald-knuth/</link>
		<comments>http://www.joaoff.com/2008/02/25/a-reward-check-from-donald-knuth/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 20:10:51 +0000</pubDate>
		<dc:creator>jff</dc:creator>
		
		<category><![CDATA[Personal]]></category>

		<category><![CDATA[check]]></category>

		<category><![CDATA[correction]]></category>

		<category><![CDATA[knuth]]></category>

		<guid isPermaLink="false">http://www.joaoff.com/2008/02/25/a-reward-check-from-donald-knuth/</guid>
		<description><![CDATA[The other day I went to my pigeon-hole to collect my snail mail, and I had a letter from Donald E. Knuth, Professor Emeritus of the Art of Computer Programming!

Inside, there was a check for a correction I sent him some months ago. In fact, it was not really a correction; it was more like [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6.1&#38;publisher=20c4d785-787c-484d-934d-0efe9b064130&#38;title=A+reward+check+from+Donald+Knuth&#38;url=http%3A%2F%2Fwww.joaoff.com%2F2008%2F02%2F25%2Fa-reward-check-from-donald-knuth%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>The other day I went to my pigeon-hole to collect my snail mail, and I had a letter from Donald E. Knuth, Professor Emeritus of the Art of Computer Programming!</p>
<div align="center"><img src='http://www.joaoff.com/wp-content/uploads/2008/02/knuth-cover.jpg' alt='Cover of the letter that Knuth sent to Joao' /></div>
<p>Inside, there was a check for a correction I sent him some months ago. In fact, it was not really a correction; it was more like a comment. And it was so obvious (he even said that) that he just sent $0.32, instead of the usual $2.56. But hey, who cares? I&#8217;ve got Knuth&#8217;s autograph now <img src='http://www.joaoff.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<div align="center"><img src='http://www.joaoff.com/wp-content/uploads/2008/02/knuth-check.jpg' alt='A reward check from Donald Knuth' /></div>
<p>Perhaps I should set as one of my goals to find a proper error, so that I can receive a $2.56 check <img src='http://www.joaoff.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> By the way, <a href="http://www-cs-faculty.stanford.edu/~knuth/gkp.html" title="Concrete Mathematics Errata">the errata of the Concrete Mathematics is available online</a> and this particular omission is documented as follows:</p>
<blockquote><p>
page 338, line 2 from the bottom<br />
&nbsp;&nbsp; change &#8220;for $z$&#8221; to &#8220;for $z$ and multiplying by $a$&#8221;
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.joaoff.com/2008/02/25/a-reward-check-from-donald-knuth/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Calculational proofs are usually direct</title>
		<link>http://www.joaoff.com/2008/02/11/direct-proofs/</link>
		<comments>http://www.joaoff.com/2008/02/11/direct-proofs/#comments</comments>
		<pubDate>Mon, 11 Feb 2008 00:02:03 +0000</pubDate>
		<dc:creator>jff</dc:creator>
		
		<category><![CDATA[Education]]></category>

		<category><![CDATA[Mathematics]]></category>

		<category><![CDATA[calculational]]></category>

		<category><![CDATA[irrationality]]></category>

		<category><![CDATA[proofs]]></category>

		<guid isPermaLink="false">http://www.joaoferreira.org/2008/02/11/direct-proofs/</guid>
		<description><![CDATA[jd2718 asked in his blog if anyone knew a direct proof of the irrationality of &#160;&#160;. In this post I present a proof that, even if some don&#8217;t consider it direct, is a nice example of the effectiveness of calculational proof. But first, there are two concepts that need to be clarified: direct proof and [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6.1&#38;publisher=20c4d785-787c-484d-934d-0efe9b064130&#38;title=Calculational+proofs+are+usually+direct&#38;url=http%3A%2F%2Fwww.joaoff.com%2F2008%2F02%2F11%2Fdirect-proofs%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://jd2718.wordpress.com/2008/02/06/is-there-a-direct-proof/" title="Is there a direct proof for the irrationality of sqrt(2)?">jd2718 asked in his blog</a> if anyone knew a direct proof of the irrationality of <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/e3ffc1186774b36e03fbf02a80b794db.png' title='$\sqrt 2$' alt='$\sqrt 2$' />&nbsp;&nbsp;. In this post I present a proof that, even if some don&#8217;t consider it direct, is a nice example of the effectiveness of calculational proof. But first, there are two concepts that need to be clarified: <em>direct proof</em> and <em>irrational number</em>.</p>
<h2>Direct proofs</h2>
<p>The concept of direct proof can vary slightly from person to person. For instance, <a href="http://en.wikipedia.org/wiki/Direct_proof" title="Definition of Direct Proof in Wikipedia">Wikipedia defines it as</a>:</p>
<blockquote><p>In mathematics and logic, a direct proof is a way of showing the truth or falsehood of a given statement by a straightforward combination of established facts, usually existing lemmas and theorems, without making any further assumptions.</p></blockquote>
<p>Alternatively, in <a href="http://zimmer.csufresno.edu/~larryc/proofs/proofs.direct.html" title="Definition of Direct Proof at Larry Cusick's website">Larry W. Cusick&#8217;s website we can read</a>:</p>
<blockquote><p>
A direct poof [<i>sic</i>] should be thought of as a flow of implications beginning with &#8220;P&#8221; and ending with &#8220;Q&#8221;.</p>
<p>P -> &#8230; -> Q</p>
<p>Most proofs are (and should be) direct proofs. Always try direct proof first, unless you have a good reason not to.
</p></blockquote>
<p>I consider the wording &#8216;<i>without making any further assumptions</i>&#8216; in the first definition ambiguous and I don&#8217;t understand why the second definition only applies to implications. But anyway, with these definitions in mind, a direct proof for the irrationality of <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/71486f265f83bc1e3d2b6f67704bcc23.png' title='$\sqrt{2}$' alt='$\sqrt{2}$' /> can be something like:</p>
<div class="latex-margin">
<img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/548fc40d95576c3a28bbccd7978041ec.png' title='\setms{0.1em}\begin{mpdisplay}{0.1em}{8.5mm}{2mm}{3}$\sqrt{2}$ is irrational\push\-\\$=$     \&gt;      \&gt;$\{$  \&gt;\+\+\+justification\-\-$~~~ \}$\pop\\$\mathit{true\/}~~.$\end{mpdisplay}' alt='\setms{0.1em}\begin{mpdisplay}{0.1em}{8.5mm}{2mm}{3}$\sqrt{2}$ is irrational\push\-\\$=$     \&gt;      \&gt;$\{$  \&gt;\+\+\+justification\-\-$~~~ \}$\pop\\$\mathit{true\/}~~.$\end{mpdisplay}' />
</div>
<p>Or, alternatively, we can also use a proof of the following shape:</p>
<div class="latex-margin">
<img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/7bea98f144c5cf871381e339a7da2770.png' title='\begin{mpdisplay}{0.1em}{8.5mm}{2mm}{3}$\sqrt{2}$ is irrational\push\-\\$\Leftarrow$    \&gt;      \&gt;$\{$  \&gt;\+\+\+justification\-\-$~~~ \}$\pop\\$\mathit{true\/}~~.$\end{mpdisplay}' alt='\begin{mpdisplay}{0.1em}{8.5mm}{2mm}{3}$\sqrt{2}$ is irrational\push\-\\$\Leftarrow$    \&gt;      \&gt;$\{$  \&gt;\+\+\+justification\-\-$~~~ \}$\pop\\$\mathit{true\/}~~.$\end{mpdisplay}' />
</div>
<h2>Irrational numbers</h2>
<p>An irrational number is a real number that can&#8217;t be expressed as a simple fraction. Therefore, the number <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/71486f265f83bc1e3d2b6f67704bcc23.png' title='$\sqrt{2}$' alt='$\sqrt{2}$' /> is irrational because for all integers m and n, with n non-negative, we have that:</p>
<div class="latex-margin">
<img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/f7b8eba2e56a090a2b1d238a148123f4.png' title='\begin{displaymath}\sqrt{2}\ms{2}~~{\neq}~~\ms{2}{\displaystyle\frac{m}{n}}\mbox{\ \ \ .}\end{displaymath}' alt='\begin{displaymath}\sqrt{2}\ms{2}~~{\neq}~~\ms{2}{\displaystyle\frac{m}{n}}\mbox{\ \ \ .}\end{displaymath}' />
</div>
<h2>A direct proof for the irrationality of <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/71486f265f83bc1e3d2b6f67704bcc23.png' title='$\sqrt{2}$' alt='$\sqrt{2}$' /></h2>
<p>Now that we have clarified the concepts above, we prove that <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/71486f265f83bc1e3d2b6f67704bcc23.png' title='$\sqrt{2}$' alt='$\sqrt{2}$' /> is irrational. For all integers m and n, with n non-negative, we have:</p>
<div class="latex-margin">
<img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/d18ae2dd07478a1d23daf198f99b64e7.png' title='\begin{mpdisplay}{0.1em}{8.5mm}{2mm}{3}$\sqrt{2}\ms{1}~{\neq}~\ms{1}{\displaystyle\frac{m}{n}}$\push\-\\$=$     \&gt;      \&gt;$\{$  \&gt;\+\+\+Use arithmetic to eliminate the square root operator.\-\-$~~~ \}$\pop\\$n^{2}{\times}2\ms{1}~{\neq}~\ms{1}m^{2}$\push\-\\$\Leftarrow$    \&gt;      \&gt;$\{$  \&gt;\+\+\+Two values are different if applying the same function to them\\ yields different values.\-\-$~~~ \}$\pop\\$\mathit{exp\/}{.}(n^{2}{\times}2)\ms{1}~{\neq}~\ms{1}\mathit{exp\/}{.}m^{2}$\push\-\\$=$     \&gt;      \&gt;$\{$  \&gt;\+\+\+Now we choose the function $exp.$\\Let $\mathit{exp\/}{.}k$ be the number that $2$ divides $k.$\\The function $\mathit{exp\/}$ has two important properties:\\~~~$\mathit{exp\/}{.}2\ms{1}{=}\ms{1}1$    and\\~~~$\mathit{exp\/}{.}(k{\times}l)\ms{2}{=}\ms{2}\mathit{exp\/}{.}k\ms{2}{+}\ms{2}\mathit{exp\/}{.}l$ .\\We apply these properties to simplify the left and right sides.\-\-$~~~ \}$\pop\\$1\ms{2}{+}\ms{2}2\ms{1}{\times}\ms{1}\mathit{exp\/}{.}n\ms{3}~{\neq}~\ms{3}2\ms{1}{\times}\ms{1}\mathit{exp\/}{.}m$\push\-\\ $=$     \&gt;      \&gt;$\{$  \&gt;\+\+\+The left side is an odd number and the right side is an even\\ number. Odd numbers and even numbers are different.\-\-$~~~ \}$\pop\\$\mathit{true\/}~~.$\end{mpdisplay}' alt='\begin{mpdisplay}{0.1em}{8.5mm}{2mm}{3}$\sqrt{2}\ms{1}~{\neq}~\ms{1}{\displaystyle\frac{m}{n}}$\push\-\\$=$     \&gt;      \&gt;$\{$  \&gt;\+\+\+Use arithmetic to eliminate the square root operator.\-\-$~~~ \}$\pop\\$n^{2}{\times}2\ms{1}~{\neq}~\ms{1}m^{2}$\push\-\\$\Leftarrow$    \&gt;      \&gt;$\{$  \&gt;\+\+\+Two values are different if applying the same function to them\\ yields different values.\-\-$~~~ \}$\pop\\$\mathit{exp\/}{.}(n^{2}{\times}2)\ms{1}~{\neq}~\ms{1}\mathit{exp\/}{.}m^{2}$\push\-\\$=$     \&gt;      \&gt;$\{$  \&gt;\+\+\+Now we choose the function $exp.$\\Let $\mathit{exp\/}{.}k$ be the number that $2$ divides $k.$\\The function $\mathit{exp\/}$ has two important properties:\\~~~$\mathit{exp\/}{.}2\ms{1}{=}\ms{1}1$    and\\~~~$\mathit{exp\/}{.}(k{\times}l)\ms{2}{=}\ms{2}\mathit{exp\/}{.}k\ms{2}{+}\ms{2}\mathit{exp\/}{.}l$ .\\We apply these properties to simplify the left and right sides.\-\-$~~~ \}$\pop\\$1\ms{2}{+}\ms{2}2\ms{1}{\times}\ms{1}\mathit{exp\/}{.}n\ms{3}~{\neq}~\ms{3}2\ms{1}{\times}\ms{1}\mathit{exp\/}{.}m$\push\-\\ $=$     \&gt;      \&gt;$\{$  \&gt;\+\+\+The left side is an odd number and the right side is an even\\ number. Odd numbers and even numbers are different.\-\-$~~~ \}$\pop\\$\mathit{true\/}~~.$\end{mpdisplay}' />
</div>
<p>Note that, unlike traditional proofs, we don&#8217;t assume that m and n are co-prime, nor that <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/71486f265f83bc1e3d2b6f67704bcc23.png' title='$\sqrt{2}$' alt='$\sqrt{2}$' /> is a rational. We essentially derive the boolean value of the expression <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/f1924c6abc6e88eeb2dc5618df8219b0.png' title='$\sqrt{2}\ms{2}~~{\neq}~~\ms{2}{\displaystyle\frac{m}{n}}\mbox{\ \ \ .}$' alt='$\sqrt{2}\ms{2}~~{\neq}~~\ms{2}{\displaystyle\frac{m}{n}}\mbox{\ \ \ .}$' /></p>
<p>If you have any suggestions or corrections, please leave a comment. I&#8217;d be more than happy to hear from you.</p>
<p>Note: I learnt the contrapositive of this proof from Roland Backhouse (page 38, <a href="http://www.amazon.co.uk/Program-Construction-Calculating-Implementations-Specifications/dp/0470848820/ref=pd_bbs_sr_1?ie=UTF8&#038;s=gateway&#038;qid=1202602020&#038;sr=8-1" title="Program Construction -- Calculating Implementations from Specifications">Program Construction &#8212; Calculating Implementations from Specifications</a>).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joaoff.com/2008/02/11/direct-proofs/feed/</wfw:commentRss>
		</item>
		<item>
		<title>In Defense Of Computer Science</title>
		<link>http://www.joaoff.com/2008/01/30/in-defense-of-computer-science/</link>
		<comments>http://www.joaoff.com/2008/01/30/in-defense-of-computer-science/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 13:10:48 +0000</pubDate>
		<dc:creator>jff</dc:creator>
		
		<category><![CDATA[Education]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://www.joaoferreira.org/2008/01/30/in-defense-of-computer-science/</guid>
		<description><![CDATA[Very good post from Paper Trail:
So why study computer science? The job prospects at the end are usually pretty good - because, if nothing else, you can become a pretty good software developer fairly quickly - but they are unknown. My argument is that the study of computer science is enough of an incentive enough [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6.1&#38;publisher=20c4d785-787c-484d-934d-0efe9b064130&#38;title=In+Defense+Of+Computer+Science&#38;url=http%3A%2F%2Fwww.joaoff.com%2F2008%2F01%2F30%2Fin-defense-of-computer-science%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://hnr.dnsalias.net/wp/?p=39" title="In Defense of Computer Science">Very good post</a> from <a href="http://hnr.dnsalias.net/wp" title="Paper Trail">Paper Trail</a>:</p>
<blockquote><p>So why study computer science? The job prospects at the end are usually pretty good - because, if nothing else, you can become a pretty good software developer fairly quickly - but they are unknown. My argument is that the study of computer science is enough of an incentive enough to make it worthwhile.</p></blockquote>
<p style="margin-top: 10px;"><strong>Related Articles:</strong></p><ul><li><a href="http://www.joaoff.com/2008/01/22/the-programmers-of-tomorrow/" rel="bookmark">The programmers of tomorrow</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.joaoff.com/2008/01/30/in-defense-of-computer-science/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The programmers of tomorrow</title>
		<link>http://www.joaoff.com/2008/01/22/the-programmers-of-tomorrow/</link>
		<comments>http://www.joaoff.com/2008/01/22/the-programmers-of-tomorrow/#comments</comments>
		<pubDate>Tue, 22 Jan 2008 23:43:00 +0000</pubDate>
		<dc:creator>jff</dc:creator>
		
		<category><![CDATA[Algorithms]]></category>

		<category><![CDATA[Education]]></category>

		<category><![CDATA[Mathematics]]></category>

		<category><![CDATA[Methodology]]></category>

		<category><![CDATA[Opinion]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[university]]></category>

		<guid isPermaLink="false">http://www.joaoferreira.org/2008/01/22/the-programmers-of-tomorrow/</guid>
		<description><![CDATA[A recent article written by Dr. Robert B.K. Dewar and Dr. Edmond Schonberg (both from AdaCore Inc.) is generating some discussion on the state of Computer Science (CS) education in the United States. In &#8220;Computer Science Education: Where Are the Software Engineers of Tomorrow?&#8220;, Dewar and Schonberg claim that U.S. universities are training unqualified and [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6.1&#38;publisher=20c4d785-787c-484d-934d-0efe9b064130&#38;title=The+programmers+of+tomorrow&#38;url=http%3A%2F%2Fwww.joaoff.com%2F2008%2F01%2F22%2Fthe-programmers-of-tomorrow%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.stsc.hill.af.mil/CrossTalk/2008/01/0801DewarSchonberg.html" title="Computer Science Education: Where Are the Software Engineers of Tomorrow?">A recent article written by Dr. Robert B.K. Dewar and Dr. Edmond Schonberg</a> (both from AdaCore Inc.) is generating <a href="http://reddit.com/r/programming/info/665i5/comments/" title="Some comments about Dewar and Schonberg article on reddit.com">some</a> discussion on the state of Computer Science (CS) education in the United States. In &#8220;<a href="http://www.stsc.hill.af.mil/CrossTalk/2008/01/0801DewarSchonberg.html" title="Computer Science Education: Where Are the Software Engineers of Tomorrow?">Computer Science Education: Where Are the Software Engineers of Tomorrow?</a>&#8220;, Dewar and Schonberg claim that U.S. universities are training unqualified and easily replaceable programmers. </p>
<blockquote><p>&#8220;It is our view that Computer Science (CS) education is neglecting basic skills, in particular in the areas of programming and formal methods. We consider that the general adoption of Java as a first programming language is in part responsible for this decline. We examine briefly the set of programming skills that should be part of every software professional’s repertoire.&#8221;</p></blockquote>
<p>The comment about Java&#8217;s adoption annoyed some Java aficionados, but <a href="http://itmanagement.earthweb.com/career/article.php/11067_3722876_1" title="Who Killed the Software Engineer? (Hint: It Happened in College)">in a recent interview</a>, Robert Dewar adds that the problem goes far beyond the choice of Java as the first programming language. The real problem is that CS programs are being dumbed down, so that they become more accessible and popular. In result, they &#8220;are not rigorous enough and don&#8217;t promote in-depth thinking and problem solving&#8221;.</p>
<blockquote><p>“A lot of it is, ‘Let’s make this all more fun.’ You know, ‘Math is not fun, let’s reduce math requirements. Algorithms are not fun, let’s get rid of them. <i>Ewww</i> – graphic libraries, they’re <i>fun</i>. Let’s have people mess with libraries. And [forget] all this business about ‘command line’ – we’ll have people use nice visual interfaces where they can point and click and do fancy graphic stuff and have <i>fun</i>.&#8221;</p></blockquote>
<p>Although the paper is concerned with the American reality, I believe we have the same problem in Europe &mdash; at least, and as far as I know, in the UK and in Portugal. However, in my opinion, the problem starts before university. The maths&#8217;s programs in secondary schools are also being simplified (or dumbed down, if you prefer) and many important concepts, like logic and proofs, are being ignored.</p>
<p>In result, first-year students usually have a poor background on maths and problem solving. In fact, most of them have never seen a proof and don&#8217;t even understand the importance of mathematical reasoning. With poor reasoning abilities, they become intellectually less curious, accepting things as they are presented, and they have tremendous difficulties creating new algorithms, or convincing someone that their own algorithms are correct.</p>
<p>Moreover, once they are in the university, one of two things happens:</p>
<ol>
<li>they are not taught explicitly how to solve problems or how to derive algorithms from their formal specifications (this is the most common case);</li>
<li>or they are taught the above skills but their poor background doesn&#8217;t allow them to fully appreciate these subjects.</li>
</ol>
<p><span id="more-27"></span></p>
<h2>What can be done?</h2>
<p>Dewar and Schonberg suggest some skills to be taught:</p>
<blockquote><p>&#8220;Students need to be exposed to the tools to construct large-scale reliable programs, as we discussed at the start of this article. Topics of relevance are studying formal specification methods and formal proof methodologies, as well as gaining an understanding of how high-reliability code is certified in the real world. When you step into a plane, you are putting your life in the hands of software which had better be totally reliable. As a computer scientist, you should have some knowledge of how this level of reliability is achieved. In this day and age, the fear of terrorist cyber attacks have given a new urgency to the building of software that is not only bug free, but is also immune from malicious attack. Such high-security software relies even more extensively on formal methodologies, and our students need to be prepared for this new world.&#8221;</p></blockquote>
<p>I agree with every word in this paragraph! We really need professionals capable of creating certified software that works under all circumstances.</p>
<h3>Joel Spolsky&#8217;s proposal</h3>
<p>Joel Spolky&#8217;s wrote <a href="http://www.joelonsoftware.com/items/2008/01/08.html" title="Undergraduate programming, by Joel Spolsky">an interesting post</a> where he suggests the following:</p>
<blockquote><p>&#8220;I think the solution would be to create a programming-intensive BFA in Software Development&#8211;a Julliard for programmers. Such a program would consist of a practical studio requirement developing significant works of software on teams with very experienced teachers, with a sprinkling of liberal arts classes for balance. It would be a huge magnet to the talented high school kids who love programming, but can&#8217;t get excited about proving theorums.&#8221;</p></blockquote>
<p>Obviously, this is a much more pragmatic and &#8220;hackish&#8221; approach than what Dewar and Schonberg suggest. He also writes:</p>
<blockquote><p>&#8220;When I said BFA, Bachelor of Fine Arts, I meant it: software development is an art, and the existing Computer Science education, where you&#8217;re expected to learn a few things about NP completeness and Quicksort is singularly inadequate to training students how to develop software.&#8221;</p></blockquote>
<p>I think I understand what Joel means when he writes that programming is an art. However, I prefer to call it a science. You see, art is subjective: it exists in your mind. We can both look to the same photograph or painting, and express different interpretations. A program, however, can&#8217;t be seen subjectively. Given a program, we have to be able to say <em>objectively</em> if it is correct (according to some specification) or if it is efficient. It is not a matter of aesthetic principles.</p>
<h3>Other Comments</h3>
<p><a href="http://www.ekinoderm.com/wordpress/?p=27" title="Who did Kill the Software Engineer?">The author of Ekinoderm caught my attention when he wrote the following:</a></p>
<blockquote><p>&#8220;When I got my B.S. (in 2003), I can remember students in my classes constantly grousing about how topics like Scheme or Finite State Automata were “useless” and we should spend our time doing “useful” things like learning how to use VB to make a database app or something. Or, God forbid, writing web apps in PHP.&#8221;</p></blockquote>
<p>Interestingly, I had a very similar experience during my university degree. Many students in my classes didn&#8217;t like functional programming nor formal methods, because, according to them, these skills were useless to get a job; and they also didn&#8217;t like to encode the usual algorithms for trees or graphs in C, because their favourite language (usually Java or VB) already had libraries with the algorithms implemented.</p>
<p>On the contrary, I was interested in functional programming and formal methods. And I think I have benefited quite a lot from studying them. I also learned a lot implementing data structures and algorithms in C. Even so, and after several programming projects at the university, and a job programming Python for a company that offered <a href="http://www.plone.org" title="Plone website">Plone</a> services, I didn&#8217;t feel ready for delivering certified programs (with proofs of correctness included). That was basically the reason why I have embarked in a PhD: I felt the need of programming by construction.</p>
<h2>Final Notes</h2>
<p>In 1975, Edsger Dijkstra wrote a famous note named &#8220;<a href="http://www.cs.utexas.edu/~EWD/transcriptions/EWD04xx/EWD498.html" title="EWD498: How do we tell truths that might hurt?">How do we tell truths that might hurt?</a>&#8220;, where he enumerated some of the unpleasant truths about Computer Science. In the first paragraph, he basically explains why exposing truths (just like Dewar and Schonberg did) gives rise to so much discussion and discordance:</p>
<blockquote><p>&#8220;Sometimes we discover unpleasant truths. Whenever we do so, we are in difficulties: suppressing them is scientifically dishonest, so we must tell them, but telling them, however, will fire back on us. If the truths are sufficiently impalatable, our audience is psychically incapable of accepting them and we will be written off as totally unrealistic, hopelessly idealistic, dangerously revolutionary, foolishly gullible or what have you. (Besides that, telling such truths is a sure way of making oneself unpopular in many circles, and, as such, it is an act that, in general, is not without personal risks. Vide Galileo Galilei&#8230;..)&#8221;</p></blockquote>
<p>What is really amazing is that, 33 years later, some of the most unpleasant truths he enumerated are still true:</p>
<blockquote>
<ul>
<li>Programming is one of the most difficult branches of applied mathematics; the poorer mathematicians had better remain pure mathematicians.</li>
<li>The easiest machine applications are the technical/scientific computations.</li>
<li>The tools we use have a profound (and devious!) influence on our thinking habits, and, therefore, on our thinking abilities.</li>
<li>The problems of business administration in general and data base management in particular are much too difficult for people that think in IBMerese, compounded with sloppy English.</li>
<li>About the use of language: it is impossible to sharpen a pencil with a blunt axe. It is equally vain to try to do it with ten blunt axes instead.</li>
<li>Besides a mathematical inclination, an exceptionally good mastery of one&#8217;s native tongue is the most vital asset of a competent programmer.</li>
<li>Simplicity is prerequisite for reliability.</li>
<li>By claiming that they can contribute to software engineering, the soft scientists make themselves even more ridiculous. (Not less dangerous, alas!) In spite of its name, software engineering requires (cruelly) hard science for its support.</li>
</ul>
</blockquote>
<p>To conclude the post, allow me to add one to the list:</p>
<blockquote><p>As long as programming is considered a soft science and the formal derivation of algorithms is neglected, there will always be people enumerating unpleasant truths about Computer Science.
</p></blockquote>
<p style="margin-top: 10px;"><strong>Related Articles:</strong></p><ul><li><a href="http://www.joaoff.com/2007/01/15/on-programming-and-mathematical-methodology-part-ii/" rel="bookmark">On Programming and Mathematical Methodology -- Part II</a></li><li><a href="http://www.joaoff.com/2006/12/28/on-programming-and-mathematical-methodology/" rel="bookmark">On Programming and Mathematical Methodology</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.joaoff.com/2008/01/22/the-programmers-of-tomorrow/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A square grid path problem</title>
		<link>http://www.joaoff.com/2008/01/20/a-square-grid-path-problem/</link>
		<comments>http://www.joaoff.com/2008/01/20/a-square-grid-path-problem/#comments</comments>
		<pubDate>Sun, 20 Jan 2008 19:30:53 +0000</pubDate>
		<dc:creator>jff</dc:creator>
		
		<category><![CDATA[Algorithms]]></category>

		<category><![CDATA[Mathematics]]></category>

		<category><![CDATA[combinatorics]]></category>

		<category><![CDATA[grid]]></category>

		<guid isPermaLink="false">http://www.joaoferreira.org/2008/01/20/a-square-grid-path-problem/</guid>
		<description><![CDATA[Last November I have solved Problem 15 of Project Euler (a counting problem involving paths in square grids), and, although the problem admits a simple solution, some of the solutions presented in their forums are very complicated. Thus, I thought it would be a good idea to present my solution, as I consider it very [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6.1&#38;publisher=20c4d785-787c-484d-934d-0efe9b064130&#38;title=A+square+grid+path+problem&#38;url=http%3A%2F%2Fwww.joaoff.com%2F2008%2F01%2F20%2Fa-square-grid-path-problem%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>Last November I have solved <a href="http://projecteuler.net/index.php?section=problems&#038;id=15" title="Project 15 of Project Euler">Problem 15 of Project Euler</a> (a counting problem involving paths in square grids), and, although the problem admits a simple solution, some of the solutions presented in their forums are very complicated. Thus, I thought it would be a good idea to present my solution, as I consider it very simple.</p>
<h2>Problem statement</h2>
<p>Starting in the top left corner of a 2&times;2 grid, there are 6 routes (without backtracking) to the bottom right corner.</p>
<div align="center">
<img src='http://www.joaoferreira.org/wp-content/uploads/2008/01/p_15.gif' alt='Path diagram for 4×4 square grid' />
</div>
<p>How many routes are there through a 20&times;20 grid?</p>
<h2>My solution</h2>
<p>In order to make the problem more interesting, let us investigate the more general problem of counting the number of routes in a n&times;n grid. Our argument is based on three observations:</p>
<ol>
<li>all the paths have size 2&times;n (the reason is obvious: you have to go right n positions and down another n positions);
</li>
<li>since we can only go right or down, we can identify every path by a string of Rs and Ds, where a R means going right and a D means going down; as an example, the paths illustrated in the problem statement are (from left to right and from top to bottom): RRDD, RDRD, RDDR, DRRD, DRDR and DDRR;</li>
<li>the strings mentioned above must contain the same number of Rs and Ds.</li>
</ol>
<p>From these three observations, we can transform the problem to the following:</p>
<p align="center">How many different strings of size 2&times;n, consisting of n Rs and n Ds,  there are?</p>
<p>The solution is now very simple, because the positioning of n Ds (or Rs) determines the positioning of the other n Rs (or Ds). Hence, the number we are interested in is the number in which we can choose n positions from 2&times;n available. The answer, using the traditional notation for the binomial coefficient, is:</p>
<div align="center">
<img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/5e853c24bdf272b76840220292269607.png' title='$${2n \choose n} = \frac{(2n)!}{n!\times n!}~~~~.$$' alt='$${2n \choose n} = \frac{(2n)!}{n!\times n!}~~~~.$$' />
</div>
<p>Instantiating n with 20, we get the answer to the initial problem of the 20&times;20 grid.</p>
<h2>Generalization to m&times;n grids</h2>
<p>The generalization to a m&times;n grid is also simple. The only difference is that the strings have length m+n. Using the same reasoning as above, the number of paths through a m&times;n grid is:</p>
<div align="center">
<img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/9da52b020e35a3b1a1c34f0d63f17b60.png' title='$${m+n \choose n} = \frac{(m+n)!}{m!\times n!}~~~~.$$' alt='$${m+n \choose n} = \frac{(m+n)!}{m!\times n!}~~~~.$$' />
</div>
<p><strong>Final note:</strong> If you want to access the forum of the problem, you have to solve it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joaoff.com/2008/01/20/a-square-grid-path-problem/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to be more confident about your own programs: an example using Perl</title>
		<link>http://www.joaoff.com/2007/07/26/how-to-be-more-confident-about-your-own-programs-an-example-using-perl/</link>
		<comments>http://www.joaoff.com/2007/07/26/how-to-be-more-confident-about-your-own-programs-an-example-using-perl/#comments</comments>
		<pubDate>Thu, 26 Jul 2007 00:09:16 +0000</pubDate>
		<dc:creator>jff</dc:creator>
		
		<category><![CDATA[Algorithms]]></category>

		<category><![CDATA[Mathematics]]></category>

		<category><![CDATA[Perl]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.joaoferreira.org/2007/07/26/how-to-be-more-confident-about-your-own-programs-an-example-using-perl/</guid>
		<description><![CDATA[Programming is one of the most difficult branches of applied mathematics; the poorer mathematicians had better remain pure mathematicians.

It was Edsger W. Dijkstra, the famous computer scientist, who wrote these words in his note named &#8220;How do we tell truths that might hurt?&#8220;. I am sure that many people didn&#8217;t like to read them, and [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6.1&#38;publisher=20c4d785-787c-484d-934d-0efe9b064130&#38;title=How+to+be+more+confident+about+your+own+programs%3A+an+example+using+Perl&#38;url=http%3A%2F%2Fwww.joaoff.com%2F2007%2F07%2F26%2Fhow-to-be-more-confident-about-your-own-programs-an-example-using-perl%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<blockquote><p><i>Programming is one of the most difficult branches of applied mathematics; the poorer mathematicians had better remain pure mathematicians.</i></p></blockquote>
<p><img align="right" height="144" width="158" src='http://www.joaoferreira.org/wp-content/uploads/2008/01/camel.gif' alt='Perl Camel' /></p>
<p>It was Edsger W. Dijkstra, the famous computer scientist, who wrote these words in his note named &#8220;<a href="http://www.cs.utexas.edu/~EWD/transcriptions/EWD04xx/EWD498.html" title="How do we tell truths that might hurt?">How do we tell truths that might hurt?</a>&#8220;. I am sure that many people didn&#8217;t like to read them, and didn&#8217;t understand what he meant.</p>
<p>Although it is not my intention to discuss his words, I want to present a simple example that demonstrates how mathematics can be used to program better and to make you more confident about your own programs.</p>
<p>This post includes a fair amount of mathematical definitions and concepts, but they should not be difficult to understand. After the mathematical discussion, I present an example using the Perl programming language (it also applies to languages like C or Java).</p>
<h3>The Problem</h3>
<p>The problem I am going to deal with, involves the ceiling and floor functions. If you don&#8217;t remember, the floor of a real number <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' /> is (usually) written as <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/8a4145c35dfd071975de295cafa007a5.png' title='$\left\lfloor{}x\right\rfloor$' alt='$\left\lfloor{}x\right\rfloor$' /> and it is defined as the greatest integer that is at most <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' />. Similarly, the ceiling of a real number <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' /> is written as <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/1ed839f9b3696f28230c4de8aca1a6ff.png' title='$\left\lceil{}x\right\rceil$' alt='$\left\lceil{}x\right\rceil$' /> and it is defined as the smallest integer that is at least <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' />.</p>
<p>The goal is to implement the ceiling function supposing that our programming language only provides the floor function to round numbers. Formally, given a real <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' />, we want to calculate an expression <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/8cd34385ed61aca950a6b06d09fb50ac.png' title='$e$' alt='$e$' /> such that:</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/b7a7964256cd15d952f026eca7c543be.png' title='\begin{displaymath}\setms{0.2em}\left\lceil{}x\right\rceil\ms{1}{=}\ms{1}\left\lfloor{}e\right\rfloor\mbox{\ \ \ .}\end{displaymath}' alt='\begin{displaymath}\setms{0.2em}\left\lceil{}x\right\rceil\ms{1}{=}\ms{1}\left\lfloor{}e\right\rfloor\mbox{\ \ \ .}\end{displaymath}' /></p>
<p><span id="more-23"></span></p>
<h3>The ceiling and floor functions</h3>
<p><!--adsense-->As I said before, the floor of a real number <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' /> is the greatest integer that is at most <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' />. Formally, we capture this notion in the following definition:</p>
<p class="display">For all real <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' />, <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/8a4145c35dfd071975de295cafa007a5.png' title='$\left\lfloor{}x\right\rfloor$' alt='$\left\lfloor{}x\right\rfloor$' /> is an integer such that, for all integers <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/55a049b8f161ae7cfeb0197d75aff967.png' title='$n$' alt='$n$' />,</p>
<p style="margin-left: 4em" class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/ce6a99028a514367daa096ae5bc9f220.png' title='\begin{displaymath}n\ms{1}{\leq}\ms{1}\left\lfloor{}x\right\rfloor\ms{1}~~{\equiv}~~\ms{1}n\ms{1}{\leq}\ms{1}x\mbox{\ \ \ .}\end{displaymath}' alt='\begin{displaymath}n\ms{1}{\leq}\ms{1}\left\lfloor{}x\right\rfloor\ms{1}~~{\equiv}~~\ms{1}n\ms{1}{\leq}\ms{1}x\mbox{\ \ \ .}\end{displaymath}' /></p>
<p>This very compact and elegant definition allows us to derive some properties very quickly. If, for instance, we instantiate <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/55a049b8f161ae7cfeb0197d75aff967.png' title='$n$' alt='$n$' /> to be <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/8a4145c35dfd071975de295cafa007a5.png' title='$\left\lfloor{}x\right\rfloor$' alt='$\left\lfloor{}x\right\rfloor$' />,  we get:</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/99c8a8d15f37084344f355970a58fd13.png' title='\begin{displaymath}\left\lfloor{}x\right\rfloor\ms{1}{\leq}\ms{1}\left\lfloor{}x\right\rfloor\ms{1}~~{\equiv}~~\ms{1}\left\lfloor{}x\right\rfloor\ms{1}{\leq}\ms{1}x\mbox{\ \ \ .}\end{displaymath}' alt='\begin{displaymath}\left\lfloor{}x\right\rfloor\ms{1}{\leq}\ms{1}\left\lfloor{}x\right\rfloor\ms{1}~~{\equiv}~~\ms{1}\left\lfloor{}x\right\rfloor\ms{1}{\leq}\ms{1}x\mbox{\ \ \ .}\end{displaymath}' /></p>
<p>Since the left side of the equivalence is true, the right side is also true. We thus have our first property:</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/40890b129d3b0f9b69c24d503121677e.png' title='(0)~~~\left\lfloor{}x\right\rfloor\ms{1}{\leq}\ms{1}x\mbox{\ \ \ .}' alt='(0)~~~\left\lfloor{}x\right\rfloor\ms{1}{\leq}\ms{1}x\mbox{\ \ \ .}' /></p>
<p>Please note that since <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/55a049b8f161ae7cfeb0197d75aff967.png' title='$n$' alt='$n$' /> is an integer by definition, we can only replace it by integer values. That is why we can replace it by <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/8a4145c35dfd071975de295cafa007a5.png' title='$\left\lfloor{}x\right\rfloor$' alt='$\left\lfloor{}x\right\rfloor$' />, which is an integer, but we can&#8217;t  instantiate it to be <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' /> because <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' /> is a real number. However, we can replace <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' /> by <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/55a049b8f161ae7cfeb0197d75aff967.png' title='$n$' alt='$n$' />, since all integers are also reals. Replacing <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' /> by <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/55a049b8f161ae7cfeb0197d75aff967.png' title='$n$' alt='$n$' />, we get:</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/0086b79881d2d48babd28d0c903172fd.png' title='\begin{displaymath}n\ms{1}{\leq}\ms{1}\left\lfloor{}n\right\rfloor\ms{1}~~{\equiv}~~\ms{1}n\ms{1}{\leq}\ms{1}n\mbox{\ \ \ ,}\end{displaymath}' alt='\begin{displaymath}n\ms{1}{\leq}\ms{1}\left\lfloor{}n\right\rfloor\ms{1}~~{\equiv}~~\ms{1}n\ms{1}{\leq}\ms{1}n\mbox{\ \ \ ,}\end{displaymath}' /></p>
<p>which simplifies to</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/2b3dcf7a7f703ac22083d0a2d92ec855.png' title='(1)~~~n\ms{1}{\leq}\ms{1}\left\lfloor{}n\right\rfloor\mbox{\ \ \ .}' alt='(1)~~~n\ms{1}{\leq}\ms{1}\left\lfloor{}n\right\rfloor\mbox{\ \ \ .}' /></p>
<p>Now, instantianting <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' /> to <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/55a049b8f161ae7cfeb0197d75aff967.png' title='$n$' alt='$n$' /> in (0), we can also conclude that</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/89008ce3314c6e4171e5b2887a363091.png' title='(2)~~~\left\lfloor{}n\right\rfloor\ms{1}{\leq}\ms{1}n\mbox{\ \ \ .}' alt='(2)~~~\left\lfloor{}n\right\rfloor\ms{1}{\leq}\ms{1}n\mbox{\ \ \ .}' /></p>
<p>Finally, from (1) and (2), we conclude that</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/be2c5c4df2dfcaff6721e110d7b5c764.png' title='\begin{displaymath}n\ms{1}{=}\ms{1}\left\lfloor{}n\right\rfloor\mbox{\ \ \ .}\end{displaymath}' alt='\begin{displaymath}n\ms{1}{=}\ms{1}\left\lfloor{}n\right\rfloor\mbox{\ \ \ .}\end{displaymath}' /></p>
<p>We already knew this property: the floor of an integer number <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/55a049b8f161ae7cfeb0197d75aff967.png' title='$n$' alt='$n$' /> is <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/55a049b8f161ae7cfeb0197d75aff967.png' title='$n$' alt='$n$' />.</p>
<p>We can do a very similar analysis for the ceiling function. We&#8217;ve seen that the ceiling of a real <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' /> is the smallest integer that is at least <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' />. So, formally, we have:</p>
<p class="display">For all real <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' />, <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/1ed839f9b3696f28230c4de8aca1a6ff.png' title='$\left\lceil{}x\right\rceil$' alt='$\left\lceil{}x\right\rceil$' /> is an integer such that, for all integers <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/55a049b8f161ae7cfeb0197d75aff967.png' title='$n$' alt='$n$' />,</p>
<p style="margin-left: 4em" class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/b1ae4112566715a1d5adefa65549059a.png' title='\begin{displaymath}\left\lceil{}x\right\rceil\ms{1}{\leq}\ms{1}n\ms{1}~~{\equiv}~~\ms{1}x\ms{1}{\leq}\ms{1}n\mbox{\ \ \ .}\end{displaymath}' alt='\begin{displaymath}\left\lceil{}x\right\rceil\ms{1}{\leq}\ms{1}n\ms{1}~~{\equiv}~~\ms{1}x\ms{1}{\leq}\ms{1}n\mbox{\ \ \ .}\end{displaymath}' /></p>
<p>Note that we can apply the contrapositive rule (that&#8217;s when we negate both sides) to this definition. Doing that, we get the equivalent definition:</p>
<p class="display">For all real <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' />, <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/1ed839f9b3696f28230c4de8aca1a6ff.png' title='$\left\lceil{}x\right\rceil$' alt='$\left\lceil{}x\right\rceil$' /> is an integer such that, for all integers <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/55a049b8f161ae7cfeb0197d75aff967.png' title='$n$' alt='$n$' />,</p>
<p style="margin-left: 4em" class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/928b099836a37475a478c960356be1b2.png' title='\begin{displaymath}n\ms{1}{&amp;lt;}\ms{1}\left\lceil{}x\right\rceil\ms{1}~~{\equiv}~~\ms{1}n\ms{1}{&amp;lt;}\ms{1}x\mbox{\ \ \ .}\end{displaymath}' alt='\begin{displaymath}n\ms{1}{&amp;lt;}\ms{1}\left\lceil{}x\right\rceil\ms{1}~~{\equiv}~~\ms{1}n\ms{1}{&amp;lt;}\ms{1}x\mbox{\ \ \ .}\end{displaymath}' /></p>
<p>I leave as an exercise to prove the dual properties of the ones we&#8217;ve seen for the floor function.</p>
<h3>Indirect equality and the solution to the problem</h3>
<p>Ok, so now that we have seen the formal definitions of the ceiling and floor functions, we can proceed. Note that these definitions have the aproppriate shape to use the proof technique named Indirect Equality. Briefly, the rule of Indirect Equality claims that two numbers <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' /> and <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/deceeaf6940a8c7a5a02373728002b0f.png' title='$y$' alt='$y$' /> are equal if, for all numbers <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/55a049b8f161ae7cfeb0197d75aff967.png' title='$n$' alt='$n$' /> of the same type as <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' /> and <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/deceeaf6940a8c7a5a02373728002b0f.png' title='$y$' alt='$y$' />, the following holds:</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/9cd7893364c6bb18e78bccf53722701f.png' title='\begin{displaymath}n\ms{1}{\leq}\ms{1}x\ms{1}~~{\equiv}~~\ms{1}n\ms{1}{\leq}\ms{1}y\mbox{\ \ \ .}\end{displaymath}' alt='\begin{displaymath}n\ms{1}{\leq}\ms{1}x\ms{1}~~{\equiv}~~\ms{1}n\ms{1}{\leq}\ms{1}y\mbox{\ \ \ .}\end{displaymath}' /></p>
<p>Recall that we want to calculate an expression <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/8cd34385ed61aca950a6b06d09fb50ac.png' title='$e$' alt='$e$' />, such that, for a given real <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' />:</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/82a1b26717c1fdf93c7b4b0bee6a77f9.png' title='\begin{displaymath}\left\lceil{}x\right\rceil\ms{1}{=}\ms{1}\left\lfloor{}e\right\rfloor\mbox{\ \ \ .}\end{displaymath}' alt='\begin{displaymath}\left\lceil{}x\right\rceil\ms{1}{=}\ms{1}\left\lfloor{}e\right\rfloor\mbox{\ \ \ .}\end{displaymath}' /></p>
<p>To use indirect equality, we will prove, for all <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/55a049b8f161ae7cfeb0197d75aff967.png' title='$n$' alt='$n$' />, the following:</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/51cfde2448b557cd96f9be01204de7c8.png' title='\begin{mpdisplay}{0.2em}{8.5mm}{2mm}{3}$n\ms{1}{\leq}\ms{1}\left\lceil{}x\right\rceil$\push\-\\$=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+hint why the step is valid\-\-$~~~ \}$\pop\\$n\ms{1}{\leq}\ms{1}\left\lfloor{}e\right\rfloor~~.$\end{mpdisplay}' alt='\begin{mpdisplay}{0.2em}{8.5mm}{2mm}{3}$n\ms{1}{\leq}\ms{1}\left\lceil{}x\right\rceil$\push\-\\$=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+hint why the step is valid\-\-$~~~ \}$\pop\\$n\ms{1}{\leq}\ms{1}\left\lfloor{}e\right\rfloor~~.$\end{mpdisplay}' /></p>
<p>The detailed proof is as follows:</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/857755b69ca4ecce959008ccc2a2e016.png' title='\begin{mpdisplay}{0.2em}{8.5mm}{2mm}{3}         $n\ms{1}{\leq}\ms{1}\left\lceil{}x\right\rceil$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+integer inequality\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{1}{&amp;lt;}\ms{1}\left\lceil{}x\right\rceil$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+contra-positive of ceiling\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{1}{&amp;lt;}\ms{1}x$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+$x\ms{2}{=}\ms{2}\mathit{int\/}{.}x\ms{2}{+}\ms{2}\mathit{frac\/}{.}x$ , where $\mathit{int\/}{.}x$ is the integer part\\         of $x$ and $\mathit{frac\/}{.}x$ is its fractional part\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{2}{&amp;lt;}\ms{2}\mathit{int\/}{.}x\ms{2}{+}\ms{2}\mathit{frac\/}{.}x$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+monotonicity: we subtract $\mathit{int\/}{.}x$ from both sides\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{2}{-}\ms{2}\mathit{int\/}{.}x\ms{2}{&amp;lt;}\ms{2}\mathit{frac\/}{.}x$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+contra-positive of ceiling\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{2}{-}\ms{2}\mathit{int\/}{.}x\ms{2}{&amp;lt;}\ms{2}\left\lceil\mathit{frac\/}{.}x\right\rceil$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+monotonicity: we add $\mathit{int\/}{.}x$ to both sides\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{2}{&amp;lt;}\ms{2}\mathit{int\/}{.}x\ms{2}{+}\ms{2}\left\lceil\mathit{frac\/}{.}x\right\rceil$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+integer inequality\-\-$~~~ \}$\pop\\         $n\ms{2}{\leq}\ms{2}\mathit{int\/}{.}x\ms{2}{+}\ms{2}\left\lceil\mathit{frac\/}{.}x\right\rceil$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+definition of floor\-\-$~~~ \}$\pop\\         $n\ms{1}{\leq}\ms{1}\left\lfloor\mathit{int\/}{.}x\ms{2}{+}\ms{2}\left\lceil\mathit{frac\/}{.}x\right\rceil\right\rfloor~~.$ \end{mpdisplay}' alt='\begin{mpdisplay}{0.2em}{8.5mm}{2mm}{3}         $n\ms{1}{\leq}\ms{1}\left\lceil{}x\right\rceil$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+integer inequality\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{1}{&amp;lt;}\ms{1}\left\lceil{}x\right\rceil$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+contra-positive of ceiling\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{1}{&amp;lt;}\ms{1}x$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+$x\ms{2}{=}\ms{2}\mathit{int\/}{.}x\ms{2}{+}\ms{2}\mathit{frac\/}{.}x$ , where $\mathit{int\/}{.}x$ is the integer part\\         of $x$ and $\mathit{frac\/}{.}x$ is its fractional part\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{2}{&amp;lt;}\ms{2}\mathit{int\/}{.}x\ms{2}{+}\ms{2}\mathit{frac\/}{.}x$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+monotonicity: we subtract $\mathit{int\/}{.}x$ from both sides\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{2}{-}\ms{2}\mathit{int\/}{.}x\ms{2}{&amp;lt;}\ms{2}\mathit{frac\/}{.}x$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+contra-positive of ceiling\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{2}{-}\ms{2}\mathit{int\/}{.}x\ms{2}{&amp;lt;}\ms{2}\left\lceil\mathit{frac\/}{.}x\right\rceil$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+monotonicity: we add $\mathit{int\/}{.}x$ to both sides\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{2}{&amp;lt;}\ms{2}\mathit{int\/}{.}x\ms{2}{+}\ms{2}\left\lceil\mathit{frac\/}{.}x\right\rceil$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+integer inequality\-\-$~~~ \}$\pop\\         $n\ms{2}{\leq}\ms{2}\mathit{int\/}{.}x\ms{2}{+}\ms{2}\left\lceil\mathit{frac\/}{.}x\right\rceil$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+definition of floor\-\-$~~~ \}$\pop\\         $n\ms{1}{\leq}\ms{1}\left\lfloor\mathit{int\/}{.}x\ms{2}{+}\ms{2}\left\lceil\mathit{frac\/}{.}x\right\rceil\right\rfloor~~.$ \end{mpdisplay}' /></p>
<p>We have thus proved that:</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/68c6feed41b7e3a9a237af4b8f8e24c6.png' title='\begin{displaymath}\left\lceil{}x\right\rceil\ms{1}{=}\ms{1}\left\lfloor\mathit{int\/}{.}x\ms{2}{+}\ms{2}\left\lceil\mathit{frac\/}{.}x\right\rceil\right\rfloor\mbox{\ \ \ .}\end{displaymath}' alt='\begin{displaymath}\left\lceil{}x\right\rceil\ms{1}{=}\ms{1}\left\lfloor\mathit{int\/}{.}x\ms{2}{+}\ms{2}\left\lceil\mathit{frac\/}{.}x\right\rceil\right\rfloor\mbox{\ \ \ .}\end{displaymath}' /></p>
<p>Note that we still have a problem: our floor expression still involves an application of the ceiling function! However, since</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/98bc519358d8112a87e969c47ebf2188.png' title='\begin{displaymath}0\ms{1}{\leq}\ms{1}\left\lceil\mathit{frac\/}{.}x\right\rceil\ms{1}{&amp;lt;}\ms{1}1\mbox{\ \ \ ,}\end{displaymath}' alt='\begin{displaymath}0\ms{1}{\leq}\ms{1}\left\lceil\mathit{frac\/}{.}x\right\rceil\ms{1}{&amp;lt;}\ms{1}1\mbox{\ \ \ ,}\end{displaymath}' /></p>
<p>we can easily determine the value of <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/68db9f2504c3a663c3c7c588baf8d8e9.png' title='$\left\lceil\mathit{frac\/}{.}x\right\rceil$' alt='$\left\lceil\mathit{frac\/}{.}x\right\rceil$' /> by a simple case analysis. If <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/332cc365a4987aacce0ead01b8bdcc0b.png' title='$x$' alt='$x$' /> is an integer, then <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/4806c2dd0af808fd41747aa6abbe3cab.png' title='$\left\lceil\mathit{frac\/}{.}x\right\rceil\ms{1}{=}\ms{1}0$' alt='$\left\lceil\mathit{frac\/}{.}x\right\rceil\ms{1}{=}\ms{1}0$' /> , else <img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/7f0cfa556c9f48a1935b17a7f7b913de.png' title='$\left\lceil\mathit{frac\/}{.}x\right\rceil\ms{1}{=}\ms{1}1$' alt='$\left\lceil\mathit{frac\/}{.}x\right\rceil\ms{1}{=}\ms{1}1$' />. Hence,</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/5b6fcc7ea9fffc5016a06e1ac2c81d73.png' title='\begin{mpdisplay}{0.2em}{8.5mm}{2mm}{3}         \push$\MPsf{if}\ms{1}$\=\+$x$ is an integer\ms{1}$\MPsf{\rightarrow}\ms{1}\left\lceil{}x\right\rceil\ms{1}{=}\ms{1}\left\lfloor\mathit{int\/}{.}x\right\rfloor\ms{1}{=}\ms{1}x;$\\         $x$ is not an integer\ms{1}$\MPsf{\rightarrow}\ms{1}\left\lceil{}x\right\rceil\ms{1}{=}\ms{1}\left\lfloor\mathit{int\/}{.}x\ms{2}{+}\ms{2}1\right\rfloor\ms{1}{=}\ms{1}\mathit{int\/}{.}x\ms{2}{+}\ms{2}1$\-\\         $\MPsf{fi}$\pop \end{mpdisplay}' alt='\begin{mpdisplay}{0.2em}{8.5mm}{2mm}{3}         \push$\MPsf{if}\ms{1}$\=\+$x$ is an integer\ms{1}$\MPsf{\rightarrow}\ms{1}\left\lceil{}x\right\rceil\ms{1}{=}\ms{1}\left\lfloor\mathit{int\/}{.}x\right\rfloor\ms{1}{=}\ms{1}x;$\\         $x$ is not an integer\ms{1}$\MPsf{\rightarrow}\ms{1}\left\lceil{}x\right\rceil\ms{1}{=}\ms{1}\left\lfloor\mathit{int\/}{.}x\ms{2}{+}\ms{2}1\right\rfloor\ms{1}{=}\ms{1}\mathit{int\/}{.}x\ms{2}{+}\ms{2}1$\-\\         $\MPsf{fi}$\pop \end{mpdisplay}' /></p>
<h3>An example in Perl</h3>
<p>An example of a language that does not provide a native function ceiling is Perl. The only native function related with rounding numbers (as far as I know) is the function <em>int</em>. This function is a mixture of the floor and ceiling function: for positive numbers it behaves as the floor function and for negative numbers it behaves as the ceiling function. This means that to solve the problem in Perl, we just have to worry about positive arguments!</p>
<p>Therefore, from our previous analysis, we can write a <strong>correct</strong> implementation of the ceiling function as follows:</p>
<pre>
sub correct_ceil {
  my $r = shift;
  my $frac = $r - int($r);
  if($frac&lt;=0) {
    return int($r);
  } else {
    return 1+int($r);
  }
}
</pre>
<p>And that&#8217;s it! We have a real proof that this function is correct! Although the problem is simple, it is very common to make mistakes. As an example, I found the following wrong ceiling implementation in a <a href="http://codingforums.com/archive/index.php?t-13775.html" title="Error in solution presented at programming forum">programming forum</a>:</p>
<p><code><br />
# ceil() funtion to use instead of loading in<br />
# the POSIX module each time<br />
{<br />
local ($amount) = @_;<br />
$floor = int($amount);<br />
$ceil = int($amount + 0.5);<br />
if ($ceil == $floor)<br />
{<br />
$ceil++;<br />
}<br />
return $ceil;<br />
}<br />
</code></p>
<p>Clearly, this function does not work for integer arguments! I just hope it is not being used anywhere <img src='http://www.joaoff.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Note</strong>: in Perl you can import the module <em>Posix</em> and use the function ceil, but our goal was to write the ceiling function knowing that the floor function is defined.</p>
<h3>Conclusions</h3>
<p>The main goal of this post was to show how mathematical arguments can be used to give us confidence in our own programs. I&#8217;m aware that, although the ceiling and floor functions are widely used (in financial applications, for instance), this example could be presented in a different way. The most obvious drawback is that the main proof is quite long; it could be shortened, but I would have to omit some intermediate steps.</p>
<p>On the positive side, once we adopt the definitions given, most part of the proofs involving the ceiling and floor functions become similar, and thus systematic. This allows us to reuse the proof techniques over and over again.</p>
<p>I hope you have enjoyed the post and I&#8217;d be glad to get some comments!</p>
<h3>A much better solution by Rob Mayoff</h3>
<p><a href="http://dqd.com/~mayoff/" title="Rob Mayoff">Rob Mayoff</a> proposed a much better solution (see comments) to this problem! A proof of his solution can be:</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/c65b9e447fd1b336badacf20c58d7ac6.png' title=' \begin{mpdisplay}{0.2em}{8.5mm}{2mm}{3}         $n\ms{1}{\leq}\ms{1}\left\lceil{}x\right\rceil$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+integer inequality\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{1}{&amp;lt;}\ms{1}\left\lceil{}x\right\rceil$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+contra-positive of ceiling\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{1}{&amp;lt;}\ms{1}x$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+multiply both sides by $-1$\-\-$~~~ \}$\pop\\         $-n\ms{2}{+}\ms{2}1\ms{1}{&amp;gt;}\ms{1}-x$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+contra-positive of floor\-\-$~~~ \}$\pop\\         $-n\ms{2}{+}\ms{2}1\ms{1}{&amp;gt;}\ms{1}\left\lfloor-x\right\rfloor$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+integer inequality\-\-$~~~ \}$\pop\\         $-n\ms{1}{\geq}\ms{1}\left\lfloor-x\right\rfloor$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+multiply both sides by $-1$\-\-$~~~ \}$\pop\\         $n\ms{1}{\leq}\ms{1}{-}\left\lfloor-x\right\rfloor~~.$ \end{mpdisplay} ' alt=' \begin{mpdisplay}{0.2em}{8.5mm}{2mm}{3}         $n\ms{1}{\leq}\ms{1}\left\lceil{}x\right\rceil$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+integer inequality\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{1}{&amp;lt;}\ms{1}\left\lceil{}x\right\rceil$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+contra-positive of ceiling\-\-$~~~ \}$\pop\\         $n\ms{2}{-}\ms{2}1\ms{1}{&amp;lt;}\ms{1}x$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+multiply both sides by $-1$\-\-$~~~ \}$\pop\\         $-n\ms{2}{+}\ms{2}1\ms{1}{&amp;gt;}\ms{1}-x$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+contra-positive of floor\-\-$~~~ \}$\pop\\         $-n\ms{2}{+}\ms{2}1\ms{1}{&amp;gt;}\ms{1}\left\lfloor-x\right\rfloor$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+integer inequality\-\-$~~~ \}$\pop\\         $-n\ms{1}{\geq}\ms{1}\left\lfloor-x\right\rfloor$\push\-\\         $=$     \&amp;gt;      \&amp;gt;$\{$  \&amp;gt;\+\+\+multiply both sides by $-1$\-\-$~~~ \}$\pop\\         $n\ms{1}{\leq}\ms{1}{-}\left\lfloor-x\right\rfloor~~.$ \end{mpdisplay} ' /></p>
<p>Therefore,</p>
<p class="display"><img class="lateximg" src='http://www.joaoferreira.org/wp-content/plugins/wp-latexrenderer/pictures/3648520a3f5833d1c456f2204c4a8678.png' title='$\left\lceil{}x\right\rceil\ms{1}{=}\ms{1}{-}\left\lfloor-x\right\rfloor$' alt='$\left\lceil{}x\right\rceil\ms{1}{=}\ms{1}{-}\left\lfloor-x\right\rfloor$' />.</p>
<p>Thanks Rob!</p>
<p style="margin-top: 10px;"><strong>Related Articles:</strong></p><ul><li><a href="http://www.joaoff.com/2007/01/15/on-programming-and-mathematical-methodology-part-ii/" rel="bookmark">On Programming and Mathematical Methodology -- Part II</a></li><li><a href="http://www.joaoff.com/2006/12/28/on-programming-and-mathematical-methodology/" rel="bookmark">On Programming and Mathematical Methodology</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.joaoff.com/2007/07/26/how-to-be-more-confident-about-your-own-programs-an-example-using-perl/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Swapping the values of two variables</title>
		<link>http://www.joaoff.com/2007/07/11/swapping-the-values-of-two-variables/</link>
		<comments>http://www.joaoff.com/2007/07/11/swapping-the-values-of-two-variables/#comments</comments>
		<pubDate>Wed, 11 Jul 2007 15:08:24 +0000</pubDate>
		<dc:creator>jff</dc:creator>
		
		<category><![CDATA[Algorithms]]></category>

		<category><![CDATA[Mathematics]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.joaoferreira.org/2007/07/11/swapping-the-values-of-two-variables/</guid>
		<description><![CDATA[In my previous post I have promised that I would put here some of my technical notes (JFFs). Today I am posting JFF1, which presents a very well-known problem in a non-traditional way. The problem is how to swap the values of two variables without using another temporary one.
I start by presenting the properties involved [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6.1&#38;publisher=20c4d785-787c-484d-934d-0efe9b064130&#38;title=Swapping+the+values+of+two+variables&#38;url=http%3A%2F%2Fwww.joaoff.com%2F2007%2F07%2F11%2Fswapping-the-values-of-two-variables%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p><!--adsense#pequeno-->In my previous post I have promised that I would put here some of my technical notes (JFFs). Today I am posting JFF1, which presents a very well-known problem in a non-traditional way. The problem is how to swap the values of two variables without using another temporary one.</p>
<p>I start by presenting the properties involved in the traditional solution and then I generalize it for arbitrary operators. I finish the note with a simple refinement. If you have any nice example instantiation for the last set of assumptions, I would be glad to know it. Other than that, comments or corrections are more than welcome!<br />
The note is available in PDF. Click the following link to get it:</p>
<p><a href="http://www.joaoferreira.org/wp-content/uploads/2007/07/jff1.pdf" id="p21">JFF1 - Swapping the value of two variables</a></p>
<p style="margin-top: 10px;"><strong>Related Articles:</strong></p><ul><li><a href="http://www.joaoff.com/2007/01/15/on-programming-and-mathematical-methodology-part-ii/" rel="bookmark">On Programming and Mathematical Methodology -- Part II</a></li><li><a href="http://www.joaoff.com/2006/12/28/on-programming-and-mathematical-methodology/" rel="bookmark">On Programming and Mathematical Methodology</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.joaoff.com/2007/07/11/swapping-the-values-of-two-variables/feed/</wfw:commentRss>
		</item>
		<item>
		<title>I am still alive!</title>
		<link>http://www.joaoff.com/2007/06/15/i-am-still-alive/</link>
		<comments>http://www.joaoff.com/2007/06/15/i-am-still-alive/#comments</comments>
		<pubDate>Fri, 15 Jun 2007 00:00:00 +0000</pubDate>
		<dc:creator>jff</dc:creator>
		
		<category><![CDATA[Algorithms]]></category>

		<category><![CDATA[Mathematics]]></category>

		<category><![CDATA[Personal]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.joaoferreira.org/2007/06/15/i-am-still-alive/</guid>
		<description><![CDATA[That&#8217;s true: the last post was exactly 5 months ago, but I&#8217;m still alive! A lot of new stuff happened during these 5 months. Two days after writing the last post, I went with my group (Foundations of Programming) to a very nice hotel in Ruddington, where, during two days, each member had to present [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6.1&#38;publisher=20c4d785-787c-484d-934d-0efe9b064130&#38;title=I+am+still+alive%21&#38;url=http%3A%2F%2Fwww.joaoff.com%2F2007%2F06%2F15%2Fi-am-still-alive%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s true: the last post was exactly 5 months ago, but I&#8217;m still alive! A lot of new stuff happened during these 5 months. Two days after writing the last post, I went with my <a href="http://www.cs.nott.ac.uk/Research/fop/" title="Foundations of Programming Group">group</a> (Foundations of Programming) to a very nice hotel in Ruddington, where, during two days, each member had to present something about his/her work. I&#8217;ve talked about a result I&#8217;ve derived related with distributivity through the Greatest Common Divisor. <a href="http://www.cs.nott.ac.uk/~nhn/FoPAD2007/Talks/jff-FoPAD2007.pdf" title="My slides at the FoP Away Day 2007">My slides</a> are available at the <a href="http://www.cs.nott.ac.uk/~nhn/FoPAD2007/" title="FoP Away Day 2007">event&#8217;s webpage</a> and I will put online a note with all the details.</p>
<p>A few days later Alexandra got ill with some strange pain in the abdominal area. The following weeks were really hard, since she had to go to the hospital emergency services. So that you have an idea of how strange the whole thing was, the doctors still don&#8217;t know what the problem is! Now, she has occasional pain, but it seems to be much more controlled.</p>
<p>Anyway, more or less at the same time I started to read a very nice article (a Functional Pearl) written by Jeremy Gibbons, Richard Bird and David Lester named &#8220;<a href="http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/rationals.pdf" title="Enumerating the Rationals article">Enumerating the Rationals</a>&#8220;. The paper presents some algorithms encoded in Haskell to enumerate the positive rational numbers. In particular, it presents algorithms to construct the famous <a href="http://www.cut-the-knot.org/blue/Stern.shtml" title="Stern-Brocot tree">Stern-Brocot</a> and <a href="http://www.math.upenn.edu/~wilf/website/recounting.pdf" title="Recounting the Rationals article, where Calkin-Wilf tree is presented">Calkin-Wilf</a> trees. It also presents a very efficient algorithm to enumerate the rationals in Calkin-Wilf order just by using as current state the previous rational (i.e., two integer numbers). However, the authors claim that &#8220;it is not at all obvious&#8221; how to create a similar efficient algorithm for enumerating the rationals in Stern-Brocot order. Well, after reading it, Roland (my supervisor) and me found a way of doing it. The key idea is that rational numbers are pairs of coprime numbers (numbers which greatest common divisor is 1) and thus, we can use Euclid&#8217;s algorithm as a basis for enumerating these pairs. By using the Extended Euclid&#8217;s algorithm written using matrix multiplication, we were able to derive both Calkin-Wilf and Stern-Brocot enumerations from the same algorithm. We wrote a <a href="http://cs.nott.ac.uk/~jff/papers/RecountingRationalsTwice.pdf" title="Recounting the Rationals: Twice!">paper named &#8220;Recounting the Rationals: Twice!&#8221;</a> that was submitted to the journal <a href="http://www.maa.org/pubs/monthly.html" title="American Mathematical Monthly">American Mathematical Monthly</a>.</p>
<p><span id="more-20"></span>I&#8217;ve also presented the algorithm at the <a href="http://sneezy.cs.nott.ac.uk/fun/may-07" title="Fun in the Afternoon, Cambridge, May 2007">&#8220;Fun in the Afternoon&#8221; event in Cambridge</a>, last May. I think the talk was clear enough and, although it has nothing to do with functional programming, its methodological aspect should be interesting enough to any (functional) programmer. I&#8217;ve had very positive feedback on the talk, which is a good sign. <a href="http://sneezy.cs.nott.ac.uk/fun/may-07/EnumeratingRationalsTwice.pdf" title="Slides of my talk at Fun in the Afternoon, May 2007, Cambridge">The slides of the talk</a> are available in the event&#8217;s webpage.</p>
<p>In April I&#8217;ve attended to the <a href="http://www.cs.nott.ac.uk/~nhn/MGS2007/" title="Midlands Graduate School 2007, Nottingham">Midlands Graduate School</a> (MGS Spring School). It was a very nice event organised by our group (in particular, I have to congratulate <a href="http://www.cs.nott.ac.uk/~nhn" title="Henrik Nilsson">Henrik</a> and <a href="http://www.cs.nott.ac.uk/~gmh/" title="Graham Hutton">Graham</a> for their excellent work!) with very nice talks as well. My favourite courses were Category Theory, Algorithmic Problem Solving and Operational Semantics, but I&#8217;ve also enjoyed the others I&#8217;ve attended. The best thing about this kind of event is the social interaction that you have with other students and researchers. And again, as happened before in other similar events, I always get that cold sensation that I don&#8217;t know nothing about anything! The good news is that this feeling is a constructive one, since I get motivated to learn more!</p>
<p>And since we&#8217;re talking about learning, I&#8217;m currently studying <a href="http://www.cut-the-knot.org/blue/GeneratingFunctions.shtml" title="Generating Functions at cut-the-knot.org">Generating Functions</a>, which are formal power series that encode information about sequences. Generating Functions are a very powerful tool: they can be used to prove identities very easily, to find nice and closed formulas to recurrence relations, to work with datatypes in order to find isomorphisms and, more importantly to my work, they can be used to solve counting problems in a very effective way. I&#8217;m writing a note about what I&#8217;m learning and I&#8217;ll probably post it here.</p>
<p>To finish the news about work, I&#8217;m currently preparing two JFFs (JFFs are my personal technical notes). The first one deals with the very known and simple problem that consists in swapping the value of two variables without using another temporary one. The second shows how to construct a very famous algorithm. I promise that I will post the notes here, as soon as they are available!</p>
<p>Besides work, I guess that the only relevant thing to talk about is that we went on holidays to Halkidiki in Greece in the last week of May. It was excellent and Alexandra and me will post a somewhat detailed description on our <a href="http://www.furiousmind.org" title="Furiousmind: Cinema, Places and Mathematics">joint blog Furiousmind.org</a>.</p>
<p><center><!--adsense#middleblock--></center>Other thing I did that I consider important enough to be mentioned, was to install Linux in my Powerbook G4. I was unhappy with Mac OS for quite a long time and decided to stop complaining and do something about it. The installation process was simple and the wireless connection worked with no further configuration (I was really surprised)! I&#8217;m now a much happier guy: I can still do what I need to do and I&#8217;m not using any proprietary software at all!To conclude the post, let me just tell you my plans for the next month:</p>
<ol>
<li>Post JFF0, JFF1 and JFF2 (these are the notes on distributivity and the greatest common divisor, how to swap values of variables without using another temporary one and the construction of an algorithm that is well-known, respectively);</li>
<li>Prepare a note I have written together with my supervisor about Number Theory to be distributed;</li>
<li>Prepare things to the <a href="http://asimod.in.tum.de/" title="Summer School in Marktoberdorf for Formal Logic Methods for System Security and Correctness">Summer School in Marktoberdorf</a> (Formal Logical Methods for System Security and Correctness). It&#8217;s true! I&#8217;ve been accepted to participate in the school and I already got the plane tickets. This means that I&#8217;ll be in Germany from the 31st July to the 12th August. Then I fly directly to Portugal and I return to Nottingham on the 29th August. So, if you want something from Germany or Portugal, let me know <img src='http://www.joaoff.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>Since I&#8217;m talking about trips, Alexandra and me are going to Amsterdam this next weekend. We&#8217;re really looking forward for it! And if you want something from there, please let us know.</li>
</ol>
<p>Thanks for reading and see you in the next post!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joaoff.com/2007/06/15/i-am-still-alive/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
