Built with Alectryon, running Coq+SerAPI v8.10.0+0.7.0. Coq sources are in this panel; goals and messages will appear in the other. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑ Ctrl+↓ to navigate, Ctrl+🖱️ to focus.
(************************************************************************)
(* * 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) *)
(************************************************************************)
Require Import Decimal DecimalFacts DecimalPos PArith NArith. Module Unsigned.n:NN.of_uint (N.to_uint n) = nn:NN.of_uint (N.to_uint n) = nN.of_uint (N.to_uint 0) = 0%Np:positiveN.of_uint (N.to_uint (N.pos p)) = N.pos preflexivity.N.of_uint (N.to_uint 0) = 0%Napply DecimalPos.Unsigned.of_to. Qed.p:positiveN.of_uint (N.to_uint (N.pos p)) = N.pos pd:uintN.to_uint (N.of_uint d) = unorm dexact (DecimalPos.Unsigned.to_of d). Qed.d:uintN.to_uint (N.of_uint d) = unorm dn, n':NN.to_uint n = N.to_uint n' -> n = n'n, n':NN.to_uint n = N.to_uint n' -> n = n'now rewrite <- (of_to n), <- (of_to n'), E. Qed.n, n':NE:N.to_uint n = N.to_uint n'n = n'd:uintexists p : N, N.to_uint p = unorm dd:uintexists p : N, N.to_uint p = unorm dapply to_of. Qed.d:uintN.to_uint (N.of_uint d) = unorm dd:uintN.of_uint (unorm d) = N.of_uint dnow induction d. Qed.d:uintN.of_uint (unorm d) = N.of_uint dd, d':uintN.of_uint d = N.of_uint d' -> unorm d = unorm d'd, d':uintN.of_uint d = N.of_uint d' -> unorm d = unorm d'd, d':uintH:N.of_uint d = N.of_uint d'unorm d = unorm d'now f_equal. Qed.d, d':uintH:N.of_uint d = N.of_uint d'N.to_uint (N.of_uint d) = N.to_uint (N.of_uint d')d, d':uintN.of_uint d = N.of_uint d' <-> unorm d = unorm d'd, d':uintN.of_uint d = N.of_uint d' <-> unorm d = unorm d'd, d':uintN.of_uint d = N.of_uint d' -> unorm d = unorm d'd, d':uintunorm d = unorm d' -> N.of_uint d = N.of_uint d'd, d':uintunorm d = unorm d' -> N.of_uint d = N.of_uint d'd, d':uintE:unorm d = unorm d'N.of_uint d = N.of_uint d'apply of_uint_norm. Qed. End Unsigned.d, d':uintE:unorm d = unorm d'N.of_uint (unorm d') = N.of_uint d'
Conversion from/to signed decimal numbers
Module Signed.n:NN.of_int (N.to_int n) = Some nn:NN.of_int (N.to_int n) = Some nn:NSome (Pos.of_uint (unorm (N.to_uint n))) = Some nn:NPos.of_uint (unorm (N.to_uint n)) = napply Unsigned.of_to. Qed.n:NN.of_uint (N.to_uint n) = nd:intn:NN.of_int d = Some n -> N.to_int n = norm dd:intn:NN.of_int d = Some n -> N.to_int n = norm dd:intn:Nmatch norm d with | Pos d0 => Some (Pos.of_uint d0) | Neg _ => None end = Some n -> N.to_int n = norm dd:intd0:uintHd:norm d = Pos d0N.to_int (Pos.of_uint d0) = Pos d0d:intd0:uintHd:norm d = Pos d0Pos (N.to_uint (Pos.of_uint d0)) = Pos d0d:intd0:uintHd:norm d = Pos d0Pos (unorm d0) = Pos d0d:intd0:uintHd:norm d = Pos d0unorm d0 = d0d, d0:uintPos (unorm d) = Pos d0 -> unorm d0 = d0d, d0:uintmatch nzhead d with | Nil => 0%int | D0 u => Neg (D0 u) | D1 u => Neg (D1 u) | D2 u => Neg (D2 u) | D3 u => Neg (D3 u) | D4 u => Neg (D4 u) | D5 u => Neg (D5 u) | D6 u => Neg (D6 u) | D7 u => Neg (D7 u) | D8 u => Neg (D8 u) | D9 u => Neg (D9 u) end = Pos d0 -> unorm d0 = d0d, d0:uintPos (unorm d) = Pos d0 -> unorm d0 = d0apply unorm_invol.d:uintunorm (unorm d) = unorm ddestruct (nzhead d); now intros [= <-]. Qed.d, d0:uintmatch nzhead d with | Nil => 0%int | D0 u => Neg (D0 u) | D1 u => Neg (D1 u) | D2 u => Neg (D2 u) | D3 u => Neg (D3 u) | D4 u => Neg (D4 u) | D5 u => Neg (D5 u) | D6 u => Neg (D6 u) | D7 u => Neg (D7 u) | D8 u => Neg (D8 u) | D9 u => Neg (D9 u) end = Pos d0 -> unorm d0 = d0n, n':NN.to_int n = N.to_int n' -> n = n'n, n':NN.to_int n = N.to_int n' -> n = n'n, n':NE:N.to_int n = N.to_int n'n = n'n, n':NE:N.to_int n = N.to_int n'Some n = Some n'n, n':NE:N.to_int n = N.to_int n'E':Some n = Some n'n = n'now rewrite <- (of_to n), <- (of_to n'), E.n, n':NE:N.to_int n = N.to_int n'Some n = Some n'now injection E'. Qed.n, n':NE:N.to_int n = N.to_int n'E':Some n = Some n'n = n'd:uintexists n : N, N.to_int n = norm (Pos d)d:uintexists n : N, N.to_int n = norm (Pos d)d:uintN.to_int (N.of_uint d) = norm (Pos d)now rewrite Unsigned.to_of. Qed.d:uintPos (N.to_uint (N.of_uint d)) = norm (Pos d)d:intN.of_int (norm d) = N.of_int dd:intN.of_int (norm d) = N.of_int dnow rewrite norm_invol. Qed.d:intmatch norm (norm d) with | Pos d0 => Some (Pos.of_uint d0) | Neg _ => None end = match norm d with | Pos d0 => Some (Pos.of_uint d0) | Neg _ => None endd, d':uintN.of_int (Pos d) = N.of_int (Pos d') -> unorm d = unorm d'd, d':uintN.of_int (Pos d) = N.of_int (Pos d') -> unorm d = unorm d'd, d':uintmatch norm (Pos d) with | Pos d0 => Some (Pos.of_uint d0) | Neg _ => None end = match norm (Pos d') with | Pos d0 => Some (Pos.of_uint d0) | Neg _ => None end -> unorm d = unorm d'd, d':uintSome (Pos.of_uint (unorm d)) = Some (Pos.of_uint (unorm d')) -> unorm d = unorm d'd, d':uintH:Pos.of_uint (unorm d) = Pos.of_uint (unorm d')unorm d = unorm d'd, d':uintH:Pos.of_uint (unorm d) = Pos.of_uint (unorm d')N.of_uint d = N.of_uint d'now rewrite <- Unsigned.of_uint_norm, H, Unsigned.of_uint_norm. Qed. End Signed.d, d':uintH:N.of_uint (unorm d) = N.of_uint (unorm d')N.of_uint d = N.of_uint d'