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