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
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 
haftmann@23708
     9
imports FixedPoint Product_Type Sum_Type
haftmann@16417
    10
uses
wenzelm@10402
    11
  ("Tools/inductive_package.ML")
berghofe@23734
    12
  ("Tools/inductive_set_package.ML")
berghofe@13705
    13
  ("Tools/inductive_realizer.ML")
haftmann@24625
    14
  "Tools/dseq.ML"
berghofe@12437
    15
  ("Tools/inductive_codegen.ML")
wenzelm@10402
    16
  ("Tools/datatype_aux.ML")
wenzelm@10402
    17
  ("Tools/datatype_prop.ML")
wenzelm@10402
    18
  ("Tools/datatype_rep_proofs.ML")
wenzelm@10402
    19
  ("Tools/datatype_abs_proofs.ML")
berghofe@13469
    20
  ("Tools/datatype_realizer.ML")
haftmann@19599
    21
  ("Tools/datatype_hooks.ML")
berghofe@22783
    22
  ("Tools/datatype_case.ML")
wenzelm@10402
    23
  ("Tools/datatype_package.ML")
berghofe@12437
    24
  ("Tools/datatype_codegen.ML")
nipkow@15131
    25
  ("Tools/primrec_package.ML")
nipkow@15131
    26
begin
wenzelm@10727
    27
berghofe@23734
    28
subsection {* Inductive predicates and 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@23734
    64
theorems basic_monos =
haftmann@22218
    65
  subset_refl imp_refl disj_mono conj_mono ex_mono all_mono if_bool_eq_conj
wenzelm@11688
    66
  Collect_mono in_mono vimage_mono
wenzelm@11688
    67
  imp_conv_disj not_not de_Morgan_disj de_Morgan_conj
wenzelm@11688
    68
  not_all not_ex
wenzelm@11688
    69
  Ball_def Bex_def
wenzelm@18456
    70
  induct_rulify_fallback
wenzelm@11688
    71
berghofe@21018
    72
use "Tools/inductive_package.ML"
berghofe@21018
    73
setup InductivePackage.setup
berghofe@21018
    74
berghofe@23734
    75
theorems [mono] =
haftmann@22218
    76
  imp_refl disj_mono conj_mono ex_mono all_mono if_bool_eq_conj
berghofe@21018
    77
  imp_conv_disj not_not de_Morgan_disj de_Morgan_conj
berghofe@21018
    78
  not_all not_ex
berghofe@21018
    79
  Ball_def Bex_def
berghofe@21018
    80
  induct_rulify_fallback
berghofe@21018
    81
haftmann@20604
    82
lemma False_meta_all:
haftmann@20604
    83
  "Trueprop False \<equiv> (\<And>P\<Colon>bool. P)"
haftmann@20604
    84
proof
haftmann@20604
    85
  fix P
haftmann@20604
    86
  assume False
haftmann@20604
    87
  then show P ..
haftmann@20604
    88
next
haftmann@20604
    89
  assume "\<And>P\<Colon>bool. P"
wenzelm@23389
    90
  then show False .
haftmann@20604
    91
qed
haftmann@20604
    92
haftmann@20604
    93
lemma not_eq_False:
haftmann@20604
    94
  assumes not_eq: "x \<noteq> y"
haftmann@22886
    95
  and eq: "x \<equiv> y"
haftmann@20604
    96
  shows False
haftmann@20604
    97
  using not_eq eq by auto
haftmann@20604
    98
haftmann@20604
    99
lemmas not_eq_quodlibet =
haftmann@20604
   100
  not_eq_False [simplified False_meta_all]
haftmann@20604
   101
wenzelm@11688
   102
wenzelm@12023
   103
subsection {* Inductive datatypes and primitive recursion *}
wenzelm@11688
   104
wenzelm@11825
   105
text {* Package setup. *}
wenzelm@11825
   106
wenzelm@10402
   107
use "Tools/datatype_aux.ML"
wenzelm@10402
   108
use "Tools/datatype_prop.ML"
wenzelm@10402
   109
use "Tools/datatype_rep_proofs.ML"
wenzelm@10402
   110
use "Tools/datatype_abs_proofs.ML"
berghofe@22783
   111
use "Tools/datatype_case.ML"
berghofe@13469
   112
use "Tools/datatype_realizer.ML"
haftmann@19599
   113
haftmann@19599
   114
use "Tools/datatype_hooks.ML"
haftmann@19599
   115
wenzelm@10402
   116
use "Tools/datatype_package.ML"
wenzelm@7700
   117
setup DatatypePackage.setup
wenzelm@10402
   118
berghofe@12437
   119
use "Tools/datatype_codegen.ML"
berghofe@12437
   120
setup DatatypeCodegen.setup
berghofe@12437
   121
berghofe@13705
   122
use "Tools/inductive_realizer.ML"
berghofe@13705
   123
setup InductiveRealizer.setup
berghofe@13705
   124
berghofe@12437
   125
use "Tools/inductive_codegen.ML"
berghofe@12437
   126
setup InductiveCodegen.setup
berghofe@12437
   127
wenzelm@10402
   128
use "Tools/primrec_package.ML"
wenzelm@7700
   129
berghofe@23734
   130
use "Tools/inductive_set_package.ML"
berghofe@23734
   131
setup InductiveSetPackage.setup
berghofe@23734
   132
nipkow@23526
   133
text{* Lambda-abstractions with pattern matching: *}
nipkow@23526
   134
nipkow@23526
   135
syntax
nipkow@23529
   136
  "_lam_pats_syntax" :: "cases_syn => 'a => 'b"               ("(%_)" 10)
nipkow@23526
   137
syntax (xsymbols)
nipkow@23529
   138
  "_lam_pats_syntax" :: "cases_syn => 'a => 'b"               ("(\<lambda>_)" 10)
nipkow@23526
   139
nipkow@23529
   140
parse_translation (advanced) {*
nipkow@23529
   141
let
nipkow@23529
   142
  fun fun_tr ctxt [cs] =
nipkow@23529
   143
    let
nipkow@23529
   144
      val x = Free (Name.variant (add_term_free_names (cs, [])) "x", dummyT);
nipkow@24349
   145
      val ft = DatatypeCase.case_tr true DatatypePackage.datatype_of_constr
nipkow@24349
   146
                 ctxt [x, cs]
nipkow@23529
   147
    in lambda x ft end
nipkow@23529
   148
in [("_lam_pats_syntax", fun_tr)] end
nipkow@23526
   149
*}
nipkow@23526
   150
nipkow@23526
   151
end