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