-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntrospectiveCalculus17.v
181 lines (148 loc) · 6.36 KB
/
IntrospectiveCalculus17.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
Set Implicit Arguments.
Set Asymmetric Patterns.
Require Import Unicode.Utf8.
Require Import Coq.Program.Equality.
Require Import Setoid.
Require Import List.
Require Import String.
(* Hack - remove later *)
Parameter cheat : ∀ {A}, A.
(* Protect myself from accidental infinite loops during dev work *)
(* Set Typeclasses Iterative Deepening. *)
Set Typeclasses Depth 3.
(****************************************************
Proof bureaucracy
****************************************************)
Section ProofBureaucracy.
(* When proving, there are a lot of simplification steps that I want to be applied automatically, with very little effort. As the definitions and lemmas proceed, I want to add more simplification steps to a hints database.
Unfortunately, the `auto` family of tactics, which apply hints from a database, cancel all the applications if you didn't solve the entire goal. That's not what I want. As a hack to work around this, it's possible to shelve an incomplete goal, and `auto` will interpret this as "success". So we just end every hint with `shelve`. *)
Ltac autouse_shelving_db steps db :=
idtac steps; match steps with
| S ?p => try ((progress (unshelve typeclasses eauto 99 with db));
autouse_shelving_db p db)
| _ => idtac "Warning: steps ran out"
end.
Create HintDb simplify.
Ltac simplify := autouse_shelving_db 20 ident:(simplify).
(* We *do* want to apply intros if it helps simplify, but not if it doesn't, so don't shelve here. Also, since it's the second-choice and can duplicate work, make it high-cost. *)
(* Hint Extern 12 => intro; intros : simplify. *)
(* ...and if we *can* solve easily, might as well. *)
Hint Extern 1 => solve [trivial | constructor | discriminate] : simplify.
(* One notable simplification step is to rewrite equality hypotheses when one side is just another hypothesis. But it's kinda expensive, so we give it a high-ish cost. *)
Hint Extern 9 => progress match goal with
| x : _ |- _ => match goal with
| eq : x = _ |- _ => rewrite eq in *; clear x eq
| eq : _ = x |- _ => rewrite <- eq in *; clear x eq
end
end; shelve
: simplify.
(* `remember`, but not if it's redundant *)
Ltac dontforget term :=
lazymatch term with
| (_ _) => lazymatch goal with
| _ : _ = term |- _ => idtac
| _ : term = _ |- _ => idtac
| _ => remember term
end
| _ => idtac
end.
End ProofBureaucracy.
(****************************************************
Contexts
****************************************************)
Section Context.
Inductive WhichChild := left | right.
Definition map_children A B (spec : A -> B) (a : WhichChild -> A) (w : WhichChild) := spec (a w).
Inductive NodeMeaning C :=
| or (cs:WhichChild -> C)
| branch (cs:WhichChild -> C).
Class CState C := {
cs_meaning : C -> NodeMeaning C
}.
Inductive Context := c_cons {
c_S : Type;
c_CS :: CState c_S;
c_root : c_S;
}.
Global Arguments c_cons {c_S} {c_CS} c_root.
Definition c_meaning (c : Context) : NodeMeaning Context :=
let (S,CS,root) := c in
match cs_meaning root with
| or cs => or (map_children c_cons cs)
| branch cs => branch (map_children c_cons cs)
end.
Instance Context_CS S {CS : CState S} : CState Context := {| cs_meaning := c_meaning |}.
CoInductive Specializes (spec : Context -> Context) : NodeMeaning Context -> NodeMeaning Context -> Prop :=
| spec_to_or b cs : (∀ w, Specializes spec b (c_meaning (cs w))) -> Specializes spec b (or cs)
| spec_or_to bs c w : Specializes spec (c_meaning (bs w)) c -> Specializes spec (or bs) c
| spec_branch_to_branch bs cs : (∀ w, spec (bs w) = (cs w)) -> Specializes spec (branch bs) (branch cs)
.
Inductive CImplies a b :=
| cimp spec : Specializes spec (c_meaning a) (c_meaning b) -> CImplies a b.
Section Properties.
Lemma imp_refl a : CImplies a a.
change (CImplies a (id a)).
apply cimp.
apply id_vs; assumption.
Qed.
Instance id_vs : ValidSpecialization id.
constructor.
econstructor; [eassumption|reflexivity].
Qed.
Definition compose {A B C} (g : B -> C) (f : A -> B) := λ x, g (f x).
Instance vs_trans spec1 spec2 : ValidSpecialization spec1 -> ValidSpecialization spec2 -> ValidSpecialization (compose spec2 spec1).
constructor.
intros.
apply H0 in H1.
destruct H1.
apply H in H1.
destruct H1.
econstructor; [eassumption|].
intros. unfold compose. rewrite -> H3. rewrite -> H2. reflexivity.
Qed.
Lemma imp_refl a : CImplies a a.
change (CImplies a (id a)).
apply cimp.
apply id_vs; assumption.
Qed.
Lemma imp_trans a b c : CImplies a b -> CImplies b c -> CImplies a c.
destruct 1 as (spec1, V1).
destruct 1 as (spec2, V2).
change (spec2 (spec1 a)) with (compose spec2 spec1 a).
apply cimp.
apply vs_trans; assumption.
Qed.
End Properties.
End Context.
(****************************************************
Concrete ContextSets
****************************************************)
Section ConcreteCSes.
Inductive CsNull := cs_null.
Instance CsNull_CS : CState CsNull := {| CsMayBeBranch := λ c cs, False |}.
Definition c_null : Context := c_cons cs_null.
(* Inductive CsAny :=
cs_any (T:Type) (t:T).
Instance CsAny_CS : CState CsAny := {| CsMayBeBranch := λ c cs, True |}.
Definition c_any : Context := c_cons (cs_any tt). *)
Inductive CsAny :=
cs_any_at (l : list WhichChild).
Inductive CsAny_MayBeBranch : CsAny -> (WhichChild -> CsAny) -> Prop :=
| cambb l : CsAny_MayBeBranch (cs_any_at l) (λ w, (cs_any_at (w::l))).
Instance CsAny_CS : CState CsAny := {| CsMayBeBranch := λ c cs, False |}.
Definition c_any : Context := c_cons (cs_any_at nil).
Section Properties.
Definition const {A B} (a : A) (b : B) := a.
Lemma imp_null a : CImplies a c_null.
change (CImplies a (const c_null a)).
apply cimp.
constructor; intros.
unfold const in H.
dependent destruction H.
destruct H.
Qed.
Lemma imp_any a : CImplies c_any a.
(* augh! You'd have to exhibit a surjective mapping from any into the other context... which you can't because I didn't claim that anything here is decidable. *)
Qed.
End Properties.
End ConcreteCSes.