Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idiomatically expressing "The Following Are Equivalent" in Coq

Tags:

coq

Exercise 6.7 in Coq'Art, or the final exercise of the Logic chapter in Software Foundations: show that the following are equivalent.

Definition peirce := forall P Q:Prop, ((P->Q)->P)->P.
Definition classic := forall P:Prop, ~~P -> P.
Definition excluded_middle := forall P:Prop, P\/~P.
Definition de_morgan_not_and_not := forall P Q:Prop, ~(~P/\~Q)->P\/Q.
Definition implies_to_or := forall P Q:Prop, (P->Q)->(~P\/Q).

The solution set expresses this by a circular chain of implications, using five separate lemmas. But "TFAE" proofs are common enough in mathematics that I'd like to have an idiom to express them. Is there one in Coq?

like image 317
Carl Patenaude Poulin Avatar asked May 13 '17 19:05

Carl Patenaude Poulin


1 Answers

This type of pattern is very easy to express in Coq, although setting up the infrastructure to do so might take some effort.

First, we define a proposition that expresses that all propositions in a list are equivalent:

Require Import Coq.Lists.List. Import ListNotations.

Definition all_equivalent (Ps : list Prop) : Prop :=
  forall n m : nat, nth n Ps False -> nth m Ps True.

Next, we want to capture the standard pattern for proving this kind of result: if each proposition in the list implies the next one, and the last implies the first, we know they are all equivalent. (We could also have a more general pattern, where we replace a straight list of implications with a graph of implications between the propositions, whose transitive closure generates a complete graph. We'll avoid that in the interest of simplicity.) The premise of this pattern is easy to express; it is just a code transcription of the English explanation above.

Fixpoint all_equivalent'_aux 
  (first current : Prop) (rest : list Prop) : Prop :=
  match rest with
  | []         => current -> first
  | P :: rest' => (current -> P) /\ all_equivalent'_aux first P rest'
  end.

Definition all_equivalent' (Ps : list Prop) : Prop :=
  match Ps with
  | first :: second :: rest =>
    (first -> second) /\ all_equivalent' first second rest
  | _ => True
  end.

The difficult part is showing that this premise implies the conclusion we want:

Lemma all_equivalentP Ps : all_equivalent' Ps -> all_equivalent Ps.

Showing that this lemma holds probably requires some ingenuity to find a strong enough inductive generalization. I can't quite prove it right now, but might add a solution later to the answer if you want.

like image 99
Arthur Azevedo De Amorim Avatar answered Nov 07 '22 23:11

Arthur Azevedo De Amorim