<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>larr&#x03bb;theliquid -&gt; Lemma the Ultimate</title>
  <link href="http://feeds.feedburner.com/lemmatheultimate" rel="self"/>
  <link href="http://lemmatheultimate.com"/>
  <updated></updated>
  <id>http://lemmatheultimate.com</id>
  <author>
    <name>Larry Diehl</name>
    <email>larrytheliquid@gmail.com</email>
  </author>
  
  <entry>
    <title>Progress Report & LCHI</title>
    <link href="http://lemmatheultimate.com/2009/11/02/progress-report-and-lchi/"/>
    <updated>2009-11-02T00:00:00-08:00</updated>
    <id>http://lemmatheultimate.com/2009/11/02/progress-report-and-lchi</id>
    <content type="html">&lt;h2 id='progress_report__lchi'&gt;Progress Report &amp;amp; LCHI&lt;/h2&gt;

&lt;h3 id='recap'&gt;Recap&lt;/h3&gt;

&lt;p&gt;After having gotten through chapters 0-3 of the &lt;a href='http://www.cs.swan.ac.uk/~csetzer/lectures/intertheo/07/interactiveTheoremProvingForAgdaUsers.html'&gt;Agda Course&lt;/a&gt;, my original plan was to keep charging through chapters 4-6. However, during the process of writing an &lt;a href='http://lemmatheultimate.com/2009/10/24/intro-to-proofs-as-programs/'&gt;intro to proofs-as-programs&lt;/a&gt; I began to notice something that bothered me. In various pieces of literature covering this domain, the notions of axioms, postulates, and judgments are used with different meanings and not clearly elaborated. Additionally, precisely defining how the previous terms and implication relate to one another is tricky. I wanted to write a post that clearly explained how these things related to one another, but I did not have enough background knowledge to do so. One quality of this field is that things are usually precisely defined, so getting away with wishy-washy explanations or guesses doesn&amp;#8217;t work =)&lt;/p&gt;

&lt;h3 id='exploring_fundamentals'&gt;Exploring Fundamentals&lt;/h3&gt;

&lt;p&gt;Rather than continuing with the Agda course, I have begun to brush up on fundamentals by reading through &lt;a href='http://www.elsevier.com/wps/find/bookdescription.cws_home/706927/description#description'&gt;LCHI&lt;/a&gt;. Even though each chapter is only 20 pages, the book is packed densely with information and references a lot of discrete topics that I&amp;#8217;ve had to refresh my memory of (and sometimes learn).. so it&amp;#8217;s a slow but enlightening read. I&amp;#8217;ve finished the first chapter, which explains the &lt;em&gt;untyped lambda calculus&lt;/em&gt;, but does so formally in terms of what the book calls &lt;em&gt;pre-terms&lt;/em&gt;. The purpose of this is to define &lt;em&gt;lambda terms&lt;/em&gt; as &lt;em&gt;alpha-conversion&lt;/em&gt; &lt;a href='http://en.wikipedia.org/wiki/Equivalence_class'&gt;equivalence classes&lt;/a&gt; of pre-terms, avoiding the handwavy notion of just &lt;em&gt;identifying&lt;/em&gt; alpha-equivalent terms. It&amp;#8217;s a pretty neat formulation, and other equivalence relations like &lt;em&gt;beta&lt;/em&gt; and &lt;em&gt;eta&lt;/em&gt; are defined on these lambda-term sets.&lt;/p&gt;

&lt;h3 id='next_up'&gt;Next Up&lt;/h3&gt;

&lt;p&gt;I&amp;#8217;m in the middle of chapter 2 right now, which is on &lt;a href='http://en.wikipedia.org/wiki/Intuitionistic_logic'&gt;intuitionistic logic&lt;/a&gt;. My plan is to finish this chapter as well as chapters 3 and 4 on the &lt;em&gt;simply typed lambda-calculus&lt;/em&gt; and the &lt;em&gt;Curry-Howard Isomorphism&lt;/em&gt; respectively. As I&amp;#8217;m reading this I&amp;#8217;m taking notes that will be used for a post that clarifies the relationship between axioms, judgments, and implication that I mentioned earlier. In particular, chapter 2&amp;#8217;s &lt;a href='http://en.wikipedia.org/wiki/Natural_deduction'&gt;natural deduction&lt;/a&gt; explanation as a formal version of the &lt;a href='http://en.wikipedia.org/wiki/Brouwer%E2%80%93Heyting%E2%80%93Kolmogorov_interpretation'&gt;BHK intepretation&lt;/a&gt; of logical connectives in intuitionistic logic includes a simple definition of implication in terms of judgments (in the &lt;em&gt;introduction&lt;/em&gt; and &lt;em&gt;elimination&lt;/em&gt; rules). With chapters 1-4 done I think I&amp;#8217;ll be able to write the aforementioned post and be able to sleep soundly about the explanation. Once again, although I&amp;#8217;m already familiar with the topics covered, the level of precision used in LCHI makes it a slow but gratifying read&amp;#8230; highly recommended if you have the will-power =)&lt;/p&gt;</content>
  </entry>
  
  <entry>
    <title>Intro to Proofs-as-Programs</title>
    <link href="http://lemmatheultimate.com/2009/10/24/intro-to-proofs-as-programs/"/>
    <updated>2009-10-24T00:00:00-07:00</updated>
    <id>http://lemmatheultimate.com/2009/10/24/intro-to-proofs-as-programs</id>
    <content type="html">&lt;h2 id='intro_to_proofsasprograms'&gt;Intro to Proofs-as-Programs&lt;/h2&gt;

&lt;h3 id='foreword'&gt;Foreword&lt;/h3&gt;

&lt;p&gt;This post is meant as a very basic introduction to the notion of Proofs-as-Programs. Like many fields, herein lie simple concepts that are obscured by notation and vocabulary, so I try to point out synonyms where possible to avoid future confusion. &lt;a href='http://wiki.portal.chalmers.se/agda'&gt;Agda&lt;/a&gt; is used to explain these concepts as realized in an actual programming language.&lt;/p&gt;

&lt;h3 id='proofsasprograms'&gt;Proofs-as-Programs&lt;/h3&gt;

&lt;p&gt;Proofs are a formal topic requiring a lot of background knowledge and experience in math and logic. Due to this, many programmers get turned off when the word &lt;em&gt;proof&lt;/em&gt; is uttered. As it turns out, an elegant analogy exists called the &lt;a href='http://en.wikipedia.org/wiki/Curry%E2%80%93Howard_correspondence'&gt;Curry-Howard Isomorphism&lt;/a&gt;. The basic idea is that &lt;em&gt;values&lt;/em&gt; are to &lt;em&gt;types&lt;/em&gt; as &lt;em&gt;proofs&lt;/em&gt; are to &lt;em&gt;formulae&lt;/em&gt;. With this stunningly simple correspondence, it is possible to reuse years of programmer experience in typed languages and get those programmers on the path to theorem proving. What follows explains a different way to think about programming, from the eyes of a theorem prover. However, take notice that only basic standard programming concepts are utilized!&lt;/p&gt;

&lt;h3 id='getting_started'&gt;Getting Started&lt;/h3&gt;

&lt;p&gt;Programming is done in a logical system, therefore almost no functions or types exist at the onset. Proofs rely on incrementally building up knowledge from previous knowledge, therefore we must define all types and functions used ourselves in the language we are using (of course, source code for common types and functions can come as part of the language in its standard library). The canonical domain we will be using is that of natural numbers (integers from zero to infinity).&lt;/p&gt;

&lt;h3 id='defining_types'&gt;Defining Types&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;data Nat : Set where&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We start with the code above by creating a new type called &lt;code&gt;Nat&lt;/code&gt; representing the type of natural numbers. &lt;code&gt;Nat&lt;/code&gt; is assigned a new unique value of type &lt;code&gt;Set&lt;/code&gt;. If you think about it, a &lt;a href='http://www.lix.polytechnique.fr/~werner/publis/tacs97.pdf'&gt;type is a set&lt;/a&gt; whose elements are values of said type. Because of this, Agda uses &lt;code&gt;Set&lt;/code&gt; as the base type from which other types are born.&lt;/p&gt;

&lt;h3 id='defining_values_for_types'&gt;Defining Values For Types&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;data Nat : Set where
  zero : Nat&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Just as we created a new value of &lt;code&gt;Set&lt;/code&gt; called &lt;code&gt;Nat&lt;/code&gt;, we now create a new value of &lt;code&gt;Nat&lt;/code&gt; called &lt;code&gt;zero&lt;/code&gt;. In other words, &lt;code&gt;zero&lt;/code&gt; is a value whose type is &lt;code&gt;Nat&lt;/code&gt;. For all intents and purposes, you can think of this &lt;code&gt;zero&lt;/code&gt; as an atom in other programming languages. For now we will use this partial definition of the natural numbers set, consisting only of &lt;code&gt;zero&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id='value_judgments'&gt;Value Judgments&lt;/h3&gt;

&lt;p&gt;A &lt;em&gt;judgment&lt;/em&gt;/&lt;em&gt;assertion&lt;/em&gt; is a value/type pair, which asserts that the value is of its pairs type. It is the compiler&amp;#8217;s job to check if the value/type assertion is correct. If we adopt the mindset of proofs-as-programs, then a type is some formula that we wish to &lt;em&gt;derive&lt;/em&gt; with some proof in the form of a value.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;natsExist : Nat
natsExist = {!!}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Here we would like to prove the existence of natural numbers. We represent this as a variable with a type of &lt;code&gt;Nat&lt;/code&gt; that we must assign to some unknown. In other words, the &lt;em&gt;goal&lt;/em&gt; is to prove the existence of &lt;code&gt;Nat&lt;/code&gt; by assigning a value that matches the type of &lt;code&gt;Nat&lt;/code&gt;. Agda uses &lt;code&gt;{!!}&lt;/code&gt; as notation for a thus far unproven goal that you may use a placeholder when constructing your proofs.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;natsExist : Nat
natsExist = zero&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With the completion of our goal, we now have a &lt;em&gt;judgment&lt;/em&gt;. In order to see if a proof &amp;#8220;checks&amp;#8221;, the compiler makes use of what are called &lt;em&gt;inference rules&lt;/em&gt;. An &lt;em&gt;inference rule&lt;/em&gt; can have 0 or more &lt;em&gt;premises&lt;/em&gt;/&lt;em&gt;pre-conditions&lt;/em&gt; that must be met to &lt;em&gt;imply&lt;/em&gt;/&lt;em&gt;prove&lt;/em&gt;/&lt;em&gt;derive&lt;/em&gt; some conclusion. In our case the &lt;code&gt;zero : Nat&lt;/code&gt; judgment is derived by the &lt;code&gt;zero : Nat&lt;/code&gt; data type that we defined earlier, which acts as an inference rule with 0 premises. When this happens the compiler determines that our proof &amp;#8220;checked&amp;#8221; and &lt;code&gt;natsExist&lt;/code&gt; is assigned to a trusted proof of &lt;code&gt;Nat&lt;/code&gt;. In effect, it has itself become a new inference rule.&lt;/p&gt;

&lt;h3 id='teatime'&gt;Teatime&lt;/h3&gt;

&lt;p&gt;Take a moment to pause and reflect on the fact that we are merely discussing simple static type checking. Nevertheless, thinking of these things from the point of view of a theorem prover is a fun and enlightening exercise. However, this isn&amp;#8217;t just fun and games, as the simple analogy will let you make powerful claims once you learn more. Another insight to ponder is that the relationship between proofs and formulae is many-to-one. This is an important observation because it means that there are many ways to prove the same thing, making your chances of finding just 1 proof (that&amp;#8217;s all you need) greater.&lt;/p&gt;

&lt;h3 id='function_judgments'&gt;Function Judgments&lt;/h3&gt;

&lt;p&gt;Proving a value judgment was pretty easy, so let&amp;#8217;s try proving a function judgment. For this we will attempt to create a judgment &lt;code&gt;add&lt;/code&gt; representing the addition of 2 natural numbers.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;add : Nat -&amp;gt; Nat -&amp;gt; Nat
add = {!!}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As before, we start off with a type declaration and a goal. The type of &lt;code&gt;add&lt;/code&gt; indicates that it is a function which accepts a &lt;code&gt;Nat&lt;/code&gt;, which returns a function that again accepts a &lt;code&gt;Nat&lt;/code&gt;, which finally returns another &lt;code&gt;Nat&lt;/code&gt;. Before we go on, realize that the ultimate intent of this judgment is to prove the existence of &lt;code&gt;Nat&lt;/code&gt; (the same goal as the previous value judgment!)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;add : Nat -&amp;gt; Nat -&amp;gt; Nat
add = \(x : Nat) -&amp;gt; {!!}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After compiling, we are assured that the first premise has been proved via an anonymous function that accepts a &lt;code&gt;Nat&lt;/code&gt; as an argument. In order for this typed lambda judgment to be proved by the compiler, several built-in inference rules are used that correspond to the typed lambda calculus (although it&amp;#8217;s not necessary to understand these in detail, as the rules are intuitive&amp;#8230; no pun intended =).&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;add : Nat -&amp;gt; Nat -&amp;gt; Nat
add = \(x : Nat) -&amp;gt; \(y : Nat) -&amp;gt; {!!}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once again, the second typed lambda judgment we presented is verified by the compiler. Take a second to think about what this function has verified so far. One may jump to a conclusion and think that we already proved &lt;code&gt;Nat&lt;/code&gt; in the first argument, so why even prove it in the second argument and result? However, even at this step we haven&amp;#8217;t proved &lt;code&gt;Nat&lt;/code&gt;. Arguments in functions correspond to premises in induction rules (see the next paragraph).&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;add : Nat -&amp;gt; Nat -&amp;gt; Nat
add = \(x : Nat) -&amp;gt; \(y : Nat) -&amp;gt; natsExist&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Here we finally prove the conclusion (the return value), and we get to do it with the &lt;code&gt;natsExist&lt;/code&gt; proof we wrote earlier (&lt;code&gt;zero&lt;/code&gt; would have worked just as well)! But, realize that what we&amp;#8217;ve really done is created a new inference rule with 2 premises. Therefore, our proof of the conclusion is not valid unless 2 proofs for each premise are supplied. In this simplistic case all 3 judgments prove the same formula. Thus getting access to the return value proof is not particularly appealing as you already have at least 1 proof of the same formula supplied as the first argument of the function (recount that proofs to formulae are many-to-one).&lt;/p&gt;

&lt;h3 id='a_step_back'&gt;A Step Back&lt;/h3&gt;

&lt;p&gt;The power of proofs-as-programs is that you can encode more powerful constraints of functions and values into their types. The canonical example is (using &lt;em&gt;dependent types&lt;/em&gt;, a subject of a future post) a sorted list insertion function that guarantees that the returned list remains sorted (along with other properties you may want to ensure such as the size being preserved, elements being preserved, etc). That said, addition is simple enough that we merely want to use its return value for computation rather than for a proof of &lt;code&gt;Nat&lt;/code&gt;. The good thing is that you can decide where the boundaries lie between simple functions and types, and complicated functions that require type-based constraints (e.g. remaining &lt;a href='http://en.wikipedia.org/wiki/Don%27t_repeat_yourself'&gt;DRY&lt;/a&gt; through the use of various complex combinators, but ensuring the function does what you want in its type.&lt;/p&gt;

&lt;h3 id='completing_nat'&gt;Completing Nat&lt;/h3&gt;

&lt;p&gt;So far we&amp;#8217;ve worked with &lt;code&gt;Nat&lt;/code&gt; as an incomplete set (it only contains &lt;code&gt;zero&lt;/code&gt;), so let&amp;#8217;s fill the rest in.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;data Nat : Set where
  zero : Nat
  succ : Nat -&amp;gt; Nat&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The rest of &lt;code&gt;Nat&lt;/code&gt; is achieved via an inductive type definition, yielding an &lt;em&gt;inductive type&lt;/em&gt;. The similarity to mathematical induction should make sense to anyone with a CS background, but basically you can think of it like a recursive definition. So, &lt;code&gt;succ&lt;/code&gt; accepts another &lt;code&gt;Nat&lt;/code&gt; which may be &lt;code&gt;zero&lt;/code&gt; or another nested &lt;code&gt;succ&lt;/code&gt;, e.g. &lt;code&gt;succ (succ (succ zero))&lt;/code&gt; representing the natural number 3. The addition function we defined earlier still works because we chose a general type, but let&amp;#8217;s make it return what we intended. Before we do that, we will first rewrite the function to use a syntax sugared version that performs pattern matching on the lambda arguments.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;add : Nat -&amp;gt; Nat -&amp;gt; Nat
add x y = natsExist&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id='coverage_checking'&gt;Coverage Checking&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;add : Nat -&amp;gt; Nat -&amp;gt; Nat
add x zero = {!!}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you attempt to compile the above you get an error, but why? When we defined &lt;code&gt;Nat&lt;/code&gt; with the &lt;code&gt;data&lt;/code&gt; directive, we once and for all defined all possible values. Agda requires functions to be &lt;em&gt;coverage&lt;/em&gt; complete with respect to type values! Now that we switched to pattern matching on the specific value &lt;code&gt;zero&lt;/code&gt;, &lt;code&gt;Nat&lt;/code&gt; coverage checking fails and the compiler tells us to also define the function for the &lt;code&gt;succ&lt;/code&gt; case.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;add : Nat -&amp;gt; Nat -&amp;gt; Nat
add x zero = {!!}
add x (succ y) = {!!}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With coverage checking you are not only assured of compile-time type safety (only &lt;code&gt;Nat&lt;/code&gt;s), but also that functions are defined for all possible values of a type (you can still encode type-level restrictions as long as all cases are accounted for, but that is again a subject of another post).&lt;/p&gt;

&lt;h3 id='completing_add'&gt;Completing add&lt;/h3&gt;

&lt;p&gt;The actual function implementation isn&amp;#8217;t the purpose of the post, so I&amp;#8217;ll quickly list it here.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;add : Nat -&amp;gt; Nat -&amp;gt; Nat
add x zero = x
add x (succ y) = succ (add x y)&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id='axioms'&gt;Axioms&lt;/h3&gt;

&lt;p&gt;You may have noticed something fishy about the data type definitions. In particular, the definition for &lt;code&gt;zero&lt;/code&gt; is similar to &lt;code&gt;natsExist&lt;/code&gt;, but there is one key difference. Namely, &lt;code&gt;zero&lt;/code&gt; does not provide a proof/value of its formula/type. Defining something this way creates an &lt;em&gt;axiom&lt;/em&gt;/&lt;em&gt;postulate&lt;/em&gt;. Using &lt;code&gt;data&lt;/code&gt; actually creates a restricted postulate that does not allow types like &lt;code&gt;Nat&lt;/code&gt; to have additional values defined in them later (if this were allowed, any coverage-based reasoning would no longer be true). Additionally, the property of coverage is enforced in future functions (with respect to the values of the newly defined type) when you use &lt;code&gt;data&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id='qed'&gt;Q.E.D.&lt;/h3&gt;

&lt;p&gt;I hope you enjoyed this post, as that&amp;#8217;s it for now. Once again, the example code produced is trivial but necessarily so to explain the concepts. Proofs-as-programs starts to be a very powerful concept with the introduction of &lt;a href='http://en.wikipedia.org/wiki/Dependent_type'&gt;Dependent types&lt;/a&gt;&amp;#8230; be patient as that post will come later =)&lt;/p&gt;

&lt;h3 id='bonus_syntax_sugar'&gt;Bonus: Syntax Sugar&lt;/h3&gt;

&lt;p&gt;Agda also let&amp;#8217;s us write prettier code with unicode and mixfix operators. I left this out until now to avoid cluttering the explanation of more important concepts.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;data ℕ : Set where
  zero : ℕ
  succ : ℕ → ℕ

_+_ : ℕ → ℕ → ℕ
x + zero = x
x + succ y = succ (x + y)

succ2 : ℕ → ℕ
succ2 = λ x → x + (succ (succ zero))&lt;/code&gt;&lt;/pre&gt;</content>
  </entry>
  
  <entry>
    <title>AgdaSpec Hackery</title>
    <link href="http://lemmatheultimate.com/2009/10/23/agda-spec-hackery/"/>
    <updated>2009-10-23T00:00:00-07:00</updated>
    <id>http://lemmatheultimate.com/2009/10/23/agda-spec-hackery</id>
    <content type="html">
&lt;h2&gt;AgdaSpec Hackery&lt;/h2&gt;

&lt;h3&gt;AgdaSpec Examples&lt;/h3&gt;

&lt;p&gt;I played around with the idea of writing a friendly &lt;a href=&quot;http://rspec.info/&quot;&gt;RSpec&lt;/a&gt;-like dsl for &lt;a href=&quot;http://wiki.portal.chalmers.se/agda/&quot;&gt;Agda&lt;/a&gt;. You can see the result below. It was just some late-night experimentation and I have been concentrating more on catching up on Lambda-Calculus, logic, and theorem proving fundamentals, so consider it less than a proof-of-concept for now. That said, I plan to come back to the idea of a more friendly dsl for Curry-Howard testing including universals once I'm more experienced.&lt;/p&gt;

&lt;pre
    &gt;&lt;a name=&quot;1&quot; class=&quot;Keyword&quot;
      &gt;module&lt;/a
      &gt;&lt;a name=&quot;7&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;8&quot; href=&quot;UsingAgdaSpec.html#8&quot; class=&quot;Module&quot;
      &gt;UsingAgdaSpec&lt;/a
      &gt;&lt;a name=&quot;21&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;22&quot; class=&quot;Keyword&quot;
      &gt;where&lt;/a
      &gt;&lt;a name=&quot;27&quot;
      &gt;
&lt;/a
      &gt;&lt;a name=&quot;28&quot; class=&quot;Keyword&quot;
      &gt;open&lt;/a
      &gt;&lt;a name=&quot;32&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;33&quot; class=&quot;Keyword&quot;
      &gt;import&lt;/a
      &gt;&lt;a name=&quot;39&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;40&quot; href=&quot;AgdaSpec.html#8&quot; class=&quot;Module&quot;
      &gt;AgdaSpec&lt;/a
      &gt;&lt;a name=&quot;48&quot;
      &gt;

&lt;/a
      &gt;&lt;a name=&quot;50&quot; class=&quot;Keyword&quot;
      &gt;data&lt;/a
      &gt;&lt;a name=&quot;54&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;55&quot; href=&quot;UsingAgdaSpec.html#55&quot; class=&quot;Datatype&quot;
      &gt;Nat&lt;/a
      &gt;&lt;a name=&quot;58&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;59&quot; class=&quot;Symbol&quot;
      &gt;:&lt;/a
      &gt;&lt;a name=&quot;60&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;61&quot; class=&quot;PrimitiveType&quot;
      &gt;Set&lt;/a
      &gt;&lt;a name=&quot;64&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;65&quot; class=&quot;Keyword&quot;
      &gt;where&lt;/a
      &gt;&lt;a name=&quot;70&quot;
      &gt;
  &lt;/a
      &gt;&lt;a name=&quot;73&quot; href=&quot;UsingAgdaSpec.html#73&quot; class=&quot;InductiveConstructor&quot;
      &gt;zero&lt;/a
      &gt;&lt;a name=&quot;77&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;78&quot; class=&quot;Symbol&quot;
      &gt;:&lt;/a
      &gt;&lt;a name=&quot;79&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;80&quot; href=&quot;UsingAgdaSpec.html#55&quot; class=&quot;Datatype&quot;
      &gt;Nat&lt;/a
      &gt;&lt;a name=&quot;83&quot;
      &gt;
  &lt;/a
      &gt;&lt;a name=&quot;86&quot; href=&quot;UsingAgdaSpec.html#86&quot; class=&quot;InductiveConstructor&quot;
      &gt;succ&lt;/a
      &gt;&lt;a name=&quot;90&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;91&quot; class=&quot;Symbol&quot;
      &gt;:&lt;/a
      &gt;&lt;a name=&quot;92&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;93&quot; href=&quot;UsingAgdaSpec.html#55&quot; class=&quot;Datatype&quot;
      &gt;Nat&lt;/a
      &gt;&lt;a name=&quot;96&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;97&quot; class=&quot;Symbol&quot;
      &gt;-&amp;gt;&lt;/a
      &gt;&lt;a name=&quot;99&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;100&quot; href=&quot;UsingAgdaSpec.html#55&quot; class=&quot;Datatype&quot;
      &gt;Nat&lt;/a
      &gt;&lt;a name=&quot;103&quot;
      &gt;

&lt;/a
      &gt;&lt;a name=&quot;105&quot; class=&quot;Comment&quot;
      &gt;-- Equal terms compile&lt;/a
      &gt;&lt;a name=&quot;127&quot;
      &gt;
&lt;/a
      &gt;&lt;a name=&quot;128&quot; class=&quot;Keyword&quot;
      &gt;postulate&lt;/a
      &gt;&lt;a name=&quot;137&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;138&quot; href=&quot;UsingAgdaSpec.html#138&quot; class=&quot;Postulate&quot;
      &gt;zeroEqualsZero&lt;/a
      &gt;&lt;a name=&quot;152&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;153&quot; class=&quot;Symbol&quot;
      &gt;:&lt;/a
      &gt;&lt;a name=&quot;154&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;155&quot; href=&quot;AgdaSpec.html#146&quot; class=&quot;Datatype Operator&quot;
      &gt;specify&lt;/a
      &gt;&lt;a name=&quot;162&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;163&quot; href=&quot;UsingAgdaSpec.html#73&quot; class=&quot;InductiveConstructor&quot;
      &gt;zero&lt;/a
      &gt;&lt;a name=&quot;167&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;168&quot; href=&quot;AgdaSpec.html#146&quot; class=&quot;Datatype Operator&quot;
      &gt;and&lt;/a
      &gt;&lt;a name=&quot;171&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;172&quot; href=&quot;UsingAgdaSpec.html#73&quot; class=&quot;InductiveConstructor&quot;
      &gt;zero&lt;/a
      &gt;&lt;a name=&quot;176&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;177&quot; href=&quot;AgdaSpec.html#146&quot; class=&quot;Datatype Operator&quot;
      &gt;are&lt;/a
      &gt;&lt;a name=&quot;180&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;181&quot; href=&quot;AgdaSpec.html#24&quot; class=&quot;Function&quot;
      &gt;equal&lt;/a
      &gt;&lt;a name=&quot;186&quot;
      &gt;
&lt;/a
      &gt;&lt;a name=&quot;187&quot; class=&quot;Keyword&quot;
      &gt;postulate&lt;/a
      &gt;&lt;a name=&quot;196&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;197&quot; href=&quot;UsingAgdaSpec.html#197&quot; class=&quot;Postulate&quot;
      &gt;oneEqualsOne&lt;/a
      &gt;&lt;a name=&quot;209&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;210&quot; class=&quot;Symbol&quot;
      &gt;:&lt;/a
      &gt;&lt;a name=&quot;211&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;212&quot; href=&quot;AgdaSpec.html#146&quot; class=&quot;Datatype Operator&quot;
      &gt;specify&lt;/a
      &gt;&lt;a name=&quot;219&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;220&quot; class=&quot;Symbol&quot;
      &gt;(&lt;/a
      &gt;&lt;a name=&quot;221&quot; href=&quot;UsingAgdaSpec.html#86&quot; class=&quot;InductiveConstructor&quot;
      &gt;succ&lt;/a
      &gt;&lt;a name=&quot;225&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;226&quot; href=&quot;UsingAgdaSpec.html#73&quot; class=&quot;InductiveConstructor&quot;
      &gt;zero&lt;/a
      &gt;&lt;a name=&quot;230&quot; class=&quot;Symbol&quot;
      &gt;)&lt;/a
      &gt;&lt;a name=&quot;231&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;232&quot; href=&quot;AgdaSpec.html#146&quot; class=&quot;Datatype Operator&quot;
      &gt;and&lt;/a
      &gt;&lt;a name=&quot;235&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;236&quot; class=&quot;Symbol&quot;
      &gt;(&lt;/a
      &gt;&lt;a name=&quot;237&quot; href=&quot;UsingAgdaSpec.html#86&quot; class=&quot;InductiveConstructor&quot;
      &gt;succ&lt;/a
      &gt;&lt;a name=&quot;241&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;242&quot; href=&quot;UsingAgdaSpec.html#73&quot; class=&quot;InductiveConstructor&quot;
      &gt;zero&lt;/a
      &gt;&lt;a name=&quot;246&quot; class=&quot;Symbol&quot;
      &gt;)&lt;/a
      &gt;&lt;a name=&quot;247&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;248&quot; href=&quot;AgdaSpec.html#146&quot; class=&quot;Datatype Operator&quot;
      &gt;are&lt;/a
      &gt;&lt;a name=&quot;251&quot;
      &gt; &lt;/a
      &gt;&lt;a name=&quot;252&quot; href=&quot;AgdaSpec.html#24&quot; class=&quot;Function&quot;
      &gt;equal&lt;/a
      &gt;&lt;a name=&quot;257&quot;
      &gt;

&lt;/a
      &gt;&lt;a name=&quot;259&quot; class=&quot;Comment&quot;
      &gt;-- Unequal terms raise compilation errors  (uncomment line below to see said errors shown in the comments for convenience)&lt;/a
      &gt;&lt;a name=&quot;324&quot;
      &gt;
&lt;/a
      &gt;&lt;a name=&quot;325&quot; class=&quot;Comment&quot;
      &gt;-- postulate zeroEqualsOne : specify zero and (succ zero) are equal&lt;/a
      &gt;&lt;a name=&quot;392&quot;
      &gt;

&lt;/a
      &gt;&lt;a name=&quot;394&quot; class=&quot;Comment&quot;
      &gt;-- zero != succ zero of type Nat&lt;/a
      &gt;&lt;a name=&quot;426&quot;
      &gt;
&lt;/a
      &gt;&lt;a name=&quot;427&quot; class=&quot;Comment&quot;
      &gt;-- when checking that the expression equal has type&lt;/a
      &gt;&lt;a name=&quot;478&quot;
      &gt;
&lt;/a
      &gt;&lt;a name=&quot;479&quot; class=&quot;Comment&quot;
      &gt;-- Expectation zero &amp;#8594; Expectation (succ zero)&lt;/a
      &gt;&lt;/pre
    &gt;

&lt;h3&gt;Implementation&lt;/h3&gt;

&lt;p&gt;The nice thing about the code above is that &lt;code&gt;equals&lt;/code&gt; is merely a function that conforms to the type signature of a binary relation (in other words, a single argument function). That means you can define arbitary functions easily to extend the &quot;library&quot; with other custom &quot;matchers&quot;. The &quot;specs&quot; are run at compile time, which means you don't get code back unless your tests pass. Additionally, tests will return proofs of their type-based specifications, which means you could reuse them compositionally to produce more complex tests/specs. Finally, the dsl'ish trick is accomplished by using a mixfix function definition in Agda via underscores in the name.&lt;/p&gt;

&lt;pre&gt;&lt;a name=&quot;1&quot; class=&quot;Keyword&quot;
        &gt;module&lt;/a
        &gt;&lt;a name=&quot;7&quot;
        &gt; &lt;/a
        &gt;&lt;a name=&quot;8&quot; href=&quot;AgdaSpec.html#8&quot; class=&quot;Module&quot;
        &gt;AgdaSpec&lt;/a
        &gt;&lt;a name=&quot;16&quot;
        &gt; &lt;/a
        &gt;&lt;a name=&quot;17&quot; class=&quot;Keyword&quot;
        &gt;where&lt;/a
        &gt;&lt;a name=&quot;22&quot;
        &gt;

&lt;/a
&gt;&lt;a name=&quot;24&quot; href=&quot;AgdaSpec.html#24&quot; class=&quot;Function&quot;
&gt;equal&lt;/a
&gt;&lt;a name=&quot;29&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;30&quot; class=&quot;Symbol&quot;
&gt;:&lt;/a
&gt;&lt;a name=&quot;31&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;32&quot; class=&quot;Symbol&quot;
&gt;{&lt;/a
&gt;&lt;a name=&quot;33&quot; href=&quot;AgdaSpec.html#33&quot; class=&quot;Bound&quot;
&gt;Poly&lt;/a
&gt;&lt;a name=&quot;37&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;38&quot; class=&quot;Symbol&quot;
&gt;:&lt;/a
&gt;&lt;a name=&quot;39&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;40&quot; class=&quot;PrimitiveType&quot;
&gt;Set&lt;/a
&gt;&lt;a name=&quot;43&quot; class=&quot;Symbol&quot;
&gt;}&lt;/a
&gt;&lt;a name=&quot;44&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;45&quot; class=&quot;Symbol&quot;
&gt;-&amp;gt;&lt;/a
&gt;&lt;a name=&quot;47&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;48&quot; href=&quot;AgdaSpec.html#33&quot; class=&quot;Bound&quot;
&gt;Poly&lt;/a
&gt;&lt;a name=&quot;52&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;53&quot; class=&quot;Symbol&quot;
&gt;-&amp;gt;&lt;/a
&gt;&lt;a name=&quot;55&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;56&quot; href=&quot;AgdaSpec.html#33&quot; class=&quot;Bound&quot;
&gt;Poly&lt;/a
&gt;&lt;a name=&quot;60&quot;
&gt;
&lt;/a
&gt;&lt;a name=&quot;61&quot; href=&quot;AgdaSpec.html#24&quot; class=&quot;Function&quot;
&gt;equal&lt;/a
&gt;&lt;a name=&quot;66&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;67&quot; href=&quot;AgdaSpec.html#67&quot; class=&quot;Bound&quot;
&gt;identity&lt;/a
&gt;&lt;a name=&quot;75&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;76&quot; class=&quot;Symbol&quot;
&gt;=&lt;/a
&gt;&lt;a name=&quot;77&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;78&quot; href=&quot;AgdaSpec.html#67&quot; class=&quot;Bound&quot;
&gt;identity&lt;/a
&gt;&lt;a name=&quot;86&quot;
&gt;

&lt;/a
&gt;&lt;a name=&quot;88&quot; class=&quot;Keyword&quot;
&gt;data&lt;/a
&gt;&lt;a name=&quot;92&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;93&quot; href=&quot;AgdaSpec.html#93&quot; class=&quot;Datatype&quot;
&gt;Expectation&lt;/a
&gt;&lt;a name=&quot;104&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;105&quot; class=&quot;Symbol&quot;
&gt;:&lt;/a
&gt;&lt;a name=&quot;106&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;107&quot; class=&quot;Symbol&quot;
&gt;{&lt;/a
&gt;&lt;a name=&quot;108&quot; href=&quot;AgdaSpec.html#108&quot; class=&quot;Bound&quot;
&gt;Poly&lt;/a
&gt;&lt;a name=&quot;112&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;113&quot; class=&quot;Symbol&quot;
&gt;:&lt;/a
&gt;&lt;a name=&quot;114&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;115&quot; class=&quot;PrimitiveType&quot;
&gt;Set&lt;/a
&gt;&lt;a name=&quot;118&quot; class=&quot;Symbol&quot;
&gt;}&lt;/a
&gt;&lt;a name=&quot;119&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;120&quot; class=&quot;Symbol&quot;
&gt;-&amp;gt;&lt;/a
&gt;&lt;a name=&quot;122&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;123&quot; href=&quot;AgdaSpec.html#108&quot; class=&quot;Bound&quot;
&gt;Poly&lt;/a
&gt;&lt;a name=&quot;127&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;128&quot; class=&quot;Symbol&quot;
&gt;-&amp;gt;&lt;/a
&gt;&lt;a name=&quot;130&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;131&quot; class=&quot;PrimitiveType&quot;
&gt;Set&lt;/a
&gt;&lt;a name=&quot;134&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;135&quot; class=&quot;Keyword&quot;
&gt;where&lt;/a
&gt;&lt;a name=&quot;140&quot;
&gt;
&lt;/a
&gt;&lt;a name=&quot;141&quot; class=&quot;Keyword&quot;
&gt;data&lt;/a
&gt;&lt;a name=&quot;145&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;146&quot; href=&quot;AgdaSpec.html#146&quot; class=&quot;Datatype Operator&quot;
&gt;specify_and_are_&lt;/a
&gt;&lt;a name=&quot;162&quot;
&gt;
&lt;/a
&gt;&lt;a name=&quot;165&quot; class=&quot;Symbol&quot;
&gt;{&lt;/a
&gt;&lt;a name=&quot;166&quot; href=&quot;AgdaSpec.html#166&quot; class=&quot;Bound&quot;
&gt;Poly&lt;/a
&gt;&lt;a name=&quot;170&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;171&quot; class=&quot;Symbol&quot;
&gt;:&lt;/a
&gt;&lt;a name=&quot;172&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;173&quot; class=&quot;PrimitiveType&quot;
&gt;Set&lt;/a
&gt;&lt;a name=&quot;176&quot; class=&quot;Symbol&quot;
&gt;}(&lt;/a
&gt;&lt;a name=&quot;178&quot; href=&quot;AgdaSpec.html#178&quot; class=&quot;Bound&quot;
&gt;a&lt;/a
&gt;&lt;a name=&quot;179&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;180&quot; class=&quot;Symbol&quot;
&gt;:&lt;/a
&gt;&lt;a name=&quot;181&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;182&quot; href=&quot;AgdaSpec.html#166&quot; class=&quot;Bound&quot;
&gt;Poly&lt;/a
&gt;&lt;a name=&quot;186&quot; class=&quot;Symbol&quot;
&gt;)(&lt;/a
&gt;&lt;a name=&quot;188&quot; href=&quot;AgdaSpec.html#188&quot; class=&quot;Bound&quot;
&gt;b&lt;/a
&gt;&lt;a name=&quot;189&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;190&quot; class=&quot;Symbol&quot;
&gt;:&lt;/a
&gt;&lt;a name=&quot;191&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;192&quot; href=&quot;AgdaSpec.html#166&quot; class=&quot;Bound&quot;
&gt;Poly&lt;/a
&gt;&lt;a name=&quot;196&quot; class=&quot;Symbol&quot;
&gt;)&lt;/a
&gt;&lt;a name=&quot;197&quot;
&gt;
&lt;/a
&gt;&lt;a name=&quot;200&quot; class=&quot;Symbol&quot;
&gt;(&lt;/a
&gt;&lt;a name=&quot;201&quot; href=&quot;AgdaSpec.html#201&quot; class=&quot;Bound&quot;
&gt;c&lt;/a
&gt;&lt;a name=&quot;202&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;203&quot; class=&quot;Symbol&quot;
&gt;:&lt;/a
&gt;&lt;a name=&quot;204&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;205&quot; href=&quot;AgdaSpec.html#93&quot; class=&quot;Datatype&quot;
&gt;Expectation&lt;/a
&gt;&lt;a name=&quot;216&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;217&quot; href=&quot;AgdaSpec.html#178&quot; class=&quot;Bound&quot;
&gt;a&lt;/a
&gt;&lt;a name=&quot;218&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;219&quot; class=&quot;Symbol&quot;
&gt;-&amp;gt;&lt;/a
&gt;&lt;a name=&quot;221&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;222&quot; href=&quot;AgdaSpec.html#93&quot; class=&quot;Datatype&quot;
&gt;Expectation&lt;/a
&gt;&lt;a name=&quot;233&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;234&quot; href=&quot;AgdaSpec.html#188&quot; class=&quot;Bound&quot;
&gt;b&lt;/a
&gt;&lt;a name=&quot;235&quot; class=&quot;Symbol&quot;
&gt;)&lt;/a
&gt;&lt;a name=&quot;236&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;237&quot; class=&quot;Symbol&quot;
&gt;:&lt;/a
&gt;&lt;a name=&quot;238&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;239&quot; class=&quot;PrimitiveType&quot;
&gt;Set&lt;/a
&gt;&lt;a name=&quot;242&quot;
&gt; &lt;/a
&gt;&lt;a name=&quot;243&quot; class=&quot;Keyword&quot;
&gt;where&lt;/a
&gt;&lt;/pre&gt;</content>
  </entry>
  
  <entry>
    <title>Agda course update</title>
    <link href="http://lemmatheultimate.com/2009/10/18/agda-course-update/"/>
    <updated>2009-10-18T00:00:00-07:00</updated>
    <id>http://lemmatheultimate.com/2009/10/18/agda-course-update</id>
    <content type="html">&lt;h2 id='agda_course_update'&gt;Agda course update&lt;/h2&gt;

&lt;h3 id='status_quo'&gt;Status quo&lt;/h3&gt;

&lt;p&gt;I just finished chapter 3 and am starting on chapter 4 in the &lt;a href='http://www.cs.swan.ac.uk/~csetzer/lectures/intertheo/07/interactiveTheoremProvingForAgdaUsers.html'&gt;Agda course&lt;/a&gt;. Chapters 0 &amp;amp; 1 starts off nice and light, giving an introduction to the course. One very nice feature of chapter 1 is a gradually built up explanation of dependent types in context of more familiar monomorphic and polymorphic static typing in languages like Java, C++, and Haskell. Chapter 2 changed abruptly to explaining what reduction systems are, but don&amp;#8217;t be deterred! Although the relation to dependent types is not clear in chapter 2, chapter 3 explains the untyped and simply typed lambda calculi. In these chapters you&amp;#8217;ll see that a given lambda calculus can be modeled as a reduction system where T is the set of lambda terms, and beta-reduction (along with alpha-conversions) constitutes the binary relation. Although a lot of complex sounding words are used (beta-redex, beta-reduct, etc.), the underlying concepts are not that complicated. More importantly, chapter 3 ends in explaining the Curry-Howard isomorphism and what it looks like in Agda. At this point I prefer Agda&amp;#8217;s approach of a unified system using types for everything, compared to Guru&amp;#8217;s split between terms/types and proofs/formulae with respect to operators and syntax. Note that after finishing chapter 3 you should be able to to watch the University of Oregon Logic and Theorem Proving &lt;a href='http://www.cs.uoregon.edu/research/summerschool/summer08/video/July22Lect1.wmv'&gt;summer school intro video&lt;/a&gt; and be comfortable with all the material.&lt;/p&gt;

&lt;h3 id='next_up'&gt;Next up&lt;/h3&gt;

&lt;p&gt;I&amp;#8217;m going to continue reading the remainder of the course slides. Between what I&amp;#8217;m learning in this course and what I&amp;#8217;ve learned from the &lt;a href='http://guru-lang.googlecode.com/svn/branches/1.0/doc/book.pdf'&gt;Guru book&lt;/a&gt; I think I&amp;#8217;ll be able to write a good intro to dependent types post for those that do not wish to read the more theoretical material. More importantly, I have an incomplete draft post that I&amp;#8217;m very excited about. The purpose of the post is to explain what dependent typing (and theorem proving therein) is in the context of dynamic typing, static typing, Test-driven development, and program verification in general. I&amp;#8217;ll probably wait until I&amp;#8217;m finished with the Agda course publishing these two. The second post especially could be an understandable and sensible reference to give to industry programmers so I&amp;#8217;d like to get the argument right. That&amp;#8217;s all for now, see you again soon!&lt;/p&gt;</content>
  </entry>
  
  <entry>
    <title>Roadmap</title>
    <link href="http://lemmatheultimate.com/2009/10/14/roadmap/"/>
    <updated>2009-10-14T00:00:00-07:00</updated>
    <id>http://lemmatheultimate.com/2009/10/14/roadmap</id>
    <content type="html">&lt;h2 id='roadmap'&gt;Roadmap&lt;/h2&gt;

&lt;h3 id='status_quo'&gt;Status Quo&lt;/h3&gt;

&lt;p&gt;After having completed the &lt;a href='http://guru-lang.googlecode.com/svn/branches/1.0/doc/book.pdf'&gt;Guru book&lt;/a&gt; I did a brief and shallow survey of the field to see what to learn next. To skip to the chase, I will currently focus on learning &lt;a href='http://wiki.portal.chalmers.se/agda/agda.php?n=Main.HomePage'&gt;Agda&lt;/a&gt; next. If you are interested in why, then continue reading as I briefly discuss some alternatives that I did not choose for now. Please be aware that my experience with the following is slim to none so my opinions could change drastically in the future. The plan is to invest in learning Agda now, then come back to read more general &lt;a href='http://www.elsevier.com/wps/find/bookdescription.cws_home/706927/description#description'&gt;Curry-Howard&lt;/a&gt; and &lt;a href='http://www.springer.com/computer/foundations/book/978-0-387-23759-6'&gt;proofs-as-programs&lt;/a&gt; books later while transcribing examples to Agda for greater understanding. I have also spent a bit of time working on a &lt;a href='http://github.com/larrytheliquid/carroll'&gt;toy implementation&lt;/a&gt; of the declarative &lt;a href='http://www.mozart-oz.org'&gt;Oz&lt;/a&gt; kernel language for elementary experience in language construction in case I feel an itch to move in that direction. I will come back to this from time to time for a small change of pace.&lt;/p&gt;

&lt;h3 id='agda'&gt;Agda&lt;/h3&gt;

&lt;p&gt;What&amp;#8217;s nice about Agda is that it feels like a very natural extension of Haskell. Haskell got a lot of things right in the way of mutation-restriction via monads and powerful type inferencing. Although it recently added &lt;a href='http://www.haskell.org/ghc/docs/latest/html/users_guide/data-type-extensions.html#gadt'&gt;Generalised Algebraic Data Types&lt;/a&gt; they are still not as flexible as completely dependent types. Agda on the other hand fills this role quite well, in fact it is itself implemented in Haskell and even makes code sharing possible. To be fair, most proof-based languages are implemented in an ML dialect or Haskell, in contrast to the C/C++/Java dna of more traditional languages. I like Agda right now for two reasons: First it has a strong emphasis of purely functional code which is much more pleasant to deal for learning. And secondly it deals with manipulating raw proofs directly rather than using &amp;#8220;script&amp;#8221; abstractions. It may turn out that both of these advantages disappear after I get passed the learning stages of this field, but from briefly looking over the language it seems cohesive enough to still be practical even after learning&amp;#8230; And a third more selfish reason is that Agda comes with a very fun Emacs mode =) My first focus will be going through &lt;a href='http://www.cs.swan.ac.uk/~csetzer/lectures/intertheo/07/interactiveTheoremProvingForAgdaUsers.html'&gt;this Agda course&lt;/a&gt; available online.&lt;/p&gt;

&lt;h3 id='coq'&gt;Coq&lt;/h3&gt;

&lt;p&gt;Coq is one of the older (but still actively developed) and more mature proof languages / systems. There is a well-organized &lt;a href='http://www.cis.upenn.edu/~bcpierce/sf/'&gt;Software Foundations&lt;/a&gt; course based on Coq available, as well as an &lt;a href='http://vimeo.com/6615365'&gt;ICFP video&lt;/a&gt; explaining its background&amp;#8230; these are both by Benjamin Pierce of &lt;a href='http://www.cis.upenn.edu/~bcpierce/tapl/'&gt;TAPL&lt;/a&gt; fame. Unlike Agda, in Coq one uses &lt;code&gt;tactics&lt;/code&gt; to write &amp;#8220;proof scripts&amp;#8221; for proving. These are a higher-level abstraction than bare-bones equational reasoning. Although this sounds great in principle, like I already said I&amp;#8217;d rather dabble at a lower level right now because I think it may result in a better base for learning. Coq also has much more literature in doing imperative proofs that I&amp;#8217;d like to steer clear from. Either way, once I have a better foundation with Agda I will definitely revisit the course linked above to mirror exercises in it. Coq is one of those widespread languages that you cannot afford to not learn. Well&amp;#8230; at least widespread in this community =)&lt;/p&gt;

&lt;h3 id='epigram'&gt;Epigram&lt;/h3&gt;

&lt;p&gt;I have not dug much into &lt;a href='http://www.e-pig.org/'&gt;this language&lt;/a&gt;. However I do know that is also written in and similar to Haskell, and the most comparable to Agda. A new significantly improved version of Epigram is in the works, which can be tracked at &lt;a href='http://www.e-pig.org/epilogue'&gt;this developer blog&lt;/a&gt;. In fact, all of the languages in this post are still in very active development, for example check out the &lt;a href='http://wiki.portal.chalmers.se/agda/agda.php?n=Main.AIMX'&gt;notes&lt;/a&gt; for the recent Agda developers annual meeting.&lt;/p&gt;

&lt;h3 id='twelf'&gt;Twelf&lt;/h3&gt;

&lt;p&gt;Curry-Howard, Martin-Löf, and the calculus of constructions are all very cool ways of brilliantly relating standard programming to proofs. That being said, &lt;a href='http://twelf.plparty.org'&gt;Twelf&lt;/a&gt; uses &lt;a href='http://en.wikipedia.org/wiki/LF_%28logical_framework%29'&gt;LF&lt;/a&gt; to take things one step further. Syntax comes as a third player to the field, making for a very unifying and grand theory. Yes&amp;#8230; even something as unassuming as syntax stands on level ground with standard programming and proofs via things like Higher-Order Abstract Syntax&amp;#8230; therein you can call syntax as if it were a function to perform variable substitution and eliminate a large class of variable capture problems&amp;#8230; amazing!!! You can find a great &lt;a href='http://www.cs.uoregon.edu/research/summerschool/summer08/'&gt;video and mini-course&lt;/a&gt; about Twelf&amp;#8230; it was part of a recently held summer school made available for free including course materials and videos (many other similar topics are covered, of course including Coq). The Twelf lectures are presented by Robert Harper of CMU so hold on to the railings for an exciting roller-coaster ride. Dr. Harper is also offering what looks like a great &lt;a href='http://www.cs.cmu.edu/~rwh/plbook/book.pdf'&gt;programming languages (in-progress) book draft&lt;/a&gt; for free. I will come back to Twelf later with the most excitement, mainly due to the fact that its intent is to focus on proving about formal properties of languages rather than integrated proofs for general-purpose programming. I haven&amp;#8217;t dug in enough to know if this is just what Twelf has been used for historically or if there is some limitation. Another reason for saving this for later is that I need enough mental energy to focus on just learning on an isomorphism =p&lt;/p&gt;

&lt;h3 id='conclusion'&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;So there&amp;#8217;s my roadmap, full of fun links and hopefully a reasonable approach to diving into the exciting field of theorem proving. To summarize, the plan is to first learn Agda and then move on to more theoretical books, and finally come back to go through Coq and Twelf courses to compare each additional language I acquire knowledge about with the previous ones. Although I wasn&amp;#8217;t expecting it, there is plenty of approachable information available. That means there are no excuses to not to explore this stuff, so join me if you would like =) As always, during the course of my learning I may find reasons to change the order I outlined above, so no promises about that. I should also note that I may dabble with going through and reworking some of the Real World Haskell book as I am learning Agda. Finally, please be kind and leave any good resources you may know of in the comments.&lt;/p&gt;</content>
  </entry>
  
  <entry>
    <title>Hello world!</title>
    <link href="http://lemmatheultimate.com/2009/10/13/hello-world/"/>
    <updated>2009-10-13T00:00:00-07:00</updated>
    <id>http://lemmatheultimate.com/2009/10/13/hello-world</id>
    <content type="html">
&lt;h2&gt;Hello world!&lt;/h2&gt;

&lt;h3&gt;Introduction&lt;/h3&gt;
&lt;p&gt;This is the first post of what I hope will be many small but frequently posted reflections. Reflections on what exactly? Trying to find ideal methods to build software (see the first paragraph on the homepage for details). In posts such as this one I will give updates on things I learn as I encounter them. In the sidebar on the homepage I will update my opinion of what I guess to be most ideal languages for writing reliable software, my current hypothesis of what reliable software entails, and whatever current project I am doing research on in an attempt to formulate more reliable guesses of the previous two things.&lt;/p&gt;

&lt;h3&gt;Why&lt;/h3&gt;
&lt;p&gt;Most of my programming experience has been with Ruby and various other dynamic languages including Common Lisp, Oz, &amp;amp; Clojure. While I enjoy using these languages, their losely restricted mutability (especially in Ruby &amp;amp; CL, but even in Oz &amp;amp; Clojure) gradually leads to time spent in the debugger, inspecting the state of things before and after each line to figure out why something strange is happening. Dynamic typing had its golden age, but with sophisticated type inferencers (most notably like what Haskell offers) the pain of types is drastically reduced to a prick of the finger. More importantly, those types become practically necessary to do any sort of universal quantification based reasoning on code. Such reasoning allows for proofs that can state properties about all instances of certain types of functions, even polymorphic types!&lt;/p&gt;

&lt;h3&gt;How&lt;/h3&gt;
&lt;p&gt;Although the exact details of how to achieve this &quot;verified&quot;, or reliable, style of programming is the topic of this blog, I have two important points to wage bets on already. Proofs about universals (&quot;for-all&quot; statements about some properties such as variables or function arguments) eliminate a lot of instances of those aforementioned debugger sessions. An important mindset that I've aquired in my career is that of Test-driven Development (TDD). Programs, through use of composition to manage complexity, still remain complex enough to require extra code to make sure that the compositions actually accomplished the original intent (i.e. tests). The epiphany is that tests (assertions) are merely the simplest type of proof (join proofs, or proofs by interpretation). Many other types of proofs exist (contrapositive, inductive, equational, etc), but there is another reason besides universals to use proofs. When typically writing a new test, or an entire suite, you start from scratch everytime. This contrasts starkly with the way other code is written. More specifically, regular code is written compositionally by building up libraries (even frameworks) of abstractions to make it easier to manage. There aren't many effective ways to compositionally build up tests. Even if you try, in dynamic and unrestrictive-mutation based languages the tests usually rely on setup/teardown that becomes too difficult to reason about sanely. On the contrary, &lt;em&gt;a proof (the code that proves an expected theorem under the Curry-Howard isomorphism) can be reused to build another more complicated proof!&lt;/em&gt; A formula can be viewed as the type of a proof that tries to prove it.&lt;/p&gt; 

&lt;h3&gt;Curry-Howard&lt;/h3&gt;
&lt;p&gt;Under this isomorphism, a type is a &quot;kind&quot; of some value expression. The complement to this relation is that a formula is a kind of some proof. Take a moment to contemplate this, it has profound implications... Notice that the relationship between proofs and formulas is many-to-one. There can be several ways to prove something but only one formula that it proves. What happens in our model when a proof does not succeed in proving some formula?... a typing error caught by compilation! Proofs (and in certain languages even types and formulas) become values themselves, leading to the composition property in testing... and also the pun on the &quot;lambda the ultimate&quot; title of this blog... Just imagine for a second &quot;calling&quot; a universal proof with a value of a specific instance that you would like to prove... this is possible and even normal under this isomorpishm... the whole idea, like many things, is old but unappreciated and heavenly.&lt;/p&gt;

&lt;h3&gt;Guru&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;http://code.google.com/p/guru-lang/&quot;&gt;Guru&lt;/a&gt; is a language currently being developed and preparing for 1.0. If you are unfamiliar with what I'm talking about, please take the time to read the book found in the doc directory of the language. Solutions to the exercises (which I recommend doing) are also found there (see my &lt;a href=&quot;http://github.com/larrytheliquid/guru-exercises&quot;&gt;similar solutions&lt;/a&gt; if you would like). I warn you that the language does not attempt even modest type inferencing. Its concept of using resources to model declarative code efficiently with imperative code in my opinion becomes impractical to deal with. This is made obvious by the definition of the non-trivial &lt;code&gt;map&lt;/code&gt; function for which the author teaches with a simple example that is a stark contrast to the version included in the distribution. This problem is exacerbated by the language's reliance on partial evaluation in proving, for which you need to look at previous function and type definitions. Nonetheless, the language is generally fairly simple and the book is an amazingly simple introduction to this type of programming.&lt;/p&gt;

&lt;h3&gt;Concurrency&lt;/h3&gt;
&lt;p&gt;For the time being, while I am learning I will be ignoring concurrency even though it is already a modern problem. I think &lt;a href=&quot;http://github.com/larrytheliquid/dataflow&quot;&gt;dataflow concurrency&lt;/a&gt; could be a natural and easy thing to exploit in this declarative world, although I am not sure (although dataflow remains declarative it is potentially non-terminating, and non-total functions are a pain to prove anything about... relating to the Halting Problem). In general declarative programs are easier to prove things about though, so hopefully I can come back to this topic later without too much pain.&lt;/p&gt;

&lt;h3&gt;Mutation&lt;/h3&gt;
&lt;p&gt;You may have noticed that I am trying to find practical ways to build this reliable software but have only alluded to declarative programming. As I am a currently novice in the field of theorem proving, I will only think about the declarative model for a little while. I think languages that restrict mutation like Haskell, and other restriction methods such as Software transactional memory (STM) will make mutation still possible as long as it is thought of as the edge case. Mutation will always be in the back of my mind though, so hopefully I won't stray too far from the path.&lt;/p&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;That's it for now. I will be posting a lot so check back often or subscribe if this kind of stuff interests you. Tell your friends if you think they would like this, and please leave comments containing helpful links as well as criticisms and other feedback! As a final note I should mention that I have not given up hope on the dynamic languages front... the tone of this blog may indicate that but I am merely playing devil's advocate to explore the other end of the pole.&lt;/p&gt;</content>
  </entry>
  
</feed>