Library Coq.PArith.BinPos
Binary positive numbers, operations and properties
Initial development by Pierre Crégut, CNET, Lannion, France
The type
positive and its constructors
xI and
xO and
xH
are now defined in
BinNums.v
Local Open Scope positive_scope.
LocalLocal
Every definitions and early properties about positive numbers
are placed in a module Pos for qualification purpose.
Definitions of operations, now in a separate file
In functor applications that follow, we only inline t and eq
Properties of operations over positive numbers
Decidability of equality on binary positive numbers
Properties of successor on binary positive numbers
Specification of xI in term of succ and xO
Successor and predecessor
Properties of addition on binary positive numbers
Specification of succ in term of add
Specification of add_carry
Permutation of add and succ
No neutral elements for addition
Commutation of addition and double
Peano induction and recursion on binary positive positive numbers
The Peano-like recursor function for
positive (due to Daniel Schepler)
Peano induction
Peano case analysis
Earlier, the Peano-like recursor was built and proved in a way due to
Conor McBride, see "The view from the left"
Properties of multiplication on binary positive numbers
One is neutral for multiplication
Right reduction properties for multiplication
Commutativity of multiplication
Distributivity of multiplication over addition
Associativity of multiplication
Successor and multiplication
Parity properties of multiplication
Simplification properties of multiplication
Inversion of multiplication
Properties of boolean comparisons
More about eqb
Properties of comparison on binary positive numbers
First, we express
compare_cont in term of
compare
From this general result, we now describe particular cases
of
compare_cont p q c = c´ :
- When c=Eq, this is directly compare
- When c<>Eq, we'll show first that c´<>Eq
- That leaves only 4 lemmas for c and c´ being Lt or Gt
We can express recursive equations for compare
Relation between compare and sub_mask
Alternative characterisation of strict order in term of addition
Basic facts about compare_cont
Basic facts about compare
More properties about compare and boolean comparisons,
including compare_spec and lt_irrefl and lt_eq_cases.
Facts about gt and ge
The predicates
lt and
le are now favored in the statements
of theorems, the use of
gt and
ge is hence not recommended.
We provide here the bare minimal results to related them with
lt and
le.
Comparison and the successor
1 is the least positive number
Comparison and multiplication
Properties of subtraction on binary positive numbers
Properties of subtraction without underflow
Recursive equations for sub
Properties of subtraction with underflow
Results concerning size and size_nat
Properties of min and max
First, the specification
We hence obtain all the generic properties of min and max.
Minimum, maximum and constant one
Minimum, maximum and operations (consequences of monotonicity)
Results concerning iter_op
Results about of_nat and of_succ_nat
Correctness proofs for the square root function
Correctness proofs for the gcd function
The first component of ggcd is gcd
The other components of ggcd are indeed the correct factors.
We can use this fact to prove a part of the gcd correctness
We now prove directly that gcd is the greatest amongst common divisors
As a consequence, the rests after division by gcd are relatively prime
Exportation of notations
Infix "+" :=
Pos.add :
positive_scope.
Infix "-" :=
Pos.sub :
positive_scope.
Infix "*" :=
Pos.mul :
positive_scope.
Infix "^" :=
Pos.pow :
positive_scope.
Infix "?=" :=
Pos.compare (
at level 70,
no associativity) :
positive_scope.
Infix "=?" :=
Pos.eqb (
at level 70,
no associativity) :
positive_scope.
Infix "<=?" :=
Pos.leb (
at level 70,
no associativity) :
positive_scope.
Infix "<?" :=
Pos.ltb (
at level 70,
no associativity) :
positive_scope.
Infix "<=" :=
Pos.le :
positive_scope.
Infix "<" :=
Pos.lt :
positive_scope.
Infix ">=" :=
Pos.ge :
positive_scope.
Infix ">" :=
Pos.gt :
positive_scope.
Notation "x <= y <= z" := (
x <= y /\ y <= z) :
positive_scope.
Notation "x <= y < z" := (
x <= y /\ y < z) :
positive_scope.
Notation "x < y < z" := (
x < y /\ y < z) :
positive_scope.
Notation "x < y <= z" := (
x < y /\ y <= z) :
positive_scope.
Notation "( p | q )" := (
Pos.divide p q) (
at level 0) :
positive_scope.
Compatibility notations
More complex compatibility facts, expressed as lemmas
(to preserve scopes for instance)
Discontinued results of little interest and little/zero use
in user contributions:
Pplus_carry_no_neutral
Pplus_carry_pred_eq_plus
Pcompare_not_Eq
Pcompare_Lt_Lt
Pcompare_Lt_eq_Lt
Pcompare_Gt_Gt
Pcompare_Gt_eq_Gt
Psucc_lt_compat
Psucc_le_compat
ZC3
Pcompare_p_Sq
Pminus_mask_carry_diag
Pminus_mask_IsNeg
ZL10
ZL11
double_eq_zero_inversion
double_plus_one_zero_discr
double_plus_one_eq_one_inversion
double_eq_one_discr
Infix "/" := Pdiv2 : positive_scope.
Old stuff, to remove someday
Incompatibilities :
- (_ ?= _)%positive expects no arg now, and designates Pos.compare
which is convertible but syntactically distinct to
Pos.compare_cont .. .. Eq.
- Pmult_nat cannot be unfolded (unfold Pos.iter_op instead).