Debian Codegraph @

theories/Corelib/Numbers/BinNums.v

raw
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 (** * Binary Numerical Datatypes *)
12
13 Set Implicit Arguments.
14
15 (** [positive] is a datatype representing the strictly positive integers
16 in a binary way. Starting from 1 (represented by [xH]), one can
17 add a new least significant digit via [xO] (digit 0) or [xI] (digit 1).
18 Numbers in [positive] will also be denoted using a decimal notation;
19 e.g. [6%positive] will abbreviate [xO (xI xH)] *)
20
21 Inductive positive : Set :=
22 | xI : positive -> positive
23 | xO : positive -> positive
24 | xH : positive.
25
26 Declare Scope positive_scope.
27 Delimit Scope positive_scope with positive.
28 Bind Scope positive_scope with positive.
29 Arguments xO _%_positive.
30 Arguments xI _%_positive.
31
32 Declare Scope hex_positive_scope.
33 Delimit Scope hex_positive_scope with xpositive.
34
35 Register positive as num.pos.type.
36 Register xI as num.pos.xI.
37 Register xO as num.pos.xO.
38 Register xH as num.pos.xH.
39
40 (** [N] is a datatype representing natural numbers in a binary way,
41 by extending the [positive] datatype with a zero.
42 Numbers in [N] will also be denoted using a decimal notation;
43 e.g. [6%N] will abbreviate [Npos (xO (xI xH))] *)
44
45 Inductive N : Set :=
46 | N0 : N
47 | Npos : positive -> N.
48
49 Declare Scope N_scope.
50 Delimit Scope N_scope with N.
51 Bind Scope N_scope with N.
52 Arguments Npos _%_positive.
53
54 Declare Scope hex_N_scope.
55 Delimit Scope hex_N_scope with xN.
56
57 Register N as num.N.type.
58 Register N0 as num.N.N0.
59 Register Npos as num.N.Npos.
60
61 (** [Z] is a datatype representing the integers in a binary way.
62 An integer is either zero or a strictly positive number
63 (coded as a [positive]) or a strictly negative number
64 (whose opposite is stored as a [positive] value).
65 Numbers in [Z] will also be denoted using a decimal notation;
66 e.g. [(-6)%Z] will abbreviate [Zneg (xO (xI xH))] *)
67
68 Inductive Z : Set :=
69 | Z0 : Z
70 | Zpos : positive -> Z
71 | Zneg : positive -> Z.
72
73 Declare Scope Z_scope.
74 Delimit Scope Z_scope with Z.
75 Bind Scope Z_scope with Z.
76 Arguments Zpos _%_positive.
77 Arguments Zneg _%_positive.
78
79 Declare Scope hex_Z_scope.
80 Delimit Scope hex_Z_scope with xZ.
81
82 Register Z as num.Z.type.
83 Register Z0 as num.Z.Z0.
84 Register Zpos as num.Z.Zpos.
85 Register Zneg as num.Z.Zneg.