src/HOLCF/Up.thy
author huffman
Wed Jan 02 19:41:12 2008 +0100 (2008-01-02)
changeset 25787 398dec10518e
parent 25785 dbe118fe3180
child 25788 30cbe0764599
permissions -rw-r--r--
update sq_ord/po instance proofs
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@15599
    89
text {* Now some lemmas about chains of @{typ "'a u"} elements *}
huffman@15599
    90
huffman@16753
    91
lemma up_lemma1: "z \<noteq> Ibottom \<Longrightarrow> Iup (THE a. Iup a = z) = z"
huffman@16753
    92
by (case_tac z, simp_all)
huffman@16319
    93
huffman@16319
    94
lemma up_lemma2:
huffman@16753
    95
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> Y (i + j) \<noteq> Ibottom"
huffman@16319
    96
apply (erule contrapos_nn)
huffman@15599
    97
apply (drule_tac x="j" and y="i + j" in chain_mono3)
huffman@15599
    98
apply (rule le_add2)
huffman@16753
    99
apply (case_tac "Y j")
huffman@16319
   100
apply assumption
huffman@16319
   101
apply simp
huffman@15599
   102
done
huffman@15599
   103
huffman@16319
   104
lemma up_lemma3:
huffman@16753
   105
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> Iup (THE a. Iup a = Y (i + j)) = Y (i + j)"
huffman@16319
   106
by (rule up_lemma1 [OF up_lemma2])
huffman@15599
   107
huffman@16319
   108
lemma up_lemma4:
huffman@16753
   109
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow> chain (\<lambda>i. THE a. Iup a = Y (i + j))"
huffman@15599
   110
apply (rule chainI)
huffman@16319
   111
apply (rule Iup_less [THEN iffD1])
huffman@16319
   112
apply (subst up_lemma3, assumption+)+
huffman@15599
   113
apply (simp add: chainE)
huffman@15599
   114
done
huffman@15599
   115
huffman@16319
   116
lemma up_lemma5:
huffman@16753
   117
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk> \<Longrightarrow>
huffman@16319
   118
    (\<lambda>i. Y (i + j)) = (\<lambda>i. Iup (THE a. Iup a = Y (i + j)))"
huffman@16319
   119
by (rule ext, rule up_lemma3 [symmetric])
huffman@15599
   120
huffman@16319
   121
lemma up_lemma6:
wenzelm@25131
   122
  "\<lbrakk>chain Y; Y j \<noteq> Ibottom\<rbrakk>
huffman@16319
   123
      \<Longrightarrow> range Y <<| Iup (\<Squnion>i. THE a. Iup a = Y(i + j))"
wenzelm@16933
   124
apply (rule_tac j1 = j in is_lub_range_shift [THEN iffD1])
huffman@16319
   125
apply assumption
huffman@16319
   126
apply (subst up_lemma5, assumption+)
huffman@16319
   127
apply (rule is_lub_Iup)
huffman@16319
   128
apply (rule thelubE [OF _ refl])
huffman@16753
   129
apply (erule (1) up_lemma4)
huffman@15599
   130
done
huffman@15599
   131
huffman@17838
   132
lemma up_chain_lemma:
huffman@16319
   133
  "chain Y \<Longrightarrow>
huffman@16319
   134
   (\<exists>A. chain A \<and> lub (range Y) = Iup (lub (range A)) \<and>
huffman@16753
   135
   (\<exists>j. \<forall>i. Y (i + j) = Iup (A i))) \<or> (Y = (\<lambda>i. Ibottom))"
huffman@16319
   136
apply (rule disjCI)
huffman@16319
   137
apply (simp add: expand_fun_eq)
huffman@16319
   138
apply (erule exE, rename_tac j)
huffman@16319
   139
apply (rule_tac x="\<lambda>i. THE a. Iup a = Y (i + j)" in exI)
huffman@16319
   140
apply (simp add: up_lemma4)
huffman@16319
   141
apply (simp add: up_lemma6 [THEN thelubI])
huffman@16319
   142
apply (rule_tac x=j in exI)
huffman@16319
   143
apply (simp add: up_lemma3)
huffman@15599
   144
done
huffman@15599
   145
huffman@16319
   146
lemma cpo_up: "chain (Y::nat \<Rightarrow> 'a u) \<Longrightarrow> \<exists>x. range Y <<| x"
huffman@17838
   147
apply (frule up_chain_lemma, safe)
huffman@16319
   148
apply (rule_tac x="Iup (lub (range A))" in exI)
huffman@17838
   149
apply (erule_tac j="j" in is_lub_range_shift [THEN iffD1, standard])
huffman@16319
   150
apply (simp add: is_lub_Iup thelubE)
huffman@17585
   151
apply (rule exI, rule lub_const)
huffman@15576
   152
done
huffman@15576
   153
huffman@15599
   154
instance u :: (cpo) cpo
huffman@15593
   155
by intro_classes (rule cpo_up)
huffman@15593
   156
huffman@18290
   157
subsection {* Lifted cpo is pointed *}
huffman@15576
   158
huffman@17585
   159
lemma least_up: "\<exists>x::'a u. \<forall>y. x \<sqsubseteq> y"
huffman@16753
   160
apply (rule_tac x = "Ibottom" in exI)
huffman@15593
   161
apply (rule minimal_up [THEN allI])
huffman@15576
   162
done
huffman@15576
   163
huffman@15599
   164
instance u :: (cpo) pcpo
huffman@15593
   165
by intro_classes (rule least_up)
huffman@15593
   166
huffman@15593
   167
text {* for compatibility with old HOLCF-Version *}
huffman@16753
   168
lemma inst_up_pcpo: "\<bottom> = Ibottom"
huffman@16319
   169
by (rule minimal_up [THEN UU_I, symmetric])
huffman@15593
   170
huffman@15593
   171
subsection {* Continuity of @{term Iup} and @{term Ifup} *}
huffman@15593
   172
huffman@15593
   173
text {* continuity for @{term Iup} *}
huffman@15576
   174
huffman@16319
   175
lemma cont_Iup: "cont Iup"
huffman@16215
   176
apply (rule contI)
huffman@15599
   177
apply (rule is_lub_Iup)
huffman@15599
   178
apply (erule thelubE [OF _ refl])
huffman@15576
   179
done
huffman@15576
   180
huffman@15593
   181
text {* continuity for @{term Ifup} *}
huffman@15576
   182
huffman@16319
   183
lemma cont_Ifup1: "cont (\<lambda>f. Ifup f x)"
huffman@16753
   184
by (induct x, simp_all)
huffman@15576
   185
huffman@16319
   186
lemma monofun_Ifup2: "monofun (\<lambda>x. Ifup f x)"
huffman@16319
   187
apply (rule monofunI)
huffman@16753
   188
apply (case_tac x, simp)
huffman@16753
   189
apply (case_tac y, simp)
huffman@16319
   190
apply (simp add: monofun_cfun_arg)
huffman@15576
   191
done
huffman@15576
   192
huffman@16319
   193
lemma cont_Ifup2: "cont (\<lambda>x. Ifup f x)"
huffman@16319
   194
apply (rule contI)
huffman@17838
   195
apply (frule up_chain_lemma, safe)
huffman@17838
   196
apply (rule_tac j="j" in is_lub_range_shift [THEN iffD1, standard])
huffman@16319
   197
apply (erule monofun_Ifup2 [THEN ch2ch_monofun])
huffman@16319
   198
apply (simp add: cont_cfun_arg)
huffman@18078
   199
apply (simp add: lub_const)
huffman@15576
   200
done
huffman@15576
   201
huffman@15593
   202
subsection {* Continuous versions of constants *}
huffman@15576
   203
wenzelm@25131
   204
definition
wenzelm@25131
   205
  up  :: "'a \<rightarrow> 'a u" where
wenzelm@25131
   206
  "up = (\<Lambda> x. Iup x)"
huffman@16319
   207
wenzelm@25131
   208
definition
wenzelm@25131
   209
  fup :: "('a \<rightarrow> 'b::pcpo) \<rightarrow> 'a u \<rightarrow> 'b" where
wenzelm@25131
   210
  "fup = (\<Lambda> f p. Ifup f p)"
huffman@15593
   211
huffman@15593
   212
translations
wenzelm@25131
   213
  "case l of CONST up\<cdot>x \<Rightarrow> t" == "CONST fup\<cdot>(\<Lambda> x. t)\<cdot>l"
wenzelm@25131
   214
  "\<Lambda>(CONST up\<cdot>x). t" == "CONST fup\<cdot>(\<Lambda> x. t)"
huffman@15593
   215
huffman@15593
   216
text {* continuous versions of lemmas for @{typ "('a)u"} *}
huffman@15576
   217
huffman@16753
   218
lemma Exh_Up: "z = \<bottom> \<or> (\<exists>x. z = up\<cdot>x)"
huffman@16753
   219
apply (induct z)
huffman@16319
   220
apply (simp add: inst_up_pcpo)
huffman@16319
   221
apply (simp add: up_def cont_Iup)
huffman@15576
   222
done
huffman@15576
   223
huffman@16753
   224
lemma up_eq [simp]: "(up\<cdot>x = up\<cdot>y) = (x = y)"
huffman@16319
   225
by (simp add: up_def cont_Iup)
huffman@15576
   226
huffman@16753
   227
lemma up_inject: "up\<cdot>x = up\<cdot>y \<Longrightarrow> x = y"
huffman@16753
   228
by simp
huffman@16319
   229
huffman@17838
   230
lemma up_defined [simp]: "up\<cdot>x \<noteq> \<bottom>"
huffman@16319
   231
by (simp add: up_def cont_Iup inst_up_pcpo)
huffman@15576
   232
huffman@25785
   233
lemma not_up_less_UU: "\<not> up\<cdot>x \<sqsubseteq> \<bottom>"
huffman@25785
   234
by simp
huffman@15576
   235
huffman@16326
   236
lemma up_less [simp]: "(up\<cdot>x \<sqsubseteq> up\<cdot>y) = (x \<sqsubseteq> y)"
huffman@16319
   237
by (simp add: up_def cont_Iup)
huffman@16319
   238
huffman@16753
   239
lemma upE: "\<lbrakk>p = \<bottom> \<Longrightarrow> Q; \<And>x. p = up\<cdot>x \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
huffman@16753
   240
apply (case_tac p)
huffman@16319
   241
apply (simp add: inst_up_pcpo)
huffman@16319
   242
apply (simp add: up_def cont_Iup)
huffman@15576
   243
done
huffman@15576
   244
huffman@17838
   245
lemma up_chain_cases:
huffman@17838
   246
  "chain Y \<Longrightarrow>
huffman@17838
   247
  (\<exists>A. chain A \<and> (\<Squnion>i. Y i) = up\<cdot>(\<Squnion>i. A i) \<and>
huffman@17838
   248
  (\<exists>j. \<forall>i. Y (i + j) = up\<cdot>(A i))) \<or> Y = (\<lambda>i. \<bottom>)"
huffman@17838
   249
by (simp add: inst_up_pcpo up_def cont_Iup up_chain_lemma)
huffman@17838
   250
huffman@17838
   251
lemma compact_up [simp]: "compact x \<Longrightarrow> compact (up\<cdot>x)"
huffman@17838
   252
apply (unfold compact_def)
huffman@17838
   253
apply (rule admI)
huffman@17838
   254
apply (drule up_chain_cases)
huffman@17838
   255
apply (elim disjE exE conjE)
huffman@17838
   256
apply simp
huffman@17838
   257
apply (erule (1) admD)
huffman@17838
   258
apply (rule allI, drule_tac x="i + j" in spec)
huffman@17838
   259
apply simp
huffman@18078
   260
apply simp
huffman@17838
   261
done
huffman@17838
   262
huffman@17838
   263
text {* properties of fup *}
huffman@17838
   264
huffman@16319
   265
lemma fup1 [simp]: "fup\<cdot>f\<cdot>\<bottom> = \<bottom>"
huffman@16319
   266
by (simp add: fup_def cont_Ifup1 cont_Ifup2 inst_up_pcpo)
huffman@15576
   267
huffman@16319
   268
lemma fup2 [simp]: "fup\<cdot>f\<cdot>(up\<cdot>x) = f\<cdot>x"
huffman@16753
   269
by (simp add: up_def fup_def cont_Iup cont_Ifup1 cont_Ifup2)
huffman@15576
   270
huffman@16553
   271
lemma fup3 [simp]: "fup\<cdot>up\<cdot>x = x"
huffman@16753
   272
by (rule_tac p=x in upE, simp_all)
huffman@15576
   273
huffman@15576
   274
end