-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLm_Lemmas.v
190 lines (159 loc) · 6.34 KB
/
Lm_Lemmas.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
182
183
184
185
186
187
188
189
190
(** Administrative lemmas for Fsub.
Authors: Edward Lee, Ondrej Lhotak
Authors: Brian Aydemir and Arthur Chargu\'eraud, with help from
Aaron Bohannon, Jeffrey Vaughan, and Dimitrios Vytiniotis.
This file contains a number of administrative lemmas that we
require for proving type-safety. The lemmas mainly concern the
relations [wf_typ] and [wf_env].
This file also contains regularity lemmas, which show that various
relations hold only for locally closed terms. In addition to
being necessary to complete the proof of type-safety, these lemmas
help demonstrate that our definitions are correct; they would be
worth proving even if they are unneeded for any "real" proofs.
Table of contents:
- #<a href="##typp">Properties of type</a>#
- #<a href="##wft">Properties of wf_typ</a>#
- #<a href="##oktwft">Properties of wf_env and wf_typ</a>#
- #<a href="##okt">Properties of wf_env</a>#
- #<a href="##subst">Properties of substitution</a>#
- #<a href="##regularity">Regularity lemmas</a>#
- #<a href="##auto">Automation</a># *)
Require Export Fsub.Lm_Infrastructure.
(* ********************************************************************** *)
(** * #<a name="oktwft"></a># Properties of [wf_env], [wf_sig], and [wf_typ] *)
Lemma uniq_from_wf_env : forall E,
wf_env E ->
uniq E.
Proof.
intros E H; induction H; auto.
Qed.
Lemma uniq_from_wf_sig : forall E R,
wf_sig E R ->
Signatures.uniq R.
Proof.
intros E R H; induction H; auto.
Qed.
(** We add [uniq_from_wf_env] as a hint here since it helps blur the
distinction between [wf_env] and [uniq] in proofs. The lemmas in
the MetatheoryEnv library use [uniq], whereas here we naturally
have (or can easily show) the stronger [wf_env]. Thus,
[uniq_from_wf_env] serves as a bridge that allows us to use the
environments library. *)
#[export] Hint Resolve uniq_from_wf_env : core.
#[export] Hint Resolve uniq_from_wf_sig : core.
(* ********************************************************************** *)
(** * #<a name="regularity"></a># Regularity of relations *)
Lemma value_regular : forall e,
value e ->
expr e
with value_record_regular : forall r,
value_record_comp r ->
record_comp r.
Proof.
------
clear value_regular.
intros e H. induction H; auto.
------
clear value_record_regular.
intros r H. induction H; auto.
Qed.
Lemma well_formed_store_add : forall l v s,
well_formed_store s ->
value v ->
well_formed_store (LabelMapImpl.add l v s).
Proof with eauto.
intros * WfS Value l' v' MapsTo.
destruct (l' == l); subst.
- eapply LabelMapFacts.add_mapsto_iff in MapsTo; intuition; subst...
- eapply LabelMapFacts.add_mapsto_iff in MapsTo; intuition; subst...
Qed.
#[export] Hint Resolve well_formed_store_add : core.
Lemma red_regular : forall e s e' s',
red e s e' s' ->
expr e /\ well_formed_store s /\ expr e' /\ well_formed_store s'
with red_record_comp_regular : forall r s r' s',
red_record_comp r s r' s' ->
record_comp r /\ well_formed_store s /\ record_comp r' /\ well_formed_store s'.
Proof with try solve [auto | intuition auto].
------
clear red_regular.
intros e s e' s' H.
induction H; assert(J := value_regular)...
Case "red_abs".
split... split... inversion H0. pick fresh y. rewrite (subst_ee_intro y)...
Case "red_record".
destruct (red_record_comp_regular _ _ _ _ H)...
------
clear red_record_comp_regular.
intros r s r' s' H.
induction H; assert(J := value_regular)...
Case "red_record_exp_1".
destruct (red_regular _ _ _ _ H0)...
Qed.
Lemma expr_multistep : forall e s e' s',
redm e s e' s' ->
expr e ->
expr e'.
Proof with eauto.
intros * Red Expr.
induction Red; subst...
edestruct (red_regular _ _ _ _ H); intuition.
Qed.
Lemma well_formed_store_multistep : forall e s e' s',
redm e s e' s' ->
well_formed_store s ->
well_formed_store s'.
Proof with eauto.
intros * Red Expr.
induction Red; subst...
edestruct (red_regular _ _ _ _ H); intuition.
Qed.
Lemma wf_sig_regular : forall E R,
wf_sig E R ->
wf_env E.
Proof with eauto.
intros. induction H...
Qed.
(* *********************************************************************** *)
(** * #<a name="auto"></a># Automation *)
(** The lemma [uniq_from_wf_env] was already added above as a hint
since it helps blur the distinction between [wf_env] and [uniq] in
proofs.
As currently stated, the regularity lemmas are ill-suited to be
used with [auto] and [eauto] since they end in conjunctions. Even
if we were, for example, to split [sub_regularity] into three
separate lemmas, the resulting lemmas would be usable only by
[eauto] and there is no guarantee that [eauto] would be able to
find proofs effectively. Thus, the hints below apply the
regularity lemmas and [type_from_wf_typ] to discharge goals about
local closure and well-formedness, but in such a way as to
minimize proof search.
The first hint introduces an [wf_env] fact into the context. It
works well when combined with the lemmas relating [wf_env] and
[wf_typ]. We choose to use those lemmas explicitly via [(auto
using ...)] tactics rather than add them as hints. When used this
way, the explicitness makes the proof more informative rather than
more cluttered (with useless details).
The other three hints try outright to solve their respective
goals. *)
(* wf_env /\ wf_sig /\ expr /\ wf_typ *)
#[export] Hint Extern 1 (wf_env ?E) =>
match goal with
| H: wf_sig _ _ |- _ => apply (wf_sig_regular _ _ H)
end : core.
#[export] Hint Extern 1 (expr ?e) =>
match goal with
| H: red ?e _ _ _ |- _ => apply (proj1 (red_regular _ _ _ _ H))
| H: red _ _ ?e _ |- _ => apply (proj1 (proj2 (proj2 (red_regular _ _ _ _ H))))
end : core.
#[export] Hint Extern 1 (well_formed_store ?s) =>
match goal with
| H: red _ ?s _ _ |- _ => apply (proj1 (proj2 (red_regular _ _ _ _ H)))
| H: red _ _ _ ?s |- _ => apply (proj2 (proj2 (proj2 (red_regular _ _ _ _ H))))
end : core.
#[export] Hint Extern 1 (record_comp ?e) =>
match goal with
| H: red_record_comp ?e _ _ _ |- _ => apply (proj1 (red_record_comp_regular _ _ _ _ H))
| H: red_record_comp _ _ ?e _ |- _ => apply (proj1 (proj2 (proj2 (red_record_comp_regular _ _ _ _ H))))
end : core.
#[export] Hint Resolve value_regular value_record_regular expr_multistep well_formed_store_multistep : core.