author | Christian Urban <urbanc@in.tum.de> |
Wed, 25 Aug 2010 22:55:42 +0800 | |
changeset 2434 | 92dc6cfa3a95 |
parent 2431 | 331873ebc5cd |
child 2435 | 3772bb3bd7ce |
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" |
|
2426
deb5be0115a7
moved lifting code from Lift.thy to nominal_dt_quot.ML
Christian Urban <urbanc@in.tum.de>
parents:
2425
diff
changeset
|
5 |
"Perm" "Tacs" "Equivp" |
1941 | 6 |
begin |
7 |
||
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
|
8 |
|
1941 | 9 |
section{* Interface for nominal_datatype *} |
10 |
||
2398 | 11 |
ML {* |
12 |
(* attributes *) |
|
13 |
val eqvt_attrib = Attrib.internal (K Nominal_ThmDecls.eqvt_add) |
|
14 |
val rsp_attrib = Attrib.internal (K Quotient_Info.rsp_rules_add) |
|
15 |
||
16 |
*} |
|
17 |
||
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
18 |
ML {* print_depth 50 *} |
1941 | 19 |
|
20 |
ML {* |
|
21 |
fun get_cnstrs dts = |
|
22 |
map (fn (_, _, _, constrs) => constrs) dts |
|
23 |
||
24 |
fun get_typed_cnstrs dts = |
|
25 |
flat (map (fn (_, bn, _, constrs) => |
|
26 |
(map (fn (bn', _, _) => (Binding.name_of bn, Binding.name_of bn')) constrs)) dts) |
|
27 |
||
28 |
fun get_cnstr_strs dts = |
|
29 |
map (fn (bn, _, _) => Binding.name_of bn) (flat (get_cnstrs dts)) |
|
30 |
||
31 |
fun get_bn_fun_strs bn_funs = |
|
32 |
map (fn (bn_fun, _, _) => Binding.name_of bn_fun) bn_funs |
|
33 |
*} |
|
34 |
||
2106
409ecb7284dd
properly exported defined bn-functions
Christian Urban <urbanc@in.tum.de>
parents:
2105
diff
changeset
|
35 |
|
1944 | 36 |
text {* Infrastructure for adding "_raw" to types and terms *} |
37 |
||
1941 | 38 |
ML {* |
39 |
fun add_raw s = s ^ "_raw" |
|
40 |
fun add_raws ss = map add_raw ss |
|
41 |
fun raw_bind bn = Binding.suffix_name "_raw" bn |
|
42 |
||
43 |
fun replace_str ss s = |
|
44 |
case (AList.lookup (op=) ss s) of |
|
45 |
SOME s' => s' |
|
46 |
| NONE => s |
|
47 |
||
48 |
fun replace_typ ty_ss (Type (a, Ts)) = Type (replace_str ty_ss a, map (replace_typ ty_ss) Ts) |
|
49 |
| replace_typ ty_ss T = T |
|
50 |
||
51 |
fun raw_dts ty_ss dts = |
|
52 |
let |
|
53 |
fun raw_dts_aux1 (bind, tys, mx) = |
|
54 |
(raw_bind bind, map (replace_typ ty_ss) tys, mx) |
|
55 |
||
56 |
fun raw_dts_aux2 (ty_args, bind, mx, constrs) = |
|
57 |
(ty_args, raw_bind bind, mx, map raw_dts_aux1 constrs) |
|
58 |
in |
|
59 |
map raw_dts_aux2 dts |
|
60 |
end |
|
61 |
||
62 |
fun replace_aterm trm_ss (Const (a, T)) = Const (replace_str trm_ss a, T) |
|
63 |
| replace_aterm trm_ss (Free (a, T)) = Free (replace_str trm_ss a, T) |
|
64 |
| replace_aterm trm_ss trm = trm |
|
65 |
||
66 |
fun replace_term trm_ss ty_ss trm = |
|
67 |
trm |> Term.map_aterms (replace_aterm trm_ss) |> map_types (replace_typ ty_ss) |
|
68 |
*} |
|
69 |
||
70 |
ML {* |
|
71 |
fun rawify_dts dt_names dts dts_env = |
|
72 |
let |
|
73 |
val raw_dts = raw_dts dts_env dts |
|
74 |
val raw_dt_names = add_raws dt_names |
|
75 |
in |
|
76 |
(raw_dt_names, raw_dts) |
|
77 |
end |
|
78 |
*} |
|
79 |
||
80 |
ML {* |
|
81 |
fun rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs = |
|
82 |
let |
|
83 |
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
|
84 |
(raw_bind bn, SOME (replace_typ dts_env ty), mx)) bn_funs |
1941 | 85 |
|
86 |
val bn_eqs' = map (fn (attr, trm) => |
|
87 |
(attr, replace_term (cnstrs_env @ bn_fun_env) dts_env trm)) bn_eqs |
|
88 |
in |
|
89 |
(bn_funs', bn_eqs') |
|
90 |
end |
|
91 |
*} |
|
92 |
||
93 |
ML {* |
|
94 |
fun rawify_bclauses dts_env cnstrs_env bn_fun_env bclauses = |
|
95 |
let |
|
96 |
fun rawify_bnds bnds = |
|
97 |
map (apfst (Option.map (replace_term (cnstrs_env @ bn_fun_env) dts_env))) bnds |
|
98 |
||
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
|
99 |
fun rawify_bclause (BC (mode, bnds, bdys)) = BC (mode, rawify_bnds bnds, bdys) |
1941 | 100 |
in |
101 |
map (map (map rawify_bclause)) bclauses |
|
102 |
end |
|
103 |
*} |
|
104 |
||
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
|
105 |
(* 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
|
106 |
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
|
107 |
bn function *) |
1941 | 108 |
ML {* |
2294
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
109 |
fun strip_bn_fun lthy args t = |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
110 |
let |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
111 |
fun aux t = |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
112 |
case t of |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
113 |
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
|
114 |
| 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
|
115 |
| 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
|
116 |
(find_index (equal x) args, NONE) :: aux y |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
117 |
| 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
|
118 |
(find_index (equal x) args, NONE) :: aux y |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
119 |
| Const (@{const_name bot}, _) => [] |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
120 |
| Const (@{const_name Nil}, _) => [] |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
121 |
| (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
|
122 |
| _ => 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
|
123 |
in |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
124 |
aux t |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
125 |
end |
1941 | 126 |
*} |
127 |
||
128 |
ML {* |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
129 |
(** definition of the raw binding functions **) |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
130 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
131 |
(* TODO: needs cleaning *) |
1941 | 132 |
fun find [] _ = error ("cannot find element") |
133 |
| find ((x, z)::xs) y = if (Long_Name.base_name x) = y then z else find xs y |
|
134 |
||
2295
8aff3f3ce47f
started to work on alpha
Christian Urban <urbanc@in.tum.de>
parents:
2294
diff
changeset
|
135 |
fun prep_bn_info lthy dt_names dts eqs = |
1941 | 136 |
let |
137 |
fun aux eq = |
|
138 |
let |
|
139 |
val (lhs, rhs) = eq |
|
140 |
|> HOLogic.dest_Trueprop |
|
141 |
|> HOLogic.dest_eq |
|
142 |
val (bn_fun, [cnstr]) = strip_comb lhs |
|
2294
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
143 |
val (_, ty) = dest_Const bn_fun |
1941 | 144 |
val (ty_name, _) = dest_Type (domain_type ty) |
145 |
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
|
146 |
val (cnstr_head, cnstr_args) = strip_comb cnstr |
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
147 |
val rhs_elements = strip_bn_fun lthy cnstr_args rhs |
1941 | 148 |
in |
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
149 |
(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
|
150 |
end |
1941 | 151 |
fun order dts i ts = |
152 |
let |
|
153 |
val dt = nth dts i |
|
154 |
val cts = map (fn (x, _, _) => Binding.name_of x) ((fn (_, _, _, x) => x) dt) |
|
155 |
val ts' = map (fn (x, y) => (fst (dest_Const x), y)) ts |
|
156 |
in |
|
157 |
map (find ts') cts |
|
158 |
end |
|
159 |
||
160 |
val unordered = AList.group (op=) (map aux eqs) |
|
161 |
val unordered' = map (fn (x, y) => (x, AList.group (op=) y)) unordered |
|
162 |
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
|
163 |
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
|
164 |
|
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
|
165 |
(*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
|
166 |
(*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
|
167 |
(*val _ = tracing ("ordered'\n" ^ @{make_string} ordered')*) |
1941 | 168 |
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
|
169 |
ordered' |
1941 | 170 |
end |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
171 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
172 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
173 |
fun define_raw_bns dt_names dts raw_bn_funs raw_bn_eqs constr_thms size_thms lthy = |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
174 |
if null raw_bn_funs |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
175 |
then ([], [], [], [], lthy) |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
176 |
else |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
177 |
let |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
178 |
val (_, lthy1) = Function.add_function raw_bn_funs raw_bn_eqs |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
179 |
Function_Common.default_config (pat_completeness_simp constr_thms) lthy |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
180 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
181 |
val (info, lthy2) = prove_termination size_thms (Local_Theory.restore lthy1) |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
182 |
val {fs, simps, inducts, ...} = info |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
183 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
184 |
val raw_bn_induct = (the inducts) |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
185 |
val raw_bn_eqs = the simps |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
186 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
187 |
val raw_bn_info = |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
188 |
prep_bn_info lthy dt_names dts (map prop_of raw_bn_eqs) |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
189 |
in |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
190 |
(fs, raw_bn_eqs, raw_bn_info, raw_bn_induct, lthy2) |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
191 |
end |
1941 | 192 |
*} |
193 |
||
194 |
ML {* |
|
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents:
2409
diff
changeset
|
195 |
fun define_raw_dts dts bn_funs bn_eqs binds lthy = |
1941 | 196 |
let |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
197 |
val thy = Local_Theory.exit_global lthy |
1941 | 198 |
val thy_name = Context.theory_name thy |
199 |
||
200 |
val dt_names = map (fn (_, s, _, _) => Binding.name_of s) dts |
|
201 |
val dt_full_names = map (Long_Name.qualify thy_name) dt_names |
|
202 |
val dt_full_names' = add_raws dt_full_names |
|
203 |
val dts_env = dt_full_names ~~ dt_full_names' |
|
204 |
||
205 |
val cnstrs = get_cnstr_strs dts |
|
206 |
val cnstrs_ty = get_typed_cnstrs dts |
|
207 |
val cnstrs_full_names = map (Long_Name.qualify thy_name) cnstrs |
|
208 |
val cnstrs_full_names' = map (fn (x, y) => Long_Name.qualify thy_name |
|
209 |
(Long_Name.qualify (add_raw x) (add_raw y))) cnstrs_ty |
|
210 |
val cnstrs_env = cnstrs_full_names ~~ cnstrs_full_names' |
|
211 |
||
212 |
val bn_fun_strs = get_bn_fun_strs bn_funs |
|
213 |
val bn_fun_strs' = add_raws bn_fun_strs |
|
214 |
val bn_fun_env = bn_fun_strs ~~ bn_fun_strs' |
|
215 |
val bn_fun_full_env = map (pairself (Long_Name.qualify thy_name)) |
|
216 |
(bn_fun_strs ~~ bn_fun_strs') |
|
217 |
||
218 |
val (raw_dt_names, raw_dts) = rawify_dts dt_names dts dts_env |
|
219 |
val (raw_bn_funs, raw_bn_eqs) = rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs |
|
220 |
val raw_bclauses = rawify_bclauses dts_env cnstrs_env bn_fun_full_env binds |
|
221 |
||
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
222 |
val (raw_dt_full_names, thy1) = |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
223 |
Datatype.add_datatype Datatype.default_config raw_dt_names raw_dts thy |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
224 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
225 |
val lthy1 = Named_Target.theory_init thy1 |
2304
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
226 |
in |
2337
b151399bd2c3
fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
2336
diff
changeset
|
227 |
(raw_dt_full_names, raw_dts, raw_bclauses, raw_bn_funs, raw_bn_eqs, lthy1) |
2304
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
228 |
end |
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
229 |
*} |
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
230 |
|
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
231 |
|
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
|
232 |
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
|
233 |
(* 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
|
234 |
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
|
235 |
|
2425
715ab84065a0
nominal_datatypes with type variables do not work
Christian Urban <urbanc@in.tum.de>
parents:
2424
diff
changeset
|
236 |
val (STEPS, STEPS_setup) = Attrib.config_int "STEPS" (K 0); |
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
|
237 |
|
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
|
238 |
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
|
239 |
*} |
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
|
240 |
|
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
|
241 |
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
|
242 |
|
1941 | 243 |
ML {* |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
244 |
fun nominal_datatype2 thm_name dts bn_funs bn_eqs bclauses lthy = |
1941 | 245 |
let |
2294
72ad4e766acf
properly exported bn_descr
Christian Urban <urbanc@in.tum.de>
parents:
2293
diff
changeset
|
246 |
(* definition of the raw datatypes *) |
2316 | 247 |
val _ = warning "Definition of raw datatypes"; |
2337
b151399bd2c3
fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
2336
diff
changeset
|
248 |
val (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
|
249 |
if get_STEPS lthy > 0 |
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents:
2409
diff
changeset
|
250 |
then define_raw_dts 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
|
251 |
else raise TEST lthy |
1941 | 252 |
|
2304
8a98171ba1fc
all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents:
2302
diff
changeset
|
253 |
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
|
254 |
val {descr, sorts, ...} = dtinfo |
2407 | 255 |
|
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
256 |
val raw_tys = all_dtyps descr sorts |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
257 |
val raw_full_ty_names = map (fst o dest_Type) raw_tys |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
258 |
val tvs = hd raw_tys |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
259 |
|> snd o dest_Type |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
260 |
|> map dest_TFree |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
261 |
|
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
262 |
val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy0)) raw_full_ty_names |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
263 |
|
2407 | 264 |
val raw_cns_info = all_dtyp_constrs_types descr sorts |
265 |
val raw_constrs = flat (map (map (fn (c, _, _, _) => c)) raw_cns_info) |
|
266 |
||
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
267 |
val raw_inject_thms = flat (map #inject dtinfos) |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
268 |
val raw_distinct_thms = flat (map #distinct dtinfos) |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
269 |
val raw_induct_thm = #induct dtinfo |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
270 |
val raw_induct_thms = #inducts dtinfo |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
271 |
val raw_exhaust_thms = map #exhaust dtinfos |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
272 |
val raw_size_trms = map size_const raw_tys |
2388 | 273 |
val raw_size_thms = Size.size_thms (ProofContext.theory_of lthy0) (hd raw_dt_names) |
274 |
|> `(fn thms => (length thms) div 2) |
|
2392
9294d7cec5e2
proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents:
2389
diff
changeset
|
275 |
|> uncurry drop |
2388 | 276 |
|
2409
83990a42a068
more tuning of the code
Christian Urban <urbanc@in.tum.de>
parents:
2407
diff
changeset
|
277 |
(* definitions of raw permutations by primitive recursion *) |
2316 | 278 |
val _ = warning "Definition of raw permutations"; |
2401
7645e18e8b19
modified the code for class instantiations (with help from Florian)
Christian Urban <urbanc@in.tum.de>
parents:
2400
diff
changeset
|
279 |
val ((raw_perm_funs, raw_perm_simps, raw_perm_laws), lthy2a) = |
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
280 |
if get_STEPS lthy0 > 1 |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
281 |
then define_raw_perms raw_full_ty_names raw_tys tvs raw_constrs raw_induct_thm lthy0 |
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
282 |
else raise TEST lthy0 |
2144 | 283 |
|
284 |
(* noting the raw permutations as eqvt theorems *) |
|
2398 | 285 |
val (_, lthy3) = Local_Theory.note ((Binding.empty, [eqvt_attrib]), raw_perm_simps) lthy2a |
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2008
diff
changeset
|
286 |
|
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
|
287 |
(* definition of raw fv_functions *) |
2316 | 288 |
val _ = warning "Definition of raw fv-functions"; |
2405
29ebbe56f450
also able to lift the bn_defs
Christian Urban <urbanc@in.tum.de>
parents:
2404
diff
changeset
|
289 |
val (raw_bns, raw_bn_defs, raw_bn_info, raw_bn_induct, lthy3a) = |
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
290 |
if get_STEPS lthy3 > 2 |
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents:
2409
diff
changeset
|
291 |
then define_raw_bns raw_full_ty_names raw_dts raw_bn_funs raw_bn_eqs |
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents:
2409
diff
changeset
|
292 |
(raw_inject_thms @ raw_distinct_thms) raw_size_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
|
293 |
else raise TEST lthy3 |
2292 | 294 |
|
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
295 |
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
|
296 |
if get_STEPS lthy3a > 3 |
2407 | 297 |
then define_raw_fvs raw_full_ty_names raw_tys raw_cns_info raw_bn_info raw_bclauses |
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents:
2409
diff
changeset
|
298 |
(raw_inject_thms @ raw_distinct_thms) raw_size_thms lthy3a |
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
299 |
else raise TEST lthy3a |
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
300 |
|
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
parents:
2008
diff
changeset
|
301 |
(* definition of raw alphas *) |
2316 | 302 |
val _ = warning "Definition of alphas"; |
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
303 |
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
|
304 |
if get_STEPS lthy3b > 4 |
2407 | 305 |
then define_raw_alpha raw_full_ty_names raw_tys raw_cns_info raw_bn_info raw_bclauses raw_fvs lthy3b |
2308
387fcbd33820
fixed problem with bn_info
Christian Urban <urbanc@in.tum.de>
parents:
2306
diff
changeset
|
306 |
else raise TEST lthy3b |
2336
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
307 |
val alpha_tys = map (domain_type o fastype_of) alpha_trms |
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
308 |
|
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
309 |
(* definition of alpha-distinct lemmas *) |
2316 | 310 |
val _ = warning "Distinct theorems"; |
2399 | 311 |
val alpha_distincts = |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
312 |
mk_alpha_distincts lthy4 alpha_cases raw_distinct_thms alpha_trms raw_tys |
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
313 |
|
2361 | 314 |
(* definition of alpha_eq_iff lemmas *) |
315 |
(* they have a funny shape for the simplifier *) |
|
2316 | 316 |
val _ = warning "Eq-iff theorems"; |
2387
082d9fd28f89
helper lemmas for rsp-lemmas
Christian Urban <urbanc@in.tum.de>
parents:
2384
diff
changeset
|
317 |
val (alpha_eq_iff_simps, alpha_eq_iff) = |
2295
8aff3f3ce47f
started to work on alpha
Christian Urban <urbanc@in.tum.de>
parents:
2294
diff
changeset
|
318 |
if get_STEPS lthy > 5 |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
319 |
then mk_alpha_eq_iff lthy4 alpha_intros raw_distinct_thms raw_inject_thms alpha_cases |
2295
8aff3f3ce47f
started to work on alpha
Christian Urban <urbanc@in.tum.de>
parents:
2294
diff
changeset
|
320 |
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
|
321 |
|
2388 | 322 |
(* proving equivariance lemmas for bns, fvs, size 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
|
323 |
val _ = warning "Proving equivariance"; |
2406
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
parents:
2405
diff
changeset
|
324 |
val raw_bn_eqvt = |
2298 | 325 |
if get_STEPS lthy > 6 |
2405
29ebbe56f450
also able to lift the bn_defs
Christian Urban <urbanc@in.tum.de>
parents:
2404
diff
changeset
|
326 |
then raw_prove_eqvt raw_bns raw_bn_induct (raw_bn_defs @ raw_perm_simps) lthy4 |
2298 | 327 |
else raise TEST lthy4 |
328 |
||
2406
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
parents:
2405
diff
changeset
|
329 |
(* noting the raw_bn_eqvt lemmas in a temprorary theory *) |
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
parents:
2405
diff
changeset
|
330 |
val lthy_tmp = snd (Local_Theory.note ((Binding.empty, [eqvt_attrib]), raw_bn_eqvt) lthy4) |
2305
93ab397f5980
smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2304
diff
changeset
|
331 |
|
2406
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
parents:
2405
diff
changeset
|
332 |
val raw_fv_eqvt = |
2298 | 333 |
if get_STEPS lthy > 7 |
2384
841b7e34e70a
fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents:
2378
diff
changeset
|
334 |
then raw_prove_eqvt (raw_fvs @ raw_fv_bns) raw_fv_bns_induct (raw_fv_defs @ raw_perm_simps) |
2388 | 335 |
(Local_Theory.restore lthy_tmp) |
336 |
else raise TEST lthy4 |
|
337 |
||
2389
0f24c961b5f6
introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents:
2388
diff
changeset
|
338 |
val raw_size_eqvt = |
2388 | 339 |
if get_STEPS lthy > 8 |
340 |
then raw_prove_eqvt raw_size_trms raw_induct_thms (raw_size_thms @ raw_perm_simps) |
|
341 |
(Local_Theory.restore lthy_tmp) |
|
2389
0f24c961b5f6
introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents:
2388
diff
changeset
|
342 |
|> map (rewrite_rule @{thms permute_nat_def[THEN eq_reflection]}) |
0f24c961b5f6
introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents:
2388
diff
changeset
|
343 |
|> map (fn thm => thm RS @{thm sym}) |
2305
93ab397f5980
smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2304
diff
changeset
|
344 |
else raise TEST lthy4 |
93ab397f5980
smaller code for raw-eqvt proofs
Christian Urban <urbanc@in.tum.de>
parents:
2304
diff
changeset
|
345 |
|
2406
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
parents:
2405
diff
changeset
|
346 |
val lthy5 = snd (Local_Theory.note ((Binding.empty, [eqvt_attrib]), raw_fv_eqvt) lthy_tmp) |
2306 | 347 |
|
2336
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
348 |
val (alpha_eqvt, lthy6) = |
2388 | 349 |
if get_STEPS lthy > 9 |
2336
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
350 |
then Nominal_Eqvt.equivariance true (alpha_trms @ alpha_bn_trms) alpha_induct alpha_intros lthy5 |
2311
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
351 |
else raise TEST lthy4 |
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
352 |
|
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
353 |
(* proving alpha equivalence *) |
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
354 |
val _ = warning "Proving equivalence" |
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
355 |
|
2316 | 356 |
val alpha_refl_thms = |
2388 | 357 |
if get_STEPS lthy > 10 |
358 |
then raw_prove_refl alpha_trms alpha_bn_trms alpha_intros raw_induct_thm lthy6 |
|
2336
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
359 |
else raise TEST lthy6 |
2316 | 360 |
|
2311
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
361 |
val alpha_sym_thms = |
2388 | 362 |
if get_STEPS lthy > 11 |
2336
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
363 |
then raw_prove_sym (alpha_trms @ alpha_bn_trms) alpha_intros alpha_induct lthy6 |
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
364 |
else raise TEST lthy6 |
2298 | 365 |
|
2311
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
366 |
val alpha_trans_thms = |
2388 | 367 |
if get_STEPS lthy > 12 |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
368 |
then raw_prove_trans (alpha_trms @ alpha_bn_trms) (raw_distinct_thms @ raw_inject_thms) |
2336
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
369 |
alpha_intros alpha_induct alpha_cases lthy6 |
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
370 |
else raise TEST lthy6 |
2311
4da5c5c29009
work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents:
2309
diff
changeset
|
371 |
|
2404
66ae73fd66c0
added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents:
2401
diff
changeset
|
372 |
val (alpha_equivp_thms, alpha_bn_equivp_thms) = |
2388 | 373 |
if get_STEPS lthy > 13 |
2404
66ae73fd66c0
added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents:
2401
diff
changeset
|
374 |
then raw_prove_equivp alpha_trms alpha_bn_trms alpha_refl_thms alpha_sym_thms |
66ae73fd66c0
added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents:
2401
diff
changeset
|
375 |
alpha_trans_thms lthy6 |
2336
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
376 |
else raise TEST lthy6 |
2322
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
377 |
|
2320
d835a2771608
prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents:
2316
diff
changeset
|
378 |
(* 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
|
379 |
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
|
380 |
|
d835a2771608
prove that alpha implies alpha_bn (needed for rsp proofs)
Christian Urban <urbanc@in.tum.de>
parents:
2316
diff
changeset
|
381 |
val alpha_bn_imp_thms = |
2388 | 382 |
if get_STEPS lthy > 14 |
2336
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
383 |
then raw_prove_bn_imp alpha_trms alpha_bn_trms alpha_intros alpha_induct lthy6 |
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
384 |
else raise TEST lthy6 |
2322
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
385 |
|
2397
c670a849af65
more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents:
2396
diff
changeset
|
386 |
(* respectfulness proofs *) |
c670a849af65
more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents:
2396
diff
changeset
|
387 |
val raw_funs_rsp_aux = raw_fv_bn_rsp_aux alpha_trms alpha_bn_trms raw_fvs |
2405
29ebbe56f450
also able to lift the bn_defs
Christian Urban <urbanc@in.tum.de>
parents:
2404
diff
changeset
|
388 |
raw_bns raw_fv_bns alpha_induct (raw_bn_defs @ raw_fv_defs) lthy6 |
2397
c670a849af65
more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents:
2396
diff
changeset
|
389 |
val raw_funs_rsp = map mk_funs_rsp raw_funs_rsp_aux |
2388 | 390 |
|
2392
9294d7cec5e2
proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents:
2389
diff
changeset
|
391 |
val raw_size_rsp = raw_size_rsp_aux (alpha_trms @ alpha_bn_trms) alpha_induct |
9294d7cec5e2
proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents:
2389
diff
changeset
|
392 |
(raw_size_thms @ raw_size_eqvt) lthy6 |
2397
c670a849af65
more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents:
2396
diff
changeset
|
393 |
|> map mk_funs_rsp |
2392
9294d7cec5e2
proved rsp-helper lemmas of size functions
Christian Urban <urbanc@in.tum.de>
parents:
2389
diff
changeset
|
394 |
|
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
395 |
val raw_constrs_rsp = raw_constrs_rsp raw_constrs alpha_trms alpha_intros |
2397
c670a849af65
more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents:
2396
diff
changeset
|
396 |
(alpha_bn_imp_thms @ raw_funs_rsp_aux) lthy6 |
c670a849af65
more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents:
2396
diff
changeset
|
397 |
|
c670a849af65
more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents:
2396
diff
changeset
|
398 |
val alpha_permute_rsp = map mk_alpha_permute_rsp alpha_eqvt |
2384
841b7e34e70a
fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents:
2378
diff
changeset
|
399 |
|
2404
66ae73fd66c0
added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents:
2401
diff
changeset
|
400 |
val alpha_bn_rsp = raw_alpha_bn_rsp alpha_bn_equivp_thms alpha_bn_imp_thms |
66ae73fd66c0
added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents:
2401
diff
changeset
|
401 |
|
2398 | 402 |
(* noting the quot_respects lemmas *) |
403 |
val (_, lthy6a) = |
|
404 |
if get_STEPS lthy > 15 |
|
405 |
then Local_Theory.note ((Binding.empty, [rsp_attrib]), |
|
2404
66ae73fd66c0
added rsp-lemmas for alpha_bns
Christian Urban <urbanc@in.tum.de>
parents:
2401
diff
changeset
|
406 |
raw_constrs_rsp @ raw_funs_rsp @ raw_size_rsp @ alpha_permute_rsp @ alpha_bn_rsp) lthy6 |
2398 | 407 |
else raise TEST lthy6 |
408 |
||
2336
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
409 |
(* defining the quotient type *) |
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
410 |
val _ = warning "Declaring the quotient types" |
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
411 |
val qty_descr = map (fn (vs, bind, mx, _) => (vs, bind, mx)) dts |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
412 |
|
2336
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
413 |
val (qty_infos, lthy7) = |
2398 | 414 |
if get_STEPS lthy > 16 |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
415 |
then define_qtypes qty_descr alpha_tys alpha_trms alpha_equivp_thms lthy6a |
2398 | 416 |
else raise TEST lthy6a |
2336
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
417 |
|
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
418 |
val qtys = map #qtyp qty_infos |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
419 |
val qty_full_names = map (fst o dest_Type) qtys |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
420 |
val qty_names = map Long_Name.base_name qty_full_names |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
421 |
|
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
422 |
|
2339
1e0b3992189c
more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents:
2338
diff
changeset
|
423 |
(* defining of quotient term-constructors, binding functions, free vars functions *) |
2378
2f13fe48c877
updated to new Isabelle; made FSet more "quiet"
Christian Urban <urbanc@in.tum.de>
parents:
2361
diff
changeset
|
424 |
val _ = warning "Defining the quotient constants" |
2346 | 425 |
val qconstrs_descr = |
2338 | 426 |
flat (map (fn (_, _, _, cs) => map (fn (b, _, mx) => (Name.of_binding b, mx)) cs) dts) |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
427 |
|> map2 (fn t => fn (b, mx) => (b, t, mx)) raw_constrs |
2338 | 428 |
|
2339
1e0b3992189c
more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents:
2338
diff
changeset
|
429 |
val qbns_descr = |
2346 | 430 |
map2 (fn (b, _, mx) => fn t => (Name.of_binding b, t, mx)) bn_funs raw_bns |
2339
1e0b3992189c
more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents:
2338
diff
changeset
|
431 |
|
1e0b3992189c
more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents:
2338
diff
changeset
|
432 |
val qfvs_descr = |
2346 | 433 |
map2 (fn n => fn t => ("fv_" ^ n, t, NoSyn)) qty_names raw_fvs |
2339
1e0b3992189c
more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents:
2338
diff
changeset
|
434 |
|
2346 | 435 |
val qfv_bns_descr = |
2398 | 436 |
map2 (fn (b, _, _) => fn t => ("fv_" ^ Name.of_binding b, t, NoSyn)) bn_funs raw_fv_bns |
2339
1e0b3992189c
more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents:
2338
diff
changeset
|
437 |
|
2384
841b7e34e70a
fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents:
2378
diff
changeset
|
438 |
val qalpha_bns_descr = |
841b7e34e70a
fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents:
2378
diff
changeset
|
439 |
map2 (fn (b, _, _) => fn t => ("alpha_" ^ Name.of_binding b, t, NoSyn)) bn_funs alpha_bn_trms |
841b7e34e70a
fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents:
2378
diff
changeset
|
440 |
|
2398 | 441 |
val qperm_descr = |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
442 |
map2 (fn n => fn t => ("permute_" ^ n, Type.legacy_freeze t, NoSyn)) qty_names raw_perm_funs |
2398 | 443 |
|
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
444 |
val qsize_descr = |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
445 |
map2 (fn n => fn t => ("size_" ^ n, t, NoSyn)) qty_names raw_size_trms |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
446 |
|
2384
841b7e34e70a
fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents:
2378
diff
changeset
|
447 |
val (((((qconstrs_info, qbns_info), qfvs_info), qfv_bns_info), qalpha_bns_info), lthy8) = |
2398 | 448 |
if get_STEPS lthy > 17 |
2346 | 449 |
then |
450 |
lthy7 |
|
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
451 |
|> define_qconsts qtys qconstrs_descr |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
452 |
||>> define_qconsts qtys qbns_descr |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
453 |
||>> define_qconsts qtys qfvs_descr |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
454 |
||>> define_qconsts qtys qfv_bns_descr |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
455 |
||>> define_qconsts qtys qalpha_bns_descr |
2338 | 456 |
else raise TEST lthy7 |
457 |
||
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
458 |
(* definition of the quotient permfunctions and pt-class *) |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
459 |
val lthy9 = |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
460 |
if get_STEPS lthy > 18 |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
461 |
then define_qperms qtys qty_full_names tvs qperm_descr raw_perm_laws lthy8 |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
462 |
else raise TEST lthy8 |
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
463 |
|
2401
7645e18e8b19
modified the code for class instantiations (with help from Florian)
Christian Urban <urbanc@in.tum.de>
parents:
2400
diff
changeset
|
464 |
val lthy9a = |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
465 |
if get_STEPS lthy > 19 |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
466 |
then define_qsizes qtys qty_full_names tvs qsize_descr lthy9 |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
467 |
else raise TEST lthy9 |
2398 | 468 |
|
2346 | 469 |
val qconstrs = map #qconst qconstrs_info |
470 |
val qbns = map #qconst qbns_info |
|
471 |
val qfvs = map #qconst qfvs_info |
|
472 |
val qfv_bns = map #qconst qfv_bns_info |
|
2384
841b7e34e70a
fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents:
2378
diff
changeset
|
473 |
val qalpha_bns = map #qconst qalpha_bns_info |
2434 | 474 |
|
475 |
(* lifting of the theorems *) |
|
476 |
val _ = warning "Lifting of Theorems" |
|
477 |
||
478 |
val eq_iff_simps = @{thms alphas permute_prod.simps prod_fv.simps prod_alpha_def prod_rel.simps |
|
479 |
prod.cases} |
|
480 |
||
481 |
val ((((((qdistincts, qeq_iffs), qfv_defs), qbn_defs), qperm_simps), qfv_qbn_eqvts), lthyA) = |
|
482 |
if get_STEPS lthy > 20 |
|
483 |
then |
|
484 |
lthy9a |
|
485 |
|> lift_thms qtys [] alpha_distincts |
|
486 |
||>> lift_thms qtys eq_iff_simps alpha_eq_iff |
|
487 |
||>> lift_thms qtys [] raw_fv_defs |
|
488 |
||>> lift_thms qtys [] raw_bn_defs |
|
489 |
||>> lift_thms qtys [] raw_perm_simps |
|
490 |
||>> lift_thms qtys [] (raw_fv_eqvt @ raw_bn_eqvt) |
|
491 |
else raise TEST lthy9a |
|
492 |
||
493 |
val (((qsize_eqvt, [qinduct]), qexhausts), lthyB) = |
|
494 |
if get_STEPS lthy > 20 |
|
495 |
then |
|
496 |
lthyA |
|
497 |
|> lift_thms qtys [] raw_size_eqvt |
|
498 |
||>> lift_thms qtys [] [raw_induct_thm] |
|
499 |
||>> lift_thms qtys [] raw_exhaust_thms |
|
500 |
else raise TEST lthyA |
|
501 |
||
2398 | 502 |
|
2388 | 503 |
(* temporary theorem bindings *) |
2434 | 504 |
val (_, lthy9') = lthyB |
505 |
|> Local_Theory.note ((@{binding "distinct"}, []), qdistincts) |
|
506 |
||>> Local_Theory.note ((@{binding "eq_iff"}, []), qeq_iffs) |
|
507 |
||>> Local_Theory.note ((@{binding "fv_defs"}, []), qfv_defs) |
|
508 |
||>> Local_Theory.note ((@{binding "bn_defs"}, []), qbn_defs) |
|
509 |
||>> Local_Theory.note ((@{binding "perm_simps"}, []), qperm_simps) |
|
510 |
||>> Local_Theory.note ((@{binding "fv_bn_eqvt"}, []), qfv_qbn_eqvts) |
|
511 |
||>> Local_Theory.note ((@{binding "size_eqvt"}, []), qsize_eqvt) |
|
512 |
||>> Local_Theory.note ((@{binding "induct"}, []), [qinduct]) |
|
513 |
||>> Local_Theory.note ((@{binding "exhaust"}, []), qexhausts) |
|
514 |
||
2397
c670a849af65
more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents:
2396
diff
changeset
|
515 |
|
2336
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
516 |
val _ = |
2434 | 517 |
if get_STEPS lthy > 21 |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
518 |
then true else raise TEST lthy9' |
2336
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
519 |
|
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
520 |
(* old stuff *) |
f2d545b77b31
added definition of the quotient types
Christian Urban <urbanc@in.tum.de>
parents:
2324
diff
changeset
|
521 |
|
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
522 |
val thy = ProofContext.theory_of lthy9' |
2398 | 523 |
val thy_name = Context.theory_name thy |
524 |
val qty_full_names = map (Long_Name.qualify thy_name) qty_names |
|
525 |
||
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 _ = warning "Proving respects"; |
2322
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
527 |
|
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
528 |
val bn_nos = map (fn (_, i, _) => i) raw_bn_info; |
2346 | 529 |
val bns = raw_bns ~~ bn_nos; |
2322
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
530 |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
531 |
val bns_rsp_pre' = build_fvbv_rsps alpha_trms alpha_induct raw_bn_defs (map fst 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
|
532 |
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
|
533 |
fn (bn_t, _) => prove_const_rsp qtys Binding.empty [bn_t] (fn _ => |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
534 |
resolve_tac bns_rsp_pre' 1)) 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
|
535 |
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
|
536 |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
537 |
fun fv_rsp_tac _ = fvbv_rsp_tac alpha_induct raw_fv_defs lthy9' 1; |
2322
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
538 |
|
24de7e548094
proved eqvip theorems for alphas
Christian Urban <urbanc@in.tum.de>
parents:
2321
diff
changeset
|
539 |
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
|
540 |
|
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
541 |
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
|
542 |
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
|
543 |
(fn fv => fn ctxt => prove_const_rsp qtys Binding.empty [fv] |
2296 | 544 |
(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
|
545 |
val fv_rsp = flat (map snd fv_rsp_pre); |
2292 | 546 |
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
|
547 |
(fn _ => asm_simp_tac (HOL_ss addsimps alpha_eqvt) 1) lthy10; |
2409
83990a42a068
more tuning of the code
Christian Urban <urbanc@in.tum.de>
parents:
2407
diff
changeset
|
548 |
fun alpha_bn_rsp_tac _ = let val alpha_bn_rsp_pre = prove_alpha_bn_rsp alpha_trms alpha_induct (alpha_eq_iff @ alpha_distincts) alpha_equivp_thms raw_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
|
549 |
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
|
550 |
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
|
551 |
fun const_rsp_tac _ = |
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
552 |
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
|
553 |
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
|
554 |
val (const_rsps, lthy12) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst] |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
555 |
const_rsp_tac) raw_constrs lthy11a |
2339
1e0b3992189c
more quotient-definitions
Christian Urban <urbanc@in.tum.de>
parents:
2338
diff
changeset
|
556 |
val qfv_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) (raw_fvs @ raw_fv_bns) |
2337
b151399bd2c3
fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
2336
diff
changeset
|
557 |
val dd = map2 (fn x => fn y => (x, y, NoSyn)) qfv_names (raw_fvs @ raw_fv_bns) |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
558 |
val (qfv_info, lthy12a) = define_qconsts qtys dd lthy12; |
2346 | 559 |
val qfv_ts = map #qconst qfv_info |
560 |
val qfv_defs = map #def qfv_info |
|
2292 | 561 |
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
|
562 |
val qbn_names = map (fn (b, _ , _) => Name.of_binding b) bn_funs |
2346 | 563 |
val dd = map2 (fn x => fn y => (x, y, NoSyn)) qbn_names raw_bns |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
564 |
val (qbn_info, lthy12b) = define_qconsts qtys dd lthy12a; |
2346 | 565 |
val qbn_ts = map #qconst qbn_info |
566 |
val qbn_defs = map #def qbn_info |
|
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
567 |
val qalpha_bn_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) alpha_bn_trms |
2337
b151399bd2c3
fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
2336
diff
changeset
|
568 |
val dd = map2 (fn x => fn y => (x, y, NoSyn)) qalpha_bn_names alpha_bn_trms |
2400
c6d30d5f5ba1
defined qperms and qsizes
Christian Urban <urbanc@in.tum.de>
parents:
2399
diff
changeset
|
569 |
val (qalpha_info, lthy12c) = define_qconsts qtys dd lthy12b; |
2346 | 570 |
val qalpha_bn_trms = map #qconst qalpha_info |
571 |
val qalphabn_defs = map #def qalpha_info |
|
572 |
||
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
|
573 |
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
|
574 |
val perm_names = map (fn x => "permute_" ^ x) qty_names |
2337
b151399bd2c3
fixed according to changes in quotient
Christian Urban <urbanc@in.tum.de>
parents:
2336
diff
changeset
|
575 |
val dd = map2 (fn x => fn y => (x, y, NoSyn)) perm_names raw_perm_funs |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
576 |
val lthy13 = define_qperms qtys qty_full_names [] dd raw_perm_laws lthy12c |
2346 | 577 |
|
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
|
578 |
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
|
579 |
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
|
580 |
val _ = warning "Lifting induction"; |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
581 |
val constr_names = map (Long_Name.base_name o fst o dest_Const) []; |
2434 | 582 |
val q_induct = Rule_Cases.name constr_names (the_single (fst (lift_thms qtys [] [raw_induct_thm] lthy13))); |
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
|
583 |
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
|
584 |
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
|
585 |
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
|
586 |
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
|
587 |
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
|
588 |
[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
|
589 |
[Rule_Cases.name constr_names q_induct]) lthy13; |
2296 | 590 |
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
|
591 |
val (_, lthy14a) = Local_Theory.note ((suffix_bind "inducts", []), q_inducts) lthy14; |
2434 | 592 |
val q_perm = fst (lift_thms qtys [] raw_perm_simps lthy14); |
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
|
593 |
val lthy15 = note_simp_suffix "perm" q_perm lthy14a; |
2434 | 594 |
val q_fv = fst (lift_thms qtys [] raw_fv_defs lthy15); |
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
|
595 |
val lthy16 = note_simp_suffix "fv" q_fv lthy15; |
2434 | 596 |
val q_bn = fst (lift_thms qtys [] raw_bn_defs lthy16); |
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
|
597 |
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
|
598 |
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
|
599 |
(*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
|
600 |
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
|
601 |
val eq_iff_unfolded1 = map (Local_Defs.unfold lthy17 @{thms Pair_eqvt}) eq_iff_unfolded0 |
2434 | 602 |
val q_eq_iff_pre0 = fst (lift_thms qtys [] eq_iff_unfolded1 lthy17); |
2089
e9f089a5cc17
Parser changes for compound relations
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2076
diff
changeset
|
603 |
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
|
604 |
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
|
605 |
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
|
606 |
val (_, lthy18) = Local_Theory.note ((suffix_bind "eq_iff", []), q_eq_iff) lthy17; |
2434 | 607 |
val q_dis = fst (lift_thms qtys [] alpha_distincts lthy18); |
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
|
608 |
val lthy19 = note_simp_suffix "distinct" q_dis lthy18; |
2434 | 609 |
val q_eqvt = fst (lift_thms qtys [] (raw_bn_eqvt @ raw_fv_eqvt) lthy19); |
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
|
610 |
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
|
611 |
[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
|
612 |
val _ = warning "Supports"; |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
613 |
val supports = map (prove_supports lthy20 q_perm) []; |
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
|
614 |
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
|
615 |
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
|
616 |
val _ = warning "Instantiating FS"; |
2396
f2f611daf480
updated to Isabelle 12th Aug
Christian Urban <urbanc@in.tum.de>
parents:
2395
diff
changeset
|
617 |
val lthy21 = Class.instantiation (qty_full_names, [], @{sort fs}) thy3; |
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
|
618 |
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
|
619 |
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
|
620 |
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
|
621 |
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
|
622 |
val _ = warning "Support Equations"; |
2409
83990a42a068
more tuning of the code
Christian Urban <urbanc@in.tum.de>
parents:
2407
diff
changeset
|
623 |
fun supp_eq_tac' _ = supp_eq_tac q_induct q_fv q_perm q_eq_iff lthy22 1; |
2023 | 624 |
val q_supp = HOLogic.conj_elims (Goal.prove lthy22 names [] supp_eq_t supp_eq_tac') handle e => |
625 |
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
|
626 |
val lthy23 = note_suffix "supp" q_supp lthy22; |
1941 | 627 |
in |
2020
8468be06bff1
Cheat support equations in new parser
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2017
diff
changeset
|
628 |
(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
|
629 |
end handle TEST ctxt => (0, ctxt) |
1941 | 630 |
*} |
631 |
||
632 |
section {* Preparing and parsing of the specification *} |
|
633 |
||
634 |
ML {* |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
635 |
(* generates the parsed datatypes and |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
636 |
declares the constructors |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
637 |
*) |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
638 |
fun prepare_dts dt_strs thy = |
1941 | 639 |
let |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
640 |
fun inter_fs_sort thy (a, S) = |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
641 |
(a, Type.inter_sort (Sign.tsig_of thy) (@{sort fs}, S)) |
1941 | 642 |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
643 |
fun mk_type tname sorts (cname, cargs, mx) = |
1941 | 644 |
let |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
645 |
val full_tname = Sign.full_name thy tname |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
646 |
val ty = Type (full_tname, map (TFree o inter_fs_sort thy) sorts) |
1941 | 647 |
in |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
648 |
(cname, cargs ---> ty, mx) |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
649 |
end |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
650 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
651 |
fun prep_constr (cname, cargs, mx, _) (constrs, sorts) = |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
652 |
let |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
653 |
val (cargs', sorts') = |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
654 |
fold_map (Datatype.read_typ thy) (map snd cargs) sorts |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
655 |
|>> map (map_type_tfree (TFree o inter_fs_sort thy)) |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
656 |
in |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
657 |
(constrs @ [(cname, cargs', mx)], sorts') |
1941 | 658 |
end |
659 |
||
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
660 |
fun prep_dts (tvs, tname, mx, constrs) (constr_trms, dts, sorts) = |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
661 |
let |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
662 |
val (constrs', sorts') = |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
663 |
fold prep_constr constrs ([], sorts) |
1941 | 664 |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
665 |
val constr_trms' = |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
666 |
map (mk_type tname (rev sorts')) constrs' |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
667 |
in |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
668 |
(constr_trms @ constr_trms', dts @ [(tvs, tname, mx, constrs')], sorts') |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
669 |
end |
2425
715ab84065a0
nominal_datatypes with type variables do not work
Christian Urban <urbanc@in.tum.de>
parents:
2424
diff
changeset
|
670 |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
671 |
val (constr_trms, dts, sorts) = fold prep_dts dt_strs ([], [], []); |
1941 | 672 |
in |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
673 |
thy |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
674 |
|> Sign.add_consts_i constr_trms |
1941 | 675 |
|> pair dts |
676 |
end |
|
677 |
*} |
|
678 |
||
679 |
ML {* |
|
680 |
(* parsing the binding function specification and *) |
|
681 |
(* declaring the functions in the local theory *) |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
682 |
fun prepare_bn_funs bn_fun_strs bn_eq_strs thy = |
1941 | 683 |
let |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
684 |
val lthy = Named_Target.theory_init thy |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
685 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
686 |
val ((bn_funs, bn_eqs), lthy') = |
1941 | 687 |
Specification.read_spec bn_fun_strs bn_eq_strs lthy |
688 |
||
689 |
fun prep_bn_fun ((bn, T), mx) = (bn, T, mx) |
|
690 |
||
691 |
val bn_funs' = map prep_bn_fun bn_funs |
|
692 |
in |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
693 |
(Local_Theory.exit_global lthy') |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
694 |
|> Sign.add_consts_i bn_funs' |
1941 | 695 |
|> pair (bn_funs', bn_eqs) |
696 |
end |
|
697 |
*} |
|
698 |
||
699 |
text {* associates every SOME with the index in the list; drops NONEs *} |
|
700 |
ML {* |
|
701 |
fun indexify xs = |
|
702 |
let |
|
703 |
fun mapp _ [] = [] |
|
704 |
| mapp i (NONE :: xs) = mapp (i + 1) xs |
|
705 |
| mapp i (SOME x :: xs) = (x, i) :: mapp (i + 1) xs |
|
706 |
in |
|
707 |
mapp 0 xs |
|
708 |
end |
|
709 |
||
710 |
fun index_lookup xs x = |
|
711 |
case AList.lookup (op=) xs x of |
|
712 |
SOME x => x |
|
713 |
| NONE => error ("Cannot find " ^ x ^ " as argument annotation."); |
|
714 |
*} |
|
715 |
||
716 |
ML {* |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
717 |
fun prepare_bclauses dt_strs thy = |
1941 | 718 |
let |
719 |
val annos_bclauses = |
|
720 |
get_cnstrs dt_strs |
|
721 |
|> map (map (fn (_, antys, _, bns) => (map fst antys, bns))) |
|
722 |
||
723 |
fun prep_binder env bn_str = |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
724 |
case (Syntax.read_term_global thy bn_str) of |
1941 | 725 |
Free (x, _) => (NONE, index_lookup env x) |
726 |
| Const (a, T) $ Free (x, _) => (SOME (Const (a, T)), index_lookup env x) |
|
727 |
| _ => error ("The term " ^ bn_str ^ " is not allowed as binding function.") |
|
728 |
||
729 |
fun prep_body env bn_str = index_lookup env bn_str |
|
730 |
||
731 |
fun prep_bclause env (mode, binders, bodies) = |
|
732 |
let |
|
733 |
val binders' = map (prep_binder env) binders |
|
734 |
val bodies' = map (prep_body env) bodies |
|
735 |
in |
|
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
736 |
BC (mode, binders', bodies') |
1941 | 737 |
end |
738 |
||
739 |
fun prep_bclauses (annos, bclause_strs) = |
|
740 |
let |
|
741 |
val env = indexify annos (* for every label, associate the index *) |
|
742 |
in |
|
743 |
map (prep_bclause env) bclause_strs |
|
744 |
end |
|
745 |
in |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
746 |
(map (map prep_bclauses) annos_bclauses, thy) |
1941 | 747 |
end |
748 |
*} |
|
749 |
||
1943 | 750 |
text {* |
751 |
adds an empty binding clause for every argument |
|
752 |
that is not already part of a binding clause |
|
753 |
*} |
|
754 |
||
1941 | 755 |
ML {* |
756 |
fun included i bcs = |
|
757 |
let |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
758 |
fun incl (BC (_, bns, bds)) = |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
759 |
member (op =) (map snd bns) i orelse member (op =) bds i |
1941 | 760 |
in |
761 |
exists incl bcs |
|
762 |
end |
|
763 |
*} |
|
764 |
||
765 |
ML {* |
|
766 |
fun complete dt_strs bclauses = |
|
767 |
let |
|
768 |
val args = |
|
769 |
get_cnstrs dt_strs |
|
770 |
|> map (map (fn (_, antys, _, _) => length antys)) |
|
771 |
||
772 |
fun complt n bcs = |
|
773 |
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
|
774 |
fun add bcs i = (if included i bcs then [] else [BC (Lst, [], [i])]) |
1941 | 775 |
in |
776 |
bcs @ (flat (map_range (add bcs) n)) |
|
777 |
end |
|
778 |
in |
|
779 |
map2 (map2 complt) args bclauses |
|
780 |
end |
|
781 |
*} |
|
782 |
||
783 |
ML {* |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
784 |
fun nominal_datatype2_cmd (opt_thm_name, dt_strs, bn_fun_strs, bn_eq_strs) lthy = |
1941 | 785 |
let |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
786 |
val (pre_typ_names, pre_typs) = split_list |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
787 |
(map (fn (tvs, tname, mx, _) => |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
788 |
(Binding.name_of tname, (tname, length tvs, mx))) dt_strs) |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
789 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
790 |
(* this theory is used just for parsing *) |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
791 |
val thy = ProofContext.theory_of lthy |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
792 |
val tmp_thy = Theory.copy thy |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
793 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
794 |
val (((dts, (bn_funs, bn_eqs)), bclauses), tmp_thy') = |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
795 |
tmp_thy |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
796 |
|> Sign.add_types pre_typs |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
797 |
|> prepare_dts dt_strs |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
798 |
||>> prepare_bn_funs bn_fun_strs bn_eq_strs |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
799 |
||>> prepare_bclauses dt_strs |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
800 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
801 |
val bclauses' = complete dt_strs bclauses |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
802 |
val thm_name = |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
803 |
the_default (Binding.name (space_implode "_" pre_typ_names)) opt_thm_name |
1941 | 804 |
in |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
805 |
timeit (fn () => nominal_datatype2 thm_name dts bn_funs bn_eqs bclauses' lthy |> snd) |
1941 | 806 |
end |
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
807 |
*} |
1941 | 808 |
|
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
809 |
ML {* |
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
810 |
(* nominal datatype parser *) |
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
811 |
local |
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
812 |
structure P = Parse; |
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
813 |
structure S = Scan |
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
814 |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
815 |
fun triple ((x, y), z) = (x, y, z) |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
816 |
fun tuple1 ((x, y, z), u) = (x, y, z, u) |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
817 |
fun tuple2 (((x, y), z), u) = (x, y, u, z) |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
818 |
fun tuple3 ((x, y), (z, u)) = (x, y, z, u) |
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
819 |
in |
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
820 |
|
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
821 |
val _ = Keyword.keyword "bind" |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
822 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
823 |
val opt_name = Scan.option (P.binding --| Args.colon) |
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
824 |
|
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
825 |
val anno_typ = S.option (P.name --| P.$$$ "::") -- P.typ |
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
826 |
|
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
827 |
val bind_mode = P.$$$ "bind" |-- |
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
828 |
S.optional (Args.parens |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
829 |
(Args.$$$ "list" >> K Lst || Args.$$$ "set" >> K Set || Args.$$$ "res" >> K Res)) Lst |
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
830 |
|
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
831 |
val bind_clauses = |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
832 |
P.enum "," (bind_mode -- S.repeat1 P.term -- (P.$$$ "in" |-- S.repeat1 P.name) >> triple) |
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
833 |
|
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
834 |
val cnstr_parser = |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
835 |
P.binding -- S.repeat anno_typ -- bind_clauses -- P.opt_mixfix >> tuple2 |
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
836 |
|
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
837 |
(* datatype parser *) |
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
838 |
val dt_parser = |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
839 |
(P.type_args -- P.binding -- P.opt_mixfix >> triple) -- |
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
840 |
(P.$$$ "=" |-- P.enum1 "|" cnstr_parser) >> tuple1 |
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
841 |
|
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
842 |
(* binding function parser *) |
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
843 |
val bnfun_parser = |
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
844 |
S.optional (P.$$$ "binder" |-- P.fixes -- Parse_Spec.where_alt_specs) ([], []) |
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
845 |
|
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
846 |
(* main parser *) |
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
847 |
val main_parser = |
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents:
2430
diff
changeset
|
848 |
opt_name -- P.and_list1 dt_parser -- bnfun_parser >> tuple3 |
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
849 |
|
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
parents:
2411
diff
changeset
|
850 |
end |
1941 | 851 |
|
852 |
(* Command Keyword *) |
|
2168 | 853 |
val _ = Outer_Syntax.local_theory "nominal_datatype" "test" Keyword.thy_decl |
1941 | 854 |
(main_parser >> nominal_datatype2_cmd) |
855 |
*} |
|
856 |
||
2292 | 857 |
|
858 |
text {* |
|
859 |
nominal_datatype2 does the following things in order: |
|
1941 | 860 |
|
2292 | 861 |
Parser.thy/raw_nominal_decls |
862 |
1) define the raw datatype |
|
863 |
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
|
864 |
|
2292 | 865 |
Perm.thy/define_raw_perms |
866 |
3) define permutations of the raw datatype and show that the raw type is |
|
867 |
in the pt typeclass |
|
868 |
||
869 |
Lift.thy/define_fv_alpha_export, Fv.thy/define_fv & define_alpha |
|
870 |
4) define fv and fv_bn |
|
871 |
5) define alpha and alpha_bn |
|
1941 | 872 |
|
2292 | 873 |
Perm.thy/distinct_rel |
874 |
6) prove alpha_distincts (C1 x \<notsimeq> C2 y ...) (Proof by cases; simp) |
|
1941 | 875 |
|
2292 | 876 |
Tacs.thy/build_rel_inj |
877 |
6) prove alpha_eq_iff (C1 x = C2 y \<leftrightarrow> P x y ...) |
|
878 |
(left-to-right by intro rule, right-to-left by cases; simp) |
|
879 |
Equivp.thy/prove_eqvt |
|
880 |
7) prove bn_eqvt (common induction on the raw datatype) |
|
881 |
8) prove fv_eqvt (common induction on the raw datatype with help of above) |
|
882 |
Rsp.thy/build_alpha_eqvts |
|
883 |
9) prove alpha_eqvt and alpha_bn_eqvt |
|
884 |
(common alpha-induction, unfolding alpha_gen, permute of #* and =) |
|
885 |
Equivp.thy/build_alpha_refl & Equivp.thy/build_equivps |
|
886 |
10) prove that alpha and alpha_bn are equivalence relations |
|
887 |
(common induction and application of 'compose' lemmas) |
|
888 |
Lift.thy/define_quotient_types |
|
889 |
11) define quotient types |
|
890 |
Rsp.thy/build_fvbv_rsps |
|
891 |
12) prove bn respects (common induction and simp with alpha_gen) |
|
892 |
Rsp.thy/prove_const_rsp |
|
893 |
13) prove fv respects (common induction and simp with alpha_gen) |
|
894 |
14) prove permute respects (unfolds to alpha_eqvt) |
|
895 |
Rsp.thy/prove_alpha_bn_rsp |
|
896 |
15) prove alpha_bn respects |
|
897 |
(alpha_induct then cases then sym and trans of the relations) |
|
898 |
Rsp.thy/prove_alpha_alphabn |
|
899 |
16) show that alpha implies alpha_bn (by unduction, needed in following step) |
|
900 |
Rsp.thy/prove_const_rsp |
|
901 |
17) prove respects for all datatype constructors |
|
902 |
(unfold eq_iff and alpha_gen; introduce zero permutations; simp) |
|
903 |
Perm.thy/quotient_lift_consts_export |
|
904 |
18) define lifted constructors, fv, bn, alpha_bn, permutations |
|
905 |
Perm.thy/define_lifted_perms |
|
906 |
19) lift permutation zero and add properties to show that quotient type is in the pt typeclass |
|
907 |
Lift.thy/lift_thm |
|
908 |
20) lift permutation simplifications |
|
909 |
21) lift induction |
|
910 |
22) lift fv |
|
911 |
23) lift bn |
|
912 |
24) lift eq_iff |
|
913 |
25) lift alpha_distincts |
|
914 |
26) lift fv and bn eqvts |
|
915 |
Equivp.thy/prove_supports |
|
916 |
27) prove that union of arguments supports constructors |
|
917 |
Equivp.thy/prove_fs |
|
918 |
28) show that the lifted type is in fs typeclass (* by q_induct, supports *) |
|
919 |
Equivp.thy/supp_eq |
|
920 |
29) prove supp = fv |
|
921 |
*} |
|
1964
209ee65b2395
added some further problemetic tests
Christian Urban <urbanc@in.tum.de>
parents:
1963
diff
changeset
|
922 |
|
1941 | 923 |
|
924 |
||
925 |
end |
|
926 |
||
927 |
||
928 |