(* 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: may 1995                                               *)
(* file: Adder.v                                                *)
(* contents: Definition of an adder for two BVs and a carry     *)
(*                                                              *)
(****************************************************************)
Require Export BV.
Require Export FullAdder.
(****************************************************************)
(* Pourquoi ne peut-on ecrire ceci: ? *)
(*Recursive Definition BV_full_adder_sum : BV -> BV -> bool -> BV := utiliser le type BV en parties gauches ????????? UN BUG DE COQ ?????????? *)
(*Recursive Definition BV_full_adder_sum: (list bool)->(list bool)->bool->BV := (nil bool) (nil bool) b => nilbv | (nil bool) (cons bool vh vt) b => (consbv (half_adder_sum vh b) (BV_full_adder_sum (nil bool) vt (half_adder_carry vh b))) | (cons bool vh vt) (nil bool) b => (consbv (half_adder_sum vh b) (BV_full_adder_sum vt (nil bool) (half_adder_carry vh b))) | (cons bool vh vt) (cons bool wh wt) b => (consbv (full_adder_sum vh wh b) (BV_full_adder_sum vt wt (full_adder_carry vh wh b))). *)
Definition BV_full_adder_sum :=
(fix F (l : list bool) : list bool -> bool -> BV :=
match l with
| nil =>
(fix F0 (l0 : list bool) : bool -> BV :=
match l0 with
| nil => fun _ : bool => nilbv
| b :: l1 =>
fun z : bool =>
consbv (half_adder_sum b z) (F0 l1 (half_adder_carry b z))
end)
| b :: l0 =>
fun x2 : list bool =>
match x2 with
| nil =>
fun y z : bool =>
consbv (half_adder_sum y z) (F l0 nil (half_adder_carry y z))
| b0 :: l1 =>
fun y z : bool =>
consbv (full_adder_sum y b0 z)
(F l0 l1 (full_adder_carry y b0 z))
end b
end).

(* Specifications: *)
Lemma BV_full_adder_sum_eq1 :
forall b : bool, BV_full_adder_sum nil nil b = nilbv.
Lemma BV_full_adder_sum_eq2 :
forall (vh : bool) (vt : list bool) (b : bool),
BV_full_adder_sum nil (vh :: vt) b =
consbv (half_adder_sum vh b)
(BV_full_adder_sum nil vt (half_adder_carry vh b)).
Lemma BV_full_adder_sum_eq3 :
forall (vh : bool) (vt : list bool) (b : bool),
BV_full_adder_sum (vh :: vt) nil b =
consbv (half_adder_sum vh b)
(BV_full_adder_sum vt nil (half_adder_carry vh b)).
Lemma BV_full_adder_sum_eq4 :
forall (vh : bool) (vt : list bool) (wh : bool) (wt : list bool) (b : bool),
BV_full_adder_sum (vh :: vt) (wh :: wt) b =
consbv (full_adder_sum vh wh b)
(BV_full_adder_sum vt wt (full_adder_carry vh wh b)).