<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Coaquarium</title>
	<atom:link href="http://scolobb.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://scolobb.wordpress.com</link>
	<description>Reports of quests for adventures and coadventures</description>
	<lastBuildDate>Sun, 12 Aug 2012 19:16:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='scolobb.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Coaquarium</title>
		<link>http://scolobb.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://scolobb.wordpress.com/osd.xml" title="Coaquarium" />
	<atom:link rel='hub' href='http://scolobb.wordpress.com/?pushpress=hub'/>
		<item>
		<title>The Revolution (The Preview)</title>
		<link>http://scolobb.wordpress.com/2012/08/12/the-revolution-the-preview/</link>
		<comments>http://scolobb.wordpress.com/2012/08/12/the-revolution-the-preview/#comments</comments>
		<pubDate>Sun, 12 Aug 2012 19:16:45 +0000</pubDate>
		<dc:creator>scolobb</dc:creator>
				<category><![CDATA[SymPy]]></category>
		<category><![CDATA[category theory]]></category>
		<category><![CDATA[commutative diagram]]></category>
		<category><![CDATA[cycles in digraphs]]></category>
		<category><![CDATA[deciding commutativity]]></category>
		<category><![CDATA[diagram]]></category>
		<category><![CDATA[diagram drawing]]></category>
		<category><![CDATA[diagram embedding]]></category>
		<category><![CDATA[subgraph isomorphism problem]]></category>

		<guid isPermaLink="false">http://scolobb.wordpress.com/?p=384</guid>
		<description><![CDATA[This week I continued the work on diagram embeddings and, unfortunately, I have discovered that Diagram did not actually work properly. I have written a status report E-mail to Tom, in which I briefly outine the progess. This E-mail (with some omissions) will serve as this week&#8217;s blog post, because writing a proper blog post [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=384&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This week I continued the work on diagram embeddings and, unfortunately, I have discovered that <tt>Diagram</tt> did not actually work properly.  I have written a status report E-mail to Tom, in which I briefly outine the progess.  This E-mail (with some omissions) will serve as this week&#8217;s blog post, because writing a proper blog post would take me at least three hours, and I would rather code right now, given the limited timeframe.</p>
<blockquote><p>
Unfortunately, I&#8217;ve got some, well, ambiguous news.</p>
<p>Remember I told you about hash-randomisation failures in computing<br />
diagram embeddings?  Well, it turned out that diagram embeddings was<br />
quite OK, and the problem went as far back as the Diagram class.<br />
Essentially, I have done a really bad job implementing it at the<br />
beginning of the summer: I wanted it to directly store all possible<br />
morphism compositions.  However, in that implementation, I didn&#8217;t<br />
really store all compositions, but just a part of them; which part I<br />
stored depended on the order in which the morphisms were supplied<br />
(severe facepalm <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  )</p>
<p>I tried thinking of some good fixes, but, as you can easily imagine,<br />
the whole idea of storing all composites has suffered an epic<br />
disintegration in the face of diagrams with cycles.  I am really<br />
_really_ astonished at how this has managed to slip by me for such a<br />
long time! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
<p>I have spent the first one third of Friday on trying to save the<br />
existing design somehow, by carefully processing all possible edge<br />
cases, but this has very quickly started to be abominable, and, of<br />
course, it didn&#8217;t work.  So, I have spent the greater part of Friday<br />
on thinking out a new Diagram.  I have spent all of yesterday, (all of<br />
Saturday, that is), on implementing this new concept.  Basically, the<br />
new Diagram only stores the relevant generator morphisms, but it is<br />
still able to correctly determine and enumerate the morphisms that<br />
belong to it.  It is also capable of determining whether it is finite<br />
or not (i.e., whether there are cycles in the underlying directed<br />
multigraph).  When asked for all morphisms, the new Diagram yields a<br />
generator which acts correctly both in the finite and infinite cases.<br />
In the finite case it produces all the morphisms of the Diagram.  This<br />
is clearly impossible in the infinite case, but Diagram is<br />
sufficiently clever in this case to produce the morphisms in a<br />
BFS-like manner.  Intuitively, it will first yield all length one<br />
morphisms, then all morphisms of length two, etc.</p>
<p>I have made some changes to the interface of the Diagram to better<br />
reflect the new internals.  Nevertheless, the behaviour in the finite<br />
case is the same as that of the old Diagram (modulo some property<br />
names and minor changes, of course).</p>
<p>One bit of good news that deserves standing out in a separate<br />
paragraph is that I only had to change _one_ line of code in<br />
diagram_drawing.py to get it to work with the new Diagram.  (Well, I<br />
did drop three other lines, because they were redundant), so this<br />
radical swerve with the Diagram has left the larger part of my GSoC<br />
work unaffected.</p>
<p>Now, I have started cherry-picking the diagram embeddings code, and I<br />
have arrived at a conclusion that Diagram has to be further extended.<br />
(&#8220;Extending&#8221; means adding something new, not rewriting it again.)<br />
Namely, it is insufficient to know whether the whole Diagram is finite<br />
or not; I really need to know whether a certain hom-set is finite or<br />
not.  It&#8217;s not that hard to implement, and I&#8217;ve got a cool book on<br />
graphs; however, it&#8217;s going to require some extra time.</p>
<p>Here comes the most important part of my message: I&#8217;m working at the<br />
fullest possible cruising speed (not sprinting yet; that I&#8217;m saving<br />
for the last 100m).  I won&#8217;t obviously have everything done tomorrow,<br />
on Monday; however, I strongly believe that I only need another couple<br />
days to finish the bulk of inferencing.  Provided that on Monday we<br />
have what is referred to as _soft_ pencils-down date, I hope that I&#8217;m<br />
still OK with the GSoC timeframe.  Further, I think I have already<br />
mentioned a couple times that I&#8217;m going to have another couple free<br />
weeks after GSoC, during which I will be easily able to finalise<br />
whatever will be unfinished.  Do note, however, that I definitely<br />
expect to have inferencing done _within_ the GSoC timeframe.</p>
<p>Conclusion: despite the rather radical direction things have taken in<br />
the last two days, I&#8217;m _still_ more or less fine with the timing.</p>
<p>At the moment, you will not be able to see the code I&#8217;m working on on<br />
GitHub.  The reason is that I&#8217;m juggling branches rather ninja-ily<br />
right now, so I don&#8217;t really have the most relevant one to push<br />
online, and they are all relatively short-lived.  I do expect to get<br />
back to working sequentially today, and once I&#8217;ve got there, I&#8217;ll push<br />
to ct3-commutativity to reflect the updates.</p>
<p>I&#8217;m documenting everything I do in as minute detail as possible.  I<br />
think the Diagram class and the embeddings functionality has more<br />
comments than actual code.  I expect this to make reviewing and later<br />
maintenance considerably more agreeable.  Further, my commits are<br />
almost all rather short, with acceptably long commit messages.  There<br />
is one commit that breaks the rule, however: the commit which adds the<br />
new Diagram.  It is one relatively large chunk of code, which replaces<br />
the old Diagram with the new one and shows that the old tests still<br />
pass modulo minor changes.  I have nevertheless reformatted the<br />
history a bit to make this commit easier to review and, of course, the<br />
code itself is just literally stuffed with comments.  All other<br />
commits are much more like my usual ones.
</p></blockquote>
<p>Whenever I&#8217;m done with the core parts of inferencing, I will write a proper blogpost.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scolobb.wordpress.com/384/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scolobb.wordpress.com/384/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=384&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://scolobb.wordpress.com/2012/08/12/the-revolution-the-preview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1128ad70a54b00a756bf154b4b73d4fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">scolobb</media:title>
		</media:content>
	</item>
		<item>
		<title>The Embedding</title>
		<link>http://scolobb.wordpress.com/2012/08/05/the-embedding/</link>
		<comments>http://scolobb.wordpress.com/2012/08/05/the-embedding/#comments</comments>
		<pubDate>Sun, 05 Aug 2012 11:29:33 +0000</pubDate>
		<dc:creator>scolobb</dc:creator>
				<category><![CDATA[SymPy]]></category>
		<category><![CDATA[category theory]]></category>
		<category><![CDATA[diagram embedding]]></category>
		<category><![CDATA[graph embedding]]></category>
		<category><![CDATA[subgraph isomorphism problem]]></category>

		<guid isPermaLink="false">http://scolobb.wordpress.com/?p=357</guid>
		<description><![CDATA[This week I have started some actual code of the derivation of commutativity of diagrams and implications. The first half of the week has gone to splitting Diagram into Diagram and Implication, as outlined in the previous post. Nothing really unexpected happened during that part, so there isn&#8217;t much to say about it, save for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=357&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This week I have started some actual code of the derivation of commutativity of diagrams and implications.  The first half of the week has gone to splitting <tt>Diagram</tt> into <tt>Diagram</tt> and <tt>Implication</tt>, as outlined in the <a href="http://scolobb.wordpress.com/2012/07/29/the-reflection-about-inference/">previous post</a>.  Nothing really unexpected happened during that part, so there isn&#8217;t much to say about it, save for the thing that the code has become clearer and better organised.  Furthermore, I have gained a better understanding of some corner cases, as well as implemented more robust handling for those corner cases.</p>
<p>The second half of the week was considerably more exciting and thought intensive: it was related to finding diagram embeddings.  As it should be clear from the <a href="http://scolobb.wordpress.com/2012/07/29/the-reflection-about-inference/">last post</a>, this functionality lies at the foundation of deciding the commutativity of diagrams and implications.  In what follows, I will refer to the diagram which we need to embed as to the <em>pattern</em>, and  to the diagram into which we need to embed as to the <em>model</em>.  This seems to be an almost universally accepted terminology and comes from the fact that finding subgraph isomorphisms often lies at the base of various pattern matching implementations.</p>
<p>I have started by selecting and analysing the excellent paper by J. R. Ullman, [Ullm1976], which describes a very clear way of enumerating all possible graph embeddings.  This solution, however, was not exactly what I needed.  First of all, the algorithm described in details in [Ullm1976] is actually meant for <em>undirected</em> graphs, whereas one can clearly see arrows in diagrams.  Furthermore (a thought that has occurred to me quite late), diagrams, are actually </em>multigraphs</em>, in the sense that there can be more than one morphism between two objects.  Yet further, a diagram embedding must preserve morphism properties, in the sense that the embedding must map a morphism in the pattern to a morphism in the model, which has exactly the same properties as the morphism in the pattern.</p>
<p>I attempted to find whether someone has addressed the directed multigraph embedding problem before; however, I haven&#8217;t managed to find any references on the Internet, so I started thinking on adapting Ullman&#8217;s solution to my case.  The first thing I figured out was that I could reduce the directed multigraph embedding problem to a directed graph embedding problem.  Indeed, take a diagram and flatten down all multiple morphisms <em>going in the same direction</em> between the same to objects to one <em>directed</em> edge between these two objects.  Then construct directed graph embeddings and, for each such embeddings, for each directed edge <img src='http://s0.wp.com/latex.php?latex=e&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='e' title='e' class='latex' /> of the flattened pattern, construct injective, property-preserving,  mappings from the set of morphisms of the pattern, which were flattened to <img src='http://s0.wp.com/latex.php?latex=e&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='e' title='e' class='latex' />, into the set of morphisms associated with the edge in the flattened model, to which <img src='http://s0.wp.com/latex.php?latex=e&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='e' title='e' class='latex' /> is mapped by the subgraph isomorphism.  (These mappings are actually property-preserving embeddings in their own right, but I won&#8217;t call them so, since I&#8217;m good and I understand that the blog post has just become a bit unclear, so to say <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' />  )</p>
<p>Let&#8217;s see an example.  Consider the diagram comprising two different morphisms: <img src='http://s0.wp.com/latex.php?latex=f%3AA%5Crightarrow+B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f:A&#92;rightarrow B' title='f:A&#92;rightarrow B' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=g%3AA%5Crightarrow+B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='g:A&#92;rightarrow B' title='g:A&#92;rightarrow B' class='latex' />, where <img src='http://s0.wp.com/latex.php?latex=f&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f' title='f' class='latex' /> has the property <tt>golden</tt>; this diagram is going to be out pattern.  Now, consider the model: a diagram comprising three morphisms <img src='http://s0.wp.com/latex.php?latex=%5Calpha%3AC%5Crightarrow+D&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='&#92;alpha:C&#92;rightarrow D' title='&#92;alpha:C&#92;rightarrow D' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=%5Cbeta%3AC%5Crightarrow+D&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='&#92;beta:C&#92;rightarrow D' title='&#92;beta:C&#92;rightarrow D' class='latex' />, and <img src='http://s0.wp.com/latex.php?latex=%5Cgamma%3AC%5Crightarrow+D&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='&#92;gamma:C&#92;rightarrow D' title='&#92;gamma:C&#92;rightarrow D' class='latex' />, in which <img src='http://s0.wp.com/latex.php?latex=%5Cbeta&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='&#92;beta' title='&#92;beta' class='latex' /> has the property <tt>golden</tt>.  Quite obviously, all of our <em>property-preserving</em> embeddings should map <img src='http://s0.wp.com/latex.php?latex=f&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f' title='f' class='latex' /> to <img src='http://s0.wp.com/latex.php?latex=%5Cbeta&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='&#92;beta' title='&#92;beta' class='latex' />, while $\latex g$ can be mapped to either <img src='http://s0.wp.com/latex.php?latex=%5Calpha&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='&#92;alpha' title='&#92;alpha' class='latex' /> or <img src='http://s0.wp.com/latex.php?latex=%5Cbeta&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='&#92;beta' title='&#92;beta' class='latex' />.  Also note that the flattened pattern in this case is the graph consisting of a single edge <img src='http://s0.wp.com/latex.php?latex=%28A%2CB%29&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='(A,B)' title='(A,B)' class='latex' />, while the flattened model is another one-edge graph, <img src='http://s0.wp.com/latex.php?latex=%28C%2CD%29&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='(C,D)' title='(C,D)' class='latex' />.  More complex diagrams are treated in a similar fashion: flatten the pattern and the model to directed graphs, find directed graph embeddings, and then find the property-preserving morphism mappings.</p>
<p>There was another slight surprise underway, however.  Ullman does describe some of the modifications which will make the original algorithm capable of constructing directed graph embeddings, however, he has apparently forgot to describe one of them.  I will give some definitions before going into more detail.  Ullman uses <img src='http://s0.wp.com/latex.php?latex=A&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A' title='A' class='latex' /> to refer to the adjacency matrix of the pattern, <img src='http://s0.wp.com/latex.php?latex=B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='B' title='B' class='latex' /> to refer to the adjacency matrix of the model, and <img src='http://s0.wp.com/latex.php?latex=M&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='M' title='M' class='latex' /> to refer to the matrix representing a mapping of the vertices of the pattern into the vertices of the model; <img src='http://s0.wp.com/latex.php?latex=M_%7Bij%7D+%3D+1&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='M_{ij} = 1' title='M_{ij} = 1' class='latex' /> means that vertex <img src='http://s0.wp.com/latex.php?latex=i&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='i' title='i' class='latex' /> in the pattern is mapped to vertex <img src='http://s0.wp.com/latex.php?latex=j&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='j' title='j' class='latex' /> in the model.</p>
<p>Now, for given <img src='http://s0.wp.com/latex.php?latex=A&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A' title='A' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='B' title='B' class='latex' />, and <img src='http://s0.wp.com/latex.php?latex=M&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='M' title='M' class='latex' />, compute <img src='http://s0.wp.com/latex.php?latex=C+%3D+M+%28M+B%29%5ET&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='C = M (M B)^T' title='C = M (M B)^T' class='latex' />.  Condition (1) in [Ullm1976] states that, if <img src='http://s0.wp.com/latex.php?latex=a_%7Bij%7D+%3D+1%5CRightarrow+c_%7Bij%7D+%3D+1&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='a_{ij} = 1&#92;Rightarrow c_{ij} = 1' title='a_{ij} = 1&#92;Rightarrow c_{ij} = 1' class='latex' />, for any vertices <img src='http://s0.wp.com/latex.php?latex=i&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='i' title='i' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=j&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='j' title='j' class='latex' /> of the patern, then <img src='http://s0.wp.com/latex.php?latex=M&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='M' title='M' class='latex' /> represents an embedding.  (As usual, <img src='http://s0.wp.com/latex.php?latex=a_%7Bij%7D&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='a_{ij}' title='a_{ij}' class='latex' /> are elements of <img src='http://s0.wp.com/latex.php?latex=A&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A' title='A' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=c_%7Bij%7D&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='c_{ij}' title='c_{ij}' class='latex' /> are elements of <img src='http://s0.wp.com/latex.php?latex=C&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='C' title='C' class='latex' />).  When I tried to actually use this criterion for a directed graph, I found that, apparently, <img src='http://s0.wp.com/latex.php?latex=C%5ET&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='C^T' title='C^T' class='latex' /> should be used, instead of <img src='http://s0.wp.com/latex.php?latex=C&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='C' title='C' class='latex' />.  The formal explanation follows.  By abuse of terminology, I will use &#8220;pattern&#8221; and &#8220;model&#8221; to refer to the flattened pattern and flattened model as well.</p>
<p>Let <img src='http://s0.wp.com/latex.php?latex=D+%3D+M+B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='D = M B' title='D = M B' class='latex' />.  <img src='http://s0.wp.com/latex.php?latex=d_%7Bij%7D+%3D+1&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='d_{ij} = 1' title='d_{ij} = 1' class='latex' /> means that <img src='http://s0.wp.com/latex.php?latex=%5Cexists%21+k+.+%28m_%7Bik%7D+%3D+1+%5Cmbox%7B+and+%7D+b_%7Bkj%7D+%3D+1%29&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='&#92;exists! k . (m_{ik} = 1 &#92;mbox{ and } b_{kj} = 1)' title='&#92;exists! k . (m_{ik} = 1 &#92;mbox{ and } b_{kj} = 1)' class='latex' />, where <img src='http://s0.wp.com/latex.php?latex=k&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='k' title='k' class='latex' /> is a vertex of the model.  In other words, this means that the vertex <img src='http://s0.wp.com/latex.php?latex=i&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='i' title='i' class='latex' /> of the pattern is mapped to a unique vertex <img src='http://s0.wp.com/latex.php?latex=k&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='k' title='k' class='latex' /> of the model, such that in the model there exists the (directed) edge <img src='http://s0.wp.com/latex.php?latex=%28k%2C+j%29&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='(k, j)' title='(k, j)' class='latex' />.  Obviously, if <img src='http://s0.wp.com/latex.php?latex=d%5ET_%7Bij%7D&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='d^T_{ij}' title='d^T_{ij}' class='latex' /> is an element of <img src='http://s0.wp.com/latex.php?latex=D%5ET&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='D^T' title='D^T' class='latex' />, the role of the indices is reversed, that is: the vertex <img src='http://s0.wp.com/latex.php?latex=j&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='j' title='j' class='latex' /> of the pattern is mapped to a unique vertex <img src='http://s0.wp.com/latex.php?latex=k&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='k' title='k' class='latex' /> of the model, such that in the model there exists the (directed) edge <img src='http://s0.wp.com/latex.php?latex=%28k%2C+i%29&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='(k, i)' title='(k, i)' class='latex' />.</p>
<p>Now, <img src='http://s0.wp.com/latex.php?latex=c_%7Bij%7D+%3D+1&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='c_{ij} = 1' title='c_{ij} = 1' class='latex' /> means that <img src='http://s0.wp.com/latex.php?latex=%5Cexists%21+t+.+%28m_%7Bit%7D+%3D+1+%5Cmbox%7B+and+%7D+d%5ET_%7Btj%7D+%3D+1%29&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='&#92;exists! t . (m_{it} = 1 &#92;mbox{ and } d^T_{tj} = 1)' title='&#92;exists! t . (m_{it} = 1 &#92;mbox{ and } d^T_{tj} = 1)' class='latex' />.  Deciphering the meanings of the values of the elements of these matrices, this means that the vertex <img src='http://s0.wp.com/latex.php?latex=i&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='i' title='i' class='latex' /> of the pattern is mapped to a vertex <img src='http://s0.wp.com/latex.php?latex=t&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='t' title='t' class='latex' /> of the model, vertex <img src='http://s0.wp.com/latex.php?latex=j&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='j' title='j' class='latex' /> of the pattern is mapped to a vertex <img src='http://s0.wp.com/latex.php?latex=k&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='k' title='k' class='latex' /> of the model, such that in the model there is the edge <img src='http://s0.wp.com/latex.php?latex=%28k%2C+t%29&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='(k, t)' title='(k, t)' class='latex' />.  Now, suppose there is an edge <img src='http://s0.wp.com/latex.php?latex=%28i%2C+j%29&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='(i, j)' title='(i, j)' class='latex' /> in the pattern.  <img src='http://s0.wp.com/latex.php?latex=c_%7Bij%7D+%3D+1&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='c_{ij} = 1' title='c_{ij} = 1' class='latex' /> means <img src='http://s0.wp.com/latex.php?latex=M&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='M' title='M' class='latex' /> maps <img src='http://s0.wp.com/latex.php?latex=i&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='i' title='i' class='latex' /> to <img src='http://s0.wp.com/latex.php?latex=t&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='t' title='t' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=j&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='j' title='j' class='latex' /> to <img src='http://s0.wp.com/latex.php?latex=k&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='k' title='k' class='latex' />, such that the model contains the edge <img src='http://s0.wp.com/latex.php?latex=%28k%2C+t%29&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='(k, t)' title='(k, t)' class='latex' />.  That is, the condition (1) as stated in [Ullm1976] and applied to directed graphs checks that <img src='http://s0.wp.com/latex.php?latex=M&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='M' title='M' class='latex' /> actually <em>reverses</em> the direction of edges!  Therefore, one must actually use <img src='http://s0.wp.com/latex.php?latex=C%5ET&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='C^T' title='C^T' class='latex' /> to check for embeddings.</p>
<p>Now, since the original algorithm in [Ullm1976] was designed for <em>undirected</em> graphs, this extra transposition did not matter, and I think this is the reason why Ullman does not mention it.</p>
<p>I have implemented all the things I have described so far, so diagram embeddings kinda work <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  I have played with python generators a bit, so the code only produces embeddings on the as-needed basis.  I did that because I thought of the situation when any diagram embedding will suffice, but also because using generators has resulted in what I believe to be more elegant code.  The code abounds in comments, so I think it shouldn&#8217;t be a problem to comprehend for someone different from myself.  I don&#8217;t have a formal proof for this statement, however, so, I guess, Tom is going to be the test subject for this supposition ^_^</p>
<p>There are still a couple things to do, though.  First of all Ullman shows a nice optimisation to his algorithm; it looks pretty simple, so I&#8217;ll add it.  I will then write a couple more tests, including some crash tests involving complete graphs.  I will also have to rename the function which does all this magic from <tt>subdiagram_embeddings</tt> to <tt>diagram_embeddings</tt>, for obvious (I hope <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ) reasons.</p>
<h3>References</h3>
<p>[Ullm1976] J. R. Ullman, An Algorithm for Subgraph Isomorphism, J. Association of Computing Machinery, March, 1976, 16, 31&#8211;42.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scolobb.wordpress.com/357/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scolobb.wordpress.com/357/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=357&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://scolobb.wordpress.com/2012/08/05/the-embedding/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1128ad70a54b00a756bf154b4b73d4fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">scolobb</media:title>
		</media:content>
	</item>
		<item>
		<title>The Reflection about Inference</title>
		<link>http://scolobb.wordpress.com/2012/07/29/the-reflection-about-inference/</link>
		<comments>http://scolobb.wordpress.com/2012/07/29/the-reflection-about-inference/#comments</comments>
		<pubDate>Sun, 29 Jul 2012 19:20:53 +0000</pubDate>
		<dc:creator>scolobb</dc:creator>
				<category><![CDATA[SymPy]]></category>
		<category><![CDATA[backward chaining]]></category>
		<category><![CDATA[deciding commutativity]]></category>
		<category><![CDATA[diagram layout]]></category>
		<category><![CDATA[pretty printing]]></category>
		<category><![CDATA[sort key]]></category>
		<category><![CDATA[string representation]]></category>
		<category><![CDATA[subgraph isomorphism problem]]></category>

		<guid isPermaLink="false">http://scolobb.wordpress.com/?p=308</guid>
		<description><![CDATA[This week I have been working both on fixing some existing code (including diagram layout) and on better understanding the code that I am going to write next. As far as the fixes are concerned, I have further polished the diagram layout code, including the addition of some pretty printing for DiagramGrid. I didn&#8217;t initially [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=308&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This week I have been working both on fixing some existing code (including <a href="https://github.com/sympy/sympy/pull/1429">diagram layout</a>) and on better understanding the code that I am going to write next.  As far as the fixes are concerned, I have further polished the diagram layout code, including the addition of some pretty printing for <tt>DiagramGrid</tt>.  I didn&#8217;t initially expect pretty printing to be useful for this class; however, it turned out that being able to quickly glance at the grid itself was very helpful in certain situations.</p>
<p>Something which makes me very content is that I have finally submitted a fix for the sort key problem for unordered collections.  The essence of the problem is as follows.  With hash randomisation enabled, the order of <tt>Basic.args</tt> changes on every run.  On the other hand, <tt>Basic.sort_key</tt> traverses the arguments in the order in which they are stored; therefore, sort keys are dependent on the actual order of the arguments.  This has given me trouble when working on laying out diagrams, specifically, in handling groups.  The thing is that the group handling code relies on <tt>FiniteSet</tt> (this maybe isn&#8217;t the best idea, but that&#8217;s a different story, really <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ): groups are eventually converted to <tt>FiniteSet</tt>&#8216;s of <tt>FiniteSet</tt>&#8216;s.  To assure stable output, the collection of <tt>FiniteSet</tt>&#8216;s is <em>sorted</em>.  However, due to the influence of hash randomisation on sort keys, this sorting would <em>not</em> actually produce the desired consequences.  There was a similar problem in the same block of functionality which had to do with sorting <tt>Diagram</tt>&#8216;s; the issue there was that a <tt>Diagram</tt> stores <tt>Dict</tt>&#8216;s which, being unordered collections, were subject to the same sort key trouble.  Pull request <a href="https://github.com/sympy/sympy/pull/1446">#1446</a> fixes all of these issues and, finally, the diagram drawing code almost always passes all of its tests.</p>
<p>It is worth mentioning that while the fix for the sort key problem was not included in the <a href="https://github.com/sympy/sympy/pull/1429">#1429</a>, I was inclined to classify all problems as related to <tt>FiniteSet.sort_key</tt>.  With the fix in the branch, it turned out that there were some other subtle sorting issues, which I am still fixing.</p>
<p>I have also sent pull request <a href="https://github.com/sympy/sympy/pull/1440">#1440</a> which fixes the pretty printing of morphisms and diagrams, introduced by myself in <a href="https://github.com/sympy/sympy/pull/1338">#1338</a>.  Initially, I would use short Unicode arrows for pretty printing morphisms, but Tom and I have arrived at the conclusion that these arrows look too condensed.  I have then chosen to use long Unicode arrows; it turned out however that Unicode characters which span more than one symbol are not rendered consistently across different machines.  On my computer, the longer arrow would overlap with the next character in line; on Tom&#8217;s, it would not.  Aaron has suggested building up arrows out of em dashes and black right-pointing triangles, and this seems to work better, although it still looks ugly with some fonts (e.g., the default font in <em>rxvt-unicode</em>, as reported by Tom).</p>
<p>I have also promised to implement variable-length horizontal arrows.  I have decided to postpone this for now, however, in order to better focus on my GSoC project.  I will keep that task in mind, however, and will most probably return to it in a couple of days.</p>
<p>As for deciding the commutativity of diagrams, I have run into an unexpected conceptual problem, arising from the fundamental difference between diagrams with conclusions and without conclusions.  Before explaining the problem, I will remind the description of these two types of constructions.  A commutative diagram is a collection of morphisms (which usually form a connected directed graph) with the property that composing all morphisms along any two paths between any two objects produces the same composite morphism.  While being quite general, in category theory it is customary to produce statements like &#8220;if there are such morphisms, there exist such morphisms, and the diagram is commutative&#8221;.  This statement is clearly an implication.  The class <tt>Diagram</tt> is a representation of the second type of statement and contains sets of premise morphisms and conclusion morphisms.  <tt>Diagram</tt> is also conventionally capable of representing simple commutativity if no conclusions are specified.</p>
<p>While I was initially quite comfortable with using <tt>Diagram</tt> for both types of statements, I am really inclined to considering the creation of two separate classes now.  Thus I plan to rename <tt>Diagram</tt> to <tt>Implication</tt> and add a different  <tt>Diagram</tt> which will represent what I used to call &#8220;commutative diagram without conclusions&#8221;.  That is, <tt>Diagram</tt> will hold only one collection of morphisms.</p>
<p>With this separation, it is immediately clear that, in the context of my model, the question &#8220;Is this diagram commutative?&#8221; actually incorporates two totally different questions:</p>
<ol>
<li>Is this <tt>Diagram</tt> commutative?</li>
<li>Is this <tt>Implication</tt> true and commutative?</li>
</ol>
<p>Fortunately for me ( <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ), this newly-discovered separation does not remove the possibility of answering both questions with almost the same algorithm.  I will start with question (1) to further stress the difference between the semantics of diagrams and implications.</p>
<p>Consider a collection of <tt>Diagram</tt>&#8216;s and <tt>Implication</tt>&#8216;s known to be commutative.  (By saying &#8220;an <tt>Implication</tt> is commutative&#8221; I will abuse the terminology and mean &#8220;an <tt>Implication</tt> is true and commutative.&#8221;)  We need to decide whether the target <tt>Diagram</tt> is commutative.  The algorithm I will describe is based on <a href="http://en.wikipedia.org/wiki/Backward_chaining">backward chaining</a> and is therefore recursive.  A recursive step consists of two stages: the <em>commutativity</em> stage and the <em>inference</em> stage.  The goal of the commutativity stage is to decide whether the current version of the target <tt>Diagram</tt> is commutative; the goal of the inference stage is to see whether applying one of the <tt>Implication</tt>&#8216;s will make the target <tt>Diagram</tt> commutative.</p>
<p>The commutativity stage starts with taking every morphism of the target <tt>Diagram</tt> and putting each of them into its own commutative subdiagram.  Now, for each commutative subdiagram, the algorithm will pick a subset of morphisms and will then put the subsets together to form another subdiagram.  This subdiagram will then be compared with each of the <tt>Diagram</tt>&#8216;s known to be commutative.  If a match is found, the subdiagram is added to the set of commutative subdiagrams.  Then, all possible &#8220;absorptions&#8221; among the diagrams are performed (i.e., if subdiagram <img src='http://s0.wp.com/latex.php?latex=A&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A' title='A' class='latex' /> is a subdiagram of <img src='http://s0.wp.com/latex.php?latex=B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='B' title='B' class='latex' />, the subdiagram <img src='http://s0.wp.com/latex.php?latex=A&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A' title='A' class='latex' /> is removed from the collection of subdiagrams (for obvious reasons)) and the iteration returns to its start, where it picks subsets of the new subdiagrams.  Since the number of morphisms in the diagram is finite, this process is finite.  If, in the end, the collection of commutative subdiagrams contains only the target diagram, it is deemed commutative.</p>
<p>Note that this alrogithm is very similar to one of the methods of finding all prime implicants of a boolean function (we called that Blake-Poretski algorithm at the university, but I cannot find any references on my Internet).  I have considered the possibilities of directly converting the commutativity stage to a boolean function minimisation problem, but I haven&#8217;t found a sufficiently elegant way yet.</p>
<p>The inference stage exactly follows the idea of backward chaining.  For each <tt>Implication</tt> an attempt is made to find the embedding of the premises into the target <tt>Diagram</tt>.  If such an embedding is found, the corresponding conclusions are added to a copy of the target <tt>Diagram</tt> and a recursive examination of the modified <tt>Diagram</tt> is made.  The found embedding of one of the <tt>Implication</tt>&#8216;s plus the added conclusions are propagated down the recursion tree as commutative subdiagrams.  The commutative stages of the following recursive calls will take their commutativity for granted.</p>
<p>If one of these recursive calls returns a positive result, this positive result is propagated up the call stack.  If neither of the recursive calls returned a positive result, or if no embedding of an <tt>Implication</tt> has been found in a certain recursive call, a negative result is returned from this recursive call.</p>
<p>Note that it actually was the inference stage that I described in my original GSoC <a href="https://github.com/sympy/sympy/wiki/GSoC-2012-Application-Sergiu-Ivanov:-Category-Theory-Module">proposal</a>.</p>
<p>Before showing how to answer question (2), I would like to analyse the algorithm idea I have just presented a little bit.  One can see that the commutativity and inference stages are <em>very</em> different; so different, in fact, that they are almost independent.  Therefore, these two bits of functionality will live in separate pieces of code, and will be later combined to function together.  I will start by defining two internal classes, <tt>_CommutativityStage</tt> and <tt>_InferenceStage</tt> which will host the corresponding functions.  The code that will actually combine the two will either be a global function or a class; this will be clearer later and is not important at the moment.</p>
<p>Question (2) now: &#8220;Is the given <tt>Implication</tt> true (and commutative)?&#8221;.  In this case, one should start from the premises of the given <tt>Implication</tt> and apply the same strategy as in answering question (1).  Here, however, the terminal criterion is that the target <tt>Diagram</tt> (obtained from the premises of the original <tt>Implication</tt>) is commutative <em>and</em> contains the conclusions of the original <tt>Implication</tt>.</p>
<p>A remark about comparing diagrams is due here: this is nothing but the <a href="http://en.wikipedia.org/wiki/Subgraph_isomorphism_problem">subgraph isomorphism problem</a>.  I have already found <a href="software.nju.edu.cn/lingzong/papers/SGI.pdf">this paper</a> (haven&#8217;t read it yet), but I&#8217;m open to other paper suggestions in this regard <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>EDIT: I have decided to not follow this article and instead focus on a more basic solution.  Should the need occur, I will implement this (apparently) more efficient version.</p>
<p>It is necessary to keep in mind that, besides finding the subgraph isomporphism proper, the code will have to pay attention to morphism properties as well.</p>
<p>Now, the most attentive readers might have already remarked that semantically splitting the class <tt>Diagram</tt> into two will impact diagram drawing.  Yet, the impact will be rather modest, since the drawing code already knows how to deal with something similar to <tt>Implication</tt>; adding explicit support for new <tt>Diagram</tt> is going to require minimal effort.</p>
<p>In this blog post, I recognize that my initial class model was flawed in yet another place.  I try to see this is as a sign of personal progress, though <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scolobb.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scolobb.wordpress.com/308/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=308&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://scolobb.wordpress.com/2012/07/29/the-reflection-about-inference/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1128ad70a54b00a756bf154b4b73d4fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">scolobb</media:title>
		</media:content>
	</item>
		<item>
		<title>The Polish and Further Planning</title>
		<link>http://scolobb.wordpress.com/2012/07/22/the-polish-and-further-planning/</link>
		<comments>http://scolobb.wordpress.com/2012/07/22/the-polish-and-further-planning/#comments</comments>
		<pubDate>Sat, 21 Jul 2012 23:21:49 +0000</pubDate>
		<dc:creator>scolobb</dc:creator>
				<category><![CDATA[SymPy]]></category>
		<category><![CDATA[automatic plotting]]></category>
		<category><![CDATA[category theory]]></category>
		<category><![CDATA[deciding commutativity]]></category>
		<category><![CDATA[diagram layout]]></category>
		<category><![CDATA[grid layout]]></category>
		<category><![CDATA[internal data structures]]></category>
		<category><![CDATA[layout algorithm]]></category>
		<category><![CDATA[timeline]]></category>

		<guid isPermaLink="false">http://scolobb.wordpress.com/?p=285</guid>
		<description><![CDATA[I am currently working on getting my two pull requests into master. Right now, the efforts have been concentrated on the first pull request, concerned with diagram layout. Among the minor fixes, there came a number of more important changes, which I am going to shortly describe in this post, before I get to my [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=285&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I am currently working on getting my two pull requests into <tt>master</tt>.  Right now, the efforts have been concentrated on the first pull request, concerned with diagram layout.  Among the minor fixes, there came a number of more important changes, which I am going to shortly describe in this post, before I get to my further plans.</p>
<p>Among the changes worth mentioning are some updates to the choice of internal data structures of <tt>DiagramGrid</tt>.  Previously, <tt>FiniteSet</tt> was used to store any sets.  Following my mentor&#8217;s suggestion, though, I have refactored the code to only use <tt>FiniteSet</tt> when something needs to be stored in <tt>Basic.args</tt>.  On all other occasions, the built-ins <tt>set</tt> and <tt>frozenset</tt> are used, depending on whether a mutable set or an immutable hashable container is needed.</p>
<p>The other change bearing no fundamental importance but still worth mentioning is the transition to storing undirected edges as two-element <tt>frozenset</tt>&#8216;s.  Previously, edges were stored as two-element tuples which caused a bit of hassle in what concerned recognizing the equality of <tt>(A, B)</tt> and <tt>(B, A)</tt>.  The choice of <tt>frozenset</tt> has brought in more elegant code.  In terms of performance, I do not think that this transition has had a really important impact, since I didn&#8217;t really keep performance in mind when writing other parts of the code anyway.  (I am mainly referring to the construction of the skeleton of the diagram and splitting it into triangles.)will l</p>
<p>Among more significant improvements, I will list the support for disconnected diagrams, one-object diagrams, and, the pinnacle, graceful handling of the situations when growing a pseudopod fails.  Before you start thinking abut who the hell would need disconnected or one-object diagrams, I will remind/introduce the process and the necessity of pseudopods in diagram layout (Hey, that did sound like rubbish, did it <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' />  )</p>
<p>The layout algorithm essentially considers the slightly augmented underlying undirected graph of the diagram and splits it into as many triangles as it can.  Then it tries to sort those triangles according to some rather heuristic (i.e., arbitrary) priority metric, picks them one by one, in this order, and tries to place them on the plane, edge to edge.  The strategy being pure greedy, at some point in time it may happen that there are still triangles, but there are no free edges on the plane to which they could be attached.  In this situation, the algorithm attempts to attach one of the remaining triangles by a vertex, that is, it tries to find such a vertex already in the plane, which also belongs to one of the remaining triangles.  Finally, the algorithm adds an edge of the found triangle to the plane and restarts the process of picking triangles and attaching them by edges.  This new added edge is referred to as <em>pseudopod</em>.</p>
<p>Now, what happens when a pseudopod cannot be grown?  Initially, I was under the impression that it is rather hard to construct such a diagram.  However, it turned out to be rather easy.  Consider the set of objects <img src='http://s0.wp.com/latex.php?latex=%5C%7BA%5C%7D%5Ccup%5C%7BA_i%5Cmid+1%5Cleq+i%5Cleq+10%5C%7D&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='&#92;{A&#92;}&#92;cup&#92;{A_i&#92;mid 1&#92;leq i&#92;leq 10&#92;}' title='&#92;{A&#92;}&#92;cup&#92;{A_i&#92;mid 1&#92;leq i&#92;leq 10&#92;}' class='latex' /> and the set of morphisms <img src='http://s0.wp.com/latex.php?latex=%5C%7Bf_i%3AA%5Crightarrow+A_i%5Cmid+1%5Cleq+i%5Cleq+10%5C%7D&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='&#92;{f_i:A&#92;rightarrow A_i&#92;mid 1&#92;leq i&#92;leq 10&#92;}' title='&#92;{f_i:A&#92;rightarrow A_i&#92;mid 1&#92;leq i&#92;leq 10&#92;}' class='latex' />.  <tt>DiagramGrid</tt> will lay out the first 8 of the <img src='http://s0.wp.com/latex.php?latex=A_i&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A_i' title='A_i' class='latex' /> quite all right: as one would expect, <img src='http://s0.wp.com/latex.php?latex=A&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A' title='A' class='latex' /> gets to be the center of a 3&#215;3 square, whose borders consist of the 8 <img src='http://s0.wp.com/latex.php?latex=A_i&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A_i' title='A_i' class='latex' />&#8216;s.  However, the last two <img src='http://s0.wp.com/latex.php?latex=A_i&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A_i' title='A_i' class='latex' />&#8216;s condition the situation when there are triangles left, but no pseudopods can be grown.</p>
<p>In an attempt to address this problem, I have considered various possible strategies, and have chosen the following one.  When no pseudopod can be grown, take the set of all objects that have not yet been placed and construct from them a subdiagram of the diagram to plot.  Lay that diagram out recursively and then attach the resulting grid to the initial diagram.</p>
<p>One important remark is due here.  This strategy is a &#8220;oh, gosh, things have gone very bad&#8221; strategy, in that is is applied only when all other approaches have failed and in that it does not really guarantee the nice look of the final diagram.  However, it does provide a graceful handling of the specific situations and I do believe that the output is still going to look acceptable.</p>
<p>While the idea itself is rather simple, it is necessary to pay attention to what subtleties it actually brings around.  First of all, the subdiagram constructed from the remaining objects is <em>not</em> necessarily connected.  That&#8217;s easy to see even in the example I have shown in the previous paragraphs.  Furthermore, the constructed diagrams do not necessarily have non-loop morphisms!  (By abuse of graph theoretic terminology, I call a morphism with the same domain and codomain a <em>loop</em> morphism).  That is, addressing pseudopod extension failures brings about the necessity to handle disconnected diagrams and one-object diagrams.</p>
<p>There is not much to say about the support of disconnected diagrams and one-object diagrams, but that I have implemented support for these two cases as well.  The latter case is handled trivially, while the former case employs standard depth-first search of the underlying undirected graph and separate layout of the connected components.  The components are currently dumbly positioned side by side, in a line, and a comment in the source code evokes the possibility of using groups to get a different layout.  I&#8217;m open to suggestions of further improvements in this area, though.</p>
<p>It&#8217;s time to speak about my plans.  I have spent more than initially expected on handling pseudopod growth failures.  This means that there are still some suggestions by my mentor waiting to get fixed (I haven&#8217;t read them yet; hopefully, nothing fundamental there <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' />  ). Further, I absolutely must fix the problem with the sort key of <tt>FiniteSet</tt>.  I have been talking about fixing it for about two weeks already, and it doesn&#8217;t seem to require that much effort.  It is essential that this fix be done, though, since, without it, tests in the <tt>categories</tt> module fail half of the time.  Finally, I will fix how morphisms are currently pretty printed by removing the use of wide Unicode symbols.  These activities will not hopefully take me more than 2 days, at the very most.</p>
<p>Next comes the other exciting part of my project, deciding the commutativity of diagrams.  I have provided the general idea of the algorithm in my <a href="https://github.com/sympy/sympy/wiki/GSoC-2012-Application-Sergiu-Ivanov:-Category-Theory-Module">proposal</a>.  Given that I am currently about two weeks behind the schedule in my proposal, and that I will still need to spend time on getting the code in the pull requests up to snuff, I&#8217;m really feeling very wary about planning my own time.  However, since deciding the algorithm for deciding the commutativity of diagrams I describe in the proposals <em>seems</em> to be rather straightforward, I think I will have at least a basic working version of it two weeks from now, that is, by August 5.  Allowing another week as buffer time and yet another week for merging the corresponding pull request, I do expect to be in time for the firm pencils-down date.</p>
<p>One last remark to make is that after the official end of the GSoC timeframe, I will still have at least one week of rather spare time (I actually expect to have about 2.5 to 3 weeks of time), which means that I will bring the code to a sufficiently polished state despite any possible lags.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scolobb.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scolobb.wordpress.com/285/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=285&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://scolobb.wordpress.com/2012/07/22/the-polish-and-further-planning/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1128ad70a54b00a756bf154b4b73d4fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">scolobb</media:title>
		</media:content>
	</item>
		<item>
		<title>The Almost There (Chapter 1)</title>
		<link>http://scolobb.wordpress.com/2012/07/17/the-almost-there-chapter-1/</link>
		<comments>http://scolobb.wordpress.com/2012/07/17/the-almost-there-chapter-1/#comments</comments>
		<pubDate>Mon, 16 Jul 2012 21:32:25 +0000</pubDate>
		<dc:creator>scolobb</dc:creator>
				<category><![CDATA[SymPy]]></category>
		<category><![CDATA[automatic plotting]]></category>
		<category><![CDATA[category theory]]></category>
		<category><![CDATA[curved arrows]]></category>
		<category><![CDATA[diagram drawing]]></category>
		<category><![CDATA[label positioning]]></category>
		<category><![CDATA[xy-pic]]></category>

		<guid isPermaLink="false">http://scolobb.wordpress.com/?p=259</guid>
		<description><![CDATA[This week I have come ridiculously close to finalising the second major part of my GSoC work: diagram plotting. Before submitting the two pull requests, I only have to add proper docstrings to a couple classes and to integrate the plotting with sympy.printing.preview for easier use. (Well, there also is a FiniteSet-related issue, but I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=259&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This week I have come ridiculously close to finalising the second major part of my GSoC work: diagram plotting.  Before submitting the two pull requests, I only have to add proper docstrings to a couple classes and to integrate the plotting with <tt>sympy.printing.preview</tt> for easier use.  (Well, there also is a <tt>FiniteSet</tt>-related issue, but I hope to be able to fix it more or less swiftly.)  The main functionality is ready, however, and that gives me hopes <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>In terms of material progress, this week has been rather unimpressive: I haven&#8217;t written that many lines of code and that which I have written has introduced seemingly inessential changes to the aspect of the diagrams.  Nevertheless, I think this week can be marked as one of the most thought-intensive.</p>
<p>In the beginning of this week I have extended the drawing of curved morphisms to take into account the situations when there are multiple morphisms between the same two pair of objects.  This allows to automatically typeset diagrams such as Diagram 1.<br />
<div id="attachment_260" class="wp-caption alignright" style="width: 210px"><a href="http://scolobb.files.wordpress.com/2012/07/multiple-curved.png"><img src="http://scolobb.files.wordpress.com/2012/07/multiple-curved.png?w=300&#038;h=292" alt="A diagram with multiple curved morphisms." title="Diagram 1" width="300" height="292" class="size-medium wp-image-260" /></a><p class="wp-caption-text">Diagram 1. Multiple curved morphisms.</p></div></p>
<p>The next two days I have been smashing my head against the simplest approach to the problem of positioning morphisms labels such that they don&#8217;t get intersected by morphisms.  The upsetting part is that, despite the amount of thinking I have done and the amount of code and comments I have written, the actual output hasn&#8217;t really got much better.  (It may be considered to be a success, though, that it hasn&#8217;t got much worse either <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ).  Consider Diagram 2.  No special care about the position of the labels is taken.<br />
<div id="attachment_264" class="wp-caption alignright" style="width: 168px"><a href="http://scolobb.files.wordpress.com/2012/07/triangle-simple.png"><img src="http://scolobb.files.wordpress.com/2012/07/triangle-simple.png?w=549" alt="Diagram 2.  Arbitrary placement of morphism labels." title="Diagram 2"   class="size-full wp-image-264" /></a><p class="wp-caption-text">Diagram 2.  Arbitrary placement of morphism labels.</p></div></p>
<p>Now consider Diagram 3; notice that the labels are now on the outer sides of the diagram.  The trick basically (very basically) consists in detecting those morphisms which form the outer edges of the diagram and then placing their labels on the proper side.  While for vertical and horizontal morphisms the procedure is pretty straightforward, for diagonal morphisms I resolved to apply some basic ideas from analytic geometry and yes, I even do floating-point computations (although I of course try to do them as little as possible).  Nevertheless, the approach I have implemented feels very far from perfect.  I hope though that I have managed to achieve some balance between code that works sufficiently fast and well and code that is intelligible.  Note that the positioning of the labels of the morphsisms which are in the bowels of the visual structure of the diagram remains pretty arbitrary, which may sometimes get ugly.<br />
<div id="attachment_267" class="wp-caption alignright" style="width: 154px"><a href="http://scolobb.files.wordpress.com/2012/07/triangle-positioned.png"><img src="http://scolobb.files.wordpress.com/2012/07/triangle-positioned.png?w=549" alt="Diagram 3.  Explicit positioning of labels of outer morphisms." title="Diagram 3"   class="size-full wp-image-267" /></a><p class="wp-caption-text">Diagram 3.  Explicit positioning of labels of outer morphisms.</p></div></p>
<p>The next feature I have added is the possibility to draw &#8220;loop&#8221; morphisms, i.e., morphisms which have the same domains and codomains.  While proper layout of such morphisms is not guaranteed for very crowded diagrams, this functionality is of some use, as can be seen in Diagram 4.<br />
<div id="attachment_272" class="wp-caption alignright" style="width: 230px"><a href="http://scolobb.files.wordpress.com/2012/07/many-loops.png"><img src="http://scolobb.files.wordpress.com/2012/07/many-loops.png?w=300&#038;h=255" alt="Diagram 4. Typesetting of loop morphisms." title="Diagram 4" width="300" height="255" class="size-medium wp-image-272" /></a><p class="wp-caption-text">Diagram 4. Typesetting of loop morphisms.</p></div></p>
<p>Finally, I have implemented the support for custom arrow formatters.  Arrow formatters are associated to morphisms properties.  Whenever a morphism with some properties is typeset, after the necessary thinking has been carried out, the resulting data is passed to the formatter.  The formatter is free to modify anything it wants in order to influence the appearance of the arrow.  A common usage is shown in Diagram 5.  This effect was achieved with a two-line formatter.<br />
<div id="attachment_275" class="wp-caption alignright" style="width: 210px"><a href="http://scolobb.files.wordpress.com/2012/07/formatter.png"><img src="http://scolobb.files.wordpress.com/2012/07/formatter.png?w=549" alt="Diagram 5. Use of formatters" title="Diagram 5"   class="size-full wp-image-275" /></a><p class="wp-caption-text">Diagram 5. Use of formatters</p></div></p>
<p>I must confess that dealing with hash randomisation-related issues takes up much more time that I always expect.  I have been constantly getting back to certain bits of my code and adding new and new invocations of <tt>sorted</tt> to assure stable output.  Working on this, as well as on some obscure tuning of small details of the diagram is actually what has consumed the bulk of my time this week.  The visual input of such modifications is usually minimal; yet, I do believe they bear a rather important role.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scolobb.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scolobb.wordpress.com/259/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=259&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://scolobb.wordpress.com/2012/07/17/the-almost-there-chapter-1/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1128ad70a54b00a756bf154b4b73d4fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">scolobb</media:title>
		</media:content>

		<media:content url="http://scolobb.files.wordpress.com/2012/07/multiple-curved.png?w=300" medium="image">
			<media:title type="html">Diagram 1</media:title>
		</media:content>

		<media:content url="http://scolobb.files.wordpress.com/2012/07/triangle-simple.png" medium="image">
			<media:title type="html">Diagram 2</media:title>
		</media:content>

		<media:content url="http://scolobb.files.wordpress.com/2012/07/triangle-positioned.png" medium="image">
			<media:title type="html">Diagram 3</media:title>
		</media:content>

		<media:content url="http://scolobb.files.wordpress.com/2012/07/many-loops.png?w=300" medium="image">
			<media:title type="html">Diagram 4</media:title>
		</media:content>

		<media:content url="http://scolobb.files.wordpress.com/2012/07/formatter.png" medium="image">
			<media:title type="html">Diagram 5</media:title>
		</media:content>
	</item>
		<item>
		<title>The First Tangible</title>
		<link>http://scolobb.wordpress.com/2012/07/09/the-first-tangible/</link>
		<comments>http://scolobb.wordpress.com/2012/07/09/the-first-tangible/#comments</comments>
		<pubDate>Sun, 08 Jul 2012 23:03:30 +0000</pubDate>
		<dc:creator>scolobb</dc:creator>
				<category><![CDATA[SymPy]]></category>
		<category><![CDATA[automatic plotting]]></category>
		<category><![CDATA[diagram]]></category>
		<category><![CDATA[diagram drawing]]></category>
		<category><![CDATA[grid layout]]></category>
		<category><![CDATA[groups]]></category>
		<category><![CDATA[line layout]]></category>
		<category><![CDATA[xy-pic]]></category>

		<guid isPermaLink="false">http://scolobb.wordpress.com/?p=238</guid>
		<description><![CDATA[I have the preliminary pleasure to announce the first more or less tangible fruits of my work: some real diagram plots. I will adjourn this part of the show-off until the end of the post, however, so that more people read the whole thing The work I have done this week belongs to two essentially [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=238&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I have the preliminary pleasure to announce the first more or less tangible fruits of my work: some real diagram plots.  I will adjourn this part of the show-off until the end of the post, however, so that more people read the whole thing <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The work I have done this week belongs to two essentially different classes.  In the first half of the week I was still adding new features to the layout functionality; this is mainly about logical groups, which are a way for the user to exercise some control over how the objects are laid out.  The idea behind offering the user some control over the layout is that <tt>DiagramGrid</tt> cannot always guess which placement of objects would be the best for the user, additional input would be very welcome on such occasions.  It was important though to require this input in such a way as to demand as little effort as possible on the part of the user.</p>
<p>Take a look at <a href="http://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Categorical_pullback_%28expanded%29.svg/225px-Categorical_pullback_%28expanded%29.svg.png">the definition of a pullback</a>.  In this diagram, one can easily see that the objects <img src='http://s0.wp.com/latex.php?latex=P&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='P' title='P' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=X&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='X' title='X' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=Y&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='Y' title='Y' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=Z&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='Z' title='Z' class='latex' /> are distinctly separated from the object <img src='http://s0.wp.com/latex.php?latex=Q&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='Q' title='Q' class='latex' />.  It is easy to note further that many of <a href="http://en.wikipedia.org/wiki/Universal_property">universal properties</a> also rely on such semantic grouping of objects.  Further yet, in a lot of diagrams, logical groups are easily seen, as it happens in the case of the <a href="http://en.wikipedia.org/wiki/Five_lemma">five lemma</a>.  These observations have made me think that allowing logical groups would be a perfect addition to the existing automatic layout functionality.</p>
<p>In the current implementation, the user specifies the logical groups by supplying a set of sets of objects.  Thus, in the case of the five lemma, the user can supply the set <img src='http://s0.wp.com/latex.php?latex=%5C%7B%5C%7BA%2C+B%2C+C%2C+D%2C+E%5C%7D%2C+%5C%7BA%27%2C+B%27%2C+C%27%2C+D%27%2C+E%27%5C%7D%5C%7D&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='&#92;{&#92;{A, B, C, D, E&#92;}, &#92;{A&#039;, B&#039;, C&#039;, D&#039;, E&#039;&#92;}&#92;}' title='&#92;{&#92;{A, B, C, D, E&#92;}, &#92;{A&#039;, B&#039;, C&#039;, D&#039;, E&#039;&#92;}&#92;}' class='latex' /> as the description of the groups that can be seen in the diagram.  In the case of the pullback, the following set would be a valid specification: <img src='http://s0.wp.com/latex.php?latex=%5C%7BQ%2C+%5C%7BP%2C+X%2C+Y%2C+Z%5C%7D%5C%7D&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='&#92;{Q, &#92;{P, X, Y, Z&#92;}&#92;}' title='&#92;{Q, &#92;{P, X, Y, Z&#92;}&#92;}' class='latex' />.  Note how it is not necessary to include separate objects in singleton sets.</p>
<p>One more detail on how the groups are handled, about which I am not yet very sure, both in the meaning of utility and test completeness, is that groups can be nested to arbitrary depth.  This is because the current procedure of handling groups is as follows: all supplied elements of the supplied set of groups, which are sets, are considered as diagrams in their own right and are laid out.  The algorithm does not really look into the structure of such a group before going into recursion.  After having laid out each of groups, the current implementation constructs a dummy diagram, starting from the original one in the following way.  The new diagram has as objects all objects and groups included in the groups set.  If between the objects of any two groups there exists a morphism, it is added to the new diagram.  Duplicate morphisms of this kind are essentially omitted for efficiency reasons.  This new dummy diagram is laid out.  Then, in the resulting grid, the cells (and the respective rows and columns) which correspond to groups are expanded to hold the grids into which the groups have been laid out.</p>
<p>The procedure I describe is rather simple, which makes me believe that it is also robust.  Nevertheless, I cannot say I am fully satisfied with how much I have tested it; somewhat pessimistically, I do expect quite a number of bugs.</p>
<p>While logical groups seems to a be rather powerful feature already, it does not help get the layout of the five lemma just like it is usually laid out.  Moreover, I noticed that the current algorithm would never lay out a line diagram in a line.  To avoid this I have added a hint to the layout functionality which would instruct the usage of a different layout algorithm, and which would result in a more line-like shapes.  This algorithm essentially does a depth-first traversal of the underlying undirected graph of the diagram and places the objects according to their distance from the root.  Now, since I wanted to see such a layout applied to some logical groups as well (cf. the five lemma), I have implemented the possibility to supply separate layout hints for each group.  With these instruments at hand, as well as with the simple hint <tt>transpose</tt> which instructs the layout engine to eventually flip the grid about its main diagonal, it is possible to give <tt>DiagramGrid</tt> sufficient information to have the five lemma laid out properly.</p>
<p>While I think that this result is pretty satisfactory, it would of course be way cooler to have <tt>DiagramGrid</tt> guess such stuff automatically.  It is a rather nontrivial task, however.  Take the five lemma, again.  It can be laid out in a line, and look not that bad.  It seems very hard to decide automatic criteria to answer such questions.  Yet, I expect that nice results can be achieved by diversifying the controls offered to the user in what concerns the layout.</p>
<p>I am also considering the possibility of a partially manual layout (and, eventually, a fully manual one), by specifying the exact initial positions of some of the objects.  I believe this would be very useful in the long run, because it would offer a great deal of control, and wouldn&#8217;t still require much unnecessary effort on the user side.  The implementation of such a thing is however still a matter of the future.</p>
<p>I have finished the first half of the week by documenting the layout algorithm in the source itself, as well writing proper docstrings for <tt>DiagramGrid</tt> and its methods.</p>
<p>The second half of the week I have spent working on producing actual <a href="http://www.tug.org/applications/Xy-pic/">Xy-pic</a> code.  As expected, the most difficult part lied in drawing bent arrows.  I have implemented some basic routine to solve this question.  The pinnacle of the currently available functionality is shown in the figure.</p>
<div id="attachment_247" class="wp-caption alignright" style="width: 279px"><a href="http://scolobb.files.wordpress.com/2012/07/cube1.png"><img src="http://scolobb.files.wordpress.com/2012/07/cube1.png?w=269&#038;h=300" alt="" title="The automatic plot of a moderately complex diagram" width="269" height="300" class="size-medium wp-image-247" /></a><p class="wp-caption-text">The automatic plot of a moderately complex diagram</p></div>
<p>There is a bit of work left, however.  First of all, notice how the arrow curving from <img src='http://s0.wp.com/latex.php?latex=A_7&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A_7' title='A_7' class='latex' /> to <img src='http://s0.wp.com/latex.php?latex=A_8&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A_8' title='A_8' class='latex' /> is too close to the objects it passes by.  I plan to solve this by increasing the default amount of curving.  Further, nothing will currently be done if another morphism between these two objects is added, which results in ugly overlaps.  Yet another important problem is positioning of the labels of the morphisms: some of them are too loose in space and it is hard to understand which arrow they belong to.  The label <img src='http://s0.wp.com/latex.php?latex=f_%7B10%7D&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f_{10}' title='f_{10}' class='latex' /> is even crossed by the arrow <img src='http://s0.wp.com/latex.php?latex=f_7&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f_7' title='f_7' class='latex' />.  Unfortunately, I don&#8217;t expect to solve all of these problems with positioning of morphisms labels, because, in many cases, it would be necessary to know the actual graphical information, which is impossible at the current level of abstraction.</p>
<p>Thus my immediate plans are to fix the problems I have enumerated to as a complete extent as possible, and to then submit the layout functionality and the actual drawing functionality as two pull requests, to facilitate review.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scolobb.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scolobb.wordpress.com/238/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=238&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://scolobb.wordpress.com/2012/07/09/the-first-tangible/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1128ad70a54b00a756bf154b4b73d4fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">scolobb</media:title>
		</media:content>

		<media:content url="http://scolobb.files.wordpress.com/2012/07/cube1.png?w=269" medium="image">
			<media:title type="html">The automatic plot of a moderately complex diagram</media:title>
		</media:content>
	</item>
		<item>
		<title>The Layout</title>
		<link>http://scolobb.wordpress.com/2012/07/02/the-layout/</link>
		<comments>http://scolobb.wordpress.com/2012/07/02/the-layout/#comments</comments>
		<pubDate>Mon, 02 Jul 2012 20:42:12 +0000</pubDate>
		<dc:creator>scolobb</dc:creator>
				<category><![CDATA[SymPy]]></category>
		<category><![CDATA[automatic plotting]]></category>
		<category><![CDATA[category theory]]></category>
		<category><![CDATA[diagrams]]></category>
		<category><![CDATA[gotcha]]></category>
		<category><![CDATA[grid layout]]></category>

		<guid isPermaLink="false">http://scolobb.wordpress.com/?p=220</guid>
		<description><![CDATA[I haven&#8217;t posted in quite some time, because I have been totally absorbed by implementing the functionality to lay out diagrams. I am painfully close to having finished it; however, I&#8217;ve been that close to it for a couple days already, and that&#8217;s something which drives me crazy OK, it&#8217;s time to take a general [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=220&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I haven&#8217;t posted in quite some time, because I have been totally absorbed by implementing the functionality to lay out diagrams.  I am painfully close to having finished it; however, I&#8217;ve been that close to it for a couple days already, and that&#8217;s something which drives me crazy <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>OK, it&#8217;s time to take a general look over what has been done.  In the end, I will describe my short-term further plans a bit.</p>
<p>First of all, the goal.  When you want to lay out a (commutative) diagram, you should really aim at grid layout.  This is how people normally typeset diagrams in articles, and this is the thing the semblance of which I would be happy to achieve.  The resulting grid layout is one of the traits of diagrams which make the task of automatically drawing them different from the task of automatically drawing a graph.  The other specific feature is that, when you get a diagram, you can (and you should) actually throw away those morphisms which are not really interesting.  In the following sections, I will try to describe the philosophy behind the functionality I have implemented, for each bit in part.</p>
<p>The first stage of the algorithm is to remove the <b>uninteresting morphisms</b>.  At this stage, those composite morphisms which have no properties are discarded; identity morphisms without properties are discarded as well.  In fact, this corresponds pretty well to how people draw diagrams.  This first stage ends by merging the premises and the conclusions of the diagram into a single container.  This is because, at drawing, the distinction between premises and conclusions is not important at all, since all interesting morphisms should make their way into the final picture.</p>
<p>At the second stage, the algorithm abstracts morphisms away, in favour of unoriented edges between objects.  The code builds the so-called <b>skeleton</b> of the diagram (that&#8217;s an ad-hoc name).  The skeleton is a graph which has all objects of the diagram as vertices.  Between two vertices of the skeleton there is an <em>undirected</em> edge, if these objects are connected by an (interesting) morphism.  Notice how we discard the direction of the connection.  After all edges corresponding to morphisms have been added, the skeleton is further completed in the following way.  An edge is added between any two objects <img src='http://s0.wp.com/latex.php?latex=A&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A' title='A' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=C&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='C' title='C' class='latex' /> for which there exists and object <img src='http://s0.wp.com/latex.php?latex=B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='B' title='B' class='latex' /> such that <img src='http://s0.wp.com/latex.php?latex=A&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A' title='A' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='B' title='B' class='latex' /> are connected with an interesting morphism and <img src='http://s0.wp.com/latex.php?latex=B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='B' title='B' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=C&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='C' title='C' class='latex' /> are connected with an interesting morphism.  This is <em>not</em> the transitive closure of the graph, it is only the first step of it.  The new edges are dummy edges, in the sense that they may not correspond to interesting morphisms.</p>
<p>The next stage is the first key stage of the algorithm.  The skeleton is tesselated into triangles, which will eventually be used to get as many right angles in the layout as possible.  Here is when the dummy edges come into play.  Their presence assures that the diagram can be completely split into triangles.  For those who have read my <a href="https://github.com/sympy/sympy/wiki/GSoC-2012-Application-Sergiu-Ivanov:-Category-Theory-Module">proposal</a>, I will remark that all the stages of diagram analysis I described <em>after</em> laying out the triangles are actually unnecessary, namely because of these dummy edges, which guarantee that we have sufficiently many triangles.  Yet, dummy edges are indeed dummy, in the sense that most of them will not appear in the final diagram.  This makes the triangles we find in the skeleton unevenly interesting to us.  Triangles which have more than one dummy edge are totally extra, because they would distract the attention of the code from  triangles with more meaningful edges and would mess things up, generally.  Therefore, such triangles are immediately dropped.</p>
<p>Once the &#8220;triangulating&#8221; stage is complete, the core of the algorithm comes into play.  Basically, the idea is to pick one of the triangles, pick one of its edges and put it on a grid, horizontally, remembering that it is in the fringe.  Then, iteratively, &#8220;<b>weld</b>&#8221; interesting triangles to the fringe, eventually placing all objects of the diagram on the grid.  This part is the trickiest part of the whole algorithm, so prepare to hear a talk about a lot of magic <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
<p>Any triangle is placed on the grid as a right-angled triangle, with the perpendicular edges being horizontal and vertical.  This assures that we keep &#8220;quite&#8221; close to the desired grid layout.  Whenever a triangle is placed on the grid, the objects which form its vertices are recorded as already placed.  Then, those triangles which only contain objects which have already been placed (uninteresting triangles) are dropped.  That is, once the places of some objects are decided, those objects are never considered again.  This may constitute a point of future improvement, of course, because objects are often drawn in several copies to make the diagram look clearer.</p>
<p>When placing the triangle on the grid, the code attempts to assure that as many interesting (not dummy) edges as possible will be drawn horizontally or vertically.  There is some dark magic in the code which detects such situations, but I hope that after following the trail of comments and just reading the code itself, the whole thing should become rather clear.</p>
<p>Now, since the algorithm is essentially greedy, there can be situations when all edges to which the remaining triangles could have been welded, have already been positioned inside the structure and it is now impossible to find the welding edge.  In this case, the algorithm attempts to attach a triangle to the existing structure by a vertex only.  If such a possibility is found, an edge (the <b>pseudopod</b>) of the triangle is placed as vertically (or horizontally) as possible and then the welding process can be continued, since there already is a welding edge.</p>
<p>Let&#8217;s now focus on what happens to the fringe.  When a new triangle is welded, the two new edges are added to the fringe.  No edges are deleted however, because the welding edge might still have some free space to its other part.  Edges are deleted from the fringe only when they are detected as possible welding edges, but when the algorithm finds that there is no space around them actually.  I have considered several possibilities of correcting the fringe on different occasions; my conclusions so far have been that it&#8217;s not generally worth it, performance-wise.  This question however should be better investigated, including doing some complexity analysis.</p>
<p>You might have noticed that I do not in any way treat the situation when a pseudopod cannot be grown.  I have not encountered such situations during the testing yet, so I decided not to attempt to handle them before I have actually seen an example.  Taking into consideration that I am going to work with diagrams rather intensively later, if such situations are possible, I will indeed run into them.  I must confess that I haven&#8217;t considered the problem theoretically yet, though <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The description of the essential parts of the algorithm is complete here, so I&#8217;m passing over to the overview of the remaining problems and further short-term plans.</p>
<p>Tom Bachmann, my mentor, has suggested that I describe the steps of the algorithm in the docs which come with the source code.  I will do this shortly.  I believe it is essential to write such documentation as soon as possible, despite the abundant (hopefully) comments in the code.</p>
<p>My immediately next task is, however, producing the actual <a href="http://www.tug.org/applications/Xy-pic/">Xy-pic</a> code.  I expect that getting this done at a basic level shouldn&#8217;t be hard.  However, drawing longer morphisms and avoiding intersections for as much as possible may prove a rather hard task to achieve.</p>
<p>Oh, and the almost forgotten conclusion: I now essentially have the core of the automatic diagram plotting functionality, since laying out objects is the most difficult part of the affair.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scolobb.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scolobb.wordpress.com/220/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=220&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://scolobb.wordpress.com/2012/07/02/the-layout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1128ad70a54b00a756bf154b4b73d4fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">scolobb</media:title>
		</media:content>
	</item>
		<item>
		<title>The Matrix</title>
		<link>http://scolobb.wordpress.com/2012/06/17/the-matrix/</link>
		<comments>http://scolobb.wordpress.com/2012/06/17/the-matrix/#comments</comments>
		<pubDate>Sat, 16 Jun 2012 22:34:34 +0000</pubDate>
		<dc:creator>scolobb</dc:creator>
				<category><![CDATA[SymPy]]></category>
		<category><![CDATA[automatic plotting]]></category>
		<category><![CDATA[category theory]]></category>
		<category><![CDATA[commutative diagram]]></category>
		<category><![CDATA[diagram drawing]]></category>
		<category><![CDATA[xy-pic]]></category>

		<guid isPermaLink="false">http://scolobb.wordpress.com/?p=200</guid>
		<description><![CDATA[Since my implementation of the base classes of category theory has received an &#8220;almost good to go&#8221; status, I am now fully transitioning into the second stage of my project: drawing diagrams. I expect this stage to be considerably more thrilling since during it I am going to write some actual functionality, i.e., code that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=200&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Since <a href="https://github.com/sympy/sympy/pull/1338">my implementation</a> of the base classes of category theory has received an &#8220;almost good to go&#8221; status, I am now fully transitioning into the second stage of <a href="https://github.com/sympy/sympy/wiki/GSoC-2012-Application-Sergiu-Ivanov:-Category-Theory-Module">my project</a>: drawing diagrams.  I expect this stage to be considerably more thrilling since during it I am going to write some actual functionality, i.e., code that does something useful&trade;.</p>
<p>Well, I guess I don&#8217;t really have to expect anything any more, since I am already thrilled: a couple days ago I found an awesome LaTeX package, <a href="http://www.tug.org/applications/Xy-pic/">Xy-pic</a>, which allows typesetting precisely what I need: diagrams with grid-like layout.  This Wikipedia <a href="http://en.wikipedia.org/wiki/File:First_isomorphism_theorem_(plain).svg">page</a> shows how easy it is do produce a commutative diagram with this package.  My initial plan was to go with <a href="http://www.texample.net/tikz/">TikZ</a>, which is also awesome, but it is much better for more general drawing tasks.  With TikZ, it would have been necessary to manually arrange objects in the diagram in a grid, place text over arrows, and decide as to how the arrows should curve.  This is not the most difficult part of the diagram drawing business, but it is always nice to use some stuff which someone else has already done (better).</p>
<p>In this post I will try to outline how I see the implementation of the diagram drawing functionality now, after I have went through the review process of my first large chunk of code in SymPy.</p>
<p>According to the <a href="https://github.com/sympy/sympy/wiki/GSoC-2012-Application-Sergiu-Ivanov:-Category-Theory-Module">proposal</a>, the process of drawing a diagram includes two stages.  After the first stage, the matrix which will serve as the outline of the visual representation of the diagram should be constructed.  I plan to have the whole first stage done in the <tt>DiagramGrid</tt> class, which will be constructed from a <tt>Diagram</tt> and will act a lot like a matrix in that it will be possible to see its dimensions and what lies at a position given by rectangular coordinates.  It will also be possible to find out which morphisms connect a certain node in the matrix to other nodes, and whether it is likely that it overlaps with other morphisms or not.  Here the job of <tt>DiagramGrid</tt> ends.  A minor remark is nevertheless due before proceeding to the actual drawing.  In the proposal I stated that certain objects which don&#8217;t fit easily in the existing matrix will be arranged in a circle around the existing structure.  I have abolished this, because it will break the idea of typesetting the diagram in a matrix, which makes the whole thing considerably harder to handle.  Instead, these &#8220;unfitting&#8221; objects will be placed along one of the four edges of the frame of the diagram, while the morphisms going into these objects will be marked with the flag which shows that they may overlap with other morphisms.</p>
<p>The second stage of the diagram drawing process is actually typesetting the diagram matrix using Xy-pic.  This part should be pretty straightforward, since it is basically about putting the matrix that has resulted from the first stage into an Xy-pic matrix.  I plan to have the second stage of drawing implemented in the class <tt>DiagramGridDrawer</tt>.  This class will contain the method <tt>draw_outline</tt>, which will return an Xy-pic representation of a <tt>DiagramGrid</tt>.  The drawer class will have a dictionary of morphism name formatters, which will associate a property to a function of one string argument.  For example, the property &#8220;exists&#8221; may be associated to a function which prepends its argument with the mathematical symbol &#8220;exists&#8221;.  The drawer class will also have a dictionary of morphism styles, which will map string properties to arrow styles.  I have also considered taking advantage of the fact that morphism properties are not enforced to be strings, and putting some additional formatting information into those properties.  I am not yet sure that it is necessary, though, so I don&#8217;t include this into the plan.</p>
<p>Now, there are some changes to the timeline in the proposal, which are caused in part by the fact that I have spent so much time on bringing my first pull request up to scratch, and in part by the fact that I now have a slightly different vision on how to implement the drawing.  Thus I plan to spend the coming week, June 18 &#8211; June 24, on implementing <tt>DiagramGrid</tt>.  Then, in the next week, June 25 &#8211; July 1, I plan to implement <tt>DiagramGridDrawer</tt> and extensively test both classes.  The week July 2 &#8211; July 8 I reserve for getting my changes merged.  Not that I expect to spend a whole week on this; but I&#8217;d rather allocate slightly more time, with some reserve, than make promises which I may fail to fulfill.</p>
<p>I would like to explicitly remark the fact that the changes to the timeline do not delay the moment when I plan to have the drawing functionality ready.  Therefore I&#8217;m still not too far astray from my planned timing <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scolobb.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scolobb.wordpress.com/200/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=200&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://scolobb.wordpress.com/2012/06/17/the-matrix/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1128ad70a54b00a756bf154b4b73d4fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">scolobb</media:title>
		</media:content>
	</item>
		<item>
		<title>The Re-Setting</title>
		<link>http://scolobb.wordpress.com/2012/06/16/the-re-setting/</link>
		<comments>http://scolobb.wordpress.com/2012/06/16/the-re-setting/#comments</comments>
		<pubDate>Fri, 15 Jun 2012 22:55:50 +0000</pubDate>
		<dc:creator>scolobb</dc:creator>
				<category><![CDATA[SymPy]]></category>
		<category><![CDATA[morphism]]></category>
		<category><![CDATA[tests]]></category>
		<category><![CDATA[timeline]]></category>

		<guid isPermaLink="false">http://scolobb.wordpress.com/?p=186</guid>
		<description><![CDATA[I have just finished complying with what I hope to be among the closing waves of remarks on the pull request I opened last week. That pull request adds the classes which model some of the fundamental notions in category theory: Object, Morphism, Diagram, Category. I described these classes in detail in the previous post. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=186&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I have just finished complying with what I hope to be among the closing waves of remarks on the <a href="https://github.com/sympy/sympy/pull/1338">pull request</a> I opened last week.  That pull request adds the classes which model some of the fundamental notions in category theory: <tt>Object</tt>, <tt>Morphism</tt>, <tt>Diagram</tt>, <tt>Category</tt>.  I described these classes in detail in the <a href="http://scolobb.wordpress.com/2012/06/11/the-setting/">previous post</a>.  This week has been revolutionary for those classes, since all all of them have suffered great changes, and the first two of them, <tt>Object</tt> and <tt>Morphism</tt>, have changed to be something radically different.</p>
<p>The most important change concerns morphisms.  In my initial version, I had one class to represent any morphism.  When fitting it into the architecture of SymPy, it turned out that distinguishing between an identity morphism and a non-identity morphism wasn&#8217;t quite that easy, because it is impossible to store a Python Boolean value in <tt>Basic.args</tt>.  The suggested solution was to splinter identity morphisms into a separate class.  Later, my mentor Tom Bachmann noticed that an even finer granularity was necessary.  Indeed, according to the code defined at that moment, if a morphism was a composite, <em>and</em> had a name, then that name wouldn&#8217;t matter at all at comparisons or at printing.  Therefore, composite morphisms don&#8217;t really seem to be the same kind of beast as named morphisms.  And yet again, identity morphisms belong to a separate class of things.</p>
<p>According to this idea, I completely threw away the old <tt>Morphism</tt> and <tt>IdentityMorphism</tt>, and replaced them with <tt>NamedMorphism</tt>, <tt>IdentityMorphism</tt>, <tt>CompositeMorphism</tt>, and a different <tt>Morphism</tt> to serve as the base class.  I have also removed the possibility to create anonymous morphisms.  This has resulted in shorter, easier to use, more flexible, and less error-prone code.  The experience was absolutely great <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Besides this change, I&#8217;ve done numerous corrections and enhancements, which have hopefully brought my code up to scratch.  I have received the relieving &#8220;almost good to go&#8221; comment from my mentor; sounds almost unbelievable <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The downside of this is that I have spent on grooming my code <em>considerably</em> more time than I initially expected.  This means that I have to hurry up with the next sections of my timeline.</p>
<p>This week I have also found something which will hopefully make implementing the diagram drawing functionality more piece-of-cakely: <a href="http://www.tug.org/applications/Xy-pic/">Xy-pic</a>.  My next bit of effort will therefore be directed towards mastering this package and adapting my initial plan to this (rather radical) change of strategy.  This will be reflected in the next blog post, which is due to come soon.  Very soon <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scolobb.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scolobb.wordpress.com/186/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=186&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://scolobb.wordpress.com/2012/06/16/the-re-setting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1128ad70a54b00a756bf154b4b73d4fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">scolobb</media:title>
		</media:content>
	</item>
		<item>
		<title>The Setting</title>
		<link>http://scolobb.wordpress.com/2012/06/11/the-setting/</link>
		<comments>http://scolobb.wordpress.com/2012/06/11/the-setting/#comments</comments>
		<pubDate>Sun, 10 Jun 2012 21:09:58 +0000</pubDate>
		<dc:creator>scolobb</dc:creator>
				<category><![CDATA[SymPy]]></category>
		<category><![CDATA[base classes]]></category>
		<category><![CDATA[diagram]]></category>
		<category><![CDATA[gotcha]]></category>
		<category><![CDATA[morphism]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://scolobb.wordpress.com/?p=119</guid>
		<description><![CDATA[This week has been my first week fully-dedicated to GSoC and my (absolutely beloved) category-theory-related project. First off, I have finished working on the first phase of the project, entitled &#8220;Base Classes&#8221;.  In the course of this phase I have implemented the base classes (oh yeah ) of the category theory module, which includes Object, Morphism, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=119&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This week has been my first week fully-dedicated to GSoC and my (absolutely beloved) category-theory-related <a href="https://github.com/sympy/sympy/wiki/GSoC-2012-Application-Sergiu-Ivanov:-Category-Theory-Module">project</a>.</p>
<p>First off, I have finished working on the first phase of the project, entitled &#8220;Base Classes&#8221;.  In the course of this phase I have implemented the base classes (oh yeah <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ) of the category theory module, which includes <tt>Object</tt>, <tt>Morphism</tt>, <tt>Category</tt>, and <tt>Diagram</tt>.</p>
<p>The names of the classes were meant to be self-documenting, but there are a couple gotchas which are determined by the pre-incipient state of the module. In the following paragraphs I will try to briefly overview the classes and point out the things which may be unexpected.</p>
<p>The first two classes in the enumeration are pretty straightforward. The class <tt>Object</tt> represents an object in an abstract category. Since we&#8217;re talking about abstract categories, an object is little more than its name. The class <tt>Morphism</tt> represents a morphism in an abstract category, which is little more than just an arrow from an object to another object. Correspondingly, a <tt>Morphism</tt>, has a string name, an <tt>Object</tt> which is the <em>domain</em> (the object where the arrow begins) and <em>codomain</em> (the object where the arrow ends). Now, morphisms can be <em>composed</em>. Thus if you have a morphism <img src='http://s0.wp.com/latex.php?latex=f&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f' title='f' class='latex' /> from <img src='http://s0.wp.com/latex.php?latex=A&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A' title='A' class='latex' /> to <img src='http://s0.wp.com/latex.php?latex=B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='B' title='B' class='latex' /> (which are objects in some (asbtract) category), and a morphism <img src='http://s0.wp.com/latex.php?latex=g&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='g' title='g' class='latex' /> from <img src='http://s0.wp.com/latex.php?latex=B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='B' title='B' class='latex' /> to <img src='http://s0.wp.com/latex.php?latex=C&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='C' title='C' class='latex' />, then you can take their composition, which is a morphism from <img src='http://s0.wp.com/latex.php?latex=A&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A' title='A' class='latex' /> to <img src='http://s0.wp.com/latex.php?latex=C&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='C' title='C' class='latex' />. This composite is often denoted <img src='http://s0.wp.com/latex.php?latex=g%5Ccirc+f&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='g&#92;circ f' title='g&#92;circ f' class='latex' /> (mind the order). The morphisms themselves are often written as <img src='http://s0.wp.com/latex.php?latex=f%3AA%5Crightarrow+B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f:A&#92;rightarrow B' title='f:A&#92;rightarrow B' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=g%3AB%5Crightarrow+C&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='g:B&#92;rightarrow C' title='g:B&#92;rightarrow C' class='latex' />. These two morphisms are called <em>composable</em> in this order.</p>
<p>While in some concrete settings like set mappings, group homomorphisms, etc. the composite function/homomorphism acts in a well-defined way, there&#8217;s no way to define the action of an abstract category theoretic morphism. In correspondence with this, compositions of <tt>Moprhism</tt>&#8216;s yield other morphisms, which store the components they were obtained from inside themselves. Composing morphisms which were already composed is all right, since a <tt>Morphism</tt> always stores the flattened-down version of the list of components. Thus a <tt>Morphism</tt> representing <img src='http://s0.wp.com/latex.php?latex=h%5Ccirc+%28g%5Ccirc+f%29&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='h&#92;circ (g&#92;circ f)' title='h&#92;circ (g&#92;circ f)' class='latex' />, the composite of <img src='http://s0.wp.com/latex.php?latex=h%3AC%5Crightarrow+D&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='h:C&#92;rightarrow D' title='h:C&#92;rightarrow D' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=g%5Ccirc+f%3AA%5Crightarrow+C&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='g&#92;circ f:A&#92;rightarrow C' title='g&#92;circ f:A&#92;rightarrow C' class='latex' />, will store the list of three morphisms representing <img src='http://s0.wp.com/latex.php?latex=f&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f' title='f' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=g&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='g' title='g' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=h&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='h' title='h' class='latex' /> (again, mind the order).</p>
<p>A morphism of the form <img src='http://s0.wp.com/latex.php?latex=id_A%3AA%5Crightarrow+A&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='id_A:A&#92;rightarrow A' title='id_A:A&#92;rightarrow A' class='latex' /> is called an <em>identity</em> if for any two other morphisms <img src='http://s0.wp.com/latex.php?latex=f%3AX%5Crightarrow+A&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f:X&#92;rightarrow A' title='f:X&#92;rightarrow A' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=g%3AA%5Crightarrow+Y&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='g:A&#92;rightarrow Y' title='g:A&#92;rightarrow Y' class='latex' /> one has <img src='http://s0.wp.com/latex.php?latex=id_A%5Ccirc+f+%3D+f&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='id_A&#92;circ f = f' title='id_A&#92;circ f = f' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=g%5Ccirc+id_A+%3D+g&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='g&#92;circ id_A = g' title='g&#92;circ id_A = g' class='latex' />, that is, identity morphisms are identities with respect to morphism composition. Instances of <tt>Morphism</tt> which have the flag <tt>identity</tt> set, behave exactly as one would expect them, i.e., if you try to compose with them, nothing happens (of course, I&#8217;m talking of the situation when you take a <em>composable</em> morphism).</p>
<p>So far so good. Here come the gotchas of <tt>Morphism</tt>, however. Morphisms are compared by domain, codomain, and name. Thus for the representations <tt>f1</tt> and <tt>f2</tt> of <img src='http://s0.wp.com/latex.php?latex=f_1%3AA%5Crightarrow+B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f_1:A&#92;rightarrow B' title='f_1:A&#92;rightarrow B' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=f_2%3AA%5Crightarrow+B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f_2:A&#92;rightarrow B' title='f_2:A&#92;rightarrow B' class='latex' />, <tt>f1 == f1</tt> is <tt>True</tt> and <tt>f1 == f2</tt> is <tt>False</tt>, even if <tt>f1</tt> and <tt>f2</tt> are actually the same morphisms with different names. Now, that&#8217;s quite understandable, since a <tt>Morphism</tt> cannot really know what you <em>actually</em> want <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  However, with the implemented apparatus, you <em>can</em> state that <tt>f1</tt> and <tt>f2</tt> are actually the same thing. Read to the end to find out how <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>On a side note, <tt>Morphism</tt> is sufficiently clever to know that all identity morphisms of the same object are equal, no matter the name.</p>
<p>Next comes <tt>Category</tt>. Unfortunately, at the moment this class isn&#8217;t capable of doing much useful stuff. One of the reasons is that the notion of a category is based on the notion of a set-theoretical <a href="http://en.wikipedia.org/wiki/Class_(set_theory)">class</a>, which is not implemented in SymPy yet. More importantly, though, for the purposes of this GSoC project, an essentially primitive <tt>Category</tt> is perfectly enough. A <tt>Category</tt> has a string name and a set of <tt>Diagram</tt>&#8216;s which are asserted to be commutative in this category.</p>
<div id="attachment_157" class="wp-caption alignright" style="width: 210px"><a href="http://scolobb.files.wordpress.com/2012/06/200px-commutative_square-svg.png"><img class="size-full wp-image-157" title="A simple diagram." src="http://scolobb.files.wordpress.com/2012/06/200px-commutative_square-svg.png?w=549" alt="A simple square diagram with four objects and four morphisms."   /></a><p class="wp-caption-text">A simple diagram.</p></div>
<p>The last and the most interesting class in the context of this project is <tt>Diagram</tt>. A diagram is a very cool way to write a lot of stuff in category theory and in algebra in general. A diagram is basically a bunch of objects from a category and some of the morphisms between these objects.  Diagrams are usually drawn, objects being represented as letters and morphisms as arrows between the letters.  A diagram is said to be <em>commutative</em>, if all paths between any two objects <img src='http://s0.wp.com/latex.php?latex=A&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='A' title='A' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='B' title='B' class='latex' /> in the diagram yield the same morphism.  For example, if the diagram in the figure is commutative, then <img src='http://s0.wp.com/latex.php?latex=k%5Ccirc+g+%3D+h%5Ccirc+f&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='k&#92;circ g = h&#92;circ f' title='k&#92;circ g = h&#92;circ f' class='latex' />.</p>
<p>The class <tt>Diagram</tt> is meant to represent such diagrammatic structures.  It cannot be plotted as yet; what it can do is storing a bunch of morphisms.  A <tt>Diagram</tt> does not know whether it is commutative or not; however, one can assert that certain <tt>Diagram</tt>&#8216;s are commutative in a ceratain <tt>Category</tt>.</p>
<p><tt>Diagram</tt> is actually meant to store something slightly more general than what is shown in the picture.  Suppose that the author of the picture has wanted to say that, if <img src='http://s0.wp.com/latex.php?latex=h&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='h' title='h' class='latex' /> is an isomorpism, then there exists a unique moprhism <img src='http://s0.wp.com/latex.php?latex=k&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='k' title='k' class='latex' /> such that the diagram commutes.  Authors often want to say such things, therefore <tt>Diagram</tt> contains <em>two</em> sets of morphisms: the <tt>premises</tt> and <tt>conclusions</tt>.  Well, actually, those are not sets, but rather dictionaries, mapping morphisms to their properties (which are really just strings).  Thus an instance of <tt>Diagram</tt> is read as follows: &#8220;If there exist such morphisms as in <tt>premises</tt> with corresponding properties, than there exist such morphisms as in <tt>conclusions</tt> with corresponding properties and the diagram is commutative&#8221;.  You can also state simpler statements which don&#8217;t look like logical implications by not using the conclusions part of the diagram.</p>
<p>Now, <tt>Diagram</tt> is awesome enough to also include all composite morphisms in premises (and in conclusions, when necessary).  If you specify that <img src='http://s0.wp.com/latex.php?latex=f%3AA%5Crightarrow+B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f:A&#92;rightarrow B' title='f:A&#92;rightarrow B' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=g%3AB%5Crightarrow+C&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='g:B&#92;rightarrow C' title='g:B&#92;rightarrow C' class='latex' /> are in the <tt>Diagram</tt>, then you don&#8217;t have to say that <img src='http://s0.wp.com/latex.php?latex=g%5Ccirc+f%3AA%5Crightarrow+C&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='g&#92;circ f:A&#92;rightarrow C' title='g&#92;circ f:A&#92;rightarrow C' class='latex' /> is in the <tt>Diagram</tt> as well.  There&#8217;s a small thing to keep in mind here: you sometimes add morphisms <em>with properties</em> to a <tt>Diagram</tt>.  When <tt>Diagram</tt> adds the composite <img src='http://s0.wp.com/latex.php?latex=g%5Ccirc+f&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='g&#92;circ f' title='g&#92;circ f' class='latex' /> to itself, the properties of the composite will be the <em>intersection</em> of the properties of <img src='http://s0.wp.com/latex.php?latex=f&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f' title='f' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=g&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='g' title='g' class='latex' />.  You can always override this by explicitly adding the composite with a different set of properties.</p>
<p>And finally, as I promised, I&#8217;ll tell how to state that <img src='http://s0.wp.com/latex.php?latex=f_1%3AA%5Crightarrow+B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f_1:A&#92;rightarrow B' title='f_1:A&#92;rightarrow B' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=f_2%3AA%5Crightarrow+B&amp;bg=000000&amp;fg=b8babb&amp;s=0' alt='f_2:A&#92;rightarrow B' title='f_2:A&#92;rightarrow B' class='latex' /> are equal, despite different names.  Well, just create a diagram with these two morphisms and assert it as commutative <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>And yet even more finally, I&#8217;d like to tell about a bit of programming experience I have found exhilarating this week.   I&#8217;ve learnt a very cool lesson: write your tests before the implementation whenever possible!  There&#8217;s no better formal way to write a specification than to write tests.  I was totally amazed at how this practice streamlined my workflow!</p>
<p>Image source: <a href="http://en.wikipedia.org/wiki/File:Commutative_square.svg">http://en.wikipedia.org/wiki/File:Commutative_square.svg</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scolobb.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scolobb.wordpress.com/119/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=scolobb.wordpress.com&#038;blog=35433045&#038;post=119&#038;subd=scolobb&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://scolobb.wordpress.com/2012/06/11/the-setting/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1128ad70a54b00a756bf154b4b73d4fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">scolobb</media:title>
		</media:content>

		<media:content url="http://scolobb.files.wordpress.com/2012/06/200px-commutative_square-svg.png" medium="image">
			<media:title type="html">A simple diagram.</media:title>
		</media:content>
	</item>
	</channel>
</rss>
