src/HOL/FunDef.thy
author krauss
Thu Sep 14 15:27:08 2006 +0200 (2006-09-14)
changeset 20536 f088edff8af8
parent 20523 36a59e5d0039
child 20654 d80502f0d701
permissions -rw-r--r--
Function package: Outside their domain functions now return "arbitrary".
wenzelm@20324
     1
(*  Title:      HOL/FunDef.thy
wenzelm@20324
     2
    ID:         $Id$
wenzelm@20324
     3
    Author:     Alexander Krauss, TU Muenchen
wenzelm@20324
     4
wenzelm@20324
     5
A package for general recursive function definitions. 
wenzelm@20324
     6
*)
wenzelm@20324
     7
krauss@19564
     8
theory FunDef
krauss@19770
     9
imports Accessible_Part Datatype Recdef
krauss@19564
    10
uses 
krauss@19770
    11
("Tools/function_package/sum_tools.ML")
krauss@19564
    12
("Tools/function_package/fundef_common.ML")
krauss@19564
    13
("Tools/function_package/fundef_lib.ML")
krauss@20523
    14
("Tools/function_package/inductive_wrap.ML")
krauss@19564
    15
("Tools/function_package/context_tree.ML")
krauss@19564
    16
("Tools/function_package/fundef_prep.ML")
krauss@19564
    17
("Tools/function_package/fundef_proof.ML")
krauss@19564
    18
("Tools/function_package/termination.ML")
krauss@19770
    19
("Tools/function_package/mutual.ML")
krauss@20270
    20
("Tools/function_package/pattern_split.ML")
krauss@19564
    21
("Tools/function_package/fundef_package.ML")
krauss@19770
    22
("Tools/function_package/fundef_datatype.ML")
krauss@19770
    23
("Tools/function_package/auto_term.ML")
krauss@19564
    24
begin
krauss@19564
    25
krauss@20536
    26
krauss@20536
    27
definition
krauss@20536
    28
  THE_default :: "'a \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a"
krauss@20536
    29
  "THE_default d P = (if (\<exists>!x. P x) then (THE x. P x) else d)"
krauss@20536
    30
krauss@20536
    31
lemma THE_defaultI': "\<exists>!x. P x \<Longrightarrow> P (THE_default d P)"
krauss@20536
    32
  by (simp add:theI' THE_default_def)
krauss@20536
    33
krauss@20536
    34
lemma THE_default1_equality: 
krauss@20536
    35
  "\<lbrakk>\<exists>!x. P x; P a\<rbrakk> \<Longrightarrow> THE_default d P = a"
krauss@20536
    36
  by (simp add:the1_equality THE_default_def)
krauss@20536
    37
krauss@20536
    38
lemma THE_default_none:
krauss@20536
    39
  "\<not>(\<exists>!x. P x) \<Longrightarrow> THE_default d P = d"
krauss@20536
    40
by (simp add:THE_default_def)
krauss@20536
    41
krauss@20536
    42
krauss@19564
    43
lemma fundef_ex1_existence:
krauss@20536
    44
assumes f_def: "f \<equiv> \<lambda>x. THE_default d (\<lambda>y. (x,y)\<in>G)"
krauss@19564
    45
assumes ex1: "\<exists>!y. (x,y)\<in>G"
krauss@19564
    46
shows "(x, f x)\<in>G"
krauss@20536
    47
  by (simp only:f_def, rule THE_defaultI', rule ex1)
krauss@19564
    48
krauss@19564
    49
lemma fundef_ex1_uniqueness:
krauss@20536
    50
assumes f_def: "f \<equiv> \<lambda>x. THE_default d (\<lambda>y. (x,y)\<in>G)"
krauss@19564
    51
assumes ex1: "\<exists>!y. (x,y)\<in>G"
krauss@19564
    52
assumes elm: "(x, h x)\<in>G"
krauss@19564
    53
shows "h x = f x"
krauss@20536
    54
  by (simp only:f_def, rule THE_default1_equality[symmetric], rule ex1, rule elm)
krauss@19564
    55
krauss@19564
    56
lemma fundef_ex1_iff:
krauss@20536
    57
assumes f_def: "f \<equiv> \<lambda>x. THE_default d (\<lambda>y. (x,y)\<in>G)"
krauss@19564
    58
assumes ex1: "\<exists>!y. (x,y)\<in>G"
krauss@19564
    59
shows "((x, y)\<in>G) = (f x = y)"
krauss@20536
    60
  apply (auto simp:ex1 f_def THE_default1_equality)
krauss@20536
    61
  by (rule THE_defaultI', rule ex1)
krauss@19564
    62
krauss@19564
    63
krauss@19770
    64
subsection {* Projections *}
krauss@19770
    65
consts
krauss@19770
    66
  lpg::"(('a + 'b) * 'a) set"
krauss@19770
    67
  rpg::"(('a + 'b) * 'b) set"
krauss@19770
    68
krauss@19770
    69
inductive lpg
krauss@19770
    70
intros
krauss@19770
    71
  "(Inl x, x) : lpg"
krauss@19770
    72
inductive rpg
krauss@19770
    73
intros
krauss@19770
    74
  "(Inr y, y) : rpg"
krauss@19770
    75
definition
krauss@19770
    76
  "lproj x = (THE y. (x,y) : lpg)"
krauss@19770
    77
  "rproj x = (THE y. (x,y) : rpg)"
krauss@19770
    78
krauss@19770
    79
lemma lproj_inl:
krauss@19770
    80
  "lproj (Inl x) = x"
krauss@19770
    81
  by (auto simp:lproj_def intro: the_equality lpg.intros elim: lpg.cases)
krauss@19770
    82
lemma rproj_inr:
krauss@19770
    83
  "rproj (Inr x) = x"
krauss@19770
    84
  by (auto simp:rproj_def intro: the_equality rpg.intros elim: rpg.cases)
krauss@19770
    85
krauss@19770
    86
krauss@19770
    87
krauss@19770
    88
krauss@19770
    89
use "Tools/function_package/sum_tools.ML"
krauss@19564
    90
use "Tools/function_package/fundef_common.ML"
krauss@19564
    91
use "Tools/function_package/fundef_lib.ML"
krauss@20523
    92
use "Tools/function_package/inductive_wrap.ML"
krauss@19564
    93
use "Tools/function_package/context_tree.ML"
krauss@19564
    94
use "Tools/function_package/fundef_prep.ML"
krauss@19564
    95
use "Tools/function_package/fundef_proof.ML"
krauss@19564
    96
use "Tools/function_package/termination.ML"
krauss@19770
    97
use "Tools/function_package/mutual.ML"
krauss@20270
    98
use "Tools/function_package/pattern_split.ML"
krauss@19564
    99
use "Tools/function_package/fundef_package.ML"
krauss@19564
   100
krauss@19564
   101
setup FundefPackage.setup
krauss@19564
   102
krauss@19770
   103
use "Tools/function_package/fundef_datatype.ML"
krauss@19770
   104
setup FundefDatatype.setup
krauss@19770
   105
krauss@19770
   106
use "Tools/function_package/auto_term.ML"
krauss@19770
   107
setup FundefAutoTerm.setup
krauss@19770
   108
krauss@19770
   109
krauss@19770
   110
lemmas [fundef_cong] = 
krauss@19770
   111
  let_cong if_cong image_cong INT_cong UN_cong bex_cong ball_cong imp_cong
krauss@19564
   112
krauss@19564
   113
krauss@19934
   114
lemma split_cong[fundef_cong]:
krauss@19934
   115
  "\<lbrakk> \<And>x y. (x, y) = q \<Longrightarrow> f x y = g x y; p = q \<rbrakk> 
krauss@19934
   116
  \<Longrightarrow> split f p = split g q"
krauss@19934
   117
  by (auto simp:split_def)
krauss@19934
   118
krauss@19934
   119
krauss@19564
   120
end