(************************************************************************)
(*         *      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)         *)
(************************************************************************)
(************************************************************************)
(** The multiplication and division of Cauchy reals.  WARNING: this file is experimental and likely to change in future releases. *)
Require Export ConstructiveCauchyReals.
Require CMorphisms.
Local Open Scope CReal_scope.
Definition CReal_mult_seq (x y : CReal) :=
(fun n : Z => seq x (n - scale y - 1)%Z
* seq y (n - scale x - 1)%Z).
Definition CReal_mult_scale (x y : CReal) : Z :=
x.(scale) + y.(scale).
Local Ltac simplify_Qpower_exponent :=
match goal with |- context [(_ ^ ?a)%Q] => ring_simplify a end.
Local Ltac simplify_Qabs :=
match goal with |- context [(Qabs ?a)%Q] => ring_simplify a end.
Local Ltac simplify_Qabs_in H :=
match type of H with context [(Qabs ?a)%Q] => ring_simplify a in H end.
Local Ltac field_simplify_Qabs :=
match goal with |- context [(Qabs ?a)%Q] => field_simplify a end.
Local Ltac pose_Qabs_pos :=
match goal with |- context [(Qabs ?a)%Q] => pose proof Qabs_nonneg a end.
Local Ltac simplify_Qle :=
match goal with |- (?l <= ?r)%Q => ring_simplify l; ring_simplify r end.
Local Ltac simplify_Qle_in H :=
match type of H with (?l <= ?r)%Q => ring_simplify l in H; ring_simplify r in H end.
Local Ltac simplify_Qlt :=
match goal with |- (?l < ?r)%Q => ring_simplify l; ring_simplify r end.
Local Ltac simplify_Qlt_in H :=
match type of H with (?l < ?r)%Q => ring_simplify l in H; ring_simplify r in H end.
Local Ltac simplify_seq_idx :=
match goal with |- context [seq ?x ?n] => progress ring_simplify n end.
Local Lemma Weaken_Qle_QpowerAddExp: forall (q : Q) (n m : Z),
(m >= 0)%Z
-> (q <= 2^n)%Q
-> (q <= 2^(n+m))%Q.
Local Lemma Weaken_Qle_QpowerRemSubExp: forall (q : Q) (n m : Z),
(m >= 0)%Z
-> (q <= 2^(n-m))%Q
-> (q <= 2^n)%Q.
Local Lemma Weaken_Qle_QpowerFac: forall (q r : Q) (n : Z),
(r >= 1)%Q
-> (q <= 2^n)%Q
-> (q <= r * 2^n)%Q.

Lemma CReal_mult_bound : forall (x y : CReal),
QBound (CReal_mult_seq x y) (CReal_mult_scale x y).