(* 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            *)
(*                       COQ v5.10                              *)
(*                                                              *)
(* Laurent Arditi.  Laboratoire I3S. CNRS ura 1376.             *)
(* Universite de Nice - Sophia Antipolis                        *)
(* arditi@unice.fr, http://wwwi3s.unice.fr/~arditi/lolo.html    *)
(*                                                              *)
(* date: july 1995                                              *)
(* file: MultSeq.v                                              *)
(* contents: VERIFICATION OF A SEQUENTIAL MULTIPLIER.           *)
(* Proofs of the invariant and the final theorem                *)
(****************************************************************)
(* L'invariant est : si t<= size alors nat(R1(t)[size-t:size-1]@R2(t))=nat(V2)*nat(V1[0:t-1]) *)
(****************************************************************)
(* D'abord on prouve l'invariant pour t=O: *)
intros. simpl in |- *.
rewrite BV_to_nat_app2. rewrite (trunc_O bool). rewrite <- length_V1_size.
rewrite (strip_all bool). rewrite length_V1_size.
simpl in |- *. elim plus_n_O. elim mult_n_O. rewrite BV_null_nat. trivial with arith.
Qed.
(****************************************************************)
(* Ensuite, lors de la preuve par induction pour t quelconque, on doit faire une preuve par cas selon R1[0]. On fait la preuve pour R1[0]=false:  (assez long) *)

Lemma inv_ind_false :
forall t n : nat,
(n <= size ->
BV_to_nat (appbv (stripbv (R1 n) (size - n)) (R2 n)) =
BV_to_nat V2 * BV_to_nat (truncbv V1 n)) ->
S n <= size ->
n <= size ->
BV_to_nat
(appbv
(stripbv
(appbv (highs (R1 n))
(Mux false (abit (BV_full_adder_sum (R2 n) V2 false) 0)
(consbv (lowbit (R2 n)) nilbv))) (size - S n))
(appbv (highs (Mux false (BV_full_adder_sum (R2 n) V2 false) (R2 n)))
(Mux false (consbv (BV_full_adder_carry (R2 n) V2 false) nilbv)
(consbv false nilbv)))) =
BV_to_nat V2 * BV_to_nat (appbv (truncbv V1 n) (consbv false nilbv)).