author | Christian Urban <urbanc@in.tum.de> |
Mon, 31 May 2010 19:57:29 +0200 | |
changeset 2304 | 8a98171ba1fc |
parent 2300 | 9fb315392493 |
child 2311 | 4da5c5c29009 |
permissions | -rw-r--r-- |
2297 | 1 |
(* Title: nominal_dt_alpha.ML |
2 |
Author: Cezary Kaliszyk |
|
3 |
Author: Christian Urban |
|
4 |
||
5 |
Definitions of the alpha relations. |
|
6 |
*) |
|
7 |
||
8 |
signature NOMINAL_DT_ALPHA = |
|
9 |
sig |
|
10 |
val define_raw_alpha: Datatype_Aux.descr -> (string * sort) list -> bn_info -> |
|
11 |
bclause list list list -> term list -> Proof.context -> |
|
2298 | 12 |
term list * term list * thm list * thm list * thm * local_theory |
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
13 |
|
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
14 |
val mk_alpha_distincts: Proof.context -> thm list -> thm list list -> |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
15 |
term list -> term list -> bn_info -> thm list * thm list |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
16 |
|
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
17 |
val mk_alpha_eq_iff: Proof.context -> thm list -> thm list -> thm list -> thm list -> thm list |
2297 | 18 |
end |
19 |
||
20 |
structure Nominal_Dt_Alpha: NOMINAL_DT_ALPHA = |
|
21 |
struct |
|
22 |
||
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
23 |
(** definition of the inductive rules for alpha and alpha_bn **) |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
24 |
|
2297 | 25 |
(* construct the compound terms for prod_fv and prod_alpha *) |
26 |
fun mk_prod_fv (t1, t2) = |
|
27 |
let |
|
28 |
val ty1 = fastype_of t1 |
|
29 |
val ty2 = fastype_of t2 |
|
30 |
val resT = HOLogic.mk_prodT (domain_type ty1, domain_type ty2) --> @{typ "atom set"} |
|
31 |
in |
|
32 |
Const (@{const_name "prod_fv"}, [ty1, ty2] ---> resT) $ t1 $ t2 |
|
33 |
end |
|
34 |
||
35 |
fun mk_prod_alpha (t1, t2) = |
|
36 |
let |
|
37 |
val ty1 = fastype_of t1 |
|
38 |
val ty2 = fastype_of t2 |
|
39 |
val prodT = HOLogic.mk_prodT (domain_type ty1, domain_type ty2) |
|
40 |
val resT = [prodT, prodT] ---> @{typ "bool"} |
|
41 |
in |
|
42 |
Const (@{const_name "prod_alpha"}, [ty1, ty2] ---> resT) $ t1 $ t2 |
|
43 |
end |
|
44 |
||
45 |
(* generates the compound binder terms *) |
|
46 |
fun mk_binders lthy bmode args bodies = |
|
47 |
let |
|
48 |
fun bind_set lthy args (NONE, i) = setify lthy (nth args i) |
|
49 |
| bind_set _ args (SOME bn, i) = bn $ (nth args i) |
|
50 |
fun bind_lst lthy args (NONE, i) = listify lthy (nth args i) |
|
51 |
| bind_lst _ args (SOME bn, i) = bn $ (nth args i) |
|
52 |
||
53 |
val (combine_fn, bind_fn) = |
|
54 |
case bmode of |
|
55 |
Lst => (mk_append, bind_lst) |
|
56 |
| Set => (mk_union, bind_set) |
|
57 |
| Res => (mk_union, bind_set) |
|
58 |
in |
|
59 |
foldl1 combine_fn (map (bind_fn lthy args) bodies) |
|
60 |
end |
|
61 |
||
62 |
(* produces the term for an alpha with abstraction *) |
|
63 |
fun mk_alpha_term bmode fv alpha args args' binders binders' = |
|
64 |
let |
|
65 |
val (alpha_name, binder_ty) = |
|
66 |
case bmode of |
|
67 |
Lst => (@{const_name "alpha_lst"}, @{typ "atom list"}) |
|
68 |
| Set => (@{const_name "alpha_gen"}, @{typ "atom set"}) |
|
69 |
| Res => (@{const_name "alpha_res"}, @{typ "atom set"}) |
|
70 |
val ty = fastype_of args |
|
71 |
val pair_ty = HOLogic.mk_prodT (binder_ty, ty) |
|
72 |
val alpha_ty = [ty, ty] ---> @{typ "bool"} |
|
73 |
val fv_ty = ty --> @{typ "atom set"} |
|
74 |
val pair_lhs = HOLogic.mk_prod (binders, args) |
|
75 |
val pair_rhs = HOLogic.mk_prod (binders', args') |
|
76 |
in |
|
77 |
HOLogic.exists_const @{typ perm} $ Abs ("p", @{typ perm}, |
|
78 |
Const (alpha_name, [pair_ty, alpha_ty, fv_ty, @{typ "perm"}, pair_ty] ---> @{typ bool}) |
|
79 |
$ pair_lhs $ alpha $ fv $ (Bound 0) $ pair_rhs) |
|
80 |
end |
|
81 |
||
82 |
(* for non-recursive binders we have to produce alpha_bn premises *) |
|
83 |
fun mk_alpha_bn_prem alpha_bn_map args args' bodies binder = |
|
84 |
case binder of |
|
85 |
(NONE, _) => [] |
|
86 |
| (SOME bn, i) => |
|
87 |
if member (op=) bodies i then [] |
|
88 |
else [the (AList.lookup (op=) alpha_bn_map bn) $ (nth args i) $ (nth args' i)] |
|
89 |
||
90 |
(* generat the premises for an alpha rule; mk_frees is used |
|
91 |
if no binders are present *) |
|
92 |
fun mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args') bclause = |
|
93 |
let |
|
94 |
fun mk_frees i = |
|
95 |
let |
|
96 |
val arg = nth args i |
|
97 |
val arg' = nth args' i |
|
98 |
val ty = fastype_of arg |
|
99 |
in |
|
100 |
if nth is_rec i |
|
101 |
then fst (the (AList.lookup (op=) alpha_map ty)) $ arg $ arg' |
|
102 |
else HOLogic.mk_eq (arg, arg') |
|
103 |
end |
|
104 |
||
105 |
fun mk_alpha_fv i = |
|
106 |
let |
|
107 |
val ty = fastype_of (nth args i) |
|
108 |
in |
|
109 |
case AList.lookup (op=) alpha_map ty of |
|
110 |
NONE => (HOLogic.eq_const ty, supp_const ty) |
|
111 |
| SOME (alpha, fv) => (alpha, fv) |
|
112 |
end |
|
113 |
in |
|
114 |
case bclause of |
|
115 |
BC (_, [], bodies) => map (HOLogic.mk_Trueprop o mk_frees) bodies |
|
116 |
| BC (bmode, binders, bodies) => |
|
117 |
let |
|
118 |
val (alphas, fvs) = split_list (map mk_alpha_fv bodies) |
|
119 |
val comp_fv = foldl1 mk_prod_fv fvs |
|
120 |
val comp_alpha = foldl1 mk_prod_alpha alphas |
|
121 |
val comp_args = foldl1 HOLogic.mk_prod (map (nth args) bodies) |
|
122 |
val comp_args' = foldl1 HOLogic.mk_prod (map (nth args') bodies) |
|
123 |
val comp_binders = mk_binders lthy bmode args binders |
|
124 |
val comp_binders' = mk_binders lthy bmode args' binders |
|
125 |
val alpha_prem = |
|
126 |
mk_alpha_term bmode comp_fv comp_alpha comp_args comp_args' comp_binders comp_binders' |
|
127 |
val alpha_bn_prems = flat (map (mk_alpha_bn_prem alpha_bn_map args args' bodies) binders) |
|
128 |
in |
|
129 |
map HOLogic.mk_Trueprop (alpha_prem::alpha_bn_prems) |
|
130 |
end |
|
131 |
end |
|
132 |
||
133 |
(* produces the introduction rule for an alpha rule *) |
|
134 |
fun mk_alpha_intros lthy alpha_map alpha_bn_map (constr, ty, arg_tys, is_rec) bclauses = |
|
135 |
let |
|
136 |
val arg_names = Datatype_Prop.make_tnames arg_tys |
|
137 |
val arg_names' = Name.variant_list arg_names arg_names |
|
138 |
val args = map Free (arg_names ~~ arg_tys) |
|
139 |
val args' = map Free (arg_names' ~~ arg_tys) |
|
140 |
val alpha = fst (the (AList.lookup (op=) alpha_map ty)) |
|
141 |
val concl = HOLogic.mk_Trueprop (alpha $ list_comb (constr, args) $ list_comb (constr, args')) |
|
142 |
val prems = map (mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args')) bclauses |
|
143 |
in |
|
144 |
Library.foldr Logic.mk_implies (flat prems, concl) |
|
145 |
end |
|
146 |
||
147 |
(* produces the premise of an alpha-bn rule; we only need to |
|
148 |
treat the case special where the binding clause is empty; |
|
149 |
||
150 |
- if the body is not included in the bn_info, then we either |
|
151 |
produce an equation or an alpha-premise |
|
152 |
||
153 |
- if the body is included in the bn_info, then we create |
|
154 |
either a recursive call to alpha-bn, or no premise *) |
|
155 |
fun mk_alpha_bn lthy alpha_map alpha_bn_map bn_args is_rec (args, args') bclause = |
|
156 |
let |
|
157 |
fun mk_alpha_bn_prem alpha_map alpha_bn_map bn_args (args, args') i = |
|
158 |
let |
|
159 |
val arg = nth args i |
|
160 |
val arg' = nth args' i |
|
161 |
val ty = fastype_of arg |
|
162 |
in |
|
163 |
case AList.lookup (op=) bn_args i of |
|
164 |
NONE => (case (AList.lookup (op=) alpha_map ty) of |
|
165 |
NONE => [HOLogic.mk_eq (arg, arg')] |
|
166 |
| SOME (alpha, _) => [alpha $ arg $ arg']) |
|
167 |
| SOME (NONE) => [] |
|
168 |
| SOME (SOME bn) => [the (AList.lookup (op=) alpha_bn_map bn) $ arg $ arg'] |
|
169 |
end |
|
170 |
in |
|
171 |
case bclause of |
|
172 |
BC (_, [], bodies) => |
|
173 |
map HOLogic.mk_Trueprop |
|
174 |
(flat (map (mk_alpha_bn_prem alpha_map alpha_bn_map bn_args (args, args')) bodies)) |
|
175 |
| _ => mk_alpha_prems lthy alpha_map alpha_bn_map is_rec (args, args') bclause |
|
176 |
end |
|
177 |
||
178 |
fun mk_alpha_bn_intro lthy bn_trm alpha_map alpha_bn_map (bn_args, (constr, _, arg_tys, is_rec)) bclauses = |
|
179 |
let |
|
180 |
val arg_names = Datatype_Prop.make_tnames arg_tys |
|
181 |
val arg_names' = Name.variant_list arg_names arg_names |
|
182 |
val args = map Free (arg_names ~~ arg_tys) |
|
183 |
val args' = map Free (arg_names' ~~ arg_tys) |
|
184 |
val alpha_bn = the (AList.lookup (op=) alpha_bn_map bn_trm) |
|
185 |
val concl = HOLogic.mk_Trueprop (alpha_bn $ list_comb (constr, args) $ list_comb (constr, args')) |
|
186 |
val prems = map (mk_alpha_bn lthy alpha_map alpha_bn_map bn_args is_rec (args, args')) bclauses |
|
187 |
in |
|
188 |
Library.foldr Logic.mk_implies (flat prems, concl) |
|
189 |
end |
|
190 |
||
191 |
fun mk_alpha_bn_intros lthy alpha_map alpha_bn_map constrs_info bclausesss (bn_trm, bn_n, bn_argss) = |
|
192 |
let |
|
193 |
val nth_constrs_info = nth constrs_info bn_n |
|
194 |
val nth_bclausess = nth bclausesss bn_n |
|
195 |
in |
|
196 |
map2 (mk_alpha_bn_intro lthy bn_trm alpha_map alpha_bn_map) (bn_argss ~~ nth_constrs_info) nth_bclausess |
|
197 |
end |
|
198 |
||
199 |
fun define_raw_alpha descr sorts bn_info bclausesss fvs lthy = |
|
200 |
let |
|
201 |
val alpha_names = prefix_dt_names descr sorts "alpha_" |
|
202 |
val alpha_arg_tys = all_dtyps descr sorts |
|
203 |
val alpha_tys = map (fn ty => [ty, ty] ---> @{typ bool}) alpha_arg_tys |
|
204 |
val alpha_frees = map Free (alpha_names ~~ alpha_tys) |
|
205 |
val alpha_map = alpha_arg_tys ~~ (alpha_frees ~~ fvs) |
|
206 |
||
207 |
val (bns, bn_tys) = split_list (map (fn (bn, i, _) => (bn, i)) bn_info) |
|
208 |
val bn_names = map (fn bn => Long_Name.base_name (fst (dest_Const bn))) bns |
|
209 |
val alpha_bn_names = map (prefix "alpha_") bn_names |
|
210 |
val alpha_bn_arg_tys = map (fn i => nth_dtyp descr sorts i) bn_tys |
|
211 |
val alpha_bn_tys = map (fn ty => [ty, ty] ---> @{typ "bool"}) alpha_bn_arg_tys |
|
212 |
val alpha_bn_frees = map Free (alpha_bn_names ~~ alpha_bn_tys) |
|
213 |
val alpha_bn_map = bns ~~ alpha_bn_frees |
|
214 |
||
215 |
val constrs_info = all_dtyp_constrs_types descr sorts |
|
216 |
||
217 |
val alpha_intros = map2 (map2 (mk_alpha_intros lthy alpha_map alpha_bn_map)) constrs_info bclausesss |
|
218 |
val alpha_bn_intros = map (mk_alpha_bn_intros lthy alpha_map alpha_bn_map constrs_info bclausesss) bn_info |
|
219 |
||
2299 | 220 |
val all_alpha_names = map (fn (a, ty) => ((Binding.name a, ty), NoSyn)) |
221 |
(alpha_names @ alpha_bn_names ~~ alpha_tys @ alpha_bn_tys) |
|
2297 | 222 |
val all_alpha_intros = map (pair Attrib.empty_binding) (flat alpha_intros @ flat alpha_bn_intros) |
223 |
||
224 |
val (alphas, lthy') = Inductive.add_inductive_i |
|
225 |
{quiet_mode = true, verbose = false, alt_name = Binding.empty, |
|
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
226 |
coind = false, no_elim = false, no_ind = false, skip_mono = false, fork_mono = false} |
2297 | 227 |
all_alpha_names [] all_alpha_intros [] lthy |
228 |
||
2298 | 229 |
val all_alpha_trms_loc = #preds alphas; |
2297 | 230 |
val alpha_induct_loc = #raw_induct alphas; |
231 |
val alpha_intros_loc = #intrs alphas; |
|
232 |
val alpha_cases_loc = #elims alphas; |
|
233 |
val phi = ProofContext.export_morphism lthy' lthy; |
|
234 |
||
2298 | 235 |
val all_alpha_trms = map (Morphism.term phi) all_alpha_trms_loc; |
2297 | 236 |
val alpha_induct = Morphism.thm phi alpha_induct_loc; |
237 |
val alpha_intros = map (Morphism.thm phi) alpha_intros_loc |
|
238 |
val alpha_cases = map (Morphism.thm phi) alpha_cases_loc |
|
2298 | 239 |
|
240 |
val (alpha_trms, alpha_bn_trms) = chop (length fvs) all_alpha_trms |
|
2297 | 241 |
in |
2298 | 242 |
(alpha_trms, alpha_bn_trms, alpha_intros, alpha_cases, alpha_induct, lthy') |
2297 | 243 |
end |
244 |
||
2300
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
245 |
|
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
246 |
(** produces the distinctness theorems **) |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
247 |
|
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
248 |
(* transforms the distinctness theorems of the constructors |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
249 |
to "not-alphas" of the constructors *) |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
250 |
fun mk_alpha_distinct_goal alpha neq = |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
251 |
let |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
252 |
val (lhs, rhs) = |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
253 |
neq |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
254 |
|> HOLogic.dest_Trueprop |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
255 |
|> HOLogic.dest_not |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
256 |
|> HOLogic.dest_eq |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
257 |
in |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
258 |
alpha $ lhs $ rhs |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
259 |
|> HOLogic.mk_not |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
260 |
|> HOLogic.mk_Trueprop |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
261 |
end |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
262 |
|
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
263 |
fun distinct_tac cases distinct_thms = |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
264 |
rtac notI THEN' eresolve_tac cases |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
265 |
THEN_ALL_NEW asm_full_simp_tac (HOL_ss addsimps distinct_thms) |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
266 |
|
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
267 |
fun mk_alpha_distinct ctxt cases_thms (distinct_thm, alpha) = |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
268 |
let |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
269 |
val ((_, thms), ctxt') = Variable.import false distinct_thm ctxt |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
270 |
val goals = map (mk_alpha_distinct_goal alpha o prop_of) thms |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
271 |
val nrels = map (fn t => Goal.prove ctxt' [] [] t (K (distinct_tac cases_thms distinct_thm 1))) goals |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
272 |
in |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
273 |
Variable.export ctxt' ctxt nrels |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
274 |
end |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
275 |
|
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
276 |
fun mk_alpha_distincts ctxt alpha_cases constrs_distinct_thms alpha_trms alpha_bn_trms bn_infos = |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
277 |
let |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
278 |
val alpha_distincts = |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
279 |
map (mk_alpha_distinct ctxt alpha_cases) (constrs_distinct_thms ~~ alpha_trms) |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
280 |
val distinc_thms = map |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
281 |
val alpha_bn_distincts_aux = map (fn (_, i, _) => nth constrs_distinct_thms i) bn_infos |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
282 |
val alpha_bn_distincts = |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
283 |
map (mk_alpha_distinct ctxt alpha_cases) (alpha_bn_distincts_aux ~~ alpha_bn_trms) |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
284 |
in |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
285 |
(flat alpha_distincts, flat alpha_bn_distincts) |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
286 |
end |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
287 |
|
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
288 |
|
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
289 |
(** produces the alpha_eq_iff simplification rules **) |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
290 |
|
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
291 |
(* in case a theorem is of the form (C.. = C..), it will be |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
292 |
rewritten to ((C.. = C..) = True) *) |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
293 |
fun mk_simp_rule thm = |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
294 |
case (prop_of thm) of |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
295 |
@{term "Trueprop"} $ (Const (@{const_name "op ="}, _) $ _ $ _) => @{thm eqTrueI} OF [thm] |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
296 |
| _ => thm |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
297 |
|
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
298 |
fun alpha_eq_iff_tac dist_inj intros elims = |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
299 |
SOLVED' (asm_full_simp_tac (HOL_ss addsimps intros)) ORELSE' |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
300 |
(rtac @{thm iffI} THEN' |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
301 |
RANGE [eresolve_tac elims THEN_ALL_NEW asm_full_simp_tac (HOL_ss addsimps dist_inj), |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
302 |
asm_full_simp_tac (HOL_ss addsimps intros)]) |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
303 |
|
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
304 |
fun mk_alpha_eq_iff_goal thm = |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
305 |
let |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
306 |
val prop = prop_of thm; |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
307 |
val concl = HOLogic.dest_Trueprop (Logic.strip_imp_concl prop); |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
308 |
val hyps = map HOLogic.dest_Trueprop (Logic.strip_imp_prems prop); |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
309 |
fun list_conj l = foldr1 HOLogic.mk_conj l; |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
310 |
in |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
311 |
if hyps = [] then HOLogic.mk_Trueprop concl |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
312 |
else HOLogic.mk_Trueprop (HOLogic.mk_eq (concl, list_conj hyps)) |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
313 |
end; |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
314 |
|
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
315 |
fun mk_alpha_eq_iff ctxt alpha_intros distinct_thms inject_thms alpha_elims = |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
316 |
let |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
317 |
val ((_, thms_imp), ctxt') = Variable.import false alpha_intros ctxt; |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
318 |
val goals = map mk_alpha_eq_iff_goal thms_imp; |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
319 |
val tac = alpha_eq_iff_tac (distinct_thms @ inject_thms) alpha_intros alpha_elims 1; |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
320 |
val thms = map (fn goal => Goal.prove ctxt' [] [] goal (K tac)) goals; |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
321 |
in |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
322 |
Variable.export ctxt' ctxt thms |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
323 |
|> map mk_simp_rule |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
324 |
end |
9fb315392493
added FSet to the correct paper
Christian Urban <urbanc@in.tum.de>
parents:
2299
diff
changeset
|
325 |
|
2297 | 326 |
end (* structure *) |
327 |