Definition dnorm (d:decimal) : decimal :=
  let norm_i i f :=
    match i with
    | Pos i => Pos (unorm i)
    | Neg i => match nzhead (app i f) with Nil => Pos zero | _ => Neg (unorm i) end
    end in
  match d with
  | Decimal i f => Decimal (norm_i i f) f
  | DecimalExp i f e =>
    match norm e with
    | Pos zero => Decimal (norm_i i f) f
    | e => DecimalExp (norm_i i f) f e
    end
  end.

Lemma dnorm_spec_i d : let (i, f) := match d with Decimal i f => (i, f) | DecimalExp i f _ => (i, f) end in let i' := match dnorm d with Decimal i _ => i | DecimalExp i _ _ => i end in match i with | Pos i => i' = Pos (unorm i) | Neg i => (i' = Neg (unorm i) /\ (nzhead i <> Nil \/ nzhead f <> Nil)) \/ (i' = Pos zero /\ (nzhead i = Nil /\ nzhead f = Nil)) end.