src/HOLCF/Fix.thy
author huffman
Tue Oct 12 05:48:15 2010 -0700 (2010-10-12)
changeset 40004 9f6ed6840e8d
parent 36452 d37c6eed8117
child 40321 d065b195ec89
permissions -rw-r--r--
reformulate lemma cont2cont_lub and move to Cont.thy
     1 (*  Title:      HOLCF/Fix.thy
     2     Author:     Franz Regensburger
     3     Author:     Brian Huffman
     4 *)
     5 
     6 header {* Fixed point operator and admissibility *}
     7 
     8 theory Fix
     9 imports Cfun
    10 begin
    11 
    12 default_sort pcpo
    13 
    14 subsection {* Iteration *}
    15 
    16 primrec iterate :: "nat \<Rightarrow> ('a::cpo \<rightarrow> 'a) \<rightarrow> ('a \<rightarrow> 'a)" where
    17     "iterate 0 = (\<Lambda> F x. x)"
    18   | "iterate (Suc n) = (\<Lambda> F x. F\<cdot>(iterate n\<cdot>F\<cdot>x))"
    19 
    20 text {* Derive inductive properties of iterate from primitive recursion *}
    21 
    22 lemma iterate_0 [simp]: "iterate 0\<cdot>F\<cdot>x = x"
    23 by simp
    24 
    25 lemma iterate_Suc [simp]: "iterate (Suc n)\<cdot>F\<cdot>x = F\<cdot>(iterate n\<cdot>F\<cdot>x)"
    26 by simp
    27 
    28 declare iterate.simps [simp del]
    29 
    30 lemma iterate_Suc2: "iterate (Suc n)\<cdot>F\<cdot>x = iterate n\<cdot>F\<cdot>(F\<cdot>x)"
    31 by (induct n) simp_all
    32 
    33 lemma iterate_iterate:
    34   "iterate m\<cdot>F\<cdot>(iterate n\<cdot>F\<cdot>x) = iterate (m + n)\<cdot>F\<cdot>x"
    35 by (induct m) simp_all
    36 
    37 text {* The sequence of function iterations is a chain. *}
    38 
    39 lemma chain_iterate [simp]: "chain (\<lambda>i. iterate i\<cdot>F\<cdot>\<bottom>)"
    40 by (rule chainI, unfold iterate_Suc2, rule monofun_cfun_arg, rule minimal)
    41 
    42 
    43 subsection {* Least fixed point operator *}
    44 
    45 definition
    46   "fix" :: "('a \<rightarrow> 'a) \<rightarrow> 'a" where
    47   "fix = (\<Lambda> F. \<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>)"
    48 
    49 text {* Binder syntax for @{term fix} *}
    50 
    51 abbreviation
    52   fix_syn :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a"  (binder "FIX " 10) where
    53   "fix_syn (\<lambda>x. f x) \<equiv> fix\<cdot>(\<Lambda> x. f x)"
    54 
    55 notation (xsymbols)
    56   fix_syn  (binder "\<mu> " 10)
    57 
    58 text {* Properties of @{term fix} *}
    59 
    60 text {* direct connection between @{term fix} and iteration *}
    61 
    62 lemma fix_def2: "fix\<cdot>F = (\<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>)"
    63 unfolding fix_def by simp
    64 
    65 lemma iterate_below_fix: "iterate n\<cdot>f\<cdot>\<bottom> \<sqsubseteq> fix\<cdot>f"
    66   unfolding fix_def2
    67   using chain_iterate by (rule is_ub_thelub)
    68 
    69 text {*
    70   Kleene's fixed point theorems for continuous functions in pointed
    71   omega cpo's
    72 *}
    73 
    74 lemma fix_eq: "fix\<cdot>F = F\<cdot>(fix\<cdot>F)"
    75 apply (simp add: fix_def2)
    76 apply (subst lub_range_shift [of _ 1, symmetric])
    77 apply (rule chain_iterate)
    78 apply (subst contlub_cfun_arg)
    79 apply (rule chain_iterate)
    80 apply simp
    81 done
    82 
    83 lemma fix_least_below: "F\<cdot>x \<sqsubseteq> x \<Longrightarrow> fix\<cdot>F \<sqsubseteq> x"
    84 apply (simp add: fix_def2)
    85 apply (rule is_lub_thelub)
    86 apply (rule chain_iterate)
    87 apply (rule ub_rangeI)
    88 apply (induct_tac i)
    89 apply simp
    90 apply simp
    91 apply (erule rev_below_trans)
    92 apply (erule monofun_cfun_arg)
    93 done
    94 
    95 lemma fix_least: "F\<cdot>x = x \<Longrightarrow> fix\<cdot>F \<sqsubseteq> x"
    96 by (rule fix_least_below, simp)
    97 
    98 lemma fix_eqI:
    99   assumes fixed: "F\<cdot>x = x" and least: "\<And>z. F\<cdot>z = z \<Longrightarrow> x \<sqsubseteq> z"
   100   shows "fix\<cdot>F = x"
   101 apply (rule below_antisym)
   102 apply (rule fix_least [OF fixed])
   103 apply (rule least [OF fix_eq [symmetric]])
   104 done
   105 
   106 lemma fix_eq2: "f \<equiv> fix\<cdot>F \<Longrightarrow> f = F\<cdot>f"
   107 by (simp add: fix_eq [symmetric])
   108 
   109 lemma fix_eq3: "f \<equiv> fix\<cdot>F \<Longrightarrow> f\<cdot>x = F\<cdot>f\<cdot>x"
   110 by (erule fix_eq2 [THEN cfun_fun_cong])
   111 
   112 lemma fix_eq4: "f = fix\<cdot>F \<Longrightarrow> f = F\<cdot>f"
   113 apply (erule ssubst)
   114 apply (rule fix_eq)
   115 done
   116 
   117 lemma fix_eq5: "f = fix\<cdot>F \<Longrightarrow> f\<cdot>x = F\<cdot>f\<cdot>x"
   118 by (erule fix_eq4 [THEN cfun_fun_cong])
   119 
   120 text {* strictness of @{term fix} *}
   121 
   122 lemma fix_defined_iff: "(fix\<cdot>F = \<bottom>) = (F\<cdot>\<bottom> = \<bottom>)"
   123 apply (rule iffI)
   124 apply (erule subst)
   125 apply (rule fix_eq [symmetric])
   126 apply (erule fix_least [THEN UU_I])
   127 done
   128 
   129 lemma fix_strict: "F\<cdot>\<bottom> = \<bottom> \<Longrightarrow> fix\<cdot>F = \<bottom>"
   130 by (simp add: fix_defined_iff)
   131 
   132 lemma fix_defined: "F\<cdot>\<bottom> \<noteq> \<bottom> \<Longrightarrow> fix\<cdot>F \<noteq> \<bottom>"
   133 by (simp add: fix_defined_iff)
   134 
   135 text {* @{term fix} applied to identity and constant functions *}
   136 
   137 lemma fix_id: "(\<mu> x. x) = \<bottom>"
   138 by (simp add: fix_strict)
   139 
   140 lemma fix_const: "(\<mu> x. c) = c"
   141 by (subst fix_eq, simp)
   142 
   143 subsection {* Fixed point induction *}
   144 
   145 lemma fix_ind: "\<lbrakk>adm P; P \<bottom>; \<And>x. P x \<Longrightarrow> P (F\<cdot>x)\<rbrakk> \<Longrightarrow> P (fix\<cdot>F)"
   146 unfolding fix_def2
   147 apply (erule admD)
   148 apply (rule chain_iterate)
   149 apply (rule nat_induct, simp_all)
   150 done
   151 
   152 lemma def_fix_ind:
   153   "\<lbrakk>f \<equiv> fix\<cdot>F; adm P; P \<bottom>; \<And>x. P x \<Longrightarrow> P (F\<cdot>x)\<rbrakk> \<Longrightarrow> P f"
   154 by (simp add: fix_ind)
   155 
   156 lemma fix_ind2:
   157   assumes adm: "adm P"
   158   assumes 0: "P \<bottom>" and 1: "P (F\<cdot>\<bottom>)"
   159   assumes step: "\<And>x. \<lbrakk>P x; P (F\<cdot>x)\<rbrakk> \<Longrightarrow> P (F\<cdot>(F\<cdot>x))"
   160   shows "P (fix\<cdot>F)"
   161 unfolding fix_def2
   162 apply (rule admD [OF adm chain_iterate])
   163 apply (rule nat_less_induct)
   164 apply (case_tac n)
   165 apply (simp add: 0)
   166 apply (case_tac nat)
   167 apply (simp add: 1)
   168 apply (frule_tac x=nat in spec)
   169 apply (simp add: step)
   170 done
   171 
   172 lemma parallel_fix_ind:
   173   assumes adm: "adm (\<lambda>x. P (fst x) (snd x))"
   174   assumes base: "P \<bottom> \<bottom>"
   175   assumes step: "\<And>x y. P x y \<Longrightarrow> P (F\<cdot>x) (G\<cdot>y)"
   176   shows "P (fix\<cdot>F) (fix\<cdot>G)"
   177 proof -
   178   from adm have adm': "adm (split P)"
   179     unfolding split_def .
   180   have "\<And>i. P (iterate i\<cdot>F\<cdot>\<bottom>) (iterate i\<cdot>G\<cdot>\<bottom>)"
   181     by (induct_tac i, simp add: base, simp add: step)
   182   hence "\<And>i. split P (iterate i\<cdot>F\<cdot>\<bottom>, iterate i\<cdot>G\<cdot>\<bottom>)"
   183     by simp
   184   hence "split P (\<Squnion>i. (iterate i\<cdot>F\<cdot>\<bottom>, iterate i\<cdot>G\<cdot>\<bottom>))"
   185     by - (rule admD [OF adm'], simp, assumption)
   186   hence "split P (\<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>, \<Squnion>i. iterate i\<cdot>G\<cdot>\<bottom>)"
   187     by (simp add: thelub_Pair)
   188   hence "P (\<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>) (\<Squnion>i. iterate i\<cdot>G\<cdot>\<bottom>)"
   189     by simp
   190   thus "P (fix\<cdot>F) (fix\<cdot>G)"
   191     by (simp add: fix_def2)
   192 qed
   193 
   194 subsection {* Fixed-points on product types *}
   195 
   196 text {*
   197   Bekic's Theorem: Simultaneous fixed points over pairs
   198   can be written in terms of separate fixed points.
   199 *}
   200 
   201 lemma fix_cprod:
   202   "fix\<cdot>(F::'a \<times> 'b \<rightarrow> 'a \<times> 'b) =
   203    (\<mu> x. fst (F\<cdot>(x, \<mu> y. snd (F\<cdot>(x, y)))),
   204     \<mu> y. snd (F\<cdot>(\<mu> x. fst (F\<cdot>(x, \<mu> y. snd (F\<cdot>(x, y)))), y)))"
   205   (is "fix\<cdot>F = (?x, ?y)")
   206 proof (rule fix_eqI)
   207   have 1: "fst (F\<cdot>(?x, ?y)) = ?x"
   208     by (rule trans [symmetric, OF fix_eq], simp)
   209   have 2: "snd (F\<cdot>(?x, ?y)) = ?y"
   210     by (rule trans [symmetric, OF fix_eq], simp)
   211   from 1 2 show "F\<cdot>(?x, ?y) = (?x, ?y)" by (simp add: Pair_fst_snd_eq)
   212 next
   213   fix z assume F_z: "F\<cdot>z = z"
   214   obtain x y where z: "z = (x,y)" by (rule prod.exhaust)
   215   from F_z z have F_x: "fst (F\<cdot>(x, y)) = x" by simp
   216   from F_z z have F_y: "snd (F\<cdot>(x, y)) = y" by simp
   217   let ?y1 = "\<mu> y. snd (F\<cdot>(x, y))"
   218   have "?y1 \<sqsubseteq> y" by (rule fix_least, simp add: F_y)
   219   hence "fst (F\<cdot>(x, ?y1)) \<sqsubseteq> fst (F\<cdot>(x, y))"
   220     by (simp add: fst_monofun monofun_cfun)
   221   hence "fst (F\<cdot>(x, ?y1)) \<sqsubseteq> x" using F_x by simp
   222   hence 1: "?x \<sqsubseteq> x" by (simp add: fix_least_below)
   223   hence "snd (F\<cdot>(?x, y)) \<sqsubseteq> snd (F\<cdot>(x, y))"
   224     by (simp add: snd_monofun monofun_cfun)
   225   hence "snd (F\<cdot>(?x, y)) \<sqsubseteq> y" using F_y by simp
   226   hence 2: "?y \<sqsubseteq> y" by (simp add: fix_least_below)
   227   show "(?x, ?y) \<sqsubseteq> z" using z 1 2 by simp
   228 qed
   229 
   230 end