src/HOLCF/Cont.thy
author wenzelm
Thu Jul 02 17:34:14 2009 +0200 (2009-07-02)
changeset 31902 862ae16a799d
parent 31076 99fe356cbbc2
child 35794 8cd7134275cc
permissions -rw-r--r--
renamed NamedThmsFun to Named_Thms;
simplified/unified names of instances of Named_Thms;
huffman@15600
     1
(*  Title:      HOLCF/Cont.thy
clasohm@1479
     2
    Author:     Franz Regensburger
nipkow@243
     3
*)
nipkow@243
     4
huffman@15577
     5
header {* Continuity and monotonicity *}
huffman@15577
     6
huffman@15577
     7
theory Cont
huffman@25786
     8
imports Pcpo
huffman@15577
     9
begin
nipkow@243
    10
huffman@15588
    11
text {*
huffman@15588
    12
   Now we change the default class! Form now on all untyped type variables are
slotosch@3323
    13
   of default class po
huffman@15588
    14
*}
nipkow@243
    15
huffman@15565
    16
defaultsort po
nipkow@243
    17
huffman@16624
    18
subsection {* Definitions *}
nipkow@243
    19
wenzelm@25131
    20
definition
wenzelm@25131
    21
  monofun :: "('a \<Rightarrow> 'b) \<Rightarrow> bool"  -- "monotonicity"  where
wenzelm@25131
    22
  "monofun f = (\<forall>x y. x \<sqsubseteq> y \<longrightarrow> f x \<sqsubseteq> f y)"
nipkow@243
    23
wenzelm@25131
    24
definition
wenzelm@25131
    25
  contlub :: "('a::cpo \<Rightarrow> 'b::cpo) \<Rightarrow> bool"  -- "first cont. def" where
wenzelm@25131
    26
  "contlub f = (\<forall>Y. chain Y \<longrightarrow> f (\<Squnion>i. Y i) = (\<Squnion>i. f (Y i)))"
nipkow@243
    27
wenzelm@25131
    28
definition
wenzelm@25131
    29
  cont :: "('a::cpo \<Rightarrow> 'b::cpo) \<Rightarrow> bool"  -- "secnd cont. def" where
wenzelm@25131
    30
  "cont f = (\<forall>Y. chain Y \<longrightarrow> range (\<lambda>i. f (Y i)) <<| f (\<Squnion>i. Y i))"
huffman@15565
    31
huffman@15565
    32
lemma contlubI:
huffman@16204
    33
  "\<lbrakk>\<And>Y. chain Y \<Longrightarrow> f (\<Squnion>i. Y i) = (\<Squnion>i. f (Y i))\<rbrakk> \<Longrightarrow> contlub f"
huffman@16204
    34
by (simp add: contlub_def)
huffman@15565
    35
huffman@15565
    36
lemma contlubE: 
huffman@16204
    37
  "\<lbrakk>contlub f; chain Y\<rbrakk> \<Longrightarrow> f (\<Squnion>i. Y i) = (\<Squnion>i. f (Y i))" 
huffman@16204
    38
by (simp add: contlub_def)
huffman@15565
    39
huffman@16204
    40
lemma contI:
huffman@16204
    41
  "\<lbrakk>\<And>Y. chain Y \<Longrightarrow> range (\<lambda>i. f (Y i)) <<| f (\<Squnion>i. Y i)\<rbrakk> \<Longrightarrow> cont f"
huffman@16204
    42
by (simp add: cont_def)
huffman@15565
    43
huffman@16204
    44
lemma contE:
huffman@16204
    45
  "\<lbrakk>cont f; chain Y\<rbrakk> \<Longrightarrow> range (\<lambda>i. f (Y i)) <<| f (\<Squnion>i. Y i)"
huffman@16204
    46
by (simp add: cont_def)
huffman@15565
    47
huffman@15565
    48
lemma monofunI: 
huffman@16204
    49
  "\<lbrakk>\<And>x y. x \<sqsubseteq> y \<Longrightarrow> f x \<sqsubseteq> f y\<rbrakk> \<Longrightarrow> monofun f"
huffman@16204
    50
by (simp add: monofun_def)
huffman@15565
    51
huffman@15565
    52
lemma monofunE: 
huffman@16204
    53
  "\<lbrakk>monofun f; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> f x \<sqsubseteq> f y"
huffman@16204
    54
by (simp add: monofun_def)
huffman@15565
    55
huffman@16624
    56
huffman@16624
    57
subsection {* @{prop "monofun f \<and> contlub f \<equiv> cont f"} *}
huffman@16624
    58
huffman@15588
    59
text {* monotone functions map chains to chains *}
huffman@15565
    60
huffman@16204
    61
lemma ch2ch_monofun: "\<lbrakk>monofun f; chain Y\<rbrakk> \<Longrightarrow> chain (\<lambda>i. f (Y i))"
huffman@15565
    62
apply (rule chainI)
huffman@16204
    63
apply (erule monofunE)
huffman@15565
    64
apply (erule chainE)
huffman@15565
    65
done
huffman@15565
    66
huffman@15588
    67
text {* monotone functions map upper bound to upper bounds *}
huffman@15565
    68
huffman@15565
    69
lemma ub2ub_monofun: 
huffman@16204
    70
  "\<lbrakk>monofun f; range Y <| u\<rbrakk> \<Longrightarrow> range (\<lambda>i. f (Y i)) <| f u"
huffman@15565
    71
apply (rule ub_rangeI)
huffman@16204
    72
apply (erule monofunE)
huffman@15565
    73
apply (erule ub_rangeD)
huffman@15565
    74
done
huffman@15565
    75
huffman@16624
    76
text {* left to right: @{prop "monofun f \<and> contlub f \<Longrightarrow> cont f"} *}
huffman@15565
    77
huffman@16204
    78
lemma monocontlub2cont: "\<lbrakk>monofun f; contlub f\<rbrakk> \<Longrightarrow> cont f"
huffman@16204
    79
apply (rule contI)
huffman@15565
    80
apply (rule thelubE)
huffman@18088
    81
apply (erule (1) ch2ch_monofun)
huffman@18088
    82
apply (erule (1) contlubE [symmetric])
huffman@15565
    83
done
huffman@15565
    84
huffman@15588
    85
text {* first a lemma about binary chains *}
huffman@15565
    86
huffman@16204
    87
lemma binchain_cont:
huffman@16204
    88
  "\<lbrakk>cont f; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> range (\<lambda>i::nat. f (if i = 0 then x else y)) <<| f y"
huffman@16204
    89
apply (subgoal_tac "f (\<Squnion>i::nat. if i = 0 then x else y) = f y")
huffman@16204
    90
apply (erule subst)
huffman@16204
    91
apply (erule contE)
huffman@15565
    92
apply (erule bin_chain)
huffman@16204
    93
apply (rule_tac f=f in arg_cong)
huffman@15565
    94
apply (erule lub_bin_chain [THEN thelubI])
huffman@15565
    95
done
huffman@15565
    96
huffman@16204
    97
text {* right to left: @{prop "cont f \<Longrightarrow> monofun f \<and> contlub f"} *}
huffman@16204
    98
text {* part1: @{prop "cont f \<Longrightarrow> monofun f"} *}
huffman@15565
    99
huffman@16204
   100
lemma cont2mono: "cont f \<Longrightarrow> monofun f"
huffman@16204
   101
apply (rule monofunI)
huffman@18088
   102
apply (drule (1) binchain_cont)
huffman@16204
   103
apply (drule_tac i=0 in is_ub_lub)
huffman@16204
   104
apply simp
huffman@15565
   105
done
huffman@15565
   106
huffman@29532
   107
lemmas cont2monofunE = cont2mono [THEN monofunE]
huffman@29532
   108
huffman@16737
   109
lemmas ch2ch_cont = cont2mono [THEN ch2ch_monofun]
huffman@16737
   110
huffman@16204
   111
text {* right to left: @{prop "cont f \<Longrightarrow> monofun f \<and> contlub f"} *}
huffman@16204
   112
text {* part2: @{prop "cont f \<Longrightarrow> contlub f"} *}
huffman@15565
   113
huffman@16624
   114
lemma cont2contlub: "cont f \<Longrightarrow> contlub f"
huffman@16204
   115
apply (rule contlubI)
huffman@15565
   116
apply (rule thelubI [symmetric])
huffman@18088
   117
apply (erule (1) contE)
huffman@15565
   118
done
huffman@15565
   119
huffman@16737
   120
lemmas cont2contlubE = cont2contlub [THEN contlubE]
huffman@16737
   121
huffman@25896
   122
lemma contI2:
huffman@25896
   123
  assumes mono: "monofun f"
huffman@31076
   124
  assumes below: "\<And>Y. \<lbrakk>chain Y; chain (\<lambda>i. f (Y i))\<rbrakk>
huffman@27413
   125
     \<Longrightarrow> f (\<Squnion>i. Y i) \<sqsubseteq> (\<Squnion>i. f (Y i))"
huffman@25896
   126
  shows "cont f"
huffman@25896
   127
apply (rule monocontlub2cont)
huffman@25896
   128
apply (rule mono)
huffman@25896
   129
apply (rule contlubI)
huffman@31076
   130
apply (rule below_antisym)
huffman@31076
   131
apply (rule below, assumption)
huffman@25896
   132
apply (erule ch2ch_monofun [OF mono])
huffman@25896
   133
apply (rule is_lub_thelub)
huffman@25896
   134
apply (erule ch2ch_monofun [OF mono])
huffman@25896
   135
apply (rule ub2ub_monofun [OF mono])
huffman@25896
   136
apply (rule is_lubD1)
huffman@26027
   137
apply (erule cpo_lubI)
huffman@25896
   138
done
huffman@25896
   139
huffman@29530
   140
subsection {* Continuity simproc *}
huffman@29530
   141
huffman@29530
   142
ML {*
wenzelm@31902
   143
structure Cont2ContData = Named_Thms
wenzelm@31902
   144
(
wenzelm@31902
   145
  val name = "cont2cont"
wenzelm@31902
   146
  val description = "continuity intro rule"
wenzelm@31902
   147
)
huffman@29530
   148
*}
huffman@29530
   149
huffman@31030
   150
setup Cont2ContData.setup
huffman@29530
   151
huffman@29530
   152
text {*
huffman@29530
   153
  Given the term @{term "cont f"}, the procedure tries to construct the
huffman@29530
   154
  theorem @{term "cont f == True"}. If this theorem cannot be completely
huffman@29530
   155
  solved by the introduction rules, then the procedure returns a
huffman@29530
   156
  conditional rewrite rule with the unsolved subgoals as premises.
huffman@29530
   157
*}
huffman@29530
   158
huffman@31030
   159
simproc_setup cont_proc ("cont f") = {*
huffman@31030
   160
  fn phi => fn ss => fn ct =>
huffman@29530
   161
    let
huffman@31030
   162
      val tr = instantiate' [] [SOME ct] @{thm Eq_TrueI};
huffman@29530
   163
      val rules = Cont2ContData.get (Simplifier.the_context ss);
huffman@29541
   164
      val tac = REPEAT_ALL_NEW (match_tac rules);
huffman@31030
   165
    in SINGLE (tac 1) tr end
huffman@29530
   166
*}
huffman@29530
   167
huffman@16624
   168
subsection {* Continuity of basic functions *}
huffman@16624
   169
huffman@16624
   170
text {* The identity function is continuous *}
huffman@15565
   171
huffman@29530
   172
lemma cont_id [cont2cont]: "cont (\<lambda>x. x)"
huffman@16624
   173
apply (rule contI)
huffman@26027
   174
apply (erule cpo_lubI)
huffman@15565
   175
done
huffman@15565
   176
huffman@16624
   177
text {* constant functions are continuous *}
huffman@16624
   178
huffman@29530
   179
lemma cont_const [cont2cont]: "cont (\<lambda>x. c)"
huffman@16624
   180
apply (rule contI)
huffman@16624
   181
apply (rule lub_const)
huffman@16624
   182
done
huffman@15565
   183
huffman@29532
   184
text {* application of functions is continuous *}
huffman@29532
   185
huffman@31041
   186
lemma cont_apply:
huffman@29532
   187
  fixes f :: "'a::cpo \<Rightarrow> 'b::cpo \<Rightarrow> 'c::cpo" and t :: "'a \<Rightarrow> 'b"
huffman@31041
   188
  assumes 1: "cont (\<lambda>x. t x)"
huffman@31041
   189
  assumes 2: "\<And>x. cont (\<lambda>y. f x y)"
huffman@31041
   190
  assumes 3: "\<And>y. cont (\<lambda>x. f x y)"
huffman@29532
   191
  shows "cont (\<lambda>x. (f x) (t x))"
huffman@29532
   192
proof (rule monocontlub2cont [OF monofunI contlubI])
huffman@29532
   193
  fix x y :: "'a" assume "x \<sqsubseteq> y"
huffman@29532
   194
  then show "f x (t x) \<sqsubseteq> f y (t y)"
huffman@31041
   195
    by (auto intro: cont2monofunE [OF 1]
huffman@31041
   196
                    cont2monofunE [OF 2]
huffman@31041
   197
                    cont2monofunE [OF 3]
huffman@31076
   198
                    below_trans)
huffman@29532
   199
next
huffman@29532
   200
  fix Y :: "nat \<Rightarrow> 'a" assume "chain Y"
huffman@29532
   201
  then show "f (\<Squnion>i. Y i) (t (\<Squnion>i. Y i)) = (\<Squnion>i. f (Y i) (t (Y i)))"
huffman@31041
   202
    by (simp only: cont2contlubE [OF 1] ch2ch_cont [OF 1]
huffman@31041
   203
                   cont2contlubE [OF 2] ch2ch_cont [OF 2]
huffman@31041
   204
                   cont2contlubE [OF 3] ch2ch_cont [OF 3]
huffman@29532
   205
                   diag_lub)
huffman@29532
   206
qed
huffman@29532
   207
huffman@31041
   208
lemma cont_compose:
huffman@29532
   209
  "\<lbrakk>cont c; cont (\<lambda>x. f x)\<rbrakk> \<Longrightarrow> cont (\<lambda>x. c (f x))"
huffman@31041
   210
by (rule cont_apply [OF _ _ cont_const])
huffman@29532
   211
huffman@16624
   212
text {* if-then-else is continuous *}
huffman@16624
   213
huffman@26452
   214
lemma cont_if [simp]:
huffman@26452
   215
  "\<lbrakk>cont f; cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. if b then f x else g x)"
huffman@16624
   216
by (induct b) simp_all
huffman@16624
   217
huffman@16624
   218
subsection {* Finite chains and flat pcpos *}
huffman@15565
   219
huffman@16624
   220
text {* monotone functions map finite chains to finite chains *}
huffman@15565
   221
huffman@16624
   222
lemma monofun_finch2finch:
huffman@16624
   223
  "\<lbrakk>monofun f; finite_chain Y\<rbrakk> \<Longrightarrow> finite_chain (\<lambda>n. f (Y n))"
huffman@16624
   224
apply (unfold finite_chain_def)
huffman@16624
   225
apply (simp add: ch2ch_monofun)
huffman@16624
   226
apply (force simp add: max_in_chain_def)
huffman@15565
   227
done
huffman@15565
   228
huffman@16624
   229
text {* The same holds for continuous functions *}
huffman@15565
   230
huffman@16624
   231
lemma cont_finch2finch:
huffman@16624
   232
  "\<lbrakk>cont f; finite_chain Y\<rbrakk> \<Longrightarrow> finite_chain (\<lambda>n. f (Y n))"
huffman@16624
   233
by (rule cont2mono [THEN monofun_finch2finch])
huffman@15565
   234
huffman@25825
   235
lemma chfindom_monofun2cont: "monofun f \<Longrightarrow> cont (f::'a::chfin \<Rightarrow> 'b::cpo)"
huffman@15565
   236
apply (rule monocontlub2cont)
huffman@15565
   237
apply assumption
huffman@16204
   238
apply (rule contlubI)
huffman@15565
   239
apply (frule chfin2finch)
huffman@16204
   240
apply (clarsimp simp add: finite_chain_def)
huffman@16204
   241
apply (subgoal_tac "max_in_chain i (\<lambda>i. f (Y i))")
huffman@16204
   242
apply (simp add: maxinch_is_thelub ch2ch_monofun)
huffman@16204
   243
apply (force simp add: max_in_chain_def)
huffman@15565
   244
done
huffman@15565
   245
huffman@16624
   246
text {* some properties of flat *}
huffman@16624
   247
huffman@16624
   248
lemma flatdom_strict2mono: "f \<bottom> = \<bottom> \<Longrightarrow> monofun (f::'a::flat \<Rightarrow> 'b::pcpo)"
huffman@16624
   249
apply (rule monofunI)
huffman@25920
   250
apply (drule ax_flat)
huffman@16624
   251
apply auto
huffman@16624
   252
done
huffman@16624
   253
huffman@16624
   254
lemma flatdom_strict2cont: "f \<bottom> = \<bottom> \<Longrightarrow> cont (f::'a::flat \<Rightarrow> 'b::pcpo)"
huffman@16624
   255
by (rule flatdom_strict2mono [THEN chfindom_monofun2cont])
huffman@15565
   256
huffman@26024
   257
text {* functions with discrete domain *}
huffman@26024
   258
huffman@26024
   259
lemma cont_discrete_cpo [simp]: "cont (f::'a::discrete_cpo \<Rightarrow> 'b::cpo)"
huffman@26024
   260
apply (rule contI)
huffman@26024
   261
apply (drule discrete_chain_const, clarify)
huffman@26024
   262
apply (simp add: lub_const)
huffman@26024
   263
done
huffman@26024
   264
nipkow@243
   265
end