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

<channel>
	<title>Michi's blog &#187; Combinatorics</title>
	<atom:link href="http://blog.mikael.johanssons.org/archive/category/mathematics/combinatorics/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mikael.johanssons.org</link>
	<description>Because my LiveJournal is too silly</description>
	<lastBuildDate>Sat, 12 Nov 2011 15:09:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Species, derivatives of types and Gröbner bases for operads</title>
		<link>http://blog.mikael.johanssons.org/archive/2010/12/species-derivatives-of-types-and-grobner-bases-for-operads/</link>
		<comments>http://blog.mikael.johanssons.org/archive/2010/12/species-derivatives-of-types-and-grobner-bases-for-operads/#comments</comments>
		<pubDate>Sat, 18 Dec 2010 01:05:30 +0000</pubDate>
		<dc:creator>Michi</dc:creator>
				<category><![CDATA[Algebra]]></category>
		<category><![CDATA[Category theory]]></category>
		<category><![CDATA[Combinatorics]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Operads and PROPs]]></category>
		<category><![CDATA[Research]]></category>

		<guid isPermaLink="false">http://blog.mikael.johanssons.org/?p=270</guid>
		<description><![CDATA[This is a typed up copy of my lecture notes from the combinatorics seminar at KTH, 2010-09-01. This is not a perfect copy of what was said at the seminar, rather a starting point from which the talk grew. In some points, I&#8217;ve tried to fill in the most sketchy and un-articulated points with some [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is a typed up copy of my lecture notes from the combinatorics seminar at KTH, 2010-09-01. This is not a perfect copy of what was said at the seminar, rather a starting point from which the talk grew.</p>
<p>In some points, I&#8217;ve tried to fill in the most sketchy and un-articulated points with some simile of what I ended up actually saying.<br />
</em></p>
<p>Combinatorial species started out as a theory to deal with enumerative combinatorics, by providing a toolset &#038; calculus for formal power series. (see Bergeron-Labelle-Leroux and Joyal)</p>
<p>As it turns out, not only is species useful for manipulating generating functions, btu it provides this with a categorical approach that may be transplanted into other areas.</p>
<p>For the benefit of the entire audience, I shall introduce some definitions.</p>
<p><strong>Definition</strong>: A <em>category</em> C is a collection of <em>objects</em> and <em>arrows</em> with each arrow assigned a <em>source</em> and <em>target</em> object, such that </p>
<ol>
<li>Each object has its own <em>identity arrow</em> 1.</li>
<li>Chains of arrows are associatively <em>composable</em>, with 1 the identity of this composition.</li>
</ol>
<p><strong>Examples</strong>: Sets, Finite sets, k-Vector spaces, left and right R-Modules, Graphs, Groups, Abelian groups.</p>
<p><img src='/latexrender/pictures/e19c41413e1b974679b02bd79d5d494c.png' title='\mathbb B' alt='\mathbb B' align='middle' />: finite sets with only bijections as morphisms.</p>
<p><strong>Examples</strong>: </p>
<ul>
<li>Category of a monoid.</li>
<li>Category generated by a graph</li>
<li>Category of a group (groupoid version of the category of a monoid)</li>
<li>Category of a poset</li>
<li>Category of Haskell types and functions.</li>
</ul>
<p><strong>Definition</strong>: A <em>functor</em> F is a map of categories, in other words, a pair of maps Fo on objects and Fa on arrows, such that the identity arrow maps to identity arrows and compositions of maps map to compositions of their images.</p>
<p><strong>Examples</strong>:<br />
Constant functor: sends every object to A, every map to 1.</p>
<p>Identity functor: sends objects and arrows to themselves.</p>
<p>Underlying set functor, free monoid/vector space/module/&#8230; functors.</p>
<p>We are now equipped to define Species:<br />
<strong>Definition</strong>: A <em>species of structures</em> is a functor <img src='/latexrender/pictures/248ed9b3523a819e669addcfca0dd9e1.png' title='\mathbb B\to\mathbb B' alt='\mathbb B\to\mathbb B' align='middle' />.</p>
<p>The idea is a set gets mapped to the set of all structures labelled by the elements in the original set. A bijection on labels maps to the <em>transport of structures</em> along the relabeling. </p>
<p><strong>Examples</strong>:<br />
<img src='/latexrender/pictures/7fc56270e7a70fa81a5935b72eacbe29.png' title='A' alt='A' align='middle' />: rooted trees, labels on vertices<br />
<img src='/latexrender/pictures/dfcf28d0734569a6a693bc8194de62bf.png' title='G' alt='G' align='middle' />: simple graphs, labels on vertices<br />
<img src='/latexrender/pictures/68306c3af365d0638ca6a65e96012770.png' title='Gc' alt='Gc' align='middle' />: connected simple graphs, labels on vertices.<br />
<img src='/latexrender/pictures/0cc175b9c0f1b6a831c399e269772661.png' title='a' alt='a' align='middle' />: trees, labels on vertices.<br />
<img src='/latexrender/pictures/f623e75af30e62bbd73d6df5b50bb7b5.png' title='D' alt='D' align='middle' />: directed graphs, labels on vertices<br />
<img src='/latexrender/pictures/1a13d972a2c8473f075ded6eca465169.png' title='\wp' alt='\wp' align='middle' />: subsets, <img src='/latexrender/pictures/ab03f17fcfe3bf3f9f730c032cf12151.png' title='\wp[U] = \{S: S\subseteq U\}' alt='\wp[U] = \{S: S\subseteq U\}' align='middle' />.<br />
<img src='/latexrender/pictures/87557f11575c0ad78e4e28abedc13b6e.png' title='End' alt='End' align='middle' />: endofunctions<br />
<img src='/latexrender/pictures/a7e871520a392b978d3c9e6344c4407f.png' title='Inv' alt='Inv' align='middle' />: involutions<br />
<img src='/latexrender/pictures/5dbc98dcc983a70728bd082d1a47546e.png' title='S' alt='S' align='middle' />: permutations<br />
<img src='/latexrender/pictures/0d61f8370cad1d412f80b84d143e1257.png' title='C' alt='C' align='middle' />: cycles<br />
<img src='/latexrender/pictures/d20caec3b48a1eef164cb4ca81ba2587.png' title='L' alt='L' align='middle' />: linear orders<br />
<img src='/latexrender/pictures/3a3ea00cfc35332cedf6e5e9a32e94da.png' title='E' alt='E' align='middle' />: sets: <img src='/latexrender/pictures/4784af6daa47ce1b4dc27c7f968b48a3.png' title='E[U] = \{U\}' alt='E[U] = \{U\}' align='middle' /><br />
<img src='/latexrender/pictures/e1671797c52e15f763380b45e841ec32.png' title='e' alt='e' align='middle' />: elements: <img src='/latexrender/pictures/8f19454f9794245cdbaabf2330720444.png' title='e[U] = U' alt='e[U] = U' align='middle' /><br />
<img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' />: singletons: <img src='/latexrender/pictures/eedeabedbaf43a4ce7a1b347c32faf43.png' title='X[U] = U' alt='X[U] = U' align='middle' /> if <img src='/latexrender/pictures/a03dbebf1f9af1a9557fff5ace5c7534.png' title='|U|=1' alt='|U|=1' align='middle' /> and <img src='/latexrender/pictures/0118beed08546bf49c98e18e68f4e401.png' title='X[U] = \emptyset' alt='X[U] = \emptyset' align='middle' /> otherwise<br />
<img src='/latexrender/pictures/c4ca4238a0b923820dcc509a6f75849b.png' title='1' alt='1' align='middle' />: empty set: <img src='/latexrender/pictures/09f8d10bb99358b7c16cdbe36bea58a0.png' title='1[\emptyset]=\{\emptyset\}' alt='1[\emptyset]=\{\emptyset\}' align='middle' />, <img src='/latexrender/pictures/926ff03720b581dc624f4de2af07bac3.png' title='1[U] = \emptyset' alt='1[U] = \emptyset' align='middle' /> otherwise<br />
<img src='/latexrender/pictures/cfcd208495d565ef66e7dff9f98764da.png' title='0' alt='0' align='middle' />: empty species: <img src='/latexrender/pictures/e864d4557560227f5f4276edab39b730.png' title='0[U] = \emptyset' alt='0[U] = \emptyset' align='middle' />.</p>
<p>In enumerative combinatorics, the power of species resides in the association to each species a number of generating functions:</p>
<p>The generating series of a species F is the exponential formal power series<br />
<img src='/latexrender/pictures/4d16123f57c0b624af2c2edf792d1cd8.png' title='F(x) = \sum_{n=0}^\infty |F[n]|\frac{x^n}{n!}' alt='F(x) = \sum_{n=0}^\infty |F[n]|\frac{x^n}{n!}' align='middle' /><br />
where we use the convention <img src='/latexrender/pictures/aa863c04e18ac592a7560ac3e3a581b1.png' title='[n] = \{1,2,\dots,n\}' alt='[n] = \{1,2,\dots,n\}' align='middle' />, and <img src='/latexrender/pictures/e246dceb6995c5555b1eeb2d505e1708.png' title='F[n] = F[[n]]' alt='F[n] = F[[n]]' align='middle' />.<br />
Thus:<br />
<img src='/latexrender/pictures/3263ff4d9c8a689eae466290bc3052c8.png' title='L(x) = \frac{1}{1-x}' alt='L(x) = \frac{1}{1-x}' align='middle' /><br />
<img src='/latexrender/pictures/3f525bcdaa7612df493b0d76e1364151.png' title='S(x) = \frac{1}{1-x}' alt='S(x) = \frac{1}{1-x}' align='middle' /><br />
<img src='/latexrender/pictures/f77a81e173d3ac51473b37a36e4b323c.png' title='E(x) = e^x' alt='E(x) = e^x' align='middle' /><br />
<img src='/latexrender/pictures/7c5625058ffe6ddb20482fc3079c784a.png' title='e(x) = xe^x' alt='e(x) = xe^x' align='middle' /><br />
<img src='/latexrender/pictures/9063d24c51c77a8c1f84d329a2bed613.png' title='\wp(x) = e^{2x}' alt='\wp(x) = e^{2x}' align='middle' /><br />
<img src='/latexrender/pictures/38d07f869ac97a6ed1deb8574ed0953e.png' title='X(x) = x' alt='X(x) = x' align='middle' /><br />
<img src='/latexrender/pictures/da2ca5efb767fbf1d7d2b4409f3c83f0.png' title='1(x) = 1' alt='1(x) = 1' align='middle' /><br />
<img src='/latexrender/pictures/a78d5784bdd192b7dc4c1b784d719d26.png' title='0(x) = 0' alt='0(x) = 0' align='middle' /></p>
<p>There are a number other in use for combinatorics, but for my purposes, this is the one I&#8217;ll focus on.</p>
<h2>Operations on species</h2>
<p>The real power, though, emerges when we start combining species, and carry over the combinations to actions on the corresponding power series.</p>
<h3>Addition</h3>
<p>The number of ways to form either, say, a graph or a linear order on a set of labels is the sum of the numbers of ways to form either in isolation.</p>
<p>This corresponds cleanly to the coproduct in Set, and we may write F+G for the species<br />
<img src='/latexrender/pictures/d6b9d55d36e1ef2d9b3cce2ce7b09615.png' title='(F+G)[U] = F[U] + G[U]' alt='(F+G)[U] = F[U] + G[U]' align='middle' /><br />
(where the second + is the coproduct — i.e. disjoint union — of sets)</p>
<p>In the power series, we get <img src='/latexrender/pictures/66cb1c86460c5b712cc3ba8b2a0d173b.png' title='(F+G)(x) = F(x) + G(x)' alt='(F+G)(x) = F(x) + G(x)' align='middle' />.</p>
<p>Examples: We may define the species of all non-empty sets <img src='/latexrender/pictures/335d135de25fe2dbf0ccd0f20e0150e1.png' title='E_+' alt='E_+' align='middle' /> by<br />
<img src='/latexrender/pictures/d3315d79ecf2826aaf6b198de80e58d7.png' title='E = 1 + E_+' alt='E = 1 + E_+' align='middle' /><br />
This kind of functional equations is where the theory of species starts to really <em>shine</em>.</p>
<h3>Multiplication</h3>
<p>A tricoloring of a set is a subdivision of the set into three disjoint subsets covering the original set. The number of tricolorings of size n is<br />
<img src='/latexrender/pictures/2cfc95b03d7d4f37d4b7410b9361c214.png' title='\sum_{i+j+k=n} \#\text{sets of size i}\cdot\#\text{sets of size j}\cdot\#\text{sets of size k}' alt='\sum_{i+j+k=n} \#\text{sets of size i}\cdot\#\text{sets of size j}\cdot\#\text{sets of size k}' align='middle' /></p>
<p>A permutation fixes some set of points. The permutation restricted to the non-fixed points is a <em>derangement</em>. Total number of permutations on n elements is<br />
<img src='/latexrender/pictures/475edeb2b536c63ecf62bc9221c06f10.png' title='\sum_{i+j=n}\#\text{sets of size i}\cdot\#\text{derangements of size j}' alt='\sum_{i+j=n}\#\text{sets of size i}\cdot\#\text{derangements of size j}' align='middle' /></p>
<p>In both of these cases, the total generating series is a product of the component series, and we end up defining<br />
<img src='/latexrender/pictures/f05a2036cc62d20e8b6c8a7262f09461.png' title='F\cdot G[U] = \{(f,g): f\in F[U_1], g\in G[U_2], U_1\cap U_2 = \emptyset, U_1\cup U_2 = U\}' alt='F\cdot G[U] = \{(f,g): f\in F[U_1], g\in G[U_2], U_1\cap U_2 = \emptyset, U_1\cup U_2 = U\}' align='middle' /><br />
So <img src='/latexrender/pictures/25b126e16d73bffde96f15011ec62ba6.png' title='F\cdot G[U] = \sum_{U_1,U_2\text{ decompose }U} F[U_1]\times G[U_2]' alt='F\cdot G[U] = \sum_{U_1,U_2\text{ decompose }U} F[U_1]\times G[U_2]' align='middle' />.</p>
<p>Thus, tricolorings are <img src='/latexrender/pictures/77d013a0d46948384f8cd9b41535b43c.png' title='E\cdot E\cdot E' alt='E\cdot E\cdot E' align='middle' /> and permutations are <img src='/latexrender/pictures/65637937dfc1372e746af745b30dabe8.png' title='S = E\cdot Der' alt='S = E\cdot Der' align='middle' />, where the set is that of fixed points, and the derangement captures the actual action of the permutation.</p>
<h3>Composition</h3>
<p>Endofunctions of sets decompose in their actions on the points as cycles or directed trees leading in to these cycles.</p>
<p>Since a collection of disjoint cycles corresponds to a permutation, we can consider such endofunctions to be permutations decorated with rooted trees attached to points of the permutations; or even permutations of rooted trees.</p>
<p>To form such a structure on a set U, we&#8217;d first partition U into subsets, put the structure of a rooted tree on each subset, and then the structure of a permutation on the set of these subsets.</p>
<p>Thus, the number of such structures on n elements is<br />
<img src='/latexrender/pictures/335e2e52de4ab24686357d7fff2b2b15.png' title='\sum_{r\leq n}\sum_{\sum_{k=1}^n i_k = n} \#\tex{permutations on [r]}\cdot\prod_{k=1}^r\#\text{rooted trees on [i_k]}' alt='\sum_{r\leq n}\sum_{\sum_{k=1}^n i_k = n} \#\tex{permutations on [r]}\cdot\prod_{k=1}^r\#\text{rooted trees on [i_k]}' align='middle' /></p>
<p>This corresponds to the power series <img src='/latexrender/pictures/e0411f63150f22a2f99be1510b5910f0.png' title='S(A(x))' alt='S(A(x))' align='middle' />, and we write, in general, <img src='/latexrender/pictures/31029fa092055be1deacf9e244f20333.png' title='F\circ G[U]' alt='F\circ G[U]' align='middle' /> for the species of F-structures of G-structures on subsets.</p>
<p><strong>Examples</strong>:<br />
A = X·E(A)<br />
L = 1 + X·L<br />
B = 1 + X·B·B</p>
<h3>Pointing</h3>
<p>Picking out a single point in a structure on n points can be done in precisely n ways.</p>
<p>Thus the corresponding generating function will be<br />
<img src='/latexrender/pictures/149891bfc400f34cdb0f99d080acc7ef.png' title='\sum n\cdot f_n\cdot\frac{x^n}{n!}' alt='\sum n\cdot f_n\cdot\frac{x^n}{n!}' align='middle' /><br />
for f-structures with a single label distinguished.</p>
<p>Since we&#8217;re working with exponential power series, we may notice that<br />
<img src='/latexrender/pictures/c561d318629404536b769f934f360554.png' title='\frac{\partial}{\partial x} \sum f_n\frac{x^n}{n!} = \sum f_{n+1}\frac{x^n}{n!}' alt='\frac{\partial}{\partial x} \sum f_n\frac{x^n}{n!} = \sum f_{n+1}\frac{x^n}{n!}' align='middle' /><br />
and thus that derivatives are shifts.<br />
Furthermore, <img src='/latexrender/pictures/be3a9d4b57954e8b767df9234c2529b4.png' title='x\cdot\sum f_n\frac{x^n}{n!} = \sum f_n\frac{x^{n+1}}{n!} = \sum f_{n-1}n\cdot{x^n}{n!}' alt='x\cdot\sum f_n\frac{x^n}{n!} = \sum f_n\frac{x^{n+1}}{n!} = \sum f_{n-1}n\cdot{x^n}{n!}' align='middle' /><br />
so that the generating function for F-structures with a single distinguished are<br />
<img src='/latexrender/pictures/594ef9019767eed975d7e51efbddf20a.png' title='F^\bullet(x) = x\cdot\frac{\partial}{\partial x}F(x)' alt='F^\bullet(x) = x\cdot\frac{\partial}{\partial x}F(x)' align='middle' /></p>
<p>In species, this process is called pointing.</p>
<p>In functional programming, Conor McBride related this construction to Huet&#8217;s Zipper datatypes.</p>
<p>As it turns out, many of the constructions for species make eminent sense outside the category <img src='/latexrender/pictures/e19c41413e1b974679b02bd79d5d494c.png' title='\mathbb B' alt='\mathbb B' align='middle' />. In fact, species in Hask are known to programming language researchers as <em>container datatypes</em> and the whole calculus translates relatively cleanly.</p>
<p>Functional equations translate to the standard new data type definitions in Haskell.</p>
<p><strong>Examples</strong>:<br />
L = 1 + X·L<br />
<code><br />
data List a = Nil | Cons a (List a)<br />
</code></p>
<p>B = 1 + X·B·B<br />
<code><br />
data BinaryTree a = Leaf | Node (BinaryTree a) a (BinaryTree a)<br />
</code></p>
<p>A = X·E(A)<br />
<code><br />
data RootedTree a = Node a (Set (RootedTree a))<br />
</code><br />
usually, we simulate the Set here by a List. If we need for our rooted trees to be planar, we can in fact impose a Linear Order structure instead, and get something like<br />
Ap = X·L(Ap)</p>
<p>The species interpretation of <img src='/latexrender/pictures/4d6c379f66675645b3ffe28a15306857.png' title='\frac{\partial}{\partial x}' alt='\frac{\partial}{\partial x}' align='middle' /> corresponding to leaving a hole in the structure carries over cleanly, so that <img src='/latexrender/pictures/27f5948c4a69349055a73e917f5f5b6e.png' title='\frac{\partial}{\partial x}T' alt='\frac{\partial}{\partial x}T' align='middle' /> is the type of T-with-a-hole.</p>
<h2>Two derivatives of lists</h2>
<p>We can deal with  <img src='/latexrender/pictures/12b5d0430c70edf45c18de84a4609c6b.png' title='\frac{\partial}{\partial x}L' alt='\frac{\partial}{\partial x}L' align='middle' /> in two different ways:</p>
<p>1.<br />
DL = D(1+X·L) = D1 + D(X·L) = 0 + DX·L+X·DL<br />
and thus<br />
DL-X·DL = 1·L<br />
so (1-X)·DL = L<br />
and thus<br />
DL = L·1/(1-X)</p>
<p>Now, from L=1+X·L follows by a similar cavalier use of subtraction and division — which, by the way, in species theory is captured by the idea of a <em>virtual species</em>, and dealt with relatively cleanly — that<br />
L = 1+X·L<br />
so<br />
L-X·L = 1<br />
and thus<br />
(1-X)·L = 1<br />
so<br />
L = 1/(1-X)</p>
<p>Thus, we can conclude that<br />
DL = L·1/(1-X) = L·L<br />
and thus, a list with a hole is a pair of lists: the stuff before the hole and the stuff after the hole.</p>
<p>2.<br />
We could, instead of using implicit differentiation, as in 1, attack the derivation we had of<br />
L = 1/(1-X) = 1+X+X·X+X·X·X+…</p>
<p>Indeed,<br />
DL = D(1/(1-X)) = D(1+X+X·X+…) = 0+1+2X+3X·X+…<br />
which we can observe factors as<br />
= (1+X+X·X+X·X·X+…)·(1+X+X·X+X·X·X+…) = L·L</p>
<p>Or we can just use the division rule<br />
DL = D(1/(1-X)) = D(1/u)·D(1-X) = -1/(u·u)·(-1) = 1/[(1-X)·(1-X)] = L·L</p>
<h2>Gröbner bases for operads</h2>
<p>All of this becomes relevant to the implementation of Buchberger&#8217;s algorithm on shuffle operads (see Dotsenko—Khoroshkin and Dotsenko—Vejdemo-Johansson)  in the step where the S-polynomials (and thereby also the reductions) are defined. With a common multiple defined, we need some way to extend the modifications that take the initial term to the common multiple to the rest of that term.</p>
<p>For this, it turns out, that the derivative of the tree datatype used provides theoretical guarantees that only partially filled in trees of the right size, with holes the right size, can be introduced; and also provides an easy and relatively efficient algorithm for contructing the hole-y trees and later filling in the holes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikael.johanssons.org/archive/2010/12/species-derivatives-of-types-and-grobner-bases-for-operads/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Homological Inclusion-Exclusion and the Mayer-Vietoris sequence</title>
		<link>http://blog.mikael.johanssons.org/archive/2009/01/homological-inclusion-exclusion-and-the-mayer-vietoris-sequence/</link>
		<comments>http://blog.mikael.johanssons.org/archive/2009/01/homological-inclusion-exclusion-and-the-mayer-vietoris-sequence/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 21:44:11 +0000</pubDate>
		<dc:creator>Michi</dc:creator>
				<category><![CDATA[Algebra]]></category>
		<category><![CDATA[Combinatorics]]></category>
		<category><![CDATA[Homology and Homotopy]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Topology]]></category>

		<guid isPermaLink="false">http://blog.mikael.johanssons.org/?p=190</guid>
		<description><![CDATA[This blogpost is inspired to a large part by comments made by Rob Ghrist, in connection to his talks on using the Euler characteristic integration theory to count targets detected by sensor networks. He pointed out that the underlying principle inducing the rule goes under many names, among those \emph{Inclusion-Exclusion}, favoured among computer scientists (and [...]]]></description>
			<content:encoded><![CDATA[<p>This blogpost is inspired to a large part by comments made by Rob Ghrist, in connection to his talks on using the Euler characteristic integration theory to count targets detected by sensor networks.</p>
<p>He pointed out that the underlying principle inducing the rule<br />
<img src='/latexrender/pictures/e64c58c3ef4aebdfc73fb2fd219b9807.png' title='\chi(A\cup B) = \chi(A)+\chi(B)-\chi(A\cap B)' alt='\chi(A\cup B) = \chi(A)+\chi(B)-\chi(A\cap B)' align='middle' /><br />
goes under many names, among those \emph{Inclusion-Exclusion}, favoured among computer scientists (and combinatoricists). He also pointed out that the origin of this principle is the Mayer-Vietoris long exact sequence<br />
<img src='/latexrender/pictures/0bb06b6958e28c2e547fffda1436bfa5.png' title='\cdots\to H_{n}(A\cap B)\to H_{n}(A)\oplus H_{n}(B)\to H_{n}(A\cup b)\to\cdots' alt='\cdots\to H_{n}(A\cap B)\to H_{n}(A)\oplus H_{n}(B)\to H_{n}(A\cup b)\to\cdots' align='middle' /></p>
<p>In this blog post, I&#8217;d like to give more meat to this assertion as well as point out how the general principle of Inclusion-Exclusion for finite sets follows immediately from Mayer-Vietoris. </p>
<h2>Inclusion-Exclusion, and the passage from two sets to many</h2>
<p>The basic principle of Inclusion-Exclusion says that if we have two sets, <img src='/latexrender/pictures/7fc56270e7a70fa81a5935b72eacbe29.png' title='A' alt='A' align='middle' /> and <img src='/latexrender/pictures/9d5ed678fe57bcca610140957afab571.png' title='B' alt='B' align='middle' />, then the following relationship of cardinalities holds:<br />
<img src='/latexrender/pictures/af5188fb6546392a153da31471c666d8.png' title='|A\cup B| = |A| + |B| &amp;#8211; |A\cap B' alt='|A\cup B| = |A| + |B| &amp;#8211; |A\cap B' align='middle' /></p>
<p>A first proof would be performed by referring to an appropriate Venn<br />
diagram, or by pointing out that if we try to count all the elements<br />
of <img src='/latexrender/pictures/fee055b62470bc8713ed312fb67bbc55.png' title='A\cup B' alt='A\cup B' align='middle' /> by adding the counts for <img src='/latexrender/pictures/7fc56270e7a70fa81a5935b72eacbe29.png' title='A' alt='A' align='middle' /> and <img src='/latexrender/pictures/9d5ed678fe57bcca610140957afab571.png' title='B' alt='B' align='middle' />, then we&#8217;ve overcounted the elements of <img src='/latexrender/pictures/fbd0dfa8f015d48acfe4570aa6babc6a.png' title='A\cap B' alt='A\cap B' align='middle' />, and thus need to subtract these.</p>
<p>Now, this is good and convincing for the situation where we have just two sets, but what if we had a whole family? What if we had <img src='/latexrender/pictures/a0cec6d1fbf031bcb86832e4624178bc.png' title='A_{1},\dots,A_{n}' alt='A_{1},\dots,A_{n}' align='middle' />? Well, our old friend the complete induction rides to our rescue. Suppose we had already proven that for <img src='/latexrender/pictures/a438673491daae8148eae77373b6a467.png' title='n-1' alt='n-1' align='middle' /> sets <img src='/latexrender/pictures/e8aaf87d9a5c35b14cfbc370d3fd7b21.png' title='A_{i}' alt='A_{i}' align='middle' />, the following formula holds:<br />
<img src='/latexrender/pictures/557f8c0625c4d5558249ea779ed211ae.png' title='\left|\bigcup_{i\in\{1,\dots,n-1\}} A_{i}\right| =&#10;  \sum_{k=1}^{n-1} (-1)^{1+k}\sum_{S\subseteq\{1,\dots,n-1\}, |S|=k}\left|\bigcap_{s\in S} A_{s}\right|' alt='\left|\bigcup_{i\in\{1,\dots,n-1\}} A_{i}\right| =&#10;  \sum_{k=1}^{n-1} (-1)^{1+k}\sum_{S\subseteq\{1,\dots,n-1\}, |S|=k}\left|\bigcap_{s\in S} A_{s}\right|' align='middle' /></p>
<p>If you think this formula is imposing, let me show you the first few ways it works out, so that you can get a feeling for it:</p>
<p><img src='/latexrender/pictures/3b8f5222fb5946404ebade7ee33c177a.png' title='|A_{1}\cup A_{2}| = |A_{1}| + |A_{2}| &amp;#8211; |A_{1}\cap A_{2}' alt='|A_{1}\cup A_{2}| = |A_{1}| + |A_{2}| &amp;#8211; |A_{1}\cap A_{2}' align='middle' /></p>
<p><img src='/latexrender/pictures/1b1dbf1d326d1f9771002c4d4463aaf1.png' title='&#10;\begin{multline*}&#10;|A_{1}\cup A_{2}\cup A_{3}| = \\&#10;|A_{1}|+|A_{2}|+|A_{3}|-|A_{1}\cap A_{2}|-|A_{1}\cap A_{3}|-|A_{2}\cap A_{3}|+\\&#10;|A_{1}\cap A_{2}\cap A_{3}|&#10;\end{multline*}' alt='&#10;\begin{multline*}&#10;|A_{1}\cup A_{2}\cup A_{3}| = \\&#10;|A_{1}|+|A_{2}|+|A_{3}|-|A_{1}\cap A_{2}|-|A_{1}\cap A_{3}|-|A_{2}\cap A_{3}|+\\&#10;|A_{1}\cap A_{2}\cap A_{3}|&#10;\end{multline*}' align='middle' /></p>
<p>Here it starts becoming apparent why it is called the Inclusion-Exclusion formula: we include all elements from all sets, but then we&#8217;ve gotten too many elements from the pairwise intersections, so we exclude those, but then we&#8217;ve gotten too few elements from the triple intersections, so we re-include those, but then we&#8217;ve gotten too few elements from the quadruple intersections &#8211; and on it goes.</p>
<p>If our assumption holds, we can consider what the appropriate size of the union of <img src='/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png' title='n' alt='n' align='middle' /> different sets should be. We can pick one set, say <img src='/latexrender/pictures/5614f2f428505eeff293fcebfdc6c8c3.png' title='A_{n}' alt='A_{n}' align='middle' />, and treat it separately. Then, certainly, the union of the rest has size given by the formula, by our induction assumption. So, consider what happens when we add in the elements in <img src='/latexrender/pictures/5614f2f428505eeff293fcebfdc6c8c3.png' title='A_{n}' alt='A_{n}' align='middle' />. We then overcount all elements in any of the intersections <img src='/latexrender/pictures/011b208bf375db0da47a055ec1d3a69e.png' title='A_{i}\cap A_{n}' alt='A_{i}\cap A_{n}' align='middle' />, so we have to subtract those. But we then have undercounted all elements in any intersection on the form <img src='/latexrender/pictures/37654875ccd47b0f8ea7063ab5a73eec.png' title='A_{i}\cap A_{j}\cap A_{n}' alt='A_{i}\cap A_{j}\cap A_{n}' align='middle' />, so we need to add those back in. And so we go on, and for each intersection that occurred in the formula for <img src='/latexrender/pictures/a438673491daae8148eae77373b6a467.png' title='n-1' alt='n-1' align='middle' /> sets, we find ourselves forced to add one new term, of the opposite sign, that counts the intersection of that old term with <img src='/latexrender/pictures/5614f2f428505eeff293fcebfdc6c8c3.png' title='A_{n}' alt='A_{n}' align='middle' />.</p>
<p>Thus, the new formula takes on the exact guise of the general formula we wanted to prove, since the terms involving <img src='/latexrender/pictures/5614f2f428505eeff293fcebfdc6c8c3.png' title='A_{n}' alt='A_{n}' align='middle' /> are precisely indexed, in that formula, by the terms excluding <img src='/latexrender/pictures/5614f2f428505eeff293fcebfdc6c8c3.png' title='A_{n}' alt='A_{n}' align='middle' />, but with opposite signs.</p>
<h2>Encoding set sizes homologically</h2>
<p>So, now that we know that pairwise Inclusion-Exclusion implies the general Inclusion-Exclusion, let us take a look on how we can express Inclusion-Exclusion with homology. We note first of all that <img src='/latexrender/pictures/012630d87ec5c11ab3069799ff9fe922.png' title='H_{0}(X)' alt='H_{0}(X)' align='middle' /> counts the number of path-connected components of a space <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' />. This follows easily from a few properties. First, a basis for the <img src='/latexrender/pictures/cfcd208495d565ef66e7dff9f98764da.png' title='0' alt='0' align='middle' />-chains of <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' /> is given by the points in <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' />. Second, two <img src='/latexrender/pictures/cfcd208495d565ef66e7dff9f98764da.png' title='0' alt='0' align='middle' />-chains are homologous precisely if there is a <img src='/latexrender/pictures/c4ca4238a0b923820dcc509a6f75849b.png' title='1' alt='1' align='middle' />-chain whose boundary is the difference between those <img src='/latexrender/pictures/cfcd208495d565ef66e7dff9f98764da.png' title='0' alt='0' align='middle' />-chains. The boundary of a path is the difference of its endpoints, so we end up with two basis elements being homologous precisely if there is a path connecting them.</p>
<p>Thus, two <img src='/latexrender/pictures/cfcd208495d565ef66e7dff9f98764da.png' title='0' alt='0' align='middle' />-chain elements are homologous precisely if they&#8217;re in the same path-component of <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' />. So, the homology classes of <img src='/latexrender/pictures/cfcd208495d565ef66e7dff9f98764da.png' title='0' alt='0' align='middle' />-chains are precisely the path-connected components.</p>
<p>So, the <img src='/latexrender/pictures/cfcd208495d565ef66e7dff9f98764da.png' title='0' alt='0' align='middle' />-degree homology classes count path-components. How do we use that? Well &#8230; if we consider a finite set <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' /> with the discrete topology &#8211; i.e. open sets are single points and any unions of single point sets, then a path is a continuous function <img src='/latexrender/pictures/e48a9c10cd61b98b008603460fe919a3.png' title='[0,1]\to X' alt='[0,1]\to X' align='middle' />, i.e. one where the preimage of any open set is open. Thus, the preimage of any point is an open set. Suppose a path contains more than one point. Then we can partition the interval <img src='/latexrender/pictures/ccfcd347d0bf65dc77afe01a3306a96b.png' title='[0,1]' alt='[0,1]' align='middle' /> into two disjoint open sets, by taking one set to be the preimage of one of the points, and the other set to be the preimage of everything else. However, the interval <img src='/latexrender/pictures/ccfcd347d0bf65dc77afe01a3306a96b.png' title='[0,1]' alt='[0,1]' align='middle' /> is connected, which means that if there are two such open sets, one of them has to be empty.</p>
<p>Thus, the path-connected components of a discrete topological space are the points themselves. So if <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' /> is discrete, then <img src='/latexrender/pictures/a7c0ab18fa068ec66e23f17b5706dfa5.png' title='H_{0}(X) = |X|' alt='H_{0}(X) = |X|' align='middle' />.</p>
<h2>Long exact sequences in homology and the Mayer-Vietoris sequence</h2>
<p>It is a theorem from homological algebra that if we have a short exact sequence of chain complexes<br />
<img src='/latexrender/pictures/fcc15bb34b9d447ec682f6bfddbe16c2.png' title='0\to A_{*}\to B_{*}\to C_{*}\to 0' alt='0\to A_{*}\to B_{*}\to C_{*}\to 0' align='middle' /><br />
then there is a long exact sequence in homology given by<br />
<img src='/latexrender/pictures/0566ac2b782b671659e7ac70ee4db10c.png' title='\cdots\to H_{n}(A_{*})\to H_{n}(B_{*})\to H_{n}(C_{*})\to H_{n-1}(A_{*})\to\cdots' alt='\cdots\to H_{n}(A_{*})\to H_{n}(B_{*})\to H_{n}(C_{*})\to H_{n-1}(A_{*})\to\cdots' align='middle' /></p>
<p>Almost all interesting long exact sequences in topology are special cases of this particular fact. We will derive one interesting sequence: the Mayer-Vietoris sequence from this.</p>
<p>Take a topological space <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' />. The singular chain complex <img src='/latexrender/pictures/c0c4fa721f58794a2efb9162c3bf7884.png' title='C_{*}(X)' alt='C_{*}(X)' align='middle' /> forms a chain complex with <img src='/latexrender/pictures/0d8f63cd9223629945a7cb4b65d3e9fe.png' title='C_{n}(X)' alt='C_{n}(X)' align='middle' /> the free abelian group of <img src='/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png' title='n' alt='n' align='middle' />-chains and the differential given by the usual formula.</p>
<p>Suppose we have two spaces: <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' /> and <img src='/latexrender/pictures/57cec4137b614c87cb4e24a3d003a3e0.png' title='Y' alt='Y' align='middle' />. Then any <img src='/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png' title='n' alt='n' align='middle' />-chain on <img src='/latexrender/pictures/f810846cb95904b01a9821200c889064.png' title='X\cap Y' alt='X\cap Y' align='middle' /> is an <img src='/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png' title='n' alt='n' align='middle' />-chain on <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' /> and an <img src='/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png' title='n' alt='n' align='middle' />-chain on <img src='/latexrender/pictures/57cec4137b614c87cb4e24a3d003a3e0.png' title='Y' alt='Y' align='middle' />. So we get an inclusion map <img src='/latexrender/pictures/ce63e1eea798844c993ea0cbefcd9632.png' title='C_{n}(X\cap Y)\to C_{n}(X)\oplus C_{n}(Y)' alt='C_{n}(X\cap Y)\to C_{n}(X)\oplus C_{n}(Y)' align='middle' /> by <img src='/latexrender/pictures/5ddc1ea1d0d7dcb22b10ecc1490dd4e4.png' title='\sigma\mapsto(\sigma,-\sigma)' alt='\sigma\mapsto(\sigma,-\sigma)' align='middle' />. We choose this sign instead of the image <img src='/latexrender/pictures/20aa3868aa5cbc38f70798c4b2361b2e.png' title='(\sigma,\sigma)' alt='(\sigma,\sigma)' align='middle' /> to make the next step cleaner. It is an injection because <img src='/latexrender/pictures/849f9df2d516521b9163ae28c1fbc16a.png' title='C_{n}' alt='C_{n}' align='middle' /> is a free abelian group, and the injections<br />
<img src='/latexrender/pictures/4e8b60820645ced2a21f47c9abf83d63.png' title='X\leftarrow X\cap Y\rightarrow Y' alt='X\leftarrow X\cap Y\rightarrow Y' align='middle' /> are set maps on bases for the corresponding chain groups.</p>
<p>Compatibility of this map with the differential is almost as easy. If we first apply the differential and then map into the direct sum, we get the map <img src='/latexrender/pictures/4b62753180220831f7158c266eaaafbe.png' title='\sigma\mapsto d\sigma\mapsto(d\sigma,-d\sigma)' alt='\sigma\mapsto d\sigma\mapsto(d\sigma,-d\sigma)' align='middle' />. If we instead first map into the direct sum, and then apply the differentials, we get the map <img src='/latexrender/pictures/7dd5af33034b42129f86640e0cb4312e.png' title='\sigma\mapsto(\sigma,-\sigma)\mapsto(d\sigma,-d\sigma)' alt='\sigma\mapsto(\sigma,-\sigma)\mapsto(d\sigma,-d\sigma)' align='middle' />. These are equal, and thus the map we&#8217;ve constructed is a chain map.</p>
<p>So, <img src='/latexrender/pictures/6e4fef0edf674f59d4927e3aaf60c6af.png' title='C_{*}(X\cap Y)\to C_{*}(X)\oplus C_{*}(Y)' alt='C_{*}(X\cap Y)\to C_{*}(X)\oplus C_{*}(Y)' align='middle' /> is an injective map of chain complexes.</p>
<p>If we now have a pair of chains, we can construct a chain on the union of the two spaces. An <img src='/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png' title='n' alt='n' align='middle' />-chain on <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' /> is automatically an <img src='/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png' title='n' alt='n' align='middle' />-chain on <img src='/latexrender/pictures/74da4429354a80f686996145d3a74c2c.png' title='X\cup Y' alt='X\cup Y' align='middle' />. Similarly, an <img src='/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png' title='n' alt='n' align='middle' />-chain on <img src='/latexrender/pictures/57cec4137b614c87cb4e24a3d003a3e0.png' title='Y' alt='Y' align='middle' /> is automatically  an <img src='/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png' title='n' alt='n' align='middle' />-chain on <img src='/latexrender/pictures/74da4429354a80f686996145d3a74c2c.png' title='X\cup Y' alt='X\cup Y' align='middle' />. So both <img src='/latexrender/pictures/0d8f63cd9223629945a7cb4b65d3e9fe.png' title='C_{n}(X)' alt='C_{n}(X)' align='middle' /> and <img src='/latexrender/pictures/701020ddc65f2588d3267a2ecd75a876.png' title='C_{n}(Y)' alt='C_{n}(Y)' align='middle' /> inject into <img src='/latexrender/pictures/ce96f93d04d882421dfb0753c604d4a2.png' title='C_{n}(X\cup Y)' alt='C_{n}(X\cup Y)' align='middle' /> by the same kind of argument as with the injection <img src='/latexrender/pictures/f747507d08b3a5a472c04429a44f7fd6.png' title='C_{n}(X\cap Y)\to C_{n}(X)' alt='C_{n}(X\cap Y)\to C_{n}(X)' align='middle' />.</p>
<p>The injections we get this way can be put together to a map <img src='/latexrender/pictures/c56630944416e05c8a73877c605ff177.png' title='C_{n}(X)\oplus C_{n}(Y)\to C_{n}(X\cup Y)' alt='C_{n}(X)\oplus C_{n}(Y)\to C_{n}(X\cup Y)' align='middle' /> by, for instance, <img src='/latexrender/pictures/637d0425ff4ca9ff1d371c5c1a186294.png' title='(\sigma,\tau)\mapsto\sigma+\tau' alt='(\sigma,\tau)\mapsto\sigma+\tau' align='middle' />. I am going to fudge over the issue of whether the <img src='/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png' title='n' alt='n' align='middle' />-chains on <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' /> and <img src='/latexrender/pictures/57cec4137b614c87cb4e24a3d003a3e0.png' title='Y' alt='Y' align='middle' /> form a generating set for the <img src='/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png' title='n' alt='n' align='middle' />-chains on <img src='/latexrender/pictures/74da4429354a80f686996145d3a74c2c.png' title='X\cup Y' alt='X\cup Y' align='middle' />, and just take it on faith that this works. The details are not particularly difficult &#8211; they are just obnoxiously long and annoying.</p>
<p>Now, given that we believe we can get a generating set by taking the union of the bases for the <img src='/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png' title='n' alt='n' align='middle' />-chains on <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' /> and <img src='/latexrender/pictures/57cec4137b614c87cb4e24a3d003a3e0.png' title='Y' alt='Y' align='middle' />, then this means that the map I gave above is surjective. Indeed, a basis element <img src='/latexrender/pictures/68b431d27bfa431ca29baf113c7a35a0.png' title='\sigma\in C_{n}(X)' alt='\sigma\in C_{n}(X)' align='middle' /> is hit by the element <img src='/latexrender/pictures/2d4c37021a6e194a3f4640f578a7c5aa.png' title='(\sigma,0)' alt='(\sigma,0)' align='middle' />, and a basis element <img src='/latexrender/pictures/c5dd47b8c1e8776a2e08593b5bc3b41e.png' title='\tau\in C_{n}(Y)' alt='\tau\in C_{n}(Y)' align='middle' /> is hit by the element <img src='/latexrender/pictures/e084be986d67b55fdef20c2d547f0be7.png' title='(0,\tau)' alt='(0,\tau)' align='middle' />.</p>
<p>This argument proves exactness at the first and last term of the short exact sequence<br />
<img src='/latexrender/pictures/50c77078f0db9d158a2a9da90ab774fb.png' title='0\to C_{*}(X\cap Y)\to C_{*}(X)\oplus C_{*}(Y)\to C_{n}(X\cup Y)\to 0' alt='0\to C_{*}(X\cap Y)\to C_{*}(X)\oplus C_{*}(Y)\to C_{n}(X\cup Y)\to 0' align='middle' /><br />
and it remains to prove exactness at the middle term. So we need to prove that<br />
<img src='/latexrender/pictures/c59f9a5e9e485d58b9f79904b0c4756b.png' title='\mathrm{ker}((\sigma,\tau)\mapsto\sigma+\tau) = \mathrm{im}(\sigma\mapsto(\sigma,-\sigma))' alt='\mathrm{ker}((\sigma,\tau)\mapsto\sigma+\tau) = \mathrm{im}(\sigma\mapsto(\sigma,-\sigma))' align='middle' /></p>
<p>Now, since <img src='/latexrender/pictures/b7831e651048c5a529162d5eb1886e66.png' title='\sigma+(-\sigma)=0' alt='\sigma+(-\sigma)=0' align='middle' />, the inclusion of the image in the kernel is obvious. So, suppose now that <img src='/latexrender/pictures/68b431d27bfa431ca29baf113c7a35a0.png' title='\sigma\in C_{n}(X)' alt='\sigma\in C_{n}(X)' align='middle' />, <img src='/latexrender/pictures/c5dd47b8c1e8776a2e08593b5bc3b41e.png' title='\tau\in C_{n}(Y)' alt='\tau\in C_{n}(Y)' align='middle' /> and <img src='/latexrender/pictures/fb6e49de619884e88aa5a9a6a711603e.png' title='\sigma+\tau=0' alt='\sigma+\tau=0' align='middle' />. Then, in <img src='/latexrender/pictures/ce96f93d04d882421dfb0753c604d4a2.png' title='C_{n}(X\cup Y)' alt='C_{n}(X\cup Y)' align='middle' />, we know that <img src='/latexrender/pictures/db8f83aedba65cc0ad5fede28348e2a9.png' title='\sigma=-\tau' alt='\sigma=-\tau' align='middle' />. But then, <img src='/latexrender/pictures/37c6598aec87cd1258aec820908e589a.png' title='\tau\in C_{n}(X)' alt='\tau\in C_{n}(X)' align='middle' /> since <img src='/latexrender/pictures/68b431d27bfa431ca29baf113c7a35a0.png' title='\sigma\in C_{n}(X)' alt='\sigma\in C_{n}(X)' align='middle' /> and similarly <img src='/latexrender/pictures/64560422992fae5541193215c27c308c.png' title='\sigma\in C_{n}&#10;(Y)' alt='\sigma\in C_{n}&#10;(Y)' align='middle' /> since <img src='/latexrender/pictures/c5dd47b8c1e8776a2e08593b5bc3b41e.png' title='\tau\in C_{n}(Y)' alt='\tau\in C_{n}(Y)' align='middle' />. So <img src='/latexrender/pictures/87dce9fd1530b806d90388cfe19e8404.png' title='\sigma,\tau\in C_{n}(X\cap Y)' alt='\sigma,\tau\in C_{n}(X\cap Y)' align='middle' /> and <img src='/latexrender/pictures/e31793bc1e2403afa614344619a9a66c.png' title='\tau=-\sigma' alt='\tau=-\sigma' align='middle' />. But then this kernel element really is in the image of the inclusion we gave.</p>
<p>So this is a short exact sequence of chain complexes. It follows from the theorem of long exact sequences in homology that there is an associated long exact sequence, called the Mayer-Vietoris sequence:<br />
<img src='/latexrender/pictures/8534990940af867f6b79cf0dfdae7bb4.png' title='\cdots\to H_{n}(X\cap Y)\to H_{n}(X)\oplus H_{n}(Y)\to H_{n}(X\cup Y)\to H_{n-1}(X\cap Y)\to\cdots' alt='\cdots\to H_{n}(X\cap Y)\to H_{n}(X)\oplus H_{n}(Y)\to H_{n}(X\cup Y)\to H_{n-1}(X\cap Y)\to\cdots' align='middle' /></p>
<h2>Putting it all together</h2>
<p>Suppose <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' /> is a discrete topological space. Then any continuous map from a <img src='/latexrender/pictures/8ce4b16b22b58894aa86c421e8759df3.png' title='k' alt='k' align='middle' />-simplex <img src='/latexrender/pictures/d2aff78b805f992d84d56d587de5c32c.png' title='\Delta^{k}' alt='\Delta^{k}' align='middle' /> to <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' /> is by necessity constant at one point. So all the singular simplices in <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' /> are constant maps, and thus a basis for any <img src='/latexrender/pictures/7b8b965ad4bca0e41ab51de7b31363a1.png' title='n' alt='n' align='middle' />-chain group is given by just the points in <img src='/latexrender/pictures/02129bb861061d1a052c592e2dc6b383.png' title='X' alt='X' align='middle' /> as such. The differential acts on such a constant map by sending it to an alternating sum of identical maps the cardinality of which is one more than the dimension of the simplex. So the differential vanishes at every other point in the chain complex, and is an isomorphism on the rest. But then we have exactly two possibilities for a homology computation:</p>
<p>Case 1: <img src='/latexrender/pictures/fbcc438086d71e0761c752136d0962ec.png' title='C_{n}(X)\overset1\to C_{n-1}(X)\overset0\to C_{n-2}(X)' alt='C_{n}(X)\overset1\to C_{n-1}(X)\overset0\to C_{n-2}(X)' align='middle' /></p>
<p>Here, the kernel is the entire chain group. But so is the image. Thus the homology group is trivial.</p>
<p>Case 2: <img src='/latexrender/pictures/e1d445aa168cf1ab5ae39120ad89971a.png' title='C_{n}(X)\overset0\to C_{n-1}(X)\overset1\to C_{n-2}(X)' alt='C_{n}(X)\overset0\to C_{n-1}(X)\overset1\to C_{n-2}(X)' align='middle' /></p>
<p>Here, the kernel is trivial, but then again, so is the image. Thus, again, so is the homology group.</p>
<p>The only part not really covered by this is the homology group <img src='/latexrender/pictures/012630d87ec5c11ab3069799ff9fe922.png' title='H_{0}(X)' alt='H_{0}(X)' align='middle' />, since this is computed from a diagram on the shape <img src='/latexrender/pictures/720f1bfea9e6828c429c4a06020527df.png' title='C_{1}(X)\overset0\to C_{0}(X)\to0' alt='C_{1}(X)\overset0\to C_{0}(X)\to0' align='middle' />. So <img src='/latexrender/pictures/012630d87ec5c11ab3069799ff9fe922.png' title='H_{0}(X)' alt='H_{0}(X)' align='middle' /> behaves like we showed above, and is the only non-trivial homology group of the discrete space.</p>
<p>But then, the only bit that remains non-zero in the Mayer-Vietoris sequence is<br />
<img src='/latexrender/pictures/1cdccbaacf3c4f8d8c1370f99a757efe.png' title='0\to H_{0}(X\cap Y)\to H_{0}(X)\oplus H_{0}(Y)\to H_{0}(X\cup Y)\to 0' alt='0\to H_{0}(X\cap Y)\to H_{0}(X)\oplus H_{0}(Y)\to H_{0}(X\cup Y)\to 0' align='middle' /></p>
<p>If we have a short exact sequence of free abelian groups, then this relates the number of basis elements in each of the groups with the structure of the sequence. Let our short exact sequence be given by <img src='/latexrender/pictures/f00d8510a6c2e9b80cb8601acb59ccbe.png' title='0\to A\to B\to C\to 0' alt='0\to A\to B\to C\to 0' align='middle' />. then, by injectivity of the map <img src='/latexrender/pictures/bd2d818ae16cdb1206ab9f554b45bad8.png' title='A\to B' alt='A\to B' align='middle' />, the cardinality of a basis of the image in <img src='/latexrender/pictures/9d5ed678fe57bcca610140957afab571.png' title='B' alt='B' align='middle' /> is equal to the cardinality of a basis for <img src='/latexrender/pictures/7fc56270e7a70fa81a5935b72eacbe29.png' title='A' alt='A' align='middle' />. By surjectivity of the map <img src='/latexrender/pictures/d6499025e76dbf1f6965fdbc360eea2c.png' title='B\to C' alt='B\to C' align='middle' />, and by Noether&#8217;s theorem, the cardinality of a basis of <img src='/latexrender/pictures/9d5ed678fe57bcca610140957afab571.png' title='B' alt='B' align='middle' /> is equal to the cardinality of a basis of the kernel of this map, plus the cardinality of a basis of <img src='/latexrender/pictures/0d61f8370cad1d412f80b84d143e1257.png' title='C' alt='C' align='middle' />. By exactness in the middle, this kernel basis is equal to the image basis from A. So, we have, writing <img src='/latexrender/pictures/0193d4d3f614be7ffb688f4a5e71a62d.png' title='|G|' alt='|G|' align='middle' /> for the cardinality of a basis of the free abelian group <img src='/latexrender/pictures/dfcf28d0734569a6a693bc8194de62bf.png' title='G' alt='G' align='middle' />, that <img src='/latexrender/pictures/e3cc75795a7c0b185ea96ca504c967ec.png' title='|B| = |A|+|C|' alt='|B| = |A|+|C|' align='middle' />. Thus, <img src='/latexrender/pictures/98eddcb74a0300e8408f486798c7ad9f.png' title='|A|-|B|+|C|=0' alt='|A|-|B|+|C|=0' align='middle' />.</p>
<p>And if we apply this to the Mayer-Vietoris sequence fragment we acquired, it follows that<br />
<img src='/latexrender/pictures/695291fcefe046dc1de194dcf2e50591.png' title='|X\cap Y| &amp;#8211; |X| &amp;#8211; |Y| + |X\cup Y| = 0' alt='|X\cap Y| &amp;#8211; |X| &amp;#8211; |Y| + |X\cup Y| = 0' align='middle' /><br />
and thus<br />
<img src='/latexrender/pictures/c025b52671e3870168e22a04150c5d2b.png' title='|X\cup Y| = |X| + |Y| &amp;#8211; |X\cap Y|' alt='|X\cup Y| = |X| + |Y| &amp;#8211; |X\cap Y|' align='middle' /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikael.johanssons.org/archive/2009/01/homological-inclusion-exclusion-and-the-mayer-vietoris-sequence/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>More on Lichtenstein</title>
		<link>http://blog.mikael.johanssons.org/archive/2008/10/more-on-lichtenstein/</link>
		<comments>http://blog.mikael.johanssons.org/archive/2008/10/more-on-lichtenstein/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 22:03:38 +0000</pubDate>
		<dc:creator>Michi</dc:creator>
				<category><![CDATA[Combinatorics]]></category>
		<category><![CDATA[Geometry]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Topology]]></category>

		<guid isPermaLink="false">http://blog.mikael.johanssons.org/?p=183</guid>
		<description><![CDATA[It turns out that there is even more to say on the communes of Lichtenstein. First of all, there is a 5-clique in the communal graph, as Brian Hayes pointed out. But there are two different excluded subgraphs for planarity &#8211; so if we aren&#8217;t looking specifically for the chromatic number, but rather how this [...]]]></description>
			<content:encoded><![CDATA[<p>It turns out that there is even more to say on <a href="http://blog.mikael.johanssons.org/archive/2008/10/on-the-chromatic-number-of-lichtenstein/">the communes of Lichtenstein.<br />
</a><br />
First of all, there is a 5-clique in the communal graph, as Brian Hayes pointed out. But there are two different excluded subgraphs for planarity &#8211; so if we aren&#8217;t looking specifically for the chromatic number, but rather how this graph fails to be a &#8220;normal&#8221; land map, we might want to see whether it realizes BOTH.</p>
<p>It turns out that it does.</p>
<p>The following are two highlighted versions of the Liechtenstein communal graph.</p>
<p><img src="http://blog.mikael.johanssons.org/wp-content/liechtenstein-k5.png"><br />
The embedded K5 with edges in blue.</p>
<p><img src="http://blog.mikael.johanssons.org/wp-content/liechtenstein-k33.png"><br />
The embedded K33 with blue and red vertices.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikael.johanssons.org/archive/2008/10/more-on-lichtenstein/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>On the chromatic number of Lichtenstein</title>
		<link>http://blog.mikael.johanssons.org/archive/2008/10/on-the-chromatic-number-of-lichtenstein/</link>
		<comments>http://blog.mikael.johanssons.org/archive/2008/10/on-the-chromatic-number-of-lichtenstein/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 18:41:17 +0000</pubDate>
		<dc:creator>Michi</dc:creator>
				<category><![CDATA[Combinatorics]]></category>
		<category><![CDATA[Geometry]]></category>
		<category><![CDATA[Mathematics]]></category>

		<guid isPermaLink="false">http://blog.mikael.johanssons.org/?p=182</guid>
		<description><![CDATA[Following the featuring of the internal political structure of Lichtenstein on the Strange Maps blog, Brian Hayes asks for the chromatic number of Lichtenstein. Rahul pointed out that I made errors in transferring the map to a graph. Specifically, I missed the borders Schellenberg-Eschen and Vaduz-Triesen. The post below changes accordingly. Warning: This post DOES [...]]]></description>
			<content:encoded><![CDATA[<p>Following the featuring of the <a href="http://strangemaps.wordpress.com/2008/10/24/322-the-claves-of-liechtenstein">internal political structure of Lichtenstein</a> on the <a href="http://strangemaps.wordpress.com">Strange Maps</a> blog, Brian Hayes asks for the <a href="http://bit-player.org/2008/the-chromatic-number-of-liechtenstein">chromatic number of Lichtenstein</a>.</p>
<p><i>Rahul pointed out that I made errors in transferring the map to a graph. Specifically, I missed the borders Schellenberg-Eschen and Vaduz-Triesen. The post below changes accordingly.</i></p>
<p>Warning: This post DOES contain spoilers to Brian&#8217;s question. If you do want to investigate it yourself, you&#8217;ll need to stop reading now. Apologies to those on my planet feeds.</p>
<p>As a first step, we need to build a graph out of it. I labeled each region in turn with the exclaves numbered higher than the &#8220;main&#8221; region of each organizational unit. And then I build a .dot file to capture them all:</p>
<pre>
graph Lichtenstein {
  Ruggell -- Schellenberg
  Ruggell -- Gamprin1
  Schellenberg -- Mauren
  Schellenberg -- Eschen1
  Mauren -- Eschen1
  Gamprin1 -- Eschen2
  Gamprin1 -- Vaduz2
  Gamprin1 -- Schaan1
  Gamprin1 -- Planken3
  Gamprin1 -- Eschen1
  Eschen1 -- Gamprin2
  Eschen1 -- Planken1
  Eschen2 -- Schaan1
  Vaduz3 -- Schaan1
  Vaduz2 -- Schaan1
  Planken3 -- Schaan1
  Planken2 -- Schaan1
  Schaan1 -- Planken1
  Schaan1 -- Planken4
  Schaan1 -- Vaduz1
  Gamprin2 -- Eschen3
  Eschen3 -- Vaduz4
  Eschen3 -- Schaan2
  Vaduz4 -- Schaan2
  Vaduz4 -- Planken1
  Schaan2 -- Planken1
  Planken1 -- Schaan3
  Vaduz1 -- Triesenberg1
  Vaduz1 -- Triesen
  Planken4 -- Triesenberg1
  Planken4 -- Balzers2
  Balzers2 -- Vaduz5
  Balzers2 -- Schaan4
  Vaduz5 -- Schaan4
  Schaan4 -- Triesenberg1
  Schaan4 -- Vaduz6
  Schaan4 -- Triesenberg2
  Triesenberg1 -- Vaduz6
  Triesenberg1 -- Triesen
  Triesenberg1 -- Balzers3
  Triesen -- Balzers3
  Triesen -- Balzers1
  Triesen -- Schaan5
  Vaduz6 -- Schaan5
  Triesenberg2 -- Schaan5
}
</pre>
<p>Compiling this, we get the graph<br />
<img src="http://blog.mikael.johanssons.org/wp-content/liechtenstein-claves.png"></p>
<p>Now, with this it is an easy job to get the adjacency graph for the communes. We can just delete all numbers in the above dot file. Graphing that, we get instead<br />
<img src="http://blog.mikael.johanssons.org/wp-content/liechtenstein-compacted.png"></p>
<p>Note, however, that the massive duplication of adjacency edges makes this rather hard to read. So we can just amalgamate all those edges into one single edge each. So in the end, the Liechtenstein graph turns out to be<br />
<img src="http://blog.mikael.johanssons.org/wp-content/liechtenstein-sorted.png"></p>
<p>Now, as Brian points out, there is a 5-clique in this map, given by Schaan, Balzers, Vaduz, Planken, Triesenberg. </p>
<p><i>Edited</i>: Michael Lugo pointed out in the comments that my exclusion criterion for 6-cliques is obviously and trivially false. Discussion below here changed appropriately</p>
<p>If there were a 6-clique in the map, there would have to be 6 communes each of which have at least 5 edges connected to them. We can construct the table of degrees for all communes, to see whether this helps:<br />
Balzers: 5<br />
Eschen: 6<br />
Gamprin: 5<br />
Mauren: 2<br />
Planken: 6<br />
Ruggell: 2<br />
Schaan: 7<br />
Schellenberg: 3<br />
Triesen: 4<br />
Triesenberg: 5<br />
Vaduz: 7</p>
<p>So, we have enough edges in Balzers, Eschen, Gamprin, Planken, Schaan, Triesenberg and Vaduz. This gives us 7 candidates for a 6-clique. Thus if two of these have too many edges outside this group, we know that there cannot be a 6-clique in the commune-graph. </p>
<p>Now note that Triesenberg borders to Triesen, so at most 4 of those 5 edges can be within a 6-clique. Also, Gamprin borders to Ruggell, so at most 4 of Gamprin&#8217;s 5 edges can be within a 6-clique. Thus the graph contains no 6-cliques.</p>
<p>Does this, though, mean that we can construct a 5-coloring of the graph? Try this on:<br />
<img src="http://blog.mikael.johanssons.org/wp-content/liechtenstein-colored.png"></p>
<p>I would recolor the Liechtenstein map using this color choice, but I haven&#8217;t gotten around to installing a decent picture editing program just yet. That&#8217;ll have to wait.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikael.johanssons.org/archive/2008/10/on-the-chromatic-number-of-lichtenstein/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>High school topology restarting</title>
		<link>http://blog.mikael.johanssons.org/archive/2007/11/high-school-topology-restarting/</link>
		<comments>http://blog.mikael.johanssons.org/archive/2007/11/high-school-topology-restarting/#comments</comments>
		<pubDate>Fri, 16 Nov 2007 15:34:49 +0000</pubDate>
		<dc:creator>Michi</dc:creator>
				<category><![CDATA[10th grade topology]]></category>
		<category><![CDATA[Combinatorics]]></category>
		<category><![CDATA[Geometry]]></category>
		<category><![CDATA[Homology and Homotopy]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Topology]]></category>

		<guid isPermaLink="false">http://blog.mikael.johanssons.org/archive/2007/11/high-school-topology-restarting/</guid>
		<description><![CDATA[Today, I told my two bright students about abstract and geometric simplicial complexes, about the boundary map and the chain complex over a ring R associated with a simplicial complex &#916;, and assigned them reading out of Hatcher&#8217;s Algebraic Topology. The next couple of weeks will be spent doing homology of simplicial complexes, singular homology, [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I told my two bright students about abstract and geometric simplicial complexes, about the boundary map and the chain complex over a ring R associated with a simplicial complex &Delta;, and assigned them reading out of Hatcher&#8217;s Algebraic Topology. </p>
<p>The next couple of weeks will be spent doing homology of simplicial complexes, singular homology, equivalence of the two, neat things you can do with them; and then we&#8217;ll start moving towards a Borsuk-Ulam-y topological combinatorics direction.</p>
<p>I might end up pulling combinatorics papers from my old &#8220;gang&#8221; in Stockholm on graph complexes, and graph property complexes, and poke around those with them. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikael.johanssons.org/archive/2007/11/high-school-topology-restarting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enumerating the Saneblidze-Umble diagonal in Haskell</title>
		<link>http://blog.mikael.johanssons.org/archive/2007/06/enumerating-the-saneblidze-umble-diagonal-in-haskell/</link>
		<comments>http://blog.mikael.johanssons.org/archive/2007/06/enumerating-the-saneblidze-umble-diagonal-in-haskell/#comments</comments>
		<pubDate>Mon, 11 Jun 2007 14:47:02 +0000</pubDate>
		<dc:creator>Michi</dc:creator>
				<category><![CDATA[A-infinity]]></category>
		<category><![CDATA[Algebra]]></category>
		<category><![CDATA[Combinatorics]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[PhD]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.mikael.johanssons.org/archive/2007/06/enumerating-the-saneblidze-umble-diagonal-in-haskell/</guid>
		<description><![CDATA[IMPORTANT: Note that the implementation herein is severely flawed. Do not use this. One subject I spent a lot of time thinking about this spring was taking tensor products of A&#8734;-algebras. This turns out to actually already being solved &#8211; having a very combinatorial and pretty neat solution. Recall that we can describe ways to [...]]]></description>
			<content:encoded><![CDATA[<p><i>IMPORTANT: Note that the implementation herein is severely flawed. Do not use this.</i></p>
<p>One subject I spent a lot of time thinking about this spring was taking tensor products of A<sub>&infin;</sub>-algebras. This turns out to actually already being solved &#8211; having a very combinatorial and pretty neat solution.</p>
<p>Recall that we can describe ways to associate operations and homotopy of associators by a sequence of polyhedra K<sub>n</sub>, n=2,3,.., called the associahedra. An A<sub>&infin;</sub>-algebra can be defined as being a map from the <i>cellular chains on the Associahedra</i> to <i>n</i>-ary endomorphisms of a graded vector space.</p>
<p>If this was incomprehensible to you, no matter for this post. The essence is that by figuring out how to deal with these polyhedra, we can figure out how to deal with A<sub>&infin;</sub>-algebras.</p>
<p>A tensor product of algebras is basically the direct product of the polyhedra, and we can get precisely the thing we want if only we find a map from the cellular chains on K<sub>n</sub> to the cellular chains on K<sub>n</sub>xK<sub>n</sub> fulfilling a few neat properties.</p>
<p>This map is what is known in the literature as the Saneblidze-Umble diagonal from the people who presented it in a paper from the late 90s. They describe in that paper, and more clearly in a later paper, how to actually get hold of one map with the right properties. The road goes over basic matrices, derived matrices and connecting matrices to trees describing associations. I&#8217;d like to take this opportunity to work through the implementation I just wrote of an enumerator for these, displaying the code and discussing it a little bit.</p>
<p>This post will be written as literate Haskell, so copy the text into a file, and then just save it as <code>SaneblidzeUmble.lhs</code> and you&#8217;re ready to go.</p>
<p>So, we will build a module named SaneblidzeUmble that shall contain the code:</p>
<div class="dean_ch" style="white-space: wrap;">
&gt; <span class="kw1">module</span> SaneblidzeUmble <span class="kw1">where</span><br />
&nbsp;</div>
<p>We&#8217;re going to juggle a lot with lists, and a little with potentially failing calculations, so we&#8217;re going to include a couple of standard utility function sets too.</p>
<div class="dean_ch" style="white-space: wrap;">
&gt; <span class="kw1">import</span> Data.List<br />
&gt; <span class="kw1">import</span> Data.<a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Maybe"><span class="kw4">Maybe</span></a><br />
&nbsp;</div>
<h2>Permutations and staircase matrices</h2>
<p>The issue we&#8217;ll want to solve in the end is to enumerate all the terms entering into a diagonal on K<sub>n</sub>xK<sub>n</sub> for one fixed <i>n</i>. These terms are, using the later to be mentioned terms, in correspondence to derived matrices of staircase matrices with entries from [1,..,n-1]. A <i>staircase matrix</i> is one with one entry for each diagonal (parallel to the main diagonal), and such that along each row and column, all entries are adjacent and strictly increasing down and to the right. </p>
<p>As an example, we have the matrix</p>
<pre>
.14
25.
3..
</pre>
<p>Given a permutation of [1,..,n-1], we can write the images in the order they occur, and then just take this as a description of the entries from lower left to upper right of a staircase matrix. </p>
<p>It turns out that the basic matrices involved in this process are in bijection to permutations of [1,..,n-1] by placing the digits into the matrix, going up whenever the next entry is lower, and going to the right whenever it is larger.</p>
<p>Thus, the example above is given by the permutation (32514).</p>
<p>So, to handle this, we need to be able to list all permutations as well as pick out all rising and all falling part runs of a permutation</p>
<div class="dean_ch" style="white-space: wrap;">
&gt; <span class="kw1">type</span> Permutation <span class="br0">&#91;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Int"><span class="kw4">Int</span></a><span class="br0">&#93;</span><br />
&gt; permutations :: <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Int"><span class="kw4">Int</span></a> -&gt; <span class="br0">&#91;</span>Permutation<span class="br0">&#93;</span><br />
&gt; permutations n = permuteList <span class="br0">&#91;</span><span class="nu0">1</span>..n<span class="br0">&#93;</span></p>
<p>&gt; permuteList :: <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Eq"><span class="kw4">Eq</span></a> a =&gt; <span class="br0">&#91;</span>a<span class="br0">&#93;</span> -&gt; <span class="br0">&#91;</span><span class="br0">&#91;</span>a<span class="br0">&#93;</span><span class="br0">&#93;</span><br />
&gt; permuteList <span class="br0">&#91;</span><span class="br0">&#93;</span> = <span class="br0">&#91;</span><span class="br0">&#93;</span><br />
&gt; permuteList <span class="br0">&#91;</span>a<span class="br0">&#93;</span> = <span class="br0">&#91;</span><span class="br0">&#91;</span>a<span class="br0">&#93;</span><span class="br0">&#93;</span><br />
&gt; permuteList list = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:concatMap"><span class="kw3">concatMap</span></a> <span class="br0">&#40;</span>\x -&gt; <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:map"><span class="kw3">map</span></a> <span class="br0">&#40;</span>x:<span class="br0">&#41;</span> <span class="br0">&#40;</span>permuteList <span class="br0">&#40;</span>l \\ <span class="br0">&#91;</span>x<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> list<br />
&nbsp;</div>
<p>This is almost readable as it stands. The permutations of [1..n] are just the permutations of the list [1..n].<br />
There are no permutations of an empty list, the list with one element has one permutation of itself, and for any larger list we pick out one element at the time, permute the rest and prepend this element. The collected results are compiled into a single long list and returned.</p>
<p>Solves, by recursion, neatly and with a lot of connection to the mathematical thought behind it our problems.</p>
<p>Now, for the chopping permutations into monotonic runs, I&#8217;ll solve it all in a manner slightly decreasing the amount of code repetition. We have a &#8220;factory function&#8221;</p>
<div class="dean_ch" style="white-space: wrap;">
&gt; monotonic :: <span class="br0">&#40;</span>a -&gt; a -&gt; <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Bool"><span class="kw4">Bool</span></a><span class="br0">&#41;</span> <span class="br0">&#91;</span>a<span class="br0">&#93;</span> -&gt; <span class="br0">&#91;</span><span class="br0">&#91;</span>a<span class="br0">&#93;</span><span class="br0">&#93;</span><br />
&gt; monotonic _ <span class="br0">&#91;</span><span class="br0">&#93;</span> = <span class="br0">&#91;</span><span class="br0">&#93;</span><br />
&gt; monotonic _ <span class="br0">&#91;</span>x<span class="br0">&#93;</span> = <span class="br0">&#91;</span><span class="br0">&#91;</span>x<span class="br0">&#93;</span><span class="br0">&#93;</span><br />
&gt; monotonic lt <span class="br0">&#40;</span>x:y:etc<span class="br0">&#41;</span> = <span class="kw1">if</span> lt x y <br />
&gt; &nbsp; &nbsp; <span class="kw1">then</span> <span class="br0">&#40;</span>x:s<span class="br0">&#41;</span>:ss<br />
&gt; &nbsp; &nbsp; <span class="kw1">else</span> <span class="br0">&#91;</span>x<span class="br0">&#93;</span>:<span class="br0">&#40;</span>s:ss<span class="br0">&#41;</span><br />
&gt; &nbsp; <span class="kw1">where</span> <span class="br0">&#40;</span>s:ss<span class="br0">&#41;</span> = monotonic lt <span class="br0">&#40;</span>y:etc<span class="br0">&#41;</span><br />
&nbsp;</div>
<p>and two use cases of this</p>
<div class="dean_ch" style="white-space: wrap;">
&gt; risers = monotonic <span class="br0">&#40;</span>&lt;=<span class="br0">&#41;</span><br />
&gt; fallers = monotonic <span class="br0">&#40;</span>&gt;=<span class="br0">&#41;</span><br />
&nbsp;</div>
<p>Using this, we can build the matrix out of a given permutation. The only really interesting thing for the diagonal about such a matrix is the contents of the rows and of the columns, so we shall just use that. This means we can represent a matrix as the list of rows and the list of columns. Since row and columns &#8220;look basically the same&#8221;, they&#8217;ll be represented by the same type. So we have</p>
<div class="dean_ch" style="white-space: wrap;">
&gt; <span class="kw1">type</span> Row <span class="br0">&#91;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Int"><span class="kw4">Int</span></a><span class="br0">&#93;</span><br />
&gt; buildMatrix :: Permutation -&gt; <span class="br0">&#40;</span><span class="br0">&#91;</span>Row<span class="br0">&#93;</span>,<span class="br0">&#91;</span>Row<span class="br0">&#93;</span><span class="br0">&#41;</span><br />
&gt; buildMatrix p = <span class="br0">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:map"><span class="kw3">map</span></a> sort <span class="br0">&#40;</span>fallers p<span class="br0">&#41;</span>, <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:reverse"><span class="kw3">reverse</span></a> <span class="br0">&#40;</span>risers p<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp;</div>
<p>The reason we use map sort and reverse is to make the result fit with the conventions chosen by Saneblidze and Umble. Note: when actually reading the results, users should take care to read the Columns backwards.</p>
<h2>Deriving staircase matrices</h2>
<p>Deriving the matrices is done with so called moves. We have a downward move, and a rightward move &#8211; both consisting of picking a subset of elements in one row or one column, and pushing them over to the next &#8211; given the condition that all the moved elements have to be larger than the largest they move over to. They also have to move to empty positions, but the ordering conditions for the staircase matrices will guarantee that if they really are larger, then the corresponding position is already empty.</p>
<p>So, we can write a a function that gives us all the subsets of the first column/row that might possibly be moved to the second in a given column/row-list of a matrix</p>
<div class="dean_ch" style="white-space: wrap;">
&gt; listMovable :: <span class="br0">&#91;</span>Row<span class="br0">&#93;</span> -&gt; <span class="br0">&#91;</span><span class="br0">&#91;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Int"><span class="kw4">Int</span></a><span class="br0">&#93;</span><span class="br0">&#93;</span><br />
&gt; listMovable <span class="br0">&#91;</span><span class="br0">&#93;</span> = <span class="br0">&#91;</span><span class="br0">&#93;</span><br />
&gt; listMovable <span class="br0">&#91;</span>a<span class="br0">&#93;</span> = <span class="br0">&#91;</span><span class="br0">&#93;</span><br />
&gt; listMovable <span class="br0">&#40;</span>a:b:<span class="kw1">as</span><span class="br0">&#41;</span> = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:filter"><span class="kw3">filter</span></a> <span class="br0">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:not"><span class="kw3">not</span></a>.<a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:null"><span class="kw3">null</span></a><span class="br0">&#41;</span> $ subsets <span class="br0">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:filter"><span class="kw3">filter</span></a> <span class="br0">&#40;</span>&gt;<span class="br0">&#40;</span>m b<span class="br0">&#41;</span><span class="br0">&#41;</span> a<span class="br0">&#41;</span> <span class="kw1">where</span><br />
&gt; &nbsp; m <span class="br0">&#91;</span><span class="br0">&#93;</span> = <span class="nu0">0</span><br />
&gt; &nbsp; m b = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:maximum"><span class="kw3">maximum</span></a> b<br />
&nbsp;</div>
<p>This function picks out all the subsets of elements that fulfill the requirement of being larger than the largest element of the next row. But hang on &#8211; this <code>subset</code>-function actually isn&#8217;t defined yet. No worries &#8211; it&#8217;s easily done:</p>
<div class="dean_ch" style="white-space: wrap;">
&gt; subsets :: <span class="br0">&#91;</span>a<span class="br0">&#93;</span> -&gt; <span class="br0">&#91;</span><span class="br0">&#91;</span>a<span class="br0">&#93;</span><span class="br0">&#93;</span><br />
&gt; subsets <span class="br0">&#91;</span><span class="br0">&#93;</span> = <span class="br0">&#91;</span><span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#93;</span><br />
&gt; subsets <span class="br0">&#40;</span>a:<span class="kw1">as</span><span class="br0">&#41;</span> = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:map"><span class="kw3">map</span></a> <span class="br0">&#40;</span>a:<span class="br0">&#41;</span> <span class="br0">&#40;</span>subsets <span class="kw1">as</span><span class="br0">&#41;</span> ++ subsets <span class="kw1">as</span><br />
&nbsp;</div>
<p>Again, we define everything recursively, relying on a base case of &#8220;blinding&#8221; simplicity, and end up with a very mathematical looking description. Here, the subsets of the empty set is just the empty set itself, and the subsets of any set with one element existing in it consists of the subsets containing that element and those that do not contain it. We simply list first those with and then those without. </p>
<p>Now, for the actual deriving move, we might run into a host of trouble, so we&#8217;ll just let it be able to return an error condition. It first checks a few possible error cases, and then writes down the actual move by picking out the rows it needs, modifying those, and putting it all together again in the end.</p>
<p>Supposing we have some set <i>m</i> we want to move, and we have a list of the rows where it could be moved, then we&#8217;ll want to first check whether all of <i>m</i> is in a single row together. Thus, for each row, we pick out all elements that are in our set <i>m</i>. But we don&#8217;t really care for what the elements are &#8211; we only need the number in each. So we compile a list of the lengths of these filtered out pieces.</p>
<p>We shall require the number of rows that have all the pieces we want to move to be 1, and also for that single row to have a good position within the matrix.</p>
<div class="dean_ch" style="white-space: wrap;">
&gt; moveDerivate :: <span class="br0">&#91;</span>Row<span class="br0">&#93;</span> -&gt; <span class="br0">&#91;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Int"><span class="kw4">Int</span></a><span class="br0">&#93;</span> -&gt; <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Maybe"><span class="kw4">Maybe</span></a> <span class="br0">&#91;</span>Row<span class="br0">&#93;</span><br />
&gt; moveDerivate rows <span class="br0">&#91;</span><span class="br0">&#93;</span> = Nothing<br />
&gt; moveDerivate rows m = returnVal <span class="kw1">where</span><br />
&gt; &nbsp; movableInRow = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:map"><span class="kw3">map</span></a> <span class="br0">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:filter"><span class="kw3">filter</span></a> <span class="br0">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:flip"><span class="kw3">flip</span></a> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:elem"><span class="kw3">elem</span></a> m<span class="br0">&#41;</span><span class="br0">&#41;</span> tr<br />
&gt; &nbsp; numberMovableInRow = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:map"><span class="kw3">map</span></a> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:length"><span class="kw3">length</span></a> movableInRow<br />
&gt; &nbsp; countRowsWithMovable = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:length"><span class="kw3">length</span></a> <span class="br0">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:filter"><span class="kw3">filter</span></a> <span class="br0">&#40;</span>==<a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:length"><span class="kw3">length</span></a> m<span class="br0">&#41;</span> numberMovableInRow<span class="br0">&#41;</span><br />
&gt; &nbsp; indexRow = findIndex <span class="br0">&#40;</span>==<a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:length"><span class="kw3">length</span></a> m<span class="br0">&#41;</span> numberMovableInRow<br />
&gt; &nbsp; returnVal <br />
&gt; &nbsp; &nbsp; | countRowsWithMovable /= <span class="nu0">1</span> = Nothing<br />
&gt; &nbsp; &nbsp; | isNothing indexRow = Nothing<br />
&gt; &nbsp; &nbsp; | index &gt; <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:length"><span class="kw3">length</span></a> rows &#8211; <span class="nu0">2</span> = Nothing<br />
&gt; &nbsp; &nbsp; | <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:minimum"><span class="kw3">minimum</span></a> m &lt; <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:maximum"><span class="kw3">maximum</span></a> <span class="br0">&#40;</span>rows !! index<span class="br0">&#41;</span> = Nothing<br />
&gt; &nbsp; &nbsp; | <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:otherwise"><span class="kw3">otherwise</span></a> = moveThem rows m index<br />
&gt; &nbsp; &nbsp; <span class="kw1">where</span><br />
&gt; &nbsp; &nbsp; &nbsp; index = fromJust indexRow<br />
&gt; &nbsp; &nbsp; &nbsp; moveThem rows m idx = Just $ <br />
&gt; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:take"><span class="kw3">take</span></a> index rows<span class="br0">&#41;</span> ++ <br />
&gt; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span><span class="br0">&#40;</span>rows !! index<span class="br0">&#41;</span> \\ m<span class="br0">&#93;</span> ++<br />
&gt; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span><span class="br0">&#40;</span>sort <span class="br0">&#40;</span>rows !! <span class="br0">&#40;</span>index + <span class="nu0">1</span><span class="br0">&#41;</span> ++ m<span class="br0">&#41;</span><span class="br0">&#93;</span> ++<br />
&gt; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:drop"><span class="kw3">drop</span></a> <span class="br0">&#40;</span>index<span class="nu0">+2</span><span class="br0">&#41;</span> rows<span class="br0">&#41;</span><br />
&nbsp;</div>
<p>That monstrous expression at the end is known as a guard expression. It works through the cases until something actually is true, and then returns whatever is after the equal sign as the value. The conditions I listed weed out all the pathologies, and lets the program pick out something sensible whenever possible.</p>
<p>So, we can list all possibilities of one row, and we can move them. This should be enough to simply generate all derived matrices, right? Let&#8217;s start simple. Let&#8217;s start with all we can do on one side of the pair &#8211; either all possible down moves or all possible right moves (they are essentially the same anyway&#8230;)</p>
<div class="dean_ch" style="white-space: wrap;">
&gt; derivedRows :: <span class="br0">&#91;</span>Rows<span class="br0">&#93;</span> -&gt; <span class="br0">&#91;</span><span class="br0">&#91;</span>Rows<span class="br0">&#93;</span><span class="br0">&#93;</span><br />
&gt; derivedRows m = derivedAcc <span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>m<span class="br0">&#93;</span> <span class="kw1">where</span><br />
&gt; &nbsp; derivedAcc out <span class="br0">&#91;</span><span class="br0">&#93;</span> = out<br />
&gt; &nbsp; derivedAcc out <span class="br0">&#40;</span>q:queue<span class="br0">&#41;</span> = derivedAcc <span class="br0">&#40;</span>out++<span class="br0">&#91;</span>q<span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>queue++rest<span class="br0">&#41;</span> <span class="kw1">where</span><br />
&gt; &nbsp; &nbsp; movables = <span class="br0">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:concatMap"><span class="kw3">concatMap</span></a> listMovable . tails<span class="br0">&#41;</span> q<br />
&gt; &nbsp; &nbsp; rest = mapMaybe <span class="br0">&#40;</span>moveDerivate q<span class="br0">&#41;</span> movables<br />
&nbsp;</div>
<p>Guiding you through this piece of code &#8211; when encountered with a list of rows, we look at each starting point, list all the possibly movable sets at that point, and move the corresponding sets, placing all the results at the back of a queue that we work through. Once the queue is empty, we know we have worked through all the results from all the moves we could find, and that no others can be found.</p>
<p>So, if we have our pair of row-lists? We first move to the right, and then down. At each point, we keep the other half fixed, and simply add it on to all the results of moving in the first part.  </p>
<div class="dean_ch" style="white-space: wrap;">
&gt; derivedMatrices :: <span class="br0">&#40;</span><span class="br0">&#91;</span>Rows<span class="br0">&#93;</span>,<span class="br0">&#91;</span>Rows<span class="br0">&#93;</span><span class="br0">&#41;</span> -&gt; <span class="br0">&#91;</span><span class="br0">&#40;</span><span class="br0">&#91;</span>Rows<span class="br0">&#93;</span>,<span class="br0">&#91;</span>Rows<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
&gt; derivedMatrices matrix@<span class="br0">&#40;</span>m1,m2<span class="br0">&#41;</span> = nub <span class="br0">&#40;</span>derivedFirst <span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>matrix<span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="kw1">where</span><br />
&gt; &nbsp; derivedFirst matrices <span class="br0">&#91;</span><span class="br0">&#93;</span> = derivedSecond <span class="br0">&#91;</span><span class="br0">&#93;</span> matrices<br />
&gt; &nbsp; derivedFirst out <span class="br0">&#40;</span><span class="br0">&#40;</span>q1,q2<span class="br0">&#41;</span>:queue<span class="br0">&#41;</span> = derivedFirst <span class="br0">&#40;</span>out++new<span class="br0">&#41;</span> queue <span class="kw1">where</span><br />
&gt; &nbsp; &nbsp; new = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:map"><span class="kw3">map</span></a> <span class="br0">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:flip"><span class="kw3">flip</span></a> <span class="br0">&#40;</span>,<span class="br0">&#41;</span> q2<span class="br0">&#41;</span> <span class="br0">&#40;</span>derivedRows q1<span class="br0">&#41;</span><br />
&gt; &nbsp; derivedSecond matrices <span class="br0">&#91;</span><span class="br0">&#93;</span> = matrices<br />
&gt; &nbsp; derivedSecond out <span class="br0">&#40;</span><span class="br0">&#40;</span>q1,q2<span class="br0">&#41;</span>:queue<span class="br0">&#41;</span> = derivedSecond <span class="br0">&#40;</span>out++new<span class="br0">&#41;</span> queue <span class="kw1">where</span><br />
&gt; &nbsp; &nbsp; new = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:map"><span class="kw3">map</span></a> <span class="br0">&#40;</span><span class="br0">&#40;</span>,<span class="br0">&#41;</span> q1<span class="br0">&#41;</span> <span class="br0">&#40;</span>derivedRows q2<span class="br0">&#41;</span><br />
&nbsp;</div>
<p>This first works through one direction, taking all derived rows, and tacking on the constant second half, then when that&#8217;s done, changes to the same but for the other half of the pair.</p>
<p>Now, we&#8217;re almost able to state what a specific diagonal looks like. There is only one more thing to handle: we might not want the results of a particular computation. More specifically, we recognize something we do not want by it having a row that isn&#8217;t consecutive, not even when including previously occurring rows. So, we need to check that.</p>
<div class="dean_ch" style="white-space: wrap;">
&gt; checkTree :: <span class="br0">&#91;</span>Row<span class="br0">&#93;</span> -&gt; <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Bool"><span class="kw4">Bool</span></a><br />
&gt; checkTree rows = checkAcc <span class="br0">&#91;</span><span class="br0">&#93;</span> rows <span class="kw1">where</span><br />
&gt; &nbsp; checkAcc seen <span class="br0">&#91;</span><span class="br0">&#93;</span> = True<br />
&gt; &nbsp; checkAcc seen <span class="br0">&#40;</span><span class="br0">&#91;</span><span class="br0">&#93;</span>:morerows<span class="br0">&#41;</span> = checkAcc seen morerows<br />
&gt; &nbsp; checkAcc seen <span class="br0">&#40;</span>row:morerows<span class="br0">&#41;</span> <br />
&gt; &nbsp; &nbsp; | isOK = checkAcc newseen morerows<br />
&gt; &nbsp; &nbsp; | <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:otherwise"><span class="kw3">otherwise</span></a> = False<br />
&gt; &nbsp; &nbsp; <span class="kw1">where</span><br />
&gt; &nbsp; &nbsp; &nbsp; newseen = seen ++ row<br />
&gt; &nbsp; &nbsp; &nbsp; minimal = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:minimum"><span class="kw3">minimum</span></a> newseen<br />
&gt; &nbsp; &nbsp; &nbsp; maximal = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:maximum"><span class="kw3">maximum</span></a> newseen<br />
&gt; &nbsp; &nbsp; &nbsp; <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:length"><span class="kw3">length</span></a> = maximal-minimal<span class="nu0">+1</span><br />
&gt; &nbsp; &nbsp; &nbsp; isOK = <span class="br0">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:length"><span class="kw3">length</span></a> == <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:length"><span class="kw3">length</span></a> newseen<span class="br0">&#41;</span><br />
&nbsp;</div>
<p>Now it&#8217;s just a matter of putting the pieces together</p>
<div class="dean_ch" style="white-space: wrap;">
&gt; diagonalTerms :: <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Int"><span class="kw4">Int</span></a> -&gt; <span class="br0">&#91;</span><span class="br0">&#40;</span><span class="br0">&#91;</span>Row<span class="br0">&#93;</span>,<span class="br0">&#91;</span>Row<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
&gt; diagonalTerms n = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:filter"><span class="kw3">filter</span></a> checkTrees allMatrices <span class="kw1">where</span><br />
&gt; &nbsp; checkTrees <span class="br0">&#40;</span>t1,t2<span class="br0">&#41;</span> = checkTree t1 &amp;&amp; checkTree <span class="br0">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:reverse"><span class="kw3">reverse</span></a> t2<span class="br0">&#41;</span><br />
&gt; &nbsp; allMatrices = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:concatMap"><span class="kw3">concatMap</span></a> derivedMatrices matrices<br />
&gt; &nbsp; matrices = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:map"><span class="kw3">map</span></a> buildMatrix <span class="br0">&#40;</span>permutations n<span class="br0">&#41;</span><br />
&nbsp;</div>
<p>Previously, a student of Ron Umble has done an implementation of the same task in C++. This cannot, according to Umble, handle anything larger than n=5. This Haskell implementation, while being surprisingly short and readable, has on my (64 bit, modern, high memory) workstation been able to meet the following execution parameters:</p>
<table border="1" width="75%" halign="center">
<tr>
<th width="10%">n</th>
<th>number of terms</th>
<th>execution time</th>
<th>memory used</th>
</tr>
<tr>
<td>5</td>
<td>46</td>
<td>0.02 s</td>
<td>4M</td>
</tr>
<tr>
<td>6</td>
<td>124</td>
<td>0.33 s</td>
<td>62M</td>
</tr>
<tr>
<td>7</td>
<td>335</td>
<td>8.77 s</td>
<td>1.9G</td>
</tr>
<tr>
<td>8</td>
<td>911</td>
<td>1020 s</td>
<td>441G</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikael.johanssons.org/archive/2007/06/enumerating-the-saneblidze-umble-diagonal-in-haskell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>looksay &#8211; today&#8217;s Haskell snippet</title>
		<link>http://blog.mikael.johanssons.org/archive/2007/04/looksay-todays-haskell-snippet/</link>
		<comments>http://blog.mikael.johanssons.org/archive/2007/04/looksay-todays-haskell-snippet/#comments</comments>
		<pubDate>Wed, 18 Apr 2007 08:34:17 +0000</pubDate>
		<dc:creator>Michi</dc:creator>
				<category><![CDATA[Combinatorics]]></category>
		<category><![CDATA[Computer]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Sillyness]]></category>

		<guid isPermaLink="false">http://blog.mikael.johanssons.org/archive/2007/04/looksay-todays-haskell-snippet/</guid>
		<description><![CDATA[nextLookSay = foldr &#40;\xs -&#62; &#40;&#91;length xs, head xs&#93;++&#41;&#41; &#91;&#93; . group lookSay = iterate nextLookSay &#91;1&#93; &#160; Conway&#8217;s Look-and-say sequence]]></description>
			<content:encoded><![CDATA[<div class="dean_ch" style="white-space: wrap;">
nextLookSay = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:foldr"><span class="kw3">foldr</span></a> <span class="br0">&#40;</span>\xs -&gt; <span class="br0">&#40;</span><span class="br0">&#91;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:length"><span class="kw3">length</span></a> xs, <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:head"><span class="kw3">head</span></a> xs<span class="br0">&#93;</span>++<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#91;</span><span class="br0">&#93;</span> . group<br />
lookSay = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:iterate"><span class="kw3">iterate</span></a> nextLookSay <span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><br />
&nbsp;</div>
<p><a href=http://en.wikipedia.org/wiki/Look_and_say_sequence>Conway&#8217;s Look-and-say sequence</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikael.johanssons.org/archive/2007/04/looksay-todays-haskell-snippet/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Borsuk-Ulam and West Wing</title>
		<link>http://blog.mikael.johanssons.org/archive/2006/02/borsuk-ulam-and-west-wing/</link>
		<comments>http://blog.mikael.johanssons.org/archive/2006/02/borsuk-ulam-and-west-wing/#comments</comments>
		<pubDate>Tue, 07 Feb 2006 21:56:03 +0000</pubDate>
		<dc:creator>Michi</dc:creator>
				<category><![CDATA[Combinatorics]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Topology]]></category>

		<guid isPermaLink="false">http://blog.mikael.johanssons.org/archives/2006/02/07/borsuk-ulam-and-west-wing/</guid>
		<description><![CDATA[In West Wing 4x20, C-J states that there are two antipodal points with identical temperature on the earth, as an argument why it should be possible to imagine that an egg could stand on its end at the spring equinox.]]></description>
			<content:encoded><![CDATA[<p>In West Wing 4&#215;20, CJ states that there are two antipodal points with identical temperature on the earth, as an argument why it should be possible to imagine that an egg could stand on its end at the spring equinox. This particular plotline also has her most emphatically claiming that this should not be possible at the autumn equinox. Why this particular physics is complete idiocy will be left as an exercise to the interested reader, and instead I will focus on the other claim.</p>
<p>This is, in fact, true. It&#8217;s a corollary to one of the prettiest theorem conglomerates I have ever seen: the Borsuk-Ulam theorem(s). Alas, I haven&#8217;t got my sources on it here at the moment, so I won&#8217;t give you the deep indepth survey I want to give; but I do want to give a bit of overview as to why the claim CJ supports her insane theory with is actually true.</p>
<p>Temperature can be seen as a function from location to the thermometer. For each place on the earth, there is a temperature rating. Furthermore, this function is continuous, since there are no discontinuities &#8211; no sudden jumps in temperature between close points.</p>
<p>This sudden jump thing merits closer explanation. It says that by measuring closer and closer together, you can get the difference in temperature as small as you want to. It doesn&#8217;t prevent steep temperature shifts, it only prevents insane. This assumption, as such, is a valid one since temperature differences tend to flatten themselves out &#8211; if you place a hot and a cold bit close to each other, the cold one heats and the hot chills.</p>
<p>So, we know that it&#8217;s continuous. This, it turns out, is an incredibly powerful to know. It brings in the entire toolbox of topology. Which, in turn, brings us closer to the topic of the post &#8211; the Borsuk-Ulam theorem.</p>
<p>The theorem has a million different equivalent statements. Borsuk himself proved that for any <em>antipodal </em> function <img src='/latexrender/pictures/8fa14cdd754f91cc6554c9e71929cce7.png' title='f' alt='f' align='middle' /> from the sphere to itself (meaning that <img src='/latexrender/pictures/5b3041b15bd7ce68950aadce48551b97.png' title='f(-x)=-f(x)' alt='f(-x)=-f(x)' align='middle' />) has <em>odd degree</em>. I won&#8217;t enter into what this means more precisely, but it has a few cool corollaries:</p>
<ol>
<li>Any family of <img src='/latexrender/pictures/40b85027598d87611b1c8d5d11e46812.png' title='n+1' alt='n+1' align='middle' /> closed sets covering <img src='/latexrender/pictures/f74115260830faf5178589e98c061a4e.png' title='S^n' alt='S^n' align='middle' /> has a member containing an antipodal pair.</li>
<li>Any map from the sphere to the plane must send some antipodal pair to the same point</li>
</ol>
<p>1 has a few fun interpretations. I will feed you with those when I get hold of my material again, or actually, you know, think of them.</p>
<p>2, on the other hand, is what we need to prove CJs statement. Our temperature function  <img src='/latexrender/pictures/e358efa489f58062f10dd7316b65649e.png' title='t' alt='t' align='middle' /> can be used to construct a function from the sphere to the plane by sending a point <img src='/latexrender/pictures/44c29edb103a2872f519ad0c9a0fdaaa.png' title='P' alt='P' align='middle' /> on the earth to the point <img src='/latexrender/pictures/d456cec5d62a6a9a4e84dea0ed6b9dec.png' title='(t(P),t(P))' alt='(t(P),t(P))' align='middle' />. This function, in turn, has an antipodal fixpoint, so there are some points <img src='/latexrender/pictures/44c29edb103a2872f519ad0c9a0fdaaa.png' title='P' alt='P' align='middle' /> and <img src='/latexrender/pictures/0c9c2c88e4d475e2325d26616cd357ea.png' title='-P' alt='-P' align='middle' /> such that <img src='/latexrender/pictures/5cf0bec7c00a493349748ba88174d1ad.png' title='(t(P),t(P))=(t(-P),t(-P))' alt='(t(P),t(P))=(t(-P),t(-P))' align='middle' />. But this also means <img src='/latexrender/pictures/147c188879a886cf8bf1fff7ca028549.png' title='t(P)=t(-P)' alt='t(P)=t(-P)' align='middle' />, so there are some pair of antipodal points on the earth with the same temperature. </p>
<p>Thanks to nerdy2@#math:ircnet for reminding me of the details of Borsuk-Ulam, and giving the construction of <img src='/latexrender/pictures/d456cec5d62a6a9a4e84dea0ed6b9dec.png' title='(t(P),t(P))' alt='(t(P),t(P))' align='middle' />.</p>
<p><em>Edit</em>: It was pointed out to me later that all this is really unnecessary. In fact, we can use Borsuk-Ulam straight off to show that on each great circle on earth, there is such an antipodal pair. Indeed, a great circle is <img src='/latexrender/pictures/679c4c927f816045befe573024ddd21b.png' title='S^1' alt='S^1' align='middle' />, and the temperature map takes <img src='/latexrender/pictures/679c4c927f816045befe573024ddd21b.png' title='S^1' alt='S^1' align='middle' /> to <img src='/latexrender/pictures/07e5a4a56a57f5c874ebf79bb67a0b18.png' title='\mathbb R' alt='\mathbb R' align='middle' />, and thus qualifies for the setup for 2 above, since the dimensions of &#8220;sphere&#8221; and &#8220;plane&#8221; don&#8217;t really matter. Thus, on each great circle there is an antipodal pair with equal temperature. And since there are many, many great circle&#8217;s on earth, there are also many, many such points.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikael.johanssons.org/archive/2006/02/borsuk-ulam-and-west-wing/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

