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