(** Normalization on little-endian numbers *)
Fixpoint nztail d :=
match d with
| Nil => Nil
| D0 d => match nztail d with Nil => Nil | d' => D0 d' end
| D1 d => D1 (nztail d)
| D2 d => D2 (nztail d)
| D3 d => D3 (nztail d)
| D4 d => D4 (nztail d)
| D5 d => D5 (nztail d)
| D6 d => D6 (nztail d)
| D7 d => D7 (nztail d)
| D8 d => D8 (nztail d)
| D9 d => D9 (nztail d)
| Da d => Da (nztail d)
| Db d => Db (nztail d)
| Dc d => Dc (nztail d)
| Dd d => Dd (nztail d)
| De d => De (nztail d)
| Df d => Df (nztail d)
end.
Definition lnorm d :=
match nztail d with
| Nil => zero
| d => d
end.

(* Specifications: *)
Lemma nzhead_revapp_0 d d' : nztail d = Nil ->
nzhead (revapp d d') = nzhead d'.
Lemma nzhead_revapp d d' : nztail d <> Nil ->
nzhead (revapp d d') = revapp (nztail d) d'.
Lemma nzhead_rev d : nztail d <> Nil ->
nzhead (rev d) = rev (nztail d).
Lemma rev_rev d : rev (rev d) = d.
Lemma nzhead_D0 u : nzhead (D0 u) = nzhead u.
Lemma rev_nil_inv d : rev d = Nil -> d = Nil.
Lemma rev_lnorm_rev d :
rev (lnorm (rev d)) = unorm d.
Lemma nzhead_nonzero d d' : nzhead d <> D0 d'.
Lemma unorm_0 d : unorm d = zero <-> nzhead d = Nil.
Lemma unorm_nonnil d : unorm d <> Nil.
Lemma unorm_iter_D0 n u : unorm (Nat.iter n D0 u) = unorm u.
Lemma del_tail_nonnil n u :
n < nb_digits u -> del_tail n u <> Nil.
Lemma nzhead_involutive d : nzhead (nzhead d) = nzhead d.
Lemma nztail_involutive d : nztail (nztail d) = nztail d.
Lemma unorm_involutive d : unorm (unorm d) = unorm d.
Lemma norm_involutive d : norm (norm d) = norm d.
Lemma lnzhead_neq_d0_head l l' : ~(lnzhead l = cons d0 l').
Lemma nzhead_del_tail_nzhead n u :
n < nb_digits (nzhead u) ->
nzhead (del_tail n (nzhead u)) = del_tail n (nzhead u).
Lemma norm_del_tail_int_norm n d :
n < nb_digits (match norm d with Pos d | Neg d => d end) ->
norm (del_tail_int n (norm d)) = del_tail_int n (norm d).
Lemma nzhead_app_nzhead d d' :
nzhead (app (nzhead d) d') = nzhead (app d d').
Lemma unorm_app_unorm d d' :
unorm (app (unorm d) d') = unorm (app d d').
Lemma norm_app_int_norm d d' :
unorm d' = zero ->
norm (app_int (norm d) d') = norm (app_int d d').