<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mathematics and Computation &#187; Logic</title>
	<atom:link href="http://math.andrej.com/category/logic/feed/?category_name=logic" rel="self" type="application/rss+xml" />
	<link>http://math.andrej.com</link>
	<description>Mathematics for computers</description>
	<lastBuildDate>Mon, 06 Feb 2012 13:47:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2-beta2-18055</generator>
		<item>
		<title>On the Bourbaki-Witt Principle in Toposes</title>
		<link>http://math.andrej.com/2012/01/04/on-the-bourbaki-witt-principle-in-toposes/</link>
		<comments>http://math.andrej.com/2012/01/04/on-the-bourbaki-witt-principle-in-toposes/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 07:09:10 +0000</pubDate>
		<dc:creator>Andrej Bauer</dc:creator>
				<category><![CDATA[Constructive math]]></category>
		<category><![CDATA[Logic]]></category>
		<category><![CDATA[Publications]]></category>

		<guid isPermaLink="false">http://math.andrej.com/?p=1104</guid>
		<description><![CDATA[<p>With Peter LeFanu Lumsdaine.</p>
<p>Abstract: The Bourbaki-Witt principle states that any progressive map on a chain-complete poset has a fixed point above every point. It is provable classically, but not intuitionistically. We study this and related principles in an intuitionistic setting. Among other things, we show that Bourbaki-Witt fails exactly when the trichotomous ordinals form a set, but does not [...]]]></description>
			<content:encoded><![CDATA[<p>With <a href="http://mathstat.dal.ca/~p.l.lumsdaine/">Peter LeFanu Lumsdaine</a>.</p>
<p><strong>Abstract: </strong>The Bourbaki-Witt principle states that any progressive map on a chain-complete poset has a fixed point above every point. It is provable classically, but not intuitionistically. We study this and related principles in an intuitionistic setting. Among other things, we show that Bourbaki-Witt fails exactly when the trichotomous ordinals form a set, but does not imply that fixed points can always be found by transfinite iteration. Meanwhile, on the side of models, we see that the principle fails in realisability toposes, and does not hold in the free topos, but does hold in all cocomplete toposes.</p>
<p><strong>Download paper:</strong> <a href="/wp-content/uploads/2012/01/bw.pdf">bw.pdf</a><br />
<strong>ArXiv version:</strong> <a href="http://arxiv.org/abs/1201.0340v1">arXiv:1201.0340v1</a> [math.CT]</p>
<p>This paper is an extension of my previous paper on <a href="/2009/01/23/on-the-failure-of-fixed-point-theorems-for-chain-complete-lattices-in-the-effective-topos/">the Bourbaki-Witt and Knaster-Tarski fixed-point theorems in the effective topos</a> (<a href="http://arxiv.org/abs/0911.0068v1">arXiv:0911.0068v1</a>).</p>
]]></content:encoded>
			<wfw:commentRss>http://math.andrej.com/2012/01/04/on-the-bourbaki-witt-principle-in-toposes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Constructive gem: an injection from Baire space to natural numbers</title>
		<link>http://math.andrej.com/2011/06/15/constructive-gem-an-injection-from-baire-space-to-natural-numbers/</link>
		<comments>http://math.andrej.com/2011/06/15/constructive-gem-an-injection-from-baire-space-to-natural-numbers/#comments</comments>
		<pubDate>Wed, 15 Jun 2011 13:48:19 +0000</pubDate>
		<dc:creator>Andrej Bauer</dc:creator>
				<category><![CDATA[Constructive math]]></category>
		<category><![CDATA[Gems and stones]]></category>
		<category><![CDATA[Logic]]></category>
		<category><![CDATA[Publications]]></category>

		<guid isPermaLink="false">http://math.andrej.com/?p=968</guid>
		<description><![CDATA[<p>I am not sure whether to call this one a constructive gem or stone. I suppose it is a matter of personal taste. I think it is a gem, albeit a very unusual one: there is a topos in which $\mathbb{N}^\mathbb{N}$ can be embedded into $\mathbb{N}$.</p>
<p>At the Mathematical Foundations of Programming Semantics XVII, which took place [...]]]></description>
			<content:encoded><![CDATA[<p>I am not sure whether to call this one a constructive gem or stone. I suppose it is a matter of personal taste. I think it is a gem, albeit a very unusual one: there is a topos in which $\mathbb{N}^\mathbb{N}$ can be embedded into $\mathbb{N}$.<span id="more-968"></span></p>
<p>At the <a href="www.math.tulane.edu/~mfps/">Mathematical Foundations of Programming Semantics XVII</a>, which took place at Carnegie Mellon University in May 2011, <a href="http://www.eecs.qmul.ac.uk/~pbo/">Paulo Oliva</a> and <a href="http://www.cs.bham.ac.uk/~mhe/">Martín Escardó</a> showed a program which witnessed the fact that there was no injection from the Baire space $\mathbb{N}^\mathbb{N}$ to natural numbers $\mathbb{N}$. The program took as input a function $h : \mathbb{N}^\mathbb{N} \to \mathbb{N}$ and produced two sequences $x, y \in \mathbb{N}^\mathbb{N}$ such that $x \neq y$ and $h(x) = h(y)$. Martín Escardó <a href="https://lists.chalmers.se/pipermail/agda/2011/003088.html">popularized the program</a> as interesting example of extraction of computational content from classical proofs, which <a href="http://groups.google.com/group/constructivenews/browse_thread/thread/5f65c7ac479c15dd">lead me to wonder</a> whether there was a constructive proof of the statement<br />
$$\forall h : \mathbb{N}^\mathbb{N} \to \mathbb{N} .<br />
\exists x, y \in \mathbb{N}^\mathbb{N} .<br />
(x \neq y \land h(x) = h(y))$$<br />
that would yield such programs more directly. <a href="http://math.fau.edu/richman/">Fred Richman</a> asked for a constructive proof of the weaker statement that there was no injection $\mathbb{N}^\mathbb{N} \to \mathbb{N}$, and nobody could come up with one.</p>
<p>Classically there is no injection $\mathbb{N}^\mathbb{N} \to \mathbb{N}$, of course. Constructively, it is easy to see that it must be wildly discontinuous, if it exists. Thus we cannot hope to find one in any of the usual varieties of constructive mathematics, as they all satisfy some kind of continuity principle.</p>
<p>If I am not mistaken, the realizability topos based on infinite time Turing machines by <a href="http://jdh.hamkins.org/">Joel Hamkins</a> contains an injection $\mathbb{N}^\mathbb{N} \to \mathbb{N}$. This is possible because infinite time Turing machines are powerful enough to be able to compute canonical realizers for infinite time computable maps $\mathbb{N} \to \mathbb{N}$. The details are in the paper, attached below. It is likely that the topos can be used for other ominous purposes. For example, it validates the principle LPO but its logic is not classical.</p>
<p><strong>Download:</strong> <a href="/wp-content/uploads/2011/06/injection.pdf">injection.pdf</a></p>
]]></content:encoded>
			<wfw:commentRss>http://math.andrej.com/2011/06/15/constructive-gem-an-injection-from-baire-space-to-natural-numbers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Running a classical proof with choice in Agda</title>
		<link>http://math.andrej.com/2011/05/10/running-a-classical-proof-with-choice-in-agda/</link>
		<comments>http://math.andrej.com/2011/05/10/running-a-classical-proof-with-choice-in-agda/#comments</comments>
		<pubDate>Tue, 10 May 2011 21:17:36 +0000</pubDate>
		<dc:creator>Martin Escardo</dc:creator>
				<category><![CDATA[Computation]]></category>
		<category><![CDATA[Constructive math]]></category>
		<category><![CDATA[Logic]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://math.andrej.com/?p=928</guid>
		<description><![CDATA[<p>As a preparation for my part of a joint tutorial Programs from proofs at MFPS 27 at the end of this month with Ulrich Berger, Monika Seisenberger, and Paulo Oliva, I&#8217;ve developed in Agda some things we&#8217;ve been doing together.</p>
<p>Using</p>

 Berardi-Bezem-Coquand functional, or alternatively,
Berger-Oliva modified bar recursion, or alternatively,
Escardo-Oliva countable product of selection functions,

<p>for giving a [...]]]></description>
			<content:encoded><![CDATA[<p>As a preparation for my part of a joint tutorial <em>Programs from proofs</em> at <a href="http://129.81.170.14/~mfps/MFPS27/MFPS_XXVII.html">MFPS 27</a> at the end of this month with <a href="http://www.cs.swan.ac.uk/~csulrich/">Ulrich Berger</a>, <a href="http://www.cs.swan.ac.uk/~csmona/">Monika Seisenberger</a>, and <a href="http://www.eecs.qmul.ac.uk/~pbo/">Paulo Oliva</a>, I&#8217;ve developed in <a href="http://wiki.portal.chalmers.se/agda/pmwiki.php">Agda</a> some things we&#8217;ve been doing together.</p>
<p>Using</p>
<ul>
<li> <a href="http://projecteuclid.org/DPubS?service=UI&amp;version=1.0&amp;verb=Display&amp;handle=euclid.jsl/1183745524">Berardi-Bezem-Coquand functional</a><a>, or alternatively,</a></li>
<li><a href="http://journals.cambridge.org/action/displayAbstract?fromPage=online&amp;aid=439279&amp;fulltextType=RA&amp;fileId=S0960129506005093">Berger-Oliva modified bar recursion</a>, or alternatively,</li>
<li><a href="http://journals.cambridge.org/action/displayAbstract?fromPage=online&amp;aid=7423096&amp;fulltextType=RA&amp;fileId=S0960129509990351">Escardo-Oliva countable product of selection functions</a>,</li>
</ul>
<p>for giving a proof term for classical countable choice, we prove the classical infinite pigeonhole principle in Agda: every infinite boolean sequence has a constant infinite subsequence, where the existential quantification is classical (double negated).</p>
<p>As a corollary, we get the finite pigeonhole principle, using Friedman&#8217;s trick to make the existential quantifiers intuitionistic.</p>
<p>This we can run, and it runs fast enough. The point is to illustrate in Agda how we can get witnesses from classical proofs that use countable choice. The finite pigeonhole principle has a simple constructive proof, of course, and hence this is really for illustration only.</p>
<p>The main Agda files are</p>
<ul>
<li><a href="http://www.cs.bham.ac.uk/~mhe/pigeon/html/InfinitePigeon.html">InfinitePigeon</a></li>
<li><a href="http://www.cs.bham.ac.uk/~mhe/pigeon/html/FinitePigeon.html">FinitePigeon</a></li>
<li><a href="http://www.cs.bham.ac.uk/~mhe/pigeon/html/Examples.html">Examples</a></li>
</ul>
<p>These are Agda files converted to html so that you can navigate them by clicking at words to go to their definitions.  A <a href="http://www.cs.bham.ac.uk/~mhe/pigeon/Pigeon.zip">zip file</a> with all Agda files is available. Not much more information is available <a href="http://www.cs.bham.ac.uk/~mhe/pigeon/">here</a>.</p>
<p>The three little modules that implement the Berardi-Bezem-Coquand, Berger-Oliva and Escardo-Oliva functionals disable the termination checker, but no other module does. The type of these functionals in Agda is the <a href="http://portal.acm.org/citation.cfm?id=1876437">J-shift principle</a>, which generalizes the double-negation shift.</p>
]]></content:encoded>
			<wfw:commentRss>http://math.andrej.com/2011/05/10/running-a-classical-proof-with-choice-in-agda/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Dialectica interpertation in Coq</title>
		<link>http://math.andrej.com/2011/01/03/the-dialectica-interpertation-in-coq/</link>
		<comments>http://math.andrej.com/2011/01/03/the-dialectica-interpertation-in-coq/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 00:07:41 +0000</pubDate>
		<dc:creator>Andrej Bauer</dc:creator>
				<category><![CDATA[Constructive math]]></category>
		<category><![CDATA[Logic]]></category>

		<guid isPermaLink="false">http://math.andrej.com/?p=800</guid>
		<description><![CDATA[<p>I think I am getting addicted to Coq, or more generally to doing mathematics, including the proofs, with computers. I spent last week finalizing a formalization of Gödel&#8217;s functional interpretation of logic, also known as the Dialectica interpretation. There does not seem to be one available already, which is a good opportunity for a blog post.</p>
<p>I [...]]]></description>
			<content:encoded><![CDATA[<p>I think I am getting addicted to <a href="http://coq.inria.fr/">Coq</a>, or more generally to doing mathematics, including the proofs, with computers. I spent last week finalizing a formalization of Gödel&#8217;s functional interpretation of logic, also known as the <em>Dialectica</em> interpretation. There does not seem to be one available already, which is a good opportunity for a blog post.</p>
<p><span id="more-800"></span>I would like to think we are not too far from a future in which the standard in mathematical research will be to always publish papers together with computer-verified proofs. In some areas of theoretical computer science, for example in the theory of programming languages, such a future is rapidly becoming the present. Mainstream mathematics is still not there, but once the tools get good enough, computer-assisted theorem proving will spread approximately as fast as TeX did some time ago. Let that be my New Year&#8217;s prediction! In the meanwhile the enthusiasts should explore the possibilities offered by what is currently available.</p>
<p>I always liked the work on <a href="http://en.wikipedia.org/wiki/Proof_mining">proof mining</a>, but I could never quite memorize the details of Gödel&#8217;s Dialectica interpretation, which lies at the basis of proof mining. Doing them in Coq was a good way of learning about the Dialectica interpretation, and I even got some new ideas (but that&#8217;s a topic for another day).</p>
<p>If you are not familiar with the Dialectica interpetation I recommend <a href="http://www.andrew.cmu.edu/user/avigad/">Jeremy Avigad&#8217;s</a> and <a href="http://math.stanford.edu/~feferman/">Solomon Feferman&#8217;s</a> chapter on <em>&#8220;<a href="http://www.andrew.cmu.edu/user/avigad/Papers/dialect.pdf">Gödel&#8217;s functional (&#8220;Dialectica&#8221;) interpretation</a>&#8220;</em> in S. Buss ed., <em>The Handbook of Proof Theory, </em>North-Holland, pages 337-405, 1999.</p>
<p>Since this is not a tutorial I will only say that the main idea is a transformation of each formula $\phi$ to a classically equivalent formula $\phi^D$ of the form $\exists x . \forall u . \phi_D(x,u)$ with $\phi_D$ quantifier-free. The amazing thing is that $\phi^D$ is sometimes constructively valid even though $\phi$ is not, so this is a systematic way of &#8220;constructivizing&#8221; classical mathematics. To see what can be done with it, have a look at <a href="http://www.mathematik.tu-darmstadt.de/~kohlenbach/">Ulrich Kohlenbach</a>&#8216;s <a href="http://www.springer.com/mathematics/book/978-3-540-77532-4">book</a>.</p>
<p>Writing this post forced me to think about how to present a computer-assisted piece of mathematics. Should I just publish the Coq file and be done with it, or should I inline the Coq code? I suppose it is better to do both.</p>
<p><strong>Download:</strong> <a href="http://math.andrej.com/wp-content/uploads/2011/01/dialectica.v">dialectica.v</a></p>
<p>The following is essentially the same as the above file. </p>
<h3>Basic definitions</h3>
<p>We present Goedel&#8217;s &#8220;Dialectica&#8221; functional interpretation of logic, slightly generalized and adapted for Coq. </p>
<p>Needed for decidable equality on natural numbers but otherwise we could do without <code>Arith</code>.</p>
<pre class="brush: plain; gutter: false; title: ;">
Require Import Arith.
Require Import Bool.
</pre>
<p>The following line is specific to Coq 8.3, but Coq 8.2 does not seem to be bothered by it, so luckily this file is compatible with both versions.</p>
<pre class="brush: plain; gutter: false; title: ;">
Unset Automatic Introduction.
Set Implicit Arguments.
</pre>
<p>We shall allow universal and existential quantification over arbitrary inhabited types. The usual interpretation allows quantification over the natural numbers (and possibly functionals over the natural numbers), which are of course inhabited.</p>
<pre class="brush: plain; gutter: false; title: ;">
Record Inhabited := inhabit { ty :&gt; Set; member : ty }.
</pre>
<p>The inhabited natural numbers:</p>
<pre class="brush: plain; gutter: false; title: ;">
Definition N := inhabit 0.
</pre>
<p>The inductive type <code>prp</code> is a kind of &#8220;deep embedding&#8221; of the abstract syntax of the object language that we shall interpret into Coq. We admit only decidable primitive predicates, as is usual in the basic Dialectica variant. (Note: The original version of this post claimed we used <a href="http://en.wikipedia.org/wiki/Higher-order_abstract_syntax">higher-order abstract syntax</a> (HOAS). Thanks to Bob Harper for pointing out that in fact we didn&#8217;t.)</p>
<pre class="brush: plain; gutter: false; title: ;">
Inductive prp : Type :=
  | primitive : bool -&gt; prp
  | conjunction : prp -&gt; prp -&gt; prp
  | disjunction : prp -&gt; prp -&gt; prp
  | implication : prp -&gt; prp -&gt; prp
  | negation : prp -&gt; prp
  | universal : forall (ty : Inhabited), (ty -&gt; prp) -&gt; prp
  | existential : forall (ty : Inhabited), (ty -&gt; prp) -&gt; prp.
</pre>
<p>Our representation of syntax allows us to express &#8220;exotic&#8221; propositional functions <code>p : ty -> prp</code> in which the logical structure of <code>p x</code> may depend on <code>x</code>. Because of this phenomenon we will be forced later on to introduce certain type dependencies where there are none in the usual Dialectica interpretation.</p>
<p>Convenient notation for the object language.</p>
<pre class="brush: plain; gutter: false; title: ;">
Notation &quot;'[' p ']'&quot; := (primitive p) (at level 80, no associativity).
Notation &quot;'neg' x&quot; := (negation x) (at level 70, no associativity).
Notation &quot;x 'and' y&quot; := (conjunction x y) (at level 74, left associativity).
Notation &quot;x 'or' y&quot; := (disjunction x y) (at level 76, left associativity).
Notation &quot;x ==&gt; y&quot; := (implication x y) (at level 78, right associativity).
Notation &quot;'all' x : t , p&quot; :=  (@universal t (fun x =&gt; p)) (at level 80, x at level 99).
Notation &quot;'some' x : t , p&quot; :=  (@existential t (fun x =&gt; p)) (at level 80, x at level 99).
</pre>
<p>With each proposition <code>p</code> we associate the types <code>W p</code> and <code>C p</code> of &#8220;witnesses&#8221; and &#8220;counters&#8221;, respectively. Think of them as moves in a game between a player <code>W</code> and an opponent <code>C</code>. We make two changes to the standard Dialectica representation:</p>
<ol>
<li>First, we use sum for counters of conjunctions, where normally a product is used. This gives us symmetry between conjunction and disjunction, simplifies the notorious conjunction contraction <code>and_contr</code>, but complicates the adjunction between implication and conjunction. Thomas Streicher pointed out that the change is inessential in the sense that we could prove a separate lemma which allows us to pass from counters for <code>p and q</code> as pairs to counters as elements of a sum (such a lemma relies in decidability of the <code>dia</code> relation defined below).</li>
<li>Second, because the structure of a propositional function is allowed to depend on its argument, we are forced to introduce type dependency into <code>W p</code> and <code>C p</code> when <code>p</code> is a quantified statement. This is not a big surprise, but what is a little more surprising is that the counters for existentials, <code>C (existential ty p')</code>, involve a dependency not only on <code>ty</code> but also on <code>W (p' x)</code>. The dependency is needed in the rule <code>exists_elim</code>. The rest of Dialectica interpetation is not influenced by this change, with the exception of the Independence of Premise where we have to impose a condition that is not required in the usual interpretation.
<p>These type-dependecies clearly points towards an even more type-dependent Dialectica variant. Indeed, we are going to investigate it in a separate file. For now we are just trying to faithfully represent the Dialectica interpretation.</li>
</ol>
<pre class="brush: plain; gutter: false; title: ;">
Fixpoint W (p : prp) :=
  (match p with
     | primitive p =&gt; unit
     | conjunction p1 p2 =&gt; (W p1) * (W p2)
     | disjunction p1 p2 =&gt; (W p1) + (W p2)
     | implication p1 p2 =&gt; (W p1 -&gt; W p2) * (W p1 * C p2 -&gt; C p1)
     | negation p' =&gt; (W p' -&gt; C p')
     | universal ty p' =&gt; (forall x : ty, W (p' x))
     | existential ty p' =&gt; { x : ty &amp; W (p' x) }
   end)%type

with C p : Set :=
  (match p with
     | primitive p =&gt; unit
     | conjunction p1 p2 =&gt; (C p1) + (C p2)
     | disjunction p1 p2 =&gt; (C p1) * (C p2)
     | implication p1 p2 =&gt; (W p1) * (C p2)
     | negation p' =&gt; W p'
     | universal ty p' =&gt; { x : ty &amp; C (p' x) }
     | existential ty p' =&gt; (forall x : ty, W (p' x) -&gt; C (p' x))
   end)%type.
</pre>
<p>The relation <code>dia p w c</code> is what is usually written as $p_D(w,c)$ in the Dialectica interpretation, i.e., the matrix of the interpreted formula.</p>
<p>In terms of games, <code>dia p w c</code> tells whether the player move <code>w</code> wins against the opponent move <code>c</code> in the game determined by the proposition <code>p</code>.</p>
<pre class="brush: plain; gutter: false; title: ;">
Fixpoint dia (p : prp) : W p -&gt; C p -&gt; Prop :=
  match p return W p -&gt; C p -&gt; Prop with
    | primitive p =&gt; (fun _ _ =&gt; Is_true p)
    | conjunction p1 p2 =&gt;
      (fun a b =&gt; match b with
                    | inl b1 =&gt; dia p1 (fst a) b1
                    | inr b2 =&gt; dia p2 (snd a) b2
                  end)
    | disjunction p1 p2 =&gt;
        (fun a b =&gt; match a with
                      | inl x =&gt; dia p1 x (fst b)
                      | inr u =&gt; dia p2 u (snd b)
                    end)
    | implication p1 p2 =&gt;
        (fun a b =&gt; dia p1 (fst b) (snd a b) -&gt; dia p2 (fst a (fst b)) (snd b))
    | negation p' =&gt;
        (fun a b =&gt; ~ dia p' b (a b))
    | universal t p' =&gt;
        (fun a b =&gt; dia (p' (projT1 b)) (a (projT1 b)) (projT2 b))
    | existential t p' =&gt;
        (fun a b =&gt; dia (p' (projT1 a)) (projT2 a) (b (projT1 a) (projT2 a)))
  end.
</pre>
<p>The <code>dia</code> relation is decidable. This fact is used only in the adjunction between conjunction and implication.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem dia_decidable (p : prp) (a : W p) (b : C p) : {dia p a b} + {not (dia p a b)}.
Proof.
  intros p a b.
  induction p.

  unfold dia, Is_true.
  induction p; tauto.

  unfold W in a; simpl in a; fold W in a.
  destruct a as [a1 a2].
  unfold C in b; simpl in b; fold C in b.
  destruct b as [b1|b2]; simpl.
  apply IHp1.
  apply IHp2.

  destruct b as [b1 b2].
  destruct a as [a1 | a2]; [apply IHp1 | apply IHp2].

  destruct a as [f g].
  destruct b as [x v].
  assert (I := IHp1 x (g (x,v))).
  assert (J := IHp2 (f x) v).
  unfold dia; fold dia.
  tauto.

  unfold dia; fold dia.
  destruct (IHp b (a b)).
  right.
  intro; contradiction.
  left; auto.

  unfold dia; fold dia.
  apply H.

  unfold dia; fold dia.
  apply H.
Qed.
</pre>
<p>Of course, a decidable proposition is stable for double negation.</p>
<pre class="brush: plain; gutter: false; title: ;">
Lemma dia_not_not_stable (p : prp) (w : W p) (c : C p) : ~ ~ dia p w c -&gt; dia p w c.
Proof.
  intros p w c H.
  destruct (dia_decidable p w c); tauto.
Qed.
</pre>
<p>The types <code>W</code> and <code>C</code> are always inhabited because we restrict quantifiers to inhabited types.</p>
<pre class="brush: plain; gutter: false; title: ;">
Definition WC_member (p : prp) : W p * C p.
  induction p; unfold W; unfold C; simpl; fold W; fold C; split; try firstorder.
  exact (member ty0).
  exact (member ty0).
Defined.

Definition W_member (p : prp) := fst (WC_member p).
Definition C_member (p : prp) := snd (WC_member p).
</pre>
<p>The predicate <code>valid p</code> is the Dialectica interpretation of <code>p</code>. It says that there is <code>w</code> such that <code>dia p w c</code> holds for any <code>c</code>. In terms of games semantics this means that <code>W</code> has a winning strategy (which amounts to a winning move <code>w</code>).</p>
<pre class="brush: plain; gutter: false; title: ;">
Definition valid (p : prp) := { a : W p | forall b : C p, dia p a b }.
</pre>
<h3>Validity of inference rules</h3>
<p>We now verify that the Hilbert-style axioms for first-order logic are validated by our interpretation. We follow Avigad &#038; Feferman.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem modus_ponens (p q : prp) : valid p -&gt; valid (p ==&gt; q) -&gt; valid q.
Proof.
  unfold valid,  W, C; simpl; fold W; fold C; simpl.
  intros p q [wp H] [[u v] G].
  simpl in G.
  exists (u wp).
  intro b.
  apply (G (wp, b)); simpl.
  apply H.
Qed.

Theorem impl_chain (p q r : prp) : valid (p ==&gt; q) -&gt; valid (q ==&gt; r) -&gt; valid (p ==&gt; r).
Proof.
  unfold valid,  W, C; simpl; fold W; fold C; simpl.
  intros p q r [[a b] H] [[c d] G].
  exists (fun w =&gt; c (a w), fun v =&gt; b (fst v, d (a (fst v), snd v))).
  simpl in H.
  simpl in G.
  simpl.
  intros g I.
  apply (G (a (fst g), snd g)); simpl.
  apply (H (fst g, d (a (fst g), snd g))); simpl.
  assumption.
Qed.

Theorem or_contr (p : prp) : valid (p or p ==&gt; p).
Proof.
  intros p.
  unfold valid, C, W; simpl; fold C; fold W.
  exists (fun x =&gt; (match x with inl a =&gt; a | inr a =&gt; a end), fun x =&gt; (snd x, snd x)); simpl.
  intros [u v]; simpl.
  destruct u; auto.
Qed.
</pre>
<p>In the following theorem we avoid decidability of <code>dia</code> because we defined counters of conjunctions as sums.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem and_contr (p : prp) : valid (p ==&gt; p and p).
Proof.
  intros p.
  unfold valid, C, W; simpl; fold C; fold W.
  exists (fun x =&gt; (x,x),
          fun y =&gt; match snd y with
                     | inl c =&gt; c
                     | inr c =&gt; c
                   end); simpl.
  intros [u [v1|v2]] H; auto.
Qed.

Theorem or_introl (p q : prp) : valid (p ==&gt; p or q).
Proof.
  intros p q.
  unfold valid, C, W; simpl; fold C; fold W.
  exists (fun x =&gt; @inl _ _ x, fun y =&gt; fst (snd y)).
  auto.
Qed.

Theorem and_eliml (p q : prp) : valid (p and q ==&gt; p).
Proof.
  intros p q.
  unfold valid, C, W; simpl; fold C; fold W.
  exists (@fst _ _, fun y =&gt; @inl _ _ (snd y)).
  tauto.
Qed.

Theorem or_comm (p q : prp) : valid (p or q ==&gt; q or p).
Proof.
  intros p q.
  unfold valid, C, W; simpl; fold C; fold W.
  exists (fun x =&gt; match x with inl a =&gt; @inr _ _ a | inr b =&gt; @inl _ _ b end,
          fun y =&gt; (snd (snd y), fst (snd y))); simpl.
  intros [u [v w]]; simpl.
  destruct u; auto.
Qed.

Theorem and_comm (p q : prp) : valid (p and q ==&gt; q and p).
Proof.
  intros p q.
  unfold valid, C, W; simpl; fold C; fold W.
  exists (fun x =&gt; (snd x, fst x),
          fun y =&gt; match snd y with
                     | inl c =&gt; @inr _ _ c
                     | inr c =&gt; @inl _ _ c
                   end).
  intros [[a1 a2] [b1|b2]]; auto.
Qed.

Theorem or_distr (p q r : prp) : valid (p ==&gt; q) -&gt; valid (r or p ==&gt; r or q).
Proof.
  intros p q r.
  unfold valid, C, W; simpl; fold C; fold W.
  intros [[a b] H].
  simpl in H.
  exists (fun x =&gt; match x with inl t =&gt; @inl _ _ t | inr u =&gt; @inr _ _ (a u) end,
          fun y =&gt; match fst y with
                     | inl i =&gt; (fst (snd y), b (W_member p, snd (snd y)))
                     | inr j =&gt; (fst (snd y), b (j, snd (snd y)))
                   end).
  intros [c [d e]]; simpl.
  destruct c; auto.
  intro G.
  apply (H (w, e)); simpl.
  apply G.
Qed.
</pre>
<p>The next two theorems verify the adjunction between conjunction and implication. This is where we need decidability of <code>dia p w c</code> and inhabitation of <code>W</code> and <code>C</code>.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem impl_conj_adjunct1 (p q r : prp) : valid (p ==&gt; (q ==&gt; r)) -&gt; valid (p and q ==&gt; r).
Proof.
  intros p q r.
  unfold valid, C, W; simpl; fold C; fold W.
  intros [[a b] H].
  simpl in H.
  eexists (fun x =&gt; fst (a (fst x)) (snd x),
          fun (y : W p * W q * C r) =&gt;
            let (wp, wq) := fst y in
            let cr := snd y in
            if dia_decidable q wq (snd (a wp) (wq, cr))
            then @inl _ _ (b (wp, (wq, cr)))
            else @inr _ _ (snd (a wp) (wq, cr))).
  simpl.
  intros [[c d] e].
  simpl.
  destruct (dia_decidable q d (snd (a c) (d,e))) as [D1 | D2].
  intro G.
  apply (H (c, (d, e))); auto.
  intro G.
  contradiction.
Qed.

Theorem impl_conj_adjunct2 (p q r : prp) : valid (p and q ==&gt; r) -&gt; valid (p ==&gt; (q ==&gt; r)).
Proof.
  intros p q r.
  unfold valid, C, W; simpl; fold C; fold W.
  intros [[a b] H]; simpl in H.
  exists (fun x =&gt; (fun u =&gt; a (x, u), fun v =&gt; match b ((x, fst v), snd v) with
                                                  | inl c =&gt; C_member q
                                                  | inr d =&gt; d
                                                end),
          fun y =&gt; match b ((fst y, fst (snd y)), snd (snd y)) with
                     | inl c =&gt; c
                     | inr d =&gt; C_member p
                   end).
  simpl.
  intros [u [v w]]; simpl.
  intros F G.
  apply (H (u, v, w)).
  destruct (b (u, v, w)); auto.
Qed.

Theorem false_elim (p : prp) : valid ([false] ==&gt; p).
Proof.
  intros p.
  unfold valid, C, W; simpl; fold C; fold W.
  exists ((fun _ =&gt; W_member p), (fun _ =&gt; tt)).
  intros [u v] G.
  contradiction.
Qed.

Theorem forall_intro (ty : Inhabited) (p : prp) (q : ty -&gt; prp) :
  (forall x : ty, valid (p  ==&gt; q x)) -&gt; valid (p ==&gt; all x : ty, q x).
Proof.
  intros t p q.
  unfold valid, C, W; simpl; fold C; fold W.
  intros H.
  exists ((fun u x =&gt; fst (projT1 (H x)) u),
          (fun (y : (W p * {x : t &amp; C (q x)})) =&gt;
           snd (projT1 (H (projT1 (snd y)))) (fst y, projT2 (snd y)))).
  intros [u [x v]].
  simpl.
  intros G.
  apply (projT2 (H x) (u, v)).
  auto.
Qed.

Theorem forall_elim (ty : Inhabited) (a : ty) (p : ty -&gt; prp) :
  valid ((all x : ty, p x) ==&gt; p a).
Proof.
  intros t a p.
  unfold valid, C, W; simpl; fold C; fold W.
  exists ((fun f =&gt; f a), (fun y =&gt; existT _ a (snd y))); auto.
Qed.

Theorem exists_intro (ty : Inhabited) (a : ty) (p : ty -&gt; prp) :
  valid (p a ==&gt; some x : ty, p x).
Proof.
  intros t a p.
  unfold valid, C, W; simpl; fold C; fold W.
  exists ((fun x =&gt; existT _ a x),
          (fun y =&gt; snd y a (fst y))); auto.
Qed.
</pre>
<p>This is the rule in which we need the dependency of counters in existential statements.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem exists_elim (ty : Inhabited) (p : ty -&gt; prp) (q : prp) :
  (forall x : ty, valid (p x ==&gt; q)) -&gt; valid ((some x : ty, p x) ==&gt; q).
Proof.
  intros t p q.
  unfold valid, C, W; simpl; fold C; fold W.
  intros H.
  exists ((fun (u : {x : t &amp; W (p x)}) =&gt; fst (projT1 (H (projT1 u))) (projT2 u)),
          (fun v x w =&gt; snd (projT1 (H x)) (w, snd v))).
  simpl.
  intros [[x u] v]; simpl.
  intro G.
  apply (projT2 (H x) (u, v)).
  simpl.
  apply G.
Qed.
</pre>
<h3>Equality</h3>
<p>Next we verify the rules of equality. To keep things simple we only consider equality of natural numbers. In the general case we could consider decidable equality on an inhabited type.</p>
<pre class="brush: plain; gutter: false; title: ;">
Definition prpEq (m n : N) := [beq_nat m n].
</pre>
<p>Dialectica equality implies equality.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem prpEq_eq (m n : N) : valid (prpEq m n) -&gt; m = n.
Proof.
  unfold prpEq, valid; simpl; fold valid.
  intros m n [_ H].
  assert (G := H tt).
  apply beq_nat_true.
  apply Is_true_eq_true.
  assumption.
Qed.
</pre>
<p>Equality implies Dialectica equality, of course, but notice how complicated the proofs seems to be. We could move the complication into <code>prpEq_refl</code> below.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem eq_prpEq (m n : N) : m = n -&gt; valid (prpEq m n).
Proof.
  intros m n E.
  rewrite E.
  exists tt.
  intro b.
  unfold dia; simpl; fold dia.
  apply Is_true_eq_right.
  apply (beq_nat_refl n).
Qed.
</pre>
<p>Reflexivity.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem prpEq_refl (n : N) : valid (prpEq n n).
Proof.
  intros n.
  apply eq_prpEq.
  reflexivity.
Qed.
</pre>
<p>Leibniz&#8217;s law as a rule of inference.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem leibniz_rule (p : N -&gt; prp) (m n : N) :
  valid (prpEq m n) -&gt; valid (p m) -&gt; valid (p n).
Proof.
  unfold valid, C, W; simpl; fold C; fold W.
  intros p m n [a H] [b G].
  assert (E := H tt).
  apply Is_true_eq_true in E.
  apply beq_nat_true in E.
  rewrite &lt;- E.
  exists b.
  assumption.
Qed.
</pre>
<p>Proving Leibniz&#8217;s law as a proposition is more complicated because of type dependency that is not present in the usual Dialectica interpretation.</p>
<p>In fact, it looks like we need UIP (Uniqueness of Identity Proofs) for natural numbers, which luckily holds since the natural numbers are decidable. Below we prove UIP for N. Coq 8.3 contains a more general proof of UIP for decidable types, see <a href="http://coq.inria.fr/stdlib/Coq.Logic.Eqdep.html"><code>Logic.Eqdep_dec</code></a>.</p>
<pre class="brush: plain; gutter: false; title: ;">
Definition eqN_compose (k m n : N) (p : k = m) (q : k = n) : m = n.
Proof.
  intros k m n p q.
  induction p.
  exact q.
Defined.

Lemma eqN_compose_transitivity (m n : N) (p : m = n) : eqN_compose p p = refl_equal n.
Proof.
  intros m n p.
  case p; trivial.
Qed.

Lemma eqN_decidable (m n : N) : {m = n} + {m &lt;&gt; n}.
Proof.
  induction m; induction n; auto.
  destruct (IHm n) as [E1 | E2].
  rewrite E1.
  left.
  reflexivity.
  right.
  injection.
  contradiction.
Qed.

Definition eqN_nu (m n : N) (p : m = n) : (m = n).
Proof.
  intros m n p.
  destruct (eqN_decidable m n) as [EQ|NEQ].
  exact EQ.
  contradiction.
Defined.

Definition eqN_mu (m n : N) (p : m = n) := eqN_compose (eqN_nu (refl_equal m)) p.

Lemma eqN_mu_nu (n m : N) (p : n = m) : eqN_mu (eqN_nu p) = p.
Proof.
  intros n m p.
  case p.
  unfold eqN_mu.
  apply eqN_compose_transitivity.
Qed.

Theorem UIP_N : forall (m n : N) (p q : m = n), p = q.
Proof.
  intros m n p q.
  elim eqN_mu_nu with (p := p).
  elim eqN_mu_nu with (p := q).
  unfold eqN_nu.
  destruct (eqN_decidable m n) as [EQ|NEQ].
  reflexivity.
  contradiction.
Qed.

Definition W_transfer (p : N -&gt; prp) (m n : N) : W (p m) -&gt; W (p n).
Proof.
  intros p m n w.
  destruct (eqN_decidable m n) as [E1 | E2].
  rewrite &lt;- E1.
  exact w.
  exact (W_member ((p n))).
Defined.

Definition C_transfer (p : N -&gt; prp) (m n : N) : C (p m) -&gt; C (p n).
Proof.
  intros p m n c.
  destruct (eqN_decidable m n) as [E1 | E2].
  rewrite &lt;- E1.
  exact c.
  exact (C_member ((p n))).
Defined.
</pre>
<p>Finally, the validity of Leibniz&#8217;s law is proved. If someone knows a shortcut, I would like to know about it.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem leibniz (p : N -&gt; prp) (m n : N) : valid (prpEq m n ==&gt; p m ==&gt; p n).
Proof.
  intros p m n.
  unfold valid, C, W; simpl; fold C; fold W.
  exists ((fun tt =&gt; ((fun (w : W (p m)) =&gt; W_transfer p m n w),
                      (fun y =&gt; C_transfer p n m (snd y)))),
          (fun _ =&gt; tt)).
  intros [u [w c]].
  simpl.
  intros E.
  apply Is_true_eq_true in E.
  apply beq_nat_true in E.
  destruct E.
  unfold C_transfer, W_transfer.
  destruct (eqN_decidable m m) as [E1 | E2].
  assert (U := UIP_N E1 (refl_equal m)).
  rewrite U.
  simpl.
  auto.
  assert (F2 : m = m); auto.
  contradiction.
Qed.
</pre>
<h3>Natural numbers</h3>
<p>Next we verify that the natural numbers obey Peano axioms. They are easy, except for induction which has two parts: the usual &#8220;forward&#8221; direction by primitive recursion, and a &#8220;backwards&#8221; direction in which we search for a counter-example, starting from an upper bound and going down to 0.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem nat_zero_not_succ (n : nat) :
  valid (neg (prpEq (S n) 0)).
Proof.
  intro n.
  unfold valid, C, W; simpl; fold C; fold W.
  exists (fun tt =&gt; tt); auto.
Qed.

Theorem succ_injective (m n : nat) :
  valid (prpEq (S m) (S n) ==&gt; prpEq m n).
Proof.
  intros m n.
  unfold valid, C, W; simpl; fold C; fold W.
  exists (fun _ =&gt; tt, fun _ =&gt; tt); auto.
Qed.
</pre>
<p>Given a propositional function <code>p : nat -> prp</code>, suppose <code>p m</code> is not valid. Then <code>p 0</code> is not valid, or one of induction steps <code>p k ==> p (S k)</code> fails. The &#8220;backwards&#8221; direction of the Dialectica interpretation of induction is a search functional which looks for a failed base case or failed induction step. We construct it separately from the main proof.</p>
<pre class="brush: plain; gutter: false; title: ;">
Definition search (p : N -&gt; prp) (m : N) :
  W (p 0) -&gt;
  (forall k : N, W (p k) -&gt; W (p (S k))) -&gt;
  (forall k : N, W (p k) * C (p (S k)) -&gt; C (p k)) -&gt;
  C (p m) -&gt;
  C (p 0) + {n : N &amp; (W (p n) * C (p (S n)))%type}.
Proof.
  intros p m z s b c.
  induction m.
  left; exact c.
  pose (w := nat_rect _ z s m).
  destruct (dia_decidable (p m) w (b m (w, c))) as [D1|D2].
  right.
  exists m.
  exact (w, c).
  apply IHm.
  exact (b m (w, c)).
Defined.
</pre>
<p>Finally we verify validity of induction.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem N_induction (p : nat -&gt; prp) (m : nat) :
  valid (p 0 and (all n : N, p n ==&gt; p (S n)) ==&gt; p m).
Proof.
  intros p m.
  unfold valid, C, W; simpl; fold C; fold W.
  exists (fun x =&gt; nat_rect _ (fst x) (fun k =&gt; fst (snd x k)) m,
          fun y =&gt; search p m (fst (fst y))
                     (fun k =&gt; fst (snd (fst y) k))
                     (fun k =&gt; snd (snd (fst y) k))
                     (snd y)).
  simpl.
  intros [[z h] c]; simpl.
  set (s := fun k : nat =&gt; fst (h k)).
  set (b := fun k : nat =&gt; snd (h k)).
  induction m; auto.
  unfold search; simpl.
  set (w := nat_rect (fun k : nat =&gt; W (p k)) z s m).
  destruct (dia_decidable (p m) w (b m (w, c))) as [D1|D2]; simpl.
  intro H.
  apply H.
  apply D1.
  intros.
  assert (G:= IHm (b m (w, c))).
  fold w in G.
  elim D2.
  apply G.
  apply H.
Qed.
</pre>
<p>Having done ordinary induction one is tempted to try validating induction for W-types&#8230; but not here.</p>
<h3>Markov Principle and Independence of Premise</h3>
<p>The Dialectica interpretation is characterized by two non-intuitionistic reasoning principles, namely <a href="http://en.wikipedia.org/wiki/Markov%27s_principle">Markov principle</a> (MP) and <a href="http://en.wikipedia.org/wiki/Independence_of_premise">Independence of Premise</a> (IP).</p>
<p>Both MP and IP involve primitive propositional function <code>N -> bool</code>. The point of these is that their <code>W</code> and <code>C</code> types are the unit. So instead of actually using primitive proposition, we shall use arbitrary propositions whose <code>W</code> and <code>C</code> types are singletons. First we make the relevant definitions.</p>
<pre class="brush: plain; gutter: false; title: ;">
Definition singleton (t : Inhabited) := forall x, x = member t.

Definition trivial_C (p : prp) := singleton (inhabit (C_member p)).
Definition trivial_W (p : prp) := singleton (inhabit (W_member p)).
</pre>
<p>Primitive propositions are trivial, of course.</p>
<pre class="brush: plain; gutter: false; title: ;">
Lemma primitive_trivial_W (b : bool) : trivial_W ([b]).
Proof.
  intros b w.
  case w; auto.
Qed.

Lemma primitive_trivial_C (b : bool) : trivial_C ([b]).
Proof.
  intros b c.
  case c; auto.
Qed.
</pre>
<p>Whether there are trivial propositions, other than the primitive ones, depends on what extra axioms we have available. For example, in the presence of extensionality of functions, implications and negations of trivial propositions are trivial. We do not dwell on the exact conditions that give us trivial propositions, but only demonstrate how to use extensionality of functions whose codomain is a singleton set to derive triviality of implication of trivial propositions.</p>
<p>Is there a better way of getting the next lemma?</p>
<pre class="brush: plain; gutter: false; title: ;">
Lemma pair_equal (X Y : Set) (p q : X * Y) :
  fst p = fst q -&gt; snd p = snd q -&gt; p = q.
Proof.
  intros X Y p q G H.
  induction p; induction q.
  simpl in G; simpl in H.
  rewrite G; rewrite H.
  reflexivity.
Qed.
</pre>
<p>We are only interested in extensionality of functions <code>s -> t</code> for which <code>t</code> is a singleton. Such extensionality can be phrased as &#8220;any power of a singleton is a singleton&#8221;.</p>
<pre class="brush: plain; gutter: false; title: ;">
Definition singleton_power :=
  forall t, singleton t -&gt; forall s : Set, singleton (inhabit (fun _ : s =&gt; member t)).
</pre>
<p>I <em>think</em> there is no way of proving <code>singleton_power</code>, is there? We can use it to show that <code>W (p ==> q)</code> is trivial if <code>C p</code> and <code>W q</code> are trivial.</p>
<pre class="brush: plain; gutter: false; title: ;">
Lemma implication_trivial_W (p q : prp) :
  singleton_power -&gt; trivial_C p -&gt; trivial_W q -&gt; trivial_W (p ==&gt; q).
Proof.
  intros p q E TCp TWq.
  unfold trivial_W.
  unfold singleton.
  unfold W_member, C_member; simpl; fold W_member; fold C_member.
  intros [f g].
  apply pair_equal; simpl.
  rewrite (E _ TWq _).
  rewrite (E _ TWq _ f).
  reflexivity.
  rewrite (E _ TCp _).
  rewrite (E _ TCp _ g).
  reflexivity.
Qed.
</pre>
<p>Triviality of <code>C (p ==> q)</code> does not require any extra assumptions.</p>
<pre class="brush: plain; gutter: false; title: ;">
Lemma implication_trivial_C (p q : prp) :
  trivial_W p -&gt; trivial_C q -&gt; trivial_C (p ==&gt; q).
Proof.
  intros p q TWp TCq.
  unfold trivial_C.
  unfold C, W; simpl; fold C; fold W.
  intros [wp cq].
  rewrite (TWp wp).
  rewrite (TCq cq).
  apply pair_equal; auto.
Qed.
</pre>
<h4>Markov principle</h4>
<p>Markov principle holds for any inhabited type (not just the natural numbers) and a proposition which has trivial <code>W</code> and <code>C</code> types.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem markov_generalized (t : Inhabited) (p : t -&gt; prp) :
  (forall x, trivial_C (p x)) -&gt;
  (forall x, trivial_W (p x)) -&gt;
  valid (neg (all x : t, neg (p x)) ==&gt; some x : t, p x).
Proof.
  intros t p TC TW.
  unfold valid, C, W; simpl; fold C; fold W.
  pose (u := fun (h : _ -&gt; {x : t &amp; W (p x)})  =&gt;
    let y := projT1 (h (fun x (_ : W (p x)) =&gt; C_member (p x))) in
      existT (fun x : t =&gt; W (p x)) y (W_member (p y))).
  exists (u, fun _ x _ =&gt; C_member (p x)); simpl.
  intros [f g].
  simpl.
  set (v := projT1 (f (fun x _ =&gt; C_member (p x)))).
  set (w := projT2 (f (fun (x : t) (_ : W (p x)) =&gt; C_member (p x)))).
  rewrite (TC v (g v (W_member (p v)))).
  rewrite (TW v w).
  apply dia_not_not_stable.
Qed.
</pre>
<p>The usual Markov principle now follows easily.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem markov (p : N -&gt; bool) :
  valid (neg (all n : N, neg [p n]) ==&gt; some n : N, [p n]).
Proof.
  intro p.
  apply markov_generalized with (t := N) (p := fun (n : N) =&gt; [p n]).
  intro; apply primitive_trivial_C.
  intro; apply primitive_trivial_W.
Qed.
</pre>
<h4>The Independence of Premise</h4>
<p>The usual IP relates a <em>decidable</em> propositional function $p$ and an <em>arbitrary</em> one $q$:</p>
<blockquote><p>$((\forall x . p(x)) \Rightarrow \exists y . q(y)) \Rightarrow \exists y . (\forall x . p(x)) \Rightarrow q(y)$</p></blockquote>
<p>It is possible to generalize the primitive $p$ to <code>p : s -> prp</code> with trival <code>W (p x)</code>. On the other hand, the type-dependencies force us to require that <code>C (q y)</code> be trivial. The proof below is unnecessarily complicated towards the end because I hit against <a href="http://coq.inria.fr/bugs/show_bug.cgi?id=2061">a bug in <code>rewrite</code></a>.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem ip_generalized (s t : Inhabited) (p : s -&gt; prp) (q : t -&gt; prp) :
  (forall (x : s), trivial_W (p x)) -&gt;
  (forall (y : t), trivial_C (q y)) -&gt;
  valid (((all x : s, p x) ==&gt; some y : t, q y) ==&gt; some y : t, (all x : s, p x) ==&gt; q y).
Proof.
  intros s t p q TW TC.
  unfold valid, C, W; simpl; fold C; fold W.
  pose (u := fun (x : s) =&gt; W_member (p x)).
  pose (v := fun (y : t) (w : W (q y)) =&gt; C_member (q y)).
  refine (existT _
          ((fun a =&gt; existT _ (projT1 (fst a u)) (fun _ =&gt; projT2 (fst a u),
                                                 (fun b =&gt; snd a (u, v)))),
           (fun _ =&gt; (u,v)))
          _).
  simpl.
  intros [[f g] h].
  simpl.
  set (y := projT1 (f u)).
  set (z := projT1 (g (u, v))).
  intros G.
  fold v.
  intro H.
  rewrite (TC y); simpl.
  rewrite (TC y (v y (projT2 (f u)))) in G; simpl in G.
  apply G.
  replace (u z) with (fst (h y (fun _ : forall x : s, W (p x) =&gt; projT2 (f u),
                                fun _ : (forall x : s, W (p x)) * C (q y) =&gt; g (u, v))) z).
  assumption.
  transitivity (member (inhabit (W_member (p z)))); apply (TW z).
Qed.
</pre>
<p>A special case of our IP occurs when <code>p</code> is a primitive propositional function.</p>
<pre class="brush: plain; gutter: false; title: ;">
Theorem ip (s t : Inhabited) (p : s -&gt; bool) (q : t -&gt; prp) :
  (forall (y : t), trivial_C (q y)) -&gt;
  valid (((all x : s, [p x]) ==&gt; some y : t, q y) ==&gt; some y : t, (all x : s, [p x]) ==&gt; q y).
Proof.
  intros s t p q TC.
  apply ip_generalized.
  intro; apply primitive_trivial_W.
  intro; apply TC.
Qed.
</pre>
<p>This concludes the verification of the Dialectica interpretation in Coq. There are at least three interesting directions to go:</p>
<ol>
<li>Extract programs from the Dialectica interpretation. It looks like this could be done for extraction into Scheme. Extraction into Haskell and Ocaml seem more complicated because the <code>W</code> and <code>C</code> types are dependent and there seems no easy way of translating them into a simply-typed programming language. Presumably, concrete examples could be extracted with the help of &#8220;<code>Extraction Inline W C.</code>&#8220;.</li>
<li>Explore other variants, such as the Diller-Nahm interpretation, or perhaps the interpretations a la <a href="http://www.mathematik.tu-darmstadt.de/~kohlenbach/">Ulrich Kohlenbach</a> and <a href="http://www.eecs.qmul.ac.uk/~pbo/">Paulo Oliva</a>.</li>
<li>Explore the possibility of having a fully dependent Dialectica interpretation. Initial investigations by <a href="http://www.mathematik.tu-darmstadt.de/~streicher/">Thomas Streicher</a> and myself indicate that it can be done. This could give us a way of constructing a two-level type system that validates MP and IP.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://math.andrej.com/2011/01/03/the-dialectica-interpertation-in-coq/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Proof of negation and proof by contradiction</title>
		<link>http://math.andrej.com/2010/03/29/proof-of-negation-and-proof-by-contradiction/</link>
		<comments>http://math.andrej.com/2010/03/29/proof-of-negation-and-proof-by-contradiction/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 15:00:04 +0000</pubDate>
		<dc:creator>Andrej Bauer</dc:creator>
				<category><![CDATA[Logic]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://math.andrej.com/?p=453</guid>
		<description><![CDATA[<p>I am discovering that mathematicians cannot tell the difference between &#8220;proof by contradiction&#8221; and &#8220;proof of negation&#8221;. This is so for good reasons, but conflation of different kinds of proofs is bad mental hygiene which leads to bad teaching practice and confusion. For reference, here is a short explanation of the difference between proof of negation [...]]]></description>
			<content:encoded><![CDATA[<p>I am discovering that mathematicians cannot tell the difference between &#8220;proof by contradiction&#8221; and &#8220;proof of negation&#8221;. This is so for good reasons, but conflation of different kinds of proofs is bad mental hygiene which leads to bad teaching practice and confusion. For reference, here is a short explanation of the difference between proof of negation and proof by contradiction.<span id="more-453"></span></p>
<p>By the way, this post is something I have been meaning to write for a while. It was finally prompted by Timothy Gowers&#8217;s blog post <a href="http://gowers.wordpress.com/2010/03/28/when-is-proof-by-contradiction-necessary/">&#8220;When is proof by contradiction necessary?</a>&#8221; in which everything seems to be called &#8220;proof by contradiction&#8221;.</p>
<p>As far as I can tell, &#8220;proof by contradiction&#8221; among ordinary mathematicians means any proof which starts with &#8220;Suppose &#8230;&#8221; and ends with a contradiction. But two kinds of proofs are like that:</p>
<p><strong>Proof of negation</strong> is an inference rule which explains how to prove a negation:</p>
<blockquote><p><em>To prove $\lnot \phi$, assume $\phi$ and derive absurdity.</em></p></blockquote>
<p>The rule for proving negation is the same classically and intuitionistically. I mention this because I have met ordinary mathematicians who think intuitionistic proofs are never allowed to reach an absurdity.</p>
<p><strong>Proof by contradiction</strong>, or <em>reductio ad absurdum</em>, is a different kind of animal. As a reasoning principle it says:</p>
<blockquote><p><em>To prove $\phi$, assume $\lnot \phi$ and derive absurdity.</em></p></blockquote>
<p>As a proposition the principle is written $\lnot \lnot \phi \Rightarrow \phi$, which can be proved from the law of excluded middle (and is in fact equivalent to it). In intuitionistic logic this is not a generally valid principle.</p>
<p>Admittedly, the two reasoning principles look very similar. A classical mathematician will quickly remark that we can get either of the two principles from the other by plugging in $\lnot \phi$ and cancelling the double negation in $\lnot \lnot \phi$ to get back to $\phi$. Yes indeed, but the cancellation of double negation is <em>precisely</em> the reasoning principle we are trying to get. These really <em>are different</em>.</p>
<p>I blame the general confusion on the fact that an informal proof of negation looks almost the same as an informal proof by contradiction.  In order to prove $\lnot \phi$ a mathematician will typically write:</p>
<blockquote><p><em>&#8220;Suppose $\phi$. Then &#8230; bla &#8230; bla &#8230; bla, which is a contradiction. QED.&#8221;</em></p></blockquote>
<p>In order to prove $\phi$ by contradiction a mathematician will typically write:</p>
<blockquote><p><em>&#8220;Suppose $\lnot \phi$. Then &#8230; bla &#8230; bla &#8230; bla, which is a contradiction. QED.&#8221;</em></p></blockquote>
<p>The difference will be further obscured because the text will typically state $\lnot \phi$ in an equivalent form with negation pushed inwards. That is, if $\phi$ is something like $\exists x, \forall y, f(y) &lt; x$ and the proof goes by contradiction then the opening statement will be &#8220;Suppose for every $x$ there were a $y$ such that $f(y) \geq x$.&#8221; With such &#8220;optimizations&#8221; we really cannot tell what is going on by looking just at the proof. We have to take into account the surrounding context (such as the original statement being proved).</p>
<p>A second good reason for the confusion is the fact that both proof principles <em>feel</em> the same when we try to use them. In both cases we assume something believed to be false and then we hunt down a contradiction. The difference in placement of negations is not easily appreciated by classical mathematicians because their brains automagically cancel out double negations, just like good students automatically cancel out double negation signs.</p>
<p>Keeping all this in mind, let us look at Timothy Gower&#8217;s blog examples.</p>
<h4>Irrationality of $\sqrt{2}$</h4>
<p>The first example is irrationality of $\sqrt{2}$. Because &#8220;$\sqrt{2}$ is irrational&#8221; is <em>by definition</em> the same as &#8220;$\sqrt{2}$ is not rational&#8221; we are clearly talking about a proof of negation. There is a theorem about normal forms of proofs in intuitionistic logic which tells us that every proof of a negation can be rearranged so that it ends with the inference rule cited above. In this sense the method of proof &#8220;assume $\sqrt{2}$ is rational, &#8230;, contradiction&#8221; is unavoidable.</p>
<p>I want to make two further remarks. The first one is that the usual proof of irrationality of $\sqrt{2}$ is intuitionistically valid. Let me spell it out:</p>
<blockquote><p><strong>Theorem:</strong> <em>$\sqrt{2}$ is not rational.</em></p>
<p><em>Proof.</em> Suppose $\sqrt{2}$ were equal to a fraction $a/b$ with $a$ and $b$ relatively prime. Then we would get $a^2 = 2 b^2$, hence $a^2$ is even and so is $a$. Write $a = 2 c$ and plug it back in to get $2 c^2 = b^2$, from which we conclude that $b$ is even as well. This is a contradiction since $a$ and $b$ were assumed to be relatively prime. QED.</p></blockquote>
<p>No proof by contradiction here!</p>
<p>My second remark is that this particular example is perhaps not good for discussing proofs of negation because it reduces to inequality of natural numbers, which is a decidable property. That is, as far as intuitionistic logic is concerned, equality and inequality of natural numbers are both equally &#8220;positive&#8221; relations. This is reflected in various variants of the proof given by Gowers on his blog, some of which are &#8220;positive&#8221; in nature.</p>
<p>The situation with reals is different. There we could define the so-called <em>apartness</em> relation $x \# y$ to mean $x &lt; y \lor y &lt; x$. The negation of apartness is equality, but the negation of equality is not apartness, at least not intuitionistically (classically of course this whole discussion is a triviality). A proof of inequality $x \neq y$ of real numbers $x$ and $y$ may thus proceed in two ways:</p>
<ol>
<li>The <em>direct</em> way: assume $x = y$ and derive absurdity</li>
<li>Via apartness: prove $x \# y$ and conclude that $x \neq y$</li>
</ol>
<p>Note that the proof of $x \# y \Rightarrow x \neq y$ still involves the usual proof of negation in which we assume $x \# y \land x = y$ and derive absurdity.</p>
<h4>A continuous map on $[0,1]$ is bounded</h4>
<p>The second example is the statement that a continuous map $f : [0,1] \to \mathbb{R}$ is bounded. The direct proof uses the Heine-Borel property of the closed interval to find a finite cover of $[0,1]$ such that $f$ is bounded on each element of the cover. There is also a proof by contradiction which goes as follows:</p>
<blockquote><p>Suppose $f$ were unbounded. Then we could find a sequence $(x_n)_n$ in $[0,1]$ such that the sequence $(f(x_n))_n$ is increasing and unbounded (this uses Countable Choice, by the way). By Bolzano-Weierstras there is a convergent subsequence $(y_n)_n$ of $(x_n)_n$. Because $f$ is continuous the sequence $(f(y_n))_n$ is convergent, which is impossible because it is a subsequence of the increasing and unbounded sequence $(f(x_n))_n$. QED.</p></blockquote>
<p>Can we turn this proof into one that does not use contradiction (but still uses Bolzano-Weierstrass)? Constructive mathematicians are well versed in doing such things. Essentially we have to look at the supremum of $f$, like Timothy Gowers does, but without actually referring to it. The following proof is constructive and direct.</p>
<blockquote><p><strong>Theorem:</strong> <em>If every sequence in a separable space $X$ has a convergent subsequence, then every continuous real map on $X$ is bounded.</em></p>
<p><em>Proof.</em> Let $(x_n)_n$ be a dense sequence in $X$ and $f : X \to \mathbb{R}$ continuous. For every $n$ there is $k$ such that $f(x_k) \geq \max(f(x_1), &#8230;, f(x_n)) &#8211; 1$. By Countable Choice there is a sequence $(k_n)_n$ such that $f(x_{k_n}) \geq \max(f(x_1), &#8230;, f(x_n)) &#8211; 1$ for every $n$. Let $(z_n)_n$ be a convergent subsequence of $(x_{k_n})_n$ and let $z$ be its limit. Because $f$ is continuous there is $d &gt; 0$ such that $f(z_n) \leq f(z) + d$ for all $n$. Consider any $x \in X$. Because $f$ is continuous and $(x_n)_n$ is dense there is $x_i$ such that $f(x) \leq f(x_i) + 1$. Observe that there is $j$ such that $f(x_{k_i})  - 1 \leq f(z_j)$. Now we get $$f(x) \leq f(x_i) + 1 \leq \max(f(x_1), &#8230;, f(x_i)) + 1 \leq f(x_{k_i}) + 2 \leq f(z_j) + 3 &lt; f(z) + d + 3.$$ We have shown that $f(z) + d + 3$ is an upper bound for $f$. QED.</p></blockquote>
<p>I am pretty sure with a bit more work we could show that $f$ attains its supremum, and in fact this must have been proved by someone constructively.</p>
<p>The moral of the story is: proofs by contradiction can often be avoided, proofs of negation generally cannot, and if you think they are the same thing, you will be confused.</p>
]]></content:encoded>
			<wfw:commentRss>http://math.andrej.com/2010/03/29/proof-of-negation-and-proof-by-contradiction/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

