Repository navigation
Expand file tree
/
Copy pathfolStringScript.sml
More file actions
284 lines (247 loc) · 7 KB
/
Copy pathfolStringScript.sml
File metadata and controls
284 lines (247 loc) · 7 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
open HolKernel boolLib Parse bossLib pred_setTheory combinTheory stringTheory string_numTheory listTheory nlistTheory folLangTheory folModelsTheory;
val _ = new_theory "folString";
Datatype:
sterm = SV string | SFn string (sterm list)
End
Datatype:
sform = SFalse
| STrue
| SPred string (sterm list)
| SNot sform
| SAnd sform sform
| SOr sform sform
| SImp sform sform
| SIff sform sform
| SForall string sform
| SExists string sform
End
Datatype:
smodel =
<| SDom : 'a set ; SFun : string -> 'a list -> 'a ;
SPred : string -> 'a list -> bool |>
End
val sterm_size_def = DB.fetch "-" "sterm_size_def";
val _ = export_rewrites ["sterm_size_def"];
val smodel_component_equality = DB.fetch "-" "smodel_component_equality";
Theorem sterm_size_lemma[simp]:
!x l a. MEM a l ==> sterm_size a < 1 + (x + sterm1_size l)
Proof
rpt gen_tac >> Induct_on `l` >> simp[] >> rpt strip_tac >> simp [] >>
res_tac >> simp []
QED
Theorem sterm_induct:
!P. (!v. P (SV v)) /\ (!n ts. (!t. MEM t ts ==> P t) ==> P (SFn n ts)) ==> !t. P t
Proof
rpt strip_tac >>
qspecl_then [`P`, `\ts. !t. MEM t ts ==> P t`]
(assume_tac o SIMP_RULE bool_ss [])
(TypeBase.induction_of ``:sterm``) >> rfs[] >>
fs[DISJ_IMP_THM, FORALL_AND_THM]
QED
val _ = TypeBase.update_induction sterm_induct;
Definition stermval[simp]:
(stermval M v (SV x) = v x)
/\
(stermval M v (SFn f l) = M.SFun f (MAP (stermval M v) l))
Termination
WF_REL_TAC `measure (sterm_size o SND o SND)` >> simp []
End
Definition sholds:
(sholds M v SFalse = F)
/\
(sholds M v STrue = T)
/\
(sholds M v (SPred s l) = M.SPred s (MAP (stermval M v) l))
/\
(sholds M v (SNot sf) = (~ sholds M v sf))
/\
(sholds M v (SAnd sf1 sf2) = (sholds M v sf1 /\ sholds M v sf2))
/\
(sholds M v (SOr sf1 sf2) = (sholds M v sf1 \/ sholds M v sf2))
/\
(sholds M v (SImp sf1 sf2) = (sholds M v sf1 ==> sholds M v sf2))
/\
(sholds M v (SIff sf1 sf2) = (sholds M v sf1 <=> sholds M v sf2))
/\
(sholds M v (SForall s sf) = !a. a IN M.SDom ==> sholds M ((s =+ a)v) sf)
/\
(sholds M v (SExists s sf) = ?a. a IN M.SDom /\ sholds M ((s =+ a)v) sf)
End
(* ----------------------- *)
(* string-num translations *)
(* ----------------------- *)
Definition sterm2term:
(sterm2term (SV s) = V (s2n s))
/\
(sterm2term (SFn s stl) = Fn (s2n s) (MAP sterm2term stl))
Termination
WF_REL_TAC `measure sterm_size` >> simp []
End
Definition term2sterm:
(term2sterm (V n) = SV (n2s n))
/\
(term2sterm (Fn n tl) = SFn (n2s n) (MAP term2sterm tl))
Termination
WF_REL_TAC `measure term_size` >> simp []
End
Definition sform2form:
(sform2form SFalse = False)
/\
(sform2form STrue = True)
/\
(sform2form (SPred s stl) = Pred (s2n s) (MAP sterm2term stl))
/\
(sform2form (SNot sf) = Not (sform2form sf))
/\
(sform2form (SAnd sf1 sf2) = And (sform2form sf1) (sform2form sf2))
/\
(sform2form (SOr sf1 sf2) = Or (sform2form sf1) (sform2form sf2))
/\
(sform2form (SImp sf1 sf2) = IMP (sform2form sf1) (sform2form sf2))
/\
(sform2form (SIff sf1 sf2) = Iff (sform2form sf1) (sform2form sf2))
/\
(sform2form (SForall s sf) = FALL (s2n s) (sform2form sf))
/\
(sform2form (SExists s sf) = Exists (s2n s) (sform2form sf))
End
Definition form2sform:
(form2sform False = SFalse)
/\
(form2sform (Pred n tl) = SPred (n2s n) (MAP term2sterm tl))
/\
(form2sform (IMP f1 f2) = SImp (form2sform f1) (form2sform f2))
/\
(form2sform (FALL n f) = SForall (n2s n) (form2sform f))
End
Definition smodel2model:
smodel2model M =
<| Dom := M.SDom ; Fun := M.SFun o n2s ; Pred := M.SPred o n2s |>
End
Definition model2smodel:
model2smodel M =
<| SDom := M.Dom ; SFun := M.Fun o s2n ; SPred := M.Pred o s2n |>
End
(* --------------- *)
(* utility results *)
(* --------------- *)
Theorem MEM_MAP_all:
!f g h l.
(!a. MEM a l ==> f a = g (h a)) ==>
MAP (\b. f b) l = MAP (\c. g c) (MAP (\d. h d) l)
Proof
strip_tac >> strip_tac >> strip_tac >>
Induct_on `l` >> rw []
QED
Theorem UPDATE_n2s_s2n_eq:
!s a v. (((s =+ a)v) o n2s) = (((s2n s) =+ a)(v o n2s))
Proof
rw [] >>
match_mp_tac EQ_EXT >>
rw [APPLY_UPDATE_THM] >-
fs [s2n_n2s] >>
fs [n2s_s2n]
QED
Theorem UPDATE_s2n_n2s_eq:
!n a v. (((n =+ a)v) o s2n) = (((n2s n) =+ a)(v o s2n))
Proof
rw [] >>
match_mp_tac EQ_EXT >>
rw [APPLY_UPDATE_THM] >-
fs [n2s_s2n] >>
fs [s2n_n2s]
QED
(* ----------------- *)
(* semantic mappings *)
(* ----------------- *)
Theorem sterm2term_term2sterm:
!t. sterm2term (term2sterm t) = t
Proof
ho_match_mp_tac term_induct >> rw [sterm2term,term2sterm] >>
Induct_on `ts` >> fs [] >> rw []
QED
Theorem term2term_sterm2sterm:
!st. term2sterm (sterm2term st) = st
Proof
ho_match_mp_tac sterm_induct >> rw [sterm2term,term2sterm] >>
Induct_on `ts` >> fs [] >> rw []
QED
Theorem sform2form_form2sform:
!f. sform2form (form2sform f) = f
Proof
Induct_on `f` >> rw [sform2form,form2sform] >>
Induct_on `l` >> fs [] >> rw [sterm2term_term2sterm]
QED
Theorem smodel2model_model2smodel:
!M. smodel2model (model2smodel M) = M
Proof
rw [smodel2model,model2smodel,model_component_equality] >>
match_mp_tac EQ_EXT >> rw []
QED
Theorem model2smodel_smodel2model:
!M. model2smodel (smodel2model M) = M
Proof
rw [smodel2model,model2smodel,smodel_component_equality] >>
match_mp_tac EQ_EXT >> rw []
QED
Theorem holds_n2s_n2s:
!M f v a s0.
holds M (((s0 =+ a)v) o n2s) f <=> holds M (((s2n s0) =+ a)(v o n2s)) f
Proof
rw [UPDATE_n2s_s2n_eq]
QED
Theorem sholds_s2n_s2n:
!M sf v a n.
sholds M (((n =+ a)v) o s2n) sf <=> sholds M (((n2s n) =+ a)(v o s2n)) sf
Proof
rw [UPDATE_s2n_n2s_eq]
QED
Theorem stermval_termval:
!M v st.
stermval M v st = termval (smodel2model M) (v o n2s) (sterm2term st)
Proof
strip_tac >> strip_tac >>
ho_match_mp_tac sterm_induct >>
rw [stermval,termval_def,smodel2model,sterm2term] >>
METIS_TAC [MEM_MAP_all]
QED
(* FIXME: better proof using equalities likely possible *)
Theorem termval_stermval:
!M v t.
termval M v t = stermval (model2smodel M) (v o s2n) (term2sterm t)
Proof
strip_tac >> strip_tac >>
ho_match_mp_tac term_induct >>
rw [stermval,termval_def,model2smodel,term2sterm] >>
METIS_TAC [MEM_MAP_all]
QED
Theorem map_stermval_termval:
!M v l.
MAP (stermval M v) l = MAP (termval (smodel2model M) (v o n2s)) (MAP sterm2term l)
Proof
strip_tac >> strip_tac >> Induct_on `l` >> rw [stermval_termval]
QED
Theorem map_termval_stermval:
!M v l.
MAP (termval M v) l = MAP (stermval (model2smodel M) (v o s2n)) (MAP term2sterm l)
Proof
strip_tac >> strip_tac >> Induct_on `l` >> rw [termval_stermval]
QED
Theorem sholds_holds:
!M v sf. sholds M v sf <=> holds (smodel2model M) (v o n2s) (sform2form sf)
Proof
Induct_on `sf` >> rw [sholds,holds_def,sform2form] >| [
rw [smodel2model,map_stermval_termval],
EQ_TAC >> rw [smodel2model] >> METIS_TAC [holds_n2s_n2s],
EQ_TAC >> rw [smodel2model] >> METIS_TAC [holds_n2s_n2s]
]
QED
Theorem holds_sholds:
!M v f. holds M v f <=> sholds (model2smodel M) (v o s2n) (form2sform f)
Proof
Induct_on `f` >> rw [sholds,holds_def,form2sform] >| [
rw [model2smodel,map_termval_stermval],
EQ_TAC >> rw [model2smodel] >> METIS_TAC [sholds_s2n_s2n]
]
QED
val _ = export_theory ();