1941
+ − 1
theory NewParser
1971
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 2
imports "../Nominal-General/Nominal2_Base"
1941
+ − 3
"../Nominal-General/Nominal2_Eqvt"
+ − 4
"../Nominal-General/Nominal2_Supp"
2297
+ − 5
"Perm" "Tacs" "Equivp" "Lift"
1941
+ − 6
begin
+ − 7
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
+ − 8
1941
+ − 9
section{* Interface for nominal_datatype *}
+ − 10
+ − 11
+ − 12
ML {*
+ − 13
(* nominal datatype parser *)
+ − 14
local
2168
+ − 15
structure P = Parse;
1941
+ − 16
structure S = Scan
+ − 17
+ − 18
fun triple1 ((x, y), z) = (x, y, z)
+ − 19
fun triple2 (x, (y, z)) = (x, y, z)
+ − 20
fun tuple ((x, y, z), u) = (x, y, z, u)
+ − 21
fun tswap (((x, y), z), u) = (x, y, u, z)
+ − 22
in
+ − 23
2168
+ − 24
val _ = Keyword.keyword "bind"
+ − 25
val _ = Keyword.keyword "bind_set"
+ − 26
val _ = Keyword.keyword "bind_res"
1941
+ − 27
1943
+ − 28
val anno_typ = S.option (P.name --| P.$$$ "::") -- P.typ
1941
+ − 29
+ − 30
val bind_mode = P.$$$ "bind" || P.$$$ "bind_set" || P.$$$ "bind_res"
+ − 31
+ − 32
val bind_clauses =
+ − 33
P.enum "," (bind_mode -- S.repeat1 P.term -- (P.$$$ "in" |-- S.repeat1 P.name) >> triple1)
+ − 34
+ − 35
val cnstr_parser =
1943
+ − 36
P.binding -- S.repeat anno_typ -- bind_clauses -- P.opt_mixfix >> tswap
1941
+ − 37
+ − 38
(* datatype parser *)
+ − 39
val dt_parser =
+ − 40
(P.type_args -- P.binding -- P.opt_mixfix >> triple1) --
1943
+ − 41
(P.$$$ "=" |-- P.enum1 "|" cnstr_parser) >> tuple
1941
+ − 42
+ − 43
(* binding function parser *)
+ − 44
val bnfun_parser =
2168
+ − 45
S.optional (P.$$$ "binder" |-- P.fixes -- Parse_Spec.where_alt_specs) ([], [])
1941
+ − 46
+ − 47
(* main parser *)
+ − 48
val main_parser =
1944
+ − 49
P.and_list1 dt_parser -- bnfun_parser >> triple2
1941
+ − 50
+ − 51
end
+ − 52
*}
+ − 53
+ − 54
ML {*
+ − 55
fun get_cnstrs dts =
+ − 56
map (fn (_, _, _, constrs) => constrs) dts
+ − 57
+ − 58
fun get_typed_cnstrs dts =
+ − 59
flat (map (fn (_, bn, _, constrs) =>
+ − 60
(map (fn (bn', _, _) => (Binding.name_of bn, Binding.name_of bn')) constrs)) dts)
+ − 61
+ − 62
fun get_cnstr_strs dts =
+ − 63
map (fn (bn, _, _) => Binding.name_of bn) (flat (get_cnstrs dts))
+ − 64
+ − 65
fun get_bn_fun_strs bn_funs =
+ − 66
map (fn (bn_fun, _, _) => Binding.name_of bn_fun) bn_funs
+ − 67
*}
+ − 68
2106
+ − 69
1941
+ − 70
ML {*
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
+ − 71
(* exports back the results *)
1941
+ − 72
fun add_primrec_wrapper funs eqs lthy =
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
+ − 73
if null funs then ([], [], lthy)
1941
+ − 74
else
+ − 75
let
+ − 76
val eqs' = map (fn (_, eq) => (Attrib.empty_binding, eq)) eqs
+ − 77
val funs' = map (fn (bn, ty, mx) => (bn, SOME ty, mx)) funs
2106
+ − 78
val ((funs'', eqs''), lthy') = Primrec.add_primrec funs' eqs' lthy
+ − 79
val phi = ProofContext.export_morphism lthy' lthy
1941
+ − 80
in
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
+ − 81
(map (Morphism.term phi) funs'', map (Morphism.thm phi) eqs'', lthy')
1941
+ − 82
end
+ − 83
*}
+ − 84
+ − 85
ML {*
+ − 86
fun add_datatype_wrapper dt_names dts =
+ − 87
let
+ − 88
val conf = Datatype.default_config
+ − 89
in
+ − 90
Local_Theory.theory_result (Datatype.add_datatype conf dt_names dts)
+ − 91
end
+ − 92
*}
+ − 93
1944
+ − 94
+ − 95
text {* Infrastructure for adding "_raw" to types and terms *}
+ − 96
1941
+ − 97
ML {*
+ − 98
fun add_raw s = s ^ "_raw"
+ − 99
fun add_raws ss = map add_raw ss
+ − 100
fun raw_bind bn = Binding.suffix_name "_raw" bn
+ − 101
+ − 102
fun replace_str ss s =
+ − 103
case (AList.lookup (op=) ss s) of
+ − 104
SOME s' => s'
+ − 105
| NONE => s
+ − 106
+ − 107
fun replace_typ ty_ss (Type (a, Ts)) = Type (replace_str ty_ss a, map (replace_typ ty_ss) Ts)
+ − 108
| replace_typ ty_ss T = T
+ − 109
+ − 110
fun raw_dts ty_ss dts =
+ − 111
let
+ − 112
fun raw_dts_aux1 (bind, tys, mx) =
+ − 113
(raw_bind bind, map (replace_typ ty_ss) tys, mx)
+ − 114
+ − 115
fun raw_dts_aux2 (ty_args, bind, mx, constrs) =
+ − 116
(ty_args, raw_bind bind, mx, map raw_dts_aux1 constrs)
+ − 117
in
+ − 118
map raw_dts_aux2 dts
+ − 119
end
+ − 120
+ − 121
fun replace_aterm trm_ss (Const (a, T)) = Const (replace_str trm_ss a, T)
+ − 122
| replace_aterm trm_ss (Free (a, T)) = Free (replace_str trm_ss a, T)
+ − 123
| replace_aterm trm_ss trm = trm
+ − 124
+ − 125
fun replace_term trm_ss ty_ss trm =
+ − 126
trm |> Term.map_aterms (replace_aterm trm_ss) |> map_types (replace_typ ty_ss)
+ − 127
*}
+ − 128
+ − 129
ML {*
+ − 130
fun rawify_dts dt_names dts dts_env =
+ − 131
let
+ − 132
val raw_dts = raw_dts dts_env dts
+ − 133
val raw_dt_names = add_raws dt_names
+ − 134
in
+ − 135
(raw_dt_names, raw_dts)
+ − 136
end
+ − 137
*}
+ − 138
+ − 139
ML {*
+ − 140
fun rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs =
+ − 141
let
+ − 142
val bn_funs' = map (fn (bn, ty, mx) =>
2304
+ − 143
(raw_bind bn, SOME (replace_typ dts_env ty), mx)) bn_funs
1941
+ − 144
+ − 145
val bn_eqs' = map (fn (attr, trm) =>
+ − 146
(attr, replace_term (cnstrs_env @ bn_fun_env) dts_env trm)) bn_eqs
+ − 147
in
+ − 148
(bn_funs', bn_eqs')
+ − 149
end
+ − 150
*}
+ − 151
+ − 152
ML {*
+ − 153
fun rawify_bclauses dts_env cnstrs_env bn_fun_env bclauses =
+ − 154
let
+ − 155
fun rawify_bnds bnds =
+ − 156
map (apfst (Option.map (replace_term (cnstrs_env @ bn_fun_env) dts_env))) bnds
+ − 157
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
+ − 158
fun rawify_bclause (BC (mode, bnds, bdys)) = BC (mode, rawify_bnds bnds, bdys)
1941
+ − 159
in
+ − 160
map (map (map rawify_bclause)) bclauses
+ − 161
end
+ − 162
*}
+ − 163
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
+ − 164
(* 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
+ − 165
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
+ − 166
bn function *)
1941
+ − 167
ML {*
2294
+ − 168
fun strip_bn_fun lthy args t =
+ − 169
let
+ − 170
fun aux t =
+ − 171
case t of
+ − 172
Const (@{const_name sup}, _) $ l $ r => aux l @ aux r
+ − 173
| Const (@{const_name append}, _) $ l $ r => aux l @ aux r
+ − 174
| Const (@{const_name insert}, _) $ (Const (@{const_name atom}, _) $ (x as Var _)) $ y =>
+ − 175
(find_index (equal x) args, NONE) :: aux y
+ − 176
| Const (@{const_name Cons}, _) $ (Const (@{const_name atom}, _) $ (x as Var _)) $ y =>
+ − 177
(find_index (equal x) args, NONE) :: aux y
+ − 178
| Const (@{const_name bot}, _) => []
+ − 179
| Const (@{const_name Nil}, _) => []
+ − 180
| (f as Const _) $ (x as Var _) => [(find_index (equal x) args, SOME f)]
+ − 181
| _ => error ("Unsupported binding function: " ^ (Syntax.string_of_term lthy t))
+ − 182
in
+ − 183
aux t
+ − 184
end
1941
+ − 185
*}
+ − 186
+ − 187
ML {*
+ − 188
fun find [] _ = error ("cannot find element")
+ − 189
| find ((x, z)::xs) y = if (Long_Name.base_name x) = y then z else find xs y
+ − 190
*}
+ − 191
+ − 192
ML {*
2295
+ − 193
fun prep_bn_info lthy dt_names dts eqs =
1941
+ − 194
let
+ − 195
fun aux eq =
+ − 196
let
+ − 197
val (lhs, rhs) = eq
+ − 198
|> HOLogic.dest_Trueprop
+ − 199
|> HOLogic.dest_eq
+ − 200
val (bn_fun, [cnstr]) = strip_comb lhs
2294
+ − 201
val (_, ty) = dest_Const bn_fun
1941
+ − 202
val (ty_name, _) = dest_Type (domain_type ty)
+ − 203
val dt_index = find_index (fn x => x = ty_name) dt_names
2294
+ − 204
val (cnstr_head, cnstr_args) = strip_comb cnstr
+ − 205
val rhs_elements = strip_bn_fun lthy cnstr_args rhs
1941
+ − 206
val included = map (apfst (fn i => length (cnstr_args) - i - 1)) rhs_elements
+ − 207
in
+ − 208
(dt_index, (bn_fun, (cnstr_head, included)))
2122
+ − 209
end
1941
+ − 210
fun order dts i ts =
+ − 211
let
+ − 212
val dt = nth dts i
+ − 213
val cts = map (fn (x, _, _) => Binding.name_of x) ((fn (_, _, _, x) => x) dt)
+ − 214
val ts' = map (fn (x, y) => (fst (dest_Const x), y)) ts
+ − 215
in
+ − 216
map (find ts') cts
+ − 217
end
+ − 218
+ − 219
val unordered = AList.group (op=) (map aux eqs)
+ − 220
val unordered' = map (fn (x, y) => (x, AList.group (op=) y)) unordered
+ − 221
val ordered = map (fn (x, y) => (x, map (fn (v, z) => (v, order dts x z)) y)) unordered'
2118
+ − 222
val ordered' = flat (map (fn (ith, l) => map (fn (bn, data) => (bn, ith, data)) l) ordered)
2122
+ − 223
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
+ − 224
(*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
+ − 225
(*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
+ − 226
(*val _ = tracing ("ordered'\n" ^ @{make_string} ordered')*)
1941
+ − 227
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
+ − 228
ordered'
1941
+ − 229
end
+ − 230
*}
+ − 231
2304
+ − 232
ML {* rawify_bn_funs *}
+ − 233
1941
+ − 234
ML {*
+ − 235
fun raw_nominal_decls dts bn_funs bn_eqs binds lthy =
+ − 236
let
+ − 237
val thy = ProofContext.theory_of lthy
+ − 238
val thy_name = Context.theory_name thy
+ − 239
+ − 240
val dt_names = map (fn (_, s, _, _) => Binding.name_of s) dts
+ − 241
val dt_full_names = map (Long_Name.qualify thy_name) dt_names
+ − 242
val dt_full_names' = add_raws dt_full_names
+ − 243
val dts_env = dt_full_names ~~ dt_full_names'
+ − 244
+ − 245
val cnstrs = get_cnstr_strs dts
+ − 246
val cnstrs_ty = get_typed_cnstrs dts
+ − 247
val cnstrs_full_names = map (Long_Name.qualify thy_name) cnstrs
+ − 248
val cnstrs_full_names' = map (fn (x, y) => Long_Name.qualify thy_name
+ − 249
(Long_Name.qualify (add_raw x) (add_raw y))) cnstrs_ty
+ − 250
val cnstrs_env = cnstrs_full_names ~~ cnstrs_full_names'
+ − 251
+ − 252
val bn_fun_strs = get_bn_fun_strs bn_funs
+ − 253
val bn_fun_strs' = add_raws bn_fun_strs
+ − 254
val bn_fun_env = bn_fun_strs ~~ bn_fun_strs'
+ − 255
val bn_fun_full_env = map (pairself (Long_Name.qualify thy_name))
+ − 256
(bn_fun_strs ~~ bn_fun_strs')
+ − 257
+ − 258
val (raw_dt_names, raw_dts) = rawify_dts dt_names dts dts_env
+ − 259
val (raw_bn_funs, raw_bn_eqs) = rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs
+ − 260
val raw_bclauses = rawify_bclauses dts_env cnstrs_env bn_fun_full_env binds
+ − 261
2294
+ − 262
val (raw_dt_full_names, lthy1) = add_datatype_wrapper raw_dt_names raw_dts lthy
2304
+ − 263
+ − 264
in
+ − 265
(dt_full_names', raw_dt_full_names, raw_dts, raw_bclauses, raw_bn_funs, raw_bn_eqs, lthy1)
+ − 266
end
+ − 267
*}
+ − 268
+ − 269
ML {*
+ − 270
fun raw_bn_decls dt_names dts raw_bn_funs raw_bn_eqs constr_thms lthy =
+ − 271
let
+ − 272
val (_, lthy2) = Function.add_function raw_bn_funs raw_bn_eqs
+ − 273
Function_Common.default_config (pat_completeness_simp constr_thms) lthy
+ − 274
+ − 275
val (info, lthy3) = prove_termination (Local_Theory.restore lthy2)
+ − 276
val {fs, simps, inducts, ...} = info;
+ − 277
2305
+ − 278
val raw_bn_induct = (the inducts)
2304
+ − 279
val raw_bn_eqs = the simps
2142
c39d4fe31100
moved the exporting part into the parser (this is still a hack); re-added CoreHaskell again to the examples - there seems to be a problem with the variable name pat
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 280
2295
+ − 281
val raw_bn_info =
2304
+ − 282
prep_bn_info lthy dt_names dts (map prop_of raw_bn_eqs)
+ − 283
1941
+ − 284
in
2304
+ − 285
(fs, raw_bn_eqs, raw_bn_info, raw_bn_induct, lthy3)
1941
+ − 286
end
+ − 287
*}
+ − 288
2304
+ − 289
2017
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 290
lemma equivp_hack: "equivp x"
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 291
sorry
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 292
ML {*
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 293
fun equivp_hack ctxt rel =
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 294
let
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 295
val thy = ProofContext.theory_of ctxt
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 296
val ty = domain_type (fastype_of rel)
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 297
val cty = ctyp_of thy ty
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 298
val ct = cterm_of thy rel
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 299
in
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 300
Drule.instantiate' [SOME cty] [SOME ct] @{thm equivp_hack}
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 301
end
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 302
*}
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 303
2023
+ − 304
ML {* val cheat_equivp = Unsynchronized.ref false *}
+ − 305
ML {* val cheat_fv_rsp = Unsynchronized.ref false *}
+ − 306
ML {* val cheat_alpha_bn_rsp = Unsynchronized.ref false *}
+ − 307
ML {* val cheat_supp_eq = Unsynchronized.ref false *}
2008
1bddffddc03f
attempted to remove dependency on (old) Fv and (old) Parser; lifting still uses Fv.thy; the examples do not work at the moment (with equivp proofs failing)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 308
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
+ − 309
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
+ − 310
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
+ − 311
(* 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
+ − 312
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
+ − 313
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
+ − 314
val (STEPS, STEPS_setup) = Attrib.config_int "STEPS" (K 10);
60ee289a8c63
made out of STEPS a configuration value so that it can be set individually in each file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 315
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
+ − 316
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
+ − 317
*}
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
+ − 318
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
+ − 319
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
+ − 320
1941
+ − 321
ML {*
+ − 322
fun nominal_datatype2 dts bn_funs bn_eqs bclauses lthy =
+ − 323
let
2294
+ − 324
(* definition of the raw datatypes *)
2304
+ − 325
val (dt_names, raw_dt_names, raw_dts, raw_bclauses, raw_bn_funs, raw_bn_eqs, lthy0) =
2295
+ − 326
if get_STEPS lthy > 1
+ − 327
then raw_nominal_decls dts bn_funs bn_eqs bclauses lthy
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 328
else raise TEST lthy
1941
+ − 329
2304
+ − 330
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
+ − 331
val {descr, sorts, ...} = dtinfo
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
+ − 332
val all_tys = map (fn (i, _) => nth_dtyp descr sorts i) descr
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
+ − 333
val all_full_tnames = map (fn (_, (n, _, _)) => n) descr
2304
+ − 334
val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy0)) all_full_tnames
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
+ − 335
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
+ − 336
val inject_thms = flat (map #inject dtinfos);
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
+ − 337
val distinct_thms = flat (map #distinct dtinfos);
2304
+ − 338
val constr_thms = inject_thms @ distinct_thms
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
+ − 339
val rel_dtinfos = List.take (dtinfos, (length dts));
2300
+ − 340
val raw_constrs_distinct = (map #distinct rel_dtinfos);
2047
+ − 341
val induct_thm = #induct dtinfo;
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
+ − 342
val exhaust_thms = map #exhaust dtinfos;
1999
+ − 343
2304
+ − 344
val (raw_bn_funs, raw_bn_eqs, raw_bn_info, raw_bn_induct, lthy1) =
+ − 345
if get_STEPS lthy0 > 1
+ − 346
then raw_bn_decls dt_names raw_dts raw_bn_funs raw_bn_eqs constr_thms lthy0
+ − 347
else raise TEST lthy0
+ − 348
2299
+ − 349
val bn_nos = map (fn (_, i, _) => i) raw_bn_info;
+ − 350
val bns = raw_bn_funs ~~ bn_nos;
+ − 351
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
+ − 352
(* definitions of raw permutations *)
2292
+ − 353
val ((raw_perm_funs, raw_perm_defs, raw_perm_simps), lthy2) =
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
+ − 354
if get_STEPS lthy1 > 2
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
+ − 355
then Local_Theory.theory_result (define_raw_perms descr sorts induct_thm (length dts)) lthy1
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
+ − 356
else raise TEST lthy1
2144
+ − 357
+ − 358
(* noting the raw permutations as eqvt theorems *)
+ − 359
val eqvt_attrib = Attrib.internal (K Nominal_ThmDecls.eqvt_add)
+ − 360
val (_, lthy2a) = Local_Theory.note ((Binding.empty, [eqvt_attrib]), raw_perm_defs) lthy2
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
+ − 361
2105
+ − 362
val thy = Local_Theory.exit_global lthy2a;
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
+ − 363
val thy_name = Context.theory_name thy
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 364
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
+ − 365
(* definition of raw fv_functions *)
1960
+ − 366
val lthy3 = Theory_Target.init NONE thy;
+ − 367
2305
+ − 368
val (raw_fvs, raw_fv_bns, raw_fv_defs, raw_fv_bns_induct, lthy3a) =
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
+ − 369
if get_STEPS lthy2 > 3
2304
+ − 370
then define_raw_fvs descr sorts raw_bn_info raw_bclauses constr_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
+ − 371
else raise TEST lthy3
2292
+ − 372
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 373
(* definition of raw alphas *)
2300
+ − 374
val (alpha_trms, alpha_bn_trms, alpha_intros, alpha_cases, alpha_induct, lthy4) =
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
+ − 375
if get_STEPS lthy > 4
2297
+ − 376
then define_raw_alpha descr sorts raw_bn_info raw_bclauses raw_fvs lthy3a
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
+ − 377
else raise TEST lthy3a
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
+ − 378
2300
+ − 379
(* definition of alpha-distinct lemmas *)
+ − 380
val (alpha_distincts, alpha_bn_distincts) =
+ − 381
mk_alpha_distincts lthy4 alpha_cases raw_constrs_distinct alpha_trms alpha_bn_trms raw_bn_info
+ − 382
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 383
(* definition of raw_alpha_eq_iff lemmas *)
2295
+ − 384
val alpha_eq_iff =
+ − 385
if get_STEPS lthy > 5
2300
+ − 386
then mk_alpha_eq_iff lthy4 alpha_intros distinct_thms inject_thms alpha_cases
2295
+ − 387
else raise TEST lthy4
2022
+ − 388
2298
+ − 389
(* proving equivariance lemmas for bns, fvs 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
+ − 390
val _ = warning "Proving equivariance";
2305
+ − 391
val bn_eqvt =
2298
+ − 392
if get_STEPS lthy > 6
2305
+ − 393
then raw_prove_eqvt raw_bn_funs raw_bn_induct (raw_bn_eqs @ raw_perm_defs) lthy4
2298
+ − 394
else raise TEST lthy4
+ − 395
2305
+ − 396
val add_eqvt = Attrib.internal (K Nominal_ThmDecls.eqvt_add)
+ − 397
val (_, lthy_tmp) = Local_Theory.note ((Binding.empty, [add_eqvt]), bn_eqvt) lthy4
+ − 398
+ − 399
val fv_eqvt =
2298
+ − 400
if get_STEPS lthy > 7
2305
+ − 401
then raw_prove_eqvt (raw_fvs @ raw_fv_bns) raw_fv_bns_induct (raw_fv_defs @ raw_perm_defs) lthy_tmp
+ − 402
else raise TEST lthy4
+ − 403
+ − 404
val (_, lthy_tmp') = Local_Theory.note ((Binding.empty, [add_eqvt]), fv_eqvt) lthy_tmp
2298
+ − 405
2306
+ − 406
+ − 407
+ − 408
val (alpha_eqvt, _) =
2298
+ − 409
if get_STEPS lthy > 8
2306
+ − 410
then Nominal_Eqvt.equivariance false alpha_trms alpha_induct alpha_intros lthy_tmp'
2305
+ − 411
else raise TEST lthy4
2298
+ − 412
2306
+ − 413
(*
+ − 414
val _ = tracing ("bn_eqvts\n" ^ cat_lines (map @{make_string} bn_eqvt))
+ − 415
val _ = tracing ("fv_eqvts\n" ^ cat_lines (map @{make_string} fv_eqvt))
+ − 416
val _ = tracing ("alpha_eqvts\n" ^ cat_lines (map @{make_string} alpha_eqvt))
+ − 417
*)
+ − 418
2305
+ − 419
val _ =
+ − 420
if get_STEPS lthy > 9
+ − 421
then true else raise TEST lthy4
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 422
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
+ − 423
(* proving alpha equivalence *)
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
+ − 424
val _ = warning "Proving equivalence";
2305
+ − 425
+ − 426
val fv_alpha_all = combine_fv_alpha_bns (raw_fvs, raw_fv_bns) (alpha_trms, alpha_bn_trms) bn_nos
+ − 427
2306
+ − 428
val reflps = build_alpha_refl fv_alpha_all alpha_trms induct_thm alpha_eq_iff lthy4;
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
+ − 429
val alpha_equivp =
2306
+ − 430
if !cheat_equivp then map (equivp_hack lthy4) alpha_trms
2300
+ − 431
else build_equivps alpha_trms reflps alpha_induct
2306
+ − 432
inject_thms alpha_eq_iff distinct_thms alpha_cases alpha_eqvt lthy4;
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
+ − 433
val qty_binds = map (fn (_, b, _, _) => b) dts;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 434
val qty_names = map Name.of_binding qty_binds;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 435
val qty_full_names = map (Long_Name.qualify thy_name) qty_names
2306
+ − 436
val (qtys, lthy7) = define_quotient_types qty_binds all_tys alpha_trms alpha_equivp lthy4;
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
+ − 437
val const_names = map Name.of_binding (flat (map (fn (_, _, _, t) => map (fn (b, _, _) => b) t) dts));
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 438
val raw_consts =
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 439
flat (map (fn (i, (_, _, l)) =>
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 440
map (fn (cname, dts) =>
2016
+ − 441
Const (cname, map (Datatype_Aux.typ_of_dtyp descr sorts) dts --->
+ − 442
Datatype_Aux.typ_of_dtyp descr sorts (Datatype_Aux.DtRec i))) l) descr);
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
+ − 443
val (consts, const_defs, lthy8) = quotient_lift_consts_export qtys (const_names ~~ raw_consts) lthy7;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 444
val _ = warning "Proving respects";
2300
+ − 445
val bns_rsp_pre' = build_fvbv_rsps alpha_trms alpha_induct raw_bn_eqs (map fst bns) lthy8;
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 446
val (bns_rsp_pre, lthy9) = fold_map (
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 447
fn (bn_t, _) => prove_const_rsp qtys Binding.empty [bn_t] (fn _ =>
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 448
resolve_tac bns_rsp_pre' 1)) bns lthy8;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 449
val bns_rsp = flat (map snd bns_rsp_pre);
2017
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 450
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 451
fun fv_rsp_tac _ = if !cheat_fv_rsp then Skip_Proof.cheat_tac thy
2296
+ − 452
else fvbv_rsp_tac alpha_induct raw_fv_defs lthy8 1;
2300
+ − 453
val fv_rsps = prove_fv_rsp fv_alpha_all alpha_trms fv_rsp_tac lthy9;
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 454
val (fv_rsp_pre, lthy10) = fold_map
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 455
(fn fv => fn ctxt => prove_const_rsp qtys Binding.empty [fv]
2296
+ − 456
(fn _ => asm_simp_tac (HOL_ss addsimps fv_rsps) 1) ctxt) (raw_fvs @ raw_fv_bns) lthy9;
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 457
val fv_rsp = flat (map snd fv_rsp_pre);
2292
+ − 458
val (perms_rsp, lthy11) = prove_const_rsp qtys Binding.empty raw_perm_funs
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 459
(fn _ => asm_simp_tac (HOL_ss addsimps alpha_eqvt) 1) lthy10;
2023
+ − 460
fun alpha_bn_rsp_tac _ = if !cheat_alpha_bn_rsp then Skip_Proof.cheat_tac thy
+ − 461
else
2300
+ − 462
let val alpha_bn_rsp_pre = prove_alpha_bn_rsp alpha_trms alpha_induct (alpha_eq_iff @ alpha_distincts @ alpha_bn_distincts) alpha_equivp exhaust_thms alpha_bn_trms lthy11 in asm_simp_tac (HOL_ss addsimps alpha_bn_rsp_pre) 1 end;
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 463
val (alpha_bn_rsps, lthy11a) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst]
2300
+ − 464
alpha_bn_rsp_tac) alpha_bn_trms lthy11
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 465
fun const_rsp_tac _ =
2300
+ − 466
let val alpha_alphabn = prove_alpha_alphabn alpha_trms alpha_induct alpha_eq_iff alpha_bn_trms lthy11a
+ − 467
in constr_rsp_tac alpha_eq_iff (fv_rsp @ bns_rsp @ reflps @ alpha_alphabn) 1 end
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 468
val (const_rsps, lthy12) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst]
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 469
const_rsp_tac) raw_consts lthy11a
2296
+ − 470
val qfv_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) (raw_fvs @ raw_fv_bns)
+ − 471
val (qfv_ts, qfv_defs, lthy12a) = quotient_lift_consts_export qtys (qfv_names ~~ (raw_fvs @ raw_fv_bns)) lthy12;
2292
+ − 472
val (qfv_ts_nobn, qfv_ts_bn) = chop (length raw_perm_funs) qfv_ts;
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 473
val qbn_names = map (fn (b, _ , _) => Name.of_binding b) bn_funs
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 474
val (qbn_ts, qbn_defs, lthy12b) = quotient_lift_consts_export qtys (qbn_names ~~ raw_bn_funs) lthy12a;
2300
+ − 475
val qalpha_bn_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) alpha_bn_trms
+ − 476
val (qalpha_bn_trms, qalphabn_defs, lthy12c) =
+ − 477
quotient_lift_consts_export qtys (qalpha_bn_names ~~ alpha_bn_trms) lthy12b;
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
+ − 478
val _ = warning "Lifting permutations";
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 479
val thy = Local_Theory.exit_global lthy12c;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 480
val perm_names = map (fn x => "permute_" ^ x) qty_names
2292
+ − 481
val thy' = define_lifted_perms qtys qty_full_names (perm_names ~~ raw_perm_funs) raw_perm_simps thy;
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
+ − 482
val lthy13 = Theory_Target.init NONE thy';
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 483
val q_name = space_implode "_" qty_names;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 484
fun suffix_bind s = Binding.qualify true q_name (Binding.name s);
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 485
val _ = warning "Lifting induction";
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 486
val constr_names = map (Long_Name.base_name o fst o dest_Const) consts;
2047
+ − 487
val q_induct = Rule_Cases.name constr_names (lift_thm qtys lthy13 induct_thm);
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 488
fun note_suffix s th ctxt =
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 489
snd (Local_Theory.note ((suffix_bind s, []), th) ctxt);
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 490
fun note_simp_suffix s th ctxt =
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 491
snd (Local_Theory.note ((suffix_bind s, [Attrib.internal (K Simplifier.simp_add)]), th) ctxt);
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 492
val (_, lthy14) = Local_Theory.note ((suffix_bind "induct",
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 493
[Attrib.internal (K (Rule_Cases.case_names constr_names))]),
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 494
[Rule_Cases.name constr_names q_induct]) lthy13;
2296
+ − 495
val q_inducts = Project_Rule.projects lthy13 (1 upto (length raw_fvs)) q_induct
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 496
val (_, lthy14a) = Local_Theory.note ((suffix_bind "inducts", []), q_inducts) lthy14;
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
+ − 497
val q_perm = map (lift_thm qtys lthy14) raw_perm_defs;
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 498
val lthy15 = note_simp_suffix "perm" q_perm lthy14a;
2296
+ − 499
val q_fv = map (lift_thm qtys lthy15) raw_fv_defs;
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 500
val lthy16 = note_simp_suffix "fv" q_fv lthy15;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 501
val q_bn = map (lift_thm qtys lthy16) raw_bn_eqs;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 502
val lthy17 = note_simp_suffix "bn" q_bn lthy16;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 503
val _ = warning "Lifting eq-iff";
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 504
(*val _ = map tracing (map PolyML.makestring alpha_eq_iff);*)
2300
+ − 505
val eq_iff_unfolded0 = map (Local_Defs.unfold lthy17 @{thms alphas}) alpha_eq_iff
2089
+ − 506
val eq_iff_unfolded1 = map (Local_Defs.unfold lthy17 @{thms Pair_eqvt}) eq_iff_unfolded0
+ − 507
val q_eq_iff_pre0 = map (lift_thm qtys lthy17) eq_iff_unfolded1;
+ − 508
val q_eq_iff_pre1 = map (Local_Defs.fold lthy17 @{thms Pair_eqvt}) q_eq_iff_pre0
+ − 509
val q_eq_iff_pre2 = map (Local_Defs.fold lthy17 @{thms alphas}) q_eq_iff_pre1
+ − 510
val q_eq_iff = map (Local_Defs.unfold lthy17 (Quotient_Info.id_simps_get lthy17)) q_eq_iff_pre2
2025
+ − 511
val (_, lthy18) = Local_Theory.note ((suffix_bind "eq_iff", []), q_eq_iff) lthy17;
2300
+ − 512
val q_dis = map (lift_thm qtys lthy18) alpha_distincts;
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 513
val lthy19 = note_simp_suffix "distinct" q_dis lthy18;
2305
+ − 514
val q_eqvt = map (lift_thm qtys lthy19) (bn_eqvt @ fv_eqvt);
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 515
val (_, lthy20) = Local_Theory.note ((Binding.empty,
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 516
[Attrib.internal (fn _ => Nominal_ThmDecls.eqvt_add)]), q_eqvt) lthy19;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 517
val _ = warning "Supports";
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 518
val supports = map (prove_supports lthy20 q_perm) consts;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 519
val fin_supp = HOLogic.conj_elims (prove_fs lthy20 q_induct supports qtys);
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 520
val thy3 = Local_Theory.exit_global lthy20;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 521
val _ = warning "Instantiating FS";
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 522
val lthy21 = Theory_Target.instantiation (qty_full_names, [], @{sort fs}) thy3;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 523
fun tac _ = Class.intro_classes_tac [] THEN (ALLGOALS (resolve_tac fin_supp))
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 524
val lthy22 = Class.prove_instantiation_instance tac lthy21
2300
+ − 525
val fv_alpha_all = combine_fv_alpha_bns (qfv_ts_nobn, qfv_ts_bn) (alpha_trms, qalpha_bn_trms) bn_nos;
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 526
val (names, supp_eq_t) = supp_eq fv_alpha_all;
2020
+ − 527
val _ = warning "Support Equations";
2023
+ − 528
fun supp_eq_tac' _ = if !cheat_supp_eq then Skip_Proof.cheat_tac thy else
2025
+ − 529
supp_eq_tac q_induct q_fv q_perm q_eq_iff lthy22 1;
2023
+ − 530
val q_supp = HOLogic.conj_elims (Goal.prove lthy22 names [] supp_eq_t supp_eq_tac') handle e =>
+ − 531
let val _ = warning ("Support eqs failed") in [] end;
2020
+ − 532
val lthy23 = note_suffix "supp" q_supp lthy22;
1941
+ − 533
in
2020
+ − 534
(0, lthy23)
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 535
end handle TEST ctxt => (0, ctxt)
1941
+ − 536
*}
+ − 537
+ − 538
section {* Preparing and parsing of the specification *}
+ − 539
+ − 540
ML {*
+ − 541
(* parsing the datatypes and declaring *)
+ − 542
(* constructors in the local theory *)
+ − 543
fun prepare_dts dt_strs lthy =
+ − 544
let
+ − 545
val thy = ProofContext.theory_of lthy
+ − 546
+ − 547
fun mk_type full_tname tvrs =
+ − 548
Type (full_tname, map (fn a => TVar ((a, 0), [])) tvrs)
+ − 549
+ − 550
fun prep_cnstr full_tname tvs (cname, anno_tys, mx, _) =
+ − 551
let
+ − 552
val tys = map (Syntax.read_typ lthy o snd) anno_tys
+ − 553
val ty = mk_type full_tname tvs
+ − 554
in
+ − 555
((cname, tys ---> ty, mx), (cname, tys, mx))
+ − 556
end
+ − 557
+ − 558
fun prep_dt (tvs, tname, mx, cnstrs) =
+ − 559
let
+ − 560
val full_tname = Sign.full_name thy tname
+ − 561
val (cnstrs', cnstrs'') =
+ − 562
split_list (map (prep_cnstr full_tname tvs) cnstrs)
+ − 563
in
+ − 564
(cnstrs', (tvs, tname, mx, cnstrs''))
+ − 565
end
+ − 566
+ − 567
val (cnstrs, dts) = split_list (map prep_dt dt_strs)
+ − 568
in
+ − 569
lthy
+ − 570
|> Local_Theory.theory (Sign.add_consts_i (flat cnstrs))
+ − 571
|> pair dts
+ − 572
end
+ − 573
*}
+ − 574
+ − 575
ML {*
+ − 576
(* parsing the binding function specification and *)
+ − 577
(* declaring the functions in the local theory *)
+ − 578
fun prepare_bn_funs bn_fun_strs bn_eq_strs lthy =
+ − 579
let
+ − 580
val ((bn_funs, bn_eqs), _) =
+ − 581
Specification.read_spec bn_fun_strs bn_eq_strs lthy
+ − 582
+ − 583
fun prep_bn_fun ((bn, T), mx) = (bn, T, mx)
+ − 584
+ − 585
val bn_funs' = map prep_bn_fun bn_funs
+ − 586
in
+ − 587
lthy
+ − 588
|> Local_Theory.theory (Sign.add_consts_i bn_funs')
+ − 589
|> pair (bn_funs', bn_eqs)
+ − 590
end
+ − 591
*}
+ − 592
+ − 593
text {* associates every SOME with the index in the list; drops NONEs *}
+ − 594
ML {*
+ − 595
fun indexify xs =
+ − 596
let
+ − 597
fun mapp _ [] = []
+ − 598
| mapp i (NONE :: xs) = mapp (i + 1) xs
+ − 599
| mapp i (SOME x :: xs) = (x, i) :: mapp (i + 1) xs
+ − 600
in
+ − 601
mapp 0 xs
+ − 602
end
+ − 603
+ − 604
fun index_lookup xs x =
+ − 605
case AList.lookup (op=) xs x of
+ − 606
SOME x => x
+ − 607
| NONE => error ("Cannot find " ^ x ^ " as argument annotation.");
+ − 608
*}
+ − 609
+ − 610
ML {*
+ − 611
fun prepare_bclauses dt_strs lthy =
+ − 612
let
+ − 613
val annos_bclauses =
+ − 614
get_cnstrs dt_strs
+ − 615
|> map (map (fn (_, antys, _, bns) => (map fst antys, bns)))
+ − 616
+ − 617
fun prep_binder env bn_str =
+ − 618
case (Syntax.read_term lthy bn_str) of
+ − 619
Free (x, _) => (NONE, index_lookup env x)
+ − 620
| Const (a, T) $ Free (x, _) => (SOME (Const (a, T)), index_lookup env x)
+ − 621
| _ => error ("The term " ^ bn_str ^ " is not allowed as binding function.")
+ − 622
+ − 623
fun prep_body env bn_str = index_lookup env bn_str
+ − 624
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
+ − 625
fun prep_mode "bind" = Lst
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 626
| prep_mode "bind_set" = Set
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 627
| prep_mode "bind_res" = Res
1941
+ − 628
+ − 629
fun prep_bclause env (mode, binders, bodies) =
+ − 630
let
+ − 631
val binders' = map (prep_binder env) binders
+ − 632
val bodies' = map (prep_body env) bodies
+ − 633
in
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 634
BC (prep_mode mode, binders', bodies')
1941
+ − 635
end
+ − 636
+ − 637
fun prep_bclauses (annos, bclause_strs) =
+ − 638
let
+ − 639
val env = indexify annos (* for every label, associate the index *)
+ − 640
in
+ − 641
map (prep_bclause env) bclause_strs
+ − 642
end
+ − 643
in
+ − 644
map (map prep_bclauses) annos_bclauses
+ − 645
end
+ − 646
*}
+ − 647
1943
+ − 648
text {*
+ − 649
adds an empty binding clause for every argument
+ − 650
that is not already part of a binding clause
+ − 651
*}
+ − 652
1941
+ − 653
ML {*
+ − 654
fun included i bcs =
+ − 655
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
+ − 656
fun incl (BC (_, bns, bds)) = (member (op =) (map snd bns) i) orelse (member (op =) bds i)
1941
+ − 657
in
+ − 658
exists incl bcs
+ − 659
end
+ − 660
*}
+ − 661
+ − 662
ML {*
+ − 663
fun complete dt_strs bclauses =
+ − 664
let
+ − 665
val args =
+ − 666
get_cnstrs dt_strs
+ − 667
|> map (map (fn (_, antys, _, _) => length antys))
+ − 668
+ − 669
fun complt n bcs =
+ − 670
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
+ − 671
fun add bcs i = (if included i bcs then [] else [BC (Lst, [], [i])])
1941
+ − 672
in
+ − 673
bcs @ (flat (map_range (add bcs) n))
+ − 674
end
+ − 675
in
+ − 676
map2 (map2 complt) args bclauses
+ − 677
end
+ − 678
*}
+ − 679
+ − 680
ML {*
+ − 681
fun nominal_datatype2_cmd (dt_strs, bn_fun_strs, bn_eq_strs) lthy =
+ − 682
let
+ − 683
fun prep_typ (tvs, tname, mx, _) = (tname, length tvs, mx)
+ − 684
val lthy0 =
+ − 685
Local_Theory.theory (Sign.add_types (map prep_typ dt_strs)) lthy
1944
+ − 686
val (dts, lthy1) = prepare_dts dt_strs lthy0
+ − 687
val ((bn_funs, bn_eqs), lthy2) = prepare_bn_funs bn_fun_strs bn_eq_strs lthy1
1941
+ − 688
val bclauses = prepare_bclauses dt_strs lthy2
+ − 689
val bclauses' = complete dt_strs bclauses
+ − 690
in
+ − 691
nominal_datatype2 dts bn_funs bn_eqs bclauses' lthy |> snd
+ − 692
end
+ − 693
+ − 694
+ − 695
(* Command Keyword *)
+ − 696
2168
+ − 697
val _ = Outer_Syntax.local_theory "nominal_datatype" "test" Keyword.thy_decl
1941
+ − 698
(main_parser >> nominal_datatype2_cmd)
+ − 699
*}
+ − 700
2292
+ − 701
+ − 702
text {*
+ − 703
nominal_datatype2 does the following things in order:
1941
+ − 704
2292
+ − 705
Parser.thy/raw_nominal_decls
+ − 706
1) define the raw datatype
+ − 707
2) define the raw binding functions
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 708
2292
+ − 709
Perm.thy/define_raw_perms
+ − 710
3) define permutations of the raw datatype and show that the raw type is
+ − 711
in the pt typeclass
+ − 712
+ − 713
Lift.thy/define_fv_alpha_export, Fv.thy/define_fv & define_alpha
+ − 714
4) define fv and fv_bn
+ − 715
5) define alpha and alpha_bn
1941
+ − 716
2292
+ − 717
Perm.thy/distinct_rel
+ − 718
6) prove alpha_distincts (C1 x \<notsimeq> C2 y ...) (Proof by cases; simp)
1941
+ − 719
2292
+ − 720
Tacs.thy/build_rel_inj
+ − 721
6) prove alpha_eq_iff (C1 x = C2 y \<leftrightarrow> P x y ...)
+ − 722
(left-to-right by intro rule, right-to-left by cases; simp)
+ − 723
Equivp.thy/prove_eqvt
+ − 724
7) prove bn_eqvt (common induction on the raw datatype)
+ − 725
8) prove fv_eqvt (common induction on the raw datatype with help of above)
+ − 726
Rsp.thy/build_alpha_eqvts
+ − 727
9) prove alpha_eqvt and alpha_bn_eqvt
+ − 728
(common alpha-induction, unfolding alpha_gen, permute of #* and =)
+ − 729
Equivp.thy/build_alpha_refl & Equivp.thy/build_equivps
+ − 730
10) prove that alpha and alpha_bn are equivalence relations
+ − 731
(common induction and application of 'compose' lemmas)
+ − 732
Lift.thy/define_quotient_types
+ − 733
11) define quotient types
+ − 734
Rsp.thy/build_fvbv_rsps
+ − 735
12) prove bn respects (common induction and simp with alpha_gen)
+ − 736
Rsp.thy/prove_const_rsp
+ − 737
13) prove fv respects (common induction and simp with alpha_gen)
+ − 738
14) prove permute respects (unfolds to alpha_eqvt)
+ − 739
Rsp.thy/prove_alpha_bn_rsp
+ − 740
15) prove alpha_bn respects
+ − 741
(alpha_induct then cases then sym and trans of the relations)
+ − 742
Rsp.thy/prove_alpha_alphabn
+ − 743
16) show that alpha implies alpha_bn (by unduction, needed in following step)
+ − 744
Rsp.thy/prove_const_rsp
+ − 745
17) prove respects for all datatype constructors
+ − 746
(unfold eq_iff and alpha_gen; introduce zero permutations; simp)
+ − 747
Perm.thy/quotient_lift_consts_export
+ − 748
18) define lifted constructors, fv, bn, alpha_bn, permutations
+ − 749
Perm.thy/define_lifted_perms
+ − 750
19) lift permutation zero and add properties to show that quotient type is in the pt typeclass
+ − 751
Lift.thy/lift_thm
+ − 752
20) lift permutation simplifications
+ − 753
21) lift induction
+ − 754
22) lift fv
+ − 755
23) lift bn
+ − 756
24) lift eq_iff
+ − 757
25) lift alpha_distincts
+ − 758
26) lift fv and bn eqvts
+ − 759
Equivp.thy/prove_supports
+ − 760
27) prove that union of arguments supports constructors
+ − 761
Equivp.thy/prove_fs
+ − 762
28) show that the lifted type is in fs typeclass (* by q_induct, supports *)
+ − 763
Equivp.thy/supp_eq
+ − 764
29) prove supp = fv
+ − 765
*}
1964
+ − 766
1941
+ − 767
+ − 768
+ − 769
end
+ − 770
+ − 771
+ − 772