(* 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).
(*Recursive Definition BV_full_adder_carry: (list bool)->(list bool)->bool->bool := (nil bool) (nil bool) b => b | (nil bool) (cons vh vt) b => (BV_full_adder_carry (nil bool) vt (half_adder_carry vh b)) | (cons vh vt) (nil bool) b => (BV_full_adder_carry vt (nil bool) (half_adder_carry vh b)) | (cons vh vt) (cons wh wt) b => (BV_full_adder_carry vt wt (full_adder_carry vh wh b)). *)
Definition BV_full_adder_carry :=
(fix F (l : list bool) : list bool -> bool -> bool :=
match l with
| nil =>
(fix F0 (l0 : list bool) : bool -> bool :=
match l0 with
| nil => fun z : bool => z
| b :: l1 => fun z : bool => F0 l1 (half_adder_carry b z)
end)
| b :: l0 =>
fun x2 : list bool =>
match x2 with
| nil => fun y z : bool => F l0 nil (half_adder_carry y z)
| b0 :: l1 => fun y z : bool => F l0 l1 (full_adder_carry y b0 z)
end b
end).

Lemma BV_full_adder_carry_eq2 :
forall (vh : bool) (vt : list bool) (b : bool),
BV_full_adder_carry nil (vh :: vt) b =
BV_full_adder_carry nil vt (half_adder_carry vh b).