<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-6918427997759942244</atom:id><lastBuildDate>Sun, 21 Apr 2013 13:11:56 +0000</lastBuildDate><category>Order Theory</category><category>Domain Driven Design</category><category>Lattice Theory</category><category>Software Engineering</category><category>Linear Algebra</category><category>Category Theory</category><category>API Design</category><category>Logic</category><category>Clojure</category><category>Data Science</category><category>Semantics</category><category>Math</category><category>Software Process</category><category>Number Theory</category><category>Probability Theory</category><category>Editing</category><category>Programming</category><category>Set Theory</category><category>Naming</category><category>Scala</category><category>Morphology</category><category>Software Complexity</category><category>Relational Algebra</category><category>Neuroscience</category><category>Complex numbers</category><category>Pair Programming</category><category>Design Patterns</category><category>Vector Space Model</category><category>Fibonacci</category><category>Computer Science</category><category>Linguistics</category><category>Group Theory</category><category>Generic Programming</category><category>Software Development</category><category>Software Frameworks</category><category>Abstract Algebra</category><category>Java</category><category>Big O</category><category>Information Entropy</category><category>Software Development Teams</category><category>Bayes</category><category>Graph Theory</category><category>Topology</category><category>Agile</category><category>Rant</category><category>Fractal Geometry</category><category>Combinatorics</category><category>Education</category><category>Code Reuse</category><category>Formal Language Theory</category><title>Elegant Coding</title><description /><link>http://www.elegantcoding.com/</link><managingEditor>noreply@blogger.com (Geoff Moes)</managingEditor><generator>Blogger</generator><openSearch:totalResults>44</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ElegantCoding" /><feedburner:info uri="elegantcoding" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-6203044671557686484</guid><pubDate>Mon, 11 Mar 2013 11:30:00 +0000</pubDate><atom:updated>2013-03-29T12:03:30.279-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Scala</category><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">Set Theory</category><category domain="http://www.blogger.com/atom/ns#">Order Theory</category><category domain="http://www.blogger.com/atom/ns#">Lattice Theory</category><title>Programming and Order Theory</title><description>&lt;style&gt;
blockquote.quote {
   border-bottom: #ddd 1px dotted;
   border-left: #ddd 1px dotted;
   padding-bottom: 0.6em;
   font-style: italic;
   font-family: calibri, tahoma, arial, sans-serif;
   margin: 1em 10% 1em 0px;
   min-height: 40px;
   padding-left: 3.8em;
   padding-right: 1em;
   background: url(http://4.bp.blogspot.com/-WkhuNlv2j88/TjXlBh6SySI/AAAAAAAAAN0/O_G2Z8YdMk8/s320/blockquote.white.png) #f0f0f0 no-repeat 4px top;
   color: #474747;
   border-top: #ddd 1px dotted;
   border-right: #ddd 1px dotted;
   padding-top: 0.6em
}

div.source-code {
    font-family       : "Courier New";
    color             : black;
    background-color  : #eee;
    font-size         : 12px;
    font-size         : 10.0pt;
    border            : 1px dashed #999999;
    line-height       : 14px;
    padding           : 5px;
    overflow          : auto;
    width             : 100%;
    text-indent       : 0px;
    margin-top        : 8px;
    margin-bottom     : 8px;
}

span.key-word {
    font-size   :   10.0pt;
    font-family :   "Courier New";
    color       :   #7F0055;
    font-weight :   bold;
}

p.codeline {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    color:black;
}

p.codeline1 {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    text-indent:.5in;
}

p.codeline2 {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    text-indent:1in;
}

p.codeline3 {

    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    text-indent:1.5in;
}
&lt;/style&gt;&lt;!--Programming and Order Theory--&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/-au0TZay2iZA/UT08V27DnLI/AAAAAAAAA-o/dkO8sGlvmZo/s1600/swtail.jpg" imageanchor="1" &gt;&lt;img border="0" src="http://2.bp.blogspot.com/-au0TZay2iZA/UT08V27DnLI/AAAAAAAAA-o/dkO8sGlvmZo/s320/swtail.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Covariance, Contravariance and Order Theory&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;In this post I make the observation that covariance and contravariance in programming are what are known as &lt;a href="http://www.elegantcoding.com/2012/09/lattice-theory-for-programmers-and-non.html#Order_Duality"&gt;Order Duals&lt;/a&gt;.  I am not the first person to make this observation, however, these ideas often tend to be buried in academic research papers like "&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.33.1539"&gt;Adding Axioms to Cardelli-Wegner Subtyping&lt;/a&gt;"  by Anthony J H Simons, don’t get me wrong I love these types of papers, they give me hope and inspiration that software engineering will someday become a first class engineering citizen.  Unfortunately, these types of papers tend to be too theoretical and thus not very accessible for the average developer.  This is unfortunate as the idea of covariance and contravariance as order duals both puts these concepts into the mathematical context of order theory and possibly gives programmers some native context for order theory.  So hopefully this post will make these ideas more programmer friendly.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;I previously wrote a post about &lt;a href="http://www.elegantcoding.com/2012/09/lattice-theory-for-programmers-and-non.html"&gt;lattice theory&lt;/a&gt;, which is part of the more general order theory, where I talked about some basic order theory ideas such as &lt;a href="http://www.elegantcoding.com/2012/09/lattice-theory-for-programmers-and-non.html#Order_Duality"&gt;duality&lt;/a&gt;.   Order theory occurs quite a lot in software and programming and this is part of a series of posts to talk about those occurrences.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Covariance and contravariance receive a fair amount of attention, as they should, in software blogs and some of these posts include some interesting observations. One, perhaps slightly off topic observation, is "&lt;a href="http://apocalisp.wordpress.com/2010/10/06/liskov-substitution-principle-is-contravariance/"&gt;Liskov Substitution Principle is Contravariance&lt;/a&gt;" which is an interesting observation and interesting post if you overlook the disdainful tone towards OO.  Another more relevant post which is a nice post about "&lt;a href="http://blogs.atlassian.com/2013/01/covariance-and-contravariance-in-scala/"&gt;Covariance and Contravaiance in Scala&lt;/a&gt;" relates these ideas to category theory which is relevant especially since apparently you can think of "&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.7855"&gt;Category Theory as Coherently Constructive Lattice Theory&lt;/a&gt;", warning heavy going in that paper.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Defining Covariance and Contravariance&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;To me one of the most striking and perhaps apropos examples of order theory in software is that of covariance and contravariance which Eric Lippert defines on his &lt;a href="http://blogs.msdn.com/b/ericlippert/archive/2007/10/16/covariance-and-contravariance-in-c-part-one.aspx"&gt;blog&lt;/a&gt; as: &lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;The first thing to understand is that for any two types T and U, exactly one of the following statements is true: &lt;/p&gt;&lt;br /&gt;
&lt;ul type=disc&gt;&lt;li&gt;T is bigger than U.&lt;/li&gt;
&lt;li&gt;T is smaller than U.&lt;/li&gt;
&lt;li&gt;T is equal to U.&lt;/li&gt;
&lt;li&gt;T is not related to U. &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;p&gt;For example, consider a type hierarchy consisting of Animal, Mammal, Reptile, Giraffe, Tiger, Snake and Turtle, with the obvious relationships. (Mammal is a subclass of Animal, etc.) Mammal is a bigger type than Giraffe and smaller than Animal, and obviously equal to Mammal. But Mammal is neither bigger than, smaller than, nor equal to Reptile, it’s just different.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;He has an eleven part series on covariance and contravariance, his posts cover some C# implantation details but the ideas are generally applicable and looking at one language’s details can help with comparing and contrasting to other languages.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Wikipedia includes the following &lt;a href="http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)"&gt;definition&lt;/a&gt;, the animal example is pretty popular:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Covariant&lt;/b&gt;: converting from wider (Animals) to narrower (Cats).&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Contravariant&lt;/b&gt;: converting from narrower (Triangles) to wider (Shapes).&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Invariant&lt;/b&gt;: Not able to convert.&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;Including this is slightly redundant but this definition captures the conversion aspect and defines the relationships explicitly.  &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Covariance and Contravariance as Order Duals&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;The above are definitions that have order theory written all over them.  In fact that is pretty much a text book definition of an &lt;a href="http://en.wikipedia.org/wiki/Order_relation"&gt;order Relation&lt;/a&gt; in that it is &lt;a href="http://en.wikipedia.org/wiki/Reflexive_relation"&gt;reflexive&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Transitive_relation"&gt;transitive&lt;/a&gt;, and &lt;a href="http://en.wikipedia.org/wiki/Antisymmetric_relation"&gt;antisymmetric&lt;/a&gt;. It is reflexive since Animal = Animal, transitive since Animal &amp;le; Mammal &amp;le; Cat implies Animal &amp;le; Cat, and antisymmetric since Animal &amp;le; Mammal implies not Animal &amp;ge; Mammal and in the animal example there are cases of both comparability and incomparability as you would find in a &lt;a href="http://en.wikipedia.org/wiki/Order_relation"&gt;partial order&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;As you can see from the above definitions both sets of terms, wider/narrower or bigger/smaller, which are the same, define an order dual for comparison.  To write it more formally we will call the set C classes of various types in an OO hierarchy. So covariant would be represented by less than or equals &amp;le; and contravariant would be represented by greater than or equals &amp;ge; and a set of classes with these order relations can be written with mathematical notation as (C, &amp;le;) = (C, &amp;ge;)&lt;sup&gt;d&lt;/sup&gt; . &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Types as Sets of Fields&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;It was in researching this post that I came across the paper "&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.33.1539"&gt;Adding Axioms to Cardelli-Wegner Subtyping&lt;/a&gt;". These kinds of discoveries are one of the reasons I write these posts.  In that paper they quote another paper "&lt;a href="http://lucacardelli.name/Papers/OnUnderstanding.A4.pdf"&gt;On understanding types, data abstraction and polymorphism&lt;/a&gt;" by Luca Cardelli and Peter Wegner:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;a type A is included in, or is a subtype of another type B when all the values of type A are also values of B, that is, exactly when A, considered as a set of values, is a subset of B&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;The ideas about types and subtypes covered in these papers extend beyond which fields a class or object has, however, I thought it would be interesting and beneficial to limit the discussion to that case.  One reason is that if you take the fields of an object or class then all subtype collections of fields will be found in the &lt;a href="http://en.wikipedia.org/wiki/Powerset"&gt;powerset&lt;/a&gt; and all subtypes will be a subset relation and these can be drawn as my favorite lattice, yes I have &lt;a href="http://www.elegantcoding.com/2012/10/the-ubiquitous-patterns-of-pascals.html#Powerset_Lattice"&gt;favorite lattice&lt;/a&gt;, the &lt;a href="http://www.elegantcoding.com/2012/09/lattice-theory-for-programmers-and-non.html#Powerset_Lattice"&gt;powerset lattice&lt;/a&gt;.  Also in this case covariance and contravariance are now defined as the &lt;a href="http://www.elegantcoding.com/2012/09/lattice-theory-for-programmers-and-non.html#The_Algebraic_Structure_of_the_Powerset_Lattice"&gt;subset and superset operations on the powerset lattice&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Types as Sets of Fields in the Real World&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Now I always feel that a real example helps quite a bit so I have created a set of example classes, Scala traits actually, which illustrate the above ideas using a quasi-real-world example.  Please note that these code examples are designed for the purposes of illustrating these ideas and may contain design issues that one would not implement in the real world, but they should be close enough to bridge the conceptual gap, if you will.  Also this first example is should be applicable to dynamically typed languages that might use &lt;a href="http://en.wikipedia.org/wiki/Duck_typing"&gt;duck typing&lt;/a&gt; or &lt;a href="http://en.wikipedia.org/wiki/Structural_type_system"&gt;structural typing&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The following Scala traits define a possible domain object hierarchy that could be used to persist data to a database and render it back to a web page among other possible uses:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;br /&gt;
&lt;p class="codeline"&gt;&lt;span class="key-word"&gt;trait&lt;/span&gt; BaseDomain {&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;override&lt;/span&gt; &lt;span class="key-word"&gt;def&lt;/span&gt; equals(that: Any) : Boolean&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;override&lt;/span&gt; &lt;span class="key-word"&gt;def&lt;/span&gt; hashCode : Int&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline"&gt;&lt;span class="key-word"&gt;trait&lt;/span&gt; PersonInfo &lt;span class="key-word"&gt;extends&lt;/span&gt; BaseDomain {&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; firstName : String&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; lastName : String&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline"&gt;&lt;span class="key-word"&gt;trait&lt;/span&gt; Address &lt;span class="key-word"&gt;extends&lt;/span&gt; BaseDomain {&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; street : String&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; street2 : String&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; city : String&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; state : String&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; country : String&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; zipCode : String&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline"&gt;&lt;span class="key-word"&gt;trait&lt;/span&gt; PhoneNumber&lt;span class="key-word"&gt; extends&lt;/span&gt; BaseDomain {&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; phoneNumber : String&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; extension : String&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline"&gt;&lt;span class="key-word"&gt;trait&lt;/span&gt; Person &lt;span class="key-word"&gt;extends&lt;/span&gt; BaseDomain {&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; personInfo : PersonInfo&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; address : Address&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; phoneNumber : PhoneNumber&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;These traits yield the following field powerset lattice:&lt;/p&gt;&lt;br /&gt;
&lt;a href="http://3.bp.blogspot.com/-49ciOtdBlq4/UT08xJjq2LI/AAAAAAAAA-w/HEo652bPbCE/s1600/ExampleHierarchySetLattice.jpg" imageanchor="1" &gt;&lt;img border="0" src="http://3.bp.blogspot.com/-49ciOtdBlq4/UT08xJjq2LI/AAAAAAAAA-w/HEo652bPbCE/s320/ExampleHierarchySetLattice.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;Now suppose we would want to define a type for each of the above lattice points, which we probably would not do but there may be cases to do similar types of things in the real world.  Let’s define the following Scala traits that wrap the above domain object hierarchy elements:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;br /&gt;
&lt;p class="codeline"&gt;&lt;span class="key-word"&gt;trait&lt;/span&gt; PersonInfoTrait &lt;span class="key-word"&gt;extends&lt;/span&gt; BaseDomain {&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; personInfo : PersonInfo&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&lt;span class="key-word"&gt;trait&lt;/span&gt; AddressTrait {&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; address : Address&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&lt;span class="key-word"&gt;trait&lt;/span&gt; PhoneNumberTrait &lt;span class="key-word"&gt;extends&lt;/span&gt; BaseDomain {&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;span class="key-word"&gt;var&lt;/span&gt; phoneNumber : PhoneNumber&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&lt;span class="key-word"&gt;trait&lt;/span&gt; PersonInfoAddressTrait &lt;span class="key-word"&gt;extends&lt;/span&gt; AddressTrait &lt;span class="key-word"&gt;with&lt;/span&gt; PersonInfoTrait {&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&lt;span class="key-word"&gt;trait&lt;/span&gt; AddressPhoneNumberTrait &lt;span class="key-word"&gt;extends&lt;/span&gt; AddressTrait &lt;span class="key-word"&gt;with&lt;/span&gt; PhoneNumberTrait {&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&lt;span class="key-word"&gt;trait&lt;/span&gt; PersonInfoPhoneNumberTrait &lt;span class="key-word"&gt;extends&lt;/span&gt; PhoneNumberTrait &lt;span class="key-word"&gt;with&lt;/span&gt; PersonInfoTrait {&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&lt;span class="key-word"&gt;trait&lt;/span&gt; PersonTrait &lt;span class="key-word"&gt;extends&lt;/span&gt; PersonInfoAddressTrait &lt;span class="key-word"&gt;with&lt;/span&gt; AddressPhoneNumberTrait &lt;span class="key-word"&gt;with&lt;/span&gt; PersonInfoPhoneNumberTrait {&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Since Scala traits support multiple inheritance we can define the above type hierarchy which can be drawn as the powerset lattice that it is:&lt;/p&gt;&lt;br /&gt;
&lt;a href="http://1.bp.blogspot.com/-3eVi7PGEGMs/UT082anPXzI/AAAAAAAAA-4/KWblYS3r7Gc/s1600/ExampleHierarchyLattice.jpg" imageanchor="1" &gt;&lt;img border="0" src="http://1.bp.blogspot.com/-3eVi7PGEGMs/UT082anPXzI/AAAAAAAAA-4/KWblYS3r7Gc/s320/ExampleHierarchyLattice.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;p&gt;Again we can see covariant and contravariant types defined on this lattice and each relation is actually the subset superset relation on fields.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;I feel the basic observations and the above examples on order duals and covariance and contravariance make the ideas pretty strait forward for field set context.  In writing this I delved into a number of papers, adding some of them to my "to read list", on Types in programming and Type Theory and I feel there are probably some deeper insights and implications of all this.  &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/Nwr-24RBRN4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/Nwr-24RBRN4/programming-and-order-theory.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-au0TZay2iZA/UT08V27DnLI/AAAAAAAAA-o/dkO8sGlvmZo/s72-c/swtail.jpg" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://www.elegantcoding.com/2013/03/programming-and-order-theory.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-7209056239108093739</guid><pubDate>Tue, 04 Dec 2012 21:53:00 +0000</pubDate><atom:updated>2012-12-04T17:01:34.577-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Morphology</category><category domain="http://www.blogger.com/atom/ns#">Graph Theory</category><category domain="http://www.blogger.com/atom/ns#">Data Science</category><category domain="http://www.blogger.com/atom/ns#">Semantics</category><category domain="http://www.blogger.com/atom/ns#">Vector Space Model</category><category domain="http://www.blogger.com/atom/ns#">Probability Theory</category><title>Data Science DC: Implicit Sentiment Mining in Twitter Streams</title><description>&lt;h2&gt;Summary and more&lt;/h2&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-NVtp7OIVdz8/ULwN3pl2K1I/AAAAAAAAA90/7KZ4TWzcKks/s1600/IMG_1879.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="300" width="400" src="http://3.bp.blogspot.com/-NVtp7OIVdz8/ULwN3pl2K1I/AAAAAAAAA90/7KZ4TWzcKks/s400/IMG_1879.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;style&gt;
blockquote.quote {
   border-bottom: #ddd 1px dotted;
   border-left: #ddd 1px dotted;
   padding-bottom: 0.6em;
   font-style: italic;
   font-family: calibri, tahoma, arial, sans-serif;
   margin: 1em 10% 1em 0px;
   min-height: 40px;
   padding-left: 3.8em;
   padding-right: 1em;
   background: url(http://4.bp.blogspot.com/-WkhuNlv2j88/TjXlBh6SySI/AAAAAAAAAN0/O_G2Z8YdMk8/s320/blockquote.white.png) #f0f0f0 no-repeat 4px top;
   color: #474747;
   border-top: #ddd 1px dotted;
   border-right: #ddd 1px dotted;
   padding-top: 0.6em
}

blockquote.paraphrase {
   border-bottom: #ddd 1px dotted;
   border-left: #ddd 1px dotted;
   padding-bottom: 0.6em;
   font-style: italic;
   font-family: calibri, tahoma, arial, sans-serif;
   margin: 1em 10% 1em 0px;
   min-height: 40px;
   padding-left: 3.8em;
   padding-right: 1em;
   background: #f0f0f0 no-repeat 4px top;
   color: #474747;
   border-top: #ddd 1px dotted;
   border-right: #ddd 1px dotted;
   padding-top: 0.6em
}

&lt;/style&gt;&lt;!-- Data Science DC: Implicit Sentiment Mining in Twitter Streams --&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;I have been attending the &lt;a href="http://www.meetup.com/Data-Science-DC/"&gt;Data Science DC meetup&lt;/a&gt; pretty regularly as it’s an interesting meetup often with quite good talks, the most recent was a very interesting presentation called "&lt;a href="http://www.meetup.com/Data-Science-DC/events/75041762/"&gt;Implicit Sentiment Mining in Twitter Streams&lt;/a&gt;" by Maksim (Max) Tsvetovat.  He discussed number of ideas that relate to semantic discovery which are of interest to me as I am doing research into related areas including applying semantic ideas to &lt;a href="http://www.elegantcoding.com/2012/07/framework-for-software-system-naming.html"&gt;software naming&lt;/a&gt;.  So I thought it would be nice to do a little review augmented with links to references that were made and additional ones that I found in the course of researching what was discussed.  I am also including some more introductory links and material as it helps me and hopefully others who are not fully versed in the world of &lt;a href="http://en.wikipedia.org/wiki/Natural_language_processing"&gt;NLP&lt;/a&gt;.  The meetup was held at Google’s downtown DC office, the irony being that the meetup was about Twitter was pointed out humorously by David Lieber of Google as he introduced Harlan for the usual Data Science DC Harlan-Mark introduction.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Max starts by talking about a system that his team at George Mason built to map sentiment during the 2012 presidential election which was then used to mine sentiment from current news, in this case the media coverage of recent conflict in Gaza. This work has yielded an algorithm to show media bias.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;He points out that there are a number of things people are trying to mine and predict using twitter, the example he cites is the wired article "&lt;a href="http://www.wired.com/wiredscience/2010/10/twitter-crystal-ball/"&gt;Twitter Can Predict the Stock Market&lt;/a&gt;".  He sees twitter not as a social network but as a wire, an analogue of physical broadcast ether.  It’s not a media carrier but a wire that other things go into with a real-time nature where things can change very quickly.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;He moves on to Sentiment analysis, mentioning a paper called "&lt;a href="http://www.customerthink.com/blog/sentiment_analysis_hard_but_worth_it"&gt;Sentiment Analysis is Hard but Worth it&lt;/a&gt;" by Michelle deHaaff.   He contrasts this title with what he describes as an easy "old school" sentiment analysis.  It's where you want to know what people think, so you take a corpus of words and a stream of data and you look for occurrences of good words vs. bad words.  You use an average or apply some formula to create a measure of sentiment, which is a naïve approach that might be used in a CS curriculum, but it does not really work in practice due to the complexity of human emotions and language that can have double and triple entendres.  He refers to a computational linguistics paper about "She said" jokes, which I believe is this "&lt;a href="http://people.cs.umass.edu/~brun/pubs/pubs/Kiddon11.pdf"&gt;That’s What She Said: Double Entendre Identification&lt;/a&gt;".  Some examples he gives of possibly deceptive and/or ambiguous statements in terms of sentiment are:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;ul&gt;&lt;li&gt;This restaurant would deserve highest praise if you were a cockroach  (a real Yelp review ;-)&lt;/li&gt;
&lt;li&gt;This is only a flesh wound!  (Monty Python and the Holy Grail)&lt;/li&gt;
&lt;li&gt;This concert was f**ing awesome!&lt;/li&gt;
&lt;li&gt;My car just got rear-ended! F**ing awesome!&lt;/li&gt;
&lt;li&gt;A rape is a gift from God  (he lost! Good ;-)&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;He summarizes these ideas which are challenges to machines learning these things:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;ul&gt;&lt;li&gt;Ambiguity is rampant&lt;/li&gt;
&lt;li&gt;Context matters&lt;/li&gt;
&lt;li&gt;Homonyms are everywhere&lt;/li&gt;
&lt;li&gt;Neutral words become charged as discourse changes, charged words lose their meaning&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;The field of &lt;a href="http://en.wikipedia.org/wiki/Computational_linguistics"&gt;computational linguistics&lt;/a&gt; has developed a number of techniques to handle some the complexity issues above by parsing text using &lt;a href="http://en.wikipedia.org/wiki/Part_of_speech"&gt;POS (parts-of-speech)&lt;/a&gt; identification which helps with homonyms and some ambiguity. He gives the following example:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;Create rules with amplifier words and inverter words:&lt;/p&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;This concert (np) was (v) f**ing (AMP) awesome (+1) = +2&lt;/li&gt;
&lt;li&gt;But the opening act (np) was (v) not (INV) great (+1) = -1&lt;/li&gt;
&lt;li&gt;My car (np) got (v) rear-ended (v)! F**ing (AMP) awesome (+1) = +2??&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;Here he introduces two concepts which modify the sentiment, which might fall under the concept of sentiment "polarity classification" or detection.  One idea is of an amplifier (AMP) which makes the sentiment stronger and an inverter (INV) which creates an opposite sentiment.  I found this idea of "sentiment modification" intriguing and did a little searching and came across a paper called "&lt;a href="http://www.win.tue.nl/~mpechen/projects/pdfs/Tromp2011.pdf"&gt;Multilingual Sentiment Analysis on Social Media&lt;/a&gt;" which describes these ideas [page 12] and a few more including an attenuator which is the opposite of an amplifier.  It also describes some other modifiers that control sentiment flow in the text, pretty interesting concepts, actually the paper looks quite interesting, I only read the first few pages.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;He cites a paper "&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.125.8012"&gt;Cognitive map dimensions of the human value system extracted from the natural language&lt;/a&gt;" by Alexei Samsonovich and Giorgio Ascoli.  This paper defines the following dimensions:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;ul&gt;&lt;li&gt;Valence (good vs. bad)&lt;/li&gt;
&lt;li&gt;Relevance (me vs. others)&lt;/li&gt;
&lt;li&gt;Immediacy (now/later) &lt;/li&gt;
&lt;li&gt;Certainty (definitely/maybe)&lt;/li&gt;
&lt;li&gt;And about 9 more less-significant dimensions&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;One result which is quite interesting is that these dimensions are pretty much language independent. While searching this out I also came across "&lt;a href="http://binf.gmu.edu/~asamsono/papers/sams08d.pdf"&gt;Computing Semantics of Preference with a Semantic Cognitive Map of Natural Language: Application to Mood Sensing from Text&lt;/a&gt;" and "&lt;a href="http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0010921"&gt;Principal Semantic Components of Language and the Measurement of Meaning&lt;/a&gt;" by the same authors.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://www.css.gmu.edu/~maksim/publications.php"&gt;Max’s work&lt;/a&gt; seems to run pretty heavy in social networking theory, which includes an Orielly book: &lt;u&gt;Social Network Analysis for Startups&lt;/u&gt;.  He also mentions having quite a bit of exposure to social psychology, consisting of "half a degree" as he put it, which also shows in his work.  He mentions a couple of human psychological aspects, somewhat NLP related but also somewhat divergent, these are the idea of mirroring and marker words.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Mirroring is the idea that when people interact, if the interaction is positive, the example that was given was a successful flirtation, then one person will mimic the others body language.  He extends this concept to the language used by various parties, in this case the tweets they emit.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Marker words are unique words an individual speaker tends to use. The idea can also extend to common expression between speakers. His description of marker words is:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;ul&gt;&lt;li&gt;All speakers have some words and expressions in common (e.g. conservative, liberal, party designation, etc)&lt;/li&gt;
&lt;li&gt;However, everyone has a set of trademark words and expressions that make him unique.&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;He extends this idea to the idea of linguistic mannerisms he cites are calling health care "Obama care" would mark you as conservative, calling Hamas "freedom fighters" would mark you as siding with Hamas.  Which he uses to observe mirroring:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;ul&gt;&lt;li&gt;We detect marker words and expressions in social media speech and compute sentiment by observing and counting mirrored phrases&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;The next part of the talk gets into the details of how to do the analysis of the raw text.   One idea that he talks about is text cleaning pointing out that Twitter data is very noisy.  The text is cleaned in part using &lt;a href="http://en.wikipedia.org/wiki/Stop_words"&gt;stop words&lt;/a&gt; which are words that are common and have little lexical meaning, some examples are {a, on, the, to}. His full list which he pilfered from &lt;a href="http://wordnet.princeton.edu/"&gt;WordNet&lt;/a&gt; is &lt;a href="https://raw.github.com/maksim2042/DC_DataScience_Meetup/master/english_stoplist.py"&gt;here&lt;/a&gt;.  &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Another important NLP concept is &lt;a href="http://en.wikipedia.org/wiki/Stemming"&gt;stemming&lt;/a&gt; a &lt;a href="http://en.wikipedia.org/wiki/Linguistic_morphology"&gt;linguistic morphology&lt;/a&gt; related concept, given by his example:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;ul&gt;&lt;li&gt;Stemming identifies root of a word, stripping away: Suffixes, prefixes, verb tense, etc&lt;/li&gt;
&lt;li&gt;"stemmer", "stemming", "stemmed" -&amp;gt;&amp;gt; "stem"&lt;/li&gt;
&lt;li&gt;"go","going","gone" -&amp;gt;&amp;gt; "go" &lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;He takes his stemming code from the &lt;a href="https://github.com/nltk/nltk"&gt;python project&lt;/a&gt;: &lt;a href="http://nltk.org/data.html"&gt;Natural Language Toolkit&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Since the data being mined is coming from the internet which is used by people all over the globe, language detection is important. While the semantic concepts as outlined in the above work by Samsonovich and Ascoli may be language independent, the stemming and stop words are not, these techniques apply to most other languages but the specific tools and data do not, so the goal is to filter out other languages.  He sums this up as:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;ul&gt;&lt;li&gt;Language identification is pretty easy...&lt;/li&gt;
&lt;li&gt;Every language has a characteristic distribution of tri-grams (3-letter sequences);&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;E.g. English is heavy on "the" trigram&lt;/li&gt;
&lt;/ul&gt;&lt;li&gt;Use open-source library "guess-language"&lt;/li&gt;&lt;br /&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;p&gt;The Python library he uses is &lt;a href="http://pypi.python.org/pypi/guess-language"&gt;guess-language&lt;/a&gt; which is based on some other implementations.  There is also a java library: &lt;a href="http://code.google.com/p/language-detection/"&gt;language-detection&lt;/a&gt; on Google code which was written by &lt;a href="http://shuyo.wordpress.com/"&gt;Nakatani Shuyo&lt;/a&gt;.  All of these use a &lt;a href="http://en.wikipedia.org/wiki/Trigram"&gt;trigram&lt;/a&gt; approach to language detection which uses an &lt;a href="http://en.wikipedia.org/wiki/N-gram"&gt;n-gram&lt;/a&gt; of characters and their probabilities to identify languages this approach is described in "&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.53.9367"&gt;N-Gram-Based Text Categorization&lt;/a&gt;".&lt;/p&gt;&lt;p&gt;After the text is filtered to English, cleaned, and stemmed this leaves roots of big words, words that carry more meaning.  These are used to create term vectors.  Term vectors are a way to map documents into a &lt;a href="http://en.wikipedia.org/wiki/Vector_space"&gt;vector space&lt;/a&gt;, this is known as the &lt;a href="http://en.wikipedia.org/wiki/Vector_space_model"&gt;Vector Space Model (VSM)&lt;/a&gt;, and is a fairly common approach, it is used in Lucene and its derivatives like Solr and ElasticSearch.  Term vectors can be built with different levels of granularity, generally in Lucene this done at the document level but it can also be done at the sentence level.&lt;/p&gt;&lt;p&gt;I was hoping to better describe what he is doing with the term vectors and how they relate to the graphs that he creates but I am unclear as to whether his term vectors are built at the document (tweet) level or sentence level, I believe it is the sentence level as he refers to a common word in two sentences being the intersection of two different term vectors.  He then starts talking about bigrams and linking speakers to bigrams, I am not sure how these relate to the term vectors.  In this case the bigrams, n-grams order 2, refer to words as opposed to the trigrams mentioned above for language detection which were for letters.&lt;/p&gt;&lt;p&gt;Regardless of how they are created the system he describes uses bigrams of words linked to speakers which form a two-mode network, a concept that I was unfamiliar with which is described in "&lt;a href="http://www.steveborgatti.com/papers/2modeconcepts.pdf"&gt;2-Mode Concepts in Social Network Analysis&lt;/a&gt;".  This two-mode graph technique drives the final graphs for the sets, in the cases of {Santorum, Gingrich, Romney} and {IDF, Hamas}.   He also points out by counting of the occurrence of bigrams the most common bigrams give the nature of discourse structure.&lt;/p&gt;&lt;p&gt;Counting bigrams enables a technique to throw out bigrams that only occur once in a certain time period, purging single occurrences cuts out the noise.  The number of co-occurrences are &lt;a href="http://en.wikipedia.org/wiki/Power_law"&gt;power law distributed&lt;/a&gt; which reduces this from a big data problem to something that runs on an Amazon micro instances.  Also dates were recorded for each occurrence which allowed noncurrent topics to be purged from the current data over time.&lt;/p&gt;&lt;p&gt;The algorithm to detect media bias, which he warned is naïve, yielded:&lt;/p&gt;&lt;table border="1" cellspacing="0" cellpadding="5"&gt;&lt;tr&gt;&lt;td&gt;NPR&lt;/td&gt;&lt;td&gt;58% favorable to IDF&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Aljazeera&lt;/td&gt;&lt;td&gt;53% favorable to IDF&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;CNN&lt;/td&gt;&lt;td&gt;59% favorable to IDF&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;BBC&lt;/td&gt;&lt;td&gt;54% favorable to IDF&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;FOX&lt;/td&gt;&lt;td&gt;51% favorable to Hamas&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;CNBC&lt;/td&gt;&lt;td&gt;60% favorable to IDF&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;p&gt;I hope others find this useful, I sure learned a lot digging into the presentation and researching the ideas presented.  This post ran longer than I had originally thought.  I attribute this to the broad subject area that this talk covered.  Semantics is a complex and deep topic with many facets and approaches, I was hoping to throw some &lt;a href="http://www.elegantcoding.com/2012/09/lattice-theory-for-programmers-and-non.html"&gt;order theory&lt;/a&gt; related ideas in as well, as they are quite applicable, but that will have to wait for another time.&lt;/p&gt;&lt;h2&gt;References&lt;/h2&gt;&lt;p&gt;The following references are a mix of works referenced in the presentation and that I came across while writing this, many are linked above but not all are:&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.meetup.com/Data-Science-DC/"&gt;Data Science DC meetup&lt;/a&gt; &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.meetup.com/Data-Science-DC/events/75041762/"&gt;Data Science DC:Implicit Sentiment Mining in Twitter Streams&lt;/a&gt; &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.meetup.com/Data-Science-DC/files/"&gt;Event Audio&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="https://github.com/maksim2042/DC_DataScience_Meetup"&gt;Code and Slides&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.css.gmu.edu/~maksim/publications.php"&gt;Maksim Tsvetovat Publications&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.elegantcoding.com/2012/05/math-of-search-and-similarity.html"&gt;The Math of Search and Similarity, Part One: Lucene, the Boolean Model, tf*idf, and the Vector Space Model&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.customerthink.com/blog/sentiment_analysis_hard_but_worth_it"&gt;Sentiment Analysis is Hard but Worth it&lt;/a&gt; by Michelle deHaaff.&lt;/p&gt;&lt;p&gt;&lt;a href="http://people.cs.umass.edu/~brun/pubs/pubs/Kiddon11.pdf"&gt;That’s What She Said: Double Entendre Identification&lt;/a&gt; by Chloe Kiddon and Yuriy Brun&lt;/p&gt;&lt;p&gt;&lt;a href="http://wordnet.princeton.edu/"&gt;WordNet&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://nlp.stanford.edu/"&gt;Stanford NLP&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://nltk.org/data.html"&gt;Natural Language Toolkit&lt;/a&gt;, &lt;a href="http://github.com/nltk/nltk"&gt;github&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.win.tue.nl/~mpechen/projects/pdfs/Tromp2011.pdf"&gt;Multilingual Sentiment Analysis on Social Media&lt;/a&gt; by Erik Tromp&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.cs.cornell.edu/home/llee/omsa/omsa.pdf"&gt;Opinion mining and sentiment analysis&lt;/a&gt; by Bo Pang and Lillian Lee&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.csc.villanova.edu/~tway/publications/IKE7710_Carpenter_Way.pdf"&gt;Tracking Sentiment Analysis through Twitter&lt;/a&gt; by Thomas Carpenter and Thomas Way&lt;/p&gt;&lt;p&gt;&lt;a href="http://homepage.cs.uiowa.edu/~ymejova/publications/CompsYelenaMejova.pdf"&gt;Sentiment Analysis: An Overview&lt;/a&gt; by Yelena Mejova&lt;/p&gt;&lt;p&gt;&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.53.9367"&gt;N-Gram-Based Text Categorization&lt;/a&gt; (1994) by William B. Cavnar , John M. Trenkle&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.steveborgatti.com/papers/2modeconcepts.pdf"&gt;2-Mode Concepts in Social Network Analysis&lt;/a&gt; by Stephen P. Borgatti&lt;/p&gt;&lt;p&gt;&lt;a href="http://jponnela.com/web_documents/twomode.pdf"&gt;Basic notions for the analysis of large two-mode networks&lt;/a&gt; by Matthieu Latapy, Clemence Magnien, and Nathalie Del Vecchio&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/LaWJyQSCXeY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/LaWJyQSCXeY/data-science-dc-implicit-sentiment.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-NVtp7OIVdz8/ULwN3pl2K1I/AAAAAAAAA90/7KZ4TWzcKks/s72-c/IMG_1879.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/12/data-science-dc-implicit-sentiment.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-9010067447037054615</guid><pubDate>Mon, 22 Oct 2012 18:39:00 +0000</pubDate><atom:updated>2012-10-22T21:23:25.917-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Scala</category><category domain="http://www.blogger.com/atom/ns#">Math</category><category domain="http://www.blogger.com/atom/ns#">Number Theory</category><category domain="http://www.blogger.com/atom/ns#">Combinatorics</category><category domain="http://www.blogger.com/atom/ns#">Clojure</category><title>The Math of the First Scala Assignment</title><description>&lt;h2&gt;Math and Scala with a Little Bit of Clojure&lt;/h2&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-ZH2ftp5o78M/UISoJ894ZdI/AAAAAAAAA8w/GLj9bo-fHRI/s1600/crater.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="289" width="400" src="http://2.bp.blogspot.com/-ZH2ftp5o78M/UISoJ894ZdI/AAAAAAAAA8w/GLj9bo-fHRI/s400/crater.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;style&gt;
div.source-code {
    font-family       : Andale Mono, Lucida Console, Monaco, fixed, monospace;
    color             : #000;
    background-color  : #eee;
    font-size         : 12px;
    border            : 1px dashed #999999;
    line-height       : 14px;
    padding           : 5px;
    overflow          : auto;
    width             : 100%;
    text-indent       : 0px;
    margin-top        : 8px;
    margin-bottom     : 8px;
}

p.codeline {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    color:black;
}

p.codeline1 {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    text-indent:.5in;
    color:black;
}

p.codeline2 {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    text-indent:1in;
    color:black;
}

p.codeline3 {

    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    text-indent:1.5in;
    color:black;
}
&lt;/style&gt;&lt;!--The Math of the First Scala Assignment--&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;Martin Odersky is teaching &lt;a href="https://www.coursera.org/course/progfun"&gt;Functional Programming Principles in Scala&lt;/a&gt; on Coursera and I attempted to complete this course, I completed the first assignment on recursion before the hard deadline which was hard given my work schedule at the time, however, I decided not to submit it, I remembered how much I hate school, or at least being a student in a school even a virtual one, I have my own timeline and my own interests.  While doing the problems I realized, and I know this is not a major revelation, that these first three problems are set in the context of math.  However, some of that math may not be immediately obvious to everyone so I thought it would make a nice post.  I was originally going to publish my solutions in this post, after the hard deadline of course, but there was recently some unpleasantness about publishing solutions and cheating and it seems that it is still possibly a violation of the honor code.  I feel having some code for two of the problems increases the quality of this posting so I will provide my examples for those solutions in Clojure, the non solution code will be in Scala so it’s now a hybrid posting.  Also the ideas for this post forced me to finally write my previous post on &lt;a href="http://www.elegantcoding.com/2012/10/the-ubiquitous-patterns-of-pascals.html"&gt;Pascal’s Triangle&lt;/a&gt;, which this post will draw on.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Exercise 1: Pascal’s Triangle&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;The first problem is to recursively compute a binomial coefficient within Pascal’s triangle, this is fairly trivial if you have exposure to &lt;a href="http://en.wikipedia.org/wiki/Recurrence_relation"&gt;recurrence relations&lt;/a&gt; and recognize it as such, it is expressed as follows:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-1ADuIk4S9Xg/UISWmfaN0QI/AAAAAAAAA44/cUMKsilewnc/s1600/Pascal%2527s%2BIdentity.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="240" src="http://1.bp.blogspot.com/-1ADuIk4S9Xg/UISWmfaN0QI/AAAAAAAAA44/cUMKsilewnc/s400/Pascal%2527s%2BIdentity.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;Some other common recurrence relations that are popular in CS educational circles include, &lt;a href="http://en.wikipedia.org/wiki/Fibonacci_number"&gt;Fibonacci numbers&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Triangular_number"&gt;triangular numbers&lt;/a&gt; and of course the &lt;a href="http://en.wikipedia.org/wiki/Factorial"&gt;factorial function&lt;/a&gt; these are expressed as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-1cQ2TkNiDow/UISWyxz6kYI/AAAAAAAAA5E/znGRXzKEul4/s1600/Fib.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="14" width="133" src="http://4.bp.blogspot.com/-1cQ2TkNiDow/UISWyxz6kYI/AAAAAAAAA5E/znGRXzKEul4/s400/Fib.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-xM0ZLwWwI4o/UISW6k663uI/AAAAAAAAA5Q/aSL5IBq6yvw/s1600/Triangualar%2BNumbers.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="14" width="105" src="http://3.bp.blogspot.com/-xM0ZLwWwI4o/UISW6k663uI/AAAAAAAAA5Q/aSL5IBq6yvw/s400/Triangualar%2BNumbers.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-FAzCO-F982Y/UISXDHGk1XI/AAAAAAAAA5c/1bsedcDJrCA/s1600/factorial.2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="14" width="170" src="http://3.bp.blogspot.com/-FAzCO-F982Y/UISXDHGk1XI/AAAAAAAAA5c/1bsedcDJrCA/s400/factorial.2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;I chose a term based representation of the factorial function over the more traditional:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Hq5GpnEExiA/UISXKlPuqUI/AAAAAAAAA5o/3AoXNDKLDFE/s1600/factorial.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="101" src="http://3.bp.blogspot.com/-Hq5GpnEExiA/UISXKlPuqUI/AAAAAAAAA5o/3AoXNDKLDFE/s400/factorial.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;These can be implemented recursively in Scala as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&lt;b&gt;def&lt;/b&gt; fibonacci(n : Int) : Long = {&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;b&gt;if&lt;/b&gt;(n &amp;lt;= 1)&lt;/p&gt;&lt;p class="codeline2"&gt;1&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/p&gt;&lt;p class="codeline2"&gt;fibonacci(n - 1) + fibonacci(n - 2)  &lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&lt;b&gt;def&lt;/b&gt; triangularNumber(n : Int) : Long = {&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;b&gt;if&lt;/b&gt;(n &amp;lt;= 1)&lt;/p&gt;&lt;p class="codeline2"&gt;1&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/p&gt;&lt;p class="codeline2"&gt;n + triangularNumber(n - 1)  &lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&lt;b&gt;def&lt;/b&gt; factorial(n : Int) : Long = {&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;b&gt;if&lt;/b&gt;(n &amp;lt;= 1)&lt;/p&gt;&lt;p class="codeline2"&gt;1&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;b&gt;else&lt;/b&gt; &lt;/p&gt;&lt;p class="codeline2"&gt;n * factorial(n - 1)  &lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;All of the above examples are inefficient and in many cases considered to be naïve solutions.  The Fibonacci example is terrible as it incurs an exponential number of function calls, fortunately there ways to optimize these algorithms.  One potential approach would be to use the closed formulas for &lt;a href="http://www.elegantcoding.com/2011/07/triangles-triangular-numbers-and.html"&gt;triangular numbers&lt;/a&gt; or Binet’s formula for &lt;a href="http://www.elegantcoding.com/2012/02/fibonacci-math-of-agile.html"&gt;Fibonacci numbers&lt;/a&gt;.  I will ignore those as I have covered them previously and they are not what I am going for here.  I want to look at two optimizations, one is a way is the use of the tail call optimization and the second is to reduce the number of function calls.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Tail_call"&gt;Tail call optimization&lt;/a&gt;, put simply, is a mechanism that allows certain recursive functions that are written in a tail recursive form to be converted to iteration when they are executed.  It is my understanding that this requires some extra work in the JVM, at least in the older versions, I think 7 and 8 makes changes for this.  So this extra work requires some special syntax beyond simply putting your code in tail recursive form, Lisp and Scheme for example do this automatically, in Scala this requires the @tailrec annotation, using this form our functions get converted as follows:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p class="codeline"&gt;&lt;b&gt;def&lt;/b&gt; triangularNumber(n:Int) : Long = {&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline1"&gt;@tailrec&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;b&gt;def&lt;/b&gt; triangularNumberAcc(acc: Long, n: Int): Long = {&lt;/p&gt;&lt;p class="codeline2"&gt;&lt;b&gt;if&lt;/b&gt; (n &amp;lt;= 1) acc&lt;/p&gt;&lt;p class="codeline2"&gt;&lt;b&gt;else&lt;/b&gt; triangularNumberAcc(n + acc, n - 1)&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline1"&gt;triangularNumberAcc(1, n)&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&lt;b&gt;def&lt;/b&gt; factorial(n:Int) : Long = {&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline1"&gt;@tailrec&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;b&gt;def&lt;/b&gt; factorialAcc(acc: Long, n: Int): Long = {&lt;/p&gt;&lt;p class="codeline2"&gt;&lt;b&gt;if&lt;/b&gt; (n &amp;lt;= 1) acc&lt;/p&gt;&lt;p class="codeline2"&gt;&lt;b&gt;else&lt;/b&gt; factorialAcc(n * acc, n - 1)&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline1"&gt;factorialAcc(1, n)&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;As you can see the tail recursive forms take on an accumulator parameter.  The other optimization  I mentioned was to get rid of the extra function call for the Fibonacci, this is done by calculating the series using a second accumulator parameter, so that term Fn and term Fn+1 are passed as accumulator parameters.   This following example came out really nice as the base function sequenceGenerator can also generate the &lt;a href="http://en.wikipedia.org/wiki/Lucas_number"&gt;Lucas&lt;/a&gt; numbers if seeded appropriately:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p class="codeline"&gt;@tailrec&lt;/p&gt;&lt;p class="codeline"&gt;&lt;b&gt;def&lt;/b&gt; sequenceGenerator(n: Int, t0: Long, t1: Long): Long = {&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;b&gt;if&lt;/b&gt;(n &amp;lt;= 0)&lt;/p&gt;&lt;p class="codeline2"&gt;t0&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/p&gt;&lt;p class="codeline2"&gt;sequenceGenerator(n - 1, t1, t0 + t1)&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&lt;b&gt;def&lt;/b&gt; fibonacci(n : Int) : Long = {&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline1"&gt;sequenceGenerator(n, 0, 1)&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&lt;b&gt;def&lt;/b&gt; lucas(n : Int) : Long = {&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline1"&gt;sequenceGenerator(n, 2, 1)&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Going back to Pascal’s Identity if we look at the example from my last post:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-xrz1usQRW-0/UISXdc9g4MI/AAAAAAAAA6A/kx2WyQ6pQpM/s1600/bc%25285%252C3%2529.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="184" src="http://4.bp.blogspot.com/-xrz1usQRW-0/UISXdc9g4MI/AAAAAAAAA6A/kx2WyQ6pQpM/s400/bc%25285%252C3%2529.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;We can represent the values that get calculated for this example visually as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Ros5iK_oDig/UISXkkeGRsI/AAAAAAAAA6M/oHlQrj9qKrM/s1600/pascalsTriangleAddLatticeCoefficientScala.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="400" src="http://3.bp.blogspot.com/-Ros5iK_oDig/UISXkkeGRsI/AAAAAAAAA6M/oHlQrj9qKrM/s400/pascalsTriangleAddLatticeCoefficientScala.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;This gives some sense of how the recursive solution moves up through the triangle to sum the values, the example code, in Clojure, the naïve solution is:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p class="codeline"&gt;(defn bc [r c]&lt;/p&gt;&lt;p class="codeline1"&gt;(if (or (&amp;lt;= c 0) (&amp;lt;= r 0) (&amp;lt;= r c))&lt;/p&gt;&lt;p class="codeline2"&gt;1&lt;/p&gt;&lt;p class="codeline2"&gt;(+ (bc (dec r) (dec c)) (bc (dec r) c))&lt;/p&gt;&lt;p class="codeline1"&gt;)&lt;/p&gt;&lt;p class="codeline"&gt;)&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Additionally the Clojure version of our Binomial Coefficient can be similarly single call/tail call optimized:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p class="codeline"&gt;(defn bc [rr cc]&lt;/p&gt;&lt;p class="codeline1"&gt;(loop [r rr c cc acc 1]&lt;/p&gt;&lt;p class="codeline2"&gt;(if (or (= c 0) (= r 0) (= r c))&lt;/p&gt;&lt;p class="codeline3"&gt;acc&lt;/p&gt;&lt;p class="codeline3"&gt;(recur (dec r) (dec c) (/ (* acc r) c)))&lt;/p&gt;&lt;p class="codeline1"&gt;)&lt;/p&gt;&lt;p class="codeline"&gt;)&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;As mentioned most of these have closed form formulas like Binet’s formula for Fibonacci numbers.  Also if we take the formula for the binomial coefficient and since r &amp;ge; c we can get the following cancelation of c!:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-KXhu2wqVtOY/UISXwYbfqhI/AAAAAAAAA6Y/x7vyLwGdW7k/s1600/Binomial-cancel.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="32" width="400" src="http://3.bp.blogspot.com/-KXhu2wqVtOY/UISXwYbfqhI/AAAAAAAAA6Y/x7vyLwGdW7k/s400/Binomial-cancel.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Which can be implemented in Scala, using the factorial function defined above, as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p class="codeline"&gt;&lt;b&gt;def&lt;/b&gt; partialFactorial(s : Int, e: Int) : Long = {&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline1"&gt;@tailrec&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;b&gt;def&lt;/b&gt; partialFactorialAcc(s : Int, e: Int, acc: Long): Long = {&lt;/p&gt;&lt;p class="codeline2"&gt;&lt;b&gt;if&lt;/b&gt;(e &amp;gt;= s) acc&lt;/p&gt;&lt;p class="codeline2"&gt;&lt;b&gt;else&lt;/b&gt;  partialFactorialAcc(s - 1, e, s * acc)&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline1"&gt;partialFactorialAcc(e, s, e)&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;p class="codeline"&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="codeline"&gt;&lt;b&gt;def&lt;/b&gt; binomialCoefficient(r : Int , c : Int) : Long = {&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;b&gt;if&lt;/b&gt;((c &amp;lt;= 0) || (r &amp;lt;= 0) || (r &amp;lt;= c))&lt;/p&gt;&lt;p class="codeline2"&gt;1&lt;/p&gt;&lt;p class="codeline1"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/p&gt;&lt;p class="codeline2"&gt;partialFactorial(r, c+1)/factorial(r-c)&lt;/p&gt;&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Both of these two “optimized” solutions for the binomial coefficient introduce division which can be problematic due to remainders and floating point rounding errors this would also be the case for the closed form approaches to calculating these numbers.  There is a variant for the binomial coefficient that is discussed in a &lt;a href=""&gt;paper&lt;/a&gt; which uses a &lt;a href="http://en.wikipedia.org/wiki/Greatest_common_divisor"&gt;gcd&lt;/a&gt; calculation to try to deal with these issues.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Another interesting observation in terms of how values are calculated between the naïve recursive approach and the tail recursive accumulator approach is that there seems to be some &lt;a href="http://www.elegantcoding.com/2012/09/lattice-theory-for-programmers-and-non.html#Order_Duality"&gt;order duality&lt;/a&gt; on how the calculations are performed.  In the naïve approaches the recursion goes to the bottom and accumulates as it comes back up in the call stack.  In the accumulator versions the values are accumulated on the way down and returned from the bottom of the call stack.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Exercise 2: Parentheses Balancing&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;The next problem is not so much about the solution as it is about the combinatorial properties of the input values.  The problem was to take a string and determine if the parenthesis in the string matched, this is also probably pretty common CS educational fodder.  So there will be no code for this problem.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The math that we are interested in here relates to the &lt;a href="http://www.elegantcoding.com/2012/10/the-ubiquitous-patterns-of-pascals.html#Central_Binomial_Coefficient_Symmetry"&gt;central binomial coefficient&lt;/a&gt;, it is a number sequence known as the &lt;a href="http://en.wikipedia.org/wiki/Catalan_number"&gt;Catalan numbers&lt;/a&gt; after the Belgian mathematician &lt;a href="http://en.wikipedia.org/wiki/Eug%C3%A8ne_Charles_Catalan"&gt;Eugène Charles Catalan&lt;/a&gt;.  It is given by the following equations:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-YVfzo3E2IlI/UISX8duaFiI/AAAAAAAAA6k/ZH-GmkRd3zk/s1600/Catalan-eq.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="400" src="http://2.bp.blogspot.com/-YVfzo3E2IlI/UISX8duaFiI/AAAAAAAAA6k/ZH-GmkRd3zk/s400/Catalan-eq.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-xa8GWxYdujM/UISYBf7uPzI/AAAAAAAAA6w/gAm2npSCiqM/s1600/Catalan-recur.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="48" width="307" src="http://2.bp.blogspot.com/-xa8GWxYdujM/UISYBf7uPzI/AAAAAAAAA6w/gAm2npSCiqM/s400/Catalan-recur.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;In the original problem the text containing parentheses was the input, since a parenthesis counting algorithm would need to filter the text or implement some type of get next parenthesis function, we will assume that we have a string that only has only parenthesis.  First thing to notice that valid input strings need to be of even length.  Each term of the Catalan numbers describes how many possible sets of matching parenthesis you can have for each number n.  The table below illustrates the first five possibilities:&lt;/p&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="2"&gt;&lt;tr&gt;   &lt;td width="55"  valign="bottom" align="center"&gt;   &lt;p&gt;n&lt;/p&gt;&lt;/td&gt;   &lt;td width="66"  valign="bottom" align="center"&gt;   &lt;p&gt;C&lt;sub&gt;n&lt;/sub&gt;&lt;/p&gt;&lt;/td&gt;   &lt;td width="294" valign="bottom" align="center"&gt;   &lt;p&gt;Matching parentheses set&lt;/p&gt;&lt;/td&gt;   &lt;td width="95"  valign="bottom" align="center"&gt;   &lt;p&gt;Total String Size 2&lt;sup&gt;2n&lt;/sup&gt;&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="55"  valign="top" align="center"&gt;   &lt;p&gt;n=0&lt;/p&gt;&lt;/td&gt;   &lt;td width="66"  valign="top" align="center"&gt;   &lt;p&gt;1 way&lt;/p&gt;&lt;/td&gt;   &lt;td width="294" valign="top"&gt;   &lt;p&gt;&amp;lambda;&lt;/p&gt;&lt;/td&gt;   &lt;td width="95"  valign="top" align="center"&gt;   &lt;p&gt;0&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="55"  valign="top" align="center"&gt;   &lt;p&gt;n=1&lt;/p&gt;&lt;/td&gt;   &lt;td width="66"  valign="top" align="center"&gt;   &lt;p&gt;1 way&lt;/p&gt;&lt;/td&gt;   &lt;td width="294" valign="top"&gt;   &lt;p&gt;()&lt;/p&gt;&lt;/td&gt;   &lt;td width="95"  valign="top" align="center"&gt;   &lt;p&gt;2&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="55"  valign="top" align="center"&gt;   &lt;p&gt;n=2&lt;/p&gt;&lt;/td&gt;   &lt;td width="66"  valign="top" align="center"&gt;   &lt;p&gt;2 ways&lt;/p&gt;&lt;/td&gt;   &lt;td width="294" valign="top"&gt;   &lt;p&gt;()(), (())&lt;/p&gt;&lt;/td&gt;   &lt;td width="95"  valign="top" align="center"&gt;   &lt;p&gt;16&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="55"  valign="top" align="center"&gt;   &lt;p&gt;n=3&lt;/p&gt;&lt;/td&gt;   &lt;td width="66"  valign="top" align="center"&gt;   &lt;p&gt;5 ways&lt;/p&gt;&lt;/td&gt;   &lt;td width="294" valign="top"&gt;   &lt;p&gt;()()(), ()(()), (())(), (()()), ((()))&lt;/p&gt;&lt;/td&gt;   &lt;td width="95"  valign="top" align="center"&gt;   &lt;p&gt;64&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="55"  valign="top" align="center"&gt;   &lt;p&gt;n=4&lt;/p&gt;&lt;/td&gt;   &lt;td width="66"  valign="top" align="center"&gt;   &lt;p&gt;14 ways&lt;/p&gt;&lt;/td&gt;   &lt;td width="294" valign="top"&gt;   &lt;p&gt;()()()(), ()()(()), ()(())(), ()(()()), ()((())),&lt;/p&gt;&lt;p&gt;(())()(), (())(()), (()())(), ((()))(), (()()()),&lt;/p&gt;&lt;p&gt;(()(())), ((())()), ((()())), (((())))&lt;/p&gt;&lt;/td&gt;   &lt;td width="95"  valign="top" align="center"&gt;   &lt;p&gt;256&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="55"  valign="top" align="center"&gt;   &lt;p&gt;n=5&lt;/p&gt;&lt;/td&gt;   &lt;td width="66"  valign="top" align="center"&gt;   &lt;p&gt;42 ways&lt;/p&gt;&lt;/td&gt;   &lt;td width="294" valign="top"&gt;   &lt;p&gt;()()()()(), ()()()(()), ()()(())(), ()()(()()), ()()((())),&lt;/p&gt;&lt;p&gt;()(())()(), ()(())(()), ()(()())(), ()((()))(), ()(()()()),&lt;/p&gt;&lt;p&gt;()(()(())), ()((())()), ()((()())), ()(((()))), (())()()(),&lt;/p&gt;&lt;p&gt;(())()(()), (())(())(), (())(()()), (())((())), (()())()(),&lt;/p&gt;&lt;p&gt;(()())(()), ((()))()(), ((()))(()), (()()())(), (()(()))(),&lt;/p&gt;&lt;p&gt;((())())(), ((()()))(), (((())))(), (()()()()), (()()(())),&lt;/p&gt;&lt;p&gt;(()(())()), (()(()())), (()((()))), ((())()()), ((())(())),&lt;/p&gt;&lt;p&gt;((()())()), (((()))()), ((()()())), ((()(()))), (((())())),&lt;/p&gt;&lt;p&gt;(((()()))), ((((()))))&lt;/p&gt;&lt;/td&gt;   &lt;td width="95"  valign="top" align="center"&gt;   &lt;p&gt;1024&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;p&gt;The table above also includes the number of possible strings with only the two parentheses, which grows at a rate 2&lt;sup&gt;2n&lt;/sup&gt;.  This table is based on one from a &lt;a href="http://www.geometer.org/mathcircles/catalan.pdf"&gt;paper&lt;/a&gt; by Tom Davis on Catalan numbers.  It is quite interesting paper as Catalan numbers also describe diagonal avoiding paths, “mountain ranges”, &lt;a href="http://en.wikipedia.org/wiki/Noncrossing_partition"&gt;noncrossing partitions&lt;/a&gt;, multiplication orderings, the number of different ways a &lt;a href="http://en.wikipedia.org/wiki/Convex_polygon" title="Convex polygon"&gt;convex polygon&lt;/a&gt; with n&amp;nbsp;+&amp;nbsp;2 sides can be cut into triangles, to mention a few.  Another interesting thing about Catalan numbers is they can be described by a recurrence relation:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-0UrN9-n9bE8/UISYoGIUP9I/AAAAAAAAA68/qR6-a4wQH_E/s1600/C1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="15" width="79" src="http://3.bp.blogspot.com/-0UrN9-n9bE8/UISYoGIUP9I/AAAAAAAAA68/qR6-a4wQH_E/s400/C1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-pKvJjtBY_BY/UISYtqAPkDI/AAAAAAAAA7I/XmQhVDc_DrE/s1600/C2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="15" width="138" src="http://4.bp.blogspot.com/-pKvJjtBY_BY/UISYtqAPkDI/AAAAAAAAA7I/XmQhVDc_DrE/s400/C2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-Bx2wkRH9sHI/UISYy0evQpI/AAAAAAAAA7U/reAUKYKNzac/s1600/C3.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="15" width="197" src="http://1.bp.blogspot.com/-Bx2wkRH9sHI/UISYy0evQpI/AAAAAAAAA7U/reAUKYKNzac/s400/C3.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-72D3n-Y4fHQ/UISY4OJjDSI/AAAAAAAAA7g/x6FjYqgN5EE/s1600/C4.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="15" width="256" src="http://2.bp.blogspot.com/-72D3n-Y4fHQ/UISY4OJjDSI/AAAAAAAAA7g/x6FjYqgN5EE/s400/C4.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-xLRO5ckf7Cw/UISY91TGaMI/AAAAAAAAA7s/Ux-KT7l2QrA/s1600/Cn.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="15" width="373" src="http://4.bp.blogspot.com/-xLRO5ckf7Cw/UISY91TGaMI/AAAAAAAAA7s/Ux-KT7l2QrA/s400/Cn.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;I confess that this may not be that pragmatic in terms of solving the problem, but I think it is interesting and possibly gives a larger context to the problem.  &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Exercise 3: Counting Change&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;The last problem, which is probably something of a CS classic problem as it appears in &lt;a href="http://mitpress.mit.edu/sicp/full-text/book/book.html"&gt;SICP&lt;/a&gt;, is the problem of &lt;a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_1.2.2"&gt;counting change&lt;/a&gt;, given some numerical amount and some set of coin denominations we need to count the number of ways that we can represent the amount given the set of denominations. I confess to having cheated a little bit, well ok a lot, I found this post by &lt;a href="http://www.billthelizard.com/2009/12/sicp-exercise-114-counting-change.html"&gt;Bill the Lizard&lt;/a&gt;. I also found this &lt;a href="http://www.billthelizard.com/2010/12/sicp-219-counting-change-revisited.html"&gt;post&lt;/a&gt; with a more elegant solution and translated these into both Scala and Clojure, well ok I guess it’s not cheating since I didn’t submit it.  The clojure version is:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p class="codeline"&gt;(defn count-change [amount coin-values]&lt;/p&gt;&lt;p class="codeline1"&gt;(cond (= amount 0) 1&lt;/p&gt;&lt;p class="codeline2"&gt;(or (&amp;lt; amount 0) (empty? coin-values)) 0&lt;/p&gt;&lt;p class="codeline1"&gt;:else&lt;/p&gt;&lt;p class="codeline2"&gt;(+ (count-change amount (rest coin-values))&lt;/p&gt;&lt;p class="codeline3"&gt;(count-change (- amount (first coin-values)) coin-values))&lt;/p&gt;&lt;p class="codeline1"&gt;)&lt;/p&gt;&lt;p class="codeline"&gt;)&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The math here is from number theory and combinatorics, actually it might fall under combinatorial number theory.  In number theory there are two pretty big areas, one is multiplicative number theory which dates back at least to the Greeks and deals with how numbers divide and remainders and prime numbers which includes things like the well known &lt;a href="http://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic"&gt;fundamental theorem of arithmetic&lt;/a&gt;.  A relatively newer area of number theory is known as arithmetic number theory and is mostly attributed to Euler. In fact it was Euler who initiated the study of number partitions in his book &lt;u&gt;Introduction to the Analysis of the Infinite&lt;/u&gt; in 1748.  It is the math of &lt;a href="http://en.wikipedia.org/wiki/Partition_%28number_theory%29"&gt;number partitions&lt;/a&gt; that our change problem falls under.   We are basically counting a subset of the partitions of a number’s &lt;a href="http://oeis.org/A000041"&gt;full partition set&lt;/a&gt;.  In fact we can create a function that uses a Clojure &lt;a href="http://en.wikipedia.org/wiki/List_comprehension"&gt;list comprehension&lt;/a&gt; to create a number partition function from our change counting function:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p class="codeline"&gt;(defn number-partition [n]&lt;/p&gt;&lt;p class="codeline1"&gt;(count-change n (for [x (range 1 (inc n))] x ))&lt;/p&gt;&lt;p class="codeline"&gt;) &lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://mathworld.wolfram.com/PartitionFunctionP.html"&gt;Functions&lt;/a&gt; to count partitions have been studied over the years and Euler invented a &lt;a href="http://mathworld.wolfram.com/GeneratingFunction.html"&gt;generating function&lt;/a&gt; that gives rise to, you guessed it, a recurrence equation to count partitions:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-Q5Y6k3zBsNw/UISZGrq1_2I/AAAAAAAAA74/rCBBO4X90iI/s1600/P%2528n%2529.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="44" width="400" src="http://2.bp.blogspot.com/-Q5Y6k3zBsNw/UISZGrq1_2I/AAAAAAAAA74/rCBBO4X90iI/s400/P%2528n%2529.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;School’s out&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;So there it is some (hopefully) interesting math context for these problems. I guess it’s kind of a gray area but I am pretty sure I didn’t cross the line on the whole honor code thing but even if I did I believe it’s covered by the People's Freedom of Choices and Voices Act. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Well it was a fun post to write, I got some code in a post, something I haven't done lately, which is only fitting for a blog called Elegant Coding, I think it came out pretty decent but remember I am still learning Scala and Clojure so my code examples here may not be as elegant as they could be.  I guess another objective of this post and my blog in general is to explore ways to mix programming and math education, while I think this post makes for a nice start along these lines, it could probably be improved which would be nice.&lt;/p&gt;&lt;br /&gt;
&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/VzeXJcp6qbQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/VzeXJcp6qbQ/the-math-of-first-scala-assignment.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-ZH2ftp5o78M/UISoJ894ZdI/AAAAAAAAA8w/GLj9bo-fHRI/s72-c/crater.jpg" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/10/the-math-of-first-scala-assignment.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-1154912453577523880</guid><pubDate>Mon, 08 Oct 2012 20:41:00 +0000</pubDate><atom:updated>2012-10-08T19:00:54.244-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Topology</category><category domain="http://www.blogger.com/atom/ns#">Math</category><category domain="http://www.blogger.com/atom/ns#">Number Theory</category><category domain="http://www.blogger.com/atom/ns#">Combinatorics</category><category domain="http://www.blogger.com/atom/ns#">Lattice Theory</category><title>The Ubiquitous Patterns of Pascal’s Triangle</title><description>&lt;!--The Ubiquitous Patterns of Pascal’s Triangle--&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-7eXPaPKFh0A/UHMobM8_KLI/AAAAAAAAA34/EKEnStLvY60/s1600/PascalsTriangleCoefficient.1.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="300" width="380" src="http://1.bp.blogspot.com/-7eXPaPKFh0A/UHMobM8_KLI/AAAAAAAAA34/EKEnStLvY60/s400/PascalsTriangleCoefficient.1.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Pascal%27s_triangle"&gt;Pascal’s Triangle&lt;/a&gt; is one of the most fascinating and intriguing objects in math, I was first introduced to it in the sterile context of high school algebra as an aside.  Only decades later did I discover its true grandeur when I rediscovered it in the context of &lt;a href="http://en.wikipedia.org/wiki/Combinatorics"&gt;combinatorics&lt;/a&gt; and number theory.  I will attempt to provide some, hopefully, enlightening images but I feel that mathematical notation is both important and beautifully concise and allows one to have a transcendent experience with math so we will start with a formula, one of my “&lt;a href="http://www.elegantcoding.com/2011/11/eleven-equations-true-computer-science.html"&gt;Eleven Equations&lt;/a&gt;”. The more I learn the more I feel it is more than justified to be in that list. I also feel that its centrality in combinatorics and probability theory makes it an equation that every math or computer science geek or enthusiast should be able to both recite off of the top their heads and be able to apply, if you don’t agree maybe this post will inspire you to think differently.  The equation is that of the &lt;a href="http://en.wikipedia.org/wiki/Binomial_coefficient"&gt;binomial coefficient formula&lt;/a&gt; and it describes each element of Pascal’s Triangle:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-iJPXhfJORs0/UHMQ1ra-r4I/AAAAAAAAAtA/GNiV45x-8-A/s1600/Binomail%2BCoeffient.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="124" src="http://2.bp.blogspot.com/-iJPXhfJORs0/UHMQ1ra-r4I/AAAAAAAAAtA/GNiV45x-8-A/s400/Binomail%2BCoeffient.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The above formula evaluates under the rules that c &amp;le; r,  r &amp;le; 0 and 0! = 1.  I prefer the use the letters r and c over the traditional n and k as in n chose k, one can as easily say r choose c.  The reason I prefer r and c is that r means row and c means column and these values can be viewed as a way to address positions within Pascal’s Triangle, for example using the binomial coefficient notation from the above formula Pascal’s Triangle can be represented as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-EJv7KfnvA0U/UHMRKw7OsII/AAAAAAAAAtM/_ykwc5ho2LY/s1600/PascalsTriangleCoefficient.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="380" width="380" src="http://3.bp.blogspot.com/-EJv7KfnvA0U/UHMRKw7OsII/AAAAAAAAAtM/_ykwc5ho2LY/s400/PascalsTriangleCoefficient.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;As you can see in the above representation each position is the address (r,c) given by the coefficient notation.  Evaluating the expressions above with the Binomial Coefficient formula yields the more common representation of Pascal’s Triangle:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-40nMzHeN8tY/UHMRXB8zHEI/AAAAAAAAAtY/_d4H-OdVjgQ/s1600/pascalsTriangle.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="280" width="320" src="http://1.bp.blogspot.com/-40nMzHeN8tY/UHMRXB8zHEI/AAAAAAAAAtY/_d4H-OdVjgQ/s400/pascalsTriangle.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name="Binomial_Theorem"&gt;&lt;/a&gt;&lt;h3&gt;Binomial Theorem&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;If I recall correctly and has been a while, the high school algebra introduction to Pascal’s triangle was mostly tied to the &lt;a href="http://en.wikipedia.org/wiki/Binomial_theorem"&gt;Binomial Theorem&lt;/a&gt;, which is written with &lt;a href="http://en.wikipedia.org/wiki/Summation"&gt;sigma (summation)&lt;/a&gt; notation as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-7KxU4FlhmAg/UHMRs3VUo7I/AAAAAAAAAtk/w5zzdMXiH_Q/s1600/binomial.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="47" width="355" src="http://1.bp.blogspot.com/-7KxU4FlhmAg/UHMRs3VUo7I/AAAAAAAAAtk/w5zzdMXiH_Q/s400/binomial.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;For our purposes we are interested in the one variable version which can be written as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-9LeaLg8bKio/UHMSA-WxPsI/AAAAAAAAAtw/RvFHyLLJ2jU/s1600/binomial-one.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="47" width="173" src="http://2.bp.blogspot.com/-9LeaLg8bKio/UHMSA-WxPsI/AAAAAAAAAtw/RvFHyLLJ2jU/s400/binomial-one.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;This can be expanded to:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-X-2HdbHUAP4/UHMSSMNOMYI/AAAAAAAAAt8/NgJ2ZxWgSIE/s1600/binomial-one-expand.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="29" width="400" src="http://4.bp.blogspot.com/-X-2HdbHUAP4/UHMSSMNOMYI/AAAAAAAAAt8/NgJ2ZxWgSIE/s400/binomial-one-expand.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;This can be written in "Pascal’s Triangle Form" as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-NYe6O3mpI1Q/UHMSZ3IxjVI/AAAAAAAAAuI/OweQanFD-FA/s1600/pascal-binom-theo.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="235" width="373" src="http://2.bp.blogspot.com/-NYe6O3mpI1Q/UHMSZ3IxjVI/AAAAAAAAAuI/OweQanFD-FA/s400/pascal-binom-theo.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name="Additive_Structure"&gt;&lt;/a&gt;&lt;h3&gt;Additive Structure&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;These types of introductions often focus on the additive properties as well. Each element is the sum of the two elements above it, which can be illustrated as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-jjhGk5hn6Vw/UHMSkMq9gEI/AAAAAAAAAuU/R1DS6z5wq1g/s1600/pascalsTriangleAddLattice.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="380" width="380" src="http://3.bp.blogspot.com/-jjhGk5hn6Vw/UHMSkMq9gEI/AAAAAAAAAuU/R1DS6z5wq1g/s400/pascalsTriangleAddLattice.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The logic of this representation assumes that there is a zero on each side to add to propagate the ones on both side, we can rewrite this using the binomial coefficient notation as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-fPNzGOQHsbs/UHMSvEWHTYI/AAAAAAAAAug/cLZIpfK5Iso/s1600/pascalsTriangleAddLatticeCoefficient.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="400" src="http://1.bp.blogspot.com/-fPNzGOQHsbs/UHMSvEWHTYI/AAAAAAAAAug/cLZIpfK5Iso/s400/pascalsTriangleAddLatticeCoefficient.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;I admit this is where it starts to get more interesting to me. Not to denigrate its importance but I never really got that excited by the whole binomial theorem thing, although the &lt;a href="http://en.wikipedia.org/wiki/Binomial_theorem#Series_for_e"&gt;series e&lt;/a&gt; stuff is pretty cool.  If we pick 5 choose 3 in the above representation, it can be written as the following sum:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-AfYKAU1ZVQU/UHMS8eMoaRI/AAAAAAAAAus/EbA0wPB-jlY/s1600/Pascal%2527s%2BIdentity%2B5-3.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="184" src="http://3.bp.blogspot.com/-AfYKAU1ZVQU/UHMS8eMoaRI/AAAAAAAAAus/EbA0wPB-jlY/s400/Pascal%2527s%2BIdentity%2B5-3.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name="Pascals_Identity"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;p&gt;If you look at the above representation you can see that this can be done for all entries that have two parents, this can be generalized as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/--_h98Nxxoe8/UHMTD-NFxSI/AAAAAAAAAu4/4SLrb3CiEZo/s1600/Pascal%2527s%2BIdentity.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="191" src="http://2.bp.blogspot.com/--_h98Nxxoe8/UHMTD-NFxSI/AAAAAAAAAu4/4SLrb3CiEZo/s400/Pascal%2527s%2BIdentity.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;This formula, which is a &lt;a href="http://en.wikipedia.org/wiki/Recurrence_relation"&gt;recurrence relation&lt;/a&gt;, is known as &lt;a href="http://en.wikipedia.org/wiki/Pascal%27s_rule"&gt;Pascal’s Identity&lt;/a&gt;, it is one of several formulas known as &lt;a href="http://en.wikipedia.org/wiki/Binomial_coefficient#Identities_involving_binomial_coefficients"&gt;Combinatorial Identities&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Powers_of_Two"&gt;&lt;/a&gt;&lt;h3&gt;Powers of Two&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Another interesting and extremely important pattern in Pascal’s Triangle is the fact that the values of each row sum to the power of two of the row number, which the following representation depicts:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-hZB9JDFYAWo/UHMTRFbeEQI/AAAAAAAAAvE/NlnilpTgqTk/s1600/pascalsTrianglePower2.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="280" width="360" src="http://4.bp.blogspot.com/-hZB9JDFYAWo/UHMTRFbeEQI/AAAAAAAAAvE/NlnilpTgqTk/s400/pascalsTrianglePower2.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;This can be written as the following formula, I think this also qualifies as an identity:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-C3ICa4fM91E/UHMTsF3ezWI/AAAAAAAAAvQ/P5Mqx_5ly20/s1600/2r.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="47" width="110" src="http://4.bp.blogspot.com/-C3ICa4fM91E/UHMTsF3ezWI/AAAAAAAAAvQ/P5Mqx_5ly20/s400/2r.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name="Sets"&gt;&lt;/a&gt;&lt;h3&gt;Sets&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;As I mentioned at the beginning the binomial coefficient formula is read as r choose c.  I was trying to get back to that but I took the long way, so looking at our examples above our 5 choose 3 means if I have five things how many ways can I choose three of them which is 10 ways .  This is useful for counting, in combinatorics and probability theory I could take a deck of 52 cards and count how many 5 card hands I could choose and calculate probabilities of getting various hands, these are pretty standard applications of these types of counting problems.  However, if we step back and look at this counting, where each row represents a set of items, then each column represents the number of subsets of size c, this another reason I prefer c here it means both column and &lt;a href="http://en.wikipedia.org/wiki/Cardinality"&gt;cardinality&lt;/a&gt; of the &lt;a href="http://en.wikipedia.org/wiki/Subset"&gt;subset&lt;/a&gt;.  We can create a representation of Pascal’s Triangle to show this, but it does become unwieldy pretty quickly due to the exponential growth of each row, we would get:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-xCj6nPdIhDI/UHMT2vj4hBI/AAAAAAAAAvc/y9swVRRg9mI/s1600/pascal-sets.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="340" width="400" src="http://4.bp.blogspot.com/-xCj6nPdIhDI/UHMT2vj4hBI/AAAAAAAAAvc/y9swVRRg9mI/s400/pascal-sets.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;In this representation each number represents a set element, these can map to any sets with these cardinalities.  Each column is wrapped by parentheses.  The ones on the left are created by the empty set and the ones on the right are created by the set itself.  So each row in Pascal’s triangle gives the structure of the &lt;a href="http://en.wikipedia.org/wiki/Power_set"&gt;powerset&lt;/a&gt; of a set with the cardinality of the row number.  Also it is not a coincidence that each row sums to a power of two since the cardinality of the powerset is the cardinality of the set raised to the power of 2.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Powerset_Lattice"&gt;&lt;/a&gt;&lt;h3&gt;Powerset Lattice&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Since I’ve had &lt;a href="http://www.elegantcoding.com/2012/09/lattice-theory-for-programmers-and-non.html"&gt;lattice theory on my mind lately&lt;/a&gt;, I couldn’t help but calling on our old friend the powerset lattice, as you can see in the context of the above each powerset lattice is going to have a row from Pascal’s triangle imprinted on it, each antichain consists of sets of the same cardinality and the number sets in the antichain maps back to a column:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-vOAePXNlq84/UHMT9zwsAlI/AAAAAAAAAvo/kxa7bnu6J1U/s1600/PowerSetLattice.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="218" width="400" src="http://1.bp.blogspot.com/-vOAePXNlq84/UHMT9zwsAlI/AAAAAAAAAvo/kxa7bnu6J1U/s400/PowerSetLattice.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name="PIE"&gt;&lt;/a&gt;&lt;h3&gt;Principle of Inclusion and Exclusion (P.I.E)&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;The principle of inclusion and exclusion is used to count the size (cardinality) of a union of sets based on the cardinality of the sets and their intersections, the most common form, which appears in many probability texts, is:&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;|A &amp;cup; B| = |A| + |B| - |A &amp;cap; B|&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The reason for this is that if you take the size of the union two sets, if they have any common elements then they counted twice, so subtracting the intersection removes the duplicate count.  This type of problem, counting things more than once and then needing to remove the duplicates comes up in other counting problems as well.  The venn diagram below shows the intersection of two sets, these are the elements that get counted twice in |A| + |B|:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-rhTef4OeEik/UHMUNJIzy_I/AAAAAAAAAv0/E6hl_lxYO28/s1600/200px-Venn0001_svg.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="146" width="200" src="http://1.bp.blogspot.com/-rhTef4OeEik/UHMUNJIzy_I/AAAAAAAAAv0/E6hl_lxYO28/s400/200px-Venn0001_svg.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Now as a disclaimer this Pascal’s triangle correlation is strictly my own observation so it might be wrong, but it seems to hold.  If you take the formula from above and add a term for the empty set, which is not needed as it evaluates to zero you get |&amp;empty;| + |A| + |B| - |A &amp;cap; B|.  Now you can see the number of elements for each term with number of sets (0, 1, 2) are 1 2 1, row 2 of Pascal’s triangle, for three you have 1 3 3 1:&lt;/p&gt;&lt;br /&gt;
&lt;table border="0" cellspacing="2" cellpadding="0"&gt;&lt;tr&gt;     &lt;td valign="center" align="left" colspan="2"&gt;&lt;p&gt;|A &amp;cup; B &amp;cup; C| =&lt;/p&gt;&lt;/td&gt;     &lt;td valign="center" align="left"&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="center" align="left" width="30"&gt;&amp;nbsp;&lt;/td&gt;     &lt;td valign="center" align="left" width="300"&gt;&lt;p&gt;|&amp;empty;| +&lt;/p&gt;&lt;/td&gt;     &lt;td valign="center" align="left"&gt;(1&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="center" align="left" width="20"&gt;&amp;nbsp;&lt;/td&gt;     &lt;td valign="center" align="left" width="300"&gt;&lt;p&gt;|A| + |B| + |C|&lt;/p&gt;&lt;/td&gt;     &lt;td valign="center" align="left"&gt;(3&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="center" align="left" width="20"&gt;&amp;nbsp;&lt;/td&gt;     &lt;td valign="center" align="left" width="300"&gt;&lt;p&gt;- |A &amp;cap; B| - |A &amp;cap; C| - |B &amp;cap; C|&lt;/p&gt;&lt;/td&gt;     &lt;td valign="center" align="left"&gt;(3&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="center" align="left" width="20"&gt;&amp;nbsp;&lt;/td&gt;     &lt;td valign="center" align="left" width="300"&gt;&lt;p&gt;+ |A &amp;cap; B &amp;cap; C|&lt;/p&gt;&lt;/td&gt;     &lt;td valign="center" align="left"&gt;(1&lt;/td&gt; &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;p&gt;And for four we have (1 4 6 4 1)&lt;/p&gt;&lt;br /&gt;
&lt;table border="0" cellspacing="2" cellpadding="0"&gt;&lt;tr&gt;     &lt;td valign="center" align="left" colspan="2"&gt;&lt;p&gt;|A &amp;cup; B &amp;cup; C &amp;cup; D | =&lt;/p&gt;&lt;/td&gt;     &lt;td valign="center" align="left"&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="center" align="left" width="30"&gt;&amp;nbsp;&lt;/td&gt;     &lt;td valign="center" align="left" width="400"&gt;&lt;p&gt;|&amp;empty;| +&lt;/p&gt;&lt;/td&gt;     &lt;td valign="center" align="left"&gt;(1&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="center" align="left" width="30"&gt;&amp;nbsp;&lt;/td&gt;     &lt;td valign="center" align="left" width="400"&gt;&lt;p&gt;|A| + |B| + |C|+ |D|&lt;/p&gt;&lt;/td&gt;     &lt;td valign="center" align="left"&gt;(4&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="center" align="left" width="30"&gt;&amp;nbsp;&lt;/td&gt;     &lt;td valign="center" align="left" width="400"&gt;&lt;p&gt;- |A &amp;cap; B| - |A &amp;cap; C| - |A &amp;cap; D| - |B &amp;cap; C| - |B &amp;cap; D| - |C &amp;cap; D|&lt;/p&gt;&lt;/td&gt;     &lt;td valign="center" align="left"&gt;(6&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="center" align="left" width="30"&gt;&amp;nbsp;&lt;/td&gt;     &lt;td valign="center" align="left" width="400"&gt;&lt;p&gt;+ |A &amp;cap; B &amp;cap; C| + |A &amp;cap; B &amp;cap; D| + |A &amp;cap; C &amp;cap; D| + |B &amp;cap; C &amp;cap; D|&lt;/p&gt;&lt;/td&gt;     &lt;td valign="center" align="left"&gt;(4&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="center" align="left" width="30"&gt;&amp;nbsp;&lt;/td&gt;     &lt;td valign="center" align="left" width="400"&gt;&lt;p&gt;- |A &amp;cap; B &amp;cap; C &amp;cap; D |&lt;/p&gt;&lt;/td&gt;     &lt;td valign="center" align="left"&gt;(1&lt;/td&gt; &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;p&gt;This does not prove it but I would bet the pattern continues.  Like I said this is my own observation, so it might be wrong, if you know either way please let me know.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Binomial_Distribution"&gt;&lt;/a&gt;&lt;h3&gt;Binomial Distribution&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;The binomial distribution is given by the following formula:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-tWFwhL8tDzY/UHMUX6RMgFI/AAAAAAAAAwE/QC7efyw5UsM/s1600/binomial-dist.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="319" src="http://1.bp.blogspot.com/-tWFwhL8tDzY/UHMUX6RMgFI/AAAAAAAAAwE/QC7efyw5UsM/s400/binomial-dist.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;I converted it to my r,c nomenclature, I may be going too far using it here but I wanted to keep consistent, remember r=n, and c=k.  It is a discrete probability distribution for the number of successes of r independent yes/no experiments each of which yields success with probability p. If you set p=1/2, the symmetric case, then the row number r divided by 2&lt;sup&gt;r&lt;/sup&gt; gives you the binomial distribution. By the &lt;a href="http://en.wikipedia.org/wiki/Central_limit_theorem"&gt;central limit theorem&lt;/a&gt; this symmetric case approaches the normal distribution as r increases.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Central_Binomial_Coefficient_Symmetry"&gt;&lt;/a&gt;&lt;h3&gt;Central Binomial Coefficient and Symmetry&lt;/h3&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-agwURIi-9Mo/UHMUhUA_JTI/AAAAAAAAAwQ/cKoK7ZDjU74/s1600/pascalsTriangleSymmetry.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="320" width="320" src="http://2.bp.blogspot.com/-agwURIi-9Mo/UHMUhUA_JTI/AAAAAAAAAwQ/cKoK7ZDjU74/s400/pascalsTriangleSymmetry.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The above representation shows the symmetry in Pascal’s Triangle, each row is colored in a way that highlights the numbers that are the same, the first and last columns consisting of ones match each other obviously, but in each row the second column matches the second to last column, and the same for the third column and so one. This gives rise to, you guessed it, another combinatorial identity:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Pr50ZvGg0Ek/UHMUn53C3dI/AAAAAAAAAwY/0ROAAfbbUmE/s1600/Binomial%2BSymetry.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="141" src="http://3.bp.blogspot.com/-Pr50ZvGg0Ek/UHMUn53C3dI/AAAAAAAAAwY/0ROAAfbbUmE/s400/Binomial%2BSymetry.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The columns highlighted in the gray box are special case called the &lt;a href="http://en.wikipedia.org/wiki/Central_binomial_coefficient"&gt;central binomial coefficient&lt;/a&gt;. If you notice each even numbered row has an odd number of columns with the central one only occurring only once, it still follows the above identity but the identity evaluates to a value equaling itself.  The central binomial coefficient is given by the following form, I use n here since we don’t care about row/column in this case:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-1XLambBt47s/UHMUyOSuEEI/AAAAAAAAAwk/aiL3Wgwlu2M/s1600/Central%2BBinomial.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="53" src="http://4.bp.blogspot.com/-1XLambBt47s/UHMUyOSuEEI/AAAAAAAAAwk/aiL3Wgwlu2M/s400/Central%2BBinomial.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name="Figurate_Numbers"&gt;&lt;/a&gt;&lt;h3&gt;Figurate Numbers&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;There is an area of math that deals with &lt;a href="http://en.wikipedia.org/wiki/Figurate_number"&gt;figurate numbers&lt;/a&gt;, these are numbers formed by arranging dots to form various polygons which form sequences as you expand size of each polygon, I looked at some interesting properties of &lt;a href="http://www.elegantcoding.com/2011/07/triangles-triangular-numbers-and.html"&gt;triangular numbers in a previous post&lt;/a&gt;, for example here are the first 5 triangular numbers:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-E8NbWJfEc5U/UHMVF1HZTVI/AAAAAAAAAww/WP1AfX8ddow/s1600/trinum.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="250" width="280" src="http://2.bp.blogspot.com/-E8NbWJfEc5U/UHMVF1HZTVI/AAAAAAAAAww/WP1AfX8ddow/s400/trinum.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Triangular numbers are created by adding up the natural numbers, but there is a binomial formula which evaluates to a closed formula:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-uhbFai7F86w/UHMVQJM_1jI/AAAAAAAAAw8/wEYLBkQ5Y7Q/s1600/trinum.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="44" width="400" src="http://1.bp.blogspot.com/-uhbFai7F86w/UHMVQJM_1jI/AAAAAAAAAw8/wEYLBkQ5Y7Q/s400/trinum.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The idea of figurate numbers can be extended into higher dimensions, so not only do you have numbers that create polygons you can create polyhedrons as well.  When you add up triangular numbers, you get the &lt;a href="http://en.wikipedia.org/wiki/Tetrahedral_number"&gt;tetrahedral number&lt;/a&gt; which can be described by an analogous formula:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-s_lnM0L_sbI/UHMVf8C2iaI/AAAAAAAAAxI/V-awTkNcKc4/s1600/tetranum.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="37" width="400" src="http://3.bp.blogspot.com/-s_lnM0L_sbI/UHMVf8C2iaI/AAAAAAAAAxI/V-awTkNcKc4/s400/tetranum.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;This can be visually depicted as stacking up the triangular number to form tetrahedrons:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-0IOkhkk14wg/UHMV21pQjKI/AAAAAAAAAxU/lGXkC1OkKt8/s1600/tetranum.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="160" width="389" src="http://1.bp.blogspot.com/-0IOkhkk14wg/UHMV21pQjKI/AAAAAAAAAxU/lGXkC1OkKt8/s400/tetranum.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Pascal’s Triangle has a number of relations with figurate numbers, but the most notable are the triangular and tetrahedral numbers, shown in red and blue respectively:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-tsVDl-fw-0U/UHMWBqO8NAI/AAAAAAAAAxg/MO7EK0lIzbk/s1600/pascalsTriangleTetrahedral.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="320" width="320" src="http://4.bp.blogspot.com/-tsVDl-fw-0U/UHMWBqO8NAI/AAAAAAAAAxg/MO7EK0lIzbk/s400/pascalsTriangleTetrahedral.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Also if you look at the binomial expression for these you will notice that the column is fixed, for triangular numbers it is c=2 and for tetrahedral numbers it is c=3, this maps our addressable form to the second and third columns as shown.&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-wXxkfnvllbQ/UHMWLJMfVMI/AAAAAAAAAxs/nLSpJGbPfzs/s1600/pascalsTriangleTable.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="226" width="400" src="http://1.bp.blogspot.com/-wXxkfnvllbQ/UHMWLJMfVMI/AAAAAAAAAxs/nLSpJGbPfzs/s400/pascalsTriangleTable.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The above tabular form is based on a table from &lt;u&gt;Concrete Mathematics&lt;/u&gt;, 2nd Edition by Ronald L. Graham, Donald E. Knuth and Oren Patashnik.  Again you can see column one, where c=1, is the natural numbers, column two is the trianglular numbers, the summation of natural numbers and three is the tetrahedral numbers, the summation of the triangular numbers.  This would imply that this pattern continues to progress, and it does. The next column are the &lt;a href="http://en.wikipedia.org/wiki/Pentatope_number"&gt;pentatope numbers&lt;/a&gt;, which describe a series of four dimensional polytopes, a &lt;a href="http://en.wikipedia.org/wiki/Polytope"&gt;polytope&lt;/a&gt; is an extension of a polyhedron into higher dimensions, called &lt;a href="http://en.wikipedia.org/wiki/Pentachoron"&gt;pentachorons&lt;/a&gt; which are formed by stacking three dimensional tetrahedrons in four dimensions. These numbers are given by the formula:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-0BksBh5T10Q/UHMWs3dYpWI/AAAAAAAAAx8/1BrQDbK3pLo/s1600/pentatopenum.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="33" width="400" src="http://1.bp.blogspot.com/-0BksBh5T10Q/UHMWs3dYpWI/AAAAAAAAAx8/1BrQDbK3pLo/s400/pentatopenum.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;And these numbers progress into higher dimensions, each summing the numbers immediately below them. These are generalized as the &lt;a href="http://blog.drscottfranklin.net/2006/10/26/multi-dimensional-pyramidal-numbers/"&gt;pyramidal numbers&lt;/a&gt; and are described by the following table:&lt;/p&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;&lt;tr&gt;     &lt;td valign="center" align="center"&gt;Number&lt;/td&gt;     &lt;td valign="center" align="center"&gt;Summation Form&lt;/td&gt;     &lt;td valign="center" align="center"&gt;Binomial Form&lt;/td&gt;     &lt;td valign="center" align="center"&gt;Closed Form&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/--CFbZvlNJ_g/UHMilmKqN6I/AAAAAAAAA2o/3RNIy3wqZtQ/s1600/P0.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="20" width="29" src="http://2.bp.blogspot.com/--CFbZvlNJ_g/UHMilmKqN6I/AAAAAAAAA2o/3RNIy3wqZtQ/s400/P0.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/--s8L5nIctVU/UHMiaiwh1yI/AAAAAAAAA2c/89ONDjMmaSg/s1600/Sum-0.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="49" width="33" src="http://1.bp.blogspot.com/--s8L5nIctVU/UHMiaiwh1yI/AAAAAAAAA2c/89ONDjMmaSg/s400/Sum-0.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-ZzOzNN8g5ZE/UHMhtjxIMgI/AAAAAAAAA1g/NXb4FpbrHJI/s1600/BinomialForm0.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="43" src="http://4.bp.blogspot.com/-ZzOzNN8g5ZE/UHMhtjxIMgI/AAAAAAAAA1g/NXb4FpbrHJI/s400/BinomialForm0.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-AePo_xR6X0c/UHMgYSeUndI/AAAAAAAAA0k/NXppof2LKGw/s1600/Closed-0.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="35" width="13" src="http://3.bp.blogspot.com/-AePo_xR6X0c/UHMgYSeUndI/AAAAAAAAA0k/NXppof2LKGw/s400/Closed-0.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-m_G_bgW7V7E/UHMisUZ5xKI/AAAAAAAAA20/TGZc2IZ7D-0/s1600/P1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="20" width="29" src="http://4.bp.blogspot.com/-m_G_bgW7V7E/UHMisUZ5xKI/AAAAAAAAA20/TGZc2IZ7D-0/s400/P1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-LA7SjER1psg/UHNaybPqvjI/AAAAAAAAA4Y/yBMO00a9FJo/s1600/Sum-1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="46" width="33" src="http://1.bp.blogspot.com/-LA7SjER1psg/UHNaybPqvjI/AAAAAAAAA4Y/yBMO00a9FJo/s400/Sum-1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-1m-NvXZRPMs/UHMhgKZ2MmI/AAAAAAAAA1U/4WVaBQE88gc/s1600/BinomialForm1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="45" src="http://4.bp.blogspot.com/-1m-NvXZRPMs/UHMhgKZ2MmI/AAAAAAAAA1U/4WVaBQE88gc/s400/BinomialForm1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-jqyOmMCBR1M/UHMgTEw8E3I/AAAAAAAAA0Y/JDSNfPEDw5g/s1600/Closed-1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="31" width="13" src="http://2.bp.blogspot.com/-jqyOmMCBR1M/UHMgTEw8E3I/AAAAAAAAA0Y/JDSNfPEDw5g/s400/Closed-1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-7OuefM5ahVY/UHMiy3llM4I/AAAAAAAAA3A/oFiyM_B3cMo/s1600/P2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="20" width="29" src="http://2.bp.blogspot.com/-7OuefM5ahVY/UHMiy3llM4I/AAAAAAAAA3A/oFiyM_B3cMo/s400/P2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-njeQhA3xewI/UHMiGLCoHAI/AAAAAAAAA2E/FsvdmqBH9eQ/s1600/Sum-2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="46" width="54" src="http://2.bp.blogspot.com/-njeQhA3xewI/UHMiGLCoHAI/AAAAAAAAA2E/FsvdmqBH9eQ/s400/Sum-2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-vmyEtFmQKdY/UHMhC0wo43I/AAAAAAAAA1I/o8ISCwd20V8/s1600/BinomialForm2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="73" src="http://1.bp.blogspot.com/-vmyEtFmQKdY/UHMhC0wo43I/AAAAAAAAA1I/o8ISCwd20V8/s400/BinomialForm2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-j4QxTEzjnKk/UHMgIOjUxRI/AAAAAAAAA0M/Cr1JKRZyidM/s1600/Closed-2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="35" width="62" src="http://2.bp.blogspot.com/-j4QxTEzjnKk/UHMgIOjUxRI/AAAAAAAAA0M/Cr1JKRZyidM/s400/Closed-2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-O6RwLUlVGbg/UHMjB__88vI/AAAAAAAAA3Q/y5jkhapWYJc/s1600/P3.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="20" width="29" src="http://1.bp.blogspot.com/-O6RwLUlVGbg/UHMjB__88vI/AAAAAAAAA3Q/y5jkhapWYJc/s400/P3.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-kOuw8aCdm_o/UHMh_iycMaI/AAAAAAAAA14/m9-ZtOj1srU/s1600/Sum-3.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="46" width="54" src="http://4.bp.blogspot.com/-kOuw8aCdm_o/UHMh_iycMaI/AAAAAAAAA14/m9-ZtOj1srU/s400/Sum-3.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-p_HqoY5MHS8/UHMg8NBTLkI/AAAAAAAAA08/qaCeXdU9cMw/s1600/BinomialForm3.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="73" src="http://1.bp.blogspot.com/-p_HqoY5MHS8/UHMg8NBTLkI/AAAAAAAAA08/qaCeXdU9cMw/s400/BinomialForm3.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-ACaFOoHfS9Y/UHMalxRjUtI/AAAAAAAAAyw/sj81ZM_Qg-A/s1600/Closed-3.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="36" width="113" src="http://4.bp.blogspot.com/-ACaFOoHfS9Y/UHMalxRjUtI/AAAAAAAAAyw/sj81ZM_Qg-A/s400/Closed-3.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-xAUUIrgEwwo/UHMjdP5CwwI/AAAAAAAAA3Y/qE7kNF7NZW4/s1600/P4.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="20" width="29" src="http://4.bp.blogspot.com/-xAUUIrgEwwo/UHMjdP5CwwI/AAAAAAAAA3Y/qE7kNF7NZW4/s400/P4.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-p5nO63nFJoc/UHMh3grsIZI/AAAAAAAAA1s/FpXuDPZ2ZVQ/s1600/Sum-4.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="46" width="54" src="http://4.bp.blogspot.com/-p5nO63nFJoc/UHMh3grsIZI/AAAAAAAAA1s/FpXuDPZ2ZVQ/s400/Sum-4.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-_HtomBe931A/UHMg2LZFiLI/AAAAAAAAA0w/XAOrsERsHwI/s1600/BinomialForm4.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="73" src="http://3.bp.blogspot.com/-_HtomBe931A/UHMg2LZFiLI/AAAAAAAAA0w/XAOrsERsHwI/s400/BinomialForm4.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td valign="center" align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-lopmdytfj-w/UHMaS5hUcbI/AAAAAAAAAyk/7S1tjRtSooo/s1600/Closed-4.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="35" width="165" src="http://1.bp.blogspot.com/-lopmdytfj-w/UHMaS5hUcbI/AAAAAAAAAyk/7S1tjRtSooo/s400/Closed-4.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-EBH5BjiHBlw/UHMfeQPc5dI/AAAAAAAAAz0/3RZj6ebb1qQ/s1600/Pc.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="20" width="28" src="http://3.bp.blogspot.com/-EBH5BjiHBlw/UHMfeQPc5dI/AAAAAAAAAz0/3RZj6ebb1qQ/s400/Pc.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-AIgQgvudEG4/UHMfxYmuw1I/AAAAAAAAA0A/cooVozJOLHg/s1600/sum-c.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="46" width="71" src="http://1.bp.blogspot.com/-AIgQgvudEG4/UHMfxYmuw1I/AAAAAAAAA0A/cooVozJOLHg/s400/sum-c.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-dzIK2c0tPkA/UHMa1NH1pbI/AAAAAAAAAzI/KbIam6Tv9d0/s1600/BinomialFormc.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="101" src="http://3.bp.blogspot.com/-dzIK2c0tPkA/UHMa1NH1pbI/AAAAAAAAAzI/KbIam6Tv9d0/s400/BinomialFormc.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;     &lt;td align="center"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-NwlrdctEv1c/UHMat85N4jI/AAAAAAAAAy8/rKVxUxpafms/s1600/Closed-c.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="36" width="221" src="http://2.bp.blogspot.com/-NwlrdctEv1c/UHMat85N4jI/AAAAAAAAAy8/rKVxUxpafms/s400/Closed-c.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;a name="Powers_of_Eleven"&gt;&lt;/a&gt;&lt;h3&gt;Powers of Eleven&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;There is another interesting pattern in Pascal’s Triangle each successive row is equivalent to a power eleven of as you can see in the following table:&lt;/p&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;&lt;tr&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;11&lt;sup&gt;0&lt;/sup&gt;&lt;/p&gt;&lt;/td&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;11&lt;sup&gt;1&lt;/sup&gt;&lt;/p&gt;&lt;/td&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;11&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;2&lt;/p&gt;&lt;/td&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;11&lt;sup&gt;2&lt;/sup&gt;&lt;/p&gt;&lt;/td&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;121&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;3&lt;/p&gt;&lt;/td&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;11&lt;sup&gt;3&lt;/sup&gt;&lt;/p&gt;&lt;/td&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;1331&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;4&lt;/p&gt;&lt;/td&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;11&lt;sup&gt;4&lt;/sup&gt;&lt;/p&gt;&lt;/td&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;14641&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;5&lt;/p&gt;&lt;/td&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;11&lt;sup&gt;5&lt;/sup&gt;&lt;/p&gt;&lt;/td&gt;     &lt;td width="106" align="center"&gt;&lt;p&gt;161051&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;p&gt;Oops, I fibbed a little here, 11&lt;sup&gt;5&lt;/sup&gt; does not equal the row (1 5 10 10 5 1), this breaks down due to the need to carry 1 to make ten. However, the pattern will hold if you push up the number base, for example 11 hexadecimal, which I will write as 11&lt;sub&gt;16&lt;/sub&gt;, to the 5&lt;sup&gt;th&lt;/sup&gt; power is (11&lt;sub&gt;16&lt;/sub&gt;)&lt;sup&gt;5&lt;/sup&gt; = 15AA51, remember A equals 10 so now the pattern holds, and it will continue to hold as long as you keep upping the number base, but remember (11&lt;sub&gt;16&lt;/sub&gt;)&lt;sup&gt;5&lt;/sup&gt;&amp;ne; 11&lt;sup&gt;5&lt;/sup&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Sierpinski_Triangle"&gt;&lt;/a&gt;&lt;h3&gt;Sierpinski Triangle&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;There is another interesting relation to another mathematically interesting triangle, the &lt;a href="http://en.wikipedia.org/wiki/Sierpinski_triangle"&gt;Sierpinski Triangle&lt;/a&gt; aka Sierpinski gasket is a fractal that can be constructed by taking an equilateral triangle and removing the center which is an equilateral triangle of ¼ area and then repeating this on each of the three remaining triangles, and so on.  It can also be created by applying modulo 2 to each element in Pascal’s Triangle as shown below. The zeros are grayed out to highlight the pattern:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-2Mnsl1y-sqI/UHMXFOJV6nI/AAAAAAAAAyE/eWj4c_fmuBI/s1600/PascalsTriangleSierpinski.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="400" src="http://3.bp.blogspot.com/-2Mnsl1y-sqI/UHMXFOJV6nI/AAAAAAAAAyE/eWj4c_fmuBI/s400/PascalsTriangleSierpinski.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;And the List Goes On...&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;As we saw we ventured into several areas of mathematics, combinatorics, number theory, probability theory, fractal geometry and geometry (topology), and lattice theory.  There are many other patterns such as relations to polytopes, cellular automata, a pattern with prime numbers and more.  The &lt;a href="http://en.wikipedia.org/wiki/Pascal%27s_triangle"&gt;Wikipedia page&lt;/a&gt; has many interesting patterns, some of which I used here also two other interesting sites are &lt;a href="http://christopherolah.wordpress.com/2011/08/29/understanding-pascals-triangle/"&gt;Christopher Olah’s post&lt;/a&gt; and &lt;a href="http://ptri1.tripod.com/"&gt;this&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/fPAHIKzyZXA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/fPAHIKzyZXA/the-ubiquitous-patterns-of-pascals.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-7eXPaPKFh0A/UHMobM8_KLI/AAAAAAAAA34/EKEnStLvY60/s72-c/PascalsTriangleCoefficient.1.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/10/the-ubiquitous-patterns-of-pascals.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-651673498477927413</guid><pubDate>Tue, 18 Sep 2012 14:38:00 +0000</pubDate><atom:updated>2012-11-09T09:53:38.926-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Math</category><category domain="http://www.blogger.com/atom/ns#">Abstract Algebra</category><category domain="http://www.blogger.com/atom/ns#">Set Theory</category><category domain="http://www.blogger.com/atom/ns#">Order Theory</category><category domain="http://www.blogger.com/atom/ns#">Lattice Theory</category><title>Lattice Theory for Programmers and Non Computer Scientists</title><description>&lt;!-- Lattice Theory for Programmers and Non Computer Scientists--&gt;&lt;br /&gt;
&lt;h2&gt;Part One: Mathematical Foundations&lt;/h2&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-KrvVV3SvYzY/UFfHghoAk-I/AAAAAAAAAsk/ROPJQYcRmaI/s1600/monarch.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="316" width="400" src="http://4.bp.blogspot.com/-KrvVV3SvYzY/UFfHghoAk-I/AAAAAAAAAsk/ROPJQYcRmaI/s400/monarch.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;style&gt;
    div.source-code {
        color             : #000;
        background-color  : #eee;
        border            : 1px dashed #999999;
        line-height       : 14px;
        padding           : 5px;
        overflow          : auto;
        width             : 100%;
        text-indent       : 0px;
        margin-top        : 8px;
        margin-bottom     : 8px;
    }
&lt;/style&gt;&lt;br /&gt;
&lt;p&gt;Matt Might has a blog post "&lt;a href="http://matt.might.net/articles/partial-orders/"&gt;Order Theory for Computer Scientists&lt;/a&gt;" in which he concisely outlines some basics of order theory.  It is a nice post but it is targeted towards computer scientists and is possibly only of interest to that audience, especially since all of his examples are in &lt;a href="learnyouahaskell.com"&gt;Haskell&lt;/a&gt;, not that there is anything wrong with that, but I think this is unfortunate as these ideas are potentially interesting to programmers as well.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;In this post I am mostly talking about &lt;a href="http://en.wikipedia.org/wiki/Lattice_%28order%29"&gt;lattice theory&lt;/a&gt; as opposed to the more general &lt;a href="http://en.wikipedia.org/wiki/Lattice_%28order%29"&gt;order theory&lt;/a&gt;.  While general order theory is both interesting and relevant to programming and CS, lattice theory is too and there are many interesting ideas that relate to lattice theory. Lattices impose more structure on orders and that is probably why there are a lot of books on lattice theory such as &lt;a href="http://server.maths.umanitoba.ca/homepages/gratzer/"&gt;George Gratzer&lt;/a&gt;’s comprehensive and recently updated &lt;u&gt;Lattice Theory : Foundation&lt;/u&gt;.  Lattice theory has been &lt;a href="http://www.ams.org/notices/199711/comm-rota.pdf"&gt;described&lt;/a&gt; by &lt;a href="http://en.wikipedia.org/wiki/Gian-Carlo_Rota"&gt;Gian-Carlo Rota&lt;/a&gt;, an accomplished twentieth century mathematician and lecturer, as having "been the object of such vociferous vituperation".  The book &lt;u&gt;Combinitorics the Rota Way&lt;/u&gt;, which he coauthored, gives deep insights into this subject and its relationship to other areas of math including, of course, combinatorics, but also topology, set theory, Boolean algebras, probability theory, and more.  I think Rota will be vindicated with a vengeance as it seems to me that lattices show up almost everywhere in math.  Additionally I feel that lattice theory will be become quintessential in computer science and software engineering and should be a mandatory math for those curricula.  I will expand on these ideas in follow up posts.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;One anecdote tells of a senior mathematician who stopped Rota in the halls of MIT and stared at him demanding: "Admit it! All lattice theory is trivial."  I confess I have some difficulty with lattice theory as it does seem to be both trivial and deep, at first the ideas don’t seem to really have that much substance, but deeper you dig the more things you find, and it seems that it is always showing up in other areas of math, and even if it is not obvious it often seems to be right under the surface.  I think that’s the duality here, the ideas, per se, are not that impressive, much of the importance comes from the application of the ideas and their relation to other areas of math.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;In George Gratzer’s updated &lt;u&gt;Lattice Theory : Foundation&lt;/u&gt; he states that a difference between the new addition and the previous edition is the addition of more diagrams, and recommends the reader drawing their own as well, in my opinion he does not go far enough, one of the goals of this post to have some pictures for the basic ideas.  I admit I will do my best here to help the motivated learner, but this post should probably be viewed as supplemental to other resources.  Also you will need to have some knowledge of set theory and concepts like Cartesian products and some knowledge of &lt;a href="http://en.wikipedia.org/wiki/Abstract_algebra"&gt;abstract algebra&lt;/a&gt; such as &lt;a href="http://en.wikipedia.org/wiki/Group_theory"&gt;group theory&lt;/a&gt; may also be helpful.  Also knowledge of basic &lt;a href="http://en.wikipedia.org/wiki/Graph_theory"&gt;graph theory&lt;/a&gt; is needed.  You will also need some comfort level with basic mathematical notation.  If you don’t have this knowledge, hopefully you are willing to get up to speed on it, trust me, it’s worth it.  Another point to note is that everything covered here will be finite, all sets, orderings, and lattices are &lt;a href="http://en.wikipedia.org/wiki/Finite_set"&gt;finite&lt;/a&gt;, I believe that much of this extends to the &lt;a href="http://en.wikipedia.org/wiki/Countable_set"&gt;countable infinite&lt;/a&gt;, etc.  I leave that for you to pursue.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Lattices_Drawn_as_Graphs"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Lattices Drawn as Graphs&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Lattices have some connections to &lt;a href="http://en.wikipedia.org/wiki/Graph_theory"&gt;graph theory&lt;/a&gt; and to really fully understand the nuances of these ideas you need to have an understanding of basic &lt;a href="http://www.elegantcoding.com/2011/08/object-graph.html"&gt;graph theory&lt;/a&gt;, specifically the differences between &lt;a href="http://en.wikipedia.org/wiki/Directed_graph"&gt;directed graphs&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Undirected_graph#Undirected_graph"&gt;undirected graphs&lt;/a&gt; and an understanding of &lt;a href="http://en.wikipedia.org/wiki/Graph_cycle"&gt;cycles&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Acyclic_graph"&gt;acyclic graphs&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-usflk-WVVv0/UFe4S1-kScI/AAAAAAAAAoM/cYZ0rKUYEJg/s1600/UnitLattice.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="300" width="380" src="http://1.bp.blogspot.com/-usflk-WVVv0/UFe4S1-kScI/AAAAAAAAAoM/cYZ0rKUYEJg/s400/UnitLattice.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Lattices can be drawn as graphs the main diagram used to visually represent lattices is the &lt;a href="http://en.wikipedia.org/wiki/Hasse_diagram"&gt;Hasse diagram&lt;/a&gt; which depict lattices as a &lt;a href="http://en.wikipedia.org/wiki/Undirected_graph#Undirected_graph"&gt;undirected graph&lt;/a&gt;, more on this below.  Also it should be noted that issues of &lt;a href="http://en.wikipedia.org/wiki/Planar_graph"&gt;graph planarity&lt;/a&gt; are ignored and two crossing edges, that is with no vertex, have no significance in terms of order, also sometimes for aesthetic reasons intersecting lines are shown as crossing behind other lines, again this has no impact on the order structure.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Binary_Relations"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Binary Relations&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Lattices are built on the concept of a &lt;a href="http://en.wikipedia.org/wiki/Binary_relation"&gt;binary relation&lt;/a&gt; on a non empty &lt;a href="http://en.wikipedia.org/wiki/Set_%28mathematics%29"&gt;set&lt;/a&gt;. This is usually expressed in terms of the &lt;a href="http://en.wikipedia.org/wiki/Cartesian_product"&gt;Cartesian product&lt;/a&gt; of a set with itself, where R is the relation and S is the set:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;R : S x S &amp;rarr; S&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;In this case the binary relation emits a member of the same set, which means it is &lt;a href="http://en.wikipedia.org/wiki/Closure_%28mathematics%29"&gt;closed&lt;/a&gt; on the set.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;For example for the set S = {a,b,c} a possible relation is the ordered pairs: R = {(a, c), (a, a), (b, c), (c, a)}.  In general a Binary Relation can be written as a set of ordered pairs.  When talking about orders there is a distinction as to whether the relationship between two elements in the set exists, meaning does the ordered pair (x,y) exist in R.  In the example above (b,c) exists, (b,c) &amp;isin; R. Also note that opposite relation of (b,c), (c,b) is not in R, (c,b) &amp;notin; R.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;This binary relation can be seen in the diagram below, each of the ordered pairs map to a directed edge:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-nCLGXOz3vzE/UFe41-fq8uI/AAAAAAAAAoY/GcXgmUnmTqU/s1600/Binary%2BRelation.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="363" width="400" src="http://3.bp.blogspot.com/-nCLGXOz3vzE/UFe41-fq8uI/AAAAAAAAAoY/GcXgmUnmTqU/s400/Binary%2BRelation.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name="Properties_of_Binary_Relations"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Properties of Binary Relations&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Binary Relations can have certain properties.  I feel this is the crux of understanding ordering relationships.  The first two properties are:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Reflexive_relation"&gt;Reflexive&lt;/a&gt; &amp;forall;x &amp;isin; S (x,x) &amp;isin; R&lt;/p&gt;&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Transitive_relation"&gt;Transitive&lt;/a&gt;&amp;forall; x,y,z &amp;isin; S if (x,y) &amp;isin; R  and (y,z) &amp;isin; R then (x,z) &amp;isin; R&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;If a binary relation has these two properties, that is it is Reflexive and Transitive then it is known as a &lt;a href="http://en.wikipedia.org/wiki/Preorder"&gt;preorder&lt;/a&gt; or &lt;b&gt;quasi-order&lt;/b&gt;.  This is a more general type of binary relation which we are not really interested in initially except in how it relates to two more specific types of binary relations.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The &lt;b&gt;symmetric&lt;/b&gt; property is defined as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Symmetric_relation"&gt;Symetric&lt;/a&gt; &amp;forall; x,y &amp;isin; S if (x,y) &amp;isin; R  then (y,x) &amp;isin; R&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;A &lt;b&gt;preorder&lt;/b&gt; with the symmetric property is known as an &lt;a href="http://en.wikipedia.org/wiki/Equivalence_relation"&gt;equivalence relation&lt;/a&gt;.  In terms of Lattice Theory this is another binary relation that we are not immediately interested in.  &lt;b&gt;Equivalence relations&lt;/b&gt; are well worth learning more about in their own right, as they play an important role in partitioning &lt;a href="http://en.wikipedia.org/wiki/Partition_of_a_set"&gt;sets&lt;/a&gt; which have interesting applications in &lt;a href="http://en.wikipedia.org/wiki/Abstract_algebra"&gt;abstract algebra&lt;/a&gt; in relation to &lt;a href="http://en.wikipedia.org/wiki/Quotient_set"&gt;quotients&lt;/a&gt; of &lt;a href="http://en.wikipedia.org/wiki/Quotient_group"&gt;groups&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Quotient_ring"&gt;rings&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Homomorphism"&gt;homomorphisms&lt;/a&gt; of &lt;a href="http://en.wikipedia.org/wiki/Group_%28mathematics%29"&gt;groups&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Ring_%28mathematics%29"&gt;rings&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The next property, which we are very interested in, is the &lt;a href="http://en.wikipedia.org/wiki/Antisymmetric_relation"&gt;antisymmetric&lt;/a&gt; property which is defined as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Symmetric_relation"&gt;Antisymmetric&lt;/a&gt; &amp;forall; x,y &amp;isin; S if (x,y) &amp;isin; R and (y,x) &amp;isin; R then x = y&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;A &lt;b&gt;preorder&lt;/b&gt; with the &lt;b&gt;antisymmetric&lt;/b&gt; property is known as an &lt;a href="http://en.wikipedia.org/wiki/Order_relation"&gt;order relation&lt;/a&gt; sometimes referred to as a &lt;b&gt;partial order&lt;/b&gt;. A set with a &lt;a href="http://en.wikipedia.org/wiki/Partially_ordered_set"&gt;partial order&lt;/a&gt; on it is called a &lt;a href="http://en.wikipedia.org/wiki/Partially_ordered_set"&gt;partially ordered set&lt;/a&gt;, &lt;b&gt;poset&lt;/b&gt;, or just an &lt;b&gt;ordered set&lt;/b&gt;.  So now we have a definition of an order:&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;If S is a non-empty set then by an order on S we mean a binary relation on S that is reflexive, anti-symmetric, and transitive.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;We will now use the less than equals symbol &amp;le; to denote our order relation which follows as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;table border="0"&gt;&lt;tr&gt;&lt;td&gt;(&amp;forall;x&amp;isin; S) x &amp;le; x;                                     &lt;/td&gt;&lt;td&gt;(reflexive)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;(&amp;forall;x, y &amp;isin; S) if x &amp;le; y and y &amp;le; x then x = y;      &lt;/td&gt;&lt;td&gt;(antisymmetric)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;(&amp;forall;x, y, z &amp;isin; S) if x &amp;le; y and y &amp;le; z then x &amp;le; z.&lt;/td&gt;&lt;td&gt;(transitive)&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;In general an order is defined using the notational convention: (S, &amp;le;) where S is the Set on which  the order is defined and &amp;le; denotes ordering relation.  &lt;b&gt;Note&lt;/b&gt;:  &amp;le; is not necessarily the same as less than or equals, it might be, but it could also be a number of other order relations.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Comparability_Partial_Orders_Total_Orders_Antichains"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Comparability: Partial Orders, Total Orders and Antichains&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;One thing that I found confusing when learning about &lt;b&gt;ordering relations&lt;/b&gt; is the difference between a &lt;b&gt;total order&lt;/b&gt; and a &lt;b&gt;partial order&lt;/b&gt;.  The idea of a &lt;b&gt;partial order&lt;/b&gt; is that not all elements in a set have a relation.  Some pairs of elements are incomparable, meaning no relation exists between them.  This is denoted using the parallel lines symbol: &amp;#x2225;, for example x &amp;#x2225; y means (x,y) &amp;notin; R and (y,x) &amp;notin; R. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;An example of a partial order is the set of partitions below:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-vKrYbY45pNI/UFe5HhfjbDI/AAAAAAAAAok/w0JwhKHPr7I/s1600/setPartitionLattice.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="260" width="380" src="http://3.bp.blogspot.com/-vKrYbY45pNI/UFe5HhfjbDI/AAAAAAAAAok/w0JwhKHPr7I/s400/setPartitionLattice.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;This is a partial order of set partitions of a set of three items.  For example suppose that the set {a,b,c} is a plate containing an apple, a banana and a cherry.  As you move down the lattice you get more partitions, in the second row you can partition two pieces of fruit onto one plate and one on another, in three different ways {a}, {b,c}  or  {b}, {a,c}  or  {c}, {a,b} .  In the bottom row you can only partition three pieces of fruit one way on three different plates {a},{b},{c}.  If you move up the lattice you can reverse the operation and consolidate the set partitions (plates) in the same manner. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;You should note that above the elements:  a|bc,  b|a,c, and c|a,b have no ordering relation to each other, that is there is no way to further partition the current plates, rearranging them isn’t allowed. So these items are incomparable: a|bc  &amp;#x2225;  b|a,c,   b|a,c  &amp;#x2225;  c|a,b , ...&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;A &lt;a href="http://en.wikipedia.org/wiki/Total_order"&gt;total order&lt;/a&gt; is also known as a &lt;b&gt;linear order&lt;/b&gt; or a &lt;b&gt;chain&lt;/b&gt;. In a &lt;b&gt;total order&lt;/b&gt; all elements are comparable meaning that the relationship has the following total property:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Total_relation"&gt;Total&lt;/a&gt; &amp;forall; x,y &amp;isin; S  (x,y) &amp;isin; R  or  (y,x) &amp;isin; R&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;A fairly simple example of a &lt;b&gt;chain&lt;/b&gt; is the integers 1-5 with the ordering relation less than or equals, which would be written as ({1,2,3,4,5}, &amp;le;) which would have the following diagram:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-P1JXOZ6vFA0/UFe5bbgZ-VI/AAAAAAAAAow/epv1swSP14c/s1600/totalOrder.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="240" width="40" src="http://4.bp.blogspot.com/-P1JXOZ6vFA0/UFe5bbgZ-VI/AAAAAAAAAow/epv1swSP14c/s400/totalOrder.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;An &lt;a href="http://en.wikipedia.org/wiki/Antichain"&gt;antichain&lt;/a&gt; is a set where no two elements are comparable:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Antichain"&gt;Antichain&lt;/a&gt; &amp;forall; x,y &amp;isin; S  (x,y) &amp;notin; R  and (y,x) &amp;notin; R&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;An example is the suits of a card deck, there are probably some exceptions, but in general a spade, a heart, a club and a diamond have no order relation to each other, this antichain can be depicted as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-hdiXfMfxclI/UFe5kA4Kh_I/AAAAAAAAAo8/W16cym4FcSM/s1600/Antichain.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="198" width="276" src="http://4.bp.blogspot.com/-hdiXfMfxclI/UFe5kA4Kh_I/AAAAAAAAAo8/W16cym4FcSM/s400/Antichain.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Also you should note that above the elements:  a|bc,  b|a,c, and c|a,b in our set partition lattice above form an &lt;b&gt;antichain&lt;/b&gt; within that lattice.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Order_Duality"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Order Duality&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Order duality is actually a fairly intuitive idea, for example if you had a list of words in alphabetical order, you can reverse the order. This holds true for every ordering relation and is called the &lt;a href="http://en.wikipedia.org/wiki/Duality_%28order_theory%29"&gt;Duality principle&lt;/a&gt;.  More formally if you have an order P = (S, &amp;le;), its dual denoted P&lt;sup&gt;d&lt;/sup&gt; would be defined as P&lt;sup&gt;d&lt;/sup&gt; =(S, &amp;ge;).  If you take any of the lattice examples above or below and reverse them, flip them upside-down, you get the dual of the order relation.  This is one of the most seminal ideas in order theory. It also shows up in other parts of math.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Powerset_Lattice"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;The Powerset Lattice&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;The &lt;a href="http://en.wikipedia.org/wiki/Powerset"&gt;powerset&lt;/a&gt; of set is a set of all of the &lt;a href="http://en.wikipedia.org/wiki/Subset"&gt;subsets&lt;/a&gt; of the set.  For a set of three items, S = {a,b,c} The power set of S, which is a set of sets, is: { {a,b,c}, {a,b }, {a,c}, {b,c}, {a}, {b}, {c}, &amp;empty; }.  A common notation for denoting the powerset is 2&lt;sup&gt;S&lt;/sup&gt;.  This notation draws from the fact that the cardinality of the &lt;b&gt;powerset&lt;/b&gt; is the cardinality, the size of the set, of the set raised to the power of 2, this can be expressed more concisely using the notation |S| to describe cardinality, so the above set has the cardinality |S| = 3. The powerset of S 2&lt;sup&gt;S&lt;/sup&gt; has the cardinality |2&lt;sup&gt;S&lt;/sup&gt; | = 2&lt;sup&gt;3&lt;/sup&gt; = 8.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The &lt;b&gt;lattice&lt;/b&gt; below shows the &lt;b&gt;ordering relation&lt;/b&gt; "is a subset of", this can be denoted by &amp;sube; and the order would be given in notational form as (2&lt;sup&gt;S&lt;/sup&gt;, &amp;sube;).&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-_Ied0sENdtM/UFe51TF9PJI/AAAAAAAAApI/MFcXHKj-n9w/s1600/powerSetLatticeUp.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="320" width="380" src="http://4.bp.blogspot.com/-_Ied0sENdtM/UFe51TF9PJI/AAAAAAAAApI/MFcXHKj-n9w/s400/powerSetLatticeUp.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Its &lt;b&gt;order dual&lt;/b&gt; which is "is a superset of" given by (2&lt;sup&gt;S&lt;/sup&gt;, &amp;supe;):&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-GDOiyEW8cV8/UFe6uJt-LwI/AAAAAAAAApU/5VeVpnOJERE/s1600/powerSetLatticeDown.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="320" width="380" src="http://4.bp.blogspot.com/-GDOiyEW8cV8/UFe6uJt-LwI/AAAAAAAAApU/5VeVpnOJERE/s400/powerSetLatticeDown.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name="Binary_Relations_Drawn_as_Graphs"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Binary Relations Drawn as Graphs&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Now that we have some definitions and diagrams in place I wanted to revisit the drawing of lattice diagrams.  Our first relation diagram above has a loop for (a,a) and (b,c) (c,a) makes it &lt;b&gt;transitive&lt;/b&gt;, but it is not &lt;b&gt;reflexive&lt;/b&gt; because it is missing loops for b and c.  So that relation is not a &lt;b&gt;preorder&lt;/b&gt; which means it is also neither an &lt;b&gt;equivalence relation&lt;/b&gt; nor an &lt;b&gt;ordering relation&lt;/b&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;For every preorder, there corresponds a &lt;a href="http://en.wikipedia.org/wiki/Directed_graph"&gt;directed graph&lt;/a&gt;, with elements of the set corresponding to vertices, and the order relation between pairs of elements corresponding to the directed edges between vertices.  Graphs of preorders can contain cycles.  Also all nodes in a preorder group will have a &lt;a href="http://en.wikipedia.org/wiki/Loop_%28graph_theory%29"&gt;loop&lt;/a&gt; for the reflexive relation that must exists on each node.  Graphs representing equivalence relations will be &lt;a href="http://en.wikipedia.org/wiki/Graph_%28mathematics%29#Undirected_graph"&gt;undirected graphs&lt;/a&gt; since these &lt;b&gt;relations&lt;/b&gt; are &lt;b&gt;symmetric&lt;/b&gt; and will of course have loops on each vertex for reflexivity.   As mentioned above graphs for partial orders will be a &lt;a href="http://en.wikipedia.org/wiki/Directed_acyclic_graph"&gt;directed acyclic graph&lt;/a&gt; graph due to antisymmetry also they should have reflexivity loops.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The total order for 1-6 mentioned above would look as follows for the relation &amp;le; it is a simple directed graph:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-8hTjBR9__ns/UFe69irdS5I/AAAAAAAAApg/-Xt6BC-LvL4/s1600/total2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="62" src="http://1.bp.blogspot.com/-8hTjBR9__ns/UFe69irdS5I/AAAAAAAAApg/-Xt6BC-LvL4/s400/total2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;If we were to add all of the transitive and reflexive relations it would look like this:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-mmoCeR2ZDx0/UFe7HpgbWGI/AAAAAAAAAps/T9lTE505qVs/s1600/total.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="200" src="http://3.bp.blogspot.com/-mmoCeR2ZDx0/UFe7HpgbWGI/AAAAAAAAAps/T9lTE505qVs/s400/total.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;As we have seen in our diagrams the reflexivity loops are omitted as they are not needed and would be increase the complexity of the diagrams.  Also in the diagrams the transitivity can be inferred by following the two paths connecting three nodes.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Hasse diagrams are drawn as undirected graphs which implies the order duality, we can decompose that graph into two directed graphs as in our example above for the two dual realtions (subset &amp;sube; and superset &amp;supe;) on the powerset lattice, the lattice is conventionally drawn as the following Hasse diagram: &lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-PjNhNlg78hY/UFe7P-jjcLI/AAAAAAAAAp4/K-RnF1WwJAk/s1600/PowerSetLattice.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="300" width="380" src="http://4.bp.blogspot.com/-PjNhNlg78hY/UFe7P-jjcLI/AAAAAAAAAp4/K-RnF1WwJAk/s400/PowerSetLattice.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Another interesting point here is the difference between equivalence relations and order relations is that no cycles will occur in an ordering relation.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Subsets_of_Posets"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Subsets of Posets&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Since we are dealing with sets, a set with an order relation, a poset (short for partially ordered set), can have subsets.  The interesting thing is that the subsets as a whole can be different types of orders than the original poset.  For example the power set above has as a sub-poset, {a,b,c}-{a,b}-{a}-&amp;empty;, which is a total order.  Additionally the antichain {{a,b}  {a,c}  {b,c}} is also a subset of the powerset poset.  These elements still have the same relations as they did in the original set, but the subsets themselves are different structures.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Upper_and_Lower_Bounds"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Upper and Lower Bounds&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;A finite set, remember we are only considering finite sets, with an order relation implies that if you move up and down the ordering relation eventually you will hit a maximum or minimum element.  The above examples, the total order has an upper bound of 5 and lower bound of 1, the powerset lattice has an upper bound of the set itself and the empty set as a lower bound.  The antichain does not have a single upper or lower bound the four elements are each both their upper and their lower bounds.  The idea of &lt;a href="http://en.wikipedia.org/wiki/Upper_and_lower_bounds"&gt;bounds&lt;/a&gt;, specifically the idea of &lt;b&gt;greatest lower bound&lt;/b&gt; (&lt;b&gt;GLB&lt;/b&gt;)  which is also known as an &lt;a href="http://en.wikipedia.org/wiki/Infimum"&gt;infimum&lt;/a&gt; and the dual the &lt;b&gt;least upper bound&lt;/b&gt; (&lt;b&gt;LUB&lt;/b&gt;) which also known as the &lt;a href="http://en.wikipedia.org/wiki/Supremum"&gt;supremum&lt;/a&gt; are important in order theory but show up in other areas of math such as topology.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;A poset may not have one upper or lower bound, this is a distinction from a lattice which is still a poset but it has a single upper and lower bound.   A lattice will have both a distinct upper and distinct lower bound, that is one element that is the upper bound and one element that is the lower bound. These are sometimes denoted as &amp;#x22A4; for upper bound and &amp;perp; for lower bound.  This bounding feature of lattices is very important as we will see.&lt;/p&gt;&lt;br /&gt;
&lt;a name="The_Samuel_L_Jackson_Lattice"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;The Samuel L Jackson Lattice (Total Order)&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Since Samuel L. Jackson has a habit of showing up everywhere, he is the new Kevin Bacon, and it is only fitting that he would show up in Lattice Theory.  Another example of a &lt;b&gt;total order&lt;/b&gt; or &lt;b&gt;chain&lt;/b&gt; is what is known as the "&lt;a href="http://www.thedailyshow.com/watch/wed-june-23-2010/samuel-l--jackson-scale-of-black-emotion"&gt;Samuel L. Jackson Scale of Black Emotion&lt;/a&gt;" which was developed by Larry Willmore of the Daily Show.  It forms a &lt;b&gt;Total Order&lt;/b&gt; also known as the &lt;b&gt;Samuel L Jackson Lattice&lt;/b&gt;, which includes the following elements:&lt;/p&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Furious Anger Guy&lt;/li&gt;
&lt;li&gt;Shaft&lt;/li&gt;
&lt;li&gt;Changing Lanes Guy&lt;/li&gt;
&lt;li&gt;Snakes on a Plane Guy&lt;/li&gt;
&lt;li&gt;Jurrasic Park Jackson &lt;/li&gt;
&lt;li&gt;Frozone&lt;/li&gt;
&lt;li&gt;Mace Windu&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;p&gt;As you can see the sup(&lt;b&gt;Samuel L. Jackson Lattice&lt;/b&gt;) = &amp;#x22A4; = "Furious Anger Guy" and the inf(&lt;b&gt;Samuel L. Jackson Lattice&lt;/b&gt;) = &amp;perp; = "Mace Windu". Now it’s pretty obvious in an intuitive human sense that the Master of the Order and Jedi &lt;a href="http://starwars.wikia.com/wiki/Mace_Windu"&gt;Master Mace Windu&lt;/a&gt; is the &lt;b&gt;lattice&lt;/b&gt; &lt;b&gt;dual&lt;/b&gt; of Furious Anger Guy of Pulp Fiction, well up to his epiphany in the diner robbery scene anyway.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;As with all lattices, this lattice has an &lt;b&gt;order dual&lt;/b&gt; denoted (&lt;b&gt;Samuel L Jackson Lattice&lt;/b&gt;)&lt;sup&gt;d&lt;/sup&gt; known as the &lt;b&gt;Inverse Samuel L Jackson Lattice&lt;/b&gt;, which just a reverse of the above list.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Ok, I’m having a little fun here, trying to lighten the mood a little.  However, this is a legitimate example of a lattice.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Lattices_vs_Posets"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Lattices vs Posets&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;By definition a lattice is a poset, however, a poset is not necessarily a lattice.  A lattice is defined as, with sup being supremum and inf being infimum:&lt;/p&gt;&lt;div class="source-code"&gt;&lt;p&gt;An order (S,&amp;le;) is a lattice if sup{a,b} and inf{a,b} exist &amp;forall; a, b &amp;isin; S.&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Actually there are some distinctions between different classes of lattices:&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;A &lt;b&gt;lattice&lt;/b&gt; is a poset in which all &lt;b&gt;nonempty finite subsets&lt;/b&gt; have both a least upper bound and a greatest lower bound.&lt;/p&gt;&lt;p&gt;A &lt;b&gt;complete lattice&lt;/b&gt; is a poset in which &lt;b&gt;&lt;i&gt;all &lt;/i&gt;&lt;/b&gt;&lt;b&gt;subsets&lt;/b&gt; have both a least upper bound and a greatest lower bound.&lt;/p&gt;&lt;p&gt;A &lt;b&gt;bounded lattice&lt;/b&gt; has a unique top element and a unique bottom element, actually there are algebraic implications that we will discuss below.&lt;/p&gt;&lt;p&gt;Finite sets form complete lattices and since we are limiting ourselves to finite sets we will only be dealing with complete lattices. Also every complete lattice is a bounded lattice so when we talk about lattices here we will mean complete lattices aka bounded lattices.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Up_and_Down_Sets"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Up and Down Sets&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;If you take an element of a poset or a Lattice and take the subset of all elements that are greater than the element you get a new poset or lattice that is a subset, these types of subsets are referred to as &lt;a href="http://en.wikipedia.org/wiki/Upper_set"&gt;up-sets&lt;/a&gt; or down-sets. An up-set of an element x denoted as &amp;uarr; x includes the element and everything above it is defined as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;&amp;uarr; x = {y&amp;isin; P : y &amp;ge; x}&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The up-set of the element {a} in the powerset lattice above would look like (shown in blue):&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-wI5ZhKTifjc/UFe7kA6CEbI/AAAAAAAAAqE/q9RAMIC8c0E/s1600/PowerSetLatticeUpperSet1.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="300" width="380" src="http://4.bp.blogspot.com/-wI5ZhKTifjc/UFe7kA6CEbI/AAAAAAAAAqE/q9RAMIC8c0E/s400/PowerSetLatticeUpperSet1.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Similarly, or perhaps "dually" the down set, denoted as &amp;darr; x, is defined as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;&amp;darr; x = {y&amp;isin; P : y &amp;le; x}&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;With the down-set of the element {a,b} in the powerset lattice (in red):&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-gusLUd-yNfE/UFe7xRGK9XI/AAAAAAAAAqQ/8qVrWxBQiQI/s1600/PowerSetLatticeDownSet.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="300" width="380" src="http://1.bp.blogspot.com/-gusLUd-yNfE/UFe7xRGK9XI/AAAAAAAAAqQ/8qVrWxBQiQI/s400/PowerSetLatticeDownSet.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name="&gt;Meet_and_Join"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Meet and Join&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Join_and_meet"&gt;Meet and Join&lt;/a&gt; are two binary operators defined on elements of posets and and lattices which yield a unique value and they are dual operations of each other.  In the case of a poset meet and join may or may not exist on any two elements, in the case of a bounded lattice they will exist.  Join is usually denoted with the or symbol: &amp;or; and meet is denoted with the and symbol: &amp;and;.  Join is equivalent to supremum and meet is equivalent to infumum. They are defined as: &lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;x &amp;or; y = sup{x,y}&lt;/p&gt;&lt;p&gt;x &amp;and; y = inf{x, y}&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The following describes their relation with ordering:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;x &amp;le; y  &amp;hArr; x &amp;or;  y = y&lt;/p&gt;&lt;p&gt;x &amp;le; y  &amp;hArr; x &amp;and;  y = x&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;As you can see above when two elements are comparable meet and join will reduce to the appropriate minimum or maximum element, when two elements are incomparable as in the picture of the join below between {a} &amp;or; {c} the lattice lines show how the join moves up to the element {a,c} that is above each element, not coincidently the join on this lattice is the set union operation &amp;cup; actually this join can be expressed as {a,c} = {a} &amp;cup; {c} which is right out of set theory.&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-wZwFA9PnzuE/UFe9N1DAqJI/AAAAAAAAAqc/zsh5ty-caz0/s1600/PowerSetLatticeAjoinC.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="320" width="380" src="http://1.bp.blogspot.com/-wZwFA9PnzuE/UFe9N1DAqJI/AAAAAAAAAqc/zsh5ty-caz0/s400/PowerSetLatticeAjoinC.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;And the dual relation is {a} &amp;cap; {c} = &amp;empty;:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-UHc5KgX7VsM/UFe9dP6emjI/AAAAAAAAAqo/miKkXX69nFA/s1600/powerSetLatticeAMeetC.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="320" width="380" src="http://4.bp.blogspot.com/-UHc5KgX7VsM/UFe9dP6emjI/AAAAAAAAAqo/miKkXX69nFA/s400/powerSetLatticeAMeetC.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name="Semilattices"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Semilattices&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;A semilattice will define either a meet or a join operation over an order resulting in either a meet  semilattice or join semilattice, technically a lattice is both of these combined. A good example is a tree which as a single root node, let’s call it a lower bound aka an infimum, a common example is the prefix tree for strings, in this case we are using binary strings 0 or 1 up to length three:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-TfakS9xpe-A/UFe9uXHu6AI/AAAAAAAAAq0/L9hc_hYltxQ/s1600/PrefixTree.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="280" width="380" src="http://1.bp.blogspot.com/-TfakS9xpe-A/UFe9uXHu6AI/AAAAAAAAAq0/L9hc_hYltxQ/s400/PrefixTree.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;In this example the order relation is: "Is a prefix of".  As you can see you can define a meet on any two elements with the empty string &amp;lambda; serving as the semi-lattice bottom &amp;perp;. Also as you can see there are no joins on this order.  Pretty much any tree can be viewed as semi lattice with descendency from the root node through all of the other nodes serving as the ordering relation.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Lattices_are_Algebraic"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Lattices are Algebraic&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;One of the interesting and sometimes confusing things about lattices is that, while they are structural they are also algebraic.  Meet and join follow a number of algebraic rules.  In general lattices can be defined as an algebra L=(S, &amp;and;, &amp;or;) which satisfy the following algebraic rules for all x, y, z &amp;isin; S:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Idempotent"&gt;Idempotent &lt;/a&gt;&lt;/p&gt;&lt;p&gt;x &amp;and; x = x&lt;/p&gt;&lt;p&gt;x &amp;or; x = x,&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Commutative_property"&gt;Commutative&lt;/a&gt;&lt;/p&gt;&lt;p&gt;x &amp;and; y = y &amp;and; x&lt;/p&gt;&lt;p&gt;x &amp;or; y = y &amp;or; x,&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Associative_property"&gt;Associative&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;x &amp;and; (y &amp;and; z) = (x &amp;and; y) &amp;and; z&lt;/p&gt;&lt;p&gt;x &amp;or; (y &amp;or; z) = (x &amp;or; y) &amp;or; z,&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Absorption_law"&gt;Absorption&lt;/a&gt;&lt;/p&gt;&lt;p&gt;x &amp;and; (x &amp;or; y) = x&lt;/p&gt;&lt;p&gt;x &amp;or; (x &amp;and; y) = x.&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The first three pairs of axioms say that L is both a meet and join semilattice. The fourth pair (the absorption laws) say that both operations induce the same order on L.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Since we are dealing with bounded lattices we extend the above laws to include the following for the top and bottom elements, here we will represent the bottom element &amp;perp; as 0 and the top element &amp;top; as 1.  For a bounded lattice the algebra is defined as L=(S, &amp;and;, &amp;or;, 0, 1) with the following identity laws:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;x &amp;or; 0 = x&lt;/p&gt;&lt;p&gt;x &amp;and; 1 = x&lt;/p&gt;&lt;p&gt;x &amp;and; 0 = 0&lt;/p&gt;&lt;p&gt;x &amp;or; 1 = 1&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;For our powerset lattice above the algebra is (S, &amp;cap;, &amp;cup;, &amp;empty;, S) with the empty set as the identity for the union operation and the set itself as the identity for the intersection.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Distributive"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Other Lattice Properties and Operations&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;If you take our powerset example above, you might have noticed that there are some more algebraic properties of this lattice that are not listed above.  The first is the distributive property.  While the powerset lattice does have the distributive property you should note that not all lattices do.  The &lt;a href="http://en.wikipedia.org/wiki/Distributivity_%28order_theory%29"&gt;distributive property&lt;/a&gt; is defined as:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;&lt;b&gt;Distributive&lt;/b&gt; &lt;b&gt;Law&lt;/b&gt;&lt;/p&gt;&lt;p&gt;x &amp;or; (y &amp;and; z) = (x &amp;or; y) &amp;and; (x &amp;or; z)&lt;/p&gt;&lt;p&gt;x &amp;and; (y &amp;or; z) = (x &amp;and; y) &amp;or; (x &amp;and; z)&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Another property which can be found in certain lattices and also applies to our powerset lattice is the property of &lt;a href="http://en.wikipedia.org/wiki/Complemented_lattice"&gt;complementation&lt;/a&gt; which means that for every element x the lattice has a complement y under both the meet and join operations:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;x &amp;and; y = 0&lt;/p&gt;&lt;p&gt;x &amp;or; y = 1&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Some Lattice which are Complemented can have additional properties which is known as orthocomplementation and has the following laws:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;&lt;b&gt;Complement Law&lt;/b&gt;&lt;/p&gt;&lt;p&gt;x &amp;and; x&lt;sup&gt;c&lt;/sup&gt; = 0&lt;/p&gt;&lt;p&gt;x &amp;or; x&lt;sup&gt;c&lt;/sup&gt; = 1&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;b&gt;Involution Law&lt;/b&gt;&lt;/p&gt;&lt;p&gt;(x&lt;sup&gt;c&lt;/sup&gt;)&lt;sup&gt;c&lt;/sup&gt; = x&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;b&gt;Order Reversing&lt;/b&gt;&lt;/p&gt;&lt;p&gt;x &amp;le; y then y&lt;sup&gt;c&lt;/sup&gt; &amp;le; x&lt;sup&gt;c&lt;/sup&gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Our power set lattice which is also a &lt;a href="http://en.wikipedia.org/wiki/Boolean_algebra_%28structure%29"&gt;Boolean Algrebra&lt;/a&gt; also follows &lt;a href="http://en.wikipedia.org/wiki/De_Morgan%27s_laws"&gt;Demorgans laws&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;&lt;b&gt;Demorgans laws&lt;/b&gt;&lt;/p&gt;&lt;p&gt;(x &amp;or; y)&lt;sup&gt;c&lt;/sup&gt; = x&lt;sup&gt;c&lt;/sup&gt; &amp;and; y&lt;sup&gt;c&lt;/sup&gt;&lt;/p&gt;&lt;p&gt;(x &amp;and; y)&lt;sup&gt;c&lt;/sup&gt; = x&lt;sup&gt;c&lt;/sup&gt; &amp;or; y&lt;sup&gt;c&lt;/sup&gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Some lattices can have a property known as &lt;a href="http://en.wikipedia.org/wiki/Modular_lattice"&gt;Modularity&lt;/a&gt; which follows the following law, which is similar to the distributive law:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;&lt;b&gt;Modular law&lt;/b&gt;&lt;/p&gt;&lt;p&gt;x &amp;le; z implies x &amp;or; (y &amp;and; z) = (x &amp;or; y) &amp;and; z&lt;/p&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;I am including Modularity for completeness as I am not discussing it or including examples.  Distributivity, Modularity and Complementation have many intricacies and there is much theory and complexity surrounding how these work and where they show up, this becomes quickly obvious if you dig into more resources on lattices.&lt;/p&gt;&lt;br /&gt;
&lt;a name="The_Algebraic_Structure_of_the_Powerset_Lattice"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;The Algebraic Structure of the Powerset Lattice&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;With the above algebraic laws of complemented (orthocomplemented) bounded lattices defined, I figured it might be nice to list out these laws as they apply to our powerset lattice, if we take the powerset 2&lt;sup&gt;S&lt;/sup&gt; of any set S, the empty set &amp;empty; is the lower bound and the set S is the upper bound. The powerset lattice has the following laws:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;&lt;b&gt;Idempotent&lt;/b&gt;&lt;/p&gt;&lt;p&gt;x &amp;cap; x = x&lt;/p&gt;&lt;p&gt;x &amp;cup; x = x&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;b&gt;Commutative&lt;/b&gt;&lt;/p&gt;&lt;p&gt;x &amp;cap; y = y &amp;cap; x&lt;/p&gt;&lt;p&gt;x &amp;cup; y = y &amp;cup; x&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;b&gt;Associative&lt;/b&gt;&lt;/p&gt;&lt;p&gt;x &amp;cap; (y &amp;cap; z) = (x &amp;cap; y) &amp;cap; z&lt;/p&gt;&lt;p&gt;x &amp;cup; (y &amp;cup; z) = (x &amp;cup; y) &amp;cup; z&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;b&gt;Absorption&lt;/b&gt;&lt;/p&gt;&lt;p&gt;x &amp;cap; (x &amp;cup; y) = x&lt;/p&gt;&lt;p&gt;x &amp;cup; (x &amp;cap; y) = x&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;b&gt;Distributive&lt;/b&gt;&lt;/p&gt;&lt;p&gt;x &amp;cup; (y &amp;cap; z) = (x &amp;cup; y) &amp;cap; (x &amp;cup; z)&lt;/p&gt;&lt;p&gt;x &amp;cap; (y &amp;cup; z) = (x &amp;cap; y) &amp;cup; (x &amp;cap; z)&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;b&gt;Identity&lt;/b&gt;&lt;/p&gt;&lt;p&gt;x &amp;cup; &amp;empty; = x&lt;/p&gt;&lt;p&gt;x &amp;cap; S = x&lt;/p&gt;&lt;p&gt;x &amp;cap; &amp;empty; = &amp;empty;&lt;/p&gt;&lt;p&gt;x &amp;cup; S = S&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;b&gt;Complement Law&lt;/b&gt;&lt;/p&gt;&lt;p&gt;x &amp;cap; x&lt;sup&gt;c&lt;/sup&gt; = &amp;empty;&lt;/p&gt;&lt;p&gt;x &amp;cup; x&lt;sup&gt;c&lt;/sup&gt; = S&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;b&gt;Involution Law&lt;/b&gt;&lt;/p&gt;&lt;p&gt;(x&lt;sup&gt;c&lt;/sup&gt;)&lt;sup&gt;c&lt;/sup&gt; = x&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;b&gt;Order Reversing&lt;/b&gt;&lt;/p&gt;&lt;p&gt;x &amp;sube; y  then  y&lt;sup&gt;c&lt;/sup&gt; &amp;sube; x&lt;sup&gt;c&lt;/sup&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;b&gt;Demorgans laws&lt;/b&gt;&lt;/p&gt;&lt;p&gt;(x &amp;cup; y)&lt;sup&gt;c&lt;/sup&gt; = x&lt;sup&gt;c&lt;/sup&gt; &amp;cap; y&lt;sup&gt;c&lt;/sup&gt;&lt;/p&gt;&lt;p&gt;(x &amp;cap; y)&lt;sup&gt;c&lt;/sup&gt; = x&lt;sup&gt;c&lt;/sup&gt; &amp;cup; y&lt;sup&gt;c&lt;/sup&gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name="The_D4_Dihedral_Subgroup_Lattice"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;The D4 Dihedral Subgroup Lattice&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;This topic might be filed under an advanced example, so feel free to skip if you’ve had enough for the moment.  In doing my research I came across the following lattice diagram, it is the lattice of the &lt;a href="http://en.wikipedia.org/wiki/Lattice_of_subgroups"&gt;subgroups&lt;/a&gt; of the D&lt;sub&gt;4&lt;/sub&gt; &lt;a href="http://en.wikipedia.org/wiki/Dihedral_group"&gt;Dihedral Group&lt;/a&gt;, I looked at cyclic groups and subgroups including the cyclic subgroups of D&lt;sub&gt;4&lt;/sub&gt; in a &lt;a href="http://www.elegantcoding.com/2012/03/interesting-group.html"&gt;previous post&lt;/a&gt; on abstract algebra.  I have modified it to better show the identity element marked in blue. It also includes the names of well known isomorphic groups that correspond to each subgroup.&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-viKdECV2S1w/UFe94L7vAII/AAAAAAAAArA/ouwspA9bqY4/s1600/500px-Dih4_subgroups_svg%2B-%2BModified.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="370" width="400" src="http://1.bp.blogspot.com/-viKdECV2S1w/UFe94L7vAII/AAAAAAAAArA/ouwspA9bqY4/s400/500px-Dih4_subgroups_svg%2B-%2BModified.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;This lattice shows some really interesting things about the dihedral group.  The top element is the D&lt;sub&gt;4&lt;/sub&gt; group itself and the bottom element is the trivial Z&lt;sub&gt;1&lt;/sub&gt; group consisting of only the identity.  As you can see the center forms a chain consisting of three cyclic groups, Z&lt;sub&gt;1&lt;/sub&gt;, Z&lt;sub&gt;2&lt;/sub&gt;, Z&lt;sub&gt;4&lt;/sub&gt;, and D&lt;sub&gt;4&lt;/sub&gt; (not cyclical).  The anti-chain of five Z&lt;sub&gt;2&lt;/sub&gt; isomorphic groups, all of which are &lt;a href="http://en.wikipedia.org/wiki/Involution_%28mathematics%29"&gt;involutions&lt;/a&gt;, like negation it is an operation which if applied twice results in the original value, on the left are the horizontal (H) and vertical (V) reflection involutions, the middle one is a 180 degree rotation (R&lt;sub&gt;2&lt;/sub&gt;) involution and on the right are two diagonal (D&lt;sub&gt;1&lt;/sub&gt;, D&lt;sub&gt;2&lt;/sub&gt;) reflection involutions. As you can see on the vertical and horizontal involutions on the left along with the rotation involution form the group (R&lt;sub&gt;0&lt;/sub&gt;, V, H, R&lt;sub&gt;2&lt;/sub&gt;) and on similarly on the right the subgroup (R&lt;sub&gt;0&lt;/sub&gt;, D&lt;sub&gt;1&lt;/sub&gt;, D&lt;sub&gt;2&lt;/sub&gt;, R&lt;sub&gt;2&lt;/sub&gt;) is formed.  Also both of these groups are isomorphic to what is known as the &lt;a href="http://en.wikipedia.org/wiki/Klein_four-group"&gt;V group&lt;/a&gt;, aka the four group, aka Klein group, aka the Vierergruppe.  I am not sure what all of this means but I find it fascinating.  Also please note that there is a minor nomenclature conflict as V refers to both the Klein group and the vertical reflection D&lt;sub&gt;4&lt;/sub&gt; group element, but the context of each is mutually exclusive. The same goes for D&lt;sub&gt;n&lt;/sub&gt; where D&lt;sub&gt;1&lt;/sub&gt; and D&lt;sub&gt;2&lt;/sub&gt; are elements and D&lt;sub&gt;4&lt;/sub&gt; is a group.  Additionally this lattice give a nice visual depiction of &lt;a href="http://en.wikipedia.org/wiki/Lagrange%27s_theorem_%28group_theory%29"&gt;Lagrange's Theorem&lt;/a&gt; which states that the order of each subgroup will evenly divide the order of the group.  Therefore, as in the lattice, a group of order 8 only has subgroups of orders 4,2,1.&lt;br /&gt;
&lt;br /&gt;
&lt;a name="Notation"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Some Notes on Notation&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;In math notation can vary and order theory has several variants on notation that it helps to be aware of.  Firstly the following sets of symbols can often be used in relations to orders:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Q5nnMHs2v5M/UFfBV1mzSYI/AAAAAAAAArY/pjw9vl_wMD4/s1600/wedge.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="14" width="65" src="http://4.bp.blogspot.com/-Q5nnMHs2v5M/UFfBV1mzSYI/AAAAAAAAArY/pjw9vl_wMD4/s400/wedge.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-AEaMHwc2ks8/UFfBeflWTMI/AAAAAAAAArk/CuI9rINdSvo/s1600/sqcap.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="14" width="66" src="http://1.bp.blogspot.com/-AEaMHwc2ks8/UFfBeflWTMI/AAAAAAAAArk/CuI9rINdSvo/s400/sqcap.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-h781-968aE8/UFfBlJ9E1LI/AAAAAAAAArw/Nzh0RSePrW8/s1600/cap.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="14" width="65" src="http://2.bp.blogspot.com/-h781-968aE8/UFfBlJ9E1LI/AAAAAAAAArw/Nzh0RSePrW8/s400/cap.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Sometimes these choices are made at a particular authors preference other times combinations of these are used, such as in discussing things like &lt;a href="http://en.wikipedia.org/wiki/Galois_connection"&gt;Galois Connections&lt;/a&gt; which are mappings between two different orders, in such a case multiple sets of the above symbols might be needed to differentiate between specific instances of different orders.  Usually the set notation symbols are not used for lattices but they sometimes are, and in our examples above both meanings apply.  Also the following symbols get used to describe comparison as well:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-EilQYE7gPCg/UFfBzKIT-XI/AAAAAAAAAsA/XthYI_jqrfA/s1600/succ.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="14" width="29" src="http://1.bp.blogspot.com/-EilQYE7gPCg/UFfBzKIT-XI/AAAAAAAAAsA/XthYI_jqrfA/s400/succ.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Another set of symbols that show up, which are often used to describe covers, or immediately precedes or immediately succeeds, in that there are no elements between the two items compared are:  &lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-8pG760YuOnU/UFfCB1cg2vI/AAAAAAAAAsI/qp0NtF0VyJo/s1600/cover.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="10" width="29" src="http://1.bp.blogspot.com/-8pG760YuOnU/UFfCB1cg2vI/AAAAAAAAAsI/qp0NtF0VyJo/s400/cover.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name="Additional_Topics"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Additional Topics&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;The topics of lattice theory and order theory are extensive and this post really just scratches the surface.  When you feel comfortable or even if you don’t depending on your learning style, there are many things that I did not cover.  There are order specific concepts like strict and asymmetric. Complete partial orders show up a lot in CS as well.  For lattices there are things that I only mentioned like modularity and Galois connections, there functions on lattices which include ideas like monotone, antitone, and isotone.  New lattice can be created by number of techniques like the Cartesian product of two lattices.  And of course there are many interesting results relating to fixed points, and the list goes on.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;In my next post I will look at some specific examples of some the ideas discussed here in everyday programming and some more theoretical examples as well.&lt;/p&gt;&lt;br /&gt;
&lt;a name="References_and_Resources"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;References and Resources&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;There are a number of books on the subject, including the previously mentioned  the recently updated &lt;u&gt;Lattice Theory: Foundation &lt;/u&gt; by George Grätzer and &lt;u&gt;Combinatorics: The Rota Way&lt;/u&gt; by Joseph P. S. Kung, Gian-Carlo Rota and Catherine H. Yan, there are a number of books on the subject including:&lt;/p&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Lattices and Ordered Algebraic Structures by T.S. Blyth&lt;/li&gt;
&lt;li&gt;Introduction to Lattices and Order by B. A. Davey and H. A. Priestley&lt;/li&gt;
&lt;li&gt;General Lattice Theory (Second Edition) by George Grätzer, B.A. Davey, R. Freese and B. Ganter&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;p&gt;If you are just getting into the subject, and even if you are not, I would recommend taking advantage of some good free resources, listed in no particular order:&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.149.3551"&gt;Lattice Theory with Applications&lt;/a&gt;  by Vijay K. Garg&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.math.hawaii.edu/~jb/"&gt;Notes on Lattice Theory&lt;/a&gt;[&lt;a href="bigcheese.math.sc.edu/~mcnulty/alglatvar/lat.pdf"&gt;complete pdf here&lt;/a&gt;] by J. B. Nation of the University of Hawaii&lt;/p&gt;&lt;p&gt;&lt;a href="http://boole.stanford.edu/cs353/handouts/book1.pdf"&gt;Chapter 1 - Lattice theory&lt;/a&gt; in Vaughan Pratt’s &lt;a href="http://www.cs.utexas.edu/~diz/353/"&gt;CS 353: Algebraic Logic&lt;/a&gt; course &lt;a href="http://boole.stanford.edu/cs353/handouts.html"&gt;handouts&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Dave Abrams "&lt;a href="http://cpp-next.com/archive/2010/02/order-i-say/"&gt;Order I Say&lt;/a&gt;" blog post, some of the above images are from his post, with his permission, thanks.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.iseclab.org/people/enji/infosys/lattice_tutorial.pdf"&gt;Lattice Tutorial&lt;/a&gt; by Nenad Jovanovic of Secure Systems Lab&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.math.cornell.edu/~levine/18.312/alg-comb-lecture-7.pdf"&gt;Lecture 7&lt;/a&gt; and &lt;a href="http://www.math.cornell.edu/~levine/18.312/alg-comb-lecture-7.pdf"&gt;lecture 8&lt;/a&gt; of Lionel Levine’s course on &lt;a href="http://www.math.cornell.edu/~levine/18.312/"&gt;Algebraic Combinatorics&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://profs.sci.univr.it/~giaco/paperi/lattices-for-CS.pdf"&gt;Chapter 2 - Ordered Sets and Complete Lattices, A Primer for Computer Science&lt;/a&gt; by Hilary A. Priestley of  the Mathematical Institute, University of Oxford&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.ams.org/notices/199711/comm-rota.pdf"&gt;The Many Lives of Lattice Theory&lt;/a&gt; by Gian-Carlo Rota&lt;/p&gt;&lt;p&gt;&lt;a href="http://mathworld.wolfram.com/topics/LatticeTheory.html"&gt;Wolfram’s Mathworld on lattices&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/MFgZPiY4sRQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/MFgZPiY4sRQ/lattice-theory-for-programmers-and-non.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-KrvVV3SvYzY/UFfHghoAk-I/AAAAAAAAAsk/ROPJQYcRmaI/s72-c/monarch.jpg" height="72" width="72" /><thr:total>4</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/09/lattice-theory-for-programmers-and-non.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-2890494797010662089</guid><pubDate>Tue, 07 Aug 2012 12:35:00 +0000</pubDate><atom:updated>2012-08-07T08:35:23.491-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">Software Development</category><category domain="http://www.blogger.com/atom/ns#">Math</category><category domain="http://www.blogger.com/atom/ns#">Software Process</category><category domain="http://www.blogger.com/atom/ns#">Rant</category><category domain="http://www.blogger.com/atom/ns#">Software Engineering</category><category domain="http://www.blogger.com/atom/ns#">Software Development Teams</category><category domain="http://www.blogger.com/atom/ns#">Education</category><category domain="http://www.blogger.com/atom/ns#">Computer Science</category><title>Why You Can’t Have a Real Software Engineering Discipline</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-HNC8TtvDVf4/UB6OPean_pI/AAAAAAAAAnY/CW_BADq2nZA/s1600/IMG_7870.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="300" src="http://1.bp.blogspot.com/-HNC8TtvDVf4/UB6OPean_pI/AAAAAAAAAnY/CW_BADq2nZA/s400/IMG_7870.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;!--Why You Can’t Have a Real Software Engineering Discipline--&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;As we all know the fields of computer science and software engineering are in their infancies.  Many a blog post has been written lamenting the fact that software engineering is not a real engineering discipline, and while I have not written that exact post, I have &lt;a href="http://www.elegantcoding.com/2011/12/metaphorically-thinking-about-software.html"&gt;written about the subject&lt;/a&gt; and have &lt;a href="http://www.elegantcoding.com/2012/01/real-software-engineering-good-bad-and.html"&gt;deconstructed what others have said&lt;/a&gt; about it.  A number of these points do apply to why software projects routinely fail, yet another topic that has received considerable attention.  Now admittedly all engineering disciplines regardless of their maturity and formalization have project failures and creating a real software engineering discipline will not eliminate this problem but one would hope that it would abate it.&lt;/p&gt;&lt;p&gt;I find it odd that at a time when so many people are involved in IT there seems to be little discernible progress in creating a real software engineering disciple.  There are probably millions of people working on creating software.  Also there are many researchers trying to solve this problem from many different angles.  Practitioners have been attempting to solve it with ideas like Agile and Software Craftsmanship, etc.  Additionally there is a long list of failures surrounding the formalization software engineering.  &lt;/p&gt;&lt;p&gt;My biggest complaint is the fact that there really are no good formal standards in general software engineering principles and methodologies lack a formal foundation and even the more vague principles can be easily thwarted and misused, and often, as I have &lt;a href="http://www.elegantcoding.com/2012/03/software-design-debate-and-futility-of.html"&gt;previously complained&lt;/a&gt;, it often ends up being based on pure opinion which is usually won through positional authority, perseverance or by those who are just more politically savvy.&lt;/p&gt;&lt;p&gt;The intent of this post is not to attempt to solve or even offer solutions to the problem of creating a real software engineering discipline but to look at what I think are some barriers to creating this discipline and in some of these cases offer thoughts on overcoming those barriers.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Low Entry Requirements&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;If we are to think software engineering as an engineering discipline, I challenge you to find another engineering discipline that routinely has practitioners with no formal training in the field.  I very much doubt that some who did not hold a degree in engineering and who built a shed in his back yard is now working as a structural engineer on a construction project, the mere idea seems ludicrous.  Yet I have worked with non technical degree holders who became software developers, one who started by building web pages and now calls himself an "Internet Application Architect", and is probably one of the biggest &lt;a href="http://www.elegantcoding.com/2011/10/confederacy-of-cargo-cult-coders.html"&gt;cargo cult coders&lt;/a&gt; I’ve ever had the misfortune to work with.  This egalitarian aspect isn’t all bad as it does let good people into the field as well.   Another non technical degree holder I once worked with became an accomplished developer and went on to get an advanced degree in CS and is now a CS professor.   Although it’s probably the case that for every good non technical degree holder who joins the field it is likely that dozens of mediocre and bad practitioners will also join.   It seems that in other engineering disciplines there are much more stringent educational requirements to ensure proper training.   To be clear here I am not equating having a degree with being competent because I have met many &lt;a href="http://www.elegantcoding.com/2011/07/certificate-industry.html"&gt;incompetent people with degrees&lt;/a&gt;, but still you need something.   I confess I am at a loss for a solution for this one.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;The Lack of Differentiation between Science and Engineering&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Chemistry is a scientific discipline, chemical engineering is an engineering discipline, and you can make this comparison between other engineering disciplines and the sciences that they employ e.g. electrical, mechanical, and structural map to various areas of physics.  Engineering and scientific disciplines are different types of disciplines often taught in separate schools.  Although each engineering discipline has some scientific overlap and it would probably be possible to move from the appropriate scientific field to the corresponding engineering field in general you probably would not do so without returning to school.   In recent years software engineering curricula have been added to the rosters of many colleges and while this is potentially a step forward, discounting for the moment that software engineering is still not really real engineering, a software engineering degree and a computer science degree in many cases gets you the same job!   &lt;/p&gt;&lt;p&gt;So in other fields there would be a differentiation between a degree that would put you on a track to do scientific research and one that would put you on a track to do engineering work.  As I understand it, if you are fresh out of school with a BS in CS that qualifies you to be a tester at Microsoft&lt;sup&gt;1&lt;/sup&gt;, developers hired right out of school need at least a Masters degree in CS.   This is an extreme case of how this really breaks down in our industry.  In most cases engineering practitioners are the software engineering, MIS, CS or even non technical degrees and the few scientific careers generally go to the advanced degree holders.  I admit this probably fairly normal a BS in chemistry or biology is also more likely to get you a job in IT than a job as a research scientist.  Still compared to more mature engineering fields there seems to be a lack of real differentiation between the degrees that yield a career as a software engineer versus one as a computer scientist.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Bad Management&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;The entry requirements for managers in software make the low entry requirements for software engineering practitioners look downright rigorous.  I have &lt;a href="http://www.elegantcoding.com/2011/05/driven-development.html"&gt;previously criticized&lt;/a&gt; the fact that many organizations find the cheapest people, especially for software management and give them an &lt;a href="http://www.pmi.org/certification/project-management-professional-pmp.aspx"&gt;obligatory certification&lt;/a&gt;.  Now I know that engineering management regardless how formal or established the engineering discipline is an area that has problems and failures, but again I very much doubt that you would find a twenty something business or liberal arts major with a freshly minted PMP suffix managing construction or civil works projects.   Yet in my experience this is pretty normal in IT especially in the government sector.  Of course bad software management is executed by older managers as well.&lt;/p&gt;&lt;p&gt;A post by Larry White titled "&lt;a href="http://deathrayresearch.tumblr.com/post/26759934886/engineering-management-is-dying"&gt;Engineering Management Is Dying"&lt;/a&gt; delves into some these issues.  It is definitely the case that methodologies like Agile have changed how software projects work and the traditional corporate management approach to software really doesn’t work.  One point he makes is that it is not uncommon to see a two hundred person project at Google headed by an engineer.  To me this implies that someone is in some way managing that project.  I think all of this is indicative of the need for software engineering mangers to also be practitioners in engineering or at least very well versed in how software development works.  The situation he talks about at Google is not the case everywhere, in that case the company is its own client, but there are many cases where software is being built for clients and this does create a need for management that deals with the client, perhaps this should be a role that is separated from management and called a client liaison, which is what often happens.  Also I am not sure how things work at Google but I have also seen internal development in organizations where the IT department provides services to an internal client, I have also seen this go horribly awry with contentious unproductive relationships between departments.  In short I feel that just as we need a real software engineering discipline we also need a real incarnation of software engineering management.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;The Disconnect between Academia and Industry&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Most practitioners do not keep up with, or read academic research, actually many practitioners don’t read at all, but that’s &lt;a href="http://www.elegantcoding.com/2011/10/confederacy-of-cargo-cult-coders.html"&gt;another issue&lt;/a&gt;, and most academicians don’t work in the field so they lack the hands on knowledge.  Unfortunately this rift can take on a somewhat disdainful tone as is the case in my exploration of one practitioner’s attempt to define "&lt;a href="http://www.elegantcoding.com/2012/01/real-software-engineering-good-bad-and.html"&gt;Real Engineering&lt;/a&gt;".   Fortunately some people, I’d like to count myself among them, take a more constructive approach to building bridges across this rift.  Daniel Lemire has an interesting &lt;a href="http://lemire.me/blog/archives/2012/06/18/on-the-quality-of-academic-software/"&gt;critique the quality of software produced in academia&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;I think the solution here is for both sides to become more engaged in problems faced on each side. I am optimistic about this one as I feel that these walls are breaking down as the field is growing up and many of the emerging technologies are forcing developers to be more cognizant of and engaged in research topics.  I also have encountered much more research that has ties to the practical concerns of day to day software development, some I have &lt;a href="http://www.elegantcoding.com/2011/07/software-frameworks-resistance-isnt.html"&gt;mentioned&lt;/a&gt; with more to come.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;The Lack of an Effective CS Math Curriculum  &lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;If you read my blog you know it to be a mix of math and software practices. I would describe myself as a software practitioner and a math enthusiast.  My math journey has taken me on some interesting math excursions into areas of math that seem to get little or no mention in CS curricula and I feel that this is a major problem in really applying math to the field of software engineering.  Another problem is in the way that it is taught, my experience was that it was not only taught badly but in a way that made it seem irrelevant to many of the programming courses.  Specifically I would shift the CS math curriculum to include less differential and integral calculus and include more logic, combinatorics, abstract algebra, graph theory, order theory, category theory and probably some topology among others.&lt;/p&gt;&lt;p&gt;Over the last few years I have been progressively learning more math which has been in part motivated by necessity for understanding research papers.  This approach has changed the way I see things, I now see the patterns of math in software. They are there and I believe that they can be exploited to create a real software engineering discipline.&lt;/p&gt;&lt;p&gt;For the math learning problem I do have some ideas many of which are expressed in my blog.  Some of my posts like &lt;a href="http://www.elegantcoding.com/2011/04/math-you-can-use.html"&gt;refactoring if statements with Demorgan’s Laws&lt;/a&gt; or the &lt;a href="http://www.elegantcoding.com/2011/05/monoid-for-masses.html"&gt;String Monoid&lt;/a&gt;, the &lt;a href="http://www.elegantcoding.com/2011/08/object-graph.html"&gt;Object Graph&lt;/a&gt;, etc. are about making these mathematical ideas more relevant and accessible to programmers. Other posts like my series on &lt;a href="http://www.elegantcoding.com/2012/05/software-system-morphology.html"&gt;naming&lt;/a&gt; and my post on &lt;a href="http://www.elegantcoding.com/2012/04/what-is-generic-programming.html"&gt;generic programming&lt;/a&gt; and &lt;a href="http://www.elegantcoding.com/2012/02/software-reuse-complexity-curve.html"&gt;entropy and complexity&lt;/a&gt; are about my own ideas and ideas in the research literature that I feel may help to create a real software engineering discipline.  These are my attempts at solutions to these problems, so expect more of both of these and more thoughts on the CS math curriculum.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;The Software Architect Debacle&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;This is one that really bothers me.  I feel the software architect role in general has a very negative effect on creating quality software and it dissuades the industry from developing a real engineering discipline.  The Software Architect role tends to be broadly defined, you have enterprise architects, software architects, etc., some architects tend to be involved with hardware and networking, some work on configuration management, some do software design, some do all of these things and more.  I feel this is a problem as each of these is a separate engineering area with different types of problems. By not breaking these down it often leads to a lack of focus on specific problems, also I have seen cases where the architect focuses on their preference and ignores other issues.  The architect role is often divorced from the code.  I have met many architects that were responsible for software but had never even looked at the code.  To me this is a huge failing that architects that are responsible for building software often lack the interest, time, or even aptitude to know the quality or underlying of structure of the software that they are delivering.&lt;/p&gt;&lt;p&gt;To really do justice to these ideas I might need a separate post, my solution would be to break down the architect role into specific engineering roles, which could include:&lt;/p&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;Software Process Engineering&lt;/b&gt; - this would be involved with software team and resources planning, some aspects of configuration management such as defining policies, requirements analysis and general project management aspects of software construction including the definition and refinement of the SDLC.  This role is tightly coupled with software engineering management.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Software Structural Engineering&lt;/b&gt; - this would include requirements comprehension, code infrastructure planning, prototyping work, hands on code structural work including custom frameworks and reusable components, third party library products, and general code quality including reviews and static analysis.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Software Quality Engineering&lt;/b&gt; - This would include the QA roles, software testing and testing tools, requirements validation and refinement, usability and reliability and general software quality issues.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Software Infrastructure Engineering&lt;/b&gt; - This would include hardware, networking, database, app server and general service infrastructure, non functional requirements fulfillment and possibly the implementation of configuration management, continuous integration, etc.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;p&gt;This is a rough "sketch" of these possible roles and each of these areas has some overlap implying that all of the people in these roles would work closely together, also some combination of, or all of these roles might be performed by a single individual depending on the organization’s size and structure.  What this approach does is clearly defines roles and responsibilities as opposed to some nebulous software architect role.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;The Continuous Turnover of the Work Force&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;A young CEO once commented that he thinks young programmers are superior.  In general companies prefer younger workers as they often don’t have family commitments so they can work more hours and you can pay them lower salaries, DC area government contractors rely on this to keep their profit margins up.&lt;/p&gt;&lt;p&gt;As an older developer I often find this frustrating.  I confess that I have not moved up the ladder and still mostly work as a developer or what might be called a hands on architect, yes I know but that’s the current term, actually my preferred title would be: Software Structural Engineer.  Working as a contractor I have on several occasions found myself on projects that were dominated by younger developers and unfortunately on more than one occasion I watched as teams would make many mistakes due to a lack of experience, in some cases I was able to help in others I was ignored by the younger developers.  This is not to say that I do not still make mistakes, I’ve just been around long enough to have made a lot of them already.&lt;/p&gt;&lt;p&gt;If you buy into the software craftsmanship thing, I admit to being skeptical of this idea, you might be inclined to draw a parallel to craftsman of the past when older established masters took on apprentices and passed on their wisdom to the next generation.  Given the access to information these days such process is somewhat antiquated and perhaps impractical.  Nevertheless I feel, and the industry supports me here, that older developers who keep their skills up to date have value.  I know several younger developers who have sought me out to learn from me so I think I can safely say I still have some value.&lt;/p&gt;&lt;p&gt;Many older developers have let their skills get rusty and have not kept up on current technologies I have seen this many times.  Also many companies seem to lack the vision to allow for real hands on technical career growth.  I can’t help but feel that this inclination to recycle developers in each new generation is hurting or at least slowing our ability to develop a real software engineering discipline, this potential loss of continuity seems like it leads to some lost wisdom.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;The Social Networking Drain and Hollywoodification of Silicon Valley&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;As I write this Hollywood gears up to deliver a &lt;a href="http://www.nytimes.com/2012/07/10/technology/silicon-valley-wary-of-reality-series.html"&gt;reality TV show&lt;/a&gt; that takes place in silicon valley and Mark Zuckerberg now gets the &lt;a href="http://gawker.com/5597293/mark-zuckerbergs-age-of-privacy-is-over-+-gallery/"&gt;paparazzi treatment&lt;/a&gt;.  Another article that I &lt;a href="http://www.elegantcoding.com/2011/07/certificate-industry.html"&gt;previously mentioned&lt;/a&gt; was about how CS enrollment was up because the movie The Social Network had enticed many aspiring Zuckerberg wannabes.  At present there does seem to be a gold rush mentality and it is noticeable and even discussed on sites like &lt;a href="http://news.ycombinator.com/"&gt;Hacker News&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;As someone who has never worked in the valley I am very much an outsider and may not have a good perspective on these things, but it seems that there are a lot of startup companies focusing on crap. Now I get it.  We live in a shallow consumer society with a rapacious appetite for crap. But are not these supposed to be some of the smartest people and I am &lt;a href="http://www.businessinsider.com/entrepreneurs-should-be-solving-real-problems-not-creating-apps-2012-3"&gt;not the only one to wonder&lt;/a&gt; why so many smart people who should have better taste and higher standards are settling for working on serving up ads and other vapid crap instead of doing more meaningful work like working on real problems that would advance human society or even just work on advancing software engineering.  Maybe I’m just jaded, so I will leave you with this and of course my apologies to &lt;a href="http://en.wikipedia.org/wiki/Allen_Ginsberg"&gt;Allen Ginsberg&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;I saw the best minds of my generation wasted by working on serving up ads,&lt;/p&gt;&lt;p&gt;dragging themselves through the startups in the valley looking for an instant cash fix,&lt;/p&gt;&lt;p&gt;angelheaded hipsters burning for the venture capital connection to the better life in the consumer culture,&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://www.wussu.com/poems/agh.htm"&gt;...&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt;I believe this was the case in the late 90’s and may have changed, this information was conveyed to me by a former Microsoft employee.&lt;/p&gt;&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/pKgUL71LmN4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/pKgUL71LmN4/why-you-cant-have-real-software.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-HNC8TtvDVf4/UB6OPean_pI/AAAAAAAAAnY/CW_BADq2nZA/s72-c/IMG_7870.JPG" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/08/why-you-cant-have-real-software.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-1158803292085313812</guid><pubDate>Tue, 17 Jul 2012 19:10:00 +0000</pubDate><atom:updated>2012-07-18T09:22:09.491-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">Naming</category><category domain="http://www.blogger.com/atom/ns#">Software Engineering</category><title>A Framework for Software System Naming</title><description>&lt;h2&gt;On the Importance of Naming in Software Systems part IV&lt;/h2&gt;&lt;style&gt;
li.listitem {
    margin-bottom : 16px;
    padding-bottom: 16px;
}&lt;/style&gt;&lt;!--A Framework for Software System Naming--&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-o3IUtZybuk8/UAWzVrAPYWI/AAAAAAAAAnA/yMEhoDE9eSA/s1600/ce11_Callisto.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="400" src="http://1.bp.blogspot.com/-o3IUtZybuk8/UAWzVrAPYWI/AAAAAAAAAnA/yMEhoDE9eSA/s400/ce11_Callisto.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;In my previous posts on naming I have laid the foundation for a framework for naming in software systems.  This post is mostly a rehashing of those previous ideas and is intended to both codify and consolidate the definitions of terms upon which I have chosen and created to build a naming framework.  It also serves as a single location to concisely reference these ideas.  To gain more insight into the background and development of these ideas see my previous three posts:  "&lt;a href="http://www.elegantcoding.com/2012/03/survey-of-conventional-wisdom-on.html"&gt;A Survey of the Conventional Wisdom on Software Naming&lt;/a&gt;",  "&lt;a href="http://www.elegantcoding.com/2012/03/more-thoughts-on-formal-approaches-to.html"&gt;More Thoughts on Formal Approaches to Naming in Software&lt;/a&gt;", and "&lt;a href="http://www.elegantcoding.com/2012/05/software-system-morphology.html"&gt;Software System Morphology&lt;/a&gt;".  The definitions are as follows:&lt;/p&gt;&lt;h3&gt;Structural&lt;/h3&gt;&lt;ul&gt;&lt;li style="padding-bottom: 16px;"&gt;&lt;b&gt;Name&lt;/b&gt; – The Signifier that consists of a string of characters that refers to a &lt;b&gt;System Referent&lt;/b&gt;.&lt;/li&gt;
&lt;li style="padding-bottom: 16px;"&gt;&lt;b&gt;Name Unit Separator&lt;/b&gt; – is a mechanism to separate name units within a &lt;b&gt;Name&lt;/b&gt;, this can be an explicit character such as "-" or "_".  It can also be in implicit mechanism such as the use of Camel Case within the name.&lt;/li&gt;
&lt;li style="padding-bottom: 16px;"&gt;&lt;b&gt;Name Unit&lt;/b&gt; – Is the smallest lexical unit of a &lt;b&gt;Name&lt;/b&gt; usually separated by a &lt;b&gt;Separator&lt;/b&gt; (&lt;b&gt;Name Unit Separator&lt;/b&gt;) and is used to describe the lexical structure of the &lt;b&gt;Name&lt;/b&gt;.&lt;/li&gt;
&lt;li style="padding-bottom: 16px;"&gt;&lt;b&gt;Named Scope Context&lt;/b&gt; – this is the location of the &lt;b&gt;Name&lt;/b&gt; within the system, e.g. where the name usage occurs.&lt;/li&gt;
&lt;li style="padding-bottom: 16px;"&gt;&lt;b&gt;System Referent&lt;/b&gt; – This is the actual instance of a thing that is named and is used in the system. See &lt;b&gt;System Referent Type&lt;/b&gt; for specific types of &lt;b&gt;System Referents&lt;/b&gt;.&lt;/li&gt;
&lt;li style="padding-bottom: 16px;"&gt;&lt;b&gt;System Referent Type&lt;/b&gt; - This is the specific type or class, as in classification, of what a &lt;b&gt;System Referent&lt;/b&gt; is in a system some examples include:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Classes&lt;/li&gt;
&lt;li&gt;Variables (local, instance, static)&lt;/li&gt;
&lt;li&gt;Methods&lt;/li&gt;
&lt;li&gt;Method Parameters&lt;/li&gt;
&lt;li&gt;Packages&lt;/li&gt;
&lt;li&gt;Database Tables, Columns, Triggers, Stored Procedures, etc.&lt;/li&gt;
&lt;li&gt;HTML Files, CSS Files, Javascript Files, Config Files, all files&lt;/li&gt;
&lt;li&gt;Directories&lt;/li&gt;
&lt;li&gt;Urls&lt;/li&gt;
&lt;li&gt;Documents&lt;/li&gt;
&lt;li&gt;XML Elements and Attributes&lt;/li&gt;
&lt;li&gt;CSS Classes&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;Semantic&lt;/h3&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li style="padding-bottom: 16px;"&gt;&lt;b&gt;System Morpheme&lt;/b&gt; – This is a conceptual unit of meaning in a system that is used in a name, it is distinguished from a &lt;b&gt;Name Unit&lt;/b&gt; in that a morpheme can consist of one or more &lt;b&gt;Name Units&lt;/b&gt;.&lt;/li&gt;
&lt;li style="padding-bottom: 16px;"&gt;&lt;b&gt;System Natural Language Set&lt;/b&gt; – This is the set of Natural Languages used to create the names.  It is often English but it need not be and a system could include components or be constructed in a way that might include hybridization between multiple natural languages.&lt;/li&gt;
&lt;li style="padding-bottom: 16px;"&gt;&lt;b&gt;Problem Domain&lt;/b&gt; - This is the &lt;a href="http://en.wikipedia.org/wiki/Semantic_domain"&gt;Semantic Domain&lt;/a&gt; that describes problem area for which the system solution is targeted.  This would be a set of concepts and &lt;b&gt;System Morphemes&lt;/b&gt; that apply to the problem domain. For example a financial system would be built using the relevant financial terms and language concepts.&lt;/li&gt;
&lt;li style="padding-bottom: 16px;"&gt;&lt;b&gt;Solution Domain&lt;/b&gt; – This is the &lt;a href="http://en.wikipedia.org/wiki/Semantic_domain"&gt;Semantic Domain&lt;/a&gt; that describes concepts that are used to implement the system including &lt;b&gt;System Morphemes&lt;/b&gt; that apply to the solution domain.  This might include things like terms that describe Design Patterns, data structures, etc.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;p&gt;As you can see from above these Ideas can be separated into two categories: Structural and Semantic. However the two categories are not completely independent of each other so there is some overlap and interdependence.  The structural ideas include: &lt;b&gt;Name Unit&lt;/b&gt;, &lt;b&gt;Named Scope Context&lt;/b&gt;, &lt;b&gt;System Referent&lt;/b&gt;, and a &lt;b&gt;System Referent Type&lt;/b&gt;.   Each &lt;b&gt;Name&lt;/b&gt; has these properties as attributes.  A name has a lexical structure made up of &lt;b&gt;Name Units&lt;/b&gt;, and refers to a &lt;b&gt;System Referent&lt;/b&gt; of some &lt;b&gt;System Referent Type&lt;/b&gt; and has one or more locations given by its &lt;b&gt;Named Scope Context&lt;/b&gt;(s).&lt;/p&gt;&lt;p&gt;The semantics of the names which has the "unit" described by the &lt;b&gt;System Morpheme&lt;/b&gt; idea has semantic properties which will fall into either the &lt;b&gt;Problem Domain&lt;/b&gt; or the &lt;b&gt;Solution Domain&lt;/b&gt;.  The expression of these concepts is dependent on the &lt;b&gt;System Natural Language Set&lt;/b&gt;, in other words the natural languages that are used to construct meaningful names for concepts in both the &lt;b&gt;Problem Domains&lt;/b&gt; and the &lt;b&gt;Solution Domains&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;This is the current state of my thinking on this. These ideas will be refined and might change over time, the objective is to develop something that is useful and that both supports and can be validated by a more analytic approach.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/yT4szl3sDhY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/yT4szl3sDhY/framework-for-software-system-naming.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-o3IUtZybuk8/UAWzVrAPYWI/AAAAAAAAAnA/yMEhoDE9eSA/s72-c/ce11_Callisto.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/07/framework-for-software-system-naming.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-3474665736560025259</guid><pubDate>Sun, 15 Jul 2012 12:45:00 +0000</pubDate><atom:updated>2012-07-15T08:45:16.449-04:00</atom:updated><title>Renaissance 2.0</title><description>&lt;br /&gt;
&lt;p&gt;Are We on the Verge of the Next Renaissance?&lt;/p&gt;&lt;!--Renaissance 2.0--&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-78cY5Je9yyA/UAK1lSwuX2I/AAAAAAAAAmw/q2qrZtSGlPA/s1600/The_Papal_Belvedere.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="309" src="http://4.bp.blogspot.com/-78cY5Je9yyA/UAK1lSwuX2I/AAAAAAAAAmw/q2qrZtSGlPA/s400/The_Papal_Belvedere.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;On 31 October 1517, &lt;a href="http://en.wikipedia.org/wiki/Martin_Luther"&gt;Martin Luther&lt;/a&gt; sent to his bishop &lt;a href="http://en.wikipedia.org/wiki/Albert_of_Mainz" title="Albert of Mainz"&gt;Albert of Mainz&lt;/a&gt; a copy of his &amp;quot;Disputation of Martin Luther on the Power and Efficacy of Indulgences&amp;quot;, which came to be known as &lt;a href="http://en.wikipedia.org/wiki/The_Ninety-Five_Theses" title="The Ninety-Five Theses"&gt;The Ninety-Five Theses&lt;/a&gt;.  In January of 1518 he also sent copies to his friends who translated it from Latin to German and had copies printed and passed them on.  In part because of easy mechanized printing it went viral, within two weeks it had spread throughout Germany and in a month throughout all of Europe. The rapid propagation of his leaked private communication caught Luther by surprise and he soon found himself in a full on “flame-war” directly with the &lt;a href="http://en.wikipedia.org/wiki/Pope_Leo_X"&gt;Pope&lt;/a&gt;.  Luther quickly mastered this new mass media and effectively used it in his fight.  This early landmark public dispute in the emergent mass media of the time demonstrated a new power structure built on the rapid spread of ideas.&lt;/p&gt;&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Johannes_Gutenberg"&gt;Guttenberg&lt;/a&gt;’s motivation for inventing the &lt;a href="http://en.wikipedia.org/wiki/Printing_press"&gt;printing press&lt;/a&gt;, an idea that had also been invented previously in Asia, was strictly entrepreneurial and it was not his first venture. Shortly after the introduction of the printing press to Europe, other entrepreneurs realized that there was a demand for books.  In some respects the printing business of the late 15&lt;sup&gt;th&lt;/sup&gt; and early 16&lt;sup&gt;th&lt;/sup&gt; centuries was very similar to the internet boom that we are currently experiencing.  This new technology not only caused the creation of new businesses but it also transformed the dissemination of information and the power of information itself in the sense that new information could be more easily created and collaboratively built and referenced also language was standardized and local &lt;a href="http://en.wikipedia.org/wiki/Vernacular"&gt;vernacular&lt;/a&gt; languages replaced Latin for scholarly works.  This new more egalitarian access to books and information fueled the spread of ideas, and caused an exponential surge forward in the ability develop science and technology and culture itself.&lt;sup&gt;1&lt;/sup&gt;&lt;/p&gt;&lt;p&gt;There was a dark side to this new change in the way information was disseminated. The Catholic Church, which held a monopoly on the dissemination of religious information&lt;sup&gt;2&lt;/sup&gt;, reacted by banning some of the books and publishing its own propaganda including lists of banned books, also the &lt;a href="http://en.wikipedia.org/wiki/Tyndale_Bible"&gt;Tyndale Bible&lt;/a&gt; written in English was banned in England until &lt;a href="http://en.wikipedia.org/wiki/Henry_VIII_of_England"&gt;Henry VIII&lt;/a&gt; broke with the Catholic Church.  An &lt;a href="http://en.wikipedia.org/wiki/Inquisition"&gt;inquisition&lt;/a&gt; was directed towards the book publishing capital of Europe, Venice, due to the publication of scientific books which contradicted the beliefs of the Roman Catholic Church.  Books were banned and burned and heresy trials were held. &lt;/p&gt;&lt;p&gt;There were several &lt;a href="http://en.wikipedia.org/wiki/Inquisition"&gt;inquisitions&lt;/a&gt; which were heinous affairs that included racial cleansing, torture, and other barbaric acts of terror. These were started before the advent of the printing press but were then directed towards this new threat. Fortunately the inquisitions eventually died out. &lt;/p&gt;&lt;p&gt;It is thought that this transformation in the spreading of ideas, coupled with the previous reintroduction of earlier &lt;a href="http://en.wikipedia.org/wiki/Transmission_of_the_Classics"&gt;Greek, Roman and Arabic knowledge&lt;/a&gt; fuelled an expansion of scientific understanding which also transformed art in terms of perspective and anatomical representation was a catalyst for the Renaissance.  All of this makes me wonder about the future possibilities of our current era and what similar parallels we could see from that previous “information technology” revolution when the dissemination of information made an exponential leap forward from the old technology, much the same way as we are experiencing an exponential leap forward in information technology.&lt;/p&gt;&lt;p&gt;We now live in an era in which I can download hundreds of books or the equivalent amount of information in minutes more than I can comprehend and software is rapidly evolving to allow me to more effectively deal with large quantities of data I can search, jump, skim, and view almost anything about any subject effectively instantly, the time that it takes to send text, audio, images and video has been reduced almost to the speed of light and that’s how quick we can get real time information from all over the world and from space. We also continuously receive an increasing amount of data from various places in the solar system and even at the &lt;a href="http://en.wikipedia.org/wiki/Voyager_program"&gt;edge&lt;/a&gt; of the &lt;a href="http://en.wikipedia.org/wiki/Heliosphere"&gt;heliosphere&lt;/a&gt;.  &lt;/p&gt;&lt;p&gt;The very tools to better manipulate crunch and comprehend large petabyte and beyond data are rapidly being invented and refined, the things that we will be able to do in even the next decade(s) is probably going to be revolutionary for human society in terms of art, science and how we live our lives, the changes are already quite pronounced.  Soon images, audio, and video will be as searchable and easily manipulated as text is now and algorithms enhanced with more and more math will be able to digest all of this and allow us to query it and manipulate it ways we probably can’t even imagine yet. &lt;/p&gt;&lt;p&gt;From the sixteenth century until the end of the twentieth century publishing grew into a vast industry expanding from books to encompass more such as periodicals. Other entire industries were spawned from it such as the newspaper industry.  This spawned new media like audio, radio and recording, movies and video that grew into entire industries.  Then along came the internet and fast data transmission. All of these industries are now under pressure and many are fighting this change.  Now it would be a bit overly dramatic to compare the copyright wars to the inquisition but the parallel is there: large organizations in control of the dissemination of information fighting the change, more egalitarian information access and distribution.  Another common thread is the use of law, the Catholic Church tried to impose its law on the local European governments to stamp out heresy.  We now find ourselves in a similar position with the established media companies using their deep pockets to attempt to write new laws that benefit them at the potential cost to a free internet and innovation, so far legislation like the &lt;a href="http://en.wikipedia.org/wiki/Research_Works_Act"&gt;Research Works Act&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Stop_Online_Piracy_Act"&gt;SOPA&lt;/a&gt; have failed but the fight continues.  Patents especially broad and abstract patents are another threat to innovation this is another system that has been gamed by the big corporations so that it now often does the opposite of the original intent of the &lt;a href="http://en.wikipedia.org/wiki/Founding_Fathers_of_the_United_States"&gt;founding fathers&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;So we now find ourselves at a unique time where there is so much potential for innovation in science and art and hopefully society. These human endeavors are built on collaboration and on the sharing, remixing, and refining of ideas. Many of Shakespeare’s works were derivative of earlier works, can you imagine if the same type of laws and litigation existed then, such works may have never been created.&lt;/p&gt;&lt;p&gt;How this potential innovation will it play out over the next two decades may very well be beyond comprehension, the things I can buy today were the devices of science fiction, specifically Star Trek, when I was growing up, even as a young adult, the idea of having a thousand books on a tablet device or watching real time video from the space station or access to terabytes of data was almost beyond my expectation, yet now I am starting to take it for granted.  My childhood almost seems like the life of a 15&lt;sup&gt;th&lt;/sup&gt; century turnip farmer who could only dream of reading scientific or any knowledge in a book.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt; Much of this is excerpted from Episode 4 of &lt;u&gt;&lt;a href="http://en.wikipedia.org/wiki/The_Day_the_Universe_Changed"&gt;The Day the Universe Changed&lt;/a&gt;&lt;/u&gt; by James Burke &lt;/p&gt;&lt;p&gt;&lt;sup&gt;2&lt;/sup&gt;The bible and all sermons were held in Latin restricting non-ecclesiastical people direct access religious doctrine.&lt;/p&gt;&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/XSYGua83SzQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/XSYGua83SzQ/renaissance-20.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-78cY5Je9yyA/UAK1lSwuX2I/AAAAAAAAAmw/q2qrZtSGlPA/s72-c/The_Papal_Belvedere.jpg" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/07/renaissance-20.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-2241176499456609810</guid><pubDate>Mon, 28 May 2012 21:37:00 +0000</pubDate><atom:updated>2012-08-30T21:21:44.816-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Linear Algebra</category><category domain="http://www.blogger.com/atom/ns#">Math</category><category domain="http://www.blogger.com/atom/ns#">Logic</category><category domain="http://www.blogger.com/atom/ns#">Vector Space Model</category><category domain="http://www.blogger.com/atom/ns#">Probability Theory</category><title>The Math of Search and Similarity</title><description>&lt;!--Math of Search and Similarity--&gt;&lt;br /&gt;
&lt;h2&gt;Part one: Lucene, The Boolean Model, tf*idf, and the Vector Space Model&lt;/h2&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-7-js_ScUkE8/T8PfQb6RtcI/AAAAAAAAAlk/4ygxkjyT6L8/s1600/resize_IMG_3632.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="300" width="400" src="http://4.bp.blogspot.com/-7-js_ScUkE8/T8PfQb6RtcI/AAAAAAAAAlk/4ygxkjyT6L8/s400/resize_IMG_3632.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a href="http://lucene.apache.org/"&gt;Lucene&lt;/a&gt; is built on classic &lt;a href="http://en.wikipedia.org/wiki/Information_retrieval"&gt;IR (Information Retrieval)&lt;/a&gt; Math concepts that are actually pretty old by current standards in our industry, with most of its roots from the 1970’s and some of them like the Boolean Model being quite a bit older.  Still that’s a solid quarter century older than search techniques like &lt;a href="http://en.wikipedia.org/wiki/PageRank"&gt;Pagerank&lt;/a&gt; and yet it can be a central and almost necessary technology used in many systems.&amp;nbsp; The mathematical domain of searching in Lucene relies on ideas like similarity measures which also relates to other disciplines that are used in &lt;a href="http://en.wikipedia.org/wiki/Data_mining"&gt;Data Mining&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Machine_learning"&gt;Machine learning&lt;/a&gt;.&amp;nbsp; The basic ideas of Lucene and IR provide a nice introduction to these ideas and I want to focus on the following classic IR topics:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Standard_Boolean_model"&gt;The Boolean Model&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Vector_Space_Model"&gt;The Vector Space Model&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Tf*idf"&gt;tf*idfweighting (Term Frequency * Inverse Document Frequency)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h2&gt;Tokenizing Text&lt;/h2&gt;&lt;br /&gt;
Lucene is built on the idea of Documents, which can be thought of as a collection of terms.&amp;nbsp; Think of a document as a web page or book and think of the terms as the words and in some cases phrases.&amp;nbsp; Lucene uses an Analyzer to tokenize the text, for example you may want not want to include Stop Words like [the, and, to, a, ...] in your index also indexes can be built using the concept of &lt;a href="http://en.wikipedia.org/wiki/N-gram"&gt;N-Grams&lt;/a&gt; take the expression "Information Retrieval" for example, you might want to treat this as a single term as opposed to breaking it up, there are also Analyzers that do &lt;a href="http://en.wikipedia.org/wiki/Stemming"&gt;Stemming&lt;/a&gt; and even &lt;a href="http://en.wikipedia.org/wiki/Phonetics"&gt;phonetic&lt;/a&gt; &lt;a href="http://lucene.apache.org/solr/api/org/apache/solr/analysis/PhoneticFilter.html"&gt;analysis&lt;/a&gt;.&amp;nbsp; The tokenizing process is involved but that should give you a basic idea, more can be found &lt;a href="http://futupark.wordpress.com/2008/04/01/text-analysis-inside-lucene/"&gt;here&lt;/a&gt;.&amp;nbsp; Tokenization allows the terms to be defined, identified and parsed and it is the properties of terms in relation to the documents which drive the Boolean Model, the Vector Space Model and tf*idf.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;The Boolean Model&lt;/h2&gt;&lt;br /&gt;
The Boolean Model treats documents as vectors of boolean indicators, this is a brief summary of ideas discussed in chapter one of &lt;u&gt;&lt;a href="http://nlp.stanford.edu/IR-book/pdf/01bool.pdf"&gt;Introduction to Information Retrieval&lt;/a&gt;&lt;/u&gt;, I am borrowing part of the example from that chapter:&lt;br /&gt;
&lt;br /&gt;
&lt;table border="1" cellspacing="0"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;&amp;nbsp;                         &lt;/td&gt;   &lt;td valign="top" width="78"&gt;Antony and Cleopatra&lt;/td&gt;   &lt;td valign="top" width="73"&gt;Julius Caesar&lt;/td&gt;   &lt;td valign="top" width="76"&gt;The Tempest&lt;/td&gt;   &lt;td valign="top" width="74"&gt;Hamlet &lt;/td&gt;   &lt;td valign="top" width="74"&gt;Othello &lt;/td&gt;   &lt;td valign="top" width="77"&gt;Macbeth&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Antony &lt;/td&gt;   &lt;td valign="top" width="78"&gt;1&lt;/td&gt;   &lt;td valign="top" width="73"&gt;1&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;0&lt;/td&gt;   &lt;td valign="top" width="77"&gt;1&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Brutus &lt;/td&gt;   &lt;td valign="top" width="78"&gt;1&lt;/td&gt;   &lt;td valign="top" width="73"&gt;1&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;1&lt;/td&gt;   &lt;td valign="top" width="74"&gt;0&lt;/td&gt;   &lt;td valign="top" width="77"&gt;0&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Caesar&lt;/td&gt;   &lt;td valign="top" width="78"&gt;1&lt;/td&gt;   &lt;td valign="top" width="73"&gt;1&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;1&lt;/td&gt;   &lt;td valign="top" width="74"&gt;1&lt;/td&gt;   &lt;td valign="top" width="77"&gt;1&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Calpurnia&lt;/td&gt;   &lt;td valign="top" width="78"&gt;0&lt;/td&gt;   &lt;td valign="top" width="73"&gt;1&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;0&lt;/td&gt;   &lt;td valign="top" width="77"&gt;0&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Cleopatra&lt;/td&gt;   &lt;td valign="top" width="78"&gt;1&lt;/td&gt;   &lt;td valign="top" width="73"&gt;0&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;0&lt;/td&gt;   &lt;td valign="top" width="77"&gt;0&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
This is an &lt;a href="http://en.wikipedia.org/wiki/Incidence_matrix"&gt;incidence matrix&lt;/a&gt; that shows which terms are in which documents.&amp;nbsp; This representation can be viewed as either a set of columns which form binary vectors indicating which term occurs in each document or it can be viewed as a set of binary term-vectors which shows which shows which documents contain a given term.&amp;nbsp; This example is also a bit deceiving in that these vectors will be pretty &lt;a href="http://en.wikipedia.org/wiki/Sparse_vector"&gt;sparse&lt;/a&gt;, The Tempest and Othello document vectors (columns) and the Cleopatra and Calpurnia term vectors (rows) are more indicative of this sparseness at this small scale.&amp;nbsp; Whether we store and search this data as a full matrix or individual vectors it would require a lot of space and the space would be mostly zeros, so a better structure to store and search this is used, the &lt;a href="http://en.wikipedia.org/wiki/Inverted_index"&gt;inverted index&lt;/a&gt;, the details of which are covered in chapter one of &lt;u&gt;Introduction to Information Retrieval&lt;/u&gt; and Apendix B of &lt;u&gt;Lucene in Action&lt;/u&gt;.&lt;br /&gt;
&lt;br /&gt;
The queries on this structure take the form of standard Boolean logic including: Logical Conjunction, Logical Disjunction and Logical Negation.  An example is (again taken from &lt;u&gt;Introduction to Information Retrieval&lt;/u&gt; with some notational modification):&lt;br /&gt;
&lt;br /&gt;
To answer the query we create a vector (q) [Brutus AND Caesar AND NOT Calpurnia], we take the Boolean vectors for Brutus (b), Caesar (c&lt;sub&gt;s&lt;/sub&gt;) and Calpurnia (c&lt;sub&gt;l&lt;/sub&gt;), complement the last, and then do a bitwise AND, where all Boolean vector operation are bitwise operations, this can all be denoted as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-KKcpUbbNt3c/T8PbSLWftlI/AAAAAAAAAhw/w4EH969jhy0/s1600/brutus.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="21" src="http://1.bp.blogspot.com/-KKcpUbbNt3c/T8PbSLWftlI/AAAAAAAAAhw/w4EH969jhy0/s400/brutus.png" width="127" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-TjlVpa-i1_k/T8PbZPZZzOI/AAAAAAAAAh8/BniCGIcSD9M/s1600/caeser.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="17" src="http://3.bp.blogspot.com/-TjlVpa-i1_k/T8PbZPZZzOI/AAAAAAAAAh8/BniCGIcSD9M/s400/caeser.png" width="135" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Lmfb17vn_SE/T8PbgX50drI/AAAAAAAAAiI/QAb-TFFjhNI/s1600/Calpurnia.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="17" src="http://3.bp.blogspot.com/-Lmfb17vn_SE/T8PbgX50drI/AAAAAAAAAiI/QAb-TFFjhNI/s400/Calpurnia.png" width="133" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-V4fync6UJzg/T8Pbmukoa8I/AAAAAAAAAiU/FzxRPWw_AGU/s1600/query.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="21" src="http://4.bp.blogspot.com/-V4fync6UJzg/T8Pbmukoa8I/AAAAAAAAAiU/FzxRPWw_AGU/s400/query.png" width="112" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-U6LedQ7PX_E/T8PbstPFL5I/AAAAAAAAAig/t0SUGBtdZL8/s1600/query1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="17" src="http://1.bp.blogspot.com/-U6LedQ7PX_E/T8PbstPFL5I/AAAAAAAAAig/t0SUGBtdZL8/s400/query1.png" width="375" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-D4jt9I-JrZo/T8Pb9hHr9dI/AAAAAAAAAiw/iI3npNJPWec/s1600/query2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="14" width="400" src="http://3.bp.blogspot.com/-D4jt9I-JrZo/T8Pb9hHr9dI/AAAAAAAAAiw/iI3npNJPWec/s400/query2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
The resulting term vector for this query yields: &lt;i&gt;[Antony and Cleopatra, Hamlet]&lt;/i&gt; vector positions one and four.&lt;br /&gt;
&lt;br /&gt;
In the above example you can see using the column vectors shows how the inverted index structure works. Here we are indexing into the corpus based on the terms not on the documents. So where a document is usually a collection terms (a column) we have inverted this document/term relationship and are now using the term/document relationship to link to the documents (rows). The inverted index structure in Lucene is built on listing terms and then linking to the documents, in Lucene each document is given an integer document id, so each term has a list of document ids that contain the document. The inverted index structure can include other information such as the position in the document or other metadata.&lt;br /&gt;
&lt;br /&gt;
The inverted index is the same concept as something known as a &lt;a href="http://en.wikipedia.org/wiki/Concordance"&gt;concordance&lt;/a&gt;, which is a list of words and their positions in a work used by scholars. A famous example is one that was published for the &lt;a href="http://en.wikipedia.org/wiki/Dead_Sea_Scrolls"&gt;Dead Sea scrolls&lt;/a&gt; by the team who exclusively controlled them, but the published images of the scrolls at a very slow pace which left many unpublished and this created a researcher monopoly on the scripts which upset many researchers who did not have access.  In 1988 Ben Zion Wacholder used a computer to reconstruct 17 documents from the concordance, these were published in 1991.&amp;nbsp; Coincidently the same month a complete set of facsimiles were discovered at the Huntington Library and published breaking the monopoly on the scrolls, they are now available &lt;a href="http://dss.collections.imj.org.il/"&gt;free on online&lt;/a&gt;, as they should be.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;tf*idf Weighting (Term Frequency*Inverse Document Frequency)&lt;/h2&gt;&lt;br /&gt;
tf*idf stands for Term Frequency – Inverse Document Frequency which is basically the Term Frequency multiplied by the Inverse Document Frequency.&amp;nbsp; In 1972 Karen Sparck Jones published a paper proposing what has become known as Inverse Document Frequency (idf) it is defined as:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-V8JDxHVNalk/T8PcQOLG-hI/AAAAAAAAAi8/t4ZF4UeUhBM/s1600/idf.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="39" width="119" src="http://4.bp.blogspot.com/-V8JDxHVNalk/T8PcQOLG-hI/AAAAAAAAAi8/t4ZF4UeUhBM/s400/idf.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Where |D| is the size of the set of all of the documents and |d&lt;sub&gt;t&lt;/sub&gt;| is the number of documents that contain the term, this formula is effectively the log of the inverse of the estimated (&lt;a href="http://en.wikipedia.org/wiki/Uniform_distribution"&gt;uniform&lt;/a&gt;) probability that a term will occur in a document, which would be given by the formula:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-JJiOnWiuqbo/T8PcWiATqzI/AAAAAAAAAjI/7X56lMf8N6c/s1600/term-prob.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="39" width="89" src="http://3.bp.blogspot.com/-JJiOnWiuqbo/T8PcWiATqzI/AAAAAAAAAjI/7X56lMf8N6c/s400/term-prob.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
This can be rewritten as:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-mVz0eL490Go/T8PcfT8p4UI/AAAAAAAAAjU/TYOlAeWsXdI/s1600/idf-prob.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="127" src="http://4.bp.blogspot.com/-mVz0eL490Go/T8PcfT8p4UI/AAAAAAAAAjU/TYOlAeWsXdI/s400/idf-prob.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Using the &lt;a href="http://www.elegantcoding.com/2011/10/ologn.html"&gt;logarithmic identity&lt;/a&gt;, this is needed since a log of a probability, which is less than or equal to one, will always be either a negative value or zero:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-qVZUFO6IWqo/UEARQMiPcQI/AAAAAAAAAnw/L2G1E0cG324/s1600/log-inv.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="140" src="http://2.bp.blogspot.com/-qVZUFO6IWqo/UEARQMiPcQI/AAAAAAAAAnw/L2G1E0cG324/s400/log-inv.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
The interesting thing about using logs is that it makes the idf terms addable for example if we want to compute the Inverse Document Frequency for term one and(&amp;wedge;) term two, assuming they are mutually exclusive which means the probability P(x &amp;wedge; y) = P(x)P(y) is multiplicative:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-8pq1gXjUZvE/T8Pd-wFk-NI/AAAAAAAAAjs/OvaiQMuQtMg/s1600/idf-der1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="219" src="http://1.bp.blogspot.com/-8pq1gXjUZvE/T8Pd-wFk-NI/AAAAAAAAAjs/OvaiQMuQtMg/s400/idf-der1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-W8B8xrIKJ34/T8PeC6b7iWI/AAAAAAAAAj4/c_PriaGI0LM/s1600/idf-der2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="239" src="http://4.bp.blogspot.com/-W8B8xrIKJ34/T8PeC6b7iWI/AAAAAAAAAj4/c_PriaGI0LM/s400/idf-der2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-l_ZifIJNVxk/T8QnK6f0PVI/AAAAAAAAAmg/iluVxRGKdFI/s1600/idf-der3.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="295" src="http://2.bp.blogspot.com/-l_ZifIJNVxk/T8QnK6f0PVI/AAAAAAAAAmg/iluVxRGKdFI/s400/idf-der3.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-gjoh0JjbXZ8/T8PeUMA70kI/AAAAAAAAAkQ/Uo77mOgNzU8/s1600/idf-der4.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="217" src="http://1.bp.blogspot.com/-gjoh0JjbXZ8/T8PeUMA70kI/AAAAAAAAAkQ/Uo77mOgNzU8/s400/idf-der4.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
The additive property is due to another logarithmic identity, which also forms a group &lt;a href="http://en.wikipedia.org/wiki/Isomorphism"&gt;isomorphism&lt;/a&gt; between multiplication of positive real numbers and addition of real numbers:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-HLxTEIwl5Kk/T8PebybZBeI/AAAAAAAAAkc/yR0pEMsibRs/s1600/log-ident-add.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="182" src="http://2.bp.blogspot.com/-HLxTEIwl5Kk/T8PebybZBeI/AAAAAAAAAkc/yR0pEMsibRs/s400/log-ident-add.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Now to get tf*idf we need to multiply the Term Frequency which is the number of times the term occurs in the document with the Inverse Document Frequency, the complete formula is:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-gkd-U7Dpric/T8PeiS3QPgI/AAAAAAAAAko/WU8Vdhfi4F4/s1600/tf-idf.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="39" width="159" src="http://3.bp.blogspot.com/-gkd-U7Dpric/T8PeiS3QPgI/AAAAAAAAAko/WU8Vdhfi4F4/s400/tf-idf.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
When I learned about this I immediately thought of the formula for &lt;a href="http://en.wikipedia.org/wiki/Information_theory"&gt;Information Theory&lt;/a&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-8SYGITehxpA/T8PenzSr3NI/AAAAAAAAAk0/peZZKfQHGr4/s1600/info-theory.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="46" width="359" src="http://4.bp.blogspot.com/-8SYGITehxpA/T8PenzSr3NI/AAAAAAAAAk0/peZZKfQHGr4/s400/info-theory.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
It turns out that this has been thought of and debated and is not really correct, a topic that is fairly involved and you can read more about it this &lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.97.7340"&gt;paper&lt;/a&gt; by Stephen Robertson.  The ideas above about the logarithmic properties of addition in idf are taken from this paper.&lt;br /&gt;
&lt;br /&gt;
Basically tf*idf is a term weighting mechanism which maps documents and terms to real numbers and we need this for the next piece of the puzzle.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-skUIKbm-Drc/T8PexB4YHDI/AAAAAAAAAlA/_GhgJXXz_so/s1600/Vector_space_model.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="393" width="400" src="http://2.bp.blogspot.com/-skUIKbm-Drc/T8PexB4YHDI/AAAAAAAAAlA/_GhgJXXz_so/s400/Vector_space_model.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Vector Space Model&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
One problem with the Boolean model is that it either gives too many results or too few.&amp;nbsp; In the example above a Shakespearean "micro-corpus" was used to demonstrate how it works but in real corpus a query like that could potentially retrieve thousands of documents which would make it impractical to attempt to wade through the result set. &amp;nbsp;This is where a weighting mechanism like tf*idf comes in, it effectively maps the boolean values to values in the domain of &lt;a href="http://en.wikipedia.org/wiki/Real_number"&gt;Real Numbers&lt;/a&gt;, well technically floating point numbers. &amp;nbsp;The vector space model uses the columns of the incidence matrix above which are the vectors of terms for each document where each term position in the vector is calculated using the tf*idf weighting scheme.&amp;nbsp; These document vectors exist in a Vector Space and a query can be constructed as a vector and each document can be compared to the query vector using the angles between the query vector and the document vectors (&amp;alpha;, &amp;theta;) to determine which documents (d&lt;sub&gt;1&lt;/sub&gt;,d&lt;sub&gt;2&lt;/sub&gt;) best answer a query (q), shown visually above.&amp;nbsp; Also you should note that this is a simple two dimensional example, in reality there will be a dimension for each additional term which becomes a hyperdimensional vector space consisting of hundreds or even thousands of dimensions.&amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
It is not the angle between vectors that is calculated but the cosine of the angle, which is known as the &lt;a href="http://en.wikipedia.org/wiki/Cosine_similarity"&gt;Cosine Similarity&lt;/a&gt;, this is used as it is easier to calculate than the angle itself, the formula is:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-cKKyWsz6-7I/T8Pj3RSTwWI/AAAAAAAAAmA/6xsfBZ5KW6c/s1600/cosine.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="38" width="229" src="http://2.bp.blogspot.com/-cKKyWsz6-7I/T8Pj3RSTwWI/AAAAAAAAAmA/6xsfBZ5KW6c/s400/cosine.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
The numerator is the &lt;a href="http://en.wikipedia.org/wiki/Dot_product"&gt;Dot Product&lt;/a&gt; of the two vectors, a query vector and a document vector, the denominator is the product of the Euclidean &lt;a href="http://en.wikipedia.org/wiki/Norm_%28mathematics%29"&gt;Norm&lt;/a&gt; or &lt;a href="http://en.wikipedia.org/wiki/Magnitude_%28mathematics%29#Euclidean_vectors"&gt;Magnitude&lt;/a&gt; of the two vectors.&amp;nbsp; The above equation can be written as follows with the expanded Dot Product and Euclidean Norm calculations:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-UnF218f9bnw/T8PjwSF6KRI/AAAAAAAAAl0/SZYE41WEKVE/s1600/cos-sim.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="94" width="277" src="http://1.bp.blogspot.com/-UnF218f9bnw/T8PjwSF6KRI/AAAAAAAAAl0/SZYE41WEKVE/s400/cos-sim.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
tf*idf is designed to increase as the number of occurrences of the term increase in a given document It should also be noted that the Vector Space Model can be built with other term weighting mechanisms other than tf*idf. &amp;nbsp;More information can be found in "&lt;a href="http://www.miislita.com/information-retrieval-tutorial/cosine-similarity-tutorial.html"&gt;Cosine Similarity and Term Weight Tutorial&lt;/a&gt;", in &lt;a href="http://nlp.stanford.edu/IR-book/pdf/06vect.pdf"&gt;chapter six of Introduction to Information Retrieval&lt;/a&gt; and Lucene specific information on &lt;a href="http://lucene.apache.org/core/3_6_0/scoring.html"&gt;scoring&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Extending our example from above we can calculate our weights, first the idf values:&lt;br /&gt;
&lt;br /&gt;
&lt;table border="1" cellspacing="0"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;&amp;nbsp;                     &lt;/td&gt;   &lt;td valign="top" width="49"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; D&lt;/td&gt;   &lt;td valign="top" width="54"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; d&lt;sub&gt;t&lt;/sub&gt;&lt;/td&gt;   &lt;td valign="top" width="108"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Idf&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Antony &lt;/td&gt;   &lt;td valign="top" width="49"&gt;6&lt;/td&gt;   &lt;td valign="top" width="54"&gt;3&lt;/td&gt;   &lt;td valign="top" width="108"&gt;0.69314718&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Brutus &lt;/td&gt;   &lt;td valign="top" width="49"&gt;6&lt;/td&gt;   &lt;td valign="top" width="54"&gt;3&lt;/td&gt;   &lt;td valign="top" width="108"&gt;0.69314718&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Caesar&lt;/td&gt;   &lt;td valign="top" width="49"&gt;6&lt;/td&gt;   &lt;td valign="top" width="54"&gt;5&lt;/td&gt;   &lt;td valign="top" width="108"&gt;0.18232155&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Calpurnia&lt;/td&gt;   &lt;td valign="top" width="49"&gt;6&lt;/td&gt;   &lt;td valign="top" width="54"&gt;1&lt;/td&gt;   &lt;td valign="top" width="108"&gt;1.79175946&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Cleopatra&lt;/td&gt;   &lt;td valign="top" width="49"&gt;6&lt;/td&gt;   &lt;td valign="top" width="54"&gt;1&lt;/td&gt;   &lt;td valign="top" width="108"&gt;1.79175946&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
From a &lt;a href="http://www.opensourceshakespeare.org/concordance/"&gt;Shakespearean concordance&lt;/a&gt; we can get the number of occurrences for each term:&lt;br /&gt;
&lt;br /&gt;
&lt;table border="1" cellspacing="0"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;&amp;nbsp;                         &lt;/td&gt;   &lt;td valign="top" width="78"&gt;Antony and Cleopatra&lt;/td&gt;   &lt;td valign="top" width="73"&gt;Julius Caesar&lt;/td&gt;   &lt;td valign="top" width="76"&gt;The Tempest&lt;/td&gt;   &lt;td valign="top" width="74"&gt;Hamlet &lt;/td&gt;   &lt;td valign="top" width="74"&gt;Othello &lt;/td&gt;   &lt;td valign="top" width="77"&gt;Macbeth&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Antony &lt;/td&gt;   &lt;td valign="top" width="78"&gt;157&lt;/td&gt;   &lt;td valign="top" width="73"&gt;61&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;0&lt;/td&gt;   &lt;td valign="top" width="77"&gt;1&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Brutus &lt;/td&gt;   &lt;td valign="top" width="78"&gt;3&lt;/td&gt;   &lt;td valign="top" width="73"&gt;112&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;1&lt;/td&gt;   &lt;td valign="top" width="74"&gt;0&lt;/td&gt;   &lt;td valign="top" width="77"&gt;0&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Caesar&lt;/td&gt;   &lt;td valign="top" width="78"&gt;159&lt;/td&gt;   &lt;td valign="top" width="73"&gt;145&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;2&lt;/td&gt;   &lt;td valign="top" width="74"&gt;1&lt;/td&gt;   &lt;td valign="top" width="77"&gt;1&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Calpurnia&lt;/td&gt;   &lt;td valign="top" width="78"&gt;0&lt;/td&gt;   &lt;td valign="top" width="73"&gt;10&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;0&lt;/td&gt;   &lt;td valign="top" width="77"&gt;0&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Cleopatra&lt;/td&gt;   &lt;td valign="top" width="78"&gt;56&lt;/td&gt;   &lt;td valign="top" width="73"&gt;0&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;0&lt;/td&gt;   &lt;td valign="top" width="74"&gt;0&lt;/td&gt;   &lt;td valign="top" width="77"&gt;0&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using the idf values and term frequencies we can calculate tf*idf for our documents:&lt;br /&gt;
&lt;br /&gt;
&lt;table border="1" cellspacing="0"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;&amp;nbsp;                         &lt;/td&gt;   &lt;td valign="top" width="78"&gt;Antony and Cleopatra&lt;/td&gt;   &lt;td valign="top" width="78"&gt;Julius Caesar&lt;/td&gt;   &lt;td valign="top" width="76"&gt;The Tempest&lt;/td&gt;   &lt;td valign="top" width="85"&gt;Hamlet&lt;/td&gt;   &lt;td valign="top" width="85"&gt;Othello&lt;/td&gt;   &lt;td valign="top" width="85"&gt;Macbeth&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Antony &lt;/td&gt;   &lt;td valign="top" width="78"&gt;108.82410&lt;/td&gt;   &lt;td valign="top" width="78"&gt;42.281978&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0.69314718&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Brutus &lt;/td&gt;   &lt;td valign="top" width="78"&gt;2.0794415&lt;/td&gt;   &lt;td valign="top" width="78"&gt;77.632484&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0.69314718&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Caesar&lt;/td&gt;   &lt;td valign="top" width="78"&gt;28.989127&lt;/td&gt;   &lt;td valign="top" width="78"&gt;26.436625&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0.36464311&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0.18232155&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0.18232155&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Calpurnia&lt;/td&gt;   &lt;td valign="top" width="78"&gt;0&lt;/td&gt;   &lt;td valign="top" width="78"&gt;17.917594&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td valign="top" width="72"&gt;Cleopatra&lt;/td&gt;   &lt;td valign="top" width="78"&gt;100.33853&lt;/td&gt;   &lt;td valign="top" width="78"&gt;0&lt;/td&gt;   &lt;td valign="top" width="76"&gt;0&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0&lt;/td&gt;   &lt;td valign="top" width="85"&gt;0&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
I will leave calculating a query as an exercise for you, if you are feeling so inclined or masochistic.&lt;br /&gt;
&lt;br /&gt;
Lucene uses a &lt;a href="http://lucene.apache.org/core/old_versioned_docs/versions/3_0_2/api/core/org/apache/lucene/search/Similarity.html"&gt;combination of the Boolean Model and the Vector Space Model&lt;/a&gt;, when the query is run the documents are first "approved", selected, by the Boolean Model and then scored by The Vector Space Model. &amp;nbsp;I believe this approach offers two advantages. &amp;nbsp;First it would reduce the number of calculations to search the Vector Space since you aren’t really searching it and limiting your calculations to a subset. &amp;nbsp;Secondly the Vector Space Model does not handle negation in queries, and I am not sure how negation is handled in Lucene in regards to scoring.&amp;nbsp; Actually there have been a number of IR tweaks and improvements for flexibility and efficiency that have been incorporated into Lucene and I confess I have only scratched the surface in both my coverage here and current knowledge.&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/S0U4_SlLtbk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/S0U4_SlLtbk/math-of-search-and-similarity.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-7-js_ScUkE8/T8PfQb6RtcI/AAAAAAAAAlk/4ygxkjyT6L8/s72-c/resize_IMG_3632.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/05/math-of-search-and-similarity.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-3572137304010579924</guid><pubDate>Sun, 13 May 2012 19:24:00 +0000</pubDate><atom:updated>2012-05-13T15:46:23.720-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Morphology</category><category domain="http://www.blogger.com/atom/ns#">Naming</category><category domain="http://www.blogger.com/atom/ns#">Software Engineering</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><category domain="http://www.blogger.com/atom/ns#">Linguistics</category><title>Software System Morphology</title><description>&lt;!--Software System Morphology--&gt;&lt;h2&gt;On the Importance of Naming in Software Systems, part III&lt;/h2&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-OU0wTOfHWQE/T7AEkPlqPXI/AAAAAAAAAhA/dY-ANZrluxo/s1600/europa_galileo.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="267" width="400" src="http://1.bp.blogspot.com/-OU0wTOfHWQE/T7AEkPlqPXI/AAAAAAAAAhA/dY-ANZrluxo/s400/europa_galileo.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;In my previous posts on naming "&lt;a href="http://www.elegantcoding.com/2012/03/survey-of-conventional-wisdom-on.html"&gt;A Survey of the Conventional Wisdom on Software Naming&lt;/a&gt;" and "&lt;a href="http://www.elegantcoding.com/2012/03/more-thoughts-on-formal-approaches-to.html"&gt;More Thoughts on Formal Approaches to Naming in Software&lt;/a&gt;" I discussed several ideas about defining a way to talk about software system naming, I feel the name "Software System Morphology" captures this "big picture" concept. My objective is to develop a comprehensive way to define and analyze the &lt;a href="http://en.wikipedia.org/wiki/Semantics"&gt;semantic&lt;/a&gt; nature (&lt;a href="http://en.wikipedia.org/wiki/Morphology_(linguistics)"&gt;morphology&lt;/a&gt;) of the construction of a software system. It’s an ambitious undertaking and whether or not I succeed in this endeavor I am hoping that these ideas will contribute to a better solution to this problem.&lt;/p&gt;&lt;p&gt;To review, I am defining three attributes that a name of signifier can have, the &lt;b&gt;&lt;i&gt;name scope context&lt;/i&gt;&lt;/b&gt;, i.e. where the name is used or occurs, the type or class of the &lt;b&gt;&lt;i&gt;system referent&lt;/i&gt;&lt;/b&gt; signified by the name, and the lexical structure of the name i.e. the &lt;a href="http://en.wikipedia.org/wiki/N-gram"&gt;n-gram&lt;/a&gt; of &lt;b&gt;&lt;i&gt;name units&lt;/i&gt;&lt;/b&gt;.  I feel that these three qualities can be used to determine and possibly measure aspects of the morphological structure of software and by determining the morphological structure of a software system that structure might be &amp;quot;comprehended&amp;quot; and refined which could yield higher quality software.  &lt;/p&gt;&lt;p&gt;In Linguistics a &lt;a href="http://en.wikipedia.org/wiki/Morpheme"&gt;morpheme&lt;/a&gt; is the smallest unit of meaning and it is considered, by some, to be a complete sub-discipline of the study of Linguistics. I admit that I am in the process of learning more about it, I am a few chapters into &lt;u&gt;What is Morphology&lt;/u&gt; by Mark Aronoff and Kirsten Fudeman it is an excellent book for linguistic neophytes like me.  &lt;b&gt;&lt;i&gt;Software System Morphology&lt;/i&gt;&lt;/b&gt; will both be divergent and dependent on &lt;a href="http://en.wikipedia.org/wiki/Natural_language"&gt;natural language&lt;/a&gt; morphological concepts, which are quite complex.  However a general understanding of linguistic morphology will make these ideas more accessible, I suggest looking into it on your own, it’s fascinating and worth it solely on its own merits.  A quick example of English Morphology can be given with the morphologically complex word autobiography which consists of the morphemes: auto/bio/graph/y, where [auto] means "self", [bio] means "life", [graph] means "drawn" and [y] means "characterized by". &lt;/p&gt;&lt;p&gt;In my first post of this series I explored various ideas proposed by a few prominent software engineers, one idea that I discussed was the use of what were denoted as qualifiers which included the scope qualifier, the type qualifier and the computed-value qualifier. These qualifiers which are prefixed or suffixed to names can be thought of more generally as morphemes. So we can now incorporate those ideas into a more general way of looking at meaning in software naming. Now the natural conclusion, if you have been paying attention, may be to assume that the name unit concept will map to the morpheme concept, it does not, at least in terms of only software morphology and this is in interesting distinction, software morphemes may consist of n-grams of name units which can be natural language morphemes two examples are CommandPattern and MedicalRecord where separating these into individual name units potentially become meaningless in certain software contexts.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;i&gt;Software System Morphology&lt;/i&gt;&lt;/b&gt; is primarily influenced by three things, the semantic nature of the &lt;b&gt;&lt;i&gt;problem domain&lt;/i&gt;&lt;/b&gt;(s), the semantic nature of the &lt;b&gt;&lt;i&gt;solution domain&lt;/i&gt;&lt;/b&gt;(s), which include languages ORMs, paradigms, design patterns, data structures, and finally the natural language(s) in which both the &lt;b&gt;&lt;i&gt;problem domain&lt;/i&gt;&lt;/b&gt; and &lt;b&gt;&lt;i&gt;solution domains&lt;/i&gt;&lt;/b&gt; are expressed. The previous example items CommandPattern and MedicalRecord illustrate these ideas as well.  &lt;/p&gt;&lt;p&gt;Ok now let’s take our concepts further with a more detailed example.  Assume we have a Hospital Medical system which has the following &lt;b&gt;&lt;i&gt;problem domain&lt;/i&gt;&lt;/b&gt; concepts: [Medical Record, Patient, Visit, Doctor, Hospital, Address, Invoice]. Obviously there are more. For the &lt;b&gt;&lt;i&gt;solution domain&lt;/i&gt;&lt;/b&gt; we will assume a JEE/Spring style implementation which might include the following concepts: [Entity, Dao, ServiceLayer, Controller, Map, View].  Now some expected names (signifiers) might be: MedicalRecordEntity, PatientEntity, PatientServiceLayer, PatientDao, PatientController, PatientView, VisitEntity, VisitDao, VisitServiceLayer, VisitController, VisitView, PatientVisitMap, PatientHospitalVisitor,... Now as you can see the names are composed of morphemes from both the &lt;b&gt;&lt;i&gt;problem domain&lt;/i&gt;&lt;/b&gt; and the &lt;b&gt;&lt;i&gt;solution domain&lt;/i&gt;&lt;/b&gt;.  This is to be expected as each name tells what it is/does in the &lt;b&gt;&lt;i&gt;problem domain&lt;/i&gt;&lt;/b&gt; and what it is/does in the &lt;b&gt;&lt;i&gt;solution domain&lt;/i&gt;&lt;/b&gt;. In fact any developer with knowledge of JEE Spring Web application developer can look at these names and know what to expect and where they fit in the system.  Additionally it is easy to look at the above set of domain concepts and anticipate &lt;b&gt;&lt;i&gt;named system referents&lt;/i&gt;&lt;/b&gt; that I omitted.&lt;/p&gt;&lt;p&gt;Previously I pointed out that the idea referred to as a qualifier is really a morpheme and while this is true the term qualifier seems to denote a more contextual setting in terms of the domain concepts.  In the above examples the &lt;b&gt;&lt;i&gt;solution domain&lt;/i&gt;&lt;/b&gt; morphemes act as qualifiers telling where and how each &lt;b&gt;&lt;i&gt;named system referent&lt;/i&gt;&lt;/b&gt; fits into the solution Entity tells that it is a domain object, Dao tells that it relates to persistence, ServiceLayer tells that one would expect to see a &lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;separation of concerns&lt;/a&gt; that would put the &lt;a href="http://en.wikipedia.org/wiki/Business_Logic"&gt;business logic&lt;/a&gt; here. Structurally one would expect the domain objects (with the Entity suffix) to be passed back from the Dao’s and ServiceLayer’s and there might be transformative manipulation or aggregation of the domain objects in the ServiceLayer.  The idea of qualification is meaning based but in this case it also indicates structural aspects of the &lt;b&gt;&lt;i&gt;solution domain&lt;/i&gt;&lt;/b&gt;. In this example I intentionally use the Entity suffix, in many systems the domain concepts would be used alone i.e. [Patient, Visit], I have mixed feelings about this in one sense it can be viewed as potentially unnecessary, in another sense it represents a qualifier that can possibly improve comprehension. Qualifiers do make names longer and while I tend to favor longer names it can become problematic if they get too long.  These ideas towards naming are powerful for building comprehensible maintainable code as you can see from the above name examples that they follow a consistent pattern, admittedly these are fairly easy naming tasks, but you would be surprised how many developers fail to even do these types of things consistently. &lt;/p&gt;&lt;p&gt;Unlike &lt;a href="http://www.elegantcoding.com/2012/03/survey-of-conventional-wisdom-on.html"&gt;others&lt;/a&gt; who advocate specific practices in regards to naming I feel that naming should be dealt with in a flexible framework that can be adapted to a specific project’s needs.  While I personally agree and disagree with ideas previously discussed, my philosophy is that naming should be done consistently and comprehensively reflecting deliberate choices using conceptual understanding and analysis of the Domains. Also it should be tracked in a Lexicon, an idea that I am working on and hope to explore in a later post.  Also as I have said before I feel that tooling could be used to allow better conceptual understanding and navigation and the use of analytics and possibly visualization could be used to ease naming decisions in practice by providing improvements to both &lt;a href="http://en.wikipedia.org/wiki/Static_program_analysis"&gt;static analysis&lt;/a&gt; and interactive &lt;a href="http://en.wikipedia.org/wiki/Autocompletion"&gt;autosuggest&lt;/a&gt;/&lt;a href="http://en.wikipedia.org/wiki/IntelliSense"&gt;intellisense&lt;/a&gt; aids.&lt;/p&gt;&lt;p&gt;I feel that these ideas are an attempt to create a more "formalized" approach to what Eric Evan’s does in &lt;u&gt;Domain Driven Design&lt;/u&gt; which also covers a number of other structural ideas, I hope to extend my ideas here to better integrate some of those as well.  The next steps for me are to undertake an analytic approach I also hope to explore the application of ideas like &lt;a href="http://en.wikipedia.org/wiki/Formal_concept_analysis"&gt;formal concept analysis&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Spectral_graph_theory"&gt;spectral graph theory&lt;/a&gt; techniques which may add some mathematical rigor to these ideas and perhaps allow some empirical validation and probably refinement. Now it gets really hard so it might be a while for those follow-ups.&lt;/p&gt;&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/Pnbh96zAS-0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/Pnbh96zAS-0/software-system-morphology.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-OU0wTOfHWQE/T7AEkPlqPXI/AAAAAAAAAhA/dY-ANZrluxo/s72-c/europa_galileo.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/05/software-system-morphology.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-4856506076120221020</guid><pubDate>Sun, 29 Apr 2012 21:12:00 +0000</pubDate><atom:updated>2012-05-27T10:12:50.902-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Scala</category><category domain="http://www.blogger.com/atom/ns#">Math</category><category domain="http://www.blogger.com/atom/ns#">Design Patterns</category><category domain="http://www.blogger.com/atom/ns#">Software Engineering</category><category domain="http://www.blogger.com/atom/ns#">Code Reuse</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><category domain="http://www.blogger.com/atom/ns#">Generic Programming</category><category domain="http://www.blogger.com/atom/ns#">Computer Science</category><title>What is Generic Programming?</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-o3_JQhsIZYg/T52KCmSVf1I/AAAAAAAAAgw/mz-7UulHJMI/s1600/paris.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="300" src="http://3.bp.blogspot.com/-o3_JQhsIZYg/T52KCmSVf1I/AAAAAAAAAgw/mz-7UulHJMI/s400/paris.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;style&gt;
blockquote.quote {
   border-bottom: #ddd 1px dotted;
   border-left: #ddd 1px dotted;
   padding-bottom: 0.6em;
   font-style: italic;
   font-family: calibri, tahoma, arial, sans-serif;
   margin: 1em 10% 1em 0px;
   min-height: 40px;
   padding-left: 3.8em;
   padding-right: 1em;
   background: url(http://4.bp.blogspot.com/-WkhuNlv2j88/TjXlBh6SySI/AAAAAAAAAN0/O_G2Z8YdMk8/s320/blockquote.white.png) #f0f0f0 no-repeat 4px top;
   color: #474747;
   border-top: #ddd 1px dotted;
   border-right: #ddd 1px dotted;
   padding-top: 0.6em
}
&lt;/style&gt;&lt;!--What is Generic Programming?--&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;Over the course of my career I have strived to write reusable code, always looking for more general patterns and trying to refactor code to more flexible more generic versions sometimes with mixed success.  Lately it has become something of an obsession of mine in that I both try to employ it and have been endeavoring to learn more about it, what it really is, and how to do it right, as I have previously pondered I believe there is a &lt;a href="http://www.elegantcoding.com/2012/02/software-reuse-complexity-curve.html"&gt;complexity cost with increased reuse&lt;/a&gt;.  Over the last few years, which I have been programming in Java, generics has become a central tool in achieving reuse.  So such a concept comes to mind but it is just one idea in a larger framework of ideas on &lt;a href="http://en.wikipedia.org/wiki/Generic_programming"&gt;generic programming&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;There is a fair amount of research and discussion of the ideas pertaining to generic programming, the title of this post is taken directly from a &lt;a href="http://lcsd05.cs.tamu.edu/papers/dos_reis_et_al.pdf"&gt;paper on the topic&lt;/a&gt;, which perhaps not so coincidently was presented at the same OOPSLA (2005) as the paper on &lt;a href="http://lcsd05.cs.tamu.edu/papers/veldhuizen.pdf"&gt;Software Reuse and Entropy&lt;/a&gt; that &lt;a href="http://www.elegantcoding.com/2011/07/software-frameworks-resistance-isnt.html"&gt;I previously discussed&lt;/a&gt;.  It just seems like every idea I explore is super-interrelated to everything else and this post will be no exception, I can conceptually connect these two papers using a Kevin Bacon like approach using just two other research papers, ideas I have for other posts.  I will try to keep this one as focused as possible.  Also the referenced &lt;a href="http://lcsd05.cs.tamu.edu/papers/dos_reis_et_al.pdf"&gt;paper&lt;/a&gt; is, like the Software Framework paper, very math heavy but different math, &lt;a href="http://en.wikipedia.org/wiki/Category_theory"&gt;Category Theory,&lt;a href="http://en.wikipedia.org/wiki/Order_theory"&gt;Order Theory&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Universal_algebra"&gt;Universal Algebra&lt;/a&gt;, etc. This post will focus on more high level concepts and not the details of math that I wish I could claim that I fully understand.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;So back to our question, what is generic programming?   For me it is about reuse, and while the information entropy approach to understanding reuse was about reuse from perspective of measure and the reuse (measurable) variation on different domains, I feel that the generic programming concept is about the structure of reuse and how it is implemented in various programming paradigms but the concept itself transcends language specific interpretations and implementations.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;As you can tell I am not sure how to exactly answer this question so I will defer to the experts.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;"&lt;a href="http://lcsd05.cs.tamu.edu/papers/dos_reis_et_al.pdf"&gt;What is generic programming?&lt;/a&gt;" in part outlines the paradigmatic distinctions between mainstream OO languages (Java Generics, C++ with STL) and Functional languages (Haskel, Scheme):&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;As for most programming paradigms, there are several definitions of generic programming in use. In the simplest view generic programming is equated to a set of language mechanisms for implementing type-safe polymorphic containers, such as List&amp;lt;T&amp;gt; in Java. The notion of generic programming that motivated the design of the Standard Template Library (STL) advocates a broader definition: a programming paradigm for designing and developing reusable and efficient collections of algorithms. The functional programming community uses the term as a synonym for polytypic and type-indexed programming, which involves designing functions that operate on data-types having certain algebraic structures.&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;In "&lt;a href="http://www.stepanovpapers.com/genprog.pdf"&gt;Generic Programming&lt;/a&gt;" written in 1988 by David A. Musser and &lt;a href="http://www.stepanovpapers.com/"&gt;Alexander A. Stepanov&lt;/a&gt; use Ada and Scheme and describe generic programming as:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;By generic programming, the definition of algorithms and data structures at an abstract or generic level, thereby accomplishing many related programming tasks simultaneously.  The central notion is that of generic algorithms, which are parameterized procedural schemata that are completely independent of the underlying data representation and are derived from concrete efficient algorithms.&lt;/p&gt;&lt;p&gt;...&lt;/p&gt;&lt;p&gt;A discipline that consists of the gradual lifting of concrete algorithms abstracting over details, while retaining the algorithm semantics and efficiency.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;That last sentence has a very Agile/Refactoring feel to it.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Ralf Hinze in "&lt;a href="www.cs.ox.ac.uk/ralf.hinze/publications/habilitation.pdf"&gt;Generic Programs and Proofs&lt;/a&gt;" describes it as: &lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;A generic program is one that the programmer writes once, but which works over many different data types.&lt;/p&gt;&lt;p&gt;...&lt;/p&gt;&lt;p&gt;Broadly speaking, generic programming aims at relieving the programmer from repeatedly writing functions of similar functionality for different user-defined data types. A generic function such as a pretty printer or a parser is written once and for all times; its specialization to different instances of data types happens without further effort from the user. This way generic programming greatly simplifies the construction and maintenance of software systems as it automatically adapts functions to changes in the representation of data.&lt;/p&gt;&lt;p&gt;...&lt;/p&gt;&lt;p&gt;So, at first sight, generic programming appears to add an extra level of complication and abstraction to programming. However, I claim that generic programming is in many cases actually simpler than conventional programming.  The fundamental reason is that genericity gives you "a lot of things for free" ...&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;This last statement resonates with me as it parallels my thoughts on the desirability of using &lt;a href="http://www.elegantcoding.com/2011/07/software-frameworks-resistance-isnt.html"&gt;software frameworks&lt;/a&gt; and I feel that I continuously have this conversation (argument) with junior level programmers and also senior level &lt;a href="http://www.elegantcoding.com/2011/10/confederacy-of-cargo-cult-coders.html"&gt;cargo cult coders&lt;/a&gt; who don’t get it.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Design Patterns are a common generic concept in mainstream programming.  It turns out that a number of design patterns can be described in the framework laid out by these papers and a number of papers do exactly that including "&lt;a href="http://www.cs.ox.ac.uk/jeremy.gibbons/publications/hodgp.pdf"&gt;Design Patterns as Higher-Order Datatype-Generic Programs &lt;/a&gt;" part of extensive research on the topic by Jeremy Gibbons:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;Design patterns, as the subtitle of the seminal book has it, are ‘elements of reusable object-oriented software’. However, within the confines of existing mainstream programming languages, these supposedly reusable elements can only be expressed extra-linguistically: as prose, pictures, and prototypes. We believe that this is not inherent in the patterns themselves, but  evidence of a lack of expressivity in the languages of today. We expect that, in the languages of the future, the code parts of design patterns will be expressible as directly-reusable library components. The benefits will be considerable: patterns may then be reasoned about, typechecked, applied and reused, just as any other abstractions can. Indeed, we claim that the languages of tomorrow will suffice; the future is not far away. All that is needed, in addition to what is provided by essentially every programming language, are higher-order (parametrization by code) and datatype-generic (parametrization by type constructor) features. Higher-order constructs have been available for decades in functional programming languages such as &lt;a href="http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&amp;amp;tid=3874"&gt;ML&lt;/a&gt; and &lt;a href="www.haskell.org/definition/haskell98-report.pdf"&gt;Haskell&lt;/a&gt;. Datatype genericity can be simulated in &lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.19.7113"&gt;existing programming languages&lt;/a&gt; &lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.71.463"&gt;[2]&lt;/a&gt;, but we already have significant experience with robust prototypes of languages that support &lt;a href="http://igitur-archive.library.uu.nl/math/2007-0404-200301/jeuring_03_generichaskellpractice_technical.pdf"&gt;it natively&lt;/a&gt; &lt;a href="http://www.andres-loeh.de/ExploringGH.pdf"&gt;[2]&lt;/a&gt;. We argue our case by capturing as higher-order datatypegeneric programs a small subset &lt;a href="http://www.cs.ox.ac.uk/jeremy.gibbons/publications/origami.pdf"&gt;ORIGAMI&lt;/a&gt; of the &lt;a href="citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.71.463"&gt;Gang of Four (GOF) patterns&lt;/a&gt;. (For the sake of rhetorical style, we equate ‘GOF patterns’ with ‘design patterns’.) These programs are parametrized along three dimensions: by the shape of the computation, which is determined by the shape of the underlying data, and represented by a type constructor (an operation on types); by the element type (a type); and by the body of the computation, which is a higher-order argument (a value, typically a function).  Although our presentation is in a functional programming style, we do not intend to argue that functional programming is the paradigm of the future (whatever we might feel personally!).  Rather, we believe that functional programming languages are a suitable test-bed for experimental language features - as evidenced by parametric polymorphism and list comprehensions, for example, which are both now finding their way into mainstream programming languages such as Java and C#.  We expect that the evolution of programming languages will continue to follow the same trend: experimental language features will be developed and explored in small, nimble laboratory languages, and the successful experiments will eventually make their way into the outside world. Specifically, we expect that the mainstream languages of tomorrow will be broadly similar to the languages of today — strongly and statically typed, object-oriented, with an underlying imperative mindset — but incorporating additional features from the functional world — specifically, higher-order operators and datatype genericity&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;Lately I have been making more of an effort to learn Scala. Bruno Oliveira and Jeremy Gibbons make the case in "&lt;a href="www.cs.ox.ac.uk/jeremy.gibbons/publications/scalagp.pdf"&gt;Scala for Generic Programmers&lt;/a&gt;" that it might be one of or even the best language for expressing Generic Programming concepts in part due to its hybridization of object oriented and functional paradigms. Here is the abstract in its entirety:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;Datatype-generic programming involves parametrization by the shape of data, in the form of type constructors such as ‘list of’.  Most approaches to datatype-generic programming are developed in the lazy functional programming language Haskell. We argue that the functional object-oriented language Scala is in many ways a better setting. Not only does Scala provide equivalents of all the necessary functional programming features (such parametric polymorphism, higher-order functions, higher-kinded type operations, and type- and constructor-classes), but it also provides the most useful features of object-oriented languages (such as subtyping, overriding, traditional single inheritance, and multiple inheritance in the form of traits). We show how this combination of features benefits datatype-generic programming, using three different approaches as illustrations.&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;So far for me Scala has been a joy.  Its features and flexibility are beautifully elegant of course I am tainted coming from the clumsy, clinking, clanking, clattering caliginous world of Java, BTW Java we need to talk, it’s not you, it’s me. I’ve met someone else.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Jeremy Gibbons Makes the following point in "&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.159.1228"&gt;Datatype-Generic Programming&lt;/a&gt;":&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;Generic programming is about making programming languages more flexible without compromising safety. Both sides of this equation are important, and becoming more so as we seek to do more and more with computer systems, while becoming ever more dependent on their reliability.&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;This idea is similar to ideas that &lt;a href="http://www.infoq.com/author/Gerald-Jay-Sussman"&gt;Gerald Sussman&lt;/a&gt; explores in his talk at &lt;a href="https://thestrangeloop.com/"&gt;Strangeloop&lt;/a&gt; 2011 "&lt;a href="http://www.infoq.com/presentations/We-Really-Dont-Know-How-To-Compute"&gt;We Really Don’t Know How To Compute&lt;/a&gt;".  However, his general and perhaps philosophical approach to the idea of generic programming is very different from the previous ideas:    &lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;[8:40]We spend all of our time modifying existing code, the problem is our code is not adequately evolvable it is not adequately modifiable to fit the future in fact what we want is to make systems that have the property that they are good for things that the designer didn’t even think of or intend.  ... That’s the real problem. ...  The problem is that when we build systems whatever they are we program ourselves into holes. ...  It means that we make decisions early in some process that spread all over our system the consequences of those decisions such that the things that we want to change later are very difficult to change because we have to change a very large amount of stuff.  ... I want to figure ways that we can organize systems so that the consequence of the decisions we make are not expensive to change, we can’t avoid making decisions but we can try to figure out ways to minimize the cost of changing decisions we have made.&lt;/p&gt;&lt;p&gt;...&lt;/p&gt;&lt;p&gt;[11:40]Dynamically extensible generic operations  ...  I want to dynamically extend things while my program is running  ... I want a program to compute up what it is going to do.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;He shows an example[19:00] which is "the definition of the method of computing Lagrange Equations from a Lagrangian given a configuration space path". This is apparently easy stuff, to him at least.  Fortunately you don’t really need to understand the details of this math to understand his points here:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;[20:45]This is a little tiny feeling of what is it needed to make things more flexible consider the value here, the value is that I am dynamically allowed to change the meaning of all my operators to add new things that they can do. Dynamically. Not at compile time, at runtime.&lt;/p&gt;&lt;p&gt;...&lt;/p&gt;&lt;p&gt;[21:15]It gives me tremendous flexibility. Flexibility because the program I wrote to run on  a bunch of numbers with only a little bit of tweaking suddenly runs on matrices so long as I didn’t make mistake of commuting something wrong. ... So this makes proving the theorems very hard In fact maybe impossible the cost and the benefits are very extreme. I can pay  correctness or proofs of correctness or belief in correctness, I can pay that for tremendous flexibility. ... Is correctness the essential thing I want, I am not opposed to proofs, I love proofs I am an old mathematician. The problem is that putting us into the situation that &lt;a href="http://en.wikipedia.org/wiki/Edsger_W._Dijkstra"&gt;Mr. Dijkstra&lt;/a&gt; got us into ... where you are supposed to prove everything to be right before you write the program getting into that situation puts us in a world where we have to make the specifications for the parts as tight as possible because it’s hard to prove general things, except occasionally it’s easier but it’s usually harder to prove a general theorem about something so you make a very specialized thing that works for a particular case you build this very big tower of stuff and boy is that brittle change the problem a little and it all falls over.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;His ideas tend towards adaptable and self modifying code at one point he talks about self modifying code in both assembly language and the use of eval in Lisp.  He also touches on a number of parallels in the biological world including genetics and the adaptability of the human immune system to fight off mutating parasites.  Interestingly some of his ideas seem similar to work done by &lt;a href="http://www.cs.unm.edu/~forrest/"&gt;Stephanie Forrest&lt;/a&gt; on using evolutionary/genetic algorithms for program repair which she speaks about at the &lt;a href="http://www.infoq.com/presentations/The-Case-for-Evolvable-Software"&gt;keynote&lt;/a&gt; of SPLASH 2010, formerly known as OOPSLA.  The genetic repair approach at the conceptual level is striving for the same results as what &lt;a href="http://www.infoq.com/author/Gerald-Jay-Sussman"&gt;Gerald Sussman&lt;/a&gt; describes.  Also did you notice that the &lt;a href="http://en.wikipedia.org/wiki/Levenshtein_distance"&gt;Levenshtein Distance&lt;/a&gt; between "generic programming" and "genetic programming" is (one substitution), pretty weird!&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Seriously though, the objectives of all of these approaches are the same: building better more flexible software that handles more situations. These ideas are reflected in how &lt;a href="http://www.elegantcoding.com/2012/01/real-software-engineering-good-bad-and.html"&gt;Glenn Vanderburg describes software engineering&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;Software engineering is the science and art of designing and making, with economy and elegance, systems so that they can readily adapt to situations which they may be subjected.&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;I feel this Software Engineering insight reinforces &lt;a href="http://www.elegantcoding.com/2012/01/real-software-engineering-good-bad-and.html"&gt;my opinion&lt;/a&gt; that we will eventually see a real math backed discipline of software engineering and I think that the research work discussed  here both supports my conjecture on this point and most likely lays part of that foundation.  I also think some of these ideas reflect ideas I discussed in "&lt;a href="http://www.elegantcoding.com/2012/02/software-reuse-complexity-curve.html"&gt;The Software Reuse Complexity Curve&lt;/a&gt;" which implies that programmers will need to become more aware and more adept at more advanced theoretically based concepts like for example &lt;a href="http://www.haskell.org/haskellwiki/GADT"&gt;GADT’s (Generalized algebraic datatypes)&lt;/a&gt;, etc. and of course math in general such as &lt;a href="http://www.elegantcoding.com/2012/03/interesting-group.html"&gt;Abstract Algebra&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Clearly the idea of Generic programming has some very specific ideas and some very general objectives. There seem to be two approaches here which might described Predictive vs. Adaptive, much like the idea of &lt;a href="http://martinfowler.com/articles/newMethodology.html#PredictiveVersusAdaptive"&gt;Separation of Design and Construction&lt;/a&gt; described by Martin Fowler.  The Gibbons et al more calculational approach is &lt;b&gt;predictive&lt;/b&gt; whereas the Sussman/Forrest ideas describe an &lt;b&gt;adaptive&lt;/b&gt; approach. I suspect that this will just be another dimension of program design that will have to be considered and assessed as a tradeoff in its application, which Sussman also mentions.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/qHMkihlk76g" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/qHMkihlk76g/what-is-generic-programming.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-o3_JQhsIZYg/T52KCmSVf1I/AAAAAAAAAgw/mz-7UulHJMI/s72-c/paris.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/04/what-is-generic-programming.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-658407234782678688</guid><pubDate>Sun, 01 Apr 2012 20:47:00 +0000</pubDate><atom:updated>2012-05-06T11:59:56.721-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">Neuroscience</category><category domain="http://www.blogger.com/atom/ns#">Pair Programming</category><title>The Coding Buzz</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-fe0RVK0ynmQ/T3i-BBa2JlI/AAAAAAAAAgk/9B61aneV_AQ/s1600/533207main_iss027e006501_full.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="274" width="400" src="http://1.bp.blogspot.com/-fe0RVK0ynmQ/T3i-BBa2JlI/AAAAAAAAAgk/9B61aneV_AQ/s400/533207main_iss027e006501_full.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;style&gt;
blockquote.quote {
   border-bottom: #ddd 1px dotted;
   border-left: #ddd 1px dotted;
   padding-bottom: 0.6em;
   font-style: italic;
   font-family: calibri, tahoma, arial, sans-serif;
   margin: 1em 10% 1em 0px;
   min-height: 40px;
   padding-left: 3.8em;
   padding-right: 1em;
   background: url(http://4.bp.blogspot.com/-WkhuNlv2j88/TjXlBh6SySI/AAAAAAAAAN0/O_G2Z8YdMk8/s320/blockquote.white.png) #f0f0f0 no-repeat 4px top;
   color: #474747;
   border-top: #ddd 1px dotted;
   border-right: #ddd 1px dotted;
   padding-top: 0.6em
}
&lt;/style&gt;&lt;!--The Coding Buzz--&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;In the episode of Seinfeld titled "The Frogger" Jerry and George discover a long lost Frogger machine that still has the G.L.C. George Louis Costanza high score of 860,000 of which George reminisces: "I remember that night. The perfect combination of Mountain Dew and mozzarella...just the right amount of grease on the joy stick..."&lt;/p&gt;&lt;p&gt;This essentially sums up what I call the coding buzz, for me it's the perfect combination of a good problem, private time to work on it, and just the right combination of caffeine and music.  The coding buzz is what I live for, those narcotic moments of creative bliss when all other distractions and even personal problems melt away into the background and your mind and fingers become one with your editor begetting a symphony of code creation.  It's a wonderful thing.&lt;/p&gt;&lt;p&gt;To really achieve the coding buzz one needs to have a level proficiency generally denoted with the quantity 10,000 hours, meaning that you need at least 10,000 hours of practice.  It turns out that the coding buzz is what is called "flow".  This is from &lt;a href="http://www.newscientist.com/article/mg21328501.600-zap-your-brain-into-the-zone-fast-track-to-pure-focus.html"&gt;an article on New Scientist&lt;/a&gt;:&lt;/p&gt;&lt;blockquote class="quote"&gt;&lt;p&gt;The first is an intense and focused absorption that makes you lose all sense of time. The second is what is known as autotelicity, the sense that the activity you are engaged in is rewarding for its own sake. The third is finding the "sweet spot", a feeling that your skills are perfectly matched to the task at hand, leaving you neither frustrated nor bored. And finally, flow is characterised by automaticity, the sense that "the piano is playing itself", for example.&lt;/p&gt;&lt;p&gt;...&lt;/p&gt;&lt;p&gt;Flow typically accompanies these actions. It involves a Zen-like feeling of intense concentration, with time seeming to stop as you focus completely on the activity in hand. The experience crops up repeatedly when experts describe what it feels like to be at the top of their game, and with years of practice it becomes second nature to enter that state.&lt;/p&gt;&lt;p&gt;...&lt;/p&gt;&lt;p&gt;Exactly what happens in the brain during flow has been of particular interest, but it has been tricky to measure. Csikszentmihalyi took an early stab at it, using electroencephalography (EEG) to measure the brain waves of expert chess players during a game. He found that the most skilled players showed less activity in the prefrontal cortex, which is typically associated with higher cognitive processes such as working memory and verbalisation. That may seem counter-intuitive, but silencing self-critical thoughts might allow more automatic processes to take hold, which would in turn produce that effortless feeling of flow.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;This is why after over two decades I still mostly like to work as a developer, admittedly not all of my career has consisted of  those moments, but the times I found myself immersed in those types of projects both personal and professional has well been worth it.  I frequently feel that I should have grown up at some point and tried to pursue the management track or a more formal architect position and I have contemporary colleagues that are VPs and CTOs, etc.  However, every time I think  about such a career path I realize how much I would dislike it and I would then have to let go of being hands on, I know there are probably cases of those types of positions where that is not the case, but you would have to find the right environment.&lt;/p&gt;&lt;p&gt;I have recently found myself in a &lt;a href="http://en.wikipedia.org/wiki/Pair_programming"&gt;pair programming&lt;/a&gt; environment and while there are some aspects of it that are ok, but I often find myself sneaking away to do the creative experimental work on my own.  As an introvert I sometimes find it hard to pair.  One problem is that there is a substantial skill differential between my teammates and me in that I am considerably more senior so that's a problem, thus I am not sure if my issues with pairing are truly accurate. Still when I need to build some complex functionality or refactor code that requires you to hold dozens of classes in your head, tasks that require intense concentration and that both require you to and reward you for being in the zone aka achieve flow, I just have trouble seeing doing this effectively with the added pressure of someone looking over your shoulder.  I have spoken with developers who like pairing and perhaps it's an introvert/extrovert preference.&lt;/p&gt;&lt;p&gt;When I originally came up with the idea for this post I just wanted to talk about the euphoric bliss of the coding buzz but now I find myself in a situation that seems to be harshing that coding buzz, to put it in the parlance of our times.  Coincidently I am writing this at time when the "group" approach seems to be coming under fire, most notably in an article in the New York Times entitled "&lt;a href="http://www.nytimes.com/2012/01/15/opinion/sunday/the-rise-of-the-new-groupthink.html"&gt;The Rise of the New Groupthink"&lt;/a&gt; by Susan Cain which includes the following:&lt;/p&gt;&lt;blockquote class="quote"&gt;&lt;p&gt;The reasons brainstorming fails are instructive for other forms of group work, too. People in groups tend to sit back and let others do the work; they instinctively mimic others' opinions and lose sight of their own; and, often succumb to peer pressure. The Emory University neuroscientist Gregory Berns found that when we take a stance different from the group's, we activate the amygdala, a small organ in the brain associated with the fear of rejection. Professor Berns calls this "the pain of independence."&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;She also includes the following excellent quote from Steve Wozniak:&lt;/p&gt;&lt;blockquote class="quote"&gt;&lt;p&gt;Most inventors and engineers I've met are like me ... they live in their heads. They're almost like artists. In fact, the very best of them are artists. And artists work best alone .... I'm going to give you some advice that might be hard to take. That advice is: Work alone... Not on a committee. Not on a team.&lt;br /&gt;
&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;She also has an interesting &lt;a href="http://www.ted.com/talks/lang/en/susan_cain_the_power_of_introverts.html"&gt;TED talk&lt;/a&gt;.  As an introvert I feel that both Woz's and her sentiments resonate with me, and I really know what it's like to live in my head, I can't imagine doing good creative work any other way.&lt;/p&gt;&lt;p&gt;As I said the groupthink backlash and pair programming skepticism seems to be something of a hot topic at the moment, see this &lt;a href="http://www.infoq.com/news/2012/03/agile_stifiling_introverts"&gt;compendium post on InfoQ&lt;/a&gt; which includes some these and other links.  Obviously communication is essential in a multi-person software project but is pair programming over doing it?  It just feels like a coding buzz kill to me.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&amp;nbsp;&lt;p&gt;&lt;p&gt;&amp;nbsp;&lt;p&gt;&lt;p&gt;&amp;nbsp;&lt;p&gt;&lt;p&gt;&amp;nbsp;&lt;p&gt;&lt;p&gt;The following two talks are some additional interesting and relevant neuroscience related resources:&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.youtube.com/watch?v=uPBapVkZJww&amp;feature=plcp&amp;context=C46fc796VDvjVQa1PpcFOKi--7u6RbCU1wl02kytFbc7KYeMQhDEE%3D"&gt;Authors@Google: Sandra Aamodt &amp; Sam Wang&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.youtube.com/watch?v=XeJSXfXep4M"&gt;Your Brain at Work by David Rock.&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/wi0Q4BILEe4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/wi0Q4BILEe4/coding-buzz.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-fe0RVK0ynmQ/T3i-BBa2JlI/AAAAAAAAAgk/9B61aneV_AQ/s72-c/533207main_iss027e006501_full.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/04/coding-buzz.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-8525151354191190000</guid><pubDate>Thu, 29 Mar 2012 01:49:00 +0000</pubDate><atom:updated>2012-05-28T21:12:18.474-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Math</category><category domain="http://www.blogger.com/atom/ns#">Complex numbers</category><category domain="http://www.blogger.com/atom/ns#">Abstract Algebra</category><category domain="http://www.blogger.com/atom/ns#">Group Theory</category><title>Amazing Abstract Algebra: Groups and Rotations</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-_Q3GAMaMIUE/T3O2gxLA4EI/AAAAAAAAAfQ/0cag7eZ6e4w/s1600/IMG_7160.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="300" width="400" src="http://1.bp.blogspot.com/-_Q3GAMaMIUE/T3O2gxLA4EI/AAAAAAAAAfQ/0cag7eZ6e4w/s400/IMG_7160.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;style&gt;
    td.z0 {
        padding:15px;
        font-size: 16px;
        text-align : center;
        background-color: #ffffff;
        color:black;
        border : 1px solid black;
    }

    td.z1 {
        padding:15px;
        font-size: 16px;
        text-align : center;
        vertical-align : center;
        background-color: #ffff00;
        color:black;
        border : 1px solid black;
    }

    td.z2 {
        padding:15px;
        font-size: 16px;
        text-align : center;
        vertical-align : center;
        background-color: #66ff33;
        color:black;
        border : 1px solid black;
    }

    td.z3 {
        padding:15px;
        font-size: 16px;
        text-align : center;
        vertical-align : center;
        background-color: #669933;
        color:black;
        border : 1px solid black;
    }

    td.v {
        padding:15px;
        font-size: 16px;
        text-align : center;
        vertical-align : center;
        background-color: #00ffff;
        color:black;
        border : 1px solid black;
    }

    td.h {
        padding:15px;
        font-size: 16px;
        text-align : center;
        vertical-align : center;
        background-color: #ff66cc;
        color:black;
        border : 1px solid black;
    }

    td.d1 {
        padding:15px;
        font-size: 16px;
        text-align : center;
        vertical-align : center;
        background-color: #9966ff;
        color:black;
        border : 1px solid black;
    }

    td.d2 {
        padding:15px;
        font-size: 16px;
        text-align : center;
        vertical-align : center;
        background-color: #0000ff;
        color:black;
        border : 1px solid black;
    }

    div.source-code {
        color             : #000;
        background-color  : #eee;
        border            : 1px dashed #999999;
        line-height       : 14px;
        padding           : 5px;
        overflow          : auto;
        width             : 100%;
        text-indent       : 0px;
        margin-top        : 8px;
        margin-bottom     : 8px;
    }
&lt;/style&gt;&lt;br /&gt;
&lt;p&gt;A little while ago I noticed a very interesting group, I am sure it is well known in math circles but I find it intriguing for a number of reasons and I have recently learned more about &lt;a href="http://en.wikipedia.org/wiki/Abstract_algebra"&gt;Abstract Algebra&lt;/a&gt; which ties in some more interesting ideas.  The group relates to &lt;a href="http://en.wikipedia.org/wiki/Imaginary_number"&gt;imaginary numbers&lt;/a&gt;, it is the set {1,-1,i,-i} which is closed under multiplication.  It has an identity which is 1.  Each element has an inverse, -1 is its own inverse: -1 &amp;middot; -1 = 1 and -i &amp;middot; i  = 1.  The following &lt;a href="http://en.wikipedia.org/wiki/Cayley_table"&gt;cayley table&lt;/a&gt; shows all this:&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="0"  style="text-align:center;"&gt;&lt;tr&gt;     &lt;td class="z0"&gt;&amp;bull;&lt;/td&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt;     &lt;td class="z0"&gt; i&lt;/td&gt;     &lt;td class="z0"&gt;-1&lt;/td&gt;     &lt;td class="z0"&gt;-i&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt;     &lt;td class="z1"&gt; i&lt;/td&gt;     &lt;td class="z2"&gt;-1&lt;/td&gt;     &lt;td class="z3"&gt;-i&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="z0"&gt; i&lt;/td&gt;     &lt;td class="z1"&gt; i&lt;/td&gt;     &lt;td class="z2"&gt;-1&lt;/td&gt;     &lt;td class="z3"&gt;-i&lt;/td&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="z0"&gt;-1&lt;/td&gt;     &lt;td class="z2"&gt;-1&lt;/td&gt;     &lt;td class="z3"&gt;-i&lt;/td&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt;     &lt;td class="z1"&gt; i&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="z0"&gt;-i&lt;/td&gt;     &lt;td class="z3"&gt;-i&lt;/td&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt;     &lt;td class="z1"&gt; i&lt;/td&gt;     &lt;td class="z2"&gt;-1&lt;/td&gt; &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;p&gt;If you are new to these ideas I recommend looking at my &lt;a href="http://www.elegantcoding.com/2012/01/abstract-algebra-logic-of-odd-and-even.html"&gt;previous post&lt;/a&gt; on abstract algebra, especially since we will be looking at some &lt;a href="http://en.wikipedia.org/wiki/Isomorphism"&gt;isomorphisms&lt;/a&gt; again.  In order to talk about the ideas in the post we need to get some group theory concepts out of the way first, don't worry they aren't hard in fact they're fairly intuitive.  Also in this post I am restricting the discussion to finite groups, groups with a finite number of elements.  In fact the first idea is the concept of group order.&lt;br /&gt;
&lt;/p&gt;&lt;div class="source-code"&gt;&lt;p&gt;The order of a finite group is simply the number of elements of the set the group is defined on and is denoted as |G|.&lt;br /&gt;
&lt;/p&gt;&lt;/div&gt;&lt;p&gt;The group above has an order of 4.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;The next idea is that of exponentiation, which can be thought of as a subset of "classical" exponentiation on the field of real numbers, see identities &lt;a href="http://www.elegantcoding.com/2011/10/ologn.html"&gt;here&lt;/a&gt;.  Exponentiation on group elements extends to integer exponents only and refers to repeated application of the binary operation to the element itself. So:&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;a&lt;sup&gt;n&lt;/sup&gt; = a&amp;middot;a&amp;middot;a&amp;middot;a...a ( a "times" itself n times)&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;a&lt;sup&gt;-n&lt;/sup&gt; = a&lt;sup&gt;-1&lt;/sup&gt;&amp;middot;a&lt;sup&gt;-1&lt;/sup&gt;&amp;middot;a&lt;sup&gt;-1&lt;/sup&gt;&amp;middot;a&lt;sup&gt;-1&lt;/sup&gt;...a&lt;sup&gt;-1&lt;/sup&gt;  (a&lt;sup&gt;-1&lt;/sup&gt; "times" itself n times or the inverse of a&lt;sup&gt;n&lt;/sup&gt;)&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;a&lt;sup&gt;0&lt;/sup&gt; = e (where e is the identity element)&lt;br /&gt;
&lt;/p&gt;&lt;/div&gt;&lt;p&gt;The laws of exponents are:&lt;br /&gt;
&lt;/p&gt;&lt;div class="source-code"&gt;&lt;p&gt;a&lt;sup&gt;m&lt;/sup&gt; a&lt;sup&gt;n&lt;/sup&gt; = a&lt;sup&gt;m+n&lt;/sup&gt;&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;(a&lt;sup&gt;m&lt;/sup&gt;)&lt;sup&gt;n&lt;/sup&gt; = a&lt;sup&gt;mn&lt;/sup&gt;&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;a&lt;sup&gt;-n&lt;/sup&gt; = (a&lt;sup&gt;-1&lt;/sup&gt;)&lt;sup&gt;n&lt;/sup&gt; = (a&lt;sup&gt;n&lt;/sup&gt;)&lt;sup&gt;-1&lt;/sup&gt;&lt;br /&gt;
&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Just as a group has an order an element of a group also has an order and it is related to exponentiation and it is defined as:&lt;br /&gt;
&lt;/p&gt;&lt;div class="source-code"&gt;&lt;p&gt;If there exists a nonzero integer m such that a&lt;sup&gt;m&lt;/sup&gt;=e, then the order of the element is defined to be the least positive integer n such that a&lt;sup&gt;n&lt;/sup&gt;=e.  Also if there does not exist any nonzero integer m such that a&lt;sup&gt;m&lt;/sup&gt;=e, we say that a has order infinity.&lt;br /&gt;
&lt;/p&gt;&lt;/div&gt;&lt;p&gt;So the elements in our group (&amp;sdot;, {1,-1,i,-i}) above have the following orders:&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;1&lt;sup&gt;1&lt;/sup&gt; = 1 (this is the identity and has order 1) [1&lt;sup&gt;1&lt;/sup&gt; = 1, ...]&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;-1&lt;sup&gt;2&lt;/sup&gt; = 1 (has order 2)  [-1&lt;sup&gt;1&lt;/sup&gt; = -1, -1&lt;sup&gt;2&lt;/sup&gt; = 1, ...]&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;i&lt;sup&gt;4&lt;/sup&gt; = 1 (has order 4) [i&lt;sup&gt;1&lt;/sup&gt; = i, i&lt;sup&gt;2&lt;/sup&gt; = -1, i&lt;sup&gt;3&lt;/sup&gt; = -i, i&lt;sup&gt;4&lt;/sup&gt; = 1, ...]&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;-i&lt;sup&gt;4&lt;/sup&gt; = 1 (has order 4) [-i&lt;sup&gt;1&lt;/sup&gt; = -i, -i&lt;sup&gt;2&lt;/sup&gt; = -1, -i&lt;sup&gt;3&lt;/sup&gt; = i, -i&lt;sup&gt;4&lt;/sup&gt; = 1, ...]&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;Order is also sometimes referred to as period and you should note that each of the above will cycle through each power listed in the square brackets so for both the order 4 elements {i, -i}:  a&lt;sup&gt;1n&lt;/sup&gt;=a&lt;sup&gt;1&lt;/sup&gt;, a&lt;sup&gt;2n&lt;/sup&gt;=a&lt;sup&gt;2&lt;/sup&gt;, a&lt;sup&gt;3n&lt;/sup&gt;=a&lt;sup&gt;3&lt;/sup&gt;, a&lt;sup&gt;4n&lt;/sup&gt;=a&lt;sup&gt;4&lt;/sup&gt; for all integers n&amp;gt;0 and the values will cycle through the list which would be the case for any element of finite order.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;As it turns out elements like i and -i which cycle through all of the elements of a group exactly once in the period have an order that is equal to the order of the group. These define what is known as a cyclic group. So our group is cyclic and any element which cycles through all elements once is the generator so i and -i are generators for the group.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;Another interesting result from group theory is that &lt;b&gt;any cyclic group of order n is isomorphic to the group (+,Z&lt;sub&gt;n&lt;/sub&gt;)&lt;/b&gt; which is the integers (mod n) under addition so our group above is just a renaming of Z&lt;sub&gt;4&lt;/sub&gt; see the similarity to the cayley table below:&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="0"  style="text-align:center;"&gt;&lt;tr&gt;     &lt;td class="z0"&gt;+&lt;/td&gt;     &lt;td class="z0"&gt;0&lt;/td&gt;     &lt;td class="z0"&gt;1&lt;/td&gt;     &lt;td class="z0"&gt;2&lt;/td&gt;     &lt;td class="z0"&gt;3&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="z0"&gt;0&lt;/td&gt;     &lt;td class="z0"&gt;0&lt;/td&gt;     &lt;td class="z1"&gt;1&lt;/td&gt;     &lt;td class="z2"&gt;2&lt;/td&gt;     &lt;td class="z3"&gt;3&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="z0"&gt;1&lt;/td&gt;     &lt;td class="z1"&gt;1&lt;/td&gt;     &lt;td class="z2"&gt;2&lt;/td&gt;     &lt;td class="z3"&gt;3&lt;/td&gt;     &lt;td class="z0"&gt;0&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="z0"&gt;2&lt;/td&gt;     &lt;td class="z2"&gt;2&lt;/td&gt;     &lt;td class="z3"&gt;3&lt;/td&gt;     &lt;td class="z0"&gt;0&lt;/td&gt;     &lt;td class="z1"&gt;1&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="z0"&gt;3&lt;/td&gt;     &lt;td class="z3"&gt;3&lt;/td&gt;     &lt;td class="z0"&gt;0&lt;/td&gt;     &lt;td class="z1"&gt;1&lt;/td&gt;     &lt;td class="z2"&gt;2&lt;/td&gt; &lt;/tr&gt;
&lt;/table&gt;&lt;p&gt;Now I want to take a look at another important group, it's called the &lt;a href="http://en.wikipedia.org/wiki/Dihedral_group"&gt;dihedral group&lt;/a&gt;, this one is known as D&lt;sub&gt;4&lt;/sub&gt; and has the cayley table:&lt;br /&gt;
&lt;/p&gt;&lt;table border="1" cellpadding="2" cellspacing="0"  style="text-align:center;"&gt;&lt;tr&gt;
    &lt;td class="z0"&gt;&amp;nbsp;&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;0&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;3&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z0"&gt;V&lt;/td&gt;
    &lt;td class="z0"&gt;H&lt;/td&gt;
    &lt;td class="z0"&gt;D&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z0"&gt;D&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;0&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;0&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z1"&gt;R&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z2"&gt;R&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z3"&gt;R&lt;sub&gt;3&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="v"&gt;V&lt;/td&gt;
    &lt;td class="h"&gt;H&lt;/td&gt;
    &lt;td class="d1"&gt;D&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="d2"&gt;D&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;1&lt;sub&gt;&lt;/td&gt;
    &lt;td class="z1"&gt;R&lt;sub&gt;1&lt;sub&gt;&lt;/td&gt;
    &lt;td class="z2"&gt;R&lt;sub&gt;2&lt;sub&gt;&lt;/td&gt;
    &lt;td class="z3"&gt;R&lt;sub&gt;3&lt;sub&gt;&lt;/td&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;0&lt;sub&gt;&lt;/td&gt;
    &lt;td class="d1"&gt;D&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="d2"&gt;D&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="h"&gt;H&lt;/td&gt;
    &lt;td class="v"&gt;V&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;2&lt;sub&gt;&lt;/td&gt;
    &lt;td class="z2"&gt;R&lt;sub&gt;2&lt;sub&gt;&lt;/td&gt;
    &lt;td class="z3"&gt;R&lt;sub&gt;3&lt;sub&gt;&lt;/td&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;0&lt;sub&gt;&lt;/td&gt;
    &lt;td class="z1"&gt;R&lt;sub&gt;1&lt;sub&gt;&lt;/td&gt;
    &lt;td class="h"&gt;H&lt;/td&gt;
    &lt;td class="v"&gt;V&lt;/td&gt;
    &lt;td class="d2"&gt;D&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="d1"&gt;D&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;3&lt;sub&gt;&lt;/td&gt;
    &lt;td class="z3"&gt;R&lt;sub&gt;3&lt;sub&gt;&lt;/td&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;0&lt;sub&gt;&lt;/td&gt;
    &lt;td class="z1"&gt;R&lt;sub&gt;1&lt;sub&gt;&lt;/td&gt;
    &lt;td class="z2"&gt;R&lt;sub&gt;2&lt;sub&gt;&lt;/td&gt;
    &lt;td class="d2"&gt;D&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="d1"&gt;D&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="v"&gt;V&lt;/td&gt;
    &lt;td class="h"&gt;H&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td class="z0"&gt;V&lt;/td&gt;
    &lt;td class="v"&gt;V&lt;/td&gt;
    &lt;td class="d2"&gt;D&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="h"&gt;H&lt;/td&gt;
    &lt;td class="d1"&gt;D&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;0&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z2"&gt;R&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z3"&gt;R&lt;sub&gt;3&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z1"&gt;R&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td class="z0"&gt;H&lt;/td&gt;
    &lt;td class="h"&gt;H&lt;/td&gt;
    &lt;td class="d1"&gt;D&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="v"&gt;V&lt;/td&gt;
    &lt;td class="d2"&gt;D&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z2"&gt;R&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;0&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z1"&gt;R&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z3"&gt;R&lt;sub&gt;3&lt;/sub&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td class="z0"&gt;D&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="d1"&gt;D&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="v"&gt;V&lt;/td&gt;
    &lt;td class="d2"&gt;D&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="h"&gt;H&lt;/td&gt;
    &lt;td class="z1"&gt;R&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z3"&gt;R&lt;sub&gt;3&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;0&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z2"&gt;R&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td class="z0"&gt;D&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="d2"&gt;D&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="h"&gt;H&lt;/td&gt;
    &lt;td class="d1"&gt;D&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="v"&gt;V&lt;/td&gt;
    &lt;td class="z3"&gt;R&lt;sub&gt;3&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z1"&gt;R&lt;sub&gt;1&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z2"&gt;R&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt;
    &lt;td class="z0"&gt;R&lt;sub&gt;0&lt;/sub&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;p&gt;The dihedral group is the group of symmetries of a regular polygon, including both rotations and reflections.  In this case we will consider the rotations and reflections of a square denoted as D&lt;sub&gt;4&lt;/sub&gt; represented visually as four couterclockwise rotations of a square:&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-DGXCZ5F0Y_I/T3O2uMywCRI/AAAAAAAAAfc/vUqqE1e-7uE/s1600/dihedral.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="376" src="http://2.bp.blogspot.com/-DGXCZ5F0Y_I/T3O2uMywCRI/AAAAAAAAAfc/vUqqE1e-7uE/s400/dihedral.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;And the following four reflections, vertical, horizontal, and two diagonal reflections:&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-LnL-QTjx6Ck/T3O2zbyrllI/AAAAAAAAAfo/M55WehpOjVQ/s1600/dihedral2.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="376" src="http://2.bp.blogspot.com/-LnL-QTjx6Ck/T3O2zbyrllI/AAAAAAAAAfo/M55WehpOjVQ/s400/dihedral2.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;With each image is included the permutation, actually dihedral groups are permutation groups and D&lt;sub&gt;4&lt;/sub&gt; is a set of 8 permutations, hence the order of the group is 8. It is a subgroup of the group of all &lt;a href="http://www.elegantcoding.com/2011/05/combinatorial-and-other-math-of-java.html"&gt;permutations&lt;/a&gt; of four items which is known as the &lt;a href="http://en.wikipedia.org/wiki/Symmetric_group"&gt;Symmetric Group&lt;/a&gt; which has order 4!=24, it's denoted as S&lt;sub&gt;4&lt;/sub&gt;.  The interesting thing here is the rotations form a subgroup that is isomorphic to our group from above and Z&lt;sub&gt;4&lt;/sub&gt;.  In a sense this isn't really surprising since it is a cyclic group of order four meaning it cycles through 4 items just as a square cycles through four rotations.&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;As you can see from the color coding, the elements {R&lt;sub&gt;0&lt;/sub&gt;, R&lt;sub&gt;1&lt;/sub&gt;, R&lt;sub&gt;2&lt;/sub&gt;, R&lt;sub&gt;3&lt;/sub&gt;} form a subgroup, a subgroup is just a subset of the elements that is still a group.  These subgroup elements forming the upper left hand corer of the table are color coded to show the isomorphism between this subgroup and Z&lt;sub&gt;4&lt;/sub&gt; and also our group (&amp;sdot;, {1,-1,i,-i}). Also R&lt;sub&gt;0&lt;/sub&gt;  is the identity which makes sense since it is a zero rotation, which means that you didn't rotate it, or you did by 360&amp;deg; aka one &lt;a href="http://tauday.com/"&gt;tau&lt;/a&gt;.&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Our Z&lt;sub&gt;4&lt;/sub&gt; isomorphic group (&amp;sdot;, {1,-1,i,-i}) also has a subgroup. Our original arrangement of the cayley table was ordered to show the Z&lt;sub&gt;4&lt;/sub&gt; isomorphism. To show our subgroup we need to rearrange the cayley table:&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="0"  style="text-align:center;"&gt;&lt;tr&gt;     &lt;td class="z0"&gt;&amp;bull;&lt;/td&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt;     &lt;td class="z0"&gt;-1&lt;/td&gt;     &lt;td class="z0"&gt; i&lt;/td&gt;     &lt;td class="z0"&gt;-i&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt;     &lt;td class="z2"&gt;-1&lt;/td&gt;     &lt;td class="z1"&gt; i&lt;/td&gt;     &lt;td class="z3"&gt;-i&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="z0"&gt;-1&lt;/td&gt;     &lt;td class="z2"&gt;-1&lt;/td&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt;     &lt;td class="z3"&gt;-i&lt;/td&gt;     &lt;td class="z1"&gt; i&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="z0"&gt; i&lt;/td&gt;     &lt;td class="z1"&gt; i&lt;/td&gt;     &lt;td class="z3"&gt;-i&lt;/td&gt;     &lt;td class="z2"&gt;-1&lt;/td&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="z0"&gt;-i&lt;/td&gt;     &lt;td class="z3"&gt;-i&lt;/td&gt;     &lt;td class="z1"&gt; i&lt;/td&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt;     &lt;td class="z2"&gt;-1&lt;/td&gt; &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;p&gt;Now it should be fairly easy to the subgroup (&amp;sdot;, {1,-1}) again forming the upper left corner in the table above, or shown by itself:&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="0"  style="text-align:center;"&gt;&lt;tr&gt;     &lt;td class="z0"&gt;&amp;bull;&lt;/td&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt;     &lt;td class="z0"&gt;-1&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt;     &lt;td class="z2"&gt;-1&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="z0"&gt;-1&lt;/td&gt;     &lt;td class="z2"&gt;-1&lt;/td&gt;     &lt;td class="z0"&gt; 1&lt;/td&gt; &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;p&gt;Now if you think about it our subgroup which is just another group is a group, 1 is the identity and -1 is its own inverse, actually it turns out that &lt;b&gt;all subgroups of cyclic groups are also cyclic groups&lt;/b&gt; and since all cyclic groups are isomorphic to Z&lt;sub&gt;n&lt;/sub&gt; groups, this group is actually one that we have &lt;a href="http://www.elegantcoding.com/2012/01/abstract-algebra-logic-of-odd-and-even.html"&gt;seen before&lt;/a&gt; it's just Z&lt;sub&gt;2&lt;/sub&gt; addition aka exclusive-or, etc.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;Also there are some remarkable connections to number theory in regards to the order of subgroups and the order of elements, for example the order of our subgroup is 2 which evenly divides 4 the order of the group, &lt;b&gt;the order of a subgroup will always evenly divide the order of the group&lt;/b&gt;. Also &lt;b&gt;the order of each element evenly divides the order of the group&lt;/b&gt;.  I suspect that these ideas have profound implications.&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Going back to our original group there are a couple of interesting things about imaginary numbers, first are the following equations:&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-5whHLifSmoU/T3O3CW4auVI/AAAAAAAAAf0/3wbGZb-g0YA/s1600/i-inverse.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="16" width="64" src="http://1.bp.blogspot.com/-5whHLifSmoU/T3O3CW4auVI/AAAAAAAAAf0/3wbGZb-g0YA/s400/i-inverse.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-HQDF9iEzIkQ/T3O3HyVWmnI/AAAAAAAAAgA/wPHd8kope0w/s1600/i-div-i.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="35" width="37" src="http://3.bp.blogspot.com/-HQDF9iEzIkQ/T3O3HyVWmnI/AAAAAAAAAgA/wPHd8kope0w/s400/i-div-i.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;If we consider the sequence of raising i to successive powers, multiplying by I each time, if we start with 1, we get the sequence (1, i, -1, -i), these are actually coordinates in the complex plane and can be written as (0i+1, 1i+0, 0i-1, -1i+0). This cycle (increasing powers of i) is the following (counter clockwise) rotation in the complex plane:&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-ct0yL-Syonw/T3O3NuosVlI/AAAAAAAAAgM/M-8D5syCITQ/s1600/complex-plane%252B1.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="400" src="http://4.bp.blogspot.com/-ct0yL-Syonw/T3O3NuosVlI/AAAAAAAAAgM/M-8D5syCITQ/s400/complex-plane%252B1.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Conversely if we divide, or repeatedly multiply by  -i, we get the following sequence (1,-i,-1,i) which correspond to the complex numbers (0i+1, -1i+0, 0i-1, 1i+0) and is the opposite (clockwise) rotation:&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-gmpn6o_UY40/T3O3THlWxNI/AAAAAAAAAgY/RNO1DI8WtIY/s1600/complex-plane-1.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="400" src="http://4.bp.blogspot.com/-gmpn6o_UY40/T3O3THlWxNI/AAAAAAAAAgY/RNO1DI8WtIY/s400/complex-plane-1.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Another interesting seemingly related concept is the idea of turning number or &lt;a href=" http://en.wikipedia.org/wiki/Winding_number"&gt;winding number&lt;/a&gt; of a curve, the red circle with clockwise rotation corresponds to curve with a winding number of -1 and the blue curve with positive increasing powers of i has a winding number of 1.&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;As we saw our group is cyclic and isomorphic to Z&lt;sub&gt;4&lt;/sub&gt; and isomorphic to the rotation subgroup of the dihedral group D&lt;sub&gt;4&lt;/sub&gt; and both of the generators of our group correspond to rotation in the complex plane. Counterclockwise rotation corresponds to the period of i and clockwise rotation corresponds to the period of -i.&lt;br /&gt;
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/RuTm0_HirUk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/RuTm0_HirUk/interesting-group.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-_Q3GAMaMIUE/T3O2gxLA4EI/AAAAAAAAAfQ/0cag7eZ6e4w/s72-c/IMG_7160.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/03/interesting-group.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-7096643175336703846</guid><pubDate>Sun, 25 Mar 2012 17:08:00 +0000</pubDate><atom:updated>2012-05-13T15:08:20.931-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Morphology</category><category domain="http://www.blogger.com/atom/ns#">Naming</category><category domain="http://www.blogger.com/atom/ns#">Software Engineering</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><category domain="http://www.blogger.com/atom/ns#">Linguistics</category><title>More Thoughts on Formal Approaches to Naming in Software</title><description>&lt;h2&gt;On the Importance of Naming in Software Systems, Part II&lt;/h2&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-4uF4DFKqu3U/T29K3M7GjCI/AAAAAAAAAfE/ONxHweH_BdM/s1600/Io_Full.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="400" src="http://4.bp.blogspot.com/-4uF4DFKqu3U/T29K3M7GjCI/AAAAAAAAAfE/ONxHweH_BdM/s400/Io_Full.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;style&gt;
blockquote.quote {
   border-bottom: #ddd 1px dotted;
   border-left: #ddd 1px dotted;
   padding-bottom: 0.6em;
   font-style: italic;
   font-family: calibri, tahoma, arial, sans-serif;
   margin: 1em 10% 1em 0px;
   min-height: 40px;
   padding-left: 3.8em;
   padding-right: 1em;
   background: url(http://4.bp.blogspot.com/-WkhuNlv2j88/TjXlBh6SySI/AAAAAAAAAN0/O_G2Z8YdMk8/s320/blockquote.white.png) #f0f0f0 no-repeat 4px top;
   color: #474747;
   border-top: #ddd 1px dotted;
   border-right: #ddd 1px dotted;
   padding-top: 0.6em
}

blockquote.paraphrase {
   border-bottom: #ddd 1px dotted;
   border-left: #ddd 1px dotted;
   padding-bottom: 0.6em;
   font-style: italic;
   font-family: calibri, tahoma, arial, sans-serif;
   margin: 1em 10% 1em 0px;
   min-height: 40px;
   padding-left: 3.8em;
   padding-right: 1em;
   background: #f0f0f0 no-repeat 4px top;
   color: #474747;
   border-top: #ddd 1px dotted;
   border-right: #ddd 1px dotted;
   padding-top: 0.6em
}


div.source-code1 {
    font-family       : Andale Mono, Lucida Console, Monaco, fixed, monospace;
    color             : #000;
    background-color  : #eee;
    font-size         : 12px;
    border            : 1px dashed #999999;
    line-height       : 10px;
    padding           : 5px;
    overflow          : auto;
    width             : 100%;
    text-indent       : 0px;
}

div.source-code {
    font-family       : Andale Mono, Lucida Console, Monaco, fixed, monospace;
    color             : #000;
    background-color  : #eee;
    font-size         : 12px;
    border            : 1px dashed #999999;
    line-height       : 14px;
    padding           : 5px;
    overflow          : auto;
    width             : 100%;
    text-indent       : 0px;
    margin-top        : 8px;
    margin-bottom     : 8px;
}

p.codeline {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    color:black;
}

p.codeline1 {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    text-indent:.5in;
    color:black;
}

p.codeline2 {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    text-indent:1in;
    color:black;
}

p.codeline3 {

    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    text-indent:1.5in;
    color:black;
}

&lt;/style&gt;&lt;!--More Thoughts on Formal Approaches to Naming in Software--&gt;&lt;br /&gt;
&lt;p&gt;In my &lt;a href="http://www.elegantcoding.com/2012/03/survey-of-conventional-wisdom-on.html"&gt;last post on naming&lt;/a&gt; I surveyed and attempted to categorize the conventional wisdom in regards to naming. Here I will expand on some of my ideas and extend my naming domain vocabulary.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;A software system is composed of many things and most of them if not all have names.  In order to talk about this I realized that I need a term to describe the things that have names, Steve McConnell makes the comment "a variable and a variable’s name are essentially the same thing".  While this is effectively true, &lt;i&gt;named things&lt;/i&gt; in a system have different types, uses, etc.  In trying to come up with a name for these &lt;i&gt;named things&lt;/i&gt;, I felt that I could do better than the phrase "named things". For the word "things" I contemplated item, object, entity, artifact, and more. These all had various connotations and possible contexts which confused the meaning. I turned to linguistics for the answer, and found the following on Wikipedia under &lt;a href="http://en.wikipedia.org/wiki/Intension"&gt;intension&lt;/a&gt;, the bolding is mine:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;&lt;i&gt;The meaning of a word can be thought of as the bond between the idea or thing the word refers to and the word itself. Swiss linguist &lt;/i&gt;&lt;a href="http://en.wikipedia.org/wiki/Ferdinand_de_Saussure" title="Ferdinand de Saussure"&gt;&lt;i&gt;Ferdinand de Saussure&lt;/i&gt;&lt;/a&gt;&lt;i&gt; contrasts three concepts:&lt;/i&gt;&lt;/p&gt;&lt;br /&gt;
&lt;ul type=disc&gt;&lt;li&gt;&lt;b&gt;&lt;i&gt;the signifier&lt;/i&gt;&lt;/b&gt;&lt;i&gt; — the &amp;quot;sound image&amp;quot; or string of &lt;/i&gt;&lt;a href="http://en.wikipedia.org/wiki/Letter_%28alphabet%29"      title="Letter (alphabet)"&gt;&lt;i&gt;letters&lt;/i&gt;&lt;/a&gt;&lt;i&gt; on a page that one recognizes as a &lt;/i&gt;&lt;a href="http://en.wikipedia.org/wiki/Sign_%28linguistics%29" title="Sign (linguistics)"&gt;&lt;i&gt;sign&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;the signified&lt;/i&gt;&lt;/b&gt;&lt;i&gt; — the &lt;/i&gt;&lt;a href="http://en.wikipedia.org/wiki/Concept"      title=Concept&gt;&lt;i&gt;concept&lt;/i&gt;&lt;/a&gt;&lt;i&gt; or &lt;/i&gt;&lt;a href="http://en.wikipedia.org/wiki/Idea" title=Idea&gt;&lt;i&gt;idea&lt;/i&gt;&lt;/a&gt;&lt;i&gt; that a sign evokes.&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;the referent&lt;/i&gt;&lt;/b&gt;&lt;i&gt; — the actual &lt;/i&gt;&lt;a href="http://en.wikipedia.org/wiki/Object_%28philosophy%29" title="Object (philosophy)"&gt;&lt;i&gt;thing&lt;/i&gt;&lt;/a&gt;&lt;i&gt; or set of things a sign refers to. See &lt;/i&gt;&lt;a href="http://en.wikipedia.org/wiki/Sign_%28semiotics%29#Dyadic_signs" title="Sign (semiotics)"&gt;Dyadic signs&lt;/a&gt;&lt;i&gt; and &lt;/i&gt;&lt;a href="http://en.wikipedia.org/wiki/Reference#Semantics" title=Reference&gt;Reference (semantics)&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;So the word &lt;b&gt;&lt;i&gt;referent&lt;/i&gt;&lt;/b&gt; seems to be a good choice as it probably has no context with relation to software engineering.  To take this further, I will use the expression &lt;b&gt;&lt;i&gt;Named System Referent&lt;/i&gt;&lt;/b&gt;&lt;i&gt; &lt;/i&gt;or possibly just &lt;b&gt;&lt;i&gt;System Referent&lt;/i&gt;&lt;/b&gt; to refer to those things in a software system that have a name.  To be clear here a name is what is referred to above as a &lt;b&gt;&lt;i&gt;signifier&lt;/i&gt;&lt;/b&gt; but I will just use name.  A &lt;b&gt;&lt;i&gt;System Referent&lt;/i&gt;&lt;/b&gt; is the thing (&lt;b&gt;&lt;i&gt;referent&lt;/i&gt;&lt;/b&gt;) in the Software System that the name refers to.  If this is confusing hopefully some examples will help.  Some &lt;b&gt;&lt;i&gt;System Referents&lt;/i&gt;&lt;/b&gt; include but are not limited to the following&lt;sup&gt;1&lt;/sup&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Classes&lt;/li&gt;
&lt;li&gt;Variables (local, instance, static)&lt;/li&gt;
&lt;li&gt;Methods&lt;/li&gt;
&lt;li&gt;Method Parameters&lt;/li&gt;
&lt;li&gt;Packages&lt;/li&gt;
&lt;li&gt;Database Tables, Columns, Triggers, Stored Procedures, etc.&lt;/li&gt;
&lt;li&gt;HTML Files, CSS Files, Javascript Files, Config Files, all files&lt;/li&gt;
&lt;li&gt;Directories&lt;/li&gt;
&lt;li&gt;Urls&lt;/li&gt;
&lt;li&gt;Documents&lt;/li&gt;
&lt;li&gt;XML Elements and Attributes&lt;/li&gt;
&lt;li&gt;CSS Classes&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;p&gt;And the list goes on.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Another observation we can make is that &lt;b&gt;&lt;i&gt;System Referents&lt;/i&gt;&lt;/b&gt; can have a context or a grouping, for example &lt;b&gt;&lt;i&gt;System Referents&lt;/i&gt;&lt;/b&gt; which include classes, packages, variables, methods, etc. may have different conventions from other &lt;b&gt;&lt;i&gt;System Referent&lt;/i&gt;&lt;/b&gt; groupings such as database &lt;b&gt;&lt;i&gt;System Referents&lt;/i&gt;&lt;/b&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Now that we have a way to talk about named items, we can explore the very important idea of naming conventions.  The name of a &lt;b&gt;&lt;i&gt;System Referent&lt;/i&gt;&lt;/b&gt; often consists of several components, from a linguistic stand point these components are similar to, but not the same as a &lt;a href="http://en.wikipedia.org/wiki/Lexical_unit"&gt;lexical unit&lt;/a&gt; or a &lt;a href="http://en.wikipedia.org/wiki/Morphemes"&gt;morpheme&lt;/a&gt;, for this I am choosing the term &lt;b&gt;&lt;i&gt;Name Unit&lt;/i&gt;&lt;/b&gt;, for example an identifier "personId" consists of two &lt;b&gt;&lt;i&gt;Name Units&lt;/i&gt;&lt;/b&gt;, "person" and "id". Name units imply a separator mechanism. In this example the use of &lt;a href="http://en.wikipedia.org/wiki/CamelCase"&gt;CamelCase&lt;/a&gt;, another example is "person_id" where the name units are separated by the separator "_".  So a &lt;b&gt;&lt;i&gt;name unit&lt;/i&gt;&lt;/b&gt; is that atomic piece of a name that is separated by a separator and a separator is either explicit e.g. "_" or implied e.g. CamelCase. In my previous post we looked at different prefix and suffix qualifiers, this is a generalization of the qualifier concept which deals with the whole name and not just one part of it.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;I wish to compare, from the structural perspective, two common conventions one for the Java &lt;b&gt;&lt;i&gt;System Referent&lt;/i&gt;&lt;/b&gt; grouping and that of an SQL Database grouping.  For the Java Naming convention we will assume the standard Java naming convention.  For the database we will limit ourselves to Tables and Columns and assume uppercase Names, &lt;b&gt;&lt;i&gt;name units&lt;/i&gt;&lt;/b&gt; that consist only of upper case characters, the separator will be an underscore "_".&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;We can define formal a more formal approach to the lexical structure of a naming convention using a &lt;a href="http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form"&gt;BNF&lt;/a&gt;, or in this case my own variant &lt;a href="http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form"&gt;extended BNF&lt;/a&gt;, for example our BNF for variable names in Java might look like the following:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;name-unit-terminal ::= [A-Z]+[a-zA-Z0-9]*&lt;/p&gt;&lt;p&gt;name-unit-prefix-terminal ::= [a-z]+[a-zA-Z0-9]*&lt;/p&gt;&lt;p&gt;&amp;lt;name&amp;gt; ::=  name-unit-prefix-terminal | name-unit-prefix-terminal &amp;lt;name-unit&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;lt;name-unit&amp;gt; ::= name-unit-terminal | name-unit-terminal &amp;lt;name-unit&amp;gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The Naming convention for our database column names and table names:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;name-unit-terminal ::= [A-Z]+[A-Z0-9]*&lt;/p&gt;&lt;p&gt;&amp;lt;name&amp;gt; ::=  name-unit-terminal | name-unit-terminal "_" &amp;lt;name&amp;gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Two Concrete examples illuminating these are as follows:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;public class Person {&lt;/p&gt;&lt;p class="codeline1"&gt;private Long id;&lt;/p&gt;&lt;p class="codeline1"&gt;private String lastName;&lt;/p&gt;&lt;p class="codeline1"&gt;private String firstName;&lt;/p&gt;&lt;p class="codeline1"&gt;private String middle;&lt;/p&gt;&lt;p class="codeline1"&gt;private String phone;&lt;/p&gt;&lt;p class="codeline1"&gt;private String email;&lt;/p&gt;&lt;p class="codeline1"&gt;public Long getId() {&lt;/p&gt;&lt;p class="codeline2"&gt;return id;&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p class="codeline1"&gt;public void setId(Long value) {&lt;/p&gt;&lt;p class="codeline2"&gt;id = value;&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p class="codeline1"&gt;public String getLastName() {&lt;/p&gt;&lt;p class="codeline2"&gt;return lastName;&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p class="codeline1"&gt;public void setLastName(String value) {&lt;/p&gt;&lt;p class="codeline2"&gt;lastName = value;&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p class="codeline1"&gt;public String getFirstName() {&lt;/p&gt;&lt;p class="codeline2"&gt;return firstName;&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p class="codeline1"&gt;public void setFirstName(String value) {&lt;/p&gt;&lt;p class="codeline2"&gt;firstName = value;&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p class="codeline1"&gt;public String getMiddle() {&lt;/p&gt;&lt;p class="codeline2"&gt;return middle;&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p class="codeline1"&gt;public void setMiddle(String value) {&lt;/p&gt;&lt;p class="codeline2"&gt;middle = value;&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p class="codeline1"&gt;public String getPhone() {&lt;/p&gt;&lt;p class="codeline2"&gt;return phone;&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p class="codeline1"&gt;public void setPhone(String value) {&lt;/p&gt;&lt;p class="codeline2"&gt;phone = value;&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p class="codeline1"&gt;public String getEmail() {&lt;/p&gt;&lt;p class="codeline2"&gt;return email;&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p class="codeline1"&gt;public void setEmail(String email) {&lt;/p&gt;&lt;p class="codeline2"&gt;this.email = email;&lt;/p&gt;&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;CREATE TABLE PERSON (&lt;/p&gt;&lt;p class="codeline1"&gt;ID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,&lt;/p&gt;&lt;p class="codeline1"&gt;LAST_NAME VARCHAR(40) NULL,&lt;/p&gt;&lt;p class="codeline1"&gt;FIRST_NAME VARCHAR(20) NULL,&lt;/p&gt;&lt;p class="codeline1"&gt;MIDDLE VARCHAR(20) NULL,&lt;/p&gt;&lt;p class="codeline1"&gt;PHONE VARCHAR(20) NULL,&lt;/p&gt;&lt;p class="codeline1"&gt;EMAIL VARCHAR(256) NOT NULL&lt;/p&gt;&lt;p&gt;);&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Naming Conventions consist of both a Lexical Component and a Semantic Component. In this post we have focused on the lexical aspects of naming, from the intension definition above we focused on the &lt;b&gt;&lt;i&gt;signifier&lt;/i&gt;&lt;/b&gt; and the &lt;b&gt;&lt;i&gt;referent&lt;/i&gt;&lt;/b&gt;. To really create a comprehensive approach the Semantic aspect cannot be ignored. In the intension definition above this can be viewed as focusing on the &lt;b&gt;&lt;i&gt;signified&lt;/i&gt;&lt;/b&gt; and the &lt;b&gt;&lt;i&gt;referent&lt;/i&gt;&lt;/b&gt;. This is an area that is explored in the idea of the &lt;b&gt;&lt;i&gt;&lt;a href="http://domaindrivendesign.org/node/132"&gt;Ubiquitous Language&lt;/a&gt;&lt;/i&gt;&lt;/b&gt; within the realm of  Domain Driven Design.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The Semantic Elements of a system and of a naming convention are more complex and ambiguous. I do think that software systems should have a &lt;b&gt;&lt;i&gt;System Lexicon&lt;/i&gt;&lt;/b&gt; which would be a more concrete formalization and extension of the &lt;b&gt;&lt;i&gt;System’s&lt;/i&gt;&lt;/b&gt; &lt;b&gt;&lt;i&gt;Vocabulary&lt;/i&gt;&lt;/b&gt; or &lt;b&gt;&lt;i&gt;Ubiquitous Language&lt;/i&gt;&lt;/b&gt; this would also incorporate ideas encapsulated in a &lt;a href="http://en.wikipedia.org/wiki/Data_dictionary"&gt;Data Dictionary&lt;/a&gt;.  A &lt;b&gt;&lt;i&gt;System Lexicon&lt;/i&gt;&lt;/b&gt; would be an entity of some complexity and would require some commitment to build also applying it could be problematic and might require tooling such as an &lt;a href="http://en.wikipedia.org/wiki/Integrated_development_environment"&gt;IDE&lt;/a&gt; interactive name suggestion feature or a &lt;a href="http://en.wikipedia.org/wiki/Static_program_analysis"&gt;static analysis&lt;/a&gt; component or both. It might even require an ontology or taxonomy oriented graphical tool for constructing and maintaining the &lt;b&gt;&lt;i&gt;System Lexicon&lt;/i&gt;&lt;/b&gt; depending on the size and complexity of the system.  I will get into some ideas that extend the lexical aspects and move into the Semantic aspects in future posts.  I know that this might seem pretty grandiose but I think this powerful stuff that could lead to better approaches to create higher quality software.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt;This list is biased to Java Web development, but these ideas should be general enough to span any software system.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/h1Ya-BNNxu0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/h1Ya-BNNxu0/more-thoughts-on-formal-approaches-to.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-4uF4DFKqu3U/T29K3M7GjCI/AAAAAAAAAfE/ONxHweH_BdM/s72-c/Io_Full.jpg" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/03/more-thoughts-on-formal-approaches-to.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-1047415023341078841</guid><pubDate>Tue, 20 Mar 2012 00:23:00 +0000</pubDate><atom:updated>2012-05-13T15:08:34.904-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Naming</category><category domain="http://www.blogger.com/atom/ns#">Domain Driven Design</category><category domain="http://www.blogger.com/atom/ns#">Software Engineering</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><category domain="http://www.blogger.com/atom/ns#">Linguistics</category><title>A Survey of the Conventional Wisdom on Software Naming</title><description>&lt;h2&gt;On the Importance of Naming in Software Systems, Part I&lt;/h2&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-k5vc99jNIPE/T2fLgRwkKbI/AAAAAAAAAe4/ldVVQ8KfR0c/s1600/P50142.1.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="338" width="400" src="http://3.bp.blogspot.com/-k5vc99jNIPE/T2fLgRwkKbI/AAAAAAAAAe4/ldVVQ8KfR0c/s400/P50142.1.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;style&gt;
blockquote.quote {
   border-bottom: #ddd 1px dotted;
   border-left: #ddd 1px dotted;
   padding-bottom: 0.6em;
   font-style: italic;
   font-family: calibri, tahoma, arial, sans-serif;
   margin: 1em 10% 1em 0px;
   min-height: 40px;
   padding-left: 3.8em;
   padding-right: 1em;
   background: url(http://4.bp.blogspot.com/-WkhuNlv2j88/TjXlBh6SySI/AAAAAAAAAN0/O_G2Z8YdMk8/s320/blockquote.white.png) #f0f0f0 no-repeat 4px top;
   color: #474747;
   border-top: #ddd 1px dotted;
   border-right: #ddd 1px dotted;
   padding-top: 0.6em
}

blockquote.paraphrase {
   border-bottom: #ddd 1px dotted;
   border-left: #ddd 1px dotted;
   padding-bottom: 0.6em;
   font-style: italic;
   font-family: calibri, tahoma, arial, sans-serif;
   margin: 1em 10% 1em 0px;
   min-height: 40px;
   padding-left: 3.8em;
   padding-right: 1em;
   background: #f0f0f0 no-repeat 4px top;
   color: #474747;
   border-top: #ddd 1px dotted;
   border-right: #ddd 1px dotted;
   padding-top: 0.6em
}


div.source-code1 {
    font-family       : Andale Mono, Lucida Console, Monaco, fixed, monospace;
    color             : #000;
    background-color  : #eee;
    font-size         : 12px;
    border            : 1px dashed #999999;
    line-height       : 10px;
    padding           : 5px;
    overflow          : auto;
    width             : 100%;
    text-indent       : 0px;
}

div.source-code {
    font-family       : Andale Mono, Lucida Console, Monaco, fixed, monospace;
    color             : #000;
    background-color  : #eee;
    font-size         : 12px;
    border            : 1px dashed #999999;
    line-height       : 14px;
    padding           : 5px;
    overflow          : auto;
    width             : 100%;
    text-indent       : 0px;
    margin-top        : 8px;
    margin-bottom     : 8px;
}

p.codeline {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    color:black;
}

p.codeline1 {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    text-indent:.5in;
    color:black;
}

p.codeline2 {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    text-indent:1in;
    color:black;
}

p.codeline3 {

    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    text-indent:1.5in;
    color:black;
}

&lt;/style&gt;&lt;!--A Survey of the Conventional Wisdom on Software Naming--&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;Naming is a very important aspect of software, however, its importance and relevance to building quality software is often overlooked or ignored all together.  I feel that naming needs to be part of a larger more formal framework for building software.  In &lt;a href="http://www.elegantcoding.com/2011/03/what-does-your-framework-look-like.html"&gt;previous posts&lt;/a&gt; I have advocated a framework approach to capturing reuse and standardizing software design and implementation and I feel that naming is a crucial part of such an approach. Previously I included the following quote about naming in an &lt;a href="http://www.elegantcoding.com/2011/07/software-frameworks-resistance-isnt.html#Names"&gt;API design talk by Joshua Bloch&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;Names matter a lot, there are some people that think that names don’t matter and when you sit down and say well this isn’t named right, they say don’t waste your time let’s just move on, it’s good enough. No! Names, in an API, that are going to be used by anyone else that includes yourself in a few months mater an awful lot. The idea is that every API is kind of a little language and people who are going to use your API needs to learn that language and then speak in that language and that means that names should be self explanatory, you should avoid cryptic abbreviations so the original Unix names, I think, fail this one miserably.&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;He is not the only prominent software engineer to advocate an attention to naming, in this post I will summarize and discuss several sources.  I will start with his material which is part of his talk on API design which I summarized in my &lt;a href="http://www.elegantcoding.com/2011/07/software-frameworks-resistance-isnt.html"&gt;previous post&lt;/a&gt;.  Actually I feel that most if not all of what he says on API design is applicable to software in general including what he has to say on naming. The summary points are as follows:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="paraphrase"&gt;&lt;p&gt;Names should be self explanatory.&lt;/p&gt;&lt;p&gt;Avoid cryptic abbreviations.&lt;/p&gt;&lt;p&gt;Don’t have multiple words meaning that same thing.&lt;/p&gt;&lt;p&gt;Names should be consistent – same word means same thing.&lt;/p&gt;&lt;p&gt;Be regular–strive for symmetry. This implies a larger context of naming and a relationship between concepts.&lt;/p&gt;&lt;p&gt;Code should read like prose. (As a result of good API design)&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;Chapter two titled "Meaningful Names" of Robert Martin’s &lt;u&gt;Clean Code&lt;/u&gt;, written by Tim Ottinger, is dedicated to naming. A summary of the advice is as follows:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="paraphrase"&gt;&lt;p&gt;Use Intention Revealing names&lt;/p&gt;&lt;p&gt;Avoid Disinformation – This is a corollary to Use Intention Revealing names. This means that the components of the name actually conceptually match the intent.&lt;/p&gt;&lt;p&gt;Make Meaningful Distinctions – This means Pick One Word per Concept.&lt;/p&gt;&lt;p&gt;Use Pronounceable Names. This means Avoid cryptic abbreviations.&lt;/p&gt;&lt;p&gt;Use Searchable Names. This is mainly about not using single character names and magic constants.&lt;/p&gt;&lt;p&gt;Avoid Encodings. This means do not use suffixes or prefixes to encode type or status as a member "m_".  He also discourages using "I" as a prefix to an interface. This includes avoiding Hungarian Notation.&lt;/p&gt;&lt;p&gt;Avoid Mental Mapping. This is an anti pattern. It is a corollary to Use Intention Revealing Names.&lt;/p&gt;&lt;p&gt;Class Names should consist of nouns of verb Phrases.&lt;/p&gt;&lt;p&gt;Method Names should consist of verbs or verb Phrases.&lt;/p&gt;&lt;p&gt;Pick One Word per Concept. &lt;/p&gt;&lt;p&gt;Use Solution Domain Names. Solution domain names refer to things like design patterns or more distinct concepts such as Queue or Binary Tree&lt;/p&gt;&lt;p&gt;Use Problem Domain Names – This is pretty straight forward, if your system processes medical records, you might expect a class called MedicalRecord.&lt;/p&gt;&lt;p&gt;Add Meaningful Context – This deals with the idea of adding suffixes or prefixes to denote additional context information in the name.  The example given is use addrState vs. state.&lt;/p&gt;&lt;p&gt;Don’t Add Gratuitous Context – This talks about the idea of adding unnecessary or too specific suffixes or prefixes to denote context.&lt;/p&gt;&lt;p&gt;Choosing good names requires good descriptive Skills and Shared cultural background&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;Steve McConnell’s &lt;u&gt;Code Complete&lt;/u&gt; contains the following advice&lt;sup&gt;1&lt;/sup&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="paraphrase"&gt;&lt;p&gt;A name should fully and accurately describe what the variable represents.&lt;/p&gt;&lt;p&gt;A good mnemonic name generally speaks to the problem rather than the solution. A good name tends to express the what more than the how. In general, if a name refers to some aspect of computing rather than to the problem, it's a how rather than a what. Avoid such a name in favor of a name that refers to the problem itself.&lt;/p&gt;&lt;p&gt;Use pronounceable names.&lt;/p&gt;&lt;p&gt;Avoid misleading names or abbreviations and use consistent abbreviations.&lt;/p&gt;&lt;p&gt;Avoid names that are misleading.&lt;/p&gt;&lt;p&gt;Avoid names with similar meanings.&lt;/p&gt;&lt;p&gt;Avoid variables with different meanings but similar names&lt;/p&gt;&lt;p&gt;Name Specific Types of Data using Standardized Prefixes – Use prefixes to denote (encode) type such as Hungarian Notation.&lt;/p&gt;&lt;p&gt;Use computed-value qualifiers if needed at the end of the name. Examples are: Total, Sum, Average, Max, Min, Record, String, or Pointer.&lt;/p&gt;&lt;p&gt;Use a Naming Convention and that naming convention should be compatible standard conventions for the language.   Naming convention should distinguish among local, class, and global data.  Naming convention should distinguish among type names, named constants, enumerated types, and ­variables.&lt;/p&gt;&lt;p&gt;Good variable names are a key element of program readability. Specific kinds of variables such as loop indexes and status variables require specific considerations.&lt;/p&gt;&lt;p&gt;Names should be as specific as possible. Names that are vague enough or general enough to be used for more than one purpose are usually bad names.&lt;/p&gt;&lt;p&gt;Naming conventions distinguish among local, class, and global data. They distinguish among type names, named constants, enumerated types, and variables.&lt;/p&gt;&lt;p&gt;Abbreviations are rarely needed with modern programming languages. If you do use abbreviations, keep track of abbreviations in a project dictionary or use the standardized prefixes approach.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;I did reword some of these to make them more stand alone. You may want to pursue the sources to gain a fuller picture of each author’s perspective.  The interesting thing here is while there are several key common themes to these approaches there are some very explicit contradictions. For example &lt;u&gt;Clean Code&lt;/u&gt; recommends against Type encoding like Hungarian Notation while &lt;u&gt;Code Complete&lt;/u&gt; recommends it.  Conversely &lt;u&gt;Code Complete&lt;/u&gt; seems to implicitly recommend against using Solution Domain Names "speaks to the problem rather than the solution" whereas &lt;u&gt;Clean Code&lt;/u&gt; advocates their use.&lt;/p&gt;&lt;p&gt;I feel that when talking about naming it is easy to conflate ideas pertaining to structural (lexical) concerns and ideas pertaining to domain (semantic) concerns.  Unfortunately while these ideas are separate they are also intertwined and an intelligent approach to naming needs to recognize this.  &lt;/p&gt;&lt;p&gt;One structural theme is the idea of qualifiers, which &lt;u&gt;Code Complete&lt;/u&gt; explicitly names, but the idea appears implicitly in &lt;u&gt;Clean Code&lt;/u&gt; as well.  Qualifiers in this context are generally prefixes and suffixes that qualify the name. Qualifiers mentioned above include &lt;i&gt;scope qualifiers&lt;/i&gt; which denote the scope of a variable such as the prefixes "m_" for member or "global_" for global. &lt;a href="http://en.wikipedia.org/wiki/Hungarian_notation"&gt;Hungarian Notation&lt;/a&gt; in this context&lt;sup&gt;2&lt;/sup&gt; is an example of a type qualifier. Additionally &lt;u&gt;Code Complete&lt;/u&gt; defines &lt;i&gt;computed-value qualifier&lt;/i&gt; suffixes to denote values which are computed values these include: Total, Sum, Average, Max, Min, Record, String, or Pointer.  Interestingly qualifiers are a structural element of a name which denotes additional specific types of semantic meaning to the name. The structural and semantic construction of names is a topic I intend to continue exploring in subsequent posts.&lt;/p&gt;&lt;p&gt;The previous ideas address both structural (lexical) and domain (semantic) concerns now I wish to look at a targeted summary of more semantic oriented conceptual advice in Eric Evan’s &lt;u&gt;Domain Driven Design&lt;/u&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="paraphrase"&gt;&lt;p&gt;Domain model terms are part the UBIQUITOUS LANGUAGE.&lt;/p&gt;&lt;p&gt;In regards to an INTENTION-REVEALING INTERFACE, name classes and operations to describe their effect and purpose without reference to the means by which they do what they promise. This relieves the client developer of the need to understand the internals. These names should conform to the UBIQUITOUS LANGUAGE so that team members can quickly infer their meaning.&lt;/p&gt;&lt;p&gt;In regards to MODULES aka Packages, If your model is telling a story your MODULES are chapters. The name of the MODULE conveys its meaning.  These names enter the UBIQUITOUS LANGUAGE.&lt;/p&gt;&lt;p&gt;Name each BOUNDED CONTEXT and make the names part of the UBIQUITOUS LANGUAGE.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;In &lt;u&gt;Domain Driven Design&lt;/u&gt; the idea of conceptually developing and implementing the Domain iteratively is explored.  This book reveals many approaches and concepts pertaining to that topic, the ideas that I am interested in which are targeted in the quotes above pertain to naming.  A common theme in naming which would be hard to dispute is to Use Problem Domain Names. The idea of a &lt;i&gt;UBIQUITOUS LANGUAGE is &lt;/i&gt;promoted in the book as a way to help define the domain so that all stakeholders have a common way to talk about the domain and its representation in the resulting software.  &lt;u&gt;Domain Driven Design&lt;/u&gt; promotes using the &lt;i&gt;UBIQUITOUS LANGUAGE&lt;/i&gt; as a theme to defining the system and unifying the system documentation.  To me a &lt;i&gt;UBIQUITOUS LANGUAGE&lt;/i&gt; implies the need to track, define and attempt to codify it over time which I think implies a more formal way to document it like a lexicon is needed, an idea I will follow up on more in a future post.&lt;/p&gt;&lt;p&gt;Another issue with talking about software naming is the idea of context.  Names pretty much always exist in a context, in Java a variable can be in the context of a method or a class. Both methods and classes themselves can exist in the context of classes and classes exist in the context of classes and packages and packages are themselves hierarchical. In fact software systems have developed the concept of Namespace to in part deal with this problem.  &lt;/p&gt;&lt;p&gt;Each name exists in a context, and in order to talk about naming we need a language just as you need to define a language for a domain. Actually naming is a domain, a meta-domain perhaps, a domain that describes other domains.  This means we need a "&lt;i&gt;UBIQUITOUS LANGUAGE&lt;/i&gt;" for the domain of naming. So in that language I am going to define &lt;a name="OLE_LINK2"&gt;&lt;/a&gt;&lt;a name="OLE_LINK1"&gt;&lt;b&gt;&lt;i&gt;name scope context&lt;/i&gt;&lt;/b&gt;&lt;/a&gt; to define to context or "hierarchical place" in which a name occurs. I am purposefully not using namespace since that has other explicit meanings.  I know using the words scope and context seem redundant but I felt using "scope" alone didn’t work because it has a &lt;a href="http://en.wikipedia.org/wiki/Scope_(computer_science)"&gt;specific meaning&lt;/a&gt; and context by itself was too vague, using &lt;b&gt;&lt;i&gt;name scope context&lt;/i&gt;&lt;/b&gt; can refer to a broader set of circumstances such as an attribute’s position in an xml document relative to its parent element or a SQL Column name relative to its parent table, a file’s directory and so on.&lt;/p&gt;&lt;p&gt;An interesting thing I have noticed about &lt;b&gt;&lt;i&gt;name scope context&lt;/i&gt;&lt;/b&gt; is that it can be redundant.  For example let’s assume that we have an object named a database table named PERSON and a corresponding object named Person.  I have seen the following approach to naming these:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;CREATE TABLE PERSON (&lt;/p&gt;&lt;p&gt;    PERSON_ID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,&lt;/p&gt;&lt;p&gt;    LAST_NAME VARCHAR(40) NULL,&lt;/p&gt;&lt;p&gt;    FIRST_NAME VARCHAR(20) NULL,&lt;/p&gt;&lt;p&gt;    MIDDLE VARCHAR(20) NULL,&lt;/p&gt;&lt;p&gt;    PHONE VARCHAR(20) NULL,&lt;/p&gt;&lt;p&gt;    EMAIL VARCHAR(256) NOT NULL,&lt;/p&gt;&lt;p&gt;    DELETED CHAR(1) NOT NULL DEFAULT 'N',&lt;/p&gt;&lt;p&gt;    CREATE_DATE TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,&lt;/p&gt;&lt;p&gt;    MODIFY_DATE TIMESTAMP NULL&lt;/p&gt;&lt;p&gt;)&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;class Person {&lt;/p&gt;&lt;p&gt;    private int personId;&lt;/p&gt;&lt;p&gt;    private String lastName;&lt;/p&gt;&lt;p&gt;    private String firstName;&lt;/p&gt;&lt;p&gt;    private String middle;&lt;/p&gt;&lt;p&gt;    private String phone;&lt;/p&gt;&lt;p&gt;    private String email;&lt;/p&gt;&lt;p&gt;    private boolean deleted;&lt;/p&gt;&lt;p&gt;    private Date createDate;&lt;/p&gt;&lt;p&gt;    private Date modifyDate;&lt;/p&gt;&lt;p&gt;...&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Now in these examples the database table PERSON contains the column named PERSON_ID and the class Person contains the corresponding field named personId.  In both of these cases ID or id respectively would be probably be better as the use of person is repeating the name used within the &lt;b&gt;&lt;i&gt;name scope context&lt;/i&gt;&lt;/b&gt; of the member variable.  The down side of this type of non-duplication is the loss of the ability to search for the names, which I think implies that software name search probably needs more sophisticated mechanisms over that of simple text searching, another idea I will expand on in the future.&lt;/p&gt;&lt;p&gt;This is my first post on naming, I have three more planned and I will get into more ideas some of which come from linguistics. I feel that &lt;u&gt;Domain Driven Design&lt;/u&gt; gets into a number of linguistic and linguistic oriented concepts, maybe what we are going for here is &lt;i&gt;Semantic Driven Design&lt;/i&gt;, but that would be just another &lt;a href="http://www.elegantcoding.com/2011/05/driven-development.html"&gt;YADD&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt; &lt;u&gt;Code Complete&lt;/u&gt; provides a lot of ideas here are few more:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="paraphrase"&gt;&lt;p&gt;The name should long enough that you don't have to puzzle it out.&lt;/p&gt;&lt;p&gt;Avoid misspelled words in names.&lt;/p&gt;&lt;p&gt;Avoid words that are commonly misspelled.&lt;/p&gt;&lt;p&gt;Don't differentiate variable names solely by capitalization.&lt;/p&gt;&lt;p&gt;Creating Short Names That Are Readable. These are guidelines for shortening names when you need to, so this is a special case not a general one.  I know I have run into this with Oracle 11g’s 30 Char limit.&lt;/p&gt;&lt;p&gt;Avoid unnecessary abbreviations.&lt;/p&gt;&lt;p&gt;Avoid multiple natural languages.&lt;/p&gt;&lt;p&gt;Avoid names that could be misread or mispronounced.&lt;/p&gt;&lt;p&gt;Avoid names that are different by only one or two characters.&lt;/p&gt;&lt;p&gt;Avoid names that sound similar.&lt;/p&gt;&lt;p&gt;Avoid names that conflict with standard library routine names or with predefined variable names.&lt;/p&gt;&lt;p&gt;Format names for readability.&lt;/p&gt;&lt;p&gt;Avoid excessively long names.&lt;/p&gt;&lt;p&gt;Code is read far more times than it is written. Be sure that the names you choose favor read-time convenience over write-time convenience.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;&lt;sup&gt;2&lt;/sup&gt; This use of Hungarian notation is apparently not how it was intended to be used see "&lt;a href="http://www.joelonsoftware.com/articles/Wrong.html"&gt;Making Wrong Code Look Wrong&lt;/a&gt;".&lt;/p&gt;&lt;br /&gt;
&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/vYSHkd-jPis" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/vYSHkd-jPis/survey-of-conventional-wisdom-on.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-k5vc99jNIPE/T2fLgRwkKbI/AAAAAAAAAe4/ldVVQ8KfR0c/s72-c/P50142.1.jpg" height="72" width="72" /><thr:total>3</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/03/survey-of-conventional-wisdom-on.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-606133454334061962</guid><pubDate>Sun, 11 Mar 2012 20:11:00 +0000</pubDate><atom:updated>2012-05-06T11:55:09.019-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Topology</category><category domain="http://www.blogger.com/atom/ns#">Fractal Geometry</category><category domain="http://www.blogger.com/atom/ns#">Math</category><category domain="http://www.blogger.com/atom/ns#">Editing</category><title>Are you sure that you are editing in two dimensions?</title><description>&lt;br /&gt;
&lt;h3&gt;Editing the Positive Orthant and The Topology of Text Editing&lt;/h3&gt;&lt;br /&gt;
&lt;style&gt;

div.source-code {
    font-family       : Andale Mono, Lucida Console, Monaco, fixed, monospace;
    color             : #000;
    background-color  : #eee;
    font-size         : 12px;
    border            : 1px dashed #999999;
    line-height       : 14px;
    padding           : 5px;
    overflow          : auto;
    width             : 100%;
    text-indent       : 0px;
    margin-top        : 8px;
    margin-bottom     : 8px;
}
&lt;/style&gt;&lt;!--Are you sure that you are editing in two dimensions?--&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-M_ynDcrUTjU/T1vjX6UQBRI/AAAAAAAAAco/WbEd2K14tn4/s1600/elegantcoding.com.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="250" width="250" src="http://1.bp.blogspot.com/-M_ynDcrUTjU/T1vjX6UQBRI/AAAAAAAAAco/WbEd2K14tn4/s400/elegantcoding.com.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;In my &lt;a href="http://www.elegantcoding.com/2011/04/typing-vs-editor-kung-fu.html"&gt;previous post on editing&lt;/a&gt; I mentioned column cutting and pasting, a powerful feature that many programmers I have worked with don’t use or even know about.  I started thinking about it in terms of math and seemed to me that this creates a dimensional difference between the standard &lt;a href="http://en.wikipedia.org/wiki/Eclipse_IDE"&gt;Eclipse Editor&lt;/a&gt; and the editor that I use.  My observation is that the standard Eclipse Editor only lets you edit in one dimension, of course such a statement might seem absurd but I think it’s true and to explain it I am going to take a little tour of the concept of dimension.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;From what I understand the idea of &lt;a href="http://en.wikipedia.org/wiki/Dimension"&gt;Dimension&lt;/a&gt; is not completely cut and dry and comes in a variety of forms, most people only know of or think of Spatial Dimension of the &lt;a href="http://en.wikipedia.org/wiki/Cartesian_coordinate_system"&gt;Cartesian Coordinate System&lt;/a&gt; in &lt;a href="http://en.wikipedia.org/wiki/Euclidean_space"&gt;Euclidean Space&lt;/a&gt; for example the screen on which your editor is displayed.  But dimension both comes in many other flavors and allows the representation of so many things.  For example Dimensions can be in the form of Fractal Dimension, Hausdorff Dimension, Topological aka Lebesgue Covering Dimension, and the list goes on.&lt;/p&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-aBChs-fnaL8/T1viOp_OoOI/AAAAAAAAAcc/i0bEwHzmagY/s1600/Toroidal_coord.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="300" width="400" src="http://2.bp.blogspot.com/-aBChs-fnaL8/T1viOp_OoOI/AAAAAAAAAcc/i0bEwHzmagY/s400/Toroidal_coord.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Another deceptive property of Dimension comes from the topological concept of &lt;a href="http://en.wikipedia.org/wiki/Surface"&gt;surfaces&lt;/a&gt; or more generally &lt;a href="http://en.wikipedia.org/wiki/Topological_manifold"&gt;Manifolds&lt;/a&gt;.  An interesting example of this is the older video game &lt;a href="http://en.wikipedia.org/wiki/Asteroids_(video_game)"&gt;Asteroids&lt;/a&gt; or any game where you move from the bottom edge to reappear on the top edge of the screen or from top to bottom of the screen, the same applies to the left to right &lt;a href="http://en.wikipedia.org/wiki/Wraparound_(video_games)"&gt;wrapping&lt;/a&gt; motion.  You are actually moving as shown above around on the surface of a &lt;a href="http://en.wikipedia.org/wiki/Torus"&gt;torus&lt;/a&gt; along the two different axes shown in red and blue.  This idea can extend to higher dimensions, imagine, instead of a square video game screen, a cube where each face was connected to the opposite face (3 connections), if you moved in any direction, in three dimensions, far enough you would always end up at the same place, actually the universe could have this shape, I am not saying that it does though, interestingly there is a &lt;a href="http://www.brianschrank.com/videogames.htm"&gt;three dimensional version of asteroids&lt;/a&gt;.  This cube torus is known as a 3-torus&lt;sup&gt;&amp;dagger;&lt;/sup&gt; which is one many 3 manifolds (three dimensional manifolds). Manifolds are a higher dimensional topological generalization of surfaces like spheres and tori.  In the case of the torus and 3-torus&lt;sup&gt;&amp;dagger;&lt;/sup&gt;, you need to step up to a higher dimension to really see the structure that you are in.&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-mlem0SgeRMU/T1vjeB0rZ2I/AAAAAAAAAc0/Wxi9TsscrbU/s1600/500px-Cartesian_coordinates_2D_svg.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="371" width="400" src="http://1.bp.blogspot.com/-mlem0SgeRMU/T1vjeB0rZ2I/AAAAAAAAAc0/Wxi9TsscrbU/s400/500px-Cartesian_coordinates_2D_svg.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Ok so some of these ideas may seem a little broad and not necessarily directly relevant but they really are and they are interesting and give a larger picture of the complexity of the idea of dimension so bear with me.  The next important and hopefully more obviously relevant idea is the concept of an &lt;a href="http://en.wikipedia.org/wiki/Orthant"&gt;Orthant&lt;/a&gt; or n-hyperoctant, these are just fancy and more general terms for a concept you probably already know.  An Orthant is the division of space around the origin, so in two dimensions there are four orthants also known as Quadrants or 2-hyperoctants.   The simplest case is two rays forming two 1-dimensional orthants, one positive and one negative.  The number of orthants grows by powers of 2, i.e. 2&lt;sup&gt;n&lt;/sup&gt;, so one dimension (line) has 2&lt;sup&gt;1&lt;/sup&gt;= 2, two dimensions (plane) has 2&lt;sup&gt;2&lt;/sup&gt;= 4, three (space): 2&lt;sup&gt;3&lt;/sup&gt;= 8 and so on.  Each orthant has all combinations of positive and negative coordinates a set that will be of size 2&lt;sup&gt;n&lt;/sup&gt;, so one dimension has {(+),(-)}, two dimensions has {(+,+),(-,+),(+,-),(-,-)},  and so on,  each dimension will have exactly one orthant that has only positive coordinates and exactly one orthant that has only negative coordinates.&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-6sRKv4Pk6e8/T1vkCYncA2I/AAAAAAAAAdA/t32a-1k746k/s1600/orth-edit.1.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="369" src="http://3.bp.blogspot.com/-6sRKv4Pk6e8/T1vkCYncA2I/AAAAAAAAAdA/t32a-1k746k/s400/orth-edit.1.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The orthant concept is very relevant to text editing, when you edit you are working in a two dimensional Euclidean space, and you are working in the Positive Quadrant (Orthant).  When you edit, you start with line one, column one and count up to the right and down, this is actually a reflection around the x-axis of the traditional plane with the positive y to the left or counter clockwise from the x axis which is the way one usually represents a Cartesian plane.  Also we are working strictly with positive non-zero integer positions so our space is (n,n) &amp;isin; (N x N)  n &amp;isin; N &amp;gt; 0 the positive quadrant of the two dimensional integer plane.&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-T7R5vOGQOzs/T1vk5LC1qzI/AAAAAAAAAdM/c2NKHbyQy7M/s1600/362px-KochFlake_svg.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="362" width="362" src="http://3.bp.blogspot.com/-T7R5vOGQOzs/T1vk5LC1qzI/AAAAAAAAAdM/c2NKHbyQy7M/s400/362px-KochFlake_svg.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;At this point, if you are still with me, you might be saying: “Aha, you just demonstrated that editing is two dimensional”, but I’m not done yet and I want to take a small digression into &lt;a href="http://en.wikipedia.org/wiki/Fractal_geometry"&gt;Fractal Geometry&lt;/a&gt; first. The &lt;a href="http://en.wikipedia.org/wiki/Koch_curve"&gt;Koch or Snowflake curve&lt;/a&gt; shown above has a &lt;a href="http://en.wikipedia.org/wiki/Fractal_dimension"&gt;Fractal Dimension&lt;/a&gt; of log(4)/log(3) =log&lt;sub&gt;3&lt;/sub&gt;4= 1.2619.  But its &lt;a href="http://en.wikipedia.org/wiki/Lebesgue_covering_dimension"&gt;Topological Dimension&lt;/a&gt; is 1 since it is a one dimensional &lt;a href="http://en.wikipedia.org/wiki/Continuous_function" title="Continuous function"&gt;continuous&lt;/a&gt; everywhere but &lt;a href="http://en.wikipedia.org/wiki/Differentiable_function" title="Differentiable function"&gt;differentiable&lt;/a&gt; nowhere curve.   In Topology you can stretch and bend things so imagine the curve is made of string and you pick it up and it loses its shape.  You can then lay it down as a circle which is a one dimensional curve, a 1-torus&lt;sup&gt;&amp;dagger;&lt;/sup&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The Koch Curve can be created using a &lt;a href="http://en.wikipedia.org/wiki/L-system"&gt;Fractal L-System&lt;/a&gt;. The important thing to realize here is that Fractal L-Systems have a strong similarity to the &lt;a href="http://en.wikipedia.org/wiki/Chomsky_hierarchy"&gt;Chomsky Hierarchy&lt;/a&gt;, now there are some substantial differences between the two &lt;a href="http://en.wikipedia.org/wiki/Rewriting_system"&gt;rewriting systems&lt;/a&gt;, but I will focus only on one of the similarities here. The Koch Curve can be defined by the following &lt;a href="http://en.wikipedia.org/wiki/Koch_snowflake#Representation_as_Lindenmayer_system"&gt;L-System&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;Alphabet&amp;nbsp;: F&lt;/p&gt;&lt;p&gt;Constants&amp;nbsp;: +, &amp;#8722;&lt;/p&gt;&lt;p&gt;Axiom&amp;nbsp;: F++F++F&lt;/p&gt;&lt;p&gt;Production rules:&lt;/p&gt;&lt;p&gt;F &amp;#8594; F&amp;#8722;F++F&amp;#8722;F&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Here, F means &amp;quot;draw forward&amp;quot;, + means &amp;quot;turn right 60°&amp;quot;, and &amp;#8722; means &amp;quot;turn left 60°&amp;quot; (see &lt;a href="http://en.wikipedia.org/wiki/Turtle_graphics" title="Turtle graphics"&gt;turtle graphics&lt;/a&gt;).&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The first four iterations, which correspond to the images above are:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;F++F++F&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;F-F++F-F++F-F++F-F++F-F++F-F&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F-F-F++F-F-F-F++F-F++F-F++F-F-F-F++F-F&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Each iteration results in a new longer more complex one [topological] dimensional strand of characters.  The striking similarity here is that much as an L-System will give you a one dimensional strand of characters a &lt;a href="http://en.wikipedia.org/wiki/Context_Free_Grammar"&gt;Context Free Grammar&lt;/a&gt; which will describe most programming languages will give you a similar one dimensional “strand” of terminal symbols which would be &lt;a href="http://en.wikipedia.org/wiki/Lexical_analysis"&gt;lexemes&lt;/a&gt; corresponding to a linear sequence of programming language statements.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;In the asteroids example we are looking at two dimensional screen that is really a two dimensional surface on a three dimensional torus, here we are looking at one dimensional strand represented on a two dimensional screen and this is the key observation that ties all of this together and shows the nuances of these ideas.  One dimensional editing is when you are editing on the &lt;i&gt;positive ray&lt;/i&gt;, &lt;i&gt;1-hyperoctant&lt;/i&gt;, cursor movement follows the strand in one dimension, in both directions along the strand, and cutting will cut one dimensional strands and only allow them to and pasted into any single position within the strand.  The default behavior of the Eclipse editor offers one dimensional editing. Now let’s compare these specific operations to another editor which allows two dimensional movement and cutting and pasting.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Cursor Movement&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;The first example shows the how the cursor behaves at the end of the line in Eclipse. In the following image the cursor is at the end of line 21, which is a coordinate of (21,37) as shown at the bottom of the image:&lt;/p&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-MpeAEdOUu3E/T1vlDRryMPI/AAAAAAAAAdY/DDL-9Iu0VvQ/s1600/Cursor1.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="312" width="400" src="http://1.bp.blogspot.com/-MpeAEdOUu3E/T1vlDRryMPI/AAAAAAAAAdY/DDL-9Iu0VvQ/s400/Cursor1.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Hitting the right arrow to move cursor right by one, moves you to the beginning of the next line, coordinate (22,1) as shown below:&lt;/p&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-hyhx4bevYm4/T1vlIwbYLlI/AAAAAAAAAdk/npIc3xBOTw4/s1600/cursor2.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="311" width="400" src="http://1.bp.blogspot.com/-hyhx4bevYm4/T1vlIwbYLlI/AAAAAAAAAdk/npIc3xBOTw4/s400/cursor2.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;This movement is along the one dimensional stand of the code itself, not the plane.  The confusing thing here is that we are looking at the text in two dimensions and using two dimensional coordinates to describe it, the next example will make it clearer.  Here is the same image from a different editor that supports two dimensional operations:&lt;/p&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-iZleP88hbuE/T1vlODZsD2I/AAAAAAAAAdw/6TZ4bO_2hfM/s1600/Cursor3.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="265" width="400" src="http://2.bp.blogspot.com/-iZleP88hbuE/T1vlODZsD2I/AAAAAAAAAdw/6TZ4bO_2hfM/s400/Cursor3.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-kfZ2L0CLHvY/T1vlS9ZGKTI/AAAAAAAAAd8/1aN_VVIV1oc/s1600/Cursor4.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="268" width="400" src="http://3.bp.blogspot.com/-kfZ2L0CLHvY/T1vlS9ZGKTI/AAAAAAAAAd8/1aN_VVIV1oc/s400/Cursor4.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;This example shows two dimensional cursor behavior at the end of line 21, which is a coordinate of (21,37) as shown at the bottom of the image, hitting the right arrow to move cursor right by one, moves you right by one position to coordinate (21,38) as shown above.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Cutting and Pasting&lt;/h3&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-k7JT476WRGg/T1vlnOPy2ZI/AAAAAAAAAeI/dUroS_io1f0/s1600/CutPaste1.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="336" width="400" src="http://4.bp.blogspot.com/-k7JT476WRGg/T1vlnOPy2ZI/AAAAAAAAAeI/dUroS_io1f0/s400/CutPaste1.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The one dimensional line cut:&lt;/p&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-_dD61eHi-bw/T1vnQv0w4aI/AAAAAAAAAeU/mV_nAgRBAB8/s1600/CutPaste2.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="333" width="400" src="http://4.bp.blogspot.com/-_dD61eHi-bw/T1vnQv0w4aI/AAAAAAAAAeU/mV_nAgRBAB8/s400/CutPaste2.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Two dimensional cutting and pasting:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-W4xKnC66DlM/T1vnV6QWAwI/AAAAAAAAAeg/QNWXpCdRwdU/s1600/CutPaste3.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="265" width="400" src="http://3.bp.blogspot.com/-W4xKnC66DlM/T1vnV6QWAwI/AAAAAAAAAeg/QNWXpCdRwdU/s400/CutPaste3.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;In both cases above we are selecting blocks of text with starting coordinate (21,12) to ending coordinate (26,18) however the Eclipse version (top) only allows the selection of a one dimensional strand of text, as you move in either direction you will only be able to grab complete lines between the start and end coordinates and if you paste this text you will be inserting a one dimensional strand into a single position in another one dimensional strand.  The two dimensional operation offers more flexibility beyond the only the one dimensional operation, actually the editor offers both one and two dimensional cutting, which is what you really want in an editor.  The resulting cuts are as follows, now admittedly the two dimensional cut in this case is not really practical.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The two dimensional column cut:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-2ELvHhJlOjI/T1vnhuY-FmI/AAAAAAAAAes/yz_nOIi_LCU/s1600/CutPaste4.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="268" width="400" src="http://2.bp.blogspot.com/-2ELvHhJlOjI/T1vnhuY-FmI/AAAAAAAAAes/yz_nOIi_LCU/s400/CutPaste4.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Hopefully this give a sense of the difference from editing on a one dimensional ray vs. a two dimensional plane.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;If we revisit the one dimensional strand of characters idea, we notice a problem.  While the strand is one dimensional in that the position of each character can be given by a single integer index into the string, which is a single axis or ray.  Each position can have a different value. In our fractal each position could contain one of three characters {F,+,-} which we could map to {0,1,2} respectively.  Now each iteration of the L-System production generates a number in base three and each position can have one of three “pixels” in the strand. Now we need another dimension, or at least part of one, to represent this additional information.  A more practical example would be a 24 bit RGB image where each pixel has a position, remember this can be stored as a single one dimensional strand of pixels but displayed in two dimensions by cutting up the strand into rows.  Similarly a program can be “pixilated” where each pixel could be an ascii character (byte), a lexical token or lexeme, or a binary zero or one bit along the one dimensional strand.  The length of the strand would vary in accordance to height of the pixels a binary pixel representation/strand would have more positions than an ascii pixel representation/strand than would the lexeme pixel representation/strand.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Ok this is probably my zaniest post about my crazy ideas which I am pretty sure are correct. Hopefully I did a decent job explaining these ideas, I find them to be quite mind blowing, at least that's the way I felt when I first understood the basic ideas about topology and manifolds, and there is still so much I don't know.  Also if you feel that you both have a better understanding of some of these ideas and at the same time feel more confused about them, I think that might be normal and I think a big part of learning math is just getting used to feeling that way all of the time, because the more you learn the stronger both of these feelings become, at least that's my experience.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;sup&gt;&amp;dagger;&lt;/sup&gt;An n-torus can mean either an n-dimensional torus or a two dimensional toriodal surface with n holes. In this post it always means n-dimensional torus.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/uk-Fn7oT6u0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/uk-Fn7oT6u0/are-you-sure-that-you-are-editing-in.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-M_ynDcrUTjU/T1vjX6UQBRI/AAAAAAAAAco/WbEd2K14tn4/s72-c/elegantcoding.com.png" height="72" width="72" /><thr:total>4</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/03/are-you-sure-that-you-are-editing-in.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-5972540536999418974</guid><pubDate>Tue, 06 Mar 2012 03:12:00 +0000</pubDate><atom:updated>2012-05-06T11:57:13.045-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Math</category><category domain="http://www.blogger.com/atom/ns#">Design Patterns</category><category domain="http://www.blogger.com/atom/ns#">API Design</category><category domain="http://www.blogger.com/atom/ns#">Combinatorics</category><category domain="http://www.blogger.com/atom/ns#">Software Engineering</category><title>The Software Design Debate and the Futility of Opinion</title><description>&lt;br /&gt;
&lt;h2&gt;A Tale of Two Classes&lt;/h2&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-psyxaFKWwjk/T1VxijBhRWI/AAAAAAAAAcE/isRT6luvL8g/s1600/IMG_2026.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="300" width="400" src="http://3.bp.blogspot.com/-psyxaFKWwjk/T1VxijBhRWI/AAAAAAAAAcE/isRT6luvL8g/s400/IMG_2026.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;style&gt;
blockquote.quote {
   border-bottom: #ddd 1px dotted;
   border-left: #ddd 1px dotted;
   padding-bottom: 0.6em;
   font-style: italic;
   font-family: calibri, tahoma, arial, sans-serif;
   margin: 1em 10% 1em 0px;
   min-height: 40px;
   padding-left: 3.8em;
   padding-right: 1em;
   background: url(http://4.bp.blogspot.com/-WkhuNlv2j88/TjXlBh6SySI/AAAAAAAAAN0/O_G2Z8YdMk8/s320/blockquote.white.png) #f0f0f0 no-repeat 4px top;
   color: #474747;
   border-top: #ddd 1px dotted;
   border-right: #ddd 1px dotted;
   padding-top: 0.6em
}

div.source-code1 {
    font-family       : Andale Mono, Lucida Console, Monaco, fixed, monospace;
    color             : #000;
    background-color  : #eee;
    font-size         : 12px;
    border            : 1px dashed #999999;
    line-height       : 10px;
    padding           : 5px;
    overflow          : auto;
    width             : 100%;
    text-indent       : 0px;
}

div.source-code {
    font-family       : Andale Mono, Lucida Console, Monaco, fixed, monospace;
    color             : #000;
    background-color  : #eee;
    font-size         : 12px;
    border            : 1px dashed #999999;
    line-height       : 14px;
    padding           : 5px;
    overflow          : auto;
    width             : 100%;
    text-indent       : 0px;
    margin-top        : 8px;
    margin-bottom     : 8px;
}

p.codeline {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    color:black;
}

p.codeline1 {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    text-indent:.5in;
    color:black;
}

p.codeline2 {

    padding: 0px;
    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    text-indent:1in;
    color:black;
}

p.codeline3 {

    margin-top:0in;
    margin-bottom:0in;
    margin-bottom:.0001pt;
    line-height: 12px;
    font-size:10.0pt;
    font-family:"Courier New";
    text-indent:1.5in;
    color:black;
}

td.comb-left {
    padding : 10px;
    text-align : center;
    background-color : #ffffff;
    color : black;
    border : 1px solid black;
    vertical-align : center;
}


td.comb {
    padding : 10px;
    text-align : left;
    background-color: #ffffff;
    color:black;
    border : 1px solid black;
    vertical-align : center;
}


&lt;/style&gt;&lt;!--The Software Design Debate and the Futility of Opinion: A Tale of Two Classes --&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;A while back when I was at a previous contract this &lt;a href="http://blogs.atlassian.com/2011/05/exceptions_are_bad/"&gt;article&lt;/a&gt; showed up on various link sites and one of the architects at that company sent it out. As a result, another developer and I, with the help of a googled code snippet, came up with the following code and added it to the common library:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p class="codeline"&gt;&lt;b&gt;public&lt;/b&gt; &lt;b&gt;class&lt;/b&gt; ServiceResponse &amp;lt;ERROR &lt;b&gt;extends&lt;/b&gt; ErrorReturn,&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline3"&gt;VALUE &lt;b&gt;extends&lt;/b&gt; ValueReturn&amp;gt; {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;&lt;b&gt;private&lt;/b&gt; ServiceResponse() {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;&lt;b&gt;public&lt;/b&gt; ERROR error() {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;return&lt;/b&gt; &lt;b&gt;null&lt;/b&gt;;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;&lt;b&gt;public&lt;/b&gt; VALUE value() {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;return&lt;/b&gt; &lt;b&gt;null&lt;/b&gt;;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;&lt;b&gt;public final static class&lt;/b&gt; Error&amp;lt;ERROR &lt;b&gt;extends&lt;/b&gt; ErrorReturn&amp;gt;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline3"&gt;&lt;b&gt;extends&lt;/b&gt; ServiceResponse&amp;lt;ERROR, ValueReturn&amp;gt; {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;private&lt;/b&gt; &lt;b&gt;final&lt;/b&gt; ERROR error;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;public&lt;/b&gt; Error(ERROR error) {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline3"&gt;&lt;b&gt;this&lt;/b&gt;.error = error;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;public&lt;/b&gt; ERROR error() {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline3"&gt;&lt;b&gt;return&lt;/b&gt; error;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;public&lt;/b&gt; &lt;b&gt;boolean&lt;/b&gt; isError() {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline3"&gt;&lt;b&gt;return&lt;/b&gt; &lt;b&gt;true&lt;/b&gt;;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;&lt;b&gt;public final static class&lt;/b&gt; Value&amp;lt;VALUE &lt;b&gt;extends&lt;/b&gt; ValueReturn&amp;gt;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline3"&gt;&lt;b&gt;extends&lt;/b&gt; ServiceResponse&amp;lt;ErrorReturn, VALUE&amp;gt; {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;private&lt;/b&gt; &lt;b&gt;final&lt;/b&gt; VALUE value;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;public&lt;/b&gt; Value(VALUE value) {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline3"&gt;&lt;b&gt;this&lt;/b&gt;.value = value;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;public&lt;/b&gt; VALUE value() {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline3"&gt;&lt;b&gt;return&lt;/b&gt; value;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;public&lt;/b&gt; &lt;b&gt;boolean&lt;/b&gt; isError() {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline3"&gt;&lt;b&gt;return&lt;/b&gt; &lt;b&gt;false&lt;/b&gt;;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;To be fair the original code was not documented, like this snippet, and there were a few other things that were a little less elegant but not hugely so, also all code here has been changed as not to infringe on intellectual property and to ensure anonymity.  As a result of the architecture and project schedule the other developer who needed the class ended not using it and also due to the aggressive project schedule there was no other follow up such as finishing the documentation or writing tests, this was partially my fault.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;A few months later the architect needed this class and discovered our implementation he rewrote it as follows:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p class="codeline"&gt;&lt;b&gt;public&lt;/b&gt; &lt;b&gt;class&lt;/b&gt; ServiceResponse&amp;lt;ERROR &lt;b&gt;extends&lt;/b&gt; ErrorReturn,&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline3"&gt;VALUE &lt;b&gt;extends&lt;/b&gt; ValueReturn&amp;gt; {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;&lt;b&gt;private&lt;/b&gt; ERROR error;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;&lt;b&gt;private&lt;/b&gt; VALUE value;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;&lt;b&gt;private&lt;/b&gt; &lt;b&gt;boolean&lt;/b&gt; isError;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;&lt;b&gt;public&lt;/b&gt; ServiceResponse(ERROR error, VALUE value,&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline3"&gt;&lt;b&gt;boolean&lt;/b&gt; isError) {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;this&lt;/b&gt;.value = value;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;this&lt;/b&gt;.error = error;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;this&lt;/b&gt;.isError = isError;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;&lt;b&gt;public&lt;/b&gt; ERROR error() {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;return&lt;/b&gt; &lt;b&gt;this&lt;/b&gt;.error;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;&lt;b&gt;public&lt;/b&gt; VALUE value() {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;return&lt;/b&gt; &lt;b&gt;this&lt;/b&gt;.value;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;&lt;b&gt;public&lt;/b&gt; &lt;b&gt;boolean&lt;/b&gt; isError() {&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline2"&gt;&lt;b&gt;return&lt;/b&gt; isError;&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline1"&gt;}&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline"&gt;}&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Upon committing it he sent out an email to announce that he felt the original code was too complicated and he had simplified it to the above code.  I responded explaining that I felt that there were some issues with the instantiation of his new implementation and the real issue here was the lack of documentation.  I was shocked by his response in which he stuck to his argument that the new class was simpler to implement and didn’t require a lot of thought and we just need a wrapper class.  I confess I was initially perturbed by this as I felt that he was both wrong and taking a cargo cult attitude which was atypical for him, I later found out that he had been suffering through a bad cold.  Since I knew I would soon be leaving the project, I left it there even though I was pretty sure that his new design was significantly worse than the original.   I am intentionally omitting the details of the debate because I want to explore these in more detail momentarily.  &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Throughout my career I have all too often found myself in these types of debates, and the thing I find so frustrating about it is the lack of real ways to accurately analyze these types of situations and the lack of any formal structure to the arguments themselves, they frequently become as constructive as a political or religious debate.  So it got me thinking, these are two pretty simple classes, how can we constructively analyze this situation and perhaps establish dispassionately and objectively which solution is better and what opportunities can this exploration present in a larger context?&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;First let’s look at the problem in the context of the current prominent thinking, let’s start with &lt;a href="http://www.elegantcoding.com/2011/07/software-frameworks-resistance-isnt.html#ApiDesign"&gt;Joshua Bloch’s API ideas&lt;/a&gt;, which I have and will continue to reference.  Now remember the class in question is part of an API so these points are very relevant.  One point he makes is that an &lt;a href="http://www.elegantcoding.com/2011/07/software-frameworks-resistance-isnt.html#Characteristics"&gt;API&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;ul type=disc&gt;&lt;li&gt;&lt;i&gt;Easy to use, even without documentation &lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Hard to misuse &lt;/i&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;So let’s assume that we have the following two classes and references:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p&gt;ErrorReturn error;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;ValueReturn value;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The original design has the two correct ways of creating it, omitting for the moment creating each with null:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p class="codeline"&gt;&lt;b&gt;new&lt;/b&gt; ServiceResponse.Error&amp;lt;ErrorReturn&amp;gt;(error);&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline"&gt;&lt;b&gt;new&lt;/b&gt; ServiceResponse.Value&amp;lt;ValueReturn&amp;gt;(value);&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The new design has the following correct instantiations:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p class="codeline"&gt;&lt;b&gt;new&lt;/b&gt; ServiceResponse&amp;lt;ErrorReturn, ValueReturn&amp;gt;(error, &lt;b&gt;null&lt;/b&gt;, &lt;b&gt;false&lt;/b&gt;);&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline"&gt;&lt;b&gt;new&lt;/b&gt; ServiceResponse&amp;lt;ErrorReturn, ValueReturn&amp;gt;(&lt;b&gt;null&lt;/b&gt;, value, &lt;b&gt;true&lt;/b&gt;);&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Also it is pretty obvious that the new design opens up several other ways that this object can be created.  It seems that new design more easily allows value and error to be mixed up.  The new design puts the responsibility of setting the Boolean isError on the user which opens it up to possibly being set incorrectly.  This breaks the &lt;i&gt;hard to misuse&lt;/i&gt; rule.  In the old design it is an artificial value that created by a &lt;a href="http://en.wikipedia.org/wiki/Pure_function"&gt;pure function&lt;/a&gt;.   So from the API design perspective it seems that the original design is better.  &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Now another piece of conventional wisdom is the minimizing the number of parameters, in Clean Code Bob Martin talks about how you really shouldn’t have more than three parameters, well both instantiations fall under that, but by this logic is not the old design with one parameter then preferable to the new design with three?  &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Another possible pro argument for the original design is the use of the "&lt;a href="http://en.wikipedia.org/wiki/Disjoint_union"&gt;Disjoint Union&lt;/a&gt;" &lt;a href="http://www.scala-lang.org/api/current/scala/Either.html"&gt;Either pattern&lt;/a&gt;, now this is not a &lt;a href="http://en.wikipedia.org/wiki/Design_Patterns"&gt;GOF pattern&lt;/a&gt; but it is a pattern, perhaps an even more mathematical pattern, but regardless it is a specific pattern with precedence.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;So that’s three pro arguments for the original design based on the current conventional software design wisdom promulgated by the leading software engineers of the field. So the original design is probably better.  Unfortunately I have found that even these arguments can be thwarted by the most recalcitrant &lt;a href="http://www.elegantcoding.com/2011/10/confederacy-of-cargo-cult-coders.html"&gt;cargo cult coder&lt;/a&gt; who doesn’t read and will always invoke arguments like "it’s too complex, it’s too abstract". &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;So I started to think, how could one look at this situation more analytically?  Going back to Joshua Blocks API talk, at some point and I don’t have this documented anywhere, he makes reference to an &lt;i&gt;object’s state space&lt;/i&gt;, but he doesn’t go into detail about the concept.  This got me thinking, in this case we could pretty easily enumerate, at least at high level, the state space for each object and then compare them.  I am not sure if this is a known technique, I wouldn’t be surprised if someone has thought of or done this before.  In this case I am going to refer to this as "Enumerative Object State Space Analysis" or just "Object State Space Analysis" for lack of a better name.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;So for this exercise we will interest ourselves in the possible values of a value or null for each parameter, where the error value is an instance of ErrorReturn and the value parameter is an instance of ValueReturn or true or false for the Boolean parameters, this is the following sets: {&amp;lt;Error&amp;gt;, null}, {&amp;lt;Value&amp;gt;, null}, and {true, false}.  &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;For the old design the possible instantiations are:&lt;/p&gt;&lt;br /&gt;
&lt;div class="source-code"&gt;&lt;p class="codeline"&gt;&lt;b&gt;new&lt;/b&gt; ServiceResponse.Error&amp;lt;ErrorReturn&amp;gt;(error);&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline"&gt;&lt;b&gt;new&lt;/b&gt; ServiceResponse.Value&amp;lt;ValueReturn&amp;gt;(value);&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline"&gt;&lt;b&gt;new&lt;/b&gt; ServiceResponse.Error&amp;lt;ErrorReturn&amp;gt;(&lt;b&gt;null&lt;/b&gt;);&lt;/p&gt;&lt;br /&gt;
&lt;p class="codeline"&gt;&lt;b&gt;new&lt;/b&gt; ServiceResponse.Value&amp;lt;ValueReturn&amp;gt;(&lt;b&gt;null&lt;/b&gt;);&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;There are 2 possible Error instantiations and 2 possible Value instantiations leading to an object state space of 2 + 2 = 4 possible states, this is an application of the &lt;a href="http://en.wikipedia.org/wiki/Rule_of_sum"&gt;Sum Rule&lt;/a&gt;.  The new class has 2 possible values per constructor parameter, similarly from the &lt;a href="http://en.wikipedia.org/wiki/Rule_of_product"&gt;Product Rule&lt;/a&gt; of &lt;a href="http://en.wikipedia.org/wiki/Combinatorics"&gt;combinatorics&lt;/a&gt; we can calculate that this leads to 2*2*2 = 8 possible states in the object state space. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;We can enumerate (list them out) the states for the original class as follows:&lt;/p&gt;&lt;br /&gt;
&lt;table class=MsoTableGrid border="1" cellspacing="0" cellpadding="0" &gt;&lt;tr&gt;     &lt;td class="comb-left" width="120"&gt;Object State&lt;/td&gt;     &lt;td class="comb-left" width="120"&gt;Comment&lt;/td&gt;     &lt;td class="comb-left"&gt;Correctness Status&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="comb-left" width="120"&gt;{Value, false}&lt;/td&gt;     &lt;td class="comb" width="120"&gt;Return state for successful operation &lt;/td&gt;     &lt;td class="comb"&gt;Correct intended state&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="comb-left" width="120"&gt;{Error, true}&lt;/td&gt;     &lt;td class="comb" width="120"&gt;Return state for operation with an error.&lt;/td&gt;     &lt;td class="comb"&gt;Correct intended state&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="comb-left" width="120"&gt;{null, false}&lt;/td&gt;     &lt;td class="comb" width="120"&gt;Return for a successful operation with no return value&lt;/td&gt;     &lt;td class="comb"&gt;State is a side effect of design, allows null, could be correct or   could be considered a degenerate state.&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="comb-left" width="120"&gt;{null, true}&lt;/td&gt;     &lt;td class="comb" width="120"&gt;Return for an operation with an error with no information &lt;/td&gt;     &lt;td class="comb"&gt;State is a side effect of design, allows null, could be correct or   could be considered a degenerate state.&lt;/td&gt; &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;p&gt;We can enumerate the states for the new class as follows:&lt;/p&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;&lt;tr&gt;     &lt;td class="comb-left" width="120"&gt;Object State&lt;/td&gt;     &lt;td class="comb-left" width="120"&gt;Comment&lt;/td&gt;     &lt;td class="comb-left"&gt;Correctness Status&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="comb-left" width="120"&gt;{null, Value, false}&lt;/td&gt;     &lt;td class="comb" width="120"&gt;Return state for successful operation&lt;/td&gt;     &lt;td class="comb"&gt;Correct intended state&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="comb-left" width="120"&gt;{Error, null, true}&lt;/td&gt;     &lt;td class="comb" width="120"&gt;Return state for operation with an error.&lt;/td&gt;     &lt;td class="comb"&gt;Correct intended state&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="comb-left" width="120"&gt;{null, null, false}&lt;/td&gt;     &lt;td class="comb" width="120"&gt;Return for a successful operation with no return value&lt;/td&gt;     &lt;td class="comb"&gt;State is a side effect of design, allows null, could be correct or could be considered a degenerate state.&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="comb-left" width="120"&gt;{null, null, true}&lt;/td&gt;     &lt;td class="comb" width="120"&gt;Return for an operation with an error with no information&lt;/td&gt;     &lt;td class="comb"&gt;State is a side effect of design, allows null, could be correct or could be considered a degenerate state.&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="comb-left" width="120"&gt;{Error, Value, false}&lt;/td&gt;     &lt;td class="comb" width="120"&gt;Return state for successful operation&lt;/td&gt;     &lt;td class="comb"&gt;State is correct from a usage standpoint but ambiguous from a programmer maintenance standpoint is this what was intended or is it reversed?&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="comb-left" width="120"&gt;{Error, Value, true}&lt;/td&gt;     &lt;td class="comb" width="120"&gt;Return state for operation with an error.&lt;/td&gt;     &lt;td class="comb"&gt;State is correct from a usage standpoint but ambiguous from a programmer maintenance standpoint is this what was intended or is it reversed?&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="comb-left" width="120"&gt;{null, Value, true}&lt;/td&gt;     &lt;td class="comb" width="120"&gt;Incorrect Usage&lt;/td&gt;     &lt;td class="comb"&gt;This is incorrect but the design allows this state to exist.&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td class="comb-left" width="120"&gt;{Error, null, false}&lt;/td&gt;     &lt;td class="comb" width="120"&gt;Incorrect Usage&lt;/td&gt;     &lt;td class="comb"&gt;This is incorrect but the design allows this state to exist.&lt;/td&gt; &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;Assuming a &lt;a href="http://en.wikipedia.org/wiki/Uniform_distribution_(discrete)"&gt;uniform distribution&lt;/a&gt; the probability for each state in the original class is 25% and 12.5% in the new class, this means that the first design has 50% correct states and 50% null states.  The new design has 25% correct states, 25% null states, 25% ambiguous states, and 25% incorrect states. Of course a uniform distribution would probably not be the case as the correct usage would always be more likely and the incorrect usage would be the most unlikely.  Still, based on this analysis I am inclined to further conclude that the original design is better, perhaps even definitively so as the old design has no incorrect states and the expanded state space, which is twice as large, exponentially larger, also increases the complexity.  &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Another possibility would be to eliminate the setting of the Boolean flag on the new design and allow it to be determined by a pure function as in the original design, but that opens up problems with respect to the ambiguous states that would exist.  In reflecting I also realized that the one of ambiguous states of the new design allow a state {Error, Value, false} which might be construed as success with information, which leads me to think that both designs are lacking and it might be better to always return an object that contains the value and some type of status object that allows error or success with info.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Now I know this is a lot and I am probably over thinking this, but I am treating this as an experiment:  Is it possible to come up with more analytical approaches using &lt;a href="http://en.wikipedia.org/wiki/Enumeration"&gt;Enumerative&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Combinatorics"&gt;Combinatorial&lt;/a&gt; techniques to guide object design or other aspects of software design in a practical way?&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/_iz_xV6YEe8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/_iz_xV6YEe8/software-design-debate-and-futility-of.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-psyxaFKWwjk/T1VxijBhRWI/AAAAAAAAAcE/isRT6luvL8g/s72-c/IMG_2026.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/03/software-design-debate-and-futility-of.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-2049190464708718480</guid><pubDate>Sat, 25 Feb 2012 17:57:00 +0000</pubDate><atom:updated>2012-06-13T09:46:40.302-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Math</category><category domain="http://www.blogger.com/atom/ns#">Number Theory</category><category domain="http://www.blogger.com/atom/ns#">Agile</category><category domain="http://www.blogger.com/atom/ns#">Fibonacci</category><title>Fibonacci: The Math of Agile</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-W-cZFF01YC0/T0kZnP7vd3I/AAAAAAAAAYs/p8AmOAizakY/s1600/fib-spiral.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="225" width="400" src="http://3.bp.blogspot.com/-W-cZFF01YC0/T0kZnP7vd3I/AAAAAAAAAYs/p8AmOAizakY/s400/fib-spiral.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;!--Fibonacci: The Math of Agile--&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Planning_poker"&gt;Agile planning poker&lt;/a&gt;&lt;sup&gt;1&lt;/sup&gt; uses the &lt;a href="http://en.wikipedia.org/wiki/Fibonacci_sequence"&gt;Fibonacci sequence&lt;/a&gt; or in some cases a bastardized version of it.  I do not know the exact reason that the series was chosen, I do know the intent is that there is a standard set of numbers and using these deters the player from the temptation of using false precision, like a value of 10.5 for example.  Also it captures growth so each next number is a "unit" of growth larger than the last.  I suspect that the sequence of powers of two (1,2,4,8,16,32,64...) would also work, and might be more apropos to the computer industry, but these two sequences are similar in that they both increase by a constant factor, each subsequent power of two is two times larger and in the Fibonacci sequence each term is roughly 1.618... larger than the previous term, also each has a closed form exponential formula for each term 2&lt;sup&gt;n&lt;/sup&gt; or for Fibonacci sequence it's Binet’s Formula, see below.   I don’t know if the Fibonacci sequence is the right way to go, but it seems to work and it is fairly prevalent in nature and art so it’s probably not a bad choice.  I confess that while this in one of my math of programming series, I am using it primarily as an excuse to write a post about some interesting results relating to the Fibonacci sequence and the &lt;a href="http://en.wikipedia.org/wiki/Golden_ratio"&gt;Golden Mean&lt;/a&gt;, so if you are only interested in Agile you may want to treat this as a short post and stop here, but I encourage you to read on, the math is mostly high school level and it really is interesting. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The Fibonacci sequence is generally attributed to a man, &lt;a href="http://en.wikipedia.org/wiki/Leonardo_of_Pisa"&gt;Leonardo Pisano Bigollo&lt;/a&gt; who went by Fibonacci and did not actually discover the sequence, it was known about five hundred years earlier in the tenth century by &lt;a href="http://en.wikipedia.org/wiki/Pingala"&gt;Pingala&lt;/a&gt; and it was probably known much earlier.  Ironically Fibonacci’s greatest mathematical contribution was the introduction of &lt;a href="http://en.wikipedia.org/wiki/Hindu-Arabic_numeral_system"&gt;Hindu-Arabic Numeral System&lt;/a&gt; to Europe, just imagine trying to do multiplication and fractions with &lt;a href="http://en.wikipedia.org/wiki/Roman_numerals"&gt;Roman numerals&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The Fibonacci sequence is what is known as a &lt;a href="http://en.wikipedia.org/wiki/Recurrence_relation"&gt;recurrence relation&lt;/a&gt; or &lt;a href="http://mathworld.wolfram.com/RecursiveSequence.html"&gt;recursive sequence&lt;/a&gt; each term is defined as the sum of the two previous terms where the first two terms, which are the generator or seed values F&lt;sub&gt;0&lt;/sub&gt; = 0 and F&lt;sub&gt;1&lt;/sub&gt; = 1, the formula is:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-_20YNn17BXE/T0kaFzH9JHI/AAAAAAAAAZE/WsHIqG5xmBg/s1600/fib-def.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="14" width="133" src="http://4.bp.blogspot.com/-_20YNn17BXE/T0kaFzH9JHI/AAAAAAAAAZE/WsHIqG5xmBg/s400/fib-def.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;It can alternatively be written as:&lt;/p&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Z2VODUo3RR0/T0kZra1PzFI/AAAAAAAAAY4/c8HofRG87dM/s1600/fib-def2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="16" width="133" src="http://4.bp.blogspot.com/-Z2VODUo3RR0/T0kZra1PzFI/AAAAAAAAAY4/c8HofRG87dM/s400/fib-def2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;This form will be more useful to us in a moment.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The &lt;a href="http://oeis.org/A000045"&gt;sequence&lt;/a&gt; is:&lt;/p&gt;&lt;p&gt;0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393,...&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The Fibonacci sequence has a very interesting relation with a very interesting number known as the Golden Mean which is sometimes referred to as phi and has the following value:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-suT9IGtPkOA/T0kasr8V19I/AAAAAAAAAZQ/usrbbD3PdLo/s1600/phi.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="37" width="85" src="http://3.bp.blogspot.com/-suT9IGtPkOA/T0kasr8V19I/AAAAAAAAAZQ/usrbbD3PdLo/s400/phi.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;An irrational number that is approximately: 1.6180339887498948482045868343656...&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The ratio of a Fibonacci number divided by the previous number in the sequence eventually converges to phi, the first few ratios are:&lt;/p&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;table border="0"&gt;&lt;tr&gt;&lt;td align="left"&gt;3/2   &lt;/td&gt;&lt;td align="left"&gt;=&lt;/td&gt;&lt;td align="left"&gt; 1.5&lt;/td&gt;
&lt;tr&gt;
&lt;tr&gt;&lt;td align="left"&gt;5/3   &lt;/td&gt;&lt;td align="left"&gt;=&lt;/td&gt;&lt;td align="left"&gt; 1.666666...&lt;/td&gt;
&lt;tr&gt;
&lt;tr&gt;&lt;td align="left"&gt;8/5   &lt;/td&gt;&lt;td align="left"&gt;=&lt;/td&gt;&lt;td align="left"&gt; 1.6&lt;/td&gt;
&lt;tr&gt;
&lt;tr&gt;&lt;td align="left"&gt;13/8  &lt;/td&gt;&lt;td align="left"&gt;=&lt;/td&gt;&lt;td align="left"&gt; 1.625&lt;/td&gt;
&lt;tr&gt;
&lt;tr&gt;&lt;td align="left"&gt;21/13 &lt;/td&gt;&lt;td align="left"&gt;=&lt;/td&gt;&lt;td align="left"&gt; 1.615384...&lt;/td&gt;
&lt;tr&gt;
&lt;tr&gt;&lt;td align="left"&gt;34/21 &lt;/td&gt;&lt;td align="left"&gt;=&lt;/td&gt;&lt;td align="left"&gt; 1.619047...&lt;/td&gt;
&lt;tr&gt;
&lt;tr&gt;&lt;td align="left"&gt;55/34 &lt;/td&gt;&lt;td align="left"&gt;=&lt;/td&gt;&lt;td align="left"&gt; 1.617647...&lt;/td&gt;
&lt;tr&gt;
&lt;tr&gt;&lt;td align="left"&gt;89/55 &lt;/td&gt;&lt;td align="left"&gt;=&lt;/td&gt;&lt;td align="left"&gt; 1.6181818...&lt;/td&gt;
&lt;tr&gt; &lt;/table&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;As you can see it is already heading there.  It is interesting that a ratio which is in the set of &lt;a href="http://en.wikipedia.org/wiki/Rational_number"&gt;rational numbers&lt;/a&gt; converges to an &lt;a href="http://en.wikipedia.org/wiki/Algebraic_number"&gt;algebraic&lt;/a&gt; &lt;a href="http://en.wikipedia.org/wiki/Irrational_number"&gt;irrational number&lt;/a&gt;. The following equation describes this relationship, the Limit of consecutive quotients:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-zTuGsUR3xcw/T0ka5L3cE4I/AAAAAAAAAZc/Ch5LrnA_rz0/s1600/fib-lim1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="37" width="109" src="http://4.bp.blogspot.com/-zTuGsUR3xcw/T0ka5L3cE4I/AAAAAAAAAZc/Ch5LrnA_rz0/s400/fib-lim1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;Additionally the following is true:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-r_AELtA7pQo/T0ka-HrC45I/AAAAAAAAAZo/SMQwA6CpJAk/s1600/fib-lim2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="38" width="111" src="http://2.bp.blogspot.com/-r_AELtA7pQo/T0ka-HrC45I/AAAAAAAAAZo/SMQwA6CpJAk/s400/fib-lim2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;If we take the following formula:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Z2VODUo3RR0/T0kZra1PzFI/AAAAAAAAAY4/c8HofRG87dM/s1600/fib-def2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="16" width="133" src="http://4.bp.blogspot.com/-Z2VODUo3RR0/T0kZra1PzFI/AAAAAAAAAY4/c8HofRG87dM/s400/fib-def2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;And divide it by F&lt;sub&gt;n&lt;/sub&gt; we get:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-aOl13y2GKEs/T0kbOHbUNOI/AAAAAAAAAZ0/qTdmS30GkcE/s1600/fib-def-div.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="37" width="129" src="http://4.bp.blogspot.com/-aOl13y2GKEs/T0kbOHbUNOI/AAAAAAAAAZ0/qTdmS30GkcE/s400/fib-def-div.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;We then take the limit as n goes to infinity, replacing the terms using the two limit equations from above:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/--N_v3WS-kc8/T0kbUEMaUxI/AAAAAAAAAaA/v3x8fcKHUvw/s1600/phi-eq1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="38" width="73" src="http://2.bp.blogspot.com/--N_v3WS-kc8/T0kbUEMaUxI/AAAAAAAAAaA/v3x8fcKHUvw/s400/phi-eq1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;And if we multiply by phi:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/--apja114bak/T0kbZEUQMtI/AAAAAAAAAaM/m9Sg6TtM5a8/s1600/phi-eq2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="19" width="77" src="http://4.bp.blogspot.com/--apja114bak/T0kbZEUQMtI/AAAAAAAAAaM/m9Sg6TtM5a8/s400/phi-eq2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Solving for zero gives us:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-b8nfbtVILpM/T0kbeVJkRvI/AAAAAAAAAaY/zRxwRW3yihQ/s1600/phi-eq3.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="19" width="106" src="http://1.bp.blogspot.com/-b8nfbtVILpM/T0kbeVJkRvI/AAAAAAAAAaY/zRxwRW3yihQ/s400/phi-eq3.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Using the &lt;a href="http://en.wikipedia.org/wiki/Quadratic_equation"&gt;quadratic equation&lt;/a&gt; we get the following two roots (conjugates):&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-wEps557o4Mg/T0kbmAFwuRI/AAAAAAAAAak/t0mzi4BuqVU/s1600/phi-tau.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="37" width="85" src="http://4.bp.blogspot.com/-wEps557o4Mg/T0kbmAFwuRI/AAAAAAAAAak/t0mzi4BuqVU/s400/phi-tau.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;This is phi and its &lt;a href="http://en.wikipedia.org/wiki/Conjugate_(algebra)"&gt;conjugate&lt;/a&gt;, which we will call tau:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-CXkE6gkNJWU/T0kbvUXENjI/AAAAAAAAAaw/gkYhIAz2yI4/s1600/phi.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="37" width="85" src="http://1.bp.blogspot.com/-CXkE6gkNJWU/T0kbvUXENjI/AAAAAAAAAaw/gkYhIAz2yI4/s400/phi.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-wYskU2oLWWk/T0kbyybCF5I/AAAAAAAAAa8/5fxJZhoO5Io/s1600/tau.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="37" width="85" src="http://1.bp.blogspot.com/-wYskU2oLWWk/T0kbyybCF5I/AAAAAAAAAa8/5fxJZhoO5Io/s400/tau.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Now that we have defined phi and tau we can describe Binet’s formula, mentioned above, which is an exponential form closed formula:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-tiztJpnrrqg/T0kb_PXG0tI/AAAAAAAAAbI/0C9fzP-0fDY/s1600/binet-fib-closed.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="39" width="102" src="http://2.bp.blogspot.com/-tiztJpnrrqg/T0kb_PXG0tI/AAAAAAAAAbI/0C9fzP-0fDY/s400/binet-fib-closed.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Binet’s formula is an easy way to compute Fibonacci Sequence values without having to calculate all of the values prior to the value you wish to calculate.  &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Additionally there is an interesting matrix based calculation:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-5CORx5WcNfc/T0kcFAnX7KI/AAAAAAAAAbU/X8DK2vEzsaU/s1600/fib-mat.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="43" width="215" src="http://3.bp.blogspot.com/-5CORx5WcNfc/T0kcFAnX7KI/AAAAAAAAAbU/X8DK2vEzsaU/s400/fib-mat.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The above matrix raised to the nth power gives the above matrix of Fibonacci numbers, the first few are:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-rUUstxmJTMQ/T0kcJCI8rfI/AAAAAAAAAbg/X9BMbWcEgtE/s1600/fib-mat-ex.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="191" width="156" src="http://4.bp.blogspot.com/-rUUstxmJTMQ/T0kcJCI8rfI/AAAAAAAAAbg/X9BMbWcEgtE/s400/fib-mat-ex.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The &lt;a href="http://en.wikipedia.org/wiki/Determinant"&gt;determinant&lt;/a&gt; of this matrix is (-1)&lt;sup&gt;n&lt;/sup&gt; which is described by &lt;a href="http://en.wikipedia.org/wiki/Cassini%27s_identity"&gt;Cassini’s Identity&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-J2rdut_M7PI/T0kdbOW2YCI/AAAAAAAAAb4/zgHb5CPrszg/s1600/Cassinis%2Bidentity.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="19" width="196" src="http://2.bp.blogspot.com/-J2rdut_M7PI/T0kdbOW2YCI/AAAAAAAAAb4/zgHb5CPrszg/s400/Cassinis%2Bidentity.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The Fibonacci sequence and the Golden mean have many interesting identities and relationships with other mathematical disciplines and natural phenomena, for example there is the famous relation rabbit breeding, it relates to bee ancestry, the packing of seeds in flowers, and other plant growth proportions. The Fibonacci sequence occurs in the shallow diagonals of &lt;a href="http://en.wikipedia.org/wiki/Pascal's_triangle"&gt;Pascal’s Triangle&lt;/a&gt;, it relates to &lt;a href="http://mathworld.wolfram.com/PythagoreanTriple.html"&gt;Pythagorean Triples&lt;/a&gt;. It relates to the similar &lt;a href="http://en.wikipedia.org/wiki/Lucas_number"&gt;Lucas Sequence &lt;/a&gt;, the Fibonacci Spiral form above which is a &lt;a href="http://en.wikipedia.org/wiki/Logarithmic_spiral"&gt;Logarithmic Spiral&lt;/a&gt; and the list goes on, a lot of this can be found on the previously linked &lt;a href="http://en.wikipedia.org/wiki/Fibonacci_number"&gt;Wikipedia Page&lt;/a&gt; and this &lt;a href="http://www.bbc.co.uk/programmes/b008ct2j"&gt;BBC radio program&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt; &lt;a href="http://renaissancesoftware.net/papers/14-papers/44-planing-poker.html"&gt;http://renaissancesoftware.net/papers/14-papers/44-planing-poker.html&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/UZVFTXhu_j4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/UZVFTXhu_j4/fibonacci-math-of-agile.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-W-cZFF01YC0/T0kZnP7vd3I/AAAAAAAAAYs/p8AmOAizakY/s72-c/fib-spiral.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/02/fibonacci-math-of-agile.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-8017777834717373551</guid><pubDate>Mon, 20 Feb 2012 18:39:00 +0000</pubDate><atom:updated>2012-05-06T12:16:28.045-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Rant</category><category domain="http://www.blogger.com/atom/ns#">Software Development Teams</category><title>Is your Team LCD (Lowest Common Denominator)?</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-8yAfoFilLNY/T0KS7-O3RJI/AAAAAAAAAYI/aMA3BMLiP8E/s1600/calder.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="280" src="http://3.bp.blogspot.com/-8yAfoFilLNY/T0KS7-O3RJI/AAAAAAAAAYI/aMA3BMLiP8E/s400/calder.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;!--Is your Team LCD (Lowest Common Denominator)?--&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;On some of my previous projects I have felt that the teams became severely dysfunctional and as a result they cater to the lowest common denominator of the team.  This was often a result of a lack of both technical and overall leadership.  In these cases schisms formed in the team I was usually at the center of one side advocating good design practices, a high degree of control and a framework approach to reuse.  I should add here that while I am very passionate about trying to build quality software and I try to be as egoless as possible.  Sadly my &lt;i&gt;opponents&lt;/i&gt; in these situations were the &lt;a href="http://www.elegantcoding.com/2011/10/confederacy-of-cargo-cult-coders.html"&gt;type of programmers&lt;/a&gt; that did not read and in some cases they were woefully ignorant of basic software design concepts like the &lt;a href="http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)"&gt;Solid principles&lt;/a&gt; and &lt;a href="http://sourcemaking.com/design_patterns"&gt;design patterns&lt;/a&gt;.  In one case we had several “senior” java developers who didn’t understand &lt;a href="http://en.wikipedia.org/wiki/Generics_in_Java"&gt;generics&lt;/a&gt; or even &lt;a href="http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)"&gt;inheritance&lt;/a&gt;, that situation really bordered on the absurd.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;In these situations I have often felt that these developers were essentially being very selfish, in some cases it was that the developers wanted a wild west chaotic approach to software development so there were no constraints and they were free to tinker with new libraries and frameworks, what I like to call &lt;a href="http://www.elegantcoding.com/2011/05/driven-development.html#RDD"&gt;Resume Driven Development&lt;/a&gt;. In other cases it was that they didn’t want to have to learn anything new or challenging, and in some cases it seemed to be pure ego driven stubbornness or inferiority complex driven compensatory behavior.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Regardless of the causes of the dysfunctional nature of the team it always resulted in the dominance of the Lowest common denominator, this can applies to technical level as well professional/maturity level, often it’s both.  The lack of leadership and a fractured team often had negative effects on morale especially for the better developers.  It often created an environment that produced suboptimal architecture and code.  Consensus was often impossible to achieve and code duplication was rampant sometimes deliberate.  Naturally code reviews were either not conducted or if they were they were done in a perfunctory way so that any feedback was completely disregarded.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The worst part of the LCD team is the lack of ability to have open objective criticism.  Criticism is hard to take but anyone engaging in any activity, especially a creative one, in which they wish to improve can greatly benefit from it, this is described in detail in a &lt;a href="http://rob.by/2011/responding-to-criticism/"&gt;great essay by Bobby Grossman&lt;/a&gt;.  To parallel that essay we had one person on the team who if you even hinted at being critical he immediately became super defensive.  He was a terrible programmer and will probably never improve.  To engineer a good system you need to have a constructive and positive way to deal with mistakes that occur in code, architecture and process. Discordance on the team causes mistakes to be viewed as validation of an opposing viewpoint.  It’s an extremely counterproductive and demoralizing environment.  It leads to less communication as many people will avoid the conflict, and in one case I felt that I had achieved a level of fatigue and I just stopped caring, I bailed shortly after.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The LCD team illustrates why so many software projects have problems, in the above case the project failed after I left, in part due to the dysfunctional nature of the team.  My goal here is not harp on the negative but to use this as &lt;i&gt;&lt;a href="http://en.wikipedia.org/wiki/Negative_space"&gt;negative space&lt;/a&gt;&lt;/i&gt; for what you really want.  The opposite of this is a team that aspires to be great and to be more than the sum of its parts. I know it sounds like a cliché but I really believe a good team is one were the stronger developers help the weaker and less experienced developers become better because everyone wants to.  You want a team that can openly discuss and criticize aspects of the system and discover and fix mistakes early.  I think this can happen with a team of professionals who can put their ego aside to do good work and a strong leader who trusts their team and leads with fairness and wisdom and who is open to hearing input from the team but willing to make firm decisions.   Human nature in most cases probably precludes such a utopian software team, I think the goal here is to optimize and aspire to it.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/9hsPJos5rE4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/9hsPJos5rE4/is-your-team-lcd-lowest-common.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-8yAfoFilLNY/T0KS7-O3RJI/AAAAAAAAAYI/aMA3BMLiP8E/s72-c/calder.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/02/is-your-team-lcd-lowest-common.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-7134691662677050483</guid><pubDate>Sun, 05 Feb 2012 22:42:00 +0000</pubDate><atom:updated>2012-05-06T12:03:03.394-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Software Complexity</category><category domain="http://www.blogger.com/atom/ns#">Software Engineering</category><category domain="http://www.blogger.com/atom/ns#">Code Reuse</category><category domain="http://www.blogger.com/atom/ns#">Information Entropy</category><title>The Software Reuse Complexity Curve</title><description>&lt;!--The Software Reuse Complexity Curve--&gt;&lt;p&gt;I have come to the conclusion that Complexity and Reuse have a nonlinear relationship that has a parabolic shape, shown below, Complexity increases on the Y axis and reuse increases on the X axis.  Code complexity is high both with very low reuse and very high reuse forming a &lt;a href="http://en.wikipedia.org/wiki/Maxima_and_minima"&gt;minima&lt;/a&gt; which might be viewed as an &lt;a href="http://en.wikipedia.org/wiki/Mathematical_optimization"&gt;optimization&lt;/a&gt; point for reusability, now remember this is a very simple two dimensional graph, a real optimization scenario for this type of problem may include many dimensions and probably would not have a nice clearly defined single minima.&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-nS0Po1Jlg98/Ty7mj9aD3uI/AAAAAAAAAX8/tzP0816pMoo/s1600/reuse-curve.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="400" src="http://3.bp.blogspot.com/-nS0Po1Jlg98/Ty7mj9aD3uI/AAAAAAAAAX8/tzP0816pMoo/s400/reuse-curve.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Scenario #1 Low Reuse&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;In a low reuse situation everything that could have been implemented using reusability is duplicated and may also be implemented inconsistently, so the code base will be larger which would require a maintainer to learn and know more code, also since there will be variations of varying degree between the similar components the maintainer would have to be constantly aware of these differences, which might be subtle, one might even find them confusing at times. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;As we have previously seen reuse relates to &lt;a href="http://www.elegantcoding.com/2011/07/software-frameworks-resistance-isnt.html"&gt;entropy&lt;/a&gt;, so a low reuse system would have a large random, “uncompressed” codebase, which has high entropy, I have seen this type of system in my career and it is something I hate to work on. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Skill vs. Complexity&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Before I go to the opposite end of the spectrum, which is probably more interesting, and perhaps more speculative on my part, I’d like to talk about the relationship of code complexity to maintainer developer skill.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;I believe, and this really shouldn’t be a stretch, that there are some types of complex code that require certain higher level proficiencies and theoretical knowledge, an obvious choice is parsers and compiler construction.  A developer who works in this area needs to have a good understanding of a number disciplines, which include but are not limited to: &lt;a href="http://en.wikipedia.org/wiki/Formal_language"&gt;Formal Language Theory&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Automata_theory"&gt;Automata Theory&lt;/a&gt; and possibly some Abstract Algebra, which sadly many developers lack.  If you had a project that had components that are any type of compiler or parser and needed someone to create and subsequently work on the maintenance of the code, they would need to know these things, they would need to understand this complexity in an organized theoretical way.  The alternative would be an ad hoc approach to solving these problems which would probably yield significant complexity issues of its own.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;These types of things can be seen at simpler scale, a system that makes use of state machines or heavy use of regular expressions will exhibit more compact and more complex code.  The maintainers have to have a skill level to deal with this more complex approach, sadly not all &lt;a href="http://www.elegantcoding.com/2011/10/confederacy-of-cargo-cult-coders.html"&gt;developers&lt;/a&gt; do.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Now you can probably find numerous code bases where these types of approaches and others were not used where they should have been, these codebases will be larger and will require a case by case effort to learn something that could have been “compressed” and generalized  with better theoretical understanding.  It’s a trade off if you cannot hire or retain people who have the advanced skills an advanced codebase can also be a maintenance liability.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Scenario #2 high reuse&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Now let’s create a hypothetical example, say we have a system that has many similar components and a brilliant programmer manages to distill this complexity into compact highly reusable code.  The problem is that our brilliant programmer is the only one who can really understand it.  Ideas similar to this are pondered by John Cook in his post &amp;quot;&lt;a href="http://www.johndcook.com/blog/2012/01/09/holographic-source-code/"&gt;Holographic Code&lt;/a&gt;&amp;quot;.  Now it might be the case that it code that is really only understandable to our brilliant programmer, or he may be the only one in the organization with that level of proficiency, also in this case we will assume that complexity was not artificially introduced, i.e. not unnecessary complexity, which is also a real problem that arises in software systems.  Also we will assume that we know that a less complex solution that is more verbose with less reuse exists, and in fact the solution of the maintainer developer might be to completely rewrite it in a less complex fashion.&lt;/p&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;As we have previously &lt;a href="http://www.elegantcoding.com/2011/07/software-frameworks-resistance-isnt.html#Entropy"&gt;seen&lt;/a&gt;, the complete compressibility of a code base can never be achieved which relates heavily to aspects of both &lt;a href="http://en.wikipedia.org/wiki/Information_theory"&gt;Information Theory&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Algorithmic_information_theory"&gt;Algorithmic Information theory&lt;/a&gt; this results in  diminishing returns in terms of shrinking an algorithm or codebase.  My speculation here, based on observation, is that as a codebase is "compressed" its complexity increases as shown above.  Essentially you need to be increasingly clever to continue to increase reuse.  Now some of these reuse complexity issues may be due to our lack of understanding of complexity in relation to software construction.  It is feasible that things that we find hard to gain reuse with today may be easier in the future with advances in this understanding.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Another idea from the research covered in my previous post is that different domains exhibit different degrees of Favorability/Resistance to reuse. I would also suspect that the types of reusable components would also vary across different domains this makes me think that perhaps in the future reusability in different domains can be guided both qualitatively and quantitatively by either empirical or theoretical means or both. This means that you might have fore-knowledge of the &amp;quot;compressibility&amp;quot; of a &amp;quot;domain solution&amp;quot; and then you would be able to guide the development effort appropriately.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;I feel the ideas here are a step back from a possible absolutist thinking to reuse.  Reuse like any important approach in software, for example test coverage, which can also exhibit diminishing returns, needs to be tempered and viewed as an optimization as to the extent of its practice.  In many respects that’s what good engineering is, working within constraints and optimizing your outcome within those constraints.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/KloltCaFaCM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/KloltCaFaCM/software-reuse-complexity-curve.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-nS0Po1Jlg98/Ty7mj9aD3uI/AAAAAAAAAX8/tzP0816pMoo/s72-c/reuse-curve.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/02/software-reuse-complexity-curve.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-2570985781047552654</guid><pubDate>Sun, 29 Jan 2012 23:47:00 +0000</pubDate><atom:updated>2012-05-06T12:04:10.335-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Math</category><category domain="http://www.blogger.com/atom/ns#">Abstract Algebra</category><category domain="http://www.blogger.com/atom/ns#">Logic</category><category domain="http://www.blogger.com/atom/ns#">Group Theory</category><title>Abstract Algebra: The Logic of Odd and Even</title><description>&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-LPcyuClBIcQ/TyXXBKatGHI/AAAAAAAAAXY/YI78XK6nuHQ/s1600/squid.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="300" src="http://1.bp.blogspot.com/-LPcyuClBIcQ/TyXXBKatGHI/AAAAAAAAAXY/YI78XK6nuHQ/s400/squid.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;!--Abstract Algebra: The Logic of Odd and Even--&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;&lt;a href="http://www.stevenstrogatz.com/"&gt;Steven Strogatz&lt;/a&gt; wrote a series of math related articles on the New York Times website one of which is called "&lt;a href="http://opinionator.blogs.nytimes.com/2010/02/07/rock-groups/"&gt;Rock Groups"&lt;/a&gt; where he looks at adding integers visually and with respect to odd and even and ventures into the territory of triangles and squares and visually portrays the closed formula for computing triangular numbers. My previous post on &lt;a href="http://www.elegantcoding.com/2011/07/triangles-triangular-numbers-and.html"&gt;triangular numbers&lt;/a&gt; in some ways parallels his "Rock Groups" article at least in respect to the visual portrayal of triangular numbers.  This post also parallels ideas in that article, in contrast his observations are geometric, these are algebraic observations about, among other things, adding and multiplying even and odd numbers, which work as follows:&lt;/p&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="4"&gt;&lt;tr&gt;   &lt;td width="221" valign="top" align="center"&gt;&lt;p&gt;+&lt;/p&gt;&lt;/td&gt;   &lt;td width="282" valign="top" align="center"&gt;&lt;p&gt;*&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="221" valign="top" align="center"&gt;&lt;p&gt;Even + Even = Even&lt;/p&gt;&lt;/td&gt;   &lt;td width="282" valign="top" align="center"&gt;&lt;p&gt;Even * Even = Even&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="221" valign="top" align="center"&gt;&lt;p&gt;Odd + Even = Odd&lt;/p&gt;&lt;/td&gt;   &lt;td width="282" valign="top" align="center"&gt;&lt;p&gt;Odd * Even = Even&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="221" valign="top" align="center"&gt;&lt;p&gt;Odd + Odd = Even&lt;/p&gt;&lt;/td&gt;   &lt;td width="282" valign="top" align="center"&gt;&lt;p&gt;Odd * Odd = Odd&lt;/p&gt;&lt;/td&gt;   &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;Now this doesn’t really give one a sense of what is going on here, however, by using a &lt;a href="http://en.wikipedia.org/wiki/Cayley_table"&gt;Cayley Table&lt;/a&gt; it can also be called an operation table in that it shows the details of an operator. It becomes more interesting we now have a better depiction of the &lt;a href="http://en.wikipedia.org/wiki/Group_(mathematics)"&gt;Group&lt;/a&gt; for Addition (+) with Even as the Identity Element and the &lt;a href="http://en.wikipedia.org/wiki/Monoid"&gt;Monoid&lt;/a&gt; for Multiplication (*) with Odd as the Identity Element:&lt;/p&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="4"&gt;&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;+&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;Even&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;Odd&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;Even&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;Even&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;Odd&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;Odd&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;Odd&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;Even&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="4"  &gt;&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;*&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;Even&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;Odd&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;Even&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;Even&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;Even&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;Odd&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;Even&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;Odd&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Now that still may not be very intuitive, however, if you convert Even to Zero (0) and Odd to One (1) you get the following, possibly more familiar Group with 0 as the identity and the Monoid respectively with 1 as the identity:&lt;/p&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="4"  &gt;&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;+&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="4"  &gt;&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;*&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The Group has 1 as is its own inverse 1 + 1 = 0.  In general these "types" of Algebraic structures consist of a binary operator and a set that is closed under the operation so I am using the notation (Operator, {Set}) to denote these and since the sets are small I can just list the elements, but you could also write (+, Z) where Z is the set of integers and in fact this is a well known group: addition on the set of integers, but the set is infinite in this case in contrast to our finite sets.  We can describe the above as the Group (+, Z&lt;sub&gt;2&lt;/sub&gt;) and the Monoid  (*, Z&lt;sub&gt;2&lt;/sub&gt;) where  Z&lt;sub&gt;2&lt;/sub&gt; is the set {0,1} of the Integers Modulo 2, or simply the Binary digits which are Base 2. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Now let’s do another transformation on our Monoid and Group, we will now map Zero (0) to False (F) and One (1) to True (T) . We will also change our operators, + now becomes &lt;a href="http://en.wikipedia.org/wiki/Exclusive_or"&gt;Exclusive-Or&lt;/a&gt; and * now becomes &lt;a href="http://en.wikipedia.org/wiki/Logical_conjunction"&gt;Logical Conjunction&lt;/a&gt; aka Logical And.&lt;/p&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="4"  &gt;&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;Xor&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="4"  &gt;&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;And&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;All of these transformations are actually &lt;a href="http://en.wikipedia.org/wiki/Isomorphism"&gt;Isomorphisms&lt;/a&gt; and the two structures combine to form a &lt;a href="http://en.wikipedia.org/wiki/Ring_(algebra)"&gt;Ring&lt;/a&gt; this is also a &lt;a href="http://en.wikipedia.org/wiki/Field_(mathematics)"&gt;Field&lt;/a&gt;, the smallest &lt;a href="http://en.wikipedia.org/wiki/Finite_field"&gt;Finite Field&lt;/a&gt; &lt;a href="http://en.wikipedia.org/wiki/GF(2)"&gt;GF(2)&lt;/a&gt;. I have a follow up for this post and I will get into these and other ideas in more detail.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Some basic algebraic structures are:&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Magma_(algebra)"&gt;Magma or Groupoid&lt;/a&gt; – A closed binary operation on a set.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Semigroup"&gt;Semigroup&lt;/a&gt; – A closed binary operation on a set, with associatively. (An associative Groupoid)&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Monoid"&gt;Monoid&lt;/a&gt; – A closed binary operation on a set, with associatively and an identity element. (A Semigroup with an identity element)&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Group_(mathematics)"&gt;Group&lt;/a&gt; – A closed binary operation on a set, with associatively and an identity element. Each element has an inverse element. (A Monoid with inverses)&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Commutative"&gt;Commutative&lt;/a&gt; (&lt;a href="http://en.wikipedia.org/wiki/Abelian"&gt;Abelian&lt;/a&gt;) – used to describe any of the above with the &lt;a href="http://en.wikipedia.org/wiki/Commutative"&gt;commutative&lt;/a&gt; property, these two terms are interchangeable but term &lt;a href="http://en.wikipedia.org/wiki/Abelian"&gt;abelian&lt;/a&gt;&lt;sup&gt;1&lt;/sup&gt; in abstract algebra is used mostly just for &lt;a href="http://en.wikipedia.org/wiki/Abelian_group"&gt;groups&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="4"  &gt;&lt;tr&gt;   &lt;td width="80" valign="top" align="center"&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;   &lt;td width="55" valign="top" align="center"&gt;&lt;p&gt;Closed&lt;/p&gt;&lt;/td&gt;   &lt;td width="82" valign="top" align="center"&gt;&lt;p&gt;Associative&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;Identity&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;Inverse&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="80" valign="top" align="center"&gt;&lt;p&gt;Magma&lt;/p&gt;&lt;/td&gt;   &lt;td width="55" valign="top" align="center"&gt;&lt;p&gt;X&lt;/p&gt;&lt;/td&gt;   &lt;td width="82" valign="top" align="center"&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="80" valign="top" align="center"&gt;&lt;p&gt;Semigroup&lt;/p&gt;&lt;/td&gt;   &lt;td width="55" valign="top" align="center"&gt;&lt;p&gt;X&lt;/p&gt;&lt;/td&gt;   &lt;td width="82" valign="top" align="center"&gt;&lt;p&gt;X&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width=80 valign="top" align="center"&gt;&lt;p&gt;Monoid&lt;/p&gt;&lt;/td&gt;   &lt;td width=55 valign="top" align="center"&gt;&lt;p&gt;X&lt;/p&gt;&lt;/td&gt;   &lt;td width=82 valign="top" align="center"&gt;&lt;p&gt;X&lt;/p&gt;&lt;/td&gt;   &lt;td width=66 valign="top" align="center"&gt;&lt;p&gt;X&lt;/p&gt;&lt;/td&gt;   &lt;td width=66 valign="top" align="center"&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width=80 valign="top" align="center"&gt;&lt;p&gt;Group&lt;/p&gt;&lt;/td&gt;   &lt;td width=55 valign="top" align="center"&gt;&lt;p&gt;X&lt;/p&gt;&lt;/td&gt;   &lt;td width=82 valign="top" align="center"&gt;&lt;p&gt;X&lt;/p&gt;&lt;/td&gt;   &lt;td width=66 valign="top" align="center"&gt;&lt;p&gt;X&lt;/p&gt;&lt;/td&gt;   &lt;td width=66 valign="top" align="center"&gt;&lt;p&gt;X&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Now Commutative is more of a property of the above, as we saw the &lt;a href="http://www.elegantcoding.com/2011/05/monoid-for-masses.html"&gt;String Monoid&lt;/a&gt; is not or Non-Commutative where as the Group (+, Z&lt;sub&gt;2&lt;/sub&gt;) and the Monoid  (*, Z&lt;sub&gt;2&lt;/sub&gt;) are both Commutative.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Going back to &lt;a href="http://en.wikipedia.org/wiki/Boolean_algebra_(logic)"&gt;Boolean Logic&lt;/a&gt;, if you have had any exposure to Boolean Logic things now may look amiss in regards to operators: such as what about the Or operator? Actually Xor can be defined in terms of &lt;a href="http://en.wikipedia.org/wiki/Logical_conjunction"&gt;Logical Conjunction&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Logical_disjunction"&gt;Logical Disjunction&lt;/a&gt; as follows:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-mLAmncN_GCU/TyXXa67p9UI/AAAAAAAAAXw/BVvtqOnEs20/s1600/XOR1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="21" width="253" src="http://4.bp.blogspot.com/-mLAmncN_GCU/TyXXa67p9UI/AAAAAAAAAXw/BVvtqOnEs20/s400/XOR1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-nBBHaCoRxps/TyXXWxHD5WI/AAAAAAAAAXk/B2Uml7cRxMk/s1600/XOR2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="21" width="240" src="http://2.bp.blogspot.com/-nBBHaCoRxps/TyXXWxHD5WI/AAAAAAAAAXk/B2Uml7cRxMk/s400/XOR2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Our Cayley Table for Logical Disjunction (Or) is:&lt;/p&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="4"  &gt;&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;Or&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Now this table is almost the same as Xor with one exception (T or T) = T vs. (T Xor T) = F.  We can still call F an identity since it combines with T to give T, but you can see with that one change we lost our inverse for T so this is a now "downgraded" to Monoid status.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Now if we add Logical Conjunction (And) back we get the familiar values in Caley tables:&lt;/p&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="4"  &gt;&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;Or&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="4"  &gt;&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;And&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;F&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;T&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Above we noted that the Group (+, Z&lt;sub&gt;2&lt;/sub&gt;) and the Monoid (*, Z&lt;sub&gt;2&lt;/sub&gt;)  formed a Ring.  Since Or is a Monoid these now combine to form a slightly different structure, a &lt;a href="http://en.wikipedia.org/wiki/Semiring"&gt;SemiRing&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Another interesting observation about these sets of &lt;a href="http://en.wikipedia.org/wiki/Logical_connective"&gt;operators&lt;/a&gt; comes from a logical standpoint. The combination of these two operators are what’s known as not being &lt;a href="http://en.wikipedia.org/wiki/Functional_completeness"&gt;functionally complete&lt;/a&gt;, which means that there exists &lt;a href="http://en.wikipedia.org/wiki/Truth_function"&gt;truth functional&lt;/a&gt; statements that cannot be expressed by these two operators alone, this can be fixed by adding negation which yields a truth functionally complete set of two dyadic and one monadic&lt;sup&gt;2&lt;/sup&gt; operators: {And, Or, Not}, which is a pretty well known and familiar set of logical operators.  The Ring operators from above {Xor, And} also form a functionally complete set. It turns out that just {And, Not} and just {Or, Not} are also each functionally complete sets as are the one element operator sets {&lt;a href="http://en.wikipedia.org/wiki/Logical_NAND"&gt;Nand&lt;/a&gt;} and {&lt;a href="http://en.wikipedia.org/wiki/Logical_NOR"&gt;Nor&lt;/a&gt;}, this is why digital logic circuits can be constructed solely with &lt;a href="http://en.wikipedia.org/wiki/NAND_gate"&gt;Nand&lt;/a&gt; &lt;a href="http://en.wikipedia.org/wiki/Logic_gate"&gt;Gates&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The thing that bothered me the most was the fact that And and Xor had this nice mapping from Boolean Logic with {T,F} to Binary Integer Arithmetic {0,1} but Or seemed to be an oddball and then I realized that you can  remap both Logical Conjunction and Logical Disjunction to the Numerical functions Min and Max, respectively:&lt;/p&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;p&gt;Max(0,0) = 0&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Max(0,1) = Max(1,0) =1&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Max(1,1) =1&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Min(0,0) = 0&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Min(0,1) = Min(1,0) =0&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Min(1,1) =1&lt;/p&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;In Caley table form which better shows the isomorphisms (&amp;cong; means bidirectionally isomorphic to) from our Caley tables above: (And, {T,F}) &amp;cong; (Min, Z&lt;sub&gt;2&lt;/sub&gt;) and (Or, {T,F}) &amp;cong; (Max, Z&lt;sub&gt;2&lt;/sub&gt;):&lt;/p&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="4"  &gt;&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;Max&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;table border="1" cellspacing="0" cellpadding="4"&gt;&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;Min&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width="47" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;   &lt;td width="54" valign="top" align="center"&gt;&lt;p&gt;0&lt;/p&gt;&lt;/td&gt;   &lt;td width="66" valign="top" align="center"&gt;&lt;p&gt;1&lt;/p&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Interestingly this mapping is the effectively definition of &lt;a href="http://en.wikipedia.org/wiki/Fuzzy_logic"&gt;Fuzzy Logic &lt;/a&gt; mapped to the discrete cases (two value logic).  &lt;a href="http://en.wikipedia.org/wiki/Boolean_algebra_(logic)"&gt;Boolean Logic&lt;/a&gt; also maps to &lt;a href="http://en.wikipedia.org/wiki/Lattice_theory"&gt;Lattices&lt;/a&gt; with disjunction being &lt;a href="http://en.wikipedia.org/wiki/Join_and_meet"&gt;meet&lt;/a&gt; and conjunction being &lt;a href="http://en.wikipedia.org/wiki/Join_and_meet"&gt;join&lt;/a&gt;, the min and max ideas give a nice intuition in relation to ordering.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;To recap we saw a number of Group and Monoid Isomorphisms (remember Z&lt;sub&gt;2&lt;/sub&gt; = {0, 1}), we saw:&lt;/p&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;p&gt;(+, Z&lt;sub&gt;2&lt;/sub&gt;) &amp;cong; (+, {Odd, Even})&lt;/p&gt;&lt;br /&gt;
&lt;p&gt; (*, Z&lt;sub&gt;2&lt;/sub&gt;) &amp;cong; (*, {Odd, Even})&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;(+, Z&lt;sub&gt;2&lt;/sub&gt;) &amp;cong; (Xor, {F, T})&lt;/p&gt;&lt;br /&gt;
&lt;p&gt; (*, Z&lt;sub&gt;2&lt;/sub&gt;) &amp;cong; (And, {F, T})&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;(Or, {F, T}) &amp;cong; (Max, Z&lt;sub&gt;2&lt;/sub&gt;)&lt;/p&gt;&lt;br /&gt;
&lt;p&gt; (And, {F, T}) &amp;cong; (Min, Z&lt;sub&gt;2&lt;/sub&gt;)&lt;/p&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;We also saw Ring Isomorphisms and a Semiring Isomorphism:&lt;/p&gt;&lt;br /&gt;
&lt;div align="center"&gt;&lt;br /&gt;
&lt;p&gt;[(+, Z&lt;sub&gt;2&lt;/sub&gt;), (*, Z&lt;sub&gt;2&lt;/sub&gt;))] &amp;cong; [(+, {Odd, Even}), (*, {Odd, Even})]&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;[(+, Z&lt;sub&gt;2&lt;/sub&gt;), (*, Z&lt;sub&gt;2&lt;/sub&gt;))] &amp;cong; [(Xor, {F, T}), (And, {F, T})]&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;[(Or, {F, T}), (And, {F, T})] &amp;cong; [(Max, Z&lt;sub&gt;2&lt;/sub&gt;), (Min, Z&lt;sub&gt;2&lt;/sub&gt;))] &lt;/p&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;I have always felt that examples are helpful and I think these give some sense of the diversity that can be found in just a small little corner of math. In researching this I came across some interesting facts which also highlight this diversity, for example the Nand operation is not associative but is commutative so it’s a commutative Groupoid.  The &lt;a href="http://en.wikipedia.org/wiki/Octonions"&gt;Octonions&lt;/a&gt;, which are &lt;a href="http://en.wikipedia.org/wiki/Hypercomplex_number"&gt;hypercomplex numbers&lt;/a&gt;,are neither associative nor commutative under multiplication but have an identity of 1 making it a non commutative Groupoid with an identity, so my point here is that the above table of basic algebraic structures that makes everything look so hierarchical is deceiving as the diversity does not seem to be constrained in any way, as far as I can tell. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt; This term is named after the Norwegian mathematician &lt;a href="http://en.wikipedia.org/wiki/Niels_Henrik_Abel"&gt;Niels Henrik Abel&lt;/a&gt; who developed Group Theory independently of &lt;a href="http://en.wikipedia.org/wiki/%C3%89variste_Galois"&gt;Galois&lt;/a&gt; and like Galois tragically died young(&amp;lt;30).&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;sup&gt;2&lt;/sup&gt; Dyadic means takes two operators, e.g. (And, Or) and monadic means takes one operand, in this case the negation (Not) operator, this should not be confused with other uses of the term Monad. &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/NHXEMis3Bjk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/NHXEMis3Bjk/abstract-algebra-logic-of-odd-and-even.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-LPcyuClBIcQ/TyXXBKatGHI/AAAAAAAAAXY/YI78XK6nuHQ/s72-c/squid.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/01/abstract-algebra-logic-of-odd-and-even.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-5595387300558512969</guid><pubDate>Wed, 25 Jan 2012 01:26:00 +0000</pubDate><atom:updated>2012-05-06T12:25:56.578-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Math</category><category domain="http://www.blogger.com/atom/ns#">Software Process</category><category domain="http://www.blogger.com/atom/ns#">Agile</category><category domain="http://www.blogger.com/atom/ns#">Software Engineering</category><title>Real Software Engineering: The Good, The Bad, and The Ugly</title><description>&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-0maylgi6ib4/TxyEatAkIYI/AAAAAAAAAXM/r3zqNrbIDPA/s1600/800px-GoldenGateBridge-001.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="300" width="400" src="http://1.bp.blogspot.com/-0maylgi6ib4/TxyEatAkIYI/AAAAAAAAAXM/r3zqNrbIDPA/s400/800px-GoldenGateBridge-001.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;style&gt;
blockquote.quote {
   border-bottom: #ddd 1px dotted;
   border-left: #ddd 1px dotted;
   padding-bottom: 0.6em;
   font-style: italic;
   font-family: calibri, tahoma, arial, sans-serif;
   margin: 1em 10% 1em 0px;
   min-height: 40px;
   padding-left: 3.8em;
   padding-right: 1em;
   background: url(http://4.bp.blogspot.com/-WkhuNlv2j88/TjXlBh6SySI/AAAAAAAAAN0/O_G2Z8YdMk8/s320/blockquote.white.png) #f0f0f0 no-repeat 4px top;
   color: #474747;
   border-top: #ddd 1px dotted;
   border-right: #ddd 1px dotted;
   padding-top: 0.6em
}
&lt;/style&gt;&lt;!--Real Software Engineering: The Good, The Bad, and The Ugly--&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Deconstructing Glenn VanderBurg’s &amp;quot;Real Software Engineering&amp;quot;&lt;/h2&gt;&lt;br /&gt;
&lt;p&gt;Many years ago when I started my career, fresh out of school with a Bachelors in Computer Science, I chose to answer that ubiquitous question &amp;quot;What do you do?&amp;quot; with the title of &amp;quot;Software Engineer&amp;quot;. Now you must realize that this was back at a time when any technical title including Programmer was as rare and mysterious as any engineering field to the average person who probably had never used a computer, not like today when everyone seems to have one in their hand at all times. When I was younger I always felt weird calling myself a programmer and I had a number of associations with other engineering disciplines, including starting my college studies in Chemical Engineering. Actually I was a chemistry nerd before I was a computer nerd, which you might have guessed as much if you read my &lt;a href="http://www.elegantcoding.com/2011/12/metaphorically-thinking-about-software.html"&gt;previous post on Software Engineering&lt;/a&gt;. I also felt weird and perhaps even a bit phony using the title Software Engineer, I still do, so now I mostly go by Software Developer.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;My original foray into the contemplation of Software Engineering lead me to do some more research which yielded an enlightening and informative presentation by Glenn Vanderburg called &amp;quot;&lt;a href="http://confreaks.net/videos/282-lsrc2010-real-software-engineering"&gt;Real Software Engineering&lt;/a&gt;&amp;quot;, &lt;a href="http://en.oreilly.com/rails2010/public/schedule/detail/14216"&gt;PDF Slides here&lt;/a&gt;, which attempts to explore ideas of what a real discipline of Software Engineering might be.  I strongly recommend watching it. It’s about 52 minutes long. I feel that his presentation has some very good points but it also has some flaws and biases.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;The good&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;He starts with a critique about the state of software engineering today, which includes the following points:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;Doesn’t reliably control costs.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Doesn’t reliably produce quality software.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Sometimes doesn’t produce software at all.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Software Engineering doesn’t work.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The term engineering is reserved for practices that work, a good capsule definition of engineering independent of any particular discipline.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The set of practices and techniques that have been determined to work reliably through experience.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Software engineering is a caricature of engineering.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;In software we have these practices that don’t work and that is called engineering&lt;/p&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;p&gt;I find myself agreeing with these, and sadly Software Engineering does seem to be a ridiculous farce that often seems to resemble a real engineering practice only minimally. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;He then goes on to talk about the NATO Software Engineering Conference in 1968 which he cites as the origin of the waterfall process as a misinterpretation of a document called:&lt;br /&gt;
&lt;a href="http://www.cs.umd.edu/class/spring2003/cmsc838p/Process/waterfall.pdf"&gt;MANAGING THE DEVELOPMENT OF LARGE SOFTWARE SYSTEMS&lt;/a&gt; by Dr. Winston W. Royce who it seems inadvertently started the waterfall process through what might be called &amp;quot;Poor Information Design&amp;quot;.&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;He continues with a quote from Parness about the document oriented path into engineering captured by the following quote:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;In Enginering ... people design through documents.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;-Parness &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;This is followed by a list that might be considered failed attempts at such an approach:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Computer-aided_software_engineering"&gt;CASE Tools&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Object-oriented_software_engineering"&gt;OOSE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Vienna_Development_Method"&gt;VDM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Unified_Modeling_Language"&gt;UML&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Model-driven_architecture"&gt;MDA&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Object-modeling_technique"&gt;OMT&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Booch_method"&gt;Booch&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;He refers to this as:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;Modelling and what I call ‘Math Envy’&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;While I agree with this last statement in practice, I feel that he goes too far with this opinion, more on that later.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;His presentation provides a good historical survey of Software Engineering with respect to the 1968 NATO Software Engineering Conference and is worth watching for that alone. He continues with some great observations about engineering in general:&lt;/p&gt;&lt;br /&gt;
&lt;a name="Creativity"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;Engineering is a creative activity it’s about designing and building and creating new things and there are always blind alleys and missteps and mistakes and discoveries and reactions to those reactions and adjustments.&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;I especially like the trial and error aspect in relation to creativity. I think this is a fundamentally important and potentially overlooked aspect of software development.  &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The following succinctly sums up what might be the kernel of general engineering:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;Different Engineering Disciplines are &lt;b&gt;Different&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;
&lt;ul type=disc&gt;&lt;li&gt;Different materials, physical effects, forces &lt;/li&gt;
&lt;li&gt;Different degrees of complexity in requirements, designs, processes, and artifacts &lt;/li&gt;
&lt;li&gt;Varied reliance on formal modeling and analysis vs. experimentation, prototyping, and testing &lt;/li&gt;
&lt;li&gt;Varied use of defined and empirical processes&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;This leads to a comparison between the empirical vs. formal predefined models:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;The defined process control model requires that every piece of work be completely understood. A defined process can be started and allowed to run until completion, with the same results every time.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The empirical process control model provides and exercises control through frequent inspection and adaptation for processes that are imperfectly defined and generate unpredictable and unrepeatable outputs.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;He then takes the following ideas from Structural Engineering:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;Structural engineering is the science and art of designing and making, with economy and elegance, […] structures so that they can safely resist the forces to which they may be subjected.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;—Structural Engineer’s Association &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Science and art, it employs the findings of science and yet is done with creativity &amp;quot;designing and making&amp;quot; engineers don’t sketch something on paper and validate it with math and throw it over the wall and never look at it again they participate in the building of what they design structural engineers have hard hats in their office because they visit the site and talk to the construction people and work with them during the process. &amp;quot;With economy and elegance&amp;quot; cost is always an object.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;From these ideas he derives a brief description of Software Engineering:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;Software engineering is the science and art of designing and making, with economy and elegance, Systems so that they can readily adapt to situations which they may be subjected. &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;With the following caveat: &lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;Software engineering will be different from other kinds of engineering.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;We know that software engineering will be different from other kinds of engineering we know that because other kinds of engineering are different from each other. Software systems are usually more complex in terms of number of moving parts and things like that than artifacts in other engineering disciplines we’re not working with physical materials we have different laws we work with and it is rare for a software project to run up against the limitations of physical materials, very rare.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;He reiterates this from the Structural Engineering piece:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;Cost is always an object.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;This is more eloquently stated by Arthur Mellen Wellington:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;Engineering is not the art of constructing. It is rather the art of not constructing: or, it is the art of doing well with one dollar what any bungler can do with two.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;—Arthur Mellen Wellington &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;The following are elements that in part drive the agile philosophy:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;The source code is the model and the document.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Source code is the detailed design&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The design and construction of software is tightly coupled.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;He draws the following inferences from the above:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;Encourage continued innovations in processes&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;And do like other engineering disciplines do. Take the processes that work and call those engineering.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Agile software development, far from being anti-engineering, represents the responsible application of engineering ideals to the field of software.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;I know that was a lot of quotes with sparse commentary, but it seemed like the best way to capture the really good points that he makes in his talk and &lt;a href="http://www.elegantcoding.com/2011/07/software-frameworks-resistance-isnt.html#ApiDesign"&gt;again&lt;/a&gt; I am trying to create a written artifact that I can reference and build upon in the future.&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;The Bad&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;One thing that I really don’t like about his presentation is the comparison of the two bridge builders: &lt;a href="http://en.wikipedia.org/wiki/Robert_Maillart"&gt;Robert Maillart&lt;/a&gt; who designed the Valtschielbach Bridge in Switzerland among others and &lt;a href="http://en.wikipedia.org/wiki/Leon_Moisseiff"&gt;Leon Moisseiff&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The distinction being that Maillart used testing and all but one of his bridges are still standing while &lt;a href="http://en.wikipedia.org/wiki/Leon_Moisseiff"&gt;Moisseiff&lt;/a&gt; used modeling most notably &lt;a href="http://www.wsdot.wa.gov/tnbhistory/people/people1.htm"&gt;Deflection Theory&lt;/a&gt; and was responsible for designing the ill fated Tacoma Narrows Bridge aka &lt;a href="http://en.wikipedia.org/wiki/Galloping_Gertie"&gt;Galloping Gertie&lt;/a&gt; possibly one of the most famous engineering disasters in history. Moisseiff was also involved in the design of Manhattan Bridge which is still standing and his Deflection Theory was used in the design of the &lt;a href="http://en.wikipedia.org/wiki/Golden_Gate_Bridge"&gt;Golden Gate Bridge&lt;/a&gt; and was later determined to be of sound design and is also still standing. The &lt;a href="http://en.wikipedia.org/wiki/Frommers"&gt;Frommers&lt;/a&gt; travel guide considers the Golden Gate Bridge &amp;quot;possibly the most beautiful, certainly the most photographed bridge in the world&amp;quot;, what bridge Maillart design?&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;I will not dispute that the collapse of the Tacoma Narrows Bridge was probably one of the most famous if not the most famous engineering disaster of all time and Moisseiff certainly suffered as a result, his career was shattered and he died shortly thereafter. Wikipedia states: &amp;quot;Though he [Moisseiff] had designed many other famous spans, the Narrows collapse overshadowed them all. It became a symbol of failed engineering and the dangers of arrogance in design.&amp;quot; I am in no position nor do I care to debate the soundness of deflection theory or the reasons for the collapse, actually it seems that reasons for the collapse are pretty &lt;a href="http://arxiv.org/abs/physics/0408101"&gt;complicated&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;From my limited understanding of Civil Engineering it seems that problems with wind are a continuous problem for Civil and Structural Engineers, I know that the &lt;a href="http://en.wikipedia.org/wiki/John_Hancock_Tower"&gt;John Hancock Tower&lt;/a&gt; in Boston was plagued by problems where wind induced twisting which caused large plate glass windows to &lt;a href="http://en.wikipedia.org/wiki/John_Hancock_Tower#Falling_glass_panes"&gt;careen&lt;/a&gt; hundreds of feet to the street making it a deadly hazard.  These were replaced with plywood earning it nicknames like the &amp;quot;Plywood Palace&amp;quot; and causing it to be condemned as a fire hazard, eventually these problems were resolved and it won awards for enhancing the Boston skyline. More recently, only twelve years ago in 2000 the &lt;a href="http://en.wikipedia.org/wiki/Millennium_Bridge_(London)"&gt;Millennium Bridge&lt;/a&gt; in London exhibited similar &lt;a href="http://en.wikipedia.org/wiki/Millennium_Bridge_(London)#Resonance"&gt;resonance problems&lt;/a&gt; to those of Galloping Gertie, it was shut down and reinforced.  So while all of this makes for interesting history of engineering fodder and good showmanship, I am not sure how directly relevant it is to software engineering. I Again I agree with his assertion that testing, perhaps not necessarily TDD in my opinion, is most likely a very important component in creating a real software engineering discipline but I feel this particular comparison argument is flawed as it is completely irrelevant to software engineering and in no way can be used to conclude that TDD should be used in software engineering. Also he contradicts his own argument with the statement, from above:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;Software engineering will be different from other kinds of engineering.&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;He also contradicts this in his slides:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;Software is very unlike bridges and buildings.&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;He ends his presentation abruptly with: &lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;Today software engineering is called Agile. &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;I hate to say it but the way he states it, it sounds a bit like &amp;quot;Mission Accomplished&amp;quot; to me and I may be misinterpreting him here but to me it sounds like his whole presentation is designed to conclude that Agile and TDD are the solution to the problem and I agree that they are probably the best solutions to the problem today, but I think they are severely lacking as an effective and precise framework for a real engineering discipline, I think we still need more cowbell. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;The Ugly&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;I feel that his presentation has anti-math and anti-academic undertones and I have to say: &amp;quot;No Sir I don’t like it.&amp;quot; The two main themes that I take issue with are:&lt;/p&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;He mostly dismisses the work of non practitioner academics. &lt;/li&gt;
&lt;li&gt;He dismisses Math and views it as only a cost saving tool.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;At various points He states the following:&lt;/p&gt;&lt;blockquote class="quote"&gt;&lt;p&gt;Advances come from practitioners not from academia.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&amp;quot;Advances come from practitioners.&amp;quot; And then are brought into academia. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Important advances often from practitioners not necessarily from academia and they are brought into the academic world and are refined and so forth. But they come from practitioners.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;They were practitioners … and there were a few academics, but the academics had good things to say as well.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;Perhaps I am misinterpreting his tone here, but the in the last statement he seems surprised that the academics had something of value to contribute. Actually I feel that he has this somewhat backwards, for example I think the work that companies like Google are doing and the general trend in analytics fundamentally contradict this sentiment. I think the way that both the fields of Computer Science and Software Engineering will inevitably move forward in both efficiently and efficacy will be through more collaboration between practitioners and academicians with both groups refining each other’s ideas. I anticipate and hope this is a trend that we will see more of. In fact some really interesting things are happening in that regard one interesting example is the &lt;a href="http://blog.mikemccandless.com/2010/12/using-finite-state-transducers-in.html"&gt;work&lt;/a&gt; that &lt;a href="http://blog.mikemccandless.com/"&gt;Mike McCandless&lt;/a&gt; has done with &lt;a href="http://lucene.apache.org/java/docs/index.html"&gt;Lucene&lt;/a&gt; using &lt;a href="http://en.wikipedia.org/wiki/Finite_state_transducer"&gt;Finite State Transducers&lt;/a&gt; which was based on &lt;a href="http://www.cs.nyu.edu/~mohri/pub/fla.pdf"&gt;academic work&lt;/a&gt;, not to mention the &lt;a href="http://www.elegantcoding.com/2011/07/software-frameworks-resistance-isnt.html"&gt;Entropy-Framework relationship&lt;/a&gt; that we have already looked at. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;He goes on to say:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;Mathematical Models were introduced to engineering as a cost saving tool it would be easy if you hear software engineering people talk about math and modeling, it would easy to get the idea that it’s the only way to do things right and that it is a tool for robustness and you don’t know it really works that it is really works unless have math to prove it, I’ve heard all of those statements. But, that’s not why it was introduced to engineering at all it was introduced to save cost because in other engineering fields they are working with real materials and things that require people and labor to go out and build and building prototypes and testing them especially at scale is extremely costly and if you can build a model, an approximation of reality you can save money.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Ask your friendly neighborhood aerospace engineer how much math he would do if building a model of his design and testing it were was effectively instantaneous and free. The answer would probably not be none, but a lot less than I do now.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;I am not sure if I agree with the idea, that seems to be implied, which is that mathematical models are strictly a cost saving measure. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Towards the end he states the following are approaches needed to advance software engineering:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;Not Math &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Not Models&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Not Documents&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Not copying other disciplines&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Learn From practioners&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Bias towards empirical processes&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;Ironically he mentions the following:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;Programming languages are formal languages some of them even have mathematically specified semantics ... and we understand the math behind them at least as well as your average structural engineer understands the math behind the procedures that he was taught to do to validate his designs.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Programs themselves are models of the solution to the problem, our very tools are mathematical in nature.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;In the slides he has the following quote, which I think he skips in his presentation due to time constraints, but I believe it is intended to reinforce his anti math-argument:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;What is needed is not classical mathematics, but mathematics. Systems should be built at levels and modules, which form a mathematical structure.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;—Friedrich Bauer &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;I was unable to find it elsewhere, so I don’t know the context of the Friedrich Bauer quote, but I find the quote interesting. I feel the key here is: &amp;quot;not classical mathematics, but mathematics&amp;quot;. My interpretation of this is that he is saying that math is important, but not the math many people think about, hence &amp;quot;not classical mathematics&amp;quot;. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;In Conclusion&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;I hope I didn’t come across as too harsh on Glenn Vanderburg but I am just being honest and as he said about Bruce Eckel, &amp;quot;He said it so I get to pick on him&amp;quot;.  &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The real strength of his presentation is that he really does step back from software and give some perspective on general engineering, and while we can all debate the utility of comparing different engineering fields it does hold that they all have a several common threads, including the application of artistry and creativity to design and construction, the objective to design and build things, working within certain constraints including cost, and the organization of people and resources to accomplish the tasks of design and construction. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;I admit that my experience with real Agile is limited and while I like what I have seen.  I still doubt that it truly fulfills very little beyond an empirical approach and it seems that its focus is primarily on the process of creating software, which is not necessarily a bad thing.  The structural aspect of software is not ignored by Agile, but I do feel that it is the structural aspects of software which is where we currently lack a real engineering framework.  This is really what needs to become more established.  Ideas like &lt;a href="http://en.wikipedia.org/wiki/Coupling_(computer_programming)"&gt;Coupling&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Cohesion_(computer_science)"&gt;Cohesion&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Refactoring"&gt;Refactoring&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Design_pattern_(computer_science)"&gt;Patterns&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Anti-patterns"&gt;Anti-patterns&lt;/a&gt;, etc. are the state of the art in terms of structure but they seem too &amp;quot;squishy&amp;quot; which leads me to ask the question, is it not possible to have more comprehensive math backed concepts like the types of things you find in other engineering disciplines?&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The answers to these questions in the past have been dominated by ideas like formal methods and metrics, ideas which have mostly failed to live up to a real promise, however, that does not mean that we should completely discount these and similar ideas in the future.  These and other more math oriented approaches may represent a failed lineage that will go extinct or they may represent the nascent ideas from which we are only now developing the theoretical and mathematical ideas to truly conquer these problems. For example the Nato Conference of 1968 is often cited as a milestone in the development of software engineering. It was only about forty years proir that Category Theory was discovered.  I wonder how many attendees or general practitioners knew about it, unlike today where it seems that almost every software blogger writes about Monads and many also mention Category Theory.  I feel that the new era of software engineering will be forged from math but it won’t be &amp;quot;Classical Math&amp;quot; like &lt;a href="http://en.wikipedia.org/wiki/Calculus"&gt;Calculus&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Algebra"&gt;Algebra&lt;/a&gt; over the &lt;a href="http://en.wikipedia.org/wiki/Field_(mathematics)"&gt;Field&lt;/a&gt; of &lt;a href="http://en.wikipedia.org/wiki/Real_number"&gt;Real Numbers&lt;/a&gt;, it will be from areas like &lt;a href="http://en.wikipedia.org/wiki/Graph_theory"&gt;Graph Theory&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Lattice_(order)"&gt;Lattice Theory&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Category_theory"&gt;Category Theory&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Information_theory"&gt;Information Theory&lt;/a&gt; and other related disciplines and not only will it be built on those disciplines but also the interrelation of those disciplines. I may be wrong about this but I have seen research that seems to point in these directions, ideas I will explore in future posts.  It seems crazy to assume that the failures of the past imply failures of the future. If math can make software cheaper and more reliable to produce it will become an inevitability.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/CLRnUk7C5xs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/CLRnUk7C5xs/real-software-engineering-good-bad-and.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-0maylgi6ib4/TxyEatAkIYI/AAAAAAAAAXM/r3zqNrbIDPA/s72-c/800px-GoldenGateBridge-001.jpg" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://www.elegantcoding.com/2012/01/real-software-engineering-good-bad-and.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-4001940086836528079</guid><pubDate>Sat, 24 Dec 2011 16:27:00 +0000</pubDate><atom:updated>2012-05-06T12:05:13.409-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Software Engineering</category><title>Metaphorically Thinking about Software Engineering</title><description>&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-RzhmswF5dck/TcIN2IxdWyI/AAAAAAAAADg/TE9SuRYxNf4/s1600/767px-Disney_Concert_Hall_by_Carol_Highsmith_edit2.jpg" imageanchor="1" style=""&gt;&lt;img border="0" height="250" width="320" src="http://2.bp.blogspot.com/-RzhmswF5dck/TcIN2IxdWyI/AAAAAAAAADg/TE9SuRYxNf4/s320/767px-Disney_Concert_Hall_by_Carol_Highsmith_edit2.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;style&gt;
blockquote {
   padding-bottom: 5px; padding-left: 5px; padding-right: 5px; font-family: calibri, tahoma, arial, sans-serif; background: #f5f5f5; color: #333; padding-top: 5px
}
&lt;/style&gt;&lt;br /&gt;
&lt;style&gt;
blockquote.quote {
   border-bottom: #ddd 1px dotted;
   border-left: #ddd 1px dotted;
   padding-bottom: 0.6em;
   font-style: italic;
   font-family: calibri, tahoma, arial, sans-serif;
   margin: 1em 10% 1em 0px;
   min-height: 40px;
   padding-left: 3.8em;
   padding-right: 1em;
   background: url(http://4.bp.blogspot.com/-WkhuNlv2j88/TjXlBh6SySI/AAAAAAAAAN0/O_G2Z8YdMk8/s320/blockquote.white.png) #f0f0f0 no-repeat 4px top;
   color: #474747;
   border-top: #ddd 1px dotted;
   border-right: #ddd 1px dotted;
   padding-top: 0.6em
}
&lt;/style&gt;&lt;!--Metaphorically Thinking about Software Engineering--&gt; &lt;div&gt;&lt;br /&gt;
&lt;p&gt;Please note this is a rewrite previous &lt;a href="http://www.elegantcoding.com/2011/05/qare-we-not-engineers.html"&gt;post&lt;/a&gt; that I was unhappy with.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Years ago I heard a comparison of &lt;a href="http://en.wikipedia.org/wiki/Software_Engineering"&gt;software engineering&lt;/a&gt; to &lt;a href="http://en.wikipedia.org/wiki/Chemical_engineering"&gt;chemical engineering&lt;/a&gt;. I believe the intent of the analogy between the two fields was due to the fact that Software Engineering is a very young discipline just as Chemical Engineering was in relatively recent history, circa 1900.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Metaphors get used a lot in our industry, in Chapter 2: “Metaphors for a Richer Understanding of Software Development” of Steve McConnell’s Code Complete they are discussed in some detail.&amp;nbsp; In that chapter he cites the following:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;A confusing abundance of metaphors has grown up around software development. David Gries says writing software is a science (1981). Donald Knuth says it's an art (1998). Watts Humphrey says it's a process (1989). P. J. Plauger and Kent Beck say it's like driving a car, although they draw nearly opposite conclusions (Plauger 1993, Beck 2000). Alistair Cockburn says it's a game (2002). Eric Raymond says it's like a bazaar (2000). Andy Hunt and Dave Thomas say it's like gardening. Paul Heckel says it's like filming Snow White and the Seven Dwarfs (1994). Fred Brooks says that it's like farming, hunting werewolves, or drowning with dinosaurs in a tar pit (1995). Which are the best metaphors?&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;I am not sure how apt the chemical engineering metaphor is either, but there are some interesting parallels.&amp;nbsp; The early chemical manufacturing process to produce &lt;a href="http://en.wikipedia.org/wiki/Sulfuric_acid"&gt;sulfuric acid&lt;/a&gt; is called the Lead &lt;a href="http://en.wikipedia.org/wiki/Lead_chamber_process"&gt;chamber process&lt;/a&gt; and it was invented in the mid 1700s. The process was not very well understood and was inefficient in that it required the use of expensive &lt;a href="http://en.wikipedia.org/wiki/Nitrate"&gt;nitrates&lt;/a&gt; often from &lt;a href="http://en.wikipedia.org/wiki/Guano"&gt;Chile&lt;/a&gt; which were partially lost as &lt;a href="http://en.wikipedia.org/wiki/Nitric_oxide"&gt;nitric oxide&lt;/a&gt; vapor, and it took over a hundred years before a way to recycle the part of nitrates was added to increase the efficiency of the process.&amp;nbsp; The discipline of chemical engineering was codified in the late 1800s when college curricula and associations for chemical engineering were created.&amp;nbsp; Over time the science of chemistry and &lt;a href="http://en.wikipedia.org/wiki/Stoichiometry"&gt;stoichiometry&lt;/a&gt; advanced as did &lt;a href="http://en.wikipedia.org/wiki/Thermodynamics"&gt;thermodynamics&lt;/a&gt; which made major steps forward around the same &lt;a href="http://en.wikipedia.org/wiki/Ludwig_Boltzmann"&gt;time&lt;/a&gt;. I am over simplifying here but eventually little understood processes that were discovered and tweaked empirically became understood and could be controlled and improved by applying the laws of science and mathematics.&amp;nbsp; Another parallel is the focus on &lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.27.3202"&gt;reusable processes&lt;/a&gt;, in that if you are building a new plant to manufacture sulfuric acid you don’t want to design it from scratch each time.&amp;nbsp; An interesting and abstract parallel is that both disciplines have their entropies, i.e. &lt;a href="http://en.wikipedia.org/wiki/Entropy_(classical_thermodynamics)"&gt;thermodynamic&lt;/a&gt; vs. &lt;a href="http://en.wikipedia.org/wiki/Entropy_(information_theory)"&gt;information&lt;/a&gt;. A social parallel may be the transformative effect that software is having on our lives and our society is as profound as that of industrial scale chemical production, this keyboard and almost thing I can see right now has been influenced in some way by chemical engineering.&amp;nbsp; Also what are the negative sides of these industries, what problems are we creating by the unregulated and somewhat opaque policies in regards to &lt;a href="http://en.wikipedia.org/wiki/Xenoestrogen"&gt;chemicals&lt;/a&gt; and what might some of the issues with software and IT &lt;a href="http://en.wikipedia.org/wiki/Network_neutrality"&gt;be&lt;/a&gt;?&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-ND-X2rE9_Fc/TgX48fBQ5hI/AAAAAAAAAGU/snC1DxotuW4/s1600/583px-Rafineria.jpg" imageanchor="1" style=""&gt;&lt;img border="0" height="200" width="194" src="http://1.bp.blogspot.com/-ND-X2rE9_Fc/TgX48fBQ5hI/AAAAAAAAAGU/snC1DxotuW4/s200/583px-Rafineria.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Now admittedly there is pretty big difference between a physical chemical process or the construction of something physical like bridge and software construction.&amp;nbsp; There are obvious parallels to building things in that people have to come together to build something that is greater than what one single individual could &lt;a href="http://en.wikipedia.org/wiki/Great_Pyramid_of_Giza"&gt;build&lt;/a&gt;. And there are similarities to Chemical processes in that once you build it that you have keep it up and running and you will probably need to do maintenance and make improvements while it is operational and even in some cases take it off line or build a new one in parallel while the old one is still in production.&amp;nbsp; Also might we possibly view Computer Science and Math as related to Software Engineering as Chemistry, stoichiometry and thermodynamics are related to Chemical Engineering?&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Like &lt;a href="http://www-cs-faculty.stanford.edu/~uno/"&gt;Donald Knuth&lt;/a&gt; I too think there is an artistic element to software, this idea is not incongruent with building or bridge architecture which is a process that organizes groups of people to build something beautiful. Perhaps a possible analogy for software engineering would be the construction of a bridge where we still don’t really understand all of the physics behind it or the best way to go about it. As a result when we are done it might stay up and it might &lt;a href="http://en.wikipedia.org/wiki/Tacoma_Narrows_Bridge"&gt;not&lt;/a&gt; and it will probably take longer than we thought to build it.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;I guess the question is it possible to create a discipline of software engineering that is as effective as the other engineering disciplines? If we use the chemical engineering metaphor, where are we in the time line of understanding the underlying science and applying it to our process? Perhaps we are at the equivalent point to the mid to late 1800s in terms of process and our understanding of the underlying science but I very much doubt the years will map linearly, it’s probably more like an exponential mapping. The elusive software engineering is probably its own entity, are our metaphors confining our thinking and hindering our ability to objectively look at this problem?&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The software industry is also different from almost any other technical industry in history just in the sheer number of people who now participate in it worldwide and it seems that the barriers to enter the field can be lower than that of other engineering and scientific disciplines in regards to formal degrees.&lt;/p&gt;&lt;br /&gt;
&lt;p class=MsoNormal&gt;&amp;nbsp;&lt;/p&gt;&lt;br /&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/yTveuqqNeEA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/yTveuqqNeEA/metaphorically-thinking-about-software.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-RzhmswF5dck/TcIN2IxdWyI/AAAAAAAAADg/TE9SuRYxNf4/s72-c/767px-Disney_Concert_Hall_by_Carol_Highsmith_edit2.jpg" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://www.elegantcoding.com/2011/12/metaphorically-thinking-about-software.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-1481582665395249582</guid><pubDate>Mon, 05 Dec 2011 16:51:00 +0000</pubDate><atom:updated>2012-05-06T12:06:43.648-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Math</category><category domain="http://www.blogger.com/atom/ns#">Combinatorics</category><category domain="http://www.blogger.com/atom/ns#">Set Theory</category><category domain="http://www.blogger.com/atom/ns#">Logic</category><category domain="http://www.blogger.com/atom/ns#">Linguistics</category><title>Responding to "Eleven Equations" Comments, Math Notation, and More</title><description>&lt;style&gt;
blockquote.quote {
   border-bottom: #ddd 1px dotted;
   border-left: #ddd 1px dotted;
   padding-bottom: 0.6em;
   font-style: italic;
   font-family: calibri, tahoma, arial, sans-serif;
   margin: 1em 10% 1em 0px;
   min-height: 40px;
   padding-left: 3.8em;
   padding-right: 1em;
   background: url(http://4.bp.blogspot.com/-WkhuNlv2j88/TjXlBh6SySI/AAAAAAAAAN0/O_G2Z8YdMk8/s320/blockquote.white.png) #f0f0f0 no-repeat 4px top;
   color: #474747;
   border-top: #ddd 1px dotted;
   border-right: #ddd 1px dotted;
   padding-top: 0.6em
}
&lt;/style&gt;&lt;!--Responding to "Eleven Equations" Comments, Math Notation, and More--&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-62wBjFX8c1M/Ttz18PzUi2I/AAAAAAAAAUk/gJSybgD-VrU/s1600/780px-Claude_Monet%252C_Impression%252C_soleil_levant%252C_1872.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="308" width="400" src="http://3.bp.blogspot.com/-62wBjFX8c1M/Ttz18PzUi2I/AAAAAAAAAUk/gJSybgD-VrU/s400/780px-Claude_Monet%252C_Impression%252C_soleil_levant%252C_1872.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;Wow that was quite an experience, I have been looking at sites like Hacker News, Reddit and DZone for years but to see my own post go to #1 on Hacker News and rise high on Reddit and DZone was quite a thrill, with over 70K hits at the time of this writing.  It has completely changed my life the phone is ringing off the hook with endorsement offers, it looks like I will only be wearing Nike for the next year. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The best part was the over 200 comments on my &lt;a href="http://www.elegantcoding.com/2011/11/eleven-equations-true-computer-science.html"&gt;Blog&lt;/a&gt;, &lt;a href="http://news.ycombinator.com/item?id=3286459"&gt;Hacker News&lt;/a&gt;, and &lt;a href="http://www.reddit.com/r/programming/comments/msl7x/eleven_equations_every_computer_science_geeks/"&gt;Reddit&lt;/a&gt;, it spawned some spirited discussion on all three locations and many people added their own equations some that I was unfamiliar with and I learned a few new things, excellent!  The various discussions for the most part were great and very enjoyable and I’d like to thank everyone who contributed.   In the post I commented that I wondered how I would feel about the list in a year and I already think I would change the list by one equation.  I was tempted to respond to the comments on all of the forums, I know I should at least respond on my own blog, I just figured I’d do it as a post that way I could hit a number of topics.  &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;One thing that people objected to was the title, which induced some inferences in the tone of the title. One redditer summed it up as:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;Someone presuming, yet again, to know what &amp;quot;every&amp;quot; Computer Scientist should know? A title like &amp;quot;my favourite computer science equations&amp;quot; might be better. This list contains a lot of ideas which are only relevant in very narrow domains.&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;Yes, probably on the title comment, but the title was an intentional "spoof" if you will of a title of an article on Wired, and if you read my post you would have gotten that.  Actually I confess that you might even accuse me of "Hacker News Post Popularity Hacking" as I saw the Wired post rise up and figured that there was a high probability that a similar CS related post could achieve a similar placement, actually I think it exceeded my expectations and went even higher, it shot to #1 in under two hours of my submitting it and it stayed on the front page for almost a day.  I felt the tone I was setting, by using the term "rip off" and the &lt;a href="http://en.wikipedia.org/wiki/This_Is_Spinal_Tap"&gt;Spinal tap&lt;/a&gt; joke (This one goes to eleven) that I don’t think anyone got, was subtly light hearted, perhaps it was too subtle.  I recall reading that the title is key to getting people to read posts, and clearly this title was somewhat controversial which probably helped it, actually most of my titles are fairly boring or references that make them less popular, but I generally title things the way want not for popularity, well with this one exception.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Another thing that people took umbrage with was the use of the equations, as I just explained since I had set my title accordingly my format was now set.  One commenter, in two different comments on a thread on Hacker News added: &lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;I think this is a pretty silly post, to be honest. CS covers so much, and everytime I see a list of &amp;quot;things you should know&amp;quot;, I have to resist the urge to roll my eyes and ignore it. But then I read it, and inevitably roll my eyes anyway.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;...&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;I disagree. Programming is math. Highly advanced math, in fact. It's just a different type of math. And the 11 equations in the OP's article just barely touches on what CS is about. There is far more to it than that.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;I mostly agree with this commenter. I admit that the sentiment that this not really about the equations but the general domain knowledge is implied, again perhaps too subtle.  At one point someone mentions memorizing these equations which again means you are missing the point.  It’s about knowing what these equations mean and how to use them.  I feel that the math domain knowledge for our field is growing and becoming more important. Do I use any of this for my day job? Well no, but I hope to one day.  As to the broad domain I actually have a post "&lt;a href="http://www.elegantcoding.com/2011/06/math-for-programmers-tng.html"&gt;Math For Programmer TNG&lt;/a&gt;" that covers a very broad domain of math that I think is potentially relevant.  Also not all areas of math are going to be used in every math related job.  &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;As to the narrowness insinuated by the two comments above, the post touched on the following domains: &lt;a href="http://en.wikipedia.org/wiki/Combinatorics"&gt;Combinatorics&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Mathematical_logic"&gt;Logic&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Boolean_Algebra"&gt;Boolean Algebra&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Set_Theory"&gt;Set Theory&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Lattice_theory"&gt;Lattice Theory&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Probability_Theory"&gt;Probability Theory&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Statistics"&gt;Statistics&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Category_Theory"&gt;Category Theory&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Number_Theory"&gt;Number Theory&lt;/a&gt; including &lt;a href="http://en.wikipedia.org/wiki/Complex_Numbers"&gt;Complex Numbers&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Relational_Algebra"&gt;Relational Algebra&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Abstract_Algebra"&gt;Abstract Algebra&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Linear_Algebra"&gt;Linear Algebra&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Shannon_information_theory"&gt;Shannon Information Theory&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Algorithmic_Information_Theory"&gt;Algorithmic Information Theory&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Kolmogorov_complexity"&gt;Kolmogorov complexity&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Graph_Theory"&gt;Graph Theory&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Formal_language_theory"&gt;Formal Language Theory&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Automata_Theory"&gt;Automata Theory&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Combinatory_logic"&gt;Combinatory Logic&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Lambda_Calculus"&gt;Lambda Calculus&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Machine_Learning"&gt;Machine Learning&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Data_Mining"&gt;Data Mining&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Encryption"&gt;Encryption&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Limit_(mathematics)"&gt;Limits&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Topology"&gt;Topology&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Fourier_analysis"&gt;Fourier Analysis&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/The_Simpsons"&gt;The Simpsons&lt;/a&gt;. Not exactly narrow, or am I missing something here?  In fact the list was picked in part for diversity. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The &lt;a href="http://en.wikipedia.org/wiki/Pumping_lemma"&gt;Pumping Lemma&lt;/a&gt; turned out to be fairly controversial, I do admit that the Pumping Lemma was perhaps a bit "contrived" as an Equation and as one person put it: "that's the most hideous formulation of the pumping lemma I have ever seen". That formulation came from Wikipedia.  As I mentioned I really did want something from Formal Language Theory or Automata Theory and it’s not so much about determining which language is regular but knowing the difference between a &lt;a href="http://en.wikipedia.org/wiki/Regular_Language"&gt;Regular Language&lt;/a&gt; and a &lt;a href="http://en.wikipedia.org/wiki/Context_free_language"&gt;Context Free Language&lt;/a&gt; so that you are not the &lt;a href="http://www.elegantcoding.com/2011/10/confederacy-of-cargo-cult-coders.html"&gt;cargo cult coder&lt;/a&gt; who tries to parse html with &lt;a href="http://en.wikipedia.org/wiki/Regular_expression"&gt;regular expressions&lt;/a&gt; because you understand these distinctions. I think the following exchange summed up what I was going for:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;(except the Pumping Lemma, WTF?)&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Reply:"Seriously, you never learnt theoretical computer science? As in, theory of computation? Automata theory? Complexity theory? Nothing like that?"&lt;/p&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;There were a number of comments about the use of mathematical notation including the following:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;"Shannon's Information Theory, Eigenvector, DeMorgan's Laws, etc. None of those names are meaningful or descriptive. And then the greek letters and made up symbols. Math could learn something from Computer Science:&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;"&lt;a href="https://www.google.com/search?q=readable+code"&gt;https://www.google.com/search?q=readable+code&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;This commenter seemed to have an issue with the actual names of things in math.  I found this to be very narrow minded. Math is many things including being a domain of knowledge, that’s like complaining about the names: &lt;a href="http://en.wikipedia.org/wiki/Ytterbium"&gt;Ytterbium&lt;/a&gt; in Chemistry, &lt;a href="http://en.wikipedia.org/wiki/Bose%E2%80%93Einstein_condensate"&gt;Bose–Einstein Condensate&lt;/a&gt; in Physics, &lt;a href="http://en.wikipedia.org/wiki/Borneo"&gt;Borneo&lt;/a&gt; in world Geography, or &lt;a href="http://en.wikipedia.org/wiki/Impressionism"&gt;Impressionism&lt;/a&gt; in art. Really!?! &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Now the complaints about the notation are more understandable but still unreasonable in my opinion, math in some respects is a language, perhaps somewhere between a natural language and programming language, it has a notation and to really be able to understand it you need to learn this notation (language).  Someone remarked that symbols were "unfriendly".  Well I find Chinese, Arabic&lt;sup&gt;1&lt;/sup&gt;, etc. to consist of unfriendly symbols, but that’s because I don’t know them.  Also like natural languages you have inconsistencies, and multiple meanings for symbols.  One person complained about my notation for the Set version of De Morgan's laws, this may be a nonstandard notation, I saw it in some course notes on probability and set theory and I liked it and I just used it without thinking about it. I do think it’s more elegant.  This makes a good point about math.  If you learn it and read from diverse sources you will encounter notational differences.  This has been my experience, in fact if you look on the Wikipedia page for &lt;a href="http://en.wikipedia.org/wiki/De_Morgan's_laws"&gt;De Morgan's laws&lt;/a&gt; you will find the following example from &lt;a href="http://en.wikipedia.org/wiki/Modal_logic"&gt;Modal Logic&lt;/a&gt;: &lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-sm13G4W5p8g/Ttz2HSvWB8I/AAAAAAAAAUw/W1sLNpO_i8U/s1600/dem-mod1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="16" width="98" src="http://2.bp.blogspot.com/-sm13G4W5p8g/Ttz2HSvWB8I/AAAAAAAAAUw/W1sLNpO_i8U/s400/dem-mod1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-CnTW5TY8nGo/Ttz2MWdgQdI/AAAAAAAAAU8/QIOuhuknko0/s1600/dem-mod2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="16" width="98" src="http://4.bp.blogspot.com/-CnTW5TY8nGo/Ttz2MWdgQdI/AAAAAAAAAU8/QIOuhuknko0/s400/dem-mod2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;I am used to the notation used in Hughes and Cresswell:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-1JpHEQk7CMs/Ttz2PrMiG6I/AAAAAAAAAVI/_NtJapVWJ0o/s1600/dem-mod-h1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="16" width="104" src="http://3.bp.blogspot.com/-1JpHEQk7CMs/Ttz2PrMiG6I/AAAAAAAAAVI/_NtJapVWJ0o/s400/dem-mod-h1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-egYfTTkjT80/Ttz2TIccVkI/AAAAAAAAAVU/O4svPO-yj2I/s1600/dem-mod-h2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="16" width="104" src="http://3.bp.blogspot.com/-egYfTTkjT80/Ttz2TIccVkI/AAAAAAAAAVU/O4svPO-yj2I/s400/dem-mod-h2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;That’s just how things work.  You can get hung up on it and complain or you can accept it and move on.   Don’t get me wrong it would be nice if there was a notational standard that every one followed for all math.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Like natural languages Math has its equivalences of "&lt;a href="http://en.wikipedia.org/wiki/Homograph"&gt;Homographs&lt;/a&gt;", for example the following  symbols can have multiple context dependent meanings: &amp;#124;b&amp;#124; can mean absolute value of b if it is a number or cardinality of b if it is a set or length of b if it is string, &amp;part; can mean &lt;a href="http://en.wikipedia.org/wiki/Partial_Derivative"&gt;Partial Derivative&lt;/a&gt; or &lt;a href="http://en.wikipedia.org/wiki/Boundary_(topology)"&gt;Topological Boundary&lt;/a&gt;,  and as we saw &amp;and; and &amp;or; can mean meet and join or "logical and" and "logical or".  &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Just as Math has "Homographs", as in natural languages it also has its equivalences of "&lt;a href="http://en.wikipedia.org/wiki/Polysemy"&gt;Polysemes&lt;/a&gt;", meaning that there are multiple ways to express the same ideas. For example set difference can be expressed as (S – T) or (S \ T), the Powerset notation can be either 2&lt;sup&gt;S&lt;/sup&gt; or P(S), and meet and join can be expressed as the either of the following sets of symbols:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-DG1Ii9SIzog/Tt0NwkZaXGI/AAAAAAAAAWo/SX5vLH2zvew/s1600/wv.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="11" width="26" src="http://4.bp.blogspot.com/-DG1Ii9SIzog/Tt0NwkZaXGI/AAAAAAAAAWo/SX5vLH2zvew/s400/wv.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-N3RHlilNOhc/Tt0N0Nw72hI/AAAAAAAAAW0/7crHyhnjM_E/s1600/sqwv.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="10" width="27" src="http://3.bp.blogspot.com/-N3RHlilNOhc/Tt0N0Nw72hI/AAAAAAAAAW0/7crHyhnjM_E/s400/sqwv.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The list of both math "Homographs" and "Polysemes" is much longer.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;For De Morgan's laws, someone added the following generalization using the Existential and Universal Quantifiers, which is really interesting and also illustrates the &lt;a href="http://en.wikipedia.org/wiki/Duality_(mathematics)#Order-reversing_dualities"&gt;duality&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;It's not much of a generalization, but I prefer the predicate version of De Morgan's: &lt;/p&gt;&lt;p&gt;~&amp;#8704;x p(x) &amp;#8801;&amp;#8707;x ~p(x)&lt;br /&gt;
~&amp;#8707;x p(x) &amp;#8801;&amp;#8704;x ~p(x)&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;If you read the Wikipedia Article it includes this generalization as well:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-T1uzCCUm7wY/Ttz24JPpEgI/AAAAAAAAAVg/Qx_7sHSNHLY/s1600/dem-wik1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="43" width="117" src="http://4.bp.blogspot.com/-T1uzCCUm7wY/Ttz24JPpEgI/AAAAAAAAAVg/Qx_7sHSNHLY/s400/dem-wik1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-vMwmDxUUx6c/Ttz29Kx3cRI/AAAAAAAAAVs/5czQhFZ4oSQ/s1600/dem-wik2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="43" width="117" src="http://2.bp.blogspot.com/-vMwmDxUUx6c/Ttz29Kx3cRI/AAAAAAAAAVs/5czQhFZ4oSQ/s400/dem-wik2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The above equations do generalize De Morgan's laws within Logic and Set Theory respectively but my point was to further generalize them in terms of &lt;a href="http://en.wikipedia.org/wiki/Lattice_theory"&gt;Lattices&lt;/a&gt; which is a different concept all together and gets at the deeper intuition about the interrelation of Logic and Set Theory, quoting from &lt;u&gt;Combinatorics the Rota way:&lt;/u&gt; by Rota and Kung, an amazing book I am trying to read, emphasis on the word trying:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;"As John Von Neumann put it, the theory of Boolean Algebras is "pointless" set theory.&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;This set version would be written using the complement exponentiation notation as follows:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-ULozrRNZj7U/Ttz3G4-2QiI/AAAAAAAAAV4/PTzEu9ikagk/s1600/Dem-set1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="53" width="141" src="http://4.bp.blogspot.com/-ULozrRNZj7U/Ttz3G4-2QiI/AAAAAAAAAV4/PTzEu9ikagk/s400/Dem-set1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-U8zUWgP4LTY/Ttz3KAvnAOI/AAAAAAAAAWE/mLt5dY7nDkw/s1600/Dem-set2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="53" width="141" src="http://2.bp.blogspot.com/-U8zUWgP4LTY/Ttz3KAvnAOI/AAAAAAAAAWE/mLt5dY7nDkw/s400/Dem-set2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;I really do prefer this notation, I originally encountered it in "&lt;a href="http://www.sics.se/~ali/prob/"&gt;Introduction to Probability Theory&lt;/a&gt;" by By &lt;a href="http://www.sics.se/~ali/"&gt;Ali Ghodsi&lt;/a&gt; and Cosmin Arad, &lt;a href="http://www.sics.se/~ali/prob/l1/l1.pdf"&gt;lecture 1&lt;/a&gt;(pdf).  This notation is also used in &lt;u&gt;Combinatorics the Rota way&lt;/u&gt;. So this notation is now the official notation of my blog, get used to it or hit the road. ;)&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;A commenter (who was also the demorgans notation complainer) responded with the following:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;...&lt;/p&gt;&lt;p&gt;For the rest, they seem more likely to be used by someone doing something related to machine learning/AI/information theory than you run of the mill I-spend-all-day-parsing-user-input programmer.&lt;br /&gt;
&lt;p&gt;Thank you for making me feel like I'm not a 'true' computer scientist. Next would you like to tell me about how I'm not a 'man' because I don't like to work on cars?&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;Well I hate to break it to you, but if this list makes you feel that way then chances are you are like me: a software developer with a CS Degree and that does not make you or me a Computer Scientist. This is from &lt;a href="http://en.wikipedia.org/wiki/Computer_science"&gt;Wikipedia&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;"The general public sometimes confuses computer scientists with other &lt;a href="http://en.wikipedia.org/wiki/Computer_professional" title="Computer professional"&gt;computer professionals&lt;/a&gt; having careers in &lt;a href="http://en.wikipedia.org/wiki/Information_technology" title="Information technology"&gt;information technology&lt;/a&gt;, or think that computer science relates to their own experience with computers, ...&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;Oh, and yes you are not a man if you do not at least know how to change your oil, including the filter. ;)&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Also a number of people remarked that I did not explain the equations in enough detail and I did not provide code examples.  It was meant as high level post, if I were to explain all of these equations the post would have been excessively long, maybe even a whole book.  As to the code examples again it would be too long, if you want code examples that relate to math, I have posts for that, I recommend the following posts on my blog, some were linked in the original post: "&lt;a href="http://www.elegantcoding.com/2011/10/ologn.html"&gt;O(log(n))&lt;/a&gt;", "&lt;a href="http://www.elegantcoding.com/2011/07/triangles-triangular-numbers-and.html"&gt;Triangles, Triangular Numbers, and the Adjacency Matrix&lt;/a&gt;", "&lt;a href="http://www.elegantcoding.com/2011/05/combinatorial-and-other-math-of-java.html"&gt;The Combinatorial and Other Math of the Java Collections API&lt;/a&gt;", "&lt;a href="http://www.elegantcoding.com/2011/04/math-you-can-use.html"&gt;Math You Can Use : Refactoring If Statements with De Morgan's Laws&lt;/a&gt;", and "&lt;a href="http://www.elegantcoding.com/2011/05/monoid-for-masses.html"&gt;Monoid for the Masses&lt;/a&gt;".&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Regrettably some people responded with the sentiment of: I’m not good at math or that math is too hard, I don’t think I can get a CS degree.  Fortunately there were a number of comments of encouragement to counter these sentiments, my favorite was this one:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;Don't let this be intimidating to you - instead of asking yourself &amp;quot;how come I don't know this?&amp;quot; ask yourself &amp;quot;how can I learn more about this?&amp;quot;. This might sound cheesy and simplified but it's as simple as &amp;quot;nobody was born knowing this&amp;quot;. I'm 31 and I wish I had the money to go back in education and learn all of this with the official way but for now I'm just picking resources on the web and who knows? It just might happen...&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;I have a post planned to talk about my experiences and thoughts about learning math, I will say if you are a programmer you are doing math in a sense.  You just need to formalize your understanding of the underlying concepts.  If it is any consolation I find Math to be very hard at times, I pretty much suck at it in the traditional sense, but it is so beautiful and when you grok a concept, at least for me, it is an incredible buzz.  Every new concept that you learn changes how you see everything, I see so much math in programming and the world now it’s scary, I just wish I could figure out how to express it.  Everything is math.  Over the last few years my ability to understand things has greatly increased and continues to do so.  Yes it’s hard but it is so worth it.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;A number of commenters added their own equations to the discussion, and this was the best part, which included a few new things for me. In general my list was mostly directed at more pure math oriented equations that I felt were fairly central to a specific discipline and encapsulated certain principles.  Here are a few recommendations and thoughts: &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;One person pointed out the absence of P=NP or P &amp;ne; NP, to which I would respond "D’oh!" If I was doing this over I might even replace the Pumping Lemma with P=NP. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;One poster recommended triangular numbers:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;Here's a real simple and practical equation: 1+2+3+4 . . .&amp;nbsp;N&amp;nbsp;=&amp;nbsp;N(N+1)/2&lt;/p&gt;&lt;p&gt;This equation represents the number ofedges on a complete&amp;nbsp;graph&amp;nbsp;with&amp;nbsp; N+1 vertices or the number of possible pairings given &amp;nbsp;N+1 objects. Useful whenestimating O(N) for certain algorithms that involve comparing an item to everyother item in a set.&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;I love &lt;a href="http://en.wikipedia.org/wiki/Triangular_Numbers"&gt;Triangular Numbers&lt;/a&gt; and this is a great equation, I wrote a whole post "&lt;a href="http://www.elegantcoding.com/2011/07/triangles-triangular-numbers-and.html"&gt;Triangles, Triangular Numbers, and the Adjacency Matrix&lt;/a&gt;" on exactly what he is mentioning, and considered that equation but rejected it because triangular numbers are sort of a special case of the &lt;a href="http://en.wikipedia.org/wiki/Binomial_coefficient"&gt;Binomial Coefficient&lt;/a&gt; equation:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-sH1zDuJBL_w/Ttz3V_sVjvI/AAAAAAAAAWQ/4wKkJ_AsVxk/s1600/triangualr-wiki.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="46" width="400" src="http://3.bp.blogspot.com/-sH1zDuJBL_w/Ttz3V_sVjvI/AAAAAAAAAWQ/4wKkJ_AsVxk/s400/triangualr-wiki.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Here are some of the other equations and theorems that were suggested, I wouldn’t really consider these because they didn’t fit my theme and criteria but that doesn’t mean they aren’t interesting:&lt;/p&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Amdahl's_law"&gt;Amdahl's law&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Fitts's_law"&gt;Fitts's Law&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Master_theorem"&gt;Master Theorem&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Akra%E2%80%93Bazzi_method"&gt;Akra–Bazzimethod&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Little%27s_law"&gt;Little's Law&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Cook%E2%80%93Levin_theorem"&gt;Cook-Levin theorem&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;p&gt;One commenter accused me of shoehorning in Euler’s Identity.  This is partially true.  He also accused me of "Name Dropping". That’s not true.  A defender supplied the following course notes: &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://www.lsi.upc.edu/~conrado/docencia/udelar-course-2011.pdf"&gt;Analytic Combinatorics: A Primer&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;I followed up on that and found that you can download a copy of &lt;a href="http://algo.inria.fr/flajolet/Publications/AnaCombi/"&gt;Analytic Combinatorics&lt;/a&gt;:&lt;br /&gt;
by &lt;a href="http://algo.inria.fr/flajolet/index.html"&gt;Flajolet&lt;/a&gt; and &lt;a href="http://www.cs.princeton.edu/~rs/"&gt;Sedgewick&lt;/a&gt;. Warning: pretty advanced stuff.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;As the popularity of my post was waning on Hacker News a math oriented post called "&lt;a href="http://ntz-develop.blogspot.com/2011/03/fuzzy-string-search.html"&gt;Fuzzy string search&lt;/a&gt;" was making its way up the ranks. It’s an interesting post and I think it helps illustrate a couple of points I have been making here, first of all it uses mathematical notation, which is not uncommon when writing about these types of topics.  Additionally the post includes the equation for the &lt;a href="http://en.wikipedia.org/wiki/Triangle_inequality"&gt;Triangle Inequality&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-jyWMfYvOTWs/Ttz3oYbNHEI/AAAAAAAAAWc/KLCjRsLT840/s1600/triangle.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="181" src="http://1.bp.blogspot.com/-jyWMfYvOTWs/Ttz3oYbNHEI/AAAAAAAAAWc/KLCjRsLT840/s400/triangle.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;An equation that crossed my mind when writing my equations post.  It is not the equation itself, but the concept, if you become familiar with the idea of a &lt;a href="http://en.wikipedia.org/wiki/Metric_(mathematics)"&gt;Metric&lt;/a&gt; or &lt;a href="http://en.wikipedia.org/wiki/Metric_space"&gt;Metric Spaces&lt;/a&gt;, you instantly recognize this equation concept without having to read the associated text, not that you shouldn’t read the associated text.  Knowing these ideas gives you the ability to better understand more complex ideas that are based on these concepts. I think this is the case in all knowledge domains.  Also I noticed that there was not one comment on that post complaining about math notation.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;A lot of what went on is part of an ongoing conversation, I blogged about it in "&lt;a href="http://www.elegantcoding.com/2011/03/math-debate.html"&gt;The Math Debate&lt;/a&gt;" which links to other famous blogs of the same ilk.  Ultimately the equations probably don’t apply to most programming jobs, the title contained as some commenters pointed out "Computer Science Geeks" not "Corporate Software Developers".  A few people castigated the commenters who seemed to be advocating positions of ignorance, thanks, BTW.  I personally find it tragic, the following comment sums this up:  &lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;&lt;p&gt;"Someone with a CS degree who knows nothing of De Morgan's law should have their credit removed and be demoted to making websites or performing tech support tasks.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Reply: "There goes 98% of your CS graduates then. I wish I was joking, but alas.."&lt;/p&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;Of course it’s a bit I ironic that as I am wrapping this up, "&lt;a href="http://queue.acm.org/detail.cfm?id=1961297&amp;amp;repost"&gt;A co-Relational Model of Data for Large Shared Data Banks&lt;/a&gt;"  by Erik Meijer, Gavin Bierman just popped up on Hacker News, the relevant quote is:&lt;/p&gt;&lt;br /&gt;
&lt;blockquote class="quote"&gt;Every programmer is familiar with the two dual forms of De Morgan’s laws&lt;/blockquote&gt;&lt;br /&gt;
&lt;p&gt;The writing quality of the post was criticized.  I don't know what people will think of this post, I feel like I just wrote a &lt;a href="http://en.wikipedia.org/wiki/Clip_show"&gt;clip show&lt;/a&gt;.  I admit that previous post was not my best effort, while it was fun putting it together it was not easy, I had hoped to learn all of the equations in more detail, I did to some degree, I confess I still don’t fully get the Y-Combinator, but I will.  I finally decided to just push it out and move on.  This post, while being relevant to my mission of blogging about math was something of a social experiment in popularity, it was interesting but I will be returning to the true mission of my blog which is my journey through math and the pursuit of a real Software Engineering discipline.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Ultimately I am interested in the readers, like a young colleague of mine who was too busy to comment because he was following the links to learn new things he didn't know, not the complainers and naysayers.   There were many positive comments and again, thanks. I did feel a needed to refute some of the negative comments. The bottom line is if you want to read about math, you need to get used to the notation, it probably won't help you to build &lt;a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete"&gt;CRUD&lt;/a&gt; Web apps but it will hopefully help you take your career to the next level.&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt;Actually this is not true I find them to be quite beautiful, especially Arabic.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/BIIcE8W5hYM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/BIIcE8W5hYM/responding-to-eleven-equations-comments.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-62wBjFX8c1M/Ttz18PzUi2I/AAAAAAAAAUk/gJSybgD-VrU/s72-c/780px-Claude_Monet%252C_Impression%252C_soleil_levant%252C_1872.jpg" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://www.elegantcoding.com/2011/12/responding-to-eleven-equations-comments.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6918427997759942244.post-3552176205618998576</guid><pubDate>Sun, 27 Nov 2011 21:13:00 +0000</pubDate><atom:updated>2012-05-06T12:08:42.258-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Linear Algebra</category><category domain="http://www.blogger.com/atom/ns#">Math</category><category domain="http://www.blogger.com/atom/ns#">Complex numbers</category><category domain="http://www.blogger.com/atom/ns#">Formal Language Theory</category><category domain="http://www.blogger.com/atom/ns#">Bayes</category><category domain="http://www.blogger.com/atom/ns#">Number Theory</category><category domain="http://www.blogger.com/atom/ns#">Combinatorics</category><category domain="http://www.blogger.com/atom/ns#">Set Theory</category><category domain="http://www.blogger.com/atom/ns#">Logic</category><category domain="http://www.blogger.com/atom/ns#">Relational Algebra</category><category domain="http://www.blogger.com/atom/ns#">Information Entropy</category><category domain="http://www.blogger.com/atom/ns#">Computer Science</category><title>Eleven Equations True Computer Science Geeks Should (at Least Pretend to) Know</title><description>&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-O4a_eSkqeNE/TtKrcgal6zI/AAAAAAAAAUY/C8P7Ex09bhk/s1600/Bayes%2527_Theorem_MMB_01.1.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="256" width="400" src="http://4.bp.blogspot.com/-O4a_eSkqeNE/TtKrcgal6zI/AAAAAAAAAUY/C8P7Ex09bhk/s400/Bayes%2527_Theorem_MMB_01.1.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;!--Eleven Equations True Computer Science Geeks Should (at Least Pretend to) Know --&gt;&lt;br /&gt;
&lt;p&gt;This idea is a complete rip off an article that appeared in &lt;a href="http://www.wired.com/wiredscience/2011/11/equations-for-geeks/?pid=2364&amp;amp;viewall=true"&gt;Wired&lt;/a&gt; a little while ago and it got me thinking what would my list for Computer Science look like?  Plus I thought it might be a fun post and unlike the Wired list this one goes to eleven.  So here they are in no particular order:&lt;/p&gt;&lt;br /&gt;
&lt;a name="Binomial_Coefficient" /&gt;&lt;br /&gt;
&lt;h2&gt;Binomial Coefficient&lt;/h2&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-l5kBy3x6eEI/TtKoHv3wvDI/AAAAAAAAAQE/MFL0ejup3vc/s1600/binomial.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="41" width="138" src="http://3.bp.blogspot.com/-l5kBy3x6eEI/TtKoHv3wvDI/AAAAAAAAAQE/MFL0ejup3vc/s400/binomial.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;The &lt;a href="http://en.wikipedia.org/wiki/Binomial_coefficient"&gt;Binomial Coefficient equation&lt;/a&gt; generates &lt;a href="http://en.wikipedia.org/wiki/Pascal%27s_triangle"&gt;Pascal’s Triangle&lt;/a&gt; and gives you the coefficients for the &lt;a href="http://en.wikipedia.org/wiki/Binomial_theorem"&gt;Binomial Theorem&lt;/a&gt; these ideas are often attributed to Pascal but in fact they have been known in part for over a millennia.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;As I mentioned that this list is no particular order and I don’t wish to play favorites but if there is one equation here that you should really consider learning and committing to memory this is it. It is central to &lt;a href="http://en.wikipedia.org/wiki/Combinatorics"&gt;Combinitorics&lt;/a&gt; which has connections to many areas of math, I guess I should qualify that if you are serious about computer science and math related programming topics then you should be able to recite and apply it from memory, even when you are drunk, sleep deprived or being held at gun point. Ok that might be a bit much but you get the idea.  If you are programmer and you haven’t learned it, or need a refresher, I have a post that relates it to the &lt;a href="http://www.elegantcoding.com/2011/05/combinatorial-and-other-math-of-java.html"&gt;Java Collections API&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Demorgans_Laws" /&gt;&lt;br /&gt;
&lt;h2&gt;Demorgan’s Laws&lt;/h2&gt;&lt;br /&gt;
&lt;p&gt;Logical form:&lt;/p&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-dnSUiAWWyYs/TtKoTWDV-qI/AAAAAAAAAQQ/kVwvQMkQlIA/s1600/demorgan-logical-1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="172" src="http://3.bp.blogspot.com/-dnSUiAWWyYs/TtKoTWDV-qI/AAAAAAAAAQQ/kVwvQMkQlIA/s400/demorgan-logical-1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-AOfZxmR5cbg/TtKoW8T6GhI/AAAAAAAAAQc/jg7xoMy2ons/s1600/demorgan-logical-2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="172" src="http://2.bp.blogspot.com/-AOfZxmR5cbg/TtKoW8T6GhI/AAAAAAAAAQc/jg7xoMy2ons/s400/demorgan-logical-2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Set Form:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-ry-FqDGZxJU/TtKomnBvoEI/AAAAAAAAAQo/fokmM9hv2pw/s1600/demorgan-set-1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="143" src="http://2.bp.blogspot.com/-ry-FqDGZxJU/TtKomnBvoEI/AAAAAAAAAQo/fokmM9hv2pw/s400/demorgan-set-1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-PJA7GIKtK8M/TtKou13h4oI/AAAAAAAAAQ0/smrKEw7nLzs/s1600/demorgan-set-2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="143" src="http://1.bp.blogspot.com/-PJA7GIKtK8M/TtKou13h4oI/AAAAAAAAAQ0/smrKEw7nLzs/s400/demorgan-set-2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Ok so that’s like four "equations" for &lt;a href="http://en.wikipedia.org/wiki/De_Morgan's_laws"&gt;DeMorgan’s Laws&lt;/a&gt;, one can’t help but to struck by the similarity between the two sets and this is not a coincidence these two sets of formulas are essentially the same thing, they are special cases of &lt;a href="http://en.wikipedia.org/wiki/Complemented_lattice"&gt;complemented&lt;/a&gt; &lt;a href="http://en.wikipedia.org/wiki/Distributive_lattice"&gt;distributive&lt;/a&gt; &lt;a href="http://en.wikipedia.org/wiki/Lattice_(order)"&gt;lattices&lt;/a&gt;&lt;sup&gt;&amp;dagger;&lt;/sup&gt;  which means technically it’s really just two formulas:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-mMW8VHofNxs/TtKozfpNScI/AAAAAAAAARA/TsFraEDN414/s1600/demorgan-lattice-1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="160" src="http://3.bp.blogspot.com/-mMW8VHofNxs/TtKozfpNScI/AAAAAAAAARA/TsFraEDN414/s400/demorgan-lattice-1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-g1Vxzl1Qh_s/TtKo3SES3jI/AAAAAAAAARM/Nw7JtwiVx6o/s1600/demorgan-lattice-2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="160" src="http://4.bp.blogspot.com/-g1Vxzl1Qh_s/TtKo3SES3jI/AAAAAAAAARM/Nw7JtwiVx6o/s400/demorgan-lattice-2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;In this case the &amp;or; symbol means lattice &lt;a href="http://en.wikipedia.org/wiki/Join_and_meet"&gt;join&lt;/a&gt; operation and the &amp;and; symbol is the lattice &lt;a href="http://en.wikipedia.org/wiki/Join_and_meet"&gt;meet&lt;/a&gt; operation and the dash with the right downward mark means lattice complementation, I used this to differentiate from the tilde for Boolean complementation.  Also these two formulas are &lt;a href="http://en.wikipedia.org/wiki/Category_theory"&gt;categorical&lt;/a&gt; &lt;a href="http://en.wikipedia.org/wiki/Duality_(mathematics)"&gt;duals&lt;/a&gt; of each other, which means that if one were smart and had a good grasp of &lt;a href="http://en.wikipedia.org/wiki/Category_theory"&gt;Category Theory&lt;/a&gt; we could probably be really OCD about it and get it down to one formula.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Understanding &lt;a href="http://en.wikipedia.org/wiki/Set_theory"&gt;Set Theory&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Boolean_algebra_(structure)"&gt;Boolean Algebra&lt;/a&gt; are very important basic concepts in our profession and the Boolean version can make you better programmer, as you can use it to &lt;a href="http://www.elegantcoding.com/2011/04/math-you-can-use.html"&gt;refactor logical if statements&lt;/a&gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;a name="Eigenvector_and_Eigenvalue" /&gt;&lt;br /&gt;
&lt;h2&gt;Eigenvector and Eigenvalue&lt;/h2&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-GCgdDQ3ueUc/TtKo8uJGqUI/AAAAAAAAARY/cZkhPfq1zM8/s1600/eigenL.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="26" width="126" src="http://1.bp.blogspot.com/-GCgdDQ3ueUc/TtKo8uJGqUI/AAAAAAAAARY/cZkhPfq1zM8/s400/eigenL.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;This &lt;a href="http://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors"&gt;equation&lt;/a&gt; and these concepts are not only central to &lt;a href="http://en.wikipedia.org/wiki/Linear_algebra"&gt;Linear Algebra&lt;/a&gt; but these Linear Algebraic ideas and others are both used and extend into many other areas of math including &lt;a href="http://en.wikipedia.org/wiki/Linear_transformation"&gt;Linear Transformations&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Graph_theory"&gt;Graphs&lt;/a&gt; in terms of matrices like the &lt;a href="http://en.wikipedia.org/wiki/Adjacency_matrix"&gt;Adjacency Matrix&lt;/a&gt; and much more.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href=""&gt;Linear Algebra&lt;/a&gt; is becoming increasingly central to the types of things we are doing in our profession, it is used heavily in &lt;a href="http://en.wikipedia.org/wiki/Statistics"&gt;Statistics&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Machine_learning"&gt;Machine Learning&lt;/a&gt; not to mention the &lt;a href="http://en.wikipedia.org/wiki/Page_rank"&gt;Page Rank Algorithm&lt;/a&gt; is based in part on this equation.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Pumping_Lemma" /&gt;&lt;br /&gt;
&lt;h2&gt;Pumping Lemma for Regular Languages&lt;/h2&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/--UjYoIZ2Gy4/TtKpMS7ttEI/AAAAAAAAARw/m782_lhMsFo/s1600/PumpingLema.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="57" width="400" src="http://3.bp.blogspot.com/--UjYoIZ2Gy4/TtKpMS7ttEI/AAAAAAAAARw/m782_lhMsFo/s400/PumpingLema.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;No Comp Sci list would be complete with at least one formula from either &lt;a href="http://en.wikipedia.org/wiki/Formal_language"&gt;Formal Language Theory&lt;/a&gt; or &lt;a href="http://en.wikipedia.org/wiki/Automata_Theory"&gt;Automata Theory&lt;/a&gt;.  The problem is that these two are pretty different from other areas of math in terms of "Equations" I tried to think of some basic Ideas and &lt;a href="http://en.wikipedia.org/wiki/Pumping_lemma_for_regular_languages"&gt;The Pumping Lemma&lt;/a&gt; came to mind, and I found the above formula concisely expressed on Wikipedia.  This version of the Pumping Lemma is a more limited version of Another Theory which is used to check whether a &lt;a href="http://en.wikipedia.org/wiki/Formal_grammar"&gt;Language&lt;/a&gt; is &lt;a href="http://en.wikipedia.org/wiki/Regular_language"&gt;Regular&lt;/a&gt;.  Also this is maybe not the best choice as it is pretty dense, if you want a better explanation I recommend &lt;a href="http://stackoverflow.com/questions/461619/in-laymens-terms-what-is-the-pumping-lemma"&gt;this&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;While this "equation" is pretty specialized, it is actually a special case of the more general Iteration Theorem, the real point here is really about more general domain knowledge.  It is central to what you do every day you are programming such as &lt;a href="http://en.wikipedia.org/wiki/Compiler"&gt;compilers&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Regular_expression"&gt;regular expressions&lt;/a&gt; not to mention the almost ubiquitous &lt;a href="http://en.wikipedia.org/wiki/Kleene_star"&gt;Kleene Star&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;a name="Information_Entropy" /&gt;&lt;br /&gt;
&lt;h2&gt;Information Entropy&lt;/h2&gt;&lt;br /&gt;
&lt;p&gt;I confess after all my machinations to try to reduce Demorgan’s Laws down to less equations I am totally cheating here by pulling a twofer in including two formulas, both &lt;a href="http://en.wikipedia.org/wiki/Information_theory"&gt;Shannon’s Information Theory&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-m_cV_hocRqs/TtKpQmDQxhI/AAAAAAAAAR8/QZ2IEXBTCFA/s1600/Shannon.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="37" width="285" src="http://3.bp.blogspot.com/-m_cV_hocRqs/TtKpQmDQxhI/AAAAAAAAAR8/QZ2IEXBTCFA/s400/Shannon.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;And the formula for &lt;a href="http://en.wikipedia.org/wiki/Chaitin's_constant"&gt;Chaitin’s Constant&lt;/a&gt;, which is associated with &lt;a href="http://en.wikipedia.org/wiki/Algorithmic_information_theory"&gt;Algorithmic Information Theory&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Kolmogorov_complexity"&gt;Kolmogorov Complexity&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-f2pTyVUHz3Y/TtKpUIJ8J4I/AAAAAAAAASI/8VX0MsTzeqQ/s1600/Chaitin.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="39" width="114" src="http://1.bp.blogspot.com/-f2pTyVUHz3Y/TtKpUIJ8J4I/AAAAAAAAASI/8VX0MsTzeqQ/s400/Chaitin.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Interestingly this area has a parallel in the physical word, in terms of &lt;a href="http://en.wikipedia.org/wiki/Entropy"&gt;Thermodynamic Entropy&lt;/a&gt;, which also parallels the &lt;a href="http://en.wikipedia.org/wiki/Boltzmann%27s_entropy_formula"&gt;Boltzman Equation&lt;/a&gt; mentioned in the Wired Article.  &lt;a href="http://arxiv.org/abs/quant-ph/9908043"&gt;Seth Loyd&lt;/a&gt; draws some interesting &lt;a href="http://en.wikipedia.org/wiki/Limits_to_computation"&gt;connections&lt;/a&gt; between computation and the physical world&lt;a/&gt; including Entropy and Boltzman’s Equation.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;In programming and computer science information is our business and these ideas are central to many things that we deal with especially the storage, transmission, computational transformation (like &lt;a href="http://mattmahoney.net/dc/dce.html?year=2011#Section_1"&gt;compression&lt;/a&gt;), and computation of information.  We’ve already seen the possible relationship between both of these theories and Reusability and &lt;a href="http://www.elegantcoding.com/2011/07/software-frameworks-resistance-isnt.html"&gt;Software Frameworks&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Bayes_Theorem" /&gt;&lt;br /&gt;
&lt;h2&gt;Bayes' Theorem&lt;/h2&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-YVZ2X0--nbo/TtKpYN2GRBI/AAAAAAAAASU/2YYh8v7eKxs/s1600/bayes.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="39" width="205" src="http://3.bp.blogspot.com/-YVZ2X0--nbo/TtKpYN2GRBI/AAAAAAAAASU/2YYh8v7eKxs/s400/bayes.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Of all of equations on the list, &lt;a href="http://en.wikipedia.org/wiki/Bayes'_theorem"&gt;Bayes' Theorem &lt;/a&gt; may stand out on its own merits as being one of the most recognizable and it might even qualify as a poster child for the statistical revolution sweeping our industry.  It rose from obscurity to being used for &lt;a href="http://www.paulgraham.com/better.html"&gt;spam detection&lt;/a&gt; and with such applications as &lt;a href="http://en.wikipedia.org/wiki/Classifier_(mathematics)"&gt;classifiers&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Machine_learning"&gt;Machine Learning&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Data_mining"&gt;Data Mining&lt;/a&gt; and more.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Mathematically it is part of a &lt;a href="http://en.wikipedia.org/wiki/Probability_interpretations"&gt;rift&lt;/a&gt; in statistics and probability and I confess I may not yet call myself "&lt;a href="http://www.codinghorror.com/blog/2007/04/an-initiate-of-the-bayesian-conspiracy.html"&gt;an initiate of the bayesian conspiracy&lt;/a&gt;" but it hard to deny its utility plus there seems to be a more axiomatic basis that relates to Boolean Logic Set Theory, which makes it all the more alluring.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Fermats_Little_Theorem" /&gt;&lt;br /&gt;
&lt;h2&gt;Fermat’s Little Theorem&lt;/h2&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-E9IYaI654Aw/TtKpfbPogDI/AAAAAAAAASg/2DbPQBe7kwU/s1600/Fermat1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="22" width="309" src="http://2.bp.blogspot.com/-E9IYaI654Aw/TtKpfbPogDI/AAAAAAAAASg/2DbPQBe7kwU/s400/Fermat1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-nGl3qvRHqHA/TtKpjbK9n5I/AAAAAAAAASs/aMpMSBGczgY/s1600/Fermat2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="20" width="291" src="http://3.bp.blogspot.com/-nGl3qvRHqHA/TtKpjbK9n5I/AAAAAAAAASs/aMpMSBGczgY/s400/Fermat2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;These two equations of &lt;a href="http://en.wikipedia.org/wiki/Fermat%27s_little_theorem"&gt;Fermat’s Little Theorem&lt;/a&gt; are really the same equation written in two different forms, where (a &amp;perp; p) means coprime and (p &amp;isin; P) means prime.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;This is a beautiful little theorem in &lt;a href="http://en.wikipedia.org/wiki/Number_theory"&gt;Number Theory&lt;/a&gt; which can be generalized and written even more succinctly using &lt;a href="http://en.wikipedia.org/wiki/Euler%27s_totient_function"&gt;Eulers Totient Function&lt;/a&gt; which is represented by &amp;phi; (n): &lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Qhxat4y8d-g/TtKpzVUmQRI/AAAAAAAAAS4/R5MEoWwk7As/s1600/totient.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="25" width="165" src="http://4.bp.blogspot.com/-Qhxat4y8d-g/TtKpzVUmQRI/AAAAAAAAAS4/R5MEoWwk7As/s400/totient.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;These ideas are crucial for understanding encryption algorithms like &lt;a href="http://en.wikipedia.org/wiki/RSA_(algorithm)#Proof_using_Fermat.27s_Little_Theorem_and_Chinese_Remainder_Theorem"&gt;RSA&lt;/a&gt; and there’s this &lt;a href="http://en.wikipedia.org/wiki/Recurring_decimal#Fractions_with_prime_denominators"&gt;cool result&lt;/a&gt;.&lt;/p&gt;&lt;a name="Natural_Join" /&gt;&lt;br /&gt;
&lt;h2&gt;Natural Join&lt;/h2&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-7E5rRgqBA1A/TtKp2w-D_ZI/AAAAAAAAATE/Ca9H0XCsqZE/s1600/NatL.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="20" width="213" src="http://3.bp.blogspot.com/-7E5rRgqBA1A/TtKp2w-D_ZI/AAAAAAAAATE/Ca9H0XCsqZE/s400/NatL.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Relational_algebra"&gt;Natural Join&lt;/a&gt;, like all of the Relational Algebra Join Operations is a composition of the more basic, operations: Selection (&amp;sigma;), Projection (&amp;pi;), Cartesian Product (&amp;times;), Set Difference (-) and Union (&amp;cup;).  Natural Join is the Cartesian Product of two tables selecting matching rows and eliminating duplicate columns.  (In the formula above the projection (&amp;pi;) is the set (A) of attributes with duplicates removed and then selects (&amp;sigma;) the set (C) of common attributes which match in both sets and are equal in both sets.)&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The Relational Algebra is in my opinion a bit of an odd beast when it comes to algebraic structures, but if you use SQL you are already using an implementation of it.  As data persistence becomes more heterogeneous I think understanding these concepts, will become more important.  Additionally Relational Algebra also has strong ties to Abstract Algebra[&lt;/a&gt; and Category Theory[&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Fixed_Point_Combinator" /&gt;&lt;br /&gt;
&lt;h2&gt;The Fixed-Point (Y) Combinator&lt;/h2&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-JsWDcsVPJzM/TtKp8xuLctI/AAAAAAAAATQ/lyHdEG0gJxQ/s1600/Y.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="17" width="227" src="http://3.bp.blogspot.com/-JsWDcsVPJzM/TtKp8xuLctI/AAAAAAAAATQ/lyHdEG0gJxQ/s400/Y.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Just as we need a "equation" from Formal Language Theory or Automata Theory we really should have one that is related to &lt;a href="http://en.wikipedia.org/wiki/Lambda_calculus"&gt;Lambda Calculus&lt;/a&gt;, in this case this equation is in the untyped lambda calculus.  Even though the &lt;a href="http://en.wikipedia.org/wiki/Fixed-point_combinator"&gt;Fixed-point Combinator&lt;/a&gt; stands up on its own, it is fairly well known, well at least in name due to the use of it by &lt;a href="http://www.paulgraham.com/"&gt;Paul Graham&lt;/a&gt; for his incubator (&lt;a href="http://ycombinator.com/"&gt;Y-Combinator&lt;/a&gt;). &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;The Fixed-Point Combinator allows one to implement anonymous recursion which is a powerful programming technique.  It also ties into some deeper theoretical aspects of computer science and logic such as &lt;a href="http://en.wikipedia.org/wiki/Combinatory_logic"&gt;Combinatory Logic&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;a name="O_n" /&gt;&lt;br /&gt;
&lt;h2&gt;O(n)&lt;/h2&gt;&lt;br /&gt;
&lt;p&gt;Many CS majors may cringe at this, and another possible reaction is that’s not much of an equation.  There’s actually quite a bit to this for example did you know there are some substantial and quite beautiful equations associated with this seemingly simple formula.  They are:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-rRTU9GHz7Xg/TtKqOF2ceiI/AAAAAAAAATc/9FlV0g1SFvk/s1600/On1.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="20" width="379" src="http://1.bp.blogspot.com/-rRTU9GHz7Xg/TtKqOF2ceiI/AAAAAAAAATc/9FlV0g1SFvk/s400/On1.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-hMQPlPgOuFo/TtKqVQcSoxI/AAAAAAAAATo/Jizwxovmqrc/s1600/On2.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="47" width="333" src="http://4.bp.blogspot.com/-hMQPlPgOuFo/TtKqVQcSoxI/AAAAAAAAATo/Jizwxovmqrc/s400/On2.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Also the following is a definition of (lim sup) &lt;a href="http://en.wikipedia.org/wiki/Limit_superior_and_limit_inferior"&gt;Limit Superior&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-BVsnr6J9H74/TtKq3QzX7JI/AAAAAAAAAUM/hm4TY-HM9HY/s1600/limitsup.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="32" width="364" src="http://1.bp.blogspot.com/-BVsnr6J9H74/TtKq3QzX7JI/AAAAAAAAAUM/hm4TY-HM9HY/s400/limitsup.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;Where inf is &lt;a href="http://en.wikipedia.org/wiki/Infimum"&gt;infimum&lt;/a&gt; and sup is &lt;a href="http://en.wikipedia.org/wiki/Supremum"&gt;supremum&lt;/a&gt; two concepts that seem to show up quite a bit especially when you are concerned with bounds like with &lt;a href="http://en.wikipedia.org/wiki/Lattice_(order)"&gt;Lattices&lt;/a&gt; and they also seem to show up in relation to &lt;a href="http://en.wikipedia.org/wiki/Topology"&gt;Topology&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;And we all know why we should care about his one: Algorithms, Algorithms, Algorithms.&lt;/p&gt;&lt;br /&gt;
&lt;a name="Eulers_Identity" /&gt;&lt;br /&gt;
&lt;h2&gt;Euler’s Identity&lt;/h2&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-sOx8imv9krw/TtKqawS-K3I/AAAAAAAAAT0/9uKKqYfa85o/s1600/Euler-identy.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="19" width="91" src="http://2.bp.blogspot.com/-sOx8imv9krw/TtKqawS-K3I/AAAAAAAAAT0/9uKKqYfa85o/s400/Euler-identy.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Euler's_identity"&gt;Euler’s Identity&lt;/a&gt; is also listed in Wired’s article and I have to agree that it is one the most beautiful and intriguing formulas in math.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Now this isn’t really as relevant to CS as the other formulas but if you a true computer geek you are hopefully some kind of math geek, and this is such a great formula, not to mention that it appears in &lt;a href="http://en.wikipedia.org/wiki/Treehouse_of_Horror_VI"&gt;The Simpsons' Homer&lt;sup&gt;3&lt;/sup&gt;&lt;/a&gt;. It’s actually a specific case (where &amp;theta; = &amp;pi;) of &lt;a href="http://en.wikipedia.org/wiki/Euler%27s_formula"&gt;Euler’s Formula&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-908bQxyVSy4/TtKqfsHyYYI/AAAAAAAAAUA/zhSF4l1luVA/s1600/Euler-form.png" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="20" width="157" src="http://1.bp.blogspot.com/-908bQxyVSy4/TtKqfsHyYYI/AAAAAAAAAUA/zhSF4l1luVA/s400/Euler-form.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;These formulas will give one a better understanding complex numbers which are needed in other areas of advanced math also these formulas relate to &lt;a href="http://en.wikipedia.org/wiki/Fourier_analysis"&gt;Fourier Analysis&lt;/a&gt; which does have applications in Computer Science.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;I am curious to see how well this list holds up, how will I feel about it in a year?  Also in writing this I realized that I still have quite a bit more to learn about at least half of this list, if not all of it, which made it hard to write as it was quite a little (unfinished) research project. I have already written individual articles on several of these equations and have at least two in the works for Linear Algebra, at least two on the Relational Algebra and one planned for Pascal’s Triangle, and those are just the ideas I’ve already had, who knows what the future holds.  I hope you enjoyed it as much as I did writing it. &lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;sup&gt;&amp;dagger;&lt;/sup&gt; The Set version may not apply to all cases in set theory, this assumes Union and Intersection over the &lt;a href="http://en.wikipedia.org/wiki/Power_set"&gt;Power Set&lt;/a&gt; of a &lt;a href="http://en.wikipedia.org/wiki/Universe_(mathematics)#In_set_theory"&gt;Set Universe&lt;/a&gt;, this would be &lt;a href="http://en.wikipedia.org/wiki/Closure_(mathematics)"&gt;closed&lt;/a&gt; under these operations and would include complements of all elements.  The Set Universe is the upper bound and the empty set is the lower bound.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ElegantCoding/~4/yirsKBYjuA8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ElegantCoding/~3/yirsKBYjuA8/eleven-equations-true-computer-science.html</link><author>noreply@blogger.com (Geoff Moes)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-O4a_eSkqeNE/TtKrcgal6zI/AAAAAAAAAUY/C8P7Ex09bhk/s72-c/Bayes%2527_Theorem_MMB_01.1.jpg" height="72" width="72" /><thr:total>39</thr:total><feedburner:origLink>http://www.elegantcoding.com/2011/11/eleven-equations-true-computer-science.html</feedburner:origLink></item></channel></rss>
