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