123 "[| P=Q; [| P --> Q; Q --> P |] ==> R |] ==> R" |
123 "[| P=Q; [| P --> Q; Q --> P |] ==> R |] ==> R" |
124 (fn [p1,p2] => [REPEAT(ares_tac([p1 RS iffD2, p1 RS iffD1, p2, impI])1)]); |
124 (fn [p1,p2] => [REPEAT(ares_tac([p1 RS iffD2, p1 RS iffD1, p2, impI])1)]); |
125 |
125 |
126 (** True **) |
126 (** True **) |
127 |
127 |
128 val TrueI = refl RS (True_def RS iffD2); |
128 val TrueI = prove_goalw HOL.thy [True_def] "True" |
|
129 (fn _ => [rtac refl 1]); |
129 |
130 |
130 val eqTrueI = prove_goal HOL.thy "P ==> P=True" |
131 val eqTrueI = prove_goal HOL.thy "P ==> P=True" |
131 (fn prems => [REPEAT(resolve_tac ([iffI,TrueI]@prems) 1)]); |
132 (fn prems => [REPEAT(resolve_tac ([iffI,TrueI]@prems) 1)]); |
132 |
133 |
133 val eqTrueE = prove_goal HOL.thy "P=True ==> P" |
134 val eqTrueE = prove_goal HOL.thy "P=True ==> P" |
134 (fn prems => [REPEAT(resolve_tac (prems@[TrueI,iffD2]) 1)]); |
135 (fn prems => [REPEAT(resolve_tac (prems@[TrueI,iffD2]) 1)]); |
135 |
136 |
136 (** Universal quantifier **) |
137 (** Universal quantifier **) |
137 |
138 |
138 val allI = prove_goal HOL.thy "(!!x::'a. P(x)) ==> !x. P(x)" |
139 val allI = prove_goalw HOL.thy [All_def] "(!!x::'a. P(x)) ==> !x. P(x)" |
139 (fn [asm] => [rtac (All_def RS ssubst) 1, rtac (asm RS (eqTrueI RS ext)) 1]); |
140 (fn prems => [resolve_tac (prems RL [eqTrueI RS ext]) 1]); |
140 |
141 |
141 val spec = prove_goal HOL.thy "! x::'a.P(x) ==> P(x)" |
142 val spec = prove_goalw HOL.thy [All_def] "! x::'a.P(x) ==> P(x)" |
142 (fn prems => |
143 (fn prems => [rtac eqTrueE 1, resolve_tac (prems RL [fun_cong]) 1]); |
143 [ rtac eqTrueE 1, |
|
144 resolve_tac (prems RL [All_def RS subst] RL [fun_cong]) 1 ]); |
|
145 |
144 |
146 val allE = prove_goal HOL.thy "[| !x.P(x); P(x) ==> R |] ==> R" |
145 val allE = prove_goal HOL.thy "[| !x.P(x); P(x) ==> R |] ==> R" |
147 (fn major::prems=> |
146 (fn major::prems=> |
148 [ (REPEAT (resolve_tac (prems @ [major RS spec]) 1)) ]); |
147 [ (REPEAT (resolve_tac (prems @ [major RS spec]) 1)) ]); |
149 |
148 |
155 |
154 |
156 (** False ** Depends upon spec; it is impossible to do propositional logic |
155 (** False ** Depends upon spec; it is impossible to do propositional logic |
157 before quantifiers! **) |
156 before quantifiers! **) |
158 |
157 |
159 val FalseE = prove_goal HOL.thy "False ==> P" |
158 val FalseE = prove_goal HOL.thy "False ==> P" |
160 (fn prems => [rtac spec 1, rtac (False_def RS subst) 1, resolve_tac prems 1]); |
159 (fn prems => [rtac spec 1, fold_tac [False_def], resolve_tac prems 1]); |
161 |
160 |
162 val False_neq_True = prove_goal HOL.thy "False=True ==> P" |
161 val False_neq_True = prove_goal HOL.thy "False=True ==> P" |
163 (fn [prem] => [rtac (prem RS eqTrueE RS FalseE) 1]); |
162 (fn [prem] => [rtac (prem RS eqTrueE RS FalseE) 1]); |
164 |
163 |
165 |
164 |
166 (** Negation **) |
165 (** Negation **) |
167 |
166 |
168 val notI = prove_goal HOL.thy "(P ==> False) ==> ~P" |
167 val notI = prove_goalw HOL.thy [not_def] "(P ==> False) ==> ~P" |
169 (fn prems=> [rtac (not_def RS ssubst) 1, rtac impI 1, eresolve_tac prems 1]); |
168 (fn prems=> [rtac impI 1, eresolve_tac prems 1]); |
170 |
169 |
171 val notE = prove_goal HOL.thy "[| ~P; P |] ==> R" |
170 val notE = prove_goalw HOL.thy [not_def] "[| ~P; P |] ==> R" |
172 (fn prems => |
171 (fn prems => [rtac (mp RS FalseE) 1, REPEAT(resolve_tac prems 1)]); |
173 [rtac (mp RS FalseE) 1, |
|
174 resolve_tac prems 2, rtac (not_def RS subst) 1, |
|
175 resolve_tac prems 1]); |
|
176 |
172 |
177 (** Implication **) |
173 (** Implication **) |
178 |
174 |
179 val impE = prove_goal HOL.thy "[| P-->Q; P; Q ==> R |] ==> R" |
175 val impE = prove_goal HOL.thy "[| P-->Q; P; Q ==> R |] ==> R" |
180 (fn prems=> [ (REPEAT (resolve_tac (prems@[mp]) 1)) ]); |
176 (fn prems=> [ (REPEAT (resolve_tac (prems@[mp]) 1)) ]); |
192 val [not_sym] = compose(sym,2,contrapos); |
188 val [not_sym] = compose(sym,2,contrapos); |
193 |
189 |
194 |
190 |
195 (** Existential quantifier **) |
191 (** Existential quantifier **) |
196 |
192 |
197 val exI = prove_goal HOL.thy "P(x) ==> ? x::'a.P(x)" |
193 val exI = prove_goalw HOL.thy [Ex_def] "P(x) ==> ? x::'a.P(x)" |
198 (fn prems => |
194 (fn prems => [rtac selectI 1, resolve_tac prems 1]); |
199 [rtac (selectI RS (Ex_def RS ssubst)) 1, |
195 |
200 resolve_tac prems 1]); |
196 val exE = prove_goalw HOL.thy [Ex_def] |
201 |
197 "[| ? x::'a.P(x); !!x. P(x) ==> Q |] ==> Q" |
202 val exE = prove_goal HOL.thy "[| ? x::'a.P(x); !!x. P(x) ==> Q |] ==> Q" |
198 (fn prems => [REPEAT(resolve_tac prems 1)]); |
203 (fn prems => |
|
204 [resolve_tac prems 1, res_inst_tac [("P","%C.C(P)")] subst 1, |
|
205 rtac Ex_def 1, resolve_tac prems 1]); |
|
206 |
199 |
207 |
200 |
208 (** Conjunction **) |
201 (** Conjunction **) |
209 |
202 |
210 val conjI = prove_goal HOL.thy "[| P; Q |] ==> P&Q" |
203 val conjI = prove_goalw HOL.thy [and_def] "[| P; Q |] ==> P&Q" |
211 (fn prems => |
204 (fn prems => |
212 [ (rtac (and_def RS ssubst) 1), |
205 [REPEAT (resolve_tac (prems@[allI,impI]) 1 ORELSE etac (mp RS mp) 1)]); |
213 (REPEAT (resolve_tac (prems@[allI,impI]) 1 ORELSE etac (mp RS mp) 1)) ]); |
206 |
214 |
207 val conjunct1 = prove_goalw HOL.thy [and_def] "[| P & Q |] ==> P" |
215 val conjunct1 = prove_goal HOL.thy "[| P & Q |] ==> P" |
208 (fn prems => |
216 (fn prems => |
209 [resolve_tac (prems RL [spec] RL [mp]) 1, REPEAT(ares_tac [impI] 1)]); |
217 [ (resolve_tac (prems RL [and_def RS subst] RL [spec] RL [mp]) 1), |
210 |
218 (REPEAT(ares_tac [impI] 1)) ]); |
211 val conjunct2 = prove_goalw HOL.thy [and_def] "[| P & Q |] ==> Q" |
219 |
212 (fn prems => |
220 val conjunct2 = prove_goal HOL.thy "[| P & Q |] ==> Q" |
213 [resolve_tac (prems RL [spec] RL [mp]) 1, REPEAT(ares_tac [impI] 1)]); |
221 (fn prems => |
|
222 [ (resolve_tac (prems RL [and_def RS subst] RL [spec] RL [mp]) 1), |
|
223 (REPEAT(ares_tac [impI] 1)) ]); |
|
224 |
214 |
225 val conjE = prove_goal HOL.thy "[| P&Q; [| P; Q |] ==> R |] ==> R" |
215 val conjE = prove_goal HOL.thy "[| P&Q; [| P; Q |] ==> R |] ==> R" |
226 (fn prems => |
216 (fn prems => |
227 [cut_facts_tac prems 1, resolve_tac prems 1, |
217 [cut_facts_tac prems 1, resolve_tac prems 1, |
228 etac conjunct1 1, etac conjunct2 1]); |
218 etac conjunct1 1, etac conjunct2 1]); |
229 |
219 |
230 (** Disjunction *) |
220 (** Disjunction *) |
231 |
221 |
232 val disjI1 = prove_goal HOL.thy "P ==> P|Q" |
222 val disjI1 = prove_goalw HOL.thy [or_def] "P ==> P|Q" |
233 (fn [prem] => |
223 (fn [prem] => [REPEAT(ares_tac [allI,impI, prem RSN (2,mp)] 1)]); |
234 [rtac (or_def RS ssubst) 1, |
224 |
235 REPEAT(ares_tac [allI,impI, prem RSN (2,mp)] 1)]); |
225 val disjI2 = prove_goalw HOL.thy [or_def] "Q ==> P|Q" |
236 |
226 (fn [prem] => [REPEAT(ares_tac [allI,impI, prem RSN (2,mp)] 1)]); |
237 val disjI2 = prove_goal HOL.thy "Q ==> P|Q" |
227 |
238 (fn [prem] => |
228 val disjE = prove_goalw HOL.thy [or_def] "[| P | Q; P ==> R; Q ==> R |] ==> R" |
239 [rtac (or_def RS ssubst) 1, |
|
240 REPEAT(ares_tac [allI,impI, prem RSN (2,mp)] 1)]); |
|
241 |
|
242 val disjE = prove_goal HOL.thy "[| P | Q; P ==> R; Q ==> R |] ==> R" |
|
243 (fn [a1,a2,a3] => |
229 (fn [a1,a2,a3] => |
244 [rtac (mp RS mp) 1, rtac spec 1, rtac (or_def RS subst) 1, rtac a1 1, |
230 [rtac (mp RS mp) 1, rtac spec 1, rtac a1 1, |
245 rtac (a2 RS impI) 1, atac 1, rtac (a3 RS impI) 1, atac 1]); |
231 rtac (a2 RS impI) 1, atac 1, rtac (a3 RS impI) 1, atac 1]); |
246 |
232 |
247 (** CCONTR -- classical logic **) |
233 (** CCONTR -- classical logic **) |
248 |
234 |
249 val ccontr = prove_goal HOL.thy "(~P ==> False) ==> P" |
235 val ccontr = prove_goal HOL.thy "(~P ==> False) ==> P" |
250 (fn prems => |
236 (fn prems => |
251 [rtac (True_or_False RS (disjE RS eqTrueE)) 1, atac 1, |
237 [rtac (True_or_False RS (disjE RS eqTrueE)) 1, atac 1, |
252 rtac spec 1, rtac (False_def RS subst) 1, resolve_tac prems 1, |
238 rtac spec 1, fold_tac [False_def], resolve_tac prems 1, |
253 rtac ssubst 1, atac 1, rtac (not_def RS ssubst) 1, |
239 rtac ssubst 1, atac 1, rewtac not_def, |
254 REPEAT (ares_tac [impI] 1) ]); |
240 REPEAT (ares_tac [impI] 1) ]); |
255 |
241 |
|
242 val ccontr = prove_goalw HOL.thy [not_def] "(~P ==> False) ==> P" |
|
243 (fn prems => |
|
244 [rtac (True_or_False RS (disjE RS eqTrueE)) 1, atac 1, |
|
245 rtac spec 1, fold_tac [False_def], resolve_tac prems 1, |
|
246 rtac ssubst 1, atac 1, REPEAT (ares_tac [impI] 1) ]); |
|
247 |
256 val classical = prove_goal HOL.thy "(~P ==> P) ==> P" |
248 val classical = prove_goal HOL.thy "(~P ==> P) ==> P" |
257 (fn prems => |
249 (fn prems => [rtac ccontr 1, REPEAT (ares_tac (prems@[notE]) 1)]); |
258 [rtac ccontr 1, |
|
259 REPEAT (ares_tac (prems@[notE]) 1)]); |
|
260 |
250 |
261 |
251 |
262 (*Double negation law*) |
252 (*Double negation law*) |
263 val notnotD = prove_goal HOL.thy "~~P ==> P" |
253 val notnotD = prove_goal HOL.thy "~~P ==> P" |
264 (fn [major]=> |
254 (fn [major]=> |
265 [ (rtac classical 1), (eresolve_tac [major RS notE] 1) ]); |
255 [ (rtac classical 1), (eresolve_tac [major RS notE] 1) ]); |
266 |
256 |
267 |
257 |
268 (** Unique existence **) |
258 (** Unique existence **) |
269 |
259 |
270 val ex1I = prove_goal HOL.thy |
260 val ex1I = prove_goalw HOL.thy [Ex1_def] |
271 "[| P(a); !!x. P(x) ==> x=a |] ==> ?! x. P(x)" |
261 "[| P(a); !!x. P(x) ==> x=a |] ==> ?! x. P(x)" |
272 (fn prems => |
262 (fn prems => |
273 [ (rtac (Ex1_def RS ssubst) 1), |
263 [REPEAT (ares_tac (prems@[exI,conjI,allI,impI]) 1)]); |
274 (REPEAT (ares_tac (prems@[exI,conjI,allI,impI]) 1)) ]); |
264 |
275 |
265 val ex1E = prove_goalw HOL.thy [Ex1_def] |
276 val ex1E = prove_goal HOL.thy |
|
277 "[| ?! x.P(x); !!x. [| P(x); ! y. P(y) --> y=x |] ==> R |] ==> R" |
266 "[| ?! x.P(x); !!x. [| P(x); ! y. P(y) --> y=x |] ==> R |] ==> R" |
278 (fn major::prems => |
267 (fn major::prems => |
279 [ (resolve_tac ([major] RL [Ex1_def RS subst] RL [exE]) 1), |
268 [rtac (major RS exE) 1, REPEAT (etac conjE 1 ORELSE ares_tac prems 1)]); |
280 (REPEAT (etac conjE 1 ORELSE ares_tac prems 1)) ]); |
|
281 |
269 |
282 |
270 |
283 (** Select: Hilbert's Epsilon-operator **) |
271 (** Select: Hilbert's Epsilon-operator **) |
284 |
272 |
285 val select_equality = prove_goal HOL.thy |
273 val select_equality = prove_goal HOL.thy |