author | Christian Urban <urbanc@in.tum.de> |
Tue, 19 Jul 2011 01:40:36 +0100 | |
changeset 2974 | b95a2065aa10 |
parent 2973 | d1038e67923a |
child 2975 | c62e26830420 |
permissions | -rw-r--r-- |
2665
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
1 |
(* Nominal Mutual Functions |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
2 |
Author: Christian Urban |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
heavily based on the code of Alexander Krauss |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
5 |
(code forked on 14 January 2011) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
6 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
7 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
8 |
Mutual recursive nominal function definitions. |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
9 |
*) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
10 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
11 |
signature NOMINAL_FUNCTION_MUTUAL = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
12 |
sig |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
13 |
|
2819
4bd584ff4fab
added an option for an invariant (at the moment only a stub)
Christian Urban <urbanc@in.tum.de>
parents:
2781
diff
changeset
|
14 |
val prepare_nominal_function_mutual : Nominal_Function_Common.nominal_function_config |
2665
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
15 |
-> string (* defname *) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
16 |
-> ((string * typ) * mixfix) list |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
17 |
-> term list |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
18 |
-> local_theory |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
19 |
-> ((thm (* goalstate *) |
2973
d1038e67923a
added a flag (eqvt) to termination proofs arising fron nominal_primrecs
Christian Urban <urbanc@in.tum.de>
parents:
2821
diff
changeset
|
20 |
* (thm -> Nominal_Function_Common.nominal_function_result) (* proof continuation *) |
2665
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
21 |
) * local_theory) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
22 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
23 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
24 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
25 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
26 |
structure Nominal_Function_Mutual: NOMINAL_FUNCTION_MUTUAL = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
27 |
struct |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
28 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
29 |
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>
parents:
2819
diff
changeset
|
30 |
open Function_Common |
2819
4bd584ff4fab
added an option for an invariant (at the moment only a stub)
Christian Urban <urbanc@in.tum.de>
parents:
2781
diff
changeset
|
31 |
open Nominal_Function_Common |
2665
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
32 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
33 |
type qgar = string * (string * typ) list * term list * term list * term |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
34 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
35 |
datatype mutual_part = MutualPart of |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
36 |
{i : int, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
37 |
i' : int, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
38 |
fvar : string * typ, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
39 |
cargTs: typ list, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
40 |
f_def: term, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
41 |
f: term option, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
42 |
f_defthm : thm option} |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
43 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
44 |
datatype mutual_info = Mutual of |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
45 |
{n : int, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
46 |
n' : int, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
47 |
fsum_var : string * typ, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
48 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
49 |
ST: typ, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
50 |
RST: typ, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
51 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
52 |
parts: mutual_part list, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
53 |
fqgars: qgar list, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
54 |
qglrs: ((string * typ) list * term list * term * term) list, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
55 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
56 |
fsum : term option} |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
57 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
58 |
fun mutual_induct_Pnames n = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
59 |
if n < 5 then fst (chop n ["P","Q","R","S"]) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
60 |
else map (fn i => "P" ^ string_of_int i) (1 upto n) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
61 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
62 |
fun get_part fname = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
63 |
the o find_first (fn (MutualPart {fvar=(n,_), ...}) => n = fname) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
64 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
65 |
(* FIXME *) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
66 |
fun mk_prod_abs e (t1, t2) = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
67 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
68 |
val bTs = rev (map snd e) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
69 |
val T1 = fastype_of1 (bTs, t1) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
70 |
val T2 = fastype_of1 (bTs, t2) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
71 |
in |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
72 |
HOLogic.pair_const T1 T2 $ t1 $ t2 |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
73 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
74 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
75 |
fun analyze_eqs ctxt defname fs eqs = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
76 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
77 |
val num = length fs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
78 |
val fqgars = map (split_def ctxt (K true)) eqs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
79 |
val arity_of = map (fn (fname,_,_,args,_) => (fname, length args)) fqgars |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
80 |
|> AList.lookup (op =) #> the |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
81 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
82 |
fun curried_types (fname, fT) = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
83 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
84 |
val (caTs, uaTs) = chop (arity_of fname) (binder_types fT) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
85 |
in |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
86 |
(caTs, uaTs ---> body_type fT) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
87 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
88 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
89 |
val (caTss, resultTs) = split_list (map curried_types fs) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
90 |
val argTs = map (foldr1 HOLogic.mk_prodT) caTss |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
91 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
92 |
val dresultTs = distinct (op =) resultTs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
93 |
val n' = length dresultTs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
94 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
95 |
val RST = Balanced_Tree.make (uncurry SumTree.mk_sumT) dresultTs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
96 |
val ST = Balanced_Tree.make (uncurry SumTree.mk_sumT) argTs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
97 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
98 |
val fsum_type = ST --> RST |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
99 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
100 |
val ([fsum_var_name], _) = Variable.add_fixes [ defname ^ "_sum" ] ctxt |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
101 |
val fsum_var = (fsum_var_name, fsum_type) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
102 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
103 |
fun define (fvar as (n, _)) caTs resultT i = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
104 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
105 |
val vars = map_index (fn (j,T) => Free ("x" ^ string_of_int j, T)) caTs (* FIXME: Bind xs properly *) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
106 |
val i' = find_index (fn Ta => Ta = resultT) dresultTs + 1 |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
107 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
108 |
val f_exp = SumTree.mk_proj RST n' i' (Free fsum_var $ SumTree.mk_inj ST num i (foldr1 HOLogic.mk_prod vars)) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
109 |
val def = Term.abstract_over (Free fsum_var, fold_rev lambda vars f_exp) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
110 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
111 |
val rew = (n, fold_rev lambda vars f_exp) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
112 |
in |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
113 |
(MutualPart {i=i, i'=i', fvar=fvar,cargTs=caTs,f_def=def,f=NONE,f_defthm=NONE}, rew) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
114 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
115 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
116 |
val (parts, rews) = split_list (map4 define fs caTss resultTs (1 upto num)) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
117 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
118 |
fun convert_eqs (f, qs, gs, args, rhs) = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
119 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
120 |
val MutualPart {i, i', ...} = get_part f parts |
2781
542ff50555f5
updated to new Isabelle (> 9 May)
Christian Urban <urbanc@in.tum.de>
parents:
2745
diff
changeset
|
121 |
val rhs' = rhs |
542ff50555f5
updated to new Isabelle (> 9 May)
Christian Urban <urbanc@in.tum.de>
parents:
2745
diff
changeset
|
122 |
|> map_aterms (fn t as Free (n, _) => the_default t (AList.lookup (op =) rews n) | t => t) |
2665
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
123 |
in |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
124 |
(qs, gs, SumTree.mk_inj ST num i (foldr1 (mk_prod_abs qs) args), |
2781
542ff50555f5
updated to new Isabelle (> 9 May)
Christian Urban <urbanc@in.tum.de>
parents:
2745
diff
changeset
|
125 |
Envir.beta_norm (SumTree.mk_inj RST n' i' rhs')) |
2665
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
126 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
127 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
128 |
val qglrs = map convert_eqs fqgars |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
129 |
in |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
130 |
Mutual {n=num, n'=n', fsum_var=fsum_var, ST=ST, RST=RST, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
131 |
parts=parts, fqgars=fqgars, qglrs=qglrs, fsum=NONE} |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
132 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
133 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
134 |
fun define_projections fixes mutual fsum lthy = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
135 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
136 |
fun def ((MutualPart {i=i, i'=i', fvar=(fname, fT), cargTs, f_def, ...}), (_, mixfix)) lthy = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
137 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
138 |
val ((f, (_, f_defthm)), lthy') = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
139 |
Local_Theory.define |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
140 |
((Binding.name fname, mixfix), |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
141 |
((Binding.conceal (Binding.name (fname ^ "_def")), []), |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
142 |
Term.subst_bound (fsum, f_def))) lthy |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
143 |
in |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
144 |
(MutualPart {i=i, i'=i', fvar=(fname, fT), cargTs=cargTs, f_def=f_def, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
145 |
f=SOME f, f_defthm=SOME f_defthm }, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
146 |
lthy') |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
147 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
148 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
149 |
val Mutual { n, n', fsum_var, ST, RST, parts, fqgars, qglrs, ... } = mutual |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
150 |
val (parts', lthy') = fold_map def (parts ~~ fixes) lthy |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
151 |
in |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
152 |
(Mutual { n=n, n'=n', fsum_var=fsum_var, ST=ST, RST=RST, parts=parts', |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
153 |
fqgars=fqgars, qglrs=qglrs, fsum=SOME fsum }, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
154 |
lthy') |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
155 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
156 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
157 |
fun in_context ctxt (f, pre_qs, pre_gs, pre_args, pre_rhs) F = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
158 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
159 |
val thy = ProofContext.theory_of ctxt |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
160 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
161 |
val oqnames = map fst pre_qs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
162 |
val (qs, _) = Variable.variant_fixes oqnames ctxt |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
163 |
|>> map2 (fn (_, T) => fn n => Free (n, T)) pre_qs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
164 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
165 |
fun inst t = subst_bounds (rev qs, t) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
166 |
val gs = map inst pre_gs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
167 |
val args = map inst pre_args |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
168 |
val rhs = inst pre_rhs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
169 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
170 |
val cqs = map (cterm_of thy) qs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
171 |
val ags = map (Thm.assume o cterm_of thy) gs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
172 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
173 |
val import = fold Thm.forall_elim cqs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
174 |
#> fold Thm.elim_implies ags |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
175 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
176 |
val export = fold_rev (Thm.implies_intr o cprop_of) ags |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
177 |
#> fold_rev forall_intr_rename (oqnames ~~ cqs) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
178 |
in |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
179 |
F ctxt (f, qs, gs, args, rhs) import export |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
180 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
181 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
182 |
fun recover_mutual_psimp all_orig_fdefs parts ctxt (fname, _, _, args, rhs) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
183 |
import (export : thm -> thm) sum_psimp_eq = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
184 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
185 |
val (MutualPart {f=SOME f, ...}) = get_part fname parts |
2974
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
186 |
|
2665
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
187 |
val psimp = import sum_psimp_eq |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
188 |
val (simp, restore_cond) = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
189 |
case cprems_of psimp of |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
190 |
[] => (psimp, I) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
191 |
| [cond] => (Thm.implies_elim psimp (Thm.assume cond), Thm.implies_intr cond) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
192 |
| _ => raise General.Fail "Too many conditions" |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
193 |
in |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
194 |
Goal.prove ctxt [] [] |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
195 |
(HOLogic.Trueprop $ HOLogic.mk_eq (list_comb (f, args), rhs)) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
196 |
(fn _ => (Local_Defs.unfold_tac ctxt all_orig_fdefs) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
197 |
THEN EqSubst.eqsubst_tac ctxt [0] [simp] 1 |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
198 |
THEN (simp_tac (simpset_of ctxt)) 1) (* FIXME: global simpset?!! *) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
199 |
|> restore_cond |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
200 |
|> export |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
201 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
202 |
|
2974
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
203 |
fun mk_meqvts ctxt eqvt_thm f_defs = |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
204 |
let |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
205 |
val ctrm1 = eqvt_thm |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
206 |
|> cprop_of |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
207 |
|> snd o Thm.dest_implies |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
208 |
|> Thm.dest_arg |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
209 |
|> Thm.dest_arg1 |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
210 |
|> Thm.dest_arg |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
211 |
|
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
212 |
fun resolve f_def = |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
213 |
let |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
214 |
val ctrm2 = f_def |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
215 |
|> cprop_of |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
216 |
|> Thm.dest_equals_lhs |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
217 |
in |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
218 |
eqvt_thm |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
219 |
|> Thm.instantiate (Thm.match (ctrm1, ctrm2)) |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
220 |
|> simplify (HOL_basic_ss addsimps (@{thm Pair_eqvt} :: @{thms permute_sum.simps})) |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
221 |
|> Local_Defs.unfold ctxt [f_def] |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
222 |
end |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
223 |
in |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
224 |
map resolve f_defs |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
225 |
end |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
226 |
|
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
227 |
|
2665
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
228 |
fun mk_applied_form ctxt caTs thm = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
229 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
230 |
val thy = ProofContext.theory_of ctxt |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
231 |
val xs = map_index (fn (i,T) => cterm_of thy (Free ("x" ^ string_of_int i, T))) caTs (* FIXME: Bind xs properly *) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
232 |
in |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
233 |
fold (fn x => fn thm => Thm.combination thm (Thm.reflexive x)) xs thm |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
234 |
|> Conv.fconv_rule (Thm.beta_conversion true) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
235 |
|> fold_rev Thm.forall_intr xs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
236 |
|> Thm.forall_elim_vars 0 |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
237 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
238 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
239 |
fun mutual_induct_rules lthy induct all_f_defs (Mutual {n, ST, parts, ...}) = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
240 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
241 |
val cert = cterm_of (ProofContext.theory_of lthy) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
242 |
val newPs = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
243 |
map2 (fn Pname => fn MutualPart {cargTs, ...} => |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
244 |
Free (Pname, cargTs ---> HOLogic.boolT)) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
245 |
(mutual_induct_Pnames (length parts)) parts |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
246 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
247 |
fun mk_P (MutualPart {cargTs, ...}) P = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
248 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
249 |
val avars = map_index (fn (i,T) => Var (("a", i), T)) cargTs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
250 |
val atup = foldr1 HOLogic.mk_prod avars |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
251 |
in |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
252 |
HOLogic.tupled_lambda atup (list_comb (P, avars)) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
253 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
254 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
255 |
val Ps = map2 mk_P parts newPs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
256 |
val case_exp = SumTree.mk_sumcases HOLogic.boolT Ps |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
257 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
258 |
val induct_inst = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
259 |
Thm.forall_elim (cert case_exp) induct |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
260 |
|> full_simplify SumTree.sumcase_split_ss |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
261 |
|> full_simplify (HOL_basic_ss addsimps all_f_defs) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
262 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
263 |
fun project rule (MutualPart {cargTs, i, ...}) k = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
264 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
265 |
val afs = map_index (fn (j,T) => Free ("a" ^ string_of_int (j + k), T)) cargTs (* FIXME! *) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
266 |
val inj = SumTree.mk_inj ST n i (foldr1 HOLogic.mk_prod afs) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
267 |
in |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
268 |
(rule |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
269 |
|> Thm.forall_elim (cert inj) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
270 |
|> full_simplify SumTree.sumcase_split_ss |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
271 |
|> fold_rev (Thm.forall_intr o cert) (afs @ newPs), |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
272 |
k + length cargTs) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
273 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
274 |
in |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
275 |
fst (fold_map (project induct_inst) parts 0) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
276 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
277 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
278 |
fun mk_partial_rules_mutual lthy inner_cont (m as Mutual {parts, fqgars, ...}) proof = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
279 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
280 |
val result = inner_cont proof |
2973
d1038e67923a
added a flag (eqvt) to termination proofs arising fron nominal_primrecs
Christian Urban <urbanc@in.tum.de>
parents:
2821
diff
changeset
|
281 |
val NominalFunctionResult {G, R, cases, psimps, simple_pinducts=[simple_pinduct], |
2974
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
282 |
termination, domintros, eqvts=[eqvt],...} = result |
2665
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
283 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
284 |
val (all_f_defs, fs) = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
285 |
map (fn MutualPart {f_defthm = SOME f_def, f = SOME f, cargTs, ...} => |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
286 |
(mk_applied_form lthy cargTs (Thm.symmetric f_def), f)) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
287 |
parts |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
288 |
|> split_list |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
289 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
290 |
val all_orig_fdefs = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
291 |
map (fn MutualPart {f_defthm = SOME f_def, ...} => f_def) parts |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
292 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
293 |
fun mk_mpsimp fqgar sum_psimp = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
294 |
in_context lthy fqgar (recover_mutual_psimp all_orig_fdefs parts) sum_psimp |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
295 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
296 |
val rew_ss = HOL_basic_ss addsimps all_f_defs |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
297 |
val mpsimps = map2 mk_mpsimp fqgars psimps |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
298 |
val minducts = mutual_induct_rules lthy simple_pinduct all_f_defs m |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
299 |
val mtermination = full_simplify rew_ss termination |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
300 |
val mdomintros = Option.map (map (full_simplify rew_ss)) domintros |
2974
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
301 |
val meqvts = mk_meqvts lthy eqvt all_f_defs |
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
302 |
in |
2973
d1038e67923a
added a flag (eqvt) to termination proofs arising fron nominal_primrecs
Christian Urban <urbanc@in.tum.de>
parents:
2821
diff
changeset
|
303 |
NominalFunctionResult { fs=fs, G=G, R=R, |
2665
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
304 |
psimps=mpsimps, simple_pinducts=minducts, |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
305 |
cases=cases, termination=mtermination, |
2974
b95a2065aa10
generated the partial eqvt-theorem for functions
Christian Urban <urbanc@in.tum.de>
parents:
2973
diff
changeset
|
306 |
domintros=mdomintros, eqvts=meqvts } |
2665
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
307 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
308 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
309 |
(* nominal *) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
310 |
fun prepare_nominal_function_mutual config defname fixes eqss lthy = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
311 |
let |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
312 |
val mutual as Mutual {fsum_var=(n, T), qglrs, ...} = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
313 |
analyze_eqs lthy defname (map fst fixes) (map Envir.beta_eta_contract eqss) |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
314 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
315 |
val ((fsum, goalstate, cont), lthy') = |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
316 |
Nominal_Function_Core.prepare_nominal_function config defname [((n, T), NoSyn)] qglrs lthy |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
317 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
318 |
val (mutual', lthy'') = define_projections fixes mutual fsum lthy' |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
319 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
320 |
val mutual_cont = mk_partial_rules_mutual lthy'' cont mutual' |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
321 |
in |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
322 |
((goalstate, mutual_cont), lthy'') |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
323 |
end |
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
324 |
|
16b5a67ee279
exported nominal function code to external file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
325 |
end |