(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)


(* Contribution to the Coq Library   V6.3 (July 1999)                    *)
(****************************************************************************)
(*                 The Calculus of Inductive Constructions                  *)
(*                                                                          *)
(*                                Projet Coq                                *)
(*                                                                          *)
(*                     INRIA                        ENS-CNRS                *)
(*              Rocquencourt                        Lyon                    *)
(*                                                                          *)
(*                                 Coq V6.1                                 *)
(*                               Oct 1st 1996                               *)
(*                                                                          *)
(****************************************************************************)
(*                               Coherence.v                                *)
(****************************************************************************)

Hint Resolve refl_equal. (* TO BE REMOVED *)
Require Import Relations.
Require Import Confluence.

Set Implicit Arguments.
Unset Strict Implicit.

Theorem Rstar_reflexive :
 forall (U : Type) (R : Relation U), Reflexive (Rstar R).
Proof.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
auto.
Qed.

Theorem Rplus_contains_R :
 forall (U : Type) (R : Relation U), Contains (Rplus R) R.
Proof.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
auto.
Qed.

Theorem Rstar_contains_R :
 forall (U : Type) (R : Relation U), Contains (Rstar R) R.
Proof.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
intros U R; red in |- *; intros x y H'; apply Rstar_n with y; auto.
Qed.

Theorem Rstar_contains_Rplus :
 forall (U : Type) (R : Relation U), Contains (Rstar R) (Rplus R).
Proof.
(* Goal: forall (U : Type) (R : Relation U), @Symmetric U (fun x y : U => @ex U (fun z : U => and (@Rstar U R x z) (@Rstar U R y z))) *)
intros U R; red in |- *.
(* Goal: forall (x y : U) (_ : @Rplus U R x y), @Rstar U R x y *)
intros x y H'; elim H'.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
generalize Rstar_contains_R; intro T; red in T; auto.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
intros x0 y0 z H'0 H'1 H'2; apply Rstar_n with y0; auto.
Qed.

Theorem Rstar_transitive :
 forall (U : Type) (R : Relation U), Transitive (Rstar R).
Proof.
(* Goal: forall (U : Type) (R : Relation U), @Symmetric U (fun x y : U => @ex U (fun z : U => and (@Rstar U R x z) (@Rstar U R y z))) *)
intros U R; red in |- *.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
intros x y z H'; elim H'; auto.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
intros x0 y0 z0 H'0 H'1 H'2 H'3; apply Rstar_n with y0; auto.
Qed.

Theorem Rstar_cases :
 forall (U : Type) (R : Relation U) (x y : U),
 Rstar R x y -> x = y \/ (exists u : U, R x u /\ Rstar R u y).
Proof.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
intros U R x y H'; elim H'; auto.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
intros x0 y0 z H'0 H'1 H'2; right; exists y0; auto.
Qed.

Theorem Rstar_equiv_Rstar1 :
 forall (U : Type) (R : Relation U), Same_relation (Rstar R) (Rstar1 R).
Proof.
(* Goal: forall (U : Type) (R : Relation U), @Same_relation U (@Rstar U R) (@Rstar1 U R) *)
generalize Rstar_contains_R; intro T; red in T.
(* Goal: forall (U : Type) (R : Relation U), @Same_relation U (@Rstar U R) (@Rstar1 U R) *)
intros U R; unfold Same_relation, Contains in |- *.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
split; intros x y H'; elim H'; auto.
(* Goal: forall (U : Type) (R : Relation U) (x y z : U) (_ : @Rstar U R x y) (_ : @Rplus U R y z), @ex U (fun u : U => and (R x u) (@Rstar U R u z)) *)
generalize Rstar_transitive; intro T1; red in T1.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
intros x0 y0 z H'0 H'1 H'2 H'3; apply T1 with y0; auto.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
intros x0 y0 z H'0 H'1 H'2; apply Rstar1_n with y0; auto.
Qed.

Theorem Rsym_imp_Rstarsym :
 forall (U : Type) (R : Relation U), Symmetric R -> Symmetric (Rstar R).
Proof.
(* Goal: forall (U : Type) (R : Relation U) (_ : @Symmetric U R), @Symmetric U (@Rstar U R) *)
intros U R H'; red in |- *.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
intros x y H'0; elim H'0; auto.
(* Goal: forall (x y z : U) (_ : R x y) (_ : @Rstar U R y z) (_ : @Rstar U R z y), @Rstar U R z x *)
intros x0 y0 z H'1 H'2 H'3.
(* Goal: forall (x y z : U) (_ : R x y) (_ : @Rstar U R y z) (_ : @Rstar U S y z), @Rstar U S x z *)
generalize Rstar_transitive; intro T; red in T.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
apply T with y0; auto.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
apply Rstar_n with x0; auto.
Qed.

Theorem Sstar_contains_Rstar :
 forall (U : Type) (R S : Relation U),
 Contains (Rstar S) R -> Contains (Rstar S) (Rstar R).
Proof.
(* Goal: forall (U : Type) (R S : Relation U) (_ : @Contains U (@Rstar U S) R), @Contains U (@Rstar U S) (@Rstar U R) *)
unfold Contains in |- *.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
intros U R S H' x y H'0; elim H'0; auto.
(* Goal: forall (x y z : U) (_ : R x y) (_ : @Rstar U R y z) (_ : @Rstar U S y z), @Rstar U S x z *)
generalize Rstar_transitive; intro T; red in T.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
intros x0 y0 z H'1 H'2 H'3; apply T with y0; auto.
Qed.

Theorem star_monotone :
 forall (U : Type) (R S : Relation U),
 Contains S R -> Contains (Rstar S) (Rstar R).
Proof.
(* Goal: forall (U : Type) (R S : Relation U) (_ : @Contains U S R), @Contains U (@Rstar U S) (@Rstar U R) *)
intros U R S H'.
(* Goal: @Contains U (@Rstar U S) (@Rstar U R) *)
apply Sstar_contains_Rstar.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
generalize (Rstar_contains_R (R:=S)); auto.
Qed.

Theorem RstarRplus_RRstar :
 forall (U : Type) (R : Relation U) (x y z : U),
 Rstar R x y -> Rplus R y z -> exists u : U, R x u /\ Rstar R u z.
Proof.
(* Goal: forall (U : Type) (R : Relation U) (x y z : U) (_ : @Rstar U R x y) (_ : @Rplus U R y z), @ex U (fun u : U => and (R x u) (@Rstar U R u z)) *)
generalize Rstar_contains_Rplus; intro T; red in T.
(* Goal: forall (U : Type) (R : Relation U) (x y z : U) (_ : @Rstar U R x y) (_ : @Rplus U R y z), @ex U (fun u : U => and (R x u) (@Rstar U R u z)) *)
generalize Rstar_transitive; intro T1; red in T1.
(* Goal: forall (U : Type) (R : Relation U) (x y z : U) (_ : @Rstar U R x y) (_ : @Rplus U R y z), @ex U (fun u : U => and (R x u) (@Rstar U R u z)) *)
intros U R x y z H'; elim H'.
(* Goal: forall (x : U) (_ : @Rplus U R x z), @ex U (fun u : U => and (R x u) (@Rstar U R u z)) *)
(* Goal: forall (x y z0 : U) (_ : R x y) (_ : @Rstar U R y z0) (_ : forall _ : @Rplus U R z0 z, @ex U (fun u : U => and (R y u) (@Rstar U R u z))) (_ : @Rplus U R z0 z), @ex U (fun u : U => and (R x u) (@Rstar U R u z)) *)
intros x0 H'0; elim H'0.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
intros; exists y0; auto.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
intros; exists y0; auto.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
intros; exists y0; auto.
(* Goal: and (R x0 y0) (@Rstar U R y0 z) *)
split; [ try assumption | idtac ].
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
apply T1 with z0; auto.
Qed.

Theorem Rstar_imp_coherent :
 forall (U : Type) (R : Relation U) (x y : U), Rstar R x y -> coherent R x y.
Proof.
(* Goal: forall (U : Type) (R : Relation U) (x y : U) (_ : @Rstar U R x y), @coherent U R x y *)
intros U R x y H'; red in |- *.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
exists y; auto.
Qed.
Hint Resolve Rstar_imp_coherent.

Theorem coherent_symmetric :
 forall (U : Type) (R : Relation U), Symmetric (coherent R).
Proof.
(* Goal: forall (U : Type) (R : Relation U), @Symmetric U (@coherent U R) *)
unfold coherent at 1 in |- *.
(* Goal: forall (U : Type) (R : Relation U), @Symmetric U (fun x y : U => @ex U (fun z : U => and (@Rstar U R x z) (@Rstar U R y z))) *)
intros U R; red in |- *.
(* Goal: forall (x y : U) (_ : @ex U (fun z : U => and (@Rstar U R x z) (@Rstar U R y z))), @ex U (fun z : U => and (@Rstar U R y z) (@Rstar U R x z)) *)
intros x y h; elim h; intros z h0; elim h0; intros H' H'0; clear h h0.
(* Goal: forall (U : Type) (R : Relation U), @Contains U (@Rplus U R) R *)
exists z; auto.
Qed.

(* $Id$ *)