src/HOL/Inductive.thy
author nipkow
Mon Aug 20 18:10:13 2007 +0200 (2007-08-20)
changeset 24349 0dd8782fb02d
parent 23734 0e11b904b3a3
child 24625 0398a5e802d3
permissions -rw-r--r--
Final mods for list comprehension
     1 (*  Title:      HOL/Inductive.thy
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Muenchen
     4 *)
     5 
     6 header {* Support for inductive sets and types *}
     7 
     8 theory Inductive 
     9 imports FixedPoint Product_Type Sum_Type
    10 uses
    11   ("Tools/inductive_package.ML")
    12   ("Tools/inductive_set_package.ML")
    13   ("Tools/inductive_realizer.ML")
    14   ("Tools/inductive_codegen.ML")
    15   ("Tools/datatype_aux.ML")
    16   ("Tools/datatype_prop.ML")
    17   ("Tools/datatype_rep_proofs.ML")
    18   ("Tools/datatype_abs_proofs.ML")
    19   ("Tools/datatype_realizer.ML")
    20   ("Tools/datatype_hooks.ML")
    21   ("Tools/datatype_case.ML")
    22   ("Tools/datatype_package.ML")
    23   ("Tools/datatype_codegen.ML")
    24   ("Tools/primrec_package.ML")
    25 begin
    26 
    27 subsection {* Inductive predicates and sets *}
    28 
    29 text {* Inversion of injective functions. *}
    30 
    31 constdefs
    32   myinv :: "('a => 'b) => ('b => 'a)"
    33   "myinv (f :: 'a => 'b) == \<lambda>y. THE x. f x = y"
    34 
    35 lemma myinv_f_f: "inj f ==> myinv f (f x) = x"
    36 proof -
    37   assume "inj f"
    38   hence "(THE x'. f x' = f x) = (THE x'. x' = x)"
    39     by (simp only: inj_eq)
    40   also have "... = x" by (rule the_eq_trivial)
    41   finally show ?thesis by (unfold myinv_def)
    42 qed
    43 
    44 lemma f_myinv_f: "inj f ==> y \<in> range f ==> f (myinv f y) = y"
    45 proof (unfold myinv_def)
    46   assume inj: "inj f"
    47   assume "y \<in> range f"
    48   then obtain x where "y = f x" ..
    49   hence x: "f x = y" ..
    50   thus "f (THE x. f x = y) = y"
    51   proof (rule theI)
    52     fix x' assume "f x' = y"
    53     with x have "f x' = f x" by simp
    54     with inj show "x' = x" by (rule injD)
    55   qed
    56 qed
    57 
    58 hide const myinv
    59 
    60 
    61 text {* Package setup. *}
    62 
    63 theorems basic_monos =
    64   subset_refl imp_refl disj_mono conj_mono ex_mono all_mono if_bool_eq_conj
    65   Collect_mono in_mono vimage_mono
    66   imp_conv_disj not_not de_Morgan_disj de_Morgan_conj
    67   not_all not_ex
    68   Ball_def Bex_def
    69   induct_rulify_fallback
    70 
    71 use "Tools/inductive_package.ML"
    72 setup InductivePackage.setup
    73 
    74 theorems [mono] =
    75   imp_refl disj_mono conj_mono ex_mono all_mono if_bool_eq_conj
    76   imp_conv_disj not_not de_Morgan_disj de_Morgan_conj
    77   not_all not_ex
    78   Ball_def Bex_def
    79   induct_rulify_fallback
    80 
    81 lemma False_meta_all:
    82   "Trueprop False \<equiv> (\<And>P\<Colon>bool. P)"
    83 proof
    84   fix P
    85   assume False
    86   then show P ..
    87 next
    88   assume "\<And>P\<Colon>bool. P"
    89   then show False .
    90 qed
    91 
    92 lemma not_eq_False:
    93   assumes not_eq: "x \<noteq> y"
    94   and eq: "x \<equiv> y"
    95   shows False
    96   using not_eq eq by auto
    97 
    98 lemmas not_eq_quodlibet =
    99   not_eq_False [simplified False_meta_all]
   100 
   101 
   102 subsection {* Inductive datatypes and primitive recursion *}
   103 
   104 text {* Package setup. *}
   105 
   106 use "Tools/datatype_aux.ML"
   107 use "Tools/datatype_prop.ML"
   108 use "Tools/datatype_rep_proofs.ML"
   109 use "Tools/datatype_abs_proofs.ML"
   110 use "Tools/datatype_case.ML"
   111 use "Tools/datatype_realizer.ML"
   112 
   113 use "Tools/datatype_hooks.ML"
   114 
   115 use "Tools/datatype_package.ML"
   116 setup DatatypePackage.setup
   117 
   118 use "Tools/datatype_codegen.ML"
   119 setup DatatypeCodegen.setup
   120 
   121 use "Tools/inductive_realizer.ML"
   122 setup InductiveRealizer.setup
   123 
   124 use "Tools/inductive_codegen.ML"
   125 setup InductiveCodegen.setup
   126 
   127 use "Tools/primrec_package.ML"
   128 
   129 use "Tools/inductive_set_package.ML"
   130 setup InductiveSetPackage.setup
   131 
   132 text{* Lambda-abstractions with pattern matching: *}
   133 
   134 syntax
   135   "_lam_pats_syntax" :: "cases_syn => 'a => 'b"               ("(%_)" 10)
   136 syntax (xsymbols)
   137   "_lam_pats_syntax" :: "cases_syn => 'a => 'b"               ("(\<lambda>_)" 10)
   138 
   139 parse_translation (advanced) {*
   140 let
   141   fun fun_tr ctxt [cs] =
   142     let
   143       val x = Free (Name.variant (add_term_free_names (cs, [])) "x", dummyT);
   144       val ft = DatatypeCase.case_tr true DatatypePackage.datatype_of_constr
   145                  ctxt [x, cs]
   146     in lambda x ft end
   147 in [("_lam_pats_syntax", fun_tr)] end
   148 *}
   149 
   150 end