src/HOLCF/Pcpodef.thy
author huffman
Mon Oct 10 04:00:40 2005 +0200 (2005-10-10)
changeset 17812 703005988cfe
parent 16918 d0fdc7b9a33f
child 17833 8631dfe017a8
permissions -rw-r--r--
added theorem typedef_chfin
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
huffman@16697
    10
uses ("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@17812
    33
subsection {* Proving a subtype is chain-finite *}
huffman@17812
    34
huffman@17812
    35
lemma monofun_Rep:
huffman@17812
    36
  assumes less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@17812
    37
  shows "monofun Rep"
huffman@17812
    38
by (rule monofunI, unfold less)
huffman@17812
    39
huffman@17812
    40
lemmas ch2ch_Rep = ch2ch_monofun [OF monofun_Rep]
huffman@17812
    41
lemmas ub2ub_Rep = ub2ub_monofun [OF monofun_Rep]
huffman@17812
    42
huffman@17812
    43
theorem typedef_chfin:
huffman@17812
    44
  fixes Abs :: "'a::chfin \<Rightarrow> 'b::po"
huffman@17812
    45
  assumes type: "type_definition Rep Abs A"
huffman@17812
    46
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@17812
    47
  shows "OFCLASS('b, chfin_class)"
huffman@17812
    48
 apply (intro_classes, clarify)
huffman@17812
    49
 apply (drule ch2ch_Rep [OF less])
huffman@17812
    50
 apply (drule chfin [rule_format])
huffman@17812
    51
 apply (unfold max_in_chain_def)
huffman@17812
    52
 apply (simp add: type_definition.Rep_inject [OF type])
huffman@17812
    53
done
huffman@17812
    54
huffman@17812
    55
huffman@16697
    56
subsection {* Proving a subtype is complete *}
huffman@16697
    57
huffman@16697
    58
text {*
huffman@16697
    59
  A subtype of a cpo is itself a cpo if the ordering is
huffman@16697
    60
  defined in the standard way, and the defining subset
huffman@16697
    61
  is closed with respect to limits of chains.  A set is
huffman@16697
    62
  closed if and only if membership in the set is an
huffman@16697
    63
  admissible predicate.
huffman@16697
    64
*}
huffman@16697
    65
huffman@16918
    66
lemma Abs_inverse_lub_Rep:
huffman@16697
    67
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::po"
huffman@16697
    68
  assumes type: "type_definition Rep Abs A"
huffman@16697
    69
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
    70
    and adm:  "adm (\<lambda>x. x \<in> A)"
huffman@16918
    71
  shows "chain S \<Longrightarrow> Rep (Abs (\<Squnion>i. Rep (S i))) = (\<Squnion>i. Rep (S i))"
huffman@16918
    72
 apply (rule type_definition.Abs_inverse [OF type])
huffman@16918
    73
 apply (erule admD [OF adm ch2ch_Rep [OF less], rule_format])
huffman@16697
    74
 apply (rule type_definition.Rep [OF type])
huffman@16697
    75
done
huffman@16697
    76
huffman@16918
    77
theorem typedef_lub:
huffman@16697
    78
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::po"
huffman@16697
    79
  assumes type: "type_definition Rep Abs A"
huffman@16697
    80
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
    81
    and adm: "adm (\<lambda>x. x \<in> A)"
huffman@16918
    82
  shows "chain S \<Longrightarrow> range S <<| Abs (\<Squnion>i. Rep (S i))"
huffman@16918
    83
 apply (frule ch2ch_Rep [OF less])
huffman@16697
    84
 apply (rule is_lubI)
huffman@16697
    85
  apply (rule ub_rangeI)
huffman@16918
    86
  apply (simp only: less Abs_inverse_lub_Rep [OF type less adm])
huffman@16918
    87
  apply (erule is_ub_thelub)
huffman@16918
    88
 apply (simp only: less Abs_inverse_lub_Rep [OF type less adm])
huffman@16918
    89
 apply (erule is_lub_thelub)
huffman@16918
    90
 apply (erule ub2ub_Rep [OF less])
huffman@16697
    91
done
huffman@16697
    92
huffman@16918
    93
lemmas typedef_thelub = typedef_lub [THEN thelubI, standard]
huffman@16918
    94
huffman@16697
    95
theorem typedef_cpo:
huffman@16697
    96
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::po"
huffman@16697
    97
  assumes type: "type_definition Rep Abs A"
huffman@16697
    98
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
    99
    and adm: "adm (\<lambda>x. x \<in> A)"
huffman@16697
   100
  shows "OFCLASS('b, cpo_class)"
huffman@16918
   101
proof
huffman@16918
   102
  fix S::"nat \<Rightarrow> 'b" assume "chain S"
huffman@16918
   103
  hence "range S <<| Abs (\<Squnion>i. Rep (S i))"
huffman@16918
   104
    by (rule typedef_lub [OF type less adm])
huffman@16918
   105
  thus "\<exists>x. range S <<| x" ..
huffman@16918
   106
qed
huffman@16697
   107
huffman@16697
   108
huffman@16697
   109
subsubsection {* Continuity of @{term Rep} and @{term Abs} *}
huffman@16697
   110
huffman@16697
   111
text {* For any sub-cpo, the @{term Rep} function is continuous. *}
huffman@16697
   112
huffman@16697
   113
theorem typedef_cont_Rep:
huffman@16697
   114
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
huffman@16697
   115
  assumes type: "type_definition Rep Abs A"
huffman@16697
   116
    and less: "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 "cont Rep"
huffman@16697
   119
 apply (rule contI)
huffman@16918
   120
 apply (simp only: typedef_thelub [OF type less adm])
huffman@16918
   121
 apply (simp only: Abs_inverse_lub_Rep [OF type less adm])
huffman@16697
   122
 apply (rule thelubE [OF _ refl])
huffman@16918
   123
 apply (erule ch2ch_Rep [OF less])
huffman@16697
   124
done
huffman@16697
   125
huffman@16697
   126
text {*
huffman@16697
   127
  For a sub-cpo, we can make the @{term Abs} function continuous
huffman@16697
   128
  only if we restrict its domain to the defining subset by
huffman@16697
   129
  composing it with another continuous function.
huffman@16697
   130
*}
huffman@16697
   131
huffman@16918
   132
theorem typedef_is_lubI:
huffman@16918
   133
  assumes less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16918
   134
  shows "range (\<lambda>i. Rep (S i)) <<| Rep x \<Longrightarrow> range S <<| x"
huffman@16918
   135
 apply (rule is_lubI)
huffman@16918
   136
  apply (rule ub_rangeI)
huffman@16918
   137
  apply (subst less)
huffman@16918
   138
  apply (erule is_ub_lub)
huffman@16918
   139
 apply (subst less)
huffman@16918
   140
 apply (erule is_lub_lub)
huffman@16918
   141
 apply (erule ub2ub_Rep [OF less])
huffman@16918
   142
done
huffman@16918
   143
huffman@16697
   144
theorem typedef_cont_Abs:
huffman@16697
   145
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
huffman@16697
   146
  fixes f :: "'c::cpo \<Rightarrow> 'a::cpo"
huffman@16697
   147
  assumes type: "type_definition Rep Abs A"
huffman@16697
   148
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16918
   149
    and adm: "adm (\<lambda>x. x \<in> A)" (* not used *)
huffman@16697
   150
    and f_in_A: "\<And>x. f x \<in> A"
huffman@16697
   151
    and cont_f: "cont f"
huffman@16697
   152
  shows "cont (\<lambda>x. Abs (f x))"
huffman@16697
   153
 apply (rule contI)
huffman@16918
   154
 apply (rule typedef_is_lubI [OF less])
huffman@16918
   155
 apply (simp only: type_definition.Abs_inverse [OF type f_in_A])
huffman@16918
   156
 apply (erule cont_f [THEN contE])
huffman@16697
   157
done
huffman@16697
   158
huffman@16697
   159
subsection {* Proving a subtype is pointed *}
huffman@16697
   160
huffman@16697
   161
text {*
huffman@16697
   162
  A subtype of a cpo has a least element if and only if
huffman@16697
   163
  the defining subset has a least element.
huffman@16697
   164
*}
huffman@16697
   165
huffman@16918
   166
theorem typedef_pcpo_generic:
huffman@16697
   167
  fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo"
huffman@16697
   168
  assumes type: "type_definition Rep Abs A"
huffman@16697
   169
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   170
    and z_in_A: "z \<in> A"
huffman@16697
   171
    and z_least: "\<And>x. x \<in> A \<Longrightarrow> z \<sqsubseteq> x"
huffman@16697
   172
  shows "OFCLASS('b, pcpo_class)"
huffman@16697
   173
 apply (intro_classes)
huffman@16697
   174
 apply (rule_tac x="Abs z" in exI, rule allI)
huffman@16697
   175
 apply (unfold less)
huffman@16697
   176
 apply (subst type_definition.Abs_inverse [OF type z_in_A])
huffman@16697
   177
 apply (rule z_least [OF type_definition.Rep [OF type]])
huffman@16697
   178
done
huffman@16697
   179
huffman@16697
   180
text {*
huffman@16697
   181
  As a special case, a subtype of a pcpo has a least element
huffman@16697
   182
  if the defining subset contains @{term \<bottom>}.
huffman@16697
   183
*}
huffman@16697
   184
huffman@16918
   185
theorem typedef_pcpo:
huffman@16697
   186
  fixes Abs :: "'a::pcpo \<Rightarrow> 'b::cpo"
huffman@16697
   187
  assumes type: "type_definition Rep Abs A"
huffman@16697
   188
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   189
    and UU_in_A: "\<bottom> \<in> A"
huffman@16697
   190
  shows "OFCLASS('b, pcpo_class)"
huffman@16918
   191
by (rule typedef_pcpo_generic [OF type less UU_in_A], rule minimal)
huffman@16697
   192
huffman@16697
   193
subsubsection {* Strictness of @{term Rep} and @{term Abs} *}
huffman@16697
   194
huffman@16697
   195
text {*
huffman@16697
   196
  For a sub-pcpo where @{term \<bottom>} is a member of the defining
huffman@16697
   197
  subset, @{term Rep} and @{term Abs} are both strict.
huffman@16697
   198
*}
huffman@16697
   199
huffman@16697
   200
theorem typedef_Abs_strict:
huffman@16697
   201
  assumes type: "type_definition Rep Abs A"
huffman@16697
   202
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   203
    and UU_in_A: "\<bottom> \<in> A"
huffman@16697
   204
  shows "Abs \<bottom> = \<bottom>"
huffman@16697
   205
 apply (rule UU_I, unfold less)
huffman@16697
   206
 apply (simp add: type_definition.Abs_inverse [OF type UU_in_A])
huffman@16697
   207
done
huffman@16697
   208
huffman@16697
   209
theorem typedef_Rep_strict:
huffman@16697
   210
  assumes type: "type_definition Rep Abs A"
huffman@16697
   211
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   212
    and UU_in_A: "\<bottom> \<in> A"
huffman@16697
   213
  shows "Rep \<bottom> = \<bottom>"
huffman@16697
   214
 apply (rule typedef_Abs_strict [OF type less UU_in_A, THEN subst])
huffman@16697
   215
 apply (rule type_definition.Abs_inverse [OF type UU_in_A])
huffman@16697
   216
done
huffman@16697
   217
huffman@16697
   218
theorem typedef_Abs_defined:
huffman@16697
   219
  assumes type: "type_definition Rep Abs A"
huffman@16697
   220
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   221
    and UU_in_A: "\<bottom> \<in> A"
huffman@16697
   222
  shows "\<lbrakk>x \<noteq> \<bottom>; x \<in> A\<rbrakk> \<Longrightarrow> Abs x \<noteq> \<bottom>"
huffman@16697
   223
 apply (rule typedef_Abs_strict [OF type less UU_in_A, THEN subst])
huffman@16697
   224
 apply (simp add: type_definition.Abs_inject [OF type] UU_in_A)
huffman@16697
   225
done
huffman@16697
   226
huffman@16697
   227
theorem typedef_Rep_defined:
huffman@16697
   228
  assumes type: "type_definition Rep Abs A"
huffman@16697
   229
    and less: "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y"
huffman@16697
   230
    and UU_in_A: "\<bottom> \<in> A"
huffman@16697
   231
  shows "x \<noteq> \<bottom> \<Longrightarrow> Rep x \<noteq> \<bottom>"
huffman@16697
   232
 apply (rule typedef_Rep_strict [OF type less UU_in_A, THEN subst])
huffman@16697
   233
 apply (simp add: type_definition.Rep_inject [OF type])
huffman@16697
   234
done
huffman@16697
   235
huffman@16697
   236
subsection {* HOLCF type definition package *}
huffman@16697
   237
huffman@16697
   238
use "pcpodef_package.ML"
huffman@16697
   239
huffman@16697
   240
end