src/HOL/HOL.thy
author haftmann
Wed Apr 15 15:34:54 2009 +0200 (2009-04-15)
changeset 30927 bc51b343f80d
parent 30609 983e8b6e4e69
child 30929 d9343c0aac11
permissions -rw-r--r--
wrecked old code_funcgr module
     1 (*  Title:      HOL/HOL.thy
     2     Author:     Tobias Nipkow, Markus Wenzel, and Larry Paulson
     3 *)
     4 
     5 header {* The basis of Higher-Order Logic *}
     6 
     7 theory HOL
     8 imports Pure
     9 uses
    10   ("Tools/hologic.ML")
    11   "~~/src/Tools/IsaPlanner/zipper.ML"
    12   "~~/src/Tools/IsaPlanner/isand.ML"
    13   "~~/src/Tools/IsaPlanner/rw_tools.ML"
    14   "~~/src/Tools/IsaPlanner/rw_inst.ML"
    15   "~~/src/Tools/intuitionistic.ML"
    16   "~~/src/Tools/project_rule.ML"
    17   "~~/src/Provers/hypsubst.ML"
    18   "~~/src/Provers/splitter.ML"
    19   "~~/src/Provers/classical.ML"
    20   "~~/src/Provers/blast.ML"
    21   "~~/src/Provers/clasimp.ML"
    22   "~~/src/Tools/coherent.ML"
    23   "~~/src/Tools/eqsubst.ML"
    24   "~~/src/Provers/quantifier1.ML"
    25   ("Tools/simpdata.ML")
    26   "~~/src/Tools/random_word.ML"
    27   "~~/src/Tools/atomize_elim.ML"
    28   "~~/src/Tools/induct.ML"
    29   ("~~/src/Tools/induct_tacs.ML")
    30   "~~/src/Tools/value.ML"
    31   "~~/src/Tools/code/code_name.ML"
    32   "~~/src/Tools/code/code_wellsorted.ML" 
    33   "~~/src/Tools/code/code_thingol.ML"
    34   "~~/src/Tools/code/code_printer.ML"
    35   "~~/src/Tools/code/code_target.ML"
    36   "~~/src/Tools/code/code_ml.ML"
    37   "~~/src/Tools/code/code_haskell.ML"
    38   "~~/src/Tools/nbe.ML"
    39   ("Tools/recfun_codegen.ML")
    40 begin
    41 
    42 setup {* Intuitionistic.method_setup "iprover" *}
    43 
    44 
    45 subsection {* Primitive logic *}
    46 
    47 subsubsection {* Core syntax *}
    48 
    49 classes type
    50 defaultsort type
    51 setup {* ObjectLogic.add_base_sort @{sort type} *}
    52 
    53 arities
    54   "fun" :: (type, type) type
    55   itself :: (type) type
    56 
    57 global
    58 
    59 typedecl bool
    60 
    61 judgment
    62   Trueprop      :: "bool => prop"                   ("(_)" 5)
    63 
    64 consts
    65   Not           :: "bool => bool"                   ("~ _" [40] 40)
    66   True          :: bool
    67   False         :: bool
    68 
    69   The           :: "('a => bool) => 'a"
    70   All           :: "('a => bool) => bool"           (binder "ALL " 10)
    71   Ex            :: "('a => bool) => bool"           (binder "EX " 10)
    72   Ex1           :: "('a => bool) => bool"           (binder "EX! " 10)
    73   Let           :: "['a, 'a => 'b] => 'b"
    74 
    75   "op ="        :: "['a, 'a] => bool"               (infixl "=" 50)
    76   "op &"        :: "[bool, bool] => bool"           (infixr "&" 35)
    77   "op |"        :: "[bool, bool] => bool"           (infixr "|" 30)
    78   "op -->"      :: "[bool, bool] => bool"           (infixr "-->" 25)
    79 
    80 local
    81 
    82 consts
    83   If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
    84 
    85 
    86 subsubsection {* Additional concrete syntax *}
    87 
    88 notation (output)
    89   "op ="  (infix "=" 50)
    90 
    91 abbreviation
    92   not_equal :: "['a, 'a] => bool"  (infixl "~=" 50) where
    93   "x ~= y == ~ (x = y)"
    94 
    95 notation (output)
    96   not_equal  (infix "~=" 50)
    97 
    98 notation (xsymbols)
    99   Not  ("\<not> _" [40] 40) and
   100   "op &"  (infixr "\<and>" 35) and
   101   "op |"  (infixr "\<or>" 30) and
   102   "op -->"  (infixr "\<longrightarrow>" 25) and
   103   not_equal  (infix "\<noteq>" 50)
   104 
   105 notation (HTML output)
   106   Not  ("\<not> _" [40] 40) and
   107   "op &"  (infixr "\<and>" 35) and
   108   "op |"  (infixr "\<or>" 30) and
   109   not_equal  (infix "\<noteq>" 50)
   110 
   111 abbreviation (iff)
   112   iff :: "[bool, bool] => bool"  (infixr "<->" 25) where
   113   "A <-> B == A = B"
   114 
   115 notation (xsymbols)
   116   iff  (infixr "\<longleftrightarrow>" 25)
   117 
   118 
   119 nonterminals
   120   letbinds  letbind
   121   case_syn  cases_syn
   122 
   123 syntax
   124   "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
   125 
   126   "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
   127   ""            :: "letbind => letbinds"                 ("_")
   128   "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
   129   "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
   130 
   131   "_case_syntax":: "['a, cases_syn] => 'b"               ("(case _ of/ _)" 10)
   132   "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
   133   ""            :: "case_syn => cases_syn"               ("_")
   134   "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
   135 
   136 translations
   137   "THE x. P"              == "The (%x. P)"
   138   "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
   139   "let x = a in e"        == "Let a (%x. e)"
   140 
   141 print_translation {*
   142 (* To avoid eta-contraction of body: *)
   143 [("The", fn [Abs abs] =>
   144      let val (x,t) = atomic_abs_tr' abs
   145      in Syntax.const "_The" $ x $ t end)]
   146 *}
   147 
   148 syntax (xsymbols)
   149   "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
   150 
   151 notation (xsymbols)
   152   All  (binder "\<forall>" 10) and
   153   Ex  (binder "\<exists>" 10) and
   154   Ex1  (binder "\<exists>!" 10)
   155 
   156 notation (HTML output)
   157   All  (binder "\<forall>" 10) and
   158   Ex  (binder "\<exists>" 10) and
   159   Ex1  (binder "\<exists>!" 10)
   160 
   161 notation (HOL)
   162   All  (binder "! " 10) and
   163   Ex  (binder "? " 10) and
   164   Ex1  (binder "?! " 10)
   165 
   166 
   167 subsubsection {* Axioms and basic definitions *}
   168 
   169 axioms
   170   refl:           "t = (t::'a)"
   171   subst:          "s = t \<Longrightarrow> P s \<Longrightarrow> P t"
   172   ext:            "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
   173     -- {*Extensionality is built into the meta-logic, and this rule expresses
   174          a related property.  It is an eta-expanded version of the traditional
   175          rule, and similar to the ABS rule of HOL*}
   176 
   177   the_eq_trivial: "(THE x. x = a) = (a::'a)"
   178 
   179   impI:           "(P ==> Q) ==> P-->Q"
   180   mp:             "[| P-->Q;  P |] ==> Q"
   181 
   182 
   183 defs
   184   True_def:     "True      == ((%x::bool. x) = (%x. x))"
   185   All_def:      "All(P)    == (P = (%x. True))"
   186   Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
   187   False_def:    "False     == (!P. P)"
   188   not_def:      "~ P       == P-->False"
   189   and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
   190   or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
   191   Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
   192 
   193 axioms
   194   iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
   195   True_or_False:  "(P=True) | (P=False)"
   196 
   197 defs
   198   Let_def:      "Let s f == f(s)"
   199   if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
   200 
   201 finalconsts
   202   "op ="
   203   "op -->"
   204   The
   205 
   206 axiomatization
   207   undefined :: 'a
   208 
   209 abbreviation (input)
   210   "arbitrary \<equiv> undefined"
   211 
   212 
   213 subsubsection {* Generic classes and algebraic operations *}
   214 
   215 class default =
   216   fixes default :: 'a
   217 
   218 class zero = 
   219   fixes zero :: 'a  ("0")
   220 
   221 class one =
   222   fixes one  :: 'a  ("1")
   223 
   224 hide (open) const zero one
   225 
   226 class plus =
   227   fixes plus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "+" 65)
   228 
   229 class minus =
   230   fixes minus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "-" 65)
   231 
   232 class uminus =
   233   fixes uminus :: "'a \<Rightarrow> 'a"  ("- _" [81] 80)
   234 
   235 class times =
   236   fixes times :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "*" 70)
   237 
   238 class inverse =
   239   fixes inverse :: "'a \<Rightarrow> 'a"
   240     and divide :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "'/" 70)
   241 
   242 class abs =
   243   fixes abs :: "'a \<Rightarrow> 'a"
   244 begin
   245 
   246 notation (xsymbols)
   247   abs  ("\<bar>_\<bar>")
   248 
   249 notation (HTML output)
   250   abs  ("\<bar>_\<bar>")
   251 
   252 end
   253 
   254 class sgn =
   255   fixes sgn :: "'a \<Rightarrow> 'a"
   256 
   257 class ord =
   258   fixes less_eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
   259     and less :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
   260 begin
   261 
   262 notation
   263   less_eq  ("op <=") and
   264   less_eq  ("(_/ <= _)" [51, 51] 50) and
   265   less  ("op <") and
   266   less  ("(_/ < _)"  [51, 51] 50)
   267   
   268 notation (xsymbols)
   269   less_eq  ("op \<le>") and
   270   less_eq  ("(_/ \<le> _)"  [51, 51] 50)
   271 
   272 notation (HTML output)
   273   less_eq  ("op \<le>") and
   274   less_eq  ("(_/ \<le> _)"  [51, 51] 50)
   275 
   276 abbreviation (input)
   277   greater_eq  (infix ">=" 50) where
   278   "x >= y \<equiv> y <= x"
   279 
   280 notation (input)
   281   greater_eq  (infix "\<ge>" 50)
   282 
   283 abbreviation (input)
   284   greater  (infix ">" 50) where
   285   "x > y \<equiv> y < x"
   286 
   287 end
   288 
   289 syntax
   290   "_index1"  :: index    ("\<^sub>1")
   291 translations
   292   (index) "\<^sub>1" => (index) "\<^bsub>\<struct>\<^esub>"
   293 
   294 typed_print_translation {*
   295 let
   296   fun tr' c = (c, fn show_sorts => fn T => fn ts =>
   297     if (not o null) ts orelse T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
   298     else Syntax.const Syntax.constrainC $ Syntax.const c $ Syntax.term_of_typ show_sorts T);
   299 in map tr' [@{const_syntax HOL.one}, @{const_syntax HOL.zero}] end;
   300 *} -- {* show types that are presumably too general *}
   301 
   302 
   303 subsection {* Fundamental rules *}
   304 
   305 subsubsection {* Equality *}
   306 
   307 lemma sym: "s = t ==> t = s"
   308   by (erule subst) (rule refl)
   309 
   310 lemma ssubst: "t = s ==> P s ==> P t"
   311   by (drule sym) (erule subst)
   312 
   313 lemma trans: "[| r=s; s=t |] ==> r=t"
   314   by (erule subst)
   315 
   316 lemma meta_eq_to_obj_eq: 
   317   assumes meq: "A == B"
   318   shows "A = B"
   319   by (unfold meq) (rule refl)
   320 
   321 text {* Useful with @{text erule} for proving equalities from known equalities. *}
   322      (* a = b
   323         |   |
   324         c = d   *)
   325 lemma box_equals: "[| a=b;  a=c;  b=d |] ==> c=d"
   326 apply (rule trans)
   327 apply (rule trans)
   328 apply (rule sym)
   329 apply assumption+
   330 done
   331 
   332 text {* For calculational reasoning: *}
   333 
   334 lemma forw_subst: "a = b ==> P b ==> P a"
   335   by (rule ssubst)
   336 
   337 lemma back_subst: "P a ==> a = b ==> P b"
   338   by (rule subst)
   339 
   340 
   341 subsubsection {*Congruence rules for application*}
   342 
   343 (*similar to AP_THM in Gordon's HOL*)
   344 lemma fun_cong: "(f::'a=>'b) = g ==> f(x)=g(x)"
   345 apply (erule subst)
   346 apply (rule refl)
   347 done
   348 
   349 (*similar to AP_TERM in Gordon's HOL and FOL's subst_context*)
   350 lemma arg_cong: "x=y ==> f(x)=f(y)"
   351 apply (erule subst)
   352 apply (rule refl)
   353 done
   354 
   355 lemma arg_cong2: "\<lbrakk> a = b; c = d \<rbrakk> \<Longrightarrow> f a c = f b d"
   356 apply (erule ssubst)+
   357 apply (rule refl)
   358 done
   359 
   360 lemma cong: "[| f = g; (x::'a) = y |] ==> f(x) = g(y)"
   361 apply (erule subst)+
   362 apply (rule refl)
   363 done
   364 
   365 
   366 subsubsection {*Equality of booleans -- iff*}
   367 
   368 lemma iffI: assumes "P ==> Q" and "Q ==> P" shows "P=Q"
   369   by (iprover intro: iff [THEN mp, THEN mp] impI assms)
   370 
   371 lemma iffD2: "[| P=Q; Q |] ==> P"
   372   by (erule ssubst)
   373 
   374 lemma rev_iffD2: "[| Q; P=Q |] ==> P"
   375   by (erule iffD2)
   376 
   377 lemma iffD1: "Q = P \<Longrightarrow> Q \<Longrightarrow> P"
   378   by (drule sym) (rule iffD2)
   379 
   380 lemma rev_iffD1: "Q \<Longrightarrow> Q = P \<Longrightarrow> P"
   381   by (drule sym) (rule rev_iffD2)
   382 
   383 lemma iffE:
   384   assumes major: "P=Q"
   385     and minor: "[| P --> Q; Q --> P |] ==> R"
   386   shows R
   387   by (iprover intro: minor impI major [THEN iffD2] major [THEN iffD1])
   388 
   389 
   390 subsubsection {*True*}
   391 
   392 lemma TrueI: "True"
   393   unfolding True_def by (rule refl)
   394 
   395 lemma eqTrueI: "P ==> P = True"
   396   by (iprover intro: iffI TrueI)
   397 
   398 lemma eqTrueE: "P = True ==> P"
   399   by (erule iffD2) (rule TrueI)
   400 
   401 
   402 subsubsection {*Universal quantifier*}
   403 
   404 lemma allI: assumes "!!x::'a. P(x)" shows "ALL x. P(x)"
   405   unfolding All_def by (iprover intro: ext eqTrueI assms)
   406 
   407 lemma spec: "ALL x::'a. P(x) ==> P(x)"
   408 apply (unfold All_def)
   409 apply (rule eqTrueE)
   410 apply (erule fun_cong)
   411 done
   412 
   413 lemma allE:
   414   assumes major: "ALL x. P(x)"
   415     and minor: "P(x) ==> R"
   416   shows R
   417   by (iprover intro: minor major [THEN spec])
   418 
   419 lemma all_dupE:
   420   assumes major: "ALL x. P(x)"
   421     and minor: "[| P(x); ALL x. P(x) |] ==> R"
   422   shows R
   423   by (iprover intro: minor major major [THEN spec])
   424 
   425 
   426 subsubsection {* False *}
   427 
   428 text {*
   429   Depends upon @{text spec}; it is impossible to do propositional
   430   logic before quantifiers!
   431 *}
   432 
   433 lemma FalseE: "False ==> P"
   434   apply (unfold False_def)
   435   apply (erule spec)
   436   done
   437 
   438 lemma False_neq_True: "False = True ==> P"
   439   by (erule eqTrueE [THEN FalseE])
   440 
   441 
   442 subsubsection {* Negation *}
   443 
   444 lemma notI:
   445   assumes "P ==> False"
   446   shows "~P"
   447   apply (unfold not_def)
   448   apply (iprover intro: impI assms)
   449   done
   450 
   451 lemma False_not_True: "False ~= True"
   452   apply (rule notI)
   453   apply (erule False_neq_True)
   454   done
   455 
   456 lemma True_not_False: "True ~= False"
   457   apply (rule notI)
   458   apply (drule sym)
   459   apply (erule False_neq_True)
   460   done
   461 
   462 lemma notE: "[| ~P;  P |] ==> R"
   463   apply (unfold not_def)
   464   apply (erule mp [THEN FalseE])
   465   apply assumption
   466   done
   467 
   468 lemma notI2: "(P \<Longrightarrow> \<not> Pa) \<Longrightarrow> (P \<Longrightarrow> Pa) \<Longrightarrow> \<not> P"
   469   by (erule notE [THEN notI]) (erule meta_mp)
   470 
   471 
   472 subsubsection {*Implication*}
   473 
   474 lemma impE:
   475   assumes "P-->Q" "P" "Q ==> R"
   476   shows "R"
   477 by (iprover intro: assms mp)
   478 
   479 (* Reduces Q to P-->Q, allowing substitution in P. *)
   480 lemma rev_mp: "[| P;  P --> Q |] ==> Q"
   481 by (iprover intro: mp)
   482 
   483 lemma contrapos_nn:
   484   assumes major: "~Q"
   485       and minor: "P==>Q"
   486   shows "~P"
   487 by (iprover intro: notI minor major [THEN notE])
   488 
   489 (*not used at all, but we already have the other 3 combinations *)
   490 lemma contrapos_pn:
   491   assumes major: "Q"
   492       and minor: "P ==> ~Q"
   493   shows "~P"
   494 by (iprover intro: notI minor major notE)
   495 
   496 lemma not_sym: "t ~= s ==> s ~= t"
   497   by (erule contrapos_nn) (erule sym)
   498 
   499 lemma eq_neq_eq_imp_neq: "[| x = a ; a ~= b; b = y |] ==> x ~= y"
   500   by (erule subst, erule ssubst, assumption)
   501 
   502 (*still used in HOLCF*)
   503 lemma rev_contrapos:
   504   assumes pq: "P ==> Q"
   505       and nq: "~Q"
   506   shows "~P"
   507 apply (rule nq [THEN contrapos_nn])
   508 apply (erule pq)
   509 done
   510 
   511 subsubsection {*Existential quantifier*}
   512 
   513 lemma exI: "P x ==> EX x::'a. P x"
   514 apply (unfold Ex_def)
   515 apply (iprover intro: allI allE impI mp)
   516 done
   517 
   518 lemma exE:
   519   assumes major: "EX x::'a. P(x)"
   520       and minor: "!!x. P(x) ==> Q"
   521   shows "Q"
   522 apply (rule major [unfolded Ex_def, THEN spec, THEN mp])
   523 apply (iprover intro: impI [THEN allI] minor)
   524 done
   525 
   526 
   527 subsubsection {*Conjunction*}
   528 
   529 lemma conjI: "[| P; Q |] ==> P&Q"
   530 apply (unfold and_def)
   531 apply (iprover intro: impI [THEN allI] mp)
   532 done
   533 
   534 lemma conjunct1: "[| P & Q |] ==> P"
   535 apply (unfold and_def)
   536 apply (iprover intro: impI dest: spec mp)
   537 done
   538 
   539 lemma conjunct2: "[| P & Q |] ==> Q"
   540 apply (unfold and_def)
   541 apply (iprover intro: impI dest: spec mp)
   542 done
   543 
   544 lemma conjE:
   545   assumes major: "P&Q"
   546       and minor: "[| P; Q |] ==> R"
   547   shows "R"
   548 apply (rule minor)
   549 apply (rule major [THEN conjunct1])
   550 apply (rule major [THEN conjunct2])
   551 done
   552 
   553 lemma context_conjI:
   554   assumes "P" "P ==> Q" shows "P & Q"
   555 by (iprover intro: conjI assms)
   556 
   557 
   558 subsubsection {*Disjunction*}
   559 
   560 lemma disjI1: "P ==> P|Q"
   561 apply (unfold or_def)
   562 apply (iprover intro: allI impI mp)
   563 done
   564 
   565 lemma disjI2: "Q ==> P|Q"
   566 apply (unfold or_def)
   567 apply (iprover intro: allI impI mp)
   568 done
   569 
   570 lemma disjE:
   571   assumes major: "P|Q"
   572       and minorP: "P ==> R"
   573       and minorQ: "Q ==> R"
   574   shows "R"
   575 by (iprover intro: minorP minorQ impI
   576                  major [unfolded or_def, THEN spec, THEN mp, THEN mp])
   577 
   578 
   579 subsubsection {*Classical logic*}
   580 
   581 lemma classical:
   582   assumes prem: "~P ==> P"
   583   shows "P"
   584 apply (rule True_or_False [THEN disjE, THEN eqTrueE])
   585 apply assumption
   586 apply (rule notI [THEN prem, THEN eqTrueI])
   587 apply (erule subst)
   588 apply assumption
   589 done
   590 
   591 lemmas ccontr = FalseE [THEN classical, standard]
   592 
   593 (*notE with premises exchanged; it discharges ~R so that it can be used to
   594   make elimination rules*)
   595 lemma rev_notE:
   596   assumes premp: "P"
   597       and premnot: "~R ==> ~P"
   598   shows "R"
   599 apply (rule ccontr)
   600 apply (erule notE [OF premnot premp])
   601 done
   602 
   603 (*Double negation law*)
   604 lemma notnotD: "~~P ==> P"
   605 apply (rule classical)
   606 apply (erule notE)
   607 apply assumption
   608 done
   609 
   610 lemma contrapos_pp:
   611   assumes p1: "Q"
   612       and p2: "~P ==> ~Q"
   613   shows "P"
   614 by (iprover intro: classical p1 p2 notE)
   615 
   616 
   617 subsubsection {*Unique existence*}
   618 
   619 lemma ex1I:
   620   assumes "P a" "!!x. P(x) ==> x=a"
   621   shows "EX! x. P(x)"
   622 by (unfold Ex1_def, iprover intro: assms exI conjI allI impI)
   623 
   624 text{*Sometimes easier to use: the premises have no shared variables.  Safe!*}
   625 lemma ex_ex1I:
   626   assumes ex_prem: "EX x. P(x)"
   627       and eq: "!!x y. [| P(x); P(y) |] ==> x=y"
   628   shows "EX! x. P(x)"
   629 by (iprover intro: ex_prem [THEN exE] ex1I eq)
   630 
   631 lemma ex1E:
   632   assumes major: "EX! x. P(x)"
   633       and minor: "!!x. [| P(x);  ALL y. P(y) --> y=x |] ==> R"
   634   shows "R"
   635 apply (rule major [unfolded Ex1_def, THEN exE])
   636 apply (erule conjE)
   637 apply (iprover intro: minor)
   638 done
   639 
   640 lemma ex1_implies_ex: "EX! x. P x ==> EX x. P x"
   641 apply (erule ex1E)
   642 apply (rule exI)
   643 apply assumption
   644 done
   645 
   646 
   647 subsubsection {*THE: definite description operator*}
   648 
   649 lemma the_equality:
   650   assumes prema: "P a"
   651       and premx: "!!x. P x ==> x=a"
   652   shows "(THE x. P x) = a"
   653 apply (rule trans [OF _ the_eq_trivial])
   654 apply (rule_tac f = "The" in arg_cong)
   655 apply (rule ext)
   656 apply (rule iffI)
   657  apply (erule premx)
   658 apply (erule ssubst, rule prema)
   659 done
   660 
   661 lemma theI:
   662   assumes "P a" and "!!x. P x ==> x=a"
   663   shows "P (THE x. P x)"
   664 by (iprover intro: assms the_equality [THEN ssubst])
   665 
   666 lemma theI': "EX! x. P x ==> P (THE x. P x)"
   667 apply (erule ex1E)
   668 apply (erule theI)
   669 apply (erule allE)
   670 apply (erule mp)
   671 apply assumption
   672 done
   673 
   674 (*Easier to apply than theI: only one occurrence of P*)
   675 lemma theI2:
   676   assumes "P a" "!!x. P x ==> x=a" "!!x. P x ==> Q x"
   677   shows "Q (THE x. P x)"
   678 by (iprover intro: assms theI)
   679 
   680 lemma the1I2: assumes "EX! x. P x" "\<And>x. P x \<Longrightarrow> Q x" shows "Q (THE x. P x)"
   681 by(iprover intro:assms(2) theI2[where P=P and Q=Q] ex1E[OF assms(1)]
   682            elim:allE impE)
   683 
   684 lemma the1_equality [elim?]: "[| EX!x. P x; P a |] ==> (THE x. P x) = a"
   685 apply (rule the_equality)
   686 apply  assumption
   687 apply (erule ex1E)
   688 apply (erule all_dupE)
   689 apply (drule mp)
   690 apply  assumption
   691 apply (erule ssubst)
   692 apply (erule allE)
   693 apply (erule mp)
   694 apply assumption
   695 done
   696 
   697 lemma the_sym_eq_trivial: "(THE y. x=y) = x"
   698 apply (rule the_equality)
   699 apply (rule refl)
   700 apply (erule sym)
   701 done
   702 
   703 
   704 subsubsection {*Classical intro rules for disjunction and existential quantifiers*}
   705 
   706 lemma disjCI:
   707   assumes "~Q ==> P" shows "P|Q"
   708 apply (rule classical)
   709 apply (iprover intro: assms disjI1 disjI2 notI elim: notE)
   710 done
   711 
   712 lemma excluded_middle: "~P | P"
   713 by (iprover intro: disjCI)
   714 
   715 text {*
   716   case distinction as a natural deduction rule.
   717   Note that @{term "~P"} is the second case, not the first
   718 *}
   719 lemma case_split [case_names True False]:
   720   assumes prem1: "P ==> Q"
   721       and prem2: "~P ==> Q"
   722   shows "Q"
   723 apply (rule excluded_middle [THEN disjE])
   724 apply (erule prem2)
   725 apply (erule prem1)
   726 done
   727 
   728 (*Classical implies (-->) elimination. *)
   729 lemma impCE:
   730   assumes major: "P-->Q"
   731       and minor: "~P ==> R" "Q ==> R"
   732   shows "R"
   733 apply (rule excluded_middle [of P, THEN disjE])
   734 apply (iprover intro: minor major [THEN mp])+
   735 done
   736 
   737 (*This version of --> elimination works on Q before P.  It works best for
   738   those cases in which P holds "almost everywhere".  Can't install as
   739   default: would break old proofs.*)
   740 lemma impCE':
   741   assumes major: "P-->Q"
   742       and minor: "Q ==> R" "~P ==> R"
   743   shows "R"
   744 apply (rule excluded_middle [of P, THEN disjE])
   745 apply (iprover intro: minor major [THEN mp])+
   746 done
   747 
   748 (*Classical <-> elimination. *)
   749 lemma iffCE:
   750   assumes major: "P=Q"
   751       and minor: "[| P; Q |] ==> R"  "[| ~P; ~Q |] ==> R"
   752   shows "R"
   753 apply (rule major [THEN iffE])
   754 apply (iprover intro: minor elim: impCE notE)
   755 done
   756 
   757 lemma exCI:
   758   assumes "ALL x. ~P(x) ==> P(a)"
   759   shows "EX x. P(x)"
   760 apply (rule ccontr)
   761 apply (iprover intro: assms exI allI notI notE [of "\<exists>x. P x"])
   762 done
   763 
   764 
   765 subsubsection {* Intuitionistic Reasoning *}
   766 
   767 lemma impE':
   768   assumes 1: "P --> Q"
   769     and 2: "Q ==> R"
   770     and 3: "P --> Q ==> P"
   771   shows R
   772 proof -
   773   from 3 and 1 have P .
   774   with 1 have Q by (rule impE)
   775   with 2 show R .
   776 qed
   777 
   778 lemma allE':
   779   assumes 1: "ALL x. P x"
   780     and 2: "P x ==> ALL x. P x ==> Q"
   781   shows Q
   782 proof -
   783   from 1 have "P x" by (rule spec)
   784   from this and 1 show Q by (rule 2)
   785 qed
   786 
   787 lemma notE':
   788   assumes 1: "~ P"
   789     and 2: "~ P ==> P"
   790   shows R
   791 proof -
   792   from 2 and 1 have P .
   793   with 1 show R by (rule notE)
   794 qed
   795 
   796 lemma TrueE: "True ==> P ==> P" .
   797 lemma notFalseE: "~ False ==> P ==> P" .
   798 
   799 lemmas [Pure.elim!] = disjE iffE FalseE conjE exE TrueE notFalseE
   800   and [Pure.intro!] = iffI conjI impI TrueI notI allI refl
   801   and [Pure.elim 2] = allE notE' impE'
   802   and [Pure.intro] = exI disjI2 disjI1
   803 
   804 lemmas [trans] = trans
   805   and [sym] = sym not_sym
   806   and [Pure.elim?] = iffD1 iffD2 impE
   807 
   808 use "Tools/hologic.ML"
   809 
   810 
   811 subsubsection {* Atomizing meta-level connectives *}
   812 
   813 axiomatization where
   814   eq_reflection: "x = y \<Longrightarrow> x \<equiv> y" (*admissible axiom*)
   815 
   816 lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
   817 proof
   818   assume "!!x. P x"
   819   then show "ALL x. P x" ..
   820 next
   821   assume "ALL x. P x"
   822   then show "!!x. P x" by (rule allE)
   823 qed
   824 
   825 lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
   826 proof
   827   assume r: "A ==> B"
   828   show "A --> B" by (rule impI) (rule r)
   829 next
   830   assume "A --> B" and A
   831   then show B by (rule mp)
   832 qed
   833 
   834 lemma atomize_not: "(A ==> False) == Trueprop (~A)"
   835 proof
   836   assume r: "A ==> False"
   837   show "~A" by (rule notI) (rule r)
   838 next
   839   assume "~A" and A
   840   then show False by (rule notE)
   841 qed
   842 
   843 lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
   844 proof
   845   assume "x == y"
   846   show "x = y" by (unfold `x == y`) (rule refl)
   847 next
   848   assume "x = y"
   849   then show "x == y" by (rule eq_reflection)
   850 qed
   851 
   852 lemma atomize_conj [atomize]: "(A &&& B) == Trueprop (A & B)"
   853 proof
   854   assume conj: "A &&& B"
   855   show "A & B"
   856   proof (rule conjI)
   857     from conj show A by (rule conjunctionD1)
   858     from conj show B by (rule conjunctionD2)
   859   qed
   860 next
   861   assume conj: "A & B"
   862   show "A &&& B"
   863   proof -
   864     from conj show A ..
   865     from conj show B ..
   866   qed
   867 qed
   868 
   869 lemmas [symmetric, rulify] = atomize_all atomize_imp
   870   and [symmetric, defn] = atomize_all atomize_imp atomize_eq
   871 
   872 
   873 subsubsection {* Atomizing elimination rules *}
   874 
   875 setup AtomizeElim.setup
   876 
   877 lemma atomize_exL[atomize_elim]: "(!!x. P x ==> Q) == ((EX x. P x) ==> Q)"
   878   by rule iprover+
   879 
   880 lemma atomize_conjL[atomize_elim]: "(A ==> B ==> C) == (A & B ==> C)"
   881   by rule iprover+
   882 
   883 lemma atomize_disjL[atomize_elim]: "((A ==> C) ==> (B ==> C) ==> C) == ((A | B ==> C) ==> C)"
   884   by rule iprover+
   885 
   886 lemma atomize_elimL[atomize_elim]: "(!!B. (A ==> B) ==> B) == Trueprop A" ..
   887 
   888 
   889 subsection {* Package setup *}
   890 
   891 subsubsection {* Classical Reasoner setup *}
   892 
   893 lemma imp_elim: "P --> Q ==> (~ R ==> P) ==> (Q ==> R) ==> R"
   894   by (rule classical) iprover
   895 
   896 lemma swap: "~ P ==> (~ R ==> P) ==> R"
   897   by (rule classical) iprover
   898 
   899 lemma thin_refl:
   900   "\<And>X. \<lbrakk> x=x; PROP W \<rbrakk> \<Longrightarrow> PROP W" .
   901 
   902 ML {*
   903 structure Hypsubst = HypsubstFun(
   904 struct
   905   structure Simplifier = Simplifier
   906   val dest_eq = HOLogic.dest_eq
   907   val dest_Trueprop = HOLogic.dest_Trueprop
   908   val dest_imp = HOLogic.dest_imp
   909   val eq_reflection = @{thm eq_reflection}
   910   val rev_eq_reflection = @{thm meta_eq_to_obj_eq}
   911   val imp_intr = @{thm impI}
   912   val rev_mp = @{thm rev_mp}
   913   val subst = @{thm subst}
   914   val sym = @{thm sym}
   915   val thin_refl = @{thm thin_refl};
   916   val prop_subst = @{lemma "PROP P t ==> PROP prop (x = t ==> PROP P x)"
   917                      by (unfold prop_def) (drule eq_reflection, unfold)}
   918 end);
   919 open Hypsubst;
   920 
   921 structure Classical = ClassicalFun(
   922 struct
   923   val imp_elim = @{thm imp_elim}
   924   val not_elim = @{thm notE}
   925   val swap = @{thm swap}
   926   val classical = @{thm classical}
   927   val sizef = Drule.size_of_thm
   928   val hyp_subst_tacs = [Hypsubst.hyp_subst_tac]
   929 end);
   930 
   931 structure BasicClassical: BASIC_CLASSICAL = Classical; 
   932 open BasicClassical;
   933 
   934 ML_Antiquote.value "claset"
   935   (Scan.succeed "Classical.local_claset_of (ML_Context.the_local_context ())");
   936 
   937 structure ResAtpset = NamedThmsFun(val name = "atp" val description = "ATP rules");
   938 
   939 structure ResBlacklist = NamedThmsFun(val name = "noatp" val description = "theorems blacklisted for ATP");
   940 *}
   941 
   942 text {*ResBlacklist holds theorems blacklisted to sledgehammer. 
   943   These theorems typically produce clauses that are prolific (match too many equality or
   944   membership literals) and relate to seldom-used facts. Some duplicate other rules.*}
   945 
   946 setup {*
   947 let
   948   (*prevent substitution on bool*)
   949   fun hyp_subst_tac' i thm = if i <= Thm.nprems_of thm andalso
   950     Term.exists_Const (fn ("op =", Type (_, [T, _])) => T <> Type ("bool", []) | _ => false)
   951       (nth (Thm.prems_of thm) (i - 1)) then Hypsubst.hyp_subst_tac i thm else no_tac thm;
   952 in
   953   Hypsubst.hypsubst_setup
   954   #> ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac)
   955   #> Classical.setup
   956   #> ResAtpset.setup
   957   #> ResBlacklist.setup
   958 end
   959 *}
   960 
   961 declare iffI [intro!]
   962   and notI [intro!]
   963   and impI [intro!]
   964   and disjCI [intro!]
   965   and conjI [intro!]
   966   and TrueI [intro!]
   967   and refl [intro!]
   968 
   969 declare iffCE [elim!]
   970   and FalseE [elim!]
   971   and impCE [elim!]
   972   and disjE [elim!]
   973   and conjE [elim!]
   974   and conjE [elim!]
   975 
   976 declare ex_ex1I [intro!]
   977   and allI [intro!]
   978   and the_equality [intro]
   979   and exI [intro]
   980 
   981 declare exE [elim!]
   982   allE [elim]
   983 
   984 ML {* val HOL_cs = @{claset} *}
   985 
   986 lemma contrapos_np: "~ Q ==> (~ P ==> Q) ==> P"
   987   apply (erule swap)
   988   apply (erule (1) meta_mp)
   989   done
   990 
   991 declare ex_ex1I [rule del, intro! 2]
   992   and ex1I [intro]
   993 
   994 lemmas [intro?] = ext
   995   and [elim?] = ex1_implies_ex
   996 
   997 (*Better then ex1E for classical reasoner: needs no quantifier duplication!*)
   998 lemma alt_ex1E [elim!]:
   999   assumes major: "\<exists>!x. P x"
  1000       and prem: "\<And>x. \<lbrakk> P x; \<forall>y y'. P y \<and> P y' \<longrightarrow> y = y' \<rbrakk> \<Longrightarrow> R"
  1001   shows R
  1002 apply (rule ex1E [OF major])
  1003 apply (rule prem)
  1004 apply (tactic {* ares_tac @{thms allI} 1 *})+
  1005 apply (tactic {* etac (Classical.dup_elim @{thm allE}) 1 *})
  1006 apply iprover
  1007 done
  1008 
  1009 ML {*
  1010 structure Blast = BlastFun
  1011 (
  1012   type claset = Classical.claset
  1013   val equality_name = @{const_name "op ="}
  1014   val not_name = @{const_name Not}
  1015   val notE = @{thm notE}
  1016   val ccontr = @{thm ccontr}
  1017   val contr_tac = Classical.contr_tac
  1018   val dup_intr = Classical.dup_intr
  1019   val hyp_subst_tac = Hypsubst.blast_hyp_subst_tac
  1020   val rep_cs = Classical.rep_cs
  1021   val cla_modifiers = Classical.cla_modifiers
  1022   val cla_meth' = Classical.cla_meth'
  1023 );
  1024 val blast_tac = Blast.blast_tac;
  1025 *}
  1026 
  1027 setup Blast.setup
  1028 
  1029 
  1030 subsubsection {* Simplifier *}
  1031 
  1032 lemma eta_contract_eq: "(%s. f s) = f" ..
  1033 
  1034 lemma simp_thms:
  1035   shows not_not: "(~ ~ P) = P"
  1036   and Not_eq_iff: "((~P) = (~Q)) = (P = Q)"
  1037   and
  1038     "(P ~= Q) = (P = (~Q))"
  1039     "(P | ~P) = True"    "(~P | P) = True"
  1040     "(x = x) = True"
  1041   and not_True_eq_False: "(\<not> True) = False"
  1042   and not_False_eq_True: "(\<not> False) = True"
  1043   and
  1044     "(~P) ~= P"  "P ~= (~P)"
  1045     "(True=P) = P"
  1046   and eq_True: "(P = True) = P"
  1047   and "(False=P) = (~P)"
  1048   and eq_False: "(P = False) = (\<not> P)"
  1049   and
  1050     "(True --> P) = P"  "(False --> P) = True"
  1051     "(P --> True) = True"  "(P --> P) = True"
  1052     "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
  1053     "(P & True) = P"  "(True & P) = P"
  1054     "(P & False) = False"  "(False & P) = False"
  1055     "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
  1056     "(P & ~P) = False"    "(~P & P) = False"
  1057     "(P | True) = True"  "(True | P) = True"
  1058     "(P | False) = P"  "(False | P) = P"
  1059     "(P | P) = P"  "(P | (P | Q)) = (P | Q)" and
  1060     "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
  1061     -- {* needed for the one-point-rule quantifier simplification procs *}
  1062     -- {* essential for termination!! *} and
  1063     "!!P. (EX x. x=t & P(x)) = P(t)"
  1064     "!!P. (EX x. t=x & P(x)) = P(t)"
  1065     "!!P. (ALL x. x=t --> P(x)) = P(t)"
  1066     "!!P. (ALL x. t=x --> P(x)) = P(t)"
  1067   by (blast, blast, blast, blast, blast, iprover+)
  1068 
  1069 lemma disj_absorb: "(A | A) = A"
  1070   by blast
  1071 
  1072 lemma disj_left_absorb: "(A | (A | B)) = (A | B)"
  1073   by blast
  1074 
  1075 lemma conj_absorb: "(A & A) = A"
  1076   by blast
  1077 
  1078 lemma conj_left_absorb: "(A & (A & B)) = (A & B)"
  1079   by blast
  1080 
  1081 lemma eq_ac:
  1082   shows eq_commute: "(a=b) = (b=a)"
  1083     and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
  1084     and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (iprover, blast+)
  1085 lemma neq_commute: "(a~=b) = (b~=a)" by iprover
  1086 
  1087 lemma conj_comms:
  1088   shows conj_commute: "(P&Q) = (Q&P)"
  1089     and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by iprover+
  1090 lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by iprover
  1091 
  1092 lemmas conj_ac = conj_commute conj_left_commute conj_assoc
  1093 
  1094 lemma disj_comms:
  1095   shows disj_commute: "(P|Q) = (Q|P)"
  1096     and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by iprover+
  1097 lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by iprover
  1098 
  1099 lemmas disj_ac = disj_commute disj_left_commute disj_assoc
  1100 
  1101 lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by iprover
  1102 lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by iprover
  1103 
  1104 lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by iprover
  1105 lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by iprover
  1106 
  1107 lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by iprover
  1108 lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by iprover
  1109 lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by iprover
  1110 
  1111 text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
  1112 lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
  1113 lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
  1114 
  1115 lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
  1116 lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
  1117 
  1118 lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
  1119   by iprover
  1120 
  1121 lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by iprover
  1122 lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
  1123 lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
  1124 lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
  1125 lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
  1126 lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
  1127   by blast
  1128 lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
  1129 
  1130 lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by iprover
  1131 
  1132 
  1133 lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
  1134   -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
  1135   -- {* cases boil down to the same thing. *}
  1136   by blast
  1137 
  1138 lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
  1139 lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
  1140 lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by iprover
  1141 lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by iprover
  1142 lemma all_not_ex: "(ALL x. P x) = (~ (EX x. ~ P x ))" by blast
  1143 
  1144 declare All_def [noatp]
  1145 
  1146 lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by iprover
  1147 lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by iprover
  1148 
  1149 text {*
  1150   \medskip The @{text "&"} congruence rule: not included by default!
  1151   May slow rewrite proofs down by as much as 50\% *}
  1152 
  1153 lemma conj_cong:
  1154     "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
  1155   by iprover
  1156 
  1157 lemma rev_conj_cong:
  1158     "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
  1159   by iprover
  1160 
  1161 text {* The @{text "|"} congruence rule: not included by default! *}
  1162 
  1163 lemma disj_cong:
  1164     "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
  1165   by blast
  1166 
  1167 
  1168 text {* \medskip if-then-else rules *}
  1169 
  1170 lemma if_True: "(if True then x else y) = x"
  1171   by (unfold if_def) blast
  1172 
  1173 lemma if_False: "(if False then x else y) = y"
  1174   by (unfold if_def) blast
  1175 
  1176 lemma if_P: "P ==> (if P then x else y) = x"
  1177   by (unfold if_def) blast
  1178 
  1179 lemma if_not_P: "~P ==> (if P then x else y) = y"
  1180   by (unfold if_def) blast
  1181 
  1182 lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
  1183   apply (rule case_split [of Q])
  1184    apply (simplesubst if_P)
  1185     prefer 3 apply (simplesubst if_not_P, blast+)
  1186   done
  1187 
  1188 lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
  1189 by (simplesubst split_if, blast)
  1190 
  1191 lemmas if_splits [noatp] = split_if split_if_asm
  1192 
  1193 lemma if_cancel: "(if c then x else x) = x"
  1194 by (simplesubst split_if, blast)
  1195 
  1196 lemma if_eq_cancel: "(if x = y then y else x) = x"
  1197 by (simplesubst split_if, blast)
  1198 
  1199 lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
  1200   -- {* This form is useful for expanding @{text "if"}s on the RIGHT of the @{text "==>"} symbol. *}
  1201   by (rule split_if)
  1202 
  1203 lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
  1204   -- {* And this form is useful for expanding @{text "if"}s on the LEFT. *}
  1205   apply (simplesubst split_if, blast)
  1206   done
  1207 
  1208 lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) iprover
  1209 lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) iprover
  1210 
  1211 text {* \medskip let rules for simproc *}
  1212 
  1213 lemma Let_folded: "f x \<equiv> g x \<Longrightarrow>  Let x f \<equiv> Let x g"
  1214   by (unfold Let_def)
  1215 
  1216 lemma Let_unfold: "f x \<equiv> g \<Longrightarrow>  Let x f \<equiv> g"
  1217   by (unfold Let_def)
  1218 
  1219 text {*
  1220   The following copy of the implication operator is useful for
  1221   fine-tuning congruence rules.  It instructs the simplifier to simplify
  1222   its premise.
  1223 *}
  1224 
  1225 constdefs
  1226   simp_implies :: "[prop, prop] => prop"  (infixr "=simp=>" 1)
  1227   [code del]: "simp_implies \<equiv> op ==>"
  1228 
  1229 lemma simp_impliesI:
  1230   assumes PQ: "(PROP P \<Longrightarrow> PROP Q)"
  1231   shows "PROP P =simp=> PROP Q"
  1232   apply (unfold simp_implies_def)
  1233   apply (rule PQ)
  1234   apply assumption
  1235   done
  1236 
  1237 lemma simp_impliesE:
  1238   assumes PQ: "PROP P =simp=> PROP Q"
  1239   and P: "PROP P"
  1240   and QR: "PROP Q \<Longrightarrow> PROP R"
  1241   shows "PROP R"
  1242   apply (rule QR)
  1243   apply (rule PQ [unfolded simp_implies_def])
  1244   apply (rule P)
  1245   done
  1246 
  1247 lemma simp_implies_cong:
  1248   assumes PP' :"PROP P == PROP P'"
  1249   and P'QQ': "PROP P' ==> (PROP Q == PROP Q')"
  1250   shows "(PROP P =simp=> PROP Q) == (PROP P' =simp=> PROP Q')"
  1251 proof (unfold simp_implies_def, rule equal_intr_rule)
  1252   assume PQ: "PROP P \<Longrightarrow> PROP Q"
  1253   and P': "PROP P'"
  1254   from PP' [symmetric] and P' have "PROP P"
  1255     by (rule equal_elim_rule1)
  1256   then have "PROP Q" by (rule PQ)
  1257   with P'QQ' [OF P'] show "PROP Q'" by (rule equal_elim_rule1)
  1258 next
  1259   assume P'Q': "PROP P' \<Longrightarrow> PROP Q'"
  1260   and P: "PROP P"
  1261   from PP' and P have P': "PROP P'" by (rule equal_elim_rule1)
  1262   then have "PROP Q'" by (rule P'Q')
  1263   with P'QQ' [OF P', symmetric] show "PROP Q"
  1264     by (rule equal_elim_rule1)
  1265 qed
  1266 
  1267 lemma uncurry:
  1268   assumes "P \<longrightarrow> Q \<longrightarrow> R"
  1269   shows "P \<and> Q \<longrightarrow> R"
  1270   using assms by blast
  1271 
  1272 lemma iff_allI:
  1273   assumes "\<And>x. P x = Q x"
  1274   shows "(\<forall>x. P x) = (\<forall>x. Q x)"
  1275   using assms by blast
  1276 
  1277 lemma iff_exI:
  1278   assumes "\<And>x. P x = Q x"
  1279   shows "(\<exists>x. P x) = (\<exists>x. Q x)"
  1280   using assms by blast
  1281 
  1282 lemma all_comm:
  1283   "(\<forall>x y. P x y) = (\<forall>y x. P x y)"
  1284   by blast
  1285 
  1286 lemma ex_comm:
  1287   "(\<exists>x y. P x y) = (\<exists>y x. P x y)"
  1288   by blast
  1289 
  1290 use "Tools/simpdata.ML"
  1291 ML {* open Simpdata *}
  1292 
  1293 setup {*
  1294   Simplifier.method_setup Splitter.split_modifiers
  1295   #> Simplifier.map_simpset (K Simpdata.simpset_simprocs)
  1296   #> Splitter.setup
  1297   #> clasimp_setup
  1298   #> EqSubst.setup
  1299 *}
  1300 
  1301 text {* Simproc for proving @{text "(y = x) == False"} from premise @{text "~(x = y)"}: *}
  1302 
  1303 simproc_setup neq ("x = y") = {* fn _ =>
  1304 let
  1305   val neq_to_EQ_False = @{thm not_sym} RS @{thm Eq_FalseI};
  1306   fun is_neq eq lhs rhs thm =
  1307     (case Thm.prop_of thm of
  1308       _ $ (Not $ (eq' $ l' $ r')) =>
  1309         Not = HOLogic.Not andalso eq' = eq andalso
  1310         r' aconv lhs andalso l' aconv rhs
  1311     | _ => false);
  1312   fun proc ss ct =
  1313     (case Thm.term_of ct of
  1314       eq $ lhs $ rhs =>
  1315         (case find_first (is_neq eq lhs rhs) (Simplifier.prems_of_ss ss) of
  1316           SOME thm => SOME (thm RS neq_to_EQ_False)
  1317         | NONE => NONE)
  1318      | _ => NONE);
  1319 in proc end;
  1320 *}
  1321 
  1322 simproc_setup let_simp ("Let x f") = {*
  1323 let
  1324   val (f_Let_unfold, x_Let_unfold) =
  1325     let val [(_ $ (f $ x) $ _)] = prems_of @{thm Let_unfold}
  1326     in (cterm_of @{theory} f, cterm_of @{theory} x) end
  1327   val (f_Let_folded, x_Let_folded) =
  1328     let val [(_ $ (f $ x) $ _)] = prems_of @{thm Let_folded}
  1329     in (cterm_of @{theory} f, cterm_of @{theory} x) end;
  1330   val g_Let_folded =
  1331     let val [(_ $ _ $ (g $ _))] = prems_of @{thm Let_folded}
  1332     in cterm_of @{theory} g end;
  1333   fun count_loose (Bound i) k = if i >= k then 1 else 0
  1334     | count_loose (s $ t) k = count_loose s k + count_loose t k
  1335     | count_loose (Abs (_, _, t)) k = count_loose  t (k + 1)
  1336     | count_loose _ _ = 0;
  1337   fun is_trivial_let (Const (@{const_name Let}, _) $ x $ t) =
  1338    case t
  1339     of Abs (_, _, t') => count_loose t' 0 <= 1
  1340      | _ => true;
  1341 in fn _ => fn ss => fn ct => if is_trivial_let (Thm.term_of ct)
  1342   then SOME @{thm Let_def} (*no or one ocurrenc of bound variable*)
  1343   else let (*Norbert Schirmer's case*)
  1344     val ctxt = Simplifier.the_context ss;
  1345     val thy = ProofContext.theory_of ctxt;
  1346     val t = Thm.term_of ct;
  1347     val ([t'], ctxt') = Variable.import_terms false [t] ctxt;
  1348   in Option.map (hd o Variable.export ctxt' ctxt o single)
  1349     (case t' of Const (@{const_name Let},_) $ x $ f => (* x and f are already in normal form *)
  1350       if is_Free x orelse is_Bound x orelse is_Const x
  1351       then SOME @{thm Let_def}
  1352       else
  1353         let
  1354           val n = case f of (Abs (x, _, _)) => x | _ => "x";
  1355           val cx = cterm_of thy x;
  1356           val {T = xT, ...} = rep_cterm cx;
  1357           val cf = cterm_of thy f;
  1358           val fx_g = Simplifier.rewrite ss (Thm.capply cf cx);
  1359           val (_ $ _ $ g) = prop_of fx_g;
  1360           val g' = abstract_over (x,g);
  1361         in (if (g aconv g')
  1362              then
  1363                 let
  1364                   val rl =
  1365                     cterm_instantiate [(f_Let_unfold, cf), (x_Let_unfold, cx)] @{thm Let_unfold};
  1366                 in SOME (rl OF [fx_g]) end
  1367              else if Term.betapply (f, x) aconv g then NONE (*avoid identity conversion*)
  1368              else let
  1369                    val abs_g'= Abs (n,xT,g');
  1370                    val g'x = abs_g'$x;
  1371                    val g_g'x = symmetric (beta_conversion false (cterm_of thy g'x));
  1372                    val rl = cterm_instantiate
  1373                              [(f_Let_folded, cterm_of thy f), (x_Let_folded, cx),
  1374                               (g_Let_folded, cterm_of thy abs_g')]
  1375                              @{thm Let_folded};
  1376                  in SOME (rl OF [transitive fx_g g_g'x])
  1377                  end)
  1378         end
  1379     | _ => NONE)
  1380   end
  1381 end *}
  1382 
  1383 lemma True_implies_equals: "(True \<Longrightarrow> PROP P) \<equiv> PROP P"
  1384 proof
  1385   assume "True \<Longrightarrow> PROP P"
  1386   from this [OF TrueI] show "PROP P" .
  1387 next
  1388   assume "PROP P"
  1389   then show "PROP P" .
  1390 qed
  1391 
  1392 lemma ex_simps:
  1393   "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
  1394   "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
  1395   "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
  1396   "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
  1397   "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
  1398   "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
  1399   -- {* Miniscoping: pushing in existential quantifiers. *}
  1400   by (iprover | blast)+
  1401 
  1402 lemma all_simps:
  1403   "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
  1404   "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
  1405   "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
  1406   "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
  1407   "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
  1408   "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
  1409   -- {* Miniscoping: pushing in universal quantifiers. *}
  1410   by (iprover | blast)+
  1411 
  1412 lemmas [simp] =
  1413   triv_forall_equality (*prunes params*)
  1414   True_implies_equals  (*prune asms `True'*)
  1415   if_True
  1416   if_False
  1417   if_cancel
  1418   if_eq_cancel
  1419   imp_disjL
  1420   (*In general it seems wrong to add distributive laws by default: they
  1421     might cause exponential blow-up.  But imp_disjL has been in for a while
  1422     and cannot be removed without affecting existing proofs.  Moreover,
  1423     rewriting by "(P|Q --> R) = ((P-->R)&(Q-->R))" might be justified on the
  1424     grounds that it allows simplification of R in the two cases.*)
  1425   conj_assoc
  1426   disj_assoc
  1427   de_Morgan_conj
  1428   de_Morgan_disj
  1429   imp_disj1
  1430   imp_disj2
  1431   not_imp
  1432   disj_not1
  1433   not_all
  1434   not_ex
  1435   cases_simp
  1436   the_eq_trivial
  1437   the_sym_eq_trivial
  1438   ex_simps
  1439   all_simps
  1440   simp_thms
  1441 
  1442 lemmas [cong] = imp_cong simp_implies_cong
  1443 lemmas [split] = split_if
  1444 
  1445 ML {* val HOL_ss = @{simpset} *}
  1446 
  1447 text {* Simplifies x assuming c and y assuming ~c *}
  1448 lemma if_cong:
  1449   assumes "b = c"
  1450       and "c \<Longrightarrow> x = u"
  1451       and "\<not> c \<Longrightarrow> y = v"
  1452   shows "(if b then x else y) = (if c then u else v)"
  1453   unfolding if_def using assms by simp
  1454 
  1455 text {* Prevents simplification of x and y:
  1456   faster and allows the execution of functional programs. *}
  1457 lemma if_weak_cong [cong]:
  1458   assumes "b = c"
  1459   shows "(if b then x else y) = (if c then x else y)"
  1460   using assms by (rule arg_cong)
  1461 
  1462 text {* Prevents simplification of t: much faster *}
  1463 lemma let_weak_cong:
  1464   assumes "a = b"
  1465   shows "(let x = a in t x) = (let x = b in t x)"
  1466   using assms by (rule arg_cong)
  1467 
  1468 text {* To tidy up the result of a simproc.  Only the RHS will be simplified. *}
  1469 lemma eq_cong2:
  1470   assumes "u = u'"
  1471   shows "(t \<equiv> u) \<equiv> (t \<equiv> u')"
  1472   using assms by simp
  1473 
  1474 lemma if_distrib:
  1475   "f (if c then x else y) = (if c then f x else f y)"
  1476   by simp
  1477 
  1478 text {* This lemma restricts the effect of the rewrite rule u=v to the left-hand
  1479   side of an equality.  Used in @{text "{Integ,Real}/simproc.ML"} *}
  1480 lemma restrict_to_left:
  1481   assumes "x = y"
  1482   shows "(x = z) = (y = z)"
  1483   using assms by simp
  1484 
  1485 
  1486 subsubsection {* Generic cases and induction *}
  1487 
  1488 text {* Rule projections: *}
  1489 
  1490 ML {*
  1491 structure ProjectRule = ProjectRuleFun
  1492 (
  1493   val conjunct1 = @{thm conjunct1}
  1494   val conjunct2 = @{thm conjunct2}
  1495   val mp = @{thm mp}
  1496 )
  1497 *}
  1498 
  1499 constdefs
  1500   induct_forall where "induct_forall P == \<forall>x. P x"
  1501   induct_implies where "induct_implies A B == A \<longrightarrow> B"
  1502   induct_equal where "induct_equal x y == x = y"
  1503   induct_conj where "induct_conj A B == A \<and> B"
  1504 
  1505 lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
  1506   by (unfold atomize_all induct_forall_def)
  1507 
  1508 lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
  1509   by (unfold atomize_imp induct_implies_def)
  1510 
  1511 lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
  1512   by (unfold atomize_eq induct_equal_def)
  1513 
  1514 lemma induct_conj_eq: "(A &&& B) == Trueprop (induct_conj A B)"
  1515   by (unfold atomize_conj induct_conj_def)
  1516 
  1517 lemmas induct_atomize = induct_forall_eq induct_implies_eq induct_equal_eq induct_conj_eq
  1518 lemmas induct_rulify [symmetric, standard] = induct_atomize
  1519 lemmas induct_rulify_fallback =
  1520   induct_forall_def induct_implies_def induct_equal_def induct_conj_def
  1521 
  1522 
  1523 lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
  1524     induct_conj (induct_forall A) (induct_forall B)"
  1525   by (unfold induct_forall_def induct_conj_def) iprover
  1526 
  1527 lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
  1528     induct_conj (induct_implies C A) (induct_implies C B)"
  1529   by (unfold induct_implies_def induct_conj_def) iprover
  1530 
  1531 lemma induct_conj_curry: "(induct_conj A B ==> PROP C) == (A ==> B ==> PROP C)"
  1532 proof
  1533   assume r: "induct_conj A B ==> PROP C" and A B
  1534   show "PROP C" by (rule r) (simp add: induct_conj_def `A` `B`)
  1535 next
  1536   assume r: "A ==> B ==> PROP C" and "induct_conj A B"
  1537   show "PROP C" by (rule r) (simp_all add: `induct_conj A B` [unfolded induct_conj_def])
  1538 qed
  1539 
  1540 lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
  1541 
  1542 hide const induct_forall induct_implies induct_equal induct_conj
  1543 
  1544 text {* Method setup. *}
  1545 
  1546 ML {*
  1547 structure Induct = InductFun
  1548 (
  1549   val cases_default = @{thm case_split}
  1550   val atomize = @{thms induct_atomize}
  1551   val rulify = @{thms induct_rulify}
  1552   val rulify_fallback = @{thms induct_rulify_fallback}
  1553 )
  1554 *}
  1555 
  1556 setup Induct.setup
  1557 
  1558 use "~~/src/Tools/induct_tacs.ML"
  1559 setup InductTacs.setup
  1560 
  1561 
  1562 subsubsection {* Coherent logic *}
  1563 
  1564 ML {*
  1565 structure Coherent = CoherentFun
  1566 (
  1567   val atomize_elimL = @{thm atomize_elimL}
  1568   val atomize_exL = @{thm atomize_exL}
  1569   val atomize_conjL = @{thm atomize_conjL}
  1570   val atomize_disjL = @{thm atomize_disjL}
  1571   val operator_names =
  1572     [@{const_name "op |"}, @{const_name "op &"}, @{const_name "Ex"}]
  1573 );
  1574 *}
  1575 
  1576 setup Coherent.setup
  1577 
  1578 
  1579 subsection {* Other simple lemmas and lemma duplicates *}
  1580 
  1581 lemma Let_0 [simp]: "Let 0 f = f 0"
  1582   unfolding Let_def ..
  1583 
  1584 lemma Let_1 [simp]: "Let 1 f = f 1"
  1585   unfolding Let_def ..
  1586 
  1587 lemma ex1_eq [iff]: "EX! x. x = t" "EX! x. t = x"
  1588   by blast+
  1589 
  1590 lemma choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))"
  1591   apply (rule iffI)
  1592   apply (rule_tac a = "%x. THE y. P x y" in ex1I)
  1593   apply (fast dest!: theI')
  1594   apply (fast intro: ext the1_equality [symmetric])
  1595   apply (erule ex1E)
  1596   apply (rule allI)
  1597   apply (rule ex1I)
  1598   apply (erule spec)
  1599   apply (erule_tac x = "%z. if z = x then y else f z" in allE)
  1600   apply (erule impE)
  1601   apply (rule allI)
  1602   apply (case_tac "xa = x")
  1603   apply (drule_tac [3] x = x in fun_cong, simp_all)
  1604   done
  1605 
  1606 lemma mk_left_commute:
  1607   fixes f (infix "\<otimes>" 60)
  1608   assumes a: "\<And>x y z. (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)" and
  1609           c: "\<And>x y. x \<otimes> y = y \<otimes> x"
  1610   shows "x \<otimes> (y \<otimes> z) = y \<otimes> (x \<otimes> z)"
  1611   by (rule trans [OF trans [OF c a] arg_cong [OF c, of "f y"]])
  1612 
  1613 lemmas eq_sym_conv = eq_commute
  1614 
  1615 lemma nnf_simps:
  1616   "(\<not>(P \<and> Q)) = (\<not> P \<or> \<not> Q)" "(\<not> (P \<or> Q)) = (\<not> P \<and> \<not>Q)" "(P \<longrightarrow> Q) = (\<not>P \<or> Q)" 
  1617   "(P = Q) = ((P \<and> Q) \<or> (\<not>P \<and> \<not> Q))" "(\<not>(P = Q)) = ((P \<and> \<not> Q) \<or> (\<not>P \<and> Q))" 
  1618   "(\<not> \<not>(P)) = P"
  1619 by blast+
  1620 
  1621 
  1622 subsection {* Basic ML bindings *}
  1623 
  1624 ML {*
  1625 val FalseE = @{thm FalseE}
  1626 val Let_def = @{thm Let_def}
  1627 val TrueI = @{thm TrueI}
  1628 val allE = @{thm allE}
  1629 val allI = @{thm allI}
  1630 val all_dupE = @{thm all_dupE}
  1631 val arg_cong = @{thm arg_cong}
  1632 val box_equals = @{thm box_equals}
  1633 val ccontr = @{thm ccontr}
  1634 val classical = @{thm classical}
  1635 val conjE = @{thm conjE}
  1636 val conjI = @{thm conjI}
  1637 val conjunct1 = @{thm conjunct1}
  1638 val conjunct2 = @{thm conjunct2}
  1639 val disjCI = @{thm disjCI}
  1640 val disjE = @{thm disjE}
  1641 val disjI1 = @{thm disjI1}
  1642 val disjI2 = @{thm disjI2}
  1643 val eq_reflection = @{thm eq_reflection}
  1644 val ex1E = @{thm ex1E}
  1645 val ex1I = @{thm ex1I}
  1646 val ex1_implies_ex = @{thm ex1_implies_ex}
  1647 val exE = @{thm exE}
  1648 val exI = @{thm exI}
  1649 val excluded_middle = @{thm excluded_middle}
  1650 val ext = @{thm ext}
  1651 val fun_cong = @{thm fun_cong}
  1652 val iffD1 = @{thm iffD1}
  1653 val iffD2 = @{thm iffD2}
  1654 val iffI = @{thm iffI}
  1655 val impE = @{thm impE}
  1656 val impI = @{thm impI}
  1657 val meta_eq_to_obj_eq = @{thm meta_eq_to_obj_eq}
  1658 val mp = @{thm mp}
  1659 val notE = @{thm notE}
  1660 val notI = @{thm notI}
  1661 val not_all = @{thm not_all}
  1662 val not_ex = @{thm not_ex}
  1663 val not_iff = @{thm not_iff}
  1664 val not_not = @{thm not_not}
  1665 val not_sym = @{thm not_sym}
  1666 val refl = @{thm refl}
  1667 val rev_mp = @{thm rev_mp}
  1668 val spec = @{thm spec}
  1669 val ssubst = @{thm ssubst}
  1670 val subst = @{thm subst}
  1671 val sym = @{thm sym}
  1672 val trans = @{thm trans}
  1673 *}
  1674 
  1675 
  1676 subsection {* Code generator basics -- see further theory @{text "Code_Setup"} *}
  1677 
  1678 text {* Equality *}
  1679 
  1680 class eq =
  1681   fixes eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
  1682   assumes eq_equals: "eq x y \<longleftrightarrow> x = y"
  1683 begin
  1684 
  1685 lemma eq: "eq = (op =)"
  1686   by (rule ext eq_equals)+
  1687 
  1688 lemma eq_refl: "eq x x \<longleftrightarrow> True"
  1689   unfolding eq by rule+
  1690 
  1691 end
  1692 
  1693 text {* Module setup *}
  1694 
  1695 use "Tools/recfun_codegen.ML"
  1696 
  1697 setup {*
  1698   Code_ML.setup
  1699   #> Code_Haskell.setup
  1700   #> Nbe.setup
  1701   #> Codegen.setup
  1702   #> RecfunCodegen.setup
  1703 *}
  1704 
  1705 
  1706 subsection {* Nitpick hooks *}
  1707 
  1708 text {* This will be relocated once Nitpick is moved to HOL. *}
  1709 
  1710 ML {*
  1711 structure Nitpick_Const_Def_Thms = NamedThmsFun
  1712 (
  1713   val name = "nitpick_const_def"
  1714   val description = "alternative definitions of constants as needed by Nitpick"
  1715 )
  1716 structure Nitpick_Const_Simp_Thms = NamedThmsFun
  1717 (
  1718   val name = "nitpick_const_simp"
  1719   val description = "equational specification of constants as needed by Nitpick"
  1720 )
  1721 structure Nitpick_Const_Psimp_Thms = NamedThmsFun
  1722 (
  1723   val name = "nitpick_const_psimp"
  1724   val description = "partial equational specification of constants as needed by Nitpick"
  1725 )
  1726 structure Nitpick_Ind_Intro_Thms = NamedThmsFun
  1727 (
  1728   val name = "nitpick_ind_intro"
  1729   val description = "introduction rules for (co)inductive predicates as needed by Nitpick"
  1730 )
  1731 *}
  1732 setup {* Nitpick_Const_Def_Thms.setup
  1733          #> Nitpick_Const_Simp_Thms.setup
  1734          #> Nitpick_Const_Psimp_Thms.setup
  1735          #> Nitpick_Ind_Intro_Thms.setup *}
  1736 
  1737 subsection {* Legacy tactics and ML bindings *}
  1738 
  1739 ML {*
  1740 fun strip_tac i = REPEAT (resolve_tac [impI, allI] i);
  1741 
  1742 (* combination of (spec RS spec RS ...(j times) ... spec RS mp) *)
  1743 local
  1744   fun wrong_prem (Const ("All", _) $ (Abs (_, _, t))) = wrong_prem t
  1745     | wrong_prem (Bound _) = true
  1746     | wrong_prem _ = false;
  1747   val filter_right = filter (not o wrong_prem o HOLogic.dest_Trueprop o hd o Thm.prems_of);
  1748 in
  1749   fun smp i = funpow i (fn m => filter_right ([spec] RL m)) ([mp]);
  1750   fun smp_tac j = EVERY'[dresolve_tac (smp j), atac];
  1751 end;
  1752 
  1753 val all_conj_distrib = thm "all_conj_distrib";
  1754 val all_simps = thms "all_simps";
  1755 val atomize_not = thm "atomize_not";
  1756 val case_split = thm "case_split";
  1757 val cases_simp = thm "cases_simp";
  1758 val choice_eq = thm "choice_eq"
  1759 val cong = thm "cong"
  1760 val conj_comms = thms "conj_comms";
  1761 val conj_cong = thm "conj_cong";
  1762 val de_Morgan_conj = thm "de_Morgan_conj";
  1763 val de_Morgan_disj = thm "de_Morgan_disj";
  1764 val disj_assoc = thm "disj_assoc";
  1765 val disj_comms = thms "disj_comms";
  1766 val disj_cong = thm "disj_cong";
  1767 val eq_ac = thms "eq_ac";
  1768 val eq_cong2 = thm "eq_cong2"
  1769 val Eq_FalseI = thm "Eq_FalseI";
  1770 val Eq_TrueI = thm "Eq_TrueI";
  1771 val Ex1_def = thm "Ex1_def"
  1772 val ex_disj_distrib = thm "ex_disj_distrib";
  1773 val ex_simps = thms "ex_simps";
  1774 val if_cancel = thm "if_cancel";
  1775 val if_eq_cancel = thm "if_eq_cancel";
  1776 val if_False = thm "if_False";
  1777 val iff_conv_conj_imp = thm "iff_conv_conj_imp";
  1778 val iff = thm "iff"
  1779 val if_splits = thms "if_splits";
  1780 val if_True = thm "if_True";
  1781 val if_weak_cong = thm "if_weak_cong"
  1782 val imp_all = thm "imp_all";
  1783 val imp_cong = thm "imp_cong";
  1784 val imp_conjL = thm "imp_conjL";
  1785 val imp_conjR = thm "imp_conjR";
  1786 val imp_conv_disj = thm "imp_conv_disj";
  1787 val simp_implies_def = thm "simp_implies_def";
  1788 val simp_thms = thms "simp_thms";
  1789 val split_if = thm "split_if";
  1790 val the1_equality = thm "the1_equality"
  1791 val theI = thm "theI"
  1792 val theI' = thm "theI'"
  1793 val True_implies_equals = thm "True_implies_equals";
  1794 val nnf_conv = Simplifier.rewrite (HOL_basic_ss addsimps simp_thms @ @{thms "nnf_simps"})
  1795 
  1796 *}
  1797 
  1798 end