Timings for ConstructivePower.v
- /home/gitlab-runner/builds/v6HyzL39/0/coq/coq/_bench/opam.OLD/ocaml-OLD/.opam-switch/build/coq-stdlib.dev/_build/default/theories//./Reals/Abstract/ConstructivePower.timing
- /home/gitlab-runner/builds/v6HyzL39/0/coq/coq/_bench/opam.NEW/ocaml-NEW/.opam-switch/build/coq-stdlib.dev/_build/default/theories//./Reals/Abstract/ConstructivePower.timing
(************************************************************************)
(* * The Coq Proof Assistant / The Coq Development Team *)
(* v * INRIA, CNRS and contributors - Copyright 1999-2019 *)
(* <O___,, * (see CREDITS file for the list of authors) *)
(* \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) *)
(************************************************************************)
Require Import QArith Qabs.
Require Import ConstructiveReals.
Require Import ConstructiveRealsMorphisms.
Require Import ConstructiveAbs.
Require Import ConstructiveLimits.
Require Import ConstructiveSum.
Local Open Scope ConstructiveReals.
(**
Definition and properties of powers.
WARNING: this file is experimental and likely to change in future releases.
*)
Fixpoint CRpow {R : ConstructiveReals} (r:CRcarrier R) (n:nat) : CRcarrier R :=
match n with
| O => 1
| S n => r * (CRpow r n)
end.
Lemma CRpow_ge_one : forall {R : ConstructiveReals} (x : CRcarrier R) (n : nat),
1 <= x
-> 1 <= CRpow x n.
apply (CRle_trans _ (x * 1)).
apply CRmult_le_compat_l_half.
apply (CRlt_le_trans _ 1).
Lemma CRpow_ge_zero : forall {R : ConstructiveReals} (x : CRcarrier R) (n : nat),
0 <= x
-> 0 <= CRpow x n.
apply CRlt_asym, CRzero_lt_one.
apply CRmult_le_0_compat.
Lemma CRpow_gt_zero : forall {R : ConstructiveReals} (x : CRcarrier R) (n : nat),
0 < x
-> 0 < CRpow x n.
apply CRmult_lt_0_compat.
Lemma CRpow_mult : forall {R : ConstructiveReals} (x y : CRcarrier R) (n:nat),
CRpow x n * CRpow y n == CRpow (x*y) n.
do 2 rewrite <- (Rmul_assoc (CRisRing R)).
rewrite <- (Rmul_comm (CRisRing R)).
rewrite <- (Rmul_assoc (CRisRing R)).
rewrite <- (Rmul_comm (CRisRing R)).
Lemma CRpow_one : forall {R : ConstructiveReals} (n:nat),
@CRpow R 1 n == 1.
transitivity (CRmult R 1 (CRpow 1 n)).
Lemma CRpow_proper : forall {R : ConstructiveReals} (x y : CRcarrier R) (n : nat),
x == y -> CRpow x n == CRpow y n.
Lemma CRpow_inv : forall {R : ConstructiveReals} (x : CRcarrier R) (xPos : 0 < x) (n : nat),
CRpow (CRinv R x (inr xPos)) n
== CRinv R (CRpow x n) (inr (CRpow_gt_zero x n xPos)).
transitivity (CRinv R x (inr xPos) * CRpow (CRinv R x (inr xPos)) n).
assert (0 < x * CRpow x n).
apply CRmult_lt_0_compat.
apply CRpow_gt_zero, xPos.
rewrite <- (CRinv_mult_distr _ _ _ _ (inr H)).
Lemma CRpow_plus_distr : forall {R : ConstructiveReals} (x : CRcarrier R) (n p:nat),
CRpow x n * CRpow x p == CRpow x (n+p).
Lemma CR_double : forall {R : ConstructiveReals} (x:CRcarrier R),
CR_of_Q R 2 * x == x + x.
rewrite (CR_of_Q_morph R 2 (1+1)).
rewrite CRmult_plus_distr_r, CRmult_1_l.
Lemma GeoCvZero : forall {R : ConstructiveReals},
CR_cv R (fun n:nat => CRpow (CR_of_Q R (1#2)) n) 0.
assert (forall n:nat, INR n < CRpow (CR_of_Q R 2) n).
rewrite (CR_of_Q_morph R _ ((Z.of_nat 1 # 1) + (Z.of_nat n #1))).
2: symmetry; apply Qinv_plus_distr.
replace (CRpow (CR_of_Q R 2) (1 + n))
with (CR_of_Q R 2 * CRpow (CR_of_Q R 2) n).
apply CRplus_le_lt_compat.
2: apply CRpow_ge_zero; apply CR_of_Q_le; discriminate.
apply (CRmult_lt_reg_l (CR_of_Q R (Z.pos p # 1))).
rewrite (CR_of_Q_morph R ((Z.pos p # 1) * (1 # p)) 1).
2: unfold Qmult, Qeq, Qnum, Qden; ring_simplify; reflexivity.
apply (CRmult_lt_reg_r (CRpow (CR_of_Q R 2) i)).
rewrite (CRpow_proper (CR_of_Q R (1 # 2) * CR_of_Q R 2) 1), CRpow_one.
rewrite CRmult_1_r, CRmult_1_l.
apply (CRle_lt_trans _ (INR i)).
rewrite <- positive_nat_Z.
setoid_replace ((1#2)*2)%Q with 1%Q.
Lemma GeoFiniteSum : forall {R : ConstructiveReals} (n:nat),
CRsum (CRpow (CR_of_Q R (1#2))) n == CR_of_Q R 2 - CRpow (CR_of_Q R (1#2)) n.
simpl (1%ConstructiveReals).
rewrite (CR_of_Q_plus R 1 1).
rewrite CRplus_opp_r, CRplus_0_r.
setoid_replace (CRsum (CRpow (CR_of_Q R (1 # 2))) (S n))
with (CRsum (CRpow (CR_of_Q R (1 # 2))) n + CRpow (CR_of_Q R (1 # 2)) (S n)).
apply (CRplus_eq_reg_l
(CRpow (CR_of_Q R (1 # 2)) n + CRpow (CR_of_Q R (1 # 2)) (S n))).
rewrite (CRplus_assoc _ _ (-CRpow (CR_of_Q R (1 # 2)) (S n))),
CRplus_opp_r, CRplus_0_r.
rewrite (CRplus_comm (CRpow (CR_of_Q R (1 # 2)) n)), CRplus_assoc.
rewrite <- (CRplus_assoc (CRpow (CR_of_Q R (1 # 2)) n)), CRplus_opp_r,
CRplus_0_l, <- CR_double.
setoid_replace (CRpow (CR_of_Q R (1 # 2)) (S n))
with (CR_of_Q R (1 # 2) * CRpow (CR_of_Q R (1 # 2)) n).
rewrite <- CRmult_assoc, <- CR_of_Q_mult.
setoid_replace (2 * (1 # 2))%Q with 1%Q.
Lemma GeoHalfBelowTwo : forall {R : ConstructiveReals} (n:nat),
CRsum (CRpow (CR_of_Q R (1#2))) n < CR_of_Q R 2.
rewrite <- (CRplus_0_r (CR_of_Q R 2)), GeoFiniteSum.
apply CRplus_lt_compat_l.
apply CRopp_gt_lt_contravar.
Lemma GeoHalfTwo : forall {R : ConstructiveReals},
series_cv (fun n => CRpow (CR_of_Q R (1#2)) n) (CR_of_Q R 2).
apply (CR_cv_eq _ (fun n => CR_of_Q R 2 - CRpow (CR_of_Q R (1 # 2)) n)).
assert (forall n:nat, INR n < CRpow (CR_of_Q R 2) n).
apply (CRlt_le_trans _ (CRpow (CR_of_Q R 2) n + 1)).
rewrite Nat2Z.inj_succ, <- Z.add_1_l.
rewrite (CR_of_Q_morph R _ (1 + (Z.of_nat n #1))).
2: symmetry; apply Qinv_plus_distr.
apply CRplus_lt_compat_r, IHn.
setoid_replace (CRpow (CR_of_Q R 2) (S n))
with (CRpow (CR_of_Q R 2) n + CRpow (CR_of_Q R 2) n).
setoid_replace (CR_of_Q R 2 - CRpow (CR_of_Q R (1 # 2)) i - CR_of_Q R 2)
with (- CRpow (CR_of_Q R (1 # 2)) i).
assert (0 < CR_of_Q R 2).
rewrite (CRpow_proper _ (CRinv R (CR_of_Q R 2) (inr H1))).
apply (CRmult_lt_reg_l (CRpow (CR_of_Q R 2) i)).
apply (CRmult_lt_reg_r (CR_of_Q R (Z.pos n#1))).
rewrite CRmult_1_l, CRmult_assoc.
rewrite (CR_of_Q_morph R ((1 # n) * (Z.pos n # 1)) 1).
apply (CRle_lt_trans _ (INR i)).
pose proof (Pos2Nat.is_pos n).
apply (Nat.le_trans _ _ _ H0).
rewrite SuccNat2Pos.id_succ.
apply (CRmult_eq_reg_l (CR_of_Q R 2)).
setoid_replace (2 * (1 # 2))%Q with 1%Q.
apply CRlt_asym, CRpow_gt_zero.
rewrite CRplus_comm, <- CRplus_assoc.
rewrite CRplus_opp_l, CRplus_0_l.