(* 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)                    *)
(* ----                 generation.v ----                                   *)
(*                                                                          *)
(* Author: Pierre Casteran.                                                 *)
(*    LABRI, URA CNRS 1304,                                                 *)
(*    Departement d'Informatique, Universite Bordeaux I,                    *)
(*    33405 Talence CEDEX,                                                  *)
(*    e-mail:  casteran@labri.u-bordeaux.fr                                 *)
(*  This file uses the results of "develop" to validate the chain generation algorithm; see also the "spec" module.  *)
(* termination of the addition chain algorithm *)
(***********************************************)
(* termination order (based on recursive calls) *)
Inductive Call_lt : Call -> Call -> Prop :=
| M_M_lt : forall p q : nat, p < q -> Call_lt (Call_M p) (Call_M q)
| C_M_lt : forall p q : nat, p < q -> Call_lt (Call_C q p) (Call_M q)
| M_C_lt : forall p q r : nat, p < r -> Call_lt (Call_M p) (Call_C r q)
| M_K_lt : forall p q r : nat, p <= r -> Call_lt (Call_M p) (Call_K r q)
| K_C_lt : forall p q r s : nat, q < s -> Call_lt (Call_K q p) (Call_C s r)
| K_K_lt : forall p q r s : nat, q < s -> Call_lt (Call_K q p) (Call_K s r).
(* In order to prove well-foundedness of Call_lt, we use an auxiliary ad-hoc measure *)
Definition Call_measure (c : Call) :=
match c return nat with
| Call_M n =>
(* Call_M n *)
S (three * n)
(* Call_C n p *)
| Call_C n p => three * n
(* Call_K n p *)
| Call_K n p => S (S (three * n))
end.
(**************************************************)

Lemma Wf_Call_lt : well_founded Call_lt.