src/HOL/FunDef.thy
author berghofe
Wed Jul 11 11:03:11 2007 +0200 (2007-07-11)
changeset 23739 c5ead5df7f35
parent 23494 f985f9239e0d
child 24162 8dfd5dd65d82
permissions -rw-r--r--
Inserted definition of in_rel again (since member2 was removed).
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
haftmann@22919
     9
imports Datatype Accessible_Part
wenzelm@22816
    10
uses
krauss@23203
    11
  ("Tools/function_package/fundef_lib.ML")
wenzelm@22816
    12
  ("Tools/function_package/fundef_common.ML")
wenzelm@22816
    13
  ("Tools/function_package/inductive_wrap.ML")
wenzelm@22816
    14
  ("Tools/function_package/context_tree.ML")
wenzelm@22816
    15
  ("Tools/function_package/fundef_core.ML")
wenzelm@22816
    16
  ("Tools/function_package/mutual.ML")
wenzelm@22816
    17
  ("Tools/function_package/pattern_split.ML")
wenzelm@22816
    18
  ("Tools/function_package/fundef_package.ML")
wenzelm@22816
    19
  ("Tools/function_package/auto_term.ML")
krauss@19564
    20
begin
krauss@19564
    21
wenzelm@22816
    22
text {* Definitions with default value. *}
krauss@20536
    23
krauss@20536
    24
definition
wenzelm@21404
    25
  THE_default :: "'a \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a" where
krauss@20536
    26
  "THE_default d P = (if (\<exists>!x. P x) then (THE x. P x) else d)"
krauss@20536
    27
krauss@20536
    28
lemma THE_defaultI': "\<exists>!x. P x \<Longrightarrow> P (THE_default d P)"
wenzelm@22816
    29
  by (simp add: theI' THE_default_def)
krauss@20536
    30
wenzelm@22816
    31
lemma THE_default1_equality:
wenzelm@22816
    32
    "\<lbrakk>\<exists>!x. P x; P a\<rbrakk> \<Longrightarrow> THE_default d P = a"
wenzelm@22816
    33
  by (simp add: the1_equality THE_default_def)
krauss@20536
    34
krauss@20536
    35
lemma THE_default_none:
wenzelm@22816
    36
    "\<not>(\<exists>!x. P x) \<Longrightarrow> THE_default d P = d"
wenzelm@22816
    37
  by (simp add:THE_default_def)
krauss@20536
    38
krauss@20536
    39
krauss@19564
    40
lemma fundef_ex1_existence:
wenzelm@22816
    41
  assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
wenzelm@22816
    42
  assumes ex1: "\<exists>!y. G x y"
wenzelm@22816
    43
  shows "G x (f x)"
wenzelm@22816
    44
  apply (simp only: f_def)
wenzelm@22816
    45
  apply (rule THE_defaultI')
wenzelm@22816
    46
  apply (rule ex1)
wenzelm@22816
    47
  done
krauss@21051
    48
krauss@19564
    49
lemma fundef_ex1_uniqueness:
wenzelm@22816
    50
  assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
wenzelm@22816
    51
  assumes ex1: "\<exists>!y. G x y"
wenzelm@22816
    52
  assumes elm: "G x (h x)"
wenzelm@22816
    53
  shows "h x = f x"
wenzelm@22816
    54
  apply (simp only: f_def)
wenzelm@22816
    55
  apply (rule THE_default1_equality [symmetric])
wenzelm@22816
    56
   apply (rule ex1)
wenzelm@22816
    57
  apply (rule elm)
wenzelm@22816
    58
  done
krauss@19564
    59
krauss@19564
    60
lemma fundef_ex1_iff:
wenzelm@22816
    61
  assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
wenzelm@22816
    62
  assumes ex1: "\<exists>!y. G x y"
wenzelm@22816
    63
  shows "(G x y) = (f x = y)"
krauss@20536
    64
  apply (auto simp:ex1 f_def THE_default1_equality)
wenzelm@22816
    65
  apply (rule THE_defaultI')
wenzelm@22816
    66
  apply (rule ex1)
wenzelm@22816
    67
  done
krauss@19564
    68
krauss@20654
    69
lemma fundef_default_value:
wenzelm@22816
    70
  assumes f_def: "f == (\<lambda>x::'a. THE_default (d x) (\<lambda>y. G x y))"
wenzelm@22816
    71
  assumes graph: "\<And>x y. G x y \<Longrightarrow> D x"
wenzelm@22816
    72
  assumes "\<not> D x"
wenzelm@22816
    73
  shows "f x = d x"
krauss@20654
    74
proof -
krauss@21051
    75
  have "\<not>(\<exists>y. G x y)"
krauss@20654
    76
  proof
krauss@21512
    77
    assume "\<exists>y. G x y"
krauss@21512
    78
    hence "D x" using graph ..
krauss@21512
    79
    with `\<not> D x` show False ..
krauss@20654
    80
  qed
krauss@21051
    81
  hence "\<not>(\<exists>!y. G x y)" by blast
wenzelm@22816
    82
krauss@20654
    83
  thus ?thesis
krauss@20654
    84
    unfolding f_def
krauss@20654
    85
    by (rule THE_default_none)
krauss@20654
    86
qed
krauss@20654
    87
berghofe@23739
    88
definition in_rel_def[simp]:
berghofe@23739
    89
  "in_rel R x y == (x, y) \<in> R"
berghofe@23739
    90
berghofe@23739
    91
lemma wf_in_rel:
berghofe@23739
    92
  "wf R \<Longrightarrow> wfP (in_rel R)"
berghofe@23739
    93
  by (simp add: wfP_def)
berghofe@23739
    94
berghofe@23739
    95
krauss@23203
    96
use "Tools/function_package/fundef_lib.ML"
krauss@19564
    97
use "Tools/function_package/fundef_common.ML"
krauss@20523
    98
use "Tools/function_package/inductive_wrap.ML"
krauss@19564
    99
use "Tools/function_package/context_tree.ML"
krauss@22166
   100
use "Tools/function_package/fundef_core.ML"
krauss@19770
   101
use "Tools/function_package/mutual.ML"
krauss@20270
   102
use "Tools/function_package/pattern_split.ML"
krauss@21319
   103
use "Tools/function_package/auto_term.ML"
krauss@19564
   104
use "Tools/function_package/fundef_package.ML"
krauss@19564
   105
krauss@19564
   106
setup FundefPackage.setup
krauss@19770
   107
haftmann@22838
   108
lemma let_cong [fundef_cong]:
haftmann@22838
   109
  "M = N \<Longrightarrow> (\<And>x. x = N \<Longrightarrow> f x = g x) \<Longrightarrow> Let M f = Let N g"
wenzelm@22816
   110
  unfolding Let_def by blast
krauss@22622
   111
wenzelm@22816
   112
lemmas [fundef_cong] =
haftmann@22838
   113
  if_cong image_cong INT_cong UN_cong
haftmann@22838
   114
  bex_cong ball_cong imp_cong
krauss@19564
   115
wenzelm@22816
   116
lemma split_cong [fundef_cong]:
haftmann@22838
   117
  "(\<And>x y. (x, y) = q \<Longrightarrow> f x y = g x y) \<Longrightarrow> p = q
wenzelm@22816
   118
    \<Longrightarrow> split f p = split g q"
wenzelm@22816
   119
  by (auto simp: split_def)
krauss@19934
   120
wenzelm@22816
   121
lemma comp_cong [fundef_cong]:
haftmann@22838
   122
  "f (g x) = f' (g' x') \<Longrightarrow> (f o g) x = (f' o g') x'"
wenzelm@22816
   123
  unfolding o_apply .
krauss@19934
   124
krauss@19564
   125
end