(************************************************************************)
(*         *   The Coq Proof Assistant / The Coq Development Team       *)
(*  v      *   INRIA, CNRS and contributors - Copyright 1999-2018       *)
(* <O___,, *       (see CREDITS file for the list of authors)           *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)
Basics ByteVector.
Local Open Scope N_scope.
Local Open Scope program_scope.
(** This file is mostly obsolete, see directly [BinNat] now. *)
(** Compatibility names for some bitwise operations *)
Notation Pxor := Pos.lxor (only parsing).
Notation Nxor := N.lxor (only parsing).
Notation Pbit := Pos.testbit_nat (only parsing).
Notation Nbit := N.testbit_nat (only parsing).
Notation Nxor_eq := N.lxor_eq (only parsing).
Notation Nxor_comm := N.lxor_comm (only parsing).
Notation Nxor_assoc := N.lxor_assoc (only parsing).
Notation Nxor_neutral_left := N.lxor_0_l (only parsing).
Notation Nxor_neutral_right := N.lxor_0_r (only parsing).
Notation Nxor_nilpotent := N.lxor_nilpotent (only parsing).
(** Equivalence of bit-testing functions, either with index in [N] or in [nat]. *)
(** Equivalence of shifts, index in [N] or [nat] *)
(** Correctness proofs for shifts, nat version *)
(** A left shift for positive numbers (used in BigN) *)
(** Semantics of bitwise operations with respect to [N.testbit_nat] *)
(** Equality over functional streams of bits *)
Definition eqf (f g:nat -> bool) := forall n:nat, f n = g n.
Program Instance eqf_equiv : Equivalence eqf.
Local Infix "==" := eqf (at level 70, no associativity).
(** If two numbers produce the same stream of bits, they are equal. *)
Local Notation Step H := (fun n => H (S n)).
Local Close Scope N_scope.
(** Checking whether a number is odd, i.e. if its lower bit is set. *)
Notation Nbit0 := N.odd (only parsing).
Definition Nodd (n:N) := N.odd n = true.
Definition Neven (n:N) := N.odd n = false.

Lemma Nsame_bit0 :
forall (a a':N) (p:positive),
N.lxor a a' = Npos (xO p) -> N.odd a = N.odd a'.