src/HOL/Inductive.thy
author berghofe
Tue Apr 24 15:18:42 2007 +0200 (2007-04-24)
changeset 22783 e5f947e0ade8
parent 22218 30a8890d2967
child 22846 fb79144af9a3
permissions -rw-r--r--
Added datatype_case.
wenzelm@7700
     1
(*  Title:      HOL/Inductive.thy
wenzelm@7700
     2
    ID:         $Id$
wenzelm@10402
     3
    Author:     Markus Wenzel, TU Muenchen
wenzelm@11688
     4
*)
wenzelm@10727
     5
wenzelm@11688
     6
header {* Support for inductive sets and types *}
lcp@1187
     7
nipkow@15131
     8
theory Inductive 
avigad@17009
     9
imports FixedPoint Sum_Type Relation Record
haftmann@16417
    10
uses
wenzelm@10402
    11
  ("Tools/inductive_package.ML")
berghofe@21018
    12
  ("Tools/old_inductive_package.ML")
berghofe@13705
    13
  ("Tools/inductive_realizer.ML")
berghofe@12437
    14
  ("Tools/inductive_codegen.ML")
wenzelm@10402
    15
  ("Tools/datatype_aux.ML")
wenzelm@10402
    16
  ("Tools/datatype_prop.ML")
wenzelm@10402
    17
  ("Tools/datatype_rep_proofs.ML")
wenzelm@10402
    18
  ("Tools/datatype_abs_proofs.ML")
berghofe@13469
    19
  ("Tools/datatype_realizer.ML")
haftmann@19599
    20
  ("Tools/datatype_hooks.ML")
berghofe@22783
    21
  ("Tools/datatype_case.ML")
wenzelm@10402
    22
  ("Tools/datatype_package.ML")
berghofe@12437
    23
  ("Tools/datatype_codegen.ML")
berghofe@12437
    24
  ("Tools/recfun_codegen.ML")
nipkow@15131
    25
  ("Tools/primrec_package.ML")
nipkow@15131
    26
begin
wenzelm@10727
    27
wenzelm@11688
    28
subsection {* Inductive sets *}
wenzelm@11688
    29
wenzelm@11688
    30
text {* Inversion of injective functions. *}
wenzelm@11436
    31
wenzelm@11436
    32
constdefs
wenzelm@11436
    33
  myinv :: "('a => 'b) => ('b => 'a)"
wenzelm@11436
    34
  "myinv (f :: 'a => 'b) == \<lambda>y. THE x. f x = y"
wenzelm@11436
    35
wenzelm@11436
    36
lemma myinv_f_f: "inj f ==> myinv f (f x) = x"
wenzelm@11436
    37
proof -
wenzelm@11436
    38
  assume "inj f"
wenzelm@11436
    39
  hence "(THE x'. f x' = f x) = (THE x'. x' = x)"
wenzelm@11436
    40
    by (simp only: inj_eq)
wenzelm@11436
    41
  also have "... = x" by (rule the_eq_trivial)
wenzelm@11439
    42
  finally show ?thesis by (unfold myinv_def)
wenzelm@11436
    43
qed
wenzelm@11436
    44
wenzelm@11436
    45
lemma f_myinv_f: "inj f ==> y \<in> range f ==> f (myinv f y) = y"
wenzelm@11436
    46
proof (unfold myinv_def)
wenzelm@11436
    47
  assume inj: "inj f"
wenzelm@11436
    48
  assume "y \<in> range f"
wenzelm@11436
    49
  then obtain x where "y = f x" ..
wenzelm@11436
    50
  hence x: "f x = y" ..
wenzelm@11436
    51
  thus "f (THE x. f x = y) = y"
wenzelm@11436
    52
  proof (rule theI)
wenzelm@11436
    53
    fix x' assume "f x' = y"
wenzelm@11436
    54
    with x have "f x' = f x" by simp
wenzelm@11436
    55
    with inj show "x' = x" by (rule injD)
wenzelm@11436
    56
  qed
wenzelm@11436
    57
qed
wenzelm@11436
    58
wenzelm@11436
    59
hide const myinv
wenzelm@11436
    60
wenzelm@11436
    61
wenzelm@11688
    62
text {* Package setup. *}
wenzelm@10402
    63
berghofe@21018
    64
use "Tools/old_inductive_package.ML"
berghofe@21018
    65
setup OldInductivePackage.setup
wenzelm@10402
    66
wenzelm@11688
    67
theorems basic_monos [mono] =
haftmann@22218
    68
  subset_refl imp_refl disj_mono conj_mono ex_mono all_mono if_bool_eq_conj
wenzelm@11688
    69
  Collect_mono in_mono vimage_mono
wenzelm@11688
    70
  imp_conv_disj not_not de_Morgan_disj de_Morgan_conj
wenzelm@11688
    71
  not_all not_ex
wenzelm@11688
    72
  Ball_def Bex_def
wenzelm@18456
    73
  induct_rulify_fallback
wenzelm@11688
    74
berghofe@21018
    75
use "Tools/inductive_package.ML"
berghofe@21018
    76
setup InductivePackage.setup
berghofe@21018
    77
berghofe@21018
    78
theorems [mono2] =
haftmann@22218
    79
  imp_refl disj_mono conj_mono ex_mono all_mono if_bool_eq_conj
berghofe@21018
    80
  imp_conv_disj not_not de_Morgan_disj de_Morgan_conj
berghofe@21018
    81
  not_all not_ex
berghofe@21018
    82
  Ball_def Bex_def
berghofe@21018
    83
  induct_rulify_fallback
berghofe@21018
    84
haftmann@20604
    85
lemma False_meta_all:
haftmann@20604
    86
  "Trueprop False \<equiv> (\<And>P\<Colon>bool. P)"
haftmann@20604
    87
proof
haftmann@20604
    88
  fix P
haftmann@20604
    89
  assume False
haftmann@20604
    90
  then show P ..
haftmann@20604
    91
next
haftmann@20604
    92
  assume "\<And>P\<Colon>bool. P"
haftmann@20604
    93
  then show "False" ..
haftmann@20604
    94
qed
haftmann@20604
    95
haftmann@20604
    96
lemma not_eq_False:
haftmann@20604
    97
  assumes not_eq: "x \<noteq> y"
haftmann@20604
    98
  and eq: "x == y"
haftmann@20604
    99
  shows False
haftmann@20604
   100
  using not_eq eq by auto
haftmann@20604
   101
haftmann@20604
   102
lemmas not_eq_quodlibet =
haftmann@20604
   103
  not_eq_False [simplified False_meta_all]
haftmann@20604
   104
wenzelm@11688
   105
wenzelm@12023
   106
subsection {* Inductive datatypes and primitive recursion *}
wenzelm@11688
   107
wenzelm@11825
   108
text {* Package setup. *}
wenzelm@11825
   109
berghofe@12437
   110
use "Tools/recfun_codegen.ML"
berghofe@12437
   111
setup RecfunCodegen.setup
berghofe@12437
   112
wenzelm@10402
   113
use "Tools/datatype_aux.ML"
wenzelm@10402
   114
use "Tools/datatype_prop.ML"
wenzelm@10402
   115
use "Tools/datatype_rep_proofs.ML"
wenzelm@10402
   116
use "Tools/datatype_abs_proofs.ML"
berghofe@22783
   117
use "Tools/datatype_case.ML"
berghofe@13469
   118
use "Tools/datatype_realizer.ML"
haftmann@19599
   119
haftmann@19599
   120
use "Tools/datatype_hooks.ML"
haftmann@19599
   121
setup DatatypeHooks.setup
haftmann@19599
   122
wenzelm@10402
   123
use "Tools/datatype_package.ML"
wenzelm@7700
   124
setup DatatypePackage.setup
wenzelm@10402
   125
berghofe@12437
   126
use "Tools/datatype_codegen.ML"
berghofe@12437
   127
setup DatatypeCodegen.setup
berghofe@12437
   128
berghofe@13705
   129
use "Tools/inductive_realizer.ML"
berghofe@13705
   130
setup InductiveRealizer.setup
berghofe@13705
   131
berghofe@12437
   132
use "Tools/inductive_codegen.ML"
berghofe@12437
   133
setup InductiveCodegen.setup
berghofe@12437
   134
wenzelm@10402
   135
use "Tools/primrec_package.ML"
wenzelm@7700
   136
wenzelm@6437
   137
end