src/HOLCF/Up.thy
author huffman
Fri Jun 20 23:01:09 2008 +0200 (2008-06-20)
changeset 27310 d0229bc6c461
parent 26962 c8b20f615d6c
child 27413 3154f3765cc7
permissions -rw-r--r--
simplify profinite class axioms
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@25911
    11
imports Bifinite
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@25827
    71
lemma u_UNIV: "UNIV = insert Ibottom (range Iup)"
huffman@25827
    72
by (auto, case_tac x, auto)
huffman@25827
    73
huffman@25827
    74
instance u :: (finite_po) finite_po
huffman@25827
    75
by (intro_classes, simp add: u_UNIV)
huffman@25827
    76
huffman@25827
    77
huffman@18290
    78
subsection {* Lifted cpo is a cpo *}
huffman@15593
    79
huffman@16319
    80
lemma is_lub_Iup:
huffman@16319
    81
  "range S <<| x \<Longrightarrow> range (\<lambda>i. Iup (S i)) <<| Iup x"
huffman@15576
    82
apply (rule is_lubI)
huffman@15576
    83
apply (rule ub_rangeI)
huffman@16319
    84
apply (subst Iup_less)
huffman@16319
    85
apply (erule is_ub_lub)
huffman@16753
    86
apply (case_tac u)
huffman@16319
    87
apply (drule ub_rangeD)
huffman@16319
    88
apply simp
huffman@16319
    89
apply simp
huffman@16319
    90
apply (erule is_lub_lub)
huffman@15576
    91
apply (rule ub_rangeI)
huffman@16319
    92
apply (drule_tac i=i in ub_rangeD)
huffman@15593
    93
apply simp
huffman@15599
    94
done
huffman@15599
    95
huffman@25789
    96
lemma is_lub_Iup': "\<lbrakk>directed S; S <<| x\<rbrakk> \<Longrightarrow> (Iup ` S) <<| Iup x"
huffman@25789
    97
apply (rule is_lubI)
huffman@25789
    98
apply (rule ub_imageI)
huffman@25789
    99
apply (subst Iup_less)
huffman@25789
   100
apply (erule (1) is_ubD [OF is_lubD1])
huffman@25789
   101
apply (case_tac u)
huffman@25789
   102
apply (drule directedD1, erule exE)
huffman@25789
   103
apply (drule (1) ub_imageD)
huffman@25789
   104
apply simp
huffman@25789
   105
apply simp
huffman@25789
   106
apply (erule is_lub_lub)
huffman@25789
   107
apply (rule is_ubI)
huffman@25789
   108
apply (drule (1) ub_imageD)
huffman@25789
   109
apply simp
huffman@25789
   110
done
huffman@25789
   111
huffman@15599
   112
text {* Now some lemmas about chains of @{typ "'a u"} elements *}
huffman@15599
   113
huffman@16753
   114
lemma up_lemma1: "z \<noteq> Ibottom \<Longrightarrow> Iup (THE a. Iup a = z) = z"
huffman@16753
   115
by (case_tac z, simp_all)
huffman@16319
   116
huffman@16319
   117
lemma up_lemma2:
huffman@16753
   118
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> Y (i + j) \<noteq> Ibottom"
huffman@16319
   119
apply (erule contrapos_nn)
huffman@25922
   120
apply (drule_tac i="j" and j="i + j" in chain_mono)
huffman@15599
   121
apply (rule le_add2)
huffman@16753
   122
apply (case_tac "Y j")
huffman@16319
   123
apply assumption
huffman@16319
   124
apply simp
huffman@15599
   125
done
huffman@15599
   126
huffman@16319
   127
lemma up_lemma3:
huffman@16753
   128
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> Iup (THE a. Iup a = Y (i + j)) = Y (i + j)"
huffman@16319
   129
by (rule up_lemma1 [OF up_lemma2])
huffman@15599
   130
huffman@16319
   131
lemma up_lemma4:
huffman@16753
   132
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> chain (\<lambda>i. THE a. Iup a = Y (i + j))"
huffman@15599
   133
apply (rule chainI)
huffman@16319
   134
apply (rule Iup_less [THEN iffD1])
huffman@16319
   135
apply (subst up_lemma3, assumption+)+
huffman@15599
   136
apply (simp add: chainE)
huffman@15599
   137
done
huffman@15599
   138
huffman@16319
   139
lemma up_lemma5:
huffman@16753
   140
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow>
huffman@16319
   141
    (\<lambda>i. Y (i + j)) = (\<lambda>i. Iup (THE a. Iup a = Y (i + j)))"
huffman@16319
   142
by (rule ext, rule up_lemma3 [symmetric])
huffman@15599
   143
huffman@16319
   144
lemma up_lemma6:
wenzelm@25131
   145
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk>
huffman@16319
   146
      \<Longrightarrow> range Y <<| Iup (\<Squnion>i. THE a. Iup a = Y(i + j))"
wenzelm@16933
   147
apply (rule_tac j1 = j in is_lub_range_shift [THEN iffD1])
huffman@16319
   148
apply assumption
huffman@16319
   149
apply (subst up_lemma5, assumption+)
huffman@16319
   150
apply (rule is_lub_Iup)
huffman@26027
   151
apply (rule cpo_lubI)
huffman@16753
   152
apply (erule (1) up_lemma4)
huffman@15599
   153
done
huffman@15599
   154
huffman@17838
   155
lemma up_chain_lemma:
huffman@16319
   156
  "chain Y \<Longrightarrow>
huffman@16319
   157
   (\<exists>A. chain A \<and> lub (range Y) = Iup (lub (range A)) \<and>
huffman@16753
   158
   (\<exists>j. \<forall>i. Y (i + j) = Iup (A i))) \<or> (Y = (\<lambda>i. Ibottom))"
huffman@16319
   159
apply (rule disjCI)
huffman@16319
   160
apply (simp add: expand_fun_eq)
huffman@16319
   161
apply (erule exE, rename_tac j)
huffman@16319
   162
apply (rule_tac x="\<lambda>i. THE a. Iup a = Y (i + j)" in exI)
huffman@16319
   163
apply (simp add: up_lemma4)
huffman@16319
   164
apply (simp add: up_lemma6 [THEN thelubI])
huffman@16319
   165
apply (rule_tac x=j in exI)
huffman@16319
   166
apply (simp add: up_lemma3)
huffman@15599
   167
done
huffman@15599
   168
huffman@16319
   169
lemma cpo_up: "chain (Y::nat \<Rightarrow> 'a u) \<Longrightarrow> \<exists>x. range Y <<| x"
huffman@17838
   170
apply (frule up_chain_lemma, safe)
huffman@16319
   171
apply (rule_tac x="Iup (lub (range A))" in exI)
huffman@17838
   172
apply (erule_tac j="j" in is_lub_range_shift [THEN iffD1, standard])
huffman@26027
   173
apply (simp add: is_lub_Iup cpo_lubI)
huffman@17585
   174
apply (rule exI, rule lub_const)
huffman@15576
   175
done
huffman@15576
   176
huffman@15599
   177
instance u :: (cpo) cpo
huffman@15593
   178
by intro_classes (rule cpo_up)
huffman@15593
   179
huffman@18290
   180
subsection {* Lifted cpo is pointed *}
huffman@15576
   181
huffman@17585
   182
lemma least_up: "\<exists>x::'a u. \<forall>y. x \<sqsubseteq> y"
huffman@16753
   183
apply (rule_tac x = "Ibottom" in exI)
huffman@15593
   184
apply (rule minimal_up [THEN allI])
huffman@15576
   185
done
huffman@15576
   186
huffman@15599
   187
instance u :: (cpo) pcpo
huffman@15593
   188
by intro_classes (rule least_up)
huffman@15593
   189
huffman@15593
   190
text {* for compatibility with old HOLCF-Version *}
huffman@16753
   191
lemma inst_up_pcpo: "\<bottom> = Ibottom"
huffman@16319
   192
by (rule minimal_up [THEN UU_I, symmetric])
huffman@15593
   193
huffman@15593
   194
subsection {* Continuity of @{term Iup} and @{term Ifup} *}
huffman@15593
   195
huffman@15593
   196
text {* continuity for @{term Iup} *}
huffman@15576
   197
huffman@16319
   198
lemma cont_Iup: "cont Iup"
huffman@16215
   199
apply (rule contI)
huffman@15599
   200
apply (rule is_lub_Iup)
huffman@26027
   201
apply (erule cpo_lubI)
huffman@15576
   202
done
huffman@15576
   203
huffman@15593
   204
text {* continuity for @{term Ifup} *}
huffman@15576
   205
huffman@16319
   206
lemma cont_Ifup1: "cont (\<lambda>f. Ifup f x)"
huffman@16753
   207
by (induct x, simp_all)
huffman@15576
   208
huffman@16319
   209
lemma monofun_Ifup2: "monofun (\<lambda>x. Ifup f x)"
huffman@16319
   210
apply (rule monofunI)
huffman@16753
   211
apply (case_tac x, simp)
huffman@16753
   212
apply (case_tac y, simp)
huffman@16319
   213
apply (simp add: monofun_cfun_arg)
huffman@15576
   214
done
huffman@15576
   215
huffman@16319
   216
lemma cont_Ifup2: "cont (\<lambda>x. Ifup f x)"
huffman@16319
   217
apply (rule contI)
huffman@17838
   218
apply (frule up_chain_lemma, safe)
huffman@17838
   219
apply (rule_tac j="j" in is_lub_range_shift [THEN iffD1, standard])
huffman@16319
   220
apply (erule monofun_Ifup2 [THEN ch2ch_monofun])
huffman@16319
   221
apply (simp add: cont_cfun_arg)
huffman@18078
   222
apply (simp add: lub_const)
huffman@15576
   223
done
huffman@15576
   224
huffman@15593
   225
subsection {* Continuous versions of constants *}
huffman@15576
   226
wenzelm@25131
   227
definition
wenzelm@25131
   228
  up  :: "'a \<rightarrow> 'a u" where
wenzelm@25131
   229
  "up = (\<Lambda> x. Iup x)"
huffman@16319
   230
wenzelm@25131
   231
definition
wenzelm@25131
   232
  fup :: "('a \<rightarrow> 'b::pcpo) \<rightarrow> 'a u \<rightarrow> 'b" where
wenzelm@25131
   233
  "fup = (\<Lambda> f p. Ifup f p)"
huffman@15593
   234
huffman@15593
   235
translations
huffman@26046
   236
  "case l of XCONST up\<cdot>x \<Rightarrow> t" == "CONST fup\<cdot>(\<Lambda> x. t)\<cdot>l"
huffman@26046
   237
  "\<Lambda>(XCONST up\<cdot>x). t" == "CONST fup\<cdot>(\<Lambda> x. t)"
huffman@15593
   238
huffman@15593
   239
text {* continuous versions of lemmas for @{typ "('a)u"} *}
huffman@15576
   240
huffman@16753
   241
lemma Exh_Up: "z = \<bottom> \<or> (\<exists>x. z = up\<cdot>x)"
huffman@16753
   242
apply (induct z)
huffman@16319
   243
apply (simp add: inst_up_pcpo)
huffman@16319
   244
apply (simp add: up_def cont_Iup)
huffman@15576
   245
done
huffman@15576
   246
huffman@16753
   247
lemma up_eq [simp]: "(up\<cdot>x = up\<cdot>y) = (x = y)"
huffman@16319
   248
by (simp add: up_def cont_Iup)
huffman@15576
   249
huffman@16753
   250
lemma up_inject: "up\<cdot>x = up\<cdot>y \<Longrightarrow> x = y"
huffman@16753
   251
by simp
huffman@16319
   252
huffman@17838
   253
lemma up_defined [simp]: "up\<cdot>x \<noteq> \<bottom>"
huffman@16319
   254
by (simp add: up_def cont_Iup inst_up_pcpo)
huffman@15576
   255
huffman@25785
   256
lemma not_up_less_UU: "\<not> up\<cdot>x \<sqsubseteq> \<bottom>"
huffman@25785
   257
by simp
huffman@15576
   258
huffman@16326
   259
lemma up_less [simp]: "(up\<cdot>x \<sqsubseteq> up\<cdot>y) = (x \<sqsubseteq> y)"
huffman@16319
   260
by (simp add: up_def cont_Iup)
huffman@16319
   261
huffman@25788
   262
lemma upE [cases type: u]: "\<lbrakk>p = \<bottom> \<Longrightarrow> Q; \<And>x. p = up\<cdot>x \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
huffman@25788
   263
apply (cases p)
huffman@16319
   264
apply (simp add: inst_up_pcpo)
huffman@16319
   265
apply (simp add: up_def cont_Iup)
huffman@15576
   266
done
huffman@15576
   267
huffman@25788
   268
lemma up_induct [induct type: u]: "\<lbrakk>P \<bottom>; \<And>x. P (up\<cdot>x)\<rbrakk> \<Longrightarrow> P x"
huffman@25788
   269
by (cases x, simp_all)
huffman@25788
   270
huffman@25827
   271
text {* lifting preserves chain-finiteness *}
huffman@25827
   272
huffman@17838
   273
lemma up_chain_cases:
huffman@17838
   274
  "chain Y \<Longrightarrow>
huffman@17838
   275
  (\<exists>A. chain A \<and> (\<Squnion>i. Y i) = up\<cdot>(\<Squnion>i. A i) \<and>
huffman@17838
   276
  (\<exists>j. \<forall>i. Y (i + j) = up\<cdot>(A i))) \<or> Y = (\<lambda>i. \<bottom>)"
huffman@17838
   277
by (simp add: inst_up_pcpo up_def cont_Iup up_chain_lemma)
huffman@17838
   278
huffman@25879
   279
lemma compact_up: "compact x \<Longrightarrow> compact (up\<cdot>x)"
huffman@25879
   280
apply (rule compactI2)
huffman@25879
   281
apply (drule up_chain_cases, safe)
huffman@25879
   282
apply (drule (1) compactD2, simp)
huffman@25879
   283
apply (erule exE, rule_tac x="i + j" in exI)
huffman@25879
   284
apply simp
huffman@25879
   285
apply simp
huffman@25879
   286
done
huffman@25879
   287
huffman@25879
   288
lemma compact_upD: "compact (up\<cdot>x) \<Longrightarrow> compact x"
huffman@25879
   289
unfolding compact_def
huffman@25879
   290
by (drule adm_subst [OF cont_Rep_CFun2 [where f=up]], simp)
huffman@25879
   291
huffman@25879
   292
lemma compact_up_iff [simp]: "compact (up\<cdot>x) = compact x"
huffman@25879
   293
by (safe elim!: compact_up compact_upD)
huffman@25879
   294
huffman@25827
   295
instance u :: (chfin) chfin
huffman@25921
   296
apply intro_classes
huffman@25879
   297
apply (erule compact_imp_max_in_chain)
huffman@25898
   298
apply (rule_tac p="\<Squnion>i. Y i" in upE, simp_all)
huffman@17838
   299
done
huffman@17838
   300
huffman@17838
   301
text {* properties of fup *}
huffman@17838
   302
huffman@16319
   303
lemma fup1 [simp]: "fup\<cdot>f\<cdot>\<bottom> = \<bottom>"
huffman@16319
   304
by (simp add: fup_def cont_Ifup1 cont_Ifup2 inst_up_pcpo)
huffman@15576
   305
huffman@16319
   306
lemma fup2 [simp]: "fup\<cdot>f\<cdot>(up\<cdot>x) = f\<cdot>x"
huffman@16753
   307
by (simp add: up_def fup_def cont_Iup cont_Ifup1 cont_Ifup2)
huffman@15576
   308
huffman@16553
   309
lemma fup3 [simp]: "fup\<cdot>up\<cdot>x = x"
huffman@25788
   310
by (cases x, simp_all)
huffman@15576
   311
huffman@25911
   312
subsection {* Lifted cpo is a bifinite domain *}
huffman@25911
   313
huffman@26962
   314
instantiation u :: (profinite) bifinite
huffman@26962
   315
begin
huffman@25911
   316
huffman@26962
   317
definition
huffman@25911
   318
  approx_up_def:
huffman@26962
   319
    "approx = (\<lambda>n. fup\<cdot>(\<Lambda> x. up\<cdot>(approx n\<cdot>x)))"
huffman@25911
   320
huffman@26962
   321
instance proof
huffman@25911
   322
  fix i :: nat and x :: "'a u"
huffman@27310
   323
  show "chain (approx :: nat \<Rightarrow> 'a u \<rightarrow> 'a u)"
huffman@25911
   324
    unfolding approx_up_def by simp
huffman@25911
   325
  show "(\<Squnion>i. approx i\<cdot>x) = x"
huffman@25911
   326
    unfolding approx_up_def
huffman@25911
   327
    by (simp add: lub_distribs eta_cfun)
huffman@25911
   328
  show "approx i\<cdot>(approx i\<cdot>x) = approx i\<cdot>x"
huffman@25911
   329
    unfolding approx_up_def
huffman@25911
   330
    by (induct x, simp, simp)
huffman@25911
   331
  have "{x::'a u. approx i\<cdot>x = x} \<subseteq>
huffman@25911
   332
        insert \<bottom> ((\<lambda>x. up\<cdot>x) ` {x::'a. approx i\<cdot>x = x})"
huffman@25911
   333
    unfolding approx_up_def
huffman@27310
   334
    by (rule subsetI, case_tac x, simp_all)
huffman@25911
   335
  thus "finite {x::'a u. approx i\<cdot>x = x}"
huffman@25911
   336
    by (rule finite_subset, simp add: finite_fixes_approx)
huffman@25911
   337
qed
huffman@25911
   338
huffman@26962
   339
end
huffman@26962
   340
huffman@25911
   341
lemma approx_up [simp]: "approx i\<cdot>(up\<cdot>x) = up\<cdot>(approx i\<cdot>x)"
huffman@25911
   342
unfolding approx_up_def by simp
huffman@25911
   343
huffman@15576
   344
end