author | Christian Urban <urbanc@in.tum.de> |
Wed, 23 Jun 2010 06:54:48 +0100 | |
changeset 2324 | 9038c9549073 |
parent 2323 | 99706604c573 |
child 2336 | f2d545b77b31 |
permissions | -rw-r--r-- |
1941 | 1 |
theory NewParser |
1971
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents:
1970
diff
changeset
|
2 |
imports "../Nominal-General/Nominal2_Base" |
1941 | 3 |
"../Nominal-General/Nominal2_Eqvt" |
4 |
"../Nominal-General/Nominal2_Supp" |
|
2324
9038c9549073
deleted compose-lemmas in Abs (not needed anymore)
Christian Urban <urbanc@in.tum.de>
parents:
2323
diff
changeset
|
5 |
"Perm" "Tacs" "Lift" "Equivp" |
1941 | 6 |
begin |
7 |
||
2314 | 8 |
(* TODO |
9 |
||
10 |
we need to also export a cases-rule for nominal datatypes |
|
11 |
size function |
|
12 |
*) |
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
2146
diff
changeset
|
13 |
|
1941 | 14 |
section{* Interface for nominal_datatype *} |
15 |
||
16 |
||
17 |
ML {* |
|
18 |
(* nominal datatype parser *) |
|
19 |
local |
|
2168 | 20 |
structure P = Parse; |
1941 | 21 |
structure S = Scan |
22 |
||
23 |
fun triple1 ((x, y), z) = (x, y, z) |
|
24 |
fun triple2 (x, (y, z)) = (x, y, z) |
|
25 |
fun tuple ((x, y, z), u) = (x, y, z, u) |
|
26 |
fun tswap (((x, y), z), u) = (x, y, u, z) |
|
27 |
in |
|
28 |
||
2168 | 29 |
val _ = Keyword.keyword "bind" |
30 |
val _ = Keyword.keyword "bind_set" |
|
31 |
val _ = Keyword.keyword "bind_res" |
|
1941 | 32 |
|
1943 | 33 |
val anno_typ = S.option (P.name --| P.$$$ "::") -- P.typ |
1941 | 34 |
|
35 |
val bind_mode = P.$$$ "bind" || P.$$$ "bind_set" || P.$$$ "bind_res" |
|
36 |
||
37 |
val bind_clauses = |
|
38 |
P.enum "," (bind_mode -- S.repeat1 P.term -- (P.$$$ "in" |-- S.repeat1 P.name) >> triple1) |
|
39 |
||
40 |
val cnstr_parser = |
|
1943 | 41 |
P.binding -- S.repeat anno_typ -- bind_clauses -- P.opt_mixfix >> tswap |
1941 | 42 |
|
43 |
(* datatype parser *) |
|
44 |
val dt_parser = |
|
45 |
(P.type_args -- P.binding -- P.opt_mixfix >> triple1) -- |
|
1943 | 46 |
(P.$$$ "=" |-- P.enum1 "|" cnstr_parser) >> tuple |
1941 | 47 |
|
48 |
(* binding function parser *) |
|
49 |
val bnfun_parser = |
|
2168 | 50 |
S.optional (P.$$$ "binder" |-- P.fixes -- Parse_Spec.where_alt_specs) ([], []) |
1941 | 51 |
|
52 |
(* main parser *) |
|
53 |
val main_parser = |
|
1944 | 54 |
P.and_list1 dt_parser -- bnfun_parser >> triple2 |
1941 | 55 |
|
56 |
end |
|
57 |
*} |
|
58 |
||
59 |
ML {* |
|
60 |
fun get_cnstrs dts = |
|
61 |
map (fn (_, _, _, constrs) => constrs) dts |
|
62 |
||
63 |
fun get_typed_cnstrs dts = |
|
64 |
flat (map (fn (_, bn, _, constrs) => |
|
65 |
(map (fn (bn', _, _) => (Binding.name_of bn, Binding.name_of bn')) constrs)) dts) |
|
66 |
||
67 |
fun get_cnstr_strs dts = |
|
68 |
map (fn (bn, _, _) => Binding.name_of bn) (flat (get_cnstrs dts)) |
|
69 |
||
70 |
fun get_bn_fun_strs bn_funs = |
|
71 |
map (fn (bn_fun, _, _) => Binding.name_of bn_fun) bn_funs |
|
72 |
*} |
|
73 |
||
2106
409ecb7284dd
properly exported defined bn-functions
Christian Urban <urbanc@in.tum.de>
parents:
2105
diff
changeset
|
74 |
|
1941 | 75 |
ML {* |
2143
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2142
diff
changeset
|
76 |
(* exports back the results *) |
1941 | 77 |
fun add_primrec_wrapper funs eqs lthy = |
2143
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2142
diff
changeset
|
78 |
if null funs then ([], [], lthy) |
1941 | 79 |
else |
80 |
let |
|
81 |
val eqs' = map (fn (_, eq) => (Attrib.empty_binding, eq)) eqs |
|
82 |
val funs' = map (fn (bn, ty, mx) => (bn, SOME ty, mx)) funs |
|
2106
409ecb7284dd
properly exported defined bn-functions
Christian Urban <urbanc@in.tum.de>
parents:
2105
diff
changeset
|
83 |
val ((funs'', eqs''), lthy') = Primrec.add_primrec funs' eqs' lthy |
409ecb7284dd
properly exported defined bn-functions
Christian Urban <urbanc@in.tum.de>
parents:
2105
diff
changeset
|
84 |
val phi = ProofContext.export_morphism lthy' lthy |
1941 | 85 |
in |
2143
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2142
diff
changeset
|
86 |
(map (Morphism.term phi) funs'', map (Morphism.thm phi) eqs'', lthy') |
1941 | 87 |
end |
88 |
*} |
|
89 |
||
90 |
ML {* |
|
91 |
fun add_datatype_wrapper dt_names dts = |
|
92 |
let |
|
93 |
val conf = Datatype.default_config |
|
94 |
in |
|
95 |
Local_Theory.theory_result (Datatype.add_datatype conf dt_names dts) |
|
96 |
end |
|
97 |
*} |
|
98 |
||
1944 | 99 |
|
100 |
text {* Infrastructure for adding "_raw" to types and terms *} |
|
101 |
||
1941 | 102 |
ML {* |
103 |
fun add_raw s = s ^ "_raw" |
|
104 |
fun add_raws ss = map add_raw ss |
|
105 |
fun raw_bind bn = Binding.suffix_name "_raw" bn |
|
106 |
||
107 |
fun replace_str ss s = |
|
108 |
case (AList.lookup (op=) ss s) of |
|
109 |
SOME s' => s' |
|
110 |
| NONE => s |
|
111 |
||
112 |
fun replace_typ ty_ss (Type (a, Ts)) = Type (replace_str ty_ss a, map (replace_typ ty_ss) Ts) |
|
113 |
| replace_typ ty_ss T = T |
|
114 |
||
115 |
fun raw_dts ty_ss dts = |
|
116 |
let |
|
117 |
fun raw_dts_aux1 (bind, tys, mx) = |
|
118 |
(raw_bind bind, map (replace_typ ty_ss) tys, mx) |
|
119 |
||
120 |
fun raw_dts_aux2 (ty_args, bind, mx, constrs) = |
|
121 |
(ty_args, raw_bind bind, mx, map raw_dts_aux1 constrs) |
|
122 |
in |
|
123 |
map raw_dts_aux2 dts |
|
124 |
end |
|
125 |
||
126 |
fun replace_aterm trm_ss (Const (a, T)) = Const (replace_str trm_ss a, T) |
|
127 |
| replace_aterm trm_ss (Free (a, T)) = Free (replace_str trm_ss a, T) |
|
128 |
| replace_aterm trm_ss trm = trm |
|
129 |
||
130 |
fun replace_term trm_ss ty_ss trm = |
|
131 |
trm |> Term.map_aterms (replace_aterm trm_ss) |> map_types (replace_typ ty_ss) |
|
132 |
*} |
|
133 |
||
134 |
ML {* |
|
135 |
fun rawify_dts dt_names dts dts_env = |
|
136 |
let |
|
137 |
val raw_dts = raw_dts dts_env dts |
|
138 |
val raw_dt_names = add_raws dt_names |
|
139 |
in |
|
140 |
(raw_dt_names, raw_dts) |
|
141 |
end |
|
142 |
*} |
|
143 |
||
144 |
ML {* |
|
145 |
fun rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs = |
|
146 |
let |
|
147 |
val bn_funs' = map (fn (bn, ty, mx) => |
|
2304
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
148 |
(raw_bind bn, SOME (replace_typ dts_env ty), mx)) bn_funs |
1941 | 149 |
|
150 |
val bn_eqs' = map (fn (attr, trm) => |
|
151 |
(attr, replace_term (cnstrs_env @ bn_fun_env) dts_env trm)) bn_eqs |
|
152 |
in |
|
153 |
(bn_funs', bn_eqs') |
|
154 |
end |
|
155 |
*} |
|
156 |
||
157 |
ML {* |
|
158 |
fun rawify_bclauses dts_env cnstrs_env bn_fun_env bclauses = |
|
159 |
let |
|
160 |
fun rawify_bnds bnds = |
|
161 |
map (apfst (Option.map (replace_term (cnstrs_env @ bn_fun_env) dts_env))) bnds |
|
162 |
||
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
2146
diff
changeset
|
163 |
fun rawify_bclause (BC (mode, bnds, bdys)) = BC (mode, rawify_bnds bnds, bdys) |
1941 | 164 |
in |
165 |
map (map (map rawify_bclause)) bclauses |
|
166 |
end |
|
167 |
*} |
|
168 |
||
2143
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2142
diff
changeset
|
169 |
(* strip_bn_fun takes a rhs of a bn function: this can only contain unions or |
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2142
diff
changeset
|
170 |
appends of elements; in case of recursive calls it retruns also the applied |
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2142
diff
changeset
|
171 |
bn function *) |
1941 | 172 |
ML {* |
2294
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
173 |
fun strip_bn_fun lthy args t = |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
174 |
let |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
175 |
fun aux t = |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
176 |
case t of |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
177 |
Const (@{const_name sup}, _) $ l $ r => aux l @ aux r |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
178 |
| Const (@{const_name append}, _) $ l $ r => aux l @ aux r |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
179 |
| Const (@{const_name insert}, _) $ (Const (@{const_name atom}, _) $ (x as Var _)) $ y => |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
180 |
(find_index (equal x) args, NONE) :: aux y |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
181 |
| Const (@{const_name Cons}, _) $ (Const (@{const_name atom}, _) $ (x as Var _)) $ y => |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
182 |
(find_index (equal x) args, NONE) :: aux y |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
183 |
| Const (@{const_name bot}, _) => [] |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
184 |
| Const (@{const_name Nil}, _) => [] |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
185 |
| (f as Const _) $ (x as Var _) => [(find_index (equal x) args, SOME f)] |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
186 |
| _ => error ("Unsupported binding function: " ^ (Syntax.string_of_term lthy t)) |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
187 |
in |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
188 |
aux t |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
189 |
end |
1941 | 190 |
*} |
191 |
||
192 |
ML {* |
|
193 |
fun find [] _ = error ("cannot find element") |
|
194 |
| find ((x, z)::xs) y = if (Long_Name.base_name x) = y then z else find xs y |
|
195 |
*} |
|
196 |
||
197 |
ML {* |
|
2295
8aff3f3ce47f
started to work on alpha
Christian Urban <urbanc@in.tum.de>
parents:
2294
diff
changeset
|
198 |
fun prep_bn_info lthy dt_names dts eqs = |
1941 | 199 |
let |
200 |
fun aux eq = |
|
201 |
let |
|
202 |
val (lhs, rhs) = eq |
|
203 |
|> HOLogic.dest_Trueprop |
|
204 |
|> HOLogic.dest_eq |
|
205 |
val (bn_fun, [cnstr]) = strip_comb lhs |
|
2294
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
206 |
val (_, ty) = dest_Const bn_fun |
1941 | 207 |
val (ty_name, _) = dest_Type (domain_type ty) |
208 |
val dt_index = find_index (fn x => x = ty_name) dt_names |
|
2294
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
209 |
val (cnstr_head, cnstr_args) = strip_comb cnstr |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
210 |
val rhs_elements = strip_bn_fun lthy cnstr_args rhs |
1941 | 211 |
in |
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
212 |
(dt_index, (bn_fun, (cnstr_head, rhs_elements))) |
2122
24ca435ead14
added term4 back to the examples
Christian Urban <urbanc@in.tum.de>
parents:
2119
diff
changeset
|
213 |
end |
1941 | 214 |
fun order dts i ts = |
215 |
let |
|
216 |
val dt = nth dts i |
|
217 |
val cts = map (fn (x, _, _) => Binding.name_of x) ((fn (_, _, _, x) => x) dt) |
|
218 |
val ts' = map (fn (x, y) => (fst (dest_Const x), y)) ts |
|
219 |
in |
|
220 |
map (find ts') cts |
|
221 |
end |
|
222 |
||
223 |
val unordered = AList.group (op=) (map aux eqs) |
|
224 |
val unordered' = map (fn (x, y) => (x, AList.group (op=) y)) unordered |
|
225 |
val ordered = map (fn (x, y) => (x, map (fn (v, z) => (v, order dts x z)) y)) unordered' |
|
2118
0e52851acac4
moved the data-transformation into the parser
Christian Urban <urbanc@in.tum.de>
parents:
2107
diff
changeset
|
226 |
val ordered' = flat (map (fn (ith, l) => map (fn (bn, data) => (bn, ith, data)) l) ordered) |
2122
24ca435ead14
added term4 back to the examples
Christian Urban <urbanc@in.tum.de>
parents:
2119
diff
changeset
|
227 |
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
2146
diff
changeset
|
228 |
(*val _ = tracing ("eqs\n" ^ cat_lines (map (Syntax.string_of_term lthy) eqs))*) |
2142
c39d4fe31100
moved the exporting part into the parser (this is still a hack); re-added CoreHaskell again to the examples - there seems to be a problem with the variable name pat
Christian Urban <urbanc@in.tum.de>
parents:
2125
diff
changeset
|
229 |
(*val _ = tracing ("map eqs\n" ^ @{make_string} (map aux2 eqs))*) |
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
2146
diff
changeset
|
230 |
(*val _ = tracing ("ordered'\n" ^ @{make_string} ordered')*) |
1941 | 231 |
in |
2125
60ee289a8c63
made out of STEPS a configuration value so that it can be set individually in each file
Christian Urban <urbanc@in.tum.de>
parents:
2122
diff
changeset
|
232 |
ordered' |
1941 | 233 |
end |
234 |
*} |
|
235 |
||
236 |
ML {* |
|
237 |
fun raw_nominal_decls dts bn_funs bn_eqs binds lthy = |
|
238 |
let |
|
239 |
val thy = ProofContext.theory_of lthy |
|
240 |
val thy_name = Context.theory_name thy |
|
241 |
||
242 |
val dt_names = map (fn (_, s, _, _) => Binding.name_of s) dts |
|
243 |
val dt_full_names = map (Long_Name.qualify thy_name) dt_names |
|
244 |
val dt_full_names' = add_raws dt_full_names |
|
245 |
val dts_env = dt_full_names ~~ dt_full_names' |
|
246 |
||
247 |
val cnstrs = get_cnstr_strs dts |
|
248 |
val cnstrs_ty = get_typed_cnstrs dts |
|
249 |
val cnstrs_full_names = map (Long_Name.qualify thy_name) cnstrs |
|
250 |
val cnstrs_full_names' = map (fn (x, y) => Long_Name.qualify thy_name |
|
251 |
(Long_Name.qualify (add_raw x) (add_raw y))) cnstrs_ty |
|
252 |
val cnstrs_env = cnstrs_full_names ~~ cnstrs_full_names' |
|
253 |
||
254 |
val bn_fun_strs = get_bn_fun_strs bn_funs |
|
255 |
val bn_fun_strs' = add_raws bn_fun_strs |
|
256 |
val bn_fun_env = bn_fun_strs ~~ bn_fun_strs' |
|
257 |
val bn_fun_full_env = map (pairself (Long_Name.qualify thy_name)) |
|
258 |
(bn_fun_strs ~~ bn_fun_strs') |
|
259 |
||
260 |
val (raw_dt_names, raw_dts) = rawify_dts dt_names dts dts_env |
|
261 |
val (raw_bn_funs, raw_bn_eqs) = rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs |
|
262 |
val raw_bclauses = rawify_bclauses dts_env cnstrs_env bn_fun_full_env binds |
|
263 |
||
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
264 |
val (raw_dt_full_names, lthy1) = |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
265 |
add_datatype_wrapper raw_dt_names raw_dts lthy |
2304
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
266 |
in |
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
267 |
(dt_full_names', raw_dt_full_names, raw_dts, raw_bclauses, raw_bn_funs, raw_bn_eqs, lthy1) |
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
268 |
end |
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
269 |
*} |
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
270 |
|
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
271 |
ML {* |
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
272 |
fun raw_bn_decls dt_names dts raw_bn_funs raw_bn_eqs constr_thms lthy = |
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
273 |
if null raw_bn_funs |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
274 |
then ([], [], [], [], lthy) |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
275 |
else |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
276 |
let |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
277 |
val (_, lthy1) = Function.add_function raw_bn_funs raw_bn_eqs |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
278 |
Function_Common.default_config (pat_completeness_simp constr_thms) lthy |
2304
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
279 |
|
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
280 |
val (info, lthy2) = prove_termination (Local_Theory.restore lthy1) |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
281 |
val {fs, simps, inducts, ...} = info; |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
282 |
|
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
283 |
val raw_bn_induct = (the inducts) |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
284 |
val raw_bn_eqs = the simps |
2142
c39d4fe31100
moved the exporting part into the parser (this is still a hack); re-added CoreHaskell again to the examples - there seems to be a problem with the variable name pat
Christian Urban <urbanc@in.tum.de>
parents:
2125
diff
changeset
|
285 |
|
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
286 |
val raw_bn_info = |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
287 |
prep_bn_info lthy dt_names dts (map prop_of raw_bn_eqs) |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
288 |
in |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
289 |
(fs, raw_bn_eqs, raw_bn_info, raw_bn_induct, lthy2) |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
290 |
end |
1941 | 291 |
*} |
292 |
||
2304
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
293 |
|
2017
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2016
diff
changeset
|
294 |
|
2023 | 295 |
ML {* val cheat_fv_rsp = Unsynchronized.ref false *} |
296 |
ML {* val cheat_alpha_bn_rsp = Unsynchronized.ref false *} |
|
297 |
ML {* val cheat_supp_eq = Unsynchronized.ref false *} |
|
2008
1bddffddc03f
attempted to remove dependency on (old) Fv and (old) Parser; lifting still uses Fv.thy; the examples do not work at the moment (with equivp proofs failing)
Christian Urban <urbanc@in.tum.de>
parents:
2007
diff
changeset
|
298 |
|
1bddffddc03f
attempted to remove dependency on (old) Fv and (old) Parser; lifting still uses Fv.thy; the examples do not work at the moment (with equivp proofs failing)
Christian Urban <urbanc@in.tum.de>
parents:
2007
diff
changeset
|
299 |
|
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
300 |
ML {* |
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
301 |
(* for testing porposes - to exit the procedure early *) |
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
302 |
exception TEST of Proof.context |
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
303 |
|
2125
60ee289a8c63
made out of STEPS a configuration value so that it can be set individually in each file
Christian Urban <urbanc@in.tum.de>
parents:
2122
diff
changeset
|
304 |
val (STEPS, STEPS_setup) = Attrib.config_int "STEPS" (K 10); |
60ee289a8c63
made out of STEPS a configuration value so that it can be set individually in each file
Christian Urban <urbanc@in.tum.de>
parents:
2122
diff
changeset
|
305 |
|
60ee289a8c63
made out of STEPS a configuration value so that it can be set individually in each file
Christian Urban <urbanc@in.tum.de>
parents:
2122
diff
changeset
|
306 |
fun get_STEPS ctxt = Config.get ctxt STEPS |
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
307 |
*} |
2008
1bddffddc03f
attempted to remove dependency on (old) Fv and (old) Parser; lifting still uses Fv.thy; the examples do not work at the moment (with equivp proofs failing)
Christian Urban <urbanc@in.tum.de>
parents:
2007
diff
changeset
|
308 |
|
2125
60ee289a8c63
made out of STEPS a configuration value so that it can be set individually in each file
Christian Urban <urbanc@in.tum.de>
parents:
2122
diff
changeset
|
309 |
setup STEPS_setup |
60ee289a8c63
made out of STEPS a configuration value so that it can be set individually in each file
Christian Urban <urbanc@in.tum.de>
parents:
2122
diff
changeset
|
310 |
|
1941 | 311 |
ML {* |
312 |
fun nominal_datatype2 dts bn_funs bn_eqs bclauses lthy = |
|
313 |
let |
|
2294
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
314 |
(* definition of the raw datatypes *) |
2316 | 315 |
val _ = warning "Definition of raw datatypes"; |
2304
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
316 |
val (dt_names, raw_dt_names, raw_dts, raw_bclauses, raw_bn_funs, raw_bn_eqs, lthy0) = |
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
317 |
if get_STEPS lthy > 0 |
2295
8aff3f3ce47f
started to work on alpha
Christian Urban <urbanc@in.tum.de>
parents:
2294
diff
changeset
|
318 |
then raw_nominal_decls dts bn_funs bn_eqs bclauses lthy |
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
319 |
else raise TEST lthy |
1941 | 320 |
|
2304
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
321 |
val dtinfo = Datatype.the_info (ProofContext.theory_of lthy0) (hd raw_dt_names) |
2143
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2142
diff
changeset
|
322 |
val {descr, sorts, ...} = dtinfo |
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2142
diff
changeset
|
323 |
val all_tys = map (fn (i, _) => nth_dtyp descr sorts i) descr |
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2142
diff
changeset
|
324 |
val all_full_tnames = map (fn (_, (n, _, _)) => n) descr |
2304
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
325 |
val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy0)) all_full_tnames |
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
326 |
|
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
327 |
val inject_thms = flat (map #inject dtinfos); |
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
328 |
val distinct_thms = flat (map #distinct dtinfos); |
2304
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
329 |
val constr_thms = inject_thms @ distinct_thms |
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
330 |
val rel_dtinfos = List.take (dtinfos, (length dts)); |
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
331 |
val raw_constrs_distinct = (map #distinct rel_dtinfos); |
2047
31ba33a199c7
fixed my error with define_raw_fv
Christian Urban <urbanc@in.tum.de>
parents:
2046
diff
changeset
|
332 |
val induct_thm = #induct dtinfo; |
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
333 |
val exhaust_thms = map #exhaust dtinfos; |
1999
4df3441aa0b4
more parser/new parser synchronization.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1996
diff
changeset
|
334 |
|
2008
1bddffddc03f
attempted to remove dependency on (old) Fv and (old) Parser; lifting still uses Fv.thy; the examples do not work at the moment (with equivp proofs failing)
Christian Urban <urbanc@in.tum.de>
parents:
2007
diff
changeset
|
335 |
(* definitions of raw permutations *) |
2316 | 336 |
val _ = warning "Definition of raw permutations"; |
2292 | 337 |
val ((raw_perm_funs, raw_perm_defs, raw_perm_simps), lthy2) = |
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
338 |
if get_STEPS lthy0 > 1 |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
339 |
then Local_Theory.theory_result (define_raw_perms descr sorts induct_thm (length dts)) lthy0 |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
340 |
else raise TEST lthy0 |
2144 | 341 |
|
342 |
(* noting the raw permutations as eqvt theorems *) |
|
343 |
val eqvt_attrib = Attrib.internal (K Nominal_ThmDecls.eqvt_add) |
|
344 |
val (_, lthy2a) = Local_Theory.note ((Binding.empty, [eqvt_attrib]), raw_perm_defs) lthy2 |
|
2143
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2142
diff
changeset
|
345 |
|
2105
e25b0fff0dd2
Include raw permutation definitions in eqvt
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2089
diff
changeset
|
346 |
val thy = Local_Theory.exit_global lthy2a; |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
347 |
val thy_name = Context.theory_name thy |
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2008
diff
changeset
|
348 |
|
2142
c39d4fe31100
moved the exporting part into the parser (this is still a hack); re-added CoreHaskell again to the examples - there seems to be a problem with the variable name pat
Christian Urban <urbanc@in.tum.de>
parents:
2125
diff
changeset
|
349 |
(* definition of raw fv_functions *) |
2316 | 350 |
val _ = warning "Definition of raw fv-functions"; |
1960
47e2e91705f3
Rewrote FV code and included the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1945
diff
changeset
|
351 |
val lthy3 = Theory_Target.init NONE thy; |
47e2e91705f3
Rewrote FV code and included the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1945
diff
changeset
|
352 |
|
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
353 |
val (raw_bn_funs, raw_bn_eqs, raw_bn_info, raw_bn_induct, lthy3a) = |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
354 |
if get_STEPS lthy3 > 2 |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
355 |
then raw_bn_decls dt_names raw_dts raw_bn_funs raw_bn_eqs constr_thms lthy3 |
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
356 |
else raise TEST lthy3 |
2292 | 357 |
|
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
358 |
val (raw_fvs, raw_fv_bns, raw_fv_defs, raw_fv_bns_induct, lthy3b) = |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
359 |
if get_STEPS lthy3a > 3 |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
360 |
then define_raw_fvs descr sorts raw_bn_info raw_bclauses constr_thms lthy3a |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
361 |
else raise TEST lthy3a |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
362 |
|
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2008
diff
changeset
|
363 |
(* definition of raw alphas *) |
2316 | 364 |
val _ = warning "Definition of alphas"; |
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
365 |
val (alpha_trms, alpha_bn_trms, alpha_intros, alpha_cases, alpha_induct, lthy4) = |
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
366 |
if get_STEPS lthy3b > 4 |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
367 |
then define_raw_alpha descr sorts raw_bn_info raw_bclauses raw_fvs lthy3b |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
368 |
else raise TEST lthy3b |
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
369 |
|
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
370 |
(* definition of alpha-distinct lemmas *) |
2316 | 371 |
val _ = warning "Distinct theorems"; |
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
372 |
val (alpha_distincts, alpha_bn_distincts) = |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
373 |
mk_alpha_distincts lthy4 alpha_cases raw_constrs_distinct alpha_trms alpha_bn_trms raw_bn_info |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
374 |
|
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2008
diff
changeset
|
375 |
(* definition of raw_alpha_eq_iff lemmas *) |
2316 | 376 |
val _ = warning "Eq-iff theorems"; |
2295
8aff3f3ce47f
started to work on alpha
Christian Urban <urbanc@in.tum.de>
parents:
2294
diff
changeset
|
377 |
val alpha_eq_iff = |
8aff3f3ce47f
started to work on alpha
Christian Urban <urbanc@in.tum.de>
parents:
2294
diff
changeset
|
378 |
if get_STEPS lthy > 5 |
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
379 |
then mk_alpha_eq_iff lthy4 alpha_intros distinct_thms inject_thms alpha_cases |
2295
8aff3f3ce47f
started to work on alpha
Christian Urban <urbanc@in.tum.de>
parents:
2294
diff
changeset
|
380 |
else raise TEST lthy4 |
2022
8ffede2c8ce9
Introduce eq_iff_simp to match the one from Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2020
diff
changeset
|
381 |
|
2298 | 382 |
(* proving equivariance lemmas for bns, fvs and alpha *) |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
383 |
val _ = warning "Proving equivariance"; |
2305
93ab397f5980
smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2304
diff
changeset
|
384 |
val bn_eqvt = |
2298 | 385 |
if get_STEPS lthy > 6 |
2305
93ab397f5980
smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2304
diff
changeset
|
386 |
then raw_prove_eqvt raw_bn_funs raw_bn_induct (raw_bn_eqs @ raw_perm_defs) lthy4 |
2298 | 387 |
else raise TEST lthy4 |
388 |
||
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
389 |
(* noting the bn_eqvt lemmas in a temprorary theory *) |
2305
93ab397f5980
smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2304
diff
changeset
|
390 |
val add_eqvt = Attrib.internal (K Nominal_ThmDecls.eqvt_add) |
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
391 |
val lthy_tmp = snd (Local_Theory.note ((Binding.empty, [add_eqvt]), bn_eqvt) lthy4) |
2305
93ab397f5980
smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2304
diff
changeset
|
392 |
|
93ab397f5980
smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2304
diff
changeset
|
393 |
val fv_eqvt = |
2298 | 394 |
if get_STEPS lthy > 7 |
2309
13f20fe02ff3
fixed problem with eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2308
diff
changeset
|
395 |
then raw_prove_eqvt (raw_fvs @ raw_fv_bns) raw_fv_bns_induct (raw_fv_defs @ raw_perm_defs) |
13f20fe02ff3
fixed problem with eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2308
diff
changeset
|
396 |
(Local_Theory.restore lthy_tmp) |
2305
93ab397f5980
smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2304
diff
changeset
|
397 |
else raise TEST lthy4 |
93ab397f5980
smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2304
diff
changeset
|
398 |
|
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
399 |
val lthy_tmp' = snd (Local_Theory.note ((Binding.empty, [add_eqvt]), fv_eqvt) lthy_tmp) |
2306 | 400 |
|
2311
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
401 |
val (alpha_eqvt, lthy_tmp'') = |
2298 | 402 |
if get_STEPS lthy > 8 |
2311
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
403 |
then Nominal_Eqvt.equivariance true (alpha_trms @ alpha_bn_trms) alpha_induct alpha_intros lthy_tmp' |
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
404 |
else raise TEST lthy4 |
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
405 |
|
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
406 |
(* proving alpha equivalence *) |
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
407 |
val _ = warning "Proving equivalence" |
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
408 |
|
2316 | 409 |
val alpha_refl_thms = |
410 |
if get_STEPS lthy > 9 |
|
411 |
then raw_prove_refl alpha_trms alpha_bn_trms alpha_intros induct_thm lthy_tmp'' |
|
412 |
else raise TEST lthy4 |
|
413 |
||
2311
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
414 |
val alpha_sym_thms = |
2316 | 415 |
if get_STEPS lthy > 10 |
2311
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
416 |
then raw_prove_sym (alpha_trms @ alpha_bn_trms) alpha_intros alpha_induct lthy_tmp'' |
2305
93ab397f5980
smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2304
diff
changeset
|
417 |
else raise TEST lthy4 |
2298 | 418 |
|
2311
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
419 |
val alpha_trans_thms = |
2316 | 420 |
if get_STEPS lthy > 11 |
2311
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
421 |
then raw_prove_trans (alpha_trms @ alpha_bn_trms) (distinct_thms @ inject_thms) |
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
422 |
alpha_intros alpha_induct alpha_cases lthy_tmp'' |
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
423 |
else raise TEST lthy4 |
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
424 |
|
2322
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
425 |
val alpha_equivp_thms = |
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
426 |
if get_STEPS lthy > 12 |
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
427 |
then raw_prove_equivp alpha_trms alpha_refl_thms alpha_sym_thms alpha_trans_thms lthy_tmp'' |
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
428 |
else raise TEST lthy4 |
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
429 |
|
2320
d835a2771608
prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents:
2316
diff
changeset
|
430 |
(* proving alpha implies alpha_bn *) |
d835a2771608
prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents:
2316
diff
changeset
|
431 |
val _ = warning "Proving alpha implies bn" |
d835a2771608
prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents:
2316
diff
changeset
|
432 |
|
d835a2771608
prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents:
2316
diff
changeset
|
433 |
val alpha_bn_imp_thms = |
2322
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
434 |
if get_STEPS lthy > 13 |
2320
d835a2771608
prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents:
2316
diff
changeset
|
435 |
then raw_prove_bn_imp alpha_trms alpha_bn_trms alpha_intros alpha_induct lthy_tmp'' |
d835a2771608
prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents:
2316
diff
changeset
|
436 |
else raise TEST lthy4 |
2322
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
437 |
|
2311
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
438 |
val _ = tracing ("alphas " ^ commas (map (Syntax.string_of_term lthy4) alpha_trms)) |
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
439 |
val _ = tracing ("alpha_bns " ^ commas (map (Syntax.string_of_term lthy4) alpha_bn_trms)) |
2316 | 440 |
val _ = tracing ("alpha_refl\n" ^ |
441 |
cat_lines (map (Syntax.string_of_term lthy4 o prop_of) alpha_refl_thms)) |
|
2320
d835a2771608
prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents:
2316
diff
changeset
|
442 |
val _ = tracing ("alpha_bn_imp\n" ^ |
d835a2771608
prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents:
2316
diff
changeset
|
443 |
cat_lines (map (Syntax.string_of_term lthy4 o prop_of) alpha_bn_imp_thms)) |
2322
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
444 |
val _ = tracing ("alpha_equivp\n" ^ |
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
445 |
cat_lines (map (Syntax.string_of_term lthy4 o prop_of) alpha_equivp_thms)) |
2311
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
446 |
|
2321
e9b0728061a8
cleaned up the FSet (noise was introduced by error)
Christian Urban <urbanc@in.tum.de>
parents:
2320
diff
changeset
|
447 |
(* old stuff *) |
2305
93ab397f5980
smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2304
diff
changeset
|
448 |
val _ = |
2322
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
449 |
if get_STEPS lthy > 14 |
2321
e9b0728061a8
cleaned up the FSet (noise was introduced by error)
Christian Urban <urbanc@in.tum.de>
parents:
2320
diff
changeset
|
450 |
then true else raise TEST lthy4 |
e9b0728061a8
cleaned up the FSet (noise was introduced by error)
Christian Urban <urbanc@in.tum.de>
parents:
2320
diff
changeset
|
451 |
|
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
452 |
val qty_binds = map (fn (_, b, _, _) => b) dts; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
453 |
val qty_names = map Name.of_binding qty_binds; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
454 |
val qty_full_names = map (Long_Name.qualify thy_name) qty_names |
2323 | 455 |
val (qtys, lthy7) = define_quotient_types qty_binds all_tys alpha_trms alpha_equivp_thms lthy4; |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
456 |
val const_names = map Name.of_binding (flat (map (fn (_, _, _, t) => map (fn (b, _, _) => b) t) dts)); |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
457 |
val raw_consts = |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
458 |
flat (map (fn (i, (_, _, l)) => |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
459 |
map (fn (cname, dts) => |
2016
1715dfe9406c
Fix Datatype_Aux calls in NewParser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2011
diff
changeset
|
460 |
Const (cname, map (Datatype_Aux.typ_of_dtyp descr sorts) dts ---> |
1715dfe9406c
Fix Datatype_Aux calls in NewParser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2011
diff
changeset
|
461 |
Datatype_Aux.typ_of_dtyp descr sorts (Datatype_Aux.DtRec i))) l) descr); |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
462 |
val (consts, const_defs, lthy8) = quotient_lift_consts_export qtys (const_names ~~ raw_consts) lthy7; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
463 |
val _ = warning "Proving respects"; |
2322
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
464 |
|
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
465 |
val bn_nos = map (fn (_, i, _) => i) raw_bn_info; |
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
466 |
val bns = raw_bn_funs ~~ bn_nos; |
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
467 |
|
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
468 |
val bns_rsp_pre' = build_fvbv_rsps alpha_trms alpha_induct raw_bn_eqs (map fst bns) lthy8; |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
469 |
val (bns_rsp_pre, lthy9) = fold_map ( |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
470 |
fn (bn_t, _) => prove_const_rsp qtys Binding.empty [bn_t] (fn _ => |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
471 |
resolve_tac bns_rsp_pre' 1)) bns lthy8; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
472 |
val bns_rsp = flat (map snd bns_rsp_pre); |
2017
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2016
diff
changeset
|
473 |
|
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2016
diff
changeset
|
474 |
fun fv_rsp_tac _ = if !cheat_fv_rsp then Skip_Proof.cheat_tac thy |
2296 | 475 |
else fvbv_rsp_tac alpha_induct raw_fv_defs lthy8 1; |
2322
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
476 |
|
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
477 |
val fv_alpha_all = combine_fv_alpha_bns (raw_fvs, raw_fv_bns) (alpha_trms, alpha_bn_trms) bn_nos |
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
478 |
|
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
479 |
val fv_rsps = prove_fv_rsp fv_alpha_all alpha_trms fv_rsp_tac lthy9; |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
480 |
val (fv_rsp_pre, lthy10) = fold_map |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
481 |
(fn fv => fn ctxt => prove_const_rsp qtys Binding.empty [fv] |
2296 | 482 |
(fn _ => asm_simp_tac (HOL_ss addsimps fv_rsps) 1) ctxt) (raw_fvs @ raw_fv_bns) lthy9; |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
483 |
val fv_rsp = flat (map snd fv_rsp_pre); |
2292 | 484 |
val (perms_rsp, lthy11) = prove_const_rsp qtys Binding.empty raw_perm_funs |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
485 |
(fn _ => asm_simp_tac (HOL_ss addsimps alpha_eqvt) 1) lthy10; |
2023 | 486 |
fun alpha_bn_rsp_tac _ = if !cheat_alpha_bn_rsp then Skip_Proof.cheat_tac thy |
487 |
else |
|
2323 | 488 |
let val alpha_bn_rsp_pre = prove_alpha_bn_rsp alpha_trms alpha_induct (alpha_eq_iff @ alpha_distincts @ alpha_bn_distincts) alpha_equivp_thms exhaust_thms alpha_bn_trms lthy11 in asm_simp_tac (HOL_ss addsimps alpha_bn_rsp_pre) 1 end; |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
489 |
val (alpha_bn_rsps, lthy11a) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst] |
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
490 |
alpha_bn_rsp_tac) alpha_bn_trms lthy11 |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
491 |
fun const_rsp_tac _ = |
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
492 |
let val alpha_alphabn = prove_alpha_alphabn alpha_trms alpha_induct alpha_eq_iff alpha_bn_trms lthy11a |
2322
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
493 |
in constr_rsp_tac alpha_eq_iff (fv_rsp @ bns_rsp @ alpha_refl_thms @ alpha_alphabn) 1 end |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
494 |
val (const_rsps, lthy12) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst] |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
495 |
const_rsp_tac) raw_consts lthy11a |
2296 | 496 |
val qfv_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) (raw_fvs @ raw_fv_bns) |
497 |
val (qfv_ts, qfv_defs, lthy12a) = quotient_lift_consts_export qtys (qfv_names ~~ (raw_fvs @ raw_fv_bns)) lthy12; |
|
2292 | 498 |
val (qfv_ts_nobn, qfv_ts_bn) = chop (length raw_perm_funs) qfv_ts; |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
499 |
val qbn_names = map (fn (b, _ , _) => Name.of_binding b) bn_funs |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
500 |
val (qbn_ts, qbn_defs, lthy12b) = quotient_lift_consts_export qtys (qbn_names ~~ raw_bn_funs) lthy12a; |
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
501 |
val qalpha_bn_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) alpha_bn_trms |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
502 |
val (qalpha_bn_trms, qalphabn_defs, lthy12c) = |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
503 |
quotient_lift_consts_export qtys (qalpha_bn_names ~~ alpha_bn_trms) lthy12b; |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
504 |
val _ = warning "Lifting permutations"; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
505 |
val thy = Local_Theory.exit_global lthy12c; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
506 |
val perm_names = map (fn x => "permute_" ^ x) qty_names |
2292 | 507 |
val thy' = define_lifted_perms qtys qty_full_names (perm_names ~~ raw_perm_funs) raw_perm_simps thy; |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
508 |
val lthy13 = Theory_Target.init NONE thy'; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
509 |
val q_name = space_implode "_" qty_names; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
510 |
fun suffix_bind s = Binding.qualify true q_name (Binding.name s); |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
511 |
val _ = warning "Lifting induction"; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
512 |
val constr_names = map (Long_Name.base_name o fst o dest_Const) consts; |
2047
31ba33a199c7
fixed my error with define_raw_fv
Christian Urban <urbanc@in.tum.de>
parents:
2046
diff
changeset
|
513 |
val q_induct = Rule_Cases.name constr_names (lift_thm qtys lthy13 induct_thm); |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
514 |
fun note_suffix s th ctxt = |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
515 |
snd (Local_Theory.note ((suffix_bind s, []), th) ctxt); |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
516 |
fun note_simp_suffix s th ctxt = |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
517 |
snd (Local_Theory.note ((suffix_bind s, [Attrib.internal (K Simplifier.simp_add)]), th) ctxt); |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
518 |
val (_, lthy14) = Local_Theory.note ((suffix_bind "induct", |
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2008
diff
changeset
|
519 |
[Attrib.internal (K (Rule_Cases.case_names constr_names))]), |
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2008
diff
changeset
|
520 |
[Rule_Cases.name constr_names q_induct]) lthy13; |
2296 | 521 |
val q_inducts = Project_Rule.projects lthy13 (1 upto (length raw_fvs)) q_induct |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
522 |
val (_, lthy14a) = Local_Theory.note ((suffix_bind "inducts", []), q_inducts) lthy14; |
2143
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2142
diff
changeset
|
523 |
val q_perm = map (lift_thm qtys lthy14) raw_perm_defs; |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
524 |
val lthy15 = note_simp_suffix "perm" q_perm lthy14a; |
2296 | 525 |
val q_fv = map (lift_thm qtys lthy15) raw_fv_defs; |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
526 |
val lthy16 = note_simp_suffix "fv" q_fv lthy15; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
527 |
val q_bn = map (lift_thm qtys lthy16) raw_bn_eqs; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
528 |
val lthy17 = note_simp_suffix "bn" q_bn lthy16; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
529 |
val _ = warning "Lifting eq-iff"; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
530 |
(*val _ = map tracing (map PolyML.makestring alpha_eq_iff);*) |
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
531 |
val eq_iff_unfolded0 = map (Local_Defs.unfold lthy17 @{thms alphas}) alpha_eq_iff |
2089
e9f089a5cc17
Parser changes for compound relations
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2076
diff
changeset
|
532 |
val eq_iff_unfolded1 = map (Local_Defs.unfold lthy17 @{thms Pair_eqvt}) eq_iff_unfolded0 |
e9f089a5cc17
Parser changes for compound relations
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2076
diff
changeset
|
533 |
val q_eq_iff_pre0 = map (lift_thm qtys lthy17) eq_iff_unfolded1; |
e9f089a5cc17
Parser changes for compound relations
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2076
diff
changeset
|
534 |
val q_eq_iff_pre1 = map (Local_Defs.fold lthy17 @{thms Pair_eqvt}) q_eq_iff_pre0 |
e9f089a5cc17
Parser changes for compound relations
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2076
diff
changeset
|
535 |
val q_eq_iff_pre2 = map (Local_Defs.fold lthy17 @{thms alphas}) q_eq_iff_pre1 |
e9f089a5cc17
Parser changes for compound relations
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2076
diff
changeset
|
536 |
val q_eq_iff = map (Local_Defs.unfold lthy17 (Quotient_Info.id_simps_get lthy17)) q_eq_iff_pre2 |
2025
070ba8972e97
Register only non-looping rules in eq_iff
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2023
diff
changeset
|
537 |
val (_, lthy18) = Local_Theory.note ((suffix_bind "eq_iff", []), q_eq_iff) lthy17; |
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
538 |
val q_dis = map (lift_thm qtys lthy18) alpha_distincts; |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
539 |
val lthy19 = note_simp_suffix "distinct" q_dis lthy18; |
2305
93ab397f5980
smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2304
diff
changeset
|
540 |
val q_eqvt = map (lift_thm qtys lthy19) (bn_eqvt @ fv_eqvt); |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
541 |
val (_, lthy20) = Local_Theory.note ((Binding.empty, |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
542 |
[Attrib.internal (fn _ => Nominal_ThmDecls.eqvt_add)]), q_eqvt) lthy19; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
543 |
val _ = warning "Supports"; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
544 |
val supports = map (prove_supports lthy20 q_perm) consts; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
545 |
val fin_supp = HOLogic.conj_elims (prove_fs lthy20 q_induct supports qtys); |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
546 |
val thy3 = Local_Theory.exit_global lthy20; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
547 |
val _ = warning "Instantiating FS"; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
548 |
val lthy21 = Theory_Target.instantiation (qty_full_names, [], @{sort fs}) thy3; |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
549 |
fun tac _ = Class.intro_classes_tac [] THEN (ALLGOALS (resolve_tac fin_supp)) |
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
550 |
val lthy22 = Class.prove_instantiation_instance tac lthy21 |
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
551 |
val fv_alpha_all = combine_fv_alpha_bns (qfv_ts_nobn, qfv_ts_bn) (alpha_trms, qalpha_bn_trms) bn_nos; |
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2000
diff
changeset
|
552 |
val (names, supp_eq_t) = supp_eq fv_alpha_all; |
2020
8468be06bff1
Cheat support equations in new parser
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2017
diff
changeset
|
553 |
val _ = warning "Support Equations"; |
2023 | 554 |
fun supp_eq_tac' _ = if !cheat_supp_eq then Skip_Proof.cheat_tac thy else |
2025
070ba8972e97
Register only non-looping rules in eq_iff
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2023
diff
changeset
|
555 |
supp_eq_tac q_induct q_fv q_perm q_eq_iff lthy22 1; |
2023 | 556 |
val q_supp = HOLogic.conj_elims (Goal.prove lthy22 names [] supp_eq_t supp_eq_tac') handle e => |
557 |
let val _ = warning ("Support eqs failed") in [] end; |
|
2020
8468be06bff1
Cheat support equations in new parser
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2017
diff
changeset
|
558 |
val lthy23 = note_suffix "supp" q_supp lthy22; |
1941 | 559 |
in |
2020
8468be06bff1
Cheat support equations in new parser
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2017
diff
changeset
|
560 |
(0, lthy23) |
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
561 |
end handle TEST ctxt => (0, ctxt) |
1941 | 562 |
*} |
563 |
||
564 |
section {* Preparing and parsing of the specification *} |
|
565 |
||
566 |
ML {* |
|
567 |
(* parsing the datatypes and declaring *) |
|
568 |
(* constructors in the local theory *) |
|
569 |
fun prepare_dts dt_strs lthy = |
|
570 |
let |
|
571 |
val thy = ProofContext.theory_of lthy |
|
572 |
||
573 |
fun mk_type full_tname tvrs = |
|
574 |
Type (full_tname, map (fn a => TVar ((a, 0), [])) tvrs) |
|
575 |
||
576 |
fun prep_cnstr full_tname tvs (cname, anno_tys, mx, _) = |
|
577 |
let |
|
578 |
val tys = map (Syntax.read_typ lthy o snd) anno_tys |
|
579 |
val ty = mk_type full_tname tvs |
|
580 |
in |
|
581 |
((cname, tys ---> ty, mx), (cname, tys, mx)) |
|
582 |
end |
|
583 |
||
584 |
fun prep_dt (tvs, tname, mx, cnstrs) = |
|
585 |
let |
|
586 |
val full_tname = Sign.full_name thy tname |
|
587 |
val (cnstrs', cnstrs'') = |
|
588 |
split_list (map (prep_cnstr full_tname tvs) cnstrs) |
|
589 |
in |
|
590 |
(cnstrs', (tvs, tname, mx, cnstrs'')) |
|
591 |
end |
|
592 |
||
593 |
val (cnstrs, dts) = split_list (map prep_dt dt_strs) |
|
594 |
in |
|
595 |
lthy |
|
596 |
|> Local_Theory.theory (Sign.add_consts_i (flat cnstrs)) |
|
597 |
|> pair dts |
|
598 |
end |
|
599 |
*} |
|
600 |
||
601 |
ML {* |
|
602 |
(* parsing the binding function specification and *) |
|
603 |
(* declaring the functions in the local theory *) |
|
604 |
fun prepare_bn_funs bn_fun_strs bn_eq_strs lthy = |
|
605 |
let |
|
606 |
val ((bn_funs, bn_eqs), _) = |
|
607 |
Specification.read_spec bn_fun_strs bn_eq_strs lthy |
|
608 |
||
609 |
fun prep_bn_fun ((bn, T), mx) = (bn, T, mx) |
|
610 |
||
611 |
val bn_funs' = map prep_bn_fun bn_funs |
|
612 |
in |
|
613 |
lthy |
|
614 |
|> Local_Theory.theory (Sign.add_consts_i bn_funs') |
|
615 |
|> pair (bn_funs', bn_eqs) |
|
616 |
end |
|
617 |
*} |
|
618 |
||
619 |
text {* associates every SOME with the index in the list; drops NONEs *} |
|
620 |
ML {* |
|
621 |
fun indexify xs = |
|
622 |
let |
|
623 |
fun mapp _ [] = [] |
|
624 |
| mapp i (NONE :: xs) = mapp (i + 1) xs |
|
625 |
| mapp i (SOME x :: xs) = (x, i) :: mapp (i + 1) xs |
|
626 |
in |
|
627 |
mapp 0 xs |
|
628 |
end |
|
629 |
||
630 |
fun index_lookup xs x = |
|
631 |
case AList.lookup (op=) xs x of |
|
632 |
SOME x => x |
|
633 |
| NONE => error ("Cannot find " ^ x ^ " as argument annotation."); |
|
634 |
*} |
|
635 |
||
636 |
ML {* |
|
637 |
fun prepare_bclauses dt_strs lthy = |
|
638 |
let |
|
639 |
val annos_bclauses = |
|
640 |
get_cnstrs dt_strs |
|
641 |
|> map (map (fn (_, antys, _, bns) => (map fst antys, bns))) |
|
642 |
||
643 |
fun prep_binder env bn_str = |
|
644 |
case (Syntax.read_term lthy bn_str) of |
|
645 |
Free (x, _) => (NONE, index_lookup env x) |
|
646 |
| Const (a, T) $ Free (x, _) => (SOME (Const (a, T)), index_lookup env x) |
|
647 |
| _ => error ("The term " ^ bn_str ^ " is not allowed as binding function.") |
|
648 |
||
649 |
fun prep_body env bn_str = index_lookup env bn_str |
|
650 |
||
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
2146
diff
changeset
|
651 |
fun prep_mode "bind" = Lst |
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
2146
diff
changeset
|
652 |
| prep_mode "bind_set" = Set |
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
2146
diff
changeset
|
653 |
| prep_mode "bind_res" = Res |
1941 | 654 |
|
655 |
fun prep_bclause env (mode, binders, bodies) = |
|
656 |
let |
|
657 |
val binders' = map (prep_binder env) binders |
|
658 |
val bodies' = map (prep_body env) bodies |
|
659 |
in |
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
2146
diff
changeset
|
660 |
BC (prep_mode mode, binders', bodies') |
1941 | 661 |
end |
662 |
||
663 |
fun prep_bclauses (annos, bclause_strs) = |
|
664 |
let |
|
665 |
val env = indexify annos (* for every label, associate the index *) |
|
666 |
in |
|
667 |
map (prep_bclause env) bclause_strs |
|
668 |
end |
|
669 |
in |
|
670 |
map (map prep_bclauses) annos_bclauses |
|
671 |
end |
|
672 |
*} |
|
673 |
||
1943 | 674 |
text {* |
675 |
adds an empty binding clause for every argument |
|
676 |
that is not already part of a binding clause |
|
677 |
*} |
|
678 |
||
1941 | 679 |
ML {* |
680 |
fun included i bcs = |
|
681 |
let |
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
2146
diff
changeset
|
682 |
fun incl (BC (_, bns, bds)) = (member (op =) (map snd bns) i) orelse (member (op =) bds i) |
1941 | 683 |
in |
684 |
exists incl bcs |
|
685 |
end |
|
686 |
*} |
|
687 |
||
688 |
ML {* |
|
689 |
fun complete dt_strs bclauses = |
|
690 |
let |
|
691 |
val args = |
|
692 |
get_cnstrs dt_strs |
|
693 |
|> map (map (fn (_, antys, _, _) => length antys)) |
|
694 |
||
695 |
fun complt n bcs = |
|
696 |
let |
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
2146
diff
changeset
|
697 |
fun add bcs i = (if included i bcs then [] else [BC (Lst, [], [i])]) |
1941 | 698 |
in |
699 |
bcs @ (flat (map_range (add bcs) n)) |
|
700 |
end |
|
701 |
in |
|
702 |
map2 (map2 complt) args bclauses |
|
703 |
end |
|
704 |
*} |
|
705 |
||
706 |
ML {* |
|
707 |
fun nominal_datatype2_cmd (dt_strs, bn_fun_strs, bn_eq_strs) lthy = |
|
708 |
let |
|
709 |
fun prep_typ (tvs, tname, mx, _) = (tname, length tvs, mx) |
|
710 |
val lthy0 = |
|
711 |
Local_Theory.theory (Sign.add_types (map prep_typ dt_strs)) lthy |
|
1944 | 712 |
val (dts, lthy1) = prepare_dts dt_strs lthy0 |
713 |
val ((bn_funs, bn_eqs), lthy2) = prepare_bn_funs bn_fun_strs bn_eq_strs lthy1 |
|
1941 | 714 |
val bclauses = prepare_bclauses dt_strs lthy2 |
715 |
val bclauses' = complete dt_strs bclauses |
|
716 |
in |
|
717 |
nominal_datatype2 dts bn_funs bn_eqs bclauses' lthy |> snd |
|
718 |
end |
|
719 |
||
720 |
||
721 |
(* Command Keyword *) |
|
722 |
||
2168 | 723 |
val _ = Outer_Syntax.local_theory "nominal_datatype" "test" Keyword.thy_decl |
1941 | 724 |
(main_parser >> nominal_datatype2_cmd) |
725 |
*} |
|
726 |
||
2292 | 727 |
|
728 |
text {* |
|
729 |
nominal_datatype2 does the following things in order: |
|
1941 | 730 |
|
2292 | 731 |
Parser.thy/raw_nominal_decls |
732 |
1) define the raw datatype |
|
733 |
2) define the raw binding functions |
|
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2037
diff
changeset
|
734 |
|
2292 | 735 |
Perm.thy/define_raw_perms |
736 |
3) define permutations of the raw datatype and show that the raw type is |
|
737 |
in the pt typeclass |
|
738 |
||
739 |
Lift.thy/define_fv_alpha_export, Fv.thy/define_fv & define_alpha |
|
740 |
4) define fv and fv_bn |
|
741 |
5) define alpha and alpha_bn |
|
1941 | 742 |
|
2292 | 743 |
Perm.thy/distinct_rel |
744 |
6) prove alpha_distincts (C1 x \<notsimeq> C2 y ...) (Proof by cases; simp) |
|
1941 | 745 |
|
2292 | 746 |
Tacs.thy/build_rel_inj |
747 |
6) prove alpha_eq_iff (C1 x = C2 y \<leftrightarrow> P x y ...) |
|
748 |
(left-to-right by intro rule, right-to-left by cases; simp) |
|
749 |
Equivp.thy/prove_eqvt |
|
750 |
7) prove bn_eqvt (common induction on the raw datatype) |
|
751 |
8) prove fv_eqvt (common induction on the raw datatype with help of above) |
|
752 |
Rsp.thy/build_alpha_eqvts |
|
753 |
9) prove alpha_eqvt and alpha_bn_eqvt |
|
754 |
(common alpha-induction, unfolding alpha_gen, permute of #* and =) |
|
755 |
Equivp.thy/build_alpha_refl & Equivp.thy/build_equivps |
|
756 |
10) prove that alpha and alpha_bn are equivalence relations |
|
757 |
(common induction and application of 'compose' lemmas) |
|
758 |
Lift.thy/define_quotient_types |
|
759 |
11) define quotient types |
|
760 |
Rsp.thy/build_fvbv_rsps |
|
761 |
12) prove bn respects (common induction and simp with alpha_gen) |
|
762 |
Rsp.thy/prove_const_rsp |
|
763 |
13) prove fv respects (common induction and simp with alpha_gen) |
|
764 |
14) prove permute respects (unfolds to alpha_eqvt) |
|
765 |
Rsp.thy/prove_alpha_bn_rsp |
|
766 |
15) prove alpha_bn respects |
|
767 |
(alpha_induct then cases then sym and trans of the relations) |
|
768 |
Rsp.thy/prove_alpha_alphabn |
|
769 |
16) show that alpha implies alpha_bn (by unduction, needed in following step) |
|
770 |
Rsp.thy/prove_const_rsp |
|
771 |
17) prove respects for all datatype constructors |
|
772 |
(unfold eq_iff and alpha_gen; introduce zero permutations; simp) |
|
773 |
Perm.thy/quotient_lift_consts_export |
|
774 |
18) define lifted constructors, fv, bn, alpha_bn, permutations |
|
775 |
Perm.thy/define_lifted_perms |
|
776 |
19) lift permutation zero and add properties to show that quotient type is in the pt typeclass |
|
777 |
Lift.thy/lift_thm |
|
778 |
20) lift permutation simplifications |
|
779 |
21) lift induction |
|
780 |
22) lift fv |
|
781 |
23) lift bn |
|
782 |
24) lift eq_iff |
|
783 |
25) lift alpha_distincts |
|
784 |
26) lift fv and bn eqvts |
|
785 |
Equivp.thy/prove_supports |
|
786 |
27) prove that union of arguments supports constructors |
|
787 |
Equivp.thy/prove_fs |
|
788 |
28) show that the lifted type is in fs typeclass (* by q_induct, supports *) |
|
789 |
Equivp.thy/supp_eq |
|
790 |
29) prove supp = fv |
|
791 |
*} |
|
1964
209ee65b2395
added some further problemetic tests
Christian Urban <urbanc@in.tum.de>
parents:
1963
diff
changeset
|
792 |
|
1941 | 793 |
|
794 |
||
795 |
end |
|
796 |
||
797 |
||
798 |