src/HOLCF/Domain_Aux.thy
author huffman
Wed Nov 10 17:56:08 2010 -0800 (2010-11-10)
changeset 40502 8e92772bc0e8
parent 40327 1dfdbd66093a
child 40503 4094d788b904
permissions -rw-r--r--
move map functions to new theory file Map_Functions; add theory file Plain_HOLCF
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@40502
     8
imports Map_Functions 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@40321
    74
lemma abs_bottom_iff: "(abs\<cdot>x = \<bottom>) = (x = \<bottom>)"
huffman@35653
    75
  by (auto elim: abs_defin' intro: abs_strict)
huffman@35653
    76
huffman@40321
    77
lemma rep_bottom_iff: "(rep\<cdot>x = \<bottom>) = (x = \<bottom>)"
huffman@40321
    78
  by (rule iso.abs_bottom_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@40321
    81
  by (simp add: rep_bottom_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@40327
    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@35655
   166
lemma lub_ID_take_induct:
huffman@35655
   167
  assumes "chain t" and "(\<Squnion>n. t n) = ID"
huffman@35655
   168
  assumes "adm P" and "\<And>n. P (t n\<cdot>x)" shows "P x"
huffman@35655
   169
proof -
huffman@35655
   170
  from `chain t` have "chain (\<lambda>n. t n\<cdot>x)" by simp
huffman@35655
   171
  from `adm P` this `\<And>n. P (t n\<cdot>x)` have "P (\<Squnion>n. t n\<cdot>x)" by (rule admD)
huffman@35655
   172
  with `chain t` `(\<Squnion>n. t n) = ID` show "P x" by (simp add: lub_distribs)
huffman@35655
   173
qed
huffman@35655
   174
huffman@35653
   175
huffman@35653
   176
subsection {* Finiteness *}
huffman@35653
   177
huffman@35653
   178
text {*
huffman@35653
   179
  Let a ``decisive'' function be a deflation that maps every input to
huffman@35653
   180
  either itself or bottom.  Then if a domain's take functions are all
huffman@35653
   181
  decisive, then all values in the domain are finite.
huffman@35653
   182
*}
huffman@35653
   183
huffman@35653
   184
definition
huffman@35653
   185
  decisive :: "('a::pcpo \<rightarrow> 'a) \<Rightarrow> bool"
huffman@35653
   186
where
huffman@35653
   187
  "decisive d \<longleftrightarrow> (\<forall>x. d\<cdot>x = x \<or> d\<cdot>x = \<bottom>)"
huffman@35653
   188
huffman@35653
   189
lemma decisiveI: "(\<And>x. d\<cdot>x = x \<or> d\<cdot>x = \<bottom>) \<Longrightarrow> decisive d"
huffman@35653
   190
  unfolding decisive_def by simp
huffman@35653
   191
huffman@35653
   192
lemma decisive_cases:
huffman@35653
   193
  assumes "decisive d" obtains "d\<cdot>x = x" | "d\<cdot>x = \<bottom>"
huffman@35653
   194
using assms unfolding decisive_def by auto
huffman@35653
   195
huffman@35653
   196
lemma decisive_bottom: "decisive \<bottom>"
huffman@35653
   197
  unfolding decisive_def by simp
huffman@35653
   198
huffman@35653
   199
lemma decisive_ID: "decisive ID"
huffman@35653
   200
  unfolding decisive_def by simp
huffman@35653
   201
huffman@35653
   202
lemma decisive_ssum_map:
huffman@35653
   203
  assumes f: "decisive f"
huffman@35653
   204
  assumes g: "decisive g"
huffman@35653
   205
  shows "decisive (ssum_map\<cdot>f\<cdot>g)"
huffman@35653
   206
apply (rule decisiveI, rename_tac s)
huffman@35653
   207
apply (case_tac s, simp_all)
huffman@35653
   208
apply (rule_tac x=x in decisive_cases [OF f], simp_all)
huffman@35653
   209
apply (rule_tac x=y in decisive_cases [OF g], simp_all)
huffman@35653
   210
done
huffman@35653
   211
huffman@35653
   212
lemma decisive_sprod_map:
huffman@35653
   213
  assumes f: "decisive f"
huffman@35653
   214
  assumes g: "decisive g"
huffman@35653
   215
  shows "decisive (sprod_map\<cdot>f\<cdot>g)"
huffman@35653
   216
apply (rule decisiveI, rename_tac s)
huffman@35653
   217
apply (case_tac s, simp_all)
huffman@35653
   218
apply (rule_tac x=x in decisive_cases [OF f], simp_all)
huffman@35653
   219
apply (rule_tac x=y in decisive_cases [OF g], simp_all)
huffman@35653
   220
done
huffman@35653
   221
huffman@35653
   222
lemma decisive_abs_rep:
huffman@35653
   223
  fixes abs rep
huffman@35653
   224
  assumes iso: "iso abs rep"
huffman@35653
   225
  assumes d: "decisive d"
huffman@35653
   226
  shows "decisive (abs oo d oo rep)"
huffman@35653
   227
apply (rule decisiveI)
huffman@35653
   228
apply (rule_tac x="rep\<cdot>x" in decisive_cases [OF d])
huffman@35653
   229
apply (simp add: iso.rep_iso [OF iso])
huffman@35653
   230
apply (simp add: iso.abs_strict [OF iso])
huffman@35653
   231
done
huffman@35653
   232
huffman@35653
   233
lemma lub_ID_finite:
huffman@35653
   234
  assumes chain: "chain d"
huffman@35653
   235
  assumes lub: "(\<Squnion>n. d n) = ID"
huffman@35653
   236
  assumes decisive: "\<And>n. decisive (d n)"
huffman@35653
   237
  shows "\<exists>n. d n\<cdot>x = x"
huffman@35653
   238
proof -
huffman@35653
   239
  have 1: "chain (\<lambda>n. d n\<cdot>x)" using chain by simp
huffman@35653
   240
  have 2: "(\<Squnion>n. d n\<cdot>x) = x" using chain lub by (rule lub_ID_reach)
huffman@35653
   241
  have "\<forall>n. d n\<cdot>x = x \<or> d n\<cdot>x = \<bottom>"
huffman@35653
   242
    using decisive unfolding decisive_def by simp
huffman@35653
   243
  hence "range (\<lambda>n. d n\<cdot>x) \<subseteq> {x, \<bottom>}"
huffman@35653
   244
    by auto
huffman@35653
   245
  hence "finite (range (\<lambda>n. d n\<cdot>x))"
huffman@35653
   246
    by (rule finite_subset, simp)
huffman@35653
   247
  with 1 have "finite_chain (\<lambda>n. d n\<cdot>x)"
huffman@35653
   248
    by (rule finite_range_imp_finch)
huffman@35653
   249
  then have "\<exists>n. (\<Squnion>n. d n\<cdot>x) = d n\<cdot>x"
huffman@35653
   250
    unfolding finite_chain_def by (auto simp add: maxinch_is_thelub)
huffman@35653
   251
  with 2 show "\<exists>n. d n\<cdot>x = x" by (auto elim: sym)
huffman@35653
   252
qed
huffman@35653
   253
huffman@35655
   254
lemma lub_ID_finite_take_induct:
huffman@35655
   255
  assumes "chain d" and "(\<Squnion>n. d n) = ID" and "\<And>n. decisive (d n)"
huffman@35655
   256
  shows "(\<And>n. P (d n\<cdot>x)) \<Longrightarrow> P x"
huffman@35655
   257
using lub_ID_finite [OF assms] by metis
huffman@35655
   258
huffman@35653
   259
subsection {* ML setup *}
huffman@35653
   260
huffman@35652
   261
use "Tools/Domain/domain_take_proofs.ML"
huffman@35652
   262
huffman@40216
   263
setup Domain_Take_Proofs.setup
huffman@40216
   264
huffman@35652
   265
end