<?xml version="1.0" encoding="ISO-8859-1" ?> 
	                <rss version="2.0"> 
	                    <channel> 
	                        <title>Dominic Orchard's Personal and Computer Science Blog</title> 
	                        <author>Dominic Orchard</author>
	                        <link>http://dorchard.co.uk/</link> 
	                        <description>A blog of life, interests, reasearch, articles, and projects.</description> 
	                        <language>en-us</language>
			<item>
			<title>2009-07-29 - Curious: Google link colour</title> 
			<link>http://dorchard.co.uk/index.php?id=57</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<p>After this morning's first Google search, I had a feeling that something looked different, <i>glitch-in-the-Matrix</i> style. The blue colour of the links looked different to how I remembered them; the links just looked brighter, and honestly, a little tackier. 
For a moment I thought it was just my eyes or my imagination but then I looked into it.</p>

<p>Currently (for me in the UK at least) the CSS for the link colour is:
<div align='center' class='figure'>
<pre>
.link{color:#3600f4!important}
</pre>
</div>

<p>I had a bit of a search and I found <a href='http://gigaom.com/2009/07/09/when-it-comes-to-links-color-matters/'>a blog post</a> from earlier this month  stating Google uses colour <tt>#2200CC</tt> for its links. Apparently Google engineers tested a variety of hues with varying levels of blue and green and found a bluer colour encouraged users to click-through more than a slightly greener hue of blue.</p>

<p>So, let's compare the ostensible previous colour <tt>#2200CC</tt> with the one I am seeing now:
<br />
<div align='center'>
<table style='width:100px' cellspacing='6' cellpadding='6'>
<tr>
<td style='width:50px;height:50px;background:#3600f4'>
</td>
<td style='width:50px;height:50px;background:#2200CC'>
</td>
</tr>
<tr><td>#3600f4</td><td>#2200CC</td></tr>
<tr><td>New</td><td>Old</td></tr>
</table>
</div><br />

The higher level of red and blue in the new link colour creates a brighter, slightly purple hue. Perhaps Google is experimenting randomly with me to see if I click through more on this new colour? I would be interested to hear if anyone else is seeing this colour too.<br />
<blockquote>
<small>To check in Firefox go to the "View" menu, click "Page Source", and then do "Edit" -> "Find", search for "link" and you should see something like <tt>.link{color:#3600f4!important}</tt>. Then post the code for the colour. For Safari, or IE users, I don't know the procedure, but for IE I think you need to do something like right clicking and choosing "View Source".</small>
</blockquote>
</p>

<p>
Good interface design applies the concept of "affordance" to interface elements - essentially, whether an element's appearance indicates to the user how to interact with it. This concept relies on some kind of experiential world knowledge e.g. buttons are raised elements that look like they can be pushed down so that they are flush with a surface. For the frequent internet-user, the blue text of a hyperlink is part of their discourse. A blue hyperlink is highly associated to visiting a new page due to its frequent usage ever since early hypertext browsers.</p>

<p>
However, whether changing the link colour of Google search results alters the click-through rate is a different issue. People expect there to be links on the search page, so even if they were red or green I believe they would still know what to do, and click on them. Google's hypothesis then must be that the blue-ish colour stimulates a conditioned behaviour, a kind of <a href='http://en.wikipedia.org/wiki/Classical_conditioning#Pavlov.27s_experiment'>Pavlov's Dog</a> effect for blue links.</p>

<p>Either way, these slightly purple Google results just look a little too garish for me! Here's what a search looks like now for me compared to what it would look like with the old colour:<br />
<div align='center'>
<table cellspacing='10' cellpadding='3'>
<tr>
<td>
<img src='/content/google-purply-links.png'>
</td>
<td>
<img src='/content/google-bluer-links.png'>
</td>
</tr>
<tr>
<td><div align='center'>New</div>
</td>
<td><div align='center'>Old</div>
</td>
</tr>
</table>
</div><br /><br />
What's crazy is that I'm so used to the bluer links I spotted the change immediately. Time to spend more time outdoors I think....
</p>

29 July 2009 11:48:16 &nbsp - &nbsp<a href='blog.php?filter=General'>General</a> |  <a href='index.php?action=view&id=57'>Comments (6)</a>]]></description>
<pubDate>Wed, 29 Jul 2009 11:48:16 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=57#comments</comments>
	               	</item>

			<item>
			<title>2009-05-18 - Morning Bride</title> 
			<link>http://dorchard.co.uk/index.php?id=56</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<p>So last week I went to a very different, and very fun, gig at Saint Mary's Old Church in Hackney. Picture a small, beautiful, 500 year old church, with old-school pews (that are very tall and have doors!), lit with candles, and bursting with some great live music.</p>
<p>The brilliant <a href='http://www.morningbride.co.uk'>Morning Bride</a> [<a href='http://www.myspace.com/morningbride'>myspace</a>] were headlining. I have the privilege of living in the same house as their cellist, Alexa, who provided me with the motivation to go along. They played a fantastically lively and beautiful set - do check them out!
</p>
<p>
I also particularly enjoyed one of the support acts: <a href='http://www.myspace.com/gadjoform'>The Gadjo Form</a>, whose style, in their own words, "lies between traditional gypsy and east european folk". This provided for some great crazy dancing!
</p>
<p>A great show and a great night- thanks Alexa for inviting me along!</p>17 May 2009 23:08:56 &nbsp - &nbsp<a href='blog.php?filter=Music'>Music</a> |  <a href='index.php?action=view&id=56'>Comments (2)</a>]]></description>
<pubDate>Sun, 17 May 2009 23:08:56 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=56#comments</comments>
	               	</item>

			<item>
			<title>2009-05-13 - Blog split</title> 
			<link>http://dorchard.co.uk/index.php?id=55</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>The separation of life and geekdom</b><br /><br /><p>
I had the realisation the other day that I had become reluctant to post computer science blog entries at the risk of annoying any non-computer science readership, and dually had become reluctant to post personal, or miscellaneous, blog entries at the risk of diluting any computer science content. This dichotomy of reluctance resulted in little to no blogging. The solution? Two blogs.
</p>
<p>
I now have a <a href='http://dorchard.g615.co.uk/blog.php?type=7'>personal</a> blog for essentially everything, and a <a href='http://dorchard.g615.co.uk/blog.php'>computer science</a> blog for maths/computer science and research-type things. Subsequently there are also two separate feeds and a feed that combines both. The old RSS feed address points to the feed for both blogs (see the pane on the right for the choices).<br />
Hopefully now I will be encouraged to blog more, both  personal and miscellaneous items that take my interest, and on computer science. I also have the ability to make a post that goes to both blogs (like this one). Hurray!
</p>
<p>
Accompanying this split is a slight revamping of fonts and layouts, and a fixing of the older posts that had broken layouts.
</p>13 May 2009 18:30:04 &nbsp - &nbsp<a href='blog.php?filter=General'>General</a> |  <a href='index.php?action=view&id=55'>Comments (8)</a>]]></description>
<pubDate>Wed, 13 May 2009 18:30:04 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=55#comments</comments>
	               	</item>

			<item>
			<title>2009-04-29 - Easter and BCTCS '09</title> 
			<link>http://dorchard.co.uk/index.php?id=53</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<div align='justify'>
<p>Apologies for the lack of blog posts over the last few months. I've been pretty busy, but also quite lazy in writing anything on here, even if just to say that I am alive and well.
It is now the "summer" term here at Cambridge and I am hoping that it will be a productive one.
</p>
<p>I had a full and fulfilling Easter holidays: attending the <a href='http://www.cs.le.ac.uk/events/mgs2009/'>Midlands Graduate School</a> (a week long pedagogical conference aimed at graduates doing theoretical CS work with programming languages), attending <a href='http://www2.warwick.ac.uk/fac/sci/dcs/events/bctcs/'>BCTCS 2009</a> (British Colloquium for Theoretical Computer Science), briefly visiting my family, and taking a trip with friends to Germany to see our good friend Larry (fantastic).<br />
It was a brilliant way to spend 3 weeks over Easter!
</p>
<p>
BCTCS '09 was held at Warwick University- the university that I graduated from just last year and that is very dear to me! I enjoyed the conference particularly as I got to spend time with Steve Matthews and Sara Kalvala (my undergraduate project supervisors from my 3rd and 4th years), old friends from my undergraduate days, new friends from other universities, and also Bill Wadge, co-creator of Lucid, who was invited to speak at BCTCS '09 all the way from Victoria, Canada.</p>
<p>
If you have ever had a conversation with me about computer science you will know I have a particular proclivity for the Lucid programming language, so getting to chat about all things Lucid for a few days was great fun. Bill supervised Steve back when Bill was at Warwick, in the early days of Lucid. The quip is that Bill is my <i>grandsupervisor</i>. <br />
The Lucian language is my own object-oriented hybrid of Lucid. I started Lucian as my 3rd year project and dissertation- quite some time ago now. The ideas developed further after discussions with Bill back in 2007, resulting in Steve and I publishing a paper which came out last year. In January 2009, with the BCTCS looming, I thought it would be fitting to talk about Lucian at BCTCS, due to Bill and Steve being present, and BCTCS being held at Warwick, the crucible of Lucid's youth. So I revisited Lucian and discovered that there was much more to say than was originally conveyed in the paper. I mulled Lucian over last term and have since revised the language and have had some further thoughts about its semantics.
</p>
<p>
I include here the slides from the my BCTCS talk. I am planning to write a few blog posts on Lucid, Lucian, and some other ideas and thoughts that came out of discussions at BCTCS, so watch this space if you are interested.
</p>
<p>
Regular blog posting: a promise so easily made and so easily broken.
</p>
<p align='center'>
<a href='/content/lucian-bctcs09-dorchard.pdf'><img src='/content/lucian-bctcs09-dorchard.png' border='0' /></a>
</p>
</div><br /><br />28 April 2009 23:14:27 &nbsp - &nbsp<a href='blog.php?filter=Lucian'>Lucian</a> |  <a href='index.php?action=view&id=53'>Comments (9)</a>]]></description>
<pubDate>Tue, 28 Apr 2009 23:14:27 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=53#comments</comments>
	               	</item>

			<item>
			<title>2009-02-19 - Boston Globe article on computational intractability</title> 
			<link>http://dorchard.co.uk/index.php?id=52</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Something for the non-math/non-compscis out there.</b><br /><br />Over dinner last night I briefly talked about intractability and the <a href='http://en.wikipedia.org/wiki/Computational_complexity_theory#The_P_.3D_NP_question'>P=NP question</a> with a non-computer scientist friend. This morning I discovered, whilst wading through a bunch of blogs that I read intermittently, a recent news article from <i>The Boston Globe</i> that gives a nice, general introduction to the idea of computational intractability.
The article is online <a href='http://www.boston.com/news/science/articles/2009/02/09/great_unknowns/'>here</a>. Here is a quote:

<blockquote>
<span style='font-family:Times;font-size:16pt;'>"</span><i>We know answers exist, but it turns out that calculating the solutions to such kinds of problems could take too long, even if all the world's most powerful computers were to work together on them. Individual instances can be solved, but there is no general way to attack such problems efficiently, which means the "universe could have degenerated into black holes while your computer is still running," said Scott Aaronson, a theoretical computer scientist at MIT.<span style='font-family:Times;font-size:16pt;'>"</span></i></blockquote>
<br/><br />

19 February 2009 13:24:25 &nbsp - &nbsp<a href='blog.php?filter=General'>General</a> |  <a href='index.php?action=view&id=52'>Comments (1)</a>]]></description>
<pubDate>Thu, 19 Feb 2009 13:24:25 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=52#comments</comments>
	               	</item>

			<item>
			<title>2009-02-18 - The Koch Snowflake</title> 
			<link>http://dorchard.co.uk/index.php?id=51</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Construction and some properties</b><br /><br />As I mentioned a couple of weeks ago I was going to write a post about a certain fractal.
Now I have finally gotten round to writing something it has come at a very appropriate time as Britain has seen
an unusual amount of snow recently. Sadly all of that snow has melted now.
I am going to briefly introduce the <a href='http://en.wikipedia.org/wiki/Koch_snowflake'>Koch Snowflake</a> (also known as the Koch Island, or Koch Star) which is a
<a href='http://en.wikipedia.org/wiki/Fractal'>fractal</a> with a very simple construction. I will first informally describe
a geometrical construction of the fractal and will then show some of its properties, particularly the property
that the fractal has an infinite length enclosing a finite area.<br /><br />

<b>Construction</b><br />
The base case of the construction is an equilateral triangle. For each successive iteration the construction proceeds as follows:
<ul><li>Divide each edge of the polygon (say of length <i>a</i>) into three equal segments of length <i>a/3</i>.</li>
<li>Replace the middle segment with an equilateral triangle of side <i>a/3.</i></li>
<li>Remove the base edge of the new equilateral triangle to form a continuous curve with other line segments.</li></ul>

Thus each edge is transformed as such:

<div align='center'>
<img src='/content/blog/koch/geometric-construction.png'>
</div><br />

The first 5 iterations look like:

<div align='center'>
<img src='/content/blog/koch/5-iterations-small.png'>
</div>
<br />
<b>Properties</b><br />
Two properties of this fractal may seem paradoxical at first but are easily shown. I will show the derivations here for the interested without skipping too many steps. <br />
For an infinite number of iterations the perimeter of the fractal (the length of all the edges) tends to infinity whilst the area enclosed remains finite.<br /><br />

<b>Infinite Perimeter</b><br />
First consider the number of edges for an infinite number of iterations. Initially the number of edges is 3, each iteration transforms a single edge into 4 edges (see above), thus the series of the edge count is: 3, 12, 48, .... The general form is:
<br /><div align='center'>
<img src='/content/blog/koch/equation1.png'>
</div><br />
Starting from an edge length of <i>a</i> each iteration divides the edge length by 3. The following defines the edge length for iteration <i>n</i> and from this calculates the perimeter for iteration <i>n</i>. The limit as <i>n</i> tends to infinity is found, showing that the
perimeter is infinite.
<br /><div align='center'>
<img src='/content/blog/koch/equation2.png'>
</div><br />
Thus it is easy to see that the perimeter length is infinite through standard results on limits. <br /><br />
<b>Finite Area</b><br />
The area calculation is a little bit more involved. The result can be seen on <a href='http://mathworld.wolfram.com/KochSnowflake.html'>Mathworld</a> or <a href='http://en.wikipedia.org/wiki/Koch_snowflake'>Wikipedia</a> but a full derivation isn't given, so I show my derivation here for the interested.<br /><br />
The area of the n-th iteration of the Koch snowflake is the area of the base triangle + the area of the new, smaller, triangles added to each edge.
From the above length calculations and construction we know that each iteration of the construction divides the length of the edges by three. First consider the relationship between the area of a triangle of edge length <i>a</i> and a triangle of edge length <i>a/3</i><br />
<div align='center'>
<table width='100%'>
<tr>
<td width='50%'>
<div align='center'>
<img src='/content/blog/koch/triangle-scale-1.png'>
</div>
</td>
<td width='50%'>
<div align='center'>
<img src='/content/blog/koch/triangle-scale-third.png'>
</div>
</td>
</tr>
<td width='50%'>
<div align='center'>
<img src='/content/blog/koch/area-equation1.png'>
</div>
</td>
<td width='50%'>
<div align='center'>
<img src='/content/blog/koch/area-equation2.png'>
</div>
</td>
</tr></table>
</div>

Unsurprisingly we see that dividing the edge length by 3 divides the area by 9.<br />
At each iteration we add new equilateral triangles to each edge, a ninth of the area of the previous iteration's triangles. 
We formulate this as a summation of base case <i>A0</i> plus the next <i>n-1</i> iterations where the triangle area at each stage is <i>A0</i> divided by <i>3<sup>2n</sup></i> or <i>9<sup>n</sup></i> (successive divisions of the area by 9).
The number of edges is defined by the previous iterations number of edges <i>3 * 4<sup>n-1</sup></i>, thus
at the <i>n</i>-th iteration we need to add this number of triangles to the snowflake.

<div align='center'>
<img src='/content/blog/koch/equation3.png'>
</div>
<br />
Thus the area is finite at <i>8/5</i> times the area of the base equilateral triangle.
<br /><br />
<b>Summary</b><br />
So the Koch snowflake construction has been introduced and it has been shown relatively easily that the area of a Koch snowflake tends to a finite limit of <i>8/5</i> times the base case area (5) and that the length of perimeter tends to infinity (4). Next time I will probably talk a bit about the <i>fractal dimension</i> of the Koch snowflake and also show an interesting problem that uses the Koch snowflake.<br /><br />
As a last note, following on from the blog post I made about the Python turtle library, a turtle program of the Koch snowflake for Python can be <a href='/content/blog/koch/koch.py'>downloaded here</a>.<br /><br />
18 February 2009 09:35:03 &nbsp - &nbsp<a href='blog.php?filter=Maths'>Maths</a> |  <a href='index.php?action=view&id=51'>Comments (7)</a>]]></description>
<pubDate>Wed, 18 Feb 2009 09:35:03 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=51#comments</comments>
	               	</item>

			<item>
			<title>2009-01-25 - Girl with violin</title> 
			<link>http://dorchard.co.uk/index.php?id=50</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<div align='center'>
<img src='/art/girl-violing.png'>
</div>
<br /><br />25 January 2009 17:46:10 &nbsp - &nbsp<a href='blog.php?filter=Art'>Art</a> |  <a href='index.php?action=view&id=50'>Comments (4)</a>]]></description>
<pubDate>Sun, 25 Jan 2009 17:46:10 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=50#comments</comments>
	               	</item>

			<item>
			<title>2009-01-23 - Fractals with the Python turtle library</title> 
			<link>http://dorchard.co.uk/index.php?id=49</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Y-fractal</b><br /><br />This coming weekend I am planning on writing a blog post about a particular fractal (I won't give the game away just yet :p), and whilst looking around at what was written on the Internet about this fractal I stumbled across a really cool little Python library: <a href='http://docs.python.org/library/turtle.html'><i>turtle</i></a>. The <i>turtle</i> library essentially provides <a href='http://en.wikipedia.org/wiki/Logo_(programming_language)'>LOGO</a>-like functionality to Python. You get a nice turtle object on which you can call standard logo functions like <i>forward</i>, <i>left</i>, <i>right</i>, <i>pen up</i>, etc. and it draws them on a Tk widget for you - FUN!<br />
I thought I'd just share a couple of simple programs I made using the turtle library. The next post I will make about fractals will be more mathematical - this post is just for fun.<br /><br />

I show here a method of drawing Y-fractals using the turtle. The informal scheme for drawing Y-fractals is: draw a Y then at the end of each of the two top branches of the Y draw smaller Y shapes and so on... A simple way to define fractals is via  a <a href='http://en.wikipedia.org/wiki/Lindenmayer_system'>Lindenmayer system</a> which is essentially a grammar of production rules, variables, constants, and starting axioms. My Y-fractal has the following L-system properties:
<ul>
<li>Constants: <ul>
	<li>L : Turn left 45 degrees</li>
	<li>F : Move forward 100/1.6^i (where <i>i</i> is a scaling factor)</li>
	<li>S : Increment scaler i</li>
	<li>A : Turn 180 degrees</li>
	<li>T : Decrement scaler i</li>
	<li>K : Turn left 90 degrees</li></ul>
<li>Rules : A -> LFSATFKFSATFL</li>
<li>Axiom (Start) : A</li>
</ul>
The single rule "A -> LFS.." gives an ordering of constants which controls the turtle (incidentally as a quick cheat A is used here as a variable for the main rule and as a constant). Repeated rewrites of the start sequence "A" based on the rule "A -> LFS..." defines the fractal up to a particular <b>finite</b> depth. You can follow the instructions yourself on paper and see that this works. Here is the Y-fractal being drawn upto a branching depth of 5:<br /><br />
<div align='center'>
<img src='/fractals/turtle-yfractal-0.png'><br />
<small>Y-fractal with branching depth of 5 in the process of being drawn by the Python <i>turtle</i> library.</small><br /><a href='/fractals/yfractal1.py'>Download the source file for this program</a>
</div><br /><br />
The neat thing about the library is that it handles all the graphics for you, so you can just have fun. The above example is only 20 lines of code:<br /><br />

<div align='center' style='padding-left:30px;padding-right:30px;'>
<div style='background:#eee;text-align:left;padding:10px;'>
<small><pre>
import turtle

# Position the turtle
turtle.up()
turtle.goto(0,-100)
turtle.left(90)
turtle.down()

# Create description of the fractal
set="A"
for i in range(5): set=set.replace("A","LFSATFKFSATFL")

i = 1
turtle.forward(40)
for move in set:
    if move is "A": turtle.left(180)
    if move is "F": turtle.forward(100.0/1.6**i)
    if move is "L": turtle.left(45)
    if move is "K": turtle.left(90)
    if move is "S": i+=1
    if move is "T": i-=1
input()</pre></small>
</div>
</div><br /><br />

Simple! The for-loop performs the L-system rewrite 5 times to create the 5 branches of the fractal. I then took this simple program a bit further and created a program that varies the branching factor and length of branches over time, generating a set of frames that emulates a tree growing from a small sapling to a densely foliaged tree:<br /><br />

<div align='center'>
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Xdoj9VT3jPk&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Xdoj9VT3jPk&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br /><br />
</div><br /><br />
Apologies: The Youtube video is pretty blurry; <a href='/fractals/y-fractal-tree.avi'>the AVI file is slightly clearer</a> although for some reason I still lost quite a bit of clarity from the generated frames. <a href='/fractals/yfractal.py'>Here is the source file for this program</a> <small>(and the supporting script files used to <a href='/fractals/convert.sh'>convert the PS files to PNGs</a>, <a href='/fractals/frameduplicate.sh'>generate still frames for the start and end of the movie</a>, and <a href='/fractals/movie.sh'>convert from a sequence of PNGs to an AVI</a>)</small>.<br /><br />

So if you want to reminisce about the good old days of programming LOGO on your school's 286 during lunchtime then have a play with the <i>turtle</i> library, it comes with standard Python 2.4 and 2.6 installs.<br /><br />
23 January 2009 01:12:18 &nbsp - &nbsp<a href='blog.php?filter=Programming'>Programming</a> |  <a href='index.php?action=view&id=49'>Comments (3)</a>]]></description>
<pubDate>Fri, 23 Jan 2009 01:12:18 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=49#comments</comments>
	               	</item>

			<item>
			<title>2009-01-22 - Submitting to the world of instant updates....</title> 
			<link>http://dorchard.co.uk/index.php?id=48</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Twit-twoo</b><br /><br />So I finally gave in and started using that <a href='http://www.twitter.com'>Twitter</a> account that I once registered for.  I'm thinking that it could provide a further means for me to structure, and account for, my day-to-day research: what I am reading, what I am thinking about, what talks/conferences/etc. I am going to, and what I am doing. This is assuming I remember to update it.<br /><Br />


I suppose I want to do this mostly for my own benefit, but it could also provide a way of publicising computer science research for fellow computer scientists and polymaths at all levels - in academia or otherwise. Anyway... I added a Twitter widget to the right-hand pane of this site showing my latest 3 updates. <br /><br />


Hope everyone is well. Dom.<br /><Br />22 January 2009 01:03:54 &nbsp - &nbsp<a href='blog.php?filter=General'>General</a> |  <a href='index.php?action=view&id=48'>Comments (4)</a>]]></description>
<pubDate>Thu, 22 Jan 2009 01:03:54 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=48#comments</comments>
	               	</item>

			<item>
			<title>2009-01-09 - Doodle - Dr. Wikipedia</title> 
			<link>http://dorchard.co.uk/index.php?id=47</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<div align='center'>
<img src='/art/doodles/cartoon5.png'>
</div>
I know the whole "Wikipedia-joke" is a bit old - I apologise! This doodle does not come from personal experience but a conversation I once had with someone about the use of Wikipedia in medicine.
<br /><br />9 January 2009 10:05:36 &nbsp - &nbsp<a href='blog.php?filter=Doodles'>Doodles</a> |  <a href='index.php?action=view&id=47'>Comments (5)</a>]]></description>
<pubDate>Fri, 09 Jan 2009 10:05:36 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=47#comments</comments>
	               	</item>

			<item>
			<title>2008-12-24 - Doodle - Animal Farm on office safety.</title> 
			<link>http://dorchard.co.uk/index.php?id=46</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<div align='center'>
<img src='/art/doodles/cartoon4.png'>
</div>
Once again this doodle requires some prior knowledge for it even to be comprehensible, let alone funny. This time its Animal Farm by George Orwell. Sorry. Happy Christmas all!<br /><br />24 December 2008 22:10:52 &nbsp - &nbsp<a href='blog.php?filter=Doodles'>Doodles</a> |  <a href='index.php?action=view&id=46'>Comments (8)</a>]]></description>
<pubDate>Wed, 24 Dec 2008 22:10:52 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=46#comments</comments>
	               	</item>

			<item>
			<title>2008-12-15 - We by Yevgeny Zamyatin</title> 
			<link>http://dorchard.co.uk/index.php?id=45</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Book recommendation</b><br /><br /><table width='100%' cellspacing='15'>
<tr>
<td valign='top' style='text-align:justify'>
<p>
Time for another book review folks. This time it's a Russian dystopian science-fiction classic - <i>We</i> by Yevgeny Zamyatin. I discovered this book a couple of months ago when browsing a bookstore and was surprised that I had never even heard of it. I finally decided to write a quick review for anyone else who hasn't heard of it. I read the 1993 English translation by Clarence Brown. I thought it was brilliant, but having read just the one translation cannot compare it to other translations.
</p>
<p>
Written between 1920 and 1921 <i>We</i> has a history that is an interesting story in itself. It was banned from publication in Russia, due to its controversial political content, and was first published in English in New York, 1924. It wasn't until 1988, towards the end of the Soviet Union, that <i>We</i> was finally published in Russia, although a Russian version was released in America in 1952. There were <a href='http://en.wikipedia.org/wiki/We_(novel)#References'>numerous translations</a> prior to the Russian release in 1988. Author's working from illegal copies of the original manuscript took extra care to make it appear as if they had translated from another translation so as to protect Zamyatin, who was already in trouble over the appearance of foreign editions.<br />
George Orwell has acknowledged that <i>We</i> provided much inspiration for <i>1984</i>, which Orwell wrote in the late 1940s.  <i>We</i> also predates Aldous Huxley's <i>Brave New World</i>, although this was written without any knowledge of <i>We</i>.
</p>
<p>
Written in a prose poem style <i>We</i> is a set of "records" written by D-503, a mathematician of OneState, and builder of the INTEGRAL space ship. D-503's records, written in the 26th century, are addressed to future readers from a different planet and culture. OneState is a city, and a society, that has emerged after a 200 year war that wiped out the majority of mankind. To ensure the happiness of man OneState fiercely restricts the freedom of the people, controlling day to day life via "The Table"; meal times are set, work times are set, even sex is programmed. Men have become as machines and are as such happy. At the outset D-503 is completely devoted to OneState and its goals, revelling in the perfect mathematical precision and admonishing the savagery of the past. However as the records progress we see D-503's world shattered as he struggles to hold on to his devotion to OneState and is pushed to edge of his reality by involvement with a woman numbered I-330.
</p>
<p>The writing is brilliant. At times it is poetic, littered with playful metaphors, at other times it is fractured and incoherent, reflecting D-503's fevered train of thought as he questions his world. The writing style alone makes it immensly enjoyable, and the story is compelling and thought provoking. I strongly recommend this classic to anyone!
</p>
</td>
<td valign='top'>
<div align='right'>
<i>We</i></a><br />
<i>Yevgeny Zamyatin</i><br /><br />
<img src='http://ecx.images-amazon.com/images/I/51Sj13EqXgL._SL500_BO2,204,203,200,_SY240_.jpg' border='0'><br />
<span style='font-size:7pt;'>Image from Amazon.co.uk</span>
<br /><br />
Find this book on:
<ul>
<li><a href='http://www.greenmetropolis.com/search.asp?book_title=We&author_name=Zamyatin&author_first_name=&ISBN=&categories=&Format=All&scope=InStock&Results=1&search.x=49&search.y=12&search=search'>
GreenMetropolis</a></li>
<li><a href='http://www.amazon.co.uk/We-Penguin-Twentieth-Century-Classics/dp/0140185852/ref=sr_1_1?ie=UTF8&s=books&qid=1229294373&sr=8-1'>Amazon.co.uk</a></li>
<li><a href='http://www.amazon.com/We-Yevgeny-Zamyatin/dp/0140185852/ref=pd_bbs_sr_2?ie=UTF8&s=books&qid=1229294450&sr=8-2'>Amazon.com</a></li>
</ul>
</div>
</td></tr></table><br /><br />
15 December 2008 00:33:28 &nbsp - &nbsp<a href='blog.php?filter=Books'>Books</a> |  <a href='index.php?action=view&id=45'>Comments (10)</a>]]></description>
<pubDate>Mon, 15 Dec 2008 00:33:28 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=45#comments</comments>
	               	</item>

			<item>
			<title>2008-12-09 - OpenCL 1.0 Specification released</title> 
			<link>http://dorchard.co.uk/index.php?id=44</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Some thoughts...</b><br /><br /><div style='text-align:justify'>
Yesterday the specification for <a href='http://www.khronos.org/registry/cl/'>OpenCL 1.0  was released</a>. For those who don't
know what OpenCL is here is a summary quote from the specification:

<blockquote>
"<i>OpenCL is an open industry standard for programming a heterogeneous collection of CPUs,
GPUs and other discrete computing devices organized into a single platform. It is more than a
language. OpenCL is a framework for parallel programming and includes a language, API,
libraries and a runtime system to support software development. Using OpenCL, for example, a
programmer can write general purpose programs that execute on GPUs without the need to map
their algorithms onto a 3D graphics API such as OpenGL or DirectX.</i>" <cite>[p. 18]</cite>
</blockquote>

A worthy goal. But is OpenCL designed for use by anyone?

<blockquote>
"<i>The target of OpenCL is expert programmers wanting to write portable yet efficient code. This
includes library writers, middleware vendors, and performance oriented application
programmers. Therefore OpenCL provides a low-level hardware abstraction plus a framework to
support programming and many details of the underlying hardware are exposed.</i>" <cite>[p. 18]</cite></blockquote>

What about the general scientific computing community? Do we expect them to be expert programmers
or have expert programmers on hand to write their simulations?<br />
While OpenCL addresses the expression of low-level programs for compilation to heterogeneous architectures it does not solve the human-tractability issues of manual parallel programming: it is complex, lengthy, tedious, error prone, and difficult to prove.<br />
OpenCL is not all things to all men/women. It does however provide a possible intermediate language for higher-level languages that abstract over low-level concurrency/parallel concepts.<br /><br />

An interesting issue, that the specification picks up on, is that heterogeneity makes portability
 difficult when to porting code between a CPU and a GPU (as opposed to between different types of CPUs and different types of GPUs).

<blockquote>
"<i>Unfortunately, there are a number of areas where idiosyncrasies of one hardware platform may
allow it to do some things that do not work on another. </i>" <cite>[p. 208]</cite>
</blockquote>

<blockquote>
"<i>Likewise, the heterogeneity of computing architectures might mean that a particular loop
construct might execute at an acceptable speed on the CPU but very poorly on a GPU, for
example. CPUs are designed in general to work well on latency sensitive algorithms on single
threaded tasks, whereas common GPUs may encounter extremely long latencies, potentially
orders of magnitude worse. A developer interested in writing portable code may find that it is
necessary to test his design on a diversity of hardware designs to make sure that key algorithms
are structured in a way that works well on a diversity of hardware. We suggest favoring more
work-items over fewer. It is anticipated that over the coming months and years experience will
produce a set of best practices that will help foster a uniformly favorable experience on a
diversity of computing devices.</i>" <cite>[p. 208]</cite>
</blockquote>

This doesn't sound like the behaviour of a language with which people want to write "portable yet efficient code." <cite>[p. 18]</cite>, but it is not the fault of OpenCL. This particular lack of portability is a necessary symptom of the low-level nature of the language. In OpenCL a loop is a loop.
How can this be solved? Ideally we don't want our programmers to have to modify their algorithms to suit a set of possible hardware. Ideally algorithms and implementation should be separated by layers of specialization.<br />
A more abstract language may describe a loop that has a semantically equivalent efficient interpretation for a GPU and a standard efficient interpretation for the CPU.
However, it is not desirable that a compiler perform significant transformations unbeknownst to the programmer, as this affects the programmer's (tacit or otherwise) cost-model for the language.<br />
Perhaps specializations should be expressed by the programmer (up to a point) via a multi-tiered approach to programming languages? Who knows! I'm just waving my hands in my head now and am going home for some tea. Check out the OpenCL project if you are interested.<br />
Bye.
</div>9 December 2008 20:27:06 &nbsp - &nbsp<a href='blog.php?filter=Programming'>Programming</a> |  <a href='index.php?action=view&id=44'>Comments (14)</a>]]></description>
<pubDate>Tue, 09 Dec 2008 20:27:06 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=44#comments</comments>
	               	</item>

			<item>
			<title>2008-11-23 - Einstein and Eddington</title> 
			<link>http://dorchard.co.uk/index.php?id=43</link>
			<author>Dominic Orchard</author>
<description><![CDATA[I just watched a brilliant drama on the BBC entitled <i>Einstein and Eddington</i> telling the story of Albert Einstein's formulation of General Relativity and its confirmation by British scientist Arthur Stanley Eddington around the time of World War 1. Plenty of details are elided and I am sure certain aspects are not entirely factually accurate but nevertheless this is a very interesting, wonderfully acted, and engaging portrayal of both scientists and their respective struggles against their peers in a politically charged climate.<br /><br />

<a href='http://www.bbc.co.uk/programmes/b00ft62c'>Watch it on the BBC iPlayer if you can!</a><br /><br />23 November 2008 14:16:55 &nbsp - &nbsp<a href='blog.php?filter=Science'>Science</a> |  <a href='index.php?action=view&id=43'>Comments (11)</a>]]></description>
<pubDate>Sun, 23 Nov 2008 14:16:55 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=43#comments</comments>
	               	</item>

			<item>
			<title>2008-11-08 - Another busy week...!</title> 
			<link>http://dorchard.co.uk/index.php?id=42</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<p>
It's been another crazy (but very enjoyable) week for me. Tuesday was of course the night of the US election. I nearly went to bed as I'd been at a formal dinner with all the computer science students at my college and then to the cinema to see <a href='http://www.imdb.com/title/tt0830515/'>Quantum of Solace</a> (which I highly recommend by the way). So by the time I got home at about 12:30am I thought I might just go to bed, then I came to my senses are realised that it would be great to witness this historical election live and to share in the experience with my friends. So I went down to the Cambridge Union with some friends and stayed up until Obama's acceptance speech -around 5am for us! There were so many students down at the Cambridge Union all night- joining in, cheering, and celebrating the final outcome. It was great to be part of it! I attemped to take a photo from the balcony with my phone, sadly it was too dark for my phone to capture the scene properly.
</p>

<div align='center'>
<a href="http://www.flickr.com/photos/30584343@N04/3012877688/" title="Cambridge Union: 2008 US Presidential Election by d.orchard, on Flickr"><img src="http://farm4.static.flickr.com/3030/3012877688_4739e0e5f9.jpg" width="500" height="375" alt="Cambridge Union: 2008 US Presidential Election" /></a>
</div>
<br /><br />

<p>
This week it seems I have done more talking and discussing than reading- but that's probably not the end of the world as some nice ideas have been forming about <a href='http://en.wikipedia.org/wiki/Structured_grid'>structured grid</a> programming this week- especially yesterday- but I won't divulge anymore at the moment.<br />One thing I have noticed recently is that every week I somehow end up having a conversation with someone about <a href='http://en.wikipedia.org/wiki/Lucid_(programming_language)'>Lucid</a> or <a href='http://www.springerlink.com/content/6hw05471029434h8/'>my work with Lucid</a>. It seems that there are still a few people around who are interested in this gem of a language!
</p>

<p>
On another note: I have removed the doodles from this blog and moved them into <a href='http://dorchard.g615.co.uk/blog.php?type=6'>their own section</a> in an attempt to keep my blog a bit more serious and free from my unfunny and bizarre doodles! I have posted a <a href='http://dorchard.g615.co.uk/blog.php?type=6'>new doodle</a> this weekend. <br />See you all later, Dominic.
</p><br />

8 November 2008 14:01:30 &nbsp - &nbsp<a href='blog.php?filter=General'>General</a> |  <a href='index.php?action=view&id=42'>Comments (3)</a>]]></description>
<pubDate>Sat, 08 Nov 2008 14:01:30 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=42#comments</comments>
	               	</item>

			<item>
			<title>2008-11-08 - Doodle - That's what she said...!</title> 
			<link>http://dorchard.co.uk/index.php?id=41</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<div align='center'><img src='http://dorchard.g615.co.uk/art/doodles/cartoon3-finished-scaled.png'>
</div>
The inspiration for this weekend's strip comes from a hilarious conversation had between Chris, Gregg, Max, Milos, and I during happy hour in the Computing Lab last night.<br />
Again apologies: this edition is probably the MOST obscure so far- sorry!<br /><br />8 November 2008 13:21:34 &nbsp - &nbsp<a href='blog.php?filter=Doodles'>Doodles</a> |  <a href='index.php?action=view&id=41'>Comments (3)</a>]]></description>
<pubDate>Sat, 08 Nov 2008 13:21:34 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=41#comments</comments>
	               	</item>

			<item>
			<title>2008-11-01 - Doodle - Venn Diagrams</title> 
			<link>http://dorchard.co.uk/index.php?id=40</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>(Walking \cap Social Engineering) = Tailgating</b><br /><br /><div align='center'><img src='/art/doodles/cartoon-2-final-scaled.png'>
</div>
This little doodle is based on a bizarre late night conversation between James Willmoth and I. Hope you like it Jim!<br /><br />1 November 2008 13:13:29 &nbsp - &nbsp<a href='blog.php?filter=Doodles'>Doodles</a> |  <a href='index.php?action=view&id=40'>Comments (2)</a>]]></description>
<pubDate>Sat, 01 Nov 2008 13:13:29 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=40#comments</comments>
	               	</item>

			<item>
			<title>2008-10-30 - Why C and FORTRAN and not Haskell?</title> 
			<link>http://dorchard.co.uk/index.php?id=39</link>
			<author>Dominic Orchard</author>
<description><![CDATA[Yesterday I attended the <a href='http://www.many-core.group.cam.ac.uk/'>Many-core Computing workshop</a> at Cambridge organised by a group of researchers at Cambridge University who are using many-core devices (such as GPUs) to accelerate their scientific applications. There were a few nice presentations showing the latest techniques that people are employing for fast computation using hardware such as the <a href='http://en.wikipedia.org/wiki/GeForce_8_Series'>NVidia Geforce 8 Series</a> and <a href='http://en.wikipedia.org/wiki/GeForce_8_Series'>9 Series</a> cards, and using tools such as <a href='http://en.wikipedia.org/wiki/CUDA'>CUDA</a>, writing  simulations in C.<Br />
I went along as my current main research interest is the development of compilers, language extensions, and languages for parallel programming- especially those targeted at many-core architectures. I am very interested in the <a href=http://www.haskell.org/haskellwiki/GHC/Data_Parallel_Haskell'>Data Parallel Haskell</a> extension for GHC, which facilitates data parallell programming in Haskell. There is a good chance I will be devoting a reasonable amount of time to this system in my research, hence at the workshop I spent a lot of time thinking, "How can we get these guys using Haskell?" and "Would these guys EVER use Haskell?" The workshop made me see how attached the scientific community are to C (and sometimes to FORTRAN), and I've been trying to ascertain why? Any suggestions? Here are some possibilities:
<ul>
<li>They were brought up, or educated, using procedural/imperative languages.</li>
<li>There are extensive libraries available for C.</li>
<li>There is a very short learning time to using these languages.</li>
<li>They like the constructs- the array handling, re-assignment, statements, side effects, and global variables?</li>
<li><b>Imperative semantics and constructs fit our default mental model of the world better than those of  functional programming?</b> [Is this true... maybe...]</li>
</ul>
Or all of the above? I had a really interesting conversation with Nick Maclaren at the workshop about various languages topics and how people like FORTRAN because of the first-class arrays and overloaded arithmetic operators for arrays. Maybe we need to make our functional array syntax and constructs better!<br /><br />
Anyway... so apart from these things I had a silly idea the other day for a humorous little comic and just quickly doodled it out. I will post this in a separate post that will appear below:<Br /><br />30 October 2008 19:51:06 &nbsp - &nbsp<a href='blog.php?filter=Languages'>Languages</a> |  <a href='index.php?action=view&id=39'>Comments (3)</a>]]></description>
<pubDate>Thu, 30 Oct 2008 19:51:06 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=39#comments</comments>
	               	</item>

			<item>
			<title>2008-10-30 - Doodle - PeArl and CamEl</title> 
			<link>http://dorchard.co.uk/index.php?id=38</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Revenge of the vowels</b><br /><br /><div align='center'>
<img src='/art/doodles/cartoon-1-scaled-finished.png'>
</div><br />
I almost did a "sea" joke... aren't you glad I didn't!<br />
For the non-computer geeks out there: there are two reasonably popular programming languages called <a href='http://en.wikipedia.org/wiki/Perl'>Perl</a> and <a href='http://en.wikipedia.org/wiki/Caml'>Caml</a>. The "fun ride x = ... " is a fragment of possible Caml code. Now you get it!!! I did actually see the word "pearl" in type the other day and thought to myself momentarily, "That's an odd spelling... oh.", and subsequently realised how much of a geek I am.<br /><br />30 October 2008 19:37:28 &nbsp - &nbsp<a href='blog.php?filter=Doodles'>Doodles</a> |  <a href='index.php?action=view&id=38'>Comments (8)</a>]]></description>
<pubDate>Thu, 30 Oct 2008 19:37:28 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=38#comments</comments>
	               	</item>

			<item>
			<title>2008-10-25 - Catastases</title> 
			<link>http://dorchard.co.uk/index.php?id=37</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>3 weeks of PhD done so far.</b><br /><br /><div align='center'>
<img src='http://dorchard.co.uk/art/doodles/catastases-sized.png'>
</div><br /><br />
So I have been doing my PhD for 3 weeks now and am really enjoying it. It's a great feeling to finally get to read and enjoy all the things I have been keeping on the back-burner until now.<br /><br />
At Cambridge there are so many great opportunities to meet some very smart people and to attend some really excellent talks on a range of topics. I may at some point post some links to some of the research topics I have been reading and hearing about in the last 3 weeks. So much stuff to learn- so little time!<br /><br />
This doodle is an approximation of me at my desk.. thinking about the construction of <a href='http://en.wikibooks.org/wiki/Haskell/Existentially_quantified_types'>existential types</a> in Haskell via the "forall" type quantifier - and  the Curry-Howard isomorphism proof of its construction [forall a. (a -> K) = (exists a . a) -> K].<br /><br />24 October 2008 23:51:12 &nbsp - &nbsp<a href='blog.php?filter=Doodles'>Doodles</a> |  <a href='index.php?action=view&id=37'>Comments (4)</a>]]></description>
<pubDate>Fri, 24 Oct 2008 23:51:12 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=37#comments</comments>
	               	</item>

			<item>
			<title>2008-10-02 - Diaspora by Greg Egan</title> 
			<link>http://dorchard.co.uk/index.php?id=36</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Book recommendation</b><br /><br /><table width='100%' cellspacing='10'>
<tr>
<td valign='top'>
This brilliant <a href='http://en.wikipedia.org/wiki/Hard_science_fiction'>hard science fiction</a> novel by Greg Egan is as much gripping as it is intelligent and thought-provoking. Egan combines <a href='http://en.wikipedia.org/wiki/Transhumanism'>transhumanism</a>, consciousness,  <a href='http://en.wikipedia.org/wiki/Multiverse'>multiverses</a>, <a href='http://en.wikipedia.org/wiki/String_theory#Extra_dimensions'>extra-dimensional theory</a>, <a href='http://en.wikipedia.org/wiki/Wormholes'>wormholes</a>, <a href='http://en.wikipedia.org/wiki/Astrobiology'>astrobiology</a>, <a href='http://en.wikipedia.org/wiki/Principle_of_Computational_Equivalence#Principle_of_computational_equivalence_2'>computational equivalence</a>, and much more, into a rivetting tale of the human race's search for immortality. The book begins in the year 2975. The human race has split into three factions: <i>fleshers</i>- what is left of homo sapiens, <i>Gleisner robots</i>- simulated human brains running inside of humanoid robots, and <i>polises</i>- supercomputers hosting millions of consciousnesses, free from any physical restrictions within their own simulated worlds and free from death- or so they think. The book follows a group of polis inhabitants, particularly Yatima, an orphan born inside the Konishi polis. Roughly twenty years after Yatima's birth it is discovered that a local <a href='http://en.wikipedia.org/wiki/Binary_stars'>binary star</a> is collapsing inexplicably faster than the known physics should dictate, the eventual collapse of which causes a gamma ray burst destroying much of Earth's surface life. The polises (and Gleisner robots) survive. One such surviving polis embark on a mission to understand what has happened and to prevent something as bad, or worse, happening again. The diaspora occurs when the polis make a thousand clones of itself and many of its citizens, sending them off into the universe to find answers. This book takes you on a vast journey leaving you feeling like you've travelled billions of light years in your own understanding to get where you are. The interactions between humans and the polis citizens is particularly interesting, as well as the clever use of extrapolated physics from the current theories and ideas of our time. Another interesting quirk of the book is that Egan uses <a href='http://en.wikipedia.org/wiki/Gender-neutral_pronoun'>gender-neutral pronouns</a> for the polis members who have opted to have a neutral gender. Definitely worth a read!
</td>
<td valign='top'>
<div align='right'>
<a href='http://www.amazon.co.uk/Diaspora-Greg-Egan/dp/0752809253/ref=sr_1_1?ie=UTF8&s=books&qid=1222958259&sr=8-1'><i>Diaspora</i></a><br />
<i>Greg Egan</i><br /><br />
<img src='http://ecx.images-amazon.com/images/I/51QC8J9VE0L._SL500_BO2,204,203,200,_SY240_.jpg' border='0'><br />
<span style='font-size:7pt;'>Image from Amazon.co.uk</span>
<br /><br />
Find this book on:
<ul>
<li><a href='http://www.greenmetropolis.com/search.asp?book_title=Diaspora&author_name=Egan&author_first_name=Greg&ISBN=&categories=&Format=All&scope=InStock&Results=1&search.x=0&search.y=0&search=search'>GreenMetropolis</a></li>
<li><a href='http://www.amazon.co.uk/Diaspora-Greg-Egan/dp/0752809253/ref=sr_1_1?ie=UTF8&s=books&qid=1222958259&sr=8-1'>Amazon.co.uk</a></li>
<li><a href='http://www.amazon.com/Diaspora-Greg-Egan/dp/0061052817/ref=sr_1_2?ie=UTF8&s=books&qid=1222958472&sr=8-2'>Amazon.com</a></li>
</ul>
</div>
</td></tr></table><br /><br />
2 October 2008 15:39:48 &nbsp - &nbsp<a href='blog.php?filter=Books'>Books</a> |  <a href='index.php?action=view&id=36'>Comments (5)</a>]]></description>
<pubDate>Thu, 02 Oct 2008 15:39:48 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=36#comments</comments>
	               	</item>

			<item>
			<title>2008-09-30 - Cambridge etc.</title> 
			<link>http://dorchard.co.uk/index.php?id=35</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Falling share prices: Even log scale graphs can't make it look good.</b><br /><br />Just a quick update of what's going on for me at the moment. I moved to Cambridge last Thursday and have until the 6<sup>th</sup> of October before I start in my department so I am just getting settled in, meeting new people, enjoying the city of Cambridge, and doing some occasional reading. I am at <a href='http://www.jesus.cam.ac.uk/'>Jesus College</a> but live just outside the college in a nice house with a *load* of other grad students. Its near the river, Jesus Green, and Midsummer Common, providing extra motivation to go for morning runs!<br />
We have a really nice library at the college which is providing me with a wealth of maths and science books I want to look at. Maybe I will form some posts around some of the things I am reading if I get time to read and think more.<br/><br />
This week we see <a href='http://news.bbc.co.uk/1/hi/business/7641193.stm'>Bradford & Bingley's nationalisation confirmed</a> after a spectacular share price descent:<br /><br />
<div align='center'>
<img src='http://ichart.europe.yahoo.com/c/1y/b/bb.l'>
</div><br /><br />
Fortunately <a href='http://www.phdcomics.com'>PHD comics</a> have calmed any sense of panic for me with their <a href='http://www.phdcomics.com/comics.php?f=1077'>informative and well constructed decision tree</a>... hurray for being a grad student.<br /><br />30 September 2008 11:53:53 &nbsp - &nbsp<a href='blog.php?filter=General'>General</a> |  <a href='index.php?action=view&id=35'>Comments (7)</a>]]></description>
<pubDate>Tue, 30 Sep 2008 11:53:53 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=35#comments</comments>
	               	</item>

			<item>
			<title>2008-09-24 - Essay on 3 Emerging Technologies</title> 
			<link>http://dorchard.co.uk/index.php?id=33</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Essay + domain</b><br /><br />I have decided to post an essay I wrote last year that outlines three emerging technologies in the fields of nanohealing, solar energy and neuron control. I really enjoyed researching these topics - which were featured in the <a href='http://www.technologyreview.com/Infotech/18333/?a=f'>2007 MIT Technology Review of 10 Emerging Technologies</a> - and found each technology, and the underpinning science, very interesting. I decided to post the essay here if anyone is interested. <a href='http://dorchard.g615.co.uk/content/dorchard-emerging-technologies.pdf'>Download the PDF</a> or read it online courtesy of <a href='http://www.pdfmenot.com'>PdfMeNot.com</a>:<br /><br />

<div align='center'>
<script type="text/javascript" src="http://pdfmenot.com/embed/?url=http://dorchard.g615.co.uk/content/dorchard-emerging-technologies.pdf&width=500&height=600"></script>
</div><br /><br />
In other news I have purchased <a href='http://dorchard.co.uk'>http://dorchard.co.uk</a> which points here (I have also switched from the riftor subdomain to dorchard subdomain on G615). Apologies to the select few of you who are subscribed to my RSS feed- I changed the addressess in the feed so now all posts will probably appear as unread. Sorry for the inconvenience!<br />
My next post will probably be from Cambridge as I move in 2 days time!<br /><Br />23 September 2008 23:19:11 &nbsp - &nbsp<a href='blog.php?filter=Science'>Science</a> |  <a href='index.php?action=view&id=33'>Comments (5)</a>]]></description>
<pubDate>Tue, 23 Sep 2008 23:19:11 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=33#comments</comments>
	               	</item>

			<item>
			<title>2008-09-19 - Yarr me hearties!</title> 
			<link>http://dorchard.co.uk/index.php?id=31</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Happy International Talk Like  a Pirate Day</b><br /><br />Ahoy! <a href='http://en.wikipedia.org/wiki/Talk_like_a_pirate_day'>Happy International Talk Like a Pirate Day</a> (shouldn't that be hyphenated?). For all those <a href='http://www.facebook.com'>Facebook</a> users, if ye want some midday mirth you can change your Facebook account language to "English (Pirate)". <br />
Examples are: "Home" -> <i>"Home Port"</i>, "Friends" -> <i>"Me Hearties"</i>, "Messages" -> <i>"Bottle o' Messages"</i>, "Search" -> <i>"Scour"</i>, "Logout" -> <i>"Abandon Ship"</i>, and my favourite "video" -> <i>"possessed portrait"</i>!<br /><br />
This is Cap'n Orchard Abandoning Ship to do something else productive....<br /><br />
p.s. In the spirit of all things Pirate - this is a hilarious <a href='http://www.snorgtees.com/pirateencyclopedia-p-353.html'> Smorgtees</a> t-shirt design of <a href='http://www.snorgtees.com/images/PirateEncyclopedia_Fullpic_1.gif'>a Pirate Encyclopedia</a>. Arrr!!!<br /><br />19 September 2008 11:57:26 &nbsp - &nbsp<a href='blog.php?filter=General'>General</a> |  <a href='index.php?action=view&id=31'>Comments (4)</a>]]></description>
<pubDate>Fri, 19 Sep 2008 11:57:26 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=31#comments</comments>
	               	</item>

			<item>
			<title>2008-09-17 - My trip to Brussels</title> 
			<link>http://dorchard.co.uk/index.php?id=30</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Photos from my trip to Brussels</b><br /><br />Recently I went on a fun trip to Brussels to basically soak in the culture for a few days. It was great fun- my friend and I serendipitously visited during the national beer festival which provided us with large amounts of Belgian specialty beers. Here are a few of the photos from the trip:

<style type="text/css">
#flickr_badge_source_txt {padding:0; font: 11px Arial, Helvetica, Sans serif; color:#666666;}
#flickr_badge_icon {display:block !important; margin:0 !important; border: 1px solid rgb(0, 0, 0) !important;}
#flickr_icon_td {padding:0 5px 0 0 !important;}
.flickr_badge_image {text-align:center !important;}
.flickr_badge_image img {border: 1px solid black !important;}
#flickr_www {display:block; text-align:left; padding:0 10px 0 10px !important; font: 11px Arial, Helvetica, Sans serif !important; color:#3993ff !important;}
#flickr_badge_uber_wrapper a:hover,
#flickr_badge_uber_wrapper a:link,
#flickr_badge_uber_wrapper a:active,
#flickr_badge_uber_wrapper a:visited {text-decoration:none !important; background:inherit !important;color:#3993ff;}
#flickr_badge_wrapper {background-color:#eee;}
#flickr_badge_source {padding:0 !important; font: 11px Arial, Helvetica, Sans serif !important; color:#666666 !important;}
</style>
<table id="flickr_badge_uber_wrapper" cellpadding="0" cellspacing="10" border="0"><tr><td><a href="http://www.flickr.com" id="flickr_www">www.<strong style="color:#3993ff">flick<span style="color:#ff1c92">r</span></strong>.com</a><table cellpadding="0" cellspacing="10" border="0" id="flickr_badge_wrapper">
<tr>
<script type="text/javascript" src="http://www.flickr.com/badge_code_v2.gne?show_name=1&count=3&display=random&size=t&layout=h&source=user_tag&user=30584343%40N04&tag=Brussels"></script>
<td id="flickr_badge_source" valign="center" align="center">
<table cellpadding="0" cellspacing="0" border="0"><tr>
<td width="10" id="flickr_icon_td"><a href="http://www.flickr.com/photos/30584343@N04/tags/Brussels/"><img id="flickr_badge_icon" alt="d.orchard's items tagged with Brussels" src="http://l.yimg.com/g/images/buddyicon.jpg#30584343@N04" align="left" width="48" height="48"></a></td>
<td id="flickr_badge_source_txt"><nobr>More of</nobr> <a href="http://www.flickr.com/photos/30584343@N04/tags/Brussels/">d.orchard's stuff tagged with Brussels</a></td>
</tr></table>
</td>
</tr>
</table>
</td></tr></table>


We stayed in a relatively nice hostel in the north of the city, just a short 10 minute walk from the centre. We walked round lots, enjoyed an art gallery, enjoyed the flea market, and of course waffles, chocolate, mussels, and beer.<br />
Here is a video I cut together from some of my footage of the Dexia Tower in Brussels, a tower whose windows are individually illuminated by flourescent tube lights turning the building into a giant pixel array.<br /><br />

<div align='center'>
<object width="283" height="233"> <param name="movie" value="http://www.youtube.com/v/x4kryeSfUHI"> </param> <embed src="http://www.youtube.com/v/x4kryeSfUHI" type="application/x-shockwave-flash" width="283" height="233"> </embed> </object>
</div><br /><br />17 September 2008 13:10:50 &nbsp - &nbsp<a href='blog.php?filter=Travel'>Travel</a> |  <a href='index.php?action=view&id=30'>Comments (2)</a>]]></description>
<pubDate>Wed, 17 Sep 2008 13:10:50 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=30#comments</comments>
	               	</item>

			<item>
			<title>2008-09-15 - Drawing/Colouring Comic Book Style</title> 
			<link>http://dorchard.co.uk/index.php?id=29</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>A time lapse</b><br /><br /><div align='center'>
<object width="425" height="350"> <param name="movie" value="http://www.youtube.com/v/uCzSNvI571M"> </param> <embed src="http://www.youtube.com/v/uCzSNvI571M" type="application/x-shockwave-flash" width="425" height="350"> </embed> </object>
</div><br />
A time-lapse of me doing a bit of comic book drawing for fun. The drawings and concepts are copied from the Amory Wars comic book series.<a href='blog.php?filter=Video'>Video</a> |  <a href='index.php?action=view&id=29'>Comments (4)</a>]]></description>
<pubDate>Mon, 15 Sep 2008 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=29#comments</comments>
	               	</item>

			<item>
			<title>2008-07-14 - Degree: over.</title> 
			<link>http://dorchard.co.uk/index.php?id=28</link>
			<author>Dominic Orchard</author>
<description><![CDATA[So yet again its been an inordinate amount of time since my last blog post; <i>why am I so bad at this?</i> Nevermind. Maybe now that I am on holiday I can update a bit more.<br /><br />

I have now completed my final year at Warwick and will be graduating tomorrow with an MEng in Computer Science with First class honours- assuming I don't get arrested in the next 24 hours and have my degree revoked- not that I think this will happen!<br />
I received my exam results a couple of weeks ago. This year went very well for me and was probably my most consistent year- the standard deviation of my marks per module was lowest this year. I received the award for the "Best overall graduating MEng student in Computer Science for 2008", which I am very pleased about. And now it is all over, culminating in my formal graduation ceremony tomorrow in the Butterworth Hall at the Warwick Arts Center.<br /><br />


I feel extremely fortunate to have gone to such a fine institution and studied in a great department with wonderful people. This last year has been extremely enjoyable- despite also being the most demanding year of my life, with a lot of very late nights and all-nighters. I hope to write about some of the results of the 4th year group project I took part in, which was probably the most enjoyable part of the year for me (academically).<br />
Besides academic enjoyment I treasure everything about my Warwick experience: the friends I've made, the fun we had, growing in my faith as a Christian- in my church and in the Christian Union, parties, making music with friends, dancing, late night chats, early starts, crazy trips to Tescos late at night, shared meals, morning saunas, Monday fried breakfasts. Everything. I've met some of the most wonderful people at university, and for that I am ever thankful!<br /><br />


There is far too much to say about how this year has been for me, so perhaps I will leave some of it for another time. However, I will say that over this last academic year I have begun to dip my toe into the pool of academic research. During the Autumn of 2007 I wrote a paper detailing my work on the integration of object-oriented programming and the dataflow paradigm, specifically my language Lucian, and the notion of <i>intensional objects</i> [more on this later]. The process of writing the paper was extremely valuable. I was able to crystallise my ideas, as well as get a taste of academic writing. My 3rd year supervisor Steve Matthews co-authored the paper- contributing many ideas to the research, spending large amounts of time with me chatting about ideas, scribbling on white boards, and reading through many drafts and revisions. Sara Kalvala was also extremely kind, reading through drafts and giving me advice on writing. The paper went through the first round of reviews and got accepted on the proviso I made some revisions and clarifications. This process was also extremely beneficial. By this point I had learnt a lot more about writing, and had crystallised some ideas even further- and so was able to rework the paper and improve its clarity.<br/>
These were all valuable experiences.<br /><br />

Back in February I attended <a href='http://sneezy.cs.nott.ac.uk/fun/'>Fun in the Afternoon</a> which I thoroughly enjoyed and which gave me a further view into the Functional programming research community.<br /><br />

During this year there has been an unofficial "language club" in our department, where a group of programming language enthusiasts in the department- staff and students- have been getting together weekly to discuss papers, and give informal presentations. The "language club" was birthed to fill the hole left by the (current) lack of a programming languages research group at Warwick. It is a great idea and has provided a nice forum for chatting about programming language research.<br /><br />

And then finally I spent a lot of time during the second term thinking about PhD proposals, reading a lot of papers, having ideas, and eventually writing a couple of proposals to submit with PhD applications. My applications were successful thus in September I am going to be starting my PhD at Cambridge University, as a member of Jesus College. I am very excited!<br /><br />

I'm glad I stayed at Warwick for another year, not only did I have a lot of fun, and learn a lot, but it provided me with a lot more opportunities to get into the 'research' mindset, and gave me time to get PhD applications and proposals together- which was not an easy process.<br /><br />

Currently I am on holiday till September when I move to Cambridge. Tomorrow is my graduation from Warwick. I will post some photos up soon after I get back from visiting friends around England and my friend's wedding.<a href='blog.php?filter=General'>General</a> |  <a href='index.php?action=view&id=28'>Comments (3)</a>]]></description>
<pubDate>Mon, 14 Jul 2008 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=28#comments</comments>
	               	</item>

			<item>
			<title>2008-02-16 - Book recommendation</title> 
			<link>http://dorchard.co.uk/index.php?id=26</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<table width='100%' cellspacing='10'>
<tr>
<td valign='top'>
<div align='right'>
<a href='http://www.amazon.co.uk/Elements-Style-William-Jr-Strunk/dp/0143112724/ref=pd_bbs_sr_2?ie=UTF8&s=books&qid=1203164841&sr=8-2'><i>The Elements Of Style</i> (illustrated)</a><br />
<i>Strunk, White, Kalman</i><br /><br />
A great book that plainly and concisely explains the basic principles of English and how to apply them in writing.</div>
</td>
<td>
<div align='right'>
<img src='http://ecx.images-amazon.com/images/I/41OEzVLbZLL._BO3,204,203,200_SY240.jpg' border='0'><br />
<span style='font-size:7pt;'>Image from Amazon.co.uk</span>
</div>
</td></tr></table><a href='blog.php?filter=Books'>Books</a> |  <a href='index.php?action=view&id=26'>Comments (2)</a>]]></description>
<pubDate>Sat, 16 Feb 2008 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=26#comments</comments>
	               	</item>

			<item>
			<title>2007-12-31 - Happy New Year</title> 
			<link>http://dorchard.co.uk/index.php?id=25</link>
			<author>Dominic Orchard</author>
<description><![CDATA[Just to say I hope everyone had a great Christmas and that they have a Happy New year! :)<a href='blog.php?filter=General'>General</a> |  <a href='index.php?action=view&id=25'>Comments (0)</a>]]></description>
<pubDate>Mon, 31 Dec 2007 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=25#comments</comments>
	               	</item>

			<item>
			<title>2007-12-24 - Creating an application with micMVC</title> 
			<link>http://dorchard.co.uk/index.php?id=23</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<style>
body {
	font-family:Verdana;
}
.console_container {
	width:90%;
	margin:10px;
}
.console,.directory,.console_code {
	background-color:#7192be;
	font-family:Courier New, Courier;
	letter-spacing:-0.6px;
	font-size:9pt;
	width:100%;
	padding:5px;
	text-align:left;
	border:solid 1px #444;
}
.console_code {
	background-color:#c4cfe0;
}
.top {
	font-weight:bold;
}
.desc {
	font-size:8pt;
}
.directory {
	width:600px;
	background-color:#eee;
	font-family:Verdana;
	letter-spacing:0px;
}
tr.line0 {
	background:#ffeeee;
}
tr.line1 {
	background:#f7eeee;
}
.code {
	font-family:Courier,Courier New;
}
</style>

The following is a step-by-step guide/tutorial to getting an app going with micMVC. It should be pretty straight forward as micMVC aims to be simple. The sample application outlined in this tutorial can be downloaded <a href='http://riftor.g615.co.uk/micmvc/sample-app-namesdb.tar.gz'>here.</a></a><br /><br />

<b>Step 1: Download and uncompress micMVC.</b> Download <a href='http://riftor.g615.co.uk/micmvc/micmvc-release.tar.gz'>the main micMVC package</a> and uncompress it in your project directory. For this example we will create a names database, so call the directory <i>namesdb</i>.
<div class='console_container' align='center'>
	<div class='console'>
		$> mkdir namesdb<br />
		$> cd namesdb<br />
		$> wget http://riftor.g615.co.uk/micmvc/micmvc-release.tar.gz<br />
		$> tar -zxf micmvc-release.tar.gz
	</div>
</div><br />
This creates the following directory structure:<br />
<div class='console_container' align='center'>
	<div class='directory'>
		<table style='width:600px;font-size:8pt;' cellspacing='0' cellpadding='2'>
			<tr class='line0'><td class='top' valign='top'>app</td><td></td><td class='desc'>The app directory contains the main application code</td></tr>
			<tr class='line1'><td class='top'></td><td valign='top'><b>controllers</b></td><td class='desc'>Controllers are the basic logic behind your interface, they typical provide the "business logic" link between the interface and database.</td></tr>
			<tr><td class='top'></td><td valign='top'>&nbsp;&nbsp;application_controller.php</td><td class='desc'>All controllers inherit from this controller, hence any functions you want to re-use in other controllers should be included here.</td></tr>
			
			<tr class='line1'><td class='top'></td><td valign='top'><b>helpers</b></td><td class='desc'>Helpers provide methods for use in the interface, views</td><?tr>
			<tr><td class='top'></td><td valign='top'>&nbsp;&nbsp;application_helper.php</td><td class='desc'>All helpers inherit from the application helper, hence this is a useful place to put any methods you want to use in all helpers/views.</td></tr>
			
			<tr class='line1'><td class='top'></td><td valign='top'><b>models</b></td><td class='desc'>Models are objects that "model" a database table. A single instantiation of an model represents a record in the database where the attributes of the object correspond to the fields in the database table.</td></tr>
			
			<tr class='line1'><td class='top'></td><td valign='top'><b>views</b></td><td class='desc'>Views are the interface designs and definitions. These typically contain mostly HTML with some basic PHP for handling data from the controllers.</td></tr>
			
			<tr><td class='top'></td></td><td valign='top'>&nbsp;&nbsp;error_no_action.php</td><td class='desc'>This page is loaded when an action that doesn't exist is called from a controller. This acts as a 404 error page.</td></tr>
			
			<tr class='line0'><td class='top' valign='top'>lib</td><td></td><td class='desc'>This contains the libraries for micMVC, most of which can be left alone by the user. A description is given here for completeness and developers.</td></tr>
			<tr><td class='top'></td><td valign='top'>DBQuery.php</td><td class='desc'>Contains the DBQuery class for accessing the database (MySQL implementation).</td></tr>
			<tr><td class='top'></td><td valign='top'>MicMVC.php</td><td class='desc'>The common include for handlers, brings together models is also contained in this file. Edit this file to include configuration for your database.</td></tr>
			<tr><td class='top'></td><td valign='top'>Model.php</td><td class='desc'>Contains the base Model class for accessing database tables and facilitating models.</td></tr>
			<tr><td class='top'></td><td valign='top'>UnitTest.php</td><td class='desc'>Contains the base Unit test class for unit testing.</td></tr>
			
			<tr class='line0'><td class='top' valign='top'>script</td><td></td><td class='desc'>Contains PHP scripts for running tests and creating/removing controllers, models and views from your application.</td></tr>
			<tr><td class='top'></td><td valign='top'>generate.php</td><td class='desc'>Script that generates new controllers, models and views in the application.</td></tr>
			<tr><td class='top'></td><td valign='top'>remove.php</td><td class='desc'>Script that removes controllers, models and views from the application.</td></tr>
			<tr><td class='top'></td><td valign='top'>run_tests.php</td><td class='desc'>Script that acts as a test suite for running all tests in the application</td></tr>
			
			<tr class='line0'><td class='top' valign='top'>test</td><td></td><td class='desc'>All tests should be placed in this directory.</td></tr>
			<tr><td class='top'></td><td valign='top'><b>unit</b></td><td class='desc'>All unit tests for models are generated here.</td></tr>
			</table>
			
				
	</div>
</div><br /><br />
<b>Step 2: Create a database and a table and get micMVC to generate a model.</b> In MySQL create a database called <i>namesdb</i> and a table called <i>person</i>:
<div class='console_container' align='center'>
	<div class='console'>
	<pre>
mysql> create database namesdb;
Query OK, 1 row affected (0.00 sec)

mysql> use namesdb;
Database changed
mysql> create table person(
    id integer auto_increment,
    firstname varchar(64),
    lastname varchar(64),
    age integer,
    PRIMARY KEY(id)
    );
Query OK, 0 rows affected (0.02 sec)

mysql> GRANT ALL ON namesdb.* TO namesdb_user@127.0.0.1 IDENTIFIED BY 'n4me5db';
Query OK, 0 rows affected (0.05 sec)

</pre>
	</div>
</div>
<br />
Now we need to tell micMVC to generate a model for us called "Person". <b>IMPORTANT</b> The name of the model must be exactly the same as the table name in the database (no pluralization rules). We generate the model by running "script/generate model person" in the top level directory of the application. <br />

<div class='console_container' align='center'>
	<div class='console'><pre>
$> script/generate model names
        creating new model: names
        creating file...         app/models/person.php
        creating file...         test/unit/person_test.php
        adding test to suit...
        adding model into application...
        done.

</pre>
	</div>
</div><br />
We now have a model and a unit test for the model. This model can be removed by running "script/remove model person". <br />

We also added the user "namesdb_user" to the database earlier. We now need to configure the database for access in the file <i>lib/MicMVC.php</i> filling in the configuration part as such:

<div class='console_container' align='center'>
	<div class='console_code'><pre>
// &lt;configuration&gt;

$host = "127.0.0.1";
$username = "namesdb_user";
$password = "n4me5db";
$database = "namesdb";

// &lt;/configuration&gt;
</pre>	
	</div>
</div>

We are now going to write some tests and some model code to help us out later.<br /><br />
<b>Step 3: Write tests and code for the model.</b> For this example we are going to write a function that compares two records based on the age so that we can sort the records based on age. This is a slightly useless example as we could easily get the database to sort for us, but it demostrates writing and testing custom model functions. We will develop the test first. Open up the newly generated <b>test/unit/person_test.php</b>. We add the method "testCompare()" inside the "PersonTest" class.<br />
<div class='console_container' align='center'>
	<div class='console_code'><pre>
		
		function testCompare(){
			// Create a person
			$person1 = new Person();
			$person1->firstname = "Malcolm";
			$person1->lastname = "Reynolds";
			$person1->age = 38;
			
			// Check this saves ok
			$this->assert($person1->save());
			
			// Create another person
			$person2 = new Person();
			$person2->firstname = "Jayne";
			$person2->lastname = "Cobb";
			$person2->age = 36;
			
			// Check person2 saves ok
			$this->assert($person2->save());
			
			// Test the compare function
			// We expect person1 to be greater, therefore return 1
			$this->assert_equal(1, $person1->compare_to($person2));
			
			// And inversely to get -1
			$this->assert_equal(-1, $person2->compare_to($person1));
			
			// If we set the ages the same then we expect a result of 0
			$person2->age = 38;
			$person2->save();
			
			$this->assert_equal(0, $person1->compare_to($person2));
			$this->assert_equal(0, $person2->compare_to($person1));
			
			// Remove the test data
			$person1->destroy();
			$person2->destroy();
		}
	</pre>
	</div>
</div><br />
This should demonstrate how to use models. A new record can be created by instantiating a model class e.g. <span class='code'>$person1 = new Person();</span> This model can be saved or updated (INSERT or UPDATE) by calling the method "save()" on the object, e.g. <span class='code'>$person1->save();</span> Fields of the record can be set as attributes. A record can be removed by calling "destroy()" on the object e.g. <span class='code'>$person1->destroy();</span>.<br />
Assertions can be tested with <span class='code'>$this->assert($boolean_expression);</span> and <span class='code'>$this->assert_equal($expression1, $expression2);</span> from within any unit test class.<br />
Now we have the test in place, lets write the code! Open up "app/models/person.php" and edit it as such:-<br />
<div class='console_container' align='center'>
	<div class='console_code'>
<pre>
&lt;?php

	require_once "lib/MicMVC.php";
	// Model for Person database table
	
	class Person extends Model {
		// Custom model operations go here
		
		// Compare a person record with another
		function compare_to($person2) {
			if ($this->age &lt; $person2->age) {
			
				// This person has a lower age
				return -1;	
				
			} elseif ($this->age > $person2->age) {
			
				// This person has a higher age
				return 1;
				
			} else {
			
				// The ages are equal
				return 0;
				
			}
		}	
	}

?&gt;</pre></div>
</div><br />
Now we have both the model and test for the model, lets run the test suite. Do this by running <span class='code'>script/run_tests</span>
<div class='console_container' align='center'>
	<div class='console'>
<pre>
$> script/run_tests

PersonTest: running tests
         Running test: testCompare              ......
         Test finished. 6 of 6 assertions passed (100%)

PersonTest: Tests finished. 6 of 6 passed (100%)


All tests completed successfully!
1 out of 1 tests completed successfully.</pre>
</div>
</div>
<b>Step 4 - Create the controller and write the interface</b> - We now write the code for the interface before writing the controller. If we generate a controller an interface template for the controller is also setup for us. <br /><br />
<div class='console_container' align='center'>
	<div class='console'><pre>
$>  script/generate controller people
        creating new controller: people
        creating file...         app/controllers/people_controller.php
        creating file...         app/helpers/people_helper.php
        creating file...         ./people.php
        creating directory...    app/views/people
        creating file...         app/views/people/index.php
        done.	</pre>
	</div>
</div><br /><br />
You'll notice that along with a controller and a helper being generated, we now have a folder named "people" created in the "app/views" folder. This is the location for the interface, "view" code. There is also a file created called "people.php" in the top level directory. This acts as the handler to the people_controller. We will add the following code to the "app/views/people/index.php" view, adding the following code to create a simple form for adding people to the database.
<div class='console_container' align='center'>
	<div class='console_code'><pre>
&lt;form action='people.php?action=add_person' method='post'>
	&lt;table>
		&lt;tr>&lt;td>First Name:&lt;/td>&lt;td>&lt;input name='firstname' />&lt;/td>&lt;/tr>
		&lt;tr>&lt;td>Last Name:&lt;/td>&lt;td>&lt;input name='lastname' />&lt;/td>&lt;/tr>
		&lt;tr>&lt;td>Age:&lt;/td>&lt;td>&lt;input name='age' />&lt;/td>&lt;/tr>
	&lt;/table>&lt;br />
	&lt;input type='submit' value='Add Person' />
	&lt;span style='color:#080'>&lt;?= ($this->message) ?>&lt;/span>&lt;br />
&lt;/form>
</pre>
</div>
</div>
We will also add some code immediately after this for displaying all the people in the database.<br /><br />
<div class='console_container' align='center'>
	<div class='console_code'><pre>
&lt;b>List of People: &lt;?= sizeof($this->people) ?> entries&lt;/b>&lt;br />
&lt;table cellpadding='5'>
	&lt;tr>&lt;th>&lt;a href='people.php?action=sort&type=firstname'>First name&lt;/a>&lt;/th>
		&lt;th>&lt;a href='people.php?action=sort&type=lastname'>Last name&lt;/a>&lt;/th>
		&lt;th>&lt;a href='people.php?action=sort&type=age'>Age&lt;/a>&lt;/th>
	&lt;/tr>
&lt;?php foreach($this->people as $person) { ?>
	&lt;tr>
		&lt;td>&lt;?= $person->firstname ?>&lt;/td>
		&lt;td>&lt;?= $person->lastname ?>&lt;/td>
		&lt;td>&lt;?= $person->age ?>&lt;/td>
		&lt;td>&lt;a href='people.php?action=delete&id=&lt;?= $person->id ?>'>Delete&lt;/a>&lt;/td>
	&lt;/tr>
&lt;?php } ?>
&lt;/table>			
</pre>
</div>
</div><br /><br />
<b>Step 5: Write the controller code</b>: 
First we add code for handling the index page, adding people to the database, and the delete function.
<div class='console_container' align='center'>
	<div class='console_code'><pre>
&lt;?php

	require "lib/MicMVC.php";
	require "app/helpers/people_helper.php";

	class People_Controller extends ApplicationController {

		var $message = "";

		// Find all the person records
		function index() {			$this->people = Person::find_all("person");
			$this->render("index");
		}
		
		// Handle adding people to the database
		function add_person(){
		
			// Create a new Person record
			$person = new Person();
			
			// Set the fields
			$person->firstname = $_POST["firstname"];
			$person->lastname = $_POST["lastname"];
			$person->age = $_POST["age"];
			
			// Save the record
			$person->save();
			
			// Set a message for the interface
			$this->message = "{$person->firstname} {$person->lastname} saved.";
			$this->index();
		}
		
		function delete(){
			// Find the person with id $_GET["id"]
			// and delete it
			
			$person = new Person($_GET["id"]);
			$person->destroy();
			
			$this->message = "{$person->firstname} {$person->lastname} deleted.";
			$this->index();
		}
	}
?>
</pre>
</div>
</div><br /><br />
Next we also add the following function inside the controller for performing sorts
<div class='console_container' align='center'>
	<div class='console_code'><pre>
	function sort(){
	
		if(!strcmp($_GET["type"], "age")){
			$people = Person::find_all("person");
		
			// Use a bubble sort
			for($i = sizeof($people) - 1; $i >=0; $i--){
				for($j = 0; $j < $i; $j++){
					if($people[$j]->compare_to($people[$j+1]) == 1){
						$tmp = $people[$j];
						$people[$j] = $people[$j+1];
						$people[$j+1] = $tmp;
					}
				}
			}
			
			$this->people = $people;
			
		} elseif (!strcmp($_GET["type"], "firstname")){
			$this->people = Person::find_all("person", "1 ORDER BY firstname");
					
			
		} elseif (!strcmp($_GET["type"], "lastname")){
			$this->people = Person::find_all("person", "1 ORDER BY lastname");

		} else {
		
		}
		
		$this->render("index");
	}
</pre>
</div>
</div>
And that's it! We now have a fully working names database where we can add, delete and sort our results. If you point your browser at your application directory at people.php then you can see it in operation (e.g. at http://127.0.0.1/namesdb/people.php).
<a href='blog.php?filter=Programming'>Programming</a> |  <a href='index.php?action=view&id=23'>Comments (4)</a>]]></description>
<pubDate>Mon, 24 Dec 2007 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=23#comments</comments>
	               	</item>

			<item>
			<title>2007-12-19 - Christmas holiday so far</title> 
			<link>http://dorchard.co.uk/index.php?id=21</link>
			<author>Dominic Orchard</author>
<description><![CDATA[Hi all,<br />
Well term has finished and I am now on my Christmas holidays. I recently went to Edinburgh to have some fun with some friends and also had the privelege of meeting up with some great computer scientists at the University of Edinburgh to talk about PhDs which was very interesting. Here are few select snaps from our little holiday:<br /><br />
<div align='center'>
<table cellspacing='0' cellpadding='1'>
<tr>
<td>
<a href='http://riftor.g615.co.uk/content/0/edinburgh/edinburgh-pic1.jpg'><img src='http://riftor.g615.co.uk/content/0/edinburgh/edinburgh-pic1t.jpg' border='0'></a>
</td>
<td>
<a href='http://riftor.g615.co.uk/content/0/edinburgh/edinburgh-pic2.jpg'><img src='http://riftor.g615.co.uk/content/0/edinburgh/edinburgh-pic2t.jpg' border='0'></a>
</td>
<td colspan='2'>
<a href='http://riftor.g615.co.uk/content/0/edinburgh/edinburgh-pic3.jpg'><img src='http://riftor.g615.co.uk/content/0/edinburgh/edinburgh-pic3t.jpg' border='0'></a>
</td></tr></table><br />
<table cellspacing='0' cellpadding='1' style='margin-top:-17px'><tr>
<td>
<a href='http://riftor.g615.co.uk/content/0/edinburgh/edinburgh-pic4.jpg'><img src='http://riftor.g615.co.uk/content/0/edinburgh/edinburgh-pic4t.jpg' border='0'></a>
</td>
<td>
<a href='http://riftor.g615.co.uk/content/0/edinburgh/edinburgh-pic5.jpg'><img src='http://riftor.g615.co.uk/content/0/edinburgh/edinburgh-pic5t.jpg' border='0'></a>
</td>
<td>
<a href='http://riftor.g615.co.uk/content/0/edinburgh/edinburgh-pic6.jpg'><img src='http://riftor.g615.co.uk/content/0/edinburgh/edinburgh-pic6t.jpg' border='0'></a>
</td>
<td>
<a href='http://riftor.g615.co.uk/content/0/edinburgh/edinburgh-pic7.jpg'><img src='http://riftor.g615.co.uk/content/0/edinburgh/edinburgh-pic7t.jpg' border='0'></a>
</td></tr></table></div><br />
Besides visiting Edinburgh I also visited Cambridge recently to meet with people at the Computing Lab at the University of Cambridge and Microsoft Research to discuss perhaps doing a PhD next year.<br />
I am now at home and back at my part-time job as a software developer which is going great. I have recently been developing a domain-specific language/algebra for expressing product promotions within my web-order entry system.<br /><br />
For all who are interested I will shortly be uploading a load of work I have been doing over the last year or so on various projects and research, including my language Lucian. If anyone is looking for my work on Lucian (which I know a few people are), then it will be appearing on this site by the weekend.<br />
Thanks!<a href='blog.php?filter=General'>General</a> |  <a href='index.php?action=view&id=21'>Comments (3)</a>]]></description>
<pubDate>Wed, 19 Dec 2007 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=21#comments</comments>
	               	</item>

			<item>
			<title>2006-09-05 - Ruby on Rails, XML Deserializer</title> 
			<link>http://dorchard.co.uk/index.php?id=20</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>An extension to ActiveRecord::Base to complement the to_xml method</b><br /><br />While working on a project recently using the <a href='http://www.rubyonrails.com'>Ruby on Rails</a> framework, I required full XML serializing and deserializing of my models (database tables) for an information services layer.<br><br>
I discovered quickly that there exists a "to_xml" method for ActiveRecord instances, but no complimentary method for deserializing an ActiveRecord instance. I Googled around and found an example of such a method the blog of <a href='http://www.wayne-robinson.com/display/ShowJournal?moduleId=549828&categoryId=40943'>Wayne Robinson</a>, which was a really good start to the problem. Then I set about making it more sound<br><br>
Please leave feedback & comments as I'm aware that it may need some more fine tuning as I can only test its robustness against my own project.
<br><br>
Thanks to YMMV and another anonymous commentor who fixed a couple of small bugs for has_many associations and uppercase attribute names.
<span style='color:#f00;font-size:8pt'>Updated 2007</span>
<div class='figure'><pre><small>
module ActiveRecord
  class Base
  
    <span style='color:#080'># XML Deserializer for ActiveRecord</span>
    <span style='color:#080'># by Wayne Robinson and Dominic Orchard</span>
    def self.from_xml(xml)
      if xml.class == String
          <span style='color:#080'># If passed a string, convert to XML object, and set root</span>
          xml = REXML::Document.new(xml) 
          root = xml.elements[1]
      else
          <span style='color:#080'># If already passed an XML object, then set root to XML object</span>
          root = xml
      end
      
      if  ((root.name.underscore != self.class_name.underscore) and 
             (root.name.underscore != self.class_name.pluralize.underscore))
              <span style='color:#080'># Check the top level is actual refering to the class</span>
              <span style='color:#080'># e.g. , for class Customer</span>
             return nil
      end
      
      <span style='color:#080'># Deal with XML data containing many record instances</span>
	if (root.name.underscore == self.class_name.pluralize.underscore and
	    self.class_name.pluralize.underscore!=self.class_name.underscore) or
	    root.name==root.elements[1].name
        
		root.elements.inject([]) do |instances, element|
			instances.push(self.from_xml(element))
		end

        else
            <span style='color:#080'># Try to retrieve from ID in</span>
            <span style='color:#080'># XML data and update this record or start a new record</span>
            <span style='color:#080'># Find an id element in the elements</span>
            id_element = root.elements.inject(nil) do |found, element|
                  if element.name=="id"
                        element
                  else
                        found
                  end
            end
            <span style='color:#080'># if we haven't found the ID element</span>
            if id_element.nil?
                  new_record = self.new
            else
                  <span style='color:#080'># Retrieve from XML</span>
                  begin            
                      new_record = self.find(id_element.text.to_i)
                  rescue
                      <span style='color:#080'># If that record in fact didn't exist... start a new one</span>
                      new_record = self.new
                  end
            end
            
            <span style='color:#080'># Iterate through elements</span>
            root.elements.each do | element |
                if ele.name.upcase == ele.name
			sym = ele.name.to_sym
		else
			sym = ele.name.underscore.to_sym
		end 
      
                <span style='color:#080'># An association</span>
              if element.has_elements?
  
                setter = (sym.to_s+"=")
                <span style='color:#080'># Check the setter is an instance method</span>
                if self.instance_methods.member?(setter)
                      klass = self.reflect_on_association(sym).klass
                      new_record.__send__(setter.to_sym, klass.from_xml(element))
                end
    
              <span style='color:#080'># An attribute</span>
              else
                  <span style='color:#080'># Check that the attribute is actual part of the record</span>
                  if new_record.attributes.member?(sym.to_s) || sym==:id
                      if element.text.nil?              
                            col = new_record.column_for_attribute(sym)
                            <span style='color:#080'># Handle an empty element with a not null column</span>
                            if !col.null
                                <span style='color:#080'># Use default value</span>
                                new_record[sym] = col.default
                            end
                      else
                            new_record[sym] = element.text
                      end
                  end
             end
          end
  
          new_record
        end
     end
  end
end</small></pre>
</div>

Wayne Robinson recommended placing this code into the bottom of your config/environment.rb file for inclusion into your models.

<div class='figure'>
<a href='content/programming/from_xml/from_xml.rb'>Download source file</a><br>
<a href='content/programming/from_xml/tests.tar'>Download unit tests</a>
</div>

(Code is presented as-is with no guarantees!)<a href='blog.php?filter=Programming'>Programming</a> |  <a href='index.php?action=view&id=20'>Comments (9)</a>]]></description>
<pubDate>Tue, 05 Sep 2006 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=20#comments</comments>
	               	</item>

			<item>
			<title>2007-11-30 - Obligatory late night post</title> 
			<link>http://dorchard.co.uk/index.php?id=19</link>
			<author>Dominic Orchard</author>
<description><![CDATA[Just to say that its 6:43am and I am finally folding into bed after completing a poster, a portfolio and a paper tonight! It feels good to have three largish pieces of work complete but I hope that I will maintain some kind of lucid thought tomorrow!
Good night all!<a href='blog.php?filter=Tired'>Tired</a> |  <a href='index.php?action=view&id=19'>Comments (4)</a>]]></description>
<pubDate>Fri, 30 Nov 2007 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=19#comments</comments>
	               	</item>

			<item>
			<title>2007-11-27 - PhDs, Research, Undergrad work</title> 
			<link>http://dorchard.co.uk/index.php?id=18</link>
			<author>Dominic Orchard</author>
<description><![CDATA[I am currently heavily in embroiled in completing a paper for submission in the field of intensional programming. This is basically consuming most of my time on top of standard undergrad work.<br /><br />
My typical day consists of stumbling out of bed at 8:45 or 9:45 to get to a meeting/lecture at 9 or 10 respectively. I then spend most of the day in lectures and meetings and working on bits of undergrad work until about 6/7 when I eat, then start up the day of a researcher, working on the research and paper until about 3/4am when I finally get into bed then can't sleep because my mind is racing!<br /><br />
But I'm not complaining about this because, although its hard work, I enjoy the research and I hope that the hard work I have put into the paper will pay off.<br /><br />
At the same time I am also investigating where I would like to do a PhD next year and am tentatively pushing doors at the moment to see where I could go. Fun times!<a href='blog.php?filter=Research'>Research</a> |  <a href='index.php?action=view&id=18'>Comments (5)</a>]]></description>
<pubDate>Tue, 27 Nov 2007 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=18#comments</comments>
	               	</item>

			<item>
			<title>2007-11-13 - Paul Hammond speaks on Flickr</title> 
			<link>http://dorchard.co.uk/index.php?id=13</link>
			<author>Dominic Orchard</author>
<description><![CDATA[My department had the good fortune of Paul Hammond from the <a href='http://www.flickr.com'>Flickr</a> team coming to speak to us today about the backend infrastructure of Flickr and how it maintains <span style='font-family:Arial;font-size:12pt;letter-spacing:0px;'>Scalability</span>,
<span style='font-family:Arial;font-size:12pt;letter-spacing:0px;'>High Availability</span> and
<span style='font-family:Arial;font-size:12pt;letter-spacing:0px;'>Performance</span> through clever server interactions and middleware to ensure a solid (but not perfect) and fast service.<br />
<div align='center'><br /><br />
	<img src='http://riftor.g615.co.uk/content/0/paulhammond_seminar.jpg' style='border:solid 4px #cacaca;'><br />
	<small><i>Apologies Paul! A Warwick Uni CS department classroom is not exactly a glamarous venue!</i></small>
</div>
<br />One interesting point that I took away from the talk that I'd like to share now was that, once again, certain methods are simply not practial or are simply unnecessary for certain applications. For instance Flickr's backend will occasionally experience some database inconsistency across shared data, however it is willing to admit this and explain this to the user simply where it is appropriate (a warning about data not being available yet).<br />The point is that Flickr isn't a safety critical system and certain systems can be made to run very fast for a very large number of users with a very occasional lapse in accuracy that is admitted rather than fixed, affording occasional slip-ups in non-critical data (such as user comments)<br /><br/ >
    Another point that I thought was very interesting was a quote that Paul accredited to his boss; "Normalised data is for sissies." Eloquently put! When designing databases my relational-database-computer-science-sense<sup>TM</sup> kicks in and I automatically dive into highly normalised tables resulting in many small tables with many relationships but I've always had this fear that sometimes I've gone too far and comprised on speed.<br />Denormalisation can be a tricky business, however in practise denormalisation of data can be very useful from an optimisation point of view. For example Flickr, as Paul explained, stores the number of photos uploaded by a user in the user record, instead of counting the photo records belonging to the user each time the count is requested. This saves a lot of processing as the photo count is used frequently. When a new photo is added the photo count is recalculated from the database to prevent some strange race conditions occuring (not too likely in this case unless the user was uploading two photos at once).<br /><br />
    Paul Hammond certainly knew his stuff and it was a great talk that I feel helped me to grasp a stronger handle on some ideas that I already had lurking in the back of my mind about how to run scalable applications.<br /><br />
Anyway enough rambling, I am departing tomorrow afternoon to head to Quinta near Wales for a Christian Union weekend away which I'm sure I will immensly enjoy and will get some good timeout and perspective. Thanks.<a href='blog.php?filter=Tech'>Tech</a> |  <a href='index.php?action=view&id=13'>Comments (8)</a>]]></description>
<pubDate>Tue, 13 Nov 2007 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=13#comments</comments>
	               	</item>

			<item>
			<title>2007-11-21 - Bugs, Ruby, Macros</title> 
			<link>http://dorchard.co.uk/index.php?id=12</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>My day in 3 nouns</b><br /><br />I have been figuring out some tricky bugs in a fairly sizable and complex Ruby on Rails app I am involved in and found some well hidden but potentially serious bugs that have slipped through the net. This resulted in me writing a correction function that takes almost 4 minutes to run and which actually causes the fastcgi handler to keel over, hence I must run it from the console instead.<br /><br />    Anyway, while googling for a particular Ruby trick I discovered this <a href='http://xtargets.com/snippets/posts/show/68'>interesting post dubbed "Python Style Ruby"</a>.<br /> This post defines a method for writing Python style code in ruby (with <a href='http://en.wikipedia.org/wiki/Off-side_rule'>off-side</a> rule indenting and colons). This isn't amazingly useful <i>per se</i>, but the technique employed is very clever. Using Ruby's deeply object-oriented nature this method works by simply require a module at the start of the "pythonized" file which reloads the caller file, processesing it, transforming it and cleanly evaluating the code back in to the module.<br />I had never seen a method of loading up a caller file from an included module and had never really thought about whether that was possible, but this little method opens up a nice way to include <a href='http://en.wikipedia.org/wiki/Macro_%28computer_science%29'><b>macros</b></a> <i>without</i> an external pre-processor.<br /><br />   
My mind began racing as I started wildly hacking <a href='http://www.lisp.org/HyperSpec/Body/mac_defmacro.html'>'defmacro'</a> style constructs into Ruby. A few regular expressions later and I remembered how much easier this kind of activity is in Lisp where blocks of code are so easily handled, examined, reparsed, partially evaluated and manipulated, a task not so easy in Ruby where some internal AST is hidden and likely obfuscated. So how does one get a nice clean system for macros in Ruby? Well, currently as I am going away tomorrow and have a bunch of assignments I should be doing as opposed to implementing a Ruby macro system I am putting this little project on the side, but I will pick it up hopefully shortly and get something posted because quite frankly, macros are delicious.<br /><a href='blog.php?filter=Programming'>Programming</a> |  <a href='index.php?action=view&id=12'>Comments (4)</a>]]></description>
<pubDate>Wed, 21 Nov 2007 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=12#comments</comments>
	               	</item>

			<item>
			<title>2007-11-21 - URSS Poster Exhibition Ceremony</title> 
			<link>http://dorchard.co.uk/index.php?id=11</link>
			<author>Dominic Orchard</author>
<description><![CDATA[Earlier this week I presented my poster and research that Daniel James and I carried out over the summer funded by the <a href='http://www2.warwick.ac.uk/services/ldc/funding/urss/'>University of Warwick URSS (Undergraduate Research Scholarship Scheme)</a> at an all day event dubbed as a 'Posted Exhibition Ceremony'. I very much enjoyed talking to people about my work and people seemed very interested (mostly because my research was robotics related (more to come soon on this)). It was also immensely enjoyable talking to other undegraduate researchers, examining their posters and discussing their results. The posters for all of the researchers can be found <a href='http://www2.warwick.ac.uk/services/ldc/funding/urss/projects_06/'>here</a>, my poster can be found <a href='http://riftor.g615.co.uk/index.php?action=view&id=10'>here also</a>. Hopefully some pictures from the event will circulate soon as there was an official photographer, I unfortunately forgot my compact in the mad rush having only a few hours sleep previous. Free lunch and danish pastries were an added bonus.<br /><a href='blog.php?filter=Poster'>Poster</a> |  <a href='index.php?action=view&id=11'>Comments (6)</a>]]></description>
<pubDate>Wed, 21 Nov 2007 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=11#comments</comments>
	               	</item>

			<item>
			<title>2007-10-28 - Robot Navigation and Control</title> 
			<link>http://dorchard.co.uk/index.php?id=10</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Poster presentation of research</b><br /><br /><div align='center'>
<a href='http://riftor.g615.co.uk/content/3/poster-small.png'><img src='content/3/poster-vsmall.png' border='0' style='border:solid 1px #ccc;'></a></div><br />
An A1 poster designed by myself summarizing research carried out by Daniel James and I in the area of robot navigation and control during Summer 2007 (see <a href='http://riftor.g615.co.uk/project.php'>Research</a> section). This poster was a requirement of the research funding and is being presented in November 2007.<br />
<small>(Click for a larger view).</small><a href='blog.php?filter=Poster'>Poster</a> |  <a href='index.php?action=view&id=10'>Comments (3)</a>]]></description>
<pubDate>Sun, 28 Oct 2007 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=10#comments</comments>
	               	</item>

			<item>
			<title>2006-01-31 - Shoes, hands and statues</title> 
			<link>http://dorchard.co.uk/index.php?id=9</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>A subset of my work from AS-level Art (2003)</b><br /><br /><img src='http://riftor.g615.co.uk/art/Unit1.jpg'><br>
Module 1 : Still life drawings/paintings<br><br>

<img src='http://riftor.g615.co.uk/art/Unit2.jpg'><br>
Module 2 : Hands<br><br>

<img src='http://riftor.g615.co.uk/art/Unit3.jpg'><br>
Module 3 : Brazillian/African statues ad abstractum 
<a href='blog.php?filter=Art'>Art</a> |  <a href='index.php?action=view&id=9'>Comments (2)</a>]]></description>
<pubDate>Tue, 31 Jan 2006 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=9#comments</comments>
	               	</item>

			<item>
			<title>2006-01-31 - Anomality</title> 
			<link>http://dorchard.co.uk/index.php?id=8</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>A painting/oil pastel/pencil piece</b><br /><br /><div align='center'>
<a href='http://riftor.g615.co.uk/art/anomality.jpg'><img src='http://riftor.g615.co.uk/art/anomality_med.jpg' border='0'></a></div><br /><br />
This is a piece of art I created back in 2003 when I was still at school using a mixture of acrylic paints, oil pastels and pencils. Feel free to express your interpretations!
<a href='blog.php?filter=Art'>Art</a> |  <a href='index.php?action=view&id=8'>Comments (4)</a>]]></description>
<pubDate>Tue, 31 Jan 2006 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=8#comments</comments>
	               	</item>

			<item>
			<title>2007-01-13 - Compiling wxHaskell 0.9.4 for wxWidgets 2.8.0</title> 
			<link>http://dorchard.co.uk/index.php?id=7</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Guide and modified code for the latest versions</b><br /><br /><p>
For a project I am using wxHaskell for some GUI and graphics things, so I went to install it. But I found that, once downloading the latest source for wxWidgets (December 2006) (2.8.0), that I couldn't compile the latest (May 2005) (0.9.4) due to quite a few compile errors. I had a look online and saw a few other people having the same issue and didn't want to really have to use an older version of wxWidgets from 2 years ago. So I set about trying to write fixes and make some hacks to get wxHaskell working with 2.8. I hope the information and code will be useful.<br><i>Note: I am using Suse Linux 10.1 with 2.6.13-15.12 kernel and GHC 6.4.1 (I know I'm a bit behind on GHC)). <b> All the information presented here is AS IS. I haven't fully tested all the features in wxHaskell using this modified source so its not impossible there may be a couple of obscure features that don't fully work as they are supposed to, but the majority I think it will be fine.</b></i>
<br><br>
<ul><li><b>Step 1</b> - Download the latest <a href='http://www.wxwidgets.org/downloads/#latest_stable'>wxWidget 2.8.0</a> and compile + install. <b>When you configure you MUST add the argument --enable-compat24.</b><br>I did:-
<blockquote>./configure --enable-compat24<br>make<br>make install</blockquote></li>
<li><b>Step 2</b> - Download and extract my <a href='http://riftor.g615.co.uk/wxhaskell/wxhaskell-0.9.4-compat-wxW2.8.tgz'>modified source for wxHaskell 0.9.4</a>. Don't compile and install yet</li>
<li><b>Step 3</b> - Set your wxWidget includes to use WXWIN_COMPATIBILITY_2_4 mode. This can be done by finding the setup.h file. I found mine by doing:-<br>
<blockquote>find /* 2>/dev/null | grep wx | grep setup.h</blockquote><br>
And on my machine it was located at /usr/local/lib/wx/include/gtk2-ansi-release-2.8/wx/setup.h
Edit this file and find the line that is:-<br>
<blockquote>#define WXWIN_COMPATIBILITY_2_4 0</blockquote><br>
<small>Line 155 for me</small>
And set it to:-<br>
<blockquote>#define WXWIN_COMPATIBILITY_2_4 1</blockquote><br>
Hence turning on 2.4 compatibility.</li>
<li><b>Step 4</b> - Go back to source for my modified wxHaskell 0.9.4. and do the usual:-<br>
<blockquote>./compile<br>make<br>make install<br></blockquote><br>
Then you should be good to go. Test the samples to make sure its all good.</li></ul>

<a href='http://riftor.g615.co.uk/wxhaskell/wxhchanges.txt'>Here is a reasonably complete list of the changes I made</a>. A few may be omitted as I was trying to do this as fast as possible for a project, there may be some dirty hacks, some of the code is good though!

Please leave feedback if you find that this process is wrong, or have any other queries, or things happen differently with your configuration.
</p><a href='blog.php?filter=Tech'>Tech</a> |  <a href='index.php?action=view&id=7'>Comments (6)</a>]]></description>
<pubDate>Sat, 13 Jan 2007 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=7#comments</comments>
	               	</item>

			<item>
			<title>2005-11-05 - Natural Primes in SML</title> 
			<link>http://dorchard.co.uk/index.php?id=6</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Lazy lists and Sieve of Eratosthenes method in SML</b><br /><br />Example of lazy lists in SML, using Sieve of Eratosthenes method to produce a lazy list of prime numbers.

<div class='figure'><b>Code</b><br>
<pre><small>
structure Lizt = 
	struct
		datatype 'a lizt = empty | cons of 'a * (unit -> 'a lizt)
		
		fun filter f empty = empty
			| filter f (cons(x,xs)) = 
				if (f x) then
					cons(x, fn ()=> filter f (xs()))
				else
					filter f (xs())

		fun hd empty = raise Empty
			| hd (cons(x,xs)) = x
		fun tl empty = raise Empty			
			| tl (cons(x,xs)) = xs()
	end
	
fun naturals n = Lizt.cons(n, fn ()=> naturals(n+1))
	
fun primes(Lizt.cons(x,xs)) = 
		Lizt.cons(x, fn ()=> primes(Lizt.filter (fn y=> y mod x <> 0) (xs ())))
		
	| primes(Lizt.empty) = Lizt.empty

val natPrimes = primes(naturals(2))
</small></pre>
</div>
<br>
<div>
<i>Example usage</i><br>
<pre>
- Lizt.hd(natPrimes);
> val it = 2 : int
- Lizt.hd(Lizt.tl(natPrimes));
> val it = 3 : int
</pre>
</div>
<a href='blog.php?filter=Programming'>Programming</a> |  <a href='index.php?action=view&id=6'>Comments (3)</a>]]></description>
<pubDate>Sat, 05 Nov 2005 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=6#comments</comments>
	               	</item>

			<item>
			<title>2005-11-08 - Conjunctive Normal Form</title> 
			<link>http://dorchard.co.uk/index.php?id=5</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>A short conversion algorithm in Scheme</b><br /><br />This is going to be a brief post of a small program that I wrote in <b><a href='http://www.schemers.org/'>Scheme</a></b> (a dialect of Lisp). It converts a propositional formula into <a href='http://en.wikipedia.org/wiki/Conjunctive_normal_form'><i>conjunctive normal form</i></a><br>

I hope that this may be useful to someone, it was for me just to get it in my head how the algorithm works, and to check my Logic assignments against ;). <br><br>

The code should be fairly portable across most Scheme implementations, if not <a href='mailto:riftor@g615.co.uk'>drop me a line</a>.<br>

So without further ado, here is the code:-<br>

<div class='figure'>
<pre>(define (cnf x)
  (cnfp (nnf (impl-free x))))

(define (cnfp x)
  (cond ((symbol? x) x)
        ((equal? (fst x) 'and) `(and ,(cnfp (scnd x)) ,(cnfp (thrd x))))
        ((equal? (fst x) 'or) (distr (cnfp (scnd x)) (cnfp (thrd x))))))

(define (distr x y)
  (cond ((equal? (fst x) 'and) `(and ,(distr (scnd x) y) ,(distr (thrd x) y)))
        ((equal? (fst y) 'and) `(and ,(distr x (scnd y)) ,(distr x (thrd y))))
        (#t `(or ,x ,y))))

(define (impl-free x)
  (cond ((symbol? x) x)
        ((equal? (fst x) 'impl) `(or (not ,(impl-free (scnd x))),(impl-free (thrd x))))
        ((equal? (fst x) 'not) `(not ,(impl-free (scnd x))))
        (#t `(,(fst x) ,(impl-free (scnd x)) ,(impl-free (thrd x))))))

(define (nnf x)
  (cond ((symbol? x) x)
        ((and (equal? (fst x) 'not) (equal? (fst (scnd x)) 'not)) (nnf (scnd (scnd x))))
        ((equal? (fst x) 'and) `(and ,(nnf (scnd x)) ,(nnf (thrd x))))
        ((equal? (fst x) 'or) `(or ,(nnf (scnd x)) ,(nnf (thrd x))))
        ((and (equal? (fst x) 'not) (equal? (fst (scnd x)) 'and))
              (nnf `(or (not ,(scnd (scnd x))) (not ,(thrd (scnd x))))))
        ((and (equal? (fst x) 'not) (equal? (fst (scnd x)) 'or))
              (nnf `(and (not ,(scnd (scnd x))) (not ,(thrd (scnd x))))))
        ((equal? (fst x) 'not) `(not ,(nnf (scnd x))))))

(define (fst x)
  (if (symbol? x) x 
      (if (list? (car x))
          (car (car x))
          (car x))))

(define (scnd x)
  (if (list? (car x))
      (cadr (car x))
      (cadr x)))

(define (thrd x)
  (if (list? (car x))
      (car (cddr (car x)))
      (car (cddr x))))
</pre>

</div>

<br>

<div class='figure'>

<small><b>Example usage</b></small><br>
<pre>

> (cnf '(not (impl p (not (and q (impl (not p) q))))))

(and p (and q (or p q)))

> (cnf '(or a (and b c)))

(and (or a b) (or a c))</pre>

</div><br>

<i>Notes on code:</i>
<br>
The program recognises implication as the symbol 'impl'.<br>
It is split into a bunch of functions, 'impl-free' takes a formula and removes all implications (a -> b), replacing them with "not a" or "b"<br>
'nnf' removes extraneous 'not's and performs deMorgans law.
<br><br>
If you notice a bug, or mistake, or have any suggestions, please tell me.
<a href='blog.php?filter=Maths'>Maths</a> |  <a href='index.php?action=view&id=5'>Comments (1)</a>]]></description>
<pubDate>Tue, 08 Nov 2005 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=5#comments</comments>
	               	</item>

			<item>
			<title>2005-10-05 - Displaying continuous data</title> 
			<link>http://dorchard.co.uk/index.php?id=4</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>Anti-aliasing lines and polygon area calculation</b><br /><br /><style>
#content {
	height:none;
	min-height:100%;
}
</style>
<div style='clear:both;background-color:#fff;'>
<table width='660'><tr><td valign='top'>
<div align='justify'\\>
<b>Introduction</b><br><br>
This article sprang from a problem put forward in "The New Turing Omnibus" by A.K Dewdney, specifically from chapter 29, related to cat-scanning/image processing techniques. The (paraphrased) problem at the end of chapter states, "Given a pixel with unit side, calculate its area of intersection with a band of width w." This sprang forth a lot of thought of implementation, and of other computer applications. Please read on.
</div>
</td><td valign='top'>
<br /><br />
<div id='files' class='figure' style='white-space:nowrap;'><b>Resources</b><br>
<a href='content/programming/areacalc/areacalc.py'>Single square area-calc [Python,<a href=" http://www.pythonware.com/products/pil/">PIL</a>]</a><br>
<a href='content/programming/areacalc/areacalc2.py'>Single square area-calc, animated [Python]</a><br>
<a href='content/programming/areacalc/areacalc3.py'>Multiple squares area-calc, animated [Python]</a><br>
<a href='content/programming/areacalc/beam.py'>Anti-aliasing implementation, animated [Python]</a><br>
</div>
<div align='right' style='margin-right:10px;'>
<small><i>This article is in its first revision<br />October 2005</i></small>
</div>
</td></tr></table><br>
<div align='justify'>
When an equation of a line is given, say y=x, it can be drawn on paper, as a continuous line, and can be calculated for any real number, with a infinite number of values. When this line is ploted on a computer, the computer display is not continuous, hence the line can only be represented in discrete units (pixels) (see Figure 0).</div>
<br>
<table width='660'><tr><td valign='top'>
<div id='image1' style='float:left;' class='figure'>
<img src='content/programming/areacalc/7_1.png' style='margin-bottom:6px;'><br><small><b>Figure</b> 0</small></div>
</td>
<td>
<div align='justify'\\>
An interesting problem arises of how to model continuous data onto a discrete display, while maintaining a sense of continuity. This technique is often known as anti-aliasing, and is commonly applied to fonts.<br>
The idea is that some pixels, near extremities, are coloured lighter shades, based on the area of the parent shape that is covering into each pixel (see Figure 1)
Some pixels are completely covered by the beam, others are only partially covered, hence have a covered area that can be expressed as a percentage of its total area.
<br>
The first challenge is to, given a square area, and equations of two lines, calculate the area of a square that is intersected by 1 or more lines The shape that is produced could be just a triangle (with only 2 intersections and a corner included), or a square (the whole square covered), or some other polygon, with up to 6 vertices (see Figure 2).
</div>
</td></tr></table>
<br>
<table width='660'><tr><td valign='top' width='255'>
<div id='image2' style='float:left;width:150px' class='figure'>
<img src='content/programming/areacalc/7_2.png' style='margin-bottom:4px;'><br><small><b>Figure 1</b> - 'Continuous' beam passing through discrete pixels</small></div><br />
<div id='images3' style='float:left;width:255px;' class='figure'>
<img src='content/programming/areacalc/7_3.png' style='margin-bottom:4px;'><br>
<img src='content/programming/areacalc/7_4.png' style='margin-bottom:4px;'><br>
<img src='content/programming/areacalc/7_5.png' style='margin-bottom:4px;'><br>
<small><b>Figure 2</b> - Area of different polygons, calculated by splitting into triangles</small></div>
</td><td valign='top'>
<div align='justify'\\>
This area can be calculated by working out the vertices that make up the polygon, and then splitting the polygon into the simplest shapes, triangles, which are easier to calculate the area of. This is shown in Figure 2. These images are generated by a short Python program (using the <a href='http://www.pythonware.com/products/pil/'>Python Imaging Library</a> to output the result as a bitmap), <a href='content/programming/areacalc/areacalc.py'>[Download areacalc program]</a>.<br><br>
<table bgcolor='#eeeeee'><tr><td>
<span style='font-family:Courier'>	Usage: Python areacalc.py angle beamwidth</span><br>e.g.<br>
<span style='font-family:Courier'>	python areacalc.py 25 100</span></td></tr></table><Br>
The program uses a stack to store the points, first checking if corners lie within the beam, and then checking where the intersections are. These points are then sorted (this is important for correctly splitting the polygon into triangles). (see Figure 3 for code). (note 'points' is a stack implementation included in the file, points.a is list used for this stack.)<br><br>
The next stage of the program is to pop 3 at a time off our stack so that the line lengths and angle between them can be calculated. This can be then used (using some simple trigonometry rules) to calculate the area of the triangle. The middle point is dropped, and the first and last popped points  are pushed back onto the stack, hence the shape has been reduced by one point, loosing a triangle on the outside. The process continues until we only have 2 points left, by which time all triangle areas have been calculated. See Figure 4 for the Python code that performs this operation (note. code is included for drawing of the colourful marking triangles). See the note below, labelled "Beam & area equations", for information on the maths used in a non-python format.
<Br><br>
Areacalc2 is an animated Tk Python program that shows the different areas that are produced, given an initial angle (in degrees), and a beam width, the program continually scans the beam over the target square, showing the resulting changing areas. <a href='content/programming/areacalc/areacalc2.py'>[Download areacalc2]</a>.<br>
The next step is to perform this operation on multiple squares, or on an area covered by pixels (squares of size 1x1). The Areacalc3 program, when given a square size, generates a list of squares (within a certain range), and performs the operation on all of them. <a href='content/programming/areacalc/areacalc3.py'>[Download areacalc3]</a><br>See Figure 5 for a still image of the program at work.
<br><br>
<table bgcolor='#eeeeee'><tr><td>
<span style='font-family:Courier;'>	Usage: python areacalc3.py angle beamwidth squaresize
<span><br>e.g.<br>
	python areacalc3.py 25 100 50</span></td></tr></table>
</td></tr></table><br>

<div style='border-style:solid;border-width:1px;padding:8px;margin:10px;padding-top:0px;border-color:#c0c0c0;'' id='figure3'>
<small><b>Figure 3</b> - Vertex detecting and ordering code</small>
<pre>
<span class='pycomment'># check for corners</span>
<span class='pykeyword'>for</span> corn <span class='pykeyword'>in</span> bCorners:
    (yC1,yC2) = calcY(corn[0],beamWidth,theta)
    <span class='pykeyword'>if</span>(corn[1]>=yC1 and corn[1]<=yC2):
         points.push((corn[0],corn[1]))
         
<span class='pycomment'># check intersections</span>
<span class='pykeyword'>for</span> calc <span class='pykeyword'>in</span> [(bStartX,calcY(bStartX,beamWidth,theta)),
            (bEndX,calcY(bEndX,beamWidth,theta))]:
    <span class='pykeyword'>if</span>(calc[1][0]>=bStartY and calc[1][0]<=bEndY):
        points.push((calc[0],calc[1][0]))
    <span class='pykeyword'>if</span>(calc[1][1]>=bStartY and calc[1][1]<=bEndY):
        points.push((calc[0],calc[1][1]))
        
<span class='pykeyword'>for</span> calc <span class='pykeyword'>in</span> [(bStartY,calcX(bStartY,beamWidth,theta)),
        (bEndY,calcX(bEndY,beamWidth,theta))]:
    <span class='pykeyword'>if</span>(calc[1][0]>=bStartX and calc[1][0]<=bEndX):
        points.push((calc[1][0],calc[0]))
    <span class='pykeyword'>if</span>(calc[1][1]>=bStartX and calc[1][1]<=bEndX):
        points.push((calc[1][1],calc[0]))

line1 = []
line2 = []
line3 = []
line4 = []
<span class='pykeyword'>for</span> point <span class='pykeyword'>in</span> points.a:
    <span class='pykeyword'>if</span>(point[1]==bStartY):
        line1.append(point)
    <span class='pykeyword'>elif</span>(point[1]==bEndY):
        line3.append(point)
    <span class='pykeyword'>elif</span>(point[0]==bEndX):
        line2.append(point)
    <span class='pykeyword'>elif</span>(point[0]==bStartX):
        line4.append(point)

line1.sort(<span class='pykeyword'>lambda</span> x,y: <span class='pyfunc'>cmp</span>(x[0],y[0]))
line2.sort(<span class='pykeyword'>lambda</span> x,y: <span class='pyfunc'>cmp</span>(x[1],y[1]))
line3.sort(<span class='pykeyword'>lambda</span> y,x: <span class='pyfunc'>cmp</span>(x[0],y[0]))
line4.sort(<span class='pykeyword'>lambda</span> y,x: <span class='pyfunc'>cmp</span>(x[1],y[1]))

points.a = line1+line2+line3+line4
</pre>
</div>
<div class='figure' id='figure4'><small><b>Figure 4</b> - Triangle area calculation</small>
<pre>
colour = (0xFF,0x90,0x00)
cx=0
areaTotal = 0
<span class='pykeyword'>while</span>(<span class='pyfunc'>len</span>(points.a)>2):
    p1 = points.pop()
    p2 = points.pop()
    p3 = points.pop()

    a = distance(p1,p2)
    b = distance(p1,p3)
    c = distance(p2,p3)
    
    phi = math.asin((a**2 - b**2 + c**2)/(2*a*c))
    
    area = 0.5 * a * c * math.cos(phi)
    areaTotal+=area
    draw.polygon([p1,p2,p3],fill=colour,outline=(0,0,0))
    
    points.push(p3)
    points.push(p1)
    
    colour = (colour[0],colour[1]+16,colour[2])
    cx+=1
</pre>
</div><br />
<div id='maths' style='border:solid 1px #ccc;width:650px;padding:7px;'>
<b>Beam & area equations:-</b><br>
<img src='content/programming/areacalc/diag.png'><br><br>
<table width='650' cellspacing='5' cellpadding='5'><tr><td width='50%'>
Equations for the y co-ordinates of the beam extremities, given <b>x</b>, the angle of the beam <b>theta</b>, and the beam width <b>b</b>.<br><br>
<img src='content/programming/areacalc/eqn1.png'><br>
<img src='content/programming/areacalc/eqn2.png'>
</td>
<td width='50%'>
Equations for the x co-ordinates of the beam extremities, given <b>y</b>, the angle of the beam <b>theta</b>, and the beam width <b>b</b>.<br><br>
<img src='content/programming/areacalc/eqn3.png'><br>
<img src='content/programming/areacalc/eqn4.png'>
</td></tr></table><br>
Area calculation equations given points a, b and c:-<br>
<img src='content/programming/areacalc/eqn5.png'><br>
<img src='content/programming/areacalc/eqn6.png'><br><br>
Distance between two points (x1,y1),(x2,y2):-<br>
<img src='content/programming/areacalc/eqn7.png'>
</div>
<table><tr><td>
	<div style='border-style:solid;border-width:1px;padding:8px;margin:10px;padding-top:0px;border-color:#c0c0c0;width:215;'' align='center' id='figure5'>
<img src='content/programming/areacalc/7_6.png' style='margin-bottom:4px;'><br><small><b>Figure 5</b> - Multiple squares being intersected, generated from:-<br>python areacalc3.py 10 100 50.</small>
</div></td><td valign='top'>
<div align='justify'><br />
Now that we have the area being calculated for any number/size of 'squares' we want, we can now start to reach our original goal, of using this data to display continuous data on our discrete displays, but using shading techniques to make the data appear continuous and 'smooth'.<br>
The program beam.py does exactly this. Instead of drawing the orange triangles the squares are shaded in proportion to the square's intersected area with the beam. In this program there are no outlines around each square so that one can see the effects more prominently if the square size is reduced down to 2x2, or even 1x1 (pixel level) [Note: this is pretty slow, the algorithm is not overly efficient, and a lot of calculations have to be made!]. <a href='content/programming/areacalc/beam.py'>[Download beam]</a>.
</div>
</td></tr></table>
<div align='justify'>

The usage is the same as areacalc3 (python beam.py angle beamwidth squaresize). See Figure 6 and 7 for the program in use. As you can clearly see from Figure 6, the squares are being shaded differently at the extremetities (produced by Python beam.py 10 100 10).<br>
Figure 7 shows 1 pixel squares, and the line passing through, creating a nice smooth line.</div><br>
<table><tr><td>
<div style='width:215;' class='figure' id='figure6'>
<img src='content/programming/areacalc/7_7.png' style='margin-bottom:4px;'><br><small><b>Figure 6</b> - Multiple squares being intersected, and shaded accordingly</small></div></td><td>
<div style='border-style:solid;border-width:1px;padding:8px;margin:10px;padding-top:0px;border-color:#c0c0c0;width:215;'' id='figure7'>
<img src='content/programming/areacalc/7_8.png' style='margin-bottom:4px;'><br><small><b>Figure 7</b> - Pixel size squares, being intersected, and shaded accordingly</small></div></td></tr></table>
<table><tr><td>
<div align='justify'>Our goal has been achieved, we can now represent our continuous line in a psuedo-continuous fashion on computer, and in the process we have explored how to calculate the area of a polygon. Note that our method of calculating a polygon's areacalc is not suitable for all polygons, and is not particurlarly efficient. It will in fact only work for shapes that are convex. A convex 2D shade is one in which all inside angles are less than or equal to 180 degrees. However with a concave shape has at least one inside angles that is greater than 180 degrees (see Figure 8).</div></td><td><div style='width:190;' class='figure' id='figure8'><img src='content/programming/areacalc/7_9.png'><br><br><small><b>Figure 8</b> - Examples of convex and concave shapes</small></div></td></tr></table>
Below is code written in Haskell that presents a more efficient algorithm for calculating the area of convex polygons, and then a more advanced algorithm for calculating the areas of convex and concave polygons.
<div class='figure' id='figure9'>
<small><b>Figure 9</b> - Haskell code for calculating the area of only convex polygons, adapted by Daniel James from "The Haskell School of Expression - by Paul Hudak (c. Cambridge Press 2000)"</small><br>
<pre>
type Vertex = (Float, Float)
type Polygon = [Vertex]

distBetween :: Vertex -> Vertex -> Float
distBetween (x1,y1) (x2,y2) = sqrt ((x1-x2)^2 + (y1-y2)^2)

triArea :: Vertex -> Vertex -> Vertex -> Float
triArea v1 v2 v3 = let a = distBetween v1 v2;
                       b = distBetween v2 v3;
                       c = distBetween v3 v1;
                       s = 0.5 * (a+b+c);
                    in sqrt (s * (s-a) * (s-b) * (s-c))

area :: Polygon -> Float
area (v1:vs)  = polyArea vs
   where polyArea       :: [Vertex] -> Float;
      polyArea (v2:v3:vs') = (triArea v1 v2 v3) + (polyArea (v3:vs'));
      polyArea _           = 0
</pre>
</div>

<div style='border-style:solid;border-width:1px;padding:8px;margin:10px;padding-top:0px;border-color:#c0c0c0;' id='figure10'>
<small><b>Figure 10</b> - Haskell code for calculating the area of convex <b>and</b> concave polygons, written by Daniel James</small>
<pre>
trapeziumArea :: Float -> Vertex -> Vertex -> Float
trapeziumArea b (x1,y1) (x2,y2) = 
     0.5 * ((y1-b)+(y2-b)) * abs (x2-x1)

minY    :: [Vertex] -> Float
minY xs = foldl (\\\\z (_,y) -> min z y) 0 xs

isLeft               :: Vertex -> Vertex -> Float
isLeft (x1,_) (x2,_) = if x1>x2 then 1 else -1

isZeroA               :: Vertex -> Vertex -> Bool
isZeroA (x1,_) (x2,_) = x1==x2

polygonArea              :: Polygon -> Float
polygonArea vs = 
    let base = minY vs
    in abs ( polygonArea' base vs )

polygonArea'              :: Float -> Polygon -> Float
polygonArea' _ [v]        = 0
polygonArea' b (v1:v2:vs) = 
    (if isZeroA v1 v2
    then 0
     else ((isLeft v1 v2)*(trapeziumArea b v1 v2)))
     + polygonArea' b (v2:vs)
</pre>
<b>Sample usage:-</b>
<pre>
polygonArea [(1.0,1.0),(1.0,2.0),(2.0,2.0),(2.0,1.0)]
</pre>
(area of 1x1 square).
</div>
Note how Figure 9 uses a more efficient means of calculating the area of a triangle, which does not need the calculation of the angle between two sides. 
The relevant code section is:-
<div class='figure'>
<pre>..... let a = distBetween v1 v2;
                       b = distBetween v2 v3;
                       c = distBetween v3 v1;
                       s = 0.5 * (a+b+c);
                    in sqrt (s * (s-a) * (s-b) * (s-c))
.....
</pre>
<img src='content/programming/areacalc/eqn8.png'><br>
<img src='content/programming/areacalc/eqn9.png'>
</div>
<div align='justify'>
Figure 10 employs a method of calculating trapezium areas, instead of triangles. This is (tentatively) a more efficient means of polygon area calculation.<br>
You may want to use these formulas for increased speed of calculation.
<br><br>
If you would like to modify/edit/use any of the code in this article, then please do. There are definately algorithmic improvements that can be made, and there is plenty of work that steams from this, related to anti-aliasing, and polygon manipulation related techniques. The sample applications are good fun to play with, and are reasonably interesting as well.
</div>
Please leave any feedback,<br>
Dom. Orchard
<br><br>
<b>Bibliography</b><br><br>
Dewdney, A.K. (2001) <i>The (new) Turing Omnibus</i>, W.h. Freeman / Owl Books<br><br>
Hudak, P (2000) <i> The Haskell School of Expression</i>, Cambridge Press<br><br>
<b>Acknowledgements</b><br><br>
Daniel James for the adapted Haskell code for concave polygons and for convex & concave polygon code.
</div>
<a href='blog.php?filter=Programming'>Programming</a> |  <a href='index.php?action=view&id=4'>Comments (3)</a>]]></description>
<pubDate>Wed, 05 Oct 2005 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=4#comments</comments>
	               	</item>

			<item>
			<title>2007-10-21 - Hello World</title> 
			<link>http://dorchard.co.uk/index.php?id=3</link>
			<author>Dominic Orchard</author>
<description><![CDATA[<b>The first post</b><br /><br />Hello all,<br />
This is my new website up and running. I tried to keep the website as simple as possible so that there is not clutter around the content. I hope the design works out fine on all browsers (I have only tested IE and Firefox), please let me know if there are any issues.<br />
Now I have to fill in all the old content! The old website can be found at <a href='http://riftor.g615.co.uk/index_old.php'>here</a><br />
Cheers!<a href='blog.php?filter=General'>General</a> |  <a href='index.php?action=view&id=3'>Comments (4)</a>]]></description>
<pubDate>Sun, 21 Oct 2007 00:00:00 +0000</pubDate>
<comments>http://dorchard.co.uk/index.php?id=3#comments</comments>
	               	</item>
</channel> 
	                </rss>