1 (* Title: FOL/simpdata |
1 (* Title: FOL/simpdata |
2 ID: $Id$ |
2 ID: $Id$ |
3 Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
3 Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
4 Copyright 1991 University of Cambridge |
4 Copyright 1994 University of Cambridge |
5 |
5 |
6 Simplification data for FOL |
6 Simplification data for FOL |
7 *) |
7 *) |
8 |
8 |
9 (*** Rewrite rules ***) |
9 (*** Rewrite rules ***) |
10 |
10 |
11 fun int_prove_fun s = |
11 fun int_prove_fun s = |
12 (writeln s; prove_goal IFOL.thy s |
12 (writeln s; |
13 (fn prems => [ (cut_facts_tac prems 1), (Int.fast_tac 1) ])); |
13 prove_goal IFOL.thy s |
|
14 (fn prems => [ (cut_facts_tac prems 1), |
|
15 (Int.fast_tac 1) ])); |
14 |
16 |
15 val conj_rews = map int_prove_fun |
17 val conj_rews = map int_prove_fun |
16 ["P & True <-> P", "True & P <-> P", |
18 ["P & True <-> P", "True & P <-> P", |
17 "P & False <-> False", "False & P <-> False", |
19 "P & False <-> False", "False & P <-> False", |
18 "P & P <-> P", |
20 "P & P <-> P", |
19 "P & ~P <-> False", "~P & P <-> False", |
21 "P & ~P <-> False", "~P & P <-> False", |
20 "(P & Q) & R <-> P & (Q & R)"]; |
22 "(P & Q) & R <-> P & (Q & R)"]; |
21 |
23 |
22 val disj_rews = map int_prove_fun |
24 val disj_rews = map int_prove_fun |
23 ["P | True <-> True", "True | P <-> True", |
25 ["P | True <-> True", "True | P <-> True", |
24 "P | False <-> P", "False | P <-> P", |
26 "P | False <-> P", "False | P <-> P", |
25 "P | P <-> P", |
27 "P | P <-> P", |
26 "(P | Q) | R <-> P | (Q | R)"]; |
28 "(P | Q) | R <-> P | (Q | R)"]; |
27 |
29 |
28 val not_rews = map int_prove_fun |
30 val not_rews = map int_prove_fun |
29 ["~ False <-> True", "~ True <-> False"]; |
31 ["~(P|Q) <-> ~P & ~Q", |
|
32 "~ False <-> True", "~ True <-> False"]; |
30 |
33 |
31 val imp_rews = map int_prove_fun |
34 val imp_rews = map int_prove_fun |
32 ["(P --> False) <-> ~P", "(P --> True) <-> True", |
35 ["(P --> False) <-> ~P", "(P --> True) <-> True", |
33 "(False --> P) <-> True", "(True --> P) <-> P", |
36 "(False --> P) <-> True", "(True --> P) <-> P", |
34 "(P --> P) <-> True", "(P --> ~P) <-> ~P"]; |
37 "(P --> P) <-> True", "(P --> ~P) <-> ~P"]; |
41 val quant_rews = map int_prove_fun |
44 val quant_rews = map int_prove_fun |
42 ["(ALL x.P) <-> P", "(EX x.P) <-> P"]; |
45 ["(ALL x.P) <-> P", "(EX x.P) <-> P"]; |
43 |
46 |
44 (*These are NOT supplied by default!*) |
47 (*These are NOT supplied by default!*) |
45 val distrib_rews = map int_prove_fun |
48 val distrib_rews = map int_prove_fun |
46 ["~(P|Q) <-> ~P & ~Q", |
49 ["P & (Q | R) <-> P&Q | P&R", |
47 "P & (Q | R) <-> P&Q | P&R", "(Q | R) & P <-> Q&P | R&P", |
50 "(Q | R) & P <-> Q&P | R&P", |
48 "(P | Q --> R) <-> (P --> R) & (Q --> R)"]; |
51 "(P | Q --> R) <-> (P --> R) & (Q --> R)"]; |
49 |
52 |
50 val P_Imp_P_iff_T = int_prove_fun "P ==> (P <-> True)"; |
53 (** Conversion into rewrite rules **) |
51 |
|
52 fun make_iff_T th = th RS P_Imp_P_iff_T; |
|
53 |
|
54 val refl_iff_T = make_iff_T refl; |
|
55 |
|
56 val notFalseI = int_prove_fun "~False"; |
|
57 |
|
58 (* Conversion into rewrite rules *) |
|
59 |
|
60 val not_P_imp_P_iff_F = int_prove_fun "~P ==> (P <-> False)"; |
|
61 |
|
62 fun mk_meta_eq th = case concl_of th of |
|
63 _ $ (Const("op <->",_)$_$_) => th RS iff_reflection |
|
64 | _ $ (Const("op =",_)$_$_) => th RS eq_reflection |
|
65 | _ $ (Const("Not",_)$_) => (th RS not_P_imp_P_iff_F) RS iff_reflection |
|
66 | _ => (make_iff_T th) RS iff_reflection; |
|
67 |
|
68 fun atomize th = case concl_of th of (*The operator below is Trueprop*) |
|
69 _ $ (Const("op -->",_) $ _ $ _) => atomize(th RS mp) |
|
70 | _ $ (Const("op &",_) $ _ $ _) => atomize(th RS conjunct1) @ |
|
71 atomize(th RS conjunct2) |
|
72 | _ $ (Const("All",_) $ _) => atomize(th RS spec) |
|
73 | _ $ (Const("True",_)) => [] |
|
74 | _ $ (Const("False",_)) => [] |
|
75 | _ => [th]; |
|
76 |
54 |
77 fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th; |
55 fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th; |
78 |
56 |
79 fun mk_rew_rules th = map mk_meta_eq (atomize(gen_all th)); |
57 (*Make atomic rewrite rules*) |
|
58 fun atomize th = case concl_of th of |
|
59 _ $ (Const("op &",_) $ _ $ _) => atomize(th RS conjunct1) @ |
|
60 atomize(th RS conjunct2) |
|
61 | _ $ (Const("op -->",_) $ _ $ _) => atomize(th RS mp) |
|
62 | _ $ (Const("All",_) $ _) => atomize(th RS spec) |
|
63 | _ $ (Const("True",_)) => [] |
|
64 | _ $ (Const("False",_)) => [] |
|
65 | _ => [th]; |
|
66 |
|
67 val P_iff_F = int_prove_fun "~P ==> (P <-> False)"; |
|
68 val iff_reflection_F = P_iff_F RS iff_reflection; |
|
69 |
|
70 val P_iff_T = int_prove_fun "P ==> (P <-> True)"; |
|
71 val iff_reflection_T = P_iff_T RS iff_reflection; |
|
72 |
|
73 (*Make meta-equalities. The operator below is Trueprop*) |
|
74 fun mk_meta_eq th = case concl_of th of |
|
75 _ $ (Const("op =",_)$_$_) => th RS eq_reflection |
|
76 | _ $ (Const("op <->",_)$_$_) => th RS iff_reflection |
|
77 | _ $ (Const("Not",_)$_) => th RS iff_reflection_F |
|
78 | _ => th RS iff_reflection_T; |
80 |
79 |
81 structure Induction = InductionFun(struct val spec=IFOL.spec end); |
80 structure Induction = InductionFun(struct val spec=IFOL.spec end); |
82 |
|
83 val IFOL_rews = |
|
84 [refl_iff_T] @ conj_rews @ disj_rews @ not_rews @ |
|
85 imp_rews @ iff_rews @ quant_rews; |
|
86 |
81 |
87 open Simplifier Induction; |
82 open Simplifier Induction; |
88 |
83 |
89 infix addcongs; |
84 infix addcongs; |
90 fun ss addcongs congs = |
85 fun ss addcongs congs = |
91 ss addeqcongs (congs RL [eq_reflection,iff_reflection]); |
86 ss addeqcongs (congs RL [eq_reflection,iff_reflection]); |
92 |
87 |
93 val IFOL_ss = empty_ss |
88 val IFOL_rews = |
94 setmksimps mk_rew_rules |
89 [refl RS P_iff_T] @ conj_rews @ disj_rews @ not_rews @ |
95 setsolver |
90 imp_rews @ iff_rews @ quant_rews; |
96 (fn prems => resolve_tac (TrueI::refl::iff_refl::notFalseI::prems) |
91 |
97 ORELSE' atac) |
92 val notFalseI = int_prove_fun "~False"; |
98 setsubgoaler asm_simp_tac |
93 val triv_rls = [TrueI,refl,iff_refl,notFalseI]; |
99 addsimps IFOL_rews |
94 |
100 addcongs [imp_cong]; |
95 val IFOL_ss = |
|
96 empty_ss |
|
97 setmksimps (map mk_meta_eq o atomize o gen_all) |
|
98 setsolver (fn prems => resolve_tac (triv_rls@prems) ORELSE' assume_tac) |
|
99 setsubgoaler asm_simp_tac |
|
100 addsimps IFOL_rews |
|
101 addcongs [imp_cong]; |
101 |
102 |
102 (*Classical version...*) |
103 (*Classical version...*) |
103 fun prove_fun s = |
104 fun prove_fun s = |
104 (writeln s; prove_goal FOL.thy s |
105 (writeln s; |
105 (fn prems => [ (cut_facts_tac prems 1), (Cla.fast_tac FOL_cs 1) ])); |
106 prove_goal FOL.thy s |
106 |
107 (fn prems => [ (cut_facts_tac prems 1), |
|
108 (Cla.fast_tac FOL_cs 1) ])); |
107 val cla_rews = map prove_fun |
109 val cla_rews = map prove_fun |
108 ["P | ~P", "~P | P", |
110 ["~(P&Q) <-> ~P | ~Q", |
|
111 "P | ~P", "~P | P", |
109 "~ ~ P <-> P", "(~P --> P) <-> P"]; |
112 "~ ~ P <-> P", "(~P --> P) <-> P"]; |
110 |
113 |
111 val FOL_ss = IFOL_ss addsimps cla_rews; |
114 val FOL_ss = IFOL_ss addsimps cla_rews; |
112 |
115 |
113 (*** case splitting ***) |
116 (*** case splitting ***) |
114 |
117 |
115 val split_tac = |
118 val meta_iffD = |
116 let val eq_reflection2 = prove_goal FOL.thy "x==y ==> x=y" |
119 prove_goal FOL.thy "[| P==Q; Q |] ==> P" |
117 (fn [prem] => [rewtac prem, rtac refl 1]) |
120 (fn [prem1,prem2] => [rewtac prem1, rtac prem2 1]) |
118 val iff_reflection2 = prove_goal FOL.thy "x==y ==> x<->y" |
121 |
119 (fn [prem] => [rewtac prem, rtac iff_refl 1]) |
122 fun split_tac splits = |
120 val [iffD] = [eq_reflection2,iff_reflection2] RL [iffD2] |
123 mk_case_split_tac meta_iffD (map mk_meta_eq splits); |
121 in fn splits => mk_case_split_tac iffD (map mk_meta_eq splits) end; |
|