src/HOL/FunDef.thy
author urbanc
Tue Jun 05 09:56:19 2007 +0200 (2007-06-05)
changeset 23243 a37d3e6e8323
parent 23203 a5026e73cfcf
child 23494 f985f9239e0d
permissions -rw-r--r--
included Class.thy in the compiling process for Nominal/Examples
     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 Datatype Accessible_Part
    10 uses
    11   ("Tools/function_package/sum_tools.ML")
    12   ("Tools/function_package/fundef_lib.ML")
    13   ("Tools/function_package/fundef_common.ML")
    14   ("Tools/function_package/inductive_wrap.ML")
    15   ("Tools/function_package/context_tree.ML")
    16   ("Tools/function_package/fundef_core.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 begin
    22 
    23 text {* Definitions with default value. *}
    24 
    25 definition
    26   THE_default :: "'a \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a" where
    27   "THE_default d P = (if (\<exists>!x. P x) then (THE x. P x) else d)"
    28 
    29 lemma THE_defaultI': "\<exists>!x. P x \<Longrightarrow> P (THE_default d P)"
    30   by (simp add: theI' THE_default_def)
    31 
    32 lemma THE_default1_equality:
    33     "\<lbrakk>\<exists>!x. P x; P a\<rbrakk> \<Longrightarrow> THE_default d P = a"
    34   by (simp add: the1_equality THE_default_def)
    35 
    36 lemma THE_default_none:
    37     "\<not>(\<exists>!x. P x) \<Longrightarrow> THE_default d P = d"
    38   by (simp add:THE_default_def)
    39 
    40 
    41 lemma fundef_ex1_existence:
    42   assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
    43   assumes ex1: "\<exists>!y. G x y"
    44   shows "G x (f x)"
    45   apply (simp only: f_def)
    46   apply (rule THE_defaultI')
    47   apply (rule ex1)
    48   done
    49 
    50 lemma fundef_ex1_uniqueness:
    51   assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
    52   assumes ex1: "\<exists>!y. G x y"
    53   assumes elm: "G x (h x)"
    54   shows "h x = f x"
    55   apply (simp only: f_def)
    56   apply (rule THE_default1_equality [symmetric])
    57    apply (rule ex1)
    58   apply (rule elm)
    59   done
    60 
    61 lemma fundef_ex1_iff:
    62   assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
    63   assumes ex1: "\<exists>!y. G x y"
    64   shows "(G x y) = (f x = y)"
    65   apply (auto simp:ex1 f_def THE_default1_equality)
    66   apply (rule THE_defaultI')
    67   apply (rule ex1)
    68   done
    69 
    70 lemma fundef_default_value:
    71   assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
    72   assumes graph: "\<And>x y. G x y \<Longrightarrow> D x"
    73   assumes "\<not> D x"
    74   shows "f x = d x"
    75 proof -
    76   have "\<not>(\<exists>y. G x y)"
    77   proof
    78     assume "\<exists>y. G x y"
    79     hence "D x" using graph ..
    80     with `\<not> D x` show False ..
    81   qed
    82   hence "\<not>(\<exists>!y. G x y)" by blast
    83 
    84   thus ?thesis
    85     unfolding f_def
    86     by (rule THE_default_none)
    87 qed
    88 
    89 
    90 use "Tools/function_package/sum_tools.ML"
    91 use "Tools/function_package/fundef_lib.ML"
    92 use "Tools/function_package/fundef_common.ML"
    93 use "Tools/function_package/inductive_wrap.ML"
    94 use "Tools/function_package/context_tree.ML"
    95 use "Tools/function_package/fundef_core.ML"
    96 use "Tools/function_package/mutual.ML"
    97 use "Tools/function_package/pattern_split.ML"
    98 use "Tools/function_package/auto_term.ML"
    99 use "Tools/function_package/fundef_package.ML"
   100 
   101 setup FundefPackage.setup
   102 
   103 lemma let_cong [fundef_cong]:
   104   "M = N \<Longrightarrow> (\<And>x. x = N \<Longrightarrow> f x = g x) \<Longrightarrow> Let M f = Let N g"
   105   unfolding Let_def by blast
   106 
   107 lemmas [fundef_cong] =
   108   if_cong image_cong INT_cong UN_cong
   109   bex_cong ball_cong imp_cong
   110 
   111 lemma split_cong [fundef_cong]:
   112   "(\<And>x y. (x, y) = q \<Longrightarrow> f x y = g x y) \<Longrightarrow> p = q
   113     \<Longrightarrow> split f p = split g q"
   114   by (auto simp: split_def)
   115 
   116 lemma comp_cong [fundef_cong]:
   117   "f (g x) = f' (g' x') \<Longrightarrow> (f o g) x = (f' o g') x'"
   118   unfolding o_apply .
   119 
   120 end