src/HOLCF/Fun_Cpo.thy
author huffman
Tue Oct 12 06:20:05 2010 -0700 (2010-10-12)
changeset 40006 116e94f9543b
parent 40004 9f6ed6840e8d
child 40011 b974cf829099
permissions -rw-r--r--
remove unneeded lemmas from Fun_Cpo.thy
huffman@40001
     1
(*  Title:      HOLCF/Fun_Cpo.thy
huffman@16202
     2
    Author:     Franz Regensburger
huffman@40001
     3
    Author:     Brian Huffman
huffman@16202
     4
*)
huffman@16202
     5
huffman@16202
     6
header {* Class instances for the full function space *}
huffman@16202
     7
huffman@40001
     8
theory Fun_Cpo
huffman@25786
     9
imports Cont
huffman@16202
    10
begin
huffman@16202
    11
huffman@18291
    12
subsection {* Full function space is a partial order *}
huffman@16202
    13
huffman@31076
    14
instantiation "fun"  :: (type, below) below
huffman@25758
    15
begin
huffman@16202
    16
huffman@25758
    17
definition
huffman@31076
    18
  below_fun_def: "(op \<sqsubseteq>) \<equiv> (\<lambda>f g. \<forall>x. f x \<sqsubseteq> g x)"
huffman@16202
    19
huffman@25758
    20
instance ..
huffman@25758
    21
end
huffman@16202
    22
huffman@25758
    23
instance "fun" :: (type, po) po
huffman@25758
    24
proof
huffman@25758
    25
  fix f :: "'a \<Rightarrow> 'b"
huffman@25758
    26
  show "f \<sqsubseteq> f"
huffman@31076
    27
    by (simp add: below_fun_def)
huffman@25758
    28
next
huffman@25758
    29
  fix f g :: "'a \<Rightarrow> 'b"
huffman@25758
    30
  assume "f \<sqsubseteq> g" and "g \<sqsubseteq> f" thus "f = g"
nipkow@39302
    31
    by (simp add: below_fun_def fun_eq_iff below_antisym)
huffman@25758
    32
next
huffman@25758
    33
  fix f g h :: "'a \<Rightarrow> 'b"
huffman@25758
    34
  assume "f \<sqsubseteq> g" and "g \<sqsubseteq> h" thus "f \<sqsubseteq> h"
huffman@31076
    35
    unfolding below_fun_def by (fast elim: below_trans)
huffman@25758
    36
qed
huffman@16202
    37
huffman@40002
    38
lemma fun_below_iff: "f \<sqsubseteq> g \<longleftrightarrow> (\<forall>x. f x \<sqsubseteq> g x)"
huffman@31076
    39
by (simp add: below_fun_def)
huffman@16202
    40
huffman@40002
    41
lemma fun_belowI: "(\<And>x. f x \<sqsubseteq> g x) \<Longrightarrow> f \<sqsubseteq> g"
huffman@31076
    42
by (simp add: below_fun_def)
huffman@16202
    43
huffman@18291
    44
subsection {* Full function space is chain complete *}
huffman@16202
    45
huffman@25786
    46
text {* function application is monotone *}
huffman@25786
    47
huffman@25786
    48
lemma monofun_app: "monofun (\<lambda>f. f x)"
huffman@31076
    49
by (rule monofunI, simp add: below_fun_def)
huffman@25786
    50
huffman@16202
    51
text {* chains of functions yield chains in the po range *}
huffman@16202
    52
huffman@16202
    53
lemma ch2ch_fun: "chain S \<Longrightarrow> chain (\<lambda>i. S i x)"
huffman@31076
    54
by (simp add: chain_def below_fun_def)
huffman@16202
    55
huffman@18092
    56
lemma ch2ch_lambda: "(\<And>x. chain (\<lambda>i. S i x)) \<Longrightarrow> chain S"
huffman@31076
    57
by (simp add: chain_def below_fun_def)
huffman@16202
    58
huffman@16202
    59
text {* upper bounds of function chains yield upper bound in the po range *}
huffman@16202
    60
huffman@16202
    61
lemma ub2ub_fun:
huffman@26028
    62
  "range S <| u \<Longrightarrow> range (\<lambda>i. S i x) <| u x"
huffman@31076
    63
by (auto simp add: is_ub_def below_fun_def)
huffman@16202
    64
huffman@16202
    65
text {* Type @{typ "'a::type => 'b::cpo"} is chain complete *}
huffman@16202
    66
huffman@26028
    67
lemma is_lub_lambda:
huffman@26028
    68
  assumes f: "\<And>x. range (\<lambda>i. Y i x) <<| f x"
huffman@26028
    69
  shows "range Y <<| f"
huffman@26028
    70
apply (rule is_lubI)
huffman@26028
    71
apply (rule ub_rangeI)
huffman@40002
    72
apply (rule fun_belowI)
huffman@26028
    73
apply (rule is_ub_lub [OF f])
huffman@40002
    74
apply (rule fun_belowI)
huffman@26028
    75
apply (rule is_lub_lub [OF f])
huffman@26028
    76
apply (erule ub2ub_fun)
huffman@26028
    77
done
huffman@26028
    78
huffman@16202
    79
lemma lub_fun:
huffman@16202
    80
  "chain (S::nat \<Rightarrow> 'a::type \<Rightarrow> 'b::cpo)
huffman@16202
    81
    \<Longrightarrow> range S <<| (\<lambda>x. \<Squnion>i. S i x)"
huffman@26028
    82
apply (rule is_lub_lambda)
huffman@26028
    83
apply (rule cpo_lubI)
huffman@16202
    84
apply (erule ch2ch_fun)
huffman@16202
    85
done
huffman@16202
    86
huffman@16202
    87
lemma thelub_fun:
huffman@16202
    88
  "chain (S::nat \<Rightarrow> 'a::type \<Rightarrow> 'b::cpo)
huffman@27413
    89
    \<Longrightarrow> (\<Squnion>i. S i) = (\<lambda>x. \<Squnion>i. S i x)"
huffman@16202
    90
by (rule lub_fun [THEN thelubI])
huffman@16202
    91
krauss@20523
    92
instance "fun"  :: (type, cpo) cpo
huffman@40006
    93
by intro_classes (rule exI, erule lub_fun)
huffman@16202
    94
huffman@25827
    95
instance "fun" :: (finite, finite_po) finite_po ..
huffman@25827
    96
huffman@26025
    97
instance "fun" :: (type, discrete_cpo) discrete_cpo
huffman@26025
    98
proof
huffman@26025
    99
  fix f g :: "'a \<Rightarrow> 'b"
huffman@26025
   100
  show "f \<sqsubseteq> g \<longleftrightarrow> f = g" 
huffman@40002
   101
    unfolding fun_below_iff fun_eq_iff
huffman@26025
   102
    by simp
huffman@26025
   103
qed
huffman@26025
   104
huffman@25827
   105
text {* chain-finite function spaces *}
huffman@25827
   106
huffman@25827
   107
lemma maxinch2maxinch_lambda:
huffman@25827
   108
  "(\<And>x. max_in_chain n (\<lambda>i. S i x)) \<Longrightarrow> max_in_chain n S"
nipkow@39302
   109
unfolding max_in_chain_def fun_eq_iff by simp
huffman@25827
   110
huffman@25827
   111
lemma maxinch_mono:
huffman@25827
   112
  "\<lbrakk>max_in_chain i Y; i \<le> j\<rbrakk> \<Longrightarrow> max_in_chain j Y"
huffman@25827
   113
unfolding max_in_chain_def
huffman@25827
   114
proof (intro allI impI)
huffman@25827
   115
  fix k
huffman@25827
   116
  assume Y: "\<forall>n\<ge>i. Y i = Y n"
huffman@25827
   117
  assume ij: "i \<le> j"
huffman@25827
   118
  assume jk: "j \<le> k"
huffman@25827
   119
  from ij jk have ik: "i \<le> k" by simp
huffman@25827
   120
  from Y ij have Yij: "Y i = Y j" by simp
huffman@25827
   121
  from Y ik have Yik: "Y i = Y k" by simp
huffman@25827
   122
  from Yij Yik show "Y j = Y k" by auto
huffman@25827
   123
qed
huffman@25827
   124
huffman@25827
   125
instance "fun" :: (finite, chfin) chfin
huffman@25921
   126
proof
huffman@25827
   127
  fix Y :: "nat \<Rightarrow> 'a \<Rightarrow> 'b"
huffman@25827
   128
  let ?n = "\<lambda>x. LEAST n. max_in_chain n (\<lambda>i. Y i x)"
huffman@25827
   129
  assume "chain Y"
huffman@25827
   130
  hence "\<And>x. chain (\<lambda>i. Y i x)"
huffman@25827
   131
    by (rule ch2ch_fun)
huffman@25827
   132
  hence "\<And>x. \<exists>n. max_in_chain n (\<lambda>i. Y i x)"
huffman@25921
   133
    by (rule chfin)
huffman@25827
   134
  hence "\<And>x. max_in_chain (?n x) (\<lambda>i. Y i x)"
huffman@25827
   135
    by (rule LeastI_ex)
huffman@25827
   136
  hence "\<And>x. max_in_chain (Max (range ?n)) (\<lambda>i. Y i x)"
huffman@25827
   137
    by (rule maxinch_mono [OF _ Max_ge], simp_all)
huffman@25827
   138
  hence "max_in_chain (Max (range ?n)) Y"
huffman@25827
   139
    by (rule maxinch2maxinch_lambda)
huffman@25827
   140
  thus "\<exists>n. max_in_chain n Y" ..
huffman@25827
   141
qed
huffman@25827
   142
huffman@18291
   143
subsection {* Full function space is pointed *}
huffman@17831
   144
huffman@17831
   145
lemma minimal_fun: "(\<lambda>x. \<bottom>) \<sqsubseteq> f"
huffman@31076
   146
by (simp add: below_fun_def)
huffman@17831
   147
huffman@25786
   148
lemma least_fun: "\<exists>x::'a::type \<Rightarrow> 'b::pcpo. \<forall>y. x \<sqsubseteq> y"
huffman@17831
   149
apply (rule_tac x = "\<lambda>x. \<bottom>" in exI)
huffman@17831
   150
apply (rule minimal_fun [THEN allI])
huffman@17831
   151
done
huffman@17831
   152
krauss@20523
   153
instance "fun"  :: (type, pcpo) pcpo
huffman@16202
   154
by intro_classes (rule least_fun)
huffman@16202
   155
huffman@16202
   156
text {* for compatibility with old HOLCF-Version *}
huffman@17831
   157
lemma inst_fun_pcpo: "\<bottom> = (\<lambda>x. \<bottom>)"
huffman@16202
   158
by (rule minimal_fun [THEN UU_I, symmetric])
huffman@16202
   159
huffman@16202
   160
text {* function application is strict in the left argument *}
huffman@16202
   161
lemma app_strict [simp]: "\<bottom> x = \<bottom>"
huffman@16202
   162
by (simp add: inst_fun_pcpo)
huffman@16202
   163
huffman@25786
   164
text {*
huffman@25786
   165
  The following results are about application for functions in @{typ "'a=>'b"}
huffman@25786
   166
*}
huffman@25786
   167
huffman@25786
   168
lemma monofun_fun_fun: "f \<sqsubseteq> g \<Longrightarrow> f x \<sqsubseteq> g x"
huffman@31076
   169
by (simp add: below_fun_def)
huffman@25786
   170
huffman@25786
   171
lemma monofun_fun_arg: "\<lbrakk>monofun f; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> f x \<sqsubseteq> f y"
huffman@25786
   172
by (rule monofunE)
huffman@25786
   173
huffman@25786
   174
lemma monofun_fun: "\<lbrakk>monofun f; monofun g; f \<sqsubseteq> g; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> f x \<sqsubseteq> g y"
huffman@31076
   175
by (rule below_trans [OF monofun_fun_arg monofun_fun_fun])
huffman@25786
   176
huffman@25786
   177
subsection {* Propagation of monotonicity and continuity *}
huffman@25786
   178
huffman@25786
   179
text {* the lub of a chain of monotone functions is monotone *}
huffman@25786
   180
huffman@25786
   181
lemma monofun_lub_fun:
huffman@25786
   182
  "\<lbrakk>chain (F::nat \<Rightarrow> 'a \<Rightarrow> 'b::cpo); \<forall>i. monofun (F i)\<rbrakk>
huffman@25786
   183
    \<Longrightarrow> monofun (\<Squnion>i. F i)"
huffman@25786
   184
apply (rule monofunI)
huffman@25786
   185
apply (simp add: thelub_fun)
huffman@25923
   186
apply (rule lub_mono)
huffman@25786
   187
apply (erule ch2ch_fun)
huffman@25786
   188
apply (erule ch2ch_fun)
huffman@25786
   189
apply (simp add: monofunE)
huffman@25786
   190
done
huffman@25786
   191
huffman@25786
   192
text {* the lub of a chain of continuous functions is continuous *}
huffman@25786
   193
huffman@25786
   194
lemma cont_lub_fun:
huffman@25786
   195
  "\<lbrakk>chain F; \<forall>i. cont (F i)\<rbrakk> \<Longrightarrow> cont (\<Squnion>i. F i)"
huffman@35914
   196
apply (rule contI2)
huffman@25786
   197
apply (erule monofun_lub_fun)
huffman@25786
   198
apply (simp add: cont2mono)
huffman@35914
   199
apply (simp add: thelub_fun cont2contlubE)
huffman@35914
   200
apply (simp add: diag_lub ch2ch_fun ch2ch_cont)
huffman@25786
   201
done
huffman@25786
   202
huffman@25786
   203
lemma mono2mono_fun: "monofun f \<Longrightarrow> monofun (\<lambda>x. f x y)"
huffman@25786
   204
apply (rule monofunI)
huffman@25786
   205
apply (erule (1) monofun_fun_arg [THEN monofun_fun_fun])
huffman@25786
   206
done
huffman@25786
   207
huffman@25786
   208
lemma cont2cont_fun: "cont f \<Longrightarrow> cont (\<lambda>x. f x y)"
huffman@35914
   209
apply (rule contI2)
huffman@25786
   210
apply (erule cont2mono [THEN mono2mono_fun])
huffman@25786
   211
apply (simp add: cont2contlubE)
huffman@25786
   212
apply (simp add: thelub_fun ch2ch_cont)
huffman@25786
   213
done
huffman@25786
   214
huffman@25786
   215
text {* Note @{text "(\<lambda>x. \<lambda>y. f x y) = f"} *}
huffman@25786
   216
huffman@26452
   217
lemma mono2mono_lambda:
huffman@26452
   218
  assumes f: "\<And>y. monofun (\<lambda>x. f x y)" shows "monofun f"
huffman@25786
   219
apply (rule monofunI)
huffman@40002
   220
apply (rule fun_belowI)
huffman@26452
   221
apply (erule monofunE [OF f])
huffman@25786
   222
done
huffman@25786
   223
huffman@26452
   224
lemma cont2cont_lambda [simp]:
huffman@26452
   225
  assumes f: "\<And>y. cont (\<lambda>x. f x y)" shows "cont f"
huffman@35914
   226
apply (rule contI2)
huffman@26452
   227
apply (simp add: mono2mono_lambda cont2mono f)
huffman@40002
   228
apply (rule fun_belowI)
huffman@35914
   229
apply (simp add: thelub_fun cont2contlubE [OF f])
huffman@25786
   230
done
huffman@25786
   231
huffman@25786
   232
text {* What D.A.Schmidt calls continuity of abstraction; never used here *}
huffman@25786
   233
huffman@25786
   234
lemma contlub_lambda:
huffman@25786
   235
  "(\<And>x::'a::type. chain (\<lambda>i. S i x::'b::cpo))
huffman@25786
   236
    \<Longrightarrow> (\<lambda>x. \<Squnion>i. S i x) = (\<Squnion>i. (\<lambda>x. S i x))"
huffman@25786
   237
by (simp add: thelub_fun ch2ch_lambda)
huffman@25786
   238
huffman@16202
   239
end