src/HOL/FunDef.thy
author wenzelm
Fri Mar 28 19:43:54 2008 +0100 (2008-03-28)
changeset 26462 dac4e2bce00d
parent 25567 5720345ea689
child 26748 4d51ddd6aa5c
permissions -rw-r--r--
avoid rebinding of existing facts;
     1 (*  Title:      HOL/FunDef.thy
     2     ID:         $Id$
     3     Author:     Alexander Krauss, TU Muenchen
     4 *)
     5 
     6 header {* General recursive function definitions *}
     7 
     8 theory FunDef
     9 imports Accessible_Part
    10 uses
    11   ("Tools/function_package/fundef_lib.ML")
    12   ("Tools/function_package/fundef_common.ML")
    13   ("Tools/function_package/inductive_wrap.ML")
    14   ("Tools/function_package/context_tree.ML")
    15   ("Tools/function_package/fundef_core.ML")
    16   ("Tools/function_package/sum_tree.ML")
    17   ("Tools/function_package/mutual.ML")
    18   ("Tools/function_package/pattern_split.ML")
    19   ("Tools/function_package/fundef_package.ML")
    20   ("Tools/function_package/auto_term.ML")
    21   ("Tools/function_package/induction_scheme.ML")
    22 begin
    23 
    24 text {* Definitions with default value. *}
    25 
    26 definition
    27   THE_default :: "'a \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a" where
    28   "THE_default d P = (if (\<exists>!x. P x) then (THE x. P x) else d)"
    29 
    30 lemma THE_defaultI': "\<exists>!x. P x \<Longrightarrow> P (THE_default d P)"
    31   by (simp add: theI' THE_default_def)
    32 
    33 lemma THE_default1_equality:
    34     "\<lbrakk>\<exists>!x. P x; P a\<rbrakk> \<Longrightarrow> THE_default d P = a"
    35   by (simp add: the1_equality THE_default_def)
    36 
    37 lemma THE_default_none:
    38     "\<not>(\<exists>!x. P x) \<Longrightarrow> THE_default d P = d"
    39   by (simp add:THE_default_def)
    40 
    41 
    42 lemma fundef_ex1_existence:
    43   assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
    44   assumes ex1: "\<exists>!y. G x y"
    45   shows "G x (f x)"
    46   apply (simp only: f_def)
    47   apply (rule THE_defaultI')
    48   apply (rule ex1)
    49   done
    50 
    51 lemma fundef_ex1_uniqueness:
    52   assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
    53   assumes ex1: "\<exists>!y. G x y"
    54   assumes elm: "G x (h x)"
    55   shows "h x = f x"
    56   apply (simp only: f_def)
    57   apply (rule THE_default1_equality [symmetric])
    58    apply (rule ex1)
    59   apply (rule elm)
    60   done
    61 
    62 lemma fundef_ex1_iff:
    63   assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
    64   assumes ex1: "\<exists>!y. G x y"
    65   shows "(G x y) = (f x = y)"
    66   apply (auto simp:ex1 f_def THE_default1_equality)
    67   apply (rule THE_defaultI')
    68   apply (rule ex1)
    69   done
    70 
    71 lemma fundef_default_value:
    72   assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
    73   assumes graph: "\<And>x y. G x y \<Longrightarrow> D x"
    74   assumes "\<not> D x"
    75   shows "f x = d x"
    76 proof -
    77   have "\<not>(\<exists>y. G x y)"
    78   proof
    79     assume "\<exists>y. G x y"
    80     hence "D x" using graph ..
    81     with `\<not> D x` show False ..
    82   qed
    83   hence "\<not>(\<exists>!y. G x y)" by blast
    84 
    85   thus ?thesis
    86     unfolding f_def
    87     by (rule THE_default_none)
    88 qed
    89 
    90 definition in_rel_def[simp]:
    91   "in_rel R x y == (x, y) \<in> R"
    92 
    93 lemma wf_in_rel:
    94   "wf R \<Longrightarrow> wfP (in_rel R)"
    95   by (simp add: wfP_def)
    96 
    97 
    98 use "Tools/function_package/fundef_lib.ML"
    99 use "Tools/function_package/fundef_common.ML"
   100 use "Tools/function_package/inductive_wrap.ML"
   101 use "Tools/function_package/context_tree.ML"
   102 use "Tools/function_package/fundef_core.ML"
   103 use "Tools/function_package/sum_tree.ML"
   104 use "Tools/function_package/mutual.ML"
   105 use "Tools/function_package/pattern_split.ML"
   106 use "Tools/function_package/auto_term.ML"
   107 use "Tools/function_package/fundef_package.ML"
   108 use "Tools/function_package/induction_scheme.ML"
   109 
   110 setup {* 
   111   FundefPackage.setup 
   112   #> InductionScheme.setup
   113 *}
   114 
   115 lemma let_cong [fundef_cong]:
   116   "M = N \<Longrightarrow> (\<And>x. x = N \<Longrightarrow> f x = g x) \<Longrightarrow> Let M f = Let N g"
   117   unfolding Let_def by blast
   118 
   119 lemmas [fundef_cong] =
   120   if_cong image_cong INT_cong UN_cong
   121   bex_cong ball_cong imp_cong
   122 
   123 lemma split_cong [fundef_cong]:
   124   "(\<And>x y. (x, y) = q \<Longrightarrow> f x y = g x y) \<Longrightarrow> p = q
   125     \<Longrightarrow> split f p = split g q"
   126   by (auto simp: split_def)
   127 
   128 lemma comp_cong [fundef_cong]:
   129   "f (g x) = f' (g' x') \<Longrightarrow> (f o g) x = (f' o g') x'"
   130   unfolding o_apply .
   131 
   132 end