<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Types of Note</title>
    <link href="https://www.typesofnote.com/atom.xml" rel="self" />
    <link href="https://www.typesofnote.com" />
    <id>https://www.typesofnote.com/atom.xml</id>
    <author>
        <name>Calvin Beck</name>
        <email>hobbes@ualberta.ca</email>
    </author>
    <updated>2019-03-13T00:00:00Z</updated>
    <entry>
    <title>Types and Verification Chattery</title>
    <link href="https://www.typesofnote.com/posts/chat.html" />
    <id>https://www.typesofnote.com/posts/chat.html</id>
    <published>2019-03-13T00:00:00Z</published>
    <updated>2019-03-13T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="blog-post">
<h2 class="blog-post-title"><a href="/posts/chat.html">Types and Verification Chattery</a></h2>
<p class="blog-post-meta">Posted on March 13, 2019  by <a href="#">Calvin Beck</a> 
 <br> Tags: <a href="/tags/coq.html">coq</a>, <a href="/tags/agda.html">agda</a>, <a href="/tags/idris.html">idris</a>, <a href="/tags/types.html">types</a>, <a href="/tags/tactics.html">tactics</a>, <a href="/tags/theorem%20proving.html">theorem proving</a>, <a href="/tags/proofs.html">proofs</a>  </p>

  
      <p>There are a small number of people who might care about this, but, there is an XMPP server available for anybody who might want to talk types, theorem proving, etc. Here are the details:</p>
<p>You may register here: <a href="https://chat.typesofnote.com/#converse/register">https://chat.typesofnote.com/#converse/register</a> And you can log in to chat here: <a href="https://chat.typesofnote.com/">https://chat.typesofnote.com/</a></p>
<p>You are of course welcome to use any XMPP client you wish, but the converse web client is available for anybody who so chooses.</p>
<p>Why use this?</p>
<p>An advantage of XMPP is that you are able to use any XMPP client you desire — no vender lock in. Be happy. Here’s a few options:</p>
<ul>
<li>pidgin</li>
<li>gajim</li>
<li>profanity</li>
<li>poezio</li>
<li>converse.js</li>
<li>conversations (Android, best gotten from f-droid)</li>
<li>ChatSecure (iOS)</li>
<li>Monal (iOS / Mac)</li>
<li>adium (Mac)</li>
</ul>
<p>I intend to keep all of the history available, so we can build up more sources of information for people getting into theorem proving and verification.</p>
<p>There probably won’t be many people hanging around, but that can change if you stick around :). Install a client on your phone and stick around, and maybe we’ll get somewhere!</p>
  

</div>
]]></summary>
</entry>
<entry>
    <title>DeepSpec 2017 Slack Notes</title>
    <link href="https://www.typesofnote.com/posts/slack.html" />
    <id>https://www.typesofnote.com/posts/slack.html</id>
    <published>2019-03-12T00:00:00Z</published>
    <updated>2019-03-12T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="blog-post">
<h2 class="blog-post-title"><a href="/posts/slack.html">DeepSpec 2017 Slack Notes</a></h2>
<p class="blog-post-meta">Posted on March 12, 2019  by <a href="#">Calvin Beck</a> 
 <br> Tags: <a href="/tags/coq.html">coq</a>, <a href="/tags/tactics.html">tactics</a>, <a href="/tags/theorem%20proving.html">theorem proving</a>, <a href="/tags/proofs.html">proofs</a>  </p>

  
      <p>I realized that there wasn’t any mention of this on the home page here. Maybe it’s time we do that. There are some notes available from the DeepSpec Summer School in 2017. These notes were extracted from the slack, and actually contain a lot of tips and tricks.</p>
<p>Dig in here: <a href="https://www.typesofnote.com/dsss17-slack.html">https://www.typesofnote.com/dsss17-slack.html</a></p>
  

</div>
]]></summary>
</entry>
<entry>
    <title>Truthiness</title>
    <link href="https://www.typesofnote.com/posts/truth.html" />
    <id>https://www.typesofnote.com/posts/truth.html</id>
    <published>2017-07-03T00:00:00Z</published>
    <updated>2017-07-03T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="blog-post">
<h2 class="blog-post-title"><a href="/posts/truth.html">Truthiness</a></h2>
<p class="blog-post-meta">Posted on July  3, 2017  by <a href="#">Calvin Beck</a> 
 <br> Tags: <a href="/tags/coq.html">coq</a>, <a href="/tags/tactics.html">tactics</a>, <a href="/tags/theorem%20proving.html">theorem proving</a>, <a href="/tags/proofs.html">proofs</a>  </p>

  
      <p>There are a couple of notions of truthiness in Coq. For example <code>Prop</code> and <code>bool</code>.</p>
<h1 id="difference-between-bool-and-prop"><span class="todo TODO">TODO</span> Difference between <code>bool</code> and <code>Prop</code></h1>
<p>One advantage of <code>Prop</code> over <code>bool</code> is that <code>Prop</code> is essentially a built in which works well with tactics like <code>rewrite</code> in the case of equality.</p>
<h1 id="difference-between-type-and-prop"><span class="todo TODO">TODO</span> Difference between <code>Type</code> and <code>Prop</code></h1>
<p>Term erasing</p>
  

</div>
]]></summary>
</entry>
<entry>
    <title>Proof Pitfalls</title>
    <link href="https://www.typesofnote.com/posts/proof-pitfalls.html" />
    <id>https://www.typesofnote.com/posts/proof-pitfalls.html</id>
    <published>2017-07-01T00:00:00Z</published>
    <updated>2017-07-01T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="blog-post">
<h2 class="blog-post-title"><a href="/posts/proof-pitfalls.html">Proof Pitfalls</a></h2>
<p class="blog-post-meta">Posted on July  1, 2017  by <a href="#">Calvin Beck</a> 
 <br> Tags: <a href="/tags/coq.html">coq</a>, <a href="/tags/tactics.html">tactics</a>, <a href="/tags/theorem%20proving.html">theorem proving</a>, <a href="/tags/proofs.html">proofs</a>  </p>

  
      <h1 id="induction">Induction</h1>
<h2 id="introducing-too-much.">Introducing too much.</h2>
<p><a href="https://softwarefoundations.cis.upenn.edu/draft/lf-current/Tactics.html#lab139" class="uri">https://softwarefoundations.cis.upenn.edu/draft/lf-current/Tactics.html#lab139</a></p>
<p>By introducing a variable you are saying for a “particular” instance of that variable. Not for all such instances of the variable.</p>
<p>Thus, when introducing more than necessary prior to induction you may unintentionally weaken the induction hypothesis that you will get, making it impossible to prove your goal.</p>
<h1 id="destruct">Destruct</h1>
<h2 id="forgetting-things">Forgetting things</h2>
<p>When you <code>destruct</code> a compound expression you lose what the original equation was. For instance:</p>
<pre class="coq"><code>destruct (beq_nat 3 n).
</code></pre>
<p>will give you two subgoals. One where <code>(beq_nat 3 n)</code> is replaced with <code>true</code>, and one where it is replaced with <code>false</code>.</p>
<p>Sometimes, however, you actually need the fact that <code>(beq_nat 3 n)
   = true</code> in that branch of the proof, or that <code>(beq_nat 3 n) =
   false</code> in the other branch of the proof. You can keep this information with:</p>
<pre class="coq"><code>destruct (beq_nat 3 n) eqn:Hbeq3.
</code></pre>
<p>Which will introduce in the context a hypothesis <code>Hbeq3</code> which will be <code>beq_nat 3 n = true</code> in the <code>true</code> branch of the proof, and <code>beq_nat 3 n = false</code> in the false branch.</p>
  

</div>
]]></summary>
</entry>
<entry>
    <title>Dependent Types and Matching in Coq</title>
    <link href="https://www.typesofnote.com/posts/dependent-types-and-matching.html" />
    <id>https://www.typesofnote.com/posts/dependent-types-and-matching.html</id>
    <published>2017-07-01T00:00:00Z</published>
    <updated>2017-07-01T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="blog-post">
<h2 class="blog-post-title"><a href="/posts/dependent-types-and-matching.html">Dependent Types and Matching in Coq</a></h2>
<p class="blog-post-meta">Posted on July  1, 2017  by <a href="#">Calvin Beck</a> 
 <br> Tags: <a href="/tags/coq.html">coq</a>, <a href="/tags/theorem%20proving.html">theorem proving</a>, <a href="/tags/proofs.html">proofs</a>, <a href="/tags/dependent%20types.html">dependent types</a>, <a href="/tags/pattern%20matching.html">pattern matching</a>  </p>

  
      <h1 id="induction">Induction</h1>
<p>Working with dependent types in Coq has been causing me a number of headaches — which I have found somewhat surprising coming from Agda / Idris.</p>
<p>I believe part of this is syntactic, and that Agda for instance kind of has you working with terms in a dependently typed language in the raw, unlike Coq which often has you using tactics, which are a bit of a step away from what’s actually going on. But the other part seems to be that Agda includes this so called “axiom K” by default, and Coq does not.</p>
<h2 id="what-is-axiom-k">What is axiom K?</h2>
<h2 id="dependent-pattern-matching-in-coq.-the-convoy-pattern.">Dependent pattern matching in Coq. The “convoy” pattern.</h2>
<h2 id="dealing-with-absurd-cases.">Dealing with absurd cases.</h2>
<p>In Agda you might use the absurd pattern to deal with branches of a program which should never be executed due to a condition which will never hold. I.e., if the condition to enter the branch is true, then that condition implies False.</p>
<pre class="coq"><code>hd {X} (xs : list X) (length xs &gt; 0) : X   
</code></pre>
<p>For instance, in the case of a <code>hd</code> function, which takes the first element of the list, you might have an argument that’s a proof that the length of the list is greater than 0. But, you still have to provide a case to the match on the list for when it’s empty.</p>
<p>Well, that’s okay. Because in Coq we can use an empty pattern match on False. So you might think you can do something like this:</p>
<pre class="coq"><code>Require Import List.

Lemma length_nil_not_gt_0 :
  forall {X}, @length X nil &gt; 0 -&gt; False.
Proof.
  intros X H. inversion H.
Qed.


Definition hd {X} (xs : list X) (pf : length xs &gt; 0) : X :=
  match xs with
  | nil =&gt; match length_nil_not_gt_0 pf with end
  | h :: t =&gt; h
  end.
</code></pre>
<p>But this doesn’t quite work.</p>
<pre class="example"><code>Error:
In environment
X : Type
xs : list X
pf : length xs &gt; 0
The term &quot;pf&quot; has type &quot;length xs &gt; 0&quot; while it is expected to have type
 &quot;length nil &gt; 0&quot;.
</code></pre>
<p>For some reason Coq seems to not be recognizing that in this branch <code>xs = nil</code>, and so it’s not replacing <code>xs</code> with <code>nil</code> when it’s typechecking.</p>
<p>So, how can we get around this? What seems to be happening is that <code>pf</code> is getting tied to the type <code>length xs &gt; 0</code> at the beginning, at the very top level.</p>
<p>The way to get around this is to make <code>hd</code> actually return a function, which takes a proof as an argument. This lets the <code>pf</code> have a different type in each branch.</p>
<pre class="coq"><code>Require Import List.

Lemma length_nil_not_gt_0 :
  forall {X}, @length X nil &gt; 0 -&gt; False.
Proof.
  intros X H. inversion H.
Qed.


Definition hd {X} (xs : list X) : (length xs &gt; 0) -&gt; X :=
  match xs with
  | nil =&gt; fun pf =&gt; match length_nil_not_gt_0 pf with end
  | h :: t =&gt; fun _ =&gt; h
  end.
</code></pre>
  

</div>
]]></summary>
</entry>
<entry>
    <title>Coq Cheat Sheet</title>
    <link href="https://www.typesofnote.com/posts/coq-cheat-sheet.html" />
    <id>https://www.typesofnote.com/posts/coq-cheat-sheet.html</id>
    <published>2017-07-01T00:00:00Z</published>
    <updated>2017-07-01T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="blog-post">
<h2 class="blog-post-title"><a href="/posts/coq-cheat-sheet.html">Coq Cheat Sheet</a></h2>
<p class="blog-post-meta">Posted on July  1, 2017  by <a href="#">Calvin Beck</a> 
 <br> Tags: <a href="/tags/coq.html">coq</a>, <a href="/tags/tactics.html">tactics</a>, <a href="/tags/theorem%20proving.html">theorem proving</a>, <a href="/tags/proofs.html">proofs</a>  </p>

  
      <h1 id="tactics">Tactics</h1>
<h2 id="intros"><code>intros</code></h2>
<p>Introduces variables and hypothesis. This takes them out of the goal and puts them in the context.</p>
<p>You can automatically destruct variables with patterns like <code>[x |
   y]</code> which will split a sum type into its two constructors, and call the resulting variables <code>x</code> and <code>y</code> respectively, leading to two subgoals. A product type may also be destructed into its parts with <code>[x y]</code>. These may be combined in arbitrary ways such as <code>[x | [x
   y] | [x | y z]]</code>, depending on the type of what is being introduced. The empty pattern <code>[]</code> may be used to destruct an impossible value, and automatically solve a branch, such as if you would be introducing <code>False</code>.</p>
<h2 id="reflexivity"><code>reflexivity</code></h2>
<p>Does reflexivity. If a goal has <code>x = y</code> it will try to simplify (by normalization) both <code>x</code> and <code>y</code>. If their normal forms are syntactically identical, then this tactic will succeed and the goal will be completed.</p>
<p>E.g.,</p>
<pre class="coq"><code>1 + 1 = 2
</code></pre>
<p>Reflexivity will solve this because <code>1 + 1</code> will evaluate to <code>2</code>, and <code>2 = 2</code> is obviously true because each side of the equality is syntactically identical.</p>
<h2 id="simpl"><code>simpl</code></h2>
<p>Attempts to simplify the goal. This essentially just evaluates to weak head normal form. Useful for seeing next steps in a proof (hard to unwind definitions in your head sometimes), and it can be used to facilitate rewrites.</p>
<pre class="coq"><code>1 + 1 = 2
</code></pre>
<p><code>simpl</code> will transform this to <code>2 = 2</code>.</p>
<p><code>simpl</code> sometimes won’t evaluate as much as you expect, because if it always evaluated as much as it possibly could you would end up with really long terms. So, simple has some heuristics to decide when to keep evaluating, and when not to.</p>
<h2 id="rewrite"><code>rewrite</code></h2>
<p>When we have <code>x = y</code> it can be used to replace <code>x</code> with <code>y</code> in a goal, or vice versa.</p>
<pre class="coq"><code>H : x = y
=========
x = y
</code></pre>
<p>Then <code>rewrite H</code> will leave us with the goal <code>y = y</code>, and <code>rewrite &lt;- H</code> will leave us with <code>x = x</code>.</p>
<h2 id="subst"><code>subst</code></h2>
<p>If you have</p>
<pre class="coq"><code>H : x = y
</code></pre>
<p>You can call <code>subst</code> and it will substitute all variable equalities. This is a bit wild, but useful with other wild tactics like <code>inversion</code></p>
<h2 id="apply"><code>apply</code></h2>
<p>Used to solve a goal by applying a theorem which has an identical conclusion to the current goal. Any hypothesis of the theorem will be added to the context.</p>
<p>This tactic can also be used on hypothesis in the context which then matches on the hypothesis of the theorem being applied and gives you a hypothesis in the context matching the goal of the theorem being applied.</p>
<pre class="coq"><code>H : x = y
=========
x = y
</code></pre>
<p><code>apply H</code> will solve the goal.</p>
<pre class="coq"><code>H : x = y -&gt; y = z
H0 : x = y
==================
y = z
</code></pre>
<p>You could solve this in two ways with <code>apply</code>:</p>
<ul>
<li><code>apply H</code> will use the theorem <code>H</code> to show that <code>y = z</code> if <code>x =
 y</code>, so it leaves you with <code>x = y</code> in your goal. This can then be solved by applying <code>H0</code>.</li>
<li><code>apply H in H0</code> will use <code>H : x = y -&gt; y = z</code> to transform <code>H0 : x
 = y</code> to <code>y = z</code>. After this we can apply <code>H0</code> to our goal.</li>
</ul>
<h2 id="assumption"><code>assumption</code></h2>
<p>This calls <code>apply</code> on a hypothesis in the context that matches the goal. I.e., it finds the hypothesis for you.</p>
<h2 id="symmetry"><code>symmetry</code></h2>
<p>Reverses an equality. Using <code>symmetry</code> will flip <code>x = y</code> to <code>y = x</code>.</p>
<p>This is useful for when you need to <code>apply</code> a theorem, but the goal is in a different order than the theorem.</p>
<h2 id="destruct"><code>destruct</code></h2>
<p>The <code>destruct</code> tactic is used to perform case analysis in Coq. It will break a possible value into all cases for that type (one for each constructor of the type). This gives you multiple goals to prove; one for each constructor.</p>
<p>This can be used on variables, or compound expressions.</p>
<p>When using destruct on a compound expression it is also possible to save the original expression.</p>
<p><code>destruct (f (x + y)) eqn:Hfxy</code></p>
<h2 id="induction"><code>induction</code></h2>
<p>The <code>induction</code> tactic is very similar to <code>destruct</code>, except that it brings an induction hypothesis into the context for recursive data types.</p>
<h2 id="inversion"><code>inversion</code></h2>
<p><code>inversion</code> provides reasoning with constructors taking into account the fact that constructors are injective and disjoint.</p>
<ul>
<li>Injective: for a constructor <code>A</code>, <code>A x = A y</code> means that <code>x = y</code> as well.</li>
<li>Disjoint: If you have two constructors <code>A</code> and <code>B</code>, then you know that <code>A</code> does not equal <code>B</code></li>
</ul>
<p>Thus the inversion tactic has several uses.</p>
<h3 id="injective-usage">Injective usage</h3>
<pre class="coq"><code>H : A x = A y
=============
x = y
</code></pre>
<p>When using <code>inversion in H</code> this gives us a new hypothesis, <code>H1</code>.</p>
<pre class="coq"><code>H : A x = A y
H1 : x = y
=============
y = y
</code></pre>
<p>It will also perform rewrites with the new hypothesis automatically, so our goal changed to <code>y = y</code> as well, since it rewrote <code>x</code> with <code>y</code> using the new hypothesis <code>H1</code>.</p>
<p>Inversion will apply this injective reasoning across multiple arguments in a constructor, and even recursively. So, if you have lists of three items that are equal you will get a hypothesis representing the equality of each item in the first list, with the equivalent item in the second list.</p>
<p>We can name the equations as well.</p>
<p><code>inversion in H as [Hxy]</code> will give:</p>
<pre class="coq"><code>H : A x = A y
Hxy : x = y
=============
y = y
</code></pre>
<h3 id="disjoint-usage">Disjoint usage</h3>
<p>If we have values constructed with two different constructors <code>A</code> and <code>B</code>, then we know that the values must be different. So if we have a hypothesis in the context with disjoint constructors, like so:</p>
<pre class="coq"><code>H: A x = B y
============
false = true
</code></pre>
<p>We can use <code>inversion H</code> which will conclude that <code>H</code> is a false hypothesis, and since we have a contradiction in our set of assumptions we may conclude the goal via the principle of explosion.</p>
<h2 id="generalize-dependent"><code>generalize dependent</code></h2>
<p>The <code>generalize dependent</code> tactic can be used to place a variable in the context back into the goal. This can be useful when you only want to introduce certain variables, like when you want to keep your induction hypothesis strong.</p>
<h2 id="unfold"><code>unfold</code></h2>
<p>This tactic is used to expand a definition.</p>
<pre class="coq"><code>Definition square n := n * n
</code></pre>
<pre class="coq"><code>square (n * m) = square n * square m
</code></pre>
<p><code>unfold square</code> will yield</p>
<pre class="coq"><code>(n * m) * (n * m) = (n * n) * (m * m)
</code></pre>
<p>which will actually display as</p>
<pre class="coq"><code>n * m * (n * m) = n * n * (m * m)
</code></pre>
<p>due to the associativity of the operators.</p>
<p>This tactic can be very useful when you can simplify a definition based on rewriting a term inside the definition. For instance if the definition contains a <code>match</code> like:</p>
<pre class="coq"><code>match test x with
  | true =&gt; some_stuff
  | false =&gt; other_stuff
end.
</code></pre>
<p>Then if you have <code>test x = true</code> in the context you can simplify this <code>match</code> to just <code>some_stuff</code>.</p>
<h2 id="assert"><code>assert</code></h2>
<p>This tactic will introduce a hypothesis into the context, and then split the goal into two subgoals. The first subgoal is to prove that this hypothesis is true, and the second subgoal is the original goal.</p>
<h2 id="replace"><span class="todo TODO">TODO</span> ~replace~</h2>
<h2 id="split"><code>split</code></h2>
<p>Used to split a conjunction in a goal into two subgoals.</p>
<p>If the conjunction is in the context, and not the goal, then one would use <code>destruct</code> instead.</p>
<h2 id="left-and-right"><code>left</code> and <code>right</code></h2>
<p>These tactics are used to pick a side of a disjunction in the goal to prove.</p>
<h2 id="exfalso"><code>exfalso</code></h2>
<p>Turns the goal into <code>False</code>. This is useful when working with negations.</p>
<h2 id="exists"><code>exists</code></h2>
<p>Used in proofs with existential quantifiers. For instance if our goal was</p>
<pre class="coq"><code>exists x : nat, x = 2 + 2
</code></pre>
<p>Then <code>exists 4</code> would substitute <code>4</code> for <code>x</code>, removing the existential quantifier, and leaving us with:</p>
<pre class="coq"><code>4 = 2 + 2
</code></pre>
<p>Which can then be solved with <code>reflexivity</code>.</p>
<h1 id="miscellaneous">Miscellaneous</h1>
<h2 id="applying-theorems-to-arguments">Applying theorems to arguments</h2>
<p>Theorems have arguments, since they’re really just types of functions. For example:</p>
<pre class="coq"><code>plus_comm : forall n m : n + m = m + n
</code></pre>
<p>When applying a theorem normally Coq guesses what the arguments to the theorem will be based on the first suitable instance it finds. This can be annoying because sometimes it applies it to the wrong part of the expression we want to prove!</p>
<p>So, instead of having Coq guess what <code>n</code> and <code>m</code> should be we can provide it with arguments.</p>
<pre class="coq"><code>rewrite (plus_comm p).
</code></pre>
<p>Will rewrite a term where <code>p</code> is substituted for <code>n</code> in the <code>plus_comm</code> theorem.</p>
<pre class="coq"><code>plus_comm p : forall m : p + m = m + p
</code></pre>
<p>This works in pretty much any tactic, like <code>destruct</code>, since theorems are just first class objects in Coq.</p>
  

</div>
]]></summary>
</entry>

</feed>
