src/HOL/FunDef.thy
author wenzelm
Thu Apr 26 16:39:10 2007 +0200 (2007-04-26)
changeset 22816 0eba117368d9
parent 22622 25693088396b
child 22838 466599ecf610
permissions -rw-r--r--
added header;
tuned presentation;
wenzelm@20324
     1
(*  Title:      HOL/FunDef.thy
wenzelm@20324
     2
    ID:         $Id$
wenzelm@20324
     3
    Author:     Alexander Krauss, TU Muenchen
wenzelm@22816
     4
*)
wenzelm@20324
     5
wenzelm@22816
     6
header {* General recursive function definitions *}
wenzelm@20324
     7
krauss@19564
     8
theory FunDef
wenzelm@22816
     9
imports Accessible_Part
wenzelm@22816
    10
uses
wenzelm@22816
    11
  ("Tools/function_package/sum_tools.ML")
wenzelm@22816
    12
  ("Tools/function_package/fundef_common.ML")
wenzelm@22816
    13
  ("Tools/function_package/fundef_lib.ML")
wenzelm@22816
    14
  ("Tools/function_package/inductive_wrap.ML")
wenzelm@22816
    15
  ("Tools/function_package/context_tree.ML")
wenzelm@22816
    16
  ("Tools/function_package/fundef_core.ML")
wenzelm@22816
    17
  ("Tools/function_package/mutual.ML")
wenzelm@22816
    18
  ("Tools/function_package/pattern_split.ML")
wenzelm@22816
    19
  ("Tools/function_package/fundef_package.ML")
wenzelm@22816
    20
  ("Tools/function_package/auto_term.ML")
krauss@19564
    21
begin
krauss@19564
    22
wenzelm@22816
    23
text {* Definitions with default value. *}
krauss@20536
    24
krauss@20536
    25
definition
wenzelm@21404
    26
  THE_default :: "'a \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a" where
krauss@20536
    27
  "THE_default d P = (if (\<exists>!x. P x) then (THE x. P x) else d)"
krauss@20536
    28
krauss@20536
    29
lemma THE_defaultI': "\<exists>!x. P x \<Longrightarrow> P (THE_default d P)"
wenzelm@22816
    30
  by (simp add: theI' THE_default_def)
krauss@20536
    31
wenzelm@22816
    32
lemma THE_default1_equality:
wenzelm@22816
    33
    "\<lbrakk>\<exists>!x. P x; P a\<rbrakk> \<Longrightarrow> THE_default d P = a"
wenzelm@22816
    34
  by (simp add: the1_equality THE_default_def)
krauss@20536
    35
krauss@20536
    36
lemma THE_default_none:
wenzelm@22816
    37
    "\<not>(\<exists>!x. P x) \<Longrightarrow> THE_default d P = d"
wenzelm@22816
    38
  by (simp add:THE_default_def)
krauss@20536
    39
krauss@20536
    40
krauss@19564
    41
lemma fundef_ex1_existence:
wenzelm@22816
    42
  assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
wenzelm@22816
    43
  assumes ex1: "\<exists>!y. G x y"
wenzelm@22816
    44
  shows "G x (f x)"
wenzelm@22816
    45
  apply (simp only: f_def)
wenzelm@22816
    46
  apply (rule THE_defaultI')
wenzelm@22816
    47
  apply (rule ex1)
wenzelm@22816
    48
  done
krauss@21051
    49
krauss@19564
    50
lemma fundef_ex1_uniqueness:
wenzelm@22816
    51
  assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
wenzelm@22816
    52
  assumes ex1: "\<exists>!y. G x y"
wenzelm@22816
    53
  assumes elm: "G x (h x)"
wenzelm@22816
    54
  shows "h x = f x"
wenzelm@22816
    55
  apply (simp only: f_def)
wenzelm@22816
    56
  apply (rule THE_default1_equality [symmetric])
wenzelm@22816
    57
   apply (rule ex1)
wenzelm@22816
    58
  apply (rule elm)
wenzelm@22816
    59
  done
krauss@19564
    60
krauss@19564
    61
lemma fundef_ex1_iff:
wenzelm@22816
    62
  assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
wenzelm@22816
    63
  assumes ex1: "\<exists>!y. G x y"
wenzelm@22816
    64
  shows "(G x y) = (f x = y)"
krauss@20536
    65
  apply (auto simp:ex1 f_def THE_default1_equality)
wenzelm@22816
    66
  apply (rule THE_defaultI')
wenzelm@22816
    67
  apply (rule ex1)
wenzelm@22816
    68
  done
krauss@19564
    69
krauss@20654
    70
lemma fundef_default_value:
wenzelm@22816
    71
  assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
wenzelm@22816
    72
  assumes graph: "\<And>x y. G x y \<Longrightarrow> D x"
wenzelm@22816
    73
  assumes "\<not> D x"
wenzelm@22816
    74
  shows "f x = d x"
krauss@20654
    75
proof -
krauss@21051
    76
  have "\<not>(\<exists>y. G x y)"
krauss@20654
    77
  proof
krauss@21512
    78
    assume "\<exists>y. G x y"
krauss@21512
    79
    hence "D x" using graph ..
krauss@21512
    80
    with `\<not> D x` show False ..
krauss@20654
    81
  qed
krauss@21051
    82
  hence "\<not>(\<exists>!y. G x y)" by blast
wenzelm@22816
    83
krauss@20654
    84
  thus ?thesis
krauss@20654
    85
    unfolding f_def
krauss@20654
    86
    by (rule THE_default_none)
krauss@20654
    87
qed
krauss@20654
    88
krauss@20654
    89
krauss@19770
    90
use "Tools/function_package/sum_tools.ML"
krauss@19564
    91
use "Tools/function_package/fundef_common.ML"
krauss@19564
    92
use "Tools/function_package/fundef_lib.ML"
krauss@20523
    93
use "Tools/function_package/inductive_wrap.ML"
krauss@19564
    94
use "Tools/function_package/context_tree.ML"
krauss@22166
    95
use "Tools/function_package/fundef_core.ML"
krauss@19770
    96
use "Tools/function_package/mutual.ML"
krauss@20270
    97
use "Tools/function_package/pattern_split.ML"
krauss@21319
    98
use "Tools/function_package/auto_term.ML"
krauss@19564
    99
use "Tools/function_package/fundef_package.ML"
krauss@19564
   100
krauss@19564
   101
setup FundefPackage.setup
krauss@19770
   102
krauss@22622
   103
lemma let_cong:
krauss@22622
   104
    "M = N ==> (!!x. x = N ==> f x = g x) ==> Let M f = Let N g"
wenzelm@22816
   105
  unfolding Let_def by blast
krauss@22622
   106
wenzelm@22816
   107
lemmas [fundef_cong] =
krauss@19770
   108
  let_cong if_cong image_cong INT_cong UN_cong bex_cong ball_cong imp_cong
krauss@19564
   109
krauss@19564
   110
wenzelm@22816
   111
lemma split_cong [fundef_cong]:
wenzelm@22816
   112
  "\<lbrakk> \<And>x y. (x, y) = q \<Longrightarrow> f x y = g x y; p = q \<rbrakk>
wenzelm@22816
   113
    \<Longrightarrow> split f p = split g q"
wenzelm@22816
   114
  by (auto simp: split_def)
krauss@19934
   115
wenzelm@22816
   116
lemma comp_cong [fundef_cong]:
krauss@22324
   117
  "f (g x) = f' (g' x')
wenzelm@22816
   118
    ==>  (f o g) x = (f' o g') x'"
wenzelm@22816
   119
  unfolding o_apply .
krauss@19934
   120
krauss@19564
   121
end