src/HOLCF/Ffun.thy
author huffman
Mon May 11 08:28:09 2009 -0700 (2009-05-11)
changeset 31095 b79d140f6d0b
parent 31076 99fe356cbbc2
child 35914 91a7311177c4
permissions -rw-r--r--
simplify fixrec proofs for mutually-recursive definitions; generate better fixpoint induction rules
huffman@16202
     1
(*  Title:      HOLCF/FunCpo.thy
huffman@16202
     2
    Author:     Franz Regensburger
huffman@16202
     3
*)
huffman@16202
     4
huffman@16202
     5
header {* Class instances for the full function space *}
huffman@16202
     6
huffman@16202
     7
theory Ffun
huffman@25786
     8
imports Cont
huffman@16202
     9
begin
huffman@16202
    10
huffman@18291
    11
subsection {* Full function space is a partial order *}
huffman@16202
    12
huffman@31076
    13
instantiation "fun"  :: (type, below) below
huffman@25758
    14
begin
huffman@16202
    15
huffman@25758
    16
definition
huffman@31076
    17
  below_fun_def: "(op \<sqsubseteq>) \<equiv> (\<lambda>f g. \<forall>x. f x \<sqsubseteq> g x)"
huffman@16202
    18
huffman@25758
    19
instance ..
huffman@25758
    20
end
huffman@16202
    21
huffman@25758
    22
instance "fun" :: (type, po) po
huffman@25758
    23
proof
huffman@25758
    24
  fix f :: "'a \<Rightarrow> 'b"
huffman@25758
    25
  show "f \<sqsubseteq> f"
huffman@31076
    26
    by (simp add: below_fun_def)
huffman@25758
    27
next
huffman@25758
    28
  fix f g :: "'a \<Rightarrow> 'b"
huffman@25758
    29
  assume "f \<sqsubseteq> g" and "g \<sqsubseteq> f" thus "f = g"
huffman@31076
    30
    by (simp add: below_fun_def expand_fun_eq below_antisym)
huffman@25758
    31
next
huffman@25758
    32
  fix f g h :: "'a \<Rightarrow> 'b"
huffman@25758
    33
  assume "f \<sqsubseteq> g" and "g \<sqsubseteq> h" thus "f \<sqsubseteq> h"
huffman@31076
    34
    unfolding below_fun_def by (fast elim: below_trans)
huffman@25758
    35
qed
huffman@16202
    36
huffman@16202
    37
text {* make the symbol @{text "<<"} accessible for type fun *}
huffman@16202
    38
huffman@31076
    39
lemma expand_fun_below: "(f \<sqsubseteq> g) = (\<forall>x. f x \<sqsubseteq> g x)"
huffman@31076
    40
by (simp add: below_fun_def)
huffman@16202
    41
huffman@31076
    42
lemma below_fun_ext: "(\<And>x. f x \<sqsubseteq> g x) \<Longrightarrow> f \<sqsubseteq> g"
huffman@31076
    43
by (simp add: below_fun_def)
huffman@16202
    44
huffman@18291
    45
subsection {* Full function space is chain complete *}
huffman@16202
    46
huffman@25786
    47
text {* function application is monotone *}
huffman@25786
    48
huffman@25786
    49
lemma monofun_app: "monofun (\<lambda>f. f x)"
huffman@31076
    50
by (rule monofunI, simp add: below_fun_def)
huffman@25786
    51
huffman@16202
    52
text {* chains of functions yield chains in the po range *}
huffman@16202
    53
huffman@16202
    54
lemma ch2ch_fun: "chain S \<Longrightarrow> chain (\<lambda>i. S i x)"
huffman@31076
    55
by (simp add: chain_def below_fun_def)
huffman@16202
    56
huffman@18092
    57
lemma ch2ch_lambda: "(\<And>x. chain (\<lambda>i. S i x)) \<Longrightarrow> chain S"
huffman@31076
    58
by (simp add: chain_def below_fun_def)
huffman@16202
    59
huffman@16202
    60
text {* upper bounds of function chains yield upper bound in the po range *}
huffman@16202
    61
huffman@16202
    62
lemma ub2ub_fun:
huffman@26028
    63
  "range S <| u \<Longrightarrow> range (\<lambda>i. S i x) <| u x"
huffman@31076
    64
by (auto simp add: is_ub_def below_fun_def)
huffman@16202
    65
huffman@16202
    66
text {* Type @{typ "'a::type => 'b::cpo"} is chain complete *}
huffman@16202
    67
huffman@26028
    68
lemma is_lub_lambda:
huffman@26028
    69
  assumes f: "\<And>x. range (\<lambda>i. Y i x) <<| f x"
huffman@26028
    70
  shows "range Y <<| f"
huffman@26028
    71
apply (rule is_lubI)
huffman@26028
    72
apply (rule ub_rangeI)
huffman@31076
    73
apply (rule below_fun_ext)
huffman@26028
    74
apply (rule is_ub_lub [OF f])
huffman@31076
    75
apply (rule below_fun_ext)
huffman@26028
    76
apply (rule is_lub_lub [OF f])
huffman@26028
    77
apply (erule ub2ub_fun)
huffman@26028
    78
done
huffman@26028
    79
huffman@16202
    80
lemma lub_fun:
huffman@16202
    81
  "chain (S::nat \<Rightarrow> 'a::type \<Rightarrow> 'b::cpo)
huffman@16202
    82
    \<Longrightarrow> range S <<| (\<lambda>x. \<Squnion>i. S i x)"
huffman@26028
    83
apply (rule is_lub_lambda)
huffman@26028
    84
apply (rule cpo_lubI)
huffman@16202
    85
apply (erule ch2ch_fun)
huffman@16202
    86
done
huffman@16202
    87
huffman@16202
    88
lemma thelub_fun:
huffman@16202
    89
  "chain (S::nat \<Rightarrow> 'a::type \<Rightarrow> 'b::cpo)
huffman@27413
    90
    \<Longrightarrow> (\<Squnion>i. S i) = (\<lambda>x. \<Squnion>i. S i x)"
huffman@16202
    91
by (rule lub_fun [THEN thelubI])
huffman@16202
    92
huffman@16202
    93
lemma cpo_fun:
huffman@16202
    94
  "chain (S::nat \<Rightarrow> 'a::type \<Rightarrow> 'b::cpo) \<Longrightarrow> \<exists>x. range S <<| x"
huffman@16202
    95
by (rule exI, erule lub_fun)
huffman@16202
    96
krauss@20523
    97
instance "fun"  :: (type, cpo) cpo
huffman@16202
    98
by intro_classes (rule cpo_fun)
huffman@16202
    99
huffman@25827
   100
instance "fun" :: (finite, finite_po) finite_po ..
huffman@25827
   101
huffman@26025
   102
instance "fun" :: (type, discrete_cpo) discrete_cpo
huffman@26025
   103
proof
huffman@26025
   104
  fix f g :: "'a \<Rightarrow> 'b"
huffman@26025
   105
  show "f \<sqsubseteq> g \<longleftrightarrow> f = g" 
huffman@31076
   106
    unfolding expand_fun_below expand_fun_eq
huffman@26025
   107
    by simp
huffman@26025
   108
qed
huffman@26025
   109
huffman@25827
   110
text {* chain-finite function spaces *}
huffman@25827
   111
huffman@25827
   112
lemma maxinch2maxinch_lambda:
huffman@25827
   113
  "(\<And>x. max_in_chain n (\<lambda>i. S i x)) \<Longrightarrow> max_in_chain n S"
huffman@25827
   114
unfolding max_in_chain_def expand_fun_eq by simp
huffman@25827
   115
huffman@25827
   116
lemma maxinch_mono:
huffman@25827
   117
  "\<lbrakk>max_in_chain i Y; i \<le> j\<rbrakk> \<Longrightarrow> max_in_chain j Y"
huffman@25827
   118
unfolding max_in_chain_def
huffman@25827
   119
proof (intro allI impI)
huffman@25827
   120
  fix k
huffman@25827
   121
  assume Y: "\<forall>n\<ge>i. Y i = Y n"
huffman@25827
   122
  assume ij: "i \<le> j"
huffman@25827
   123
  assume jk: "j \<le> k"
huffman@25827
   124
  from ij jk have ik: "i \<le> k" by simp
huffman@25827
   125
  from Y ij have Yij: "Y i = Y j" by simp
huffman@25827
   126
  from Y ik have Yik: "Y i = Y k" by simp
huffman@25827
   127
  from Yij Yik show "Y j = Y k" by auto
huffman@25827
   128
qed
huffman@25827
   129
huffman@25827
   130
instance "fun" :: (finite, chfin) chfin
huffman@25921
   131
proof
huffman@25827
   132
  fix Y :: "nat \<Rightarrow> 'a \<Rightarrow> 'b"
huffman@25827
   133
  let ?n = "\<lambda>x. LEAST n. max_in_chain n (\<lambda>i. Y i x)"
huffman@25827
   134
  assume "chain Y"
huffman@25827
   135
  hence "\<And>x. chain (\<lambda>i. Y i x)"
huffman@25827
   136
    by (rule ch2ch_fun)
huffman@25827
   137
  hence "\<And>x. \<exists>n. max_in_chain n (\<lambda>i. Y i x)"
huffman@25921
   138
    by (rule chfin)
huffman@25827
   139
  hence "\<And>x. max_in_chain (?n x) (\<lambda>i. Y i x)"
huffman@25827
   140
    by (rule LeastI_ex)
huffman@25827
   141
  hence "\<And>x. max_in_chain (Max (range ?n)) (\<lambda>i. Y i x)"
huffman@25827
   142
    by (rule maxinch_mono [OF _ Max_ge], simp_all)
huffman@25827
   143
  hence "max_in_chain (Max (range ?n)) Y"
huffman@25827
   144
    by (rule maxinch2maxinch_lambda)
huffman@25827
   145
  thus "\<exists>n. max_in_chain n Y" ..
huffman@25827
   146
qed
huffman@25827
   147
huffman@18291
   148
subsection {* Full function space is pointed *}
huffman@17831
   149
huffman@17831
   150
lemma minimal_fun: "(\<lambda>x. \<bottom>) \<sqsubseteq> f"
huffman@31076
   151
by (simp add: below_fun_def)
huffman@17831
   152
huffman@25786
   153
lemma least_fun: "\<exists>x::'a::type \<Rightarrow> 'b::pcpo. \<forall>y. x \<sqsubseteq> y"
huffman@17831
   154
apply (rule_tac x = "\<lambda>x. \<bottom>" in exI)
huffman@17831
   155
apply (rule minimal_fun [THEN allI])
huffman@17831
   156
done
huffman@17831
   157
krauss@20523
   158
instance "fun"  :: (type, pcpo) pcpo
huffman@16202
   159
by intro_classes (rule least_fun)
huffman@16202
   160
huffman@16202
   161
text {* for compatibility with old HOLCF-Version *}
huffman@17831
   162
lemma inst_fun_pcpo: "\<bottom> = (\<lambda>x. \<bottom>)"
huffman@16202
   163
by (rule minimal_fun [THEN UU_I, symmetric])
huffman@16202
   164
huffman@16202
   165
text {* function application is strict in the left argument *}
huffman@16202
   166
lemma app_strict [simp]: "\<bottom> x = \<bottom>"
huffman@16202
   167
by (simp add: inst_fun_pcpo)
huffman@16202
   168
huffman@25786
   169
text {*
huffman@25786
   170
  The following results are about application for functions in @{typ "'a=>'b"}
huffman@25786
   171
*}
huffman@25786
   172
huffman@25786
   173
lemma monofun_fun_fun: "f \<sqsubseteq> g \<Longrightarrow> f x \<sqsubseteq> g x"
huffman@31076
   174
by (simp add: below_fun_def)
huffman@25786
   175
huffman@25786
   176
lemma monofun_fun_arg: "\<lbrakk>monofun f; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> f x \<sqsubseteq> f y"
huffman@25786
   177
by (rule monofunE)
huffman@25786
   178
huffman@25786
   179
lemma monofun_fun: "\<lbrakk>monofun f; monofun g; f \<sqsubseteq> g; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> f x \<sqsubseteq> g y"
huffman@31076
   180
by (rule below_trans [OF monofun_fun_arg monofun_fun_fun])
huffman@25786
   181
huffman@25786
   182
subsection {* Propagation of monotonicity and continuity *}
huffman@25786
   183
huffman@25786
   184
text {* the lub of a chain of monotone functions is monotone *}
huffman@25786
   185
huffman@25786
   186
lemma monofun_lub_fun:
huffman@25786
   187
  "\<lbrakk>chain (F::nat \<Rightarrow> 'a \<Rightarrow> 'b::cpo); \<forall>i. monofun (F i)\<rbrakk>
huffman@25786
   188
    \<Longrightarrow> monofun (\<Squnion>i. F i)"
huffman@25786
   189
apply (rule monofunI)
huffman@25786
   190
apply (simp add: thelub_fun)
huffman@25923
   191
apply (rule lub_mono)
huffman@25786
   192
apply (erule ch2ch_fun)
huffman@25786
   193
apply (erule ch2ch_fun)
huffman@25786
   194
apply (simp add: monofunE)
huffman@25786
   195
done
huffman@25786
   196
huffman@25786
   197
text {* the lub of a chain of continuous functions is continuous *}
huffman@25786
   198
huffman@25786
   199
lemma contlub_lub_fun:
huffman@25786
   200
  "\<lbrakk>chain F; \<forall>i. cont (F i)\<rbrakk> \<Longrightarrow> contlub (\<Squnion>i. F i)"
huffman@25786
   201
apply (rule contlubI)
huffman@25786
   202
apply (simp add: thelub_fun)
huffman@25786
   203
apply (simp add: cont2contlubE)
huffman@25786
   204
apply (rule ex_lub)
huffman@25786
   205
apply (erule ch2ch_fun)
huffman@25786
   206
apply (simp add: ch2ch_cont)
huffman@25786
   207
done
huffman@25786
   208
huffman@25786
   209
lemma cont_lub_fun:
huffman@25786
   210
  "\<lbrakk>chain F; \<forall>i. cont (F i)\<rbrakk> \<Longrightarrow> cont (\<Squnion>i. F i)"
huffman@25786
   211
apply (rule monocontlub2cont)
huffman@25786
   212
apply (erule monofun_lub_fun)
huffman@25786
   213
apply (simp add: cont2mono)
huffman@25786
   214
apply (erule (1) contlub_lub_fun)
huffman@25786
   215
done
huffman@25786
   216
huffman@25786
   217
lemma cont2cont_lub:
huffman@25786
   218
  "\<lbrakk>chain F; \<And>i. cont (F i)\<rbrakk> \<Longrightarrow> cont (\<lambda>x. \<Squnion>i. F i x)"
huffman@25786
   219
by (simp add: thelub_fun [symmetric] cont_lub_fun)
huffman@25786
   220
huffman@25786
   221
lemma mono2mono_fun: "monofun f \<Longrightarrow> monofun (\<lambda>x. f x y)"
huffman@25786
   222
apply (rule monofunI)
huffman@25786
   223
apply (erule (1) monofun_fun_arg [THEN monofun_fun_fun])
huffman@25786
   224
done
huffman@25786
   225
huffman@25786
   226
lemma cont2cont_fun: "cont f \<Longrightarrow> cont (\<lambda>x. f x y)"
huffman@25786
   227
apply (rule monocontlub2cont)
huffman@25786
   228
apply (erule cont2mono [THEN mono2mono_fun])
huffman@25786
   229
apply (rule contlubI)
huffman@25786
   230
apply (simp add: cont2contlubE)
huffman@25786
   231
apply (simp add: thelub_fun ch2ch_cont)
huffman@25786
   232
done
huffman@25786
   233
huffman@25786
   234
text {* Note @{text "(\<lambda>x. \<lambda>y. f x y) = f"} *}
huffman@25786
   235
huffman@26452
   236
lemma mono2mono_lambda:
huffman@26452
   237
  assumes f: "\<And>y. monofun (\<lambda>x. f x y)" shows "monofun f"
huffman@25786
   238
apply (rule monofunI)
huffman@31076
   239
apply (rule below_fun_ext)
huffman@26452
   240
apply (erule monofunE [OF f])
huffman@25786
   241
done
huffman@25786
   242
huffman@26452
   243
lemma cont2cont_lambda [simp]:
huffman@26452
   244
  assumes f: "\<And>y. cont (\<lambda>x. f x y)" shows "cont f"
huffman@25786
   245
apply (subgoal_tac "monofun f")
huffman@25786
   246
apply (rule monocontlub2cont)
huffman@25786
   247
apply assumption
huffman@25786
   248
apply (rule contlubI)
huffman@25786
   249
apply (rule ext)
huffman@25786
   250
apply (simp add: thelub_fun ch2ch_monofun)
huffman@26452
   251
apply (erule cont2contlubE [OF f])
huffman@26452
   252
apply (simp add: mono2mono_lambda cont2mono f)
huffman@25786
   253
done
huffman@25786
   254
huffman@25786
   255
text {* What D.A.Schmidt calls continuity of abstraction; never used here *}
huffman@25786
   256
huffman@25786
   257
lemma contlub_lambda:
huffman@25786
   258
  "(\<And>x::'a::type. chain (\<lambda>i. S i x::'b::cpo))
huffman@25786
   259
    \<Longrightarrow> (\<lambda>x. \<Squnion>i. S i x) = (\<Squnion>i. (\<lambda>x. S i x))"
huffman@25786
   260
by (simp add: thelub_fun ch2ch_lambda)
huffman@25786
   261
huffman@25786
   262
lemma contlub_abstraction:
huffman@25786
   263
  "\<lbrakk>chain Y; \<forall>y. cont (\<lambda>x.(c::'a::cpo\<Rightarrow>'b::type\<Rightarrow>'c::cpo) x y)\<rbrakk> \<Longrightarrow>
huffman@25786
   264
    (\<lambda>y. \<Squnion>i. c (Y i) y) = (\<Squnion>i. (\<lambda>y. c (Y i) y))"
huffman@25786
   265
apply (rule thelub_fun [symmetric])
huffman@26452
   266
apply (simp add: ch2ch_cont)
huffman@25786
   267
done
huffman@25786
   268
huffman@25786
   269
lemma mono2mono_app:
huffman@25786
   270
  "\<lbrakk>monofun f; \<forall>x. monofun (f x); monofun t\<rbrakk> \<Longrightarrow> monofun (\<lambda>x. (f x) (t x))"
huffman@25786
   271
apply (rule monofunI)
huffman@25786
   272
apply (simp add: monofun_fun monofunE)
huffman@25786
   273
done
huffman@25786
   274
huffman@25786
   275
lemma cont2contlub_app:
huffman@25786
   276
  "\<lbrakk>cont f; \<forall>x. cont (f x); cont t\<rbrakk> \<Longrightarrow> contlub (\<lambda>x. (f x) (t x))"
huffman@25786
   277
apply (rule contlubI)
huffman@25786
   278
apply (subgoal_tac "chain (\<lambda>i. f (Y i))")
huffman@25786
   279
apply (subgoal_tac "chain (\<lambda>i. t (Y i))")
huffman@25786
   280
apply (simp add: cont2contlubE thelub_fun)
huffman@25786
   281
apply (rule diag_lub)
huffman@25786
   282
apply (erule ch2ch_fun)
huffman@25786
   283
apply (drule spec)
huffman@25786
   284
apply (erule (1) ch2ch_cont)
huffman@25786
   285
apply (erule (1) ch2ch_cont)
huffman@25786
   286
apply (erule (1) ch2ch_cont)
huffman@25786
   287
done
huffman@25786
   288
huffman@25786
   289
lemma cont2cont_app:
huffman@25786
   290
  "\<lbrakk>cont f; \<forall>x. cont (f x); cont t\<rbrakk> \<Longrightarrow> cont (\<lambda>x. (f x) (t x))"
huffman@25786
   291
by (blast intro: monocontlub2cont mono2mono_app cont2mono cont2contlub_app)
huffman@25786
   292
huffman@25786
   293
lemmas cont2cont_app2 = cont2cont_app [rule_format]
huffman@25786
   294
huffman@25786
   295
lemma cont2cont_app3: "\<lbrakk>cont f; cont t\<rbrakk> \<Longrightarrow> cont (\<lambda>x. f (t x))"
huffman@25786
   296
by (rule cont2cont_app2 [OF cont_const])
huffman@25786
   297
huffman@16202
   298
end