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