src/HOL/HOL.thy
 author wenzelm Thu Jan 19 21:22:08 2006 +0100 (2006-01-19 ago) changeset 18708 4b3dadb4fe33 parent 18702 7dc7dcd63224 child 18757 f0d901bc0686 permissions -rw-r--r--
setup: theory -> theory;
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 ("cladata.ML") ("blastdata.ML") ("simpdata.ML")
12 begin
14 subsection {* Primitive logic *}
16 subsubsection {* Core syntax *}
18 classes type
19 defaultsort type
21 global
23 typedecl bool
25 arities
26   bool :: type
27   fun :: (type, type) type
29 judgment
30   Trueprop      :: "bool => prop"                   ("(_)" 5)
32 consts
33   Not           :: "bool => bool"                   ("~ _"  40)
34   True          :: bool
35   False         :: bool
36   arbitrary     :: '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)
54 subsubsection {* Additional concrete syntax *}
56 nonterminals
57   letbinds  letbind
58   case_syn  cases_syn
60 syntax
61   "_not_equal"  :: "['a, 'a] => bool"                    (infixl "~=" 50)
62   "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
64   "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
65   ""            :: "letbind => letbinds"                 ("_")
66   "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
67   "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
69   "_case_syntax":: "['a, cases_syn] => 'b"               ("(case _ of/ _)" 10)
70   "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
71   ""            :: "case_syn => cases_syn"               ("_")
72   "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
74 translations
75   "x ~= y"                == "~ (x = y)"
76   "THE x. P"              == "The (%x. P)"
77   "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
78   "let x = a in e"        == "Let a (%x. e)"
80 print_translation {*
81 (* To avoid eta-contraction of body: *)
82 [("The", fn [Abs abs] =>
83      let val (x,t) = atomic_abs_tr' abs
84      in Syntax.const "_The" \$ x \$ t end)]
85 *}
87 syntax (output)
88   "="           :: "['a, 'a] => bool"                    (infix 50)
89   "_not_equal"  :: "['a, 'a] => bool"                    (infix "~=" 50)
91 syntax (xsymbols)
92   Not           :: "bool => bool"                        ("\<not> _"  40)
93   "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
94   "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
95   "op -->"      :: "[bool, bool] => bool"                (infixr "\<longrightarrow>" 25)
96   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
97   "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
98   "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
99   "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
100   "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
101 (*"_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ \<orelse> _")*)
103 syntax (xsymbols output)
104   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
106 syntax (HTML output)
107   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
108   Not           :: "bool => bool"                        ("\<not> _"  40)
109   "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
110   "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
111   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
112   "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
113   "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
114   "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
116 syntax (HOL)
117   "ALL "        :: "[idts, bool] => bool"                ("(3! _./ _)" [0, 10] 10)
118   "EX "         :: "[idts, bool] => bool"                ("(3? _./ _)" [0, 10] 10)
119   "EX! "        :: "[idts, bool] => bool"                ("(3?! _./ _)" [0, 10] 10)
121 syntax
122   "_iff" :: "bool => bool => bool"                       (infixr "<->" 25)
123 syntax (xsymbols)
124   "_iff" :: "bool => bool => bool"                       (infixr "\<longleftrightarrow>" 25)
125 translations
126   "op <->" => "op = :: bool => bool => bool"
128 typed_print_translation {*
129   let
130     fun iff_tr' _ (Type ("fun", (Type ("bool", _) :: _))) ts =
131           if Output.has_mode "iff" then Term.list_comb (Syntax.const "_iff", ts)
132           else raise Match
133       | iff_tr' _ _ _ = raise Match;
134   in [("op =", iff_tr')] end
135 *}
138 subsubsection {* Axioms and basic definitions *}
140 axioms
141   eq_reflection:  "(x=y) ==> (x==y)"
143   refl:           "t = (t::'a)"
145   ext:            "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
146     -- {*Extensionality is built into the meta-logic, and this rule expresses
147          a related property.  It is an eta-expanded version of the traditional
148          rule, and similar to the ABS rule of HOL*}
150   the_eq_trivial: "(THE x. x = a) = (a::'a)"
152   impI:           "(P ==> Q) ==> P-->Q"
153   mp:             "[| P-->Q;  P |] ==> Q"
156 text{*Thanks to Stephan Merz*}
157 theorem subst:
158   assumes eq: "s = t" and p: "P(s)"
159   shows "P(t::'a)"
160 proof -
161   from eq have meta: "s \<equiv> t"
162     by (rule eq_reflection)
163   from p show ?thesis
164     by (unfold meta)
165 qed
167 defs
168   True_def:     "True      == ((%x::bool. x) = (%x. x))"
169   All_def:      "All(P)    == (P = (%x. True))"
170   Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
171   False_def:    "False     == (!P. P)"
172   not_def:      "~ P       == P-->False"
173   and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
174   or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
175   Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
177 axioms
178   iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
179   True_or_False:  "(P=True) | (P=False)"
181 defs
182   Let_def:      "Let s f == f(s)"
183   if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
185 finalconsts
186   "op ="
187   "op -->"
188   The
189   arbitrary
191 subsubsection {* Generic algebraic operations *}
193 axclass zero < type
194 axclass one < type
195 axclass plus < type
196 axclass minus < type
197 axclass times < type
198 axclass inverse < type
200 global
202 consts
203   "0"           :: "'a::zero"                       ("0")
204   "1"           :: "'a::one"                        ("1")
205   "+"           :: "['a::plus, 'a]  => 'a"          (infixl 65)
206   -             :: "['a::minus, 'a] => 'a"          (infixl 65)
207   uminus        :: "['a::minus] => 'a"              ("- _"  80)
208   *             :: "['a::times, 'a] => 'a"          (infixl 70)
210 syntax
211   "_index1"  :: index    ("\<^sub>1")
212 translations
213   (index) "\<^sub>1" => (index) "\<^bsub>\<struct>\<^esub>"
215 local
217 typed_print_translation {*
218   let
219     fun tr' c = (c, fn show_sorts => fn T => fn ts =>
220       if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
221       else Syntax.const Syntax.constrainC \$ Syntax.const c \$ Syntax.term_of_typ show_sorts T);
222   in [tr' "0", tr' "1"] end;
223 *} -- {* show types that are presumably too general *}
226 consts
227   abs           :: "'a::minus => 'a"
228   inverse       :: "'a::inverse => 'a"
229   divide        :: "['a::inverse, 'a] => 'a"        (infixl "'/" 70)
231 syntax (xsymbols)
232   abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
233 syntax (HTML output)
234   abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
237 subsection {*Equality*}
239 lemma sym: "s = t ==> t = s"
240   by (erule subst) (rule refl)
242 lemma ssubst: "t = s ==> P s ==> P t"
243   by (drule sym) (erule subst)
245 lemma trans: "[| r=s; s=t |] ==> r=t"
246   by (erule subst)
248 lemma def_imp_eq: assumes meq: "A == B" shows "A = B"
249   by (unfold meq) (rule refl)
252 (*Useful with eresolve_tac for proving equalties from known equalities.
253         a = b
254         |   |
255         c = d   *)
256 lemma box_equals: "[| a=b;  a=c;  b=d |] ==> c=d"
257 apply (rule trans)
258 apply (rule trans)
259 apply (rule sym)
260 apply assumption+
261 done
263 text {* For calculational reasoning: *}
265 lemma forw_subst: "a = b ==> P b ==> P a"
266   by (rule ssubst)
268 lemma back_subst: "P a ==> a = b ==> P b"
269   by (rule subst)
272 subsection {*Congruence rules for application*}
274 (*similar to AP_THM in Gordon's HOL*)
275 lemma fun_cong: "(f::'a=>'b) = g ==> f(x)=g(x)"
276 apply (erule subst)
277 apply (rule refl)
278 done
280 (*similar to AP_TERM in Gordon's HOL and FOL's subst_context*)
281 lemma arg_cong: "x=y ==> f(x)=f(y)"
282 apply (erule subst)
283 apply (rule refl)
284 done
286 lemma arg_cong2: "\<lbrakk> a = b; c = d \<rbrakk> \<Longrightarrow> f a c = f b d"
287 apply (erule ssubst)+
288 apply (rule refl)
289 done
292 lemma cong: "[| f = g; (x::'a) = y |] ==> f(x) = g(y)"
293 apply (erule subst)+
294 apply (rule refl)
295 done
298 subsection {*Equality of booleans -- iff*}
300 lemma iffI: assumes prems: "P ==> Q" "Q ==> P" shows "P=Q"
301   by (iprover intro: iff [THEN mp, THEN mp] impI prems)
303 lemma iffD2: "[| P=Q; Q |] ==> P"
304   by (erule ssubst)
306 lemma rev_iffD2: "[| Q; P=Q |] ==> P"
307   by (erule iffD2)
309 lemmas iffD1 = sym [THEN iffD2, standard]
310 lemmas rev_iffD1 = sym [THEN  rev_iffD2, standard]
312 lemma iffE:
313   assumes major: "P=Q"
314       and minor: "[| P --> Q; Q --> P |] ==> R"
315   shows R
316   by (iprover intro: minor impI major [THEN iffD2] major [THEN iffD1])
319 subsection {*True*}
321 lemma TrueI: "True"
322   by (unfold True_def) (rule refl)
324 lemma eqTrueI: "P ==> P=True"
325   by (iprover intro: iffI TrueI)
327 lemma eqTrueE: "P=True ==> P"
328 apply (erule iffD2)
329 apply (rule TrueI)
330 done
333 subsection {*Universal quantifier*}
335 lemma allI: assumes p: "!!x::'a. P(x)" shows "ALL x. P(x)"
336 apply (unfold All_def)
337 apply (iprover intro: ext eqTrueI p)
338 done
340 lemma spec: "ALL x::'a. P(x) ==> P(x)"
341 apply (unfold All_def)
342 apply (rule eqTrueE)
343 apply (erule fun_cong)
344 done
346 lemma allE:
347   assumes major: "ALL x. P(x)"
348       and minor: "P(x) ==> R"
349   shows "R"
350 by (iprover intro: minor major [THEN spec])
352 lemma all_dupE:
353   assumes major: "ALL x. P(x)"
354       and minor: "[| P(x); ALL x. P(x) |] ==> R"
355   shows "R"
356 by (iprover intro: minor major major [THEN spec])
359 subsection {*False*}
360 (*Depends upon spec; it is impossible to do propositional logic before quantifiers!*)
362 lemma FalseE: "False ==> P"
363 apply (unfold False_def)
364 apply (erule spec)
365 done
367 lemma False_neq_True: "False=True ==> P"
368 by (erule eqTrueE [THEN FalseE])
371 subsection {*Negation*}
373 lemma notI:
374   assumes p: "P ==> False"
375   shows "~P"
376 apply (unfold not_def)
377 apply (iprover intro: impI p)
378 done
380 lemma False_not_True: "False ~= True"
381 apply (rule notI)
382 apply (erule False_neq_True)
383 done
385 lemma True_not_False: "True ~= False"
386 apply (rule notI)
387 apply (drule sym)
388 apply (erule False_neq_True)
389 done
391 lemma notE: "[| ~P;  P |] ==> R"
392 apply (unfold not_def)
393 apply (erule mp [THEN FalseE])
394 apply assumption
395 done
397 (* Alternative ~ introduction rule: [| P ==> ~ Pa; P ==> Pa |] ==> ~ P *)
398 lemmas notI2 = notE [THEN notI, standard]
401 subsection {*Implication*}
403 lemma impE:
404   assumes "P-->Q" "P" "Q ==> R"
405   shows "R"
406 by (iprover intro: prems mp)
408 (* Reduces Q to P-->Q, allowing substitution in P. *)
409 lemma rev_mp: "[| P;  P --> Q |] ==> Q"
410 by (iprover intro: mp)
412 lemma contrapos_nn:
413   assumes major: "~Q"
414       and minor: "P==>Q"
415   shows "~P"
416 by (iprover intro: notI minor major [THEN notE])
418 (*not used at all, but we already have the other 3 combinations *)
419 lemma contrapos_pn:
420   assumes major: "Q"
421       and minor: "P ==> ~Q"
422   shows "~P"
423 by (iprover intro: notI minor major notE)
425 lemma not_sym: "t ~= s ==> s ~= t"
426 apply (erule contrapos_nn)
427 apply (erule sym)
428 done
430 (*still used in HOLCF*)
431 lemma rev_contrapos:
432   assumes pq: "P ==> Q"
433       and nq: "~Q"
434   shows "~P"
435 apply (rule nq [THEN contrapos_nn])
436 apply (erule pq)
437 done
439 subsection {*Existential quantifier*}
441 lemma exI: "P x ==> EX x::'a. P x"
442 apply (unfold Ex_def)
443 apply (iprover intro: allI allE impI mp)
444 done
446 lemma exE:
447   assumes major: "EX x::'a. P(x)"
448       and minor: "!!x. P(x) ==> Q"
449   shows "Q"
450 apply (rule major [unfolded Ex_def, THEN spec, THEN mp])
451 apply (iprover intro: impI [THEN allI] minor)
452 done
455 subsection {*Conjunction*}
457 lemma conjI: "[| P; Q |] ==> P&Q"
458 apply (unfold and_def)
459 apply (iprover intro: impI [THEN allI] mp)
460 done
462 lemma conjunct1: "[| P & Q |] ==> P"
463 apply (unfold and_def)
464 apply (iprover intro: impI dest: spec mp)
465 done
467 lemma conjunct2: "[| P & Q |] ==> Q"
468 apply (unfold and_def)
469 apply (iprover intro: impI dest: spec mp)
470 done
472 lemma conjE:
473   assumes major: "P&Q"
474       and minor: "[| P; Q |] ==> R"
475   shows "R"
476 apply (rule minor)
477 apply (rule major [THEN conjunct1])
478 apply (rule major [THEN conjunct2])
479 done
481 lemma context_conjI:
482   assumes prems: "P" "P ==> Q" shows "P & Q"
483 by (iprover intro: conjI prems)
486 subsection {*Disjunction*}
488 lemma disjI1: "P ==> P|Q"
489 apply (unfold or_def)
490 apply (iprover intro: allI impI mp)
491 done
493 lemma disjI2: "Q ==> P|Q"
494 apply (unfold or_def)
495 apply (iprover intro: allI impI mp)
496 done
498 lemma disjE:
499   assumes major: "P|Q"
500       and minorP: "P ==> R"
501       and minorQ: "Q ==> R"
502   shows "R"
503 by (iprover intro: minorP minorQ impI
504                  major [unfolded or_def, THEN spec, THEN mp, THEN mp])
507 subsection {*Classical logic*}
510 lemma classical:
511   assumes prem: "~P ==> P"
512   shows "P"
513 apply (rule True_or_False [THEN disjE, THEN eqTrueE])
514 apply assumption
515 apply (rule notI [THEN prem, THEN eqTrueI])
516 apply (erule subst)
517 apply assumption
518 done
520 lemmas ccontr = FalseE [THEN classical, standard]
522 (*notE with premises exchanged; it discharges ~R so that it can be used to
523   make elimination rules*)
524 lemma rev_notE:
525   assumes premp: "P"
526       and premnot: "~R ==> ~P"
527   shows "R"
528 apply (rule ccontr)
529 apply (erule notE [OF premnot premp])
530 done
532 (*Double negation law*)
533 lemma notnotD: "~~P ==> P"
534 apply (rule classical)
535 apply (erule notE)
536 apply assumption
537 done
539 lemma contrapos_pp:
540   assumes p1: "Q"
541       and p2: "~P ==> ~Q"
542   shows "P"
543 by (iprover intro: classical p1 p2 notE)
546 subsection {*Unique existence*}
548 lemma ex1I:
549   assumes prems: "P a" "!!x. P(x) ==> x=a"
550   shows "EX! x. P(x)"
551 by (unfold Ex1_def, iprover intro: prems exI conjI allI impI)
553 text{*Sometimes easier to use: the premises have no shared variables.  Safe!*}
554 lemma ex_ex1I:
555   assumes ex_prem: "EX x. P(x)"
556       and eq: "!!x y. [| P(x); P(y) |] ==> x=y"
557   shows "EX! x. P(x)"
558 by (iprover intro: ex_prem [THEN exE] ex1I eq)
560 lemma ex1E:
561   assumes major: "EX! x. P(x)"
562       and minor: "!!x. [| P(x);  ALL y. P(y) --> y=x |] ==> R"
563   shows "R"
564 apply (rule major [unfolded Ex1_def, THEN exE])
565 apply (erule conjE)
566 apply (iprover intro: minor)
567 done
569 lemma ex1_implies_ex: "EX! x. P x ==> EX x. P x"
570 apply (erule ex1E)
571 apply (rule exI)
572 apply assumption
573 done
576 subsection {*THE: definite description operator*}
578 lemma the_equality:
579   assumes prema: "P a"
580       and premx: "!!x. P x ==> x=a"
581   shows "(THE x. P x) = a"
582 apply (rule trans [OF _ the_eq_trivial])
583 apply (rule_tac f = "The" in arg_cong)
584 apply (rule ext)
585 apply (rule iffI)
586  apply (erule premx)
587 apply (erule ssubst, rule prema)
588 done
590 lemma theI:
591   assumes "P a" and "!!x. P x ==> x=a"
592   shows "P (THE x. P x)"
593 by (iprover intro: prems the_equality [THEN ssubst])
595 lemma theI': "EX! x. P x ==> P (THE x. P x)"
596 apply (erule ex1E)
597 apply (erule theI)
598 apply (erule allE)
599 apply (erule mp)
600 apply assumption
601 done
603 (*Easier to apply than theI: only one occurrence of P*)
604 lemma theI2:
605   assumes "P a" "!!x. P x ==> x=a" "!!x. P x ==> Q x"
606   shows "Q (THE x. P x)"
607 by (iprover intro: prems theI)
609 lemma the1_equality [elim?]: "[| EX!x. P x; P a |] ==> (THE x. P x) = a"
610 apply (rule the_equality)
611 apply  assumption
612 apply (erule ex1E)
613 apply (erule all_dupE)
614 apply (drule mp)
615 apply  assumption
616 apply (erule ssubst)
617 apply (erule allE)
618 apply (erule mp)
619 apply assumption
620 done
622 lemma the_sym_eq_trivial: "(THE y. x=y) = x"
623 apply (rule the_equality)
624 apply (rule refl)
625 apply (erule sym)
626 done
629 subsection {*Classical intro rules for disjunction and existential quantifiers*}
631 lemma disjCI:
632   assumes "~Q ==> P" shows "P|Q"
633 apply (rule classical)
634 apply (iprover intro: prems disjI1 disjI2 notI elim: notE)
635 done
637 lemma excluded_middle: "~P | P"
638 by (iprover intro: disjCI)
640 text{*case distinction as a natural deduction rule. Note that @{term "~P"}
641    is the second case, not the first.*}
642 lemma case_split_thm:
643   assumes prem1: "P ==> Q"
644       and prem2: "~P ==> Q"
645   shows "Q"
646 apply (rule excluded_middle [THEN disjE])
647 apply (erule prem2)
648 apply (erule prem1)
649 done
651 (*Classical implies (-->) elimination. *)
652 lemma impCE:
653   assumes major: "P-->Q"
654       and minor: "~P ==> R" "Q ==> R"
655   shows "R"
656 apply (rule excluded_middle [of P, THEN disjE])
657 apply (iprover intro: minor major [THEN mp])+
658 done
660 (*This version of --> elimination works on Q before P.  It works best for
661   those cases in which P holds "almost everywhere".  Can't install as
662   default: would break old proofs.*)
663 lemma impCE':
664   assumes major: "P-->Q"
665       and minor: "Q ==> R" "~P ==> R"
666   shows "R"
667 apply (rule excluded_middle [of P, THEN disjE])
668 apply (iprover intro: minor major [THEN mp])+
669 done
671 (*Classical <-> elimination. *)
672 lemma iffCE:
673   assumes major: "P=Q"
674       and minor: "[| P; Q |] ==> R"  "[| ~P; ~Q |] ==> R"
675   shows "R"
676 apply (rule major [THEN iffE])
677 apply (iprover intro: minor elim: impCE notE)
678 done
680 lemma exCI:
681   assumes "ALL x. ~P(x) ==> P(a)"
682   shows "EX x. P(x)"
683 apply (rule ccontr)
684 apply (iprover intro: prems exI allI notI notE [of "\<exists>x. P x"])
685 done
689 subsection {* Theory and package setup *}
691 ML
692 {*
693 val eq_reflection = thm "eq_reflection"
694 val refl = thm "refl"
695 val subst = thm "subst"
696 val ext = thm "ext"
697 val impI = thm "impI"
698 val mp = thm "mp"
699 val True_def = thm "True_def"
700 val All_def = thm "All_def"
701 val Ex_def = thm "Ex_def"
702 val False_def = thm "False_def"
703 val not_def = thm "not_def"
704 val and_def = thm "and_def"
705 val or_def = thm "or_def"
706 val Ex1_def = thm "Ex1_def"
707 val iff = thm "iff"
708 val True_or_False = thm "True_or_False"
709 val Let_def = thm "Let_def"
710 val if_def = thm "if_def"
711 val sym = thm "sym"
712 val ssubst = thm "ssubst"
713 val trans = thm "trans"
714 val def_imp_eq = thm "def_imp_eq"
715 val box_equals = thm "box_equals"
716 val fun_cong = thm "fun_cong"
717 val arg_cong = thm "arg_cong"
718 val cong = thm "cong"
719 val iffI = thm "iffI"
720 val iffD2 = thm "iffD2"
721 val rev_iffD2 = thm "rev_iffD2"
722 val iffD1 = thm "iffD1"
723 val rev_iffD1 = thm "rev_iffD1"
724 val iffE = thm "iffE"
725 val TrueI = thm "TrueI"
726 val eqTrueI = thm "eqTrueI"
727 val eqTrueE = thm "eqTrueE"
728 val allI = thm "allI"
729 val spec = thm "spec"
730 val allE = thm "allE"
731 val all_dupE = thm "all_dupE"
732 val FalseE = thm "FalseE"
733 val False_neq_True = thm "False_neq_True"
734 val notI = thm "notI"
735 val False_not_True = thm "False_not_True"
736 val True_not_False = thm "True_not_False"
737 val notE = thm "notE"
738 val notI2 = thm "notI2"
739 val impE = thm "impE"
740 val rev_mp = thm "rev_mp"
741 val contrapos_nn = thm "contrapos_nn"
742 val contrapos_pn = thm "contrapos_pn"
743 val not_sym = thm "not_sym"
744 val rev_contrapos = thm "rev_contrapos"
745 val exI = thm "exI"
746 val exE = thm "exE"
747 val conjI = thm "conjI"
748 val conjunct1 = thm "conjunct1"
749 val conjunct2 = thm "conjunct2"
750 val conjE = thm "conjE"
751 val context_conjI = thm "context_conjI"
752 val disjI1 = thm "disjI1"
753 val disjI2 = thm "disjI2"
754 val disjE = thm "disjE"
755 val classical = thm "classical"
756 val ccontr = thm "ccontr"
757 val rev_notE = thm "rev_notE"
758 val notnotD = thm "notnotD"
759 val contrapos_pp = thm "contrapos_pp"
760 val ex1I = thm "ex1I"
761 val ex_ex1I = thm "ex_ex1I"
762 val ex1E = thm "ex1E"
763 val ex1_implies_ex = thm "ex1_implies_ex"
764 val the_equality = thm "the_equality"
765 val theI = thm "theI"
766 val theI' = thm "theI'"
767 val theI2 = thm "theI2"
768 val the1_equality = thm "the1_equality"
769 val the_sym_eq_trivial = thm "the_sym_eq_trivial"
770 val disjCI = thm "disjCI"
771 val excluded_middle = thm "excluded_middle"
772 val case_split_thm = thm "case_split_thm"
773 val impCE = thm "impCE"
774 val impCE = thm "impCE"
775 val iffCE = thm "iffCE"
776 val exCI = thm "exCI"
778 (* combination of (spec RS spec RS ...(j times) ... spec RS mp) *)
779 local
780   fun wrong_prem (Const ("All", _) \$ (Abs (_, _, t))) = wrong_prem t
781   |   wrong_prem (Bound _) = true
782   |   wrong_prem _ = false
783   val filter_right = List.filter (fn t => not (wrong_prem (HOLogic.dest_Trueprop (hd (Thm.prems_of t)))))
784 in
785   fun smp i = funpow i (fn m => filter_right ([spec] RL m)) ([mp])
786   fun smp_tac j = EVERY'[dresolve_tac (smp j), atac]
787 end
790 fun strip_tac i = REPEAT(resolve_tac [impI,allI] i)
792 (*Obsolete form of disjunctive case analysis*)
793 fun excluded_middle_tac sP =
794     res_inst_tac [("Q",sP)] (excluded_middle RS disjE)
796 fun case_tac a = res_inst_tac [("P",a)] case_split_thm
797 *}
799 theorems case_split = case_split_thm [case_names True False]
801 ML {*
802 structure ProjectRule = ProjectRuleFun
803 (struct
804   val conjunct1 = thm "conjunct1";
805   val conjunct2 = thm "conjunct2";
806   val mp = thm "mp";
807 end)
808 *}
811 subsubsection {* Intuitionistic Reasoning *}
813 lemma impE':
814   assumes 1: "P --> Q"
815     and 2: "Q ==> R"
816     and 3: "P --> Q ==> P"
817   shows R
818 proof -
819   from 3 and 1 have P .
820   with 1 have Q by (rule impE)
821   with 2 show R .
822 qed
824 lemma allE':
825   assumes 1: "ALL x. P x"
826     and 2: "P x ==> ALL x. P x ==> Q"
827   shows Q
828 proof -
829   from 1 have "P x" by (rule spec)
830   from this and 1 show Q by (rule 2)
831 qed
833 lemma notE':
834   assumes 1: "~ P"
835     and 2: "~ P ==> P"
836   shows R
837 proof -
838   from 2 and 1 have P .
839   with 1 show R by (rule notE)
840 qed
842 lemmas [Pure.elim!] = disjE iffE FalseE conjE exE
843   and [Pure.intro!] = iffI conjI impI TrueI notI allI refl
844   and [Pure.elim 2] = allE notE' impE'
845   and [Pure.intro] = exI disjI2 disjI1
847 lemmas [trans] = trans
848   and [sym] = sym not_sym
849   and [Pure.elim?] = iffD1 iffD2 impE
852 subsubsection {* Atomizing meta-level connectives *}
854 lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
855 proof
856   assume "!!x. P x"
857   show "ALL x. P x" by (rule allI)
858 next
859   assume "ALL x. P x"
860   thus "!!x. P x" by (rule allE)
861 qed
863 lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
864 proof
865   assume r: "A ==> B"
866   show "A --> B" by (rule impI) (rule r)
867 next
868   assume "A --> B" and A
869   thus B by (rule mp)
870 qed
872 lemma atomize_not: "(A ==> False) == Trueprop (~A)"
873 proof
874   assume r: "A ==> False"
875   show "~A" by (rule notI) (rule r)
876 next
877   assume "~A" and A
878   thus False by (rule notE)
879 qed
881 lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
882 proof
883   assume "x == y"
884   show "x = y" by (unfold prems) (rule refl)
885 next
886   assume "x = y"
887   thus "x == y" by (rule eq_reflection)
888 qed
890 lemma atomize_conj [atomize]:
891   "(!!C. (A ==> B ==> PROP C) ==> PROP C) == Trueprop (A & B)"
892 proof
893   assume "!!C. (A ==> B ==> PROP C) ==> PROP C"
894   show "A & B" by (rule conjI)
895 next
896   fix C
897   assume "A & B"
898   assume "A ==> B ==> PROP C"
899   thus "PROP C"
900   proof this
901     show A by (rule conjunct1)
902     show B by (rule conjunct2)
903   qed
904 qed
906 lemmas [symmetric, rulify] = atomize_all atomize_imp
909 subsubsection {* Classical Reasoner setup *}
912 setup hypsubst_setup
914 setup {* ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac) *}
916 setup Classical.setup
917 setup clasetup
919 declare ex_ex1I [rule del, intro! 2]
920   and ex1I [intro]
922 lemmas [intro?] = ext
923   and [elim?] = ex1_implies_ex
925 use "blastdata.ML"
926 setup Blast.setup
929 subsubsection {* Simplifier setup *}
931 lemma meta_eq_to_obj_eq: "x == y ==> x = y"
932 proof -
933   assume r: "x == y"
934   show "x = y" by (unfold r) (rule refl)
935 qed
937 lemma eta_contract_eq: "(%s. f s) = f" ..
939 lemma simp_thms:
940   shows not_not: "(~ ~ P) = P"
941   and Not_eq_iff: "((~P) = (~Q)) = (P = Q)"
942   and
943     "(P ~= Q) = (P = (~Q))"
944     "(P | ~P) = True"    "(~P | P) = True"
945     "(x = x) = True"
946     "(~True) = False"  "(~False) = True"
947     "(~P) ~= P"  "P ~= (~P)"
948     "(True=P) = P"  "(P=True) = P"  "(False=P) = (~P)"  "(P=False) = (~P)"
949     "(True --> P) = P"  "(False --> P) = True"
950     "(P --> True) = True"  "(P --> P) = True"
951     "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
952     "(P & True) = P"  "(True & P) = P"
953     "(P & False) = False"  "(False & P) = False"
954     "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
955     "(P & ~P) = False"    "(~P & P) = False"
956     "(P | True) = True"  "(True | P) = True"
957     "(P | False) = P"  "(False | P) = P"
958     "(P | P) = P"  "(P | (P | Q)) = (P | Q)" and
959     "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
960     -- {* needed for the one-point-rule quantifier simplification procs *}
961     -- {* essential for termination!! *} and
962     "!!P. (EX x. x=t & P(x)) = P(t)"
963     "!!P. (EX x. t=x & P(x)) = P(t)"
964     "!!P. (ALL x. x=t --> P(x)) = P(t)"
965     "!!P. (ALL x. t=x --> P(x)) = P(t)"
966   by (blast, blast, blast, blast, blast, iprover+)
968 lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
969   by iprover
971 lemma ex_simps:
972   "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
973   "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
974   "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
975   "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
976   "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
977   "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
978   -- {* Miniscoping: pushing in existential quantifiers. *}
979   by (iprover | blast)+
981 lemma all_simps:
982   "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
983   "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
984   "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
985   "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
986   "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
987   "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
988   -- {* Miniscoping: pushing in universal quantifiers. *}
989   by (iprover | blast)+
991 lemma disj_absorb: "(A | A) = A"
992   by blast
994 lemma disj_left_absorb: "(A | (A | B)) = (A | B)"
995   by blast
997 lemma conj_absorb: "(A & A) = A"
998   by blast
1000 lemma conj_left_absorb: "(A & (A & B)) = (A & B)"
1001   by blast
1003 lemma eq_ac:
1004   shows eq_commute: "(a=b) = (b=a)"
1005     and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
1006     and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (iprover, blast+)
1007 lemma neq_commute: "(a~=b) = (b~=a)" by iprover
1009 lemma conj_comms:
1010   shows conj_commute: "(P&Q) = (Q&P)"
1011     and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by iprover+
1012 lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by iprover
1014 lemma disj_comms:
1015   shows disj_commute: "(P|Q) = (Q|P)"
1016     and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by iprover+
1017 lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by iprover
1019 lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by iprover
1020 lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by iprover
1022 lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by iprover
1023 lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by iprover
1025 lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by iprover
1026 lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by iprover
1027 lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by iprover
1029 text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
1030 lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
1031 lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
1033 lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
1034 lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
1036 lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by iprover
1037 lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
1038 lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
1039 lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
1040 lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
1041 lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
1042   by blast
1043 lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
1045 lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by iprover
1048 lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
1049   -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
1050   -- {* cases boil down to the same thing. *}
1051   by blast
1053 lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
1054 lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
1055 lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by iprover
1056 lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by iprover
1058 lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by iprover
1059 lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by iprover
1061 text {*
1062   \medskip The @{text "&"} congruence rule: not included by default!
1063   May slow rewrite proofs down by as much as 50\% *}
1065 lemma conj_cong:
1066     "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
1067   by iprover
1069 lemma rev_conj_cong:
1070     "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
1071   by iprover
1073 text {* The @{text "|"} congruence rule: not included by default! *}
1075 lemma disj_cong:
1076     "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
1077   by blast
1079 lemma eq_sym_conv: "(x = y) = (y = x)"
1080   by iprover
1083 text {* \medskip if-then-else rules *}
1085 lemma if_True: "(if True then x else y) = x"
1086   by (unfold if_def) blast
1088 lemma if_False: "(if False then x else y) = y"
1089   by (unfold if_def) blast
1091 lemma if_P: "P ==> (if P then x else y) = x"
1092   by (unfold if_def) blast
1094 lemma if_not_P: "~P ==> (if P then x else y) = y"
1095   by (unfold if_def) blast
1097 lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
1098   apply (rule case_split [of Q])
1099    apply (simplesubst if_P)
1100     prefer 3 apply (simplesubst if_not_P, blast+)
1101   done
1103 lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
1104 by (simplesubst split_if, blast)
1106 lemmas if_splits = split_if split_if_asm
1108 lemma if_def2: "(if Q then x else y) = ((Q --> x) & (~ Q --> y))"
1109   by (rule split_if)
1111 lemma if_cancel: "(if c then x else x) = x"
1112 by (simplesubst split_if, blast)
1114 lemma if_eq_cancel: "(if x = y then y else x) = x"
1115 by (simplesubst split_if, blast)
1117 lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
1118   -- {* This form is useful for expanding @{text if}s on the RIGHT of the @{text "==>"} symbol. *}
1119   by (rule split_if)
1121 lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
1122   -- {* And this form is useful for expanding @{text if}s on the LEFT. *}
1123   apply (simplesubst split_if, blast)
1124   done
1126 lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) iprover
1127 lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) iprover
1129 text {* \medskip let rules for simproc *}
1131 lemma Let_folded: "f x \<equiv> g x \<Longrightarrow>  Let x f \<equiv> Let x g"
1132   by (unfold Let_def)
1134 lemma Let_unfold: "f x \<equiv> g \<Longrightarrow>  Let x f \<equiv> g"
1135   by (unfold Let_def)
1137 text {*
1138   The following copy of the implication operator is useful for
1139   fine-tuning congruence rules.  It instructs the simplifier to simplify
1140   its premise.
1141 *}
1143 constdefs
1144   simp_implies :: "[prop, prop] => prop"  (infixr "=simp=>" 1)
1145   "simp_implies \<equiv> op ==>"
1147 lemma simp_impliesI:
1148   assumes PQ: "(PROP P \<Longrightarrow> PROP Q)"
1149   shows "PROP P =simp=> PROP Q"
1150   apply (unfold simp_implies_def)
1151   apply (rule PQ)
1152   apply assumption
1153   done
1155 lemma simp_impliesE:
1156   assumes PQ:"PROP P =simp=> PROP Q"
1157   and P: "PROP P"
1158   and QR: "PROP Q \<Longrightarrow> PROP R"
1159   shows "PROP R"
1160   apply (rule QR)
1161   apply (rule PQ [unfolded simp_implies_def])
1162   apply (rule P)
1163   done
1165 lemma simp_implies_cong:
1166   assumes PP' :"PROP P == PROP P'"
1167   and P'QQ': "PROP P' ==> (PROP Q == PROP Q')"
1168   shows "(PROP P =simp=> PROP Q) == (PROP P' =simp=> PROP Q')"
1169 proof (unfold simp_implies_def, rule equal_intr_rule)
1170   assume PQ: "PROP P \<Longrightarrow> PROP Q"
1171   and P': "PROP P'"
1172   from PP' [symmetric] and P' have "PROP P"
1173     by (rule equal_elim_rule1)
1174   hence "PROP Q" by (rule PQ)
1175   with P'QQ' [OF P'] show "PROP Q'" by (rule equal_elim_rule1)
1176 next
1177   assume P'Q': "PROP P' \<Longrightarrow> PROP Q'"
1178   and P: "PROP P"
1179   from PP' and P have P': "PROP P'" by (rule equal_elim_rule1)
1180   hence "PROP Q'" by (rule P'Q')
1181   with P'QQ' [OF P', symmetric] show "PROP Q"
1182     by (rule equal_elim_rule1)
1183 qed
1186 text {* \medskip Actual Installation of the Simplifier. *}
1188 use "simpdata.ML"
1189 setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup
1190 setup Splitter.setup setup Clasimp.setup
1191 setup EqSubst.setup
1194 subsubsection {* Code generator setup *}
1196 types_code
1197   "bool"  ("bool")
1198 attach (term_of) {*
1199 fun term_of_bool b = if b then HOLogic.true_const else HOLogic.false_const;
1200 *}
1201 attach (test) {*
1202 fun gen_bool i = one_of [false, true];
1203 *}
1205 consts_code
1206   "True"    ("true")
1207   "False"   ("false")
1208   "Not"     ("not")
1209   "op |"    ("(_ orelse/ _)")
1210   "op &"    ("(_ andalso/ _)")
1211   "HOL.If"      ("(if _/ then _/ else _)")
1213 ML {*
1214 local
1216 fun eq_codegen thy defs gr dep thyname b t =
1217     (case strip_comb t of
1218        (Const ("op =", Type (_, [Type ("fun", _), _])), _) => NONE
1219      | (Const ("op =", _), [t, u]) =>
1220           let
1221             val (gr', pt) = Codegen.invoke_codegen thy defs dep thyname false (gr, t);
1222             val (gr'', pu) = Codegen.invoke_codegen thy defs dep thyname false (gr', u);
1223             val (gr''', _) = Codegen.invoke_tycodegen thy defs dep thyname false (gr'', HOLogic.boolT)
1224           in
1225             SOME (gr''', Codegen.parens
1226               (Pretty.block [pt, Pretty.str " =", Pretty.brk 1, pu]))
1227           end
1228      | (t as Const ("op =", _), ts) => SOME (Codegen.invoke_codegen
1229          thy defs dep thyname b (gr, Codegen.eta_expand t ts 2))
1230      | _ => NONE);
1232 in
1234 val eq_codegen_setup = Codegen.add_codegen "eq_codegen" eq_codegen;
1236 end;
1237 *}
1239 setup eq_codegen_setup
1242 subsection {* Other simple lemmas *}
1244 declare disj_absorb [simp] conj_absorb [simp]
1246 lemma ex1_eq[iff]: "EX! x. x = t" "EX! x. t = x"
1247 by blast+
1250 theorem choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))"
1251   apply (rule iffI)
1252   apply (rule_tac a = "%x. THE y. P x y" in ex1I)
1253   apply (fast dest!: theI')
1254   apply (fast intro: ext the1_equality [symmetric])
1255   apply (erule ex1E)
1256   apply (rule allI)
1257   apply (rule ex1I)
1258   apply (erule spec)
1259   apply (erule_tac x = "%z. if z = x then y else f z" in allE)
1260   apply (erule impE)
1261   apply (rule allI)
1262   apply (rule_tac P = "xa = x" in case_split_thm)
1263   apply (drule_tac  x = x in fun_cong, simp_all)
1264   done
1266 text{*Needs only HOL-lemmas:*}
1267 lemma mk_left_commute:
1268   assumes a: "\<And>x y z. f (f x y) z = f x (f y z)" and
1269           c: "\<And>x y. f x y = f y x"
1270   shows "f x (f y z) = f y (f x z)"
1271 by(rule trans[OF trans[OF c a] arg_cong[OF c, of "f y"]])
1274 subsection {* Generic cases and induction *}
1276 constdefs
1277   induct_forall where "induct_forall P == \<forall>x. P x"
1278   induct_implies where "induct_implies A B == A \<longrightarrow> B"
1279   induct_equal where "induct_equal x y == x = y"
1280   induct_conj where "induct_conj A B == A \<and> B"
1282 lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
1283   by (unfold atomize_all induct_forall_def)
1285 lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
1286   by (unfold atomize_imp induct_implies_def)
1288 lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
1289   by (unfold atomize_eq induct_equal_def)
1291 lemma induct_conj_eq:
1292   includes meta_conjunction_syntax
1293   shows "(A && B) == Trueprop (induct_conj A B)"
1294   by (unfold atomize_conj induct_conj_def)
1296 lemmas induct_atomize = induct_forall_eq induct_implies_eq induct_equal_eq induct_conj_eq
1297 lemmas induct_rulify [symmetric, standard] = induct_atomize
1298 lemmas induct_rulify_fallback =
1299   induct_forall_def induct_implies_def induct_equal_def induct_conj_def
1302 lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
1303     induct_conj (induct_forall A) (induct_forall B)"
1304   by (unfold induct_forall_def induct_conj_def) iprover
1306 lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
1307     induct_conj (induct_implies C A) (induct_implies C B)"
1308   by (unfold induct_implies_def induct_conj_def) iprover
1310 lemma induct_conj_curry: "(induct_conj A B ==> PROP C) == (A ==> B ==> PROP C)"
1311 proof
1312   assume r: "induct_conj A B ==> PROP C" and A B
1313   show "PROP C" by (rule r) (simp add: induct_conj_def `A` `B`)
1314 next
1315   assume r: "A ==> B ==> PROP C" and "induct_conj A B"
1316   show "PROP C" by (rule r) (simp_all add: `induct_conj A B` [unfolded induct_conj_def])
1317 qed
1319 lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
1321 hide const induct_forall induct_implies induct_equal induct_conj
1324 text {* Method setup. *}
1326 ML {*
1327   structure InductMethod = InductMethodFun
1328   (struct
1329     val cases_default = thm "case_split"
1330     val atomize = thms "induct_atomize"
1331     val rulify = thms "induct_rulify"
1332     val rulify_fallback = thms "induct_rulify_fallback"
1333   end);
1334 *}
1336 setup InductMethod.setup
1339 subsubsection {*Tags, for the ATP Linkup *}
1341 constdefs
1342   tag :: "bool => bool"
1343   "tag P == P"
1345 text{*These label the distinguished literals of introduction and elimination
1346 rules.*}
1348 lemma tagI: "P ==> tag P"
1349 by (simp add: tag_def)
1351 lemma tagD: "tag P ==> P"
1352 by (simp add: tag_def)
1354 text{*Applications of "tag" to True and False must go!*}
1356 lemma tag_True: "tag True = True"
1357 by (simp add: tag_def)
1359 lemma tag_False: "tag False = False"
1360 by (simp add: tag_def)
1363 subsection {* Code generator setup *}
1365 code_alias
1366   bool "HOL.bool"
1367   True "HOL.True"
1368   False "HOL.False"
1369   "op =" "HOL.op_eq"
1370   "op -->" "HOL.op_implies"
1371   "op &" "HOL.op_and"
1372   "op |" "HOL.op_or"
1373   "op +" "IntDef.op_add"
1374   "op -" "IntDef.op_minus"
1375   "op *" "IntDef.op_times"
1376   Not "HOL.not"
1377   uminus "HOL.uminus"
1379 code_syntax_tyco bool
1380   ml (atom "bool")
1381   haskell (atom "Bool")
1383 code_syntax_const
1384   Not
1385     ml (atom "not")
1386     haskell (atom "not")
1387   "op &"
1388     ml (infixl 1 "andalso")
1389     haskell (infixl 3 "&&")
1390   "op |"
1391     ml (infixl 0 "orelse")
1392     haskell (infixl 2 "||")
1393   If
1394     ml ("if __/ then __/ else __")
1395     haskell ("if __/ then __/ else __")
1396   "op =" (* an intermediate solution *)
1397     ml (infixl 6 "=")
1398     haskell (infixl 4 "==")
1400 end