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