src/HOL/HOLCF/Cont.thy
author wenzelm
Sat Nov 04 15:24:40 2017 +0100 (20 months ago)
changeset 67003 49850a679c2c
parent 62175 8ffc4d0e652d
child 67312 0d25e02759b7
permissions -rw-r--r--
more robust sorted_entries;
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
wenzelm@62175
     6
section \<open>Continuity and monotonicity\<close>
huffman@15577
     7
huffman@15577
     8
theory Cont
huffman@25786
     9
imports Pcpo
huffman@15577
    10
begin
nipkow@243
    11
wenzelm@62175
    12
text \<open>
huffman@15588
    13
   Now we change the default class! Form now on all untyped type variables are
slotosch@3323
    14
   of default class po
wenzelm@62175
    15
\<close>
nipkow@243
    16
wenzelm@36452
    17
default_sort po
nipkow@243
    18
wenzelm@62175
    19
subsection \<open>Definitions\<close>
nipkow@243
    20
wenzelm@25131
    21
definition
wenzelm@62175
    22
  monofun :: "('a \<Rightarrow> 'b) \<Rightarrow> bool"  \<comment> "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
wenzelm@62175
    47
subsection \<open>Equivalence of alternate definition\<close>
huffman@16624
    48
wenzelm@62175
    49
text \<open>monotone functions map chains to chains\<close>
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
wenzelm@62175
    57
text \<open>monotone functions map upper bound to upper bounds\<close>
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
wenzelm@62175
    66
text \<open>a lemma about binary chains\<close>
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
wenzelm@62175
    78
text \<open>continuity implies monotonicity\<close>
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
wenzelm@62175
    91
text \<open>continuity implies preservation of lubs\<close>
huffman@15565
    92
huffman@35914
    93
lemma cont2contlubE:
wenzelm@60585
    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
wenzelm@62175
   121
subsection \<open>Collection of continuity rules\<close>
huffman@29530
   122
wenzelm@57945
   123
named_theorems cont2cont "continuity intro rule"
huffman@29530
   124
huffman@29530
   125
wenzelm@62175
   126
subsection \<open>Continuity of basic functions\<close>
huffman@16624
   127
wenzelm@62175
   128
text \<open>The identity function is continuous\<close>
huffman@15565
   129
huffman@37079
   130
lemma cont_id [simp, cont2cont]: "cont (\<lambda>x. x)"
huffman@16624
   131
apply (rule contI)
huffman@26027
   132
apply (erule cpo_lubI)
huffman@15565
   133
done
huffman@15565
   134
wenzelm@62175
   135
text \<open>constant functions are continuous\<close>
huffman@16624
   136
huffman@37079
   137
lemma cont_const [simp, cont2cont]: "cont (\<lambda>x. c)"
huffman@40771
   138
  using is_lub_const by (rule contI)
huffman@15565
   139
wenzelm@62175
   140
text \<open>application of functions is continuous\<close>
huffman@29532
   141
huffman@31041
   142
lemma cont_apply:
huffman@29532
   143
  fixes f :: "'a::cpo \<Rightarrow> 'b::cpo \<Rightarrow> 'c::cpo" and t :: "'a \<Rightarrow> 'b"
huffman@31041
   144
  assumes 1: "cont (\<lambda>x. t x)"
huffman@31041
   145
  assumes 2: "\<And>x. cont (\<lambda>y. f x y)"
huffman@31041
   146
  assumes 3: "\<And>y. cont (\<lambda>x. f x y)"
huffman@29532
   147
  shows "cont (\<lambda>x. (f x) (t x))"
huffman@35914
   148
proof (rule contI2 [OF monofunI])
huffman@29532
   149
  fix x y :: "'a" assume "x \<sqsubseteq> y"
huffman@29532
   150
  then show "f x (t x) \<sqsubseteq> f y (t y)"
huffman@31041
   151
    by (auto intro: cont2monofunE [OF 1]
huffman@31041
   152
                    cont2monofunE [OF 2]
huffman@31041
   153
                    cont2monofunE [OF 3]
huffman@31076
   154
                    below_trans)
huffman@29532
   155
next
huffman@29532
   156
  fix Y :: "nat \<Rightarrow> 'a" assume "chain Y"
huffman@35914
   157
  then show "f (\<Squnion>i. Y i) (t (\<Squnion>i. Y i)) \<sqsubseteq> (\<Squnion>i. f (Y i) (t (Y i)))"
huffman@31041
   158
    by (simp only: cont2contlubE [OF 1] ch2ch_cont [OF 1]
huffman@31041
   159
                   cont2contlubE [OF 2] ch2ch_cont [OF 2]
huffman@31041
   160
                   cont2contlubE [OF 3] ch2ch_cont [OF 3]
huffman@35914
   161
                   diag_lub below_refl)
huffman@29532
   162
qed
huffman@29532
   163
huffman@31041
   164
lemma cont_compose:
huffman@29532
   165
  "\<lbrakk>cont c; cont (\<lambda>x. f x)\<rbrakk> \<Longrightarrow> cont (\<lambda>x. c (f x))"
huffman@31041
   166
by (rule cont_apply [OF _ _ cont_const])
huffman@29532
   167
wenzelm@62175
   168
text \<open>Least upper bounds preserve continuity\<close>
huffman@40004
   169
huffman@40004
   170
lemma cont2cont_lub [simp]:
huffman@40004
   171
  assumes chain: "\<And>x. chain (\<lambda>i. F i x)" and cont: "\<And>i. cont (\<lambda>x. F i x)"
huffman@40004
   172
  shows "cont (\<lambda>x. \<Squnion>i. F i x)"
huffman@40004
   173
apply (rule contI2)
huffman@40004
   174
apply (simp add: monofunI cont2monofunE [OF cont] lub_mono chain)
huffman@40004
   175
apply (simp add: cont2contlubE [OF cont])
huffman@40004
   176
apply (simp add: diag_lub ch2ch_cont [OF cont] chain)
huffman@40004
   177
done
huffman@40004
   178
wenzelm@62175
   179
text \<open>if-then-else is continuous\<close>
huffman@16624
   180
huffman@37099
   181
lemma cont_if [simp, cont2cont]:
huffman@26452
   182
  "\<lbrakk>cont f; cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. if b then f x else g x)"
huffman@16624
   183
by (induct b) simp_all
huffman@16624
   184
wenzelm@62175
   185
subsection \<open>Finite chains and flat pcpos\<close>
huffman@15565
   186
wenzelm@62175
   187
text \<open>Monotone functions map finite chains to finite chains.\<close>
huffman@15565
   188
huffman@16624
   189
lemma monofun_finch2finch:
huffman@16624
   190
  "\<lbrakk>monofun f; finite_chain Y\<rbrakk> \<Longrightarrow> finite_chain (\<lambda>n. f (Y n))"
huffman@16624
   191
apply (unfold finite_chain_def)
huffman@16624
   192
apply (simp add: ch2ch_monofun)
huffman@16624
   193
apply (force simp add: max_in_chain_def)
huffman@15565
   194
done
huffman@15565
   195
wenzelm@62175
   196
text \<open>The same holds for continuous functions.\<close>
huffman@15565
   197
huffman@16624
   198
lemma cont_finch2finch:
huffman@16624
   199
  "\<lbrakk>cont f; finite_chain Y\<rbrakk> \<Longrightarrow> finite_chain (\<lambda>n. f (Y n))"
huffman@16624
   200
by (rule cont2mono [THEN monofun_finch2finch])
huffman@15565
   201
wenzelm@62175
   202
text \<open>All monotone functions with chain-finite domain are continuous.\<close>
huffman@40010
   203
huffman@25825
   204
lemma chfindom_monofun2cont: "monofun f \<Longrightarrow> cont (f::'a::chfin \<Rightarrow> 'b::cpo)"
huffman@35914
   205
apply (erule contI2)
huffman@15565
   206
apply (frule chfin2finch)
huffman@16204
   207
apply (clarsimp simp add: finite_chain_def)
huffman@16204
   208
apply (subgoal_tac "max_in_chain i (\<lambda>i. f (Y i))")
huffman@16204
   209
apply (simp add: maxinch_is_thelub ch2ch_monofun)
huffman@16204
   210
apply (force simp add: max_in_chain_def)
huffman@15565
   211
done
huffman@15565
   212
wenzelm@62175
   213
text \<open>All strict functions with flat domain are continuous.\<close>
huffman@16624
   214
huffman@16624
   215
lemma flatdom_strict2mono: "f \<bottom> = \<bottom> \<Longrightarrow> monofun (f::'a::flat \<Rightarrow> 'b::pcpo)"
huffman@16624
   216
apply (rule monofunI)
huffman@25920
   217
apply (drule ax_flat)
huffman@16624
   218
apply auto
huffman@16624
   219
done
huffman@16624
   220
huffman@16624
   221
lemma flatdom_strict2cont: "f \<bottom> = \<bottom> \<Longrightarrow> cont (f::'a::flat \<Rightarrow> 'b::pcpo)"
huffman@16624
   222
by (rule flatdom_strict2mono [THEN chfindom_monofun2cont])
huffman@15565
   223
wenzelm@62175
   224
text \<open>All functions with discrete domain are continuous.\<close>
huffman@26024
   225
huffman@37079
   226
lemma cont_discrete_cpo [simp, cont2cont]: "cont (f::'a::discrete_cpo \<Rightarrow> 'b::cpo)"
huffman@26024
   227
apply (rule contI)
huffman@26024
   228
apply (drule discrete_chain_const, clarify)
huffman@40771
   229
apply (simp add: is_lub_const)
huffman@26024
   230
done
huffman@26024
   231
nipkow@243
   232
end