Library enhancements

Misc stuff

This module does the importing of the Coq library and collects many results that don't really fit anywhere else. Some parts should probably put into separate files, such as the counted_list. There are also a lot of lemmas where I try to prove something just for better understanding of the intuitionistic logic of Coq.

Require Export Coq.Bool.Bool.
Require Export Arith.
Require Omega.
Require Export Coq.Lists.List.
Export ListNotations.

Definition non_empty_type(A : Type) : Prop := (a : A), True.

Definition injective{X Y : Type}(f : XY) : Prop :=
  (x y : X), f x = f yx = y.

Definition enumerator(X : Type) : Type := {f : natX | injective f}.

Definition enum_elem{X : Type}(f : enumerator X) : X := proj1_sig f 0.

Definition countably_infinite(X : Type) : Prop :=
  (f : enumerator X), True.

Definition enum_infinite{X : Type}(f : enumerator X) : countably_infinite X :=
  ex_intro _ f I.

Lemma countably_infinite_non_empty :
  (X : Type)(P : Prop),
    ((non_empty : X), P) →
    countably_infinite X
      P.

Recognizers for the library


Definition is_some{A : Type}(opt : option A) : Prop :=
  match opt with
    | Some _True
    | NoneFalse
  end.

Definition is_none{A : Type}(opt : option A) : Prop :=
  match opt with
    | Some _False
    | NoneTrue
  end.

Lemma neg_is_none : (A : Type)(o : option A),
  ¬ (is_some o)is_none o.

Lemma option_contradiction : (A : Type)(o : option A),
  is_some ois_none oFalse.

Definition is_inl{A B : Type}(ab : A + B) : Prop :=
  match ab with
    | inl _True
    | inr _False
  end.

Definition is_inr{A B : Type}(ab : A + B) : Prop :=
  match ab with
    | inl _False
    | inr _True
  end.

Definition swap_pair{A B : Type}(ab : A × B) : B × A := (snd ab, fst ab).

Lemma split_nat_case_lt : (n m : nat)(P : Prop),
  (n < mP) → (n mP) → P.

Lemma split_nat_case_le : (n m : nat)(P : Prop),
  (n mP) → (n > mP) → P.

Inductive dep_and (A : Type) (B : AType) : Type :=
  dep_conj : (a : A), B adep_and A B.

Notation " p # P /#\ Q " := (dep_and P (fun(p : P) ⇒ Q))
    (at level 80, right associativity) : type_scope.


Lemma iff_right : {P Q : Prop}, (P Q) → PQ.

Lemma iff_left : {P Q : Prop}, (P Q) → QP.

Definition eq_type(A : Type) : Type := (x y : A), {x = y}+{x y}.

Lemma eq_equal : (A B : Type)(f : eq_type A)(a : A)(b1 b2 : B),
  (if f a a then b1 else b2) = b1.

Lemma eq_unequal : (A B : Type)(f : eq_type A)(a1 a2 : A)(b1 b2 : B),
  a1 a2
    (if f a1 a2 then b1 else b2) = b2.

function update


Definition function_update{A B : Type}(a_eq : eq_type A)
                          (f : AB)(a0 : A)(b0 : B) : AB :=
   fun(a : A) ⇒
     if a_eq a a0 then b0
     else f a.

Lemma function_update_eq :
  {A B : Type}(a_eq : eq_type A)(f : AB)(a : A)(b : B),
    function_update a_eq f a b a = b.

Lemma function_update_unequal :
  {A B : Type}(a_eq : eq_type A)(f : AB)(a1 a2 : A)(b : B),
    a1 a2
      function_update a_eq f a1 b a2 = f a2.

Lemma function_update_twice :
  {A B : Type}(a_eq : eq_type A)(f : AB)(a0 : A)(b0 : B),
    function_update a_eq (function_update a_eq f a0 b0) a0 b0 a0 =
    function_update a_eq f a0 b0 a0.

Lemma function_update_split :
  {A B : Type}(P : BProp)
        (a_eq : eq_type A)(f : AB)(a a' : A)(b : B),
    (a = a'P b) →
    (a a'P (f a')) →
      P (function_update a_eq f a b a').

Lemma function_update_split_result :
  {A B : Type}(a_eq : eq_type A)(f : AB)(a1 a2 : A)(b1 b2 : B),
    b1 = b2
    f a2 = b2
      function_update a_eq f a1 b1 a2 = b2.

Definition fcompose{X Y Z : Type}(f : YZ)(g : XY)(x : X) : Z :=
  f(g(x)).


Lemma ge_refl : (n : nat), n n.

Lemma add_minus_diag : (a b : nat), a + b - b = a.

Lemma plus_minus_assoc : (a b c : nat),
  b ca + b - c = a + (b - c).

Intuitionistic exercises


Lemma bcontrapositive : {P Q : bool},
  (P = trueQ = true) →
    (negb Q = truenegb P = true).

Lemma contrapositive : {P Q : Prop}, (PQ) → (¬Q¬P).

Lemma neg_implies : (P Q : Prop), ~(PQ) → (¬P¬Q).

Lemma neg_neg_implies : (P Q : Prop), ~~(PQ) → (~~P~~Q).

Lemma iff_neg : (P Q : Prop), (P Q) → (¬P ¬Q).

Lemma iff_and : (P1 P2 Q1 Q2 : Prop),
  (P1 Q1) → (P2 Q2) → ((P1 P2) (Q1 Q2)).

Lemma neg_double_neg : {P : Prop}, P¬ ¬ P.

Lemma exists_not_not_implies : {A : Type}{P : AProp},
  ( a : A, ¬ P a) → (¬ (a : A), P a).

Lemma forall_not_iff_not_exists : {A : Type}{P : AProp},
  ((a : A), ¬ P a) (¬ a : A, P a).

Lemma or_neg_neg_and : (P Q : Prop),
  ((¬ P) (¬ Q)) → ¬ (P Q).



Lemma double_neg_impl_neg_or :
  (P Q : Prop), (~~(PQ)) (~~(~P Q)).

Definition dneg_or(P Q : Prop) : Prop := ¬ (~ P ¬ Q).

Lemma dneg_or_intro : (P Q : Prop), Pdneg_or P Q.

Lemma dneg_or_elim : (G P Q : Prop),
  (PG) → (QG) → dneg_or P Q¬ ¬ G.

Lemma single_prop_ax_correct : (P : Prop),
  dneg_or P (¬ P).

Lemma prop_ax_down_correct : (G P : Prop),
  dneg_or P (dneg_or (¬ P) G).

Lemma prop_ax_up_correct : (G P : Prop),
  dneg_or P (dneg_or (¬ P) G) → True.

Lemma prop_and_down_correct : (G P Q : Prop),
  dneg_or P Gdneg_or Q Gdneg_or (P Q) G.

Lemma prop_and_up_correct : (G P Q : Prop),
  dneg_or (P Q) G(dneg_or P G) dneg_or Q G.

Lemma prop_or_down_correct : (G P Q : Prop),
  dneg_or (¬ P) (dneg_or (¬ Q) G) → dneg_or (¬ (P Q)) G.

Lemma prop_or_up_correct_context : (G P Q : Prop),
   dneg_or (¬ (P Q)) Gdneg_or (¬ P) (dneg_or (¬ Q) G).

Lemma prop_or_up_correct : (P Q : Prop),
   (¬ (P Q)) → dneg_or (¬ P) (¬ Q).

Lemma prop_neg_down_correct : (G P : Prop),
  dneg_or P Gdneg_or (¬ ¬ P) G.

Lemma prop_neg_up_correct : (G P : Prop),
  dneg_or (¬ ¬ P) Gdneg_or P G.

max


Lemma max_mono_both : (n1 n2 n3 n4 : nat),
  n1 n3n2 n4max n1 n2 max n3 n4.

counted lists


Inductive counted_list(A : Type) : natType :=
  | counted_nil : counted_list A 0
  | counted_cons : (n : nat),
      Acounted_list A ncounted_list A (S n).

Implicit Arguments counted_nil [[A]].
Implicit Arguments counted_cons [A n].

Definition counted_head{A : Type}{n : nat}(l : counted_list A (S n)) : A :=
  match l in (counted_list _ n')
          return (match n' return Type with
                    | 0 ⇒ nat
                    | S _A
                  end)
  with
    | counted_nil ⇒ 0
    | counted_cons _ a _a
  end.

Fixpoint counted_map{A B : Type}{n : nat}(f : AB)(al : counted_list A n) :
                                                           counted_list B n :=
  match al with
    | counted_nilcounted_nil
    | counted_cons n a alcounted_cons (f a) (counted_map f al)
  end.

Fixpoint list_of_counted_list{A : Type}{n : nat}(l : counted_list A n) :
                                                                      list A :=
  match l with
    | counted_nil[]
    | counted_cons n a la :: (list_of_counted_list l)
  end.

Lemma list_of_counted_list_map :
  (A B : Type)(n : nat)(f : AB)(al : counted_list A n),
    list_of_counted_list (counted_map f al) = map f (list_of_counted_list al).

Lemma length_list_of_counted_list :
  (A : Type)(n : nat)(l : counted_list A n),
    length (list_of_counted_list l) = n.

Lemma less_length_counted_list :
  {A : Type}(i n : nat)(l : counted_list A n),
    i < ni < length (list_of_counted_list l).

Lemma counted_list_eta : {A : Type}{n : nat}(l : counted_list A n),
  match n return counted_list A nProp with
    | 0 ⇒ fun(l : counted_list A 0) ⇒ l = counted_nil
    | S nfun(l : counted_list A (S n)) ⇒
      (a : A)(tl : counted_list A n), l = counted_cons a tl
  end l.

Lemma counted_list_eta_1 : {A : Type}(l : counted_list A 1),
  (a : A), l = counted_cons a counted_nil.

Lemma counted_0_destruction :
  (A : Type)(P : counted_list A 0 → Prop)(v : counted_list A 0),
    P counted_nil
      P v.

Lemma counted_list_equal :
  {A : Type}{n : nat}(l1 l2 : counted_list A n),
    list_of_counted_list l1 = list_of_counted_list l2
      l1 = l2.