From 09211a4dea75bc9bb16f3d0786e74aed8a733d96 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 27 Apr 2012 14:05:47 +0200
Subject: [PATCH 001/110] Added metric.v defining metric spaces; should replace
Classified.v
---
broken/metric.v | 303 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 303 insertions(+)
create mode 100644 broken/metric.v
diff --git a/broken/metric.v b/broken/metric.v
new file mode 100644
index 00000000..d6e9b767
--- /dev/null
+++ b/broken/metric.v
@@ -0,0 +1,303 @@
+(*Add Rec LoadPath "/home/emakarov/work/formath/corn" as CoRN.
+Add Rec LoadPath "/home/emakarov/work/formath/corn/math-classes/src" as MathClasses.*)
+
+Require Import
+ Psatz QArith
+ theory.setoids (* Equiv Prop *) theory.products
+ Qinf Qpossec QposInf QnonNeg abstract_algebra QType_rationals additional_operations.
+(*Import (*QnonNeg.notations*) QArith.*)
+Import Qinf.notations.
+
+Notation "n .+1" := (S n) (at level 2, left associativity, format "n .+1") : nat_scope.
+
+Local Notation Qnn := QnonNeg.T.
+
+Instance Qnn_eq : Equiv Qnn := eq.
+Instance Qnn_zero : Zero Qnn := QnonNeg.zero.
+Instance Qnn_one : One Qnn := QnonNeg.one.
+Instance Qnn_plus : Plus Qnn := QnonNeg.plus.
+Instance Qnn_mult : Mult Qnn := QnonNeg.mult.
+Instance Qnn_inv : DecRecip Qnn := QnonNeg.inv.
+
+Instance Qpos_eq : Equiv Qpos := Qpossec.QposEq.
+Instance Qpos_one : One Qpos := Qpossec.Qpos_one.
+Instance Qpos_plus : Plus Qpos := Qpossec.Qpos_plus.
+Instance Qpos_mult : Mult Qpos := Qpossec.Qpos_mult.
+Instance Qpos_inv : DecRecip Qpos := Qpossec.Qpos_inv.
+
+Ltac Qsimpl := unfold
+ equiv, zero, one, plus, mult, dec_recip,
+ Qnn_eq, Qnn_zero, Qnn_one, Qnn_plus, Qnn_mult, Qnn_inv,
+ QnonNeg.eq, QnonNeg.zero, QnonNeg.one, QnonNeg.plus, QnonNeg.mult, QnonNeg.inv,
+ Qpos_eq, Qpos_one, Qpos_plus, Qpos_mult, Qpos_inv,
+ Qpossec.QposEq, Qpossec.Qpos_one, Qpossec.Qpos_plus, Qpossec.Qpos_mult, Qpossec.Qpos_inv,
+ to_Q, QposAsQ;
+ simpl.
+
+(*Open Scope Q_scope.*)
+
+Class ExtMetricSpaceBall (X : Type) : Type := ext_mspc_ball: Qinf → relation X.
+
+Local Notation B' := ext_mspc_ball.
+
+(* In the proof of Banach fixpoint theorem we have to use arithmetic
+expressions such as q^n / (1 - q) when 0 <= q < 1 as the ball radius. If
+the radius is in Qnn (ie., QnonNeg.T), then we have to prove that 1 - q :
+Qnn. It seems more convenient to have the radius live in Q and have the
+axiom that no points are separated by a negative distance. *)
+
+Class ExtMetricSpace (X : Type) `{Equiv X} `{ExtMetricSpaceBall X} : Prop :=
+ { ext_mspc_setoid : Setoid X
+ ; ext_mspc_ball_proper:> Proper (=) B'
+ ; ext_mspc_ball_inf: ∀ x y, B' Qinf.infinite x y
+ ; ext_mspc_ball_negative: ∀ (e: Q), (e < 0)%Q → ∀ x y, ~ B' e x y
+ ; ext_mspc_ball_zero: ∀ x y, B' 0 x y ↔ x = y
+ ; ext_mspc_refl:> ∀ e, (0 <= e)%Qinf → Reflexive (B' e)
+ ; ext_mspc_sym:> ∀ e, Symmetric (B' e)
+ ; ext_mspc_triangle: ∀ (e1 e2: Qinf) (a b c: X),
+ B' e1 a b → B' e2 b c → B' (e1 + e2) a c
+ ; ext_mspc_closed: ∀ (e: Qinf) (a b: X),
+ (∀ d: Qpos, B' (e + d) a b) → B' e a b }.
+
+Class MetricSpaceBall (X : Type) : Type := mspc_ball: Q → relation X.
+
+Local Notation B := mspc_ball.
+
+Class MetricSpace (X : Type) `{Equiv X} `{MetricSpaceBall X} : Prop :=
+ { mspc_setoid : Setoid X
+ ; mspc_ball_proper:> Proper (=) B
+ ; mspc_ball_negative: ∀ (e: Q), (e < 0)%Q → ∀ x y, ~ B e x y
+ ; mspc_ball_zero: ∀ x y, B 0 x y ↔ x = y
+ ; mspc_refl:> ∀ e, (0 <= e)%Q → Reflexive (B e)
+ ; mspc_sym:> ∀ e, Symmetric (B e)
+ ; mspc_triangle: ∀ (e1 e2: Q) (a b c: X), B e1 a b → B e2 b c → B (e1 + e2) a c
+ ; mspc_closed: ∀ (e: Q) (a b: X), (∀ d: Qpos, B (e + d) a b) → B e a b
+ ; mspc_finite: forall x1 x2 : X, exists e : Q, mspc_ball e x1 x2 }.
+
+Section Coercion.
+
+Context `{MetricSpace X}.
+
+Global Instance : ExtMetricSpaceBall X := λ e : Qinf,
+match e with
+| Qinf.infinite => λ _ _, True
+| Qinf.finite e => B e
+end.
+
+Global Instance : ExtMetricSpace X.
+Admitted.
+
+End Coercion.
+
+
+(*Section MetricSpaceClass.
+
+Context `{MetricSpaceClass X}.
+
+Program Definition Qnn_minus `(A : q1 <= q2) : Qnn := (q2 - q1)%Q.
+Next Obligation. lra. Qed.
+
+Lemma mspc_zero : ∀ x y : X, (∀ q : Qpos, mspc_ball q x y) → mspc_ball 0 x y.
+Proof.
+intros x y A. apply mspc_closed; intro d. rewrite plus_0_l; trivial.
+Qed.
+
+Lemma mspc_eq' : ∀ x y : X, (∀ q : Qpos, mspc_ball q x y) → x = y.
+Proof.
+intros x y A; apply mspc_eq; intros [q A1].
+destruct (Qle_lt_or_eq _ _ A1) as [A2 | A2].
+setoid_replace (q ↾ A1) with (from_Qpos (q ↾ A2)) by reflexivity; apply A.
+setoid_replace (q ↾ A1) with 0 by (symmetry in A2; apply A2).
+apply mspc_zero, A.
+Qed.
+
+Lemma mspc_triangle' :
+ ∀ (q1 q2 : Qnn) (b a c : X) (q : Qnn),
+ q1 + q2 = q → mspc_ball q1 a b → mspc_ball q2 b c → mspc_ball q a c.
+Proof.
+intros q1 q2 b a c q A1 A2 A3. rewrite <- A1. eapply mspc_triangle; eauto.
+Qed.
+
+Lemma mspc_monotone :
+ ∀ q1 q2 : Qnn, (q1 <= q2)%Q -> ∀ x y : X, mspc_ball q1 x y → mspc_ball q2 x y.
+Proof.
+intros q1 q2 A1 x y A2.
+setoid_replace q2 with (q1 + (Qnn_minus A1)).
+apply mspc_triangle with (b := y); [| apply mspc_refl]; trivial.
+unfold Qnn_minus; Qsimpl; lra.
+Qed.
+
+Lemma mspc_zero_eq : ∀ x y : X, mspc_ball 0 x y ↔ x = y.
+Proof.
+intros x y; split; intro A1; [| rewrite A1; apply mspc_refl].
+apply mspc_eq. intro q; apply (mspc_monotone 0); trivial. apply (proj2_sig q).
+Qed.
+
+End MetricSpaceClass.
+*)
+
+Record UniformlyContinuous
+ (X Y : Type) `{Equiv X, Equiv Y, ExtMetricSpaceBall X, ExtMetricSpaceBall Y} := mkUniformlyContinuous {
+ uc_fun :> X → Y;
+ uc_mu : Qpos -> QposInf;
+ uc_proper : Proper (=) uc_fun;
+ uc_prf : ∀ (q: Qpos) (a b: X), B' (uc_mu q) a b → B' q (uc_fun a) (uc_fun b)
+}.
+
+Arguments uc_fun {X} {Y} {_} {_} {_} {_} _ _.
+Arguments uc_mu {X} {Y} {_} {_} {_} {_} _ _.
+Arguments uc_prf {X} {Y} {_} {_} {_} {_} _ _ _ _ _.
+
+Global Existing Instance uc_proper.
+
+(*Section UCFMetricSpace.
+
+Context `{MetricSpaceClass X, MetricSpaceClass Y}.
+
+Instance UCFEquiv : Equiv (UniformlyContinuous X Y) := @equiv (X -> Y) _.
+
+Lemma UCFSetoid : Setoid (UniformlyContinuous X Y).
+Proof.
+constructor.
+intros f x y A; now rewrite A.
+intros f g A1 x y A2; rewrite A2; symmetry; now apply A1.
+intros f g h A1 A2 x y A3; rewrite A3; now transitivity (g y); [apply A1 | apply A2].
+Qed.
+
+Instance UCFSpaceBall : MetricSpaceBall (UniformlyContinuous X Y) :=
+ fun q f g => forall x, mspc_ball q (f x) (g x).
+
+Lemma UCFBallProper : Proper equiv mspc_ball.
+Proof.
+intros q1 q2 A1 f1 f2 A2 g1 g2 A3; split; intros A4 x.
++ rewrite <- A1. rewrite <- (A2 x x); [| reflexivity]. rewrite <- (A3 x x); [| reflexivity]. apply A4.
++ rewrite A1. rewrite (A2 x x); [| reflexivity]. rewrite (A3 x x); [| reflexivity]. apply A4.
+Qed.
+
+Global Instance : MetricSpaceClass (UniformlyContinuous X Y).
+Proof.
+constructor.
+apply UCFSetoid.
+apply UCFBallProper.
+intros q f x; apply mspc_refl.
+intros q f g A x; apply mspc_symm; trivial.
+intros q1 q2 f g h A1 A2 x; apply mspc_triangle with (b := g x); trivial.
+intros q f g A x; apply mspc_closed; intro d; apply A.
+intros f g A1 x y A2. rewrite A2. eapply mspc_eq; trivial. intro q; apply A1.
+Qed.
+
+End UCFMetricSpace.
+*)
+
+Definition sequence (X : Type) := nat -> X.
+
+Section MetricSpaceDefs.
+
+Context `{ExtMetricSpace X}.
+
+Definition cauchy (x : sequence X) :=
+ ∀ q : Qpos, ∃ N : nat, ∀ m n : nat, (N < m)%nat -> (N < n)%nat -> B' q (x m) (x n).
+
+Definition limit (x : sequence X) (a : X) :=
+ ∀ q : Qpos, ∃ N : nat, ∀ n : nat, (N < n)%nat -> B' q (x n) a.
+
+Definition complete := ∀ x : sequence X, cauchy x → ∃ a : X, limit x a.
+
+End MetricSpaceDefs.
+
+Arguments complete X {_} : clear implicits.
+
+(*Program Definition contr_modulus (q : Qnn) :=
+match q with
+
+Record Contraction
+ (X Y : Type) `{Equiv X, Equiv Y, ExtMetricSpaceBall X, ExtMetricSpaceBall Y} := mkContraction {
+ contr_fun :> X → Y;
+ contr_mu : Qnn;
+ contr_mu1 : (contr_mu < 1)%Q;
+ contr_proper : Proper (=) contr_fun;
+ contr_prf : ∀ (e : Qpos) (x1 x2 : X),
+ mspc_ball (e / contr_mu) x1 x2 → mspc_ball e (contr_fun x1) (contr_fun x2)
+}.
+
+Arguments contr_fun {X} {Y} {_} {_} {_} {_} _ _.
+Arguments contr_mu {X} {Y} {_} {_} {_} {_} _.
+Arguments contr_prf {X} {Y} {_} {_} {_} {_} _ _ _ _ _.
+
+Global Existing Instance contr_proper.
+*)
+
+(*Section Contractions.*)
+
+(*Context (X Y : Type) `{Equiv X, Equiv Y, MetricSpaceBall X, MetricSpaceBall Y}.*)
+
+(*
+Definition contr_to_cont
+ (X Y : Type) `{Equiv X, Equiv Y, MetricSpaceBall X, MetricSpaceBall Y} (f : Contraction X Y) : UniformlyContinuous X Y.
+split with (uc_fun := f) (uc_mu := fun e => e / contr_mu f).
+(* uc_proper *)
+apply f.
+(* uc_prf *)
+apply contr_prf.
+Defined.
+
+(*End Contractions.*)
+
+Coercion contr_to_cont : Contraction >-> UniformlyContinuous.
+
+Section MetricSpaceLimits.
+
+Context `{MetricSpaceClass X, MetricSpaceClass Y}.
+
+Theorem limit_unique : ∀ (x : sequence X) (a b : X), limit x a → limit x b → a = b.
+Proof.
+intros x a b A1 A2; apply mspc_eq'; intro q.
+specialize (A1 (q / 2)); specialize (A2 (q / 2)).
+destruct A1 as [N1 A1]; destruct A2 as [N2 A2].
+set (N := S (Peano.max N1 N2)). specialize (A1 N); specialize (A2 N).
+apply (mspc_triangle' (q / 2) (q / 2) (x N));
+[Qsimpl; field | apply mspc_symm |];
+[apply A1 | apply A2]; subst N; lia.
+Qed.
+
+Theorem limit_cont : ∀ (f : UniformlyContinuous X Y) (x : sequence X) (a : X),
+ limit x a → limit (f ∘ x) (f a).
+Proof.
+intros f x a A1 q.
+specialize (A1 (uc_mu f q)).
+destruct A1 as [N A1]. exists N; intros n A2. now apply uc_prf, A1.
+Qed.
+
+Theorem limit_contr : ∀ (f : Contraction X Y) (x : sequence X) (a : X),
+ limit x a → limit (f ∘ x) (f a).
+Proof. intro f; apply (limit_cont f). Qed.
+
+End MetricSpaceLimits.
+*)
+
+Section BanachFixpoint.
+
+Context `{MetricSpace X} (f : (*Contraction*) X -> X) (x0 : X).
+
+(*Let q : Q := f.(contr_mu).*)
+Let x n := nat_iter n f x0.
+
+Variable d : Q.
+
+Hypothesis dist_x0_x1 : B d (x 0) (x 1).
+
+Open Scope Qinf_scope.
+Variables (a b : Q) (n : nat). Check (a^n).
+Check _ : Pow Q nat.
+SearchAbout (Pow Q nat).
+
+Lemma dist_xn_xn' : forall n : nat, ball (d * q^n) (x n) (x n.+1).
+
+
+SearchAbout "iter".
+
+SearchAbout "power".
+Lemma distance_n : ∀ n, mspc_ball
+
+
+
From ea317ca5cde62feeaefca234df478c9d912ddf39 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 27 Apr 2012 14:39:13 +0200
Subject: [PATCH 002/110] git testing
---
README | 1 +
1 file changed, 1 insertion(+)
diff --git a/README b/README
index a09b4fa3..dc1ea956 100644
--- a/README
+++ b/README
@@ -68,3 +68,4 @@ PLOTS
If you want high resolution plots in examples/Circle.v, follow the instructions
in dump/INSTALL
+
From 27727755fa362e997e4e338ca44165f03ae24060 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 8 May 2012 18:19:03 +0200
Subject: [PATCH 003/110] Changed UniformlyContinuous and Contraction into
unbundled type classes. Bundling is expected to be done later, if necessary.
---
broken/metric.v | 169 ++++++++++++++++++++++++++++--------------------
1 file changed, 99 insertions(+), 70 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index d6e9b767..a0046923 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -1,10 +1,7 @@
-(*Add Rec LoadPath "/home/emakarov/work/formath/corn" as CoRN.
-Add Rec LoadPath "/home/emakarov/work/formath/corn/math-classes/src" as MathClasses.*)
-
Require Import
Psatz QArith
theory.setoids (* Equiv Prop *) theory.products
- Qinf Qpossec QposInf QnonNeg abstract_algebra QType_rationals additional_operations.
+ stdlib_rationals Qinf Qpossec QposInf QnonNeg abstract_algebra QType_rationals additional_operations.
(*Import (*QnonNeg.notations*) QArith.*)
Import Qinf.notations.
@@ -25,15 +22,42 @@ Instance Qpos_plus : Plus Qpos := Qpossec.Qpos_plus.
Instance Qpos_mult : Mult Qpos := Qpossec.Qpos_mult.
Instance Qpos_inv : DecRecip Qpos := Qpossec.Qpos_inv.
-Ltac Qsimpl := unfold
- equiv, zero, one, plus, mult, dec_recip,
+Instance Qinf_one : One Qinf := 1%Q.
+
+Module Qinf.
+
+Definition lt (x y : Qinf) : Prop :=
+match x, y with
+| Qinf.finite a, Qinf.finite b => Qlt a b
+| Qinf.finite _, Qinf.infinite => True
+| Qinf.infinite, _ => False
+end.
+
+Instance: Proper (=) lt.
+Proof.
+intros [x1 |] [x2 |] A1 [y1 |] [y2 |] A2; revert A1 A2;
+unfold Qinf.eq, Q_eq, equiv; simpl; intros A1 A2;
+try contradiction; try reflexivity.
+rewrite A1, A2; reflexivity.
+Qed.
+
+End Qinf.
+
+Instance Qinf_lt : Lt Qinf := Qinf.lt.
+
+Ltac Qsimpl' := unfold
Qnn_eq, Qnn_zero, Qnn_one, Qnn_plus, Qnn_mult, Qnn_inv,
QnonNeg.eq, QnonNeg.zero, QnonNeg.one, QnonNeg.plus, QnonNeg.mult, QnonNeg.inv,
Qpos_eq, Qpos_one, Qpos_plus, Qpos_mult, Qpos_inv,
Qpossec.QposEq, Qpossec.Qpos_one, Qpossec.Qpos_plus, Qpossec.Qpos_mult, Qpossec.Qpos_inv,
+ Qinf.eq, Qinf.lt, Qinf_lt, Qinf_one, Zero_instance_0 (* Zero Qinf *),
+ Q_eq, Q_lt, Q_le, Q_0, Q_1, Q_opp, Q_plus, Q_mult, Q_recip,
+ equiv, lt, le, zero, one, plus, mult, dec_recip,
to_Q, QposAsQ;
simpl.
+Tactic Notation "Qsimpl" hyp_list(A) := revert A; Qsimpl'; intros A.
+
(*Open Scope Q_scope.*)
Class ExtMetricSpaceBall (X : Type) : Type := ext_mspc_ball: Qinf → relation X.
@@ -47,32 +71,34 @@ Qnn. It seems more convenient to have the radius live in Q and have the
axiom that no points are separated by a negative distance. *)
Class ExtMetricSpace (X : Type) `{Equiv X} `{ExtMetricSpaceBall X} : Prop :=
- { ext_mspc_setoid : Setoid X
- ; ext_mspc_ball_proper:> Proper (=) B'
+ { ext_mspc_setoid :> Setoid X
+ ; ext_mspc_ball_proper:> Proper (=) ext_mspc_ball
; ext_mspc_ball_inf: ∀ x y, B' Qinf.infinite x y
; ext_mspc_ball_negative: ∀ (e: Q), (e < 0)%Q → ∀ x y, ~ B' e x y
; ext_mspc_ball_zero: ∀ x y, B' 0 x y ↔ x = y
- ; ext_mspc_refl:> ∀ e, (0 <= e)%Qinf → Reflexive (B' e)
+ ; ext_mspc_refl:> ∀ e : Q, (0 <= e)%Q → Reflexive (B' e)
; ext_mspc_sym:> ∀ e, Symmetric (B' e)
; ext_mspc_triangle: ∀ (e1 e2: Qinf) (a b c: X),
- B' e1 a b → B' e2 b c → B' (e1 + e2) a c
- ; ext_mspc_closed: ∀ (e: Qinf) (a b: X),
- (∀ d: Qpos, B' (e + d) a b) → B' e a b }.
+ B' e1 a b → B' e2 b c → B' (e1 + e2)%Qinf a c
+ ; ext_mspc_closed: ∀ (e: Q) (a b: X),
+ (∀ d: Q, (0 < d)%Q -> B' (e + d) a b) → B' e a b }.
Class MetricSpaceBall (X : Type) : Type := mspc_ball: Q → relation X.
Local Notation B := mspc_ball.
-Class MetricSpace (X : Type) `{Equiv X} `{MetricSpaceBall X} : Prop :=
- { mspc_setoid : Setoid X
+Class MetricSpaceDistance `{MetricSpaceBall X} := msd : X -> X -> Q.
+
+Class MetricSpace (X : Type) `{Equiv X} `{MetricSpaceBall X} `{MetricSpaceDistance X}: Prop :=
+ { mspc_setoid :> Setoid X
; mspc_ball_proper:> Proper (=) B
; mspc_ball_negative: ∀ (e: Q), (e < 0)%Q → ∀ x y, ~ B e x y
; mspc_ball_zero: ∀ x y, B 0 x y ↔ x = y
- ; mspc_refl:> ∀ e, (0 <= e)%Q → Reflexive (B e)
+ ; mspc_refl:> ∀ e : Q, (0 <= e)%Q → Reflexive (B e)
; mspc_sym:> ∀ e, Symmetric (B e)
; mspc_triangle: ∀ (e1 e2: Q) (a b c: X), B e1 a b → B e2 b c → B (e1 + e2) a c
- ; mspc_closed: ∀ (e: Q) (a b: X), (∀ d: Qpos, B (e + d) a b) → B e a b
- ; mspc_finite: forall x1 x2 : X, exists e : Q, mspc_ball e x1 x2 }.
+ ; mspc_closed: ∀ (e: Q) (a b: X), (∀ d: Q, (0 < d)%Q -> B (e + d) a b) → B e a b
+ ; mspc_distance: forall x1 x2 : X, B (msd x1 x2) x1 x2 }.
Section Coercion.
@@ -90,11 +116,11 @@ Admitted.
End Coercion.
-(*Section MetricSpaceClass.
+Section ExtMetricSpaceClass.
-Context `{MetricSpaceClass X}.
+Context `{ExtMetricSpace X}.
-Program Definition Qnn_minus `(A : q1 <= q2) : Qnn := (q2 - q1)%Q.
+(*Program Definition Qnn_minus `(A : q1 <= q2) : Qnn := (q2 - q1)%Q.
Next Obligation. lra. Qed.
Lemma mspc_zero : ∀ x y : X, (∀ q : Qpos, mspc_ball q x y) → mspc_ball 0 x y.
@@ -116,39 +142,72 @@ Lemma mspc_triangle' :
q1 + q2 = q → mspc_ball q1 a b → mspc_ball q2 b c → mspc_ball q a c.
Proof.
intros q1 q2 b a c q A1 A2 A3. rewrite <- A1. eapply mspc_triangle; eauto.
-Qed.
+Qed.*)
Lemma mspc_monotone :
- ∀ q1 q2 : Qnn, (q1 <= q2)%Q -> ∀ x y : X, mspc_ball q1 x y → mspc_ball q2 x y.
-Proof.
+ ∀ q1 q2 : Q, q1 <= q2 -> ∀ x y : X, B' q1 x y → B' q2 x y.
+Admitted.
+(*Proof.
intros q1 q2 A1 x y A2.
setoid_replace q2 with (q1 + (Qnn_minus A1)).
apply mspc_triangle with (b := y); [| apply mspc_refl]; trivial.
unfold Qnn_minus; Qsimpl; lra.
-Qed.
+Qed.*)
-Lemma mspc_zero_eq : ∀ x y : X, mspc_ball 0 x y ↔ x = y.
+(*Lemma mspc_zero_eq : ∀ x y : X, mspc_ball 0 x y ↔ x = y.
Proof.
intros x y; split; intro A1; [| rewrite A1; apply mspc_refl].
apply mspc_eq. intro q; apply (mspc_monotone 0); trivial. apply (proj2_sig q).
-Qed.
+Qed.*)
-End MetricSpaceClass.
-*)
+End ExtMetricSpaceClass.
+
+Section UniformContinuity.
+
+Context `{ExtMetricSpace X, ExtMetricSpace Y}.
-Record UniformlyContinuous
- (X Y : Type) `{Equiv X, Equiv Y, ExtMetricSpaceBall X, ExtMetricSpaceBall Y} := mkUniformlyContinuous {
- uc_fun :> X → Y;
- uc_mu : Qpos -> QposInf;
- uc_proper : Proper (=) uc_fun;
- uc_prf : ∀ (q: Qpos) (a b: X), B' (uc_mu q) a b → B' q (uc_fun a) (uc_fun b)
+Class UniformlyContinuous (f : X -> Y) (mu : Q -> Qinf) := {
+ uc_proper :> Proper (=) f;
+ uc_pos : forall e : Q, 0 < e -> (0 < mu e);
+ uc_prf : ∀ (e : Q) (x1 x2: X), 0 < e -> B' (mu e) x1 x2 → B' e (f x1) (f x2)
}.
-Arguments uc_fun {X} {Y} {_} {_} {_} {_} _ _.
-Arguments uc_mu {X} {Y} {_} {_} {_} {_} _ _.
-Arguments uc_prf {X} {Y} {_} {_} {_} {_} _ _ _ _ _.
+Class Contraction (f : X -> Y) (q : Q) := {
+ contr_proper :> Proper (=) f;
+ contr_nonneg_mu : 0 <= q;
+ contr_lt_mu_1 : q < 1;
+ contr_prf : forall (x1 x2 : X) (e : Q), B' e x1 x2 -> B' (q * e) (f x1) (f x2)
+}.
+
+Definition contr_modulus (q e : Q) : Qinf :=
+ if (decide (q = 0)) then 1 else (e / q)%Q.
+
+Close Scope Qinf_scope.
+
+Instance contr_to_uc : forall `(Contraction f q), UniformlyContinuous f (contr_modulus q).
+Proof.
+intros f q fc. constructor.
+apply fc.
+intros e A. unfold contr_modulus. destruct (decide (q = 0)) as [A1 | A1].
+Qsimpl; auto with qarith.
+destruct fc as [_ A2 _ _]. apply Q.Qmult_lt_0_compat; [apply A | apply Qinv_lt_0_compat].
+revert A A1; Qsimpl; lra.
+intros e x1 x2 A1 A2. unfold contr_modulus in A2. destruct (decide (q = 0)) as [A | A].
+apply contr_prf in A2. rewrite A, Qmult_0_l in A2.
+apply mspc_monotone with (q1 := 0); trivial. apply Qlt_le_weak; trivial.
+apply contr_prf in A2. setoid_replace (q * (e / q)) with e in A2; trivial.
+Qsimpl A; field; trivial.
+Qed.
-Global Existing Instance uc_proper.
+End UniformContinuity.
+
+(*
+Why does
+SearchPattern (@Proper _ (@equiv (Q -> Qinf) _) _).
+work but
+SearchPattern (@Proper _ (@equiv _ _) _).
+does not?
+*)
(*Section UCFMetricSpace.
@@ -207,26 +266,6 @@ End MetricSpaceDefs.
Arguments complete X {_} : clear implicits.
-(*Program Definition contr_modulus (q : Qnn) :=
-match q with
-
-Record Contraction
- (X Y : Type) `{Equiv X, Equiv Y, ExtMetricSpaceBall X, ExtMetricSpaceBall Y} := mkContraction {
- contr_fun :> X → Y;
- contr_mu : Qnn;
- contr_mu1 : (contr_mu < 1)%Q;
- contr_proper : Proper (=) contr_fun;
- contr_prf : ∀ (e : Qpos) (x1 x2 : X),
- mspc_ball (e / contr_mu) x1 x2 → mspc_ball e (contr_fun x1) (contr_fun x2)
-}.
-
-Arguments contr_fun {X} {Y} {_} {_} {_} {_} _ _.
-Arguments contr_mu {X} {Y} {_} {_} {_} {_} _.
-Arguments contr_prf {X} {Y} {_} {_} {_} {_} _ _ _ _ _.
-
-Global Existing Instance contr_proper.
-*)
-
(*Section Contractions.*)
(*Context (X Y : Type) `{Equiv X, Equiv Y, MetricSpaceBall X, MetricSpaceBall Y}.*)
@@ -275,6 +314,7 @@ Proof. intro f; apply (limit_cont f). Qed.
End MetricSpaceLimits.
*)
+(*
Section BanachFixpoint.
Context `{MetricSpace X} (f : (*Contraction*) X -> X) (x0 : X).
@@ -286,18 +326,7 @@ Variable d : Q.
Hypothesis dist_x0_x1 : B d (x 0) (x 1).
-Open Scope Qinf_scope.
-Variables (a b : Q) (n : nat). Check (a^n).
-Check _ : Pow Q nat.
-SearchAbout (Pow Q nat).
-
Lemma dist_xn_xn' : forall n : nat, ball (d * q^n) (x n) (x n.+1).
-
-SearchAbout "iter".
-
-SearchAbout "power".
-Lemma distance_n : ∀ n, mspc_ball
-
-
+*)
From b546fb4a467293c6db1eeeb63158abe6c6f5b3a8 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 11 May 2012 16:42:55 +0200
Subject: [PATCH 004/110] Proved a lemma for the fixpoint theorem about the
distance between x_n and x_{n+1}
---
broken/metric.v | 57 +++++++++++++++++++++----------------------------
1 file changed, 24 insertions(+), 33 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index a0046923..e5f56485 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -4,6 +4,7 @@ Require Import
stdlib_rationals Qinf Qpossec QposInf QnonNeg abstract_algebra QType_rationals additional_operations.
(*Import (*QnonNeg.notations*) QArith.*)
Import Qinf.notations.
+Import peano_naturals.
Notation "n .+1" := (S n) (at level 2, left associativity, format "n .+1") : nat_scope.
@@ -45,17 +46,24 @@ End Qinf.
Instance Qinf_lt : Lt Qinf := Qinf.lt.
+Ltac mc_simpl := unfold
+ equiv, zero, one, plus, negate, mult, dec_recip, le, lt.
+
Ltac Qsimpl' := unfold
Qnn_eq, Qnn_zero, Qnn_one, Qnn_plus, Qnn_mult, Qnn_inv,
QnonNeg.eq, QnonNeg.zero, QnonNeg.one, QnonNeg.plus, QnonNeg.mult, QnonNeg.inv,
Qpos_eq, Qpos_one, Qpos_plus, Qpos_mult, Qpos_inv,
Qpossec.QposEq, Qpossec.Qpos_one, Qpossec.Qpos_plus, Qpossec.Qpos_mult, Qpossec.Qpos_inv,
Qinf.eq, Qinf.lt, Qinf_lt, Qinf_one, Zero_instance_0 (* Zero Qinf *),
- Q_eq, Q_lt, Q_le, Q_0, Q_1, Q_opp, Q_plus, Q_mult, Q_recip,
- equiv, lt, le, zero, one, plus, mult, dec_recip,
- to_Q, QposAsQ;
+ Q_eq, Q_lt, Q_le, Q_0, Q_1, Q_opp, Q_plus, Q_mult, Q_recip;
+ mc_simpl;
+ unfold to_Q, QposAsQ;
simpl.
+Ltac nat_simpl := unfold
+ nat_equiv, nat_0, nat_1, nat_plus, nat_plus, nat_mult, nat_le, nat_lt;
+ mc_simpl.
+
Tactic Notation "Qsimpl" hyp_list(A) := revert A; Qsimpl'; intros A.
(*Open Scope Q_scope.*)
@@ -87,7 +95,7 @@ Class MetricSpaceBall (X : Type) : Type := mspc_ball: Q → relation X.
Local Notation B := mspc_ball.
-Class MetricSpaceDistance `{MetricSpaceBall X} := msd : X -> X -> Q.
+Class MetricSpaceDistance (X : Type) := msd : X -> X -> Q.
Class MetricSpace (X : Type) `{Equiv X} `{MetricSpaceBall X} `{MetricSpaceDistance X}: Prop :=
{ mspc_setoid :> Setoid X
@@ -115,7 +123,6 @@ Admitted.
End Coercion.
-
Section ExtMetricSpaceClass.
Context `{ExtMetricSpace X}.
@@ -266,25 +273,7 @@ End MetricSpaceDefs.
Arguments complete X {_} : clear implicits.
-(*Section Contractions.*)
-
-(*Context (X Y : Type) `{Equiv X, Equiv Y, MetricSpaceBall X, MetricSpaceBall Y}.*)
-
-(*
-Definition contr_to_cont
- (X Y : Type) `{Equiv X, Equiv Y, MetricSpaceBall X, MetricSpaceBall Y} (f : Contraction X Y) : UniformlyContinuous X Y.
-split with (uc_fun := f) (uc_mu := fun e => e / contr_mu f).
-(* uc_proper *)
-apply f.
-(* uc_prf *)
-apply contr_prf.
-Defined.
-
-(*End Contractions.*)
-
-Coercion contr_to_cont : Contraction >-> UniformlyContinuous.
-
-Section MetricSpaceLimits.
+(*Section MetricSpaceLimits.
Context `{MetricSpaceClass X, MetricSpaceClass Y}.
@@ -314,19 +303,21 @@ Proof. intro f; apply (limit_cont f). Qed.
End MetricSpaceLimits.
*)
-(*
Section BanachFixpoint.
-Context `{MetricSpace X} (f : (*Contraction*) X -> X) (x0 : X).
+Context `{MetricSpace X} (f : X -> X) `{!Contraction f q} (x0 : X).
-(*Let q : Q := f.(contr_mu).*)
Let x n := nat_iter n f x0.
-Variable d : Q.
-
-Hypothesis dist_x0_x1 : B d (x 0) (x 1).
-
-Lemma dist_xn_xn' : forall n : nat, ball (d * q^n) (x n) (x n.+1).
+Let d := msd (x 0) (x 1).
-*)
+Lemma dist_xn_xn' : forall n : nat, B (d * q^n)%mc (x n) (x n.+1).
+Proof.
+induction n using nat_induction.
++ rewrite nat_pow_0, right_identity; subst d; apply mspc_distance.
++ rewrite nat_pow_S. setoid_replace (d * (q * q ^ n)) with (q * (d * q^n)) by (Qsimpl; lra).
+ nat_simpl. simpl. subst x. simpl.
+apply (@contr_prf X H (@ExtMetricSpaceBall_instance_0 X H0)
+X H (@ExtMetricSpaceBall_instance_0 X H0) f q). assumption. assumption.
+Qed.
From 646504088879a1d78b3bbc572a5e10e6d4d999f5 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Wed, 16 May 2012 14:58:36 +0200
Subject: [PATCH 005/110] Proved a lemma needed to show that the sequence of
approximations is a Cauchy sequence.
---
broken/metric.v | 146 ++++++++++++++++++++++++++++++------------------
1 file changed, 92 insertions(+), 54 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index e5f56485..a9dba182 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -1,9 +1,17 @@
Require Import
- Psatz QArith
+ QArith
theory.setoids (* Equiv Prop *) theory.products
stdlib_rationals Qinf Qpossec QposInf QnonNeg abstract_algebra QType_rationals additional_operations.
(*Import (*QnonNeg.notations*) QArith.*)
-Import Qinf.notations.
+Require Import Qauto QOrderedType.
+(*Require Import orders.*)
+Require Import theory.rings theory.dec_fields orders.rings nat_pow.
+Require Import interfaces.naturals interfaces.orders.
+
+Add Field Q : (stdlib_field_theory Q).
+
+(*Import Qinf.notations.*)
+Notation Qinf := Qinf.T.
Import peano_naturals.
Notation "n .+1" := (S n) (at level 2, left associativity, format "n .+1") : nat_scope.
@@ -62,15 +70,16 @@ Ltac Qsimpl' := unfold
Ltac nat_simpl := unfold
nat_equiv, nat_0, nat_1, nat_plus, nat_plus, nat_mult, nat_le, nat_lt;
- mc_simpl.
+ mc_simpl;
+ simpl.
Tactic Notation "Qsimpl" hyp_list(A) := revert A; Qsimpl'; intros A.
(*Open Scope Q_scope.*)
-Class ExtMetricSpaceBall (X : Type) : Type := ext_mspc_ball: Qinf → relation X.
+Class MetricSpaceBall (X : Type) : Type := mspc_ball: Qinf → relation X.
-Local Notation B' := ext_mspc_ball.
+Local Notation B := mspc_ball.
(* In the proof of Banach fixpoint theorem we have to use arithmetic
expressions such as q^n / (1 - q) when 0 <= q < 1 as the ball radius. If
@@ -78,37 +87,29 @@ the radius is in Qnn (ie., QnonNeg.T), then we have to prove that 1 - q :
Qnn. It seems more convenient to have the radius live in Q and have the
axiom that no points are separated by a negative distance. *)
-Class ExtMetricSpace (X : Type) `{Equiv X} `{ExtMetricSpaceBall X} : Prop :=
- { ext_mspc_setoid :> Setoid X
- ; ext_mspc_ball_proper:> Proper (=) ext_mspc_ball
- ; ext_mspc_ball_inf: ∀ x y, B' Qinf.infinite x y
- ; ext_mspc_ball_negative: ∀ (e: Q), (e < 0)%Q → ∀ x y, ~ B' e x y
- ; ext_mspc_ball_zero: ∀ x y, B' 0 x y ↔ x = y
- ; ext_mspc_refl:> ∀ e : Q, (0 <= e)%Q → Reflexive (B' e)
- ; ext_mspc_sym:> ∀ e, Symmetric (B' e)
- ; ext_mspc_triangle: ∀ (e1 e2: Qinf) (a b c: X),
- B' e1 a b → B' e2 b c → B' (e1 + e2)%Qinf a c
- ; ext_mspc_closed: ∀ (e: Q) (a b: X),
- (∀ d: Q, (0 < d)%Q -> B' (e + d) a b) → B' e a b }.
-
-Class MetricSpaceBall (X : Type) : Type := mspc_ball: Q → relation X.
-
-Local Notation B := mspc_ball.
-
-Class MetricSpaceDistance (X : Type) := msd : X -> X -> Q.
-
-Class MetricSpace (X : Type) `{Equiv X} `{MetricSpaceBall X} `{MetricSpaceDistance X}: Prop :=
+Class ExtMetricSpace (X : Type) `{Equiv X} `{MetricSpaceBall X} : Prop :=
{ mspc_setoid :> Setoid X
; mspc_ball_proper:> Proper (=) B
- ; mspc_ball_negative: ∀ (e: Q), (e < 0)%Q → ∀ x y, ~ B e x y
+ ; mspc_ball_inf: ∀ x y, B Qinf.infinite x y
+ ; mspc_ball_negative: ∀ (e: Q), e < 0 → ∀ x y, ~ B e x y
; mspc_ball_zero: ∀ x y, B 0 x y ↔ x = y
- ; mspc_refl:> ∀ e : Q, (0 <= e)%Q → Reflexive (B e)
+ ; mspc_refl:> ∀ e : Q, 0 ≤ e → Reflexive (B e)
; mspc_sym:> ∀ e, Symmetric (B e)
- ; mspc_triangle: ∀ (e1 e2: Q) (a b c: X), B e1 a b → B e2 b c → B (e1 + e2) a c
- ; mspc_closed: ∀ (e: Q) (a b: X), (∀ d: Q, (0 < d)%Q -> B (e + d) a b) → B e a b
- ; mspc_distance: forall x1 x2 : X, B (msd x1 x2) x1 x2 }.
+ ; mspc_triangle: ∀ (e1 e2: Q) (a b c: X),
+ B e1 a b → B e2 b c → B (e1 + e2) a c
+ ; mspc_closed: ∀ (e: Q) (a b: X),
+ (∀ d: Q, 0 < d -> B (e + d) a b) → B e a b }.
+
+(*Class MetricSpaceBall (X : Type) : Type := mspc_ball: Q → relation X.
+
+Local Notation B := mspc_ball.*)
+
+Class MetricSpaceDistance (X : Type) := msd : X -> X -> Q.
+
+Class MetricSpace (X : Type) `{ExtMetricSpace X} `{MetricSpaceDistance X} : Prop :=
+ mspc_distance : forall x1 x2 : X, B (msd x1 x2) x1 x2.
-Section Coercion.
+(*Section Coercion.
Context `{MetricSpace X}.
@@ -121,7 +122,7 @@ end.
Global Instance : ExtMetricSpace X.
Admitted.
-End Coercion.
+End Coercion.*)
Section ExtMetricSpaceClass.
@@ -142,17 +143,17 @@ destruct (Qle_lt_or_eq _ _ A1) as [A2 | A2].
setoid_replace (q ↾ A1) with (from_Qpos (q ↾ A2)) by reflexivity; apply A.
setoid_replace (q ↾ A1) with 0 by (symmetry in A2; apply A2).
apply mspc_zero, A.
-Qed.
+Qed.*)
Lemma mspc_triangle' :
- ∀ (q1 q2 : Qnn) (b a c : X) (q : Qnn),
- q1 + q2 = q → mspc_ball q1 a b → mspc_ball q2 b c → mspc_ball q a c.
+ ∀ (q1 q2 : Q) (x2 x1 x3 : X) (q : Q),
+ q1 + q2 = q → B q1 x1 x2 → B q2 x2 x3 → B q x1 x3.
Proof.
-intros q1 q2 b a c q A1 A2 A3. rewrite <- A1. eapply mspc_triangle; eauto.
-Qed.*)
+intros q1 q2 x2 x1 x3 q A1 A2 A3. rewrite <- A1. eapply mspc_triangle; eauto.
+Qed.
Lemma mspc_monotone :
- ∀ q1 q2 : Q, q1 <= q2 -> ∀ x y : X, B' q1 x y → B' q2 x y.
+ ∀ q1 q2 : Q, q1 ≤ q2 -> ∀ x y : X, B q1 x y → B q2 x y.
Admitted.
(*Proof.
intros q1 q2 A1 x y A2.
@@ -169,6 +170,20 @@ Qed.*)
End ExtMetricSpaceClass.
+Section MetricSpaceClass.
+
+Context `{MetricSpace X}.
+
+Lemma msd_nonneg : forall x1 x2 : X, 0 ≤ msd x1 x2.
+Proof.
+intros x1 x2.
+assert (A := mspc_distance x1 x2).
+destruct (le_or_lt 0 (msd x1 x2)) as [A1 | A1]; trivial.
+contradict A; now apply mspc_ball_negative.
+Qed.
+
+End MetricSpaceClass.
+
Section UniformContinuity.
Context `{ExtMetricSpace X, ExtMetricSpace Y}.
@@ -176,18 +191,22 @@ Context `{ExtMetricSpace X, ExtMetricSpace Y}.
Class UniformlyContinuous (f : X -> Y) (mu : Q -> Qinf) := {
uc_proper :> Proper (=) f;
uc_pos : forall e : Q, 0 < e -> (0 < mu e);
- uc_prf : ∀ (e : Q) (x1 x2: X), 0 < e -> B' (mu e) x1 x2 → B' e (f x1) (f x2)
+ uc_prf : ∀ (e : Q) (x1 x2: X), 0 < e -> B (mu e) x1 x2 → B e (f x1) (f x2)
}.
Class Contraction (f : X -> Y) (q : Q) := {
contr_proper :> Proper (=) f;
- contr_nonneg_mu : 0 <= q;
+ contr_nonneg_mu : 0 ≤ q;
contr_lt_mu_1 : q < 1;
- contr_prf : forall (x1 x2 : X) (e : Q), B' e x1 x2 -> B' (q * e) (f x1) (f x2)
+ contr_prf : forall (x1 x2 : X) (e : Q), B e x1 x2 -> B (q * e) (f x1) (f x2)
}.
+Global Arguments contr_nonneg_mu f q {_} _.
+Global Arguments contr_lt_mu_1 f q {_}.
+Global Arguments contr_prf f q {_} _ _ _ _.
+
Definition contr_modulus (q e : Q) : Qinf :=
- if (decide (q = 0)) then 1 else (e / q)%Q.
+ if (decide (q = 0)) then 1 else (e / q).
Close Scope Qinf_scope.
@@ -198,12 +217,12 @@ apply fc.
intros e A. unfold contr_modulus. destruct (decide (q = 0)) as [A1 | A1].
Qsimpl; auto with qarith.
destruct fc as [_ A2 _ _]. apply Q.Qmult_lt_0_compat; [apply A | apply Qinv_lt_0_compat].
-revert A A1; Qsimpl; lra.
+revert A1 A2; Qsimpl; q_order.
intros e x1 x2 A1 A2. unfold contr_modulus in A2. destruct (decide (q = 0)) as [A | A].
-apply contr_prf in A2. rewrite A, Qmult_0_l in A2.
-apply mspc_monotone with (q1 := 0); trivial. apply Qlt_le_weak; trivial.
-apply contr_prf in A2. setoid_replace (q * (e / q)) with e in A2; trivial.
-Qsimpl A; field; trivial.
+apply (contr_prf f q) in A2. rewrite A, Qmult_0_l in A2.
+apply mspc_monotone with (q1 := 0); trivial. apply: Qlt_le_weak; trivial.
+apply (contr_prf f q) in A2. mc_setoid_replace (q * (e / q)) with e in A2; trivial.
+field; trivial.
Qed.
End UniformContinuity.
@@ -262,10 +281,10 @@ Section MetricSpaceDefs.
Context `{ExtMetricSpace X}.
Definition cauchy (x : sequence X) :=
- ∀ q : Qpos, ∃ N : nat, ∀ m n : nat, (N < m)%nat -> (N < n)%nat -> B' q (x m) (x n).
+ ∀ q : Qpos, ∃ N : nat, ∀ m n : nat, (N < m)%nat -> (N < n)%nat -> B q (x m) (x n).
Definition limit (x : sequence X) (a : X) :=
- ∀ q : Qpos, ∃ N : nat, ∀ n : nat, (N < n)%nat -> B' q (x n) a.
+ ∀ q : Qpos, ∃ N : nat, ∀ n : nat, (N < n)%nat -> B q (x n) a.
Definition complete := ∀ x : sequence X, cauchy x → ∃ a : X, limit x a.
@@ -309,15 +328,34 @@ Context `{MetricSpace X} (f : X -> X) `{!Contraction f q} (x0 : X).
Let x n := nat_iter n f x0.
+Lemma x_Sn : forall n, x n.+1 = f (x n).
+Proof. reflexivity. Qed.
+
Let d := msd (x 0) (x 1).
-Lemma dist_xn_xn' : forall n : nat, B (d * q^n)%mc (x n) (x n.+1).
+Lemma dist_xn_xSn : forall n : nat, B (d * q^n) (x n) (x n.+1).
Proof.
induction n using nat_induction.
+ rewrite nat_pow_0, right_identity; subst d; apply mspc_distance.
-+ rewrite nat_pow_S. setoid_replace (d * (q * q ^ n)) with (q * (d * q^n)) by (Qsimpl; lra).
- nat_simpl. simpl. subst x. simpl.
-apply (@contr_prf X H (@ExtMetricSpaceBall_instance_0 X H0)
-X H (@ExtMetricSpaceBall_instance_0 X H0) f q). assumption. assumption.
++ rewrite nat_pow_S. mc_setoid_replace (d * (q * q ^ n)) with (q * (d * q^n)) by ring.
+ nat_simpl; rewrite 2!x_Sn; now apply contr_prf.
+Qed.
+
+Lemma ne_q_1 : 1 - q ≠ 0.
+Proof.
+assert (A := contr_lt_mu_1 f q).
+rewrite <- flip_lt_negate in A. apply (strictly_order_preserving (1 +)) in A.
+rewrite plus_negate_r in A. now apply lt_ne_flip.
+Qed.
+
+Lemma dist_xm_xn : forall m n : nat, B (d * q^m * (1 - q^n) / (1 - q)) (x m) (x (m + n)%mc).
+Proof.
+intro m; induction n as [| n IH] using nat_induction.
++ rewrite right_identity; apply mspc_refl.
+ now rewrite nat_pow_0, plus_negate_r, right_absorb, left_absorb.
++ apply (mspc_triangle' (d * q^m * (1 - q^n) / (1 - q))%mc (d * q^(m + n))%mc (x (m + n)%mc)); trivial.
+ - rewrite nat_pow_S, nat_pow_exp_plus; field; apply ne_q_1.
+ - mc_setoid_replace (m + (1 + n)) with (1 + (m + n)) by ring. apply dist_xn_xSn.
Qed.
+End BanachFixpoint.
From 0b36eb482bc6c134a9718574d6cbdb7aac651008 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Mon, 21 May 2012 15:51:00 +0200
Subject: [PATCH 006/110] Proved lemma dist_xm_xn'
---
broken/metric.v | 49 ++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 38 insertions(+), 11 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index a9dba182..e4428a2e 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -10,6 +10,8 @@ Require Import interfaces.naturals interfaces.orders.
Add Field Q : (stdlib_field_theory Q).
+Bind Scope mc_scope with Q.
+
(*Import Qinf.notations.*)
Notation Qinf := Qinf.T.
Import peano_naturals.
@@ -328,12 +330,31 @@ Context `{MetricSpace X} (f : X -> X) `{!Contraction f q} (x0 : X).
Let x n := nat_iter n f x0.
-Lemma x_Sn : forall n, x n.+1 = f (x n).
+Arguments x n%mc.
+
+Lemma x_Sn : forall n, x (1 + n) = f (x n).
Proof. reflexivity. Qed.
Let d := msd (x 0) (x 1).
-Lemma dist_xn_xSn : forall n : nat, B (d * q^n) (x n) (x n.+1).
+Instance : PropHolds (0 ≤ d).
+Proof. apply msd_nonneg. Qed.
+
+Instance : PropHolds (0 ≤ q).
+Proof. apply (contr_nonneg_mu f q). Qed.
+
+Instance : PropHolds (0 < 1 - q).
+Proof.
+assert (A := contr_lt_mu_1 f q).
+rewrite <- flip_lt_negate in A. apply (strictly_order_preserving (1 +)) in A.
+now rewrite plus_negate_r in A.
+Qed.
+
+Instance pos_ne_0 : forall `{StrictSetoidOrder A} `{Zero A} (x : A),
+ PropHolds (0 < x) -> PropHolds (x ≠ 0).
+Proof. intros; now apply lt_ne_flip. Qed.
+
+Lemma dist_xn_xSn : forall n : nat, B (d * q^n) (x n) (x (1 + n)).
Proof.
induction n using nat_induction.
+ rewrite nat_pow_0, right_identity; subst d; apply mspc_distance.
@@ -341,21 +362,27 @@ induction n using nat_induction.
nat_simpl; rewrite 2!x_Sn; now apply contr_prf.
Qed.
-Lemma ne_q_1 : 1 - q ≠ 0.
-Proof.
-assert (A := contr_lt_mu_1 f q).
-rewrite <- flip_lt_negate in A. apply (strictly_order_preserving (1 +)) in A.
-rewrite plus_negate_r in A. now apply lt_ne_flip.
-Qed.
+(*Lemma nonzero_1_minus_q : 1 - q ≠ 0.
+Proof. apply lt_ne_flip, pos_1_minus_q. Qed.*)
-Lemma dist_xm_xn : forall m n : nat, B (d * q^m * (1 - q^n) / (1 - q)) (x m) (x (m + n)%mc).
+Lemma dist_xm_xn : forall m n : nat, B (d * q^m * (1 - q^n) / (1 - q)) (x m) (x (m + n)).
Proof.
intro m; induction n as [| n IH] using nat_induction.
+ rewrite right_identity; apply mspc_refl.
now rewrite nat_pow_0, plus_negate_r, right_absorb, left_absorb.
-+ apply (mspc_triangle' (d * q^m * (1 - q^n) / (1 - q))%mc (d * q^(m + n))%mc (x (m + n)%mc)); trivial.
- - rewrite nat_pow_S, nat_pow_exp_plus; field; apply ne_q_1.
++ apply (mspc_triangle' (d * q^m * (1 - q^n) / (1 - q)) (d * q^(m + n)) (x (m + n))); trivial.
+ - rewrite nat_pow_S, nat_pow_exp_plus. field; solve_propholds.
- mc_setoid_replace (m + (1 + n)) with (1 + (m + n)) by ring. apply dist_xn_xSn.
Qed.
+Lemma dist_xm_xn' : forall m n : nat, B (d * q^m / (1 - q)) (x m) (x (m + n)).
+Proof.
+intros m n. apply (mspc_monotone (d * q^m * (1 - q^n) / (1 - q))); [| apply dist_xm_xn].
+apply (order_preserving (.* /(1 - q))). rewrite <- associativity.
+apply (order_preserving (d *.)). rewrite <- (mult_1_r (q^m)) at 2.
+apply (order_preserving (q^m *.)). rewrite <- (plus_0_r 1) at 2.
+apply (order_preserving (1 +)). rewrite <- negate_0.
+apply <- flip_le_negate. solve_propholds.
+Qed.
+
End BanachFixpoint.
From 4f0a09f57bca82983b0dccbddbd78f4cd33c58f2 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 1 Jun 2012 14:19:59 +0200
Subject: [PATCH 007/110] Defined complete metric spaces
---
broken/metric.v | 88 +++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 74 insertions(+), 14 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index e4428a2e..4ebded12 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -77,7 +77,8 @@ Ltac nat_simpl := unfold
Tactic Notation "Qsimpl" hyp_list(A) := revert A; Qsimpl'; intros A.
-(*Open Scope Q_scope.*)
+Lemma plus_comm `{SemiRing R} (x y : R) : x + y = y + x.
+Proof. rapply commonoid_commutative; apply _. Qed.
Class MetricSpaceBall (X : Type) : Type := mspc_ball: Qinf → relation X.
@@ -276,23 +277,86 @@ Qed.
End UCFMetricSpace.
*)
-Definition sequence (X : Type) := nat -> X.
+Instance pos_ne_0 : forall `{StrictSetoidOrder A} `{Zero A} (x : A),
+ PropHolds (0 < x) -> PropHolds (x ≠ 0).
+Proof. intros; now apply lt_ne_flip. Qed.
+
+Section Isometry.
+
+Context `{ExtMetricSpace X, ExtMetricSpace Y}.
+
+Class Isometry (f : X -> Y) :=
+ isometry : forall (e : Q) (x1 x2 : X), B e x1 x2 <-> B e (f x1) (f x2).
+
+Global Instance isometry_injective `{Isometry f} : Injective f.
+Proof.
+constructor; [| constructor]; try apply _; intros x y; rewrite <- !mspc_ball_zero;
+intros ?; [apply <- isometry | apply -> isometry]; trivial.
+Qed.
+
+Class IsometricIsomorphism (f : X -> Y) (g : Inverse f) := {
+ isometric_isomorphism_isometry :> Isometry f;
+ isometric_isomorphism_surjection :> Surjective f
+}.
-Section MetricSpaceDefs.
+End Isometry.
+
+Section CompleteMetricSpace.
Context `{ExtMetricSpace X}.
-Definition cauchy (x : sequence X) :=
- ∀ q : Qpos, ∃ N : nat, ∀ m n : nat, (N < m)%nat -> (N < n)%nat -> B q (x m) (x n).
+Class IsRegularFunction (f : Q -> X) : Prop :=
+ cauchy : forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> B (e1 + e2) (f e1) (f e2).
-Definition limit (x : sequence X) (a : X) :=
- ∀ q : Qpos, ∃ N : nat, ∀ n : nat, (N < n)%nat -> B q (x n) a.
+Record RegularFunction := {
+ rf_func :> Q -> X;
+ rf_proof : IsRegularFunction rf_func
+}.
-Definition complete := ∀ x : sequence X, cauchy x → ∃ a : X, limit x a.
+Arguments Build_RegularFunction {_} _.
-End MetricSpaceDefs.
+Global Existing Instance rf_proof.
-Arguments complete X {_} : clear implicits.
+Instance rf_eq : Equiv RegularFunction :=
+ λ f1 f2, forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> B (e1 + e2) (f1 e1) (f2 e2).
+
+Instance rf_setoid : Setoid RegularFunction.
+Proof.
+constructor.
++ intros f e1 e2; apply cauchy.
++ intros f1 f2 A e1 e2 A1 A2. rewrite plus_comm. now apply mspc_sym, A.
++ intros f1 f2 f3 A1 A2 e1 e3 A3 A4. apply mspc_closed. intros d A5.
+ mc_setoid_replace (e1 + e3 + d) with ((e1 + d / 2) + (e3 + d / 2))
+ by (field; change ((2 : Q) ≠ 0); solve_propholds).
+ apply mspc_triangle with (b := f2 (d / 2));
+ [apply A1 | rewrite plus_comm; apply A2]; try solve_propholds.
+Qed.
+
+Instance rf_msb : MetricSpaceBall RegularFunction :=
+ λ e f1 f2, forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> B (e + e1 + e2) (f1 e1) (f2 e2).
+
+Instance rf_mspc : ExtMetricSpace RegularFunction.
+Proof.
+constructor.
+apply _.
+Admitted.
+
+Lemma unit_reg (x : X) : IsRegularFunction (λ _, x).
+Proof. intros e1 e2 A1 A2; apply mspc_refl; solve_propholds. Qed.
+
+Definition reg_unit (x : X) := Build_RegularFunction (unit_reg x).
+
+Class Limit := lim : RegularFunction -> X.
+
+Class CompleteMetricSpace `{Limit} := cmspc : IsometricIsomorphism reg_unit lim.
+
+Lemma limit_def `{CompleteMetricSpace} (f : RegularFunction) :
+ forall e : Q, 0 < e -> B e (f e) (lim f).
+Proof.
+intros e A.
+Admitted.
+
+End CompleteMetricSpace.
(*Section MetricSpaceLimits.
@@ -350,10 +414,6 @@ rewrite <- flip_lt_negate in A. apply (strictly_order_preserving (1 +)) in A.
now rewrite plus_negate_r in A.
Qed.
-Instance pos_ne_0 : forall `{StrictSetoidOrder A} `{Zero A} (x : A),
- PropHolds (0 < x) -> PropHolds (x ≠ 0).
-Proof. intros; now apply lt_ne_flip. Qed.
-
Lemma dist_xn_xSn : forall n : nat, B (d * q^n) (x n) (x (1 + n)).
Proof.
induction n using nat_induction.
From fb046cf74a145abd90ef850d9adc6a9e744ef9a8 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 5 Jun 2012 14:58:18 +0200
Subject: [PATCH 008/110] Defined complete metric space
---
broken/metric.v | 83 +++++++++++++++++++++++++------------------------
1 file changed, 42 insertions(+), 41 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index 4ebded12..b4585f4f 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -230,14 +230,6 @@ Qed.
End UniformContinuity.
-(*
-Why does
-SearchPattern (@Proper _ (@equiv (Q -> Qinf) _) _).
-work but
-SearchPattern (@Proper _ (@equiv _ _) _).
-does not?
-*)
-
(*Section UCFMetricSpace.
Context `{MetricSpaceClass X, MetricSpaceClass Y}.
@@ -281,6 +273,7 @@ Instance pos_ne_0 : forall `{StrictSetoidOrder A} `{Zero A} (x : A),
PropHolds (0 < x) -> PropHolds (x ≠ 0).
Proof. intros; now apply lt_ne_flip. Qed.
+(*
Section Isometry.
Context `{ExtMetricSpace X, ExtMetricSpace Y}.
@@ -300,6 +293,41 @@ Class IsometricIsomorphism (f : X -> Y) (g : Inverse f) := {
}.
End Isometry.
+*)
+
+Definition seq A := nat -> A.
+
+Section MetricSpaceLimits.
+
+Context `{ExtMetricSpace X, ExtMetricSpace Y}.
+
+(*Definition slim (x : seq X) (a : X) :=
+ forall
+
+Theorem limit_unique : ∀ (x : seq X) (a b : X), limit x a → limit x b → a = b.
+Proof.
+intros x a b A1 A2; apply mspc_eq'; intro q.
+specialize (A1 (q / 2)); specialize (A2 (q / 2)).
+destruct A1 as [N1 A1]; destruct A2 as [N2 A2].
+set (N := S (Peano.max N1 N2)). specialize (A1 N); specialize (A2 N).
+apply (mspc_triangle' (q / 2) (q / 2) (x N));
+[Qsimpl; field | apply mspc_symm |];
+[apply A1 | apply A2]; subst N; lia.
+Qed.
+
+Theorem limit_cont : ∀ (f : UniformlyContinuous X Y) (x : seq X) (a : X),
+ limit x a → limit (f ∘ x) (f a).
+Proof.
+intros f x a A1 q.
+specialize (A1 (uc_mu f q)).
+destruct A1 as [N A1]. exists N; intros n A2. now apply uc_prf, A1.
+Qed.
+
+Theorem limit_contr : ∀ (f : Contraction X Y) (x : seq X) (a : X),
+ limit x a → limit (f ∘ x) (f a).
+Proof. intro f; apply (limit_cont f). Qed.*)
+
+End MetricSpaceLimits.
Section CompleteMetricSpace.
@@ -348,45 +376,18 @@ Definition reg_unit (x : X) := Build_RegularFunction (unit_reg x).
Class Limit := lim : RegularFunction -> X.
-Class CompleteMetricSpace `{Limit} := cmspc : IsometricIsomorphism reg_unit lim.
+Class CompleteMetricSpace `{Limit} := cmspc :> Surjective reg_unit (inv := lim).
Lemma limit_def `{CompleteMetricSpace} (f : RegularFunction) :
forall e : Q, 0 < e -> B e (f e) (lim f).
Proof.
-intros e A.
-Admitted.
-
-End CompleteMetricSpace.
-
-(*Section MetricSpaceLimits.
-
-Context `{MetricSpaceClass X, MetricSpaceClass Y}.
-
-Theorem limit_unique : ∀ (x : sequence X) (a b : X), limit x a → limit x b → a = b.
-Proof.
-intros x a b A1 A2; apply mspc_eq'; intro q.
-specialize (A1 (q / 2)); specialize (A2 (q / 2)).
-destruct A1 as [N1 A1]; destruct A2 as [N2 A2].
-set (N := S (Peano.max N1 N2)). specialize (A1 N); specialize (A2 N).
-apply (mspc_triangle' (q / 2) (q / 2) (x N));
-[Qsimpl; field | apply mspc_symm |];
-[apply A1 | apply A2]; subst N; lia.
-Qed.
-
-Theorem limit_cont : ∀ (f : UniformlyContinuous X Y) (x : sequence X) (a : X),
- limit x a → limit (f ∘ x) (f a).
-Proof.
-intros f x a A1 q.
-specialize (A1 (uc_mu f q)).
-destruct A1 as [N A1]. exists N; intros n A2. now apply uc_prf, A1.
+intros e2 A2. apply mspc_sym; apply mspc_closed.
+(* [apply mspc_sym, mspc_closed.] does not work *)
+intros e1 A1. change (lim f) with (reg_unit (lim f) e1). rewrite plus_comm.
+rapply (surjective reg_unit (inv := lim)); trivial; reflexivity.
Qed.
-Theorem limit_contr : ∀ (f : Contraction X Y) (x : sequence X) (a : X),
- limit x a → limit (f ∘ x) (f a).
-Proof. intro f; apply (limit_cont f). Qed.
-
-End MetricSpaceLimits.
-*)
+End CompleteMetricSpace.
Section BanachFixpoint.
From b49bee409c6f6e990622123b9d494be89e6a9024 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 12 Jun 2012 16:25:18 +0200
Subject: [PATCH 009/110] Proved theorems about limits and continuous
functions, contractions
---
broken/metric.v | 334 +++++++++++++++++++++++++++++-------------------
1 file changed, 202 insertions(+), 132 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index b4585f4f..0a16cb10 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -5,9 +5,19 @@ Require Import
(*Import (*QnonNeg.notations*) QArith.*)
Require Import Qauto QOrderedType.
(*Require Import orders.*)
-Require Import theory.rings theory.dec_fields orders.rings nat_pow.
+Require Import theory.rings theory.dec_fields orders.rings orders.dec_fields nat_pow.
Require Import interfaces.naturals interfaces.orders.
+Lemma neq_symm `{Ae : Equiv X} `{!Symmetric Ae} (x y : X) : x ≠ y -> y ≠ x.
+Proof. intros A1 A2; apply A1; now symmetry. Qed.
+
+Lemma plus_comm `{SemiRing R} (x y : R) : x + y = y + x.
+Proof. rapply commonoid_commutative; apply _. Qed.
+
+Instance pos_ne_0 : forall `{StrictSetoidOrder A} `{Zero A} (x : A),
+ PropHolds (0 < x) -> PropHolds (x ≠ 0).
+Proof. intros; now apply lt_ne_flip. Qed.
+
Add Field Q : (stdlib_field_theory Q).
Bind Scope mc_scope with Q.
@@ -77,9 +87,6 @@ Ltac nat_simpl := unfold
Tactic Notation "Qsimpl" hyp_list(A) := revert A; Qsimpl'; intros A.
-Lemma plus_comm `{SemiRing R} (x y : R) : x + y = y + x.
-Proof. rapply commonoid_commutative; apply _. Qed.
-
Class MetricSpaceBall (X : Type) : Type := mspc_ball: Qinf → relation X.
Local Notation B := mspc_ball.
@@ -92,10 +99,10 @@ axiom that no points are separated by a negative distance. *)
Class ExtMetricSpace (X : Type) `{Equiv X} `{MetricSpaceBall X} : Prop :=
{ mspc_setoid :> Setoid X
- ; mspc_ball_proper:> Proper (=) B
- ; mspc_ball_inf: ∀ x y, B Qinf.infinite x y
- ; mspc_ball_negative: ∀ (e: Q), e < 0 → ∀ x y, ~ B e x y
- ; mspc_ball_zero: ∀ x y, B 0 x y ↔ x = y
+ ; mspc_proper:> Proper (=) B
+ ; mspc_inf: ∀ x y, B Qinf.infinite x y
+ ; mspc_negative: ∀ (e: Q), e < 0 → ∀ x y, ~ B e x y
+ ; mspc_zero: ∀ x y, B 0 x y ↔ x = y
; mspc_refl:> ∀ e : Q, 0 ≤ e → Reflexive (B e)
; mspc_sym:> ∀ e, Symmetric (B e)
; mspc_triangle: ∀ (e1 e2: Q) (a b c: X),
@@ -103,51 +110,26 @@ Class ExtMetricSpace (X : Type) `{Equiv X} `{MetricSpaceBall X} : Prop :=
; mspc_closed: ∀ (e: Q) (a b: X),
(∀ d: Q, 0 < d -> B (e + d) a b) → B e a b }.
-(*Class MetricSpaceBall (X : Type) : Type := mspc_ball: Q → relation X.
-
-Local Notation B := mspc_ball.*)
+(*
+This shows that if axioms of metric space are formulated with Qinf instead of Q,
+the [apply] tactic won't be able to unify them with goals using Q
+
+Goal (forall (e1 e2 : Qinf) (x1 x2 : X), B (e1 + e2) x1 x2) ->
+ (forall (e1 e2 : Q) (x1 x2 : X), B (e1 + e2) x1 x2).
+intros A e1 e2 x1 x2.
+change (e1 + e2 : Qinf) with ((Qinf.finite e1) + (Qinf.finite e2)).
+apply A.
+*)
Class MetricSpaceDistance (X : Type) := msd : X -> X -> Q.
Class MetricSpace (X : Type) `{ExtMetricSpace X} `{MetricSpaceDistance X} : Prop :=
mspc_distance : forall x1 x2 : X, B (msd x1 x2) x1 x2.
-(*Section Coercion.
-
-Context `{MetricSpace X}.
-
-Global Instance : ExtMetricSpaceBall X := λ e : Qinf,
-match e with
-| Qinf.infinite => λ _ _, True
-| Qinf.finite e => B e
-end.
-
-Global Instance : ExtMetricSpace X.
-Admitted.
-
-End Coercion.*)
-
-Section ExtMetricSpaceClass.
+Section ExtMetricSpace.
Context `{ExtMetricSpace X}.
-(*Program Definition Qnn_minus `(A : q1 <= q2) : Qnn := (q2 - q1)%Q.
-Next Obligation. lra. Qed.
-
-Lemma mspc_zero : ∀ x y : X, (∀ q : Qpos, mspc_ball q x y) → mspc_ball 0 x y.
-Proof.
-intros x y A. apply mspc_closed; intro d. rewrite plus_0_l; trivial.
-Qed.
-
-Lemma mspc_eq' : ∀ x y : X, (∀ q : Qpos, mspc_ball q x y) → x = y.
-Proof.
-intros x y A; apply mspc_eq; intros [q A1].
-destruct (Qle_lt_or_eq _ _ A1) as [A2 | A2].
-setoid_replace (q ↾ A1) with (from_Qpos (q ↾ A2)) by reflexivity; apply A.
-setoid_replace (q ↾ A1) with 0 by (symmetry in A2; apply A2).
-apply mspc_zero, A.
-Qed.*)
-
Lemma mspc_triangle' :
∀ (q1 q2 : Q) (x2 x1 x3 : X) (q : Q),
q1 + q2 = q → B q1 x1 x2 → B q2 x2 x3 → B q x1 x3.
@@ -157,23 +139,25 @@ Qed.
Lemma mspc_monotone :
∀ q1 q2 : Q, q1 ≤ q2 -> ∀ x y : X, B q1 x y → B q2 x y.
-Admitted.
-(*Proof.
+Proof.
intros q1 q2 A1 x y A2.
-setoid_replace q2 with (q1 + (Qnn_minus A1)).
-apply mspc_triangle with (b := y); [| apply mspc_refl]; trivial.
-unfold Qnn_minus; Qsimpl; lra.
-Qed.*)
+apply (mspc_triangle' q1 (q2 - q1) y); [ring | trivial |]. apply mspc_refl.
+apply (order_preserving (+ (-q1))) in A1. now rewrite plus_negate_r in A1.
+Qed.
-(*Lemma mspc_zero_eq : ∀ x y : X, mspc_ball 0 x y ↔ x = y.
+Lemma mspc_zero' : ∀ x y : X, (∀ e : Q, 0 < e -> B e x y) ↔ B 0 x y.
Proof.
-intros x y; split; intro A1; [| rewrite A1; apply mspc_refl].
-apply mspc_eq. intro q; apply (mspc_monotone 0); trivial. apply (proj2_sig q).
-Qed.*)
+intros x y; split; intro A.
++ apply mspc_closed; intro d. change 0%Q with (@zero Q _); rewrite plus_0_l; apply A.
++ intros e e_pos. apply (mspc_monotone 0); trivial; solve_propholds.
+Qed.
-End ExtMetricSpaceClass.
+Lemma mspc_eq : ∀ x y : X, (∀ e : Q, 0 < e -> B e x y) ↔ x = y.
+Proof. intros x y. rewrite <- mspc_zero. apply mspc_zero'. Qed.
-Section MetricSpaceClass.
+End ExtMetricSpace.
+
+Section MetricSpace.
Context `{MetricSpace X}.
@@ -182,23 +166,40 @@ Proof.
intros x1 x2.
assert (A := mspc_distance x1 x2).
destruct (le_or_lt 0 (msd x1 x2)) as [A1 | A1]; trivial.
-contradict A; now apply mspc_ball_negative.
+contradict A; now apply mspc_negative.
Qed.
-End MetricSpaceClass.
+End MetricSpace.
+
+Lemma le_not_eq `{FullPartialOrder A} (x y : A) : x ≤ y -> x ≶ y -> x < y.
+Proof. intros ? ?; apply lt_iff_le_apart; now split. Qed.
Section UniformContinuity.
Context `{ExtMetricSpace X, ExtMetricSpace Y}.
-Class UniformlyContinuous (f : X -> Y) (mu : Q -> Qinf) := {
- uc_proper :> Proper (=) f;
+Class IsUniformlyContinuous (f : X -> Y) (mu : Q -> Qinf) := {
uc_pos : forall e : Q, 0 < e -> (0 < mu e);
uc_prf : ∀ (e : Q) (x1 x2: X), 0 < e -> B (mu e) x1 x2 → B e (f x1) (f x2)
}.
-Class Contraction (f : X -> Y) (q : Q) := {
- contr_proper :> Proper (=) f;
+Global Arguments uc_pos f mu {_} e _.
+Global Arguments uc_prf f mu {_} e x1 x2 _ _.
+
+Global Instance uc_proper `{IsUniformlyContinuous f mu} : Proper ((=) ==> (=)) f.
+Proof.
+intros x1 x2 A. apply mspc_eq. intros e e_pos. apply (uc_prf f mu); trivial.
+pose proof (uc_pos f mu e e_pos) as ?.
+destruct (mu e); [apply mspc_eq; trivial | apply mspc_inf].
+Qed.
+
+End UniformContinuity.
+
+Section Contractions.
+
+Context `{MetricSpace X, ExtMetricSpace Y}.
+
+Class IsContraction (f : X -> Y) (q : Q) := {
contr_nonneg_mu : 0 ≤ q;
contr_lt_mu_1 : q < 1;
contr_prf : forall (x1 x2 : X) (e : Q), B e x1 x2 -> B (q * e) (f x1) (f x2)
@@ -209,34 +210,31 @@ Global Arguments contr_lt_mu_1 f q {_}.
Global Arguments contr_prf f q {_} _ _ _ _.
Definition contr_modulus (q e : Q) : Qinf :=
- if (decide (q = 0)) then 1 else (e / q).
-
-Close Scope Qinf_scope.
+ if (decide (0 = q)) then Qinf.infinite else (e / q).
-Instance contr_to_uc : forall `(Contraction f q), UniformlyContinuous f (contr_modulus q).
+Global Instance contr_to_uc `(IsContraction f q) :
+ IsUniformlyContinuous f (contr_modulus q).
Proof.
-intros f q fc. constructor.
-apply fc.
-intros e A. unfold contr_modulus. destruct (decide (q = 0)) as [A1 | A1].
-Qsimpl; auto with qarith.
-destruct fc as [_ A2 _ _]. apply Q.Qmult_lt_0_compat; [apply A | apply Qinv_lt_0_compat].
-revert A1 A2; Qsimpl; q_order.
-intros e x1 x2 A1 A2. unfold contr_modulus in A2. destruct (decide (q = 0)) as [A | A].
-apply (contr_prf f q) in A2. rewrite A, Qmult_0_l in A2.
-apply mspc_monotone with (q1 := 0); trivial. apply: Qlt_le_weak; trivial.
-apply (contr_prf f q) in A2. mc_setoid_replace (q * (e / q)) with e in A2; trivial.
-field; trivial.
+constructor.
++ intros e A. unfold contr_modulus. destruct (decide (0 = q)) as [A1 | A1]; [apply I |].
+ change (0 < e / q). (* Changes from Qinf, which is not declared as ordered ring, to Q *)
+ pose proof (contr_nonneg_mu f q) as A2. pose proof (le_not_eq _ _ A2 A1). solve_propholds.
++ intros e x1 x2 A1 A2. unfold contr_modulus in A2. destruct (decide (0 = q)) as [A | A].
+ - assert (A3 := contr_prf f q x1 x2 (msd x1 x2) (mspc_distance x1 x2)).
+ rewrite <- A, mult_0_l in A3; now apply mspc_zero'.
+ - mc_setoid_replace e with (q * (e / q)) by (field; now apply neq_symm).
+ now apply contr_prf.
Qed.
-End UniformContinuity.
+End Contractions.
(*Section UCFMetricSpace.
Context `{MetricSpaceClass X, MetricSpaceClass Y}.
-Instance UCFEquiv : Equiv (UniformlyContinuous X Y) := @equiv (X -> Y) _.
+Instance UCFEquiv : Equiv (IsUniformlyContinuous X Y) := @equiv (X -> Y) _.
-Lemma UCFSetoid : Setoid (UniformlyContinuous X Y).
+Lemma UCFSetoid : Setoid (IsUniformlyContinuous X Y).
Proof.
constructor.
intros f x y A; now rewrite A.
@@ -244,17 +242,17 @@ intros f g A1 x y A2; rewrite A2; symmetry; now apply A1.
intros f g h A1 A2 x y A3; rewrite A3; now transitivity (g y); [apply A1 | apply A2].
Qed.
-Instance UCFSpaceBall : MetricSpaceBall (UniformlyContinuous X Y) :=
- fun q f g => forall x, mspc_ball q (f x) (g x).
+Instance UCFSpaceBall : MetricSpaceBall (IsUniformlyContinuous X Y) :=
+ fun q f g => forall x, B q (f x) (g x).
-Lemma UCFBallProper : Proper equiv mspc_ball.
+Lemma UCFBallProper : Proper equiv B.
Proof.
intros q1 q2 A1 f1 f2 A2 g1 g2 A3; split; intros A4 x.
+ rewrite <- A1. rewrite <- (A2 x x); [| reflexivity]. rewrite <- (A3 x x); [| reflexivity]. apply A4.
+ rewrite A1. rewrite (A2 x x); [| reflexivity]. rewrite (A3 x x); [| reflexivity]. apply A4.
Qed.
-Global Instance : MetricSpaceClass (UniformlyContinuous X Y).
+Global Instance : MetricSpaceClass (IsUniformlyContinuous X Y).
Proof.
constructor.
apply UCFSetoid.
@@ -269,10 +267,6 @@ Qed.
End UCFMetricSpace.
*)
-Instance pos_ne_0 : forall `{StrictSetoidOrder A} `{Zero A} (x : A),
- PropHolds (0 < x) -> PropHolds (x ≠ 0).
-Proof. intros; now apply lt_ne_flip. Qed.
-
(*
Section Isometry.
@@ -283,7 +277,7 @@ Class Isometry (f : X -> Y) :=
Global Instance isometry_injective `{Isometry f} : Injective f.
Proof.
-constructor; [| constructor]; try apply _; intros x y; rewrite <- !mspc_ball_zero;
+constructor; [| constructor]; try apply _; intros x y; rewrite <- !B_zero;
intros ?; [apply <- isometry | apply -> isometry]; trivial.
Qed.
@@ -295,46 +289,14 @@ Class IsometricIsomorphism (f : X -> Y) (g : Inverse f) := {
End Isometry.
*)
-Definition seq A := nat -> A.
-
-Section MetricSpaceLimits.
-
-Context `{ExtMetricSpace X, ExtMetricSpace Y}.
-
-(*Definition slim (x : seq X) (a : X) :=
- forall
-
-Theorem limit_unique : ∀ (x : seq X) (a b : X), limit x a → limit x b → a = b.
-Proof.
-intros x a b A1 A2; apply mspc_eq'; intro q.
-specialize (A1 (q / 2)); specialize (A2 (q / 2)).
-destruct A1 as [N1 A1]; destruct A2 as [N2 A2].
-set (N := S (Peano.max N1 N2)). specialize (A1 N); specialize (A2 N).
-apply (mspc_triangle' (q / 2) (q / 2) (x N));
-[Qsimpl; field | apply mspc_symm |];
-[apply A1 | apply A2]; subst N; lia.
-Qed.
-
-Theorem limit_cont : ∀ (f : UniformlyContinuous X Y) (x : seq X) (a : X),
- limit x a → limit (f ∘ x) (f a).
-Proof.
-intros f x a A1 q.
-specialize (A1 (uc_mu f q)).
-destruct A1 as [N A1]. exists N; intros n A2. now apply uc_prf, A1.
-Qed.
-
-Theorem limit_contr : ∀ (f : Contraction X Y) (x : seq X) (a : X),
- limit x a → limit (f ∘ x) (f a).
-Proof. intro f; apply (limit_cont f). Qed.*)
-
-End MetricSpaceLimits.
-
Section CompleteMetricSpace.
Context `{ExtMetricSpace X}.
Class IsRegularFunction (f : Q -> X) : Prop :=
- cauchy : forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> B (e1 + e2) (f e1) (f e2).
+ rf_prf : forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> B (e1 + e2) (f e1) (f e2).
+
+Require Import interfaces.monads.
Record RegularFunction := {
rf_func :> Q -> X;
@@ -351,7 +313,7 @@ Instance rf_eq : Equiv RegularFunction :=
Instance rf_setoid : Setoid RegularFunction.
Proof.
constructor.
-+ intros f e1 e2; apply cauchy.
++ intros f e1 e2; apply rf_prf.
+ intros f1 f2 A e1 e2 A1 A2. rewrite plus_comm. now apply mspc_sym, A.
+ intros f1 f2 f3 A1 A2 e1 e3 A3 A4. apply mspc_closed. intros d A5.
mc_setoid_replace (e1 + e3 + d) with ((e1 + d / 2) + (e3 + d / 2))
@@ -363,12 +325,6 @@ Qed.
Instance rf_msb : MetricSpaceBall RegularFunction :=
λ e f1 f2, forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> B (e + e1 + e2) (f1 e1) (f2 e2).
-Instance rf_mspc : ExtMetricSpace RegularFunction.
-Proof.
-constructor.
-apply _.
-Admitted.
-
Lemma unit_reg (x : X) : IsRegularFunction (λ _, x).
Proof. intros e1 e2 A1 A2; apply mspc_refl; solve_propholds. Qed.
@@ -389,9 +345,123 @@ Qed.
End CompleteMetricSpace.
+Definition seq A := nat -> A.
+
+Section SequenceLimits.
+
+Context `{ExtMetricSpace X}.
+
+Definition seq_lim (x : seq X) (a : X) (N : Q -> nat) :=
+ forall e : Q, 0 < e -> forall n : nat, N e ≤ n -> B e (x n) a.
+
+(*Hint Unfold seq : typeclass_instances.*)
+(* This unfolds [seq X] as [nat -> X] and allows ext_equiv to find an
+instance of [Equiv (seq X)] *)
+
+Instance : Proper (((=) ==> (=)) ==> (=) ==> (=) ==> iff) seq_lim.
+Proof.
+intros x1 x2 A1 a1 a2 A2 N1 N2 A3; split; intros A e e_pos n A4.
++ mc_setoid_replace (x2 n) with (x1 n) by (symmetry; now apply A1).
+ rewrite <- A2. mc_setoid_replace (N2 e) with (N1 e) in A4 by (symmetry; now apply A3).
+ now apply A.
++ mc_setoid_replace (x1 n) with (x2 n) by now apply A1.
+ rewrite A2. mc_setoid_replace (N1 e) with (N2 e) in A4 by now apply A3.
+ now apply A.
+Qed.
+
+Lemma seq_lim_unique : ∀ (x : seq X) (a1 a2 : X) N1 N2, seq_lim x a1 N1 → seq_lim x a2 N2 → a1 = a2.
+Proof.
+intros x a1 a2 N1 N2 A1 A2. apply mspc_eq; intros q A.
+assert (A3 : 0 < q / 2) by solve_propholds.
+specialize (A1 (q / 2) A3); specialize (A2 (q / 2) A3).
+set (M := Peano.max (N1 (q / 2)) (N2 (q / 2))).
+assert (A4 : N1 (q / 2) ≤ M) by apply le_max_l.
+assert (A5 : N2 (q / 2) ≤ M) by apply le_max_r.
+specialize (A1 M A4); specialize (A2 M A5).
+apply mspc_sym in A1.
+apply (mspc_triangle' (q / 2) (q / 2) (x M)); trivial.
+field; change ((2 : Q) ≠ 0); solve_propholds.
+Qed.
+
+Lemma seq_lim_S (x : seq X) (a : X) N : seq_lim x a N -> seq_lim (x ∘ S) a N.
+Proof. intros A e A1 n A2. apply A; trivial. apply le_S, A2. Qed.
+
+Lemma seq_lim_S' (x : seq X) (a : X) N : seq_lim (x ∘ S) a N -> seq_lim x a (S ∘ N).
+Proof.
+intros A e A1 n A2.
+destruct n as [| n].
++ contradict A2; apply le_Sn_0.
++ apply A; trivial. apply le_S_n, A2.
+Qed.
+
+End SequenceLimits.
+
+Definition comp_inf {X Z : Type} (g : Q -> Z) (f : X -> Qinf) (inf : Z) (x : X) :=
+match (f x) with
+| Qinf.finite y => g y
+| Qinf.infinite => inf
+end.
+
+Section ContinuousFunctionSequence.
+
+Context `{ExtMetricSpace X, ExtMetricSpace Y} (f : X -> Y).
+
+Theorem seq_lim_cont `{!IsUniformlyContinuous f mu} (x : seq X) (a : X) (N : Q -> nat) :
+ seq_lim x a N → seq_lim (f ∘ x) (f a) (comp_inf N mu 0).
+Proof.
+intros A e e_pos n A1. apply (uc_prf f mu); trivial.
+unfold comp_inf in A1; assert (A2 := uc_pos f mu e e_pos).
+now destruct (mu e); [apply A | apply mspc_inf].
+Qed.
+
+(* Now suppose that X is a regular metric space *)
+Context `{MetricSpaceDistance X} `{@MetricSpace X _ _ _ _}.
+
+Theorem seq_lim_contr `{!IsContraction f q} (x : seq X) (a : X) (N : Q -> nat) :
+ seq_lim x a N → seq_lim (f ∘ x) (f a) (comp_inf N (contr_modulus q) 0).
+Proof. intro A; now apply seq_lim_cont. Qed.
+
+End ContinuousFunctionSequence.
+
+Section CompleteSpaceSequenceLimits.
+
+Context `{CompleteMetricSpace X}.
+
+Definition cauchy (x : seq X) (N : Q -> nat) :=
+ forall e : Q, 0 < e -> forall m n : nat, N e ≤ m -> N e ≤ n -> B e (x m) (x n).
+
+Definition reg_fun (x : seq X) (N : Q -> nat) (A : cauchy x N) : RegularFunction.
+refine (Build_RegularFunction (x ∘ N) _).
+(* without loss of generality, N e1 ≤ N e2 *)
+assert (A3 : forall e1 e2, 0 < e1 -> 0 < e2 -> N e1 ≤ N e2 -> B (e1 + e2) ((x ∘ N) e1) ((x ∘ N) e2)).
++ intros e1 e2 A1 A2 A3.
+ apply (mspc_monotone e1).
+ - apply (strictly_order_preserving (e1 +)) in A2; rewrite plus_0_r in A2; solve_propholds.
+ - apply A; trivial; reflexivity.
++ intros e1 e2 A1 A2.
+ assert (A4 : TotalRelation (A := nat) (≤)) by apply _; destruct (A4 (N e1) (N e2)).
+ - now apply A3.
+ - rewrite plus_comm; now apply mspc_sym, A3.
+Defined.
+
+Arguments reg_fun {_} {_} _.
+
+Lemma seq_lim_lim (x : seq X) (N : Q -> nat) (A : cauchy x N) :
+ seq_lim x (lim (reg_fun A)) (λ e, N (e / 2)).
+Proof.
+set (f := reg_fun A).
+intros e A1 n A2. apply (mspc_triangle' (e / 2) (e / 2) (x (N (e / 2)))).
++ field; change ((2 : Q) ≠ 0); solve_propholds.
++ now apply mspc_sym, A; [solve_propholds | reflexivity |].
++ change (x (N (e / 2))) with (f (e / 2)).
+ apply limit_def; solve_propholds.
+Qed.
+
+End CompleteSpaceSequenceLimits.
+
Section BanachFixpoint.
-Context `{MetricSpace X} (f : X -> X) `{!Contraction f q} (x0 : X).
+Context `{MetricSpace X} (f : X -> X) `{!IsContraction f q} (x0 : X).
Let x n := nat_iter n f x0.
From cfd5d02afb364437d693de044326756528e0ec9c Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 21 Jun 2012 17:32:53 +0200
Subject: [PATCH 010/110] Proved Banach fixpoint theorem
---
broken/metric.v | 237 +++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 212 insertions(+), 25 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index 0a16cb10..3416ff48 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -8,6 +8,93 @@ Require Import Qauto QOrderedType.
Require Import theory.rings theory.dec_fields orders.rings orders.dec_fields nat_pow.
Require Import interfaces.naturals interfaces.orders.
+Require Import CRGeometricSum.
+Import Qround Qpower.
+
+Set Printing Coercions.
+
+Lemma iff_not (P Q : Prop) : (P <-> Q) -> (not P <-> not Q).
+Proof. tauto. Qed.
+
+Notation "x ²" := (x * x) (at level 30) : mc_scope.
+
+(*Lemma expand_square `{SemiRing A} `{Naturals C} `{!NatPowSpec A C pw} :
+ forall x : A, x² = x * x.
+Proof. intro y; now rewrite nat_pow_S, <- (plus_0_r 1), nat_pow_S, nat_pow_0, mult_1_r. Qed.*)
+
+Lemma po_proper' `{PartialOrder A} {x1 x2 y1 y2 : A} :
+ x1 ≤ y1 -> x1 = x2 -> y1 = y2 -> x2 ≤ y2.
+Proof. intros A1 A2 A3; now apply (po_proper _ _ A2 _ _ A3). Qed.
+
+Lemma le_not_eq `{FullPartialOrder A} (x y : A) : x ≤ y -> x ≶ y -> x < y.
+Proof. intros ? ?; apply lt_iff_le_apart; now split. Qed.
+
+Lemma le_lt_eq `{@FullPartialOrder B Be Bap Ble Blt} `{@TrivialApart B Be Bap}
+ `{forall x y : B, Decision (x = y)} (x y : B) : x ≤ y ↔ x < y ∨ x = y.
+Proof.
+assert (Setoid B) by apply po_setoid.
+split; intro A.
++ destruct (decide (x = y)) as [A1 | A1]; [now right |].
+ apply trivial_apart in A1. left; apply lt_iff_le_apart; now split.
++ destruct A as [A | A].
+ - apply lt_iff_le_apart in A; now destruct A.
+ - now rewrite A.
+Qed.
+
+Lemma Zto_nat_nonpos (z : Z) : (z <= 0)%Z -> Z.to_nat z ≡ 0.
+Proof.
+intro A; destruct z as [| p | p]; trivial.
+unfold Z.le in A; now contradict A.
+Qed.
+
+Lemma le_Z_to_nat (n : nat) (z : Z) : (Z.to_nat z <= n)%nat <-> (z <= Z.of_nat n)%Z.
+Proof.
+pose proof (le_0_n n). pose proof (Zle_0_nat n).
+destruct (Z.neg_nonneg_cases z).
++ rewrite Zto_nat_nonpos by now apply Z.lt_le_incl. split; auto with zarith.
++ split; intro A.
+ - apply inj_le in A. rewrite Z2Nat.id in A; trivial.
+ - apply Z2Nat.inj_le in A; trivial. rewrite Nat2Z.id in A; trivial.
+Qed.
+
+Lemma lt_Z_to_nat (n : nat) (z : Z) : (n < Z.to_nat z)%nat <-> (Z.of_nat n < z)%Z.
+Proof.
+assert (A : forall (m n : nat), not (m <= n)%nat <-> (n < m)%nat).
++ intros; split; [apply not_le | apply gt_not_le].
++ assert (A1 := le_Z_to_nat n z). apply iff_not in A1.
+ now rewrite A, Z.nle_gt in A1.
+Qed.
+
+(* Qlt_Qceiling is not used below *)
+Lemma Qlt_Qceiling (q : Q) : (Qceiling q < q + 1)%Q.
+Proof.
+apply Qplus_lt_l with (z := -1). setoid_replace (q + 1 + -1)%Q with q.
++ assert (A := Qceiling_lt q). unfold Z.sub in A.
+ now rewrite inject_Z_plus, inject_Z_opp in A.
++ now rewrite <- Qplus_assoc, Qplus_opp_r, Qplus_0_r.
+Qed.
+
+Lemma Qle_Qceiling_Z (q : Q) (z : Z) : (Qceiling q <= z)%Z <-> (q <= z)%Q.
+Proof.
+split; intro A.
++ rewrite Zle_Qle in A. apply Qle_trans with (y := Qceiling q); [apply Qle_ceiling | trivial].
++ apply Z.lt_pred_le. rewrite Zlt_Qlt. now apply Qlt_le_trans with (y := q); [apply Qceiling_lt |].
+Qed.
+
+Lemma Qle_Qceiling_nat (q : Q) (n : nat) : (Z.to_nat (Qceiling q) <= n)%nat <-> (q <= n)%Q.
+Proof. rewrite le_Z_to_nat; apply Qle_Qceiling_Z. Qed.
+
+Lemma Qlt_Qceiling_Z (q : Q) (z : Z) : (z < q)%Q <-> (z < Qceiling q)%Z.
+Proof.
+assert (A : forall (x y : Q), not (x <= y)%Q <-> (y < x)%Q).
++ intros; split; [apply Qnot_le_lt | apply Qlt_not_le].
++ assert (A1 := Qle_Qceiling_Z q z). apply iff_not in A1.
+ now rewrite A, Z.nle_gt in A1.
+Qed.
+
+Lemma Qlt_Qceiling_nat (q : Q) (n : nat) : (n < q)%Q <-> (n < Z.to_nat (Qceiling q))%nat.
+Proof. rewrite (Qlt_Qceiling_Z q n); symmetry; apply lt_Z_to_nat. Qed.
+
Lemma neq_symm `{Ae : Equiv X} `{!Symmetric Ae} (x y : X) : x ≠ y -> y ≠ x.
Proof. intros A1 A2; apply A1; now symmetry. Qed.
@@ -171,9 +258,6 @@ Qed.
End MetricSpace.
-Lemma le_not_eq `{FullPartialOrder A} (x y : A) : x ≤ y -> x ≶ y -> x < y.
-Proof. intros ? ?; apply lt_iff_le_apart; now split. Qed.
-
Section UniformContinuity.
Context `{ExtMetricSpace X, ExtMetricSpace Y}.
@@ -296,8 +380,6 @@ Context `{ExtMetricSpace X}.
Class IsRegularFunction (f : Q -> X) : Prop :=
rf_prf : forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> B (e1 + e2) (f e1) (f e2).
-Require Import interfaces.monads.
-
Record RegularFunction := {
rf_func :> Q -> X;
rf_proof : IsRegularFunction rf_func
@@ -345,8 +427,16 @@ Qed.
End CompleteMetricSpace.
+Arguments RegularFunction X {_}.
+Arguments Limit X {_}.
+Arguments CompleteMetricSpace X {_ _ _ _}.
+
Definition seq A := nat -> A.
+(*Hint Unfold seq : typeclass_instances.*)
+(* This unfolds [seq X] as [nat -> X] and allows ext_equiv to find an
+instance of [Equiv (seq X)] *)
+
Section SequenceLimits.
Context `{ExtMetricSpace X}.
@@ -354,11 +444,7 @@ Context `{ExtMetricSpace X}.
Definition seq_lim (x : seq X) (a : X) (N : Q -> nat) :=
forall e : Q, 0 < e -> forall n : nat, N e ≤ n -> B e (x n) a.
-(*Hint Unfold seq : typeclass_instances.*)
-(* This unfolds [seq X] as [nat -> X] and allows ext_equiv to find an
-instance of [Equiv (seq X)] *)
-
-Instance : Proper (((=) ==> (=)) ==> (=) ==> (=) ==> iff) seq_lim.
+Global Instance : Proper (((=) ==> (=)) ==> (=) ==> (=) ==> iff) seq_lim.
Proof.
intros x1 x2 A1 a1 a2 A2 N1 N2 A3; split; intros A e e_pos n A4.
+ mc_setoid_replace (x2 n) with (x1 n) by (symmetry; now apply A1).
@@ -369,6 +455,15 @@ intros x1 x2 A1 a1 a2 A2 N1 N2 A3; split; intros A e e_pos n A4.
now apply A.
Qed.
+Global Instance : Proper (((=) ==> (=)) ==> (=) ==> (≡) ==> iff) seq_lim.
+Proof.
+intros x1 x2 A1 a1 a2 A2 N1 N2 A3; split; intros A e e_pos n A4.
++ mc_setoid_replace (x2 n) with (x1 n) by (symmetry; now apply A1).
+ rewrite <- A2. rewrite <- A3 in A4. now apply A.
++ mc_setoid_replace (x1 n) with (x2 n) by now apply A1.
+ rewrite A2. rewrite A3 in A4. now apply A.
+Qed.
+
Lemma seq_lim_unique : ∀ (x : seq X) (a1 a2 : X) N1 N2, seq_lim x a1 N1 → seq_lim x a2 N2 → a1 = a2.
Proof.
intros x a1 a2 N1 N2 A1 A2. apply mspc_eq; intros q A.
@@ -402,11 +497,11 @@ match (f x) with
| Qinf.infinite => inf
end.
-Section ContinuousFunctionSequence.
+(*Section ContinuousFunctionSequence.*)
-Context `{ExtMetricSpace X, ExtMetricSpace Y} (f : X -> Y).
-
-Theorem seq_lim_cont `{!IsUniformlyContinuous f mu} (x : seq X) (a : X) (N : Q -> nat) :
+Theorem seq_lim_cont
+ `{ExtMetricSpace X, ExtMetricSpace Y} (f : X -> Y) `{!IsUniformlyContinuous f mu}
+ (x : seq X) (a : X) (N : Q -> nat) :
seq_lim x a N → seq_lim (f ∘ x) (f a) (comp_inf N mu 0).
Proof.
intros A e e_pos n A1. apply (uc_prf f mu); trivial.
@@ -414,14 +509,21 @@ unfold comp_inf in A1; assert (A2 := uc_pos f mu e e_pos).
now destruct (mu e); [apply A | apply mspc_inf].
Qed.
-(* Now suppose that X is a regular metric space *)
-Context `{MetricSpaceDistance X} `{@MetricSpace X _ _ _ _}.
-
-Theorem seq_lim_contr `{!IsContraction f q} (x : seq X) (a : X) (N : Q -> nat) :
+Theorem seq_lim_contr
+ `{MetricSpace X, ExtMetricSpace Y} (f : X -> Y) `{!IsContraction f q}
+ (x : seq X) (a : X) (N : Q -> nat) :
seq_lim x a N → seq_lim (f ∘ x) (f a) (comp_inf N (contr_modulus q) 0).
-Proof. intro A; now apply seq_lim_cont. Qed.
+Proof. intro A; apply seq_lim_cont; [apply _ | apply A]. Qed.
-End ContinuousFunctionSequence.
+Lemma iter_fixpoint
+ `{ExtMetricSpace X, ExtMetricSpace Y}
+ (f : X -> X) `{!IsUniformlyContinuous f mu} (x : seq X) (a : X) (N : Q -> nat) :
+ (forall n : nat, x (S n) = f (x n)) -> seq_lim x a N -> f a = a.
+Proof.
+intros A1 A2; generalize A2; intro A3. apply seq_lim_S in A2. apply (seq_lim_cont f) in A3.
+mc_setoid_replace (x ∘ S) with (f ∘ x) in A2 by (intros ? ? eqmn; rewrite eqmn; apply A1).
+eapply seq_lim_unique; eauto.
+Qed.
Section CompleteSpaceSequenceLimits.
@@ -430,7 +532,7 @@ Context `{CompleteMetricSpace X}.
Definition cauchy (x : seq X) (N : Q -> nat) :=
forall e : Q, 0 < e -> forall m n : nat, N e ≤ m -> N e ≤ n -> B e (x m) (x n).
-Definition reg_fun (x : seq X) (N : Q -> nat) (A : cauchy x N) : RegularFunction.
+Definition reg_fun (x : seq X) (N : Q -> nat) (A : cauchy x N) : RegularFunction X.
refine (Build_RegularFunction (x ∘ N) _).
(* without loss of generality, N e1 ≤ N e2 *)
assert (A3 : forall e1 e2, 0 < e1 -> 0 < e2 -> N e1 ≤ N e2 -> B (e1 + e2) ((x ∘ N) e1) ((x ∘ N) e2)).
@@ -461,7 +563,9 @@ End CompleteSpaceSequenceLimits.
Section BanachFixpoint.
-Context `{MetricSpace X} (f : X -> X) `{!IsContraction f q} (x0 : X).
+Context `{MetricSpace X} {Xlim : Limit X} {Xcms : CompleteMetricSpace X}.
+
+Context (f : X -> X) `{!IsContraction f q} (x0 : X).
Let x n := nat_iter n f x0.
@@ -478,6 +582,9 @@ Proof. apply msd_nonneg. Qed.
Instance : PropHolds (0 ≤ q).
Proof. apply (contr_nonneg_mu f q). Qed.
+Instance : PropHolds (q < 1).
+Proof. apply (contr_lt_mu_1 f q). Qed.
+
Instance : PropHolds (0 < 1 - q).
Proof.
assert (A := contr_lt_mu_1 f q).
@@ -493,9 +600,6 @@ induction n using nat_induction.
nat_simpl; rewrite 2!x_Sn; now apply contr_prf.
Qed.
-(*Lemma nonzero_1_minus_q : 1 - q ≠ 0.
-Proof. apply lt_ne_flip, pos_1_minus_q. Qed.*)
-
Lemma dist_xm_xn : forall m n : nat, B (d * q^m * (1 - q^n) / (1 - q)) (x m) (x (m + n)).
Proof.
intro m; induction n as [| n IH] using nat_induction.
@@ -516,4 +620,87 @@ apply (order_preserving (1 +)). rewrite <- negate_0.
apply <- flip_le_negate. solve_propholds.
Qed.
+(*Let NQ (e : Q) : Q := (d / (e * (1 - q)^2)).
+
+Let N (e : Q) : nat := Z.to_nat (Qceiling (NQ e)).
+
+Lemma NQ_pos (e : Q) : 0 < d -> 0 < e -> 0 < NQ e.
+Proof. intros; subst NQ; solve_propholds. Qed.
+
+Lemma N_pos (e : Q) : 0 < d -> 0 < e -> 0 < N e.
+Proof. intros; now apply Qlt_Qceiling_nat, NQ_pos. Qed.*)
+
+Lemma Qpower_mc_power (e : Q) (n : nat) : (e ^ n)%Q = (e ^ n)%mc.
+Proof.
+induction n as [| n IH] using nat_induction.
++ now rewrite nat_pow_0.
++ rewrite Nat2Z.inj_add, Qpower_plus'.
+ - now rewrite nat_pow_S, IH.
+ - rewrite <- Nat2Z.inj_add; change 0%Z with (Z.of_nat 0); rewrite Nat2Z.inj_iff;
+ apply not_eq_sym, O_S.
+(*
+SearchPattern (?x ≢ ?y -> ?y ≢ ?x).
+Anomaly: Signature and its instance do not match. Please report.
+*)
+Qed.
+
+Lemma power_tends_to_zero (e : Q) (n : nat) :
+ 0 < e -> Z.to_nat (Qceiling (/(e * (1 - q)))%mc) ≤ n -> q ^ n ≤ e.
+Proof.
+intros A1 A2.
+assert (A3 : 0 < n).
++ let T := type of A2 in match T with (?lhs ≤ _) => apply lt_le_trans with (y := lhs) end; [| trivial].
+ apply Qlt_Qceiling_nat; change (0 < / (e * (1 - q))); solve_propholds.
++ destruct n as [| n]; [elim (lt_irrefl _ A3) |].
+ rewrite <- Qpower_mc_power.
+ apply GeometricCovergenceLemma with (e := e ↾ A1); [solve_propholds .. |].
+ apply (Qle_Qceiling_nat _ (S n)), A2.
+Qed.
+
+Lemma const_x (N : Q -> nat) : d = 0 -> cauchy x N.
+Proof.
+intro eq_d_0.
+assert (A := mspc_distance (x 0) (x 1)).
+subst d; rewrite eq_d_0 in A; apply mspc_zero in A.
+assert (C : forall n, x n = x 0).
++ induction n as [| n IH] using nat_induction; [easy |].
+ change (x (1 + n)) with (f (x n)). rewrite IH. symmetry; apply A.
++ intros e e_pos m n _ _. rewrite (C m), (C n). (* second "rewrite C" does not work *)
+ apply mspc_refl. solve_propholds.
+Qed.
+
+Lemma cauchy_x : cauchy x (λ e, Z.to_nat (Qceiling (d / (e * (1 - q)²))%mc)).
+Proof.
+assert (d_nonneg : 0 ≤ d) by solve_propholds.
+assert (d_pos_0 : 0 < d \/ 0 = d) by now apply le_lt_eq.
+destruct d_pos_0 as [d_pos | d_0]; [| now apply const_x].
+intros e e_pos.
+(* without loss of generality, m ≤ n *)
+match goal with
+|- forall m n, @?G m n => intros m n; assert (A : forall m n, m ≤ n -> G m n)
+end.
++ clear m n; intros m n le_m_n A _.
+ rewrite <- (cut_minus_le n m); trivial. rewrite plus_comm.
+ apply (mspc_monotone (d * q^m / (1 - q))); [| apply dist_xm_xn'].
+ cut (q ^ m ≤ e * (1 - q) / d).
+ - intro A1. apply (order_preserving (d *.)), (order_preserving (.* /(1 - q))) in A1.
+ apply (po_proper' A1); [easy | field; split; solve_propholds].
+ - apply power_tends_to_zero; [solve_propholds |].
+ apply (po_proper' A); [| easy]. apply f_equal, Qceiling_comp.
+ match goal with |- (Qeq ?l ?r) => change (l = r) end.
+ field; repeat split; solve_propholds.
++ assert (A1 : TotalRelation (A := nat) (≤)) by apply _; destruct (A1 m n).
+ - now apply A.
+ - intros; apply mspc_sym; now apply A.
+Qed.
+
+Let a := lim (reg_fun x _ cauchy_x).
+
+Lemma banach_fixpoint : f a = a.
+Proof.
+assert (C := cauchy_x).
+(* [Check seq_lim_lim (A := C)] says "Wrong argument name: A", but [About seq_lim_lim] shows A *)
+eapply (iter_fixpoint f x); [easy | apply seq_lim_lim].
+Qed.
+
End BanachFixpoint.
From 34e397db7a129d3610dc93bab1bb1a1d5bd02adb Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Mon, 25 Jun 2012 15:49:29 +0200
Subject: [PATCH 011/110] Changed the definition of equality in a metric space
and removed unnecessary axioms
---
broken/metric.v | 137 ++++++++++++++++++++++++++++--------------------
1 file changed, 79 insertions(+), 58 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index 3416ff48..611f1bcc 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -7,6 +7,7 @@ Require Import Qauto QOrderedType.
(*Require Import orders.*)
Require Import theory.rings theory.dec_fields orders.rings orders.dec_fields nat_pow.
Require Import interfaces.naturals interfaces.orders.
+Import peano_naturals.
Require Import CRGeometricSum.
Import Qround Qpower.
@@ -18,10 +19,6 @@ Proof. tauto. Qed.
Notation "x ²" := (x * x) (at level 30) : mc_scope.
-(*Lemma expand_square `{SemiRing A} `{Naturals C} `{!NatPowSpec A C pw} :
- forall x : A, x² = x * x.
-Proof. intro y; now rewrite nat_pow_S, <- (plus_0_r 1), nat_pow_S, nat_pow_0, mult_1_r. Qed.*)
-
Lemma po_proper' `{PartialOrder A} {x1 x2 y1 y2 : A} :
x1 ≤ y1 -> x1 = x2 -> y1 = y2 -> x2 ≤ y2.
Proof. intros A1 A2 A3; now apply (po_proper _ _ A2 _ _ A3). Qed.
@@ -109,12 +106,11 @@ Add Field Q : (stdlib_field_theory Q).
Bind Scope mc_scope with Q.
-(*Import Qinf.notations.*)
Notation Qinf := Qinf.T.
-Import peano_naturals.
Notation "n .+1" := (S n) (at level 2, left associativity, format "n .+1") : nat_scope.
+(*
Local Notation Qnn := QnonNeg.T.
Instance Qnn_eq : Equiv Qnn := eq.
@@ -131,6 +127,7 @@ Instance Qpos_mult : Mult Qpos := Qpossec.Qpos_mult.
Instance Qpos_inv : DecRecip Qpos := Qpossec.Qpos_inv.
Instance Qinf_one : One Qinf := 1%Q.
+*)
Module Qinf.
@@ -153,6 +150,7 @@ End Qinf.
Instance Qinf_lt : Lt Qinf := Qinf.lt.
+(*
Ltac mc_simpl := unfold
equiv, zero, one, plus, negate, mult, dec_recip, le, lt.
@@ -173,10 +171,11 @@ Ltac nat_simpl := unfold
simpl.
Tactic Notation "Qsimpl" hyp_list(A) := revert A; Qsimpl'; intros A.
+*)
Class MetricSpaceBall (X : Type) : Type := mspc_ball: Qinf → relation X.
-Local Notation B := mspc_ball.
+Local Notation ball := mspc_ball.
(* In the proof of Banach fixpoint theorem we have to use arithmetic
expressions such as q^n / (1 - q) when 0 <= q < 1 as the ball radius. If
@@ -184,25 +183,24 @@ the radius is in Qnn (ie., QnonNeg.T), then we have to prove that 1 - q :
Qnn. It seems more convenient to have the radius live in Q and have the
axiom that no points are separated by a negative distance. *)
-Class ExtMetricSpace (X : Type) `{Equiv X} `{MetricSpaceBall X} : Prop :=
- { mspc_setoid :> Setoid X
- ; mspc_proper:> Proper (=) B
- ; mspc_inf: ∀ x y, B Qinf.infinite x y
- ; mspc_negative: ∀ (e: Q), e < 0 → ∀ x y, ~ B e x y
- ; mspc_zero: ∀ x y, B 0 x y ↔ x = y
- ; mspc_refl:> ∀ e : Q, 0 ≤ e → Reflexive (B e)
- ; mspc_sym:> ∀ e, Symmetric (B e)
- ; mspc_triangle: ∀ (e1 e2: Q) (a b c: X),
- B e1 a b → B e2 b c → B (e1 + e2) a c
- ; mspc_closed: ∀ (e: Q) (a b: X),
- (∀ d: Q, 0 < d -> B (e + d) a b) → B e a b }.
+Class ExtMetricSpace (X : Type) `{MetricSpaceBall X} : Prop := {
+ mspc_radius_proper : Proper ((=) ==> (≡) ==> (≡) ==> iff) ball;
+ mspc_inf: ∀ x y, ball Qinf.infinite x y;
+ mspc_negative: ∀ (e: Q), e < 0 → ∀ x y, ~ ball e x y;
+ mspc_refl:> ∀ e : Q, 0 ≤ e → Reflexive (ball e);
+ mspc_symm:> ∀ e, Symmetric (ball e);
+ mspc_triangle: ∀ (e1 e2: Q) (a b c: X),
+ ball e1 a b → ball e2 b c → ball (e1 + e2) a c;
+ mspc_closed: ∀ (e: Q) (a b: X),
+ (∀ d: Q, 0 < d -> ball (e + d) a b) → ball e a b
+}.
(*
This shows that if axioms of metric space are formulated with Qinf instead of Q,
the [apply] tactic won't be able to unify them with goals using Q
-Goal (forall (e1 e2 : Qinf) (x1 x2 : X), B (e1 + e2) x1 x2) ->
- (forall (e1 e2 : Q) (x1 x2 : X), B (e1 + e2) x1 x2).
+Goal (forall (e1 e2 : Qinf) (x1 x2 : X), ball (e1 + e2) x1 x2) ->
+ (forall (e1 e2 : Q) (x1 x2 : X), ball (e1 + e2) x1 x2).
intros A e1 e2 x1 x2.
change (e1 + e2 : Qinf) with ((Qinf.finite e1) + (Qinf.finite e2)).
apply A.
@@ -211,37 +209,59 @@ apply A.
Class MetricSpaceDistance (X : Type) := msd : X -> X -> Q.
Class MetricSpace (X : Type) `{ExtMetricSpace X} `{MetricSpaceDistance X} : Prop :=
- mspc_distance : forall x1 x2 : X, B (msd x1 x2) x1 x2.
+ mspc_distance : forall x1 x2 : X, ball (msd x1 x2) x1 x2.
Section ExtMetricSpace.
Context `{ExtMetricSpace X}.
+Global Instance mspc_equiv : Equiv X := λ x1 x2, ball 0%Q x1 x2.
+
+Global Instance mspc_setoid : Setoid X.
+Proof.
+constructor.
++ now apply mspc_refl.
++ apply mspc_symm.
++ intros x1 x2 x3 eq12 eq23.
+ unfold mspc_equiv, equiv; change 0%Q with (0%Q + 0%Q); now apply mspc_triangle with (b := x2).
+Qed.
+
+Global Instance mspc_proper : Proper ((=) ==> (=) ==> (=) ==> iff) ball.
+Proof.
+assert (A := @mspc_radius_proper X _ _).
+intros e1 e2 Ee1e2 x1 x2 Ex1x2 y1 y2 Ey1y2;
+destruct e1 as [e1 |]; destruct e2 as [e2 |]; split; intro B; try apply mspc_inf;
+try (unfold Qinf.eq, equiv in *; contradiction).
++ mc_setoid_replace e2 with (0 + (e2 + 0)) by ring.
+ apply mspc_triangle with (b := x1); [apply mspc_symm, Ex1x2 |].
+ now apply mspc_triangle with (b := y1); [rewrite <- Ee1e2 |].
++ mc_setoid_replace e1 with (0 + (e1 + 0)) by ring.
+ apply mspc_triangle with (b := x2); [apply Ex1x2 |].
+ now apply mspc_triangle with (b := y2); [rewrite Ee1e2 | apply mspc_symm].
+Qed.
+
Lemma mspc_triangle' :
∀ (q1 q2 : Q) (x2 x1 x3 : X) (q : Q),
- q1 + q2 = q → B q1 x1 x2 → B q2 x2 x3 → B q x1 x3.
+ q1 + q2 = q → ball q1 x1 x2 → ball q2 x2 x3 → ball q x1 x3.
Proof.
intros q1 q2 x2 x1 x3 q A1 A2 A3. rewrite <- A1. eapply mspc_triangle; eauto.
Qed.
Lemma mspc_monotone :
- ∀ q1 q2 : Q, q1 ≤ q2 -> ∀ x y : X, B q1 x y → B q2 x y.
+ ∀ q1 q2 : Q, q1 ≤ q2 -> ∀ x y : X, ball q1 x y → ball q2 x y.
Proof.
intros q1 q2 A1 x y A2.
apply (mspc_triangle' q1 (q2 - q1) y); [ring | trivial |]. apply mspc_refl.
apply (order_preserving (+ (-q1))) in A1. now rewrite plus_negate_r in A1.
Qed.
-Lemma mspc_zero' : ∀ x y : X, (∀ e : Q, 0 < e -> B e x y) ↔ B 0 x y.
+Lemma mspc_eq : ∀ x y : X, (∀ e : Q, 0 < e -> ball e x y) ↔ x = y.
Proof.
intros x y; split; intro A.
+ apply mspc_closed; intro d. change 0%Q with (@zero Q _); rewrite plus_0_l; apply A.
+ intros e e_pos. apply (mspc_monotone 0); trivial; solve_propholds.
Qed.
-Lemma mspc_eq : ∀ x y : X, (∀ e : Q, 0 < e -> B e x y) ↔ x = y.
-Proof. intros x y. rewrite <- mspc_zero. apply mspc_zero'. Qed.
-
End ExtMetricSpace.
Section MetricSpace.
@@ -264,7 +284,7 @@ Context `{ExtMetricSpace X, ExtMetricSpace Y}.
Class IsUniformlyContinuous (f : X -> Y) (mu : Q -> Qinf) := {
uc_pos : forall e : Q, 0 < e -> (0 < mu e);
- uc_prf : ∀ (e : Q) (x1 x2: X), 0 < e -> B (mu e) x1 x2 → B e (f x1) (f x2)
+ uc_prf : ∀ (e : Q) (x1 x2: X), 0 < e -> ball (mu e) x1 x2 → ball e (f x1) (f x2)
}.
Global Arguments uc_pos f mu {_} e _.
@@ -272,7 +292,7 @@ Global Arguments uc_prf f mu {_} e x1 x2 _ _.
Global Instance uc_proper `{IsUniformlyContinuous f mu} : Proper ((=) ==> (=)) f.
Proof.
-intros x1 x2 A. apply mspc_eq. intros e e_pos. apply (uc_prf f mu); trivial.
+intros x1 x2 A. apply -> mspc_eq. intros e e_pos. apply (uc_prf f mu); trivial.
pose proof (uc_pos f mu e e_pos) as ?.
destruct (mu e); [apply mspc_eq; trivial | apply mspc_inf].
Qed.
@@ -286,7 +306,7 @@ Context `{MetricSpace X, ExtMetricSpace Y}.
Class IsContraction (f : X -> Y) (q : Q) := {
contr_nonneg_mu : 0 ≤ q;
contr_lt_mu_1 : q < 1;
- contr_prf : forall (x1 x2 : X) (e : Q), B e x1 x2 -> B (q * e) (f x1) (f x2)
+ contr_prf : forall (x1 x2 : X) (e : Q), ball e x1 x2 -> ball (q * e) (f x1) (f x2)
}.
Global Arguments contr_nonneg_mu f q {_} _.
@@ -305,7 +325,7 @@ constructor.
pose proof (contr_nonneg_mu f q) as A2. pose proof (le_not_eq _ _ A2 A1). solve_propholds.
+ intros e x1 x2 A1 A2. unfold contr_modulus in A2. destruct (decide (0 = q)) as [A | A].
- assert (A3 := contr_prf f q x1 x2 (msd x1 x2) (mspc_distance x1 x2)).
- rewrite <- A, mult_0_l in A3; now apply mspc_zero'.
+ rewrite <- A, mult_0_l in A3; now apply mspc_eq.
- mc_setoid_replace e with (q * (e / q)) by (field; now apply neq_symm).
now apply contr_prf.
Qed.
@@ -327,9 +347,9 @@ intros f g h A1 A2 x y A3; rewrite A3; now transitivity (g y); [apply A1 | apply
Qed.
Instance UCFSpaceBall : MetricSpaceBall (IsUniformlyContinuous X Y) :=
- fun q f g => forall x, B q (f x) (g x).
+ fun q f g => forall x, ball q (f x) (g x).
-Lemma UCFBallProper : Proper equiv B.
+Lemma UCFBallProper : Proper equiv ball.
Proof.
intros q1 q2 A1 f1 f2 A2 g1 g2 A3; split; intros A4 x.
+ rewrite <- A1. rewrite <- (A2 x x); [| reflexivity]. rewrite <- (A3 x x); [| reflexivity]. apply A4.
@@ -357,11 +377,11 @@ Section Isometry.
Context `{ExtMetricSpace X, ExtMetricSpace Y}.
Class Isometry (f : X -> Y) :=
- isometry : forall (e : Q) (x1 x2 : X), B e x1 x2 <-> B e (f x1) (f x2).
+ isometry : forall (e : Q) (x1 x2 : X), ball e x1 x2 <-> ball e (f x1) (f x2).
Global Instance isometry_injective `{Isometry f} : Injective f.
Proof.
-constructor; [| constructor]; try apply _; intros x y; rewrite <- !B_zero;
+constructor; [| constructor]; try apply _; intros x y; rewrite <- !ball_zero;
intros ?; [apply <- isometry | apply -> isometry]; trivial.
Qed.
@@ -378,7 +398,7 @@ Section CompleteMetricSpace.
Context `{ExtMetricSpace X}.
Class IsRegularFunction (f : Q -> X) : Prop :=
- rf_prf : forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> B (e1 + e2) (f e1) (f e2).
+ rf_prf : forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> ball (e1 + e2) (f e1) (f e2).
Record RegularFunction := {
rf_func :> Q -> X;
@@ -390,13 +410,13 @@ Arguments Build_RegularFunction {_} _.
Global Existing Instance rf_proof.
Instance rf_eq : Equiv RegularFunction :=
- λ f1 f2, forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> B (e1 + e2) (f1 e1) (f2 e2).
+ λ f1 f2, forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> ball (e1 + e2) (f1 e1) (f2 e2).
Instance rf_setoid : Setoid RegularFunction.
Proof.
constructor.
+ intros f e1 e2; apply rf_prf.
-+ intros f1 f2 A e1 e2 A1 A2. rewrite plus_comm. now apply mspc_sym, A.
++ intros f1 f2 A e1 e2 A1 A2. rewrite plus_comm. now apply mspc_symm, A.
+ intros f1 f2 f3 A1 A2 e1 e3 A3 A4. apply mspc_closed. intros d A5.
mc_setoid_replace (e1 + e3 + d) with ((e1 + d / 2) + (e3 + d / 2))
by (field; change ((2 : Q) ≠ 0); solve_propholds).
@@ -405,7 +425,7 @@ constructor.
Qed.
Instance rf_msb : MetricSpaceBall RegularFunction :=
- λ e f1 f2, forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> B (e + e1 + e2) (f1 e1) (f2 e2).
+ λ e f1 f2, forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> ball (e + e1 + e2) (f1 e1) (f2 e2).
Lemma unit_reg (x : X) : IsRegularFunction (λ _, x).
Proof. intros e1 e2 A1 A2; apply mspc_refl; solve_propholds. Qed.
@@ -417,10 +437,10 @@ Class Limit := lim : RegularFunction -> X.
Class CompleteMetricSpace `{Limit} := cmspc :> Surjective reg_unit (inv := lim).
Lemma limit_def `{CompleteMetricSpace} (f : RegularFunction) :
- forall e : Q, 0 < e -> B e (f e) (lim f).
+ forall e : Q, 0 < e -> ball e (f e) (lim f).
Proof.
-intros e2 A2. apply mspc_sym; apply mspc_closed.
-(* [apply mspc_sym, mspc_closed.] does not work *)
+intros e2 A2. apply mspc_symm; apply mspc_closed.
+(* [apply mspc_symm, mspc_closed.] does not work *)
intros e1 A1. change (lim f) with (reg_unit (lim f) e1). rewrite plus_comm.
rapply (surjective reg_unit (inv := lim)); trivial; reflexivity.
Qed.
@@ -429,7 +449,7 @@ End CompleteMetricSpace.
Arguments RegularFunction X {_}.
Arguments Limit X {_}.
-Arguments CompleteMetricSpace X {_ _ _ _}.
+Arguments CompleteMetricSpace X {_ _ _}.
Definition seq A := nat -> A.
@@ -442,9 +462,9 @@ Section SequenceLimits.
Context `{ExtMetricSpace X}.
Definition seq_lim (x : seq X) (a : X) (N : Q -> nat) :=
- forall e : Q, 0 < e -> forall n : nat, N e ≤ n -> B e (x n) a.
+ forall e : Q, 0 < e -> forall n : nat, N e ≤ n -> ball e (x n) a.
-Global Instance : Proper (((=) ==> (=)) ==> (=) ==> (=) ==> iff) seq_lim.
+Global Instance : Proper (((=) ==> (=)) ==> (=) ==> ((=) ==> (=)) ==> iff) seq_lim.
Proof.
intros x1 x2 A1 a1 a2 A2 N1 N2 A3; split; intros A e e_pos n A4.
+ mc_setoid_replace (x2 n) with (x1 n) by (symmetry; now apply A1).
@@ -466,14 +486,14 @@ Qed.
Lemma seq_lim_unique : ∀ (x : seq X) (a1 a2 : X) N1 N2, seq_lim x a1 N1 → seq_lim x a2 N2 → a1 = a2.
Proof.
-intros x a1 a2 N1 N2 A1 A2. apply mspc_eq; intros q A.
+intros x a1 a2 N1 N2 A1 A2. apply -> mspc_eq; intros q A.
assert (A3 : 0 < q / 2) by solve_propholds.
specialize (A1 (q / 2) A3); specialize (A2 (q / 2) A3).
set (M := Peano.max (N1 (q / 2)) (N2 (q / 2))).
assert (A4 : N1 (q / 2) ≤ M) by apply le_max_l.
assert (A5 : N2 (q / 2) ≤ M) by apply le_max_r.
specialize (A1 M A4); specialize (A2 M A5).
-apply mspc_sym in A1.
+apply mspc_symm in A1.
apply (mspc_triangle' (q / 2) (q / 2) (x M)); trivial.
field; change ((2 : Q) ≠ 0); solve_propholds.
Qed.
@@ -530,12 +550,12 @@ Section CompleteSpaceSequenceLimits.
Context `{CompleteMetricSpace X}.
Definition cauchy (x : seq X) (N : Q -> nat) :=
- forall e : Q, 0 < e -> forall m n : nat, N e ≤ m -> N e ≤ n -> B e (x m) (x n).
+ forall e : Q, 0 < e -> forall m n : nat, N e ≤ m -> N e ≤ n -> ball e (x m) (x n).
Definition reg_fun (x : seq X) (N : Q -> nat) (A : cauchy x N) : RegularFunction X.
refine (Build_RegularFunction (x ∘ N) _).
(* without loss of generality, N e1 ≤ N e2 *)
-assert (A3 : forall e1 e2, 0 < e1 -> 0 < e2 -> N e1 ≤ N e2 -> B (e1 + e2) ((x ∘ N) e1) ((x ∘ N) e2)).
+assert (A3 : forall e1 e2, 0 < e1 -> 0 < e2 -> N e1 ≤ N e2 -> ball (e1 + e2) ((x ∘ N) e1) ((x ∘ N) e2)).
+ intros e1 e2 A1 A2 A3.
apply (mspc_monotone e1).
- apply (strictly_order_preserving (e1 +)) in A2; rewrite plus_0_r in A2; solve_propholds.
@@ -543,7 +563,7 @@ assert (A3 : forall e1 e2, 0 < e1 -> 0 < e2 -> N e1 ≤ N e2 -> B (e1 + e2) ((x
+ intros e1 e2 A1 A2.
assert (A4 : TotalRelation (A := nat) (≤)) by apply _; destruct (A4 (N e1) (N e2)).
- now apply A3.
- - rewrite plus_comm; now apply mspc_sym, A3.
+ - rewrite plus_comm; now apply mspc_symm, A3.
Defined.
Arguments reg_fun {_} {_} _.
@@ -554,7 +574,7 @@ Proof.
set (f := reg_fun A).
intros e A1 n A2. apply (mspc_triangle' (e / 2) (e / 2) (x (N (e / 2)))).
+ field; change ((2 : Q) ≠ 0); solve_propholds.
-+ now apply mspc_sym, A; [solve_propholds | reflexivity |].
++ now apply mspc_symm, A; [solve_propholds | reflexivity |].
+ change (x (N (e / 2))) with (f (e / 2)).
apply limit_def; solve_propholds.
Qed.
@@ -592,15 +612,16 @@ rewrite <- flip_lt_negate in A. apply (strictly_order_preserving (1 +)) in A.
now rewrite plus_negate_r in A.
Qed.
-Lemma dist_xn_xSn : forall n : nat, B (d * q^n) (x n) (x (1 + n)).
+Lemma dist_xn_xSn : forall n : nat, ball (d * q^n) (x n) (x (1 + n)).
Proof.
induction n using nat_induction.
+ rewrite nat_pow_0, right_identity; subst d; apply mspc_distance.
+ rewrite nat_pow_S. mc_setoid_replace (d * (q * q ^ n)) with (q * (d * q^n)) by ring.
- nat_simpl; rewrite 2!x_Sn; now apply contr_prf.
+ change (x (1 + n)) with (f (x n)); change (x (1 + (1 + n))) with (f (x (1 + n))).
+ now apply contr_prf.
Qed.
-Lemma dist_xm_xn : forall m n : nat, B (d * q^m * (1 - q^n) / (1 - q)) (x m) (x (m + n)).
+Lemma dist_xm_xn : forall m n : nat, ball (d * q^m * (1 - q^n) / (1 - q)) (x m) (x (m + n)).
Proof.
intro m; induction n as [| n IH] using nat_induction.
+ rewrite right_identity; apply mspc_refl.
@@ -610,7 +631,7 @@ intro m; induction n as [| n IH] using nat_induction.
- mc_setoid_replace (m + (1 + n)) with (1 + (m + n)) by ring. apply dist_xn_xSn.
Qed.
-Lemma dist_xm_xn' : forall m n : nat, B (d * q^m / (1 - q)) (x m) (x (m + n)).
+Lemma dist_xm_xn' : forall m n : nat, ball (d * q^m / (1 - q)) (x m) (x (m + n)).
Proof.
intros m n. apply (mspc_monotone (d * q^m * (1 - q^n) / (1 - q))); [| apply dist_xm_xn].
apply (order_preserving (.* /(1 - q))). rewrite <- associativity.
@@ -661,7 +682,7 @@ Lemma const_x (N : Q -> nat) : d = 0 -> cauchy x N.
Proof.
intro eq_d_0.
assert (A := mspc_distance (x 0) (x 1)).
-subst d; rewrite eq_d_0 in A; apply mspc_zero in A.
+subst d; rewrite eq_d_0 in A.
assert (C : forall n, x n = x 0).
+ induction n as [| n IH] using nat_induction; [easy |].
change (x (1 + n)) with (f (x n)). rewrite IH. symmetry; apply A.
@@ -691,7 +712,7 @@ end.
field; repeat split; solve_propholds.
+ assert (A1 : TotalRelation (A := nat) (≤)) by apply _; destruct (A1 m n).
- now apply A.
- - intros; apply mspc_sym; now apply A.
+ - intros; apply mspc_symm; now apply A.
Qed.
Let a := lim (reg_fun x _ cauchy_x).
From 361b4da9032791cb68a386fc69f53910e59c1851 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 28 Jun 2012 20:58:20 +0200
Subject: [PATCH 012/110] Added FromMetric2.v to define conversion from
metric2.Metric to the metric space type class
---
broken/FromMetric2.v | 91 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 91 insertions(+)
create mode 100644 broken/FromMetric2.v
diff --git a/broken/FromMetric2.v b/broken/FromMetric2.v
new file mode 100644
index 00000000..6d982a18
--- /dev/null
+++ b/broken/FromMetric2.v
@@ -0,0 +1,91 @@
+Require Import Complete metric.
+Require Import
+ abstract_algebra stdlib_rationals
+ orders.orders theory.rings.
+
+Program Instance : ∀ x y : Q, Decision (x < y) := λ x y,
+ match Qlt_le_dec x y with
+ | left H => left H
+ | right _ => right _
+ end.
+Next Obligation. now apply Qle_not_lt. Qed.
+
+Section Conversion.
+
+Variable X : MetricSpace.
+
+Instance ms_msb : MetricSpaceBall X := λ (e : Qinf) (x y : X),
+match e with
+| Qinf.finite e' =>
+ if (decide (e' = 0))
+ then (forall d : Qpos, ball d x y)
+ else
+ match (decide (0 < e')) with
+ | left e'_pos => ball (mkQpos e'_pos) x y
+ | right _ => False
+ end
+| Qinf.infinite => True
+end.
+
+Instance : Proper ((=) ==> (≡) ==> (≡) ==> iff) mspc_ball.
+Proof.
+intros e1 e2 E1 x1 x2 E2 y1 y2 E3.
+destruct e1 as [e1 |]; destruct e2 as [e2 |];
+try (unfold equiv, Qinf.eq in *; contradiction); try reflexivity.
+unfold mspc_ball, ms_msb.
+change (e1 = e2) in E1.
+destruct (decide (e1 = 0)) as [A1 | A1]; destruct (decide (e2 = 0)) as [A2 | A2];
+[now rewrite E2, E3 | rewrite <- E1 in A2; now contradict A2 .. |].
+destruct (decide (0 < e1)) as [B1 | B1]; destruct (decide (0 < e2)) as [B2 | B2];
+[| exfalso; rewrite <- E1 in B2; now contradict B2 .. | easy].
+apply ball_wd; [apply E1 | now rewrite E2 | now rewrite E3].
+Qed.
+
+Lemma msp_triangle' (e1 e2: Qpos) (y x z : X) (e : Qpos) :
+ (e1 + e2)%Qpos == e -> ball e1 x y -> ball e2 y z -> ball e x z.
+Proof.
+intros E A1 A2. setoid_replace e with (e1 + e2)%Qpos by easy.
+eapply (msp_triangle (msp X)); eauto.
+Qed.
+
+Lemma half_n_half (e : Q) : e / 2 + e / 2 = e.
+Proof. field; (change (not (2 ≡ 0)%Z); discriminate). Qed.
+
+Lemma mspc_triangle_0 (e : Q) (x y z : X) :
+ mspc_ball 0 x y → mspc_ball e y z → mspc_ball e x z.
+Proof.
+intros A1 A2. unfold mspc_ball, ms_msb in *; simpl in A1.
+destruct (decide (e = 0)).
+(* intro d; setoid_replace d with (d * (1#2) + d * (1#2))%Qpos. *)
++ intros [d d_pos]. assert (hd_pos : (0 < d / 2)%Q) by (apply Q.Qmult_lt_0_compat; auto with qarith).
+ apply (msp_triangle' (mkQpos hd_pos) (mkQpos hd_pos) y); [| apply A1 | apply A2].
+ apply half_n_half.
++ destruct (decide (0 < e)) as [E | E]; [| contradiction].
+ apply (msp_closed (msp X)). intro d.
+ apply (msp_triangle' d (mkQpos E) y); [| apply A1 | apply A2].
+ destruct d as [d d_pos]; change (d + e = e + d); ring.
+Qed.
+
+Instance : ExtMetricSpaceClass X.
+Proof.
+constructor.
++ apply _.
++ intros; apply I.
++ intros e e_neg x y A. unfold mspc_ball, ms_msb in A.
+ destruct (decide (e = 0)); [eapply lt_ne; eauto |].
+ destruct (decide (0 < e)); [eapply lt_flip; eauto | trivial].
++ intros e e_nonneg x. unfold mspc_ball, ms_msb.
+ destruct (decide (e = 0)); [intro d; apply (msp_refl (msp X)) |].
+ destruct (decide (0 < e)) as [A | A]; [apply (msp_refl (msp X)) |].
+ apply A, lt_iff_le_ne. now split; [| apply neq_symm].
++ intros e x y A; unfold mspc_ball, ms_msb in *.
+ destruct e as [e |]; [| trivial].
+ destruct (decide (e = 0)); [intro d; now apply (msp_sym (msp X)) |].
+ now destruct (decide (0 < e)); [apply (msp_sym (msp X)) |].
++ intros e1 e2 x y z A1 A2.
+ destruct (decide (e1 = 0)) as [E1 | E1].
+ - rewrite E1 in A1 |- *; rewrite plus_0_l.
+ now apply mspc_triangle_0 with (y := y).
+ -
+unfold mspc_ball, ms_msb in A1.
+
From f3a24134b440801b188a31e64016ff45b48de633 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 3 Jul 2012 16:59:46 +0200
Subject: [PATCH 013/110] Proved that metric spaces in terms of
CoRN.metric2.Metric are metric spaces in terms of type classes
---
broken/FromMetric2.v | 118 ++++++++++++++++++++++++++++++++++---------
1 file changed, 94 insertions(+), 24 deletions(-)
diff --git a/broken/FromMetric2.v b/broken/FromMetric2.v
index 6d982a18..99cf7837 100644
--- a/broken/FromMetric2.v
+++ b/broken/FromMetric2.v
@@ -1,7 +1,16 @@
Require Import Complete metric.
Require Import
abstract_algebra stdlib_rationals
- orders.orders theory.rings.
+ orders.orders orders.semirings orders.rings theory.rings.
+
+Instance Qinf_plus_proper : Proper ((=) ==> (=) ==> (=)) Qinf.plus.
+Proof.
+intros x1 x2 Ex y1 y2 Ey.
+destruct x1 as [x1 |]; destruct x2 as [x2 |]; destruct y1 as [y1 |]; destruct y2 as [y2 |];
+unfold equiv, Qinf.eq in *; try contradiction; trivial.
+change (x1 = x2) in Ex; change (y1 = y2) in Ey; change (x1 + y1 = x2 + y2).
+now rewrite Ex, Ey.
+Qed.
Program Instance : ∀ x y : Q, Decision (x < y) := λ x y,
match Qlt_le_dec x y with
@@ -10,7 +19,7 @@ Program Instance : ∀ x y : Q, Decision (x < y) := λ x y,
end.
Next Obligation. now apply Qle_not_lt. Qed.
-Section Conversion.
+Section FromMetricSpace.
Variable X : MetricSpace.
@@ -48,8 +57,31 @@ intros E A1 A2. setoid_replace e with (e1 + e2)%Qpos by easy.
eapply (msp_triangle (msp X)); eauto.
Qed.
-Lemma half_n_half (e : Q) : e / 2 + e / 2 = e.
-Proof. field; (change (not (2 ≡ 0)%Z); discriminate). Qed.
+Lemma mspc_negative_help (e : Q) : e < 0 → ∀ x y, ~ mspc_ball e x y.
+Proof.
+intros e_neg x y A. unfold mspc_ball, ms_msb in A.
+destruct (decide (e = 0)); [eapply lt_ne; eauto |].
+destruct (decide (0 < e)); [eapply lt_flip; eauto | trivial].
+Qed.
+
+Lemma mspc_refl_help (e : Q) : 0 ≤ e → Reflexive (mspc_ball e).
+Proof.
+intros e_nonneg x. unfold mspc_ball, ms_msb.
+destruct (decide (e = 0)); [intro d; apply (msp_refl (msp X)) |].
+destruct (decide (0 < e)) as [A | A]; [apply (msp_refl (msp X)) |].
+apply A, lt_iff_le_ne. now split; [| apply neq_symm].
+Qed.
+
+Lemma mspc_symm_help (e : Qinf) : Symmetric (mspc_ball e).
+Proof.
+intros x y A; unfold mspc_ball, ms_msb in *.
+destruct e as [e |]; [| trivial].
+destruct (decide (e = 0)); [intro d; now apply (msp_sym (msp X)) |].
+now destruct (decide (0 < e)); [apply (msp_sym (msp X)) |].
+Qed.
+
+(*Lemma half_n_half (e : Q) : e / 2 + e / 2 = e.
+Proof. field; discriminate. Qed.*)
Lemma mspc_triangle_0 (e : Q) (x y z : X) :
mspc_ball 0 x y → mspc_ball e y z → mspc_ball e x z.
@@ -59,11 +91,57 @@ destruct (decide (e = 0)).
(* intro d; setoid_replace d with (d * (1#2) + d * (1#2))%Qpos. *)
+ intros [d d_pos]. assert (hd_pos : (0 < d / 2)%Q) by (apply Q.Qmult_lt_0_compat; auto with qarith).
apply (msp_triangle' (mkQpos hd_pos) (mkQpos hd_pos) y); [| apply A1 | apply A2].
- apply half_n_half.
+ change (d / 2 + d / 2 = d); field; discriminate.
+ destruct (decide (0 < e)) as [E | E]; [| contradiction].
apply (msp_closed (msp X)). intro d.
- apply (msp_triangle' d (mkQpos E) y); [| apply A1 | apply A2].
- destruct d as [d d_pos]; change (d + e = e + d); ring.
+ apply (msp_triangle' d (mkQpos E) y); [apply plus_comm | apply A1 | apply A2].
+Qed.
+
+Lemma mspc_triangle_help (e1 e2 : Q) (x y z : X) :
+ mspc_ball e1 x y → mspc_ball e2 y z → mspc_ball (e1 + e2) x z.
+Proof.
+intros A1 A2. generalize A1 A2; intros A1' A2'.
+unfold mspc_ball, ms_msb in A1. destruct (decide (e1 = 0)) as [E1 | E1].
++ change ((e1 : Qinf) + (e2 : Qinf)) with (Qinf.finite (e1 + e2)%mc).
+ rewrite E1, plus_0_l. rewrite E1 in A1'. now apply mspc_triangle_0 with (y := y).
++ unfold mspc_ball, ms_msb in A2. destruct (decide (e2 = 0)) as [E2 | E2].
+ - change ((e1 : Qinf) + (e2 : Qinf)) with (Qinf.finite (e1 + e2)%mc).
+ rewrite E2, plus_0_r. rewrite E2 in A2'. apply mspc_symm_help.
+ now apply mspc_triangle_0 with (y := y); apply mspc_symm_help.
+ - destruct (decide (0 < e1)) as [e1_pos | ?]; destruct (decide (0 < e2)) as [e2_pos | ?];
+ [| contradiction ..].
+ assert (0 < e1 + e2) by solve_propholds. assert (e1 + e2 ≠ 0) by solve_propholds.
+ unfold mspc_ball, ms_msb; simpl.
+ destruct (decide (e1 + e2 = 0)); [contradiction |].
+ destruct (decide (0 < e1 + e2)) as [pos | nonpos]; [| contradiction].
+ setoid_replace (mkQpos pos) with (Qpos_plus (mkQpos e1_pos) (mkQpos e2_pos)) by easy.
+ now apply (msp_triangle (msp X)) with (b := y).
+Qed.
+
+Lemma mspc_ball_pos {e : Q} (e_pos : 0 < e) (x y : X) :
+ mspc_ball e x y <-> ball (mkQpos e_pos) x y.
+Proof.
+unfold mspc_ball, ms_msb.
+destruct (decide (e = 0)); [exfalso; now apply (lt_ne 0 e) |].
+destruct (decide (0 < e)) as [e_pos' | ?]; [now apply (ball_wd X) | contradiction].
+Qed.
+
+Lemma mspc_closed_help (e : Q) (x y : X) :
+ (∀ d : Q, 0 < d → mspc_ball (e + d) x y) → mspc_ball e x y.
+Proof.
+intro C. unfold mspc_ball, ms_msb.
+destruct (decide (e = 0)) as [e_zero | e_nonzero].
++ intros [d d_pos]; specialize (C d d_pos). rewrite e_zero, plus_0_l in C.
+ now apply (mspc_ball_pos d_pos) in C.
++ destruct (decide (0 < e)) as [e_pos | e_nonpos].
+ - apply (msp_closed (msp X)). intros [d d_pos]; specialize (C d d_pos).
+ assert (pos : 0 < e + d) by solve_propholds.
+ apply (mspc_ball_pos pos) in C.
+ now match goal with |- ball ?r x y => setoid_replace r with (mkQpos pos) by easy end.
+ - assert (e / 2 < 0) by (apply neg_pos_mult; now destruct (lt_trichotomy e 0) as [? | [? | ?]]).
+ assert (he_pos : 0 < -(e/2)) by now apply flip_neg_negate.
+ eapply mspc_negative_help; [| apply (C _ he_pos)].
+ now mc_setoid_replace (e - e / 2) with (e / 2) by (field; discriminate).
Qed.
Instance : ExtMetricSpaceClass X.
@@ -71,21 +149,13 @@ Proof.
constructor.
+ apply _.
+ intros; apply I.
-+ intros e e_neg x y A. unfold mspc_ball, ms_msb in A.
- destruct (decide (e = 0)); [eapply lt_ne; eauto |].
- destruct (decide (0 < e)); [eapply lt_flip; eauto | trivial].
-+ intros e e_nonneg x. unfold mspc_ball, ms_msb.
- destruct (decide (e = 0)); [intro d; apply (msp_refl (msp X)) |].
- destruct (decide (0 < e)) as [A | A]; [apply (msp_refl (msp X)) |].
- apply A, lt_iff_le_ne. now split; [| apply neq_symm].
-+ intros e x y A; unfold mspc_ball, ms_msb in *.
- destruct e as [e |]; [| trivial].
- destruct (decide (e = 0)); [intro d; now apply (msp_sym (msp X)) |].
- now destruct (decide (0 < e)); [apply (msp_sym (msp X)) |].
-+ intros e1 e2 x y z A1 A2.
- destruct (decide (e1 = 0)) as [E1 | E1].
- - rewrite E1 in A1 |- *; rewrite plus_0_l.
- now apply mspc_triangle_0 with (y := y).
- -
-unfold mspc_ball, ms_msb in A1.
++ apply mspc_negative_help.
++ apply mspc_refl_help.
++ apply mspc_symm_help.
++ apply mspc_triangle_help.
++ apply mspc_closed_help.
+Qed.
+
+End FromMetricSpace.
+
From 518d0ac3565a8948065f3bebd4e58ca3e61947f0 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 3 Jul 2012 21:51:32 +0200
Subject: [PATCH 014/110] Used CoRN.metric2.Metric.gball to shorten the
conversion from CoRN metric space to type class version
---
broken/FromMetric2.v | 146 ++++++++-----------------------------------
1 file changed, 27 insertions(+), 119 deletions(-)
diff --git a/broken/FromMetric2.v b/broken/FromMetric2.v
index 99cf7837..a53d825a 100644
--- a/broken/FromMetric2.v
+++ b/broken/FromMetric2.v
@@ -3,36 +3,13 @@ Require Import
abstract_algebra stdlib_rationals
orders.orders orders.semirings orders.rings theory.rings.
-Instance Qinf_plus_proper : Proper ((=) ==> (=) ==> (=)) Qinf.plus.
-Proof.
-intros x1 x2 Ex y1 y2 Ey.
-destruct x1 as [x1 |]; destruct x2 as [x2 |]; destruct y1 as [y1 |]; destruct y2 as [y2 |];
-unfold equiv, Qinf.eq in *; try contradiction; trivial.
-change (x1 = x2) in Ex; change (y1 = y2) in Ey; change (x1 + y1 = x2 + y2).
-now rewrite Ex, Ey.
-Qed.
-
-Program Instance : ∀ x y : Q, Decision (x < y) := λ x y,
- match Qlt_le_dec x y with
- | left H => left H
- | right _ => right _
- end.
-Next Obligation. now apply Qle_not_lt. Qed.
-
Section FromMetricSpace.
Variable X : MetricSpace.
-Instance ms_msb : MetricSpaceBall X := λ (e : Qinf) (x y : X),
+Instance msp_mspc_ball : MetricSpaceBall X := λ (e : Qinf) (x y : X),
match e with
-| Qinf.finite e' =>
- if (decide (e' = 0))
- then (forall d : Qpos, ball d x y)
- else
- match (decide (0 < e')) with
- | left e'_pos => ball (mkQpos e'_pos) x y
- | right _ => False
- end
+| Qinf.finite e' => gball e' x y
| Qinf.infinite => True
end.
@@ -41,107 +18,37 @@ Proof.
intros e1 e2 E1 x1 x2 E2 y1 y2 E3.
destruct e1 as [e1 |]; destruct e2 as [e2 |];
try (unfold equiv, Qinf.eq in *; contradiction); try reflexivity.
-unfold mspc_ball, ms_msb.
-change (e1 = e2) in E1.
-destruct (decide (e1 = 0)) as [A1 | A1]; destruct (decide (e2 = 0)) as [A2 | A2];
-[now rewrite E2, E3 | rewrite <- E1 in A2; now contradict A2 .. |].
-destruct (decide (0 < e1)) as [B1 | B1]; destruct (decide (0 < e2)) as [B2 | B2];
-[| exfalso; rewrite <- E1 in B2; now contradict B2 .. | easy].
-apply ball_wd; [apply E1 | now rewrite E2 | now rewrite E3].
+unfold mspc_ball, msp_mspc_ball.
+change (e1 = e2) in E1. now rewrite E1, E2, E3.
Qed.
-Lemma msp_triangle' (e1 e2: Qpos) (y x z : X) (e : Qpos) :
- (e1 + e2)%Qpos == e -> ball e1 x y -> ball e2 y z -> ball e x z.
+Lemma gball_pos {e : Q} (e_pos : 0 < e) (x y : X) : ball (e ↾ e_pos) x y <-> gball e x y.
Proof.
-intros E A1 A2. setoid_replace e with (e1 + e2)%Qpos by easy.
-eapply (msp_triangle (msp X)); eauto.
+unfold gball. destruct (Qsec.Qdec_sign e) as [[e_neg | e_pos'] | e_zero].
++ elim (Qlt_irrefl _ (Qlt_trans _ _ _ e_pos e_neg)).
++ mc_setoid_replace (e ↾ e_pos) with (e ↾ e_pos'); easy.
++ exfalso; rewrite e_zero in e_pos; apply (Qlt_irrefl _ e_pos).
Qed.
-Lemma mspc_negative_help (e : Q) : e < 0 → ∀ x y, ~ mspc_ball e x y.
+Lemma gball_neg (e : Q) (x y : X) : e < 0 -> ~ gball e x y.
Proof.
-intros e_neg x y A. unfold mspc_ball, ms_msb in A.
-destruct (decide (e = 0)); [eapply lt_ne; eauto |].
-destruct (decide (0 < e)); [eapply lt_flip; eauto | trivial].
-Qed.
-
-Lemma mspc_refl_help (e : Q) : 0 ≤ e → Reflexive (mspc_ball e).
-Proof.
-intros e_nonneg x. unfold mspc_ball, ms_msb.
-destruct (decide (e = 0)); [intro d; apply (msp_refl (msp X)) |].
-destruct (decide (0 < e)) as [A | A]; [apply (msp_refl (msp X)) |].
-apply A, lt_iff_le_ne. now split; [| apply neq_symm].
-Qed.
-
-Lemma mspc_symm_help (e : Qinf) : Symmetric (mspc_ball e).
-Proof.
-intros x y A; unfold mspc_ball, ms_msb in *.
-destruct e as [e |]; [| trivial].
-destruct (decide (e = 0)); [intro d; now apply (msp_sym (msp X)) |].
-now destruct (decide (0 < e)); [apply (msp_sym (msp X)) |].
-Qed.
-
-(*Lemma half_n_half (e : Q) : e / 2 + e / 2 = e.
-Proof. field; discriminate. Qed.*)
-
-Lemma mspc_triangle_0 (e : Q) (x y z : X) :
- mspc_ball 0 x y → mspc_ball e y z → mspc_ball e x z.
-Proof.
-intros A1 A2. unfold mspc_ball, ms_msb in *; simpl in A1.
-destruct (decide (e = 0)).
-(* intro d; setoid_replace d with (d * (1#2) + d * (1#2))%Qpos. *)
-+ intros [d d_pos]. assert (hd_pos : (0 < d / 2)%Q) by (apply Q.Qmult_lt_0_compat; auto with qarith).
- apply (msp_triangle' (mkQpos hd_pos) (mkQpos hd_pos) y); [| apply A1 | apply A2].
- change (d / 2 + d / 2 = d); field; discriminate.
-+ destruct (decide (0 < e)) as [E | E]; [| contradiction].
- apply (msp_closed (msp X)). intro d.
- apply (msp_triangle' d (mkQpos E) y); [apply plus_comm | apply A1 | apply A2].
-Qed.
-
-Lemma mspc_triangle_help (e1 e2 : Q) (x y z : X) :
- mspc_ball e1 x y → mspc_ball e2 y z → mspc_ball (e1 + e2) x z.
-Proof.
-intros A1 A2. generalize A1 A2; intros A1' A2'.
-unfold mspc_ball, ms_msb in A1. destruct (decide (e1 = 0)) as [E1 | E1].
-+ change ((e1 : Qinf) + (e2 : Qinf)) with (Qinf.finite (e1 + e2)%mc).
- rewrite E1, plus_0_l. rewrite E1 in A1'. now apply mspc_triangle_0 with (y := y).
-+ unfold mspc_ball, ms_msb in A2. destruct (decide (e2 = 0)) as [E2 | E2].
- - change ((e1 : Qinf) + (e2 : Qinf)) with (Qinf.finite (e1 + e2)%mc).
- rewrite E2, plus_0_r. rewrite E2 in A2'. apply mspc_symm_help.
- now apply mspc_triangle_0 with (y := y); apply mspc_symm_help.
- - destruct (decide (0 < e1)) as [e1_pos | ?]; destruct (decide (0 < e2)) as [e2_pos | ?];
- [| contradiction ..].
- assert (0 < e1 + e2) by solve_propholds. assert (e1 + e2 ≠ 0) by solve_propholds.
- unfold mspc_ball, ms_msb; simpl.
- destruct (decide (e1 + e2 = 0)); [contradiction |].
- destruct (decide (0 < e1 + e2)) as [pos | nonpos]; [| contradiction].
- setoid_replace (mkQpos pos) with (Qpos_plus (mkQpos e1_pos) (mkQpos e2_pos)) by easy.
- now apply (msp_triangle (msp X)) with (b := y).
-Qed.
-
-Lemma mspc_ball_pos {e : Q} (e_pos : 0 < e) (x y : X) :
- mspc_ball e x y <-> ball (mkQpos e_pos) x y.
-Proof.
-unfold mspc_ball, ms_msb.
-destruct (decide (e = 0)); [exfalso; now apply (lt_ne 0 e) |].
-destruct (decide (0 < e)) as [e_pos' | ?]; [now apply (ball_wd X) | contradiction].
+intro e_neg. unfold gball. destruct (Qsec.Qdec_sign e) as [[E | E] | E]; [easy | |].
++ intros _; apply (Qlt_irrefl _ (Qlt_trans _ _ _ e_neg E)).
++ rewrite E in e_neg. intros _; apply (Qlt_irrefl _ e_neg).
Qed.
Lemma mspc_closed_help (e : Q) (x y : X) :
(∀ d : Q, 0 < d → mspc_ball (e + d) x y) → mspc_ball e x y.
Proof.
-intro C. unfold mspc_ball, ms_msb.
-destruct (decide (e = 0)) as [e_zero | e_nonzero].
-+ intros [d d_pos]; specialize (C d d_pos). rewrite e_zero, plus_0_l in C.
- now apply (mspc_ball_pos d_pos) in C.
-+ destruct (decide (0 < e)) as [e_pos | e_nonpos].
- - apply (msp_closed (msp X)). intros [d d_pos]; specialize (C d d_pos).
- assert (pos : 0 < e + d) by solve_propholds.
- apply (mspc_ball_pos pos) in C.
- now match goal with |- ball ?r x y => setoid_replace r with (mkQpos pos) by easy end.
- - assert (e / 2 < 0) by (apply neg_pos_mult; now destruct (lt_trichotomy e 0) as [? | [? | ?]]).
- assert (he_pos : 0 < -(e/2)) by now apply flip_neg_negate.
- eapply mspc_negative_help; [| apply (C _ he_pos)].
- now mc_setoid_replace (e - e / 2) with (e / 2) by (field; discriminate).
+intro C. change (gball e x y). unfold gball.
+destruct (Qsec.Qdec_sign e) as [[e_neg | e_pos] | e_zero].
++ assert (e / 2 < 0) by now apply neg_pos_mult.
+ apply (gball_neg (e/2) x y); [easy |].
+ mc_setoid_replace (e / 2) with (e - e / 2) by (field; discriminate).
+ now apply C, flip_neg_negate.
++ apply (msp_closed (msp X)). intros [d d_pos]. now apply gball_pos, C.
++ apply ball_eq. intros [d d_pos]. apply gball_pos.
+ setoid_replace d with (e + d); [now apply C | rewrite e_zero; symmetry; apply plus_0_l].
Qed.
Instance : ExtMetricSpaceClass X.
@@ -149,13 +56,14 @@ Proof.
constructor.
+ apply _.
+ intros; apply I.
-+ apply mspc_negative_help.
-+ apply mspc_refl_help.
-+ apply mspc_symm_help.
-+ apply mspc_triangle_help.
++ intros; now apply gball_neg.
++ apply gball_refl.
++ intros [e |]; [apply gball_sym | easy].
++ apply gball_triangle.
+ apply mspc_closed_help.
Qed.
End FromMetricSpace.
+
From e4681f8b4f72367f0780c44e12ab7c1173b77206 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 5 Jul 2012 13:01:38 +0200
Subject: [PATCH 015/110] Proved that the completion of a metric space in the
sense of Metric2.Complete is complete in the sense of type classes
---
broken/FromMetric2.v | 57 +++++++++++++++++-
broken/metric.v | 139 ++++++++++++++++++++++++++++++++-----------
2 files changed, 159 insertions(+), 37 deletions(-)
diff --git a/broken/FromMetric2.v b/broken/FromMetric2.v
index a53d825a..03a60918 100644
--- a/broken/FromMetric2.v
+++ b/broken/FromMetric2.v
@@ -1,4 +1,4 @@
-Require Import Complete metric.
+Require Import metric2.Complete metric2.Metric metric.
Require Import
abstract_algebra stdlib_rationals
orders.orders orders.semirings orders.rings theory.rings.
@@ -7,7 +7,7 @@ Section FromMetricSpace.
Variable X : MetricSpace.
-Instance msp_mspc_ball : MetricSpaceBall X := λ (e : Qinf) (x y : X),
+Global Instance msp_mspc_ball : MetricSpaceBall X := λ (e : Qinf) (x y : X),
match e with
| Qinf.finite e' => gball e' x y
| Qinf.infinite => True
@@ -51,7 +51,7 @@ destruct (Qsec.Qdec_sign e) as [[e_neg | e_pos] | e_zero].
setoid_replace d with (e + d); [now apply C | rewrite e_zero; symmetry; apply plus_0_l].
Qed.
-Instance : ExtMetricSpaceClass X.
+Global Instance : ExtMetricSpaceClass X.
Proof.
constructor.
+ apply _.
@@ -63,7 +63,58 @@ constructor.
+ apply mspc_closed_help.
Qed.
+Definition conv_reg (f : RegularFunction X) : Complete.RegularFunction X.
+refine (@mkRegularFunction _ (f 0) (λ e : Qpos, let (e', _) := e in f e') _).
+intros [e1 e1_pos] [e2 e2_pos]. now apply gball_pos, (rf_proof f).
+Defined.
+
End FromMetricSpace.
+Arguments conv_reg {X} _.
+
+Set Printing Coercions.
+
+Definition ext_equiv' `{Equiv A} `{Equiv B} : Equiv (A → B) :=
+ λ f g, ∀ x : A, f x = g x.
+
+Infix "=1" := ext_equiv' (at level 70, no associativity) : type_scope.
+
+Lemma ext_equiv_l `{Setoid A, Setoid B} (f g : A -> B) :
+ Proper ((=) ==> (=)) f -> f =1 g -> f = g.
+Proof. intros P eq1_f_g x y eq_x_y; rewrite eq_x_y; apply eq1_f_g. Qed.
+
+Lemma ext_equiv_r `{Setoid A, Setoid B} (f g : A -> B) :
+ Proper ((=) ==> (=)) g -> f =1 g -> f = g.
+Proof. intros P eq1_f_g x y eq_x_y; rewrite <- eq_x_y; apply eq1_f_g. Qed.
+
+Section FromCompleteMetricSpace.
+
+Variable X : MetricSpace.
+
+(*Definition conv_reg_help (f : Q -> X) : QposInf -> X := λ e,
+match e with
+| Qpos2QposInf (e' ↾ _) => f e'
+| QposInfinity => f 0
+end.
+
+Lemma conv_reg_help_correct (f : Q -> X) :
+ IsRegularFunction f -> is_RegularFunction (conv_reg_help f).
+Proof. intros A [e1 e1_pos] [e2 e2_pos]; now apply gball_pos, A. Qed.*)
+
+Global Instance limit_complete : Limit (Complete X) :=
+ λ f : RegularFunction (Complete X), Cjoin_fun (conv_reg f).
+
+Global Instance : CompleteMetricSpaceClass (Complete X).
+Proof.
+constructor.
++ apply ext_equiv_r; [intros x y E; apply E |].
+ intros f e1 e2 e1_pos e2_pos.
+ eapply gball_pos, (CunitCjoin (conv_reg f) (e1 ↾ e1_pos) (e2 ↾ e2_pos)).
++ constructor; [apply _ .. |].
+ intros x y eq_x_y e1 e2 e1_pos e2_pos. apply mspc_eq; solve_propholds.
+Qed.
+
+End FromCompleteMetricSpace.
+
diff --git a/broken/metric.v b/broken/metric.v
index 611f1bcc..74d7619d 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -26,6 +26,7 @@ Proof. intros A1 A2 A3; now apply (po_proper _ _ A2 _ _ A3). Qed.
Lemma le_not_eq `{FullPartialOrder A} (x y : A) : x ≤ y -> x ≶ y -> x < y.
Proof. intros ? ?; apply lt_iff_le_apart; now split. Qed.
+(* Use orders.orders.le_equiv_lt instead *)
Lemma le_lt_eq `{@FullPartialOrder B Be Bap Ble Blt} `{@TrivialApart B Be Bap}
`{forall x y : B, Decision (x = y)} (x y : B) : x ≤ y ↔ x < y ∨ x = y.
Proof.
@@ -95,21 +96,37 @@ Proof. rewrite (Qlt_Qceiling_Z q n); symmetry; apply lt_Z_to_nat. Qed.
Lemma neq_symm `{Ae : Equiv X} `{!Symmetric Ae} (x y : X) : x ≠ y -> y ≠ x.
Proof. intros A1 A2; apply A1; now symmetry. Qed.
-Lemma plus_comm `{SemiRing R} (x y : R) : x + y = y + x.
-Proof. rapply commonoid_commutative; apply _. Qed.
+Lemma plus_comm `{SemiRing R} : Commutative (+).
+Proof. eapply commonoid_commutative; apply _. Qed.
+
+Lemma plus_assoc `{SemiRing R} : forall x y z : R, x + (y + z) = (x + y) + z.
+Proof. apply sg_ass, _. Qed.
Instance pos_ne_0 : forall `{StrictSetoidOrder A} `{Zero A} (x : A),
PropHolds (0 < x) -> PropHolds (x ≠ 0).
Proof. intros; now apply lt_ne_flip. Qed.
+(*Ltac MCQconst t :=
+match t with
+(*| @zero Q _ _ => constr:(Qmake Z0 xH)
+| @one Q _ _ => constr:(Qmake (Zpos xH) xH)*)
+| _ => Qcst t
+end.
+
+Add Field Q : (stdlib_field_theory Q)
+ (decidable Qeq_bool_eq,
+ completeness Qeq_eq_bool,
+ constants [MCQconst]).
+
+Goal forall x y : Q, (1#1)%Q * x = x.
+intros x y. ring.*)
+
Add Field Q : (stdlib_field_theory Q).
Bind Scope mc_scope with Q.
Notation Qinf := Qinf.T.
-Notation "n .+1" := (S n) (at level 2, left associativity, format "n .+1") : nat_scope.
-
(*
Local Notation Qnn := QnonNeg.T.
@@ -183,7 +200,7 @@ the radius is in Qnn (ie., QnonNeg.T), then we have to prove that 1 - q :
Qnn. It seems more convenient to have the radius live in Q and have the
axiom that no points are separated by a negative distance. *)
-Class ExtMetricSpace (X : Type) `{MetricSpaceBall X} : Prop := {
+Class ExtMetricSpaceClass (X : Type) `{MetricSpaceBall X} : Prop := {
mspc_radius_proper : Proper ((=) ==> (≡) ==> (≡) ==> iff) ball;
mspc_inf: ∀ x y, ball Qinf.infinite x y;
mspc_negative: ∀ (e: Q), e < 0 → ∀ x y, ~ ball e x y;
@@ -208,12 +225,12 @@ apply A.
Class MetricSpaceDistance (X : Type) := msd : X -> X -> Q.
-Class MetricSpace (X : Type) `{ExtMetricSpace X} `{MetricSpaceDistance X} : Prop :=
+Class MetricSpaceClass (X : Type) `{ExtMetricSpaceClass X} `{MetricSpaceDistance X} : Prop :=
mspc_distance : forall x1 x2 : X, ball (msd x1 x2) x1 x2.
Section ExtMetricSpace.
-Context `{ExtMetricSpace X}.
+Context `{ExtMetricSpaceClass X}.
Global Instance mspc_equiv : Equiv X := λ x1 x2, ball 0%Q x1 x2.
@@ -266,7 +283,7 @@ End ExtMetricSpace.
Section MetricSpace.
-Context `{MetricSpace X}.
+Context `{MetricSpaceClass X}.
Lemma msd_nonneg : forall x1 x2 : X, 0 ≤ msd x1 x2.
Proof.
@@ -280,7 +297,7 @@ End MetricSpace.
Section UniformContinuity.
-Context `{ExtMetricSpace X, ExtMetricSpace Y}.
+Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
Class IsUniformlyContinuous (f : X -> Y) (mu : Q -> Qinf) := {
uc_pos : forall e : Q, 0 < e -> (0 < mu e);
@@ -301,7 +318,7 @@ End UniformContinuity.
Section Contractions.
-Context `{MetricSpace X, ExtMetricSpace Y}.
+Context `{MetricSpaceClass X, ExtMetricSpaceClass Y}.
Class IsContraction (f : X -> Y) (q : Q) := {
contr_nonneg_mu : 0 ≤ q;
@@ -374,7 +391,7 @@ End UCFMetricSpace.
(*
Section Isometry.
-Context `{ExtMetricSpace X, ExtMetricSpace Y}.
+Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
Class Isometry (f : X -> Y) :=
isometry : forall (e : Q) (x1 x2 : X), ball e x1 x2 <-> ball e (f x1) (f x2).
@@ -395,7 +412,7 @@ End Isometry.
Section CompleteMetricSpace.
-Context `{ExtMetricSpace X}.
+Context `{ExtMetricSpaceClass X}.
Class IsRegularFunction (f : Q -> X) : Prop :=
rf_prf : forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> ball (e1 + e2) (f e1) (f e2).
@@ -412,7 +429,7 @@ Global Existing Instance rf_proof.
Instance rf_eq : Equiv RegularFunction :=
λ f1 f2, forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> ball (e1 + e2) (f1 e1) (f2 e2).
-Instance rf_setoid : Setoid RegularFunction.
+Global Instance rf_setoid : Setoid RegularFunction.
Proof.
constructor.
+ intros f e1 e2; apply rf_prf.
@@ -434,9 +451,9 @@ Definition reg_unit (x : X) := Build_RegularFunction (unit_reg x).
Class Limit := lim : RegularFunction -> X.
-Class CompleteMetricSpace `{Limit} := cmspc :> Surjective reg_unit (inv := lim).
+Class CompleteMetricSpaceClass `{Limit} := cmspc :> Surjective reg_unit (inv := lim).
-Lemma limit_def `{CompleteMetricSpace} (f : RegularFunction) :
+Lemma limit_def `{CompleteMetricSpaceClass} (f : RegularFunction) :
forall e : Q, 0 < e -> ball e (f e) (lim f).
Proof.
intros e2 A2. apply mspc_symm; apply mspc_closed.
@@ -449,7 +466,7 @@ End CompleteMetricSpace.
Arguments RegularFunction X {_}.
Arguments Limit X {_}.
-Arguments CompleteMetricSpace X {_ _ _}.
+Arguments CompleteMetricSpaceClass X {_ _ _}.
Definition seq A := nat -> A.
@@ -459,7 +476,7 @@ instance of [Equiv (seq X)] *)
Section SequenceLimits.
-Context `{ExtMetricSpace X}.
+Context `{ExtMetricSpaceClass X}.
Definition seq_lim (x : seq X) (a : X) (N : Q -> nat) :=
forall e : Q, 0 < e -> forall n : nat, N e ≤ n -> ball e (x n) a.
@@ -517,10 +534,8 @@ match (f x) with
| Qinf.infinite => inf
end.
-(*Section ContinuousFunctionSequence.*)
-
Theorem seq_lim_cont
- `{ExtMetricSpace X, ExtMetricSpace Y} (f : X -> Y) `{!IsUniformlyContinuous f mu}
+ `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y} (f : X -> Y) `{!IsUniformlyContinuous f mu}
(x : seq X) (a : X) (N : Q -> nat) :
seq_lim x a N → seq_lim (f ∘ x) (f a) (comp_inf N mu 0).
Proof.
@@ -530,13 +545,13 @@ now destruct (mu e); [apply A | apply mspc_inf].
Qed.
Theorem seq_lim_contr
- `{MetricSpace X, ExtMetricSpace Y} (f : X -> Y) `{!IsContraction f q}
+ `{MetricSpaceClass X, ExtMetricSpaceClass Y} (f : X -> Y) `{!IsContraction f q}
(x : seq X) (a : X) (N : Q -> nat) :
seq_lim x a N → seq_lim (f ∘ x) (f a) (comp_inf N (contr_modulus q) 0).
Proof. intro A; apply seq_lim_cont; [apply _ | apply A]. Qed.
Lemma iter_fixpoint
- `{ExtMetricSpace X, ExtMetricSpace Y}
+ `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}
(f : X -> X) `{!IsUniformlyContinuous f mu} (x : seq X) (a : X) (N : Q -> nat) :
(forall n : nat, x (S n) = f (x n)) -> seq_lim x a N -> f a = a.
Proof.
@@ -547,7 +562,7 @@ Qed.
Section CompleteSpaceSequenceLimits.
-Context `{CompleteMetricSpace X}.
+Context `{CompleteMetricSpaceClass X}.
Definition cauchy (x : seq X) (N : Q -> nat) :=
forall e : Q, 0 < e -> forall m n : nat, N e ≤ m -> N e ≤ n -> ball e (x m) (x n).
@@ -583,7 +598,7 @@ End CompleteSpaceSequenceLimits.
Section BanachFixpoint.
-Context `{MetricSpace X} {Xlim : Limit X} {Xcms : CompleteMetricSpace X}.
+Context `{MetricSpaceClass X} {Xlim : Limit X} {Xcms : CompleteMetricSpaceClass X}.
Context (f : X -> X) `{!IsContraction f q} (x0 : X).
@@ -612,6 +627,14 @@ rewrite <- flip_lt_negate in A. apply (strictly_order_preserving (1 +)) in A.
now rewrite plus_negate_r in A.
Qed.
+Instance : PropHolds (0 ≤ / q - 1).
+Proof. Admitted.
+(*(*apply (strictly_order_reflecting (+ (-1))).*)
+assert (A : q < 1) by solve_propholds. apply flip_lt_dec_recip in A.
+rewrite dec_recip_1 in A.
+apply (strictly_order_preserving (+ (-1))) in A. now rewrite plus_negate_r in A.
+Qed.*)
+
Lemma dist_xn_xSn : forall n : nat, ball (d * q^n) (x n) (x (1 + n)).
Proof.
induction n using nat_induction.
@@ -641,16 +664,6 @@ apply (order_preserving (1 +)). rewrite <- negate_0.
apply <- flip_le_negate. solve_propholds.
Qed.
-(*Let NQ (e : Q) : Q := (d / (e * (1 - q)^2)).
-
-Let N (e : Q) : nat := Z.to_nat (Qceiling (NQ e)).
-
-Lemma NQ_pos (e : Q) : 0 < d -> 0 < e -> 0 < NQ e.
-Proof. intros; subst NQ; solve_propholds. Qed.
-
-Lemma N_pos (e : Q) : 0 < d -> 0 < e -> 0 < N e.
-Proof. intros; now apply Qlt_Qceiling_nat, NQ_pos. Qed.*)
-
Lemma Qpower_mc_power (e : Q) (n : nat) : (e ^ n)%Q = (e ^ n)%mc.
Proof.
induction n as [| n IH] using nat_induction.
@@ -665,6 +678,64 @@ Anomaly: Signature and its instance do not match. Please report.
*)
Qed.
+Lemma Qstepl : forall (x y z : Q), x ≤ y -> x = z -> z ≤ y.
+Proof. intros ? ? ? ? A2; now rewrite <- A2. Qed.
+
+Lemma Qstepr : forall (x y z : Q), x ≤ y -> y = z -> x ≤ z.
+Proof. intros ? ? ? ? A2; now rewrite <- A2. Qed.
+
+Declare Left Step Qstepl.
+Declare Right Step Qstepr.
+
+Lemma binom_ineq (a : Q) (n : nat) : -1 ≤ a -> 1 + (n : Q) * a ≤ (1 + a)^n.
+Proof.
+intro A.
+assert (A1 : 0 ≤ 1 + a) by (now apply (order_preserving (1 +)) in A; rewrite plus_negate_r in A).
+induction n as [| n IH] using nat_induction.
++ rewrite nat_pow_0; change (1 + 0 * a ≤ 1); now rewrite mult_0_l, plus_0_r.
++ rewrite nat_pow_S. transitivity ((1 + a) * (1 + (n : Q) * a)).
+ - rewrite Nat2Z.inj_add, inject_Z_plus.
+ stepr (1 + (1 + (n : Q)) * a + (n : Q) * a²) by ring.
+ apply nonneg_plus_le_compat_r, nonneg_mult_compat; [apply Qle_Qceiling_nat, le_0_n | apply square_nonneg].
+ - now apply (order_preserving ((1 + a) *.)) in IH.
+Qed.
+
+Lemma nat_pow_recip `{DecField A} `{Naturals B} `{!NatPowSpec A B pw} :
+ (∀ x y : A, Decision (x = y)) ->
+ forall (a : A) (n : B), (/a) ^ n = /(a ^ n).
+Proof.
+intros D a. apply naturals.induction.
++ intros n1 n2 E; now rewrite E.
++ rewrite !nat_pow_0; symmetry; apply dec_recip_1.
++ intros n IH. now rewrite !nat_pow_S, dec_recip_distr, IH.
+Qed.
+
+(*
+Lemma power_tends_to_zero (e : Q) (n : nat) :
+ 0 < e -> Z.to_nat (Qceiling (q * (1 - e) / (e * (1 - q)))%mc) ≤ n -> q ^ n ≤ e.
+Proof.
+intros e_pos n_big.
+assert (A : /e ≤ (/q)^n).
++ mc_setoid_replace (/ q) with (1 + (/ q - 1)) by ring.
+ transitivity (1 + (n : Q) * (/ q - 1)).
+ - apply Qle_Qceiling_nat in n_big. set (m := (n : Q)) in *.
+ let T := type of n_big in match T with (Qle ?l ?r) => change (l ≤ r) in n_big end.
+ apply (order_reflecting (-1 +)). rewrite plus_assoc, plus_negate_l, plus_0_l.
+ apply (order_preserving (.* (/q - 1))) in n_big.
+ apply (po_proper' n_big); [| easy]. field.
+ (* When [plus_assoc : Associative (+)], the last rewrite does not work *)
+cut (forall x y z : Q, x + (y + z) = (x + y) + z). intro ass. rewrite ass.
+rewrite plus_assoc.
+ - apply binom_ineq. rewrite <- (plus_0_l (-1)) at 1.
+ apply (order_preserving (+ (-1))); solve_propholds.
++ rewrite nat_pow_recip in A; [| apply _]. apply flip_le_dec_recip in A; [| solve_propholds].
+ now rewrite !dec_recip_involutive in A.
+Qed.
+
+SearchAbout (/ (/ _) )%mc.
+flip_le_dec_recip
+*)
+
Lemma power_tends_to_zero (e : Q) (n : nat) :
0 < e -> Z.to_nat (Qceiling (/(e * (1 - q)))%mc) ≤ n -> q ^ n ≤ e.
Proof.
From e4bb1dd8cc39529c48aaf4b24d9a406ff8b11bfe Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 7 Aug 2012 13:32:50 +0200
Subject: [PATCH 016/110] Started adapting Simpson integration to AR
---
broken/SimpsonIntegration.v | 73 +++++++++++++++++++++++++++++++++----
1 file changed, 65 insertions(+), 8 deletions(-)
diff --git a/broken/SimpsonIntegration.v b/broken/SimpsonIntegration.v
index 613a08da..a497ba48 100755
--- a/broken/SimpsonIntegration.v
+++ b/broken/SimpsonIntegration.v
@@ -2,7 +2,7 @@ Require Import
List NPeano
QArith Qabs Qpossec Qsums Qround
Qmetric ZArith
- CRArith CRsum AbstractIntegration
+ CRArith CRsum (*AbstractIntegration*)
util.Qgcd
Program
uneven_CRplus
@@ -124,20 +124,77 @@ Print mkRegularFunction.
End definition.
-(*
-Open Scope Q_scope.
+Require Import ARtrans.
+Require Import Qdlog.
+Require Import ARbigD.
+
+Section ARInt.
+
+(*Open Scope Q_scope.*)
+
+Context
+ `{AppRationals AQ}
+ (f : AQ_as_MetricSpace --> AR)
+ (B : Q). (* bound for the absolute value of f's fourth derivative *)
+
+Definition ARsum_list_raw (l : list AR) (e : QposInf) : AQ :=
+fold_left (@plus AQ _)
+match l with
+| nil => nil
+| cons h t =>
+ let e' := QposInf_mult (1#(P_of_succ_nat (length t)))%Qpos e in
+ (map (fun x => approximate x e') l)
+end
+0.
+
+Lemma ARsum_list_prf : forall l, @is_RegularFunction AQ_as_MetricSpace (ARsum_list_raw l).
+Admitted.
+
+Definition ARsum_list (l : list AR) : AR := Build_RegularFunction (ARsum_list_prf l).
+
+Section ARapprox.
+
+ Context (a : AQ) (w : AQ) (eps : Qpos).
+
+ Definition N' : Z := 1 + Zdiv (Qdlog2 ('w^5 / 2880 * B / eps))%Q 4.
-Definition answer (n:positive) (r:CR) : Z :=
+ Definition iw' : AQ := w ≪ -N'.
+ (*Definition halfiw: Qpos := (w / ((2#1) * N))%Qpos.*)
+
+ Definition simpson' (a' : AQ) : AR :=
+ ('iw' * (f a' + f (a' + (iw' ≪ -1)) * '4 + f (a' + iw'))).
+
+ Definition approx' : AR :=
+ ARsum_list (map (fun i : nat => simpson' (a + '(i : Z) * iw')) (N.enum (2^(Z.to_nat N')))).
+
+End ARapprox.
+
+Lemma regular' a w : is_RegularFunction_noInf AR (approx' a w).
+Admitted.
+
+Definition simpson_integral' a w : AR := Cjoin (mkRegularFunction 0 (regular' a w)).
+
+End ARInt.
+
+(*Definition answer (n:positive) (r:CR) : Z :=
let m := (iter_pos n _ (Pmult 10) 1%positive) in
let (a,b) := (approximate r (1#m)%Qpos)*m in
- Zdiv a b.
+ Zdiv a b.*)
+
+Eval compute in N.enum (S O).
+
+Eval vm_compute in (N.enum ((2 : nat)^(Z.to_nat (N' (AQ := bigD) 1 1 (1#1000))))).
+
+Eval compute in (*cast _ Q*) (iw' (AQ := bigD) 1 1 (1#10)).
+Eval compute in simpson' (AQ := bigD) ARsin_uc 1 1 (1#10)%Qpos 0
-Require Import CRsin.
+Eval vm_compute in cast _ Q (approximate (approx' (AQ := bigD) ARsin_uc 1 0 1 (1#10)%Qpos) (1#10)%Qpos).
-Print simpson_integral.
+Time Eval vm_compute in
+ cast _ Q (approximate (simpson_integral' (AQ := bigD) ARsin_uc 1 0 1) (1#5)%Qpos).
-Time Eval compute in (answer 3 (simpson_integral sin_uc 1 0 1)).
+Time Eval compute in (cast _ Q (approximate (simpson_integral' (AQ := bigD) ARsin_uc 1 0 1) (1#100)%Qpos)).
(*
= 459
: Z
From 4358e011334613634aa28123cdd919a92e678c3b Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 21 Aug 2012 16:15:51 +0200
Subject: [PATCH 017/110] Now compiles with Coq 8.4
---
coq_reals/Rreals_iso.v | 4 ++--
model/structures/StepQsec.v | 6 +++---
reals/fast/CRArith.v | 6 +++---
reals/fast/CRseries.v | 4 +---
reals/faster/ARQ.v | 2 +-
reals/faster/ARbigQ.v | 2 +-
6 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/coq_reals/Rreals_iso.v b/coq_reals/Rreals_iso.v
index dd55cd37..195a78a5 100644
--- a/coq_reals/Rreals_iso.v
+++ b/coq_reals/Rreals_iso.v
@@ -882,9 +882,9 @@ Proof.
apply PI_RGT_0.
Qed.
-Lemma R_pi_alt_as_IR : RasIR (PI) [=] pi.
+Lemma R_pi_alt_as_IR : RasIR (Alt_PI) [=] pi.
Proof.
- unfold PI.
+ unfold Alt_PI.
unfold pi.
destruct (exist_PI) as [x prf].
unfold pi_series.
diff --git a/model/structures/StepQsec.v b/model/structures/StepQsec.v
index 0a8cbcc1..ec719eb4 100644
--- a/model/structures/StepQsec.v
+++ b/model/structures/StepQsec.v
@@ -246,9 +246,9 @@ Qed.
Lemma StepQRing_Morphism : ring_eq_ext StepQplus StepQmult StepQopp (@StepF_eq QS).
Proof.
split.
- apply StepQplus_wd.
- apply StepQmult_wd.
- apply StepQopp_wd.
+ apply: StepQplus_wd.
+ apply: StepQmult_wd.
+ apply: StepQopp_wd.
Qed.
Ltac isStepQcst t :=
diff --git a/reals/fast/CRArith.v b/reals/fast/CRArith.v
index a8a4eb1c..df678efc 100644
--- a/reals/fast/CRArith.v
+++ b/reals/fast/CRArith.v
@@ -238,9 +238,9 @@ Ltac CRring_pre := autorewrite with toCRring.
Lemma CR_ring_eq_ext : ring_eq_ext (ucFun2 CRplus_uc) CRmult CRopp (@st_eq CR).
Proof.
split.
- apply ucFun2_wd.
- apply CRmult_wd.
- apply uc_wd.
+ rapply ucFun2_wd.
+ rapply CRmult_wd.
+ rapply uc_wd.
Qed.
Add Ring CR_ring : CR_ring_theory (morphism CR_Q_ring_morphism, setoid (@st_isSetoid (@msp_is_setoid CR)) CR_ring_eq_ext, constants [CRcst], preprocess [CRring_pre]).
diff --git a/reals/fast/CRseries.v b/reals/fast/CRseries.v
index 7b0f059f..ce1ad1ee 100644
--- a/reals/fast/CRseries.v
+++ b/reals/fast/CRseries.v
@@ -179,7 +179,6 @@ Proof.
apply Qmult_le_compat_r; try assumption.
apply Qabs_nonneg.
apply: mult_Streams_Gs.
- apply _.
now destruct Hy.
Qed.
@@ -533,6 +532,5 @@ Proof.
right.
intros _.
apply: Stream_Bound_zl.
- apply Qrecip_factorial_bounded.
- apply _.
+ apply Qrecip_factorial_bounded.
Defined.
diff --git a/reals/faster/ARQ.v b/reals/faster/ARQ.v
index ed74822e..ca01ce20 100644
--- a/reals/faster/ARQ.v
+++ b/reals/faster/ARQ.v
@@ -18,7 +18,7 @@ Proof.
now apply ball_sym, approximateQ_correct.
change (/ Qpower (2%Z) p == 1 # 2 ^ p).
rewrite <-Qpower.Zpower_Qpower; auto with zarith.
- now rewrite Zpower_Ppow.
+ now rewrite <- Zpower_Ppow.
Qed.
Instance Q_approx_div: AppDiv Q := λ x y k, app_approx (x / y) k.
diff --git a/reals/faster/ARbigQ.v b/reals/faster/ARbigQ.v
index af02d169..f369ea4a 100644
--- a/reals/faster/ARbigQ.v
+++ b/reals/faster/ARbigQ.v
@@ -38,7 +38,7 @@ Proof.
rewrite BigN.spec_shiftl, Z.shiftl_1_l.
replace (BigZ.to_Z (BigZ.Pos (BigN.of_pos p))) with (Zpos p) by (symmetry; apply BigN.spec_of_pos).
rewrite BigN.spec_of_pos.
- replace (Z2P (2 ^ p)) with (2 ^ p)%positive by now rewrite Zpower_Ppow.
+ replace (Z2P (2 ^ p)) with (2 ^ p)%positive by now rewrite <- Zpower_Ppow.
rewrite <-Zpower_Ppow.
rewrite Z2P_correct.
reflexivity.
From 6f9a857142a3b53cb3a3e4922dde21640856e120 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Wed, 22 Aug 2012 17:18:49 +0200
Subject: [PATCH 018/110] Performed experiments with Simpson integration
---
broken/SimpsonIntegration.v | 211 ++++++++++++++++++++++++++++++++----
1 file changed, 191 insertions(+), 20 deletions(-)
mode change 100755 => 100644 broken/SimpsonIntegration.v
diff --git a/broken/SimpsonIntegration.v b/broken/SimpsonIntegration.v
old mode 100755
new mode 100644
index 613a08da..c0e7f7bb
--- a/broken/SimpsonIntegration.v
+++ b/broken/SimpsonIntegration.v
@@ -2,7 +2,7 @@ Require Import
List NPeano
QArith Qabs Qpossec Qsums Qround
Qmetric ZArith
- CRArith CRsum AbstractIntegration
+ CRArith CRsum (*AbstractIntegration*)
util.Qgcd
Program
uneven_CRplus
@@ -90,32 +90,40 @@ Definition Q_4th_root_floor_plain (q: Q): Z := Z_4th_root_floor_plain (Qceiling
Section definition.
- Context
+ Context
(f: Q_as_MetricSpace --> CR)
(b: Q). (* bound for the absolute value of f's fourth derivative *)
Section approx.
- Context (fr: Q) (w: Qpos) (e: Qpos).
+ Context (n : positive)(fr: Q) (w: Qpos) (e: Qpos).
Definition N: positive := P_of_succ_nat (Zabs_nat (Q_4th_root_floor_plain ((w^5) / 2880 * b / e))).
(* This Zabs is silly because we know the squaring thing only returns nonnegatives, but whatever. *)
(* Also, a ceil variant would obviate need to take the successor, but I haven't defined ceil variants
of the 4th root for Z/Q yet. *)
- Definition iw: Qpos := (w / N)%Qpos.
- Definition halfiw: Qpos := (w / ((2#1) * N))%Qpos.
-Open Scope Q_scope.
+ Definition iw : Qpos := (w / N)%Qpos.
+ Definition iw1 : Qpos := (w / n)%Qpos.
+ Definition halfiw : Qpos := (w / ((2#1) * N))%Qpos.
+ Definition halfiw1 : Qpos := (w / ((2#1) * n))%Qpos.
+
+ Open Scope Q_scope.
+
Definition simpson (fr: Q): CR :=
(' (iw / 6) * (f fr + f (fr + halfiw)%Q * '4 + f (fr + iw)%Q))%CR.
+ Definition simpson1 (fr: Q): CR :=
+ (' (iw1) * (f fr + f (fr + halfiw1)%Q * '4 + f (fr + iw1)%Q))%CR.
Definition approx: CR := CRsum_list (map (fun i: nat => simpson (fr + i * iw)) (N.enum (nat_of_P N))).
+ Definition approx1 : CR :=
+ CRsum_list (map (fun i: nat => simpson1 (fr + i * iw1)) (N.enum (nat_of_P n))).
End approx.
Lemma regular fr w: is_RegularFunction_noInf CR (approx fr w).
Admitted.
-Print mkRegularFunction.
+
Definition simpson_integral fr w: CR := Cjoin (mkRegularFunction ('(0%Q))%CR (regular fr w)).
(*
@@ -124,24 +132,187 @@ Print mkRegularFunction.
End definition.
-(*
-Open Scope Q_scope.
+Require Import CRsin CRexp.
+Require Import ARtrans.
+Require Import Qdlog.
+Require Import ARbigD.
+
+Definition eps (n : positive) := (1 # (10^n))%Qpos.
Definition answer (n:positive) (r:CR) : Z :=
- let m := (iter_pos n _ (Pmult 10) 1%positive) in
- let (a,b) := (approximate r (1#m)%Qpos)*m in
+ let m := (10^n)%positive in
+ let (a,b) := ((approximate r (1#m)%Qpos) * m)%Q in
Zdiv a b.
-Require Import CRsin.
+(*Time Eval vm_compute in approximate (simpson_integral sin_uc 1 0 1) (1#100000)%Qpos.*)
-Print simpson_integral.
+Section ARsum.
-Time Eval compute in (answer 3 (simpson_integral sin_uc 1 0 1)).
-(*
- = 459
- : Z
-Finished transaction in 17. secs (16.597038u,0.064004s)
-*)
+Context `{AppRationals AQ}.
+
+Definition ARsum_list_raw (l : list AR) (e : QposInf) : AQ :=
+fold_left (@plus AQ _)
+match l with
+| nil => nil
+| cons h t =>
+ let e' := QposInf_mult (1#(P_of_succ_nat (length t)))%Qpos e in
+ (map (fun x => approximate x e') l)
+end
+0.
+
+Lemma ARsum_list_prf : forall l, @is_RegularFunction AQ_as_MetricSpace (ARsum_list_raw l).
+Admitted.
+
+Definition ARsum_list (l : list AR) : AR := Build_RegularFunction (ARsum_list_prf l).
+
+End ARsum.
+
+Section ARInt.
+
+Context
+ `{AppRationals AQ}
+ (f : AR -> AR)
+ (B : Q). (* bound for the absolute value of f's fourth derivative *)
+
+Section ARIntSum.
+
+Context (*n : positive*) (a : AR) (w : AQ) (eps : Qpos).
+
+Definition num_intervals : nat := S (Z.to_nat (Q_4th_root_floor_plain ('w^5 / 2880 * B / eps))).
+
+Let f' (n : nat) := f(a + '(n : Z) * 'w * AQinv ('(2 * (num_intervals : Z))%Z)).
+
+Definition ARsimpson_raw : AR :=
+ (ARscale 4 (ARsum_list (map (fun i : nat => f' (2 * i + 1)) (N.enum (num_intervals - 0)))) +
+ ARscale 2 (ARsum_list (map (fun i : nat => f' (2 * i + 2)) (N.enum (num_intervals - 1)))) +
+ f' 0 + f' (2 * num_intervals)) * 'w * AQinv ('(6 * (num_intervals : Z))%Z).
+
+End ARIntSum.
+
+Lemma ARsimson_regular a w : is_RegularFunction_noInf AR (ARsimpson_raw a w).
+Admitted.
+
+Definition ARsimpson a w : AR := Cjoin (mkRegularFunction 0 (ARsimson_regular a w)).
+
+End ARInt.
+
+(*Compute Q_4th_root_floor_plain (3#28).*)
+Compute num_intervals (AQ := bigD) 3 1 (eps 15).
+
+(*Time Compute approximate (ARsimpson (AQ := bigD) ARexp 3 0 1) (eps 15).*)
+
+Section ARInt'.
+
+Context
+ `{AppRationals AQ}
+ (f : AQ -> AR)
+ (B : Q). (* bound for the absolute value of f's fourth derivative *)
+
+Section ARapprox.
+
+ Context (n : positive) (a : AQ) (w : AQ) (eps : Qpos).
+
+ Definition N' : nat := Z.to_nat (1 + Zdiv (Qdlog2 ('w^5 / 2880 * B / eps))%Q 4).
+
+ Definition iw' : AQ := w ≪ -(N' : Z).
+ Definition iw1' : AQ := w ≪ -(n : Z).
+
+ Definition simpson' (a' : AQ) : AR :=
+ ('iw' * (f a' + f (a' + (iw' ≪ -1)) * '4 + f (a' + iw'))).
+ Definition simpson1' (a' : AQ) : AR :=
+ ('iw1' * (f a' + f (a' + (iw1' ≪ -1)) * '4 + f (a' + iw1'))).
+
+ Definition approx' : AR :=
+ ARsum_list (map (fun i : nat => simpson' (a + '(i : Z) * iw')) (N.enum (2^N'))).
+ Definition approx1' : AR :=
+ ARsum_list (map (fun i : nat => simpson1' (a + '(i : Z) * iw1')) (N.enum (nat_of_P (2^n)%positive))).
+
+End ARapprox.
+
+Lemma regular' a w : is_RegularFunction_noInf AR (approx' a w).
+Admitted.
+
+Definition simpson_integral' a w : AR := Cjoin (mkRegularFunction 0 (regular' a w)).
+
+End ARInt'.
+
+Time Compute approximate (simpson_integral' ARexp 3 0 1) (eps 10).
+
+
+(*Eval compute in N' (AQ := bigD) 1 1 (eps 8).
+Eval compute in N 1 1 (eps 8).*)
+
+(*Time Check approximate (ARexp_bounded_uc (AQ := bigD) 2 1) (eps 20).
+Time Check approximate (ARexp (AQ := bigD) 1) (eps 20).
+
+Time Eval vm_compute in approximate (ARexp_bounded_uc (AQ := bigD) 2 1) (eps 20).
+Time Eval vm_compute in approximate (ARexp (AQ := bigD) 1) (eps 20).*)
+
+(*Time Check approximate (Cjoin_fun (Cmap_fun AQPrelengthSpace (ARexp_bounded_uc (AQ := bigD) 2) 1)) (eps 20).
+Time Eval vm_compute in
+ approximate (Cjoin_fun (Cmap_fun AQPrelengthSpace (ARexp_bounded_uc (AQ := bigD) 2) 1)) (eps 20).*)
+
+Goal approximate (ARexp (AQ := bigD) 1) (eps 20) = 0.
+unfold ARexp.
+change (Qceiling (' approximate 1 (1 # 1)%Qpos + 1)) with 2%Z.
+unfold ARexp_bounded, Cbind, Cmap, Cjoin, uc_compose, ucFun, Cjoin_fun, Cmap_fun.
+change (
+Cjoin_raw
+ {|
+ approximate := λ e : QposInf,
+ (ARexp_bounded_uc 2)
+ (approximate 1
+ (QposInf_bind
+ (mu (ARexp_bounded_uc (AQ := bigD) 2)) e));
+ regFun_prf := Cmap_fun_prf AQPrelengthSpace
+ (ARexp_bounded_uc 2) 1 |} (eps 20) = 0).
+unfold Cjoin_raw.
+change (approximate (ARexp_bounded_uc (AQ := bigD) 2 1) ((1 # 2)%Qpos * eps 20) = 0).
+
+
+
+simpl approximate.
+unfold Cjoin_raw. simpl.
+
+Time Eval vm_compute in approximate (ARexp (AQ := bigD) 1) (eps 20).
+Time Eval vm_compute in approximate (exp 1) (eps 20).
+Time Eval vm_compute in approximate (exp_bound_uc 3 1) (eps 130).
+
+Time Eval vm_compute in approximate (ARsin_uc (AQ := bigD) 1) (eps 20).
+Time Eval vm_compute in approximate (sin_uc 1) (eps 20).
+
+Time Eval vm_compute in approximate (sin_slow 1) (eps 50).
+Time Eval vm_compute in approximate (ARsin (AQ := bigD) 1) (eps 50).
+
+Require Import PowerSeries.
+
+Time Eval vm_compute in
+ approximate (ARsin (AQ := bigD) (ARsin (AQ := bigD) (ARsin (AQ := bigD) 1))) (eps 25).
+
+Time Eval vm_compute in approximate (approx1 sin_uc 32 0 1) (eps 50).
+Time Eval vm_compute in approximate (approx1' (AQ := bigD) ARsin_uc 5 0 1) (eps 50).
+
+
+
+Time Eval vm_compute in
+ (fun _ => tt) (map (fun _ => approximate (ARsin_uc (AQ := bigD) 1) (eps 10)) (N.enum 10)).
+Time Eval vm_compute in
+ (fun _ => tt) (map (fun _ => approximate (sin_uc 1) (eps 10)) (N.enum 10)).
+
+
+Time Eval vm_compute in approximate (approx' (AQ := bigD) ARsin_uc 1 0 1 (eps 8)) (eps 8).
+
+Time Eval vm_compute in approximate (simpson_integral sin_uc 1 0 1) (1#100000000)%Qpos.
+Time Eval vm_compute in answer 8 (simpson_integral sin_uc 1 0 1).
+
+(*Eval vm_compute in approximate (simpson' (AQ := bigD) ARsin_uc 1 1 (1#1)%Qpos 0) (1#1)%Qpos.*)
+
+(*Eval vm_compute in (*cast _ Q*)
+ (approximate (approx' (AQ := bigD) ARsin_uc 1 0 1 (1#10)%Qpos) (1#10)%Qpos).*)
+
+
+Time Eval vm_compute in
+ cast _ Q (approximate (simpson_integral' (AQ := bigD) ARsin_uc 1 0 1) (1#100000000)%Qpos).
-*)
\ No newline at end of file
+Time Eval vm_compute in N.enum ((2 : nat)^(N' (AQ := bigD) 1 1 (1#10000000000)%Qpos)).
\ No newline at end of file
From 29076dd1e7ba8ccce42a3fbb4e9e5fa78663159e Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Wed, 5 Sep 2012 21:58:10 +0200
Subject: [PATCH 019/110] Experiments on Simpson integration
---
broken/SimpsonIntegration.v | 311 +++++++++++++++++++++++++++++++-----
1 file changed, 274 insertions(+), 37 deletions(-)
diff --git a/broken/SimpsonIntegration.v b/broken/SimpsonIntegration.v
index a497ba48..37dae043 100755
--- a/broken/SimpsonIntegration.v
+++ b/broken/SimpsonIntegration.v
@@ -70,7 +70,7 @@ Proof.
unfold projT1 at 1.
generalize (Zsqrt_plain_is_pos). (* p (Zle_0_pos p)). *)
unfold Zsqrt_plain.
- generalize (Zsqrt). (*p (Zle_0_pos p)).*)
+ (*generalize (Zsqrt).*) (*p (Zle_0_pos p)).*)
admit.
(*
destruct s.
@@ -90,32 +90,40 @@ Definition Q_4th_root_floor_plain (q: Q): Z := Z_4th_root_floor_plain (Qceiling
Section definition.
- Context
+ Context
(f: Q_as_MetricSpace --> CR)
(b: Q). (* bound for the absolute value of f's fourth derivative *)
Section approx.
- Context (fr: Q) (w: Qpos) (e: Qpos).
+ Context (n : positive)(fr: Q) (w: Qpos) (e: Qpos).
Definition N: positive := P_of_succ_nat (Zabs_nat (Q_4th_root_floor_plain ((w^5) / 2880 * b / e))).
(* This Zabs is silly because we know the squaring thing only returns nonnegatives, but whatever. *)
(* Also, a ceil variant would obviate need to take the successor, but I haven't defined ceil variants
of the 4th root for Z/Q yet. *)
- Definition iw: Qpos := (w / N)%Qpos.
- Definition halfiw: Qpos := (w / ((2#1) * N))%Qpos.
-Open Scope Q_scope.
+ Definition iw : Qpos := (w / N)%Qpos.
+ Definition iw1 : Qpos := (w / n)%Qpos.
+ Definition halfiw : Qpos := (w / ((2#1) * N))%Qpos.
+ Definition halfiw1 : Qpos := (w / ((2#1) * n))%Qpos.
+
+ Open Scope Q_scope.
+
Definition simpson (fr: Q): CR :=
(' (iw / 6) * (f fr + f (fr + halfiw)%Q * '4 + f (fr + iw)%Q))%CR.
+ Definition simpson1 (fr: Q): CR :=
+ (' (iw1) * (f fr + f (fr + halfiw1)%Q * '4 + f (fr + iw1)%Q))%CR.
Definition approx: CR := CRsum_list (map (fun i: nat => simpson (fr + i * iw)) (N.enum (nat_of_P N))).
+ Definition approx1 : CR :=
+ CRsum_list (map (fun i: nat => simpson1 (fr + i * iw1)) (N.enum (nat_of_P n))).
End approx.
Lemma regular fr w: is_RegularFunction_noInf CR (approx fr w).
Admitted.
-Print mkRegularFunction.
+
Definition simpson_integral fr w: CR := Cjoin (mkRegularFunction ('(0%Q))%CR (regular fr w)).
(*
@@ -128,44 +136,241 @@ Require Import ARtrans.
Require Import Qdlog.
Require Import ARbigD.
-Section ARInt.
+Definition eps (n : positive) := (1 # (10^n))%Qpos.
-(*Open Scope Q_scope.*)
+Definition answer (n:positive) (r:CR) : Z :=
+ let m := (10^n)%positive in
+ let (a,b) := ((approximate r (1#m)%Qpos) * m)%Q in
+ Zdiv a b.
-Context
- `{AppRationals AQ}
- (f : AQ_as_MetricSpace --> AR)
- (B : Q). (* bound for the absolute value of f's fourth derivative *)
+
+(*Time Eval vm_compute in approximate (simpson_integral sin_uc 1 0 1) (1#100000)%Qpos.*)
+
+Definition sum_pos `{Zero A, Plus A} (f : positive -> A) (n : positive) :=
+ Pos.peano_rect (λ _, A) 0 (λ p x, f p + x) n.
+
+Definition sum_pos_iter `{Zero A, Plus A} (f : positive -> A) (n : positive) : A :=
+match n with
+| xH => 0
+| _ =>
+ let z :=
+ Pos.iter
+ (Pos.pred n)
+ (λ y : positive * A, let (p, x) := y in ((Pos.succ p), (f p + x)))
+ (1%positive, 0) in
+ snd z
+end.
+
+Section ARsum.
+
+Context `{AppRationals AQ}.
Definition ARsum_list_raw (l : list AR) (e : QposInf) : AQ :=
fold_left (@plus AQ _)
match l with
| nil => nil
| cons h t =>
- let e' := QposInf_mult (1#(P_of_succ_nat (length t)))%Qpos e in
+ let e' := QposInf_mult (1#(Pos.of_nat (length t)))%Qpos e in
(map (fun x => approximate x e') l)
end
0.
+Definition ARsum_raw (f : positive -> AR) (n : positive) (eps : QposInf) : AQ :=
+let e := (eps * (1 # Pos.pred n)%Qpos)%QposInf in
+ sum_pos_iter (λ p, approximate (f p) e) n.
+
Lemma ARsum_list_prf : forall l, @is_RegularFunction AQ_as_MetricSpace (ARsum_list_raw l).
Admitted.
+Lemma ARsum_prf : forall f n, @is_RegularFunction AQ_as_MetricSpace (ARsum_raw f n).
+Admitted.
+
Definition ARsum_list (l : list AR) : AR := Build_RegularFunction (ARsum_list_prf l).
+Definition ARsum (f : positive -> AR) (n : positive) : AR := Build_RegularFunction (ARsum_prf f n).
+
+End ARsum.
+
+Section ARInt.
+
+Context
+ `{AppRationals AQ}
+ (f : AR -> AR)
+ (B : Q) (* bound for the absolute value of f's fourth derivative *)
+ (a b : AR) (w : AQ).
+
+Let width : AR := b - a.
+
+Section ARIntN.
+
+Variable n : positive.
+
+Section ARIntEps.
+
+Variable eps : Qpos.
+
+Let hl' : AR := width * AQinv ('(Zpos n~0)). (* hl' = width / (2 * n) *)
+Let eps' : Qpos := eps * (1 # (6 * n)%positive)%Qpos.
+Let h (p : positive) := approximate (f (a + ARscale ('(Zpos p)) hl')) eps'.
+
+Definition ARsimpson_sum_raw : AQ :=
+ 4 * (sum_pos_iter (λ p, h (Pos.pred_double p)) (Pos.succ n)) +
+ 2 * (sum_pos_iter (λ p, h p~0) n) +
+ (approximate (f a) eps' + approximate (f b) eps').
+
+End ARIntEps.
+
+Lemma ARsimson_sum_regular : is_RegularFunction_noInf AQ_as_MetricSpace ARsimpson_sum_raw.
+Admitted.
+
+Definition ARsimpson_sum : AR := mkRegularFunction 0 ARsimson_sum_regular.
+
+End ARIntN.
+
+Section ARIntEps1.
+
+Variable eps : Qpos.
+
+Definition num_intervals : nat := S (Z.to_nat (Q_4th_root_floor_plain ('w^5 / 2880 * B / eps))).
+(* To be optimized *)
+Definition num_intervals1 : positive :=
+ P_of_succ_nat (Zabs_nat (Q_4th_root_floor_plain (('w^5) / 2880 * B / eps))).
+
+(* The following Check workd, but Definition does not
+Check fun x y : Q =>
+let w : Q := 'approximate width 1 + (1#1) in w.
+Definition aa := fun x y : Q =>
+let w : Q := 'approximate width 1 + (1#1) in w.*)
+
+(* Says can't find instance of Cast QA Q
+Definition num_intervals2 : Q :=
+ let w : Q := (cast AQ Q (approximate width (1#1)%Qpos) + (1#1))%Q in
+ Pos.succ (Z.to_pos (Q_4th_root_floor_plain (('w^5) / 2880 * B / eps))).*)
+
+Definition num_intervals2 : positive :=
+ let w : Q := 'approximate width (1#1000)%Qpos + (1#1000) in
+ Pos.succ (Z.to_pos (Q_4th_root_floor_plain (w^5 / 2880 * B / eps))).
+
+(* half-length *)
+Let hl : AR := width * AQinv ('(Zpos (num_intervals2~0)%positive)).
+
+Let f' (n : nat) := f(a + '(n : Z) * 'w * AQinv ('(2 * (num_intervals : Z))%Z)).
+Let g (p : positive) := f(a + ARscale ('(Zpos p)) hl).
+(*Let h (p : positive) (e : Qpos) := approximate (f (a + ARscale ('(Zpos p)) hl)) e.*)
+
+Definition ARsimpson_raw : AR :=
+ (ARscale 4 (ARsum_list (map (fun i : nat => f' (2 * i + 1)) (N.enum (num_intervals - 0)))) +
+ ARscale 2 (ARsum_list (map (fun i : nat => f' (2 * i + 2)) (N.enum (num_intervals - 1)))) +
+ (f' 0 + f' (2 * num_intervals))) * 'w * AQinv ('(6 * (num_intervals : Z))%Z).
+
+Definition ARsimpson1_raw : AR :=
+ ((ARscale 4 (ARsum (λ p, g (Pos.pred_double p)) (Pos.succ num_intervals2))) +
+ (ARscale 2 (ARsum (λ p, g p~0) num_intervals2)) +
+ (f a + f b))
+ * width * AQinv ('(6 * (num_intervals2 : Z))%Z).
+
+(*Definition ARsimpson_sum_raw : AQ :=
+ let e := eps * (1 # (6 * num_intervals2)%positive)%Qpos in
+ 4 * (sum_pos_iter (λ p, h (Pos.pred_double p) e) (Pos.succ num_intervals2)) +
+ 2 * (sum_pos_iter (λ p, h p~0 e) num_intervals2) +
+ (approximate (f a) e + approximate (f b) e).*)
+
+Definition ARsimpson2_raw : AR :=
+ ARsimpson_sum num_intervals2 * (width * AQinv ('Zpos (6 * num_intervals2)%positive)).
+
+End ARIntEps1.
+
+(*Lemma ARsimson_regular : is_RegularFunction_noInf AR ARsimpson_raw.
+Admitted.
+
+Lemma ARsimson1_regular : is_RegularFunction_noInf AR ARsimpson1_raw.
+Admitted.*)
+
+Lemma ARsimson2_regular : is_RegularFunction_noInf AR ARsimpson2_raw.
+Admitted.
+
+(*Definition ARsimpson : AR := Cjoin (mkRegularFunction 0 ARsimson_regular).
+Definition ARsimpson1 : AR := Cjoin (mkRegularFunction 0 ARsimson1_regular).*)
+Definition ARsimpson2 : AR := Cjoin (mkRegularFunction 0 ARsimson2_regular).
+
+(*Definition ARsimpson2 a b : AR :=
+ (ARsimpson_sum a b) * (width a b * AQinv ('(6 * (num_intervals2 a b : Z))%Z)).*)
+
+End ARInt.
+
+(*Time Compute approximate (ARexp (AQ := bigD) 4) (eps 2000)
+
+Time Check approximate ((ARexp (AQ := bigD) 4) * '((10 ^ 1000)%positive : Z)) (1#1)%Qpos.*)
+
+(*Compute N 3 1 (eps 20).
+Compute num_intervals (AQ := bigD) 3 1 (eps 13).*)
+
+(*Extraction "mult.ml" ARmult.*)
+
+(*Time Compute approximate (simpson_integral (exp_bound_uc 2) 3 0 1) (eps 11).*)
+
+(*
+(* The following shows that in evaluating x * y up to eps, (approximate x
+(eps / (2 * c))) where c is an approximation of y up to 1, is computed once
+and not twice. We make y very large so that the approximation of x takes a
+long time. Multiplcation takes less than twice the time of the approximation of x. *)
+
+Definition int := (ARsimpson (AQ := bigD) (ARexp_bounded (AQ := bigD) 2) 3 0 1).
+Definition e := '((10 ^ 12)%positive : Z) : ARbigD.
+
+Time Compute approximate (int * e) (1#1)%Qpos.
+
+Time Compute approximate int (eps 13).
+*)
+
+(* (ARexp x) calls ARexp_bounded on (Qceiling ('approximate x (1#1)%Qpos + (1#1))) and x.
+If x = 1, then the approximation is 2. *)
+
+Definition repeat {A : Type} (M : unit -> A) (n : positive) :=
+ Pos.iter n (fun _ => (fun _ => tt) (M tt)) tt.
+
+(*Definition M :=
+ fun _ : unit =>
+ approximate (ARexp_bounded (AQ := bigD) 2 1) (eps 12).*)
+
+Compute num_intervals2 (AQ := bigD) 3 0 1 (eps 15).
+
+(*Time Compute approximate (ARsimpson (AQ := bigD) (ARexp_bounded (AQ := bigD) 2) 3 0 1) (eps 14).*)
+Time Compute approximate (ARsimpson_sum (AQ := bigD) (ARexp_bounded (AQ := bigD) 2) 0 1 1012) (eps 14).
+Time Compute approximate (ARsimpson2 (AQ := bigD) (ARexp_bounded (AQ := bigD) 2) 3 0 1) (eps 14).
+
+
+(*Time Compute approximate (ARsimpson (AQ := bigD) ARexp 3 0 1) (eps 10).
+Time Compute approximate (ARsimpson (AQ := bigD) ARarctan 1 0 1) (eps 1).
+Time Compute approximate (ARsimpson (AQ := bigD) ARsqrt 3 0 1) (eps 12).
+Timeout 30 Compute approximate (ARsimpson (AQ := bigD) ARexp 3 0 1) (eps 1).
+Compute num_intervals (AQ := bigD) 3 1 (eps 0).*)
+
+Section ARInt'.
+
+Context
+ `{AppRationals AQ}
+ (f : AQ -> AR)
+ (B : Q). (* bound for the absolute value of f's fourth derivative *)
+
Section ARapprox.
- Context (a : AQ) (w : AQ) (eps : Qpos).
+ Context (n : positive) (a : AQ) (w : AQ) (eps : Qpos).
- Definition N' : Z := 1 + Zdiv (Qdlog2 ('w^5 / 2880 * B / eps))%Q 4.
+ Definition N' : nat := Z.to_nat (1 + Zdiv (Qdlog2 ('w^5 / 2880 * B / eps))%Q 4).
- Definition iw' : AQ := w ≪ -N'.
- (*Definition halfiw: Qpos := (w / ((2#1) * N))%Qpos.*)
+ Definition iw' : AQ := w ≪ -(N' : Z).
+ Definition iw1' : AQ := w ≪ -(n : Z).
Definition simpson' (a' : AQ) : AR :=
('iw' * (f a' + f (a' + (iw' ≪ -1)) * '4 + f (a' + iw'))).
+ Definition simpson1' (a' : AQ) : AR :=
+ ('iw1' * (f a' + f (a' + (iw1' ≪ -1)) * '4 + f (a' + iw1'))).
Definition approx' : AR :=
- ARsum_list (map (fun i : nat => simpson' (a + '(i : Z) * iw')) (N.enum (2^(Z.to_nat N')))).
+ ARsum_list (map (fun i : nat => simpson' (a + '(i : Z) * iw')) (N.enum (2^N'))).
+ Definition approx1' : AR :=
+ ARsum_list (map (fun i : nat => simpson1' (a + '(i : Z) * iw1')) (N.enum (nat_of_P (2^n)%positive))).
End ARapprox.
@@ -174,31 +379,63 @@ Admitted.
Definition simpson_integral' a w : AR := Cjoin (mkRegularFunction 0 (regular' a w)).
-End ARInt.
+End ARInt'.
+
+Time Compute approximate (simpson_integral' (AQ := bigD) AQexp 3 0 1) (eps 10).
+Time Compute approximate (simpson_integral' (AQ := bigD) ARexp 3 0 1) (eps 10).
-(*Definition answer (n:positive) (r:CR) : Z :=
- let m := (iter_pos n _ (Pmult 10) 1%positive) in
- let (a,b) := (approximate r (1#m)%Qpos)*m in
- Zdiv a b.*)
-Eval compute in N.enum (S O).
+(*Eval compute in N' (AQ := bigD) 1 1 (eps 8).
+Eval compute in N 1 1 (eps 8).*)
-Eval vm_compute in (N.enum ((2 : nat)^(Z.to_nat (N' (AQ := bigD) 1 1 (1#1000))))).
+(*Time Check approximate (ARexp_bounded_uc (AQ := bigD) 2 1) (eps 20).
+Time Check approximate (ARexp (AQ := bigD) 1) (eps 20).
-Eval compute in (*cast _ Q*) (iw' (AQ := bigD) 1 1 (1#10)).
+Time Eval vm_compute in approximate (ARexp_bounded_uc (AQ := bigD) 2 1) (eps 20).
+Time Eval vm_compute in approximate (ARexp (AQ := bigD) 1) (eps 20).*)
-Eval compute in simpson' (AQ := bigD) ARsin_uc 1 1 (1#10)%Qpos 0
+(*Time Check approximate (Cjoin_fun (Cmap_fun AQPrelengthSpace (ARexp_bounded_uc (AQ := bigD) 2) 1)) (eps 20).
+Time Eval vm_compute in
+ approximate (Cjoin_fun (Cmap_fun AQPrelengthSpace (ARexp_bounded_uc (AQ := bigD) 2) 1)) (eps 20).*)
-Eval vm_compute in cast _ Q (approximate (approx' (AQ := bigD) ARsin_uc 1 0 1 (1#10)%Qpos) (1#10)%Qpos).
+Time Eval vm_compute in approximate (ARexp (AQ := bigD) 1) (eps 20).
+Time Eval vm_compute in approximate (exp 1) (eps 20).
+Time Eval vm_compute in approximate (exp_bound_uc 3 1) (eps 130).
+
+Time Eval vm_compute in approximate (ARsin_uc (AQ := bigD) 1) (eps 20).
+Time Eval vm_compute in approximate (sin_uc 1) (eps 20).
+
+Time Eval vm_compute in approximate (sin_slow 1) (eps 50).
+Time Eval vm_compute in approximate (ARsin (AQ := bigD) 1) (eps 50).
+
+Require Import PowerSeries.
Time Eval vm_compute in
- cast _ Q (approximate (simpson_integral' (AQ := bigD) ARsin_uc 1 0 1) (1#5)%Qpos).
+ approximate (ARsin (AQ := bigD) (ARsin (AQ := bigD) (ARsin (AQ := bigD) 1))) (eps 25).
-Time Eval compute in (cast _ Q (approximate (simpson_integral' (AQ := bigD) ARsin_uc 1 0 1) (1#100)%Qpos)).
-(*
- = 459
- : Z
-Finished transaction in 17. secs (16.597038u,0.064004s)
-*)
+Time Eval vm_compute in approximate (approx1 sin_uc 32 0 1) (eps 50).
+Time Eval vm_compute in approximate (approx1' (AQ := bigD) ARsin_uc 5 0 1) (eps 50).
+
+
+
+Time Eval vm_compute in
+ (fun _ => tt) (map (fun _ => approximate (ARsin_uc (AQ := bigD) 1) (eps 10)) (N.enum 10)).
+Time Eval vm_compute in
+ (fun _ => tt) (map (fun _ => approximate (sin_uc 1) (eps 10)) (N.enum 10)).
+
+
+Time Eval vm_compute in approximate (approx' (AQ := bigD) ARsin_uc 1 0 1 (eps 8)) (eps 8).
+
+Time Eval vm_compute in approximate (simpson_integral sin_uc 1 0 1) (1#100000000)%Qpos.
+Time Eval vm_compute in answer 8 (simpson_integral sin_uc 1 0 1).
+
+(*Eval vm_compute in approximate (simpson' (AQ := bigD) ARsin_uc 1 1 (1#1)%Qpos 0) (1#1)%Qpos.*)
+
+(*Eval vm_compute in (*cast _ Q*)
+ (approximate (approx' (AQ := bigD) ARsin_uc 1 0 1 (1#10)%Qpos) (1#10)%Qpos).*)
+
+
+Time Eval vm_compute in
+ cast _ Q (approximate (simpson_integral' (AQ := bigD) ARsin_uc 1 0 1) (1#100000000)%Qpos).
-*)
\ No newline at end of file
+Time Eval vm_compute in N.enum ((2 : nat)^(N' (AQ := bigD) 1 1 (1#10000000000)%Qpos)).
\ No newline at end of file
From 00d9f75b257e0c2e05fe13f2263a5e3866374301 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 11 Sep 2012 15:39:37 +0200
Subject: [PATCH 020/110] Added Picard iteration
---
broken/SimpsonIntegration.v | 55 ++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 25 deletions(-)
diff --git a/broken/SimpsonIntegration.v b/broken/SimpsonIntegration.v
index 37dae043..51d54ca2 100755
--- a/broken/SimpsonIntegration.v
+++ b/broken/SimpsonIntegration.v
@@ -134,7 +134,7 @@ End definition.
Require Import ARtrans.
Require Import Qdlog.
-Require Import ARbigD.
+Require Import BigQ ARbigQ ARQ ARbigD.
Definition eps (n : positive) := (1 # (10^n))%Qpos.
@@ -234,18 +234,7 @@ Variable eps : Qpos.
Definition num_intervals : nat := S (Z.to_nat (Q_4th_root_floor_plain ('w^5 / 2880 * B / eps))).
(* To be optimized *)
Definition num_intervals1 : positive :=
- P_of_succ_nat (Zabs_nat (Q_4th_root_floor_plain (('w^5) / 2880 * B / eps))).
-
-(* The following Check workd, but Definition does not
-Check fun x y : Q =>
-let w : Q := 'approximate width 1 + (1#1) in w.
-Definition aa := fun x y : Q =>
-let w : Q := 'approximate width 1 + (1#1) in w.*)
-
-(* Says can't find instance of Cast QA Q
-Definition num_intervals2 : Q :=
- let w : Q := (cast AQ Q (approximate width (1#1)%Qpos) + (1#1))%Q in
- Pos.succ (Z.to_pos (Q_4th_root_floor_plain (('w^5) / 2880 * B / eps))).*)
+ P_of_succ_nat (Zabs_nat (Q_4th_root_floor_plain (('w^5) / 2880 * B / eps))).
Definition num_intervals2 : positive :=
let w : Q := 'approximate width (1#1000)%Qpos + (1#1000) in
@@ -280,22 +269,19 @@ Definition ARsimpson2_raw : AR :=
End ARIntEps1.
-(*Lemma ARsimson_regular : is_RegularFunction_noInf AR ARsimpson_raw.
+Lemma ARsimson_regular : is_RegularFunction_noInf AR ARsimpson_raw.
Admitted.
Lemma ARsimson1_regular : is_RegularFunction_noInf AR ARsimpson1_raw.
-Admitted.*)
+Admitted.
Lemma ARsimson2_regular : is_RegularFunction_noInf AR ARsimpson2_raw.
Admitted.
-(*Definition ARsimpson : AR := Cjoin (mkRegularFunction 0 ARsimson_regular).
-Definition ARsimpson1 : AR := Cjoin (mkRegularFunction 0 ARsimson1_regular).*)
+Definition ARsimpson : AR := Cjoin (mkRegularFunction 0 ARsimson_regular).
+Definition ARsimpson1 : AR := Cjoin (mkRegularFunction 0 ARsimson1_regular).
Definition ARsimpson2 : AR := Cjoin (mkRegularFunction 0 ARsimson2_regular).
-(*Definition ARsimpson2 a b : AR :=
- (ARsimpson_sum a b) * (width a b * AQinv ('(6 * (num_intervals2 a b : Z))%Z)).*)
-
End ARInt.
(*Time Compute approximate (ARexp (AQ := bigD) 4) (eps 2000)
@@ -333,11 +319,30 @@ Definition repeat {A : Type} (M : unit -> A) (n : positive) :=
fun _ : unit =>
approximate (ARexp_bounded (AQ := bigD) 2 1) (eps 12).*)
-Compute num_intervals2 (AQ := bigD) 3 0 1 (eps 15).
+(*Compute num_intervals2 (AQ := bigD) 3 0 1 (eps 15).*)
+
+(*Time Compute approximate (ARsimpson (AQ := bigD) (ARexp_bounded (AQ := bigD) 2) 3 0 1) (eps 14).
+Time Compute approximate (ARsimpson1 (AQ := bigD) (ARexp_bounded (AQ := bigD) 2) 3 0 1) (eps 14).*)
+(*Time Compute approximate (ARsimpson2 (AQ := Q) (ARexp_bounded 2) 3 0 1) (eps 9).
+Time Compute approximate (ARsimpson_sum (AQ := bigD) (ARexp_bounded (AQ := bigD) 2) 0 1 1012) (eps 14).*)
+
+Section Picard.
+
+Context `{AppRationals AQ} (F : AR -> AR) (a b : AR).
+
+Definition picard (f : AR -> AR) (x : AR) := b + ARsimpson2 (AQ := AQ) (λ t, F (f t)) 1 a x.
+
+Definition picard_iter (n : nat) : AR -> AR := nat_iter n picard (λ _, b).
+
+End Picard.
+
+Definition d := approximate (picard_iter (AQ := bigD) (λ y, y) 0 1 6 1) (eps 1).
+
+Extraction "simpson.ml" d.
+
+Time Compute approximate (picard_iter (AQ := bigD) (λ y, y) 0 1 6 1) (eps 1).
+
-(*Time Compute approximate (ARsimpson (AQ := bigD) (ARexp_bounded (AQ := bigD) 2) 3 0 1) (eps 14).*)
-Time Compute approximate (ARsimpson_sum (AQ := bigD) (ARexp_bounded (AQ := bigD) 2) 0 1 1012) (eps 14).
-Time Compute approximate (ARsimpson2 (AQ := bigD) (ARexp_bounded (AQ := bigD) 2) 3 0 1) (eps 14).
(*Time Compute approximate (ARsimpson (AQ := bigD) ARexp 3 0 1) (eps 10).
@@ -438,4 +443,4 @@ Time Eval vm_compute in answer 8 (simpson_integral sin_uc 1 0 1).
Time Eval vm_compute in
cast _ Q (approximate (simpson_integral' (AQ := bigD) ARsin_uc 1 0 1) (1#100000000)%Qpos).
-Time Eval vm_compute in N.enum ((2 : nat)^(N' (AQ := bigD) 1 1 (1#10000000000)%Qpos)).
\ No newline at end of file
+Time Eval vm_compute in N.enum ((2 : nat)^(N' (AQ := bigD) 1 1 (1#10000000000)%Qpos)).
From 9ea81f49afc811bcdb10df903d65d0a1ef9619f5 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 2 Oct 2012 16:25:27 +0200
Subject: [PATCH 021/110] Moved Banach Fixpoint theorem into BanachFixpoint.v.
Added locally uniformly continuous functions to metric.v
---
broken/AbstractIntegration.v | 7 +-
broken/BanachFixpoint.v | 206 +++++++++++++++++++++++++++++++
broken/Classified.v | 55 +++++----
broken/FromMetric2.v | 10 --
broken/metric.v | 227 ++++++++---------------------------
5 files changed, 294 insertions(+), 211 deletions(-)
create mode 100644 broken/BanachFixpoint.v
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index c1bc560e..77a6057f 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -9,7 +9,7 @@ Require Import
stdlib_omissions.Z
stdlib_omissions.Q
stdlib_omissions.N
- metric2.Classified.
+ (*metric2.Classified*).
Require QnonNeg QnnInf CRball.
Import QnonNeg.notations QnnInf.notations CRball.notations.
@@ -240,7 +240,7 @@ Section integral_interface.
split...
rewrite <- (Qplus_0_r from) at 1.
apply Qplus_le_compat...
- assert (lo <= hi) as lohi. apply CRle_trans with (f from); apply A...
+ assert (lo <= hi) as lohi. (*apply CRle_trans with (f from); apply A...
set (r := ' (1#2) * (hi - lo)).
set (mid := ' (1#2) * (lo + hi)).
assert (mid - r == lo) as loE by (subst mid r; ring).
@@ -258,7 +258,8 @@ Section integral_interface.
intros.
apply CRball.as_distance_bound, CRdistance_CRle.
rewrite loE, hiE...
- Qed.
+ Qed.*)
+ Admitted.
(** We now work towards unicity, for which we use that implementations must agree with Riemann
approximations. But since those are only valid for locally uniformly continuous functions, our proof
diff --git a/broken/BanachFixpoint.v b/broken/BanachFixpoint.v
new file mode 100644
index 00000000..348be2ae
--- /dev/null
+++ b/broken/BanachFixpoint.v
@@ -0,0 +1,206 @@
+Require Import
+ QArith
+ stdlib_rationals Qinf Qpossec QposInf QnonNeg abstract_algebra QType_rationals additional_operations.
+Require Import Qauto QOrderedType.
+Require Import theory.rings theory.dec_fields orders.rings orders.dec_fields nat_pow.
+Require Import interfaces.naturals interfaces.orders.
+Import peano_naturals.
+
+Require Import CRGeometricSum.
+Import Qround Qpower.
+Require Import metric.
+
+Local Notation ball := mspc_ball.
+
+Section BanachFixpoint.
+
+Context `{MetricSpaceClass X} {Xlim : Limit X} {Xcms : CompleteMetricSpaceClass X}.
+
+Context (f : X -> X) `{!IsContraction f q} (x0 : X).
+
+Let x n := nat_iter n f x0.
+
+Arguments x n%mc.
+
+Lemma x_Sn : forall n, x (1 + n) = f (x n).
+Proof. reflexivity. Qed.
+
+Let d := msd (x 0) (x 1).
+
+Instance : PropHolds (0 ≤ d).
+Proof. apply msd_nonneg. Qed.
+
+Instance : PropHolds (0 ≤ q).
+Proof. apply (contr_nonneg_mu f q). Qed.
+
+Instance : PropHolds (q < 1).
+Proof. apply (contr_lt_mu_1 f q). Qed.
+
+Instance : PropHolds (0 < 1 - q).
+Proof.
+assert (A := contr_lt_mu_1 f q).
+rewrite <- flip_lt_negate in A. apply (strictly_order_preserving (1 +)) in A.
+now rewrite plus_negate_r in A.
+Qed.
+
+Lemma dist_xn_xSn : forall n : nat, ball (d * q^n) (x n) (x (1 + n)).
+Proof.
+induction n using nat_induction.
++ rewrite nat_pow_0, right_identity; subst d; apply mspc_distance.
++ rewrite nat_pow_S. mc_setoid_replace (d * (q * q ^ n)) with (q * (d * q^n)) by ring.
+ change (x (1 + n)) with (f (x n)); change (x (1 + (1 + n))) with (f (x (1 + n))).
+ now apply contr_prf.
+Qed.
+
+Lemma dist_xm_xn : forall m n : nat, ball (d * q^m * (1 - q^n) / (1 - q)) (x m) (x (m + n)).
+Proof.
+intro m; induction n as [| n IH] using nat_induction.
++ rewrite right_identity; apply mspc_refl.
+ now rewrite nat_pow_0, plus_negate_r, right_absorb, left_absorb.
++ apply (mspc_triangle' (d * q^m * (1 - q^n) / (1 - q)) (d * q^(m + n)) (x (m + n))); trivial.
+ - rewrite nat_pow_S, nat_pow_exp_plus. field; solve_propholds.
+ - mc_setoid_replace (m + (1 + n)) with (1 + (m + n)) by ring. apply dist_xn_xSn.
+Qed.
+
+Lemma dist_xm_xn' : forall m n : nat, ball (d * q^m / (1 - q)) (x m) (x (m + n)).
+Proof.
+intros m n. apply (mspc_monotone (d * q^m * (1 - q^n) / (1 - q))); [| apply dist_xm_xn].
+apply (order_preserving (.* /(1 - q))). rewrite <- associativity.
+apply (order_preserving (d *.)). rewrite <- (mult_1_r (q^m)) at 2.
+apply (order_preserving (q^m *.)). rewrite <- (plus_0_r 1) at 2.
+apply (order_preserving (1 +)). rewrite <- negate_0.
+apply <- flip_le_negate. solve_propholds.
+Qed.
+
+Lemma Qpower_mc_power (e : Q) (n : nat) : (e ^ n)%Q = (e ^ n)%mc.
+Proof.
+induction n as [| n IH] using nat_induction.
++ now rewrite nat_pow_0.
++ rewrite Nat2Z.inj_add, Qpower_plus'.
+ - now rewrite nat_pow_S, IH.
+ - rewrite <- Nat2Z.inj_add; change 0%Z with (Z.of_nat 0); rewrite Nat2Z.inj_iff;
+ apply not_eq_sym, O_S.
+(*
+SearchPattern (?x ≢ ?y -> ?y ≢ ?x).
+Anomaly: Signature and its instance do not match. Please report.
+*)
+Qed.
+
+Lemma Qstepl : forall (x y z : Q), x ≤ y -> x = z -> z ≤ y.
+Proof. intros ? ? ? ? A2; now rewrite <- A2. Qed.
+
+Lemma Qstepr : forall (x y z : Q), x ≤ y -> y = z -> x ≤ z.
+Proof. intros ? ? ? ? A2; now rewrite <- A2. Qed.
+
+Declare Left Step Qstepl.
+Declare Right Step Qstepr.
+
+Lemma binom_ineq (a : Q) (n : nat) : -1 ≤ a -> 1 + (n : Q) * a ≤ (1 + a)^n.
+Proof.
+intro A.
+assert (A1 : 0 ≤ 1 + a) by (now apply (order_preserving (1 +)) in A; rewrite plus_negate_r in A).
+induction n as [| n IH] using nat_induction.
++ rewrite nat_pow_0; change (1 + 0 * a ≤ 1); now rewrite mult_0_l, plus_0_r.
++ rewrite nat_pow_S. transitivity ((1 + a) * (1 + (n : Q) * a)).
+ - rewrite Nat2Z.inj_add, inject_Z_plus.
+ stepr (1 + (1 + (n : Q)) * a + (n : Q) * a²) by ring.
+ apply nonneg_plus_le_compat_r, nonneg_mult_compat; [apply Qle_Qceiling_nat, le_0_n | apply square_nonneg].
+ - now apply (order_preserving ((1 + a) *.)) in IH.
+Qed.
+
+Lemma nat_pow_recip `{DecField A} `{Naturals B} `{!NatPowSpec A B pw} :
+ (∀ x y : A, Decision (x = y)) ->
+ forall (a : A) (n : B), (/a) ^ n = /(a ^ n).
+Proof.
+intros D a. apply naturals.induction.
++ intros n1 n2 E; now rewrite E.
++ rewrite !nat_pow_0; symmetry; apply dec_recip_1.
++ intros n IH. now rewrite !nat_pow_S, dec_recip_distr, IH.
+Qed.
+
+(*
+Lemma power_tends_to_zero (e : Q) (n : nat) :
+ 0 < e -> Z.to_nat (Qceiling (q * (1 - e) / (e * (1 - q)))%mc) ≤ n -> q ^ n ≤ e.
+Proof.
+intros e_pos n_big.
+assert (A : /e ≤ (/q)^n).
++ mc_setoid_replace (/ q) with (1 + (/ q - 1)) by ring.
+ transitivity (1 + (n : Q) * (/ q - 1)).
+ - apply Qle_Qceiling_nat in n_big. set (m := (n : Q)) in *.
+ let T := type of n_big in match T with (Qle ?l ?r) => change (l ≤ r) in n_big end.
+ apply (order_reflecting (-1 +)). rewrite plus_assoc, plus_negate_l, plus_0_l.
+ apply (order_preserving (.* (/q - 1))) in n_big.
+ apply (po_proper' n_big); [| easy]. field.
+ (* When [plus_assoc : Associative (+)], the last rewrite does not work *)
+cut (forall x y z : Q, x + (y + z) = (x + y) + z). intro ass. rewrite ass.
+rewrite plus_assoc.
+ - apply binom_ineq. rewrite <- (plus_0_l (-1)) at 1.
+ apply (order_preserving (+ (-1))); solve_propholds.
++ rewrite nat_pow_recip in A; [| apply _]. apply flip_le_dec_recip in A; [| solve_propholds].
+ now rewrite !dec_recip_involutive in A.
+Qed.
+
+SearchAbout (/ (/ _) )%mc.
+flip_le_dec_recip
+*)
+
+Lemma power_tends_to_zero (e : Q) (n : nat) :
+ 0 < e -> Z.to_nat (Qceiling (/(e * (1 - q)))%mc) ≤ n -> q ^ n ≤ e.
+Proof.
+intros A1 A2.
+assert (A3 : 0 < n).
++ let T := type of A2 in match T with (?lhs ≤ _) => apply lt_le_trans with (y := lhs) end; [| trivial].
+ apply Qlt_Qceiling_nat; change (0 < / (e * (1 - q))); solve_propholds.
++ destruct n as [| n]; [elim (lt_irrefl _ A3) |].
+ rewrite <- Qpower_mc_power.
+ apply GeometricCovergenceLemma with (e := e ↾ A1); [solve_propholds .. |].
+ apply (Qle_Qceiling_nat _ (S n)), A2.
+Qed.
+
+Lemma const_x (N : Q -> nat) : d = 0 -> cauchy x N.
+Proof.
+intro eq_d_0.
+assert (A := mspc_distance (x 0) (x 1)).
+subst d; rewrite eq_d_0 in A.
+assert (C : forall n, x n = x 0).
++ induction n as [| n IH] using nat_induction; [easy |].
+ change (x (1 + n)) with (f (x n)). rewrite IH. symmetry; apply A.
++ intros e e_pos m n _ _. rewrite (C m), (C n). (* second "rewrite C" does not work *)
+ apply mspc_refl. solve_propholds.
+Qed.
+
+Lemma cauchy_x : cauchy x (λ e, Z.to_nat (Qceiling (d / (e * (1 - q)²))%mc)).
+Proof.
+assert (d_nonneg : 0 ≤ d) by solve_propholds.
+assert (d_pos_0 : 0 < d \/ 0 = d) by now apply le_lt_eq.
+destruct d_pos_0 as [d_pos | d_0]; [| now apply const_x].
+intros e e_pos.
+(* without loss of generality, m ≤ n *)
+match goal with
+|- forall m n, @?G m n => intros m n; assert (A : forall m n, m ≤ n -> G m n)
+end.
++ clear m n; intros m n le_m_n A _.
+ rewrite <- (cut_minus_le n m); trivial. rewrite plus_comm.
+ apply (mspc_monotone (d * q^m / (1 - q))); [| apply dist_xm_xn'].
+ cut (q ^ m ≤ e * (1 - q) / d).
+ - intro A1. apply (order_preserving (d *.)), (order_preserving (.* /(1 - q))) in A1.
+ apply (po_proper' A1); [easy | field; split; solve_propholds].
+ - apply power_tends_to_zero; [solve_propholds |].
+ apply (po_proper' A); [| easy]. apply f_equal, Qceiling_comp.
+ match goal with |- (Qeq ?l ?r) => change (l = r) end.
+ field; repeat split; solve_propholds.
++ assert (A1 : TotalRelation (A := nat) (≤)) by apply _; destruct (A1 m n).
+ - now apply A.
+ - intros; apply mspc_symm; now apply A.
+Qed.
+
+Let a := lim (reg_fun x _ cauchy_x).
+
+Lemma banach_fixpoint : f a = a.
+Proof.
+assert (C := cauchy_x).
+(* [Check seq_lim_lim (A := C)] says "Wrong argument name: A", but [About seq_lim_lim] shows A *)
+eapply (iter_fixpoint f x); [easy | apply seq_lim_lim].
+Qed.
+
+End BanachFixpoint.
diff --git a/broken/Classified.v b/broken/Classified.v
index ca81c268..2065b13c 100644
--- a/broken/Classified.v
+++ b/broken/Classified.v
@@ -5,7 +5,7 @@
Require Import
Arith List
- CSetoids Qmetric Qring Qinf ProductMetric QposInf
+ CSetoids Qmetric Qring Qinf ProductMetric QposInf Qposclasses (* defines Equiv on Qpos *)
UniformContinuity stdlib_rationals
stdlib_omissions.Pair stdlib_omissions.Q PointFree
interfaces.abstract_algebra
@@ -227,14 +227,14 @@ Proof. intros; now apply genball_Proper. Qed.
change (genball (exist _ e1 B + exist _ e2 E )%Qpos a c).
apply ball_genball.
apply Rtriangle with b; apply ball_genball...
- rewrite <- V. rewrite F. rewrite Qplus_0_r...
+ rewrite <- V. Admitted. (*rewrite F. rewrite Qplus_0_r...
rewrite U, C, Qplus_0_l...
exfalso. apply (Qlt_irrefl (e1 + e2)). rewrite -> C at 1. rewrite -> F at 1...
exfalso. apply (Qlt_irrefl (e1 + e2)). rewrite -> J at 1...
revert U. rewrite <- V, <- (Qplus_0_r e1), <- F, J...
revert V. rewrite <- (Qplus_0_l e2), <- C, J, U...
transitivity b...
- Qed.
+ Qed.*)
Lemma genball_closed :
(∀ (e: Qinf) (a b: X), (∀ d: Qpos, genball (e + d) a b) → genball e a b).
@@ -261,9 +261,10 @@ Proof. intros; now apply genball_Proper. Qed.
apply Req.
intros.
apply ball_genball.
- rewrite <- (Qplus_0_l d).
+ admit.
+ (*rewrite <- (Qplus_0_l d).
rewrite <- q0.
- apply H2.
+ apply H2.*)
Qed.
Instance genball_MetricSpace: @MetricSpaceClass X _ genball.
@@ -288,10 +289,11 @@ Proof.
apply genball_MetricSpace; try apply _.
apply msp_refl, X.
apply msp_sym, X.
- apply msp_triangle, X.
+(* apply msp_triangle, X.
apply msp_eq, X.
apply msp_closed, X.
-Qed.
+Qed.*)
+Admitted.
Section products.
@@ -360,7 +362,8 @@ Section vector_setoid.
unfold equiv.
unfold Equiv_instance_0.
induction x; simpl; constructor...
- reflexivity.
+ Admitted.
+(* reflexivity.
unfold equiv.
unfold Equiv_instance_0.
unfold Symmetric.
@@ -369,7 +372,7 @@ Section vector_setoid.
apply Vector.Forall2_ind; constructor...
symmetry...
admit. (* transitivity *)
- Qed.
+ Qed.*)
End vector_setoid. (* Todo: Move. *)
@@ -527,7 +530,7 @@ Section uniform_continuity.
Let hint := uc_from.
Let hint' := uc_to.
- Program Definition wrap_uc_fun
+(* Program Definition wrap_uc_fun
: UniformlyContinuousFunction (bundle_MetricSpace X) (bundle_MetricSpace Y)
:= @Build_UniformlyContinuousFunction (bundle_MetricSpace X) (bundle_MetricSpace Y) f uc_mu _.
@@ -537,7 +540,7 @@ Section uniform_continuity.
apply uniformlyContinuous.
destruct uc_mu...
apply (mspc_ball_inf X).
- Qed.
+ Qed.*)
(** Note that wrap_uc_fun _also_ bundles the source and target metric spaces, because
UniformlyContinuousFunction is expressed in terms of the bundled data type for metric spaces. *)
@@ -724,10 +727,11 @@ Section proper_functions.
constructor.
intros ????.
destruct x...
- repeat intro. symmetry...
+ repeat intro. (*symmetry...
repeat intro.
transitivity (proj1_sig y x0)...
- Qed.
+ Qed.*)
+ Admitted.
Global Instance: MetricSpaceBall T := λ e f g, Qinf.le 0 e ∧ ∀ a, mspc_ball e (` f a) (` g a).
(* The 0<=e condition is needed because otherwise if A is empty, we cannot deduce
@@ -771,7 +775,7 @@ Section proper_functions.
repeat intro.
destruct H2.
destruct x.
- simpl.
+ (*simpl.
rewrite H3.
apply (mspc_ball_zero B)...
split.
@@ -820,7 +824,8 @@ Section proper_functions.
apply (mspc_closed B).
intros.
apply H2.
- Qed. (* Todo: This is awful. Clean it up once these blasted evar anomalies are under control. *)
+ Qed.*) (* Todo: This is awful. Clean it up once these blasted evar anomalies are under control. *)
+ Admitted.
End proper_functions.
@@ -842,9 +847,10 @@ Section uc_functions.
intros ????.
set (_: Proper (=) (ucFun_itself x)).
destruct x...
- repeat intro. symmetry...
+ repeat intro. (*symmetry...
intros ? y ??? x. transitivity (y x)...
- Qed.
+ Qed.*)
+ Admitted.
Global Instance: MetricSpaceBall (UCFunction A B) := λ e f g, Qinf.le 0 e ∧ ∀ a, mspc_ball e (f a) (g a).
(* The 0<=e condition is needed because otherwise if A is empty, we cannot deduce
@@ -860,7 +866,7 @@ Section uc_functions.
rewrite <- H3.
apply H6.
intros.
- rewrite <- H3.
+ (*rewrite <- H3.
rewrite <- (H4 a). 2: reflexivity.
rewrite <- (H5 a). 2: reflexivity.
apply H6...
@@ -935,7 +941,8 @@ Section uc_functions.
apply (mspc_closed B).
intros.
apply H3.
- Qed. (* Todo: This is awful. Clean it up once these blasted evar anomalies are under control. *)
+ Qed.*) (* Todo: This is awful. Clean it up once these blasted evar anomalies are under control. *)
+ Admitted.
End uc_functions.
@@ -1070,11 +1077,12 @@ Section map_pair_uc.
Global Instance: UniformlyContinuous (map_pair f g).
Proof with auto.
constructor; try apply _. intros.
- pose proof (together_uc (wrap_uc_fun f) (wrap_uc_fun g) e a b) as P.
+ (*pose proof (together_uc (wrap_uc_fun f) (wrap_uc_fun g) e a b) as P.
apply P. simpl in *.
destruct (QposInf_min)...
simpl...
- Qed.
+ Qed.*)
+ Admitted.
End map_pair_uc.
(** The diagonal function is uniformly continuous: *)
@@ -1123,14 +1131,15 @@ Section compose_uc.
Global Instance compose_uc: UniformlyContinuous (f ∘ g)%prg.
Proof with auto.
constructor; try apply _.
- intros ??? P.
+ (*intros ??? P.
apply (uniformlyContinuous f).
revert P. simpl.
generalize (uc_mu f e).
destruct q; intros; simpl.
apply (uniformlyContinuous g)...
apply (mspc_ball_inf Y).
- Qed.
+ Qed.*)
+ Admitted.
End compose_uc.
Section curried_uc.
diff --git a/broken/FromMetric2.v b/broken/FromMetric2.v
index 03a60918..b19c88d4 100644
--- a/broken/FromMetric2.v
+++ b/broken/FromMetric2.v
@@ -91,16 +91,6 @@ Section FromCompleteMetricSpace.
Variable X : MetricSpace.
-(*Definition conv_reg_help (f : Q -> X) : QposInf -> X := λ e,
-match e with
-| Qpos2QposInf (e' ↾ _) => f e'
-| QposInfinity => f 0
-end.
-
-Lemma conv_reg_help_correct (f : Q -> X) :
- IsRegularFunction f -> is_RegularFunction (conv_reg_help f).
-Proof. intros A [e1 e1_pos] [e2 e2_pos]; now apply gball_pos, A. Qed.*)
-
Global Instance limit_complete : Limit (Complete X) :=
λ f : RegularFunction (Complete X), Cjoin_fun (conv_reg f).
diff --git a/broken/metric.v b/broken/metric.v
index 74d7619d..8c8238bb 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -596,203 +596,80 @@ Qed.
End CompleteSpaceSequenceLimits.
-Section BanachFixpoint.
+Section SubMetricSpace.
-Context `{MetricSpaceClass X} {Xlim : Limit X} {Xcms : CompleteMetricSpaceClass X}.
+Context `{ExtMetricSpaceClass X} (P : X -> Prop).
-Context (f : X -> X) `{!IsContraction f q} (x0 : X).
+Global Instance sig_mspc_ball : MetricSpaceBall (sig P) := λ e x y, ball e (` x) (` y).
-Let x n := nat_iter n f x0.
+Global Instance sig_mspc : ExtMetricSpaceClass (sig P).
+Proof.
+constructor.
++ repeat intro; rapply mspc_radius_proper; congruence.
++ repeat intro; rapply mspc_inf.
++ intros; now rapply mspc_negative.
++ repeat intro; now rapply mspc_refl.
++ repeat intro; now rapply mspc_symm.
++ repeat intro; rapply mspc_triangle; eauto.
++ repeat intro; now rapply mspc_closed.
+Qed.
-Arguments x n%mc.
+End SubMetricSpace.
-Lemma x_Sn : forall n, x (1 + n) = f (x n).
-Proof. reflexivity. Qed.
+Section LocalUniformContinuity.
-Let d := msd (x 0) (x 1).
+Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
-Instance : PropHolds (0 ≤ d).
-Proof. apply msd_nonneg. Qed.
+Definition restrict (f : X -> Y) (x : X) (r : Q) : sig (ball r x) -> Y :=
+ f ∘ @proj1_sig _ _.
-Instance : PropHolds (0 ≤ q).
-Proof. apply (contr_nonneg_mu f q). Qed.
+Class IsLocallyUniformlyContinuous (f : X -> Y) (lmu : X -> Q -> Q -> Qinf) := {
+ luc_pos : forall (x : X) (r e : Q), 0 < e -> (0 < lmu x r e);
+ luc_prf : forall (x : X) (r : Q), IsUniformlyContinuous (restrict f x r) (lmu x r)
+}.
-Instance : PropHolds (q < 1).
-Proof. apply (contr_lt_mu_1 f q). Qed.
+(*Global Arguments luc_pos f mu {_} e _.
+Global Arguments luc_prf f mu {_} e x1 x2 _ _.*)
-Instance : PropHolds (0 < 1 - q).
+Global Instance uc_ulc (f : X -> Y) `{!IsUniformlyContinuous f mu} :
+ IsLocallyUniformlyContinuous f (λ _ _, mu).
Proof.
-assert (A := contr_lt_mu_1 f q).
-rewrite <- flip_lt_negate in A. apply (strictly_order_preserving (1 +)) in A.
-now rewrite plus_negate_r in A.
+constructor.
++ intros _ _; now apply (uc_pos f).
++ intros x r. constructor; [now apply (uc_pos f) |].
+ intros e [x1 A1] [x2 A2] e_pos A. now apply (uc_prf f mu).
Qed.
-Instance : PropHolds (0 ≤ / q - 1).
-Proof. Admitted.
-(*(*apply (strictly_order_reflecting (+ (-1))).*)
-assert (A : q < 1) by solve_propholds. apply flip_lt_dec_recip in A.
-rewrite dec_recip_1 in A.
-apply (strictly_order_preserving (+ (-1))) in A. now rewrite plus_negate_r in A.
-Qed.*)
-
-Lemma dist_xn_xSn : forall n : nat, ball (d * q^n) (x n) (x (1 + n)).
-Proof.
-induction n using nat_induction.
-+ rewrite nat_pow_0, right_identity; subst d; apply mspc_distance.
-+ rewrite nat_pow_S. mc_setoid_replace (d * (q * q ^ n)) with (q * (d * q^n)) by ring.
- change (x (1 + n)) with (f (x n)); change (x (1 + (1 + n))) with (f (x (1 + n))).
- now apply contr_prf.
-Qed.
+End LocalUniformContinuity.
-Lemma dist_xm_xn : forall m n : nat, ball (d * q^m * (1 - q^n) / (1 - q)) (x m) (x (m + n)).
-Proof.
-intro m; induction n as [| n IH] using nat_induction.
-+ rewrite right_identity; apply mspc_refl.
- now rewrite nat_pow_0, plus_negate_r, right_absorb, left_absorb.
-+ apply (mspc_triangle' (d * q^m * (1 - q^n) / (1 - q)) (d * q^(m + n)) (x (m + n))); trivial.
- - rewrite nat_pow_S, nat_pow_exp_plus. field; solve_propholds.
- - mc_setoid_replace (m + (1 + n)) with (1 + (m + n)) by ring. apply dist_xn_xSn.
-Qed.
-Lemma dist_xm_xn' : forall m n : nat, ball (d * q^m / (1 - q)) (x m) (x (m + n)).
-Proof.
-intros m n. apply (mspc_monotone (d * q^m * (1 - q^n) / (1 - q))); [| apply dist_xm_xn].
-apply (order_preserving (.* /(1 - q))). rewrite <- associativity.
-apply (order_preserving (d *.)). rewrite <- (mult_1_r (q^m)) at 2.
-apply (order_preserving (q^m *.)). rewrite <- (plus_0_r 1) at 2.
-apply (order_preserving (1 +)). rewrite <- negate_0.
-apply <- flip_le_negate. solve_propholds.
-Qed.
+(*Section ClosedSegmentComplete.
-Lemma Qpower_mc_power (e : Q) (n : nat) : (e ^ n)%Q = (e ^ n)%mc.
-Proof.
-induction n as [| n IH] using nat_induction.
-+ now rewrite nat_pow_0.
-+ rewrite Nat2Z.inj_add, Qpower_plus'.
- - now rewrite nat_pow_S, IH.
- - rewrite <- Nat2Z.inj_add; change 0%Z with (Z.of_nat 0); rewrite Nat2Z.inj_iff;
- apply not_eq_sym, O_S.
-(*
-SearchPattern (?x ≢ ?y -> ?y ≢ ?x).
-Anomaly: Signature and its instance do not match. Please report.
-*)
-Qed.
+Context `{CompleteMetricSpaceClass X, Le X, @PartialOrder X _ _}.
-Lemma Qstepl : forall (x y z : Q), x ≤ y -> x = z -> z ≤ y.
-Proof. intros ? ? ? ? A2; now rewrite <- A2. Qed.
+Variables a b : X.
-Lemma Qstepr : forall (x y z : Q), x ≤ y -> y = z -> x ≤ z.
-Proof. intros ? ? ? ? A2; now rewrite <- A2. Qed.
+Definition segment := sig (λ x, a ≤ x ≤ b).
-Declare Left Step Qstepl.
-Declare Right Step Qstepr.
+Typeclasses Transparent segment.
-Lemma binom_ineq (a : Q) (n : nat) : -1 ≤ a -> 1 + (n : Q) * a ≤ (1 + a)^n.
-Proof.
-intro A.
-assert (A1 : 0 ≤ 1 + a) by (now apply (order_preserving (1 +)) in A; rewrite plus_negate_r in A).
-induction n as [| n IH] using nat_induction.
-+ rewrite nat_pow_0; change (1 + 0 * a ≤ 1); now rewrite mult_0_l, plus_0_r.
-+ rewrite nat_pow_S. transitivity ((1 + a) * (1 + (n : Q) * a)).
- - rewrite Nat2Z.inj_add, inject_Z_plus.
- stepr (1 + (1 + (n : Q)) * a + (n : Q) * a²) by ring.
- apply nonneg_plus_le_compat_r, nonneg_mult_compat; [apply Qle_Qceiling_nat, le_0_n | apply square_nonneg].
- - now apply (order_preserving ((1 + a) *.)) in IH.
-Qed.
+(*Program Instance segment_limit : Limit segment :=
+ λ f, lim (Build_RegularFunction (λ e, proj1_sig (f e)) _).
+generates an infinite number of obligation [MetricSpaceBall segment] *)
-Lemma nat_pow_recip `{DecField A} `{Naturals B} `{!NatPowSpec A B pw} :
- (∀ x y : A, Decision (x = y)) ->
- forall (a : A) (n : B), (/a) ^ n = /(a ^ n).
-Proof.
-intros D a. apply naturals.induction.
-+ intros n1 n2 E; now rewrite E.
-+ rewrite !nat_pow_0; symmetry; apply dec_recip_1.
-+ intros n IH. now rewrite !nat_pow_S, dec_recip_distr, IH.
-Qed.
-
-(*
-Lemma power_tends_to_zero (e : Q) (n : nat) :
- 0 < e -> Z.to_nat (Qceiling (q * (1 - e) / (e * (1 - q)))%mc) ≤ n -> q ^ n ≤ e.
-Proof.
-intros e_pos n_big.
-assert (A : /e ≤ (/q)^n).
-+ mc_setoid_replace (/ q) with (1 + (/ q - 1)) by ring.
- transitivity (1 + (n : Q) * (/ q - 1)).
- - apply Qle_Qceiling_nat in n_big. set (m := (n : Q)) in *.
- let T := type of n_big in match T with (Qle ?l ?r) => change (l ≤ r) in n_big end.
- apply (order_reflecting (-1 +)). rewrite plus_assoc, plus_negate_l, plus_0_l.
- apply (order_preserving (.* (/q - 1))) in n_big.
- apply (po_proper' n_big); [| easy]. field.
- (* When [plus_assoc : Associative (+)], the last rewrite does not work *)
-cut (forall x y z : Q, x + (y + z) = (x + y) + z). intro ass. rewrite ass.
-rewrite plus_assoc.
- - apply binom_ineq. rewrite <- (plus_0_l (-1)) at 1.
- apply (order_preserving (+ (-1))); solve_propholds.
-+ rewrite nat_pow_recip in A; [| apply _]. apply flip_le_dec_recip in A; [| solve_propholds].
- now rewrite !dec_recip_involutive in A.
-Qed.
-
-SearchAbout (/ (/ _) )%mc.
-flip_le_dec_recip
-*)
-
-Lemma power_tends_to_zero (e : Q) (n : nat) :
- 0 < e -> Z.to_nat (Qceiling (/(e * (1 - q)))%mc) ≤ n -> q ^ n ≤ e.
-Proof.
-intros A1 A2.
-assert (A3 : 0 < n).
-+ let T := type of A2 in match T with (?lhs ≤ _) => apply lt_le_trans with (y := lhs) end; [| trivial].
- apply Qlt_Qceiling_nat; change (0 < / (e * (1 - q))); solve_propholds.
-+ destruct n as [| n]; [elim (lt_irrefl _ A3) |].
- rewrite <- Qpower_mc_power.
- apply GeometricCovergenceLemma with (e := e ↾ A1); [solve_propholds .. |].
- apply (Qle_Qceiling_nat _ (S n)), A2.
-Qed.
-
-Lemma const_x (N : Q -> nat) : d = 0 -> cauchy x N.
-Proof.
-intro eq_d_0.
-assert (A := mspc_distance (x 0) (x 1)).
-subst d; rewrite eq_d_0 in A.
-assert (C : forall n, x n = x 0).
-+ induction n as [| n IH] using nat_induction; [easy |].
- change (x (1 + n)) with (f (x n)). rewrite IH. symmetry; apply A.
-+ intros e e_pos m n _ _. rewrite (C m), (C n). (* second "rewrite C" does not work *)
- apply mspc_refl. solve_propholds.
-Qed.
+(* In the context (f : RegularFunction segment), (proj1_sig ∘ f) does not typecheck,
+but (λ e, proj1_sig (f e)) does *)
-Lemma cauchy_x : cauchy x (λ e, Z.to_nat (Qceiling (d / (e * (1 - q)²))%mc)).
+Lemma lim_inside_r (f : RegularFunction X) :
+ (forall e, f e ≤ b) -> lim f ≤ b.
Proof.
-assert (d_nonneg : 0 ≤ d) by solve_propholds.
-assert (d_pos_0 : 0 < d \/ 0 = d) by now apply le_lt_eq.
-destruct d_pos_0 as [d_pos | d_0]; [| now apply const_x].
-intros e e_pos.
-(* without loss of generality, m ≤ n *)
-match goal with
-|- forall m n, @?G m n => intros m n; assert (A : forall m n, m ≤ n -> G m n)
-end.
-+ clear m n; intros m n le_m_n A _.
- rewrite <- (cut_minus_le n m); trivial. rewrite plus_comm.
- apply (mspc_monotone (d * q^m / (1 - q))); [| apply dist_xm_xn'].
- cut (q ^ m ≤ e * (1 - q) / d).
- - intro A1. apply (order_preserving (d *.)), (order_preserving (.* /(1 - q))) in A1.
- apply (po_proper' A1); [easy | field; split; solve_propholds].
- - apply power_tends_to_zero; [solve_propholds |].
- apply (po_proper' A); [| easy]. apply f_equal, Qceiling_comp.
- match goal with |- (Qeq ?l ?r) => change (l = r) end.
- field; repeat split; solve_propholds.
-+ assert (A1 : TotalRelation (A := nat) (≤)) by apply _; destruct (A1 m n).
- - now apply A.
- - intros; apply mspc_symm; now apply A.
-Qed.
-
-Let a := lim (reg_fun x _ cauchy_x).
+intro A.
-Lemma banach_fixpoint : f a = a.
-Proof.
-assert (C := cauchy_x).
-(* [Check seq_lim_lim (A := C)] says "Wrong argument name: A", but [About seq_lim_lim] shows A *)
-eapply (iter_fixpoint f x); [easy | apply seq_lim_lim].
-Qed.
-End BanachFixpoint.
+Global Instance segment_limit : Limit segment.
+intro f.
+(* Check (λ (e : Q), `(f e)) : Q -> X. does not work *)
+(* refine (lim (Build_RegularFunction (λ e, proj1_sig (f e)) _) ↾ _).
+This generates one goal and one existential variable instead of two goals *)
+refine (lim (Build_RegularFunction (λ e, proj1_sig (f e)) (rf_proof f)) ↾ _).
+*)
From fbbcc5c5762880d4c2d23c6a9d237652089edefd Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 4 Oct 2012 13:59:58 +0200
Subject: [PATCH 022/110] Proving approximation by Riemann sums in
AbstractIntegration
---
broken/AbstractIntegration.v | 51 +++++++++++++++++++++++++++---------
broken/FromMetric2.v | 7 +++--
broken/metric.v | 23 +++++++++-------
3 files changed, 58 insertions(+), 23 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 77a6057f..f9d71da2 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -8,12 +8,39 @@ Require Import
stdlib_omissions.P
stdlib_omissions.Z
stdlib_omissions.Q
- stdlib_omissions.N
- (*metric2.Classified*).
+ stdlib_omissions.N.
+ (*metric2.Classified*)
+Require Import metric FromMetric2.
Require QnonNeg QnnInf CRball.
Import QnonNeg.notations QnnInf.notations CRball.notations.
+(*Notation Qinf := Qinf.T.
+
+Module Qinf.
+
+Definition le (x y : Qinf) : Prop :=
+match y with
+| Qinf.finite b =>
+ match x with
+ | Qinf.finite a => Qle a b
+ | Qinf.infinite => False
+ end
+| Qinf.infinite => True
+end.
+
+Instance: Proper (Qinf.eq ==> Qinf.eq ==> iff) le.
+Proof.
+intros [x1 |] [x2 |] A1 [y1 |] [y2 |] A2; revert A1 A2;
+unfold Qinf.eq, canonical_names.equiv, stdlib_rationals.Q_eq; simpl; intros A1 A2;
+try contradiction; try reflexivity.
+rewrite A1, A2; reflexivity.
+Qed.
+
+End Qinf.
+
+Instance Qinf_le : canonical_names.Le Qinf := Qinf.le.*)
+
Open Local Scope Q_scope.
Open Local Scope uc_scope.
Open Local Scope CR_scope.
@@ -240,7 +267,7 @@ Section integral_interface.
split...
rewrite <- (Qplus_0_r from) at 1.
apply Qplus_le_compat...
- assert (lo <= hi) as lohi. (*apply CRle_trans with (f from); apply A...
+ assert (lo <= hi) as lohi by (destruct (A _ B); now apply CRle_trans with (f from)).
set (r := ' (1#2) * (hi - lo)).
set (mid := ' (1#2) * (lo + hi)).
assert (mid - r == lo) as loE by (subst mid r; ring).
@@ -256,17 +283,16 @@ Section integral_interface.
rewrite <- (CRplus_opp lo).
apply (CRplus_le_r lo hi (-lo))...
intros.
- apply CRball.as_distance_bound, CRdistance_CRle.
+ apply CRball.as_distance_bound. apply -> CRdistance_CRle.
rewrite loE, hiE...
- Qed.*)
- Admitted.
+ Qed.
(** We now work towards unicity, for which we use that implementations must agree with Riemann
approximations. But since those are only valid for locally uniformly continuous functions, our proof
of unicity only works for such functions. Todo: There should really be a proof that does not depend
on continuity. *)
- Context `{!LocallyUniformlyContinuous_mu f} `{!LocallyUniformlyContinuous f}.
+ Context (*`{!LocallyUniformlyContinuous_mu f}*) `{!IsLocallyUniformlyContinuous f lmu}.
(*
Lemma gball_integral (e: Qpos) (a a': Q) (ww: Qpos) (w: QnonNeg):
@@ -301,11 +327,12 @@ Section integral_interface.
Qed.
*)
(** Iterating this result shows that Riemann sums are arbitrarily good approximations: *)
-(*
- Lemma Riemann_sums_approximate_integral (a: Q) (w: Qpos) (e: Qpos) (iw: QnonNeg) (n: nat):
- (n * iw == w)%Qnn ->
- (iw <= @luc_mu _ _ f _ a w e)%QnnInf ->
- gball (e * w) (cmΣ n (fun i => ' ` iw * f (a + i * ` iw)%Q)) (∫ f a w).
+
+ Import Qinf.notations.
+ Lemma Riemann_sums_approximate_integral (a: Q) (w: Qpos) (e: Qpos) (iw: Q) (n: nat):
+ (n * iw == w)%Q ->
+ (iw <= lmu a w e)%Qinf ->
+ gball (e * w) (cmΣ n (fun i => ' iw * f (a + i * iw)%Q)) (∫ f a w).
Proof with auto.
intros A B.
simpl.
diff --git a/broken/FromMetric2.v b/broken/FromMetric2.v
index b19c88d4..606d9d2e 100644
--- a/broken/FromMetric2.v
+++ b/broken/FromMetric2.v
@@ -3,6 +3,10 @@ Require Import
abstract_algebra stdlib_rationals
orders.orders orders.semirings orders.rings theory.rings.
+Section QField.
+
+Add Field Q : (dec_fields.stdlib_field_theory Q).
+
Section FromMetricSpace.
Variable X : MetricSpace.
@@ -106,5 +110,4 @@ Qed.
End FromCompleteMetricSpace.
-
-
+End QField.
diff --git a/broken/metric.v b/broken/metric.v
index 8c8238bb..9d8badcb 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -121,12 +121,6 @@ Add Field Q : (stdlib_field_theory Q)
Goal forall x y : Q, (1#1)%Q * x = x.
intros x y. ring.*)
-Add Field Q : (stdlib_field_theory Q).
-
-Bind Scope mc_scope with Q.
-
-Notation Qinf := Qinf.T.
-
(*
Local Notation Qnn := QnonNeg.T.
@@ -146,6 +140,8 @@ Instance Qpos_inv : DecRecip Qpos := Qpossec.Qpos_inv.
Instance Qinf_one : One Qinf := 1%Q.
*)
+Notation Qinf := Qinf.T.
+
Module Qinf.
Definition lt (x y : Qinf) : Prop :=
@@ -190,6 +186,12 @@ Ltac nat_simpl := unfold
Tactic Notation "Qsimpl" hyp_list(A) := revert A; Qsimpl'; intros A.
*)
+Section QField.
+
+Add Field Q : (stdlib_field_theory Q).
+
+Bind Scope mc_scope with Q.
+
Class MetricSpaceBall (X : Type) : Type := mspc_ball: Qinf → relation X.
Local Notation ball := mspc_ball.
@@ -464,9 +466,9 @@ Qed.
End CompleteMetricSpace.
-Arguments RegularFunction X {_}.
-Arguments Limit X {_}.
-Arguments CompleteMetricSpaceClass X {_ _ _}.
+Global Arguments RegularFunction X {_}.
+Global Arguments Limit X {_}.
+Global Arguments CompleteMetricSpaceClass X {_ _ _}.
Definition seq A := nat -> A.
@@ -673,3 +675,6 @@ intro f.
This generates one goal and one existential variable instead of two goals *)
refine (lim (Build_RegularFunction (λ e, proj1_sig (f e)) (rf_proof f)) ↾ _).
*)
+
+End QField.
+
From 6b91c40911b86eb6a527378df92d740a07e3266f Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 9 Oct 2012 14:52:56 +0200
Subject: [PATCH 023/110] Proving Riemann approximation
---
broken/AbstractIntegration.v | 157 +++++++++++++++++++++++++++--------
broken/metric.v | 12 +--
2 files changed, 125 insertions(+), 44 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index f9d71da2..400a6e56 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -13,7 +13,8 @@ Require Import
Require Import metric FromMetric2.
Require QnonNeg QnnInf CRball.
-Import QnonNeg.notations QnnInf.notations CRball.notations.
+Import Qinf.notations QnonNeg.notations QnnInf.notations CRball.notations Qabs.
+(*Import canonical_names.*)
(*Notation Qinf := Qinf.T.
@@ -48,6 +49,15 @@ Open Local Scope CR_scope.
(** Any nonnegative width can be split up into an integral number of
equal-sized pieces no bigger than a given bound: *)
+
+(*Lemma proj_exist {X : Type} (P : X -> Prop) (x : X) (Px : P x) : ` (exist _ x Px) = x.
+Proof. reflexivity. Qed.*)
+
+(*Lemma gball_abs (e a b : Q) : gball e a b ↔ (Qabs (a - b) <= e)%Q.
+Proof.
+unfold gball.
+SearchAbout Qdec_sign.*)
+
Definition split (w: QnonNeg) (bound: QposInf):
{ x: nat * QnonNeg | (fst x * snd x == w)%Qnn /\ (snd x <= bound)%QnnInf }.
Proof with simpl; auto with *.
@@ -328,48 +338,123 @@ Section integral_interface.
*)
(** Iterating this result shows that Riemann sums are arbitrarily good approximations: *)
- Import Qinf.notations.
- Lemma Riemann_sums_approximate_integral (a: Q) (w: Qpos) (e: Qpos) (iw: Q) (n: nat):
- (n * iw == w)%Q ->
- (iw <= lmu a w e)%Qinf ->
+
+ Lemma CRnonNegQpos : forall e : Qpos, CRnonNeg (' ` e).
+ Proof.
+ intros [e e_pos]; apply CRnonNeg_criterion; simpl.
+ intros q A; apply Qlt_le_weak, Qlt_le_trans with (y := e); trivial.
+ now apply CRle_Qle.
+ Qed.
+
+ Lemma luc_gball (a w delta eps x y : Q) : (delta <= lmu a w eps)%Qinf ->
+ gball w a x -> gball w a y -> gball delta x y -> gball eps (f x) (f y).
+ Proof.
+intros A1 A2 A3 A4.
+assert (B1 : mspc_ball w a x) by apply A2.
+assert (B2 : mspc_ball w a y) by apply A3.
+change (f x) with (restrict f a w (exist _ _ A2)).
+change (f y) with (restrict f a w (exist _ _ A3)).
+Admitted.
+(*Check _ : IsUniformlyContinuous (restrict f a w) _.
+apply (uc_prf (restrict f a w)).*)
+
+
+Lemma Qabs_le_nonneg (x y : Q) : 0 <= x -> (Qabs x <= y <-> x <= y).
+
+ Lemma Riemann_sums_approximate_integral (a: Q) (w: Qpos) (e: Qpos) (iw: QnonNeg) (n: nat):
+ (n * iw == w)%Qnn ->
+ (`iw <= lmu a w e)%Qinf ->
gball (e * w) (cmΣ n (fun i => ' iw * f (a + i * iw)%Q)) (∫ f a w).
Proof with auto.
intros A B.
- simpl.
rewrite <- A.
- rewrite <- integral_repeated_additive...
- setoid_replace ((e * w)%Qpos: Q) with ((n * (iw * e))%Qnn: Q).
- apply (CRΣ_gball_ex _ _ (iw * e)%Qnn).
- intros.
- simpl.
- apply (gball_integral e a (a+m*`iw) w iw)...
- apply ball_gball.
- apply in_Qball.
- split.
- apply Qle_trans with (a + 0)%Q.
- apply Qplus_le_compat...
- change (-w <= -0)%Q.
- apply Qopp_le_compat...
+ rewrite <- integral_repeated_additive.
+ setoid_replace ((e * w)%Qpos: Q) with ((n * (iw * e))%Qnn: Q) by
+ (simpl in *; unfold QnonNeg.eq in A; simpl in A;
+ unfold QposAsQ; rewrite Qmult_assoc; rewrite A; ring).
+ apply (CRΣ_gball_ex _ _ (iw * e)%Qnn).
+ intros. simpl.
+ rewrite CRmult_scale.
+ apply gball_sym. apply CRball.rational.
+ setoid_replace (' (` iw * ` e)%Q) with (scale iw (' (` e))) by now rewrite <- scale_Qmult.
+ apply integral_bounded; [apply CRnonNegQpos |].
+ intros x [A1 A2]. apply CRball.rational. apply (luc_gball a w (`iw)); trivial.
+apply ball_gball, Qball_Qabs.
+setoid_replace (a - (a + m * iw))%Q with (- (m * iw))%Q by ring.
+rewrite Qabs_opp. (*apply Qabs_Qle_condition. split.*)
+
+
+SearchAbout (Qabs _ <= _)%Q.
+SearchAbout AbsSmall.
+
+Qabs_Qle_condition: ∀ x y : Q, (Qabs x <= y)%Q ↔ - y <= x <= y
+Qabs_Qle: ∀ x y : Q, (Qabs x <= y)%Q ↔ - y <= x <= y
+AbsSmall_Qabs: ∀ x y : Q, (Qabs y <= x)%Q ↔ AbsSmall x y
+CRcorrect.AbsSmall_Qabs: ∀ x y : Q, (Qabs y <= x)%Q ↔ AbsSmall x y
+
+
+apply Qball_Qabs.
+SearchAbout "ball" "abs".
+
+Qball_Qabs: ∀ (e : Qpos) (a b : Q), Qball e a b ↔ (Qabs.Qabs (a - b) <= e)%Q
+
+
+
+assert (A3 : mspc_ball w a (a + m * iw)%Q). admit.
+assert (A4 : mspc_ball w a x). admit.
+change (f (a + m * iw)) with (restrict f a w (exist _ _ A3)).
+change (f x) with (restrict f a w (exist _ _ A4)).
+erewrite <- (proj_exist (ball w a) (a + m * iw)%Q).
+specialize (IsLocallyUniformlyContinuous0 a w).
+destruct IsLocallyUniformlyContinuous0 as [C1 C2].
+Import canonical_names.
+
+setoid_replace (f (a + m * iw)) with (restrict f a w (a + m * iw)%Q).
+assert (mspc_balla + m * iw
+
+
+unfold IsLocallyUniformlyContinuous in IsLocallyUniformlyContinuous0.
+SearchAbout CRnonNeg.
+
+CRball.rational:
+ ∀ (M : MetricSpace) (r : Q) (x y : M), gball r x y ↔ CRball (' r) x y
+
+
+rapply bounded_with_nonneg_radius.
+
+@gball CR (Qmult (QposAsQ width) (QnonNeg.to_Q r))
+ (@integrate f Integral0 from (QnonNeg.from_Qpos width))
+ (@ucFun CR CR (scale (QposAsQ width)) mid)
+
+
+
+SearchAbout gball "sym".
+
+
+
+
+
+ apply (gball_integral e a (a+m*`iw) w iw)...
+ apply ball_gball.
+ apply in_Qball.
+ split.
+ apply Qle_trans with (a + 0)%Q.
apply Qplus_le_compat...
- apply Qmult_le_0_compat...
- apply Qle_nat.
+ change (-w <= -0)%Q.
+ apply Qopp_le_compat...
apply Qplus_le_compat...
- change (n * iw == w)%Q in A.
- rewrite <- A.
- unfold QnonNeg.to_Q.
- apply Qmult_le_compat_r...
- apply Qlt_le_weak.
- rewrite <- Zlt_Qlt.
- apply inj_lt...
- simpl in *.
- unfold QnonNeg.eq in A.
- simpl in A.
- unfold QposAsQ.
- rewrite Qmult_assoc.
- rewrite A.
- ring.
+ apply Qmult_le_0_compat...
+ apply Qle_nat.
+ apply Qplus_le_compat...
+ change (n * iw == w)%Q in A.
+ rewrite <- A.
+ unfold QnonNeg.to_Q.
+ apply Qmult_le_compat_r...
+ apply Qlt_le_weak.
+ rewrite <- Zlt_Qlt.
+ apply inj_lt...*)
Qed.
-*)
+
End singular_props.
(** Unicity itself will of course have to be stated w.r.t. *two* integrals: *)
diff --git a/broken/metric.v b/broken/metric.v
index 9d8badcb..10cc179e 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -625,10 +625,8 @@ Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
Definition restrict (f : X -> Y) (x : X) (r : Q) : sig (ball r x) -> Y :=
f ∘ @proj1_sig _ _.
-Class IsLocallyUniformlyContinuous (f : X -> Y) (lmu : X -> Q -> Q -> Qinf) := {
- luc_pos : forall (x : X) (r e : Q), 0 < e -> (0 < lmu x r e);
- luc_prf : forall (x : X) (r : Q), IsUniformlyContinuous (restrict f x r) (lmu x r)
-}.
+Class IsLocallyUniformlyContinuous (f : X -> Y) (lmu : X -> Q -> Q -> Qinf) :=
+ luc_prf : forall (x : X) (r : Q), IsUniformlyContinuous (restrict f x r) (lmu x r).
(*Global Arguments luc_pos f mu {_} e _.
Global Arguments luc_prf f mu {_} e x1 x2 _ _.*)
@@ -636,10 +634,8 @@ Global Arguments luc_prf f mu {_} e x1 x2 _ _.*)
Global Instance uc_ulc (f : X -> Y) `{!IsUniformlyContinuous f mu} :
IsLocallyUniformlyContinuous f (λ _ _, mu).
Proof.
-constructor.
-+ intros _ _; now apply (uc_pos f).
-+ intros x r. constructor; [now apply (uc_pos f) |].
- intros e [x1 A1] [x2 A2] e_pos A. now apply (uc_prf f mu).
+intros x r. constructor; [now apply (uc_pos f) |].
+intros e [x1 A1] [x2 A2] e_pos A. now apply (uc_prf f mu).
Qed.
End LocalUniformContinuity.
From 99fd2fa0477830d616e68e9a7f97f76ac8ec4248 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 19 Oct 2012 19:34:49 +0200
Subject: [PATCH 024/110] Proved completeness of the metric space of uniformly
continuous functions. Started proving completeness of a closed ball.
---
broken/AbstractIntegration.v | 194 +++++++++++++++++++----------------
broken/FromMetric2.v | 110 ++++++++++++++++----
broken/metric.v | 158 +++++++++++++++++++++++-----
3 files changed, 326 insertions(+), 136 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 400a6e56..7c22c431 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -53,10 +53,44 @@ Open Local Scope CR_scope.
(*Lemma proj_exist {X : Type} (P : X -> Prop) (x : X) (Px : P x) : ` (exist _ x Px) = x.
Proof. reflexivity. Qed.*)
-(*Lemma gball_abs (e a b : Q) : gball e a b ↔ (Qabs (a - b) <= e)%Q.
+Section QFacts.
+
+Open Scope Q_scope.
+
+Lemma Qminus_less (x y : Q) : 0 <= y -> x - y <= x.
Proof.
-unfold gball.
-SearchAbout Qdec_sign.*)
+intro H. rewrite <- (Qplus_0_r x) at 2. apply Qplus_le_r. change 0 with (-0).
+now apply Qopp_le_compat.
+Qed.
+
+Lemma Qabs_zero (x : Q) : Qabs x == 0 <-> x == 0.
+Proof.
+split; intro H; [| now rewrite H].
+destruct (Qdec_sign x) as [[x_neg | x_pos] | x_zero]; [| | trivial].
++ rewrite Qabs_neg in H; [| apply Qlt_le_weak; trivial].
+ now rewrite <- (Qopp_involutive x), H.
++ rewrite Qabs_pos in H; [| apply Qlt_le_weak]; trivial.
+Qed.
+
+Lemma Qabs_nonpos (x : Q) : Qabs x <= 0 -> x == 0.
+Proof.
+intro H. apply Qle_lteq in H. destruct H as [H | H].
++ elim (Qlt_not_le _ _ H (Qabs_nonneg x)).
++ now apply Qabs_zero.
+Qed.
+
+Lemma gball_abs (e a b : Q) : gball e a b ↔ (Qabs (a - b) <= e).
+Proof.
+unfold gball. destruct (Qdec_sign e) as [[e_neg | e_pos] | e_zero].
++ split; intros H; [easy |]. assert (H1 := Qle_lt_trans _ _ _ H e_neg).
+ eapply Qle_not_lt; [apply Qabs_nonneg | apply H1].
++ apply Qball_Qabs.
++ split; intro H.
+ - rewrite e_zero, H; setoid_replace (b - b) with 0 by ring; apply Qle_refl.
+ - rewrite e_zero in H. apply Qabs_nonpos in H; now apply Qminus_eq.
+Qed.
+
+End QFacts.
Definition split (w: QnonNeg) (bound: QposInf):
{ x: nat * QnonNeg | (fst x * snd x == w)%Qnn /\ (snd x <= bound)%QnnInf }.
@@ -346,26 +380,36 @@ Section integral_interface.
now apply CRle_Qle.
Qed.
- Lemma luc_gball (a w delta eps x y : Q) : (delta <= lmu a w eps)%Qinf ->
+ Open Scope Q_scope.
+
+ Lemma luc_gball (a w delta eps x y : Q) :
+ 0 < eps ->
+ (delta <= lmu a w eps)%Qinf ->
gball w a x -> gball w a y -> gball delta x y -> gball eps (f x) (f y).
Proof.
-intros A1 A2 A3 A4.
-assert (B1 : mspc_ball w a x) by apply A2.
-assert (B2 : mspc_ball w a y) by apply A3.
-change (f x) with (restrict f a w (exist _ _ A2)).
-change (f y) with (restrict f a w (exist _ _ A3)).
-Admitted.
-(*Check _ : IsUniformlyContinuous (restrict f a w) _.
-apply (uc_prf (restrict f a w)).*)
+ intros A A1 A2 A3 A4.
+ destruct (luc_prf f lmu a w) as [_ H].
+ change (f x) with (restrict f a w (exist _ _ A2)).
+ change (f y) with (restrict f a w (exist _ _ A3)).
+ apply H; [apply A |].
+ destruct (lmu a w eps) as [q |] eqn:A5; [| easy].
+ apply (mspc_monotone delta); [apply A1 | apply A4].
+ Qed.
-Lemma Qabs_le_nonneg (x y : Q) : 0 <= x -> (Qabs x <= y <-> x <= y).
+ Lemma Qabs_le_nonneg (x y : Q) : 0 <= x -> (Qabs x <= y <-> x <= y).
+ Proof.
+ intro A. rewrite Qabs_Qle_condition.
+ split; [intros [_ ?]; trivial | intro A1; split; [| trivial]].
+ apply Qle_trans with (y := 0); [| trivial].
+ apply (Qopp_le_compat 0); eapply Qle_trans; eauto.
+ Qed.
Lemma Riemann_sums_approximate_integral (a: Q) (w: Qpos) (e: Qpos) (iw: QnonNeg) (n: nat):
(n * iw == w)%Qnn ->
(`iw <= lmu a w e)%Qinf ->
- gball (e * w) (cmΣ n (fun i => ' iw * f (a + i * iw)%Q)) (∫ f a w).
- Proof with auto.
+ gball (e * w) (cmΣ n (fun i => 'iw * f (a + i * iw))%CR) (∫ f a w).
+ Proof.
intros A B.
rewrite <- A.
rewrite <- integral_repeated_additive.
@@ -373,88 +417,56 @@ Lemma Qabs_le_nonneg (x y : Q) : 0 <= x -> (Qabs x <= y <-> x <= y).
(simpl in *; unfold QnonNeg.eq in A; simpl in A;
unfold QposAsQ; rewrite Qmult_assoc; rewrite A; ring).
apply (CRΣ_gball_ex _ _ (iw * e)%Qnn).
- intros. simpl.
+ intros m H; simpl.
rewrite CRmult_scale.
apply gball_sym. apply CRball.rational.
- setoid_replace (' (` iw * ` e)%Q) with (scale iw (' (` e))) by now rewrite <- scale_Qmult.
+ setoid_replace (' (` iw * ` e)) with (scale iw (' (` e))) by now rewrite <- scale_Qmult.
apply integral_bounded; [apply CRnonNegQpos |].
intros x [A1 A2]. apply CRball.rational. apply (luc_gball a w (`iw)); trivial.
-apply ball_gball, Qball_Qabs.
-setoid_replace (a - (a + m * iw))%Q with (- (m * iw))%Q by ring.
-rewrite Qabs_opp. (*apply Qabs_Qle_condition. split.*)
-
-
-SearchAbout (Qabs _ <= _)%Q.
-SearchAbout AbsSmall.
-
-Qabs_Qle_condition: ∀ x y : Q, (Qabs x <= y)%Q ↔ - y <= x <= y
-Qabs_Qle: ∀ x y : Q, (Qabs x <= y)%Q ↔ - y <= x <= y
-AbsSmall_Qabs: ∀ x y : Q, (Qabs y <= x)%Q ↔ AbsSmall x y
-CRcorrect.AbsSmall_Qabs: ∀ x y : Q, (Qabs y <= x)%Q ↔ AbsSmall x y
-
-
-apply Qball_Qabs.
-SearchAbout "ball" "abs".
-
-Qball_Qabs: ∀ (e : Qpos) (a b : Q), Qball e a b ↔ (Qabs.Qabs (a - b) <= e)%Q
-
-
-
-assert (A3 : mspc_ball w a (a + m * iw)%Q). admit.
-assert (A4 : mspc_ball w a x). admit.
-change (f (a + m * iw)) with (restrict f a w (exist _ _ A3)).
-change (f x) with (restrict f a w (exist _ _ A4)).
-erewrite <- (proj_exist (ball w a) (a + m * iw)%Q).
-specialize (IsLocallyUniformlyContinuous0 a w).
-destruct IsLocallyUniformlyContinuous0 as [C1 C2].
-Import canonical_names.
-
-setoid_replace (f (a + m * iw)) with (restrict f a w (a + m * iw)%Q).
-assert (mspc_balla + m * iw
-
-
-unfold IsLocallyUniformlyContinuous in IsLocallyUniformlyContinuous0.
-SearchAbout CRnonNeg.
-
-CRball.rational:
- ∀ (M : MetricSpace) (r : Q) (x y : M), gball r x y ↔ CRball (' r) x y
-
-
-rapply bounded_with_nonneg_radius.
-
-@gball CR (Qmult (QposAsQ width) (QnonNeg.to_Q r))
- (@integrate f Integral0 from (QnonNeg.from_Qpos width))
- (@ucFun CR CR (scale (QposAsQ width)) mid)
-
-
-
-SearchAbout gball "sym".
-
-
-
-
-
- apply (gball_integral e a (a+m*`iw) w iw)...
- apply ball_gball.
- apply in_Qball.
- split.
- apply Qle_trans with (a + 0)%Q.
- apply Qplus_le_compat...
- change (-w <= -0)%Q.
- apply Qopp_le_compat...
- apply Qplus_le_compat...
- apply Qmult_le_0_compat...
- apply Qle_nat.
- apply Qplus_le_compat...
- change (n * iw == w)%Q in A.
- rewrite <- A.
- unfold QnonNeg.to_Q.
- apply Qmult_le_compat_r...
- apply Qlt_le_weak.
- rewrite <- Zlt_Qlt.
- apply inj_lt...*)
+ + apply ball_gball, Qball_Qabs.
+ setoid_replace (a - (a + m * iw)) with (- (m * iw)) by ring.
+ rewrite Qabs_opp. apply Qabs_le_nonneg.
+ apply Qmult_le_0_compat; [apply Qle_nat | apply (proj2_sig iw)].
+ apply Qle_trans with (y := (n * iw)).
+ apply Qmult_le_compat_r. apply Qlt_le_weak. rewrite <- Zlt_Qlt. now apply inj_lt.
+ apply (proj2_sig iw).
+ change (n * iw == w) in A. rewrite <- A; reflexivity.
+ + apply gball_abs, Qabs_Qle_condition.
+ split.
+ apply Qplus_le_l with (z := x), Qplus_le_l with (z := w).
+ setoid_replace (- w + x + w) with x by ring. setoid_replace (a - x + x + w) with (a + w) by ring.
+ apply Qle_trans with (y := (a + m * ` iw + ` iw)); [easy |].
+ setoid_rewrite <- (Qmult_1_l (` iw)) at 2. change 1%Q with (inject_Z (Z.of_nat 1)).
+ rewrite <- Qplus_assoc, <- Qmult_plus_distr_l, <- Zplus_Qplus, <- Nat2Z.inj_add.
+ apply Qplus_le_r. change (n * iw == w) in A. rewrite <- A.
+ apply Qmult_le_compat_r. rewrite <- Zle_Qle. apply inj_le. rewrite Plus.plus_comm.
+ now apply lt_le_S.
+ apply (proj2_sig iw).
+ apply Qplus_le_l with (z := x), Qplus_le_l with (z := -w).
+ setoid_replace (a - x + x + - w) with (a - w) by ring.
+ setoid_replace (w + x + - w) with x by ring.
+ apply Qle_trans with (y := a). rewrite <- (Qplus_0_r a) at 2.
+ apply Qplus_le_r. change 0 with (-0). apply Qopp_le_compat, Qlt_le_weak, (proj2_sig w).
+ apply Qle_trans with (y := a + m * ` iw); [| easy].
+ rewrite <- (Qplus_0_r a) at 1. apply Qplus_le_r, Qmult_le_0_compat; [apply Qle_nat | apply (proj2_sig iw)].
+ + apply gball_abs, Qabs_Qle_condition; split.
+ apply (Qplus_le_r (x + `iw)).
+ setoid_replace (x + `iw + - `iw) with x by ring.
+ setoid_replace (x + `iw + (a + m * iw - x)) with (a + m * iw + `iw) by ring. apply A2.
+ apply (Qplus_le_r (x - `iw)).
+ setoid_replace (x - `iw + (a + m * iw - x)) with (a + m * iw - `iw) by ring.
+ setoid_replace (x - `iw + `iw) with x by ring.
+ apply Qle_trans with (y := a + m * iw); [| easy].
+ apply Qminus_less. apply (proj2_sig iw).
Qed.
+ Lemma Riemann_sums_approximate_integral' (a : Q) (w : Qpos) (e : Qpos) :
+ {iw: QnonNeg & {n: nat |
+ (n * iw == w)%Qnn ->
+ (`iw <= lmu a w e)%Qinf ->
+ gball (e * w) (cmΣ n (fun i => 'iw * f (a + i * iw))%CR) (∫ f a w).
+ Proof with auto.
+
End singular_props.
(** Unicity itself will of course have to be stated w.r.t. *two* integrals: *)
diff --git a/broken/FromMetric2.v b/broken/FromMetric2.v
index 606d9d2e..4b5514cc 100644
--- a/broken/FromMetric2.v
+++ b/broken/FromMetric2.v
@@ -1,4 +1,32 @@
Require Import metric2.Complete metric2.Metric metric.
+
+Lemma Qle_half (x : Q) : 0 <= x -> (1 # 2) * x <= x.
+Proof.
+intro H. rewrite <- (Qmult_1_l x) at 2. apply Qmult_le_compat_r; auto with qarith.
+Qed.
+
+Lemma Qmult_neg_pos (x y : Q) : x < 0 -> 0 < y -> x * y < 0.
+Proof.
+intros H1 H2.
+apply Q.Qopp_Qlt_0_l. setoid_replace (- (x * y)) with ((- x) * y) by ring.
+apply Q.Qmult_lt_0_compat; trivial. now apply Q.Qopp_Qlt_0_l.
+Qed.
+
+Lemma Qmult_pos_neg (x y : Q) : 0 < x -> y < 0 -> x * y < 0.
+Proof. intros H1 H2. rewrite Qmult_comm. now apply Qmult_neg_pos. Qed.
+
+Lemma Qmult_pos_r : forall x y : Q, 0 < x -> 0 < x * y -> 0 < y.
+Proof.
+intros x y H1 H2.
+destruct (Qsec.Qdec_sign y) as [[? | ?] | H]; trivial.
++ exfalso; apply (Qlt_irrefl 0), Qlt_trans with (y := x * y); trivial.
+ now apply Qmult_pos_neg.
++ rewrite H, Qmult_0_r in H2. exfalso; now apply (Qlt_irrefl 0).
+Qed.
+
+Lemma Qmult_pos_l : forall x y : Q, 0 < y -> 0 < x * y -> 0 < x.
+Proof. intros x y H1 H2. rewrite Qmult_comm in H2. now apply (Qmult_pos_r y x). Qed.
+
Require Import
abstract_algebra stdlib_rationals
orders.orders orders.semirings orders.rings theory.rings.
@@ -49,7 +77,7 @@ destruct (Qsec.Qdec_sign e) as [[e_neg | e_pos] | e_zero].
+ assert (e / 2 < 0) by now apply neg_pos_mult.
apply (gball_neg (e/2) x y); [easy |].
mc_setoid_replace (e / 2) with (e - e / 2) by (field; discriminate).
- now apply C, flip_neg_negate.
+ apply C; now apply flip_neg_negate.
+ apply (msp_closed (msp X)). intros [d d_pos]. now apply gball_pos, C.
+ apply ball_eq. intros [d d_pos]. apply gball_pos.
setoid_replace d with (e + d); [now apply C | rewrite e_zero; symmetry; apply plus_0_l].
@@ -78,19 +106,6 @@ Arguments conv_reg {X} _.
Set Printing Coercions.
-Definition ext_equiv' `{Equiv A} `{Equiv B} : Equiv (A → B) :=
- λ f g, ∀ x : A, f x = g x.
-
-Infix "=1" := ext_equiv' (at level 70, no associativity) : type_scope.
-
-Lemma ext_equiv_l `{Setoid A, Setoid B} (f g : A -> B) :
- Proper ((=) ==> (=)) f -> f =1 g -> f = g.
-Proof. intros P eq1_f_g x y eq_x_y; rewrite eq_x_y; apply eq1_f_g. Qed.
-
-Lemma ext_equiv_r `{Setoid A, Setoid B} (f g : A -> B) :
- Proper ((=) ==> (=)) g -> f =1 g -> f = g.
-Proof. intros P eq1_f_g x y eq_x_y; rewrite <- eq_x_y; apply eq1_f_g. Qed.
-
Section FromCompleteMetricSpace.
Variable X : MetricSpace.
@@ -100,14 +115,69 @@ Global Instance limit_complete : Limit (Complete X) :=
Global Instance : CompleteMetricSpaceClass (Complete X).
Proof.
-constructor.
-+ apply ext_equiv_r; [intros x y E; apply E |].
- intros f e1 e2 e1_pos e2_pos.
- eapply gball_pos, (CunitCjoin (conv_reg f) (e1 ↾ e1_pos) (e2 ↾ e2_pos)).
-+ constructor; [apply _ .. |].
- intros x y eq_x_y e1 e2 e1_pos e2_pos. apply mspc_eq; solve_propholds.
+constructor; [| apply _].
+apply ext_equiv_r; [intros x y E; apply E |].
+intros f e1 e2 e1_pos e2_pos.
+eapply gball_pos, (CunitCjoin (conv_reg f) (e1 ↾ e1_pos) (e2 ↾ e2_pos)).
+Qed.
+
+Lemma gball_complete (r : Q) (x y : Complete X) :
+ gball r x y <->
+ forall e1 e2 : Qpos, gball (QposAsQ e1 + r + QposAsQ e2)%mc (approximate x e1) (approximate y e2).
+Proof.
+destruct (Qsec.Qdec_sign r) as [[r_neg | r_pos] | r_zero].
++ split; intro H; [elim (gball_neg _ _ _ _ r_neg H) |].
+ assert (H1 : 0 < -(r / 3)) by (apply Q.Qopp_Qlt_0_l, Qmult_neg_pos; auto with qarith).
+ specialize (H (exist _ _ H1) (exist _ _ H1)); simpl in H.
+ mc_setoid_replace (- (r / 3) + r + - (r / 3)) with (r / 3) in H by (field; discriminate).
+ exfalso; eapply gball_neg; [| apply H]; now eapply Q.Qopp_Qlt_0_l.
++ rewrite <- (gball_pos _ r_pos). simpl; unfold regFunBall. split; intros H e1 e2.
+ - specialize (H e1 e2). apply gball_pos in H. apply H.
+ - apply gball_pos, H.
++ rewrite r_zero. unfold gball at 1; simpl; unfold regFunEq. split; intros H e1 e2; specialize (H e1 e2).
+ - apply gball_pos in H. now rewrite r_zero, Qplus_0_r.
+ - apply gball_pos. now rewrite r_zero, Qplus_0_r in H.
Qed.
End FromCompleteMetricSpace.
+Require Import CRmetric.
+
+Section CompleteSegment.
+
+Context (r : Q) (a : CR).
+
+Global (*Program*) Instance : Limit (sig (mspc_ball r a)).
+(*:= λ f, exist _ (lim (Build_RegularFunction (@proj1_sig _ _ ∘ f) _)) _.*)
+(*Next Obligation.
+apply f.
+Qed.
+Next Obligation.*)
+intros [f f_reg]. set (g := @proj1_sig CR _ ∘ f).
+assert (g_reg : IsRegularFunction g) by apply f_reg.
+exists (lim (Build_RegularFunction g g_reg)).
+unfold mspc_ball, msp_mspc_ball. apply gball_complete. intros e1 e2.
+unfold lim, limit_complete, Cjoin_fun, Cjoin_raw; simpl.
+assert (H : mspc_ball r a (g ((1 # 2) * QposAsQ e2)%Q)) by apply (proj2_sig (f ((1 # 2) * e2))).
+unfold mspc_ball, msp_mspc_ball in H.
+apply gball_weak_le with (q := QposAsQ e1 + r + (QposAsQ ((1 # 2) * e2)%Qpos)).
++ apply Qplus_le_r. apply Qle_half; auto.
++ apply gball_complete, H.
+Defined.
+
+(*Global Instance : CompleteMetricSpaceClass (sig (mspc_ball r a)).
+Proof.
+constructor; [| apply _].
+apply ext_equiv_r; [intros x y E; apply E |].
+intros [f f_reg] e1 e2 e1_pos e2_pos.
+set (g := @proj1_sig CR _ ∘ f).
+assert (g_reg : IsRegularFunction g) by apply f_reg.
+assert (H : CompleteMetricSpaceClass CR) by apply _.
+destruct H as [H _]. specialize (H (Build_RegularFunction g g_reg) (Build_RegularFunction g g_reg)).
+simpl in *.
+eapply H.
+*)
+
+End CompleteSegment.
+
End QField.
diff --git a/broken/metric.v b/broken/metric.v
index 10cc179e..9b0f2ce5 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -106,6 +106,19 @@ Instance pos_ne_0 : forall `{StrictSetoidOrder A} `{Zero A} (x : A),
PropHolds (0 < x) -> PropHolds (x ≠ 0).
Proof. intros; now apply lt_ne_flip. Qed.
+Definition ext_equiv' `{Equiv A} `{Equiv B} : Equiv (A → B) :=
+ λ f g, ∀ x : A, f x = g x.
+
+Infix "=1" := ext_equiv' (at level 70, no associativity) : type_scope.
+
+Lemma ext_equiv_l `{Setoid A, Setoid B} (f g : A -> B) :
+ Proper ((=) ==> (=)) f -> f =1 g -> f = g.
+Proof. intros P eq1_f_g x y eq_x_y; rewrite eq_x_y; apply eq1_f_g. Qed.
+
+Lemma ext_equiv_r `{Setoid A, Setoid B} (f g : A -> B) :
+ Proper ((=) ==> (=)) g -> f =1 g -> f = g.
+Proof. intros P eq1_f_g x y eq_x_y; rewrite <- eq_x_y; apply eq1_f_g. Qed.
+
(*Ltac MCQconst t :=
match t with
(*| @zero Q _ _ => constr:(Qmake Z0 xH)
@@ -309,6 +322,18 @@ Class IsUniformlyContinuous (f : X -> Y) (mu : Q -> Qinf) := {
Global Arguments uc_pos f mu {_} e _.
Global Arguments uc_prf f mu {_} e x1 x2 _ _.
+Record UniformlyContinuous := {
+ uc_func :> X -> Y;
+ uc_mu : Q -> Qinf;
+ uc_proof : IsUniformlyContinuous uc_func uc_mu
+}.
+
+(* We will prove next that IsUniformlyContinuous is a subclass of Proper,
+i.e., uniformly continuous functions are morphisms. But if we have [f :
+UniformlyContinuous], in order for uc_func f to be considered a morphism,
+we need to declare uc_proof an instance. *)
+Global Existing Instance uc_proof.
+
Global Instance uc_proper `{IsUniformlyContinuous f mu} : Proper ((=) ==> (=)) f.
Proof.
intros x1 x2 A. apply -> mspc_eq. intros e e_pos. apply (uc_prf f mu); trivial.
@@ -318,6 +343,8 @@ Qed.
End UniformContinuity.
+Global Arguments UniformlyContinuous X {_} Y {_}.
+
Section Contractions.
Context `{MetricSpaceClass X, ExtMetricSpaceClass Y}.
@@ -332,6 +359,12 @@ Global Arguments contr_nonneg_mu f q {_} _.
Global Arguments contr_lt_mu_1 f q {_}.
Global Arguments contr_prf f q {_} _ _ _ _.
+Record Contraction := {
+ contr_func : X -> Y;
+ contr_q : Q;
+ contr_proof : IsContraction contr_func contr_q
+}.
+
Definition contr_modulus (q e : Q) : Qinf :=
if (decide (0 = q)) then Qinf.infinite else (e / q).
@@ -351,44 +384,52 @@ Qed.
End Contractions.
-(*Section UCFMetricSpace.
+Global Arguments Contraction X {_} Y {_}.
+
+Section UCFMetricSpace.
-Context `{MetricSpaceClass X, MetricSpaceClass Y}.
+Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
-Instance UCFEquiv : Equiv (IsUniformlyContinuous X Y) := @equiv (X -> Y) _.
+Instance UCFEquiv : Equiv (UniformlyContinuous X Y) := @equiv (X -> Y) _.
-Lemma UCFSetoid : Setoid (IsUniformlyContinuous X Y).
+Lemma UCFSetoid : Setoid (UniformlyContinuous X Y).
Proof.
constructor.
-intros f x y A; now rewrite A.
+intros f x y A. now rewrite A.
intros f g A1 x y A2; rewrite A2; symmetry; now apply A1.
intros f g h A1 A2 x y A3; rewrite A3; now transitivity (g y); [apply A1 | apply A2].
Qed.
-Instance UCFSpaceBall : MetricSpaceBall (IsUniformlyContinuous X Y) :=
- fun q f g => forall x, ball q (f x) (g x).
+Global Instance UCFSpaceBall : MetricSpaceBall (UniformlyContinuous X Y) :=
+ λ e f g, forall x, ball e (f x) (g x).
+(* match e with
+ | Qinf.infinite => True
+ | Qinf.finite e' =>
+ if (decide_rel (<) e' 0)
+ then False
+ else (forall x, ball e' (f x) (g x))
+ end.*)
-Lemma UCFBallProper : Proper equiv ball.
+Lemma UCFBallProper : Proper ((=) ==> (≡) ==> (≡) ==> iff) ball.
Proof.
-intros q1 q2 A1 f1 f2 A2 g1 g2 A3; split; intros A4 x.
-+ rewrite <- A1. rewrite <- (A2 x x); [| reflexivity]. rewrite <- (A3 x x); [| reflexivity]. apply A4.
-+ rewrite A1. rewrite (A2 x x); [| reflexivity]. rewrite (A3 x x); [| reflexivity]. apply A4.
+intros q1 q2 A1 f1 f2 A2 g1 g2 A3; rewrite A2, A3.
+split; intros A4 x; [rewrite <- A1 | rewrite A1]; apply A4.
Qed.
-Global Instance : MetricSpaceClass (IsUniformlyContinuous X Y).
+Global Instance : `{NonEmpty X} -> ExtMetricSpaceClass (UniformlyContinuous X Y).
Proof.
-constructor.
-apply UCFSetoid.
-apply UCFBallProper.
-intros q f x; apply mspc_refl.
-intros q f g A x; apply mspc_symm; trivial.
-intros q1 q2 f g h A1 A2 x; apply mspc_triangle with (b := g x); trivial.
-intros q f g A x; apply mspc_closed; intro d; apply A.
-intros f g A1 x y A2. rewrite A2. eapply mspc_eq; trivial. intro q; apply A1.
+intros [x0]; constructor.
++ apply UCFBallProper.
++ intros f g x; apply mspc_inf.
++ intros e e_neg f g A. specialize (A x0). eapply mspc_negative; eauto.
++ intros e e_nonneg f x; now apply mspc_refl.
++ intros e f g A x; now apply mspc_symm.
++ intros e1 e2 f g h A1 A2 x; now apply mspc_triangle with (b := g x).
++ intros e f g A x. apply mspc_closed; intros d A1. now apply A.
Qed.
End UCFMetricSpace.
-*)
+
(*
Section Isometry.
@@ -428,7 +469,7 @@ Arguments Build_RegularFunction {_} _.
Global Existing Instance rf_proof.
-Instance rf_eq : Equiv RegularFunction :=
+Global Instance rf_eq : Equiv RegularFunction :=
λ f1 f2, forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> ball (e1 + e2) (f1 e1) (f2 e2).
Global Instance rf_setoid : Setoid RegularFunction.
@@ -451,10 +492,19 @@ Proof. intros e1 e2 A1 A2; apply mspc_refl; solve_propholds. Qed.
Definition reg_unit (x : X) := Build_RegularFunction (unit_reg x).
+Global Instance : Setoid_Morphism reg_unit.
+Proof.
+constructor; [apply _ .. |].
+intros x y eq_x_y e1 e2 e1_pos e2_pos. apply mspc_eq; solve_propholds.
+Qed.
+
Class Limit := lim : RegularFunction -> X.
Class CompleteMetricSpaceClass `{Limit} := cmspc :> Surjective reg_unit (inv := lim).
+Definition tends_to (f : RegularFunction) (l : X) :=
+ forall e : Q, 0 < e -> ball e (f e) l.
+
Lemma limit_def `{CompleteMetricSpaceClass} (f : RegularFunction) :
forall e : Q, 0 < e -> ball e (f e) (lim f).
Proof.
@@ -470,6 +520,65 @@ Global Arguments RegularFunction X {_}.
Global Arguments Limit X {_}.
Global Arguments CompleteMetricSpaceClass X {_ _ _}.
+(* The exclamation mark before Limit avoids introducing a second assumption
+MetricSpaceBall X *)
+Lemma completeness_criterion `{ExtMetricSpaceClass X, !Limit X} :
+ CompleteMetricSpaceClass X <-> forall f : RegularFunction X, tends_to f (lim f).
+Proof.
+split; intro A.
++ intros f e2 A2. apply mspc_symm, mspc_closed.
+ intros e1 A1. change (lim f) with (reg_unit (lim f) e1). rewrite plus_comm.
+ rapply (surjective reg_unit (A := X) (inv := lim)); trivial; reflexivity.
++ constructor; [| apply _].
+ apply ext_equiv_r; [apply _|].
+ intros f e1 e2 e1_pos e2_pos.
+ apply (mspc_monotone e2); [apply nonneg_plus_le_compat_l; solve_propholds |].
+ now apply mspc_symm, A.
+Qed.
+
+Section UCFComplete.
+
+Context `{NonEmpty X, ExtMetricSpaceClass X, CompleteMetricSpaceClass Y}.
+
+Program Definition pointwise_regular
+ (F : RegularFunction (UniformlyContinuous X Y)) (x : X) : RegularFunction Y :=
+ Build_RegularFunction (λ e, F e x) _.
+Next Obligation.
+intros e1 e2 e1_pos e2_pos; now apply F.
+Qed.
+
+Global Program Instance ucf_limit : Limit (UniformlyContinuous X Y) :=
+ λ F, Build_UniformlyContinuous
+ (λ x, lim (pointwise_regular F x))
+ (λ e, uc_mu (F (e/3)) (e/3))
+ _.
+Next Obligation.
+constructor.
+* intros e e_pos.
+ destruct (F (e/3)) as [g ? ?]; simpl; apply uc_pos with (f := g); trivial.
+ apply Q.Qmult_lt_0_compat; auto with qarith.
+* intros e x1 x2 e_pos A.
+ apply (mspc_triangle' (e/3) (e/3 + e/3) (F (e/3) x1)); [field; discriminate | |].
+ + apply mspc_symm. change ((F (e / 3)) x1) with (pointwise_regular F x1 (e/3)).
+ (* without [change], neither [apply limit_def] nor [rapply limit_def] work *)
+ apply completeness_criterion, Q.Qmult_lt_0_compat; auto with qarith.
+ + apply mspc_triangle with (b := F (e / 3) x2).
+ - destruct (F (e/3)); eapply uc_prf; eauto.
+ apply Q.Qmult_lt_0_compat; auto with qarith.
+ - change ((F (e / 3)) x2) with (pointwise_regular F x2 (e/3)).
+ apply completeness_criterion, Q.Qmult_lt_0_compat; auto with qarith.
+Qed.
+
+Global Instance : CompleteMetricSpaceClass (UniformlyContinuous X Y).
+Proof.
+apply completeness_criterion. intros F e e_pos x.
+change (lim F x) with (lim (pointwise_regular F x)).
+change (F e x) with (pointwise_regular F x e).
+now apply completeness_criterion.
+Qed.
+
+End UCFComplete.
+
Definition seq A := nat -> A.
(*Hint Unfold seq : typeclass_instances.*)
@@ -593,7 +702,7 @@ intros e A1 n A2. apply (mspc_triangle' (e / 2) (e / 2) (x (N (e / 2)))).
+ field; change ((2 : Q) ≠ 0); solve_propholds.
+ now apply mspc_symm, A; [solve_propholds | reflexivity |].
+ change (x (N (e / 2))) with (f (e / 2)).
- apply limit_def; solve_propholds.
+ apply completeness_criterion; solve_propholds.
Qed.
End CompleteSpaceSequenceLimits.
@@ -628,8 +737,7 @@ Definition restrict (f : X -> Y) (x : X) (r : Q) : sig (ball r x) -> Y :=
Class IsLocallyUniformlyContinuous (f : X -> Y) (lmu : X -> Q -> Q -> Qinf) :=
luc_prf : forall (x : X) (r : Q), IsUniformlyContinuous (restrict f x r) (lmu x r).
-(*Global Arguments luc_pos f mu {_} e _.
-Global Arguments luc_prf f mu {_} e x1 x2 _ _.*)
+Global Arguments luc_prf f lmu {_} x r.
Global Instance uc_ulc (f : X -> Y) `{!IsUniformlyContinuous f mu} :
IsLocallyUniformlyContinuous f (λ _ _, mu).
From e9ecadc6875834de7e27c1d5fa484897d3c8f9a5 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 23 Oct 2012 15:39:16 +0200
Subject: [PATCH 025/110] Proving corollaries of Riemann approximation
---
broken/AbstractIntegration.v | 107 ++++++++++++++++++++++++++++++-----
1 file changed, 93 insertions(+), 14 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 7c22c431..d4daeb81 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -12,7 +12,7 @@ Require Import
(*metric2.Classified*)
Require Import metric FromMetric2.
-Require QnonNeg QnnInf CRball.
+Require Qinf QnonNeg QnnInf CRball.
Import Qinf.notations QnonNeg.notations QnnInf.notations CRball.notations Qabs.
(*Import canonical_names.*)
@@ -46,13 +46,6 @@ Open Local Scope Q_scope.
Open Local Scope uc_scope.
Open Local Scope CR_scope.
-(** Any nonnegative width can be split up into an integral number of
- equal-sized pieces no bigger than a given bound: *)
-
-
-(*Lemma proj_exist {X : Type} (P : X -> Prop) (x : X) (Px : P x) : ` (exist _ x Px) = x.
-Proof. reflexivity. Qed.*)
-
Section QFacts.
Open Scope Q_scope.
@@ -63,6 +56,35 @@ intro H. rewrite <- (Qplus_0_r x) at 2. apply Qplus_le_r. change 0 with (-0).
now apply Qopp_le_compat.
Qed.
+(* The following two lemmas are obtained from the lemmas with the same name
+in Coq.QArith.QArith_base by replacing -> with <-> *)
+
+Lemma Qle_shift_div_l : forall a b c, 0 < c -> (a * c <= b <-> a <= b / c).
+Proof.
+intros a b c A; split; [now apply Qle_shift_div_l |].
+intro A1. apply (Qmult_le_r _ _ (/c)); [now apply Qinv_lt_0_compat |].
+rewrite <- Qmult_assoc, Qmult_inv_r; [now rewrite Qmult_1_r | auto with qarith].
+Qed.
+
+Lemma Qle_shift_div_r : forall a b c, 0 < b -> (a <= c * b <-> a / b <= c).
+Proof.
+intros a b c A; split; [now apply Qle_shift_div_r |].
+intro A1. apply (Qmult_le_r _ _ (/b)); [now apply Qinv_lt_0_compat |].
+rewrite <- Qmult_assoc, Qmult_inv_r; [now rewrite Qmult_1_r | auto with qarith].
+Qed.
+
+Lemma Qle_div_l : forall a b c, 0 < b -> 0 < c -> (a / b <= c <-> a / c <= b).
+Proof.
+intros a b c A1 A2.
+rewrite <- Qle_shift_div_r; [| easy]. rewrite (Qmult_comm c b). rewrite Qle_shift_div_r; easy.
+Qed.
+
+Lemma Qle_div_r : forall a b c, 0 < b -> 0 < c -> (b <= a / c <-> c <= a / b).
+Proof.
+intros a b c A1 A2.
+rewrite <- Qle_shift_div_l; [| easy]. rewrite (Qmult_comm b c). rewrite Qle_shift_div_l; easy.
+Qed.
+
Lemma Qabs_zero (x : Q) : Qabs x == 0 <-> x == 0.
Proof.
split; intro H; [| now rewrite H].
@@ -92,6 +114,9 @@ Qed.
End QFacts.
+(** Any nonnegative width can be split up into an integral number of
+ equal-sized pieces no bigger than a given bound: *)
+
Definition split (w: QnonNeg) (bound: QposInf):
{ x: nat * QnonNeg | (fst x * snd x == w)%Qnn /\ (snd x <= bound)%QnnInf }.
Proof with simpl; auto with *.
@@ -119,6 +144,12 @@ define very simple summation and a key property thereof: *)
Definition cmΣ {M: CMonoid} (n: nat) (f: nat -> M): M := cm_Sum (map f (enum n)).
+(*Lemma cmΣ_sum {M: CMonoid} (n : nat) (f g : nat -> M) : cmΣ n
+
+M := cm_Sum (map f (enum n)).
+
+SearchAbout cm_Sum.*)
+
(** If the elementwise distance between two summations over the same domain
is bounded, then so is the distance between the summations: *)
@@ -405,6 +436,13 @@ Section integral_interface.
apply (Qopp_le_compat 0); eapply Qle_trans; eauto.
Qed.
+ Program Definition step (w : Qpos) (n : positive) : QnonNeg := exist _ (w * (1 # n)) _.
+ Next Obligation. Qauto_nonneg. Qed.
+
+ Definition Riemann_sum (a : Q) (w : Qpos) (n : positive) :=
+ let iw := step w n in
+ cmΣ (Pos.to_nat n) (fun i => 'iw * f (a + i * iw))%CR.
+
Lemma Riemann_sums_approximate_integral (a: Q) (w: Qpos) (e: Qpos) (iw: QnonNeg) (n: nat):
(n * iw == w)%Qnn ->
(`iw <= lmu a w e)%Qinf ->
@@ -460,12 +498,53 @@ Section integral_interface.
apply Qminus_less. apply (proj2_sig iw).
Qed.
- Lemma Riemann_sums_approximate_integral' (a : Q) (w : Qpos) (e : Qpos) :
- {iw: QnonNeg & {n: nat |
- (n * iw == w)%Qnn ->
- (`iw <= lmu a w e)%Qinf ->
- gball (e * w) (cmΣ n (fun i => 'iw * f (a + i * iw))%CR) (∫ f a w).
- Proof with auto.
+ Lemma Riemann_sums_approximate_integral' (a : Q) (w : Qpos) (e : Qpos) (n : positive) :
+ (step w n <= lmu a w e)%Qinf ->
+ gball (e * w) (Riemann_sum a w n) (∫ f a w).
+ Proof.
+ intro A; unfold Riemann_sum. apply Riemann_sums_approximate_integral; [| easy].
+ unfold step. change (Pos.to_nat n * (w * (1 # n)) == w).
+ rewrite positive_nat_Z. unfold inject_Z. rewrite !Qmake_Qdiv; field; auto.
+ Qed.
+
+ Lemma le_Z_to_pos (z : Z) (p : positive) : (Z.to_pos z <= p)%positive <-> (z <= p)%Z.
+ Proof.
+ destruct z as [| q | q]; simpl.
+ + split; intros _; [apply Zle_0_pos | apply Pos.le_1_l].
+ + apply Ple_Zle.
+ + split; intros _; [apply Zle_neg_pos | apply Pos.le_1_l].
+ Qed.
+
+ Lemma Riemann_sums_approximate_integral'' (a : Q) (w : Qpos) (e : Qpos) :
+ exists N : positive, forall n : positive, (N <= n)%positive ->
+ gball e (Riemann_sum a w n) (∫ f a w).
+ Proof.
+ set (N := Z.to_pos (Qceiling (comp_inf (λ x, w / x) (lmu a w) 0 (e / w)))).
+ exists N; intros n A. setoid_replace (QposAsQ e) with ((e / w)%Qpos * w)
+ by (change (e == e / w * w); field; auto).
+ apply Riemann_sums_approximate_integral'.
+ unfold step, comp_inf in *. change ((w * (1 # n))%Q <= lmu a w (e / w))%Qinf.
+ assert (0 <= lmu a w (e / w))%Qinf.
+ unfold IsLocallyUniformlyContinuous in *.
+
+(*assert (IsUniformlyContinuous (restrict f a w) (lmu a w)).
+specialize (IsLocallyUniformlyContinuous0 a w).
+apply _.
+apply IsLocallyUniformlyContinuous0.
+
+
+
+ rapply (uc_pos (restrict f a w) (lmu a w)).
+ destruct (lmu a w (e / w)) as [mu |] eqn:A1; [| easy].
+ (*assert (0 < mu). rewrite <- A1.*)
+ rewrite Qmake_Qdiv, injZ_One. unfold Qdiv. rewrite Qmult_assoc, Qmult_1_r.
+ change (w / n <= mu). apply Qle_div_l.
+ apply Qle_shift_div_r; [easy |].
+ subst N. apply le_Z_to_pos, Qle_Qceiling_Z in A.*)
+ Admitted.
+
+
+
End singular_props.
From 82e55821ea755edf41661d84109c9ee978fba32b Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 26 Oct 2012 18:27:47 +0200
Subject: [PATCH 026/110] Proved that a closed ball in a complete metric space
is a complete metric subspace (FromMetric2.v)
---
broken/AbstractIntegration.v | 190 ++++++++++++++++++++++++-----------
broken/FromMetric2.v | 58 +++++------
2 files changed, 162 insertions(+), 86 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index d4daeb81..3e7d21ca 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -367,7 +367,7 @@ Section integral_interface.
of unicity only works for such functions. Todo: There should really be a proof that does not depend
on continuity. *)
- Context (*`{!LocallyUniformlyContinuous_mu f}*) `{!IsLocallyUniformlyContinuous f lmu}.
+ Context `{L : !IsLocallyUniformlyContinuous f lmu}.
(*
Lemma gball_integral (e: Qpos) (a a': Q) (ww: Qpos) (w: QnonNeg):
@@ -436,73 +436,78 @@ Section integral_interface.
apply (Qopp_le_compat 0); eapply Qle_trans; eauto.
Qed.
- Program Definition step (w : Qpos) (n : positive) : QnonNeg := exist _ (w * (1 # n)) _.
- Next Obligation. Qauto_nonneg. Qed.
-
- Definition Riemann_sum (a : Q) (w : Qpos) (n : positive) :=
- let iw := step w n in
- cmΣ (Pos.to_nat n) (fun i => 'iw * f (a + i * iw))%CR.
-
- Lemma Riemann_sums_approximate_integral (a: Q) (w: Qpos) (e: Qpos) (iw: QnonNeg) (n: nat):
- (n * iw == w)%Qnn ->
- (`iw <= lmu a w e)%Qinf ->
+ Lemma Riemann_sums_approximate_integral (a: Q) (w: Qpos) (e: Qpos) (iw: Q) (n: nat):
+ (n * iw == w)%Q ->
+ (iw <= lmu a w e)%Qinf ->
gball (e * w) (cmΣ n (fun i => 'iw * f (a + i * iw))%CR) (∫ f a w).
Proof.
intros A B.
+ assert (iw_nn : 0 <= iw) by (apply Qlt_le_weak, (Qmult_pos_r n); [| rewrite A]; Qauto_nonneg).
+ set (iw' := exist _ iw iw_nn : QnonNeg ).
+ change iw with (QnonNeg.to_Q iw').
+ change (n * iw' == w)%Qnn in A.
rewrite <- A.
rewrite <- integral_repeated_additive.
- setoid_replace ((e * w)%Qpos: Q) with ((n * (iw * e))%Qnn: Q) by
+ setoid_replace ((e * w)%Qpos: Q) with ((n * (iw' * e))%Qnn: Q) by
(simpl in *; unfold QnonNeg.eq in A; simpl in A;
unfold QposAsQ; rewrite Qmult_assoc; rewrite A; ring).
- apply (CRΣ_gball_ex _ _ (iw * e)%Qnn).
- intros m H; simpl.
+ apply (CRΣ_gball_ex _ _ (iw' * e)%Qnn).
+ intros m H.
rewrite CRmult_scale.
apply gball_sym. apply CRball.rational.
- setoid_replace (' (` iw * ` e)) with (scale iw (' (` e))) by now rewrite <- scale_Qmult.
+ setoid_replace (' (` iw' * ` e)) with (scale iw' (' (` e))) by now rewrite <- scale_Qmult.
apply integral_bounded; [apply CRnonNegQpos |].
- intros x [A1 A2]. apply CRball.rational. apply (luc_gball a w (`iw)); trivial.
+ intros x [A1 A2]. apply CRball.rational. apply (luc_gball a w (`iw')); trivial.
+ apply ball_gball, Qball_Qabs.
- setoid_replace (a - (a + m * iw)) with (- (m * iw)) by ring.
- rewrite Qabs_opp. apply Qabs_le_nonneg.
- apply Qmult_le_0_compat; [apply Qle_nat | apply (proj2_sig iw)].
- apply Qle_trans with (y := (n * iw)).
+ setoid_replace (a - (a + m * iw')) with (- (m * iw')) by ring.
+ rewrite Qabs_opp. apply Qabs_le_nonneg; [Qauto_nonneg |].
+ apply Qle_trans with (y := (n * iw')).
apply Qmult_le_compat_r. apply Qlt_le_weak. rewrite <- Zlt_Qlt. now apply inj_lt.
- apply (proj2_sig iw).
- change (n * iw == w) in A. rewrite <- A; reflexivity.
+ apply (proj2_sig iw').
+ change (n * iw' == w) in A. rewrite <- A; reflexivity.
+ apply gball_abs, Qabs_Qle_condition.
split.
apply Qplus_le_l with (z := x), Qplus_le_l with (z := w).
setoid_replace (- w + x + w) with x by ring. setoid_replace (a - x + x + w) with (a + w) by ring.
- apply Qle_trans with (y := (a + m * ` iw + ` iw)); [easy |].
- setoid_rewrite <- (Qmult_1_l (` iw)) at 2. change 1%Q with (inject_Z (Z.of_nat 1)).
+ apply Qle_trans with (y := (a + m * ` iw' + ` iw')); [easy |].
+ setoid_rewrite <- (Qmult_1_l (` iw')) at 2. change 1%Q with (inject_Z (Z.of_nat 1)).
rewrite <- Qplus_assoc, <- Qmult_plus_distr_l, <- Zplus_Qplus, <- Nat2Z.inj_add.
- apply Qplus_le_r. change (n * iw == w) in A. rewrite <- A.
+ apply Qplus_le_r. change (n * iw' == w) in A. rewrite <- A.
apply Qmult_le_compat_r. rewrite <- Zle_Qle. apply inj_le. rewrite Plus.plus_comm.
now apply lt_le_S.
- apply (proj2_sig iw).
+ apply (proj2_sig iw').
apply Qplus_le_l with (z := x), Qplus_le_l with (z := -w).
setoid_replace (a - x + x + - w) with (a - w) by ring.
setoid_replace (w + x + - w) with x by ring.
apply Qle_trans with (y := a). rewrite <- (Qplus_0_r a) at 2.
apply Qplus_le_r. change 0 with (-0). apply Qopp_le_compat, Qlt_le_weak, (proj2_sig w).
- apply Qle_trans with (y := a + m * ` iw); [| easy].
- rewrite <- (Qplus_0_r a) at 1. apply Qplus_le_r, Qmult_le_0_compat; [apply Qle_nat | apply (proj2_sig iw)].
+ apply Qle_trans with (y := a + m * ` iw'); [| easy].
+ rewrite <- (Qplus_0_r a) at 1. apply Qplus_le_r, Qmult_le_0_compat; [apply Qle_nat | apply (proj2_sig iw')].
+ apply gball_abs, Qabs_Qle_condition; split.
- apply (Qplus_le_r (x + `iw)).
- setoid_replace (x + `iw + - `iw) with x by ring.
- setoid_replace (x + `iw + (a + m * iw - x)) with (a + m * iw + `iw) by ring. apply A2.
- apply (Qplus_le_r (x - `iw)).
- setoid_replace (x - `iw + (a + m * iw - x)) with (a + m * iw - `iw) by ring.
- setoid_replace (x - `iw + `iw) with x by ring.
- apply Qle_trans with (y := a + m * iw); [| easy].
- apply Qminus_less. apply (proj2_sig iw).
+ apply (Qplus_le_r (x + `iw')).
+ setoid_replace (x + `iw' + - `iw') with x by ring.
+ setoid_replace (x + `iw' + (a + m * iw' - x)) with (a + m * iw' + `iw') by ring. apply A2.
+ apply (Qplus_le_r (x - `iw')).
+ setoid_replace (x - `iw' + (a + m * iw' - x)) with (a + m * iw' - `iw') by ring.
+ setoid_replace (x - `iw' + `iw') with x by ring.
+ apply Qle_trans with (y := a + m * iw'); [| easy].
+ apply Qminus_less. apply (proj2_sig iw').
Qed.
+(* Program Definition step (w : Qpos) (n : positive) : QnonNeg := exist _ (w * (1 # n)) _.
+ Next Obligation. Qauto_nonneg. Qed.*)
+
+ Definition step (w : Qpos) (n : positive) : Q := w * (1 # n).
+
+ Definition riemann_sum (a : Q) (w : Qpos) (n : positive) :=
+ let iw := step w n in
+ cmΣ (Pos.to_nat n) (fun i => 'iw * f (a + i * iw))%CR.
+
Lemma Riemann_sums_approximate_integral' (a : Q) (w : Qpos) (e : Qpos) (n : positive) :
(step w n <= lmu a w e)%Qinf ->
- gball (e * w) (Riemann_sum a w n) (∫ f a w).
+ gball (e * w) (riemann_sum a w n) (∫ f a w).
Proof.
- intro A; unfold Riemann_sum. apply Riemann_sums_approximate_integral; [| easy].
+ intro A; unfold riemann_sum. apply Riemann_sums_approximate_integral; [| easy].
unfold step. change (Pos.to_nat n * (w * (1 # n)) == w).
rewrite positive_nat_Z. unfold inject_Z. rewrite !Qmake_Qdiv; field; auto.
Qed.
@@ -517,34 +522,21 @@ Section integral_interface.
Lemma Riemann_sums_approximate_integral'' (a : Q) (w : Qpos) (e : Qpos) :
exists N : positive, forall n : positive, (N <= n)%positive ->
- gball e (Riemann_sum a w n) (∫ f a w).
+ gball e (riemann_sum a w n) (∫ f a w).
Proof.
set (N := Z.to_pos (Qceiling (comp_inf (λ x, w / x) (lmu a w) 0 (e / w)))).
exists N; intros n A. setoid_replace (QposAsQ e) with ((e / w)%Qpos * w)
by (change (e == e / w * w); field; auto).
apply Riemann_sums_approximate_integral'.
unfold step, comp_inf in *. change ((w * (1 # n))%Q <= lmu a w (e / w))%Qinf.
- assert (0 <= lmu a w (e / w))%Qinf.
- unfold IsLocallyUniformlyContinuous in *.
-
-(*assert (IsUniformlyContinuous (restrict f a w) (lmu a w)).
-specialize (IsLocallyUniformlyContinuous0 a w).
-apply _.
-apply IsLocallyUniformlyContinuous0.
-
-
-
- rapply (uc_pos (restrict f a w) (lmu a w)).
+ assert (A2 : 0 < e / w) by (apply Qmult_lt_0_compat; [| apply Qinv_lt_0_compat]; auto).
destruct (lmu a w (e / w)) as [mu |] eqn:A1; [| easy].
- (*assert (0 < mu). rewrite <- A1.*)
+ assert (A3 := @uc_pos _ _ _ _ _ _ (L a w) (e / w) A2). rewrite A1 in A3.
+ change (0 < mu) in A3.
rewrite Qmake_Qdiv, injZ_One. unfold Qdiv. rewrite Qmult_assoc, Qmult_1_r.
- change (w / n <= mu). apply Qle_div_l.
- apply Qle_shift_div_r; [easy |].
- subst N. apply le_Z_to_pos, Qle_Qceiling_Z in A.*)
- Admitted.
-
-
-
+ change (w / n <= mu). apply Qle_div_l; auto.
+ subst N. now apply le_Z_to_pos, Qle_Qceiling_Z in A.
+ Qed.
End singular_props.
@@ -597,6 +589,88 @@ Proof with auto.
apply (integral_wd f)...
Qed.
+Require Import ARtrans. (* This is almost all CoRN *)
+Import canonical_names.
+
+Program Instance CR_abs : Abs CR := λ x, CRabs x.
+Next Obligation. split; [apply CRabs_pos | apply CRabs_neg]. Qed.
+
+Lemma CRabs_nonneg (x : CR) : 0 ≤ CRabs x.
+Proof.
+apply -> CRabs_cases; [| apply _ | apply _].
+split; [trivial | apply (proj1 (rings.flip_nonpos_negate x))].
+Qed.
+
+Lemma gball_CRabs (r : Q) (x y : CR) : gball r x y <-> CRabs (x - y) ≤ 'r.
+Proof. rewrite CRball.rational. apply CRball.as_distance_bound. Qed.
+
+Lemma minus_0_r `{Ring R} (x : R) : x - 0 = x.
+Proof. rewrite rings.negate_0; apply rings.plus_0_r. Qed.
+
+Section RiemannSumBounds.
+
+Context (f : Q -> CR).
+
+Lemma riemann_sum_const (a : Q) (w : Qpos) (m : CR) (n : positive) :
+ riemann_sum (λ _, m) a w n = scale w m.
+Proof.
+
+SearchAbout cm_Sum.
+
+
+Lemma riemann_sum_bounds (a : Q) (w : Qpos) (m : CR) (e : Q) (n : positive) :
+ (forall (x : Q), (a ≤ x ≤ a + w) -> gball e (f x) m) ->
+ gball (w * e) (riemann_sum f a w n) (scale w m).
+Proof.
+intro A.
+
+
+
+
+
+
+
+End RiemannSumBounds.
+
+Section IntegralBound.
+
+Context (f : Q -> CR) `{Integrable f}.
+
+Add Ring CR : (rings.stdlib_ring_theory CR).
+
+Lemma scale_0_r (x : Q) : scale x 0 = 0.
+Proof. rewrite <- CRmult_scale; change (cast Q CR x * 0 = 0); ring. Qed.
+
+Lemma integral_abs_bound (from : Q) (width : Qpos) (M : Q) :
+ (forall (x : Q), (from ≤ x ≤ from + width) -> CRabs (f x) ≤ 'M) ->
+ CRabs (∫ f from width) ≤ '(`width * M).
+Proof.
+intro A. rewrite <- (CRplus_0_r (∫ f from width)), <- CRopp_0.
+apply CRball.as_distance_bound, CRball.rational. rewrite <- (scale_0_r width).
+assert (A1 : 0 ≤ M).
++ apply CRle_Qle. apply CRle_trans with (y := CRabs (f from)); [apply CRabs_nonneg |].
+ apply A. split; [reflexivity |].
+ apply semirings.nonneg_plus_le_compat_r. apply orders.lt_le; Qauto_nonneg.
++ change M with (QnonNeg.to_Q (exist _ M A1)).
+ apply bounded_with_nonneg_radius; [easy |].
+ intros x A2; apply gball_CRabs; rewrite minus_0_r; now apply A.
+Qed.
+
+
+Section IntegralOfSum.
+
+Context (f g : Q -> CR) `{Integral f, !Integrable f} `{Integral g, !Integrable g}.
+
+Notation "f +1 g" := (λ x, f x + g x) (at level 50, left associativity).
+
+Theorem integral_sum (a : Q) (w : Qpos) : ∫ (f +1 g) a w = ∫ f a w + ∫ g a w.
+
+
+
+
+
+
+
(*
Lemma integrate_proper
(f g: Q → CR)
diff --git a/broken/FromMetric2.v b/broken/FromMetric2.v
index 4b5514cc..987b2632 100644
--- a/broken/FromMetric2.v
+++ b/broken/FromMetric2.v
@@ -15,16 +15,16 @@ Qed.
Lemma Qmult_pos_neg (x y : Q) : 0 < x -> y < 0 -> x * y < 0.
Proof. intros H1 H2. rewrite Qmult_comm. now apply Qmult_neg_pos. Qed.
-Lemma Qmult_pos_r : forall x y : Q, 0 < x -> 0 < x * y -> 0 < y.
+Lemma Qmult_pos_r : forall x y : Q, 0 <= x -> 0 < x * y -> 0 < y.
Proof.
intros x y H1 H2.
destruct (Qsec.Qdec_sign y) as [[? | ?] | H]; trivial.
-+ exfalso; apply (Qlt_irrefl 0), Qlt_trans with (y := x * y); trivial.
- now apply Qmult_pos_neg.
++ exfalso. apply (Qlt_irrefl 0), Qlt_le_trans with (y := x * y); trivial.
+ now apply Q.Qmult_nonneg_nonpos; [| apply Qlt_le_weak].
+ rewrite H, Qmult_0_r in H2. exfalso; now apply (Qlt_irrefl 0).
Qed.
-Lemma Qmult_pos_l : forall x y : Q, 0 < y -> 0 < x * y -> 0 < x.
+Lemma Qmult_pos_l : forall x y : Q, 0 <= y -> 0 < x * y -> 0 < x.
Proof. intros x y H1 H2. rewrite Qmult_comm in H2. now apply (Qmult_pos_r y x). Qed.
Require Import
@@ -69,10 +69,10 @@ intro e_neg. unfold gball. destruct (Qsec.Qdec_sign e) as [[E | E] | E]; [easy |
+ rewrite E in e_neg. intros _; apply (Qlt_irrefl _ e_neg).
Qed.
-Lemma mspc_closed_help (e : Q) (x y : X) :
- (∀ d : Q, 0 < d → mspc_ball (e + d) x y) → mspc_ball e x y.
+Lemma gball_closed (e : Q) (x y : X) :
+ (∀ d : Q, 0 < d → gball (e + d) x y) → gball e x y.
Proof.
-intro C. change (gball e x y). unfold gball.
+intro C. (*change (gball e x y).*) unfold gball.
destruct (Qsec.Qdec_sign e) as [[e_neg | e_pos] | e_zero].
+ assert (e / 2 < 0) by now apply neg_pos_mult.
apply (gball_neg (e/2) x y); [easy |].
@@ -83,6 +83,12 @@ destruct (Qsec.Qdec_sign e) as [[e_neg | e_pos] | e_zero].
setoid_replace d with (e + d); [now apply C | rewrite e_zero; symmetry; apply plus_0_l].
Qed.
+Lemma gball_closed_eq (x y : X) : (∀ d : Q, 0 < d -> gball d x y) -> x = y.
+Proof.
+intro C. change (gball 0 x y). apply gball_closed. intro d.
+setoid_replace (0 + d)%Q with d by apply plus_0_l. apply C.
+Qed.
+
Global Instance : ExtMetricSpaceClass X.
Proof.
constructor.
@@ -92,7 +98,7 @@ constructor.
+ apply gball_refl.
+ intros [e |]; [apply gball_sym | easy].
+ apply gball_triangle.
-+ apply mspc_closed_help.
++ apply gball_closed.
Qed.
Definition conv_reg (f : RegularFunction X) : Complete.RegularFunction X.
@@ -145,38 +151,34 @@ Require Import CRmetric.
Section CompleteSegment.
-Context (r : Q) (a : CR).
+Context {X : MetricSpace} (r : Q) (a : Complete X).
-Global (*Program*) Instance : Limit (sig (mspc_ball r a)).
-(*:= λ f, exist _ (lim (Build_RegularFunction (@proj1_sig _ _ ∘ f) _)) _.*)
-(*Next Obligation.
+Global Program Instance : Limit (sig (mspc_ball r a)) :=
+ λ f, exist _ (lim (Build_RegularFunction (@proj1_sig _ _ ∘ f) _)) _.
+Next Obligation.
apply f.
Qed.
-Next Obligation.*)
-intros [f f_reg]. set (g := @proj1_sig CR _ ∘ f).
-assert (g_reg : IsRegularFunction g) by apply f_reg.
-exists (lim (Build_RegularFunction g g_reg)).
-unfold mspc_ball, msp_mspc_ball. apply gball_complete. intros e1 e2.
+Next Obligation.
+apply gball_complete; intros e1 e2.
unfold lim, limit_complete, Cjoin_fun, Cjoin_raw; simpl.
-assert (H : mspc_ball r a (g ((1 # 2) * QposAsQ e2)%Q)) by apply (proj2_sig (f ((1 # 2) * e2))).
+assert (H : mspc_ball r a ((@proj1_sig _ _ ∘ f) ((1 # 2) * QposAsQ e2)%Q)) by
+ apply (proj2_sig (f ((1 # 2) * e2))).
unfold mspc_ball, msp_mspc_ball in H.
apply gball_weak_le with (q := QposAsQ e1 + r + (QposAsQ ((1 # 2) * e2)%Qpos)).
+ apply Qplus_le_r. apply Qle_half; auto.
+ apply gball_complete, H.
-Defined.
+Qed.
-(*Global Instance : CompleteMetricSpaceClass (sig (mspc_ball r a)).
+Global Instance : CompleteMetricSpaceClass (sig (mspc_ball r a)).
Proof.
constructor; [| apply _].
apply ext_equiv_r; [intros x y E; apply E |].
-intros [f f_reg] e1 e2 e1_pos e2_pos.
-set (g := @proj1_sig CR _ ∘ f).
-assert (g_reg : IsRegularFunction g) by apply f_reg.
-assert (H : CompleteMetricSpaceClass CR) by apply _.
-destruct H as [H _]. specialize (H (Build_RegularFunction g g_reg) (Build_RegularFunction g g_reg)).
-simpl in *.
-eapply H.
-*)
+intros f e1 e2 e1_pos e2_pos; unfold Datatypes.id.
+assert (C : CompleteMetricSpaceClass (Complete X)) by apply _.
+destruct C as [C _].
+assert (R : IsRegularFunction (@proj1_sig _ _ ∘ f)) by apply f.
+specialize (C (Build_RegularFunction _ R) (Build_RegularFunction _ R)). now apply C.
+Qed.
End CompleteSegment.
From 59ce4ff07a42bbc5f7e72ad7c2dfdc86262c5120 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Mon, 29 Oct 2012 13:57:28 +0100
Subject: [PATCH 027/110] Moved lemmas about Q and Z into corresponding files
---
broken/AbstractIntegration.v | 111 ++++-------------------------------
broken/metric.v | 20 +++----
model/metric2/Qmetric.v | 11 ++++
reals/fast/CRArith.v | 7 +++
stdlib_omissions/Q.v | 61 ++++++++++++++++++-
stdlib_omissions/Z.v | 8 +++
6 files changed, 108 insertions(+), 110 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 3e7d21ca..000a6c9f 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -14,7 +14,10 @@ Require Import metric FromMetric2.
Require Qinf QnonNeg QnnInf CRball.
Import Qinf.notations QnonNeg.notations QnnInf.notations CRball.notations Qabs.
-(*Import canonical_names.*)
+
+Require Import CRtrans ARtrans. (* This is almost all CoRN *)
+
+
(*Notation Qinf := Qinf.T.
@@ -46,73 +49,7 @@ Open Local Scope Q_scope.
Open Local Scope uc_scope.
Open Local Scope CR_scope.
-Section QFacts.
-
-Open Scope Q_scope.
-
-Lemma Qminus_less (x y : Q) : 0 <= y -> x - y <= x.
-Proof.
-intro H. rewrite <- (Qplus_0_r x) at 2. apply Qplus_le_r. change 0 with (-0).
-now apply Qopp_le_compat.
-Qed.
-
-(* The following two lemmas are obtained from the lemmas with the same name
-in Coq.QArith.QArith_base by replacing -> with <-> *)
-
-Lemma Qle_shift_div_l : forall a b c, 0 < c -> (a * c <= b <-> a <= b / c).
-Proof.
-intros a b c A; split; [now apply Qle_shift_div_l |].
-intro A1. apply (Qmult_le_r _ _ (/c)); [now apply Qinv_lt_0_compat |].
-rewrite <- Qmult_assoc, Qmult_inv_r; [now rewrite Qmult_1_r | auto with qarith].
-Qed.
-
-Lemma Qle_shift_div_r : forall a b c, 0 < b -> (a <= c * b <-> a / b <= c).
-Proof.
-intros a b c A; split; [now apply Qle_shift_div_r |].
-intro A1. apply (Qmult_le_r _ _ (/b)); [now apply Qinv_lt_0_compat |].
-rewrite <- Qmult_assoc, Qmult_inv_r; [now rewrite Qmult_1_r | auto with qarith].
-Qed.
-
-Lemma Qle_div_l : forall a b c, 0 < b -> 0 < c -> (a / b <= c <-> a / c <= b).
-Proof.
-intros a b c A1 A2.
-rewrite <- Qle_shift_div_r; [| easy]. rewrite (Qmult_comm c b). rewrite Qle_shift_div_r; easy.
-Qed.
-
-Lemma Qle_div_r : forall a b c, 0 < b -> 0 < c -> (b <= a / c <-> c <= a / b).
-Proof.
-intros a b c A1 A2.
-rewrite <- Qle_shift_div_l; [| easy]. rewrite (Qmult_comm b c). rewrite Qle_shift_div_l; easy.
-Qed.
-
-Lemma Qabs_zero (x : Q) : Qabs x == 0 <-> x == 0.
-Proof.
-split; intro H; [| now rewrite H].
-destruct (Qdec_sign x) as [[x_neg | x_pos] | x_zero]; [| | trivial].
-+ rewrite Qabs_neg in H; [| apply Qlt_le_weak; trivial].
- now rewrite <- (Qopp_involutive x), H.
-+ rewrite Qabs_pos in H; [| apply Qlt_le_weak]; trivial.
-Qed.
-
-Lemma Qabs_nonpos (x : Q) : Qabs x <= 0 -> x == 0.
-Proof.
-intro H. apply Qle_lteq in H. destruct H as [H | H].
-+ elim (Qlt_not_le _ _ H (Qabs_nonneg x)).
-+ now apply Qabs_zero.
-Qed.
-
-Lemma gball_abs (e a b : Q) : gball e a b ↔ (Qabs (a - b) <= e).
-Proof.
-unfold gball. destruct (Qdec_sign e) as [[e_neg | e_pos] | e_zero].
-+ split; intros H; [easy |]. assert (H1 := Qle_lt_trans _ _ _ H e_neg).
- eapply Qle_not_lt; [apply Qabs_nonneg | apply H1].
-+ apply Qball_Qabs.
-+ split; intro H.
- - rewrite e_zero, H; setoid_replace (b - b) with 0 by ring; apply Qle_refl.
- - rewrite e_zero in H. apply Qabs_nonpos in H; now apply Qminus_eq.
-Qed.
-
-End QFacts.
+SearchAbout CRnonNeg.
(** Any nonnegative width can be split up into an integral number of
equal-sized pieces no bigger than a given bound: *)
@@ -403,14 +340,6 @@ Section integral_interface.
*)
(** Iterating this result shows that Riemann sums are arbitrarily good approximations: *)
-
- Lemma CRnonNegQpos : forall e : Qpos, CRnonNeg (' ` e).
- Proof.
- intros [e e_pos]; apply CRnonNeg_criterion; simpl.
- intros q A; apply Qlt_le_weak, Qlt_le_trans with (y := e); trivial.
- now apply CRle_Qle.
- Qed.
-
Open Scope Q_scope.
Lemma luc_gball (a w delta eps x y : Q) :
@@ -427,15 +356,6 @@ Section integral_interface.
apply (mspc_monotone delta); [apply A1 | apply A4].
Qed.
-
- Lemma Qabs_le_nonneg (x y : Q) : 0 <= x -> (Qabs x <= y <-> x <= y).
- Proof.
- intro A. rewrite Qabs_Qle_condition.
- split; [intros [_ ?]; trivial | intro A1; split; [| trivial]].
- apply Qle_trans with (y := 0); [| trivial].
- apply (Qopp_le_compat 0); eapply Qle_trans; eauto.
- Qed.
-
Lemma Riemann_sums_approximate_integral (a: Q) (w: Qpos) (e: Qpos) (iw: Q) (n: nat):
(n * iw == w)%Q ->
(iw <= lmu a w e)%Qinf ->
@@ -465,7 +385,7 @@ Section integral_interface.
apply Qmult_le_compat_r. apply Qlt_le_weak. rewrite <- Zlt_Qlt. now apply inj_lt.
apply (proj2_sig iw').
change (n * iw' == w) in A. rewrite <- A; reflexivity.
- + apply gball_abs, Qabs_Qle_condition.
+ + apply gball_Qabs, Qabs_Qle_condition.
split.
apply Qplus_le_l with (z := x), Qplus_le_l with (z := w).
setoid_replace (- w + x + w) with x by ring. setoid_replace (a - x + x + w) with (a + w) by ring.
@@ -483,7 +403,7 @@ Section integral_interface.
apply Qplus_le_r. change 0 with (-0). apply Qopp_le_compat, Qlt_le_weak, (proj2_sig w).
apply Qle_trans with (y := a + m * ` iw'); [| easy].
rewrite <- (Qplus_0_r a) at 1. apply Qplus_le_r, Qmult_le_0_compat; [apply Qle_nat | apply (proj2_sig iw')].
- + apply gball_abs, Qabs_Qle_condition; split.
+ + apply gball_Qabs, Qabs_Qle_condition; split.
apply (Qplus_le_r (x + `iw')).
setoid_replace (x + `iw' + - `iw') with x by ring.
setoid_replace (x + `iw' + (a + m * iw' - x)) with (a + m * iw' + `iw') by ring. apply A2.
@@ -512,14 +432,6 @@ Section integral_interface.
rewrite positive_nat_Z. unfold inject_Z. rewrite !Qmake_Qdiv; field; auto.
Qed.
- Lemma le_Z_to_pos (z : Z) (p : positive) : (Z.to_pos z <= p)%positive <-> (z <= p)%Z.
- Proof.
- destruct z as [| q | q]; simpl.
- + split; intros _; [apply Zle_0_pos | apply Pos.le_1_l].
- + apply Ple_Zle.
- + split; intros _; [apply Zle_neg_pos | apply Pos.le_1_l].
- Qed.
-
Lemma Riemann_sums_approximate_integral'' (a : Q) (w : Qpos) (e : Qpos) :
exists N : positive, forall n : positive, (N <= n)%positive ->
gball e (riemann_sum a w n) (∫ f a w).
@@ -535,7 +447,7 @@ Section integral_interface.
change (0 < mu) in A3.
rewrite Qmake_Qdiv, injZ_One. unfold Qdiv. rewrite Qmult_assoc, Qmult_1_r.
change (w / n <= mu). apply Qle_div_l; auto.
- subst N. now apply le_Z_to_pos, Qle_Qceiling_Z in A.
+ subst N. now apply Ple_Zle_to_pos_l, Qle_Qceiling_Z in A.
Qed.
End singular_props.
@@ -589,7 +501,6 @@ Proof with auto.
apply (integral_wd f)...
Qed.
-Require Import ARtrans. (* This is almost all CoRN *)
Import canonical_names.
Program Instance CR_abs : Abs CR := λ x, CRabs x.
@@ -607,7 +518,7 @@ Proof. rewrite CRball.rational. apply CRball.as_distance_bound. Qed.
Lemma minus_0_r `{Ring R} (x : R) : x - 0 = x.
Proof. rewrite rings.negate_0; apply rings.plus_0_r. Qed.
-Section RiemannSumBounds.
+(*Section RiemannSumBounds.
Context (f : Q -> CR).
@@ -631,6 +542,7 @@ intro A.
End RiemannSumBounds.
+*)
Section IntegralBound.
@@ -657,6 +569,7 @@ assert (A1 : 0 ≤ M).
Qed.
+(*
Section IntegralOfSum.
Context (f g : Q -> CR) `{Integral f, !Integrable f} `{Integral g, !Integrable g}.
@@ -664,7 +577,7 @@ Context (f g : Q -> CR) `{Integral f, !Integrable f} `{Integral g, !Integrable g
Notation "f +1 g" := (λ x, f x + g x) (at level 50, left associativity).
Theorem integral_sum (a : Q) (w : Qpos) : ∫ (f +1 g) a w = ∫ f a w + ∫ g a w.
-
+*)
diff --git a/broken/metric.v b/broken/metric.v
index 9b0f2ce5..cbbc8394 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -45,7 +45,7 @@ intro A; destruct z as [| p | p]; trivial.
unfold Z.le in A; now contradict A.
Qed.
-Lemma le_Z_to_nat (n : nat) (z : Z) : (Z.to_nat z <= n)%nat <-> (z <= Z.of_nat n)%Z.
+Lemma le_Zle_to_nat_l (n : nat) (z : Z) : (Z.to_nat z <= n)%nat <-> (z <= Z.of_nat n)%Z.
Proof.
pose proof (le_0_n n). pose proof (Zle_0_nat n).
destruct (Z.neg_nonneg_cases z).
@@ -55,11 +55,11 @@ destruct (Z.neg_nonneg_cases z).
- apply Z2Nat.inj_le in A; trivial. rewrite Nat2Z.id in A; trivial.
Qed.
-Lemma lt_Z_to_nat (n : nat) (z : Z) : (n < Z.to_nat z)%nat <-> (Z.of_nat n < z)%Z.
+Lemma lt_Zlt_to_nat_r (n : nat) (z : Z) : (n < Z.to_nat z)%nat <-> (Z.of_nat n < z)%Z.
Proof.
assert (A : forall (m n : nat), not (m <= n)%nat <-> (n < m)%nat).
+ intros; split; [apply not_le | apply gt_not_le].
-+ assert (A1 := le_Z_to_nat n z). apply iff_not in A1.
++ assert (A1 := le_Zle_to_nat_l n z). apply iff_not in A1.
now rewrite A, Z.nle_gt in A1.
Qed.
@@ -72,26 +72,26 @@ apply Qplus_lt_l with (z := -1). setoid_replace (q + 1 + -1)%Q with q.
+ now rewrite <- Qplus_assoc, Qplus_opp_r, Qplus_0_r.
Qed.
-Lemma Qle_Qceiling_Z (q : Q) (z : Z) : (Qceiling q <= z)%Z <-> (q <= z)%Q.
+Lemma Zle_Qle_Qceiling_l (q : Q) (z : Z) : (Qceiling q <= z)%Z <-> (q <= z)%Q.
Proof.
split; intro A.
+ rewrite Zle_Qle in A. apply Qle_trans with (y := Qceiling q); [apply Qle_ceiling | trivial].
+ apply Z.lt_pred_le. rewrite Zlt_Qlt. now apply Qlt_le_trans with (y := q); [apply Qceiling_lt |].
Qed.
-Lemma Qle_Qceiling_nat (q : Q) (n : nat) : (Z.to_nat (Qceiling q) <= n)%nat <-> (q <= n)%Q.
-Proof. rewrite le_Z_to_nat; apply Qle_Qceiling_Z. Qed.
+Lemma le_Qle_Qceiling_Qceiling_to_nat_l (q : Q) (n : nat) : (Z.to_nat (Qceiling q) <= n)%nat <-> (q <= n)%Q.
+Proof. rewrite le_Zle_to_nat_l; apply Zle_Qle_Qceiling_l. Qed.
-Lemma Qlt_Qceiling_Z (q : Q) (z : Z) : (z < q)%Q <-> (z < Qceiling q)%Z.
+Lemma Qlt_Zlt_inject_Z_l (q : Q) (z : Z) : (z < q)%Q <-> (z < Qceiling q)%Z.
Proof.
assert (A : forall (x y : Q), not (x <= y)%Q <-> (y < x)%Q).
+ intros; split; [apply Qnot_le_lt | apply Qlt_not_le].
-+ assert (A1 := Qle_Qceiling_Z q z). apply iff_not in A1.
++ assert (A1 := Zle_Qle_Qceiling_l q z). apply iff_not in A1.
now rewrite A, Z.nle_gt in A1.
Qed.
-Lemma Qlt_Qceiling_nat (q : Q) (n : nat) : (n < q)%Q <-> (n < Z.to_nat (Qceiling q))%nat.
-Proof. rewrite (Qlt_Qceiling_Z q n); symmetry; apply lt_Z_to_nat. Qed.
+Lemma Qlt_lt_of_nat_inject_Z_l (q : Q) (n : nat) : (n < q)%Q <-> (n < Z.to_nat (Qceiling q))%nat.
+Proof. rewrite (Qlt_Zlt_inject_Z_l q n); symmetry; apply lt_Zlt_to_nat_r. Qed.
Lemma neq_symm `{Ae : Equiv X} `{!Symmetric Ae} (x y : X) : x ≠ y -> y ≠ x.
Proof. intros A1 A2; apply A1; now symmetry. Qed.
diff --git a/model/metric2/Qmetric.v b/model/metric2/Qmetric.v
index 0b8e5865..48b50c9b 100644
--- a/model/metric2/Qmetric.v
+++ b/model/metric2/Qmetric.v
@@ -75,6 +75,17 @@ Qed.
Lemma Qball_Qabs : forall e a b, Qball e a b <-> Qabs (a - b) <= e.
Proof. split; apply AbsSmall_Qabs. Qed.
+Lemma gball_Qabs (e a b : Q) : gball e a b ↔ (Qabs (a - b) <= e).
+Proof.
+unfold gball. destruct (Qdec_sign e) as [[e_neg | e_pos] | e_zero].
++ split; intros H; [easy |]. assert (H1 := Qle_lt_trans _ _ _ H e_neg).
+ eapply Qle_not_lt; [apply Qabs_nonneg | apply H1].
++ apply Qball_Qabs.
++ split; intro H.
+ - rewrite e_zero, H; setoid_replace (b - b) with 0 by ring; apply Qle_refl.
+ - rewrite e_zero in H. apply Qabs_nonpos in H; now apply Qminus_eq.
+Qed.
+
Lemma Qle_closed : (forall e x, (forall d : Qpos, x <= e+d) -> x <= e).
Proof.
intros.
diff --git a/reals/fast/CRArith.v b/reals/fast/CRArith.v
index a8a4eb1c..7436e318 100644
--- a/reals/fast/CRArith.v
+++ b/reals/fast/CRArith.v
@@ -623,6 +623,13 @@ Proof with auto.
apply CRle_trans with y...
Qed.
+Lemma CRnonNegQpos : forall e : Qpos, CRnonNeg (' ` e).
+Proof.
+ intros [e e_pos]; apply CRnonNeg_criterion; simpl.
+ intros q A; apply Qlt_le_weak, Qlt_le_trans with (y := e); trivial.
+ now apply CRle_Qle.
+Qed.
+
Lemma scale_0 x: scale 0 x == 0.
Proof. rewrite <- CRmult_scale. ring. Qed.
diff --git a/stdlib_omissions/Q.v b/stdlib_omissions/Q.v
index 3affed72..952a8e36 100644
--- a/stdlib_omissions/Q.v
+++ b/stdlib_omissions/Q.v
@@ -312,6 +312,12 @@ Proof.
apply Qplus_le_compat; assumption.
Qed.
+Lemma Qminus_less (x y : Q) : 0 <= y -> x - y <= x.
+Proof.
+intro H. rewrite <- (Qplus_0_r x) at 2. apply Qplus_le_r. change 0 with (-0).
+now apply Qopp_le_compat.
+Qed.
+
Lemma Qabs_Qle x y: (Qabs x <= y) <-> (-y <= x <= y).
Proof with intuition.
split.
@@ -341,7 +347,31 @@ Proof with try ring.
setoid_replace (y - r + r) with y...
intuition.
Qed.
-
+
+Lemma Qabs_zero (x : Q) : Qabs x == 0 <-> x == 0.
+Proof.
+split; intro H; [| now rewrite H].
+destruct (Qdec_sign x) as [[x_neg | x_pos] | x_zero]; [| | trivial].
++ rewrite Qabs_neg in H; [| apply Qlt_le_weak; trivial].
+ now rewrite <- (Qopp_involutive x), H.
++ rewrite Qabs_pos in H; [| apply Qlt_le_weak]; trivial.
+Qed.
+
+Lemma Qabs_nonpos (x : Q) : Qabs x <= 0 -> x == 0.
+Proof.
+intro H. apply Qle_lteq in H. destruct H as [H | H].
++ elim (Qlt_not_le _ _ H (Qabs_nonneg x)).
++ now apply Qabs_zero.
+Qed.
+
+Lemma Qabs_le_nonneg (x y : Q) : 0 <= x -> (Qabs x <= y <-> x <= y).
+Proof.
+ intro A. rewrite Qabs_Qle_condition.
+ split; [intros [_ ?]; trivial | intro A1; split; [| trivial]].
+ apply Qle_trans with (y := 0); [| trivial].
+ apply (Qopp_le_compat 0); eapply Qle_trans; eauto.
+Qed.
+
Lemma Qdiv_le_1 (x y: Q): 0 <= x <= y -> x / y <= 1.
Proof with intuition.
intros.
@@ -357,6 +387,35 @@ Proof with intuition.
exfalso. apply ynnP...
Qed.
+(* The following two lemmas are obtained from the lemmas with the same name
+in Coq.QArith.QArith_base by replacing -> with <-> *)
+
+Lemma Qle_shift_div_l : forall a b c, 0 < c -> (a * c <= b <-> a <= b / c).
+Proof.
+intros a b c A; split; [now apply Qle_shift_div_l |].
+intro A1. apply (Qmult_le_r _ _ (/c)); [now apply Qinv_lt_0_compat |].
+rewrite <- Qmult_assoc, Qmult_inv_r; [now rewrite Qmult_1_r | auto with qarith].
+Qed.
+
+Lemma Qle_shift_div_r : forall a b c, 0 < b -> (a <= c * b <-> a / b <= c).
+Proof.
+intros a b c A; split; [now apply Qle_shift_div_r |].
+intro A1. apply (Qmult_le_r _ _ (/b)); [now apply Qinv_lt_0_compat |].
+rewrite <- Qmult_assoc, Qmult_inv_r; [now rewrite Qmult_1_r | auto with qarith].
+Qed.
+
+Lemma Qle_div_l : forall a b c, 0 < b -> 0 < c -> (a / b <= c <-> a / c <= b).
+Proof.
+intros a b c A1 A2.
+rewrite <- Qle_shift_div_r; [| easy]. rewrite (Qmult_comm c b). rewrite Qle_shift_div_r; easy.
+Qed.
+
+Lemma Qle_div_r : forall a b c, 0 < b -> 0 < c -> (b <= a / c <-> c <= a / b).
+Proof.
+intros a b c A1 A2.
+rewrite <- Qle_shift_div_l; [| easy]. rewrite (Qmult_comm b c). rewrite Qle_shift_div_l; easy.
+Qed.
+
Lemma nat_lt_Qlt n m: (n < m)%nat -> (inject_Z (Z_of_nat n) + (1#2) < inject_Z (Z_of_nat m))%Q.
Proof with intuition.
unfold lt.
diff --git a/stdlib_omissions/Z.v b/stdlib_omissions/Z.v
index 09fcd906..fbb4f4b0 100644
--- a/stdlib_omissions/Z.v
+++ b/stdlib_omissions/Z.v
@@ -94,5 +94,13 @@ Proof.
reflexivity.
Qed.
+Lemma Ple_Zle_to_pos_l (z : Z) (p : positive) : (Z.to_pos z <= p)%positive <-> (z <= p)%Z.
+Proof.
+ destruct z as [| q | q]; simpl.
+ + split; intros _; [apply Zle_0_pos | apply Pos.le_1_l].
+ + apply Ple_Zle.
+ + split; intros _; [apply Zle_neg_pos | apply Pos.le_1_l].
+Qed.
+
Lemma add_pos_nonneg (a b: Z): 0 < a -> 0 <= b -> 0 < a+b.
Proof. intros. omega. Qed.
From 90baee16f46d48897a1dc964f681ce851ed9bcb6 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 30 Oct 2012 21:39:07 +0100
Subject: [PATCH 028/110] Moved lemmas about Q, gball, etc. to other places in
CoRN
---
broken/AbstractIntegration.v | 24 +++++--------
broken/FromMetric2.v | 70 +++---------------------------------
broken/metric.v | 57 -----------------------------
metric2/Metric.v | 35 ++++++++++++++++++
model/metric2/Qmetric.v | 23 ++++++------
reals/fast/CRabs.v | 6 ++++
reals/fast/CRball.v | 3 ++
stdlib_omissions/Q.v | 62 +++++++++++++++++++++++++++++++-
stdlib_omissions/Z.v | 30 +++++++++++++++-
9 files changed, 159 insertions(+), 151 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 000a6c9f..536f2ead 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -9,15 +9,12 @@ Require Import
stdlib_omissions.Z
stdlib_omissions.Q
stdlib_omissions.N.
- (*metric2.Classified*)
Require Import metric FromMetric2.
Require Qinf QnonNeg QnnInf CRball.
Import Qinf.notations QnonNeg.notations QnnInf.notations CRball.notations Qabs.
-Require Import CRtrans ARtrans. (* This is almost all CoRN *)
-
-
+(*Require Import CRtrans ARtrans.*) (* This is almost all CoRN *)
(*Notation Qinf := Qinf.T.
@@ -447,7 +444,7 @@ Section integral_interface.
change (0 < mu) in A3.
rewrite Qmake_Qdiv, injZ_One. unfold Qdiv. rewrite Qmult_assoc, Qmult_1_r.
change (w / n <= mu). apply Qle_div_l; auto.
- subst N. now apply Ple_Zle_to_pos_l, Qle_Qceiling_Z in A.
+ subst N. now apply Z.Ple_Zle_to_pos, Q.Zle_Qle_Qceiling in A.
Qed.
End singular_props.
@@ -503,8 +500,8 @@ Qed.
Import canonical_names.
-Program Instance CR_abs : Abs CR := λ x, CRabs x.
-Next Obligation. split; [apply CRabs_pos | apply CRabs_neg]. Qed.
+(* Should this lemma be used to CoRN.reals.fast.CRabs? That file does not use
+type class notations from canonical_names like ≤ *)
Lemma CRabs_nonneg (x : CR) : 0 ≤ CRabs x.
Proof.
@@ -512,12 +509,6 @@ apply -> CRabs_cases; [| apply _ | apply _].
split; [trivial | apply (proj1 (rings.flip_nonpos_negate x))].
Qed.
-Lemma gball_CRabs (r : Q) (x y : CR) : gball r x y <-> CRabs (x - y) ≤ 'r.
-Proof. rewrite CRball.rational. apply CRball.as_distance_bound. Qed.
-
-Lemma minus_0_r `{Ring R} (x : R) : x - 0 = x.
-Proof. rewrite rings.negate_0; apply rings.plus_0_r. Qed.
-
(*Section RiemannSumBounds.
Context (f : Q -> CR).
@@ -553,6 +544,8 @@ Add Ring CR : (rings.stdlib_ring_theory CR).
Lemma scale_0_r (x : Q) : scale x 0 = 0.
Proof. rewrite <- CRmult_scale; change (cast Q CR x * 0 = 0); ring. Qed.
+Require Import propholds.
+
Lemma integral_abs_bound (from : Q) (width : Qpos) (M : Q) :
(forall (x : Q), (from ≤ x ≤ from + width) -> CRabs (f x) ≤ 'M) ->
CRabs (∫ f from width) ≤ '(`width * M).
@@ -562,10 +555,11 @@ apply CRball.as_distance_bound, CRball.rational. rewrite <- (scale_0_r width).
assert (A1 : 0 ≤ M).
+ apply CRle_Qle. apply CRle_trans with (y := CRabs (f from)); [apply CRabs_nonneg |].
apply A. split; [reflexivity |].
- apply semirings.nonneg_plus_le_compat_r. apply orders.lt_le; Qauto_nonneg.
+ apply semirings.nonneg_plus_le_compat_r; change (0 <= width)%Q; Qauto_nonneg.
+ change M with (QnonNeg.to_Q (exist _ M A1)).
apply bounded_with_nonneg_radius; [easy |].
- intros x A2; apply gball_CRabs; rewrite minus_0_r; now apply A.
+ intros x A2. apply CRball.gball_CRabs. change (f x - 0%mc)%CR with (f x - 0).
+ rewrite rings.minus_0_r; now apply A.
Qed.
diff --git a/broken/FromMetric2.v b/broken/FromMetric2.v
index 987b2632..f3b04ebe 100644
--- a/broken/FromMetric2.v
+++ b/broken/FromMetric2.v
@@ -1,32 +1,5 @@
Require Import metric2.Complete metric2.Metric metric.
-Lemma Qle_half (x : Q) : 0 <= x -> (1 # 2) * x <= x.
-Proof.
-intro H. rewrite <- (Qmult_1_l x) at 2. apply Qmult_le_compat_r; auto with qarith.
-Qed.
-
-Lemma Qmult_neg_pos (x y : Q) : x < 0 -> 0 < y -> x * y < 0.
-Proof.
-intros H1 H2.
-apply Q.Qopp_Qlt_0_l. setoid_replace (- (x * y)) with ((- x) * y) by ring.
-apply Q.Qmult_lt_0_compat; trivial. now apply Q.Qopp_Qlt_0_l.
-Qed.
-
-Lemma Qmult_pos_neg (x y : Q) : 0 < x -> y < 0 -> x * y < 0.
-Proof. intros H1 H2. rewrite Qmult_comm. now apply Qmult_neg_pos. Qed.
-
-Lemma Qmult_pos_r : forall x y : Q, 0 <= x -> 0 < x * y -> 0 < y.
-Proof.
-intros x y H1 H2.
-destruct (Qsec.Qdec_sign y) as [[? | ?] | H]; trivial.
-+ exfalso. apply (Qlt_irrefl 0), Qlt_le_trans with (y := x * y); trivial.
- now apply Q.Qmult_nonneg_nonpos; [| apply Qlt_le_weak].
-+ rewrite H, Qmult_0_r in H2. exfalso; now apply (Qlt_irrefl 0).
-Qed.
-
-Lemma Qmult_pos_l : forall x y : Q, 0 <= y -> 0 < x * y -> 0 < x.
-Proof. intros x y H1 H2. rewrite Qmult_comm in H2. now apply (Qmult_pos_r y x). Qed.
-
Require Import
abstract_algebra stdlib_rationals
orders.orders orders.semirings orders.rings theory.rings.
@@ -54,41 +27,6 @@ unfold mspc_ball, msp_mspc_ball.
change (e1 = e2) in E1. now rewrite E1, E2, E3.
Qed.
-Lemma gball_pos {e : Q} (e_pos : 0 < e) (x y : X) : ball (e ↾ e_pos) x y <-> gball e x y.
-Proof.
-unfold gball. destruct (Qsec.Qdec_sign e) as [[e_neg | e_pos'] | e_zero].
-+ elim (Qlt_irrefl _ (Qlt_trans _ _ _ e_pos e_neg)).
-+ mc_setoid_replace (e ↾ e_pos) with (e ↾ e_pos'); easy.
-+ exfalso; rewrite e_zero in e_pos; apply (Qlt_irrefl _ e_pos).
-Qed.
-
-Lemma gball_neg (e : Q) (x y : X) : e < 0 -> ~ gball e x y.
-Proof.
-intro e_neg. unfold gball. destruct (Qsec.Qdec_sign e) as [[E | E] | E]; [easy | |].
-+ intros _; apply (Qlt_irrefl _ (Qlt_trans _ _ _ e_neg E)).
-+ rewrite E in e_neg. intros _; apply (Qlt_irrefl _ e_neg).
-Qed.
-
-Lemma gball_closed (e : Q) (x y : X) :
- (∀ d : Q, 0 < d → gball (e + d) x y) → gball e x y.
-Proof.
-intro C. (*change (gball e x y).*) unfold gball.
-destruct (Qsec.Qdec_sign e) as [[e_neg | e_pos] | e_zero].
-+ assert (e / 2 < 0) by now apply neg_pos_mult.
- apply (gball_neg (e/2) x y); [easy |].
- mc_setoid_replace (e / 2) with (e - e / 2) by (field; discriminate).
- apply C; now apply flip_neg_negate.
-+ apply (msp_closed (msp X)). intros [d d_pos]. now apply gball_pos, C.
-+ apply ball_eq. intros [d d_pos]. apply gball_pos.
- setoid_replace d with (e + d); [now apply C | rewrite e_zero; symmetry; apply plus_0_l].
-Qed.
-
-Lemma gball_closed_eq (x y : X) : (∀ d : Q, 0 < d -> gball d x y) -> x = y.
-Proof.
-intro C. change (gball 0 x y). apply gball_closed. intro d.
-setoid_replace (0 + d)%Q with d by apply plus_0_l. apply C.
-Qed.
-
Global Instance : ExtMetricSpaceClass X.
Proof.
constructor.
@@ -132,12 +70,12 @@ Lemma gball_complete (r : Q) (x y : Complete X) :
forall e1 e2 : Qpos, gball (QposAsQ e1 + r + QposAsQ e2)%mc (approximate x e1) (approximate y e2).
Proof.
destruct (Qsec.Qdec_sign r) as [[r_neg | r_pos] | r_zero].
-+ split; intro H; [elim (gball_neg _ _ _ _ r_neg H) |].
- assert (H1 : 0 < -(r / 3)) by (apply Q.Qopp_Qlt_0_l, Qmult_neg_pos; auto with qarith).
++ split; intro H; [elim (gball_neg _ _ r_neg H) |].
+ assert (H1 : 0 < -(r / 3)) by (apply Q.Qopp_Qlt_0_l, Q.Qmult_neg_pos; auto with qarith).
specialize (H (exist _ _ H1) (exist _ _ H1)); simpl in H.
mc_setoid_replace (- (r / 3) + r + - (r / 3)) with (r / 3) in H by (field; discriminate).
exfalso; eapply gball_neg; [| apply H]; now eapply Q.Qopp_Qlt_0_l.
-+ rewrite <- (gball_pos _ r_pos). simpl; unfold regFunBall. split; intros H e1 e2.
++ rewrite <- (gball_pos r_pos). simpl; unfold regFunBall. split; intros H e1 e2.
- specialize (H e1 e2). apply gball_pos in H. apply H.
- apply gball_pos, H.
+ rewrite r_zero. unfold gball at 1; simpl; unfold regFunEq. split; intros H e1 e2; specialize (H e1 e2).
@@ -165,7 +103,7 @@ assert (H : mspc_ball r a ((@proj1_sig _ _ ∘ f) ((1 # 2) * QposAsQ e2)%Q)) by
apply (proj2_sig (f ((1 # 2) * e2))).
unfold mspc_ball, msp_mspc_ball in H.
apply gball_weak_le with (q := QposAsQ e1 + r + (QposAsQ ((1 # 2) * e2)%Qpos)).
-+ apply Qplus_le_r. apply Qle_half; auto.
++ apply Qplus_le_r. apply Q.Qle_half; auto.
+ apply gball_complete, H.
Qed.
diff --git a/broken/metric.v b/broken/metric.v
index cbbc8394..e2a22bc7 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -14,9 +14,6 @@ Import Qround Qpower.
Set Printing Coercions.
-Lemma iff_not (P Q : Prop) : (P <-> Q) -> (not P <-> not Q).
-Proof. tauto. Qed.
-
Notation "x ²" := (x * x) (at level 30) : mc_scope.
Lemma po_proper' `{PartialOrder A} {x1 x2 y1 y2 : A} :
@@ -39,60 +36,6 @@ split; intro A.
- now rewrite A.
Qed.
-Lemma Zto_nat_nonpos (z : Z) : (z <= 0)%Z -> Z.to_nat z ≡ 0.
-Proof.
-intro A; destruct z as [| p | p]; trivial.
-unfold Z.le in A; now contradict A.
-Qed.
-
-Lemma le_Zle_to_nat_l (n : nat) (z : Z) : (Z.to_nat z <= n)%nat <-> (z <= Z.of_nat n)%Z.
-Proof.
-pose proof (le_0_n n). pose proof (Zle_0_nat n).
-destruct (Z.neg_nonneg_cases z).
-+ rewrite Zto_nat_nonpos by now apply Z.lt_le_incl. split; auto with zarith.
-+ split; intro A.
- - apply inj_le in A. rewrite Z2Nat.id in A; trivial.
- - apply Z2Nat.inj_le in A; trivial. rewrite Nat2Z.id in A; trivial.
-Qed.
-
-Lemma lt_Zlt_to_nat_r (n : nat) (z : Z) : (n < Z.to_nat z)%nat <-> (Z.of_nat n < z)%Z.
-Proof.
-assert (A : forall (m n : nat), not (m <= n)%nat <-> (n < m)%nat).
-+ intros; split; [apply not_le | apply gt_not_le].
-+ assert (A1 := le_Zle_to_nat_l n z). apply iff_not in A1.
- now rewrite A, Z.nle_gt in A1.
-Qed.
-
-(* Qlt_Qceiling is not used below *)
-Lemma Qlt_Qceiling (q : Q) : (Qceiling q < q + 1)%Q.
-Proof.
-apply Qplus_lt_l with (z := -1). setoid_replace (q + 1 + -1)%Q with q.
-+ assert (A := Qceiling_lt q). unfold Z.sub in A.
- now rewrite inject_Z_plus, inject_Z_opp in A.
-+ now rewrite <- Qplus_assoc, Qplus_opp_r, Qplus_0_r.
-Qed.
-
-Lemma Zle_Qle_Qceiling_l (q : Q) (z : Z) : (Qceiling q <= z)%Z <-> (q <= z)%Q.
-Proof.
-split; intro A.
-+ rewrite Zle_Qle in A. apply Qle_trans with (y := Qceiling q); [apply Qle_ceiling | trivial].
-+ apply Z.lt_pred_le. rewrite Zlt_Qlt. now apply Qlt_le_trans with (y := q); [apply Qceiling_lt |].
-Qed.
-
-Lemma le_Qle_Qceiling_Qceiling_to_nat_l (q : Q) (n : nat) : (Z.to_nat (Qceiling q) <= n)%nat <-> (q <= n)%Q.
-Proof. rewrite le_Zle_to_nat_l; apply Zle_Qle_Qceiling_l. Qed.
-
-Lemma Qlt_Zlt_inject_Z_l (q : Q) (z : Z) : (z < q)%Q <-> (z < Qceiling q)%Z.
-Proof.
-assert (A : forall (x y : Q), not (x <= y)%Q <-> (y < x)%Q).
-+ intros; split; [apply Qnot_le_lt | apply Qlt_not_le].
-+ assert (A1 := Zle_Qle_Qceiling_l q z). apply iff_not in A1.
- now rewrite A, Z.nle_gt in A1.
-Qed.
-
-Lemma Qlt_lt_of_nat_inject_Z_l (q : Q) (n : nat) : (n < q)%Q <-> (n < Z.to_nat (Qceiling q))%nat.
-Proof. rewrite (Qlt_Zlt_inject_Z_l q n); symmetry; apply lt_Zlt_to_nat_r. Qed.
-
Lemma neq_symm `{Ae : Equiv X} `{!Symmetric Ae} (x y : X) : x ≠ y -> y ≠ x.
Proof. intros A1 A2; apply A1; now symmetry. Qed.
diff --git a/metric2/Metric.v b/metric2/Metric.v
index 24d62aca..241bb556 100644
--- a/metric2/Metric.v
+++ b/metric2/Metric.v
@@ -302,4 +302,39 @@ Section gball.
rewrite <- C...
Qed.
+ Lemma gball_pos {e : Q} (e_pos : 0 < e) (x y : m) : ball (exist _ e e_pos) x y <-> gball e x y.
+ Proof.
+ unfold gball. destruct (Qsec.Qdec_sign e) as [[e_neg | e_pos'] | e_zero].
+ + elim (Qlt_irrefl _ (Qlt_trans _ _ _ e_pos e_neg)).
+ + setoid_replace (exist _ e e_pos) with (exist _ e e_pos'); easy.
+ + exfalso; rewrite e_zero in e_pos; apply (Qlt_irrefl _ e_pos).
+ Qed.
+
+ Lemma gball_neg (e : Q) (x y : m) : e < 0 -> ~ gball e x y.
+ Proof.
+ intro e_neg. unfold gball. destruct (Qsec.Qdec_sign e) as [[E | E] | E]; [easy | |].
+ + intros _; apply (Qlt_irrefl _ (Qlt_trans _ _ _ e_neg E)).
+ + rewrite E in e_neg. intros _; apply (Qlt_irrefl _ e_neg).
+ Qed.
+
+ Lemma gball_closed (e : Q) (x y : m) :
+ (forall d : Q, 0 < d -> gball (e + d) x y) -> gball e x y.
+ Proof.
+ intro C. (*change (gball e x y).*) unfold gball.
+ destruct (Qsec.Qdec_sign e) as [[e_neg | e_pos] | e_zero].
+ + assert (e / 2 < 0) by now apply Qmult_neg_pos.
+ apply (@gball_neg (e/2) x y); [easy |].
+ setoid_replace (e / 2) with (e - e / 2) by (field; discriminate).
+ apply C; now apply Qopp_Qlt_0_l.
+ + apply (msp_closed (msp m)). intros [d d_pos]. now apply gball_pos, C.
+ + apply ball_eq. intros [d d_pos]. apply gball_pos.
+ setoid_replace d with (e + d); [now apply C | rewrite e_zero; symmetry; apply Qplus_0_l].
+ Qed.
+
+ Lemma gball_closed_eq (x y : m) : (forall d : Q, 0 < d -> gball d x y) -> x [=] y.
+ Proof.
+ intro C. change (gball 0 x y). apply gball_closed. intro d.
+ setoid_replace (0 + d)%Q with d by apply Qplus_0_l. apply C.
+ Qed.
+
End gball.
diff --git a/model/metric2/Qmetric.v b/model/metric2/Qmetric.v
index 48b50c9b..d9f35a91 100644
--- a/model/metric2/Qmetric.v
+++ b/model/metric2/Qmetric.v
@@ -75,17 +75,6 @@ Qed.
Lemma Qball_Qabs : forall e a b, Qball e a b <-> Qabs (a - b) <= e.
Proof. split; apply AbsSmall_Qabs. Qed.
-Lemma gball_Qabs (e a b : Q) : gball e a b ↔ (Qabs (a - b) <= e).
-Proof.
-unfold gball. destruct (Qdec_sign e) as [[e_neg | e_pos] | e_zero].
-+ split; intros H; [easy |]. assert (H1 := Qle_lt_trans _ _ _ H e_neg).
- eapply Qle_not_lt; [apply Qabs_nonneg | apply H1].
-+ apply Qball_Qabs.
-+ split; intro H.
- - rewrite e_zero, H; setoid_replace (b - b) with 0 by ring; apply Qle_refl.
- - rewrite e_zero in H. apply Qabs_nonpos in H; now apply Qminus_eq.
-Qed.
-
Lemma Qle_closed : (forall e x, (forall d : Qpos, x <= e+d) -> x <= e).
Proof.
intros.
@@ -426,3 +415,15 @@ Proof.
apply Is_true_eq_left.
now apply sumbool_eq_true.
Qed.
+
+Lemma gball_Qabs (e a b : Q) : gball e a b <-> (Qabs (a - b) <= e).
+Proof.
+unfold gball. destruct (Qdec_sign e) as [[e_neg | e_pos] | e_zero].
++ split; intros H; [easy |]. assert (H1 := Qle_lt_trans _ _ _ H e_neg).
+ eapply Qle_not_lt; [apply Qabs_nonneg | apply H1].
++ apply Qball_Qabs.
++ split; intro H.
+ - rewrite e_zero, H; setoid_replace (b - b) with 0 by ring; apply Qle_refl.
+ - rewrite e_zero in H. apply Q.Qabs_nonpos in H; now apply Q.Qminus_eq.
+Qed.
+
diff --git a/reals/fast/CRabs.v b/reals/fast/CRabs.v
index 38efb0e8..62393ecf 100644
--- a/reals/fast/CRabs.v
+++ b/reals/fast/CRabs.v
@@ -223,3 +223,9 @@ Proof.
CRring_replace (x - y) (-(y - x)).
apply CRabs_opp.
Qed.
+
+Import canonical_names.
+
+Program Instance CR_abs : Abs CR := fun x => CRabs x.
+Next Obligation. split; [apply CRabs_pos | apply CRabs_neg]. Qed.
+
diff --git a/reals/fast/CRball.v b/reals/fast/CRball.v
index 9977e3c8..10ef4aa1 100644
--- a/reals/fast/CRball.v
+++ b/reals/fast/CRball.v
@@ -87,6 +87,9 @@ Proof with auto.
apply CRplus_le_compat...
Qed. (* todo: clean up *)
+Lemma gball_CRabs (r : Q) (x y : CR) : gball r x y <-> CRabs (x - y) <= ' r.
+Proof. rewrite rational. apply as_distance_bound. Qed.
+
Module notations.
Notation CRball := CRball.
diff --git a/stdlib_omissions/Q.v b/stdlib_omissions/Q.v
index 952a8e36..aa74f841 100644
--- a/stdlib_omissions/Q.v
+++ b/stdlib_omissions/Q.v
@@ -288,6 +288,28 @@ Proof with auto.
apply (Zmult_le_compat_l (Qnum y) 0 (Qnum x))...
Qed.
+Lemma Qmult_neg_pos (x y : Q) : x < 0 -> 0 < y -> x * y < 0.
+Proof.
+intros H1 H2.
+apply Qopp_Qlt_0_l. setoid_replace (- (x * y)) with ((- x) * y) by ring.
+apply Qmult_lt_0_compat; trivial. now apply Qopp_Qlt_0_l.
+Qed.
+
+Lemma Qmult_pos_neg (x y : Q) : 0 < x -> y < 0 -> x * y < 0.
+Proof. intros H1 H2. rewrite Qmult_comm. now apply Qmult_neg_pos. Qed.
+
+Lemma Qmult_pos_r : forall x y : Q, 0 <= x -> 0 < x * y -> 0 < y.
+Proof.
+intros x y H1 H2.
+destruct (Q_dec y 0) as [[? | ?] | H]; trivial.
++ exfalso. apply (Qlt_irrefl 0), Qlt_le_trans with (y := x * y); trivial.
+ now apply Qmult_nonneg_nonpos; [| apply Qlt_le_weak].
++ rewrite H, Qmult_0_r in H2. exfalso; now apply (Qlt_irrefl 0).
+Qed.
+
+Lemma Qmult_pos_l : forall x y : Q, 0 <= y -> 0 < x * y -> 0 < x.
+Proof. intros x y H1 H2. rewrite Qmult_comm in H2. now apply (Qmult_pos_r y x). Qed.
+
Lemma Qplus_lt_le_0_compat x y: 0 < x -> 0 <= y -> 0 < x + y.
Proof with auto.
unfold Qlt, Qle. simpl.
@@ -351,7 +373,7 @@ Qed.
Lemma Qabs_zero (x : Q) : Qabs x == 0 <-> x == 0.
Proof.
split; intro H; [| now rewrite H].
-destruct (Qdec_sign x) as [[x_neg | x_pos] | x_zero]; [| | trivial].
+destruct (Q_dec x 0) as [[x_neg | x_pos] | x_zero]; [| | trivial].
+ rewrite Qabs_neg in H; [| apply Qlt_le_weak; trivial].
now rewrite <- (Qopp_involutive x), H.
+ rewrite Qabs_pos in H; [| apply Qlt_le_weak]; trivial.
@@ -416,6 +438,11 @@ intros a b c A1 A2.
rewrite <- Qle_shift_div_l; [| easy]. rewrite (Qmult_comm b c). rewrite Qle_shift_div_l; easy.
Qed.
+Lemma Qle_half (x : Q) : 0 <= x -> (1 # 2) * x <= x.
+Proof.
+intro H. rewrite <- (Qmult_1_l x) at 2. apply Qmult_le_compat_r; auto with qarith.
+Qed.
+
Lemma nat_lt_Qlt n m: (n < m)%nat -> (inject_Z (Z_of_nat n) + (1#2) < inject_Z (Z_of_nat m))%Q.
Proof with intuition.
unfold lt.
@@ -447,6 +474,39 @@ Qed.
Hint Immediate positive_in_Q.
+SearchAbout (_ - ?x < _ - ?x)%Q.
+
+Lemma Qlt_Qceiling (q : Q) : inject_Z (Qceiling q) < q + 1.
+Proof.
+apply Qplus_lt_l with (z := (-1 # 1)). setoid_replace (q + 1 + (-1 # 1))%Q with q.
++ assert (A := Qceiling_lt q). unfold Z.sub in A.
+ now rewrite inject_Z_plus, inject_Z_opp in A.
++ now rewrite <- Qplus_assoc, Qplus_opp_r, Qplus_0_r.
+Qed.
+
+Lemma Zle_Qle_Qceiling (q : Q) (z : Z) : (Qceiling q <= z)%Z <-> q <= inject_Z z.
+Proof.
+split; intro A.
++ rewrite Zle_Qle in A. apply Qle_trans with (y := inject_Z (Qceiling q)); [apply Qle_ceiling | trivial].
++ apply Z.lt_pred_le. rewrite Zlt_Qlt. now apply Qlt_le_trans with (y := q); [apply Qceiling_lt |].
+Qed.
+
+Lemma le_Qle_Qceiling_to_nat (q : Q) (n : nat) :
+ (Z.to_nat (Qceiling q) <= n)%nat <-> q <= inject_Z (Z.of_nat n).
+Proof. rewrite Z.le_Zle_to_nat; apply Zle_Qle_Qceiling. Qed.
+
+Lemma Qlt_Zlt_inject_Z (q : Q) (z : Z) : inject_Z z < q <-> (z < Qceiling q)%Z.
+Proof.
+assert (A : forall (x y : Q), not (x <= y)%Q <-> (y < x)%Q).
++ intros; split; [apply Qnot_le_lt | apply Qlt_not_le].
++ assert (A1 := Zle_Qle_Qceiling q z). apply Z.iff_not in A1.
+ now rewrite A, Z.nle_gt in A1.
+Qed.
+
+Lemma Qlt_lt_of_nat_inject_Z (q : Q) (n : nat) :
+ inject_Z (Z.of_nat n) < q <-> (n < Z.to_nat (Qceiling q))%nat.
+Proof. rewrite (Qlt_Zlt_inject_Z q (Z.of_nat n)); apply Z.lt_Zlt_to_nat. Qed.
+
(** NoDup isn't /directly/ useful for Q because Q does not use a canonical representation
and NoDup doesn't support setoid equalities such as Qeq. However, since we have Qred,
which yields canonical representations, we can use: *)
diff --git a/stdlib_omissions/Z.v b/stdlib_omissions/Z.v
index fbb4f4b0..9f8efbb6 100644
--- a/stdlib_omissions/Z.v
+++ b/stdlib_omissions/Z.v
@@ -3,6 +3,9 @@ Require Import ZArith NPeano stdlib_omissions.P.
Open Scope Z_scope.
+Lemma iff_not (P Q : Prop) : (P <-> Q) -> (not P <-> not Q).
+Proof. tauto. Qed.
+
Definition nat_of_Z (x : Z) : nat :=
match x with
| Z0 => O
@@ -87,6 +90,12 @@ Proof.
reflexivity.
Qed.
+Lemma Zto_nat_nonpos (z : Z) : z <= 0 -> Z.to_nat z = 0%nat.
+Proof.
+intro A; destruct z as [| p | p]; trivial.
+unfold Z.le in A; now contradict A.
+Qed.
+
Lemma Ple_Zle (p q: positive): Ple p q <-> (Zpos p <= Zpos q).
Proof.
rewrite Ple_le, inj_le_iff.
@@ -94,7 +103,7 @@ Proof.
reflexivity.
Qed.
-Lemma Ple_Zle_to_pos_l (z : Z) (p : positive) : (Z.to_pos z <= p)%positive <-> (z <= p)%Z.
+Lemma Ple_Zle_to_pos (z : Z) (p : positive) : (Z.to_pos z <= p)%positive <-> z <= Zpos p.
Proof.
destruct z as [| q | q]; simpl.
+ split; intros _; [apply Zle_0_pos | apply Pos.le_1_l].
@@ -102,5 +111,24 @@ Proof.
+ split; intros _; [apply Zle_neg_pos | apply Pos.le_1_l].
Qed.
+Lemma le_Zle_to_nat (n : nat) (z : Z) : (Z.to_nat z <= n)%nat <-> z <= Z.of_nat n.
+Proof.
+pose proof (le_0_n n). pose proof (Zle_0_nat n).
+destruct (Z.neg_nonneg_cases z).
++ rewrite Zto_nat_nonpos by now apply Z.lt_le_incl. split; auto with zarith.
++ split; intro A.
+ - apply inj_le in A. rewrite Z2Nat.id in A; trivial.
+ - apply Z2Nat.inj_le in A; trivial. rewrite Nat2Z.id in A; trivial.
+Qed.
+
+Lemma lt_Zlt_to_nat (n : nat) (z : Z) : Z.of_nat n < z <-> (n < Z.to_nat z)%nat.
+Proof.
+assert (A : forall (m n : nat), not (m <= n)%nat <-> (n < m)%nat).
++ intros; split; [apply not_le | apply gt_not_le].
++ assert (A1 := le_Zle_to_nat n z). apply iff_not in A1.
+ now rewrite A, Z.nle_gt in A1.
+Qed.
+
Lemma add_pos_nonneg (a b: Z): 0 < a -> 0 <= b -> 0 < a+b.
Proof. intros. omega. Qed.
+
From 899ba666b3a1f17e7b500e789d1d28ccdea831d5 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Wed, 31 Oct 2012 21:58:28 +0100
Subject: [PATCH 029/110] Proving properties of Riemann sums
---
broken/AbstractIntegration.v | 113 +++++++++++++++++++++++++++++------
1 file changed, 96 insertions(+), 17 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 536f2ead..6590d474 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -87,6 +87,7 @@ SearchAbout cm_Sum.*)
(** If the elementwise distance between two summations over the same domain
is bounded, then so is the distance between the summations: *)
+(*
Lemma CRΣ_gball_ex (f g: nat -> CR) (e: QnnInf) (n: nat):
(forall m, (m < n)%nat -> gball_ex e (f m) (g m)) ->
(gball_ex (n * e)%QnnInf (cmΣ n f) (cmΣ n g)).
@@ -101,6 +102,19 @@ Proof with simpl; auto.
unfold cmΣ. simpl @cm_Sum.
apply CRgball_plus...
Qed.
+*)
+
+Lemma CRΣ_gball (f g: nat -> CR) (e : Q) (n : nat):
+ (forall m, (m < n)%nat -> gball e (f m) (g m)) ->
+ (gball (n * e) (cmΣ n f) (cmΣ n g)).
+Proof.
+ induction n; [reflexivity |].
+ intros.
+ rewrite Q.S_Qplus.
+ setoid_replace ((n+1) * e)%Q with (e + n * e)%Q by ring.
+ unfold cmΣ. simpl @cm_Sum.
+ apply CRgball_plus; auto.
+Qed.
Hint Immediate ball_refl Qle_refl.
@@ -365,14 +379,14 @@ Section integral_interface.
change (n * iw' == w)%Qnn in A.
rewrite <- A.
rewrite <- integral_repeated_additive.
- setoid_replace ((e * w)%Qpos: Q) with ((n * (iw' * e))%Qnn: Q) by
- (simpl in *; unfold QnonNeg.eq in A; simpl in A;
- unfold QposAsQ; rewrite Qmult_assoc; rewrite A; ring).
- apply (CRΣ_gball_ex _ _ (iw' * e)%Qnn).
+ setoid_replace (e * w)%Q with (n * (iw * e))%Q by
+ (unfold QnonNeg.eq in A; simpl in A;
+ rewrite Qmult_assoc; rewrite A; apply Qmult_comm).
+ apply CRΣ_gball.
intros m H.
rewrite CRmult_scale.
apply gball_sym. apply CRball.rational.
- setoid_replace (' (` iw' * ` e)) with (scale iw' (' (` e))) by now rewrite <- scale_Qmult.
+ setoid_replace (' (iw * e)) with (scale iw' (' ` e)) by now rewrite <- scale_Qmult.
apply integral_bounded; [apply CRnonNegQpos |].
intros x [A1 A2]. apply CRball.rational. apply (luc_gball a w (`iw')); trivial.
+ apply ball_gball, Qball_Qabs.
@@ -414,9 +428,16 @@ Section integral_interface.
(* Program Definition step (w : Qpos) (n : positive) : QnonNeg := exist _ (w * (1 # n)) _.
Next Obligation. Qauto_nonneg. Qed.*)
- Definition step (w : Qpos) (n : positive) : Q := w * (1 # n).
+ Definition step (w : Q) (n : positive) : Q := w * (1 # n).
+
+ Lemma step_mult (w : Q) (n : positive) : (n : Q) * step w n == w.
+ Proof.
+ unfold step.
+ rewrite Qmake_Qdiv. unfold Qdiv. rewrite Qmult_1_l, (Qmult_comm w), Qmult_assoc.
+ rewrite Qmult_inv_r, Qmult_1_l; [reflexivity | auto with qarith].
+ Qed.
- Definition riemann_sum (a : Q) (w : Qpos) (n : positive) :=
+ Definition riemann_sum (a : Q) (w : Q) (n : positive) :=
let iw := step w n in
cmΣ (Pos.to_nat n) (fun i => 'iw * f (a + i * iw))%CR.
@@ -498,7 +519,7 @@ Proof with auto.
apply (integral_wd f)...
Qed.
-Import canonical_names.
+Import abstract_algebra.
(* Should this lemma be used to CoRN.reals.fast.CRabs? That file does not use
type class notations from canonical_names like ≤ *)
@@ -509,22 +530,80 @@ apply -> CRabs_cases; [| apply _ | apply _].
split; [trivial | apply (proj1 (rings.flip_nonpos_negate x))].
Qed.
-(*Section RiemannSumBounds.
+Add Ring Q : (rings.stdlib_ring_theory CR).
+
+Section RiemannSumBounds.
+
+Lemma sum_empty (M : CMonoid) (f : nat -> M) : cmΣ 0 f = [0].
+Proof. reflexivity. Qed.
+
+Lemma sum_succ (M : CMonoid) (n : nat) (f : nat -> M) : cmΣ (S n) f = f n [+] cmΣ n f.
+Proof. reflexivity. Qed.
Context (f : Q -> CR).
-Lemma riemann_sum_const (a : Q) (w : Qpos) (m : CR) (n : positive) :
- riemann_sum (λ _, m) a w n = scale w m.
+Lemma sum_const (n : nat) (m : CR) : cmΣ n (λ _, m) = m * '(n : Q).
+Proof.
+induction n as [| n IH].
++ rewrite sum_empty. change (0 = m * 0). symmetry; apply rings.mult_0_r.
++ rewrite sum_succ, IH, S_Qplus, <- CRplus_Qplus.
+ change (m + m * '(n : Q) = m * ('(n : Q) + 1)). ring.
+Qed.
+
+Lemma mult_comm `{SemiRing R} : Commutative (.*.).
+Proof. apply commonoid_commutative with (Aunit := one), _. Qed.
+
+Lemma mult_assoc `{SemiRing R} (x y z : R) : x * (y * z) = x * y * z.
+Proof. apply sg_ass, _. Qed.
+
+Lemma riemann_sum_const (a : Q) (w : Q) (m : CR) (n : positive) :
+ riemann_sum (λ _, m) a w n = 'w * m.
+Proof.
+unfold riemann_sum. rewrite sum_const, positive_nat_Z.
+change ('step w n * m * '(n : Q) = 'w * m).
+rewrite (mult_comm _ ('(n : Q))), mult_assoc, CRmult_Qmult, step_mult; reflexivity.
+Qed.
+
+Require Import CRtrans ARtrans. (* This is almost all CoRN *)
+(*SearchAbout "ball" "mult".
+
+Qball_Qmult_Q_r:
+ ∀ (d : Qpos) (z x y : Q),
+ Qball (d / QabsQpos z) x y → Qball d (x * z) (y * z)
+Qball_Qmult_Q_l:
+ ∀ (d : Qpos) (z x y : Q),
+ Qball (d / QabsQpos z) x y → Qball d (z * x) (z * y)
+Qball_Qmult_r:
+ ∀ (d z : Qpos) (x y : Q), Qball (d / z) x y → Qball d (x * z) (y * z)
+Qball_Qmult_l:
+ ∀ (d z : Qpos) (x y : Q), Qball (d / z) x y → Qball d (z * x) (z * y)*)
+
+SearchAbout "stable".
+SearchAbout CRabs scale.
+
+Lemma gball_mult (e a : Q) (x y : CR) :
+ gball e x y -> gball (Qabs a * e) ('a * x) ('a * y).
Proof.
+SearchAbout gball.
+SearchAbout CRabs Qabs.
+SearchAbout (abs _ * abs _)%mc.
-SearchAbout cm_Sum.
+CR_abs_obligation_1:
+ ∀ x : CR, (0 ≤ x → CRabs x = x) ∧ (x ≤ 0 → CRabs x = - x)
+CRball.gball_CRabs:
+ ∀ (r : Q) (x y : CR), gball r x y ↔ CRabs (x - y)%CR <= (' r)%CR
+in_CRgball:
+ ∀ (r : Q) (x y : CR), (x - ' r)%CR <= y ∧ y <= (x + ' r)%CR ↔ gball r x y
-Lemma riemann_sum_bounds (a : Q) (w : Qpos) (m : CR) (e : Q) (n : positive) :
- (forall (x : Q), (a ≤ x ≤ a + w) -> gball e (f x) m) ->
- gball (w * e) (riemann_sum f a w n) (scale w m).
+Lemma riemann_sum_bounds (a w : Q) (m : CR) (e : Q) (n : positive) :
+ 0 ≤ w -> (forall (x : Q), (a ≤ x ≤ a + w) -> gball e (f x) m) ->
+ gball (w * e) (riemann_sum f a w n) ('w * m).
Proof.
-intro A.
+intros w_nn A. rewrite <- (riemann_sum_const a w m n). unfold riemann_sum.
+rewrite <- (step_mult w n), <- (Qmult_assoc n _ e), <- (positive_nat_Z n).
+apply CRΣ_gball. intros k A1.
+SearchAbout (ball (_ * _) _ _).
@@ -533,7 +612,7 @@ intro A.
End RiemannSumBounds.
-*)
+
Section IntegralBound.
From 835f55ebb21dfb6703543828f3eaaaf469e664ba Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 1 Nov 2012 18:59:21 +0100
Subject: [PATCH 030/110] Proved that uniformly continuous functions from R to
R are determined by their values on rational numbers
---
broken/AbstractIntegration.v | 86 +++++++++++++++++++++---------------
1 file changed, 51 insertions(+), 35 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 6590d474..ecaef230 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -14,7 +14,7 @@ Require Import metric FromMetric2.
Require Qinf QnonNeg QnnInf CRball.
Import Qinf.notations QnonNeg.notations QnnInf.notations CRball.notations Qabs.
-(*Require Import CRtrans ARtrans.*) (* This is almost all CoRN *)
+Require CRtrans ARtrans. (* This is almost all CoRN *)
(*Notation Qinf := Qinf.T.
@@ -46,7 +46,51 @@ Open Local Scope Q_scope.
Open Local Scope uc_scope.
Open Local Scope CR_scope.
-SearchAbout CRnonNeg.
+Lemma lift_eq_complete (X Y : MetricSpace) (f g : Complete X --> Complete Y) :
+ (forall x : X, f (Cunit x) [=] g (Cunit x)) -> (forall x : Complete X, f x [=] g x).
+Proof.
+intros A x. apply ball_eq; intro e.
+set (e2 := ((1#2) * e)%Qpos).
+set (d := QposInf_min (mu f e2) (mu g e2)).
+setoid_replace e with (e2 + e2)%Qpos by (subst e2; QposRing).
+apply ball_triangle with (b := f (Cunit (approximate x d))).
++ apply (UniformContinuity.uc_prf f).
+ apply (ball_ex_weak_le _ d); [apply QposInf_min_lb_l | apply ball_ex_approx_r].
++ rewrite A. apply (UniformContinuity.uc_prf g).
+ apply (ball_ex_weak_le _ d); [apply QposInf_min_lb_r | apply ball_ex_approx_l].
+Qed.
+
+Lemma CRabs_scale (a : Q) (x : CR) : CRabs (scale a x) == scale (Qabs a) (CRabs x).
+Proof.
+apply lift_eq_complete with (f := uc_compose CRabs (scale a)) (g := uc_compose (scale (Qabs a)) CRabs).
+intros q e1 e2. change (ball (e1 + e2) (Qabs (a * q)) (Qabs a * Qabs q)%Q).
+apply <- ball_eq_iff. apply Qabs_Qmult.
+Qed.
+
+(*Lemma CRabs_scale' (a : Q) (x : CR) : CRabs (scale a x) == scale (Qabs a) (CRabs x).
+Proof.
+unfold CRabs, scale.
+setoid_rewrite <- fast_MonadLaw2.*)
+
+Corollary CRabs_CRmult_Q (a : Q) (x : CR) : CRabs ('a * x) == '(Qabs a) * (CRabs x).
+Proof. rewrite !CRmult_scale. apply CRabs_scale. Qed.
+
+Lemma gball_CRmult_Q (e a : Q) (x y : CR) :
+ gball e x y -> gball (Qabs a * e) ('a * x) ('a * y).
+Proof.
+intro A. apply CRball.gball_CRabs.
+setoid_replace ('a * x - 'a * y) with ('a * (x - y)) by ring.
+rewrite CRabs_CRmult_Q, <- CRmult_Qmult.
+assert (0 <= 'Qabs a) by (apply CRle_Qle; auto).
+apply (orders.order_preserving (CRmult (' Qabs a))).
+now apply CRball.gball_CRabs.
+Qed.
+
+Corollary gball_CRmult_Q_nonneg (e a : Q) (x y : CR) :
+ (0 <= a)%Q -> gball e x y -> gball (a * e) ('a * x) ('a * y).
+Proof.
+intros A1 A2. rewrite <- (Qabs_pos a) at 1; [apply gball_CRmult_Q |]; easy.
+Qed.
(** Any nonnegative width can be split up into an integral number of
equal-sized pieces no bigger than a given bound: *)
@@ -430,6 +474,9 @@ Section integral_interface.
Definition step (w : Q) (n : positive) : Q := w * (1 # n).
+ Lemma step_nonneg (w : Q) (n : positive) : 0 <= w -> 0 <= step w n.
+ Proof. intros w_nn; unfold step; Qauto_nonneg. Qed.
+
Lemma step_mult (w : Q) (n : positive) : (n : Q) * step w n == w.
Proof.
unfold step.
@@ -564,45 +611,14 @@ change ('step w n * m * '(n : Q) = 'w * m).
rewrite (mult_comm _ ('(n : Q))), mult_assoc, CRmult_Qmult, step_mult; reflexivity.
Qed.
-Require Import CRtrans ARtrans. (* This is almost all CoRN *)
-(*SearchAbout "ball" "mult".
-
-Qball_Qmult_Q_r:
- ∀ (d : Qpos) (z x y : Q),
- Qball (d / QabsQpos z) x y → Qball d (x * z) (y * z)
-Qball_Qmult_Q_l:
- ∀ (d : Qpos) (z x y : Q),
- Qball (d / QabsQpos z) x y → Qball d (z * x) (z * y)
-Qball_Qmult_r:
- ∀ (d z : Qpos) (x y : Q), Qball (d / z) x y → Qball d (x * z) (y * z)
-Qball_Qmult_l:
- ∀ (d z : Qpos) (x y : Q), Qball (d / z) x y → Qball d (z * x) (z * y)*)
-
-SearchAbout "stable".
-SearchAbout CRabs scale.
-
-Lemma gball_mult (e a : Q) (x y : CR) :
- gball e x y -> gball (Qabs a * e) ('a * x) ('a * y).
-Proof.
-SearchAbout gball.
-SearchAbout CRabs Qabs.
-SearchAbout (abs _ * abs _)%mc.
-
-CR_abs_obligation_1:
- ∀ x : CR, (0 ≤ x → CRabs x = x) ∧ (x ≤ 0 → CRabs x = - x)
-CRball.gball_CRabs:
- ∀ (r : Q) (x y : CR), gball r x y ↔ CRabs (x - y)%CR <= (' r)%CR
-in_CRgball:
- ∀ (r : Q) (x y : CR), (x - ' r)%CR <= y ∧ y <= (x + ' r)%CR ↔ gball r x y
-
-
Lemma riemann_sum_bounds (a w : Q) (m : CR) (e : Q) (n : positive) :
0 ≤ w -> (forall (x : Q), (a ≤ x ≤ a + w) -> gball e (f x) m) ->
gball (w * e) (riemann_sum f a w n) ('w * m).
Proof.
intros w_nn A. rewrite <- (riemann_sum_const a w m n). unfold riemann_sum.
rewrite <- (step_mult w n), <- (Qmult_assoc n _ e), <- (positive_nat_Z n).
-apply CRΣ_gball. intros k A1.
+apply CRΣ_gball. intros k A1. apply gball_CRmult_Q_nonneg; [now apply step_nonneg |].
+apply A.
SearchAbout (ball (_ * _) _ _).
From 027d4ae0b0d2a3491cb961767739fca317fb3ce7 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 2 Nov 2012 19:27:19 +0100
Subject: [PATCH 031/110] Proving that the sum of two integrable functions is
integrable
---
broken/AbstractIntegration.v | 114 ++++++++++++++++++++++++++---------
1 file changed, 87 insertions(+), 27 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index ecaef230..2ffff5a9 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -16,6 +16,13 @@ Import Qinf.notations QnonNeg.notations QnnInf.notations CRball.notations Qabs.
Require CRtrans ARtrans. (* This is almost all CoRN *)
+Ltac done :=
+ trivial; hnf; intros; solve
+ [ repeat (first [solve [trivial | apply: sym_equal; trivial]
+ | discriminate | contradiction | split])
+(* | case not_locked_false_eq_true; assumption*)
+ | match goal with H : ~ _ |- _ => solve [case H; trivial] end ].
+
(*Notation Qinf := Qinf.T.
Module Qinf.
@@ -46,7 +53,7 @@ Open Local Scope Q_scope.
Open Local Scope uc_scope.
Open Local Scope CR_scope.
-Lemma lift_eq_complete (X Y : MetricSpace) (f g : Complete X --> Complete Y) :
+Lemma lift_eq_complete {X Y : MetricSpace} (f g : Complete X --> Complete Y) :
(forall x : X, f (Cunit x) [=] g (Cunit x)) -> (forall x : Complete X, f x [=] g x).
Proof.
intros A x. apply ball_eq; intro e.
@@ -60,6 +67,15 @@ apply ball_triangle with (b := f (Cunit (approximate x d))).
apply (ball_ex_weak_le _ d); [apply QposInf_min_lb_r | apply ball_ex_approx_l].
Qed.
+(* [SearchAbout ((Cmap _ _) (Cunit _)).] does not find anything, but it
+should find metric2.Prelength.fast_MonadLaw3 *)
+
+Corollary map_eq_complete {X Y : MetricSpace} {plX : PrelengthSpace X} (f g : X --> Y) :
+ (forall x : X, f x [=] g x) -> (forall x : Complete X, Cmap plX f x [=] Cmap plX g x).
+Proof.
+intros A x. apply lift_eq_complete. intro y. rewrite !fast_MonadLaw3, A. reflexivity.
+Qed.
+
Lemma CRabs_scale (a : Q) (x : CR) : CRabs (scale a x) == scale (Qabs a) (CRabs x).
Proof.
apply lift_eq_complete with (f := uc_compose CRabs (scale a)) (g := uc_compose (scale (Qabs a)) CRabs).
@@ -67,10 +83,13 @@ intros q e1 e2. change (ball (e1 + e2) (Qabs (a * q)) (Qabs a * Qabs q)%Q).
apply <- ball_eq_iff. apply Qabs_Qmult.
Qed.
-(*Lemma CRabs_scale' (a : Q) (x : CR) : CRabs (scale a x) == scale (Qabs a) (CRabs x).
+(* Another proof *)
+
+Lemma CRabs_scale' (a : Q) (x : CR) : CRabs (scale a x) == scale (Qabs a) (CRabs x).
Proof.
-unfold CRabs, scale.
-setoid_rewrite <- fast_MonadLaw2.*)
+unfold CRabs, scale. setoid_rewrite <- fast_MonadLaw2.
+apply map_eq_complete. intro q. apply Qabs_Qmult.
+Qed.
Corollary CRabs_CRmult_Q (a : Q) (x : CR) : CRabs ('a * x) == '(Qabs a) * (CRabs x).
Proof. rewrite !CRmult_scale. apply CRabs_scale. Qed.
@@ -568,6 +587,12 @@ Qed.
Import abstract_algebra.
+Lemma mult_comm `{SemiRing R} : Commutative (.*.).
+Proof. apply commonoid_commutative with (Aunit := one), _. Qed.
+
+Lemma mult_assoc `{SemiRing R} (x y z : R) : x * (y * z) = x * y * z.
+Proof. apply sg_ass, _. Qed.
+
(* Should this lemma be used to CoRN.reals.fast.CRabs? That file does not use
type class notations from canonical_names like ≤ *)
@@ -577,59 +602,94 @@ apply -> CRabs_cases; [| apply _ | apply _].
split; [trivial | apply (proj1 (rings.flip_nonpos_negate x))].
Qed.
-Add Ring Q : (rings.stdlib_ring_theory CR).
+Add Ring CR_ring : (rings.stdlib_ring_theory CR).
-Section RiemannSumBounds.
+Notation "f +1 g" := (λ x, f x + g x) (at level 50, left associativity).
-Lemma sum_empty (M : CMonoid) (f : nat -> M) : cmΣ 0 f = [0].
+Lemma cmΣ_empty {M : CMonoid} (f : nat -> M) : cmΣ 0 f = [0].
Proof. reflexivity. Qed.
-Lemma sum_succ (M : CMonoid) (n : nat) (f : nat -> M) : cmΣ (S n) f = f n [+] cmΣ n f.
+Lemma cmΣ_succ {M : CMonoid} (n : nat) (f : nat -> M) : cmΣ (S n) f = f n [+] cmΣ n f.
Proof. reflexivity. Qed.
-Context (f : Q -> CR).
+Lemma cmΣ_plus (n : nat) (f g : nat -> CR) : cmΣ n (f +1 g) = cmΣ n f + cmΣ n g.
+Proof.
+induction n as [| n IH].
++ symmetry; apply cm_rht_unit.
++ rewrite !cmΣ_succ. rewrite IH.
+ change (f n + g n + (cmΣ n f + cmΣ n g) = f n + cmΣ n f + (g n + cmΣ n g)).
+ change (CRasCMonoid : Type) with (CR : Type). ring.
+Qed.
-Lemma sum_const (n : nat) (m : CR) : cmΣ n (λ _, m) = m * '(n : Q).
+Lemma cmΣ_const (n : nat) (m : CR) : cmΣ n (λ _, m) = m * '(n : Q).
Proof.
induction n as [| n IH].
-+ rewrite sum_empty. change (0 = m * 0). symmetry; apply rings.mult_0_r.
-+ rewrite sum_succ, IH, S_Qplus, <- CRplus_Qplus.
++ rewrite cmΣ_empty. change (0 = m * 0). symmetry; apply rings.mult_0_r.
++ rewrite cmΣ_succ, IH, S_Qplus, <- CRplus_Qplus.
change (m + m * '(n : Q) = m * ('(n : Q) + 1)). ring.
Qed.
-Lemma mult_comm `{SemiRing R} : Commutative (.*.).
-Proof. apply commonoid_commutative with (Aunit := one), _. Qed.
-
-Lemma mult_assoc `{SemiRing R} (x y z : R) : x * (y * z) = x * y * z.
-Proof. apply sg_ass, _. Qed.
-
Lemma riemann_sum_const (a : Q) (w : Q) (m : CR) (n : positive) :
riemann_sum (λ _, m) a w n = 'w * m.
Proof.
-unfold riemann_sum. rewrite sum_const, positive_nat_Z.
+unfold riemann_sum. rewrite cmΣ_const, positive_nat_Z.
change ('step w n * m * '(n : Q) = 'w * m).
rewrite (mult_comm _ ('(n : Q))), mult_assoc, CRmult_Qmult, step_mult; reflexivity.
Qed.
-Lemma riemann_sum_bounds (a w : Q) (m : CR) (e : Q) (n : positive) :
- 0 ≤ w -> (forall (x : Q), (a ≤ x ≤ a + w) -> gball e (f x) m) ->
- gball (w * e) (riemann_sum f a w n) ('w * m).
+Lemma riemann_sum_plus (f g : Q -> CR) (a w : Q) (n : positive) :
+ riemann_sum (f +1 g) a w n = riemann_sum f a w n + riemann_sum g a w n.
Proof.
-intros w_nn A. rewrite <- (riemann_sum_const a w m n). unfold riemann_sum.
-rewrite <- (step_mult w n), <- (Qmult_assoc n _ e), <- (positive_nat_Z n).
-apply CRΣ_gball. intros k A1. apply gball_CRmult_Q_nonneg; [now apply step_nonneg |].
-apply A.
-SearchAbout (ball (_ * _) _ _).
+unfold riemann_sum. rewrite <- cmΣ_plus. apply cm_Sum_eq. intro k.
+rapply mult_assoc.
+SearchAbout "ass" CR.
+SearchAbout (?x * (_ + _) == ?x * _ + ?x * _)%CR.
+change (
+ cast Q CR (step w n) * (f (a + k * step w n) + g (a + k * step w n)) =
+ cast Q CR (step w n) * f (a + k * step w n) + cast Q CR (step w n) * g (a + k * step w n)).
+SearchAbout cm_Sum.
+
+
+
+SearchAbout cmΣ.
+
+Section RiemannSumBounds.
+Context (f : Q -> CR).
+Global Instance Qle_nat (n : nat) : PropHolds (0 ≤ (n : Q)).
+Proof. apply Qle_nat. Qed.
+Instance step_nonneg' (w : Q) (n : positive) : PropHolds (0 ≤ w) -> PropHolds (0 ≤ step w n).
+Proof. apply step_nonneg. Qed.
+Lemma index_inside_l (a w : Q) (k : nat) (n : positive) :
+ 0 ≤ w -> k < Pos.to_nat n -> a ≤ a + (k : Q) * step w n.
+Proof. intros; apply semirings.nonneg_plus_le_compat_r; solve_propholds. Qed.
+Lemma index_inside_r (a w : Q) (k : nat) (n : positive) :
+ 0 ≤ w -> k < Pos.to_nat n -> a + (k : Q) * step w n ≤ a + w.
+Proof.
+intros A1 A2. apply (orders.order_preserving (a +)).
+mc_setoid_replace w with ((n : Q) * (step w n)) at 2 by (symmetry; apply step_mult).
+apply (orders.order_preserving (.* step w n)).
+rewrite <- Zle_Qle, <- positive_nat_Z. apply inj_le. change (k ≤ Pos.to_nat n). solve_propholds.
+Qed.
+Lemma riemann_sum_bounds (a w : Q) (m : CR) (e : Q) (n : positive) :
+ 0 ≤ w -> (forall (x : Q), (a ≤ x ≤ a + w) -> gball e (f x) m) ->
+ gball (w * e) (riemann_sum f a w n) ('w * m).
+Proof.
+intros w_nn A. rewrite <- (riemann_sum_const a w m n). unfold riemann_sum.
+rewrite <- (step_mult w n), <- (Qmult_assoc n _ e), <- (positive_nat_Z n).
+apply CRΣ_gball. intros k A1. apply gball_CRmult_Q_nonneg; [now apply step_nonneg |].
+apply A. split; [apply index_inside_l | apply index_inside_r]; trivial.
+Qed.
End RiemannSumBounds.
+
Section IntegralBound.
Context (f : Q -> CR) `{Integrable f}.
From 1c1b567c61690e14df8bea4d12380a6c915f0dcd Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Mon, 5 Nov 2012 14:10:37 +0100
Subject: [PATCH 032/110] Update math-classes submodule.
---
.gitmodules | 2 +-
math-classes | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/.gitmodules b/.gitmodules
index 120767e1..8d0e97bb 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,3 @@
[submodule "math-classes"]
path = math-classes
- url = git://github.com/robbertkrebbers/math-classes.git
+ url = git://github.com/EvgenyMakarov/math-classes.git
diff --git a/math-classes b/math-classes
index 9b9625e1..bc501547 160000
--- a/math-classes
+++ b/math-classes
@@ -1 +1 @@
-Subproject commit 9b9625e1fec07206a5ce0dcaa8b8f0e708fe25bd
+Subproject commit bc5015474dba2a2e6a571a1d84a472ed8d56221b
From f15aec7b589fad5bbfb856c3203156fadf8a383e Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 6 Nov 2012 19:29:50 +0100
Subject: [PATCH 033/110] Proved that the sum of two locally uniformly
continuous integrable functions is integrable
---
broken/AbstractIntegration.v | 62 ++++++++++++++++++++++++++----------
1 file changed, 45 insertions(+), 17 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 2ffff5a9..c830dd34 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -641,17 +641,11 @@ Lemma riemann_sum_plus (f g : Q -> CR) (a w : Q) (n : positive) :
riemann_sum (f +1 g) a w n = riemann_sum f a w n + riemann_sum g a w n.
Proof.
unfold riemann_sum. rewrite <- cmΣ_plus. apply cm_Sum_eq. intro k.
-rapply mult_assoc.
-SearchAbout "ass" CR.
-SearchAbout (?x * (_ + _) == ?x * _ + ?x * _)%CR.
change (
- cast Q CR (step w n) * (f (a + k * step w n) + g (a + k * step w n)) =
- cast Q CR (step w n) * f (a + k * step w n) + cast Q CR (step w n) * g (a + k * step w n)).
-SearchAbout cm_Sum.
-
-
-
-SearchAbout cmΣ.
+ cast Q CR (step w n) * (f (a + (k : Q) * step w n) + g (a + (k : Q) * step w n)) =
+ cast Q CR (step w n) * f (a + (k : Q) * step w n) + cast Q CR (step w n) * g (a + (k : Q) * step w n)).
+apply rings.plus_mult_distr_l.
+Qed.
Section RiemannSumBounds.
@@ -688,8 +682,6 @@ Qed.
End RiemannSumBounds.
-
-
Section IntegralBound.
Context (f : Q -> CR) `{Integrable f}.
@@ -717,20 +709,56 @@ assert (A1 : 0 ≤ M).
rewrite rings.minus_0_r; now apply A.
Qed.
+End IntegralBound.
-(*
Section IntegralOfSum.
-Context (f g : Q -> CR) `{Integral f, !Integrable f} `{Integral g, !Integrable g}.
+Context (f g : Q -> CR)
+ `{!IsLocallyUniformlyContinuous f f_mu, !IsLocallyUniformlyContinuous g g_mu}
+ `{Integral f, !Integrable f, Integral g, !Integrable g}.
-Notation "f +1 g" := (λ x, f x + g x) (at level 50, left associativity).
+Global Instance integrate_sum : Integral (f +1 g) := λ a w, integrate f a w + integrate g a w.
-Theorem integral_sum (a : Q) (w : Qpos) : ∫ (f +1 g) a w = ∫ f a w + ∫ g a w.
-*)
+Lemma integral_sum_additive (a : Q) (b c : QnonNeg) :
+ ∫ (f +1 g) a b + ∫ (f +1 g) (a + ` b) c = ∫ (f +1 g) a (b + c)%Qnn.
+Proof.
+unfold integrate, integrate_sum.
+rewrite <- !integral_additive; trivial.
+change (
+ ∫ f a b + ∫ g a b + (∫ f (a + ` b) c + ∫ g (a + ` b) c) =
+ (∫ f a b + ∫ f (a + ` b) c) + (∫ g a b + ∫ g (a + ` b) c)). ring.
+Qed.
+(* When the last argument of ball is ('(width * mid)), typechecking diverges *)
+Lemma integral_sum_integrable (from : Q) (width : Qpos) (mid : Q) (r : Qpos) :
+ (∀ x : Q, from ≤ x ≤ from + width → ball r (f x + g x) ('mid))
+ → ball (width * r) (∫ (f +1 g) from width) ('((width : Q) * mid)).
+Proof.
+intros A. apply ball_gball; simpl. apply gball_closed. intros e e_pos.
+setoid_replace (width * r + e)%Q with (e + width * r)%Q by apply Qplus_comm.
+destruct (Riemann_sums_approximate_integral'' f from width ((1#2) * mkQpos e_pos)%Qpos) as [Nf F].
+destruct (Riemann_sums_approximate_integral'' g from width ((1#2) * mkQpos e_pos)%Qpos) as [Ng G].
+set (n := Pos.max Nf Ng).
+assert (le_Nf_n : (Nf <= n)%positive) by apply Pos.le_max_l.
+assert (le_Ng_n : (Ng <= n)%positive) by apply Pos.le_max_r.
+specialize (F n le_Nf_n). specialize (G n le_Ng_n).
+apply gball_triangle with (b := riemann_sum (f +1 g) from width n).
++ rewrite riemann_sum_plus. setoid_replace e with ((1#2) * e + (1#2) * e)%Q by ring.
+ apply CRgball_plus; apply gball_sym; trivial.
++ (* apply riemann_sum_bounds. diverges *)
+ rewrite <- CRmult_Qmult. apply riemann_sum_bounds; [solve_propholds |].
+ intros. apply ball_gball. apply A; trivial.
+Qed.
+Global Instance : Integrable (f +1 g).
+constructor.
++ apply integral_sum_additive.
++ apply integral_sum_integrable.
++ intros a1 a2 A1 w1 w2 A2. unfold integrate, integrate_sum. rewrite A1, A2; reflexivity.
+Qed.
+End IntegralOfSum.
(*
From a9aeb4f4bb5712849eb6d770b920de4648966ee3 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Wed, 7 Nov 2012 21:52:03 +0100
Subject: [PATCH 034/110] Started adapting SimpleIntegration.v to metric.v
instead of Classified.v
---
broken/AbstractIntegration.v | 121 ++++++++++++++++++-----------------
broken/SimpleIntegration.v | 56 +++++++++++-----
broken/metric.v | 99 ++++++++++++++++------------
3 files changed, 159 insertions(+), 117 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index c830dd34..82ada5b3 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -585,6 +585,66 @@ Proof with auto.
apply (integral_wd f)...
Qed.
+(** Finally, we offer a smart constructor for implementations that would need to recognize and
+ treat the zero-width case specially anyway (which is the case for the implementation
+with Riemann sums, because there, a positive width is needed to divide the error by). *)
+
+Section extension_to_nn_width.
+
+ Context
+ (f: Q → CR)
+ (pre_integral: Q → Qpos → CR) (* Note the Qpos instead of QnonNeg. *)
+ (* The three properties limited to pre_integral: *)
+ (pre_additive: forall (a: Q) (b c: Qpos),
+ pre_integral a b + pre_integral (a + `b)%Q c[=]pre_integral a (b + c)%Qpos)
+ (pre_bounded: forall (from: Q) (width: Qpos) (mid: Q) (r: Qpos),
+ (forall x: Q, from <= x <= from + width -> ball r (f x) (' mid)) ->
+ ball (width * r) (pre_integral from width) (' (width * mid)%Q))
+ {pre_wd: Proper (Qeq ==> QposEq ==> @st_eq _) pre_integral}.
+
+ Instance integral_extended_to_nn_width: Integral f :=
+ fun from => QnonNeg.rect (fun _ => CR)
+ (fun _ _ => '0%Q)
+ (fun n d _ => pre_integral from (QposMake n d)).
+
+ Let proper: Proper (Qeq ==> QnonNeg.eq ==> @st_eq _) (∫ f).
+ Proof with auto.
+ intros ?????.
+ induction x0 using QnonNeg.rect;
+ induction y0 using QnonNeg.rect.
+ reflexivity.
+ discriminate.
+ discriminate.
+ intros. apply pre_wd...
+ Qed.
+
+ Let bounded (from: Q) (width: Qpos) (mid: Q) (r: Qpos):
+ (forall x, from <= x <= from + width -> ball r (f x) (' mid)) ->
+ ball (width * r) (∫ f from width) (' (width * mid)%Q).
+ Proof.
+ induction width using Qpos_positive_numerator_rect.
+ apply (pre_bounded from (a#b) mid r).
+ Qed.
+
+ Let additive (a: Q) (b c: QnonNeg): ∫ f a b + ∫ f (a + `b)%Q c == ∫ f a (b + c)%Qnn.
+ Proof.
+ unfold integrate.
+ induction b using QnonNeg.rect;
+ induction c using QnonNeg.rect; simpl integral_extended_to_nn_width; intros.
+ ring.
+ rewrite CRplus_0_l.
+ apply pre_wd; unfold QposEq, Qeq; simpl; repeat rewrite Zpos_mult_morphism; ring.
+ rewrite CRplus_0_r.
+ apply pre_wd; unfold QposEq, Qeq; simpl; repeat rewrite Zpos_mult_morphism; ring.
+ rewrite (pre_additive a (QposMake n d) (QposMake n0 d0)).
+ apply pre_wd; reflexivity.
+ Qed.
+
+ Lemma integral_extended_to_nn_width_correct: Integrable f.
+ Proof. constructor; auto. Qed.
+
+End extension_to_nn_width.
+
Import abstract_algebra.
Lemma mult_comm `{SemiRing R} : Commutative (.*.).
@@ -779,64 +839,5 @@ Proof with try assumption.
apply (unique g)...
apply (Integrable_proper_l f)...
Qed.
-
-(** Finally, we offer a smart constructor for implementations that would need to recognize and
- treat the zero-width case specially anyway (which is the case for the implementation
-with Riemann sums, because there, a positive width is needed to divide the error by). *)
-
-Section extension_to_nn_width.
-
- Context
- (f: Q → CR)
- (pre_integral: Q → Qpos → CR) (* Note the Qpos instead of QnonNeg. *)
- (* The three properties limited to pre_integral: *)
- (pre_additive: forall (a: Q) (b c: Qpos),
- pre_integral a b + pre_integral (a + `b)%Q c[=]pre_integral a (b + c)%Qpos)
- (pre_bounded: forall (from: Q) (width: Qpos) (mid: Q) (r: Qpos),
- (forall x: Q, from <= x <= from + width -> ball r (f x) (' mid)) ->
- ball (width * r) (pre_integral from width) (' (width * mid)))
- {pre_wd: Proper (Qeq ==> QposEq ==> @st_eq _) pre_integral}.
-
- Instance integral_extended_to_nn_width: Integral f :=
- fun from => QnonNeg.rect (fun _ => CR)
- (fun _ _ => '0)
- (fun n d _ => pre_integral from (QposMake n d)).
-
- Let proper: Proper (Qeq ==> QnonNeg.eq ==> @st_eq _) (∫ f).
- Proof with auto.
- intros ?????.
- induction x0 using QnonNeg.rect;
- induction y0 using QnonNeg.rect.
- reflexivity.
- discriminate.
- discriminate.
- intros. apply pre_wd...
- Qed.
-
- Let bounded (from: Q) (width: Qpos) (mid: Q) (r: Qpos):
- (forall x, from <= x <= from + width -> ball r (f x) (' mid)) ->
- ball (width * r) (∫ f from width) (' (width * mid)).
- Proof.
- induction width using Qpos_positive_numerator_rect.
- apply (pre_bounded from (a#b) mid r).
- Qed.
-
- Let additive (a: Q) (b c: QnonNeg): ∫ f a b + ∫ f (a + `b)%Q c == ∫ f a (b + c)%Qnn.
- Proof.
- unfold integrate.
- induction b using QnonNeg.rect;
- induction c using QnonNeg.rect; simpl integral_extended_to_nn_width; intros.
- ring.
- rewrite CRplus_0_l.
- apply pre_wd; unfold QposEq, Qeq; simpl; repeat rewrite Zpos_mult_morphism; ring.
- rewrite CRplus_0_r.
- apply pre_wd; unfold QposEq, Qeq; simpl; repeat rewrite Zpos_mult_morphism; ring.
- rewrite (pre_additive a (QposMake n d) (QposMake n0 d0)).
- apply pre_wd; reflexivity.
- Qed.
-
- Lemma integral_extended_to_nn_width_correct: Integrable f.
- Proof. constructor; auto. Qed.
-
-End extension_to_nn_width.
*)
+
diff --git a/broken/SimpleIntegration.v b/broken/SimpleIntegration.v
index 62f74625..be331d9e 100644
--- a/broken/SimpleIntegration.v
+++ b/broken/SimpleIntegration.v
@@ -1,5 +1,3 @@
-(*
-
(** A straightforward implementation of the abstract integration interface
in AbstractionIntegration using Riemann sums. The sole product of
this module are the Integrate and Integrable type class instances.
@@ -11,7 +9,7 @@
Require Import
List NPeano Unicode.Utf8
QArith Qabs Qpossec Qsums
- Qmetric
+ Qmetric Qsetoid (* Needs imported for Q_is_Setoid to be a canonical structure *)
CRArith AbstractIntegration
util.Qgcd
Program
@@ -19,9 +17,31 @@ Require Import
stdlib_omissions.P
stdlib_omissions.Z
stdlib_omissions.Q
- metric2.Classified
+ metric FromMetric2
+ Qauto
implementations.stdlib_rationals.
+Open Scope Q_scope.
+
+Lemma Qplus_pos_compat (x y : Q) : 0 < x -> 0 < y -> 0 < x + y.
+Proof. intros; apply Qplus_lt_le_0_compat; [| apply Qlt_le_weak]; trivial. Qed.
+
+Ltac Qauto_pos :=
+ repeat (first [ assumption
+ | constructor
+ | apply Qplus_pos_compat
+ | apply Qmult_lt_0_compat
+ | apply Qinv_lt_0_compat]);
+ auto with *.
+
+Lemma gball_mspc_ball {X : MetricSpace} (r : Q) (x y : X) :
+ gball r x y <-> mspc_ball r x y.
+Proof. reflexivity. Qed.
+
+Lemma ball_mspc_ball {X : MetricSpace} (r : Qpos) (x y : X) :
+ ball r x y <-> mspc_ball r x y.
+Proof. rewrite <- ball_gball; reflexivity. Qed.
+
Open Scope uc_scope.
Hint Resolve Qpos_nonzero.
@@ -47,7 +67,7 @@ Definition plus_half_times (x y: Q): Q := x * y + (1#2)*y.
Section definition.
- Context (f: Q -> CR) `{!LocallyUniformlyContinuous_mu f} `{!LocallyUniformlyContinuous f}.
+ Context (f: Q -> CR) `{UC : !IsLocallyUniformlyContinuous f lmu}.
(** Note that in what follows we don't specialize for [0,1] or [0,w] ranges first. While this
would make the definition marginally cleaner, the resulting definition is harder to prove
@@ -55,13 +75,18 @@ Section definition.
don't come with Proper proofs, which means that common sense reasoning about
those operations with their arguments transformed doesn't work well. *)
- Definition intervals (from: Q) (w: Qpos) (error: Qpos): positive :=
- match luc_mu f from w (error / w) with
+ Program Definition intervals (from: Q) (w: Qpos) (error: Qpos): positive :=
+ match lmu from w (error / w) with
(* Todo: This is nice and simple, but suboptimal. Better would be to take the luc_mu
around the midpoint and with radius (w/2). *)
- | QposInfinity => 1%positive
- | Qpos2QposInf mue => QposCeiling ((1#2) * w / mue)%Qpos
+ | Qinf.infinite => 1%positive
+ | Qinf.finite mue => QposCeiling ((1#2) * w / mue)%Qpos
end.
+ Next Obligation.
+ change (Qinf.lt 0 mue). rewrite Heq_anonymous.
+ (*unfold IsLocallyUniformlyContinuous in *.*)
+ apply (uc_pos (restrict f from w)); [apply UC | Qauto_pos].
+ Qed.
Definition approx (from: Q) (w: Qpos) (e: Qpos): Q :=
let halferror := (e * (1#2))%Qpos in
@@ -83,6 +108,8 @@ Section definition.
Proof with auto.
unfold plus_half_times.
apply ball_sym.
+ unfold IsLocallyUniformlyContinuous in UC.
+apply ball_mspc_ball. admit. (*apply (uc_prf _ (lmu fr wb)).
apply (locallyUniformlyContinuous f fr wb (he / wb)).
unfold mspc_ball.
unfold CRGroupOps.MetricSpaceBall_instance_0.
@@ -148,14 +175,14 @@ Section definition.
rewrite inject_nat_convert.
apply Qfloor_ball.
unfold QposEq. simpl.
- field. split; try discriminate...
+ field. split; try discriminate...*)
Qed.
(** To construct a CR, we'll need to prove that approx is a regular function.
However, that property is essentially a specialization of a more general
well-definedness property that we'll need anyway, so we prove that one first. *)
- Let hint := luc_Proper f.
+ (*Let hint := luc_Proper f.*)
Lemma wd
(from1 from2: Q) (w: bool -> Qpos) (e: bool -> Qpos)
@@ -229,7 +256,7 @@ End definition.
Section implements_abstract_interface.
- Context (f: Q → CR) `{!LocallyUniformlyContinuous_mu f} `{!LocallyUniformlyContinuous f}.
+ Context (f: Q → CR) `{!IsLocallyUniformlyContinuous f lmu}.
Section additivity.
@@ -251,7 +278,7 @@ Section implements_abstract_interface.
Let approx01 (i: nat) :=
approximate (f (a + plus_half_times i (totalw / w01ints))) (e * (1 # 2) / totalw)%Qpos.
- Let hint := luc_Proper f.
+ (*Let hint := luc_Proper f.*)
Lemma added_summations: Qball (e + e)
(Σ (wbints true) approx0 * (ww true / wbints true) +
@@ -431,7 +458,7 @@ Section implements_abstract_interface.
Let bounded (from: Q) (width: Qpos) (mid: Q) (r: Qpos):
(forall x, from <= x <= from + width -> ball r (f x) ('mid)%CR) ->
- ball (width * r) (pre_result f from width) (' (width * mid))%CR.
+ ball (width * r) (pre_result f from width) (' (width * mid)%Q)%CR.
Proof with auto.
intros. apply (@regFunBall_Cunit Q_as_MetricSpace).
intro. unfold pre_result. simpl approximate.
@@ -463,4 +490,3 @@ Section implements_abstract_interface.
Qed.
End implements_abstract_interface.
-*)
diff --git a/broken/metric.v b/broken/metric.v
index e2a22bc7..fa697921 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -215,6 +215,10 @@ try (unfold Qinf.eq, equiv in *; contradiction).
now apply mspc_triangle with (b := y2); [rewrite Ee1e2 | apply mspc_symm].
Qed.
+(*Check _ : Le Qinf.T.
+Lemma mspc_refl ∀ e : Q, 0 ≤ e → Reflexive (ball e);*)
+
+
Lemma mspc_triangle' :
∀ (q1 q2 : Q) (x2 x1 x3 : X) (q : Q),
q1 + q2 = q → ball q1 x1 x2 → ball q2 x2 x3 → ball q x1 x3.
@@ -288,6 +292,59 @@ End UniformContinuity.
Global Arguments UniformlyContinuous X {_} Y {_}.
+Section SubMetricSpace.
+
+Context `{ExtMetricSpaceClass X} (P : X -> Prop).
+
+Global Instance sig_mspc_ball : MetricSpaceBall (sig P) := λ e x y, ball e (` x) (` y).
+
+Global Instance sig_mspc : ExtMetricSpaceClass (sig P).
+Proof.
+constructor.
++ repeat intro; rapply mspc_radius_proper; congruence.
++ repeat intro; rapply mspc_inf.
++ intros; now rapply mspc_negative.
++ repeat intro; now rapply mspc_refl.
++ repeat intro; now rapply mspc_symm.
++ repeat intro; rapply mspc_triangle; eauto.
++ repeat intro; now rapply mspc_closed.
+Qed.
+
+End SubMetricSpace.
+
+Section LocalUniformContinuity.
+
+Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
+
+Definition restrict (f : X -> Y) (x : X) (r : Q) : sig (ball r x) -> Y :=
+ f ∘ @proj1_sig _ _.
+
+Class IsLocallyUniformlyContinuous (f : X -> Y) (lmu : X -> Q -> Q -> Qinf) :=
+ luc_prf : forall (x : X) (r : Q), IsUniformlyContinuous (restrict f x r) (lmu x r).
+
+Global Arguments luc_prf f lmu {_} x r.
+
+Global Instance uc_ulc (f : X -> Y) `{!IsUniformlyContinuous f mu} :
+ IsLocallyUniformlyContinuous f (λ _ _, mu).
+Proof.
+intros x r. constructor; [now apply (uc_pos f) |].
+intros e [x1 A1] [x2 A2] e_pos A. now apply (uc_prf f mu).
+Qed.
+
+Global Instance luc_proper `{IsLocallyUniformlyContinuous f lmu} : Proper ((=) ==> (=)) f.
+Proof.
+intros x1 x2 A. apply -> mspc_eq. intros e e_pos.
+assert (A1 : ball 1%Q x1 x1) by (apply mspc_refl; Qauto_nonneg).
+assert (A2 : ball 1%Q x1 x2) by (rewrite A; apply mspc_refl; Qauto_nonneg).
+change (ball e (restrict f x1 1 (exist _ x1 A1)) (restrict f x1 1 (exist _ x2 A2))).
+unfold IsLocallyUniformlyContinuous in *. apply (uc_prf _ (lmu x1 1)); [easy |].
+change (ball (lmu x1 1 e) x1 x2).
+rewrite <- A. assert (0 < lmu x1 1 e) by now apply (uc_pos (restrict f x1 1)).
+destruct (lmu x1 1 e) as [q |]; [apply mspc_refl; solve_propholds | apply mspc_inf].
+Qed.
+
+End LocalUniformContinuity.
+
Section Contractions.
Context `{MetricSpaceClass X, ExtMetricSpaceClass Y}.
@@ -650,48 +707,6 @@ Qed.
End CompleteSpaceSequenceLimits.
-Section SubMetricSpace.
-
-Context `{ExtMetricSpaceClass X} (P : X -> Prop).
-
-Global Instance sig_mspc_ball : MetricSpaceBall (sig P) := λ e x y, ball e (` x) (` y).
-
-Global Instance sig_mspc : ExtMetricSpaceClass (sig P).
-Proof.
-constructor.
-+ repeat intro; rapply mspc_radius_proper; congruence.
-+ repeat intro; rapply mspc_inf.
-+ intros; now rapply mspc_negative.
-+ repeat intro; now rapply mspc_refl.
-+ repeat intro; now rapply mspc_symm.
-+ repeat intro; rapply mspc_triangle; eauto.
-+ repeat intro; now rapply mspc_closed.
-Qed.
-
-End SubMetricSpace.
-
-Section LocalUniformContinuity.
-
-Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
-
-Definition restrict (f : X -> Y) (x : X) (r : Q) : sig (ball r x) -> Y :=
- f ∘ @proj1_sig _ _.
-
-Class IsLocallyUniformlyContinuous (f : X -> Y) (lmu : X -> Q -> Q -> Qinf) :=
- luc_prf : forall (x : X) (r : Q), IsUniformlyContinuous (restrict f x r) (lmu x r).
-
-Global Arguments luc_prf f lmu {_} x r.
-
-Global Instance uc_ulc (f : X -> Y) `{!IsUniformlyContinuous f mu} :
- IsLocallyUniformlyContinuous f (λ _ _, mu).
-Proof.
-intros x r. constructor; [now apply (uc_pos f) |].
-intros e [x1 A1] [x2 A2] e_pos A. now apply (uc_prf f mu).
-Qed.
-
-End LocalUniformContinuity.
-
-
(*Section ClosedSegmentComplete.
Context `{CompleteMetricSpaceClass X, Le X, @PartialOrder X _ _}.
From b08f2efe2d997181bc46ed7274702436e0dd2dea Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 8 Nov 2012 22:22:29 +0100
Subject: [PATCH 035/110] Adapting SimpleIntegration.v to metric.v instead of
Classified.v
---
broken/SimpleIntegration.v | 146 +++++++++++++++++++++----------------
1 file changed, 85 insertions(+), 61 deletions(-)
diff --git a/broken/SimpleIntegration.v b/broken/SimpleIntegration.v
index be331d9e..274eee14 100644
--- a/broken/SimpleIntegration.v
+++ b/broken/SimpleIntegration.v
@@ -65,6 +65,10 @@ Proof. destruct e. apply Qball_plus_r. intuition. Qed.
Definition plus_half_times (x y: Q): Q := x * y + (1#2)*y.
+Lemma ball_ex_symm (X : MetricSpace) (e : QposInf) (x y : X) :
+ ball_ex e x y -> ball_ex e y x.
+Proof. destruct e as [e |]; [apply ball_sym | trivial]. Qed.
+
Section definition.
Context (f: Q -> CR) `{UC : !IsLocallyUniformlyContinuous f lmu}.
@@ -75,18 +79,28 @@ Section definition.
don't come with Proper proofs, which means that common sense reasoning about
those operations with their arguments transformed doesn't work well. *)
- Program Definition intervals (from: Q) (w: Qpos) (error: Qpos): positive :=
- match lmu from w (error / w) with
- (* Todo: This is nice and simple, but suboptimal. Better would be to take the luc_mu
- around the midpoint and with radius (w/2). *)
- | Qinf.infinite => 1%positive
- | Qinf.finite mue => QposCeiling ((1#2) * w / mue)%Qpos
- end.
+ Program Definition lmu' (a w : Q) (e : Qpos) : QposInf :=
+ match lmu a w e with
+ | Qinf.infinite => QposInfinity
+ | Qinf.finite x => Qpos2QposInf x
+ end.
Next Obligation.
+ change (Qinf.lt 0 x). rewrite Heq_anonymous.
+ apply (uc_pos (restrict f a w)); [apply UC | apply (proj2_sig e)].
+ Qed.
+
+ Definition intervals (from: Q) (w: Qpos) (error: Qpos): positive :=
+ match lmu' from w (error / w) with
+ (* Todo: This is nice and simple, but suboptimal. Better would be to take the luc_mu
+ around the midpoint and with radius (w/2). *)
+ | QposInfinity => 1%positive
+ | Qpos2QposInf x => QposCeiling ((1#2) * w / x)%Qpos
+ end.
+ (*Next Obligation.
change (Qinf.lt 0 mue). rewrite Heq_anonymous.
(*unfold IsLocallyUniformlyContinuous in *.*)
- apply (uc_pos (restrict f from w)); [apply UC | Qauto_pos].
- Qed.
+ apply (uc_pos (restrict f from w)). apply UC. Qauto_pos.
+ Qed.*)
Definition approx (from: Q) (w: Qpos) (e: Qpos): Q :=
let halferror := (e * (1#2))%Qpos in
@@ -102,17 +116,19 @@ Section definition.
Hint Resolve Qinv_le_0_compat Qmult_le_0_compat.
Hint Immediate Zle_0_POS Zlt_0_POS.
- Lemma sampling_over_subdivision (fr: Q) (i: nat) (t: positive) (he wb: Qpos) (ile: le i (intervals fr wb he * t)%positive): ball (he / wb)
- (f (fr + plus_half_times (i / t)%nat (wb * / intervals fr wb he)))
- (f (fr + i * / (intervals fr wb he * t)%positive * wb)).
+ Lemma sampling_over_subdivision (fr: Q) (i: nat) (t: positive) (he wb: Qpos) :
+ (i < (intervals fr wb he * t)%positive)%nat ->
+ ball (he / wb)
+ (f (fr + plus_half_times (i / t)%nat (wb * / intervals fr wb he)))
+ (f (fr + i * / (intervals fr wb he * t)%positive * wb)).
Proof with auto.
+ intro ile.
unfold plus_half_times.
apply ball_sym.
unfold IsLocallyUniformlyContinuous in UC.
-apply ball_mspc_ball. admit. (*apply (uc_prf _ (lmu fr wb)).
- apply (locallyUniformlyContinuous f fr wb (he / wb)).
- unfold mspc_ball.
- unfold CRGroupOps.MetricSpaceBall_instance_0.
+ (*apply ball_mspc_ball.*)
+ (*apply (locallyUniformlyContinuous f fr wb (he / wb)).*)
+ assert (A1 : Qball wb fr (fr + i * / (intervals fr wb he * t)%positive * wb)).
rewrite <- (Qplus_0_r fr) at 1.
apply Qball_plus_r.
apply in_Qball.
@@ -132,51 +148,61 @@ apply ball_mspc_ball. admit. (*apply (uc_prf _ (lmu fr wb)).
rewrite Qmult_1_l.
rewrite <- Zle_Qle.
rewrite <- ZL9.
- apply inj_le...
+ apply inj_le; auto with arith.
intro.
assert (0 < / (intervals fr wb he * t)%positive).
apply Qinv_lt_0_compat...
revert H0.
rewrite H.
apply (Qlt_irrefl 0).
- pose proof mspc_ball_ex_Symmetric.
- symmetry.
- apply Qball_ex_plus_r.
- unfold intervals.
- set (luc_mu f fr wb (he / wb)).
- destruct q; simpl...
- set (mym := QposCeiling ((1 # 2) * wb / q)).
- apply ball_weak_le with (wb * (1#2) * Qpos_inv mym)%Qpos.
+ assert
+ (A2 : ball_ex
+ (lmu' fr wb (he / wb) )
+ (fr + i * / (intervals fr wb he * t)%positive * wb)
+ (fr + ((i / t)%nat * (wb * / intervals fr wb he) + (1 # 2) * (wb * / intervals fr wb he)))).
+ apply ball_ex_symm.
+ apply Qball_ex_plus_r.
+ unfold intervals.
+ set (q := lmu' fr wb (he / wb)).
+ destruct q; simpl...
+ set (mym := QposCeiling ((1 # 2) * wb / q)).
+ apply ball_weak_le with (wb * (1#2) * Qpos_inv mym)%Qpos.
+ simpl.
+ rewrite (Qmult_comm (wb)).
+ simpl.
+ subst mym.
+ rewrite QposCeiling_Qceiling.
+ apply Qle_shift_div_r...
+ apply Qlt_le_trans with ((1#2) * wb / q)%Qpos...
+ auto with *.
+ setoid_replace ((1#2) * wb) with (q * ((1#2) * wb / q)).
+ apply Qmult_le_compat_l...
+ auto with *.
+ change (Qeq ((1 # 2) * wb) (q * ((1 # 2) * wb / q))).
+ field...
simpl.
- rewrite (Qmult_comm (wb)).
+ rewrite Q.Pmult_Qmult.
+ apply Qball_Qdiv_inv with (Qpos_inv mym * wb)%Qpos.
simpl.
- subst mym.
- rewrite QposCeiling_Qceiling.
- apply Qle_shift_div_r...
- apply Qlt_le_trans with ((1#2) * wb / q)%Qpos...
- auto with *.
- setoid_replace ((1#2) * wb) with (q * ((1#2) * wb / q)).
- apply Qmult_le_compat_l...
- auto with *.
- change (Qeq ((1 # 2) * wb) (q * ((1 # 2) * wb / q))).
- field...
- simpl.
- rewrite Q.Pmult_Qmult.
- apply Qball_Qdiv_inv with (Qpos_inv mym * wb)%Qpos.
- simpl.
- field_simplify...
- unfold Qdiv.
- rewrite Qmult_plus_distr_l.
- field_simplify...
- rewrite Qdiv_1_r.
- setoid_replace (wb * (1 # 2) / mym / (Qpos_inv mym * wb))%Qpos with (1#2)%Qpos.
- rewrite Z.div_Zdiv...
- rewrite Q.Zdiv_Qdiv.
- rewrite inject_nat_convert.
- apply Qfloor_ball.
- unfold QposEq. simpl.
- field. split; try discriminate...*)
- Qed.
+ field_simplify...
+ unfold Qdiv.
+ rewrite Qmult_plus_distr_l.
+ field_simplify...
+ rewrite Qdiv_1_r.
+ setoid_replace (wb * (1 # 2) / mym / (Qpos_inv mym * wb))%Qpos with (1#2)%Qpos.
+ rewrite Z.div_Zdiv...
+ rewrite Q.Zdiv_Qdiv.
+ rewrite inject_nat_convert.
+ apply Qfloor_ball.
+ unfold QposEq. simpl.
+ field. split; try discriminate...
+ assert (A3 : Qball wb fr (fr + ((i / t)%nat * (wb * / intervals fr wb he) + (1 # 2) * (wb * / intervals fr wb he)))).
+ set (n := intervals fr wb he).
+ rewrite <- (Qplus_0_r fr) at 1.
+ apply Qball_plus_r. admit.
+ (*SearchAbout (Qball _ 0 _).
+ apply in_Qball.*)
+ Admitted.
(** To construct a CR, we'll need to prove that approx is a regular function.
However, that property is essentially a specialization of a more general
@@ -225,13 +251,11 @@ apply ball_mspc_ball. admit. (*apply (uc_prf _ (lmu fr wb)).
_ (f (from2 + i * / (m true * m false)%positive * w false)) _).
rewrite <- fE.
rewrite <- wE.
- apply (sampling_over_subdivision from1 i (m false) (halfe true) (w true)).
- apply lt_le_weak...
+ apply (sampling_over_subdivision from1 i (m false) (halfe true) (w true))...
apply ball_sym.
rewrite Pmult_comm.
apply sampling_over_subdivision.
- rewrite Pmult_comm.
- apply lt_le_weak...
+ rewrite Pmult_comm...
Qed.
Lemma regular fr w: is_RegularFunction_noInf Q_as_MetricSpace (approx fr w).
@@ -355,7 +379,7 @@ Section implements_abstract_interface.
setoid_replace (i0 * (totalw / (w01ints * k))) with (i0 * / (w01ints * k)%positive * totalw).
apply sampling_over_subdivision...
rewrite Pmult_comm.
- apply lt_le_weak...
+ (*apply lt_le_weak...*)
apply lt_trans with (i * wbints true)%positive...
apply inj_lt_iff.
rewrite Zlt_Qlt.
@@ -397,7 +421,7 @@ Section implements_abstract_interface.
(((i * wbints true)%positive + i0)%nat * / (intervals f a totalw (e * (1#2)) * k)%positive * totalw).
apply (sampling_over_subdivision f a ((i * wbints true)%positive + i0) k (e*(1#2)) totalw).
fold w01ints.
- apply le_trans with ((i * wbints true)%positive + (j * wbints false)%positive)%nat...
+ apply lt_le_trans with ((i * wbints true)%positive + (j * wbints false)%positive)%nat...
apply inj_le_iff.
rewrite Zle_Qle.
rewrite inj_plus.
@@ -407,9 +431,9 @@ Section implements_abstract_interface.
rewrite iE, jE, kE.
simpl.
field_simplify...
- unfold Qdiv.
+ unfold Qdiv.
rewrite (Qmult_comm totalw).
- rewrite inj_plus, Zplus_Qplus.
+ rewrite inj_plus, Zplus_Qplus.
rewrite <- Pmult_Qmult.
rewrite Qmult_assoc.
rewrite <- Zpos_eq_Z_of_nat_o_nat_of_P.
From 0f36628d3acce5cddc3e2289aa90a7d595d8ab2a Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 9 Nov 2012 21:12:55 +0100
Subject: [PATCH 036/110] Finished adapting SimpleIntegration.v
---
broken/SimpleIntegration.v | 95 ++++++++++++++++++++++----------------
1 file changed, 54 insertions(+), 41 deletions(-)
diff --git a/broken/SimpleIntegration.v b/broken/SimpleIntegration.v
index 274eee14..4a678cff 100644
--- a/broken/SimpleIntegration.v
+++ b/broken/SimpleIntegration.v
@@ -79,28 +79,32 @@ Section definition.
don't come with Proper proofs, which means that common sense reasoning about
those operations with their arguments transformed doesn't work well. *)
- Program Definition lmu' (a w : Q) (e : Qpos) : QposInf :=
- match lmu a w e with
- | Qinf.infinite => QposInfinity
- | Qinf.finite x => Qpos2QposInf x
+ (* Reimplementation of Qpossec.QposCeiling that takes a Q instead of a Qpos *)
+
+ Definition QposCeiling (q : Q) : positive :=
+ match Qround.Qceiling q with
+ | Zpos p => p
+ | _ => 1%positive
end.
- Next Obligation.
- change (Qinf.lt 0 x). rewrite Heq_anonymous.
- apply (uc_pos (restrict f a w)); [apply UC | apply (proj2_sig e)].
+
+ Lemma QposCeiling_Qceiling (q : Qpos) : (QposCeiling q : Z) = Qround.Qceiling q.
+ Proof with auto with qarith.
+ unfold QposCeiling.
+ pose proof Qround.Qle_ceiling q.
+ destruct (Qround.Qceiling q); try reflexivity; exfalso; destruct q; simpl in *.
+ apply (Qlt_not_le 0 x q)...
+ apply (Qlt_irrefl 0).
+ apply Qlt_le_trans with x...
+ apply Qle_trans with (Zneg p)...
Qed.
Definition intervals (from: Q) (w: Qpos) (error: Qpos): positive :=
- match lmu' from w (error / w) with
+ match lmu from w (error / w) with
(* Todo: This is nice and simple, but suboptimal. Better would be to take the luc_mu
around the midpoint and with radius (w/2). *)
- | QposInfinity => 1%positive
- | Qpos2QposInf x => QposCeiling ((1#2) * w / x)%Qpos
+ | Qinf.infinite => 1%positive
+ | Qinf.finite x => QposCeiling ((1#2) * w / x)
end.
- (*Next Obligation.
- change (Qinf.lt 0 mue). rewrite Heq_anonymous.
- (*unfold IsLocallyUniformlyContinuous in *.*)
- apply (uc_pos (restrict f from w)). apply UC. Qauto_pos.
- Qed.*)
Definition approx (from: Q) (w: Qpos) (e: Qpos): Q :=
let halferror := (e * (1#2))%Qpos in
@@ -125,9 +129,6 @@ Section definition.
intro ile.
unfold plus_half_times.
apply ball_sym.
- unfold IsLocallyUniformlyContinuous in UC.
- (*apply ball_mspc_ball.*)
- (*apply (locallyUniformlyContinuous f fr wb (he / wb)).*)
assert (A1 : Qball wb fr (fr + i * / (intervals fr wb he * t)%positive * wb)).
rewrite <- (Qplus_0_r fr) at 1.
apply Qball_plus_r.
@@ -156,29 +157,32 @@ Section definition.
rewrite H.
apply (Qlt_irrefl 0).
assert
- (A2 : ball_ex
- (lmu' fr wb (he / wb) )
+ (A2 : mspc_ball
+ (lmu fr wb (he / wb))
(fr + i * / (intervals fr wb he * t)%positive * wb)
(fr + ((i / t)%nat * (wb * / intervals fr wb he) + (1 # 2) * (wb * / intervals fr wb he)))).
- apply ball_ex_symm.
- apply Qball_ex_plus_r.
unfold intervals.
- set (q := lmu' fr wb (he / wb)).
- destruct q; simpl...
- set (mym := QposCeiling ((1 # 2) * wb / q)).
+ destruct (lmu fr wb (he / wb)) as [q |] eqn:L; [| apply mspc_inf].
+ (* apply gball_mspc_ball. does not change the goal *)
+ unfold mspc_ball, msp_mspc_ball.
+ assert (q_pos : 0 < q).
+ change (Qinf.lt 0 q). rewrite <- L. apply (uc_pos (restrict f fr wb)); [apply UC | Qauto_pos].
+ set (q' := exist _ q q_pos : Qpos).
+ change q with (QposAsQ q').
+ apply ball_gball, ball_sym, Qball_plus_r.
+ change ((1 # 2) * wb / q')%Q with (QposAsQ ((1 # 2) * wb / q')%Qpos).
+ set (mym := QposCeiling ((1 # 2) * wb / q')%Qpos).
apply ball_weak_le with (wb * (1#2) * Qpos_inv mym)%Qpos.
- simpl.
+ change (wb * (1 # 2) / mym <= q').
rewrite (Qmult_comm (wb)).
- simpl.
subst mym.
rewrite QposCeiling_Qceiling.
apply Qle_shift_div_r...
- apply Qlt_le_trans with ((1#2) * wb / q)%Qpos...
+ apply Qlt_le_trans with ((1#2) * wb / q')%Qpos...
auto with *.
- setoid_replace ((1#2) * wb) with (q * ((1#2) * wb / q)).
+ setoid_replace ((1#2) * wb) with (q' * ((1#2) * wb / q')).
apply Qmult_le_compat_l...
auto with *.
- change (Qeq ((1 # 2) * wb) (q * ((1 # 2) * wb / q))).
field...
simpl.
rewrite Q.Pmult_Qmult.
@@ -199,17 +203,25 @@ Section definition.
assert (A3 : Qball wb fr (fr + ((i / t)%nat * (wb * / intervals fr wb he) + (1 # 2) * (wb * / intervals fr wb he)))).
set (n := intervals fr wb he).
rewrite <- (Qplus_0_r fr) at 1.
- apply Qball_plus_r. admit.
- (*SearchAbout (Qball _ 0 _).
- apply in_Qball.*)
- Admitted.
+ apply Qball_plus_r.
+ apply in_Qball; unfold Qminus; rewrite !Qplus_0_l; split.
+ apply Qle_trans with (y := 0); [auto with qarith | Qauto_nonneg].
+ rewrite <- Qmult_plus_distr_l, (Qmult_comm wb), Qmult_assoc. rewrite <- (Qmult_1_l wb) at 2.
+ apply Qmult_le_compat_r; [| auto].
+ apply Qdiv_le_1. split; [Qauto_nonneg |]. rewrite <- (positive_nat_Z n).
+ apply Qlt_le_weak, nat_lt_Qlt, Nat.div_lt_upper_bound; [auto |].
+ rewrite mult_comm, <- Pos2Nat.inj_mul; apply ile.
+ apply ball_mspc_ball. eapply luc with (a := fr) (r := wb); [apply UC | | | |]. (* Why is [apply UC] not done automatically? *)
+ Qauto_pos.
+ apply ball_gball, A1.
+ apply ball_gball, A3.
+ apply A2.
+ Qed.
(** To construct a CR, we'll need to prove that approx is a regular function.
However, that property is essentially a specialization of a more general
well-definedness property that we'll need anyway, so we prove that one first. *)
- (*Let hint := luc_Proper f.*)
-
Lemma wd
(from1 from2: Q) (w: bool -> Qpos) (e: bool -> Qpos)
(fE: from1 == from2) (wE: w true == w false):
@@ -276,6 +288,8 @@ Section definition.
End definition.
+Arguments intervals lmu from w error : clear implicits.
+
(** Next, we prove that this implements the abstract interface. *)
Section implements_abstract_interface.
@@ -293,8 +307,8 @@ Section implements_abstract_interface.
Variable e: Qpos.
Let ec b := (e * (ww b / totalw))%Qpos.
- Let wbints (b : bool) := intervals f (if b then a else a+ww true) (ww b) (ec b * (1 # 2)).
- Let w01ints := intervals f a totalw (e * (1 # 2)).
+ Let wbints (b : bool) := intervals lmu (if b then a else a+ww true) (ww b) (ec b * (1 # 2)).
+ Let w01ints := intervals lmu a totalw (e * (1 # 2)).
Let approx0 (i: nat) :=
approximate (f (a + plus_half_times i (ww true / wbints true))) (ec true * (1 # 2) / ww true)%Qpos.
Let approx1 (i: nat) :=
@@ -379,7 +393,6 @@ Section implements_abstract_interface.
setoid_replace (i0 * (totalw / (w01ints * k))) with (i0 * / (w01ints * k)%positive * totalw).
apply sampling_over_subdivision...
rewrite Pmult_comm.
- (*apply lt_le_weak...*)
apply lt_trans with (i * wbints true)%positive...
apply inj_lt_iff.
rewrite Zlt_Qlt.
@@ -418,7 +431,7 @@ Section implements_abstract_interface.
by (rewrite iE, kE; unfold Q_eq; simpl; field; auto).
rewrite <- Pmult_Qmult.
setoid_replace (((i * wbints true)%positive + i0) * (totalw / (w01ints * k))) with
- (((i * wbints true)%positive + i0)%nat * / (intervals f a totalw (e * (1#2)) * k)%positive * totalw).
+ (((i * wbints true)%positive + i0)%nat * / (intervals lmu a totalw (e * (1#2)) * k)%positive * totalw).
apply (sampling_over_subdivision f a ((i * wbints true)%positive + i0) k (e*(1#2)) totalw).
fold w01ints.
apply lt_le_trans with ((i * wbints true)%positive + (j * wbints false)%positive)%nat...
@@ -488,7 +501,7 @@ Section implements_abstract_interface.
intro. unfold pre_result. simpl approximate.
unfold approx.
rewrite fastΣ_correct.
- set (ints := intervals f from width (d * (1 # 2))).
+ set (ints := intervals lmu from width (d * (1 # 2))).
apply (ball_weak_le Q_as_MetricSpace (d*(1#2) + width * r) (d + width * r)).
simpl. apply Qplus_le_compat...
simpl.
From d53269b5b77d51878a9cde3f6790419cde3e55b9 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 30 Nov 2012 17:56:05 +0100
Subject: [PATCH 037/110] Defined Lipschitz and expressed Contraction through
it
---
broken/SimpleIntegration.v | 11 --
broken/metric.v | 226 ++++++++++++++++++++-----------------
2 files changed, 121 insertions(+), 116 deletions(-)
diff --git a/broken/SimpleIntegration.v b/broken/SimpleIntegration.v
index 4a678cff..e78b40e0 100644
--- a/broken/SimpleIntegration.v
+++ b/broken/SimpleIntegration.v
@@ -23,17 +23,6 @@ Require Import
Open Scope Q_scope.
-Lemma Qplus_pos_compat (x y : Q) : 0 < x -> 0 < y -> 0 < x + y.
-Proof. intros; apply Qplus_lt_le_0_compat; [| apply Qlt_le_weak]; trivial. Qed.
-
-Ltac Qauto_pos :=
- repeat (first [ assumption
- | constructor
- | apply Qplus_pos_compat
- | apply Qmult_lt_0_compat
- | apply Qinv_lt_0_compat]);
- auto with *.
-
Lemma gball_mspc_ball {X : MetricSpace} (r : Q) (x y : X) :
gball r x y <-> mspc_ball r x y.
Proof. reflexivity. Qed.
diff --git a/broken/metric.v b/broken/metric.v
index fa697921..f1df8828 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -16,6 +16,31 @@ Set Printing Coercions.
Notation "x ²" := (x * x) (at level 30) : mc_scope.
+Import Qinf.notations.
+
+Definition Qinf_recip (a : Q) : Qinf := if (decide (a = 0)) then Qinf.infinite else /a.
+
+Definition comp_inf {X Z : Type} (g : Q -> Z) (f : X -> Qinf) (inf : Z) (x : X) :=
+match (f x) with
+| Qinf.finite y => g y
+| Qinf.infinite => inf
+end.
+
+Definition Qinf_div (a b : Q) := comp_inf (a *.) Qinf_recip 0 b.
+
+Infix "/" := Qinf_div : Qinf_scope.
+
+Lemma Qplus_pos_compat (x y : Q) : (0 < x -> 0 < y -> 0 < x + y)%Q.
+Proof. intros; apply Q.Qplus_lt_le_0_compat; [| apply Qlt_le_weak]; trivial. Qed.
+
+Ltac Qauto_pos :=
+ repeat (first [ assumption
+ | constructor
+ | apply Qplus_pos_compat
+ | apply Q.Qmult_lt_0_compat
+ | apply Qinv_lt_0_compat]);
+ auto with *.
+
Lemma po_proper' `{PartialOrder A} {x1 x2 y1 y2 : A} :
x1 ≤ y1 -> x1 = x2 -> y1 = y2 -> x2 ≤ y2.
Proof. intros A1 A2 A3; now apply (po_proper _ _ A2 _ _ A3). Qed.
@@ -96,8 +121,6 @@ Instance Qpos_inv : DecRecip Qpos := Qpossec.Qpos_inv.
Instance Qinf_one : One Qinf := 1%Q.
*)
-Notation Qinf := Qinf.T.
-
Module Qinf.
Definition lt (x y : Qinf) : Prop :=
@@ -257,6 +280,26 @@ Qed.
End MetricSpace.
+Section SubMetricSpace.
+
+Context `{ExtMetricSpaceClass X} (P : X -> Prop).
+
+Global Instance sig_mspc_ball : MetricSpaceBall (sig P) := λ e x y, ball e (` x) (` y).
+
+Global Instance sig_mspc : ExtMetricSpaceClass (sig P).
+Proof.
+constructor.
++ repeat intro; rapply mspc_radius_proper; congruence.
++ repeat intro; rapply mspc_inf.
++ intros; now rapply mspc_negative.
++ repeat intro; now rapply mspc_refl.
++ repeat intro; now rapply mspc_symm.
++ repeat intro; rapply mspc_triangle; eauto.
++ repeat intro; now rapply mspc_closed.
+Qed.
+
+End SubMetricSpace.
+
Section UniformContinuity.
Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
@@ -292,26 +335,6 @@ End UniformContinuity.
Global Arguments UniformlyContinuous X {_} Y {_}.
-Section SubMetricSpace.
-
-Context `{ExtMetricSpaceClass X} (P : X -> Prop).
-
-Global Instance sig_mspc_ball : MetricSpaceBall (sig P) := λ e x y, ball e (` x) (` y).
-
-Global Instance sig_mspc : ExtMetricSpaceClass (sig P).
-Proof.
-constructor.
-+ repeat intro; rapply mspc_radius_proper; congruence.
-+ repeat intro; rapply mspc_inf.
-+ intros; now rapply mspc_negative.
-+ repeat intro; now rapply mspc_refl.
-+ repeat intro; now rapply mspc_symm.
-+ repeat intro; rapply mspc_triangle; eauto.
-+ repeat intro; now rapply mspc_closed.
-Qed.
-
-End SubMetricSpace.
-
Section LocalUniformContinuity.
Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
@@ -331,7 +354,7 @@ intros x r. constructor; [now apply (uc_pos f) |].
intros e [x1 A1] [x2 A2] e_pos A. now apply (uc_prf f mu).
Qed.
-Global Instance luc_proper `{IsLocallyUniformlyContinuous f lmu} : Proper ((=) ==> (=)) f.
+Global Instance luc_proper (f : X -> Y) `{!IsLocallyUniformlyContinuous f lmu} : Proper ((=) ==> (=)) f.
Proof.
intros x1 x2 A. apply -> mspc_eq. intros e e_pos.
assert (A1 : ball 1%Q x1 x1) by (apply mspc_refl; Qauto_nonneg).
@@ -343,44 +366,97 @@ rewrite <- A. assert (0 < lmu x1 1 e) by now apply (uc_pos (restrict f x1 1)).
destruct (lmu x1 1 e) as [q |]; [apply mspc_refl; solve_propholds | apply mspc_inf].
Qed.
+Lemma luc (f : X -> Y) `{IsLocallyUniformlyContinuous f lmu} (r e : Q) (a x y : X) :
+ 0 < e -> ball r a x -> ball r a y -> ball (lmu a r e) x y -> ball e (f x) (f y).
+Proof.
+intros e_pos A1 A2 A3.
+change (f x) with (restrict f a r (exist _ x A1)).
+change (f y) with (restrict f a r (exist _ y A2)).
+apply uc_prf with (mu := lmu a r); trivial.
+(* The predicate symbol of the goal is IsUniformlyContinuous, which is a
+type class. Yet, without [trivial] above, instead of solving it by [apply
+H3], Coq gives it as a subgoal. *)
+Qed.
+
End LocalUniformContinuity.
+Section Lipschitz.
+
+Context `{MetricSpaceClass X, MetricSpaceClass Y}.
+
+Class IsLipschitz (f : X -> Y) (L : Q) := {
+ lip_nonneg : 0 ≤ L;
+ lip_prf : forall (x1 x2 : X) (e : Q), ball e x1 x2 -> ball (L * e) (f x1) (f x2)
+}.
+
+Global Arguments lip_nonneg f L {_} _.
+Global Arguments lip_prf f L {_} _ _ _ _.
+
+Record Lipschitz := {
+ lip_func : X -> Y;
+ lip_const : Q;
+ lip_proof : IsLipschitz lip_func lip_const
+}.
+
+Global Instance lip_uc `(IsLipschitz f L) : IsUniformlyContinuous f (λ e, (e / L)%Qinf).
+Proof.
+constructor.
++ intros e A.
+ unfold Qinf_div, comp_inf, Qinf_recip.
+ destruct (decide (L = 0)) as [A1 | A1]. [apply I |].
+ apply neq_symm in A1.
+ change (0 < e / L). (* Changes from Qinf, which is not declared as ordered ring, to Q *)
+ assert (0 ≤ L) by apply (lip_nonneg f L).
+ assert (0 < L) by now apply QOrder.le_neq_lt. Qauto_pos.
++ intros e x1 x2 A1 A2. destruct (decide (L = 0)) as [A | A].
+ - apply mspc_eq; [| easy]. unfold equiv, mspc_equiv. rewrite <- (Qmult_0_l (msd x1 x2)), <- A.
+ now apply lip_prf; [| apply mspc_distance].
+ - mc_setoid_replace e with (L * (e / L)) by now field.
+ now apply lip_prf.
+Qed.
+
+End Lipschitz.
+
+Section LocallyLipschitz.
+
+Context `{MetricSpaceClass X, ExtMetricSpaceClass Y}.
+
+Class IsLocallyLipschitz (f : X -> Y) (L : X -> Q -> Q) :=
+ llip_prf : forall (x : X) (r : Q), IsLipschitz (restrict f x r) (L x r).
+
+Global Arguments llip_prf f L {_} x r.
+
+Global Instance lip_llip (f : X -> Y) `{!IsLipschitz f L} : IsLocallyLipschitz f (λ _ _, L).
+Proof.
+intros x r. constructor; [now apply (lip_nonneg f) |].
+intros [x1 x1b] [x2 x2b] e A. change (ball (L * e) (f x1) (f x2)). now apply lip_prf.
+Qed.
+
+End LocallyLipschitz.
+
Section Contractions.
Context `{MetricSpaceClass X, ExtMetricSpaceClass Y}.
Class IsContraction (f : X -> Y) (q : Q) := {
- contr_nonneg_mu : 0 ≤ q;
- contr_lt_mu_1 : q < 1;
- contr_prf : forall (x1 x2 : X) (e : Q), ball e x1 x2 -> ball (q * e) (f x1) (f x2)
+ contr_prf :> IsLipschitz f q;
+ contr_lt_1 : q < 1
}.
-Global Arguments contr_nonneg_mu f q {_} _.
-Global Arguments contr_lt_mu_1 f q {_}.
-Global Arguments contr_prf f q {_} _ _ _ _.
+Global Arguments contr_lt_1 f q {_}.
+Global Arguments contr_prf f q {_}.
Record Contraction := {
contr_func : X -> Y;
- contr_q : Q;
- contr_proof : IsContraction contr_func contr_q
+ contr_const : Q;
+ contr_proof : IsContraction contr_func contr_const
}.
-Definition contr_modulus (q e : Q) : Qinf :=
- if (decide (0 = q)) then Qinf.infinite else (e / q).
+(* Do we need the following?
Global Instance contr_to_uc `(IsContraction f q) :
- IsUniformlyContinuous f (contr_modulus q).
-Proof.
-constructor.
-+ intros e A. unfold contr_modulus. destruct (decide (0 = q)) as [A1 | A1]; [apply I |].
- change (0 < e / q). (* Changes from Qinf, which is not declared as ordered ring, to Q *)
- pose proof (contr_nonneg_mu f q) as A2. pose proof (le_not_eq _ _ A2 A1). solve_propholds.
-+ intros e x1 x2 A1 A2. unfold contr_modulus in A2. destruct (decide (0 = q)) as [A | A].
- - assert (A3 := contr_prf f q x1 x2 (msd x1 x2) (mspc_distance x1 x2)).
- rewrite <- A, mult_0_l in A3; now apply mspc_eq.
- - mc_setoid_replace e with (q * (e / q)) by (field; now apply neq_symm).
- now apply contr_prf.
-Qed.
+ IsUniformlyContinuous f (λ e, if (decide (q = 0)) then Qinf.infinite else (e / q)).
+Proof. apply _. Qed.*)
End Contractions.
@@ -430,29 +506,6 @@ Qed.
End UCFMetricSpace.
-
-(*
-Section Isometry.
-
-Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
-
-Class Isometry (f : X -> Y) :=
- isometry : forall (e : Q) (x1 x2 : X), ball e x1 x2 <-> ball e (f x1) (f x2).
-
-Global Instance isometry_injective `{Isometry f} : Injective f.
-Proof.
-constructor; [| constructor]; try apply _; intros x y; rewrite <- !ball_zero;
-intros ?; [apply <- isometry | apply -> isometry]; trivial.
-Qed.
-
-Class IsometricIsomorphism (f : X -> Y) (g : Inverse f) := {
- isometric_isomorphism_isometry :> Isometry f;
- isometric_isomorphism_surjection :> Surjective f
-}.
-
-End Isometry.
-*)
-
Section CompleteMetricSpace.
Context `{ExtMetricSpaceClass X}.
@@ -639,12 +692,6 @@ Qed.
End SequenceLimits.
-Definition comp_inf {X Z : Type} (g : Q -> Z) (f : X -> Qinf) (inf : Z) (x : X) :=
-match (f x) with
-| Qinf.finite y => g y
-| Qinf.infinite => inf
-end.
-
Theorem seq_lim_cont
`{ExtMetricSpaceClass X, ExtMetricSpaceClass Y} (f : X -> Y) `{!IsUniformlyContinuous f mu}
(x : seq X) (a : X) (N : Q -> nat) :
@@ -707,36 +754,5 @@ Qed.
End CompleteSpaceSequenceLimits.
-(*Section ClosedSegmentComplete.
-
-Context `{CompleteMetricSpaceClass X, Le X, @PartialOrder X _ _}.
-
-Variables a b : X.
-
-Definition segment := sig (λ x, a ≤ x ≤ b).
-
-Typeclasses Transparent segment.
-
-(*Program Instance segment_limit : Limit segment :=
- λ f, lim (Build_RegularFunction (λ e, proj1_sig (f e)) _).
-generates an infinite number of obligation [MetricSpaceBall segment] *)
-
-(* In the context (f : RegularFunction segment), (proj1_sig ∘ f) does not typecheck,
-but (λ e, proj1_sig (f e)) does *)
-
-Lemma lim_inside_r (f : RegularFunction X) :
- (forall e, f e ≤ b) -> lim f ≤ b.
-Proof.
-intro A.
-
-
-Global Instance segment_limit : Limit segment.
-intro f.
-(* Check (λ (e : Q), `(f e)) : Q -> X. does not work *)
-(* refine (lim (Build_RegularFunction (λ e, proj1_sig (f e)) _) ↾ _).
-This generates one goal and one existential variable instead of two goals *)
-refine (lim (Build_RegularFunction (λ e, proj1_sig (f e)) (rf_proof f)) ↾ _).
-*)
-
End QField.
From 0d0e99a86db39f9cf59301c248026eebafe26cc2 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 4 Dec 2012 14:17:54 +0100
Subject: [PATCH 038/110] Adapting to Lipschitz class
---
broken/FromMetric2.v | 2 ++
broken/SimpleIntegration.v | 6 +++---
broken/metric.v | 32 ++++++++++----------------------
3 files changed, 15 insertions(+), 25 deletions(-)
diff --git a/broken/FromMetric2.v b/broken/FromMetric2.v
index f3b04ebe..f614c9de 100644
--- a/broken/FromMetric2.v
+++ b/broken/FromMetric2.v
@@ -4,6 +4,8 @@ Require Import
abstract_algebra stdlib_rationals
orders.orders orders.semirings orders.rings theory.rings.
+Import Qinf.notations.
+
Section QField.
Add Field Q : (dec_fields.stdlib_field_theory Q).
diff --git a/broken/SimpleIntegration.v b/broken/SimpleIntegration.v
index e78b40e0..6b6ebe20 100644
--- a/broken/SimpleIntegration.v
+++ b/broken/SimpleIntegration.v
@@ -17,8 +17,8 @@ Require Import
stdlib_omissions.P
stdlib_omissions.Z
stdlib_omissions.Q
- metric FromMetric2
Qauto
+ metric FromMetric2
implementations.stdlib_rationals.
Open Scope Q_scope.
@@ -154,8 +154,8 @@ Section definition.
destruct (lmu fr wb (he / wb)) as [q |] eqn:L; [| apply mspc_inf].
(* apply gball_mspc_ball. does not change the goal *)
unfold mspc_ball, msp_mspc_ball.
- assert (q_pos : 0 < q).
- change (Qinf.lt 0 q). rewrite <- L. apply (uc_pos (restrict f fr wb)); [apply UC | Qauto_pos].
+ assert (q_pos : 0 < q) by
+ (change (Qinf.lt 0 q); rewrite <- L; apply (uc_pos (restrict f fr wb)); [apply UC | Qauto_pos]).
set (q' := exist _ q q_pos : Qpos).
change q with (QposAsQ q').
apply ball_gball, ball_sym, Qball_plus_r.
diff --git a/broken/metric.v b/broken/metric.v
index f1df8828..c6cba5f7 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -10,26 +10,18 @@ Require Import interfaces.naturals interfaces.orders.
Import peano_naturals.
Require Import CRGeometricSum.
-Import Qround Qpower.
+Import Qround Qpower Qinf.notations.
Set Printing Coercions.
Notation "x ²" := (x * x) (at level 30) : mc_scope.
-Import Qinf.notations.
-
-Definition Qinf_recip (a : Q) : Qinf := if (decide (a = 0)) then Qinf.infinite else /a.
-
Definition comp_inf {X Z : Type} (g : Q -> Z) (f : X -> Qinf) (inf : Z) (x : X) :=
match (f x) with
| Qinf.finite y => g y
| Qinf.infinite => inf
end.
-Definition Qinf_div (a b : Q) := comp_inf (a *.) Qinf_recip 0 b.
-
-Infix "/" := Qinf_div : Qinf_scope.
-
Lemma Qplus_pos_compat (x y : Q) : (0 < x -> 0 < y -> 0 < x + y)%Q.
Proof. intros; apply Q.Qplus_lt_le_0_compat; [| apply Qlt_le_weak]; trivial. Qed.
@@ -393,22 +385,25 @@ Global Arguments lip_nonneg f L {_} _.
Global Arguments lip_prf f L {_} _ _ _ _.
Record Lipschitz := {
- lip_func : X -> Y;
+ lip_func :> X -> Y;
lip_const : Q;
lip_proof : IsLipschitz lip_func lip_const
}.
-Global Instance lip_uc `(IsLipschitz f L) : IsUniformlyContinuous f (λ e, (e / L)%Qinf).
+Definition lip_modulus (L e : Q) : Qinf :=
+ if (decide (L = 0)) then Qinf.infinite else e / L.
+
+Global Instance lip_uc `(IsLipschitz f L) : IsUniformlyContinuous f (lip_modulus L).
Proof.
constructor.
+ intros e A.
- unfold Qinf_div, comp_inf, Qinf_recip.
- destruct (decide (L = 0)) as [A1 | A1]. [apply I |].
+ unfold lip_modulus.
+ destruct (decide (L = 0)) as [A1 | A1]; [apply I |].
apply neq_symm in A1.
change (0 < e / L). (* Changes from Qinf, which is not declared as ordered ring, to Q *)
assert (0 ≤ L) by apply (lip_nonneg f L).
assert (0 < L) by now apply QOrder.le_neq_lt. Qauto_pos.
-+ intros e x1 x2 A1 A2. destruct (decide (L = 0)) as [A | A].
++ unfold lip_modulus. intros e x1 x2 A1 A2. destruct (decide (L = 0)) as [A | A].
- apply mspc_eq; [| easy]. unfold equiv, mspc_equiv. rewrite <- (Qmult_0_l (msd x1 x2)), <- A.
now apply lip_prf; [| apply mspc_distance].
- mc_setoid_replace e with (L * (e / L)) by now field.
@@ -478,13 +473,6 @@ Qed.
Global Instance UCFSpaceBall : MetricSpaceBall (UniformlyContinuous X Y) :=
λ e f g, forall x, ball e (f x) (g x).
-(* match e with
- | Qinf.infinite => True
- | Qinf.finite e' =>
- if (decide_rel (<) e' 0)
- then False
- else (forall x, ball e' (f x) (g x))
- end.*)
Lemma UCFBallProper : Proper ((=) ==> (≡) ==> (≡) ==> iff) ball.
Proof.
@@ -705,7 +693,7 @@ Qed.
Theorem seq_lim_contr
`{MetricSpaceClass X, ExtMetricSpaceClass Y} (f : X -> Y) `{!IsContraction f q}
(x : seq X) (a : X) (N : Q -> nat) :
- seq_lim x a N → seq_lim (f ∘ x) (f a) (comp_inf N (contr_modulus q) 0).
+ seq_lim x a N → seq_lim (f ∘ x) (f a) (comp_inf N (lip_modulus q) 0).
Proof. intro A; apply seq_lim_cont; [apply _ | apply A]. Qed.
Lemma iter_fixpoint
From 50900d0221d9e00e4a4b8a121312e835cfc42b6f Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 4 Dec 2012 18:55:59 +0100
Subject: [PATCH 039/110] Finished expressing Contraction through Lipschitz
---
broken/BanachFixpoint.v | 25 +++++++++++++++----------
broken/SimpleIntegration.v | 2 +-
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/broken/BanachFixpoint.v b/broken/BanachFixpoint.v
index 348be2ae..e7e5734d 100644
--- a/broken/BanachFixpoint.v
+++ b/broken/BanachFixpoint.v
@@ -14,6 +14,8 @@ Local Notation ball := mspc_ball.
Section BanachFixpoint.
+Add Field Q : (stdlib_field_theory Q).
+
Context `{MetricSpaceClass X} {Xlim : Limit X} {Xcms : CompleteMetricSpaceClass X}.
Context (f : X -> X) `{!IsContraction f q} (x0 : X).
@@ -31,14 +33,16 @@ Instance : PropHolds (0 ≤ d).
Proof. apply msd_nonneg. Qed.
Instance : PropHolds (0 ≤ q).
-Proof. apply (contr_nonneg_mu f q). Qed.
+Proof. apply (lip_nonneg f q).
+(* [apply (lip_nonneg f)] leaves a goal [IsLipschitz f q], which [apply _] solves *)
+Qed.
Instance : PropHolds (q < 1).
-Proof. apply (contr_lt_mu_1 f q). Qed.
+Proof. apply (contr_lt_1 f q). Qed.
Instance : PropHolds (0 < 1 - q).
Proof.
-assert (A := contr_lt_mu_1 f q).
+assert (A := contr_lt_1 f q).
rewrite <- flip_lt_negate in A. apply (strictly_order_preserving (1 +)) in A.
now rewrite plus_negate_r in A.
Qed.
@@ -57,19 +61,19 @@ Proof.
intro m; induction n as [| n IH] using nat_induction.
+ rewrite right_identity; apply mspc_refl.
now rewrite nat_pow_0, plus_negate_r, right_absorb, left_absorb.
-+ apply (mspc_triangle' (d * q^m * (1 - q^n) / (1 - q)) (d * q^(m + n)) (x (m + n))); trivial.
++ apply (mspc_triangle' (d * q^m * (1 - q^n) / (1 - q))%mc (d * q^(m + n))%mc (x (m + n))); trivial.
- rewrite nat_pow_S, nat_pow_exp_plus. field; solve_propholds.
- mc_setoid_replace (m + (1 + n)) with (1 + (m + n)) by ring. apply dist_xn_xSn.
Qed.
Lemma dist_xm_xn' : forall m n : nat, ball (d * q^m / (1 - q)) (x m) (x (m + n)).
Proof.
-intros m n. apply (mspc_monotone (d * q^m * (1 - q^n) / (1 - q))); [| apply dist_xm_xn].
+intros m n. apply (mspc_monotone (d * q^m * (1 - q^n) / (1 - q))%mc); [| apply dist_xm_xn].
apply (order_preserving (.* /(1 - q))). rewrite <- associativity.
apply (order_preserving (d *.)). rewrite <- (mult_1_r (q^m)) at 2.
apply (order_preserving (q^m *.)). rewrite <- (plus_0_r 1) at 2.
apply (order_preserving (1 +)). rewrite <- negate_0.
-apply <- flip_le_negate. solve_propholds.
+apply flip_le_negate. solve_propholds.
Qed.
Lemma Qpower_mc_power (e : Q) (n : nat) : (e ^ n)%Q = (e ^ n)%mc.
@@ -104,7 +108,8 @@ induction n as [| n IH] using nat_induction.
+ rewrite nat_pow_S. transitivity ((1 + a) * (1 + (n : Q) * a)).
- rewrite Nat2Z.inj_add, inject_Z_plus.
stepr (1 + (1 + (n : Q)) * a + (n : Q) * a²) by ring.
- apply nonneg_plus_le_compat_r, nonneg_mult_compat; [apply Qle_Qceiling_nat, le_0_n | apply square_nonneg].
+ (* [apply nonneg_plus_le_compat_r, nonneg_mult_compat.] does not work *)
+ apply nonneg_plus_le_compat_r. apply nonneg_mult_compat; [solve_propholds | apply square_nonneg].
- now apply (order_preserving ((1 + a) *.)) in IH.
Qed.
@@ -150,11 +155,11 @@ Proof.
intros A1 A2.
assert (A3 : 0 < n).
+ let T := type of A2 in match T with (?lhs ≤ _) => apply lt_le_trans with (y := lhs) end; [| trivial].
- apply Qlt_Qceiling_nat; change (0 < / (e * (1 - q))); solve_propholds.
+ apply Q.Qlt_lt_of_nat_inject_Z; change (0 < / (e * (1 - q))); solve_propholds.
+ destruct n as [| n]; [elim (lt_irrefl _ A3) |].
rewrite <- Qpower_mc_power.
apply GeometricCovergenceLemma with (e := e ↾ A1); [solve_propholds .. |].
- apply (Qle_Qceiling_nat _ (S n)), A2.
+ apply (Q.le_Qle_Qceiling_to_nat _ (S n)), A2.
Qed.
Lemma const_x (N : Q -> nat) : d = 0 -> cauchy x N.
@@ -181,7 +186,7 @@ match goal with
end.
+ clear m n; intros m n le_m_n A _.
rewrite <- (cut_minus_le n m); trivial. rewrite plus_comm.
- apply (mspc_monotone (d * q^m / (1 - q))); [| apply dist_xm_xn'].
+ apply (mspc_monotone (d * q^m / (1 - q))%mc); [| apply dist_xm_xn'].
cut (q ^ m ≤ e * (1 - q) / d).
- intro A1. apply (order_preserving (d *.)), (order_preserving (.* /(1 - q))) in A1.
apply (po_proper' A1); [easy | field; split; solve_propholds].
diff --git a/broken/SimpleIntegration.v b/broken/SimpleIntegration.v
index 6b6ebe20..5e1ff39c 100644
--- a/broken/SimpleIntegration.v
+++ b/broken/SimpleIntegration.v
@@ -335,7 +335,7 @@ Section implements_abstract_interface.
simpl. field.
repeat split; discriminate.
do 2 rewrite <- nat_of_P_mult_morphism.
- rewrite plus_comm.
+ rewrite Plus.plus_comm.
rewrite Σ_plus_bound.
setoid_replace ((e + e) / x)%Qpos with ((ec true + ec true) / x + (ec false + ec false) / x)%Qpos.
Focus 2.
From 374c673903093b3a1c6a7e00e2aa5582fa5a30ad Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Wed, 5 Dec 2012 19:57:13 +0100
Subject: [PATCH 040/110] Proving that integral of locally Lipschitz functions
is locally Lipschitz
---
broken/AbstractIntegration.v | 40 ++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 82ada5b3..6646fcb6 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -820,6 +820,46 @@ Qed.
End IntegralOfSum.
+Program Definition int (f : Q -> CR) `{Integral f} (from to : Q) :=
+ if (decide (from ≤ to))
+ then integrate f from (to - from)
+ else -integrate f to (from - to).
+Next Obligation.
+change (0 ≤ to - from). (* without [change], the following [apply] does not work *)
+now apply rings.flip_nonneg_minus.
+Qed.
+Next Obligation.
+change (0 ≤ from - to).
+(* [apply rings.flip_nonneg_minus, orders.le_flip] does not work *)
+apply rings.flip_nonneg_minus; now apply orders.le_flip.
+Qed.
+
+Section IntegralLipschitz.
+
+Notation ball := mspc_ball.
+
+Context (f : Q -> CR) `{!IsLocallyLipschitz f L} `{Integral f, !Integrable f}.
+
+Variables (a r x0 x1 x2 : Q).
+Hypotheses (I1 : ball r a x1) (I2 : ball r a x2).
+
+Let F (x : Q) := int f x0 x.
+
+Let La := L a r.
+
+Lemma int_lip (e M : Q) :
+ (∀ x, ball r a x -> abs (f x) ≤ 'M) ->
+ ball e x1 x2 -> ball (e * (M + La * e)) (F x1) (F x2).
+Proof.
+intros A1 A2.
+apply CRball.gball_CRabs.
+
+
+
+Lemma integral_lipschitz (e : Q) : IsLocallyLipschitz F (* to insert a constant later *).
+
+
+
(*
Lemma integrate_proper
From 35255a8a1a3ca289e7240aa6add749539c0d4241 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 7 Dec 2012 18:27:17 +0100
Subject: [PATCH 041/110] Proving that integral is Lipschitz
---
broken/AbstractIntegration.v | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 6646fcb6..61686d47 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -820,7 +820,13 @@ Qed.
End IntegralOfSum.
-Program Definition int (f : Q -> CR) `{Integral f} (from to : Q) :=
+Add Field Q : (dec_fields.stdlib_field_theory Q).
+
+Section IntegralTotal.
+
+Context (f : Q -> CR) `{Integrable f}.
+
+Program Definition int (from to : Q) :=
if (decide (from ≤ to))
then integrate f from (to - from)
else -integrate f to (from - to).
@@ -834,6 +840,26 @@ change (0 ≤ from - to).
apply rings.flip_nonneg_minus; now apply orders.le_flip.
Qed.
+Lemma integral_additive' (a b : Q) (u v w : QnonNeg) :
+ a + `u = b -> `u + `v = `w -> ∫ f a u + ∫ f b v = ∫ f a w.
+Proof.
+intros A1 A2. change (u + v = w)%Qnn in A2.
+rewrite <- A1, <- A2. now apply integral_additive.
+Qed.
+
+Lemma int_add (a b c : Q) : int a b + int b c = int a c.
+Proof.
+unfold int.
+destruct (decide (a ≤ b)) as [AB | AB];
+destruct (decide (b ≤ c)) as [BC | BC];
+destruct (decide (a ≤ c)) as [AC | AC].
++ apply integral_additive'; simpl; ring.
++
+
+
+
+End IntegralTotal.
+
Section IntegralLipschitz.
Notation ball := mspc_ball.
@@ -851,8 +877,7 @@ Lemma int_lip (e M : Q) :
(∀ x, ball r a x -> abs (f x) ≤ 'M) ->
ball e x1 x2 -> ball (e * (M + La * e)) (F x1) (F x2).
Proof.
-intros A1 A2.
-apply CRball.gball_CRabs.
+intros A1 A2. apply CRball.gball_CRabs.
From acb72627df4d6d5e1c78c1b4c7070f48b36564fb Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Mon, 10 Dec 2012 21:58:17 +0100
Subject: [PATCH 042/110] Proving that integral is Lipschitz
---
broken/AbstractIntegration.v | 76 +++++++++++++++++++++++++++++++++---
broken/Ranges.v | 4 +-
2 files changed, 72 insertions(+), 8 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 61686d47..07b66322 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -822,6 +822,43 @@ End IntegralOfSum.
Add Field Q : (dec_fields.stdlib_field_theory Q).
+Section RingFacts.
+
+Context `{Ring R}.
+
+Lemma plus_left_cancel (z x y : R) : z + x = z + y <-> x = y.
+Proof.
+split.
+(* [apply (left_cancellation (+)).] leaves the goal [LeftCancellation plus z],
+which is solved by [apply _]. Why is it left? *)
++ apply (left_cancellation (+) z).
++ intro A; now rewrite A.
+Qed.
+
+Lemma plus_right_cancel (z x y : R) : x + z = y + z <-> x = y.
+Proof. rewrite (plus_comm x z), (plus_comm y z); apply plus_left_cancel. Qed.
+
+Lemma plus_eq_minus (x y z : R) : x + y = z <-> x = z - y.
+Proof.
+split; intro A.
++ apply (right_cancellation (+) y).
+ now rewrite <- plus_assoc, rings.plus_negate_l, rings.plus_0_r.
++ apply (right_cancellation (+) (-y)).
+ now rewrite <- plus_assoc, rings.plus_negate_r, rings.plus_0_r.
+Qed.
+
+Lemma minus_eq_plus (x y z : R) : x - y = z <-> x = z + y.
+Proof. now rewrite plus_eq_minus, rings.negate_involutive. Qed.
+
+Lemma negate_inj (x y : R) : -x = -y <-> x = y.
+Proof. now rewrite rings.flip_negate, rings.negate_involutive. Qed.
+
+End RingFacts.
+
+Definition Segment (T : Type) := prod T T.
+
+Instance contains_Q : Contains Q (Segment Q) := λ x s, (fst s ⊓ snd s ≤ x ≤ fst s ⊔ snd s).
+
Section IntegralTotal.
Context (f : Q -> CR) `{Integrable f}.
@@ -848,15 +885,40 @@ rewrite <- A1, <- A2. now apply integral_additive.
Qed.
Lemma int_add (a b c : Q) : int a b + int b c = int a c.
-Proof.
+Proof with apply integral_additive'; simpl; ring.
unfold int.
destruct (decide (a ≤ b)) as [AB | AB];
destruct (decide (b ≤ c)) as [BC | BC];
destruct (decide (a ≤ c)) as [AC | AC].
-+ apply integral_additive'; simpl; ring.
-+
++ idtac...
++ assert (A : a ≤ c) by (now transitivity b); elim (AC A).
++ apply minus_eq_plus; symmetry...
++ rewrite minus_eq_plus, (plus_comm (-integrate _ _ _)), <- plus_eq_minus, (plus_comm (integrate _ _ _))...
++ rewrite (plus_comm (-integrate _ _ _)), minus_eq_plus, (plus_comm (integrate _ _ _)); symmetry...
++ rewrite (plus_comm (-integrate _ _ _)), minus_eq_plus, (plus_comm (-integrate _ _ _)), <- plus_eq_minus...
++ assert (b ≤ a) by (now apply orders.le_flip); assert (B : b ≤ c) by (now transitivity a); elim (BC B).
++ rewrite <- rings.negate_plus_distr, negate_inj, (plus_comm (integrate _ _ _))...
+Qed.
+Lemma int_diff (a b c : Q) : int a b - int a c = int c b.
+Proof. apply minus_eq_plus. rewrite plus_comm. symmetry; apply int_add. Qed.
+Lemma int_zero_width (a : Q) : int a a = 0.
+Proof. apply (plus_right_cancel (int a a)); rewrite rings.plus_0_l; apply int_add. Qed.
+
+Lemma int_negate (a b : Q) : int a b = - int b a.
+Proof.
+apply rings.equal_by_zero_sum. rewrite rings.negate_involutive, int_add. apply int_zero_width.
+Qed.
+
+Lemma int_abs_bound (a b M : Q) :
+ (forall x : Q, x ∈ (a, b) -> abs (f x) ≤ 'M) -> abs (int a b) ≤ '(abs (b - a) * M).
+Proof.
+intros A. unfold int. destruct (decide (a ≤ b)) as [AB | AB].
+rewrite abs.abs_nonneg by now apply rings.flip_nonneg_minus.
+rapply integral_abs_bound.
+
+SearchAbout (0 ≤ _ - _).
End IntegralTotal.
@@ -874,10 +936,12 @@ Let F (x : Q) := int f x0 x.
Let La := L a r.
Lemma int_lip (e M : Q) :
- (∀ x, ball r a x -> abs (f x) ≤ 'M) ->
- ball e x1 x2 -> ball (e * (M + La * e)) (F x1) (F x2).
+ (∀ x, ball r a x -> abs (f x) ≤ 'M) -> ball e x1 x2 -> ball (e * M) (F x1) (F x2).
Proof.
-intros A1 A2. apply CRball.gball_CRabs.
+intros A1 A2. apply CRball.gball_CRabs. subst F; cbv beta.
+change (int f x0 x1 - int f x0 x2)%CR with (int f x0 x1 - int f x0 x2).
+rewrite int_diff; [| trivial]. (* Why does it leave the second subgoal [Integrable f]? *)
+
diff --git a/broken/Ranges.v b/broken/Ranges.v
index d7952bf7..865cdcb9 100644
--- a/broken/Ranges.v
+++ b/broken/Ranges.v
@@ -12,8 +12,8 @@ Instance in_CRRange: Container CR (Range CR)
Instance in_sig_Range `{Container A (Range A)} (P: A → Prop): Container (sig P) (Range (sig P))
:= λ r x, In (` (fst r), ` (snd r)) (` x).
-Lemma alt_in_QRange (q: Q) (r: Range Q): q ∈ r <->
+(*Lemma alt_in_QRange (q: Q) (r: Range Q): q ∈ r <->
(∃ e, 0 <= e <= 1 ∧ fst r + e * (snd r - fst r) == q)%Q.
Proof with auto.
-Admitted.
+Admitted.*)
(* also: ∃ e, 0 <= e <= 1 ∧ q == fst r * e + snd r * (1 - e) *)
From f221fd74713220536c63cb9a1ad0ac59364ee90c Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 11 Dec 2012 23:12:44 +0100
Subject: [PATCH 043/110] Proved that the integral of a locally Lipschitz
function is locally Lipschitz
---
broken/AbstractIntegration.v | 126 +++++++++++++++++++++++++++++------
broken/metric.v | 4 +-
2 files changed, 108 insertions(+), 22 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 07b66322..c1f357ac 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -656,7 +656,7 @@ Proof. apply sg_ass, _. Qed.
(* Should this lemma be used to CoRN.reals.fast.CRabs? That file does not use
type class notations from canonical_names like ≤ *)
-Lemma CRabs_nonneg (x : CR) : 0 ≤ CRabs x.
+Lemma CRabs_nonneg (x : CR) : 0 ≤ abs x.
Proof.
apply -> CRabs_cases; [| apply _ | apply _].
split; [trivial | apply (proj1 (rings.flip_nonpos_negate x))].
@@ -753,12 +753,24 @@ Proof. rewrite <- CRmult_scale; change (cast Q CR x * 0 = 0); ring. Qed.
Require Import propholds.
-Lemma integral_abs_bound (from : Q) (width : Qpos) (M : Q) :
+Lemma integral_abs_bound (from : Q) (width : QnonNeg) (M : Q) :
(forall (x : Q), (from ≤ x ≤ from + width) -> CRabs (f x) ≤ 'M) ->
CRabs (∫ f from width) ≤ '(`width * M).
Proof.
intro A. rewrite <- (CRplus_0_r (∫ f from width)), <- CRopp_0.
-apply CRball.as_distance_bound, CRball.rational. rewrite <- (scale_0_r width).
+apply CRball.as_distance_bound. rewrite <- (scale_0_r width).
+rewrite <- CRmult_Qmult, CRmult_scale.
+apply integral_bounded; trivial.
++ apply CRnonNeg_le_0.
+ apply CRle_trans with (y := CRabs (f from)); [apply CRabs_nonneg |].
+ apply A. split; [reflexivity |].
+ apply semirings.nonneg_plus_le_compat_r; change (0 <= width)%Q; Qauto_nonneg.
++ intros x A2. apply CRball.as_distance_bound. rewrite CRdistance_comm.
+ change (CRabs (f x - 0) ≤ 'M).
+ rewrite rings.minus_0_r; now apply A.
+Qed.
+
+(*apply CRball.as_distance_bound, CRball.rational. rewrite <- (scale_0_r width).
assert (A1 : 0 ≤ M).
+ apply CRle_Qle. apply CRle_trans with (y := CRabs (f from)); [apply CRabs_nonneg |].
apply A. split; [reflexivity |].
@@ -767,7 +779,7 @@ assert (A1 : 0 ≤ M).
apply bounded_with_nonneg_radius; [easy |].
intros x A2. apply CRball.gball_CRabs. change (f x - 0%mc)%CR with (f x - 0).
rewrite rings.minus_0_r; now apply A.
-Qed.
+Qed.*)
End IntegralBound.
@@ -855,9 +867,25 @@ Proof. now rewrite rings.flip_negate, rings.negate_involutive. Qed.
End RingFacts.
-Definition Segment (T : Type) := prod T T.
+Definition Range (T : Type) := prod T T.
+
+Instance contains_Q : Contains Q (Range Q) := λ x s, (fst s ⊓ snd s ≤ x ≤ fst s ⊔ snd s).
-Instance contains_Q : Contains Q (Segment Q) := λ x s, (fst s ⊓ snd s ≤ x ≤ fst s ⊔ snd s).
+Lemma Qrange_comm (a b x : Q) : x ∈ (a, b) <-> x ∈ (b, a).
+Admitted.
+
+Lemma range_le (a b : Q) : a ≤ b -> forall x, a ≤ x ≤ b <-> x ∈ (a, b).
+Admitted.
+
+Lemma CRabs_negate (x : CR) : abs (-x) = abs x.
+Proof.
+change (abs (-x)) with (CRabs (-x)).
+rewrite CRabs_opp; reflexivity.
+Qed.
+
+Lemma mspc_ball_convex (x1 x2 r a x : Q) :
+ mspc_ball r a x1 -> mspc_ball r a x2 -> x ∈ (x1, x2) -> mspc_ball r a x.
+Admitted.
Section IntegralTotal.
@@ -914,41 +942,99 @@ Qed.
Lemma int_abs_bound (a b M : Q) :
(forall x : Q, x ∈ (a, b) -> abs (f x) ≤ 'M) -> abs (int a b) ≤ '(abs (b - a) * M).
Proof.
-intros A. unfold int. destruct (decide (a ≤ b)) as [AB | AB].
-rewrite abs.abs_nonneg by now apply rings.flip_nonneg_minus.
-rapply integral_abs_bound.
+intros A. unfold int. destruct (decide (a ≤ b)) as [AB | AB];
+[| pose proof (orders.le_flip _ _ AB); mc_setoid_replace (b - a) with (-(a - b)) by ring;
+ rewrite CRabs_negate, abs.abs_negate];
+rewrite abs.abs_nonneg by (now apply rings.flip_nonneg_minus);
+apply integral_abs_bound; trivial; (* [Integrable f] is not discharged *)
+intros x A1; apply A.
++ apply -> range_le; [| easy].
+ now mc_setoid_replace b with (a + (b - a)) by ring.
++ apply Qrange_comm. apply -> range_le; [| easy].
+ now mc_setoid_replace a with (b + (a - b)) by ring.
+Qed.
-SearchAbout (0 ≤ _ - _).
+(* [SearchAbout (CRabs (- ?x)%CR)] does not find [CRabs_opp] *)
End IntegralTotal.
+Import interfaces.orders orders.semirings.
+
+Definition Qupper_bound (x : CR) := approximate x 1%Qpos + 1.
+
+Lemma Qupper_bound_ge (x : CR) : x ≤ 'Qupper_bound x.
+Admitted.
+(* Similar to
+upper_CRapproximation:
+ ∀ (x : CR) (e : Qpos), x <= (' (approximate x e + e)%Q)%CR
+CRexp.exp_bound_lemma:
+ ∀ x : CR, x <= (' (approximate x (1 # 1)%Qpos + 1)%Q)%CR *)
+
+Lemma CRabs_triang (x y z : CR) : x = y + z -> abs x ≤ abs y + abs z.
+Admitted.
+
Section IntegralLipschitz.
Notation ball := mspc_ball.
-Context (f : Q -> CR) `{!IsLocallyLipschitz f L} `{Integral f, !Integrable f}.
-
-Variables (a r x0 x1 x2 : Q).
-Hypotheses (I1 : ball r a x1) (I2 : ball r a x2).
+Context (f : Q -> CR) (x0 : Q) `{!IsLocallyLipschitz f L} `{Integral f, !Integrable f}.
Let F (x : Q) := int f x0 x.
+Section IntegralLipschitzBall.
+
+Variables (a r x1 x2 : Q).
+
+Hypotheses (I1 : ball r a x1) (I2 : ball r a x2) (r_nonneg : 0 ≤ r).
+
Let La := L a r.
Lemma int_lip (e M : Q) :
- (∀ x, ball r a x -> abs (f x) ≤ 'M) -> ball e x1 x2 -> ball (e * M) (F x1) (F x2).
+ (∀ x, ball r a x -> abs (f x) ≤ 'M) -> ball e x1 x2 -> ball (M * e) (F x1) (F x2).
Proof.
intros A1 A2. apply CRball.gball_CRabs. subst F; cbv beta.
change (int f x0 x1 - int f x0 x2)%CR with (int f x0 x1 - int f x0 x2).
rewrite int_diff; [| trivial]. (* Why does it leave the second subgoal [Integrable f]? *)
+change (abs (int f x2 x1) ≤ '(M * e)).
+transitivity ('(M * abs (x1 - x2))).
++ rewrite mult_comm. apply int_abs_bound; trivial. intros x A3; apply A1, (mspc_ball_convex x2 x1); easy.
++ apply CRle_Qle. assert (0 ≤ M).
+ - apply CRle_Qle. transitivity (abs (f a)); [apply CRabs_nonneg | apply A1, mspc_refl]; easy.
+ - change (M * abs (x1 - x2) ≤ M * e). apply (orders.order_preserving (M *.)).
+ apply gball_Qabs, A2.
+Qed.
+End IntegralLipschitzBall.
+Lemma integral_lipschitz (e : Q) :
+ IsLocallyLipschitz F (λ a r, Qupper_bound (abs (f a)) + L a r * r).
+Proof.
+intros a r r_nonneg. constructor.
++ apply nonneg_plus_compat.
+ - apply CRle_Qle. transitivity (abs (f a)); [apply CRabs_nonneg | apply Qupper_bound_ge].
+ - apply nonneg_mult_compat; [apply (lip_nonneg (restrict f a r)) |]; auto.
+ (* Not good to provide [(restrict f a r)]. [IsLipschitz (restrict f a r) (L a r)] is generated *)
++ (* PG ignores the following tactic *) idtac. intros x1 x2 d A.
+ destruct x1 as [x1 A1]; destruct x2 as [x2 A2].
+ change (ball ((Qupper_bound (abs (f a)) + L a r * r) * d) (F x1) (F x2)).
+ apply (int_lip a r); trivial.
+ intros x B. transitivity (abs (f a) + '(L a r * r)).
+ - transitivity (abs (f a) + abs (f x - f a)); [apply CRabs_triang; ring |].
+ apply (order_preserving (abs (f a) +)).
+ apply CRball.gball_CRabs. apply gball_sym.
+ (* There should be a lemma similar to metric.luc for locally Lipschitz:
+ the following invocation of lip_prf is too complex *)
+ assert (B1 : ball r a a) by now apply mspc_refl.
+ change (ball (L a r * r) (restrict f a r (a ↾ B1)) (restrict f a r (x ↾ B))).
+ specialize (IsLocallyLipschitz0 a r r_nonneg).
+ now apply lip_prf.
+ - rewrite <- CRplus_Qplus.
+ change (abs (f a) + ' (L a r * r) ≤ ' Qupper_bound (abs (f a)) + ' (L a r * r)).
+ apply plus_le_compat; (* does not work wothout [change] *)
+ [apply Qupper_bound_ge | reflexivity].
+Qed.
-
-Lemma integral_lipschitz (e : Q) : IsLocallyLipschitz F (* to insert a constant later *).
-
-
-
+End IntegralLipschitz.
(*
Lemma integrate_proper
diff --git a/broken/metric.v b/broken/metric.v
index c6cba5f7..3eaee119 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -417,9 +417,9 @@ Section LocallyLipschitz.
Context `{MetricSpaceClass X, ExtMetricSpaceClass Y}.
Class IsLocallyLipschitz (f : X -> Y) (L : X -> Q -> Q) :=
- llip_prf : forall (x : X) (r : Q), IsLipschitz (restrict f x r) (L x r).
+ llip_prf : forall (x : X) (r : Q), 0 ≤ r -> IsLipschitz (restrict f x r) (L x r).
-Global Arguments llip_prf f L {_} x r.
+Global Arguments llip_prf f L {_} x r _.
Global Instance lip_llip (f : X -> Y) `{!IsLipschitz f L} : IsLocallyLipschitz f (λ _ _, L).
Proof.
From 93aa644dfcf26d34d6ea2b5df8a280c1605f35b6 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Mon, 17 Dec 2012 15:04:56 +0100
Subject: [PATCH 044/110] Moved some lemmas to other parts of CoRN
---
broken/AbstractIntegration.v | 81 ------------------------------------
broken/BanachFixpoint.v | 6 ++-
broken/metric.v | 73 +++++---------------------------
metric2/Complete.v | 17 ++++++++
metric2/Prelength.v | 8 ++++
model/structures/Qinf.v | 16 ++++++-
reals/fast/CRabs.v | 21 ++++++++++
reals/fast/CRball.v | 17 ++++++++
stdlib_omissions/Q.v | 3 ++
tactics/Qauto.v | 9 ++--
10 files changed, 101 insertions(+), 150 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index c1f357ac..8b19a95d 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -23,94 +23,13 @@ Ltac done :=
(* | case not_locked_false_eq_true; assumption*)
| match goal with H : ~ _ |- _ => solve [case H; trivial] end ].
-(*Notation Qinf := Qinf.T.
-
-Module Qinf.
-
-Definition le (x y : Qinf) : Prop :=
-match y with
-| Qinf.finite b =>
- match x with
- | Qinf.finite a => Qle a b
- | Qinf.infinite => False
- end
-| Qinf.infinite => True
-end.
-
-Instance: Proper (Qinf.eq ==> Qinf.eq ==> iff) le.
-Proof.
-intros [x1 |] [x2 |] A1 [y1 |] [y2 |] A2; revert A1 A2;
-unfold Qinf.eq, canonical_names.equiv, stdlib_rationals.Q_eq; simpl; intros A1 A2;
-try contradiction; try reflexivity.
-rewrite A1, A2; reflexivity.
-Qed.
-
-End Qinf.
-
-Instance Qinf_le : canonical_names.Le Qinf := Qinf.le.*)
-
Open Local Scope Q_scope.
Open Local Scope uc_scope.
Open Local Scope CR_scope.
-Lemma lift_eq_complete {X Y : MetricSpace} (f g : Complete X --> Complete Y) :
- (forall x : X, f (Cunit x) [=] g (Cunit x)) -> (forall x : Complete X, f x [=] g x).
-Proof.
-intros A x. apply ball_eq; intro e.
-set (e2 := ((1#2) * e)%Qpos).
-set (d := QposInf_min (mu f e2) (mu g e2)).
-setoid_replace e with (e2 + e2)%Qpos by (subst e2; QposRing).
-apply ball_triangle with (b := f (Cunit (approximate x d))).
-+ apply (UniformContinuity.uc_prf f).
- apply (ball_ex_weak_le _ d); [apply QposInf_min_lb_l | apply ball_ex_approx_r].
-+ rewrite A. apply (UniformContinuity.uc_prf g).
- apply (ball_ex_weak_le _ d); [apply QposInf_min_lb_r | apply ball_ex_approx_l].
-Qed.
-
(* [SearchAbout ((Cmap _ _) (Cunit _)).] does not find anything, but it
should find metric2.Prelength.fast_MonadLaw3 *)
-Corollary map_eq_complete {X Y : MetricSpace} {plX : PrelengthSpace X} (f g : X --> Y) :
- (forall x : X, f x [=] g x) -> (forall x : Complete X, Cmap plX f x [=] Cmap plX g x).
-Proof.
-intros A x. apply lift_eq_complete. intro y. rewrite !fast_MonadLaw3, A. reflexivity.
-Qed.
-
-Lemma CRabs_scale (a : Q) (x : CR) : CRabs (scale a x) == scale (Qabs a) (CRabs x).
-Proof.
-apply lift_eq_complete with (f := uc_compose CRabs (scale a)) (g := uc_compose (scale (Qabs a)) CRabs).
-intros q e1 e2. change (ball (e1 + e2) (Qabs (a * q)) (Qabs a * Qabs q)%Q).
-apply <- ball_eq_iff. apply Qabs_Qmult.
-Qed.
-
-(* Another proof *)
-
-Lemma CRabs_scale' (a : Q) (x : CR) : CRabs (scale a x) == scale (Qabs a) (CRabs x).
-Proof.
-unfold CRabs, scale. setoid_rewrite <- fast_MonadLaw2.
-apply map_eq_complete. intro q. apply Qabs_Qmult.
-Qed.
-
-Corollary CRabs_CRmult_Q (a : Q) (x : CR) : CRabs ('a * x) == '(Qabs a) * (CRabs x).
-Proof. rewrite !CRmult_scale. apply CRabs_scale. Qed.
-
-Lemma gball_CRmult_Q (e a : Q) (x y : CR) :
- gball e x y -> gball (Qabs a * e) ('a * x) ('a * y).
-Proof.
-intro A. apply CRball.gball_CRabs.
-setoid_replace ('a * x - 'a * y) with ('a * (x - y)) by ring.
-rewrite CRabs_CRmult_Q, <- CRmult_Qmult.
-assert (0 <= 'Qabs a) by (apply CRle_Qle; auto).
-apply (orders.order_preserving (CRmult (' Qabs a))).
-now apply CRball.gball_CRabs.
-Qed.
-
-Corollary gball_CRmult_Q_nonneg (e a : Q) (x y : CR) :
- (0 <= a)%Q -> gball e x y -> gball (a * e) ('a * x) ('a * y).
-Proof.
-intros A1 A2. rewrite <- (Qabs_pos a) at 1; [apply gball_CRmult_Q |]; easy.
-Qed.
-
(** Any nonnegative width can be split up into an integral number of
equal-sized pieces no bigger than a given bound: *)
diff --git a/broken/BanachFixpoint.v b/broken/BanachFixpoint.v
index e7e5734d..bb47e5b2 100644
--- a/broken/BanachFixpoint.v
+++ b/broken/BanachFixpoint.v
@@ -177,8 +177,8 @@ Qed.
Lemma cauchy_x : cauchy x (λ e, Z.to_nat (Qceiling (d / (e * (1 - q)²))%mc)).
Proof.
assert (d_nonneg : 0 ≤ d) by solve_propholds.
-assert (d_pos_0 : 0 < d \/ 0 = d) by now apply le_lt_eq.
-destruct d_pos_0 as [d_pos | d_0]; [| now apply const_x].
+assert (d_pos_0 : 0 = d \/ 0 < d) by now apply le_equiv_lt.
+destruct d_pos_0 as [d_0 | d_pos]; [now apply const_x |].
intros e e_pos.
(* without loss of generality, m ≤ n *)
match goal with
@@ -199,6 +199,8 @@ end.
- intros; apply mspc_symm; now apply A.
Qed.
+SearchAbout (?x = ?y ∨ ?x < ?y).
+
Let a := lim (reg_fun x _ cauchy_x).
Lemma banach_fixpoint : f a = a.
diff --git a/broken/metric.v b/broken/metric.v
index 3eaee119..6e5a22ed 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -14,7 +14,7 @@ Import Qround Qpower Qinf.notations.
Set Printing Coercions.
-Notation "x ²" := (x * x) (at level 30) : mc_scope.
+(*Notation "x ²" := (x * x) (at level 30) : mc_scope.*)
Definition comp_inf {X Z : Type} (g : Q -> Z) (f : X -> Qinf) (inf : Z) (x : X) :=
match (f x) with
@@ -22,49 +22,17 @@ match (f x) with
| Qinf.infinite => inf
end.
-Lemma Qplus_pos_compat (x y : Q) : (0 < x -> 0 < y -> 0 < x + y)%Q.
-Proof. intros; apply Q.Qplus_lt_le_0_compat; [| apply Qlt_le_weak]; trivial. Qed.
-
-Ltac Qauto_pos :=
- repeat (first [ assumption
- | constructor
- | apply Qplus_pos_compat
- | apply Q.Qmult_lt_0_compat
- | apply Qinv_lt_0_compat]);
- auto with *.
-
+(* [po_proper'] is useful for proving [a2 ≤ b2] from [H : a1 ≤ b1] when
+[a1 = a2] and [b1 = b2]. Then [apply (po_proper' H)] generates [a1 = a2]
+and [b1 = b2]. Should it be moved to MathClasses? *)
Lemma po_proper' `{PartialOrder A} {x1 x2 y1 y2 : A} :
x1 ≤ y1 -> x1 = x2 -> y1 = y2 -> x2 ≤ y2.
Proof. intros A1 A2 A3; now apply (po_proper _ _ A2 _ _ A3). Qed.
-Lemma le_not_eq `{FullPartialOrder A} (x y : A) : x ≤ y -> x ≶ y -> x < y.
-Proof. intros ? ?; apply lt_iff_le_apart; now split. Qed.
-
-(* Use orders.orders.le_equiv_lt instead *)
-Lemma le_lt_eq `{@FullPartialOrder B Be Bap Ble Blt} `{@TrivialApart B Be Bap}
- `{forall x y : B, Decision (x = y)} (x y : B) : x ≤ y ↔ x < y ∨ x = y.
-Proof.
-assert (Setoid B) by apply po_setoid.
-split; intro A.
-+ destruct (decide (x = y)) as [A1 | A1]; [now right |].
- apply trivial_apart in A1. left; apply lt_iff_le_apart; now split.
-+ destruct A as [A | A].
- - apply lt_iff_le_apart in A; now destruct A.
- - now rewrite A.
-Qed.
-
-Lemma neq_symm `{Ae : Equiv X} `{!Symmetric Ae} (x y : X) : x ≠ y -> y ≠ x.
-Proof. intros A1 A2; apply A1; now symmetry. Qed.
-
-Lemma plus_comm `{SemiRing R} : Commutative (+).
-Proof. eapply commonoid_commutative; apply _. Qed.
-
-Lemma plus_assoc `{SemiRing R} : forall x y z : R, x + (y + z) = (x + y) + z.
-Proof. apply sg_ass, _. Qed.
-
-Instance pos_ne_0 : forall `{StrictSetoidOrder A} `{Zero A} (x : A),
+(* This is a special case of lt_ne_flip. Do we need it? *)
+(*Instance pos_ne_0 : forall `{StrictSetoidOrder A} `{Zero A} (x : A),
PropHolds (0 < x) -> PropHolds (x ≠ 0).
-Proof. intros; now apply lt_ne_flip. Qed.
+Proof. intros; now apply lt_ne_flip. Qed.*)
Definition ext_equiv' `{Equiv A} `{Equiv B} : Equiv (A → B) :=
λ f g, ∀ x : A, f x = g x.
@@ -113,25 +81,6 @@ Instance Qpos_inv : DecRecip Qpos := Qpossec.Qpos_inv.
Instance Qinf_one : One Qinf := 1%Q.
*)
-Module Qinf.
-
-Definition lt (x y : Qinf) : Prop :=
-match x, y with
-| Qinf.finite a, Qinf.finite b => Qlt a b
-| Qinf.finite _, Qinf.infinite => True
-| Qinf.infinite, _ => False
-end.
-
-Instance: Proper (=) lt.
-Proof.
-intros [x1 |] [x2 |] A1 [y1 |] [y2 |] A2; revert A1 A2;
-unfold Qinf.eq, Q_eq, equiv; simpl; intros A1 A2;
-try contradiction; try reflexivity.
-rewrite A1, A2; reflexivity.
-Qed.
-
-End Qinf.
-
Instance Qinf_lt : Lt Qinf := Qinf.lt.
(*
@@ -230,10 +179,6 @@ try (unfold Qinf.eq, equiv in *; contradiction).
now apply mspc_triangle with (b := y2); [rewrite Ee1e2 | apply mspc_symm].
Qed.
-(*Check _ : Le Qinf.T.
-Lemma mspc_refl ∀ e : Q, 0 ≤ e → Reflexive (ball e);*)
-
-
Lemma mspc_triangle' :
∀ (q1 q2 : Q) (x2 x1 x3 : X) (q : Q),
q1 + q2 = q → ball q1 x1 x2 → ball q2 x2 x3 → ball q x1 x3.
@@ -327,6 +272,10 @@ End UniformContinuity.
Global Arguments UniformlyContinuous X {_} Y {_}.
+Class Map (A : Type -> Type -> Type) := map : forall X Y, A X Y -> X -> Y.
+
+Instance : Map UniformlyContinuous.
+
Section LocalUniformContinuity.
Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
diff --git a/metric2/Complete.v b/metric2/Complete.v
index 85738291..14155328 100644
--- a/metric2/Complete.v
+++ b/metric2/Complete.v
@@ -369,6 +369,23 @@ Proof.
Qed.
(* end hide *)
+(** If two functions between complete metric spaces are equal on the images
+of [Cunit], then they are equal everywhere *)
+
+Lemma lift_eq_complete {X Y : MetricSpace} (f g : Complete X --> Complete Y) :
+ (forall x : X, f (Cunit x) [=] g (Cunit x)) -> (forall x : Complete X, f x [=] g x).
+Proof.
+intros A x. apply ball_eq; intro e.
+set (e2 := ((1#2) * e)%Qpos).
+set (d := QposInf_min (mu f e2) (mu g e2)).
+setoid_replace e with (e2 + e2)%Qpos by (subst e2; QposRing).
+apply ball_triangle with (b := f (Cunit (approximate x d))).
++ apply (UniformContinuity.uc_prf f).
+ apply (ball_ex_weak_le _ d); [apply QposInf_min_lb_l | apply ball_ex_approx_r].
++ rewrite A. apply (UniformContinuity.uc_prf g).
+ apply (ball_ex_weak_le _ d); [apply QposInf_min_lb_r | apply ball_ex_approx_l].
+Qed.
+
Section Faster.
Variable X : MetricSpace.
diff --git a/metric2/Prelength.v b/metric2/Prelength.v
index 5bbf849b..9e0b9958 100644
--- a/metric2/Prelength.v
+++ b/metric2/Prelength.v
@@ -347,6 +347,14 @@ Proof.
apply Cmap_correct.
Qed.
+(** [Cmap] preserves extensional equality *)
+
+Lemma map_eq_complete {X Y : MetricSpace} {plX : PrelengthSpace X} (f g : X --> Y) :
+ (forall x : X, f x [=] g x) -> (forall x : Complete X, Cmap plX f x [=] Cmap plX g x).
+Proof.
+intros A x. apply lift_eq_complete. intro y. rewrite !fast_MonadLaw3, A. reflexivity.
+Qed.
+
End Map.
Section fast_Monad_Laws.
diff --git a/model/structures/Qinf.v b/model/structures/Qinf.v
index 44007b41..8109f142 100644
--- a/model/structures/Qinf.v
+++ b/model/structures/Qinf.v
@@ -45,6 +45,21 @@ Proof.
now rewrite E, F.
Qed.
+Definition lt (x y : Qinf) : Prop :=
+match x, y with
+| Qinf.finite a, Qinf.finite b => Qlt a b
+| Qinf.finite _, Qinf.infinite => True
+| Qinf.infinite, _ => False
+end.
+
+Instance: Proper (=) lt.
+Proof.
+intros [x1 |] [x2 |] A1 [y1 |] [y2 |] A2; revert A1 A2;
+unfold Qinf.eq, Q_eq, equiv; simpl; intros A1 A2;
+try contradiction; try reflexivity.
+rewrite A1, A2; reflexivity.
+Qed.
+
Instance: Zero T := finite 0%Q.
Instance plus: Plus T := λ x y,
@@ -82,7 +97,6 @@ Module notations.
Global Infix "==" := eq: Qinf_scope.
Global Infix "<=" := le: Qinf_scope.
Global Infix "+" := plus: Qinf_scope.
- Global Infix "*" := mult: Qinf_scope.
Global Notation Qinf := T.
End notations.
diff --git a/reals/fast/CRabs.v b/reals/fast/CRabs.v
index 62393ecf..63ffa844 100644
--- a/reals/fast/CRabs.v
+++ b/reals/fast/CRabs.v
@@ -201,6 +201,27 @@ Proof with auto.
apply -> CRle_opp...
Qed.
+Lemma CRabs_scale (a : Q) (x : CR) : CRabs (scale a x) == scale (Qabs a) (CRabs x).
+Proof.
+apply lift_eq_complete with (f := uc_compose CRabs (scale a)) (g := uc_compose (scale (Qabs a)) CRabs).
+intros q e1 e2. change (ball (e1 + e2) (Qabs (a * q)) (Qabs a * Qabs q)%Q).
+apply <- ball_eq_iff. apply Qabs_Qmult.
+Qed.
+
+(* begin hide *)
+(* Another proof *)
+
+Lemma CRabs_scale' (a : Q) (x : CR) : CRabs (scale a x) == scale (Qabs a) (CRabs x).
+Proof.
+unfold CRabs, scale. setoid_rewrite <- fast_MonadLaw2.
+apply map_eq_complete. intro q. apply Qabs_Qmult.
+Qed.
+
+(* end hide *)
+
+Lemma CRabs_CRmult_Q (a : Q) (x : CR) : CRabs ('a * x) == '(Qabs a) * (CRabs x).
+Proof. rewrite !CRmult_scale. apply CRabs_scale. Qed.
+
Definition CRdistance (x y: CR): CR := CRabs (x - y).
Lemma CRdistance_CRle (r x y: CR): x - r <= y /\ y <= x + r <-> CRdistance x y <= r.
diff --git a/reals/fast/CRball.v b/reals/fast/CRball.v
index 10ef4aa1..1c462013 100644
--- a/reals/fast/CRball.v
+++ b/reals/fast/CRball.v
@@ -90,6 +90,23 @@ Qed. (* todo: clean up *)
Lemma gball_CRabs (r : Q) (x y : CR) : gball r x y <-> CRabs (x - y) <= ' r.
Proof. rewrite rational. apply as_distance_bound. Qed.
+Lemma gball_CRmult_Q (e a : Q) (x y : CR) :
+ gball e x y -> gball (Qabs a * e) ('a * x) ('a * y).
+Proof.
+intro A. apply CRball.gball_CRabs.
+setoid_replace ('a * x - 'a * y) with ('a * (x - y)) by ring.
+rewrite CRabs_CRmult_Q, <- CRmult_Qmult.
+assert (0 <= 'Qabs a) by (apply CRle_Qle; auto).
+apply (orders.order_preserving (CRmult (' Qabs a))).
+now apply CRball.gball_CRabs.
+Qed.
+
+Lemma gball_CRmult_Q_nonneg (e a : Q) (x y : CR) :
+ (0 <= a)%Q -> gball e x y -> gball (a * e) ('a * x) ('a * y).
+Proof.
+intros A1 A2. rewrite <- (Qabs_pos a) at 1; [apply gball_CRmult_Q |]; easy.
+Qed.
+
Module notations.
Notation CRball := CRball.
diff --git a/stdlib_omissions/Q.v b/stdlib_omissions/Q.v
index aa74f841..69f35424 100644
--- a/stdlib_omissions/Q.v
+++ b/stdlib_omissions/Q.v
@@ -334,6 +334,9 @@ Proof.
apply Qplus_le_compat; assumption.
Qed.
+Lemma Qplus_pos_compat (x y : Q) : 0 < x -> 0 < y -> 0 < x + y.
+Proof. intros; apply Qplus_lt_le_0_compat; [| apply Qlt_le_weak]; trivial. Qed.
+
Lemma Qminus_less (x y : Q) : 0 <= y -> x - y <= x.
Proof.
intro H. rewrite <- (Qplus_0_r x) at 2. apply Qplus_le_r. change 0 with (-0).
diff --git a/tactics/Qauto.v b/tactics/Qauto.v
index 80e57864..6712c997 100644
--- a/tactics/Qauto.v
+++ b/tactics/Qauto.v
@@ -26,10 +26,11 @@ Require Import Qabs.
Require Import CornTac.
Ltac Qauto_pos :=
- repeat (first [assumption
- |constructor
- |apply: plus_resp_pos;simpl
- |apply: mult_resp_pos;simpl]);
+ repeat (first [ assumption
+ | constructor
+ | apply Q.Qplus_pos_compat
+ | apply Q.Qmult_lt_0_compat
+ | apply Qinv_lt_0_compat]);
auto with *.
Ltac Qauto_nonneg :=
From 00c84e0f3a3d2ad0ccee2d3dc89ab7a137bc4686 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Mon, 17 Dec 2012 22:43:00 +0100
Subject: [PATCH 045/110] Defined class Map for types that can be converted to
functions (an analog of cast)
---
broken/metric.v | 53 +++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 49 insertions(+), 4 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index 6e5a22ed..61909110 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -1,7 +1,7 @@
Require Import
QArith
theory.setoids (* Equiv Prop *) theory.products
- stdlib_rationals Qinf Qpossec QposInf QnonNeg abstract_algebra QType_rationals additional_operations.
+ stdlib_rationals (*Qinf*) Qpossec (*QposInf*) (*QnonNeg*) abstract_algebra QType_rationals additional_operations.
(*Import (*QnonNeg.notations*) QArith.*)
Require Import Qauto QOrderedType.
(*Require Import orders.*)
@@ -81,7 +81,9 @@ Instance Qpos_inv : DecRecip Qpos := Qpossec.Qpos_inv.
Instance Qinf_one : One Qinf := 1%Q.
*)
-Instance Qinf_lt : Lt Qinf := Qinf.lt.
+Instance Qinf_lt : Lt Qinf.
+Admitted.
+(* := Qinf.lt.*)
(*
Ltac mc_simpl := unfold
@@ -266,15 +268,58 @@ Proof.
intros x1 x2 A. apply -> mspc_eq. intros e e_pos. apply (uc_prf f mu); trivial.
pose proof (uc_pos f mu e e_pos) as ?.
destruct (mu e); [apply mspc_eq; trivial | apply mspc_inf].
+admit.
Qed.
End UniformContinuity.
Global Arguments UniformlyContinuous X {_} Y {_}.
-Class Map (A : Type -> Type -> Type) := map : forall X Y, A X Y -> X -> Y.
+Class Map (A X Y : Type) := map : A -> X -> Y.
-Instance : Map UniformlyContinuous.
+Instance uniformly_continuous_map `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y} :
+ Map (UniformlyContinuous X Y) X Y := λ f, f.
+
+Section FunctionMetricSpace.
+
+Context `{NonEmpty X, ExtMetricSpaceClass Y, Map T X Y}.
+
+Global Instance func_space_ball : MetricSpaceBall T :=
+ λ e f g, forall x, ball e (map f x) (map g x).
+
+Lemma FuncBallProper : Proper ((=) ==> (≡) ==> (≡) ==> iff) ball.
+Proof.
+intros q1 q2 A1 f1 f2 A2 g1 g2 A3; rewrite A2, A3.
+split; intros A4 x; [rewrite <- A1 | rewrite A1]; apply A4.
+Qed.
+
+Global Instance : ExtMetricSpaceClass T.
+Proof.
+match goal with | H : NonEmpty X |- _ => destruct H as [x0] end.
+constructor.
++ apply FuncBallProper.
++ intros f g x; apply mspc_inf.
++ intros e e_neg f g A. specialize (A x0). eapply mspc_negative; eauto.
++ intros e e_nonneg f x; now apply mspc_refl.
++ intros e f g A x; now apply mspc_symm.
++ intros e1 e2 f g h A1 A2 x. now apply mspc_triangle with (b := g x).
++ intros e f g A x. apply mspc_closed; intros d A1. now apply A.
+Qed.
+
+End FunctionMetricSpace.
+
+(*Section Test.
+
+Context `{ExtMetricSpaceClass X} `{ExtMetricSpaceClass Y}.
+Context `{NonEmpty X}.
+
+Check _ : MetricSpaceBall (UniformlyContinuous X Y).
+Require Import CRtrans.
+SearchAbout CR "min".
+Check _ : MetricSpaceBall (X -> Y).
+
+Goal forall `{ExtMetricSpaceClass X} `{ExtMetricSpaceClass Y},
+ ExtMetricSpaceClass (UniformlyContinuous X Y).*)
Section LocalUniformContinuity.
From 68f5cdf8ff01bc234d3e61f76a6d8b332ccd91a0 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 18 Dec 2012 13:55:09 +0100
Subject: [PATCH 046/110] Compiled lemmas moved to other parts of CoRN
---
metric2/Prelength.v | 16 ++++++++--------
metric2/StepFunction.v | 2 +-
model/structures/Qinf.v | 10 +++++-----
reals/fast/CRball.v | 6 +++---
4 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/metric2/Prelength.v b/metric2/Prelength.v
index 9e0b9958..cf35fa48 100644
--- a/metric2/Prelength.v
+++ b/metric2/Prelength.v
@@ -347,14 +347,6 @@ Proof.
apply Cmap_correct.
Qed.
-(** [Cmap] preserves extensional equality *)
-
-Lemma map_eq_complete {X Y : MetricSpace} {plX : PrelengthSpace X} (f g : X --> Y) :
- (forall x : X, f x [=] g x) -> (forall x : Complete X, Cmap plX f x [=] Cmap plX g x).
-Proof.
-intros A x. apply lift_eq_complete. intro y. rewrite !fast_MonadLaw3, A. reflexivity.
-Qed.
-
End Map.
Section fast_Monad_Laws.
@@ -381,6 +373,14 @@ End fast_Monad_Laws.
Open Local Scope uc_scope.
+(** [Cmap] preserves extensional equality *)
+
+Lemma map_eq_complete {X Y : MetricSpace} {plX : PrelengthSpace X} (f g : X --> Y) :
+ (forall x : X, f x [=] g x) -> (forall x : Complete X, Cmap plX f x [=] Cmap plX g x).
+Proof.
+intros A x. apply lift_eq_complete. intro y. rewrite !fast_MonadLaw3, A. reflexivity.
+Qed.
+
(** Similarly we define a new Cbind *)
Definition Cbind X Y plX (f:X-->Complete Y) := uc_compose Cjoin (Cmap plX f).
diff --git a/metric2/StepFunction.v b/metric2/StepFunction.v
index bca9f851..1c6a7fc6 100644
--- a/metric2/StepFunction.v
+++ b/metric2/StepFunction.v
@@ -181,7 +181,7 @@ Proof.
induction s; induction t; induction u; try contradiction; simpl; auto with *.
intros; transitivity x0; assumption.
intros [H0 [H1 H2]] [H3 [H4 H5]].
- repeat split; eauto with *.
+ repeat split; [rewrite H0 | |]; eauto.
Qed.
(* begin hide *)
Hint Resolve StepF_Qeq_refl StepF_Qeq_sym StepF_Qeq_trans.
diff --git a/model/structures/Qinf.v b/model/structures/Qinf.v
index 8109f142..99800ff7 100644
--- a/model/structures/Qinf.v
+++ b/model/structures/Qinf.v
@@ -45,17 +45,17 @@ Proof.
now rewrite E, F.
Qed.
-Definition lt (x y : Qinf) : Prop :=
+Definition lt (x y : T) : Prop :=
match x, y with
-| Qinf.finite a, Qinf.finite b => Qlt a b
-| Qinf.finite _, Qinf.infinite => True
-| Qinf.infinite, _ => False
+| finite a, finite b => Qlt a b
+| finite _, infinite => True
+| infinite, _ => False
end.
Instance: Proper (=) lt.
Proof.
intros [x1 |] [x2 |] A1 [y1 |] [y2 |] A2; revert A1 A2;
-unfold Qinf.eq, Q_eq, equiv; simpl; intros A1 A2;
+unfold eq, Q_eq, equiv; simpl; intros A1 A2;
try contradiction; try reflexivity.
rewrite A1, A2; reflexivity.
Qed.
diff --git a/reals/fast/CRball.v b/reals/fast/CRball.v
index 1c462013..253fc481 100644
--- a/reals/fast/CRball.v
+++ b/reals/fast/CRball.v
@@ -1,5 +1,5 @@
Require Import
- CRArith CRabs.
+ Qabs CRArith CRabs.
Hint Immediate CRle_refl. (* todo: move *)
@@ -93,12 +93,12 @@ Proof. rewrite rational. apply as_distance_bound. Qed.
Lemma gball_CRmult_Q (e a : Q) (x y : CR) :
gball e x y -> gball (Qabs a * e) ('a * x) ('a * y).
Proof.
-intro A. apply CRball.gball_CRabs.
+intro A. apply gball_CRabs.
setoid_replace ('a * x - 'a * y) with ('a * (x - y)) by ring.
rewrite CRabs_CRmult_Q, <- CRmult_Qmult.
assert (0 <= 'Qabs a) by (apply CRle_Qle; auto).
apply (orders.order_preserving (CRmult (' Qabs a))).
-now apply CRball.gball_CRabs.
+now apply gball_CRabs.
Qed.
Lemma gball_CRmult_Q_nonneg (e a : Q) (x y : CR) :
From 592b97576b08747aa764cde62e79f8fc5bfadfb5 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 18 Dec 2012 14:06:44 +0100
Subject: [PATCH 047/110] Added lemmas in math-classes and proved that
functions between metric spaced form a metric space w.r.t. the supremum
distance
---
broken/metric.v | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index 61909110..aa3ccec6 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -1,7 +1,7 @@
Require Import
QArith
theory.setoids (* Equiv Prop *) theory.products
- stdlib_rationals (*Qinf*) Qpossec (*QposInf*) (*QnonNeg*) abstract_algebra QType_rationals additional_operations.
+ stdlib_rationals Qinf (*Qpossec QposInf QnonNeg*) abstract_algebra QType_rationals additional_operations.
(*Import (*QnonNeg.notations*) QArith.*)
Require Import Qauto QOrderedType.
(*Require Import orders.*)
@@ -302,7 +302,7 @@ constructor.
+ intros e e_neg f g A. specialize (A x0). eapply mspc_negative; eauto.
+ intros e e_nonneg f x; now apply mspc_refl.
+ intros e f g A x; now apply mspc_symm.
-+ intros e1 e2 f g h A1 A2 x. now apply mspc_triangle with (b := g x).
++ intros e1 e2 f g h A1 A2 x. now apply mspc_triangle with (b := map g x).
+ intros e f g A x. apply mspc_closed; intros d A1. now apply A.
Qed.
From b4636a1d2f522babd376b7e0bb246de0549ac0f0 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 21 Dec 2012 20:28:08 +0100
Subject: [PATCH 048/110] Picard iterations
---
broken/Picard.v | 4 +-
broken/metric.v | 139 +++++++++++++++++++-----------------------------
2 files changed, 56 insertions(+), 87 deletions(-)
diff --git a/broken/Picard.v b/broken/Picard.v
index 89b6c08e..b2f79639 100644
--- a/broken/Picard.v
+++ b/broken/Picard.v
@@ -1,6 +1,6 @@
Require Import CRArith CRtrans CRconst Qmetric Utf8.
-Require Import ProductMetric CompleteProduct CPoly_Newton.
-Require Import metric2.Classified.
+Require Import ProductMetric CompleteProduct (*CPoly_Newton*).
+Require Import (*metric2.*)Classified.
Notation "X × Y" := (ProductMS X Y) (at level 40).
Notation "f >> g" := (Cbind_slow f ∘ g) (at level 50).
diff --git a/broken/metric.v b/broken/metric.v
index aa3ccec6..37c19d40 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -1,7 +1,8 @@
Require Import
QArith
theory.setoids (* Equiv Prop *) theory.products
- stdlib_rationals Qinf (*Qpossec QposInf QnonNeg*) abstract_algebra QType_rationals additional_operations.
+ stdlib_rationals (*Qinf*) (*Qpossec QposInf QnonNeg*) abstract_algebra QType_rationals additional_operations.
+Require Qinf.
(*Import (*QnonNeg.notations*) QArith.*)
Require Import Qauto QOrderedType.
(*Require Import orders.*)
@@ -81,9 +82,7 @@ Instance Qpos_inv : DecRecip Qpos := Qpossec.Qpos_inv.
Instance Qinf_one : One Qinf := 1%Q.
*)
-Instance Qinf_lt : Lt Qinf.
-Admitted.
-(* := Qinf.lt.*)
+Instance Qinf_lt : Lt Qinf := Qinf.lt.
(*
Ltac mc_simpl := unfold
@@ -239,6 +238,44 @@ Qed.
End SubMetricSpace.
+(** We define [Map T X Y] if there is a coercion map from T to (X -> Y),
+i.e., T is a type of functions. It can be instatiated with (locally)
+uniformly continuous function, (locally) Lipschitz functions, contractions
+and so on. For instances T of [Map] we can define supremum metric ball
+(i.e., L∞ metric) and prove that T is a metric space. [Map T X Y] is
+similar to [Cast T (X -> Y)], but [cast] has types as explicit arguments,
+so for [f : T] one would have to write [cast _ _ f x] instead of [map f x]. *)
+
+Class Map (T X Y : Type) := map : T -> X -> Y.
+
+Section FunctionMetricSpace.
+
+Context `{NonEmpty X, ExtMetricSpaceClass Y, Map T X Y}.
+
+Global Instance Linf_metric_space_ball : MetricSpaceBall T :=
+ λ e f g, forall x, ball e (map f x) (map g x).
+
+Lemma FuncBallProper : Proper ((=) ==> (≡) ==> (≡) ==> iff) ball.
+Proof.
+intros q1 q2 A1 f1 f2 A2 g1 g2 A3; rewrite A2, A3.
+split; intros A4 x; [rewrite <- A1 | rewrite A1]; apply A4.
+Qed.
+
+Global Instance Linf_metric_space_class : ExtMetricSpaceClass T.
+Proof.
+match goal with | H : NonEmpty X |- _ => destruct H as [x0] end.
+constructor.
++ apply FuncBallProper.
++ intros f g x; apply mspc_inf.
++ intros e e_neg f g A. specialize (A x0). eapply mspc_negative; eauto.
++ intros e e_nonneg f x; now apply mspc_refl.
++ intros e f g A x; now apply mspc_symm.
++ intros e1 e2 f g h A1 A2 x. now apply mspc_triangle with (b := map g x).
++ intros e f g A x. apply mspc_closed; intros d A1. now apply A.
+Qed.
+
+End FunctionMetricSpace.
+
Section UniformContinuity.
Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
@@ -268,59 +305,15 @@ Proof.
intros x1 x2 A. apply -> mspc_eq. intros e e_pos. apply (uc_prf f mu); trivial.
pose proof (uc_pos f mu e e_pos) as ?.
destruct (mu e); [apply mspc_eq; trivial | apply mspc_inf].
-admit.
Qed.
End UniformContinuity.
Global Arguments UniformlyContinuous X {_} Y {_}.
-Class Map (A X Y : Type) := map : A -> X -> Y.
-
Instance uniformly_continuous_map `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y} :
Map (UniformlyContinuous X Y) X Y := λ f, f.
-Section FunctionMetricSpace.
-
-Context `{NonEmpty X, ExtMetricSpaceClass Y, Map T X Y}.
-
-Global Instance func_space_ball : MetricSpaceBall T :=
- λ e f g, forall x, ball e (map f x) (map g x).
-
-Lemma FuncBallProper : Proper ((=) ==> (≡) ==> (≡) ==> iff) ball.
-Proof.
-intros q1 q2 A1 f1 f2 A2 g1 g2 A3; rewrite A2, A3.
-split; intros A4 x; [rewrite <- A1 | rewrite A1]; apply A4.
-Qed.
-
-Global Instance : ExtMetricSpaceClass T.
-Proof.
-match goal with | H : NonEmpty X |- _ => destruct H as [x0] end.
-constructor.
-+ apply FuncBallProper.
-+ intros f g x; apply mspc_inf.
-+ intros e e_neg f g A. specialize (A x0). eapply mspc_negative; eauto.
-+ intros e e_nonneg f x; now apply mspc_refl.
-+ intros e f g A x; now apply mspc_symm.
-+ intros e1 e2 f g h A1 A2 x. now apply mspc_triangle with (b := map g x).
-+ intros e f g A x. apply mspc_closed; intros d A1. now apply A.
-Qed.
-
-End FunctionMetricSpace.
-
-(*Section Test.
-
-Context `{ExtMetricSpaceClass X} `{ExtMetricSpaceClass Y}.
-Context `{NonEmpty X}.
-
-Check _ : MetricSpaceBall (UniformlyContinuous X Y).
-Require Import CRtrans.
-SearchAbout CR "min".
-Check _ : MetricSpaceBall (X -> Y).
-
-Goal forall `{ExtMetricSpaceClass X} `{ExtMetricSpaceClass Y},
- ExtMetricSpaceClass (UniformlyContinuous X Y).*)
-
Section LocalUniformContinuity.
Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
@@ -421,8 +414,21 @@ intros x r. constructor; [now apply (lip_nonneg f) |].
intros [x1 x1b] [x2 x2b] e A. change (ball (L * e) (f x1) (f x2)). now apply lip_prf.
Qed.
+Record LocallyLipschitz := {
+ llip_func :> X -> Y;
+ llip_const : X -> Q -> Q;
+ llip_proof : IsLocallyLipschitz llip_func llip_const
+}.
+
End LocallyLipschitz.
+Global Arguments LocallyLipschitz X {_} Y {_}.
+
+Instance locally_lipschitz_map `{MetricSpaceClass X, ExtMetricSpaceClass Y} :
+ Map (LocallyLipschitz X Y) X Y := λ f, f.
+
+Notation "X LL-> Y" := (LocallyLipschitz X Y) (at level 55, right associativity).
+
Section Contractions.
Context `{MetricSpaceClass X, ExtMetricSpaceClass Y}.
@@ -451,43 +457,6 @@ End Contractions.
Global Arguments Contraction X {_} Y {_}.
-Section UCFMetricSpace.
-
-Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
-
-Instance UCFEquiv : Equiv (UniformlyContinuous X Y) := @equiv (X -> Y) _.
-
-Lemma UCFSetoid : Setoid (UniformlyContinuous X Y).
-Proof.
-constructor.
-intros f x y A. now rewrite A.
-intros f g A1 x y A2; rewrite A2; symmetry; now apply A1.
-intros f g h A1 A2 x y A3; rewrite A3; now transitivity (g y); [apply A1 | apply A2].
-Qed.
-
-Global Instance UCFSpaceBall : MetricSpaceBall (UniformlyContinuous X Y) :=
- λ e f g, forall x, ball e (f x) (g x).
-
-Lemma UCFBallProper : Proper ((=) ==> (≡) ==> (≡) ==> iff) ball.
-Proof.
-intros q1 q2 A1 f1 f2 A2 g1 g2 A3; rewrite A2, A3.
-split; intros A4 x; [rewrite <- A1 | rewrite A1]; apply A4.
-Qed.
-
-Global Instance : `{NonEmpty X} -> ExtMetricSpaceClass (UniformlyContinuous X Y).
-Proof.
-intros [x0]; constructor.
-+ apply UCFBallProper.
-+ intros f g x; apply mspc_inf.
-+ intros e e_neg f g A. specialize (A x0). eapply mspc_negative; eauto.
-+ intros e e_nonneg f x; now apply mspc_refl.
-+ intros e f g A x; now apply mspc_symm.
-+ intros e1 e2 f g h A1 A2 x; now apply mspc_triangle with (b := g x).
-+ intros e f g A x. apply mspc_closed; intros d A1. now apply A.
-Qed.
-
-End UCFMetricSpace.
-
Section CompleteMetricSpace.
Context `{ExtMetricSpaceClass X}.
From c6b057e6348347457ad05903213efa7feae6326c Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Mon, 24 Dec 2012 21:30:36 +0100
Subject: [PATCH 049/110] Defined product metric space with supremum norm
---
broken/metric.v | 51 +++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 47 insertions(+), 4 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index 37c19d40..63288cb6 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -238,6 +238,34 @@ Qed.
End SubMetricSpace.
+Section ProductMetricSpace.
+
+Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
+
+Global Instance Linf_product_metric_space_ball : MetricSpaceBall (X * Y) :=
+ λ e a b, ball e (fst a) (fst b) /\ ball e (snd a) (snd b).
+
+Lemma product_ball_proper : Proper ((=) ==> (≡) ==> (≡) ==> iff) ball.
+Proof.
+intros e1 e2 A1 a1 a2 A2 b1 b2 A3.
+unfold mspc_ball, Linf_product_metric_space_ball.
+rewrite A1, A2, A3; reflexivity.
+Qed.
+
+Global Instance Linf_product_metric_space_class : ExtMetricSpaceClass (X * Y).
+Proof.
+constructor.
++ apply product_ball_proper.
++ intros x y; split; apply mspc_inf.
++ intros e e_neg x y [A _]. eapply (@mspc_negative X); eauto.
++ intros e e_nonneg x; split; apply mspc_refl; trivial.
++ intros e a b [A1 A2]; split; apply mspc_symm; trivial.
++ intros e1 e2 a b c [A1 A2] [B1 B2]; split; eapply mspc_triangle; eauto.
++ intros e a b A; split; apply mspc_closed; firstorder.
+Qed.
+
+End ProductMetricSpace.
+
(** We define [Map T X Y] if there is a coercion map from T to (X -> Y),
i.e., T is a type of functions. It can be instatiated with (locally)
uniformly continuous function, (locally) Lipschitz functions, contractions
@@ -252,20 +280,20 @@ Section FunctionMetricSpace.
Context `{NonEmpty X, ExtMetricSpaceClass Y, Map T X Y}.
-Global Instance Linf_metric_space_ball : MetricSpaceBall T :=
+Global Instance Linf_func_metric_space_ball : MetricSpaceBall T :=
λ e f g, forall x, ball e (map f x) (map g x).
-Lemma FuncBallProper : Proper ((=) ==> (≡) ==> (≡) ==> iff) ball.
+Lemma func_ball_proper : Proper ((=) ==> (≡) ==> (≡) ==> iff) ball.
Proof.
intros q1 q2 A1 f1 f2 A2 g1 g2 A3; rewrite A2, A3.
split; intros A4 x; [rewrite <- A1 | rewrite A1]; apply A4.
Qed.
-Global Instance Linf_metric_space_class : ExtMetricSpaceClass T.
+Global Instance Linf_func_metric_space_class : ExtMetricSpaceClass T.
Proof.
match goal with | H : NonEmpty X |- _ => destruct H as [x0] end.
constructor.
-+ apply FuncBallProper.
++ apply func_ball_proper.
+ intros f g x; apply mspc_inf.
+ intros e e_neg f g A. specialize (A x0). eapply mspc_negative; eauto.
+ intros e e_nonneg f x; now apply mspc_refl.
@@ -457,6 +485,21 @@ End Contractions.
Global Arguments Contraction X {_} Y {_}.
+Section ProductSpaces.
+
+Context `{ExtMetricSpaceClass X}.
+
+Definition diag (x : X) : X * X := (x, x).
+
+Global Instance diag_lipschitz : IsUniformlyContinuous diag (λ e, e).
+Proof.
+constructor.
++ auto.
++ intros e x1 x2 e_pos A; now split.
+Qed.
+
+End ProductSpaces.
+
Section CompleteMetricSpace.
Context `{ExtMetricSpaceClass X}.
From ed663bbac9b1209dcd46a40308d8c8d4014adb3a Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 27 Dec 2012 21:10:23 +0100
Subject: [PATCH 050/110] Proved that the composition if uniformly continuous
functions is uniformly continuous
---
broken/metric.v | 112 +++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 107 insertions(+), 5 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index 63288cb6..5870c4d5 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -82,6 +82,7 @@ Instance Qpos_inv : DecRecip Qpos := Qpossec.Qpos_inv.
Instance Qinf_one : One Qinf := 1%Q.
*)
+Instance Qinf_le : Le Qinf := Qinf.le.
Instance Qinf_lt : Lt Qinf := Qinf.lt.
(*
@@ -195,6 +196,14 @@ apply (mspc_triangle' q1 (q2 - q1) y); [ring | trivial |]. apply mspc_refl.
apply (order_preserving (+ (-q1))) in A1. now rewrite plus_negate_r in A1.
Qed.
+Lemma mspc_monotone' :
+ ∀ q1 q2 : Qinf, q1 ≤ q2 -> ∀ x y : X, ball q1 x y → ball q2 x y.
+Proof.
+intros [q1 |] [q2 |] A1 x y A2; try apply mspc_inf.
++ apply (mspc_monotone q1); trivial.
++ elim A1.
+Qed.
+
Lemma mspc_eq : ∀ x y : X, (∀ e : Q, 0 < e -> ball e x y) ↔ x = y.
Proof.
intros x y; split; intro A.
@@ -339,7 +348,25 @@ End UniformContinuity.
Global Arguments UniformlyContinuous X {_} Y {_}.
-Instance uniformly_continuous_map `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y} :
+Global Instance compose_uc {X Y Z : Type}
+ `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y, ExtMetricSpaceClass Z}
+ (f : X -> Y) (g : Y -> Z) (f_mu g_mu : Q -> Qinf)
+ `{!IsUniformlyContinuous f f_mu, !IsUniformlyContinuous g g_mu} :
+ IsUniformlyContinuous (g ∘ f) (comp_inf f_mu g_mu Qinf.infinite).
+Proof.
+constructor.
++ intros e e_pos. assert (0 < g_mu e) by (apply (uc_pos g); trivial).
+ unfold comp_inf. destruct (g_mu e); [apply (uc_pos f) |]; trivial.
++ intros e x1 x2 e_pos A. unfold compose. apply (uc_prf g g_mu); trivial.
+ assert (0 < g_mu e) by (apply (uc_pos g); trivial).
+ unfold comp_inf in A. destruct (g_mu e) as [e' |]; [| apply mspc_inf].
+ apply (uc_prf f f_mu); trivial.
+Qed.
+
+Global Instance id_uc `{ExtMetricSpaceClass X} : IsUniformlyContinuous id id.
+Proof. constructor; trivial. Qed.
+
+Global Instance uniformly_continuous_map `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y} :
Map (UniformlyContinuous X Y) X Y := λ f, f.
Section LocalUniformContinuity.
@@ -485,21 +512,96 @@ End Contractions.
Global Arguments Contraction X {_} Y {_}.
-Section ProductSpaces.
+Global Instance : PreOrder Qinf.le.
+Proof.
+constructor.
++ intros [x |]; [apply Qle_refl | easy].
++ intros [x |] [y |] [z |]; solve [intros [] | intros _ [] | easy | apply Qle_trans].
+Qed.
-Context `{ExtMetricSpaceClass X}.
+Global Instance : AntiSymmetric Qinf.le.
+Proof.
+intros [x |] [y |] A B; [apply Qle_antisym | elim B | elim A |]; easy.
+Qed.
-Definition diag (x : X) : X * X := (x, x).
+Global Instance : PartialOrder Qinf.le.
+Proof. constructor; apply _. Qed.
-Global Instance diag_lipschitz : IsUniformlyContinuous diag (λ e, e).
+Global Instance : TotalRelation Qinf.le.
+Proof.
+intros [x |] [y |]; [change (x ≤ y \/ y ≤ x); apply total, _ | left | right | left]; easy.
+Qed.
+
+Global Instance : TotalOrder Qinf.le.
+Proof. constructor; apply _. Qed.
+
+Global Instance : ∀ x y : Qinf, Decision (x ≤ y).
+intros [x |] [y |]; [change (Decision (x ≤ y)); apply _ | left | right | left]; easy.
+Defined.
+
+Import minmax.
+
+(* Instances above allow using min and max for Qinf *)
+
+Section TotalOrderLattice.
+
+Context `{TotalOrder A} `{Lt A} `{∀ x y: A, Decision (x ≤ y)}.
+
+Lemma min_ind (R : relation A) (x y z : A) : R z x → R z y → R z (min x y).
+Proof. unfold min, sort. destruct (decide_rel le x y); auto. Qed.
+
+End TotalOrderLattice.
+
+Section ProductSpaces.
+
+Definition diag `{ExtMetricSpaceClass X} (x : X) : X * X := (x, x).
+
+Global Instance diag_uc `{ExtMetricSpaceClass X} : IsUniformlyContinuous diag (λ e, e).
Proof.
constructor.
+ auto.
+ intros e x1 x2 e_pos A; now split.
Qed.
+Lemma t : forall x y : Q, meet x x = x.
+intros x y.
+apply idempotency. apply binary_idempotent.
+Qed.
+
+Definition together {X1 Y1 X2 Y2 : Type} (f1 : X1 -> Y1) (f2 : X2 -> Y2) : X1 * X2 -> Y1 * Y2 :=
+ λ p, (f1 (fst p), f2 (snd p)).
+
+Global Instance together_uc
+ `{ExtMetricSpaceClass X1, ExtMetricSpaceClass Y1, ExtMetricSpaceClass X2, ExtMetricSpaceClass Y2}
+ (f1 : X1 -> Y1) (f2 : X2 -> Y2)
+ `{!IsUniformlyContinuous f1 mu1, !IsUniformlyContinuous f2 mu2} :
+ IsUniformlyContinuous (together f1 f2) (λ e, min (mu1 e) (mu2 e)).
+Proof.
+constructor.
++ intros e e_pos. apply min_ind; [apply (uc_pos f1) | apply (uc_pos f2)]; trivial.
+ (* [trivial] solves, in particular, [IsUniformlyContinuous f1 mu1], which should
+ have been solved automatically *)
++ intros e z z' e_pos [A1 A2]. split; simpl.
+ - apply (uc_prf f1 mu1); trivial.
+ apply (mspc_monotone' (min (mu1 e) (mu2 e))); [apply: meet_lb_l | trivial].
+ - apply (uc_prf f2 mu2); trivial.
+ apply (mspc_monotone' (min (mu1 e) (mu2 e))); [apply: meet_lb_r | trivial].
+Qed.
+
End ProductSpaces.
+(*
+Section Test.
+
+Context `{ExtMetricSpaceClass A, ExtMetricSpaceClass B, ExtMetricSpaceClass C}
+ (f : A -> B) `{!IsUniformlyContinuous f f_mu}
+ (v : A * B -> C) `{!IsUniformlyContinuous v v_mu}.
+
+Check _ : IsUniformlyContinuous (v ∘ (together id f) ∘ diag) _.
+
+End Test.
+*)
+
Section CompleteMetricSpace.
Context `{ExtMetricSpaceClass X}.
From 1097472a6f903d107dc479340c9a8c42f7e1c813 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Sat, 29 Dec 2012 21:20:03 +0100
Subject: [PATCH 051/110] Ran 'git add math-classes'
---
math-classes | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/math-classes b/math-classes
index bc501547..eb03507e 160000
--- a/math-classes
+++ b/math-classes
@@ -1 +1 @@
-Subproject commit bc5015474dba2a2e6a571a1d84a472ed8d56221b
+Subproject commit eb03507e225d0e4381bf670b6ceecdbf71da3981
From d8103a5a9eb6aa75216d7d57b4f1adeaf3349a92 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 1 Jan 2013 23:53:44 +0100
Subject: [PATCH 052/110] Changed Map to Func
---
broken/metric.v | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index 5870c4d5..569f7b77 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -275,22 +275,22 @@ Qed.
End ProductMetricSpace.
-(** We define [Map T X Y] if there is a coercion map from T to (X -> Y),
+(** We define [Func T X Y] if there is a coercion func from T to (X -> Y),
i.e., T is a type of functions. It can be instatiated with (locally)
uniformly continuous function, (locally) Lipschitz functions, contractions
-and so on. For instances T of [Map] we can define supremum metric ball
-(i.e., L∞ metric) and prove that T is a metric space. [Map T X Y] is
+and so on. For instances T of [Func] we can define supremum metric ball
+(i.e., L∞ metric) and prove that T is a metric space. [Func T X Y] is
similar to [Cast T (X -> Y)], but [cast] has types as explicit arguments,
-so for [f : T] one would have to write [cast _ _ f x] instead of [map f x]. *)
+so for [f : T] one would have to write [cast _ _ f x] instead of [func f x]. *)
-Class Map (T X Y : Type) := map : T -> X -> Y.
+Class Func (T X Y : Type) := func : T -> X -> Y.
Section FunctionMetricSpace.
-Context `{NonEmpty X, ExtMetricSpaceClass Y, Map T X Y}.
+Context `{NonEmpty X, ExtMetricSpaceClass Y, Func T X Y}.
Global Instance Linf_func_metric_space_ball : MetricSpaceBall T :=
- λ e f g, forall x, ball e (map f x) (map g x).
+ λ e f g, forall x, ball e (func f x) (func g x).
Lemma func_ball_proper : Proper ((=) ==> (≡) ==> (≡) ==> iff) ball.
Proof.
@@ -307,7 +307,7 @@ constructor.
+ intros e e_neg f g A. specialize (A x0). eapply mspc_negative; eauto.
+ intros e e_nonneg f x; now apply mspc_refl.
+ intros e f g A x; now apply mspc_symm.
-+ intros e1 e2 f g h A1 A2 x. now apply mspc_triangle with (b := map g x).
++ intros e1 e2 f g h A1 A2 x. now apply mspc_triangle with (b := func g x).
+ intros e f g A x. apply mspc_closed; intros d A1. now apply A.
Qed.
@@ -366,8 +366,8 @@ Qed.
Global Instance id_uc `{ExtMetricSpaceClass X} : IsUniformlyContinuous id id.
Proof. constructor; trivial. Qed.
-Global Instance uniformly_continuous_map `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y} :
- Map (UniformlyContinuous X Y) X Y := λ f, f.
+Global Instance uniformly_continuous_func `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y} :
+ Func (UniformlyContinuous X Y) X Y := λ f, f.
Section LocalUniformContinuity.
@@ -479,8 +479,8 @@ End LocallyLipschitz.
Global Arguments LocallyLipschitz X {_} Y {_}.
-Instance locally_lipschitz_map `{MetricSpaceClass X, ExtMetricSpaceClass Y} :
- Map (LocallyLipschitz X Y) X Y := λ f, f.
+Instance locally_lipschitz_func `{MetricSpaceClass X, ExtMetricSpaceClass Y} :
+ Func (LocallyLipschitz X Y) X Y := λ f, f.
Notation "X LL-> Y" := (LocallyLipschitz X Y) (at level 55, right associativity).
@@ -692,9 +692,7 @@ Context `{NonEmpty X, ExtMetricSpaceClass X, CompleteMetricSpaceClass Y}.
Program Definition pointwise_regular
(F : RegularFunction (UniformlyContinuous X Y)) (x : X) : RegularFunction Y :=
Build_RegularFunction (λ e, F e x) _.
-Next Obligation.
-intros e1 e2 e1_pos e2_pos; now apply F.
-Qed.
+Next Obligation. intros e1 e2 e1_pos e2_pos; now apply F. Qed.
Global Program Instance ucf_limit : Limit (UniformlyContinuous X Y) :=
λ F, Build_UniformlyContinuous
@@ -721,8 +719,8 @@ Qed.
Global Instance : CompleteMetricSpaceClass (UniformlyContinuous X Y).
Proof.
apply completeness_criterion. intros F e e_pos x.
-change (lim F x) with (lim (pointwise_regular F x)).
-change (F e x) with (pointwise_regular F x e).
+change (func (lim F) x) with (lim (pointwise_regular F x)).
+change (func (F e) x) with (pointwise_regular F x e).
now apply completeness_criterion.
Qed.
@@ -810,7 +808,7 @@ Lemma iter_fixpoint
(forall n : nat, x (S n) = f (x n)) -> seq_lim x a N -> f a = a.
Proof.
intros A1 A2; generalize A2; intro A3. apply seq_lim_S in A2. apply (seq_lim_cont f) in A3.
-mc_setoid_replace (x ∘ S) with (f ∘ x) in A2 by (intros ? ? eqmn; rewrite eqmn; apply A1).
+setoid_replace (@compose nat nat X x S) with (@compose nat X X f x) in A2. by (intros ? ? eqmn; rewrite eqmn; apply A1).
eapply seq_lim_unique; eauto.
Qed.
From a7b2298843b9e82d83d03a9e4b7bb60461139248 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Wed, 16 Jan 2013 22:27:37 +0100
Subject: [PATCH 053/110] Started defining Picard operator
---
broken/AbstractIntegration.v | 121 +++++++++++++++++++++++++++++++++--
broken/metric.v | 25 ++++++--
2 files changed, 133 insertions(+), 13 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 8b19a95d..208aa960 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -655,7 +655,7 @@ Lemma riemann_sum_bounds (a w : Q) (m : CR) (e : Q) (n : positive) :
Proof.
intros w_nn A. rewrite <- (riemann_sum_const a w m n). unfold riemann_sum.
rewrite <- (step_mult w n), <- (Qmult_assoc n _ e), <- (positive_nat_Z n).
-apply CRΣ_gball. intros k A1. apply gball_CRmult_Q_nonneg; [now apply step_nonneg |].
+apply CRΣ_gball. intros k A1. apply CRball.gball_CRmult_Q_nonneg; [now apply step_nonneg |].
apply A. split; [apply index_inside_l | apply index_inside_r]; trivial.
Qed.
@@ -753,6 +753,28 @@ End IntegralOfSum.
Add Field Q : (dec_fields.stdlib_field_theory Q).
+(* In theory.rings, we have
+
+[rings.plus_assoc : ... Associative plus]
+
+and
+
+[rings.plus_comm : ... Commutative plus].
+
+One difference is that [Commutative] is defined directly while
+[Associative] is defined through [HeteroAssociative]. For this or some
+other reason, rewriting [rings.plus_comm] works while rewriting
+[rings.plus_assoc] does not. Interestingly, all arguments before x y z in
+[rings.plus_assoc] are implicit, and when we make [R] explicit, rewriting
+works. However, in this case [rewrite] leaves a goal [SemiRing R], which is
+not solved by [trivial], [auto] or [easy], but only by [apply _]. If
+[rings.plus_assoc] is formulated as [x + (y + z) = (x + y) + z] instead of
+[Associative plus], then rewriting works; however, then it cannot be an
+instance (of [Associative]). Make this change in theory.rings? *)
+
+Lemma plus_assoc `{SemiRing R} : forall (x y z : R), x + (y + z) = (x + y) + z.
+Proof. exact simple_associativity. Qed.
+
Section RingFacts.
Context `{Ring R}.
@@ -767,7 +789,7 @@ which is solved by [apply _]. Why is it left? *)
Qed.
Lemma plus_right_cancel (z x y : R) : x + z = y + z <-> x = y.
-Proof. rewrite (plus_comm x z), (plus_comm y z); apply plus_left_cancel. Qed.
+Proof. rewrite (rings.plus_comm x z), (rings.plus_comm y z); apply plus_left_cancel. Qed.
Lemma plus_eq_minus (x y z : R) : x + y = z <-> x = z - y.
Proof.
@@ -840,15 +862,15 @@ destruct (decide (a ≤ c)) as [AC | AC].
+ idtac...
+ assert (A : a ≤ c) by (now transitivity b); elim (AC A).
+ apply minus_eq_plus; symmetry...
-+ rewrite minus_eq_plus, (plus_comm (-integrate _ _ _)), <- plus_eq_minus, (plus_comm (integrate _ _ _))...
-+ rewrite (plus_comm (-integrate _ _ _)), minus_eq_plus, (plus_comm (integrate _ _ _)); symmetry...
-+ rewrite (plus_comm (-integrate _ _ _)), minus_eq_plus, (plus_comm (-integrate _ _ _)), <- plus_eq_minus...
++ rewrite minus_eq_plus, (rings.plus_comm (-integrate _ _ _)), <- plus_eq_minus, (rings.plus_comm (integrate _ _ _))...
++ rewrite (rings.plus_comm (-integrate _ _ _)), minus_eq_plus, (rings.plus_comm (integrate _ _ _)); symmetry...
++ rewrite (rings.plus_comm (-integrate _ _ _)), minus_eq_plus, (rings.plus_comm (-integrate _ _ _)), <- plus_eq_minus...
+ assert (b ≤ a) by (now apply orders.le_flip); assert (B : b ≤ c) by (now transitivity a); elim (BC B).
-+ rewrite <- rings.negate_plus_distr, negate_inj, (plus_comm (integrate _ _ _))...
++ rewrite <- rings.negate_plus_distr, negate_inj, (rings.plus_comm (integrate _ _ _))...
Qed.
Lemma int_diff (a b c : Q) : int a b - int a c = int c b.
-Proof. apply minus_eq_plus. rewrite plus_comm. symmetry; apply int_add. Qed.
+Proof. apply minus_eq_plus. rewrite rings.plus_comm. symmetry; apply int_add. Qed.
Lemma int_zero_width (a : Q) : int a a = 0.
Proof. apply (plus_right_cancel (int a a)); rewrite rings.plus_0_l; apply int_add. Qed.
@@ -955,6 +977,91 @@ Qed.
End IntegralLipschitz.
+Import minmax.
+
+(*Global Instance Qball_decidable (r : Qinf) (a x : Q) : Decision (mspc_ball r a x).
+destruct r as [r |]; [| now left].
+apply (decision_proper (Qabs (a - x) <= r)%Q); [symmetry; apply gball_Qabs | apply _].
+Defined.*)
+
+Section AbsFacts.
+
+Context `{Ring R} `{!FullPseudoSemiRingOrder Rle Rlt} `{!Abs R}.
+
+(* Should this be made a Class? It seems particular and complicated *)
+Definition abs_cases_statement (P : R -> Prop) :=
+ Proper (equiv ==> iff) P -> (forall x, Stable (P x)) ->
+ forall x : R, (0 ≤ x -> P x) /\ (x ≤ 0 -> P (- x)) -> P (abs x).
+
+Context `(abs_cases : forall P : R -> Prop, abs_cases_statement P)
+ `{le_stable : forall x y : R, Stable (x ≤ y)}.
+
+Lemma abs_nonneg' (x : R) : 0 ≤ abs x.
+Proof.
+apply abs_cases.
++ intros y1 y2 E; now rewrite E.
++ apply _.
++ split; [trivial |]. intros ?; now apply rings.flip_nonpos_negate.
+Qed.
+
+End AbsFacts.
+
+Lemma Qabs_cases : forall P : Q -> Prop, abs_cases_statement P.
+Proof.
+intros P Pp Ps x [? ?].
+destruct (decide (0 ≤ x)) as [A | A];
+ [rewrite abs.abs_nonneg | apply le_flip in A; rewrite abs.abs_nonpos]; auto.
+(* [easy] instead of [auto] does not work *)
+Qed.
+
+Lemma Qabs_nonneg (x : Q) : 0 ≤ abs x.
+Proof. apply abs_nonneg'; [apply Qabs_cases | apply _]. Qed.
+
+Section Extend.
+
+Context `{ExtMetricSpaceClass Y} (a : Q) (r : QnonNeg) (f : sig (mspc_ball r a) -> Y).
+
+Program Definition extend : Q -> Y :=
+ λ x, if (decide (x ≤ a - r))
+ then f (a - r)
+ else if (decide (a + r ≤ x))
+ then f (a + r)
+ else f x.
+Next Obligation.
+destruct r as [e ?]; simpl.
+apply gball_Qabs. mc_setoid_replace (a - (a - e)) with e by ring.
+change (abs e ≤ e). rewrite abs.abs_nonneg; [reflexivity | trivial].
+Qed.
+
+Next Obligation.
+destruct r as [e ?]; simpl.
+apply gball_Qabs. mc_setoid_replace (a - (a + e)) with (-e) by ring.
+change (abs (-e) ≤ e). rewrite abs.abs_negate, abs.abs_nonneg; [reflexivity | trivial].
+Qed.
+
+Next Obligation.
+apply gball_Qabs, Qabs_diff_Qle. apply le_flip in H1; apply le_flip in H2.
+split; trivial.
+Qed.
+
+Global Instance extend_uc `{!IsUniformlyContinuous f f_mu} :
+ IsUniformlyContinuous extend f_mu.
+Admitted.
+
+End Extend.
+
+Section Picard.
+
+Context (x0 y0 : Q) (rx ry : QnonNeg).
+
+Notation sx := (sig (mspc_ball rx x0)).
+Notation sy := (sig (mspc_ball ry y0)).
+
+Context (v : sx * sy -> CR) `{!IsUniformlyContinuous v v_mu}.
+
+Definition picard' (f : sx -> sy) : sx -> CR :=
+ λ x, y0 + int (extend x0 rx (v ∘ (together id f) ∘ diag)) x0 x.
+
(*
Lemma integrate_proper
(f g: Q → CR)
diff --git a/broken/metric.v b/broken/metric.v
index 569f7b77..97ca66ed 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -287,12 +287,18 @@ Class Func (T X Y : Type) := func : T -> X -> Y.
Section FunctionMetricSpace.
-Context `{NonEmpty X, ExtMetricSpaceClass Y, Func T X Y}.
+Context {X Y T : Type} `{Func T X Y, NonEmpty X, ExtMetricSpaceClass Y}.
+
+(* For any type that is convertible to functions we want to define the
+supremum metric. This would give rise to an equality and a setoid
+([mspc_equiv] and [mspc_setoid]).However, a type of functions also gets an
+equality using [ext_equiv]. We want the second method to have a priority
+for some type (X -> Y). Therefore *)
Global Instance Linf_func_metric_space_ball : MetricSpaceBall T :=
λ e f g, forall x, ball e (func f x) (func g x).
-Lemma func_ball_proper : Proper ((=) ==> (≡) ==> (≡) ==> iff) ball.
+Lemma func_ball_proper : Proper ((=) ==> (≡) ==> (≡) ==> iff) (ball (X := T)).
Proof.
intros q1 q2 A1 f1 f2 A2 g1 g2 A3; rewrite A2, A3.
split; intros A4 x; [rewrite <- A1 | rewrite A1]; apply A4.
@@ -728,7 +734,7 @@ End UCFComplete.
Definition seq A := nat -> A.
-(*Hint Unfold seq : typeclass_instances.*)
+Hint Unfold seq : typeclass_instances.
(* This unfolds [seq X] as [nat -> X] and allows ext_equiv to find an
instance of [Equiv (seq X)] *)
@@ -739,7 +745,7 @@ Context `{ExtMetricSpaceClass X}.
Definition seq_lim (x : seq X) (a : X) (N : Q -> nat) :=
forall e : Q, 0 < e -> forall n : nat, N e ≤ n -> ball e (x n) a.
-Global Instance : Proper (((=) ==> (=)) ==> (=) ==> ((=) ==> (=)) ==> iff) seq_lim.
+(*Global Instance : Proper (((=) ==> (=)) ==> (=) ==> ((=) ==> (=)) ==> iff) seq_lim.
Proof.
intros x1 x2 A1 a1 a2 A2 N1 N2 A3; split; intros A e e_pos n A4.
+ mc_setoid_replace (x2 n) with (x1 n) by (symmetry; now apply A1).
@@ -748,7 +754,14 @@ intros x1 x2 A1 a1 a2 A2 N1 N2 A3; split; intros A e e_pos n A4.
+ mc_setoid_replace (x1 n) with (x2 n) by now apply A1.
rewrite A2. mc_setoid_replace (N1 e) with (N2 e) in A4 by now apply A3.
now apply A.
-Qed.
+Qed.*)
+
+(* The following instance uses Leibniz equality for the third argument of
+seq_lim, i.e., the modulus of type [Q -> nat]. This is because extensional
+equality = is not reflexive on functions: [f = f] iff [f] is a morphism.
+And we need reflexivity when we replace the first argument of seq_lim and
+leave the third one unchanged. Do we need the previous instance with
+extensional equality for the third argument? *)
Global Instance : Proper (((=) ==> (=)) ==> (=) ==> (≡) ==> iff) seq_lim.
Proof.
@@ -808,7 +821,7 @@ Lemma iter_fixpoint
(forall n : nat, x (S n) = f (x n)) -> seq_lim x a N -> f a = a.
Proof.
intros A1 A2; generalize A2; intro A3. apply seq_lim_S in A2. apply (seq_lim_cont f) in A3.
-setoid_replace (@compose nat nat X x S) with (@compose nat X X f x) in A2. by (intros ? ? eqmn; rewrite eqmn; apply A1).
+setoid_replace (x ∘ S) with (f ∘ x) in A2 by (intros ? ? eqmn; rewrite eqmn; apply A1).
eapply seq_lim_unique; eauto.
Qed.
From 36c30499046e4c61b0adff629e59a37eee5c5bde Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 17 Jan 2013 22:15:52 +0100
Subject: [PATCH 054/110] Moved the new code about Picard iterations into
Picard.v
---
broken/AbstractIntegration.v | 49 ++-----------------------
broken/Picard.v | 69 +++++++++++++++++++++++++++++++++++-
2 files changed, 70 insertions(+), 48 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 208aa960..71addbd6 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -24,7 +24,7 @@ Ltac done :=
| match goal with H : ~ _ |- _ => solve [case H; trivial] end ].
Open Local Scope Q_scope.
-Open Local Scope uc_scope.
+(*Open Local Scope uc_scope.*)
Open Local Scope CR_scope.
(* [SearchAbout ((Cmap _ _) (Cunit _)).] does not find anything, but it
@@ -977,7 +977,7 @@ Qed.
End IntegralLipschitz.
-Import minmax.
+Import minmax (*Coq.Program.*)Basics.
(*Global Instance Qball_decidable (r : Qinf) (a x : Q) : Decision (mspc_ball r a x).
destruct r as [r |]; [| now left].
@@ -1017,51 +1017,6 @@ Qed.
Lemma Qabs_nonneg (x : Q) : 0 ≤ abs x.
Proof. apply abs_nonneg'; [apply Qabs_cases | apply _]. Qed.
-Section Extend.
-
-Context `{ExtMetricSpaceClass Y} (a : Q) (r : QnonNeg) (f : sig (mspc_ball r a) -> Y).
-
-Program Definition extend : Q -> Y :=
- λ x, if (decide (x ≤ a - r))
- then f (a - r)
- else if (decide (a + r ≤ x))
- then f (a + r)
- else f x.
-Next Obligation.
-destruct r as [e ?]; simpl.
-apply gball_Qabs. mc_setoid_replace (a - (a - e)) with e by ring.
-change (abs e ≤ e). rewrite abs.abs_nonneg; [reflexivity | trivial].
-Qed.
-
-Next Obligation.
-destruct r as [e ?]; simpl.
-apply gball_Qabs. mc_setoid_replace (a - (a + e)) with (-e) by ring.
-change (abs (-e) ≤ e). rewrite abs.abs_negate, abs.abs_nonneg; [reflexivity | trivial].
-Qed.
-
-Next Obligation.
-apply gball_Qabs, Qabs_diff_Qle. apply le_flip in H1; apply le_flip in H2.
-split; trivial.
-Qed.
-
-Global Instance extend_uc `{!IsUniformlyContinuous f f_mu} :
- IsUniformlyContinuous extend f_mu.
-Admitted.
-
-End Extend.
-
-Section Picard.
-
-Context (x0 y0 : Q) (rx ry : QnonNeg).
-
-Notation sx := (sig (mspc_ball rx x0)).
-Notation sy := (sig (mspc_ball ry y0)).
-
-Context (v : sx * sy -> CR) `{!IsUniformlyContinuous v v_mu}.
-
-Definition picard' (f : sx -> sy) : sx -> CR :=
- λ x, y0 + int (extend x0 rx (v ∘ (together id f) ∘ diag)) x0 x.
-
(*
Lemma integrate_proper
(f g: Q → CR)
diff --git a/broken/Picard.v b/broken/Picard.v
index b2f79639..0f943a41 100644
--- a/broken/Picard.v
+++ b/broken/Picard.v
@@ -1,3 +1,69 @@
+Require Import
+ QArith
+ metric FromMetric2 AbstractIntegration SimpleIntegration.
+
+Section Extend.
+
+Context `{ExtMetricSpaceClass Y} (a : Q) (r : QnonNeg) (f : sig (mspc_ball r a) -> Y).
+
+Program Definition extend : Q -> Y :=
+ λ x, if (decide (x ≤ a - r))
+ then f (a - r)
+ else if (decide (a + r ≤ x))
+ then f (a + r)
+ else f x.
+Next Obligation.
+destruct r as [e ?]; simpl.
+apply gball_Qabs. mc_setoid_replace (a - (a - e)) with e by ring.
+change (abs e ≤ e). rewrite abs.abs_nonneg; [reflexivity | trivial].
+Qed.
+
+Next Obligation.
+destruct r as [e ?]; simpl.
+apply gball_Qabs. mc_setoid_replace (a - (a + e)) with (-e) by ring.
+change (abs (-e) ≤ e). rewrite abs.abs_negate, abs.abs_nonneg; [reflexivity | trivial].
+Qed.
+
+Next Obligation.
+apply gball_Qabs, Qabs_diff_Qle. apply le_flip in H1; apply le_flip in H2.
+split; trivial.
+Qed.
+
+Global Instance extend_uc `{!IsUniformlyContinuous f f_mu} :
+ IsUniformlyContinuous extend f_mu.
+Admitted.
+
+End Extend.
+
+Section Picard.
+
+Context (x0 : Q) (y0 : CR) (rx ry : QnonNeg).
+
+Notation sx := (sig (mspc_ball rx x0)).
+Notation sy := (sig (mspc_ball ry y0)).
+
+Context (v : sx * sy -> CR) `{!IsUniformlyContinuous v v_mu}
+(f : sx -> sy) `{!IsUniformlyContinuous f f_mu}.
+
+(*Check _ : MetricSpaceBall
+ (@sig Q
+ (@mspc_ball Q
+ (msp_mspc_ball Q_as_MetricSpace)
+ (Qinf.finite (QnonNeg.to_Q rx)) x0)).
+Check _ : MetricSpaceBall sx.
+
+Check (@diag sx _ _).*)
+
+Variable x : sx.
+
+Check _ : Integral (v ∘ (together Datatypes.id f) ∘ diag) _.
+
+Definition picard' (f : sx -> sy) (*: sx -> CR*) :=
+ λ x, y0 + int (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) x0 (`x).
+
+
+
+(*
Require Import CRArith CRtrans CRconst Qmetric Utf8.
Require Import ProductMetric CompleteProduct (*CPoly_Newton*).
Require Import (*metric2.*)Classified.
@@ -69,4 +135,5 @@ Time Eval vm_compute in (eval 3 (Picard_raw (@const_uc Q_as_MetricSpace (1#1)) 1
Time Eval vm_compute in (eval 3 (picard 1 1)).
Time Eval vm_compute in (eval 2 (picard 2 1)).
-End example.
\ No newline at end of file
+End example.
+*)
\ No newline at end of file
From 485d2953b516b724cbb8c929ad50dc7b8f6a1860 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 18 Jan 2013 19:15:49 +0100
Subject: [PATCH 055/110] Started proving that the function to which Picard
operator is applied is Lipschitz
---
broken/Picard.v | 27 ++++++++++++++++++++-------
broken/metric.v | 23 ++++++++++++++++++++---
model/metric2/Qmetric.v | 4 ++--
3 files changed, 42 insertions(+), 12 deletions(-)
diff --git a/broken/Picard.v b/broken/Picard.v
index 0f943a41..10150bdc 100644
--- a/broken/Picard.v
+++ b/broken/Picard.v
@@ -1,6 +1,19 @@
Require Import
- QArith
- metric FromMetric2 AbstractIntegration SimpleIntegration.
+ Unicode.Utf8 Program
+ CRArith CRabs
+ Qauto Qround Qmetric
+ (*stdlib_omissions.P
+ stdlib_omissions.Z
+ stdlib_omissions.Q
+ stdlib_omissions.N*).
+
+Require Qinf QnonNeg QnnInf CRball.
+Import Qinf.notations QnonNeg.notations QnnInf.notations CRball.notations Qabs.
+
+Require Import metric FromMetric2 AbstractIntegration SimpleIntegration.
+Require Import canonical_names decision setoid_tactics.
+
+Close Scope uc_scope. (* There is a leak in some module *)
Section Extend.
@@ -14,18 +27,18 @@ Program Definition extend : Q -> Y :=
else f x.
Next Obligation.
destruct r as [e ?]; simpl.
-apply gball_Qabs. mc_setoid_replace (a - (a - e)) with e by ring.
+apply Qmetric.gball_Qabs. mc_setoid_replace (a - (a - e)) with e by ring.
change (abs e ≤ e). rewrite abs.abs_nonneg; [reflexivity | trivial].
Qed.
Next Obligation.
destruct r as [e ?]; simpl.
-apply gball_Qabs. mc_setoid_replace (a - (a + e)) with (-e) by ring.
+apply Qmetric.gball_Qabs. mc_setoid_replace (a - (a + e)) with (-e) by ring.
change (abs (-e) ≤ e). rewrite abs.abs_negate, abs.abs_nonneg; [reflexivity | trivial].
Qed.
Next Obligation.
-apply gball_Qabs, Qabs_diff_Qle. apply le_flip in H1; apply le_flip in H2.
+apply Qmetric.gball_Qabs, Q.Qabs_diff_Qle. apply orders.le_flip in H1; apply orders.le_flip in H2.
split; trivial.
Qed.
@@ -56,9 +69,9 @@ Check (@diag sx _ _).*)
Variable x : sx.
-Check _ : Integral (v ∘ (together Datatypes.id f) ∘ diag) _.
+Check _ : Integral (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)).
-Definition picard' (f : sx -> sy) (*: sx -> CR*) :=
+Definition picard' (*f : sx -> sy*) : sx -> CR :=
λ x, y0 + int (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) x0 (`x).
diff --git a/broken/metric.v b/broken/metric.v
index 97ca66ed..f85ec74b 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -369,9 +369,6 @@ constructor.
apply (uc_prf f f_mu); trivial.
Qed.
-Global Instance id_uc `{ExtMetricSpaceClass X} : IsUniformlyContinuous id id.
-Proof. constructor; trivial. Qed.
-
Global Instance uniformly_continuous_func `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y} :
Func (UniformlyContinuous X Y) X Y := λ f, f.
@@ -422,6 +419,7 @@ End LocalUniformContinuity.
Section Lipschitz.
+(* Should the codomain be EXtMetricSpaceClass? *)
Context `{MetricSpaceClass X, MetricSpaceClass Y}.
Class IsLipschitz (f : X -> Y) (L : Q) := {
@@ -460,6 +458,25 @@ Qed.
End Lipschitz.
+Global Instance compose_lip {X Y Z : Type}
+ `{MetricSpaceClass X, MetricSpaceClass Y, MetricSpaceClass Z}
+ (f : X -> Y) (g : Y -> Z) (Lf Lg : Q)
+ `{!IsLipschitz f Lf, !IsLipschitz g Lg} :
+ IsLipschitz (g ∘ f) (Lg * Lf).
+Proof.
+constructor.
++ apply nonneg_mult_compat; [apply (lip_nonneg g), _ | apply (lip_nonneg f), _].
++ intros x1 x2 e A.
+ (* [rewrite <- mult_assoc] does not work *)
+ mc_setoid_replace (Lg * Lf * e) with (Lg * (Lf * e)) by (symmetry; apply simple_associativity).
+ now apply (lip_prf g Lg), (lip_prf f Lf).
+Qed.
+
+Global Instance id_lip `{MetricSpaceClass X} : IsLipschitz id 1.
+Proof.
+constructor; [solve_propholds |]. intros; now rewrite mult_1_l.
+Qed.
+
Section LocallyLipschitz.
Context `{MetricSpaceClass X, ExtMetricSpaceClass Y}.
diff --git a/model/metric2/Qmetric.v b/model/metric2/Qmetric.v
index d9f35a91..747e79bc 100644
--- a/model/metric2/Qmetric.v
+++ b/model/metric2/Qmetric.v
@@ -158,9 +158,9 @@ Qed.
(* end hide *)
Definition Q_as_MetricSpace : MetricSpace :=
@Build_MetricSpace QS _ Qball_wd Q_is_MetricSpace.
-(* begin hide *)
+
Canonical Structure Q_as_MetricSpace.
-(* end hide *)
+
Lemma QPrelengthSpace_help : forall (e d1 d2:Qpos), e < d1+d2 -> forall (a b c:QS), ball e a b -> (c == (a*d2 + b*d1)/(d1+d2)%Qpos) -> ball d1 a c.
Proof with auto with *.
intros e d1 d2 He a b c Hab Hc.
From 49d8c0fbe68703ea2e99558fb67966ae1ca8d1a8 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 22 Jan 2013 18:03:40 +0100
Subject: [PATCH 056/110] .
---
broken/metric.v | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index f85ec74b..2217096d 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -575,30 +575,24 @@ Proof. unfold min, sort. destruct (decide_rel le x y); auto. Qed.
End TotalOrderLattice.
-Section ProductSpaces.
+Section ProductSpaceFunctions.
-Definition diag `{ExtMetricSpaceClass X} (x : X) : X * X := (x, x).
+Definition diag {X : Type} (x : X) : X * X := (x, x).
-Global Instance diag_uc `{ExtMetricSpaceClass X} : IsUniformlyContinuous diag (λ e, e).
+Global Instance diag_lip `{MetricSpaceClass X} : IsLipschitz (@diag X) 1.
Proof.
constructor.
-+ auto.
-+ intros e x1 x2 e_pos A; now split.
-Qed.
-
-Lemma t : forall x y : Q, meet x x = x.
-intros x y.
-apply idempotency. apply binary_idempotent.
++ solve_propholds.
++ intros x1 x2 e A. rewrite mult_1_l. now split.
Qed.
Definition together {X1 Y1 X2 Y2 : Type} (f1 : X1 -> Y1) (f2 : X2 -> Y2) : X1 * X2 -> Y1 * Y2 :=
λ p, (f1 (fst p), f2 (snd p)).
-Global Instance together_uc
- `{ExtMetricSpaceClass X1, ExtMetricSpaceClass Y1, ExtMetricSpaceClass X2, ExtMetricSpaceClass Y2}
+Global Instance together_lip
+ `{MetricSpaceClass X1, MetricSpaceClass Y1, MetricSpaceClass X2, MetricSpaceClass Y2}
(f1 : X1 -> Y1) (f2 : X2 -> Y2)
- `{!IsUniformlyContinuous f1 mu1, !IsUniformlyContinuous f2 mu2} :
- IsUniformlyContinuous (together f1 f2) (λ e, min (mu1 e) (mu2 e)).
+ `{!IsLipschitz f1 L1, !IsLipschitz f2 L2} : IsLipschitz (together f1 f2) (max L1 L2).
Proof.
constructor.
+ intros e e_pos. apply min_ind; [apply (uc_pos f1) | apply (uc_pos f2)]; trivial.
@@ -611,7 +605,7 @@ constructor.
apply (mspc_monotone' (min (mu1 e) (mu2 e))); [apply: meet_lb_r | trivial].
Qed.
-End ProductSpaces.
+End ProductSpaceFunctions.
(*
Section Test.
From 944984d4c407b75d6d9b38f6562f7b3363f493cd Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 24 Jan 2013 22:10:51 +0100
Subject: [PATCH 057/110] Proved some facts about Lipschitz functions
---
broken/metric.v | 40 ++++++++++++++++++++++++++++++++--------
1 file changed, 32 insertions(+), 8 deletions(-)
diff --git a/broken/metric.v b/broken/metric.v
index 2217096d..f8126e71 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -211,19 +211,20 @@ intros x y; split; intro A.
+ intros e e_pos. apply (mspc_monotone 0); trivial; solve_propholds.
Qed.
+Lemma radius_nonneg (x y : X) (e : Q) : ball e x y -> 0 ≤ e.
+Proof.
+intro A. destruct (le_or_lt 0 e) as [A1 | A1]; [trivial |].
+contradict A; now apply mspc_negative.
+Qed.
+
End ExtMetricSpace.
Section MetricSpace.
Context `{MetricSpaceClass X}.
-Lemma msd_nonneg : forall x1 x2 : X, 0 ≤ msd x1 x2.
-Proof.
-intros x1 x2.
-assert (A := mspc_distance x1 x2).
-destruct (le_or_lt 0 (msd x1 x2)) as [A1 | A1]; trivial.
-contradict A; now apply mspc_negative.
-Qed.
+Lemma msd_nonneg (x1 x2 : X) : 0 ≤ msd x1 x2.
+Proof. apply (radius_nonneg x1 x2), mspc_distance. Qed.
End MetricSpace.
@@ -592,9 +593,31 @@ Definition together {X1 Y1 X2 Y2 : Type} (f1 : X1 -> Y1) (f2 : X2 -> Y2) : X1 *
Global Instance together_lip
`{MetricSpaceClass X1, MetricSpaceClass Y1, MetricSpaceClass X2, MetricSpaceClass Y2}
(f1 : X1 -> Y1) (f2 : X2 -> Y2)
- `{!IsLipschitz f1 L1, !IsLipschitz f2 L2} : IsLipschitz (together f1 f2) (max L1 L2).
+ `{!IsLipschitz f1 L1, !IsLipschitz f2 L2} : IsLipschitz (together f1 f2) (join L1 L2).
+(* What if we define the Lipschitz constant for [together f1 f2] to be [max
+L1 L2], where [max] is the name of an instance of [Join A] in
+orders.minmax? In fact, [Check _ : Join Q] returns [max]. I.e., [join x y]
+for [x y : Q] reduces to [max x y]. However, it is difficult to apply
+[lattices.join_le_compat_r] to the goal [0 ≤ max L1 L2]. Simple [apply]
+does not work (probably because the theorem has to be reduced to match the
+goal). As for [apply:] and [rapply], they invoke [refine (@join_le_compat_r
+_ _ ...)]. Some of the _ are implicit arguments and type classes (e.g.,
+[Equiv] [Le]), and they are instantiated with the instances found first,
+which happen to be for [Qinf]. Apparently, unification does not try other
+instances. So, [apply:] with type classes is problematic.
+[apply: (@lattices.join_le_compat_r Q)] gives "Anomaly: Evd.define: cannot define an evar twice" *)
Proof.
constructor.
++ apply lattices.join_le_compat_r, (lip_nonneg f1 L1).
++ intros x1 x2 e [A1 A2].
+ assert (0 ≤ e) by now apply (radius_nonneg (fst x1) (fst x2)).
+ split; simpl.
+ - apply (mspc_monotone (L1 * e)); [apply (order_preserving (.* e)); apply join_ub_l |].
+ (* [apply (order_preserving (.* e)), join_ub_l.] does not work *)
+ apply lip_prf; trivial.
+ - apply (mspc_monotone (L2 * e)); [apply (order_preserving (.* e)); apply join_ub_r |].
+ apply lip_prf; trivial.
+(* Proof of [IsUniformlyContinuous (together f1 f2) _].
+ intros e e_pos. apply min_ind; [apply (uc_pos f1) | apply (uc_pos f2)]; trivial.
(* [trivial] solves, in particular, [IsUniformlyContinuous f1 mu1], which should
have been solved automatically *)
@@ -603,6 +626,7 @@ constructor.
apply (mspc_monotone' (min (mu1 e) (mu2 e))); [apply: meet_lb_l | trivial].
- apply (uc_prf f2 mu2); trivial.
apply (mspc_monotone' (min (mu1 e) (mu2 e))); [apply: meet_lb_r | trivial].
+*)
Qed.
End ProductSpaceFunctions.
From 4dfdc139faea806fa50ab5800308d255add64440 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 25 Jan 2013 19:21:42 +0100
Subject: [PATCH 058/110] Changed type class arguments of some functions and
theorems (e.g., diag_lip and compose_lip) to avoid requiring MetricSpaceClass
when not necessary. Now they require MetricSpaceBall or ExtMetricSpaceClass,
which are superclasses of MetricSpaceClass. This way we don't need proving
that sigma-types and product types are MetricSpaceClass's. Defined the
computational part of Picard operator.
---
broken/Picard.v | 26 +++++++--------------
broken/metric.v | 61 ++++++++++++++++++++++++++++++++++---------------
2 files changed, 50 insertions(+), 37 deletions(-)
diff --git a/broken/Picard.v b/broken/Picard.v
index 10150bdc..4130c1d4 100644
--- a/broken/Picard.v
+++ b/broken/Picard.v
@@ -15,6 +15,11 @@ Require Import canonical_names decision setoid_tactics.
Close Scope uc_scope. (* There is a leak in some module *)
+Global Instance Qmsd : MetricSpaceDistance Q := λ x y, abs (x - y).
+
+Global Instance Qmsc : MetricSpaceClass Q.
+Proof. intros x1 x2; apply gball_Qabs; reflexivity. Qed.
+
Section Extend.
Context `{ExtMetricSpaceClass Y} (a : Q) (r : QnonNeg) (f : sig (mspc_ball r a) -> Y).
@@ -42,8 +47,7 @@ apply Qmetric.gball_Qabs, Q.Qabs_diff_Qle. apply orders.le_flip in H1; apply ord
split; trivial.
Qed.
-Global Instance extend_uc `{!IsUniformlyContinuous f f_mu} :
- IsUniformlyContinuous extend f_mu.
+Global Instance extend_lip `{!IsLipschitz f L} : IsLipschitz extend L.
Admitted.
End Extend.
@@ -55,23 +59,9 @@ Context (x0 : Q) (y0 : CR) (rx ry : QnonNeg).
Notation sx := (sig (mspc_ball rx x0)).
Notation sy := (sig (mspc_ball ry y0)).
-Context (v : sx * sy -> CR) `{!IsUniformlyContinuous v v_mu}
-(f : sx -> sy) `{!IsUniformlyContinuous f f_mu}.
-
-(*Check _ : MetricSpaceBall
- (@sig Q
- (@mspc_ball Q
- (msp_mspc_ball Q_as_MetricSpace)
- (Qinf.finite (QnonNeg.to_Q rx)) x0)).
-Check _ : MetricSpaceBall sx.
-
-Check (@diag sx _ _).*)
-
-Variable x : sx.
-
-Check _ : Integral (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)).
+Context (v : sx * sy -> CR) `{!IsLipschitz v Lv}.
-Definition picard' (*f : sx -> sy*) : sx -> CR :=
+Definition picard' (f : sx -> sy) `{!IsLipschitz f Lf} : sx -> CR :=
λ x, y0 + int (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) x0 (`x).
diff --git a/broken/metric.v b/broken/metric.v
index f8126e71..269add14 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -322,7 +322,7 @@ End FunctionMetricSpace.
Section UniformContinuity.
-Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
+Context `{MetricSpaceBall X, MetricSpaceBall Y}.
Class IsUniformlyContinuous (f : X -> Y) (mu : Q -> Qinf) := {
uc_pos : forall e : Q, 0 < e -> (0 < mu e);
@@ -344,7 +344,8 @@ UniformlyContinuous], in order for uc_func f to be considered a morphism,
we need to declare uc_proof an instance. *)
Global Existing Instance uc_proof.
-Global Instance uc_proper `{IsUniformlyContinuous f mu} : Proper ((=) ==> (=)) f.
+Global Instance uc_proper {_ : ExtMetricSpaceClass X} {_ : ExtMetricSpaceClass Y}
+ `{IsUniformlyContinuous f mu} : Proper ((=) ==> (=)) f.
Proof.
intros x1 x2 A. apply -> mspc_eq. intros e e_pos. apply (uc_prf f mu); trivial.
pose proof (uc_pos f mu e e_pos) as ?.
@@ -355,8 +356,11 @@ End UniformContinuity.
Global Arguments UniformlyContinuous X {_} Y {_}.
+(* In [compose_uc] below, if we don't explicitly specify [Z] as an
+argument, then [`{MetricSpaceBall Z}] does not generalize [Z] but rather
+interprets it as integers. For symmetry we specify [X] and [Y] as well. *)
Global Instance compose_uc {X Y Z : Type}
- `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y, ExtMetricSpaceClass Z}
+ `{MetricSpaceBall X, ExtMetricSpaceClass Y, MetricSpaceBall Z}
(f : X -> Y) (g : Y -> Z) (f_mu g_mu : Q -> Qinf)
`{!IsUniformlyContinuous f f_mu, !IsUniformlyContinuous g g_mu} :
IsUniformlyContinuous (g ∘ f) (comp_inf f_mu g_mu Qinf.infinite).
@@ -370,12 +374,12 @@ constructor.
apply (uc_prf f f_mu); trivial.
Qed.
-Global Instance uniformly_continuous_func `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y} :
+Global Instance uniformly_continuous_func `{MetricSpaceBall X, MetricSpaceBall Y} :
Func (UniformlyContinuous X Y) X Y := λ f, f.
Section LocalUniformContinuity.
-Context `{ExtMetricSpaceClass X, ExtMetricSpaceClass Y}.
+Context `{MetricSpaceBall X, MetricSpaceBall Y}.
Definition restrict (f : X -> Y) (x : X) (r : Q) : sig (ball r x) -> Y :=
f ∘ @proj1_sig _ _.
@@ -392,7 +396,9 @@ intros x r. constructor; [now apply (uc_pos f) |].
intros e [x1 A1] [x2 A2] e_pos A. now apply (uc_prf f mu).
Qed.
-Global Instance luc_proper (f : X -> Y) `{!IsLocallyUniformlyContinuous f lmu} : Proper ((=) ==> (=)) f.
+Global Instance luc_proper
+ {_ : ExtMetricSpaceClass X} {_ : ExtMetricSpaceClass Y}
+ (f : X -> Y) `{!IsLocallyUniformlyContinuous f lmu} : Proper ((=) ==> (=)) f.
Proof.
intros x1 x2 A. apply -> mspc_eq. intros e e_pos.
assert (A1 : ball 1%Q x1 x1) by (apply mspc_refl; Qauto_nonneg).
@@ -420,8 +426,7 @@ End LocalUniformContinuity.
Section Lipschitz.
-(* Should the codomain be EXtMetricSpaceClass? *)
-Context `{MetricSpaceClass X, MetricSpaceClass Y}.
+Context `{MetricSpaceBall X, MetricSpaceBall Y}.
Class IsLipschitz (f : X -> Y) (L : Q) := {
lip_nonneg : 0 ≤ L;
@@ -440,7 +445,16 @@ Record Lipschitz := {
Definition lip_modulus (L e : Q) : Qinf :=
if (decide (L = 0)) then Qinf.infinite else e / L.
-Global Instance lip_uc `(IsLipschitz f L) : IsUniformlyContinuous f (lip_modulus L).
+(* It is nice to declare only [MetricSpaceBall X] above because this is all
+we need to know about X to define [IsLipschitz]. But for the following
+theorem we also need [ExtMetricSpaceClass X], [MetricSpaceDistance X] and
+[MetricSpaceClass X]. How to add these assumptions? Saying [`{MetricSpaceClass X}]
+would add a second copy of [MetricSpaceBall X]. *)
+
+Context {EM : ExtMetricSpaceClass X} {m : MetricSpaceDistance X}.
+
+Global Instance lip_uc {_ : MetricSpaceClass X} {_ : ExtMetricSpaceClass Y} `(IsLipschitz f L) :
+ IsUniformlyContinuous f (lip_modulus L).
Proof.
constructor.
+ intros e A.
@@ -459,8 +473,11 @@ Qed.
End Lipschitz.
+(* We need [ExtMetricSpaceClass Z] because we rewrite the ball radius, so
+[mspc_radius_proper] is required. See comment before [compose_uc] for why
+[{X Y Z : Type}] is necessary. *)
Global Instance compose_lip {X Y Z : Type}
- `{MetricSpaceClass X, MetricSpaceClass Y, MetricSpaceClass Z}
+ `{MetricSpaceBall X, MetricSpaceBall Y, ExtMetricSpaceClass Z}
(f : X -> Y) (g : Y -> Z) (Lf Lg : Q)
`{!IsLipschitz f Lf, !IsLipschitz g Lg} :
IsLipschitz (g ∘ f) (Lg * Lf).
@@ -473,14 +490,15 @@ constructor.
now apply (lip_prf g Lg), (lip_prf f Lf).
Qed.
-Global Instance id_lip `{MetricSpaceClass X} : IsLipschitz id 1.
+(* [ExtMetricSpaceClass X] is needed for rewriting *)
+Global Instance id_lip `{ExtMetricSpaceClass X} : IsLipschitz id 1.
Proof.
constructor; [solve_propholds |]. intros; now rewrite mult_1_l.
Qed.
Section LocallyLipschitz.
-Context `{MetricSpaceClass X, ExtMetricSpaceClass Y}.
+Context `{MetricSpaceBall X, MetricSpaceBall Y}.
Class IsLocallyLipschitz (f : X -> Y) (L : X -> Q -> Q) :=
llip_prf : forall (x : X) (r : Q), 0 ≤ r -> IsLipschitz (restrict f x r) (L x r).
@@ -503,14 +521,14 @@ End LocallyLipschitz.
Global Arguments LocallyLipschitz X {_} Y {_}.
-Instance locally_lipschitz_func `{MetricSpaceClass X, ExtMetricSpaceClass Y} :
+Instance locally_lipschitz_func `{MetricSpaceBall X, MetricSpaceBall Y} :
Func (LocallyLipschitz X Y) X Y := λ f, f.
Notation "X LL-> Y" := (LocallyLipschitz X Y) (at level 55, right associativity).
Section Contractions.
-Context `{MetricSpaceClass X, ExtMetricSpaceClass Y}.
+Context `{MetricSpaceBall X, MetricSpaceBall Y}.
Class IsContraction (f : X -> Y) (q : Q) := {
contr_prf :> IsLipschitz f q;
@@ -580,7 +598,7 @@ Section ProductSpaceFunctions.
Definition diag {X : Type} (x : X) : X * X := (x, x).
-Global Instance diag_lip `{MetricSpaceClass X} : IsLipschitz (@diag X) 1.
+Global Instance diag_lip `{ExtMetricSpaceClass X} : IsLipschitz (@diag X) 1.
Proof.
constructor.
+ solve_propholds.
@@ -591,7 +609,7 @@ Definition together {X1 Y1 X2 Y2 : Type} (f1 : X1 -> Y1) (f2 : X2 -> Y2) : X1 *
λ p, (f1 (fst p), f2 (snd p)).
Global Instance together_lip
- `{MetricSpaceClass X1, MetricSpaceClass Y1, MetricSpaceClass X2, MetricSpaceClass Y2}
+ `{ExtMetricSpaceClass X1, ExtMetricSpaceClass Y1, ExtMetricSpaceClass X2, ExtMetricSpaceClass Y2}
(f1 : X1 -> Y1) (f2 : X2 -> Y2)
`{!IsLipschitz f1 L1, !IsLipschitz f2 L2} : IsLipschitz (together f1 f2) (join L1 L2).
(* What if we define the Lipschitz constant for [together f1 f2] to be [max
@@ -609,8 +627,11 @@ instances. So, [apply:] with type classes is problematic.
Proof.
constructor.
+ apply lattices.join_le_compat_r, (lip_nonneg f1 L1).
-+ intros x1 x2 e [A1 A2].
- assert (0 ≤ e) by now apply (radius_nonneg (fst x1) (fst x2)).
++ intros z1 z2 e [A1 A2].
+ (* Below we prove [0 ≤ e] using [radius_nonneg], which requires
+ [ExtMetricSpaceClass]. Another way is to add the assymption [0 ≤ e] to
+ [lip_prf], sinilar to [uc_prf]. *)
+ assert (0 ≤ e) by now apply (radius_nonneg (fst z1) (fst z2)).
split; simpl.
- apply (mspc_monotone (L1 * e)); [apply (order_preserving (.* e)); apply join_ub_l |].
(* [apply (order_preserving (.* e)), join_ub_l.] does not work *)
@@ -645,7 +666,7 @@ End Test.
Section CompleteMetricSpace.
-Context `{ExtMetricSpaceClass X}.
+Context `{MetricSpaceBall X}.
Class IsRegularFunction (f : Q -> X) : Prop :=
rf_prf : forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> ball (e1 + e2) (f e1) (f e2).
@@ -662,6 +683,8 @@ Global Existing Instance rf_proof.
Global Instance rf_eq : Equiv RegularFunction :=
λ f1 f2, forall e1 e2 : Q, 0 < e1 -> 0 < e2 -> ball (e1 + e2) (f1 e1) (f2 e2).
+Context {EM : ExtMetricSpaceClass X}.
+
Global Instance rf_setoid : Setoid RegularFunction.
Proof.
constructor.
From 4e2972ccd15f8c234267e07b0bddc980f71712b8 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 29 Jan 2013 17:32:04 +0100
Subject: [PATCH 059/110] .
---
broken/AbstractIntegration.v | 2 --
broken/FromMetric2.v | 12 ++++++++++++
broken/metric.v | 4 +++-
3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 71addbd6..c5c1a563 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -583,8 +583,6 @@ Qed.
Add Ring CR_ring : (rings.stdlib_ring_theory CR).
-Notation "f +1 g" := (λ x, f x + g x) (at level 50, left associativity).
-
Lemma cmΣ_empty {M : CMonoid} (f : nat -> M) : cmΣ 0 f = [0].
Proof. reflexivity. Qed.
diff --git a/broken/FromMetric2.v b/broken/FromMetric2.v
index f614c9de..a44cb542 100644
--- a/broken/FromMetric2.v
+++ b/broken/FromMetric2.v
@@ -122,4 +122,16 @@ Qed.
End CompleteSegment.
+(* The following has to be generalized from CR to a metric space where
+[ball r x y] is defined as [abs (x - y) ≤ r], probably a normed vector
+space *)
+Global Instance sum_lip `{MetricSpaceBall X}
+ (f g : X -> CR) `{!IsLipschitz f Lf} `{!IsLipschitz g Lg} :
+ IsLipschitz (f +1 g) (Lf + Lg).
+Proof.
+constructor.
++ pose proof (lip_nonneg f Lf); pose proof (lip_nonneg g Lg); change (0 ≤ Lf + Lg);
+ solve_propholds.
++ intros x1 x2 e A.
+
End QField.
diff --git a/broken/metric.v b/broken/metric.v
index 269add14..8189a840 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -15,6 +15,7 @@ Import Qround Qpower Qinf.notations.
Set Printing Coercions.
+Notation "f +1 g" := (λ x, f x + g x) (at level 50, left associativity).
(*Notation "x ²" := (x * x) (at level 30) : mc_scope.*)
Definition comp_inf {X Z : Type} (g : Q -> Z) (f : X -> Qinf) (inf : Z) (x : X) :=
@@ -453,7 +454,8 @@ would add a second copy of [MetricSpaceBall X]. *)
Context {EM : ExtMetricSpaceClass X} {m : MetricSpaceDistance X}.
-Global Instance lip_uc {_ : MetricSpaceClass X} {_ : ExtMetricSpaceClass Y} `(IsLipschitz f L) :
+Global Instance lip_uc {_ : MetricSpaceClass X} {_ : ExtMetricSpaceClass Y}
+ (f : X -> Y) `{!IsLipschitz f L} :
IsUniformlyContinuous f (lip_modulus L).
Proof.
constructor.
From 52cff51082b12f18af0b38faec4e1a76ff570dcd Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 29 Jan 2013 17:34:49 +0100
Subject: [PATCH 060/110] .
---
broken/BanachFixpoint.v | 2 --
broken/metric.v | 2 +-
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/broken/BanachFixpoint.v b/broken/BanachFixpoint.v
index bb47e5b2..b110674d 100644
--- a/broken/BanachFixpoint.v
+++ b/broken/BanachFixpoint.v
@@ -199,8 +199,6 @@ end.
- intros; apply mspc_symm; now apply A.
Qed.
-SearchAbout (?x = ?y ∨ ?x < ?y).
-
Let a := lim (reg_fun x _ cauchy_x).
Lemma banach_fixpoint : f a = a.
diff --git a/broken/metric.v b/broken/metric.v
index 269add14..0aaffaaa 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -630,7 +630,7 @@ constructor.
+ intros z1 z2 e [A1 A2].
(* Below we prove [0 ≤ e] using [radius_nonneg], which requires
[ExtMetricSpaceClass]. Another way is to add the assymption [0 ≤ e] to
- [lip_prf], sinilar to [uc_prf]. *)
+ [lip_prf], similar to [uc_prf]. *)
assert (0 ≤ e) by now apply (radius_nonneg (fst z1) (fst z2)).
split; simpl.
- apply (mspc_monotone (L1 * e)); [apply (order_preserving (.* e)); apply join_ub_l |].
From aa4e7984629ea3cd28ae53fd538cac680b4d4b2c Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Wed, 30 Jan 2013 00:24:58 +0100
Subject: [PATCH 061/110] Defining Picard operator
---
broken/AbstractIntegration.v | 2 +-
broken/FromMetric2.v | 12 +++++++++++-
broken/Picard.v | 9 +++++++++
broken/metric.v | 10 ++++++++++
4 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index c5c1a563..4d8667ff 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -93,7 +93,7 @@ Proof.
induction n; [reflexivity |].
intros.
rewrite Q.S_Qplus.
- setoid_replace ((n+1) * e)%Q with (e + n * e)%Q by ring.
+ setoid_replace ((n + 1) * e)%Q with (e + n * e)%Q by ring.
unfold cmΣ. simpl @cm_Sum.
apply CRgball_plus; auto.
Qed.
diff --git a/broken/FromMetric2.v b/broken/FromMetric2.v
index a44cb542..b7edacf7 100644
--- a/broken/FromMetric2.v
+++ b/broken/FromMetric2.v
@@ -122,6 +122,13 @@ Qed.
End CompleteSegment.
+Require Import CRArith CRball CRabs.
+
+Add Ring CR : (stdlib_ring_theory CR).
+
+Close Scope CR_scope.
+Unset Printing Coercions.
+
(* The following has to be generalized from CR to a metric space where
[ball r x y] is defined as [abs (x - y) ≤ r], probably a normed vector
space *)
@@ -132,6 +139,9 @@ Proof.
constructor.
+ pose proof (lip_nonneg f Lf); pose proof (lip_nonneg g Lg); change (0 ≤ Lf + Lg);
solve_propholds.
-+ intros x1 x2 e A.
++ intros x1 x2 e A. change (Lf + Lg)%Q with (Lf + Lg). rewrite plus_mult_distr_r.
+ apply CRgball_plus; [now apply: (lip_prf f Lf) | now apply: (lip_prf g Lg)].
+Qed.
End QField.
+
diff --git a/broken/Picard.v b/broken/Picard.v
index 4130c1d4..4562abee 100644
--- a/broken/Picard.v
+++ b/broken/Picard.v
@@ -52,6 +52,9 @@ Admitted.
End Extend.
+(* To be moved to metric.v *)
+Global Arguments Lipschitz X {_} Y {_}.
+
Section Picard.
Context (x0 : Q) (y0 : CR) (rx ry : QnonNeg).
@@ -64,6 +67,12 @@ Context (v : sx * sy -> CR) `{!IsLipschitz v Lv}.
Definition picard' (f : sx -> sy) `{!IsLipschitz f Lf} : sx -> CR :=
λ x, y0 + int (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) x0 (`x).
+(*Set Printing Coercions.
+Variable f : Lipschitz sx sy. Check f : sx -> sy. Check _ : IsLipschitz f _.*)
+
+(*Program Definition picard'' (f : Lipschitz sx sy) : Lipschitz sx CR :=
+ Build_Lipschitz (picard' f) _ _.*)
+
(*
diff --git a/broken/metric.v b/broken/metric.v
index bd1891cc..80af2999 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -546,6 +546,16 @@ Record Contraction := {
contr_proof : IsContraction contr_func contr_const
}.
+Global Instance const_contr `{!ExtMetricSpaceClass Y} (c : Y) : IsContraction (λ x : X, c) 0.
+Proof.
+constructor.
++ constructor.
+ - reflexivity.
+ - intros; apply mspc_refl.
+ rewrite mult_0_l; reflexivity.
++ solve_propholds.
+Qed.
+
(* Do we need the following?
Global Instance contr_to_uc `(IsContraction f q) :
From 2d98acbd5c458b66d4f8019f87139d1e3b1d4be3 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Wed, 30 Jan 2013 23:28:46 +0100
Subject: [PATCH 062/110] Proving that extend is Lipschitz
---
broken/Picard.v | 68 ++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 56 insertions(+), 12 deletions(-)
diff --git a/broken/Picard.v b/broken/Picard.v
index 4562abee..0cc7a8de 100644
--- a/broken/Picard.v
+++ b/broken/Picard.v
@@ -8,12 +8,15 @@ Require Import
stdlib_omissions.N*).
Require Qinf QnonNeg QnnInf CRball.
-Import Qinf.notations QnonNeg.notations QnnInf.notations CRball.notations Qabs.
+Import
+ QnonNeg Qinf.notations QnonNeg.notations QnnInf.notations CRball.notations
+ Qabs propholds.
Require Import metric FromMetric2 AbstractIntegration SimpleIntegration.
Require Import canonical_names decision setoid_tactics.
Close Scope uc_scope. (* There is a leak in some module *)
+Open Scope signature_scope. (* To interpret "==>" *)
Global Instance Qmsd : MetricSpaceDistance Q := λ x y, abs (x - y).
@@ -22,25 +25,57 @@ Proof. intros x1 x2; apply gball_Qabs; reflexivity. Qed.
Section Extend.
-Context `{ExtMetricSpaceClass Y} (a : Q) (r : QnonNeg) (f : sig (mspc_ball r a) -> Y).
+Context `{ExtMetricSpaceClass Y} (a : Q) (r : QnonNeg).
+
+(* Sould [r] be [Q] or [QnonNeg]? If [r : Q], then [extend] below is not
+necessarily continuous. This may be OK because we could add the premise [0
+≤ r] to the lemma that says that [extend] is Lipschitz. However, the
+definition below is not well-typed because if [r < 0], then [ball r a (a -
+r)] is false, so we can't apply [f] to [a - r]. So we assume [r : QnonNeg]. *)
+
+Lemma mspc_ball_edge_l : mspc_ball r a (a - to_Q r).
+Admitted.
+
+Lemma mspc_ball_edge_r : mspc_ball r a (a + to_Q r).
+Admitted.
+
+Notation S := (sig (mspc_ball r a)).
+
+(* We need to know that [f : S -> Y] is a morphism in the sense that [f x]
+depends only on [`x = proj1_sig x] and not on [proj2_sig x]. There are two options.
+
+There are at least two equalities on S: [canonical_names.sig_equiv] and
+[metric.mspc_equiv]. *)
+
+Context (f : S -> Y) (*`{!Proper ((@equiv _ (sig_equiv _)) ==> (=)) f}*).
+
+(* Since the following is a Program Definition, we could write [f (a - r)]
+and prove the obligation [mspc_ball r a (a - r)]. However, this obligation
+would depend on x and [H1 : x ≤ a - r] even though they are not used in the
+proof. So, if [x1 ≤ a - r] and [x2 ≤ a - r], then [extend x1] would reduce
+to [f ((a - r) ↾ extend_obligation_1 x1 H1)] and [extend x2] would reduce
+to [f ((a - r) ↾ extend_obligation_1 x2 H2)]. To apply mspc_refl, we would
+need to prove that these applications of f are equal, i.e., f is a morphism
+that does not depend on the second component of the pair. So instead we
+prove mspc_ball_edge_l and mspc_ball_edge_r, which don't depend on x. *)
Program Definition extend : Q -> Y :=
λ x, if (decide (x ≤ a - r))
- then f (a - r)
+ then f ((a - r) ↾ mspc_ball_edge_l)
else if (decide (a + r ≤ x))
- then f (a + r)
- else f x.
-Next Obligation.
-destruct r as [e ?]; simpl.
+ then f ((a + r) ↾ mspc_ball_edge_r)
+ else f (x ↾ _).
+(*Next Obligation. exact ball_edge_l. Qed.
+(*destruct r as [e ?]; simpl.
apply Qmetric.gball_Qabs. mc_setoid_replace (a - (a - e)) with e by ring.
change (abs e ≤ e). rewrite abs.abs_nonneg; [reflexivity | trivial].
-Qed.
+Qed.*)
-Next Obligation.
-destruct r as [e ?]; simpl.
+Next Obligation. exact ball_edge_r. Qed.
+(*destruct r as [e ?]; simpl.
apply Qmetric.gball_Qabs. mc_setoid_replace (a - (a + e)) with (-e) by ring.
change (abs (-e) ≤ e). rewrite abs.abs_negate, abs.abs_nonneg; [reflexivity | trivial].
-Qed.
+Qed.*)*)
Next Obligation.
apply Qmetric.gball_Qabs, Q.Qabs_diff_Qle. apply orders.le_flip in H1; apply orders.le_flip in H2.
@@ -48,7 +83,16 @@ split; trivial.
Qed.
Global Instance extend_lip `{!IsLipschitz f L} : IsLipschitz extend L.
-Admitted.
+Proof.
+constructor; [apply (lip_nonneg f L) |].
+intros x1 x2 e A; unfold extend.
+assert (0 ≤ e) by now apply (radius_nonneg x1 x2).
+assert (0 ≤ L) by apply (lip_nonneg f L).
+destruct (decide (x1 ≤ a - to_Q r)) as [L1 | L1];
+destruct (decide (x2 ≤ a - to_Q r)) as [L2 | L2].
+* apply mspc_refl; solve_propholds.
+* destruct (decide (a + to_Q r ≤ x2)) as [R2 | R2].
+ + apply (lip_prf f L).
End Extend.
From 17b76c9f07fb9d18eea4400c913566365ceef819 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 31 Jan 2013 23:41:31 +0100
Subject: [PATCH 063/110] Proved that extension of a Lipschitz function is
Lipschitz
---
broken/FromMetric2.v | 24 +++++++++
broken/Picard.v | 123 +++++++++++++++++++++++++++++--------------
broken/metric.v | 14 ++++-
3 files changed, 120 insertions(+), 41 deletions(-)
diff --git a/broken/FromMetric2.v b/broken/FromMetric2.v
index b7edacf7..d9aa54cb 100644
--- a/broken/FromMetric2.v
+++ b/broken/FromMetric2.v
@@ -132,6 +132,29 @@ Unset Printing Coercions.
(* The following has to be generalized from CR to a metric space where
[ball r x y] is defined as [abs (x - y) ≤ r], probably a normed vector
space *)
+
+(*Section LocallyLipschitz'.
+
+Context `{MetricSpaceBall X, MetricSpaceBall Y}.
+
+Class IsLocallyLipschitz' (f : X -> Y) (L : X -> Q -> Q) :=
+ llip_prf' :> forall (x : X) (r : Q), PropHolds (0 ≤ r) -> IsLipschitz (restrict f x r) (L x r).
+
+End LocallyLipschitz'.*)
+
+Global Instance sum_llip `{MetricSpaceBall X}
+ (f g : X -> CR) `{!IsLocallyLipschitz f Lf} `{!IsLocallyLipschitz g Lg} :
+ IsLocallyLipschitz (f +1 g) (λ x r, Lf x r + Lg x r).
+Proof.
+constructor.
++ pose proof (lip_nonneg (restrict f x r) (Lf x r)).
+ pose proof (lip_nonneg (restrict g x r) (Lg x r)). solve_propholds.
++ intros x1 x2 e A. rewrite plus_mult_distr_r.
+ apply CRgball_plus;
+ [now apply: (lip_prf (restrict f x r) _) | now apply: (lip_prf (restrict g x r) _)].
+Qed.
+
+(*
Global Instance sum_lip `{MetricSpaceBall X}
(f g : X -> CR) `{!IsLipschitz f Lf} `{!IsLipschitz g Lg} :
IsLipschitz (f +1 g) (Lf + Lg).
@@ -142,6 +165,7 @@ constructor.
+ intros x1 x2 e A. change (Lf + Lg)%Q with (Lf + Lg). rewrite plus_mult_distr_r.
apply CRgball_plus; [now apply: (lip_prf f Lf) | now apply: (lip_prf g Lg)].
Qed.
+*)
End QField.
diff --git a/broken/Picard.v b/broken/Picard.v
index 0cc7a8de..85e4b51a 100644
--- a/broken/Picard.v
+++ b/broken/Picard.v
@@ -18,11 +18,36 @@ Require Import canonical_names decision setoid_tactics.
Close Scope uc_scope. (* There is a leak in some module *)
Open Scope signature_scope. (* To interpret "==>" *)
+(* The following instances are needed to show that Lipschitz functions are
+uniformly continuous: metric.lip_uc *)
Global Instance Qmsd : MetricSpaceDistance Q := λ x y, abs (x - y).
Global Instance Qmsc : MetricSpaceClass Q.
Proof. intros x1 x2; apply gball_Qabs; reflexivity. Qed.
+(* Should be generalized from Q *)
+Lemma mspc_ball_abs (r x y : Q) : mspc_ball r x y ↔ abs (x - y) ≤ r.
+Proof. apply gball_Qabs. Qed.
+
+Lemma mspc_ball_abs_flip (r x y : Q) : mspc_ball r x y ↔ abs (y - x) ≤ r.
+Proof.
+rewrite <- abs.abs_negate, <- rings.negate_swap_r. apply gball_Qabs.
+Qed.
+
+Lemma nested_balls {x1 x2 y1 y2 e : Q} :
+ mspc_ball e x1 x2 -> x1 ≤ y1 -> y1 ≤ y2 -> y2 ≤ x2 -> mspc_ball e y1 y2.
+Proof.
+intros B A1 A2 A3. apply mspc_ball_abs_flip in B. apply mspc_ball_abs_flip.
+assert (x1 ≤ x2) by (transitivity y1; [| transitivity y2]; trivial).
+rewrite abs.abs_nonneg by now apply rings.flip_nonneg_minus.
+rewrite abs.abs_nonneg in B by now apply rings.flip_nonneg_minus.
+apply rings.flip_le_minus_l. apply rings.flip_le_minus_l in B.
+transitivity x2; [easy |]. transitivity (e + x1); [easy |].
+apply (orders.order_preserving (e +)); easy.
+Qed. (* Too long? *)
+
+SearchAbout abs Q.
+
Section Extend.
Context `{ExtMetricSpaceClass Y} (a : Q) (r : QnonNeg).
@@ -33,21 +58,21 @@ necessarily continuous. This may be OK because we could add the premise [0
definition below is not well-typed because if [r < 0], then [ball r a (a -
r)] is false, so we can't apply [f] to [a - r]. So we assume [r : QnonNeg]. *)
-Lemma mspc_ball_edge_l : mspc_ball r a (a - to_Q r).
-Admitted.
-
-Lemma mspc_ball_edge_r : mspc_ball r a (a + to_Q r).
-Admitted.
-
-Notation S := (sig (mspc_ball r a)).
-
-(* We need to know that [f : S -> Y] is a morphism in the sense that [f x]
-depends only on [`x = proj1_sig x] and not on [proj2_sig x]. There are two options.
+Lemma mspc_ball_edge_l : mspc_ball r a (a - `r).
+Proof.
+destruct r as [e ?]; simpl.
+apply gball_Qabs. mc_setoid_replace (a - (a - e)) with e by ring.
+change (abs e ≤ e). rewrite abs.abs_nonneg; [reflexivity | trivial].
+Qed.
-There are at least two equalities on S: [canonical_names.sig_equiv] and
-[metric.mspc_equiv]. *)
+Lemma mspc_ball_edge_r : mspc_ball r a (a + `r).
+Proof.
+destruct r as [e ?]; simpl.
+apply Qmetric.gball_Qabs. mc_setoid_replace (a - (a + e)) with (-e) by ring.
+change (abs (-e) ≤ e). rewrite abs.abs_negate, abs.abs_nonneg; [reflexivity | trivial].
+Qed.
-Context (f : S -> Y) (*`{!Proper ((@equiv _ (sig_equiv _)) ==> (=)) f}*).
+Context (f : sig (mspc_ball r a) -> Y).
(* Since the following is a Program Definition, we could write [f (a - r)]
and prove the obligation [mspc_ball r a (a - r)]. However, this obligation
@@ -65,39 +90,48 @@ Program Definition extend : Q -> Y :=
else if (decide (a + r ≤ x))
then f ((a + r) ↾ mspc_ball_edge_r)
else f (x ↾ _).
-(*Next Obligation. exact ball_edge_l. Qed.
-(*destruct r as [e ?]; simpl.
-apply Qmetric.gball_Qabs. mc_setoid_replace (a - (a - e)) with e by ring.
-change (abs e ≤ e). rewrite abs.abs_nonneg; [reflexivity | trivial].
-Qed.*)
-
-Next Obligation. exact ball_edge_r. Qed.
-(*destruct r as [e ?]; simpl.
-apply Qmetric.gball_Qabs. mc_setoid_replace (a - (a + e)) with (-e) by ring.
-change (abs (-e) ≤ e). rewrite abs.abs_negate, abs.abs_nonneg; [reflexivity | trivial].
-Qed.*)*)
-
Next Obligation.
-apply Qmetric.gball_Qabs, Q.Qabs_diff_Qle. apply orders.le_flip in H1; apply orders.le_flip in H2.
+apply Qmetric.gball_Qabs, Q.Qabs_diff_Qle.
+apply orders.le_flip in H1; apply orders.le_flip in H2.
split; trivial.
Qed.
Global Instance extend_lip `{!IsLipschitz f L} : IsLipschitz extend L.
-Proof.
+Proof with (assumption || (apply orders.le_flip; assumption) || reflexivity).
constructor; [apply (lip_nonneg f L) |].
-intros x1 x2 e A; unfold extend.
+intros x1 x2 e A.
assert (0 ≤ e) by now apply (radius_nonneg x1 x2).
assert (0 ≤ L) by apply (lip_nonneg f L).
-destruct (decide (x1 ≤ a - to_Q r)) as [L1 | L1];
-destruct (decide (x2 ≤ a - to_Q r)) as [L2 | L2].
+assert (a - to_Q r ≤ a + to_Q r) by
+ (destruct r; simpl; transitivity a;
+ [apply rings.nonneg_minus_compat | apply semirings.plus_le_compat_r]; (easy || reflexivity)).
+unfold extend.
+destruct (decide (x1 ≤ a - to_Q r)); destruct (decide (x2 ≤ a - to_Q r)).
* apply mspc_refl; solve_propholds.
-* destruct (decide (a + to_Q r ≤ x2)) as [R2 | R2].
- + apply (lip_prf f L).
+* destruct (decide (a + to_Q r ≤ x2)); apply (lip_prf f L).
+ + apply (nested_balls A)...
+ + apply (nested_balls A)...
+* destruct (decide (a + to_Q r ≤ x1)); apply (lip_prf f L).
+ + apply mspc_symm; apply mspc_symm in A. apply (nested_balls A)...
+ + apply mspc_symm; apply mspc_symm in A. apply (nested_balls A)...
+* destruct (decide (a + to_Q r ≤ x1)); destruct (decide (a + to_Q r ≤ x2));
+ apply (lip_prf f L).
+ + apply mspc_refl; solve_propholds.
+ + apply mspc_symm; apply mspc_symm in A. apply (nested_balls A)...
+ + apply (nested_balls A)...
+ + apply A.
+Qed.
End Extend.
-(* To be moved to metric.v *)
-Global Arguments Lipschitz X {_} Y {_}.
+(*Section LocallyLipschitz'.
+
+Context `{MetricSpaceBall X, MetricSpaceBall Y}.
+
+Class IsLocallyLipschitz' (f : X -> Y) (L : X -> Q -> Q) :=
+ llip_prf' :> forall (x : X) (r : Q), PropHolds (0 ≤ r) -> IsLipschitz (restrict f x r) (L x r).
+
+End LocallyLipschitz'.*)
Section Picard.
@@ -108,14 +142,23 @@ Notation sy := (sig (mspc_ball ry y0)).
Context (v : sx * sy -> CR) `{!IsLipschitz v Lv}.
-Definition picard' (f : sx -> sy) `{!IsLipschitz f Lf} : sx -> CR :=
- λ x, y0 + int (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) x0 (`x).
+(*Context (f : sx -> sy) `{!IsLipschitz f Lf}.
+
+Check _ : IsLocallyUniformlyContinuous (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) _.*)
-(*Set Printing Coercions.
-Variable f : Lipschitz sx sy. Check f : sx -> sy. Check _ : IsLipschitz f _.*)
+Definition picard' (f : sx -> sy) `{!IsLipschitz f Lf} : Q -> CR :=
+ λ x, y0 + int (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) x0 x.
-(*Program Definition picard'' (f : Lipschitz sx sy) : Lipschitz sx CR :=
- Build_Lipschitz (picard' f) _ _.*)
+(*
+Variable f : Lipschitz sx sy. Check _ : IsLipschitz f _.
+*)
+
+Program Definition picard'' (f : Lipschitz sx sy) : Lipschitz sx CR :=
+ Build_Lipschitz (restrict (picard' f) x0 rx) _ _.
+Next Obligation.
+Check _ : IsLipschitz f _. (* does not work, though exactly the same thing above does *)
+Check _ : IsLipschitz (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) _.
+Check _ : IsLipschitz (λ x, int (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) x0 x) _.
diff --git a/broken/metric.v b/broken/metric.v
index 80af2999..330dc85b 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -475,6 +475,12 @@ Qed.
End Lipschitz.
+(* To be able to say [Lipschitz X Y] instead of [@Lipschitz X _ Y _] *)
+Global Arguments Lipschitz X {_} Y {_}.
+
+(* Allows concluding [IsLipschitz f _] from [f : Lipschitz] *)
+Global Existing Instance lip_proof.
+
(* We need [ExtMetricSpaceClass Z] because we rewrite the ball radius, so
[mspc_radius_proper] is required. See comment before [compose_uc] for why
[{X Y Z : Type}] is necessary. *)
@@ -502,8 +508,14 @@ Section LocallyLipschitz.
Context `{MetricSpaceBall X, MetricSpaceBall Y}.
+(* Delaring llip_prf below an instance introduces a loop between
+[IsLipschitz] and [IsLocallyLipschitz]. But if we are searching for a proof
+of [IsLipschitz f _] for a specific term [f], then Coq should not enter an
+infinite loop because that would require unifying [f] with [restrict _ _ _].
+We need this instance to apply [lip_nonneg (restrict f x r) _] in order
+to prove [0 ≤ Lf x r] when [IsLocallyLipschitz f Lf]. *)
Class IsLocallyLipschitz (f : X -> Y) (L : X -> Q -> Q) :=
- llip_prf : forall (x : X) (r : Q), 0 ≤ r -> IsLipschitz (restrict f x r) (L x r).
+ llip_prf :> forall (x : X) (r : Q), PropHolds (0 ≤ r) -> IsLipschitz (restrict f x r) (L x r).
Global Arguments llip_prf f L {_} x r _.
From ce84ea61596479a38052f7039ab087019a438988 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Sat, 2 Feb 2013 23:25:05 +0100
Subject: [PATCH 064/110] Proved that the result of the Picard operators is
Lipschitz
---
broken/AbstractIntegration.v | 2 +-
broken/Picard.v | 44 ++++++++++++++++++++++++++++++------
2 files changed, 38 insertions(+), 8 deletions(-)
diff --git a/broken/AbstractIntegration.v b/broken/AbstractIntegration.v
index 4d8667ff..80d7fbc9 100644
--- a/broken/AbstractIntegration.v
+++ b/broken/AbstractIntegration.v
@@ -945,7 +945,7 @@ Qed.
End IntegralLipschitzBall.
-Lemma integral_lipschitz (e : Q) :
+Global Instance integral_lipschitz :
IsLocallyLipschitz F (λ a r, Qupper_bound (abs (f a)) + L a r * r).
Proof.
intros a r r_nonneg. constructor.
diff --git a/broken/Picard.v b/broken/Picard.v
index 85e4b51a..b28a3cad 100644
--- a/broken/Picard.v
+++ b/broken/Picard.v
@@ -150,15 +150,45 @@ Definition picard' (f : sx -> sy) `{!IsLipschitz f Lf} : Q -> CR :=
λ x, y0 + int (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) x0 x.
(*
-Variable f : Lipschitz sx sy. Check _ : IsLipschitz f _.
+Variable f : Lipschitz sx sy.
+(*Check _ : IsLipschitz f _.*)
+Check _ : IsLocallyLipschitz (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) _.
+Check _ : Integral (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)).
+Check _ : Integrable (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)).
+Check _ : IsLocallyLipschitz (λ x : Q, int (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) x0 x) _.
+Check _ : IsLocallyLipschitz (picard' f) _. Goal True.
+assert (0 ≤ to_Q rx). apply (proj2_sig rx).
+Check _ : PropHolds (0 ≤ to_Q rx).
+Check _ : IsLipschitz (restrict (picard' f) x0 rx) _.
*)
-Program Definition picard'' (f : Lipschitz sx sy) : Lipschitz sx CR :=
- Build_Lipschitz (restrict (picard' f) x0 rx) _ _.
-Next Obligation.
-Check _ : IsLipschitz f _. (* does not work, though exactly the same thing above does *)
-Check _ : IsLipschitz (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) _.
-Check _ : IsLipschitz (λ x, int (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) x0 x) _.
+Definition picard'' (f : Lipschitz sx sy) : Lipschitz sx CR.
+assert (0 ≤ to_Q rx) by apply (proj2_sig rx). (* Add this to typeclass_instances? *)
+refine (Build_Lipschitz (restrict (picard' f) x0 rx) _ _).
+Defined.
+
+Variable M : Q.
+
+Hypothesis v_bounded : forall z : sx * sy, v z ≤ 'M.
+
+Hypothesis rx_ry : M * rx ≤ ry.
+
+Lemma picard_sy (f : Lipschitz sx sy) (x : sx) : mspc_ball ry y0 (restrict (picard' f) x0 rx x).
+Proof.
+destruct x as [x x_sx]. change (restrict (picard' f) x0 rx (x ↾ x_sx)) with (picard' f x).
+unfold picard'. apply CRball.gball_CRabs.
+match goal with
+| |- context [int ?g ?x1 ?x2] => change (abs (y0 - (y0 + int g x1 x2)) ≤ '`ry)
+end.
+mc_setoid_replace (y0 -
+ (y0 + int (extend x0 rx (v ∘ together Datatypes.id f ∘ diag)) x0 x))
+with (- int (extend x0 rx (v ∘ together Datatypes.id f ∘ diag)) x0 x).
+
+
+rewrite rings.negate_plus_distr.
+
+
+SearchAbout (- (_ + _)).
From 32b8f3293d0cc6089fe4d0a3bf5f049f2394f10e Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 5 Feb 2013 00:29:24 +0100
Subject: [PATCH 065/110] Proved that the image of the image of the Picard
operator lies in the required segment
---
broken/Picard.v | 45 +++++++++++++++++++++++++++------------------
1 file changed, 27 insertions(+), 18 deletions(-)
diff --git a/broken/Picard.v b/broken/Picard.v
index b28a3cad..68ca3d92 100644
--- a/broken/Picard.v
+++ b/broken/Picard.v
@@ -122,16 +122,13 @@ destruct (decide (x1 ≤ a - to_Q r)); destruct (decide (x2 ≤ a - to_Q r)).
+ apply A.
Qed.
-End Extend.
-
-(*Section LocallyLipschitz'.
-
-Context `{MetricSpaceBall X, MetricSpaceBall Y}.
+Lemma extend_inside (x : Q) (A : mspc_ball r a x) : extend x = f (x ↾ A).
+Admitted.
-Class IsLocallyLipschitz' (f : X -> Y) (L : X -> Q -> Q) :=
- llip_prf' :> forall (x : X) (r : Q), PropHolds (0 ≤ r) -> IsLipschitz (restrict f x r) (L x r).
+End Extend.
-End LocallyLipschitz'.*)
+Global Instance : Proper (equiv ==> equiv) (abs (A := CR)).
+Proof. change abs with (@ucFun CR CR CRabs); apply _. Qed.
Section Picard.
@@ -169,9 +166,16 @@ Defined.
Variable M : Q.
-Hypothesis v_bounded : forall z : sx * sy, v z ≤ 'M.
+Hypothesis v_bounded : forall z : sx * sy, abs (v z) ≤ 'M.
-Hypothesis rx_ry : M * rx ≤ ry.
+Hypothesis rx_ry : `rx * M ≤ ry.
+
+Instance M_nonneg : PropHolds (0 ≤ M).
+Proof.
+assert (Ax : mspc_ball rx x0 x0) by apply mspc_refl, (proj2_sig rx).
+assert (Ay : mspc_ball ry y0 y0) by apply mspc_refl, (proj2_sig ry).
+apply CRle_Qle. transitivity (abs (v (x0 ↾ Ax , y0 ↾ Ay))); [apply CRabs_nonneg | apply v_bounded].
+Qed.
Lemma picard_sy (f : Lipschitz sx sy) (x : sx) : mspc_ball ry y0 (restrict (picard' f) x0 rx x).
Proof.
@@ -180,16 +184,21 @@ unfold picard'. apply CRball.gball_CRabs.
match goal with
| |- context [int ?g ?x1 ?x2] => change (abs (y0 - (y0 + int g x1 x2)) ≤ '`ry)
end.
-mc_setoid_replace (y0 -
- (y0 + int (extend x0 rx (v ∘ together Datatypes.id f ∘ diag)) x0 x))
-with (- int (extend x0 rx (v ∘ together Datatypes.id f ∘ diag)) x0 x).
-
-
-rewrite rings.negate_plus_distr.
-
+rewrite rings.negate_plus_distr, plus_assoc, rings.plus_negate_r, rings.plus_0_l, CRabs_negate.
+transitivity ('(abs (x - x0) * M)).
++ apply int_abs_bound. apply _. (* Should not be required *)
+ intros t A.
+ assert (A1 : mspc_ball rx x0 t) by
+ (apply (mspc_ball_convex x0 x); [apply mspc_refl, (proj2_sig rx) | |]; trivial).
+ (* [(extend_inside (A:= A1))]: "Wrong argument name: A" *)
+ rewrite (extend_inside _ _ _ _ A1). apply v_bounded.
++ apply CRle_Qle. change (abs (x - x0) * M ≤ ry). transitivity (`rx * M).
+ - now apply (orders.order_preserving (.* M)), mspc_ball_abs_flip.
+ - apply rx_ry.
+Qed.
-SearchAbout (- (_ + _)).
+End Picard.
(*
From f6aa710570b43034b2620062569a507b23869fe1 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 5 Feb 2013 18:16:51 +0100
Subject: [PATCH 066/110] .
---
broken/Picard.v | 10 +++++++++-
broken/metric.v | 15 ++++++++++++---
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/broken/Picard.v b/broken/Picard.v
index 68ca3d92..1281b137 100644
--- a/broken/Picard.v
+++ b/broken/Picard.v
@@ -161,7 +161,7 @@ Check _ : IsLipschitz (restrict (picard' f) x0 rx) _.
Definition picard'' (f : Lipschitz sx sy) : Lipschitz sx CR.
assert (0 ≤ to_Q rx) by apply (proj2_sig rx). (* Add this to typeclass_instances? *)
-refine (Build_Lipschitz (restrict (picard' f) x0 rx) _ _).
+apply (Build_Lipschitz (restrict (picard' f) x0 rx) _ _).
Defined.
Variable M : Q.
@@ -197,6 +197,14 @@ transitivity ('(abs (x - x0) * M)).
- apply rx_ry.
Qed.
+Require Import Integration.
+
+(*Program*) Definition picard (f : Lipschitz sx sy) : Lipschitz sx sy.
+let K := (Build_Lipschitz (restrict (picard' f) x0 rx) _ _) in idtac.
+
+assert (IsLipschitz (restrict (picard' f) x0 rx) _).
+ Build_Lipschitz (restrict (picard' f) x0 rx) _ _.
+
End Picard.
diff --git a/broken/metric.v b/broken/metric.v
index 330dc85b..e4913e41 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -293,9 +293,18 @@ Context {X Y T : Type} `{Func T X Y, NonEmpty X, ExtMetricSpaceClass Y}.
(* For any type that is convertible to functions we want to define the
supremum metric. This would give rise to an equality and a setoid
-([mspc_equiv] and [mspc_setoid]).However, a type of functions also gets an
-equality using [ext_equiv]. We want the second method to have a priority
-for some type (X -> Y). Therefore *)
+([mspc_equiv] and [mspc_setoid]). Thus, when Coq needs equality on any type
+T at all, it may try to prove that T is a metric space by showing that T is
+convertible to functions, i.e., there is an in instance of [Func T X Y] for
+some types X, Y. This is why we make [Func T X Y] the first assumption
+above. This way, if there is no instance of this class, the search for
+[MetricSpaceBall T] fails quickly and Coq starts looking for an equality on
+T using other means. If we make, for example, [ExtMetricSpaceClass Y] the
+first assumption, Coq may eneter in an infinite loop: To find
+[MetricSpaceBall T] it will look for [ExtMetricSpaceClass Y] for some
+uninstantiated Y, for this in needs [MetricSpaceBall Y] and so on. This is
+all because Coq proves assumptions (i.e., searches instances of classes) in
+the order of the assumptions. *)
Global Instance Linf_func_metric_space_ball : MetricSpaceBall T :=
λ e f g, forall x, ball e (func f x) (func g x).
From 2da833fd11f609a82b4bc2ce29fc73181b72840e Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 7 Feb 2013 02:54:26 +0100
Subject: [PATCH 067/110] Changed Picard iterations from Lipschitz to
UniformlyContinuous. Tested iterations.
---
broken/Picard.v | 132 ++++++++++++++++++++++++++++++++++++++----------
broken/metric.v | 43 +++++++++++++---
2 files changed, 142 insertions(+), 33 deletions(-)
diff --git a/broken/Picard.v b/broken/Picard.v
index 1281b137..4b0970be 100644
--- a/broken/Picard.v
+++ b/broken/Picard.v
@@ -46,8 +46,6 @@ transitivity x2; [easy |]. transitivity (e + x1); [easy |].
apply (orders.order_preserving (e +)); easy.
Qed. (* Too long? *)
-SearchAbout abs Q.
-
Section Extend.
Context `{ExtMetricSpaceClass Y} (a : Q) (r : QnonNeg).
@@ -96,6 +94,7 @@ apply orders.le_flip in H1; apply orders.le_flip in H2.
split; trivial.
Qed.
+(*
Global Instance extend_lip `{!IsLipschitz f L} : IsLipschitz extend L.
Proof with (assumption || (apply orders.le_flip; assumption) || reflexivity).
constructor; [apply (lip_nonneg f L) |].
@@ -121,15 +120,47 @@ destruct (decide (x1 ≤ a - to_Q r)); destruct (decide (x2 ≤ a - to_Q r)).
+ apply (nested_balls A)...
+ apply A.
Qed.
+*)
+
+Global Instance extend_uc `{!IsUniformlyContinuous f mu_f} : IsUniformlyContinuous extend mu_f.
+Admitted.
Lemma extend_inside (x : Q) (A : mspc_ball r a x) : extend x = f (x ↾ A).
Admitted.
End Extend.
+Section Bounded.
+
+Class Bounded {X : Type} (f : X -> CR) (M : Q) := bounded : forall x, abs (f x) ≤ 'M.
+
+Global Instance comp_bounded {X Y : Type} (f : X -> Y) (g : Y -> CR)
+ `{!Bounded g M} : Bounded (g ∘ f) M.
+Proof.
+Admitted.
+
+Global Instance extend_bounded {a : Q} {r : QnonNeg} (f : {x | mspc_ball r a x} -> CR)
+ `{!Bounded f M} : Bounded (extend a r f) M.
+Admitted.
+
+End Bounded.
+
+Global Instance bounded_int_uc
+ `{!Bounded f M} `{!IsLocallyUniformlyContinuous f mu_f} (x0 : Q) :
+ IsUniformlyContinuous (λ x, int f x0 x) (λ e, e / M).
+Admitted.
+
Global Instance : Proper (equiv ==> equiv) (abs (A := CR)).
Proof. change abs with (@ucFun CR CR CRabs); apply _. Qed.
+Global Existing Instance luc_prf.
+
+Global Instance sum_luc `{MetricSpaceBall X}
+ (f g : X -> CR) `{!IsUniformlyContinuous f mu_f} `{!IsUniformlyContinuous g mu_g} :
+ IsUniformlyContinuous (f +1 g) (λ e, meet (mu_f (e * (1 # 2))) (mu_g (e * (1 # 2)))).
+Proof.
+Admitted.
+
Section Picard.
Context (x0 : Q) (y0 : CR) (rx ry : QnonNeg).
@@ -137,18 +168,28 @@ Context (x0 : Q) (y0 : CR) (rx ry : QnonNeg).
Notation sx := (sig (mspc_ball rx x0)).
Notation sy := (sig (mspc_ball ry y0)).
-Context (v : sx * sy -> CR) `{!IsLipschitz v Lv}.
+Context (v : sx * sy -> CR) `{!Bounded v M} `{!IsUniformlyContinuous v mu_v} (L : Q).
+
+Hypothesis v_lip : forall x : sx, IsLipschitz (λ y, v (x, y)) L.
+
+Hypothesis rx_ry : `rx * M ≤ ry.
+
+(*Check _ : MetricSpaceClass sx.
+Check _ : IsUniformlyContinuous v _.
+
+Context (f : sx -> sy) `{!IsUniformlyContinuous f mu_f}.
-(*Context (f : sx -> sy) `{!IsLipschitz f Lf}.
+Check _ : IsUniformlyContinuous ((@Datatypes.id sx) ∘ (@Datatypes.id sx)) _.
+Check _ : IsUniformlyContinuous (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) _.
Check _ : IsLocallyUniformlyContinuous (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) _.*)
-Definition picard' (f : sx -> sy) `{!IsLipschitz f Lf} : Q -> CR :=
+Definition picard' (f : sx -> sy) `{!IsUniformlyContinuous f mu_f} : Q -> CR :=
λ x, y0 + int (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) x0 x.
(*
-Variable f : Lipschitz sx sy.
-(*Check _ : IsLipschitz f _.*)
+Variable f : UniformlyContinuous sx sy.
+Check _ : IsUniformlyContinuous f _.
Check _ : IsLocallyLipschitz (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)) _.
Check _ : Integral (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)).
Check _ : Integrable (extend x0 rx (v ∘ (together Datatypes.id f) ∘ diag)).
@@ -159,27 +200,23 @@ Check _ : PropHolds (0 ≤ to_Q rx).
Check _ : IsLipschitz (restrict (picard' f) x0 rx) _.
*)
-Definition picard'' (f : Lipschitz sx sy) : Lipschitz sx CR.
+Definition picard'' (f : UniformlyContinuous sx sy) : UniformlyContinuous sx CR.
assert (0 ≤ to_Q rx) by apply (proj2_sig rx). (* Add this to typeclass_instances? *)
-apply (Build_Lipschitz (restrict (picard' f) x0 rx) _ _).
+apply (Build_UniformlyContinuous (restrict (picard' f) x0 rx) _ _).
Defined.
-Variable M : Q.
-
-Hypothesis v_bounded : forall z : sx * sy, abs (v z) ≤ 'M.
-
-Hypothesis rx_ry : `rx * M ≤ ry.
-
Instance M_nonneg : PropHolds (0 ≤ M).
Proof.
-assert (Ax : mspc_ball rx x0 x0) by apply mspc_refl, (proj2_sig rx).
+Admitted.
+(*assert (Ax : mspc_ball rx x0 x0) by apply mspc_refl, (proj2_sig rx).
assert (Ay : mspc_ball ry y0 y0) by apply mspc_refl, (proj2_sig ry).
apply CRle_Qle. transitivity (abs (v (x0 ↾ Ax , y0 ↾ Ay))); [apply CRabs_nonneg | apply v_bounded].
-Qed.
+Qed.*)
-Lemma picard_sy (f : Lipschitz sx sy) (x : sx) : mspc_ball ry y0 (restrict (picard' f) x0 rx x).
+Lemma picard_sy (f : UniformlyContinuous sx sy) (x : sx) : mspc_ball ry y0 (picard'' f x).
Proof.
-destruct x as [x x_sx]. change (restrict (picard' f) x0 rx (x ↾ x_sx)) with (picard' f x).
+Admitted.
+(*destruct x as [x x_sx]. change (restrict (picard' f) x0 rx (x ↾ x_sx)) with (picard' f x).
unfold picard'. apply CRball.gball_CRabs.
match goal with
| |- context [int ?g ?x1 ?x2] => change (abs (y0 - (y0 + int g x1 x2)) ≤ '`ry)
@@ -195,18 +232,61 @@ transitivity ('(abs (x - x0) * M)).
+ apply CRle_Qle. change (abs (x - x0) * M ≤ ry). transitivity (`rx * M).
- now apply (orders.order_preserving (.* M)), mspc_ball_abs_flip.
- apply rx_ry.
-Qed.
+Qed.*)
+
+(*Require Import Integration.*)
+
+Definition picard (f : UniformlyContinuous sx sy) : UniformlyContinuous sx sy.
+set (g := picard'' f).
+set (h x := exist _ (g x) (picard_sy f x)).
+assert (C : IsUniformlyContinuous h (uc_mu g)) by admit.
+exact (Build_UniformlyContinuous _ _ C).
+Defined.
+
+End Picard.
+
+Section Computation.
+
+Definition x0 : Q := 0.
+Definition y0 : CR := 1.
+Definition rx : QnonNeg := (1 # 2)%Qnn.
+Definition ry : QnonNeg := 2.
+
+Notation sx := (sig (mspc_ball rx x0)).
+Notation sy := (sig (mspc_ball ry y0)).
+
+Definition v (z : sx * sy) : CR := proj1_sig (snd z).
+Definition M : Q := 2.
+Definition mu_v (e : Q) : Qinf := e.
+
+Instance : Bounded v M.
+Admitted.
+
+Instance : IsUniformlyContinuous v mu_v.
+Admitted.
+
+Program Definition f0 : UniformlyContinuous sx sy :=
+ Build_UniformlyContinuous (λ x, y0) _ _.
+Next Obligation. apply mspc_refl; Qauto_nonneg. Qed.
+Next Obligation. exact Qinf.infinite. Defined.
+Next Obligation. admit. Qed.
+
+Definition picard_iter (n : nat) := nat_iter n (picard x0 y0 rx ry v) f0.
+
+Definition answer (n : positive) (r : CR) : Z :=
+ let m := (iter_pos n _ (Pmult 10) 1%positive) in
+ let (a,b) := (approximate r (1#m)%Qpos)*m in
+ Zdiv a b.
+
+Program Definition half : sx := 1 # 2.
+Next Obligation. admit. Qed.
+
+Time Compute answer 2 (proj1_sig (picard_iter 3 half)).
-Require Import Integration.
-(*Program*) Definition picard (f : Lipschitz sx sy) : Lipschitz sx sy.
-let K := (Build_Lipschitz (restrict (picard' f) x0 rx) _ _) in idtac.
-assert (IsLipschitz (restrict (picard' f) x0 rx) _).
- Build_Lipschitz (restrict (picard' f) x0 rx) _ _.
-End Picard.
(*
diff --git a/broken/metric.v b/broken/metric.v
index e4913e41..d6de434e 100644
--- a/broken/metric.v
+++ b/broken/metric.v
@@ -233,7 +233,7 @@ Section SubMetricSpace.
Context `{ExtMetricSpaceClass X} (P : X -> Prop).
-Global Instance sig_mspc_ball : MetricSpaceBall (sig P) := λ e x y, ball e (` x) (` y).
+Global Instance sig_mspc_ball : MetricSpaceBall (sig P) := λ e x y, ball e (`x) (`y).
Global Instance sig_mspc : ExtMetricSpaceClass (sig P).
Proof.
@@ -247,6 +247,13 @@ constructor.
+ repeat intro; now rapply mspc_closed.
Qed.
+Context {d : MetricSpaceDistance X} {MSC : MetricSpaceClass X}.
+
+Global Instance sig_msd : MetricSpaceDistance (sig P) := λ x y, msd (`x) (`y).
+
+Global Instance sig_mspc_distance : MetricSpaceClass (sig P).
+Proof. intros x1 x2; apply: mspc_distance. Qed.
+
End SubMetricSpace.
Section ProductMetricSpace.
@@ -275,6 +282,17 @@ constructor.
+ intros e a b A; split; apply mspc_closed; firstorder.
Qed.
+Context {dx : MetricSpaceDistance X} {dy : MetricSpaceDistance Y}
+ {MSCx : MetricSpaceClass X} {MSCy : MetricSpaceClass Y}.
+
+(* Need consistent names of instances for sig, product and func *)
+
+Global Instance Linf_product_msd : MetricSpaceDistance (X * Y) :=
+ λ a b, join (msd (fst a) (fst b)) (msd (snd a) (snd b)).
+
+Global Instance Linf_product_mspc_distance : MetricSpaceClass (X * Y).
+Admitted.
+
End ProductMetricSpace.
(** We define [Func T X Y] if there is a coercion func from T to (X -> Y),
@@ -458,8 +476,10 @@ Definition lip_modulus (L e : Q) : Qinf :=
(* It is nice to declare only [MetricSpaceBall X] above because this is all
we need to know about X to define [IsLipschitz]. But for the following
theorem we also need [ExtMetricSpaceClass X], [MetricSpaceDistance X] and
-[MetricSpaceClass X]. How to add these assumptions? Saying [`{MetricSpaceClass X}]
-would add a second copy of [MetricSpaceBall X]. *)
+[MetricSpaceClass X]. How to add these assumptions? Saying
+[`{MetricSpaceClass X}] would add a second copy of [MetricSpaceBall X]. We
+write the names EM and m below because "Anonymous variables not allowed in
+contexts" *)
Context {EM : ExtMetricSpaceClass X} {m : MetricSpaceDistance X}.
@@ -641,7 +661,7 @@ Qed.
Definition together {X1 Y1 X2 Y2 : Type} (f1 : X1 -> Y1) (f2 : X2 -> Y2) : X1 * X2 -> Y1 * Y2 :=
λ p, (f1 (fst p), f2 (snd p)).
-Global Instance together_lip
+(*Global Instance together_lip
`{ExtMetricSpaceClass X1, ExtMetricSpaceClass Y1, ExtMetricSpaceClass X2, ExtMetricSpaceClass Y2}
(f1 : X1 -> Y1) (f2 : X2 -> Y2)
`{!IsLipschitz f1 L1, !IsLipschitz f2 L2} : IsLipschitz (together f1 f2) (join L1 L2).
@@ -670,8 +690,17 @@ constructor.
(* [apply (order_preserving (.* e)), join_ub_l.] does not work *)
apply lip_prf; trivial.
- apply (mspc_monotone (L2 * e)); [apply (order_preserving (.* e)); apply join_ub_r |].
- apply lip_prf; trivial.
-(* Proof of [IsUniformlyContinuous (together f1 f2) _].
+ apply lip_prf; trivial.*)
+
+Global Instance together_uc
+ `{ExtMetricSpaceClass X1, ExtMetricSpaceClass Y1, ExtMetricSpaceClass X2, ExtMetricSpaceClass Y2}
+ (f1 : X1 -> Y1) (f2 : X2 -> Y2)
+ `{!IsUniformlyContinuous f1 mu1, !IsUniformlyContinuous f2 mu2} :
+ IsUniformlyContinuous (together f1 f2) (λ e, meet (mu1 e) (mu2 e)).
+Proof.
+Admitted.
+(*
+constructor.
+ intros e e_pos. apply min_ind; [apply (uc_pos f1) | apply (uc_pos f2)]; trivial.
(* [trivial] solves, in particular, [IsUniformlyContinuous f1 mu1], which should
have been solved automatically *)
@@ -680,8 +709,8 @@ constructor.
apply (mspc_monotone' (min (mu1 e) (mu2 e))); [apply: meet_lb_l | trivial].
- apply (uc_prf f2 mu2); trivial.
apply (mspc_monotone' (min (mu1 e) (mu2 e))); [apply: meet_lb_r | trivial].
-*)
Qed.
+*)
End ProductSpaceFunctions.
From ef2c3c18890f0a73311d794585fee11112cca1e6 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 7 Feb 2013 04:01:44 +0100
Subject: [PATCH 068/110] Created directory 'ode' for ODE solvers
---
broken/Picard.v | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/broken/Picard.v b/broken/Picard.v
index 4b0970be..84d84b9d 100644
--- a/broken/Picard.v
+++ b/broken/Picard.v
@@ -281,7 +281,7 @@ Definition answer (n : positive) (r : CR) : Z :=
Program Definition half : sx := 1 # 2.
Next Obligation. admit. Qed.
-Time Compute answer 2 (proj1_sig (picard_iter 3 half)).
+Time Compute answer 2 (proj1_sig (picard_iter 2 half)).
From a34e5ea908a00c62907cafa996a2b87aa368db62 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 7 Feb 2013 04:04:49 +0100
Subject: [PATCH 069/110] Moved ODE solver files to ode/
---
{broken => ode}/AbstractIntegration.v | 0
{broken => ode}/BanachFixpoint.v | 0
{broken => ode}/FromMetric2.v | 0
{broken => ode}/Picard.v | 0
{broken => ode}/SimpleIntegration.v | 0
{broken => ode}/metric.v | 0
6 files changed, 0 insertions(+), 0 deletions(-)
rename {broken => ode}/AbstractIntegration.v (100%)
rename {broken => ode}/BanachFixpoint.v (100%)
rename {broken => ode}/FromMetric2.v (100%)
rename {broken => ode}/Picard.v (100%)
rename {broken => ode}/SimpleIntegration.v (100%)
rename {broken => ode}/metric.v (100%)
diff --git a/broken/AbstractIntegration.v b/ode/AbstractIntegration.v
similarity index 100%
rename from broken/AbstractIntegration.v
rename to ode/AbstractIntegration.v
diff --git a/broken/BanachFixpoint.v b/ode/BanachFixpoint.v
similarity index 100%
rename from broken/BanachFixpoint.v
rename to ode/BanachFixpoint.v
diff --git a/broken/FromMetric2.v b/ode/FromMetric2.v
similarity index 100%
rename from broken/FromMetric2.v
rename to ode/FromMetric2.v
diff --git a/broken/Picard.v b/ode/Picard.v
similarity index 100%
rename from broken/Picard.v
rename to ode/Picard.v
diff --git a/broken/SimpleIntegration.v b/ode/SimpleIntegration.v
similarity index 100%
rename from broken/SimpleIntegration.v
rename to ode/SimpleIntegration.v
diff --git a/broken/metric.v b/ode/metric.v
similarity index 100%
rename from broken/metric.v
rename to ode/metric.v
From f4a0b6bc1a4ade5c1635be17cf1a98ae8e9a623a Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Mon, 11 Feb 2013 22:42:00 +0100
Subject: [PATCH 070/110] Made BanachFixpoint.v compile
---
ode/BanachFixpoint.v | 4 ++++
ode/Picard.v | 7 +++++++
ode/metric.v | 1 -
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/ode/BanachFixpoint.v b/ode/BanachFixpoint.v
index b110674d..17807a1c 100644
--- a/ode/BanachFixpoint.v
+++ b/ode/BanachFixpoint.v
@@ -11,6 +11,7 @@ Import Qround Qpower.
Require Import metric.
Local Notation ball := mspc_ball.
+Local Notation "x ²" := (x * x) (at level 30) : mc_scope.
Section BanachFixpoint.
@@ -47,6 +48,9 @@ rewrite <- flip_lt_negate in A. apply (strictly_order_preserving (1 +)) in A.
now rewrite plus_negate_r in A.
Qed.
+Instance : forall q : Q, PropHolds (0 < q) -> PropHolds (q ≠ 0).
+Proof. apply lt_ne_flip. Qed.
+
Lemma dist_xn_xSn : forall n : nat, ball (d * q^n) (x n) (x (1 + n)).
Proof.
induction n using nat_induction.
diff --git a/ode/Picard.v b/ode/Picard.v
index 84d84b9d..318f73bd 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -245,6 +245,12 @@ Defined.
End Picard.
+Require Import BanachFixpoint.
+
+
+
+
+
Section Computation.
Definition x0 : Q := 0.
@@ -285,6 +291,7 @@ Time Compute answer 2 (proj1_sig (picard_iter 2 half)).
+End Computation.
diff --git a/ode/metric.v b/ode/metric.v
index d6de434e..332279b2 100644
--- a/ode/metric.v
+++ b/ode/metric.v
@@ -16,7 +16,6 @@ Import Qround Qpower Qinf.notations.
Set Printing Coercions.
Notation "f +1 g" := (λ x, f x + g x) (at level 50, left associativity).
-(*Notation "x ²" := (x * x) (at level 30) : mc_scope.*)
Definition comp_inf {X Z : Type} (g : Q -> Z) (f : X -> Qinf) (inf : Z) (x : X) :=
match (f x) with
From 3dc2166003358b340671d30605f590600bf7ee31 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 12 Feb 2013 23:01:42 +0100
Subject: [PATCH 071/110] .
---
ode/AbstractIntegration.v | 2 ++
ode/Picard.v | 66 ++++++++++++++++++++++++++++++---------
ode/SimpleIntegration.v | 2 ++
ode/metric.v | 15 ++-------
4 files changed, 58 insertions(+), 27 deletions(-)
diff --git a/ode/AbstractIntegration.v b/ode/AbstractIntegration.v
index 80d7fbc9..155f4264 100644
--- a/ode/AbstractIntegration.v
+++ b/ode/AbstractIntegration.v
@@ -102,6 +102,8 @@ Hint Immediate ball_refl Qle_refl.
(** Next up, the actual interface for integrable functions. *)
+Bind Scope Q_scope with Q.
+
Class Integral (f: Q → CR) := integrate: forall (from: Q) (w: QnonNeg), CR.
Implicit Arguments integrate [[Integral]].
diff --git a/ode/Picard.v b/ode/Picard.v
index 318f73bd..0e0c23ad 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -18,6 +18,13 @@ Require Import canonical_names decision setoid_tactics.
Close Scope uc_scope. (* There is a leak in some module *)
Open Scope signature_scope. (* To interpret "==>" *)
+Bind Scope mc_scope with Q.
+
+Local Notation ball := mspc_ball.
+
+Instance Q_nonneg (rx : QnonNeg) : PropHolds (@le Q _ 0 rx).
+Proof. apply (proj2_sig rx). Qed.
+
(* The following instances are needed to show that Lipschitz functions are
uniformly continuous: metric.lip_uc *)
Global Instance Qmsd : MetricSpaceDistance Q := λ x y, abs (x - y).
@@ -26,16 +33,24 @@ Global Instance Qmsc : MetricSpaceClass Q.
Proof. intros x1 x2; apply gball_Qabs; reflexivity. Qed.
(* Should be generalized from Q *)
-Lemma mspc_ball_abs (r x y : Q) : mspc_ball r x y ↔ abs (x - y) ≤ r.
+Lemma mspc_ball_plus_l (e x y y' : Q) : ball e y y' -> ball e (x + y) (x + y').
+Proof.
+intro A. assert (A1 := radius_nonneg _ _ _ A).
+destruct (orders.le_equiv_lt _ _ A1) as [e_zero | e_pos].
++ rewrite <- e_zero in A |- *. now rewrite A.
++ apply (gball_pos e_pos _ _) in A. now apply (gball_pos e_pos _ _), Qball_plus_r.
+Qed.
+
+Lemma mspc_ball_abs (r x y : Q) : ball r x y ↔ abs (x - y) ≤ r.
Proof. apply gball_Qabs. Qed.
-Lemma mspc_ball_abs_flip (r x y : Q) : mspc_ball r x y ↔ abs (y - x) ≤ r.
+Lemma mspc_ball_abs_flip (r x y : Q) : ball r x y ↔ abs (y - x) ≤ r.
Proof.
rewrite <- abs.abs_negate, <- rings.negate_swap_r. apply gball_Qabs.
Qed.
Lemma nested_balls {x1 x2 y1 y2 e : Q} :
- mspc_ball e x1 x2 -> x1 ≤ y1 -> y1 ≤ y2 -> y2 ≤ x2 -> mspc_ball e y1 y2.
+ ball e x1 x2 -> x1 ≤ y1 -> y1 ≤ y2 -> y2 ≤ x2 -> ball e y1 y2.
Proof.
intros B A1 A2 A3. apply mspc_ball_abs_flip in B. apply mspc_ball_abs_flip.
assert (x1 ≤ x2) by (transitivity y1; [| transitivity y2]; trivial).
@@ -56,21 +71,21 @@ necessarily continuous. This may be OK because we could add the premise [0
definition below is not well-typed because if [r < 0], then [ball r a (a -
r)] is false, so we can't apply [f] to [a - r]. So we assume [r : QnonNeg]. *)
-Lemma mspc_ball_edge_l : mspc_ball r a (a - `r).
+Lemma mspc_ball_edge_l : ball r a (a - `r).
Proof.
destruct r as [e ?]; simpl.
apply gball_Qabs. mc_setoid_replace (a - (a - e)) with e by ring.
change (abs e ≤ e). rewrite abs.abs_nonneg; [reflexivity | trivial].
Qed.
-Lemma mspc_ball_edge_r : mspc_ball r a (a + `r).
+Lemma mspc_ball_edge_r : ball r a (a + `r).
Proof.
destruct r as [e ?]; simpl.
apply Qmetric.gball_Qabs. mc_setoid_replace (a - (a + e)) with (-e) by ring.
change (abs (-e) ≤ e). rewrite abs.abs_negate, abs.abs_nonneg; [reflexivity | trivial].
Qed.
-Context (f : sig (mspc_ball r a) -> Y).
+Context (f : sig (ball r a) -> Y).
(* Since the following is a Program Definition, we could write [f (a - r)]
and prove the obligation [mspc_ball r a (a - r)]. However, this obligation
@@ -125,7 +140,7 @@ Qed.
Global Instance extend_uc `{!IsUniformlyContinuous f mu_f} : IsUniformlyContinuous extend mu_f.
Admitted.
-Lemma extend_inside (x : Q) (A : mspc_ball r a x) : extend x = f (x ↾ A).
+Lemma extend_inside (x : Q) (A : ball r a x) : extend x = f (x ↾ A).
Admitted.
End Extend.
@@ -139,7 +154,7 @@ Global Instance comp_bounded {X Y : Type} (f : X -> Y) (g : Y -> CR)
Proof.
Admitted.
-Global Instance extend_bounded {a : Q} {r : QnonNeg} (f : {x | mspc_ball r a x} -> CR)
+Global Instance extend_bounded {a : Q} {r : QnonNeg} (f : {x | ball r a x} -> CR)
`{!Bounded f M} : Bounded (extend a r f) M.
Admitted.
@@ -165,15 +180,23 @@ Section Picard.
Context (x0 : Q) (y0 : CR) (rx ry : QnonNeg).
-Notation sx := (sig (mspc_ball rx x0)).
-Notation sy := (sig (mspc_ball ry y0)).
+Notation sx := (sig (ball rx x0)).
+Notation sy := (sig (ball ry y0)).
Context (v : sx * sy -> CR) `{!Bounded v M} `{!IsUniformlyContinuous v mu_v} (L : Q).
Hypothesis v_lip : forall x : sx, IsLipschitz (λ y, v (x, y)) L.
+Hypothesis L_rx : L * rx < 1.
+
Hypothesis rx_ry : `rx * M ≤ ry.
+Instance L_nonneg : PropHolds (0 ≤ L).
+Proof.
+assert (B : ball rx x0 x0) by (apply mspc_refl; solve_propholds).
+apply (lip_nonneg (λ y, v ((x0 ↾ B), y)) L).
+Qed.
+
(*Check _ : MetricSpaceClass sx.
Check _ : IsUniformlyContinuous v _.
@@ -201,7 +224,6 @@ Check _ : IsLipschitz (restrict (picard' f) x0 rx) _.
*)
Definition picard'' (f : UniformlyContinuous sx sy) : UniformlyContinuous sx CR.
-assert (0 ≤ to_Q rx) by apply (proj2_sig rx). (* Add this to typeclass_instances? *)
apply (Build_UniformlyContinuous (restrict (picard' f) x0 rx) _ _).
Defined.
@@ -213,7 +235,7 @@ assert (Ay : mspc_ball ry y0 y0) by apply mspc_refl, (proj2_sig ry).
apply CRle_Qle. transitivity (abs (v (x0 ↾ Ax , y0 ↾ Ay))); [apply CRabs_nonneg | apply v_bounded].
Qed.*)
-Lemma picard_sy (f : UniformlyContinuous sx sy) (x : sx) : mspc_ball ry y0 (picard'' f x).
+Lemma picard_sy (f : UniformlyContinuous sx sy) (x : sx) : ball ry y0 (picard'' f x).
Proof.
Admitted.
(*destruct x as [x x_sx]. change (restrict (picard' f) x0 rx (x ↾ x_sx)) with (picard' f x).
@@ -243,6 +265,22 @@ assert (C : IsUniformlyContinuous h (uc_mu g)) by admit.
exact (Build_UniformlyContinuous _ _ C).
Defined.
+Lemma picard_contraction : IsContraction picard (L * rx).
+Proof.
+constructor; [| exact L_rx].
+constructor; [solve_propholds |].
+intros f1 f2 e A [x ?].
+change (ball (L * rx * e) (picard' f1 x) (picard' f2 x)).
+unfold picard'.
+SearchAbout (gball _ (?x + _)%CR (?y + _)%CR).
+apply mspc_ball_plus_l.
+SearchAbout "ball" "plus".
+
+
+
+
+
+
End Picard.
Require Import BanachFixpoint.
@@ -258,8 +296,8 @@ Definition y0 : CR := 1.
Definition rx : QnonNeg := (1 # 2)%Qnn.
Definition ry : QnonNeg := 2.
-Notation sx := (sig (mspc_ball rx x0)).
-Notation sy := (sig (mspc_ball ry y0)).
+Notation sx := (sig (ball rx x0)).
+Notation sy := (sig (ball ry y0)).
Definition v (z : sx * sy) : CR := proj1_sig (snd z).
Definition M : Q := 2.
diff --git a/ode/SimpleIntegration.v b/ode/SimpleIntegration.v
index 5e1ff39c..a48e8a94 100644
--- a/ode/SimpleIntegration.v
+++ b/ode/SimpleIntegration.v
@@ -21,6 +21,8 @@ Require Import
metric FromMetric2
implementations.stdlib_rationals.
+Bind Scope Q_scope with Q.
+
Open Scope Q_scope.
Lemma gball_mspc_ball {X : MetricSpace} (r : Q) (x y : X) :
diff --git a/ode/metric.v b/ode/metric.v
index 332279b2..41a908dc 100644
--- a/ode/metric.v
+++ b/ode/metric.v
@@ -108,12 +108,12 @@ Ltac nat_simpl := unfold
Tactic Notation "Qsimpl" hyp_list(A) := revert A; Qsimpl'; intros A.
*)
+Bind Scope mc_scope with Q.
+
Section QField.
Add Field Q : (stdlib_field_theory Q).
-Bind Scope mc_scope with Q.
-
Class MetricSpaceBall (X : Type) : Type := mspc_ball: Qinf → relation X.
Local Notation ball := mspc_ball.
@@ -136,17 +136,6 @@ Class ExtMetricSpaceClass (X : Type) `{MetricSpaceBall X} : Prop := {
(∀ d: Q, 0 < d -> ball (e + d) a b) → ball e a b
}.
-(*
-This shows that if axioms of metric space are formulated with Qinf instead of Q,
-the [apply] tactic won't be able to unify them with goals using Q
-
-Goal (forall (e1 e2 : Qinf) (x1 x2 : X), ball (e1 + e2) x1 x2) ->
- (forall (e1 e2 : Q) (x1 x2 : X), ball (e1 + e2) x1 x2).
-intros A e1 e2 x1 x2.
-change (e1 + e2 : Qinf) with ((Qinf.finite e1) + (Qinf.finite e2)).
-apply A.
-*)
-
Class MetricSpaceDistance (X : Type) := msd : X -> X -> Q.
Class MetricSpaceClass (X : Type) `{ExtMetricSpaceClass X} `{MetricSpaceDistance X} : Prop :=
From 4f437f59dfd9b93e62b65b6187f01759c5623c54 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Wed, 13 Feb 2013 21:50:56 +0100
Subject: [PATCH 072/110] .
---
ode/AbstractIntegration.v | 7 +++++++
ode/Picard.v | 32 +++++++++++++++++++++++++-------
2 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/ode/AbstractIntegration.v b/ode/AbstractIntegration.v
index 155f4264..1ae7eb92 100644
--- a/ode/AbstractIntegration.v
+++ b/ode/AbstractIntegration.v
@@ -899,6 +899,13 @@ Qed.
End IntegralTotal.
+Lemma int_plus (f g : Q -> CR) `{Integrable f, Integrable g}
+ `{!IsLocallyUniformlyContinuous f f_mu, !IsLocallyUniformlyContinuous f f_mu} (a b : Q) :
+ int f a b + int g a b = int (f +1 g) a b.
+Proof.
+Admitted.
+
+
Import interfaces.orders orders.semirings.
Definition Qupper_bound (x : CR) := approximate x 1%Qpos + 1.
diff --git a/ode/Picard.v b/ode/Picard.v
index 0e0c23ad..88f4c308 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -32,8 +32,9 @@ Global Instance Qmsd : MetricSpaceDistance Q := λ x y, abs (x - y).
Global Instance Qmsc : MetricSpaceClass Q.
Proof. intros x1 x2; apply gball_Qabs; reflexivity. Qed.
-(* Should be generalized from Q *)
-Lemma mspc_ball_plus_l (e x y y' : Q) : ball e y y' -> ball e (x + y) (x + y').
+
+(* Should be generalized from Q and CR *)
+Lemma mspc_ball_Qplus_l (e x y y' : Q) : ball e y y' -> ball e (x + y) (x + y').
Proof.
intro A. assert (A1 := radius_nonneg _ _ _ A).
destruct (orders.le_equiv_lt _ _ A1) as [e_zero | e_pos].
@@ -41,18 +42,33 @@ destruct (orders.le_equiv_lt _ _ A1) as [e_zero | e_pos].
+ apply (gball_pos e_pos _ _) in A. now apply (gball_pos e_pos _ _), Qball_plus_r.
Qed.
-Lemma mspc_ball_abs (r x y : Q) : ball r x y ↔ abs (x - y) ≤ r.
+Lemma mspc_ball_CRplus_l (e : Q) (x y y' : CR) : ball e y y' -> ball e (x + y) (x + y').
+Proof.
+intro A. rewrite <- (rings.plus_0_l e). apply CRgball_plus; [| easy].
+(*[ apply mspc_refl] does not work *)
+change (ball 0 x x); now apply mspc_refl.
+Qed.
+
+Lemma mspc_ball_Qabs (r x y : Q) : ball r x y ↔ abs (x - y) ≤ r.
Proof. apply gball_Qabs. Qed.
-Lemma mspc_ball_abs_flip (r x y : Q) : ball r x y ↔ abs (y - x) ≤ r.
+Lemma mspc_ball_Qabs_flip (r x y : Q) : ball r x y ↔ abs (y - x) ≤ r.
Proof.
rewrite <- abs.abs_negate, <- rings.negate_swap_r. apply gball_Qabs.
Qed.
+Lemma mspc_ball_CRabs (r : Q) (x y : CR) : ball r x y ↔ abs (x - y) ≤ 'r.
+Proof. apply CRball.gball_CRabs. Qed.
+
+(*Lemma mspc_ball_CRabs_flip (r : Q) (x y : CR) : ball r x y ↔ abs (y - x) ≤ 'r.
+Proof.
+rewrite <- abs.abs_negate, <- rings.negate_swap_r. apply gball_Qabs.
+Qed.*)
+
Lemma nested_balls {x1 x2 y1 y2 e : Q} :
ball e x1 x2 -> x1 ≤ y1 -> y1 ≤ y2 -> y2 ≤ x2 -> ball e y1 y2.
Proof.
-intros B A1 A2 A3. apply mspc_ball_abs_flip in B. apply mspc_ball_abs_flip.
+intros B A1 A2 A3. apply mspc_ball_Qabs_flip in B. apply mspc_ball_Qabs_flip.
assert (x1 ≤ x2) by (transitivity y1; [| transitivity y2]; trivial).
rewrite abs.abs_nonneg by now apply rings.flip_nonneg_minus.
rewrite abs.abs_nonneg in B by now apply rings.flip_nonneg_minus.
@@ -252,7 +268,7 @@ transitivity ('(abs (x - x0) * M)).
(* [(extend_inside (A:= A1))]: "Wrong argument name: A" *)
rewrite (extend_inside _ _ _ _ A1). apply v_bounded.
+ apply CRle_Qle. change (abs (x - x0) * M ≤ ry). transitivity (`rx * M).
- - now apply (orders.order_preserving (.* M)), mspc_ball_abs_flip.
+ - now apply (orders.order_preserving (.* M)), mspc_ball_Qabs_flip.
- apply rx_ry.
Qed.*)
@@ -271,7 +287,9 @@ constructor; [| exact L_rx].
constructor; [solve_propholds |].
intros f1 f2 e A [x ?].
change (ball (L * rx * e) (picard' f1 x) (picard' f2 x)).
-unfold picard'.
+unfold picard'. apply mspc_ball_CRplus_l, mspc_ball_CRabs.
+
+
SearchAbout (gball _ (?x + _)%CR (?y + _)%CR).
apply mspc_ball_plus_l.
SearchAbout "ball" "plus".
From bbd13ac592f8e8f3dd25056ba326eca43af2dc9c Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 14 Feb 2013 21:51:13 +0100
Subject: [PATCH 073/110] .
---
ode/AbstractIntegration.v | 46 +++++++++++++++++++++++++++++++--------
ode/FromMetric2.v | 2 +-
ode/metric.v | 9 +++++++-
3 files changed, 46 insertions(+), 11 deletions(-)
diff --git a/ode/AbstractIntegration.v b/ode/AbstractIntegration.v
index 1ae7eb92..b68f7020 100644
--- a/ode/AbstractIntegration.v
+++ b/ode/AbstractIntegration.v
@@ -591,7 +591,7 @@ Proof. reflexivity. Qed.
Lemma cmΣ_succ {M : CMonoid} (n : nat) (f : nat -> M) : cmΣ (S n) f = f n [+] cmΣ n f.
Proof. reflexivity. Qed.
-Lemma cmΣ_plus (n : nat) (f g : nat -> CR) : cmΣ n (f +1 g) = cmΣ n f + cmΣ n g.
+Lemma cmΣ_plus (n : nat) (f g : nat -> CR) : cmΣ n (f + g) = cmΣ n f + cmΣ n g.
Proof.
induction n as [| n IH].
+ symmetry; apply cm_rht_unit.
@@ -617,7 +617,7 @@ rewrite (mult_comm _ ('(n : Q))), mult_assoc, CRmult_Qmult, step_mult; reflexivi
Qed.
Lemma riemann_sum_plus (f g : Q -> CR) (a w : Q) (n : positive) :
- riemann_sum (f +1 g) a w n = riemann_sum f a w n + riemann_sum g a w n.
+ riemann_sum (f + g) a w n = riemann_sum f a w n + riemann_sum g a w n.
Proof.
unfold riemann_sum. rewrite <- cmΣ_plus. apply cm_Sum_eq. intro k.
change (
@@ -708,10 +708,11 @@ Context (f g : Q -> CR)
`{!IsLocallyUniformlyContinuous f f_mu, !IsLocallyUniformlyContinuous g g_mu}
`{Integral f, !Integrable f, Integral g, !Integrable g}.
-Global Instance integrate_sum : Integral (f +1 g) := λ a w, integrate f a w + integrate g a w.
+Global Instance integrate_sum : Integral (f + g) := λ a w, integrate f a w + integrate g a w.
+Global Instance integrate_negate : Integral (- f) := λ a w, - integrate f a w.
Lemma integral_sum_additive (a : Q) (b c : QnonNeg) :
- ∫ (f +1 g) a b + ∫ (f +1 g) (a + ` b) c = ∫ (f +1 g) a (b + c)%Qnn.
+ ∫ (f + g) a b + ∫ (f + g) (a + ` b) c = ∫ (f + g) a (b + c)%Qnn.
Proof.
unfold integrate, integrate_sum.
rewrite <- !integral_additive; trivial.
@@ -720,11 +721,20 @@ change (
(∫ f a b + ∫ f (a + ` b) c) + (∫ g a b + ∫ g (a + ` b) c)). ring.
Qed.
+Lemma integral_negate_additive (a : Q) (b c : QnonNeg) :
+ ∫ (- f) a b + ∫ (- f) (a + ` b) c = ∫ (- f) a (b + c)%Qnn.
+Proof.
+unfold integrate, integrate_negate.
+rewrite <- rings.negate_plus_distr. apply CRopp_wd_Proper. (* Where is it defined? *)
+now apply integral_additive.
+Qed.
+
+
(* When the last argument of ball is ('(width * mid)), typechecking diverges *)
Lemma integral_sum_integrable (from : Q) (width : Qpos) (mid : Q) (r : Qpos) :
(∀ x : Q, from ≤ x ≤ from + width → ball r (f x + g x) ('mid))
- → ball (width * r) (∫ (f +1 g) from width) ('((width : Q) * mid)).
+ → ball (width * r) (∫ (f + g) from width) ('((width : Q) * mid)).
Proof.
intros A. apply ball_gball; simpl. apply gball_closed. intros e e_pos.
setoid_replace (width * r + e)%Q with (e + width * r)%Q by apply Qplus_comm.
@@ -734,7 +744,7 @@ set (n := Pos.max Nf Ng).
assert (le_Nf_n : (Nf <= n)%positive) by apply Pos.le_max_l.
assert (le_Ng_n : (Ng <= n)%positive) by apply Pos.le_max_r.
specialize (F n le_Nf_n). specialize (G n le_Ng_n).
-apply gball_triangle with (b := riemann_sum (f +1 g) from width n).
+apply gball_triangle with (b := riemann_sum (f + g) from width n).
+ rewrite riemann_sum_plus. setoid_replace e with ((1#2) * e + (1#2) * e)%Q by ring.
apply CRgball_plus; apply gball_sym; trivial.
+ (* apply riemann_sum_bounds. diverges *)
@@ -742,7 +752,15 @@ apply gball_triangle with (b := riemann_sum (f +1 g) from width n).
intros. apply ball_gball. apply A; trivial.
Qed.
-Global Instance : Integrable (f +1 g).
+Lemma integral_negate_integrable (from : Q) (width : Qpos) (mid : Q) (r : Qpos) :
+ (∀ x : Q, from ≤ x ≤ from + width → ball r ((- f) x) ('mid))
+ → ball (width * r) (∫ (- f) from width) ('((width : Q) * mid)).
+Proof.
+intros A. unfold integrate, integrate_negate.
+SearchAbout gball CRopp.
+SearchAbout (gball _ (CRopp _) (CRopp _)).
+
+Global Instance : Integrable (f + g).
constructor.
+ apply integral_sum_additive.
+ apply integral_sum_integrable.
@@ -901,9 +919,19 @@ End IntegralTotal.
Lemma int_plus (f g : Q -> CR) `{Integrable f, Integrable g}
`{!IsLocallyUniformlyContinuous f f_mu, !IsLocallyUniformlyContinuous f f_mu} (a b : Q) :
- int f a b + int g a b = int (f +1 g) a b.
+ int f a b + int g a b = int (f + g) a b.
Proof.
-Admitted.
+unfold int. destruct (decide (a ≤ b)); [reflexivity |].
+symmetry; unfold integrate at 1, integrate_sum.
+apply rings.negate_plus_distr. (* does not work without unfold *)
+Qed.
+SearchAbout (- (_ + _)).
+
+
+
+
+
+
Import interfaces.orders orders.semirings.
diff --git a/ode/FromMetric2.v b/ode/FromMetric2.v
index d9aa54cb..50b82732 100644
--- a/ode/FromMetric2.v
+++ b/ode/FromMetric2.v
@@ -144,7 +144,7 @@ End LocallyLipschitz'.*)
Global Instance sum_llip `{MetricSpaceBall X}
(f g : X -> CR) `{!IsLocallyLipschitz f Lf} `{!IsLocallyLipschitz g Lg} :
- IsLocallyLipschitz (f +1 g) (λ x r, Lf x r + Lg x r).
+ IsLocallyLipschitz (f + g) (λ x r, Lf x r + Lg x r).
Proof.
constructor.
+ pose proof (lip_nonneg (restrict f x r) (Lf x r)).
diff --git a/ode/metric.v b/ode/metric.v
index 41a908dc..045c0b7e 100644
--- a/ode/metric.v
+++ b/ode/metric.v
@@ -15,7 +15,14 @@ Import Qround Qpower Qinf.notations.
Set Printing Coercions.
-Notation "f +1 g" := (λ x, f x + g x) (at level 50, left associativity).
+Definition ext_plus {A} `{Plus B} : Plus (A -> B) := λ f g x, f x + g x.
+Hint Extern 10 (Plus (_ -> _)) => apply @ext_plus : typeclass_instances.
+
+Definition ext_negate {A} `{Negate B} : Negate (A -> B) := λ f x, - (f x).
+Hint Extern 10 (Negate (_ -> _)) => apply @ext_negate : typeclass_instances.
+
+(* The definitions above replace the following.
+Notation "f +1 g" := (λ x, f x + g x) (at level 50, left associativity).*)
Definition comp_inf {X Z : Type} (g : Q -> Z) (f : X -> Qinf) (inf : Z) (x : X) :=
match (f x) with
From 3b7e09bccd6c08ae01ae81215b47d7c2c0fe9c15 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Sat, 16 Feb 2013 17:23:37 +0100
Subject: [PATCH 074/110] Merged master and UC (UniformlyContinuous)
---
ode/AbstractIntegration.v | 11 ++---------
ode/Picard.v | 8 ++++----
2 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/ode/AbstractIntegration.v b/ode/AbstractIntegration.v
index b68f7020..6b9be682 100644
--- a/ode/AbstractIntegration.v
+++ b/ode/AbstractIntegration.v
@@ -752,13 +752,13 @@ apply gball_triangle with (b := riemann_sum (f + g) from width n).
intros. apply ball_gball. apply A; trivial.
Qed.
-Lemma integral_negate_integrable (from : Q) (width : Qpos) (mid : Q) (r : Qpos) :
+(*Lemma integral_negate_integrable (from : Q) (width : Qpos) (mid : Q) (r : Qpos) :
(∀ x : Q, from ≤ x ≤ from + width → ball r ((- f) x) ('mid))
→ ball (width * r) (∫ (- f) from width) ('((width : Q) * mid)).
Proof.
intros A. unfold integrate, integrate_negate.
SearchAbout gball CRopp.
-SearchAbout (gball _ (CRopp _) (CRopp _)).
+SearchAbout (gball _ (CRopp _) (CRopp _)).*)
Global Instance : Integrable (f + g).
constructor.
@@ -925,13 +925,6 @@ unfold int. destruct (decide (a ≤ b)); [reflexivity |].
symmetry; unfold integrate at 1, integrate_sum.
apply rings.negate_plus_distr. (* does not work without unfold *)
Qed.
-SearchAbout (- (_ + _)).
-
-
-
-
-
-
Import interfaces.orders orders.semirings.
diff --git a/ode/Picard.v b/ode/Picard.v
index 88f4c308..f5511eae 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -188,7 +188,7 @@ Global Existing Instance luc_prf.
Global Instance sum_luc `{MetricSpaceBall X}
(f g : X -> CR) `{!IsUniformlyContinuous f mu_f} `{!IsUniformlyContinuous g mu_g} :
- IsUniformlyContinuous (f +1 g) (λ e, meet (mu_f (e * (1 # 2))) (mu_g (e * (1 # 2)))).
+ IsUniformlyContinuous (f + g) (λ e, meet (mu_f (e * (1 # 2))) (mu_g (e * (1 # 2)))).
Proof.
Admitted.
@@ -281,7 +281,7 @@ assert (C : IsUniformlyContinuous h (uc_mu g)) by admit.
exact (Build_UniformlyContinuous _ _ C).
Defined.
-Lemma picard_contraction : IsContraction picard (L * rx).
+(*Lemma picard_contraction : IsContraction picard (L * rx).
Proof.
constructor; [| exact L_rx].
constructor; [solve_propholds |].
@@ -292,7 +292,7 @@ unfold picard'. apply mspc_ball_CRplus_l, mspc_ball_CRabs.
SearchAbout (gball _ (?x + _)%CR (?y + _)%CR).
apply mspc_ball_plus_l.
-SearchAbout "ball" "plus".
+SearchAbout "ball" "plus".*)
@@ -425,4 +425,4 @@ Time Eval vm_compute in (eval 3 (picard 1 1)).
Time Eval vm_compute in (eval 2 (picard 2 1)).
End example.
-*)
\ No newline at end of file
+*)
From bc16c560a05886399c289286c9e7b3dd09b3a664 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Sat, 16 Feb 2013 17:37:30 +0100
Subject: [PATCH 075/110] Added the ode/ directory to SConstruct to be compiled
---
SConstruct | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SConstruct b/SConstruct
index 76b5c1de..fe9cf2e9 100644
--- a/SConstruct
+++ b/SConstruct
@@ -1,7 +1,7 @@
import os, glob, string
# Removing examples directory since we do not need it every time.
-dirs_to_compile = ['algebra', 'complex', 'coq_reals', 'fta', 'ftc', 'logic', 'metrics', 'model', 'raster', 'reals', 'tactics', 'transc', 'order', 'metric2', 'Liouville', 'stdlib_omissions', 'util', 'classes']
+dirs_to_compile = ['algebra', 'complex', 'coq_reals', 'fta', 'ftc', 'logic', 'metrics', 'model', 'raster', 'reals', 'tactics', 'transc', 'order', 'metric2', 'Liouville', 'stdlib_omissions', 'util', 'classes', 'ode']
nodes = map(lambda x: './' + x, dirs_to_compile)
dirs = []
From 75c5e4bb20f4ae9383f9c456a73465ea8253d63f Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Sat, 16 Feb 2013 17:51:06 +0100
Subject: [PATCH 076/110] Updated README: Coq 8.4pl1 instead of beta
EvgenyMakarov in URL instead of c-corn
---
README | 22 ++--------------------
1 file changed, 2 insertions(+), 20 deletions(-)
diff --git a/README b/README
index dc1ea956..83b6db2a 100644
--- a/README
+++ b/README
@@ -6,18 +6,10 @@ PREREQUISITES
This version of C-CoRN is known to compile with:
- - Coq 8.4 beta
-
- One might also perform the following optimizations:
- * Change size = 6 to size = 12 in theories/Numbers/Natural/BigN/NMake_gen.ml
- to increase performance for big numbers.
+ - Coq 8.4pl1
- SCons 1.2
- - In order to build the dependency graph you need a Haskell compiler and the
- Graphviz library for Haskell. The latter can be obtained using the Cabal
- package manager.
-
GIT CHECKOUT & SUBMODULES
-------------------------
@@ -27,7 +19,7 @@ Math Classes is contained in the C-CoRN git repository as a submodule. You can
obtain math-classes automatically by giving the --recursive option when you
clone the git repository:
- git clone --recursive https://github.com/c-corn/corn.git
+ git clone --recursive https://github.com/EvgenyMakarov/corn.git
If you have already cloned the CoRN repository without --recursive, you can
still get the submodules with
@@ -59,13 +51,3 @@ BUILDING DOCUMENTATION
----------------------
To build CoqDoc documentation, say "scons coqdoc".
-
-A dependency graph in DOT format can be created with "scons deps.dot".
-
-PLOTS
------
-
-If you want high resolution plots in examples/Circle.v, follow the instructions
-in dump/INSTALL
-
-
From 5f01698bde590092bf91bb7372ba158f1d1daed1 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Mon, 18 Feb 2013 00:46:16 +0100
Subject: [PATCH 077/110] Proved that Picard operator is a contraction
---
ode/AbstractIntegration.v | 12 +++++++--
ode/Picard.v | 55 ++++++++++++++++++++++++++++++---------
ode/SimpleIntegration.v | 13 ++++++++-
ode/metric.v | 13 ++++++---
4 files changed, 74 insertions(+), 19 deletions(-)
diff --git a/ode/AbstractIntegration.v b/ode/AbstractIntegration.v
index 6b9be682..47dc33a9 100644
--- a/ode/AbstractIntegration.v
+++ b/ode/AbstractIntegration.v
@@ -33,6 +33,12 @@ should find metric2.Prelength.fast_MonadLaw3 *)
(** Any nonnegative width can be split up into an integral number of
equal-sized pieces no bigger than a given bound: *)
+Add Field Qfield : Qsft
+ (decidable Qeq_bool_eq,
+ completeness Qeq_eq_bool,
+ constants [Qcst],
+ power_tac Qpower_theory [Qpow_tac]).
+
Definition split (w: QnonNeg) (bound: QposInf):
{ x: nat * QnonNeg | (fst x * snd x == w)%Qnn /\ (snd x <= bound)%QnnInf }.
Proof with simpl; auto with *.
@@ -702,6 +708,7 @@ Qed.*)
End IntegralBound.
+(*
Section IntegralOfSum.
Context (f g : Q -> CR)
@@ -768,6 +775,7 @@ constructor.
Qed.
End IntegralOfSum.
+*)
Add Field Q : (dec_fields.stdlib_field_theory Q).
@@ -917,14 +925,14 @@ Qed.
End IntegralTotal.
-Lemma int_plus (f g : Q -> CR) `{Integrable f, Integrable g}
+(*Lemma int_plus (f g : Q -> CR) `{Integrable f, Integrable g}
`{!IsLocallyUniformlyContinuous f f_mu, !IsLocallyUniformlyContinuous f f_mu} (a b : Q) :
int f a b + int g a b = int (f + g) a b.
Proof.
unfold int. destruct (decide (a ≤ b)); [reflexivity |].
symmetry; unfold integrate at 1, integrate_sum.
apply rings.negate_plus_distr. (* does not work without unfold *)
-Qed.
+Qed.*)
Import interfaces.orders orders.semirings.
diff --git a/ode/Picard.v b/ode/Picard.v
index f5511eae..65439838 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -13,7 +13,7 @@ Import
Qabs propholds.
Require Import metric FromMetric2 AbstractIntegration SimpleIntegration.
-Require Import canonical_names decision setoid_tactics.
+Require Import canonical_names decision setoid_tactics util.
Close Scope uc_scope. (* There is a leak in some module *)
Open Scope signature_scope. (* To interpret "==>" *)
@@ -22,9 +22,16 @@ Bind Scope mc_scope with Q.
Local Notation ball := mspc_ball.
+(*Hint Extern 10 (ExtMetricSpaceClass (UniformlyContinuous _ _)) =>
+ apply @Linf_func_metric_space_class : typeclass_instances.*)
+
Instance Q_nonneg (rx : QnonNeg) : PropHolds (@le Q _ 0 rx).
Proof. apply (proj2_sig rx). Qed.
+Program Instance sig_nonempty `{ExtMetricSpaceClass X}
+ (r : QnonNeg) (x : X) : NonEmpty (sig (ball r x)) := inhabits x.
+Next Obligation. apply mspc_refl; solve_propholds. Qed.
+
(* The following instances are needed to show that Lipschitz functions are
uniformly continuous: metric.lip_uc *)
Global Instance Qmsd : MetricSpaceDistance Q := λ x y, abs (x - y).
@@ -32,6 +39,7 @@ Global Instance Qmsd : MetricSpaceDistance Q := λ x y, abs (x - y).
Global Instance Qmsc : MetricSpaceClass Q.
Proof. intros x1 x2; apply gball_Qabs; reflexivity. Qed.
+(*Instance Q_nonempty : NonEmpty Q := inhabits 0%Q.*)
(* Should be generalized from Q and CR *)
Lemma mspc_ball_Qplus_l (e x y y' : Q) : ball e y y' -> ball e (x + y) (x + y').
@@ -192,6 +200,25 @@ Global Instance sum_luc `{MetricSpaceBall X}
Proof.
Admitted.
+Global Instance negate_luc `{MetricSpaceBall X} (f : X -> CR)
+ `{!IsUniformlyContinuous f mu_f} : IsUniformlyContinuous (- f) mu_f.
+Proof.
+Admitted.
+
+Lemma int_plus (f g : Q -> CR)
+ `{!IsUniformlyContinuous f f_mu, !IsUniformlyContinuous g g_mu} (a b : Q) :
+ int (f + g) a b = int f a b + int g a b.
+Admitted.
+
+Lemma int_negate (f : Q -> CR) `{!IsUniformlyContinuous f f_mu} (a b : Q) :
+ int (- f) a b = - int f a b.
+Admitted.
+
+Lemma int_minus (f g : Q -> CR)
+ `{!IsUniformlyContinuous f f_mu, !IsUniformlyContinuous g g_mu} (a b : Q) :
+ int (f - g) a b = int f a b - int g a b.
+Proof. rewrite int_plus, int_negate; reflexivity. Qed.
+
Section Picard.
Context (x0 : Q) (y0 : CR) (rx ry : QnonNeg).
@@ -281,23 +308,27 @@ assert (C : IsUniformlyContinuous h (uc_mu g)) by admit.
exact (Build_UniformlyContinuous _ _ C).
Defined.
-(*Lemma picard_contraction : IsContraction picard (L * rx).
+Lemma picard_contraction : IsContraction picard (L * rx).
Proof.
constructor; [| exact L_rx].
constructor; [solve_propholds |].
intros f1 f2 e A [x ?].
change (ball (L * rx * e) (picard' f1 x) (picard' f2 x)).
unfold picard'. apply mspc_ball_CRplus_l, mspc_ball_CRabs.
-
-
-SearchAbout (gball _ (?x + _)%CR (?y + _)%CR).
-apply mspc_ball_plus_l.
-SearchAbout "ball" "plus".*)
-
-
-
-
-
+rewrite <- int_minus. transitivity ('(abs (x - x0) * (L * e))).
++ apply int_abs_bound; [apply _ |]. (* remove [apply _] *)
+ intros x' B. assert (B1 : ball rx x0 x') by
+ (apply (mspc_ball_convex x0 x); [apply mspc_refl | |]; solve_propholds).
+ unfold plus, negate, ext_plus, ext_negate.
+ rewrite !(extend_inside x0 rx _ x' B1).
+ apply mspc_ball_CRabs. unfold diag, together, Datatypes.id, Basics.compose; simpl.
+ apply (lip_prf (λ y, v (_, y)) L), A.
++ apply CRle_Qle. mc_setoid_replace (L * rx * e) with ((to_Q rx) * (L * e)) by ring.
+ assert (0 ≤ e) by apply (radius_nonneg f1 f2 e A).
+ change ((abs (x - x0) * (L * e)) ≤ ((to_Q rx) * (L * e))).
+ apply (orders.order_preserving (.* (L * e))).
+ now apply mspc_ball_Qabs_flip.
+Qed.
End Picard.
diff --git a/ode/SimpleIntegration.v b/ode/SimpleIntegration.v
index a48e8a94..aa5203eb 100644
--- a/ode/SimpleIntegration.v
+++ b/ode/SimpleIntegration.v
@@ -22,7 +22,6 @@ Require Import
implementations.stdlib_rationals.
Bind Scope Q_scope with Q.
-
Open Scope Q_scope.
Lemma gball_mspc_ball {X : MetricSpace} (r : Q) (x y : X) :
@@ -62,6 +61,12 @@ Proof. destruct e as [e |]; [apply ball_sym | trivial]. Qed.
Section definition.
+ Add Field Qfield : Qsft
+ (decidable Qeq_bool_eq,
+ completeness Qeq_eq_bool,
+ constants [Qcst],
+ power_tac Qpower_theory [Qpow_tac]).
+
Context (f: Q -> CR) `{UC : !IsLocallyUniformlyContinuous f lmu}.
(** Note that in what follows we don't specialize for [0,1] or [0,w] ranges first. While this
@@ -285,6 +290,12 @@ Arguments intervals lmu from w error : clear implicits.
Section implements_abstract_interface.
+ Add Field Qfield' : Qsft
+ (decidable Qeq_bool_eq,
+ completeness Qeq_eq_bool,
+ constants [Qcst],
+ power_tac Qpower_theory [Qpow_tac]).
+
Context (f: Q → CR) `{!IsLocallyUniformlyContinuous f lmu}.
Section additivity.
diff --git a/ode/metric.v b/ode/metric.v
index 045c0b7e..1ed4c3f0 100644
--- a/ode/metric.v
+++ b/ode/metric.v
@@ -117,7 +117,7 @@ Tactic Notation "Qsimpl" hyp_list(A) := revert A; Qsimpl'; intros A.
Bind Scope mc_scope with Q.
-Section QField.
+(*Section QField.*)
Add Field Q : (stdlib_field_theory Q).
@@ -328,7 +328,7 @@ intros q1 q2 A1 f1 f2 A2 g1 g2 A3; rewrite A2, A3.
split; intros A4 x; [rewrite <- A1 | rewrite A1]; apply A4.
Qed.
-Global Instance Linf_func_metric_space_class : ExtMetricSpaceClass T.
+Lemma Linf_func_metric_space_class : ExtMetricSpaceClass T.
Proof.
match goal with | H : NonEmpty X |- _ => destruct H as [x0] end.
constructor.
@@ -400,6 +400,9 @@ Qed.
Global Instance uniformly_continuous_func `{MetricSpaceBall X, MetricSpaceBall Y} :
Func (UniformlyContinuous X Y) X Y := λ f, f.
+Hint Extern 10 (ExtMetricSpaceClass (UniformlyContinuous _ _)) =>
+ apply @Linf_func_metric_space_class : typeclass_instances.
+
Section LocalUniformContinuity.
Context `{MetricSpaceBall X, MetricSpaceBall Y}.
@@ -562,6 +565,9 @@ Global Arguments LocallyLipschitz X {_} Y {_}.
Instance locally_lipschitz_func `{MetricSpaceBall X, MetricSpaceBall Y} :
Func (LocallyLipschitz X Y) X Y := λ f, f.
+Hint Extern 10 (ExtMetricSpaceClass (LocallyLipschitz _ _)) =>
+ apply @Linf_func_metric_space_class : typeclass_instances.
+
Notation "X LL-> Y" := (LocallyLipschitz X Y) (at level 55, right associativity).
Section Contractions.
@@ -976,5 +982,4 @@ Qed.
End CompleteSpaceSequenceLimits.
-End QField.
-
+(*End QField.*)
From f3953a8c18585291300957009db9fe58a22b3bb4 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 19 Feb 2013 00:17:39 +0100
Subject: [PATCH 078/110] Proved that Picard operator has a fixpoint
---
ode/BanachFixpoint.v | 4 ++--
ode/Picard.v | 32 ++++++++++++++++++++++++++------
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/ode/BanachFixpoint.v b/ode/BanachFixpoint.v
index 17807a1c..edbd6634 100644
--- a/ode/BanachFixpoint.v
+++ b/ode/BanachFixpoint.v
@@ -203,9 +203,9 @@ end.
- intros; apply mspc_symm; now apply A.
Qed.
-Let a := lim (reg_fun x _ cauchy_x).
+Definition fp := lim (reg_fun x _ cauchy_x).
-Lemma banach_fixpoint : f a = a.
+Lemma banach_fixpoint : f fp = fp.
Proof.
assert (C := cauchy_x).
(* [Check seq_lim_lim (A := C)] says "Wrong argument name: A", but [About seq_lim_lim] shows A *)
diff --git a/ode/Picard.v b/ode/Picard.v
index 65439838..d335e6da 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -12,7 +12,7 @@ Import
QnonNeg Qinf.notations QnonNeg.notations QnnInf.notations CRball.notations
Qabs propholds.
-Require Import metric FromMetric2 AbstractIntegration SimpleIntegration.
+Require Import metric FromMetric2 AbstractIntegration SimpleIntegration BanachFixpoint.
Require Import canonical_names decision setoid_tactics util.
Close Scope uc_scope. (* There is a leak in some module *)
@@ -22,9 +22,6 @@ Bind Scope mc_scope with Q.
Local Notation ball := mspc_ball.
-(*Hint Extern 10 (ExtMetricSpaceClass (UniformlyContinuous _ _)) =>
- apply @Linf_func_metric_space_class : typeclass_instances.*)
-
Instance Q_nonneg (rx : QnonNeg) : PropHolds (@le Q _ 0 rx).
Proof. apply (proj2_sig rx). Qed.
@@ -240,6 +237,13 @@ assert (B : ball rx x0 x0) by (apply mspc_refl; solve_propholds).
apply (lip_nonneg (λ y, v ((x0 ↾ B), y)) L).
Qed.
+Instance uc_msd : MetricSpaceDistance (UniformlyContinuous sx sy) := λ f1 f2, 2 * ry.
+
+Instance uc_msc : MetricSpaceClass (UniformlyContinuous sx sy).
+Proof.
+intros f1 f2. admit.
+Qed.
+
(*Check _ : MetricSpaceClass sx.
Check _ : IsUniformlyContinuous v _.
@@ -308,7 +312,7 @@ assert (C : IsUniformlyContinuous h (uc_mu g)) by admit.
exact (Build_UniformlyContinuous _ _ C).
Defined.
-Lemma picard_contraction : IsContraction picard (L * rx).
+Instance picard_contraction : IsContraction picard (L * rx).
Proof.
constructor; [| exact L_rx].
constructor; [solve_propholds |].
@@ -330,9 +334,25 @@ rewrite <- int_minus. transitivity ('(abs (x - x0) * (L * e))).
now apply mspc_ball_Qabs_flip.
Qed.
+Program Definition f0 : UniformlyContinuous sx sy :=
+ Build_UniformlyContinuous (λ x, y0) (λ e, Qinf.infinite) _.
+Next Obligation. apply mspc_refl; solve_propholds. Qed.
+
+Next Obligation.
+constructor.
++ intros; easy.
++ intros e x1 x2 e_pos B. change (ball e y0 y0). apply mspc_refl; solve_propholds.
+Qed.
+
+(*Let emsc := _ : ExtMetricSpaceClass (UniformlyContinuous sx sy).
+Check _ : MetricSpaceClass (UniformlyContinuous sx sy).*)
+
+Lemma ode_solution : let f := fp picard f0 in picard f = f.
+Proof. apply banach_fixpoint. Qed.
+
End Picard.
-Require Import BanachFixpoint.
+
From 216d75f6f68d89f777ce17ddce3aaab522acf16c Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 22 Feb 2013 20:11:02 +0100
Subject: [PATCH 079/110] Proved some lemmas
---
ode/BanachFixpoint.v | 2 +-
ode/Picard.v | 110 +++++++++++++++++++++++++++++++------------
ode/metric.v | 7 +++
3 files changed, 89 insertions(+), 30 deletions(-)
diff --git a/ode/BanachFixpoint.v b/ode/BanachFixpoint.v
index edbd6634..0603126e 100644
--- a/ode/BanachFixpoint.v
+++ b/ode/BanachFixpoint.v
@@ -48,7 +48,7 @@ rewrite <- flip_lt_negate in A. apply (strictly_order_preserving (1 +)) in A.
now rewrite plus_negate_r in A.
Qed.
-Instance : forall q : Q, PropHolds (0 < q) -> PropHolds (q ≠ 0).
+Global Instance : forall q : Q, PropHolds (0 < q) -> PropHolds (q ≠ 0).
Proof. apply lt_ne_flip. Qed.
Lemma dist_xn_xSn : forall n : nat, ball (d * q^n) (x n) (x (1 + n)).
diff --git a/ode/Picard.v b/ode/Picard.v
index d335e6da..7b839bb5 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -22,13 +22,29 @@ Bind Scope mc_scope with Q.
Local Notation ball := mspc_ball.
+Lemma Qinf_lt_le (x y : Qinf) : x < y → x ≤ y.
+Proof.
+destruct x as [x |]; destruct y as [y |]; [| easy..].
+change (x < y -> x ≤ y). intros; solve_propholds.
+Qed.
+
Instance Q_nonneg (rx : QnonNeg) : PropHolds (@le Q _ 0 rx).
Proof. apply (proj2_sig rx). Qed.
+Instance Q_nonempty : NonEmpty Q := inhabits 0.
+
Program Instance sig_nonempty `{ExtMetricSpaceClass X}
(r : QnonNeg) (x : X) : NonEmpty (sig (ball r x)) := inhabits x.
Next Obligation. apply mspc_refl; solve_propholds. Qed.
+Instance prod_nonempty `{NonEmpty X, NonEmpty Y} : NonEmpty (X * Y).
+Proof.
+(* In order not to refer to the name of the variable that has type NonEmpty X *)
+match goal with H : NonEmpty X |- _ => destruct H as [x] end.
+match goal with H : NonEmpty Y |- _ => destruct H as [y] end.
+exact (inhabits (x, y)).
+Qed.
+
(* The following instances are needed to show that Lipschitz functions are
uniformly continuous: metric.lip_uc *)
Global Instance Qmsd : MetricSpaceDistance Q := λ x y, abs (x - y).
@@ -70,10 +86,11 @@ Proof.
rewrite <- abs.abs_negate, <- rings.negate_swap_r. apply gball_Qabs.
Qed.*)
-Lemma nested_balls {x1 x2 y1 y2 e : Q} :
+Lemma nested_balls (x1 x2 : Q) {y1 y2 : Q} {e : Qinf} :
ball e x1 x2 -> x1 ≤ y1 -> y1 ≤ y2 -> y2 ≤ x2 -> ball e y1 y2.
Proof.
-intros B A1 A2 A3. apply mspc_ball_Qabs_flip in B. apply mspc_ball_Qabs_flip.
+intros B A1 A2 A3. destruct e as [e |]; [| apply mspc_inf].
+apply mspc_ball_Qabs_flip in B. apply mspc_ball_Qabs_flip.
assert (x1 ≤ x2) by (transitivity y1; [| transitivity y2]; trivial).
rewrite abs.abs_nonneg by now apply rings.flip_nonneg_minus.
rewrite abs.abs_nonneg in B by now apply rings.flip_nonneg_minus.
@@ -111,7 +128,7 @@ Context (f : sig (ball r a) -> Y).
(* Since the following is a Program Definition, we could write [f (a - r)]
and prove the obligation [mspc_ball r a (a - r)]. However, this obligation
would depend on x and [H1 : x ≤ a - r] even though they are not used in the
-proof. So, if [x1 ≤ a - r] and [x2 ≤ a - r], then [extend x1] would reduce
+proof. So, if [H1 : x1 ≤ a - r] and [H2 : x2 ≤ a - r], then [extend x1] would reduce
to [f ((a - r) ↾ extend_obligation_1 x1 H1)] and [extend x2] would reduce
to [f ((a - r) ↾ extend_obligation_1 x2 H2)]. To apply mspc_refl, we would
need to prove that these applications of f are equal, i.e., f is a morphism
@@ -159,10 +176,33 @@ Qed.
*)
Global Instance extend_uc `{!IsUniformlyContinuous f mu_f} : IsUniformlyContinuous extend mu_f.
-Admitted.
+Proof with (assumption || (apply orders.le_flip; assumption) || reflexivity).
+constructor; [apply (uc_pos f mu_f) |].
+intros e x1 x2 e_pos A.
+assert (a - to_Q r ≤ a + to_Q r) by
+ (destruct r; simpl; transitivity a;
+ [apply rings.nonneg_minus_compat | apply semirings.plus_le_compat_r]; (easy || reflexivity)).
+unfold extend.
+destruct (decide (x1 ≤ a - to_Q r)); destruct (decide (x2 ≤ a - to_Q r)).
+* apply mspc_refl; solve_propholds.
+* destruct (decide (a + to_Q r ≤ x2)); apply (uc_prf f mu_f); trivial.
+ + apply (nested_balls _ _ A)...
+ + apply (nested_balls _ _ A)...
+* destruct (decide (a + to_Q r ≤ x1)); apply (uc_prf f mu_f); trivial.
+ + apply mspc_symm; apply mspc_symm in A. apply (nested_balls _ _ A)...
+ + apply mspc_symm; apply mspc_symm in A. apply (nested_balls _ _ A)...
+* destruct (decide (a + to_Q r ≤ x1)); destruct (decide (a + to_Q r ≤ x2));
+ apply (uc_prf f mu_f); trivial.
+ + apply mspc_refl'. now apply Qinf_lt_le, (uc_pos f mu_f).
+ + apply mspc_symm; apply mspc_symm in A. apply (nested_balls _ _ A)...
+ + apply (nested_balls _ _ A)...
+Qed.
Lemma extend_inside (x : Q) (A : ball r a x) : extend x = f (x ↾ A).
+Proof.
Admitted.
+(*apply mspc_ball_Qabs in A.*)
+
End Extend.
@@ -172,32 +212,38 @@ Class Bounded {X : Type} (f : X -> CR) (M : Q) := bounded : forall x, abs (f x)
Global Instance comp_bounded {X Y : Type} (f : X -> Y) (g : Y -> CR)
`{!Bounded g M} : Bounded (g ∘ f) M.
-Proof.
-Admitted.
+Proof. intro x; unfold Basics.compose; apply bounded. Qed.
Global Instance extend_bounded {a : Q} {r : QnonNeg} (f : {x | ball r a x} -> CR)
`{!Bounded f M} : Bounded (extend a r f) M.
-Admitted.
+Proof.
+intro x. unfold extend.
+destruct (decide (x ≤ a - to_Q r)); [| destruct (decide (a + to_Q r ≤ x))]; apply bounded.
+Qed.
-End Bounded.
+Global Instance bounded_nonneg {X : Type} (f : X -> CR) `{!Bounded f M} `{NonEmpty X} :
+ PropHolds (0 ≤ M).
+Proof.
+match goal with H : NonEmpty X |- _ => destruct H as [x] end.
+apply CRle_Qle. change (@zero CR _ ≤ 'M). transitivity (abs (f x)).
++ apply CRabs_nonneg.
++ apply bounded.
+Qed.
-Global Instance bounded_int_uc
- `{!Bounded f M} `{!IsLocallyUniformlyContinuous f mu_f} (x0 : Q) :
- IsUniformlyContinuous (λ x, int f x0 x) (λ e, e / M).
-Admitted.
+End Bounded.
Global Instance : Proper (equiv ==> equiv) (abs (A := CR)).
Proof. change abs with (@ucFun CR CR CRabs); apply _. Qed.
Global Existing Instance luc_prf.
-Global Instance sum_luc `{MetricSpaceBall X}
+Global Instance sum_uc `{MetricSpaceBall X}
(f g : X -> CR) `{!IsUniformlyContinuous f mu_f} `{!IsUniformlyContinuous g mu_g} :
IsUniformlyContinuous (f + g) (λ e, meet (mu_f (e * (1 # 2))) (mu_g (e * (1 # 2)))).
Proof.
Admitted.
-Global Instance negate_luc `{MetricSpaceBall X} (f : X -> CR)
+Global Instance negate_uc `{MetricSpaceBall X} (f : X -> CR)
`{!IsUniformlyContinuous f mu_f} : IsUniformlyContinuous (- f) mu_f.
Proof.
Admitted.
@@ -216,6 +262,21 @@ Lemma int_minus (f g : Q -> CR)
int (f - g) a b = int f a b - int g a b.
Proof. rewrite int_plus, int_negate; reflexivity. Qed.
+Global Instance bounded_int_uc {f : Q -> CR} {M : Q} `{PropHolds (0 < M)}
+ `{!Bounded f M} `{!IsUniformlyContinuous f mu_f} (x0 : Q) :
+ IsUniformlyContinuous (λ x, int f x0 x) (λ e, e / M).
+Proof.
+constructor.
++ intros. apply orders.pos_mult_compat. apply _.
+apply dec_fields.pos_dec_recip_compat. apply _. (* why does solve_propholds not work? *)
++ intros e x1 x2 e_pos A. apply mspc_ball_CRabs. rewrite int_diff; [| apply _].
+ transitivity ('(abs (x1 - x2) * M)).
+ - apply int_abs_bound; [apply _ |]. intros x _; apply bounded.
+ - apply CRle_Qle. change (abs (x1 - x2) * M ≤ e).
+ apply mspc_ball_Qabs in A. apply (orders.order_preserving (.* M)) in A.
+ now mc_setoid_replace (e / M * M) with e in A by (field; solve_propholds).
+Qed.
+
Section Picard.
Context (x0 : Q) (y0 : CR) (rx ry : QnonNeg).
@@ -284,24 +345,21 @@ Qed.*)
Lemma picard_sy (f : UniformlyContinuous sx sy) (x : sx) : ball ry y0 (picard'' f x).
Proof.
-Admitted.
-(*destruct x as [x x_sx]. change (restrict (picard' f) x0 rx (x ↾ x_sx)) with (picard' f x).
-unfold picard'. apply CRball.gball_CRabs.
-match goal with
-| |- context [int ?g ?x1 ?x2] => change (abs (y0 - (y0 + int g x1 x2)) ≤ '`ry)
-end.
+destruct x as [x x_sx]. unfold picard''; simpl.
+unfold restrict, Basics.compose; simpl.
+unfold picard'. apply mspc_ball_CRabs.
rewrite rings.negate_plus_distr, plus_assoc, rings.plus_negate_r, rings.plus_0_l, CRabs_negate.
transitivity ('(abs (x - x0) * M)).
-+ apply int_abs_bound. apply _. (* Should not be required *)
++ apply int_abs_bound; [apply _ |]. (* Should not be required *)
intros t A.
assert (A1 : mspc_ball rx x0 t) by
(apply (mspc_ball_convex x0 x); [apply mspc_refl, (proj2_sig rx) | |]; trivial).
(* [(extend_inside (A:= A1))]: "Wrong argument name: A" *)
- rewrite (extend_inside _ _ _ _ A1). apply v_bounded.
+ rewrite (extend_inside _ _ _ _ A1). apply bounded.
+ apply CRle_Qle. change (abs (x - x0) * M ≤ ry). transitivity (`rx * M).
- now apply (orders.order_preserving (.* M)), mspc_ball_Qabs_flip.
- apply rx_ry.
-Qed.*)
+Qed.
(*Require Import Integration.*)
@@ -352,12 +410,6 @@ Proof. apply banach_fixpoint. Qed.
End Picard.
-
-
-
-
-
-
Section Computation.
Definition x0 : Q := 0.
diff --git a/ode/metric.v b/ode/metric.v
index 1ed4c3f0..f8368629 100644
--- a/ode/metric.v
+++ b/ode/metric.v
@@ -177,6 +177,13 @@ try (unfold Qinf.eq, equiv in *; contradiction).
now apply mspc_triangle with (b := y2); [rewrite Ee1e2 | apply mspc_symm].
Qed.
+Lemma mspc_refl' (e : Qinf) : 0 ≤ e → Reflexive (ball e).
+Proof.
+intros E. destruct e as [e |].
++ apply mspc_refl, E.
++ intro x; apply mspc_inf.
+Qed.
+
Lemma mspc_triangle' :
∀ (q1 q2 : Q) (x2 x1 x3 : X) (q : Q),
q1 + q2 = q → ball q1 x1 x2 → ball q2 x2 x3 → ball q x1 x3.
From 0769db979427cfc9dcdb9053a148ce6d17061daa Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 26 Feb 2013 22:11:21 +0100
Subject: [PATCH 080/110] .
---
ode/Picard.v | 12 +++++++-----
ode/metric.v | 17 ++++++++++-------
2 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/ode/Picard.v b/ode/Picard.v
index 7b839bb5..5082efbe 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -262,18 +262,20 @@ Lemma int_minus (f g : Q -> CR)
int (f - g) a b = int f a b - int g a b.
Proof. rewrite int_plus, int_negate; reflexivity. Qed.
-Global Instance bounded_int_uc {f : Q -> CR} {M : Q} `{PropHolds (0 < M)}
+Global Instance bounded_int_uc {f : Q -> CR} {M : Q}
`{!Bounded f M} `{!IsUniformlyContinuous f mu_f} (x0 : Q) :
- IsUniformlyContinuous (λ x, int f x0 x) (λ e, e / M).
+ IsUniformlyContinuous (λ x, int f x0 x) (lip_modulus M).
Proof.
constructor.
-+ intros. apply orders.pos_mult_compat. apply _.
-apply dec_fields.pos_dec_recip_compat. apply _. (* why does solve_propholds not work? *)
++ intros. apply lip_modulus_pos; solve_propholds.
+ intros e x1 x2 e_pos A. apply mspc_ball_CRabs. rewrite int_diff; [| apply _].
transitivity ('(abs (x1 - x2) * M)).
- apply int_abs_bound; [apply _ |]. intros x _; apply bounded.
- apply CRle_Qle. change (abs (x1 - x2) * M ≤ e).
- apply mspc_ball_Qabs in A. apply (orders.order_preserving (.* M)) in A.
+ unfold lip_modulus in A. destruct (decide (M = 0)) as [E | E].
+ rewrite E, rings.mult_0_r. now apply orders.lt_le. (* why does [solve_propholds] not work? *)
+ apply mspc_ball_Qabs in A. assert (0 ≤ M) by solve_propholds.
+ apply (orders.order_preserving (.* M)) in A.
now mc_setoid_replace (e / M * M) with e in A by (field; solve_propholds).
Qed.
diff --git a/ode/metric.v b/ode/metric.v
index f8368629..7e006795 100644
--- a/ode/metric.v
+++ b/ode/metric.v
@@ -478,6 +478,15 @@ Record Lipschitz := {
Definition lip_modulus (L e : Q) : Qinf :=
if (decide (L = 0)) then Qinf.infinite else e / L.
+Lemma lip_modulus_pos (L e : Q) : 0 ≤ L -> 0 < e -> 0 < lip_modulus L e.
+Proof.
+intros L_nonneg e_pos. unfold lip_modulus.
+destruct (decide (L = 0)) as [A1 | A1]; [apply I |].
+apply neq_symm in A1.
+change (0 < e / L). (* Changes from Qinf, which is not declared as ordered ring, to Q *)
+assert (0 < L) by now apply QOrder.le_neq_lt. Qauto_pos.
+Qed.
+
(* It is nice to declare only [MetricSpaceBall X] above because this is all
we need to know about X to define [IsLipschitz]. But for the following
theorem we also need [ExtMetricSpaceClass X], [MetricSpaceDistance X] and
@@ -493,13 +502,7 @@ Global Instance lip_uc {_ : MetricSpaceClass X} {_ : ExtMetricSpaceClass Y}
IsUniformlyContinuous f (lip_modulus L).
Proof.
constructor.
-+ intros e A.
- unfold lip_modulus.
- destruct (decide (L = 0)) as [A1 | A1]; [apply I |].
- apply neq_symm in A1.
- change (0 < e / L). (* Changes from Qinf, which is not declared as ordered ring, to Q *)
- assert (0 ≤ L) by apply (lip_nonneg f L).
- assert (0 < L) by now apply QOrder.le_neq_lt. Qauto_pos.
++ intros. apply lip_modulus_pos; [| assumption]. now apply (lip_nonneg f L).
+ unfold lip_modulus. intros e x1 x2 A1 A2. destruct (decide (L = 0)) as [A | A].
- apply mspc_eq; [| easy]. unfold equiv, mspc_equiv. rewrite <- (Qmult_0_l (msd x1 x2)), <- A.
now apply lip_prf; [| apply mspc_distance].
From 686ce0278a67d274d814bc16fcc1ae47b410b90b Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Thu, 21 Mar 2013 01:03:40 +0400
Subject: [PATCH 081/110] Proved that unformly continuous functions are closed
under addition and negation
---
ode/FromMetric2.v | 96 +++++++++++++++++++++++++++++++++++++++++++++--
ode/Picard.v | 70 +++-------------------------------
ode/metric.v | 7 +++-
3 files changed, 103 insertions(+), 70 deletions(-)
diff --git a/ode/FromMetric2.v b/ode/FromMetric2.v
index 50b82732..49a87309 100644
--- a/ode/FromMetric2.v
+++ b/ode/FromMetric2.v
@@ -122,16 +122,75 @@ Qed.
End CompleteSegment.
-Require Import CRArith CRball CRabs.
+Require Import Qsetoid Qmetric CRArith CRball CRabs abs minmax.
Add Ring CR : (stdlib_ring_theory CR).
Close Scope CR_scope.
Unset Printing Coercions.
-(* The following has to be generalized from CR to a metric space where
-[ball r x y] is defined as [abs (x - y) ≤ r], probably a normed vector
-space *)
+Global Instance CRabs_proper : Proper (equiv ==> equiv) (abs (A := CR)).
+Proof. change abs with (@ucFun CR CR CRabs); apply _. Qed.
+
+Section CRQBallProperties.
+
+Local Notation ball := mspc_ball.
+
+(* The following has to be generalized from Q and CR to a metric space
+where [ball r x y] is defined as [abs (x - y) ≤ r], probably a normed
+vector space *)
+
+Lemma mspc_ball_Qabs (r x y : Q) : ball r x y ↔ abs (x - y) ≤ r.
+Proof. apply gball_Qabs. Qed.
+
+Lemma mspc_ball_Qabs_flip (r x y : Q) : ball r x y ↔ abs (y - x) ≤ r.
+Proof.
+rewrite <- abs.abs_negate, <- rings.negate_swap_r. apply gball_Qabs.
+Qed.
+
+Lemma mspc_ball_CRabs (r : Q) (x y : CR) : ball r x y ↔ abs (x - y) ≤ 'r.
+Proof. apply CRball.gball_CRabs. Qed.
+
+(*Lemma mspc_ball_CRabs_flip (r : Q) (x y : CR) : ball r x y ↔ abs (y - x) ≤ 'r.
+Proof.
+rewrite <- abs.abs_negate, <- rings.negate_swap_r. apply gball_Qabs.
+Qed.*)
+
+Lemma mspc_ball_Qplus_l (e x y y' : Q) : ball e y y' -> ball e (x + y) (x + y').
+Proof.
+intro A. assert (A1 := radius_nonneg _ _ _ A).
+destruct (orders.le_equiv_lt _ _ A1) as [e_zero | e_pos].
++ rewrite <- e_zero in A |- *. now rewrite A.
++ apply (gball_pos e_pos _ _) in A. now apply (gball_pos e_pos _ _), Qball_plus_r.
+Qed.
+
+Lemma mspc_ball_CRplus_l (e : Q) (x y y' : CR) : ball e y y' -> ball e (x + y) (x + y').
+Proof.
+intro A. rewrite <- (rings.plus_0_l e). apply CRgball_plus; [| easy].
+(*[ apply mspc_refl] does not work *)
+change (ball 0 x x); now apply mspc_refl.
+Qed.
+
+Lemma mspc_ball_CRnegate (e : Q) (x y : CR) : mspc_ball e x y -> mspc_ball e (-x) (-y).
+Proof.
+intro A. apply mspc_ball_CRabs. mc_setoid_replace (-x - -y) with (y - x) by ring.
+now apply mspc_ball_CRabs, mspc_symm.
+Qed.
+
+Lemma nested_balls (x1 x2 : Q) {y1 y2 : Q} {e : Qinf} :
+ ball e x1 x2 -> x1 ≤ y1 -> y1 ≤ y2 -> y2 ≤ x2 -> ball e y1 y2.
+Proof.
+intros B A1 A2 A3. destruct e as [e |]; [| apply mspc_inf].
+apply mspc_ball_Qabs_flip in B. apply mspc_ball_Qabs_flip.
+assert (x1 ≤ x2) by (transitivity y1; [| transitivity y2]; trivial).
+rewrite abs.abs_nonneg by now apply rings.flip_nonneg_minus.
+rewrite abs.abs_nonneg in B by now apply rings.flip_nonneg_minus.
+apply rings.flip_le_minus_l. apply rings.flip_le_minus_l in B.
+transitivity x2; [easy |]. transitivity (e + x1); [easy |].
+apply (orders.order_preserving (e +)); easy.
+Qed. (* Too long? *)
+
+End CRQBallProperties.
(*Section LocallyLipschitz'.
@@ -167,5 +226,34 @@ constructor.
Qed.
*)
+(* Needed to be able to state the property that the integral of the sum is
+the sum of integrals *)
+Global Instance sum_uc `{ExtMetricSpaceClass X}
+ (f g : X -> CR) `{!IsUniformlyContinuous f mu_f} `{!IsUniformlyContinuous g mu_g} :
+ IsUniformlyContinuous (f + g) (λ e, min (mu_f (e / 2)) (mu_g (e / 2))).
+Proof.
+constructor.
+* intros e e_pos. apply lt_min; [apply (uc_pos f mu_f) | apply (uc_pos g mu_g)]; solve_propholds.
+* intros e x1 x2 e_pos A. mc_setoid_replace e with (e / 2 + e / 2) by (field; discriminate).
+ apply CRgball_plus.
+ + apply: (uc_prf f mu_f); [solve_propholds |].
+ apply (mspc_monotone' (min (mu_f (e / 2)) (mu_g (e / 2)))); [| assumption].
+ change ((mu_f (e / 2)) ⊓ (mu_g (e / 2)) ≤ mu_f (e / 2)).
+ apply orders.meet_lb_l. (* does not work without [change] *)
+ + apply: (uc_prf g mu_g); [solve_propholds |].
+ apply (mspc_monotone' (min (mu_f (e / 2)) (mu_g (e / 2)))); [| assumption].
+ change ((mu_f (e / 2)) ⊓ (mu_g (e / 2)) ≤ mu_g (e / 2)).
+ apply orders.meet_lb_r.
+Qed.
+
+
+Global Instance negate_uc `{MetricSpaceBall X} (f : X -> CR)
+ `{!IsUniformlyContinuous f mu_f} : IsUniformlyContinuous (- f) mu_f.
+Proof.
+constructor.
+* apply (uc_pos f _).
+* intros e x1 x2 e_pos A. apply mspc_ball_CRnegate, (uc_prf f mu_f); easy.
+Qed.
+
End QField.
diff --git a/ode/Picard.v b/ode/Picard.v
index 5082efbe..892b41c9 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -54,51 +54,6 @@ Proof. intros x1 x2; apply gball_Qabs; reflexivity. Qed.
(*Instance Q_nonempty : NonEmpty Q := inhabits 0%Q.*)
-(* Should be generalized from Q and CR *)
-Lemma mspc_ball_Qplus_l (e x y y' : Q) : ball e y y' -> ball e (x + y) (x + y').
-Proof.
-intro A. assert (A1 := radius_nonneg _ _ _ A).
-destruct (orders.le_equiv_lt _ _ A1) as [e_zero | e_pos].
-+ rewrite <- e_zero in A |- *. now rewrite A.
-+ apply (gball_pos e_pos _ _) in A. now apply (gball_pos e_pos _ _), Qball_plus_r.
-Qed.
-
-Lemma mspc_ball_CRplus_l (e : Q) (x y y' : CR) : ball e y y' -> ball e (x + y) (x + y').
-Proof.
-intro A. rewrite <- (rings.plus_0_l e). apply CRgball_plus; [| easy].
-(*[ apply mspc_refl] does not work *)
-change (ball 0 x x); now apply mspc_refl.
-Qed.
-
-Lemma mspc_ball_Qabs (r x y : Q) : ball r x y ↔ abs (x - y) ≤ r.
-Proof. apply gball_Qabs. Qed.
-
-Lemma mspc_ball_Qabs_flip (r x y : Q) : ball r x y ↔ abs (y - x) ≤ r.
-Proof.
-rewrite <- abs.abs_negate, <- rings.negate_swap_r. apply gball_Qabs.
-Qed.
-
-Lemma mspc_ball_CRabs (r : Q) (x y : CR) : ball r x y ↔ abs (x - y) ≤ 'r.
-Proof. apply CRball.gball_CRabs. Qed.
-
-(*Lemma mspc_ball_CRabs_flip (r : Q) (x y : CR) : ball r x y ↔ abs (y - x) ≤ 'r.
-Proof.
-rewrite <- abs.abs_negate, <- rings.negate_swap_r. apply gball_Qabs.
-Qed.*)
-
-Lemma nested_balls (x1 x2 : Q) {y1 y2 : Q} {e : Qinf} :
- ball e x1 x2 -> x1 ≤ y1 -> y1 ≤ y2 -> y2 ≤ x2 -> ball e y1 y2.
-Proof.
-intros B A1 A2 A3. destruct e as [e |]; [| apply mspc_inf].
-apply mspc_ball_Qabs_flip in B. apply mspc_ball_Qabs_flip.
-assert (x1 ≤ x2) by (transitivity y1; [| transitivity y2]; trivial).
-rewrite abs.abs_nonneg by now apply rings.flip_nonneg_minus.
-rewrite abs.abs_nonneg in B by now apply rings.flip_nonneg_minus.
-apply rings.flip_le_minus_l. apply rings.flip_le_minus_l in B.
-transitivity x2; [easy |]. transitivity (e + x1); [easy |].
-apply (orders.order_preserving (e +)); easy.
-Qed. (* Too long? *)
-
Section Extend.
Context `{ExtMetricSpaceClass Y} (a : Q) (r : QnonNeg).
@@ -221,8 +176,8 @@ intro x. unfold extend.
destruct (decide (x ≤ a - to_Q r)); [| destruct (decide (a + to_Q r ≤ x))]; apply bounded.
Qed.
-Global Instance bounded_nonneg {X : Type} (f : X -> CR) `{!Bounded f M} `{NonEmpty X} :
- PropHolds (0 ≤ M).
+Lemma bounded_nonneg {X : Type} (f : X -> CR) `{!Bounded f M} `{NonEmpty X} :
+ (*PropHolds*) (0 ≤ M).
Proof.
match goal with H : NonEmpty X |- _ => destruct H as [x] end.
apply CRle_Qle. change (@zero CR _ ≤ 'M). transitivity (abs (f x)).
@@ -232,22 +187,8 @@ Qed.
End Bounded.
-Global Instance : Proper (equiv ==> equiv) (abs (A := CR)).
-Proof. change abs with (@ucFun CR CR CRabs); apply _. Qed.
-
Global Existing Instance luc_prf.
-Global Instance sum_uc `{MetricSpaceBall X}
- (f g : X -> CR) `{!IsUniformlyContinuous f mu_f} `{!IsUniformlyContinuous g mu_g} :
- IsUniformlyContinuous (f + g) (λ e, meet (mu_f (e * (1 # 2))) (mu_g (e * (1 # 2)))).
-Proof.
-Admitted.
-
-Global Instance negate_uc `{MetricSpaceBall X} (f : X -> CR)
- `{!IsUniformlyContinuous f mu_f} : IsUniformlyContinuous (- f) mu_f.
-Proof.
-Admitted.
-
Lemma int_plus (f g : Q -> CR)
`{!IsUniformlyContinuous f f_mu, !IsUniformlyContinuous g g_mu} (a b : Q) :
int (f + g) a b = int f a b + int g a b.
@@ -267,14 +208,14 @@ Global Instance bounded_int_uc {f : Q -> CR} {M : Q}
IsUniformlyContinuous (λ x, int f x0 x) (lip_modulus M).
Proof.
constructor.
-+ intros. apply lip_modulus_pos; solve_propholds.
++ intros. apply lip_modulus_pos; [apply (bounded_nonneg f) | easy].
+ intros e x1 x2 e_pos A. apply mspc_ball_CRabs. rewrite int_diff; [| apply _].
transitivity ('(abs (x1 - x2) * M)).
- apply int_abs_bound; [apply _ |]. intros x _; apply bounded.
- apply CRle_Qle. change (abs (x1 - x2) * M ≤ e).
unfold lip_modulus in A. destruct (decide (M = 0)) as [E | E].
rewrite E, rings.mult_0_r. now apply orders.lt_le. (* why does [solve_propholds] not work? *)
- apply mspc_ball_Qabs in A. assert (0 ≤ M) by solve_propholds.
+ apply mspc_ball_Qabs in A. assert (0 ≤ M) by apply (bounded_nonneg f).
apply (orders.order_preserving (.* M)) in A.
now mc_setoid_replace (e / M * M) with e in A by (field; solve_propholds).
Qed.
@@ -434,7 +375,8 @@ Admitted.
Program Definition f0 : UniformlyContinuous sx sy :=
Build_UniformlyContinuous (λ x, y0) _ _.
-Next Obligation. apply mspc_refl; Qauto_nonneg. Qed.
+(* [Admit Obligations] causes uncaught exception *)
+Next Obligation. (*apply mspc_refl; Qauto_nonneg. Qed.*)
Next Obligation. exact Qinf.infinite. Defined.
Next Obligation. admit. Qed.
diff --git a/ode/metric.v b/ode/metric.v
index 7e006795..36766cf5 100644
--- a/ode/metric.v
+++ b/ode/metric.v
@@ -653,9 +653,12 @@ Section TotalOrderLattice.
Context `{TotalOrder A} `{Lt A} `{∀ x y: A, Decision (x ≤ y)}.
-Lemma min_ind (R : relation A) (x y z : A) : R z x → R z y → R z (min x y).
+Lemma min_ind (P : A -> Prop) (x y : A) : P x → P y → P (min x y).
Proof. unfold min, sort. destruct (decide_rel le x y); auto. Qed.
+Lemma lt_min (x y z : A) : z < x -> z < y -> z < min x y.
+Proof. apply min_ind. Qed.
+
End TotalOrderLattice.
Section ProductSpaceFunctions.
@@ -712,7 +715,7 @@ Proof.
Admitted.
(*
constructor.
-+ intros e e_pos. apply min_ind; [apply (uc_pos f1) | apply (uc_pos f2)]; trivial.
++ intros e e_pos. apply min_ind; [apply (uc_pos f1) | apply (uc_pos f2)]; trivial. (* or use lt_min *)
(* [trivial] solves, in particular, [IsUniformlyContinuous f1 mu1], which should
have been solved automatically *)
+ intros e z z' e_pos [A1 A2]. split; simpl.
From 3799b0ccbceb2392cc43908203061d272f42eb1d Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Tue, 2 Apr 2013 22:53:31 +0400
Subject: [PATCH 082/110] Proved several lemmas
---
ode/AbstractIntegration.v | 37 ++++++++++++++++++++++++++++++++++---
ode/Picard.v | 15 ++++++++-------
ode/metric.v | 29 +++++++++++------------------
3 files changed, 53 insertions(+), 28 deletions(-)
diff --git a/ode/AbstractIntegration.v b/ode/AbstractIntegration.v
index 47dc33a9..476582f4 100644
--- a/ode/AbstractIntegration.v
+++ b/ode/AbstractIntegration.v
@@ -834,15 +834,37 @@ Proof. now rewrite rings.flip_negate, rings.negate_involutive. Qed.
End RingFacts.
+Import interfaces.orders.
+
+Lemma join_comm `{JoinSemiLatticeOrder L} : Commutative join.
+Proof.
+intros x y. apply antisymmetry with (R := (≤)); [apply _ | |];
+(apply join_lub; [apply join_ub_r | apply join_ub_l]).
+(* why is [apply _] needed? *)
+Qed.
+
+Lemma meet_comm `{MeetSemiLatticeOrder L} : Commutative meet.
+Proof.
+intros x y. apply antisymmetry with (R := (≤)); [apply _ | |];
+(apply meet_glb; [apply meet_lb_r | apply meet_lb_l]).
+Qed.
+
Definition Range (T : Type) := prod T T.
Instance contains_Q : Contains Q (Range Q) := λ x s, (fst s ⊓ snd s ≤ x ≤ fst s ⊔ snd s).
Lemma Qrange_comm (a b x : Q) : x ∈ (a, b) <-> x ∈ (b, a).
-Admitted.
+Proof.
+unfold contains, contains_Q; simpl.
+rewrite join_comm, meet_comm; reflexivity.
+Qed.
Lemma range_le (a b : Q) : a ≤ b -> forall x, a ≤ x ≤ b <-> x ∈ (a, b).
-Admitted.
+Proof.
+intros A x; unfold contains, contains_Q; simpl.
+mc_setoid_replace (meet a b) with a by now apply lattices.meet_l.
+mc_setoid_replace (join a b) with b by now apply lattices.join_r. reflexivity.
+Qed.
Lemma CRabs_negate (x : CR) : abs (-x) = abs x.
Proof.
@@ -850,9 +872,18 @@ change (abs (-x)) with (CRabs (-x)).
rewrite CRabs_opp; reflexivity.
Qed.
+Lemma mspc_ball_Qle (r a x : Q) : mspc_ball r a x <-> a - r ≤ x ≤ a + r.
+Proof. rewrite mspc_ball_Qabs; apply Qabs_diff_Qle. Qed.
+
Lemma mspc_ball_convex (x1 x2 r a x : Q) :
mspc_ball r a x1 -> mspc_ball r a x2 -> x ∈ (x1, x2) -> mspc_ball r a x.
-Admitted.
+Proof.
+intros A1 A2 A3.
+rewrite mspc_ball_Qle in A1, A2. apply mspc_ball_Qle.
+destruct A1 as [A1' A1'']; destruct A2 as [A2' A2'']; destruct A3 as [A3' A3'']. split.
++ now transitivity (meet x1 x2); [apply meet_glb |].
++ now transitivity (join x1 x2); [| apply join_lub].
+Qed.
Section IntegralTotal.
diff --git a/ode/Picard.v b/ode/Picard.v
index 892b41c9..84a5febb 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -241,11 +241,16 @@ assert (B : ball rx x0 x0) by (apply mspc_refl; solve_propholds).
apply (lip_nonneg (λ y, v ((x0 ↾ B), y)) L).
Qed.
+(* Needed to apply Banach fixpoint theorem, which requires a finite
+distance between any two points *)
Instance uc_msd : MetricSpaceDistance (UniformlyContinuous sx sy) := λ f1 f2, 2 * ry.
Instance uc_msc : MetricSpaceClass (UniformlyContinuous sx sy).
Proof.
-intros f1 f2. admit.
+intros f1 f2. unfold msd, uc_msd. intro x. apply (mspc_triangle' ry ry y0).
++ change (to_Q ry + to_Q ry = 2 * (to_Q ry)). ring.
++ apply mspc_symm; apply (proj2_sig (func f1 x)).
++ apply (proj2_sig (func f2 x)).
Qed.
(*Check _ : MetricSpaceClass sx.
@@ -278,13 +283,9 @@ Definition picard'' (f : UniformlyContinuous sx sy) : UniformlyContinuous sx CR.
apply (Build_UniformlyContinuous (restrict (picard' f) x0 rx) _ _).
Defined.
+(* Needed below to be able to apply (order_preserving (.* M)) *)
Instance M_nonneg : PropHolds (0 ≤ M).
-Proof.
-Admitted.
-(*assert (Ax : mspc_ball rx x0 x0) by apply mspc_refl, (proj2_sig rx).
-assert (Ay : mspc_ball ry y0 y0) by apply mspc_refl, (proj2_sig ry).
-apply CRle_Qle. transitivity (abs (v (x0 ↾ Ax , y0 ↾ Ay))); [apply CRabs_nonneg | apply v_bounded].
-Qed.*)
+Proof. apply (bounded_nonneg v). Qed.
Lemma picard_sy (f : UniformlyContinuous sx sy) (x : sx) : ball ry y0 (picard'' f x).
Proof.
diff --git a/ode/metric.v b/ode/metric.v
index 36766cf5..991a962c 100644
--- a/ode/metric.v
+++ b/ode/metric.v
@@ -293,7 +293,14 @@ Global Instance Linf_product_msd : MetricSpaceDistance (X * Y) :=
λ a b, join (msd (fst a) (fst b)) (msd (snd a) (snd b)).
Global Instance Linf_product_mspc_distance : MetricSpaceClass (X * Y).
-Admitted.
+Proof.
+intros z1 z2; split.
+(* Without unfolding Linf_product_msd, the following [apply join_ub_l] fails *)
++ apply (mspc_monotone (msd (fst z1) (fst z2)));
+ [unfold msd, Linf_product_msd; apply join_ub_l | apply mspc_distance].
++ apply (mspc_monotone (msd (snd z1) (snd z2)));
+ [unfold msd, Linf_product_msd; apply join_ub_r | apply mspc_distance].
+Qed.
End ProductMetricSpace.
@@ -710,12 +717,11 @@ Global Instance together_uc
`{ExtMetricSpaceClass X1, ExtMetricSpaceClass Y1, ExtMetricSpaceClass X2, ExtMetricSpaceClass Y2}
(f1 : X1 -> Y1) (f2 : X2 -> Y2)
`{!IsUniformlyContinuous f1 mu1, !IsUniformlyContinuous f2 mu2} :
- IsUniformlyContinuous (together f1 f2) (λ e, meet (mu1 e) (mu2 e)).
+ IsUniformlyContinuous (together f1 f2) (λ e, min (mu1 e) (mu2 e)).
Proof.
-Admitted.
-(*
constructor.
-+ intros e e_pos. apply min_ind; [apply (uc_pos f1) | apply (uc_pos f2)]; trivial. (* or use lt_min *)
++ intros e e_pos. (* [apply min_ind] does not work if the goal has [meet] instead of [min] *)
+ apply lt_min; [apply (uc_pos f1) | apply (uc_pos f2)]; trivial.
(* [trivial] solves, in particular, [IsUniformlyContinuous f1 mu1], which should
have been solved automatically *)
+ intros e z z' e_pos [A1 A2]. split; simpl.
@@ -724,22 +730,9 @@ constructor.
- apply (uc_prf f2 mu2); trivial.
apply (mspc_monotone' (min (mu1 e) (mu2 e))); [apply: meet_lb_r | trivial].
Qed.
-*)
End ProductSpaceFunctions.
-(*
-Section Test.
-
-Context `{ExtMetricSpaceClass A, ExtMetricSpaceClass B, ExtMetricSpaceClass C}
- (f : A -> B) `{!IsUniformlyContinuous f f_mu}
- (v : A * B -> C) `{!IsUniformlyContinuous v v_mu}.
-
-Check _ : IsUniformlyContinuous (v ∘ (together id f) ∘ diag) _.
-
-End Test.
-*)
-
Section CompleteMetricSpace.
Context `{MetricSpaceBall X}.
From d790bbc819c94d75dca177a5093104d3168fd92c Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Sat, 6 Apr 2013 00:05:30 +0400
Subject: [PATCH 083/110] Proved all lemmas outside of Picard.v
---
ode/AbstractIntegration.v | 47 +++++++++++++++++++--------------------
ode/FromMetric2.v | 9 --------
ode/metric.v | 18 +++++++++++++++
3 files changed, 41 insertions(+), 33 deletions(-)
diff --git a/ode/AbstractIntegration.v b/ode/AbstractIntegration.v
index 476582f4..58d246b7 100644
--- a/ode/AbstractIntegration.v
+++ b/ode/AbstractIntegration.v
@@ -970,16 +970,16 @@ Import interfaces.orders orders.semirings.
Definition Qupper_bound (x : CR) := approximate x 1%Qpos + 1.
-Lemma Qupper_bound_ge (x : CR) : x ≤ 'Qupper_bound x.
-Admitted.
-(* Similar to
-upper_CRapproximation:
- ∀ (x : CR) (e : Qpos), x <= (' (approximate x e + e)%Q)%CR
-CRexp.exp_bound_lemma:
- ∀ x : CR, x <= (' (approximate x (1 # 1)%Qpos + 1)%Q)%CR *)
-
+(* To be proved by lifting from Q.
Lemma CRabs_triang (x y z : CR) : x = y + z -> abs x ≤ abs y + abs z.
Admitted.
+*)
+
+(* The section IntegralLipschitz is not used in the ODE solver through
+Picard iterations. Instead of assuming the function that is being
+integrated to be Lipschitz, the development assumes that it is uniformly
+continuous and bounded. Then integral is Lispchitz, but it is only proved
+that it is uniformly continuous. *)
Section IntegralLipschitz.
@@ -1014,32 +1014,31 @@ Qed.
End IntegralLipschitzBall.
+Lemma lipschitz_bounded (a r M x : Q) :
+ abs (f a) ≤ 'M -> ball r a x -> abs (f x) ≤ '(M + L a r * r).
+Proof.
+intros A1 A2. mc_setoid_replace (f x) with (f x - 0) by ring.
+apply mspc_ball_CRabs, mspc_symm.
+(* [apply mspc_triangle with (c := f a)] does not work *)
+apply (mspc_triangle _ _ _ (f a)).
++ apply mspc_ball_CRabs. mc_setoid_replace (0 - f a) with (- f a) by ring.
+ now rewrite CRabs_negate.
++ apply llip; trivial. now apply mspc_refl, (radius_nonneg a x).
+Qed.
+
Global Instance integral_lipschitz :
IsLocallyLipschitz F (λ a r, Qupper_bound (abs (f a)) + L a r * r).
Proof.
intros a r r_nonneg. constructor.
+ apply nonneg_plus_compat.
- - apply CRle_Qle. transitivity (abs (f a)); [apply CRabs_nonneg | apply Qupper_bound_ge].
+ - apply CRle_Qle. transitivity (abs (f a)); [apply CRabs_nonneg | apply upper_CRapproximation].
- apply nonneg_mult_compat; [apply (lip_nonneg (restrict f a r)) |]; auto.
(* Not good to provide [(restrict f a r)]. [IsLipschitz (restrict f a r) (L a r)] is generated *)
-+ (* PG ignores the following tactic *) idtac. intros x1 x2 d A.
++ intros x1 x2 d A.
destruct x1 as [x1 A1]; destruct x2 as [x2 A2].
change (ball ((Qupper_bound (abs (f a)) + L a r * r) * d) (F x1) (F x2)).
apply (int_lip a r); trivial.
- intros x B. transitivity (abs (f a) + '(L a r * r)).
- - transitivity (abs (f a) + abs (f x - f a)); [apply CRabs_triang; ring |].
- apply (order_preserving (abs (f a) +)).
- apply CRball.gball_CRabs. apply gball_sym.
- (* There should be a lemma similar to metric.luc for locally Lipschitz:
- the following invocation of lip_prf is too complex *)
- assert (B1 : ball r a a) by now apply mspc_refl.
- change (ball (L a r * r) (restrict f a r (a ↾ B1)) (restrict f a r (x ↾ B))).
- specialize (IsLocallyLipschitz0 a r r_nonneg).
- now apply lip_prf.
- - rewrite <- CRplus_Qplus.
- change (abs (f a) + ' (L a r * r) ≤ ' Qupper_bound (abs (f a)) + ' (L a r * r)).
- apply plus_le_compat; (* does not work wothout [change] *)
- [apply Qupper_bound_ge | reflexivity].
+ intros x B. now apply lipschitz_bounded; [apply upper_CRapproximation |].
Qed.
End IntegralLipschitz.
diff --git a/ode/FromMetric2.v b/ode/FromMetric2.v
index 49a87309..69f2177b 100644
--- a/ode/FromMetric2.v
+++ b/ode/FromMetric2.v
@@ -192,15 +192,6 @@ Qed. (* Too long? *)
End CRQBallProperties.
-(*Section LocallyLipschitz'.
-
-Context `{MetricSpaceBall X, MetricSpaceBall Y}.
-
-Class IsLocallyLipschitz' (f : X -> Y) (L : X -> Q -> Q) :=
- llip_prf' :> forall (x : X) (r : Q), PropHolds (0 ≤ r) -> IsLipschitz (restrict f x r) (L x r).
-
-End LocallyLipschitz'.*)
-
Global Instance sum_llip `{MetricSpaceBall X}
(f g : X -> CR) `{!IsLocallyLipschitz f Lf} `{!IsLocallyLipschitz g Lg} :
IsLocallyLipschitz (f + g) (λ x r, Lf x r + Lg x r).
diff --git a/ode/metric.v b/ode/metric.v
index 991a962c..110803e7 100644
--- a/ode/metric.v
+++ b/ode/metric.v
@@ -558,6 +558,14 @@ of [IsLipschitz f _] for a specific term [f], then Coq should not enter an
infinite loop because that would require unifying [f] with [restrict _ _ _].
We need this instance to apply [lip_nonneg (restrict f x r) _] in order
to prove [0 ≤ Lf x r] when [IsLocallyLipschitz f Lf]. *)
+
+(* We make an assumption [0 ≤ r] in llip_prf below to make proving that
+functions are locally Lipschitz easier. As a part of such proof, one needs
+to show that [0 ≤ L x r] ([lip_nonneg]). Proving this under the assumption
+[0 ≤ r] may allow having simpler definitions of the uniform [L]. In
+particular, integral_lipschitz in AbstractIntegration.v defines [L] as
+[λ a r, abs (f a) + L' a r * r]. *)
+
Class IsLocallyLipschitz (f : X -> Y) (L : X -> Q -> Q) :=
llip_prf :> forall (x : X) (r : Q), PropHolds (0 ≤ r) -> IsLipschitz (restrict f x r) (L x r).
@@ -569,6 +577,16 @@ intros x r. constructor; [now apply (lip_nonneg f) |].
intros [x1 x1b] [x2 x2b] e A. change (ball (L * e) (f x1) (f x2)). now apply lip_prf.
Qed.
+Lemma llip `{!ExtMetricSpaceClass X} (f : X -> Y) `{IsLocallyLipschitz f L} (r e : Q) (a x y : X) :
+ ball r a x -> ball r a y -> ball e x y -> ball (L a r * e) (f x) (f y).
+Proof.
+intros A1 A2 A3.
+change (f x) with (restrict f a r (exist _ x A1)).
+change (f y) with (restrict f a r (exist _ y A2)).
+assert (0 ≤ r) by now apply (radius_nonneg a x).
+apply (lip_prf _ (L a r)); trivial.
+Qed.
+
Record LocallyLipschitz := {
llip_func :> X -> Y;
llip_const : X -> Q -> Q;
From e16593ec28c2e5f4e4a97e8bf9332fa87ad4cf90 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Wed, 17 Apr 2013 01:56:24 +0400
Subject: [PATCH 084/110] Made AbstractIntegration.v require
SimpleIntegration.v instead of the other way around. SimpleIntegration.v
defines integral for uniformly comtinuous functions; AbstractIntegration.v
proves properties of integral. Also proved several lemmas about rational
numbers.
---
ode/AbstractIntegration.v | 259 ++++++++++++++++++++------------------
ode/FromMetric2.v | 13 +-
ode/Picard.v | 16 ---
ode/SimpleIntegration.v | 116 ++++++++++++++++-
ode/metric.v | 5 +-
5 files changed, 260 insertions(+), 149 deletions(-)
diff --git a/ode/AbstractIntegration.v b/ode/AbstractIntegration.v
index 58d246b7..75a6a913 100644
--- a/ode/AbstractIntegration.v
+++ b/ode/AbstractIntegration.v
@@ -9,7 +9,7 @@ Require Import
stdlib_omissions.Z
stdlib_omissions.Q
stdlib_omissions.N.
-Require Import metric FromMetric2.
+Require Import metric FromMetric2 SimpleIntegration.
Require Qinf QnonNeg QnnInf CRball.
Import Qinf.notations QnonNeg.notations QnnInf.notations CRball.notations Qabs.
@@ -39,6 +39,42 @@ Add Field Qfield : Qsft
constants [Qcst],
power_tac Qpower_theory [Qpow_tac]).
+(* To be added to stdlib.omissions.Q *)
+Section QFacts.
+
+Open Scope Q_scope.
+
+Lemma Qmult_inv_l (x : Q) : ~ x == 0 -> / x * x == 1.
+Proof. intros; rewrite Qmult_comm; apply Qmult_inv_r; trivial. Qed.
+
+Lemma Qinv_0 (x : Q) : / x == 0 <-> x == 0.
+Proof.
+split; intro H; [| now rewrite H].
+destruct x as [m n]; destruct m as [| p | p]; unfold Qinv in *; simpl in *; [reflexivity | |];
+unfold Qeq in H; simpl in H; rewrite Pos.mul_1_r in H; discriminate H.
+Qed.
+
+Lemma Qinv_not_0 (x : Q) : ~ / x == 0 <-> ~ x == 0.
+Proof. now rewrite Qinv_0. Qed.
+
+Lemma Qdiv_l (x y z : Q) : ~ x == 0 -> (x * y == z <-> y == z / x).
+Proof.
+intro H1.
+rewrite <- (Qmult_injective_l x H1 y (z / x)). unfold Qdiv.
+now rewrite <- Qmult_assoc, (Qmult_inv_l x H1), Qmult_1_r, Qmult_comm.
+Qed.
+
+Lemma Qdiv_r (x y z : Q) : ~ y == 0 -> (x * y == z <-> x == z / y).
+Proof. rewrite Qmult_comm; apply Qdiv_l. Qed.
+
+Lemma Q_of_nat_inj (m n : nat) : m == n <-> m = n.
+Proof.
+split; intro H; [| now rewrite H].
+rewrite QArith_base.inject_Z_injective in H. now apply Nat2Z.inj in H.
+Qed.
+
+End QFacts.
+
Definition split (w: QnonNeg) (bound: QposInf):
{ x: nat * QnonNeg | (fst x * snd x == w)%Qnn /\ (snd x <= bound)%QnnInf }.
Proof with simpl; auto with *.
@@ -47,7 +83,7 @@ Proof with simpl; auto with *.
Focus 2. exists (1%nat, w). simpl. split... ring.
induction w using QnonNeg.rect.
exists (0%nat, 0%Qnn)...
- set (p := QposCeiling (QposMake n d / q)%Qpos).
+ set (p := Qpossec.QposCeiling (QposMake n d / q)%Qpos).
exists (nat_of_P p, ((QposMake n d / p)%Qpos):QnonNeg)...
split.
rewrite <- Zpos_eq_Z_of_nat_o_nat_of_P.
@@ -55,7 +91,7 @@ Proof with simpl; auto with *.
field. discriminate.
subst p.
apply Qle_shift_div_r...
- rewrite QposCeiling_Qceiling. simpl.
+ rewrite Qpossec.QposCeiling_Qceiling. simpl.
setoid_replace (n#d:Q) with (q * ((n#d) * / q))%Q at 1 by (simpl; field)...
do 2 rewrite (Qmult_comm q).
apply Qmult_le_compat_r...
@@ -110,43 +146,11 @@ Hint Immediate ball_refl Qle_refl.
Bind Scope Q_scope with Q.
-Class Integral (f: Q → CR) := integrate: forall (from: Q) (w: QnonNeg), CR.
-
-Implicit Arguments integrate [[Integral]].
+(*Arguments integral_additive {f} {_} {_} a b c _ _.*)
-Notation "∫" := integrate.
+Section integral_approximation.
-Section integral_interface.
-
- Context (f: Q → CR).
-
- Class Integrable `{!Integral f}: Prop :=
- { integral_additive:
- forall (a: Q) b c, ∫ f a b + ∫ f (a+` b) c == ∫ f a (b+c)%Qnn
-
- ; integral_bounded_prim: forall (from: Q) (width: Qpos) (mid: Q) (r: Qpos),
- (forall x, from <= x <= from+width -> ball r (f x) ('mid)) ->
- ball (width * r) (∫ f from width) (' (width * mid)%Q)
-
- ; integral_wd:> Proper (Qeq ==> QnonNeg.eq ==> @st_eq CRasCSetoid) (∫ f) }.
-
- (* Todo: Show that the sign function is integrable while not locally uniformly continuous. *)
-
- (** This closely resembles the axiomatization given in
- Bridger's "Real Analysis: A Constructive Approach", Ch. 5. *)
-
- (** The boundedness property is stated very primitively here, in that r is a Qpos instead of a CR,
- w is a Qpos instead of a QnonNeg, and mid is a Q instead of a CR. This means that it's easy to
- show that particular implementations satisfy this interface, but hard to use this property directly.
- Hence, we will show in a moment that the property as stated actually implies its generalization
- with r and mid in CR and w in QnonNeg. *)
-
- (** Note: Another way to state the property still more primitively (and thus more easily provable) might
- be to make the inequalities in "from <= x <= from+width" strict. *)
-
- Section singular_props. (* Properties we can derive for a single integral of a function. *)
-
- Context `{Int: Integrable}.
+ Context (f: Q → CR) `{Int: Integrable f}.
(** The additive property implies that zero width intervals have zero surface: *)
@@ -357,19 +361,23 @@ Section integral_interface.
apply (mspc_monotone delta); [apply A1 | apply A4].
Qed.
- Lemma Riemann_sums_approximate_integral (a: Q) (w: Qpos) (e: Qpos) (iw: Q) (n: nat):
- (n * iw == w)%Q ->
+ Lemma Riemann_sums_approximate_integral (a: Q) (w: QnonNeg) (e: Qpos) (iw: Q) (n: nat):
+ (S n * iw == w)%Q ->
(iw <= lmu a w e)%Qinf ->
- gball (e * w) (cmΣ n (fun i => 'iw * f (a + i * iw))%CR) (∫ f a w).
+ gball (e * w) (cmΣ (S n) (fun i => 'iw * f (a + i * iw))%CR) (∫ f a w).
Proof.
intros A B.
- assert (iw_nn : 0 <= iw) by (apply Qlt_le_weak, (Qmult_pos_r n); [| rewrite A]; Qauto_nonneg).
+ assert (ne_sn_0 : ~ S n == 0) by
+ (change 0 with (inject_Z (Z.of_nat 0)); rewrite Q_of_nat_inj; apply S_O).
+ assert (iw_nn : 0 <= iw) by
+ (apply Qdiv_l in A; [| assumption]; rewrite A; apply Qmult_le_0_compat; [now auto|];
+ apply Qinv_le_0_compat, Qle_nat). (* This should be automated *)
set (iw' := exist _ iw iw_nn : QnonNeg ).
change iw with (QnonNeg.to_Q iw').
- change (n * iw' == w)%Qnn in A.
- rewrite <- A.
+ change (S n * iw' == w)%Qnn in A.
+ rewrite <- A at 2.
rewrite <- integral_repeated_additive.
- setoid_replace (e * w)%Q with (n * (iw * e))%Q by
+ setoid_replace (e * w)%Q with (S n * (iw * e))%Q by
(unfold QnonNeg.eq in A; simpl in A;
rewrite Qmult_assoc; rewrite A; apply Qmult_comm).
apply CRΣ_gball.
@@ -379,13 +387,13 @@ Section integral_interface.
setoid_replace (' (iw * e)) with (scale iw' (' ` e)) by now rewrite <- scale_Qmult.
apply integral_bounded; [apply CRnonNegQpos |].
intros x [A1 A2]. apply CRball.rational. apply (luc_gball a w (`iw')); trivial.
- + apply ball_gball, Qball_Qabs.
+ + apply gball_Qabs.
setoid_replace (a - (a + m * iw')) with (- (m * iw')) by ring.
rewrite Qabs_opp. apply Qabs_le_nonneg; [Qauto_nonneg |].
- apply Qle_trans with (y := (n * iw')).
+ apply Qle_trans with (y := (S n * iw')).
apply Qmult_le_compat_r. apply Qlt_le_weak. rewrite <- Zlt_Qlt. now apply inj_lt.
apply (proj2_sig iw').
- change (n * iw' == w) in A. rewrite <- A; reflexivity.
+ change (S n * iw' == w) in A. rewrite <- A; reflexivity.
+ apply gball_Qabs, Qabs_Qle_condition.
split.
apply Qplus_le_l with (z := x), Qplus_le_l with (z := w).
@@ -393,7 +401,7 @@ Section integral_interface.
apply Qle_trans with (y := (a + m * ` iw' + ` iw')); [easy |].
setoid_rewrite <- (Qmult_1_l (` iw')) at 2. change 1%Q with (inject_Z (Z.of_nat 1)).
rewrite <- Qplus_assoc, <- Qmult_plus_distr_l, <- Zplus_Qplus, <- Nat2Z.inj_add.
- apply Qplus_le_r. change (n * iw' == w) in A. rewrite <- A.
+ apply Qplus_le_r. change (S n * iw' == w) in A. rewrite <- A.
apply Qmult_le_compat_r. rewrite <- Zle_Qle. apply inj_le. rewrite Plus.plus_comm.
now apply lt_le_S.
apply (proj2_sig iw').
@@ -401,7 +409,7 @@ Section integral_interface.
setoid_replace (a - x + x + - w) with (a - w) by ring.
setoid_replace (w + x + - w) with x by ring.
apply Qle_trans with (y := a). rewrite <- (Qplus_0_r a) at 2.
- apply Qplus_le_r. change 0 with (-0). apply Qopp_le_compat, Qlt_le_weak, (proj2_sig w).
+ apply Qplus_le_r. change 0 with (-0). apply Qopp_le_compat, (proj2_sig w).
apply Qle_trans with (y := a + m * ` iw'); [| easy].
rewrite <- (Qplus_0_r a) at 1. apply Qplus_le_r, Qmult_le_0_compat; [apply Qle_nat | apply (proj2_sig iw')].
+ apply gball_Qabs, Qabs_Qle_condition; split.
@@ -415,9 +423,6 @@ Section integral_interface.
apply Qminus_less. apply (proj2_sig iw').
Qed.
-(* Program Definition step (w : Qpos) (n : positive) : QnonNeg := exist _ (w * (1 # n)) _.
- Next Obligation. Qauto_nonneg. Qed.*)
-
Definition step (w : Q) (n : positive) : Q := w * (1 # n).
Lemma step_nonneg (w : Q) (n : positive) : 0 <= w -> 0 <= step w n.
@@ -434,16 +439,24 @@ Section integral_interface.
let iw := step w n in
cmΣ (Pos.to_nat n) (fun i => 'iw * f (a + i * iw))%CR.
- Lemma Riemann_sums_approximate_integral' (a : Q) (w : Qpos) (e : Qpos) (n : positive) :
+(*Set Printing Coercions.
+SearchAbout Pos.to_nat.
+ZL4': ∀ y : positive, {h : nat | Pos.to_nat y = S h}
+nat_of_P_nonzero: ∀ p : positive, Pos.to_nat p ≠ 0%nat
+Pos2Nat.is_succ: ∀ p : positive, ∃ n : nat, Pos.to_nat p = S n*)
+
+ Lemma Riemann_sums_approximate_integral' (a : Q) (w : QnonNeg) (e : Qpos) (n : positive) :
(step w n <= lmu a w e)%Qinf ->
gball (e * w) (riemann_sum a w n) (∫ f a w).
Proof.
- intro A; unfold riemann_sum. apply Riemann_sums_approximate_integral; [| easy].
+ intro A; unfold riemann_sum.
+ destruct (Pos2Nat.is_succ n) as [m M]. rewrite M.
+ apply Riemann_sums_approximate_integral; [rewrite <- M | easy].
unfold step. change (Pos.to_nat n * (w * (1 # n)) == w).
rewrite positive_nat_Z. unfold inject_Z. rewrite !Qmake_Qdiv; field; auto.
Qed.
- Lemma Riemann_sums_approximate_integral'' (a : Q) (w : Qpos) (e : Qpos) :
+ Lemma Riemann_sums_approximate_integral'' (a : Q) (w : QnonNeg) (e : Qpos) :
exists N : positive, forall n : positive, (N <= n)%positive ->
gball e (riemann_sum a w n) (∫ f a w).
Proof.
@@ -461,8 +474,6 @@ Section integral_interface.
subst N. now apply Z.Ple_Zle_to_pos, Q.Zle_Qle_Qceiling in A.
Qed.
- End singular_props.
-
(** Unicity itself will of course have to be stated w.r.t. *two* integrals: *)
(*
Lemma unique
@@ -492,7 +503,7 @@ Section integral_interface.
apply (Riemann_sums_approximate_integral a x ((1 # 2) * e / x)%Qpos t n H H0).
Qed.
*)
-End integral_interface.
+End integral_approximation.
(** If f==g, then an integral for f is an integral for g. *)
@@ -502,76 +513,16 @@ Proof with auto.
constructor.
replace (@integrate g) with (@integrate f) by reflexivity.
intros.
- apply (integral_additive f).
+ apply integral_additive.
replace (@integrate g) with (@integrate f) by reflexivity.
intros.
- apply (integral_bounded_prim f)...
+ apply integral_bounded_prim...
intros.
rewrite (H x x (refl_equal _))...
replace (@integrate g) with (@integrate f) by reflexivity.
- apply (integral_wd f)...
+ apply integral_wd...
Qed.
-(** Finally, we offer a smart constructor for implementations that would need to recognize and
- treat the zero-width case specially anyway (which is the case for the implementation
-with Riemann sums, because there, a positive width is needed to divide the error by). *)
-
-Section extension_to_nn_width.
-
- Context
- (f: Q → CR)
- (pre_integral: Q → Qpos → CR) (* Note the Qpos instead of QnonNeg. *)
- (* The three properties limited to pre_integral: *)
- (pre_additive: forall (a: Q) (b c: Qpos),
- pre_integral a b + pre_integral (a + `b)%Q c[=]pre_integral a (b + c)%Qpos)
- (pre_bounded: forall (from: Q) (width: Qpos) (mid: Q) (r: Qpos),
- (forall x: Q, from <= x <= from + width -> ball r (f x) (' mid)) ->
- ball (width * r) (pre_integral from width) (' (width * mid)%Q))
- {pre_wd: Proper (Qeq ==> QposEq ==> @st_eq _) pre_integral}.
-
- Instance integral_extended_to_nn_width: Integral f :=
- fun from => QnonNeg.rect (fun _ => CR)
- (fun _ _ => '0%Q)
- (fun n d _ => pre_integral from (QposMake n d)).
-
- Let proper: Proper (Qeq ==> QnonNeg.eq ==> @st_eq _) (∫ f).
- Proof with auto.
- intros ?????.
- induction x0 using QnonNeg.rect;
- induction y0 using QnonNeg.rect.
- reflexivity.
- discriminate.
- discriminate.
- intros. apply pre_wd...
- Qed.
-
- Let bounded (from: Q) (width: Qpos) (mid: Q) (r: Qpos):
- (forall x, from <= x <= from + width -> ball r (f x) (' mid)) ->
- ball (width * r) (∫ f from width) (' (width * mid)%Q).
- Proof.
- induction width using Qpos_positive_numerator_rect.
- apply (pre_bounded from (a#b) mid r).
- Qed.
-
- Let additive (a: Q) (b c: QnonNeg): ∫ f a b + ∫ f (a + `b)%Q c == ∫ f a (b + c)%Qnn.
- Proof.
- unfold integrate.
- induction b using QnonNeg.rect;
- induction c using QnonNeg.rect; simpl integral_extended_to_nn_width; intros.
- ring.
- rewrite CRplus_0_l.
- apply pre_wd; unfold QposEq, Qeq; simpl; repeat rewrite Zpos_mult_morphism; ring.
- rewrite CRplus_0_r.
- apply pre_wd; unfold QposEq, Qeq; simpl; repeat rewrite Zpos_mult_morphism; ring.
- rewrite (pre_additive a (QposMake n d) (QposMake n0 d0)).
- apply pre_wd; reflexivity.
- Qed.
-
- Lemma integral_extended_to_nn_width_correct: Integrable f.
- Proof. constructor; auto. Qed.
-
-End extension_to_nn_width.
-
Import abstract_algebra.
Lemma mult_comm `{SemiRing R} : Commutative (.*.).
@@ -834,7 +785,7 @@ Proof. now rewrite rings.flip_negate, rings.negate_involutive. Qed.
End RingFacts.
-Import interfaces.orders.
+Import interfaces.orders orders.minmax.
Lemma join_comm `{JoinSemiLatticeOrder L} : Commutative join.
Proof.
@@ -965,6 +916,68 @@ symmetry; unfold integrate at 1, integrate_sum.
apply rings.negate_plus_distr. (* does not work without unfold *)
Qed.*)
+Lemma integrate_plus (f g : Q -> CR)
+ `{!IsUniformlyContinuous f f_mu, !IsUniformlyContinuous g g_mu} (a : Q) (w : Qpos) :
+ ∫ (f + g) a w = ∫ f a w + ∫ g a w.
+Proof.
+apply mspc_closed. intros e e_pos. (* Why is 0%Q? *)
+mc_setoid_replace (0 + e) with e by ring.
+assert (he_pos : 0 < e / 2) by solve_propholds.
+assert (qe_pos : 0 < e / 4) by solve_propholds.
+destruct (Riemann_sums_approximate_integral'' f a w (mkQpos qe_pos)) as [Nf F].
+destruct (Riemann_sums_approximate_integral'' g a w (mkQpos qe_pos)) as [Ng G].
+destruct (Riemann_sums_approximate_integral'' (f + g) a w (mkQpos he_pos)) as [Ns S].
+(* [Le positive] is not yet defined *)
+set (n := Pos.max (Pos.max Nf Ng) Ns).
+assert (Nf <= n)%positive by (transitivity (Pos.max Nf Ng); apply Pos.le_max_l).
+assert (Ng <= n)%positive by (transitivity (Pos.max Nf Ng); [apply Pos.le_max_r | apply Pos.le_max_l]).
+assert (Ns <= n)%positive by apply Pos.le_max_r.
+apply (mspc_triangle' (e / 2) (e / 2) (riemann_sum (f + g) a w n)); [field; discriminate | |].
+* apply mspc_symm, S; assumption.
+* rewrite riemann_sum_plus.
+ mc_setoid_replace (e / 2) with (e / 4 + e / 4) by (field; split; discriminate).
+ now apply mspc_ball_CRplus; [apply F | apply G].
+Qed.
+
+Lemma int_plus (f g : Q -> CR)
+ `{!IsUniformlyContinuous f f_mu, !IsUniformlyContinuous g g_mu} (a b : Q) :
+ int (f + g) a b = int f a b + int g a b.
+Proof.
+destruct (trichotomy (<) a b) as [A | [A | A]].
++ assert (L : a ≤ b) by solve_propholds.
+ assert (P : 0 < b - a) by now apply rings.flip_pos_minus.
+ unfold int; destruct (decide (a ≤ b)) as [B | B]; [clear L | elim (B L)].
+ (* Bad because it mentions [int_obligation_1] *)
+ setoid_replace ((b - a) ↾ int_obligation_1 a b B) with
+ (QnonNeg.from_Qpos (mkQpos P)) using relation QnonNeg.eq by reflexivity.
+ apply integrate_plus.
++ change (Qeq a b) in A. rewrite A.
+
+
+
+intros A. apply ball_gball; simpl. apply gball_closed. intros e e_pos.
+setoid_replace (width * r + e)%Q with (e + width * r)%Q by apply Qplus_comm.
+destruct (Riemann_sums_approximate_integral'' f from width ((1#2) * mkQpos e_pos)%Qpos) as [Nf F].
+destruct (Riemann_sums_approximate_integral'' g from width ((1#2) * mkQpos e_pos)%Qpos) as [Ng G].
+set (n := Pos.max Nf Ng).
+assert (le_Nf_n : (Nf <= n)%positive) by apply Pos.le_max_l.
+assert (le_Ng_n : (Ng <= n)%positive) by apply Pos.le_max_r.
+specialize (F n le_Nf_n). specialize (G n le_Ng_n).
+apply gball_triangle with (b := riemann_sum (f + g) from width n).
++ rewrite riemann_sum_plus. setoid_replace e with ((1#2) * e + (1#2) * e)%Q by ring.
+ apply CRgball_plus; apply gball_sym; trivial.
++ (* apply riemann_sum_bounds. diverges *)
+ rewrite <- CRmult_Qmult. apply riemann_sum_bounds; [solve_propholds |].
+ intros. apply ball_gball. apply A; trivial.
+
+Lemma int_negate (f : Q -> CR) `{!IsUniformlyContinuous f f_mu} (a b : Q) :
+ int (- f) a b = - int f a b.
+Admitted.
+
+Lemma int_minus (f g : Q -> CR)
+ `{!IsUniformlyContinuous f f_mu, !IsUniformlyContinuous g g_mu} (a b : Q) :
+ int (f - g) a b = int f a b - int g a b.
+Proof. rewrite int_plus, int_negate; reflexivity. Qed.
Import interfaces.orders orders.semirings.
diff --git a/ode/FromMetric2.v b/ode/FromMetric2.v
index 69f2177b..0a6461e4 100644
--- a/ode/FromMetric2.v
+++ b/ode/FromMetric2.v
@@ -164,11 +164,18 @@ destruct (orders.le_equiv_lt _ _ A1) as [e_zero | e_pos].
+ apply (gball_pos e_pos _ _) in A. now apply (gball_pos e_pos _ _), Qball_plus_r.
Qed.
+(* This is a copy of [CRgball_plus] formulated in terms of [mspc_ball]
+instead of [gball]. Applying [CRgball_plus] introduces [gball] into the
+goal, and then applying some theorems about [mspc_ball] may not work. This
+is because [mspc_ball] reduces to [gball] but not the other way around. *)
+Lemma mspc_ball_CRplus (e1 e2 : Q) (x x' y y' : CR) :
+ ball e1 x x' -> ball e2 y y' -> ball (e1 + e2) (x + y) (x' + y').
+Proof. apply CRgball_plus. Qed.
+
Lemma mspc_ball_CRplus_l (e : Q) (x y y' : CR) : ball e y y' -> ball e (x + y) (x + y').
Proof.
-intro A. rewrite <- (rings.plus_0_l e). apply CRgball_plus; [| easy].
-(*[ apply mspc_refl] does not work *)
-change (ball 0 x x); now apply mspc_refl.
+intro A. rewrite <- (rings.plus_0_l e). apply mspc_ball_CRplus; [| easy].
+now apply mspc_refl.
Qed.
Lemma mspc_ball_CRnegate (e : Q) (x y : CR) : mspc_ball e x y -> mspc_ball e (-x) (-y).
diff --git a/ode/Picard.v b/ode/Picard.v
index 84a5febb..eb6eadc1 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -187,22 +187,6 @@ Qed.
End Bounded.
-Global Existing Instance luc_prf.
-
-Lemma int_plus (f g : Q -> CR)
- `{!IsUniformlyContinuous f f_mu, !IsUniformlyContinuous g g_mu} (a b : Q) :
- int (f + g) a b = int f a b + int g a b.
-Admitted.
-
-Lemma int_negate (f : Q -> CR) `{!IsUniformlyContinuous f f_mu} (a b : Q) :
- int (- f) a b = - int f a b.
-Admitted.
-
-Lemma int_minus (f g : Q -> CR)
- `{!IsUniformlyContinuous f f_mu, !IsUniformlyContinuous g g_mu} (a b : Q) :
- int (f - g) a b = int f a b - int g a b.
-Proof. rewrite int_plus, int_negate; reflexivity. Qed.
-
Global Instance bounded_int_uc {f : Q -> CR} {M : Q}
`{!Bounded f M} `{!IsUniformlyContinuous f mu_f} (x0 : Q) :
IsUniformlyContinuous (λ x, int f x0 x) (lip_modulus M).
diff --git a/ode/SimpleIntegration.v b/ode/SimpleIntegration.v
index aa5203eb..76a5e751 100644
--- a/ode/SimpleIntegration.v
+++ b/ode/SimpleIntegration.v
@@ -8,9 +8,9 @@
Require Import
List NPeano Unicode.Utf8
- QArith Qabs Qpossec Qsums
+ QArith Qabs Qpossec QnonNeg Qsums
Qmetric Qsetoid (* Needs imported for Q_is_Setoid to be a canonical structure *)
- CRArith AbstractIntegration
+ CRArith (*AbstractIntegration*)
util.Qgcd
Program
uneven_CRplus
@@ -21,8 +21,10 @@ Require Import
metric FromMetric2
implementations.stdlib_rationals.
+Import QnonNeg.notations.
+
Bind Scope Q_scope with Q.
-Open Scope Q_scope.
+Local Open Scope Q_scope.
Lemma gball_mspc_ball {X : MetricSpace} (r : Q) (x y : X) :
gball r x y <-> mspc_ball r x y.
@@ -32,6 +34,108 @@ Lemma ball_mspc_ball {X : MetricSpace} (r : Qpos) (x y : X) :
ball r x y <-> mspc_ball r x y.
Proof. rewrite <- ball_gball; reflexivity. Qed.
+Class Integral (f: Q → CR) := integrate: forall (from: Q) (w: QnonNeg), CR.
+
+Implicit Arguments integrate [[Integral]].
+
+Notation "∫" := integrate.
+
+Section integral_interface.
+
+ Open Scope CR_scope.
+
+ (*Context (f: Q → CR).*)
+
+ Class Integrable `{!Integral f}: Prop :=
+ { integral_additive:
+ forall (a: Q) b c, ∫ f a b + ∫ f (a+` b) c == ∫ f a (b+c)%Qnn
+
+ ; integral_bounded_prim: forall (from: Q) (width: Qpos) (mid: Q) (r: Qpos),
+ (forall x, from <= x <= from+width -> ball r (f x) ('mid)) ->
+ ball (width * r) (∫ f from width) (' (width * mid)%Q)
+
+ ; integral_wd:> Proper (Qeq ==> QnonNeg.eq ==> @st_eq CRasCSetoid) (∫ f) }.
+
+ (* Todo: Show that the sign function is integrable while not locally uniformly continuous. *)
+
+ (** This closely resembles the axiomatization given in
+ Bridger's "Real Analysis: A Constructive Approach", Ch. 5. *)
+
+ (** The boundedness property is stated very primitively here, in that r is a Qpos instead of a CR,
+ w is a Qpos instead of a QnonNeg, and mid is a Q instead of a CR. This means that it's easy to
+ show that particular implementations satisfy this interface, but hard to use this property directly.
+ Hence, we will show in a moment that the property as stated actually implies its generalization
+ with r and mid in CR and w in QnonNeg. *)
+
+ (** Note: Another way to state the property still more primitively (and thus more easily provable) might
+ be to make the inequalities in "from <= x <= from+width" strict. *)
+
+End integral_interface.
+
+Arguments Integrable f {_}.
+
+(** We offer a smart constructor for implementations that would need to recognize and
+ treat the zero-width case specially anyway (which is the case for the implementation
+with Riemann sums, because there, a positive width is needed to divide the error by). *)
+
+Section extension_to_nn_width.
+
+ Open Scope CR_scope.
+
+ Context
+ (f: Q → CR)
+ (pre_integral: Q → Qpos → CR) (* Note the Qpos instead of QnonNeg. *)
+ (* The three properties limited to pre_integral: *)
+ (pre_additive: forall (a: Q) (b c: Qpos),
+ pre_integral a b + pre_integral (a + `b)%Q c[=]pre_integral a (b + c)%Qpos)
+ (pre_bounded: forall (from: Q) (width: Qpos) (mid: Q) (r: Qpos),
+ (forall x: Q, from <= x <= from + width -> ball r (f x) (' mid)) ->
+ ball (width * r) (pre_integral from width) (' (width * mid)%Q))
+ {pre_wd: Proper (Qeq ==> QposEq ==> @st_eq _) pre_integral}.
+
+ Instance integral_extended_to_nn_width: Integral f :=
+ fun from => QnonNeg.rect (fun _ => CR)
+ (fun _ _ => '0%Q)
+ (fun n d _ => pre_integral from (QposMake n d)).
+
+ Let proper: Proper (Qeq ==> QnonNeg.eq ==> @st_eq _) (∫ f).
+ Proof with auto.
+ intros ?????.
+ induction x0 using QnonNeg.rect;
+ induction y0 using QnonNeg.rect.
+ reflexivity.
+ discriminate.
+ discriminate.
+ intros. apply pre_wd...
+ Qed.
+
+ Let bounded (from: Q) (width: Qpos) (mid: Q) (r: Qpos):
+ (forall x, from <= x <= from + width -> ball r (f x) (' mid)) ->
+ ball (width * r) (∫ f from width) (' (width * mid)%Q).
+ Proof.
+ induction width using Qpos_positive_numerator_rect.
+ apply (pre_bounded from (a#b) mid r).
+ Qed.
+
+ Let additive (a: Q) (b c: QnonNeg): ∫ f a b + ∫ f (a + `b)%Q c == ∫ f a (b + c)%Qnn.
+ Proof.
+ unfold integrate.
+ induction b using QnonNeg.rect;
+ induction c using QnonNeg.rect; simpl integral_extended_to_nn_width; intros.
+ ring.
+ rewrite CRplus_0_l.
+ apply pre_wd; unfold QposEq, Qeq; simpl; repeat rewrite Zpos_mult_morphism; ring.
+ rewrite CRplus_0_r.
+ apply pre_wd; unfold QposEq, Qeq; simpl; repeat rewrite Zpos_mult_morphism; ring.
+ rewrite (pre_additive a (QposMake n d) (QposMake n0 d0)).
+ apply pre_wd; reflexivity.
+ Qed.
+
+ Lemma integral_extended_to_nn_width_correct: Integrable f.
+ Proof. constructor; auto. Qed.
+
+End extension_to_nn_width.
+
Open Scope uc_scope.
Hint Resolve Qpos_nonzero.
@@ -274,7 +378,7 @@ Section definition.
Definition pre_result fr w: CR := mkRegularFunction (0:Q_as_MetricSpace) (regular fr w).
- Global Instance integrate: Integral f := @integral_extended_to_nn_width f pre_result.
+ Global Instance (*integrate*): Integral f := @integral_extended_to_nn_width f pre_result.
Global Instance: Proper (Qeq ==> QposEq ==> @st_eq _) pre_result.
Proof.
@@ -477,7 +581,7 @@ Section implements_abstract_interface.
Lemma data_points_in_range (from: Q) (width: Qpos) (ints: positive) (i : nat) (Ilt: (i < ints)%nat):
from <= (from + (i * (`width / ints) + (1 # 2) * (`width / ints))) <= from + `width.
- Proof with auto.
+ Proof with auto with qarith.
split.
rewrite <- (Qplus_0_r from) at 1.
apply Qplus_le_compat...
@@ -498,7 +602,7 @@ Section implements_abstract_interface.
Let bounded (from: Q) (width: Qpos) (mid: Q) (r: Qpos):
(forall x, from <= x <= from + width -> ball r (f x) ('mid)%CR) ->
ball (width * r) (pre_result f from width) (' (width * mid)%Q)%CR.
- Proof with auto.
+ Proof with auto with qarith.
intros. apply (@regFunBall_Cunit Q_as_MetricSpace).
intro. unfold pre_result. simpl approximate.
unfold approx.
diff --git a/ode/metric.v b/ode/metric.v
index 110803e7..252a1edd 100644
--- a/ode/metric.v
+++ b/ode/metric.v
@@ -424,8 +424,11 @@ Context `{MetricSpaceBall X, MetricSpaceBall Y}.
Definition restrict (f : X -> Y) (x : X) (r : Q) : sig (ball r x) -> Y :=
f ∘ @proj1_sig _ _.
+(* See the remark about llip_prf below about the loop between
+IsUniformlyContinuous and IsLocallyUniformlyContinuous *)
+
Class IsLocallyUniformlyContinuous (f : X -> Y) (lmu : X -> Q -> Q -> Qinf) :=
- luc_prf : forall (x : X) (r : Q), IsUniformlyContinuous (restrict f x r) (lmu x r).
+ luc_prf :> forall (x : X) (r : Q), IsUniformlyContinuous (restrict f x r) (lmu x r).
Global Arguments luc_prf f lmu {_} x r.
From 4855512b7c8b459e360df4ba6533e10145656503 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Sat, 20 Apr 2013 03:17:42 +0400
Subject: [PATCH 085/110] Proved that the integral of a sum equals the sum of
integrals
---
ode/AbstractIntegration.v | 182 +++++++++++++++++++++++++-------------
1 file changed, 121 insertions(+), 61 deletions(-)
diff --git a/ode/AbstractIntegration.v b/ode/AbstractIntegration.v
index 75a6a913..7bfc7e65 100644
--- a/ode/AbstractIntegration.v
+++ b/ode/AbstractIntegration.v
@@ -12,7 +12,7 @@ Require Import
Require Import metric FromMetric2 SimpleIntegration.
Require Qinf QnonNeg QnnInf CRball.
-Import Qinf.notations QnonNeg.notations QnnInf.notations CRball.notations Qabs.
+Import Qinf.notations QnonNeg.notations QnnInf.notations CRball.notations Qabs (*canonical_names*).
Require CRtrans ARtrans. (* This is almost all CoRN *)
@@ -23,9 +23,8 @@ Ltac done :=
(* | case not_locked_false_eq_true; assumption*)
| match goal with H : ~ _ |- _ => solve [case H; trivial] end ].
-Open Local Scope Q_scope.
-(*Open Local Scope uc_scope.*)
-Open Local Scope CR_scope.
+Local Open Scope Q_scope.
+Local Open Scope CR_scope.
(* [SearchAbout ((Cmap _ _) (Cunit _)).] does not find anything, but it
should find metric2.Prelength.fast_MonadLaw3 *)
@@ -128,6 +127,15 @@ Proof with simpl; auto.
Qed.
*)
+Lemma cmΣ_0 (f : nat -> CR) (n : nat) :
+ (forall m, (m < n)%nat -> f m [=] 0) -> cmΣ n f [=] 0.
+Proof.
+induction n as [| n IH]; intro H; [reflexivity |].
+unfold cmΣ. simpl @cm_Sum. rewrite H by apply lt_n_Sn.
+rewrite IH; [apply CRplus_0_l |].
+intros m H1; apply H. now apply lt_S.
+Qed.
+
Lemma CRΣ_gball (f g: nat -> CR) (e : Q) (n : nat):
(forall m, (m < n)%nat -> gball e (f m) (g m)) ->
(gball (n * e) (cmΣ n f) (cmΣ n g)).
@@ -140,6 +148,14 @@ Proof.
apply CRgball_plus; auto.
Qed.
+(*Instance cmΣ_proper : Proper (eq ==> @ext_equiv nat _ CR _ ==> @st_eq CR) cmΣ.
+Proof.
+intros n1 n2 E1 f1 f2 E2. rewrite E1.
+change (gball 0 (cmΣ n2 f1) (cmΣ n2 f2)).
+setoid_replace 0%Q with (n2 * 0)%Q by ring.
+apply CRΣ_gball. now intros m _; apply E2.
+Qed.*)
+
Hint Immediate ball_refl Qle_refl.
(** Next up, the actual interface for integrable functions. *)
@@ -428,6 +444,9 @@ Section integral_approximation.
Lemma step_nonneg (w : Q) (n : positive) : 0 <= w -> 0 <= step w n.
Proof. intros w_nn; unfold step; Qauto_nonneg. Qed.
+ Lemma step_0 (n : positive) : step 0 n == 0.
+ Proof. unfold step; now rewrite Qmult_0_l. Qed.
+
Lemma step_mult (w : Q) (n : positive) : (n : Q) * step w n == w.
Proof.
unfold step.
@@ -435,15 +454,21 @@ Section integral_approximation.
rewrite Qmult_inv_r, Qmult_1_l; [reflexivity | auto with qarith].
Qed.
- Definition riemann_sum (a : Q) (w : Q) (n : positive) :=
+ Definition riemann_sum (a w : Q) (n : positive) :=
let iw := step w n in
cmΣ (Pos.to_nat n) (fun i => 'iw * f (a + i * iw))%CR.
-(*Set Printing Coercions.
-SearchAbout Pos.to_nat.
-ZL4': ∀ y : positive, {h : nat | Pos.to_nat y = S h}
-nat_of_P_nonzero: ∀ p : positive, Pos.to_nat p ≠ 0%nat
-Pos2Nat.is_succ: ∀ p : positive, ∃ n : nat, Pos.to_nat p = S n*)
+ (*Instance : Proper (Qeq ==> Qeq ==> eq ==> @st_eq CR) riemann_sum.
+ Proof.
+ intros a1 a2 Ea w1 w2 Ew n1 n2 En. apply cmΣ_proper; [now rewrite En |].
+ intros i1 i2 Ei.*)
+
+ Lemma riemann_sum_0 (a : Q) (n : positive) : riemann_sum a 0 n [=] 0%CR.
+ Proof.
+ unfold riemann_sum. apply cmΣ_0.
+ intros m _. rewrite step_0.
+ now setoid_replace (0 * f (a + m * 0))%CR with 0%CR by ring.
+ Qed.
Lemma Riemann_sums_approximate_integral' (a : Q) (w : QnonNeg) (e : Qpos) (n : positive) :
(step w n <= lmu a w e)%Qinf ->
@@ -456,22 +481,45 @@ Pos2Nat.is_succ: ∀ p : positive, ∃ n : nat, Pos.to_nat p = S n*)
rewrite positive_nat_Z. unfold inject_Z. rewrite !Qmake_Qdiv; field; auto.
Qed.
- Lemma Riemann_sums_approximate_integral'' (a : Q) (w : QnonNeg) (e : Qpos) :
+ Lemma integral_approximation (a : Q) (w : QnonNeg) (e : Qpos) :
exists N : positive, forall n : positive, (N <= n)%positive ->
- gball e (riemann_sum a w n) (∫ f a w).
+ mspc_ball e (riemann_sum a w n) (∫ f a w).
Proof.
+ destruct (Qlt_le_dec 1 w) as [A1 | A1].
+ * assert (0 < w) by (apply (Qlt_trans _ 1); auto with qarith).
set (N := Z.to_pos (Qceiling (comp_inf (λ x, w / x) (lmu a w) 0 (e / w)))).
- exists N; intros n A. setoid_replace (QposAsQ e) with ((e / w)%Qpos * w)
- by (change (e == e / w * w); field; auto).
+ exists N; intros n A2.
+ setoid_replace (QposAsQ e) with (e / w * w) by (field; auto with qarith).
+ (* [apply Riemann_sums_approximate_integral'] does not unify because in
+ this lemma, the radius is [(QposAsQ e) * (QnonNeg.to_Q w)], and in the
+ goal the radius is [(QposAsQ e) / (QnonNeg.to_Q w) * (QnonNeg.to_Q w)]. *)
+ assert (P : 0 < e / w) by (apply Qmult_lt_0_compat; [| apply Qinv_lt_0_compat]; auto).
+ change (e / w) with (QposAsQ (mkQpos P)).
apply Riemann_sums_approximate_integral'.
- unfold step, comp_inf in *. change ((w * (1 # n))%Q <= lmu a w (e / w))%Qinf.
- assert (A2 : 0 < e / w) by (apply Qmult_lt_0_compat; [| apply Qinv_lt_0_compat]; auto).
- destruct (lmu a w (e / w)) as [mu |] eqn:A1; [| easy].
- assert (A3 := @uc_pos _ _ _ _ _ _ (L a w) (e / w) A2). rewrite A1 in A3.
- change (0 < mu) in A3.
- rewrite Qmake_Qdiv, injZ_One. unfold Qdiv. rewrite Qmult_assoc, Qmult_1_r.
- change (w / n <= mu). apply Qle_div_l; auto.
- subst N. now apply Z.Ple_Zle_to_pos, Q.Zle_Qle_Qceiling in A.
+ change (QposAsQ (mkQpos P)) with (e / w).
+ destruct (lmu a w (e / w)) as [mu |] eqn:A3; [| easy].
+ subst N; unfold comp_inf in A2; rewrite A3 in A2.
+ change (step w n <= mu); unfold step.
+ rewrite Qmake_Qdiv, injZ_One; unfold Qdiv; rewrite Qmult_assoc, Qmult_1_r.
+ assert (A4 : 0 < mu) by (change (Qinf.lt 0 mu); rewrite <- A3;
+ apply (uc_pos (restrict f a w) (lmu a w)); trivial).
+ apply Qle_div_l; auto.
+ now apply Z.Ple_Zle_to_pos, Q.Zle_Qle_Qceiling in A2.
+ * set (N := Z.to_pos (Qceiling (comp_inf (λ x, 1 / x) (lmu a w) 0 e))).
+ exists N; intros n A2.
+ apply (mspc_monotone (e * w)).
+ + change (e * w <= e). rewrite <- (Qmult_1_r e) at 2. apply Qmult_le_compat_l; auto.
+ + apply Riemann_sums_approximate_integral'.
+ destruct (lmu a w e) as [mu |] eqn:A3; [| easy].
+ subst N; unfold comp_inf in A2; rewrite A3 in A2.
+ change (step w n <= mu); unfold step.
+ rewrite Qmake_Qdiv, injZ_One; unfold Qdiv; rewrite Qmult_assoc, Qmult_1_r.
+ assert (A4 : 0 < mu) by (change (Qinf.lt 0 mu); rewrite <- A3;
+ apply (uc_pos (restrict f a w) (lmu a w)), (proj2_sig e)).
+ apply Qle_div_l; auto.
+ apply Z.Ple_Zle_to_pos, Q.Zle_Qle_Qceiling in A2.
+ apply (Qle_trans _ (1 / mu)); trivial. apply Qmult_le_compat_r; trivial.
+ now apply Qinv_le_0_compat, Qlt_le_weak.
Qed.
(** Unicity itself will of course have to be stated w.r.t. *two* integrals: *)
@@ -503,6 +551,7 @@ Pos2Nat.is_succ: ∀ p : positive, ∃ n : nat, Pos.to_nat p = S n*)
apply (Riemann_sums_approximate_integral a x ((1 # 2) * e / x)%Qpos t n H H0).
Qed.
*)
+
End integral_approximation.
(** If f==g, then an integral for f is an integral for g. *)
@@ -523,7 +572,11 @@ Proof with auto.
apply integral_wd...
Qed.
-Import abstract_algebra.
+Import canonical_names abstract_algebra.
+
+Local Open Scope mc_scope.
+
+Add Ring CR : (rings.stdlib_ring_theory CR).
Lemma mult_comm `{SemiRing R} : Commutative (.*.).
Proof. apply commonoid_commutative with (Aunit := one), _. Qed.
@@ -540,8 +593,6 @@ apply -> CRabs_cases; [| apply _ | apply _].
split; [trivial | apply (proj1 (rings.flip_nonpos_negate x))].
Qed.
-Add Ring CR_ring : (rings.stdlib_ring_theory CR).
-
Lemma cmΣ_empty {M : CMonoid} (f : nat -> M) : cmΣ 0 f = [0].
Proof. reflexivity. Qed.
@@ -557,6 +608,15 @@ induction n as [| n IH].
change (CRasCMonoid : Type) with (CR : Type). ring.
Qed.
+Lemma cmΣ_negate (n : nat) (f : nat -> CR) : cmΣ n (- f) = - cmΣ n f.
+Proof.
+induction n as [| n IH].
++ change ((0 : CR) = - 0). (* [change (0 = - 0)] loops *) ring.
++ rewrite !cmΣ_succ. rewrite IH.
+ change (- f n - cmΣ n f = - (f n + cmΣ n f)).
+ change (CRasCMonoid : Type) with (CR : Type). (* Why the last command? *) ring.
+Qed.
+
Lemma cmΣ_const (n : nat) (m : CR) : cmΣ n (λ _, m) = m * '(n : Q).
Proof.
induction n as [| n IH].
@@ -580,7 +640,15 @@ unfold riemann_sum. rewrite <- cmΣ_plus. apply cm_Sum_eq. intro k.
change (
cast Q CR (step w n) * (f (a + (k : Q) * step w n) + g (a + (k : Q) * step w n)) =
cast Q CR (step w n) * f (a + (k : Q) * step w n) + cast Q CR (step w n) * g (a + (k : Q) * step w n)).
-apply rings.plus_mult_distr_l.
+apply rings.plus_mult_distr_l. (* Without [change] unification fails, [apply:] loops *)
+Qed.
+
+Lemma riemann_sum_negate (f : Q -> CR) (a w : Q) (n : positive) :
+ riemann_sum (- f) a w n = - riemann_sum f a w n.
+Proof.
+unfold riemann_sum. rewrite <- cmΣ_negate. apply cm_Sum_eq. intro k.
+change ('step w n * (- f (a + (k : Q) * step w n)) = -('step w n * f (a + (k : Q) * step w n))).
+ring.
Qed.
Section RiemannSumBounds.
@@ -622,8 +690,6 @@ Section IntegralBound.
Context (f : Q -> CR) `{Integrable f}.
-Add Ring CR : (rings.stdlib_ring_theory CR).
-
Lemma scale_0_r (x : Q) : scale x 0 = 0.
Proof. rewrite <- CRmult_scale; change (cast Q CR x * 0 = 0); ring. Qed.
@@ -785,7 +851,7 @@ Proof. now rewrite rings.flip_negate, rings.negate_involutive. Qed.
End RingFacts.
-Import interfaces.orders orders.minmax.
+Import interfaces.orders orders.minmax theory.rings.
Lemma join_comm `{JoinSemiLatticeOrder L} : Commutative join.
Proof.
@@ -883,7 +949,7 @@ Proof. apply minus_eq_plus. rewrite rings.plus_comm. symmetry; apply int_add. Qe
Lemma int_zero_width (a : Q) : int a a = 0.
Proof. apply (plus_right_cancel (int a a)); rewrite rings.plus_0_l; apply int_add. Qed.
-Lemma int_negate (a b : Q) : int a b = - int b a.
+Lemma int_opposite (a b : Q) : int a b = - int b a.
Proof.
apply rings.equal_by_zero_sum. rewrite rings.negate_involutive, int_add. apply int_zero_width.
Qed.
@@ -917,16 +983,16 @@ apply rings.negate_plus_distr. (* does not work without unfold *)
Qed.*)
Lemma integrate_plus (f g : Q -> CR)
- `{!IsUniformlyContinuous f f_mu, !IsUniformlyContinuous g g_mu} (a : Q) (w : Qpos) :
+ `{!IsUniformlyContinuous f f_mu, !IsUniformlyContinuous g g_mu} (a : Q) (w : QnonNeg) :
∫ (f + g) a w = ∫ f a w + ∫ g a w.
Proof.
apply mspc_closed. intros e e_pos. (* Why is 0%Q? *)
mc_setoid_replace (0 + e) with e by ring.
assert (he_pos : 0 < e / 2) by solve_propholds.
assert (qe_pos : 0 < e / 4) by solve_propholds.
-destruct (Riemann_sums_approximate_integral'' f a w (mkQpos qe_pos)) as [Nf F].
-destruct (Riemann_sums_approximate_integral'' g a w (mkQpos qe_pos)) as [Ng G].
-destruct (Riemann_sums_approximate_integral'' (f + g) a w (mkQpos he_pos)) as [Ns S].
+destruct (integral_approximation f a w (mkQpos qe_pos)) as [Nf F].
+destruct (integral_approximation g a w (mkQpos qe_pos)) as [Ng G].
+destruct (integral_approximation (f + g) a w (mkQpos he_pos)) as [Ns S].
(* [Le positive] is not yet defined *)
set (n := Pos.max (Pos.max Nf Ng) Ns).
assert (Nf <= n)%positive by (transitivity (Pos.max Nf Ng); apply Pos.le_max_l).
@@ -939,40 +1005,34 @@ apply (mspc_triangle' (e / 2) (e / 2) (riemann_sum (f + g) a w n)); [field; disc
now apply mspc_ball_CRplus; [apply F | apply G].
Qed.
+Lemma integrate_negate (f : Q -> CR)
+ `{!IsUniformlyContinuous f f_mu} (a : Q) (w : QnonNeg) : ∫ (- f) a w = - ∫ f a w.
+Proof.
+apply mspc_closed. intros e e_pos.
+mc_setoid_replace (0 + e) with e by ring.
+assert (he_pos : 0 < e / 2) by solve_propholds.
+destruct (integral_approximation (- f) a w (mkQpos he_pos)) as [N1 F1].
+destruct (integral_approximation f a w (mkQpos he_pos)) as [N2 F2].
+set (n := Pos.max N1 N2).
+assert (N1 <= n)%positive by apply Pos.le_max_l.
+assert (N2 <= n)%positive by apply Pos.le_max_r.
+apply (mspc_triangle' (e / 2) (e / 2) (riemann_sum (- f) a w n)); [field; discriminate | |].
+* now apply mspc_symm, F1.
+* rewrite riemann_sum_negate. now apply mspc_ball_CRnegate, F2.
+Qed.
+
Lemma int_plus (f g : Q -> CR)
`{!IsUniformlyContinuous f f_mu, !IsUniformlyContinuous g g_mu} (a b : Q) :
int (f + g) a b = int f a b + int g a b.
Proof.
-destruct (trichotomy (<) a b) as [A | [A | A]].
-+ assert (L : a ≤ b) by solve_propholds.
- assert (P : 0 < b - a) by now apply rings.flip_pos_minus.
- unfold int; destruct (decide (a ≤ b)) as [B | B]; [clear L | elim (B L)].
- (* Bad because it mentions [int_obligation_1] *)
- setoid_replace ((b - a) ↾ int_obligation_1 a b B) with
- (QnonNeg.from_Qpos (mkQpos P)) using relation QnonNeg.eq by reflexivity.
- apply integrate_plus.
-+ change (Qeq a b) in A. rewrite A.
-
-
-
-intros A. apply ball_gball; simpl. apply gball_closed. intros e e_pos.
-setoid_replace (width * r + e)%Q with (e + width * r)%Q by apply Qplus_comm.
-destruct (Riemann_sums_approximate_integral'' f from width ((1#2) * mkQpos e_pos)%Qpos) as [Nf F].
-destruct (Riemann_sums_approximate_integral'' g from width ((1#2) * mkQpos e_pos)%Qpos) as [Ng G].
-set (n := Pos.max Nf Ng).
-assert (le_Nf_n : (Nf <= n)%positive) by apply Pos.le_max_l.
-assert (le_Ng_n : (Ng <= n)%positive) by apply Pos.le_max_r.
-specialize (F n le_Nf_n). specialize (G n le_Ng_n).
-apply gball_triangle with (b := riemann_sum (f + g) from width n).
-+ rewrite riemann_sum_plus. setoid_replace e with ((1#2) * e + (1#2) * e)%Q by ring.
- apply CRgball_plus; apply gball_sym; trivial.
-+ (* apply riemann_sum_bounds. diverges *)
- rewrite <- CRmult_Qmult. apply riemann_sum_bounds; [solve_propholds |].
- intros. apply ball_gball. apply A; trivial.
+unfold int; destruct (decide (a ≤ b)); rewrite integrate_plus; ring.
+Qed.
Lemma int_negate (f : Q -> CR) `{!IsUniformlyContinuous f f_mu} (a b : Q) :
int (- f) a b = - int f a b.
-Admitted.
+Proof.
+unfold int; destruct (decide (a ≤ b)); rewrite integrate_negate; reflexivity.
+Qed.
Lemma int_minus (f g : Q -> CR)
`{!IsUniformlyContinuous f f_mu, !IsUniformlyContinuous g g_mu} (a b : Q) :
From f1bd925d6a66ddb3297239b6008d3111950e758b Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Sun, 21 Apr 2013 01:56:45 +0400
Subject: [PATCH 086/110] Proved lemmas needed for computational example
---
ode/Picard.v | 57 +++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 47 insertions(+), 10 deletions(-)
diff --git a/ode/Picard.v b/ode/Picard.v
index eb6eadc1..a43d3902 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -330,40 +330,77 @@ constructor.
+ intros e x1 x2 e_pos B. change (ball e y0 y0). apply mspc_refl; solve_propholds.
Qed.
-(*Let emsc := _ : ExtMetricSpaceClass (UniformlyContinuous sx sy).
-Check _ : MetricSpaceClass (UniformlyContinuous sx sy).*)
-
Lemma ode_solution : let f := fp picard f0 in picard f = f.
Proof. apply banach_fixpoint. Qed.
End Picard.
+Import theory.rings orders.rings.
+
Section Computation.
Definition x0 : Q := 0.
Definition y0 : CR := 1.
Definition rx : QnonNeg := (1 # 2)%Qnn.
-Definition ry : QnonNeg := 2.
+Definition ry : QnonNeg := 1.
Notation sx := (sig (ball rx x0)).
Notation sy := (sig (ball ry y0)).
-Definition v (z : sx * sy) : CR := proj1_sig (snd z).
+Definition v (z : sx * sy) : CR := ` (snd z).
Definition M : Q := 2.
Definition mu_v (e : Q) : Qinf := e.
+Definition L : Q := 1.
Instance : Bounded v M.
-Admitted.
+Proof.
+intros [x [y H]]. unfold v; simpl. unfold M, ry, y0 in *.
+apply mspc_ball_CRabs, CRdistance_CRle in H. destruct H as [H1 H2].
+change (1 - 1 ≤ y) in H1. change (y ≤ 1 + 1) in H2. change (abs y ≤ 2).
+rewrite plus_negate_r in H1. apply CRabs_AbsSmall. split; [| assumption].
+change (-2 ≤ y). transitivity (0 : CR); [| easy]. rewrite <- negate_0.
+apply flip_le_negate; solve_propholds.
+Qed.
Instance : IsUniformlyContinuous v mu_v.
-Admitted.
+Proof.
+constructor.
+* now intros.
+* unfold mu_v. intros e z1 z2 e_pos H. now destruct H.
+Qed.
-Program Definition f0 : UniformlyContinuous sx sy :=
+Instance v_lip (x : sx) : IsLipschitz (λ y : sy, v (x, y)) L.
+Proof.
+constructor.
+* unfold L. solve_propholds.
+* intros y1 y2 e H. unfold L; rewrite mult_1_l. apply H.
+Qed.
+
+Lemma L_rx : L * rx < 1.
+Proof.
+unfold L, rx; simpl. rewrite mult_1_l. change (1 # 2 < 1)%Q. auto with qarith.
+Qed.
+
+Lemma rx_M : `rx * M ≤ ry.
+Proof.
+unfold rx, ry, M; simpl. rewrite Qmake_Qdiv. change (1 * / 2 * 2 <= 1)%Q.
+rewrite <- Qmult_assoc, Qmult_inv_l; [auto with qarith | discriminate].
+Qed.
+
+(*Program Definition f0' : UniformlyContinuous sx sy :=
Build_UniformlyContinuous (λ x, y0) _ _.
(* [Admit Obligations] causes uncaught exception *)
-Next Obligation. (*apply mspc_refl; Qauto_nonneg. Qed.*)
+Next Obligation. apply mspc_refl; Qauto_nonneg. Qed.
Next Obligation. exact Qinf.infinite. Defined.
-Next Obligation. admit. Qed.
+Next Obligation.
+constructor.
+* now intros.
+* intros e x1 x2 e_pos _. change (ball e y0 y0). apply mspc_refl. solve_propholds.
+Qed.*)
+
+Let f := fp (picard x0 y0 rx ry v rx_M) (f0 x0 y0 rx ry). ode_solution x0 y0 rx ry v L v_lip L_rx rx_M
+
+Let f0 := f0 x0 y0 rx ry.
Definition picard_iter (n : nat) := nat_iter n (picard x0 y0 rx ry v) f0.
From 79c6dc64d160a4d42a7e7974682d424db1a5a757 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Mon, 22 Apr 2013 04:36:26 +0400
Subject: [PATCH 087/110] Did computational experiments
---
ode/Picard.v | 76 ++++++++++++++++++++++++++++++++++------------------
1 file changed, 50 insertions(+), 26 deletions(-)
diff --git a/ode/Picard.v b/ode/Picard.v
index a43d3902..0a760924 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -217,7 +217,7 @@ Hypothesis v_lip : forall x : sx, IsLipschitz (λ y, v (x, y)) L.
Hypothesis L_rx : L * rx < 1.
-Hypothesis rx_ry : `rx * M ≤ ry.
+Context {rx_M : PropHolds (`rx * M ≤ ry)}.
Instance L_nonneg : PropHolds (0 ≤ L).
Proof.
@@ -227,9 +227,9 @@ Qed.
(* Needed to apply Banach fixpoint theorem, which requires a finite
distance between any two points *)
-Instance uc_msd : MetricSpaceDistance (UniformlyContinuous sx sy) := λ f1 f2, 2 * ry.
+Global Instance uc_msd : MetricSpaceDistance (UniformlyContinuous sx sy) := λ f1 f2, 2 * ry.
-Instance uc_msc : MetricSpaceClass (UniformlyContinuous sx sy).
+Global Instance uc_msc : MetricSpaceClass (UniformlyContinuous sx sy).
Proof.
intros f1 f2. unfold msd, uc_msd. intro x. apply (mspc_triangle' ry ry y0).
+ change (to_Q ry + to_Q ry = 2 * (to_Q ry)). ring.
@@ -286,7 +286,7 @@ transitivity ('(abs (x - x0) * M)).
rewrite (extend_inside _ _ _ _ A1). apply bounded.
+ apply CRle_Qle. change (abs (x - x0) * M ≤ ry). transitivity (`rx * M).
- now apply (orders.order_preserving (.* M)), mspc_ball_Qabs_flip.
- - apply rx_ry.
+ - apply rx_M.
Qed.
(*Require Import Integration.*)
@@ -294,11 +294,13 @@ Qed.
Definition picard (f : UniformlyContinuous sx sy) : UniformlyContinuous sx sy.
set (g := picard'' f).
set (h x := exist _ (g x) (picard_sy f x)).
-assert (C : IsUniformlyContinuous h (uc_mu g)) by admit.
-exact (Build_UniformlyContinuous _ _ C).
+assert (C : IsUniformlyContinuous h (uc_mu g)); [| exact (Build_UniformlyContinuous _ _ C)].
+constructor.
++ apply (uc_pos g), (uc_proof g).
++ intros e x1 x2 e_pos A. change (ball e (g x1) (g x2)). apply (uc_prf g (uc_mu g)); assumption.
Defined.
-Instance picard_contraction : IsContraction picard (L * rx).
+Global Instance picard_contraction : IsContraction picard (L * rx).
Proof.
constructor; [| exact L_rx].
constructor; [solve_propholds |].
@@ -344,7 +346,7 @@ Definition y0 : CR := 1.
Definition rx : QnonNeg := (1 # 2)%Qnn.
Definition ry : QnonNeg := 1.
-Notation sx := (sig (ball rx x0)).
+Notation sx := (sig (ball rx x0)). (* Why does Coq still print {x | ball rx x0 x} in full? *)
Notation sy := (sig (ball ry y0)).
Definition v (z : sx * sy) : CR := ` (snd z).
@@ -381,28 +383,47 @@ Proof.
unfold L, rx; simpl. rewrite mult_1_l. change (1 # 2 < 1)%Q. auto with qarith.
Qed.
-Lemma rx_M : `rx * M ≤ ry.
+Instance rx_M : PropHolds (`rx * M ≤ ry).
Proof.
unfold rx, ry, M; simpl. rewrite Qmake_Qdiv. change (1 * / 2 * 2 <= 1)%Q.
rewrite <- Qmult_assoc, Qmult_inv_l; [auto with qarith | discriminate].
Qed.
-(*Program Definition f0' : UniformlyContinuous sx sy :=
- Build_UniformlyContinuous (λ x, y0) _ _.
-(* [Admit Obligations] causes uncaught exception *)
-Next Obligation. apply mspc_refl; Qauto_nonneg. Qed.
-Next Obligation. exact Qinf.infinite. Defined.
-Next Obligation.
-constructor.
-* now intros.
-* intros e x1 x2 e_pos _. change (ball e y0 y0). apply mspc_refl. solve_propholds.
-Qed.*)
+(*Notation ucf := (UniformlyContinuous sx sy).
+
+Check _ : MetricSpaceBall ucf.
+Check _ : ExtMetricSpaceClass ucf. (* Why two colons? *)
+Check _ : MetricSpaceDistance ucf.
+Check _ : MetricSpaceClass ucf.
+Check _ : Limit ucf.*)
+(* [Check _ : IsContraction (picard x0 y0 rx ry v rx_M) (L * rx)] At this point this does not work *)
+(* The following is bad because it creates a proof different from
+picard_contraction. Therefore, ode_solution cannot be applied. *)
+(*
+Instance : IsContraction (picard x0 y0 rx ry v rx_M) (L * rx).
+Proof.
+apply picard_contraction.
+apply v_lip. (* Is this needed because there is an explicit argument before IsLipschitz in picard_contraction? *)
+apply L_rx.
+Qed.
-Let f := fp (picard x0 y0 rx ry v rx_M) (f0 x0 y0 rx ry). ode_solution x0 y0 rx ry v L v_lip L_rx rx_M
+Check _ : IsContraction (picard x0 y0 rx ry v rx_M) (L * rx).*)
-Let f0 := f0 x0 y0 rx ry.
+Let f := @fp _ _ _ _ _ _ (picard x0 y0 rx ry v) _ (picard_contraction x0 y0 rx ry v L v_lip L_rx) (f0 x0 y0 rx ry).
-Definition picard_iter (n : nat) := nat_iter n (picard x0 y0 rx ry v) f0.
+(* L_rx should also be declared implicit using Context and omitted from the list of arguments *)
+
+(* When [IsContraction (picard x0 y0 rx ry v rx_M) (L * rx)] did not work,
+the error message was 'Error: Cannot infer the implicit parameter H of
+fp. Could not find an instance for [MetricSpaceBall (UniformlyContinuous sx sy)]'.
+In fact, [MetricSpaceBall (UniformlyContinuous sx sy)] worked fine. *)
+
+(* f is indeed the fixpoint *)
+
+Theorem f_fixpoint : picard x0 y0 rx ry v f = f.
+Proof. apply ode_solution. Qed.
+
+Definition picard_iter (n : nat) := nat_iter n (picard x0 y0 rx ry v) (f0 x0 y0 rx ry).
Definition answer (n : positive) (r : CR) : Z :=
let m := (iter_pos n _ (Pmult 10) 1%positive) in
@@ -410,11 +431,14 @@ Definition answer (n : positive) (r : CR) : Z :=
Zdiv a b.
Program Definition half : sx := 1 # 2.
-Next Obligation. admit. Qed.
-
-Time Compute answer 2 (proj1_sig (picard_iter 2 half)).
-
+Next Obligation.
+apply mspc_ball_Qabs_flip. unfold x0. rewrite negate_0, plus_0_r.
+rewrite abs.abs_nonneg; [reflexivity |].
+change (0 <= 1 # 2)%Q. auto with qarith.
+Qed.
+Time Compute answer 2 (` (picard_iter 3 half)). (* 10 minutes *)
+Time Compute answer 1 (` (f half)). (* Too long *)
End Computation.
From 0a75d15c5b6b013526572b0e87d87cfb34e4d466 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Sun, 28 Apr 2013 23:37:28 +0400
Subject: [PATCH 088/110] Removed all admit's. Proved that Picard iterations
converge to the solution of an integral equation.
---
ode/AbstractIntegration.v | 1 -
ode/Picard.v | 140 ++++++++++----------------------------
2 files changed, 35 insertions(+), 106 deletions(-)
diff --git a/ode/AbstractIntegration.v b/ode/AbstractIntegration.v
index 7bfc7e65..cd4b9c41 100644
--- a/ode/AbstractIntegration.v
+++ b/ode/AbstractIntegration.v
@@ -1045,7 +1045,6 @@ Definition Qupper_bound (x : CR) := approximate x 1%Qpos + 1.
(* To be proved by lifting from Q.
Lemma CRabs_triang (x y z : CR) : x = y + z -> abs x ≤ abs y + abs z.
-Admitted.
*)
(* The section IntegralLipschitz is not used in the ODE solver through
diff --git a/ode/Picard.v b/ode/Picard.v
index 0a760924..751e45e9 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -83,23 +83,23 @@ Context (f : sig (ball r a) -> Y).
(* Since the following is a Program Definition, we could write [f (a - r)]
and prove the obligation [mspc_ball r a (a - r)]. However, this obligation
would depend on x and [H1 : x ≤ a - r] even though they are not used in the
-proof. So, if [H1 : x1 ≤ a - r] and [H2 : x2 ≤ a - r], then [extend x1] would reduce
-to [f ((a - r) ↾ extend_obligation_1 x1 H1)] and [extend x2] would reduce
-to [f ((a - r) ↾ extend_obligation_1 x2 H2)]. To apply mspc_refl, we would
-need to prove that these applications of f are equal, i.e., f is a morphism
-that does not depend on the second component of the pair. So instead we
-prove mspc_ball_edge_l and mspc_ball_edge_r, which don't depend on x. *)
+proof. So, if [H1 : x1 ≤ a - r] and [H2 : x2 ≤ a - r], then [extend x1]
+would reduce to [f ((a - r) ↾ extend_obligation_1 x1 H1)] and [extend x2]
+would reduce to [f ((a - r) ↾ extend_obligation_1 x2 H2)]. To apply
+mspc_refl (see [extend_uc] below), we would need to prove that these
+applications of f are equal, i.e., f is a morphism that does not depend on
+the second component of the pair. So instead we prove mspc_ball_edge_l and
+mspc_ball_edge_r, which don't depend on x. *)
Program Definition extend : Q -> Y :=
- λ x, if (decide (x ≤ a - r))
+ λ x, if (decide (x < a - r))
then f ((a - r) ↾ mspc_ball_edge_l)
- else if (decide (a + r ≤ x))
+ else if (decide (a + r < x))
then f ((a + r) ↾ mspc_ball_edge_r)
else f (x ↾ _).
Next Obligation.
-apply Qmetric.gball_Qabs, Q.Qabs_diff_Qle.
-apply orders.le_flip in H1; apply orders.le_flip in H2.
-split; trivial.
+apply mspc_ball_Qle.
+apply orders.not_lt_le_flip in H1. apply orders.not_lt_le_flip in H2. now split.
Qed.
(*
@@ -131,36 +131,44 @@ Qed.
*)
Global Instance extend_uc `{!IsUniformlyContinuous f mu_f} : IsUniformlyContinuous extend mu_f.
-Proof with (assumption || (apply orders.le_flip; assumption) || reflexivity).
+Proof with (solve_propholds || (apply orders.not_lt_le_flip; assumption) || reflexivity).
constructor; [apply (uc_pos f mu_f) |].
intros e x1 x2 e_pos A.
assert (a - to_Q r ≤ a + to_Q r) by
(destruct r; simpl; transitivity a;
[apply rings.nonneg_minus_compat | apply semirings.plus_le_compat_r]; (easy || reflexivity)).
unfold extend.
-destruct (decide (x1 ≤ a - to_Q r)); destruct (decide (x2 ≤ a - to_Q r)).
-* apply mspc_refl; solve_propholds.
-* destruct (decide (a + to_Q r ≤ x2)); apply (uc_prf f mu_f); trivial.
+destruct (decide (x1 < a - to_Q r)); destruct (decide (x2 < a - to_Q r)).
+* apply mspc_refl...
+* destruct (decide (a + to_Q r < x2)); apply (uc_prf f mu_f); trivial.
+ apply (nested_balls _ _ A)...
+ apply (nested_balls _ _ A)...
-* destruct (decide (a + to_Q r ≤ x1)); apply (uc_prf f mu_f); trivial.
+* destruct (decide (a + to_Q r < x1)); apply (uc_prf f mu_f); trivial.
+ apply mspc_symm; apply mspc_symm in A. apply (nested_balls _ _ A)...
+ apply mspc_symm; apply mspc_symm in A. apply (nested_balls _ _ A)...
-* destruct (decide (a + to_Q r ≤ x1)); destruct (decide (a + to_Q r ≤ x2));
+* destruct (decide (a + to_Q r < x1)); destruct (decide (a + to_Q r < x2));
apply (uc_prf f mu_f); trivial.
- + apply mspc_refl'. now apply Qinf_lt_le, (uc_pos f mu_f).
+ + apply mspc_refl'; now apply Qinf_lt_le, (uc_pos f mu_f).
+ apply mspc_symm; apply mspc_symm in A. apply (nested_balls _ _ A)...
+ apply (nested_balls _ _ A)...
Qed.
-Lemma extend_inside (x : Q) (A : ball r a x) : extend x = f (x ↾ A).
-Proof.
-Admitted.
-(*apply mspc_ball_Qabs in A.*)
-
-
End Extend.
+Lemma extend_inside `{ExtMetricSpaceClass Y} (a x : Q) (r : QnonNeg) :
+ ball r a x -> exists p : ball r a x, forall f : sig (ball r a) -> Y,
+ extend a r f x = f (x ↾ p).
+Proof.
+intros A. apply mspc_ball_Qle in A. destruct A as [A1 A2]. unfold extend.
+destruct (decide (x < a - to_Q r)) as [H1 | H1].
+(* [to_Q] is needed because otherwise [Negate QnonNeg] is unsatisfied.
+Backtick [`] is not enough because the goal is not simplified. *)
+* apply orders.lt_not_le_flip in H1; elim (H1 A1).
+* destruct (decide (a + to_Q r < x)) as [H2 | H2].
+ + apply orders.lt_not_le_flip in H2; elim (H2 A2).
+ + eexists; intro f; reflexivity.
+Qed.
+
Section Bounded.
Class Bounded {X : Type} (f : X -> CR) (M : Q) := bounded : forall x, abs (f x) ≤ 'M.
@@ -173,7 +181,7 @@ Global Instance extend_bounded {a : Q} {r : QnonNeg} (f : {x | ball r a x} -> CR
`{!Bounded f M} : Bounded (extend a r f) M.
Proof.
intro x. unfold extend.
-destruct (decide (x ≤ a - to_Q r)); [| destruct (decide (a + to_Q r ≤ x))]; apply bounded.
+destruct (decide (x < a - to_Q r)); [| destruct (decide (a + to_Q r < x))]; apply bounded.
Qed.
Lemma bounded_nonneg {X : Type} (f : X -> CR) `{!Bounded f M} `{NonEmpty X} :
@@ -282,8 +290,7 @@ transitivity ('(abs (x - x0) * M)).
intros t A.
assert (A1 : mspc_ball rx x0 t) by
(apply (mspc_ball_convex x0 x); [apply mspc_refl, (proj2_sig rx) | |]; trivial).
- (* [(extend_inside (A:= A1))]: "Wrong argument name: A" *)
- rewrite (extend_inside _ _ _ _ A1). apply bounded.
+ apply extend_inside in A1. destruct A1 as [p A1]. rewrite A1. apply bounded.
+ apply CRle_Qle. change (abs (x - x0) * M ≤ ry). transitivity (`rx * M).
- now apply (orders.order_preserving (.* M)), mspc_ball_Qabs_flip.
- apply rx_M.
@@ -312,7 +319,7 @@ rewrite <- int_minus. transitivity ('(abs (x - x0) * (L * e))).
intros x' B. assert (B1 : ball rx x0 x') by
(apply (mspc_ball_convex x0 x); [apply mspc_refl | |]; solve_propholds).
unfold plus, negate, ext_plus, ext_negate.
- rewrite !(extend_inside x0 rx _ x' B1).
+ apply extend_inside in B1. destruct B1 as [p B1]. rewrite !B1.
apply mspc_ball_CRabs. unfold diag, together, Datatypes.id, Basics.compose; simpl.
apply (lip_prf (λ y, v (_, y)) L), A.
+ apply CRle_Qle. mc_setoid_replace (L * rx * e) with ((to_Q rx) * (L * e)) by ring.
@@ -442,80 +449,3 @@ Time Compute answer 1 (` (f half)). (* Too long *)
End Computation.
-
-
-
-(*
-Require Import CRArith CRtrans CRconst Qmetric Utf8.
-Require Import ProductMetric CompleteProduct (*CPoly_Newton*).
-Require Import (*metric2.*)Classified.
-
-Notation "X × Y" := (ProductMS X Y) (at level 40).
-Notation "f >> g" := (Cbind_slow f ∘ g) (at level 50).
-Notation "x >>= f" := (Cbind_slow f x) (at level 50).
-Notation "( f , g )" := (together f g).
-
-Section ODE.
- Open Scope uc_scope.
-
- Variable v: (Q_as_MetricSpace × Q_as_MetricSpace) --> CR.
- Variable f: Q_as_MetricSpace --> CR.
-
- Definition vxfx := (v >> Couple ∘ (Cunit, f) ∘ diag _).
-End ODE.
-
-Section Picard_op.
- Definition k := (1#2).
- Variable f: Q_as_MetricSpace --> CR.
- Require SimpsonIntegration Qpossec.
-
- (* Picard operator, ∫ f, from 0 to t *)
- Definition Picard_raw (t:Q_as_MetricSpace) : CR :=
- let f' := uc_compose (scale k) f in
- (1 + (SimpsonIntegration.simpson_integral f' 1 0 (QabsQpos t)))%CR.
-
- Lemma Picard_uc: (is_UniformlyContinuousFunction Picard_raw (λ (ε:Qpos), ε)).
- admit.
- Qed.
-
- (* locally lipschitz *)
- Definition Picard := (Cbind QPrelengthSpace (Build_UniformlyContinuousFunction Picard_uc)).
-
-End Picard_op.
-
-Section Banach_iter.
- (* Iterate operator L, n times *)
- Variable L:CR-->CR.
- Fixpoint Picard_seq (n : nat) : Q_as_MetricSpace --> CR :=
- match n with
- | O => L ∘ Cunit
- | S m => (Picard (Picard_seq m) ) ∘ Cunit
- end.
-End Banach_iter.
-
-Section example.
-
-Definition g : CR --> CR := Cbind QPrelengthSpace (const_uc (1:Q_as_MetricSpace)).
-
-Definition picard (n:nat) := (Picard_seq g n).
-
-Definition eval (n:positive) (r:CR) : Z :=
- let m := (iter_pos n _ (Pmult 10) 1%positive) in
- let (a,b) := (approximate r (1#m)%Qpos)*m in
- Zdiv a b.
-
-Definition h := const_uc (5#7:Q_as_MetricSpace).
-Definition h' := uc_compose (scale (11#13)) h.
-
-Require Import Integration.
-Require Import SimpsonIntegration.
-
-Time Eval vm_compute in (eval 3 (1 + (Integrate h' 0 (1#2)))%CR).
-Time Eval vm_compute in (eval 3 (1 + (simpson_integral h' 1 0 (1#2)))%CR).
-
-Time Eval vm_compute in (eval 3 (Picard_raw (@const_uc Q_as_MetricSpace (1#1)) 1)).
-Time Eval vm_compute in (eval 3 (picard 1 1)).
-Time Eval vm_compute in (eval 2 (picard 2 1)).
-
-End example.
-*)
From cc2a62e70db0911dd0e02cf3d2f3af89d42d5f02 Mon Sep 17 00:00:00 2001
From: Evgeny Makarov
Date: Fri, 10 May 2013 13:21:52 +0400
Subject: [PATCH 089/110] Commented out computations that take too long in
Picard.v
---
ode/FromMetric2.v | 1 +
ode/Picard.v | 2 ++
2 files changed, 3 insertions(+)
diff --git a/ode/FromMetric2.v b/ode/FromMetric2.v
index 0a6461e4..f098bba8 100644
--- a/ode/FromMetric2.v
+++ b/ode/FromMetric2.v
@@ -129,6 +129,7 @@ Add Ring CR : (stdlib_ring_theory CR).
Close Scope CR_scope.
Unset Printing Coercions.
+(* Uniformly continuous functions respect equality (see metric2.UniformContinuity.v) *)
Global Instance CRabs_proper : Proper (equiv ==> equiv) (abs (A := CR)).
Proof. change abs with (@ucFun CR CR CRabs); apply _. Qed.
diff --git a/ode/Picard.v b/ode/Picard.v
index 751e45e9..3d971867 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -444,8 +444,10 @@ rewrite abs.abs_nonneg; [reflexivity |].
change (0 <= 1 # 2)%Q. auto with qarith.
Qed.
+(*
Time Compute answer 2 (` (picard_iter 3 half)). (* 10 minutes *)
Time Compute answer 1 (` (f half)). (* Too long *)
+*)
End Computation.
From 27a36b2c1a9ce69af035d55829bf05f4301ce3f6 Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Mon, 1 Jul 2013 11:55:04 +0200
Subject: [PATCH 090/110] merging
---
math-classes | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/math-classes b/math-classes
index eb03507e..57a8b2d4 160000
--- a/math-classes
+++ b/math-classes
@@ -1 +1 @@
-Subproject commit eb03507e225d0e4381bf670b6ceecdbf71da3981
+Subproject commit 57a8b2d4f79c1bd15166e912f62c3dc16756f462
From 6177545d50e87d5794b748aa4313c32a1132225d Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Thu, 3 Apr 2014 14:23:36 +0200
Subject: [PATCH 091/110] Updating the math-classes submodule
---
.gitmodules | 3 ++-
README | 4 ++--
math-classes | 2 +-
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/.gitmodules b/.gitmodules
index 8d0e97bb..342bd5fd 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,4 @@
[submodule "math-classes"]
path = math-classes
- url = git://github.com/EvgenyMakarov/math-classes.git
+# url = git://github.com/EvgenyMakarov/math-classes.git
+ url = git://github.com/math-classes/math-classes.git
diff --git a/README b/README
index 83b6db2a..6b3f4f8a 100644
--- a/README
+++ b/README
@@ -6,7 +6,7 @@ PREREQUISITES
This version of C-CoRN is known to compile with:
- - Coq 8.4pl1
+ - Coq 8.4pl4
- SCons 1.2
@@ -19,7 +19,7 @@ Math Classes is contained in the C-CoRN git repository as a submodule. You can
obtain math-classes automatically by giving the --recursive option when you
clone the git repository:
- git clone --recursive https://github.com/EvgenyMakarov/corn.git
+ git clone --recursive https://github.com/c-corn/corn.git
If you have already cloned the CoRN repository without --recursive, you can
still get the submodules with
diff --git a/math-classes b/math-classes
index 57a8b2d4..ec6d10d9 160000
--- a/math-classes
+++ b/math-classes
@@ -1 +1 @@
-Subproject commit 57a8b2d4f79c1bd15166e912f62c3dc16756f462
+Subproject commit ec6d10d98c432a8fbf9c251647c8dae17de14f62
From d82c44138f38fc241a4f6319926ac43b67621326 Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Thu, 3 Apr 2014 16:19:42 +0200
Subject: [PATCH 092/110] Now works ith 8.4pl4
---
ode/metric.v | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ode/metric.v b/ode/metric.v
index 252a1edd..ba5903b2 100644
--- a/ode/metric.v
+++ b/ode/metric.v
@@ -13,7 +13,7 @@ Import peano_naturals.
Require Import CRGeometricSum.
Import Qround Qpower Qinf.notations.
-Set Printing Coercions.
+(* Set Printing Coercions.*)
Definition ext_plus {A} `{Plus B} : Plus (A -> B) := λ f g x, f x + g x.
Hint Extern 10 (Plus (_ -> _)) => apply @ext_plus : typeclass_instances.
@@ -492,7 +492,7 @@ Lemma lip_modulus_pos (L e : Q) : 0 ≤ L -> 0 < e -> 0 < lip_modulus L e.
Proof.
intros L_nonneg e_pos. unfold lip_modulus.
destruct (decide (L = 0)) as [A1 | A1]; [apply I |].
-apply neq_symm in A1.
+apply not_symmetry in A1.
change (0 < e / L). (* Changes from Qinf, which is not declared as ordered ring, to Q *)
assert (0 < L) by now apply QOrder.le_neq_lt. Qauto_pos.
Qed.
From abc13954354ffbf3207594eff66eaba2b4673f7c Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Fri, 4 Apr 2014 18:31:09 +0200
Subject: [PATCH 093/110] Updating description
---
description | 47 ++++++++++++++++++++++++++---------------------
1 file changed, 26 insertions(+), 21 deletions(-)
diff --git a/description b/description
index a3496154..5aa89f78 100644
--- a/description
+++ b/description
@@ -1,39 +1,35 @@
Name: CoRN
-Title: Constructive Coq Repository at Nijmegen
-Author: Herman Geuvers
-Institution: Radboud University Nijmegen
+Title: Coq Repository at Nijmegen
+
+Author: Evgeny Makarov
+Author: Robbert Krebbers
+Author: Eelis van der Weegen
+Author: Bas Spitters
+Author: Jelle Herold
+Author: Russell O'Connor
+Author: Cezary Kaliszyk
+Author: Dan Synek
Author: Luís Cruz-Filipe
-Institution: Radboud University Nijmegen
Author: Milad Niqui
-Institution: Radboud University Nijmegen
+Author: Iris Loeb
+Author: Herman Geuvers
+Author: Randy Pollack
Author: Freek Wiedijk
-Institution: Radboud University Nijmegen
Author: Jan Zwanenburg
-Institution: Radboud University Nijmegen
-Author: Randy Pollack
+Author: Dimitri Hendriks
Author: Henk Barendregt
-Institution: Radboud University Nijmegen
Author: Mariusz Giero
Author: Rik van Ginneken
-Institution: Radboud University Nijmegen
Author: Dimitri Hendriks
Author: Sébastien Hinderer
Author: Bart Kirkels
Author: Pierre Letouzey
-Author: Iris Loeb
-Institution: Radboud University Nijmegen
Author: Lionel Mamane
-Author: Russell O'Connor
-Institution: Radboud University Nijmegen
-Author: Nickolay V. Shmyrev
-Author: Bas Spitters
-Institution: Radboud University Nijmegen
-Author: Dan Synek
+Author: Nickolay Shmyrev
Institution: Radboud University Nijmegen
+
Description:
- The Constructive Coq Repository at Nijmegen, C-CoRN, aims at building
- a computer based library of constructive mathematics, formalized in
- the theorem prover Coq. It includes the following parts:
+ The Coq Repository at Nijmegen, CoRN, includes the following parts:
* Algebraic Hierarchy
@@ -58,8 +54,17 @@ Description:
including continuity, differentiability, integration,
Taylor's theorem and the Fundamental Theorem of Calculus
+* Exact Real Computation
+ o Fast verified computation inside Coq. This includes: real numbers, functions,
+ integrals, graphs of functions, differential equations.
+
+CoRN depends on the math-classes contribution. This mostly replaces the old algebraic hierarchy.
+
+The author list is roughly in anti-chronological order.
+
URL: http://c-corn.cs.ru.nl
Keywords: constructive mathematics, algebra, real calculus, real numbers,
Fundamental Theorem of Algebra
Category: Mathematics/Algebra
Category: Mathematics/Real Calculus and Topology
+Category: Mathematics/Exact Real computation
From 1d0c7c02631849e7e1704adb35a2f46481a937c8 Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Fri, 23 May 2014 14:38:19 +0200
Subject: [PATCH 094/110] Small changes in example
---
examples/RealFaster.v | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/examples/RealFaster.v b/examples/RealFaster.v
index 83365bdf..2e8f4b88 100644
--- a/examples/RealFaster.v
+++ b/examples/RealFaster.v
@@ -14,21 +14,32 @@ Definition answer (n : positive) (r : ARQ) : Z :=
let m := (iter_pos n _ (Pmult 10) 1%positive) in
let (a,b) := (approximate r (1#m)%Qpos)*m in
Zdiv a b.
-
+*)
Definition answer (n : positive) (r : ARbigD) : bigZ :=
let m := iter_pos n _ (Pmult 10) 1%positive in
let (a, b) := (approximate r (1#m)%Qpos : bigD) * 'Zpos m in
BigZ.shiftl a b.
-*)
-Definition answer (n : positive) (r : myAR) :=
- let m := iter_pos n _ (Pmult 10) 1%positive in let _ := approximate r (1#m)%Qpos in tt.
+(* To avoid timing the printing mechanism *)
+Definition no_answer (n : positive) (r : myAR) :=
+ let m := iter_pos n _ (Pmult 10) 1%positive in let _ :=
+ approximate r (1#m)%Qpos in tt.
+
+(* xkcd.org/217 *)
+Definition xkcd : myAR := (ARexp ARpi)-ARpi.
+
+Time Eval vm_compute in (answer 10 xkcd).
+
+Example xkcd217A : ARltT xkcd ('20%Z).
+Proof. Time AR_solve_ltT (-8)%Z. Defined.
(* Many of the following expressions are taken from the "Many Digits friendly competition" problem set *)
-Definition P01 : myAR := ARsin (ARsin (AQsin 1)).
-Time Eval vm_compute in (answer 500 P01).
+(* Instance resolution takes 3s *)
+Time Definition P01 : myAR := ARsin (ARsin (AQsin 1)).
+Time Eval vm_compute in (answer 500 P01).
+Time Eval vm_compute in (no_answer 500 P01).
Definition P02 : myAR := ARsqrt (ARcompress ARpi).
Time Eval vm_compute in (answer 500 P02).
@@ -76,7 +87,4 @@ Definition ARtest3 : myAR := ARsqrt 2.
Time Eval vm_compute in (answer 1000 ARtest3).
Definition ARtest4 : myAR := ARsin ARpi.
-Time Eval vm_compute in (answer 500 ARtest4).
-
-Example xkcd217A : ARltT ARtest4 ('20%Z).
-Proof. Time AR_solve_ltT (-8)%Z. Defined.
+Time Eval vm_compute in (answer 500 ARtest4).
\ No newline at end of file
From 4d76587ae720f587bc3d452feea4e7355f1f0aac Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Mon, 2 Jun 2014 18:31:46 +0200
Subject: [PATCH 095/110] Removing html files here, as they are now on:
https://github.com/c-corn/c-corn.github.com
---
doc/www/download.html | 61 ------------
doc/www/history.html | 176 ----------------------------------
doc/www/index.html | 118 -----------------------
doc/www/info.html | 35 -------
doc/www/lib.html | 56 -----------
doc/www/library/alghier.html | 18 ----
doc/www/library/fastreal.html | 47 ---------
doc/www/library/fta.html | 60 ------------
doc/www/library/metric2.html | 47 ---------
doc/www/library/model.html | 67 -------------
doc/www/library/realcalc.html | 68 -------------
doc/www/people.html | 38 --------
doc/www/pub.html | 103 --------------------
13 files changed, 894 deletions(-)
delete mode 100644 doc/www/download.html
delete mode 100644 doc/www/history.html
delete mode 100644 doc/www/index.html
delete mode 100644 doc/www/info.html
delete mode 100644 doc/www/lib.html
delete mode 100644 doc/www/library/alghier.html
delete mode 100644 doc/www/library/fastreal.html
delete mode 100644 doc/www/library/fta.html
delete mode 100644 doc/www/library/metric2.html
delete mode 100644 doc/www/library/model.html
delete mode 100644 doc/www/library/realcalc.html
delete mode 100644 doc/www/people.html
delete mode 100644 doc/www/pub.html
diff --git a/doc/www/download.html b/doc/www/download.html
deleted file mode 100644
index d437819e..00000000
--- a/doc/www/download.html
+++ /dev/null
@@ -1,61 +0,0 @@
-
-
-C-CoRN -- Download
-
-
-
-
-Downloads
-Tarballs
-You can download the total formalization or just specific parts of it.
-
-
-To download the full system, just click on the first link. The partial distributions should be self-contained, e.g. you do not need to download Core in order to use Algebraic Hierarchy. After you untar the files (which will create a CoRN/ directory at the place of installation) you will find a.o. a README file which contains more detailed instructions on how to proceed. It is (unfortunately) quite likely that all will not go well, especially if you only download parts of C-CoRN; if this happens, please contact me.
-
-
-Bleeding Edge and Contributors
-
- You can also use Git to get the latest development of CoRN and its recent development history by cloning our repository:
-
-git clone http://www.fnds.cs.ru.nl/git/CoRN.git
-
-This is particularly recommended if
-
- - You want to contribute back improvements to CoRN. (In this
- case, you will probably want to fork CoRN into your own
- repository and ask us to merge from you when your contribution
- is mature.)
- - You are in a tremendous hurry and don't want to wait for the
- above tarballs to be regenerated.
-
- We currently have the following archives and branches for CoRN of
- general interest:
-
- The following archives and branches for CoRN of historical interest and are no longer maintained.
-
- - coq-8.0
-
This is the last version of CoRN that was compatible coq 8.0.
-
-
-
-
-
diff --git a/doc/www/history.html b/doc/www/history.html
deleted file mode 100644
index bb8f6e66..00000000
--- a/doc/www/history.html
+++ /dev/null
@@ -1,176 +0,0 @@
-
-
-C-CoRN -- History
-
-
-
-
-History
-
-The C-CoRN repository grew out of the
-FTA project, where
-a constructive proof of the Fundamental Theorem of Algebra was formalized in Coq. This
-theorem states that every non-constant polynomial f over the complex
-numbers has a root, i.e. there is a complex number z such that f(z) = 0.
-The FTA project was performed by Herman Geuvers, Freek Wiedijk, Jan
-Zwanenburg, Randy Pollack, Milad Niqui, and Henk Barendregt. The
-motivations for starting this project were the following
-
-- Formalize a large piece of real mathematics. See whether it can be done and which
- problems arise.
-
- Create a library for basic constructive algebra and analysis, to
-be used by others. Often, a formalization is only used by the person
-that created it (or is not used further at all!), whereas one of the
-goals of formalizing mathematics is to create a joint repository of
-mathematics.
-
- Investigate the current limitations of theorem provers, notably
-Coq, and the type theoretic approach towards theorem proving.
-
- Manage this project. Work with a group of people on one
-theory/proof-development. Initially, the following three sequential/parallel
-phases were distinguished:
-
-- Mathematical proof: LaTeX document (the mathematical proof with
-lots of details filled in)
-
-
- Theory development: Coq file (just definitions and statements of
-lemmas)
-
- Proof development: Coq file (formal proofs filled in)
-
-
-The goal is to keep these phases consistent, so the theory/proof
-development process proceeds in a ``literate programming'' style: by
-working (in parallel) on three documents, one creates a complete
-formal development of FTA, together with a documentation, which
-consists of the LaTeX document (the high level specification) and the
-theory development (the low level specification, containing all the
-precise definitions and names of lemmas etc.) It is not trivial to
-keep these phases consistent (and in fact in FTA this consistency has
-not been maintained till the end): a lemma in the LaTeX version may
-be just wrong, a definition may be incomplete or the `basic
-properties' that one thinks one needs (say about fields) are just not
-the ones that one really needs.
-
- - Constructive proof. We view a
-real number as a (potentially) infinite object. So the equality on
-them is undecidable and one can not define functions by cases. A good
-thing is that we are actually proving the correctness of a
-root-finding algorithm. Details of the proof can be found in
-{GeuversWiedijkZwanenburg-TYPES-2001}.
-
-
-The proof did not proceed by constructing the reals in Coq, but by axiomatic
-reasoning. So the axioms of the real numbers were defined in
-Coq. As a matter of fact, we have proceeded even more generally by
-first defining an algebraic hierarchy (semi-groups, monoids, groups,
-rings, fields, ordered fields); see
-{GeuversPollackWiedijkZwanenburg-JSC-2002}. The advantages of this
-approach are: reuse of proven results and reuse of notation. (The
-reals and complex numbers are fields and the polynomials form a ring.)
-Then IR was defined to be an (arbitrary) Cauchy-complete
-Archimedean ordered field. Given such an IR, the complex numbers can be
-defined by CC := IR x IR. To make sure that the axioms for IR make
-sense, a concrete instantiation for IR has been constructed by Niqui.
-
-Completely formalized in the theorem prover Coq, the proof and theory
-development amounts to the following. This is the size of the input files (definitions,
-lemmas, tactic scripts)
-
-- Sets and Basics 41 kb
-
- Algebra (up to Ordered Fields) 165 kb
-
- Reals 52 kb
-
- Polynomials 113 kb
-
- Real-valued functions / Basic Analysis 30 kb
-
- Complex numbers 98 kb
-
- FTA proof 70 kb
-
- Construction of IR 309 kb
-
- Rational Tactic 49 kb
-
-
-To modularize the proof and in order to create a real ``library'', we
-have first defined an algebraic hierarchy in the FTA project. In
-proving FTA, we have to deal with real numbers, complex numbers and
-polynomials and many of the properties we use are generic and
-algebraic. To be able to reuse results (also for future developments)
-we have defined a hierarchy of algebraic structures. The basic level
-consists of constructive setoids, (A, #, =), with
-A: Set, # an apartness and = an equivalence
-relation. (Classically, apartness is just the negation of equality,
-but constructively, apartness is more `primitive' than equality and
-equality is usually defined as the negation of apartness. To
-understand this, think of two reals x and y as (infinite) Cauchy
-sequences: we may determine in a finite amount of time whether x # y,
-but we can in general never know in a finite amount of time that
-x=y.)
-On the next level we have semi-groups, (S, +), with S a
-setoid and + an associative binary operation on S.
-
-Inside the algebraic hierarchy we have `inheritance via coercions'.
-We have the following coercions.
-
-OrdField >-> Field >-> Ring >-> Group
- Group >-> Monoid >-> Semi_grp >-> Setoid
-
-This means that
-all properties of groups are inherited by rings,
-fields, etc.
-Also notation is inherited:
-x[+]y
-denotes the addition of x and y for x,y:G from any semi-group (or monoid, group, ring,...) G.
-The coercions must form a tree, so there is no real
-multiple inheritance,
-e.g. it is not
-possible to define rings in such a way that it inherits both from its
-additive group and its multiplicative monoid.
-
-In the proof of FTA we needed
-proofs of equalities between rational expressions.
-These were automatized using so called `partial reflection'.
-
-The axioms for real numbers are (apart from the fact that the reals
-form a constructive ordered field)
-
-- All Cauchy sequences have a limit:
-SeqLim : {g: nat ->F | Cauchy(g)} -> F
-CauchyProp: forall g: nat->F. Cauchy(g) -> forall e: F{>0}. exists N: nat.forall m>= N.(|g_m - SeqLim(g)|
-- Axiom of Archimedes: (there are no non-standard elements)
-forall x: F. exists n: nat (n>x)
-
-
-The axiom of Archimedes proves that `epsilon-Cauchy sequences' and
-`1/k-Cauchy sequences' coincide (and similar for limits).
-Viz: g:nat->F is a 1/k-Cauchy sequence if
-forall k: nat. \exists N:nat.forall m\geq N(|g_m - g_N|
-<1/k
-
-
-To be sure that our axioms can be satisfied, we have also constructed
-a Real Number Structure via the standard technique of taking the Cauchy
-sequences of rational numbers and defining an appropriate apartness on
-them. It turns out (as was to be expected) that real number structures
-are categorical: Any two real number structures are isomorphic. This
-fact has been proved within Coq.
-
-In conclusion we have found:
-
-- Real mathematics, involving both a
-bit of algebra and a bit of analysis can be formalized completely
-within a theorem prover (Coq).
-
- Setting up a basic library and some
-good proof automation procedures is a substantial part of the work.
-
- An important issue remains how to present the development (and the
-proof). In the formalization process, the connection with the LaTeX
-file has been abandoned. We believe that it is essential to provide a
-system in which one can write the formalization and the documentation
-in one file.
-
- Work is in progress regarding the extraction of the algorithm implicit
-in the proof. This has turned out to be far from trivial, and has provided
-important insight in issues such as how the sorts of Coq should be used.
-
-See the publications page for more information.
-
-
-
-
diff --git a/doc/www/index.html b/doc/www/index.html
deleted file mode 100644
index 436e51e2..00000000
--- a/doc/www/index.html
+++ /dev/null
@@ -1,118 +0,0 @@
-
-
-C-CoRN
-
-
-
-
-Constructive Coq Repository at Nijmegen
-
-
-
-
-The Constructive Coq Repository at Nijmegen, C-CoRN, aims at building
-a computer based library of constructive mathematics, formalized in
-the theorem prover Coq.
-
-
-Background There is a lot of mathematical knowledge. This
-knowledge is mainly stored in books and in the heads of mathematicians
-and other scientists. Putting this knowledge in the right form on a
-computer, the mathematics should be more readily available to be used
-by others (either humans or other computer applications). C-CoRN aims
-at being a starting point and a test-bed for this: we put mathematics
-on a computer in an active (formalized) way to see how one can
-interact with it (consult, use, extend) and how to manage it
-(document, update, keep consistent). The reason for working
-constructively is partly historical,
-partly practical (because we wanted to use Coq, which is a
-constructive theorem prover), but mainly because constructive
-mathematics has the additional bonus of providing (actual, executable)
-algorithms for the functions that we prove to exist. C-CoRN grew out
-of the FTA project, formalizing the Fundamental Theorem of
-Algebra. (See the history page
-for an overview and links.) The repository is developed and maintained
-by the Foundations Group of
-the NIII (Computer Science Department) of the University of Nijmegen,
-but everybody is cordially invited to participate in its further
-development.
-
-
-Why Computer formalized mathematics has a high potential: a
-good computer-representation of mathematics will enable the following.
-
-- Browsing and searching libraries of
-mathematics in an easy way, (so it should both be readable, like a
-mathematics book and searchable like a database),
-
- Using the stored mathematics, e.g. by computing
-with it or proving with it (so it should be possible to actively use
-the mathematics in a computer algebra system or a theorem prover),
-
- Extending the corpus of mathematics. For example by
-extending the formalized theory or by adding an illuminating example.
-Extending should be as easy as writing it up in, say, LaTeX.
-
-
-An important condition for opening up these potential advantages of
-formalized mathematics is having an extensive formalized library of
-(basic) results. C-CoRN aims at being such a library. In the context
-of our work, this library serves several purposes.
-
-- A library for (basic) constructive results, say in algebra and
-analysis should be usable by others. Often, a formalization is only
-used by the person that created it (or is not used further at
-all!). We want C-CoRN explicitly to be used and extended by people
-from our group, but also by interested outsiders. This requires a
-certain way of working when doing a formalization, but it also
-requires a certain managerial structure (CVS etc.). Join our
- our discussion Mailing List.
-
-
- A library should be presented, both to its readers and to its
-users. The `readers' may just be interested in the mathematical line
-of thought, on a relatively high level, whereas the `users' will want
-to know the formalization details on a much lower level. So there is
-not just one good presentation, but presentation is vital for C-CoRN,
-given the huge amount of data. The Helm project provides interesting
-tools for presenting formalized mathematics on the web. To be able to
-present a theory/proof development, the files have to be
-documented. Therefore also documenting the repository is a
-focal point.
-
-
- Extending the library can be done with the existing tools for Coq
-(Proof General, PCoq). To attract mathematical users, a more
-mathematical input language (corresponding to a `mathematical
-vernacular') would be desirable. The repository can act as a test-bed
-for new interfaces.
-
-
- Building up a real library of real mathematics faces us with the
-current limitations of theorem provers, notably Coq. This concerns
-not only tactics for enhancing the proving process, but also more fundamental
-issues like the use of records, modules and coercions.
-
-
- Manage a big library of mathematics. At present, only Mizar has a really big library of
-formalized mathematics. Mizar is not distributed, and so isn't
-C-CoRN. Having a distributed library may be useful in the future.
-
-
-
-
-
-What We formalize constructive mathematics in Coq. See the library for an overview. Currently we have: a
-Constructive Algebraic Hierarchy (up to the reals), a theory of Metric Spaces and Compact Subsets of complete metric spaces, an Effective Model of the Real Numbers, a proof of the Fundamental Theorem of Algebra and the Fundamental Theorem of Calculus, and the ability to generate plots of uniformly continuous functions.
-
-
-
-Who See the people page to see who
-has contributed to C-CoRN.
-
-
-
-
-
-
diff --git a/doc/www/info.html b/doc/www/info.html
deleted file mode 100644
index 102eb69d..00000000
--- a/doc/www/info.html
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
-C-CoRN -- Contacts
-
-
-
-
-Contact Information
-For general information, questions, suggestions or problems,
- you can contact us on
- our discussion Mailing List.
-For specific information on each of the formalized topics, please contact directly
- the person responsible for it:
-
-
- Feel free to subscribe to the
- Mailing List!
-
-
-
-
diff --git a/doc/www/lib.html b/doc/www/lib.html
deleted file mode 100644
index eb8f3a98..00000000
--- a/doc/www/lib.html
+++ /dev/null
@@ -1,56 +0,0 @@
-
-
-C-CoRN -- Library
-
-
-
-
-Library
-The library includes the following parts:
-
- - Algebraic Hierarchy
-
- - An axiomatic formalization of the most common algebraic structures,
- including setoids, monoids, groups, rings, fields, ordered fields, rings
- of polynomials, real and complex numbers
-
-
-
- - Model of the Real Numbers
-
- - Construction of a concrete real number structure satisfying the previously
- defined axioms
-
-
- - Fundamental Theorem of Algebra
-
- - A proof that every non-constant polynomial on the complex plane has
- at least one root
-
-
- - Real Calculus
-
- - A collection of elementary results on real analysis, including continuity,
- differentiability, integration, Taylor's theorem and the Fundamental Theorem
- of Calculus
-
-
- - Metric Spaces
-
- - A theory of metric spaces. Includes product metrics,
- complete metrics, finite enumeration, compact sets.
-
-
- - Effective Real Numbers
-
- - An effective implementation of real numbers for computing within Coq.
-
-
-
-
-
-
-
diff --git a/doc/www/library/alghier.html b/doc/www/library/alghier.html
deleted file mode 100644
index 75b8aade..00000000
--- a/doc/www/library/alghier.html
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-C-CoRN -- Libraries
-
-
-
-
-The Algebraic Hierarchy
-Description: a detailed description [to be written by someone]
-References: bibliographic references (if applicable) [to be written
- by someone]
-Maintainer: Russell O’Connor
-Developers: Henk Barendregt, Luís Cruz-Filipe, Herman Geuvers,
- Milad Niqui, Randy Pollack, Freek Wiedijk, Jan Zwanenburg
-Documentation
-Download
-
-
diff --git a/doc/www/library/fastreal.html b/doc/www/library/fastreal.html
deleted file mode 100644
index fabf6471..00000000
--- a/doc/www/library/fastreal.html
+++ /dev/null
@@ -1,47 +0,0 @@
-
-
-
- C-CoRN -- Computable Real Numbers
-
-
-
-
-
-Metric Spaces
-
-Description: This library provides a model of the real numbers, CR, that is suitable for computing with inside Coq. Also included is a rasterization library for computing plots of uniformly continuous functions.
- The formalization includes:
-
-
- - field operations, abs, sin, cos, exp, square root, ln, arctan for CR.
- - integration of uniformly continuous functions on [0,1]
- - proofs that these operations are equivalent to the ones on IR.
- - a tactic,
IR_solve_ineq, for automatically strict inequalities over IR that are closed expressions.
- - a function,
PlotQ for creating plots of uniformly continuous functions
-
-
-
-References:
-
-
- - Russell O’Connor. "A monadic, functional implementation of real numbers", Mathematical. Structures in Comp. Sci., 17(1):129–159, 2007.
-
-
- Russell O’Connor. "Certified exact transcendental real number computation in Coq". In Theorem Proving in Higher Order Logics, 21st International Conference, TPHOLs 2008, LNCS. Springer-Verlag, 2008. to appear.
-
-
- Russell O’Connor. "A Computer Verified Theory of Compact Sets". to appear.
-
-
-
-
-
-Maintainer: Russell O’Connor
-
-Developers: Russell O’Connor
-
-Documentation
-
-Download
-
-
-
diff --git a/doc/www/library/fta.html b/doc/www/library/fta.html
deleted file mode 100644
index f48ce7b3..00000000
--- a/doc/www/library/fta.html
+++ /dev/null
@@ -1,60 +0,0 @@
-
-
-C-CoRN -- Libraries
-
-
-
-
-The Fundamental Theorem of Algebra
-
-Description: This library contains the constructive proof of
-the Fundamental Theorem of Algebra, along the lines of the proof of
-Kneser, which originally appeared in Kneser?? (but see also TvD?? for
-a presentation). We have adapted (improved and made more precise, as
-we would view it) the proof quite a bit; an account of the formalised
-mathematical proof is presented in GeuWieZwa??. This library rests on
-the algebraic hierarchy, which defines all the basic concepts, like
-the reals, the complex numbers, polynomials etc. The FTA library
-contains more specific operations on and properties of the reals, the
-complex numbers and polynomials, required for the FTA
-proof. Furthermore it contains the Kneser proof, devided in 4 stages.
-
-
- - results about preservation of continuity through algebraic operations;
- - the usual rules for derivation; - formalization of power series and
-Taylor series;
- - several formulations of Rolle's Theorem, the Mean Law, convergence
-theorems and error estimates for Taylor series;
- - the Key Lemma and the Main Lemma, stating results about
-(finite sequences of) reals, specifically needed for FTA. (These
-are more or less implicit in the original proof of Kneser);
- - the Kneser Lemma
- - FTA for regular polynomials (i.e. where we know that the leading coefficient is 1);
- - FTA for arbitrary non-constant polynomials.
-
-
-
-References:
-
-
- - For the mathematical content:
-
- - Bishop, E., "Foundations of Constructive Analysis", McGraw-Hill Book
-Company, 1967
-
- - About the formalization itself:
-
- - Cruz-Filipe, L., "Formalizing Real Calculus in Coq", in Theorem
-Proving in Higher Order Logics , Carreño, V., Muñoz, C. and
-Tahar, S. (eds.), NASA Conference Proceedings, Hampton VA, 2002 (ps, pdf)
-
-
-
-Maintainer: Freek Wiedijk
-Developers: Henk Barendregt, Herman Geuvers, Randy Pollack, Jan Zwanenburg
-Documentation
-Download
-
-
diff --git a/doc/www/library/metric2.html b/doc/www/library/metric2.html
deleted file mode 100644
index a0f21fca..00000000
--- a/doc/www/library/metric2.html
+++ /dev/null
@@ -1,47 +0,0 @@
-
-
-
- C-CoRN -- Metric Spaces
-
-
-
-
-
-Metric Spaces
-
-Description: This library formalizes metric spaces. This unique formulation defines a metric as a ball relation ball : Qpos -> X -> X -> Prop.
- The formalization includes:
-
-
- - definition of metrics and uniformly continuous functions
- - product metrics
- - a monadic completion operation for creating complete metric spaces
- - a compact operation for creating the metric space of compact subsets of metric spaces using the Hausdorff metric
- - a metric space of step functions.
-
-
-
-References:
-
-
- - Russell O’Connor. "A monadic, functional implementation of real numbers", Mathematical. Structures in Comp. Sci., 17(1):129–159, 2007.
-
-
- Russell O’Connor. "Certified exact transcendental real number computation in Coq". In Theorem Proving in Higher Order Logics, 21st International Conference, TPHOLs 2008, LNCS. Springer-Verlag, 2008. to appear.
-
-
- Russell O’Connor. "A Computer Verified Theory of Compact Sets". to appear.
-
-
-
-
-
-Maintainer: Russell O’Connor
-
-Developers: Russell O’Connor
-
-Documentation
-
-Download
-
-
-
diff --git a/doc/www/library/model.html b/doc/www/library/model.html
deleted file mode 100644
index e90a7c90..00000000
--- a/doc/www/library/model.html
+++ /dev/null
@@ -1,67 +0,0 @@
-
-
-C-CoRN -- Libraries
-
-
-
-
-A Model of the Real Numbers
-Description: This library consists of a formalisation of a
-concrete
-model of a real numbers structure and a proof of categoricity of
-the
-axioms for a real number structure. Real numbers are defined as the set
-of Cauchy sequences of rational numbers. A detailed discussion of the
-axioms and the formalisation is given in [2]. The formalisation
-includes:
-
-
-
-- Formalisation of rational numbers as a set of pairs of natural
-numbers and integers and the proof that this model is an Archimedean
-constructive
-ordered field.
-
--
-Proof of the fact that the set of Cauchy sequences of any Archimedean
-constructive ordered field is a real numbers structure.
-
--
-Definition of a notion of isomorphism between two real number structures
-and proof of the fact that any two real number structures are isomorphic.
-
--
-Proof of the fact that the axioms for a real numbers structure are
-equivalent to those
-introduced in [1].
-
-
-
-
-References:
-
--
-[1]
-Douglas S. Bridges; Constructive mathematics:
-a foundation for computable analysis
-, Theoretical Computer Science 219 (1999) 95-109
-
- -
-[2]
-Herman Geuvers, Milad
-Niqui; Constructive
-Reals in
-Coq: Axioms and Categoricity, In P. Callaghan, Z. Luo, J.
-McKinna, R. Pollack (Eds.), Proceedings of TYPES 2000 Workshop,
-Durham, UK,
-LNCS 2277, 79-95, 2002
-
-Maintainer: Milad Niqui
-Developers: Milad Niqui
-Documentation
-Download
-
-
diff --git a/doc/www/library/realcalc.html b/doc/www/library/realcalc.html
deleted file mode 100644
index 3f08c966..00000000
--- a/doc/www/library/realcalc.html
+++ /dev/null
@@ -1,68 +0,0 @@
-
-
-
- C-CoRN -- Libraries
-
-
-
-
-
-Real Calculus
-
-Description: This library includes a formalization of Real Analysis
-following Bishop (see references). Starting with the real numbers and partial
-functions axiomatized in the algebraic hierarchy, we define notions of continuity,
-differentiability and integral in compact intervals and in more general subsets
-of IR.
- The formalization includes:
-
-
- - results about preservation of continuity through algebraic operations;
- - the usual rules for derivation; - formalization of power series and
-Taylor series;
- - several formulations of Rolle's Theorem, the Mean Law, convergence
-theorems and error estimates for Taylor series;
- - the fundamental theorem of calculus;
- - definition of the usual elementary transcendental functions (exp, sin,
-cos, tan) and their inverses (log, arcsin, arccos, arctan), along with their
-usual algebraic properties;
- - tactics for automatically proving usual properties about continuity
-and derivatives of these functions.
-
-
-
-References:
-
-
- - For the mathematical content:
-
- - Bishop, E., "Foundations of Constructive Analysis", McGraw-Hill Book
-Company, 1967
-
- - About the formalization itself:
-
- - Cruz-Filipe, L., "Formalizing Real Calculus in Coq", in Theorem
-Proving in Higher Order Logics , Carreño, V., Muñoz, C. and
-Tahar, S. (eds.), NASA Conference Proceedings, Hampton VA, 2002 (ps, pdf)
- - ``A Constructive Formalization of the Fundamental Theorem of Calculus'',
- Springer-Verlag, in Types 2002, Proceedings of the workshop Types for Proof and Programs, Geuvers, H. and Wiedijk, F.
-(eds.), LNCS, Springer-Verlag 2003; ps,pdf
-
-
-
-
-Maintainer: Luís Cruz-Filipe
-
-Developers: Luís Cruz-Filipe
-
-Documentation
-
-Download
-
-
-
diff --git a/doc/www/people.html b/doc/www/people.html
deleted file mode 100644
index 74d3e281..00000000
--- a/doc/www/people.html
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-C-CoRN -- People
-
-
-
-
-People
-The following people have contributed to this project:
-
-
-
-
diff --git a/doc/www/pub.html b/doc/www/pub.html
deleted file mode 100644
index 3db7c911..00000000
--- a/doc/www/pub.html
+++ /dev/null
@@ -1,103 +0,0 @@
-
-
-
- C-CoRN - Publications
-
-
-
-
-
-Publications
-
-
- -
- L. Cruz-Filipe, "A Constructive Formalization of the Fundamental
- Theorem of Calculus",
- Springer-Verlag, in H. Geuvers and F. Wiedijk (eds.), Types
- 2002, Proceedings of the workshop Types for Proof and Programs,
- pages 108-126, LNCS 2646, Springer-Verlag 2003;
- ps,
- pdf,
- BiBTeX
-
- -
- L. Cruz-Filipe, "Constructive Real Analysis: a Type-Theoretical
- Formalization and Applications", PhD thesis, 2004;
- ps.gz,
- pdf,
- BiBTeX
-
- -
- L. Cruz-Filipe, "Formalizing Real Calculus in Coq", in
- Carreño, V., Muñoz, C. and Tahar, S. (eds.),
- Theorem Proving in Higher Order Logics, pages 158-166, NASA
- Conference Proceedings, Hampton VA, 2002;
- ps,
- pdf,
- BiBTeX
-
- -
- L. Cruz-Filipe and B. Spitters, "Program Extraction from Large Proof
- Developments",
- Springer-Verlag, in D. Basin and B. Wolff (eds.), Theorem
- Proving in Higher Order Logics (16th International Conference,
- TPHOLs2003), pages 205-220, LNCS 2758, Springer, 2003;
- ps,
- pdf,
- BiBTeX
-
- -
- H. Geuvers, R. Pollack, F. Wiedijk & J. Zwanenburg, "A
- Constructive Algebraic Hierarchy in Coq", in S. Linton &
- R. Sebasitani (eds.), Journal of Symbolic Computation,
- Special Issue on the Integration of Automated Reasoning and Computer
- Algebra Systems, 34(4), Elsevier, 271-286, 2002;
- ps.gz
- dvi
-
- -
- H. Geuvers, R.Pollack, F. Wiedijk & J. Zwanenburg, Skeleton
- for the Proof development leading to the Fundamental Theorem of
- Algebra , Outline of the mathematics of a constructive proof of
- the Fundamental Theorem of Algebra
-
- -
- H. Geuvers, F. Wiedijk & J. Zwanenburg, "A Constructive Proof of
- the Fundamental Theorem of Algebra without using the Rationals", in
- P. Callaghan, Z. Luo, J. McKinna & R. Pollack (eds.), Types
- for Proofs and Programs, Proceedings of the International
- Workshop, TYPES 2000, Durham, Springer LNCS 2277, 96-111,
- 2001;
- ps.gz
- dvi
-
- -
- H. Geuvers, F. Wiedijk & J. Zwanenburg, "Equational Reasoning
- via Partial Reflection.", in J. Harrison & M. Aagaard,
- Theorem Proving in Higher Order Logics, 13th International
- Conference, TPHOLs 2000, Portland, Oregon, Springer LNCS
- 1869, 162-178, 2000;
- ps.gz
- dvi
-
- -
- S. Hinderer, "Formalization d'éléments d'analyse complexe et de
- topologie en Coq", Bachelor Thesis, École Normale Supérieure de Lyon,
- 2003;
-
-
-
-
-
-
-
-
-
From 084928315fb3ac1cad51d24ba0f3a328ed6f652b Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Mon, 25 Aug 2014 16:22:05 +0200
Subject: [PATCH 096/110] Adding .aux .native
---
.gitignore | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.gitignore b/.gitignore
index a1ed2b8e..095ce187 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,6 +18,8 @@ coqidescript
*#
deps.dot
deps.pdf
+*.native
+*.aux
*.crashcoqide
*.cmi
*.cmo
From e879504d28b28600ec073ac3a0f21a5ba84e95a1 Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Tue, 26 Aug 2014 12:27:41 +0200
Subject: [PATCH 097/110] updating README
---
README | 2 +-
math-classes | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/README b/README
index 6b3f4f8a..6cad5586 100644
--- a/README
+++ b/README
@@ -6,7 +6,7 @@ PREREQUISITES
This version of C-CoRN is known to compile with:
- - Coq 8.4pl4
+ - Coq trunk
- SCons 1.2
diff --git a/math-classes b/math-classes
index ec6d10d9..9db63131 160000
--- a/math-classes
+++ b/math-classes
@@ -1 +1 @@
-Subproject commit ec6d10d98c432a8fbf9c251647c8dae17de14f62
+Subproject commit 9db63131144f270b6fe45ae613668ca41341bc38
From 184c69a13d5db9ca6dd2244cd792d611fa59ef0d Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Wed, 27 Aug 2014 17:52:44 +0200
Subject: [PATCH 098/110] In the process of making compile with trunk
---
.gitignore | 3 +
algebra/Bernstein.v | 20 +++---
algebra/CPoly_Degree.v | 3 +
algebra/CPoly_NthCoeff.v | 2 +
algebra/CPolynomials.v | 15 ++---
complex/NRootCC.v | 73 ++++++++-------------
coq_reals/Rreals_iso.v | 14 ++--
ftc/Composition.v | 2 +-
logic/CLogic.v | 10 +--
math-classes | 2 +-
metric2/Compact.v | 2 +-
metric2/Complete.v | 7 +-
metric2/Graph.v | 12 ++--
metric2/Prelength.v | 8 +--
metrics/Prod_Sub.v | 4 +-
model/Zmod/IrrCrit.v | 4 +-
model/Zmod/ZGcd.v | 2 +-
model/fields/CRfield.v | 4 +-
model/groups/CRgroup.v | 8 +--
model/ordfields/CRordfield.v | 4 +-
model/reals/CRreal.v | 8 +--
model/rings/CRring.v | 2 +-
model/structures/NNUpperR.v | 2 +-
model/structures/Npossec.v | 2 +-
ode/BanachFixpoint.v | 4 +-
order/TotalOrder.v | 35 +++++-----
raster/Raster.v | 4 +-
reals/OddPolyRootIR.v | 4 +-
reals/fast/CRAlternatingSum.v | 4 +-
reals/fast/CRFieldOps.v | 6 +-
reals/fast/CRGroupOps.v | 32 +++++----
reals/fast/CRIR.v | 2 +-
reals/fast/CRartanh_slow.v | 2 +-
reals/fast/CRcorrect.v | 98 ++++++++++++++--------------
reals/fast/CRexp.v | 2 +-
reals/fast/CRroot.v | 4 +-
reals/fast/CRseries.v | 2 +-
reals/fast/Integration.v | 4 +-
reals/fast/Interval.v | 2 +-
reals/fast/ModulusDerivative.v | 2 +-
reals/fast/MultivariatePolynomials.v | 28 ++++----
reals/faster/ARArith.v | 2 +-
stdlib_omissions/List.v | 2 -
stdlib_omissions/Z.v | 7 +-
tactics/csetoid_rewrite.v | 18 ++---
transc/ArTanH.v | 2 +-
transc/MoreArcTan.v | 2 +-
util/Qdlog.v | 15 ++---
util/Qsums.v | 4 +-
util/SetoidPermutation.v | 2 +-
50 files changed, 249 insertions(+), 253 deletions(-)
diff --git a/.gitignore b/.gitignore
index 095ce187..c428b464 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,3 +30,6 @@ deps.pdf
*.o
plot.pgm
coqdoc
+*.native
+*.aux
+
diff --git a/algebra/Bernstein.v b/algebra/Bernstein.v
index 12d4b1f2..95b74963 100644
--- a/algebra/Bernstein.v
+++ b/algebra/Bernstein.v
@@ -270,6 +270,8 @@ Qed.
Opaque Bernstein.
(** Given a vector of coefficents for a polynomial in the Bernstein basis, return the polynomial *)
+Implicit Arguments Vector.nil [A].
+Implicit Arguments Vector.cons [A].
Fixpoint evalBernsteinBasisH (n i:nat) (v:Vector.t R i) : i <= n -> cpoly_cring R :=
match v in Vector.t _ i return i <= n -> cpoly_cring R with
@@ -296,13 +298,13 @@ Proof.
apply Vector.nil.
inversion v as [| a n0 H0 H1]; inversion v0 as [| a0 n1 H2 H3].
- exact (Vector.cons A (g a a0) n (h H0 H2)).
+ exact (Vector.cons (g a a0) n (h H0 H2)).
Defined.
Definition Vid n : Vector.t A n -> Vector.t A n :=
match n with
- | O => fun _ => Vector.nil A
- | S n' => fun v : Vector.t A (S n') => Vector.cons A (Vector.hd v) _ (Vector.tl v)
+ | O => fun _ => Vector.nil
+ | S n' => fun v : Vector.t A (S n') => Vector.cons (Vector.hd v) _ (Vector.tl v)
end.
Lemma Vid_eq : forall (n:nat) (v:Vector.t A n), v = Vid v.
@@ -311,13 +313,13 @@ Proof.
Qed.
Lemma VSn_eq :
- forall (n : nat) (v : Vector.t A (S n)), v = Vector.cons A (Vector.hd v) _ (Vector.tl v).
+ forall (n : nat) (v : Vector.t A (S n)), v = Vector.cons (Vector.hd v) _ (Vector.tl v).
Proof.
intros.
exact (Vid_eq v).
Qed.
-Lemma V0_eq : forall (v : Vector.t A 0), v = Vector.nil A.
+Lemma V0_eq : forall (v : Vector.t A 0), v = Vector.nil.
Proof.
intros.
exact (Vid_eq v).
@@ -394,10 +396,10 @@ ring homomorphism from [Q] to R *)
Fixpoint BernsteinBasisTimesXH (n i:nat) (v:Vector.t R i) : i <= n -> Vector.t R (S i) :=
match v in Vector.t _ i return i <= n -> Vector.t R (S i) with
-| Vector.nil => fun _ => Vector.cons _ [0] _ (Vector.nil _)
+| Vector.nil => fun _ => Vector.cons [0] _ Vector.nil
| Vector.cons a i' v' => match n as n return S i' <= n -> Vector.t R (S (S i')) with
| O => fun p => False_rect _ (le_Sn_O _ p)
- | S n' => fun p => Vector.cons _ (eta(Qred (i#P_of_succ_nat n'))[*]a) _ (BernsteinBasisTimesXH v' (le_Sn_le _ _ p))
+ | S n' => fun p => Vector.cons (eta(Qred (i#P_of_succ_nat n'))[*]a) _ (BernsteinBasisTimesXH v' (le_Sn_le _ _ p))
end
end.
@@ -470,8 +472,8 @@ Qed.
(** Convert a polynomial to the Bernstein basis *)
Fixpoint BernsteinCoefficents (p:cpoly_cring R) : sigT (Vector.t R) :=
match p with
-| cpoly_zero => existT _ _ (Vector.nil R)
-| cpoly_linear c p' =>
+| cpoly_zero _ => existT _ _ Vector.nil
+| cpoly_linear _ c p' =>
let (n', b') := (BernsteinCoefficents p') in
existT _ _ (Vbinary (fun (x y:R)=>x[+]y) (Vector.const c _) (BernsteinBasisTimesX b'))
end.
diff --git a/algebra/CPoly_Degree.v b/algebra/CPoly_Degree.v
index 2f5b332d..8001181f 100644
--- a/algebra/CPoly_Degree.v
+++ b/algebra/CPoly_Degree.v
@@ -64,6 +64,9 @@ is always [1] higher than the `degree' (assuming that the highest
coefficient is [[#][0]])!
*)
+Implicit Arguments cpoly_zero [CR].
+Implicit Arguments cpoly_linear [CR].
+
Fixpoint lth_of_poly (p : RX) : nat :=
match p with
| cpoly_zero => 0
diff --git a/algebra/CPoly_NthCoeff.v b/algebra/CPoly_NthCoeff.v
index 8bde79c8..0b6b812d 100644
--- a/algebra/CPoly_NthCoeff.v
+++ b/algebra/CPoly_NthCoeff.v
@@ -61,6 +61,8 @@ The [n]-th coefficient of a polynomial. The default value is
polynomial $a_0 +a_1 X +a_2 X^2 + \cdots + a_n X^n$ #a0 +a1 X +a2 X^2
+ ... + an X^n#, the [Zero]-th coefficient is $a_0$#a0#, the first
is $a_1$#a1# etcetera. *)
+Implicit Arguments cpoly_zero [CR].
+Implicit Arguments cpoly_linear [CR].
Fixpoint nth_coeff (n : nat) (p : RX) {struct p} : R :=
match p with
diff --git a/algebra/CPolynomials.v b/algebra/CPolynomials.v
index ac837e2d..d5cc6c52 100644
--- a/algebra/CPolynomials.v
+++ b/algebra/CPolynomials.v
@@ -1922,8 +1922,8 @@ Transparent cpoly_csetoid.
Fixpoint cpoly_apply (p : RX) (x : CR) {struct p} : CR :=
match p with
- | cpoly_zero => [0]
- | cpoly_linear c p1 => c[+]x[*]cpoly_apply p1 x
+ | cpoly_zero _ => [0]
+ | cpoly_linear _ c p1 => c[+]x[*]cpoly_apply p1 x
end.
Lemma cpoly_apply_strext : bin_fun_strext _ _ _ cpoly_apply.
@@ -2443,8 +2443,8 @@ Notation RX:= (cpoly_cring R).
Fixpoint cpoly_diff (p : RX) : RX :=
match p with
-| cpoly_zero => [0]
-| cpoly_linear c p1 => p1[+]([0][+X*](cpoly_diff p1))
+| cpoly_zero _ => [0]
+| cpoly_linear _ c p1 => p1[+]([0][+X*](cpoly_diff p1))
end.
Lemma cpoly_diff_strext : un_op_strext _ cpoly_diff.
@@ -2514,8 +2514,7 @@ Proof.
reflexivity.
intros [|a q].
rewrite -> cm_rht_unit_unfolded.
- change (cpoly_zero R) with ([0]:cpoly_cring R).
- rewrite -> diff_zero; algebra.
+ change (cpoly_zero R) with ([0]:cpoly_cring R); algebra.
change ((p[+]q)[+]cpoly_linear _ [0] (_D_ (p[+]q))[=]
(p[+]cpoly_linear _ [0] (_D_ p))[+](q[+]cpoly_linear _ [0] (_D_ q))).
do 3 rewrite -> poly_linear.
@@ -2605,8 +2604,8 @@ Notation SX := (cpoly_cring S).
Fixpoint cpoly_map_fun (p:RX) : SX :=
match p with
-| cpoly_zero => cpoly_zero _
-| cpoly_linear c p1 => cpoly_linear _ (f c) (cpoly_map_fun p1)
+| cpoly_zero _ => cpoly_zero _
+| cpoly_linear _ c p1 => cpoly_linear _ (f c) (cpoly_map_fun p1)
end.
Lemma cpoly_map_strext : fun_strext cpoly_map_fun.
diff --git a/complex/NRootCC.v b/complex/NRootCC.v
index 0813ca27..4d78bd7f 100644
--- a/complex/NRootCC.v
+++ b/complex/NRootCC.v
@@ -54,29 +54,17 @@ Section CC_ap_zero.
Lemma cc_ap_zero : forall P : CC -> Prop,
(forall a b, a [#] [0] -> P (a[+I*]b)) -> (forall a b, b [#] [0] -> P (a[+I*]b)) -> forall c, c [#] [0] -> P c.
Proof.
- intro. intro. intro. intro.
- elim c. intros a b. intro H1.
- elim H1; intros H2.
- apply H.
- (* algebra. *)
- exact H2.
- apply H0.
- (* algebra. *)
- exact H2.
+ intros ????.
+ elim c. intros a b H1.
+ elim H1; intros H2; auto.
Qed.
Lemma C_cc_ap_zero : forall P : CC -> CProp,
(forall a b, a [#] [0] -> P (a[+I*]b)) -> (forall a b, b [#] [0] -> P (a[+I*]b)) -> forall c, c [#] [0] -> P c.
Proof.
- intro. intro H. intro H0. intro.
+ intro. intros H H0 c.
elim c. intros a b. intro H1.
- elim H1; intros H2.
- apply H.
- (* algebra. *)
- exact H2.
- apply H0.
- (* algebra. *)
- exact H2.
+ elim H1; intros H2;auto.
Qed.
End CC_ap_zero.
@@ -87,22 +75,19 @@ Section Imag_to_Real.
Lemma imag_to_real : forall a b a' b', a'[+I*]b' [=] (a[+I*]b) [*]II -> a [#] [0] -> b' [#] [0].
Proof.
- do 5 intro. intro H0.
+ intros ????? H0.
cut (b' [=] a); intros.
(* astepl a. *)
- apply ap_wdl_unfolded with a.
- exact H0.
- apply eq_symmetric_unfolded. exact H1.
- (* astepl (Im a'[+I*]b'). *)
- apply eq_transitive_unfolded with (Im (a'[+I*]b')).
- apply eq_reflexive_unfolded.
+ now apply ap_wdl with a.
+ apply eq_transitive with (Im (a'[+I*]b')).
+ apply eq_reflexive.
(* astepl (Im a[+I*]b[*]II). *)
- apply eq_transitive_unfolded with (Im ((a[+I*]b) [*]II)).
- apply Im_wd. exact H.
+ apply eq_transitive with (Im ((a[+I*]b) [*]II)).
+ now apply Im_wd.
(* Step_final (Im ( [--]b) [+I*]a). *)
- apply eq_transitive_unfolded with (Im ( [--]b[+I*]a)).
+ apply eq_transitive with (Im ( [--]b[+I*]a)).
apply Im_wd. apply mult_I.
- apply eq_reflexive_unfolded.
+ apply eq_reflexive.
Qed.
End Imag_to_Real.
@@ -118,28 +103,26 @@ Definition sqrt_I := sqrt_Half[+I*]sqrt_Half.
Lemma sqrt_I_nexp : sqrt_I[^]2 [=] II.
Proof.
(* astepl sqrt_I[*]sqrt_I. *)
- apply eq_transitive_unfolded with (sqrt_I[*]sqrt_I).
+ apply eq_transitive with (sqrt_I[*]sqrt_I).
apply nexp_two.
unfold sqrt_I in |- *.
(* astepl (sqrt_Half[*]sqrt_Half[-]sqrt_Half[*]sqrt_Half) [+I*]
(sqrt_Half[*]sqrt_Half[+]sqrt_Half[*]sqrt_Half). *)
- apply eq_transitive_unfolded with ((sqrt_Half[*]sqrt_Half[-]sqrt_Half[*]sqrt_Half) [+I*]
+ apply eq_transitive with ((sqrt_Half[*]sqrt_Half[-]sqrt_Half[*]sqrt_Half) [+I*]
(sqrt_Half[*]sqrt_Half[+]sqrt_Half[*]sqrt_Half)).
apply eq_reflexive_unfolded.
cut (sqrt_Half[*]sqrt_Half [=] Half); intros.
(* astepl [0][+I*] (Half[+]Half). *)
- apply eq_transitive_unfolded with ([0][+I*] (Half[+]Half)).
+ apply eq_transitive with ([0][+I*] (Half[+]Half)).
apply I_wd. apply cg_minus_correct. apply bin_op_wd_unfolded. exact H.
exact H.
(* Step_final [0][+I*][1]. *)
- apply eq_transitive_unfolded with ([0][+I*][1]).
- apply I_wd. apply eq_reflexive_unfolded. apply half_2.
- apply eq_reflexive_unfolded.
+ apply eq_transitive with ([0][+I*][1]).
+ apply I_wd. apply eq_reflexive. apply half_2.
+ apply eq_reflexive.
(* astepl sqrt_Half[^] (2). *)
- apply eq_transitive_unfolded with (sqrt_Half[^]2).
- apply eq_symmetric_unfolded. apply nexp_two.
- unfold sqrt_Half in |- *.
- (* algebra. *)
+ apply eq_transitive with (sqrt_Half[^]2).
+ apply eq_symmetric. apply nexp_two.
apply sqrt_sqr.
Qed.
@@ -161,17 +144,17 @@ Proof.
intros n on.
unfold nroot_I in |- *.
(* astepl II[^] (mult n n). *)
- apply eq_transitive_unfolded with (II[^] (n * n)).
+ apply eq_transitive with (II[^] (n * n)).
apply nexp_mult.
elim (nroot_I_nexp_aux n); try assumption.
intros m H.
rewrite H.
(* astepl II[^] (mult (4) m) [*]II[^] (1). *)
- apply eq_transitive_unfolded with (II[^] (4 * m) [*]II[^]1).
- apply eq_symmetric_unfolded. apply nexp_plus.
+ apply eq_transitive with (II[^] (4 * m) [*]II[^]1).
+ apply eq_symmetric. apply nexp_plus.
(* astepl (II[^] (4)) [^]m[*]II. *)
- apply eq_transitive_unfolded with ((II[^]4) [^]m[*]II).
- apply bin_op_wd_unfolded. apply eq_symmetric_unfolded. apply nexp_mult.
+ apply eq_transitive with ((II[^]4) [^]m[*]II).
+ apply bin_op_wd_unfolded. apply eq_symmetric. apply nexp_mult.
apply nexp_one.
cut (II[^]4 [=] [1]); intros.
(* astepl [1][^]m[*]II. *)
@@ -652,8 +635,8 @@ Section NRootCC_3.
Fixpoint Im_poly (p : cpoly CC) : cpoly IR :=
match p with
- | cpoly_zero => cpoly_zero IR
- | cpoly_linear c p1 => cpoly_linear IR (Im c) (Im_poly p1)
+ | cpoly_zero _ => cpoly_zero IR
+ | cpoly_linear _ c p1 => cpoly_linear IR (Im c) (Im_poly p1)
end.
Lemma nrCC3_a1 : forall p r, (Im_poly p) ! r [=] Im p ! (cc_IR r).
diff --git a/coq_reals/Rreals_iso.v b/coq_reals/Rreals_iso.v
index 195a78a5..2455f99a 100644
--- a/coq_reals/Rreals_iso.v
+++ b/coq_reals/Rreals_iso.v
@@ -39,6 +39,12 @@ Require Import MoreArcTan.
Require Import PropDecid.
Require Import Exponential.
+(* This changed in RLogic and should probably be moved there: *)
+Lemma forall_dec : forall P:nat->Prop, (forall n, {P n} + {~ P n}) -> {forall n, P n} + {~forall n, P n}.
+intros.
+case (sig_forall_dec _ H) as [[n H1] | H1];intuition.
+Qed.
+
(** * Coq Real Numbers and IR isomorphisms
Warning: The Coq real numbers depend on classical logic. Importing this
@@ -353,7 +359,7 @@ Proof.
apply constructive_indefinite_description_nat.
intros N.
apply forall_dec.
- intros n0.
+ intros n0.
apply forall_dec.
intros n1.
apply imp_dec.
@@ -366,13 +372,11 @@ Proof.
left; auto with *.
right; auto with *.
apply Rlt_dec.
- apply cauchy.
- auto with *.
+ apply cauchy; auto with *.
destruct H as [N HN].
exists (S N).
intros m Hm.
- assert (N <= pred m)%nat.
- auto with *.
+ assert (N <= pred m)%nat by auto with *.
assert (HH := HN (pred m) N H (le_refl N)).
clear - HH Hm.
destruct m.
diff --git a/ftc/Composition.v b/ftc/Composition.v
index a57e2cd9..dc33253a 100644
--- a/ftc/Composition.v
+++ b/ftc/Composition.v
@@ -833,7 +833,7 @@ Proof.
assert (Y:forall n : nat, Dom (f n) x).
intros n.
refine (Continuous_imp_inc _ _ _ _ _).
- apply contf.
+ 2:apply contf.
Included.
rename H0 into X1.
assert (Z:=fun_conv_imp_seq_conv _ _ _ _ _ _ _ (X a b Hab Hinc) x X1 Y Hx).
diff --git a/logic/CLogic.v b/logic/CLogic.v
index c22171b9..71e7456e 100644
--- a/logic/CLogic.v
+++ b/logic/CLogic.v
@@ -110,12 +110,12 @@ Definition Iff (A B : CProp) : CProp := prod (A -> B) (B -> A).
Definition proj1_sigT (A : Type) (P : A -> CProp) (e : sigT P) :=
match e with
- | existT a b => a
+ | existT _ a b => a
end.
Definition proj2_sigT (A : Type) (P : A -> CProp) (e : sigT P) :=
match e return (P (proj1_sigT A P e)) with
- | existT a b => b
+ | existT _ a b => b
end.
Inductive sig2T (A : Type) (P Q : A -> CProp) : CProp :=
@@ -123,17 +123,17 @@ Inductive sig2T (A : Type) (P Q : A -> CProp) : CProp :=
Definition proj1_sig2T (A : Type) (P Q : A -> CProp) (e : sig2T A P Q) :=
match e with
- | exist2T a b c => a
+ | exist2T _ _ _ a b c => a
end.
Definition proj2a_sig2T (A : Type) (P Q : A -> CProp) (e : sig2T A P Q) :=
match e return (P (proj1_sig2T A P Q e)) with
- | exist2T a b c => b
+ | exist2T _ _ _ a b c => b
end.
Definition proj2b_sig2T (A : Type) (P Q : A -> CProp) (e : sig2T A P Q) :=
match e return (Q (proj1_sig2T A P Q e)) with
- | exist2T a b c => c
+ | exist2T _ _ _ a b c => c
end.
End Basics.
diff --git a/math-classes b/math-classes
index 9db63131..de742fdc 160000
--- a/math-classes
+++ b/math-classes
@@ -1 +1 @@
-Subproject commit 9db63131144f270b6fe45ae613668ca41341bc38
+Subproject commit de742fdc0b6c2f51df2d75fe4353b13d8d9af9ac
diff --git a/metric2/Compact.v b/metric2/Compact.v
index 79d409bd..4a718249 100644
--- a/metric2/Compact.v
+++ b/metric2/Compact.v
@@ -1723,7 +1723,7 @@ Proof.
unfold FinEnum_map_modulus.
case_eq (mu f ((1#4)*d1)).
intros d Hd.
- apply: almostIn_map2;[|apply H].
+ apply: almostIn_map2. 3:apply H.
rewrite Hd.
apply: Qle_refl.
intros H0.
diff --git a/metric2/Complete.v b/metric2/Complete.v
index 14155328..4226e7c9 100644
--- a/metric2/Complete.v
+++ b/metric2/Complete.v
@@ -661,7 +661,7 @@ Lemma MonadLaw1 : forall a, Cmap_slow_fun (uc_id X) a =m a.
Proof.
intros x e1 e2.
simpl.
- apply: ball_weak_le;[|apply regFun_prf].
+ eapply ball_weak_le; [|apply regFun_prf].
autorewrite with QposElim.
Qauto_le.
Qed.
@@ -997,8 +997,7 @@ Proof.
transitivity (Cmap_slow_fun x1 y2).
apply (@uc_wd _ _ (Cmap_slow x1) _ _ Hy).
generalize y2.
- apply:(@uc_wd _ _ (Cmap_strong_slow X Y)).
- assumption.
+ now apply (@uc_wd _ _ (Cmap_strong_slow X Y)).
Qed.
Add Parametric Morphism X Y : (@Cap_weak_slow X Y) with signature (@st_eq _) ==> (@st_eq _) as Cap_weak_slow_wd.
@@ -1013,7 +1012,7 @@ Proof.
transitivity (Cap_slow_fun x1 y2).
apply (@uc_wd _ _ (Cap_weak_slow x1) _ _ Hy).
generalize y2.
- apply:(@uc_wd _ _ (Cap_slow X Y));assumption.
+ apply (@uc_wd _ _ (Cap_slow X Y));assumption.
Qed.
Transparent Complete.
(* end hide *)
diff --git a/metric2/Graph.v b/metric2/Graph.v
index 285952dc..5a188146 100644
--- a/metric2/Graph.v
+++ b/metric2/Graph.v
@@ -247,10 +247,10 @@ Proof.
symmetry.
rewrite <- (CoupleCorrect2 p q1).
apply: CompactGraph_correct3.
- apply Hq1.
+ 3:apply Hq1.
rewrite <- (CoupleCorrect2 p q2).
apply: CompactGraph_correct3.
- apply Hq2.
+ 3:apply Hq2.
Qed.
Lemma CompactGraph_correct : forall plX plFEX x y s,
@@ -265,7 +265,7 @@ Proof.
symmetry.
transitivity (Csnd (Couple (x,y))).
apply: CompactGraph_correct3.
- apply H.
+ 3:apply H.
apply CoupleCorrect3.
destruct H as [H0 H1].
change (x, y) with (PairMS x y).
@@ -552,10 +552,10 @@ Proof.
symmetry.
rewrite <- (CoupleCorrect2 p q1).
apply: CompactGraph_b_correct3.
- apply Hq1.
+ 3:apply Hq1.
rewrite <- (CoupleCorrect2 p q2).
apply: CompactGraph_b_correct3.
- apply Hq2.
+ 3:apply Hq2.
Qed.
Lemma CompactGraph_b_correct : forall plX plFEX x y s,
@@ -570,7 +570,7 @@ Proof.
symmetry.
transitivity (Csnd (Couple (x,y))).
apply: CompactGraph_b_correct3.
- apply H.
+ 3:apply H.
apply CoupleCorrect3.
destruct H as [H0 H1].
change (x, y) with (PairMS x y).
diff --git a/metric2/Prelength.v b/metric2/Prelength.v
index cf35fa48..2f49a288 100644
--- a/metric2/Prelength.v
+++ b/metric2/Prelength.v
@@ -95,7 +95,7 @@ Proof.
assert ((Qmax 0 (e-x)) CProp)
(f : CSetoid_bin_fun X X IR) (a b : Build_SubCSetoid X P) : IR :=
match a, b with
- | Build_subcsetoid_crr x p, Build_subcsetoid_crr y q => f x y
+ | Build_subcsetoid_crr _ _ x p, Build_subcsetoid_crr _ _ y q => f x y
end.
@@ -211,7 +211,7 @@ Implicit Arguments restr_bin_fun [X].
Definition restr_bin_fun' (X : CPsMetricSpace) (P : cms_crr X -> CProp)
(f : CSetoid_bin_fun X X IR) (a : X) (b : Build_SubCSetoid X P) : IR :=
match b with
- | Build_subcsetoid_crr y q => f a y
+ | Build_subcsetoid_crr _ _ y q => f a y
end.
Implicit Arguments restr_bin_fun' [X].
diff --git a/model/Zmod/IrrCrit.v b/model/Zmod/IrrCrit.v
index 415f9839..e57a7802 100644
--- a/model/Zmod/IrrCrit.v
+++ b/model/Zmod/IrrCrit.v
@@ -82,8 +82,8 @@ Definition fpx := (cpoly_cring fp).
Fixpoint zxfpx (p:zx) : fpx :=
match p with
- | cpoly_zero => (cpoly_zero fp : fpx)
- | cpoly_linear c p1 => (zfp c)[+X*](zxfpx p1)
+ | cpoly_zero _ => (cpoly_zero fp : fpx)
+ | cpoly_linear _ c p1 => (zfp c)[+X*](zxfpx p1)
end.
Definition P (f g:zx):= f[=]g -> (zxfpx f)[=](zxfpx g).
diff --git a/model/Zmod/ZGcd.v b/model/Zmod/ZGcd.v
index bfc7ab3e..528d97b1 100644
--- a/model/Zmod/ZGcd.v
+++ b/model/Zmod/ZGcd.v
@@ -126,7 +126,7 @@ Definition pp_gcd_ind (ab : pp) :
(Hind : forall cd : pp, pp_lt cd (a, b) -> positive * (Z * Z)) =>
match rem_dec a b with
| inl _ => (b, (0%Z, 1%Z))
- | inr (existT r' Hr') =>
+ | inr (existT _ r' Hr') =>
let (d, uv) := Hind (b, r') (rem_lt a b r' Hr') in
let (u, v) := uv in (d, (v, (u - Zpos a / Zpos b * v)%Z))
end) ab.
diff --git a/model/fields/CRfield.v b/model/fields/CRfield.v
index 03cf3ee8..0cbed37c 100644
--- a/model/fields/CRfield.v
+++ b/model/fields/CRfield.v
@@ -40,7 +40,7 @@ Proof.
stepl ((CRasCauchy_IR x)[*](CRasCauchy_IR (CRinvT x x_))); [| now apply CR_mult_as_Cauchy_IR_mult].
stepl ((CRasCauchy_IR x)[*](f_rcpcl (CRasCauchy_IR x) (CR_nonZero_as_Cauchy_IR_nonZero_1 _ x_))); [| now
apply bin_op_is_wd_un_op_rht; apply CR_inv_as_Cauchy_IR_inv].
- apply: eq_transitive.
+ eapply eq_transitive.
apply field_mult_inv.
apply: CR_inject_Q_as_Cauchy_IR_inject_Q.
change ((CRinvT x x_)*x==1)%CR.
@@ -48,7 +48,7 @@ Proof.
stepl ((CRasCauchy_IR (CRinvT x x_))[*](CRasCauchy_IR x)); [| now apply CR_mult_as_Cauchy_IR_mult].
stepl ((f_rcpcl (CRasCauchy_IR x) (CR_nonZero_as_Cauchy_IR_nonZero_1 _ x_))[*](CRasCauchy_IR x)); [| now
apply bin_op_is_wd_un_op_lft; apply CR_inv_as_Cauchy_IR_inv].
- apply: eq_transitive.
+ eapply eq_transitive.
apply field_mult_inv_op.
apply: CR_inject_Q_as_Cauchy_IR_inject_Q.
Qed.
diff --git a/model/groups/CRgroup.v b/model/groups/CRgroup.v
index f88873ff..48d09fb1 100644
--- a/model/groups/CRgroup.v
+++ b/model/groups/CRgroup.v
@@ -35,8 +35,8 @@ Proof.
intros x y H.
change (CRapartT x y)%CR.
apply CR_ap_as_Cauchy_IR_ap_2.
- apply: un_op_strext_unfolded.
- stepl (CRasCauchy_IR (-x)%CR); [| now apply eq_symmetric; apply CR_opp_as_Cauchy_IR_opp].
+ apply: un_op_strext_unfolded.
+ 2:stepl (CRasCauchy_IR (-x)%CR); [| now apply eq_symmetric; apply CR_opp_as_Cauchy_IR_opp].
stepr (CRasCauchy_IR (-y)%CR); [| now apply eq_symmetric; apply CR_opp_as_Cauchy_IR_opp].
apply CR_ap_as_Cauchy_IR_ap_1.
apply H.
@@ -54,14 +54,14 @@ Proof.
stepl ((CRasCauchy_IR x)[+][--](CRasCauchy_IR x)); [| now
apply plus_resp_eq; apply CR_opp_as_Cauchy_IR_opp].
apply: eq_transitive.
- apply cg_rht_inv_unfolded.
+ 2:apply cg_rht_inv_unfolded.
apply: CR_inject_Q_as_Cauchy_IR_inject_Q.
change (-x + x==0)%CR.
rewrite <- CR_eq_as_Cauchy_IR_eq.
stepl ((CRasCauchy_IR (-x)%CR)[+](CRasCauchy_IR x)); [| now apply CR_plus_as_Cauchy_IR_plus].
stepl ([--](CRasCauchy_IR x)[+](CRasCauchy_IR x)); [| now
apply bin_op_is_wd_un_op_lft; apply CR_opp_as_Cauchy_IR_opp].
- apply: eq_transitive.
+ eapply eq_transitive.
apply cg_lft_inv_unfolded.
apply: CR_inject_Q_as_Cauchy_IR_inject_Q.
Qed.
diff --git a/model/ordfields/CRordfield.v b/model/ordfields/CRordfield.v
index 2bf4aba1..7d77c2ef 100644
--- a/model/ordfields/CRordfield.v
+++ b/model/ordfields/CRordfield.v
@@ -65,9 +65,9 @@ Proof.
change (0 < x*y)%CR.
apply CR_lt_as_Cauchy_IR_lt_2.
stepr ((CRasCauchy_IR x)[*](CRasCauchy_IR y)); [| now apply CR_mult_as_Cauchy_IR_mult].
- apply: less_wdl;[|apply (CR_inject_Q_as_Cauchy_IR_inject_Q 0)].
+ eapply less_wdl;[|apply (CR_inject_Q_as_Cauchy_IR_inject_Q 0)].
apply mult_resp_pos;(
- apply: less_wdl;[|apply eq_symmetric;apply (CR_inject_Q_as_Cauchy_IR_inject_Q 0)];
+ eapply less_wdl;[|apply eq_symmetric;apply (CR_inject_Q_as_Cauchy_IR_inject_Q 0)];
apply CR_lt_as_Cauchy_IR_lt_1;assumption).
intros x y.
split.
diff --git a/model/reals/CRreal.v b/model/reals/CRreal.v
index c0e62851..8adfd4c6 100644
--- a/model/reals/CRreal.v
+++ b/model/reals/CRreal.v
@@ -105,7 +105,7 @@ Proof.
| Qpos2QposInf e => let (n,_) := Hf (inject_Q_CR e) (CRlt_Qlt _ _ (Qpos_prf e)) in f n end).
abstract ( intros e1 e2; destruct (Hf (inject_Q_CR e1) (CRlt_Qlt _ _ (Qpos_prf e1))) as [n1 Hn1];
destruct (Hf (inject_Q_CR e2) (CRlt_Qlt _ _ (Qpos_prf e2))) as [n2 Hn2];
- apply: ball_triangle;[apply ball_sym|];rewrite <- CRAbsSmall_ball; [apply Hn1;apply le_max_l|
+ eapply ball_triangle;[apply ball_sym|];rewrite <- CRAbsSmall_ball; [apply Hn1;apply le_max_l|
apply Hn2;apply le_max_r]) using Rlim_subproof0.
Defined.
@@ -131,7 +131,7 @@ Proof.
change (ball (e1+d+e2) (f m) (f a)).
destruct (le_ge_dec a m).
rewrite <- CRAbsSmall_ball.
- apply: AbsSmall_leEq_trans;[|apply Ha;assumption].
+ eapply AbsSmall_leEq_trans;[|apply Ha;assumption].
intros x.
autorewrite with QposElim.
change (-x <= e1 + d + e2 - e2).
@@ -157,7 +157,7 @@ Proof.
intros n d X.
rewrite (anti_convert_pred_convert n) in X.
exists (nat_of_P n)%nat.
- apply: leEq_transitive.
+ eapply leEq_transitive.
apply X.
clear X.
intros z.
@@ -190,7 +190,7 @@ Proof.
replace RHS with
((approximate (nring (R:=CRasCRing) a) ((1 # 2) * q)%Qpos + 1) + - ((Psucc (P_of_succ_nat a) # d)%Qpos- 1%Q))%Q by (simpl; ring).
rewrite<- Qle_minus_iff.
- apply: Qle_trans;[|apply IHa].
+ eapply Qle_trans;[|apply IHa].
generalize (P_of_succ_nat a).
intros p.
rewrite -> Qle_minus_iff.
diff --git a/model/rings/CRring.v b/model/rings/CRring.v
index 612b05a8..bccf6954 100644
--- a/model/rings/CRring.v
+++ b/model/rings/CRring.v
@@ -99,7 +99,7 @@ Proof.
apply cs_bin_op_wd; apply CR_mult_as_Cauchy_IR_mult.
change (CRapartT 1 0)%CR.
apply CR_ap_as_Cauchy_IR_ap_2.
- apply: ap_wd.
+ eapply ap_wd.
apply one_ap_zero.
apply: CR_inject_Q_as_Cauchy_IR_inject_Q.
apply: CR_inject_Q_as_Cauchy_IR_inject_Q.
diff --git a/model/structures/NNUpperR.v b/model/structures/NNUpperR.v
index 078d2951..51242109 100644
--- a/model/structures/NNUpperR.v
+++ b/model/structures/NNUpperR.v
@@ -365,7 +365,7 @@ Proof binop_assoc Qmult Qmult_le_0_compat Qmult_comm Qmult_assoc Qmult_le_compat
Lemma mult_plus_distr n m p: (n + m) * p == n * p + m * p.
Proof with auto; simpl.
unfold eq. split.
- intros _ [_ _ [e d ?? b ?][g f ?? c ?]a ?] r H0...
+ intros _ [_ _ [e d ?? b ?][g f ?? c ?]a ?] r ? ...
apply BinopBound_le with (e * d + g * f)%Qnn...
apply Qle_trans with (`b + `c)%Q...
apply Qplus_le_compat...
diff --git a/model/structures/Npossec.v b/model/structures/Npossec.v
index a6d46378..36935dd9 100644
--- a/model/structures/Npossec.v
+++ b/model/structures/Npossec.v
@@ -37,7 +37,7 @@
(** printing Npos $\mathbb{N}^{+}$ #N+# *)
Require Export Nsec.
-Require Import Arith.
+Require Import Arith Omega.
(**
** [Npos]
diff --git a/ode/BanachFixpoint.v b/ode/BanachFixpoint.v
index 0603126e..bd2a4b3f 100644
--- a/ode/BanachFixpoint.v
+++ b/ode/BanachFixpoint.v
@@ -21,7 +21,7 @@ Context `{MetricSpaceClass X} {Xlim : Limit X} {Xcms : CompleteMetricSpaceClass
Context (f : X -> X) `{!IsContraction f q} (x0 : X).
-Let x n := nat_iter n f x0.
+Let x n := Nat.iter n f x0.
Arguments x n%mc.
@@ -112,7 +112,7 @@ induction n as [| n IH] using nat_induction.
+ rewrite nat_pow_S. transitivity ((1 + a) * (1 + (n : Q) * a)).
- rewrite Nat2Z.inj_add, inject_Z_plus.
stepr (1 + (1 + (n : Q)) * a + (n : Q) * a²) by ring.
- (* [apply nonneg_plus_le_compat_r, nonneg_mult_compat.] does not work *)
+ (* [apply nonneg_plus_le_compat_r, nonneg_mult_compat. does not work *)
apply nonneg_plus_le_compat_r. apply nonneg_mult_compat; [solve_propholds | apply square_nonneg].
- now apply (order_preserving ((1 + a) *.)) in IH.
Qed.
diff --git a/order/TotalOrder.v b/order/TotalOrder.v
index 282e75eb..83156884 100644
--- a/order/TotalOrder.v
+++ b/order/TotalOrder.v
@@ -62,14 +62,15 @@ Qed.
(** meet distributes over any monotone function. *)
Lemma monotone_meet_distr : forall x y : X, f (meet x y) == meet (f x) (f y).
Proof.
- revert Hf; rewrite -> monotone_def. intro Hf.
+ set (Hf':=Hf). (* The section hypothesis is used in monotone_compat and hence cannot be changed. *)
+ rewrite -> monotone_def in Hf'.
assert (forall x y : X, x <= y -> f (meet x y) == meet (f x) (f y)).
intros x y Hxy.
- assert (Hfxfy:=Hf _ _ Hxy).
- rewrite -> le_meet_l in Hxy.
- rewrite -> Hxy.
- rewrite -> le_meet_l in Hfxfy.
- rewrite -> Hfxfy.
+ assert (Hfxfy:=Hf' _ _ Hxy).
+ rewrite -> le_meet_l in Hxy.
+ rewrite -> le_meet_l in Hfxfy.
+ rewrite -> Hfxfy.
+ rewrite -> Hxy.
reflexivity.
intros.
destruct (le_total _ x y).
@@ -83,7 +84,7 @@ End Monotone.
(** join distributes over meet *)
Lemma join_meet_distr_r : forall x y z:X, (join x (meet y z))==(meet (join x y) (join x z)).
-Proof (fun a => monotone_meet_distr _ (join_monotone_r X a)).
+Proof (fun a => monotone_meet_distr _ (join_monotone_r X a)).
Lemma join_meet_distr_l : forall x y z:X, (join (meet y z) x)==(meet (join y x) (join z x)).
Proof (fun a => monotone_meet_distr _ (join_monotone_l X a)).
@@ -94,7 +95,7 @@ Variable f : X -> X.
Hypothesis Hf : antitone X f.
(* begin hide *)
-Add Morphism f with signature (@st_eq X) ==> (@st_eq X) as antitone_compat.
+Add Parametric Morphism: f with signature (@st_eq X) ==> (@st_eq X) as antitone_compat.
Proof.
revert Hf; rewrite -> antitone_def; intros.
rewrite -> equiv_le_def in *.
@@ -105,15 +106,15 @@ Qed.
(* meet transforms into join for antitone functions *)
Lemma antitone_meet_join_distr : forall x y : X, f (meet x y) == join (f x) (f y).
Proof.
- revert Hf;rewrite -> antitone_def; intro Hf.
+ pose (Hf':=Hf).
+ rewrite antitone_def in Hf'.
assert (forall x y : X, x <= y -> f (meet x y) == join (f x) (f y)).
intros x y Hxy.
- assert (Hfxfy:=Hf _ _ Hxy).
+ assert (Hfxfy:=Hf' _ _ Hxy).
rewrite -> le_meet_l in Hxy.
- rewrite -> Hxy.
rewrite -> le_join_l in Hfxfy.
- rewrite -> Hfxfy.
- reflexivity.
+ rewrite -> Hfxfy. clear Hfxfy.
+ apply antitone_compat. rewrite -> Hxy. reflexivity.
intros.
destruct (le_total _ x y).
auto.
@@ -283,13 +284,13 @@ end.
Lemma min_def1 : forall x y, le x y -> equiv (min x y) x.
Proof.
intros.
- apply min_case; firstorder.
+ apply min_case; firstorder auto.
Qed.
Lemma min_def2 : forall x y, le y x -> equiv (min x y) y.
Proof.
intros.
- apply min_case; firstorder.
+ apply min_case; firstorder auto.
Qed.
End MinDefault.
@@ -314,13 +315,13 @@ Definition max_case :
Lemma max_def1 : forall x y, le y x -> equiv (max x y) x.
Proof.
refine (min_def1 A equiv flip_le _ flip_le_total).
- firstorder.
+ firstorder auto.
Qed.
Lemma max_def2 : forall x y, le x y -> equiv (max x y) y.
Proof.
refine (min_def2 A equiv flip_le _ flip_le_total).
- firstorder.
+ firstorder auto.
Qed.
End MaxDefault.
diff --git a/raster/Raster.v b/raster/Raster.v
index 096986e4..bd496647 100644
--- a/raster/Raster.v
+++ b/raster/Raster.v
@@ -70,8 +70,8 @@ Qed.
pixel. *)
Fixpoint updateVector A n (v : Vector.t A n) (f : A->A) : nat -> Vector.t A n :=
match v with
- | Vector.nil => fun _ => Vector.nil A
- | Vector.cons a' n' v' => fun i =>
+ | Vector.nil _ => fun _ => Vector.nil A
+ | Vector.cons _ a' n' v' => fun i =>
match i with
| 0 => Vector.cons A (f a') n' v'
| S i' => Vector.cons A a' n' (updateVector v' f i')
diff --git a/reals/OddPolyRootIR.v b/reals/OddPolyRootIR.v
index be4f4a08..56daccad 100644
--- a/reals/OddPolyRootIR.v
+++ b/reals/OddPolyRootIR.v
@@ -140,8 +140,8 @@ Let RX := (cpoly R).
Fixpoint flip (p : RX) : RX :=
match p with
- | cpoly_zero => cpoly_zero _
- | cpoly_linear c q => cpoly_inv _ (cpoly_linear _ c (flip q))
+ | cpoly_zero _ => cpoly_zero _
+ | cpoly_linear _ c q => cpoly_inv _ (cpoly_linear _ c (flip q))
end.
Lemma flip_poly : forall (p : RX) x, (flip p) ! x [=] [--]p ! ( [--]x).
diff --git a/reals/fast/CRAlternatingSum.v b/reals/fast/CRAlternatingSum.v
index 9f1c7395..a64860ae 100644
--- a/reals/fast/CRAlternatingSum.v
+++ b/reals/fast/CRAlternatingSum.v
@@ -472,7 +472,7 @@ Proof.
apply AbsSmall_minus.
stepr (InfiniteAlternatingSum seq); [| now (unfold cg_minus;simpl;ring)].
apply leEq_imp_AbsSmall;[apply InfiniteAlternatingSum_nonneg|].
- apply: leEq_transitive;simpl.
+ eapply leEq_transitive;simpl.
apply InfiniteAlternatingSum_bound.
assert ((hd seq)%CR == (1*hd seq)%Q). ring. rewrite -> H. clear H.
destruct X; assumption.
@@ -503,7 +503,7 @@ Proof.
with (-(Sum0 (G:=Q_as_CAbGroup) n
(fun n0 : nat => ((- (1)) ^ n0 * Str_nth n0 (tl seq)))))%Q.
simpl. ring.
- apply: eq_transitive;[|apply (inv_Sum0 Q_as_CAbGroup)].
+ eapply eq_transitive;[|apply (inv_Sum0 Q_as_CAbGroup)].
apply: Sum0_wd.
intros i; simpl.
change (Qpower_positive (- (1)) (P_of_succ_nat i)) with ((-(1))^ S i).
diff --git a/reals/fast/CRFieldOps.v b/reals/fast/CRFieldOps.v
index 021ef908..f603c326 100644
--- a/reals/fast/CRFieldOps.v
+++ b/reals/fast/CRFieldOps.v
@@ -111,7 +111,7 @@ Infix "<" := CRltT : CR_scope.
Lemma CRltT_wd : forall x1 x2, (x1==x2 -> forall y1 y2, y1==y2 -> x1 < y1 -> x2 < y2)%CR.
Proof.
intros x1 x2 Hx y1 y2 Hy H.
- apply: CRpos_wd;[|apply H].
+ apply: CRpos_wd. 3:apply H.
abstract ( rewrite <- Hx; rewrite <- Hy; reflexivity ).
Defined.
@@ -603,7 +603,7 @@ Proof.
intros e a0 a1 Ha.
simpl in *.
unfold Qball in *.
- apply: AbsSmall_cancel_mult.
+ eapply AbsSmall_cancel_mult.
instantiate (1:=(Qmax c a0)*(Qmax c a1)).
rewrite <- (QposAsmkQpos (Qpos_Qmax c a0)).
rewrite <- (QposAsmkQpos (Qpos_Qmax c a1)).
@@ -614,7 +614,7 @@ Proof.
rewrite <- (QposAsmkQpos (Qpos_Qmax a b)).
apply Qpos_nonzero.
stepr (Qmax c a1 - Qmax c a0); [| simpl; field; repeat split; apply H].
- apply: AbsSmall_leEq_trans.
+ eapply AbsSmall_leEq_trans.
instantiate (1:=(c*c*e)).
rewrite -> Qmult_comm.
apply mult_resp_leEq_lft;[|apply Qpos_nonneg].
diff --git a/reals/fast/CRGroupOps.v b/reals/fast/CRGroupOps.v
index 1b67845c..9755cd46 100644
--- a/reals/fast/CRGroupOps.v
+++ b/reals/fast/CRGroupOps.v
@@ -59,7 +59,7 @@ Qed.
Definition Qtranslate_uc (a:Q_as_MetricSpace) : Q_as_MetricSpace --> Q_as_MetricSpace :=
Build_UniformlyContinuousFunction (Qtranslate_uc_prf a).
-
+Transparent CR.
Definition translate (a:Q) : CR --> CR := Cmap QPrelengthSpace (Qtranslate_uc a).
Lemma translate_ident : forall x:CR, (translate 0 x==x)%CR.
@@ -71,10 +71,12 @@ Proof.
simpl.
ring.
simpl.
+Admitted.
+(*
rewrite -> H.
rewrite -> Cmap_fun_correct.
apply: MonadLaw1.
-Qed.
+Qed.*)
(** Lifting translate yields binary addition over CR. *)
Lemma Qplus_uc_prf : is_UniformlyContinuousFunction Qtranslate_uc Qpos2QposInf.
@@ -172,13 +174,14 @@ Proof.
unfold ucFun2, CRplus.
unfold Cmap2.
unfold inject_Q_CR.
- simpl.
- do 2 rewrite -> Cmap_fun_correct.
+Admitted.
+(*
+ simpl. do 2 rewrite -> Cmap_fun_correct.
rewrite -> Cap_fun_correct.
rewrite -> MonadLaw3.
rewrite -> StrongMonadLaw1.
reflexivity.
-Qed.
+Qed.*)
Hint Rewrite CRplus_translate : CRfast_compute.
@@ -186,8 +189,7 @@ Lemma translate_Qplus : forall a b:Q, (translate a ('b)=='(a+b)%Q)%CR.
Proof.
intros a b.
unfold translate, Cmap.
- simpl.
- rewrite -> Cmap_fun_correct.
+ setoid_rewrite -> Cmap_fun_correct.
apply: MonadLaw3.
Qed.
@@ -448,13 +450,14 @@ Proof.
unfold ucFun2, CRmax.
unfold Cmap2.
unfold inject_Q_CR.
- simpl.
+ simpl. (*
do 2 rewrite -> Cmap_fun_correct.
rewrite -> Cap_fun_correct.
rewrite -> MonadLaw3.
rewrite -> StrongMonadLaw1.
reflexivity.
-Qed.
+Qed.*)
+Admitted.
(** Basic properties of CRmax. *)
Lemma CRmax_ub_l : forall x y, (x <= CRmax x y)%CR.
Proof.
@@ -527,7 +530,7 @@ Proof.
apply Qplus_le_compat;[|apply Qmax_case;intro;assumption].
cut (ball ((1#2)*e)%Qpos (approximate z ((1#2)*((1 # 2) * e))%Qpos)
(approximate z ((1#2)*((1 # 2) * ((1 # 2) * e)))%Qpos));[intros [A B]; assumption|].
- apply: ball_weak_le;[|apply regFun_prf].
+ apply: ball_weak_le. 3:apply regFun_prf.
rewrite -> Qle_minus_iff.
autorewrite with QposElim.
ring_simplify.
@@ -583,14 +586,15 @@ Proof.
intros a y.
unfold ucFun2, CRmin.
unfold Cmap2.
- unfold inject_Q_CR.
- simpl.
+ unfold inject_Q_CR. (*
+ simpl.(
do 2 rewrite -> Cmap_fun_correct.
rewrite -> Cap_fun_correct.
rewrite -> MonadLaw3.
rewrite -> StrongMonadLaw1.
reflexivity.
-Qed.
+Qed.*)
+Admitted.
(** Basic properties of CRmin. *)
Lemma CRmin_lb_l : forall x y, (CRmin x y <= x)%CR.
@@ -665,7 +669,7 @@ Proof.
apply Qplus_le_compat;[|apply Qmin_case;intro;assumption].
cut (ball ((1#2)*e)%Qpos (approximate z ((1#2)*((1 # 2) * ((1 # 2) * e)))%Qpos)
(approximate z ((1#2)*((1 # 2) * e))%Qpos));[intros [A B]; assumption|].
- apply: ball_weak_le;[|apply regFun_prf].
+ apply: ball_weak_le. 3:apply regFun_prf.
rewrite -> Qle_minus_iff.
autorewrite with QposElim.
ring_simplify.
diff --git a/reals/fast/CRIR.v b/reals/fast/CRIR.v
index f36cec3b..1f3e1250 100644
--- a/reals/fast/CRIR.v
+++ b/reals/fast/CRIR.v
@@ -175,7 +175,7 @@ Lemma IR_div_as_CR : forall x y y_ y__,
(IRasCR (x[/]y[//]y_)==(IRasCR x[/]IRasCR y[//]y__))%CR.
Proof.
intros x y y_ y__.
- apply: mult_cancel_lft.
+ eapply mult_cancel_lft.
apply (map_pres_ap_zero _ _ (iso_map_rht _ _ CRIR_iso) y y_).
change ((IRasCR y[*]IRasCR (x[/]y[//]y_):CR)==IRasCR y*((IRasCR x[/]IRasCR y[//]y__):CR))%CR.
rewrite <- IR_mult_as_CR.
diff --git a/reals/fast/CRartanh_slow.v b/reals/fast/CRartanh_slow.v
index 038ef725..f351ea79 100644
--- a/reals/fast/CRartanh_slow.v
+++ b/reals/fast/CRartanh_slow.v
@@ -127,7 +127,7 @@ Proof.
clear IHn.
csetoid_replace (ArTanH_series_coef (double n)[*]nexp IR (double n) (inj_Q IR a[-][0])) ([0]:IR).
csetoid_replace (ArTanH_series_coef (S (double n))[*]A) (inj_Q IR (Str_nth n (arctanSequence a))).
- rational.
+ ring. (* rational.*)
unfold ArTanH_series_coef.
case_eq (even_odd_dec (S (double n))); intros H.
elim (not_even_and_odd _ H).
diff --git a/reals/fast/CRcorrect.v b/reals/fast/CRcorrect.v
index d9b2d531..619e241b 100644
--- a/reals/fast/CRcorrect.v
+++ b/reals/fast/CRcorrect.v
@@ -57,10 +57,10 @@ Proof.
rewrite <- anti_convert_pred_convert.
intros m Hm.
change (ball (en#ed) (approximate x (1 # P_of_succ_nat m)%Qpos) (approximate x (1#(2*ed)))%Qpos).
- apply: ball_weak_le;[|apply regFun_prf].
+ eapply ball_weak_le ;[|apply regFun_prf].
autorewrite with QposElim.
apply Qle_trans with (((1 # P_of_succ_nat (pred (nat_of_P (2*ed)))) + (1 # 2 * ed)))%Q.
- apply: plus_resp_leEq.
+ eapply plus_resp_leEq.
change (P_of_succ_nat (pred (nat_of_P (2*ed))) <= P_of_succ_nat m)%Z.
rewrite <-!POS_anti_convert. apply inj_le. omega.
rewrite <- anti_convert_pred_convert.
@@ -79,7 +79,7 @@ Build_CauchySeq _ _ (CRasCauchy_IR_raw_is_Cauchy x).
Lemma CRasCauchy_IR_wd : forall (x y:CR), (x==y)%CR -> CRasCauchy_IR x[=]CRasCauchy_IR y.
Proof.
intros x y Hxy.
- apply: Eq_alt_2_2.
+ eapply Eq_alt_2_2.
intros e He.
rewrite <- (QposAsmkQpos He).
generalize (mkQpos He).
@@ -92,12 +92,12 @@ Proof.
unfold CRasCauchy_IR_raw.
set (d:=(1 # P_of_succ_nat m)%Qpos).
change (ball (en#ed)%Qpos (approximate x d) (approximate y d)).
- apply: ball_weak_le;[|apply Hxy].
+ eapply ball_weak_le;[|apply Hxy].
unfold d.
autorewrite with QposElim.
ring_simplify.
apply Qle_trans with ((2#1)*(1#(2 * ed)))%Q.
- apply: mult_resp_leEq_lft;try discriminate.
+ eapply mult_resp_leEq_lft;try discriminate.
change ((2*ed)<=P_of_succ_nat m)%Z.
rewrite <- Zpos_mult_morphism.
rewrite (anti_convert_pred_convert (2*ed)).
@@ -136,15 +136,15 @@ Proof.
Qball (e1 + e2) (f n1) (f n2)).
intros H.
destruct (le_ge_dec n1 n2).
- apply: ball_sym;simpl.
+ eapply ball_sym;simpl.
setoid_replace (e1+e2)%Qpos with (e2+e1)%Qpos by QposRing.
apply H; assumption.
auto.
clear - Hf.
intros e1 e2 n1 n2 H Hn1 Hn2.
setoid_replace (e1+e2)%Qpos with (e2+e1)%Qpos by QposRing.
- apply: ball_weak.
- apply: Hn2.
+ eapply ball_weak.
+ eapply Hn2.
assumption.
Qed.
@@ -154,7 +154,7 @@ Build_RegularFunction (Cauchy_IRasCR_is_Regular x).
Lemma Cauchy_IRasCR_wd : forall (x y:Cauchy_IR), x[=]y -> (Cauchy_IRasCR x==Cauchy_IRasCR y)%CR.
Proof.
intros [x Hx] [y Hy] Hxy.
- apply: regFunEq_e.
+ eapply regFunEq_e.
intros e.
apply ball_closed.
intros d.
@@ -167,7 +167,7 @@ Proof.
set (n:=max (max a b) c).
stepr ((x a - x n) + (y n - y b) + (x n - y n))%Q; [| simpl; ring].
autorewrite with QposElim.
- repeat (apply: AbsSmall_plus).
+ repeat (eapply AbsSmall_plus).
apply AbsSmall_minus.
apply Ha;unfold n;apply le_trans with (max a b); auto with *.
apply Hb; unfold n;apply le_trans with (max a b); auto with *.
@@ -178,21 +178,21 @@ Qed.
Lemma CRasCR : forall x:CR, (Cauchy_IRasCR (CRasCauchy_IR x)==x)%CR.
Proof.
intros x.
- apply: regFunEq_e.
+ eapply regFunEq_e.
intros e.
simpl.
destruct (CRasCauchy_IR_raw_is_Cauchy x (e:Q) (Qpos_prf e)) as [n Hn].
unfold CRasCauchy_IR_raw in *.
- apply: ball_closed.
+ eapply ball_closed.
apply Qpos_positive_numerator_rect.
intros dn dd.
setoid_replace (e+e+(dn#dd))%Qpos with (e+((dn#dd)+e))%Qpos by QposRing.
apply ball_triangle with (approximate x (1#P_of_succ_nat (n+(nat_of_P dd))))%Qpos.
apply ball_sym.
- apply: Hn;auto with *.
- apply: ball_weak_le;[|apply regFun_prf].
+ eapply Hn;auto with *.
+ eapply ball_weak_le;[|apply regFun_prf].
autorewrite with QposElim.
- apply: plus_resp_leEq;simpl.
+ eapply plus_resp_leEq;simpl.
apply Qle_trans with (1#dd)%Q.
change (dd <= P_of_succ_nat (n + nat_of_P dd))%Z.
destruct n.
@@ -220,7 +220,7 @@ Qed.
Lemma Cauchy_IRasCauchy_IR : forall x:Cauchy_IR, CRasCauchy_IR (Cauchy_IRasCR x)[=]x.
Proof.
intros [x Hx].
- apply: Eq_alt_2_2.
+ eapply Eq_alt_2_2.
intros e He.
rewrite <- (QposAsmkQpos He).
set (e':=(mkQpos He)).
@@ -228,7 +228,7 @@ Proof.
clear e He.
assert (Z:(0<(1#2)*e')%Q).
rewrite <- (Qmult_0_r (1#2)).
- apply: mult_resp_less_lft.
+ eapply mult_resp_less_lft.
apply Qpos_prf.
constructor.
destruct (Hx _ Z) as [n Hn].
@@ -240,7 +240,7 @@ Proof.
destruct Hx as [n' Hn'].
apply AbsSmall_minus.
destruct (le_lt_dec n' m) as [H|H].
- apply: AbsSmall_trans;[|apply Hn';assumption].
+ eapply AbsSmall_trans;[|apply Hn';assumption].
change (ed < en*(P_of_succ_nat m))%Z.
apply Zlt_le_trans with (P_of_succ_nat m).
rewrite <- POS_anti_convert.
@@ -360,11 +360,11 @@ Lemma Cauchy_IR_inject_Q_as_CR_inject_Q : forall x:Q,
(' x == Cauchy_IRasCR (Cauchy_CReals.inject_Q _ x))%CR.
Proof.
intros x.
- apply: regFunEq_e.
+ eapply regFunEq_e.
intros e.
simpl.
destruct (CS_seq_const Q_as_COrdField x (e:Q) (Qpos_prf e)).
- apply: ball_refl.
+ eapply ball_refl.
Qed.
Hint Rewrite Cauchy_IR_inject_Q_as_CR_inject_Q : CRtoCauchy_IR.
@@ -373,7 +373,7 @@ Lemma CR_inject_Q_as_Cauchy_IR_inject_Q : forall x:Q,
Cauchy_CReals.inject_Q _ x [=] CRasCauchy_IR (' x)%CR.
Proof.
intros x.
- apply: Eq_alt_2_2.
+ eapply Eq_alt_2_2.
simpl.
intros e He.
exists 0.
@@ -390,7 +390,7 @@ Lemma Cauchy_IR_plus_as_CR_plus : forall x y:Cauchy_IR,
(Cauchy_IRasCR x + Cauchy_IRasCR y == Cauchy_IRasCR (x[+]y))%CR.
Proof.
intros [x Hx] [y Hy].
- apply: regFunEq_e.
+ eapply regFunEq_e.
intros e.
simpl.
unfold Cap_raw.
@@ -416,7 +416,7 @@ Proof.
rewrite (max_comm n1).
rewrite max_assoc.
auto with *.
- apply: Hn3; unfold n; auto with *.
+ eapply Hn3; unfold n; auto with *.
Qed.
Hint Rewrite Cauchy_IR_plus_as_CR_plus : CRtoCauchy_IR.
@@ -433,7 +433,7 @@ Lemma Cauchy_IR_opp_as_CR_opp : forall x:Cauchy_IR,
(-Cauchy_IRasCR x == Cauchy_IRasCR ([--]x))%CR.
Proof.
intros [x Hx].
- apply: regFunEq_e.
+ eapply regFunEq_e.
intros e.
simpl.
destruct (Hx (e:Q) (Qpos_prf e)) as [n1 Hn1].
@@ -472,17 +472,17 @@ Proof.
assert (m2:n1<=m);[unfold m; apply le_trans with (max n1 n2); auto with *|].
assert (m3:n2<=m);[unfold m; apply le_trans with (max n1 n2); auto with *|].
apply (Qle_not_lt _ _ H1').
- apply: inv_cancel_less;simpl.
+ eapply inv_cancel_less;simpl.
clear H1'.
autorewrite with QposElim in *.
apply Qlt_le_trans with ((2#3)*e)%Q.
ring_simplify.
- apply: mult_resp_less.
+ eapply mult_resp_less.
constructor.
assumption.
stepl (e + - ((1#2)*((1#3)*e)) + - ((1#2)*((1#3)*e)))%Q; [| simpl; ring].
stepr ((x m - y m) + (y m - y n1) + -(x m - x n2))%Q; [| simpl; ring].
- apply: plus_resp_leEq_both.
+ eapply plus_resp_leEq_both.
apply plus_resp_leEq_both.
apply H2; assumption.
refine (proj1 (Hn1 m _));assumption.
@@ -507,7 +507,7 @@ Proof.
unfold cg_minus.
simpl.
stepr ((x m - x n2) + -(y m - y n1) + -(y n1 + - x n2))%Q; [| simpl; ring].
- apply: plus_resp_leEq.
+ eapply plus_resp_leEq.
stepl (-((1 # 2) * e) + - ((1 # 2) * e))%Q; [| simpl; ring].
apply plus_resp_leEq_both.
refine (proj1 (Hn2 _ _)).
@@ -535,7 +535,7 @@ forall (z:Qpos) (N:nat), (forall i:nat, (N<=i) -> AbsSmall (z:Q) (CS_seq _ y i))
Proof.
intros [x Hx] y z N Hz.
destruct y as [y Hy].
- apply: regFunEq_e.
+ eapply regFunEq_e.
intros e.
simpl.
destruct CS_seq_mult as [n3 Hn3].
@@ -551,7 +551,7 @@ Proof.
ring.
rewrite -> H. clear H.
change (ball (e+e) (0 * y n) (x n3 * y n3))%Q.
- apply ball_triangle with (x n*y n)%Q;[|apply: Hn3; unfold n; auto with *].
+ apply ball_triangle with (x n*y n)%Q;[|eapply Hn3; unfold n; auto with *].
apply ball_sym.
simpl.
rewrite <- Hxn1.
@@ -571,7 +571,7 @@ Proof.
assert (n3 <= n);[unfold n; apply le_trans with (max n3 N); auto with *|].
assert (N <= n);[unfold n; apply le_trans with (max n3 N); auto with *|].
change (Qball (e+e)) with (@ball Q_as_MetricSpace (e + e)).
- apply ball_triangle with (x n * y n)%Q;[|apply: Hn3; assumption].
+ apply ball_triangle with (x n * y n)%Q;[|eapply Hn3; assumption].
clear Hn3.
setoid_replace e with ((1#2)*e + (1#2)*e)%Qpos by QposRing.
apply ball_triangle with (x n1 * y n)%Q; apply ball_sym; simpl; unfold Qball.
@@ -602,12 +602,12 @@ Proof.
apply X1.
rewrite -> Qle_minus_iff.
stepr ((y n + (-1 # 1) * y n2 + w)+(y n2 + - z))%Q; [| simpl; ring].
- apply: plus_resp_nonneg; assumption.
- apply: leEq_imp_AbsSmall; simpl; ring_simplify.
+ eapply plus_resp_nonneg; assumption.
+ eapply leEq_imp_AbsSmall; simpl; ring_simplify.
apply X0.
rewrite -> Qle_minus_iff.
stepr ((w + (-1 # 1) * y n + y n2)+(- z + - y n2))%Q; [| simpl; ring].
- apply: plus_resp_nonneg; assumption.
+ eapply plus_resp_nonneg; assumption.
stepr ((x n - x n1)*y n)%Q; [| simpl; ring].
autorewrite with QposElim.
stepl (((1#2)*e/z)*z)%Q; [| simpl; field; apply Qpos_nonzero].
@@ -631,7 +631,7 @@ Proof.
apply inv_resp_AbsSmall.
assumption.
rewrite -> X.
- apply: H2.
+ eapply H2.
rewrite -> Qle_minus_iff in H.
ring_simplify in H.
ring_simplify.
@@ -663,7 +663,7 @@ Proof.
auto with *.
apply Cauchy_IR_mult_as_CRmult_bounded with n.
intros i Hi.
- apply: AbsSmall_trans;[|apply Hn;assumption].
+ eapply AbsSmall_trans;[|apply Hn;assumption].
simpl.
rewrite -> Qlt_minus_iff.
unfold k'.
@@ -693,7 +693,7 @@ Proof.
exists (mkQpos He).
abstract ( autorewrite with CRtoCauchy_IR; intros [m [d Hd Hm]];
refine (Qle_not_lt _ _ (Hn (max n m) _) _);[auto with *|]; rewrite -> Qlt_minus_iff;
- apply Qlt_le_trans with d;[assumption|]; autorewrite with QposElim in Hm; apply: Hm; auto with *
+ apply Qlt_le_trans with d;[assumption|]; autorewrite with QposElim in Hm; eapply Hm; auto with *
).
Defined.
@@ -703,7 +703,7 @@ Proof.
intros x y [e He].
apply shift_zero_less_minus'.
apply (less_leEq_trans _ [0] (Cauchy_CReals.inject_Q _ (e:Q))).
- apply: ing_lt.
+ eapply ing_lt.
apply Qpos_prf.
unfold cg_minus.
stepr (CRasCauchy_IR (y-x))%CR.
@@ -711,11 +711,11 @@ Proof.
rewrite <- Cauchy_IR_le_as_CR_le.
do 2 rewrite -> CRasCR.
assumption.
- apply: CR_inject_Q_as_Cauchy_IR_inject_Q.
+ eapply CR_inject_Q_as_Cauchy_IR_inject_Q.
stepl (CRasCauchy_IR y[+]CRasCauchy_IR(- x)%CR).
apply plus_resp_eq.
- apply: CR_opp_as_Cauchy_IR_opp.
- apply: CR_plus_as_Cauchy_IR_plus.
+ eapply CR_opp_as_Cauchy_IR_opp.
+ eapply CR_plus_as_Cauchy_IR_plus.
Qed.
Lemma Cauchy_IR_lt_as_CR_lt_2 : forall (x y:Cauchy_IR),
@@ -768,7 +768,7 @@ forall (z:Qpos) (N:nat), (forall i:nat, (N<=i) -> (z <= (CS_seq _ x i))%Q) ->
(CRinv_pos z (Cauchy_IRasCR x) == Cauchy_IRasCR (f_rcpcl x (@inr _ _ x_)))%CR.
Proof.
intros [x Hx] [a [d d_ x_]] z n Hn.
- apply: regFunEq_e.
+ eapply regFunEq_e.
intros e.
simpl.
unfold Qinv_modulus.
@@ -785,7 +785,7 @@ Proof.
assert (Hm1: c<=m).
unfold m; apply le_trans with (max b c); auto with *.
change (ball (e+e) (/ Qmax z (x b))%Q (y c)).
- apply ball_triangle with (y m);[|apply: Hc;assumption].
+ apply ball_triangle with (y m);[|eapply Hc;assumption].
clear Hc.
unfold y.
destruct (lt_le_dec m a) as [Z|Z].
@@ -795,7 +795,7 @@ Proof.
change (AbsSmall (e:Q) (/ Qmax z (x b)-1 * / x m))%Q.
clear y.
assert (T:(~ (x m == 0)%Q /\ ~ (Qmax z (x b) == 0)%Q)).
- split; apply (ap_symmetric_unfolded Q_as_CSetoid); apply: Qlt_not_eq.
+ split; apply (ap_symmetric_unfolded Q_as_CSetoid); eapply Qlt_not_eq.
apply Qlt_le_trans with z.
apply Qpos_prf.
apply Hn.
@@ -861,7 +861,7 @@ Proof.
stepr (CRasCauchy_IR 0%CR).
apply CR_ap_as_Cauchy_IR_ap_1.
assumption.
- apply: CR_inject_Q_as_Cauchy_IR_inject_Q.
+ eapply CR_inject_Q_as_Cauchy_IR_inject_Q.
Defined.
Lemma Cauchy_IR_inv_as_CR_inv_short : forall (x:Cauchy_IR) x_,
@@ -883,16 +883,16 @@ Proof.
set (X := (Cauchy_IRasCR (f_rcpcl (F:=Cauchy_IR) [--](x':Cauchy_IR)
(@inr (R_lt Q_as_COrdField [--](x':Cauchy_IR) ([0]:Cauchy_IR)) ([0][<][--](x':Cauchy_IR)) H')))%CR).
rewrite -> Cauchy_IR_opp_as_CR_opp.
- apply: Cauchy_IR_inv_as_CRinv_pos.
+ eapply Cauchy_IR_inv_as_CRinv_pos.
intros i Hi.
autorewrite with QposElim.
simpl.
stepr (0 - x i)%Q; [| simpl; ring].
- apply: H.
+ eapply H.
apply Hi.
unfold y.
apply Cauchy_IRasCR_wd.
- apply: mult_cancel_lft.
+ eapply mult_cancel_lft.
left.
apply H.
stepr ([1]:Cauchy_IR).
@@ -905,7 +905,7 @@ Proof.
apply eq_symmetric.
apply x_div_x.
destruct H as [n [e He H]].
- apply: Cauchy_IR_inv_as_CRinv_pos.
+ eapply Cauchy_IR_inv_as_CRinv_pos.
intros i Hi.
autorewrite with QposElim.
simpl in *.
diff --git a/reals/fast/CRexp.v b/reals/fast/CRexp.v
index 869171e6..2b5c714e 100644
--- a/reals/fast/CRexp.v
+++ b/reals/fast/CRexp.v
@@ -372,7 +372,7 @@ Qed.
Definition rational_exp_neg (a:Q) : a <= 0 -> CR.
Proof.
intros Ha.
- refine (@rational_exp_neg_bounded _ a _).
+ eapply (rational_exp_neg_bounded).
split.
apply (rational_exp_bound_power_2 Ha).
apply Ha.
diff --git a/reals/fast/CRroot.v b/reals/fast/CRroot.v
index 1f8b54b1..69a93f3c 100644
--- a/reals/fast/CRroot.v
+++ b/reals/fast/CRroot.v
@@ -734,11 +734,11 @@ Qed.
Definition rational_sqrt_pos a (Ha:0 X.
rewrite -> StepFSupBallGlueGlue.
split.
- apply: ball_weak_le;[|simpl; apply H0].
+ eapply ball_weak_le;[|simpl; apply H0].
autorewrite with QposElim.
apply Qplus_le_compat; apply Qmax_ub_l.
- apply: ball_weak_le;[|simpl; apply H1].
+ eapply ball_weak_le;[|simpl; apply H1].
autorewrite with QposElim.
apply Qplus_le_compat; apply Qmax_ub_r.
Qed.
diff --git a/reals/fast/Interval.v b/reals/fast/Interval.v
index d9005aab..623ca205 100644
--- a/reals/fast/Interval.v
+++ b/reals/fast/Interval.v
@@ -494,7 +494,7 @@ Lemma CompactIntervalQ_bonus_correct : forall e x,
Proof.
intros [e|] x H.
simpl in H.
- apply: UniformPartition_inside.
+ eapply UniformPartition_inside.
apply H.
elim H.
Qed.
diff --git a/reals/fast/ModulusDerivative.v b/reals/fast/ModulusDerivative.v
index a354fc66..14437e95 100644
--- a/reals/fast/ModulusDerivative.v
+++ b/reals/fast/ModulusDerivative.v
@@ -138,7 +138,7 @@ Proof.
auto.
assert (Z:[0][<]inj_Q IR (y:Q)).
(stepl (inj_Q IR ([0]:Q)); [| now apply (inj_Q_nring IR 0)]); apply inj_Q_less; apply Qpos_prf.
- apply: eq_transitive.
+ eapply eq_transitive.
apply mult_wdl.
apply (inj_Q_div IR e _ (pos_ap_zero _ _ Z)).
apply div_1.
diff --git a/reals/fast/MultivariatePolynomials.v b/reals/fast/MultivariatePolynomials.v
index c098304a..22dadbf9 100644
--- a/reals/fast/MultivariatePolynomials.v
+++ b/reals/fast/MultivariatePolynomials.v
@@ -194,8 +194,8 @@ Open Local Scope Q_scope.
(** Definition of the unit hyperinterval of n dimensions *)
Fixpoint UnitHyperInterval (n:nat) (v:Vector.t Q n) : Prop :=
match v with
-| Vector.nil => True
-| Vector.cons a _ v' => 0 <= a <= 1 /\ UnitHyperInterval v'
+| Vector.nil _ => True
+| Vector.cons _ a _ v' => 0 <= a <= 1 /\ UnitHyperInterval v'
end.
(* begin hide *)
@@ -229,8 +229,8 @@ Qed.
(** Return the ith entry of a vector *)
Fixpoint Vector_ix A (n i:nat) (H:(i < n)%nat) (v:Vector.t A n) : A :=
match v in Vector.t _ m return (i < m)%nat -> A with
-| Vector.nil => fun p => False_rect _ (lt_n_O _ p)
-| Vector.cons c n' v' => fun _ => match lt_le_dec i n' with
+| Vector.nil _ => fun p => False_rect _ (lt_n_O _ p)
+| Vector.cons _ c n' v' => fun _ => match lt_le_dec i n' with
| left p => Vector_ix p v'
| right _ => c
end
@@ -884,11 +884,11 @@ Lemma MVP_uc_fun_close_weaken : forall n (e1 e2:Qpos) f g, (e1 <= e2) ->
MVP_uc_fun_close_sig n e2 f g.
Proof.
induction n; intros e1 e2 f g He H.
- apply: ball_weak_le.
+ eapply ball_weak_le.
apply He.
apply H.
intros x Hx0 Hx1.
- apply: IHn.
+ eapply IHn.
apply He.
apply H; auto.
Qed.
@@ -925,7 +925,7 @@ Proof.
apply H0.
apply H1.
intros x Hx0 Hx1.
- apply: IHn.
+ eapply IHn.
apply H0; auto.
apply H1; auto.
Qed.
@@ -940,7 +940,7 @@ Proof.
apply H0.
apply H1.
intros x Hx0 Hx1.
- apply: IHn.
+ eapply IHn.
apply H0; auto.
apply H1; auto.
Qed.
@@ -964,7 +964,7 @@ Proof.
induction n.
apply ball_triangle.
intros e1 e2 f g h H0 H1 x Hx0 Hx1.
- apply: IHn.
+ eapply IHn.
apply H0; auto.
apply H1; auto.
Qed.
@@ -1150,7 +1150,7 @@ Proof.
apply Qpos_nonzero.
elim (Qle_not_lt 0 (Zneg nb # db)); auto with *.
rewrite <- CRle_Qle.
- apply: AbsSmall_nonneg.
+ eapply AbsSmall_nonneg.
apply Hb.
cut (Not (Not (AbsSmall (CRabs p[*](' q)%CR) (p[*](x[-]y))))).
unfold Not, AbsSmall.
@@ -1218,8 +1218,8 @@ match n return MultivariatePolynomial Q_as_CRing n -> Q with
| O => Qabs
| S n' => fix MVP_poor_Bound01_H p : Q :=
match p with
- | cpoly_zero => 0
- | cpoly_linear s p' => MVP_poor_Bound01 n' s + MVP_poor_Bound01_H p'
+ | cpoly_zero _ => 0
+ | cpoly_linear _ s p' => MVP_poor_Bound01 n' s + MVP_poor_Bound01_H p'
end
end.
@@ -1296,8 +1296,8 @@ Proof.
intros y _ _.
apply IHn.
change (MVP_is_Bound01 n (' (MVP_poor_Bound01 n s + (fix MVP_poor_Bound01_H (p0 : cpoly
- (MultivariatePolynomial Q_as_CRing n)) : Q := match p0 with | cpoly_zero => 0
- | cpoly_linear s0 p' => (MVP_poor_Bound01 n s0 + MVP_poor_Bound01_H p')%Q end) p)%Q)%CR
+ (MultivariatePolynomial Q_as_CRing n)) : Q := match p0 with | cpoly_zero _ => 0
+ | cpoly_linear _ s0 p' => (MVP_poor_Bound01 n s0 + MVP_poor_Bound01_H p')%Q end) p)%Q)%CR
(MVP_map inject_Q_hom n s[+]MVP_C_ CRasCRing n x[*](cpoly_map (MVP_map inject_Q_hom n) p) ! (MVP_C_ CRasCRing n x))).
rewrite <- CRplus_Qplus.
apply MVP_is_Bound01_plus.
diff --git a/reals/faster/ARArith.v b/reals/faster/ARArith.v
index cf1e81eb..b3b57909 100644
--- a/reals/faster/ARArith.v
+++ b/reals/faster/ARArith.v
@@ -426,7 +426,7 @@ Proof.
apply orders.eq_le.
rewrite (commutativity _ k), shiftl.shiftl_exp_plus, shiftl.shiftl_1.
rewrite rings.plus_mult_distr_r, rings.mult_1_l.
- rewrite rings.negate_plus_distr, associativity, rings.plus_negate_r. ring.
+ rewrite rings.negate_plus_distr, associativity, rings.plus_negate_r. ring.
apply (order_reflecting (cast AQ Q)).
rewrite rings.preserves_negate.
exact (E ('Pos_shiftl (1 : AQ₊) k)).
diff --git a/stdlib_omissions/List.v b/stdlib_omissions/List.v
index f6adeeef..8013bc2f 100644
--- a/stdlib_omissions/List.v
+++ b/stdlib_omissions/List.v
@@ -139,8 +139,6 @@ Proof with auto.
reflexivity.
Qed.
-Existing Instance Permutation_map_aux_Proper.
-
Instance: forall A (x: A), Proper (@Permutation A ==> iff) (@In A x).
Proof. pose proof Permutation_in. firstorder. Qed.
diff --git a/stdlib_omissions/Z.v b/stdlib_omissions/Z.v
index 9f8efbb6..5d1131c7 100644
--- a/stdlib_omissions/Z.v
+++ b/stdlib_omissions/Z.v
@@ -1,5 +1,4 @@
-
-Require Import ZArith NPeano stdlib_omissions.P.
+Require Import ZArith NPeano NSigNAxioms stdlib_omissions.P.
Open Scope Z_scope.
@@ -60,7 +59,7 @@ Proof.
rewrite <- inj_mult.
rewrite <- inj_plus.
apply inj_eq.
- apply div_mod.
+ apply Nat.div_mod.
assumption.
Qed.
@@ -73,7 +72,7 @@ Proof with auto with *.
apply Nat.mod_upper_bound...
rewrite <- div_Zdiv...
rewrite <- inj_mult, <- inj_plus.
- apply inj_eq, div_mod...
+ apply inj_eq, Nat.div_mod...
Qed.
Lemma P_of_succ_nat_Zplus (m: nat): Zpos (P_of_succ_nat m) = Z_of_nat m + 1.
diff --git a/tactics/csetoid_rewrite.v b/tactics/csetoid_rewrite.v
index 7df6f4fe..4423fa37 100644
--- a/tactics/csetoid_rewrite.v
+++ b/tactics/csetoid_rewrite.v
@@ -174,10 +174,10 @@ Inductive tot_set_exp (S:CSetoid) : CSetoid -> Type :=
Fixpoint tse_int (S T:CSetoid) (r:S) (e:tot_set_exp S T) {struct e} : T :=
match e with
- | tse_var => r
- | tse_fun T1 T2 f e0 => f (tse_int S T1 r e0)
- | tse_bfun T1 T2 T3 f e1 e2 => f (tse_int S T1 r e1) (tse_int S T2 r e2)
- | tse_con T t => t
+ | tse_var _ => r
+ | tse_fun _ T1 T2 f e0 => f (tse_int S T1 r e0)
+ | tse_bfun _ T1 T2 T3 f e1 e2 => f (tse_int S T1 r e1) (tse_int S T2 r e2)
+ | tse_con _ T t => t
end.
(** [tse_int] is well-defined. *)
@@ -645,12 +645,12 @@ Inductive my_sigT (A:Type) (P:A -> Type) : Type :=
Definition proj1_my_sigT (A:Type) (P:A -> Type) (e:my_sigT A P) :=
match e with
- | my_existT a b => a
+ | my_existT _ _ a b => a
end.
Definition proj2_my_sigT (A:Type) (P:A -> Type) (e:my_sigT A P) :=
match e return P (proj1_my_sigT A P e) with
- | my_existT a b => b
+ | my_existT _ _ a b => b
end.
Set Implicit Arguments.
@@ -715,9 +715,9 @@ extracts the syntactical component from heavy expressions. *)
Fixpoint forget (t:T) (e:part_set_xexp t) {struct e} : part_set_exp :=
match e with
| psxe_var => pse_var
- | psxe_uop F t0 e0 => pse_uop F (forget e0)
- | psxe_bop F t1 t2 e1 e2 => pse_bop F (forget e1) (forget e2)
- | psxe_pop F t0 H e0 => pse_pop F (forget e0)
+ | psxe_uop F e0 => pse_uop F (forget e0)
+ | psxe_bop F e1 e2 => pse_bop F (forget e1) (forget e2)
+ | @psxe_pop F _ _ e0 => pse_pop F (forget e0)
| psxe_con t => pse_con t
end.
diff --git a/transc/ArTanH.v b/transc/ArTanH.v
index b128c9b1..37218126 100644
--- a/transc/ArTanH.v
+++ b/transc/ArTanH.v
@@ -146,7 +146,7 @@ Proof.
exists Hcd.
split.
intros y [Hy _].
- apply: less_leEq_trans;[|apply Hy].
+ eapply less_leEq_trans ;[|apply Hy].
apply div_resp_pos.
assumption.
destruct (H _ (compact_inc_lft _ _ Hab)) as [A _].
diff --git a/transc/MoreArcTan.v b/transc/MoreArcTan.v
index 857c86cb..6fcf492a 100644
--- a/transc/MoreArcTan.v
+++ b/transc/MoreArcTan.v
@@ -297,7 +297,7 @@ Proof.
rational.
elimtype False.
refine (eq_imp_not_ap _ [--][1] [1] _ _).
- now stepr x.
+ 2: now stepr x.
apply ap_symmetric.
apply zero_minus_apart.
rstepl (Two:IR).
diff --git a/util/Qdlog.v b/util/Qdlog.v
index 5616b172..a8324428 100644
--- a/util/Qdlog.v
+++ b/util/Qdlog.v
@@ -29,8 +29,7 @@ Proof.
apply dec_fields.flip_lt_dec_recip_r; trivial.
apply orders.lt_iff_le_ne. tauto.
now apply Qle_ceiling.
- split.
- rewrite int_pow_negate.
+ split. setoid_rewrite int_pow_negate.
apply dec_fields.flip_le_dec_recip_l; trivial.
transitivity ('Qceiling (/x)).
now apply Qle_ceiling.
@@ -169,9 +168,9 @@ Definition Qdlog (n : Z) (x : Q) : Z := Qdlog_bounded (Zabs_nat (Qdlog2 x)) n x.
Lemma Qdlog_bounded_nonneg (b : nat) (n : Z) (x : Q) :
0 ≤ Qdlog_bounded b n x.
Proof.
- revert x. induction b; simpl; [reflexivity |].
+ revert x. induction b; unfold Qdlog_bounded; [reflexivity |].
intros. case (decide_rel _); intros; [reflexivity |].
- apply semirings.nonneg_plus_compat; [easy | apply IHb].
+ apply semirings.nonneg_plus_compat ; [easy | apply IHb].
Qed.
Lemma Qdlog2_le1 (n : Z) (x : Q) :
@@ -212,7 +211,7 @@ Proof.
assert (0 < ('n : Q))
by (apply orders.lt_le_trans with 2; [solve_propholds | assumption]).
revert x Eb Ex.
- induction b; simpl.
+ induction b.
intros x Eb Ex.
split; [assumption|].
apply orders.lt_le_trans with 2; try assumption.
@@ -221,7 +220,7 @@ Proof.
apply (antisymmetry (≤)); try assumption.
now apply Qdlog2_nonneg.
intros x Eb Ex.
- case (decide_rel _); [intuition |]; intros E.
+ unfold Qdlog_bounded. case (decide_rel _); [intuition |]; intros E.
apply orders.not_lt_le_flip in E.
assert (x = 'n * (x / 'n)) as Ex2.
rewrite (commutativity x), associativity.
@@ -241,8 +240,8 @@ Proof.
rewrite <-Qdlog2_half.
now apply rings.flip_le_minus_l.
now apply orders.lt_le_trans with 1; [solve_propholds | assumption].
- rewrite int_pow_S_nonneg by (now apply Qdlog_bounded_nonneg).
- rewrite int_pow_S_nonneg by (apply semirings.nonneg_plus_compat; [easy | now apply Qdlog_bounded_nonneg]).
+ fold Qdlog_bounded. setoid_rewrite int_pow_S_nonneg at 1. 2: apply Qdlog_bounded_nonneg.
+ setoid_rewrite int_pow_S_nonneg. 2: (apply semirings.nonneg_plus_compat; [easy | now apply Qdlog_bounded_nonneg]).
setoid_rewrite Ex2 at 2 3.
split.
now apply (order_preserving (('n:Q) *.)).
diff --git a/util/Qsums.v b/util/Qsums.v
index f8708139..ef2f6e23 100644
--- a/util/Qsums.v
+++ b/util/Qsums.v
@@ -150,7 +150,7 @@ Proof with intuition.
Qed.
Lemma Qmult_Σ (f: nat -> Q) n (k: nat):
- Σ n f * k == Σ (k * n) (f ∘ flip div k).
+ Σ n f * k == Σ (k * n) (f ∘ flip Nat.div k).
Proof with auto with *.
unfold Basics.compose.
rewrite mult_comm.
@@ -168,7 +168,7 @@ Proof with auto with *.
Qed.
Lemma Σ_multiply_bound n (k: positive) (f: nat -> Q):
- Σ n f == Σ (k * n) (f ∘ flip div k) / k.
+ Σ n f == Σ (k * n) (f ∘ flip Nat.div k) / k.
Proof.
rewrite <- Qmult_Σ.
rewrite <- Zpos_eq_Z_of_nat_o_nat_of_P.
diff --git a/util/SetoidPermutation.v b/util/SetoidPermutation.v
index 838f4233..599005c9 100644
--- a/util/SetoidPermutation.v
+++ b/util/SetoidPermutation.v
@@ -105,5 +105,5 @@ Proof with simpl; auto; try reflexivity.
apply s_perm_trans with (map y l')...
apply s_perm_trans with (map x l')...
clear IHX1 IHX2 X1 X2.
- induction l'... intuition.
+ induction l'... constructor. now symmetry; apply H1. easy.
Qed.
From e1a44aad80a53a07ea443ea3a16efd5367bdd194 Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Fri, 29 Aug 2014 17:21:14 +0200
Subject: [PATCH 099/110] Making compile with trunk
---
ode/AbstractIntegration.v | 12 ++++++++----
ode/Picard.v | 23 +++++++++++++----------
reals/fast/CRartanh_slow.v | 10 +++++-----
reals/faster/ARAlternatingSum.v | 5 +++--
reals/faster/ARArith.v | 6 +++---
reals/faster/ARQ.v | 3 ++-
reals/faster/ARarctan_small.v | 4 ++--
reals/faster/ARpi.v | 3 ++-
reals/faster/ARsin.v | 5 ++---
util/Extract.v | 3 ++-
10 files changed, 42 insertions(+), 32 deletions(-)
diff --git a/ode/AbstractIntegration.v b/ode/AbstractIntegration.v
index cd4b9c41..f0f83ccf 100644
--- a/ode/AbstractIntegration.v
+++ b/ode/AbstractIntegration.v
@@ -957,7 +957,9 @@ Qed.
Lemma int_abs_bound (a b M : Q) :
(forall x : Q, x ∈ (a, b) -> abs (f x) ≤ 'M) -> abs (int a b) ≤ '(abs (b - a) * M).
Proof.
-intros A. unfold int. destruct (decide (a ≤ b)) as [AB | AB];
+intros A. unfold int.
+(* Looks like a type class regression *)
+ admit. (*destruct (decide (a ≤ b)) as [AB | AB];
[| pose proof (orders.le_flip _ _ AB); mc_setoid_replace (b - a) with (-(a - b)) by ring;
rewrite CRabs_negate, abs.abs_negate];
rewrite abs.abs_nonneg by (now apply rings.flip_nonneg_minus);
@@ -966,7 +968,7 @@ intros x A1; apply A.
+ apply -> range_le; [| easy].
now mc_setoid_replace b with (a + (b - a)) by ring.
+ apply Qrange_comm. apply -> range_le; [| easy].
- now mc_setoid_replace a with (b + (a - b)) by ring.
+ now mc_setoid_replace a with (b + (a - b)) by ring.*)
Qed.
(* [SearchAbout (CRabs (- ?x)%CR)] does not find [CRabs_opp] *)
@@ -998,7 +1000,8 @@ set (n := Pos.max (Pos.max Nf Ng) Ns).
assert (Nf <= n)%positive by (transitivity (Pos.max Nf Ng); apply Pos.le_max_l).
assert (Ng <= n)%positive by (transitivity (Pos.max Nf Ng); [apply Pos.le_max_r | apply Pos.le_max_l]).
assert (Ns <= n)%positive by apply Pos.le_max_r.
-apply (mspc_triangle' (e / 2) (e / 2) (riemann_sum (f + g) a w n)); [field; discriminate | |].
+apply (mspc_triangle' (e / 2) (e / 2) (riemann_sum (f + g) a w n)).
+ (* regression connected to numbers ? [field; discriminate | |].*) admit.
* apply mspc_symm, S; assumption.
* rewrite riemann_sum_plus.
mc_setoid_replace (e / 2) with (e / 4 + e / 4) by (field; split; discriminate).
@@ -1016,7 +1019,8 @@ destruct (integral_approximation f a w (mkQpos he_pos)) as [N2 F2].
set (n := Pos.max N1 N2).
assert (N1 <= n)%positive by apply Pos.le_max_l.
assert (N2 <= n)%positive by apply Pos.le_max_r.
-apply (mspc_triangle' (e / 2) (e / 2) (riemann_sum (- f) a w n)); [field; discriminate | |].
+apply (mspc_triangle' (e / 2) (e / 2) (riemann_sum (- f) a w n)).
+(* regression connected to numbers ? [field; discriminate | |].*) admit.
* now apply mspc_symm, F1.
* rewrite riemann_sum_negate. now apply mspc_ball_CRnegate, F2.
Qed.
diff --git a/ode/Picard.v b/ode/Picard.v
index 3d971867..c33574df 100644
--- a/ode/Picard.v
+++ b/ode/Picard.v
@@ -1,17 +1,18 @@
Require Import
Unicode.Utf8 Program
CRArith CRabs
- Qauto Qround Qmetric
- (*stdlib_omissions.P
+ Qauto Qround Qmetric.
+ (* stdlib_omissions.P
stdlib_omissions.Z
stdlib_omissions.Q
- stdlib_omissions.N*).
+ stdlib_omissions.N. *)
Require Qinf QnonNeg QnnInf CRball.
Import
QnonNeg Qinf.notations QnonNeg.notations QnnInf.notations CRball.notations
Qabs propholds.
+Require Import stdlib_rationals theory.rationals.
Require Import metric FromMetric2 AbstractIntegration SimpleIntegration BanachFixpoint.
Require Import canonical_names decision setoid_tactics util.
@@ -79,7 +80,6 @@ change (abs (-e) ≤ e). rewrite abs.abs_negate, abs.abs_nonneg; [reflexivity |
Qed.
Context (f : sig (ball r a) -> Y).
-
(* Since the following is a Program Definition, we could write [f (a - r)]
and prove the obligation [mspc_ball r a (a - r)]. However, this obligation
would depend on x and [H1 : x ≤ a - r] even though they are not used in the
@@ -90,9 +90,14 @@ mspc_refl (see [extend_uc] below), we would need to prove that these
applications of f are equal, i.e., f is a morphism that does not depend on
the second component of the pair. So instead we prove mspc_ball_edge_l and
mspc_ball_edge_r, which don't depend on x. *)
+Global Existing Instance Q_lt.
+(* Goal True.
+Admitted.
+regression: numbers interacting with type classes ?
+Was; (decide x<(a-r))
Program Definition extend : Q -> Y :=
- λ x, if (decide (x < a - r))
+ λ x:Q, if (@decide rationals.slow_rat_dec (@lt Q Q_lt x (@plus Q Q_plus a (to_Q (@negate T _ r)))))
then f ((a - r) ↾ mspc_ball_edge_l)
else if (decide (a + r < x))
then f ((a + r) ↾ mspc_ball_edge_r)
@@ -152,9 +157,9 @@ destruct (decide (x1 < a - to_Q r)); destruct (decide (x2 < a - to_Q r)).
+ apply mspc_symm; apply mspc_symm in A. apply (nested_balls _ _ A)...
+ apply (nested_balls _ _ A)...
Qed.
-
+*)
End Extend.
-
+(*
Lemma extend_inside `{ExtMetricSpaceClass Y} (a x : Q) (r : QnonNeg) :
ball r a x -> exists p : ball r a x, forall f : sig (ball r a) -> Y,
extend a r f x = f (x ↾ p).
@@ -448,6 +453,4 @@ Qed.
Time Compute answer 2 (` (picard_iter 3 half)). (* 10 minutes *)
Time Compute answer 1 (` (f half)). (* Too long *)
*)
-
-End Computation.
-
+End Computation. *)
\ No newline at end of file
diff --git a/reals/fast/CRartanh_slow.v b/reals/fast/CRartanh_slow.v
index f351ea79..0ae00b3e 100644
--- a/reals/fast/CRartanh_slow.v
+++ b/reals/fast/CRartanh_slow.v
@@ -125,9 +125,9 @@ Proof.
fold (double n).
csetoid_rewrite_rev IHn.
clear IHn.
- csetoid_replace (ArTanH_series_coef (double n)[*]nexp IR (double n) (inj_Q IR a[-][0])) ([0]:IR).
- csetoid_replace (ArTanH_series_coef (S (double n))[*]A) (inj_Q IR (Str_nth n (arctanSequence a))).
- ring. (* rational.*)
+ setoid_replace (ArTanH_series_coef (double n)[*]nexp IR (double n) (inj_Q IR a[-][0])) with ([0]:IR).
+ setoid_replace (ArTanH_series_coef (S (double n))[*](nexp IR (Nat.double n)(inj_Q IR a [-] [0]) [*] (inj_Q IR a [-] [0])))
+ with (inj_Q IR (Str_nth n (arctanSequence a))). rational.
unfold ArTanH_series_coef.
case_eq (even_odd_dec (S (double n))); intros H.
elim (not_even_and_odd _ H).
@@ -167,8 +167,8 @@ Proof.
reflexivity.
unfold A; clear A.
eapply eq_transitive;[|apply eq_symmetric; apply inj_Q_power].
- change ((inj_Q IR a[-][0])[^](n+S n)[=]inj_Q IR a[^](1 + 2 * n)).
- replace (n + S n)%nat with (1 + 2*n)%nat by ring.
+ change ((inj_Q IR a[-][0])[^](S( n+ n))[=]inj_Q IR a[^](1 + 2 * n)).
+ replace (S (n + n))%nat with (1 + 2*n)%nat by ring.
apply nexp_wd.
rational.
unfold ArTanH_series_coef.
diff --git a/reals/faster/ARAlternatingSum.v b/reals/faster/ARAlternatingSum.v
index 0e2215a7..b4066fda 100644
--- a/reals/faster/ARAlternatingSum.v
+++ b/reals/faster/ARAlternatingSum.v
@@ -232,12 +232,13 @@ Lemma ARInfAltSum_length_ge (ε : Qpos) :
Proof.
transitivity (4 + takeUntil_length _ (LazyExists_Str_nth_tl (Limit_near sQ 0 ε) (dnn_in_Qball_0_EventuallyForall sQ ε) 4)).
apply takeUntil_length_Str_nth_tl.
- unfold ARInfAltSum_length.
+ unfold ARInfAltSum_length.
+ (* replace (Init.Nat.add (S (S (S (S O))))) with (plus (plus one (plus one (plus one one)))).
apply (order_preserving (4 +)).
apply takeUntil_length_ForAllIf.
apply ARInfAltSum_stream_preserves_ball.
now apply DivisionStream_Str_nth_tl.
- now apply _.
+ now apply _.*) admit.
Qed.
Lemma ARInfAltSum_length_pos (k : Z) :
diff --git a/reals/faster/ARArith.v b/reals/faster/ARArith.v
index b3b57909..8f093794 100644
--- a/reals/faster/ARArith.v
+++ b/reals/faster/ARArith.v
@@ -426,7 +426,7 @@ Proof.
apply orders.eq_le.
rewrite (commutativity _ k), shiftl.shiftl_exp_plus, shiftl.shiftl_1.
rewrite rings.plus_mult_distr_r, rings.mult_1_l.
- rewrite rings.negate_plus_distr, associativity, rings.plus_negate_r. ring.
+ rewrite rings.negate_plus_distr, associativity, rings.plus_negate_r. simpl. ring.
apply (order_reflecting (cast AQ Q)).
rewrite rings.preserves_negate.
exact (E ('Pos_shiftl (1 : AQ₊) k)).
@@ -611,8 +611,8 @@ Hint Rewrite ARtoCR_preserves_inv_pos : ARtoCR.
Definition ARinvT (x : AR) (x_ : ARapartT x 0) : AR :=
match x_ with
- | inl (exist c _) => - ARinv_pos c (- x)
- | inr (exist c _) => ARinv_pos c x
+ | inl (exist _ c _) => - ARinv_pos c (- x)
+ | inr (exist _ c _) => ARinv_pos c x
end.
Lemma ARtoCR_preserves_invT x x_ x__:
diff --git a/reals/faster/ARQ.v b/reals/faster/ARQ.v
index ca01ce20..46c8140a 100644
--- a/reals/faster/ARQ.v
+++ b/reals/faster/ARQ.v
@@ -30,7 +30,8 @@ Instance: AppRationals Q.
Proof.
split; try apply _.
repeat (split; try apply _).
- split; try apply _. intros.
+ (* regression in type_classes *) admit. admit. admit. admit. admit. admit.
+ split; try apply _. admit. intros.
apply ball_weak_le with (2 ^ Qdlog2 ε)%Qpos.
now apply (Qpos_dlog2_spec ε).
now apply Q_approx_correct.
diff --git a/reals/faster/ARarctan_small.v b/reals/faster/ARarctan_small.v
index 95b00dcb..afd129be 100644
--- a/reals/faster/ARarctan_small.v
+++ b/reals/faster/ARarctan_small.v
@@ -39,8 +39,8 @@ Proof.
apply rings.injective_ne_0.
apply orders.lt_ne_flip.
now apply orders.le_lt_trans with num.
- field_simplify. reflexivity.
- solve_propholds.
+ field_simplify. admit. (* reflexivity.
+ solve_propholds.*)
split; solve_propholds.
rewrite 2!Str_nth_everyOther.
rewrite Str_nth_Qrecip_positives'.
diff --git a/reals/faster/ARpi.v b/reals/faster/ARpi.v
index 640fc805..575d8491 100644
--- a/reals/faster/ARpi.v
+++ b/reals/faster/ARpi.v
@@ -14,7 +14,8 @@ Program Definition AQpi (x : AQ) : AR :=
ARscale ('28%Z * x) (AQarctan_small_pos (AQpi_prf (239%Z) _))) +
(ARscale ('(-48)%Z * x) (AQarctan_small_pos (AQpi_prf (682%Z) _)) +
ARscale ('96%Z * x) (AQarctan_small_pos (AQpi_prf (12943%Z) _))).
-Solve Obligations using compute; now split.
+Obligation Tactic := compute; now split.
+Solve Obligations.
Lemma ARtoCR_preserves_AQpi x : 'AQpi x = r_pi ('x).
Proof.
diff --git a/reals/faster/ARsin.v b/reals/faster/ARsin.v
index 9d30d29c..46e1e258 100644
--- a/reals/faster/ARsin.v
+++ b/reals/faster/ARsin.v
@@ -37,10 +37,9 @@ Proof.
rewrite 2!int_pow_recip.
change (Qdiv ('num) ('den)) with ('num / 'den : Q).
destruct (decide ('den = (0:Q))) as [Pden | Pden].
- rewrite ?Pden, rings.mult_0_l, dec_recip_0. ring.
+ rewrite ?Pden, rings.mult_0_l, dec_recip_0. admit. (* ring.*)
assert (PropHolds ('den ≠ (0:Q))) by assumption.
- field_simplify. reflexivity.
- solve_propholds.
+ field_simplify. admit. (*reflexivity. solve_propholds.*)
split; solve_propholds.
rewrite 2!Str_nth_everyOther.
change (@tl AQ) with (@Str_nth_tl AQ 1).
diff --git a/util/Extract.v b/util/Extract.v
index cc646d06..b8eba127 100644
--- a/util/Extract.v
+++ b/util/Extract.v
@@ -61,7 +61,8 @@ Extract Inlined Constant Pminus => "\n m -> max 1 (n - m)".
Extract Inlined Constant Pmult => "(*)".
Extract Inlined Constant Pmin => "min".
Extract Inlined Constant Pmax => "max".
-Extract Inlined Constant Pcompare => "compare".
+(* Probably a change in the way Coq handles numbers, ask PL.
+Extract Inlined Constant Pcompare => "compare".*)
Extract Inlined Constant positive_eq_dec => "(==)".
Extraction Inline positive_rec.
From beec5f2a108e18985ca58140a027cabad884f67b Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Mon, 1 Sep 2014 15:21:16 +0200
Subject: [PATCH 100/110] Adding file
---
metric2/CompletePointFree.v | 81 -------------------------------------
1 file changed, 81 deletions(-)
delete mode 100644 metric2/CompletePointFree.v
diff --git a/metric2/CompletePointFree.v b/metric2/CompletePointFree.v
deleted file mode 100644
index f9768175..00000000
--- a/metric2/CompletePointFree.v
+++ /dev/null
@@ -1,81 +0,0 @@
-(*
-
-(* This is a test of how to combine type classes with the old records.
-Specifically, how to use the pointfree machinery with the [Complete] monad *)
-Require Import CRtrans.
-Require Import Qmetric.
-
-Section ODE.
-Open Scope uc_scope.
-Require Import ProductMetric CompleteProduct.
-Require Import Unicode.Utf8.
-Require Import metric2.Classified.
-Require Import stdlib_rationals.
-
-(*
-Check (_:MetricSpaceClass (Q*Q)).
-Check (_:MetricSpaceClass (CR*Q)).
-*)
-
-Section bind_uc.
-(* We use the packed MetricSpace because we do not (yet) want to redefine Complete.
-However, here is a first attempt:
-Definition CompleteC Y `{MetricSpaceClass Y}:=(Complete (bundle_MetricSpace Y)).
- Context `{MetricSpaceClass X} `{MetricSpaceClass Y}
- {f: X → CompleteC Y} `{!UniformlyContinuous_mu f} `{!UniformlyContinuous f}.
-*)
-
-Context {X Y : MetricSpace} (f: X → Complete Y) `{!UniformlyContinuous_mu f} `{!UniformlyContinuous f}.
-
-(* Definition bindf : Complete X -> Complete Y :=
- Cbind_slow (wrap_uc_fun' f).
-
-Definition test: UCFunction (Complete X) (Complete Y):=
- ucFunction (fun x => bindf x). *)
-
-(* The classified version *)
-Definition Cbind_slowC: UCFunction (Complete X) (Complete Y):=
- ucFunction (Cbind_slow (wrap_uc_fun' f)).
-
-Variable g:X --> Complete Y.
-Definition test': UCFunction (Complete X) (Complete Y):=
- ucFunction (fun x => (Cbind_slow g) x).
-
-(* Note that: unwrap_uc_fun automatically unwraps g *)
-End bind_uc.
-Notation " f >> g ":= (Cbind_slowC f ∘ g) (at level 50).
-Notation " x >>= f ":= (Cbind_slowC f x) (at level 50).
-
-Section test.
-(* Should Q*Q be bundled ? *)
-Context (v: (Q*Q) → CR)
- `{!UniformlyContinuous_mu v}
- `{!UniformlyContinuous v}.
-
-Context (f:Q→CR)
- `{!UniformlyContinuous_mu f}
- `{!UniformlyContinuous f}.
-
-(*
-Can be replace by the default (,) ?
-Notation "( f , g )":= (together f g).
-We would like to define fun x => v (x, f x), more precisely:
-*)
-
-(* Check (Cbind_slowC v).
-Definition vxfx : UCFunction Q CR :=
- ucFunction (fun x => (Couple (Cunit x, f x) >>= v)).
-
-Better:
-Definition vxfx : UCFunction Q CR :=
- ucFunction (fun x => (Couple (x, f x) >>= v)).
-
-Where Cunit is derived from the Coercion inject_Q.
-Coercion inject_Q: QArith_base.Q>-> CR.
-But this cannot be a Coercion(?)
-*)
-
-End test.
-End ODE.
-
-*)
From 70389f367253a4479d902c75818a9cd32fb158a5 Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Mon, 1 Sep 2014 16:00:25 +0200
Subject: [PATCH 101/110] Moving files.
---
broken/Classified.v | 1225 --------------------------
broken/Ranges.v | 19 -
{broken => metric2}/list_separates.v | 6 +-
3 files changed, 4 insertions(+), 1246 deletions(-)
delete mode 100644 broken/Classified.v
delete mode 100644 broken/Ranges.v
rename {broken => metric2}/list_separates.v (91%)
diff --git a/broken/Classified.v b/broken/Classified.v
deleted file mode 100644
index 2065b13c..00000000
--- a/broken/Classified.v
+++ /dev/null
@@ -1,1225 +0,0 @@
-
-(** MathClasses-style operational & structural classes for a Russell-style metric space (i.e. MetricSpace).
- We don't put this in MathClasses because for reasons of interoperability with the existing MetricSpace
- it is still bound to stdlib Q rather than an abstract Rationals implementation. *)
-
-Require Import
- Arith List
- CSetoids Qmetric Qring Qinf ProductMetric QposInf Qposclasses (* defines Equiv on Qpos *)
- UniformContinuity stdlib_rationals
- stdlib_omissions.Pair stdlib_omissions.Q PointFree
- interfaces.abstract_algebra
- theory.setoids theory.products.
-
-Import Qinf.notations.
-
-Require Vector.
-
-Section MetricSpaceClass.
-
- Variable X: Type.
-
- Class MetricSpaceBall: Type := mspc_ball: Qinf → relation X.
-Hint Unfold relation : type_classes.
- (** We used to have mspc_ball take a Qpos instead of a Qinf. Because it is sometimes convenient
- to speak in terms of a generalized notion of balls that can have infinite or negative radius, we used
- a separate derived definition for that (which return False for negative radii, True for an infinite radius,
- and reduced to setoid equality for a radius equal to 0). This kinda worked, but had a big downside.
- The derived generalized ball relation (let's call it "gball") was defined using case distinctions on the
- finiteness and sign of the radius. These case distinctions routinely got in the way, because it
- meant that e.g. gball for the product metric space did not reduce to the composition of gballs derived
- for the constituent metrics spaces. Consequently, both the basic ball and the generalized ball
- relation were used side-by-side, and converting between the two was a constant annoyance.
-
- Because of this, we now use the generalized type for the "basic" ball. Now the product metric space's
- (generalized) ball relation is defined directly in terms of the constituent metric spaces' balls, and
- so reduces nicely. It also means that there is now a _single_ ball relation that is used everywhere.
-
- Of course, when defining the ball relation for a concrete metric space, the generalization to a Qinf
- parameter implies "more work". Fortunately, the additional work can be factored out into a smart
- constructor (defined later in this module) that takes the version with a Qpos parameter and extends
- it to Qinf in the way described above. All the ball's properties can be lifted along with this extension. *)
-
- Context `{!Equiv X} `{!MetricSpaceBall}.
-
- Class MetricSpaceClass: Prop :=
- { mspc_setoid : Setoid X
- ; mspc_ball_proper:> Proper (=) mspc_ball
- ; mspc_ball_inf: ∀ x y, mspc_ball Qinf.infinite x y
- ; mspc_ball_negative: ∀ (e: Q), (e < 0)%Q → ∀ x y, ~ mspc_ball e x y
- ; mspc_ball_zero: ∀ x y, mspc_ball 0 x y ↔ x = y
- ; mspc_refl:> ∀ e, (0 <= e)%Qinf → Reflexive (mspc_ball e)
- ; mspc_sym:> ∀ e, Symmetric (mspc_ball e)
- ; mspc_triangle: ∀ (e1 e2: Qinf) (a b c: X),
- mspc_ball e1 a b → mspc_ball e2 b c → mspc_ball (e1 + e2) a c
- ; mspc_closed: ∀ (e: Qinf) (a b: X),
- (∀ d: Qpos, mspc_ball (e + d) a b) → mspc_ball e a b }.
-
- Context `{MetricSpaceClass}.
-Local Existing Instance mspc_setoid.
- (** Two simple derived properties: *)
- Lemma mspc_eq a b: (∀ e: Qpos, mspc_ball e a b) → a = b.
- Proof with auto.
- intros.
- apply mspc_ball_zero.
- apply mspc_closed.
- intros.
- setoid_replace (@plus Qinf _ 0 d) with (d: Qinf)...
- change (0 + d == d). ring.
- Qed. (* Todo: Use a bi-impl instead. *)
-
- Lemma mspc_ball_weak_le (q q': Qinf): (q <= q')%Qinf → ∀ x y: X, mspc_ball q x y → mspc_ball q' x y.
- Proof with auto.
- destruct q, q'; simpl; intros...
- assert (q0 == q + (q0 - q))%Q as E by ring.
- rewrite E.
- change (mspc_ball (Qinf.finite q + Qinf.finite (q0 - q)%Q) x y).
- apply mspc_triangle with y...
- apply mspc_refl.
- simpl.
- apply QArith_base.Qplus_le_r with q.
- ring_simplify...
- apply mspc_ball_inf.
- intuition.
- Qed.
-
- (** Instances can be bundled to yield MetricSpaces: *)
- Program Definition bundle_MetricSpace: MetricSpace :=
- @Build_MetricSpace (mcSetoid_as_RSetoid X) mspc_ball _ _.
-
- Next Obligation. apply mspc_ball_proper; assumption. Qed.
-
- Next Obligation. Proof with auto.
- constructor; try apply _.
- intro e. apply mspc_refl...
- intros. apply (mspc_triangle e1 e2 a b c)...
- intros. apply mspc_closed...
- apply mspc_eq.
- Qed.
-
- (** .. which obviously have the same carrier: *)
-
- Goal X ≡ bundle_MetricSpace.
- Proof. reflexivity. Qed.
-
-End MetricSpaceClass.
-
-Instance: Params (@mspc_ball) 2.
-
-Hint Resolve Qlt_le_weak Qplus_lt_le_0_compat.
- (* Todo: Move. *)
-
-(** We now define the smart constructor that builds a MetricSpace from a ball relation with positive radius. *)
-
-Section genball.
-
- Context
- `{Setoid X}
- (R: Qpos → relation X) `{!Proper (QposEq ==> (=)) R} `{∀ e, Reflexive (R e)} `{∀ e, Symmetric (R e)}
- (Rtriangle: ∀ (e1 e2: Qpos) (a b c: X), R e1 a b → R e2 b c → R (e1 + e2)%Qpos a c)
- (Req: ∀ (a b: X), (∀ d: Qpos, R d a b) → a = b)
- (Rclosed: ∀ (e: Qpos) (a b: X), (∀ d: Qpos, R (e + d)%Qpos a b) → R e a b).
-
- Definition genball: MetricSpaceBall X := λ (oe: Qinf),
- match oe with
- | Qinf.infinite => λ _ _, True
- | Qinf.finite e =>
- match Qdec_sign e with
- | inl (inl _) => λ _ _ , False
- | inl (inr p) => R (exist (Qlt 0) e p)
- | inr _ => equiv
- end
- end.
-
- Definition ball_genball (q: Qpos) (a b: X): genball q a b ↔ R q a b.
- Proof.
- unfold genball.
- destruct Qdec_sign as [[|]|U].
- exfalso.
- destruct q.
- apply (Qlt_is_antisymmetric_unfolded 0 x); assumption.
- apply Proper0; reflexivity.
- exfalso.
- destruct q.
- simpl in U.
- revert q.
- rewrite U.
- apply Qlt_irrefl.
- Qed.
-
- Lemma genball_alt (q: Q) (x y: X):
- genball q x y <->
- match Qdec_sign q with
- | inl (inl _) => False
- | inl (inr p) => genball q x y
- | inr _ => x=y
- end.
- Proof.
- unfold genball. simpl.
- split; destruct Qdec_sign as [[|]|]; auto.
- Qed.
-
- Instance genball_Proper: Proper ((=) ==> (=) ==> (=) ==> iff) genball.
- Proof with auto; intuition.
- unfold genball.
- intros u e' E.
- destruct u, e'.
- change (q = q0) in E.
- destruct Qdec_sign as [[|]|]; destruct Qdec_sign as [[|]|].
- repeat intro...
- exfalso. revert q1. apply Qlt_is_antisymmetric_unfolded. rewrite E...
- exfalso. revert q1. rewrite E. rewrite q2. apply Qlt_irrefl.
- exfalso. revert q1. rewrite E. apply Qlt_is_antisymmetric_unfolded...
- apply Proper0...
- exfalso. revert q1. rewrite E, q2. apply Qlt_irrefl.
- exfalso. revert q2. rewrite <- E, q1. apply Qlt_irrefl.
- exfalso. revert q2. rewrite <- E, q1. apply Qlt_irrefl.
- intros ?? A ?? B. rewrite A, B...
- repeat intro...
- intuition.
- repeat intro.
- reflexivity.
- Qed.
-
-Instance: ∀ e, Proper ((=) ==> (=) ==> iff) (genball e).
-Proof. intros; now apply genball_Proper. Qed.
-
- Lemma genball_negative (q: Q): (q < 0)%Q → ∀ x y: X, ~ genball q x y.
- Proof with auto.
- unfold genball.
- intros E ??.
- destruct Qdec_sign as [[|]|U]; intro...
- apply (Qlt_is_antisymmetric_unfolded 0 q)...
- revert E.
- rewrite U.
- apply Qlt_irrefl.
- Qed.
-
- Lemma genball_Reflexive (q: Qinf): (0 <= q)%Qinf → Reflexive (genball q).
- Proof with auto.
- repeat intro.
- unfold genball.
- destruct q...
- destruct Qdec_sign as [[|]|]; intuition...
- apply (Qlt_not_le q 0)...
- Qed.
-
- Global Instance genball_Symmetric: ∀ e, Symmetric (genball e).
- Proof with auto.
- intros [q|]... simpl. destruct Qdec_sign as [[|]|]; try apply _...
- Qed.
-
- Lemma genball_triangle (e1 e2: Qinf) (a b c: X): genball e1 a b → genball e2 b c → genball (e1 + e2) a c.
- Proof with auto.
- intros U V.
- destruct e1 as [e1|]...
- destruct e2 as [e2|]...
- apply genball_alt.
- apply genball_alt in U.
- apply genball_alt in V.
- destruct (Qdec_sign (e1 + e2)) as [[G | I] | J];
- destruct (Qdec_sign e1) as [[A | B] | C];
- destruct (Qdec_sign e2) as [[D | E] | F]; intuition.
- revert G. apply (Qlt_is_antisymmetric_unfolded _ _)...
- revert G. rewrite F, Qplus_0_r. apply (Qlt_is_antisymmetric_unfolded _ _ B)...
- revert G. rewrite C, Qplus_0_l. apply (Qlt_is_antisymmetric_unfolded _ _ E)...
- revert G. rewrite C, F. apply Qlt_irrefl.
- change (genball (exist _ e1 B + exist _ e2 E )%Qpos a c).
- apply ball_genball.
- apply Rtriangle with b; apply ball_genball...
- rewrite <- V. Admitted. (*rewrite F. rewrite Qplus_0_r...
- rewrite U, C, Qplus_0_l...
- exfalso. apply (Qlt_irrefl (e1 + e2)). rewrite -> C at 1. rewrite -> F at 1...
- exfalso. apply (Qlt_irrefl (e1 + e2)). rewrite -> J at 1...
- revert U. rewrite <- V, <- (Qplus_0_r e1), <- F, J...
- revert V. rewrite <- (Qplus_0_l e2), <- C, J, U...
- transitivity b...
- Qed.*)
-
- Lemma genball_closed :
- (∀ (e: Qinf) (a b: X), (∀ d: Qpos, genball (e + d) a b) → genball e a b).
- Proof with auto with *.
- intros.
- unfold genball.
- destruct e...
- destruct Qdec_sign as [[|]|].
- assert (0 < (1#2) * -q)%Q.
- apply Qmult_lt_0_compat...
- apply Qopp_Qlt_0_l...
- pose proof (H2 (exist _ _ H3)).
- refine (genball_negative _ _ _ _ H4).
- simpl.
- ring_simplify.
- apply Qopp_Qlt_0_l...
- setoid_replace (- ((1 # 2) * q))%Q with (-q * (1#2))%Q by (simpl; ring).
- apply Qmult_lt_0_compat...
- apply Qopp_Qlt_0_l...
- apply Rclosed.
- intros.
- apply ball_genball.
- apply (H2 d).
- apply Req.
- intros.
- apply ball_genball.
- admit.
- (*rewrite <- (Qplus_0_l d).
- rewrite <- q0.
- apply H2.*)
- Qed.
-
- Instance genball_MetricSpace: @MetricSpaceClass X _ genball.
- Proof with auto.
- constructor; try apply _.
- unfold mspc_ball. simpl...
- apply genball_negative.
- reflexivity.
- apply genball_Reflexive.
- apply genball_triangle.
- apply genball_closed.
- Qed.
-
-End genball.
-
-(** Bundled MetricSpaces immediately yield instances of the classes: *)
-
-Instance: ∀ X: MetricSpace, MetricSpaceBall X := λ X, @genball X _ (@ball X).
-
-Instance class_from_MetricSpace (X: MetricSpace): MetricSpaceClass X.
-Proof.
- apply genball_MetricSpace; try apply _.
- apply msp_refl, X.
- apply msp_sym, X.
-(* apply msp_triangle, X.
- apply msp_eq, X.
- apply msp_closed, X.
-Qed.*)
-Admitted.
-
-Section products.
-
- Context `{MetricSpaceClass X} `{MetricSpaceClass Y}.
-
- Global Instance: MetricSpaceBall (X * Y)
- := λ e a b, mspc_ball X e (fst a) (fst b) ∧ mspc_ball Y e (snd a) (snd b).
-
- (* We do not reuse ProductMS here because to do so we'd need to go through genball,
- resulting in the problems described earlier. *)
-
- Global Instance: MetricSpaceClass (X * Y).
- Proof with auto.
- pose (mspc_setoid X).
- pose (mspc_setoid Y).
- constructor.
- apply _.
- repeat intro.
- split.
- split.
- rewrite <- H3, <- H4, <- H5. apply H6.
- rewrite <- H3, <- H4, <- H5. apply H6.
- split. rewrite -> H3, H4, H5. apply H6.
- rewrite -> H3, H4, H5. apply H6.
- split. apply (mspc_ball_inf X).
- apply (mspc_ball_inf Y).
- repeat intro.
- destruct H4.
- apply (mspc_ball_negative X _ H3 _ _ H4).
- intros.
- change ((mspc_ball X 0 (fst x) (fst y) ∧ mspc_ball Y 0 (snd x) (snd y)) ↔ x = y).
- rewrite (mspc_ball_zero X), (mspc_ball_zero Y). reflexivity.
- split. apply (mspc_refl X)...
- apply (mspc_refl Y)...
- split; apply (@symmetry _ _ ); try apply _; apply H3. (* just using [symmetry] here causes evar anomalies.. *)
- split.
- apply (mspc_triangle X) with (fst b).
- apply H3.
- apply H4.
- apply (mspc_triangle Y) with (snd b).
- apply H3.
- apply H4.
- split.
- apply (mspc_closed X). apply H3.
- apply (mspc_closed Y). apply H3.
- Qed.
-
-End products.
-
-Definition vector_zip {X Y} {n} : Vector.t X n → Vector.t Y n → Vector.t (X * Y) n :=
- Vector.rect2 (λ n _ _, Vector.t (X * Y) n)
- (Vector.nil _)
- (λ _ _ _ r (x: X) (y: Y), Vector.cons _ (x, y) _ r).
- (* Todo: Move. *)
-
-Section vector_setoid.
-
- Context `{Setoid X} (n: nat).
-
- Global Instance: Equiv (Vector.t X n) := Vector.Forall2 equiv.
-
- Global Instance vector_setoid: Setoid (Vector.t X n).
- Proof with auto.
- constructor.
- repeat intro.
- unfold equiv.
- unfold Equiv_instance_0.
- induction x; simpl; constructor...
- Admitted.
-(* reflexivity.
- unfold equiv.
- unfold Equiv_instance_0.
- unfold Symmetric.
- intros.
- revert n x y H0.
- apply Vector.Forall2_ind; constructor...
- symmetry...
- admit. (* transitivity *)
- Qed.*)
-
-End vector_setoid. (* Todo: Move. *)
-
-Section vectors.
-
- Context `{MetricSpaceClass X} (n: nat).
-
- Global Instance: MetricSpaceBall (Vector.t X n) := λ e, Vector.Forall2 (mspc_ball X e).
-
- Global Instance: MetricSpaceClass (Vector.t X n).
- Proof with auto.
- pose proof (mspc_setoid X).
- split.
- apply _.
- admit.
- admit.
- admit.
- admit.
- admit.
- admit.
- admit.
- admit.
- Qed.
-
-End vectors.
-
-(** I decided to experiment with a class used strictly to declare a metric space's
- components in a section using [Context] without also declaring the metric space structure
- itself, and risking accidental parameterization of the section context on the proof of that
- metric space structure if such parametrization is unneeded (for instance because there is
- already a UniformContinuous constraint which incorporates the metric space proof. *)
-
-Class MetricSpaceComponents X `{Equiv X} `{MetricSpaceBall X}: Prop.
-
-(** Next, we introduce classes for uniform continuity (which is what we're really after, since
- we will use these to automatically derive uniform continuity for various forms of function
- composition). *)
-
-Implicit Arguments mspc_ball [[X] [MetricSpaceBall]].
-
-Class Canonical (T: Type): Type := canonical: T.
- (* Todo: Move. *)
-
-Instance: ∀ {T: Type}, Canonical (T → T) := @Datatypes.id.
-
-Instance: Canonical (Qpos → Qinf) := Qinf.finite ∘ QposAsQ.
-
-Instance composed_Proper `{Equiv A} `{Equiv B} `{Equiv C} (f: B → C) (g: A → B):
- Proper (=) f → Proper (=) g → Proper (=) (f ∘ g).
-Proof with auto.
- repeat intro.
- unfold Basics.compose.
- apply H2.
- apply H3.
- assumption.
-Qed.
-
-Instance: Proper (QposEq ==> (=)) QposAsQ.
-Proof. repeat intro. assumption. Qed.
-
-Require Import util.Container.
-
-Definition Ball X R := prod X R.
-Hint Extern 0 (Equiv (Ball _ _)) => eapply @prod_equiv : typeclass_instances.
-
-Section Ball.
- Context X `{MetricSpaceBall X} (R: Type) `{Canonical (R → Qinf)}.
-
- Global Instance ball_contains: Container X (Ball X R) := fun b => mspc_ball (canonical (snd b)) (fst b).
-
- Context `{Equiv X} `{Equiv R} `{!MetricSpaceClass X} `{!Proper (=) (canonical: R → Qinf)}.
-
- Global Instance ball_contains_Proper: Proper (=) (In: Ball X R → X → Prop).
- Proof with auto.
- repeat intro.
- unfold In, ball_contains.
- apply (mspc_ball_proper X)...
- apply Proper0.
- apply H3.
- apply H3.
- Qed. (* Todo: Clean up. *)
-
-End Ball.
-
-
-(*Instance: Params (@contains) 4.
-
-Implicit Arguments contains [[X] [H] [H0] [R]].*)
-
-
-Section sig_metricspace.
-
- Context `{MetricSpaceClass X} (P: X → Prop).
-
- Global Instance sig_mspc_ball: MetricSpaceBall (sig P) := λ e x y, mspc_ball e (` x) (` y).
-
- Global Instance sig_mspc: MetricSpaceClass (sig P).
- Proof with auto.
- pose proof (mspc_setoid X).
- constructor.
- apply _.
- repeat intro.
- change (mspc_ball x (` x0) (` x1) = mspc_ball y (` y0) (` y1)).
- apply (mspc_ball_proper X)...
- repeat intro.
- change (mspc_ball Qinf.infinite (` x) (` y)).
- apply (mspc_ball_inf X).
- repeat intro. apply (mspc_ball_negative X e H2 (` x) (` y))...
- intros.
- change (mspc_ball 0 (` x) (` y) ↔ (` x) = (` y)).
- apply (mspc_ball_zero X).
- repeat intro.
- change (mspc_ball e (` x) (` x)).
- apply (mspc_refl X)...
- repeat intro.
- change (mspc_ball e (` y) (` x)).
- symmetry...
- repeat intro.
- apply (mspc_triangle X e1 e2 (` a) (` b))...
- intros.
- apply (mspc_closed X e (` a) (` b))...
- Qed.
-
-End sig_metricspace.
-
-Instance Qpos_mspc_ball: MetricSpaceBall Qpos := @sig_mspc_ball Q_as_MetricSpace _ (Qlt 0).
-Instance Qpos_mspc: MetricSpaceClass Qpos := @sig_mspc Q_as_MetricSpace _ _ _ (Qlt 0).
-
-Instance: Cast QnnInf.T Qinf :=
- λ x, match x with
- | QnnInf.Infinite => Qinf.infinite
- | QnnInf.Finite q => Qinf.finite q
- end.
-
-Section uniform_continuity.
-
- Context `{MetricSpaceComponents X} `{MetricSpaceComponents Y}.
-
- Class UniformlyContinuous_mu (f: X → Y): Type := { uc_mu: Qpos → QposInf }.
- (* Note: If we omit the {} around the uc_mu field and let the class become a definitional class,
- instance resolution will often find the wrong instance because the type of uc_mu is the same for
- different instantiations of X and Y. This solution is not ideal. *)
-
- Context (f: X → Y) `{!UniformlyContinuous_mu f}.
-
- Class UniformlyContinuous: Prop :=
- { uc_from: MetricSpaceClass X
- ; uc_to: MetricSpaceClass Y
- ; uniformlyContinuous: ∀ (e: Qpos) (a b: X), mspc_ball (uc_mu e) a b → mspc_ball e (f a) (f b) }.
-
- (** If we have a function with this constraint, then we can bundle it into a UniformlyContinuousFunction: *)
-
- Context `{uc: UniformlyContinuous}.
-
- Let hint := uc_from.
- Let hint' := uc_to.
-
-(* Program Definition wrap_uc_fun
- : UniformlyContinuousFunction (bundle_MetricSpace X) (bundle_MetricSpace Y)
- := @Build_UniformlyContinuousFunction (bundle_MetricSpace X) (bundle_MetricSpace Y) f uc_mu _.
-
- Next Obligation. Proof with auto.
- repeat intro.
- unfold ball. simpl.
- apply uniformlyContinuous.
- destruct uc_mu...
- apply (mspc_ball_inf X).
- Qed.*)
-
- (** Note that wrap_uc_fun _also_ bundles the source and target metric spaces, because
- UniformlyContinuousFunction is expressed in terms of the bundled data type for metric spaces. *)
-
-End uniform_continuity.
-
-Implicit Arguments uc_mu [[X] [Y] [UniformlyContinuous_mu]].
-
-(** Local uniform continuity just means that the function restricted to any finite balls
- is uniformly continuous: *)
-
-Section local_uniform_continuity.
-
- Context `{MetricSpaceComponents X} `{MetricSpaceComponents Y}.
-
- Definition restrict (b: Ball X Qpos) (f: X → Y): sig ((∈ b)) → Y
- := f ∘ @proj1_sig _ _.
-
- Class LocallyUniformlyContinuous_mu (f: X → Y): Type :=
- luc_mu (b: Ball X Qpos):> UniformlyContinuous_mu (restrict b f).
-
- Context (f: X → Y) {mu: LocallyUniformlyContinuous_mu f}.
-
- Class LocallyUniformlyContinuous: Prop :=
- { luc_from: MetricSpaceClass X
- ; luc_to: MetricSpaceClass Y
- ; luc_uc (b: Ball X Qpos): UniformlyContinuous (restrict b f) }.
-
- Context `{LocallyUniformlyContinuous}.
-
- Instance luc_Proper: Proper (=) f.
- Proof with simpl; intuition.
- repeat intro.
- pose proof luc_to.
- apply (mspc_eq Y).
- intros.
- set (b := (x, e): Ball X Qpos).
- destruct H5.
- specialize (luc_uc0 b).
- destruct luc_uc0.
- unfold restrict in uniformlyContinuous0.
- unfold Basics.compose in *.
- pose proof (mspc_setoid X).
- assert (x ∈ b).
- subst b. unfold In, ball_contains. simpl.
- apply (mspc_refl X)...
- assert (y ∈ b).
- rewrite <- H6...
- apply (uniformlyContinuous0 e (exist _ x H9) (exist _ y H10)).
- change (mspc_ball (uc_mu (restrict b f) e) x y).
- rewrite <- H6.
- apply (mspc_refl X).
- simpl.
- set (uc_mu (restrict b f) e).
- destruct q; simpl...
- Qed.
-
-End local_uniform_continuity.
-
-
-Section local_from_global_continuity.
-
- Context `{MetricSpaceComponents X} `{MetricSpaceComponents Y}.
-
- Context (f: X → Y) {mu: UniformlyContinuous_mu f} {uc: UniformlyContinuous f}.
-
- Instance local_from_global_uc_mu: LocallyUniformlyContinuous_mu f
- := λ _, Build_UniformlyContinuous_mu _ (uc_mu f).
-
- Instance local_from_global_uc: LocallyUniformlyContinuous f.
- Proof with auto.
- constructor.
- apply uc.
- apply uc.
- intro.
- pose proof (uc_from f).
- pose proof (uc_to f).
- constructor; try apply _.
- intros.
- apply (uniformlyContinuous f).
- assumption.
- Qed.
-
-End local_from_global_continuity.
-
-
-(** Normally, we would like to use the type class constraints whenever we need uniform continuity of
- functions, including in the types for higher order functions. For instance, we would like to assign
- an integration function for uniformly continuous functions a type along the lines of:
- ∀ (f: sig (∈ r) → CR) `{!UniformlyContinuous f}, CR
- However, dependent types like these get in the way when we subsequently want to express continuity
- of this higher order function itself. Hence, a modicum of bundling is hard to avoid. However, we
- only need to bundle the components of the uniformly continuous function itself---there is no need to
- also start bundling source and target metric spaces the way UniformlyContinuousFunction and
- wrap_uc_fun do. Hence, we now introduce a record for uniformly continuous functions that does not
- needlessly bundle the source and target metric spaces. *)
-
-Section shallowly_wrapped_ucfuns.
-
- Context `{@MetricSpaceComponents X Xe Xb} `{@MetricSpaceComponents Y Ye Yb}.
- (* We must name Xe/Xb/Ye/Yb here so that we can repeat them in the implicit argument
- specification later on. This could have been avoided if Coq offered more flexible
- commands for implicit argument specification that would let one reset implicit-ness for
- individual parameters without restating the whole list. *)
-
- Record UCFunction: Type := ucFunction
- { ucFun_itself:> X → Y
- ; ucFun_mu: UniformlyContinuous_mu ucFun_itself
- ; ucFun_uc: UniformlyContinuous ucFun_itself }.
-
- Global Instance: ∀ (f: UCFunction), Proper (=) (f: X → Y).
- Proof. intros. destruct f.
- simpl.
- set (local_from_global_uc_mu ucFun_itself0).
- apply (@luc_Proper X _ _ Y _ _ ucFun_itself0 l).
- apply (local_from_global_uc _).
- Qed.
-
-End shallowly_wrapped_ucfuns.
-
-
-Existing Instance ucFun_mu.
-Existing Instance ucFun_uc.
-
-Implicit Arguments UCFunction [[Xe] [Xb] [Yb] [Ye]].
-Implicit Arguments ucFunction [[X] [Xe] [Xb] [Y] [Yb] [Ye] [ucFun_mu] [ucFun_uc]].
-
-
-Section delegated_mspc.
-
- Context (X: Type) `{MetricSpaceClass Y} (xy: X → Y).
-
- Instance delegated_ball: MetricSpaceBall X := λ e a b, mspc_ball e (xy a) (xy b).
-
- Instance delegated_equiv: Equiv X := λ a b, xy a = xy b.
-
- Instance delegated_mspc: MetricSpaceClass X.
- Proof with intuition.
- constructor.
- admit.
- repeat intro.
- unfold mspc_ball, delegated_ball.
- apply (mspc_ball_proper Y)...
- intros.
- unfold mspc_ball, delegated_ball.
- apply (mspc_ball_inf Y).
- repeat intro.
- apply (mspc_ball_negative Y e H1 (xy x) (xy y))...
- intros.
- unfold mspc_ball, delegated_ball.
- rewrite (mspc_ball_zero Y).
- reflexivity.
- unfold mspc_ball, delegated_ball.
- repeat intro.
- apply (mspc_refl Y e H1).
- unfold mspc_ball, delegated_ball.
- repeat intro.
- apply (mspc_sym Y)...
- unfold mspc_ball, delegated_ball.
- intros e1 e2 a b c.
- apply (mspc_triangle Y e1 e2).
- unfold mspc_ball, delegated_ball.
- intros.
- apply (mspc_closed Y)...
- Qed.
-
-End delegated_mspc.
-
-
-Section proper_functions.
-
- (* Todo: This is bad. Make instances for (@sig (A → B) (Proper equiv)) instead and delegate to it for UCFunction. *)
-
- Context `{Setoid A} `{MetricSpaceClass B}.
-
- Let T := (@sig (A → B) (Proper equiv)).
-
- Global Instance: Equiv T := λ x y, proj1_sig x = proj1_sig y.
-
- Let hint' := mspc_setoid B.
-
- Global Instance: Setoid T.
- Proof with intuition.
- constructor.
- intros ????.
- destruct x...
- repeat intro. (*symmetry...
- repeat intro.
- transitivity (proj1_sig y x0)...
- Qed.*)
- Admitted.
-
- Global Instance: MetricSpaceBall T := λ e f g, Qinf.le 0 e ∧ ∀ a, mspc_ball e (` f a) (` g a).
- (* The 0<=e condition is needed because otherwise if A is empty, we cannot deduce
- False from a premise of two functions being inside a negative ball of eachother.
- If this turns out to be annoying, we can make a separate higher-priority metric space instance
- for functions from a known-nonempty type (registered with a NonEmpty type class). *)
-
- Global Instance ProperFunction_mspc: MetricSpaceClass T.
- Proof with simpl; auto; try reflexivity.
- constructor; try apply _.
- split.
- split.
- rewrite <- H2.
- apply H5.
- intros.
- rewrite <- H2.
- rewrite <- (H3 a). 2: reflexivity.
- rewrite <- (H4 a). 2: reflexivity.
- apply H5...
- split.
- rewrite H2. apply H5.
- intros.
- rewrite H2.
- rewrite (H3 a). 2: reflexivity.
- rewrite (H4 a). 2: reflexivity.
- apply H5.
- split.
- simpl.
- auto.
- intros.
- apply (mspc_ball_inf B).
- repeat intro.
- unfold mspc_ball in H3.
- destruct H3.
- simpl in H3.
- apply (Qlt_not_le e 0)...
- unfold mspc_ball.
- unfold MetricSpaceBall_instance_2.
- intros.
- split.
- repeat intro.
- destruct H2.
- destruct x.
- (*simpl.
- rewrite H3.
- apply (mspc_ball_zero B)...
- split.
- simpl. auto with *.
- intros.
- apply (mspc_ball_zero B)...
- apply H2.
- reflexivity.
- split. simpl. auto.
- intros.
- apply (mspc_refl B e)...
- split.
- apply H2.
- intros.
- apply (mspc_sym B).
- apply H2.
- split.
- apply Qinf.le_0_plus_compat.
- apply H2.
- apply H3.
- intros.
- apply (mspc_triangle B) with (proj1_sig b a0).
- apply H2.
- apply H3.
- split.
- destruct e. 2: simpl; auto.
- unfold mspc_ball in H2.
- unfold MetricSpaceBall_instance_2 in H2.
- destruct (Qdec_sign q) as [[|]|].
- exfalso.
- assert (0 < (1#2) * -q)%Q.
- apply Qmult_lt_0_compat...
- apply Qopp_Qlt_0_l...
- destruct (H2 (exist _ _ H3)).
- simpl in H4.
- clear H3 H5.
- ring_simplify in H4.
- apply (Qlt_not_le q 0). auto.
- setoid_replace q with ((1 # 2) * q + (1 # 2) * q)%Q by (simpl; ring).
- apply Qplus_nonneg...
- simpl. auto with *.
- rewrite q0.
- simpl.
- apply Qle_refl.
- intros.
- apply (mspc_closed B).
- intros.
- apply H2.
- Qed.*) (* Todo: This is awful. Clean it up once these blasted evar anomalies are under control. *)
- Admitted.
-
-End proper_functions.
-
-
-Section uc_functions.
-
- (* Todo: Just delegate to proper_functions. *)
-
- Context `{MetricSpaceClass A} `{MetricSpaceClass B}.
-
- Global Instance: Equiv (UCFunction A B) := equiv: relation (A→B).
-
- Let hint := mspc_setoid A.
- Let hint' := mspc_setoid B.
-
- Global Instance: Setoid (UCFunction A B).
- Proof with intuition.
- constructor.
- intros ????.
- set (_: Proper (=) (ucFun_itself x)).
- destruct x...
- repeat intro. (*symmetry...
- intros ? y ??? x. transitivity (y x)...
- Qed.*)
- Admitted.
-
- Global Instance: MetricSpaceBall (UCFunction A B) := λ e f g, Qinf.le 0 e ∧ ∀ a, mspc_ball e (f a) (g a).
- (* The 0<=e condition is needed because otherwise if A is empty, we cannot deduce
- False from a premise of two functions being inside a negative ball of eachother.
- If this turns out to be annoying, we can make a separate higher-priority metric space instance
- for functions from a known-nonempty type (registered with a NonEmpty type class). *)
-
- Global Instance UCFunction_MetricSpace: MetricSpaceClass (UCFunction A B).
- Proof with simpl; auto; try reflexivity.
- constructor; try apply _.
- split.
- split.
- rewrite <- H3.
- apply H6.
- intros.
- (*rewrite <- H3.
- rewrite <- (H4 a). 2: reflexivity.
- rewrite <- (H5 a). 2: reflexivity.
- apply H6...
- split.
- rewrite H3. apply H6.
- intros.
- rewrite H3.
- rewrite (H4 a). 2: reflexivity.
- rewrite (H5 a). 2: reflexivity.
- apply H6.
- split.
- simpl.
- auto.
- intros.
- apply (mspc_ball_inf B).
- repeat intro.
- unfold mspc_ball in H4.
- destruct H4.
- simpl in H4.
- apply (Qlt_not_le e 0)...
- unfold mspc_ball.
- unfold MetricSpaceBall_instance_2.
- intros.
- split.
- repeat intro.
- destruct H3.
- rewrite H4.
- apply (mspc_ball_zero B)...
- split.
- simpl. auto with *.
- intros.
- apply (mspc_ball_zero B)...
- apply H3.
- reflexivity.
- split. simpl. auto.
- intros.
- apply (mspc_refl B e)...
- split.
- apply H3.
- intros.
- apply (mspc_sym B).
- apply H3.
- split.
- apply Qinf.le_0_plus_compat.
- apply H3.
- apply H4.
- intros.
- apply (mspc_triangle B) with (b a0).
- apply H3.
- apply H4.
- split.
- destruct e. 2: simpl; auto.
- unfold mspc_ball in H3.
- unfold MetricSpaceBall_instance_2 in H3.
- destruct (Qdec_sign q) as [[|]|].
- exfalso.
- assert (0 < (1#2) * -q)%Q.
- apply Qmult_lt_0_compat...
- apply Qopp_Qlt_0_l...
- destruct (H3 (exist _ _ H4)).
- simpl in H5.
- clear H4 H6.
- ring_simplify in H5.
- apply (Qlt_not_le q 0). auto.
- setoid_replace q with ((1 # 2) * q + (1 # 2) * q)%Q by (simpl; ring).
- apply Qplus_nonneg...
- simpl. auto with *.
- rewrite q0.
- simpl.
- apply Qle_refl.
- intros.
- apply (mspc_closed B).
- intros.
- apply H3.
- Qed.*) (* Todo: This is awful. Clean it up once these blasted evar anomalies are under control. *)
- Admitted.
-
-End uc_functions.
-
-(** If source and target are /already/ bundled, then we don't need to rebundle them when bundling
- a uniformly continuous function: *)
-
-Program Definition wrap_uc_fun' {X Y: MetricSpace} (f: X → Y)
- `{!UniformlyContinuous_mu f}
- `{@UniformlyContinuous X _ _ Y _ _ f _}:
- UniformlyContinuousFunction X Y :=
- @Build_UniformlyContinuousFunction X Y f (uc_mu f) _.
-
-Next Obligation. Proof with auto.
- intros ????.
- assert (mspc_ball (uc_mu f e) a b).
- revert H0.
- set (uc_mu f e).
- intros.
- destruct q...
- apply <- (ball_genball (@ball X) q)...
- pose proof (uniformlyContinuous f e a b H1).
- apply ball_genball...
- apply _.
-Qed.
-
-(** Conversely, if we have a UniformlyContinuousFunction (between bundled metric spaces) and project
- the real function out of it, instances of the classes can easily be derived. *)
-
-Open Scope uc_scope.
-
-Section unwrap_uc.
-
- Context {X Y: MetricSpace} (f: X --> Y).
-
- Global Instance unwrap_mu: UniformlyContinuous_mu f := { uc_mu := mu f }.
-
- Global Instance unwrap_uc_fun: UniformlyContinuous f.
- Proof with auto.
- constructor; try apply _.
- unfold uc_mu, unwrap_mu.
- destruct f.
- simpl. intros.
- unfold mspc_ball.
- unfold MetricSpaceBall_instance_0.
- apply ball_genball.
- apply _.
- apply uc_prf.
- set (mu e) in *.
- destruct q...
- simpl.
- apply ball_genball...
- apply _.
- Qed.
-
-End unwrap_uc.
-
-(** Extentionally equal functions are obviously equally uniformly continuous (with extensionally equal mu's): *)
-
-Lemma UniformlyContinuous_proper `{MetricSpaceClass X} `{MetricSpaceClass Y} (f g: X → Y)
- `{!UniformlyContinuous_mu f} `{!UniformlyContinuous_mu g}:
- (∀ x, f x = g x) → (∀ e, uc_mu f e ≡ uc_mu g e) →
- UniformlyContinuous f → UniformlyContinuous g.
- (* Todo: Stronger versions of this statement can be proved with a little effort. *)
-Proof.
- constructor; try apply _.
- intros ????.
- pose proof (mspc_ball_proper Y).
- pose proof (mspc_setoid X).
- pose proof (mspc_setoid Y).
- rewrite <- (H3 a).
- rewrite <- (H3 b).
- apply (uniformlyContinuous f).
- rewrite H4. auto.
-Qed.
-
-
-(** We now show that a couple of basic functions are continuous: *)
-
-(** The identity function is uniformly continuous: *)
-
-Section id_uc. Context `{MetricSpaceClass X}.
- Global Instance: UniformlyContinuous_mu (@Datatypes.id X) := { uc_mu := Qpos2QposInf }.
- Global Instance: UniformlyContinuous (@Datatypes.id X).
- Proof. constructor; try apply _. intros. assumption. Qed.
-End id_uc.
- (* Note: We don't need a separate instance for the [id] constant. If such an instance
- is needed, we can use [Hint Unfold id: typeclass_instances.] *)
-
-(** Constant functions are uniformly continuous: *)
-
-Section const_uc. Context `{MetricSpaceClass X} `{MetricSpaceClass Y} (y: Y).
- Global Instance: UniformlyContinuous_mu (@Basics.const Y X y) := { uc_mu := λ _, QposInfinity }.
- Global Instance: UniformlyContinuous (@Basics.const Y X y).
- Proof. repeat intro. constructor; try apply _. intros. apply (mspc_refl Y e). simpl. auto. Qed.
-End const_uc.
-
-(** Mapping both of a pair's components by uniformly continuous functions
- is uniformly continuous: *)
-
-Section exist_uc.
- Context `{MetricSpaceComponents X} `{MetricSpaceComponents Y} (P: Y → Prop)
- (f: X → Y) (g: ∀ x, P (f x)) `{!UniformlyContinuous_mu f} `{!UniformlyContinuous f}.
-
- Global Instance exist_mu: UniformlyContinuous_mu (λ x: X, exist P (f x) (g x)) := { uc_mu := uc_mu f }.
-
- Global Instance exist_uc: UniformlyContinuous (λ x: X, exist P (f x) (g x)).
- Proof with auto.
- constructor.
- apply (uc_from f).
- pose proof (uc_to f).
- apply _.
- intros.
- apply (uniformlyContinuous f).
- assumption.
- Qed.
-End exist_uc.
-
-Section map_pair_uc.
- Context `{MetricSpaceComponents X} `{MetricSpaceComponents Y}
- `{MetricSpaceComponents A} `{MetricSpaceComponents B}
- (f: X → Y) `{!UniformlyContinuous_mu f} `{!UniformlyContinuous f}
- (g: A → B) `{!UniformlyContinuous_mu g} `{!UniformlyContinuous g}.
-
- Global Instance: UniformlyContinuous_mu (map_pair f g) :=
- { uc_mu := λ x, QposInf_min (uc_mu f x) (uc_mu g x) }.
-
- Let hint := uc_from g.
- Let hint' := uc_to g.
- Let hint'' := uc_from f.
- Let hint''' := uc_to f.
-
- Global Instance: UniformlyContinuous (map_pair f g).
- Proof with auto.
- constructor; try apply _. intros.
- (*pose proof (together_uc (wrap_uc_fun f) (wrap_uc_fun g) e a b) as P.
- apply P. simpl in *.
- destruct (QposInf_min)...
- simpl...
- Qed.*)
- Admitted.
-End map_pair_uc.
-
-(** The diagonal function is uniformly continuous: *)
-
-Section diagonal_uc.
- Context `{MetricSpaceClass X}.
-
- Global Instance: UniformlyContinuous_mu (@diagonal X) := { uc_mu := Qpos2QposInf }.
-
- Global Instance: UniformlyContinuous (@diagonal X).
- Proof. constructor; try apply _. intros ??? E. split; auto. Qed.
-End diagonal_uc.
-
-(** fst/snd/pair are uniformly continuous: *)
-
-Section pairops_uc.
- Context `{MetricSpaceClass A} `{MetricSpaceClass B}.
-
- Global Instance: UniformlyContinuous_mu (@fst A B) := { uc_mu := Qpos2QposInf }.
- Global Instance: UniformlyContinuous_mu (@snd A B) := { uc_mu := Qpos2QposInf }.
- Global Instance: UniformlyContinuous_mu (uncurry (@pair A B)) := { uc_mu := Qpos2QposInf }.
- Global Instance: ∀ a, UniformlyContinuous_mu (@pair A B a) := { uc_mu := Qpos2QposInf }.
-
- Global Instance: UniformlyContinuous (@fst A B).
- Proof. constructor; try apply _. intros ??? P. apply P. Qed.
- Global Instance: UniformlyContinuous (@snd A B).
- Proof. constructor; try apply _. intros ??? P. apply P. Qed.
- Global Instance: UniformlyContinuous (uncurry (@pair A B)).
- Proof. constructor; try apply _. intros ??? P. apply P. Qed.
- Global Instance: ∀ a, UniformlyContinuous (@pair A B a).
- Proof. constructor; try apply _. intros ??? P. split. apply (mspc_refl A). simpl. auto. apply P. Qed.
-End pairops_uc.
-
-Section compose_uc.
- Context `{MetricSpaceComponents X} `{MetricSpaceComponents Y} `{MetricSpaceComponents Z'}
- (f: Y → Z') `{!UniformlyContinuous_mu f} `{!UniformlyContinuous f}
- (g: X → Y) `{!UniformlyContinuous_mu g} `{!UniformlyContinuous g}.
-
- Global Instance compose_mu: UniformlyContinuous_mu (f ∘ g)%prg :=
- { uc_mu := λ e, QposInf_bind (uc_mu g) (uc_mu f e) }.
-
- Let hint := uc_from g.
- Let hint' := uc_to g.
- Let hint'' := uc_to f.
-
- Global Instance compose_uc: UniformlyContinuous (f ∘ g)%prg.
- Proof with auto.
- constructor; try apply _.
- (*intros ??? P.
- apply (uniformlyContinuous f).
- revert P. simpl.
- generalize (uc_mu f e).
- destruct q; intros; simpl.
- apply (uniformlyContinuous g)...
- apply (mspc_ball_inf Y).
- Qed.*)
- Admitted.
-End compose_uc.
-
-Section curried_uc.
- Context `{MetricSpaceClass X} `{MetricSpaceClass Y} `{MetricSpaceClass Z'} (f: X → Y → Z')
- `{fmu1: ∀ x: X, UniformlyContinuous_mu (f x)}
- `{fuc1: ∀ x: X, UniformlyContinuous (f x)}
- `{fmu: !UniformlyContinuous_mu (λ p, f (fst p) (snd p))}
- `{fuc: !UniformlyContinuous (λ p, f (fst p) (snd p))}.
-
- Local Notation F := (λ x: X, {| ucFun_itself := λ y: Y, f x y; ucFun_mu := fmu1 x; ucFun_uc := fuc1 x |}).
-
- Global Instance curried_mu: UniformlyContinuous_mu F := { uc_mu := uc_mu (λ p, f (fst p) (snd p)) }.
-
- Global Instance curried_uc: UniformlyContinuous F.
- Proof with simpl; auto.
- constructor; try apply _.
- split...
- simpl in *.
- destruct fuc.
- intros.
- apply (@uniformlyContinuous0 e (a, a0) (b, a0)).
- simpl.
- set (q := uc_mu (λ p, f (fst p) (snd p)) e) in *.
- destruct q...
- split...
- apply (mspc_refl Y)...
- apply (mspc_ball_inf _).
- Qed.
-End curried_uc.
-
-Class HasLambda `{X: Type} (x: X): Prop.
-
-Instance lambda_has_lambda `(f: A → B): HasLambda (λ x, f x).
-Instance application_has_lambda_left: ∀ `(f: A → B) (x: A), HasLambda f → HasLambda (f x).
-Instance application_has_lambda_right: ∀ `(f: A → B) (x: A), HasLambda x → HasLambda (f x).
-
-
-Section lambda_uc.
-
- Context `{MetricSpaceComponents A} `{MetricSpaceComponents B} (f: A → B).
-
- Global Instance lambda_mu `{!HasLambda f} {free_f: A → B} `{!PointFree f free_f} `{!UniformlyContinuous_mu free_f}: UniformlyContinuous_mu f.
- (* Note: The HasLambda and PointFree constraints cannot be added to the Context declaration
- above because the definition of this mu needs to depend on them /despite/ not using them.
- Without the dependency, lambda_mu would be allowed to find a random free_f of the right signature
- for which it happens to have a mu already, and use that one.
- We do not factor out the mu constraint either, because for (dubious) efficiency reasons it is critical
- that it appear /after/ the PointFree constraint.*)
- Proof. constructor. apply UniformlyContinuous_mu0. Defined.
-
- Context `{!HasLambda f} {free_f: A → B} `{!PointFree f free_f} `{!UniformlyContinuous_mu free_f} `{!UniformlyContinuous free_f}.
-
- Global Instance lambda_uc: UniformlyContinuous f.
- Proof.
- destruct UniformlyContinuous0.
- constructor.
- apply _.
- apply _.
- destruct uc_from0.
- destruct uc_to0.
- intros.
- unfold PointFree in PointFree0.
- rewrite PointFree0.
- apply uniformlyContinuous0.
- unfold uc_mu in H5.
- simpl in H5.
- assumption.
- Qed. (* Todo: Clean up. *)
-
-End lambda_uc.
-
-Module test.
-Section test.
-
- Context
- `{MetricSpaceClass A}
- (f: A → A → A)
- `{!UniformlyContinuous_mu (uncurry f)} `{!UniformlyContinuous (uncurry f)} `{!Proper (=) f}.
-
- Definition t0: UniformlyContinuous_mu (λ (x: A), f (f x x) (f x (f x x))) := _.
-
-End test.
-End test.
diff --git a/broken/Ranges.v b/broken/Ranges.v
deleted file mode 100644
index 865cdcb9..00000000
--- a/broken/Ranges.v
+++ /dev/null
@@ -1,19 +0,0 @@
-
-Require Import Program canonical_names util.Container QArith QMinMax CRlattice.
-
-Definition Range (T: Type) := prod T T.
-
-Instance in_QRange: Container Q (Range Q)
- := λ r x, (Qmin (fst r) (snd r) <= x <= Qmax (fst r) (snd r))%Q.
-
-Instance in_CRRange: Container CR (Range CR)
- := λ r x, (CRmin (fst r) (snd r) <= x ∧ x <= CRmax (fst r) (snd r))%CR.
-
-Instance in_sig_Range `{Container A (Range A)} (P: A → Prop): Container (sig P) (Range (sig P))
- := λ r x, In (` (fst r), ` (snd r)) (` x).
-
-(*Lemma alt_in_QRange (q: Q) (r: Range Q): q ∈ r <->
- (∃ e, 0 <= e <= 1 ∧ fst r + e * (snd r - fst r) == q)%Q.
-Proof with auto.
-Admitted.*)
- (* also: ∃ e, 0 <= e <= 1 ∧ q == fst r * e + snd r * (1 - e) *)
diff --git a/broken/list_separates.v b/metric2/list_separates.v
similarity index 91%
rename from broken/list_separates.v
rename to metric2/list_separates.v
index c9aced95..3d9d7b22 100644
--- a/broken/list_separates.v
+++ b/metric2/list_separates.v
@@ -37,6 +37,7 @@ Instance separates_Proper {A}:
Proof with simpl; auto; intuition.
intros ?? P.
induction P...
+ 3:eauto.
apply s_perm_skip. split...
apply (map_perm_proper (pair_rel eq (@Permutation A)))...
intros ?? [??]. split...
@@ -45,6 +46,7 @@ Proof with simpl; auto; intuition.
do 2 rewrite map_map.
apply (map_perm_proper _ _ _)...
intros ?? [C D]. split...
- apply list_eq_eq in D. rewrite D...
- eauto.
+ apply perm_trans with (l':=(x :: y :: snd x0))...
+ do 2 apply perm_skip...
+ apply SetoidPermutation_eq...
Qed.
From c9fc7019f7948861a28dfb51f290af3d3488d0c0 Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Mon, 1 Sep 2014 16:41:21 +0200
Subject: [PATCH 102/110] Adding files
---
broken/CompletePointFree.v | 75 +++
examples/Picard.v | 207 ++++++
examples/bigD.v | 35 ++
metric2/Classified.v | 1225 ++++++++++++++++++++++++++++++++++++
metric2/Ranges.v | 19 +
5 files changed, 1561 insertions(+)
create mode 100644 broken/CompletePointFree.v
create mode 100644 examples/Picard.v
create mode 100644 examples/bigD.v
create mode 100644 metric2/Classified.v
create mode 100644 metric2/Ranges.v
diff --git a/broken/CompletePointFree.v b/broken/CompletePointFree.v
new file mode 100644
index 00000000..a154a865
--- /dev/null
+++ b/broken/CompletePointFree.v
@@ -0,0 +1,75 @@
+(* This is a test of how to combine type classes with the old records.
+Specifically, how to use the pointfree machinery with the [Complete] monad *)
+Require Import CRtrans.
+Require Import Qmetric.
+
+Section ODE.
+Open Scope uc_scope.
+Require Import ProductMetric CompleteProduct.
+Require Import Unicode.Utf8.
+Require Import metric2.Classified.
+Require Import stdlib_rationals.
+
+(*
+Check (_:MetricSpaceClass (Q*Q)).
+Check (_:MetricSpaceClass (CR*Q)).
+*)
+
+Section bind_uc.
+(* We use the packed MetricSpace because we do not (yet) want to redefine Complete.
+However, here is a first attempt:
+Definition CompleteC Y `{MetricSpaceClass Y}:=(Complete (bundle_MetricSpace Y)).
+ Context `{MetricSpaceClass X} `{MetricSpaceClass Y}
+ {f: X → CompleteC Y} `{!UniformlyContinuous_mu f} `{!UniformlyContinuous f}.
+*)
+
+Context {X Y : MetricSpace} (f: X → Complete Y) `{!UniformlyContinuous_mu f} `{!UniformlyContinuous f}.
+
+(* Definition bindf : Complete X -> Complete Y :=
+ Cbind_slow (wrap_uc_fun' f).
+
+Definition test: UCFunction (Complete X) (Complete Y):=
+ ucFunction (fun x => bindf x). *)
+
+(* The classified version *)
+Definition Cbind_slowC: UCFunction (Complete X) (Complete Y):=
+ ucFunction (Cbind_slow (wrap_uc_fun' f)).
+
+Variable g:X --> Complete Y.
+Definition test': UCFunction (Complete X) (Complete Y):=
+ ucFunction (fun x => (Cbind_slow g) x).
+
+(* Note that: unwrap_uc_fun automatically unwraps g *)
+End bind_uc.
+Notation " f >> g ":= (Cbind_slowC f ∘ g) (at level 50).
+Notation " x >>= f ":= (Cbind_slowC f x) (at level 50).
+
+Section test.
+(* Should Q*Q be bundled ? *)
+Context (v: (Q*Q) → CR)
+ `{!UniformlyContinuous_mu v}
+ `{!UniformlyContinuous v}.
+
+Context (f:Q→CR)
+ `{!UniformlyContinuous_mu f}
+ `{!UniformlyContinuous f}.
+
+(*
+Can be replace by the default (,) ?
+Notation "( f , g )":= (together f g).
+We would like to define fun x => v (x, f x), more precisely:
+*)
+
+Check (Cbind_slowC v).
+Definition vxfx : UCFunction Q CR :=
+ ucFunction (fun x => (Couple (Cunit x, f x) >>= v)).
+
+Better:
+Definition vxfx : UCFunction Q CR :=
+ ucFunction (fun x => (Couple (x, f x) >>= v)).
+
+Where Cunit is derived from the Coercion inject_Q.
+Coercion inject_Q: QArith_base.Q>-> CR.
+But this cannot be a Coercion(?)
+*)
+End test.
\ No newline at end of file
diff --git a/examples/Picard.v b/examples/Picard.v
new file mode 100644
index 00000000..167516a0
--- /dev/null
+++ b/examples/Picard.v
@@ -0,0 +1,207 @@
+Require Import CRtrans.
+Require Import Qmetric.
+
+(* For comparison with Pattison's paper:
+The ODE:
+f'=λx.2f(x)+1
+f(0)=0
+*)
+
+Section ODE.
+Open Scope uc_scope.
+Require Import ProductMetric CompleteProduct.
+Require Import Unicode.Utf8.
+Require Import CPoly_Newton.
+Require Import metric2.Classified.
+Require Import Circle.
+Notation "X * Y":=(ProductMS X Y).
+Notation " f >> g ":= (Cbind_slow f ∘ g) (at level 50).
+Notation " x >>= f ":= (Cbind_slow f x) (at level 50).
+
+Section Picard_op.
+Require Import AbstractIntegration.
+(*
+Require Import stdlib_omissions.Pair.
+For diagonal*)
+
+Variable v: (Q*Q) -->CR.
+Variable f:Q-->CR.
+Notation "( f , g )":= (together f g).
+Definition vxfx:= (v >> Couple ∘ (Cunit, f) ∘ diag _).
+
+Require Import SimpleIntegration.
+
+(* Uniformly continuous function should be a type class
+so that we can define functions using Program Instance *)
+(* Integration takes a width, need the integral from a to b.*)
+
+Definition integral: ((Q-->CR) * Q * Q) -> CR.
+intros [[g a] b].
+destruct (QMinMax.Qlt_le_dec_fast b a).
+assert (a_min_b:Qpos). exists (a-b) . admit.
+exact (- ∫ g b (a_min_b))%CR.
+
+(* Do the zero case *)
+assert (b_min_a:Qpos). exists (b-a). admit.
+exact ( ∫ g a (b_min_a))%CR.
+Defined.
+
+(* Need continuous Q--> CR then continuous CR --> CR *)
+
+
+(* The integral is locally uniformly continuous *)
+(* Context (f: Q -> CR) `{!LocallyUniformlyContinuous_mu f} `{!LocallyUniformlyContinuous f}.*)
+(* Definition intregral_uc:= (is_UniformlyContinuousFunction integral (fun e => e)%Qpos ). *)
+
+Definition Picard_raw:=fun t:Q => integral (f, 0, t).
+
+Lemma Picard_uc: (is_UniformlyContinuousFunction Picard_raw (fun e => e)%Qpos).
+admit.
+Qed.
+(* Locally Lipschitz:
+∫ 0 t f - ∫ 0 s f = ∫ s t f ≤ |t-s| sup_[s,t] f
+Hence the constant is: r sup_B f on the ball B(t,r).
+differentiable maps are Lipschitz.
+Locally Lipschitz functions compose
+on B(x,r),
+| f x - f y | ≤ L_B |x -y|
+Hence fB ⊂ B(f x, L r) and g is Lipschitz cont on this ball.
+*)
+
+Definition Picard:=(Cbind_slow (Build_UniformlyContinuousFunction Picard_uc)).
+End Picard_op.
+
+Section Banach_it.
+Context {X} `(F:X-->X).
+Fixpoint Banach_seq (n : nat) : X --> X :=
+ match n with
+ | O => F
+ | S m => F ∘ (Banach_seq m)
+ end.
+
+Variable f:CR-->CR.
+Check Picard.
+Fixpoint Picard_seq (n : nat) : Q --> CR :=
+ match n with
+ | O => f ∘ Cunit
+ | S m => (Picard (Picard_seq m) )∘ Cunit
+ end.
+End Banach_it.
+
+Section Picard.
+Variable L:Qpos.
+Variable c:Qpos.
+Hypothesis c_unit:1-c>0.
+Program Definition oneminc:=(1-c):Qpos.
+Next Obligation.
+admit.
+Defined.
+Variables a K:Q.
+Hypothesis aL_le_c:(a*LCR.
+
+Hypothesis Lipschitz: forall x, -a<=x -> x<=a -> forall y, -K<=y -> y<=K ->
+ forall y':Q, -K<=y' -> y <=K ->
+ ((CRabs ((v (x, y)) - (v (x, y'))))<= 'L* 'Qabs (y-y'))%CR.
+
+Section BanachFPT.
+Context (X: MetricSpace).
+Context (d:X->X->CR).
+
+(*
+Notation Qset:=QArith.QArith_base.Q.
+Coercion inject_Q:Qset>-> (msp_is_setoid CR).
+*)
+Variable metric_function: forall e x y, ball e x y <-> ((d x y) <='e)%CR.
+Class Contraction `(F:X-->X)`(c:Qpos):= contraction:
+ c<1-> forall x x', ((d x x') <= 'c*(d (F x) (F x')))%CR.
+
+(* forall ϵ, (ball ϵ x x')-> (ball (c*ϵ) (F x) (F x' )) *)
+Context {F}`{conF: Contraction F}.
+Require Export CRGeometricSum.
+
+(*
+Definition InfiniteSum_raw_F rec (err_prop: (Stream X) -> bool) (s:Stream X) : X :=
+if (err_prop s) then 0 else (Qplus' (hd s) (rec err_prop (tl s))).
+
+Definition InfiniteGeometricSum_raw series (e:QposInf) : X :=
+match e with
+| ∞ => 0
+| Qpos2QposInf err => InfiniteSum_raw_N (InfiniteGeometricSum_maxIter series err)
+ (fun err s => 0) (err_prop err) series
+end.
+*)
+
+Lemma bla: forall n m:nat, forall x:X,
+ (ball (c^m) (@Banach_seq _ F n x) (@Banach_seq _ F (n+m) x)).
+Admitted.
+
+Lemma bla2: forall n:nat, forall x:X, (ball (Qpos_inv oneminc) x (@Banach_seq _ F n x)).
+Admitted.
+
+Lemma bla3: forall n m:nat, forall x:X, forall e,
+ (ball e x (F x)) ->
+ (ball (c^m*(Qpos_inv oneminc)*e) (@Banach_seq _ F n x) (@Banach_seq _ F m x)).
+Admitted.
+
+Variable x:X.
+Definition DiffSeries:=fun n => d (@Banach_seq _ F n x) (@Banach_seq _ F (S n) x).
+Require Import StreamMemo.
+Definition DiffStream:=(memo_list _ DiffSeries).
+Require Import Streams.
+
+(* ForAll_map in Streams ?? *)
+Definition GeometricSeriesCR (c:CR):=
+ (ForAll (fun s:Stream CR => (CRabs ((hd (tl s))) <= c*(CRabs(hd s)))%CR)).
+
+Lemma GeomDiff:GeometricSeriesCR ('c)%CR DiffStream.
+unfold GeometricSeriesCR.
+unfold DiffStream.
+unfold memo_list.
+unfold memo_make.
+simpl.
+admit.
+Qed.
+
+(* The Banach sequence is a Cauchy sequence.*)
+
+(* Use:
+Lemma GeometricCovergenceLemma : forall (n:positive) (e:Qpos),
+ /(e*(1 - a)) <= n -> a^n <= e.
+with e:=ϵ *oneminc/ (d x0 x1)
+*)
+
+Lemma BanachCauchy: forall ϵ:Qpos, exists N, forall n m:nat , n >=N-> m>= N ->
+ (ball ϵ (@Banach_seq _ F n x) (@Banach_seq _ F m x)).
+intros.
+(* Needs to be of type Qpos, want Qpos as a type class *)
+(* A rational number bigger than (d x0 x1) *)
+set ceil:=(Qabs (approximate (d (@Banach_seq _ F 0 x) (@Banach_seq _ F 1 x))
+ (Qpos2QposInf (1#1))))+1:Qpos.
+
+exists ( /((ϵ*oneminc/ceil)(oneminc))).
+
+
+(* Note that to apply the geomSum we do compute all the norms *)
+
+
+End BanachFPT.
+
+Section BanachFPT2.
+Context {X} (F:Complete X--> Complete X) `{conF: Contraction (Complete X) F}.
+Theorem BanachFPT : exists x, (F x) =x.
+eexists y.
+Admitted.
+(* x= lim F^n
+F x - x = F lim F^n - lim F^n = lim F^n+1 - lim F^n.
+*)
+
+(* Moreover, it is unique *)
+
+Theorem PicardFPT: exists f, (Picard f) = (f ∘ Cunit).
+apply BanachFPT.
+Qed.
\ No newline at end of file
diff --git a/examples/bigD.v b/examples/bigD.v
new file mode 100644
index 00000000..62d61279
--- /dev/null
+++ b/examples/bigD.v
@@ -0,0 +1,35 @@
+Require Import
+ Program QArith ZArith BigZ Qpossec
+ MetricMorphisms Qmetric Qdlog ARArith
+ theory.int_pow theory.nat_pow
+ stdlib_rationals stdlib_binary_integers fast_integers dyadics.
+
+Add Field Q : (dec_fields.stdlib_field_theory Q).
+
+Notation bigD := (Dyadic bigZ).
+
+Print Dyadic.
+
+(* We want to avoid timing the printing mechanism *)
+
+Definition test:bigD->True.
+intro x;auto.
+Defined.
+
+Definition x:bigD:= (dyadic (10000000%bigZ) (100000%bigZ)).
+Definition square:bigD-> bigD:=fun x:bigD => (dy_mult x x) .
+Check dy_pow.
+
+Check (Z⁺).
+Check NonNeg.
+SearchAbout NonNeg.
+Check ((1 _):(Z⁺)).
+
+(* Time Eval vm_compute in (test (dy_pow x (((40%Z) _)))).*)
+
+Time Eval native_compute in (test (square x)).
+
+
+Require Import ARbigD.
+Time Eval vm_compute in (test (bigD_div (square x) x (10000%Z))).
+Require Import ApproximateRationals.
diff --git a/metric2/Classified.v b/metric2/Classified.v
new file mode 100644
index 00000000..2065b13c
--- /dev/null
+++ b/metric2/Classified.v
@@ -0,0 +1,1225 @@
+
+(** MathClasses-style operational & structural classes for a Russell-style metric space (i.e. MetricSpace).
+ We don't put this in MathClasses because for reasons of interoperability with the existing MetricSpace
+ it is still bound to stdlib Q rather than an abstract Rationals implementation. *)
+
+Require Import
+ Arith List
+ CSetoids Qmetric Qring Qinf ProductMetric QposInf Qposclasses (* defines Equiv on Qpos *)
+ UniformContinuity stdlib_rationals
+ stdlib_omissions.Pair stdlib_omissions.Q PointFree
+ interfaces.abstract_algebra
+ theory.setoids theory.products.
+
+Import Qinf.notations.
+
+Require Vector.
+
+Section MetricSpaceClass.
+
+ Variable X: Type.
+
+ Class MetricSpaceBall: Type := mspc_ball: Qinf → relation X.
+Hint Unfold relation : type_classes.
+ (** We used to have mspc_ball take a Qpos instead of a Qinf. Because it is sometimes convenient
+ to speak in terms of a generalized notion of balls that can have infinite or negative radius, we used
+ a separate derived definition for that (which return False for negative radii, True for an infinite radius,
+ and reduced to setoid equality for a radius equal to 0). This kinda worked, but had a big downside.
+ The derived generalized ball relation (let's call it "gball") was defined using case distinctions on the
+ finiteness and sign of the radius. These case distinctions routinely got in the way, because it
+ meant that e.g. gball for the product metric space did not reduce to the composition of gballs derived
+ for the constituent metrics spaces. Consequently, both the basic ball and the generalized ball
+ relation were used side-by-side, and converting between the two was a constant annoyance.
+
+ Because of this, we now use the generalized type for the "basic" ball. Now the product metric space's
+ (generalized) ball relation is defined directly in terms of the constituent metric spaces' balls, and
+ so reduces nicely. It also means that there is now a _single_ ball relation that is used everywhere.
+
+ Of course, when defining the ball relation for a concrete metric space, the generalization to a Qinf
+ parameter implies "more work". Fortunately, the additional work can be factored out into a smart
+ constructor (defined later in this module) that takes the version with a Qpos parameter and extends
+ it to Qinf in the way described above. All the ball's properties can be lifted along with this extension. *)
+
+ Context `{!Equiv X} `{!MetricSpaceBall}.
+
+ Class MetricSpaceClass: Prop :=
+ { mspc_setoid : Setoid X
+ ; mspc_ball_proper:> Proper (=) mspc_ball
+ ; mspc_ball_inf: ∀ x y, mspc_ball Qinf.infinite x y
+ ; mspc_ball_negative: ∀ (e: Q), (e < 0)%Q → ∀ x y, ~ mspc_ball e x y
+ ; mspc_ball_zero: ∀ x y, mspc_ball 0 x y ↔ x = y
+ ; mspc_refl:> ∀ e, (0 <= e)%Qinf → Reflexive (mspc_ball e)
+ ; mspc_sym:> ∀ e, Symmetric (mspc_ball e)
+ ; mspc_triangle: ∀ (e1 e2: Qinf) (a b c: X),
+ mspc_ball e1 a b → mspc_ball e2 b c → mspc_ball (e1 + e2) a c
+ ; mspc_closed: ∀ (e: Qinf) (a b: X),
+ (∀ d: Qpos, mspc_ball (e + d) a b) → mspc_ball e a b }.
+
+ Context `{MetricSpaceClass}.
+Local Existing Instance mspc_setoid.
+ (** Two simple derived properties: *)
+ Lemma mspc_eq a b: (∀ e: Qpos, mspc_ball e a b) → a = b.
+ Proof with auto.
+ intros.
+ apply mspc_ball_zero.
+ apply mspc_closed.
+ intros.
+ setoid_replace (@plus Qinf _ 0 d) with (d: Qinf)...
+ change (0 + d == d). ring.
+ Qed. (* Todo: Use a bi-impl instead. *)
+
+ Lemma mspc_ball_weak_le (q q': Qinf): (q <= q')%Qinf → ∀ x y: X, mspc_ball q x y → mspc_ball q' x y.
+ Proof with auto.
+ destruct q, q'; simpl; intros...
+ assert (q0 == q + (q0 - q))%Q as E by ring.
+ rewrite E.
+ change (mspc_ball (Qinf.finite q + Qinf.finite (q0 - q)%Q) x y).
+ apply mspc_triangle with y...
+ apply mspc_refl.
+ simpl.
+ apply QArith_base.Qplus_le_r with q.
+ ring_simplify...
+ apply mspc_ball_inf.
+ intuition.
+ Qed.
+
+ (** Instances can be bundled to yield MetricSpaces: *)
+ Program Definition bundle_MetricSpace: MetricSpace :=
+ @Build_MetricSpace (mcSetoid_as_RSetoid X) mspc_ball _ _.
+
+ Next Obligation. apply mspc_ball_proper; assumption. Qed.
+
+ Next Obligation. Proof with auto.
+ constructor; try apply _.
+ intro e. apply mspc_refl...
+ intros. apply (mspc_triangle e1 e2 a b c)...
+ intros. apply mspc_closed...
+ apply mspc_eq.
+ Qed.
+
+ (** .. which obviously have the same carrier: *)
+
+ Goal X ≡ bundle_MetricSpace.
+ Proof. reflexivity. Qed.
+
+End MetricSpaceClass.
+
+Instance: Params (@mspc_ball) 2.
+
+Hint Resolve Qlt_le_weak Qplus_lt_le_0_compat.
+ (* Todo: Move. *)
+
+(** We now define the smart constructor that builds a MetricSpace from a ball relation with positive radius. *)
+
+Section genball.
+
+ Context
+ `{Setoid X}
+ (R: Qpos → relation X) `{!Proper (QposEq ==> (=)) R} `{∀ e, Reflexive (R e)} `{∀ e, Symmetric (R e)}
+ (Rtriangle: ∀ (e1 e2: Qpos) (a b c: X), R e1 a b → R e2 b c → R (e1 + e2)%Qpos a c)
+ (Req: ∀ (a b: X), (∀ d: Qpos, R d a b) → a = b)
+ (Rclosed: ∀ (e: Qpos) (a b: X), (∀ d: Qpos, R (e + d)%Qpos a b) → R e a b).
+
+ Definition genball: MetricSpaceBall X := λ (oe: Qinf),
+ match oe with
+ | Qinf.infinite => λ _ _, True
+ | Qinf.finite e =>
+ match Qdec_sign e with
+ | inl (inl _) => λ _ _ , False
+ | inl (inr p) => R (exist (Qlt 0) e p)
+ | inr _ => equiv
+ end
+ end.
+
+ Definition ball_genball (q: Qpos) (a b: X): genball q a b ↔ R q a b.
+ Proof.
+ unfold genball.
+ destruct Qdec_sign as [[|]|U].
+ exfalso.
+ destruct q.
+ apply (Qlt_is_antisymmetric_unfolded 0 x); assumption.
+ apply Proper0; reflexivity.
+ exfalso.
+ destruct q.
+ simpl in U.
+ revert q.
+ rewrite U.
+ apply Qlt_irrefl.
+ Qed.
+
+ Lemma genball_alt (q: Q) (x y: X):
+ genball q x y <->
+ match Qdec_sign q with
+ | inl (inl _) => False
+ | inl (inr p) => genball q x y
+ | inr _ => x=y
+ end.
+ Proof.
+ unfold genball. simpl.
+ split; destruct Qdec_sign as [[|]|]; auto.
+ Qed.
+
+ Instance genball_Proper: Proper ((=) ==> (=) ==> (=) ==> iff) genball.
+ Proof with auto; intuition.
+ unfold genball.
+ intros u e' E.
+ destruct u, e'.
+ change (q = q0) in E.
+ destruct Qdec_sign as [[|]|]; destruct Qdec_sign as [[|]|].
+ repeat intro...
+ exfalso. revert q1. apply Qlt_is_antisymmetric_unfolded. rewrite E...
+ exfalso. revert q1. rewrite E. rewrite q2. apply Qlt_irrefl.
+ exfalso. revert q1. rewrite E. apply Qlt_is_antisymmetric_unfolded...
+ apply Proper0...
+ exfalso. revert q1. rewrite E, q2. apply Qlt_irrefl.
+ exfalso. revert q2. rewrite <- E, q1. apply Qlt_irrefl.
+ exfalso. revert q2. rewrite <- E, q1. apply Qlt_irrefl.
+ intros ?? A ?? B. rewrite A, B...
+ repeat intro...
+ intuition.
+ repeat intro.
+ reflexivity.
+ Qed.
+
+Instance: ∀ e, Proper ((=) ==> (=) ==> iff) (genball e).
+Proof. intros; now apply genball_Proper. Qed.
+
+ Lemma genball_negative (q: Q): (q < 0)%Q → ∀ x y: X, ~ genball q x y.
+ Proof with auto.
+ unfold genball.
+ intros E ??.
+ destruct Qdec_sign as [[|]|U]; intro...
+ apply (Qlt_is_antisymmetric_unfolded 0 q)...
+ revert E.
+ rewrite U.
+ apply Qlt_irrefl.
+ Qed.
+
+ Lemma genball_Reflexive (q: Qinf): (0 <= q)%Qinf → Reflexive (genball q).
+ Proof with auto.
+ repeat intro.
+ unfold genball.
+ destruct q...
+ destruct Qdec_sign as [[|]|]; intuition...
+ apply (Qlt_not_le q 0)...
+ Qed.
+
+ Global Instance genball_Symmetric: ∀ e, Symmetric (genball e).
+ Proof with auto.
+ intros [q|]... simpl. destruct Qdec_sign as [[|]|]; try apply _...
+ Qed.
+
+ Lemma genball_triangle (e1 e2: Qinf) (a b c: X): genball e1 a b → genball e2 b c → genball (e1 + e2) a c.
+ Proof with auto.
+ intros U V.
+ destruct e1 as [e1|]...
+ destruct e2 as [e2|]...
+ apply genball_alt.
+ apply genball_alt in U.
+ apply genball_alt in V.
+ destruct (Qdec_sign (e1 + e2)) as [[G | I] | J];
+ destruct (Qdec_sign e1) as [[A | B] | C];
+ destruct (Qdec_sign e2) as [[D | E] | F]; intuition.
+ revert G. apply (Qlt_is_antisymmetric_unfolded _ _)...
+ revert G. rewrite F, Qplus_0_r. apply (Qlt_is_antisymmetric_unfolded _ _ B)...
+ revert G. rewrite C, Qplus_0_l. apply (Qlt_is_antisymmetric_unfolded _ _ E)...
+ revert G. rewrite C, F. apply Qlt_irrefl.
+ change (genball (exist _ e1 B + exist _ e2 E )%Qpos a c).
+ apply ball_genball.
+ apply Rtriangle with b; apply ball_genball...
+ rewrite <- V. Admitted. (*rewrite F. rewrite Qplus_0_r...
+ rewrite U, C, Qplus_0_l...
+ exfalso. apply (Qlt_irrefl (e1 + e2)). rewrite -> C at 1. rewrite -> F at 1...
+ exfalso. apply (Qlt_irrefl (e1 + e2)). rewrite -> J at 1...
+ revert U. rewrite <- V, <- (Qplus_0_r e1), <- F, J...
+ revert V. rewrite <- (Qplus_0_l e2), <- C, J, U...
+ transitivity b...
+ Qed.*)
+
+ Lemma genball_closed :
+ (∀ (e: Qinf) (a b: X), (∀ d: Qpos, genball (e + d) a b) → genball e a b).
+ Proof with auto with *.
+ intros.
+ unfold genball.
+ destruct e...
+ destruct Qdec_sign as [[|]|].
+ assert (0 < (1#2) * -q)%Q.
+ apply Qmult_lt_0_compat...
+ apply Qopp_Qlt_0_l...
+ pose proof (H2 (exist _ _ H3)).
+ refine (genball_negative _ _ _ _ H4).
+ simpl.
+ ring_simplify.
+ apply Qopp_Qlt_0_l...
+ setoid_replace (- ((1 # 2) * q))%Q with (-q * (1#2))%Q by (simpl; ring).
+ apply Qmult_lt_0_compat...
+ apply Qopp_Qlt_0_l...
+ apply Rclosed.
+ intros.
+ apply ball_genball.
+ apply (H2 d).
+ apply Req.
+ intros.
+ apply ball_genball.
+ admit.
+ (*rewrite <- (Qplus_0_l d).
+ rewrite <- q0.
+ apply H2.*)
+ Qed.
+
+ Instance genball_MetricSpace: @MetricSpaceClass X _ genball.
+ Proof with auto.
+ constructor; try apply _.
+ unfold mspc_ball. simpl...
+ apply genball_negative.
+ reflexivity.
+ apply genball_Reflexive.
+ apply genball_triangle.
+ apply genball_closed.
+ Qed.
+
+End genball.
+
+(** Bundled MetricSpaces immediately yield instances of the classes: *)
+
+Instance: ∀ X: MetricSpace, MetricSpaceBall X := λ X, @genball X _ (@ball X).
+
+Instance class_from_MetricSpace (X: MetricSpace): MetricSpaceClass X.
+Proof.
+ apply genball_MetricSpace; try apply _.
+ apply msp_refl, X.
+ apply msp_sym, X.
+(* apply msp_triangle, X.
+ apply msp_eq, X.
+ apply msp_closed, X.
+Qed.*)
+Admitted.
+
+Section products.
+
+ Context `{MetricSpaceClass X} `{MetricSpaceClass Y}.
+
+ Global Instance: MetricSpaceBall (X * Y)
+ := λ e a b, mspc_ball X e (fst a) (fst b) ∧ mspc_ball Y e (snd a) (snd b).
+
+ (* We do not reuse ProductMS here because to do so we'd need to go through genball,
+ resulting in the problems described earlier. *)
+
+ Global Instance: MetricSpaceClass (X * Y).
+ Proof with auto.
+ pose (mspc_setoid X).
+ pose (mspc_setoid Y).
+ constructor.
+ apply _.
+ repeat intro.
+ split.
+ split.
+ rewrite <- H3, <- H4, <- H5. apply H6.
+ rewrite <- H3, <- H4, <- H5. apply H6.
+ split. rewrite -> H3, H4, H5. apply H6.
+ rewrite -> H3, H4, H5. apply H6.
+ split. apply (mspc_ball_inf X).
+ apply (mspc_ball_inf Y).
+ repeat intro.
+ destruct H4.
+ apply (mspc_ball_negative X _ H3 _ _ H4).
+ intros.
+ change ((mspc_ball X 0 (fst x) (fst y) ∧ mspc_ball Y 0 (snd x) (snd y)) ↔ x = y).
+ rewrite (mspc_ball_zero X), (mspc_ball_zero Y). reflexivity.
+ split. apply (mspc_refl X)...
+ apply (mspc_refl Y)...
+ split; apply (@symmetry _ _ ); try apply _; apply H3. (* just using [symmetry] here causes evar anomalies.. *)
+ split.
+ apply (mspc_triangle X) with (fst b).
+ apply H3.
+ apply H4.
+ apply (mspc_triangle Y) with (snd b).
+ apply H3.
+ apply H4.
+ split.
+ apply (mspc_closed X). apply H3.
+ apply (mspc_closed Y). apply H3.
+ Qed.
+
+End products.
+
+Definition vector_zip {X Y} {n} : Vector.t X n → Vector.t Y n → Vector.t (X * Y) n :=
+ Vector.rect2 (λ n _ _, Vector.t (X * Y) n)
+ (Vector.nil _)
+ (λ _ _ _ r (x: X) (y: Y), Vector.cons _ (x, y) _ r).
+ (* Todo: Move. *)
+
+Section vector_setoid.
+
+ Context `{Setoid X} (n: nat).
+
+ Global Instance: Equiv (Vector.t X n) := Vector.Forall2 equiv.
+
+ Global Instance vector_setoid: Setoid (Vector.t X n).
+ Proof with auto.
+ constructor.
+ repeat intro.
+ unfold equiv.
+ unfold Equiv_instance_0.
+ induction x; simpl; constructor...
+ Admitted.
+(* reflexivity.
+ unfold equiv.
+ unfold Equiv_instance_0.
+ unfold Symmetric.
+ intros.
+ revert n x y H0.
+ apply Vector.Forall2_ind; constructor...
+ symmetry...
+ admit. (* transitivity *)
+ Qed.*)
+
+End vector_setoid. (* Todo: Move. *)
+
+Section vectors.
+
+ Context `{MetricSpaceClass X} (n: nat).
+
+ Global Instance: MetricSpaceBall (Vector.t X n) := λ e, Vector.Forall2 (mspc_ball X e).
+
+ Global Instance: MetricSpaceClass (Vector.t X n).
+ Proof with auto.
+ pose proof (mspc_setoid X).
+ split.
+ apply _.
+ admit.
+ admit.
+ admit.
+ admit.
+ admit.
+ admit.
+ admit.
+ admit.
+ Qed.
+
+End vectors.
+
+(** I decided to experiment with a class used strictly to declare a metric space's
+ components in a section using [Context] without also declaring the metric space structure
+ itself, and risking accidental parameterization of the section context on the proof of that
+ metric space structure if such parametrization is unneeded (for instance because there is
+ already a UniformContinuous constraint which incorporates the metric space proof. *)
+
+Class MetricSpaceComponents X `{Equiv X} `{MetricSpaceBall X}: Prop.
+
+(** Next, we introduce classes for uniform continuity (which is what we're really after, since
+ we will use these to automatically derive uniform continuity for various forms of function
+ composition). *)
+
+Implicit Arguments mspc_ball [[X] [MetricSpaceBall]].
+
+Class Canonical (T: Type): Type := canonical: T.
+ (* Todo: Move. *)
+
+Instance: ∀ {T: Type}, Canonical (T → T) := @Datatypes.id.
+
+Instance: Canonical (Qpos → Qinf) := Qinf.finite ∘ QposAsQ.
+
+Instance composed_Proper `{Equiv A} `{Equiv B} `{Equiv C} (f: B → C) (g: A → B):
+ Proper (=) f → Proper (=) g → Proper (=) (f ∘ g).
+Proof with auto.
+ repeat intro.
+ unfold Basics.compose.
+ apply H2.
+ apply H3.
+ assumption.
+Qed.
+
+Instance: Proper (QposEq ==> (=)) QposAsQ.
+Proof. repeat intro. assumption. Qed.
+
+Require Import util.Container.
+
+Definition Ball X R := prod X R.
+Hint Extern 0 (Equiv (Ball _ _)) => eapply @prod_equiv : typeclass_instances.
+
+Section Ball.
+ Context X `{MetricSpaceBall X} (R: Type) `{Canonical (R → Qinf)}.
+
+ Global Instance ball_contains: Container X (Ball X R) := fun b => mspc_ball (canonical (snd b)) (fst b).
+
+ Context `{Equiv X} `{Equiv R} `{!MetricSpaceClass X} `{!Proper (=) (canonical: R → Qinf)}.
+
+ Global Instance ball_contains_Proper: Proper (=) (In: Ball X R → X → Prop).
+ Proof with auto.
+ repeat intro.
+ unfold In, ball_contains.
+ apply (mspc_ball_proper X)...
+ apply Proper0.
+ apply H3.
+ apply H3.
+ Qed. (* Todo: Clean up. *)
+
+End Ball.
+
+
+(*Instance: Params (@contains) 4.
+
+Implicit Arguments contains [[X] [H] [H0] [R]].*)
+
+
+Section sig_metricspace.
+
+ Context `{MetricSpaceClass X} (P: X → Prop).
+
+ Global Instance sig_mspc_ball: MetricSpaceBall (sig P) := λ e x y, mspc_ball e (` x) (` y).
+
+ Global Instance sig_mspc: MetricSpaceClass (sig P).
+ Proof with auto.
+ pose proof (mspc_setoid X).
+ constructor.
+ apply _.
+ repeat intro.
+ change (mspc_ball x (` x0) (` x1) = mspc_ball y (` y0) (` y1)).
+ apply (mspc_ball_proper X)...
+ repeat intro.
+ change (mspc_ball Qinf.infinite (` x) (` y)).
+ apply (mspc_ball_inf X).
+ repeat intro. apply (mspc_ball_negative X e H2 (` x) (` y))...
+ intros.
+ change (mspc_ball 0 (` x) (` y) ↔ (` x) = (` y)).
+ apply (mspc_ball_zero X).
+ repeat intro.
+ change (mspc_ball e (` x) (` x)).
+ apply (mspc_refl X)...
+ repeat intro.
+ change (mspc_ball e (` y) (` x)).
+ symmetry...
+ repeat intro.
+ apply (mspc_triangle X e1 e2 (` a) (` b))...
+ intros.
+ apply (mspc_closed X e (` a) (` b))...
+ Qed.
+
+End sig_metricspace.
+
+Instance Qpos_mspc_ball: MetricSpaceBall Qpos := @sig_mspc_ball Q_as_MetricSpace _ (Qlt 0).
+Instance Qpos_mspc: MetricSpaceClass Qpos := @sig_mspc Q_as_MetricSpace _ _ _ (Qlt 0).
+
+Instance: Cast QnnInf.T Qinf :=
+ λ x, match x with
+ | QnnInf.Infinite => Qinf.infinite
+ | QnnInf.Finite q => Qinf.finite q
+ end.
+
+Section uniform_continuity.
+
+ Context `{MetricSpaceComponents X} `{MetricSpaceComponents Y}.
+
+ Class UniformlyContinuous_mu (f: X → Y): Type := { uc_mu: Qpos → QposInf }.
+ (* Note: If we omit the {} around the uc_mu field and let the class become a definitional class,
+ instance resolution will often find the wrong instance because the type of uc_mu is the same for
+ different instantiations of X and Y. This solution is not ideal. *)
+
+ Context (f: X → Y) `{!UniformlyContinuous_mu f}.
+
+ Class UniformlyContinuous: Prop :=
+ { uc_from: MetricSpaceClass X
+ ; uc_to: MetricSpaceClass Y
+ ; uniformlyContinuous: ∀ (e: Qpos) (a b: X), mspc_ball (uc_mu e) a b → mspc_ball e (f a) (f b) }.
+
+ (** If we have a function with this constraint, then we can bundle it into a UniformlyContinuousFunction: *)
+
+ Context `{uc: UniformlyContinuous}.
+
+ Let hint := uc_from.
+ Let hint' := uc_to.
+
+(* Program Definition wrap_uc_fun
+ : UniformlyContinuousFunction (bundle_MetricSpace X) (bundle_MetricSpace Y)
+ := @Build_UniformlyContinuousFunction (bundle_MetricSpace X) (bundle_MetricSpace Y) f uc_mu _.
+
+ Next Obligation. Proof with auto.
+ repeat intro.
+ unfold ball. simpl.
+ apply uniformlyContinuous.
+ destruct uc_mu...
+ apply (mspc_ball_inf X).
+ Qed.*)
+
+ (** Note that wrap_uc_fun _also_ bundles the source and target metric spaces, because
+ UniformlyContinuousFunction is expressed in terms of the bundled data type for metric spaces. *)
+
+End uniform_continuity.
+
+Implicit Arguments uc_mu [[X] [Y] [UniformlyContinuous_mu]].
+
+(** Local uniform continuity just means that the function restricted to any finite balls
+ is uniformly continuous: *)
+
+Section local_uniform_continuity.
+
+ Context `{MetricSpaceComponents X} `{MetricSpaceComponents Y}.
+
+ Definition restrict (b: Ball X Qpos) (f: X → Y): sig ((∈ b)) → Y
+ := f ∘ @proj1_sig _ _.
+
+ Class LocallyUniformlyContinuous_mu (f: X → Y): Type :=
+ luc_mu (b: Ball X Qpos):> UniformlyContinuous_mu (restrict b f).
+
+ Context (f: X → Y) {mu: LocallyUniformlyContinuous_mu f}.
+
+ Class LocallyUniformlyContinuous: Prop :=
+ { luc_from: MetricSpaceClass X
+ ; luc_to: MetricSpaceClass Y
+ ; luc_uc (b: Ball X Qpos): UniformlyContinuous (restrict b f) }.
+
+ Context `{LocallyUniformlyContinuous}.
+
+ Instance luc_Proper: Proper (=) f.
+ Proof with simpl; intuition.
+ repeat intro.
+ pose proof luc_to.
+ apply (mspc_eq Y).
+ intros.
+ set (b := (x, e): Ball X Qpos).
+ destruct H5.
+ specialize (luc_uc0 b).
+ destruct luc_uc0.
+ unfold restrict in uniformlyContinuous0.
+ unfold Basics.compose in *.
+ pose proof (mspc_setoid X).
+ assert (x ∈ b).
+ subst b. unfold In, ball_contains. simpl.
+ apply (mspc_refl X)...
+ assert (y ∈ b).
+ rewrite <- H6...
+ apply (uniformlyContinuous0 e (exist _ x H9) (exist _ y H10)).
+ change (mspc_ball (uc_mu (restrict b f) e) x y).
+ rewrite <- H6.
+ apply (mspc_refl X).
+ simpl.
+ set (uc_mu (restrict b f) e).
+ destruct q; simpl...
+ Qed.
+
+End local_uniform_continuity.
+
+
+Section local_from_global_continuity.
+
+ Context `{MetricSpaceComponents X} `{MetricSpaceComponents Y}.
+
+ Context (f: X → Y) {mu: UniformlyContinuous_mu f} {uc: UniformlyContinuous f}.
+
+ Instance local_from_global_uc_mu: LocallyUniformlyContinuous_mu f
+ := λ _, Build_UniformlyContinuous_mu _ (uc_mu f).
+
+ Instance local_from_global_uc: LocallyUniformlyContinuous f.
+ Proof with auto.
+ constructor.
+ apply uc.
+ apply uc.
+ intro.
+ pose proof (uc_from f).
+ pose proof (uc_to f).
+ constructor; try apply _.
+ intros.
+ apply (uniformlyContinuous f).
+ assumption.
+ Qed.
+
+End local_from_global_continuity.
+
+
+(** Normally, we would like to use the type class constraints whenever we need uniform continuity of
+ functions, including in the types for higher order functions. For instance, we would like to assign
+ an integration function for uniformly continuous functions a type along the lines of:
+ ∀ (f: sig (∈ r) → CR) `{!UniformlyContinuous f}, CR
+ However, dependent types like these get in the way when we subsequently want to express continuity
+ of this higher order function itself. Hence, a modicum of bundling is hard to avoid. However, we
+ only need to bundle the components of the uniformly continuous function itself---there is no need to
+ also start bundling source and target metric spaces the way UniformlyContinuousFunction and
+ wrap_uc_fun do. Hence, we now introduce a record for uniformly continuous functions that does not
+ needlessly bundle the source and target metric spaces. *)
+
+Section shallowly_wrapped_ucfuns.
+
+ Context `{@MetricSpaceComponents X Xe Xb} `{@MetricSpaceComponents Y Ye Yb}.
+ (* We must name Xe/Xb/Ye/Yb here so that we can repeat them in the implicit argument
+ specification later on. This could have been avoided if Coq offered more flexible
+ commands for implicit argument specification that would let one reset implicit-ness for
+ individual parameters without restating the whole list. *)
+
+ Record UCFunction: Type := ucFunction
+ { ucFun_itself:> X → Y
+ ; ucFun_mu: UniformlyContinuous_mu ucFun_itself
+ ; ucFun_uc: UniformlyContinuous ucFun_itself }.
+
+ Global Instance: ∀ (f: UCFunction), Proper (=) (f: X → Y).
+ Proof. intros. destruct f.
+ simpl.
+ set (local_from_global_uc_mu ucFun_itself0).
+ apply (@luc_Proper X _ _ Y _ _ ucFun_itself0 l).
+ apply (local_from_global_uc _).
+ Qed.
+
+End shallowly_wrapped_ucfuns.
+
+
+Existing Instance ucFun_mu.
+Existing Instance ucFun_uc.
+
+Implicit Arguments UCFunction [[Xe] [Xb] [Yb] [Ye]].
+Implicit Arguments ucFunction [[X] [Xe] [Xb] [Y] [Yb] [Ye] [ucFun_mu] [ucFun_uc]].
+
+
+Section delegated_mspc.
+
+ Context (X: Type) `{MetricSpaceClass Y} (xy: X → Y).
+
+ Instance delegated_ball: MetricSpaceBall X := λ e a b, mspc_ball e (xy a) (xy b).
+
+ Instance delegated_equiv: Equiv X := λ a b, xy a = xy b.
+
+ Instance delegated_mspc: MetricSpaceClass X.
+ Proof with intuition.
+ constructor.
+ admit.
+ repeat intro.
+ unfold mspc_ball, delegated_ball.
+ apply (mspc_ball_proper Y)...
+ intros.
+ unfold mspc_ball, delegated_ball.
+ apply (mspc_ball_inf Y).
+ repeat intro.
+ apply (mspc_ball_negative Y e H1 (xy x) (xy y))...
+ intros.
+ unfold mspc_ball, delegated_ball.
+ rewrite (mspc_ball_zero Y).
+ reflexivity.
+ unfold mspc_ball, delegated_ball.
+ repeat intro.
+ apply (mspc_refl Y e H1).
+ unfold mspc_ball, delegated_ball.
+ repeat intro.
+ apply (mspc_sym Y)...
+ unfold mspc_ball, delegated_ball.
+ intros e1 e2 a b c.
+ apply (mspc_triangle Y e1 e2).
+ unfold mspc_ball, delegated_ball.
+ intros.
+ apply (mspc_closed Y)...
+ Qed.
+
+End delegated_mspc.
+
+
+Section proper_functions.
+
+ (* Todo: This is bad. Make instances for (@sig (A → B) (Proper equiv)) instead and delegate to it for UCFunction. *)
+
+ Context `{Setoid A} `{MetricSpaceClass B}.
+
+ Let T := (@sig (A → B) (Proper equiv)).
+
+ Global Instance: Equiv T := λ x y, proj1_sig x = proj1_sig y.
+
+ Let hint' := mspc_setoid B.
+
+ Global Instance: Setoid T.
+ Proof with intuition.
+ constructor.
+ intros ????.
+ destruct x...
+ repeat intro. (*symmetry...
+ repeat intro.
+ transitivity (proj1_sig y x0)...
+ Qed.*)
+ Admitted.
+
+ Global Instance: MetricSpaceBall T := λ e f g, Qinf.le 0 e ∧ ∀ a, mspc_ball e (` f a) (` g a).
+ (* The 0<=e condition is needed because otherwise if A is empty, we cannot deduce
+ False from a premise of two functions being inside a negative ball of eachother.
+ If this turns out to be annoying, we can make a separate higher-priority metric space instance
+ for functions from a known-nonempty type (registered with a NonEmpty type class). *)
+
+ Global Instance ProperFunction_mspc: MetricSpaceClass T.
+ Proof with simpl; auto; try reflexivity.
+ constructor; try apply _.
+ split.
+ split.
+ rewrite <- H2.
+ apply H5.
+ intros.
+ rewrite <- H2.
+ rewrite <- (H3 a). 2: reflexivity.
+ rewrite <- (H4 a). 2: reflexivity.
+ apply H5...
+ split.
+ rewrite H2. apply H5.
+ intros.
+ rewrite H2.
+ rewrite (H3 a). 2: reflexivity.
+ rewrite (H4 a). 2: reflexivity.
+ apply H5.
+ split.
+ simpl.
+ auto.
+ intros.
+ apply (mspc_ball_inf B).
+ repeat intro.
+ unfold mspc_ball in H3.
+ destruct H3.
+ simpl in H3.
+ apply (Qlt_not_le e 0)...
+ unfold mspc_ball.
+ unfold MetricSpaceBall_instance_2.
+ intros.
+ split.
+ repeat intro.
+ destruct H2.
+ destruct x.
+ (*simpl.
+ rewrite H3.
+ apply (mspc_ball_zero B)...
+ split.
+ simpl. auto with *.
+ intros.
+ apply (mspc_ball_zero B)...
+ apply H2.
+ reflexivity.
+ split. simpl. auto.
+ intros.
+ apply (mspc_refl B e)...
+ split.
+ apply H2.
+ intros.
+ apply (mspc_sym B).
+ apply H2.
+ split.
+ apply Qinf.le_0_plus_compat.
+ apply H2.
+ apply H3.
+ intros.
+ apply (mspc_triangle B) with (proj1_sig b a0).
+ apply H2.
+ apply H3.
+ split.
+ destruct e. 2: simpl; auto.
+ unfold mspc_ball in H2.
+ unfold MetricSpaceBall_instance_2 in H2.
+ destruct (Qdec_sign q) as [[|]|].
+ exfalso.
+ assert (0 < (1#2) * -q)%Q.
+ apply Qmult_lt_0_compat...
+ apply Qopp_Qlt_0_l...
+ destruct (H2 (exist _ _ H3)).
+ simpl in H4.
+ clear H3 H5.
+ ring_simplify in H4.
+ apply (Qlt_not_le q 0). auto.
+ setoid_replace q with ((1 # 2) * q + (1 # 2) * q)%Q by (simpl; ring).
+ apply Qplus_nonneg...
+ simpl. auto with *.
+ rewrite q0.
+ simpl.
+ apply Qle_refl.
+ intros.
+ apply (mspc_closed B).
+ intros.
+ apply H2.
+ Qed.*) (* Todo: This is awful. Clean it up once these blasted evar anomalies are under control. *)
+ Admitted.
+
+End proper_functions.
+
+
+Section uc_functions.
+
+ (* Todo: Just delegate to proper_functions. *)
+
+ Context `{MetricSpaceClass A} `{MetricSpaceClass B}.
+
+ Global Instance: Equiv (UCFunction A B) := equiv: relation (A→B).
+
+ Let hint := mspc_setoid A.
+ Let hint' := mspc_setoid B.
+
+ Global Instance: Setoid (UCFunction A B).
+ Proof with intuition.
+ constructor.
+ intros ????.
+ set (_: Proper (=) (ucFun_itself x)).
+ destruct x...
+ repeat intro. (*symmetry...
+ intros ? y ??? x. transitivity (y x)...
+ Qed.*)
+ Admitted.
+
+ Global Instance: MetricSpaceBall (UCFunction A B) := λ e f g, Qinf.le 0 e ∧ ∀ a, mspc_ball e (f a) (g a).
+ (* The 0<=e condition is needed because otherwise if A is empty, we cannot deduce
+ False from a premise of two functions being inside a negative ball of eachother.
+ If this turns out to be annoying, we can make a separate higher-priority metric space instance
+ for functions from a known-nonempty type (registered with a NonEmpty type class). *)
+
+ Global Instance UCFunction_MetricSpace: MetricSpaceClass (UCFunction A B).
+ Proof with simpl; auto; try reflexivity.
+ constructor; try apply _.
+ split.
+ split.
+ rewrite <- H3.
+ apply H6.
+ intros.
+ (*rewrite <- H3.
+ rewrite <- (H4 a). 2: reflexivity.
+ rewrite <- (H5 a). 2: reflexivity.
+ apply H6...
+ split.
+ rewrite H3. apply H6.
+ intros.
+ rewrite H3.
+ rewrite (H4 a). 2: reflexivity.
+ rewrite (H5 a). 2: reflexivity.
+ apply H6.
+ split.
+ simpl.
+ auto.
+ intros.
+ apply (mspc_ball_inf B).
+ repeat intro.
+ unfold mspc_ball in H4.
+ destruct H4.
+ simpl in H4.
+ apply (Qlt_not_le e 0)...
+ unfold mspc_ball.
+ unfold MetricSpaceBall_instance_2.
+ intros.
+ split.
+ repeat intro.
+ destruct H3.
+ rewrite H4.
+ apply (mspc_ball_zero B)...
+ split.
+ simpl. auto with *.
+ intros.
+ apply (mspc_ball_zero B)...
+ apply H3.
+ reflexivity.
+ split. simpl. auto.
+ intros.
+ apply (mspc_refl B e)...
+ split.
+ apply H3.
+ intros.
+ apply (mspc_sym B).
+ apply H3.
+ split.
+ apply Qinf.le_0_plus_compat.
+ apply H3.
+ apply H4.
+ intros.
+ apply (mspc_triangle B) with (b a0).
+ apply H3.
+ apply H4.
+ split.
+ destruct e. 2: simpl; auto.
+ unfold mspc_ball in H3.
+ unfold MetricSpaceBall_instance_2 in H3.
+ destruct (Qdec_sign q) as [[|]|].
+ exfalso.
+ assert (0 < (1#2) * -q)%Q.
+ apply Qmult_lt_0_compat...
+ apply Qopp_Qlt_0_l...
+ destruct (H3 (exist _ _ H4)).
+ simpl in H5.
+ clear H4 H6.
+ ring_simplify in H5.
+ apply (Qlt_not_le q 0). auto.
+ setoid_replace q with ((1 # 2) * q + (1 # 2) * q)%Q by (simpl; ring).
+ apply Qplus_nonneg...
+ simpl. auto with *.
+ rewrite q0.
+ simpl.
+ apply Qle_refl.
+ intros.
+ apply (mspc_closed B).
+ intros.
+ apply H3.
+ Qed.*) (* Todo: This is awful. Clean it up once these blasted evar anomalies are under control. *)
+ Admitted.
+
+End uc_functions.
+
+(** If source and target are /already/ bundled, then we don't need to rebundle them when bundling
+ a uniformly continuous function: *)
+
+Program Definition wrap_uc_fun' {X Y: MetricSpace} (f: X → Y)
+ `{!UniformlyContinuous_mu f}
+ `{@UniformlyContinuous X _ _ Y _ _ f _}:
+ UniformlyContinuousFunction X Y :=
+ @Build_UniformlyContinuousFunction X Y f (uc_mu f) _.
+
+Next Obligation. Proof with auto.
+ intros ????.
+ assert (mspc_ball (uc_mu f e) a b).
+ revert H0.
+ set (uc_mu f e).
+ intros.
+ destruct q...
+ apply <- (ball_genball (@ball X) q)...
+ pose proof (uniformlyContinuous f e a b H1).
+ apply ball_genball...
+ apply _.
+Qed.
+
+(** Conversely, if we have a UniformlyContinuousFunction (between bundled metric spaces) and project
+ the real function out of it, instances of the classes can easily be derived. *)
+
+Open Scope uc_scope.
+
+Section unwrap_uc.
+
+ Context {X Y: MetricSpace} (f: X --> Y).
+
+ Global Instance unwrap_mu: UniformlyContinuous_mu f := { uc_mu := mu f }.
+
+ Global Instance unwrap_uc_fun: UniformlyContinuous f.
+ Proof with auto.
+ constructor; try apply _.
+ unfold uc_mu, unwrap_mu.
+ destruct f.
+ simpl. intros.
+ unfold mspc_ball.
+ unfold MetricSpaceBall_instance_0.
+ apply ball_genball.
+ apply _.
+ apply uc_prf.
+ set (mu e) in *.
+ destruct q...
+ simpl.
+ apply ball_genball...
+ apply _.
+ Qed.
+
+End unwrap_uc.
+
+(** Extentionally equal functions are obviously equally uniformly continuous (with extensionally equal mu's): *)
+
+Lemma UniformlyContinuous_proper `{MetricSpaceClass X} `{MetricSpaceClass Y} (f g: X → Y)
+ `{!UniformlyContinuous_mu f} `{!UniformlyContinuous_mu g}:
+ (∀ x, f x = g x) → (∀ e, uc_mu f e ≡ uc_mu g e) →
+ UniformlyContinuous f → UniformlyContinuous g.
+ (* Todo: Stronger versions of this statement can be proved with a little effort. *)
+Proof.
+ constructor; try apply _.
+ intros ????.
+ pose proof (mspc_ball_proper Y).
+ pose proof (mspc_setoid X).
+ pose proof (mspc_setoid Y).
+ rewrite <- (H3 a).
+ rewrite <- (H3 b).
+ apply (uniformlyContinuous f).
+ rewrite H4. auto.
+Qed.
+
+
+(** We now show that a couple of basic functions are continuous: *)
+
+(** The identity function is uniformly continuous: *)
+
+Section id_uc. Context `{MetricSpaceClass X}.
+ Global Instance: UniformlyContinuous_mu (@Datatypes.id X) := { uc_mu := Qpos2QposInf }.
+ Global Instance: UniformlyContinuous (@Datatypes.id X).
+ Proof. constructor; try apply _. intros. assumption. Qed.
+End id_uc.
+ (* Note: We don't need a separate instance for the [id] constant. If such an instance
+ is needed, we can use [Hint Unfold id: typeclass_instances.] *)
+
+(** Constant functions are uniformly continuous: *)
+
+Section const_uc. Context `{MetricSpaceClass X} `{MetricSpaceClass Y} (y: Y).
+ Global Instance: UniformlyContinuous_mu (@Basics.const Y X y) := { uc_mu := λ _, QposInfinity }.
+ Global Instance: UniformlyContinuous (@Basics.const Y X y).
+ Proof. repeat intro. constructor; try apply _. intros. apply (mspc_refl Y e). simpl. auto. Qed.
+End const_uc.
+
+(** Mapping both of a pair's components by uniformly continuous functions
+ is uniformly continuous: *)
+
+Section exist_uc.
+ Context `{MetricSpaceComponents X} `{MetricSpaceComponents Y} (P: Y → Prop)
+ (f: X → Y) (g: ∀ x, P (f x)) `{!UniformlyContinuous_mu f} `{!UniformlyContinuous f}.
+
+ Global Instance exist_mu: UniformlyContinuous_mu (λ x: X, exist P (f x) (g x)) := { uc_mu := uc_mu f }.
+
+ Global Instance exist_uc: UniformlyContinuous (λ x: X, exist P (f x) (g x)).
+ Proof with auto.
+ constructor.
+ apply (uc_from f).
+ pose proof (uc_to f).
+ apply _.
+ intros.
+ apply (uniformlyContinuous f).
+ assumption.
+ Qed.
+End exist_uc.
+
+Section map_pair_uc.
+ Context `{MetricSpaceComponents X} `{MetricSpaceComponents Y}
+ `{MetricSpaceComponents A} `{MetricSpaceComponents B}
+ (f: X → Y) `{!UniformlyContinuous_mu f} `{!UniformlyContinuous f}
+ (g: A → B) `{!UniformlyContinuous_mu g} `{!UniformlyContinuous g}.
+
+ Global Instance: UniformlyContinuous_mu (map_pair f g) :=
+ { uc_mu := λ x, QposInf_min (uc_mu f x) (uc_mu g x) }.
+
+ Let hint := uc_from g.
+ Let hint' := uc_to g.
+ Let hint'' := uc_from f.
+ Let hint''' := uc_to f.
+
+ Global Instance: UniformlyContinuous (map_pair f g).
+ Proof with auto.
+ constructor; try apply _. intros.
+ (*pose proof (together_uc (wrap_uc_fun f) (wrap_uc_fun g) e a b) as P.
+ apply P. simpl in *.
+ destruct (QposInf_min)...
+ simpl...
+ Qed.*)
+ Admitted.
+End map_pair_uc.
+
+(** The diagonal function is uniformly continuous: *)
+
+Section diagonal_uc.
+ Context `{MetricSpaceClass X}.
+
+ Global Instance: UniformlyContinuous_mu (@diagonal X) := { uc_mu := Qpos2QposInf }.
+
+ Global Instance: UniformlyContinuous (@diagonal X).
+ Proof. constructor; try apply _. intros ??? E. split; auto. Qed.
+End diagonal_uc.
+
+(** fst/snd/pair are uniformly continuous: *)
+
+Section pairops_uc.
+ Context `{MetricSpaceClass A} `{MetricSpaceClass B}.
+
+ Global Instance: UniformlyContinuous_mu (@fst A B) := { uc_mu := Qpos2QposInf }.
+ Global Instance: UniformlyContinuous_mu (@snd A B) := { uc_mu := Qpos2QposInf }.
+ Global Instance: UniformlyContinuous_mu (uncurry (@pair A B)) := { uc_mu := Qpos2QposInf }.
+ Global Instance: ∀ a, UniformlyContinuous_mu (@pair A B a) := { uc_mu := Qpos2QposInf }.
+
+ Global Instance: UniformlyContinuous (@fst A B).
+ Proof. constructor; try apply _. intros ??? P. apply P. Qed.
+ Global Instance: UniformlyContinuous (@snd A B).
+ Proof. constructor; try apply _. intros ??? P. apply P. Qed.
+ Global Instance: UniformlyContinuous (uncurry (@pair A B)).
+ Proof. constructor; try apply _. intros ??? P. apply P. Qed.
+ Global Instance: ∀ a, UniformlyContinuous (@pair A B a).
+ Proof. constructor; try apply _. intros ??? P. split. apply (mspc_refl A). simpl. auto. apply P. Qed.
+End pairops_uc.
+
+Section compose_uc.
+ Context `{MetricSpaceComponents X} `{MetricSpaceComponents Y} `{MetricSpaceComponents Z'}
+ (f: Y → Z') `{!UniformlyContinuous_mu f} `{!UniformlyContinuous f}
+ (g: X → Y) `{!UniformlyContinuous_mu g} `{!UniformlyContinuous g}.
+
+ Global Instance compose_mu: UniformlyContinuous_mu (f ∘ g)%prg :=
+ { uc_mu := λ e, QposInf_bind (uc_mu g) (uc_mu f e) }.
+
+ Let hint := uc_from g.
+ Let hint' := uc_to g.
+ Let hint'' := uc_to f.
+
+ Global Instance compose_uc: UniformlyContinuous (f ∘ g)%prg.
+ Proof with auto.
+ constructor; try apply _.
+ (*intros ??? P.
+ apply (uniformlyContinuous f).
+ revert P. simpl.
+ generalize (uc_mu f e).
+ destruct q; intros; simpl.
+ apply (uniformlyContinuous g)...
+ apply (mspc_ball_inf Y).
+ Qed.*)
+ Admitted.
+End compose_uc.
+
+Section curried_uc.
+ Context `{MetricSpaceClass X} `{MetricSpaceClass Y} `{MetricSpaceClass Z'} (f: X → Y → Z')
+ `{fmu1: ∀ x: X, UniformlyContinuous_mu (f x)}
+ `{fuc1: ∀ x: X, UniformlyContinuous (f x)}
+ `{fmu: !UniformlyContinuous_mu (λ p, f (fst p) (snd p))}
+ `{fuc: !UniformlyContinuous (λ p, f (fst p) (snd p))}.
+
+ Local Notation F := (λ x: X, {| ucFun_itself := λ y: Y, f x y; ucFun_mu := fmu1 x; ucFun_uc := fuc1 x |}).
+
+ Global Instance curried_mu: UniformlyContinuous_mu F := { uc_mu := uc_mu (λ p, f (fst p) (snd p)) }.
+
+ Global Instance curried_uc: UniformlyContinuous F.
+ Proof with simpl; auto.
+ constructor; try apply _.
+ split...
+ simpl in *.
+ destruct fuc.
+ intros.
+ apply (@uniformlyContinuous0 e (a, a0) (b, a0)).
+ simpl.
+ set (q := uc_mu (λ p, f (fst p) (snd p)) e) in *.
+ destruct q...
+ split...
+ apply (mspc_refl Y)...
+ apply (mspc_ball_inf _).
+ Qed.
+End curried_uc.
+
+Class HasLambda `{X: Type} (x: X): Prop.
+
+Instance lambda_has_lambda `(f: A → B): HasLambda (λ x, f x).
+Instance application_has_lambda_left: ∀ `(f: A → B) (x: A), HasLambda f → HasLambda (f x).
+Instance application_has_lambda_right: ∀ `(f: A → B) (x: A), HasLambda x → HasLambda (f x).
+
+
+Section lambda_uc.
+
+ Context `{MetricSpaceComponents A} `{MetricSpaceComponents B} (f: A → B).
+
+ Global Instance lambda_mu `{!HasLambda f} {free_f: A → B} `{!PointFree f free_f} `{!UniformlyContinuous_mu free_f}: UniformlyContinuous_mu f.
+ (* Note: The HasLambda and PointFree constraints cannot be added to the Context declaration
+ above because the definition of this mu needs to depend on them /despite/ not using them.
+ Without the dependency, lambda_mu would be allowed to find a random free_f of the right signature
+ for which it happens to have a mu already, and use that one.
+ We do not factor out the mu constraint either, because for (dubious) efficiency reasons it is critical
+ that it appear /after/ the PointFree constraint.*)
+ Proof. constructor. apply UniformlyContinuous_mu0. Defined.
+
+ Context `{!HasLambda f} {free_f: A → B} `{!PointFree f free_f} `{!UniformlyContinuous_mu free_f} `{!UniformlyContinuous free_f}.
+
+ Global Instance lambda_uc: UniformlyContinuous f.
+ Proof.
+ destruct UniformlyContinuous0.
+ constructor.
+ apply _.
+ apply _.
+ destruct uc_from0.
+ destruct uc_to0.
+ intros.
+ unfold PointFree in PointFree0.
+ rewrite PointFree0.
+ apply uniformlyContinuous0.
+ unfold uc_mu in H5.
+ simpl in H5.
+ assumption.
+ Qed. (* Todo: Clean up. *)
+
+End lambda_uc.
+
+Module test.
+Section test.
+
+ Context
+ `{MetricSpaceClass A}
+ (f: A → A → A)
+ `{!UniformlyContinuous_mu (uncurry f)} `{!UniformlyContinuous (uncurry f)} `{!Proper (=) f}.
+
+ Definition t0: UniformlyContinuous_mu (λ (x: A), f (f x x) (f x (f x x))) := _.
+
+End test.
+End test.
diff --git a/metric2/Ranges.v b/metric2/Ranges.v
new file mode 100644
index 00000000..865cdcb9
--- /dev/null
+++ b/metric2/Ranges.v
@@ -0,0 +1,19 @@
+
+Require Import Program canonical_names util.Container QArith QMinMax CRlattice.
+
+Definition Range (T: Type) := prod T T.
+
+Instance in_QRange: Container Q (Range Q)
+ := λ r x, (Qmin (fst r) (snd r) <= x <= Qmax (fst r) (snd r))%Q.
+
+Instance in_CRRange: Container CR (Range CR)
+ := λ r x, (CRmin (fst r) (snd r) <= x ∧ x <= CRmax (fst r) (snd r))%CR.
+
+Instance in_sig_Range `{Container A (Range A)} (P: A → Prop): Container (sig P) (Range (sig P))
+ := λ r x, In (` (fst r), ` (snd r)) (` x).
+
+(*Lemma alt_in_QRange (q: Q) (r: Range Q): q ∈ r <->
+ (∃ e, 0 <= e <= 1 ∧ fst r + e * (snd r - fst r) == q)%Q.
+Proof with auto.
+Admitted.*)
+ (* also: ∃ e, 0 <= e <= 1 ∧ q == fst r * e + snd r * (1 - e) *)
From 7bbcb66ff20992a9f079fd85e27ded79a2e14bbf Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Mon, 1 Sep 2014 22:13:24 +0200
Subject: [PATCH 103/110] updating
---
{broken => algebra}/CPoly_Newton.v | 236 +++++++++++++++++++++++++----
1 file changed, 208 insertions(+), 28 deletions(-)
rename {broken => algebra}/CPoly_Newton.v (72%)
diff --git a/broken/CPoly_Newton.v b/algebra/CPoly_Newton.v
similarity index 72%
rename from broken/CPoly_Newton.v
rename to algebra/CPoly_Newton.v
index 88a5d978..b8a4ffa8 100644
--- a/broken/CPoly_Newton.v
+++ b/algebra/CPoly_Newton.v
@@ -4,29 +4,13 @@ Require Import
CSetoids CPoly_ApZero CRings CPoly_Degree
CRArith Qmetric Qring CReals Ranges
stdlib_omissions.Pair stdlib_omissions.Q
- list_separates SetoidPermutation
- util.Container NewAbstractIntegration.
-
+ list_separates SetoidPermutation.
Require ne_list.
Import ne_list.notations.
-Fixpoint iterate {T: nat → Type} (f: ∀ {n}, T (S n) → T n) {n}: T n → T O :=
- match n return T n → T O with
- | O => Datatypes.id
- | S n' => (iterate f ∘ f n')%prg
- end.
- (* Todo: Move into some util module. *)
+Set Automatic Introduction.
Coercion Vector.to_list: Vector.t >-> list.
-Definition Q01 := sig (λ x: Q, 0 <= x <= 1).
-Implicit Arguments proj1_sig [[A] [P]].
-Definition B01: Ball Q Qpos := (1#2, (1#2)%Qpos).
-Definition D01 := sig ((∈ B01)).
-Program Definition D01zero: D01 := 0.
-Next Obligation. admit. Qed.
-Instance: Canonical (QnonNeg.T → Qinf).
-Admitted.
- (* Todo: All this belongs elsewhere. *)
Instance: UniformlyContinuous_mu (util.uncurry Qplus).
Admitted.
@@ -85,7 +69,7 @@ Section continuous_vector_operations.
constructor; apply A.
Qed.
-End continuous_vector_operations. (* Todo: Move elsewhere. *)
+End continuous_vector_operations.
Section contents.
@@ -282,7 +266,7 @@ Section contents.
intro.
unfold Basics.compose.
rewrite <- CRminus_Qminus.
- change ((' (- fst x1)%Q + ' x * (1 + 'x * 0)) [=] (' x - ' fst x1)).
+ change ((' (- fst x1)%Q + ' x * (1 + ' x * 0)) [=] (' x - ' fst x1)).
ring.
Qed.
@@ -300,12 +284,12 @@ Section contents.
Proof. reflexivity. Qed.
Lemma an_applied_0 (t: QPoint) (x: Q) (xs: ne_list QPoint):
- List.In x (map fst xs) -> an_applied x (t ::: xs) [=] 0.
+ In x (map fst xs) -> an_applied x (t ::: xs) [=] 0.
Proof with auto.
intros. unfold an_applied.
simpl @tl.
rewrite (cr_Product_0 (x - x))%Q.
- change (divdiff (t ::: xs) [*] [0] [=] [0]).
+ change (divdiff (t ::: xs) [*] 0 [=] 0).
apply cring_mult_zero.
change (x - x == 0)%Q. ring.
unfold Basics.compose.
@@ -325,7 +309,7 @@ Section contents.
an_applied (fst x) (x ::: y ::: xs)+an_applied (fst x) (y ::: xs) + applied xs (fst x))%CR.
ring.
change ((divdiff_l x xs - divdiff_l y xs) * ' (/ (fst x - fst y))[*]
- ' (Qminus (fst x) (fst y) * Π (map (Qminus (fst x) ∘ fst)%prg xs))%Q +
+ ' (Qminus (fst x) (fst y) * Π (map (Qminus (fst x) ∘ fst)%prg xs))%Q+
divdiff_l y xs[*]' Π (map (Qminus (fst x) ∘ fst)%prg xs)[=]
divdiff_l x xs[*]' Π (map (Qminus (fst x) ∘ fst)%prg xs)).
generalize (Π (map (Qminus (fst x) ∘ fst)%prg xs)).
@@ -446,15 +430,15 @@ Section contents.
rewrite nth_coeff_plus.
rewrite (degree l (length l)).
2: destruct l; simpl; auto.
- change (nth_coeff (length l) (an (p ::: l)) + 0==divdiff (p ::: l)). (* to change [+] into + *)
+ change (nth_coeff (length l) (an (p ::: l))+0==divdiff (p ::: l)). (* to change [+] into + *)
ring_simplify.
unfold an.
rewrite nth_coeff_c_mult_p.
simpl tl.
- set (f := fun x: Q and CR => ' (- fst x)%Q [+X*][1]).
+ set (f := fun x: Q and CR => ' (- fst x)%Q[+X*] [1]).
replace (length l) with (length (map f l) * 1)%nat.
rewrite lead_coeff_product_1.
- change (divdiff (p ::: l) * 1 [=] divdiff (p ::: l))... (* to change [*] into * *)
+ change (divdiff (p ::: l)*1[=]divdiff (p ::: l))... (* to change [*] into * *)
intros q. rewrite in_map_iff. intros [x [[] B]].
split. reflexivity.
apply degree_le_cpoly_linear_inv.
@@ -490,7 +474,10 @@ Section contents.
rewrite E.
apply interpolates_economically.
unfold QNoDup.
- rewrite <- E...
+(* assert (ne_list.Permutation (map fst x) (map fst y)).
+ assert (QNoDup (map fst y)).
+ rewrite <- E...*)
+admit.
Qed.
Lemma divdiff_Permutation (x y: ne_list QPoint): QNoDup (map fst x) →
@@ -506,6 +493,199 @@ Section contents.
rewrite (N_Permutation x y)...
reflexivity.
unfold QNoDup.
- rewrite <- P...
+ admit. (* too slow
+ rewrite <- P...*)
Qed.
+
+Fixpoint ne_list_zip {X Y} (xs: ne_list X) (ys: ne_list Y): ne_list (X * Y) :=
+ match xs, ys with
+ | ne_list.cons x xs', ne_list.cons y ys' => ne_list.cons (x, y) (ne_list_zip xs' ys')
+ | _, _ => ne_list.one (ne_list.head xs, ne_list.head ys)
+ end.
+(*
+Fixpoint iterate {T: nat → Type} (f: ∀ {n}, T (S n) → T n) {n}: T n → T O :=
+ match n return T n → T O with
+ | O => Datatypes.id
+ | S n' => (iterate f ∘ f n')%prg
+ end.
+*)
+(*
+ Section iterate.
+ Context (T: nat → Type) (f: ∀ {n}, T n → T (S n)).
+
+ Fixpoint iterate (n: nat) {m: nat} (x: T m): T (n + m) :=
+ match n with
+ | O => x
+ | S n' => f _ (iterate n' x)
+ end.
+
+ Definition iterate_comm (n: nat) {m: nat} (x: T m): T (m + n).
+ rewrite plus_comm.
+ exact (iterate n x).
+ Defined.
+
+ Context
+ `{∀ n, canonical_names.Equiv (T n)}
+ `{∀ n, MetricSpaceBall (T n)}
+ `{∀ n, MetricSpaceClass (T n)}
+ `{∀ n, UniformlyContinuous_mu (f n)}
+ `{∀ n, UniformlyContinuous (f n)}.
+
+ Global Instance iterate_mu {n m}: UniformlyContinuous_mu (@iterate n m).
+ Admitted.
+ Global Instance iterate_comm_mu {n m}: UniformlyContinuous_mu (@iterate_comm n m).
+ Admitted.
+
+ Global Instance iterate_uc {n m}: UniformlyContinuous (@iterate n m).
+ Admitted.
+ Global Instance iterate_comm__uc {n m}: UniformlyContinuous (@iterate_comm n m).
+ Admitted.
+
+ End iterate.
+*)
+
+
+Definition Q01 := sig (λ x: Q, 0 <= x <= 1).
+Definition Range (T: Type) := prod T T.
+Class Container (Elem C: Type) := In: C → Elem → Prop.
+Hint Unfold In.
+Notation "x ∈ y" := (In y x) (at level 40).
+Notation "(∈ y )" := (In y) (at level 40).
+Notation "x ∉ y" := (In y x → False) (at level 40).
+Instance in_QRange: Container Q (Range Q) := λ r x, fst r <= x <= snd r.
+Implicit Arguments proj1_sig [[A] [P]].
+Program Instance in_sig_QRange (P: Q → Prop): Container (sig P) (Range (sig P)) := λ r x, fst r <= x <= snd r.
+Definition B01: Ball Q Qpos := (1#2, (1#2)%Qpos).
+(*Definition D01 := sig (contains B01).
+
+ Program Definition D01zero: D01 := 0.
+ Next Obligation.
+ red.
+ simpl.
+ red.
+ red.
+ simpl.
+ red.
+ simpl.
+ red.
+ simpl.
+ split.
+ admit.
+ admit.
+ Qed.
+*)
+(* Instance: Canonical (QnonNeg.T → Qinf.Qinf).
+ Admitted.
+*)
+ Section divdiff_as_repeated_integral.
+
+ Context
+ (n: nat) (points: Vector.t Q (S n))
+ (lo hi: Q).
+
+ Definition lohi (q: Q): Prop := lo <= q <= hi.
+ Definition Qbp: Type := sig lohi.
+
+(* Context
+ (points_lohi: Vector.Forall lohi points)
+ (upper: CR)
+ (nth_deriv: Q → CR (*sig (λ x: CR, x <= upper)*))
+ `{!UniformlyContinuous_mu nth_deriv}
+ `{!UniformlyContinuous nth_deriv}
+ (* Todo: This should be replaced with some "n times differentiable" requirement on a subject function. *)
+ (integrate: Range Q01 * UCFunction Q01 CR → CR)
+ `{!UniformlyContinuous_mu integrate}
+ `{!UniformlyContinuous integrate}.
+ (* Todo: The integration function should not be a parameter. We should just use SimpleIntegration's implementation. *)
+*)
+(*
+Require Import CRabs.
+Import QnonNeg.notations.
+Definition ZeroRangeToBall (q: QnonNeg.T): Ball Q QnonNeg.T := (0, ((1#2) * q)%Qnn).
+ Variable integrate_on_01:
+ ∀ (u: QnonNeg.T) (f: sig (contains (ZeroRangeToBall u)) → CR) c,
+ (∀ x, CRabs (f x) <= c) →
+ CRabs (integrate _ f) <= c.
+*)
+ Opaque Qmult Qplus Qminus.
+ (* Without these, instance resolution gets a little too enthusiastic and breaks these operations open when
+ looking for PointFree instances below. It's actually kinda neat that it can put these in PointFree form though. *)
+
+
+ Notation SomeWeights n := ((*sig (λ ts:*) Vector.t Q01 n (*, cm_Sum (map proj1_sig ts) <= 1)%Q*)).
+ Notation Weights := ((*sig (λ ts:*) Vector.t Q01 (S n) (*, cm_Sum (map proj1_sig ts) == 1)%Q*)).
+
+ (** apply_weights: *)
+
+ Program Definition apply_weights (w: Weights): Qbp :=
+ cm_Sum (map (λ p, Qmult (fst p) (` (snd p))) (zip points (Vector.to_list w))).
+
+ Next Obligation.
+ Admitted.
+
+ Instance apply_weights_mu: UniformlyContinuous_mu apply_weights.
+ Admitted.
+
+(* Instance apply_weights_uc: UniformlyContinuous apply_weights.
+ Admitted.*)
+
+ Obligation Tactic := idtac.
+
+ (** "inner", the function of n weights: *)
+(*
+ Program Definition inner: SomeWeights n → CR
+ := λ ts, nth_deriv (apply_weights
+ (Vector.cons _ (1 - cm_Sum (map proj1_sig (Vector.to_list ts)): Q01) _ ts))%Q.
+
+ Next Obligation.
+ intros ts (*[ts ?]*).
+ simpl @proj1_sig.
+ split.
+ admit. (* easy *)
+ admit. (* easy *)
+ Qed.
+
+ Instance inner_mu: UniformlyContinuous_mu inner.
+ Admitted.
+
+ Instance inner_uc: UniformlyContinuous inner.
+ Admitted.
+*)
+ (* Next up is "reduce", which *)
+(*
+ Definition G (n: nat): Type := UCFunction (Vector.t Q01 n) CR.
+
+ Section reduce.
+ Variables (m: nat) (X: G (S m)).
+
+ Definition integrand (ts: SomeWeights m) (t: Q01): CR := X (uncurry_Vector_cons _ (t, ts)).
+
+ Program Definition reduce_raw: SomeWeights m → CR
+ := λ ts, integrate ((0, 1 - cm_Sum (map proj1_sig (Vector.to_list ts)))%Q, ucFunction (integrand ts)).
+
+ Next Obligation. split. reflexivity. auto. Qed.
+
+ Next Obligation.
+ intros ts (*[ts ?]*).
+ simpl.
+ split. admit. (* easy *)
+ admit. (* easy *)
+ Qed.
+
+ Axiom reduce_mu: UniformlyContinuous_mu reduce_raw.
+ Existing Instance reduce_mu.
+ Axiom reduce_uc: UniformlyContinuous reduce_raw.
+ Existing Instance reduce_uc.
+
+ Definition reduce: G m := ucFunction reduce_raw.
+
+ End reduce.
+
+ (*Program*) Definition alt_divdiff: CR (*sig (λ r, r <= upper)*)
+ := iterate reduce (ucFunction inner) (Vector.nil Q01).
+
+ Next Obligation. simpl. auto with arith. Qed.
+*)
+ End divdiff_as_repeated_integral.
+
End contents.
From 86854d9f196e99a378bb86fb791a21e726b42156 Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Tue, 2 Sep 2014 17:21:06 +0200
Subject: [PATCH 104/110] Removing some old tactics.
---
transc/Pi.v | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/transc/Pi.v b/transc/Pi.v
index e6799b99..b0f068e0 100644
--- a/transc/Pi.v
+++ b/transc/Pi.v
@@ -976,7 +976,7 @@ Proof.
clear H.
destruct Hx as [[] [[] Hx]].
apply (Hx I).
- csetoid_rewrite (Tan_Sin_over_Cos y Hy H0).
+ rewrite (Tan_Sin_over_Cos y Hy H0).
unfold y.
assert (H2:([--](Sin x))[#][0]).
csetoid_rewrite_rev (Cos_plus_HalfPi x).
@@ -988,7 +988,7 @@ Proof.
clear H0.
rstepl (((Cos x[/][--](Sin x)[//]H2)[*](Tan x Hx))[/](Tan x Hx)[//]H).
apply div_wd;[|apply eq_reflexive].
- csetoid_rewrite (Tan_Sin_over_Cos x Hx H1).
+ rewrite (Tan_Sin_over_Cos x Hx H1).
rational.
Qed.
From d6b1a6df353e6053d5237e4e51a7bc241b73eb41 Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Tue, 2 Sep 2014 17:36:47 +0200
Subject: [PATCH 105/110] Removing dependency
---
tactics/Qauto.v | 1 -
1 file changed, 1 deletion(-)
diff --git a/tactics/Qauto.v b/tactics/Qauto.v
index 6712c997..0889ff97 100644
--- a/tactics/Qauto.v
+++ b/tactics/Qauto.v
@@ -23,7 +23,6 @@ Require Export Qordfield.
Require Import COrdFields2.
Require Import Qpower.
Require Import Qabs.
-Require Import CornTac.
Ltac Qauto_pos :=
repeat (first [ assumption
From c8c19217d205caafb11ce83b5822316d3241059e Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Tue, 2 Sep 2014 17:53:11 +0200
Subject: [PATCH 106/110] Removing admit.
---
reals/faster/ARAlternatingSum.v | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/reals/faster/ARAlternatingSum.v b/reals/faster/ARAlternatingSum.v
index b4066fda..a33c87df 100644
--- a/reals/faster/ARAlternatingSum.v
+++ b/reals/faster/ARAlternatingSum.v
@@ -233,12 +233,13 @@ Proof.
transitivity (4 + takeUntil_length _ (LazyExists_Str_nth_tl (Limit_near sQ 0 ε) (dnn_in_Qball_0_EventuallyForall sQ ε) 4)).
apply takeUntil_length_Str_nth_tl.
unfold ARInfAltSum_length.
- (* replace (Init.Nat.add (S (S (S (S O))))) with (plus (plus one (plus one (plus one one)))).
+ (* Regression, the following line was not necessary before. *)
+ change (Init.Nat.add (S (S (S (S O))))) with (plus (plus one (plus one (plus one (S 0))))).
apply (order_preserving (4 +)).
apply takeUntil_length_ForAllIf.
apply ARInfAltSum_stream_preserves_ball.
now apply DivisionStream_Str_nth_tl.
- now apply _.*) admit.
+ now apply _.
Qed.
Lemma ARInfAltSum_length_pos (k : Z) :
From 05d24dffb97b17669909e4d47d63db1f0e085bec Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Tue, 2 Sep 2014 19:56:47 +0200
Subject: [PATCH 107/110] Cleaning up
---
ode/AbstractIntegration.v | 17 +++++---
transc/Pi.v | 82 +++++++++++++++++++--------------------
2 files changed, 51 insertions(+), 48 deletions(-)
diff --git a/ode/AbstractIntegration.v b/ode/AbstractIntegration.v
index f0f83ccf..5d7e055e 100644
--- a/ode/AbstractIntegration.v
+++ b/ode/AbstractIntegration.v
@@ -957,13 +957,17 @@ Qed.
Lemma int_abs_bound (a b M : Q) :
(forall x : Q, x ∈ (a, b) -> abs (f x) ≤ 'M) -> abs (int a b) ≤ '(abs (b - a) * M).
Proof.
-intros A. unfold int.
-(* Looks like a type class regression *)
- admit. (*destruct (decide (a ≤ b)) as [AB | AB];
+intros A. unfold int. admit.
+(* Looks like a type class regression, unfolded the tactic soup a bit. *)
+(* destruct (decide (a ≤ b)) as [AB | AB];
[| pose proof (orders.le_flip _ _ AB); mc_setoid_replace (b - a) with (-(a - b)) by ring;
rewrite CRabs_negate, abs.abs_negate];
-rewrite abs.abs_nonneg by (now apply rings.flip_nonneg_minus);
-apply integral_abs_bound; trivial; (* [Integrable f] is not discharged *)
+rewrite abs.abs_nonneg.
+2: apply rings.flip_nonneg_minus.
+4: try (now apply rings.flip_nonneg_minus).
+1: apply integral_abs_bound;trivial; +(* [Integrable f] is not discharged *)
+intros x A1; apply A.
+3: apply integral_abs_bound;trivial; +(* [Integrable f] is not discharged *)
intros x A1; apply A.
+ apply -> range_le; [| easy].
now mc_setoid_replace b with (a + (b - a)) by ring.
@@ -1001,7 +1005,8 @@ assert (Nf <= n)%positive by (transitivity (Pos.max Nf Ng); apply Pos.le_max_l).
assert (Ng <= n)%positive by (transitivity (Pos.max Nf Ng); [apply Pos.le_max_r | apply Pos.le_max_l]).
assert (Ns <= n)%positive by apply Pos.le_max_r.
apply (mspc_triangle' (e / 2) (e / 2) (riemann_sum (f + g) a w n)).
- (* regression connected to numbers ? [field; discriminate | |].*) admit.
+ change (Qeq ((e / (2#1)) + (e / (2#1))) e)%Q.
+ (* regression connected in field numbers ? [field; discriminate | |].*) admit.
* apply mspc_symm, S; assumption.
* rewrite riemann_sum_plus.
mc_setoid_replace (e / 2) with (e / 4 + e / 4) by (field; split; discriminate).
diff --git a/transc/Pi.v b/transc/Pi.v
index b0f068e0..f6a5e042 100644
--- a/transc/Pi.v
+++ b/transc/Pi.v
@@ -102,7 +102,7 @@ Proof.
2: unfold cg_minus at 1 in |- *; apply bin_op_wd_unfolded.
2: algebra.
2: rstepr ( [--] ( {--}Cosine t Ht[-] {--}Cosine x I)).
- 2: apply un_op_wd_unfolded; eapply eq_transitive_unfolded.
+ 2: apply un_op_wd_unfolded; eapply eq_transitive.
2: apply B'.
2: algebra.
clear B' B H3.
@@ -182,13 +182,13 @@ Proof.
apply leEq_transitive with x; auto.
eapply leEq_wdl.
apply H3.
- eapply eq_transitive_unfolded.
+ eapply eq_transitive.
apply Min_comm.
apply leEq_imp_Min_is_lft; auto.
apply leEq_transitive with y; auto.
eapply leEq_wdr.
apply H4.
- eapply eq_transitive_unfolded.
+ eapply eq_transitive.
apply Max_comm.
apply leEq_imp_Max_is_rht; auto.
Qed.
@@ -385,14 +385,14 @@ Proof.
exists (S (S N)); intros.
apply AbsIR_imp_AbsSmall.
apply leEq_wdl with (pi_seq m[-]pi_seq (S (S N))).
- 2: apply eq_symmetric_unfolded; apply AbsIR_eq_x.
+ 2: apply eq_symmetric; apply AbsIR_eq_x.
2: apply shift_leEq_minus; astepl (pi_seq (S (S N))).
2: apply local_mon_imp_mon'.
2: intro; apply pi_seq_incr; auto.
2: auto.
cut (m = S (pred m)); [ intro | apply S_pred with (S N); auto ].
apply leEq_wdl with (Sum (S (S N)) (pred m) (fun i : nat => pi_seq (S i) [-]pi_seq i)).
- 2: eapply eq_transitive_unfolded.
+ 2: eapply eq_transitive.
2: apply Mengolli_Sum_gen with (f := pi_seq).
2: algebra.
2: auto with arith.
@@ -405,7 +405,7 @@ Proof.
intros; apply pi_seq_bnd''.
apply le_trans with (S (S N)); auto with arith.
eapply leEq_wdl.
- 2: apply eq_symmetric_unfolded; apply Sum_comm_scal with (s := fun i : nat => z[^]pred i).
+ 2: apply eq_symmetric; apply Sum_comm_scal with (s := fun i : nat => z[^]pred i).
rstepl (Sum (S (S N)) (pred m) (fun i : nat => z[^]pred i) [*] (pi_seq 2[-]pi_seq 1)).
apply shift_mult_leEq with H1.
auto.
@@ -415,7 +415,7 @@ Proof.
2: apply Sum_shift; algebra.
cut (z[-][1] [#] [0]). intro H4.
eapply leEq_wdl.
- 2: apply eq_symmetric_unfolded; apply Sum_c_exp with (H := H4).
+ 2: apply eq_symmetric; apply Sum_c_exp with (H := H4).
rstepl ((z[^]S (pred (pred m)) [/] _[//]H4) [-] (z[^]S N[/] _[//]H4)).
apply leEq_transitive with ( [--] (z[^]S N) [/] _[//]H4).
apply shift_minus_leEq; rstepr ZeroR; apply less_leEq.
@@ -490,8 +490,8 @@ Proof.
Qed.
Lemma Cos_HalfPi : Cos (Pi [/]TwoNZ) [=] [0].
- apply eq_transitive_unfolded with (Cos (Lim (Build_CauchySeq _ _ pi_seq_Cauchy))).
Proof.
+ transitivity (Cos (Lim (Build_CauchySeq _ _ pi_seq_Cauchy))).
apply Cos_wd; unfold Pi in |- *; rational.
astepr (Lim (Build_CauchySeq _ _ pi_seq_Cauchy) [-] Lim (Build_CauchySeq _ _ pi_seq_Cauchy)).
assert (H : Cauchy_prop (fun n : nat => pi_seq (S n))).
@@ -500,7 +500,7 @@ Proof.
simpl in |- *; auto.
algebra.
apply pi_seq_Cauchy.
- apply eq_transitive_unfolded with
+ transitivity
(Lim (Build_CauchySeq _ _ H) [-]Lim (Build_CauchySeq _ _ pi_seq_Cauchy)).
2: apply cg_minus_wd; algebra.
2: apply Lim_subseq_eq_Lim_seq with S; auto with arith.
@@ -509,13 +509,13 @@ Proof.
2: algebra.
2: left; intros; simpl in |- *.
2: apply local_mon_imp_mon'; auto; apply pi_seq_incr.
- eapply eq_transitive_unfolded.
+ eapply eq_transitive.
2: apply Lim_minus.
assert (H0 : Cauchy_prop (fun n : nat => Cosine (pi_seq n) (cos_domain _))).
apply Cauchy_prop_wd with (fun n : nat => pi_seq (S n) [-]pi_seq n).
2: intros; simpl in |- *; rational.
exact (Cauchy_minus (Build_CauchySeq _ _ H) (Build_CauchySeq _ _ pi_seq_Cauchy)).
- apply eq_transitive_unfolded with (Lim (Build_CauchySeq _ _ H0)).
+ transitivity (Lim (Build_CauchySeq _ _ H0)).
2: apply Lim_wd'; intros; simpl in |- *; rational.
simpl in |- *.
apply Continuous_imp_comm_Lim with (e := OneR) (x := Build_CauchySeq _ _ pi_seq_Cauchy)
@@ -775,7 +775,7 @@ Proof.
2: algebra.
apply bin_op_wd_unfolded.
2: algebra.
- apply eq_transitive_unfolded with (Cos (Two[*]Pi [/]FourNZ)).
+ transitivity (Cos (Two[*]Pi [/]FourNZ)).
apply eq_symmetric_unfolded; apply Cos_double.
apply Cos_wd; rational.
Qed.
@@ -829,9 +829,9 @@ Proof.
apply cg_minus_wd.
apply bin_op_wd_unfolded.
apply nexp_wd.
- apply eq_symmetric_unfolded; apply Cos_QuarterPi.
+ apply eq_symmetric; apply Cos_QuarterPi.
algebra.
- apply eq_symmetric_unfolded; apply sqrt_lemma.
+ apply eq_symmetric; apply sqrt_lemma.
Qed.
Hint Resolve Sin_QuarterPi Cos_QuarterPi: algebra.
@@ -863,22 +863,22 @@ Qed.
Lemma Sin_HalfPi : Sin (Pi [/]TwoNZ) [=] [1].
Proof.
- apply eq_transitive_unfolded with (Sin (Two[*]Pi [/]FourNZ)).
+ transitivity (Sin (Two[*]Pi [/]FourNZ)).
apply Sin_wd; rational.
- eapply eq_transitive_unfolded.
+ eapply eq_transitive.
apply Sin_double.
astepr ((Two:IR) [*][1] [/]TwoNZ).
- eapply eq_transitive_unfolded.
- apply eq_symmetric_unfolded; apply mult_assoc_unfolded.
+ eapply eq_transitive.
+ apply eq_symmetric; apply mult_assoc.
apply mult_wdr.
cut (sqrt _ (less_leEq _ _ _ (pos_two IR)) [#] [0]). intro H.
- eapply eq_transitive_unfolded.
- 2: apply eq_symmetric_unfolded; apply (sqrt_lemma _ H).
+ eapply eq_transitive.
+ 2: symmetry; apply (sqrt_lemma _ H).
simpl in |- *.
- eapply eq_transitive_unfolded.
- 2: apply mult_assoc_unfolded.
- eapply eq_transitive_unfolded.
- apply eq_symmetric_unfolded; apply one_mult.
+ eapply eq_transitive.
+ 2: apply mult_assoc.
+ eapply eq_transitive.
+ apply eq_symmetric; apply one_mult.
apply mult_wdr.
apply mult_wd.
apply Sin_QuarterPi.
@@ -892,7 +892,7 @@ Hint Resolve Sin_HalfPi: algebra.
Lemma Sin_plus_HalfPi : forall x : IR, Sin (x[+]Pi [/]TwoNZ) [=] Cos x.
Proof.
intro.
- eapply eq_transitive_unfolded.
+ eapply eq_transitive.
apply Sin_plus.
astepl (Sin x[*][0][+]Cos x[*][1]).
Step_final ([0][+]Cos x).
@@ -903,7 +903,7 @@ Proof.
intros.
unfold cg_minus in |- *.
astepl (Sin ( [--]x[+]Pi [/]TwoNZ)).
- eapply eq_transitive_unfolded.
+ eapply eq_transitive.
apply Sin_plus_HalfPi.
algebra.
Qed.
@@ -911,7 +911,7 @@ Qed.
Lemma Cos_plus_HalfPi : forall x : IR, Cos (x[+]Pi [/]TwoNZ) [=] [--] (Sin x).
Proof.
intro.
- eapply eq_transitive_unfolded.
+ eapply eq_transitive.
apply Cos_plus.
astepl (Cos x[*][0][-]Sin x[*][1]).
Step_final ([0][-]Sin x).
@@ -922,14 +922,14 @@ Proof.
intros.
unfold cg_minus in |- *.
astepl (Cos ( [--]x[+]Pi [/]TwoNZ)).
- eapply eq_transitive_unfolded.
+ eapply eq_transitive.
apply Cos_plus_HalfPi.
Step_final (Sin [--][--]x).
Qed.
Lemma Sin_Pi : Sin Pi [=] [0].
Proof.
- apply eq_transitive_unfolded with (Sin (Pi [/]TwoNZ[+]Pi [/]TwoNZ)).
+ transitivity (Sin (Pi [/]TwoNZ[+]Pi [/]TwoNZ)).
apply Sin_wd; rational.
eapply eq_transitive_unfolded.
apply Sin_plus_HalfPi.
@@ -938,9 +938,9 @@ Qed.
Lemma Cos_Pi : Cos Pi [=] [--][1].
Proof.
- apply eq_transitive_unfolded with (Cos (Pi [/]TwoNZ[+]Pi [/]TwoNZ)).
+ transitivity (Cos (Pi [/]TwoNZ[+]Pi [/]TwoNZ)).
apply Cos_wd; rational.
- eapply eq_transitive_unfolded.
+ eapply eq_transitive.
apply Cos_plus_HalfPi.
algebra.
Qed.
@@ -948,9 +948,9 @@ Qed.
Lemma Sin_plus_Pi : forall x : IR, Sin (x[+]Pi) [=] [--] (Sin x).
Proof.
intros.
- apply eq_transitive_unfolded with (Sin (x[+]Pi [/]TwoNZ[+]Pi [/]TwoNZ)).
+ transitivity (Sin (x[+]Pi [/]TwoNZ[+]Pi [/]TwoNZ)).
apply Sin_wd; rational.
- eapply eq_transitive_unfolded.
+ eapply eq_transitive.
apply Sin_plus_HalfPi.
apply Cos_plus_HalfPi.
Qed.
@@ -958,9 +958,9 @@ Qed.
Lemma Cos_plus_Pi : forall x : IR, Cos (x[+]Pi) [=] [--] (Cos x).
Proof.
intros.
- apply eq_transitive_unfolded with (Cos (x[+]Pi [/]TwoNZ[+]Pi [/]TwoNZ)).
+ transitivity (Cos (x[+]Pi [/]TwoNZ[+]Pi [/]TwoNZ)).
apply Cos_wd; rational.
- eapply eq_transitive_unfolded.
+ eapply eq_transitive.
apply Cos_plus_HalfPi.
apply un_op_wd_unfolded; apply Sin_plus_HalfPi.
Qed.
@@ -978,9 +978,7 @@ Proof.
apply (Hx I).
rewrite (Tan_Sin_over_Cos y Hy H0).
unfold y.
- assert (H2:([--](Sin x))[#][0]).
- csetoid_rewrite_rev (Cos_plus_HalfPi x).
- apply H0.
+ assert (H2:([--](Sin x))[#][0]) by (now csetoid_rewrite_rev (Cos_plus_HalfPi x)).
stepr (Cos x[/]([--](Sin x))[//]H2).
apply div_wd.
apply Sin_plus_HalfPi.
@@ -988,7 +986,7 @@ Proof.
clear H0.
rstepl (((Cos x[/][--](Sin x)[//]H2)[*](Tan x Hx))[/](Tan x Hx)[//]H).
apply div_wd;[|apply eq_reflexive].
- rewrite (Tan_Sin_over_Cos x Hx H1).
+ rewrite (Tan_Sin_over_Cos x Hx H1).
rational.
Qed.
@@ -999,7 +997,7 @@ Hint Resolve Sin_plus_Pi Cos_plus_Pi: algebra.
Lemma Sin_periodic : forall x : IR, Sin (x[+]Two[*]Pi) [=] Sin x.
Proof.
intro.
- apply eq_transitive_unfolded with (Sin (x[+]Pi[+]Pi)).
+ transitivity (Sin (x[+]Pi[+]Pi)).
apply Sin_wd; rational.
astepl ( [--] (Sin (x[+]Pi))).
Step_final ( [--][--] (Sin x)).
@@ -1008,7 +1006,7 @@ Qed.
Lemma Cos_periodic : forall x : IR, Cos (x[+]Two[*]Pi) [=] Cos x.
Proof.
intro.
- apply eq_transitive_unfolded with (Cos (x[+]Pi[+]Pi)).
+ transitivity (Cos (x[+]Pi[+]Pi)).
apply Cos_wd; rational.
astepl ( [--] (Cos (x[+]Pi))).
Step_final ( [--][--] (Cos x)).
@@ -1053,7 +1051,7 @@ Proof.
intros.
cut (Cos x [#] [0]). intro H.
assert (H0 : [--] (Cos x) [#] [0]). apply inv_resp_ap_zero; auto.
- apply eq_transitive_unfolded with (Sin x[/] _[//]H).
+ transitivity (Sin x[/] _[//]H).
2: unfold Tan, Tang in |- *; simpl in |- *; algebra.
rstepr ( [--] (Sin x) [/] _[//]H0).
assert (H1 : Cos (x[+]Pi) [#] [0]). astepl ( [--] (Cos x)); auto.
From cc4f9d64ab53932a1a721ff836203b3d22e58f5b Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Thu, 18 Sep 2014 18:20:16 +0200
Subject: [PATCH 108/110] Make compile with trunk
---
algebra/CPoly_Degree.v | 10 +++++-----
reals/fast/MultivariatePolynomials.v | 4 ++--
tactics/CornTac.v | 18 ------------------
3 files changed, 7 insertions(+), 25 deletions(-)
diff --git a/algebra/CPoly_Degree.v b/algebra/CPoly_Degree.v
index 8001181f..e6132f64 100644
--- a/algebra/CPoly_Degree.v
+++ b/algebra/CPoly_Degree.v
@@ -218,14 +218,14 @@ Lemma Sum_degree_le : forall (f : nat -> RX) (n k l : nat), k <= S l ->
Proof.
unfold degree_le in |- *. intros. induction l as [| l Hrecl]; intros.
generalize (toCle _ _ H); clear H; intro H.
- inversion H as [|m0 X].
+ inversion H as [|m0 X].
unfold Sum in |- *. unfold Sum1 in |- *. simpl in |- *.
- apply eq_transitive_unfolded with (nth_coeff m ([0]:RX)).
+ apply eq_transitive with (nth_coeff m ([0]:RX)).
apply nth_coeff_wd. algebra. algebra.
- inversion X. unfold Sum in |- *. unfold Sum1 in |- *. simpl in |- *.
- apply eq_transitive_unfolded with (nth_coeff m (f 0)).
+ inversion X. rename H3 into kis0. unfold Sum in |- *. unfold Sum1 in |- *. simpl in |- *.
+ apply eq_transitive with (nth_coeff m (f 0)).
apply nth_coeff_wd. cut (f 0[-][0] [=] f 0). auto. algebra.
- apply H0; try auto. rewrite H2. auto.
+ apply H0; try auto. rewrite kis0; auto.
elim (le_lt_eq_dec _ _ H); intro y.
apply eq_transitive_unfolded with (nth_coeff m (Sum k l f[+]f (S l))).
apply nth_coeff_wd. algebra.
diff --git a/reals/fast/MultivariatePolynomials.v b/reals/fast/MultivariatePolynomials.v
index 22dadbf9..3018b0a5 100644
--- a/reals/fast/MultivariatePolynomials.v
+++ b/reals/fast/MultivariatePolynomials.v
@@ -243,7 +243,7 @@ Proof.
apply Qle_refl.
revert p H.
dependent inversion v as [|a n0 v0].
- clear H0.
+ clear H.
intros p [[Ha0 Ha1] Hv].
stepl (@MVP_apply Q_as_CRing (S n) (let (n0, b) := BernsteinCoefficents (MVP_C_ Q_as_CRing n) p in
evalBernsteinBasis (MultivariatePolynomial Q_as_CRing n) b) (@Vector.cons Q a n v0));
@@ -365,7 +365,7 @@ Proof.
apply Qle_refl.
revert p H.
dependent inversion v as [| a n0 v0 ].
- clear H0.
+ clear H.
intros p [[Ha0 Ha1] Hv].
stepr (@MVP_apply Q_as_CRing (S n) (let (n0, b) := BernsteinCoefficents (MVP_C_ Q_as_CRing n) p in
evalBernsteinBasis (MultivariatePolynomial Q_as_CRing n) b) (Vector.cons _ a _ v0));
diff --git a/tactics/CornTac.v b/tactics/CornTac.v
index 0d9a6d5d..965755c0 100644
--- a/tactics/CornTac.v
+++ b/tactics/CornTac.v
@@ -21,24 +21,6 @@
Require Import SetoidTactics.
-(* Implements an apply-like tactic that uses refine's strong unifcation algorithm
-REPLACED by ssr apply
-Ltac rapply T :=
- (refine T ||
- refine (T _) ||
- refine (T _ _) ||
- refine (T _ _ _) ||
- refine (T _ _ _ _) ||
- refine (T _ _ _ _ _) ||
- refine (T _ _ _ _ _ _) ||
- refine (T _ _ _ _ _ _ _) ||
- refine (T _ _ _ _ _ _ _ _) ||
- refine (T _ _ _ _ _ _ _ _ _) ||
- refine (T _ _ _ _ _ _ _ _ _ _) ||
- refine (T _ _ _ _ _ _ _ _ _ _ _)).
-
-Ltac rsapply T := rapply T; simpl.
-*)
(* Replace the LHS or RHS of an expression with another expression
This tactic along with the setiod functionality, basically replaces the step
tactic *)
From 82325fb931a4d1e0dacb0d4ad4613dd2246760b7 Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Thu, 18 Sep 2014 18:22:35 +0200
Subject: [PATCH 109/110] update README
---
README | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README b/README
index 6cad5586..319defa0 100644
--- a/README
+++ b/README
@@ -6,7 +6,7 @@ PREREQUISITES
This version of C-CoRN is known to compile with:
- - Coq trunk
+ - Coq trunk (d9736dae4168927f735ca4f60b61a83929ae4435)
- SCons 1.2
From 3854436f8883c2c02fcd30dd799d0c0b9c2ff704 Mon Sep 17 00:00:00 2001
From: Bas Spitters
Date: Thu, 25 Sep 2014 17:45:39 +0200
Subject: [PATCH 110/110] Removing unused tactics
---
tactics/rational.ml | 512 --------------------------------------------
1 file changed, 512 deletions(-)
delete mode 100644 tactics/rational.ml
diff --git a/tactics/rational.ml b/tactics/rational.ml
deleted file mode 100644
index c2fdecfb..00000000
--- a/tactics/rational.ml
+++ /dev/null
@@ -1,512 +0,0 @@
-(* Copyright © 1998-2006
- * Henk Barendregt
- * Luís Cruz-Filipe
- * Herman Geuvers
- * Mariusz Giero
- * Rik van Ginneken
- * Dimitri Hendriks
- * Sébastien Hinderer
- * Bart Kirkels
- * Pierre Letouzey
- * Iris Loeb
- * Lionel Mamane
- * Milad Niqui
- * Russell O’Connor
- * Randy Pollack
- * Nickolay V. Shmyrev
- * Bas Spitters
- * Dan Synek
- * Freek Wiedijk
- * Jan Zwanenburg
- *
- * This work is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This work is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this work; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *)
-
-open Util
-open Pp
-open Printer
-open Term
-open Names
-open Nameops
-open Libnames
-open Closure
-open Reductionops
-open Tactics
-open Tacmach
-open Proof_trees
-open Environ
-open Declarations
-open Inductiveops
-
-let coq_modules = Coqlib.init_modules @ Coqlib.zarith_base_modules
-
-let coq_constant s =
- Coqlib.gen_constant_in_modules "CoRN" coq_modules s
-
-let constant s =
- try
- constr_of_reference (Nametab.absolute_reference (path_of_string s))
- with Not_found ->
- error (Printf.sprintf "constant %s" s)
- | Anomaly _ ->
- error (Printf.sprintf "constant %s" s)
-
-let constant_algebra s = constant ("CoRN.algebra." ^ s)
-let constant_tactics s = constant ("CoRN.tactics." ^ s)
-
-type xexpr =
- X_var of int
- | X_unop of int * xexpr
- | X_binop of int * xexpr * xexpr
- | X_part of int * xexpr * constr
- | X_int of int
- | X_plus of xexpr * xexpr
- | X_mult of xexpr * xexpr
- | X_div of xexpr * xexpr * constr
- | X_zero
- | X_one
- | X_nat of int
- | X_inv of xexpr
- | X_minus of xexpr * xexpr
- | X_power of xexpr * int
-
-let hd_app c = fst (destApplication c)
-
-let args_app c = snd (destApplication c)
-
-let first_arg c = (args_app c).(0)
-let third_arg c = (args_app c).(2)
-let sixth_arg c = (args_app c).(5)
-
-let xinterp g c = sixth_arg (pf_type_of g c)
-
-let mk_existential env = Evarutil.new_evar_in_sign env
-
-let mk_lambda n t c = mkLambda (n,t,c)
-let mk_cast c t = mkCast (c,t)
-let mk_case ci a b c = mkCase (ci,a,b,c)
-
-let pf_nf_betadeltaiota = pf_reduce nf_betadeltaiota
-let pf_cbv_betadeltaiota = pf_reduce Tacred.cbv_betadeltaiota
-
-let pf_whd_all_but sp =
- let flags =
- RedFlags.red_sub
- (RedFlags.red_add_transparent betadeltaiota (Conv_oracle.freeze()))
- (RedFlags.fCONST sp) in
- pf_reduce (clos_norm_flags flags)
-
-let xrational verbose g a =
-
- let cr_crr = constant_algebra "CRings.cr_crr"
- and cf_crr = constant_algebra "CFields.cf_crr" in
-
- let the_csetoid = a.(0) in
- let the_csemigroup = first_arg the_csetoid in
- let the_cmonoid = first_arg the_csemigroup in
- let the_cgroup = first_arg the_cmonoid in
- let the_cabgroup = first_arg the_cgroup in
-
- let the_cstructure,the_suffix,the_file =
- if isApp the_cabgroup && hd_app the_cabgroup = cr_crr then
- let the_cring = first_arg the_cabgroup in
- if isApp the_cring && hd_app the_cring = cf_crr then
- let the_cfield = first_arg the_cring in
- the_cfield,"F","FieldReflection"
- else the_cring,"R","RingReflection"
- else the_cabgroup,"G","GroupReflection" in
-
- let nat_nat = coq_constant "nat"
- and nat_O = coq_constant "O"
- and nat_S = coq_constant "S"
- and refl_equal = coq_constant "refl_equal"
- and bool_bool = coq_constant "bool"
- and bool_true = coq_constant "true"
- and pos_xI = coq_constant "xI"
- and pos_xO = coq_constant "xO"
- and pos_xH = coq_constant "xH"
- and int_ZERO = coq_constant "ZERO"
- and int_POS = coq_constant "POS"
- and int_NEG = coq_constant "NEG"
-
- and cs_eq = constant_algebra "CSetoids.cs_eq" in
-
- let xexpr_constant s =
- try constant_tactics (the_file ^ ".xexpr" ^ the_suffix ^ "_" ^ s)
- with _ -> nat_O in
- let xexpr_var = xexpr_constant "var"
- and xexpr_unop = xexpr_constant "unop"
- and xexpr_binop = xexpr_constant "binop"
- and xexpr_part = xexpr_constant "part"
- and xexpr_int = xexpr_constant "int"
- and xexpr_plus = xexpr_constant "plus"
- and xexpr_mult = xexpr_constant "mult"
- and xexpr_div = xexpr_constant "div"
- and xexpr_zero = xexpr_constant "zero"
- and xexpr_one = xexpr_constant "one"
- and xexpr_nat = xexpr_constant "nat"
- and xexpr_inv = xexpr_constant "inv"
- and xexpr_minus = xexpr_constant "minus"
- and xexpr_power = xexpr_constant "power" in
-
- let the_file_constant s = constant_tactics
- (the_file ^ "." ^ s ^ the_suffix) in
- let xforget = the_file_constant "xforget"
- and tactic_lemma = the_file_constant "Tactic_lemma" in
-
- let norm = constant_tactics ("AlgReflection.Norm" ^ the_suffix) in
-
- let csf_fun = constant_algebra "CSetoids.csf_fun"
- and csbf_fun = constant_algebra "CSetoids.csbf_fun"
- and csg_unit = constant_algebra "CMonoids.cm_unit"
- and cr_one = constant_algebra "CRings.cr_one"
- and nring = constant_algebra "CRings.nring"
- and zring = constant_algebra "CRings.zring"
- and csg_op = constant_algebra "CSemiGroups.csg_op"
- and cg_inv = constant_algebra "CGroups.cg_inv"
- and cg_minus = constant_algebra "CGroups.cg_minus"
- and cr_mult = constant_algebra "CRings.cr_mult"
- and cf_div = constant_algebra "CFields.cf_div"
- and nexp_op = constant_algebra "CRings.nexp_op"
- and expr_minus = constant_tactics "AlgReflection.expr_minus"
- and pfpfun = constant_algebra "CSetoidFun.pfpfun"
- and id_un_op = constant_algebra "CSetoids.id_un_op"
- and cs_binproj1 = constant_algebra "CSetoidFun.cs_binproj1"
- and fid = constant_algebra "CSetoidFun.Fid"
- and csetoid_un_op = constant_algebra "CSetoids.CSetoid_un_op"
- and csetoid_bin_op = constant_algebra "CSetoids.CSetoid_bin_op"
- and partFunct = constant_algebra "CSetoidFun.PartFunct"
-
- in
-
- let ind_of_ref = function
- | IndRef (kn,i) -> (kn,i)
- | _ -> anomaly "IndRef expected" in
-
- let nat_info =
- let nat = ind_of_ref Coqlib.glob_nat in
- make_default_case_info (Global.env()) RegularStyle nat
- in
-
- let rec evalnat n =
- if eq_constr n nat_O then 0
- else if isApp n & eq_constr (hd_app n) nat_S then
- let a = args_app n in
- if Array.length a > 0 then (evalnat a.(0)) + 1
- else raise (Failure "evalnat")
- else raise (Failure "evalnat") in
-
- let rec evalpos n =
- if eq_constr n pos_xH then 1
- else if isApp n then
- let f = hd_app n
- and a = args_app n in
- if Array.length a > 0 then
- if eq_constr f pos_xI then 2 * (evalpos a.(0)) + 1
- else if eq_constr f pos_xO then 2 * (evalpos a.(0))
- else raise (Failure "evalint")
- else raise (Failure "evalint")
- else raise (Failure "evalint") in
-
- let rec evalint n =
- if eq_constr n int_ZERO then 0
- else if isApp n then
- let f = hd_app n
- and a = args_app n in
- if Array.length a > 0 then
- if eq_constr f int_POS then evalpos a.(0)
- else if eq_constr f int_NEG then -(evalpos a.(0))
- else raise (Failure "evalint")
- else raise (Failure "evalint")
- else raise (Failure "evalint") in
-
- let rec envindex : constr * constr list -> int * constr list =
- function (x,e) ->
- match e with
- [] -> (0,[x])
- | y::f ->
- if eq_constr x y then (0, e) else
- let (i,g) = envindex (x,f) in
- (i + 1, y::g) in
-
- let liftV : constr * constr list * constr list * constr list * constr list -> xexpr * constr list * constr list * constr list * constr list =
- function (x,eV,eU,eB,eP) -> let (i,fV) = envindex (x,eV) in (X_var i, fV,eU,eB,eP) in
-
- let rec
- liftU : constr * constr * constr list * constr list * constr list * constr list -> xexpr * constr list * constr list * constr list * constr list =
- function (f,x,eV,eU,eB,eP) ->
- let (x',fV,fU,fB,fP) = lift (x,eV,eU,eB,eP) in
- let (i,gU) = envindex (f,fU) in (X_unop(i,x'),fV,gU,fB,fP) and
-
- liftB : constr * constr * constr * constr list * constr list * constr list * constr list -> xexpr * constr list * constr list * constr list * constr list =
- function (f,x,y,eV,eU,eB,eP) ->
- let (x',fV,fU,fB,fP) = lift (x,eV,eU,eB,eP) in
- let (y',gV,gU,gB,gP) = lift (y,fV,fU,fB,fP) in
- let (i,hB) = envindex (f,gB) in (X_binop(i,x',y'),gV,gU,hB,gP) and
-
- liftP : constr * constr * constr * constr list * constr list * constr list * constr list -> xexpr * constr list * constr list * constr list * constr list =
- function (x,y,h,eV,eU,eB,eP) -> let (z,fV,fU,fB,fP) = lift (y,eV,eU,eB,eP) in
- let (i,gP) = envindex (x,fP) in (X_part(i,z,h), fV,fU,fB,gP) and
-
- lift : constr * constr list * constr list * constr list * constr list -> xexpr * constr list * constr list * constr list * constr list =
- function (x0,eV,eU,eB,eP) ->
- let x = strip_outer_cast x0 in
- if isApp x then
- let f = hd_app x
- and a = args_app x in
- if eq_constr f csg_unit then (X_zero, eV,eU,eB,eP)
- else if eq_constr f cr_one then (X_one, eV,eU,eB,eP)
- else if eq_constr f nring & Array.length a > 1 then
- try (X_nat(evalnat a.(1)), eV,eU,eB,eP)
- with Failure "evalnat" -> liftV (x,eV,eU,eB,eP)
- else if eq_constr f zring & Array.length a > 1 then
- try (X_int(evalint a.(1)), eV,eU,eB,eP)
- with Failure "evalint" -> liftV (x,eV,eU,eB,eP)
- else if eq_constr f pfpfun & Array.length a > 3 then
- liftP(a.(1),a.(2),a.(3),eV,eU,eB,eP)
- else if eq_constr f csbf_fun then
- if Array.length a > 5 & eq_constr a.(0) a.(2) & eq_constr a.(1) a.(2)
- then
- if isApp a.(3) then
- let g = hd_app a.(3) in
- if eq_constr g csg_op
- then
- let (t1,e1V,e1U,e1B,e1P) = lift (a.(4),eV,eU,eB,eP) in
- let (t2,e2V,e2U,e2B,e2P) = lift (a.(5),e1V,e1U,e1B,e1P) in
- (X_plus(t1,t2), e2V,e2U,e2B,e2P)
- else
- if eq_constr g cr_mult
- then
- let (t1,e1V,e1U,e1B,e1P) = lift (a.(4),eV,eU,eB,eP) in
- let (t2,e2V,e2U,e2B,e2P) = lift (a.(5),e1V,e1U,e1B,e1P) in
- (X_mult(t1,t2), e2V,e2U,e2B,e2P)
- else liftB(a.(3),a.(4),a.(5),eV,eU,eB,eP)
- else liftB(a.(3),a.(4),a.(5),eV,eU,eB,eP)
- else liftV (x,eV,eU,eB,eP)
- else if eq_constr f csf_fun then
- if Array.length a > 3 & eq_constr a.(0) a.(1) then
- if isApp a.(2) then
- let g = hd_app a.(2) in
- let b = args_app a.(2) in
- if eq_constr g cg_inv then
- let (t1,e1V,e1U,e1B,e1P) = lift (a.(3),eV,eU,eB,eP) in
- (X_inv(t1), e1V,e1U,e1B,e1P)
- else
- if eq_constr g nexp_op & Array.length b > 1 then
- try
- let n = evalnat b.(1) in
- let (t1,e1V,e1U,e1B,e1P) = lift (a.(3),eV,eU,eB,eP) in
- (X_power(t1,n), e1V,e1U,e1B,e1P)
- with Failure "evalnat" -> liftV (x,eV,eU,eB,eP)
- else liftU (a.(2),a.(3),eV,eU,eB,eP)
- else liftU (a.(2),a.(3),eV,eU,eB,eP)
- else liftV (x,eV,eU,eB,eP)
- else if eq_constr f cg_minus then
- if Array.length a > 2 then
- let (t1,e1V,e1U,e1B,e1P) = lift (a.(1),eV,eU,eB,eP) in
- let (t2,e2V,e2U,e2B,e2P) = lift (a.(2),e1V,e1U,e1B,e1P) in
- (X_minus(t1,t2), e2V,e2U,e2B,e2P)
- else liftV (x,eV,eU,eB,eP)
- else if eq_constr f cf_div then
- if Array.length a > 3 then
- let (t1,e1V,e1U,e1B,e1P) = lift (a.(1),eV,eU,eB,eP) in
- let (t2,e2V,e2U,e2B,e2P) = lift (a.(2),e1V,e1U,e1B,e1P) in
- (X_div(t1,t2,a.(3)), e2V,e2U,e2B,e2P)
- else liftV (x,eV,eU,eB,eP)
- else if isApp f then
- lift ((collapse_appl x), eV,eU,eB,eP)
- else liftV (x,eV,eU,eB,eP)
- else liftV (x,eV,eU,eB,eP) in
-
- let rec natconstr i =
- if i > 0 then mkApp(nat_S, [| natconstr (i - 1) |]) else nat_O in
-
- let rec posconstr k =
- if k == 1 then pos_xH else
- let l = k mod 2 in
- mkApp((if l == 0 then pos_xO else pos_xI), [| posconstr (k / 2) |]) in
-
- let rec intconstr k =
- if k == 0 then int_ZERO else
- if k > 0 then mkApp(int_POS, [| posconstr k |]) else
- mkApp(int_NEG, [| posconstr (- k) |]) in
-
- let rec xexprconstr t rhoV rhoU rhoB rhoP =
- match t with
- X_var i -> mkApp(xexpr_var, [| the_cstructure; rhoV; rhoU; rhoB; rhoP; natconstr i |])
- | X_unop (i,t1) ->
- let c1 = xexprconstr t1 rhoV rhoU rhoB rhoP in
- mkApp(xexpr_unop, [| the_cstructure; rhoV; rhoU; rhoB; rhoP; xinterp g c1; natconstr i; c1 |])
- | X_binop (i,t1,t2) ->
- let c1 = xexprconstr t1 rhoV rhoU rhoB rhoP in
- let c2 = xexprconstr t2 rhoV rhoU rhoB rhoP in
- mkApp(xexpr_binop, [| the_cstructure; rhoV; rhoU; rhoB; rhoP; xinterp g c1; xinterp g c2; natconstr i; c1; c2 |])
- | X_part (i,t,h) ->
- let c = xexprconstr t rhoV rhoU rhoB rhoP in
- mkApp(xexpr_part, [| the_cstructure; rhoV; rhoU; rhoB; rhoP; xinterp g c; natconstr i; c; h |])
- | X_int i -> mkApp(xexpr_int, [| the_cstructure; rhoV; rhoU; rhoB; rhoP; intconstr i |])
- | X_plus (t1,t2) ->
- let c1 = xexprconstr t1 rhoV rhoU rhoB rhoP
- and c2 = xexprconstr t2 rhoV rhoU rhoB rhoP in
- mkApp(xexpr_plus, [| the_cstructure; rhoV; rhoU; rhoB; rhoP;
- xinterp g c1; xinterp g c2; c1; c2 |])
- | X_mult (t1,t2) ->
- let c1 = xexprconstr t1 rhoV rhoU rhoB rhoP
- and c2 = xexprconstr t2 rhoV rhoU rhoB rhoP in
- mkApp(xexpr_mult, [| the_cstructure; rhoV; rhoU; rhoB; rhoP;
- xinterp g c1; xinterp g c2; c1; c2 |])
- | X_div (t1,t2,nz) ->
- let c1 = xexprconstr t1 rhoV rhoU rhoB rhoP
- and c2 = xexprconstr t2 rhoV rhoU rhoB rhoP in
- mkApp(xexpr_div, [| the_cstructure; rhoV; rhoU; rhoB; rhoP;
- xinterp g c1; xinterp g c2; c1; c2; nz |])
- | X_zero ->
- mkApp(xexpr_zero, [| the_cstructure; rhoV; rhoU; rhoB; rhoP |])
- | X_one ->
- mkApp(xexpr_one, [| the_cstructure; rhoV; rhoU; rhoB; rhoP |])
- | X_nat i ->
- mkApp(xexpr_nat, [| the_cstructure; rhoV; rhoU; rhoB; rhoP; natconstr i |])
- | X_inv (t1) ->
- let c1 = xexprconstr t1 rhoV rhoU rhoB rhoP in
- mkApp(xexpr_inv, [| the_cstructure; rhoV; rhoU; rhoB; rhoP; xinterp g c1; c1 |])
- | X_minus (t1,t2) ->
- let c1 = xexprconstr t1 rhoV rhoU rhoB rhoP
- and c2 = xexprconstr t2 rhoV rhoU rhoB rhoP in
- mkApp(xexpr_minus, [| the_cstructure; rhoV; rhoU; rhoB; rhoP;
- xinterp g c1; xinterp g c2; c1; c2 |])
- | X_power (t1,n) ->
- let c1 = xexprconstr t1 rhoV rhoU rhoB rhoP in
- mkApp(xexpr_power, [| the_cstructure; rhoV; rhoU; rhoB; rhoP;
- xinterp g c1; c1; natconstr n |]) in
-
- let rec valconstr e ta =
- match e with
- [] -> mk_lambda Anonymous nat_nat
- (mk_cast (mkApp(csg_unit, [|the_cmonoid |])) ta)
- | [c] -> mk_lambda Anonymous nat_nat c
- | c::f -> mk_lambda (Name (id_of_string "n")) nat_nat
- (mk_case nat_info ta (mkRel 1) [| c; valconstr f ta |]) in
-
- let rec unconstr e ta =
- match e with
- [] -> mk_lambda Anonymous nat_nat
- (mk_cast (mkApp(id_un_op, [|the_csetoid |])) ta)
- | [c] -> mk_lambda Anonymous nat_nat c
- | c::f -> mk_lambda (Name (id_of_string "n")) nat_nat
- (mk_case nat_info ta (mkRel 1) [| c; unconstr f ta |]) in
-
- let rec binconstr e ta =
- match e with
- [] -> mk_lambda Anonymous nat_nat
- (mk_cast (mkApp(cs_binproj1, [|the_csetoid |])) ta)
- | [c] -> mk_lambda Anonymous nat_nat c
- | c::f -> mk_lambda (Name (id_of_string "n")) nat_nat
- (mk_case nat_info ta (mkRel 1) [| c; binconstr f ta |]) in
-
- let rec funconstr e ta =
- match e with
- [] -> mk_lambda Anonymous nat_nat
- (mk_cast (mkApp(fid, [|the_csetoid |])) ta)
- | [c] -> mk_lambda Anonymous nat_nat c
- | c::f -> mk_lambda (Name (id_of_string "n")) nat_nat
- (mk_case nat_info ta (mkRel 1) [| c; funconstr f ta |]) in
-
- let rec printval i e =
- match e with
- [] -> ()
- | c::f ->
- msgnl (str "(" ++ int i ++ str ") -> " ++ prterm c);
- printval (i + 1) f in
-
- let report g fV fU fB fP a xleft xright rhoV rhoU rhoB rhoP =
- (let left =
- pf_nf_betadeltaiota g
- (mkApp(xforget, [| the_cstructure; rhoV; rhoU; rhoB; rhoP; xinterp g xleft; xleft |]))
- and right =
- pf_nf_betadeltaiota g
- (mkApp(xforget, [| the_cstructure; rhoV; rhoU; rhoB; rhoP; xinterp g xright; xright |]))
- in
- let nleft =
- pf_cbv_betadeltaiota g (mkApp(norm, [| left |]))
- and nright =
- pf_cbv_betadeltaiota g (mkApp(norm, [| right |]))
- in
- msgnl (mt ()); printval 0 fV; msgnl (mt ());
- msgnl (mt ()); printval 0 fU; msgnl (mt ());
- msgnl (mt ()); printval 0 fB; msgnl (mt ());
- msgnl (mt ()); printval 0 fP; msgnl (mt ());
- msgnl (prterm a.(1));
- msgnl ( prterm left );
- msgnl ( prterm nleft ++ fnl ());
- msgnl ( prterm a.(2) );
- msgnl ( prterm right );
- msgnl ( prterm nright ++ fnl ());
- if the_suffix = "F" then
- let difference =
- (pf_cbv_betadeltaiota g
- (mkApp(norm, [| mkApp(expr_minus, [| left; right |]) |]))) in
- msgnl ( prterm difference ++ fnl ())
- else ())
- in
-
- let ta = pf_type_of g a.(1) in
- let fleft = a.(1) and fright = a.(2) in
- let (l,eV,eU,eB,eP) = lift (fleft,[],[],[],[]) in
- let (r,fV,fU,fB,fP) = lift (fright,eV,eU,eB,eP) in
- let rhoV = valconstr fV ta in
- let rhoU = unconstr fU (mkApp(csetoid_un_op, [|the_csetoid|])) in
- let rhoB = binconstr fB (mkApp(csetoid_bin_op, [|the_csetoid|])) in
- let rhoP = funconstr fP (mkApp(partFunct, [|the_csetoid|])) in
- let xleft = xexprconstr l rhoV rhoU rhoB rhoP
- and xright = xexprconstr r rhoV rhoU rhoB rhoP in
- if verbose then
- report g fV fU fB fP a xleft xright rhoV rhoU rhoB rhoP;
- let term =
- mkApp(tactic_lemma,
- [| the_cstructure; rhoV; rhoU; rhoB; rhoP; fleft; fright; xleft; xright;
- mkApp(refl_equal, [| bool_bool; bool_true |]) |])
- in
- let result =
- try
- exact_check term g
- with e when Logic.catchable_exception e -> error "cannot establish equality"
- in
- if verbose then msgnl (str "end Rational");
- result
-
-
-let hrational verbose g =
-
- let cs_eq = constant_algebra "CSetoids.cs_eq" in
-
- let c = strip_outer_cast (pf_concl g) in
- if isApp c & eq_constr (hd_app c) cs_eq then
- let a = args_app c in
- if Array.length a > 2 then
- xrational verbose g a
- else error "not an [=] equation"
- else error "not an [=] equation"
-
-let hrational1 verbose g =
- if verbose then msgnl (str "begin Rational");
- hrational verbose g
-
-TACTIC EXTEND Rational
-| ["Rational"] -> [ hrational1 false ]
-END
-
-TACTIC EXTEND RationalVerbose
-| ["Rational" "Verbose"] -> [ hrational1 true ]
-END