Built with Alectryon, running Coq+SerAPI v8.19.0+0.19.3. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑Ctrl+↓ to navigate, Ctrl+🖱️ to focus. On Mac, use ⌘ instead of Ctrl.
(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \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) *)(************************************************************************)(************************************************************************)(* This file has been modified for use in the HoTT library *)(************************************************************************)
[Loading ML file number_string_notation_plugin.cmxs (using legacy method) ... done]
(** * Decimal numbers *)(** These numbers coded in base 10 will be used for parsing and printing other Coq numeral datatypes in an human-readable way. See the [Numeral Notation] command. We represent numbers in base 10 as lists of decimal digits, in big-endian order (most significant digit comes first). *)(** Unsigned integers are just lists of digits. For instance, ten is (D1 (D0 Nil)) *)Inductiveuint : Type0 :=
| Nil
| D0 (_:uint)
| D1 (_:uint)
| D2 (_:uint)
| D3 (_:uint)
| D4 (_:uint)
| D5 (_:uint)
| D6 (_:uint)
| D7 (_:uint)
| D8 (_:uint)
| D9 (_:uint).(** [Nil] is the number terminator. Taken alone, it behaves as zero, but rather use [D0 Nil] instead, since this form will be denoted as [0], while [Nil] will be printed as [Nil]. *)Notationzero := (D0 Nil).(** For signed integers, we use two constructors [Pos] and [Neg]. *)Variantint : Type0 := Pos (d:uint) | Neg (d:uint).(** For decimal numbers, we use two constructors [Decimal] and [DecimalExp], depending on whether or not they are given with an exponent (e.g., 1.02e+01). [i] is the integral part while [f] is the fractional part (beware that leading zeroes do matter). *)Variantdecimal : Type0 :=
| Decimal (i:int) (f:uint)
| DecimalExp (i:int) (f:uint) (e:int).Declare Scope dec_uint_scope.Delimit Scope dec_uint_scope with uint.Bind Scope dec_uint_scope with uint.Declare Scope dec_int_scope.Delimit Scope dec_int_scope with int.Bind Scope dec_int_scope with int.Register uint as num.uint.type.Register int as num.int.type.Register decimal as num.decimal.type.Fixpointnb_digitsd :=
match d with
| Nil => O
| D0 d | D1 d | D2 d | D3 d | D4 d | D5 d | D6 d | D7 d | D8 d | D9 d =>
S (nb_digits d)
end.(** This representation favors simplicity over canonicity. For normalizing numbers, we need to remove head zero digits, and choose our canonical representation of 0 (here [D0 Nil] for unsigned numbers and [Pos (D0 Nil)] for signed numbers). *)(** [nzhead] removes all head zero digits *)Fixpointnzheadd :=
match d with
| D0 d => nzhead d
| _ => d
end.(** [unorm] : normalization of unsigned integers *)Definitionunormd :=
match nzhead d with
| Nil => zero
| d => d
end.(** [norm] : normalization of signed integers *)Definitionnormd :=
match d with
| Pos d => Pos (unorm d)
| Neg d =>
match nzhead d with
| Nil => Pos zero
| d => Neg d
endend.(** A few easy operations. For more advanced computations, use the conversions with other Coq numeral datatypes (e.g. Z) and the operations on them. *)Definitionopp (d:int) :=
match d with
| Pos d => Neg d
| Neg d => Pos d
end.(** For conversions with binary numbers, it is easier to operate on little-endian numbers. *)Fixpointrevapp (dd' : uint) :=
match d with
| Nil => d'
| D0 d => revapp d (D0 d')
| D1 d => revapp d (D1 d')
| D2 d => revapp d (D2 d')
| D3 d => revapp d (D3 d')
| D4 d => revapp d (D4 d')
| D5 d => revapp d (D5 d')
| D6 d => revapp d (D6 d')
| D7 d => revapp d (D7 d')
| D8 d => revapp d (D8 d')
| D9 d => revapp d (D9 d')
end.Definitionrevd := revapp d Nil.Definitionappdd' := revapp (rev d) d'.Definitionapp_intd1d2 :=
match d1 with Pos d1 => Pos (app d1 d2) | Neg d1 => Neg (app d1 d2) end.(** [nztail] removes all trailing zero digits and return both the result and the number of removed digits. *)Definitionnztaild :=
let fixauxd_rev :=
match d_rev with
| D0 d_rev => let (r, n) := aux d_rev in pair r (S n)
| _ => pair d_rev O
endinlet (r, n) := aux (rev d) in pair (rev r) n.Definitionnztail_intd :=
match d with
| Pos d => let (r, n) := nztail d in pair (Pos r) n
| Neg d => let (r, n) := nztail d in pair (Neg r) n
end.ModuleLittle.(** Successor of little-endian numbers *)Fixpointsuccd :=
match d with
| Nil => D1 Nil
| D0 d => D1 d
| D1 d => D2 d
| D2 d => D3 d
| D3 d => D4 d
| D4 d => D5 d
| D5 d => D6 d
| D6 d => D7 d
| D7 d => D8 d
| D8 d => D9 d
| D9 d => D0 (succ d)
end.(** Doubling little-endian numbers *)Fixpointdoubled :=
match d with
| Nil => Nil
| D0 d => D0 (double d)
| D1 d => D2 (double d)
| D2 d => D4 (double d)
| D3 d => D6 (double d)
| D4 d => D8 (double d)
| D5 d => D0 (succ_double d)
| D6 d => D2 (succ_double d)
| D7 d => D4 (succ_double d)
| D8 d => D6 (succ_double d)
| D9 d => D8 (succ_double d)
endwith succ_double d :=
match d with
| Nil => D1 Nil
| D0 d => D1 (double d)
| D1 d => D3 (double d)
| D2 d => D5 (double d)
| D3 d => D7 (double d)
| D4 d => D9 (double d)
| D5 d => D1 (succ_double d)
| D6 d => D3 (succ_double d)
| D7 d => D5 (succ_double d)
| D8 d => D7 (succ_double d)
| D9 d => D9 (succ_double d)
end.EndLittle.(** Pseudo-conversion functions used when declaring Numeral Notations on [uint] and [int]. *)Definitionuint_of_uint (i:uint) := i.Definitionint_of_int (i:int) := i.