<?xml version="1.0" ?><?xml-stylesheet type="text/xsl" href="moviola.xsl"?><?xml-stylesheet type="text/xsl" href="moviola-coqdoc.xsl"?><movie><film><frame frameNumber="0"><command>(** * Proving with computer assistance, Spring 2011 *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
<a name="lab1"/><h1 class="section">Proving with computer assistance, Spring 2010</h1>

</div></command-coqdoc></frame><frame frameNumber="1"><command>
(* Version of 25/3/2010 *)</command><response/><command-coqdoc/></frame><frame frameNumber="2"><command>


(* ###################################################################### *)</command><response/><command-coqdoc/></frame><frame frameNumber="3"><command>
(** * Coq *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
<a name="lab1"/><h1 class="section">Coq</h1>

</div></command-coqdoc></frame><frame frameNumber="4"><command>

(** The main PA for this course is the Coq proof assistant.  

    Coq can be seen as a combination of:
      - a simple but still very expressive functional programming language,
      - a language for defining abstract and concrete mathematical concepts,
      - a language for writing logical formulas expressing properties of 
        mathematical concepts or assertions of programs 
      - a language and a set of tools for proving these formulas

    The Coq system has fairly few things &quot;built in&quot;, but there is a
    standard library which contains basic things like booleans,
    numbers and lists. Also there are many user contributions around
    on the web. Also, Coq provides powerful tools for defining your
    own types and functions and for constructing your own proof
    tactics. *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
The main PA for this course is the Coq proof assistant.  
<br/>
    Coq can be seen as a combination of:

<ul>
<li> a simple but still very expressive functional programming language,

</li>
<li> a language for defining abstract and concrete mathematical concepts,

</li>
<li> a language for writing logical formulas expressing properties of 
        mathematical concepts or assertions of programs 

</li>
<li> a language and a set of tools for proving these formulas

</li>
</ul>

    The Coq system has fairly few things &quot;built in&quot;, but there is a
    standard library which contains basic things like booleans,
    numbers and lists. Also there are many user contributions around
    on the web. Also, Coq provides powerful tools for defining your
    own types and functions and for constructing your own proof
    tactics. 
</div></command-coqdoc></frame><frame frameNumber="5"><command>

(* ###################################################################### *)</command><response/><command-coqdoc/></frame><frame frameNumber="6"><command>
(** * Working with Coq *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
<a name="lab1"/><h1 class="section">Working with Coq</h1>

</div></command-coqdoc></frame><frame frameNumber="7"><command>

(** Coq is a free program available via the site 
    http://coq.inria.fr. There are compiled binary versions 
    for Linux and Windows.
 
    For this practicum it is recommended that you install Coq
    IDE or ProofGeneral or that you use the prover system:
    http://prover.cs.ru.nl
 
    For getting a login for the course (and teh prover system) and in
    general for more information, look at:
    http://www.cs.ru.nl/H.Geuvers/onderwijs/provingwithCA/
 
 *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
Coq is a free program available via the site 
    http://coq.inria.fr. There are compiled binary versions 
    for Linux and Windows.

<br/><br/>
    For this practicum it is recommended that you install Coq
    IDE or ProofGeneral or that you use the prover system:
    http://prover.cs.ru.nl

<br/><br/>
    For getting a login for the course (and teh prover system) and in
    general for more information, look at:
    http://www.cs.ru.nl/H.Geuvers/onderwijs/provingwithCA/

<br/><br/>
 
</div></command-coqdoc></frame><frame frameNumber="8"><command>



Section Introduction.</command><response/><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Section</span> <span class="id" type="var">Introduction</span>.
</div></command-coqdoc></frame><frame frameNumber="9"><command>
(** 
   Using the command Goal we enter the proof mode and set the
   proposition that we will try to prove.
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
   Using the command Goal we enter the proof mode and set the
   proposition that we will try to prove.

</div></command-coqdoc></frame><frame frameNumber="10"><command>

Goal forall A B C: Prop, (A -&gt; B -&gt; C) -&gt; (A -&gt; B) -&gt; (A -&gt; C).</command><response>1 subgoal
  
  ============================
   forall A B C : Prop, (A -&gt; B -&gt; C) -&gt; (A -&gt; B) -&gt; A -&gt; C
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Goal</span> <span class="id" type="keyword">forall</span> <span class="id" type="var">A</span> <span class="id" type="var">B</span> <span class="id" type="var">C</span>: <span class="id" type="keyword">Prop</span>, (<span class="id" type="var">A</span> -&gt; <span class="id" type="var">B</span> -&gt; <span class="id" type="var">C</span>) -&gt; (<span class="id" type="var">A</span> -&gt; <span class="id" type="var">B</span>) -&gt; (<span class="id" type="var">A</span> -&gt; <span class="id" type="var">C</span>).
</div></command-coqdoc></frame><frame frameNumber="11"><command>
intros.</command><response>1 subgoal
  
  A : Prop
  B : Prop
  C : Prop
  H : A -&gt; B -&gt; C
  H0 : A -&gt; B
  H1 : A
  ============================
   C
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">intros</span>.
</div></command-coqdoc></frame><frame frameNumber="12"><command>
apply H.</command><response>2 subgoals
  
  A : Prop
  B : Prop
  C : Prop
  H : A -&gt; B -&gt; C
  H0 : A -&gt; B
  H1 : A
  ============================
   A

subgoal 2 is:
 B
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">apply</span> <span class="id" type="var">H</span>.
</div></command-coqdoc></frame><frame frameNumber="13"><command>
assumption.</command><response>1 subgoal
  
  A : Prop
  B : Prop
  C : Prop
  H : A -&gt; B -&gt; C
  H0 : A -&gt; B
  H1 : A
  ============================
   B
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">assumption</span>.
</div></command-coqdoc></frame><frame frameNumber="14"><command>
apply H0.</command><response>1 subgoal
  
  A : Prop
  B : Prop
  C : Prop
  H : A -&gt; B -&gt; C
  H0 : A -&gt; B
  H1 : A
  ============================
   A
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">apply</span> <span class="id" type="var">H0</span>.
</div></command-coqdoc></frame><frame frameNumber="15"><command>
assumption.</command><response>Proof completed.
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">assumption</span>.
</div></command-coqdoc></frame><frame frameNumber="16"><command>
(**  
  The proof is now complete. It can be saved for future use 
 with the command Save, followed by a name for the new
 theorem. This also ends the proof mode.
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  The proof is now complete. It can be saved for future use 
 with the command Save, followed by a name for the new
 theorem. This also ends the proof mode.

</div></command-coqdoc></frame><frame frameNumber="17"><command>
Save Tautology1.</command><response>Tautology1 is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Save</span> <span class="id" type="var">Tautology1</span>.
</div></command-coqdoc></frame><frame frameNumber="18"><command>

(**  
  To prove and save the result above, we could also have 
 stated it as a Theorem or Lemma, as follows: 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  To prove and save the result above, we could also have 
 stated it as a Theorem or Lemma, as follows: 

</div></command-coqdoc></frame><frame frameNumber="19"><command>

Lemma Tautology1': 
forall A B C:Prop, (A -&gt; B -&gt; C) -&gt; (A -&gt; B) -&gt; (A -&gt; C).</command><response>1 subgoal
  
  ============================
   forall A B C : Prop, (A -&gt; B -&gt; C) -&gt; (A -&gt; B) -&gt; A -&gt; C
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">Tautology1'</span>: <br/>
<span class="id" type="keyword">forall</span> <span class="id" type="var">A</span> <span class="id" type="var">B</span> <span class="id" type="var">C</span>:Prop, (<span class="id" type="var">A</span> -&gt; <span class="id" type="var">B</span> -&gt; <span class="id" type="var">C</span>) -&gt; (<span class="id" type="var">A</span> -&gt; <span class="id" type="var">B</span>) -&gt; (<span class="id" type="var">A</span> -&gt; <span class="id" type="var">C</span>).
</div></command-coqdoc></frame><frame frameNumber="20"><command>
Proof.</command><response/><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Proof</span>.
</div></command-coqdoc></frame><frame frameNumber="21"><command>
intros.</command><response>1 subgoal
  
  A : Prop
  B : Prop
  C : Prop
  H : A -&gt; B -&gt; C
  H0 : A -&gt; B
  H1 : A
  ============================
   C
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">intros</span>.
</div></command-coqdoc></frame><frame frameNumber="22"><command>
apply H.</command><response>2 subgoals
  
  A : Prop
  B : Prop
  C : Prop
  H : A -&gt; B -&gt; C
  H0 : A -&gt; B
  H1 : A
  ============================
   A

subgoal 2 is:
 B
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">apply</span> <span class="id" type="var">H</span>.
</div></command-coqdoc></frame><frame frameNumber="23"><command>
assumption.</command><response>1 subgoal
  
  A : Prop
  B : Prop
  C : Prop
  H : A -&gt; B -&gt; C
  H0 : A -&gt; B
  H1 : A
  ============================
   B
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">assumption</span>.
</div></command-coqdoc></frame><frame frameNumber="24"><command>
apply H0.</command><response>1 subgoal
  
  A : Prop
  B : Prop
  C : Prop
  H : A -&gt; B -&gt; C
  H0 : A -&gt; B
  H1 : A
  ============================
   A
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">apply</span> <span class="id" type="var">H0</span>.
</div></command-coqdoc></frame><frame frameNumber="25"><command>
assumption.</command><response>Proof completed.
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">assumption</span>.
</div></command-coqdoc></frame><frame frameNumber="26"><command>
Qed.</command><response>Tautology1' is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Qed</span>.
</div></command-coqdoc></frame><frame frameNumber="27"><command>

(** 
  NB &quot;tauto&quot; just finishes the proof right away;
     it is a complete tautology checker for constructive 
     propositional logic

  NB &quot;Admitted&quot; leaves the proof without finishing it;
     this can be useful if you first want to prove something else

  With Qed. the proof is validated and added to the environment. 
  In fact this method is usually preferred unless we do not
 want to give a name to a proof.
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  NB &quot;tauto&quot; just finishes the proof right away;
     it is a complete tautology checker for constructive 
     propositional logic

<br/><br/>
  NB &quot;Admitted&quot; leaves the proof without finishing it;
     this can be useful if you first want to prove something else

<br/><br/>
  With Qed. the proof is validated and added to the environment. 
  In fact this method is usually preferred unless we do not
 want to give a name to a proof.

</div></command-coqdoc></frame><frame frameNumber="28"><command>

(**
 The natural numbers are pre-defined in Coq as
&gt; nat: Set
 Check that with the command
&gt; Check nat.
  The terms &quot;O&quot; and &quot;S&quot; represent the natural number zero 
 and the successor function (adding of 1). Check their 
 types with the Check command.
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
 The natural numbers are pre-defined in Coq as
&gt; nat: Set
 Check that with the command
&gt; Check nat.
  The terms &quot;O&quot; and &quot;S&quot; represent the natural number zero 
 and the successor function (adding of 1). Check their 
 types with the Check command.

</div></command-coqdoc></frame><frame frameNumber="29"><command>
Check nat.</command><response>nat
     : Set
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Check</span> <span class="id" type="var">nat</span>.
</div></command-coqdoc></frame><frame frameNumber="30"><command>
Check O.</command><response>0
     : nat
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Check</span> <span class="id" type="var">O</span>.
</div></command-coqdoc></frame><frame frameNumber="31"><command>
Check S.</command><response>S
     : nat -&gt; nat
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Check</span> <span class="id" type="var">S</span>.
</div></command-coqdoc></frame><frame frameNumber="32"><command>

(** 
  The function that adds two to its argument can be defined as: 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  The function that adds two to its argument can be defined as: 

</div></command-coqdoc></frame><frame frameNumber="33"><command>
Definition Add_two := fun x:nat =&gt; S (S x).</command><response>Add_two is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">Add_two</span> := <span class="id" type="keyword">fun</span> <span class="id" type="var">x</span>:nat =&gt; <span class="id" type="var">S</span> (<span class="id" type="var">S</span> <span class="id" type="var">x</span>).
</div></command-coqdoc></frame><frame frameNumber="34"><command>

(** But also, the number two can be defined as *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
But also, the number two can be defined as 
</div></command-coqdoc></frame><frame frameNumber="35"><command>
Definition two := 2.</command><response>two is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">two</span> := 2.
</div></command-coqdoc></frame><frame frameNumber="36"><command>
(** 
  We could have also used &quot;S (S 0)&quot; in place of &quot;2&quot;, they are
 equivalent
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  We could have also used &quot;S (S 0)&quot; in place of &quot;2&quot;, they are
 equivalent

</div></command-coqdoc></frame><frame frameNumber="37"><command>

(** Now two can be used in the definition of the function: *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
Now two can be used in the definition of the function: 
</div></command-coqdoc></frame><frame frameNumber="38"><command>

Definition Add_two' (x: nat) := x + two.</command><response>Add_two' is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">Add_two'</span> (<span class="id" type="var">x</span>: <span class="id" type="var">nat</span>) := <span class="id" type="var">x</span> + <span class="id" type="var">two</span>.
</div></command-coqdoc></frame><frame frameNumber="39"><command>

(**  
  Note the parameter in the definition. This is a syntactic
 sugar and a more readable way of writing:
&gt; Definition Add_two'' := fun x: nat =&gt; x + two.
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  Note the parameter in the definition. This is a syntactic
 sugar and a more readable way of writing:
&gt; Definition Add_two'' := fun x: nat =&gt; x + two.

</div></command-coqdoc></frame><frame frameNumber="40"><command>

(**
  One example on how the notion of equality can be introduced
 in Coq. (Note: Coq has already a built-in equality denoted by
 the symbol &quot;=&quot;, but in this example we define our own).
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
  One example on how the notion of equality can be introduced
 in Coq. (Note: Coq has already a built-in equality denoted by
 the symbol &quot;=&quot;, but in this example we define our own).

</div></command-coqdoc></frame><frame frameNumber="41"><command>
Variable IS : forall A: Set, A -&gt; A -&gt; Prop.</command><response>IS is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Variable</span> <span class="id" type="var">IS</span> : <span class="id" type="keyword">forall</span> <span class="id" type="var">A</span>: <span class="id" type="keyword">Set</span>, <span class="id" type="var">A</span> -&gt; <span class="id" type="var">A</span> -&gt; <span class="id" type="keyword">Prop</span>.
</div></command-coqdoc></frame><frame frameNumber="42"><command>

(** 
  The line above only defines &quot;IS&quot; as a binary relation on an 
 arbitrary set &quot;A&quot; - this is a polymorphic equality. 
 Reflexivity can be introduced by an extra axiom:
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  The line above only defines &quot;IS&quot; as a binary relation on an 
 arbitrary set &quot;A&quot; - this is a polymorphic equality. 
 Reflexivity can be introduced by an extra axiom:

</div></command-coqdoc></frame><frame frameNumber="43"><command>
Axiom refl: forall (A: Set) (z: A), IS A z z.</command><response>refl is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Axiom</span> <span class="id" type="var">refl</span>: <span class="id" type="keyword">forall</span> (<span class="id" type="var">A</span>: <span class="id" type="keyword">Set</span>) (<span class="id" type="var">z</span>: <span class="id" type="var">A</span>), <span class="id" type="var">IS</span> <span class="id" type="var">A</span> <span class="id" type="var">z</span> <span class="id" type="var">z</span>.
</div></command-coqdoc></frame><frame frameNumber="44"><command>

(** 
  Now we should be able to prove &quot;IS nat (Add_two O) two&quot; and 
 indeed  this is the case as shown below  
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  Now we should be able to prove &quot;IS nat (Add_two O) two&quot; and 
 indeed  this is the case as shown below  

</div></command-coqdoc></frame><frame frameNumber="45"><command>

Goal (IS nat (Add_two O) two).</command><response>1 subgoal
  
  IS : forall A : Set, A -&gt; A -&gt; Prop
  ============================
   IS nat (Add_two 0) two
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Goal</span> (<span class="id" type="var">IS</span> <span class="id" type="var">nat</span> (<span class="id" type="var">Add_two</span> <span class="id" type="var">O</span>) <span class="id" type="var">two</span>).
</div></command-coqdoc></frame><frame frameNumber="46"><command>
apply refl.</command><response>Proof completed.
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">apply</span> <span class="id" type="var">refl</span>.
</div></command-coqdoc></frame><frame frameNumber="47"><command>
Qed.</command><response>Unnamed_thm is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Qed</span>.
</div></command-coqdoc></frame><frame frameNumber="48"><command>

Goal (IS nat (Add_two' O) two).</command><response>1 subgoal
  
  IS : forall A : Set, A -&gt; A -&gt; Prop
  ============================
   IS nat (Add_two' 0) two
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Goal</span> (<span class="id" type="var">IS</span> <span class="id" type="var">nat</span> (<span class="id" type="var">Add_two'</span> <span class="id" type="var">O</span>) <span class="id" type="var">two</span>).
</div></command-coqdoc></frame><frame frameNumber="49"><command>
apply refl.</command><response>Proof completed.
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">apply</span> <span class="id" type="var">refl</span>.
</div></command-coqdoc></frame><frame frameNumber="50"><command>
Qed.</command><response>Unnamed_thm0 is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Qed</span>.
</div></command-coqdoc></frame><frame frameNumber="51"><command>

(** 
  What happened here? Coq can see that 
 &quot;IS nat (Add_two' O) two)&quot; is an instance of the reflexivity 
 axiom &quot;IS A z z&quot;. It takes &quot;nat&quot; for the set &quot;A&quot; and &quot;two&quot; for
 &quot;z&quot;, but &quot;two&quot; is (by definition) equal to 
 &quot;Add_two' O&quot;. This check is performed automatically as 
 follows:

Add_two' O =                    (By unfolding Add_two)
0 + two =                       (By beta-reduction)
two

   Hence, when comparing two terms, Coq folds or unfolds 
 definitions as necessary 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  What happened here? Coq can see that 
 &quot;IS nat (Add_two' O) two)&quot; is an instance of the reflexivity 
 axiom &quot;IS A z z&quot;. It takes &quot;nat&quot; for the set &quot;A&quot; and &quot;two&quot; for
 &quot;z&quot;, but &quot;two&quot; is (by definition) equal to 
 &quot;Add_two' O&quot;. This check is performed automatically as 
 follows:

<br/><br/>
Add_two' O =                    (By unfolding Add_two)
0 + two =                       (By beta-reduction)
two

<br/><br/>
   Hence, when comparing two terms, Coq folds or unfolds 
 definitions as necessary 

</div></command-coqdoc></frame><frame frameNumber="52"><command>

(* ###################################################################### *)</command><response/><command-coqdoc/></frame><frame frameNumber="53"><command>

(** * Classical Logic in Coq *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
<a name="lab1"/><h1 class="section">Classical Logic in Coq</h1>

</div></command-coqdoc></frame><frame frameNumber="54"><command>

(** 
  This example shows how we can do classical logic in Coq

  Suppose we want to prove that for all propositions &quot;A&quot; and &quot;B&quot; 
 the following holds: &quot;(~A -&gt; B) -&gt; (~B -&gt; A)&quot;.
  Note that negation is defined as
&gt; Definition not (A: Prop) := A -&gt; False
 and &quot;~A&quot; is an abbreviation for &quot;not A&quot;.
  Let us give this proposition the name contra (from
 contraposition): 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  This example shows how we can do classical logic in Coq

<br/><br/>
  Suppose we want to prove that for all propositions &quot;A&quot; and &quot;B&quot; 
 the following holds: &quot;(~A -&gt; B) -&gt; (~B -&gt; A)&quot;.
  Note that negation is defined as
&gt; Definition not (A: Prop) := A -&gt; False
 and &quot;~A&quot; is an abbreviation for &quot;not A&quot;.
  Let us give this proposition the name contra (from
 contraposition): 

</div></command-coqdoc></frame><frame frameNumber="55"><command>
Print not.</command><response>not = fun A : Prop =&gt; A -&gt; False
     : Prop -&gt; Prop

Argument scope is [type_scope]
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Print</span> <span class="id" type="var">not</span>.
</div></command-coqdoc></frame><frame frameNumber="56"><command>

Definition contra := forall A B: Prop, (~A -&gt; B) -&gt; (~B -&gt; A).</command><response>contra is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">contra</span> := <span class="id" type="keyword">forall</span> <span class="id" type="var">A</span> <span class="id" type="var">B</span>: <span class="id" type="keyword">Prop</span>, (~A -&gt; <span class="id" type="var">B</span>) -&gt; (~B -&gt; <span class="id" type="var">A</span>).
</div></command-coqdoc></frame><frame frameNumber="57"><command>
Print contra.</command><response>contra = forall A B : Prop, (~ A -&gt; B) -&gt; ~ B -&gt; A
     : Prop
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Print</span> <span class="id" type="var">contra</span>.
</div></command-coqdoc></frame><frame frameNumber="58"><command>

(**  
  You can try to prove contra using the tauto or the intuition 
 tactic:

&gt; Goal contra.

&gt; tauto.

  Unfortunately, Coq cannot prove contra with the tactic 
 tauto or intuition, because it is not provable in the
 constructive logic of Coq. To prove this proposition, we
 need the axiom for double negation: 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  You can try to prove contra using the tauto or the intuition 
 tactic:

<br/><br/>
&gt; Goal contra.

<br/><br/>
&gt; tauto.

<br/><br/>
  Unfortunately, Coq cannot prove contra with the tactic 
 tauto or intuition, because it is not provable in the
 constructive logic of Coq. To prove this proposition, we
 need the axiom for double negation: 

</div></command-coqdoc></frame><frame frameNumber="59"><command>
Hypothesis classical: forall A: Prop, ~~A -&gt; A.</command><response>classical is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Hypothesis</span> <span class="id" type="var">classical</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">A</span>: <span class="id" type="keyword">Prop</span>, ~~A -&gt; <span class="id" type="var">A</span>.
</div></command-coqdoc></frame><frame frameNumber="60"><command>

(** With this extra axiom we can prove contra *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
With this extra axiom we can prove contra 
</div></command-coqdoc></frame><frame frameNumber="61"><command>

Goal contra.</command><response>1 subgoal
  
  IS : forall A : Set, A -&gt; A -&gt; Prop
  classical : forall A : Prop, ~ ~ A -&gt; A
  ============================
   contra
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Goal</span> <span class="id" type="var">contra</span>.
</div></command-coqdoc></frame><frame frameNumber="62"><command>
unfold contra.</command><response>1 subgoal
  
  IS : forall A : Set, A -&gt; A -&gt; Prop
  classical : forall A : Prop, ~ ~ A -&gt; A
  ============================
   forall A B : Prop, (~ A -&gt; B) -&gt; ~ B -&gt; A
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">unfold</span> <span class="id" type="var">contra</span>.
</div></command-coqdoc></frame><frame frameNumber="63"><command>
intros.</command><response>1 subgoal
  
  IS : forall A : Set, A -&gt; A -&gt; Prop
  classical : forall A : Prop, ~ ~ A -&gt; A
  A : Prop
  B : Prop
  H : ~ A -&gt; B
  H0 : ~ B
  ============================
   A
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">intros</span>.
</div></command-coqdoc></frame><frame frameNumber="64"><command>
apply classical.</command><response>1 subgoal
  
  IS : forall A : Set, A -&gt; A -&gt; Prop
  classical : forall A : Prop, ~ ~ A -&gt; A
  A : Prop
  B : Prop
  H : ~ A -&gt; B
  H0 : ~ B
  ============================
   ~ ~ A
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">apply</span> <span class="id" type="var">classical</span>.
</div></command-coqdoc></frame><frame frameNumber="65"><command>
(* 
 The goal at this moment is

  A : Prop

  B : Prop

  H : ~A-&gt;B

  H0 : ~B

  ===================

  ~~A

 Remember the definition of &quot;not&quot;? &quot;~~A&quot; can also be written 
  as &quot;~A -&gt; False&quot;, so...
*)</command><response/><command-coqdoc/></frame><frame frameNumber="66"><command>

intro.</command><response>1 subgoal
  
  IS : forall A : Set, A -&gt; A -&gt; Prop
  classical : forall A : Prop, ~ ~ A -&gt; A
  A : Prop
  B : Prop
  H : ~ A -&gt; B
  H0 : ~ B
  H1 : ~ A
  ============================
   False
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">intro</span>.
</div></command-coqdoc></frame><frame frameNumber="67"><command>

(*
 This results in the following goal:

  A : Prop

  B : Prop

  H : ~A-&gt;B

  H0 : ~B

  H1 : ~A

  ===================

  False

 In this context, from &quot;H&quot; and &quot;H1&quot; we can obtain a proof of 
&quot;B&quot; and since H0 is a proof of &quot;~B&quot; (i.e. &quot;B -&gt; False&quot;), we 
will get False. However, Coq always works in a backwards 
manner, we need to use first &quot;H0&quot; (and then the goal will be to 
prove &quot;B&quot;). Next, to prove &quot;B&quot;, we will need to use &quot;H&quot; (and 
the goal will become &quot;~A&quot;). The final step will be trivial, 
because &quot;H1&quot; is a proof of &quot;~A&quot;.
*)</command><response/><command-coqdoc/></frame><frame frameNumber="68"><command>

apply H0.</command><response>1 subgoal
  
  IS : forall A : Set, A -&gt; A -&gt; Prop
  classical : forall A : Prop, ~ ~ A -&gt; A
  A : Prop
  B : Prop
  H : ~ A -&gt; B
  H0 : ~ B
  H1 : ~ A
  ============================
   B
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">apply</span> <span class="id" type="var">H0</span>.
</div></command-coqdoc></frame><frame frameNumber="69"><command>

(*

  A : Prop

  B : Prop

  H : ~A-&gt;B

  H0 : ~B

  H1 : ~A

  ===================

  B
*)</command><response/><command-coqdoc/></frame><frame frameNumber="70"><command>
apply H.</command><response>1 subgoal
  
  IS : forall A : Set, A -&gt; A -&gt; Prop
  classical : forall A : Prop, ~ ~ A -&gt; A
  A : Prop
  B : Prop
  H : ~ A -&gt; B
  H0 : ~ B
  H1 : ~ A
  ============================
   ~ A
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">apply</span> <span class="id" type="var">H</span>.
</div></command-coqdoc></frame><frame frameNumber="71"><command>

(*

  A : Prop

  B : Prop

  H : ~A-&gt;B

  H0 : ~B

  H1 : ~A

  ===================

  ~A
*)</command><response/><command-coqdoc/></frame><frame frameNumber="72"><command>

assumption.</command><response>Proof completed.
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="tactic">assumption</span>.
</div></command-coqdoc></frame><frame frameNumber="73"><command>

(** To see the proof-term that we created, use Show Proof: *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
To see the proof-term that we created, use Show Proof: 
</div></command-coqdoc></frame><frame frameNumber="74"><command>
Show Proof.</command><response>LOC: 
Subgoals
Proof: fun (A B : Prop) (H : ~ A -&gt; B) (H0 : ~ B) =&gt;
       classical A (fun H1 : ~ A =&gt; H0 (H H1))
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Show</span> <span class="id" type="keyword">Proof</span>.
</div></command-coqdoc></frame><frame frameNumber="75"><command>

(**
&gt; Proof: fun (A B: Prop)(H: ~A -&gt; B)(H0: ~B) =&gt;
&gt;    classical A (fun H1: ~A =&gt; H0 (H H1))

  Although we prove a formula in classical logic, you can still
 use the automated tactics of Coq. They will work for subgoals
 that do not require the axiom &quot;classical&quot;
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
&gt; Proof: fun (A B: Prop)(H: ~A -&gt; B)(H0: ~B) =&gt;
&gt;    classical A (fun H1: ~A =&gt; H0 (H H1))

<br/><br/>
  Although we prove a formula in classical logic, you can still
 use the automated tactics of Coq. They will work for subgoals
 that do not require the axiom &quot;classical&quot;

</div></command-coqdoc></frame><frame frameNumber="76"><command>
Qed.</command><response>Unnamed_thm1 is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Qed</span>.
</div></command-coqdoc></frame><frame frameNumber="77"><command>

(** 
  The part with the worked-out examples ends here. Now you can 
 try to prove the exercises below yourself.
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  The part with the worked-out examples ends here. Now you can 
 try to prove the exercises below yourself.

</div></command-coqdoc></frame><frame frameNumber="78"><command>

End Introduction.</command><response/><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">End</span> <span class="id" type="var">Introduction</span>.
</div></command-coqdoc></frame><frame frameNumber="79"><command>

(* ###################################################################### *)</command><response/><command-coqdoc/></frame><frame frameNumber="80"><command>

(** *** Exercise 1. (implications)  *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
<a name="lab1"/><h3 class="section">Exercise 1. (implications)</h3>

</div></command-coqdoc></frame><frame frameNumber="81"><command>

(** Prove the following propositions: 

So you have to replace all the Admitted by real Coq proofs.
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
Prove the following propositions: 

<br/><br/>
So you have to replace all the Admitted by real Coq proofs.

</div></command-coqdoc></frame><frame frameNumber="82"><command>
Lemma L1_1: forall p q r: Prop, 
  (p -&gt; q) -&gt; (q -&gt; r) -&gt; (p -&gt; r).</command><response>1 subgoal
  
  ============================
   forall p q r : Prop, (p -&gt; q) -&gt; (q -&gt; r) -&gt; p -&gt; r
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">L1_1</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span> <span class="id" type="var">r</span>: <span class="id" type="keyword">Prop</span>, <br/>
  (<span class="id" type="var">p</span> -&gt; <span class="id" type="var">q</span>) -&gt; (<span class="id" type="var">q</span> -&gt; <span class="id" type="var">r</span>) -&gt; (<span class="id" type="var">p</span> -&gt; <span class="id" type="var">r</span>).
</div></command-coqdoc></frame><frame frameNumber="83"><command>
Admitted.</command><response>L1_1 is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="84"><command>

Lemma L1_2: forall p q: Prop, (p -&gt; p -&gt; q) -&gt; (p -&gt; q).</command><response>1 subgoal
  
  ============================
   forall p q : Prop, (p -&gt; p -&gt; q) -&gt; p -&gt; q
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">L1_2</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>: <span class="id" type="keyword">Prop</span>, (<span class="id" type="var">p</span> -&gt; <span class="id" type="var">p</span> -&gt; <span class="id" type="var">q</span>) -&gt; (<span class="id" type="var">p</span> -&gt; <span class="id" type="var">q</span>).
</div></command-coqdoc></frame><frame frameNumber="85"><command>
Admitted.</command><response>L1_2 is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="86"><command>

Lemma L1_3: forall p q: Prop, (p -&gt; q) -&gt; (p -&gt; p -&gt; q).</command><response>1 subgoal
  
  ============================
   forall p q : Prop, (p -&gt; q) -&gt; p -&gt; p -&gt; q
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">L1_3</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>: <span class="id" type="keyword">Prop</span>, (<span class="id" type="var">p</span> -&gt; <span class="id" type="var">q</span>) -&gt; (<span class="id" type="var">p</span> -&gt; <span class="id" type="var">p</span> -&gt; <span class="id" type="var">q</span>).
</div></command-coqdoc></frame><frame frameNumber="87"><command>
Admitted.</command><response>L1_3 is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="88"><command>

Lemma L1_4: forall p q r:Prop, (p -&gt; q -&gt; r) -&gt; (q -&gt; p -&gt; r).</command><response>1 subgoal
  
  ============================
   forall p q r : Prop, (p -&gt; q -&gt; r) -&gt; q -&gt; p -&gt; r
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">L1_4</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span> <span class="id" type="var">r</span>:Prop, (<span class="id" type="var">p</span> -&gt; <span class="id" type="var">q</span> -&gt; <span class="id" type="var">r</span>) -&gt; (<span class="id" type="var">q</span> -&gt; <span class="id" type="var">p</span> -&gt; <span class="id" type="var">r</span>).
</div></command-coqdoc></frame><frame frameNumber="89"><command>
Admitted.</command><response>L1_4 is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="90"><command>

(* ###################################################################### *)</command><response/><command-coqdoc/></frame><frame frameNumber="91"><command>
(** *** Exercise 2. (falsum)  *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
<a name="lab1"/><h3 class="section">Exercise 2. (falsum)</h3>

</div></command-coqdoc></frame><frame frameNumber="92"><command>

(**
 Define &quot;false&quot; as follows: 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
 Define &quot;false&quot; as follows: 

</div></command-coqdoc></frame><frame frameNumber="93"><command>
Definition false := forall p: Prop, p.</command><response>false is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">false</span> := <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span>: <span class="id" type="keyword">Prop</span>, <span class="id" type="var">p</span>.
</div></command-coqdoc></frame><frame frameNumber="94"><command>
Check false.</command><response>false
     : Prop
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Check</span> <span class="id" type="var">false</span>.
</div></command-coqdoc></frame><frame frameNumber="95"><command>

(** 
  Prove that from &quot;false&quot; follows any other proposition, 
 i.e. prove the following 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  Prove that from &quot;false&quot; follows any other proposition, 
 i.e. prove the following 

</div></command-coqdoc></frame><frame frameNumber="96"><command>
Lemma ex_falso: forall p:Prop, false -&gt; p.</command><response>1 subgoal
  
  ============================
   forall p : Prop, false -&gt; p
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">ex_falso</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span>:Prop, <span class="id" type="var">false</span> -&gt; <span class="id" type="var">p</span>.
</div></command-coqdoc></frame><frame frameNumber="97"><command>
Admitted.</command><response>ex_falso is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="98"><command>

(** Prove the following propositions: *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
Prove the following propositions: 
</div></command-coqdoc></frame><frame frameNumber="99"><command>

Lemma L2_1: forall p q: Prop, (p -&gt; q) -&gt; ~q -&gt; ~p.</command><response>1 subgoal
  
  ============================
   forall p q : Prop, (p -&gt; q) -&gt; ~ q -&gt; ~ p
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">L2_1</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>: <span class="id" type="keyword">Prop</span>, (<span class="id" type="var">p</span> -&gt; <span class="id" type="var">q</span>) -&gt; ~q -&gt; ~p.
</div></command-coqdoc></frame><frame frameNumber="100"><command>
Admitted.</command><response>L2_1 is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="101"><command>

Lemma L2_2: forall p: Prop, p -&gt; ~~p.</command><response>1 subgoal
  
  ============================
   forall p : Prop, p -&gt; ~ ~ p
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">L2_2</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span>: <span class="id" type="keyword">Prop</span>, <span class="id" type="var">p</span> -&gt; ~~p.
</div></command-coqdoc></frame><frame frameNumber="102"><command>
Admitted.</command><response>L2_2 is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="103"><command>

Lemma L2_3: forall p: Prop, ~~~p -&gt; ~p.</command><response>1 subgoal
  
  ============================
   forall p : Prop, ~ ~ ~ p -&gt; ~ p
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">L2_3</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span>: <span class="id" type="keyword">Prop</span>, ~~~p -&gt; ~p.
</div></command-coqdoc></frame><frame frameNumber="104"><command>
Admitted.</command><response>L2_3 is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="105"><command>

(* ###################################################################### *)</command><response/><command-coqdoc/></frame><frame frameNumber="106"><command>
(** *** Exercise 3. *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
<a name="lab1"/><h3 class="section">Exercise 3.</h3>

</div></command-coqdoc></frame><frame frameNumber="107"><command>

(** 
 Introduce the following axiom 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
 Introduce the following axiom 

</div></command-coqdoc></frame><frame frameNumber="108"><command>

Axiom classical: forall p: Prop, ~~p -&gt; p.</command><response>classical is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Axiom</span> <span class="id" type="var">classical</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span>: <span class="id" type="keyword">Prop</span>, ~~p -&gt; <span class="id" type="var">p</span>.
</div></command-coqdoc></frame><frame frameNumber="109"><command>

(** Using it prove: *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
Using it prove: 
</div></command-coqdoc></frame><frame frameNumber="110"><command>

Lemma L3_1: forall p q: Prop, (~q -&gt; ~p) -&gt; (p -&gt; q).</command><response>1 subgoal
  
  ============================
   forall p q : Prop, (~ q -&gt; ~ p) -&gt; p -&gt; q
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">L3_1</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>: <span class="id" type="keyword">Prop</span>, (~q -&gt; ~p) -&gt; (<span class="id" type="var">p</span> -&gt; <span class="id" type="var">q</span>).
</div></command-coqdoc></frame><frame frameNumber="111"><command>
Admitted.</command><response>L3_1 is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="112"><command>

(** 
  For the following lemma you may want need to use the tactic:
&gt; absurd X
  that changes the present goal to two subgoals: &quot;X&quot; and &quot;~X&quot;.

   You may find this lemma difficult to prove - if so then
 skip it and do not spend too much time on it.
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  For the following lemma you may want need to use the tactic:
&gt; absurd X
  that changes the present goal to two subgoals: &quot;X&quot; and &quot;~X&quot;.

<br/><br/>
   You may find this lemma difficult to prove - if so then
 skip it and do not spend too much time on it.

</div></command-coqdoc></frame><frame frameNumber="113"><command>
Lemma L3_2: forall p q: Prop, ((p -&gt; q) -&gt; p) -&gt; p.</command><response>1 subgoal
  
  ============================
   forall p q : Prop, ((p -&gt; q) -&gt; p) -&gt; p
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">L3_2</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>: <span class="id" type="keyword">Prop</span>, ((<span class="id" type="var">p</span> -&gt; <span class="id" type="var">q</span>) -&gt; <span class="id" type="var">p</span>) -&gt; <span class="id" type="var">p</span>.
</div></command-coqdoc></frame><frame frameNumber="114"><command>
Admitted.</command><response>L3_2 is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="115"><command>

(* ###################################################################### *)</command><response/><command-coqdoc/></frame><frame frameNumber="116"><command>
(** *** Exercise 4. (conjunction) *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
<a name="lab1"/><h3 class="section">Exercise 4. (conjunction)</h3>

</div></command-coqdoc></frame><frame frameNumber="117"><command>

(**  Define conjunction by 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
 Define conjunction by 

</div></command-coqdoc></frame><frame frameNumber="118"><command>

Definition AND (p q:Prop) := 
  forall (a: Prop), (p -&gt; q -&gt; a)-&gt;a.</command><response>AND is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">AND</span> (<span class="id" type="var">p</span> <span class="id" type="var">q</span>:Prop) := <br/>
  <span class="id" type="keyword">forall</span> (<span class="id" type="var">a</span>: <span class="id" type="keyword">Prop</span>), (<span class="id" type="var">p</span> -&gt; <span class="id" type="var">q</span> -&gt; <span class="id" type="var">a</span>)-&gt;a.
</div></command-coqdoc></frame><frame frameNumber="119"><command>

Check AND.</command><response>AND
     : Prop -&gt; Prop -&gt; Prop
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Check</span> <span class="id" type="var">AND</span>.
</div></command-coqdoc></frame><frame frameNumber="120"><command>

Lemma projl: forall p q: Prop, AND p q -&gt; p.</command><response>1 subgoal
  
  ============================
   forall p q : Prop, AND p q -&gt; p
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">projl</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>: <span class="id" type="keyword">Prop</span>, <span class="id" type="var">AND</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span> -&gt; <span class="id" type="var">p</span>.
</div></command-coqdoc></frame><frame frameNumber="121"><command>
Admitted.</command><response>projl is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="122"><command>

Lemma projr: forall p q: Prop, AND p q -&gt; q.</command><response>1 subgoal
  
  ============================
   forall p q : Prop, AND p q -&gt; q
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">projr</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>: <span class="id" type="keyword">Prop</span>, <span class="id" type="var">AND</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span> -&gt; <span class="id" type="var">q</span>.
</div></command-coqdoc></frame><frame frameNumber="123"><command>
Admitted.</command><response>projr is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="124"><command>

Lemma pair:  forall p q: Prop, p -&gt; q -&gt; AND p q.</command><response>1 subgoal
  
  ============================
   forall p q : Prop, p -&gt; q -&gt; AND p q
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">pair</span>:  <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>: <span class="id" type="keyword">Prop</span>, <span class="id" type="var">p</span> -&gt; <span class="id" type="var">q</span> -&gt; <span class="id" type="var">AND</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>.
</div></command-coqdoc></frame><frame frameNumber="125"><command>
Admitted.</command><response>pair is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="126"><command>

(** 
  Note: Coq defines conjunction and disjunction in a different
 way than the one we are using here. More information on this 
 can be found in the Coq tutorial (see the Coq homepage) 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  Note: Coq defines conjunction and disjunction in a different
 way than the one we are using here. More information on this 
 can be found in the Coq tutorial (see the Coq homepage) 

</div></command-coqdoc></frame><frame frameNumber="127"><command>

(* ###################################################################### *)</command><response/><command-coqdoc/></frame><frame frameNumber="128"><command>
(** *** Exercise 5. (disjunction) *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
<a name="lab1"/><h3 class="section">Exercise 5. (disjunction)</h3>

</div></command-coqdoc></frame><frame frameNumber="129"><command>

(** Define disjunction as follows 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
Define disjunction as follows 

</div></command-coqdoc></frame><frame frameNumber="130"><command>

Definition OR (p q: Prop) := forall (a: Prop), 
 (p -&gt; a) -&gt; (q -&gt; a) -&gt; a.</command><response>OR is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">OR</span> (<span class="id" type="var">p</span> <span class="id" type="var">q</span>: <span class="id" type="keyword">Prop</span>) := <span class="id" type="keyword">forall</span> (<span class="id" type="var">a</span>: <span class="id" type="keyword">Prop</span>), <br/>
 (<span class="id" type="var">p</span> -&gt; <span class="id" type="var">a</span>) -&gt; (<span class="id" type="var">q</span> -&gt; <span class="id" type="var">a</span>) -&gt; <span class="id" type="var">a</span>.
</div></command-coqdoc></frame><frame frameNumber="131"><command>
Check OR.</command><response>OR
     : Prop -&gt; Prop -&gt; Prop
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Check</span> <span class="id" type="var">OR</span>.
</div></command-coqdoc></frame><frame frameNumber="132"><command>

(** Prove the following tautologies: *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
Prove the following tautologies: 
</div></command-coqdoc></frame><frame frameNumber="133"><command>

Lemma inl: forall p q: Prop, p -&gt; OR p q.</command><response>1 subgoal
  
  ============================
   forall p q : Prop, p -&gt; OR p q
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">inl</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>: <span class="id" type="keyword">Prop</span>, <span class="id" type="var">p</span> -&gt; <span class="id" type="var">OR</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>.
</div></command-coqdoc></frame><frame frameNumber="134"><command>
Admitted.</command><response>inl is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="135"><command>

Lemma inr: forall p q: Prop, q -&gt; OR p q.</command><response>1 subgoal
  
  ============================
   forall p q : Prop, q -&gt; OR p q
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">inr</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>: <span class="id" type="keyword">Prop</span>, <span class="id" type="var">q</span> -&gt; <span class="id" type="var">OR</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>.
</div></command-coqdoc></frame><frame frameNumber="136"><command>
Admitted.</command><response>inr is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="137"><command>

(* ###################################################################### *)</command><response/><command-coqdoc/></frame><frame frameNumber="138"><command>
(** *** Exercise 6. (more junctions) *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
<a name="lab1"/><h3 class="section">Exercise 6. (more junctions)</h3>

</div></command-coqdoc></frame><frame frameNumber="139"><command>

(**  Prove the following using the lemmas proved in Exercise 4
 and 5: 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
 Prove the following using the lemmas proved in Exercise 4
 and 5: 

</div></command-coqdoc></frame><frame frameNumber="140"><command>

Lemma L6_1: forall p q: Prop, AND p q -&gt; OR q p.</command><response>1 subgoal
  
  ============================
   forall p q : Prop, AND p q -&gt; OR q p
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">L6_1</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>: <span class="id" type="keyword">Prop</span>, <span class="id" type="var">AND</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span> -&gt; <span class="id" type="var">OR</span> <span class="id" type="var">q</span> <span class="id" type="var">p</span>.
</div></command-coqdoc></frame><frame frameNumber="141"><command>
Admitted.</command><response>L6_1 is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="142"><command>

Lemma L6_2: forall p q: Prop, AND p q -&gt; AND q p.</command><response>1 subgoal
  
  ============================
   forall p q : Prop, AND p q -&gt; AND q p
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">L6_2</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>: <span class="id" type="keyword">Prop</span>, <span class="id" type="var">AND</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span> -&gt; <span class="id" type="var">AND</span> <span class="id" type="var">q</span> <span class="id" type="var">p</span>.
</div></command-coqdoc></frame><frame frameNumber="143"><command>
Admitted.</command><response>L6_2 is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="144"><command>

Lemma L6_3: forall p q r: Prop, OR (OR p q) r -&gt; OR p (OR q r).</command><response>1 subgoal
  
  ============================
   forall p q r : Prop, OR (OR p q) r -&gt; OR p (OR q r)
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">L6_3</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span> <span class="id" type="var">r</span>: <span class="id" type="keyword">Prop</span>, <span class="id" type="var">OR</span> (<span class="id" type="var">OR</span> <span class="id" type="var">p</span> <span class="id" type="var">q</span>) <span class="id" type="var">r</span> -&gt; <span class="id" type="var">OR</span> <span class="id" type="var">p</span> (<span class="id" type="var">OR</span> <span class="id" type="var">q</span> <span class="id" type="var">r</span>).
</div></command-coqdoc></frame><frame frameNumber="145"><command>
Admitted.</command><response>L6_3 is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="146"><command>

(* ###################################################################### *)</command><response/><command-coqdoc/></frame><frame frameNumber="147"><command>
(** *** Exercise 7 (Inductive types) *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
<a name="lab1"/><h3 class="section">Exercise 7 (Inductive types)</h3>

</div></command-coqdoc></frame><frame frameNumber="148"><command>

(**
 Define the type of the finite lists of natural numbers: 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
 Define the type of the finite lists of natural numbers: 

</div></command-coqdoc></frame><frame frameNumber="149"><command>

Inductive List: Set :=
 | nil: List
 | cons: nat -&gt; List -&gt; List.</command><response>List is defined
List_rect is defined
List_ind is defined
List_rec is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Inductive</span> <span class="id" type="var">List</span>: <span class="id" type="keyword">Set</span> :=<br/>
 | <span class="id" type="var">nil</span>: <span class="id" type="var">List</span><br/>
 | <span class="id" type="var">cons</span>: <span class="id" type="var">nat</span> -&gt; <span class="id" type="var">List</span> -&gt; <span class="id" type="var">List</span>.
</div></command-coqdoc></frame><frame frameNumber="150"><command>

(** 
  Coq defines automatically the corresponding induction 
 principle: 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  Coq defines automatically the corresponding induction 
 principle: 

</div></command-coqdoc></frame><frame frameNumber="151"><command>
Check List_ind.</command><response>List_ind
     : forall P : List -&gt; Prop,
       P nil -&gt;
       (forall (n : nat) (l : List), P l -&gt; P (cons n l)) -&gt;
       forall l : List, P l
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Check</span> <span class="id" type="var">List_ind</span>.
</div></command-coqdoc></frame><frame frameNumber="152"><command>

(** 
  Hence we can prove properties of lists of natural numbers 
 by induction. Furthermore, we can define functions with 
 recursion: 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  Hence we can prove properties of lists of natural numbers 
 by induction. Furthermore, we can define functions with 
 recursion: 

</div></command-coqdoc></frame><frame frameNumber="153"><command>

(** Length of a list, defined by pattern matching. *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
Length of a list, defined by pattern matching. 
</div></command-coqdoc></frame><frame frameNumber="154"><command>
Fixpoint Len (L: List) : nat :=
 match L with
 | nil =&gt; O
 | cons l ls =&gt; S (Len ls)
 end.</command><response>Len is recursively defined (decreasing on 1st argument)
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Fixpoint</span> <span class="id" type="var">Len</span> (<span class="id" type="var">L</span>: <span class="id" type="var">List</span>) : <span class="id" type="var">nat</span> :=<br/>
 <span class="id" type="keyword">match</span> <span class="id" type="var">L</span> <span class="id" type="keyword">with</span><br/>
 | <span class="id" type="var">nil</span> =&gt; <span class="id" type="var">O</span><br/>
 | <span class="id" type="var">cons</span> <span class="id" type="var">l</span> <span class="id" type="var">ls</span> =&gt; <span class="id" type="var">S</span> (<span class="id" type="var">Len</span> <span class="id" type="var">ls</span>)<br/>
 <span class="id" type="keyword">end</span>.
</div></command-coqdoc></frame><frame frameNumber="155"><command>

(** 
  Appending two lists.
  For recursive definitions to be well-defined one of the 
 arguments must be decreasing (becoming smaller in the 
 recursive call to ensure that the recursion will terminate). 
 If there is more than one parameter we must inform Coq which
 one is decreasing by the &quot;struct&quot; keyword.
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  Appending two lists.
  For recursive definitions to be well-defined one of the 
 arguments must be decreasing (becoming smaller in the 
 recursive call to ensure that the recursion will terminate). 
 If there is more than one parameter we must inform Coq which
 one is decreasing by the &quot;struct&quot; keyword.

</div></command-coqdoc></frame><frame frameNumber="156"><command>
Fixpoint Append (L R: List) {struct L} : List :=
 match L with
 | nil =&gt; R
 | cons l ls =&gt; cons l (Append ls R)
end.</command><response>Append is recursively defined (decreasing on 1st argument)
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Fixpoint</span> <span class="id" type="var">Append</span> (<span class="id" type="var">L</span> <span class="id" type="var">R</span>: <span class="id" type="var">List</span>) {<span class="id" type="keyword">struct</span> <span class="id" type="var">L</span>} : <span class="id" type="var">List</span> :=<br/>
 <span class="id" type="keyword">match</span> <span class="id" type="var">L</span> <span class="id" type="keyword">with</span><br/>
 | <span class="id" type="var">nil</span> =&gt; <span class="id" type="var">R</span><br/>
 | <span class="id" type="var">cons</span> <span class="id" type="var">l</span> <span class="id" type="var">ls</span> =&gt; <span class="id" type="var">cons</span> <span class="id" type="var">l</span> (<span class="id" type="var">Append</span> <span class="id" type="var">ls</span> <span class="id" type="var">R</span>)<br/>
<span class="id" type="keyword">end</span>.
</div></command-coqdoc></frame><frame frameNumber="157"><command>

Print Append.</command><response>Append = 
fix Append (L R : List) : List :=
  match L with
  | nil =&gt; R
  | cons l ls =&gt; cons l (Append ls R)
  end
     : List -&gt; List -&gt; List
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Print</span> <span class="id" type="var">Append</span>.
</div></command-coqdoc></frame><frame frameNumber="158"><command>

(** Prove the following: *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
Prove the following: 
</div></command-coqdoc></frame><frame frameNumber="159"><command>

Lemma Len_nil: Len nil = O.</command><response>1 subgoal
  
  ============================
   Len nil = 0
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">Len_nil</span>: <span class="id" type="var">Len</span> <span class="id" type="var">nil</span> = <span class="id" type="var">O</span>.
</div></command-coqdoc></frame><frame frameNumber="160"><command>
Admitted.</command><response>Len_nil is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="161"><command>

Lemma Len_Append: forall L R: List, 
  Len (Append L R) = Len L + Len R.</command><response>1 subgoal
  
  ============================
   forall L R : List, Len (Append L R) = Len L + Len R
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">Len_Append</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">L</span> <span class="id" type="var">R</span>: <span class="id" type="var">List</span>, <br/>
  <span class="id" type="var">Len</span> (<span class="id" type="var">Append</span> <span class="id" type="var">L</span> <span class="id" type="var">R</span>) = <span class="id" type="var">Len</span> <span class="id" type="var">L</span> + <span class="id" type="var">Len</span> <span class="id" type="var">R</span>.
</div></command-coqdoc></frame><frame frameNumber="162"><command>
Admitted.</command><response>Len_Append is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="163"><command>

(** 
  We define a function Reverse that given a list returns 
 another list with the elements of the first in reverse order 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  We define a function Reverse that given a list returns 
 another list with the elements of the first in reverse order 

</div></command-coqdoc></frame><frame frameNumber="164"><command>

Fixpoint Reverse (L: List) : List :=
 match L with
 | nil =&gt; nil 
 | cons l ls =&gt; Append (Reverse ls) (cons l nil)
 end.</command><response>Reverse is recursively defined (decreasing on 1st argument)
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Fixpoint</span> <span class="id" type="var">Reverse</span> (<span class="id" type="var">L</span>: <span class="id" type="var">List</span>) : <span class="id" type="var">List</span> :=<br/>
 <span class="id" type="keyword">match</span> <span class="id" type="var">L</span> <span class="id" type="keyword">with</span><br/>
 | <span class="id" type="var">nil</span> =&gt; <span class="id" type="var">nil</span> <br/>
 | <span class="id" type="var">cons</span> <span class="id" type="var">l</span> <span class="id" type="var">ls</span> =&gt; <span class="id" type="var">Append</span> (<span class="id" type="var">Reverse</span> <span class="id" type="var">ls</span>) (<span class="id" type="var">cons</span> <span class="id" type="var">l</span> <span class="id" type="var">nil</span>)<br/>
 <span class="id" type="keyword">end</span>.
</div></command-coqdoc></frame><frame frameNumber="165"><command>

Lemma Reverse_nil: Reverse nil = nil.</command><response>1 subgoal
  
  ============================
   Reverse nil = nil
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">Reverse_nil</span>: <span class="id" type="var">Reverse</span> <span class="id" type="var">nil</span> = <span class="id" type="var">nil</span>.
</div></command-coqdoc></frame><frame frameNumber="166"><command>
Admitted.</command><response>Reverse_nil is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="167"><command>

Lemma Reverse_two_elts: forall a b: nat, 
 Reverse (cons a (cons b nil))= cons b (cons a nil).</command><response>1 subgoal
  
  ============================
   forall a b : nat, Reverse (cons a (cons b nil)) = cons b (cons a nil)
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">Reverse_two_elts</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">a</span> <span class="id" type="var">b</span>: <span class="id" type="var">nat</span>, <br/>
 <span class="id" type="var">Reverse</span> (<span class="id" type="var">cons</span> <span class="id" type="var">a</span> (<span class="id" type="var">cons</span> <span class="id" type="var">b</span> <span class="id" type="var">nil</span>))= <span class="id" type="var">cons</span> <span class="id" type="var">b</span> (<span class="id" type="var">cons</span> <span class="id" type="var">a</span> <span class="id" type="var">nil</span>).
</div></command-coqdoc></frame><frame frameNumber="168"><command>
Admitted.</command><response>Reverse_two_elts is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="169"><command>

(** 
  In the following lemma you may need to use the commutativity
 of plus. This result is present in Coq standard library
 together with plenty of other results.
 See: http://coq.inria.fr/library-eng.html

  Libraries can be loaded using &quot;Require Import&quot; command.
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  In the following lemma you may need to use the commutativity
 of plus. This result is present in Coq standard library
 together with plenty of other results.
 See: http://coq.inria.fr/library-eng.html

<br/><br/>
  Libraries can be loaded using &quot;Require Import&quot; command.

</div></command-coqdoc></frame><frame frameNumber="170"><command>
Require Import Arith.</command><response/><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Require</span> <span class="id" type="keyword">Import</span> <span class="id" type="var">Arith</span>.
</div></command-coqdoc></frame><frame frameNumber="171"><command>
(**
  You can search for all results concerning plus (or any other 
 definition) with the following command:
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
  You can search for all results concerning plus (or any other 
 definition) with the following command:

</div></command-coqdoc></frame><frame frameNumber="172"><command>
SearchAbout plus.</command><response>natSRth: semi_ring_theory 0 1 plus mult eq
nat_morph_N:
  semi_morph 0 1 plus mult eq BinNat.N0 (BinNat.Npos 1) BinNat.Nplus
    BinNat.Nmult Neq_bool Nnat.nat_of_N
natr_ring_lemma1:
  forall (n : nat) (l : List.list nat)
    (lpe : List.list
             (Ring_polynom.PExpr BinNat.N * Ring_polynom.PExpr BinNat.N))
    (pe1 pe2 : Ring_polynom.PExpr BinNat.N),
  Ring_polynom.interp_PElist 0 plus mult (SRsub plus) SRopp eq Nnat.nat_of_N
    id_phi_N (pow_N 1 mult) l lpe -&gt;
  (let lmp :=
     Ring_polynom.mk_monpol_list BinNat.N0 (BinNat.Npos 1) BinNat.Nplus
       BinNat.Nmult BinNat.Nplus (fun x : BinNat.N =&gt; x) Neq_bool
       ZOdiv_def.Ndiv_eucl lpe in
   Ring_polynom.Peq Neq_bool
     (Ring_polynom.norm_subst BinNat.N0 (BinNat.Npos 1) BinNat.Nplus
        BinNat.Nmult BinNat.Nplus (fun x : BinNat.N =&gt; x) Neq_bool
        ZOdiv_def.Ndiv_eucl n lmp pe1)
     (Ring_polynom.norm_subst BinNat.N0 (BinNat.Npos 1) BinNat.Nplus
        BinNat.Nmult BinNat.Nplus (fun x : BinNat.N =&gt; x) Neq_bool
        ZOdiv_def.Ndiv_eucl n lmp pe2)) = true -&gt;
  Ring_polynom.PEeval 0 plus mult (SRsub plus) SRopp Nnat.nat_of_N id_phi_N
    (pow_N 1 mult) l pe1 =
  Ring_polynom.PEeval 0 plus mult (SRsub plus) SRopp Nnat.nat_of_N id_phi_N
    (pow_N 1 mult) l pe2
natr_ring_lemma2:
  forall (n : nat)
    (lH : List.list
            (Ring_polynom.PExpr BinNat.N * Ring_polynom.PExpr BinNat.N))
    (l : List.list nat),
  Ring_polynom.interp_PElist 0 plus mult (SRsub plus) SRopp eq Nnat.nat_of_N
    id_phi_N (pow_N 1 mult) l lH -&gt;
  forall
    lmp : List.list (BinNat.N * Ring_polynom.Mon * Ring_polynom.Pol BinNat.N),
  Ring_polynom.mk_monpol_list BinNat.N0 (BinNat.Npos 1) BinNat.Nplus
    BinNat.Nmult BinNat.Nplus (fun x : BinNat.N =&gt; x) Neq_bool
    ZOdiv_def.Ndiv_eucl lH = lmp -&gt;
  forall (pe : Ring_polynom.PExpr BinNat.N) (npe : Ring_polynom.Pol BinNat.N),
  Ring_polynom.norm_subst BinNat.N0 (BinNat.Npos 1) BinNat.Nplus BinNat.Nmult
    BinNat.Nplus (fun x : BinNat.N =&gt; x) Neq_bool ZOdiv_def.Ndiv_eucl n lmp
    pe = npe -&gt;
  Ring_polynom.PEeval 0 plus mult (SRsub plus) SRopp Nnat.nat_of_N id_phi_N
    (pow_N 1 mult) l pe =
  Ring_polynom.Pphi_dev 0 1 plus mult (SRsub plus) SRopp BinNat.N0
    (BinNat.Npos 1) Neq_bool Nnat.nat_of_N get_sign_None l npe
BinInt.ZL0: 2 = 1 + 1
Div2.double_plus:
  forall n m : nat, Div2.double (n + m) = Div2.double n + Div2.double m
Even.even_plus_split:
  forall n m : nat,
  Even.even (n + m) -&gt; Even.even n /\ Even.even m \/ Even.odd n /\ Even.odd m
Even.odd_plus_split:
  forall n m : nat,
  Even.odd (n + m) -&gt; Even.odd n /\ Even.even m \/ Even.even n /\ Even.odd m
Even.even_even_plus:
  forall n m : nat, Even.even n -&gt; Even.even m -&gt; Even.even (n + m)
Even.odd_plus_l:
  forall n m : nat, Even.odd n -&gt; Even.even m -&gt; Even.odd (n + m)
Even.odd_plus_r:
  forall n m : nat, Even.even n -&gt; Even.odd m -&gt; Even.odd (n + m)
Even.odd_even_plus:
  forall n m : nat, Even.odd n -&gt; Even.odd m -&gt; Even.even (n + m)
Even.even_plus_aux:
  forall n m : nat,
  (Even.odd (n + m) &lt;-&gt;
   Even.odd n /\ Even.even m \/ Even.even n /\ Even.odd m) /\
  (Even.even (n + m) &lt;-&gt;
   Even.even n /\ Even.even m \/ Even.odd n /\ Even.odd m)
Even.even_plus_even_inv_r:
  forall n m : nat, Even.even (n + m) -&gt; Even.even n -&gt; Even.even m
Even.even_plus_even_inv_l:
  forall n m : nat, Even.even (n + m) -&gt; Even.even m -&gt; Even.even n
Even.even_plus_odd_inv_r:
  forall n m : nat, Even.even (n + m) -&gt; Even.odd n -&gt; Even.odd m
Even.even_plus_odd_inv_l:
  forall n m : nat, Even.even (n + m) -&gt; Even.odd m -&gt; Even.odd n
Even.odd_plus_even_inv_l:
  forall n m : nat, Even.odd (n + m) -&gt; Even.odd m -&gt; Even.even n
Even.odd_plus_even_inv_r:
  forall n m : nat, Even.odd (n + m) -&gt; Even.odd n -&gt; Even.even m
Even.odd_plus_odd_inv_l:
  forall n m : nat, Even.odd (n + m) -&gt; Even.even m -&gt; Even.odd n
Even.odd_plus_odd_inv_r:
  forall n m : nat, Even.odd (n + m) -&gt; Even.even n -&gt; Even.odd m
plus_gt_reg_l: forall n m p : nat, p + n &gt; p + m -&gt; n &gt; m
plus_gt_compat_l: forall n m p : nat, n &gt; m -&gt; p + n &gt; p + m
List.app_length:
  forall (A : Type) (l l' : List.list A),
  List.length (List.app l l') = List.length l + List.length l'
List.seq_nth:
  forall len start n d : nat,
  n &lt; len -&gt; List.nth n (List.seq start len) d = start + n
minus_plus_simpl_l_reverse: forall n m p : nat, n - m = p + n - (p + m)
plus_minus: forall n m p : nat, n = m + p -&gt; p = n - m
minus_plus: forall n m : nat, n + m - n = m
le_plus_minus: forall n m : nat, n &lt;= m -&gt; m = n + (m - n)
le_plus_minus_r: forall n m : nat, n &lt;= m -&gt; n + (m - n) = m
mult_plus_distr_r: forall n m p : nat, (n + m) * p = n * p + m * p
mult_plus_distr_l: forall n m p : nat, n * (m + p) = n * m + n * p
mult_succ_l: forall n m : nat, S n * m = n * m + m
mult_succ_r: forall n m : nat, n * S m = n * m + n
odd_even_lem: forall p q : nat, 2 * p + 1 &lt;&gt; 2 * q
mult_acc_aux: forall n m p : nat, m + n * p = mult_acc m p n
Nnat.nat_of_Nplus:
  forall a a' : BinNat.N,
  Nnat.nat_of_N (BinNat.Nplus a a') = Nnat.nat_of_N a + Nnat.nat_of_N a'
Nnat.N_of_plus:
  forall n n' : nat,
  Nnat.N_of_nat (n + n') = BinNat.Nplus (Nnat.N_of_nat n) (Nnat.N_of_nat n')
plus_n_O: forall n : nat, n = n + 0
plus_O_n: forall n : nat, 0 + n = n
plus_n_Sm: forall n m : nat, S (n + m) = n + S m
plus_Sn_m: forall n m : nat, S n + m = S (n + m)
mult_n_Sm: forall n m : nat, n * m + n = n * S m
plus_0_l: forall n : nat, 0 + n = n
plus_0_r: forall n : nat, n + 0 = n
plus_comm: forall n m : nat, n + m = m + n
plus_Snm_nSm: forall n m : nat, S n + m = n + S m
plus_assoc: forall n m p : nat, n + (m + p) = n + m + p
plus_permute: forall n m p : nat, n + (m + p) = m + (n + p)
plus_assoc_reverse: forall n m p : nat, n + m + p = n + (m + p)
plus_reg_l: forall n m p : nat, p + n = p + m -&gt; n = m
plus_le_reg_l: forall n m p : nat, p + n &lt;= p + m -&gt; n &lt;= m
plus_lt_reg_l: forall n m p : nat, p + n &lt; p + m -&gt; n &lt; m
plus_le_compat_l: forall n m p : nat, n &lt;= m -&gt; p + n &lt;= p + m
plus_le_compat_r: forall n m p : nat, n &lt;= m -&gt; n + p &lt;= m + p
le_plus_l: forall n m : nat, n &lt;= n + m
le_plus_r: forall n m : nat, m &lt;= n + m
le_plus_trans: forall n m p : nat, n &lt;= m -&gt; n &lt;= m + p
lt_plus_trans: forall n m p : nat, n &lt; m -&gt; n &lt; m + p
plus_lt_compat_l: forall n m p : nat, n &lt; m -&gt; p + n &lt; p + m
plus_lt_compat_r: forall n m p : nat, n &lt; m -&gt; n + p &lt; m + p
plus_le_compat: forall n m p q : nat, n &lt;= m -&gt; p &lt;= q -&gt; n + p &lt;= m + q
plus_le_lt_compat: forall n m p q : nat, n &lt;= m -&gt; p &lt; q -&gt; n + p &lt; m + q
plus_lt_le_compat: forall n m p q : nat, n &lt; m -&gt; p &lt;= q -&gt; n + p &lt; m + q
plus_lt_compat: forall n m p q : nat, n &lt; m -&gt; p &lt; q -&gt; n + p &lt; m + q
plus_is_O: forall n m : nat, n + m = 0 -&gt; n = 0 /\ m = 0
plus_is_one:
  forall m n : nat, m + n = 1 -&gt; {m = 0 /\ n = 1} + {m = 1 /\ n = 0}
plus_permute_2_in_4: forall n m p q : nat, n + m + (p + q) = n + p + (m + q)
plus_tail_plus: forall n m : nat, n + m = tail_plus n m
succ_plus_discr: forall n m : nat, n &lt;&gt; S (m + n)
Pnat.Pmult_nat_succ_morphism:
  forall (p : BinPos.positive) (n : nat),
  BinPos.Pmult_nat (BinPos.Psucc p) n = n + BinPos.Pmult_nat p n
Pnat.Pmult_nat_plus_carry_morphism:
  forall (p q : BinPos.positive) (n : nat),
  BinPos.Pmult_nat (BinPos.Pplus_carry p q) n =
  n + BinPos.Pmult_nat (BinPos.Pplus p q) n
Pnat.Pmult_nat_l_plus_morphism:
  forall (p q : BinPos.positive) (n : nat),
  BinPos.Pmult_nat (BinPos.Pplus p q) n =
  BinPos.Pmult_nat p n + BinPos.Pmult_nat q n
Pnat.nat_of_P_plus_morphism:
  forall p q : BinPos.positive,
  BinPos.nat_of_P (BinPos.Pplus p q) = BinPos.nat_of_P p + BinPos.nat_of_P q
Pnat.Pmult_nat_r_plus_morphism:
  forall (p : BinPos.positive) (n : nat),
  BinPos.Pmult_nat p (n + n) = BinPos.Pmult_nat p n + BinPos.Pmult_nat p n
Pnat.ZL6:
  forall p : BinPos.positive,
  BinPos.Pmult_nat p 2 = BinPos.nat_of_P p + BinPos.nat_of_P p
Pnat.ZL7: forall n m : nat, n &lt; m -&gt; n + n &lt; m + m
Pnat.ZL8: forall n m : nat, n &lt; m -&gt; S (n + n) &lt; m + m
Pnat.ZL3:
  forall n : nat,
  BinPos.Psucc (BinPos.P_of_succ_nat (n + n)) =
  BinPos.xO (BinPos.P_of_succ_nat n)
Pnat.ZL5:
  forall n : nat,
  BinPos.P_of_succ_nat (S n + S n) = BinPos.xI (BinPos.P_of_succ_nat n)
iter_nat_plus:
  forall (n m : nat) (A : Type) (f : A -&gt; A) (x : A),
  iter_nat (n + m) A f x = iter_nat n A f (iter_nat m A f x)
Zabs.Zabs_nat_Zplus:
  forall x y : BinInt.Z,
  BinInt.Zle 0 x -&gt;
  BinInt.Zle 0 y -&gt;
  BinInt.Zabs_nat (BinInt.Zplus x y) = BinInt.Zabs_nat x + BinInt.Zabs_nat y
Znat.inj_plus:
  forall n m : nat,
  BinInt.Z_of_nat (n + m) =
  BinInt.Zplus (BinInt.Z_of_nat n) (BinInt.Z_of_nat m)
Len_Append: forall L R : List, Len (Append L R) = Len L + Len R
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Search</span><span class="id" type="var">About</span> <span class="id" type="var">plus</span>.
</div></command-coqdoc></frame><frame frameNumber="173"><command>
(**
  The lemma stating commutativity of plus is called &quot;plus_comm&quot;
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
  The lemma stating commutativity of plus is called &quot;plus_comm&quot;

</div></command-coqdoc></frame><frame frameNumber="174"><command>
Check plus_comm.</command><response>plus_comm
     : forall n m : nat, n + m = m + n
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Check</span> <span class="id" type="var">plus_comm</span>.
</div></command-coqdoc></frame><frame frameNumber="175"><command>

(** 
  Prove that Reverse returns a list of the same size as 
 its argument 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  Prove that Reverse returns a list of the same size as 
 its argument 

</div></command-coqdoc></frame><frame frameNumber="176"><command>
Lemma Reverse_Len: forall L: List, Len (Reverse L) = Len L.</command><response>1 subgoal
  
  ============================
   forall L : List, Len (Reverse L) = Len L
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">Reverse_Len</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">L</span>: <span class="id" type="var">List</span>, <span class="id" type="var">Len</span> (<span class="id" type="var">Reverse</span> <span class="id" type="var">L</span>) = <span class="id" type="var">Len</span> <span class="id" type="var">L</span>.
</div></command-coqdoc></frame><frame frameNumber="177"><command>
Admitted.</command><response>Reverse_Len is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="178"><command>

(** 
  Prove that if we apply Reverse two times we get back the 
 original list. For that you may need a number of auxiliary 
 lemmas, like: associativity of Append
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  Prove that if we apply Reverse two times we get back the 
 original list. For that you may need a number of auxiliary 
 lemmas, like: associativity of Append

</div></command-coqdoc></frame><frame frameNumber="179"><command>
Lemma Append_assoc: forall L R T: List, 
 Append (Append L R) T = Append L (Append R T).</command><response>1 subgoal
  
  ============================
   forall L R T : List, Append (Append L R) T = Append L (Append R T)
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">Append_assoc</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">L</span> <span class="id" type="var">R</span> <span class="id" type="var">T</span>: <span class="id" type="var">List</span>, <br/>
 <span class="id" type="var">Append</span> (<span class="id" type="var">Append</span> <span class="id" type="var">L</span> <span class="id" type="var">R</span>) <span class="id" type="var">T</span> = <span class="id" type="var">Append</span> <span class="id" type="var">L</span> (<span class="id" type="var">Append</span> <span class="id" type="var">R</span> <span class="id" type="var">T</span>).
</div></command-coqdoc></frame><frame frameNumber="180"><command>
Admitted.</command><response>Append_assoc is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="181"><command>

(**
  ... appending with an empty list as second argument
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
  ... appending with an empty list as second argument

</div></command-coqdoc></frame><frame frameNumber="182"><command>
Lemma Append_nil: forall L: List, Append L nil = L.</command><response>1 subgoal
  
  ============================
   forall L : List, Append L nil = L
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">Append_nil</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">L</span>: <span class="id" type="var">List</span>, <span class="id" type="var">Append</span> <span class="id" type="var">L</span> <span class="id" type="var">nil</span> = <span class="id" type="var">L</span>.
</div></command-coqdoc></frame><frame frameNumber="183"><command>
Admitted.</command><response>Append_nil is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="184"><command>

(**
 ... and distributivity of Reverse with Append
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
 ... and distributivity of Reverse with Append

</div></command-coqdoc></frame><frame frameNumber="185"><command>
Lemma Reverse_Append: forall L R: List, 
 Reverse (Append L R) = Append (Reverse R) (Reverse L).</command><response>1 subgoal
  
  ============================
   forall L R : List, Reverse (Append L R) = Append (Reverse R) (Reverse L)
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">Reverse_Append</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">L</span> <span class="id" type="var">R</span>: <span class="id" type="var">List</span>, <br/>
 <span class="id" type="var">Reverse</span> (<span class="id" type="var">Append</span> <span class="id" type="var">L</span> <span class="id" type="var">R</span>) = <span class="id" type="var">Append</span> (<span class="id" type="var">Reverse</span> <span class="id" type="var">R</span>) (<span class="id" type="var">Reverse</span> <span class="id" type="var">L</span>).
</div></command-coqdoc></frame><frame frameNumber="186"><command>
Admitted.</command><response>Reverse_Append is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="187"><command>

(**
 Finally: double Reverse
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
 Finally: double Reverse

</div></command-coqdoc></frame><frame frameNumber="188"><command>
Lemma Reverse_twice: forall L: List, L = Reverse (Reverse L).</command><response>1 subgoal
  
  ============================
   forall L : List, L = Reverse (Reverse L)
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">Reverse_twice</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">L</span>: <span class="id" type="var">List</span>, <span class="id" type="var">L</span> = <span class="id" type="var">Reverse</span> (<span class="id" type="var">Reverse</span> <span class="id" type="var">L</span>).
</div></command-coqdoc></frame><frame frameNumber="189"><command>
Admitted.</command><response>Reverse_twice is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="190"><command>

(* ###################################################################### *)</command><response/><command-coqdoc/></frame><frame frameNumber="191"><command>
(** * Naive Set Theory *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
<a name="lab1"/><h1 class="section">Naive Set Theory</h1>

</div></command-coqdoc></frame><frame frameNumber="192"><command>
(** *** Exercise 8. (naive set representation) *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
<a name="lab1"/><h3 class="section">Exercise 8. (naive set representation)</h3>

</div></command-coqdoc></frame><frame frameNumber="193"><command>

(**
 Introduce a variable U of type Set.: 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">
 Introduce a variable U of type Set.: 

</div></command-coqdoc></frame><frame frameNumber="194"><command>

Variable U: Set.</command><response>U is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Variable</span> <span class="id" type="var">U</span>: <span class="id" type="keyword">Set</span>.
</div></command-coqdoc></frame><frame frameNumber="195"><command>

(** 
   We can think of the predicates on &quot;U&quot; as sets, i.e. &quot;U&quot; is the 
 'universe' of all objects and a set is a predicate that describes
 which of the elements of the universe belong to it. If &quot;A&quot; is of 
 type &quot;U -&gt; Prop&quot; then &quot;A&quot; can be seen as the set {x:U | A(x)}, 
 the elements of U for which the predicate holds. Hence we define
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
   We can think of the predicates on &quot;U&quot; as sets, i.e. &quot;U&quot; is the 
 'universe' of all objects and a set is a predicate that describes
 which of the elements of the universe belong to it. If &quot;A&quot; is of 
 type &quot;U -&gt; Prop&quot; then &quot;A&quot; can be seen as the set {x:U | A(x)}, 
 the elements of U for which the predicate holds. Hence we define

</div></command-coqdoc></frame><frame frameNumber="196"><command>
Definition SET := U -&gt; Prop.</command><response>SET is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">SET</span> := <span class="id" type="var">U</span> -&gt; <span class="id" type="keyword">Prop</span>.
</div></command-coqdoc></frame><frame frameNumber="197"><command>

(** 
  If &quot;A: SET&quot; and &quot;x: U&quot; then &quot;A x&quot; means `x is an element of A'. 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  If &quot;A: SET&quot; and &quot;x: U&quot; then &quot;A x&quot; means `x is an element of A'. 

</div></command-coqdoc></frame><frame frameNumber="198"><command>

(** 1. Define the subset relation on SET. *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
1. Define the subset relation on SET. 
</div></command-coqdoc></frame><frame frameNumber="199"><command>
Definition subset (P Q: SET) := forall x: U, P x -&gt; Q x.</command><response>subset is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">subset</span> (<span class="id" type="var">P</span> <span class="id" type="var">Q</span>: <span class="id" type="var">SET</span>) := <span class="id" type="keyword">forall</span> <span class="id" type="var">x</span>: <span class="id" type="var">U</span>, <span class="id" type="var">P</span> <span class="id" type="var">x</span> -&gt; <span class="id" type="var">Q</span> <span class="id" type="var">x</span>.
</div></command-coqdoc></frame><frame frameNumber="200"><command>
Check subset.</command><response>subset
     : SET -&gt; SET -&gt; Prop
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Check</span> <span class="id" type="var">subset</span>.
</div></command-coqdoc></frame><frame frameNumber="201"><command>

(** 2. Prove that subset is reflexive and transitive *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
2. Prove that subset is reflexive and transitive 
</div></command-coqdoc></frame><frame frameNumber="202"><command>
Lemma subset_refl: forall A: SET, subset A A.</command><response>1 subgoal
  
  ============================
   forall A : SET, subset A A
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">subset_refl</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">A</span>: <span class="id" type="var">SET</span>, <span class="id" type="var">subset</span> <span class="id" type="var">A</span> <span class="id" type="var">A</span>.
</div></command-coqdoc></frame><frame frameNumber="203"><command>
Admitted.</command><response>subset_refl is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="204"><command>

Lemma subset_trans: forall A B C: SET, 
 subset A B -&gt; subset B C -&gt; subset A C.</command><response>1 subgoal
  
  ============================
   forall A B C : SET, subset A B -&gt; subset B C -&gt; subset A C
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">subset_trans</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">A</span> <span class="id" type="var">B</span> <span class="id" type="var">C</span>: <span class="id" type="var">SET</span>, <br/>
 <span class="id" type="var">subset</span> <span class="id" type="var">A</span> <span class="id" type="var">B</span> -&gt; <span class="id" type="var">subset</span> <span class="id" type="var">B</span> <span class="id" type="var">C</span> -&gt; <span class="id" type="var">subset</span> <span class="id" type="var">A</span> <span class="id" type="var">C</span>.
</div></command-coqdoc></frame><frame frameNumber="205"><command>
Admitted.</command><response>subset_trans is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="206"><command>

(** 
  3. Using subset, define equality, union and intersection of 
 SETs. Note that &quot;/\&quot; is Coq notation for conjunction and &quot;\/&quot;
 for disjunction.
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  3. Using subset, define equality, union and intersection of 
 SETs. Note that &quot;/\&quot; is Coq notation for conjunction and &quot;\/&quot;
 for disjunction.

</div></command-coqdoc></frame><frame frameNumber="207"><command>
Definition eq_set (A B: SET) := subset A B /\ subset B A.</command><response>eq_set is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">eq_set</span> (<span class="id" type="var">A</span> <span class="id" type="var">B</span>: <span class="id" type="var">SET</span>) := <span class="id" type="var">subset</span> <span class="id" type="var">A</span> <span class="id" type="var">B</span> /\ <span class="id" type="var">subset</span> <span class="id" type="var">B</span> <span class="id" type="var">A</span>.
</div></command-coqdoc></frame><frame frameNumber="208"><command>
Definition union (A B: SET) := fun x:U =&gt; A x \/ B x.</command><response>union is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">union</span> (<span class="id" type="var">A</span> <span class="id" type="var">B</span>: <span class="id" type="var">SET</span>) := <span class="id" type="keyword">fun</span> <span class="id" type="var">x</span>:U =&gt; <span class="id" type="var">A</span> <span class="id" type="var">x</span> \/ <span class="id" type="var">B</span> <span class="id" type="var">x</span>.
</div></command-coqdoc></frame><frame frameNumber="209"><command>
Definition intersection (A B: SET) := fun x:U =&gt; A x /\ B x.</command><response>intersection is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">intersection</span> (<span class="id" type="var">A</span> <span class="id" type="var">B</span>: <span class="id" type="var">SET</span>) := <span class="id" type="keyword">fun</span> <span class="id" type="var">x</span>:U =&gt; <span class="id" type="var">A</span> <span class="id" type="var">x</span> /\ <span class="id" type="var">B</span> <span class="id" type="var">x</span>.
</div></command-coqdoc></frame><frame frameNumber="210"><command>

(** 4. Prove *)</command><response/><command-coqdoc><div class="doc" divNumber="0">
4. Prove 
</div></command-coqdoc></frame><frame frameNumber="211"><command>
Lemma intersection_subset: forall A B: SET,
  subset (intersection A B) A.</command><response>1 subgoal
  
  ============================
   forall A B : SET, subset (intersection A B) A
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">intersection_subset</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">A</span> <span class="id" type="var">B</span>: <span class="id" type="var">SET</span>,<br/>
  <span class="id" type="var">subset</span> (<span class="id" type="var">intersection</span> <span class="id" type="var">A</span> <span class="id" type="var">B</span>) <span class="id" type="var">A</span>.
</div></command-coqdoc></frame><frame frameNumber="212"><command>
Admitted.</command><response>intersection_subset is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="213"><command>

Lemma subset_union: forall A B: SET,
  subset A (union A B).</command><response>1 subgoal
  
  ============================
   forall A B : SET, subset A (union A B)
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">subset_union</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">A</span> <span class="id" type="var">B</span>: <span class="id" type="var">SET</span>,<br/>
  <span class="id" type="var">subset</span> <span class="id" type="var">A</span> (<span class="id" type="var">union</span> <span class="id" type="var">A</span> <span class="id" type="var">B</span>).
</div></command-coqdoc></frame><frame frameNumber="214"><command>
Admitted.</command><response>subset_union is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="215"><command>

Lemma union_double: forall A: SET, eq_set (union A A) A.</command><response>1 subgoal
  
  ============================
   forall A : SET, eq_set (union A A) A
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">union_double</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">A</span>: <span class="id" type="var">SET</span>, <span class="id" type="var">eq_set</span> (<span class="id" type="var">union</span> <span class="id" type="var">A</span> <span class="id" type="var">A</span>) <span class="id" type="var">A</span>.
</div></command-coqdoc></frame><frame frameNumber="216"><command>
Admitted.</command><response>union_double is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="217"><command>

(** 
  5. Define the empty set and prove that it is a subset of every 
 other SET. 
*)</command><response/><command-coqdoc><div class="doc" divNumber="0">

<br/><br/>
  5. Define the empty set and prove that it is a subset of every 
 other SET. 

</div></command-coqdoc></frame><frame frameNumber="218"><command>
Definition empty := fun x:U =&gt; False.</command><response>empty is defined
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">empty</span> := <span class="id" type="keyword">fun</span> <span class="id" type="var">x</span>:U =&gt; <span class="id" type="var">False</span>.
</div></command-coqdoc></frame><frame frameNumber="219"><command>

Lemma empty_subset: forall A: SET, subset empty A.</command><response>1 subgoal
  
  ============================
   forall A : SET, subset empty A
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">empty_subset</span>: <span class="id" type="keyword">forall</span> <span class="id" type="var">A</span>: <span class="id" type="var">SET</span>, <span class="id" type="var">subset</span> <span class="id" type="var">empty</span> <span class="id" type="var">A</span>.
</div></command-coqdoc></frame><frame frameNumber="220"><command>
Admitted.</command><response>empty_subset is assumed
</response><command-coqdoc><div class="code" divNumber="0">

<br/>
<span class="id" type="var">Admitted</span>.
</div></command-coqdoc></frame><frame frameNumber="221"><command>
</command><response/><command-coqdoc/></frame></film><scenes><scene class="doc" sceneNumber="0"><div-reference div="0" frame="0"/><div-reference div="0" frame="3"/><div-reference div="0" frame="4"/><div-reference div="0" frame="6"/><div-reference div="0" frame="7"/></scene><scene class="code" sceneNumber="1"><div-reference div="0" frame="8"/></scene><scene class="doc" sceneNumber="2"><div-reference div="0" frame="9"/></scene><scene class="code" sceneNumber="3"><div-reference div="0" frame="10"/><div-reference div="0" frame="11"/><div-reference div="0" frame="12"/><div-reference div="0" frame="13"/><div-reference div="0" frame="14"/><div-reference div="0" frame="15"/></scene><scene class="doc" sceneNumber="4"><div-reference div="0" frame="16"/></scene><scene class="code" sceneNumber="5"><div-reference div="0" frame="17"/></scene><scene class="doc" sceneNumber="6"><div-reference div="0" frame="18"/></scene><scene class="code" sceneNumber="7"><div-reference div="0" frame="19"/><div-reference div="0" frame="20"/><div-reference div="0" frame="21"/><div-reference div="0" frame="22"/><div-reference div="0" frame="23"/><div-reference div="0" frame="24"/><div-reference div="0" frame="25"/><div-reference div="0" frame="26"/></scene><scene class="doc" sceneNumber="8"><div-reference div="0" frame="27"/><div-reference div="0" frame="28"/></scene><scene class="code" sceneNumber="9"><div-reference div="0" frame="29"/><div-reference div="0" frame="30"/><div-reference div="0" frame="31"/></scene><scene class="doc" sceneNumber="10"><div-reference div="0" frame="32"/></scene><scene class="code" sceneNumber="11"><div-reference div="0" frame="33"/></scene><scene class="doc" sceneNumber="12"><div-reference div="0" frame="34"/></scene><scene class="code" sceneNumber="13"><div-reference div="0" frame="35"/></scene><scene class="doc" sceneNumber="14"><div-reference div="0" frame="36"/><div-reference div="0" frame="37"/></scene><scene class="code" sceneNumber="15"><div-reference div="0" frame="38"/></scene><scene class="doc" sceneNumber="16"><div-reference div="0" frame="39"/><div-reference div="0" frame="40"/></scene><scene class="code" sceneNumber="17"><div-reference div="0" frame="41"/></scene><scene class="doc" sceneNumber="18"><div-reference div="0" frame="42"/></scene><scene class="code" sceneNumber="19"><div-reference div="0" frame="43"/></scene><scene class="doc" sceneNumber="20"><div-reference div="0" frame="44"/></scene><scene class="code" sceneNumber="21"><div-reference div="0" frame="45"/><div-reference div="0" frame="46"/><div-reference div="0" frame="47"/><div-reference div="0" frame="48"/><div-reference div="0" frame="49"/><div-reference div="0" frame="50"/></scene><scene class="doc" sceneNumber="22"><div-reference div="0" frame="51"/><div-reference div="0" frame="53"/><div-reference div="0" frame="54"/></scene><scene class="code" sceneNumber="23"><div-reference div="0" frame="55"/><div-reference div="0" frame="56"/><div-reference div="0" frame="57"/></scene><scene class="doc" sceneNumber="24"><div-reference div="0" frame="58"/></scene><scene class="code" sceneNumber="25"><div-reference div="0" frame="59"/></scene><scene class="doc" sceneNumber="26"><div-reference div="0" frame="60"/></scene><scene class="code" sceneNumber="27"><div-reference div="0" frame="61"/><div-reference div="0" frame="62"/><div-reference div="0" frame="63"/><div-reference div="0" frame="64"/><div-reference div="0" frame="66"/><div-reference div="0" frame="68"/><div-reference div="0" frame="70"/><div-reference div="0" frame="72"/></scene><scene class="doc" sceneNumber="28"><div-reference div="0" frame="73"/></scene><scene class="code" sceneNumber="29"><div-reference div="0" frame="74"/></scene><scene class="doc" sceneNumber="30"><div-reference div="0" frame="75"/></scene><scene class="code" sceneNumber="31"><div-reference div="0" frame="76"/></scene><scene class="doc" sceneNumber="32"><div-reference div="0" frame="77"/></scene><scene class="code" sceneNumber="33"><div-reference div="0" frame="78"/></scene><scene class="doc" sceneNumber="34"><div-reference div="0" frame="80"/><div-reference div="0" frame="81"/></scene><scene class="code" sceneNumber="35"><div-reference div="0" frame="82"/><div-reference div="0" frame="83"/><div-reference div="0" frame="84"/><div-reference div="0" frame="85"/><div-reference div="0" frame="86"/><div-reference div="0" frame="87"/><div-reference div="0" frame="88"/><div-reference div="0" frame="89"/></scene><scene class="doc" sceneNumber="36"><div-reference div="0" frame="91"/><div-reference div="0" frame="92"/></scene><scene class="code" sceneNumber="37"><div-reference div="0" frame="93"/><div-reference div="0" frame="94"/></scene><scene class="doc" sceneNumber="38"><div-reference div="0" frame="95"/></scene><scene class="code" sceneNumber="39"><div-reference div="0" frame="96"/><div-reference div="0" frame="97"/></scene><scene class="doc" sceneNumber="40"><div-reference div="0" frame="98"/></scene><scene class="code" sceneNumber="41"><div-reference div="0" frame="99"/><div-reference div="0" frame="100"/><div-reference div="0" frame="101"/><div-reference div="0" frame="102"/><div-reference div="0" frame="103"/><div-reference div="0" frame="104"/></scene><scene class="doc" sceneNumber="42"><div-reference div="0" frame="106"/><div-reference div="0" frame="107"/></scene><scene class="code" sceneNumber="43"><div-reference div="0" frame="108"/></scene><scene class="doc" sceneNumber="44"><div-reference div="0" frame="109"/></scene><scene class="code" sceneNumber="45"><div-reference div="0" frame="110"/><div-reference div="0" frame="111"/></scene><scene class="doc" sceneNumber="46"><div-reference div="0" frame="112"/></scene><scene class="code" sceneNumber="47"><div-reference div="0" frame="113"/><div-reference div="0" frame="114"/></scene><scene class="doc" sceneNumber="48"><div-reference div="0" frame="116"/><div-reference div="0" frame="117"/></scene><scene class="code" sceneNumber="49"><div-reference div="0" frame="118"/><div-reference div="0" frame="119"/><div-reference div="0" frame="120"/><div-reference div="0" frame="121"/><div-reference div="0" frame="122"/><div-reference div="0" frame="123"/><div-reference div="0" frame="124"/><div-reference div="0" frame="125"/></scene><scene class="doc" sceneNumber="50"><div-reference div="0" frame="126"/><div-reference div="0" frame="128"/><div-reference div="0" frame="129"/></scene><scene class="code" sceneNumber="51"><div-reference div="0" frame="130"/><div-reference div="0" frame="131"/></scene><scene class="doc" sceneNumber="52"><div-reference div="0" frame="132"/></scene><scene class="code" sceneNumber="53"><div-reference div="0" frame="133"/><div-reference div="0" frame="134"/><div-reference div="0" frame="135"/><div-reference div="0" frame="136"/></scene><scene class="doc" sceneNumber="54"><div-reference div="0" frame="138"/><div-reference div="0" frame="139"/></scene><scene class="code" sceneNumber="55"><div-reference div="0" frame="140"/><div-reference div="0" frame="141"/><div-reference div="0" frame="142"/><div-reference div="0" frame="143"/><div-reference div="0" frame="144"/><div-reference div="0" frame="145"/></scene><scene class="doc" sceneNumber="56"><div-reference div="0" frame="147"/><div-reference div="0" frame="148"/></scene><scene class="code" sceneNumber="57"><div-reference div="0" frame="149"/></scene><scene class="doc" sceneNumber="58"><div-reference div="0" frame="150"/></scene><scene class="code" sceneNumber="59"><div-reference div="0" frame="151"/></scene><scene class="doc" sceneNumber="60"><div-reference div="0" frame="152"/><div-reference div="0" frame="153"/></scene><scene class="code" sceneNumber="61"><div-reference div="0" frame="154"/></scene><scene class="doc" sceneNumber="62"><div-reference div="0" frame="155"/></scene><scene class="code" sceneNumber="63"><div-reference div="0" frame="156"/><div-reference div="0" frame="157"/></scene><scene class="doc" sceneNumber="64"><div-reference div="0" frame="158"/></scene><scene class="code" sceneNumber="65"><div-reference div="0" frame="159"/><div-reference div="0" frame="160"/><div-reference div="0" frame="161"/><div-reference div="0" frame="162"/></scene><scene class="doc" sceneNumber="66"><div-reference div="0" frame="163"/></scene><scene class="code" sceneNumber="67"><div-reference div="0" frame="164"/><div-reference div="0" frame="165"/><div-reference div="0" frame="166"/><div-reference div="0" frame="167"/><div-reference div="0" frame="168"/></scene><scene class="doc" sceneNumber="68"><div-reference div="0" frame="169"/></scene><scene class="code" sceneNumber="69"><div-reference div="0" frame="170"/></scene><scene class="doc" sceneNumber="70"><div-reference div="0" frame="171"/></scene><scene class="code" sceneNumber="71"><div-reference div="0" frame="172"/></scene><scene class="doc" sceneNumber="72"><div-reference div="0" frame="173"/></scene><scene class="code" sceneNumber="73"><div-reference div="0" frame="174"/></scene><scene class="doc" sceneNumber="74"><div-reference div="0" frame="175"/></scene><scene class="code" sceneNumber="75"><div-reference div="0" frame="176"/><div-reference div="0" frame="177"/></scene><scene class="doc" sceneNumber="76"><div-reference div="0" frame="178"/></scene><scene class="code" sceneNumber="77"><div-reference div="0" frame="179"/><div-reference div="0" frame="180"/></scene><scene class="doc" sceneNumber="78"><div-reference div="0" frame="181"/></scene><scene class="code" sceneNumber="79"><div-reference div="0" frame="182"/><div-reference div="0" frame="183"/></scene><scene class="doc" sceneNumber="80"><div-reference div="0" frame="184"/></scene><scene class="code" sceneNumber="81"><div-reference div="0" frame="185"/><div-reference div="0" frame="186"/></scene><scene class="doc" sceneNumber="82"><div-reference div="0" frame="187"/></scene><scene class="code" sceneNumber="83"><div-reference div="0" frame="188"/><div-reference div="0" frame="189"/></scene><scene class="doc" sceneNumber="84"><div-reference div="0" frame="191"/><div-reference div="0" frame="192"/><div-reference div="0" frame="193"/></scene><scene class="code" sceneNumber="85"><div-reference div="0" frame="194"/></scene><scene class="doc" sceneNumber="86"><div-reference div="0" frame="195"/></scene><scene class="code" sceneNumber="87"><div-reference div="0" frame="196"/></scene><scene class="doc" sceneNumber="88"><div-reference div="0" frame="197"/><div-reference div="0" frame="198"/></scene><scene class="code" sceneNumber="89"><div-reference div="0" frame="199"/><div-reference div="0" frame="200"/></scene><scene class="doc" sceneNumber="90"><div-reference div="0" frame="201"/></scene><scene class="code" sceneNumber="91"><div-reference div="0" frame="202"/><div-reference div="0" frame="203"/><div-reference div="0" frame="204"/><div-reference div="0" frame="205"/></scene><scene class="doc" sceneNumber="92"><div-reference div="0" frame="206"/></scene><scene class="code" sceneNumber="93"><div-reference div="0" frame="207"/><div-reference div="0" frame="208"/><div-reference div="0" frame="209"/></scene><scene class="doc" sceneNumber="94"><div-reference div="0" frame="210"/></scene><scene class="code" sceneNumber="95"><div-reference div="0" frame="211"/><div-reference div="0" frame="212"/><div-reference div="0" frame="213"/><div-reference div="0" frame="214"/><div-reference div="0" frame="215"/><div-reference div="0" frame="216"/></scene><scene class="doc" sceneNumber="96"><div-reference div="0" frame="217"/></scene><scene class="code" sceneNumber="97"><div-reference div="0" frame="218"/><div-reference div="0" frame="219"/><div-reference div="0" frame="220"/></scene></scenes></movie>
