-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_eps.v
129 lines (99 loc) · 3.18 KB
/
c_eps.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
(**************************************************************)
(* Copyright Dominique Larchey-Wendling [*] *)
(* *)
(* [*] Affiliation LORIA -- CNRS *)
(**************************************************************)
(* This file is distributed under the terms of the *)
(* CeCILL v2 FREE SOFTWARE LICENSE AGREEMENT *)
(**************************************************************)
Require Import Arith Lia Extraction.
Set Implicit Arguments.
Section nat_rev_ind.
Variables (P : nat -> Prop)
(HP : forall n, P (S n) -> P n).
Theorem nat_rev_ind x y : x <= y -> P y -> P x.
Proof. induction 1; auto. Qed.
End nat_rev_ind.
Section Decidable_Minimization.
Variable (P : nat -> Prop)
(P_dec : forall n, { P n } + { ~ P n }).
Inductive bar n : Prop :=
| in_bar_0 : P n -> bar n
| in_bar_1 : bar (S n) -> bar n.
Local Fact exists_bar n : (exists i, n <= i /\ P i) -> bar n.
Proof.
intros (i & H1 & H2).
apply in_bar_0 in H2.
revert n i H1 H2.
apply nat_rev_ind.
apply in_bar_1.
Qed.
Section Constructive_Epsilon.
Let Fixpoint loop n (Hn : bar n) : { i | P i }.
Proof.
refine (
match P_dec n with
| left H => exist _ n _
| right H => let (m,Hm) := loop (S n) _
in exist _ m _
end).
+ trivial.
+ inversion Hn.
* destruct H; assumption.
* assumption.
+ trivial.
Qed.
Print loop.
(*
Fact bar_eq_domain n : bar n <-> exists i, n <= i /\ P i.
Proof.
split.
+ intros Hn.
destruct (@loop n Hn) as (i & Hi).
exists i; auto.
+ apply exists_bar.
Qed.
*)
Definition constructive_epsilon : (exists x, P x) -> { x | P x }.
Proof.
intros H.
refine (let (x,Hx) := @loop 0 _ in exist _ x _ ).
+ apply exists_bar.
destruct H as (i & Hi); exists i; split; auto; lia.
+ tauto.
Defined.
End Constructive_Epsilon.
Section Unbounded_Min.
Let Fixpoint loop n (Hn : bar n) : { m | P m /\ forall i, P i -> i < n \/ m <= i }.
Proof.
refine (match P_dec n with
| left H => exist _ n _
| right H => let (m,Hm) := loop (S n) _
in exist _ m _
end).
1-2: cycle 1.
* inversion Hn; auto; tauto.
* split; auto; intros; lia.
* destruct Hm as (H1 & H2); split; auto.
intros i Hi.
destruct (eq_nat_dec i n).
+ subst; tauto.
+ apply H2 in Hi; lia.
Qed.
Definition unb_dec_min : ex P -> { m | P m /\ forall i, P i -> m <= i }.
Proof.
intros H.
refine (let (m,Hm) := @loop 0 _ in exist _ m _).
+ apply exists_bar; auto.
destruct H as (i & Hi); exists i; split; auto; lia.
+ destruct Hm as (H1 & H2).
split; auto.
intros i Hi; apply H2 in Hi; lia.
Defined.
End Unbounded_Min.
End Decidable_Minimization.
Extract Inductive sumbool => "bool" [ "true" "false" ].
Check constructive_epsilon.
Extraction constructive_epsilon.
Check unb_dec_min.
Extraction unb_dec_min.