author | urbanc |
Wed, 01 Mar 2006 10:27:01 +0100 | |
changeset 19163 | b61039bf141f |
parent 19151 | 66e841b1001e |
child 19169 | 20a73345dd6e |
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 |
fun perm_eval_simproc sg ss redex = |
18 |
(case redex of |
|
19163 | 19 |
(* case pi o (f x) == (pi o f) (pi o x) *) |
20 |
(* special treatment when head of f is a constants *) |
|
19144 | 21 |
(Const("nominal.perm", |
22 |
Type("fun",[Type("List.list",[Type("*",[Type(n,_),_])]),_])) $ pi $ (f $ x)) => |
|
23 |
(case (head_of f) of |
|
19163 | 24 |
Const _ => NONE (* nothing to do on constants *) |
25 |
| _ => |
|
26 |
let |
|
27 |
val name = Sign.base_name n |
|
28 |
val at_inst = dynamic_thm ss ("at_"^name^"_inst") |
|
29 |
val pt_inst = dynamic_thm ss ("pt_"^name^"_inst") |
|
30 |
val perm_eq_app = thm "nominal.pt_fun_app_eq" |
|
31 |
in SOME ((at_inst RS (pt_inst RS perm_eq_app)) RS eq_reflection) end) |
|
19139 | 32 |
|
33 |
(* case pi o (%x. f x) == (%x. pi o (f ((rev pi)o x))) *) |
|
19144 | 34 |
| (Const("nominal.perm",_) $ pi $ (Abs _)) => |
35 |
let |
|
19163 | 36 |
val perm_fun_def = thm "nominal.perm_fun_def" |
19139 | 37 |
in SOME (perm_fun_def) end |
38 |
||
39 |
(* no redex otherwise *) |
|
40 |
| _ => NONE); |
|
41 |
||
42 |
val perm_eval = |
|
43 |
Simplifier.simproc (Theory.sign_of (the_context ())) "perm_eval" |
|
44 |
["nominal.perm pi x"] perm_eval_simproc; |
|
45 |
||
18279
f7a18e2b10fc
made some of the theorem look-ups static (by using
urbanc
parents:
18052
diff
changeset
|
46 |
(* these lemmas are created dynamically according to the atom types *) |
19163 | 47 |
val perm_swap = dynamic_thms ss "perm_swap" |
48 |
val perm_fresh = dynamic_thms ss "perm_fresh_fresh" |
|
49 |
val perm_bij = dynamic_thms ss "perm_bij" |
|
50 |
val perm_compose' = dynamic_thms ss "perm_compose'" |
|
51 |
val perm_pi_simp = dynamic_thms ss "perm_pi_simp" |
|
19139 | 52 |
val ss' = ss addsimps (perm_swap@perm_fresh@perm_bij@perm_compose'@perm_pi_simp) |
18012 | 53 |
in |
19163 | 54 |
("general simplification step", |
55 |
FIRST [rtac conjI i, asm_full_simp_tac (ss' addsimprocs [perm_eval]) i]) |
|
18012 | 56 |
end; |
17870 | 57 |
|
18434
a31e52a3e6ef
fixed a bug that occured when more than one atom-type
urbanc
parents:
18279
diff
changeset
|
58 |
(* 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
|
59 |
(* in case there are more atom-types we have to check every possible instance *) |
19139 | 60 |
(* of perm_compose *) |
18012 | 61 |
fun apply_perm_compose_tac ss i = |
62 |
let |
|
18434
a31e52a3e6ef
fixed a bug that occured when more than one atom-type
urbanc
parents:
18279
diff
changeset
|
63 |
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
|
64 |
val tacs = map (fn thm => (rtac (thm RS trans) i)) perm_compose |
18012 | 65 |
in |
18434
a31e52a3e6ef
fixed a bug that occured when more than one atom-type
urbanc
parents:
18279
diff
changeset
|
66 |
("analysing permutation compositions on the lhs",FIRST (tacs)) |
18012 | 67 |
end |
68 |
||
69 |
(* applying Stefan's smart congruence tac *) |
|
70 |
fun apply_cong_tac i = |
|
71 |
("application of congruence", |
|
72 |
(fn st => DatatypeAux.cong_tac i st handle Subscript => no_tac st)); |
|
17870 | 73 |
|
74 |
(* unfolds the definition of permutations applied to functions *) |
|
18012 | 75 |
fun unfold_perm_fun_def_tac i = |
76 |
let |
|
77 |
val perm_fun_def = thm "nominal.perm_fun_def" |
|
78 |
in |
|
79 |
("unfolding of permutations on functions", |
|
80 |
simp_tac (HOL_basic_ss addsimps [perm_fun_def]) i) |
|
17870 | 81 |
end |
82 |
||
18012 | 83 |
(* applies the expand_fun_eq rule to the first goal and strips off all universal quantifiers *) |
84 |
fun expand_fun_eq_tac i = |
|
85 |
("extensionality expansion of functions", |
|
86 |
EVERY [simp_tac (HOL_basic_ss addsimps [expand_fun_eq]) i, REPEAT_DETERM (rtac allI i)]); |
|
17870 | 87 |
|
88 |
(* debugging *) |
|
89 |
fun DEBUG_tac (msg,tac) = |
|
18012 | 90 |
EVERY [CHANGED tac, print_tac ("after "^msg)]; |
17870 | 91 |
fun NO_DEBUG_tac (_,tac) = CHANGED tac; |
92 |
||
93 |
(* Main Tactic *) |
|
18012 | 94 |
|
95 |
fun perm_simp_tac tactical ss i = |
|
19139 | 96 |
DETERM (tactical (perm_eval_tac ss i)); |
97 |
||
19151 | 98 |
|
99 |
(* perm_simp_tac plus additional tactics to decide *) |
|
100 |
(* support problems *) |
|
19163 | 101 |
(* the "recursion"-depth is set to 10 - this seems sufficient *) |
19151 | 102 |
fun perm_supports_tac tactical ss n = |
103 |
if n=0 then K all_tac |
|
104 |
else DETERM o |
|
105 |
(FIRST'[fn i => tactical (perm_eval_tac ss i), |
|
19163 | 106 |
fn i => tactical (apply_perm_compose_tac ss i), |
107 |
fn i => tactical (apply_cong_tac i), |
|
108 |
fn i => tactical (unfold_perm_fun_def_tac i), |
|
109 |
fn i => tactical (expand_fun_eq_tac i)] |
|
19151 | 110 |
THEN_ALL_NEW (TRY o (perm_supports_tac tactical ss (n-1)))); |
17870 | 111 |
|
19139 | 112 |
(* tactic that first unfolds the support definition *) |
113 |
(* and strips off the intros, then applies perm_supports_tac *) |
|
18012 | 114 |
fun supports_tac tactical ss i = |
115 |
let |
|
116 |
val supports_def = thm "nominal.op supports_def"; |
|
117 |
val fresh_def = thm "nominal.fresh_def"; |
|
118 |
val fresh_prod = thm "nominal.fresh_prod"; |
|
119 |
val simps = [supports_def,symmetric fresh_def,fresh_prod] |
|
17870 | 120 |
in |
19151 | 121 |
EVERY [tactical ("unfolding of supports ", simp_tac (HOL_basic_ss addsimps simps) i), |
122 |
tactical ("stripping of foralls ", REPEAT_DETERM (rtac allI i)), |
|
123 |
tactical ("geting rid of the imps", rtac impI i), |
|
124 |
tactical ("eliminating conjuncts ", REPEAT_DETERM (etac conjE i)), |
|
125 |
tactical ("applying perm_simp ", perm_supports_tac tactical ss 10 i)] |
|
17870 | 126 |
end; |
127 |
||
19151 | 128 |
|
129 |
(* tactic that guesses the finite-support of a goal *) |
|
130 |
||
131 |
fun collect_vars i (Bound j) vs = if j < i then vs else Bound (j - i) ins vs |
|
132 |
| collect_vars i (v as Free _) vs = v ins vs |
|
133 |
| collect_vars i (v as Var _) vs = v ins vs |
|
134 |
| collect_vars i (Const _) vs = vs |
|
135 |
| collect_vars i (Abs (_, _, t)) vs = collect_vars (i+1) t vs |
|
136 |
| collect_vars i (t $ u) vs = collect_vars i u (collect_vars i t vs); |
|
137 |
||
138 |
val supports_rule = thm "supports_finite"; |
|
139 |
||
140 |
fun finite_guess_tac tactical ss i st = |
|
141 |
let val goal = List.nth(cprems_of st, i-1) |
|
142 |
in |
|
143 |
case Logic.strip_assums_concl (term_of goal) of |
|
144 |
_ $ (Const ("op :", _) $ (Const ("nominal.supp", T) $ x) $ |
|
145 |
Const ("Finite_Set.Finites", _)) => |
|
146 |
let |
|
147 |
val cert = Thm.cterm_of (sign_of_thm st); |
|
148 |
val ps = Logic.strip_params (term_of goal); |
|
149 |
val Ts = rev (map snd ps); |
|
150 |
val vs = collect_vars 0 x []; |
|
151 |
val s = foldr (fn (v, s) => |
|
152 |
HOLogic.pair_const (fastype_of1 (Ts, v)) (fastype_of1 (Ts, s)) $ v $ s) |
|
153 |
HOLogic.unit vs; |
|
154 |
val s' = list_abs (ps, |
|
155 |
Const ("nominal.supp", fastype_of1 (Ts, s) --> body_type T) $ s); |
|
156 |
val supports_rule' = Thm.lift_rule goal supports_rule; |
|
157 |
val _ $ (_ $ S $ _) = |
|
158 |
Logic.strip_assums_concl (hd (prems_of supports_rule')); |
|
159 |
val supports_rule'' = Drule.cterm_instantiate |
|
160 |
[(cert (head_of S), cert s')] supports_rule' |
|
161 |
in |
|
162 |
(tactical ("guessing of the right supports-set", |
|
163 |
EVERY [compose_tac (false, supports_rule'', 2) i, |
|
164 |
asm_full_simp_tac ss (i+1), |
|
165 |
supports_tac tactical ss i])) st |
|
166 |
end |
|
167 |
| _ => Seq.empty |
|
168 |
end |
|
169 |
handle Subscript => Seq.empty |
|
170 |
||
17870 | 171 |
in |
172 |
||
173 |
||
18012 | 174 |
fun simp_meth_setup tac = |
18046
b7389981170b
Changed Simplifier.simp_modifiers to Simplifier.simp_modifiers'.
urbanc
parents:
18012
diff
changeset
|
175 |
Method.only_sectioned_args (Simplifier.simp_modifiers' @ Splitter.split_modifiers) |
18012 | 176 |
(Method.SIMPLE_METHOD' HEADGOAL o tac o local_simpset_of); |
17870 | 177 |
|
19151 | 178 |
val perm_eq_meth = simp_meth_setup (perm_simp_tac NO_DEBUG_tac); |
179 |
val perm_eq_meth_debug = simp_meth_setup (perm_simp_tac DEBUG_tac); |
|
180 |
val supports_meth = simp_meth_setup (supports_tac NO_DEBUG_tac); |
|
181 |
val supports_meth_debug = simp_meth_setup (supports_tac DEBUG_tac); |
|
182 |
val finite_gs_meth = simp_meth_setup (finite_guess_tac NO_DEBUG_tac); |
|
183 |
val finite_gs_meth_debug = simp_meth_setup (finite_guess_tac DEBUG_tac); |
|
17870 | 184 |
|
185 |
end |
|
186 |
||
187 |
||
188 |