663
|
1 |
(* Title: FOL/ex/mini
|
|
2 |
ID: $Id$
|
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
|
|
4 |
Copyright 1994 University of Cambridge
|
|
5 |
|
|
6 |
Classical First-Order Logic
|
|
7 |
|
|
8 |
Conversion to nnf/miniscope format: pushing quantifiers in
|
|
9 |
|
|
10 |
Demonstration of formula rewriting by proof
|
|
11 |
*)
|
|
12 |
|
|
13 |
val ccontr = FalseE RS classical;
|
|
14 |
|
|
15 |
(**** Negation Normal Form ****)
|
|
16 |
|
|
17 |
(*** de Morgan laws ***)
|
|
18 |
|
|
19 |
val not_conjD = prove_fun "~(P&Q) ==> ~P | ~Q";
|
|
20 |
val not_disjD = prove_fun "~(P|Q) ==> ~P & ~Q";
|
|
21 |
val not_notD = prove_fun "~~P ==> P";
|
|
22 |
val not_allD = prove_fun "~(ALL x.P(x)) ==> EX x. ~P(x)";
|
|
23 |
val not_exD = prove_fun "~(EX x.P(x)) ==> ALL x. ~P(x)";
|
|
24 |
|
|
25 |
|
|
26 |
(*** Removal of --> and <-> (positive and negative occurrences) ***)
|
|
27 |
|
|
28 |
val imp_to_disjD = prove_fun "P-->Q ==> ~P | Q";
|
|
29 |
val not_impD = prove_fun "~(P-->Q) ==> P & ~Q";
|
|
30 |
|
|
31 |
val iff_to_disjD = prove_fun "P<->Q ==> (~P | Q) & (~Q | P)";
|
|
32 |
|
|
33 |
(*Much more efficient than (P & ~Q) | (Q & ~P) for computing CNF*)
|
|
34 |
val not_iffD = prove_fun "~(P<->Q) ==> (P | Q) & (~P | ~Q)";
|
|
35 |
|
|
36 |
|
|
37 |
(*** Pushing in the existential quantifiers ***)
|
|
38 |
|
|
39 |
val null_exD = prove_fun "EX x. P ==> P";
|
|
40 |
|
|
41 |
(** Conjunction **)
|
|
42 |
|
|
43 |
val conj_exD1 = prove_fun "EX x. P(x) & Q ==> (EX x.P(x)) & Q";
|
|
44 |
val conj_exD2 = prove_fun "EX x. P & Q(x) ==> P & (EX x.Q(x))";
|
|
45 |
|
|
46 |
(** Disjunction **)
|
|
47 |
|
|
48 |
val disj_exD = prove_fun "EX x. P(x) | Q(x) ==> (EX x.P(x)) | (EX x.Q(x))";
|
|
49 |
val disj_exD1 = prove_fun "EX x. P(x) | Q ==> (EX x.P(x)) | Q";
|
|
50 |
val disj_exD2 = prove_fun "EX x. P | Q(x) ==> P | (EX x.Q(x))";
|
|
51 |
|
|
52 |
|
|
53 |
(*** Pushing in the universal quantifiers ***)
|
|
54 |
|
|
55 |
val null_allD = prove_fun "ALL x. P ==> P";
|
|
56 |
|
|
57 |
(** Conjunction **)
|
|
58 |
|
|
59 |
val conj_allD = prove_fun "ALL x. P(x) & Q(x) ==> (ALL x.P(x)) & (ALL x.Q(x))";
|
|
60 |
val conj_allD1 = prove_fun "ALL x. P(x) & Q ==> (ALL x.P(x)) & Q";
|
|
61 |
val conj_allD2 = prove_fun "ALL x. P & Q(x) ==> P & (ALL x.Q(x))";
|
|
62 |
|
|
63 |
(** Disjunction **)
|
|
64 |
|
|
65 |
val disj_allD1 = prove_fun "ALL x. P(x) | Q ==> (ALL x.P(x)) | Q";
|
|
66 |
val disj_allD2 = prove_fun "ALL x. P | Q(x) ==> P | (ALL x.Q(x))";
|
|
67 |
|
|
68 |
|
|
69 |
(**** Lemmas for forward proof (like congruence rules) ****)
|
|
70 |
|
|
71 |
(*NOTE: could handle conjunctions (faster?) by
|
|
72 |
nf(th RS conjunct2) RS (nf(th RS conjunct1) RS conjI) *)
|
|
73 |
val major::prems = goal FOL.thy
|
|
74 |
"[| P'&Q'; P' ==> P; Q' ==> Q |] ==> P&Q";
|
|
75 |
by (rtac (major RS conjE) 1);
|
|
76 |
by (rtac conjI 1);
|
|
77 |
by (ALLGOALS (eresolve_tac prems));
|
|
78 |
val conj_forward = result();
|
|
79 |
|
|
80 |
val major::prems = goal FOL.thy
|
|
81 |
"[| P'|Q'; P' ==> P; Q' ==> Q |] ==> P|Q";
|
|
82 |
by (rtac (major RS disjE) 1);
|
|
83 |
by (ALLGOALS (dresolve_tac prems));
|
|
84 |
by (ALLGOALS (eresolve_tac [disjI1,disjI2]));
|
|
85 |
val disj_forward = result();
|
|
86 |
|
|
87 |
val major::prems = goal FOL.thy
|
|
88 |
"[| ALL x. P'(x); !!x. P'(x) ==> P(x) |] ==> ALL x. P(x)";
|
|
89 |
by (rtac allI 1);
|
|
90 |
by (resolve_tac prems 1);
|
|
91 |
by (rtac (major RS spec) 1);
|
|
92 |
val all_forward = result();
|
|
93 |
|
|
94 |
val major::prems = goal FOL.thy
|
|
95 |
"[| EX x. P'(x); !!x. P'(x) ==> P(x) |] ==> EX x. P(x)";
|
|
96 |
by (rtac (major RS exE) 1);
|
|
97 |
by (rtac exI 1);
|
|
98 |
by (eresolve_tac prems 1);
|
|
99 |
val ex_forward = result();
|
|
100 |
|
|
101 |
|
|
102 |
val mini_rls =
|
|
103 |
[imp_to_disjD, iff_to_disjD, not_conjD, not_disjD,
|
|
104 |
not_impD, not_iffD, not_allD, not_exD, not_notD,
|
|
105 |
null_exD, conj_exD1, conj_exD2, disj_exD, disj_exD1, disj_exD2,
|
|
106 |
null_allD, conj_allD, conj_allD1, conj_allD2, disj_allD1, disj_allD2];
|
|
107 |
|
|
108 |
val forward_rls = [conj_forward, disj_forward, all_forward, ex_forward];
|
|
109 |
|
|
110 |
(*** The transformation is done by forward proof: resolution.
|
|
111 |
A tactic approach using dresolve_tac seems to be MUCH slower.
|
|
112 |
The simplifier could compute nnf but not miniscope.
|
|
113 |
***)
|
|
114 |
|
|
115 |
(*Permits forward proof from rules that discharge assumptions*)
|
|
116 |
fun forward_res nf state =
|
|
117 |
Sequence.hd
|
|
118 |
(tapply(ALLGOALS (METAHYPS (fn [prem] => rtac (nf prem) 1)),
|
|
119 |
state));
|
|
120 |
|
|
121 |
(**** Operators for forward proof ****)
|
|
122 |
|
|
123 |
(*raises exception if no rules apply -- unlike RL*)
|
|
124 |
fun tryres (th, rl::rls) = (th RS rl handle THM _ => tryres(th,rls))
|
|
125 |
| tryres (th, []) = raise THM("tryres", 0, [th]);
|
|
126 |
|
|
127 |
(*insert one destruction rule into the net*)
|
|
128 |
fun insert_D_rl (th, net) =
|
|
129 |
Net.insert_term ((hd (prems_of th), th), net, K false);
|
|
130 |
|
|
131 |
fun net_tryres rls =
|
|
132 |
let val net = foldr insert_D_rl (rls, Net.empty)
|
|
133 |
fun tfun th = tryres (th, Net.unify_term net (concl_of th))
|
|
134 |
in tfun end;
|
|
135 |
|
|
136 |
val try_mini = net_tryres mini_rls
|
|
137 |
and try_forward = net_tryres forward_rls;
|
|
138 |
|
|
139 |
fun make_mini th = sub_mini (try_mini th)
|
|
140 |
handle THM _ => th
|
|
141 |
and sub_mini th = sub_mini (try_mini th)
|
|
142 |
handle THM _ => make_mini (forward_res sub_mini (try_forward th))
|
|
143 |
handle THM _ => th;
|
|
144 |
|
|
145 |
fun mini_tac prems = cut_facts_tac (map sub_mini prems);
|
|
146 |
|
|
147 |
fun MINI tac = SELECT_GOAL
|
|
148 |
(EVERY1 [rtac ccontr,
|
|
149 |
METAHYPS (fn negs =>
|
|
150 |
EVERY1 [mini_tac negs, tac])]);
|
|
151 |
|