Library Coq.ZArith.BinInt
Binary Integers
Initial author: Pierre Crégut, CNET, Lannion, France
The type
Z and its constructors
Z0 and
Zpos and
Zneg
are now defined in
BinNums.v
Local Open Scope Z_scope.
Every definitions and early properties about binary integers
are placed in a module Z for qualification purpose.
Definitions of operations, now in a separate file
When including property functors, only inline t eq zero one two
Decidability of equality.
Properties of pos_sub
pos_sub can be written in term of positive comparison
and subtraction (cf. earlier definition of addition of Z)
Particular cases of the previous result
The opposite of pos_sub is pos_sub with reversed arguments
In the following module, we group results that are needed now
to prove specifications of operations, but will also be provided
later by the generic functor of properties.
Properties of addition
Zero is neutral for addition
Opposite distributes over addition
Subtraction and successor
Opposite is inverse for addition
Commutativity of multiplication
Associativity of multiplication
Multiplication and constants
Multiplication and Opposite
Distributivity of multiplication over addition
Basic properties of divisibility
Conversions between Z.testbit and N.testbit
Proofs of specifications
Specification of constants
Specification of addition
Specification of opposite
Specification of successor and predecessor
Specification of subtraction
Specification of multiplication
Specification of comparisons and order
Some more advanced properties of comparison and orders,
including compare_spec and lt_irrefl and lt_eq_cases.
Remaining specification of lt and le
Specification of minimum and maximum
Specification of absolute value
For folding back a pow_pos into a pow
Specification of square root
Specification of logarithm
Specification of parity functions
Multiplication and Doubling
Correctness proofs for Trunc division
Correctness proofs for Floor division
Correctness proofs for gcd
ggcd and opp : an auxiliary result used in QArith
Proofs of specifications for bitwise operations
Correctness proofs about Z.shiftr and Z.shiftl
Correctness proofs for bitwise operations
Induction principles based on successor / predecessor
Proofs of morphisms, obvious since eq is Leibniz
The Bind Scope prevents Z to stay associated with abstract_scope.
(TODO FIX)
In generic statements, the predicates lt and le have been
favored, whereas gt and ge don't even exist in the abstract
layers. The use of gt and ge is hence not recommended. We provide
here the bare minimal results to related them with lt and le.
We provide a tactic converting from one style to the other.
Similarly, the boolean comparisons ltb and leb are favored
over their dual gtb and geb. We prove here the equivalence
and a few minimal results.
TODO : to add in Numbers ?
Re-export Notations
Infix "+" :=
Z.add :
Z_scope.
Notation "- x" := (
Z.opp x) :
Z_scope.
Infix "-" :=
Z.sub :
Z_scope.
Infix "*" :=
Z.mul :
Z_scope.
Infix "^" :=
Z.pow :
Z_scope.
Infix "/" :=
Z.div :
Z_scope.
Infix "mod" :=
Z.modulo (
at level 40,
no associativity) :
Z_scope.
Infix "÷" :=
Z.quot (
at level 40,
left associativity) :
Z_scope.
Infix "?=" :=
Z.compare (
at level 70,
no associativity) :
Z_scope.
Infix "=?" :=
Z.eqb (
at level 70,
no associativity) :
Z_scope.
Infix "<=?" :=
Z.leb (
at level 70,
no associativity) :
Z_scope.
Infix "<?" :=
Z.ltb (
at level 70,
no associativity) :
Z_scope.
Infix ">=?" :=
Z.geb (
at level 70,
no associativity) :
Z_scope.
Infix ">?" :=
Z.gtb (
at level 70,
no associativity) :
Z_scope.
Notation "( x | y )" := (
Z.divide x y) (
at level 0) :
Z_scope.
Infix "<=" :=
Z.le :
Z_scope.
Infix "<" :=
Z.lt :
Z_scope.
Infix ">=" :=
Z.ge :
Z_scope.
Infix ">" :=
Z.gt :
Z_scope.
Notation "x <= y <= z" := (
x <= y /\ y <= z) :
Z_scope.
Notation "x <= y < z" := (
x <= y /\ y < z) :
Z_scope.
Notation "x < y < z" := (
x < y /\ y < z) :
Z_scope.
Notation "x < y <= z" := (
x < y /\ y <= z) :
Z_scope.
Conversions from / to positive numbers
Some results concerning Z.neg
Compatibility Notations
Compatibility lemmas. These could be notations,
but scope information would be lost.
Notation SYM1 lem := (
fun n =>
eq_sym (
lem n)).
Notation SYM2 lem := (
fun n m =>
eq_sym (
lem n m)).
Notation SYM3 lem := (
fun n m p =>
eq_sym (
lem n m p)).
Lemma Zplus_assoc_reverse :
forall n m p,
n+m+p = n+(m+p).
Lemma Zplus_succ_r_reverse :
forall n m,
Z.succ (
n+m)
= n+Z.succ m.
Notation Zplus_succ_r :=
Zplus_succ_r_reverse (
only parsing).
Lemma Zplus_0_r_reverse :
forall n,
n = n + 0.
Lemma Zplus_eq_compat :
forall n m p q,
n=m ->
p=q ->
n+p=m+q.
Lemma Zsucc_pred :
forall n,
n = Z.succ (
Z.pred n).
Lemma Zpred_succ :
forall n,
n = Z.pred (
Z.succ n).
Lemma Zsucc_eq_compat :
forall n m,
n = m ->
Z.succ n = Z.succ m.
Lemma Zminus_0_l_reverse :
forall n,
n = n - 0.
Lemma Zminus_diag_reverse :
forall n, 0
= n-n.
Lemma Zminus_succ_l :
forall n m,
Z.succ (
n - m)
= Z.succ n - m.
Lemma Zplus_minus_eq :
forall n m p,
n = m + p ->
p = n - m.
Lemma Zplus_minus :
forall n m,
n + (m - n) = m.
Lemma Zminus_plus_simpl_l :
forall n m p,
p + n - (p + m) = n - m.
Lemma Zminus_plus_simpl_l_reverse :
forall n m p,
n - m = p + n - (p + m).
Lemma Zminus_plus_simpl_r :
forall n m p,
n + p - (m + p) = n - m.
Lemma Zeq_minus :
forall n m,
n = m ->
n - m = 0.
Lemma Zminus_eq :
forall n m,
n - m = 0 ->
n = m.
Lemma Zmult_0_r_reverse :
forall n, 0
= n * 0.
Lemma Zmult_assoc_reverse :
forall n m p,
n * m * p = n * (m * p).
Lemma Zmult_integral :
forall n m,
n * m = 0 ->
n = 0
\/ m = 0.
Lemma Zmult_integral_l :
forall n m,
n <> 0 ->
m * n = 0 ->
m = 0.
Lemma Zopp_mult_distr_l :
forall n m,
- (n * m) = - n * m.
Lemma Zopp_mult_distr_r :
forall n m,
- (n * m) = n * - m.
Lemma Zmult_minus_distr_l :
forall n m p,
p * (n - m) = p * n - p * m.
Lemma Zmult_succ_r_reverse :
forall n m,
n * m + n = n * Z.succ m.
Lemma Zmult_succ_l_reverse :
forall n m,
n * m + m = Z.succ n * m.
Lemma Zpos_eq :
forall p q,
p = q ->
Z.pos p = Z.pos q.
Lemma Zpos_eq_iff :
forall p q,
p = q <-> Z.pos p = Z.pos q.
Hint Immediate Zsucc_pred:
zarith.
Obsolete stuff