| author | urbanc | 
| Sun, 26 Feb 2006 22:24:05 +0100 | |
| changeset 19139 | af69e41eab5d | 
| parent 18434 | a31e52a3e6ef | 
| child 19144 | 9c8793c62d0c | 
| permissions | -rw-r--r-- | 
| 17870 | 1  | 
(* $Id$ *)  | 
2  | 
||
3  | 
(* METHOD FOR ANALYSING EQUATION INVOLVING PERMUTATION *)  | 
|
4  | 
||
5  | 
local  | 
|
6  | 
||
| 18012 | 7  | 
(* pulls out dynamically a thm via the simpset *)  | 
| 
18434
 
a31e52a3e6ef
fixed a bug that occured when more than one atom-type
 
urbanc 
parents: 
18279 
diff
changeset
 | 
8  | 
fun dynamic_thms ss name =  | 
| 
 
a31e52a3e6ef
fixed a bug that occured when more than one atom-type
 
urbanc 
parents: 
18279 
diff
changeset
 | 
9  | 
ProofContext.get_thms (Simplifier.the_context ss) (Name name);  | 
| 19139 | 10  | 
fun dynamic_thm ss name =  | 
11  | 
ProofContext.get_thm (Simplifier.the_context ss) (Name name);  | 
|
| 18012 | 12  | 
|
| 19139 | 13  | 
(* FIXME: make it usable for all atom-types *)  | 
| 18012 | 14  | 
(* initial simplification step in the tactic *)  | 
| 19139 | 15  | 
fun perm_eval_tac ss i =  | 
| 18012 | 16  | 
let  | 
| 19139 | 17  | 
val perm_eq_app = thm "nominal.pt_fun_app_eq";  | 
18  | 
val at_inst = dynamic_thm ss "at_name_inst";  | 
|
19  | 
val pt_inst = dynamic_thm ss "pt_name_inst";  | 
|
20  | 
||
21  | 
fun perm_eval_simproc sg ss redex =  | 
|
22  | 
(case redex of  | 
|
23  | 
(* case pi o (f x) == (pi o f) (pi o x) *)  | 
|
24  | 
(* special treatment in cases of constants *)  | 
|
25  | 
        (Const("nominal.perm",Type("fun",[Type("List.list",[Type("*",[ty,_])]),_])) $ pi $ (f $ x)) 
 | 
|
26  | 
=> let  | 
|
27  | 
             val _ = warning ("type: "^Sign.string_of_typ (sign_of (the_context())) ty)
 | 
|
28  | 
in  | 
|
29  | 
||
30  | 
(case f of  | 
|
31  | 
(* nothing to do on constants *)  | 
|
32  | 
(* FIXME: proper treatment of constants *)  | 
|
33  | 
Const(_,_) => NONE  | 
|
34  | 
| (Const(_,_) $ _) => NONE  | 
|
35  | 
| ((Const(_,_) $ _) $ _) => NONE  | 
|
36  | 
| (((Const(_,_) $ _) $ _) $ _) => NONE  | 
|
37  | 
| _ =>  | 
|
38  | 
(* FIXME: analyse type here or at "pty"*)  | 
|
39  | 
SOME ((at_inst RS (pt_inst RS perm_eq_app)) RS eq_reflection))  | 
|
40  | 
end  | 
|
41  | 
||
42  | 
(* case pi o (%x. f x) == (%x. pi o (f ((rev pi)o x))) *)  | 
|
43  | 
        | (Const("nominal.perm",_) $ pi $ (Abs _)) 
 | 
|
44  | 
=> let  | 
|
45  | 
val perm_fun_def = thm "nominal.perm_fun_def"  | 
|
46  | 
in SOME (perm_fun_def) end  | 
|
47  | 
||
48  | 
(* no redex otherwise *)  | 
|
49  | 
| _ => NONE);  | 
|
50  | 
||
51  | 
val perm_eval =  | 
|
52  | 
Simplifier.simproc (Theory.sign_of (the_context ())) "perm_eval"  | 
|
53  | 
["nominal.perm pi x"] perm_eval_simproc;  | 
|
54  | 
||
| 
18279
 
f7a18e2b10fc
made some of the theorem look-ups static (by using
 
urbanc 
parents: 
18052 
diff
changeset
 | 
55  | 
(* these lemmas are created dynamically according to the atom types *)  | 
| 19139 | 56  | 
val perm_swap = dynamic_thms ss "perm_swap";  | 
57  | 
val perm_fresh = dynamic_thms ss "perm_fresh_fresh";  | 
|
58  | 
val perm_bij = dynamic_thms ss "perm_bij";  | 
|
59  | 
val perm_compose' = dynamic_thms ss "perm_compose'";  | 
|
60  | 
val perm_pi_simp = dynamic_thms ss "perm_pi_simp";  | 
|
61  | 
val ss' = ss addsimps (perm_swap@perm_fresh@perm_bij@perm_compose'@perm_pi_simp)  | 
|
62  | 
addsimprocs [perm_eval];  | 
|
63  | 
||
| 18012 | 64  | 
in  | 
65  | 
      ("general simplification step", FIRST [rtac conjI i, asm_full_simp_tac ss' i])
 | 
|
66  | 
end;  | 
|
| 17870 | 67  | 
|
| 
18434
 
a31e52a3e6ef
fixed a bug that occured when more than one atom-type
 
urbanc 
parents: 
18279 
diff
changeset
 | 
68  | 
(* applies the perm_compose rule - this rule would loop in the simplifier *)  | 
| 
 
a31e52a3e6ef
fixed a bug that occured when more than one atom-type
 
urbanc 
parents: 
18279 
diff
changeset
 | 
69  | 
(* in case there are more atom-types we have to check every possible instance *)  | 
| 19139 | 70  | 
(* of perm_compose *)  | 
| 18012 | 71  | 
fun apply_perm_compose_tac ss i =  | 
72  | 
let  | 
|
| 
18434
 
a31e52a3e6ef
fixed a bug that occured when more than one atom-type
 
urbanc 
parents: 
18279 
diff
changeset
 | 
73  | 
val perm_compose = dynamic_thms ss "perm_compose";  | 
| 
 
a31e52a3e6ef
fixed a bug that occured when more than one atom-type
 
urbanc 
parents: 
18279 
diff
changeset
 | 
74  | 
val tacs = map (fn thm => (rtac (thm RS trans) i)) perm_compose  | 
| 18012 | 75  | 
in  | 
| 
18434
 
a31e52a3e6ef
fixed a bug that occured when more than one atom-type
 
urbanc 
parents: 
18279 
diff
changeset
 | 
76  | 
	("analysing permutation compositions on the lhs",FIRST (tacs))
 | 
| 18012 | 77  | 
end  | 
78  | 
||
79  | 
(* applying Stefan's smart congruence tac *)  | 
|
80  | 
fun apply_cong_tac i =  | 
|
81  | 
    ("application of congruence",
 | 
|
82  | 
(fn st => DatatypeAux.cong_tac i st handle Subscript => no_tac st));  | 
|
| 17870 | 83  | 
|
84  | 
(* unfolds the definition of permutations applied to functions *)  | 
|
| 18012 | 85  | 
fun unfold_perm_fun_def_tac i =  | 
86  | 
let  | 
|
87  | 
val perm_fun_def = thm "nominal.perm_fun_def"  | 
|
88  | 
in  | 
|
89  | 
	("unfolding of permutations on functions", 
 | 
|
90  | 
simp_tac (HOL_basic_ss addsimps [perm_fun_def]) i)  | 
|
| 17870 | 91  | 
end  | 
92  | 
||
| 18012 | 93  | 
(* applies the expand_fun_eq rule to the first goal and strips off all universal quantifiers *)  | 
94  | 
fun expand_fun_eq_tac i =  | 
|
95  | 
    ("extensionality expansion of functions",
 | 
|
96  | 
EVERY [simp_tac (HOL_basic_ss addsimps [expand_fun_eq]) i, REPEAT_DETERM (rtac allI i)]);  | 
|
| 17870 | 97  | 
|
98  | 
(* debugging *)  | 
|
99  | 
fun DEBUG_tac (msg,tac) =  | 
|
| 18012 | 100  | 
    EVERY [CHANGED tac, print_tac ("after "^msg)]; 
 | 
| 17870 | 101  | 
fun NO_DEBUG_tac (_,tac) = CHANGED tac;  | 
102  | 
||
103  | 
(* Main Tactic *)  | 
|
| 18012 | 104  | 
|
105  | 
fun perm_simp_tac tactical ss i =  | 
|
| 19139 | 106  | 
DETERM (tactical (perm_eval_tac ss i));  | 
107  | 
||
108  | 
(* perm_simp_tac plus additional tactics to decide *)  | 
|
109  | 
(* support problems *)  | 
|
110  | 
(* the "repeating"-depth is set to 40 - this seems sufficient *)  | 
|
111  | 
fun perm_supports_tac tactical ss i =  | 
|
| 18012 | 112  | 
DETERM (REPEAT_DETERM_N 40  | 
| 19139 | 113  | 
(FIRST[tactical (perm_eval_tac ss i),  | 
| 18012 | 114  | 
tactical (apply_perm_compose_tac ss i),  | 
115  | 
tactical (apply_cong_tac i),  | 
|
116  | 
tactical (unfold_perm_fun_def_tac i),  | 
|
117  | 
tactical (expand_fun_eq_tac i)]));  | 
|
| 17870 | 118  | 
|
| 19139 | 119  | 
(* tactic that first unfolds the support definition *)  | 
120  | 
(* and strips off the intros, then applies perm_supports_tac *)  | 
|
| 18012 | 121  | 
fun supports_tac tactical ss i =  | 
122  | 
let  | 
|
123  | 
val supports_def = thm "nominal.op supports_def";  | 
|
124  | 
val fresh_def = thm "nominal.fresh_def";  | 
|
125  | 
val fresh_prod = thm "nominal.fresh_prod";  | 
|
126  | 
val simps = [supports_def,symmetric fresh_def,fresh_prod]  | 
|
| 17870 | 127  | 
in  | 
| 18012 | 128  | 
      EVERY [tactical ("unfolding of supports ",simp_tac (HOL_basic_ss addsimps simps) i),
 | 
129  | 
             tactical ("stripping of foralls  " ,REPEAT_DETERM (rtac allI i)),
 | 
|
130  | 
             tactical ("geting rid of the imps",rtac impI i),
 | 
|
131  | 
             tactical ("eliminating conjuncts ",REPEAT_DETERM (etac  conjE i)),
 | 
|
| 19139 | 132  | 
             tactical ("applying perm_simp    ",perm_supports_tac tactical ss i)]
 | 
| 17870 | 133  | 
end;  | 
134  | 
||
135  | 
in  | 
|
136  | 
||
137  | 
||
| 18012 | 138  | 
fun simp_meth_setup tac =  | 
| 
18046
 
b7389981170b
Changed Simplifier.simp_modifiers to Simplifier.simp_modifiers'.
 
urbanc 
parents: 
18012 
diff
changeset
 | 
139  | 
Method.only_sectioned_args (Simplifier.simp_modifiers' @ Splitter.split_modifiers)  | 
| 18012 | 140  | 
(Method.SIMPLE_METHOD' HEADGOAL o tac o local_simpset_of);  | 
| 17870 | 141  | 
|
| 18012 | 142  | 
val perm_eq_meth = simp_meth_setup (perm_simp_tac NO_DEBUG_tac);  | 
143  | 
val perm_eq_meth_debug = simp_meth_setup (perm_simp_tac DEBUG_tac);  | 
|
144  | 
val supports_meth = simp_meth_setup (supports_tac NO_DEBUG_tac);  | 
|
145  | 
val supports_meth_debug = simp_meth_setup (supports_tac DEBUG_tac);  | 
|
| 17870 | 146  | 
|
147  | 
end  | 
|
148  | 
||
149  | 
||
150  |