Why should I trust Coq when assumption-free proof of False in Coq exists? - MathOverflow [closed] most recent 30 from http://mathoverflow.net 2013-05-21T13:58:47Z http://mathoverflow.net/feeds/question/75604 http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://mathoverflow.net/questions/75604/why-should-i-trust-coq-when-assumption-free-proof-of-false-in-coq-exists Why should I trust Coq when assumption-free proof of False in Coq exists? joro 2011-09-16T14:54:50Z 2011-09-16T15:13:24Z <p>Damien Pous <a href="https://sympa-roc.inria.fr/wws/arc/coqdev/2011-07/msg00018.html" rel="nofollow">announced</a> <a href="http://coq.inria.fr/bugs/show_bug.cgi?id=2580" rel="nofollow">code</a> for assumption-free proof of False in Coq which means inconsistency in Coq (without using exploits, lol).</p> <p>Damien is critical of "fully certified decision procedure returning wrong results"</p> <p>My quesion is:</p> <blockquote> <p>Why should I trust Coq if it proves False?</p> </blockquote> <p>(If someone mentions results of <code>coqchk</code>, it is a bug by itself to not trust their compiler and in addition <code>coqchk</code> is known to loop forever after minor hex editing <code>.vo</code>s).</p> <p>Here is an session:</p> <pre><code> ~/coq-test/bin/coqtop Welcome to Coq 8.3pl2 (June 2011) Coq &lt; Require Import bug2. Coq &lt; Check Omega. Omega : False Coq &lt; Print Assumptions Omega. Closed under the global context </code></pre> <p>(code bug2.v for posterity, author Damien Pous)</p> <pre><code> Require List. Set Implicit Arguments. Implicit Arguments inr [A B]. Implicit Arguments inl [A B]. (* a simple signature for maps *) Module Type MAP. Parameter key: Type. Parameter t: Type -&gt; Type. Section s. Variable A: Type. Parameter empty: t A. Parameter add: key -&gt; A -&gt; t A -&gt; t A. Parameter find: key -&gt; t A -&gt; option A. End s. Implicit Arguments empty [[A]]. End MAP. (* maps indexed by natural numbers *) Module NMap &lt;: MAP. Definition key := nat. Section s. Variable A: Type. Definition t := list (option A). Definition empty: t := nil. Fixpoint add i v (m: t) := match i,m with | O,nil =&gt; cons (Some v) nil | O,cons _ q =&gt; cons (Some v) q | S i,nil =&gt; cons None (add i v nil) | S i,cons o q =&gt; cons o (add i v q) end. Definition find i (m: t) := List.nth i m None. End s. Implicit Arguments empty [[A]]. End NMap. (* maps indexed by booleans *) Module BMap &lt;: MAP. Definition key := bool. Section s. Variable A: Type. Definition t := (option A*option A)%type. Definition empty:t := (None,None). Definition find (b: bool) (m: t) := if b then fst m else snd m. Definition add (b: bool) v (m: t) := let (t,f) := m in if b then (Some v,f) else (t,Some v). End s. Implicit Arguments empty [[A]]. End BMap. (* maps indexed by unit *) Module UMap &lt;: MAP. Definition key := unit. Section s. Variable A: Type. Definition t := option A. Definition empty: t := None. Definition find (b: unit) (m: t): option A := m. Definition add (b: unit) (v: A) (m: t): t := Some v. End s. Implicit Arguments empty [[A]]. End UMap. (* maps indexed by pairs *) Module PairMap(H: MAP)(K: MAP) &lt;: MAP. Definition key := prod H.key K.key. Section s. Variable A: Type. Definition t := H.t (K.t A). Definition empty: t := H.empty. Definition find xy (m: t) := let '(pair x y) := xy in match H.find x m with | None =&gt; None | Some n =&gt; K.find y n end. Definition add xy v (m: t) := let '(pair x y) := xy in match H.find x m with | None =&gt; H.add x (K.add y v K.empty) m | Some n =&gt; H.add x (K.add y v n) m end. End s. Implicit Arguments empty [[A]]. End PairMap. (* maps indexed by sums *) Module SumMap(H: MAP)(K: MAP) &lt;: MAP. Definition key := sum H.key K.key. Section s. Variable A: Type. Definition t := prod (H.t A) (K.t A). Definition empty: t := (H.empty, K.empty). Definition find s (m: t) := match s with | inl x =&gt; H.find x (fst m) | inr y =&gt; K.find y (snd m) end. Definition add s v (m: t) := let '(h,k) := m in match s with | inl x =&gt; (H.add x v h,k) | inr y =&gt; (h,K.add y v k) end. End s. Implicit Arguments empty [[A]]. End SumMap. (** selecting these lines, we will get a proof of [False] *) Module MMap := NMap. Definition v := O. (** selecting these lines will give a "bus error" rather than a proof of [False] *) (* Module MMap := BMap. *) (* Definition v := false. *) (** selecting these ones will silently kill the coq process instead *) (* Module MMap := UMap. *) (* Definition v := tt. *) (* we need a functor to make the bug appear *) Module Make(VMap: MAP). (* I didn't manage to get the bug with fewer functor applications *) Module TMap := SumMap VMap MMap. Module MTMap := PairMap MMap TMap. Module MTTMap := PairMap MTMap TMap. (* commenting this goal makes the first bug disappear! *) Goal MTTMap.find (v,inr v,inr v) (MTTMap.add (v,inr v,inr v) 64 MTTMap.empty) = Some 64. Proof. vm_compute. reflexivity. Qed. End Make. Module Import B := Make UMap. (* uncommenting this goal and its proof makes the bug disappear! *) (* Goal MTMap.find (v,inr v) *) (* (MTMap.add (v,inl tt) 16 (MTMap.add (v,inr v) 64 MTMap.empty)) &lt;&gt; None. *) (* Proof. vm_compute. congruence. Qed. *) (* this lemma is ok, and proved with [compute] *) Lemma l1: MTTMap.find (v,inr v,inr v) (MTTMap.add (v,inr v,inl tt) 16 (MTTMap.add (v,inr v,inr v) 64 MTTMap.empty)) = Some 64. Proof. compute. reflexivity. Qed. (* BUG: this lemma is wrong but proved thanks to [vm_compute] *) Lemma l2: MTTMap.find (v,inr v,inr v) (MTTMap.add (v,inr v,inl tt) 16 (MTTMap.add (v,inr v,inr v) 64 MTTMap.empty)) = None. Proof. vm_compute. reflexivity. Qed. (* coqcheck detects that this assumption-free proof of [False] is ill-typed *) Theorem Omega: False. Proof. generalize l1 l2. congruence. Qed. Print Assumptions Omega. (* renaming the module for the first call to [add] solves the problem! *) Module M := MTTMap. Goal MTTMap.find (v,inr v,inr v) (M.add (v,inr v,inl tt) 16 (MTTMap.add (v,inr v,inr v) 64 MTTMap.empty)) &lt;&gt; None. Proof. vm_compute. congruence. Qed. (* no problemb without the functor [Make] *) Module Ok. Module TMap := SumMap UMap MMap. Module MTMap := PairMap MMap TMap. Module MTTMap := PairMap MTMap TMap. Goal MTTMap.find (v,inr v,inr v) (MTTMap.add (v,inr v,inl tt) 16 (MTTMap.add (v,inr v,inr v) 64 MTTMap.empty)) = Some 64. Proof. vm_compute. reflexivity. Qed. End Ok. (* Tested with v8.3 -r 14152 and -r 14299 trunk -r 14299 *) </code></pre>