src/HOLCF/Up.thy
author huffman
Wed Jan 02 20:23:49 2008 +0100 (2008-01-02)
changeset 25789 c0506ac5b6b4
parent 25788 30cbe0764599
child 25827 c2adeb1bae5c
permissions -rw-r--r--
add dcpo instance proof
huffman@15599
     1
(*  Title:      HOLCF/Up.thy
huffman@15576
     2
    ID:         $Id$
wenzelm@16070
     3
    Author:     Franz Regensburger and Brian Huffman
huffman@15576
     4
huffman@15576
     5
Lifting.
huffman@15576
     6
*)
huffman@15576
     7
huffman@15576
     8
header {* The type of lifted values *}
huffman@15576
     9
huffman@15577
    10
theory Up
huffman@19105
    11
imports Cfun
huffman@15577
    12
begin
huffman@15576
    13
huffman@15599
    14
defaultsort cpo
huffman@15599
    15
huffman@15593
    16
subsection {* Definition of new type for lifting *}
huffman@15576
    17
huffman@16753
    18
datatype 'a u = Ibottom | Iup 'a
huffman@15576
    19
huffman@18290
    20
syntax (xsymbols)
huffman@18290
    21
  "u" :: "type \<Rightarrow> type" ("(_\<^sub>\<bottom>)" [1000] 999)
huffman@18290
    22
huffman@15576
    23
consts
huffman@16753
    24
  Ifup :: "('a \<rightarrow> 'b::pcpo) \<Rightarrow> 'a u \<Rightarrow> 'b"
huffman@15576
    25
huffman@16753
    26
primrec
huffman@16753
    27
  "Ifup f Ibottom = \<bottom>"
huffman@16753
    28
  "Ifup f (Iup x) = f\<cdot>x"
huffman@15576
    29
huffman@18290
    30
subsection {* Ordering on lifted cpo *}
huffman@15593
    31
huffman@25787
    32
instantiation u :: (cpo) sq_ord
huffman@25787
    33
begin
huffman@15576
    34
huffman@25787
    35
definition
huffman@16753
    36
  less_up_def:
huffman@16753
    37
    "(op \<sqsubseteq>) \<equiv> (\<lambda>x y. case x of Ibottom \<Rightarrow> True | Iup a \<Rightarrow>
huffman@16753
    38
      (case y of Ibottom \<Rightarrow> False | Iup b \<Rightarrow> a \<sqsubseteq> b))"
huffman@15576
    39
huffman@25787
    40
instance ..
huffman@25787
    41
end
huffman@25787
    42
huffman@16753
    43
lemma minimal_up [iff]: "Ibottom \<sqsubseteq> z"
huffman@16753
    44
by (simp add: less_up_def)
huffman@15576
    45
huffman@16753
    46
lemma not_Iup_less [iff]: "\<not> Iup x \<sqsubseteq> Ibottom"
huffman@16753
    47
by (simp add: less_up_def)
huffman@15576
    48
huffman@16319
    49
lemma Iup_less [iff]: "(Iup x \<sqsubseteq> Iup y) = (x \<sqsubseteq> y)"
huffman@16753
    50
by (simp add: less_up_def)
huffman@15576
    51
huffman@18290
    52
subsection {* Lifted cpo is a partial order *}
huffman@15576
    53
huffman@15599
    54
instance u :: (cpo) po
huffman@25787
    55
proof
huffman@25787
    56
  fix x :: "'a u"
huffman@25787
    57
  show "x \<sqsubseteq> x"
huffman@25787
    58
    unfolding less_up_def by (simp split: u.split)
huffman@25787
    59
next
huffman@25787
    60
  fix x y :: "'a u"
huffman@25787
    61
  assume "x \<sqsubseteq> y" "y \<sqsubseteq> x" thus "x = y"
huffman@25787
    62
    unfolding less_up_def
huffman@25787
    63
    by (auto split: u.split_asm intro: antisym_less)
huffman@25787
    64
next
huffman@25787
    65
  fix x y z :: "'a u"
huffman@25787
    66
  assume "x \<sqsubseteq> y" "y \<sqsubseteq> z" thus "x \<sqsubseteq> z"
huffman@25787
    67
    unfolding less_up_def
huffman@25787
    68
    by (auto split: u.split_asm intro: trans_less)
huffman@25787
    69
qed
huffman@15576
    70
huffman@18290
    71
subsection {* Lifted cpo is a cpo *}
huffman@15593
    72
huffman@16319
    73
lemma is_lub_Iup:
huffman@16319
    74
  "range S <<| x \<Longrightarrow> range (\<lambda>i. Iup (S i)) <<| Iup x"
huffman@15576
    75
apply (rule is_lubI)
huffman@15576
    76
apply (rule ub_rangeI)
huffman@16319
    77
apply (subst Iup_less)
huffman@16319
    78
apply (erule is_ub_lub)
huffman@16753
    79
apply (case_tac u)
huffman@16319
    80
apply (drule ub_rangeD)
huffman@16319
    81
apply simp
huffman@16319
    82
apply simp
huffman@16319
    83
apply (erule is_lub_lub)
huffman@15576
    84
apply (rule ub_rangeI)
huffman@16319
    85
apply (drule_tac i=i in ub_rangeD)
huffman@15593
    86
apply simp
huffman@15599
    87
done
huffman@15599
    88
huffman@25789
    89
lemma is_lub_Iup': "\<lbrakk>directed S; S <<| x\<rbrakk> \<Longrightarrow> (Iup ` S) <<| Iup x"
huffman@25789
    90
apply (rule is_lubI)
huffman@25789
    91
apply (rule ub_imageI)
huffman@25789
    92
apply (subst Iup_less)
huffman@25789
    93
apply (erule (1) is_ubD [OF is_lubD1])
huffman@25789
    94
apply (case_tac u)
huffman@25789
    95
apply (drule directedD1, erule exE)
huffman@25789
    96
apply (drule (1) ub_imageD)
huffman@25789
    97
apply simp
huffman@25789
    98
apply simp
huffman@25789
    99
apply (erule is_lub_lub)
huffman@25789
   100
apply (rule is_ubI)
huffman@25789
   101
apply (drule (1) ub_imageD)
huffman@25789
   102
apply simp
huffman@25789
   103
done
huffman@25789
   104
huffman@15599
   105
text {* Now some lemmas about chains of @{typ "'a u"} elements *}
huffman@15599
   106
huffman@16753
   107
lemma up_lemma1: "z \<noteq> Ibottom \<Longrightarrow> Iup (THE a. Iup a = z) = z"
huffman@16753
   108
by (case_tac z, simp_all)
huffman@16319
   109
huffman@16319
   110
lemma up_lemma2:
huffman@16753
   111
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> Y (i + j) \<noteq> Ibottom"
huffman@16319
   112
apply (erule contrapos_nn)
huffman@15599
   113
apply (drule_tac x="j" and y="i + j" in chain_mono3)
huffman@15599
   114
apply (rule le_add2)
huffman@16753
   115
apply (case_tac "Y j")
huffman@16319
   116
apply assumption
huffman@16319
   117
apply simp
huffman@15599
   118
done
huffman@15599
   119
huffman@16319
   120
lemma up_lemma3:
huffman@16753
   121
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> Iup (THE a. Iup a = Y (i + j)) = Y (i + j)"
huffman@16319
   122
by (rule up_lemma1 [OF up_lemma2])
huffman@15599
   123
huffman@16319
   124
lemma up_lemma4:
huffman@16753
   125
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> chain (\<lambda>i. THE a. Iup a = Y (i + j))"
huffman@15599
   126
apply (rule chainI)
huffman@16319
   127
apply (rule Iup_less [THEN iffD1])
huffman@16319
   128
apply (subst up_lemma3, assumption+)+
huffman@15599
   129
apply (simp add: chainE)
huffman@15599
   130
done
huffman@15599
   131
huffman@16319
   132
lemma up_lemma5:
huffman@16753
   133
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow>
huffman@16319
   134
    (\<lambda>i. Y (i + j)) = (\<lambda>i. Iup (THE a. Iup a = Y (i + j)))"
huffman@16319
   135
by (rule ext, rule up_lemma3 [symmetric])
huffman@15599
   136
huffman@16319
   137
lemma up_lemma6:
wenzelm@25131
   138
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk>
huffman@16319
   139
      \<Longrightarrow> range Y <<| Iup (\<Squnion>i. THE a. Iup a = Y(i + j))"
wenzelm@16933
   140
apply (rule_tac j1 = j in is_lub_range_shift [THEN iffD1])
huffman@16319
   141
apply assumption
huffman@16319
   142
apply (subst up_lemma5, assumption+)
huffman@16319
   143
apply (rule is_lub_Iup)
huffman@16319
   144
apply (rule thelubE [OF _ refl])
huffman@16753
   145
apply (erule (1) up_lemma4)
huffman@15599
   146
done
huffman@15599
   147
huffman@17838
   148
lemma up_chain_lemma:
huffman@16319
   149
  "chain Y \<Longrightarrow>
huffman@16319
   150
   (\<exists>A. chain A \<and> lub (range Y) = Iup (lub (range A)) \<and>
huffman@16753
   151
   (\<exists>j. \<forall>i. Y (i + j) = Iup (A i))) \<or> (Y = (\<lambda>i. Ibottom))"
huffman@16319
   152
apply (rule disjCI)
huffman@16319
   153
apply (simp add: expand_fun_eq)
huffman@16319
   154
apply (erule exE, rename_tac j)
huffman@16319
   155
apply (rule_tac x="\<lambda>i. THE a. Iup a = Y (i + j)" in exI)
huffman@16319
   156
apply (simp add: up_lemma4)
huffman@16319
   157
apply (simp add: up_lemma6 [THEN thelubI])
huffman@16319
   158
apply (rule_tac x=j in exI)
huffman@16319
   159
apply (simp add: up_lemma3)
huffman@15599
   160
done
huffman@15599
   161
huffman@16319
   162
lemma cpo_up: "chain (Y::nat \<Rightarrow> 'a u) \<Longrightarrow> \<exists>x. range Y <<| x"
huffman@17838
   163
apply (frule up_chain_lemma, safe)
huffman@16319
   164
apply (rule_tac x="Iup (lub (range A))" in exI)
huffman@17838
   165
apply (erule_tac j="j" in is_lub_range_shift [THEN iffD1, standard])
huffman@16319
   166
apply (simp add: is_lub_Iup thelubE)
huffman@17585
   167
apply (rule exI, rule lub_const)
huffman@15576
   168
done
huffman@15576
   169
huffman@15599
   170
instance u :: (cpo) cpo
huffman@15593
   171
by intro_classes (rule cpo_up)
huffman@15593
   172
huffman@25789
   173
lemma up_directed_lemma:
huffman@25789
   174
  "directed (S::'a::dcpo u set) \<Longrightarrow>
huffman@25789
   175
    (directed (Iup -` S) \<and> S <<| Iup (lub (Iup -` S))) \<or>
huffman@25789
   176
    S = {Ibottom}"
huffman@25789
   177
apply (case_tac "\<exists>x. Iup x \<in> S")
huffman@25789
   178
apply (rule disjI1)
huffman@25789
   179
apply (subgoal_tac "directed (Iup -` S)")
huffman@25789
   180
apply (rule conjI, assumption)
huffman@25789
   181
apply (rule is_lubI)
huffman@25789
   182
apply (rule is_ubI)
huffman@25789
   183
apply (case_tac x, simp, simp)
huffman@25789
   184
apply (erule is_ub_thelub', simp)
huffman@25789
   185
apply (case_tac u)
huffman@25789
   186
apply (erule exE)
huffman@25789
   187
apply (drule (1) is_ubD)
huffman@25789
   188
apply simp
huffman@25789
   189
apply simp
huffman@25789
   190
apply (erule is_lub_thelub')
huffman@25789
   191
apply (rule is_ubI, simp)
huffman@25789
   192
apply (drule (1) is_ubD, simp)
huffman@25789
   193
apply (rule directedI)
huffman@25789
   194
apply (erule exE)
huffman@25789
   195
apply (rule exI)
huffman@25789
   196
apply (erule vimageI2)
huffman@25789
   197
apply simp
huffman@25789
   198
apply (drule_tac x="Iup x" and y="Iup y" in directedD2, assumption+)
huffman@25789
   199
apply (erule bexE, rename_tac z)
huffman@25789
   200
apply (case_tac z)
huffman@25789
   201
apply simp
huffman@25789
   202
apply (rule_tac x=a in bexI)
huffman@25789
   203
apply simp
huffman@25789
   204
apply simp
huffman@25789
   205
apply (rule disjI2)
huffman@25789
   206
apply (simp, safe)
huffman@25789
   207
apply (case_tac x, simp, simp)
huffman@25789
   208
apply (drule directedD1)
huffman@25789
   209
apply (clarify, rename_tac x)
huffman@25789
   210
apply (case_tac x, simp, simp)
huffman@25789
   211
done
huffman@25789
   212
huffman@25789
   213
lemma dcpo_up: "directed (S::'a::dcpo u set) \<Longrightarrow> \<exists>x. S <<| x"
huffman@25789
   214
apply (frule up_directed_lemma, safe)
huffman@25789
   215
apply (erule exI)
huffman@25789
   216
apply (rule exI, rule is_lub_singleton)
huffman@25789
   217
done
huffman@25789
   218
huffman@25789
   219
instance u :: (dcpo) dcpo
huffman@25789
   220
by intro_classes (rule dcpo_up)
huffman@25789
   221
huffman@18290
   222
subsection {* Lifted cpo is pointed *}
huffman@15576
   223
huffman@17585
   224
lemma least_up: "\<exists>x::'a u. \<forall>y. x \<sqsubseteq> y"
huffman@16753
   225
apply (rule_tac x = "Ibottom" in exI)
huffman@15593
   226
apply (rule minimal_up [THEN allI])
huffman@15576
   227
done
huffman@15576
   228
huffman@15599
   229
instance u :: (cpo) pcpo
huffman@15593
   230
by intro_classes (rule least_up)
huffman@15593
   231
huffman@15593
   232
text {* for compatibility with old HOLCF-Version *}
huffman@16753
   233
lemma inst_up_pcpo: "\<bottom> = Ibottom"
huffman@16319
   234
by (rule minimal_up [THEN UU_I, symmetric])
huffman@15593
   235
huffman@15593
   236
subsection {* Continuity of @{term Iup} and @{term Ifup} *}
huffman@15593
   237
huffman@15593
   238
text {* continuity for @{term Iup} *}
huffman@15576
   239
huffman@16319
   240
lemma cont_Iup: "cont Iup"
huffman@16215
   241
apply (rule contI)
huffman@15599
   242
apply (rule is_lub_Iup)
huffman@15599
   243
apply (erule thelubE [OF _ refl])
huffman@15576
   244
done
huffman@15576
   245
huffman@15593
   246
text {* continuity for @{term Ifup} *}
huffman@15576
   247
huffman@16319
   248
lemma cont_Ifup1: "cont (\<lambda>f. Ifup f x)"
huffman@16753
   249
by (induct x, simp_all)
huffman@15576
   250
huffman@16319
   251
lemma monofun_Ifup2: "monofun (\<lambda>x. Ifup f x)"
huffman@16319
   252
apply (rule monofunI)
huffman@16753
   253
apply (case_tac x, simp)
huffman@16753
   254
apply (case_tac y, simp)
huffman@16319
   255
apply (simp add: monofun_cfun_arg)
huffman@15576
   256
done
huffman@15576
   257
huffman@16319
   258
lemma cont_Ifup2: "cont (\<lambda>x. Ifup f x)"
huffman@16319
   259
apply (rule contI)
huffman@17838
   260
apply (frule up_chain_lemma, safe)
huffman@17838
   261
apply (rule_tac j="j" in is_lub_range_shift [THEN iffD1, standard])
huffman@16319
   262
apply (erule monofun_Ifup2 [THEN ch2ch_monofun])
huffman@16319
   263
apply (simp add: cont_cfun_arg)
huffman@18078
   264
apply (simp add: lub_const)
huffman@15576
   265
done
huffman@15576
   266
huffman@15593
   267
subsection {* Continuous versions of constants *}
huffman@15576
   268
wenzelm@25131
   269
definition
wenzelm@25131
   270
  up  :: "'a \<rightarrow> 'a u" where
wenzelm@25131
   271
  "up = (\<Lambda> x. Iup x)"
huffman@16319
   272
wenzelm@25131
   273
definition
wenzelm@25131
   274
  fup :: "('a \<rightarrow> 'b::pcpo) \<rightarrow> 'a u \<rightarrow> 'b" where
wenzelm@25131
   275
  "fup = (\<Lambda> f p. Ifup f p)"
huffman@15593
   276
huffman@15593
   277
translations
wenzelm@25131
   278
  "case l of CONST up\<cdot>x \<Rightarrow> t" == "CONST fup\<cdot>(\<Lambda> x. t)\<cdot>l"
wenzelm@25131
   279
  "\<Lambda>(CONST up\<cdot>x). t" == "CONST fup\<cdot>(\<Lambda> x. t)"
huffman@15593
   280
huffman@15593
   281
text {* continuous versions of lemmas for @{typ "('a)u"} *}
huffman@15576
   282
huffman@16753
   283
lemma Exh_Up: "z = \<bottom> \<or> (\<exists>x. z = up\<cdot>x)"
huffman@16753
   284
apply (induct z)
huffman@16319
   285
apply (simp add: inst_up_pcpo)
huffman@16319
   286
apply (simp add: up_def cont_Iup)
huffman@15576
   287
done
huffman@15576
   288
huffman@16753
   289
lemma up_eq [simp]: "(up\<cdot>x = up\<cdot>y) = (x = y)"
huffman@16319
   290
by (simp add: up_def cont_Iup)
huffman@15576
   291
huffman@16753
   292
lemma up_inject: "up\<cdot>x = up\<cdot>y \<Longrightarrow> x = y"
huffman@16753
   293
by simp
huffman@16319
   294
huffman@17838
   295
lemma up_defined [simp]: "up\<cdot>x \<noteq> \<bottom>"
huffman@16319
   296
by (simp add: up_def cont_Iup inst_up_pcpo)
huffman@15576
   297
huffman@25785
   298
lemma not_up_less_UU: "\<not> up\<cdot>x \<sqsubseteq> \<bottom>"
huffman@25785
   299
by simp
huffman@15576
   300
huffman@16326
   301
lemma up_less [simp]: "(up\<cdot>x \<sqsubseteq> up\<cdot>y) = (x \<sqsubseteq> y)"
huffman@16319
   302
by (simp add: up_def cont_Iup)
huffman@16319
   303
huffman@25788
   304
lemma upE [cases type: u]: "\<lbrakk>p = \<bottom> \<Longrightarrow> Q; \<And>x. p = up\<cdot>x \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
huffman@25788
   305
apply (cases p)
huffman@16319
   306
apply (simp add: inst_up_pcpo)
huffman@16319
   307
apply (simp add: up_def cont_Iup)
huffman@15576
   308
done
huffman@15576
   309
huffman@25788
   310
lemma up_induct [induct type: u]: "\<lbrakk>P \<bottom>; \<And>x. P (up\<cdot>x)\<rbrakk> \<Longrightarrow> P x"
huffman@25788
   311
by (cases x, simp_all)
huffman@25788
   312
huffman@17838
   313
lemma up_chain_cases:
huffman@17838
   314
  "chain Y \<Longrightarrow>
huffman@17838
   315
  (\<exists>A. chain A \<and> (\<Squnion>i. Y i) = up\<cdot>(\<Squnion>i. A i) \<and>
huffman@17838
   316
  (\<exists>j. \<forall>i. Y (i + j) = up\<cdot>(A i))) \<or> Y = (\<lambda>i. \<bottom>)"
huffman@17838
   317
by (simp add: inst_up_pcpo up_def cont_Iup up_chain_lemma)
huffman@17838
   318
huffman@17838
   319
lemma compact_up [simp]: "compact x \<Longrightarrow> compact (up\<cdot>x)"
huffman@17838
   320
apply (unfold compact_def)
huffman@17838
   321
apply (rule admI)
huffman@17838
   322
apply (drule up_chain_cases)
huffman@17838
   323
apply (elim disjE exE conjE)
huffman@17838
   324
apply simp
huffman@17838
   325
apply (erule (1) admD)
huffman@17838
   326
apply (rule allI, drule_tac x="i + j" in spec)
huffman@17838
   327
apply simp
huffman@18078
   328
apply simp
huffman@17838
   329
done
huffman@17838
   330
huffman@17838
   331
text {* properties of fup *}
huffman@17838
   332
huffman@16319
   333
lemma fup1 [simp]: "fup\<cdot>f\<cdot>\<bottom> = \<bottom>"
huffman@16319
   334
by (simp add: fup_def cont_Ifup1 cont_Ifup2 inst_up_pcpo)
huffman@15576
   335
huffman@16319
   336
lemma fup2 [simp]: "fup\<cdot>f\<cdot>(up\<cdot>x) = f\<cdot>x"
huffman@16753
   337
by (simp add: up_def fup_def cont_Iup cont_Ifup1 cont_Ifup2)
huffman@15576
   338
huffman@16553
   339
lemma fup3 [simp]: "fup\<cdot>up\<cdot>x = x"
huffman@25788
   340
by (cases x, simp_all)
huffman@15576
   341
huffman@15576
   342
end