<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>A Critical Systems Blog</title>
	<atom:link href="http://leepike.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://leepike.wordpress.com</link>
	<description>Thoughts on safe and secure embedded computer systems</description>
	<lastBuildDate>Fri, 20 Jan 2012 06:46:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='leepike.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/c2ede898327d02503441840e70158104?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>A Critical Systems Blog</title>
		<link>http://leepike.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://leepike.wordpress.com/osd.xml" title="A Critical Systems Blog" />
	<atom:link rel='hub' href='http://leepike.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Who&#8217;s Afraid of Software?</title>
		<link>http://leepike.wordpress.com/2012/01/19/whos-afraid-of-software/</link>
		<comments>http://leepike.wordpress.com/2012/01/19/whos-afraid-of-software/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 06:46:03 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[fear]]></category>
		<category><![CDATA[risk]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=513</guid>
		<description><![CDATA[Who&#8217;s afraid of software?  I mean viscerally, stomach-knotting afraid.  Afraid like you might be when you come across a snake or a bear, or when you are mugged.  Do you obsess about a phishing attack each time you open your email?  Do you worry there&#8217;s an eavesdropper when you join the open wifi access point [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=513&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Who&#8217;s afraid of software?  I mean viscerally, stomach-knotting afraid.  Afraid like you might be when you come across a snake or a bear, or when you are mugged.  Do you obsess about a phishing attack each time you open your email?  Do you worry there&#8217;s an eavesdropper when you join the open wifi access point in a coffee shop?  Do you worry your software will fail in your modern automobile or aircraft?</p>
<p>I listened to a <a href="http://www.freakonomics.com/2011/11/23/the-truth-is-out-there%E2%80%A6isn%E2%80%99t-it-a-new-freakonomics-radio-podcast/">Freakonomics podcast</a> about risk, uncertainty, and beliefs.  One point made during the show was that our fears are shaped by evolution&#8212;to our ancestors, it made sense to be afraid of threatening animals.  In modern life, however, our fears don&#8217;t match risks&#8212;we&#8217;d be much better off being afraid of cheeseburgers, as pointed out in the show.  Some people are afraid of modern risks.  I know people afraid of cancer, for example.</p>
<p>That got me thinking about fearing software.  Software is certainly among the most complex artifacts created by humans.  Modern <a href="http://spectrum.ieee.org/green-tech/advanced-cars/this-car-runs-on-code">cars contain 100+ million lines of code</a>.  Nearly every day there is a story about a large corporation being hacked and of <a href="http://en.wikipedia.org/wiki/Iran%E2%80%93U.S._RQ-170_incident">cyber-warfare</a> between nations.</p>
<p>My question is serious&#8212;I really do wonder if people are genuinely afraid of software.  I work in the area of software assurance, and while I take precautions against viruses, phishing attacks, etc., I don&#8217;t particularly worry about software failures, even when my life might depend on it.  This is despite issues just last year like <a href="http://www.telegraph.co.uk/motoring/8841996/Jaguar-recalls-cars-after-cruise-control-fault.html">this</a> and <a href="http://blogs.computerworld.com/15547/toyotas_lesson_software_can_be_unsafe_at_any_speed">this</a> in automotive software.  I get to see a somewhat how the sausage is made, and in general, we only exercise a small fraction of the state-space of deployed software in validation and in actual usage.  There are legitimate risks, but there seems to be very little fear.</p>
<p>Perhaps like a medical doctors stereotypically neglecting their own health, I don&#8217;t worry day-to-day about software assurance despite working in the field.  But it seems nobody else really fears software, either.</p>
<p>In the podcast, the topic of polarizing claims, like global warming, is discussed.  Outside of academic circles, one&#8217;s view on the risks of software are not so polarizing&#8212;your views on the topic won&#8217;t cause your friends or colleagues to disparage you (indeed, if anything, the main risk is likely boring others in discussing the topic!).  I wonder just what the &#8220;global warming&#8221; of software might be in the future.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/513/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/513/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/513/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/513/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/513/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/513/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/513/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=513&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2012/01/19/whos-afraid-of-software/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>Copilot featured in Aerospace America</title>
		<link>http://leepike.wordpress.com/2011/12/10/copilot-featured-in-aerospace-america/</link>
		<comments>http://leepike.wordpress.com/2011/12/10/copilot-featured-in-aerospace-america/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 19:03:36 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Copilot]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=506</guid>
		<description><![CDATA[My Copilot project, sponsored by NASA, was featured in the Aerospace America magazine &#8220;Year in Review&#8221; edition (December 2011). We recently finished up the project, which focused on solving the problem of failure in complex embedded systems (like flight control systems in commercial aircraft).  Our approach was a language called Copilot for runtime monitoring of embedded systems [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=506&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My <a href="http://leepike.github.com/Copilot/">Copilot project</a>, sponsored by NASA, was featured in the <a href="http://www.aerospaceamerica.org/Pages/TableOfContents.aspx">Aerospace America</a> magazine &#8220;Year in Review&#8221; edition (December 2011). We recently finished up the project, which focused on solving the problem of failure in complex embedded systems (like flight control systems in commercial aircraft).  Our approach was a language called Copilot for runtime monitoring of embedded systems corroborated with experiments on airspeed sensor systems and an autopilot communication link.</p>
<p>Here&#8217;s <a href="http://ti.arc.nasa.gov/m/profile/kyrozier/papers/AerospaceAmericaIntelligentSystemsYiR2011.pdf">a link</a> to the page from the magazine mentioning us from the author&#8217;s page. (The relevant paragraph is in the middle of the right column).</p>
<p>Thanks to <a href="http://corp.galois.com/">Galois</a> and the <a href="http://www.nianet.org/">National Institute of Aerospace</a> where the work was done, the NASA folks we collaborated with, and especially Alwyn Goodloe, Nis Wegmann, Sebastian Niller, and Robin Morisset who worked on the project with me.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/506/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/506/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/506/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/506/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/506/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/506/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/506/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/506/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/506/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/506/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/506/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/506/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/506/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/506/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=506&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2011/12/10/copilot-featured-in-aerospace-america/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>Stable Names in Haskell</title>
		<link>http://leepike.wordpress.com/2011/11/26/stable-names-in-haskell/</link>
		<comments>http://leepike.wordpress.com/2011/11/26/stable-names-in-haskell/#comments</comments>
		<pubDate>Sat, 26 Nov 2011 23:37:39 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Copilot]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=499</guid>
		<description><![CDATA[Stable names in GHC &#8220;are a way of performing fast (O(1)), not-quite-exact comparison between objects.&#8221;  Andy Gill showed how to use them to extract the explicit graph from writing recursive functions in his Data.Reify package (and associated paper).  It&#8217;s a great idea and very practical for embedded domain-specific languages&#8212;we&#8217;ve used the idea in Copilot to recover sharing. However, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=499&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.haskell.org/ghc/docs/latest/html/libraries/base-4.4.1.0/System-Mem-StableName.html">Stable names</a> in GHC &#8220;are a way of performing fast (O(1)), not-quite-exact comparison between objects.&#8221;  Andy Gill showed how to use them to extract the explicit graph from writing recursive functions in his <a href="http://hackage.haskell.org/package/data-reify">Data.Reify</a> package (and associated paper).  It&#8217;s a great idea and very practical for embedded domain-specific languages&#8212;we&#8217;ve used the idea in <a href="http://hackage.haskell.org/package/copilot-2.0.1">Copilot</a> to recover sharing.</p>
<p>However, consider <a href="https://gist.github.com/1385118">this example</a>, with three tests executed in GHCI.</p>
<p>For a function with type constraints, stable names fails to &#8220;realize&#8221; that we are pointing to the same object. As a couple of my colleagues pointed out, the cause is the dictionary being passed around causing new closures to be created. Simon Marlow noted that if you compile with <code>-O</code>, the explicit dictionaries get optimized away.</p>
<p>Here are the solutions I have to &#8220;fixing&#8221; the problem, in the context of a DSL:</p>
<ul>
<li>Tell your users that recursive expressions must be monomorphic&#8212;only &#8220;pure functions&#8221; over the expressions of your DSL can be polymorphic.</li>
<li>Implement a check in your reifier to see how many stable names have been created&#8212;if some upper-bound is violated, then the user has created an infinite expression, the expression is extremely large (in which case the user should try to use some sharing mechanism, such as let-expressions inside the language), or we&#8217;ve hit a stable-names issue.</li>
<li>Ensure your DSL programs are always compiled.</li>
<li>Of course, you can always take another approach, like Template Haskell or not using recursion at the Haskell level; also check out Andy Gill&#8217;s <a href="http://www.ittc.ku.edu/~andygill/paper.php?label=DSLExtract09">paper</a> for other solutions to the observable sharing problem.</li>
</ul>
<p>I don&#8217;t see how to use (deep)seq to fix the problem, at least as it&#8217;s presented in the example above, but I&#8217;d be keen to know if there are other solutions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/499/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/499/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/499/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/499/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/499/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/499/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/499/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/499/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/499/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/499/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/499/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/499/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/499/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/499/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=499&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2011/11/26/stable-names-in-haskell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>FM@Galois Talks</title>
		<link>http://leepike.wordpress.com/2011/11/10/fmgalois-talks/</link>
		<comments>http://leepike.wordpress.com/2011/11/10/fmgalois-talks/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 06:33:35 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Formal methods]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=495</guid>
		<description><![CDATA[As I posted over on the Galois blog, I recently gave a talk a couple of times on formal methods at Galois over the years (pdf). It&#8217;s been fun putting theory into practice!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=495&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As I posted over on the <a href="http://corp.galois.com/blog/2011/11/10/11-years-of-formal-methods-at-galois.html">Galois blog</a>, I recently gave a talk a couple of times on formal methods at Galois over the years (<a href="http://www.galois.com/~leepike/fm-galois.pdf">pdf</a>). It&#8217;s been fun putting theory into practice!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/495/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/495/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/495/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/495/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/495/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/495/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/495/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/495/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/495/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/495/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/495/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/495/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/495/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/495/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=495&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2011/11/10/fmgalois-talks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>Making your Ubuntu life better</title>
		<link>http://leepike.wordpress.com/2011/06/18/making-your-ubuntu-life-better/</link>
		<comments>http://leepike.wordpress.com/2011/06/18/making-your-ubuntu-life-better/#comments</comments>
		<pubDate>Sat, 18 Jun 2011 19:40:27 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=487</guid>
		<description><![CDATA[I&#8217;ve had a lot of trouble with Ubuntu 11.04 (Natty Narwhal) on a laptop (ThinkPad 420), and I&#8217;ve had problems including: Not being able to use dual monitors, Random logoffs. I tentatively think I was able to solve them with two easy fixes: Turn off Unity. You can do this in the login screen. In [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=487&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had a lot of trouble with Ubuntu 11.04 (Natty Narwhal) on a laptop (ThinkPad 420), and I&#8217;ve had problems including:</p>
<ul>
<li>Not being able to use dual monitors,</li>
<li>Random logoffs.</li>
</ul>
<p>I tentatively think I was able to solve them with two easy fixes:</p>
<ul>
<li>Turn off Unity.  You can do this in the login screen.</li>
<li>In the Update Manager, under &#8220;Settings&#8221;, check &#8220;Proposed updates&#8221;.</li>
</ul>
<p>With the proposed updates, Unity may be working; try that at your own risk.  With that, I have a reasonably stable system.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/487/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/487/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/487/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/487/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/487/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/487/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/487/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/487/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/487/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/487/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/487/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/487/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/487/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/487/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=487&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2011/06/18/making-your-ubuntu-life-better/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>Meta-Programming and eDSLs</title>
		<link>http://leepike.wordpress.com/2011/01/30/meta-programming-and-edsls/</link>
		<comments>http://leepike.wordpress.com/2011/01/30/meta-programming-and-edsls/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 21:02:04 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Copilot]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=465</guid>
		<description><![CDATA[I&#8217;ve been working on a domain-specific language that is embedded in Haskell (an &#8220;eDSL&#8221;) that essentially takes a set of Haskell stream (infinite list) equations and turns them into a real-time C program implementing the state-machine defined by the streams. It&#8217;s called Copilot, and in fact, it&#8217;s built on top of another Haskell eDSL called [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=465&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a domain-specific language that is embedded in Haskell (an &#8220;eDSL&#8221;) that essentially takes a set of Haskell stream (infinite list) equations and turns them into a real-time C program implementing the state-machine defined by the streams. It&#8217;s called <a href="http://leepike.github.com/Copilot/">Copilot</a>, and in fact, it&#8217;s built on top of another Haskell eDSL called <a href="http://hackage.haskell.org/package/atom/">Atom</a>,<sup>1</sup> which actually does the heavy lifting in generating the C code.</p>
<p>For example, here&#8217;s the Fibonacci sequence in Copilot:</p>
<pre><code>fib = do let f = varW64 "f" f .= [0,1] ++ f + (drop 1 f) </code></pre>
<p>I&#8217;ve been writing Copilot libraries recently, and I&#8217;ve had the following realization about eDSLs and meta-programming (let me know if someone has had this idea already!). Many languages treat meta-programming as a second-class feature&#8212;I&#8217;m thinking of macros used by the C preprocessor, for example (it&#8217;s probably generous even to call the C preprocessor &#8216;meta-programming&#8217;). One reason why Lisp-like languages were exciting is that the <em>language</em> is a first-class datatype, so meta-programming is on par with programming. In my experience, you don&#8217;t think twice about meta-programming in Lisp. (Haskell is more like C in this regard&#8212;you do think twice before using Template Haskell.)</p>
<p>So languages generally treat meta-programming as either second-class or first-class. What&#8217;s interesting about eDSLs, I think, is that they treat meta-programming as first-class, but programming as <em>second</em>-class! This isn&#8217;t surprising, since an eDSL is a first-class datatype, but the language is <em>not</em> first-class&#8212;its host language is.</p>
<p>Practically, what this means is that you spend very little time actually writing eDSL programs but rather <em>generating</em> eDSL programs. It is natural to layer eDSLs on top of other eDSLs.</p>
<p>This is just how Copilot came about: I was writing various Atom programs and realized that for my purposes, I just needed a restricted set of behaviors provided by Atom that are naturally represented by stream equations (and make some other tasks, like writing an interpreter, easier).</p>
<p>But as soon as Copilot was written, we<sup>2</sup> started writing libraries implementing past-time linear temporal logic (LTL) operators, bounded LTL operators, fault-tolerant voting algorithms, regular expressions, and so on.</p>
<p>You wouldn&#8217;t think about combining the intermediate languages of a compiler into the same program. The idea of a language is more fluid, more organic in the context of eDSLs, where now libraries can be quickly written and different levels can be easily combined.</p>
<p><sup>1</sup>Tom Hawkins wrote Atom.<br />
<sup>2</sup>Credit for Copilot also goes to Sebastian Niller, Robin Morisset, Alwyn Goodloe.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/465/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/465/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/465/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=465&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2011/01/30/meta-programming-and-edsls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>Haskell and Hardware for the Holidays</title>
		<link>http://leepike.wordpress.com/2010/12/18/haskell-and-hardware-for-the-holidays/</link>
		<comments>http://leepike.wordpress.com/2010/12/18/haskell-and-hardware-for-the-holidays/#comments</comments>
		<pubDate>Sat, 18 Dec 2010 23:24:11 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Copilot]]></category>
		<category><![CDATA[Embedded Software]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Verification]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=427</guid>
		<description><![CDATA["Jersey Shore" may have introduced you to the concept of gym, tan, laundry, but here we'll stick to test, build, verify.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=427&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Looking to make a statement this holiday season?  You could try to win the office &#8220;ugly holiday sweater&#8221; contest.  Or, you could play &#8220;Jingle Bells&#8221; on your Arduino microcontroller, using Haskell.  This post is about the latter.</p>
<p>We&#8217;re going to write this small program using the Copilot embedded domain-specific language (on <a href="http://hackage.haskell.org/package/copilot">Hackage</a> and the source on <a href="https://github.com/leepike/Copilot">Github</a>).  Copilot is a stream language that allows you to generate embedded C code from programs written essentially as Haskell lists (using <a href="http://hackage.haskell.org/package/atom">Atom</a> as a backend for the C code generation).  This post is about how to use Copilot/Haskell (v. 1.0) to make your embedded C programming easier and more likely to be correct.  Here&#8217;s what we&#8217;re going to do&#8212;please don&#8217;t look too closely at my soldering, and turn the volume up, since a piezo speaker isn&#8217;t loud:</p>
<span style="text-align:center; display: block;"><a href="http://leepike.wordpress.com/2010/12/18/haskell-and-hardware-for-the-holidays/"><img src="http://img.youtube.com/vi/bN-VEGoiKlg/2.jpg" alt="" /></a></span>
<p>(For the impatient, the Haskell file is <a href="https://gist.github.com/747707">here</a>, and the generated <code>.c</code> and <code>.h</code> files are <a href="https://gist.github.com/747710">here</a> and <a href="https://gist.github.com/747711">here</a>, respectively.)</p>
<p>We&#8217;re going to essentially recreate <a href="http://www.arduino.cc/en/Tutorial/PlayMelody">this</a> C/Wiring program, plus flash some LEDs, but hopefully in a easier, safer way.  We need to manage three tasks:</p>
<ol>
<li>Determine the note and number of beats to play.</li>
<li>Play the piezo speaker.</li>
<li>Flash the LEDs.</li>
</ol>
<p>We&#8217;ll start by defining which pins control what function:</p>
<pre>-- pin numbers
speaker, red, green :: Spec Int32
speaker = 13
red     = 12
green   = 11</pre>
<p>The type <code>Spec Int32</code> takes an <code>Int32</code> and lifts it into a Copilot expression.</p>
<p>We&#8217;ll call the program <code>cycleSong</code>.  The type of a Copilot program is <code>Streams</code>, which is a collection of <code>Spec a</code>`s, and it resides within the Writer Monad.  First, we&#8217;ll declare some variables.</p>
<pre>cycleSong :: Streams
cycleSong = do
  -- Copilot vars
  let idx       = varI32 "idx"
      notes     = varI32 "notes"
      duration  = varI32 "duration"
      odd       = varI32 "odd"
      even      = varI32 "even"
      playNote  = varB   "playNote"
  -- external vars
      note = extArrI32 "notes" idx
      beat = extArrI32 "beats" idx</pre>
<p>There are two classes of variables: Copilot variables that will refer to streams (infinite lists), and external variables, which can refer to data from C (including the return values of functions, global variables, and arrays).  The constructors are mnemonics for the type of the variables; for example, <code>varI32</code> is a variable that will refer to a stream of <code>Int32</code>s.  Similarly, <code>extArrI32</code> is an external variable referring to a C array of <code>Int32</code>s (i.e., <code>int32_t</code>).  Notice the <code>idx</code> argument&#8212;it is the stream of values from which the index into the array is drawn (constants can also be used for indexes).</p>
<p>Now for the actual program:</p>
<pre> idx      .= [0] ++ (idx + 1) `mod` (fromIntegral $ length notesLst)
 notes    .= note
 duration .= beat * 300
 odd      .= mux (idx `mod` 2 == 1) green red
 even     .= mux (idx `mod` 2 == 1) red green
 playNote .= true
 -- triggers
 trigger playNote "digitalWrite" (odd &lt;&gt; true)
 trigger playNote "digitalWrite" (even &lt;&gt; false)
 trigger playNote "playtone" (speaker &lt;&gt; notes &lt;&gt; duration)</pre>
<p>And that&#8217;s basically it.  There are two parts to the program, the definition of Copilot streams, which manage data-flow and control, and triggers, which call an external C function when some property is true.  Copilot streams look pretty much like Haskell lists, except that functions are automatically lifted to the stream level for convenience.  Thus, instead of writing,</p>
<pre> x = [0] ++ map (+1) x</pre>
<p>in Copilot, you simply write</p>
<pre> x .= [0] ++ x + 1</pre>
<p>Similarly for constants, so the Copilot stream definition</p>
<pre>playNote .= true</pre>
<p>lifts the constant <code>true</code> to an infinite stream of <code>true</code> values.  The function <code>mux</code> is <code>if then else</code>&#8212;<code>mux</code> refers to a <a href="http://en.wikipedia.org/wiki/Multiplexer">2-to-1 multiplexer</a>.  So that means that the stream <code>odd</code> takes the value of <code>green</code> when <code>idx</code> is odd, and <code>red</code> otherwise, where <code>green</code> and <code>red</code> refer to the pins controlling the respective LEDs.</p>
<p>Just to round out the description of the other defined streams, <code>idx</code> is the index into the C arrays containing the notes and beats, respectively&#8212;that&#8217;s why we perform modular arithmetic.  The stream <code>duration</code> tells us how long to hold a note; 300 is a magic &#8220;tempo&#8221; constant.</p>
<p>Now for the triggers.  Each of our triggers &#8220;fires&#8221; whenever the stream <code>playNote</code> is true; in our case, because it is a constant stream of trues, this happens on each iteration.  So on each iteration, the C functions <code>digitalWrite</code> and <code>playTone</code> are called with the respective function arguments (&#8216;<code>&lt;&gt;</code>&#8216; separates arguments).  The function <code>digitalWrite</code> is a function that is part of the <a href="http://wiring.org.co/">Wiring language</a>, which is basically C with some standard libraries, from which <code>digitalWrite</code> comes.  We&#8217;ll write <code>playTone</code> ourselves in a second.</p>
<h2>The C Code</h2>
<p>We need a little C code now.  We could write this directly, but we&#8217;ll just do this in Haskell, since there&#8217;s so little we need to write&#8212;the Copilot program handles most of the work.  But a caveat: it&#8217;s a little ugly, since we&#8217;re just constructing Haskell strings.  Here are <a href="http://leepike.github.com/Copilot/doc/Language-Copilot-AdHocC.html">a few functions</a> (included with Copilot) to make this easier, and here are <a href="https://github.com/norm2782/blink.hs/blob/master/CHS.hs">some more</a>.  (If someone properly writes a package to write ad-hoc C code from Haskell, please leave a comment!)</p>
<p>First, we need more magic constants to give the frequency associated with notes (a space is a rest).</p>
<pre>freq :: Char -&gt; Int32
freq note  =
  case note of
    'c' -&gt; 1915
    'd' -&gt; 1700
    'e' -&gt; 1519
         ...
</pre>
<p>and here are the notes of the song and the beats per note:</p>
<pre>jingleBellsNotes = "eeeeeeegcdefffffeeeddedgeeeeeeegcdefffffeeggfdc"
jingleBellsBeats =
  [ 1,1,2  , 1,1,2, 1,1,1,1, 4
  , 1,1,1,1, 1,1,2, 1,1,1,1, 2,2
  , 1,1,2  , 1,1,2, 1,1,1,1, 4
  , 1,1,1,1, 1,1,2, 1,1,1,1, 4
  ]</pre>
<p>The other main piece of C code we need to write is the function <code>playtone</code>.  The piezo speaker is controlled by pulse width modulation, basically meaning we&#8217;ll turn it on and off really fast to simulate an analogue signal.  Here is it&#8217;s definition (using a little helper Haskell function to construct C functions):</p>
<pre>    [ function "void" "playtone" ["int32_t speaker", "int32_t tone", "int32_t duration"] P.++ "{"
    , "#ifdef CBMC"
    , "  for (int32_t i = 0; i &lt; 1; i ++) {"
    , "#else"
    , "  for (int32_t i = 0; i &lt; duration * 1000; i += tone * 2) {"
    , "#endif"
    , "    digitalWrite(speaker, HIGH);"
    , "    delayMicroseconds(tone);"
    , "    digitalWrite(speaker, LOW);"
    , "    delayMicroseconds(tone);"
    , "  }"
    , "}"
    ]</pre>
<p><code>HIGH</code>, <code>LOW</code>, <code>digitalWrite</code>, and <code>delayMicroseconds</code> are all part of the Wiring standard library.  That <code>ifdef</code> is for verification purposes, which we&#8217;ll describe in just a bit.</p>
<p>Besides a little more cruft, that&#8217;s it!</p>
<h2>Test, Build, Verify</h2>
<p>&#8220;Jersey Shore&#8221; may have introduced you to the concept of <em>gym, tan, laundry</em>, but here we&#8217;ll stick to <em>test, build, verify</em>.  That is, first we&#8217;ll test our program using the Copilot interpreter, then we&#8217;ll build it, then we&#8217;ll prove the memory safety of the generated C program.</p>
<ul>
<li><em>Interpret.</em> We define a function that calls the Copilot interpreter:
<pre>interpreter =
  interpret cycleSong 20
    $ setE (emptySM {i32Map = fromList [ ("notes", notesLst)
                                       , ("beats", beatsLst)]})
    baseOpts</pre>
<p>This calls the Copilot interpreter, saying to unroll <code>cycleSong</code> 20 times.  Because the Copilot program samples some external C values, we need to provide that data to the interpreter.  Fortunately, we have those arrays already defined as Haskell lists.  Executing this, we get the following:</p>
<pre>period: 0   duration: 300   even: 11   idx: 0   notes: 1519   odd: 12   playNote: 1
period: 1   duration: 300   even: 12   idx: 1   notes: 1519   odd: 11   playNote: 1
period: 2   duration: 600   even: 11   idx: 2   notes: 1519   odd: 12   playNote: 1
period: 3   duration: 300   even: 12   idx: 3   notes: 1519   odd: 11   playNote: 1
period: 4   duration: 300   even: 11   idx: 4   notes: 1519   odd: 12   playNote: 1
period: 5   duration: 600   even: 12   idx: 5   notes: 1519   odd: 11   playNote: 1
period: 6   duration: 300   even: 11   idx: 6   notes: 1519   odd: 12   playNote: 1
                                               . . .</pre>
<p>Good, it looks right.  (<code>period</code> isn&#8217;t a Copilot variable but just keeps track of what round we&#8217;re on.)</li>
<li><em>Build.</em> To build, we generate the C code from the Copilot program, then we&#8217;ll use a cross-compiler targeting the <a href="http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove">ATmega328</a>.  The easiest way (I&#8217;ve found) is via Homin Lee&#8217;s <a href="http://code.google.com/p/arscons/">Arscons</a>.  Arscons is based on <a href="http://www.scons.org/">Scons</a>, a Python-based build system.  Arscons makes three assumptions: (1) the program is written as a Wiring program (e.g., there&#8217;s a <code>loop()</code> function instead of a <code>main()</code> function is the main difference), (2) the extension of the Wiring program is <code>.pde</code>, and (3) the directory containing the <code>XXX.pde</code> is <code>XXX</code>.  For us, all that really means is that we have to change the extension of the generated program from <code>.c</code> to <code>.pde</code>.  So we define
<pre>main :: IO ()
main = do
  compile cycleSong name
    $ setPP cCode  -- C code for above/below the Copilot program
    $ setV Verbose -- Verbose compilation
    baseOpts
  copyFile (name P.++ ".c") (name P.++ ".pde") -- SConstruct expects .pde</pre>
<p>and then execute</p>
<pre>&gt; runhaskell CopilotSong.hs</pre>
<p>to do this.</p>
<p>To build the executable, we issue</p>
<pre>&gt; scons</pre>
<p>then</p>
<pre>scons upload</pre>
<p>when we&#8217;re ready to flash the microcontroller.</li>
<li><em>Verify. </em>Is the generated C program memory safe?  Wait&#8230; What do I mean by &#8216;memory safe&#8217;?  I&#8217;ll consider the program to be memory safe if the following hold:
<ul>
<li>No arithmetic underflows or overflows.</li>
<li>No floating-point not-a-numbers (NaNs).</li>
<li>No division by zero.</li>
<li>No array bounds underflows or overflows.</li>
<li>No Null pointer dereferences.</li>
</ul>
<p>Of course this is an approximates memory-safety, but it&#8217;s a pretty good start.  If the compiler is built correctly, we should be pretty close to a memory-safe program.  But we want to check the compiler, even though Haskell&#8217;s type system gives us some evidence of guarantees already.  Furthermore, the compiler knows nothing about arbitrary C functions, and it doesn&#8217;t know how large external C arrays are.</p>
<p>We can <em>prove</em> that the program is memory safe.  We call out to <a href="http://www.cprover.org/cbmc/">CBMC</a>, a C model-checker developed primarily by Daniel Kröning.  This is whole-program analysis, so we have to provide the location of the libraries.  We define</p>
<pre>verifying :: IO ()
verifying =
  verify (name P.++ ".c") (length notesLst * 4 + 3)
    (     "-DCBMC -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/ "
     P.++ "-I/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/avr-4/include "
     P.++ "--function cbmc")</pre>
<p>which calls <code>cbmc</code> on our generated C program.  Let me briefly explain the arguments.  First we give the name of the C program.  </p>
<p>Then we say how many times to unroll the loops.  This requires a little thinking.  We want to unroll the loops enough times to potentially get into a state where we might have an out of bounds array access (recall that the Copilot stream <code>idx</code> generates indexes into the arrays).  The length of the C arrays are given by <code>length notesLst</code>.  When compiling the Copilot program (calling the module&#8217;s <code>main</code> function, a periodic schedule is generated for the program).  From the schedule, we can see that <code>idx</code> is updated every fourth pass through the loop.  So we unwind it enough loop passes for the counter to have the opportunity to walk off the end of the array, plus a few extra passes for setup.  This is a minimum bound; you could of course over-approximate and unroll the loop, say, 1000 times.</p>
<p>Regarding loop unrolling, remember that <code>#ifdef</code> from the definition of <code>playtone()</code>?  We include that to reduce the difficulty of loop unrolling.  <code>playtone()</code> gets called on every fourth pass through the main loop, and unrolling both loops is just too much for symbolic model-checking (at least on my laptop).  So we give ourselves an informal argument that the loop in <code>playtone()</code> won&#8217;t introduce any memory safety violations, and the <code>#ifdef</code> gives us one iteration through the loop if we&#8217;re verifying the system.  A lot of times with embedded code, this is a non-issue, since loops can just be completely unrolled.</p>
<p>The <code>-D</code> flag defines a preprocessor macro, and the <code>-I</code> defines a include path.  Finally, the <code>--function</code> flag gives the entry point into the program.  Because we generated a Wiring program which generates a <code>while(1)</code> loop for us through macro magic, we have to create an explicit loop ourselves for verification purposes.</p>
<p>If you&#8217;re interested in seeing what things look like when they fail, change the <code>idx</code> stream to be</p>
<pre>
  idx .= [0] ++ (idx + 1)
</pre>
<p>and <code>cbmc</code> will complain</p>
<pre>
Violated property:
  file CopilotSing.c line 180 function __r11
  array `beats' upper bound
  (long int)__1 &lt; 47

VERIFICATION FAILED
</pre>
</li>
</ul>
<p>So that&#8217;s it.  Happy holidays!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/427/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/427/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/427/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/427/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/427/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/427/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/427/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=427&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2010/12/18/haskell-and-hardware-for-the-holidays/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>Backseat Driving: Copilot Updates</title>
		<link>http://leepike.wordpress.com/2010/11/20/backseat-driving-copilot-updates/</link>
		<comments>http://leepike.wordpress.com/2010/11/20/backseat-driving-copilot-updates/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 05:33:29 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Embedded Software]]></category>
		<category><![CDATA[Formal methods]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=410</guid>
		<description><![CDATA[A lot has been going on since the announcement of Copilot, a Haskell DSL for generating hard real-time C monitors. We&#8217;ve presented Copilot a few times, including at Runtime Verification 2010, at a Galois Technical Seminar (video of the talk is here), and at a recent NASA Technical Interchange. Copilot has had five releases since [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=410&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A lot has been going on since the <a href="http://leepike.wordpress.com/2010/09/25/copilot-a-dsl-for-monitoring-embedded-systems/">announcement of Copilot</a>, a Haskell DSL for generating hard real-time C monitors. We&#8217;ve presented Copilot a few times, including at <a href="http://www.rv2010.org/">Runtime Verification 2010</a>, at a <a href="http://www.galois.com/blog/2010/11/02/tech-talk-copilot-a-hard-real-time-runtime-monitor/">Galois Technical Seminar</a> (video of the talk is <a href="http://www.galois.com/blog/2010/11/10/tech-talk-video-copilot-a-hard-real-time-runtime-monitor%E2%80%9D/">here</a>), and at a recent NASA Technical Interchange.</p>
<p>Copilot has had five releases since we originally open-sourced the project.  Recent work has focused on making the language more straightforward and improving Copilot libraries.  But first, let me remind you how to use Copilot: you can compile specs to hard real-time C code, you can interpret them, you can model-check them, and you can generate specs to test the compiler and interpreter&#8212;you can see a bit about usage <a href="http://leepike.github.com/Copilot/">here</a>.</p>
<p>For example, here&#8217;s a Copilot specification that generates the Fibonacci sequence (over <code>Word64</code>s) and tests for even numbers:</p>
<pre>fib :: Streams
fib = do
  let f = varW64 "f"
  let t = varB "t"
  f .= [0,1] ++ f + (drop 1 f)
  t .= even f
  where even :: Spec Word64 -&gt; Spec Bool
            even w' = w' `mod` 2 == 0</pre>
<p>Notice that lists look <em>almost </em>exactly like Haskell lists.</p>
<p>What about something a little more complicated?  Consider the property:</p>
<p style="text-align:center;"><em>If the temperature rises more than 2.3 degrees within 2 seconds, then the engine has been shut off.</em></p>
<p style="text-align:left;">We might use a Copilot specification like the following to express it, assuming that <code>temp</code> and <code>shutoff</code> are C variables being sampled at phases 1 and 2 respectively, and the period of execution is 1 second:</p>
<pre>engine :: Streams
engine = do
<span style="color:#808080;">  -- external vars</span>
  let temp     = extF "temp" 1
  let shutoff  = extB "shutoff" 2
<span style="color:#808080;">  -- Copilot vars</span>
  let temps    = varF "temps"
  let overTemp = varB "overTemp"
  let trigger  = varB "trigger"
<span style="color:#808080;">  -- Copilot specification</span>
  temps    .= [0, 0, 0] ++ temp
  overTemp .= drop 2 temps &gt; 2.3 + temps
  trigger  .= overTemp ==&gt; shutoff</pre>
<p>Here&#8217;s something that I think shows why you want to write your DSLs in Haskell: Haskell gives you a macro language for your DSL&#8230; for free.  For example, consider the following (more complicated) property:</p>
<p style="text-align:center;"><em>&#8220;If the engine temperature exeeds 250 degrees, then the engine is shut off within one second, and in the 0.1 second following the shutoff, the cooler is engaged and remains engaged.&#8221;</em></p>
<p style="text-align:left;">We can more succinctly specify this property using <a href="http://fsl.cs.uiuc.edu/index.php/Past_Time_Linear_Temporal_Logic">past-time linear temporal logic (ptLTL)</a>.  There&#8217;s a Copilot library for writing those kind of specs, which can be interspersed with normal Copilot streams&#8212;the ptLTL specs are highlighted in blue below.  Again, assume a period of execution of 1 second:</p>
<pre>engine :: Streams
engine = do
<span style="color:#808080;">  -- external vars</span>
  let engineTemp = extW8 "engineTemp" 1
  let engineOff  = extB "engineOff" 1
  let coolerOn   = extB "coolerOn" 1
<span style="color:#808080;">  -- Copilot vars</span>
  let cnt        = varW8 "cnt"
  let temp       = varB "temp"
  let cooler     = varB "cooler"
  let off        = varB "off"
  let monitor    = varB "monitor"
<span style="color:#808080;">  -- Copilot specification</span>
<span style="color:#0000ff;">  temp    `ptltl` (alwaysBeen (engineTemp &gt; 250))</span>
  cnt     .=      [0] ++ mux (temp &amp;&amp; cnt &lt; 10) (cnt + 1) cnt
  off     .=      cnt &gt;= 10 ==&gt; engineOff
<span style="color:#0000ff;">  cooler  `ptltl` (coolerOn `since` engineOff)</span>
  monitor .=      off &amp;&amp; cooler</pre>
<p>Today, I finished updating another feature of Copilot: the ability to send stream values over ports to other components in a distributed system.  We had an implementation of this, but it was a bit hacky.  Hopefully, it&#8217;s a bit less hacky now.  For example, consider the following specification:</p>
<pre>distrib :: Streams
distrib = do
  -- Copilot vars
  let a = varW8 "a"
  let b = varB "b"
  -- Copilot spec
  a .= [0,1] ++ a + 1
  b .= mod a 2 == 0
  -- send commands
 <span style="color:#0000ff;"> send "portA" (port 2) a 1</span>
<span style="color:#0000ff;">  send "portB" (port 1) b 2</span></pre>
<p>The blue commands are send commands.  For example, the first command says, &#8220;call the C function <code>portA(str, num)</code>, where argument <code>str</code> is the value of stream <code>a</code> and <code>num</code> is port number 1.&#8221;  The port number says who to send it to.</p>
<p>These are just a few of the recent updates.  We&#8217;re still working on Copilot, so let me know if you have questions or comments.</p>
<p>Interested?  Get Copilot on <a href="http://hackage.haskell.org/package/copilot">Hackage</a> or <a href="https://github.com/leepike/Copilot">GitHub</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/410/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=410&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2010/11/20/backseat-driving-copilot-updates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>Copilot: a DSL for Monitoring Embedded Systems</title>
		<link>http://leepike.wordpress.com/2010/09/25/copilot-a-dsl-for-monitoring-embedded-systems/</link>
		<comments>http://leepike.wordpress.com/2010/09/25/copilot-a-dsl-for-monitoring-embedded-systems/#comments</comments>
		<pubDate>Sun, 26 Sep 2010 05:24:47 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Embedded Software]]></category>
		<category><![CDATA[Fault Tolerance]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=387</guid>
		<description><![CDATA[In case you missed all the excitement on the Galois blog, what follows is a re-post. Introducing Copilot Can you write a list in Haskell? Then you can write embedded C code using Copilot. Here&#8217;s a Copilot program that computes the Fibonacci sequence (over Word 64s) and tests for even a numbers: fib :: Streams [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=387&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In case you missed all the excitement on the <a href="http://www.galois.com/blog/2010/09/22/copilot-a-dsl-for-monitoring-embedded-systems/">Galois blog</a>, what follows is a re-post.</p>
<h1>Introducing Copilot</h1>
<p>Can you write a list in Haskell? Then you can write embedded C code     using Copilot. Here&#8217;s a Copilot program that computes the Fibonacci     sequence (over Word 64s) and tests for even a numbers:</p>
<pre><code>
fib :: Streams
fib = do
  "fib" .= [0,1] ++ var "fib" + (drop 1 $ varW64 "fib")
  "t" .= even (var "fib")
    where even :: Spec Word64 -&gt; Spec Bool
          even w = w `mod` const 2 == const 0
</code></pre>
<p>Copilot contains an interpreter, a compiler, and uses a model-checker to check     the correctness of your program. The compiler generates constant time and     constant space C code via <a href="http://github.com/tomahawkins/atom">Tom     Hawkin&#8217;s Atom Language</a> (thanks Tom!). Copilot is specifically developed to write     embedded software monitors for more complex embedded systems, but it can be used to     develop a variety of functional-style embedded code.</p>
<p>Executing</p>
<pre>&gt; compile fib "fib" baseOpts</pre>
<p>generates <a href="http://leepike.github.com/Copilot/code/fib.c">fib.c</a> and <a href="http://leepike.github.com/Copilot/code/fib.h">fib.h</a> (with a <tt>main()</tt> for simulation&#8212;other options     change that). We can then run</p>
<pre>&gt; interpret fib 100 baseOpts</pre>
<p>to check that the Copilot program does what we expect. Finally, if we have <a href="http://www.cprover.org/cbmc/">CBMC</a> installed, we can run</p>
<pre>&gt; verify "fib.c"</pre>
<p>to prove a bunch of memory safety properties of the generated program.</p>
<p><strong>Galois has open-sourced Copilot (BSD3 licence).  More information is available on the <a href="http://leepike.github.com/Copilot/">Copilot homepage</a>.  Of course, <a href="http://hackage.haskell.org/package/copilot">it&#8217;s available from Hackage</a>, too.</strong></p>
<h1>Flight of the Navigator</h1>
<p><img title="Aberdeen Farms entrance" align="RIGHT" src="http://lh4.ggpht.com/_WtJlY4o2uqU/TIVRKhAQgrI/AAAAAAAAAJk/yJcdRvJTn8Q/s640/DSC03839.JPG" alt="Aberdeen Farms entrance" width="250" /></p>
<p><img title="View of the James River." align="RIGHT" src="http://lh5.ggpht.com/_WtJlY4o2uqU/TIVO11G4dpI/AAAAAAAAAIQ/jzZX7fe6we8/s640/DSC03794.JPG" alt="View of the James River." width="250" /></p>
<p><img title="Pitot tube on the test aircraft." align="RIGHT" src="http://lh4.ggpht.com/_WtJlY4o2uqU/TIVQ3vPY4zI/AAAAAAAAAJ0/85Z0ZUItyzw/s640/DSC03836.JPG" alt="Pitot tube on the test aircraft." width="250" /></p>
<p><img title="Our testbed stack: 4 STM32 microcontrollers (ARM Cortex M3s), an SD card for logging data, air pressure sensor, and voltage regulator." align="RIGHT" src="http://lh6.ggpht.com/_WtJlY4o2uqU/TIVPszn1uzI/AAAAAAAAAIs/pqARfDX2Epc/s640/DSC03805.JPG" alt="Our testbed stack: 4 STM32 microcontrollers (ARM Cortex M3s), an SD card for logging data, air pressure sensor, and voltage regulator." width="250" /></p>
<p><img class="alignnone" title="Stack in the hull" align="RIGHT" src="http://lh3.ggpht.com/_WtJlY4o2uqU/TIVRK35yLNI/AAAAAAAAAJs/xLThwc5FNQg/uav1.jpg" alt="" width="250" /></p>
<p><img title="Sebastian installing the stack." align="RIGHT" src="http://lh6.ggpht.com/_WtJlY4o2uqU/TIVPtaZH8QI/AAAAAAAAAI4/d8tep3tkD4I/s640/DSC03810.JPG" alt="Sebastian installing the stack." width="250" /></p>
<p><img alt="" align="RIGHT" src="http://lh4.ggpht.com/_WtJlY4o2uqU/TIKitvr733I/AAAAAAAAABA/gl6bxrpDa_I/s640/photo-8.JPG" title="Getting the plane ready" class="alignnone" width="250" /></p>
<p>Copilot took its maiden flight in August 2010 in Smithfield, Virginia.  NASA rents a private airfield for test flights like this, but you have to get past the intimidating sign posted upon entering the airfield.  However, once you arrive, there&#8217;s a beautiful view of the James River.</p>
<p>We were flying on a RC aircraft that NASA Langley uses to conduct a variety of <a href="http://www.nasa.gov/centers/ames/research/humaninspace/humansinspace-ivhm.html">Integrated Vehicle Health Management</a> (IVHM) experiments.  (It coincidentally had Galois colors!)  Our experiments for Copilot were to determine its effectiveness at detecting faults in embedded guidance, navigation, and control software.  The test-bed we flew was a partially fault-tolerant <a href="http://en.wikipedia.org/wiki/Pitot_tube">pitot tube</a> (air pressure) sensor.  Our pitot tube sat at the edge of the wing.   Pitot tubes are used on commercial aircraft and they&#8217;re a big deal: a number of aircraft accidents and mishaps have been due, in part, to <a href="http://en.wikipedia.org/wiki/Pitot-static_system#Pitot-static_related_disasters">pitot tube failures</a>.</p>
<p>Our experiment consisted of a beautiful hardware stack, crafted by Sebastian Niller of the Technische Universität Ilmenau.  Sebastian also led the programming for the stack.  The stack consisted of four STM32 ARM Cortex M3 microprocessors.  In addition, there was an SD card for writing flight data, and power management.  The stack just fit into the hull of the aircraft.  Sebastian installed our stack in front of another stack used by NASA on the same flights.</p>
<p>The microprocessors were arranged to provide <a href="http://en.wikipedia.org/wiki/Byzantine_fault">Byzantine fault-tolerance</a> on the sensor values.  One microprocessor acted as the general, receiving inputs from the pitot tube and distributing those values to the other microprocessors.  The other microprocessors would exchange their values and perform a fault-tolerant vote on them.  Granted, the fault-tolerance was for demonstration purposes only: all  the microprocessors ran off the same clock, and the sensor wasn&#8217;t replicated (we&#8217;re currently working on a fully fault-tolerant system).  During the flight tests, we injected (in software) faults by having intermittently incorrect sensor values distributed to various nodes.</p>
<p>The pitot sensor system (including the fault-tolerance code) is a hard real-time system, meaning events have to happen at predefined deadlines.  We wrote it in a combination of <a href="http://hackage.haskell.org/package/atom">Tom Hawkin&#8217;s Atom</a>, a Haskell DSL that generates C, and C directly.</p>
<p>Integrated with the pitot sensor system are Copilot-generated monitors.  The monitors detected</p>
<ul>
<li>unexpected sensor values (e.g., the delta change is too extreme),</li>
<li>the correctness of the voting algorithm (we used <a href="http://userweb.cs.utexas.edu/~moore/best-ideas/mjrty/index.html">Boyer-Moore majority voting</a>, which returns the majority only if one exists; our monitor checked whether a majority indeed exists), and</li>
<li>whether the majority votes agreed.</li>
</ul>
<p>The monitors integrated with the sensor system without disrupting its real-time behavior.</p>
<p><img class="alignnone" title="Getting data from the SD card." align="RIGHT" src="http://lh6.ggpht.com/_WtJlY4o2uqU/TIKjCrYlaLI/AAAAAAAAABY/IB_INTgHHQw/s512/photo-15.JPG" alt="" width="250" /></p>
<p>We gathered data on six flights.  In between flights, we&#8217;d get the data from the SD card.</p>
<p><img alt="" align="RIGHT" src="http://lh4.ggpht.com/_WtJlY4o2uqU/TIVQa0vf_cI/AAAAAAAAAJM/gukUmoiq54Q/s640/DSC03831.JPG" title="The Copilot Team" class="alignnone" width="250" /></p>
<p><img alt="" align="RIGHT" src="http://lh6.ggpht.com/_WtJlY4o2uqU/TIVQ36Q1sGI/AAAAAAAAAJg/I_Ka1vcSXIE/s640/DSC03838.JPG" title="The entire flight team" class="alignnone" width="250" /></p>
<p>We took some time to pose with the aircraft.  The Copilot team from left to right is Alwyn Goodloe, <a href="http://www.nianet.org/">National Institute of Aerospace</a>; Lee Pike, <a href="http://www.galois.com">Galois, Inc.</a>; Robin Morisset, &Eacute;cole Normale Sup&eacute;rieure; and Sebastian Niller, Technische Universit&auml;t Ilmenau.  Robin and Sebastian are Visiting Scholars at the NIA for the project.  Thanks for all the hard work!</p>
<p>There were a bunch of folks involved in the flight test that day, and we got a group photo with everyone.  We are very thankful that the researchers at NASA were gracious enough to give us their time and resources to fly our experiments.  Thank you!</p>
<p>Finally, here are two short videos.  The first is of our aircraft&#8217;s takeoff during one of the flights.  Interestingly, it has an electric engine to reduce the engine vibration&#8217;s effects on experiments.</p>
<p><a href="http://player.vimeo.com/video/15198286">http://player.vimeo.com/video/15198286</a></p>
<p>The second is of AirStar, which we weren&#8217;t involved in, but that also flew the same day.  AirStar is a scaled-down jet (yes, jet) aircraft that was really loud and really fast.  I&#8217;m posting its takeoff, since it&#8217;s just so cool.  That thing was a rocket!</p>
<p><a href="http://player.vimeo.com/video/15204969">http://player.vimeo.com/video/15204969</a></p>
<h1>More Details</h1>
<p>Copilot and the flight test is part of a NASA-sponsored project (<a href="http://www.reuters.com/article/idUS221847+23-Apr-2009+PRN20090423">NASA press-release</a>) led by <a href="http://www.cs.indiana.edu/~lepike/">Lee Pike</a> at Galois.  It&#8217;s a 3 year project, and we&#8217;re currently in the second year.</p>
<h1>Even More Details</h1>
<p>Besides the language and flight test, we&#8217;ve written a few papers:</p>
<ul>
<li>Lee Pike, Alwyn Goodloe, Robin Morisset, and Sebastian Niller.  <a href="http://www.cs.indiana.edu/%7Elepike/pub_pages/rv2010.html">Copilot: A Hard Real-Time Runtime Monitor</a>.  To appear in the proceedings of the <em>1st Intl. Conference on Runtime Verification (RV&#8217;2010)</em>, 2010.  Springer.</li>
</ul>
<p style="padding-left:60px;">This paper describes the Copilot language.</p>
<ul>
<li>Lee Pike.  <a href="http://www.cs.indiana.edu/%7Elepike/pub_pages/dsn.html">Schrödinger&#8217;s CRCs (Fast Abstract)</a>.  <em>40th Annual IEEE/IFIP International Conference on Dependable Systems and Networks (DSN 2010)</em>, 2010.</li>
</ul>
<p style="padding-left:60px;">Byzantine faults are fascinating.  Here&#8217;s a 2-page paper that shows one reason why.</p>
<ul>
<li>Alwyn Goodloe and Lee Pike.  <a href="http://www.cs.indiana.edu/%7Elepike/pub_pages/monitors.html">Monitoring distributed real-time systems: a survey and future directions</a>.  NASA Contractor Report NASA/CR-2010-216724, 2010.</li>
</ul>
<p style="padding-left:60px;">At the beginning of our work, we tried to survey prior results in the field and discuss the constraints of the problem.  This report is a bit lengthy (almost 50 pages), but it&#8217;s a gentle introduction to our problem space.</p>
<ul>
<li>Lee Pike, Geoffrey M. Brown, and Alwyn Goodloe.  <a href="http://www.cs.indiana.edu/%7Elepike/pub_pages/qc-biphase.html">Roll your own  test bed for embedded real-time protocols: a Haskell experience</a>.  In <a href="http://www.haskell.org/haskell-symposium/2009/"><em>Haskell Symposium</em></a>, 2009.</li>
</ul>
<p style="padding-left:60px;">Yes, QuickCheck can be used to test low-level protocols.</p>
<ul>
<li>Alwyn Goodloe and Lee Pike.  <a href="http://www.cs.indiana.edu/%7Elepike/pub_pages/shm.html">Toward monitoring fault-tolerant embedded systems (extended abstract)</a>.  In <a href="http://www.isis.vanderbilt.edu/workshops/smc-it-2009-shm"><em>International Workshop on Software Health Management</em></a> (SHM&#8217;09), 2009.</li>
</ul>
<p style="padding-left:60px;">A short paper motivating the need for runtime monitoring of critical embedded systems.</p>
<h1>You&#8217;re <em>Still</em> Interested?</h1>
<p>We&#8217;re always looking for collaborators, users, and we may need 1-2 visiting scholars interested in embedded systems &amp; Haskell next summer.  If any of these interest you, drop Lee Pike a note (hint: if you read any of the papers or download Copilot, you can find my email).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/387/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=387&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2010/09/25/copilot-a-dsl-for-monitoring-embedded-systems/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>

		<media:content url="http://lh4.ggpht.com/_WtJlY4o2uqU/TIVRKhAQgrI/AAAAAAAAAJk/yJcdRvJTn8Q/s640/DSC03839.JPG" medium="image">
			<media:title type="html">Aberdeen Farms entrance</media:title>
		</media:content>

		<media:content url="http://lh5.ggpht.com/_WtJlY4o2uqU/TIVO11G4dpI/AAAAAAAAAIQ/jzZX7fe6we8/s640/DSC03794.JPG" medium="image">
			<media:title type="html">View of the James River.</media:title>
		</media:content>

		<media:content url="http://lh4.ggpht.com/_WtJlY4o2uqU/TIVQ3vPY4zI/AAAAAAAAAJ0/85Z0ZUItyzw/s640/DSC03836.JPG" medium="image">
			<media:title type="html">Pitot tube on the test aircraft.</media:title>
		</media:content>

		<media:content url="http://lh6.ggpht.com/_WtJlY4o2uqU/TIVPszn1uzI/AAAAAAAAAIs/pqARfDX2Epc/s640/DSC03805.JPG" medium="image">
			<media:title type="html">Our testbed stack: 4 STM32 microcontrollers (ARM Cortex M3s), an SD card for logging data, air pressure sensor, and voltage regulator.</media:title>
		</media:content>

		<media:content url="http://lh3.ggpht.com/_WtJlY4o2uqU/TIVRK35yLNI/AAAAAAAAAJs/xLThwc5FNQg/uav1.jpg" medium="image">
			<media:title type="html">Stack in the hull</media:title>
		</media:content>

		<media:content url="http://lh6.ggpht.com/_WtJlY4o2uqU/TIVPtaZH8QI/AAAAAAAAAI4/d8tep3tkD4I/s640/DSC03810.JPG" medium="image">
			<media:title type="html">Sebastian installing the stack.</media:title>
		</media:content>

		<media:content url="http://lh4.ggpht.com/_WtJlY4o2uqU/TIKitvr733I/AAAAAAAAABA/gl6bxrpDa_I/s640/photo-8.JPG" medium="image">
			<media:title type="html">Getting the plane ready</media:title>
		</media:content>

		<media:content url="http://lh6.ggpht.com/_WtJlY4o2uqU/TIKjCrYlaLI/AAAAAAAAABY/IB_INTgHHQw/s512/photo-15.JPG" medium="image">
			<media:title type="html">Getting data from the SD card.</media:title>
		</media:content>

		<media:content url="http://lh4.ggpht.com/_WtJlY4o2uqU/TIVQa0vf_cI/AAAAAAAAAJM/gukUmoiq54Q/s640/DSC03831.JPG" medium="image">
			<media:title type="html">The Copilot Team</media:title>
		</media:content>

		<media:content url="http://lh6.ggpht.com/_WtJlY4o2uqU/TIVQ36Q1sGI/AAAAAAAAAJg/I_Ka1vcSXIE/s640/DSC03838.JPG" medium="image">
			<media:title type="html">The entire flight team</media:title>
		</media:content>
	</item>
		<item>
		<title>Shocking Tell-All Interview on Software Assurance</title>
		<link>http://leepike.wordpress.com/2010/08/29/shocking-tell-all-interview-on-software-assurance/</link>
		<comments>http://leepike.wordpress.com/2010/08/29/shocking-tell-all-interview-on-software-assurance/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 02:22:52 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Embedded Software]]></category>
		<category><![CDATA[Formal methods]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Verification]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=373</guid>
		<description><![CDATA[I was recently interviewed by Flight International magazine, one of the oldest aviation news magazines.  Their reporter, Stephen Trimble, was writing on the Air Force&#8217;s Chief Scientist&#8217;s recent report stating that new software verification and validation techniques are desperately needed. Here&#8217;s an online copy of the article.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=373&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was recently interviewed by <em><a href="http://en.wikipedia.org/wiki/Flight_International">Flight International</a></em> magazine, one of the oldest aviation news magazines.  Their reporter, Stephen Trimble, was writing on the Air Force&#8217;s Chief Scientist&#8217;s recent report stating that new software verification and validation techniques are desperately needed.</p>
<p>Here&#8217;s an online copy of the <a href="http://www.flightglobal.com/articles/2010/08/05/345765/control-science-tops-list-of-usaf-science-and-technology.html">article</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/373/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=373&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2010/08/29/shocking-tell-all-interview-on-software-assurance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>Copilot: A Hard Real-Time Runtime Monitor</title>
		<link>http://leepike.wordpress.com/2010/08/22/copilot-a-hard-real-time-runtime-monitor/</link>
		<comments>http://leepike.wordpress.com/2010/08/22/copilot-a-hard-real-time-runtime-monitor/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 07:01:14 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Embedded Software]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=369</guid>
		<description><![CDATA[I&#8217;m the principal investigator on a NASA-sponsored research project investigating new approaches for monitoring the correctness of safety-critical guidance, navigation, and control software at run-time.  We just got a paper accepted at the Runtime Verification Conference on some of our recent work developing a language for writing monitors.  The language, Copilot, is a domain-specific language [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=369&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m the principal investigator on a <a href="http://www.reuters.com/article/idUS221847+23-Apr-2009+PRN20090423">NASA-sponsored research project</a> investigating new approaches for monitoring the correctness of safety-critical guidance, navigation, and control software at run-time.  We just got a paper accepted at the <a href="http://www.rv2010.org/">Runtime Verification Conference</a> on some of our recent work developing a language for writing monitors.  The language, Copilot, is a domain-specific language (DSL) embedded in Haskell that uses the powerful <a href="http://hackage.haskell.org/package/atom">Atom DSL</a> as a back-end.  Perhaps the best tag-line for Copilot is, &#8220;Know how to write Haskell lists?  Good; then you&#8217;re ready to write embedded software.&#8221;</p>
<p>Stay tuned for a software release and updates on a flight-test of our software on a NASA test UAV&#8230;  In the meantime, <a href="http://www.cs.indiana.edu/~lepike/pub_pages/rv2010.html">check out the paper</a>!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/369/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=369&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2010/08/22/copilot-a-hard-real-time-runtime-monitor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>Twinkle Twinkle Little Haskell</title>
		<link>http://leepike.wordpress.com/2010/05/31/twinkle-twinkle-little-haskell/</link>
		<comments>http://leepike.wordpress.com/2010/05/31/twinkle-twinkle-little-haskell/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 06:02:49 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Embedded Software]]></category>
		<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=320</guid>
		<description><![CDATA[Update Sept 28,2010: the Makefile mentioned below worked fine, except for something having to do with timing.  I was too lazy to track the problem down, but fortunately, I found an scons script (using the scons build system) that I modified to run on Mac OSX, and it works perfectly.  The original script is here&#8212;thanks [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=320&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Update Sept 28,2010</strong>: the Makefile mentioned below worked fine, except for something having to  do with timing.  I was too lazy to track the problem down, but  fortunately, I found an <a href="http://leepike.wordpress.com/atomled-hs/sconstruct/">scons script</a> (using the <a href="http://www.scons.org/">scons</a> build system) that I modified to run on Mac OSX, and it works  perfectly.  The original script is <a href="http://code.google.com/p/arscons/">here</a>&#8212;thanks Homin Lee!  The post has been modified appropriately.</p>
<p><strong>Update Oct 1, 2010: </strong>Homin Lee has updated the script to work on Mac OSX, so you can just grab the <a href="http://code.google.com/p/arscons/">original script</a> now.</p>
<hr />It&#8217;s been a <span style="text-decoration:line-through;">few months</span> almost a year(!) since John Van Enk <a href="http://blog.sw17ch.com/wordpress/?p=111">showed us</a> how to twinkle (blink) an LED on his <a href="http://arduino.cc/en/Main/HomePage">Arduino</a> microcontroller using Atom/Haskell.  Since that time, <a href="http://hackage.haskell.org/package/atom">Atom</a> (a Haskell embedded domain-specific language for generating constant time/space C programs) has undergone multiple revisions, and the standard Arduino tool-chain has been updated, so I thought it&#8217;d be worthwhile to &#8220;re-solve&#8221; the problem with something more streamlined that should work today for all your Haskell -&gt; Arduino programming needs.  With the changes to Atom, we can blink a LED with just a couple lines of core logic (as you&#8217;d expect given the simplicity of the problem).</p>
<p>For this post, I&#8217;m using</p>
<ul>
<li><a href="http://hackage.haskell.org/package/atom">Atom 1.0.4</a></li>
<li>The <a href="http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove">Arduino Duemilanove</a> (ATmega328)&#8212;pretty common, as of 2009.</li>
<li>The Arduino <a href="http://code.google.com/p/arduino/">0018 tool-chain</a> (on Mac OS X).  This can also be downloaded from the <a href="http://arduino.cc/en/Main/Software">Arduino website</a>.</li>
</ul>
<p>If you&#8217;ve played with the Arduino, you&#8217;ve noticed how nice the integrated IDE/tool-chain is.  Ok, the editor leaves everything to be desired, but otherwise, things just work.  The language is basically C with a few macros and Atmel AVR-specific libraries (the family to which Arduino hardware belongs).</p>
<p>However, if you venture off the beaten path at all&#8212;say, trying to compile your own C program outside the IDE&#8212;things get messy quickly.  Fortunately, with the <a href="http://leepike.wordpress.com/atomled-hs/sconstruct/">scons script</a>, things are a piece of cake.</p>
<p>What we&#8217;ll do is write a Haskell program AtomLED.hs and use that to generate AtomLED.c.  From that, the scons script will take care of the rest.</p>
<h2>The Core Logic</h2>
<p>Here&#8217;s the core logic we use for blinking the LED from Atom:</p>
<pre>ph :: Int
ph = 40000 -- Sufficiently large number of ticks (the Duemilanove is 16MHz)

blink :: Atom ()
blink = do
  on &lt;- bool "on" True -- Declare a Boolean variable on, initialized to True.

  -- At period ph and phase 0, do ...
  period ph $ phase 0 $ atom "blinkOn" $ do
    call "avr_blink"        -- Call a locally-defined C function, blink().
    on &lt;== not_ (value on)  -- Flip the Boolean.

  period ph $ phase (quot ph 8) $ atom "blinkOff" $ do
    call "avr_blink"
    on &lt;== not_ (value on)</pre>
<p>And that&#8217;s it!  The <tt>blink</tt> function has two rules, &#8220;blinkOn&#8221; and &#8220;blinkOff&#8221;.  Both rules execute every 40,000 ticks.  (A &#8220;tick&#8221; in our case is just a local variable that&#8217;s incremented, but it could be run off the hardware clock.  Nevertheless, we still know we&#8217;re getting nearly constant-time due to the code Atom generates.)  The first rule starts at tick 0, and executes at ticks 40,000, 80,000, etc., while the second starts at tick 40,000/8 = 5000 and executes at ticks 5000, 45,000, 85,000, etc.  In each rule, after calling the <tt>avr_blink()</tt> C function (we&#8217;ll define), it modulates a Boolean upon which <tt>blink()</tt> depends.  Thus, the LED is on 1/8 of the time and off 7/8 of the time.  (If we wanted the LED to be on the same amount of time as it is off, we could have done the whole thing with one rule.)</p>
<h2>The Details</h2>
<p>Really the only other thing we need to do is add a bit of C code around the core logic.  Here&#8217;s the listing for the C code stuck at the beginning, written as strings:<br />
<code><br />
[ (varInit Int16 "ledPin" "13")  -- We're using pin 13 on the Arduino.<br />
, "void avr_blink(void);"<br />
]<br />
</code><br />
and here&#8217;s some code for afterward:<br />
<code><br />
[<br />
"void setup()   {"<br />
, "  // initialize the digital pin as an output:"<br />
, "  pinMode(ledPin, OUTPUT);"<br />
, "}"<br />
, ""<br />
, "// set the LED on or off"<br />
, "void avr_blink() { digitalWrite(ledPin, state.AtomLED.on); }"<br />
, ""<br />
, "void loop() {"<br />
, "  " ++ atomName ++ "();"<br />
, "}"<br />
]<br />
</code></p>
<p>The IDE tool-chain expects there to be a <tt>setup()</tt> and <tt>loop()</tt> function defined, and it then pretty-prints a <tt>main()</tt> function from which both are called. The code never returns from <tt>loop()</tt>.</p>
<p>To blink the LED, we call <tt>digitalWrite()</tt> from <tt>avr_blink()</tt>.  <tt>digitalWrite()</tt> is provided by the <a href="http://arduino.cc/en/Reference/HomePage">Arduino language</a>.  (In John&#8217;s post, he manipulated the <a href="http://www.arduino.cc/en/Reference/PortManipulation">port registers</a> directly, which is faster and doesn&#8217;t rely on the Arduino libraries, but it&#8217;s also lower-level and less portable between Atmel controllers.)  Atom-defined variables are stored in a struct, so <tt>state.AtomLED.on</tt> references the Atom Boolean variable defined earlier.</p>
<h2>Make it Work!</h2>
<p>Now just drop the scons script into the directory (the directory must have the same name as the Haskell file, dropping the extension), and run<br />
<code><br />
&gt; runhaskell AtomLED.hs<br />
&gt; scons<br />
&gt; scons upload<br />
</code><br />
And your Haskell should be twinkling your LED.  <tt>runhaskell AtomLED.hs</tt> invokes the Atom compile function to generate a C file and headers; <tt>scons</tt> invokes the build script to build an ELF image to upload, and <tt>scons upload</tt> again invokes the compiler to upload to your board.</p>
<p>This should work for any Atom-generated program you want to run on your Arduino (modulo deviations from the configuration I mentioned initially).  Also, note the conventions and parameters to set in the scons script.</p>
<p>Post if you have any problems, and I might be able to help.  Also, I&#8217;d love to package the boilerplate up into a &#8220;backend&#8221; for Atom, but if you have time, please beat me to it.  Thanks.</p>
<p>Code:</p>
<ul>
<li><a href="http://leepike.wordpress.com/atomled-hs/">AtomLED.hs</a></li>
<li><a href="http://leepike.wordpress.com/atomled-hs/atomled-c/">AtomLED.c</a> (auto-generated from AtomLED.hs&#8212;included for the curious).</li>
<li><span style="text-decoration:line-through;"><a href="../atomled-hs/makefile/">Makefile</a></span> <a href="../atomled-hs/sconstruct/">SConstruct</a>&#8212;remember you also need <a href="http://www.scons.org/">scons</a>.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/320/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=320&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2010/05/31/twinkle-twinkle-little-haskell/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>New Group: Functional Programming for Embedded Systems</title>
		<link>http://leepike.wordpress.com/2010/05/30/new-group-functional-programming-for-embedded-systems/</link>
		<comments>http://leepike.wordpress.com/2010/05/30/new-group-functional-programming-for-embedded-systems/#comments</comments>
		<pubDate>Sun, 30 May 2010 18:16:59 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=318</guid>
		<description><![CDATA[Are you interested in how functional programming can be leveraged to make embedded-systems programming easier and more reliable?  You are not alone.  For example, check out what&#8217;s been happening in just the past couple of years. Programming the Arduino micro-controller with Atom/Haskell. The Atom eDSL language itself. The Feldspar language for DSP (embedded in Haskell). [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=318&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Are you interested in how functional programming can be leveraged to make embedded-systems programming easier and more reliable?  You are not alone.  For example, check out what&#8217;s been happening in just the past couple of years.</p>
<ul>
<li><a href="http://blog.sw17ch.com/wordpress/?p=111">Programming the Arduino</a> micro-controller with Atom/Haskell.</li>
<li>The <a href="http://hackage.haskell.org/package/atom">Atom eDSL</a> language itself.</li>
<li>The <a href="http://feldspar.inf.elte.hu/feldspar/">Feldspar</a> language for DSP (embedded in Haskell).</li>
<li>Writing a <a href="http://portal.acm.org/citation.cfm?id=1596582&amp;dl=GUIDE&amp;coll=GUIDE&amp;CFID=92164243&amp;CFTOKEN=17243443">DO178B-compliant compiler</a> in Ocaml (presented at <a href="http://www.cs.nott.ac.uk/~gmh/icfp09.html">ICFP&#8217;09</a>).</li>
<li>&#8230; And others.</li>
</ul>
<p>Now <a href="http://tomahawkins.org/">Tom Hawkins</a> (designer of Atom) has started a Google group, <a href="http://groups.google.com/group/fp-embedded">fp-embedded</a>, to discuss these issues.  Please join and post your projects &amp; questions!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/318/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=318&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2010/05/30/new-group-functional-programming-for-embedded-systems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>An Apologia for Formal Methods</title>
		<link>http://leepike.wordpress.com/2010/03/14/an-apologia-for-formal-methods/</link>
		<comments>http://leepike.wordpress.com/2010/03/14/an-apologia-for-formal-methods/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 15:23:34 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Formal methods]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[IEEE Computer]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=300</guid>
		<description><![CDATA[In the January 2010 copy of IEEE Computer, David Parnas published an article, &#8220;Really Rethinking &#8216;Formal Methods&#8217;&#8221; (sorry, you&#8217;ll need an IEEE subscription or purchase the article to access it), with the following abstract: We must question the assumptions underlying the well-known current formal software development methods to see why they have not been widely [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=300&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the January 2010 copy of <em><a href="http://www.computer.org/portal/web/csdl/magazines/computer#3">IEEE Computer</a></em>, <a href="http://en.wikipedia.org/wiki/David_Parnas">David Parnas</a> published an article, &#8220;<a href="http://www.computer.org/portal/web/csdl/magazines/computer#4">Really Rethinking &#8216;Formal Methods&#8217;</a>&#8221; (sorry, you&#8217;ll need an IEEE subscription or purchase the article to access it), with the following abstract:</p>
<p style="padding-left:30px;">We must question the assumptions underlying the well-known current  formal software development methods to see why they have not been widely  adopted and what should be changed.</p>
<p>I found some of the opinions therein to be antiquated, so I wrote a <a href="http://www.computer.org/portal/web/csdl/abs/html/mags/co/2010/03/mco2010030006.htm">letter to the editor</a> (free content!), which appears in the <a href="http://www.computer.org/portal/web/csdl/abs/mags/co/2010/03/toc.htm">March 2010 edition</a>.  IEEE also published a response from David Parnas, which you can also access at the letter link above.</p>
<p>I&#8217;ll refrain from visiting this debate here, but please have a look at the letters, enjoy the controversy, and do not hesitate to leave a comment!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/300/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=300&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2010/03/14/an-apologia-for-formal-methods/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>10 to the -9</title>
		<link>http://leepike.wordpress.com/2010/01/24/10-9/</link>
		<comments>http://leepike.wordpress.com/2010/01/24/10-9/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 06:00:12 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Fault Tolerance]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[10^-9]]></category>
		<category><![CDATA[probability]]></category>
		<category><![CDATA[reliability]]></category>
		<category><![CDATA[safety-critical systems]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=235</guid>
		<description><![CDATA[, or one-in-a-billion, is the famed number given for the maximum probability of a catastrophic failure, per hour of operation, in life-critical systems like commercial aircraft.  The number is part of the folklore of the safety-critical systems literature; where does it come from? First, it&#8217;s worth noting just how small that number is.  As pointed [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=235&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src='http://s0.wp.com/latex.php?latex=10%5E%7B-9%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='10^{-9}' title='10^{-9}' class='latex' />, or one-in-a-billion, is the famed number given for the maximum probability of a catastrophic failure, per hour of operation, in life-critical systems like commercial aircraft.  The number is part of the folklore of the safety-critical systems literature; where does it come from?</p>
<p>First, it&#8217;s worth noting just how small that number is.  As pointed out by Driscoll <em>et al</em>. in the paper, <a href="//books.google.com/books?id=N4tGyPJ5qYkC&amp;pg=PA235&amp;lpg=PA235&amp;dq=byzantine++from+theory+to+reality&amp;source=bl&amp;ots=rx0FcInyRS&amp;sig=tVxuS1kaN8Mhkr0Mks8wuN2Zj3c&amp;hl=en&amp;ei=-XVYS7XWKI7KsQOF5PjFBw&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=4&amp;ved=0CBsQ6AEwAw#v=onepage&amp;q=byzantine%20%20from%20theory%20to%20reality&amp;f=false">Byzantine Fault Tolerance, from Theory to Reality</a>, the probability of winning the U.K. lottery is 1 in 10s of millions, and the probability of being struck by lightening (in the U.S.) is <img src='http://s0.wp.com/latex.php?latex=1.6+%5Ctimes+10%5E%7B-6%7D%2C&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='1.6 &#92;times 10^{-6},' title='1.6 &#92;times 10^{-6},' class='latex' /> more than a 1,000 times more likely than <img src='http://s0.wp.com/latex.php?latex=10%5E%7B-9%7D.&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='10^{-9}.' title='10^{-9}.' class='latex' /></p>
<p>So where did <img src='http://s0.wp.com/latex.php?latex=10%5E%7B-9%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='10^{-9}' title='10^{-9}' class='latex' /> come from?  A nice explanation comes from <a href="http://www.csl.sri.com/users/rushby/abstracts/sefm09">a recent paper by John Rushby</a>:</p>
<p style="padding-left:30px;">If we consider the example of an airplane type with 100 members, each flying <img src='http://s0.wp.com/latex.php?latex=3000&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='3000' title='3000' class='latex' /> hours per year over an operational life of 33 years, then we have a total exposure of about 107 flight hours. If hazard analysis reveals ten potentially catastrophic failures in each of ten subsystems, then the &#8220;budget&#8221; for each, if none are expected to occur in the life of the fleet, is a failure probability of about <img src='http://s0.wp.com/latex.php?latex=10%5E%7B-9%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='10^{-9}' title='10^{-9}' class='latex' /> per hour [1, page 37]. This serves to explain the well-known <img src='http://s0.wp.com/latex.php?latex=10%5E%7B-9%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='10^{-9}' title='10^{-9}' class='latex' /> requirement, which is stated as follows: &#8220;when using quantitative analyses. . . numerical probabilities. . . on the order of <img src='http://s0.wp.com/latex.php?latex=10%5E%7B-9%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='10^{-9}' title='10^{-9}' class='latex' /> per flight-hour. . . based on a flight of mean duration for the airplane type may be used. . . as aids to engineering judgment. . . to. . . help determine compliance&#8221; (with the requirement for extremely improbable failure conditions) [2, paragraph 10.b].</p>
<p style="padding-left:30px;">[1] E. Lloyd and W. Tye, Systematic Safety: Safety Assessment of Aircraft Systems. London, England: Civil Aviation Authority, 1982, reprinted 1992.</p>
<p style="padding-left:30px;">[2] System Design and Analysis, Federal Aviation Administration, Jun. 21, 1988, advisory Circular 25.1309-1A.</p>
<p>(By the way, it&#8217;s worth reading the rest of the paper&#8212;it&#8217;s the first attempt I know of to formally connect the notions of (software) formal verification and reliability.)</p>
<p>So there a probabilistic argument being made, but let&#8217;s spell it out in a little more detail.  If there are 10 potential failures in 10 subsystems, then there are <img src='http://s0.wp.com/latex.php?latex=10+%5Ctimes+10+%3D+100&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='10 &#92;times 10 = 100' title='10 &#92;times 10 = 100' class='latex' /> potential failures.  Thus, there are <img src='http://s0.wp.com/latex.php?latex=2%5E%7B100%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='2^{100}' title='2^{100}' class='latex' /> possible configurations of failure/non-failure in the subsystems.  Only one of these configurations is acceptable&#8212;the one in which there are no faults.</p>
<p>If the probability of failure is <img src='http://s0.wp.com/latex.php?latex=x%2C&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='x,' title='x,' class='latex' /> then the probability of non-failure is <img src='http://s0.wp.com/latex.php?latex=1+-+x.&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='1 - x.' title='1 - x.' class='latex' />  So if the probability of failure for each subsystem is <img src='http://s0.wp.com/latex.php?latex=10%5E%7B-9%7D%2C&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='10^{-9},' title='10^{-9},' class='latex' /> then the probability of being in the one non-failure configuration is</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle%281+-+10%5E%7B-9%7D%29%5E%7B100%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle(1 - 10^{-9})^{100}' title='&#92;displaystyle(1 - 10^{-9})^{100}' class='latex' /></p>
<p>We want that probability of non-failure to be greater than the required probability of non-failure, given the total number of flight hours.  Thus,</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%281+-+10%5E%7B-9%7D%29%5E%7B100%7D+%3E+1+-+10%5E%7B-7%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle (1 - 10^{-9})^{100} &gt; 1 - 10^{-7}' title='&#92;displaystyle (1 - 10^{-9})^{100} &gt; 1 - 10^{-7}' class='latex' /></p>
<p>which indeed holds:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%281+-+10%5E%7B-9%7D%29%5E%7B100%7D+-+%281+-+10%5E%7B-7%7D%29&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle (1 - 10^{-9})^{100} - (1 - 10^{-7})' title='&#92;displaystyle (1 - 10^{-9})^{100} - (1 - 10^{-7})' class='latex' /></p>
<p>is around <img src='http://s0.wp.com/latex.php?latex=4.95+%5Ctimes+10%5E%7B-15%7D.&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='4.95 &#92;times 10^{-15}.' title='4.95 &#92;times 10^{-15}.' class='latex' /></p>
<p>Can we generalize the inequality?  The hint for how to do so is that the number of subsystems (<img src='http://s0.wp.com/latex.php?latex=100&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='100' title='100' class='latex' />) is no more than the overall failure rate divided by the subsystem rate:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cfrac%7B10%5E%7B-7%7D%7D%7B10%5E%7B-9%7D%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;frac{10^{-7}}{10^{-9}}' title='&#92;displaystyle &#92;frac{10^{-7}}{10^{-9}}' class='latex' /></p>
<p>This suggests the general form is something like</p>
<hr />
<p style="text-align:center;"><em>Subsystem reliability inequality</em>: <img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%281+-+C%5E%7B-n%7D%29%5E%7BC%5E%7Bn-m%7D%7D+%5Cgeq+1+-+C%5E%7B-m%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle (1 - C^{-n})^{C^{n-m}} &#92;geq 1 - C^{-m}' title='&#92;displaystyle (1 - C^{-n})^{C^{n-m}} &#92;geq 1 - C^{-m}' class='latex' /></p>
<hr />where <img src='http://s0.wp.com/latex.php?latex=C%2C&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='C,' title='C,' class='latex' /> <img src='http://s0.wp.com/latex.php?latex=n%2C&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='n,' title='n,' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=m&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='m' title='m' class='latex' /> are real numbers, <img src='http://s0.wp.com/latex.php?latex=C+%5Cgeq+1%2C&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='C &#92;geq 1,' title='C &#92;geq 1,' class='latex' /> <img src='http://s0.wp.com/latex.php?latex=n+%5Cgeq+0%2C&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='n &#92;geq 0,' title='n &#92;geq 0,' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=n+%5Cgeq+m.&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='n &#92;geq m.' title='n &#92;geq m.' class='latex' /></p>
<p>Let&#8217;s prove the inequality holds.  <a href="http://www.gilith.com/">Joe Hurd</a> figured out the proof, sketched below (but I take responsibility for any mistakes in it&#8217;s presentation).  For convenience, we&#8217;ll prove the inequality holds specifically when <img src='http://s0.wp.com/latex.php?latex=C+%3D+e%2C&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='C = e,' title='C = e,' class='latex' /> but the proof can be generalized.  </p>
<p>First, if <img src='http://s0.wp.com/latex.php?latex=n+%3D+0%2C&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='n = 0,' title='n = 0,' class='latex' /> the inequality holds immediately.  Next, we&#8217;ll show that</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%281+-+e%5E%7B-n%7D%29%5E%7Be%5E%7Bn-m%7D%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle (1 - e^{-n})^{e^{n-m}}' title='&#92;displaystyle (1 - e^{-n})^{e^{n-m}}' class='latex' /></p>
<p>is monotonically non-decreasing with respect to <img src='http://s0.wp.com/latex.php?latex=n&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='n' title='n' class='latex' /> by showing that the derivative of its logarithm is greater or equal to zero for all <img src='http://s0.wp.com/latex.php?latex=n+%3E+0.&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='n &gt; 0.' title='n &gt; 0.' class='latex' />  So the derivative of its logarithm is</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cfrac%7Bd%7D%7Bdn%7D+%5C%3B+e%5E%7Bn-m%7D%5Cln%281-e%5E%7B-n%7D%29+%3D+e%5E%7Bn-m%7D%5Cln%281-e%5E%7B-n%7D%29%2B%5Cfrac%7Be%5E%7B-m%7D%7D%7B1-e%5E%7B-n%7D%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;frac{d}{dn} &#92;; e^{n-m}&#92;ln(1-e^{-n}) = e^{n-m}&#92;ln(1-e^{-n})+&#92;frac{e^{-m}}{1-e^{-n}}' title='&#92;displaystyle &#92;frac{d}{dn} &#92;; e^{n-m}&#92;ln(1-e^{-n}) = e^{n-m}&#92;ln(1-e^{-n})+&#92;frac{e^{-m}}{1-e^{-n}}' class='latex' /></p>
<p>We show</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+e%5E%7Bn-m%7D%5Cln%281-e%7B-n%7D%29%2B%5Cfrac%7Be%5E%7B-m%7D%7D%7B1-e%5E%7B-n%7D%7D+%5Cgeq+0&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle e^{n-m}&#92;ln(1-e{-n})+&#92;frac{e^{-m}}{1-e^{-n}} &#92;geq 0' title='&#92;displaystyle e^{n-m}&#92;ln(1-e{-n})+&#92;frac{e^{-m}}{1-e^{-n}} &#92;geq 0' class='latex' /></p>
<p>iff</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+e%5E%7B-m%7D%5Cleft%28e%5E%7Bn%7D%5Cln%281-e%5E%7B-n%7D%29+%2B+%5Cfrac%7B1%7D%7B1-e%5E%7B-n%7D%7D%5Cright%29+%5Cgeq+0&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle e^{-m}&#92;left(e^{n}&#92;ln(1-e^{-n}) + &#92;frac{1}{1-e^{-n}}&#92;right) &#92;geq 0' title='&#92;displaystyle e^{-m}&#92;left(e^{n}&#92;ln(1-e^{-n}) + &#92;frac{1}{1-e^{-n}}&#92;right) &#92;geq 0' class='latex' /></p>
<p>and since <img src='http://s0.wp.com/latex.php?latex=e%5E%7B-m%7D+%5Cgeq+0%2C&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='e^{-m} &#92;geq 0,' title='e^{-m} &#92;geq 0,' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+e%5E%7Bn%7D%5Cln%281-e%5E%7B-n%7D%29+%2B+%5Cfrac%7B1%7D%7B1-e%5E%7B-n%7D%7D+%5Cgeq+0&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle e^{n}&#92;ln(1-e^{-n}) + &#92;frac{1}{1-e^{-n}} &#92;geq 0' title='&#92;displaystyle e^{n}&#92;ln(1-e^{-n}) + &#92;frac{1}{1-e^{-n}} &#92;geq 0' class='latex' /></p>
<p>iff</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+e%5E%7Bn%7D%5Cln%281-e%5E%7B-n%7D%29+%5Cgeq+-+%5Cfrac%7B1%7D%7B1-e%5E%7B-n%7D%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle e^{n}&#92;ln(1-e^{-n}) &#92;geq - &#92;frac{1}{1-e^{-n}}' title='&#92;displaystyle e^{n}&#92;ln(1-e^{-n}) &#92;geq - &#92;frac{1}{1-e^{-n}}' class='latex' /></p>
<p>Let <img src='http://s0.wp.com/latex.php?latex=x+%3D+e%5E%7B-n%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='x = e^{-n}' title='x = e^{-n}' class='latex' />, so the range of <img src='http://s0.wp.com/latex.php?latex=x&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='x' title='x' class='latex' /> is <img src='http://s0.wp.com/latex.php?latex=0+%3C+x+%3C+1.&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='0 &lt; x &lt; 1.' title='0 &lt; x &lt; 1.' class='latex' /><br />
<img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle%5Cln%281-x%29+%5Cgeq+-+%5Cfrac%7Bx%7D%7B1-x%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle&#92;ln(1-x) &#92;geq - &#92;frac{x}{1-x}' title='&#92;displaystyle&#92;ln(1-x) &#92;geq - &#92;frac{x}{1-x}' class='latex' /></p>
<p>Now we show that in the range of <img src='http://s0.wp.com/latex.php?latex=x&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='x' title='x' class='latex' />, the left-hand side is bounded below by the right-hand side of the inequality.<br />
<img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Clim_%7Bx+%5Cto+0%7D+%5C%3B+%5Cln%281-x%29+%3D+0&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;lim_{x &#92;to 0} &#92;; &#92;ln(1-x) = 0' title='&#92;displaystyle &#92;lim_{x &#92;to 0} &#92;; &#92;ln(1-x) = 0' class='latex' /></p>
<p>and<br />
<img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+-+%5Cfrac%7Bx%7D%7B1-x%7D+%3D+0&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle - &#92;frac{x}{1-x} = 0' title='&#92;displaystyle - &#92;frac{x}{1-x} = 0' class='latex' /></p>
<p>Now taking their derivatives<br />
<img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cfrac%7Bd%7D%7Bdx%7D+%5C%3B+%5Cln%281-x%29+%3D+%5Cfrac%7B1%7D%7Bx-1%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;frac{d}{dx} &#92;; &#92;ln(1-x) = &#92;frac{1}{x-1}' title='&#92;displaystyle &#92;frac{d}{dx} &#92;; &#92;ln(1-x) = &#92;frac{1}{x-1}' class='latex' /></p>
<p>and<br />
<img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cfrac%7Bd%7D%7Bdx%7D+%5C%3B+-+%5Cfrac%7Bx%7D%7B1-x%7D+%3D+-+%5Cfrac%7B1%7D%7B%28x-1%29%5E2%7D&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;frac{d}{dx} &#92;; - &#92;frac{x}{1-x} = - &#92;frac{1}{(x-1)^2}' title='&#92;displaystyle &#92;frac{d}{dx} &#92;; - &#92;frac{x}{1-x} = - &#92;frac{1}{(x-1)^2}' class='latex' /></p>
<p>Because <img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+x-1+%5Cgeq+-+%28x-1%29%5E2&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;displaystyle x-1 &#92;geq - (x-1)^2' title='&#92;displaystyle x-1 &#92;geq - (x-1)^2' class='latex' /> in the range of <img src='http://s0.wp.com/latex.php?latex=x&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='x' title='x' class='latex' />, our proof holds.</p>
<p>The purpose of this post was to clarify the folklore of ultra-reliable systems.  The subsystem reliability inequality presented allows for easy generalization to other reliable systems.</p>
<p>Thanks again for the help, Joe!<span id="more-235"></span><!--more--><!--more--><!--more--><!--more--></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/235/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/235/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/235/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/235/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/235/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/235/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/235/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/235/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/235/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/235/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/235/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/235/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/235/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/235/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=235&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2010/01/24/10-9/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>Writer&#8217;s Unblock</title>
		<link>http://leepike.wordpress.com/2009/09/30/writers-unblock/</link>
		<comments>http://leepike.wordpress.com/2009/09/30/writers-unblock/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 06:01:42 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Verification]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=230</guid>
		<description><![CDATA[I&#8217;ve recently got a few technical papers out the door involving Haskell, physical-layer protocols, SMT, security modeling, and run-time verification of embedded systems (phew!).  One of the benefits of industrial research is getting your hands involved in a lot of different research projects. This paper is about using Haskell to model physical-layer protocols and using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=230&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently got a few technical papers out the door involving Haskell, physical-layer protocols, SMT, security modeling, and run-time verification of embedded systems (phew!).  One of the benefits of <a href="http://www.galois.com">industrial research</a> is getting your hands involved in a lot of different research projects.</p>
<ul>
<li><a href="http://www.cs.indiana.edu/~lepike/pub_pages/qc-biphase.html">This paper</a> is about using Haskell to model physical-layer protocols and using QuickCheck to test them.  Physical-layer protocols are used to transmit bits from one clock-domain to another and are used in ethernet, credit card swipers, CD players, and so on.  The gist of the paper is that even though Haskell is pure &amp; lazy, it works great for modeling and testing real-time protocols and even for computing reliability statistics.  I presented it at the <a href="http://www.haskell.org/haskell-symposium/2009/">Haskell Symposium</a> in September &#8217;09, which was associated with <a href="http://www.cs.nott.ac.uk/~gmh/icfp09.html">ICFP</a>.  (The talk video is <a href="http://www.vimeo.com/6684450">online</a>!)  The paper is a short experience report&#8212;indeed, it is the only experience report that was accepted at the symposium.  The Haskell Symposium was an entertaining and friendly environment for presenting.</li>
</ul>
<ul>
<li><a href="http://www.cs.indiana.edu/~lepike/pub_pages/bmp-jrnl.html">This paper</a> actually precedes the Haskell paper, but it extends the results by describing how to formally verify physical-layer protocols using SMT solvers and <em>k</em>-induction (we use SRI&#8217;s <a href="http://sal.csl.sri.com/">SAL</a> tool in this work).  The paper is a journal article accepted at <a href="http://www.bcs-facs.org/journal/">Formal Aspects of Computing</a>.  You&#8217;ll find at least two things interesting about this article: (1) For all the excitement about SMT, there don&#8217;t seem to be a lot of great examples demonstrating its efficacy&#8212;the problems described in this paper were (laboriously!) verified using theorem-provers by others previously, and our approach using SMT is much more automated.  (2) We provide a nice general model of cross clock-domain circuits and particularly metastability.
<p>So if you can verify physical-layer protocols, why model them in Haskell and QuickCheck them (as we did above)?  There are at least two reasons.  First, if you&#8217;re using SMT, then your timing constraints need to be linear inequalities to be decidable.  For systems that with nonlinear constraints, QuickCheck might be your only recourse.  Second, QuickCheck gives you <em>concrete</em> counterexamples and test-cases that you can use to test implementations (SMT solvers often return symbolic counterexamples).</li>
</ul>
<ul>
<li><a href="http://www.cs.indiana.edu/~lepike/pub_pages/infoflow.html">This paper</a> describes a simple model for analyzing information flow in a system (where a &#8220;system&#8221; could be a program, a network, an OS, etc.).  The main portion of the paper describes heuristics based on graph algorithms for deciding what sort of information flow policies you might want to enforce in your system.  In general, there&#8217;s been a lot of work on analyzing access control policies but not so much work in figuring out <em>what</em> kind of policy you should have in the first place (if you know of such work, please tell me!).  The paper isn&#8217;t deep, and it&#8217;s also preliminary insofar as I don&#8217;t describe building a complex system using the techniques.  Still, there&#8217;s a small (Haskell) script <a href="http://www.cs.indiana.edu/~lepike/pub_pages/infoflow.html">available</a> that implements the algorithms described; I&#8217;d love to see these analyses find their way into a tool to help system designers build secure systems.</li>
</ul>
<ul>
<li>Finally, <a href="http://www.cs.indiana.edu/~lepike/pub_pages/monitors.html">this report</a> describes the field of run-time monitoring (or run-time verification) as it applies to safety-critical real-time embedded software.  Run-time monitoring compliments formal verification since when a system is too complicated to verify <em>a priori</em>, it can be monitored at run-time to ensure it conforms to its specification.  Not a lot of work has been done on monitoring software that&#8217;s hard real-time, distributed, or fault-tolerant&#8212;which ironically could benefit the most from run-time monitoring.  The report should serve as a nice, gentle introduction.  The report should be published soon as a NASA Contractor Report&#8212;the work was done under a <a href="http://news.prnewswire.com/DisplayReleaseContent.aspx?ACCT=104&amp;STORY=/www/story/04-23-2009/0005012113&amp;EDATE=">NASA-sponsored project</a> for which I&#8217;m the PI.</li>
</ul>
<p>Don&#8217;t hesitate to give me feedback on any of these papers.  Ok, time to fill up the queue again&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/230/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=230&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2009/09/30/writers-unblock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>Finding Boole</title>
		<link>http://leepike.wordpress.com/2009/08/10/finding-boole/</link>
		<comments>http://leepike.wordpress.com/2009/08/10/finding-boole/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 03:47:38 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Verification]]></category>
		<category><![CDATA[model checking]]></category>
		<category><![CDATA[SAL]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=202</guid>
		<description><![CDATA[Here&#8217;s a simple challenge-problem for model-checking Boolean functions: Suppose you want to compute some Boolean function , where represents 0 or more Boolean arguments. Let , , , range over 2-ary Boolean functions, (of type ), and suppose that is a fixed composition of , , , . (By the way, I&#8217;m going to talk [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=202&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple challenge-problem for model-checking Boolean functions: Suppose you want to compute some Boolean function <img src='http://s0.wp.com/latex.php?latex=spec+%3A%3A+B%5Ek+%5Crightarrow+B&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='spec :: B^k &#92;rightarrow B' title='spec :: B^k &#92;rightarrow B' class='latex' />, where <img src='http://s0.wp.com/latex.php?latex=B%5Ek&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='B^k' title='B^k' class='latex' /> represents 0 or more Boolean arguments.</p>
<p>Let <img src='http://s0.wp.com/latex.php?latex=f_0&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='f_0' title='f_0' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=f_1&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='f_1' title='f_1' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=%5Cldots&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;ldots' title='&#92;ldots' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=f_j&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='f_j' title='f_j' class='latex' /> range over 2-ary Boolean functions, (of type <img src='http://s0.wp.com/latex.php?latex=%28Bool%2C+Bool%29+%5Crightarrow+Bool&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='(Bool, Bool) &#92;rightarrow Bool' title='(Bool, Bool) &#92;rightarrow Bool' class='latex' />), and suppose that <img src='http://s0.wp.com/latex.php?latex=f&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='f' title='f' class='latex' /> is a fixed composition of <img src='http://s0.wp.com/latex.php?latex=f_0&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='f_0' title='f_0' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=f_1&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='f_1' title='f_1' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=%5Cldots&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;ldots' title='&#92;ldots' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=f_j&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='f_j' title='f_j' class='latex' />.  (By the way, I&#8217;m going to talk about functions, but you can think of these as combinatorial circuits, if you prefer.)</p>
<p>Our question is, &#8220;Do there exist instantiations of <img src='http://s0.wp.com/latex.php?latex=f_0&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='f_0' title='f_0' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=f_1&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='f_1' title='f_1' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=%5Cldots&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='&#92;ldots' title='&#92;ldots' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=f_j&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='f_j' title='f_j' class='latex' /> such that for all inputs, <img src='http://s0.wp.com/latex.php?latex=f+%3D+spec&amp;bg=fafafa&amp;fg=000000&amp;s=0' alt='f = spec' title='f = spec' class='latex' />?</p>
<p>What is interesting to me is that our question is quantified and of the form, &#8220;exists a forall b &#8230;&#8221;, and it is &#8220;higher-order&#8221; insofar as we want to find whether there exist satisfying functions.  That said, the property is easy to encode as a model-checking problem.  Here, I&#8217;ll encode it into <a href="http://sal.csl.sri.com/">SRI&#8217;s Symbolic Analysis Laboratory</a> (SAL) using its BDD engine.  (The SAL file in its entirety is <a href="source-code/findingboole-sal/" target="_blank">here</a>.)</p>
<p>To code the problem in SAL, we&#8217;ll first define for convenience a shorthand for the built-in type, <tt>BOOLEAN</tt>:</p>
<pre>B: TYPE = BOOLEAN;</pre>
<p>And we&#8217;ll define an enumerated data type representing the 16 possible 2-ary Boolean functions:</p>
<pre>B2ARY: TYPE = { False, Nor, NorNot, NotA, AndNot, NotB, Xor, Nand
              , And, Eqv, B, NandNot, A, OrNot, Or, True};</pre>
<p>Now we need an application function that takes an element <tt>f</tt> from <tt>B2ARY</tt> and two Boolean arguments, and depending on <tt>f</tt>, applies the appropriate 2-ary Boolean function:</p>
<pre>app(f: B2ARY, a: B, b: B): B =
  IF    f = False   THEN FALSE
  ELSIF f = Nor     THEN NOT (a OR b)
  ELSIF f = NorNot  THEN NOT a AND b
  ELSIF f = NotA    THEN NOT a
  ELSIF f = AndNot  THEN a AND NOT b
  ELSIF f = NotB    THEN NOT b
  ELSIF f = Xor     THEN a XOR b
  ELSIF f = Nand    THEN NOT (a AND b)
  ELSIF f = And     THEN a AND b
  ELSIF f = Eqv     THEN NOT (a XOR b)
  ELSIF f = B       THEN b
  ELSIF f = NandNot THEN NOT a OR b
  ELSIF f = A       THEN a
  ELSIF f = OrNot   THEN a OR NOT b
  ELSIF f = Or      THEN a OR b
  ELSE                   TRUE
  ENDIF;</pre>
<p>Let&#8217;s give a concrete definition to <tt>f</tt> and say that it is the composition of five 2-ary Boolean functions, <tt>f0</tt> through <tt>f4</tt>.  In the language of SAL:</p>
<pre>f(b0: B, b1: B, b2: B, b3: B, b4: B, b5: B):
  [[B2ARY, B2ARY, B2ARY, B2ARY, B2ARY] -&gt; B] =
    LAMBDA (f0: B2ARY, f1: B2ARY, f2: B2ARY, f3: B2ARY, f4: B2ARY):
      app(f0, app(f1, app(f2, b0,
                              app(f3, app(f4, b1, b2),
                                      b3)),
                      b4),
              b5);</pre>
<p>Now let&#8217;s define the <tt>spec</tt> function that <tt>f</tt> should implement:</p>
<pre>spec(b0: B, b1: B, b2: B, b3: B, b4: B, b5: B): B =
  (b0 AND b1) OR (b2 AND b3) OR (b4 AND b5);</pre>
<p>Now, we&#8217;ll define a module <tt>m</tt>; modules are SAL&#8217;s building blocks for defining state machines.  However, in our case, we won&#8217;t define an actual state machine since we&#8217;re only modeling function composition (or combinatorial circuits).  The module has variables corresponding the function inputs, function identifiers, and a Boolean stating whether <tt>f</tt> is equivalent to its specification (we&#8217;ll label the classes of variables <tt>INPUT</tt>, <tt>LOCAL</tt>, and <tt>OUTPUT</tt>, to distinguish them, but for our purposes, the distinction doesn&#8217;t matter).</p>
<pre>m: MODULE =
BEGIN
  INPUT b0, b1, b2, b3, b4, b5 : B
  LOCAL f0, f1, f2, f3, f4 : B2ARY
  OUTPUT equiv : B

  DEFINITION
    equiv = FORALL (b0: B, b1: B, b2: B, b3: B, b4: B, b5: B):
              spec(b0, b1, b2, b3, b4, b5)
            = f(b0, b1, b2, b3, b4, b5)(f0, f1, f2, f3, f4);
END;</pre>
<p>Notice we&#8217;ve universally quantified the free variables in <tt>spec</tt> and the definition of <tt>f</tt>.</p>
<p>Finally, all we have to do is state the following theorem:</p>
<pre>instance : THEOREM m |- NOT equiv;</pre>
<p>Asking whether <tt>equiv</tt> is false in module <tt>m</tt>.  Issuing</p>
<pre>$ sal-smc FindingBoole.sal instance</pre>
<p>asks SAL&#8217;s BDD-based model-checker to solve theorem <tt>instance</tt>.  In a couple of seconds, SAL says the theorem is proved.  So <tt>spec</tt> can&#8217;t be implemented by <tt>f</tt>, for any instantiation of <tt>f0</tt> through <tt>f4</tt>!  OK, what about</p>
<pre>spec(b0: B, b1: B, b2: B, b3: B, b4: B, b5: B): B =
  TRUE;</pre>
<p>Issuing</p>
<pre>$ sal-smc FindingBoole.sal instance</pre>
<p>we get a counterexample this time:</p>
<pre>f0 = True
f1 = NandNot
f2 = NorNot
f3 = And
f4 = Xor</pre>
<p>which is an assignment to the function symbols.  Obviously, to compute the constant <tt>TRUE</tt>, only the outermost function, <tt>f0</tt>, matters, and as we see, it is defined to be <tt>TRUE</tt>.</p>
<p>By the way, the purpose of defining the enumerated type <tt>B2ARY</tt> should be clear now&#8212;if we hadn&#8217;t, SAL would just return a mess in which the value of each function <tt>f0</tt> through <tt>f4</tt> is enumerated:</p>
<pre>f0(false, false) = true
f0(true, false) = true
f0(false, true) = true
f0(true, true) = true
f1(false, false) = true
f1(true, false) = true
f1(false, true) = false
f1(true, true) = true
f2(false, false) = false
f2(true, false) = true
f2(false, true) = false
f2(true, true) = false
f3(false, false) = false
f3(true, false) = false
f3(false, true) = false
f3(true, true) = true
f4(false, false) = false
f4(true, false) = true
f4(false, true) = true
f4(true, true) = false</pre>
<p>OK, let&#8217;s conclude with one more spec:</p>
<pre>spec(b0: B, b1: B, b2: B, b3: B, b4: B, b5: B): B =
  (NOT (b0 AND ((b1 OR b2) XOR b3)) AND b4) XOR b5;</pre>
<p>This is implementable by <tt>f</tt>, and SAL returns</p>
<pre>f0 = Eqv
f1 = OrNot
f2 = And
f3 = Eqv
f4 = Nor</pre>
<p>Although these assignments compute the same function, they differ from those in our specification.  Just to double-check, we can ask SAL if they&#8217;re equivalent:</p>
<pre>spec1(b0: B, b1: B, b2: B, b3: B, b4: B, b5: B): B =
  ((b0 AND ((NOT (b1 OR b2))  b3)) OR NOT b4)  b5;</pre>
<p>specifies the assignments returned, and</p>
<pre>eq: THEOREM m |- spec(b0, b1, b2, b3, b4, b5) =  spec1(b0, b1, b2, b3, b4, b5);</pre>
<p>asks if the two specifications are equivalent.  They are.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/202/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=202&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2009/08/10/finding-boole/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Schrodinger&#8217;s Probability&#8221; for Error-Checking Codes</title>
		<link>http://leepike.wordpress.com/2009/05/15/schrodingers-ratio-for-error-checking-codes/</link>
		<comments>http://leepike.wordpress.com/2009/05/15/schrodingers-ratio-for-error-checking-codes/#comments</comments>
		<pubDate>Fri, 15 May 2009 22:32:57 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Fault Tolerance]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Byzantine fault]]></category>
		<category><![CDATA[CRC]]></category>
		<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=108</guid>
		<description><![CDATA[In a previous post, I discussed the notion of Schrödinger CRCs, first described by Kevin Driscoll et al. in their paper Byzantine Fault Tolerance, from Theory to Reality. The basic idea is that error-detecting codes do not necessarily prevent two receivers from obtaining messages that are semantically different (i.e., different data) but syntactically valid (i.e., [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=108&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://leepike.wordpress.com/2009/04/18/reconsidering-cyclic-redundancy-checks-crc/">previous post</a>, I discussed the notion of <em>Schrödinger CRCs</em>, first described by Kevin Driscoll et al. in their paper <a href="http://www.springerlink.com/content/hx63utlym13x85nv/"><em>Byzantine Fault Tolerance, from Theory to Reality</em></a>.  The basic idea is that error-detecting codes do not necessarily prevent two receivers from obtaining messages that are semantically different (i.e., different data) but syntactically valid (i.e., the CRC matches the respective data words received).  The upshot is that even with CRCs, you can suffer <a href="http://en.wikipedia.org/wiki/Byzantine_Fault_Tolerance">Byzantine faults</a>, with some probability.</p>
<p>&#8230; So what <em>is</em> that probability of a Schrödinger’s CRC?  That&#8217;s the topic of this post&#8212;which cleans up a few of the ideas I presented earlier.  I published a short paper on the topic, which I presented at <a href="http://2010.dsn.org/"><em>Dependable Sensors and Networks, 2010</em></a>, while Kevin Driscoll was in the audience!  If you&#8217;d prefer to read the PDF or get the slides, they&#8217;re <a href="http://www.cs.indiana.edu/~lepike/pub_pages/dsn.html">here</a>.  The simulation code (Haskell) is <a href="http://leepike.wordpress.com/source-code/crc-hs/">here</a>.</p>
<iframe class="scribd_iframe_embed" src="http://www.scribd.com/embeds/36908542/content?start_page=1&view_mode=list&access_key=key-1yvth4zq1gg67bkc42t0" data-auto-height="true" scrolling="no" id="scribd_36908542" width="100%" height="500" frameborder="0"></iframe>
<div style="font-size:10px;text-align:center;width:100%"><a href="http://www.scribd.com/doc/36908542">View this document on Scribd</a></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/108/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=108&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2009/05/15/schrodingers-ratio-for-error-checking-codes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
		<item>
		<title>An Atomic Fibonacci Server: Exploring the Atom (Haskell) DSL</title>
		<link>http://leepike.wordpress.com/2009/05/05/an-atomic-fibonacci-server-exploring-the-atom-haskell-dsl/</link>
		<comments>http://leepike.wordpress.com/2009/05/05/an-atomic-fibonacci-server-exploring-the-atom-haskell-dsl/#comments</comments>
		<pubDate>Tue, 05 May 2009 18:03:09 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Atom]]></category>
		<category><![CDATA[embedded C]]></category>
		<category><![CDATA[Fibonacci]]></category>
		<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=59</guid>
		<description><![CDATA[This post is consistent with Atom 0.0.1 and not the latest version, Atom 0.0.5 (the author went off and implemented changes I and others suggested :)).  I&#8217;ll update the post&#8230; soon. Tom Hawkins has open-sourced Atom, a domain-specific language (DSL) for writing embedded real-time software. Atom is actually an &#8220;embedded DSL&#8221; (I prefer the term [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=59&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>This post is consistent with <a href="http://hackage.haskell.org/package/atom-0.0.1">Atom 0.0.1</a> and not the latest version, <a href="http://hackage.haskell.org/package/atom-0.0.5">Atom 0.0.5</a> (the author went off and implemented changes I and others suggested :)).  I&#8217;ll update the post&#8230; soon.</strong></p>
<p>Tom Hawkins has open-sourced <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/atom">Atom</a>, a domain-specific language (DSL) for writing embedded real-time software.  Atom is actually an &#8220;embedded DSL&#8221; (I prefer the term &#8220;lightweight DSL&#8221;) in the functional language <a href="http://en.wikipedia.org/wiki/Haskell_(programming_language)">Haskell</a>.  It&#8217;s a lightweight DSL (LwDSL) because you write legal Haskell and let the Haskell compiler do all the heavy lifting.  The DSL is a set of special functions and data types and a &#8220;compile function&#8221; that generates embedded (i.e., no dynamic memory) C code.  You don&#8217;t have to write your own compiler from scratch.</p>
<p>John Van Enk has already posted a couple of blog entries on using Atom; first on <a href="http://blog.sw17ch.com/wordpress/?p=84">adding slightly to the LwDSL</a> (one <em>major</em> advantage of a LwDSL is that it&#8217;s easy to extend the language&#8212;you don&#8217;t have to re-engineer a standalone compiler) and then on <a href="http://blog.sw17ch.com/wordpress/?p=111">using Atom to blink some LEDs on the Arduino</a>.  Keep checking his blog for more updates!</p>
<p>Here, I write a little device and driver program in Atom: the driver sends an index <em>i</em>, and the device returns the <em>i</em>th <a href="http://en.wikipedia.org/wiki/Fibonacci_number">Fibonacci number</a>.  The little bit of challenge in doing this is that the device and driver may run at different rates, so their communication is asynchronous.  How does this work in a language like Atom?</p>
<h2>Writing in the Atom DSL</h2>
<p>Let&#8217;s think about the Fibonacci device (we&#8217;ll call it <code>fibDev</code>) first.  The device  <code>fibDev</code> will do three things:</p>
<ol>
<li>Wait for a new index <em>i</em> from the driver.</li>
<li>Produce a result, fib(<em>i</em>).</li>
<li>Give the result to the driver.</li>
</ol>
<p>Let&#8217;s think about step (2) first.  Think for a second how we&#8217;d write this (efficiently) in Haskell:</p>
<blockquote>
<table border="1" rules="none">
<pre><span style="color:blue;">fib</span> <span style="color:red;">::</span> Int <span style="color:red;">-&gt;</span> Int
<span style="color:blue;">fib</span> n <span style="color:red;">=</span> fst <span style="color:cyan;">$</span> fibHlp n
    <span style="color:green;"><span style="text-decoration:underline;">where</span></span> fibHlp n <span style="color:red;">=</span>
              <span style="color:green;"><span style="text-decoration:underline;">case</span></span> n <span style="color:green;"><span style="text-decoration:underline;">of</span></span>
                <span style="color:magenta;">0</span> <span style="color:red;">-&gt;</span> <span style="color:cyan;">(</span><span style="color:magenta;">1</span><span style="color:cyan;">,</span> <span style="color:magenta;">1</span><span style="color:cyan;">)</span>
                <span style="color:green;"><span style="text-decoration:underline;">_</span></span> <span style="color:red;">-&gt;</span> <span style="color:green;"><span style="text-decoration:underline;">let</span></span> <span style="color:cyan;">(</span>a<span style="color:cyan;">,</span>b<span style="color:cyan;">)</span> <span style="color:red;">=</span> fibHlp <span style="color:cyan;">(</span>n<span style="color:blue;">-</span><span style="color:magenta;">1</span><span style="color:cyan;">)</span>
                     <span style="color:green;"><span style="text-decoration:underline;">in</span></span> <span style="color:cyan;">(</span>b<span style="color:cyan;">,</span>a<span style="color:cyan;">+</span>b<span style="color:cyan;">)</span></pre>
</table>
</blockquote>
<p>The Atom implementation will use the same algorithm, but it&#8217;ll look different.  Atom is a <a href="http://en.wikipedia.org/wiki/Synchronous_programming_language">synchronous language</a>, so you specify rules that fire on clock ticks.  Here&#8217;s what the core of the algorithm looks like in Atom (I haven&#8217;t shown the variable declarations, but look you can look at the <a href="http://leepike.wordpress.com/source-code/atomfibhs/">full source</a>):</p>
<blockquote>
<table border="1" rules="none">
<pre>atom <span style="color:magenta;">"computeFib"</span> <span style="color:cyan;">$</span> <span style="color:green;"><span style="text-decoration:underline;">do</span></span>
  cond <span style="color:cyan;">$</span> value runFib
  cond <span style="color:cyan;">$</span> value i <span style="color:cyan;">&gt;.</span> <span style="color:magenta;">0</span>
  decr i
  snd <span style="color:cyan;">&lt;==</span> <span style="color:cyan;">(</span>value fst<span style="color:cyan;">)</span> <span style="color:cyan;">+</span> <span style="color:cyan;">(</span>value snd<span style="color:cyan;">)</span>
  fst <span style="color:cyan;">&lt;==</span> value snd</pre>
</table>
</blockquote>
<p>Atom is written in a monadic style.  Here, we have two conditions, both of which must be true for the rule to &#8220;fire&#8221;.  The first condition is that <code>runFib</code> is true (telling the device it&#8217;s in its computation step), and the second condition is that the index is greater than 0 (we stop computing at zero).  If the conditions are true, then the value of <code>i</code> is decremented, and we update the values of the <code>fst</code> and <code>snd</code> variables, corresponding the first and second elements, respectively, of the pair in the Haskell specification.  Again, this is legal Haskell; the Atom library defines the special operators (e.g., <code>&gt;.</code>).  One great thing about writing embedded code in Atom is that variable updates are synchronous.  For example, in the code above, <code>fst</code> is updated to the previous value of <code>snd</code><code>. </code>That&#8217;s the core of the Fibonacci device.</p>
<p>The rest of the architecture handles the message passing (in the C code we&#8217;ll generate, messages are passed via global variables) and synchronization between the driver and device, as summarized below:</p>
<div id="attachment_73" class="wp-caption aligncenter" style="width: 350px"><img class="size-full wp-image-73" title="arch2" src="http://leepike.files.wordpress.com/2009/05/arch2.jpg?w=590" alt="System Architecture"   /><p class="wp-caption-text">System Architecture</p></div>
<p>We do not assume that <code>fibDvr</code> and <code>fibDev</code> execute at the same rate, so we handle message passing with a series of handshakes.  First, <code>fibDvr</code> sends a new value <code>x</code> and notifies <code>fibDev</code> that the value is ready (by issuing <code>newInd</code>).  <code>fibDev</code> acknowledges that <code>x</code> has been received with <code>valRcvd</code>.  At this point, <code>fibDvr</code> knows to wait for <code>fibDev</code> to compute fib<em>(x</em>).  Once it receives the notice <code>ansReady</code>, it reads off the answer, <code>ans</code>.</p>
<p>All we have to do now is implement the handshakes.  For example, let&#8217;s look at step (3) of the device, sending the final answer to the driver.  It&#8217;s behavior should be clear from the architectural description.</p>
<blockquote>
<table border="1" rules="none">
<pre>atom <span style="color:magenta;">"sendVal"</span> <span style="color:cyan;">$</span> <span style="color:green;"><span style="text-decoration:underline;">do</span></span>
  cond <span style="color:cyan;">$</span> value i <span style="color:cyan;">==.</span> <span style="color:magenta;">0</span>
  cond <span style="color:cyan;">$</span> value runFib
  runFib   <span style="color:cyan;">&lt;==</span> false
  ans      <span style="color:cyan;">&lt;==</span> value fst
  ansReady <span style="color:cyan;">&lt;==</span> true
  valRcvd  <span style="color:cyan;">&lt;==</span> false</pre>
</table>
</blockquote>
<p>And here&#8217;s step (1) for <code>fibDev</code>, waiting for a new index from the driver:</p>
<blockquote>
<table border="1" rules="none">
<pre>atom <span style="color:magenta;">"getIndex"</span> <span style="color:cyan;">$</span> <span style="color:green;"><span style="text-decoration:underline;">do</span></span>
  cond <span style="color:cyan;">$</span> not_ <span style="color:cyan;">(</span>value runFib<span style="color:cyan;">)</span>
  cond <span style="color:cyan;">$</span> value newInd
  i        <span style="color:cyan;">&lt;==</span> value x
  runFib   <span style="color:cyan;">&lt;==</span> true
  fst      <span style="color:cyan;">&lt;==</span> <span style="color:magenta;">1</span>
  snd      <span style="color:cyan;">&lt;==</span> <span style="color:magenta;">1</span>
  ansReady <span style="color:cyan;">&lt;==</span> false
  valRcvd  <span style="color:cyan;">&lt;==</span> true</pre>
</table>
</blockquote>
<p>These three rules for <code>fibDev</code> define the body of <code>fibDev</code>&#8216;s &#8220;do&#8221; block.</p>
<pre><span style="color:blue;">fibDev</span> <span style="color:red;">::</span> Atom ()
<span style="color:blue;">fibDev</span> <span style="color:red;">=</span> period <span style="color:magenta;">3</span> <span style="color:cyan;">$</span> <span style="color:green;"><span style="text-decoration:underline;">do</span></span> ...</pre>
<p>We tell atom that the period is 3, meaning execute each of our three rules every three clock ticks (based on the underlying clock).</p>
<p>Now that we&#8217;re comfortable with the language, let&#8217;s look at the entire definition of <code>fibDvr</code> in one go.  Recall the job of <code>fibDvr</code> is to send a value then wait for an answer.  Our driver will increment values by 5, starting at 0.  It&#8217;ll stop sending new values if the index is bigger than 50.</p>
<blockquote>
<table border="1" rules="none">
<pre><span style="color:blue;">fibDvr</span> <span style="color:red;">::</span> Atom ()
<span style="color:blue;">fibDvr</span> <span style="color:red;">=</span> period <span style="color:magenta;">20</span> <span style="color:cyan;">$</span> <span style="color:green;"><span style="text-decoration:underline;">do</span></span>
  x        <span style="color:red;">&lt;-</span> word64 <span style="color:magenta;">"x"</span> <span style="color:magenta;">0</span> <span style="color:blue;">-- new index to send</span>
  oldInd   <span style="color:red;">&lt;-</span> word64 <span style="color:magenta;">"oldInd"</span> <span style="color:magenta;">0</span> <span style="color:blue;">-- previous index sent</span>
<span style="color:blue;">  -- external signals --</span>
  valRcvd  <span style="color:red;">&lt;-</span> bool' <span style="color:magenta;">"valRcvd"</span> <span style="color:blue;">-- has the device received the new index?</span>
  ans      <span style="color:red;">&lt;-</span> word64' <span style="color:magenta;">"ans"</span> <span style="color:blue;">-- the newly-computed fib(x)</span>
  ansReady <span style="color:red;">&lt;-</span> bool' <span style="color:magenta;">"ansReady"</span> <span style="color:blue;">-- is an answer waiting?</span>
<span style="color:blue;">  ----------------------</span>
  valD     <span style="color:red;">&lt;-</span> word64 <span style="color:magenta;">"valD"</span> <span style="color:magenta;">1</span> <span style="color:blue;">-- local copy of fib(x)</span>
  newInd   <span style="color:red;">&lt;-</span> bool <span style="color:magenta;">"newInd"</span> True <span style="color:blue;">-- a new index is ready</span>
  waiting  <span style="color:red;">&lt;-</span> bool <span style="color:magenta;">"waiting"</span> True <span style="color:blue;">-- waiting for a new computation</span>

  atom <span style="color:magenta;">"wait"</span> <span style="color:cyan;">$</span> <span style="color:green;"><span style="text-decoration:underline;">do</span></span>
    cond <span style="color:cyan;">$</span> value valRcvd
    cond <span style="color:cyan;">$</span> not_ <span style="color:cyan;">$</span> value waiting
    newInd  <span style="color:cyan;">&lt;==</span> false
    waiting <span style="color:cyan;">&lt;==</span> true

  atom <span style="color:magenta;">"getAns"</span> <span style="color:cyan;">$</span> <span style="color:green;"><span style="text-decoration:underline;">do</span></span>
    cond <span style="color:cyan;">$</span> value ansReady
    cond <span style="color:cyan;">$</span> value waiting
    cond <span style="color:cyan;">$</span> value x <span style="color:cyan;">&lt;.</span> <span style="color:magenta;">50</span>
    valD    <span style="color:cyan;">&lt;==</span> value ans
    x       <span style="color:cyan;">&lt;==</span> value x <span style="color:cyan;">+</span> <span style="color:magenta;">5</span>
    waiting <span style="color:cyan;">&lt;==</span> false
    newInd  <span style="color:cyan;">&lt;==</span> true
    oldInd  <span style="color:cyan;">&lt;==</span> value x</pre>
</table>
</blockquote>
<p>Note that we&#8217;ve specified the period of the driver to be 20, meaning that its two rules get executed every 20 ticks.  So the driver is much slower than the device, but if our handshakes are correct, the two devices communicate correctly for any rates of execution of the two components.  (Proving it for all-time is a classic <a href="http://en.wikipedia.org/wiki/Model_checking">model checking</a> problem.)</p>
<h2>Compiling to C</h2>
<p>We include a little Haskell function that we can call to &#8220;compile&#8221; <code>fibDev</code> and <code>fibDvr</code> into embedded C files.  (The <code>compile</code> function is part of Atom, and it takes a name for the generated C file and Atom specifications to compile.)</p>
<blockquote>
<table border="1" rules="none">
<pre><span style="color:blue;">compileFib</span> <span style="color:red;">::</span> IO ()
<span style="color:blue;">compileFib</span> <span style="color:red;">=</span> <span style="color:green;"><span style="text-decoration:underline;">do</span></span>
  compile <span style="color:magenta;">"fibDev"</span> <span style="color:cyan;">$</span> fibDev
  compile <span style="color:magenta;">"fibDvr"</span> <span style="color:cyan;">$</span> fibDvr</pre>
</table>
</blockquote>
<p>We can call this from an interpreter for Haskell; it takes about a second to compile.  Doing so <em>almost</em> produces the source files <code><a href="http://leepike.wordpress.com/source-code/fibdvrc/">fibDvr.c</a></code> and <code><a href="http://leepike.wordpress.com/source-code/fibdevc/">fibDev.c</a></code>.  We do a few things manually:</p>
<ul>
<li>Write two header files, <code>fibDvr.h</code> and <code>fibDev.h</code> and import them.  This is the code we want to talk to each other through global variables.  We&#8217;ll also include <code>stdio.h</code> so we can <code>printf</code> our results.</li>
<li>Because Atom automatically (<em>atom</em>atically? :)) generates variable and function names in the generated code, we declare some of the identifiers in <code>fibDev.c</code> to be <code>static</code> so they aren&#8217;t globally visible.</li>
<li>We <code>#define</code> the variable names from the Atom-generated identifiers back to the expected identifiers for the variables that are shared.</li>
<li>And we add a little main function to execute the code: let&#8217;s execute the driver and device for 500 clock ticks:<br />
<blockquote>
<table border="1" rules="none">
<pre>int main() {
   while(__clock &lt; 500) {
      fibDvr();
      fibDev();
   }
   return 0;
}</pre>
</table>
</blockquote>
</li>
</ul>
<p>Of course, Atom could be extended to handle these things itself&#8212;John Van Enk has already <a href="http://blog.sw17ch.com/wordpress/?p=84">started doing</a> some of it.  In all, our 80-some lines of Atom compile to over 200 lines of embedded C.  So let&#8217;s test it!</p>
<p style="padding-left:30px;"><code>&gt; gcc -Wall -o fibDvr fibDev.c fibDvr.c<br />
&gt; ./fibDvr</code></p>
<p>generates the following output:</p>
<pre style="padding-left:30px;">i: 0, fib(i): 1
i: 0, fib(i): 1
i: 0, fib(i): 1
i: 5, fib(i): 8
i: 5, fib(i): 8
i: 10, fib(i): 89
i: 10, fib(i): 89
i: 10, fib(i): 89
i: 15, fib(i): 987
i: 15, fib(i): 987
i: 15, fib(i): 987
i: 15, fib(i): 987
i: 20, fib(i): 10946
i: 20, fib(i): 10946
i: 20, fib(i): 10946
i: 20, fib(i): 10946
i: 25, fib(i): 121393
i: 25, fib(i): 121393
i: 25, fib(i): 121393
i: 25, fib(i): 121393
i: 25, fib(i): 121393
i: 30, fib(i): 1346269
i: 30, fib(i): 1346269
i: 30, fib(i): 1346269
i: 30, fib(i): 1346269</pre>
<p>Wait, why are we getting the same answers multiple times?  Recall that Atom is a synchronous language, so functions are executed based on time (measured in underlying clock ticks), not events.  But most times, the guards don&#8217;t hold, so state isn&#8217;t updated.  That&#8217;s what we see here.</p>
<p>Oh, we should check our specification.  We can do that using our original Haskell specification:</p>
<pre style="padding-left:30px;">&gt; map fib [0,5..30]
[1,8,89,987,10946,121393,1346269]</pre>
<p>Looks good!</p>
<p>Let me know if this helps you understand Atom, or if you have thoughts on how Atom compares to other languages.</p>
<p>Finally, here are the sources:</p>
<ul>
<li><a href="http://leepike.wordpress.com/source-code/atomfibhs/">AtomFib.hs</a></li>
<li><a href="http://leepike.wordpress.com/source-code/fibdvrc/">fibDvr.c</a></li>
<li><a href="http://leepike.wordpress.com/source-code/fibdevc/">fibDev.c</a></li>
<li><a href="http://leepike.wordpress.com/source-code/fibdvrh/">fibDvr.h</a></li>
<li><a href="http://leepike.wordpress.com/source-code/fibdevh/">fibDev.h</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=59&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2009/05/05/an-atomic-fibonacci-server-exploring-the-atom-haskell-dsl/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>

		<media:content url="http://leepike.files.wordpress.com/2009/05/arch2.jpg" medium="image">
			<media:title type="html">arch2</media:title>
		</media:content>
	</item>
		<item>
		<title>N-Version Programming&#8230;  For the nth Time</title>
		<link>http://leepike.wordpress.com/2009/04/27/n-version-programming-for-the-nth-time/</link>
		<comments>http://leepike.wordpress.com/2009/04/27/n-version-programming-for-the-nth-time/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 17:32:37 +0000</pubDate>
		<dc:creator>Lee Pike</dc:creator>
				<category><![CDATA[Fault Tolerance]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[n-version programming]]></category>
		<category><![CDATA[reliability]]></category>

		<guid isPermaLink="false">http://leepike.wordpress.com/?p=25</guid>
		<description><![CDATA[Software contains faults.  The question is how to cost-effectively reduce the number of faults.  One approach that gained traction and then fell out of favor was N-version programming.  The basic idea is simple: have developer teams implement a specification independent from one another.  Then we can execute the programs concurrently and compare their results.  If [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=25&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Software contains faults.  The question is how to cost-effectively reduce the number of faults.  One approach that gained traction and then fell out of favor was <em><a href="http://en.wikipedia.org/wiki/N-version_programming">N-version programming</a></em>.  The basic idea is simple: have developer teams implement a specification independent from one another.  Then we can execute the programs concurrently and compare their results.  If we have, say, three separate programs, we vote their results, and if one result disagrees with the others, we presume that program contained a software bug.</p>
<p><em>N</em>-version programming rests on the assumption that software bugs in independently-implemented programs are random, statistically-uncorrelated events.  Otherwise, multiple versions are not effective at detecting errors if the different versions are likely to suffer the same errors.</p>
<p>John Knight and Nancy Leveson famously debunked this assumption on which <em>N</em>-version programming rested in the &#8220;Knight-Leveson experiment&#8221; they published in 1986.  In 1990, Knight and Leveson published a brief summary of the original experiment, as well as responses to subsequent criticisms made about it, in their paper, <a href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fsunnyday.mit.edu%2Fcritics.pdf&amp;ei=ztHqSeytCoKUswOF1NHiAQ&amp;usg=AFQjCNEuCLgJPwnUw05Z3UkJ4aF4WQL3Gw"><em>A Reply to the Criticisms of the Knight &amp; Leveson Experiment</em></a>.</p>
<p>The problem with <em>N</em>-version programming is subtle: it&#8217;s not that it provides <em>zero</em> improvement in reliability but that it provides significantly less improvement than is needed to make it cost-effective compared to other kinds of fault-tolerance (like <a href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fntrs.nasa.gov%2Farchive%2Fnasa%2Fcasi.ntrs.nasa.gov%2F20080009026_2008008714.pdf&amp;ei=sbv1SYzUD6P0tAPa_bz2Cg&amp;usg=AFQjCNEHVU2b6f74yCuxD8q2pJXwlir9fg">architecture-level fault-tolerance</a>).  The problem is that even small probabilities of correlated faults lead to significant reductions in potential reliability improvements.</p>
<p>Lui Sha has a more recent (2001) <em>IEEE Software</em> <a href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=2&amp;url=https%3A%2F%2Fagora.cs.illinois.edu%2Fdownload%2Fattachments%2F10581%2FIEEESoftware.pdf&amp;ei=40f1SYKUIJqytAOevLj6Cg&amp;usg=AFQjCNEJORj6PJHwLdoqXVeoAVBn-NX7Ow">article</a> discussing <em>N</em>-version programming, taking into account that the software development cycle is finite: is it better to spend all your time and money on one reliable implementation or on three implementations that&#8217;ll be voted at runtime?  His answer is almost always the former (even if we assume <em>un</em>correlated faults!).</p>
<p>But rather than <em>N</em>-versions of the same program, what about different programs compared at runtime?  That&#8217;s the basic idea of <a href="http://rtg.cis.upenn.edu/mac/index.php3">runtime monitoring</a>.  In runtime monitoring, one program is the implementation and another is the specification; the implementation is checked against the specification at runtime.  This is easier than checking before runtime (in which case you&#8217;d have to mathematically <em>prove</em> every possible execution satisfies the specification).  As Sha points out in his article, the specification can be slow and simple.  He gives the example of using the very simple <a href="http://en.wikipedia.org/wiki/Bubble_sort">Bubblesort</a> as the runtime specification of the more complex <a href="http://en.wikipedia.org/wiki/Sorting_algorithm#Quicksort">Quicksort</a>: if the Quicksort does its job correctly (in <em>O</em>(<em>n</em> log <em>n</em>), assuming a good pivot element), then checking its output (i.e., a hopefully properly sorted list) with Bubblesort will only take linear time (despite Bubble sort taking <em>O</em>(<em>n</em><sup>2</sup>) in general).</p>
<p>The simple idea of simple monitors fascinates me.  Of course, Bubblesort is not a full specification, though.  Although Sha doesn&#8217;t suggest it, we&#8217;d probably like our monitor to compare the lengths of the input and output lists to ensure that the Quicksort implementation didn&#8217;t remove elements.  And there&#8217;s still the possibility that the Quicksort implementation modifies elements, which is also unchecked by a Bubblesort monitor.</p>
<p>But instead of just checking the output, we could sort the same input with both Quickcheck and Bubblesort and compare the results.  This is a &#8220;stronger&#8221; check insofar as different sorts would have to have exactly the same faults (e.g., not sorting, removing elements, changing elements) for an error not to be caught.  The principal drawback is the latency of the slower Bubblesort check as compared to Quicksort.  But sometimes, it may be ok to signal an error (shortly) after a result is provided.</p>
<p>Just like for <em>N</em>-version programming, we would like the faults in our monitor to be statistically uncorrelated with those in the monitored software.  I am left wondering about the following questions:</p>
<ul>
<li>Is there research comparing the kinds of programming errors made in radically different paradigms, such as a Haskell and C?  Are there any faults we can claim are statistically uncorrelated?</li>
<li>Runtime monitoring itself is predicated on the belief that the implementations of different <em>programs</em> will fail in statistically independent ways, just like <em>N</em>-version programming is.  While more plausible, does this assumption hold?</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/leepike.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/leepike.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/leepike.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/leepike.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/leepike.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/leepike.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/leepike.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/leepike.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/leepike.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/leepike.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/leepike.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/leepike.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/leepike.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/leepike.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=leepike.wordpress.com&amp;blog=7358124&amp;post=25&amp;subd=leepike&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://leepike.wordpress.com/2009/04/27/n-version-programming-for-the-nth-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ac4f09f8947a82184e56daacb1bd2fe?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">leepike</media:title>
		</media:content>
	</item>
	</channel>
</rss>
