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"
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
+ − 5
"Perm" "NewFv" "NewAlpha" "Tacs" "Equivp" "Lift"
1941
+ − 6
begin
+ − 7
+ − 8
section{* Interface for nominal_datatype *}
+ − 9
+ − 10
+ − 11
ML {*
+ − 12
(* nominal datatype parser *)
+ − 13
local
+ − 14
structure P = OuterParse;
+ − 15
structure S = Scan
+ − 16
+ − 17
fun triple1 ((x, y), z) = (x, y, z)
+ − 18
fun triple2 (x, (y, z)) = (x, y, z)
+ − 19
fun tuple ((x, y, z), u) = (x, y, z, u)
+ − 20
fun tswap (((x, y), z), u) = (x, y, u, z)
+ − 21
in
+ − 22
+ − 23
val _ = OuterKeyword.keyword "bind"
+ − 24
val _ = OuterKeyword.keyword "bind_set"
+ − 25
val _ = OuterKeyword.keyword "bind_res"
+ − 26
1943
+ − 27
val anno_typ = S.option (P.name --| P.$$$ "::") -- P.typ
1941
+ − 28
+ − 29
val bind_mode = P.$$$ "bind" || P.$$$ "bind_set" || P.$$$ "bind_res"
+ − 30
+ − 31
val bind_clauses =
+ − 32
P.enum "," (bind_mode -- S.repeat1 P.term -- (P.$$$ "in" |-- S.repeat1 P.name) >> triple1)
+ − 33
+ − 34
val cnstr_parser =
1943
+ − 35
P.binding -- S.repeat anno_typ -- bind_clauses -- P.opt_mixfix >> tswap
1941
+ − 36
+ − 37
(* datatype parser *)
+ − 38
val dt_parser =
+ − 39
(P.type_args -- P.binding -- P.opt_mixfix >> triple1) --
1943
+ − 40
(P.$$$ "=" |-- P.enum1 "|" cnstr_parser) >> tuple
1941
+ − 41
+ − 42
(* binding function parser *)
+ − 43
val bnfun_parser =
1944
+ − 44
S.optional (P.$$$ "binder" |-- P.fixes -- SpecParse.where_alt_specs) ([], [])
1941
+ − 45
+ − 46
(* main parser *)
+ − 47
val main_parser =
1944
+ − 48
P.and_list1 dt_parser -- bnfun_parser >> triple2
1941
+ − 49
+ − 50
end
+ − 51
*}
+ − 52
+ − 53
ML {*
+ − 54
fun get_cnstrs dts =
+ − 55
map (fn (_, _, _, constrs) => constrs) dts
+ − 56
+ − 57
fun get_typed_cnstrs dts =
+ − 58
flat (map (fn (_, bn, _, constrs) =>
+ − 59
(map (fn (bn', _, _) => (Binding.name_of bn, Binding.name_of bn')) constrs)) dts)
+ − 60
+ − 61
fun get_cnstr_strs dts =
+ − 62
map (fn (bn, _, _) => Binding.name_of bn) (flat (get_cnstrs dts))
+ − 63
+ − 64
fun get_bn_fun_strs bn_funs =
+ − 65
map (fn (bn_fun, _, _) => Binding.name_of bn_fun) bn_funs
+ − 66
*}
+ − 67
2106
+ − 68
1941
+ − 69
ML {*
+ − 70
fun add_primrec_wrapper funs eqs lthy =
+ − 71
if null funs then (([], []), lthy)
+ − 72
else
+ − 73
let
+ − 74
val eqs' = map (fn (_, eq) => (Attrib.empty_binding, eq)) eqs
+ − 75
val funs' = map (fn (bn, ty, mx) => (bn, SOME ty, mx)) funs
2106
+ − 76
val ((funs'', eqs''), lthy') = Primrec.add_primrec funs' eqs' lthy
+ − 77
val phi = ProofContext.export_morphism lthy' lthy
1941
+ − 78
in
2106
+ − 79
((map (Morphism.term phi) funs'', map (Morphism.thm phi) eqs''), lthy')
1941
+ − 80
end
+ − 81
*}
+ − 82
+ − 83
ML {*
+ − 84
fun add_datatype_wrapper dt_names dts =
+ − 85
let
+ − 86
val conf = Datatype.default_config
+ − 87
in
+ − 88
Local_Theory.theory_result (Datatype.add_datatype conf dt_names dts)
+ − 89
end
+ − 90
*}
+ − 91
1944
+ − 92
+ − 93
text {* Infrastructure for adding "_raw" to types and terms *}
+ − 94
1941
+ − 95
ML {*
+ − 96
fun add_raw s = s ^ "_raw"
+ − 97
fun add_raws ss = map add_raw ss
+ − 98
fun raw_bind bn = Binding.suffix_name "_raw" bn
+ − 99
+ − 100
fun replace_str ss s =
+ − 101
case (AList.lookup (op=) ss s) of
+ − 102
SOME s' => s'
+ − 103
| NONE => s
+ − 104
+ − 105
fun replace_typ ty_ss (Type (a, Ts)) = Type (replace_str ty_ss a, map (replace_typ ty_ss) Ts)
+ − 106
| replace_typ ty_ss T = T
+ − 107
+ − 108
fun raw_dts ty_ss dts =
+ − 109
let
+ − 110
fun raw_dts_aux1 (bind, tys, mx) =
+ − 111
(raw_bind bind, map (replace_typ ty_ss) tys, mx)
+ − 112
+ − 113
fun raw_dts_aux2 (ty_args, bind, mx, constrs) =
+ − 114
(ty_args, raw_bind bind, mx, map raw_dts_aux1 constrs)
+ − 115
in
+ − 116
map raw_dts_aux2 dts
+ − 117
end
+ − 118
+ − 119
fun replace_aterm trm_ss (Const (a, T)) = Const (replace_str trm_ss a, T)
+ − 120
| replace_aterm trm_ss (Free (a, T)) = Free (replace_str trm_ss a, T)
+ − 121
| replace_aterm trm_ss trm = trm
+ − 122
+ − 123
fun replace_term trm_ss ty_ss trm =
+ − 124
trm |> Term.map_aterms (replace_aterm trm_ss) |> map_types (replace_typ ty_ss)
+ − 125
*}
+ − 126
+ − 127
ML {*
+ − 128
fun rawify_dts dt_names dts dts_env =
+ − 129
let
+ − 130
val raw_dts = raw_dts dts_env dts
+ − 131
val raw_dt_names = add_raws dt_names
+ − 132
in
+ − 133
(raw_dt_names, raw_dts)
+ − 134
end
+ − 135
*}
+ − 136
+ − 137
ML {*
+ − 138
fun rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs =
+ − 139
let
+ − 140
val bn_funs' = map (fn (bn, ty, mx) =>
+ − 141
(raw_bind bn, replace_typ dts_env ty, mx)) bn_funs
+ − 142
+ − 143
val bn_eqs' = map (fn (attr, trm) =>
+ − 144
(attr, replace_term (cnstrs_env @ bn_fun_env) dts_env trm)) bn_eqs
+ − 145
in
+ − 146
(bn_funs', bn_eqs')
+ − 147
end
+ − 148
*}
+ − 149
+ − 150
ML {*
+ − 151
fun rawify_bclauses dts_env cnstrs_env bn_fun_env bclauses =
+ − 152
let
+ − 153
fun rawify_bnds bnds =
+ − 154
map (apfst (Option.map (replace_term (cnstrs_env @ bn_fun_env) dts_env))) bnds
+ − 155
+ − 156
fun rawify_bclause (BEmy n) = BEmy n
+ − 157
| rawify_bclause (BLst (bnds, bdys)) = BLst (rawify_bnds bnds, bdys)
+ − 158
| rawify_bclause (BSet (bnds, bdys)) = BSet (rawify_bnds bnds, bdys)
+ − 159
| rawify_bclause (BRes (bnds, bdys)) = BRes (rawify_bnds bnds, bdys)
+ − 160
in
+ − 161
map (map (map rawify_bclause)) bclauses
+ − 162
end
+ − 163
*}
+ − 164
2027
+ − 165
(* strip_bn_fun takes a bn function defined by the user as a union or
+ − 166
append of elements and returns those elements together with bn functions
+ − 167
applied *)
1941
+ − 168
ML {*
+ − 169
fun strip_bn_fun t =
+ − 170
case t of
+ − 171
Const (@{const_name sup}, _) $ l $ r => strip_bn_fun l @ strip_bn_fun r
+ − 172
| Const (@{const_name append}, _) $ l $ r => strip_bn_fun l @ strip_bn_fun r
+ − 173
| Const (@{const_name insert}, _) $ (Const (@{const_name atom}, _) $ Bound i) $ y =>
+ − 174
(i, NONE) :: strip_bn_fun y
+ − 175
| Const (@{const_name Cons}, _) $ (Const (@{const_name atom}, _) $ Bound i) $ y =>
+ − 176
(i, NONE) :: strip_bn_fun y
+ − 177
| Const (@{const_name bot}, _) => []
+ − 178
| Const (@{const_name Nil}, _) => []
+ − 179
| (f as Free _) $ Bound i => [(i, SOME f)]
+ − 180
| _ => error ("Unsupported binding function: " ^ (PolyML.makestring t))
+ − 181
*}
+ − 182
+ − 183
ML {*
+ − 184
fun find [] _ = error ("cannot find element")
+ − 185
| find ((x, z)::xs) y = if (Long_Name.base_name x) = y then z else find xs y
+ − 186
*}
+ − 187
2118
+ − 188
ML {* print_depth 50 *}
+ − 189
1941
+ − 190
ML {*
2122
+ − 191
fun prep_bn lthy dt_names dts eqs =
1941
+ − 192
let
+ − 193
fun aux eq =
+ − 194
let
+ − 195
val (lhs, rhs) = eq
+ − 196
|> strip_qnt_body "all"
+ − 197
|> HOLogic.dest_Trueprop
+ − 198
|> HOLogic.dest_eq
+ − 199
val (bn_fun, [cnstr]) = strip_comb lhs
+ − 200
val (_, ty) = dest_Free bn_fun
+ − 201
val (ty_name, _) = dest_Type (domain_type ty)
+ − 202
val dt_index = find_index (fn x => x = ty_name) dt_names
+ − 203
val (cnstr_head, cnstr_args) = strip_comb cnstr
+ − 204
val rhs_elements = strip_bn_fun rhs
+ − 205
val included = map (apfst (fn i => length (cnstr_args) - i - 1)) rhs_elements
+ − 206
in
+ − 207
(dt_index, (bn_fun, (cnstr_head, included)))
2122
+ − 208
end
+ − 209
fun aux2 eq =
+ − 210
let
+ − 211
val (lhs, rhs) = eq
+ − 212
|> strip_qnt_body "all"
+ − 213
|> HOLogic.dest_Trueprop
+ − 214
|> HOLogic.dest_eq
+ − 215
val (bn_fun, [cnstr]) = strip_comb lhs
+ − 216
val (_, ty) = dest_Free bn_fun
+ − 217
val (ty_name, _) = dest_Type (domain_type ty)
+ − 218
val dt_index = find_index (fn x => x = ty_name) dt_names
+ − 219
val (cnstr_head, cnstr_args) = strip_comb cnstr
+ − 220
val rhs_elements = strip_bn_fun rhs
+ − 221
val included = map (apfst (fn i => length (cnstr_args) - i - 1)) rhs_elements
+ − 222
in
+ − 223
(bn_fun, dt_index, (cnstr_head, included))
1941
+ − 224
end
+ − 225
fun order dts i ts =
+ − 226
let
+ − 227
val dt = nth dts i
+ − 228
val cts = map (fn (x, _, _) => Binding.name_of x) ((fn (_, _, _, x) => x) dt)
+ − 229
val ts' = map (fn (x, y) => (fst (dest_Const x), y)) ts
+ − 230
in
+ − 231
map (find ts') cts
+ − 232
end
+ − 233
+ − 234
val unordered = AList.group (op=) (map aux eqs)
+ − 235
val unordered' = map (fn (x, y) => (x, AList.group (op=) y)) unordered
+ − 236
val ordered = map (fn (x, y) => (x, map (fn (v, z) => (v, order dts x z)) y)) unordered'
2118
+ − 237
val ordered' = flat (map (fn (ith, l) => map (fn (bn, data) => (bn, ith, data)) l) ordered)
2122
+ − 238
+ − 239
val _ = tracing ("eqs\n" ^ cat_lines (map (Syntax.string_of_term lthy) eqs))
+ − 240
val _ = tracing ("map eqs\n" ^ @{make_string} (map aux2 eqs))
+ − 241
val _ = tracing ("ordered'\n" ^ @{make_string} ordered')
1941
+ − 242
in
2122
+ − 243
ordered' (*map aux2 eqs*)
1941
+ − 244
end
+ − 245
*}
+ − 246
+ − 247
ML {*
+ − 248
fun raw_nominal_decls dts bn_funs bn_eqs binds lthy =
+ − 249
let
+ − 250
val thy = ProofContext.theory_of lthy
+ − 251
val thy_name = Context.theory_name thy
+ − 252
+ − 253
val dt_names = map (fn (_, s, _, _) => Binding.name_of s) dts
+ − 254
val dt_full_names = map (Long_Name.qualify thy_name) dt_names
+ − 255
val dt_full_names' = add_raws dt_full_names
+ − 256
val dts_env = dt_full_names ~~ dt_full_names'
+ − 257
+ − 258
val cnstrs = get_cnstr_strs dts
+ − 259
val cnstrs_ty = get_typed_cnstrs dts
+ − 260
val cnstrs_full_names = map (Long_Name.qualify thy_name) cnstrs
+ − 261
val cnstrs_full_names' = map (fn (x, y) => Long_Name.qualify thy_name
+ − 262
(Long_Name.qualify (add_raw x) (add_raw y))) cnstrs_ty
+ − 263
val cnstrs_env = cnstrs_full_names ~~ cnstrs_full_names'
+ − 264
+ − 265
val bn_fun_strs = get_bn_fun_strs bn_funs
+ − 266
val bn_fun_strs' = add_raws bn_fun_strs
+ − 267
val bn_fun_env = bn_fun_strs ~~ bn_fun_strs'
+ − 268
val bn_fun_full_env = map (pairself (Long_Name.qualify thy_name))
+ − 269
(bn_fun_strs ~~ bn_fun_strs')
+ − 270
+ − 271
val (raw_dt_names, raw_dts) = rawify_dts dt_names dts dts_env
+ − 272
+ − 273
val (raw_bn_funs, raw_bn_eqs) = rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs
+ − 274
+ − 275
val raw_bclauses = rawify_bclauses dts_env cnstrs_env bn_fun_full_env binds
+ − 276
2122
+ − 277
val raw_bns = prep_bn lthy dt_full_names' raw_dts (map snd raw_bn_eqs)
1941
+ − 278
in
+ − 279
lthy
+ − 280
|> add_datatype_wrapper raw_dt_names raw_dts
+ − 281
||>> add_primrec_wrapper raw_bn_funs raw_bn_eqs
+ − 282
||>> pair raw_bclauses
+ − 283
||>> pair raw_bns
+ − 284
end
+ − 285
*}
+ − 286
2017
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 287
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
+ − 288
sorry
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 289
ML {*
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 290
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
+ − 291
let
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 292
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
+ − 293
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
+ − 294
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
+ − 295
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
+ − 296
in
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 297
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
+ − 298
end
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 299
*}
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 300
2023
+ − 301
ML {* val cheat_equivp = Unsynchronized.ref false *}
+ − 302
ML {* val cheat_fv_rsp = Unsynchronized.ref false *}
+ − 303
ML {* val cheat_alpha_bn_rsp = Unsynchronized.ref false *}
+ − 304
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
+ − 305
2025
+ − 306
ML {*
+ − 307
fun remove_loop t =
+ − 308
let val _ = HOLogic.dest_eq (HOLogic.dest_Trueprop (prop_of t)) in t end
+ − 309
handle TERM _ => @{thm eqTrueI} OF [t]
+ − 310
*}
+ − 311
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
+ − 312
text {*
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
+ − 313
nominal_datatype2 does the following things in order:
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
+ − 314
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
+ − 315
Parser.thy/raw_nominal_decls
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
+ − 316
1) define the raw datatype
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
+ − 317
2) define the raw binding functions
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
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
+ − 319
Perm.thy/define_raw_perms
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
+ − 320
3) define permutations of the raw datatype and show that the raw type is
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
+ − 321
in the pt typeclass
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
+ − 322
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
+ − 323
Lift.thy/define_fv_alpha_export, Fv.thy/define_fv & define_alpha
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
+ − 324
4) define fv and fv_bn
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
+ − 325
5) define alpha and alpha_bn
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
+ − 326
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
+ − 327
Perm.thy/distinct_rel
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
+ − 328
6) prove alpha_distincts (C1 x \<notsimeq> C2 y ...) (Proof by cases; simp)
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
+ − 329
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
+ − 330
Tacs.thy/build_rel_inj
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
+ − 331
6) prove alpha_eq_iff (C1 x = C2 y \<leftrightarrow> P x y ...)
1bddffddc03f
attempted to remove dependency on (old) Fv and (old) Parser; lifting still uses Fv.thy; the examples do not work at the moment (with equivp proofs failing)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 332
(left-to-right by intro rule, right-to-left by cases; simp)
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
+ − 333
Equivp.thy/prove_eqvt
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
+ − 334
7) prove bn_eqvt (common induction on the raw datatype)
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
+ − 335
8) prove fv_eqvt (common induction on the raw datatype with help of above)
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
+ − 336
Rsp.thy/build_alpha_eqvts
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
+ − 337
9) prove alpha_eqvt and alpha_bn_eqvt
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
+ − 338
(common alpha-induction, unfolding alpha_gen, permute of #* and =)
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
+ − 339
Equivp.thy/build_alpha_refl & Equivp.thy/build_equivps
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
+ − 340
10) prove that alpha and alpha_bn are equivalence relations
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
+ − 341
(common induction and application of 'compose' lemmas)
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
+ − 342
Lift.thy/define_quotient_types
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
+ − 343
11) define quotient types
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
+ − 344
Rsp.thy/build_fvbv_rsps
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
+ − 345
12) prove bn respects (common induction and simp with alpha_gen)
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
+ − 346
Rsp.thy/prove_const_rsp
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
+ − 347
13) prove fv respects (common induction and simp with alpha_gen)
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
+ − 348
14) prove permute respects (unfolds to alpha_eqvt)
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
+ − 349
Rsp.thy/prove_alpha_bn_rsp
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
+ − 350
15) prove alpha_bn respects
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
+ − 351
(alpha_induct then cases then sym and trans of the relations)
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
Rsp.thy/prove_alpha_alphabn
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
+ − 353
16) show that alpha implies alpha_bn (by unduction, needed in following step)
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
+ − 354
Rsp.thy/prove_const_rsp
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
+ − 355
17) prove respects for all datatype constructors
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
+ − 356
(unfold eq_iff and alpha_gen; introduce zero permutations; simp)
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
+ − 357
Perm.thy/quotient_lift_consts_export
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
+ − 358
18) define lifted constructors, fv, bn, alpha_bn, permutations
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
+ − 359
Perm.thy/define_lifted_perms
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
+ − 360
19) lift permutation zero and add properties to show that quotient type is in the pt typeclass
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
+ − 361
Lift.thy/lift_thm
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
+ − 362
20) lift permutation simplifications
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
+ − 363
21) lift induction
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
+ − 364
22) lift fv
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
+ − 365
23) lift bn
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
+ − 366
24) lift eq_iff
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
+ − 367
25) lift alpha_distincts
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
+ − 368
26) lift fv and bn eqvts
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
+ − 369
Equivp.thy/prove_supports
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
+ − 370
27) prove that union of arguments supports constructors
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
+ − 371
Equivp.thy/prove_fs
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
+ − 372
28) show that the lifted type is in fs typeclass (* by q_induct, supports *)
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
+ − 373
Equivp.thy/supp_eq
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
+ − 374
29) prove supp = fv
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
+ − 375
*}
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
+ − 376
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
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
+ − 378
(* 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
+ − 379
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
+ − 380
2048
+ − 381
val STEPS = 10
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
+ − 382
*}
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
+ − 383
1941
+ − 384
ML {*
+ − 385
fun nominal_datatype2 dts bn_funs bn_eqs bclauses lthy =
+ − 386
let
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
+ − 387
(* definition of the raw datatype and raw bn-functions *)
2106
+ − 388
val ((((raw_dt_names, (raw_bn_funs, raw_bn_eqs)), raw_bclauses), raw_bns), 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
+ − 389
if STEPS > 1 then raw_nominal_decls dts bn_funs bn_eqs bclauses lthy
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
+ − 390
else raise TEST lthy
1941
+ − 391
1945
+ − 392
val dtinfo = Datatype.the_info (ProofContext.theory_of lthy1) (hd raw_dt_names);
+ − 393
val {descr, sorts, ...} = dtinfo;
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 394
val raw_tys = map (fn (i, _) => nth_dtyp descr sorts i) descr;
2016
+ − 395
val all_typs = map (fn i => Datatype_Aux.typ_of_dtyp descr sorts (Datatype_Aux.DtRec i)) (map fst descr)
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
+ − 396
val all_full_tnames = map (fn (_, (n, _, _)) => n) descr;
1945
+ − 397
1999
+ − 398
val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy1)) 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
+ − 399
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
+ − 400
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
+ − 401
val distinct_thms = flat (map #distinct 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
+ − 402
val rel_dtinfos = List.take (dtinfos, (length dts));
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
+ − 403
val rel_distinct = map #distinct rel_dtinfos; (* thm list list *)
2047
+ − 404
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
+ − 405
val exhaust_thms = map #exhaust dtinfos;
1999
+ − 406
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
+ − 407
(* definitions of raw permutations *)
1945
+ − 408
val ((raw_perm_def, raw_perm_simps, perms), lthy2) =
2047
+ − 409
if STEPS > 2 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
+ − 410
else raise TEST lthy1
1960
+ − 411
2106
+ − 412
(* definition of raw fv_functions *)
1960
+ − 413
val morphism_2_0 = ProofContext.export_morphism lthy2 lthy
2118
+ − 414
fun export_fun f (t, n , l) = (f t, n, map (map (apsnd (Option.map f))) l);
+ − 415
val bn_funs_decls = map (export_fun (Morphism.term morphism_2_0)) raw_bns;
+ − 416
2105
+ − 417
val (_, lthy2a) = Local_Theory.note ((Binding.empty,
+ − 418
[Attrib.internal (fn _ => Nominal_ThmDecls.eqvt_add)]), raw_perm_def) lthy2;
+ − 419
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
+ − 420
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
+ − 421
1960
+ − 422
val lthy3 = Theory_Target.init NONE thy;
2000
+ − 423
val raw_bn_funs = map (fn (f, _, _) => f) bn_funs_decls;
1960
+ − 424
2106
+ − 425
val _ = tracing ("raw_bns\n" ^ @{make_string} raw_bns)
+ − 426
val _ = tracing ("bn_funs\n" ^ @{make_string} bn_funs_decls)
2118
+ − 427
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
+ − 428
val ((fv, fvbn), fv_def, lthy3a) =
2047
+ − 429
if STEPS > 3 then define_raw_fv descr sorts bn_funs_decls raw_bclauses 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
+ − 430
else raise TEST lthy3
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 431
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
+ − 432
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 433
(* definition of raw alphas *)
1999
+ − 434
val (((alpha_ts, alpha_intros), (alpha_cases, alpha_induct)), lthy4) =
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
+ − 435
if STEPS > 4 then define_raw_alpha dtinfo bn_funs_decls raw_bclauses fv 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
+ − 436
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
+ − 437
1999
+ − 438
val (alpha_ts_nobn, alpha_ts_bn) = chop (length fv) alpha_ts
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 439
2000
+ − 440
val dts_names = map (fn (i, (s, _, _)) => (s, i)) (#descr dtinfo);
+ − 441
val bn_tys = map (domain_type o fastype_of) raw_bn_funs;
+ − 442
val bn_nos = map (dtyp_no_of_typ dts_names) bn_tys;
+ − 443
val bns = raw_bn_funs ~~ bn_nos;
+ − 444
val rel_dists = flat (map (distinct_rel lthy4 alpha_cases)
+ − 445
(rel_distinct ~~ alpha_ts_nobn));
+ − 446
val rel_dists_bn = flat (map (distinct_rel lthy4 alpha_cases)
+ − 447
((map (fn i => nth rel_distinct i) bn_nos) ~~ alpha_ts_bn))
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 448
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 449
(* definition of raw_alpha_eq_iff lemmas *)
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
+ − 450
val alpha_eq_iff = build_rel_inj alpha_intros (inject_thms @ distinct_thms) alpha_cases lthy4
2025
+ − 451
val alpha_eq_iff_simp = map remove_loop alpha_eq_iff;
+ − 452
val _ = map tracing (map PolyML.makestring alpha_eq_iff_simp);
2022
+ − 453
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 454
(* proving equivariance lemmas *)
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
+ − 455
val _ = warning "Proving equivariance";
2047
+ − 456
val (bv_eqvt, lthy5) = prove_eqvt raw_tys induct_thm (raw_bn_eqs @ raw_perm_def) (map fst bns) lthy4
+ − 457
val (fv_eqvt, lthy6) = prove_eqvt raw_tys induct_thm (fv_def @ raw_perm_def) (fv @ fvbn) lthy5
2114
+ − 458
val (alpha_eqvt, lthy6a) = Nominal_Eqvt.equivariance alpha_ts alpha_induct alpha_intros lthy6;
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 459
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
+ − 460
(* 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
+ − 461
val _ = warning "Proving equivalence";
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 462
val fv_alpha_all = combine_fv_alpha_bns (fv, fvbn) (alpha_ts_nobn, alpha_ts_bn) bn_nos;
2114
+ − 463
val reflps = build_alpha_refl fv_alpha_all alpha_ts induct_thm alpha_eq_iff_simp lthy6a;
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
+ − 464
val alpha_equivp =
2114
+ − 465
if !cheat_equivp then map (equivp_hack lthy6a) alpha_ts
2017
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 466
else build_equivps alpha_ts reflps alpha_induct
2114
+ − 467
inject_thms alpha_eq_iff_simp distinct_thms alpha_cases alpha_eqvt lthy6a;
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 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
+ − 469
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
+ − 470
val qty_full_names = map (Long_Name.qualify thy_name) qty_names
2114
+ − 471
val (qtys, lthy7) = define_quotient_types qty_binds all_typs alpha_ts_nobn alpha_equivp lthy6a;
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
+ − 472
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
+ − 473
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
+ − 474
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
+ − 475
map (fn (cname, dts) =>
2016
+ − 476
Const (cname, map (Datatype_Aux.typ_of_dtyp descr sorts) dts --->
+ − 477
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
+ − 478
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
+ − 479
val _ = warning "Proving respects";
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 bns_rsp_pre' = build_fvbv_rsps alpha_ts alpha_induct raw_bn_eqs (map fst 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
+ − 481
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
+ − 482
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
+ − 483
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
+ − 484
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
+ − 485
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 486
fun fv_rsp_tac _ = if !cheat_fv_rsp then Skip_Proof.cheat_tac thy
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 487
else fvbv_rsp_tac alpha_induct fv_def lthy8 1;
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
val fv_rsps = prove_fv_rsp fv_alpha_all alpha_ts fv_rsp_tac lthy9;
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
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
+ − 490
(fn fv => fn ctxt => prove_const_rsp qtys Binding.empty [fv]
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
(fn _ => asm_simp_tac (HOL_ss addsimps fv_rsps) 1) ctxt) (fv @ fvbn) lthy9;
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 fv_rsp = flat (map snd fv_rsp_pre);
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 493
val (perms_rsp, lthy11) = prove_const_rsp qtys Binding.empty perms
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 494
(fn _ => asm_simp_tac (HOL_ss addsimps alpha_eqvt) 1) lthy10;
2023
+ − 495
fun alpha_bn_rsp_tac _ = if !cheat_alpha_bn_rsp then Skip_Proof.cheat_tac thy
+ − 496
else
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
+ − 497
let val alpha_bn_rsp_pre = prove_alpha_bn_rsp alpha_ts alpha_induct (alpha_eq_iff_simp @ rel_dists @ rel_dists_bn) alpha_equivp exhaust_thms alpha_ts_bn 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
+ − 498
val (alpha_bn_rsps, lthy11a) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst]
2023
+ − 499
alpha_bn_rsp_tac) alpha_ts_bn 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
+ − 500
fun const_rsp_tac _ =
2022
+ − 501
let val alpha_alphabn = prove_alpha_alphabn alpha_ts alpha_induct alpha_eq_iff_simp alpha_ts_bn lthy11a
+ − 502
in constr_rsp_tac alpha_eq_iff_simp (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
+ − 503
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
+ − 504
const_rsp_tac) raw_consts lthy11a
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 505
val qfv_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) (fv @ fvbn)
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 506
val (qfv_ts, qfv_defs, lthy12a) = quotient_lift_consts_export qtys (qfv_names ~~ (fv @ fvbn)) lthy12;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 507
val (qfv_ts_nobn, qfv_ts_bn) = chop (length perms) qfv_ts;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 508
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
+ − 509
val (qbn_ts, qbn_defs, lthy12b) = quotient_lift_consts_export qtys (qbn_names ~~ raw_bn_funs) lthy12a;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 510
val qalpha_bn_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) alpha_ts_bn
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 511
val (qalpha_ts_bn, qalphabn_defs, lthy12c) =
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 512
quotient_lift_consts_export qtys (qalpha_bn_names ~~ alpha_ts_bn) 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
+ − 513
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
+ − 514
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
+ − 515
val perm_names = map (fn x => "permute_" ^ x) 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
+ − 516
val thy' = define_lifted_perms qtys qty_full_names (perm_names ~~ perms) raw_perm_simps 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
+ − 517
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
+ − 518
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
+ − 519
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
+ − 520
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
+ − 521
val constr_names = map (Long_Name.base_name o fst o dest_Const) consts;
2047
+ − 522
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
+ − 523
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
+ − 524
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
+ − 525
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
+ − 526
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
+ − 527
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
+ − 528
[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
+ − 529
[Rule_Cases.name constr_names q_induct]) lthy13;
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
+ − 530
val q_inducts = Project_Rule.projects lthy13 (1 upto (length fv)) q_induct
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 531
val (_, lthy14a) = Local_Theory.note ((suffix_bind "inducts", []), q_inducts) lthy14;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 532
val q_perm = map (lift_thm qtys lthy14) raw_perm_def;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 533
val lthy15 = note_simp_suffix "perm" q_perm lthy14a;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 534
val q_fv = map (lift_thm qtys lthy15) fv_def;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 535
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
+ − 536
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
+ − 537
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
+ − 538
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
+ − 539
(*val _ = map tracing (map PolyML.makestring alpha_eq_iff);*)
2089
+ − 540
val eq_iff_unfolded0 = map (Local_Defs.unfold lthy17 @{thms alphas}) alpha_eq_iff_simp
+ − 541
val eq_iff_unfolded1 = map (Local_Defs.unfold lthy17 @{thms Pair_eqvt}) eq_iff_unfolded0
+ − 542
val q_eq_iff_pre0 = map (lift_thm qtys lthy17) eq_iff_unfolded1;
+ − 543
val q_eq_iff_pre1 = map (Local_Defs.fold lthy17 @{thms Pair_eqvt}) q_eq_iff_pre0
+ − 544
val q_eq_iff_pre2 = map (Local_Defs.fold lthy17 @{thms alphas}) q_eq_iff_pre1
+ − 545
val q_eq_iff = map (Local_Defs.unfold lthy17 (Quotient_Info.id_simps_get lthy17)) q_eq_iff_pre2
2025
+ − 546
val (_, lthy18) = Local_Theory.note ((suffix_bind "eq_iff", []), q_eq_iff) lthy17;
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
+ − 547
val q_dis = map (lift_thm qtys lthy18) rel_dists;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 548
val lthy19 = note_simp_suffix "distinct" q_dis lthy18;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 549
val q_eqvt = map (lift_thm qtys lthy19) (bv_eqvt @ fv_eqvt);
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 550
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
+ − 551
[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
+ − 552
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
+ − 553
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
+ − 554
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
+ − 555
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
+ − 556
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
+ − 557
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
+ − 558
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
+ − 559
val lthy22 = Class.prove_instantiation_instance tac lthy21
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 560
val fv_alpha_all = combine_fv_alpha_bns (qfv_ts_nobn, qfv_ts_bn) (alpha_ts_nobn, qalpha_ts_bn) bn_nos;
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 561
val (names, supp_eq_t) = supp_eq fv_alpha_all;
2020
+ − 562
val _ = warning "Support Equations";
2023
+ − 563
fun supp_eq_tac' _ = if !cheat_supp_eq then Skip_Proof.cheat_tac thy else
2025
+ − 564
supp_eq_tac q_induct q_fv q_perm q_eq_iff lthy22 1;
2023
+ − 565
val q_supp = HOLogic.conj_elims (Goal.prove lthy22 names [] supp_eq_t supp_eq_tac') handle e =>
+ − 566
let val _ = warning ("Support eqs failed") in [] end;
2020
+ − 567
val lthy23 = note_suffix "supp" q_supp lthy22;
1941
+ − 568
in
2020
+ − 569
(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
+ − 570
end handle TEST ctxt => (0, ctxt)
1941
+ − 571
*}
+ − 572
+ − 573
section {* Preparing and parsing of the specification *}
+ − 574
+ − 575
ML {*
+ − 576
(* parsing the datatypes and declaring *)
+ − 577
(* constructors in the local theory *)
+ − 578
fun prepare_dts dt_strs lthy =
+ − 579
let
+ − 580
val thy = ProofContext.theory_of lthy
+ − 581
+ − 582
fun mk_type full_tname tvrs =
+ − 583
Type (full_tname, map (fn a => TVar ((a, 0), [])) tvrs)
+ − 584
+ − 585
fun prep_cnstr full_tname tvs (cname, anno_tys, mx, _) =
+ − 586
let
+ − 587
val tys = map (Syntax.read_typ lthy o snd) anno_tys
+ − 588
val ty = mk_type full_tname tvs
+ − 589
in
+ − 590
((cname, tys ---> ty, mx), (cname, tys, mx))
+ − 591
end
+ − 592
+ − 593
fun prep_dt (tvs, tname, mx, cnstrs) =
+ − 594
let
+ − 595
val full_tname = Sign.full_name thy tname
+ − 596
val (cnstrs', cnstrs'') =
+ − 597
split_list (map (prep_cnstr full_tname tvs) cnstrs)
+ − 598
in
+ − 599
(cnstrs', (tvs, tname, mx, cnstrs''))
+ − 600
end
+ − 601
+ − 602
val (cnstrs, dts) = split_list (map prep_dt dt_strs)
+ − 603
in
+ − 604
lthy
+ − 605
|> Local_Theory.theory (Sign.add_consts_i (flat cnstrs))
+ − 606
|> pair dts
+ − 607
end
+ − 608
*}
+ − 609
+ − 610
ML {*
+ − 611
(* parsing the binding function specification and *)
+ − 612
(* declaring the functions in the local theory *)
+ − 613
fun prepare_bn_funs bn_fun_strs bn_eq_strs lthy =
+ − 614
let
+ − 615
val ((bn_funs, bn_eqs), _) =
+ − 616
Specification.read_spec bn_fun_strs bn_eq_strs lthy
+ − 617
+ − 618
fun prep_bn_fun ((bn, T), mx) = (bn, T, mx)
+ − 619
+ − 620
val bn_funs' = map prep_bn_fun bn_funs
+ − 621
in
+ − 622
lthy
+ − 623
|> Local_Theory.theory (Sign.add_consts_i bn_funs')
+ − 624
|> pair (bn_funs', bn_eqs)
+ − 625
end
+ − 626
*}
+ − 627
+ − 628
text {* associates every SOME with the index in the list; drops NONEs *}
+ − 629
ML {*
+ − 630
fun indexify xs =
+ − 631
let
+ − 632
fun mapp _ [] = []
+ − 633
| mapp i (NONE :: xs) = mapp (i + 1) xs
+ − 634
| mapp i (SOME x :: xs) = (x, i) :: mapp (i + 1) xs
+ − 635
in
+ − 636
mapp 0 xs
+ − 637
end
+ − 638
+ − 639
fun index_lookup xs x =
+ − 640
case AList.lookup (op=) xs x of
+ − 641
SOME x => x
+ − 642
| NONE => error ("Cannot find " ^ x ^ " as argument annotation.");
+ − 643
*}
+ − 644
+ − 645
ML {*
+ − 646
fun prepare_bclauses dt_strs lthy =
+ − 647
let
+ − 648
val annos_bclauses =
+ − 649
get_cnstrs dt_strs
+ − 650
|> map (map (fn (_, antys, _, bns) => (map fst antys, bns)))
+ − 651
+ − 652
fun prep_binder env bn_str =
+ − 653
case (Syntax.read_term lthy bn_str) of
+ − 654
Free (x, _) => (NONE, index_lookup env x)
+ − 655
| Const (a, T) $ Free (x, _) => (SOME (Const (a, T)), index_lookup env x)
+ − 656
| _ => error ("The term " ^ bn_str ^ " is not allowed as binding function.")
+ − 657
+ − 658
fun prep_body env bn_str = index_lookup env bn_str
+ − 659
+ − 660
fun prep_mode "bind" = BLst
+ − 661
| prep_mode "bind_set" = BSet
+ − 662
| prep_mode "bind_res" = BRes
+ − 663
+ − 664
fun prep_bclause env (mode, binders, bodies) =
+ − 665
let
+ − 666
val binders' = map (prep_binder env) binders
+ − 667
val bodies' = map (prep_body env) bodies
+ − 668
in
+ − 669
prep_mode mode (binders', bodies')
+ − 670
end
+ − 671
+ − 672
fun prep_bclauses (annos, bclause_strs) =
+ − 673
let
+ − 674
val env = indexify annos (* for every label, associate the index *)
+ − 675
in
+ − 676
map (prep_bclause env) bclause_strs
+ − 677
end
+ − 678
in
+ − 679
map (map prep_bclauses) annos_bclauses
+ − 680
end
+ − 681
*}
+ − 682
1943
+ − 683
text {*
+ − 684
adds an empty binding clause for every argument
+ − 685
that is not already part of a binding clause
+ − 686
*}
+ − 687
1941
+ − 688
ML {*
+ − 689
fun included i bcs =
+ − 690
let
+ − 691
fun incl (BEmy j) = i = j
2076
+ − 692
| incl (BLst (bns, bds)) = (member (op =) (map snd bns) i) orelse (member (op =) bds i)
+ − 693
| incl (BSet (bns, bds)) = (member (op =) (map snd bns) i) orelse (member (op =) bds i)
+ − 694
| incl (BRes (bns, bds)) = (member (op =) (map snd bns) i) orelse (member (op =) bds i)
1941
+ − 695
in
+ − 696
exists incl bcs
+ − 697
end
+ − 698
*}
+ − 699
+ − 700
ML {*
+ − 701
fun complete dt_strs bclauses =
+ − 702
let
+ − 703
val args =
+ − 704
get_cnstrs dt_strs
+ − 705
|> map (map (fn (_, antys, _, _) => length antys))
+ − 706
+ − 707
fun complt n bcs =
+ − 708
let
+ − 709
fun add bcs i = (if included i bcs then [] else [BEmy i])
+ − 710
in
+ − 711
bcs @ (flat (map_range (add bcs) n))
+ − 712
end
+ − 713
in
+ − 714
map2 (map2 complt) args bclauses
+ − 715
end
+ − 716
*}
+ − 717
+ − 718
ML {*
+ − 719
fun nominal_datatype2_cmd (dt_strs, bn_fun_strs, bn_eq_strs) lthy =
+ − 720
let
+ − 721
fun prep_typ (tvs, tname, mx, _) = (tname, length tvs, mx)
+ − 722
val lthy0 =
+ − 723
Local_Theory.theory (Sign.add_types (map prep_typ dt_strs)) lthy
1944
+ − 724
val (dts, lthy1) = prepare_dts dt_strs lthy0
+ − 725
val ((bn_funs, bn_eqs), lthy2) = prepare_bn_funs bn_fun_strs bn_eq_strs lthy1
1941
+ − 726
val bclauses = prepare_bclauses dt_strs lthy2
+ − 727
val bclauses' = complete dt_strs bclauses
+ − 728
in
+ − 729
nominal_datatype2 dts bn_funs bn_eqs bclauses' lthy |> snd
+ − 730
end
+ − 731
+ − 732
+ − 733
(* Command Keyword *)
+ − 734
+ − 735
val _ = OuterSyntax.local_theory "nominal_datatype" "test" OuterKeyword.thy_decl
+ − 736
(main_parser >> nominal_datatype2_cmd)
+ − 737
*}
+ − 738
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
+ − 739
(*
2035
3622cae9b10e
to my best knowledge the number of datatypes is equal to the length of the dt_descr; so we can save one argument in define_raw_perm
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 740
atom_decl name
1941
+ − 741
1971
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 742
nominal_datatype lam =
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 743
Var name
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 744
| App lam lam
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 745
| Lam x::name t::lam bind_set x in t
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 746
| Let p::pt t::lam bind_set "bn p" in t
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 747
and pt =
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 748
P1 name
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 749
| P2 pt pt
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 750
binder
1981
+ − 751
bn::"pt \<Rightarrow> atom set"
1971
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 752
where
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 753
"bn (P1 x) = {atom x}"
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 754
| "bn (P2 p1 p2) = bn p1 \<union> bn p2"
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 755
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
+ − 756
find_theorems Var_raw
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
+ − 757
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
+ − 758
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
+ − 759
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
+ − 760
thm lam_pt.bn
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 761
thm lam_pt.fv[simplified lam_pt.supp(1-2)]
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 762
thm lam_pt.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
+ − 763
thm lam_pt.induct
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 764
thm lam_pt.perm
1941
+ − 765
+ − 766
nominal_datatype exp =
+ − 767
EVar name
+ − 768
| EUnit
1988
+ − 769
| EPair q1::exp q2::exp
1941
+ − 770
| ELetRec l::lrbs e::exp bind "b_lrbs l" in e l
+ − 771
+ − 772
and fnclause =
1988
+ − 773
K x::name p::pat f::exp bind_res "b_pat p" in f
1941
+ − 774
+ − 775
and fnclauses =
+ − 776
S fnclause
+ − 777
| ORs fnclause fnclauses
+ − 778
+ − 779
and lrb =
+ − 780
Clause fnclauses
+ − 781
+ − 782
and lrbs =
+ − 783
Single lrb
+ − 784
| More lrb lrbs
+ − 785
+ − 786
and pat =
+ − 787
PVar name
+ − 788
| PUnit
+ − 789
| PPair pat pat
+ − 790
+ − 791
binder
1988
+ − 792
b_lrbs :: "lrbs \<Rightarrow> atom list" and
1941
+ − 793
b_pat :: "pat \<Rightarrow> atom set" and
1988
+ − 794
b_fnclauses :: "fnclauses \<Rightarrow> atom list" and
+ − 795
b_fnclause :: "fnclause \<Rightarrow> atom list" and
+ − 796
b_lrb :: "lrb \<Rightarrow> atom list"
1941
+ − 797
+ − 798
where
+ − 799
"b_lrbs (Single l) = b_lrb l"
1988
+ − 800
| "b_lrbs (More l ls) = append (b_lrb l) (b_lrbs ls)"
1941
+ − 801
| "b_pat (PVar x) = {atom x}"
+ − 802
| "b_pat (PUnit) = {}"
+ − 803
| "b_pat (PPair p1 p2) = b_pat p1 \<union> b_pat p2"
+ − 804
| "b_fnclauses (S fc) = (b_fnclause fc)"
1988
+ − 805
| "b_fnclauses (ORs fc fcs) = append (b_fnclause fc) (b_fnclauses fcs)"
1941
+ − 806
| "b_lrb (Clause fcs) = (b_fnclauses fcs)"
1988
+ − 807
| "b_fnclause (K x pat exp) = [atom x]"
1941
+ − 808
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
+ − 809
thm exp_fnclause_fnclauses_lrb_lrbs_pat.bn
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 810
thm exp_fnclause_fnclauses_lrb_lrbs_pat.fv
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 811
thm exp_fnclause_fnclauses_lrb_lrbs_pat.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
+ − 812
thm exp_fnclause_fnclauses_lrb_lrbs_pat.induct
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 813
thm exp_fnclause_fnclauses_lrb_lrbs_pat.perm
1945
+ − 814
1988
+ − 815
nominal_datatype ty =
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
+ − 816
Vr "name"
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 817
| Fn "ty" "ty"
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 818
and tys =
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 819
Al xs::"name fset" t::"ty" bind_res xs in t
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 820
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 821
thm ty_tys.fv[simplified ty_tys.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
+ − 822
thm ty_tys.eq_iff
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 823
2017
6a4049e1d68d
Add explicit cheats in NewParser and comment out the examples for outside use.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 824
*)
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
+ − 825
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 826
(* some further tests *)
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 827
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
+ − 828
(*
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
+ − 829
nominal_datatype ty2 =
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
+ − 830
Vr2 "name"
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
+ − 831
| Fn2 "ty2" "ty2"
1988
+ − 832
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
+ − 833
nominal_datatype tys2 =
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
+ − 834
All2 xs::"name fset" ty::"ty2" bind_res xs in ty
1964
+ − 835
1971
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 836
nominal_datatype lam2 =
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 837
Var2 "name"
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 838
| App2 "lam2" "lam2 list"
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 839
| Lam2 x::"name" t::"lam2" bind x in t
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
+ − 840
*)
1964
+ − 841
1941
+ − 842
+ − 843
+ − 844
end
+ − 845
+ − 846
+ − 847