2665
+ − 1
(* Nominal Mutual Functions
+ − 2
Author: Christian Urban
+ − 3
+ − 4
heavily based on the code of Alexander Krauss
+ − 5
(code forked on 14 January 2011)
+ − 6
+ − 7
+ − 8
Mutual recursive nominal function definitions.
+ − 9
*)
+ − 10
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 11
2665
+ − 12
signature NOMINAL_FUNCTION_MUTUAL =
+ − 13
sig
+ − 14
2819
+ − 15
val prepare_nominal_function_mutual : Nominal_Function_Common.nominal_function_config
2665
+ − 16
-> string (* defname *)
+ − 17
-> ((string * typ) * mixfix) list
+ − 18
-> term list
+ − 19
-> local_theory
+ − 20
-> ((thm (* goalstate *)
2973
d1038e67923a
added a flag (eqvt) to termination proofs arising fron nominal_primrecs
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 21
* (thm -> Nominal_Function_Common.nominal_function_result) (* proof continuation *)
2665
+ − 22
) * local_theory)
+ − 23
+ − 24
end
+ − 25
+ − 26
+ − 27
structure Nominal_Function_Mutual: NOMINAL_FUNCTION_MUTUAL =
+ − 28
struct
+ − 29
+ − 30
open Function_Lib
2821
c7d4bd9e89e0
fixed problem with earlier commit about nominal_function_common; added facility for specifying an invariant - added a definition of frees_set which need a finiteness invariant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 31
open Function_Common
2819
+ − 32
open Nominal_Function_Common
2665
+ − 33
+ − 34
type qgar = string * (string * typ) list * term list * term list * term
+ − 35
+ − 36
datatype mutual_part = MutualPart of
+ − 37
{i : int,
+ − 38
i' : int,
+ − 39
fvar : string * typ,
+ − 40
cargTs: typ list,
+ − 41
f_def: term,
+ − 42
f: term option,
+ − 43
f_defthm : thm option}
+ − 44
+ − 45
datatype mutual_info = Mutual of
+ − 46
{n : int,
+ − 47
n' : int,
+ − 48
fsum_var : string * typ,
+ − 49
+ − 50
ST: typ,
+ − 51
RST: typ,
+ − 52
+ − 53
parts: mutual_part list,
+ − 54
fqgars: qgar list,
+ − 55
qglrs: ((string * typ) list * term list * term * term) list,
+ − 56
+ − 57
fsum : term option}
+ − 58
+ − 59
fun mutual_induct_Pnames n =
+ − 60
if n < 5 then fst (chop n ["P","Q","R","S"])
+ − 61
else map (fn i => "P" ^ string_of_int i) (1 upto n)
+ − 62
+ − 63
fun get_part fname =
+ − 64
the o find_first (fn (MutualPart {fvar=(n,_), ...}) => n = fname)
+ − 65
+ − 66
(* FIXME *)
+ − 67
fun mk_prod_abs e (t1, t2) =
+ − 68
let
+ − 69
val bTs = rev (map snd e)
+ − 70
val T1 = fastype_of1 (bTs, t1)
+ − 71
val T2 = fastype_of1 (bTs, t2)
+ − 72
in
+ − 73
HOLogic.pair_const T1 T2 $ t1 $ t2
+ − 74
end
+ − 75
+ − 76
fun analyze_eqs ctxt defname fs eqs =
+ − 77
let
+ − 78
val num = length fs
+ − 79
val fqgars = map (split_def ctxt (K true)) eqs
+ − 80
val arity_of = map (fn (fname,_,_,args,_) => (fname, length args)) fqgars
+ − 81
|> AList.lookup (op =) #> the
+ − 82
+ − 83
fun curried_types (fname, fT) =
+ − 84
let
+ − 85
val (caTs, uaTs) = chop (arity_of fname) (binder_types fT)
+ − 86
in
+ − 87
(caTs, uaTs ---> body_type fT)
+ − 88
end
+ − 89
+ − 90
val (caTss, resultTs) = split_list (map curried_types fs)
+ − 91
val argTs = map (foldr1 HOLogic.mk_prodT) caTss
+ − 92
+ − 93
val dresultTs = distinct (op =) resultTs
+ − 94
val n' = length dresultTs
+ − 95
+ − 96
val RST = Balanced_Tree.make (uncurry SumTree.mk_sumT) dresultTs
+ − 97
val ST = Balanced_Tree.make (uncurry SumTree.mk_sumT) argTs
+ − 98
+ − 99
val fsum_type = ST --> RST
+ − 100
+ − 101
val ([fsum_var_name], _) = Variable.add_fixes [ defname ^ "_sum" ] ctxt
+ − 102
val fsum_var = (fsum_var_name, fsum_type)
+ − 103
+ − 104
fun define (fvar as (n, _)) caTs resultT i =
+ − 105
let
+ − 106
val vars = map_index (fn (j,T) => Free ("x" ^ string_of_int j, T)) caTs (* FIXME: Bind xs properly *)
+ − 107
val i' = find_index (fn Ta => Ta = resultT) dresultTs + 1
+ − 108
+ − 109
val f_exp = SumTree.mk_proj RST n' i' (Free fsum_var $ SumTree.mk_inj ST num i (foldr1 HOLogic.mk_prod vars))
+ − 110
val def = Term.abstract_over (Free fsum_var, fold_rev lambda vars f_exp)
+ − 111
+ − 112
val rew = (n, fold_rev lambda vars f_exp)
+ − 113
in
+ − 114
(MutualPart {i=i, i'=i', fvar=fvar,cargTs=caTs,f_def=def,f=NONE,f_defthm=NONE}, rew)
+ − 115
end
+ − 116
+ − 117
val (parts, rews) = split_list (map4 define fs caTss resultTs (1 upto num))
+ − 118
+ − 119
fun convert_eqs (f, qs, gs, args, rhs) =
+ − 120
let
+ − 121
val MutualPart {i, i', ...} = get_part f parts
2781
+ − 122
val rhs' = rhs
+ − 123
|> map_aterms (fn t as Free (n, _) => the_default t (AList.lookup (op =) rews n) | t => t)
2665
+ − 124
in
+ − 125
(qs, gs, SumTree.mk_inj ST num i (foldr1 (mk_prod_abs qs) args),
2781
+ − 126
Envir.beta_norm (SumTree.mk_inj RST n' i' rhs'))
2665
+ − 127
end
+ − 128
+ − 129
val qglrs = map convert_eqs fqgars
+ − 130
in
+ − 131
Mutual {n=num, n'=n', fsum_var=fsum_var, ST=ST, RST=RST,
+ − 132
parts=parts, fqgars=fqgars, qglrs=qglrs, fsum=NONE}
+ − 133
end
+ − 134
+ − 135
fun define_projections fixes mutual fsum lthy =
+ − 136
let
+ − 137
fun def ((MutualPart {i=i, i'=i', fvar=(fname, fT), cargTs, f_def, ...}), (_, mixfix)) lthy =
+ − 138
let
+ − 139
val ((f, (_, f_defthm)), lthy') =
+ − 140
Local_Theory.define
+ − 141
((Binding.name fname, mixfix),
+ − 142
((Binding.conceal (Binding.name (fname ^ "_def")), []),
+ − 143
Term.subst_bound (fsum, f_def))) lthy
+ − 144
in
+ − 145
(MutualPart {i=i, i'=i', fvar=(fname, fT), cargTs=cargTs, f_def=f_def,
+ − 146
f=SOME f, f_defthm=SOME f_defthm },
+ − 147
lthy')
+ − 148
end
+ − 149
+ − 150
val Mutual { n, n', fsum_var, ST, RST, parts, fqgars, qglrs, ... } = mutual
+ − 151
val (parts', lthy') = fold_map def (parts ~~ fixes) lthy
+ − 152
in
+ − 153
(Mutual { n=n, n'=n', fsum_var=fsum_var, ST=ST, RST=RST, parts=parts',
+ − 154
fqgars=fqgars, qglrs=qglrs, fsum=SOME fsum },
+ − 155
lthy')
+ − 156
end
+ − 157
+ − 158
fun in_context ctxt (f, pre_qs, pre_gs, pre_args, pre_rhs) F =
+ − 159
let
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
+ − 160
val thy = Proof_Context.theory_of ctxt
2665
+ − 161
+ − 162
val oqnames = map fst pre_qs
+ − 163
val (qs, _) = Variable.variant_fixes oqnames ctxt
+ − 164
|>> map2 (fn (_, T) => fn n => Free (n, T)) pre_qs
+ − 165
+ − 166
fun inst t = subst_bounds (rev qs, t)
+ − 167
val gs = map inst pre_gs
+ − 168
val args = map inst pre_args
+ − 169
val rhs = inst pre_rhs
+ − 170
+ − 171
val cqs = map (cterm_of thy) qs
+ − 172
val ags = map (Thm.assume o cterm_of thy) gs
+ − 173
+ − 174
val import = fold Thm.forall_elim cqs
+ − 175
#> fold Thm.elim_implies ags
+ − 176
+ − 177
val export = fold_rev (Thm.implies_intr o cprop_of) ags
+ − 178
#> fold_rev forall_intr_rename (oqnames ~~ cqs)
+ − 179
in
+ − 180
F ctxt (f, qs, gs, args, rhs) import export
+ − 181
end
+ − 182
+ − 183
fun recover_mutual_psimp all_orig_fdefs parts ctxt (fname, _, _, args, rhs)
+ − 184
import (export : thm -> thm) sum_psimp_eq =
+ − 185
let
+ − 186
val (MutualPart {f=SOME f, ...}) = get_part fname parts
2974
+ − 187
2665
+ − 188
val psimp = import sum_psimp_eq
+ − 189
val (simp, restore_cond) =
+ − 190
case cprems_of psimp of
+ − 191
[] => (psimp, I)
+ − 192
| [cond] => (Thm.implies_elim psimp (Thm.assume cond), Thm.implies_intr cond)
+ − 193
| _ => raise General.Fail "Too many conditions"
+ − 194
in
+ − 195
Goal.prove ctxt [] []
+ − 196
(HOLogic.Trueprop $ HOLogic.mk_eq (list_comb (f, args), rhs))
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 197
(fn _ => (Local_Defs.unfold_tac ctxt all_orig_fdefs)
2665
+ − 198
THEN EqSubst.eqsubst_tac ctxt [0] [simp] 1
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 199
THEN (simp_tac (simpset_of ctxt)) 1) (* FIXME: global simpset?!! *)
2981
+ − 200
|> restore_cond
+ − 201
|> export
+ − 202
end
+ − 203
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 204
val inl_perm = @{lemma "x = Inl y ==> Sum_Type.Projl (permute p x) = permute p (Sum_Type.Projl x)" by simp}
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 205
val inr_perm = @{lemma "x = Inr y ==> Sum_Type.Projr (permute p x) = permute p (Sum_Type.Projr x)" by simp}
2981
+ − 206
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 207
fun recover_mutual_eqvt eqvt_thm all_orig_fdefs parts ctxt (fname, _, _, args, _)
2981
+ − 208
import (export : thm -> thm) sum_psimp_eq =
+ − 209
let
+ − 210
val (MutualPart {f=SOME f, ...}) = get_part fname parts
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 211
2981
+ − 212
val psimp = import sum_psimp_eq
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 213
val (cond, simp, restore_cond) =
2981
+ − 214
case cprems_of psimp of
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 215
[] => ([], psimp, I)
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 216
| [cond] => ([Thm.assume cond], Thm.implies_elim psimp (Thm.assume cond), Thm.implies_intr cond)
2981
+ − 217
| _ => raise General.Fail "Too many conditions"
+ − 218
+ − 219
val ([p], ctxt') = Variable.variant_fixes ["p"] ctxt
+ − 220
val p = Free (p, @{typ perm})
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 221
val ss = HOL_basic_ss addsimps
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 222
@{thms permute_sum.simps[symmetric] Pair_eqvt[symmetric]} @
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 223
@{thms Projr.simps Projl.simps} @
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 224
[(cond MRS eqvt_thm) RS @{thm sym}] @
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 225
[inl_perm, inr_perm, simp]
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 226
val goal_lhs = mk_perm p (list_comb (f, args))
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 227
val goal_rhs = list_comb (f, map (mk_perm p) args)
2981
+ − 228
in
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 229
Goal.prove ctxt' [] [] (HOLogic.Trueprop $ HOLogic.mk_eq (goal_lhs, goal_rhs))
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 230
(fn _ => (Local_Defs.unfold_tac ctxt all_orig_fdefs)
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 231
THEN (asm_full_simp_tac ss 1))
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
+ − 232
|> singleton (Proof_Context.export ctxt' ctxt)
2665
+ − 233
|> restore_cond
+ − 234
|> export
+ − 235
end
+ − 236
+ − 237
fun mk_applied_form ctxt caTs thm =
+ − 238
let
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
+ − 239
val thy = Proof_Context.theory_of ctxt
2665
+ − 240
val xs = map_index (fn (i,T) => cterm_of thy (Free ("x" ^ string_of_int i, T))) caTs (* FIXME: Bind xs properly *)
+ − 241
in
+ − 242
fold (fn x => fn thm => Thm.combination thm (Thm.reflexive x)) xs thm
+ − 243
|> Conv.fconv_rule (Thm.beta_conversion true)
+ − 244
|> fold_rev Thm.forall_intr xs
+ − 245
|> Thm.forall_elim_vars 0
+ − 246
end
+ − 247
+ − 248
fun mutual_induct_rules lthy induct all_f_defs (Mutual {n, ST, parts, ...}) =
+ − 249
let
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
+ − 250
val cert = cterm_of (Proof_Context.theory_of lthy)
2665
+ − 251
val newPs =
+ − 252
map2 (fn Pname => fn MutualPart {cargTs, ...} =>
+ − 253
Free (Pname, cargTs ---> HOLogic.boolT))
+ − 254
(mutual_induct_Pnames (length parts)) parts
+ − 255
+ − 256
fun mk_P (MutualPart {cargTs, ...}) P =
+ − 257
let
+ − 258
val avars = map_index (fn (i,T) => Var (("a", i), T)) cargTs
+ − 259
val atup = foldr1 HOLogic.mk_prod avars
+ − 260
in
+ − 261
HOLogic.tupled_lambda atup (list_comb (P, avars))
+ − 262
end
+ − 263
+ − 264
val Ps = map2 mk_P parts newPs
+ − 265
val case_exp = SumTree.mk_sumcases HOLogic.boolT Ps
+ − 266
+ − 267
val induct_inst =
+ − 268
Thm.forall_elim (cert case_exp) induct
+ − 269
|> full_simplify SumTree.sumcase_split_ss
+ − 270
|> full_simplify (HOL_basic_ss addsimps all_f_defs)
+ − 271
+ − 272
fun project rule (MutualPart {cargTs, i, ...}) k =
+ − 273
let
+ − 274
val afs = map_index (fn (j,T) => Free ("a" ^ string_of_int (j + k), T)) cargTs (* FIXME! *)
+ − 275
val inj = SumTree.mk_inj ST n i (foldr1 HOLogic.mk_prod afs)
+ − 276
in
+ − 277
(rule
+ − 278
|> Thm.forall_elim (cert inj)
+ − 279
|> full_simplify SumTree.sumcase_split_ss
+ − 280
|> fold_rev (Thm.forall_intr o cert) (afs @ newPs),
+ − 281
k + length cargTs)
+ − 282
end
+ − 283
in
+ − 284
fst (fold_map (project induct_inst) parts 0)
+ − 285
end
+ − 286
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 287
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 288
fun forall_elim s (Const ("all", _) $ Abs (_, _, t)) = subst_bound (s, t)
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 289
| forall_elim _ t = t
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 290
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 291
val forall_elim_list = fold forall_elim
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 292
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 293
fun split_conj_thm th =
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 294
(split_conj_thm (th RS conjunct1)) @ (split_conj_thm (th RS conjunct2)) handle THM _ => [th];
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 295
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 296
fun prove_eqvt ctxt fs argTss eqvts_thms induct_thms =
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 297
let
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 298
fun aux argTs s = argTs
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 299
|> map (pair s)
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 300
|> Variable.variant_frees ctxt fs
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 301
val argss' = map2 aux argTss (Name.invent (Variable.names_of ctxt) "" (length fs))
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 302
val argss = (map o map) Free argss'
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 303
val arg_namess = (map o map) fst argss'
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 304
val insts = (map o map) SOME arg_namess
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 305
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 306
val ([p_name], ctxt') = Variable.variant_fixes ["p"] ctxt
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 307
val p = Free (p_name, @{typ perm})
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 308
2983
+ − 309
(* extracting the acc-premises from the induction theorems *)
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 310
val acc_prems =
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 311
map prop_of induct_thms
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 312
|> map2 forall_elim_list argss
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 313
|> map (strip_qnt_body "all")
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 314
|> map (curry Logic.nth_prem 1)
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 315
|> map HOLogic.dest_Trueprop
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 316
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 317
fun mk_goal acc_prem (f, args) =
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 318
let
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 319
val goal_lhs = mk_perm p (list_comb (f, args))
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 320
val goal_rhs = list_comb (f, map (mk_perm p) args)
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 321
in
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 322
HOLogic.mk_imp (acc_prem, HOLogic.mk_eq (goal_lhs, goal_rhs))
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 323
end
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 324
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 325
val goal = fold_conj_balanced (map2 mk_goal acc_prems (fs ~~ argss))
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 326
|> HOLogic.mk_Trueprop
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 327
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 328
val induct_thm = case induct_thms of
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 329
[thm] => thm
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 330
|> Drule.gen_all
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 331
|> Thm.permute_prems 0 1
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 332
|> (fn thm => atomize_rule (length (prems_of thm) - 1) thm)
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 333
| thms => thms
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 334
|> map Drule.gen_all
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 335
|> map (Rule_Cases.add_consumes 1)
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 336
|> snd o Rule_Cases.strict_mutual_rule ctxt'
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 337
|> atomize_concl
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 338
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 339
fun tac thm = rtac (Drule.gen_all thm) THEN_ALL_NEW atac
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 340
in
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 341
Goal.prove ctxt' (flat arg_namess) [] goal
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 342
(fn {context, ...} => HEADGOAL (DETERM o (rtac induct_thm) THEN' RANGE (map tac eqvts_thms)))
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
+ − 343
|> singleton (Proof_Context.export ctxt' ctxt)
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 344
|> split_conj_thm
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 345
|> map (fn th => th RS mp)
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 346
end
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 347
2665
+ − 348
fun mk_partial_rules_mutual lthy inner_cont (m as Mutual {parts, fqgars, ...}) proof =
+ − 349
let
+ − 350
val result = inner_cont proof
2973
d1038e67923a
added a flag (eqvt) to termination proofs arising fron nominal_primrecs
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 351
val NominalFunctionResult {G, R, cases, psimps, simple_pinducts=[simple_pinduct],
2974
+ − 352
termination, domintros, eqvts=[eqvt],...} = result
2665
+ − 353
+ − 354
val (all_f_defs, fs) =
+ − 355
map (fn MutualPart {f_defthm = SOME f_def, f = SOME f, cargTs, ...} =>
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 356
(mk_applied_form lthy cargTs (Thm.symmetric f_def), f))
2665
+ − 357
parts
+ − 358
|> split_list
+ − 359
+ − 360
val all_orig_fdefs =
+ − 361
map (fn MutualPart {f_defthm = SOME f_def, ...} => f_def) parts
+ − 362
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 363
val cargTss =
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 364
map (fn MutualPart {f = SOME f, cargTs, ...} => cargTs) parts
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 365
2665
+ − 366
fun mk_mpsimp fqgar sum_psimp =
+ − 367
in_context lthy fqgar (recover_mutual_psimp all_orig_fdefs parts) sum_psimp
+ − 368
2981
+ − 369
fun mk_meqvts fqgar sum_psimp =
+ − 370
in_context lthy fqgar (recover_mutual_eqvt eqvt all_orig_fdefs parts) sum_psimp
+ − 371
2665
+ − 372
val rew_ss = HOL_basic_ss addsimps all_f_defs
+ − 373
val mpsimps = map2 mk_mpsimp fqgars psimps
+ − 374
val minducts = mutual_induct_rules lthy simple_pinduct all_f_defs m
+ − 375
val mtermination = full_simplify rew_ss termination
+ − 376
val mdomintros = Option.map (map (full_simplify rew_ss)) domintros
2981
+ − 377
val meqvts = map2 mk_meqvts fqgars psimps
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 378
val meqvt_funs = prove_eqvt lthy fs cargTss meqvts minducts
2974
+ − 379
in
2973
d1038e67923a
added a flag (eqvt) to termination proofs arising fron nominal_primrecs
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 380
NominalFunctionResult { fs=fs, G=G, R=R,
2665
+ − 381
psimps=mpsimps, simple_pinducts=minducts,
+ − 382
cases=cases, termination=mtermination,
2982
4a00077c008f
completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 383
domintros=mdomintros, eqvts=meqvt_funs }
2665
+ − 384
end
+ − 385
+ − 386
(* nominal *)
+ − 387
fun prepare_nominal_function_mutual config defname fixes eqss lthy =
+ − 388
let
+ − 389
val mutual as Mutual {fsum_var=(n, T), qglrs, ...} =
+ − 390
analyze_eqs lthy defname (map fst fixes) (map Envir.beta_eta_contract eqss)
+ − 391
+ − 392
val ((fsum, goalstate, cont), lthy') =
+ − 393
Nominal_Function_Core.prepare_nominal_function config defname [((n, T), NoSyn)] qglrs lthy
+ − 394
+ − 395
val (mutual', lthy'') = define_projections fixes mutual fsum lthy'
+ − 396
+ − 397
val mutual_cont = mk_partial_rules_mutual lthy'' cont mutual'
+ − 398
in
+ − 399
((goalstate, mutual_cont), lthy'')
+ − 400
end
+ − 401
+ − 402
end