src/HOL/HOLCF/Cont.thy
author haftmann
Sun Jun 23 21:16:07 2013 +0200 (2013-06-23)
changeset 52435 6646bb548c6b
parent 45294 3c5d3d286055
child 57945 cacb00a569e0
permissions -rw-r--r--
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
wenzelm@42151
     1
(*  Title:      HOL/HOLCF/Cont.thy
clasohm@1479
     2
    Author:     Franz Regensburger
huffman@35794
     3
    Author:     Brian Huffman
nipkow@243
     4
*)
nipkow@243
     5
huffman@15577
     6
header {* Continuity and monotonicity *}
huffman@15577
     7
huffman@15577
     8
theory Cont
huffman@25786
     9
imports Pcpo
huffman@15577
    10
begin
nipkow@243
    11
huffman@15588
    12
text {*
huffman@15588
    13
   Now we change the default class! Form now on all untyped type variables are
slotosch@3323
    14
   of default class po
huffman@15588
    15
*}
nipkow@243
    16
wenzelm@36452
    17
default_sort po
nipkow@243
    18
huffman@16624
    19
subsection {* Definitions *}
nipkow@243
    20
wenzelm@25131
    21
definition
wenzelm@25131
    22
  monofun :: "('a \<Rightarrow> 'b) \<Rightarrow> bool"  -- "monotonicity"  where
wenzelm@25131
    23
  "monofun f = (\<forall>x y. x \<sqsubseteq> y \<longrightarrow> f x \<sqsubseteq> f y)"
nipkow@243
    24
wenzelm@25131
    25
definition
huffman@35914
    26
  cont :: "('a::cpo \<Rightarrow> 'b::cpo) \<Rightarrow> bool"
huffman@35914
    27
where
wenzelm@25131
    28
  "cont f = (\<forall>Y. chain Y \<longrightarrow> range (\<lambda>i. f (Y i)) <<| f (\<Squnion>i. Y i))"
huffman@15565
    29
huffman@16204
    30
lemma contI:
huffman@16204
    31
  "\<lbrakk>\<And>Y. chain Y \<Longrightarrow> range (\<lambda>i. f (Y i)) <<| f (\<Squnion>i. Y i)\<rbrakk> \<Longrightarrow> cont f"
huffman@16204
    32
by (simp add: cont_def)
huffman@15565
    33
huffman@16204
    34
lemma contE:
huffman@16204
    35
  "\<lbrakk>cont f; chain Y\<rbrakk> \<Longrightarrow> range (\<lambda>i. f (Y i)) <<| f (\<Squnion>i. Y i)"
huffman@16204
    36
by (simp add: cont_def)
huffman@15565
    37
huffman@15565
    38
lemma monofunI: 
huffman@16204
    39
  "\<lbrakk>\<And>x y. x \<sqsubseteq> y \<Longrightarrow> f x \<sqsubseteq> f y\<rbrakk> \<Longrightarrow> monofun f"
huffman@16204
    40
by (simp add: monofun_def)
huffman@15565
    41
huffman@15565
    42
lemma monofunE: 
huffman@16204
    43
  "\<lbrakk>monofun f; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> f x \<sqsubseteq> f y"
huffman@16204
    44
by (simp add: monofun_def)
huffman@15565
    45
huffman@16624
    46
huffman@35900
    47
subsection {* Equivalence of alternate definition *}
huffman@16624
    48
huffman@15588
    49
text {* monotone functions map chains to chains *}
huffman@15565
    50
huffman@16204
    51
lemma ch2ch_monofun: "\<lbrakk>monofun f; chain Y\<rbrakk> \<Longrightarrow> chain (\<lambda>i. f (Y i))"
huffman@15565
    52
apply (rule chainI)
huffman@16204
    53
apply (erule monofunE)
huffman@15565
    54
apply (erule chainE)
huffman@15565
    55
done
huffman@15565
    56
huffman@15588
    57
text {* monotone functions map upper bound to upper bounds *}
huffman@15565
    58
huffman@15565
    59
lemma ub2ub_monofun: 
huffman@16204
    60
  "\<lbrakk>monofun f; range Y <| u\<rbrakk> \<Longrightarrow> range (\<lambda>i. f (Y i)) <| f u"
huffman@15565
    61
apply (rule ub_rangeI)
huffman@16204
    62
apply (erule monofunE)
huffman@15565
    63
apply (erule ub_rangeD)
huffman@15565
    64
done
huffman@15565
    65
huffman@35914
    66
text {* a lemma about binary chains *}
huffman@15565
    67
huffman@16204
    68
lemma binchain_cont:
huffman@16204
    69
  "\<lbrakk>cont f; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> range (\<lambda>i::nat. f (if i = 0 then x else y)) <<| f y"
huffman@16204
    70
apply (subgoal_tac "f (\<Squnion>i::nat. if i = 0 then x else y) = f y")
huffman@16204
    71
apply (erule subst)
huffman@16204
    72
apply (erule contE)
huffman@15565
    73
apply (erule bin_chain)
huffman@16204
    74
apply (rule_tac f=f in arg_cong)
huffman@40771
    75
apply (erule is_lub_bin_chain [THEN lub_eqI])
huffman@15565
    76
done
huffman@15565
    77
huffman@35914
    78
text {* continuity implies monotonicity *}
huffman@15565
    79
huffman@16204
    80
lemma cont2mono: "cont f \<Longrightarrow> monofun f"
huffman@16204
    81
apply (rule monofunI)
huffman@18088
    82
apply (drule (1) binchain_cont)
huffman@40771
    83
apply (drule_tac i=0 in is_lub_rangeD1)
huffman@16204
    84
apply simp
huffman@15565
    85
done
huffman@15565
    86
huffman@29532
    87
lemmas cont2monofunE = cont2mono [THEN monofunE]
huffman@29532
    88
huffman@16737
    89
lemmas ch2ch_cont = cont2mono [THEN ch2ch_monofun]
huffman@16737
    90
huffman@35914
    91
text {* continuity implies preservation of lubs *}
huffman@15565
    92
huffman@35914
    93
lemma cont2contlubE:
huffman@35914
    94
  "\<lbrakk>cont f; chain Y\<rbrakk> \<Longrightarrow> f (\<Squnion> i. Y i) = (\<Squnion> i. f (Y i))"
huffman@40771
    95
apply (rule lub_eqI [symmetric])
huffman@18088
    96
apply (erule (1) contE)
huffman@15565
    97
done
huffman@15565
    98
huffman@25896
    99
lemma contI2:
huffman@40736
   100
  fixes f :: "'a::cpo \<Rightarrow> 'b::cpo"
huffman@25896
   101
  assumes mono: "monofun f"
huffman@31076
   102
  assumes below: "\<And>Y. \<lbrakk>chain Y; chain (\<lambda>i. f (Y i))\<rbrakk>
huffman@27413
   103
     \<Longrightarrow> f (\<Squnion>i. Y i) \<sqsubseteq> (\<Squnion>i. f (Y i))"
huffman@25896
   104
  shows "cont f"
huffman@40736
   105
proof (rule contI)
huffman@40736
   106
  fix Y :: "nat \<Rightarrow> 'a"
huffman@40736
   107
  assume Y: "chain Y"
huffman@40736
   108
  with mono have fY: "chain (\<lambda>i. f (Y i))"
huffman@40736
   109
    by (rule ch2ch_monofun)
huffman@40736
   110
  have "(\<Squnion>i. f (Y i)) = f (\<Squnion>i. Y i)"
huffman@40736
   111
    apply (rule below_antisym)
huffman@40736
   112
    apply (rule lub_below [OF fY])
huffman@40736
   113
    apply (rule monofunE [OF mono])
huffman@40736
   114
    apply (rule is_ub_thelub [OF Y])
huffman@40736
   115
    apply (rule below [OF Y fY])
huffman@40736
   116
    done
huffman@40736
   117
  with fY show "range (\<lambda>i. f (Y i)) <<| f (\<Squnion>i. Y i)"
huffman@40736
   118
    by (rule thelubE)
huffman@40736
   119
qed
huffman@25896
   120
huffman@37079
   121
subsection {* Collection of continuity rules *}
huffman@29530
   122
huffman@29530
   123
ML {*
wenzelm@31902
   124
structure Cont2ContData = Named_Thms
wenzelm@31902
   125
(
wenzelm@45294
   126
  val name = @{binding cont2cont}
wenzelm@31902
   127
  val description = "continuity intro rule"
wenzelm@31902
   128
)
huffman@29530
   129
*}
huffman@29530
   130
huffman@31030
   131
setup Cont2ContData.setup
huffman@29530
   132
huffman@16624
   133
subsection {* Continuity of basic functions *}
huffman@16624
   134
huffman@16624
   135
text {* The identity function is continuous *}
huffman@15565
   136
huffman@37079
   137
lemma cont_id [simp, cont2cont]: "cont (\<lambda>x. x)"
huffman@16624
   138
apply (rule contI)
huffman@26027
   139
apply (erule cpo_lubI)
huffman@15565
   140
done
huffman@15565
   141
huffman@16624
   142
text {* constant functions are continuous *}
huffman@16624
   143
huffman@37079
   144
lemma cont_const [simp, cont2cont]: "cont (\<lambda>x. c)"
huffman@40771
   145
  using is_lub_const by (rule contI)
huffman@15565
   146
huffman@29532
   147
text {* application of functions is continuous *}
huffman@29532
   148
huffman@31041
   149
lemma cont_apply:
huffman@29532
   150
  fixes f :: "'a::cpo \<Rightarrow> 'b::cpo \<Rightarrow> 'c::cpo" and t :: "'a \<Rightarrow> 'b"
huffman@31041
   151
  assumes 1: "cont (\<lambda>x. t x)"
huffman@31041
   152
  assumes 2: "\<And>x. cont (\<lambda>y. f x y)"
huffman@31041
   153
  assumes 3: "\<And>y. cont (\<lambda>x. f x y)"
huffman@29532
   154
  shows "cont (\<lambda>x. (f x) (t x))"
huffman@35914
   155
proof (rule contI2 [OF monofunI])
huffman@29532
   156
  fix x y :: "'a" assume "x \<sqsubseteq> y"
huffman@29532
   157
  then show "f x (t x) \<sqsubseteq> f y (t y)"
huffman@31041
   158
    by (auto intro: cont2monofunE [OF 1]
huffman@31041
   159
                    cont2monofunE [OF 2]
huffman@31041
   160
                    cont2monofunE [OF 3]
huffman@31076
   161
                    below_trans)
huffman@29532
   162
next
huffman@29532
   163
  fix Y :: "nat \<Rightarrow> 'a" assume "chain Y"
huffman@35914
   164
  then show "f (\<Squnion>i. Y i) (t (\<Squnion>i. Y i)) \<sqsubseteq> (\<Squnion>i. f (Y i) (t (Y i)))"
huffman@31041
   165
    by (simp only: cont2contlubE [OF 1] ch2ch_cont [OF 1]
huffman@31041
   166
                   cont2contlubE [OF 2] ch2ch_cont [OF 2]
huffman@31041
   167
                   cont2contlubE [OF 3] ch2ch_cont [OF 3]
huffman@35914
   168
                   diag_lub below_refl)
huffman@29532
   169
qed
huffman@29532
   170
huffman@31041
   171
lemma cont_compose:
huffman@29532
   172
  "\<lbrakk>cont c; cont (\<lambda>x. f x)\<rbrakk> \<Longrightarrow> cont (\<lambda>x. c (f x))"
huffman@31041
   173
by (rule cont_apply [OF _ _ cont_const])
huffman@29532
   174
huffman@40004
   175
text {* Least upper bounds preserve continuity *}
huffman@40004
   176
huffman@40004
   177
lemma cont2cont_lub [simp]:
huffman@40004
   178
  assumes chain: "\<And>x. chain (\<lambda>i. F i x)" and cont: "\<And>i. cont (\<lambda>x. F i x)"
huffman@40004
   179
  shows "cont (\<lambda>x. \<Squnion>i. F i x)"
huffman@40004
   180
apply (rule contI2)
huffman@40004
   181
apply (simp add: monofunI cont2monofunE [OF cont] lub_mono chain)
huffman@40004
   182
apply (simp add: cont2contlubE [OF cont])
huffman@40004
   183
apply (simp add: diag_lub ch2ch_cont [OF cont] chain)
huffman@40004
   184
done
huffman@40004
   185
huffman@16624
   186
text {* if-then-else is continuous *}
huffman@16624
   187
huffman@37099
   188
lemma cont_if [simp, cont2cont]:
huffman@26452
   189
  "\<lbrakk>cont f; cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. if b then f x else g x)"
huffman@16624
   190
by (induct b) simp_all
huffman@16624
   191
huffman@16624
   192
subsection {* Finite chains and flat pcpos *}
huffman@15565
   193
huffman@40010
   194
text {* Monotone functions map finite chains to finite chains. *}
huffman@15565
   195
huffman@16624
   196
lemma monofun_finch2finch:
huffman@16624
   197
  "\<lbrakk>monofun f; finite_chain Y\<rbrakk> \<Longrightarrow> finite_chain (\<lambda>n. f (Y n))"
huffman@16624
   198
apply (unfold finite_chain_def)
huffman@16624
   199
apply (simp add: ch2ch_monofun)
huffman@16624
   200
apply (force simp add: max_in_chain_def)
huffman@15565
   201
done
huffman@15565
   202
huffman@40010
   203
text {* The same holds for continuous functions. *}
huffman@15565
   204
huffman@16624
   205
lemma cont_finch2finch:
huffman@16624
   206
  "\<lbrakk>cont f; finite_chain Y\<rbrakk> \<Longrightarrow> finite_chain (\<lambda>n. f (Y n))"
huffman@16624
   207
by (rule cont2mono [THEN monofun_finch2finch])
huffman@15565
   208
huffman@40010
   209
text {* All monotone functions with chain-finite domain are continuous. *}
huffman@40010
   210
huffman@25825
   211
lemma chfindom_monofun2cont: "monofun f \<Longrightarrow> cont (f::'a::chfin \<Rightarrow> 'b::cpo)"
huffman@35914
   212
apply (erule contI2)
huffman@15565
   213
apply (frule chfin2finch)
huffman@16204
   214
apply (clarsimp simp add: finite_chain_def)
huffman@16204
   215
apply (subgoal_tac "max_in_chain i (\<lambda>i. f (Y i))")
huffman@16204
   216
apply (simp add: maxinch_is_thelub ch2ch_monofun)
huffman@16204
   217
apply (force simp add: max_in_chain_def)
huffman@15565
   218
done
huffman@15565
   219
huffman@40010
   220
text {* All strict functions with flat domain are continuous. *}
huffman@16624
   221
huffman@16624
   222
lemma flatdom_strict2mono: "f \<bottom> = \<bottom> \<Longrightarrow> monofun (f::'a::flat \<Rightarrow> 'b::pcpo)"
huffman@16624
   223
apply (rule monofunI)
huffman@25920
   224
apply (drule ax_flat)
huffman@16624
   225
apply auto
huffman@16624
   226
done
huffman@16624
   227
huffman@16624
   228
lemma flatdom_strict2cont: "f \<bottom> = \<bottom> \<Longrightarrow> cont (f::'a::flat \<Rightarrow> 'b::pcpo)"
huffman@16624
   229
by (rule flatdom_strict2mono [THEN chfindom_monofun2cont])
huffman@15565
   230
huffman@40010
   231
text {* All functions with discrete domain are continuous. *}
huffman@26024
   232
huffman@37079
   233
lemma cont_discrete_cpo [simp, cont2cont]: "cont (f::'a::discrete_cpo \<Rightarrow> 'b::cpo)"
huffman@26024
   234
apply (rule contI)
huffman@26024
   235
apply (drule discrete_chain_const, clarify)
huffman@40771
   236
apply (simp add: is_lub_const)
huffman@26024
   237
done
huffman@26024
   238
nipkow@243
   239
end