(************************************************************************)
(*         *      The Rocq Prover / The Rocq Development Team           *)
(*  v      *         Copyright INRIA, CNRS and contributors             *)
(* <O___,, * (see version control and CREDITS file for authors & dates) *)
(*   \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)         *)
(************************************************************************)
(** * DecimalQ  Proofs that conversions between decimal numbers and [Q] are bijections. *)

Lemma of_to (q:IQ) : forall d, to_decimal q = Some d -> of_decimal d = q.
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.