src/HOLCF/Domain_Aux.thy
author huffman
Mon Mar 08 09:33:05 2010 -0800 (2010-03-08)
changeset 35653 f87132febfac
parent 35652 05ca920cd94b
child 35655 e8e4af6da819
permissions -rw-r--r--
move lemmas from Domain.thy to Domain_Aux.thy
huffman@35652
     1
(*  Title:      HOLCF/Domain_Aux.thy
huffman@35652
     2
    Author:     Brian Huffman
huffman@35652
     3
*)
huffman@35652
     4
huffman@35652
     5
header {* Domain package support *}
huffman@35652
     6
huffman@35652
     7
theory Domain_Aux
huffman@35652
     8
imports Ssum Sprod Fixrec
huffman@35652
     9
uses
huffman@35652
    10
  ("Tools/Domain/domain_take_proofs.ML")
huffman@35652
    11
begin
huffman@35652
    12
huffman@35653
    13
subsection {* Continuous isomorphisms *}
huffman@35653
    14
huffman@35653
    15
text {* A locale for continuous isomorphisms *}
huffman@35653
    16
huffman@35653
    17
locale iso =
huffman@35653
    18
  fixes abs :: "'a \<rightarrow> 'b"
huffman@35653
    19
  fixes rep :: "'b \<rightarrow> 'a"
huffman@35653
    20
  assumes abs_iso [simp]: "rep\<cdot>(abs\<cdot>x) = x"
huffman@35653
    21
  assumes rep_iso [simp]: "abs\<cdot>(rep\<cdot>y) = y"
huffman@35653
    22
begin
huffman@35653
    23
huffman@35653
    24
lemma swap: "iso rep abs"
huffman@35653
    25
  by (rule iso.intro [OF rep_iso abs_iso])
huffman@35653
    26
huffman@35653
    27
lemma abs_below: "(abs\<cdot>x \<sqsubseteq> abs\<cdot>y) = (x \<sqsubseteq> y)"
huffman@35653
    28
proof
huffman@35653
    29
  assume "abs\<cdot>x \<sqsubseteq> abs\<cdot>y"
huffman@35653
    30
  then have "rep\<cdot>(abs\<cdot>x) \<sqsubseteq> rep\<cdot>(abs\<cdot>y)" by (rule monofun_cfun_arg)
huffman@35653
    31
  then show "x \<sqsubseteq> y" by simp
huffman@35653
    32
next
huffman@35653
    33
  assume "x \<sqsubseteq> y"
huffman@35653
    34
  then show "abs\<cdot>x \<sqsubseteq> abs\<cdot>y" by (rule monofun_cfun_arg)
huffman@35653
    35
qed
huffman@35653
    36
huffman@35653
    37
lemma rep_below: "(rep\<cdot>x \<sqsubseteq> rep\<cdot>y) = (x \<sqsubseteq> y)"
huffman@35653
    38
  by (rule iso.abs_below [OF swap])
huffman@35653
    39
huffman@35653
    40
lemma abs_eq: "(abs\<cdot>x = abs\<cdot>y) = (x = y)"
huffman@35653
    41
  by (simp add: po_eq_conv abs_below)
huffman@35653
    42
huffman@35653
    43
lemma rep_eq: "(rep\<cdot>x = rep\<cdot>y) = (x = y)"
huffman@35653
    44
  by (rule iso.abs_eq [OF swap])
huffman@35653
    45
huffman@35653
    46
lemma abs_strict: "abs\<cdot>\<bottom> = \<bottom>"
huffman@35653
    47
proof -
huffman@35653
    48
  have "\<bottom> \<sqsubseteq> rep\<cdot>\<bottom>" ..
huffman@35653
    49
  then have "abs\<cdot>\<bottom> \<sqsubseteq> abs\<cdot>(rep\<cdot>\<bottom>)" by (rule monofun_cfun_arg)
huffman@35653
    50
  then have "abs\<cdot>\<bottom> \<sqsubseteq> \<bottom>" by simp
huffman@35653
    51
  then show ?thesis by (rule UU_I)
huffman@35653
    52
qed
huffman@35653
    53
huffman@35653
    54
lemma rep_strict: "rep\<cdot>\<bottom> = \<bottom>"
huffman@35653
    55
  by (rule iso.abs_strict [OF swap])
huffman@35653
    56
huffman@35653
    57
lemma abs_defin': "abs\<cdot>x = \<bottom> \<Longrightarrow> x = \<bottom>"
huffman@35653
    58
proof -
huffman@35653
    59
  have "x = rep\<cdot>(abs\<cdot>x)" by simp
huffman@35653
    60
  also assume "abs\<cdot>x = \<bottom>"
huffman@35653
    61
  also note rep_strict
huffman@35653
    62
  finally show "x = \<bottom>" .
huffman@35653
    63
qed
huffman@35653
    64
huffman@35653
    65
lemma rep_defin': "rep\<cdot>z = \<bottom> \<Longrightarrow> z = \<bottom>"
huffman@35653
    66
  by (rule iso.abs_defin' [OF swap])
huffman@35653
    67
huffman@35653
    68
lemma abs_defined: "z \<noteq> \<bottom> \<Longrightarrow> abs\<cdot>z \<noteq> \<bottom>"
huffman@35653
    69
  by (erule contrapos_nn, erule abs_defin')
huffman@35653
    70
huffman@35653
    71
lemma rep_defined: "z \<noteq> \<bottom> \<Longrightarrow> rep\<cdot>z \<noteq> \<bottom>"
huffman@35653
    72
  by (rule iso.abs_defined [OF iso.swap]) (rule iso_axioms)
huffman@35653
    73
huffman@35653
    74
lemma abs_defined_iff: "(abs\<cdot>x = \<bottom>) = (x = \<bottom>)"
huffman@35653
    75
  by (auto elim: abs_defin' intro: abs_strict)
huffman@35653
    76
huffman@35653
    77
lemma rep_defined_iff: "(rep\<cdot>x = \<bottom>) = (x = \<bottom>)"
huffman@35653
    78
  by (rule iso.abs_defined_iff [OF iso.swap]) (rule iso_axioms)
huffman@35653
    79
huffman@35653
    80
lemma casedist_rule: "rep\<cdot>x = \<bottom> \<or> P \<Longrightarrow> x = \<bottom> \<or> P"
huffman@35653
    81
  by (simp add: rep_defined_iff)
huffman@35653
    82
huffman@35653
    83
lemma compact_abs_rev: "compact (abs\<cdot>x) \<Longrightarrow> compact x"
huffman@35653
    84
proof (unfold compact_def)
huffman@35653
    85
  assume "adm (\<lambda>y. \<not> abs\<cdot>x \<sqsubseteq> y)"
huffman@35653
    86
  with cont_Rep_CFun2
huffman@35653
    87
  have "adm (\<lambda>y. \<not> abs\<cdot>x \<sqsubseteq> abs\<cdot>y)" by (rule adm_subst)
huffman@35653
    88
  then show "adm (\<lambda>y. \<not> x \<sqsubseteq> y)" using abs_below by simp
huffman@35653
    89
qed
huffman@35653
    90
huffman@35653
    91
lemma compact_rep_rev: "compact (rep\<cdot>x) \<Longrightarrow> compact x"
huffman@35653
    92
  by (rule iso.compact_abs_rev [OF iso.swap]) (rule iso_axioms)
huffman@35653
    93
huffman@35653
    94
lemma compact_abs: "compact x \<Longrightarrow> compact (abs\<cdot>x)"
huffman@35653
    95
  by (rule compact_rep_rev) simp
huffman@35653
    96
huffman@35653
    97
lemma compact_rep: "compact x \<Longrightarrow> compact (rep\<cdot>x)"
huffman@35653
    98
  by (rule iso.compact_abs [OF iso.swap]) (rule iso_axioms)
huffman@35653
    99
huffman@35653
   100
lemma iso_swap: "(x = abs\<cdot>y) = (rep\<cdot>x = y)"
huffman@35653
   101
proof
huffman@35653
   102
  assume "x = abs\<cdot>y"
huffman@35653
   103
  then have "rep\<cdot>x = rep\<cdot>(abs\<cdot>y)" by simp
huffman@35653
   104
  then show "rep\<cdot>x = y" by simp
huffman@35653
   105
next
huffman@35653
   106
  assume "rep\<cdot>x = y"
huffman@35653
   107
  then have "abs\<cdot>(rep\<cdot>x) = abs\<cdot>y" by simp
huffman@35653
   108
  then show "x = abs\<cdot>y" by simp
huffman@35653
   109
qed
huffman@35653
   110
huffman@35653
   111
end
huffman@35653
   112
huffman@35653
   113
huffman@35652
   114
subsection {* Proofs about take functions *}
huffman@35652
   115
huffman@35652
   116
text {*
huffman@35652
   117
  This section contains lemmas that are used in a module that supports
huffman@35652
   118
  the domain isomorphism package; the module contains proofs related
huffman@35652
   119
  to take functions and the finiteness predicate.
huffman@35652
   120
*}
huffman@35652
   121
huffman@35652
   122
lemma deflation_abs_rep:
huffman@35652
   123
  fixes abs and rep and d
huffman@35652
   124
  assumes abs_iso: "\<And>x. rep\<cdot>(abs\<cdot>x) = x"
huffman@35652
   125
  assumes rep_iso: "\<And>y. abs\<cdot>(rep\<cdot>y) = y"
huffman@35652
   126
  shows "deflation d \<Longrightarrow> deflation (abs oo d oo rep)"
huffman@35652
   127
by (rule ep_pair.deflation_e_d_p) (simp add: ep_pair.intro assms)
huffman@35652
   128
huffman@35652
   129
lemma deflation_chain_min:
huffman@35652
   130
  assumes chain: "chain d"
huffman@35652
   131
  assumes defl: "\<And>n. deflation (d n)"
huffman@35652
   132
  shows "d m\<cdot>(d n\<cdot>x) = d (min m n)\<cdot>x"
huffman@35652
   133
proof (rule linorder_le_cases)
huffman@35652
   134
  assume "m \<le> n"
huffman@35652
   135
  with chain have "d m \<sqsubseteq> d n" by (rule chain_mono)
huffman@35652
   136
  then have "d m\<cdot>(d n\<cdot>x) = d m\<cdot>x"
huffman@35652
   137
    by (rule deflation_below_comp1 [OF defl defl])
huffman@35652
   138
  moreover from `m \<le> n` have "min m n = m" by simp
huffman@35652
   139
  ultimately show ?thesis by simp
huffman@35652
   140
next
huffman@35652
   141
  assume "n \<le> m"
huffman@35652
   142
  with chain have "d n \<sqsubseteq> d m" by (rule chain_mono)
huffman@35652
   143
  then have "d m\<cdot>(d n\<cdot>x) = d n\<cdot>x"
huffman@35652
   144
    by (rule deflation_below_comp2 [OF defl defl])
huffman@35652
   145
  moreover from `n \<le> m` have "min m n = n" by simp
huffman@35652
   146
  ultimately show ?thesis by simp
huffman@35652
   147
qed
huffman@35652
   148
huffman@35653
   149
lemma lub_ID_take_lemma:
huffman@35653
   150
  assumes "chain t" and "(\<Squnion>n. t n) = ID"
huffman@35653
   151
  assumes "\<And>n. t n\<cdot>x = t n\<cdot>y" shows "x = y"
huffman@35653
   152
proof -
huffman@35653
   153
  have "(\<Squnion>n. t n\<cdot>x) = (\<Squnion>n. t n\<cdot>y)"
huffman@35653
   154
    using assms(3) by simp
huffman@35653
   155
  then have "(\<Squnion>n. t n)\<cdot>x = (\<Squnion>n. t n)\<cdot>y"
huffman@35653
   156
    using assms(1) by (simp add: lub_distribs)
huffman@35653
   157
  then show "x = y"
huffman@35653
   158
    using assms(2) by simp
huffman@35653
   159
qed
huffman@35653
   160
huffman@35653
   161
lemma lub_ID_reach:
huffman@35653
   162
  assumes "chain t" and "(\<Squnion>n. t n) = ID"
huffman@35653
   163
  shows "(\<Squnion>n. t n\<cdot>x) = x"
huffman@35653
   164
using assms by (simp add: lub_distribs)
huffman@35653
   165
huffman@35653
   166
huffman@35653
   167
subsection {* Finiteness *}
huffman@35653
   168
huffman@35653
   169
text {*
huffman@35653
   170
  Let a ``decisive'' function be a deflation that maps every input to
huffman@35653
   171
  either itself or bottom.  Then if a domain's take functions are all
huffman@35653
   172
  decisive, then all values in the domain are finite.
huffman@35653
   173
*}
huffman@35653
   174
huffman@35653
   175
definition
huffman@35653
   176
  decisive :: "('a::pcpo \<rightarrow> 'a) \<Rightarrow> bool"
huffman@35653
   177
where
huffman@35653
   178
  "decisive d \<longleftrightarrow> (\<forall>x. d\<cdot>x = x \<or> d\<cdot>x = \<bottom>)"
huffman@35653
   179
huffman@35653
   180
lemma decisiveI: "(\<And>x. d\<cdot>x = x \<or> d\<cdot>x = \<bottom>) \<Longrightarrow> decisive d"
huffman@35653
   181
  unfolding decisive_def by simp
huffman@35653
   182
huffman@35653
   183
lemma decisive_cases:
huffman@35653
   184
  assumes "decisive d" obtains "d\<cdot>x = x" | "d\<cdot>x = \<bottom>"
huffman@35653
   185
using assms unfolding decisive_def by auto
huffman@35653
   186
huffman@35653
   187
lemma decisive_bottom: "decisive \<bottom>"
huffman@35653
   188
  unfolding decisive_def by simp
huffman@35653
   189
huffman@35653
   190
lemma decisive_ID: "decisive ID"
huffman@35653
   191
  unfolding decisive_def by simp
huffman@35653
   192
huffman@35653
   193
lemma decisive_ssum_map:
huffman@35653
   194
  assumes f: "decisive f"
huffman@35653
   195
  assumes g: "decisive g"
huffman@35653
   196
  shows "decisive (ssum_map\<cdot>f\<cdot>g)"
huffman@35653
   197
apply (rule decisiveI, rename_tac s)
huffman@35653
   198
apply (case_tac s, simp_all)
huffman@35653
   199
apply (rule_tac x=x in decisive_cases [OF f], simp_all)
huffman@35653
   200
apply (rule_tac x=y in decisive_cases [OF g], simp_all)
huffman@35653
   201
done
huffman@35653
   202
huffman@35653
   203
lemma decisive_sprod_map:
huffman@35653
   204
  assumes f: "decisive f"
huffman@35653
   205
  assumes g: "decisive g"
huffman@35653
   206
  shows "decisive (sprod_map\<cdot>f\<cdot>g)"
huffman@35653
   207
apply (rule decisiveI, rename_tac s)
huffman@35653
   208
apply (case_tac s, simp_all)
huffman@35653
   209
apply (rule_tac x=x in decisive_cases [OF f], simp_all)
huffman@35653
   210
apply (rule_tac x=y in decisive_cases [OF g], simp_all)
huffman@35653
   211
done
huffman@35653
   212
huffman@35653
   213
lemma decisive_abs_rep:
huffman@35653
   214
  fixes abs rep
huffman@35653
   215
  assumes iso: "iso abs rep"
huffman@35653
   216
  assumes d: "decisive d"
huffman@35653
   217
  shows "decisive (abs oo d oo rep)"
huffman@35653
   218
apply (rule decisiveI)
huffman@35653
   219
apply (rule_tac x="rep\<cdot>x" in decisive_cases [OF d])
huffman@35653
   220
apply (simp add: iso.rep_iso [OF iso])
huffman@35653
   221
apply (simp add: iso.abs_strict [OF iso])
huffman@35653
   222
done
huffman@35653
   223
huffman@35653
   224
lemma lub_ID_finite:
huffman@35653
   225
  assumes chain: "chain d"
huffman@35653
   226
  assumes lub: "(\<Squnion>n. d n) = ID"
huffman@35653
   227
  assumes decisive: "\<And>n. decisive (d n)"
huffman@35653
   228
  shows "\<exists>n. d n\<cdot>x = x"
huffman@35653
   229
proof -
huffman@35653
   230
  have 1: "chain (\<lambda>n. d n\<cdot>x)" using chain by simp
huffman@35653
   231
  have 2: "(\<Squnion>n. d n\<cdot>x) = x" using chain lub by (rule lub_ID_reach)
huffman@35653
   232
  have "\<forall>n. d n\<cdot>x = x \<or> d n\<cdot>x = \<bottom>"
huffman@35653
   233
    using decisive unfolding decisive_def by simp
huffman@35653
   234
  hence "range (\<lambda>n. d n\<cdot>x) \<subseteq> {x, \<bottom>}"
huffman@35653
   235
    by auto
huffman@35653
   236
  hence "finite (range (\<lambda>n. d n\<cdot>x))"
huffman@35653
   237
    by (rule finite_subset, simp)
huffman@35653
   238
  with 1 have "finite_chain (\<lambda>n. d n\<cdot>x)"
huffman@35653
   239
    by (rule finite_range_imp_finch)
huffman@35653
   240
  then have "\<exists>n. (\<Squnion>n. d n\<cdot>x) = d n\<cdot>x"
huffman@35653
   241
    unfolding finite_chain_def by (auto simp add: maxinch_is_thelub)
huffman@35653
   242
  with 2 show "\<exists>n. d n\<cdot>x = x" by (auto elim: sym)
huffman@35653
   243
qed
huffman@35653
   244
huffman@35653
   245
subsection {* ML setup *}
huffman@35653
   246
huffman@35652
   247
use "Tools/Domain/domain_take_proofs.ML"
huffman@35652
   248
huffman@35652
   249
end