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