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