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