(* 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 V5.10                                 *)
(*                              Nov 25th 1994                               *)
(*                                                                          *)
(****************************************************************************)
(****************************************************************************)
(*                               Residuals.v                                *)
(*                                                                          *)
(*                                Gerard Huet                               *)
(*                                                                          *)
(* Developed in V5.8  January 1993                                          *)
(* Ported    to V5.10 January 1995                                          *)
(****************************************************************************)
(*************************************************)
(* Parallel beta reduction with residual tracing *)
(*************************************************)
(* (residuals U V W) means W are residuals of redexes U by step V *)
Inductive residuals : redexes -> redexes -> redexes -> Prop :=
| Res_Var : forall n : nat, residuals (Var n) (Var n) (Var n)
| Res_Fun :
forall U V W : redexes,
residuals U V W -> residuals (Fun U) (Fun V) (Fun W)
| Res_Ap :
forall U1 V1 W1 : redexes,
residuals U1 V1 W1 ->
forall U2 V2 W2 : redexes,
residuals U2 V2 W2 ->
forall b : bool, residuals (Ap b U1 U2) (Ap false V1 V2) (Ap b W1 W2)
| Res_redex :
forall U1 V1 W1 : redexes,
residuals U1 V1 W1 ->
forall U2 V2 W2 : redexes,
residuals U2 V2 W2 ->
forall b : bool,
residuals (Ap b (Fun U1) U2) (Ap true (Fun V1) V2) (subst_r W2 W1).
Hint Resolve Res_Var Res_Fun Res_Ap Res_redex.
(* Commutation theorem *)
Hint Resolve residuals_lift.
Hint Resolve residuals_subst_rec.
(***************************)
(* The Commutation Theorem *)
(***************************)
(* We take residuals only by regular redexes *)
(* Conversely, residuals by compatible regular redexes always exist (and are unique by residuals_function lemma above) *)
(* Residuals preserve regularity *)

Lemma residuals_preserve_regular :
forall U V W : redexes, residuals U V W -> regular U -> regular W.