<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Formalized Mathematics</title>
	<atom:link href="http://slawekk.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://slawekk.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Tue, 11 Aug 2009 23:30:02 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='slawekk.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/e99386e8a31d363c8fa3d904083f0fbd?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Formalized Mathematics</title>
		<link>http://slawekk.wordpress.com</link>
	</image>
			<item>
		<title>Markov chains &#8211; simulation</title>
		<link>http://slawekk.wordpress.com/2009/08/01/markov-chains-simulation/</link>
		<comments>http://slawekk.wordpress.com/2009/08/01/markov-chains-simulation/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 01:32:33 +0000</pubDate>
		<dc:creator>slawekk</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[mathematics]]></category>
		<category><![CDATA[probability]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://slawekk.wordpress.com/?p=406</guid>
		<description><![CDATA[I have to say it took me considerable effort to figure out how to use the part of Haskell&#8217;s probability library that deals with randomness and simulation. The intuition developed by programming in imperative languages is especially harmful here.
The paper on which the library is based mentions a function &#8220;pick, which selects exactly one value [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=406&subd=slawekk&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have to say it took me considerable effort to figure out how to use the part of Haskell&#8217;s probability library that deals with randomness and simulation. The intuition developed by programming in imperative languages is especially harmful here.<span id="more-406"></span><br />
The <a href="http://web.engr.oregonstate.edu/~erwig/papers/PFP_JFP06.pdf">paper</a> on which the library is based mentions a function &#8220;<code>pick</code>, which selects exactly one value from a distribution by randomly yielding one of the values according to the specified probabilities&#8221;. Great, let&#8217;s try that out and toss a coin with it.</p>
<pre>&gt; :m +Numeric.Probability.Distribution
&gt; :m +Numeric.Probability.Random
&gt; pick $ choose 0.5 0 1

:1:0:
    No instance for (Show (Numeric.Probability.Random.T a))
      arising from a use of `Prelude.print' at :1:0-20
    Possible fix:
      add an instance declaration for
      (Show (Numeric.Probability.Random.T a))
    In the expression: Prelude.print it
    In a 'do' expression: Prelude.print it</pre>
<p>A closer analysis of the type signatures reveals that the type of the library function pick is not <code>IO a</code> as in the paper and to get IO from that we need to compose it with <code>run</code>.</p>
<pre>&gt; run $ pick $ choose 0.5 0 1
Loading package array-0.1.0.0 ... linking ... done.
Loading package containers-0.1.0.1 ... linking ... done.
Loading package old-locale-1.0.0.0 ... linking ... done.
Loading package old-time-1.0.0.0 ... linking ... done.
Loading package random-1.0.0.0 ... linking ... done.
Loading package mtl-1.1.0.0 ... linking ... done.
Loading package probability-0.2.1 ... linking ... done.
0</pre>
<p>This is better, lets try it again.</p>
<pre>&gt; run $ pick $ choose 0.5 0 1
0</pre>
<p>And again.</p>
<pre>&gt; run $ pick $ choose 0.5 0 1
0</pre>
<p>What the hell? We keep tossing a coin and get the same result every time! That&#8217;s Haskell in its referentially transparent glory.<br />
To get a sample of tossing several coins we need to pick from their joint distribution.</p>
<pre>&gt; run $ pick $ replicateM 10 $ choose 0.5 0 1
[0,0,1,1,0,1,0,1,1,0]</pre>
<p><strong>Simulation</strong></p>
<p>In my <a href="http://slawekk.wordpress.com/2009/06/05/markov-chains/">post on Markov chains</a> I defined a transition function on paths for a simple random walk that goes up or down by one with the same probability.</p>
<pre>rwstran :: Tran.T Double [Int]
rwstran x = D.choose 0.5 (x ++ [(last x) + 1]) (x ++ [(last x) - 1])</pre>
<p>The probability distribution on paths of legth n starting from state v can be calculated as</p>
<pre>rws :: Int -&gt; Int -&gt; D.T Double [Int]
rws v n = (Tran.compose $ replicate n rwstran) [v]</pre>
<p>This allows for exact calculations of probability of certain events. The basic problem with modeling Markov chains this way is that even for short chains we need lots of the memory to represent the whole sample space.<br />
For the above random walk we can calculate probability that, say, in the first 10 steps we will not go negative, but trying to do the same for 20 steps took longer than I had patience to wait. Haskell&#8217;s probability library offers a solution to that: approximating the real distribution with an empirical one obtained from simulation.<br />
I was a bit confused when I first tried to understand this. To simulate a sequence of i.i.d random variables we need to provide the distribution to sample from. But we can&#8217;t just repeatedly sample from the same distribution, as we would get the same number all the time. We would have to first create the joint distribution with <code>replicateM</code>. But that defies the purpose, as such distribution would be too large. The answer that the probability library offers is that the simplest objects it models are not sequences of i.i.d random variables, but homogeneous Markov chains. Such Markov chains are determined by the initial value and a function that assigns a probability distribution to each element of the state space (let&#8217;s call it a transition funtion). The i.i.d random variables can also be treated as a special case, but the basic setup is tailored for modeling Markov chains.</p>
<p>The most useful tool for simulation is the <code>~*.</code> operator provided by the Simulation module. It takes a pair of integers as a left side parameter. The first Int is the number of elements in the sample space we want to use. The second one defines the length of the Markov chain we want to simulate. On the right hand side of the operator we put the transition function. So, if we have defined</p>
<pre>emprws :: Int -&gt; Int -&gt; IO (T Double [Int])
emprws n k = Rnd.run $ (n,k) ~*. rwstran $ [0]</pre>
<p>Then we can get the empirical distribution on paths of the Markov chain of length 20 simulated 10 times as follows:</p>
<pre>&gt; emprws 10 20
fromFreqs [([0,-1,-2,-1,-2,-1,-2,-1,0,-1,0,-1,0,-1,-2,-1,-2,-1,-2,-3,-2],0.1),
([0,-1,0,-1,0,-1,-2,-3,-2,-1,0,-1,-2,-3,-2,-1,-2,-1,0,-1,0],0.1),
([0,-1,0,1,0,-1,-2,-1,0,1,2,1,2,3,4,3,2,3,4,5,4],0.1),
([0,1,0,-1,-2,-3,-4,-5,-6,-7,-6,-7,-8,-9,-10,-9,-10,-11,-10,-11,-12],0.1),
([0,1,0,1,0,1,0,-1,-2,-3,-2,-1,0,1,2,1,2,1,2,1,0],0.1),
([0,1,2,1,0,-1,-2,-1,-2,-1,0,-1,-2,-1,-2,-3,-4,-5,-6,-5,-4],0.1),
([0,1,2,1,2,1,0,1,0,-1,0,-1,0,-1,-2,-3,-4,-5,-6,-5,-6],0.1),
([0,1,2,3,2,1,0,-1,-2,-1,-2,-3,-2,-3,-2,-3,-4,-3,-4,-5,-4],0.1),
([0,1,2,3,2,1,2,3,2,1,0,-1,-2,-3,-2,-3,-2,-3,-4,-5,-4],0.1),
([0,1,2,3,2,3,4,3,2,3,4,5,4,5,6,5,6,5,6,5,6],0.1)]</pre>
<p>Note that since we use random number generator, the distribution in the result&#8217;s type of the simulation is wrapped in the IO monad. Because of that we need to put fmap before using the event probability operator <code>??</code> if we want to ask for probability of some event. For example to find out an approximate probability that a random walk of length 20 starting from 0 never goes negative based on simulating the random walk 2000 times we can do</p>
<p>&gt; fmap ((all (&gt;= 0)) ?? ) $ emprws 2000 20<br />
0.17200000000000013</p>
<p><strong>Even more random simulation</strong></p>
<p>The Simulation module defines two instances of the class that the <code>~*.</code> operator works for. One instance is for distributions as defined in the Distribution module. Such distributions are essentially lists of pairs (value, probability). We describe the Markov chain we want to simulate by defining a function that assigns a distribution of that type to each value of the state space. This works well for Markov chains in which for each state there are only some small number of states where the chain can go next. However consider a Markov chain where the next value is determined by a continuous distribution, for example when <img src='http://s1.wordpress.com/latex.php?latex=X_%7Bn%2B1%7D+%3D+X_n+%2B+E_n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='X_{n+1} = X_n + E_n' title='X_{n+1} = X_n + E_n' class='latex' />, where <img src='http://s2.wordpress.com/latex.php?latex=%5C%7B+E_n%5C%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\{ E_n\}' title='\{ E_n\}' class='latex' /> is a sequence of i.i.d random variables distributed uniformly on the interval <img src='http://s3.wordpress.com/latex.php?latex=%28-1%2C1%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(-1,1)' title='(-1,1)' class='latex' />. To simulate such Markov chains we can use the second instance of the class defined in the Simulation module. In this second instance we use numbers obtained from a random numbers generator instead of the explicit distribution.</p>
<p>Let&#8217;s look at an example. First we define a transition function that describes our Markov chain. We want to model paths of the Markov chain, so the function takes a path (a list of floats) and assigns a (random) path that has one more element, obtained from the random numbers generator.</p>
<pre>rwrnd :: Rnd.Change [Float]
rwrnd x = fmap (\delta -&gt; x ++ [(last x) + delta]) $ Rnd.randomR (-1,1)</pre>
<p>Such transition function can be used with the <code>~*.</code> operator in the same way as the rws transition function above.</p>
<pre>emprwrnd :: Int -&gt; Int -&gt;  IO (T Double[Float])
emprwrnd n k =  Rnd.run $ (n,k) ~*. rwrnd $ [0]</pre>
<p>Now let&#8217;s simulate this Markov chain, getting 5 paths of length 10 each:</p>
<pre>&gt; emprwrnd 5 10
fromFreqs
[([0.0,-0.87644845,-1.8566498,-1.7820039,-1.9403718,-0.9496375,-1.4706907,
-0.8597232,-1.6741004,-2.1475728,-2.224792],0.2),
([0.0,-0.48623613,-2.408719e-,0.60908824,0.9019042,1.3207725,1.9422557,
1.1668808,0.5517659,1.1509926,1.1245335],0.2),
([0.0,-0.18386137,-1.0592186,-0.95641375,-0.9876149,-1.7923257,-1.4315606,
-1.8640705,-2.6031392,-1.7015955,-1.166816],0.2),
([0.0,2.0809833e-,-0.6174592,-0.41014677,0.42637175,0.4807669,1.0540222,
8.9894295e-2,-0.18835253,0.6476095,0.9155247],0.2),
([0.0,0.97053343,6.692678e-,0.55357254,0.7402272,0.40708384,0.19999743,
-0.37751698,0.5084936,0.303145,0.9905505],0.2)]</pre>
<p>We can also ask the same type of questions as we did with with the discrete random walk in a similar way. So, what is the probability that in 20 steps we never go negative?</p>
<pre>&gt; fmap ((all (&gt;= 0)) ?? ) $ emprwrnd 2000 20
0.12650000000000008</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/slawekk.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/slawekk.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/slawekk.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/slawekk.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/slawekk.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/slawekk.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/slawekk.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/slawekk.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/slawekk.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/slawekk.wordpress.com/406/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=406&subd=slawekk&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://slawekk.wordpress.com/2009/08/01/markov-chains-simulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f0b149bf16959cf73a06bf8dae8298a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">slawekk</media:title>
		</media:content>
	</item>
		<item>
		<title>Haskell in Q</title>
		<link>http://slawekk.wordpress.com/2009/07/24/haskell-in-q/</link>
		<comments>http://slawekk.wordpress.com/2009/07/24/haskell-in-q/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 01:54:03 +0000</pubDate>
		<dc:creator>slawekk</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Q]]></category>

		<guid isPermaLink="false">http://slawekk.wordpress.com/?p=391</guid>
		<description><![CDATA[My new job will involve coding in Q. Q is a scripting language derived from APL. It is mostly used for stuff related to trading and finance.  I don&#8217;t know it yet, I&#8217;m supposed to learn it on the job, so I decided to have a look at it.
As an exercise, I took a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=391&subd=slawekk&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>My new job will involve coding in <a title="Q" href="http://en.wikipedia.org/wiki/Q_(programming_language_from_Kx_Systems)">Q</a>. Q is a scripting language derived from APL. It is mostly used for stuff related to trading and finance.  I don&#8217;t know it yet, I&#8217;m supposed to learn it on the job, so I decided to have a look at it.<span id="more-391"></span><br />
As an exercise, I took a couple of Haskell functions in the standard Data.List module and tried to see how one can express them in Q. Experienced Q developers (called &#8220;Q gods&#8221; in the Q terminology) will probably laugh at my code, but well, I have to start from something. Any corrections and idioms from Q gods are welcome.</p>
<p>Here are a couple of trivial functions that are special cases of builtin Q functions</p>
<pre>init: {-1_x} 

tail: {1_x}  

head: {x[0]}</pre>
<p>Q is a functional language. It allows to take functions as parameters in functions. Here the <code>takeWhile</code> function takes a predicate as its first parameter. The code is probably too imperative for Q, I am sure there is a better way.</p>
<pre>takeWhile:{[p;xs]
           i:0;
           while[(i &lt; count xs) &amp; p[xs[i]]; i+:1];
           xs[til i] / quite readable, isn't it
          }</pre>
<p>Q supports anonymous functions so one can call <code>takeWhile</code> as follows:</p>
<pre>q) takeWhile [{x&gt;0}; (1;2;4;0;3;4;5)]
1 2 4</pre>
<p>Here <code> {x&gt;0}</code> is an anonymous function that returns true (1b) when the argument is positive and 0b when it is less or equal 0.</p>
<p>My first shot at Haskell&#8217;s <code>intersperse</code> looked like this:</p>
<pre>intersperse: { -1 _ raze y ,' x }</pre>
<p>Here <code>y ,'  x</code> creates pairs with first element taken from y and second equal to x:</p>
<pre>(1;2;3) ,' 0
1 0
2 0
3 0</pre>
<p><code>raze</code> removes one level of nesting so we get a list instead of a list of pairs:</p>
<pre>raze (1;2;3) ,' 0
1 0 2 0 3 0</pre>
<p><code>-1 _</code> then drops the last element</p>
<p>This works well, but only when the first argument is an atom (not list).</p>
<pre>intersperse[0;(1;2;3)]
1 0 2 0 3</pre>
<p>But when we want to intersperse a list we get an error:</p>
<pre>q) intersperse [(0;0);((1;1);(2;2);(3;3))]
{-1 _ raze y ,' x }
'length</pre>
<p>To get a more general version we first define Haskell&#8217;s replicate:</p>
<pre>replicate: {[n;e]
		a: {x, (enlist z)};
		() a[ ; ;e]/ (til n) / folds the dyadic (binary) function a[ ; ;e] over a list of length n
	}</pre>
<p>Here <code>a: {x, (enlist z)}</code> creates a triadic (ternary) function that appends the third argument to the first and ignores the second.<br />
This replicate implementation seems too complicated for such simple task, but I was unable to figure out anything simpler.</p>
<p>We also need Haskell&#8217;s <code>zip</code>:</p>
<pre>zip: { x {(x;y)}' y }</pre>
<p>And now we can define intersperse:</p>
<pre>intersperse: { -1 _ raze zip [y ; replicate[count y;x]] }</pre>
<p>This works better than the first attempt:</p>
<pre>q) intersperse [(0;0);((1;1);(2;2);(3;3))]
1 1
0 0
2 2
0 0
3 3</pre>
<p>Haskell&#8217;s <code>map</code> is kind of redundant in Q as unary functions (called &#8220;monadic&#8221; in Q, isn&#8217;t that funny?) get mapped when called with a list as an argument.</p>
<pre>q)(3+)4
7
q) (3+)(1;2;3)
4 5 6
q)</pre>
<p>This approach causes problems though when we want to map a function that works both for atoms and lists. One such function is <code>enlist</code>, which creates a singleton list in Q, kind of like Haskell&#8217;s <code>return</code> in the list monad.</p>
<pre>(enlist 3)[0]
3</pre>
<p>So how can we map <code>enlist</code> over a list? Just calling it on a list gives a singleton list with the argument as the only element of the result:</p>
<pre>q) count (enlist (1;2;3))
1</pre>
<p>The only solution I can see is to use a trick with folding similar to the one in the definition of <code>replicate</code> above.</p>
<pre>map: { [f;xs]
	a: {x, (enlist z[y])};
	() a[ ; ;f]/ xs
	}</pre>
<p>This works:</p>
<pre>q)map[enlist; (1;2;3)]
1
2
3</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/slawekk.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/slawekk.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/slawekk.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/slawekk.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/slawekk.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/slawekk.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/slawekk.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/slawekk.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/slawekk.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/slawekk.wordpress.com/391/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=391&subd=slawekk&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://slawekk.wordpress.com/2009/07/24/haskell-in-q/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f0b149bf16959cf73a06bf8dae8298a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">slawekk</media:title>
		</media:content>
	</item>
		<item>
		<title>Moving again</title>
		<link>http://slawekk.wordpress.com/2009/07/22/moving-again/</link>
		<comments>http://slawekk.wordpress.com/2009/07/22/moving-again/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 21:59:24 +0000</pubDate>
		<dc:creator>slawekk</dc:creator>
				<category><![CDATA[offtopic]]></category>
		<category><![CDATA[personal]]></category>

		<guid isPermaLink="false">http://slawekk.wordpress.com/?p=383</guid>
		<description><![CDATA[I have decided to move with my family to Poland. I will be describing the experience on another blog.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=383&subd=slawekk&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have decided to move with my family to Poland. I will be describing the experience on another <a title="Repat in Poland" href="http://repatinpoland.wordpress.com/">blog</a>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/slawekk.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/slawekk.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/slawekk.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/slawekk.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/slawekk.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/slawekk.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/slawekk.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/slawekk.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/slawekk.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/slawekk.wordpress.com/383/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=383&subd=slawekk&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://slawekk.wordpress.com/2009/07/22/moving-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f0b149bf16959cf73a06bf8dae8298a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">slawekk</media:title>
		</media:content>
	</item>
		<item>
		<title>IsarMathLib version 1.6.9 released</title>
		<link>http://slawekk.wordpress.com/2009/07/07/isarmathlib-version-1-6-9-released/</link>
		<comments>http://slawekk.wordpress.com/2009/07/07/isarmathlib-version-1-6-9-released/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 23:06:58 +0000</pubDate>
		<dc:creator>slawekk</dc:creator>
				<category><![CDATA[announcements]]></category>
		<category><![CDATA[IsarMathLib releases]]></category>

		<guid isPermaLink="false">http://slawekk.wordpress.com/?p=379</guid>
		<description><![CDATA[I have released a new version of IsarMathLib. There are about 20 new theorems and a new theory on topological groups. The theory contains some basic definitions and notation and ends with a theorem that a subgroup of a topological group is a topological group.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=379&subd=slawekk&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have released a new version of IsarMathLib. There are about 20 new theorems and a new <a title="TopologicalGroup_ZF" href="http://isarmathlib.org/TopologicalGroup_ZF.html">theory</a> on topological groups. The theory contains some basic definitions and notation and ends with a theorem that a subgroup of a topological group is a topological group.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/slawekk.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/slawekk.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/slawekk.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/slawekk.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/slawekk.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/slawekk.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/slawekk.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/slawekk.wordpress.com/379/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/slawekk.wordpress.com/379/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/slawekk.wordpress.com/379/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=379&subd=slawekk&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://slawekk.wordpress.com/2009/07/07/isarmathlib-version-1-6-9-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f0b149bf16959cf73a06bf8dae8298a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">slawekk</media:title>
		</media:content>
	</item>
		<item>
		<title>Formalpedia</title>
		<link>http://slawekk.wordpress.com/2009/06/15/formalpedia/</link>
		<comments>http://slawekk.wordpress.com/2009/06/15/formalpedia/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 08:22:20 +0000</pubDate>
		<dc:creator>slawekk</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[reviews]]></category>
		<category><![CDATA[formalized mathematics]]></category>
		<category><![CDATA[formalized mathematics wiki]]></category>

		<guid isPermaLink="false">http://slawekk.wordpress.com/?p=362</guid>
		<description><![CDATA[Formalpedia is an &#8220;editable online repository of code and formal math&#8221;. It is on its way to became the first formalized mathematics wiki that goes online. Formalpedia is still read only, so it is not there yet. Mathematics on Formalpedia is (to be) verified by HOL Light. Most of the proofs are &#8220;not available yet&#8221;, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=362&subd=slawekk&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a title="FormalPedia" href="http://formalpedia.org/Top">Formalpedia</a> is an &#8220;editable online repository of code and formal math&#8221;. It is on its way to became the first formalized mathematics wiki that goes online. <span id="more-362"></span>Formalpedia is still read only, so it is not there yet. <a title="Mathematics" href="http://formalpedia.org/Mathematics">Mathematics</a> on Formalpedia is (to be) verified by <a title="HOL Light" href="http://www.cl.cam.ac.uk/~jrh13/hol-light/">HOL Light</a>. Most of the proofs are &#8220;not available yet&#8221;, but there are a couple that have been imported, so one can get the idea for how the presentation looks like. HOL Light verification scripts are known to be mostly write only, but one can see that the web presentation can help a lot in this respect. Formalpedia does use some mathematical notation and provides links to the &#8220;tactics&#8221; referenced in proofs. The assertion of a typical theorem looks like this:</p>
<p>Theorem (fact_divides_thm).</p>
<p><img src='http://s2.wordpress.com/latex.php?latex=%5Cforall+m%5C%3B+n.%5C%3B+m+%5Cleq_N+n+%5CRightarrow+%28%5Cexists+d+.%5C%3B+Arith.fact%5C%3B+n+%3D+d%5Ctimes_N+Arith.fact%5C%3B+m%29+&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\forall m\; n.\; m \leq_N n \Rightarrow (\exists d .\; Arith.fact\; n = d\times_N Arith.fact\; m) ' title='\forall m\; n.\; m \leq_N n \Rightarrow (\exists d .\; Arith.fact\; n = d\times_N Arith.fact\; m) ' class='latex' /></p>
<p>As we can see there is some confusing &#8220;Arith.fact&#8221; noise. Also for the theorem to be true the relation &#8220;<img src='http://s3.wordpress.com/latex.php?latex=m%5Cleq_N+m&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='m\leq_N m' title='m\leq_N m' class='latex' />&#8221; would have to somehow imply that <img src='http://s1.wordpress.com/latex.php?latex=m%2Cn&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='m,n' title='m,n' class='latex' /> are elements of some field. To understand how this happens I tried to click on <img src='http://s2.wordpress.com/latex.php?latex=%5Cleq_N&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\leq_N' title='\leq_N' class='latex' /> symbol, but that does not lead to the definition of that symbol, but rather to the whole rather big file where I guess the definition is. But with proper links to definitions and some effort from the reader I believe verification scripts presented at Formalpedia can be converted into readable proofs. Allowing informal (but LaTeX enabled) text to be interleaved with the formal HOL Light text would greatly improve readability of mathematics for people who are not HOL Light users. Clickable symbols in mathematical formulas is a very good idea and I would like to have something like that in IsarMathLib presentation at<a title="FormalMath.org" href="http://isarmathlib.org/"> FormalMath.org</a> as well. I don&#8217;t think jsMath that displays the math there supports that though.</p>
<p>Formalpedia is clearly under development and it is good that the authors (author?) decided to post this early alpha version. It would be better if they provided an easy way for getting a feedback from viewers. I could not find any link to a forum, blog or even e-mail that would allow for that. Maybe I missed something.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/slawekk.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/slawekk.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/slawekk.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/slawekk.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/slawekk.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/slawekk.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/slawekk.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/slawekk.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/slawekk.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/slawekk.wordpress.com/362/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=362&subd=slawekk&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://slawekk.wordpress.com/2009/06/15/formalpedia/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f0b149bf16959cf73a06bf8dae8298a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">slawekk</media:title>
		</media:content>
	</item>
		<item>
		<title>Markov chains</title>
		<link>http://slawekk.wordpress.com/2009/06/05/markov-chains/</link>
		<comments>http://slawekk.wordpress.com/2009/06/05/markov-chains/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 02:00:44 +0000</pubDate>
		<dc:creator>slawekk</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[mathematics]]></category>
		<category><![CDATA[probability]]></category>

		<guid isPermaLink="false">http://slawekk.wordpress.com/?p=335</guid>
		<description><![CDATA[The approach taken in the Haskell&#8217;s probability library makes it especially convenient for modeling Markov chains.
Suppose   is a Markov chain on a state space . Distribution of the process  is determined by the distribution of  and the numbers , , called transition probabilities. For simplicity let&#8217;s consider only time-homogeneous Markov chains where [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=335&subd=slawekk&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The approach taken in the Haskell&#8217;s probability library makes it especially convenient for modeling <a href="http://en.wikipedia.org/wiki/Markov_chain">Markov chains</a>.<br />
Suppose  <img src='http://s2.wordpress.com/latex.php?latex=%5C%7BX_n%5C%7D_%7Bn+%5Cin+%5Cmathbb%7BN%7D%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\{X_n\}_{n \in \mathbb{N}}' title='\{X_n\}_{n \in \mathbb{N}}' class='latex' /> is a Markov chain on a state space <img src='http://s3.wordpress.com/latex.php?latex=S&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='S' title='S' class='latex' />. Distribution of the process <img src='http://s1.wordpress.com/latex.php?latex=%5C%7BX_n%5C%7D_%7Bn+%5Cin+%5Cmathbb%7BN%7D%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\{X_n\}_{n \in \mathbb{N}}' title='\{X_n\}_{n \in \mathbb{N}}' class='latex' /> is determined by the distribution of <img src='http://s2.wordpress.com/latex.php?latex=X_0&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='X_0' title='X_0' class='latex' /> and the numbers <img src='http://s3.wordpress.com/latex.php?latex=Pr%28X_%7Bn%2B1%7D%3Dy+%7C+X_n+%3D+x%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Pr(X_{n+1}=y | X_n = x)' title='Pr(X_{n+1}=y | X_n = x)' class='latex' />, <img src='http://s1.wordpress.com/latex.php?latex=x%2Cy+%5Cin+S%2C+n+%5Cin+%5Cmathbb%7BN%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x,y \in S, n \in \mathbb{N}' title='x,y \in S, n \in \mathbb{N}' class='latex' />, called transition probabilities. For simplicity let&#8217;s consider only time-homogeneous Markov chains where these numbers don&#8217;t depend on <img src='http://s2.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> and let&#8217;s assume that the initial distribution is a point mass, i.e. <img src='http://s3.wordpress.com/latex.php?latex=X_0+%3D+x_0&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='X_0 = x_0' title='X_0 = x_0' class='latex' /> for some <img src='http://s1.wordpress.com/latex.php?latex=x_0%5Cin+S&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x_0\in S' title='x_0\in S' class='latex' />. Then we can define a function <img src='http://s2.wordpress.com/latex.php?latex=f%3A+S+%5Crightarrow+Dist%28S%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='f: S \rightarrow Dist(S)' title='f: S \rightarrow Dist(S)' class='latex' />, where for each <img src='http://s3.wordpress.com/latex.php?latex=x+%5Cin+S&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x \in S' title='x \in S' class='latex' /> the value <img src='http://s1.wordpress.com/latex.php?latex=f%28x%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='f(x)' title='f(x)' class='latex' /> is a distribution on <img src='http://s2.wordpress.com/latex.php?latex=S&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='S' title='S' class='latex' /> defined by <img src='http://s3.wordpress.com/latex.php?latex=%28f%28x%29%29%28y%29+%3D+Pr%28X_%7Bn%2B1%7D%3Dy+%7C+X_n+%3D+x%29%2C+x%2Cy+%5Cin+S%2C+n+%5Cin+%5Cmathbb%7BN%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(f(x))(y) = Pr(X_{n+1}=y | X_n = x), x,y \in S, n \in \mathbb{N}' title='(f(x))(y) = Pr(X_{n+1}=y | X_n = x), x,y \in S, n \in \mathbb{N}' class='latex' />. Here <img src='http://s1.wordpress.com/latex.php?latex=Dist%28S%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Dist(S)' title='Dist(S)' class='latex' /> denotes the set of finitely supported nonnegative functions on <img src='http://s2.wordpress.com/latex.php?latex=S&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='S' title='S' class='latex' /> that sum up to 1. Conceptually, <img src='http://s3.wordpress.com/latex.php?latex=f%28x%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='f(x)' title='f(x)' class='latex' /> is the the distribution of the next value of the chain given the current value is <img src='http://s1.wordpress.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x' title='x' class='latex' />. This is exactly the kind of distribution-valued function that is the right hand side operand of the <img src='http://s2.wordpress.com/latex.php?latex=%5Cleadsto&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\leadsto' title='\leadsto' class='latex' /> operation from the<a title="Probability monad post" href="http://slawekk.wordpress.com/2009/05/31/probability-monad/"> previous post</a>, which corresponds to the Haskell&#8217;s <code> &gt;&gt;= </code> operation in the probability monad.<span id="more-335"></span></p>
<p>The probability library&#8217;s Transition module contains a funtion called &#8220;compose&#8221; that allows to obtain the final distribution of a Markov chain given a list of transition functions and some initial value. Let&#8217;s consider a random walk as an example. Suppose we start from 0 and in each step we go up or down by 1 with the same probability. After importing Numeric.Probability.Distribution as D and Numeric.Probability.Transition as Tran we define the transition probabilities</p>
<p><code><br />
rwtran :: Tran.T Double Int<br />
rwtran x = D.choose 0.5 (x+1) (x-1)<br />
</code></p>
<p><code>Tran.T</code> is the type of transition functions, that is functions that assign distributions on some type (<code>Int</code> in this case) to values from that type.<br />
Now the final distribution of values after <img src='http://s3.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> steps of this Markov chain starting from initial value <img src='http://s1.wordpress.com/latex.php?latex=v&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='v' title='v' class='latex' /> can be calculated by</p>
<p><code><br />
rw :: Int -&gt; Int -&gt; D.T Double Int<br />
rw v n = (Tran.compose $ replicate n rwtran) v<br />
</code></p>
<p>Here <code> replicate n rwtran </code> creates a list of <img src='http://s2.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> (identical) transition functions that is magicaly composed by <code> compose</code> into one transition function that takes us all the way from the initial value to the final distriibution. From GHCi the distrubution after 5 steps looks like this:</p>
<pre>*ProbLib&gt; rw 0 5
fromFreqs [(-1,0.3125),(1,0.3125),(-3,0.15625),(3,0.15625),(-5,3.125e-2),(5,3.125e-2)]</pre>
<p>Using the ?? operator from the Distribution module we can ask about probability of some event, like what is the probability that after 10 steps the value is positive.</p>
<pre>*ProbLib Numeric.Probability.Distribution&gt; (&gt;0) ?? (rw 0 10)
0.376953125</pre>
<p>Sometimes the questions we want to ask are not about the the properties of the final random variable <img src='http://s3.wordpress.com/latex.php?latex=X_n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='X_n' title='X_n' class='latex' /> of a Markov chain, but about the whole path <img src='http://s1.wordpress.com/latex.php?latex=X_1%2C+X_2%2C+...%2C+X_n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='X_1, X_2, ..., X_n' title='X_1, X_2, ..., X_n' class='latex' />. For example suppose we want to know the probability that the random walk is never (up to n steps) negative. One way to do that is to consider another Markov chain <img src='http://s2.wordpress.com/latex.php?latex=%5C%7B+X%5E%2A_n%5C%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\{ X^*_n\}' title='\{ X^*_n\}' class='latex' /> whose state space is the set of sequences <img src='http://s3.wordpress.com/latex.php?latex=S%5E%2A+%3D+%5Cbigcup_%7Bn+%3E+0%7D+%28n%5Crightarrow+S%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='S^* = \bigcup_{n &gt; 0} (n\rightarrow S)' title='S^* = \bigcup_{n &gt; 0} (n\rightarrow S)' class='latex' /><br />
The transition function takes a sequence <img src='http://s1.wordpress.com/latex.php?latex=%28x_0%2C+x_1%2C...%2Cx_%7Bn-1%7D%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(x_0, x_1,...,x_{n-1})' title='(x_0, x_1,...,x_{n-1})' class='latex' /> of length <img src='http://s2.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> and assigns a distribution on sequences of length <img src='http://s3.wordpress.com/latex.php?latex=n%2B1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n+1' title='n+1' class='latex' /> in the obvious way. For our random walk example in Haskell we could write the following transition function</p>
<p><code><br />
rwptran :: Tran.T Double [Int]<br />
rwptran x = D.choose 0.5 (x ++ [(last x) + 1]) (x ++ [(last x) - 1])<br />
</code></p>
<p>And the distribution on the path space after n steps is calculated by</p>
<p><code><br />
rwp :: Int -&gt; Int -&gt; D.T Double [Int]<br />
rwp v n = (Tran.compose $ replicate n rwptran) [v]<br />
</code></p>
<p>For this particular process the distribution on the path space is not very interesting by itself as each path has the same probability.</p>
<pre>*ProbLib Numeric.Probability.Distribution&gt; rwp 0 3
fromFreqs [([0,-1,-2,-3],0.125),([0,-1,-2,-1],0.125),([0,-1,0,-1],0.125),
([0,-1,0,1],0.125),([0,1,0,-1],0.125),([0,1,0,1],0.125),([0,1,2,1],0.125),
([0,1,2,3],0.125)]</pre>
<p>However, now we can ask questions related to paths. For example, what is the probability that in 10 steps we never go negative?</p>
<pre>*ProbLib Numeric.Probability.Distribution&gt; (all (&gt;= 0)) ?? (rwp 0 10)
0.24609375</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/slawekk.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/slawekk.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/slawekk.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/slawekk.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/slawekk.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/slawekk.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/slawekk.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/slawekk.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/slawekk.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/slawekk.wordpress.com/335/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=335&subd=slawekk&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://slawekk.wordpress.com/2009/06/05/markov-chains/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f0b149bf16959cf73a06bf8dae8298a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">slawekk</media:title>
		</media:content>
	</item>
		<item>
		<title>Probability monad</title>
		<link>http://slawekk.wordpress.com/2009/05/31/probability-monad/</link>
		<comments>http://slawekk.wordpress.com/2009/05/31/probability-monad/#comments</comments>
		<pubDate>Sun, 31 May 2009 22:39:43 +0000</pubDate>
		<dc:creator>slawekk</dc:creator>
				<category><![CDATA[mathematics]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[probability]]></category>

		<guid isPermaLink="false">http://slawekk.wordpress.com/?p=295</guid>
		<description><![CDATA[My favourite programming language Haskell has a nice library for doing calculations with probablility distributions, called probability.
The library was originally written by Martin Ewig and Steve Kollmansberger and then extended and packaged for convenient installation by Henning Thieleman. Its main idea for the implementation is to use the fact that &#8220;probability distributions form a monad&#8221; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=295&subd=slawekk&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>My favourite programming language <a title="Haskell" href="http://haskell.org/">Haskell</a> has a nice library for doing calculations with probablility distributions, called <a title="Probability library" href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/probability"><em>probability</em></a>.<br />
The library was originally <a title="probability in Haskell" href="http://web.engr.oregonstate.edu/~erwig/pfp/">written</a> by Martin Ewig and Steve Kollmansberger and then extended and packaged for convenient installation by Henning Thieleman. Its main idea for the implementation is to use the fact that &#8220;probability distributions form a monad&#8221; (from a <a title="Probabilistic Functional Programming" href="http://web.engr.oregonstate.edu/~erwig/papers/PFP_JFP06.pdf">paper</a> by the authors of the library ). This post aims at translating this claim into standard probability notation and showing how it is used in the library.<span id="more-295"></span></p>
<p>Monad is a notion in category theory which is defined as a monoid in the category of endofunctors. That sounds so cool that I really wish I knew what it means. The only thing I know now is that the &#8220;monoid&#8221; here is not the standard <a title="Monoid" href="http://en.wikipedia.org/wiki/Monoid_(algebra)">monoid</a> from mathematics founded on set theory, but rather its category theory analogue. So what does the claim &#8220;probability distributions form a monad&#8221; mean Haskell-wise?</p>
<p>Let&#8217;s load the library and play with it.</p>
<pre>Prelude&gt;:m +Numeric.Probability.Distribution</pre>
<p>In the <em>probability</em> library distributions are (essentially) represented as lists of pairs (element, probability).<br />
There are a couple of functions defined that provide means of generating some often used distributions. For example &#8220;choose p a b&#8221; will generate a distribution that assigns probability p to a value a and (1-p) to b.</p>
<pre>Prelude Numeric.Probability.Distribution&gt; choose 0.3 0 1

Loading package array-0.1.0.0 ... linking ... done.
Loading package containers-0.1.0.1 ... linking ... done.
Loading package mtl-1.1.0.0 ... linking ... done.
Loading package old-locale-1.0.0.0 ... linking ... done.
Loading package old-time-1.0.0.0 ... linking ... done.
Loading package random-1.0.0.0 ... linking ... done.
Loading package probability-0.2.1 ... linking ... done.
fromFreqs [(1,0.7),(0,0.3)]</pre>
<p>Another example is the function &#8220;uniform&#8221; that assigns the same probability to all elements of a list.</p>
<pre>Prelude Numeric.Probability.Distribution&gt; uniform [0,1,2,3]

fromFreqs [(0,0.25),(1,0.25),(2,0.25),(3,0.25)]</pre>
<p>There is also a function &#8220;certainly&#8221; that constructs a point mass</p>
<pre>Prelude Numeric.Probability.Distribution&gt; certainly 5

fromFreqs [(5,1)]</pre>
<p>Now what about that monad thing? Let&#8217;s think about distributions on a given finite set <img src='http://s2.wordpress.com/latex.php?latex=X&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='X' title='X' class='latex' /> as nonnegative functions that sum up to 1 and let <img src='http://s3.wordpress.com/latex.php?latex=Dist%28X%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Dist(X)' title='Dist(X)' class='latex' /> be the set of such distributions. So, we have <img src='http://s1.wordpress.com/latex.php?latex=Dist%28X%29+%3D+%5C%7B+P%3A+X+%5Crightarrow+%5B0%2C1%5D+%7C+%5Csum_%7Bx%5Cin+X%7D+P%28x%29+%3D+1%5C%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Dist(X) = \{ P: X \rightarrow [0,1] | \sum_{x\in X} P(x) = 1\}' title='Dist(X) = \{ P: X \rightarrow [0,1] | \sum_{x\in X} P(x) = 1\}' class='latex' />. Suppose now we have two finite sets <img src='http://s2.wordpress.com/latex.php?latex=A%2CB&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='A,B' title='A,B' class='latex' />. We can define a binary operation <img src='http://s3.wordpress.com/latex.php?latex=%5Cleadsto%3A%28Dist%28A%29+%5Ctimes+%28A+%5Crightarrow+Dist%28B%29%29%29+%5Crightarrow+Dist%28B%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\leadsto:(Dist(A) \times (A \rightarrow Dist(B))) \rightarrow Dist(B)' title='\leadsto:(Dist(A) \times (A \rightarrow Dist(B))) \rightarrow Dist(B)' class='latex' /> that takes a distribution on <img src='http://s1.wordpress.com/latex.php?latex=A&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='A' title='A' class='latex' /> and a function that assigns a distribution on <img src='http://s2.wordpress.com/latex.php?latex=B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='B' title='B' class='latex' /> to every element of <img src='http://s3.wordpress.com/latex.php?latex=A&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='A' title='A' class='latex' />, and creates a distribution on <img src='http://s1.wordpress.com/latex.php?latex=B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='B' title='B' class='latex' /> in a (quite) natural way:</p>
<p><img src='http://s2.wordpress.com/latex.php?latex=%28P+%5Cleadsto+f%29%28b%29+%3D+%5Csum_%7Ba%5Cin+A%7D+P%28a%29%5Ccdot+%28f%28a%29%29%28b%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(P \leadsto f)(b) = \sum_{a\in A} P(a)\cdot (f(a))(b)' title='(P \leadsto f)(b) = \sum_{a\in A} P(a)\cdot (f(a))(b)' class='latex' /> for any <img src='http://s3.wordpress.com/latex.php?latex=P%5Cin+Dist%28A%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='P\in Dist(A)' title='P\in Dist(A)' class='latex' /> and <img src='http://s1.wordpress.com/latex.php?latex=f%3A+A%5Crightarrow+Dist%28B%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='f: A\rightarrow Dist(B)' title='f: A\rightarrow Dist(B)' class='latex' />.</p>
<p>By taking the sum over all <img src='http://s2.wordpress.com/latex.php?latex=b+%5Cin+B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='b \in B' title='b \in B' class='latex' /> it is easy to check that <img src='http://s3.wordpress.com/latex.php?latex=P+%5Cleadsto+f&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='P \leadsto f' title='P \leadsto f' class='latex' /> is indeed a distribution on <img src='http://s1.wordpress.com/latex.php?latex=B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='B' title='B' class='latex' />. It can be interpreted as the distribution of the result of selecting first <img src='http://s2.wordpress.com/latex.php?latex=a+%5Cin+A&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='a \in A' title='a \in A' class='latex' /> according to distribution <img src='http://s3.wordpress.com/latex.php?latex=P&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='P' title='P' class='latex' /> and then selecting from the set <img src='http://s1.wordpress.com/latex.php?latex=B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='B' title='B' class='latex' /> according to the distribution given by <img src='http://s2.wordpress.com/latex.php?latex=f%28a%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='f(a)' title='f(a)' class='latex' />.</p>
<p>We can use the &#8220;<img src='http://s3.wordpress.com/latex.php?latex=%5Cleadsto+&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\leadsto ' title='\leadsto ' class='latex' />&#8221; (corresponding to Haskell&#8217;s &#8220;&gt;&gt;=&#8221;) operation to construct joint distributions. For example to generate o model of two coin tosses we can do</p>
<pre>Prelude Numeric.Probability.Distribution&gt;
(choose 0.5 0 1) &gt;&gt;= (\x -&gt; choose 0.5 (x,0) (x,1))

fromFreqs [((0,0),0.25),((0,1),0.25),((1,0),0.25),((1,1),0.25)]</pre>
<p>Now suppose we have three finite sets <img src='http://s1.wordpress.com/latex.php?latex=A%2CB%2CC&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='A,B,C' title='A,B,C' class='latex' /> and corresponding operations in</p>
<p><img src='http://s2.wordpress.com/latex.php?latex=%28Dist%28A%29+%5Ctimes+%28A+%5Crightarrow+Dist%28B%29%29%29+%5Crightarrow+Dist%28B%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(Dist(A) \times (A \rightarrow Dist(B))) \rightarrow Dist(B)' title='(Dist(A) \times (A \rightarrow Dist(B))) \rightarrow Dist(B)' class='latex' /></p>
<p>and</p>
<p><img src='http://s3.wordpress.com/latex.php?latex=%28Dist%28B%29+%5Ctimes+%28B+%5Crightarrow+Dist%28C%29%29%29+%5Crightarrow+Dist%28C%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(Dist(B) \times (B \rightarrow Dist(C))) \rightarrow Dist(C)' title='(Dist(B) \times (B \rightarrow Dist(C))) \rightarrow Dist(C)' class='latex' /></p>
<p>that we will both denote <img src='http://s1.wordpress.com/latex.php?latex=%5Cleadsto&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\leadsto' title='\leadsto' class='latex' />. Then for all <img src='http://s2.wordpress.com/latex.php?latex=P+%5Cin+Dist%28A%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='P \in Dist(A)' title='P \in Dist(A)' class='latex' />, <img src='http://s3.wordpress.com/latex.php?latex=f%3A+A%5Crightarrow+Dist%28B%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='f: A\rightarrow Dist(B)' title='f: A\rightarrow Dist(B)' class='latex' /> and <img src='http://s1.wordpress.com/latex.php?latex=g+%5Cin+B%5Crightarrow+Dist%28C%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g \in B\rightarrow Dist(C)' title='g \in B\rightarrow Dist(C)' class='latex' /> we have the identity <img src='http://s2.wordpress.com/latex.php?latex=%28%28P+%5Cleadsto+f%29+%5Cleadsto+g%29+%3D+P+%5Cleadsto+h&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='((P \leadsto f) \leadsto g) = P \leadsto h' title='((P \leadsto f) \leadsto g) = P \leadsto h' class='latex' />, where <img src='http://s3.wordpress.com/latex.php?latex=h%3A+A+%5Crightarrow+Dist%28C%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h: A \rightarrow Dist(C)' title='h: A \rightarrow Dist(C)' class='latex' /> is defined as <img src='http://s1.wordpress.com/latex.php?latex=h%28a%29+%3D+F%28a%29+%5Cleadsto+g%2C%5C+a%5Cin+A&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h(a) = F(a) \leadsto g,\ a\in A' title='h(a) = F(a) \leadsto g,\ a\in A' class='latex' />.<br />
Note that if <img src='http://s2.wordpress.com/latex.php?latex=a+%5Cin+A&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='a \in A' title='a \in A' class='latex' /> then <img src='http://s3.wordpress.com/latex.php?latex=h%28a%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h(a)' title='h(a)' class='latex' /> is a distribution on <img src='http://s1.wordpress.com/latex.php?latex=C&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C' title='C' class='latex' /> and <img src='http://s2.wordpress.com/latex.php?latex=%28h%28a%29%29+%28c%29+%3D+%5Csum_%7Bb%5Cin+B%7D+%28f%28a%29%29%28b%29%5Ccdot+%28g%28b%29%29%28c%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(h(a)) (c) = \sum_{b\in B} (f(a))(b)\cdot (g(b))(c)' title='(h(a)) (c) = \sum_{b\in B} (f(a))(b)\cdot (g(b))(c)' class='latex' /> for <img src='http://s3.wordpress.com/latex.php?latex=c+%5Cin+C&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='c \in C' title='c \in C' class='latex' />.</p>
<p>Let&#8217;s expand both sides to see that the identity really holds. Fix <img src='http://s1.wordpress.com/latex.php?latex=c+%5Cin+C&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='c \in C' title='c \in C' class='latex' />. We want to see that the values of the distributions  <img src='http://s2.wordpress.com/latex.php?latex=%28P+%5Cleadsto+f%29+%5Cleadsto+g&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(P \leadsto f) \leadsto g' title='(P \leadsto f) \leadsto g' class='latex' /> and <img src='http://s3.wordpress.com/latex.php?latex=P+%5Cleadsto+h&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='P \leadsto h' title='P \leadsto h' class='latex' /> are the same on <img src='http://s1.wordpress.com/latex.php?latex=c&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='c' title='c' class='latex' />.</p>
<p>The left hand side evaluates to</p>
<p><img src='http://s2.wordpress.com/latex.php?latex=%5Csum_%7Bb%5Cin+B%7D+%28P+%5Cleadsto+f%29%28b%29+%5Ccdot+%28g%28b%29%29%28c%29+%3D+%5Csum_%7Bb%5Cin+B%7D+%5Csum_%7Ba%5Cin+A%7D+P%28a%29+%5Ccdot+%28f%28a%29%29%28b%29%5Ccdot+%28g%28b%29%29%28c%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\sum_{b\in B} (P \leadsto f)(b) \cdot (g(b))(c) = \sum_{b\in B} \sum_{a\in A} P(a) \cdot (f(a))(b)\cdot (g(b))(c)' title='\sum_{b\in B} (P \leadsto f)(b) \cdot (g(b))(c) = \sum_{b\in B} \sum_{a\in A} P(a) \cdot (f(a))(b)\cdot (g(b))(c)' class='latex' /></p>
<p>and on the right hand side we have</p>
<p><img src='http://s3.wordpress.com/latex.php?latex=%5Csum_%7Ba%5Cin+A%7D+P%28a%29%5Ccdot+%28h%28a%29%29%28c%29+%3D+%5Csum_%7Ba%5Cin+A%7D+P%28a%29%5Ccdot+%5Csum_%7Bb%5Cin+B%7D+%28f%28a%29%29%28b%29%5Ccdot+%28g%28b%29%29%28c%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\sum_{a\in A} P(a)\cdot (h(a))(c) = \sum_{a\in A} P(a)\cdot \sum_{b\in B} (f(a))(b)\cdot (g(b))(c)' title='\sum_{a\in A} P(a)\cdot (h(a))(c) = \sum_{a\in A} P(a)\cdot \sum_{b\in B} (f(a))(b)\cdot (g(b))(c)' class='latex' />.</p>
<p>So they are the same.</p>
<p>The fact that we have such quasi-associativity (plus two other conditions that are trivial to check) allows to claim that the type of distributions forms a monad. In Haskell this opens up a whole world of possibilities. There are hundreds of functions related to monads in Haskell libraries. One can assume that each one does something useful when applied to probabilistic calculations and the only problem is to figure out what that useful thing is.<br />
For example the function &#8220;replicateM&#8221; creates distributions of sequences of independent identically distributed random variables:</p>
<pre>Prelude Numeric.Probability.Distribution&gt; :m + Control.Monad
Prelude Numeric.Probability.Distribution Control.Monad&gt;
replicateM 4 (choose 0.5 0 1)

fromFreqs [([0,0,0,0],6.25e-2),([0,0,0,1],6.25e-2),([0,0,1,0],6.25e-2),
([0,0,1,1],6.25e-2),([0,1,0,0],6.25e-2),([0,1,0,1],6.25e-2),([0,1,1,0],
6.25e-2),([0,1,1,1],6.25e-2),([1,0,0,0],6.25e-2),([1,0,0,1],6.25e-2),
([1,0,1,0],6.25e-2),([1,0,1,1],6.25e-2),([1,1,0,0],6.25e-2),
([1,1,0,1],6.25e-2),([1,1,1,0],6.25e-2),([1,1,1,1],6.25e-2)]</pre>
<p>One can define a function that calculates the sequence of expectations of maximum of <img src='http://s1.wordpress.com/latex.php?latex=1%2C2%2C...n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='1,2,...n' title='1,2,...n' class='latex' /> i.i.d random variables with common distribution <img src='http://s2.wordpress.com/latex.php?latex=d&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d' title='d' class='latex' /> as follows:</p>
<pre>expmaxseq n d = [D.expected $ D.map maximum $ replicateM k d | k &lt;- [1..n]]</pre>
<p>For throwing dice we get the following expectations of maximum for 1,2,&#8230;, 7 dice:</p>
<pre>ProbLib Numeric.Probability.Distribution&gt; expmaxseq 7 (uniform [1..6])

[3.5,4.472222222222223,4.958333333333335,5.2445987654321105,
5.4309413580246915,5.560292352536542,5.65411736969124]</pre>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:0;width:1px;height:1px;">and Steve Kollmansberger</div>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/slawekk.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/slawekk.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/slawekk.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/slawekk.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/slawekk.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/slawekk.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/slawekk.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/slawekk.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/slawekk.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/slawekk.wordpress.com/295/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=295&subd=slawekk&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://slawekk.wordpress.com/2009/05/31/probability-monad/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f0b149bf16959cf73a06bf8dae8298a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">slawekk</media:title>
		</media:content>
	</item>
		<item>
		<title>IsarMathLib version 1.6.8 released</title>
		<link>http://slawekk.wordpress.com/2009/04/26/isarmathlin-version-168-released/</link>
		<comments>http://slawekk.wordpress.com/2009/04/26/isarmathlin-version-168-released/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 00:17:52 +0000</pubDate>
		<dc:creator>slawekk</dc:creator>
				<category><![CDATA[IsarMathLib releases]]></category>
		<category><![CDATA[announcements]]></category>

		<guid isPermaLink="false">http://slawekk.wordpress.com/?p=286</guid>
		<description><![CDATA[This release is  the first version of the IsarMathLib library for the new Isabelle2009. There is a little bit of new formalized mathematics as well.
The new CommutativeSemigroup_ZF theory is another take on the subject of summing up elements of some finite subset of a semigroup. This is similar to what was done in the Semigroup [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=286&subd=slawekk&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>This release is  the first version of the <a title="IsarMathLib home" href="http://www.nongnu.org/isarmathlib/">IsarMathLib</a> library for the new Isabelle2009. There is a little bit of new formalized mathematics as well.<span id="more-286"></span></p>
<p>The new <a title="CommutativeSemigroup theory" href="http://isarmathlib.org/CommutativeSemigroup_ZF.html">CommutativeSemigroup_ZF</a> theory is another take on the subject of summing up elements of some finite subset of a semigroup. This is similar to what was done in the <a title="Semigroup" href="http://isarmathlib.org/Semigroup_ZF.html">Semigroup</a> theory, but this time the approach is more specific to the case when the semigroup operation is commutative and does not require a linear order on the elements that we are summing up. This formalizes the definition of <img src='http://s3.wordpress.com/latex.php?latex=%5Csum_A+a&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\sum_A a' title='\sum_A a' class='latex' /> where <img src='http://s1.wordpress.com/latex.php?latex=a%3A+X+%5Crightarrow+G&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='a: X \rightarrow G' title='a: X \rightarrow G' class='latex' /> is an indexed  family of elements of the semigroup <img src='http://s2.wordpress.com/latex.php?latex=G&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='G' title='G' class='latex' /> and  <img src='http://s3.wordpress.com/latex.php?latex=A%5Csubseteq+X&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='A\subseteq X' title='A\subseteq X' class='latex' /> is some finite subset of the index set. I have  written a bit about it that <a title="Int. Arith. pass 1" href="http://slawekk.wordpress.com/2008/12/06/interval-arithmetic-in-groups-pass-1/">previously</a>.</p>
<p>I also added a couple of <a href="http://isarmathlib.org/func_ZF.html#lift_subsets_binop">theorems</a> on the notion of lifting an operation to subsets. This is just a name I came up with for the operation on subsets of <img src='http://s1.wordpress.com/latex.php?latex=X&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='X' title='X' class='latex' /> that is defined naturally by any binary operation on <img src='http://s2.wordpress.com/latex.php?latex=X&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='X' title='X' class='latex' />. I discussed this in the &#8220;<a title="Intrv. Arith. pass 2" href="http://slawekk.wordpress.com/2009/03/01/interval-arithmetic-in-groups-pass-2/">Interval arithmetic in groups &#8211; pass  2</a>&#8221; post.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/slawekk.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/slawekk.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/slawekk.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/slawekk.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/slawekk.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/slawekk.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/slawekk.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/slawekk.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/slawekk.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/slawekk.wordpress.com/286/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=286&subd=slawekk&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://slawekk.wordpress.com/2009/04/26/isarmathlin-version-168-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f0b149bf16959cf73a06bf8dae8298a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">slawekk</media:title>
		</media:content>
	</item>
		<item>
		<title>Isabelle 2009 released</title>
		<link>http://slawekk.wordpress.com/2009/04/22/isabelle-2009-released/</link>
		<comments>http://slawekk.wordpress.com/2009/04/22/isabelle-2009-released/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 00:06:10 +0000</pubDate>
		<dc:creator>slawekk</dc:creator>
				<category><![CDATA[announcements]]></category>
		<category><![CDATA[Isabelle]]></category>
		<category><![CDATA[Isabelle 2009]]></category>
		<category><![CDATA[readability]]></category>

		<guid isPermaLink="false">http://slawekk.wordpress.com/?p=278</guid>
		<description><![CDATA[The Isabelle team has released version 2009. Updating IsarMathLib to Isabelle 2009 was very easy. I only had to make a couple of corrections to proofs that used assumptions implicitly. The only more complicated change was related to renaming variables in the locale syntax.
Isabelle supports &#8220;locales&#8221; that are constructs that allow to limit the scope [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=278&subd=slawekk&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The <a title="Isabelle home" href="http://www.cl.cam.ac.uk/research/hvg/Isabelle/">Isabelle</a> team has released version 2009. Updating IsarMathLib to Isabelle 2009 was very easy. I only had to make a couple of corrections to proofs that used assumptions implicitly. The only more complicated change was related to renaming variables in the locale syntax.<span id="more-278"></span></p>
<p>Isabelle supports &#8220;locales&#8221; that are constructs that allow to limit the scope of definitions and notation. In IsarMathLib locales are used as kind of contexts  that hold certain assumptions and define notation specific to the some area of mathematics. For example, an IsarMathLib locale called <em>ring0 </em>contains an assumption that the sets <img src='http://s1.wordpress.com/latex.php?latex=R%2CA%2CM&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='R,A,M' title='R,A,M' class='latex' /> form a ring. This locale assumption is then implicitly added to all theorems  proven in the locale. In case of the <em>ring0</em> locale the set <img src='http://s2.wordpress.com/latex.php?latex=R&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='R' title='R' class='latex' /> is the &#8220;carrier&#8221; of the ring, <img src='http://s3.wordpress.com/latex.php?latex=A&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='A' title='A' class='latex' /> represents the addition and <img src='http://s1.wordpress.com/latex.php?latex=M&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='M' title='M' class='latex' /> is the multiplication (recall that in ZF set theory binary operations are sets). Locales can form hierarchies in a way similar to classes in OO programming languages, inheriting assumptions and notation. In IsarMathLib locale <em>field0</em> extends locale <em>ring0</em> by adding an assumption that multiplicative inverses exist for all non-zero elements. Locales also allow to rename the variables inherited from the parent. In case of the <em>field0</em> locale the carrier is named <img src='http://s2.wordpress.com/latex.php?latex=K&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='K' title='K' class='latex' /> rather that <img src='http://s3.wordpress.com/latex.php?latex=R&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='R' title='R' class='latex' />, as is customary for fields. It is the syntax for renaming that got changed in Isabelle 2009. In Isabelle 2008 I could write</p>
<pre>locale field0 = ring0 K</pre>
<p>and the first variable in the <em>ring0</em> locale could be used as <img src='http://s1.wordpress.com/latex.php?latex=K&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='K' title='K' class='latex' /> in the <em>field0</em> locale. For Isabelle 2009 it seems I have to write</p>
<pre>locale field0 = ring0 K A M for K A M,</pre>
<p>repeating the fixed sets of the locale twice. I can live with it, but it looks weird and programmish. The main reason I like the Isar proof language is that it is typically similar to what one would write in a standard (informal) mathematical proof. This change is a step away from this idea. I think it would be better to be able to write something like</p>
<pre>locale field0 =  ring0 renaming R to K .</pre>
<p>This way it would look a bit like Cobol and I am saying there is nothing wrong with that.</p>
<p>In addition to the old ProofGeneral interface the 2009 release contains an experimental interface written in Scala as a <a title="Jedit" href="http://www.jedit.org/">Jedit</a> plugin. I am planning on checking that out.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/slawekk.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/slawekk.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/slawekk.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/slawekk.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/slawekk.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/slawekk.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/slawekk.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/slawekk.wordpress.com/278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/slawekk.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/slawekk.wordpress.com/278/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=278&subd=slawekk&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://slawekk.wordpress.com/2009/04/22/isabelle-2009-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f0b149bf16959cf73a06bf8dae8298a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">slawekk</media:title>
		</media:content>
	</item>
		<item>
		<title>MathWiki project is hiring</title>
		<link>http://slawekk.wordpress.com/2009/03/10/mathwiki-project-is-hiring/</link>
		<comments>http://slawekk.wordpress.com/2009/03/10/mathwiki-project-is-hiring/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 21:38:57 +0000</pubDate>
		<dc:creator>slawekk</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[formalized mathematics wiki]]></category>
		<category><![CDATA[mathwiki]]></category>

		<guid isPermaLink="false">http://slawekk.wordpress.com/?p=272</guid>
		<description><![CDATA[Apparently the formalized mathematics project at Radboud University Nijmegen (NL) that I wrote about previously did get some funding after all and they are hiring two people to work on it. The PhD position is for 4 years and the postdoc position is 3 years. I hope that a usable formalized mathematics wiki will be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=272&subd=slawekk&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Apparently the formalized mathematics project at <span class="yshortcuts" style="border-bottom:1px dashed #0066cc;background:transparent none repeat scroll 0 0;cursor:pointer;">Radboud University Nijmegen</span> (NL) that I <a title="MathWiki" href="http://slawekk.wordpress.com/2008/10/11/math-wiki-news/">wrote</a> about previously did get some funding after all and they are <a title="MathWiki nnouncement" href="http://groups.google.com/group/eafit-logic-and-computation/browse_thread/thread/ebdeb162936701cc">hiring</a> two people to work on it. The PhD position is for 4 years and the postdoc position is 3 years. I hope that a usable formalized mathematics wiki will be available earlier.</p>
<p>The postdoc position pays a &#8220;maximum salary&#8221;  of 3755 Euro per month. Such wording immediately makes me curious what is the minimum &#8230; .</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/slawekk.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/slawekk.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/slawekk.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/slawekk.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/slawekk.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/slawekk.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/slawekk.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/slawekk.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/slawekk.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/slawekk.wordpress.com/272/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=slawekk.wordpress.com&blog=1771533&post=272&subd=slawekk&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://slawekk.wordpress.com/2009/03/10/mathwiki-project-is-hiring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f0b149bf16959cf73a06bf8dae8298a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">slawekk</media:title>
		</media:content>
	</item>
	</channel>
</rss>