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

<channel>
	<title>Steffen Haugk</title>
	<atom:link href="http://haugk.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://haugk.co.uk</link>
	<description></description>
	<lastBuildDate>Sun, 25 Nov 2012 12:39:35 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Luma &#8211; Rec. 601 vs Rec. 709</title>
		<link>http://haugk.co.uk/2012/11/22/luma-rec-601-vs-rec-709/</link>
		<comments>http://haugk.co.uk/2012/11/22/luma-rec-601-vs-rec-709/#comments</comments>
		<pubDate>Thu, 22 Nov 2012 22:49:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Legacy]]></category>

		<guid isPermaLink="false">http://haugk.co.uk/?p=198</guid>
		<description><![CDATA[When an image is taken by an electronic camera, two aspects of each point have to be recorded. One is the colour (chroma), the other the brightness (luma). It is common to represent a colour by means of a red, a green, and a blue value (RGB). Each colour can have a value between 0 [...]]]></description>
				<content:encoded><![CDATA[<p>When an image is taken by an electronic camera, two aspects of each point have to be recorded. One is the colour (<em>chroma</em>), the other the brightness (<em>luma</em>). It is common to represent a colour by means of a red, a green, and a blue value (RGB). Each colour can have a value between 0 and 255. The most widely used digital image formats use an RGB colour space.</p>
<p>If all colour information is taken away, all that is left is a map of brightness, aka a greyscale image. But RGB image formats do not store luma (<em>Y&#8217;</em>) separately. To achieve this effect, the luma (brightness) has to be deduced from the colour components. The most common method to convert an image to greyscale is by setting the grey value to the weighted sum of the colour&#8217;s red, green and blue values, using the following formula:<span id="more-198"></span></p>
<p><img src="//s0.wp.com/latex.php?latex=Y%27+%3D+0.3+R+%2B+0.59+G+%2B+0.11+B&#038;bg=ffffff&#038;fg=000&#038;s=0" alt="Y&#039; = 0.3 R + 0.59 G + 0.11 B" title="Y&#039; = 0.3 R + 0.59 G + 0.11 B" class="latex" /><br />
</p>
<p>Of course RGB formats do not have a &#8216;grey value&#8217;. What will happen is, all three colour values are set to Y&#8217;. This results in an greyscale image. No colours can be perceived. Note that if a point has already a grey value (R=G=B), the luma of that point will be Y&#8217;=R=G=B. That is because 0.3 + 0.59 + 0.11 = 1.</p>
<p>The colour components are weighted because of the perceived difference of brightness of colours with the same value. For example, a green value 208 (0xD0) is perceived to be brighter than a red value of 208, and that again brighter as a blue value of 208. See if you agree:</p>
<div style="width:300px;background-color:#D00000">&nbsp;</div>
<div style="width:300px;background-color:#00D000">&nbsp;</div>
<div style="width:300px;background-color:#0000D0">&nbsp;</div>
<p></p>
<p>Converted to greyscale, these colours translate to (have a luma of)</p>
<ul>
<li>R = 62 = 0.3 x 208</li>
<li>G = 123 = 0.59 x 208</li>
<li>B = 23 = 0.11 x 208</li>
</ul>
<p></p>
<p>And if we now show these grey values:</p>
<div style="width:300px;background-color:#3E3E3E">&nbsp;</div>
<div style="width:300px;background-color:#7B7B7B">&nbsp;</div>
<div style="width:300px;background-color:#171717">&nbsp;</div>
<p></p>
<p>To turn this around, can we find different colour values that have the same luma? Of course. If we want to stick with the primary colours and completely disregard combinations of RGB, we immediately realise, that the highest luma we can achieve in blue is 255 x 0.11 = 28 = 0x1C. Further we find:</p>
<ul>
<li>Y&#8217;<sub>R</sub> = 28 = 0.3 x 93</li>
<li>Y&#8217;<sub>G</sub> = 28 = 0.59 x 47</li>
<li>Y&#8217;<sub>B</sub> = 28 = 0.11 x 255</li>
</ul>
<p></p>
<p>Let&#8217;s have a look how these colours are displayed:</p>
<div style="width:300px;background-color:#5D0000">&nbsp;</div>
<div style="width:300px;background-color:#002F00">&nbsp;</div>
<div style="width:300px;background-color:#0000FF">&nbsp;</div>
<p></p>
<p>Whether these colours look like they have the same brightness largely depends on your screen. On my laptop it looks as if blue is way brighter than red and green. I wonder if anybody still has a CRT monitor, maybe the colours are equally bright on one of those?</p>
<p>The 0.3 / 0.59 / 0.11 rule is very simple, it can never be right for all monitors or even one monitor. It is based on the recommendation of Rec. 601[1]. The exact values are:</p>
<p><img src="//s0.wp.com/latex.php?latex=Y%27+%3D+R+%5Ccdot+0.299+%2B+G+%5Ccdot+0.587+%2B+B+%5Ccdot+0.114&#038;bg=ffffff&#038;fg=000&#038;s=0" alt="Y&#039; = R &#92;cdot 0.299 + G &#92;cdot 0.587 + B &#92;cdot 0.114" title="Y&#039; = R &#92;cdot 0.299 + G &#92;cdot 0.587 + B &#92;cdot 0.114" class="latex" /><br />
</p>
<p>It appears this is how PAL/SECAM/NTSC systems calculate luma. HDTV uses an amended formula according to Rec. 709[2]:</p>
<p><img src="//s0.wp.com/latex.php?latex=Y%27+%3D+R+%5Ccdot+0.2126+%2B+G+%5Ccdot+0.7152+%2B+B+%5Ccdot+0.0722&#038;bg=ffffff&#038;fg=000&#038;s=0" alt="Y&#039; = R &#92;cdot 0.2126 + G &#92;cdot 0.7152 + B &#92;cdot 0.0722" title="Y&#039; = R &#92;cdot 0.2126 + G &#92;cdot 0.7152 + B &#92;cdot 0.0722" class="latex" /><br />
</p>
<p>Blue comes out even darker, and green is brighter still. To illustrate this point, try to move your mouse over the image below. A grey vertical stripe will appear around the mouse position. Watch closely, above the mouse pointer grey is calculated according to Rec.&nbsp;601, below the mouse pointer according to Rec.&nbsp;709. You will notice that 601 red is lighter, and 601 green is darker than under 709.<br />
<em>(Refresh page if you can&#8217;t see the image)</em></p>

<canvas id="canvas" style="cursor: crosshair" width="621", height="438"></canvas>
<canvas id="canvasCol" style="display:none" width="621", height="438"></canvas>
<canvas id="canvasPAL" style="display:none" width="621", height="438"></canvas>
<canvas id="canvasHDTV" style="display:none" width="621", height="438"></canvas>
<script type="application/javascript">

	var canCol = document.getElementById("canvasCol");
	var ctxCol = canCol.getContext("2d");
	var canvMain = document.getElementById("canvas");
	var width = canvMain.width;
	var height = canvMain.height;
	var ctxMain = canvMain.getContext("2d");
	ctxMain.font = '16pt Courier';
	ctxMain.fillStyle = '#00ff00';
	var canvPAL = document.getElementById("canvasPAL");
	var ctxPAL = canvPAL.getContext("2d");
	var canvHDTV = document.getElementById("canvasHDTV");
	var ctxHDTV = canvHDTV.getContext("2d");

	function imageLoaded(ev) {
	    im = ev.target; // the image
	
	    ctxMain.drawImage(im, 0, 0);
	    ctxCol.drawImage(im, 0, 0);
	
	    // PAL
	    imageData = ctxMain.getImageData(0, 0, width, height);
	
	    for (y = 0; y < height; y++) {
	        inpos = y * width * 4; // *4 for 4 ints per pixel
	        pos = inpos;
	        for (x = 0; x < width; x++) {
	            r = imageData.data[inpos++] * 0.3;
	            g = imageData.data[inpos++] * 0.59;
	            b = imageData.data[inpos++] * 0.11;
	            a = imageData.data[inpos++];    
	
	            grey = Math.floor(r + g + b);
	
	            imageData.data[pos++] = grey;
	            imageData.data[pos++] = grey;
	            imageData.data[pos++] = grey;
	            imageData.data[pos++] = a;
	
	        }
	    }
	
	    // copy pixel data on canvas
	    ctxPAL.putImageData(imageData, 0, 0);
	
	    // HDTV
	    imageData = ctxMain.getImageData(0, 0, width, height);
	
	    for (y = 0; y < height; y++) {
	        inpos = y * width * 4;
	        pos = inpos;
	        for (x = 0; x < width; x++) {
	            r = imageData.data[inpos++] * 0.2126;
	            g = imageData.data[inpos++] * 0.7152;
	            b = imageData.data[inpos++] * 0.0722;
	            a = imageData.data[inpos++];    
	
	            grey = Math.floor(r + g + b);
	
	            imageData.data[pos++] = grey;
	            imageData.data[pos++] = grey;
	            imageData.data[pos++] = grey;
	            imageData.data[pos++] = a;
	
	        }
	    }
	
	    // copy pixel data on canvas
	    ctxHDTV.putImageData(imageData, 0, 0);
	}

	function grayStripe(x, y) {
		imageData = ctxCol.getImageData(0, 0, width, height);
		ctxMain.putImageData(imageData, 0, 0);
		
		var halfS = 65;
		left = x - halfS; if (left < 0) left = 0;
		right = 2 * halfS;
		if (x + halfS > width) right = width - x + halfS;
		imageData = ctxPAL.getImageData(left, 0, right, y);
		ctxMain.putImageData(imageData, left, 0);
		ctxMain.fillText('PAL', x-18, 20);    
		
		imageData = ctxHDTV.getImageData(left, y, right, height);
		ctxMain.putImageData(imageData, left, y);
		ctxMain.fillText('HDTV', x-25, height-8);    
	}

	canvMain.addEventListener('mousemove', function(evt) {
		var rect = canvMain.getBoundingClientRect();
		grayStripe(evt.clientX - rect.left, evt.clientY - rect.top);
	}, false);

	im = new Image();
	im.onload = imageLoaded;
	im.src = "http://haugk.co.uk/wp-content/uploads/2012/11/grey01.png"; 

</script>

<p>
<em>The author with his helmet.</em></p>
<p>Conclusion: There is no all-purpose greyscale algorithm. Different images call for different methods.</p>
<hr />
[1] <a ref="http://en.wikipedia.org/wiki/CCIR_601">ITU-R Recommendation BT.601</a><br />
[2] <a ref="http://en.wikipedia.org/wiki/Rec._709">ITU-R Recommendation BT.709</a></p>
]]></content:encoded>
			<wfw:commentRss>http://haugk.co.uk/2012/11/22/luma-rec-601-vs-rec-709/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cogwheels with Raphaël – part 2</title>
		<link>http://haugk.co.uk/2011/06/05/cogwheels-with-raphael-part-2/</link>
		<comments>http://haugk.co.uk/2011/06/05/cogwheels-with-raphael-part-2/#comments</comments>
		<pubDate>Sun, 05 Jun 2011 09:26:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Raphaël]]></category>

		<guid isPermaLink="false">http://haugk.co.uk/?p=61</guid>
		<description><![CDATA[Teething In this article we will grow teeth on our cogwheel. We start with a wheel having 12 teeth and we double that number. As explained in the last article, we have function getPath() dedicated to generating the path in string format. To animate teething we generate the new path and then morph: 180, 180 [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Teething</strong> In this article we will grow teeth on our cogwheel. We start with a wheel having 12 teeth and we double that number. As explained in the last article, we have function <em>getPath()</em> dedicated to generating the path in string format. To animate teething we generate the new path and then morph:</p>
<pre class="brush: jscript; first-line: 111; title: ; notranslate">
teeth = 12;
paths = new Array();
paths[1] = getPath(180, 180, 120, 12, 0);
paths[2] = getPath(180, 180, 120, 24, 0);
</pre>
<p>180, 180 is the centre point, 120 is the radius, and 12 &#038; 24 are number of teeth. The function to morph is:</p>
<pre class="brush: jscript; first-line: 126; title: ; notranslate">
function morph()
{
	teeth = 36 - teeth;
	big.animate({path:paths[teeth/12]},5000); 
}
</pre>
<p>As <em>teeth</em> oscillates between 12 and 24, the path is set to either paths[1] or paths[2]. 5000 is the duration of the animation in milliseconds. We are ready to go. Press <em>Morph</em>!</p>
<p>
<!-- iframe plugin v.2.6 wordpress.org/extend/plugins/iframe/ -->
<iframe width="640" height="400" src="http://www.haugk.co.uk/ttc/cog-02.html" scrolling="no" class="iframe-class" frameborder="0"></iframe><br />
</p>
<p>Oops, something went wrong. Looks like when we double or halve the number of teeth, Rapha&euml;l  is messing up the points on the path that are for teeth and the points for the holes. <span id="more-61"></span>A point is a point, Rapha&euml;l has no concept of what the points are for. The best solution to this I could think of is to give the 12 teeth cogwheel twice as many points, the second half all being identical to the last of the first half, if that makes sense. The cogwheel will still look the same, but when morphed to a 24 teeth cogwheel the number of points is identical and hence the allocation of points to teeth and holes is the same. </p>
<p>In the code that builds the path we add four dummy points for every tooth we are planning to add. This is because every tooth consists of two half circles, one convex and one concave, each requiring a start and an end point:</p>
<pre class="brush: jscript; first-line: 68; title: ; notranslate">
/* add extras */
extras = 4 * extras;
while (extras--)
{
	path = path +&quot; L &quot; +(cx+x1)+&quot;,&quot;+(cy+y1);
}
</pre>
<p>This should do the trick. Or does it? Click <em>Morph</em> below. It works great for one tooth, and for the 12/24 teeth cog the holes stay intact. But it still doesn&#8217;t look right.</p>
<p>
<!-- iframe plugin v.2.6 wordpress.org/extend/plugins/iframe/ -->
<iframe width="640" height="400" src="http://www.haugk.co.uk/ttc/cog-03.html" scrolling="no" class="iframe-class" frameborder="0"></iframe><br />
</p>
<p>What we can do is add one tooth at the time. After all, this seems to work. Click on <em>Morph</em> to see this in action.</p>
<p>
<!-- iframe plugin v.2.6 wordpress.org/extend/plugins/iframe/ -->
<iframe width="640" height="400" src="http://www.haugk.co.uk/ttc/cog-04.html" scrolling="no" class="iframe-class" frameborder="0"></iframe><br />
</p>
<p>How is it done? We use 13 paths, one for each new tooth. Then we animate from one path to the next. Since we are using the same paths over and over again in this little app it makes sense to store them in an array. </p>
<pre class="brush: jscript; first-line: 112; title: ; notranslate">
paths = new Array();
paths[12] = getPath(180, 180, 120, 12, 12);
paths[13] = getPath(180, 180, 120, 13, 11);
paths[14] = getPath(180, 180, 120, 14, 10);
paths[15] = getPath(180, 180, 120, 15, 9);
paths[16] = getPath(180, 180, 120, 16, 8);
paths[17] = getPath(180, 180, 120, 17, 7);
paths[18] = getPath(180, 180, 120, 18, 6);
paths[19] = getPath(180, 180, 120, 19, 5);
paths[20] = getPath(180, 180, 120, 20, 4);
paths[21] = getPath(180, 180, 120, 21, 3);
paths[22] = getPath(180, 180, 120, 22, 2);
paths[23] = getPath(180, 180, 120, 23, 1);
paths[24] = getPath(180, 180, 120, 24, 0);
</pre>
<p>The last two parameters passed to <em>getPath()</em> are the number of actual and dummy teeth.  See how the number of teeth &#8211; actual plus dummy &#8211; is constant. These variables could easily be set in a loop, or be calculated when needed. In our case it makes sense to store the paths. In real life, once the number of teeth has been reduced to the final count &#8211; in our case 12, be should then get rid of the dummy points in the path with:</p>
<pre class="brush: jscript; title: ; notranslate">
cog.attr({path: getPath(180, 180, 120, 12, 0)});
</pre>
<p>Time to take a look at the <em>morph()</em> function.</p>
<pre class="brush: jscript; first-line: 138; title: ; notranslate">
function morph()
{
	if (teeth == 12)
		grow(); /* grow teeth */
	else
		lose(); /* lose teeth */
}
function grow()
{
	if (teeth &lt; 24)
	cog.animate({path:paths[++teeth]},500,grow); 
}
function lose()
{
	if (teeth &gt; 12)
	cog.animate({path:paths[--teeth]},500,lose); 
}
</pre>
<p>Depending on the number of teeth the cogwheel has at the moment, we will either grow teeth or lose teeth. The <em>grow()</em> function animates the path to the one with one more tooth, the <em>lose()</em> function animates the path to the one with one less tooth. See how both function use the <em>animate</em> method with the callback argument, calling itself once one step of the animation had finished. Only until we have reached the intended number of teeth &#8211; 24 or 12 respectively.</p>
<p>Adding one tooth at a time is great, but why don&#8217;t we try and add the teeth in between the existing teeth? Then we only need two paths to morph between.</p>
<p>
<!-- iframe plugin v.2.6 wordpress.org/extend/plugins/iframe/ -->
<iframe width="640" height="400" src="http://www.haugk.co.uk/ttc/cog-05.html" scrolling="no" class="iframe-class" frameborder="0"></iframe><br />
</p>
<p>While we animate the growing teeth so elegantly, the wheel rolls from side to side as well. And why not?</p>
<pre class="brush: jscript; first-line: 125; title: ; notranslate">
paths = new Array();
paths[1] = getPath(170, 180, 120, 12, 12);
paths[2] = getPath(440, 180, 120, 24, 0);
 
function morph()
{
	teeth = 36 - teeth;
	cog.animate({path:paths[teeth/12], rotation:teeth*7.5},8000,'&lt;&gt;'); 
}
</pre>
<p>Let&#8217;s finish this article with a bit of fun.</p>
<p>
<!-- iframe plugin v.2.6 wordpress.org/extend/plugins/iframe/ -->
<iframe width="640" height="400" src="http://www.haugk.co.uk/ttc/cog-06.html" scrolling="no" class="iframe-class" frameborder="0"></iframe><br /></p>
]]></content:encoded>
			<wfw:commentRss>http://haugk.co.uk/2011/06/05/cogwheels-with-raphael-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Thoughts on Fibonacci Numbers</title>
		<link>http://haugk.co.uk/2011/05/30/thoughts-on-fibonacci-numbers/</link>
		<comments>http://haugk.co.uk/2011/05/30/thoughts-on-fibonacci-numbers/#comments</comments>
		<pubDate>Mon, 30 May 2011 08:17:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Legacy]]></category>

		<guid isPermaLink="false">http://haugk.co.uk/?p=55</guid>
		<description><![CDATA[In 1988, round about the time I first learned of Binet&#8217;s formula which appears to have been described by de Moivre some 50 years before Binet was born, I was calculating for no good reason on my very own Casio FX730P when a friend looked over my shoulder and made a discovery. She had noticed [...]]]></description>
				<content:encoded><![CDATA[<p>In 1988, round about the time I first learned of Binet&#8217;s formula</p>
<img src="//s0.wp.com/latex.php?latex=F_n+%3D+%5Cfrac%7B%5Cleft+%281+%2B+%5Csqrt%7B5%7D+%5Cright+%29%5En+-+%5Cleft+%281+-+%5Csqrt%7B5%7D+%5Cright+%29%5En%7D%7B2%5En+%5Csqrt%7B5%7D%7D+%5Cqquad+%5Cqquad+%5Cforall+n+%5Cgeq+0&#038;bg=ffffff&#038;fg=000&#038;s=0" alt="F_n = &#92;frac{&#92;left (1 + &#92;sqrt{5} &#92;right )^n - &#92;left (1 - &#92;sqrt{5} &#92;right )^n}{2^n &#92;sqrt{5}} &#92;qquad &#92;qquad &#92;forall n &#92;geq 0" title="F_n = &#92;frac{&#92;left (1 + &#92;sqrt{5} &#92;right )^n - &#92;left (1 - &#92;sqrt{5} &#92;right )^n}{2^n &#92;sqrt{5}} &#92;qquad &#92;qquad &#92;forall n &#92;geq 0" class="latex" />
<p></p>
<p>which appears to have been described by <em>de Moivre</em> some 50 years before <em>Binet</em> was born, I was calculating</p>
<img src="//s0.wp.com/latex.php?latex=F_n+%5Cbmod%7Bn%7D&#038;bg=ffffff&#038;fg=000&#038;s=0" alt="F_n &#92;bmod{n}" title="F_n &#92;bmod{n}" class="latex" />
<p></p>
<p>for no good reason on my very own Casio FX730P</p>
<p><img src="http://www.haugk.co.uk/wp-content/uploads/2011/05/Casio-FX730P.jpg" alt="" title="Casio-FX730P" width="509" height="251" class="aligncenter size-full wp-image-393" /></p>
<p>when a friend looked over my shoulder and made a discovery. <span id="more-55"></span>She had noticed that </p>
<img src="//s0.wp.com/latex.php?latex=F_p+%5Cequiv+%5Cpm1+%5Cpmod%7Bp%7D+%5Cqquad+%5Cqquad+%5Ctext%7Bif+%7Dp+%5Ctext%7B+is+prime%7D%2C+p+%5Cneq+5&#038;bg=ffffff&#038;fg=000&#038;s=0" alt="F_p &#92;equiv &#92;pm1 &#92;pmod{p} &#92;qquad &#92;qquad &#92;text{if }p &#92;text{ is prime}, p &#92;neq 5" title="F_p &#92;equiv &#92;pm1 &#92;pmod{p} &#92;qquad &#92;qquad &#92;text{if }p &#92;text{ is prime}, p &#92;neq 5" class="latex" />
<p></p>
<p>(The prime 5 had soon to be excluded, since F<sub>5</sub> = 5 &equiv; 0 (mod 5).)</p>
<p>The program was modified to confirm this conjecture, at least in the Casio&#8217;s integer range. It became clear that a prime <em>p</em> was sufficient but not necessary, because early on we found</p>
<img src="//s0.wp.com/latex.php?latex=F_%7B4%7D+%5Cequiv+-1+%5Cpmod%7B4%7D%5C%5CF_%7B14%7D+%5Cequiv+-1+%5Cpmod%7B14%7D%5C%5CF_%7B22%7D+%5Cequiv+%2B1+%5Cpmod%7B22%7D%5C%5CF_%7B26%7D+%5Cequiv+-1+%5Cpmod%7B26%7D%5C%5CF_%7B34%7D+%5Cequiv+-1+%5Cpmod%7B34%7D%5C%5CF_%7B38%7D+%5Cequiv+%2B1+%5Cpmod%7B38%7D%5C%5CF_%7B46%7D+%5Cequiv+-1+%5Cpmod%7B46%7D%5C%5CF_%7B58%7D+%5Cequiv+%2B1+%5Cpmod%7B58%7D%5C%5CF_%7B62%7D+%5Cequiv+%2B1+%5Cpmod%7B62%7D%5C%5CF_%7B74%7D+%5Cequiv+-1+%5Cpmod%7B74%7D%5C%5CF_%7B82%7D+%5Cequiv+%2B1+%5Cpmod%7B82%7D%5C%5CF_%7B86%7D+%5Cequiv+-1+%5Cpmod%7B86%7D%5C%5CF_%7B94%7D+%5Cequiv+-1+%5Cpmod%7B94%7D%5C%5C&#038;bg=ffffff&#038;fg=000&#038;s=0" alt="F_{4} &#92;equiv -1 &#92;pmod{4}&#92;&#92;F_{14} &#92;equiv -1 &#92;pmod{14}&#92;&#92;F_{22} &#92;equiv +1 &#92;pmod{22}&#92;&#92;F_{26} &#92;equiv -1 &#92;pmod{26}&#92;&#92;F_{34} &#92;equiv -1 &#92;pmod{34}&#92;&#92;F_{38} &#92;equiv +1 &#92;pmod{38}&#92;&#92;F_{46} &#92;equiv -1 &#92;pmod{46}&#92;&#92;F_{58} &#92;equiv +1 &#92;pmod{58}&#92;&#92;F_{62} &#92;equiv +1 &#92;pmod{62}&#92;&#92;F_{74} &#92;equiv -1 &#92;pmod{74}&#92;&#92;F_{82} &#92;equiv +1 &#92;pmod{82}&#92;&#92;F_{86} &#92;equiv -1 &#92;pmod{86}&#92;&#92;F_{94} &#92;equiv -1 &#92;pmod{94}&#92;&#92;" title="F_{4} &#92;equiv -1 &#92;pmod{4}&#92;&#92;F_{14} &#92;equiv -1 &#92;pmod{14}&#92;&#92;F_{22} &#92;equiv +1 &#92;pmod{22}&#92;&#92;F_{26} &#92;equiv -1 &#92;pmod{26}&#92;&#92;F_{34} &#92;equiv -1 &#92;pmod{34}&#92;&#92;F_{38} &#92;equiv +1 &#92;pmod{38}&#92;&#92;F_{46} &#92;equiv -1 &#92;pmod{46}&#92;&#92;F_{58} &#92;equiv +1 &#92;pmod{58}&#92;&#92;F_{62} &#92;equiv +1 &#92;pmod{62}&#92;&#92;F_{74} &#92;equiv -1 &#92;pmod{74}&#92;&#92;F_{82} &#92;equiv +1 &#92;pmod{82}&#92;&#92;F_{86} &#92;equiv -1 &#92;pmod{86}&#92;&#92;F_{94} &#92;equiv -1 &#92;pmod{94}&#92;&#92;" class="latex" />
<p></p>
<p>Those were all even numbers, they couldn&#8217;t be prime anyway. We were now looking for </p>
<img src="//s0.wp.com/latex.php?latex=F_n+%5Cequiv+%5Cpm1+%5Cpmod%7Bn%7D+%5Cqquad+%5Cqquad+%5Ctext%7Bwhere+%7Dn+%5Ctext%7B+is+odd+and+not+prime%7D&#038;bg=ffffff&#038;fg=000&#038;s=0" alt="F_n &#92;equiv &#92;pm1 &#92;pmod{n} &#92;qquad &#92;qquad &#92;text{where }n &#92;text{ is odd and not prime}" title="F_n &#92;equiv &#92;pm1 &#92;pmod{n} &#92;qquad &#92;qquad &#92;text{where }n &#92;text{ is odd and not prime}" class="latex" />
<p></p>
<p>Those were the first we found</p>
<img src="//s0.wp.com/latex.php?latex=F_%7B323%7D+%3D+17+%5Ccdot+19+%5Cequiv+%2B1+%5Cpmod%7B323%7D%5C%5CF_%7B2737%7D+%3D+7+%5Ccdot+17+%5Ccdot+23+%5Cequiv+%2B1+%5Cpmod%7B2737%7D%5C%5CF_%7B4181%7D+%3D+37+%5Ccdot+113+%5Cequiv+%2B1+%5Cpmod%7B4181%7D%5C%5CF_%7B5777%7D+%3D+53+%5Ccdot+109+%5Cequiv+-1+%5Cpmod%7B5777%7D%5C%5CF_%7B6479%7D+%3D+11+%5Ccdot+19+%5Ccdot+31+%5Cequiv+%2B1+%5Cpmod%7B6479%7D%5C%5CF_%7B6721%7D+%3D+11+%5Ccdot+13+%5Ccdot+47+%5Cequiv+%2B1+%5Cpmod%7B6721%7D%5C%5CF_%7B7743%7D+%3D+3+%5Ccdot+29+%5Ccdot+89+%5Cequiv+%2B1+%5Cpmod%7B7743%7D%5C%5C&#038;bg=ffffff&#038;fg=000&#038;s=0" alt="F_{323} = 17 &#92;cdot 19 &#92;equiv +1 &#92;pmod{323}&#92;&#92;F_{2737} = 7 &#92;cdot 17 &#92;cdot 23 &#92;equiv +1 &#92;pmod{2737}&#92;&#92;F_{4181} = 37 &#92;cdot 113 &#92;equiv +1 &#92;pmod{4181}&#92;&#92;F_{5777} = 53 &#92;cdot 109 &#92;equiv -1 &#92;pmod{5777}&#92;&#92;F_{6479} = 11 &#92;cdot 19 &#92;cdot 31 &#92;equiv +1 &#92;pmod{6479}&#92;&#92;F_{6721} = 11 &#92;cdot 13 &#92;cdot 47 &#92;equiv +1 &#92;pmod{6721}&#92;&#92;F_{7743} = 3 &#92;cdot 29 &#92;cdot 89 &#92;equiv +1 &#92;pmod{7743}&#92;&#92;" title="F_{323} = 17 &#92;cdot 19 &#92;equiv +1 &#92;pmod{323}&#92;&#92;F_{2737} = 7 &#92;cdot 17 &#92;cdot 23 &#92;equiv +1 &#92;pmod{2737}&#92;&#92;F_{4181} = 37 &#92;cdot 113 &#92;equiv +1 &#92;pmod{4181}&#92;&#92;F_{5777} = 53 &#92;cdot 109 &#92;equiv -1 &#92;pmod{5777}&#92;&#92;F_{6479} = 11 &#92;cdot 19 &#92;cdot 31 &#92;equiv +1 &#92;pmod{6479}&#92;&#92;F_{6721} = 11 &#92;cdot 13 &#92;cdot 47 &#92;equiv +1 &#92;pmod{6721}&#92;&#92;F_{7743} = 3 &#92;cdot 29 &#92;cdot 89 &#92;equiv +1 &#92;pmod{7743}&#92;&#92;" class="latex" />
<p></p>
<p>I could not find how these numbers were connected. Still, our initial conjecture was pretty cool. I showed it to a few mathematicians who assured me we were on to something. I never managed to prove it and eventually forgot about it. Then in May 2008 a paper captured my attention[1]. It includes reference to a proof in [2]. It turns out that the conjecture can be made more precise:</p>
<img src="//s0.wp.com/latex.php?latex=%5Ctext%7BFor+%7Dp%5Ctext%7B+a+prime%2C+%7Dk+%3E+0%5C%5CF_p+%5Cequiv%5Cbegin%7Bcases%7D+%2B1+%5Cpmod%7Bp%7D%2C+%26+p+%3D+5k%5Cpm1%5C%5C+-1+%5Cpmod%7Bp%7D%2C+%26+p+%3D+5k%5Cpm2%5Cend%7Bcases%7D&#038;bg=ffffff&#038;fg=000&#038;s=0" alt="&#92;text{For }p&#92;text{ a prime, }k &gt; 0&#92;&#92;F_p &#92;equiv&#92;begin{cases} +1 &#92;pmod{p}, &amp; p = 5k&#92;pm1&#92;&#92; -1 &#92;pmod{p}, &amp; p = 5k&#92;pm2&#92;end{cases}" title="&#92;text{For }p&#92;text{ a prime, }k &gt; 0&#92;&#92;F_p &#92;equiv&#92;begin{cases} +1 &#92;pmod{p}, &amp; p = 5k&#92;pm1&#92;&#92; -1 &#92;pmod{p}, &amp; p = 5k&#92;pm2&#92;end{cases}" class="latex" />
<p></p>
<p>[1] V. E. Hoggatt, Jr. and Marjorie Bicknell: <em>Some Congruences of the Fibonacci Numbers Modulo a Prime P</em>; Mathematics Magazine, Vol. 47, No. 4, (Sep., 1974), pp. 210-214</p>
<p>[2] G. H. Hardy, and E. M. Wright: <em>An Introduction to the Theory of Numbers</em>; 4th ed., Oxford University Press, 1960</p>
]]></content:encoded>
			<wfw:commentRss>http://haugk.co.uk/2011/05/30/thoughts-on-fibonacci-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cogwheels with Raphaël &#8211; part 1</title>
		<link>http://haugk.co.uk/2011/05/28/cogwheels-with-raphael-part-1/</link>
		<comments>http://haugk.co.uk/2011/05/28/cogwheels-with-raphael-part-1/#comments</comments>
		<pubDate>Sat, 28 May 2011 10:26:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Raphaël]]></category>

		<guid isPermaLink="false">http://haugk.co.uk/?p=68</guid>
		<description><![CDATA[As a way to learn Raphaël I want play with cogwheels. I will build this up gradually. This is the first installment. Let&#8217;s begin with two cogs. Below is a working example of them, press the buttons to try the different easings that are supported by the Raphaël animate method. First create canvas. Next define [...]]]></description>
				<content:encoded><![CDATA[<p>As a way to learn <a href="http://raphaeljs.com/">Raphaël</a> I want play with cogwheels. I will build this up gradually. This is the first installment. Let&#8217;s begin with two cogs. Below is a working example of them, press the buttons to try the different easings that are supported by the Raphaël <em>animate</em> method. </p>
<p>
<!-- iframe plugin v.2.6 wordpress.org/extend/plugins/iframe/ -->
<iframe width="580" height="430" src="http://www.haugk.co.uk/ttc/cog-01.html" scrolling="no" class="iframe-class" frameborder="0"></iframe><br />
</p>
<p>First create canvas. </p>
<pre class="brush: jscript; title: ; notranslate">
var r = Raphael(&quot;canvas&quot;, 600, 450);
</pre>
<p>Next define a <em>cogwheel()</em> function, that takes radius and number of teeth as arguments.<br />
<span id="more-68"></span></p>
<pre class="brush: jscript; first-line: 2; title: ; notranslate">
function cogwheel(radius, teeth)
{
	var path = getPath(0, 0, radius, teeth);
	var cog = r.path(path);
	
	return cog; 
}
</pre>
<p>Finally create two cogs. The radius and number of teeth of the second wheel are three times that of the first. See how we shift the wheels and set attributes like fill gradient and stroke width.</p>
<pre class="brush: jscript; first-line: 9; title: ; notranslate">
small = cogwheel(50,13).translate(343,88).attr({
	gradient: '90-#526c7a-#64a0c1',  
	stroke: '#3b4449',  
	'stroke-width': 3,  
	'stroke-linejoin': 'round'
	}); 
big = cogwheel(150,39).translate(200,230).attr({
	gradient: '90-#7a6c52-#a0c164',  
	stroke: '#49443b',  
	'stroke-width': 3,  
	'stroke-linejoin': 'round'
	});
</pre>
<p>To generate a path that describes a cogwheel, the <em>cogwheel()</em> uses function <em>getPath()</em>. This returns a string holding the path for a cogwheel. A point [x,y] on the x-axis is rotated by an angle equivalent to 360&deg;/(number of teeth). For 12 teeth this would be 30&deg;. Since a tooth consists of a convex and a concave half circle, we also need a point in the middle, hence the rotation of [x,y] by sector/2. Note how we add the coordinates of the centre point [cx,cy] to the path. This is so as to make the rotation of [x,y] around [0,0], which is the easiest.</p>
<pre class="brush: jscript; first-line: 54; title: ; notranslate">
/* now rotate */
var z = teeth;
while (z--)
{
	x1 = x * Math.cos(sector) - y * Math.sin(sector);
	y1 = x * Math.sin(sector) + y * Math.cos(sector);
	x2 = x * Math.cos(sector/2) - y * Math.sin(sector/2);
	y2 = x * Math.sin(sector/2) + y * Math.cos(sector/2);
	
	path = path + &quot; A &quot;+rs+&quot;,&quot;+rs+&quot;  0 1,1 &quot;+(cx+x2) + &quot;,&quot; + (cy+y2); 
	path = path + &quot; A &quot;+rs+&quot;,&quot;+rs+&quot;  0 0,0 &quot;+(cx+x1) + &quot;,&quot; + (cy+y1); 
	x = x1;
	y = y1;
}
</pre>
<p>This is what we have got so far. We have 12 teeth, three in each quadrant:</p>
<p><img src="http://www.haugk.co.uk/wp-content/uploads/2011/05/cog1.png" alt="" title="cog1" width="200" height="150" class="aligncenter size-full wp-image-375" /></p>
<p>It is easy to add a hole in the middle. We do this by building a circle out of two half circles.</p>
<pre class="brush: jscript; first-line: 73; title: ; notranslate">
rs1 = radius / 10;
path = path + &quot; M &quot;+(cx-rs1)+&quot;,&quot;+cy;
path = path + &quot; A &quot;+rs1+&quot;,&quot;+rs1+&quot;  0 0,0 &quot;+(cx+rs1) + &quot;,&quot;+cy; 
path = path + &quot; A &quot;+rs1+&quot;,&quot;+rs1+&quot;  0 0,0 &quot;+(cx-rs1) + &quot;,&quot;+cy; 
</pre>
<p>The trick is to make the teeth go around clockwise, and the hole in the middle counter clockwise. That way the area, that this path describes, is subtracted from the object.</p>
<p><img src="http://www.haugk.co.uk/wp-content/uploads/2011/05/cog2.png" alt="" title="cog2" width="200" height="150" class="aligncenter size-full wp-image-374" /></p>
<p>The last thing we need to do is to make the spokes by adding four fan-shaped holes. Each of these consists of two lines and two arcs. I spare you the maths. Here is the finished cogwheel:</p>
<p><img src="http://www.haugk.co.uk/wp-content/uploads/2011/05/cog3.png" alt="" title="cog3" width="200" height="150" class="aligncenter size-full wp-image-372" /></p>
]]></content:encoded>
			<wfw:commentRss>http://haugk.co.uk/2011/05/28/cogwheels-with-raphael-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pocket calculator with Raphaël &#8211; part 2: The LED display</title>
		<link>http://haugk.co.uk/2011/05/22/pocket-calculator-with-raphael-part-2-the-led-display/</link>
		<comments>http://haugk.co.uk/2011/05/22/pocket-calculator-with-raphael-part-2-the-led-display/#comments</comments>
		<pubDate>Sun, 22 May 2011 07:59:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Raphaël]]></category>

		<guid isPermaLink="false">http://haugk.co.uk/?p=44</guid>
		<description><![CDATA[Let&#8217;s have a look at some implementation details of the upside-down calculator mentioned in this post. What we are interested in is the LED display. Remember we are using Raphaël. Below is one digit of the 7 segment LED. Click the buttons to control the segments and the decimal point. Because the digit is slanted, [...]]]></description>
				<content:encoded><![CDATA[<p>Let&#8217;s have a look at some implementation details of the upside-down calculator mentioned in <a title="Pocket calculator with Raphaël" href="http://www.haugk.co.uk/2011/05/03/pocket-calculator-with-raphael/" target="_blank">this</a> post. What we are interested in is the LED display. Remember we are using <a title="Raphael JS" href="http://raphaeljs.com/" target="_blank">Raphaël</a>.</p>
<p>Below is one digit of the 7 segment LED. Click the buttons to control the segments and the decimal point.</p>
<p>
<!-- iframe plugin v.2.6 wordpress.org/extend/plugins/iframe/ -->
<iframe width="400" height="260" src="http://www.haugk.co.uk/ttc/led-display.html" scrolling="no" class="iframe-class" frameborder="0"></iframe><br />
</p>
<p>Because the digit is slanted, it can easily be put into a row to form a calculator display. There is space for the decimal point. How convinient. <span id="more-44"></span></p>
<p>Now let&#8217;s look at the simplified code for this LED digit. After creating the Rapha&euml;l canvas we set a black background for the LED digit.</p>
<pre class="brush: jscript; first-line: 20; pad-line-numbers: 2; title: ; toolbar: false; notranslate">
window.onload = function () 
{
  var r = Raphael(&quot;canvas&quot;, 240, 250);
  var display = r.rect(0,0,185,244,0).animate({fill: &quot;#000&quot;},0);
</pre>
<p>The digit is stored in a set. We push on the paths for the segments and a circle for the decimal point.</p>
<pre class="brush: jscript; first-line: 26; pad-line-numbers: 2; title: ; toolbar: false; notranslate">
  led = r.set();
  led.push(
    r.path(&quot;M 11,0 L 35,0 35,1 32,4 12,4 8,1 z&quot;),
    r.path(&quot;M 32,4 L 36,1 37,3 33,22 31,24 29,22 z&quot;),
    r.path(&quot;M 28,27 L 30,25 31,25 32,27 29,45 28,48 25,45 z&quot;),
    r.path(&quot;M 4,45 L 24,45 27,48 25,49 2,49 1,48 z&quot;),
    r.path(&quot;M 6,25 L 7,27 4,44 0,48 0,47 3,27 z&quot;),
    r.path(&quot;M 8,1 L 11,4 8,21 6,24 4,22 7,3 z&quot;),
    r.path(&quot;M 9,22 L 28,22 30,24 28,26 8,26 6,25 6,24 z&quot;),
    r.circle(34,47,2)
  );
</pre>
<p>After that the segments are filled with a dark grey.</p>
<pre class="brush: jscript; first-line: 38; pad-line-numbers: 2; title: ; toolbar: false; notranslate">
  for (var i = 0; i&lt;8; i++) 
  {
    led[i].animate({fill:colourledoff, &quot;stroke-width&quot;: 0}, 1000);
  }
}
</pre>
<p>We now need a function to switch the relevant segments on or off. First we create an array of on/off flags for every segment and every symbol, i.e. &#8217;0&#8242;..&#8217;9&#8242;, &#8216;-&#8217;, and &#8216;E&#8217;. For example, to show a &#8217;5&#8242; all segments are on apart from segments 2 and 5. We also define the colours to use for the segments.</p>
<pre class="brush: jscript; pad-line-numbers: 2; title: ; toolbar: false; notranslate">
var colourledon  = &quot;#0F0&quot;;
var colourledoff = &quot;#444&quot;;

var segments = [];
segments['0'] = new Array(1,1,1,1,1,1,0);
segments['1'] = new Array(0,1,1,0,0,0,0);
segments['2'] = new Array(1,1,0,1,1,0,1);
segments['3'] = new Array(1,1,1,1,0,0,1);
segments['4'] = new Array(0,1,1,0,0,1,1);
segments['5'] = new Array(1,0,1,1,0,1,1);
segments['6'] = new Array(1,0,1,1,1,1,1);
segments['7'] = new Array(1,1,1,0,0,0,0);
segments['8'] = new Array(1,1,1,1,1,1,1);
segments['9'] = new Array(1,1,1,1,0,1,1);
segments['-'] = new Array(0,0,0,0,0,0,1);
segments['E'] = new Array(1,0,0,1,1,1,1);
</pre>
<p>This array is used in the update() function, which takes one character as its argument:</p>
<pre class="brush: jscript; first-line: 44; pad-line-numbers: 2; title: ; toolbar: false; notranslate">
function update(num) 
{
  var x=7;
  while (x--)
  {
    if (segments[num][x])
    {
      led[x].animate({fill:colourledon}, 1000);
    }
    else
    {
      led[x].animate({fill:colourledoff}, 1000);
    }
  }
}
</pre>
<p>A similar function controls the decimal point.</p>
<pre class="brush: jscript; first-line: 61; pad-line-numbers: 2; title: ; toolbar: false; notranslate">
function decimal(pChecked) 
{
  if (pChecked)
  {
    colour=colourledon;
  }
  else
  {
    colour=colourledoff;
  }
  led[7].animate({fill:colour}, 1000);
}
</pre>
<p>This was the simplified code for one digit. In the calculator code the digit is cloned into an array of LED digits:</p>
<pre class="brush: jscript; first-line: 65; pad-line-numbers: 2; title: ; toolbar: false; notranslate">
/* clone single LED */
var ledrow=[];
ledrow[0] = led;
var z=10;
while (z--)
{
  ledrow[10-z] = ledrow[9-z].clone();
  ledrow[10-z].translate(-41,0)
}
</pre>
<p>When you flip the display and you have a really slow computer you might see the segments being dragged behind as shown in the following screenshot:</p>
<p><img src="http://www.haugk.co.uk/wp-content/uploads/2011/05/ttc01-300x179.png" alt="" title="ttc01" width="300" height="179" class="aligncenter size-medium wp-image-323" /></p>
]]></content:encoded>
			<wfw:commentRss>http://haugk.co.uk/2011/05/22/pocket-calculator-with-raphael-part-2-the-led-display/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>micro-PROLOG: variable names</title>
		<link>http://haugk.co.uk/2011/05/14/micro-prolog-variable-names/</link>
		<comments>http://haugk.co.uk/2011/05/14/micro-prolog-variable-names/#comments</comments>
		<pubDate>Sat, 14 May 2011 07:22:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Legacy]]></category>

		<guid isPermaLink="false">http://haugk.co.uk/?p=26</guid>
		<description><![CDATA[micro-PROLOG variable names consist of a prefix character followed by an optional subscript number. Here are the details: prefix character : X &#124; Y &#124; Z &#124; x &#124; y &#124; z subscript number : 0..127 The string of digits that form the subscript is interpreted as a number and internally stored as such against [...]]]></description>
				<content:encoded><![CDATA[<p>micro-PROLOG variable names consist of a prefix character followed by an optional subscript number. Here are the details:</p>
<ul>
prefix character :  X | Y | Z | x | y | z<br />
subscript number : 0..127
</ul>
<p></p>
<p>The string of digits that form the subscript is interpreted as a number and internally stored as such against a variable prefix. This is not the prefix given by yourself. Rather, prefixes are dished out in the order </p>
<ul>
X, Y, Z, x, y, z
</ul>
<p></p>
<p>Read variable names like so:</p>
<ul>
Y3 => Y<sub>3</sub><br />
x14 => x<sub>14</sub><br />
z027 => z27 => z<sub>27</sub><br />
X => X0 => X<sub>0</sub><br />
Y312 => Y56 => Y<sub>56</sub>
</ul>
<p></p>
<p>Note how 027 is equivalent to 27. Further notice that a variable prefix on its own implies subscript 0. The last line illustrates another peculiarity. Subscripts are in the range 0..127. The variable name Y312 will internally be represented as Y<sub>56</sub>. </p>
<p>Since values are stored against a prefix and its subscript, the variable name that was used when the variable has been defined is lost and cannot be restored. Prefix and subscript depend on the position of the variable in a clause. Confused?<span id="more-26"></span></p>
<p>Let&#8217;s try this. Gives us a chance to interact with the system. First we enter a program:</p>
<pre class="brush: plain; pad-line-numbers: 4; title: ; notranslate">
&amp;.((Reverse y26 X40)
1.   (Reverse y026 () X40))
&amp;.(Reverse (x0|Y2) x2 z0)
1.   (Reverse Y2 (x|x2) z0))
&amp;.(Reverse () z z)
&amp;.
</pre>
<p>The variable names are a bit silly, but this is for demonstration purposes. Now let&#8217;s run the program. </p>
<pre class="brush: plain; first-line: 6; pad-line-numbers: 4; title: ; notranslate">
&amp;.?((Reverse (1 2 3 4 5 6) x8) (P x8))
(6 5 4 3 2 1)
&amp;.
</pre>
<p>It works. Time to list the <em>Reverse</em> program:</p>
<pre class="brush: plain; first-line: 8; pad-line-numbers: 4; title: ; notranslate">
&amp;.LIST (Reverse)
&amp;.((Reverse X Y)
1.   (Reverse X () Y))
&amp;.(Reverse (X|Y) Z x)
1.   (Reverse Y (X|Z) x))
&amp;.(Reverse () X X)
&amp;.
</pre>
<p>If this is what you have expected then give yourself a pat on the shoulder.</p>
<p><strong>What&#8217;s this about?</strong> The reason for this strange naming convention is simply the fact that the tokeniser has to make a distinction between variable names and constants. If it is not a variable name it is a constant.</p>
<p>These are not variable names:</p>
<ul>
K023<br />
Name<br />
post_code<br />
$temp<br />
X_01
</ul>
<p></p>
<p><strong>Stuck with it?</strong> No, not at all. The syntax rules were provided in an editable file and could thus be changed. For example, the prefix characters could be changed from </p>
<ul>
X | Y | Z | x | y | z
</ul>
<p></p>
<p>to</p>
<ul>
a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z
</ul>
<p></p>
<p>making all tokens starting with a lowercase letter followed by a number a variable name, and the rest a constant.</p>
]]></content:encoded>
			<wfw:commentRss>http://haugk.co.uk/2011/05/14/micro-prolog-variable-names/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&lt;isindex&gt; tag</title>
		<link>http://haugk.co.uk/2011/05/09/isindex-tag/</link>
		<comments>http://haugk.co.uk/2011/05/09/isindex-tag/#comments</comments>
		<pubDate>Mon, 09 May 2011 10:50:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Legacy]]></category>

		<guid isPermaLink="false">http://haugk.co.uk/?p=74</guid>
		<description><![CDATA[To send data to a www server the http client posts form data by either the GET or the POST method. But this was not always the case. The form tag has only been introduced in HTML 2.0 (IETF RFC 1866). The first specification, known as &#8220;Hypertext Markup Language (HTML)&#8221; Internet-Draft, does not mention forms. [...]]]></description>
				<content:encoded><![CDATA[<p>To send data to a www server the http client posts form data by either the GET or the POST method. But this was not always the case. The <em>form</em> tag has only been introduced in HTML 2.0 (<a href="http://tools.ietf.org/html/rfc1866">IETF RFC 1866</a>). The first specification, known as  <a href="http://www.w3.org/MarkUp/draft-ietf-iiir-html-01.txt">&#8220;Hypertext Markup Language (HTML)&#8221; Internet-Draft</a>, does not mention forms. This specification describes another mechanism to allow clients to initiate searches on the server. Surprisingly, this method is still supported by many browsers.</p>
<p><strong>&lt;isindex&gt;</strong> All that is needed is adding the <em>isindex</em> tag to the head of the html document:</p>
<pre class="brush: xml; highlight: [3]; pad-line-numbers: 4; title: ; notranslate">
&lt;html&gt;
&lt;head&gt;
&lt;isindex&gt;
...
&lt;/head&gt;
&lt;body&gt;
...
</pre>
<p>This tag would tell the browser that this document is searchable (is an index). The browser now has to provide means for the user to enter search terms. As an example here a screenshot of how Mosaic 1.0 did this in 1993.<span id="more-74"></span> The search field is placed below the rendered html page:</p>
<p><img class="aligncenter size-full wp-image-114" title="isindex-mosaic1.0-1993" src="http://www.haugk.co.uk/wp-content/uploads/2011/05/isindex-mosaic1.0-1993.png" alt="" width="545" height="453" /></p>
<p>Other browsers I have tried show the input field as part of the html page, at the very top and usually separated from the actual page by a horizontal ruler. You will find more examples, including from recent browsers, at the bottom of this post. </p>
<p>Suppose the user enters search words and presses return. What then?</p>
<p><strong>Search</strong> What happens is this: The browser requests the same page again, but this time the search words are appended to the URL. The search words are combined with the &#8216;+&#8217; sign. The separator between URL and search string is the question mark. Example:</p>
<p><code>http://www.server.com/index.html?africa+magpie</code></p>
<p>You will have three thoughts now:<br />
1. This looks kind of familiar.<br />
2. What happens if this hits the server? What does <em>search</em> mean?<br />
3. How can a html document perform a search anyway?</p>
<p>1. The URL looks like a URL passing GET parameters from a form, only &#8211; not quite. What is missing is the name of the form field:</p>
<p><code>http://www.server.com/index.html?search=africa+magpie</code></p>
<p>2. The meaning of <em>search</em> is not defined. It is up to the server to perform a search suiting the presented data. The server could highlight all search words in the document, or only display chapters with one of the search words in the title. The sky is the limit!</p>
<p>3. You are right, it can&#8217;t. The actual search would be carried out by a CGI, in those days probably a command-line executable. The easiest way to achieve this is to have the start page generated by the CGI as well. The URL could then look something like that:</p>
<p><code>http://www.server.com/cgi-bin/index.cgi?africa+magpie</code></p>
<p>The alternative is to modify index.html in this way:</p>
<pre class="brush: xml; highlight: [4]; pad-line-numbers: 4; title: ; notranslate">
&lt;html&gt;
&lt;head&gt;
&lt;isindex&gt;
&lt;base href=&quot;http://www.server.com/cgi-bin/index.cgi&quot;&gt;
...
&lt;/head&gt;
&lt;body&gt;
...
</pre>
<p>Either way, index.cgi will be able to access the search words in two ways:</p>
<p>&#8226; Each word is a command-line parameter of the executable.<br />
&#8226; The entire search string is present in the environment variable QUERY_STRING (sounds familiar?).</p>
<p><strong>Example</strong> Try it while you can. (isindex is <a href="http://htmlhelp.com/reference/html40/deprecated.html">deprecated in HTML 4</a>.) Have a look how your browser handles <em>isindex</em>. I have changed the default prompt. (Styling is possible by playing with the <em>body</em> tag.) </p>
<pre class="brush: xml; first-line: 3; pad-line-numbers: 4; title: ; notranslate">
&lt;isindex prompt=&quot;Find Shakespeare Play&quot;&gt;
</pre>
<p>Enter a word to filter the list of Shakespear&#8217;s plays:</p>
<p>
<!-- iframe plugin v.2.6 wordpress.org/extend/plugins/iframe/ -->
<iframe width="640" height="400" src="http://www.haugk.co.uk/wp/isindex.php" frameborder="1" scrolling="yes" class="iframe-class"></iframe><br />
</p>
<p><strong>Browsers</strong> Below a few examples, including recent browsers.</p>
<p>Netscape 1.1 (1995):<br />
<img class="aligncenter size-full wp-image-115" title="isindex-netscape1.1-1995" src="http://www.haugk.co.uk/wp-content/uploads/2011/05/isindex-netscape1.1-1995.png" alt="" width="496" height="60" /></p>
<p>Opera 6.0 (2001):<br />
<img class="aligncenter size-full wp-image-116" title="isindex-opera6.0-2001" src="http://www.haugk.co.uk/wp-content/uploads/2011/05/isindex-opera6.0-2001.png" alt="" width="174" height="47" /></p>
<p>Opera 7.50 (2003):<br />
<img class="aligncenter size-full wp-image-117" title="isindex-opera7.50-2003" src="http://www.haugk.co.uk/wp-content/uploads/2011/05/isindex-opera7.50-2003.png" alt="" width="454" height="96" /></p>
<p>Firefox 3.6 (2010):<br />
<img class="aligncenter size-full wp-image-112" title="isindex-ff3.6-2010" src="http://www.haugk.co.uk/wp-content/uploads/2011/05/isindex-ff3.6-2010.png" alt="" width="525" height="63" /></p>
<p>Safari 5 (2011):<br />
<img class="aligncenter size-full wp-image-118" title="isindex-safari5-2011" src="http://www.haugk.co.uk/wp-content/uploads/2011/05/isindex-safari5-2011.png" alt="" width="472" height="58" /></p>
<p>Google Chrome 11 (2011):<br />
<img class="aligncenter size-full wp-image-111" title="isindex-chrome11-2011" src="http://www.haugk.co.uk/wp-content/uploads/2011/05/isindex-chrome11-2011.png" alt="" width="471" height="62" /></p>
<p>Internet Explorer 9 (2011):</p>
<p><img class="aligncenter size-full wp-image-113" title="isindex-ie9-2011" src="http://www.haugk.co.uk/wp-content/uploads/2011/05/isindex-ie9-2011.png" alt="" width="598" height="59" /></p>
]]></content:encoded>
			<wfw:commentRss>http://haugk.co.uk/2011/05/09/isindex-tag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Animated GIFs &#8211; part 2</title>
		<link>http://haugk.co.uk/2011/05/06/animated-gifs-part-2/</link>
		<comments>http://haugk.co.uk/2011/05/06/animated-gifs-part-2/#comments</comments>
		<pubDate>Fri, 06 May 2011 07:52:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Legacy]]></category>

		<guid isPermaLink="false">http://haugk.co.uk/?p=35</guid>
		<description><![CDATA[I saw a wooden model of such a gear in 1982, and always wanted to build one myself. Instead I&#8217;ve modelled it in AutoCAD and created this GIF (around 1998).]]></description>
				<content:encoded><![CDATA[<p>I saw a wooden model of such a gear in 1982, and always wanted to build one myself. Instead I&#8217;ve modelled it in AutoCAD and created this GIF (around 1998).</p>
<p><img src="http://www.haugk.co.uk/wp-content/uploads/2011/05/gear.gif" alt="gear" title="gear" width="413" height="105" class="aligncenter size-full wp-image-40" /></p>
]]></content:encoded>
			<wfw:commentRss>http://haugk.co.uk/2011/05/06/animated-gifs-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>micro-PROLOG: programs</title>
		<link>http://haugk.co.uk/2011/05/05/micro-prolog-programs/</link>
		<comments>http://haugk.co.uk/2011/05/05/micro-prolog-programs/#comments</comments>
		<pubDate>Thu, 05 May 2011 07:32:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Legacy]]></category>

		<guid isPermaLink="false">http://haugk.co.uk/?p=31</guid>
		<description><![CDATA[In 1987 I started learning PROLOG. I had a copy of micro-PROLOG, which had been developed at the Imperial College in London. I liked the LISP-like syntax and loved learning micro-PROLOG. Here you can see my original 8&#8243; floppy. If only I had a drive to read it, I would be able to play with [...]]]></description>
				<content:encoded><![CDATA[<p>In 1987 I started learning PROLOG. I had a copy of micro-PROLOG, which had been developed at the Imperial College in London. I liked the LISP-like syntax and loved learning micro-PROLOG. </p>
<p>Here you can see my original 8&#8243; floppy. If only I had a drive to read it, I would be able to play with the interpreter again! For those who don&#8217;t know what 8&#8243; are I have included a smartcard for reference. Click to enlarge.</p>
<p><a href="http://www.haugk.co.uk/wp-content/uploads/2011/05/floppy8.jpg"><img src="http://www.haugk.co.uk/wp-content/uploads/2011/05/floppy8-296x300.jpg" alt="" title="8 inch floppy" width="296" height="300" class="aligncenter size-medium wp-image-62" /></a></p>
<p><strong>Programs</strong> What is called a function or a routine in other systems is called a <em>program</em> in micro-PROLOG. Here are the famous two clauses that define the <em>append</em> program. <span id="more-31"></span>The ampersand is the <em>supervisor</em> prompt, the dot the prompt of the <em>read</em> function. Note that on line three there is no supervisor prompt as the clause has not been entered completely. The read function displays the number of open parentheses and its prompt, the dot, to say it is ready for more input.</p>
<pre class="brush: plain; title: ; notranslate">
&amp;.((Append () x x))
&amp;.((Append (x|X) Y (x|Z))
1.     (Append X Y Z))
&amp;.
</pre>
<p>Before we try and run a program, let&#8217;s look at the SUM program for a moment. Here are examples of how it can be used:</p>
<ul>
(SUM 3 4 x) yields x = 7<br />
(SUM 1 x 9) yields x = 8<br />
(SUM x 5 11) yields x = 6
</ul>
<p></p>
<p>But there is another way to use it. Can you guess?</p>
<ul>
(SUM 17 26 43) succeeds<br />
(SUM 13 42 54) fails
</ul>
<p></p>
<p>To execute a program, the run command &#8220;?&#8221; is used. The run command will only report if the goal succeeded or failed. If the goal succeeds, the run command finishes silently and the supervisor prompt is shown. The supervisor is ready for new input.</p>
<pre class="brush: plain; first-line: 5; title: ; notranslate">
&amp;.?(SUM 1 x 9)
&amp;.
</pre>
<p>If the goal fails, run will print a &#8220;?&#8221; before handing over to the supervisor:</p>
<pre class="brush: plain; first-line: 6; title: ; notranslate">
&amp;.?(SUM 13 42 54)
?
&amp;.
</pre>
<p>To see the actual result of a calulation, a print instruction needs to be included in the goal. As an example we use PROD which does multiplication:</p>
<pre class="brush: plain; first-line: 8; title: ; notranslate">
&amp;.?((PROD x 7 35) (PP The result is x))
The result is 5
&amp;.
</pre>
<p>SUM and PROD are built-in programs. Needless to say, there are no programs for subtraction and division. One more interesting fact about the PROD program shall be mentioned here. It can be matched with four arguments, the last being the remainder of the division:</p>
<pre class="brush: plain; first-line: 10; title: ; notranslate">
&amp;.?((PROD 4 x 19 y) (PP factor x remainder y))
factor 4 remainder 3
&amp;.
</pre>
<p>To round off this post, we finally run the append function we defined at the beginning of his post. First we append one list to another.</p>
<pre class="brush: plain; first-line: 12; title: ; notranslate">
&amp;.?((Append (1 2) (3 4) x) (P x))
(1 2 3 4)
&amp;.
</pre>
<p>Next find the missing sub-list:</p>
<pre class="brush: plain; first-line: 14; title: ; notranslate">
&amp;.?((Append x (6 7) (3 4 5 6 7)) (P x))
(3 4 5)
&amp;.?((Append (1 2) x (1 2 3 4 5 6 7)) (P x))
(3 4 5 6 7)
&amp;.
</pre>
<p>Split a list:</p>
<pre class="brush: plain; first-line: 14; title: ; notranslate">
&amp;.?((Append x y (1 2 3 4 5)) (P x y))
() (1 2 3 4 5)
(1) (2 3 4 5)
(1 2) (3 4 5)
(1 2 3) (4 5)
(1 2 3 4) (5)
(1 2 3 4 5) ()
&amp;.
</pre>
<p>I know what you are thinking now. Can we use PROD for factorisation?</p>
<pre class="brush: plain; first-line: 21; title: ; notranslate">
&amp;.?((PROD x y 60) (LESS x y) (P x y))
1 60
2 30
3 20
4 15
5 12
6 10
&amp;.
</pre>
<p>Unfortunately, the built-in PROD program does not support this. </p>
<p><strong>Features</strong> There are other topics I would like to write about. I plan to do a short post on tail recursion, optimisation, the list constructor, and even on variable names.</p>
]]></content:encoded>
			<wfw:commentRss>http://haugk.co.uk/2011/05/05/micro-prolog-programs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Animated GIFs &#8211; part 1</title>
		<link>http://haugk.co.uk/2011/05/04/animated-gifs-part-1/</link>
		<comments>http://haugk.co.uk/2011/05/04/animated-gifs-part-1/#comments</comments>
		<pubDate>Wed, 04 May 2011 07:56:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Legacy]]></category>

		<guid isPermaLink="false">http://haugk.co.uk/?p=39</guid>
		<description><![CDATA[When I was a webmaster for the first time, webpages were pretty static. With my provider (demon) anyway. The only way to make anything move was an animated GIF. This train started as a cartoon from a book. There it had a diesel engine. I have ruined the joke by replacing that with a steam [...]]]></description>
				<content:encoded><![CDATA[<p>When I was a <em>webmaster</em> for the first time, webpages were pretty static. With my provider (demon) anyway. The only way to make anything move was an animated GIF. </p>
<p>This train started as a cartoon from a book. There it had a diesel engine. I have ruined the joke by replacing that with a steam engine. Then I made it go round the track (1996).</p>
<p><img src="http://www.haugk.co.uk/wp-content/uploads/2011/05/chuff.gif" alt="train" title="chuff" width="400" height="330" class="aligncenter size-full wp-image-39" /></p>
<p>The animation consists of 27 images. To safe space an optimizer was run to find those areas of a frame that have changed in relation to the previous frame. Only the first image is full size, the rest merely update an area. The next image shows this in slow motion:</p>
<p><img src="http://www.haugk.co.uk/wp-content/uploads/2011/05/chuff_boxes.gif" alt="" title="chuff_boxes" width="400" height="268" class="aligncenter size-full wp-image-60" /></p>
<p>Note that the train is pulling a &#8216;tail&#8217; of empty space. This is to get rid of the end of the last carriage.</p>
<p>The animation was created with <em>Advanced GIF Animator</em>, a Canadian software if memory serves, and the killer app of the day.</p>
]]></content:encoded>
			<wfw:commentRss>http://haugk.co.uk/2011/05/04/animated-gifs-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.634 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2013-05-21 18:56:38 -->
