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 PArith NArith. Module Unsigned. Local Open Scope N.
A direct version of of_little_uint
Fixpoint of_lu (d:uint) : N := match d with | Nil => 0 | D0 d => 10 * of_lu d | D1 d => 1 + 10 * of_lu d | D2 d => 2 + 10 * of_lu d | D3 d => 3 + 10 * of_lu d | D4 d => 4 + 10 * of_lu d | D5 d => 5 + 10 * of_lu d | D6 d => 6 + 10 * of_lu d | D7 d => 7 + 10 * of_lu d | D8 d => 8 + 10 * of_lu d | D9 d => 9 + 10 * of_lu d end. Definition hd d := match d with | Nil => 0 | D0 _ => 0 | D1 _ => 1 | D2 _ => 2 | D3 _ => 3 | D4 _ => 4 | D5 _ => 5 | D6 _ => 6 | D7 _ => 7 | D8 _ => 8 | D9 _ => 9 end. Definition tl d := match d with | Nil => d | D0 d | D1 d | D2 d | D3 d | D4 d | D5 d | D6 d | D7 d | D8 d | D9 d => d end.d:uintof_lu d = hd d + 10 * of_lu (tl d)induction d; simpl; trivial. Qed. Ltac simpl_of_lu := match goal with | |- context [ of_lu (?f ?x) ] => rewrite (of_lu_eqn (f x)); simpl hd; simpl tl end. Fixpoint usize (d:uint) : N := match d with | Nil => 0 | D0 d => N.succ (usize d) | D1 d => N.succ (usize d) | D2 d => N.succ (usize d) | D3 d => N.succ (usize d) | D4 d => N.succ (usize d) | D5 d => N.succ (usize d) | D6 d => N.succ (usize d) | D7 d => N.succ (usize d) | D8 d => N.succ (usize d) | D9 d => N.succ (usize d) end.d:uintof_lu d = hd d + 10 * of_lu (tl d)d, d':uintof_lu (revapp d d') = of_lu (rev d) + of_lu d' * 10 ^ usize dd, d':uintof_lu (revapp d d') = of_lu (rev d) + of_lu d' * 10 ^ usize dinduction d; simpl; intro d'; [ now rewrite N.mul_1_r | .. ]; unfold rev; simpl revapp; rewrite 2 IHd; rewrite <- N.add_assoc; f_equal; simpl_of_lu; simpl of_lu; rewrite N.pow_succ_r'; ring. Qed. Definition Nadd n p := match n with | N0 => p | Npos p0 => (p0+p)%positive end.d:uintforall d' : uint, of_lu (revapp d d') = of_lu (rev d) + of_lu d' * 10 ^ usize dn:Np, q:positiveN.pos (Nadd n (p * q)) = n + N.pos p * N.pos qnow destruct n. Qed.n:Np, q:positiveN.pos (Nadd n (p * q)) = n + N.pos p * N.pos qd:uintacc:positived <> Nil -> Pos.of_uint_acc d acc = Pos.of_uint_acc (tl d) (Nadd (hd d) (10 * acc))d:uintacc:positived <> Nil -> Pos.of_uint_acc d acc = Pos.of_uint_acc (tl d) (Nadd (hd d) (10 * acc))now destruct 1. Qed.acc:positiveNil <> Nil -> acc = ((acc + acc~0~0)~0)%positived:uintacc:positiveN.pos (Pos.of_uint_acc d acc) = of_lu (rev d) + N.pos acc * 10 ^ usize dd:uintacc:positiveN.pos (Pos.of_uint_acc d acc) = of_lu (rev d) + N.pos acc * 10 ^ usize dinduction d; intros; simpl usize; [ simpl; now rewrite Pos.mul_1_r | .. ]; rewrite N.pow_succ_r'; unfold rev; simpl revapp; try rewrite of_lu_revapp; simpl of_lu; rewrite of_uint_acc_eqn by easy; simpl tl; simpl hd; rewrite IHd, Nadd_simpl; ring. Qed.d:uintforall acc : positive, N.pos (Pos.of_uint_acc d acc) = of_lu (rev d) + N.pos acc * 10 ^ usize dd:uintPos.of_uint d = of_lu (rev d)d:uintPos.of_uint d = of_lu (rev d)d:uintIHd:Pos.of_uint d = of_lu (rev d)Pos.of_uint d = of_lu (rev d) + 0 * 10 ^ usize dring. Qed.d:uintIHd:Pos.of_uint d = of_lu (rev d)of_lu (rev d) = of_lu (rev d) + 0 * 10 ^ usize dd:uintPos.of_uint (rev d) = of_lu dd:uintPos.of_uint (rev d) = of_lu dnow rewrite rev_rev. Qed.d:uintof_lu (rev (rev d)) = of_lu dd:uintof_lu (Little.double d) = N.double (of_lu d) /\ of_lu (Little.succ_double d) = N.succ_double (of_lu d)d:uintof_lu (Little.double d) = N.double (of_lu d) /\ of_lu (Little.succ_double d) = N.succ_double (of_lu d)induction d; try destruct IHd as (IH1,IH2); simpl Little.double; simpl Little.succ_double; repeat (simpl_of_lu; rewrite ?IH1, ?IH2); split; reflexivity || ring. Qed.d:uintof_lu (Little.double d) = 2 * of_lu d /\ of_lu (Little.succ_double d) = 2 * of_lu d + 1d:uintof_lu (Little.double d) = N.double (of_lu d)apply of_lu_double_gen. Qed.d:uintof_lu (Little.double d) = N.double (of_lu d)d:uintof_lu (Little.succ_double d) = N.succ_double (of_lu d)apply of_lu_double_gen. Qed.d:uintof_lu (Little.succ_double d) = N.succ_double (of_lu d)
First bijection result
p:positivePos.of_uint (Pos.to_uint p) = N.pos pp:positivePos.of_uint (Pos.to_uint p) = N.pos pp:positivePos.of_uint (rev (Pos.to_little_uint p)) = N.pos pp:positiveof_lu (Pos.to_little_uint p) = N.pos pp:positiveIHp:of_lu (Pos.to_little_uint p) = N.pos pof_lu (Little.succ_double (Pos.to_little_uint p)) = N.pos p~1p:positiveIHp:of_lu (Pos.to_little_uint p) = N.pos pof_lu (Little.double (Pos.to_little_uint p)) = N.pos p~0now rewrite of_lu_succ_double, IHp.p:positiveIHp:of_lu (Pos.to_little_uint p) = N.pos pof_lu (Little.succ_double (Pos.to_little_uint p)) = N.pos p~1now rewrite of_lu_double, IHp. Qed.p:positiveIHp:of_lu (Pos.to_little_uint p) = N.pos pof_lu (Little.double (Pos.to_little_uint p)) = N.pos p~0
The other direction
Definition to_lu n := match n with | N0 => Decimal.zero | Npos p => Pos.to_little_uint p end.d:uintLittle.succ_double d = Little.succ (Little.double d)now induction d. Qed.d:uintLittle.succ_double d = Little.succ (Little.double d)d:uintLittle.double (Little.succ d) = Little.succ (Little.succ_double d)induction d; simpl; f_equal; auto using succ_double_alt. Qed.d:uintLittle.double (Little.succ d) = Little.succ (Little.succ_double d)n:Nto_lu (N.succ n) = Little.succ (to_lu n)n:Nto_lu (N.succ n) = Little.succ (to_lu n)induction p; simpl; rewrite ?IHp; auto using succ_double_alt, double_succ. Qed.p:positivePos.to_little_uint (Pos.succ p) = Little.succ (Pos.to_little_uint p)n:natA:Typef:A -> Ai:ANat.iter (S n) f i = f (Nat.iter n f i)reflexivity. Qed.n:natA:Typef:A -> Ai:ANat.iter (S n) f i = f (Nat.iter n f i)A:Typef:A -> Ai:ANat.iter 0 f i = ireflexivity. Qed.A:Typef:A -> Ai:ANat.iter 0 f i = ip:positiveto_lu (10 * N.pos p) = D0 (to_lu (N.pos p))p:positiveto_lu (10 * N.pos p) = D0 (to_lu (N.pos p))to_lu (10 * 1) = D0 (to_lu 1)p:positiveIHp:to_lu (10 * N.pos p) = D0 (to_lu (N.pos p))to_lu (10 * N.pos (Pos.succ p)) = D0 (to_lu (N.pos (Pos.succ p)))trivial.to_lu (10 * 1) = D0 (to_lu 1)p:positiveIHp:to_lu (10 * N.pos p) = D0 (to_lu (N.pos p))to_lu (10 * N.pos (Pos.succ p)) = D0 (to_lu (N.pos (Pos.succ p)))p:positiveIHp:to_lu (10 * N.pos p) = D0 (to_lu (N.pos p))to_lu (10 * N.succ (N.pos p)) = D0 (to_lu (N.succ (N.pos p)))p:positiveIHp:to_lu (10 * N.pos p) = D0 (to_lu (N.pos p))to_lu (10 * N.pos p + 10) = D0 (to_lu (N.succ (N.pos p)))p:positiveIHp:to_lu (10 * N.pos p) = D0 (to_lu (N.pos p))to_lu (10 * N.pos p + Nat.iter 10 N.succ 0) = D0 (to_lu (N.succ (N.pos p)))p:positiveIHp:to_lu (10 * N.pos p) = D0 (to_lu (N.pos p))to_lu (10 * N.pos p + N.succ (N.succ (N.succ (N.succ (N.succ (N.succ (N.succ (N.succ (N.succ (N.succ 0)))))))))) = D0 (to_lu (N.succ (N.pos p)))destruct (to_lu (N.pos p)); simpl; auto. Qed.p:positiveIHp:to_lu (10 * N.pos p) = D0 (to_lu (N.pos p))Little.succ (Little.succ (Little.succ (Little.succ (Little.succ (Little.succ (Little.succ (Little.succ (Little.succ (Little.succ (D0 (to_lu (N.pos p)))))))))))) = D0 (Little.succ (to_lu (N.pos p)))d:uintof_lu d = 0 <-> nztail d = Nild:uintof_lu d = 0 <-> nztail d = Nild:uintIHd:of_lu d = 0 <-> nztail d = Nil0 + 10 * of_lu d = 0 -> nztail (D0 d) = Nild:uintIHd:of_lu d = 0 <-> nztail d = Nilnztail (D0 d) = Nil -> 0 + 10 * of_lu d = 0d:uintIHd:of_lu d = 0 <-> nztail d = Nil0 + 10 * of_lu d = 0 -> nztail (D0 d) = Nild:uintIHd:of_lu d = 0 <-> nztail d = Nil10 * of_lu d = 0 -> nztail (D0 d) = Nild:uintIHd:of_lu d = 0 <-> nztail d = NilH:10 * of_lu d = 0nztail (D0 d) = Nild:uintIHd:of_lu d = 0 <-> nztail d = NilH:of_lu d = 0nztail (D0 d) = Nild:uintIHd:of_lu d = 0 <-> nztail d = NilH:nztail d = Nilnztail (D0 d) = Nilnow rewrite H.d:uintIHd:of_lu d = 0 <-> nztail d = NilH:nztail d = Nilmatch nztail d with | Nil => Nil | D0 u => D0 (D0 u) | D1 u => D0 (D1 u) | D2 u => D0 (D2 u) | D3 u => D0 (D3 u) | D4 u => D0 (D4 u) | D5 u => D0 (D5 u) | D6 u => D0 (D6 u) | D7 u => D0 (D7 u) | D8 u => D0 (D8 u) | D9 u => D0 (D9 u) end = Nild:uintIHd:of_lu d = 0 <-> nztail d = Nilnztail (D0 d) = Nil -> 0 + 10 * of_lu d = 0d:uintIHd:of_lu d = 0 <-> nztail d = Nilmatch nztail d with | Nil => Nil | D0 u => D0 (D0 u) | D1 u => D0 (D1 u) | D2 u => D0 (D2 u) | D3 u => D0 (D3 u) | D4 u => D0 (D4 u) | D5 u => D0 (D5 u) | D6 u => D0 (D6 u) | D7 u => D0 (D7 u) | D8 u => D0 (D8 u) | D9 u => D0 (D9 u) end = Nil -> match of_lu d with | 0 => 0 | N.pos q => N.pos (q + q~0~0)~0 end = 0now destruct IHd as [_ ->]. Qed.d:uintIHd:of_lu d = 0 <-> Nil = NilNil = Nil -> match of_lu d with | 0 => 0 | N.pos q => N.pos (q + q~0~0)~0 end = 0d:uintto_lu (of_lu d) = lnorm d -> to_lu (10 * of_lu d) = lnorm (D0 d)d:uintto_lu (of_lu d) = lnorm d -> to_lu (10 * of_lu d) = lnorm (D0 d)d:uintIH:to_lu (of_lu d) = lnorm dto_lu (10 * of_lu d) = lnorm (D0 d)d:uintIH:to_lu (of_lu d) = lnorm dH:of_lu d = 0to_lu (10 * of_lu d) = lnorm (D0 d)d:uintIH:to_lu (of_lu d) = lnorm dH:of_lu d <> 0to_lu (10 * of_lu d) = lnorm (D0 d)d:uintIH:to_lu (of_lu d) = lnorm dH:of_lu d = 0to_lu (10 * of_lu d) = lnorm (D0 d)d:uintIH:to_lu (of_lu d) = lnorm dH:of_lu d = 0to_lu (10 * 0) = lnorm (D0 d)d:uintIH:to_lu (of_lu d) = lnorm dH:of_lu d = 00%uint = lnorm (D0 d)d:uintIH:to_lu (of_lu d) = lnorm dH:nztail d = Nil0%uint = lnorm (D0 d)d:uintIH:to_lu (of_lu d) = lnorm dH:nztail d = Nil0%uint = match nztail (D0 d) with | Nil => 0%uint | D0 u => D0 u | D1 u => D1 u | D2 u => D2 u | D3 u => D3 u | D4 u => D4 u | D5 u => D5 u | D6 u => D6 u | D7 u => D7 u | D8 u => D8 u | D9 u => D9 u endnow rewrite H.d:uintIH:to_lu (of_lu d) = lnorm dH:nztail d = Nil0%uint = match match nztail d with | Nil => Nil | D0 u => D0 (D0 u) | D1 u => D0 (D1 u) | D2 u => D0 (D2 u) | D3 u => D0 (D3 u) | D4 u => D0 (D4 u) | D5 u => D0 (D5 u) | D6 u => D0 (D6 u) | D7 u => D0 (D7 u) | D8 u => D0 (D8 u) | D9 u => D0 (D9 u) end with | Nil => 0%uint | D0 u => D0 u | D1 u => D1 u | D2 u => D2 u | D3 u => D3 u | D4 u => D4 u | D5 u => D5 u | D6 u => D6 u | D7 u => D7 u | D8 u => D8 u | D9 u => D9 u endd:uintIH:to_lu (of_lu d) = lnorm dH:of_lu d <> 0to_lu (10 * of_lu d) = lnorm (D0 d)d:uintp:positiveEq:of_lu d = N.pos pIH:to_lu (N.pos p) = lnorm dH:N.pos p <> 0to_lu (10 * N.pos p) = lnorm (D0 d)d:uintp:positiveEq:of_lu d = N.pos pIH:to_lu (N.pos p) = lnorm dH:N.pos p <> 0D0 (to_lu (N.pos p)) = lnorm (D0 d)d:uintp:positiveEq:of_lu d = N.pos pIH:to_lu (N.pos p) = lnorm dH:N.pos p <> 0D0 (lnorm d) = lnorm (D0 d)d:uintp:positiveEq:of_lu d = N.pos pIH:to_lu (N.pos p) = lnorm dH:of_lu d <> 0D0 (lnorm d) = lnorm (D0 d)d:uintp:positiveEq:of_lu d = N.pos pIH:to_lu (N.pos p) = lnorm dH:nztail d <> NilD0 (lnorm d) = lnorm (D0 d)d:uintp:positiveEq:of_lu d = N.pos pIH:to_lu (N.pos p) = lnorm dH:nztail d <> NilD0 match nztail d with | Nil => 0 | D0 u => D0 u | D1 u => D1 u | D2 u => D2 u | D3 u => D3 u | D4 u => D4 u | D5 u => D5 u | D6 u => D6 u | D7 u => D7 u | D8 u => D8 u | D9 u => D9 u end = match nztail (D0 d) with | Nil => 0%uint | D0 u => D0 u | D1 u => D1 u | D2 u => D2 u | D3 u => D3 u | D4 u => D4 u | D5 u => D5 u | D6 u => D6 u | D7 u => D7 u | D8 u => D8 u | D9 u => D9 u endnow destruct (nztail d). Qed.d:uintp:positiveEq:of_lu d = N.pos pIH:to_lu (N.pos p) = lnorm dH:nztail d <> NilD0 match nztail d with | Nil => 0 | D0 u => D0 u | D1 u => D1 u | D2 u => D2 u | D3 u => D3 u | D4 u => D4 u | D5 u => D5 u | D6 u => D6 u | D7 u => D7 u | D8 u => D8 u | D9 u => D9 u end = match match nztail d with | Nil => Nil | D0 u => D0 (D0 u) | D1 u => D0 (D1 u) | D2 u => D0 (D2 u) | D3 u => D0 (D3 u) | D4 u => D0 (D4 u) | D5 u => D0 (D5 u) | D6 u => D0 (D6 u) | D7 u => D0 (D7 u) | D8 u => D0 (D8 u) | D9 u => D0 (D9 u) end with | Nil => 0%uint | D0 u => D0 u | D1 u => D1 u | D2 u => D2 u | D3 u => D3 u | D4 u => D4 u | D5 u => D5 u | D6 u => D6 u | D7 u => D7 u | D8 u => D8 u | D9 u => D9 u endn, m:Nn + m = Nat.iter (N.to_nat n) N.succ mn, m:Nn + m = Nat.iter (N.to_nat n) N.succ mm:N0 + m = Nat.iter (N.to_nat 0) N.succ mp:positivem:NN.pos p + m = Nat.iter (N.to_nat (N.pos p)) N.succ mp:positivem:NN.pos p + m = Nat.iter (N.to_nat (N.pos p)) N.succ mm:N1 + m = Nat.iter (N.to_nat 1) N.succ mp:positivem:NIHp:N.pos p + m = Nat.iter (N.to_nat (N.pos p)) N.succ mN.pos (Pos.succ p) + m = Nat.iter (N.to_nat (N.pos (Pos.succ p))) N.succ mnow rewrite N.add_1_l.m:N1 + m = Nat.iter (N.to_nat 1) N.succ mp:positivem:NIHp:N.pos p + m = Nat.iter (N.to_nat (N.pos p)) N.succ mN.pos (Pos.succ p) + m = Nat.iter (N.to_nat (N.pos (Pos.succ p))) N.succ mnow rewrite N.add_succ_l, IHp, N2Nat.inj_succ. Qed. Ltac simpl_to_nat := simpl N.to_nat; unfold Pos.to_nat; simpl Pos.iter_op.p:positivem:NIHp:N.pos p + m = Nat.iter (N.to_nat (N.pos p)) N.succ mN.succ (N.pos p) + m = Nat.iter (N.to_nat (N.succ (N.pos p))) N.succ md:uintto_lu (of_lu d) = lnorm dinduction d; [reflexivity|..]; simpl_of_lu; rewrite Nadd_alt; simpl_to_nat; rewrite ?nat_iter_S, nat_iter_0, ?to_lu_succ, to_of_lu_tenfold by assumption; unfold lnorm; simpl; destruct nztail; auto. Qed.d:uintto_lu (of_lu d) = lnorm d
Second bijection result
d:uintN.to_uint (Pos.of_uint d) = unorm dd:uintN.to_uint (Pos.of_uint d) = unorm dd:uintN.to_uint (of_lu (rev d)) = unorm dd:uintmatch of_lu (rev d) with | 0 => 0%uint | N.pos p => rev (Pos.to_little_uint p) end = unorm dd:uintH:of_lu (rev d) = 00%uint = unorm dd:uintp:positiveH:of_lu (rev d) = N.pos prev (Pos.to_little_uint p) = unorm dd:uintH:of_lu (rev d) = 00%uint = unorm dd:uintH:nztail (rev d) = Nil0%uint = unorm dd:uintH:nztail (rev d) = Nil0%uint = rev (lnorm (rev d))now rewrite H.d:uintH:nztail (rev d) = Nil0%uint = rev match nztail (rev d) with | Nil => 0 | D0 u => D0 u | D1 u => D1 u | D2 u => D2 u | D3 u => D3 u | D4 u => D4 u | D5 u => D5 u | D6 u => D6 u | D7 u => D7 u | D8 u => D8 u | D9 u => D9 u endd:uintp:positiveH:of_lu (rev d) = N.pos prev (Pos.to_little_uint p) = unorm dd:uintp:positiveH:of_lu (rev d) = N.pos prev (to_lu (N.pos p)) = unorm dd:uintp:positiveH:of_lu (rev d) = N.pos prev (to_lu (of_lu (rev d))) = unorm dapply rev_lnorm_rev. Qed.d:uintp:positiveH:of_lu (rev d) = N.pos prev (lnorm (rev d)) = unorm d
Some consequences
p:positivePos.to_uint p <> 0%uintp:positivePos.to_uint p <> 0%uintp:positiveE:Pos.to_uint p = 0%uintFalsenow rewrite E. Qed.p:positiveE:Pos.to_uint p = 0%uintPos.of_uint (Pos.to_uint p) = N.pos p -> Falsep:positivePos.to_uint p <> Nilp:positivePos.to_uint p <> Nilp:positiveE:Pos.to_uint p = NilFalsenow rewrite E. Qed.p:positiveE:Pos.to_uint p = NilPos.of_uint (Pos.to_uint p) = N.pos p -> Falsep, p':positivePos.to_uint p = Pos.to_uint p' -> p = p'p, p':positivePos.to_uint p = Pos.to_uint p' -> p = p'p, p':positiveE:Pos.to_uint p = Pos.to_uint p'p = p'p, p':positiveE:Pos.to_uint p = Pos.to_uint p'N.pos p = N.pos p'p, p':positiveE:Pos.to_uint p = Pos.to_uint p'E':N.pos p = N.pos p'p = p'now rewrite <- (of_to p), <- (of_to p'), E.p, p':positiveE:Pos.to_uint p = Pos.to_uint p'N.pos p = N.pos p'now injection E'. Qed.p, p':positiveE:Pos.to_uint p = Pos.to_uint p'E':N.pos p = N.pos p'p = p'd:uintunorm d <> 0%uint -> exists p : positive, Pos.to_uint p = unorm dd:uintunorm d <> 0%uint -> exists p : positive, Pos.to_uint p = unorm dd:uintH:unorm d <> 0%uintexists p : positive, Pos.to_uint p = unorm dd:uintH:unorm d <> 0%uintE:Pos.of_uint d = 0exists p : positive, Pos.to_uint p = unorm dd:uintH:unorm d <> 0%uintp:positiveE:Pos.of_uint d = N.pos pexists p0 : positive, Pos.to_uint p0 = unorm dd:uintH:unorm d <> 0%uintE:Pos.of_uint d = 0exists p : positive, Pos.to_uint p = unorm dd:uintE:Pos.of_uint d = 0unorm d = 0%uintnow rewrite E.d:uintE:Pos.of_uint d = 0N.to_uint (Pos.of_uint d) = unorm d -> unorm d = 0%uintd:uintH:unorm d <> 0%uintp:positiveE:Pos.of_uint d = N.pos pexists p0 : positive, Pos.to_uint p0 = unorm dd:uintH:unorm d <> 0%uintp:positiveE:Pos.of_uint d = N.pos pPos.to_uint p = unorm dnow rewrite E. Qed.d:uintH:unorm d <> 0%uintp:positiveE:Pos.of_uint d = N.pos pN.to_uint (Pos.of_uint d) = unorm d -> Pos.to_uint p = unorm dd:uintPos.of_uint (unorm d) = Pos.of_uint dnow induction d. Qed.d:uintPos.of_uint (unorm d) = Pos.of_uint dd, d':uintPos.of_uint d = Pos.of_uint d' -> unorm d = unorm d'd, d':uintPos.of_uint d = Pos.of_uint d' -> unorm d = unorm d'd, d':uintH:Pos.of_uint d = Pos.of_uint d'unorm d = unorm d'now f_equal. Qed.d, d':uintH:Pos.of_uint d = Pos.of_uint d'N.to_uint (Pos.of_uint d) = N.to_uint (Pos.of_uint d')d, d':uintPos.of_uint d = Pos.of_uint d' <-> unorm d = unorm d'd, d':uintPos.of_uint d = Pos.of_uint d' <-> unorm d = unorm d'd, d':uintPos.of_uint d = Pos.of_uint d' -> unorm d = unorm d'd, d':uintunorm d = unorm d' -> Pos.of_uint d = Pos.of_uint d'd, d':uintunorm d = unorm d' -> Pos.of_uint d = Pos.of_uint d'd, d':uintE:unorm d = unorm d'Pos.of_uint d = Pos.of_uint d'apply of_uint_norm. Qed. End Unsigned.d, d':uintE:unorm d = unorm d'Pos.of_uint (unorm d') = Pos.of_uint d'
Conversion from/to signed decimal numbers
Module Signed.p:positivePos.of_int (Pos.to_int p) = Some pp:positivePos.of_int (Pos.to_int p) = Some pnow rewrite Unsigned.of_to. Qed.p:positivematch Pos.of_uint (Pos.to_uint p) with | 0%N => None | N.pos p0 => Some p0 end = Some pd:intp:positivePos.of_int d = Some p -> Pos.to_int p = norm dd:intp:positivePos.of_int d = Some p -> Pos.to_int p = norm dd:intp:positivematch d with | Pos d0 => match Pos.of_uint d0 with | 0%N => None | N.pos p0 => Some p0 end | Neg _ => None end = Some p -> Pos.to_int p = norm dd:uintp:positivematch Pos.of_uint d with | 0%N => None | N.pos p0 => Some p0 end = Some p -> Pos.to_int p = norm (Pos d)d:uintp:positivematch Pos.of_uint d with | 0%N => None | N.pos p0 => Some p0 end = Some p -> Pos.to_int p = Pos (unorm d)destruct (Pos.of_uint d); now intros [= <-]. Qed.d:uintp:positivematch Pos.of_uint d with | 0%N => None | N.pos p0 => Some p0 end = Some p -> Pos.to_int p = Pos (N.to_uint (Pos.of_uint d))p, p':positivePos.to_int p = Pos.to_int p' -> p = p'p, p':positivePos.to_int p = Pos.to_int p' -> p = p'p, p':positiveE:Pos.to_int p = Pos.to_int p'p = p'p, p':positiveE:Pos.to_int p = Pos.to_int p'Some p = Some p'p, p':positiveE:Pos.to_int p = Pos.to_int p'E':Some p = Some p'p = p'now rewrite <- (of_to p), <- (of_to p'), E.p, p':positiveE:Pos.to_int p = Pos.to_int p'Some p = Some p'now injection E'. Qed.p, p':positiveE:Pos.to_int p = Pos.to_int p'E':Some p = Some p'p = p'd:uintunorm d <> 0%uint -> exists p : positive, Pos.to_int p = norm (Pos d)d:uintunorm d <> 0%uint -> exists p : positive, Pos.to_int p = norm (Pos d)d:uintunorm d <> 0%uint -> exists p : positive, Pos.to_int p = Pos (unorm d)d:uintunorm d <> 0%uint -> exists p : positive, Pos (Pos.to_uint p) = Pos (unorm d)d:uintH:unorm d <> 0%uintexists p : positive, Pos (Pos.to_uint p) = Pos (unorm d)d:uintH:unorm d <> 0%uintp:positiveHp:Pos.to_uint p = unorm dexists p0 : positive, Pos (Pos.to_uint p0) = Pos (unorm d)now f_equal. Qed.d:uintH:unorm d <> 0%uintp:positiveHp:Pos.to_uint p = unorm dPos (Pos.to_uint p) = Pos (unorm d)d:intPos.of_int (norm d) = Pos.of_int dd:intPos.of_int (norm d) = Pos.of_int dd:intmatch norm d with | Pos d0 => match Pos.of_uint d0 with | 0%N => None | N.pos p => Some p end | Neg _ => None end = match d with | Pos d0 => match Pos.of_uint d0 with | 0%N => None | N.pos p => Some p end | Neg _ => None endd:uintmatch norm (Pos d) with | Pos d0 => match Pos.of_uint d0 with | 0%N => None | N.pos p => Some p end | Neg _ => None end = match Pos.of_uint d with | 0%N => None | N.pos p => Some p endd:uintmatch norm (Neg d) with | Pos d0 => match Pos.of_uint d0 with | 0%N => None | N.pos p => Some p end | Neg _ => None end = Noned:uintmatch norm (Pos d) with | Pos d0 => match Pos.of_uint d0 with | 0%N => None | N.pos p => Some p end | Neg _ => None end = match Pos.of_uint d with | 0%N => None | N.pos p => Some p endnow rewrite Unsigned.of_uint_norm.d:uintmatch Pos.of_uint (unorm d) with | 0%N => None | N.pos p => Some p end = match Pos.of_uint d with | 0%N => None | N.pos p => Some p endd:uintmatch norm (Neg d) with | Pos d0 => match Pos.of_uint d0 with | 0%N => None | N.pos p => Some p end | Neg _ => None end = Nonenow destruct (nzhead d) eqn:H. Qed.d:uintmatch match 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 with | Pos d0 => match Pos.of_uint d0 with | 0%N => None | N.pos p => Some p end | Neg _ => None end = Noned, d':uintPos.of_int (Pos d) = Pos.of_int (Pos d') -> unorm d = unorm d'd, d':uintPos.of_int (Pos d) = Pos.of_int (Pos d') -> unorm d = unorm d'd, d':uintmatch Pos.of_uint d with | 0%N => None | N.pos p => Some p end = match Pos.of_uint d' with | 0%N => None | N.pos p => Some p end -> unorm d = unorm d'd, d':uintHd:Pos.of_uint d = 0%NHd':Pos.of_uint d' = 0%Nunorm d = unorm d'd, d':uintp:positiveHd:Pos.of_uint d = N.pos pp0:positiveHd':Pos.of_uint d' = N.pos p0H0:p = p0unorm d = unorm d'apply Unsigned.of_inj; now rewrite Hd, Hd'.d, d':uintHd:Pos.of_uint d = 0%NHd':Pos.of_uint d' = 0%Nunorm d = unorm d'apply Unsigned.of_inj; rewrite Hd, Hd'; now f_equal. Qed. End Signed.d, d':uintp:positiveHd:Pos.of_uint d = N.pos pp0:positiveHd':Pos.of_uint d' = N.pos p0H0:p = p0unorm d = unorm d'