2297
+ − 1
(* Title: nominal_dt_alpha.ML
+ − 2
Author: Cezary Kaliszyk
+ − 3
Author: Christian Urban
+ − 4
2313
+ − 5
Definitions and proofs for the alpha-relations.
2297
+ − 6
*)
+ − 7
+ − 8
signature NOMINAL_DT_ALPHA =
+ − 9
sig
2611
3d101f2f817c
simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 10
val comb_binders: Proof.context -> bmode -> term list -> (term option * int) list -> term
3d101f2f817c
simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 11
2957
+ − 12
val define_raw_alpha: raw_dt_info -> bn_info list -> bclause list list list -> term list ->
+ − 13
Proof.context -> alpha_result * local_theory
2300
+ − 14
2480
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 15
val induct_prove: typ list -> (typ * (term -> term)) list -> thm ->
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 16
(Proof.context -> int -> tactic) -> Proof.context -> thm list
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 17
2389
+ − 18
val alpha_prove: term list -> (term * ((term * term) -> term)) list -> thm ->
+ − 19
(Proof.context -> int -> tactic) -> Proof.context -> thm list
+ − 20
2957
+ − 21
val raw_prove_alpha_distincts: Proof.context -> alpha_result -> raw_dt_info -> thm list
+ − 22
val raw_prove_alpha_eq_iff: Proof.context -> alpha_result -> raw_dt_info -> thm list
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 23
val raw_prove_refl: Proof.context -> alpha_result -> thm -> thm list
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 24
val raw_prove_sym: Proof.context -> alpha_result -> thm list -> thm list
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 25
val raw_prove_trans: Proof.context -> alpha_result -> thm list -> thm list -> thm list
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 26
val raw_prove_equivp: Proof.context -> alpha_result -> thm list -> thm list -> thm list ->
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 27
thm list * thm list
2928
+ − 28
val raw_prove_bn_imp: Proof.context -> alpha_result -> thm list
+ − 29
val raw_fv_bn_rsp_aux: Proof.context -> alpha_result -> term list -> term list -> term list ->
+ − 30
thm list -> thm list
+ − 31
val raw_size_rsp_aux: Proof.context -> alpha_result -> thm list -> thm list
+ − 32
val raw_constrs_rsp: Proof.context -> alpha_result -> term list -> thm list -> thm list
+ − 33
val raw_alpha_bn_rsp: alpha_result -> thm list -> thm list -> thm list
+ − 34
val raw_perm_bn_rsp: Proof.context -> alpha_result -> term list -> thm list -> thm list
2561
+ − 35
2397
+ − 36
val mk_funs_rsp: thm -> thm
+ − 37
val mk_alpha_permute_rsp: thm -> thm
2297
+ − 38
end
+ − 39
+ − 40
structure Nominal_Dt_Alpha: NOMINAL_DT_ALPHA =
+ − 41
struct
+ − 42
2765
7ac5e5c86c7d
introduced framework for finetuning eqvt-rules; this solves problem with permute_pure called in nominal_inductive
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 43
open Nominal_Permeq
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 44
open Nominal_Dt_Data
2765
7ac5e5c86c7d
introduced framework for finetuning eqvt-rules; this solves problem with permute_pure called in nominal_inductive
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 45
2320
+ − 46
fun lookup xs x = the (AList.lookup (op=) xs x)
+ − 47
fun group xs = AList.group (op=) xs
+ − 48
2926
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 49
2300
+ − 50
(** definition of the inductive rules for alpha and alpha_bn **)
+ − 51
2297
+ − 52
(* construct the compound terms for prod_fv and prod_alpha *)
+ − 53
fun mk_prod_fv (t1, t2) =
2476
+ − 54
let
+ − 55
val ty1 = fastype_of t1
+ − 56
val ty2 = fastype_of t2
+ − 57
val resT = HOLogic.mk_prodT (domain_type ty1, domain_type ty2) --> @{typ "atom set"}
+ − 58
in
+ − 59
Const (@{const_name "prod_fv"}, [ty1, ty2] ---> resT) $ t1 $ t2
+ − 60
end
2297
+ − 61
+ − 62
fun mk_prod_alpha (t1, t2) =
2476
+ − 63
let
+ − 64
val ty1 = fastype_of t1
+ − 65
val ty2 = fastype_of t2
+ − 66
val prodT = HOLogic.mk_prodT (domain_type ty1, domain_type ty2)
+ − 67
val resT = [prodT, prodT] ---> @{typ "bool"}
+ − 68
in
+ − 69
Const (@{const_name "prod_alpha"}, [ty1, ty2] ---> resT) $ t1 $ t2
+ − 70
end
2297
+ − 71
+ − 72
(* generates the compound binder terms *)
2611
3d101f2f817c
simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 73
fun comb_binders lthy bmode args binders =
2476
+ − 74
let
+ − 75
fun bind_set lthy args (NONE, i) = setify lthy (nth args i)
+ − 76
| bind_set _ args (SOME bn, i) = bn $ (nth args i)
+ − 77
fun bind_lst lthy args (NONE, i) = listify lthy (nth args i)
+ − 78
| bind_lst _ args (SOME bn, i) = bn $ (nth args i)
2297
+ − 79
2476
+ − 80
val (combine_fn, bind_fn) =
+ − 81
case bmode of
+ − 82
Lst => (mk_append, bind_lst)
+ − 83
| Set => (mk_union, bind_set)
+ − 84
| Res => (mk_union, bind_set)
+ − 85
in
+ − 86
binders
+ − 87
|> map (bind_fn lthy args)
+ − 88
|> foldl1 combine_fn
+ − 89
end
2297
+ − 90
+ − 91
(* produces the term for an alpha with abstraction *)
+ − 92
fun mk_alpha_term bmode fv alpha args args' binders binders' =
2476
+ − 93
let
+ − 94
val (alpha_name, binder_ty) =
+ − 95
case bmode of
+ − 96
Lst => (@{const_name "alpha_lst"}, @{typ "atom list"})
+ − 97
| Set => (@{const_name "alpha_set"}, @{typ "atom set"})
+ − 98
| Res => (@{const_name "alpha_res"}, @{typ "atom set"})
+ − 99
val ty = fastype_of args
+ − 100
val pair_ty = HOLogic.mk_prodT (binder_ty, ty)
+ − 101
val alpha_ty = [ty, ty] ---> @{typ "bool"}
+ − 102
val fv_ty = ty --> @{typ "atom set"}
+ − 103
val pair_lhs = HOLogic.mk_prod (binders, args)
+ − 104
val pair_rhs = HOLogic.mk_prod (binders', args')
+ − 105
in
+ − 106
HOLogic.exists_const @{typ perm} $ Abs ("p", @{typ perm},
+ − 107
Const (alpha_name, [pair_ty, alpha_ty, fv_ty, @{typ "perm"}, pair_ty] ---> @{typ bool})
+ − 108
$ pair_lhs $ alpha $ fv $ (Bound 0) $ pair_rhs)
+ − 109
end
2297
+ − 110
+ − 111
(* for non-recursive binders we have to produce alpha_bn premises *)
+ − 112
fun mk_alpha_bn_prem alpha_bn_map args args' bodies binder =
+ − 113
case binder of
+ − 114
(NONE, _) => []
+ − 115
| (SOME bn, i) =>
+ − 116
if member (op=) bodies i then []
2320
+ − 117
else [lookup alpha_bn_map bn $ nth args i $ nth args' i]
2297
+ − 118
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 119
(* generate the premises for an alpha rule; mk_frees is used
2297
+ − 120
if no binders are present *)
+ − 121
fun mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args') bclause =
2476
+ − 122
let
+ − 123
fun mk_frees i =
+ − 124
let
+ − 125
val arg = nth args i
+ − 126
val arg' = nth args' i
+ − 127
val ty = fastype_of arg
+ − 128
in
+ − 129
if nth is_rec i
+ − 130
then fst (lookup alpha_map ty) $ arg $ arg'
+ − 131
else HOLogic.mk_eq (arg, arg')
+ − 132
end
2297
+ − 133
2476
+ − 134
fun mk_alpha_fv i =
+ − 135
let
+ − 136
val ty = fastype_of (nth args i)
+ − 137
in
+ − 138
case AList.lookup (op=) alpha_map ty of
+ − 139
NONE => (HOLogic.eq_const ty, supp_const ty)
+ − 140
| SOME (alpha, fv) => (alpha, fv)
+ − 141
end
+ − 142
in
+ − 143
case bclause of
+ − 144
BC (_, [], bodies) => map (HOLogic.mk_Trueprop o mk_frees) bodies
+ − 145
| BC (bmode, binders, bodies) =>
+ − 146
let
+ − 147
val (alphas, fvs) = split_list (map mk_alpha_fv bodies)
+ − 148
val comp_fv = foldl1 mk_prod_fv fvs
+ − 149
val comp_alpha = foldl1 mk_prod_alpha alphas
+ − 150
val comp_args = foldl1 HOLogic.mk_prod (map (nth args) bodies)
+ − 151
val comp_args' = foldl1 HOLogic.mk_prod (map (nth args') bodies)
2611
3d101f2f817c
simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 152
val comp_binders = comb_binders lthy bmode args binders
3d101f2f817c
simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 153
val comp_binders' = comb_binders lthy bmode args' binders
2476
+ − 154
val alpha_prem =
+ − 155
mk_alpha_term bmode comp_fv comp_alpha comp_args comp_args' comp_binders comp_binders'
+ − 156
val alpha_bn_prems = flat (map (mk_alpha_bn_prem alpha_bn_map args args' bodies) binders)
+ − 157
in
+ − 158
map HOLogic.mk_Trueprop (alpha_prem::alpha_bn_prems)
+ − 159
end
+ − 160
end
2297
+ − 161
+ − 162
(* produces the introduction rule for an alpha rule *)
+ − 163
fun mk_alpha_intros lthy alpha_map alpha_bn_map (constr, ty, arg_tys, is_rec) bclauses =
2476
+ − 164
let
+ − 165
val arg_names = Datatype_Prop.make_tnames arg_tys
+ − 166
val arg_names' = Name.variant_list arg_names arg_names
+ − 167
val args = map Free (arg_names ~~ arg_tys)
+ − 168
val args' = map Free (arg_names' ~~ arg_tys)
+ − 169
val alpha = fst (lookup alpha_map ty)
+ − 170
val concl = HOLogic.mk_Trueprop (alpha $ list_comb (constr, args) $ list_comb (constr, args'))
+ − 171
val prems = map (mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args')) bclauses
+ − 172
in
+ − 173
Library.foldr Logic.mk_implies (flat prems, concl)
+ − 174
end
2297
+ − 175
+ − 176
(* produces the premise of an alpha-bn rule; we only need to
+ − 177
treat the case special where the binding clause is empty;
+ − 178
+ − 179
- if the body is not included in the bn_info, then we either
+ − 180
produce an equation or an alpha-premise
+ − 181
+ − 182
- if the body is included in the bn_info, then we create
+ − 183
either a recursive call to alpha-bn, or no premise *)
+ − 184
fun mk_alpha_bn lthy alpha_map alpha_bn_map bn_args is_rec (args, args') bclause =
+ − 185
let
2476
+ − 186
fun mk_alpha_bn_prem i =
+ − 187
let
+ − 188
val arg = nth args i
+ − 189
val arg' = nth args' i
+ − 190
val ty = fastype_of arg
+ − 191
in
+ − 192
case AList.lookup (op=) bn_args i of
+ − 193
NONE => (case (AList.lookup (op=) alpha_map ty) of
+ − 194
NONE => [HOLogic.mk_eq (arg, arg')]
+ − 195
| SOME (alpha, _) => [alpha $ arg $ arg'])
+ − 196
| SOME (NONE) => []
+ − 197
| SOME (SOME bn) => [lookup alpha_bn_map bn $ arg $ arg']
+ − 198
end
2297
+ − 199
in
2476
+ − 200
case bclause of
+ − 201
BC (_, [], bodies) =>
+ − 202
map HOLogic.mk_Trueprop (flat (map mk_alpha_bn_prem bodies))
+ − 203
| _ => mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args') bclause
+ − 204
end
2297
+ − 205
+ − 206
fun mk_alpha_bn_intro lthy bn_trm alpha_map alpha_bn_map (bn_args, (constr, _, arg_tys, is_rec)) bclauses =
2476
+ − 207
let
+ − 208
val arg_names = Datatype_Prop.make_tnames arg_tys
+ − 209
val arg_names' = Name.variant_list arg_names arg_names
+ − 210
val args = map Free (arg_names ~~ arg_tys)
+ − 211
val args' = map Free (arg_names' ~~ arg_tys)
+ − 212
val alpha_bn = lookup alpha_bn_map bn_trm
+ − 213
val concl = HOLogic.mk_Trueprop (alpha_bn $ list_comb (constr, args) $ list_comb (constr, args'))
+ − 214
val prems = map (mk_alpha_bn lthy alpha_map alpha_bn_map bn_args is_rec (args, args')) bclauses
+ − 215
in
+ − 216
Library.foldr Logic.mk_implies (flat prems, concl)
+ − 217
end
2297
+ − 218
+ − 219
fun mk_alpha_bn_intros lthy alpha_map alpha_bn_map constrs_info bclausesss (bn_trm, bn_n, bn_argss) =
2476
+ − 220
let
+ − 221
val nth_constrs_info = nth constrs_info bn_n
+ − 222
val nth_bclausess = nth bclausesss bn_n
+ − 223
in
+ − 224
map2 (mk_alpha_bn_intro lthy bn_trm alpha_map alpha_bn_map) (bn_argss ~~ nth_constrs_info) nth_bclausess
+ − 225
end
2297
+ − 226
2957
+ − 227
fun define_raw_alpha raw_dt_info bn_info bclausesss fvs lthy =
2476
+ − 228
let
2957
+ − 229
val RawDtInfo {raw_dt_names, raw_tys, raw_cns_info, ...} = raw_dt_info
+ − 230
+ − 231
val alpha_names = map (prefix "alpha_" o Long_Name.base_name) raw_dt_names
2476
+ − 232
val alpha_tys = map (fn ty => [ty, ty] ---> @{typ bool}) raw_tys
+ − 233
val alpha_frees = map Free (alpha_names ~~ alpha_tys)
+ − 234
val alpha_map = raw_tys ~~ (alpha_frees ~~ fvs)
2297
+ − 235
2476
+ − 236
val (bns, bn_tys) = split_list (map (fn (bn, i, _) => (bn, i)) bn_info)
+ − 237
val bn_names = map (fn bn => Long_Name.base_name (fst (dest_Const bn))) bns
+ − 238
val alpha_bn_names = map (prefix "alpha_") bn_names
+ − 239
val alpha_bn_arg_tys = map (nth raw_tys) bn_tys
+ − 240
val alpha_bn_tys = map (fn ty => [ty, ty] ---> @{typ "bool"}) alpha_bn_arg_tys
+ − 241
val alpha_bn_frees = map Free (alpha_bn_names ~~ alpha_bn_tys)
+ − 242
val alpha_bn_map = bns ~~ alpha_bn_frees
2297
+ − 243
2957
+ − 244
val alpha_intros = map2 (map2 (mk_alpha_intros lthy alpha_map alpha_bn_map)) raw_cns_info bclausesss
+ − 245
val alpha_bn_intros = map (mk_alpha_bn_intros lthy alpha_map alpha_bn_map raw_cns_info bclausesss) bn_info
2297
+ − 246
2476
+ − 247
val all_alpha_names = map (fn (a, ty) => ((Binding.name a, ty), NoSyn))
+ − 248
(alpha_names @ alpha_bn_names ~~ alpha_tys @ alpha_bn_tys)
+ − 249
val all_alpha_intros = map (pair Attrib.empty_binding) (flat alpha_intros @ flat alpha_bn_intros)
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 250
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 251
val (alpha_info, lthy') = Inductive.add_inductive_i
2476
+ − 252
{quiet_mode = true, verbose = false, alt_name = Binding.empty,
+ − 253
coind = false, no_elim = false, no_ind = false, skip_mono = false, fork_mono = false}
+ − 254
all_alpha_names [] all_alpha_intros [] lthy
2297
+ − 255
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 256
val all_alpha_trms_loc = #preds alpha_info;
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 257
val alpha_raw_induct_loc = #raw_induct alpha_info;
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 258
val alpha_intros_loc = #intrs alpha_info;
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 259
val alpha_cases_loc = #elims alpha_info;
3045
d0ad264f8c4f
updated to Isabelle 3 Nov; it includes a hack to work around a bug in the localised version of the quotient package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 260
val phi = Proof_Context.export_morphism lthy' lthy;
2888
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 261
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 262
val all_alpha_trms = all_alpha_trms_loc
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 263
|> map (Morphism.term phi)
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 264
|> map Type.legacy_freeze
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 265
val alpha_raw_induct = Morphism.thm phi alpha_raw_induct_loc
2476
+ − 266
val alpha_intros = map (Morphism.thm phi) alpha_intros_loc
+ − 267
val alpha_cases = map (Morphism.thm phi) alpha_cases_loc
2298
+ − 268
2888
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 269
val (alpha_trms, alpha_bn_trms) = chop (length fvs) all_alpha_trms
2928
+ − 270
+ − 271
val alpha_tys = map (domain_type o fastype_of) alpha_trms
+ − 272
val alpha_bn_tys = map (domain_type o fastype_of) alpha_bn_trms
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 273
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 274
val alpha_names = map (fst o dest_Const) alpha_trms
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 275
val alpha_bn_names = map (fst o dest_Const) alpha_bn_trms
2928
+ − 276
in
+ − 277
(AlphaResult
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 278
{alpha_names = alpha_names,
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 279
alpha_trms = alpha_trms,
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 280
alpha_tys = alpha_tys,
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 281
alpha_bn_names = alpha_bn_names,
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 282
alpha_bn_trms = alpha_bn_trms,
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 283
alpha_bn_tys = alpha_bn_tys,
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 284
alpha_intros = alpha_intros,
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 285
alpha_cases = alpha_cases,
2928
+ − 286
alpha_raw_induct = alpha_raw_induct}, lthy')
2476
+ − 287
end
2297
+ − 288
2300
+ − 289
2926
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 290
(** induction proofs **)
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 291
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 292
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 293
(* proof by structural induction over data types *)
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 294
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 295
fun induct_prove tys props induct_thm cases_tac ctxt =
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 296
let
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 297
val (arg_names, ctxt') =
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 298
Variable.variant_fixes (replicate (length tys) "x") ctxt
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 299
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 300
val args = map2 (curry Free) arg_names tys
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 301
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 302
val true_trms = replicate (length tys) (K @{term True})
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 303
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 304
fun apply_all x fs = map (fn f => f x) fs
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 305
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 306
val goals =
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 307
group (props @ (tys ~~ true_trms))
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 308
|> map snd
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 309
|> map2 apply_all args
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 310
|> map fold_conj
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 311
|> foldr1 HOLogic.mk_conj
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 312
|> HOLogic.mk_Trueprop
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 313
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 314
fun tac ctxt =
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 315
HEADGOAL
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 316
(DETERM o (rtac induct_thm)
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 317
THEN_ALL_NEW
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 318
(REPEAT_ALL_NEW (FIRST' [resolve_tac @{thms TrueI conjI}, cases_tac ctxt])))
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 319
in
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 320
Goal.prove ctxt' [] [] goals (fn {context, ...} => tac context)
3045
d0ad264f8c4f
updated to Isabelle 3 Nov; it includes a hack to work around a bug in the localised version of the quotient package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 321
|> singleton (Proof_Context.export ctxt' ctxt)
2926
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 322
|> Datatype_Aux.split_conj_thm
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 323
|> map Datatype_Aux.split_conj_thm
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 324
|> flat
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 325
|> filter_out (is_true o concl_of)
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 326
|> map zero_var_indexes
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 327
end
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 328
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 329
(* proof by rule induction over the alpha-definitions *)
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 330
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 331
fun alpha_prove alphas props alpha_induct_thm cases_tac ctxt =
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 332
let
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 333
val arg_tys = map (domain_type o fastype_of) alphas
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 334
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 335
val ((arg_names1, arg_names2), ctxt') =
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 336
ctxt
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 337
|> Variable.variant_fixes (replicate (length alphas) "x")
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 338
||>> Variable.variant_fixes (replicate (length alphas) "y")
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 339
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 340
val args1 = map2 (curry Free) arg_names1 arg_tys
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 341
val args2 = map2 (curry Free) arg_names2 arg_tys
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 342
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 343
val true_trms = replicate (length alphas) (K @{term True})
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 344
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 345
fun apply_all x fs = map (fn f => f x) fs
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 346
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 347
val goals_rhs =
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 348
group (props @ (alphas ~~ true_trms))
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 349
|> map snd
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 350
|> map2 apply_all (args1 ~~ args2)
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 351
|> map fold_conj
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 352
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 353
fun apply_trm_pair t (ar1, ar2) = t $ ar1 $ ar2
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 354
val goals_lhs = map2 apply_trm_pair alphas (args1 ~~ args2)
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 355
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 356
val goals =
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 357
(map2 (curry HOLogic.mk_imp) goals_lhs goals_rhs)
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 358
|> foldr1 HOLogic.mk_conj
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 359
|> HOLogic.mk_Trueprop
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 360
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 361
fun tac ctxt =
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 362
HEADGOAL
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 363
(DETERM o (rtac alpha_induct_thm)
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 364
THEN_ALL_NEW FIRST' [rtac @{thm TrueI}, cases_tac ctxt])
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 365
in
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 366
Goal.prove ctxt' [] [] goals (fn {context, ...} => tac context)
3045
d0ad264f8c4f
updated to Isabelle 3 Nov; it includes a hack to work around a bug in the localised version of the quotient package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 367
|> singleton (Proof_Context.export ctxt' ctxt)
2926
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 368
|> Datatype_Aux.split_conj_thm
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 369
|> map (fn th => th RS mp)
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 370
|> map Datatype_Aux.split_conj_thm
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 371
|> flat
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 372
|> filter_out (is_true o concl_of)
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 373
|> map zero_var_indexes
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 374
end
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 375
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 376
2316
+ − 377
2300
+ − 378
(** produces the distinctness theorems **)
+ − 379
2926
37c0d7953cba
moved Classical and Let temporarily into a section where "sorry" is allowed; this makes all test go through
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 380
2300
+ − 381
(* transforms the distinctness theorems of the constructors
2888
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 382
into "not-alphas" of the constructors *)
2399
+ − 383
fun mk_distinct_goal ty_trm_assoc neq =
2476
+ − 384
let
2888
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 385
val (Const (@{const_name "HOL.eq"}, ty_eq) $ lhs $ rhs) =
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 386
HOLogic.dest_not (HOLogic.dest_Trueprop neq)
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 387
val ty_str = fst (dest_Type (domain_type ty_eq))
2476
+ − 388
in
2888
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 389
Const (lookup ty_trm_assoc ty_str, ty_eq) $ lhs $ rhs
2476
+ − 390
|> HOLogic.mk_not
+ − 391
|> HOLogic.mk_Trueprop
+ − 392
end
2300
+ − 393
2399
+ − 394
fun distinct_tac cases_thms distinct_thms =
+ − 395
rtac notI THEN' eresolve_tac cases_thms
2300
+ − 396
THEN_ALL_NEW asm_full_simp_tac (HOL_ss addsimps distinct_thms)
+ − 397
2957
+ − 398
fun raw_prove_alpha_distincts ctxt alpha_result raw_dt_info =
2476
+ − 399
let
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 400
val AlphaResult {alpha_names, alpha_cases, ...} = alpha_result
2957
+ − 401
val RawDtInfo {raw_dt_names, raw_distinct_thms, ...} = raw_dt_info
2300
+ − 402
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 403
val ty_trm_assoc = raw_dt_names ~~ alpha_names
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 404
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 405
fun mk_alpha_distinct raw_distinct_trm =
2476
+ − 406
let
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 407
val goal = mk_distinct_goal ty_trm_assoc raw_distinct_trm
2476
+ − 408
in
2888
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 409
Goal.prove ctxt [] [] goal
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 410
(K (distinct_tac alpha_cases raw_distinct_thms 1))
2476
+ − 411
end
2399
+ − 412
in
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 413
map (mk_alpha_distinct o prop_of) raw_distinct_thms
2399
+ − 414
end
2300
+ − 415
+ − 416
2316
+ − 417
2300
+ − 418
(** produces the alpha_eq_iff simplification rules **)
+ − 419
2475
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 420
(* in case a theorem is of the form (Rel Const Const), it will be
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 421
rewritten to ((Rel Const = Const) = True)
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 422
*)
2300
+ − 423
fun mk_simp_rule thm =
+ − 424
case (prop_of thm) of
2475
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 425
@{term "Trueprop"} $ (_ $ Const _ $ Const _) => thm RS @{thm eqTrueI}
2300
+ − 426
| _ => thm
+ − 427
+ − 428
fun alpha_eq_iff_tac dist_inj intros elims =
+ − 429
SOLVED' (asm_full_simp_tac (HOL_ss addsimps intros)) ORELSE'
+ − 430
(rtac @{thm iffI} THEN'
+ − 431
RANGE [eresolve_tac elims THEN_ALL_NEW asm_full_simp_tac (HOL_ss addsimps dist_inj),
+ − 432
asm_full_simp_tac (HOL_ss addsimps intros)])
+ − 433
+ − 434
fun mk_alpha_eq_iff_goal thm =
+ − 435
let
+ − 436
val prop = prop_of thm;
+ − 437
val concl = HOLogic.dest_Trueprop (Logic.strip_imp_concl prop);
+ − 438
val hyps = map HOLogic.dest_Trueprop (Logic.strip_imp_prems prop);
+ − 439
fun list_conj l = foldr1 HOLogic.mk_conj l;
+ − 440
in
+ − 441
if hyps = [] then HOLogic.mk_Trueprop concl
+ − 442
else HOLogic.mk_Trueprop (HOLogic.mk_eq (concl, list_conj hyps))
+ − 443
end;
+ − 444
2957
+ − 445
fun raw_prove_alpha_eq_iff ctxt alpha_result raw_dt_info =
2476
+ − 446
let
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 447
val AlphaResult {alpha_intros, alpha_cases, ...} = alpha_result
2957
+ − 448
val RawDtInfo {raw_distinct_thms, raw_inject_thms, ...} = raw_dt_info
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 449
2476
+ − 450
val ((_, thms_imp), ctxt') = Variable.import false alpha_intros ctxt;
+ − 451
val goals = map mk_alpha_eq_iff_goal thms_imp;
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 452
val tac = alpha_eq_iff_tac (raw_distinct_thms @ raw_inject_thms) alpha_intros alpha_cases 1;
2476
+ − 453
val thms = map (fn goal => Goal.prove ctxt' [] [] goal (K tac)) goals;
+ − 454
in
+ − 455
Variable.export ctxt' ctxt thms
+ − 456
|> map mk_simp_rule
+ − 457
end
2300
+ − 458
2311
+ − 459
2316
+ − 460
(** reflexivity proof for the alphas **)
+ − 461
+ − 462
val exi_zero = @{lemma "P (0::perm) ==> (? x. P x)" by auto}
+ − 463
2480
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 464
fun cases_tac intros ctxt =
2476
+ − 465
let
2559
add799cf0817
adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 466
val prod_simps = @{thms split_conv prod_alpha_def prod_rel_def}
2316
+ − 467
2476
+ − 468
val unbound_tac = REPEAT o (etac @{thm conjE}) THEN' atac
2316
+ − 469
2476
+ − 470
val bound_tac =
+ − 471
EVERY' [ rtac exi_zero,
+ − 472
resolve_tac @{thms alpha_refl},
+ − 473
asm_full_simp_tac (HOL_ss addsimps prod_simps) ]
+ − 474
in
2480
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 475
resolve_tac intros THEN_ALL_NEW FIRST' [rtac @{thm refl}, unbound_tac, bound_tac]
2476
+ − 476
end
2316
+ − 477
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 478
fun raw_prove_refl ctxt alpha_result raw_dt_induct =
2476
+ − 479
let
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 480
val AlphaResult {alpha_trms, alpha_tys, alpha_bn_trms, alpha_bn_tys, alpha_intros, ...} =
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 481
alpha_result
2480
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 482
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 483
val props =
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 484
map (fn (ty, c) => (ty, fn x => c $ x $ x))
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 485
((alpha_tys ~~ alpha_trms) @ (alpha_bn_tys ~~ alpha_bn_trms))
2476
+ − 486
in
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 487
induct_prove alpha_tys props raw_dt_induct (cases_tac alpha_intros) ctxt
2476
+ − 488
end
2316
+ − 489
+ − 490
+ − 491
2311
+ − 492
(** symmetry proof for the alphas **)
+ − 493
+ − 494
val exi_neg = @{lemma "(EX (p::perm). P p) ==> (!!q. P q ==> Q (- q)) ==> EX p. Q p"
+ − 495
by (erule exE, rule_tac x="-p" in exI, auto)}
+ − 496
+ − 497
(* for premises that contain binders *)
2868
+ − 498
fun prem_bound_tac pred_names alpha_eqvt ctxt =
2476
+ − 499
let
+ − 500
fun trans_prem_tac pred_names ctxt =
+ − 501
SUBPROOF (fn {prems, context, ...} =>
+ − 502
let
+ − 503
val prems' = map (transform_prem1 context pred_names) prems
+ − 504
in
+ − 505
resolve_tac prems' 1
+ − 506
end) ctxt
2559
add799cf0817
adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 507
val prod_simps = @{thms split_conv permute_prod.simps prod_alpha_def prod_rel_def alphas}
2476
+ − 508
in
+ − 509
EVERY'
+ − 510
[ etac exi_neg,
+ − 511
resolve_tac @{thms alpha_sym_eqvt},
+ − 512
asm_full_simp_tac (HOL_ss addsimps prod_simps),
2868
+ − 513
eqvt_tac ctxt (eqvt_relaxed_config addpres alpha_eqvt) THEN' rtac @{thm refl},
+ − 514
trans_prem_tac pred_names ctxt]
2476
+ − 515
end
2311
+ − 516
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 517
fun raw_prove_sym ctxt alpha_result alpha_eqvt =
2476
+ − 518
let
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 519
val AlphaResult {alpha_names, alpha_trms, alpha_bn_names, alpha_bn_trms,
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 520
alpha_intros, alpha_raw_induct, ...} = alpha_result
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 521
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 522
val alpha_trms = alpha_trms @ alpha_bn_trms
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 523
val alpha_names = alpha_names @ alpha_bn_names
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 524
2476
+ − 525
val props = map (fn t => fn (x, y) => t $ y $ x) alpha_trms
2868
+ − 526
2476
+ − 527
fun tac ctxt =
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 528
resolve_tac alpha_intros THEN_ALL_NEW
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 529
FIRST' [atac, rtac @{thm sym} THEN' atac, prem_bound_tac alpha_names alpha_eqvt ctxt]
2476
+ − 530
in
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 531
alpha_prove alpha_trms (alpha_trms ~~ props) alpha_raw_induct tac ctxt
2389
+ − 532
end
2311
+ − 533
+ − 534
+ − 535
(** transitivity proof for alphas **)
+ − 536
2314
+ − 537
(* applies cases rules and resolves them with the last premise *)
2313
+ − 538
fun ecases_tac cases =
+ − 539
Subgoal.FOCUS (fn {prems, ...} =>
+ − 540
HEADGOAL (resolve_tac cases THEN' rtac (List.last prems)))
+ − 541
+ − 542
fun aatac pred_names =
+ − 543
SUBPROOF (fn {prems, context, ...} =>
+ − 544
HEADGOAL (resolve_tac (map (transform_prem1 context pred_names) prems)))
+ − 545
2314
+ − 546
(* instantiates exI with the permutation p + q *)
2313
+ − 547
val perm_inst_tac =
+ − 548
Subgoal.FOCUS (fn {params, ...} =>
+ − 549
let
+ − 550
val (p, q) = pairself snd (last2 params)
+ − 551
val pq_inst = foldl1 (uncurry Thm.capply) [@{cterm "plus::perm => perm => perm"}, p, q]
+ − 552
val exi_inst = Drule.instantiate' [SOME (@{ctyp "perm"})] [NONE, SOME pq_inst] @{thm exI}
+ − 553
in
+ − 554
HEADGOAL (rtac exi_inst)
+ − 555
end)
+ − 556
2868
+ − 557
fun non_trivial_cases_tac pred_names intros alpha_eqvt ctxt =
2476
+ − 558
let
2559
add799cf0817
adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 559
val prod_simps = @{thms split_conv alphas permute_prod.simps prod_alpha_def prod_rel_def}
2476
+ − 560
in
+ − 561
resolve_tac intros
+ − 562
THEN_ALL_NEW (asm_simp_tac HOL_basic_ss THEN'
+ − 563
TRY o EVERY' (* if binders are present *)
+ − 564
[ etac @{thm exE},
+ − 565
etac @{thm exE},
+ − 566
perm_inst_tac ctxt,
3029
+ − 567
resolve_tac @{thms alpha_trans_eqvt},
2476
+ − 568
atac,
+ − 569
aatac pred_names ctxt,
2868
+ − 570
eqvt_tac ctxt (eqvt_relaxed_config addpres alpha_eqvt) THEN' rtac @{thm refl},
2476
+ − 571
asm_full_simp_tac (HOL_ss addsimps prod_simps) ])
+ − 572
end
2313
+ − 573
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 574
fun prove_trans_tac alpha_result raw_dt_thms alpha_eqvt ctxt =
2476
+ − 575
let
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 576
val AlphaResult {alpha_names, alpha_bn_names, alpha_intros, alpha_cases, ...} = alpha_result
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 577
val alpha_names = alpha_names @ alpha_bn_names
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 578
2476
+ − 579
fun all_cases ctxt =
+ − 580
asm_full_simp_tac (HOL_basic_ss addsimps raw_dt_thms)
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 581
THEN' TRY o non_trivial_cases_tac alpha_names alpha_intros alpha_eqvt ctxt
2476
+ − 582
in
+ − 583
EVERY' [ rtac @{thm allI}, rtac @{thm impI},
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 584
ecases_tac alpha_cases ctxt THEN_ALL_NEW all_cases ctxt ]
2476
+ − 585
end
2311
+ − 586
2389
+ − 587
fun prep_trans_goal alpha_trm (arg1, arg2) =
2476
+ − 588
let
+ − 589
val arg_ty = fastype_of arg1
+ − 590
val mid = alpha_trm $ arg2 $ (Bound 0)
+ − 591
val rhs = alpha_trm $ arg1 $ (Bound 0)
+ − 592
in
+ − 593
HOLogic.all_const arg_ty $ Abs ("z", arg_ty, HOLogic.mk_imp (mid, rhs))
+ − 594
end
2311
+ − 595
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 596
fun raw_prove_trans ctxt alpha_result raw_dt_thms alpha_eqvt =
2476
+ − 597
let
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 598
val AlphaResult {alpha_names, alpha_trms, alpha_bn_names, alpha_bn_trms,
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 599
alpha_raw_induct, ...} = alpha_result
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 600
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 601
val alpha_trms = alpha_trms @ alpha_bn_trms
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 602
2476
+ − 603
val props = map prep_trans_goal alpha_trms
+ − 604
in
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 605
alpha_prove alpha_trms (alpha_trms ~~ props) alpha_raw_induct
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 606
(prove_trans_tac alpha_result raw_dt_thms alpha_eqvt) ctxt
2476
+ − 607
end
2311
+ − 608
2390
+ − 609
+ − 610
(** proves the equivp predicate for all alphas **)
2322
+ − 611
2592
+ − 612
val reflp_def' =
+ − 613
@{lemma "reflp R == !x. R x x" by (simp add: reflp_def refl_on_def)}
+ − 614
+ − 615
val symp_def' =
+ − 616
@{lemma "symp R == !x y . R x y --> R y x" by (simp add: symp_def sym_def)}
+ − 617
2397
+ − 618
val transp_def' =
+ − 619
@{lemma "transp R == !x y. R x y --> (!z. R y z --> R x z)"
2592
+ − 620
by (rule eq_reflection, auto simp add: trans_def transp_def)}
2322
+ − 621
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 622
fun raw_prove_equivp ctxt alpha_result refl symm trans =
2476
+ − 623
let
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 624
val AlphaResult {alpha_trms, alpha_bn_trms, ...} = alpha_result
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 625
2592
+ − 626
val refl' = map (fold_rule [reflp_def'] o atomize) refl
+ − 627
val symm' = map (fold_rule [symp_def'] o atomize) symm
2476
+ − 628
val trans' = map (fold_rule [transp_def'] o atomize) trans
2397
+ − 629
2476
+ − 630
fun prep_goal t =
+ − 631
HOLogic.mk_Trueprop (Const (@{const_name "equivp"}, fastype_of t --> @{typ bool}) $ t)
+ − 632
in
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 633
Goal.prove_multi ctxt [] [] (map prep_goal (alpha_trms @ alpha_bn_trms))
2476
+ − 634
(K (HEADGOAL (Goal.conjunction_tac THEN_ALL_NEW (rtac @{thm equivpI} THEN'
+ − 635
RANGE [resolve_tac refl', resolve_tac symm', resolve_tac trans']))))
2927
116f9ba4f59f
combined distributed data for alpha in alpha_result (partially done)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 636
|> chop (length alpha_trms)
2476
+ − 637
end
2322
+ − 638
2320
+ − 639
+ − 640
(* proves that alpha_raw implies alpha_bn *)
+ − 641
2928
+ − 642
fun raw_prove_bn_imp_tac alpha_result ctxt =
2322
+ − 643
SUBPROOF (fn {prems, context, ...} =>
2320
+ − 644
let
2928
+ − 645
val AlphaResult {alpha_names, alpha_intros, ...} = alpha_result
+ − 646
2320
+ − 647
val prems' = flat (map Datatype_Aux.split_conj_thm prems)
2928
+ − 648
val prems'' = map (transform_prem1 context alpha_names) prems'
2320
+ − 649
in
2322
+ − 650
HEADGOAL
+ − 651
(REPEAT_ALL_NEW
+ − 652
(FIRST' [ rtac @{thm TrueI},
+ − 653
rtac @{thm conjI},
+ − 654
resolve_tac prems',
+ − 655
resolve_tac prems'',
+ − 656
resolve_tac alpha_intros ]))
2320
+ − 657
end) ctxt
+ − 658
2928
+ − 659
+ − 660
fun raw_prove_bn_imp ctxt alpha_result =
2476
+ − 661
let
2928
+ − 662
val AlphaResult {alpha_trms, alpha_tys, alpha_bn_trms, alpha_raw_induct, ...} = alpha_result
+ − 663
2476
+ − 664
val arg_ty = domain_type o fastype_of
2928
+ − 665
val ty_assoc = alpha_tys ~~ alpha_trms
2476
+ − 666
val props = map (fn t => (lookup ty_assoc (arg_ty t), fn (x, y) => t $ x $ y)) alpha_bn_trms
+ − 667
in
2928
+ − 668
alpha_prove (alpha_trms @ alpha_bn_trms) props alpha_raw_induct
+ − 669
(raw_prove_bn_imp_tac alpha_result) ctxt
2476
+ − 670
end
2320
+ − 671
2387
+ − 672
2393
d9a0cf26a88c
added a function that transforms the helper-rsp lemmas into real rsp lemmas
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 673
(* respectfulness for fv_raw / bn_raw *)
2387
+ − 674
2928
+ − 675
fun raw_fv_bn_rsp_aux ctxt alpha_result fvs bns fv_bns simps =
2476
+ − 676
let
2928
+ − 677
val AlphaResult {alpha_trms, alpha_tys, alpha_bn_trms, alpha_raw_induct, ...} = alpha_result
+ − 678
+ − 679
val arg_ty = domain_type o fastype_of
+ − 680
val ty_assoc = alpha_tys ~~ alpha_trms
2476
+ − 681
fun mk_eq' t x y = HOLogic.mk_eq (t $ x, t $ y)
2387
+ − 682
2476
+ − 683
val prop1 = map (fn t => (lookup ty_assoc (arg_ty t), fn (x, y) => mk_eq' t x y)) fvs
+ − 684
val prop2 = map (fn t => (lookup ty_assoc (arg_ty t), fn (x, y) => mk_eq' t x y)) (bns @ fv_bns)
+ − 685
val prop3 = map2 (fn t1 => fn t2 => (t1, fn (x, y) => mk_eq' t2 x y)) alpha_bn_trms fv_bns
2888
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 686
2476
+ − 687
val ss = HOL_ss addsimps (simps @ @{thms alphas prod_fv.simps set.simps append.simps}
+ − 688
@ @{thms Un_assoc Un_insert_left Un_empty_right Un_empty_left})
+ − 689
in
2928
+ − 690
alpha_prove (alpha_trms @ alpha_bn_trms) (prop1 @ prop2 @ prop3) alpha_raw_induct
2476
+ − 691
(K (asm_full_simp_tac ss)) ctxt
+ − 692
end
2387
+ − 693
2395
+ − 694
2393
d9a0cf26a88c
added a function that transforms the helper-rsp lemmas into real rsp lemmas
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 695
(* respectfulness for size *)
2392
+ − 696
2928
+ − 697
fun raw_size_rsp_aux ctxt alpha_result simps =
2476
+ − 698
let
2928
+ − 699
val AlphaResult {alpha_trms, alpha_tys, alpha_bn_trms, alpha_bn_tys, alpha_raw_induct, ...} =
+ − 700
alpha_result
+ − 701
2476
+ − 702
fun mk_prop ty (x, y) = HOLogic.mk_eq
+ − 703
(HOLogic.size_const ty $ x, HOLogic.size_const ty $ y)
2392
+ − 704
2928
+ − 705
val props = (alpha_trms @ alpha_bn_trms) ~~ (map mk_prop (alpha_tys @ alpha_bn_tys))
2392
+ − 706
2559
add799cf0817
adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 707
val ss = HOL_ss addsimps (simps @ @{thms alphas prod_alpha_def prod_rel_def
2476
+ − 708
permute_prod_def prod.cases prod.recs})
2392
+ − 709
2476
+ − 710
val tac = (TRY o REPEAT o etac @{thm exE}) THEN' asm_full_simp_tac ss
+ − 711
in
2928
+ − 712
alpha_prove (alpha_trms @ alpha_bn_trms) props alpha_raw_induct (K tac) ctxt
2476
+ − 713
end
2392
+ − 714
2393
d9a0cf26a88c
added a function that transforms the helper-rsp lemmas into real rsp lemmas
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 715
2395
+ − 716
(* respectfulness for constructors *)
+ − 717
+ − 718
fun raw_constr_rsp_tac alpha_intros simps =
2476
+ − 719
let
+ − 720
val pre_ss = HOL_ss addsimps @{thms fun_rel_def}
2559
add799cf0817
adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 721
val post_ss = HOL_ss addsimps @{thms alphas prod_alpha_def prod_rel_def
2476
+ − 722
prod_fv.simps fresh_star_zero permute_zero prod.cases} @ simps
+ − 723
in
+ − 724
asm_full_simp_tac pre_ss
+ − 725
THEN' REPEAT o (resolve_tac @{thms allI impI})
+ − 726
THEN' resolve_tac alpha_intros
+ − 727
THEN_ALL_NEW (TRY o (rtac exi_zero) THEN' asm_full_simp_tac post_ss)
+ − 728
end
2395
+ − 729
2928
+ − 730
fun raw_constrs_rsp ctxt alpha_result constrs simps =
2476
+ − 731
let
2928
+ − 732
val AlphaResult {alpha_trms, alpha_tys, alpha_intros, ...} = alpha_result
+ − 733
2476
+ − 734
fun lookup ty =
2928
+ − 735
case AList.lookup (op=) (alpha_tys ~~ alpha_trms) ty of
2476
+ − 736
NONE => HOLogic.eq_const ty
+ − 737
| SOME alpha => alpha
2395
+ − 738
2888
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 739
fun fun_rel_app (t1, t2) =
2476
+ − 740
Const (@{const_name "fun_rel"}, dummyT) $ t1 $ t2
2395
+ − 741
2476
+ − 742
fun prep_goal trm =
+ − 743
trm
+ − 744
|> strip_type o fastype_of
2888
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 745
|> (fn (tys, ty) => tys @ [ty])
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 746
|> map lookup
eda5aeb056a6
fixed nasty bug with type variables in nominal_datatypes; this included to be careful with the output of the inductive and function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 747
|> foldr1 fun_rel_app
2476
+ − 748
|> (fn t => t $ trm $ trm)
+ − 749
|> Syntax.check_term ctxt
+ − 750
|> HOLogic.mk_Trueprop
+ − 751
in
+ − 752
Goal.prove_multi ctxt [] [] (map prep_goal constrs)
+ − 753
(K (HEADGOAL
+ − 754
(Goal.conjunction_tac THEN_ALL_NEW raw_constr_rsp_tac alpha_intros simps)))
+ − 755
end
2395
+ − 756
+ − 757
2404
+ − 758
(* rsp lemmas for alpha_bn relations *)
+ − 759
+ − 760
val rsp_equivp =
+ − 761
@{lemma "[|equivp Q; !!x y. R x y ==> Q x y|] ==> (R ===> R ===> op =) Q Q"
+ − 762
by (simp only: fun_rel_def equivp_def, metis)}
+ − 763
2440
0a36825b16c1
"isabelle make test" makes all major examples....they work up to supp theorems (excluding)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 764
0a36825b16c1
"isabelle make test" makes all major examples....they work up to supp theorems (excluding)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 765
(* we have to reorder the alpha_bn_imps theorems in order
0a36825b16c1
"isabelle make test" makes all major examples....they work up to supp theorems (excluding)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 766
to be in order with alpha_bn_trms *)
2928
+ − 767
fun raw_alpha_bn_rsp alpha_result alpha_bn_equivp alpha_bn_imps =
2476
+ − 768
let
2928
+ − 769
val AlphaResult {alpha_bn_trms, ...} = alpha_result
+ − 770
2476
+ − 771
fun mk_map thm =
+ − 772
thm |> `prop_of
+ − 773
|>> List.last o snd o strip_comb
+ − 774
|>> HOLogic.dest_Trueprop
+ − 775
|>> head_of
+ − 776
|>> fst o dest_Const
2440
0a36825b16c1
"isabelle make test" makes all major examples....they work up to supp theorems (excluding)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 777
2476
+ − 778
val alpha_bn_imps' =
+ − 779
map (lookup (map mk_map alpha_bn_imps) o fst o dest_Const) alpha_bn_trms
2440
0a36825b16c1
"isabelle make test" makes all major examples....they work up to supp theorems (excluding)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 780
2476
+ − 781
fun mk_thm thm1 thm2 =
+ − 782
(forall_intr_vars thm2) COMP (thm1 RS rsp_equivp)
+ − 783
in
+ − 784
map2 mk_thm alpha_bn_equivp alpha_bn_imps'
+ − 785
end
2404
+ − 786
+ − 787
2561
+ − 788
(* rsp for permute_bn functions *)
+ − 789
+ − 790
val perm_bn_rsp = @{lemma "(!x y p. R x y --> R (f p x) (f p y)) ==> (op= ===> R ===> R) f f"
+ − 791
by (simp add: fun_rel_def)}
+ − 792
2928
+ − 793
fun raw_prove_perm_bn_tac alpha_result simps ctxt =
2561
+ − 794
SUBPROOF (fn {prems, context, ...} =>
+ − 795
let
2928
+ − 796
val AlphaResult {alpha_names, alpha_bn_names, alpha_intros, ...} = alpha_result
2561
+ − 797
val prems' = flat (map Datatype_Aux.split_conj_thm prems)
2928
+ − 798
val prems'' = map (transform_prem1 context (alpha_names @ alpha_bn_names)) prems'
2561
+ − 799
in
+ − 800
HEADGOAL
+ − 801
(simp_tac (HOL_basic_ss addsimps (simps @ prems'))
+ − 802
THEN' TRY o REPEAT_ALL_NEW
+ − 803
(FIRST' [ rtac @{thm TrueI},
+ − 804
rtac @{thm conjI},
+ − 805
rtac @{thm refl},
+ − 806
resolve_tac prems',
+ − 807
resolve_tac prems'',
+ − 808
resolve_tac alpha_intros ]))
+ − 809
end) ctxt
+ − 810
2928
+ − 811
fun raw_perm_bn_rsp ctxt alpha_result perm_bns simps =
2561
+ − 812
let
2928
+ − 813
val AlphaResult {alpha_trms, alpha_tys, alpha_bn_trms, alpha_bn_tys, alpha_raw_induct, ...} =
+ − 814
alpha_result
+ − 815
2561
+ − 816
val perm_bn_ty = range_type o range_type o fastype_of
2928
+ − 817
val ty_assoc = (alpha_tys @ alpha_bn_tys) ~~ (alpha_trms @ alpha_bn_trms)
2561
+ − 818
+ − 819
val ([p], ctxt') = Variable.variant_fixes ["p"] ctxt
+ − 820
val p = Free (p, @{typ perm})
+ − 821
+ − 822
fun mk_prop t =
+ − 823
let
+ − 824
val alpha_trm = lookup ty_assoc (perm_bn_ty t)
+ − 825
in
+ − 826
(alpha_trm, fn (x, y) => alpha_trm $ (t $ p $ x) $ (t $ p $ y))
+ − 827
end
+ − 828
2928
+ − 829
val goals = map mk_prop perm_bns
2561
+ − 830
in
2928
+ − 831
alpha_prove (alpha_trms @ alpha_bn_trms) goals alpha_raw_induct
+ − 832
(raw_prove_perm_bn_tac alpha_result simps) ctxt
3045
d0ad264f8c4f
updated to Isabelle 3 Nov; it includes a hack to work around a bug in the localised version of the quotient package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 833
|> Proof_Context.export ctxt' ctxt
2561
+ − 834
|> map atomize
+ − 835
|> map single
+ − 836
|> map (curry (op OF) perm_bn_rsp)
+ − 837
end
+ − 838
+ − 839
+ − 840
2399
+ − 841
(* transformation of the natural rsp-lemmas into standard form *)
2397
+ − 842
+ − 843
val fun_rsp = @{lemma
2559
add799cf0817
adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 844
"(!x y. R x y --> f x = f y) ==> (R ===> (op =)) f f" by (simp add: fun_rel_def)}
2397
+ − 845
+ − 846
fun mk_funs_rsp thm =
2476
+ − 847
thm
+ − 848
|> atomize
+ − 849
|> single
+ − 850
|> curry (op OF) fun_rsp
2393
d9a0cf26a88c
added a function that transforms the helper-rsp lemmas into real rsp lemmas
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 851
2397
+ − 852
+ − 853
val permute_rsp = @{lemma
+ − 854
"(!x y p. R x y --> R (permute p x) (permute p y))
2559
add799cf0817
adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 855
==> ((op =) ===> R ===> R) permute permute" by (simp add: fun_rel_def)}
2397
+ − 856
+ − 857
fun mk_alpha_permute_rsp thm =
2476
+ − 858
thm
+ − 859
|> atomize
+ − 860
|> single
+ − 861
|> curry (op OF) permute_rsp
2397
+ − 862
2393
d9a0cf26a88c
added a function that transforms the helper-rsp lemmas into real rsp lemmas
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 863
d9a0cf26a88c
added a function that transforms the helper-rsp lemmas into real rsp lemmas
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 864
2404
+ − 865
2297
+ − 866
end (* structure *)
+ − 867