src/HOL/HOLCF/Cpodef.thy
author wenzelm
Thu Mar 15 22:08:53 2012 +0100 (2012-03-15)
changeset 46950 d0181abdbdac
parent 45606 b1e1508643b1
child 48891 c0eafbd55de3
permissions -rw-r--r--
declare command keywords via theory header, including strict checking outside Pure;
wenzelm@42151
     1
(*  Title:      HOL/HOLCF/Cpodef.thy
huffman@16697
     2
    Author:     Brian Huffman
huffman@16697
     3
*)
huffman@16697
     4
huffman@16697
     5
header {* Subtypes of pcpos *}
huffman@16697
     6
huffman@40772
     7
theory Cpodef
huffman@16697
     8
imports Adm
wenzelm@46950
     9
keywords "pcpodef" "cpodef" :: thy_goal
huffman@40772
    10
uses ("Tools/cpodef.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@31076
    20
setup {* Sign.add_const_constraint (@{const_name Porder.below}, NONE) *}
haftmann@28073
    21
huffman@16697
    22
theorem typedef_po:
haftmann@28073
    23
  fixes Abs :: "'a::po \<Rightarrow> 'b::type"
huffman@16697
    24
  assumes type: "type_definition Rep Abs A"
huffman@31076
    25
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
    26
  shows "OFCLASS('b, po_class)"
huffman@31076
    27
 apply (intro_classes, unfold below)
huffman@31076
    28
   apply (rule below_refl)
huffman@31076
    29
  apply (erule (1) below_trans)
huffman@26420
    30
 apply (rule type_definition.Rep_inject [OF type, THEN iffD1])
huffman@31076
    31
 apply (erule (1) below_antisym)
huffman@16697
    32
done
huffman@16697
    33
huffman@31076
    34
setup {* Sign.add_const_constraint (@{const_name Porder.below},
huffman@31076
    35
  SOME @{typ "'a::below \<Rightarrow> 'a::below \<Rightarrow> bool"}) *}
haftmann@28073
    36
huffman@25827
    37
subsection {* Proving a subtype is finite *}
huffman@25827
    38
huffman@27296
    39
lemma typedef_finite_UNIV:
huffman@27296
    40
  fixes Abs :: "'a::type \<Rightarrow> 'b::type"
huffman@27296
    41
  assumes type: "type_definition Rep Abs A"
huffman@27296
    42
  shows "finite A \<Longrightarrow> finite (UNIV :: 'b set)"
huffman@25827
    43
proof -
huffman@25827
    44
  assume "finite A"
huffman@25827
    45
  hence "finite (Abs ` A)" by (rule finite_imageI)
huffman@27296
    46
  thus "finite (UNIV :: 'b set)"
huffman@27296
    47
    by (simp only: type_definition.Abs_image [OF type])
huffman@25827
    48
qed
huffman@25827
    49
huffman@17812
    50
subsection {* Proving a subtype is chain-finite *}
huffman@17812
    51
huffman@40035
    52
lemma ch2ch_Rep:
huffman@31076
    53
  assumes below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@40035
    54
  shows "chain S \<Longrightarrow> chain (\<lambda>i. Rep (S i))"
huffman@40035
    55
unfolding chain_def below .
huffman@17812
    56
huffman@17812
    57
theorem typedef_chfin:
huffman@17812
    58
  fixes Abs :: "'a::chfin \<Rightarrow> 'b::po"
huffman@17812
    59
  assumes type: "type_definition Rep Abs A"
huffman@31076
    60
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@17812
    61
  shows "OFCLASS('b, chfin_class)"
huffman@25921
    62
 apply intro_classes
huffman@31076
    63
 apply (drule ch2ch_Rep [OF below])
huffman@25921
    64
 apply (drule chfin)
huffman@17812
    65
 apply (unfold max_in_chain_def)
huffman@17812
    66
 apply (simp add: type_definition.Rep_inject [OF type])
huffman@17812
    67
done
huffman@17812
    68
huffman@16697
    69
subsection {* Proving a subtype is complete *}
huffman@16697
    70
huffman@16697
    71
text {*
huffman@16697
    72
  A subtype of a cpo is itself a cpo if the ordering is
huffman@16697
    73
  defined in the standard way, and the defining subset
huffman@16697
    74
  is closed with respect to limits of chains.  A set is
huffman@16697
    75
  closed if and only if membership in the set is an
huffman@16697
    76
  admissible predicate.
huffman@16697
    77
*}
huffman@16697
    78
huffman@40035
    79
lemma typedef_is_lubI:
huffman@40035
    80
  assumes below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@40035
    81
  shows "range (\<lambda>i. Rep (S i)) <<| Rep x \<Longrightarrow> range S <<| x"
huffman@40035
    82
unfolding is_lub_def is_ub_def below by simp
huffman@40035
    83
huffman@16918
    84
lemma Abs_inverse_lub_Rep:
huffman@16697
    85
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::po"
huffman@16697
    86
  assumes type: "type_definition Rep Abs A"
huffman@31076
    87
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
    88
    and adm:  "adm (\<lambda>x. x \<in> A)"
huffman@16918
    89
  shows "chain S \<Longrightarrow> Rep (Abs (\<Squnion>i. Rep (S i))) = (\<Squnion>i. Rep (S i))"
huffman@16918
    90
 apply (rule type_definition.Abs_inverse [OF type])
huffman@31076
    91
 apply (erule admD [OF adm ch2ch_Rep [OF below]])
huffman@16697
    92
 apply (rule type_definition.Rep [OF type])
huffman@16697
    93
done
huffman@16697
    94
huffman@40770
    95
theorem typedef_is_lub:
huffman@16697
    96
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::po"
huffman@16697
    97
  assumes type: "type_definition Rep Abs A"
huffman@31076
    98
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
    99
    and adm: "adm (\<lambda>x. x \<in> A)"
huffman@16918
   100
  shows "chain S \<Longrightarrow> range S <<| Abs (\<Squnion>i. Rep (S i))"
huffman@40035
   101
proof -
huffman@40035
   102
  assume S: "chain S"
huffman@40035
   103
  hence "chain (\<lambda>i. Rep (S i))" by (rule ch2ch_Rep [OF below])
huffman@40035
   104
  hence "range (\<lambda>i. Rep (S i)) <<| (\<Squnion>i. Rep (S i))" by (rule cpo_lubI)
huffman@40035
   105
  hence "range (\<lambda>i. Rep (S i)) <<| Rep (Abs (\<Squnion>i. Rep (S i)))"
huffman@40035
   106
    by (simp only: Abs_inverse_lub_Rep [OF type below adm S])
huffman@40035
   107
  thus "range S <<| Abs (\<Squnion>i. Rep (S i))"
huffman@40035
   108
    by (rule typedef_is_lubI [OF below])
huffman@40035
   109
qed
huffman@16697
   110
wenzelm@45606
   111
lemmas typedef_lub = typedef_is_lub [THEN lub_eqI]
huffman@16918
   112
huffman@16697
   113
theorem typedef_cpo:
huffman@16697
   114
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::po"
huffman@16697
   115
  assumes type: "type_definition Rep Abs A"
huffman@31076
   116
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   117
    and adm: "adm (\<lambda>x. x \<in> A)"
huffman@16697
   118
  shows "OFCLASS('b, cpo_class)"
huffman@16918
   119
proof
huffman@16918
   120
  fix S::"nat \<Rightarrow> 'b" assume "chain S"
huffman@16918
   121
  hence "range S <<| Abs (\<Squnion>i. Rep (S i))"
huffman@40770
   122
    by (rule typedef_is_lub [OF type below adm])
huffman@16918
   123
  thus "\<exists>x. range S <<| x" ..
huffman@16918
   124
qed
huffman@16697
   125
huffman@35900
   126
subsubsection {* Continuity of \emph{Rep} and \emph{Abs} *}
huffman@16697
   127
huffman@16697
   128
text {* For any sub-cpo, the @{term Rep} function is continuous. *}
huffman@16697
   129
huffman@16697
   130
theorem typedef_cont_Rep:
huffman@16697
   131
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
huffman@16697
   132
  assumes type: "type_definition Rep Abs A"
huffman@31076
   133
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   134
    and adm: "adm (\<lambda>x. x \<in> A)"
huffman@40834
   135
  shows "cont (\<lambda>x. f x) \<Longrightarrow> cont (\<lambda>x. Rep (f x))"
huffman@40834
   136
 apply (erule cont_apply [OF _ _ cont_const])
huffman@16697
   137
 apply (rule contI)
huffman@40770
   138
 apply (simp only: typedef_lub [OF type below adm])
huffman@31076
   139
 apply (simp only: Abs_inverse_lub_Rep [OF type below adm])
huffman@26027
   140
 apply (rule cpo_lubI)
huffman@31076
   141
 apply (erule ch2ch_Rep [OF below])
huffman@16697
   142
done
huffman@16697
   143
huffman@16697
   144
text {*
huffman@16697
   145
  For a sub-cpo, we can make the @{term Abs} function continuous
huffman@16697
   146
  only if we restrict its domain to the defining subset by
huffman@16697
   147
  composing it with another continuous function.
huffman@16697
   148
*}
huffman@16697
   149
huffman@16697
   150
theorem typedef_cont_Abs:
huffman@16697
   151
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
huffman@16697
   152
  fixes f :: "'c::cpo \<Rightarrow> 'a::cpo"
huffman@16697
   153
  assumes type: "type_definition Rep Abs A"
huffman@31076
   154
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16918
   155
    and adm: "adm (\<lambda>x. x \<in> A)" (* not used *)
huffman@16697
   156
    and f_in_A: "\<And>x. f x \<in> A"
huffman@40325
   157
  shows "cont f \<Longrightarrow> cont (\<lambda>x. Abs (f x))"
huffman@40325
   158
unfolding cont_def is_lub_def is_ub_def ball_simps below
huffman@40325
   159
by (simp add: type_definition.Abs_inverse [OF type f_in_A])
huffman@16697
   160
huffman@17833
   161
subsection {* Proving subtype elements are compact *}
huffman@17833
   162
huffman@17833
   163
theorem typedef_compact:
huffman@17833
   164
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
huffman@17833
   165
  assumes type: "type_definition Rep Abs A"
huffman@31076
   166
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@17833
   167
    and adm: "adm (\<lambda>x. x \<in> A)"
huffman@17833
   168
  shows "compact (Rep k) \<Longrightarrow> compact k"
huffman@17833
   169
proof (unfold compact_def)
huffman@17833
   170
  have cont_Rep: "cont Rep"
huffman@40834
   171
    by (rule typedef_cont_Rep [OF type below adm cont_id])
huffman@41182
   172
  assume "adm (\<lambda>x. Rep k \<notsqsubseteq> x)"
huffman@41182
   173
  with cont_Rep have "adm (\<lambda>x. Rep k \<notsqsubseteq> Rep x)" by (rule adm_subst)
huffman@41182
   174
  thus "adm (\<lambda>x. k \<notsqsubseteq> x)" by (unfold below)
huffman@17833
   175
qed
huffman@17833
   176
huffman@16697
   177
subsection {* Proving a subtype is pointed *}
huffman@16697
   178
huffman@16697
   179
text {*
huffman@16697
   180
  A subtype of a cpo has a least element if and only if
huffman@16697
   181
  the defining subset has a least element.
huffman@16697
   182
*}
huffman@16697
   183
huffman@16918
   184
theorem typedef_pcpo_generic:
huffman@16697
   185
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
huffman@16697
   186
  assumes type: "type_definition Rep Abs A"
huffman@31076
   187
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   188
    and z_in_A: "z \<in> A"
huffman@16697
   189
    and z_least: "\<And>x. x \<in> A \<Longrightarrow> z \<sqsubseteq> x"
huffman@16697
   190
  shows "OFCLASS('b, pcpo_class)"
huffman@16697
   191
 apply (intro_classes)
huffman@16697
   192
 apply (rule_tac x="Abs z" in exI, rule allI)
huffman@31076
   193
 apply (unfold below)
huffman@16697
   194
 apply (subst type_definition.Abs_inverse [OF type z_in_A])
huffman@16697
   195
 apply (rule z_least [OF type_definition.Rep [OF type]])
huffman@16697
   196
done
huffman@16697
   197
huffman@16697
   198
text {*
huffman@16697
   199
  As a special case, a subtype of a pcpo has a least element
huffman@16697
   200
  if the defining subset contains @{term \<bottom>}.
huffman@16697
   201
*}
huffman@16697
   202
huffman@16918
   203
theorem typedef_pcpo:
huffman@16697
   204
  fixes Abs :: "'a::pcpo \<Rightarrow> 'b::cpo"
huffman@16697
   205
  assumes type: "type_definition Rep Abs A"
huffman@31076
   206
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@41430
   207
    and bottom_in_A: "\<bottom> \<in> A"
huffman@16697
   208
  shows "OFCLASS('b, pcpo_class)"
huffman@41430
   209
by (rule typedef_pcpo_generic [OF type below bottom_in_A], rule minimal)
huffman@16697
   210
huffman@35900
   211
subsubsection {* Strictness of \emph{Rep} and \emph{Abs} *}
huffman@16697
   212
huffman@16697
   213
text {*
huffman@16697
   214
  For a sub-pcpo where @{term \<bottom>} is a member of the defining
huffman@16697
   215
  subset, @{term Rep} and @{term Abs} are both strict.
huffman@16697
   216
*}
huffman@16697
   217
huffman@16697
   218
theorem typedef_Abs_strict:
huffman@16697
   219
  assumes type: "type_definition Rep Abs A"
huffman@31076
   220
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@41430
   221
    and bottom_in_A: "\<bottom> \<in> A"
huffman@16697
   222
  shows "Abs \<bottom> = \<bottom>"
huffman@41430
   223
 apply (rule bottomI, unfold below)
huffman@41430
   224
 apply (simp add: type_definition.Abs_inverse [OF type bottom_in_A])
huffman@16697
   225
done
huffman@16697
   226
huffman@16697
   227
theorem typedef_Rep_strict:
huffman@16697
   228
  assumes type: "type_definition Rep Abs A"
huffman@31076
   229
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@41430
   230
    and bottom_in_A: "\<bottom> \<in> A"
huffman@16697
   231
  shows "Rep \<bottom> = \<bottom>"
huffman@41430
   232
 apply (rule typedef_Abs_strict [OF type below bottom_in_A, THEN subst])
huffman@41430
   233
 apply (rule type_definition.Abs_inverse [OF type bottom_in_A])
huffman@16697
   234
done
huffman@16697
   235
huffman@40321
   236
theorem typedef_Abs_bottom_iff:
huffman@25926
   237
  assumes type: "type_definition Rep Abs A"
huffman@31076
   238
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@41430
   239
    and bottom_in_A: "\<bottom> \<in> A"
huffman@25926
   240
  shows "x \<in> A \<Longrightarrow> (Abs x = \<bottom>) = (x = \<bottom>)"
huffman@41430
   241
 apply (rule typedef_Abs_strict [OF type below bottom_in_A, THEN subst])
huffman@41430
   242
 apply (simp add: type_definition.Abs_inject [OF type] bottom_in_A)
huffman@25926
   243
done
huffman@25926
   244
huffman@40321
   245
theorem typedef_Rep_bottom_iff:
huffman@25926
   246
  assumes type: "type_definition Rep Abs A"
huffman@31076
   247
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@41430
   248
    and bottom_in_A: "\<bottom> \<in> A"
huffman@25926
   249
  shows "(Rep x = \<bottom>) = (x = \<bottom>)"
huffman@41430
   250
 apply (rule typedef_Rep_strict [OF type below bottom_in_A, THEN subst])
huffman@25926
   251
 apply (simp add: type_definition.Rep_inject [OF type])
huffman@25926
   252
done
huffman@25926
   253
huffman@19519
   254
subsection {* Proving a subtype is flat *}
huffman@19519
   255
huffman@19519
   256
theorem typedef_flat:
huffman@19519
   257
  fixes Abs :: "'a::flat \<Rightarrow> 'b::pcpo"
huffman@19519
   258
  assumes type: "type_definition Rep Abs A"
huffman@31076
   259
    and below: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@41430
   260
    and bottom_in_A: "\<bottom> \<in> A"
huffman@19519
   261
  shows "OFCLASS('b, flat_class)"
huffman@19519
   262
 apply (intro_classes)
huffman@31076
   263
 apply (unfold below)
huffman@19519
   264
 apply (simp add: type_definition.Rep_inject [OF type, symmetric])
huffman@41430
   265
 apply (simp add: typedef_Rep_strict [OF type below bottom_in_A])
huffman@19519
   266
 apply (simp add: ax_flat)
huffman@19519
   267
done
huffman@19519
   268
huffman@16697
   269
subsection {* HOLCF type definition package *}
huffman@16697
   270
huffman@40772
   271
use "Tools/cpodef.ML"
huffman@16697
   272
huffman@16697
   273
end