Appendix A -- Abstract Reduction Systems.

Tactics

Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Require Import Coq.Program.Equality.

Delimit Scope prop_scope with PROP.
Open Scope prop_scope.

Ltac inv H := inversion H; subst; clear H.

Code by Adam Chlipala.
Ltac not_in_context P :=
  match goal with
    |[_ : P |- _] fail 1
    | _ idtac
  end.

Code by Adam Chlipala. Extend context by proposition of given proof. Fail if proposition is already in context.
Ltac extend H :=
let A := type of H in not_in_context A; generalize H; intro.

Definition Rel (T : Type) := T T Prop.

Union of two relations
Inductive Or {X} (R R': X X Prop) : X X Prop :=
| Inl x y : R x y Or R R' x y
| Inr x y : R' x y Or R R' x y.

Hint Constructors Or.

Reflexive, Transitive closure


Section Definitions.

Variables (T : Type) (e : Rel T).
Implicit Types (R S : T T Prop).

Inductive star (x : T) : T Prop :=
| starR : star x x
| starSE y z : e x y star y z star x z.

Hint Constructors star.
Hint Resolve starR.

Lemma star1 x y : e x y star x y.
Proof. intros. eapply starSE; eauto. Qed.

Lemma star_trans y x z : star x y star y z star x z.
Proof.
  intros H H'. revert x H.
  induction H' as [|x y z IH]; intros; eauto. eapply IH. induction H; eauto.
Qed.


End Definitions.
Hint Constructors star.

Arguments star_trans {T e} y {x z} A B.

Lemma star_img (f : ) ( : Rel ) :
  ( x y, x y star (f x) (f y))
  ( x y, star x y star (f x) (f y)).
Proof.
  intros. induction ; eauto.
  eapply star_trans with ( := f y); eauto.
Qed.


Lemma star_hom (f : ) ( : Rel ) ( : Rel ) :
  ( x y, x y (f x) (f y))
  ( x y, star x y star (f x) (f y)).
Proof.
  intros. induction ; eauto.
Qed.


Arguments star_hom { } f {} A x y B.

Inductive plus {X} (R : X X Prop) : X X Prop :=
 | plusR s t u : R s t star R t u plus R s u.

Hint Constructors plus star.

Lemma star_plus {X} (R: X X Prop) s t :
  star R s t star (plus R) s t.
Proof.
  induction 1; eauto.
Qed.


Strong Normalisation


Inductive sn T (e: Rel T) : T Prop :=
| SNI x: ( y, e x y sn e y) sn e x.

Hint Immediate SNI.

Definition morphism { } ( : Rel ) ( : Rel ) (h : ) :=
   x y, x y (h x) (h y).

Hint Unfold morphism.

Morphism lemma, due to Steven Schäfer.
Fact sn_morphism { } ( : Rel ) ( : Rel ) (h : ) x :
  morphism h sn (h x) sn x.
Proof.
  intros H .
  remember (h x) as a eqn:. revert x .
  induction as [a _ IH]. intros x .
  constructor. intros y % H.
  apply (IH _ ). reflexivity.
Qed.


Lemma sn_orL X (R R' : X X Prop) s:
  sn (Or R R') s sn R s.
Proof.
  intros H. induction H.
  constructor; intros; eauto.
Qed.


Lemma sn_orR X (R R' : X X Prop) s:
  sn (Or R R') s sn R' s.
Proof.
  intros H. induction H.
  constructor; intros; eauto.
Qed.


Forward Propagation.
Fact sn_forward_star X (R : X X Prop) s t : sn R s star R s t sn R t.
Proof.
  intros H. revert t. induction H.
  intros. inv .
  - now constructor.
  - eapply ; eauto.
Qed.


Strong normalisation of a relation <-> strong normalisation of its transitive closure.
Lemma sn_plus {X} (R : X X Prop) x:
  sn R x sn (plus R) x.
Proof.
  split.
  - induction 1.
    constructor. intros. destruct .
    specialize ( _ ).
    apply sn_forward_star with (s := t); eauto using star_plus.
  - apply sn_morphism with (h := @id X).
    unfold morphism. econstructor; eauto.
Qed.


Local confluence, confluence, and Newman's Lemma.

Proofs by Gert Smolka, Semantics.

Definition locally_confluent {X} (R: X X Prop) :=
   s t, R s t t', R s t' u, star R t u star R t' u.

Definition confluent {X} (R: X X Prop) :=
   s t, star R s t t', star R s t' u, star R t u star R t' u.

Definition terminating {X} (R : X X Prop) :=
   x, sn R x.

Hint Unfold terminating.

Fact newman {X} (R : X X Prop) :
  terminating R locally_confluent R confluent R.
Proof.
  intros x.
  generalize ( x).
  induction 1 as [x _ IH].
  intros .
  destruct as [| ].
  { exists ; eauto. }
  destruct as [| ].
  { exists . eauto. }
  assert ( u, (star R) u star R u) as (u&&).
  { eapply ; eauto. }
  assert ( v, (star R) u v star R v) as (v&&).
  { eapply (IH ); eauto. }
  assert ( w, (star R) w star R v w) as (w&&).
  { eapply (IH ); eauto using star_trans. }
  exists w. eauto using star_trans.
Qed.