src/HOLCF/Bifinite.thy
author huffman
Thu Jun 12 22:41:03 2008 +0200 (2008-06-12)
changeset 27186 416d66c36d8f
parent 26962 c8b20f615d6c
child 27309 c74270fd72a8
permissions -rw-r--r--
add lemma finite_image_approx; remove unnecessary sort annotations
huffman@25903
     1
(*  Title:      HOLCF/Bifinite.thy
huffman@25903
     2
    ID:         $Id$
huffman@25903
     3
    Author:     Brian Huffman
huffman@25903
     4
*)
huffman@25903
     5
huffman@25903
     6
header {* Bifinite domains and approximation *}
huffman@25903
     7
huffman@25903
     8
theory Bifinite
huffman@25903
     9
imports Cfun
huffman@25903
    10
begin
huffman@25903
    11
huffman@26407
    12
subsection {* Omega-profinite and bifinite domains *}
huffman@25903
    13
huffman@26962
    14
class profinite = cpo +
huffman@26962
    15
  fixes approx :: "nat \<Rightarrow> 'a \<rightarrow> 'a"
huffman@26962
    16
  assumes chain_approx_app: "chain (\<lambda>i. approx i\<cdot>x)"
huffman@26962
    17
  assumes lub_approx_app [simp]: "(\<Squnion>i. approx i\<cdot>x) = x"
huffman@26962
    18
  assumes approx_idem: "approx i\<cdot>(approx i\<cdot>x) = approx i\<cdot>x"
huffman@26962
    19
  assumes finite_fixes_approx: "finite {x. approx i\<cdot>x = x}"
huffman@25903
    20
huffman@26962
    21
class bifinite = profinite + pcpo
huffman@25909
    22
huffman@25903
    23
lemma finite_range_imp_finite_fixes:
huffman@25903
    24
  "finite {x. \<exists>y. x = f y} \<Longrightarrow> finite {x. f x = x}"
huffman@25903
    25
apply (subgoal_tac "{x. f x = x} \<subseteq> {x. \<exists>y. x = f y}")
huffman@25903
    26
apply (erule (1) finite_subset)
huffman@25903
    27
apply (clarify, erule subst, rule exI, rule refl)
huffman@25903
    28
done
huffman@25903
    29
huffman@27186
    30
lemma chain_approx [simp]: "chain approx"
huffman@25903
    31
apply (rule chainI)
huffman@25903
    32
apply (rule less_cfun_ext)
huffman@25903
    33
apply (rule chainE)
huffman@25903
    34
apply (rule chain_approx_app)
huffman@25903
    35
done
huffman@25903
    36
huffman@27186
    37
lemma lub_approx [simp]: "(\<Squnion>i. approx i) = (\<Lambda> x. x)"
huffman@25903
    38
by (rule ext_cfun, simp add: contlub_cfun_fun)
huffman@25903
    39
huffman@27186
    40
lemma approx_less: "approx i\<cdot>x \<sqsubseteq> x"
huffman@25903
    41
apply (subgoal_tac "approx i\<cdot>x \<sqsubseteq> (\<Squnion>i. approx i\<cdot>x)", simp)
huffman@25903
    42
apply (rule is_ub_thelub, simp)
huffman@25903
    43
done
huffman@25903
    44
huffman@25903
    45
lemma approx_strict [simp]: "approx i\<cdot>(\<bottom>::'a::bifinite) = \<bottom>"
huffman@25903
    46
by (rule UU_I, rule approx_less)
huffman@25903
    47
huffman@25903
    48
lemma approx_approx1:
huffman@27186
    49
  "i \<le> j \<Longrightarrow> approx i\<cdot>(approx j\<cdot>x) = approx i\<cdot>x"
huffman@25903
    50
apply (rule antisym_less)
huffman@25903
    51
apply (rule monofun_cfun_arg [OF approx_less])
huffman@25903
    52
apply (rule sq_ord_eq_less_trans [OF approx_idem [symmetric]])
huffman@25903
    53
apply (rule monofun_cfun_arg)
huffman@25903
    54
apply (rule monofun_cfun_fun)
huffman@25922
    55
apply (erule chain_mono [OF chain_approx])
huffman@25903
    56
done
huffman@25903
    57
huffman@25903
    58
lemma approx_approx2:
huffman@27186
    59
  "j \<le> i \<Longrightarrow> approx i\<cdot>(approx j\<cdot>x) = approx j\<cdot>x"
huffman@25903
    60
apply (rule antisym_less)
huffman@25903
    61
apply (rule approx_less)
huffman@25903
    62
apply (rule sq_ord_eq_less_trans [OF approx_idem [symmetric]])
huffman@25903
    63
apply (rule monofun_cfun_fun)
huffman@25922
    64
apply (erule chain_mono [OF chain_approx])
huffman@25903
    65
done
huffman@25903
    66
huffman@25903
    67
lemma approx_approx [simp]:
huffman@27186
    68
  "approx i\<cdot>(approx j\<cdot>x) = approx (min i j)\<cdot>x"
huffman@25903
    69
apply (rule_tac x=i and y=j in linorder_le_cases)
huffman@25903
    70
apply (simp add: approx_approx1 min_def)
huffman@25903
    71
apply (simp add: approx_approx2 min_def)
huffman@25903
    72
done
huffman@25903
    73
huffman@25903
    74
lemma idem_fixes_eq_range:
huffman@25903
    75
  "\<forall>x. f (f x) = f x \<Longrightarrow> {x. f x = x} = {y. \<exists>x. y = f x}"
huffman@25903
    76
by (auto simp add: eq_sym_conv)
huffman@25903
    77
huffman@27186
    78
lemma finite_approx: "finite {y. \<exists>x. y = approx n\<cdot>x}"
huffman@25903
    79
using finite_fixes_approx by (simp add: idem_fixes_eq_range)
huffman@25903
    80
huffman@27186
    81
lemma finite_image_approx: "finite ((\<lambda>x. approx n\<cdot>x) ` A)"
huffman@27186
    82
by (rule finite_subset [OF _ finite_fixes_approx [where i=n]]) auto
huffman@25903
    83
huffman@27186
    84
lemma finite_range_approx: "finite (range (\<lambda>x. approx n\<cdot>x))"
huffman@27186
    85
by (rule finite_image_approx)
huffman@27186
    86
huffman@27186
    87
lemma compact_approx [simp]: "compact (approx n\<cdot>x)"
huffman@25903
    88
proof (rule compactI2)
huffman@25903
    89
  fix Y::"nat \<Rightarrow> 'a"
huffman@25903
    90
  assume Y: "chain Y"
huffman@25903
    91
  have "finite_chain (\<lambda>i. approx n\<cdot>(Y i))"
huffman@25903
    92
  proof (rule finite_range_imp_finch)
huffman@25903
    93
    show "chain (\<lambda>i. approx n\<cdot>(Y i))"
huffman@25903
    94
      using Y by simp
huffman@25903
    95
    have "range (\<lambda>i. approx n\<cdot>(Y i)) \<subseteq> {x. approx n\<cdot>x = x}"
huffman@25903
    96
      by clarsimp
huffman@25903
    97
    thus "finite (range (\<lambda>i. approx n\<cdot>(Y i)))"
huffman@25903
    98
      using finite_fixes_approx by (rule finite_subset)
huffman@25903
    99
  qed
huffman@25903
   100
  hence "\<exists>j. (\<Squnion>i. approx n\<cdot>(Y i)) = approx n\<cdot>(Y j)"
huffman@25903
   101
    by (simp add: finite_chain_def maxinch_is_thelub Y)
huffman@25903
   102
  then obtain j where j: "(\<Squnion>i. approx n\<cdot>(Y i)) = approx n\<cdot>(Y j)" ..
huffman@25903
   103
huffman@25903
   104
  assume "approx n\<cdot>x \<sqsubseteq> (\<Squnion>i. Y i)"
huffman@25903
   105
  hence "approx n\<cdot>(approx n\<cdot>x) \<sqsubseteq> approx n\<cdot>(\<Squnion>i. Y i)"
huffman@25903
   106
    by (rule monofun_cfun_arg)
huffman@25903
   107
  hence "approx n\<cdot>x \<sqsubseteq> (\<Squnion>i. approx n\<cdot>(Y i))"
huffman@25903
   108
    by (simp add: contlub_cfun_arg Y)
huffman@25903
   109
  hence "approx n\<cdot>x \<sqsubseteq> approx n\<cdot>(Y j)"
huffman@25903
   110
    using j by simp
huffman@25903
   111
  hence "approx n\<cdot>x \<sqsubseteq> Y j"
huffman@25903
   112
    using approx_less by (rule trans_less)
huffman@25903
   113
  thus "\<exists>j. approx n\<cdot>x \<sqsubseteq> Y j" ..
huffman@25903
   114
qed
huffman@25903
   115
huffman@25903
   116
lemma bifinite_compact_eq_approx:
huffman@25903
   117
  assumes x: "compact x"
huffman@25903
   118
  shows "\<exists>i. approx i\<cdot>x = x"
huffman@25903
   119
proof -
huffman@25903
   120
  have chain: "chain (\<lambda>i. approx i\<cdot>x)" by simp
huffman@25903
   121
  have less: "x \<sqsubseteq> (\<Squnion>i. approx i\<cdot>x)" by simp
huffman@25903
   122
  obtain i where i: "x \<sqsubseteq> approx i\<cdot>x"
huffman@25903
   123
    using compactD2 [OF x chain less] ..
huffman@25903
   124
  with approx_less have "approx i\<cdot>x = x"
huffman@25903
   125
    by (rule antisym_less)
huffman@25903
   126
  thus "\<exists>i. approx i\<cdot>x = x" ..
huffman@25903
   127
qed
huffman@25903
   128
huffman@25903
   129
lemma bifinite_compact_iff:
huffman@27186
   130
  "compact x \<longleftrightarrow> (\<exists>n. approx n\<cdot>x = x)"
huffman@25903
   131
 apply (rule iffI)
huffman@25903
   132
  apply (erule bifinite_compact_eq_approx)
huffman@25903
   133
 apply (erule exE)
huffman@25903
   134
 apply (erule subst)
huffman@25903
   135
 apply (rule compact_approx)
huffman@25903
   136
done
huffman@25903
   137
huffman@25903
   138
lemma approx_induct:
huffman@25903
   139
  assumes adm: "adm P" and P: "\<And>n x. P (approx n\<cdot>x)"
huffman@27186
   140
  shows "P x"
huffman@25903
   141
proof -
huffman@25903
   142
  have "P (\<Squnion>n. approx n\<cdot>x)"
huffman@25903
   143
    by (rule admD [OF adm], simp, simp add: P)
huffman@25903
   144
  thus "P x" by simp
huffman@25903
   145
qed
huffman@25903
   146
huffman@27186
   147
lemma bifinite_less_ext: "(\<And>i. approx i\<cdot>x \<sqsubseteq> approx i\<cdot>y) \<Longrightarrow> x \<sqsubseteq> y"
huffman@25903
   148
apply (subgoal_tac "(\<Squnion>i. approx i\<cdot>x) \<sqsubseteq> (\<Squnion>i. approx i\<cdot>y)", simp)
huffman@25923
   149
apply (rule lub_mono, simp, simp, simp)
huffman@25903
   150
done
huffman@25903
   151
huffman@25903
   152
subsection {* Instance for continuous function space *}
huffman@25903
   153
huffman@25903
   154
lemma finite_range_lemma:
huffman@25903
   155
  fixes h :: "'a::cpo \<rightarrow> 'b::cpo"
huffman@25903
   156
  fixes k :: "'c::cpo \<rightarrow> 'd::cpo"
huffman@25903
   157
  shows "\<lbrakk>finite {y. \<exists>x. y = h\<cdot>x}; finite {y. \<exists>x. y = k\<cdot>x}\<rbrakk>
huffman@25903
   158
    \<Longrightarrow> finite {g. \<exists>f. g = (\<Lambda> x. k\<cdot>(f\<cdot>(h\<cdot>x)))}"
huffman@25903
   159
 apply (rule_tac f="\<lambda>g. {(h\<cdot>x, y) |x y. y = g\<cdot>x}" in finite_imageD)
huffman@25903
   160
  apply (rule_tac B="Pow ({y. \<exists>x. y = h\<cdot>x} \<times> {y. \<exists>x. y = k\<cdot>x})"
huffman@25903
   161
           in finite_subset)
huffman@25903
   162
   apply (rule image_subsetI)
huffman@25903
   163
   apply (clarsimp, fast)
huffman@25903
   164
  apply simp
huffman@25903
   165
 apply (rule inj_onI)
huffman@25903
   166
 apply (clarsimp simp add: expand_set_eq)
huffman@25903
   167
 apply (rule ext_cfun, simp)
huffman@25903
   168
 apply (drule_tac x="h\<cdot>x" in spec)
huffman@25903
   169
 apply (drule_tac x="k\<cdot>(f\<cdot>(h\<cdot>x))" in spec)
huffman@25903
   170
 apply (drule iffD1, fast)
huffman@25903
   171
 apply clarsimp
huffman@25903
   172
done
huffman@25903
   173
huffman@26962
   174
instantiation "->" :: (profinite, profinite) profinite
huffman@26962
   175
begin
huffman@25903
   176
huffman@26962
   177
definition
huffman@25903
   178
  approx_cfun_def:
huffman@26962
   179
    "approx = (\<lambda>n. \<Lambda> f x. approx n\<cdot>(f\<cdot>(approx n\<cdot>x)))"
huffman@25903
   180
huffman@26962
   181
instance
huffman@25903
   182
 apply (intro_classes, unfold approx_cfun_def)
huffman@25903
   183
    apply simp
huffman@25903
   184
   apply (simp add: lub_distribs eta_cfun)
huffman@25903
   185
  apply simp
huffman@25903
   186
 apply simp
huffman@25903
   187
 apply (rule finite_range_imp_finite_fixes)
huffman@25903
   188
 apply (intro finite_range_lemma finite_approx)
huffman@25903
   189
done
huffman@25903
   190
huffman@26962
   191
end
huffman@26962
   192
huffman@26407
   193
instance "->" :: (profinite, bifinite) bifinite ..
huffman@25909
   194
huffman@25903
   195
lemma approx_cfun: "approx n\<cdot>f\<cdot>x = approx n\<cdot>(f\<cdot>(approx n\<cdot>x))"
huffman@25903
   196
by (simp add: approx_cfun_def)
huffman@25903
   197
huffman@25903
   198
end