author | wenzelm |
Wed, 21 Sep 1994 15:40:41 +0200 | |
changeset 145 | a9f7ff3a464c |
parent 129 | 0bba840aa07c |
child 198 | 663cead79989 |
permissions | -rw-r--r-- |
1 | 1 |
(* Title: HOL/simpdata.ML |
2 |
ID: $Id$ |
|
3 |
Author: Tobias Nipkow |
|
4 |
Copyright 1991 University of Cambridge |
|
5 |
||
6 |
Instantiation of the generic simplifier |
|
7 |
*) |
|
8 |
||
0 | 9 |
open Simplifier; |
10 |
||
11 |
local |
|
12 |
||
13 |
fun prover s = prove_goal HOL.thy s (fn _ => [fast_tac HOL_cs 1]); |
|
14 |
||
15 |
val P_imp_P_iff_True = prover "P --> (P = True)" RS mp; |
|
16 |
val P_imp_P_eq_True = P_imp_P_iff_True RS eq_reflection; |
|
17 |
||
18 |
val not_P_imp_P_iff_F = prover "~P --> (P = False)" RS mp; |
|
19 |
val not_P_imp_P_eq_False = not_P_imp_P_iff_F RS eq_reflection; |
|
20 |
||
129 | 21 |
fun atomize pairs = |
22 |
let fun atoms th = |
|
23 |
(case concl_of th of |
|
24 |
Const("Trueprop",_) $ p => |
|
25 |
(case head_of p of |
|
26 |
Const(a,_) => |
|
27 |
(case assoc(pairs,a) of |
|
28 |
Some(rls) => flat (map atoms ([th] RL rls)) |
|
29 |
| None => [th]) |
|
30 |
| _ => [th]) |
|
31 |
| _ => [th]) |
|
32 |
in atoms end; |
|
0 | 33 |
|
129 | 34 |
fun mk_meta_eq r = case concl_of r of |
0 | 35 |
Const("==",_)$_$_ => r |
36 |
| _$(Const("op =",_)$_$_) => r RS eq_reflection |
|
37 |
| _$(Const("not",_)$_) => r RS not_P_imp_P_eq_False |
|
38 |
| _ => r RS P_imp_P_eq_True; |
|
39 |
(* last 2 lines requires all formulae to be of the from Trueprop(.) *) |
|
40 |
||
41 |
fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th; |
|
42 |
||
1 | 43 |
val imp_cong = impI RSN |
0 | 44 |
(2, prove_goal HOL.thy "(P=P')--> (P'--> (Q=Q'))--> ((P-->Q) = (P'-->Q'))" |
45 |
(fn _=> [fast_tac HOL_cs 1]) RS mp RS mp); |
|
46 |
||
66 | 47 |
val o_apply = prove_goalw HOL.thy [o_def] "(f o g)(x) = f(g(x))" |
48 |
(fn _ => [rtac refl 1]); |
|
0 | 49 |
|
50 |
val simp_thms = map prover |
|
51 |
[ "(x=x) = True", |
|
52 |
"(~True) = False", "(~False) = True", "(~ ~ P) = P", |
|
40 | 53 |
"(~P) ~= P", "P ~= (~P)", "(P ~= Q) = (P = (~Q))", |
0 | 54 |
"(True=P) = P", "(P=True) = P", |
55 |
"(True --> P) = P", "(False --> P) = True", |
|
56 |
"(P --> True) = True", "(P --> P) = True", |
|
129 | 57 |
"(P --> False) = (~P)", "(P --> ~P) = (~P)", |
0 | 58 |
"(P & True) = P", "(True & P) = P", |
59 |
"(P & False) = False", "(False & P) = False", "(P & P) = P", |
|
60 |
"(P | True) = True", "(True | P) = True", |
|
61 |
"(P | False) = P", "(False | P) = P", "(P | P) = P", |
|
30
2fdeeae553ac
modified solver of HOL_ss to take the new simplifier into account: the thm to
nipkow
parents:
3
diff
changeset
|
62 |
"(!x.P) = P", "(? x.P) = P", |
0 | 63 |
"(P|Q --> R) = ((P-->R)&(Q-->R))" ]; |
64 |
||
99 | 65 |
in |
66 |
||
100 | 67 |
val meta_eq_to_obj_eq = prove_goal HOL.thy "x==y ==> x=y" |
0 | 68 |
(fn [prem] => [rewtac prem, rtac refl 1]); |
69 |
||
95 | 70 |
val eq_sym_conv = prover "(x=y) = (y=x)"; |
71 |
||
34 | 72 |
val conj_assoc = prover "((P&Q)&R) = (P&(Q&R))"; |
57 | 73 |
val conj_commute = prover "(P&Q) = (Q&P)"; |
62 | 74 |
val conj_left_commute = prover "(P&(Q&R)) = (Q&(P&R))"; |
75 |
val conj_comms = [conj_commute, conj_left_commute]; |
|
0 | 76 |
|
66 | 77 |
val if_True = prove_goalw HOL.thy [if_def] "if(True,x,y) = x" |
78 |
(fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]); |
|
0 | 79 |
|
66 | 80 |
val if_False = prove_goalw HOL.thy [if_def] "if(False,x,y) = y" |
81 |
(fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]); |
|
0 | 82 |
|
83 |
val if_P = prove_goal HOL.thy "P ==> if(P,x,y) = x" |
|
84 |
(fn [prem] => [ stac (prem RS eqTrueI) 1, rtac if_True 1 ]); |
|
85 |
||
86 |
val if_not_P = prove_goal HOL.thy "~P ==> if(P,x,y) = y" |
|
87 |
(fn [prem] => [ stac (prem RS not_P_imp_P_iff_F) 1, rtac if_False 1 ]); |
|
88 |
||
89 |
val expand_if = prove_goal HOL.thy |
|
90 |
"P(if(Q,x,y)) = ((Q --> P(x)) & (~Q --> P(y)))" |
|
91 |
(fn _=> [ (res_inst_tac [("Q","Q")] (excluded_middle RS disjE) 1), |
|
92 |
rtac (if_P RS ssubst) 2, |
|
93 |
rtac (if_not_P RS ssubst) 1, |
|
94 |
REPEAT(fast_tac HOL_cs 1) ]); |
|
95 |
||
1 | 96 |
infix addcongs; |
97 |
fun ss addcongs congs = ss addeqcongs (congs RL [eq_reflection]); |
|
0 | 98 |
|
129 | 99 |
val mksimps_pairs = |
100 |
[("op -->", [mp]), ("op &", [conjunct1,conjunct2]), |
|
101 |
("All", [spec]), ("True", []), ("False", [])]; |
|
102 |
||
103 |
fun mksimps pairs = map mk_meta_eq o atomize pairs o gen_all; |
|
104 |
||
0 | 105 |
val HOL_ss = empty_ss |
129 | 106 |
setmksimps (mksimps mksimps_pairs) |
43 | 107 |
setsolver (fn prems => resolve_tac (TrueI::refl::prems) ORELSE' atac |
108 |
ORELSE' etac FalseE) |
|
0 | 109 |
setsubgoaler asm_simp_tac |
34 | 110 |
addsimps ([if_True, if_False, o_apply, conj_assoc] @ simp_thms) |
1 | 111 |
addcongs [imp_cong]; |
0 | 112 |
|
113 |
fun split_tac splits = |
|
129 | 114 |
mk_case_split_tac (meta_eq_to_obj_eq RS iffD2) (map mk_meta_eq splits); |
0 | 115 |
|
40 | 116 |
(* eliminiation of existential quantifiers in assumptions *) |
117 |
||
118 |
val ex_all_equiv = |
|
119 |
let val lemma1 = prove_goal HOL.thy |
|
120 |
"(? x. P(x) ==> PROP Q) ==> (!!x. P(x) ==> PROP Q)" |
|
121 |
(fn prems => [resolve_tac prems 1, etac exI 1]); |
|
66 | 122 |
val lemma2 = prove_goalw HOL.thy [Ex_def] |
40 | 123 |
"(!!x. P(x) ==> PROP Q) ==> (? x. P(x) ==> PROP Q)" |
124 |
(fn prems => [REPEAT(resolve_tac prems 1)]) |
|
125 |
in equal_intr lemma1 lemma2 end; |
|
126 |
||
30
2fdeeae553ac
modified solver of HOL_ss to take the new simplifier into account: the thm to
nipkow
parents:
3
diff
changeset
|
127 |
(** '&' congruence rule: not included by default! *) |
2fdeeae553ac
modified solver of HOL_ss to take the new simplifier into account: the thm to
nipkow
parents:
3
diff
changeset
|
128 |
|
2fdeeae553ac
modified solver of HOL_ss to take the new simplifier into account: the thm to
nipkow
parents:
3
diff
changeset
|
129 |
val conj_cong = impI RSN |
2fdeeae553ac
modified solver of HOL_ss to take the new simplifier into account: the thm to
nipkow
parents:
3
diff
changeset
|
130 |
(2, prove_goal HOL.thy "(P=P')--> (P'--> (Q=Q'))--> ((P&Q) = (P'&Q'))" |
2fdeeae553ac
modified solver of HOL_ss to take the new simplifier into account: the thm to
nipkow
parents:
3
diff
changeset
|
131 |
(fn _=> [fast_tac HOL_cs 1]) RS mp RS mp); |
2fdeeae553ac
modified solver of HOL_ss to take the new simplifier into account: the thm to
nipkow
parents:
3
diff
changeset
|
132 |
|
3
a910a65478be
This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents:
1
diff
changeset
|
133 |
(** 'if' congruence rules: neither included by default! *) |
a910a65478be
This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents:
1
diff
changeset
|
134 |
|
a910a65478be
This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents:
1
diff
changeset
|
135 |
(*Simplifies x assuming c and y assuming ~c*) |
a910a65478be
This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents:
1
diff
changeset
|
136 |
val if_cong = prove_goal HOL.thy |
a910a65478be
This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents:
1
diff
changeset
|
137 |
"[| b=c; c ==> x=u; ~c ==> y=v |] ==> if(b,x,y) = if(c,u,v)" |
a910a65478be
This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents:
1
diff
changeset
|
138 |
(fn rew::prems => |
a910a65478be
This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents:
1
diff
changeset
|
139 |
[stac rew 1, stac expand_if 1, stac expand_if 1, |
a910a65478be
This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents:
1
diff
changeset
|
140 |
fast_tac (HOL_cs addDs prems) 1]); |
a910a65478be
This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents:
1
diff
changeset
|
141 |
|
a910a65478be
This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents:
1
diff
changeset
|
142 |
(*Prevents simplification of x and y: much faster*) |
a910a65478be
This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents:
1
diff
changeset
|
143 |
val if_weak_cong = prove_goal HOL.thy |
a910a65478be
This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents:
1
diff
changeset
|
144 |
"b=c ==> if(b,x,y) = if(c,x,y)" |
a910a65478be
This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents:
1
diff
changeset
|
145 |
(fn [prem] => [rtac (prem RS arg_cong) 1]); |
a910a65478be
This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents:
1
diff
changeset
|
146 |
|
32 | 147 |
(*Prevents simplification of t: much faster*) |
148 |
val let_weak_cong = prove_goal HOL.thy |
|
149 |
"a = b ==> (let x=a in t(x)) = (let x=b in t(x))" |
|
150 |
(fn [prem] => [rtac (prem RS arg_cong) 1]); |
|
151 |
||
0 | 152 |
end; |