src/HOLCF/Up.thy
author huffman
Mon Nov 09 15:51:32 2009 -0800 (2009-11-09)
changeset 33587 54f98d225163
parent 33504 b4210cc3ac97
child 33808 31169fdc5ae7
permissions -rw-r--r--
add map_map lemmas
huffman@15599
     1
(*  Title:      HOLCF/Up.thy
wenzelm@16070
     2
    Author:     Franz Regensburger and Brian Huffman
huffman@15576
     3
*)
huffman@15576
     4
huffman@15576
     5
header {* The type of lifted values *}
huffman@15576
     6
huffman@15577
     7
theory Up
huffman@25911
     8
imports Bifinite
huffman@15577
     9
begin
huffman@15576
    10
huffman@15599
    11
defaultsort cpo
huffman@15599
    12
huffman@15593
    13
subsection {* Definition of new type for lifting *}
huffman@15576
    14
huffman@16753
    15
datatype 'a u = Ibottom | Iup 'a
huffman@15576
    16
huffman@18290
    17
syntax (xsymbols)
huffman@18290
    18
  "u" :: "type \<Rightarrow> type" ("(_\<^sub>\<bottom>)" [1000] 999)
huffman@18290
    19
huffman@15576
    20
consts
huffman@16753
    21
  Ifup :: "('a \<rightarrow> 'b::pcpo) \<Rightarrow> 'a u \<Rightarrow> 'b"
huffman@15576
    22
huffman@16753
    23
primrec
huffman@16753
    24
  "Ifup f Ibottom = \<bottom>"
huffman@16753
    25
  "Ifup f (Iup x) = f\<cdot>x"
huffman@15576
    26
huffman@18290
    27
subsection {* Ordering on lifted cpo *}
huffman@15593
    28
huffman@31076
    29
instantiation u :: (cpo) below
huffman@25787
    30
begin
huffman@15576
    31
huffman@25787
    32
definition
huffman@31076
    33
  below_up_def:
huffman@16753
    34
    "(op \<sqsubseteq>) \<equiv> (\<lambda>x y. case x of Ibottom \<Rightarrow> True | Iup a \<Rightarrow>
huffman@16753
    35
      (case y of Ibottom \<Rightarrow> False | Iup b \<Rightarrow> a \<sqsubseteq> b))"
huffman@15576
    36
huffman@25787
    37
instance ..
huffman@25787
    38
end
huffman@25787
    39
huffman@16753
    40
lemma minimal_up [iff]: "Ibottom \<sqsubseteq> z"
huffman@31076
    41
by (simp add: below_up_def)
huffman@15576
    42
huffman@31076
    43
lemma not_Iup_below [iff]: "\<not> Iup x \<sqsubseteq> Ibottom"
huffman@31076
    44
by (simp add: below_up_def)
huffman@15576
    45
huffman@31076
    46
lemma Iup_below [iff]: "(Iup x \<sqsubseteq> Iup y) = (x \<sqsubseteq> y)"
huffman@31076
    47
by (simp add: below_up_def)
huffman@15576
    48
huffman@18290
    49
subsection {* Lifted cpo is a partial order *}
huffman@15576
    50
huffman@15599
    51
instance u :: (cpo) po
huffman@25787
    52
proof
huffman@25787
    53
  fix x :: "'a u"
huffman@25787
    54
  show "x \<sqsubseteq> x"
huffman@31076
    55
    unfolding below_up_def by (simp split: u.split)
huffman@25787
    56
next
huffman@25787
    57
  fix x y :: "'a u"
huffman@25787
    58
  assume "x \<sqsubseteq> y" "y \<sqsubseteq> x" thus "x = y"
huffman@31076
    59
    unfolding below_up_def
huffman@31076
    60
    by (auto split: u.split_asm intro: below_antisym)
huffman@25787
    61
next
huffman@25787
    62
  fix x y z :: "'a u"
huffman@25787
    63
  assume "x \<sqsubseteq> y" "y \<sqsubseteq> z" thus "x \<sqsubseteq> z"
huffman@31076
    64
    unfolding below_up_def
huffman@31076
    65
    by (auto split: u.split_asm intro: below_trans)
huffman@25787
    66
qed
huffman@15576
    67
huffman@25827
    68
lemma u_UNIV: "UNIV = insert Ibottom (range Iup)"
huffman@25827
    69
by (auto, case_tac x, auto)
huffman@25827
    70
huffman@25827
    71
instance u :: (finite_po) finite_po
huffman@25827
    72
by (intro_classes, simp add: u_UNIV)
huffman@25827
    73
huffman@25827
    74
huffman@18290
    75
subsection {* Lifted cpo is a cpo *}
huffman@15593
    76
huffman@16319
    77
lemma is_lub_Iup:
huffman@16319
    78
  "range S <<| x \<Longrightarrow> range (\<lambda>i. Iup (S i)) <<| Iup x"
huffman@15576
    79
apply (rule is_lubI)
huffman@15576
    80
apply (rule ub_rangeI)
huffman@31076
    81
apply (subst Iup_below)
huffman@16319
    82
apply (erule is_ub_lub)
huffman@16753
    83
apply (case_tac u)
huffman@16319
    84
apply (drule ub_rangeD)
huffman@16319
    85
apply simp
huffman@16319
    86
apply simp
huffman@16319
    87
apply (erule is_lub_lub)
huffman@15576
    88
apply (rule ub_rangeI)
huffman@16319
    89
apply (drule_tac i=i in ub_rangeD)
huffman@15593
    90
apply simp
huffman@15599
    91
done
huffman@15599
    92
huffman@15599
    93
text {* Now some lemmas about chains of @{typ "'a u"} elements *}
huffman@15599
    94
huffman@16753
    95
lemma up_lemma1: "z \<noteq> Ibottom \<Longrightarrow> Iup (THE a. Iup a = z) = z"
huffman@16753
    96
by (case_tac z, simp_all)
huffman@16319
    97
huffman@16319
    98
lemma up_lemma2:
huffman@16753
    99
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> Y (i + j) \<noteq> Ibottom"
huffman@16319
   100
apply (erule contrapos_nn)
huffman@25922
   101
apply (drule_tac i="j" and j="i + j" in chain_mono)
huffman@15599
   102
apply (rule le_add2)
huffman@16753
   103
apply (case_tac "Y j")
huffman@16319
   104
apply assumption
huffman@16319
   105
apply simp
huffman@15599
   106
done
huffman@15599
   107
huffman@16319
   108
lemma up_lemma3:
huffman@16753
   109
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> Iup (THE a. Iup a = Y (i + j)) = Y (i + j)"
huffman@16319
   110
by (rule up_lemma1 [OF up_lemma2])
huffman@15599
   111
huffman@16319
   112
lemma up_lemma4:
huffman@16753
   113
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> chain (\<lambda>i. THE a. Iup a = Y (i + j))"
huffman@15599
   114
apply (rule chainI)
huffman@31076
   115
apply (rule Iup_below [THEN iffD1])
huffman@16319
   116
apply (subst up_lemma3, assumption+)+
huffman@15599
   117
apply (simp add: chainE)
huffman@15599
   118
done
huffman@15599
   119
huffman@16319
   120
lemma up_lemma5:
huffman@16753
   121
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow>
huffman@16319
   122
    (\<lambda>i. Y (i + j)) = (\<lambda>i. Iup (THE a. Iup a = Y (i + j)))"
huffman@16319
   123
by (rule ext, rule up_lemma3 [symmetric])
huffman@15599
   124
huffman@16319
   125
lemma up_lemma6:
wenzelm@25131
   126
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk>
huffman@16319
   127
      \<Longrightarrow> range Y <<| Iup (\<Squnion>i. THE a. Iup a = Y(i + j))"
wenzelm@16933
   128
apply (rule_tac j1 = j in is_lub_range_shift [THEN iffD1])
huffman@16319
   129
apply assumption
huffman@16319
   130
apply (subst up_lemma5, assumption+)
huffman@16319
   131
apply (rule is_lub_Iup)
huffman@26027
   132
apply (rule cpo_lubI)
huffman@16753
   133
apply (erule (1) up_lemma4)
huffman@15599
   134
done
huffman@15599
   135
huffman@17838
   136
lemma up_chain_lemma:
huffman@16319
   137
  "chain Y \<Longrightarrow>
huffman@27413
   138
   (\<exists>A. chain A \<and> (\<Squnion>i. Y i) = Iup (\<Squnion>i. A i) \<and>
huffman@16753
   139
   (\<exists>j. \<forall>i. Y (i + j) = Iup (A i))) \<or> (Y = (\<lambda>i. Ibottom))"
huffman@16319
   140
apply (rule disjCI)
huffman@16319
   141
apply (simp add: expand_fun_eq)
huffman@16319
   142
apply (erule exE, rename_tac j)
huffman@16319
   143
apply (rule_tac x="\<lambda>i. THE a. Iup a = Y (i + j)" in exI)
huffman@16319
   144
apply (simp add: up_lemma4)
huffman@16319
   145
apply (simp add: up_lemma6 [THEN thelubI])
huffman@16319
   146
apply (rule_tac x=j in exI)
huffman@16319
   147
apply (simp add: up_lemma3)
huffman@15599
   148
done
huffman@15599
   149
huffman@16319
   150
lemma cpo_up: "chain (Y::nat \<Rightarrow> 'a u) \<Longrightarrow> \<exists>x. range Y <<| x"
huffman@17838
   151
apply (frule up_chain_lemma, safe)
huffman@27413
   152
apply (rule_tac x="Iup (\<Squnion>i. A i)" in exI)
huffman@17838
   153
apply (erule_tac j="j" in is_lub_range_shift [THEN iffD1, standard])
huffman@26027
   154
apply (simp add: is_lub_Iup cpo_lubI)
huffman@17585
   155
apply (rule exI, rule lub_const)
huffman@15576
   156
done
huffman@15576
   157
huffman@15599
   158
instance u :: (cpo) cpo
huffman@15593
   159
by intro_classes (rule cpo_up)
huffman@15593
   160
huffman@18290
   161
subsection {* Lifted cpo is pointed *}
huffman@15576
   162
huffman@17585
   163
lemma least_up: "\<exists>x::'a u. \<forall>y. x \<sqsubseteq> y"
huffman@16753
   164
apply (rule_tac x = "Ibottom" in exI)
huffman@15593
   165
apply (rule minimal_up [THEN allI])
huffman@15576
   166
done
huffman@15576
   167
huffman@15599
   168
instance u :: (cpo) pcpo
huffman@15593
   169
by intro_classes (rule least_up)
huffman@15593
   170
huffman@15593
   171
text {* for compatibility with old HOLCF-Version *}
huffman@16753
   172
lemma inst_up_pcpo: "\<bottom> = Ibottom"
huffman@16319
   173
by (rule minimal_up [THEN UU_I, symmetric])
huffman@15593
   174
huffman@15593
   175
subsection {* Continuity of @{term Iup} and @{term Ifup} *}
huffman@15593
   176
huffman@15593
   177
text {* continuity for @{term Iup} *}
huffman@15576
   178
huffman@16319
   179
lemma cont_Iup: "cont Iup"
huffman@16215
   180
apply (rule contI)
huffman@15599
   181
apply (rule is_lub_Iup)
huffman@26027
   182
apply (erule cpo_lubI)
huffman@15576
   183
done
huffman@15576
   184
huffman@15593
   185
text {* continuity for @{term Ifup} *}
huffman@15576
   186
huffman@16319
   187
lemma cont_Ifup1: "cont (\<lambda>f. Ifup f x)"
huffman@16753
   188
by (induct x, simp_all)
huffman@15576
   189
huffman@16319
   190
lemma monofun_Ifup2: "monofun (\<lambda>x. Ifup f x)"
huffman@16319
   191
apply (rule monofunI)
huffman@16753
   192
apply (case_tac x, simp)
huffman@16753
   193
apply (case_tac y, simp)
huffman@16319
   194
apply (simp add: monofun_cfun_arg)
huffman@15576
   195
done
huffman@15576
   196
huffman@16319
   197
lemma cont_Ifup2: "cont (\<lambda>x. Ifup f x)"
huffman@16319
   198
apply (rule contI)
huffman@17838
   199
apply (frule up_chain_lemma, safe)
huffman@17838
   200
apply (rule_tac j="j" in is_lub_range_shift [THEN iffD1, standard])
huffman@16319
   201
apply (erule monofun_Ifup2 [THEN ch2ch_monofun])
huffman@16319
   202
apply (simp add: cont_cfun_arg)
huffman@18078
   203
apply (simp add: lub_const)
huffman@15576
   204
done
huffman@15576
   205
huffman@15593
   206
subsection {* Continuous versions of constants *}
huffman@15576
   207
wenzelm@25131
   208
definition
wenzelm@25131
   209
  up  :: "'a \<rightarrow> 'a u" where
wenzelm@25131
   210
  "up = (\<Lambda> x. Iup x)"
huffman@16319
   211
wenzelm@25131
   212
definition
wenzelm@25131
   213
  fup :: "('a \<rightarrow> 'b::pcpo) \<rightarrow> 'a u \<rightarrow> 'b" where
wenzelm@25131
   214
  "fup = (\<Lambda> f p. Ifup f p)"
huffman@15593
   215
huffman@15593
   216
translations
huffman@26046
   217
  "case l of XCONST up\<cdot>x \<Rightarrow> t" == "CONST fup\<cdot>(\<Lambda> x. t)\<cdot>l"
huffman@26046
   218
  "\<Lambda>(XCONST up\<cdot>x). t" == "CONST fup\<cdot>(\<Lambda> x. t)"
huffman@15593
   219
huffman@15593
   220
text {* continuous versions of lemmas for @{typ "('a)u"} *}
huffman@15576
   221
huffman@16753
   222
lemma Exh_Up: "z = \<bottom> \<or> (\<exists>x. z = up\<cdot>x)"
huffman@16753
   223
apply (induct z)
huffman@16319
   224
apply (simp add: inst_up_pcpo)
huffman@16319
   225
apply (simp add: up_def cont_Iup)
huffman@15576
   226
done
huffman@15576
   227
huffman@16753
   228
lemma up_eq [simp]: "(up\<cdot>x = up\<cdot>y) = (x = y)"
huffman@16319
   229
by (simp add: up_def cont_Iup)
huffman@15576
   230
huffman@16753
   231
lemma up_inject: "up\<cdot>x = up\<cdot>y \<Longrightarrow> x = y"
huffman@16753
   232
by simp
huffman@16319
   233
huffman@17838
   234
lemma up_defined [simp]: "up\<cdot>x \<noteq> \<bottom>"
huffman@16319
   235
by (simp add: up_def cont_Iup inst_up_pcpo)
huffman@15576
   236
huffman@25785
   237
lemma not_up_less_UU: "\<not> up\<cdot>x \<sqsubseteq> \<bottom>"
huffman@31076
   238
by simp (* FIXME: remove? *)
huffman@15576
   239
huffman@31076
   240
lemma up_below [simp]: "up\<cdot>x \<sqsubseteq> up\<cdot>y \<longleftrightarrow> x \<sqsubseteq> y"
huffman@16319
   241
by (simp add: up_def cont_Iup)
huffman@16319
   242
huffman@25788
   243
lemma upE [cases type: u]: "\<lbrakk>p = \<bottom> \<Longrightarrow> Q; \<And>x. p = up\<cdot>x \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
huffman@25788
   244
apply (cases p)
huffman@16319
   245
apply (simp add: inst_up_pcpo)
huffman@16319
   246
apply (simp add: up_def cont_Iup)
huffman@15576
   247
done
huffman@15576
   248
huffman@25788
   249
lemma up_induct [induct type: u]: "\<lbrakk>P \<bottom>; \<And>x. P (up\<cdot>x)\<rbrakk> \<Longrightarrow> P x"
huffman@25788
   250
by (cases x, simp_all)
huffman@25788
   251
huffman@25827
   252
text {* lifting preserves chain-finiteness *}
huffman@25827
   253
huffman@17838
   254
lemma up_chain_cases:
huffman@17838
   255
  "chain Y \<Longrightarrow>
huffman@17838
   256
  (\<exists>A. chain A \<and> (\<Squnion>i. Y i) = up\<cdot>(\<Squnion>i. A i) \<and>
huffman@17838
   257
  (\<exists>j. \<forall>i. Y (i + j) = up\<cdot>(A i))) \<or> Y = (\<lambda>i. \<bottom>)"
huffman@17838
   258
by (simp add: inst_up_pcpo up_def cont_Iup up_chain_lemma)
huffman@17838
   259
huffman@25879
   260
lemma compact_up: "compact x \<Longrightarrow> compact (up\<cdot>x)"
huffman@25879
   261
apply (rule compactI2)
huffman@25879
   262
apply (drule up_chain_cases, safe)
huffman@25879
   263
apply (drule (1) compactD2, simp)
huffman@25879
   264
apply (erule exE, rule_tac x="i + j" in exI)
huffman@25879
   265
apply simp
huffman@25879
   266
apply simp
huffman@25879
   267
done
huffman@25879
   268
huffman@25879
   269
lemma compact_upD: "compact (up\<cdot>x) \<Longrightarrow> compact x"
huffman@25879
   270
unfolding compact_def
huffman@25879
   271
by (drule adm_subst [OF cont_Rep_CFun2 [where f=up]], simp)
huffman@25879
   272
huffman@25879
   273
lemma compact_up_iff [simp]: "compact (up\<cdot>x) = compact x"
huffman@25879
   274
by (safe elim!: compact_up compact_upD)
huffman@25879
   275
huffman@25827
   276
instance u :: (chfin) chfin
huffman@25921
   277
apply intro_classes
huffman@25879
   278
apply (erule compact_imp_max_in_chain)
huffman@25898
   279
apply (rule_tac p="\<Squnion>i. Y i" in upE, simp_all)
huffman@17838
   280
done
huffman@17838
   281
huffman@17838
   282
text {* properties of fup *}
huffman@17838
   283
huffman@16319
   284
lemma fup1 [simp]: "fup\<cdot>f\<cdot>\<bottom> = \<bottom>"
huffman@29530
   285
by (simp add: fup_def cont_Ifup1 cont_Ifup2 inst_up_pcpo cont2cont_LAM)
huffman@15576
   286
huffman@16319
   287
lemma fup2 [simp]: "fup\<cdot>f\<cdot>(up\<cdot>x) = f\<cdot>x"
huffman@29530
   288
by (simp add: up_def fup_def cont_Iup cont_Ifup1 cont_Ifup2 cont2cont_LAM)
huffman@15576
   289
huffman@16553
   290
lemma fup3 [simp]: "fup\<cdot>up\<cdot>x = x"
huffman@25788
   291
by (cases x, simp_all)
huffman@15576
   292
huffman@33504
   293
subsection {* Map function for lifted cpo *}
huffman@33504
   294
huffman@33504
   295
definition
huffman@33504
   296
  u_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a u \<rightarrow> 'b u"
huffman@33504
   297
where
huffman@33504
   298
  "u_map = (\<Lambda> f. fup\<cdot>(up oo f))"
huffman@33504
   299
huffman@33504
   300
lemma u_map_strict [simp]: "u_map\<cdot>f\<cdot>\<bottom> = \<bottom>"
huffman@33504
   301
unfolding u_map_def by simp
huffman@33504
   302
huffman@33504
   303
lemma u_map_up [simp]: "u_map\<cdot>f\<cdot>(up\<cdot>x) = up\<cdot>(f\<cdot>x)"
huffman@33504
   304
unfolding u_map_def by simp
huffman@33504
   305
huffman@33587
   306
lemma u_map_map: "u_map\<cdot>f\<cdot>(u_map\<cdot>g\<cdot>p) = u_map\<cdot>(\<Lambda> x. f\<cdot>(g\<cdot>x))\<cdot>p"
huffman@33587
   307
by (induct p) simp_all
huffman@33587
   308
huffman@33504
   309
lemma ep_pair_u_map: "ep_pair e p \<Longrightarrow> ep_pair (u_map\<cdot>e) (u_map\<cdot>p)"
huffman@33504
   310
apply default
huffman@33504
   311
apply (case_tac x, simp, simp add: ep_pair.e_inverse)
huffman@33504
   312
apply (case_tac y, simp, simp add: ep_pair.e_p_below)
huffman@33504
   313
done
huffman@33504
   314
huffman@33504
   315
lemma deflation_u_map: "deflation d \<Longrightarrow> deflation (u_map\<cdot>d)"
huffman@33504
   316
apply default
huffman@33504
   317
apply (case_tac x, simp, simp add: deflation.idem)
huffman@33504
   318
apply (case_tac x, simp, simp add: deflation.below)
huffman@33504
   319
done
huffman@33504
   320
huffman@33504
   321
lemma finite_deflation_u_map:
huffman@33504
   322
  assumes "finite_deflation d" shows "finite_deflation (u_map\<cdot>d)"
huffman@33504
   323
proof (intro finite_deflation.intro finite_deflation_axioms.intro)
huffman@33504
   324
  interpret d: finite_deflation d by fact
huffman@33504
   325
  have "deflation d" by fact
huffman@33504
   326
  thus "deflation (u_map\<cdot>d)" by (rule deflation_u_map)
huffman@33504
   327
  have "{x. u_map\<cdot>d\<cdot>x = x} \<subseteq> insert \<bottom> ((\<lambda>x. up\<cdot>x) ` {x. d\<cdot>x = x})"
huffman@33504
   328
    by (rule subsetI, case_tac x, simp_all)
huffman@33504
   329
  thus "finite {x. u_map\<cdot>d\<cdot>x = x}"
huffman@33504
   330
    by (rule finite_subset, simp add: d.finite_fixes)
huffman@33504
   331
qed
huffman@33504
   332
huffman@25911
   333
subsection {* Lifted cpo is a bifinite domain *}
huffman@25911
   334
huffman@26962
   335
instantiation u :: (profinite) bifinite
huffman@26962
   336
begin
huffman@25911
   337
huffman@26962
   338
definition
huffman@25911
   339
  approx_up_def:
huffman@33504
   340
    "approx = (\<lambda>n. u_map\<cdot>(approx n))"
huffman@25911
   341
huffman@26962
   342
instance proof
huffman@25911
   343
  fix i :: nat and x :: "'a u"
huffman@27310
   344
  show "chain (approx :: nat \<Rightarrow> 'a u \<rightarrow> 'a u)"
huffman@25911
   345
    unfolding approx_up_def by simp
huffman@25911
   346
  show "(\<Squnion>i. approx i\<cdot>x) = x"
huffman@25911
   347
    unfolding approx_up_def
huffman@33504
   348
    by (induct x, simp, simp add: lub_distribs)
huffman@25911
   349
  show "approx i\<cdot>(approx i\<cdot>x) = approx i\<cdot>x"
huffman@25911
   350
    unfolding approx_up_def
huffman@33504
   351
    by (induct x) simp_all
huffman@33504
   352
  show "finite {x::'a u. approx i\<cdot>x = x}"
huffman@25911
   353
    unfolding approx_up_def
huffman@33504
   354
    by (intro finite_deflation.finite_fixes
huffman@33504
   355
              finite_deflation_u_map
huffman@33504
   356
              finite_deflation_approx)
huffman@25911
   357
qed
huffman@25911
   358
huffman@26962
   359
end
huffman@26962
   360
huffman@25911
   361
lemma approx_up [simp]: "approx i\<cdot>(up\<cdot>x) = up\<cdot>(approx i\<cdot>x)"
huffman@25911
   362
unfolding approx_up_def by simp
huffman@25911
   363
huffman@15576
   364
end