2454
+ − 1
theory Nominal2
2435
+ − 2
imports
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 3
Nominal2_Base Nominal2_Abs
2598
+ − 4
uses ("nominal_dt_rawfuns.ML")
2435
+ − 5
("nominal_dt_alpha.ML")
+ − 6
("nominal_dt_quot.ML")
2631
e73bd379e839
removed local fix for bug in induction_schema; added setup method for strong inductions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 7
("nominal_induct.ML")
2819
+ − 8
("nominal_inductive.ML")
+ − 9
("nominal_function_common.ML")
2665
+ − 10
("nominal_function_core.ML")
+ − 11
("nominal_mutual.ML")
+ − 12
("nominal_function.ML")
1941
+ − 13
begin
+ − 14
2435
+ − 15
use "nominal_dt_rawfuns.ML"
+ − 16
ML {* open Nominal_Dt_RawFuns *}
+ − 17
+ − 18
use "nominal_dt_alpha.ML"
+ − 19
ML {* open Nominal_Dt_Alpha *}
+ − 20
+ − 21
use "nominal_dt_quot.ML"
+ − 22
ML {* open Nominal_Dt_Quot *}
+ − 23
2631
e73bd379e839
removed local fix for bug in induction_schema; added setup method for strong inductions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 24
(*****************************************)
e73bd379e839
removed local fix for bug in induction_schema; added setup method for strong inductions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 25
(* setup for induction principles method *)
e73bd379e839
removed local fix for bug in induction_schema; added setup method for strong inductions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 26
use "nominal_induct.ML"
e73bd379e839
removed local fix for bug in induction_schema; added setup method for strong inductions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 27
method_setup nominal_induct =
e73bd379e839
removed local fix for bug in induction_schema; added setup method for strong inductions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 28
{* NominalInduct.nominal_induct_method *}
e73bd379e839
removed local fix for bug in induction_schema; added setup method for strong inductions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 29
{* nominal induction *}
2609
666ffc8a92a9
freshness theorem in strong exhausts; (temporarily includes a cheat_tac to make all tests go through)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 30
2639
+ − 31
(****************************************************)
+ − 32
(* inductive definition involving nominal datatypes *)
+ − 33
use "nominal_inductive.ML"
+ − 34
+ − 35
2665
+ − 36
(***************************************)
+ − 37
(* forked code of the function package *)
+ − 38
(* for defining nominal functions *)
2819
+ − 39
use "nominal_function_common.ML"
2665
+ − 40
use "nominal_function_core.ML"
+ − 41
use "nominal_mutual.ML"
+ − 42
use "nominal_function.ML"
+ − 43
2603
+ − 44
ML {*
+ − 45
val eqvt_attr = Attrib.internal (K Nominal_ThmDecls.eqvt_add)
+ − 46
val rsp_attr = Attrib.internal (K Quotient_Info.rsp_rules_add)
+ − 47
val simp_attr = Attrib.internal (K Simplifier.simp_add)
2787
1a6593bc494d
added eq_iff and distinct lemmas of nominal datatypes to the simplifier
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 48
val induct_attr = Attrib.internal (K Induct.induct_simp_add)
2603
+ − 49
*}
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
+ − 50
1941
+ − 51
section{* Interface for nominal_datatype *}
+ − 52
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
+ − 53
ML {* print_depth 50 *}
1941
+ − 54
+ − 55
ML {*
+ − 56
fun get_cnstrs dts =
+ − 57
map (fn (_, _, _, constrs) => constrs) dts
+ − 58
+ − 59
fun get_typed_cnstrs dts =
+ − 60
flat (map (fn (_, bn, _, constrs) =>
+ − 61
(map (fn (bn', _, _) => (Binding.name_of bn, Binding.name_of bn')) constrs)) dts)
+ − 62
+ − 63
fun get_cnstr_strs dts =
+ − 64
map (fn (bn, _, _) => Binding.name_of bn) (flat (get_cnstrs dts))
+ − 65
+ − 66
fun get_bn_fun_strs bn_funs =
+ − 67
map (fn (bn_fun, _, _) => Binding.name_of bn_fun) bn_funs
+ − 68
*}
+ − 69
2106
+ − 70
1944
+ − 71
text {* Infrastructure for adding "_raw" to types and terms *}
+ − 72
1941
+ − 73
ML {*
+ − 74
fun add_raw s = s ^ "_raw"
+ − 75
fun add_raws ss = map add_raw ss
+ − 76
fun raw_bind bn = Binding.suffix_name "_raw" bn
+ − 77
+ − 78
fun replace_str ss s =
+ − 79
case (AList.lookup (op=) ss s) of
+ − 80
SOME s' => s'
+ − 81
| NONE => s
+ − 82
+ − 83
fun replace_typ ty_ss (Type (a, Ts)) = Type (replace_str ty_ss a, map (replace_typ ty_ss) Ts)
+ − 84
| replace_typ ty_ss T = T
+ − 85
+ − 86
fun raw_dts ty_ss dts =
+ − 87
let
2640
75d353e8e60e
made sure the raw datatypes and raw functions do not get any mixfix syntax
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 88
fun raw_dts_aux1 (bind, tys, _) =
75d353e8e60e
made sure the raw datatypes and raw functions do not get any mixfix syntax
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 89
(raw_bind bind, map (replace_typ ty_ss) tys, NoSyn)
1941
+ − 90
2640
75d353e8e60e
made sure the raw datatypes and raw functions do not get any mixfix syntax
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 91
fun raw_dts_aux2 (ty_args, bind, _, constrs) =
75d353e8e60e
made sure the raw datatypes and raw functions do not get any mixfix syntax
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 92
(ty_args, raw_bind bind, NoSyn, map raw_dts_aux1 constrs)
1941
+ − 93
in
+ − 94
map raw_dts_aux2 dts
+ − 95
end
+ − 96
+ − 97
fun replace_aterm trm_ss (Const (a, T)) = Const (replace_str trm_ss a, T)
+ − 98
| replace_aterm trm_ss (Free (a, T)) = Free (replace_str trm_ss a, T)
+ − 99
| replace_aterm trm_ss trm = trm
+ − 100
+ − 101
fun replace_term trm_ss ty_ss trm =
+ − 102
trm |> Term.map_aterms (replace_aterm trm_ss) |> map_types (replace_typ ty_ss)
+ − 103
*}
+ − 104
+ − 105
ML {*
+ − 106
fun rawify_dts dt_names dts dts_env =
+ − 107
let
+ − 108
val raw_dts = raw_dts dts_env dts
+ − 109
val raw_dt_names = add_raws dt_names
+ − 110
in
+ − 111
(raw_dt_names, raw_dts)
+ − 112
end
+ − 113
*}
+ − 114
+ − 115
ML {*
+ − 116
fun rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs =
+ − 117
let
2640
75d353e8e60e
made sure the raw datatypes and raw functions do not get any mixfix syntax
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 118
val bn_funs' = map (fn (bn, ty, _) =>
75d353e8e60e
made sure the raw datatypes and raw functions do not get any mixfix syntax
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 119
(raw_bind bn, SOME (replace_typ dts_env ty), NoSyn)) bn_funs
1941
+ − 120
+ − 121
val bn_eqs' = map (fn (attr, trm) =>
+ − 122
(attr, replace_term (cnstrs_env @ bn_fun_env) dts_env trm)) bn_eqs
+ − 123
in
+ − 124
(bn_funs', bn_eqs')
+ − 125
end
+ − 126
*}
+ − 127
+ − 128
ML {*
+ − 129
fun rawify_bclauses dts_env cnstrs_env bn_fun_env bclauses =
+ − 130
let
+ − 131
fun rawify_bnds bnds =
+ − 132
map (apfst (Option.map (replace_term (cnstrs_env @ bn_fun_env) dts_env))) bnds
+ − 133
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
+ − 134
fun rawify_bclause (BC (mode, bnds, bdys)) = BC (mode, rawify_bnds bnds, bdys)
1941
+ − 135
in
2612
+ − 136
(map o map o map) rawify_bclause bclauses
1941
+ − 137
end
+ − 138
*}
+ − 139
+ − 140
+ − 141
ML {*
2600
ca6b4bc7a871
kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 142
fun define_raw_dts dts bn_funs bn_eqs bclauses lthy =
1941
+ − 143
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 144
val thy = Local_Theory.exit_global lthy
1941
+ − 145
val thy_name = Context.theory_name thy
+ − 146
+ − 147
val dt_names = map (fn (_, s, _, _) => Binding.name_of s) dts
+ − 148
val dt_full_names = map (Long_Name.qualify thy_name) dt_names
+ − 149
val dt_full_names' = add_raws dt_full_names
+ − 150
val dts_env = dt_full_names ~~ dt_full_names'
+ − 151
2633
+ − 152
val cnstr_names = get_cnstr_strs dts
+ − 153
val cnstr_tys = get_typed_cnstrs dts
+ − 154
val cnstr_full_names = map (Long_Name.qualify thy_name) cnstr_names
+ − 155
val cnstr_full_names' = map (fn (x, y) => Long_Name.qualify thy_name
+ − 156
(Long_Name.qualify (add_raw x) (add_raw y))) cnstr_tys
+ − 157
val cnstrs_env = cnstr_full_names ~~ cnstr_full_names'
1941
+ − 158
+ − 159
val bn_fun_strs = get_bn_fun_strs bn_funs
+ − 160
val bn_fun_strs' = add_raws bn_fun_strs
+ − 161
val bn_fun_env = bn_fun_strs ~~ bn_fun_strs'
+ − 162
val bn_fun_full_env = map (pairself (Long_Name.qualify thy_name))
+ − 163
(bn_fun_strs ~~ bn_fun_strs')
+ − 164
+ − 165
val (raw_dt_names, raw_dts) = rawify_dts dt_names dts dts_env
+ − 166
val (raw_bn_funs, raw_bn_eqs) = rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs
2600
ca6b4bc7a871
kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 167
val raw_bclauses = rawify_bclauses dts_env cnstrs_env bn_fun_full_env bclauses
1941
+ − 168
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 169
val (raw_dt_full_names, thy1) =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 170
Datatype.add_datatype Datatype.default_config raw_dt_names raw_dts thy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 171
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 172
val lthy1 = Named_Target.theory_init thy1
2304
+ − 173
in
2633
+ − 174
(raw_dt_full_names, raw_dts, raw_bclauses, raw_bn_funs, raw_bn_eqs, cnstr_names, lthy1)
2304
+ − 175
end
+ − 176
*}
+ − 177
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
+ − 178
1941
+ − 179
ML {*
2436
+ − 180
fun nominal_datatype2 opt_thms_name dts bn_funs bn_eqs bclauses lthy =
1941
+ − 181
let
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 182
val _ = trace_msg (K "Defining raw datatypes...")
2633
+ − 183
val (raw_dt_names, raw_dts, raw_bclauses, raw_bn_funs, raw_bn_eqs, cnstr_names, lthy0) =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 184
define_raw_dts dts bn_funs bn_eqs bclauses lthy
1941
+ − 185
2304
+ − 186
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
+ − 187
val {descr, sorts, ...} = dtinfo
2407
+ − 188
2400
+ − 189
val raw_tys = all_dtyps descr sorts
+ − 190
val raw_full_ty_names = map (fst o dest_Type) raw_tys
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 191
val tvs = hd raw_tys
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 192
|> snd o dest_Type
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 193
|> map dest_TFree
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 194
2400
+ − 195
val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy0)) raw_full_ty_names
+ − 196
2407
+ − 197
val raw_cns_info = all_dtyp_constrs_types descr sorts
2612
+ − 198
val raw_constrs = (map o map) (fn (c, _, _, _) => c) raw_cns_info
2407
+ − 199
2400
+ − 200
val raw_inject_thms = flat (map #inject dtinfos)
+ − 201
val raw_distinct_thms = flat (map #distinct dtinfos)
+ − 202
val raw_induct_thm = #induct dtinfo
+ − 203
val raw_induct_thms = #inducts dtinfo
+ − 204
val raw_exhaust_thms = map #exhaust dtinfos
2611
3d101f2f817c
simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 205
val raw_size_trms = map HOLogic.size_const raw_tys
2388
+ − 206
val raw_size_thms = Size.size_thms (ProofContext.theory_of lthy0) (hd raw_dt_names)
+ − 207
|> `(fn thms => (length thms) div 2)
2392
+ − 208
|> uncurry drop
2388
+ − 209
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 210
val _ = trace_msg (K "Defining raw permutations...")
2401
7645e18e8b19
modified the code for class instantiations (with help from Florian)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 211
val ((raw_perm_funs, raw_perm_simps, raw_perm_laws), lthy2a) =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 212
define_raw_perms raw_full_ty_names raw_tys tvs (flat raw_constrs) raw_induct_thm lthy0
2144
+ − 213
+ − 214
(* noting the raw permutations as eqvt theorems *)
2448
+ − 215
val (_, lthy3) = Local_Theory.note ((Binding.empty, [eqvt_attr]), 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
+ − 216
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 217
val _ = trace_msg (K "Defining raw fv- and bn-functions...")
2405
+ − 218
val (raw_bns, raw_bn_defs, raw_bn_info, raw_bn_induct, lthy3a) =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 219
define_raw_bns raw_full_ty_names raw_dts raw_bn_funs raw_bn_eqs
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 220
(raw_inject_thms @ raw_distinct_thms) raw_size_thms lthy3
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 221
2560
+ − 222
(* defining the permute_bn functions *)
2561
+ − 223
val (raw_perm_bns, raw_perm_bn_simps, lthy3b) =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 224
define_raw_bn_perms raw_tys raw_bn_info raw_cns_info
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 225
(raw_inject_thms @ raw_distinct_thms) raw_size_thms lthy3a
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 226
2560
+ − 227
val (raw_fvs, raw_fv_bns, raw_fv_defs, raw_fv_bns_induct, lthy3c) =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 228
define_raw_fvs raw_full_ty_names raw_tys raw_cns_info raw_bn_info raw_bclauses
2560
+ − 229
(raw_inject_thms @ raw_distinct_thms) raw_size_thms lthy3b
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 230
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 231
val _ = trace_msg (K "Defining alpha relations...")
2300
+ − 232
val (alpha_trms, alpha_bn_trms, alpha_intros, alpha_cases, alpha_induct, lthy4) =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 233
define_raw_alpha raw_full_ty_names raw_tys raw_cns_info raw_bn_info raw_bclauses raw_fvs lthy3c
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 234
2336
+ − 235
val alpha_tys = map (domain_type o fastype_of) alpha_trms
+ − 236
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 237
val _ = trace_msg (K "Proving distinct theorems...")
2399
+ − 238
val alpha_distincts =
2400
+ − 239
mk_alpha_distincts lthy4 alpha_cases raw_distinct_thms alpha_trms raw_tys
2300
+ − 240
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 241
val _ = trace_msg (K "Proving eq-iff theorems...")
2475
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 242
val alpha_eq_iff =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 243
mk_alpha_eq_iff lthy4 alpha_intros raw_distinct_thms raw_inject_thms alpha_cases
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 244
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 245
val _ = trace_msg (K "Proving equivariance of bns, fvs, size and alpha...")
2406
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 246
val raw_bn_eqvt =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 247
raw_prove_eqvt raw_bns raw_bn_induct (raw_bn_defs @ raw_perm_simps) lthy4
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 248
2406
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 249
(* noting the raw_bn_eqvt lemmas in a temprorary theory *)
2448
+ − 250
val lthy_tmp = snd (Local_Theory.note ((Binding.empty, [eqvt_attr]), raw_bn_eqvt) lthy4)
2305
+ − 251
2406
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 252
val raw_fv_eqvt =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 253
raw_prove_eqvt (raw_fvs @ raw_fv_bns) raw_fv_bns_induct (raw_fv_defs @ raw_perm_simps)
2388
+ − 254
(Local_Theory.restore lthy_tmp)
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 255
2389
+ − 256
val raw_size_eqvt =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 257
raw_prove_eqvt raw_size_trms raw_induct_thms (raw_size_thms @ raw_perm_simps)
2388
+ − 258
(Local_Theory.restore lthy_tmp)
2389
+ − 259
|> map (rewrite_rule @{thms permute_nat_def[THEN eq_reflection]})
+ − 260
|> map (fn thm => thm RS @{thm sym})
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 261
2448
+ − 262
val lthy5 = snd (Local_Theory.note ((Binding.empty, [eqvt_attr]), raw_fv_eqvt) lthy_tmp)
2306
+ − 263
2336
+ − 264
val (alpha_eqvt, lthy6) =
2650
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 265
Nominal_Eqvt.raw_equivariance true (alpha_trms @ alpha_bn_trms) alpha_induct alpha_intros lthy5
2311
+ − 266
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 267
val _ = trace_msg (K "Proving equivalence of alpha...")
2316
+ − 268
val alpha_refl_thms =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 269
raw_prove_refl alpha_trms alpha_bn_trms alpha_intros raw_induct_thm lthy6
2316
+ − 270
2311
+ − 271
val alpha_sym_thms =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 272
raw_prove_sym (alpha_trms @ alpha_bn_trms) alpha_intros alpha_induct lthy6
2298
+ − 273
2311
+ − 274
val alpha_trans_thms =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 275
raw_prove_trans (alpha_trms @ alpha_bn_trms) (raw_distinct_thms @ raw_inject_thms)
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 276
alpha_intros alpha_induct alpha_cases lthy6
2311
+ − 277
2404
+ − 278
val (alpha_equivp_thms, alpha_bn_equivp_thms) =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 279
raw_prove_equivp alpha_trms alpha_bn_trms alpha_refl_thms alpha_sym_thms
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 280
alpha_trans_thms lthy6
2322
+ − 281
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 282
val _ = trace_msg (K "Proving alpha implies bn...")
2320
+ − 283
val alpha_bn_imp_thms =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 284
raw_prove_bn_imp alpha_trms alpha_bn_trms alpha_intros alpha_induct lthy6
2322
+ − 285
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 286
val _ = trace_msg (K "Proving respectfulness...")
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 287
val raw_funs_rsp_aux =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 288
raw_fv_bn_rsp_aux alpha_trms alpha_bn_trms raw_fvs
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 289
raw_bns raw_fv_bns alpha_induct (raw_bn_defs @ raw_fv_defs) lthy6
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 290
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 291
val raw_funs_rsp = map mk_funs_rsp raw_funs_rsp_aux
2388
+ − 292
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 293
val raw_size_rsp =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 294
raw_size_rsp_aux (alpha_trms @ alpha_bn_trms) alpha_induct
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 295
(raw_size_thms @ raw_size_eqvt) lthy6
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 296
|> map mk_funs_rsp
2392
+ − 297
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 298
val raw_constrs_rsp =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 299
raw_constrs_rsp (flat raw_constrs) alpha_trms alpha_intros
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 300
(alpha_bn_imp_thms @ raw_funs_rsp_aux) lthy6
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 301
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 302
val alpha_permute_rsp = map mk_alpha_permute_rsp alpha_eqvt
2384
+ − 303
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 304
val alpha_bn_rsp =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 305
raw_alpha_bn_rsp alpha_bn_trms alpha_bn_equivp_thms alpha_bn_imp_thms
2404
+ − 306
2561
+ − 307
val raw_perm_bn_rsp =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 308
raw_perm_bn_rsp (alpha_trms @ alpha_bn_trms) raw_perm_bns alpha_induct
2561
+ − 309
alpha_intros raw_perm_bn_simps lthy6
+ − 310
2398
+ − 311
(* noting the quot_respects lemmas *)
+ − 312
val (_, lthy6a) =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 313
Local_Theory.note ((Binding.empty, [rsp_attr]),
2561
+ − 314
raw_constrs_rsp @ raw_funs_rsp @ raw_size_rsp @ alpha_permute_rsp @
+ − 315
alpha_bn_rsp @ raw_perm_bn_rsp) lthy6
2398
+ − 316
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 317
val _ = trace_msg (K "Defining the quotient types...")
2336
+ − 318
val qty_descr = map (fn (vs, bind, mx, _) => (vs, bind, mx)) dts
2400
+ − 319
2336
+ − 320
val (qty_infos, lthy7) =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 321
define_qtypes qty_descr alpha_tys alpha_trms alpha_equivp_thms lthy6a
2336
+ − 322
+ − 323
val qtys = map #qtyp qty_infos
2400
+ − 324
val qty_full_names = map (fst o dest_Type) qtys
+ − 325
val qty_names = map Long_Name.base_name qty_full_names
+ − 326
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 327
val _ = trace_msg (K "Defining the quotient constants...")
2600
ca6b4bc7a871
kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 328
val qconstrs_descrs =
2781
+ − 329
(map2 o map2) (fn (b, _, mx) => fn t => (Variable.check_name b, t, mx)) (get_cnstrs dts) raw_constrs
2338
+ − 330
2339
+ − 331
val qbns_descr =
2781
+ − 332
map2 (fn (b, _, mx) => fn t => (Variable.check_name b, t, mx)) bn_funs raw_bns
2339
+ − 333
+ − 334
val qfvs_descr =
2346
+ − 335
map2 (fn n => fn t => ("fv_" ^ n, t, NoSyn)) qty_names raw_fvs
2339
+ − 336
2346
+ − 337
val qfv_bns_descr =
2781
+ − 338
map2 (fn (b, _, _) => fn t => ("fv_" ^ Variable.check_name b, t, NoSyn)) bn_funs raw_fv_bns
2339
+ − 339
2384
+ − 340
val qalpha_bns_descr =
2781
+ − 341
map2 (fn (b, _, _) => fn t => ("alpha_" ^ Variable.check_name b, t, NoSyn)) bn_funs alpha_bn_trms
2384
+ − 342
2398
+ − 343
val qperm_descr =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 344
map2 (fn n => fn t => ("permute_" ^ n, Type.legacy_freeze t, NoSyn)) qty_names raw_perm_funs
2398
+ − 345
2400
+ − 346
val qsize_descr =
+ − 347
map2 (fn n => fn t => ("size_" ^ n, t, NoSyn)) qty_names raw_size_trms
+ − 348
2562
+ − 349
val qperm_bn_descr =
2781
+ − 350
map2 (fn (b, _, _) => fn t => ("permute_" ^ Variable.check_name b, t, NoSyn)) bn_funs raw_perm_bns
2562
+ − 351
2600
ca6b4bc7a871
kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 352
val ((((((qconstrs_infos, qbns_info), qfvs_info), qfv_bns_info), qalpha_bns_info), qperm_bns_info),
ca6b4bc7a871
kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 353
lthy8) =
2346
+ − 354
lthy7
2600
ca6b4bc7a871
kept the nested structure of constructors (belonging to one datatype)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 355
|> fold_map (define_qconsts qtys) qconstrs_descrs
2400
+ − 356
||>> define_qconsts qtys qbns_descr
+ − 357
||>> define_qconsts qtys qfvs_descr
+ − 358
||>> define_qconsts qtys qfv_bns_descr
+ − 359
||>> define_qconsts qtys qalpha_bns_descr
2562
+ − 360
||>> define_qconsts qtys qperm_bn_descr
2338
+ − 361
2400
+ − 362
val lthy9 =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 363
define_qperms qtys qty_full_names tvs qperm_descr raw_perm_laws lthy8
2400
+ − 364
2401
7645e18e8b19
modified the code for class instantiations (with help from Florian)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 365
val lthy9a =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 366
define_qsizes qtys qty_full_names tvs qsize_descr lthy9
2398
+ − 367
2612
+ − 368
val qtrms = (map o map) #qconst qconstrs_infos
2346
+ − 369
val qbns = map #qconst qbns_info
+ − 370
val qfvs = map #qconst qfvs_info
+ − 371
val qfv_bns = map #qconst qfv_bns_info
2384
+ − 372
val qalpha_bns = map #qconst qalpha_bns_info
2593
25dcb2b1329e
ordered raw_bn_info to agree with the order of the raw_bn_functions; started alpha_bn proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 373
val qperm_bns = map #qconst qperm_bns_info
2434
+ − 374
2649
a8ebcb368a15
a modified function package where, as a test, True has been injected into the compatibility condictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 375
val _ = trace_msg (K "Lifting of theorems...")
2559
add799cf0817
adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 376
val eq_iff_simps = @{thms alphas permute_prod.simps prod_fv.simps prod_alpha_def prod_rel_def
2434
+ − 377
prod.cases}
+ − 378
+ − 379
val ((((((qdistincts, qeq_iffs), qfv_defs), qbn_defs), qperm_simps), qfv_qbn_eqvts), lthyA) =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 380
lthy9a
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 381
|> lift_thms qtys [] alpha_distincts
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 382
||>> lift_thms qtys eq_iff_simps alpha_eq_iff
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 383
||>> lift_thms qtys [] raw_fv_defs
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 384
||>> lift_thms qtys [] raw_bn_defs
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 385
||>> lift_thms qtys [] raw_perm_simps
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 386
||>> lift_thms qtys [] (raw_fv_eqvt @ raw_bn_eqvt)
2434
+ − 387
2594
+ − 388
val ((((((qsize_eqvt, [qinduct]), qexhausts), qsize_simps), qperm_bn_simps), qalpha_refl_thms), lthyB) =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 389
lthyA
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 390
|> lift_thms qtys [] raw_size_eqvt
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 391
||>> lift_thms qtys [] [raw_induct_thm]
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 392
||>> lift_thms qtys [] raw_exhaust_thms
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 393
||>> lift_thms qtys [] raw_size_thms
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 394
||>> lift_thms qtys [] raw_perm_bn_simps
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 395
||>> lift_thms qtys [] alpha_refl_thms
2434
+ − 396
2474
+ − 397
val qinducts = Project_Rule.projections lthyA qinduct
+ − 398
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 399
val _ = trace_msg (K "Proving supp lemmas and fs-instances...")
2448
+ − 400
val qsupports_thms =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 401
prove_supports lthyB qperm_simps (flat qtrms)
2448
+ − 402
2451
+ − 403
(* finite supp lemmas *)
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 404
val qfsupp_thms = prove_fsupp lthyB qtys qinduct qsupports_thms
2450
+ − 405
2451
+ − 406
(* fs instances *)
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 407
val lthyC = fs_instance qtys qty_full_names tvs qfsupp_thms lthyB
2448
+ − 408
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 409
val _ = trace_msg (K "Proving equality between fv and supp...")
2475
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 410
val qfv_supp_thms =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 411
prove_fv_supp qtys (flat qtrms) qfvs qfv_bns qalpha_bns qfv_defs qeq_iffs
2481
3a5ebb2fcdbf
made supp proofs more robust by not using the standard induction; renamed some example files
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 412
qperm_simps qfv_qbn_eqvts qinduct (flat raw_bclauses) lthyC
2475
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 413
2492
5ac9a74d22fd
post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 414
(* postprocessing of eq and fv theorems *)
5ac9a74d22fd
post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 415
val qeq_iffs' = qeq_iffs
2493
+ − 416
|> map (simplify (HOL_basic_ss addsimps qfv_supp_thms))
+ − 417
|> map (simplify (HOL_basic_ss addsimps @{thms prod_fv_supp prod_alpha_eq Abs_eq_iff[symmetric]}))
2492
5ac9a74d22fd
post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 418
5ac9a74d22fd
post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 419
val qsupp_constrs = qfv_defs
5ac9a74d22fd
post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 420
|> map (simplify (HOL_basic_ss addsimps (take (length qfvs) qfv_supp_thms)))
5ac9a74d22fd
post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 421
2493
+ − 422
val transform_thm = @{lemma "x = y \<Longrightarrow> a \<notin> x \<longleftrightarrow> a \<notin> y" by simp}
+ − 423
val transform_thms =
+ − 424
[ @{lemma "a \<notin> (S \<union> T) \<longleftrightarrow> a \<notin> S \<and> a \<notin> T" by simp},
+ − 425
@{lemma "a \<notin> (S - T) \<longleftrightarrow> a \<notin> S \<or> a \<in> T" by simp},
+ − 426
@{lemma "(lhs = (a \<notin> {})) \<longleftrightarrow> lhs" by simp},
+ − 427
@{thm fresh_def[symmetric]}]
+ − 428
+ − 429
val qfresh_constrs = qsupp_constrs
+ − 430
|> map (fn thm => thm RS transform_thm)
+ − 431
|> map (simplify (HOL_basic_ss addsimps transform_thms))
+ − 432
2593
25dcb2b1329e
ordered raw_bn_info to agree with the order of the raw_bn_functions; started alpha_bn proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 433
(* proving that the qbn result is finite *)
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 434
val qbn_finite_thms = prove_bns_finite qtys qbns qinduct qbn_defs lthyC
2593
25dcb2b1329e
ordered raw_bn_info to agree with the order of the raw_bn_functions; started alpha_bn proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 435
25dcb2b1329e
ordered raw_bn_info to agree with the order of the raw_bn_functions; started alpha_bn proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 436
(* proving that perm_bns preserve alpha *)
2594
+ − 437
val qperm_bn_alpha_thms =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 438
prove_perm_bn_alpha_thms qtys qperm_bns qalpha_bns qinduct qperm_bn_simps qeq_iffs'
2594
+ − 439
qalpha_refl_thms lthyC
2493
+ − 440
2598
+ − 441
(* proving the relationship of bn and permute_bn *)
+ − 442
val qpermute_bn_thms =
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 443
prove_permute_bn_thms qtys qbns qperm_bns qinduct qperm_bn_simps qbn_defs qfv_qbn_eqvts lthyC
2598
+ − 444
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 445
val _ = trace_msg (K "Proving strong exhaust lemmas...")
2619
+ − 446
val qstrong_exhaust_thms = prove_strong_exhausts lthyC qexhausts bclauses qbn_finite_thms qeq_iffs'
2616
dd7490fdd998
all examples for strong exhausts work; recursive binders need to be treated differently; still unclean version with lots of diagnostic code
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 447
qfv_qbn_eqvts qpermute_bn_thms qperm_bn_alpha_thms
dd7490fdd998
all examples for strong exhausts work; recursive binders need to be treated differently; still unclean version with lots of diagnostic code
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 448
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 449
val _ = trace_msg (K "Proving strong induct lemmas...")
2633
+ − 450
val qstrong_induct_thms = prove_strong_induct lthyC qinduct qstrong_exhaust_thms qsize_simps bclauses
2628
+ − 451
2436
+ − 452
(* noting the theorems *)
+ − 453
+ − 454
(* generating the prefix for the theorem names *)
+ − 455
val thms_name =
+ − 456
the_default (Binding.name (space_implode "_" qty_names)) opt_thms_name
+ − 457
fun thms_suffix s = Binding.qualified true s thms_name
2633
+ − 458
val case_names_attr = Attrib.internal (K (Rule_Cases.case_names cnstr_names))
2436
+ − 459
2451
+ − 460
val (_, lthy9') = lthyC
2787
1a6593bc494d
added eq_iff and distinct lemmas of nominal datatypes to the simplifier
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 461
|> Local_Theory.note ((thms_suffix "distinct", [induct_attr, simp_attr]), qdistincts)
1a6593bc494d
added eq_iff and distinct lemmas of nominal datatypes to the simplifier
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 462
||>> Local_Theory.note ((thms_suffix "eq_iff", [induct_attr, simp_attr]), qeq_iffs')
2436
+ − 463
||>> Local_Theory.note ((thms_suffix "fv_defs", []), qfv_defs)
+ − 464
||>> Local_Theory.note ((thms_suffix "bn_defs", []), qbn_defs)
2448
+ − 465
||>> Local_Theory.note ((thms_suffix "perm_simps", [eqvt_attr, simp_attr]), qperm_simps)
2436
+ − 466
||>> Local_Theory.note ((thms_suffix "fv_bn_eqvt", []), qfv_qbn_eqvts)
2487
+ − 467
||>> Local_Theory.note ((thms_suffix "size", []), qsize_simps)
2436
+ − 468
||>> Local_Theory.note ((thms_suffix "size_eqvt", []), qsize_eqvt)
2633
+ − 469
||>> Local_Theory.note ((thms_suffix "induct", [case_names_attr]), [qinduct])
+ − 470
||>> Local_Theory.note ((thms_suffix "inducts", [case_names_attr]), qinducts)
+ − 471
||>> Local_Theory.note ((thms_suffix "exhaust", [case_names_attr]), qexhausts)
+ − 472
||>> Local_Theory.note ((thms_suffix "strong_exhaust", [case_names_attr]), qstrong_exhaust_thms)
+ − 473
||>> Local_Theory.note ((thms_suffix "strong_induct", [case_names_attr]), qstrong_induct_thms)
2448
+ − 474
||>> Local_Theory.note ((thms_suffix "supports", []), qsupports_thms)
2450
+ − 475
||>> Local_Theory.note ((thms_suffix "fsupp", []), qfsupp_thms)
2492
5ac9a74d22fd
post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 476
||>> Local_Theory.note ((thms_suffix "supp", []), qsupp_constrs)
2493
+ − 477
||>> Local_Theory.note ((thms_suffix "fresh", []), qfresh_constrs)
2500
+ − 478
||>> Local_Theory.note ((thms_suffix "raw_alpha", []), alpha_intros)
2563
+ − 479
||>> Local_Theory.note ((thms_suffix "perm_bn_simps", []), qperm_bn_simps)
2571
+ − 480
||>> Local_Theory.note ((thms_suffix "bn_finite", []), qbn_finite_thms)
2593
25dcb2b1329e
ordered raw_bn_info to agree with the order of the raw_bn_functions; started alpha_bn proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 481
||>> Local_Theory.note ((thms_suffix "perm_bn_alpha", []), qperm_bn_alpha_thms)
2598
+ − 482
||>> Local_Theory.note ((thms_suffix "permute_bn", []), qpermute_bn_thms)
1941
+ − 483
in
2601
+ − 484
lthy9'
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 485
end
1941
+ − 486
*}
+ − 487
2475
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 488
1941
+ − 489
section {* Preparing and parsing of the specification *}
+ − 490
+ − 491
ML {*
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 492
(* generates the parsed datatypes and
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 493
declares the constructors
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 494
*)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 495
fun prepare_dts dt_strs thy =
1941
+ − 496
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 497
fun inter_fs_sort thy (a, S) =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 498
(a, Type.inter_sort (Sign.tsig_of thy) (@{sort fs}, S))
1941
+ − 499
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 500
fun mk_type tname sorts (cname, cargs, mx) =
1941
+ − 501
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 502
val full_tname = Sign.full_name thy tname
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 503
val ty = Type (full_tname, map (TFree o inter_fs_sort thy) sorts)
1941
+ − 504
in
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 505
(cname, cargs ---> ty, mx)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 506
end
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 507
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 508
fun prep_constr (cname, cargs, mx, _) (constrs, sorts) =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 509
let
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 510
val (cargs', sorts') =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 511
fold_map (Datatype.read_typ thy) (map snd cargs) sorts
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 512
|>> map (map_type_tfree (TFree o inter_fs_sort thy))
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 513
in
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 514
(constrs @ [(cname, cargs', mx)], sorts')
1941
+ − 515
end
+ − 516
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 517
fun prep_dts (tvs, tname, mx, constrs) (constr_trms, dts, sorts) =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 518
let
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 519
val (constrs', sorts') =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 520
fold prep_constr constrs ([], sorts)
1941
+ − 521
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 522
val constr_trms' =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 523
map (mk_type tname (rev sorts')) constrs'
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 524
in
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 525
(constr_trms @ constr_trms', dts @ [(tvs, tname, mx, constrs')], sorts')
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 526
end
2425
+ − 527
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 528
val (constr_trms, dts, sorts) = fold prep_dts dt_strs ([], [], []);
1941
+ − 529
in
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 530
thy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 531
|> Sign.add_consts_i constr_trms
1941
+ − 532
|> pair dts
+ − 533
end
+ − 534
*}
+ − 535
+ − 536
ML {*
+ − 537
(* parsing the binding function specification and *)
+ − 538
(* declaring the functions in the local theory *)
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 539
fun prepare_bn_funs bn_fun_strs bn_eq_strs thy =
1941
+ − 540
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 541
val lthy = Named_Target.theory_init thy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 542
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 543
val ((bn_funs, bn_eqs), lthy') =
1941
+ − 544
Specification.read_spec bn_fun_strs bn_eq_strs lthy
+ − 545
+ − 546
fun prep_bn_fun ((bn, T), mx) = (bn, T, mx)
+ − 547
+ − 548
val bn_funs' = map prep_bn_fun bn_funs
+ − 549
in
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 550
(Local_Theory.exit_global lthy')
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 551
|> Sign.add_consts_i bn_funs'
1941
+ − 552
|> pair (bn_funs', bn_eqs)
+ − 553
end
+ − 554
*}
+ − 555
+ − 556
text {* associates every SOME with the index in the list; drops NONEs *}
+ − 557
ML {*
+ − 558
fun indexify xs =
+ − 559
let
+ − 560
fun mapp _ [] = []
+ − 561
| mapp i (NONE :: xs) = mapp (i + 1) xs
+ − 562
| mapp i (SOME x :: xs) = (x, i) :: mapp (i + 1) xs
+ − 563
in
+ − 564
mapp 0 xs
+ − 565
end
+ − 566
+ − 567
fun index_lookup xs x =
+ − 568
case AList.lookup (op=) xs x of
+ − 569
SOME x => x
+ − 570
| NONE => error ("Cannot find " ^ x ^ " as argument annotation.");
+ − 571
*}
+ − 572
+ − 573
ML {*
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 574
fun prepare_bclauses dt_strs thy =
1941
+ − 575
let
+ − 576
val annos_bclauses =
+ − 577
get_cnstrs dt_strs
2612
+ − 578
|> (map o map) (fn (_, antys, _, bns) => (map fst antys, bns))
1941
+ − 579
+ − 580
fun prep_binder env bn_str =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 581
case (Syntax.read_term_global thy bn_str) of
1941
+ − 582
Free (x, _) => (NONE, index_lookup env x)
+ − 583
| Const (a, T) $ Free (x, _) => (SOME (Const (a, T)), index_lookup env x)
+ − 584
| _ => error ("The term " ^ bn_str ^ " is not allowed as binding function.")
+ − 585
+ − 586
fun prep_body env bn_str = index_lookup env bn_str
+ − 587
+ − 588
fun prep_bclause env (mode, binders, bodies) =
+ − 589
let
+ − 590
val binders' = map (prep_binder env) binders
+ − 591
val bodies' = map (prep_body env) bodies
+ − 592
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
+ − 593
BC (mode, binders', bodies')
1941
+ − 594
end
+ − 595
+ − 596
fun prep_bclauses (annos, bclause_strs) =
+ − 597
let
+ − 598
val env = indexify annos (* for every label, associate the index *)
+ − 599
in
+ − 600
map (prep_bclause env) bclause_strs
+ − 601
end
+ − 602
in
2612
+ − 603
((map o map) prep_bclauses annos_bclauses, thy)
1941
+ − 604
end
+ − 605
*}
+ − 606
1943
+ − 607
text {*
+ − 608
adds an empty binding clause for every argument
+ − 609
that is not already part of a binding clause
+ − 610
*}
+ − 611
1941
+ − 612
ML {*
+ − 613
fun included i bcs =
+ − 614
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 615
fun incl (BC (_, bns, bds)) =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 616
member (op =) (map snd bns) i orelse member (op =) bds i
1941
+ − 617
in
+ − 618
exists incl bcs
+ − 619
end
+ − 620
*}
+ − 621
+ − 622
ML {*
+ − 623
fun complete dt_strs bclauses =
+ − 624
let
+ − 625
val args =
+ − 626
get_cnstrs dt_strs
2612
+ − 627
|> (map o map) (fn (_, antys, _, _) => length antys)
1941
+ − 628
+ − 629
fun complt n bcs =
+ − 630
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
+ − 631
fun add bcs i = (if included i bcs then [] else [BC (Lst, [], [i])])
1941
+ − 632
in
+ − 633
bcs @ (flat (map_range (add bcs) n))
+ − 634
end
+ − 635
in
2616
dd7490fdd998
all examples for strong exhausts work; recursive binders need to be treated differently; still unclean version with lots of diagnostic code
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 636
(map2 o map2) complt args bclauses
1941
+ − 637
end
+ − 638
*}
+ − 639
+ − 640
ML {*
2436
+ − 641
fun nominal_datatype2_cmd (opt_thms_name, dt_strs, bn_fun_strs, bn_eq_strs) lthy =
1941
+ − 642
let
2436
+ − 643
val pre_typs =
+ − 644
map (fn (tvs, tname, mx, _) => (tname, length tvs, mx)) dt_strs
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 645
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 646
(* this theory is used just for parsing *)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 647
val thy = ProofContext.theory_of lthy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 648
val tmp_thy = Theory.copy thy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 649
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 650
val (((dts, (bn_funs, bn_eqs)), bclauses), tmp_thy') =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 651
tmp_thy
2770
+ − 652
|> Sign.add_types_global pre_typs
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 653
|> prepare_dts dt_strs
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 654
||>> prepare_bn_funs bn_fun_strs bn_eq_strs
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 655
||>> prepare_bclauses dt_strs
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 656
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 657
val bclauses' = complete dt_strs bclauses
1941
+ − 658
in
2679
+ − 659
nominal_datatype2 opt_thms_name dts bn_funs bn_eqs bclauses' lthy
1941
+ − 660
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
+ − 661
*}
1941
+ − 662
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
+ − 663
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
+ − 664
(* 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
+ − 665
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
+ − 666
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
+ − 667
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
+ − 668
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 669
fun triple ((x, y), z) = (x, y, z)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 670
fun tuple1 ((x, y, z), u) = (x, y, z, u)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 671
fun tuple2 (((x, y), z), u) = (x, y, u, z)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 672
fun tuple3 ((x, y), (z, u)) = (x, y, z, u)
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 673
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
+ − 674
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
+ − 675
val _ = Keyword.keyword "bind"
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 676
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 677
val opt_name = Scan.option (P.binding --| Args.colon)
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 678
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
+ − 679
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
+ − 680
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
+ − 681
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
+ − 682
S.optional (Args.parens
2634
3ce1089cdbf3
changed res keyword to set+ for restrictions; comment by a referee
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 683
(Args.$$$ "list" >> K Lst || (Args.$$$ "set" -- Args.$$$ "+") >> K Res || Args.$$$ "set" >> K Set)) Lst
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 684
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
+ − 685
val bind_clauses =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 686
P.enum "," (bind_mode -- S.repeat1 P.term -- (P.$$$ "in" |-- S.repeat1 P.name) >> triple)
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 687
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
+ − 688
val cnstr_parser =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 689
P.binding -- S.repeat anno_typ -- bind_clauses -- P.opt_mixfix >> tuple2
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 690
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
+ − 691
(* 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
+ − 692
val dt_parser =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 693
(P.type_args -- P.binding -- P.opt_mixfix >> triple) --
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 694
(P.$$$ "=" |-- P.enum1 "|" cnstr_parser) >> tuple1
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 695
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
+ − 696
(* 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
+ − 697
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
+ − 698
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
+ − 699
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
+ − 700
(* 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
+ − 701
val main_parser =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 702
opt_name -- P.and_list1 dt_parser -- bnfun_parser >> tuple3
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 703
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
+ − 704
end
1941
+ − 705
+ − 706
(* Command Keyword *)
2168
+ − 707
val _ = Outer_Syntax.local_theory "nominal_datatype" "test" Keyword.thy_decl
1941
+ − 708
(main_parser >> nominal_datatype2_cmd)
+ − 709
*}
+ − 710
2679
+ − 711
(*
2647
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 712
ML {*
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 713
trace := true
5e95387bef45
removed debugging code abd introduced a guarded tracing function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 714
*}
2679
+ − 715
*)
2292
+ − 716
1941
+ − 717
end
+ − 718
+ − 719
+ − 720