src/HOLCF/Bifinite.thy
author ballarin
Tue Sep 16 12:25:26 2008 +0200 (2008-09-16)
changeset 28234 fc420a5cf72e
parent 27402 253a06dfadce
child 29138 661a8db7e647
child 29237 e90d9d51106b
permissions -rw-r--r--
Do not rely on locale assumption in interpretation.
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@27402
     9
imports Deflation
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@27310
    16
  assumes chain_approx [simp]: "chain approx"
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@27402
    23
lemma approx_less: "approx i\<cdot>x \<sqsubseteq> x"
huffman@27402
    24
proof -
huffman@27402
    25
  have "chain (\<lambda>i. approx i\<cdot>x)" by simp
huffman@27402
    26
  hence "approx i\<cdot>x \<sqsubseteq> (\<Squnion>i. approx i\<cdot>x)" by (rule is_ub_thelub)
huffman@27402
    27
  thus "approx i\<cdot>x \<sqsubseteq> x" by simp
huffman@27402
    28
qed
huffman@27402
    29
huffman@27402
    30
lemma finite_deflation_approx: "finite_deflation (approx i)"
huffman@27402
    31
proof
huffman@27402
    32
  fix x :: 'a
huffman@27402
    33
  show "approx i\<cdot>(approx i\<cdot>x) = approx i\<cdot>x"
huffman@27402
    34
    by (rule approx_idem)
huffman@27402
    35
  show "approx i\<cdot>x \<sqsubseteq> x"
huffman@27402
    36
    by (rule approx_less)
huffman@27402
    37
  show "finite {x. approx i\<cdot>x = x}"
huffman@27402
    38
    by (rule finite_fixes_approx)
huffman@27402
    39
qed
huffman@27402
    40
huffman@27402
    41
interpretation approx: finite_deflation ["approx i"]
huffman@27402
    42
by (rule finite_deflation_approx)
huffman@27402
    43
ballarin@28234
    44
lemma (in deflation) deflation: "deflation d" ..
ballarin@28234
    45
huffman@27402
    46
lemma deflation_approx: "deflation (approx i)"
ballarin@28234
    47
by (rule approx.deflation)
huffman@25903
    48
huffman@27186
    49
lemma lub_approx [simp]: "(\<Squnion>i. approx i) = (\<Lambda> x. x)"
huffman@25903
    50
by (rule ext_cfun, simp add: contlub_cfun_fun)
huffman@25903
    51
huffman@27309
    52
lemma approx_strict [simp]: "approx i\<cdot>\<bottom> = \<bottom>"
huffman@25903
    53
by (rule UU_I, rule approx_less)
huffman@25903
    54
huffman@25903
    55
lemma approx_approx1:
huffman@27186
    56
  "i \<le> j \<Longrightarrow> approx i\<cdot>(approx j\<cdot>x) = approx i\<cdot>x"
huffman@27402
    57
apply (rule deflation_less_comp1 [OF deflation_approx deflation_approx])
huffman@25922
    58
apply (erule chain_mono [OF chain_approx])
huffman@25903
    59
done
huffman@25903
    60
huffman@25903
    61
lemma approx_approx2:
huffman@27186
    62
  "j \<le> i \<Longrightarrow> approx i\<cdot>(approx j\<cdot>x) = approx j\<cdot>x"
huffman@27402
    63
apply (rule deflation_less_comp2 [OF deflation_approx deflation_approx])
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@27402
    74
lemma finite_image_approx: "finite ((\<lambda>x. approx n\<cdot>x) ` A)"
huffman@27402
    75
by (rule approx.finite_image)
huffman@25903
    76
huffman@27402
    77
lemma finite_range_approx: "finite (range (\<lambda>x. approx i\<cdot>x))"
huffman@27402
    78
by (rule approx.finite_range)
huffman@27186
    79
huffman@27186
    80
lemma compact_approx [simp]: "compact (approx n\<cdot>x)"
huffman@27402
    81
by (rule approx.compact)
huffman@25903
    82
huffman@27309
    83
lemma profinite_compact_eq_approx: "compact x \<Longrightarrow> \<exists>i. approx i\<cdot>x = x"
huffman@27402
    84
by (rule admD2, simp_all)
huffman@25903
    85
huffman@27309
    86
lemma profinite_compact_iff: "compact x \<longleftrightarrow> (\<exists>n. approx n\<cdot>x = x)"
huffman@25903
    87
 apply (rule iffI)
huffman@27309
    88
  apply (erule profinite_compact_eq_approx)
huffman@25903
    89
 apply (erule exE)
huffman@25903
    90
 apply (erule subst)
huffman@25903
    91
 apply (rule compact_approx)
huffman@25903
    92
done
huffman@25903
    93
huffman@25903
    94
lemma approx_induct:
huffman@25903
    95
  assumes adm: "adm P" and P: "\<And>n x. P (approx n\<cdot>x)"
huffman@27186
    96
  shows "P x"
huffman@25903
    97
proof -
huffman@25903
    98
  have "P (\<Squnion>n. approx n\<cdot>x)"
huffman@25903
    99
    by (rule admD [OF adm], simp, simp add: P)
huffman@25903
   100
  thus "P x" by simp
huffman@25903
   101
qed
huffman@25903
   102
huffman@27309
   103
lemma profinite_less_ext: "(\<And>i. approx i\<cdot>x \<sqsubseteq> approx i\<cdot>y) \<Longrightarrow> x \<sqsubseteq> y"
huffman@25903
   104
apply (subgoal_tac "(\<Squnion>i. approx i\<cdot>x) \<sqsubseteq> (\<Squnion>i. approx i\<cdot>y)", simp)
huffman@25923
   105
apply (rule lub_mono, simp, simp, simp)
huffman@25903
   106
done
huffman@25903
   107
huffman@25903
   108
subsection {* Instance for continuous function space *}
huffman@25903
   109
huffman@27402
   110
lemma finite_range_cfun_lemma:
huffman@27402
   111
  assumes a: "finite (range (\<lambda>x. a\<cdot>x))"
huffman@27402
   112
  assumes b: "finite (range (\<lambda>y. b\<cdot>y))"
huffman@27402
   113
  shows "finite (range (\<lambda>f. \<Lambda> x. b\<cdot>(f\<cdot>(a\<cdot>x))))"  (is "finite (range ?h)")
huffman@27402
   114
proof (rule finite_imageD)
huffman@27402
   115
  let ?f = "\<lambda>g. range (\<lambda>x. (a\<cdot>x, g\<cdot>x))"
huffman@27402
   116
  show "finite (?f ` range ?h)"
huffman@27402
   117
  proof (rule finite_subset)
huffman@27402
   118
    let ?B = "Pow (range (\<lambda>x. a\<cdot>x) \<times> range (\<lambda>y. b\<cdot>y))"
huffman@27402
   119
    show "?f ` range ?h \<subseteq> ?B"
huffman@27402
   120
      by clarsimp
huffman@27402
   121
    show "finite ?B"
huffman@27402
   122
      by (simp add: a b)
huffman@27402
   123
  qed
huffman@27402
   124
  show "inj_on ?f (range ?h)"
huffman@27402
   125
  proof (rule inj_onI, rule ext_cfun, clarsimp)
huffman@27402
   126
    fix x f g
huffman@27402
   127
    assume "range (\<lambda>x. (a\<cdot>x, b\<cdot>(f\<cdot>(a\<cdot>x)))) = range (\<lambda>x. (a\<cdot>x, b\<cdot>(g\<cdot>(a\<cdot>x))))"
huffman@27402
   128
    hence "range (\<lambda>x. (a\<cdot>x, b\<cdot>(f\<cdot>(a\<cdot>x)))) \<subseteq> range (\<lambda>x. (a\<cdot>x, b\<cdot>(g\<cdot>(a\<cdot>x))))"
huffman@27402
   129
      by (rule equalityD1)
huffman@27402
   130
    hence "(a\<cdot>x, b\<cdot>(f\<cdot>(a\<cdot>x))) \<in> range (\<lambda>x. (a\<cdot>x, b\<cdot>(g\<cdot>(a\<cdot>x))))"
huffman@27402
   131
      by (simp add: subset_eq)
huffman@27402
   132
    then obtain y where "(a\<cdot>x, b\<cdot>(f\<cdot>(a\<cdot>x))) = (a\<cdot>y, b\<cdot>(g\<cdot>(a\<cdot>y)))"
huffman@27402
   133
      by (rule rangeE)
huffman@27402
   134
    thus "b\<cdot>(f\<cdot>(a\<cdot>x)) = b\<cdot>(g\<cdot>(a\<cdot>x))"
huffman@27402
   135
      by clarsimp
huffman@27402
   136
  qed
huffman@27402
   137
qed
huffman@25903
   138
huffman@26962
   139
instantiation "->" :: (profinite, profinite) profinite
huffman@26962
   140
begin
huffman@25903
   141
huffman@26962
   142
definition
huffman@25903
   143
  approx_cfun_def:
huffman@26962
   144
    "approx = (\<lambda>n. \<Lambda> f x. approx n\<cdot>(f\<cdot>(approx n\<cdot>x)))"
huffman@25903
   145
huffman@27402
   146
instance proof
huffman@27402
   147
  show "chain (approx :: nat \<Rightarrow> ('a \<rightarrow> 'b) \<rightarrow> ('a \<rightarrow> 'b))"
huffman@27402
   148
    unfolding approx_cfun_def by simp
huffman@27402
   149
next
huffman@27402
   150
  fix x :: "'a \<rightarrow> 'b"
huffman@27402
   151
  show "(\<Squnion>i. approx i\<cdot>x) = x"
huffman@27402
   152
    unfolding approx_cfun_def
huffman@27402
   153
    by (simp add: lub_distribs eta_cfun)
huffman@27402
   154
next
huffman@27402
   155
  fix i :: nat and x :: "'a \<rightarrow> 'b"
huffman@27402
   156
  show "approx i\<cdot>(approx i\<cdot>x) = approx i\<cdot>x"
huffman@27402
   157
    unfolding approx_cfun_def by simp
huffman@27402
   158
next
huffman@27402
   159
  fix i :: nat
huffman@27402
   160
  show "finite {x::'a \<rightarrow> 'b. approx i\<cdot>x = x}"
huffman@27402
   161
    apply (rule finite_range_imp_finite_fixes)
huffman@27402
   162
    apply (simp add: approx_cfun_def)
huffman@27402
   163
    apply (intro finite_range_cfun_lemma finite_range_approx)
huffman@27402
   164
    done
huffman@27402
   165
qed
huffman@25903
   166
huffman@26962
   167
end
huffman@26962
   168
huffman@26407
   169
instance "->" :: (profinite, bifinite) bifinite ..
huffman@25909
   170
huffman@25903
   171
lemma approx_cfun: "approx n\<cdot>f\<cdot>x = approx n\<cdot>(f\<cdot>(approx n\<cdot>x))"
huffman@25903
   172
by (simp add: approx_cfun_def)
huffman@25903
   173
huffman@25903
   174
end