<?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>Looking Out To Sea</title>
	<atom:link href="http://www.dougalstanton.net/blog/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dougalstanton.net/blog</link>
	<description></description>
	<lastBuildDate>Fri, 30 Jul 2010 10:07:09 +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>Cyber security teaser challenge</title>
		<link>http://www.dougalstanton.net/blog/index.php/2010/07/30/cyber-security-teaser-challenge/</link>
		<comments>http://www.dougalstanton.net/blog/index.php/2010/07/30/cyber-security-teaser-challenge/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 10:07:09 +0000</pubDate>
		<dc:creator>Dougal</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.dougalstanton.net/blog/?p=1121</guid>
		<description><![CDATA[During the week a friend from work pointed me towards the Cyber Security Challenge, which is being touted as a popular method to promote the field of computer security in the UK.

They had released a teaser challenge as a sample of the main competition which seemed like it was worth trying. It took us a [...]]]></description>
			<content:encoded><![CDATA[<p>During the week a friend from work pointed me towards the <a href="https://cybersecuritychallenge.org.uk" title="Cyber Security Challenge">Cyber Security Challenge</a>, which is being touted as a popular method to promote the field of computer security in the UK.</p>

<p>They had released a <a href="https://cybersecuritychallenge.org.uk/cipher.html" title="Teaser challenge starting page">teaser challenge as a sample of the main competition</a> which seemed like it was worth trying. It took us a couple of days to get to the answer, not least of all because we actually had work to do!</p>

<p>Since the teaser challenge is now well over and the &#8220;official&#8221; method has been published <a href="https://cybersecuritychallenge.org.uk" title="Cyber Security Challenge">on the challenge page</a> (move your mouse over the big white space to see the solution) I thought it would be interesting to go through my solution and see (a) what the puzzle-setters had done (b) how the answer was stumbled upon (c) how the answer could have been derived and (d) where my method differed from the official approach, despite reaching basically the same answer. It&#8217;s been a while since I thought about the practical techniques of cryptanalysis so my methods are neither the best nor the most sensible, but at least I can be honest. Helen&#8217;s just finished reading <em>Cryptonomicon</em> so will probably tell where I went wrong!</p>

<p>If you want to try out your skills <a href="https://cybersecuritychallenge.org.uk/docs/cybersecuritychallenge.txt" title="Initial problem">the original problem is still available</a> and will probably be there for some time. At least you can see what the starting point was.</p>

<p>I&#8217;ll write up my results and methods in the next few days, posting each section as it goes. I&#8217;ll also publish the code I used to extract the solution, which was written in Haskell. I&#8217;ve never done anything like this before but the Haskell list-munging functions and point-free style made it simple. The effortless compositional style of creating pipelines of functions meant that I could play with little sections, joining and splicing them as necessary, until I found something which seemed like a good result. But there will be more details in the coming days.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougalstanton.net/blog/index.php/2010/07/30/cyber-security-teaser-challenge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Networking and redundancy (double meanings)</title>
		<link>http://www.dougalstanton.net/blog/index.php/2010/07/24/networking-and-redundancy-double-meanings/</link>
		<comments>http://www.dougalstanton.net/blog/index.php/2010/07/24/networking-and-redundancy-double-meanings/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 18:10:45 +0000</pubDate>
		<dc:creator>Dougal</dc:creator>
				<category><![CDATA[Humour]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.dougalstanton.net/blog/?p=1117</guid>
		<description><![CDATA[For the past three and a half years I have been working on router redundancy protocols. When your router (or its upstream connection) dies for some reason you want to minimise the loss on people using the network. Ideally users should never notice loss of connection, though in the real world there will be some [...]]]></description>
			<content:encoded><![CDATA[<p>For the past three and a half years I have been working on router redundancy protocols. When your router (or its upstream connection) dies for some reason you want to minimise the loss on people using the network. Ideally users should never notice loss of connection, though in the real world there will be some time delay before things are working again. The work I&#8217;ve been doing relies on having a second router which has its own connection to the local network and to the wider world. It acts as a redundant backup so that when the first one dies the second can step into its place within some short period.</p>

<p>When the primary router is working normally the secondary doesn&#8217;t do much. Its only role is to monitor the liveliness of the primary machine. The redundant router can often be used for other things when the primary is operating &#8212; and many times the primary acts as a redundant router for the secondary&#8217;s clients. Each provides backup for the other.</p>

<p>So when I found out recently that I was being made redundant I thought &#8220;great! I&#8217;ll just sit and watch other people working and take over if they burst into flames&#8221;. But it turns out that when people are redundant it&#8217;s totally different from when routers are redundant. Instead of being relied on for backup in case of failure, it means &#8220;no longer working&#8221;. Strange but true! I can see why it wouldn&#8217;t catch on very well in networking.</p>

<p>My last day at Cisco is this Friday (30 July). It&#8217;s been an interesting few years and provided novel experiences, silly conversations about <em>Star Trek</em> and given me a bit more confidence. I&#8217;m sad to be going, and though there will always be loose ends to tie up and the promise of interesting projects on the horizon, the team I&#8217;m leaving behind seems to have a glut of these at the moment. I&#8217;m also disappointed that the study group at work will continue reading SICP without me. Obviously I can read it alone but the discussion and peer support/pressure was a useful part of it.</p>

<p>Meanwhile, the job hunt continues. Recruitment agencies make this process at least ten times harder by hiding the employer, the industry and the specifics of the job for their own ends. I have had a few friends pass on job details, and had some telephone discussions, but no success yet. Watch this space, or one very much like it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougalstanton.net/blog/index.php/2010/07/24/networking-and-redundancy-double-meanings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What does your IP address mean?</title>
		<link>http://www.dougalstanton.net/blog/index.php/2010/07/23/what-does-your-ip-address-mean/</link>
		<comments>http://www.dougalstanton.net/blog/index.php/2010/07/23/what-does-your-ip-address-mean/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 18:27:03 +0000</pubDate>
		<dc:creator>Dougal</dc:creator>
				<category><![CDATA[Networking]]></category>

		<guid isPermaLink="false">http://www.dougalstanton.net/blog/?p=878</guid>
		<description><![CDATA[The internet protocol (IP) address of my laptop is 192.168.0.3/24. What does this mean?

The first and obvious question is, What&#8217;s an IP address? It&#8217;s an identifier that your computer uses to talk to other computers on the network. It bears a lot of resemblance in form and function to a telephone number. There are prefixes [...]]]></description>
			<content:encoded><![CDATA[<p>The internet protocol (IP) address of my laptop is 192.168.0.3/24. What does this mean?</p>

<p>The first and obvious question is, What&#8217;s an IP address? It&#8217;s an identifier that your computer uses to talk to other computers on the network. It bears a lot of resemblance in form and function to a telephone number. There are prefixes which are shared by every address in the area, and then there&#8217;s a bit specific to you.</p>

<p><img src="http://farm1.static.flickr.com/51/152502539_c4cb9121eb.jpg" class="show" alt="ethernet cable" /></p>

<p>An IP address has two important pieces of information embedded in it. The first is the <em>host ID</em> &#8212; the identifier of my specific computer. The second is the <em>network address</em> &#8212; which is the number of the network my computer is found in, and is analogous to a telephone area code.</p>

<p>Just to make things difficult though, the two numbers are joined together so you can&#8217;t tell where one part ends and the other begins. So when talking about addresses we need another piece of information to tell us which part is network and which part is host.</p>

<p>First, let&#8217;s write out 192.168.0.3 in binary. This makes a very long number but it will make everything much clearer from here on. Each number between the dots is converted separately. This number is not the same as 19,216,803.</p>

<p><div>
<pre>192.168.0.3 = 11000000 10101000 00000000 00000011</pre>
</div></p>

<p>I&#8217;ve left spaces where the dots were previously. Each section is 8 binary digits long, so each section can represent a maximum number of 11111111 &#8212; which is 255 in decimal.</p>

<p>The next bit we come to is choosing a point on that line so that all the digits on the <em>left</em> represent the network address and all the ones on the right show the host address. Looking back up at the address I gave at the top you&#8217;ll see a &#8220;/24&#8221; sitting at the end. This is called the <em>network mask</em> and it works just like a piece of card with a hole in it. You write out your address and then align 24 bits underneath: everything with a 0 underneath is masked out, leaving the network address. We are getting the result of 1 whenever both the address <em>and</em> the mask is 1.</p>

<p><div>
<pre>192.168.0.3  = 11000000 10101000 00000000 00000011
mask 24 bits = 11111111 11111111 11111111 00000000
result       = 11000000 10101000 00000000 00000000</pre>
</div></p>

<p>Back in decimal land, that network address is 192.168.0.0. Since the network mask is also a binary number it is often written like an IP address, as four decimal numbers separated by dots. The same address can be written as 192.168.0.3/24 or 192.168.0.3/255.255.255.0.</p>

<p>We can invert the network mask to give a host mask and use the same procedure to find out the host ID, which turns out to be 00000011, otherwise known as 3.</p>

<p><div>
<pre>192.168.0.3 = 11000000 10101000 00000000 00000011
mask 8 bits = 00000000 00000000 00000000 11111111
result      = 00000000 00000000 00000000 00000011</pre>
</div></p>

<p>You probably knew that from inspection but computers ain&#8217;t so clever!</p>

<p>Another useful number we can learn from the address and mask is the <em>broadcast address</em>. This can be used to send messages to everyone on the network. We calculate this by inverting the mask again, so we&#8217;ve got 8 bits on the right instead of 24 bits on the left, and taking the result to be 1 wherever the address <em>or</em> the mask is 1.</p>

<p><div>
<pre>192.168.0.3 = 11000000 10101000 00000000 00000011
mask 8 bits = 00000000 00000000 00000000 11111111
result      = 11000000 10101000 00000000 11111111</pre>
</div></p>

<p>The result can then be written as 192.168.0.255 in dotted-decimal format. Packets sent to this address will be examined by every host on the local network. This is useful if you don&#8217;t know the address of your recipient!</p>

<p><small>Photo is <a href="http://www.flickr.com/photos/saschaaa/152502539/">The World&#8217;s Network</a> by saschaaa.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougalstanton.net/blog/index.php/2010/07/23/what-does-your-ip-address-mean/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mex-a-Tron!</title>
		<link>http://www.dougalstanton.net/blog/index.php/2010/07/08/mex-a-tron/</link>
		<comments>http://www.dougalstanton.net/blog/index.php/2010/07/08/mex-a-tron/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 21:32:33 +0000</pubDate>
		<dc:creator>Dougal</dc:creator>
				<category><![CDATA[Films]]></category>
		<category><![CDATA[Food]]></category>
		<category><![CDATA[Reviews]]></category>

		<guid isPermaLink="false">http://www.dougalstanton.net/blog/?p=1106</guid>
		<description><![CDATA[I don&#8217;t know if I ever saw it the first time round, but I saw Tron this evening. Now I&#8217;m fully prepared for the sequel when it appears.

A few friends came over and we got fajitas from Los Cardos across the road &#8212; and despite the utilitarian appearance the food was pretty good. The staff [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know if I ever saw it the first time round, but I saw <em>Tron</em> this evening. Now I&#8217;m fully prepared for the sequel when it appears.</p>

<p>A few friends came over and we got fajitas from <a href="http://www.edinburghspotlight.com/2010/06/review-los-cardos-leith/">Los Cardos</a> across the road &#8212; and despite the utilitarian appearance the food was pretty good. The staff were friendly too. I got a &#8220;fajita burrito&#8221;, which is kinda what I&#8217;d call a fajita if I was making it at home, except they loaded it with rice as well as the usual fried onions, peppers, cheese, salsa and spicy chicken. (There are a number of other fillings available besides chicken, including haggis&#8230;) The food was more or less what you&#8217;d make yourself, simple but plentiful, and they had big, good quality tortillas which seems to be the hardest part when it comes to make-your-own fajita meals.</p>

<p>The film was weird as all hell. I borrowed the special edition with audio commentary and a separate making-of disc &#8212; I wonder what explanation they&#8217;ll have for some of the stranger scenes. Some didn&#8217;t even seem to connect at all to the rest of the story. It certainly wasn&#8217;t what I expected. I knew there was action in light-striped arenas that probably represented some gaming system, but I didn&#8217;t realise that most of the protagonists would be computer programs. Needless to say, if you know <em>anything</em> about computers you have to plug your ears at some points or risk bursting into entirely inappropriate laughter. The plot is a bit like <em>The Lord of the Rings</em> (take the magical item into the evil overlord&#8217;s domain to free everyone from tyranny).</p>

<p>The sequel &#8212; coming out in December I think, so aiming for the family Christmas market I suppose &#8212; follows the action twenty five years later in the same inner-computer environment. Hopefully they won&#8217;t be relying on the crutch of dazzling graphics and spectacle instead of coherent plot. But that&#8217;s probably a foolish hope&#8230;</p>

<p>Helen&#8217;s out tonight because one of her colleagues is leaving the lab, so she didn&#8217;t get to see it. Maybe we&#8217;ll watch it tomorrow with extras before I give the DVD back.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougalstanton.net/blog/index.php/2010/07/08/mex-a-tron/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>New active lifestyle, available in five exciting colours!</title>
		<link>http://www.dougalstanton.net/blog/index.php/2010/06/30/new-active-lifestyle-available-in-five-exciting-colours/</link>
		<comments>http://www.dougalstanton.net/blog/index.php/2010/06/30/new-active-lifestyle-available-in-five-exciting-colours/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 17:43:18 +0000</pubDate>
		<dc:creator>Dougal</dc:creator>
				<category><![CDATA[Hobbies]]></category>
		<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://www.dougalstanton.net/blog/?p=1102</guid>
		<description><![CDATA[Among the many advantages of no longer having a swollen infected toe is the ability to do sports again. I know, it doesn&#8217;t seem like me, but I have been known to do it in the past.

At the weekend Helen and I went an epic (miniature epic?) walk up the Water of Leith, from Bonnington [...]]]></description>
			<content:encoded><![CDATA[<p>Among the many advantages of no longer having a swollen infected toe is the ability to do sports again. I know, it doesn&#8217;t seem like me, but I have been known to do it in the past.</p>

<p>At the weekend Helen and I went an epic (miniature epic?) walk up the Water of Leith, from Bonnington to Juniper Green. <a href="http://www.communitywalk.com/map/12213#101;3;kA010755.3^T86-3.YK2M9">This map shows the extent of the Water of Leith Walkway</a> but we didn&#8217;t cover all of it. We started near the firth outlet, about halfway between Craigleith and the docks I think, and went to Juniper Green which is one of the yellow-marked waypoints. It was probably about 8 or 9 miles in total, uphill but mostly on a very slight incline and broken up by lots of down and flat bits.</p>

<p>We passed by the <a href="http://www.waterofleith.org.uk/">Water of Leith Visitor Centre</a> (why does a river have a visitor centre? who knows) but it was closed. We saw a couple of herons like in the photo on the visitor centre website. I took <a href="http://www.usa.canon.com/consumer/controller?act=ModelInfoAct&amp;fcategoryid=144&amp;modelid=19211">my new camera</a> and spent the day playing with different settings in Manual mode, trying to get a feel for how things turn out. I&#8217;m not confident but I&#8217;m much closer than I was, and I&#8217;m enjoying it greatly.</p>

<p>When we got to Juniper Green we had tea at <a href="http://edinburghmenus.com/directory/al_borgo_eh145de/">Ristorante Al Borgo</a>, which is owned and run by the parents of one of Helen&#8217;s colleagues. After a half day walking in serious heat it was a relief to hop on the bus and get back home again.</p>

<p>But that&#8217;s not the extent of the new, exercising, Dougal. Oh no! Near to the flat is the <a href="http://www.outoftheblue.org.uk/">Out of the Blue arts centre</a>, an ex-drill hall that&#8217;s been gutted and refurbished to include studio spaces, exhibition areas, a cafe and so on. We go to regular art fairs there and I&#8217;ve often seen a poster on the wall advertising their capoeira classes. Last night I popped over to the beginners class organised by the <a href="http://www.maonochao.org/">M&atilde;o no Ch&atilde;o</a>. They were very friendly and the guest tutor was genial and enthusiastic in equal measure. The class lasted an hour longer than advertised: it should have been 8&#8211;9.30 so by the time I got home at 10.40 I was completely wiped out.</p>

<p>It was great fun though. I last did any capoeira about 8 years ago so some of the ideas seemed familiar but it&#8217;s not like falling off a bike. It can be forgotten!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougalstanton.net/blog/index.php/2010/06/30/new-active-lifestyle-available-in-five-exciting-colours/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How filtered-accumulate generalises accumulate</title>
		<link>http://www.dougalstanton.net/blog/index.php/2010/06/28/how-filtered-accumulate-generalises-accumulate/</link>
		<comments>http://www.dougalstanton.net/blog/index.php/2010/06/28/how-filtered-accumulate-generalises-accumulate/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 12:05:17 +0000</pubDate>
		<dc:creator>Dougal</dc:creator>
				<category><![CDATA[Maths & Computer Science]]></category>

		<guid isPermaLink="false">http://www.dougalstanton.net/blog/?p=1095</guid>
		<description><![CDATA[I posted a couple of days ago about one of the earlier exercises (ex1.33) in SICP. After some discussion with Brent Yorgey on Facebook I had another look at some of the definitions given in the book. Yes, if in doubt, re-read the question! :-)

The issue that needed clarified was whether I could justify treating [...]]]></description>
			<content:encoded><![CDATA[<p>I posted a couple of days ago <a href="http://www.dougalstanton.net/blog/index.php/2010/06/26/does-filter-accumulate-generalise-accumulate/">about one of the earlier exercises (ex1.33) in SICP</a>. After some discussion with <a href="http://byorgey.wordpress.com/">Brent Yorgey</a> on Facebook I had another look at some of the definitions given in the book. Yes, if in doubt, re-read the question! :-)</p>

<p>The issue that needed clarified was whether I could justify treating the <code>null-value</code> argument as a full-blown identity element. The text says:</p>

<blockquote>
  <p>a <code>null-value</code> that specifies what base value to use when the terms run out.</p>
</blockquote>

<p>(It&#8217;s worth noting that the definition of <code>combiner</code> also isn&#8217;t specified very well: a &#8220;procedure (of two arguments) that specifies how the current term is to be combined with the accumulation of the preceding terms&#8221;.)</p>

<p>This isn&#8217;t abundantly clear but it suggests that <code>null-value</code> is the last element that can be included in the calculation, so that:</p>

<p><div>
<pre>5 + 4 + 3 + 2 + 1 + 0</pre>
</div></p>

<p>is allowed but</p>

<p><div>
<pre>0 + 1 + 2 + 3 + 4 + 5</pre>
</div></p>

<p>is not allowed, because I&#8217;m starting with my <code>null-value</code> (ie, 0) and adding the remaining values to it. In this case there is no difference in result. So I needed to find a situation where some element work as an identity on the right but not on the left. Wikipedia to the rescue!</p>

<p>The number 1 as an identity element for exponents if it&#8217;s the power but not if it&#8217;s the base. Using <code>^</code> as an infix exponent function, for any <em>x</em>:</p>

<p><div>
<pre>x ^ 1 = x</pre>
</div></p>

<p>but</p>

<p><div>
<pre>1 ^ x = 1</pre>
</div></p>

<p>We can create a chain of odd-numbered exponents to test our implementations of <code>filter-accumulate</code>:</p>

<p><div>
<pre class="scheme"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>odd-exponent-chain a b<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>filtered-accumulate <span style="color: #b1b100;">odd?</span> <span style="color: #b1b100;">expt</span> <span style="color: #cc66cc;">1</span> identity a inc b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre>
</div></p>

<p>An implementation of <code>filtered-accumulate</code> which cleaves as closely as possible to the definitions should implement <code>(odd-exponent-chain 2 6)</code> as <code>(expt 3 (expt 5 1))</code>.</p>

<p>This conclusion that <code>null-value</code> only works as a right-identity has further repercussions &#8212; most of the answers published for iterative version of <code>accumulate</code> are wrong. Why?</p>

<p><div>
<pre class="scheme"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>accumulate combiner null-value term a next b<span style="color: #66cc66;">&#41;</span> 
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>go acc n<span style="color: #66cc66;">&#41;</span> 
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>&gt; n b<span style="color: #66cc66;">&#41;</span>
        acc
        <span style="color: #66cc66;">&#40;</span>go <span style="color: #66cc66;">&#40;</span>combiner acc <span style="color: #66cc66;">&#40;</span>term a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>next n<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> 
  <span style="color: #66cc66;">&#40;</span>go null-value a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre>
</div></p>

<p>The iterative versions <em>always</em> start with the <code>null-value</code> in the accumulator and slowly combine each new term until the end. But the definition above clearly states that <code>null-value</code> is to be combined with the results when there are no more terms left.</p>

<p>This is possible but not as elegant as the recursive solution by a long shot. There&#8217;s probably a good way of cleaning it up that I haven&#8217;t spotted yet.</p>

<p><div>
<pre class="scheme"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>accumulate-iter combiner null-value term a next b<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>go acc n<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>n &gt; b<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>combiner acc null-value<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>go <span style="color: #66cc66;">&#40;</span>combiner acc <span style="color: #66cc66;">&#40;</span>term n<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>next n<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>a &gt; b<span style="color: #66cc66;">&#41;</span>
      null-value
      <span style="color: #66cc66;">&#40;</span>go <span style="color: #66cc66;">&#40;</span>term a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>next a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre>
</div></p>

<p>Having got this far we realise we can no longer implement <code>filtered-accumulate</code> in terms of <code>accumulate</code>: the first term forms the seed for the accumulator whether it is appropriate or not. In this case we <em>do</em> have to create a new <code>filtered-accumulate</code> which is more powerful than <code>accumulate</code> on its own.</p>

<p><div>
<pre class="scheme"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>filtered-accumulate-iter filter combiner null-value term a next b<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>go acc n<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>n &gt; b<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>combiner acc null-value<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>go <span style="color: #66cc66;">&#40;</span>combiner acc <span style="color: #66cc66;">&#40;</span>term n<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>next n<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>start n<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>n &gt; b<span style="color: #66cc66;">&#41;</span> null-value<span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>filter n<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>go <span style="color: #66cc66;">&#40;</span>term n<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>next n<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#40;</span>start <span style="color: #66cc66;">&#40;</span>next n<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>start a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre>
</div></p>

<p>After all this it seems prudent to ask &#8220;who&#8217;s being pedantic here?&#8221; and whether the mistakes identified are the right ones.</p>

<ul>
<li>The lack of formal specification of parameters like <code>null-value</code> encourages assumptions. Most people doing these exercises assumed that <code>null-value</code> works as an identity element per the examples of (+,0) and (*,1). These examples reinforced rather than highlighted the assumptions.</li>
<li>With this assumption it is possible to implement <code>filtered-accumulate</code> in terms of <code>accumulate</code>, contra the question. I haven&#8217;t found an instance online where someone spotted this mismatch. </li>
<li>The &#8220;obvious&#8221; ways of writing the iterative and recursive <code>accumulate</code> have different semantics if you don&#8217;t pay close attention. (Which is another way of saying one of them is wrong.) Hence the problem with making poor assumptions.</li>
<li>The only way that requires a rewrite of <code>filtered-accumulate</code> is one that doesn&#8217;t assume a left-identity element.</li>
<li>There is an official tutor&#8217;s book published but not available online (presumably to prohibit cheating for universities who use this textbook). So we don&#8217;t know what the writers had in mind when they wrote that section.</li>
</ul>

<p>It&#8217;s been an interesting few days of thinking! Many thanks to Brent for making me re-examine the text and my assumptions a further time. I think we got to the bottom of it in the end.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougalstanton.net/blog/index.php/2010/06/28/how-filtered-accumulate-generalises-accumulate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Does filter-accumulate generalise accumulate?</title>
		<link>http://www.dougalstanton.net/blog/index.php/2010/06/26/does-filter-accumulate-generalise-accumulate/</link>
		<comments>http://www.dougalstanton.net/blog/index.php/2010/06/26/does-filter-accumulate-generalise-accumulate/#comments</comments>
		<pubDate>Sat, 26 Jun 2010 11:20:09 +0000</pubDate>
		<dc:creator>Dougal</dc:creator>
				<category><![CDATA[Maths & Computer Science]]></category>

		<guid isPermaLink="false">http://www.dougalstanton.net/blog/?p=1091</guid>
		<description><![CDATA[My latest interesting thought while doing the exercises in SICP is a bit confusing because the book is suggesting something which seems wrong. In Exercise 1.33, after creating a function accumulate (a kind of fold without lists where the start and end values are specified) it asks:


  You can obtain an even more general [...]]]></description>
			<content:encoded><![CDATA[<p>My latest interesting thought while doing the exercises in SICP is a bit confusing because the book is suggesting something which seems wrong. In <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-12.html#%_idx_1024" title="Exercise 1.33 of SICP, HTML version">Exercise 1.33</a>, after creating a function <code>accumulate</code> (a kind of fold without lists where the start and end values are specified) it asks:</p>

<blockquote>
  <p>You can obtain an even more general version of <code>accumulate</code> by introducing the
  notion of a <em>filter</em> on the terms to be combined. That is, combine only those
  terms derived from values in the range that satisfy a specified condition.
  The resulting <code>filtered-accumulate</code> abstraction takes the same arguments as
  accumulate, together with an additional predicate of one argument that
  specifies the filter. Write <code>filtered-accumulate</code> as a procedure.</p>
</blockquote>

<p>The tricky bit I see is the &#8220;even more general version&#8221; instruction. As far as I can tell <code>filtered-accumulate</code> can be written in terms of <code>accumulate</code>. It&#8217;s <em>not</em> more general or more powerful than the plain <code>accumulate</code>.</p>

<p>The previously-defined <code>accumulate</code> takes the following arguments:</p>

<ul>
<li>a null-value and a combiner-function (which is to say the binary operator and identity for some monoid)</li>
<li>a pair of numbers representing the start and end value in the range we want to accumulate over</li>
<li>a function which maps values in this range to values in the monoid described above (and it could be the identity)</li>
<li>a function to get to the next value in the range given the current one</li>
</ul>

<p>My (recursive) <code>accumulate</code> looks like this:</p>

<p><div>
<pre class="scheme"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>accumulate combiner null-value term a next b<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>&gt; a b<span style="color: #66cc66;">&#41;</span>
    null-value
    <span style="color: #66cc66;">&#40;</span>combiner <span style="color: #66cc66;">&#40;</span>term a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>accumulate combiner null-value term <span style="color: #66cc66;">&#40;</span>next a<span style="color: #66cc66;">&#41;</span> next b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre>
</div></p>

<p>Exercise 1.33 wants you to pre-filter values so that they don&#8217;t all get added together. Only those <code>a</code> which pass some predicate get combined into the result. But since the combining function comes specified with a null value it&#8217;s not necessary to skip over undesired results. All we need to do is convert any values which fail the test into the null value.</p>

<p>Put it this way: given a list of numbers between one and ten, you could find the sum of primes by either removing all the non-primes, or converting them into zeroes, because adding zero doesn&#8217;t affect the result. Similarly if you want the product of odd numbers between 14 and 103 you can filter out all the even numbers or turn them into 1s, because multiplying by 1 doesn&#8217;t affect the end result.</p>

<p>And it just so happens that there is <em>already</em> a way in <code>accumulate</code> to convert numbers before they are combined together, the <code>term</code> argument. This is used to square input values or apply some other function. The key argument is that this function can check if the input meets some criterion and then either process it further or replace it with <code>null-value</code>.</p>

<p><div>
<pre class="scheme"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>filtered-accumulate filter combiner null-value term a next b<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>filterterm n<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>filter n<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>term n<span style="color: #66cc66;">&#41;</span> null-value<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>accumulate combiner null-value filterterm a next b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre>
</div></p>

<p>All the solutions to this exercise that I have seen online basically re-implement the rest of <code>accumulate</code> with extra filtering. This doesn&#8217;t seem to be necessary. My implementation above works for the following two exercises (sum of squares of primes, and product of all relatively prime integers).</p>

<p>But the exercise plainly says that <code>filter-accumulate</code> is &#8220;an even more general version of <code>accumulate</code>&#8221;, which to my mind means that <code>filter-accumulate</code> should be able to produce answers which standard <code>accumulate</code> cannot. (And that <code>filter-accumulate</code> cannot be implemented in terms of <code>accumulate</code>.) What is the counter-example that I&#8217;m missing, or is the book wrong?</p>

<p>Note: I&#8217;ve starting putting my solutions for the SICP exercises online, at <a href="http://www.dougalstanton.net/code/sicp/">http://www.dougalstanton.net/code/sicp/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougalstanton.net/blog/index.php/2010/06/26/does-filter-accumulate-generalise-accumulate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A simple lab book</title>
		<link>http://www.dougalstanton.net/blog/index.php/2010/06/22/a-simple-lab-book/</link>
		<comments>http://www.dougalstanton.net/blog/index.php/2010/06/22/a-simple-lab-book/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 10:13:07 +0000</pubDate>
		<dc:creator>Dougal</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://www.dougalstanton.net/blog/?p=1084</guid>
		<description><![CDATA[At work I keep all my different tasks in separate screen sessions. Each session has a friendly name which makes sense to me, but also has a variable which captures the bug ID. There are various command line tools I interact with that require the ID so it&#8217;s easier if I set it once and [...]]]></description>
			<content:encoded><![CDATA[<p>At work I keep all my different tasks in separate <a href="http://www.gnu.org/software/screen/">screen</a> sessions. Each session has a friendly name which makes sense to me, but also has a variable which captures the bug ID. There are various command line tools I interact with that require the ID so it&#8217;s easier if I set it once and don&#8217;t need to copy-paste it in each time.</p>

<p>After seeing <a href="http://blog.nelhage.com/2010/06/lab-notebooking-for-the-software-engineer/">this post on keeping a &#8220;lab book&#8221;</a> I realised I could make extra use of this environment variable that I already used.</p>

<p>I save this file in <code>~/bin/note</code> and I can write quick scribbles to myself in whichever window I&#8217;m using and it will go to the correct &#8220;book&#8221;:</p>

<p><div>
<pre class="bash"><span style="color: #808080; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">LOGDIR=</span><span style="color: #007800;">$HOME</span>/labbook
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;&quot;</span> == <span style="color: #ff0000;">&quot;$BUGID&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span> <span style="color: #007800;">LOGFILE=</span><span style="color: #007800;">$LOGDIR</span>/GENERAL.log
<span style="color: #000000; font-weight: bold;">else</span> <span style="color: #007800;">LOGFILE=</span><span style="color: #007800;">$LOGDIR</span>/<span style="color: #007800;">$BUGID</span>.log
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;&quot;</span> == <span style="color: #ff0000;">&quot;$*&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;No log written: message empty&quot;</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #007800;">DATE=</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #c20cb9; font-weight: bold;">date</span> +%Y%m%d-%H:%M <span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #c20cb9; font-weight: bold;">mkdir</span> -p <span style="color: #007800;">$LOGDIR</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$DATE</span> $* &gt;&gt; <span style="color: #007800;">$LOGFILE</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre>
</div></p>

<p>It&#8217;s not complex but I think it will do wonders for how much I remember to document about my work from day to day.</p>

<hr />

<p>Update: I learned today the delight of this one-liner which prints everything I&#8217;ve done today in order. It&#8217;s quite pleasing.</p>

<p><div>
<pre>$ grep -h `date +%Y%m%d` labbook/* | sort</pre>
</div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougalstanton.net/blog/index.php/2010/06/22/a-simple-lab-book/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Initial thoughts on SICP study group</title>
		<link>http://www.dougalstanton.net/blog/index.php/2010/06/19/initial-thoughts-on-sicp-study-group/</link>
		<comments>http://www.dougalstanton.net/blog/index.php/2010/06/19/initial-thoughts-on-sicp-study-group/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 23:13:37 +0000</pubDate>
		<dc:creator>Dougal</dc:creator>
				<category><![CDATA[Maths & Computer Science]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.dougalstanton.net/blog/?p=1082</guid>
		<description><![CDATA[A few weeks ago I mentioned the idea of a study group at work, for the purpose of reading through some programming-relevant texts and discussing them. We&#8217;ve been working on Structure and Interpretation of Computer Programs (SICP) for a few weeks now. I&#8217;m enjoying it more than I expected. The exercises are mostly within grasp [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I mentioned the idea of a study group at work, for the purpose of reading through some programming-relevant texts and discussing them. We&#8217;ve been working on <em>Structure and Interpretation of Computer Programs</em> (SICP) for a few weeks now. I&#8217;m enjoying it more than I expected. The exercises are mostly within grasp and I&#8217;m happy to note that I&#8217;m not being left behind intellectually. There are a few mathematical proof exercises I&#8217;ve been skipping and some of the more boring &#8220;run this computation by hand&#8221; are not worth taking to completion once you&#8217;ve seen the basic point. But mostly we&#8217;re following the exercises as planned.</p>

<p>Scheme is not so interesting so far. The parentheses still bug me and we haven&#8217;t got to the stage where dynamic typing has proven useful so I&#8217;m smarting from the lack of a decent type system. From what I remember when I skimmed the book in the past most of Scheme development involves creating ad hoc type systems in the runtime. :-) Many people insist that dynamic languages are good for something so hopefully this something will become apparent.</p>

<p>I have enjoyed several of the exercises which require rewriting recursive algorithms in an iterative style. Seeing the contrast and thinking up different routes to the end product is fun, and I&#8217;m glad we&#8217;ve got a unit test framework (SchemeUnit) to help in that regard. I tried to track down a Scheme version of QuickCheck but while one used to exist it&#8217;s disappeared off the net.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougalstanton.net/blog/index.php/2010/06/19/initial-thoughts-on-sicp-study-group/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Four book medley</title>
		<link>http://www.dougalstanton.net/blog/index.php/2010/06/12/four-book-medley/</link>
		<comments>http://www.dougalstanton.net/blog/index.php/2010/06/12/four-book-medley/#comments</comments>
		<pubDate>Sat, 12 Jun 2010 12:56:37 +0000</pubDate>
		<dc:creator>Dougal</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Reviews]]></category>

		<guid isPermaLink="false">http://www.dougalstanton.net/blog/?p=1078</guid>
		<description><![CDATA[I&#8217;ve managed to get a lot of reading done in the past few weeks, so maybe it&#8217;s time to mention a few. Most of these came from the book swap group.


Measuring the Universe by Kitty Ferguson

A kind of history of geometry and cosmology, to answer the question, &#8220;how do we measure things that we can&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve managed to get a lot of reading done in the past few weeks, so maybe it&#8217;s time to mention a few. Most of these came from the book swap group.</p>

<ul>
<li><p><em>Measuring the Universe</em> by Kitty Ferguson</p>

<p>A kind of history of geometry and cosmology, to answer the question, &#8220;how do we measure things that we can&#8217;t hold a yardstick against?&#8221;. It covers the history of the ancient Hellenic philosophers who calculated the diameter of the Earth, the distance to the Moon, and so on, right up to the discovery of the size and shape of the Milky Way and the distance to the furthest reaches of the Universe. It was interesting to see how much we currently know is very modern knowledge. Before the 1920s we didn&#8217;t know there were other galaxies! I also liked learning about the contributions made by people who I&#8217;m familiar with through their namesakes &#8212; the Cassinis, the Hubbles, the Oorts.</p></li>
<li><p><em>The Steel Remains</em> by Richard Morgan</p>

<p>Richard Morgan is more known for his hard-edged post-cyberpunk science fiction. This is his first foray into &#8220;high fantasy&#8221;, the realm of dragons, gods and barbarian adventurers with big swords. This book had most of the above, including what I believe to be the first gay sword-wielding hero &#8212; a move so obvious in hindsight it is hard to believe it&#8217;s taken this long. I enjoyed the book a lot but felt the point of the villains eluded me, and the ending lacked satisfaction. More than enough sex and blood-letting to count as a Richard Morgan book though.</p></li>
<li><p><em>Wicked</em> by Gregory Maguire</p>

<p>This one took me by surprise. I suppose it&#8217;s not totally odd that book with the tagline &#8220;inspired the hit musical and sold two million copies&#8221; would be worth trying but I was still very pleased by everything that it delivered. It&#8217;s the life story of Elphaba, the Wicked Witch of the West from L Frank Baum&#8217;s <em>The Wonderful Wizard of Oz</em>. She is an outcast from the start, being born green and allergic to water, in a little rural town in Munchkinland. I felt quite caught up in the events of her life and as the events of <em>The Wonderful Wizard of Oz</em> began to overlap with <em>Wicked</em> it was quite painful, knowing that she would soon die from a bucket of water, her dreams unfulfilled and her friends tormented by the despotic Wizard. I&#8217;ve added the two sequels to my wishlist.</p></li>
<li><p><em>Dark Entries</em> by Ian Rankin and Werther Dell&#8217;Edera</p>

<p>The one book on this list which didn&#8217;t come from the book group, this is a graphic novel written by the same Ian Rankin who writes the Rebus novels. It&#8217;s a very short (I read it in an evening) John Constantine novel about a Big Brother-style reality show whose contestants are having horrifying visions. Constantine is brought in to exorcise the house or otherwise get to the bottom of the problem, though things don&#8217;t go according to plan. The drawing was strangely out-of-kilter with the story &#8212; the London graffiti with American spelling, the dialogue describing Highland Park as a whiskey-with-an-e alongside a picture of the bottle showing whisky-without-an-e. It all just seemed badly put together, and the failure to decide whether the story was darkly comic or properly horrific didn&#8217;t help. Maybe not bother.</p></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.dougalstanton.net/blog/index.php/2010/06/12/four-book-medley/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
