src/HOL/FunDef.thy
author krauss
Thu Sep 21 12:22:05 2006 +0200 (2006-09-21)
changeset 20654 d80502f0d701
parent 20536 f088edff8af8
child 21051 c49467a9c1e1
permissions -rw-r--r--
1. Function package accepts a parameter (default "some_term"), which specifies the functions
behaviour outside its domain.
2. Bugfix: An exception occured when a function in a mutual definition
was declared but no equation was given.
     1 (*  Title:      HOL/FunDef.thy
     2     ID:         $Id$
     3     Author:     Alexander Krauss, TU Muenchen
     4 
     5 A package for general recursive function definitions. 
     6 *)
     7 
     8 theory FunDef
     9 imports Accessible_Part Datatype Recdef
    10 uses 
    11 ("Tools/function_package/sum_tools.ML")
    12 ("Tools/function_package/fundef_common.ML")
    13 ("Tools/function_package/fundef_lib.ML")
    14 ("Tools/function_package/inductive_wrap.ML")
    15 ("Tools/function_package/context_tree.ML")
    16 ("Tools/function_package/fundef_prep.ML")
    17 ("Tools/function_package/fundef_proof.ML")
    18 ("Tools/function_package/termination.ML")
    19 ("Tools/function_package/mutual.ML")
    20 ("Tools/function_package/pattern_split.ML")
    21 ("Tools/function_package/fundef_package.ML")
    22 ("Tools/function_package/fundef_datatype.ML")
    23 ("Tools/function_package/auto_term.ML")
    24 begin
    25 
    26 
    27 definition
    28   THE_default :: "'a \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a"
    29   "THE_default d P = (if (\<exists>!x. P x) then (THE x. P x) else d)"
    30 
    31 lemma THE_defaultI': "\<exists>!x. P x \<Longrightarrow> P (THE_default d P)"
    32   by (simp add:theI' THE_default_def)
    33 
    34 lemma THE_default1_equality: 
    35   "\<lbrakk>\<exists>!x. P x; P a\<rbrakk> \<Longrightarrow> THE_default d P = a"
    36   by (simp add:the1_equality THE_default_def)
    37 
    38 lemma THE_default_none:
    39   "\<not>(\<exists>!x. P x) \<Longrightarrow> THE_default d P = d"
    40 by (simp add:THE_default_def)
    41 
    42 
    43 lemma fundef_ex1_existence:
    44 assumes f_def: "f \<equiv> \<lambda>x. THE_default (d x) (\<lambda>y. (x,y)\<in>G)"
    45 assumes ex1: "\<exists>!y. (x,y)\<in>G"
    46 shows "(x, f x)\<in>G"
    47   by (simp only:f_def, rule THE_defaultI', rule ex1)
    48 
    49 lemma fundef_ex1_uniqueness:
    50 assumes f_def: "f \<equiv> \<lambda>x. THE_default (d x) (\<lambda>y. (x,y)\<in>G)"
    51 assumes ex1: "\<exists>!y. (x,y)\<in>G"
    52 assumes elm: "(x, h x)\<in>G"
    53 shows "h x = f x"
    54   by (simp only:f_def, rule THE_default1_equality[symmetric], rule ex1, rule elm)
    55 
    56 lemma fundef_ex1_iff:
    57 assumes f_def: "f \<equiv> \<lambda>x. THE_default (d x) (\<lambda>y. (x,y)\<in>G)"
    58 assumes ex1: "\<exists>!y. (x,y)\<in>G"
    59 shows "((x, y)\<in>G) = (f x = y)"
    60   apply (auto simp:ex1 f_def THE_default1_equality)
    61   by (rule THE_defaultI', rule ex1)
    62 
    63 lemma fundef_default_value:
    64 assumes f_def: "f \<equiv> \<lambda>x. THE_default (d x) (\<lambda>y. (x,y)\<in>G)"
    65 assumes graph: "\<And>x y. (x,y) \<in> G \<Longrightarrow> x \<in> D"
    66 assumes "x \<notin> D"
    67 shows "f x = d x"
    68 proof -
    69   have "\<not>(\<exists>y. (x, y) \<in> G)"
    70   proof
    71     assume "(\<exists>y. (x, y) \<in> G)"
    72     with graph and `x\<notin>D` show False by blast
    73   qed
    74   hence "\<not>(\<exists>!y. (x, y) \<in> G)" by blast
    75   
    76   thus ?thesis
    77     unfolding f_def
    78     by (rule THE_default_none)
    79 qed
    80 
    81 
    82 
    83 
    84 subsection {* Projections *}
    85 consts
    86   lpg::"(('a + 'b) * 'a) set"
    87   rpg::"(('a + 'b) * 'b) set"
    88 
    89 inductive lpg
    90 intros
    91   "(Inl x, x) : lpg"
    92 inductive rpg
    93 intros
    94   "(Inr y, y) : rpg"
    95 definition
    96   "lproj x = (THE y. (x,y) : lpg)"
    97   "rproj x = (THE y. (x,y) : rpg)"
    98 
    99 lemma lproj_inl:
   100   "lproj (Inl x) = x"
   101   by (auto simp:lproj_def intro: the_equality lpg.intros elim: lpg.cases)
   102 lemma rproj_inr:
   103   "rproj (Inr x) = x"
   104   by (auto simp:rproj_def intro: the_equality rpg.intros elim: rpg.cases)
   105 
   106 
   107 
   108 
   109 use "Tools/function_package/sum_tools.ML"
   110 use "Tools/function_package/fundef_common.ML"
   111 use "Tools/function_package/fundef_lib.ML"
   112 use "Tools/function_package/inductive_wrap.ML"
   113 use "Tools/function_package/context_tree.ML"
   114 use "Tools/function_package/fundef_prep.ML"
   115 use "Tools/function_package/fundef_proof.ML"
   116 use "Tools/function_package/termination.ML"
   117 use "Tools/function_package/mutual.ML"
   118 use "Tools/function_package/pattern_split.ML"
   119 use "Tools/function_package/fundef_package.ML"
   120 
   121 setup FundefPackage.setup
   122 
   123 use "Tools/function_package/fundef_datatype.ML"
   124 setup FundefDatatype.setup
   125 
   126 use "Tools/function_package/auto_term.ML"
   127 setup FundefAutoTerm.setup
   128 
   129 
   130 lemmas [fundef_cong] = 
   131   let_cong if_cong image_cong INT_cong UN_cong bex_cong ball_cong imp_cong
   132 
   133 
   134 lemma split_cong[fundef_cong]:
   135   "\<lbrakk> \<And>x y. (x, y) = q \<Longrightarrow> f x y = g x y; p = q \<rbrakk> 
   136   \<Longrightarrow> split f p = split g q"
   137   by (auto simp:split_def)
   138 
   139 
   140 end