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