src/HOL/HOL.thy
 author wenzelm Tue Nov 07 11:47:57 2006 +0100 (2006-11-07) changeset 21210 c17fd2df4e9e parent 21179 99f546731724 child 21218 38013c3a77a2 permissions -rw-r--r--
renamed 'const_syntax' to 'notation';
1 (*  Title:      HOL/HOL.thy
2     ID:         \$Id\$
3     Author:     Tobias Nipkow, Markus Wenzel, and Larry Paulson
4 *)
6 header {* The basis of Higher-Order Logic *}
8 theory HOL
9 imports CPure
10 uses ("simpdata.ML") "Tools/res_atpset.ML"
11 begin
13 subsection {* Primitive logic *}
15 subsubsection {* Core syntax *}
17 classes type
18 defaultsort type
20 global
22 typedecl bool
24 arities
25   bool :: type
26   "fun" :: (type, type) type
28 judgment
29   Trueprop      :: "bool => prop"                   ("(_)" 5)
31 consts
32   Not           :: "bool => bool"                   ("~ _"  40)
33   True          :: bool
34   False         :: bool
35   arbitrary     :: 'a
36   undefined     :: 'a
38   The           :: "('a => bool) => 'a"
39   All           :: "('a => bool) => bool"           (binder "ALL " 10)
40   Ex            :: "('a => bool) => bool"           (binder "EX " 10)
41   Ex1           :: "('a => bool) => bool"           (binder "EX! " 10)
42   Let           :: "['a, 'a => 'b] => 'b"
44   "="           :: "['a, 'a] => bool"               (infixl 50)
45   &             :: "[bool, bool] => bool"           (infixr 35)
46   "|"           :: "[bool, bool] => bool"           (infixr 30)
47   -->           :: "[bool, bool] => bool"           (infixr 25)
49 local
51 consts
52   If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
55 subsubsection {* Additional concrete syntax *}
57 notation (output)
58   "op ="  (infix "=" 50)
60 abbreviation
61   not_equal     :: "['a, 'a] => bool"               (infixl "~=" 50)
62   "x ~= y == ~ (x = y)"
64 notation (output)
65   not_equal  (infix "~=" 50)
67 notation (xsymbols)
68   Not  ("\<not> _"  40)
69   "op &"  (infixr "\<and>" 35)
70   "op |"  (infixr "\<or>" 30)
71   "op -->"  (infixr "\<longrightarrow>" 25)
72   not_equal  (infix "\<noteq>" 50)
74 notation (HTML output)
75   Not  ("\<not> _"  40)
76   "op &"  (infixr "\<and>" 35)
77   "op |"  (infixr "\<or>" 30)
78   not_equal  (infix "\<noteq>" 50)
80 abbreviation (iff)
81   iff :: "[bool, bool] => bool"  (infixr "<->" 25)
82   "A <-> B == A = B"
84 notation (xsymbols)
85   iff  (infixr "\<longleftrightarrow>" 25)
88 nonterminals
89   letbinds  letbind
90   case_syn  cases_syn
92 syntax
93   "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
95   "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
96   ""            :: "letbind => letbinds"                 ("_")
97   "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
98   "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
100   "_case_syntax":: "['a, cases_syn] => 'b"               ("(case _ of/ _)" 10)
101   "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
102   ""            :: "case_syn => cases_syn"               ("_")
103   "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
105 translations
106   "THE x. P"              == "The (%x. P)"
107   "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
108   "let x = a in e"        == "Let a (%x. e)"
110 print_translation {*
111 (* To avoid eta-contraction of body: *)
112 [("The", fn [Abs abs] =>
113      let val (x,t) = atomic_abs_tr' abs
114      in Syntax.const "_The" \$ x \$ t end)]
115 *}
117 syntax (xsymbols)
118   "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
119   "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
120   "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
121   "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
122 (*"_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ \<orelse> _")*)
124 syntax (HTML output)
125   "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
126   "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
127   "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
129 syntax (HOL)
130   "ALL "        :: "[idts, bool] => bool"                ("(3! _./ _)" [0, 10] 10)
131   "EX "         :: "[idts, bool] => bool"                ("(3? _./ _)" [0, 10] 10)
132   "EX! "        :: "[idts, bool] => bool"                ("(3?! _./ _)" [0, 10] 10)
135 subsubsection {* Axioms and basic definitions *}
137 axioms
138   eq_reflection:  "(x=y) ==> (x==y)"
140   refl:           "t = (t::'a)"
142   ext:            "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
143     -- {*Extensionality is built into the meta-logic, and this rule expresses
144          a related property.  It is an eta-expanded version of the traditional
145          rule, and similar to the ABS rule of HOL*}
147   the_eq_trivial: "(THE x. x = a) = (a::'a)"
149   impI:           "(P ==> Q) ==> P-->Q"
150   mp:             "[| P-->Q;  P |] ==> Q"
153 defs
154   True_def:     "True      == ((%x::bool. x) = (%x. x))"
155   All_def:      "All(P)    == (P = (%x. True))"
156   Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
157   False_def:    "False     == (!P. P)"
158   not_def:      "~ P       == P-->False"
159   and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
160   or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
161   Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
163 axioms
164   iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
165   True_or_False:  "(P=True) | (P=False)"
167 defs
168   Let_def:      "Let s f == f(s)"
169   if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
171 finalconsts
172   "op ="
173   "op -->"
174   The
175   arbitrary
176   undefined
179 subsubsection {* Generic algebraic operations *}
181 class zero =
182   fixes zero :: "'a"                       ("\<^loc>0")
184 class one =
185   fixes one  :: "'a"                       ("\<^loc>1")
187 hide (open) const zero one
189 class plus =
190   fixes plus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"   (infixl "\<^loc>+" 65)
192 class minus =
193   fixes uminus :: "'a \<Rightarrow> 'a"
194   fixes minus  :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<^loc>-" 65)
195   fixes abs    :: "'a \<Rightarrow> 'a"
197 class times =
198   fixes times :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "\<^loc>*" 70)
200 class inverse =
201   fixes inverse :: "'a \<Rightarrow> 'a"
202   fixes divide :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<^loc>'/" 70)
204 syntax
205   "_index1"  :: index    ("\<^sub>1")
206 translations
207   (index) "\<^sub>1" => (index) "\<^bsub>\<struct>\<^esub>"
209 typed_print_translation {*
210 let
211   val syntax_name = Sign.const_syntax_name (the_context ());
212   fun tr' c = (c, fn show_sorts => fn T => fn ts =>
213     if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
214     else Syntax.const Syntax.constrainC \$ Syntax.const c \$ Syntax.term_of_typ show_sorts T);
215 in map (tr' o Sign.const_syntax_name (the_context ())) ["HOL.one", "HOL.zero"] end;
216 *} -- {* show types that are presumably too general *}
218 notation
219   uminus  ("- _"  80)
221 notation (xsymbols)
222   abs  ("\<bar>_\<bar>")
223 notation (HTML output)
224   abs  ("\<bar>_\<bar>")
227 subsection {* Fundamental rules *}
229 subsubsection {* Equality *}
231 text {* Thanks to Stephan Merz *}
232 lemma subst:
233   assumes eq: "s = t" and p: "P s"
234   shows "P t"
235 proof -
236   from eq have meta: "s \<equiv> t"
237     by (rule eq_reflection)
238   from p show ?thesis
239     by (unfold meta)
240 qed
242 lemma sym: "s = t ==> t = s"
243   by (erule subst) (rule refl)
245 lemma ssubst: "t = s ==> P s ==> P t"
246   by (drule sym) (erule subst)
248 lemma trans: "[| r=s; s=t |] ==> r=t"
249   by (erule subst)
251 lemma def_imp_eq:
252   assumes meq: "A == B"
253   shows "A = B"
254   by (unfold meq) (rule refl)
256 (*a mere copy*)
257 lemma meta_eq_to_obj_eq:
258   assumes meq: "A == B"
259   shows "A = B"
260   by (unfold meq) (rule refl)
262 text {* Useful with eresolve\_tac for proving equalties from known equalities. *}
263      (* a = b
264         |   |
265         c = d   *)
266 lemma box_equals: "[| a=b;  a=c;  b=d |] ==> c=d"
267 apply (rule trans)
268 apply (rule trans)
269 apply (rule sym)
270 apply assumption+
271 done
273 text {* For calculational reasoning: *}
275 lemma forw_subst: "a = b ==> P b ==> P a"
276   by (rule ssubst)
278 lemma back_subst: "P a ==> a = b ==> P b"
279   by (rule subst)
282 subsubsection {*Congruence rules for application*}
284 (*similar to AP_THM in Gordon's HOL*)
285 lemma fun_cong: "(f::'a=>'b) = g ==> f(x)=g(x)"
286 apply (erule subst)
287 apply (rule refl)
288 done
290 (*similar to AP_TERM in Gordon's HOL and FOL's subst_context*)
291 lemma arg_cong: "x=y ==> f(x)=f(y)"
292 apply (erule subst)
293 apply (rule refl)
294 done
296 lemma arg_cong2: "\<lbrakk> a = b; c = d \<rbrakk> \<Longrightarrow> f a c = f b d"
297 apply (erule ssubst)+
298 apply (rule refl)
299 done
301 lemma cong: "[| f = g; (x::'a) = y |] ==> f(x) = g(y)"
302 apply (erule subst)+
303 apply (rule refl)
304 done
307 subsubsection {*Equality of booleans -- iff*}
309 lemma iffI: assumes prems: "P ==> Q" "Q ==> P" shows "P=Q"
310   by (iprover intro: iff [THEN mp, THEN mp] impI prems)
312 lemma iffD2: "[| P=Q; Q |] ==> P"
313   by (erule ssubst)
315 lemma rev_iffD2: "[| Q; P=Q |] ==> P"
316   by (erule iffD2)
318 lemmas iffD1 = sym [THEN iffD2, standard]
319 lemmas rev_iffD1 = sym [THEN  rev_iffD2, standard]
321 lemma iffE:
322   assumes major: "P=Q"
323       and minor: "[| P --> Q; Q --> P |] ==> R"
324   shows R
325   by (iprover intro: minor impI major [THEN iffD2] major [THEN iffD1])
328 subsubsection {*True*}
330 lemma TrueI: "True"
331   by (unfold True_def) (rule refl)
333 lemma eqTrueI: "P ==> P=True"
334   by (iprover intro: iffI TrueI)
336 lemma eqTrueE: "P=True ==> P"
337 apply (erule iffD2)
338 apply (rule TrueI)
339 done
342 subsubsection {*Universal quantifier*}
344 lemma allI: assumes p: "!!x::'a. P(x)" shows "ALL x. P(x)"
345 apply (unfold All_def)
346 apply (iprover intro: ext eqTrueI p)
347 done
349 lemma spec: "ALL x::'a. P(x) ==> P(x)"
350 apply (unfold All_def)
351 apply (rule eqTrueE)
352 apply (erule fun_cong)
353 done
355 lemma allE:
356   assumes major: "ALL x. P(x)"
357       and minor: "P(x) ==> R"
358   shows "R"
359 by (iprover intro: minor major [THEN spec])
361 lemma all_dupE:
362   assumes major: "ALL x. P(x)"
363       and minor: "[| P(x); ALL x. P(x) |] ==> R"
364   shows "R"
365 by (iprover intro: minor major major [THEN spec])
368 subsubsection {*False*}
369 (*Depends upon spec; it is impossible to do propositional logic before quantifiers!*)
371 lemma FalseE: "False ==> P"
372 apply (unfold False_def)
373 apply (erule spec)
374 done
376 lemma False_neq_True: "False=True ==> P"
377 by (erule eqTrueE [THEN FalseE])
380 subsubsection {*Negation*}
382 lemma notI:
383   assumes p: "P ==> False"
384   shows "~P"
385 apply (unfold not_def)
386 apply (iprover intro: impI p)
387 done
389 lemma False_not_True: "False ~= True"
390 apply (rule notI)
391 apply (erule False_neq_True)
392 done
394 lemma True_not_False: "True ~= False"
395 apply (rule notI)
396 apply (drule sym)
397 apply (erule False_neq_True)
398 done
400 lemma notE: "[| ~P;  P |] ==> R"
401 apply (unfold not_def)
402 apply (erule mp [THEN FalseE])
403 apply assumption
404 done
406 (* Alternative ~ introduction rule: [| P ==> ~ Pa; P ==> Pa |] ==> ~ P *)
407 lemmas notI2 = notE [THEN notI, standard]
410 subsubsection {*Implication*}
412 lemma impE:
413   assumes "P-->Q" "P" "Q ==> R"
414   shows "R"
415 by (iprover intro: prems mp)
417 (* Reduces Q to P-->Q, allowing substitution in P. *)
418 lemma rev_mp: "[| P;  P --> Q |] ==> Q"
419 by (iprover intro: mp)
421 lemma contrapos_nn:
422   assumes major: "~Q"
423       and minor: "P==>Q"
424   shows "~P"
425 by (iprover intro: notI minor major [THEN notE])
427 (*not used at all, but we already have the other 3 combinations *)
428 lemma contrapos_pn:
429   assumes major: "Q"
430       and minor: "P ==> ~Q"
431   shows "~P"
432 by (iprover intro: notI minor major notE)
434 lemma not_sym: "t ~= s ==> s ~= t"
435 apply (erule contrapos_nn)
436 apply (erule sym)
437 done
439 (*still used in HOLCF*)
440 lemma rev_contrapos:
441   assumes pq: "P ==> Q"
442       and nq: "~Q"
443   shows "~P"
444 apply (rule nq [THEN contrapos_nn])
445 apply (erule pq)
446 done
448 subsubsection {*Existential quantifier*}
450 lemma exI: "P x ==> EX x::'a. P x"
451 apply (unfold Ex_def)
452 apply (iprover intro: allI allE impI mp)
453 done
455 lemma exE:
456   assumes major: "EX x::'a. P(x)"
457       and minor: "!!x. P(x) ==> Q"
458   shows "Q"
459 apply (rule major [unfolded Ex_def, THEN spec, THEN mp])
460 apply (iprover intro: impI [THEN allI] minor)
461 done
464 subsubsection {*Conjunction*}
466 lemma conjI: "[| P; Q |] ==> P&Q"
467 apply (unfold and_def)
468 apply (iprover intro: impI [THEN allI] mp)
469 done
471 lemma conjunct1: "[| P & Q |] ==> P"
472 apply (unfold and_def)
473 apply (iprover intro: impI dest: spec mp)
474 done
476 lemma conjunct2: "[| P & Q |] ==> Q"
477 apply (unfold and_def)
478 apply (iprover intro: impI dest: spec mp)
479 done
481 lemma conjE:
482   assumes major: "P&Q"
483       and minor: "[| P; Q |] ==> R"
484   shows "R"
485 apply (rule minor)
486 apply (rule major [THEN conjunct1])
487 apply (rule major [THEN conjunct2])
488 done
490 lemma context_conjI:
491   assumes prems: "P" "P ==> Q" shows "P & Q"
492 by (iprover intro: conjI prems)
495 subsubsection {*Disjunction*}
497 lemma disjI1: "P ==> P|Q"
498 apply (unfold or_def)
499 apply (iprover intro: allI impI mp)
500 done
502 lemma disjI2: "Q ==> P|Q"
503 apply (unfold or_def)
504 apply (iprover intro: allI impI mp)
505 done
507 lemma disjE:
508   assumes major: "P|Q"
509       and minorP: "P ==> R"
510       and minorQ: "Q ==> R"
511   shows "R"
512 by (iprover intro: minorP minorQ impI
513                  major [unfolded or_def, THEN spec, THEN mp, THEN mp])
516 subsubsection {*Classical logic*}
518 lemma classical:
519   assumes prem: "~P ==> P"
520   shows "P"
521 apply (rule True_or_False [THEN disjE, THEN eqTrueE])
522 apply assumption
523 apply (rule notI [THEN prem, THEN eqTrueI])
524 apply (erule subst)
525 apply assumption
526 done
528 lemmas ccontr = FalseE [THEN classical, standard]
530 (*notE with premises exchanged; it discharges ~R so that it can be used to
531   make elimination rules*)
532 lemma rev_notE:
533   assumes premp: "P"
534       and premnot: "~R ==> ~P"
535   shows "R"
536 apply (rule ccontr)
537 apply (erule notE [OF premnot premp])
538 done
540 (*Double negation law*)
541 lemma notnotD: "~~P ==> P"
542 apply (rule classical)
543 apply (erule notE)
544 apply assumption
545 done
547 lemma contrapos_pp:
548   assumes p1: "Q"
549       and p2: "~P ==> ~Q"
550   shows "P"
551 by (iprover intro: classical p1 p2 notE)
554 subsubsection {*Unique existence*}
556 lemma ex1I:
557   assumes prems: "P a" "!!x. P(x) ==> x=a"
558   shows "EX! x. P(x)"
559 by (unfold Ex1_def, iprover intro: prems exI conjI allI impI)
561 text{*Sometimes easier to use: the premises have no shared variables.  Safe!*}
562 lemma ex_ex1I:
563   assumes ex_prem: "EX x. P(x)"
564       and eq: "!!x y. [| P(x); P(y) |] ==> x=y"
565   shows "EX! x. P(x)"
566 by (iprover intro: ex_prem [THEN exE] ex1I eq)
568 lemma ex1E:
569   assumes major: "EX! x. P(x)"
570       and minor: "!!x. [| P(x);  ALL y. P(y) --> y=x |] ==> R"
571   shows "R"
572 apply (rule major [unfolded Ex1_def, THEN exE])
573 apply (erule conjE)
574 apply (iprover intro: minor)
575 done
577 lemma ex1_implies_ex: "EX! x. P x ==> EX x. P x"
578 apply (erule ex1E)
579 apply (rule exI)
580 apply assumption
581 done
584 subsubsection {*THE: definite description operator*}
586 lemma the_equality:
587   assumes prema: "P a"
588       and premx: "!!x. P x ==> x=a"
589   shows "(THE x. P x) = a"
590 apply (rule trans [OF _ the_eq_trivial])
591 apply (rule_tac f = "The" in arg_cong)
592 apply (rule ext)
593 apply (rule iffI)
594  apply (erule premx)
595 apply (erule ssubst, rule prema)
596 done
598 lemma theI:
599   assumes "P a" and "!!x. P x ==> x=a"
600   shows "P (THE x. P x)"
601 by (iprover intro: prems the_equality [THEN ssubst])
603 lemma theI': "EX! x. P x ==> P (THE x. P x)"
604 apply (erule ex1E)
605 apply (erule theI)
606 apply (erule allE)
607 apply (erule mp)
608 apply assumption
609 done
611 (*Easier to apply than theI: only one occurrence of P*)
612 lemma theI2:
613   assumes "P a" "!!x. P x ==> x=a" "!!x. P x ==> Q x"
614   shows "Q (THE x. P x)"
615 by (iprover intro: prems theI)
617 lemma the1_equality [elim?]: "[| EX!x. P x; P a |] ==> (THE x. P x) = a"
618 apply (rule the_equality)
619 apply  assumption
620 apply (erule ex1E)
621 apply (erule all_dupE)
622 apply (drule mp)
623 apply  assumption
624 apply (erule ssubst)
625 apply (erule allE)
626 apply (erule mp)
627 apply assumption
628 done
630 lemma the_sym_eq_trivial: "(THE y. x=y) = x"
631 apply (rule the_equality)
632 apply (rule refl)
633 apply (erule sym)
634 done
637 subsubsection {*Classical intro rules for disjunction and existential quantifiers*}
639 lemma disjCI:
640   assumes "~Q ==> P" shows "P|Q"
641 apply (rule classical)
642 apply (iprover intro: prems disjI1 disjI2 notI elim: notE)
643 done
645 lemma excluded_middle: "~P | P"
646 by (iprover intro: disjCI)
648 text {*
649   case distinction as a natural deduction rule.
650   Note that @{term "~P"} is the second case, not the first
651 *}
652 lemma case_split_thm:
653   assumes prem1: "P ==> Q"
654       and prem2: "~P ==> Q"
655   shows "Q"
656 apply (rule excluded_middle [THEN disjE])
657 apply (erule prem2)
658 apply (erule prem1)
659 done
660 lemmas case_split = case_split_thm [case_names True False]
662 (*Classical implies (-->) elimination. *)
663 lemma impCE:
664   assumes major: "P-->Q"
665       and minor: "~P ==> R" "Q ==> R"
666   shows "R"
667 apply (rule excluded_middle [of P, THEN disjE])
668 apply (iprover intro: minor major [THEN mp])+
669 done
671 (*This version of --> elimination works on Q before P.  It works best for
672   those cases in which P holds "almost everywhere".  Can't install as
673   default: would break old proofs.*)
674 lemma impCE':
675   assumes major: "P-->Q"
676       and minor: "Q ==> R" "~P ==> R"
677   shows "R"
678 apply (rule excluded_middle [of P, THEN disjE])
679 apply (iprover intro: minor major [THEN mp])+
680 done
682 (*Classical <-> elimination. *)
683 lemma iffCE:
684   assumes major: "P=Q"
685       and minor: "[| P; Q |] ==> R"  "[| ~P; ~Q |] ==> R"
686   shows "R"
687 apply (rule major [THEN iffE])
688 apply (iprover intro: minor elim: impCE notE)
689 done
691 lemma exCI:
692   assumes "ALL x. ~P(x) ==> P(a)"
693   shows "EX x. P(x)"
694 apply (rule ccontr)
695 apply (iprover intro: prems exI allI notI notE [of "\<exists>x. P x"])
696 done
699 subsubsection {* Intuitionistic Reasoning *}
701 lemma impE':
702   assumes 1: "P --> Q"
703     and 2: "Q ==> R"
704     and 3: "P --> Q ==> P"
705   shows R
706 proof -
707   from 3 and 1 have P .
708   with 1 have Q by (rule impE)
709   with 2 show R .
710 qed
712 lemma allE':
713   assumes 1: "ALL x. P x"
714     and 2: "P x ==> ALL x. P x ==> Q"
715   shows Q
716 proof -
717   from 1 have "P x" by (rule spec)
718   from this and 1 show Q by (rule 2)
719 qed
721 lemma notE':
722   assumes 1: "~ P"
723     and 2: "~ P ==> P"
724   shows R
725 proof -
726   from 2 and 1 have P .
727   with 1 show R by (rule notE)
728 qed
730 lemmas [Pure.elim!] = disjE iffE FalseE conjE exE
731   and [Pure.intro!] = iffI conjI impI TrueI notI allI refl
732   and [Pure.elim 2] = allE notE' impE'
733   and [Pure.intro] = exI disjI2 disjI1
735 lemmas [trans] = trans
736   and [sym] = sym not_sym
737   and [Pure.elim?] = iffD1 iffD2 impE
740 subsubsection {* Atomizing meta-level connectives *}
742 lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
743 proof
744   assume "!!x. P x"
745   show "ALL x. P x" by (rule allI)
746 next
747   assume "ALL x. P x"
748   thus "!!x. P x" by (rule allE)
749 qed
751 lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
752 proof
753   assume r: "A ==> B"
754   show "A --> B" by (rule impI) (rule r)
755 next
756   assume "A --> B" and A
757   thus B by (rule mp)
758 qed
760 lemma atomize_not: "(A ==> False) == Trueprop (~A)"
761 proof
762   assume r: "A ==> False"
763   show "~A" by (rule notI) (rule r)
764 next
765   assume "~A" and A
766   thus False by (rule notE)
767 qed
769 lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
770 proof
771   assume "x == y"
772   show "x = y" by (unfold prems) (rule refl)
773 next
774   assume "x = y"
775   thus "x == y" by (rule eq_reflection)
776 qed
778 lemma atomize_conj [atomize]:
779   includes meta_conjunction_syntax
780   shows "(A && B) == Trueprop (A & B)"
781 proof
782   assume conj: "A && B"
783   show "A & B"
784   proof (rule conjI)
785     from conj show A by (rule conjunctionD1)
786     from conj show B by (rule conjunctionD2)
787   qed
788 next
789   assume conj: "A & B"
790   show "A && B"
791   proof -
792     from conj show A ..
793     from conj show B ..
794   qed
795 qed
797 lemmas [symmetric, rulify] = atomize_all atomize_imp
798   and [symmetric, defn] = atomize_all atomize_imp atomize_eq
801 subsection {* Package setup *}
803 subsubsection {* Fundamental ML bindings *}
805 ML {*
806 structure HOL =
807 struct
808   (*FIXME reduce this to a minimum*)
809   val eq_reflection = thm "eq_reflection";
810   val def_imp_eq = thm "def_imp_eq";
811   val meta_eq_to_obj_eq = thm "meta_eq_to_obj_eq";
812   val ccontr = thm "ccontr";
813   val impI = thm "impI";
814   val impCE = thm "impCE";
815   val notI = thm "notI";
816   val notE = thm "notE";
817   val iffI = thm "iffI";
818   val iffCE = thm "iffCE";
819   val conjI = thm "conjI";
820   val conjE = thm "conjE";
821   val disjCI = thm "disjCI";
822   val disjE = thm "disjE";
823   val TrueI = thm "TrueI";
824   val FalseE = thm "FalseE";
825   val allI = thm "allI";
826   val allE = thm "allE";
827   val exI = thm "exI";
828   val exE = thm "exE";
829   val ex_ex1I = thm "ex_ex1I";
830   val the_equality = thm "the_equality";
831   val mp = thm "mp";
832   val rev_mp = thm "rev_mp"
833   val classical = thm "classical";
834   val subst = thm "subst";
835   val refl = thm "refl";
836   val sym = thm "sym";
837   val trans = thm "trans";
838   val arg_cong = thm "arg_cong";
839   val iffD1 = thm "iffD1";
840   val iffD2 = thm "iffD2";
841   val disjE = thm "disjE";
842   val conjE = thm "conjE";
843   val exE = thm "exE";
844   val contrapos_nn = thm "contrapos_nn";
845   val contrapos_pp = thm "contrapos_pp";
846   val notnotD = thm "notnotD";
847   val conjunct1 = thm "conjunct1";
848   val conjunct2 = thm "conjunct2";
849   val spec = thm "spec";
850   val imp_cong = thm "imp_cong";
851   val the_sym_eq_trivial = thm "the_sym_eq_trivial";
852   val triv_forall_equality = thm "triv_forall_equality";
853   val case_split = thm "case_split_thm";
854 end
855 *}
858 subsubsection {* Classical Reasoner setup *}
860 lemma thin_refl:
861   "\<And>X. \<lbrakk> x=x; PROP W \<rbrakk> \<Longrightarrow> PROP W" .
863 ML {*
864 structure Hypsubst = HypsubstFun(
865 struct
866   structure Simplifier = Simplifier
867   val dest_eq = HOLogic.dest_eq_typ
868   val dest_Trueprop = HOLogic.dest_Trueprop
869   val dest_imp = HOLogic.dest_imp
870   val eq_reflection = HOL.eq_reflection
871   val rev_eq_reflection = HOL.def_imp_eq
872   val imp_intr = HOL.impI
873   val rev_mp = HOL.rev_mp
874   val subst = HOL.subst
875   val sym = HOL.sym
876   val thin_refl = thm "thin_refl";
877 end);
879 structure Classical = ClassicalFun(
880 struct
881   val mp = HOL.mp
882   val not_elim = HOL.notE
883   val classical = HOL.classical
884   val sizef = Drule.size_of_thm
885   val hyp_subst_tacs = [Hypsubst.hyp_subst_tac]
886 end);
888 structure BasicClassical: BASIC_CLASSICAL = Classical;
889 *}
891 setup {*
892 let
893   (*prevent substitution on bool*)
894   fun hyp_subst_tac' i thm = if i <= Thm.nprems_of thm andalso
895     Term.exists_Const (fn ("op =", Type (_, [T, _])) => T <> Type ("bool", []) | _ => false)
896       (nth (Thm.prems_of thm) (i - 1)) then Hypsubst.hyp_subst_tac i thm else no_tac thm;
897 in
898   Hypsubst.hypsubst_setup
899   #> ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac)
900   #> Classical.setup
901   #> ResAtpset.setup
902 end
903 *}
905 declare iffI [intro!]
906   and notI [intro!]
907   and impI [intro!]
908   and disjCI [intro!]
909   and conjI [intro!]
910   and TrueI [intro!]
911   and refl [intro!]
913 declare iffCE [elim!]
914   and FalseE [elim!]
915   and impCE [elim!]
916   and disjE [elim!]
917   and conjE [elim!]
918   and conjE [elim!]
920 declare ex_ex1I [intro!]
921   and allI [intro!]
922   and the_equality [intro]
923   and exI [intro]
925 declare exE [elim!]
926   allE [elim]
928 ML {*
929 structure HOL =
930 struct
932 open HOL;
934 val claset = Classical.claset_of (the_context ());
936 end;
937 *}
939 lemma contrapos_np: "~ Q ==> (~ P ==> Q) ==> P"
940   apply (erule swap)
941   apply (erule (1) meta_mp)
942   done
944 declare ex_ex1I [rule del, intro! 2]
945   and ex1I [intro]
947 lemmas [intro?] = ext
948   and [elim?] = ex1_implies_ex
950 (*Better then ex1E for classical reasoner: needs no quantifier duplication!*)
951 lemma alt_ex1E [elim!]:
952   assumes major: "\<exists>!x. P x"
953       and prem: "\<And>x. \<lbrakk> P x; \<forall>y y'. P y \<and> P y' \<longrightarrow> y = y' \<rbrakk> \<Longrightarrow> R"
954   shows R
955 apply (rule ex1E [OF major])
956 apply (rule prem)
957 apply (tactic "ares_tac [HOL.allI] 1")+
958 apply (tactic "etac (Classical.dup_elim HOL.allE) 1")
959 by iprover
961 ML {*
962 structure Blast = BlastFun(
963 struct
964   type claset = Classical.claset
965   val equality_name = "op ="
966   val not_name = "Not"
967   val notE = HOL.notE
968   val ccontr = HOL.ccontr
969   val contr_tac = Classical.contr_tac
970   val dup_intr = Classical.dup_intr
971   val hyp_subst_tac = Hypsubst.blast_hyp_subst_tac
972   val claset	= Classical.claset
973   val rep_cs = Classical.rep_cs
974   val cla_modifiers = Classical.cla_modifiers
975   val cla_meth' = Classical.cla_meth'
976 end);
978 structure HOL =
979 struct
981 open HOL;
983 val Blast_tac = Blast.Blast_tac;
984 val blast_tac = Blast.blast_tac;
986 fun case_tac a = res_inst_tac [("P", a)] case_split;
988 (* combination of (spec RS spec RS ...(j times) ... spec RS mp) *)
989 local
990   fun wrong_prem (Const ("All", _) \$ (Abs (_, _, t))) = wrong_prem t
991     | wrong_prem (Bound _) = true
992     | wrong_prem _ = false;
993   val filter_right = filter (not o wrong_prem o HOLogic.dest_Trueprop o hd o Thm.prems_of);
994 in
995   fun smp i = funpow i (fn m => filter_right ([spec] RL m)) ([mp]);
996   fun smp_tac j = EVERY'[dresolve_tac (smp j), atac];
997 end;
999 fun strip_tac i = REPEAT (resolve_tac [impI, allI] i);
1001 fun Trueprop_conv conv ct = (case term_of ct of
1002     Const ("Trueprop", _) \$ _ =>
1003       let val (ct1, ct2) = Thm.dest_comb ct
1004       in Thm.combination (Thm.reflexive ct1) (conv ct2) end
1005   | _ => raise TERM ("Trueprop_conv", []));
1007 fun Equals_conv conv ct = (case term_of ct of
1008     Const ("op =", _) \$ _ \$ _ =>
1009       let
1010         val ((ct1, ct2), ct3) = (apfst Thm.dest_comb o Thm.dest_comb) ct;
1011       in Thm.combination (Thm.combination (Thm.reflexive ct1) (conv ct2)) (conv ct3) end
1012   | _ => conv ct);
1014 fun constrain_op_eq_thms thy thms =
1015   let
1016     fun add_eq (Const ("op =", ty)) =
1017           fold (insert (eq_fst (op =)))
1018             (Term.add_tvarsT ty [])
1019       | add_eq _ =
1020           I
1021     val eqs = fold (fold_aterms add_eq o Thm.prop_of) thms [];
1022     val instT = map (fn (v_i, sort) =>
1023       (Thm.ctyp_of thy (TVar (v_i, sort)),
1024          Thm.ctyp_of thy (TVar (v_i, Sorts.inter_sort (Sign.classes_of thy) (sort, [HOLogic.class_eq]))))) eqs;
1025   in
1026     thms
1027     |> map (Thm.instantiate (instT, []))
1028   end;
1030 end;
1031 *}
1033 setup Blast.setup
1036 subsubsection {* Simplifier *}
1038 lemma eta_contract_eq: "(%s. f s) = f" ..
1040 lemma simp_thms:
1041   shows not_not: "(~ ~ P) = P"
1042   and Not_eq_iff: "((~P) = (~Q)) = (P = Q)"
1043   and
1044     "(P ~= Q) = (P = (~Q))"
1045     "(P | ~P) = True"    "(~P | P) = True"
1046     "(x = x) = True"
1047   and not_True_eq_False: "(\<not> True) = False"
1048   and not_False_eq_True: "(\<not> False) = True"
1049   and
1050     "(~P) ~= P"  "P ~= (~P)"
1051     "(True=P) = P"
1052   and eq_True: "(P = True) = P"
1053   and "(False=P) = (~P)"
1054   and eq_False: "(P = False) = (\<not> P)"
1055   and
1056     "(True --> P) = P"  "(False --> P) = True"
1057     "(P --> True) = True"  "(P --> P) = True"
1058     "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
1059     "(P & True) = P"  "(True & P) = P"
1060     "(P & False) = False"  "(False & P) = False"
1061     "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
1062     "(P & ~P) = False"    "(~P & P) = False"
1063     "(P | True) = True"  "(True | P) = True"
1064     "(P | False) = P"  "(False | P) = P"
1065     "(P | P) = P"  "(P | (P | Q)) = (P | Q)" and
1066     "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
1067     -- {* needed for the one-point-rule quantifier simplification procs *}
1068     -- {* essential for termination!! *} and
1069     "!!P. (EX x. x=t & P(x)) = P(t)"
1070     "!!P. (EX x. t=x & P(x)) = P(t)"
1071     "!!P. (ALL x. x=t --> P(x)) = P(t)"
1072     "!!P. (ALL x. t=x --> P(x)) = P(t)"
1073   by (blast, blast, blast, blast, blast, iprover+)
1075 lemma disj_absorb: "(A | A) = A"
1076   by blast
1078 lemma disj_left_absorb: "(A | (A | B)) = (A | B)"
1079   by blast
1081 lemma conj_absorb: "(A & A) = A"
1082   by blast
1084 lemma conj_left_absorb: "(A & (A & B)) = (A & B)"
1085   by blast
1087 lemma eq_ac:
1088   shows eq_commute: "(a=b) = (b=a)"
1089     and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
1090     and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (iprover, blast+)
1091 lemma neq_commute: "(a~=b) = (b~=a)" by iprover
1093 lemma conj_comms:
1094   shows conj_commute: "(P&Q) = (Q&P)"
1095     and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by iprover+
1096 lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by iprover
1098 lemmas conj_ac = conj_commute conj_left_commute conj_assoc
1100 lemma disj_comms:
1101   shows disj_commute: "(P|Q) = (Q|P)"
1102     and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by iprover+
1103 lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by iprover
1105 lemmas disj_ac = disj_commute disj_left_commute disj_assoc
1107 lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by iprover
1108 lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by iprover
1110 lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by iprover
1111 lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by iprover
1113 lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by iprover
1114 lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by iprover
1115 lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by iprover
1117 text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
1118 lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
1119 lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
1121 lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
1122 lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
1124 lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
1125   by iprover
1127 lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by iprover
1128 lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
1129 lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
1130 lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
1131 lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
1132 lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
1133   by blast
1134 lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
1136 lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by iprover
1139 lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
1140   -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
1141   -- {* cases boil down to the same thing. *}
1142   by blast
1144 lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
1145 lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
1146 lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by iprover
1147 lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by iprover
1149 lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by iprover
1150 lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by iprover
1152 text {*
1153   \medskip The @{text "&"} congruence rule: not included by default!
1154   May slow rewrite proofs down by as much as 50\% *}
1156 lemma conj_cong:
1157     "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
1158   by iprover
1160 lemma rev_conj_cong:
1161     "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
1162   by iprover
1164 text {* The @{text "|"} congruence rule: not included by default! *}
1166 lemma disj_cong:
1167     "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
1168   by blast
1171 text {* \medskip if-then-else rules *}
1173 lemma if_True: "(if True then x else y) = x"
1174   by (unfold if_def) blast
1176 lemma if_False: "(if False then x else y) = y"
1177   by (unfold if_def) blast
1179 lemma if_P: "P ==> (if P then x else y) = x"
1180   by (unfold if_def) blast
1182 lemma if_not_P: "~P ==> (if P then x else y) = y"
1183   by (unfold if_def) blast
1185 lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
1186   apply (rule case_split [of Q])
1187    apply (simplesubst if_P)
1188     prefer 3 apply (simplesubst if_not_P, blast+)
1189   done
1191 lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
1192 by (simplesubst split_if, blast)
1194 lemmas if_splits = split_if split_if_asm
1196 lemma if_cancel: "(if c then x else x) = x"
1197 by (simplesubst split_if, blast)
1199 lemma if_eq_cancel: "(if x = y then y else x) = x"
1200 by (simplesubst split_if, blast)
1202 lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
1203   -- {* This form is useful for expanding @{text "if"}s on the RIGHT of the @{text "==>"} symbol. *}
1204   by (rule split_if)
1206 lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
1207   -- {* And this form is useful for expanding @{text "if"}s on the LEFT. *}
1208   apply (simplesubst split_if, blast)
1209   done
1211 lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) iprover
1212 lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) iprover
1214 text {* \medskip let rules for simproc *}
1216 lemma Let_folded: "f x \<equiv> g x \<Longrightarrow>  Let x f \<equiv> Let x g"
1217   by (unfold Let_def)
1219 lemma Let_unfold: "f x \<equiv> g \<Longrightarrow>  Let x f \<equiv> g"
1220   by (unfold Let_def)
1222 text {*
1223   The following copy of the implication operator is useful for
1224   fine-tuning congruence rules.  It instructs the simplifier to simplify
1225   its premise.
1226 *}
1228 constdefs
1229   simp_implies :: "[prop, prop] => prop"  (infixr "=simp=>" 1)
1230   "simp_implies \<equiv> op ==>"
1232 lemma simp_impliesI:
1233   assumes PQ: "(PROP P \<Longrightarrow> PROP Q)"
1234   shows "PROP P =simp=> PROP Q"
1235   apply (unfold simp_implies_def)
1236   apply (rule PQ)
1237   apply assumption
1238   done
1240 lemma simp_impliesE:
1241   assumes PQ:"PROP P =simp=> PROP Q"
1242   and P: "PROP P"
1243   and QR: "PROP Q \<Longrightarrow> PROP R"
1244   shows "PROP R"
1245   apply (rule QR)
1246   apply (rule PQ [unfolded simp_implies_def])
1247   apply (rule P)
1248   done
1250 lemma simp_implies_cong:
1251   assumes PP' :"PROP P == PROP P'"
1252   and P'QQ': "PROP P' ==> (PROP Q == PROP Q')"
1253   shows "(PROP P =simp=> PROP Q) == (PROP P' =simp=> PROP Q')"
1254 proof (unfold simp_implies_def, rule equal_intr_rule)
1255   assume PQ: "PROP P \<Longrightarrow> PROP Q"
1256   and P': "PROP P'"
1257   from PP' [symmetric] and P' have "PROP P"
1258     by (rule equal_elim_rule1)
1259   hence "PROP Q" by (rule PQ)
1260   with P'QQ' [OF P'] show "PROP Q'" by (rule equal_elim_rule1)
1261 next
1262   assume P'Q': "PROP P' \<Longrightarrow> PROP Q'"
1263   and P: "PROP P"
1264   from PP' and P have P': "PROP P'" by (rule equal_elim_rule1)
1265   hence "PROP Q'" by (rule P'Q')
1266   with P'QQ' [OF P', symmetric] show "PROP Q"
1267     by (rule equal_elim_rule1)
1268 qed
1270 lemma uncurry:
1271   assumes "P \<longrightarrow> Q \<longrightarrow> R"
1272   shows "P \<and> Q \<longrightarrow> R"
1273   using prems by blast
1275 lemma iff_allI:
1276   assumes "\<And>x. P x = Q x"
1277   shows "(\<forall>x. P x) = (\<forall>x. Q x)"
1278   using prems by blast
1280 lemma iff_exI:
1281   assumes "\<And>x. P x = Q x"
1282   shows "(\<exists>x. P x) = (\<exists>x. Q x)"
1283   using prems by blast
1285 lemma all_comm:
1286   "(\<forall>x y. P x y) = (\<forall>y x. P x y)"
1287   by blast
1289 lemma ex_comm:
1290   "(\<exists>x y. P x y) = (\<exists>y x. P x y)"
1291   by blast
1293 use "simpdata.ML"
1294 setup {*
1295   Simplifier.method_setup Splitter.split_modifiers
1296   #> (fn thy => (change_simpset_of thy (fn _ => HOL.simpset_simprocs); thy))
1297   #> Splitter.setup
1298   #> Clasimp.setup
1299   #> EqSubst.setup
1300 *}
1302 lemma True_implies_equals: "(True \<Longrightarrow> PROP P) \<equiv> PROP P"
1303 proof
1304   assume prem: "True \<Longrightarrow> PROP P"
1305   from prem [OF TrueI] show "PROP P" .
1306 next
1307   assume "PROP P"
1308   show "PROP P" .
1309 qed
1311 lemma ex_simps:
1312   "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
1313   "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
1314   "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
1315   "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
1316   "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
1317   "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
1318   -- {* Miniscoping: pushing in existential quantifiers. *}
1319   by (iprover | blast)+
1321 lemma all_simps:
1322   "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
1323   "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
1324   "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
1325   "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
1326   "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
1327   "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
1328   -- {* Miniscoping: pushing in universal quantifiers. *}
1329   by (iprover | blast)+
1331 declare triv_forall_equality [simp] (*prunes params*)
1332   and True_implies_equals [simp] (*prune asms `True'*)
1333   and if_True [simp]
1334   and if_False [simp]
1335   and if_cancel [simp]
1336   and if_eq_cancel [simp]
1337   and imp_disjL [simp]
1338   (*In general it seems wrong to add distributive laws by default: they
1339     might cause exponential blow-up.  But imp_disjL has been in for a while
1340     and cannot be removed without affecting existing proofs.  Moreover,
1341     rewriting by "(P|Q --> R) = ((P-->R)&(Q-->R))" might be justified on the
1342     grounds that it allows simplification of R in the two cases.*)
1343   and conj_assoc [simp]
1344   and disj_assoc [simp]
1345   and de_Morgan_conj [simp]
1346   and de_Morgan_disj [simp]
1347   and imp_disj1 [simp]
1348   and imp_disj2 [simp]
1349   and not_imp [simp]
1350   and disj_not1 [simp]
1351   and not_all [simp]
1352   and not_ex [simp]
1353   and cases_simp [simp]
1354   and the_eq_trivial [simp]
1355   and the_sym_eq_trivial [simp]
1356   and ex_simps [simp]
1357   and all_simps [simp]
1358   and simp_thms [simp]
1359   and imp_cong [cong]
1360   and simp_implies_cong [cong]
1361   and split_if [split]
1363 ML {*
1364 structure HOL =
1365 struct
1367 open HOL;
1369 val simpset = Simplifier.simpset_of (the_context ());
1371 end;
1372 *}
1374 text {* Simplifies x assuming c and y assuming ~c *}
1375 lemma if_cong:
1376   assumes "b = c"
1377       and "c \<Longrightarrow> x = u"
1378       and "\<not> c \<Longrightarrow> y = v"
1379   shows "(if b then x else y) = (if c then u else v)"
1380   unfolding if_def using prems by simp
1382 text {* Prevents simplification of x and y:
1383   faster and allows the execution of functional programs. *}
1384 lemma if_weak_cong [cong]:
1385   assumes "b = c"
1386   shows "(if b then x else y) = (if c then x else y)"
1387   using prems by (rule arg_cong)
1389 text {* Prevents simplification of t: much faster *}
1390 lemma let_weak_cong:
1391   assumes "a = b"
1392   shows "(let x = a in t x) = (let x = b in t x)"
1393   using prems by (rule arg_cong)
1395 text {* To tidy up the result of a simproc.  Only the RHS will be simplified. *}
1396 lemma eq_cong2:
1397   assumes "u = u'"
1398   shows "(t \<equiv> u) \<equiv> (t \<equiv> u')"
1399   using prems by simp
1401 lemma if_distrib:
1402   "f (if c then x else y) = (if c then f x else f y)"
1403   by simp
1405 text {* For expand\_case\_tac *}
1406 lemma expand_case:
1407   assumes "P \<Longrightarrow> Q True"
1408       and "~P \<Longrightarrow> Q False"
1409   shows "Q P"
1410 proof (tactic {* HOL.case_tac "P" 1 *})
1411   assume P
1412   then show "Q P" by simp
1413 next
1414   assume "\<not> P"
1415   then have "P = False" by simp
1416   with prems show "Q P" by simp
1417 qed
1419 text {* This lemma restricts the effect of the rewrite rule u=v to the left-hand
1420   side of an equality.  Used in {Integ,Real}/simproc.ML *}
1421 lemma restrict_to_left:
1422   assumes "x = y"
1423   shows "(x = z) = (y = z)"
1424   using prems by simp
1427 subsubsection {* Generic cases and induction *}
1429 text {* Rule projections: *}
1431 ML {*
1432 structure ProjectRule = ProjectRuleFun
1433 (struct
1434   val conjunct1 = thm "conjunct1";
1435   val conjunct2 = thm "conjunct2";
1436   val mp = thm "mp";
1437 end)
1438 *}
1440 constdefs
1441   induct_forall where "induct_forall P == \<forall>x. P x"
1442   induct_implies where "induct_implies A B == A \<longrightarrow> B"
1443   induct_equal where "induct_equal x y == x = y"
1444   induct_conj where "induct_conj A B == A \<and> B"
1446 lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
1447   by (unfold atomize_all induct_forall_def)
1449 lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
1450   by (unfold atomize_imp induct_implies_def)
1452 lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
1453   by (unfold atomize_eq induct_equal_def)
1455 lemma induct_conj_eq:
1456   includes meta_conjunction_syntax
1457   shows "(A && B) == Trueprop (induct_conj A B)"
1458   by (unfold atomize_conj induct_conj_def)
1460 lemmas induct_atomize = induct_forall_eq induct_implies_eq induct_equal_eq induct_conj_eq
1461 lemmas induct_rulify [symmetric, standard] = induct_atomize
1462 lemmas induct_rulify_fallback =
1463   induct_forall_def induct_implies_def induct_equal_def induct_conj_def
1466 lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
1467     induct_conj (induct_forall A) (induct_forall B)"
1468   by (unfold induct_forall_def induct_conj_def) iprover
1470 lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
1471     induct_conj (induct_implies C A) (induct_implies C B)"
1472   by (unfold induct_implies_def induct_conj_def) iprover
1474 lemma induct_conj_curry: "(induct_conj A B ==> PROP C) == (A ==> B ==> PROP C)"
1475 proof
1476   assume r: "induct_conj A B ==> PROP C" and A B
1477   show "PROP C" by (rule r) (simp add: induct_conj_def `A` `B`)
1478 next
1479   assume r: "A ==> B ==> PROP C" and "induct_conj A B"
1480   show "PROP C" by (rule r) (simp_all add: `induct_conj A B` [unfolded induct_conj_def])
1481 qed
1483 lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
1485 hide const induct_forall induct_implies induct_equal induct_conj
1487 text {* Method setup. *}
1489 ML {*
1490   structure InductMethod = InductMethodFun
1491   (struct
1492     val cases_default = thm "case_split"
1493     val atomize = thms "induct_atomize"
1494     val rulify = thms "induct_rulify"
1495     val rulify_fallback = thms "induct_rulify_fallback"
1496   end);
1497 *}
1499 setup InductMethod.setup
1503 subsection {* Other simple lemmas and lemma duplicates *}
1505 lemmas eq_sym_conv = eq_commute
1506 lemmas if_def2 = if_bool_eq_conj
1508 lemma ex1_eq [iff]: "EX! x. x = t" "EX! x. t = x"
1509   by blast+
1511 lemma choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))"
1512   apply (rule iffI)
1513   apply (rule_tac a = "%x. THE y. P x y" in ex1I)
1514   apply (fast dest!: theI')
1515   apply (fast intro: ext the1_equality [symmetric])
1516   apply (erule ex1E)
1517   apply (rule allI)
1518   apply (rule ex1I)
1519   apply (erule spec)
1520   apply (erule_tac x = "%z. if z = x then y else f z" in allE)
1521   apply (erule impE)
1522   apply (rule allI)
1523   apply (rule_tac P = "xa = x" in case_split_thm)
1524   apply (drule_tac  x = x in fun_cong, simp_all)
1525   done
1527 text {* Needs only HOL-lemmas *}
1528 lemma mk_left_commute:
1529   assumes a: "\<And>x y z. f (f x y) z = f x (f y z)" and
1530           c: "\<And>x y. f x y = f y x"
1531   shows "f x (f y z) = f y (f x z)"
1532   by (rule trans [OF trans [OF c a] arg_cong [OF c, of "f y"]])
1534 end