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.
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.
Definition Nadd n p :=
match n with
| N0 => p
| Npos p0 => (p0+p)%positive
end.
(** First bijection result *)
(** The other direction *)
Definition to_lu n :=
match n with
| N0 => Decimal.zero
| Npos p => Pos.to_little_uint p
end.
Ltac simpl_to_nat := simpl N.to_nat; unfold Pos.to_nat; simpl Pos.iter_op.
(** Second bijection result *)
(** Some consequences *)

Lemma of_uint_norm d : Pos.of_uint (unorm d) = Pos.of_uint d.