src/HOLCF/Pcpodef.thy
author huffman
Fri Jan 18 20:22:07 2008 +0100 (2008-01-18)
changeset 25925 3dc4acca4388
parent 25921 0ca392ab7f37
child 25926 aa0eca1ccb19
permissions -rw-r--r--
change lemma admD to rule_format
huffman@16697
     1
(*  Title:      HOLCF/Pcpodef.thy
huffman@16697
     2
    ID:         $Id$
huffman@16697
     3
    Author:     Brian Huffman
huffman@16697
     4
*)
huffman@16697
     5
huffman@16697
     6
header {* Subtypes of pcpos *}
huffman@16697
     7
huffman@16697
     8
theory Pcpodef
huffman@16697
     9
imports Adm
wenzelm@23152
    10
uses ("Tools/pcpodef_package.ML")
huffman@16697
    11
begin
huffman@16697
    12
huffman@16697
    13
subsection {* Proving a subtype is a partial order *}
huffman@16697
    14
huffman@16697
    15
text {*
huffman@16697
    16
  A subtype of a partial order is itself a partial order,
huffman@16697
    17
  if the ordering is defined in the standard way.
huffman@16697
    18
*}
huffman@16697
    19
huffman@16697
    20
theorem typedef_po:
huffman@16697
    21
  fixes Abs :: "'a::po \<Rightarrow> 'b::sq_ord"
huffman@16697
    22
  assumes type: "type_definition Rep Abs A"
huffman@16697
    23
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
    24
  shows "OFCLASS('b, po_class)"
huffman@16697
    25
 apply (intro_classes, unfold less)
huffman@16697
    26
   apply (rule refl_less)
huffman@16918
    27
  apply (rule type_definition.Rep_inject [OF type, THEN iffD1])
huffman@16918
    28
  apply (erule (1) antisym_less)
huffman@16918
    29
 apply (erule (1) trans_less)
huffman@16697
    30
done
huffman@16697
    31
huffman@16697
    32
huffman@25827
    33
subsection {* Proving a subtype is finite *}
huffman@25827
    34
huffman@25827
    35
context type_definition
huffman@25827
    36
begin
huffman@25827
    37
huffman@25827
    38
lemma Abs_image:
huffman@25827
    39
  shows "Abs ` A = UNIV"
huffman@25827
    40
proof
huffman@25827
    41
  show "Abs ` A <= UNIV" by simp
huffman@25827
    42
  show "UNIV <= Abs ` A"
huffman@25827
    43
  proof
huffman@25827
    44
    fix x
huffman@25827
    45
    have "x = Abs (Rep x)" by (rule Rep_inverse [symmetric])
huffman@25827
    46
    thus "x : Abs ` A" using Rep by (rule image_eqI)
huffman@25827
    47
  qed
huffman@25827
    48
qed
huffman@25827
    49
huffman@25827
    50
lemma finite_UNIV: "finite A \<Longrightarrow> finite (UNIV :: 'b set)"
huffman@25827
    51
proof -
huffman@25827
    52
  assume "finite A"
huffman@25827
    53
  hence "finite (Abs ` A)" by (rule finite_imageI)
huffman@25827
    54
  thus "finite (UNIV :: 'b set)" by (simp only: Abs_image)
huffman@25827
    55
qed
huffman@25827
    56
huffman@25827
    57
end
huffman@25827
    58
huffman@25827
    59
theorem typedef_finite_po:
huffman@25827
    60
  fixes Abs :: "'a::finite_po \<Rightarrow> 'b::po"
huffman@25827
    61
  assumes type: "type_definition Rep Abs A"
huffman@25827
    62
  shows "OFCLASS('b, finite_po_class)"
huffman@25827
    63
 apply (intro_classes)
huffman@25827
    64
 apply (rule type_definition.finite_UNIV [OF type])
huffman@25827
    65
 apply (rule finite)
huffman@25827
    66
done
huffman@25827
    67
huffman@17812
    68
subsection {* Proving a subtype is chain-finite *}
huffman@17812
    69
huffman@17812
    70
lemma monofun_Rep:
huffman@17812
    71
  assumes less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@17812
    72
  shows "monofun Rep"
huffman@17812
    73
by (rule monofunI, unfold less)
huffman@17812
    74
huffman@17812
    75
lemmas ch2ch_Rep = ch2ch_monofun [OF monofun_Rep]
huffman@17812
    76
lemmas ub2ub_Rep = ub2ub_monofun [OF monofun_Rep]
huffman@17812
    77
huffman@17812
    78
theorem typedef_chfin:
huffman@17812
    79
  fixes Abs :: "'a::chfin \<Rightarrow> 'b::po"
huffman@17812
    80
  assumes type: "type_definition Rep Abs A"
huffman@17812
    81
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@17812
    82
  shows "OFCLASS('b, chfin_class)"
huffman@25921
    83
 apply intro_classes
huffman@17812
    84
 apply (drule ch2ch_Rep [OF less])
huffman@25921
    85
 apply (drule chfin)
huffman@17812
    86
 apply (unfold max_in_chain_def)
huffman@17812
    87
 apply (simp add: type_definition.Rep_inject [OF type])
huffman@17812
    88
done
huffman@17812
    89
huffman@16697
    90
subsection {* Proving a subtype is complete *}
huffman@16697
    91
huffman@16697
    92
text {*
huffman@16697
    93
  A subtype of a cpo is itself a cpo if the ordering is
huffman@16697
    94
  defined in the standard way, and the defining subset
huffman@16697
    95
  is closed with respect to limits of chains.  A set is
huffman@16697
    96
  closed if and only if membership in the set is an
huffman@16697
    97
  admissible predicate.
huffman@16697
    98
*}
huffman@16697
    99
huffman@16918
   100
lemma Abs_inverse_lub_Rep:
huffman@16697
   101
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::po"
huffman@16697
   102
  assumes type: "type_definition Rep Abs A"
huffman@16697
   103
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   104
    and adm:  "adm (\<lambda>x. x \<in> A)"
huffman@16918
   105
  shows "chain S \<Longrightarrow> Rep (Abs (\<Squnion>i. Rep (S i))) = (\<Squnion>i. Rep (S i))"
huffman@16918
   106
 apply (rule type_definition.Abs_inverse [OF type])
huffman@25925
   107
 apply (erule admD [OF adm ch2ch_Rep [OF less]])
huffman@16697
   108
 apply (rule type_definition.Rep [OF type])
huffman@16697
   109
done
huffman@16697
   110
huffman@16918
   111
theorem typedef_lub:
huffman@16697
   112
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::po"
huffman@16697
   113
  assumes type: "type_definition Rep Abs A"
huffman@16697
   114
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   115
    and adm: "adm (\<lambda>x. x \<in> A)"
huffman@16918
   116
  shows "chain S \<Longrightarrow> range S <<| Abs (\<Squnion>i. Rep (S i))"
huffman@16918
   117
 apply (frule ch2ch_Rep [OF less])
huffman@16697
   118
 apply (rule is_lubI)
huffman@16697
   119
  apply (rule ub_rangeI)
huffman@16918
   120
  apply (simp only: less Abs_inverse_lub_Rep [OF type less adm])
huffman@16918
   121
  apply (erule is_ub_thelub)
huffman@16918
   122
 apply (simp only: less Abs_inverse_lub_Rep [OF type less adm])
huffman@16918
   123
 apply (erule is_lub_thelub)
huffman@16918
   124
 apply (erule ub2ub_Rep [OF less])
huffman@16697
   125
done
huffman@16697
   126
huffman@16918
   127
lemmas typedef_thelub = typedef_lub [THEN thelubI, standard]
huffman@16918
   128
huffman@16697
   129
theorem typedef_cpo:
huffman@16697
   130
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::po"
huffman@16697
   131
  assumes type: "type_definition Rep Abs A"
huffman@16697
   132
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   133
    and adm: "adm (\<lambda>x. x \<in> A)"
huffman@16697
   134
  shows "OFCLASS('b, cpo_class)"
huffman@16918
   135
proof
huffman@16918
   136
  fix S::"nat \<Rightarrow> 'b" assume "chain S"
huffman@16918
   137
  hence "range S <<| Abs (\<Squnion>i. Rep (S i))"
huffman@16918
   138
    by (rule typedef_lub [OF type less adm])
huffman@16918
   139
  thus "\<exists>x. range S <<| x" ..
huffman@16918
   140
qed
huffman@16697
   141
huffman@16697
   142
huffman@16697
   143
subsubsection {* Continuity of @{term Rep} and @{term Abs} *}
huffman@16697
   144
huffman@16697
   145
text {* For any sub-cpo, the @{term Rep} function is continuous. *}
huffman@16697
   146
huffman@16697
   147
theorem typedef_cont_Rep:
huffman@16697
   148
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
huffman@16697
   149
  assumes type: "type_definition Rep Abs A"
huffman@16697
   150
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   151
    and adm: "adm (\<lambda>x. x \<in> A)"
huffman@16697
   152
  shows "cont Rep"
huffman@16697
   153
 apply (rule contI)
huffman@16918
   154
 apply (simp only: typedef_thelub [OF type less adm])
huffman@16918
   155
 apply (simp only: Abs_inverse_lub_Rep [OF type less adm])
huffman@16697
   156
 apply (rule thelubE [OF _ refl])
huffman@16918
   157
 apply (erule ch2ch_Rep [OF less])
huffman@16697
   158
done
huffman@16697
   159
huffman@16697
   160
text {*
huffman@16697
   161
  For a sub-cpo, we can make the @{term Abs} function continuous
huffman@16697
   162
  only if we restrict its domain to the defining subset by
huffman@16697
   163
  composing it with another continuous function.
huffman@16697
   164
*}
huffman@16697
   165
huffman@16918
   166
theorem typedef_is_lubI:
huffman@16918
   167
  assumes less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16918
   168
  shows "range (\<lambda>i. Rep (S i)) <<| Rep x \<Longrightarrow> range S <<| x"
huffman@16918
   169
 apply (rule is_lubI)
huffman@16918
   170
  apply (rule ub_rangeI)
huffman@16918
   171
  apply (subst less)
huffman@16918
   172
  apply (erule is_ub_lub)
huffman@16918
   173
 apply (subst less)
huffman@16918
   174
 apply (erule is_lub_lub)
huffman@16918
   175
 apply (erule ub2ub_Rep [OF less])
huffman@16918
   176
done
huffman@16918
   177
huffman@16697
   178
theorem typedef_cont_Abs:
huffman@16697
   179
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
huffman@16697
   180
  fixes f :: "'c::cpo \<Rightarrow> 'a::cpo"
huffman@16697
   181
  assumes type: "type_definition Rep Abs A"
huffman@16697
   182
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16918
   183
    and adm: "adm (\<lambda>x. x \<in> A)" (* not used *)
huffman@16697
   184
    and f_in_A: "\<And>x. f x \<in> A"
huffman@16697
   185
    and cont_f: "cont f"
huffman@16697
   186
  shows "cont (\<lambda>x. Abs (f x))"
huffman@16697
   187
 apply (rule contI)
huffman@16918
   188
 apply (rule typedef_is_lubI [OF less])
huffman@16918
   189
 apply (simp only: type_definition.Abs_inverse [OF type f_in_A])
huffman@16918
   190
 apply (erule cont_f [THEN contE])
huffman@16697
   191
done
huffman@16697
   192
huffman@17833
   193
subsection {* Proving subtype elements are compact *}
huffman@17833
   194
huffman@17833
   195
theorem typedef_compact:
huffman@17833
   196
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
huffman@17833
   197
  assumes type: "type_definition Rep Abs A"
huffman@17833
   198
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@17833
   199
    and adm: "adm (\<lambda>x. x \<in> A)"
huffman@17833
   200
  shows "compact (Rep k) \<Longrightarrow> compact k"
huffman@17833
   201
proof (unfold compact_def)
huffman@17833
   202
  have cont_Rep: "cont Rep"
huffman@17833
   203
    by (rule typedef_cont_Rep [OF type less adm])
huffman@17833
   204
  assume "adm (\<lambda>x. \<not> Rep k \<sqsubseteq> x)"
huffman@17833
   205
  with cont_Rep have "adm (\<lambda>x. \<not> Rep k \<sqsubseteq> Rep x)" by (rule adm_subst)
huffman@17833
   206
  thus "adm (\<lambda>x. \<not> k \<sqsubseteq> x)" by (unfold less)
huffman@17833
   207
qed
huffman@17833
   208
huffman@16697
   209
subsection {* Proving a subtype is pointed *}
huffman@16697
   210
huffman@16697
   211
text {*
huffman@16697
   212
  A subtype of a cpo has a least element if and only if
huffman@16697
   213
  the defining subset has a least element.
huffman@16697
   214
*}
huffman@16697
   215
huffman@16918
   216
theorem typedef_pcpo_generic:
huffman@16697
   217
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
huffman@16697
   218
  assumes type: "type_definition Rep Abs A"
huffman@16697
   219
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   220
    and z_in_A: "z \<in> A"
huffman@16697
   221
    and z_least: "\<And>x. x \<in> A \<Longrightarrow> z \<sqsubseteq> x"
huffman@16697
   222
  shows "OFCLASS('b, pcpo_class)"
huffman@16697
   223
 apply (intro_classes)
huffman@16697
   224
 apply (rule_tac x="Abs z" in exI, rule allI)
huffman@16697
   225
 apply (unfold less)
huffman@16697
   226
 apply (subst type_definition.Abs_inverse [OF type z_in_A])
huffman@16697
   227
 apply (rule z_least [OF type_definition.Rep [OF type]])
huffman@16697
   228
done
huffman@16697
   229
huffman@16697
   230
text {*
huffman@16697
   231
  As a special case, a subtype of a pcpo has a least element
huffman@16697
   232
  if the defining subset contains @{term \<bottom>}.
huffman@16697
   233
*}
huffman@16697
   234
huffman@16918
   235
theorem typedef_pcpo:
huffman@16697
   236
  fixes Abs :: "'a::pcpo \<Rightarrow> 'b::cpo"
huffman@16697
   237
  assumes type: "type_definition Rep Abs A"
huffman@16697
   238
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   239
    and UU_in_A: "\<bottom> \<in> A"
huffman@16697
   240
  shows "OFCLASS('b, pcpo_class)"
huffman@16918
   241
by (rule typedef_pcpo_generic [OF type less UU_in_A], rule minimal)
huffman@16697
   242
huffman@16697
   243
subsubsection {* Strictness of @{term Rep} and @{term Abs} *}
huffman@16697
   244
huffman@16697
   245
text {*
huffman@16697
   246
  For a sub-pcpo where @{term \<bottom>} is a member of the defining
huffman@16697
   247
  subset, @{term Rep} and @{term Abs} are both strict.
huffman@16697
   248
*}
huffman@16697
   249
huffman@16697
   250
theorem typedef_Abs_strict:
huffman@16697
   251
  assumes type: "type_definition Rep Abs A"
huffman@16697
   252
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   253
    and UU_in_A: "\<bottom> \<in> A"
huffman@16697
   254
  shows "Abs \<bottom> = \<bottom>"
huffman@16697
   255
 apply (rule UU_I, unfold less)
huffman@16697
   256
 apply (simp add: type_definition.Abs_inverse [OF type UU_in_A])
huffman@16697
   257
done
huffman@16697
   258
huffman@16697
   259
theorem typedef_Rep_strict:
huffman@16697
   260
  assumes type: "type_definition Rep Abs A"
huffman@16697
   261
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   262
    and UU_in_A: "\<bottom> \<in> A"
huffman@16697
   263
  shows "Rep \<bottom> = \<bottom>"
huffman@16697
   264
 apply (rule typedef_Abs_strict [OF type less UU_in_A, THEN subst])
huffman@16697
   265
 apply (rule type_definition.Abs_inverse [OF type UU_in_A])
huffman@16697
   266
done
huffman@16697
   267
huffman@16697
   268
theorem typedef_Abs_defined:
huffman@16697
   269
  assumes type: "type_definition Rep Abs A"
huffman@16697
   270
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   271
    and UU_in_A: "\<bottom> \<in> A"
huffman@16697
   272
  shows "\<lbrakk>x \<noteq> \<bottom>; x \<in> A\<rbrakk> \<Longrightarrow> Abs x \<noteq> \<bottom>"
huffman@16697
   273
 apply (rule typedef_Abs_strict [OF type less UU_in_A, THEN subst])
huffman@16697
   274
 apply (simp add: type_definition.Abs_inject [OF type] UU_in_A)
huffman@16697
   275
done
huffman@16697
   276
huffman@16697
   277
theorem typedef_Rep_defined:
huffman@16697
   278
  assumes type: "type_definition Rep Abs A"
huffman@16697
   279
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   280
    and UU_in_A: "\<bottom> \<in> A"
huffman@16697
   281
  shows "x \<noteq> \<bottom> \<Longrightarrow> Rep x \<noteq> \<bottom>"
huffman@16697
   282
 apply (rule typedef_Rep_strict [OF type less UU_in_A, THEN subst])
huffman@16697
   283
 apply (simp add: type_definition.Rep_inject [OF type])
huffman@16697
   284
done
huffman@16697
   285
huffman@19519
   286
subsection {* Proving a subtype is flat *}
huffman@19519
   287
huffman@19519
   288
theorem typedef_flat:
huffman@19519
   289
  fixes Abs :: "'a::flat \<Rightarrow> 'b::pcpo"
huffman@19519
   290
  assumes type: "type_definition Rep Abs A"
huffman@19519
   291
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@19519
   292
    and UU_in_A: "\<bottom> \<in> A"
huffman@19519
   293
  shows "OFCLASS('b, flat_class)"
huffman@19519
   294
 apply (intro_classes)
huffman@19519
   295
 apply (unfold less)
huffman@19519
   296
 apply (simp add: type_definition.Rep_inject [OF type, symmetric])
huffman@19519
   297
 apply (simp add: typedef_Rep_strict [OF type less UU_in_A])
huffman@19519
   298
 apply (simp add: ax_flat)
huffman@19519
   299
done
huffman@19519
   300
huffman@16697
   301
subsection {* HOLCF type definition package *}
huffman@16697
   302
wenzelm@23152
   303
use "Tools/pcpodef_package.ML"
huffman@16697
   304
huffman@16697
   305
end