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