2454
+ − 1
theory Nominal2
2435
+ − 2
imports
2568
8193bbaa07fe
merged Nominal-General directory into Nominal; renamed Abs.thy to Nominal2_Abs.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 3
Nominal2_Base Nominal2_Eqvt Nominal2_Abs
2598
+ − 4
uses ("nominal_dt_rawfuns.ML")
2435
+ − 5
("nominal_dt_alpha.ML")
+ − 6
("nominal_dt_quot.ML")
1941
+ − 7
begin
+ − 8
2435
+ − 9
use "nominal_dt_rawfuns.ML"
+ − 10
ML {* open Nominal_Dt_RawFuns *}
+ − 11
+ − 12
use "nominal_dt_alpha.ML"
+ − 13
ML {* open Nominal_Dt_Alpha *}
+ − 14
+ − 15
use "nominal_dt_quot.ML"
+ − 16
ML {* open Nominal_Dt_Quot *}
+ − 17
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
+ − 18
1941
+ − 19
section{* Interface for nominal_datatype *}
+ − 20
2398
+ − 21
ML {*
+ − 22
(* attributes *)
2448
+ − 23
val eqvt_attr = Attrib.internal (K Nominal_ThmDecls.eqvt_add)
+ − 24
val rsp_attr = Attrib.internal (K Quotient_Info.rsp_rules_add)
+ − 25
val simp_attr = Attrib.internal (K Simplifier.simp_add)
2398
+ − 26
+ − 27
*}
+ − 28
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
+ − 29
ML {* print_depth 50 *}
1941
+ − 30
+ − 31
ML {*
+ − 32
fun get_cnstrs dts =
+ − 33
map (fn (_, _, _, constrs) => constrs) dts
+ − 34
+ − 35
fun get_typed_cnstrs dts =
+ − 36
flat (map (fn (_, bn, _, constrs) =>
+ − 37
(map (fn (bn', _, _) => (Binding.name_of bn, Binding.name_of bn')) constrs)) dts)
+ − 38
+ − 39
fun get_cnstr_strs dts =
+ − 40
map (fn (bn, _, _) => Binding.name_of bn) (flat (get_cnstrs dts))
+ − 41
+ − 42
fun get_bn_fun_strs bn_funs =
+ − 43
map (fn (bn_fun, _, _) => Binding.name_of bn_fun) bn_funs
+ − 44
*}
+ − 45
2106
+ − 46
1944
+ − 47
text {* Infrastructure for adding "_raw" to types and terms *}
+ − 48
1941
+ − 49
ML {*
+ − 50
fun add_raw s = s ^ "_raw"
+ − 51
fun add_raws ss = map add_raw ss
+ − 52
fun raw_bind bn = Binding.suffix_name "_raw" bn
+ − 53
+ − 54
fun replace_str ss s =
+ − 55
case (AList.lookup (op=) ss s) of
+ − 56
SOME s' => s'
+ − 57
| NONE => s
+ − 58
+ − 59
fun replace_typ ty_ss (Type (a, Ts)) = Type (replace_str ty_ss a, map (replace_typ ty_ss) Ts)
+ − 60
| replace_typ ty_ss T = T
+ − 61
+ − 62
fun raw_dts ty_ss dts =
+ − 63
let
+ − 64
fun raw_dts_aux1 (bind, tys, mx) =
+ − 65
(raw_bind bind, map (replace_typ ty_ss) tys, mx)
+ − 66
+ − 67
fun raw_dts_aux2 (ty_args, bind, mx, constrs) =
+ − 68
(ty_args, raw_bind bind, mx, map raw_dts_aux1 constrs)
+ − 69
in
+ − 70
map raw_dts_aux2 dts
+ − 71
end
+ − 72
+ − 73
fun replace_aterm trm_ss (Const (a, T)) = Const (replace_str trm_ss a, T)
+ − 74
| replace_aterm trm_ss (Free (a, T)) = Free (replace_str trm_ss a, T)
+ − 75
| replace_aterm trm_ss trm = trm
+ − 76
+ − 77
fun replace_term trm_ss ty_ss trm =
+ − 78
trm |> Term.map_aterms (replace_aterm trm_ss) |> map_types (replace_typ ty_ss)
+ − 79
*}
+ − 80
+ − 81
ML {*
+ − 82
fun rawify_dts dt_names dts dts_env =
+ − 83
let
+ − 84
val raw_dts = raw_dts dts_env dts
+ − 85
val raw_dt_names = add_raws dt_names
+ − 86
in
+ − 87
(raw_dt_names, raw_dts)
+ − 88
end
+ − 89
*}
+ − 90
+ − 91
ML {*
+ − 92
fun rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs =
+ − 93
let
+ − 94
val bn_funs' = map (fn (bn, ty, mx) =>
2304
+ − 95
(raw_bind bn, SOME (replace_typ dts_env ty), mx)) bn_funs
1941
+ − 96
+ − 97
val bn_eqs' = map (fn (attr, trm) =>
+ − 98
(attr, replace_term (cnstrs_env @ bn_fun_env) dts_env trm)) bn_eqs
+ − 99
in
+ − 100
(bn_funs', bn_eqs')
+ − 101
end
+ − 102
*}
+ − 103
+ − 104
ML {*
+ − 105
fun rawify_bclauses dts_env cnstrs_env bn_fun_env bclauses =
+ − 106
let
+ − 107
fun rawify_bnds bnds =
+ − 108
map (apfst (Option.map (replace_term (cnstrs_env @ bn_fun_env) dts_env))) bnds
+ − 109
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
+ − 110
fun rawify_bclause (BC (mode, bnds, bdys)) = BC (mode, rawify_bnds bnds, bdys)
1941
+ − 111
in
+ − 112
map (map (map rawify_bclause)) bclauses
+ − 113
end
+ − 114
*}
+ − 115
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
+ − 116
(* 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
+ − 117
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
+ − 118
bn function *)
1941
+ − 119
ML {*
2294
+ − 120
fun strip_bn_fun lthy args t =
+ − 121
let
+ − 122
fun aux t =
+ − 123
case t of
+ − 124
Const (@{const_name sup}, _) $ l $ r => aux l @ aux r
+ − 125
| Const (@{const_name append}, _) $ l $ r => aux l @ aux r
+ − 126
| Const (@{const_name insert}, _) $ (Const (@{const_name atom}, _) $ (x as Var _)) $ y =>
+ − 127
(find_index (equal x) args, NONE) :: aux y
+ − 128
| Const (@{const_name Cons}, _) $ (Const (@{const_name atom}, _) $ (x as Var _)) $ y =>
+ − 129
(find_index (equal x) args, NONE) :: aux y
+ − 130
| Const (@{const_name bot}, _) => []
+ − 131
| Const (@{const_name Nil}, _) => []
+ − 132
| (f as Const _) $ (x as Var _) => [(find_index (equal x) args, SOME f)]
+ − 133
| _ => error ("Unsupported binding function: " ^ (Syntax.string_of_term lthy t))
+ − 134
in
+ − 135
aux t
+ − 136
end
1941
+ − 137
*}
+ − 138
+ − 139
ML {*
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 140
(** definition of the raw binding functions **)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 141
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
+ − 142
fun prep_bn_info lthy dt_names dts bn_funs eqs =
1941
+ − 143
let
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
+ − 144
fun process_eq eq =
1941
+ − 145
let
+ − 146
val (lhs, rhs) = eq
+ − 147
|> HOLogic.dest_Trueprop
+ − 148
|> HOLogic.dest_eq
+ − 149
val (bn_fun, [cnstr]) = strip_comb lhs
2294
+ − 150
val (_, ty) = dest_Const bn_fun
1941
+ − 151
val (ty_name, _) = dest_Type (domain_type ty)
+ − 152
val dt_index = find_index (fn x => x = ty_name) dt_names
2294
+ − 153
val (cnstr_head, cnstr_args) = strip_comb cnstr
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
+ − 154
val cnstr_name = Long_Name.base_name (fst (dest_Const cnstr_head))
2294
+ − 155
val rhs_elements = strip_bn_fun lthy cnstr_args rhs
1941
+ − 156
in
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
+ − 157
((bn_fun, dt_index), (cnstr_name, rhs_elements))
2122
+ − 158
end
2560
+ − 159
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
+ − 160
(* order according to constructor names *)
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
+ − 161
fun cntrs_order ((bn, dt_index), data) =
1941
+ − 162
let
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
+ − 163
val dt = nth dts dt_index
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
+ − 164
val cts = (fn (_, _, _, x) => x) dt
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
+ − 165
val ct_names = map (Binding.name_of o (fn (x, _, _) => x)) cts
1941
+ − 166
in
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
+ − 167
(bn, (bn, dt_index, order (op=) ct_names data))
1941
+ − 168
end
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
+ − 169
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
+ − 170
in
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
+ − 171
eqs
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
+ − 172
|> map process_eq
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
+ − 173
|> AList.group (op=) (* eqs grouped according to bn_functions *)
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
+ − 174
|> map cntrs_order (* inner data ordered according to constructors *)
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
+ − 175
|> order (op=) bn_funs (* ordered according to bn_functions *)
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
+ − 176
end
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
+ − 177
*}
1941
+ − 178
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
+ − 179
ML {*
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 180
fun define_raw_bns dt_names dts raw_bn_funs raw_bn_eqs constr_thms size_thms lthy =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 181
if null raw_bn_funs
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 182
then ([], [], [], [], lthy)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 183
else
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 184
let
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 185
val (_, lthy1) = Function.add_function raw_bn_funs raw_bn_eqs
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 186
Function_Common.default_config (pat_completeness_simp constr_thms) lthy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 187
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 188
val (info, lthy2) = prove_termination size_thms (Local_Theory.restore lthy1)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 189
val {fs, simps, inducts, ...} = info
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 190
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 191
val raw_bn_induct = (the inducts)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 192
val raw_bn_eqs = the simps
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 193
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 194
val raw_bn_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
+ − 195
prep_bn_info lthy dt_names dts fs (map prop_of raw_bn_eqs)
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 196
in
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 197
(fs, raw_bn_eqs, raw_bn_info, raw_bn_induct, lthy2)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 198
end
2560
+ − 199
1941
+ − 200
*}
+ − 201
+ − 202
ML {*
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 203
fun define_raw_dts dts bn_funs bn_eqs binds lthy =
1941
+ − 204
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 205
val thy = Local_Theory.exit_global lthy
1941
+ − 206
val thy_name = Context.theory_name thy
+ − 207
+ − 208
val dt_names = map (fn (_, s, _, _) => Binding.name_of s) dts
+ − 209
val dt_full_names = map (Long_Name.qualify thy_name) dt_names
+ − 210
val dt_full_names' = add_raws dt_full_names
+ − 211
val dts_env = dt_full_names ~~ dt_full_names'
+ − 212
+ − 213
val cnstrs = get_cnstr_strs dts
+ − 214
val cnstrs_ty = get_typed_cnstrs dts
+ − 215
val cnstrs_full_names = map (Long_Name.qualify thy_name) cnstrs
+ − 216
val cnstrs_full_names' = map (fn (x, y) => Long_Name.qualify thy_name
+ − 217
(Long_Name.qualify (add_raw x) (add_raw y))) cnstrs_ty
+ − 218
val cnstrs_env = cnstrs_full_names ~~ cnstrs_full_names'
+ − 219
+ − 220
val bn_fun_strs = get_bn_fun_strs bn_funs
+ − 221
val bn_fun_strs' = add_raws bn_fun_strs
+ − 222
val bn_fun_env = bn_fun_strs ~~ bn_fun_strs'
+ − 223
val bn_fun_full_env = map (pairself (Long_Name.qualify thy_name))
+ − 224
(bn_fun_strs ~~ bn_fun_strs')
+ − 225
+ − 226
val (raw_dt_names, raw_dts) = rawify_dts dt_names dts dts_env
+ − 227
val (raw_bn_funs, raw_bn_eqs) = rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs
+ − 228
val raw_bclauses = rawify_bclauses dts_env cnstrs_env bn_fun_full_env binds
+ − 229
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 230
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
+ − 231
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
+ − 232
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 233
val lthy1 = Named_Target.theory_init thy1
2304
+ − 234
in
2337
+ − 235
(raw_dt_full_names, raw_dts, raw_bclauses, raw_bn_funs, raw_bn_eqs, lthy1)
2304
+ − 236
end
+ − 237
*}
+ − 238
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
+ − 239
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
+ − 240
(* 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
+ − 241
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
+ − 242
2436
+ − 243
val (STEPS, STEPS_setup) = Attrib.config_int "STEPS" (K 100);
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
+ − 244
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
+ − 245
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
+ − 246
*}
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
+ − 247
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
+ − 248
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
+ − 249
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
+ − 250
1941
+ − 251
ML {*
2436
+ − 252
fun nominal_datatype2 opt_thms_name dts bn_funs bn_eqs bclauses lthy =
1941
+ − 253
let
2294
+ − 254
(* definition of the raw datatypes *)
2316
+ − 255
val _ = warning "Definition of raw datatypes";
2337
+ − 256
val (raw_dt_names, raw_dts, raw_bclauses, raw_bn_funs, raw_bn_eqs, lthy0) =
2308
+ − 257
if get_STEPS lthy > 0
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 258
then define_raw_dts dts bn_funs bn_eqs bclauses lthy
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 259
else raise TEST lthy
1941
+ − 260
2304
+ − 261
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
+ − 262
val {descr, sorts, ...} = dtinfo
2407
+ − 263
2400
+ − 264
val raw_tys = all_dtyps descr sorts
+ − 265
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
+ − 266
val tvs = hd raw_tys
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 267
|> snd o dest_Type
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 268
|> map dest_TFree
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 269
2400
+ − 270
val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy0)) raw_full_ty_names
+ − 271
2407
+ − 272
val raw_cns_info = all_dtyp_constrs_types descr sorts
+ − 273
val raw_constrs = flat (map (map (fn (c, _, _, _) => c)) raw_cns_info)
+ − 274
2400
+ − 275
val raw_inject_thms = flat (map #inject dtinfos)
+ − 276
val raw_distinct_thms = flat (map #distinct dtinfos)
+ − 277
val raw_induct_thm = #induct dtinfo
+ − 278
val raw_induct_thms = #inducts dtinfo
+ − 279
val raw_exhaust_thms = map #exhaust dtinfos
+ − 280
val raw_size_trms = map size_const raw_tys
2388
+ − 281
val raw_size_thms = Size.size_thms (ProofContext.theory_of lthy0) (hd raw_dt_names)
+ − 282
|> `(fn thms => (length thms) div 2)
2392
+ − 283
|> uncurry drop
2388
+ − 284
2409
+ − 285
(* definitions of raw permutations by primitive recursion *)
2316
+ − 286
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
+ − 287
val ((raw_perm_funs, raw_perm_simps, raw_perm_laws), lthy2a) =
2560
+ − 288
if get_STEPS lthy0 > 0
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 289
then define_raw_perms raw_full_ty_names raw_tys tvs raw_constrs raw_induct_thm lthy0
2308
+ − 290
else raise TEST lthy0
2144
+ − 291
+ − 292
(* noting the raw permutations as eqvt theorems *)
2448
+ − 293
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
+ − 294
2560
+ − 295
(* definition of raw fv and bn functions *)
+ − 296
val _ = warning "Definition of raw fv- and bn-functions";
2405
+ − 297
val (raw_bns, raw_bn_defs, raw_bn_info, raw_bn_induct, lthy3a) =
2560
+ − 298
if get_STEPS lthy3 > 1
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 299
then define_raw_bns raw_full_ty_names raw_dts raw_bn_funs raw_bn_eqs
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 300
(raw_inject_thms @ raw_distinct_thms) raw_size_thms lthy3
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 301
else raise TEST lthy3
2292
+ − 302
2560
+ − 303
(* defining the permute_bn functions *)
2561
+ − 304
val (raw_perm_bns, raw_perm_bn_simps, lthy3b) =
2560
+ − 305
if get_STEPS lthy3a > 2
+ − 306
then 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
+ − 307
(raw_inject_thms @ raw_distinct_thms) raw_size_thms lthy3a
2308
+ − 308
else raise TEST lthy3a
+ − 309
2560
+ − 310
val (raw_fvs, raw_fv_bns, raw_fv_defs, raw_fv_bns_induct, lthy3c) =
+ − 311
if get_STEPS lthy3b > 3
+ − 312
then define_raw_fvs raw_full_ty_names raw_tys raw_cns_info raw_bn_info raw_bclauses
+ − 313
(raw_inject_thms @ raw_distinct_thms) raw_size_thms lthy3b
+ − 314
else raise TEST lthy3b
+ − 315
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 316
(* definition of raw alphas *)
2316
+ − 317
val _ = warning "Definition of alphas";
2300
+ − 318
val (alpha_trms, alpha_bn_trms, alpha_intros, alpha_cases, alpha_induct, lthy4) =
2560
+ − 319
if get_STEPS lthy3c > 4
+ − 320
then define_raw_alpha raw_full_ty_names raw_tys raw_cns_info raw_bn_info raw_bclauses raw_fvs lthy3c
+ − 321
else raise TEST lthy3c
2336
+ − 322
val alpha_tys = map (domain_type o fastype_of) alpha_trms
+ − 323
2300
+ − 324
(* definition of alpha-distinct lemmas *)
2316
+ − 325
val _ = warning "Distinct theorems";
2399
+ − 326
val alpha_distincts =
2400
+ − 327
mk_alpha_distincts lthy4 alpha_cases raw_distinct_thms alpha_trms raw_tys
2300
+ − 328
2361
+ − 329
(* definition of alpha_eq_iff lemmas *)
2316
+ − 330
val _ = warning "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
+ − 331
val alpha_eq_iff =
2295
+ − 332
if get_STEPS lthy > 5
2400
+ − 333
then mk_alpha_eq_iff lthy4 alpha_intros raw_distinct_thms raw_inject_thms alpha_cases
2295
+ − 334
else raise TEST lthy4
2022
+ − 335
2388
+ − 336
(* 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
+ − 337
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
+ − 338
val raw_bn_eqvt =
2298
+ − 339
if get_STEPS lthy > 6
2405
+ − 340
then raw_prove_eqvt raw_bns raw_bn_induct (raw_bn_defs @ raw_perm_simps) lthy4
2298
+ − 341
else raise TEST lthy4
+ − 342
2406
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 343
(* noting the raw_bn_eqvt lemmas in a temprorary theory *)
2448
+ − 344
val lthy_tmp = snd (Local_Theory.note ((Binding.empty, [eqvt_attr]), raw_bn_eqvt) lthy4)
2305
+ − 345
2406
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 346
val raw_fv_eqvt =
2298
+ − 347
if get_STEPS lthy > 7
2384
+ − 348
then raw_prove_eqvt (raw_fvs @ raw_fv_bns) raw_fv_bns_induct (raw_fv_defs @ raw_perm_simps)
2388
+ − 349
(Local_Theory.restore lthy_tmp)
+ − 350
else raise TEST lthy4
+ − 351
2389
+ − 352
val raw_size_eqvt =
2388
+ − 353
if get_STEPS lthy > 8
+ − 354
then raw_prove_eqvt raw_size_trms raw_induct_thms (raw_size_thms @ raw_perm_simps)
+ − 355
(Local_Theory.restore lthy_tmp)
2389
+ − 356
|> map (rewrite_rule @{thms permute_nat_def[THEN eq_reflection]})
+ − 357
|> map (fn thm => thm RS @{thm sym})
2305
+ − 358
else raise TEST lthy4
+ − 359
2448
+ − 360
val lthy5 = snd (Local_Theory.note ((Binding.empty, [eqvt_attr]), raw_fv_eqvt) lthy_tmp)
2306
+ − 361
2336
+ − 362
val (alpha_eqvt, lthy6) =
2388
+ − 363
if get_STEPS lthy > 9
2336
+ − 364
then Nominal_Eqvt.equivariance true (alpha_trms @ alpha_bn_trms) alpha_induct alpha_intros lthy5
2311
+ − 365
else raise TEST lthy4
+ − 366
+ − 367
(* proving alpha equivalence *)
+ − 368
val _ = warning "Proving equivalence"
+ − 369
2316
+ − 370
val alpha_refl_thms =
2388
+ − 371
if get_STEPS lthy > 10
+ − 372
then raw_prove_refl alpha_trms alpha_bn_trms alpha_intros raw_induct_thm lthy6
2336
+ − 373
else raise TEST lthy6
2316
+ − 374
2311
+ − 375
val alpha_sym_thms =
2388
+ − 376
if get_STEPS lthy > 11
2336
+ − 377
then raw_prove_sym (alpha_trms @ alpha_bn_trms) alpha_intros alpha_induct lthy6
+ − 378
else raise TEST lthy6
2298
+ − 379
2311
+ − 380
val alpha_trans_thms =
2388
+ − 381
if get_STEPS lthy > 12
2400
+ − 382
then raw_prove_trans (alpha_trms @ alpha_bn_trms) (raw_distinct_thms @ raw_inject_thms)
2336
+ − 383
alpha_intros alpha_induct alpha_cases lthy6
+ − 384
else raise TEST lthy6
2311
+ − 385
2404
+ − 386
val (alpha_equivp_thms, alpha_bn_equivp_thms) =
2388
+ − 387
if get_STEPS lthy > 13
2404
+ − 388
then raw_prove_equivp alpha_trms alpha_bn_trms alpha_refl_thms alpha_sym_thms
+ − 389
alpha_trans_thms lthy6
2336
+ − 390
else raise TEST lthy6
2322
+ − 391
2320
+ − 392
(* proving alpha implies alpha_bn *)
+ − 393
val _ = warning "Proving alpha implies bn"
+ − 394
+ − 395
val alpha_bn_imp_thms =
2388
+ − 396
if get_STEPS lthy > 14
2336
+ − 397
then raw_prove_bn_imp alpha_trms alpha_bn_trms alpha_intros alpha_induct lthy6
+ − 398
else raise TEST lthy6
2322
+ − 399
2397
+ − 400
(* respectfulness proofs *)
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 401
val raw_funs_rsp_aux =
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 402
if get_STEPS lthy > 15
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 403
then raw_fv_bn_rsp_aux alpha_trms alpha_bn_trms raw_fvs
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 404
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
+ − 405
else raise TEST lthy6
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 406
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 407
val raw_funs_rsp =
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 408
if get_STEPS lthy > 16
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 409
then map mk_funs_rsp raw_funs_rsp_aux
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 410
else raise TEST lthy6
2388
+ − 411
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 412
val raw_size_rsp =
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 413
if get_STEPS lthy > 17
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 414
then
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 415
raw_size_rsp_aux (alpha_trms @ alpha_bn_trms) alpha_induct
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 416
(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
+ − 417
|> map mk_funs_rsp
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 418
else raise TEST lthy6
2392
+ − 419
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 420
val raw_constrs_rsp =
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 421
if get_STEPS lthy > 18
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 422
then raw_constrs_rsp raw_constrs alpha_trms alpha_intros
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 423
(alpha_bn_imp_thms @ raw_funs_rsp_aux) lthy6
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 424
else raise TEST lthy6
2397
+ − 425
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 426
val alpha_permute_rsp =
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 427
if get_STEPS lthy > 19
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 428
then map mk_alpha_permute_rsp alpha_eqvt
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 429
else raise TEST lthy6
2384
+ − 430
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 431
val alpha_bn_rsp =
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 432
if get_STEPS lthy > 20
2440
0a36825b16c1
"isabelle make test" makes all major examples....they work up to supp theorems (excluding)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 433
then raw_alpha_bn_rsp alpha_bn_trms alpha_bn_equivp_thms alpha_bn_imp_thms
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 434
else raise TEST lthy6
2404
+ − 435
2561
+ − 436
val raw_perm_bn_rsp =
+ − 437
if get_STEPS lthy > 21
+ − 438
then raw_perm_bn_rsp (alpha_trms @ alpha_bn_trms) raw_perm_bns alpha_induct
+ − 439
alpha_intros raw_perm_bn_simps lthy6
+ − 440
else raise TEST lthy6
+ − 441
2398
+ − 442
(* noting the quot_respects lemmas *)
+ − 443
val (_, lthy6a) =
2561
+ − 444
if get_STEPS lthy > 22
2448
+ − 445
then Local_Theory.note ((Binding.empty, [rsp_attr]),
2561
+ − 446
raw_constrs_rsp @ raw_funs_rsp @ raw_size_rsp @ alpha_permute_rsp @
+ − 447
alpha_bn_rsp @ raw_perm_bn_rsp) lthy6
2398
+ − 448
else raise TEST lthy6
+ − 449
2336
+ − 450
(* defining the quotient type *)
+ − 451
val _ = warning "Declaring the quotient types"
+ − 452
val qty_descr = map (fn (vs, bind, mx, _) => (vs, bind, mx)) dts
2400
+ − 453
2336
+ − 454
val (qty_infos, lthy7) =
2561
+ − 455
if get_STEPS lthy > 23
2400
+ − 456
then define_qtypes qty_descr alpha_tys alpha_trms alpha_equivp_thms lthy6a
2398
+ − 457
else raise TEST lthy6a
2336
+ − 458
+ − 459
val qtys = map #qtyp qty_infos
2400
+ − 460
val qty_full_names = map (fst o dest_Type) qtys
+ − 461
val qty_names = map Long_Name.base_name qty_full_names
+ − 462
2339
+ − 463
(* defining of quotient term-constructors, binding functions, free vars functions *)
2378
+ − 464
val _ = warning "Defining the quotient constants"
2346
+ − 465
val qconstrs_descr =
2338
+ − 466
flat (map (fn (_, _, _, cs) => map (fn (b, _, mx) => (Name.of_binding b, mx)) cs) dts)
2400
+ − 467
|> map2 (fn t => fn (b, mx) => (b, t, mx)) raw_constrs
2338
+ − 468
2339
+ − 469
val qbns_descr =
2346
+ − 470
map2 (fn (b, _, mx) => fn t => (Name.of_binding b, t, mx)) bn_funs raw_bns
2339
+ − 471
+ − 472
val qfvs_descr =
2346
+ − 473
map2 (fn n => fn t => ("fv_" ^ n, t, NoSyn)) qty_names raw_fvs
2339
+ − 474
2346
+ − 475
val qfv_bns_descr =
2398
+ − 476
map2 (fn (b, _, _) => fn t => ("fv_" ^ Name.of_binding b, t, NoSyn)) bn_funs raw_fv_bns
2339
+ − 477
2384
+ − 478
val qalpha_bns_descr =
+ − 479
map2 (fn (b, _, _) => fn t => ("alpha_" ^ Name.of_binding b, t, NoSyn)) bn_funs alpha_bn_trms
+ − 480
2398
+ − 481
val qperm_descr =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 482
map2 (fn n => fn t => ("permute_" ^ n, Type.legacy_freeze t, NoSyn)) qty_names raw_perm_funs
2398
+ − 483
2400
+ − 484
val qsize_descr =
+ − 485
map2 (fn n => fn t => ("size_" ^ n, t, NoSyn)) qty_names raw_size_trms
+ − 486
2562
+ − 487
val qperm_bn_descr =
+ − 488
map2 (fn (b, _, _) => fn t => ("permute_" ^ Name.of_binding b, t, NoSyn)) bn_funs raw_perm_bns
+ − 489
+ − 490
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
+ − 491
val ((((((qconstrs_info, qbns_info), qfvs_info), qfv_bns_info), qalpha_bns_info), qperm_bns_info), lthy8)=
2561
+ − 492
if get_STEPS lthy > 24
2346
+ − 493
then
+ − 494
lthy7
2400
+ − 495
|> define_qconsts qtys qconstrs_descr
+ − 496
||>> define_qconsts qtys qbns_descr
+ − 497
||>> define_qconsts qtys qfvs_descr
+ − 498
||>> define_qconsts qtys qfv_bns_descr
+ − 499
||>> define_qconsts qtys qalpha_bns_descr
2562
+ − 500
||>> define_qconsts qtys qperm_bn_descr
2338
+ − 501
else raise TEST lthy7
+ − 502
2400
+ − 503
(* definition of the quotient permfunctions and pt-class *)
+ − 504
val lthy9 =
2561
+ − 505
if get_STEPS lthy > 25
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 506
then define_qperms qtys qty_full_names tvs qperm_descr raw_perm_laws lthy8
2400
+ − 507
else raise TEST lthy8
+ − 508
2401
7645e18e8b19
modified the code for class instantiations (with help from Florian)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 509
val lthy9a =
2561
+ − 510
if get_STEPS lthy > 26
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 511
then define_qsizes qtys qty_full_names tvs qsize_descr lthy9
2400
+ − 512
else raise TEST lthy9
2398
+ − 513
2448
+ − 514
val qtrms = map #qconst qconstrs_info
2346
+ − 515
val qbns = map #qconst qbns_info
+ − 516
val qfvs = map #qconst qfvs_info
+ − 517
val qfv_bns = map #qconst qfv_bns_info
2384
+ − 518
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
+ − 519
val qperm_bns = map #qconst qperm_bns_info
2434
+ − 520
+ − 521
(* lifting of the theorems *)
+ − 522
val _ = warning "Lifting of Theorems"
+ − 523
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
+ − 524
val eq_iff_simps = @{thms alphas permute_prod.simps prod_fv.simps prod_alpha_def prod_rel_def
2434
+ − 525
prod.cases}
+ − 526
+ − 527
val ((((((qdistincts, qeq_iffs), qfv_defs), qbn_defs), qperm_simps), qfv_qbn_eqvts), lthyA) =
2561
+ − 528
if get_STEPS lthy > 27
2434
+ − 529
then
+ − 530
lthy9a
+ − 531
|> lift_thms qtys [] alpha_distincts
+ − 532
||>> lift_thms qtys eq_iff_simps alpha_eq_iff
+ − 533
||>> lift_thms qtys [] raw_fv_defs
+ − 534
||>> lift_thms qtys [] raw_bn_defs
+ − 535
||>> lift_thms qtys [] raw_perm_simps
+ − 536
||>> lift_thms qtys [] (raw_fv_eqvt @ raw_bn_eqvt)
+ − 537
else raise TEST lthy9a
+ − 538
2594
+ − 539
val ((((((qsize_eqvt, [qinduct]), qexhausts), qsize_simps), qperm_bn_simps), qalpha_refl_thms), lthyB) =
2561
+ − 540
if get_STEPS lthy > 28
2434
+ − 541
then
+ − 542
lthyA
+ − 543
|> lift_thms qtys [] raw_size_eqvt
+ − 544
||>> lift_thms qtys [] [raw_induct_thm]
+ − 545
||>> lift_thms qtys [] raw_exhaust_thms
2487
+ − 546
||>> lift_thms qtys [] raw_size_thms
2563
+ − 547
||>> lift_thms qtys [] raw_perm_bn_simps
2594
+ − 548
||>> lift_thms qtys [] alpha_refl_thms
2434
+ − 549
else raise TEST lthyA
+ − 550
2474
+ − 551
val qinducts = Project_Rule.projections lthyA qinduct
+ − 552
2451
+ − 553
(* supports lemmas *)
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
+ − 554
val _ = warning "Proving Supports Lemmas and fs-Instances"
2448
+ − 555
val qsupports_thms =
2561
+ − 556
if get_STEPS lthy > 29
2448
+ − 557
then prove_supports lthyB qperm_simps qtrms
+ − 558
else raise TEST lthyB
+ − 559
2451
+ − 560
(* finite supp lemmas *)
2450
+ − 561
val qfsupp_thms =
2561
+ − 562
if get_STEPS lthy > 30
2450
+ − 563
then prove_fsupp lthyB qtys qinduct qsupports_thms
+ − 564
else raise TEST lthyB
+ − 565
2451
+ − 566
(* fs instances *)
+ − 567
val lthyC =
2561
+ − 568
if get_STEPS lthy > 31
2451
+ − 569
then fs_instance qtys qty_full_names tvs qfsupp_thms lthyB
+ − 570
else raise TEST lthyB
2448
+ − 571
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
+ − 572
(* fv - supp equality *)
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
+ − 573
val _ = warning "Proving Equality between fv and supp"
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
+ − 574
val qfv_supp_thms =
2561
+ − 575
if get_STEPS lthy > 32
2483
+ − 576
then prove_fv_supp qtys 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
+ − 577
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
+ − 578
else []
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
+ − 579
2492
5ac9a74d22fd
post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 580
(* 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
+ − 581
5ac9a74d22fd
post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 582
val qeq_iffs' = qeq_iffs
2493
+ − 583
|> map (simplify (HOL_basic_ss addsimps qfv_supp_thms))
+ − 584
|> 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
+ − 585
5ac9a74d22fd
post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 586
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
+ − 587
|> 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
+ − 588
2493
+ − 589
val transform_thm = @{lemma "x = y \<Longrightarrow> a \<notin> x \<longleftrightarrow> a \<notin> y" by simp}
+ − 590
val transform_thms =
+ − 591
[ @{lemma "a \<notin> (S \<union> T) \<longleftrightarrow> a \<notin> S \<and> a \<notin> T" by simp},
+ − 592
@{lemma "a \<notin> (S - T) \<longleftrightarrow> a \<notin> S \<or> a \<in> T" by simp},
+ − 593
@{lemma "(lhs = (a \<notin> {})) \<longleftrightarrow> lhs" by simp},
+ − 594
@{thm fresh_def[symmetric]}]
+ − 595
+ − 596
val qfresh_constrs = qsupp_constrs
+ − 597
|> map (fn thm => thm RS transform_thm)
+ − 598
|> map (simplify (HOL_basic_ss addsimps transform_thms))
+ − 599
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
+ − 600
(* proving that the qbn result is finite *)
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
+ − 601
val qbn_finite_thms =
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
+ − 602
if get_STEPS lthy > 33
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
+ − 603
then prove_bns_finite qtys qbns qinduct qbn_defs lthyC
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
+ − 604
else []
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
+ − 605
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
+ − 606
(* proving that perm_bns preserve alpha *)
2594
+ − 607
val qperm_bn_alpha_thms =
+ − 608
if get_STEPS lthy > 33
+ − 609
then prove_perm_bn_alpha_thms qtys qperm_bns qalpha_bns qinduct qperm_bn_simps qeq_iffs'
+ − 610
qalpha_refl_thms lthyC
+ − 611
else []
2493
+ − 612
2598
+ − 613
(* proving the relationship of bn and permute_bn *)
+ − 614
val qpermute_bn_thms =
+ − 615
if get_STEPS lthy > 33
+ − 616
then prove_permute_bn_thms qtys qbns qperm_bns qinduct qperm_bn_simps qbn_defs qfv_qbn_eqvts lthyC
+ − 617
else []
+ − 618
2436
+ − 619
(* noting the theorems *)
+ − 620
+ − 621
(* generating the prefix for the theorem names *)
+ − 622
val thms_name =
+ − 623
the_default (Binding.name (space_implode "_" qty_names)) opt_thms_name
+ − 624
fun thms_suffix s = Binding.qualified true s thms_name
+ − 625
2451
+ − 626
val (_, lthy9') = lthyC
2436
+ − 627
|> Local_Theory.note ((thms_suffix "distinct", []), qdistincts)
2492
5ac9a74d22fd
post-processed eq_iff and supp threormes according to the fv-supp equality
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 628
||>> Local_Theory.note ((thms_suffix "eq_iff", []), qeq_iffs')
2436
+ − 629
||>> Local_Theory.note ((thms_suffix "fv_defs", []), qfv_defs)
+ − 630
||>> Local_Theory.note ((thms_suffix "bn_defs", []), qbn_defs)
2448
+ − 631
||>> Local_Theory.note ((thms_suffix "perm_simps", [eqvt_attr, simp_attr]), qperm_simps)
2436
+ − 632
||>> Local_Theory.note ((thms_suffix "fv_bn_eqvt", []), qfv_qbn_eqvts)
2487
+ − 633
||>> Local_Theory.note ((thms_suffix "size", []), qsize_simps)
2436
+ − 634
||>> Local_Theory.note ((thms_suffix "size_eqvt", []), qsize_eqvt)
+ − 635
||>> Local_Theory.note ((thms_suffix "induct", []), [qinduct])
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
+ − 636
||>> Local_Theory.note ((thms_suffix "inducts", []), qinducts)
2436
+ − 637
||>> Local_Theory.note ((thms_suffix "exhaust", []), qexhausts)
2448
+ − 638
||>> Local_Theory.note ((thms_suffix "supports", []), qsupports_thms)
2450
+ − 639
||>> 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
+ − 640
||>> Local_Theory.note ((thms_suffix "supp", []), qsupp_constrs)
2493
+ − 641
||>> Local_Theory.note ((thms_suffix "fresh", []), qfresh_constrs)
2500
+ − 642
||>> Local_Theory.note ((thms_suffix "raw_alpha", []), alpha_intros)
2563
+ − 643
||>> Local_Theory.note ((thms_suffix "perm_bn_simps", []), qperm_bn_simps)
2571
+ − 644
||>> 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
+ − 645
||>> Local_Theory.note ((thms_suffix "perm_bn_alpha", []), qperm_bn_alpha_thms)
2598
+ − 646
||>> Local_Theory.note ((thms_suffix "permute_bn", []), qpermute_bn_thms)
1941
+ − 647
in
2435
+ − 648
(0, lthy9')
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
+ − 649
end handle TEST ctxt => (0, ctxt)
1941
+ − 650
*}
+ − 651
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
+ − 652
1941
+ − 653
section {* Preparing and parsing of the specification *}
+ − 654
+ − 655
ML {*
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 656
(* generates the parsed datatypes and
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 657
declares the constructors
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 658
*)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 659
fun prepare_dts dt_strs thy =
1941
+ − 660
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 661
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
+ − 662
(a, Type.inter_sort (Sign.tsig_of thy) (@{sort fs}, S))
1941
+ − 663
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 664
fun mk_type tname sorts (cname, cargs, mx) =
1941
+ − 665
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 666
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
+ − 667
val ty = Type (full_tname, map (TFree o inter_fs_sort thy) sorts)
1941
+ − 668
in
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 669
(cname, cargs ---> ty, mx)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 670
end
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 671
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 672
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
+ − 673
let
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 674
val (cargs', sorts') =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 675
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
+ − 676
|>> 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
+ − 677
in
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 678
(constrs @ [(cname, cargs', mx)], sorts')
1941
+ − 679
end
+ − 680
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 681
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
+ − 682
let
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 683
val (constrs', sorts') =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 684
fold prep_constr constrs ([], sorts)
1941
+ − 685
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 686
val constr_trms' =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 687
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
+ − 688
in
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 689
(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
+ − 690
end
2425
+ − 691
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 692
val (constr_trms, dts, sorts) = fold prep_dts dt_strs ([], [], []);
1941
+ − 693
in
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 694
thy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 695
|> Sign.add_consts_i constr_trms
1941
+ − 696
|> pair dts
+ − 697
end
+ − 698
*}
+ − 699
+ − 700
ML {*
+ − 701
(* parsing the binding function specification and *)
+ − 702
(* 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
+ − 703
fun prepare_bn_funs bn_fun_strs bn_eq_strs thy =
1941
+ − 704
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 705
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
+ − 706
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 707
val ((bn_funs, bn_eqs), lthy') =
1941
+ − 708
Specification.read_spec bn_fun_strs bn_eq_strs lthy
+ − 709
+ − 710
fun prep_bn_fun ((bn, T), mx) = (bn, T, mx)
+ − 711
+ − 712
val bn_funs' = map prep_bn_fun bn_funs
+ − 713
in
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 714
(Local_Theory.exit_global lthy')
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 715
|> Sign.add_consts_i bn_funs'
1941
+ − 716
|> pair (bn_funs', bn_eqs)
+ − 717
end
+ − 718
*}
+ − 719
+ − 720
text {* associates every SOME with the index in the list; drops NONEs *}
+ − 721
ML {*
+ − 722
fun indexify xs =
+ − 723
let
+ − 724
fun mapp _ [] = []
+ − 725
| mapp i (NONE :: xs) = mapp (i + 1) xs
+ − 726
| mapp i (SOME x :: xs) = (x, i) :: mapp (i + 1) xs
+ − 727
in
+ − 728
mapp 0 xs
+ − 729
end
+ − 730
+ − 731
fun index_lookup xs x =
+ − 732
case AList.lookup (op=) xs x of
+ − 733
SOME x => x
+ − 734
| NONE => error ("Cannot find " ^ x ^ " as argument annotation.");
+ − 735
*}
+ − 736
+ − 737
ML {*
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 738
fun prepare_bclauses dt_strs thy =
1941
+ − 739
let
+ − 740
val annos_bclauses =
+ − 741
get_cnstrs dt_strs
+ − 742
|> map (map (fn (_, antys, _, bns) => (map fst antys, bns)))
+ − 743
+ − 744
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
+ − 745
case (Syntax.read_term_global thy bn_str) of
1941
+ − 746
Free (x, _) => (NONE, index_lookup env x)
+ − 747
| Const (a, T) $ Free (x, _) => (SOME (Const (a, T)), index_lookup env x)
+ − 748
| _ => error ("The term " ^ bn_str ^ " is not allowed as binding function.")
+ − 749
+ − 750
fun prep_body env bn_str = index_lookup env bn_str
+ − 751
+ − 752
fun prep_bclause env (mode, binders, bodies) =
+ − 753
let
+ − 754
val binders' = map (prep_binder env) binders
+ − 755
val bodies' = map (prep_body env) bodies
+ − 756
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
+ − 757
BC (mode, binders', bodies')
1941
+ − 758
end
+ − 759
+ − 760
fun prep_bclauses (annos, bclause_strs) =
+ − 761
let
+ − 762
val env = indexify annos (* for every label, associate the index *)
+ − 763
in
+ − 764
map (prep_bclause env) bclause_strs
+ − 765
end
+ − 766
in
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 767
(map (map prep_bclauses) annos_bclauses, thy)
1941
+ − 768
end
+ − 769
*}
+ − 770
1943
+ − 771
text {*
+ − 772
adds an empty binding clause for every argument
+ − 773
that is not already part of a binding clause
+ − 774
*}
+ − 775
1941
+ − 776
ML {*
+ − 777
fun included i bcs =
+ − 778
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 779
fun incl (BC (_, bns, bds)) =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 780
member (op =) (map snd bns) i orelse member (op =) bds i
1941
+ − 781
in
+ − 782
exists incl bcs
+ − 783
end
+ − 784
*}
+ − 785
+ − 786
ML {*
+ − 787
fun complete dt_strs bclauses =
+ − 788
let
+ − 789
val args =
+ − 790
get_cnstrs dt_strs
+ − 791
|> map (map (fn (_, antys, _, _) => length antys))
+ − 792
+ − 793
fun complt n bcs =
+ − 794
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
+ − 795
fun add bcs i = (if included i bcs then [] else [BC (Lst, [], [i])])
1941
+ − 796
in
+ − 797
bcs @ (flat (map_range (add bcs) n))
+ − 798
end
+ − 799
in
+ − 800
map2 (map2 complt) args bclauses
+ − 801
end
+ − 802
*}
+ − 803
+ − 804
ML {*
2436
+ − 805
fun nominal_datatype2_cmd (opt_thms_name, dt_strs, bn_fun_strs, bn_eq_strs) lthy =
1941
+ − 806
let
2436
+ − 807
val pre_typs =
+ − 808
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
+ − 809
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 810
(* 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
+ − 811
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
+ − 812
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
+ − 813
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 814
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
+ − 815
tmp_thy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 816
|> Sign.add_types pre_typs
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 817
|> prepare_dts dt_strs
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 818
||>> 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
+ − 819
||>> prepare_bclauses dt_strs
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 820
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 821
val bclauses' = complete dt_strs bclauses
1941
+ − 822
in
2436
+ − 823
timeit (fn () => nominal_datatype2 opt_thms_name dts bn_funs bn_eqs bclauses' lthy |> snd)
1941
+ − 824
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
+ − 825
*}
1941
+ − 826
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
+ − 827
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
+ − 828
(* 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
+ − 829
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
+ − 830
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
+ − 831
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
+ − 832
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 833
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
+ − 834
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
+ − 835
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
+ − 836
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
+ − 837
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
+ − 838
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
+ − 839
val _ = Keyword.keyword "bind"
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 840
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 841
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
+ − 842
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
+ − 843
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
+ − 844
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
+ − 845
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
+ − 846
S.optional (Args.parens
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 847
(Args.$$$ "list" >> K Lst || Args.$$$ "set" >> K Set || Args.$$$ "res" >> K Res)) Lst
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 848
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
+ − 849
val bind_clauses =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 850
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
+ − 851
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
+ − 852
val cnstr_parser =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 853
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
+ − 854
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
+ − 855
(* 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
+ − 856
val dt_parser =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 857
(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
+ − 858
(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
+ − 859
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
+ − 860
(* 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
+ − 861
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
+ − 862
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
+ − 863
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
+ − 864
(* 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
+ − 865
val main_parser =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 866
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
+ − 867
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
+ − 868
end
1941
+ − 869
+ − 870
(* Command Keyword *)
2168
+ − 871
val _ = Outer_Syntax.local_theory "nominal_datatype" "test" Keyword.thy_decl
1941
+ − 872
(main_parser >> nominal_datatype2_cmd)
+ − 873
*}
+ − 874
2292
+ − 875
1941
+ − 876
end
+ − 877
+ − 878
+ − 879