src/HOL/HOLCF/Fun_Cpo.thy
author huffman
Mon Dec 06 10:08:33 2010 -0800 (2010-12-06)
changeset 41030 ff7d177128ef
parent 40774 0437dbc127b3
child 41032 75b4ff66781c
permissions -rw-r--r--
rename lub_fun -> is_lub_fun, thelub_fun -> lub_fun
huffman@40001
     1
(*  Title:      HOLCF/Fun_Cpo.thy
huffman@16202
     2
    Author:     Franz Regensburger
huffman@40001
     3
    Author:     Brian Huffman
huffman@16202
     4
*)
huffman@16202
     5
huffman@16202
     6
header {* Class instances for the full function space *}
huffman@16202
     7
huffman@40001
     8
theory Fun_Cpo
huffman@40011
     9
imports Adm
huffman@16202
    10
begin
huffman@16202
    11
huffman@18291
    12
subsection {* Full function space is a partial order *}
huffman@16202
    13
huffman@31076
    14
instantiation "fun"  :: (type, below) below
huffman@25758
    15
begin
huffman@16202
    16
huffman@25758
    17
definition
huffman@31076
    18
  below_fun_def: "(op \<sqsubseteq>) \<equiv> (\<lambda>f g. \<forall>x. f x \<sqsubseteq> g x)"
huffman@16202
    19
huffman@25758
    20
instance ..
huffman@25758
    21
end
huffman@16202
    22
huffman@25758
    23
instance "fun" :: (type, po) po
huffman@25758
    24
proof
huffman@25758
    25
  fix f :: "'a \<Rightarrow> 'b"
huffman@25758
    26
  show "f \<sqsubseteq> f"
huffman@31076
    27
    by (simp add: below_fun_def)
huffman@25758
    28
next
huffman@25758
    29
  fix f g :: "'a \<Rightarrow> 'b"
huffman@25758
    30
  assume "f \<sqsubseteq> g" and "g \<sqsubseteq> f" thus "f = g"
nipkow@39302
    31
    by (simp add: below_fun_def fun_eq_iff below_antisym)
huffman@25758
    32
next
huffman@25758
    33
  fix f g h :: "'a \<Rightarrow> 'b"
huffman@25758
    34
  assume "f \<sqsubseteq> g" and "g \<sqsubseteq> h" thus "f \<sqsubseteq> h"
huffman@31076
    35
    unfolding below_fun_def by (fast elim: below_trans)
huffman@25758
    36
qed
huffman@16202
    37
huffman@40002
    38
lemma fun_below_iff: "f \<sqsubseteq> g \<longleftrightarrow> (\<forall>x. f x \<sqsubseteq> g x)"
huffman@31076
    39
by (simp add: below_fun_def)
huffman@16202
    40
huffman@40002
    41
lemma fun_belowI: "(\<And>x. f x \<sqsubseteq> g x) \<Longrightarrow> f \<sqsubseteq> g"
huffman@31076
    42
by (simp add: below_fun_def)
huffman@16202
    43
huffman@40011
    44
lemma fun_belowD: "f \<sqsubseteq> g \<Longrightarrow> f x \<sqsubseteq> g x"
huffman@40011
    45
by (simp add: below_fun_def)
huffman@40011
    46
huffman@18291
    47
subsection {* Full function space is chain complete *}
huffman@16202
    48
huffman@40011
    49
text {* Properties of chains of functions. *}
huffman@40011
    50
huffman@40011
    51
lemma fun_chain_iff: "chain S \<longleftrightarrow> (\<forall>x. chain (\<lambda>i. S i x))"
huffman@40011
    52
unfolding chain_def fun_below_iff by auto
huffman@16202
    53
huffman@16202
    54
lemma ch2ch_fun: "chain S \<Longrightarrow> chain (\<lambda>i. S i x)"
huffman@31076
    55
by (simp add: chain_def below_fun_def)
huffman@16202
    56
huffman@18092
    57
lemma ch2ch_lambda: "(\<And>x. chain (\<lambda>i. S i x)) \<Longrightarrow> chain S"
huffman@31076
    58
by (simp add: chain_def below_fun_def)
huffman@16202
    59
huffman@16202
    60
text {* Type @{typ "'a::type => 'b::cpo"} is chain complete *}
huffman@16202
    61
huffman@26028
    62
lemma is_lub_lambda:
huffman@40011
    63
  "(\<And>x. range (\<lambda>i. Y i x) <<| f x) \<Longrightarrow> range Y <<| f"
huffman@40011
    64
unfolding is_lub_def is_ub_def below_fun_def by simp
huffman@26028
    65
huffman@41030
    66
lemma is_lub_fun:
huffman@16202
    67
  "chain (S::nat \<Rightarrow> 'a::type \<Rightarrow> 'b::cpo)
huffman@16202
    68
    \<Longrightarrow> range S <<| (\<lambda>x. \<Squnion>i. S i x)"
huffman@26028
    69
apply (rule is_lub_lambda)
huffman@26028
    70
apply (rule cpo_lubI)
huffman@16202
    71
apply (erule ch2ch_fun)
huffman@16202
    72
done
huffman@16202
    73
huffman@41030
    74
lemma lub_fun:
huffman@16202
    75
  "chain (S::nat \<Rightarrow> 'a::type \<Rightarrow> 'b::cpo)
huffman@27413
    76
    \<Longrightarrow> (\<Squnion>i. S i) = (\<lambda>x. \<Squnion>i. S i x)"
huffman@41030
    77
by (rule is_lub_fun [THEN lub_eqI])
huffman@16202
    78
krauss@20523
    79
instance "fun"  :: (type, cpo) cpo
huffman@41030
    80
by intro_classes (rule exI, erule is_lub_fun)
huffman@16202
    81
huffman@40011
    82
subsection {* Chain-finiteness of function space *}
huffman@25827
    83
huffman@25827
    84
lemma maxinch2maxinch_lambda:
huffman@25827
    85
  "(\<And>x. max_in_chain n (\<lambda>i. S i x)) \<Longrightarrow> max_in_chain n S"
nipkow@39302
    86
unfolding max_in_chain_def fun_eq_iff by simp
huffman@25827
    87
huffman@25827
    88
lemma maxinch_mono:
huffman@25827
    89
  "\<lbrakk>max_in_chain i Y; i \<le> j\<rbrakk> \<Longrightarrow> max_in_chain j Y"
huffman@25827
    90
unfolding max_in_chain_def
huffman@25827
    91
proof (intro allI impI)
huffman@25827
    92
  fix k
huffman@25827
    93
  assume Y: "\<forall>n\<ge>i. Y i = Y n"
huffman@25827
    94
  assume ij: "i \<le> j"
huffman@25827
    95
  assume jk: "j \<le> k"
huffman@25827
    96
  from ij jk have ik: "i \<le> k" by simp
huffman@25827
    97
  from Y ij have Yij: "Y i = Y j" by simp
huffman@25827
    98
  from Y ik have Yik: "Y i = Y k" by simp
huffman@25827
    99
  from Yij Yik show "Y j = Y k" by auto
huffman@25827
   100
qed
huffman@25827
   101
huffman@40011
   102
instance "fun" :: (type, discrete_cpo) discrete_cpo
huffman@40011
   103
proof
huffman@40011
   104
  fix f g :: "'a \<Rightarrow> 'b"
huffman@40011
   105
  show "f \<sqsubseteq> g \<longleftrightarrow> f = g" 
huffman@40011
   106
    unfolding fun_below_iff fun_eq_iff
huffman@40011
   107
    by simp
huffman@40011
   108
qed
huffman@40011
   109
huffman@18291
   110
subsection {* Full function space is pointed *}
huffman@17831
   111
huffman@17831
   112
lemma minimal_fun: "(\<lambda>x. \<bottom>) \<sqsubseteq> f"
huffman@31076
   113
by (simp add: below_fun_def)
huffman@17831
   114
huffman@40011
   115
instance "fun"  :: (type, pcpo) pcpo
huffman@40011
   116
by default (fast intro: minimal_fun)
huffman@17831
   117
huffman@17831
   118
lemma inst_fun_pcpo: "\<bottom> = (\<lambda>x. \<bottom>)"
huffman@16202
   119
by (rule minimal_fun [THEN UU_I, symmetric])
huffman@16202
   120
huffman@16202
   121
lemma app_strict [simp]: "\<bottom> x = \<bottom>"
huffman@16202
   122
by (simp add: inst_fun_pcpo)
huffman@16202
   123
huffman@40011
   124
lemma lambda_strict: "(\<lambda>x. \<bottom>) = \<bottom>"
huffman@40011
   125
by (rule UU_I, rule minimal_fun)
huffman@25786
   126
huffman@25786
   127
subsection {* Propagation of monotonicity and continuity *}
huffman@25786
   128
huffman@40011
   129
text {* The lub of a chain of monotone functions is monotone. *}
huffman@40011
   130
huffman@40011
   131
lemma adm_monofun: "adm monofun"
huffman@41030
   132
by (rule admI, simp add: lub_fun fun_chain_iff monofun_def lub_mono)
huffman@25786
   133
huffman@40011
   134
text {* The lub of a chain of continuous functions is continuous. *}
huffman@25786
   135
huffman@40011
   136
lemma adm_cont: "adm cont"
huffman@41030
   137
by (rule admI, simp add: lub_fun fun_chain_iff)
huffman@25786
   138
huffman@40011
   139
text {* Function application preserves monotonicity and continuity. *}
huffman@25786
   140
huffman@25786
   141
lemma mono2mono_fun: "monofun f \<Longrightarrow> monofun (\<lambda>x. f x y)"
huffman@40011
   142
by (simp add: monofun_def fun_below_iff)
huffman@25786
   143
huffman@25786
   144
lemma cont2cont_fun: "cont f \<Longrightarrow> cont (\<lambda>x. f x y)"
huffman@35914
   145
apply (rule contI2)
huffman@25786
   146
apply (erule cont2mono [THEN mono2mono_fun])
huffman@41030
   147
apply (simp add: cont2contlubE lub_fun ch2ch_cont)
huffman@25786
   148
done
huffman@25786
   149
huffman@40622
   150
lemma cont_fun: "cont (\<lambda>f. f x)"
huffman@40622
   151
using cont_id by (rule cont2cont_fun)
huffman@40622
   152
huffman@40011
   153
text {*
huffman@40011
   154
  Lambda abstraction preserves monotonicity and continuity.
huffman@40011
   155
  (Note @{text "(\<lambda>x. \<lambda>y. f x y) = f"}.)
huffman@40011
   156
*}
huffman@25786
   157
huffman@26452
   158
lemma mono2mono_lambda:
huffman@26452
   159
  assumes f: "\<And>y. monofun (\<lambda>x. f x y)" shows "monofun f"
huffman@40011
   160
using f by (simp add: monofun_def fun_below_iff)
huffman@25786
   161
huffman@26452
   162
lemma cont2cont_lambda [simp]:
huffman@26452
   163
  assumes f: "\<And>y. cont (\<lambda>x. f x y)" shows "cont f"
huffman@40011
   164
by (rule contI, rule is_lub_lambda, rule contE [OF f])
huffman@25786
   165
huffman@25786
   166
text {* What D.A.Schmidt calls continuity of abstraction; never used here *}
huffman@25786
   167
huffman@25786
   168
lemma contlub_lambda:
huffman@25786
   169
  "(\<And>x::'a::type. chain (\<lambda>i. S i x::'b::cpo))
huffman@25786
   170
    \<Longrightarrow> (\<lambda>x. \<Squnion>i. S i x) = (\<Squnion>i. (\<lambda>x. S i x))"
huffman@41030
   171
by (simp add: lub_fun ch2ch_lambda)
huffman@25786
   172
huffman@16202
   173
end