Debian Codegraph @

reals/stdlib/Markov.v

raw
1 (*
2 Copyright © 2020 Vincent Semeria
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
6 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
8 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 *)
10
11 (** Consequence of the Markov principle on constructive reals. *)
12
13 From Coq Require Import QArith_base.
14 From Coq Require Import ConstructiveReals.
15 From Coq Require Import ConstructiveAbs.
16
17 Local Open Scope ConstructiveReals.
18
19 (* This axiom has computational content :
20 run the unbounded search Pdec 0, Pdec 1, ...
21 and the last hypothesis is a proof of termination. *)
22 Definition Markov : Prop
23 := forall (P : nat -> Prop),
24 (forall n:nat, {P n} + {~P n})
25 -> (~~exists n:nat, P n)
26 -> exists n:nat, P n.
27
28 Lemma Markov_notnot_lt_0 : forall {R : ConstructiveReals} (x : CRcarrier R),
29 Markov -> (~~CRltProp R 0 x) -> CRltProp R 0 x.
30 Proof.
31 intro R.
32 assert (forall (x : CRcarrier R) (n:nat),
33 x - CR_of_Q R (1#Pos.of_nat n) < x) as bumpDown.
34 { intros x n.
35 apply (CRlt_le_trans _ (x-0)).
36 apply CRplus_lt_compat_l.
37 apply CRopp_gt_lt_contravar, CR_of_Q_lt.
38 reflexivity.
39 unfold CRminus. rewrite CRopp_0, CRplus_0_r.
40 apply CRle_refl. }
41 intros x markov xpos.
42 assert (exists n:nat, Qlt 0 (let (q,_) := CR_Q_dense R _ _ (bumpDown x n) in q)).
43 { apply markov.
44 - intro n.
45 destruct (CR_Q_dense R _ _ (bumpDown x n)) as [q H].
46 destruct (Qlt_le_dec 0 q).
47 left. exact q0. right. apply (Qle_not_lt _ _ q0).
48 - intro abs. contradict xpos; intro xpos.
49 apply CRltEpsilon in xpos.
50 contradict abs.
51 destruct (CR_archimedean R (CRinv R x (inr xpos))) as [n H].
52 exists (Pos.to_nat n).
53 destruct ( CR_Q_dense R (x - CR_of_Q R (1 # Pos.of_nat (Pos.to_nat n)))%ConstructiveReals
54 x (bumpDown x (Pos.to_nat n))) as [q H0].
55 apply (lt_CR_of_Q R).
56 refine (CRle_lt_trans _ _ _ _ (fst H0)).
57 clear H0 q.
58 rewrite Pos2Nat.id.
59 apply (CRplus_le_reg_r (CR_of_Q R (1#n))).
60 unfold CRminus.
61 rewrite CRplus_0_l.
62 rewrite CRplus_assoc.
63 rewrite CRplus_opp_l, CRplus_0_r.
64 apply CRlt_asym in H.
65 apply (CRmult_le_compat_l x) in H.
66 rewrite CRinv_r in H.
67 apply (CRmult_le_compat_r (CR_of_Q R (1#n))) in H.
68 rewrite CRmult_1_l, CRmult_assoc, <- CR_of_Q_mult in H.
69 setoid_replace ((Z.pos n # 1) * (1 # n))%Q with 1%Q in H.
70 rewrite CRmult_1_r in H. exact H.
71 unfold Qeq; simpl.
72 rewrite Pos.mul_1_r, Pos.mul_1_r. reflexivity.
73 apply CR_of_Q_le; discriminate.
74 apply CRlt_asym, xpos. }
75 clear xpos.
76 destruct H as [n H].
77 destruct (CR_Q_dense R _ _ (bumpDown x n)) as [q H0].
78 apply CRltForget.
79 apply (CRlt_trans _ (CR_of_Q R q)).
80 apply CR_of_Q_lt, H.
81 apply H0.
82 Qed.
83
84 Lemma Markov_notnot_lt : forall {R : ConstructiveReals} (x y : CRcarrier R),
85 Markov -> (~~CRltProp R x y) -> CRltProp R x y.
86 Proof.
87 intros. apply CRltForget.
88 apply (CRplus_lt_reg_r (-x)).
89 apply (CRle_lt_trans _ 0).
90 rewrite CRplus_opp_r. apply CRle_refl.
91 apply CRltEpsilon.
92 apply (Markov_notnot_lt_0 (y-x) H).
93 intro abs. contradict H0; intro H0.
94 contradict abs.
95 apply CRltForget.
96 apply (CRplus_lt_reg_r x).
97 apply (CRle_lt_trans _ x).
98 rewrite CRplus_0_l. apply CRle_refl.
99 apply (CRlt_le_trans _ y).
100 apply CRltEpsilon, H0.
101 unfold CRminus.
102 rewrite CRplus_assoc, CRplus_opp_l, CRplus_0_r.
103 apply CRle_refl.
104 Qed.
105
106 Lemma Markov_notnot_apart_0 : forall {R : ConstructiveReals} (x : CRcarrier R),
107 Markov -> (~(x == 0)) -> (x ≶ 0).
108 Proof.
109 intros.
110 apply CRabs_appart_0.
111 apply CRltEpsilon, (Markov_notnot_lt_0 _ H).
112 intro abs. contradict H0.
113 assert (CRabs R x <= 0) as H0.
114 { intro H0. contradict abs.
115 apply CRltForget, H0. }
116 pose proof (CRabs_def2 x 0 H0) as [H1 H2].
117 rewrite CRopp_0 in H2.
118 split; assumption.
119 Qed.
120
121 Lemma Markov_notnot_apart : forall {R : ConstructiveReals} (x y : CRcarrier R),
122 Markov -> (~(x == y)) -> (x ≶ y).
123 Proof.
124 intros.
125 apply (CRplus_appart_reg_r (-y)).
126 rewrite CRplus_opp_r.
127 apply (Markov_notnot_apart_0 _ H).
128 intro abs. contradict H0.
129 apply (CRplus_eq_reg_r (-y)).
130 rewrite CRplus_opp_r. exact abs.
131 Qed.