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