1 (* Title: HOL/HOLCF/Fix.thy |
1 (* Title: HOL/HOLCF/Fix.thy |
2 Author: Franz Regensburger |
2 Author: Franz Regensburger |
3 Author: Brian Huffman |
3 Author: Brian Huffman |
4 *) |
4 *) |
5 |
5 |
6 section {* Fixed point operator and admissibility *} |
6 section \<open>Fixed point operator and admissibility\<close> |
7 |
7 |
8 theory Fix |
8 theory Fix |
9 imports Cfun |
9 imports Cfun |
10 begin |
10 begin |
11 |
11 |
12 default_sort pcpo |
12 default_sort pcpo |
13 |
13 |
14 subsection {* Iteration *} |
14 subsection \<open>Iteration\<close> |
15 |
15 |
16 primrec iterate :: "nat \<Rightarrow> ('a::cpo \<rightarrow> 'a) \<rightarrow> ('a \<rightarrow> 'a)" where |
16 primrec iterate :: "nat \<Rightarrow> ('a::cpo \<rightarrow> 'a) \<rightarrow> ('a \<rightarrow> 'a)" where |
17 "iterate 0 = (\<Lambda> F x. x)" |
17 "iterate 0 = (\<Lambda> F x. x)" |
18 | "iterate (Suc n) = (\<Lambda> F x. F\<cdot>(iterate n\<cdot>F\<cdot>x))" |
18 | "iterate (Suc n) = (\<Lambda> F x. F\<cdot>(iterate n\<cdot>F\<cdot>x))" |
19 |
19 |
20 text {* Derive inductive properties of iterate from primitive recursion *} |
20 text \<open>Derive inductive properties of iterate from primitive recursion\<close> |
21 |
21 |
22 lemma iterate_0 [simp]: "iterate 0\<cdot>F\<cdot>x = x" |
22 lemma iterate_0 [simp]: "iterate 0\<cdot>F\<cdot>x = x" |
23 by simp |
23 by simp |
24 |
24 |
25 lemma iterate_Suc [simp]: "iterate (Suc n)\<cdot>F\<cdot>x = F\<cdot>(iterate n\<cdot>F\<cdot>x)" |
25 lemma iterate_Suc [simp]: "iterate (Suc n)\<cdot>F\<cdot>x = F\<cdot>(iterate n\<cdot>F\<cdot>x)" |
32 |
32 |
33 lemma iterate_iterate: |
33 lemma iterate_iterate: |
34 "iterate m\<cdot>F\<cdot>(iterate n\<cdot>F\<cdot>x) = iterate (m + n)\<cdot>F\<cdot>x" |
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 |
35 by (induct m) simp_all |
36 |
36 |
37 text {* The sequence of function iterations is a chain. *} |
37 text \<open>The sequence of function iterations is a chain.\<close> |
38 |
38 |
39 lemma chain_iterate [simp]: "chain (\<lambda>i. iterate i\<cdot>F\<cdot>\<bottom>)" |
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) |
40 by (rule chainI, unfold iterate_Suc2, rule monofun_cfun_arg, rule minimal) |
41 |
41 |
42 |
42 |
43 subsection {* Least fixed point operator *} |
43 subsection \<open>Least fixed point operator\<close> |
44 |
44 |
45 definition |
45 definition |
46 "fix" :: "('a \<rightarrow> 'a) \<rightarrow> 'a" where |
46 "fix" :: "('a \<rightarrow> 'a) \<rightarrow> 'a" where |
47 "fix = (\<Lambda> F. \<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>)" |
47 "fix = (\<Lambda> F. \<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>)" |
48 |
48 |
49 text {* Binder syntax for @{term fix} *} |
49 text \<open>Binder syntax for @{term fix}\<close> |
50 |
50 |
51 abbreviation |
51 abbreviation |
52 fix_syn :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a" (binder "\<mu> " 10) where |
52 fix_syn :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a" (binder "\<mu> " 10) where |
53 "fix_syn (\<lambda>x. f x) \<equiv> fix\<cdot>(\<Lambda> x. f x)" |
53 "fix_syn (\<lambda>x. f x) \<equiv> fix\<cdot>(\<Lambda> x. f x)" |
54 |
54 |
55 notation (ASCII) |
55 notation (ASCII) |
56 fix_syn (binder "FIX " 10) |
56 fix_syn (binder "FIX " 10) |
57 |
57 |
58 text {* Properties of @{term fix} *} |
58 text \<open>Properties of @{term fix}\<close> |
59 |
59 |
60 text {* direct connection between @{term fix} and iteration *} |
60 text \<open>direct connection between @{term fix} and iteration\<close> |
61 |
61 |
62 lemma fix_def2: "fix\<cdot>F = (\<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>)" |
62 lemma fix_def2: "fix\<cdot>F = (\<Squnion>i. iterate i\<cdot>F\<cdot>\<bottom>)" |
63 unfolding fix_def by simp |
63 unfolding fix_def by simp |
64 |
64 |
65 lemma iterate_below_fix: "iterate n\<cdot>f\<cdot>\<bottom> \<sqsubseteq> fix\<cdot>f" |
65 lemma iterate_below_fix: "iterate n\<cdot>f\<cdot>\<bottom> \<sqsubseteq> fix\<cdot>f" |
66 unfolding fix_def2 |
66 unfolding fix_def2 |
67 using chain_iterate by (rule is_ub_thelub) |
67 using chain_iterate by (rule is_ub_thelub) |
68 |
68 |
69 text {* |
69 text \<open> |
70 Kleene's fixed point theorems for continuous functions in pointed |
70 Kleene's fixed point theorems for continuous functions in pointed |
71 omega cpo's |
71 omega cpo's |
72 *} |
72 \<close> |
73 |
73 |
74 lemma fix_eq: "fix\<cdot>F = F\<cdot>(fix\<cdot>F)" |
74 lemma fix_eq: "fix\<cdot>F = F\<cdot>(fix\<cdot>F)" |
75 apply (simp add: fix_def2) |
75 apply (simp add: fix_def2) |
76 apply (subst lub_range_shift [of _ 1, symmetric]) |
76 apply (subst lub_range_shift [of _ 1, symmetric]) |
77 apply (rule chain_iterate) |
77 apply (rule chain_iterate) |
129 by (simp add: fix_bottom_iff) |
129 by (simp add: fix_bottom_iff) |
130 |
130 |
131 lemma fix_defined: "F\<cdot>\<bottom> \<noteq> \<bottom> \<Longrightarrow> fix\<cdot>F \<noteq> \<bottom>" |
131 lemma fix_defined: "F\<cdot>\<bottom> \<noteq> \<bottom> \<Longrightarrow> fix\<cdot>F \<noteq> \<bottom>" |
132 by (simp add: fix_bottom_iff) |
132 by (simp add: fix_bottom_iff) |
133 |
133 |
134 text {* @{term fix} applied to identity and constant functions *} |
134 text \<open>@{term fix} applied to identity and constant functions\<close> |
135 |
135 |
136 lemma fix_id: "(\<mu> x. x) = \<bottom>" |
136 lemma fix_id: "(\<mu> x. x) = \<bottom>" |
137 by (simp add: fix_strict) |
137 by (simp add: fix_strict) |
138 |
138 |
139 lemma fix_const: "(\<mu> x. c) = c" |
139 lemma fix_const: "(\<mu> x. c) = c" |
140 by (subst fix_eq, simp) |
140 by (subst fix_eq, simp) |
141 |
141 |
142 subsection {* Fixed point induction *} |
142 subsection \<open>Fixed point induction\<close> |
143 |
143 |
144 lemma fix_ind: "\<lbrakk>adm P; P \<bottom>; \<And>x. P x \<Longrightarrow> P (F\<cdot>x)\<rbrakk> \<Longrightarrow> P (fix\<cdot>F)" |
144 lemma fix_ind: "\<lbrakk>adm P; P \<bottom>; \<And>x. P x \<Longrightarrow> P (F\<cdot>x)\<rbrakk> \<Longrightarrow> P (fix\<cdot>F)" |
145 unfolding fix_def2 |
145 unfolding fix_def2 |
146 apply (erule admD) |
146 apply (erule admD) |
147 apply (rule chain_iterate) |
147 apply (rule chain_iterate) |
200 assumes "P \<bottom> \<bottom>" |
200 assumes "P \<bottom> \<bottom>" |
201 assumes "\<And>x y. P x y \<Longrightarrow> P (F x) (G y)" |
201 assumes "\<And>x y. P x y \<Longrightarrow> P (F x) (G y)" |
202 shows "P (fix\<cdot>(Abs_cfun F)) (fix\<cdot>(Abs_cfun G))" |
202 shows "P (fix\<cdot>(Abs_cfun F)) (fix\<cdot>(Abs_cfun G))" |
203 by (rule parallel_fix_ind, simp_all add: assms) |
203 by (rule parallel_fix_ind, simp_all add: assms) |
204 |
204 |
205 subsection {* Fixed-points on product types *} |
205 subsection \<open>Fixed-points on product types\<close> |
206 |
206 |
207 text {* |
207 text \<open> |
208 Bekic's Theorem: Simultaneous fixed points over pairs |
208 Bekic's Theorem: Simultaneous fixed points over pairs |
209 can be written in terms of separate fixed points. |
209 can be written in terms of separate fixed points. |
210 *} |
210 \<close> |
211 |
211 |
212 lemma fix_cprod: |
212 lemma fix_cprod: |
213 "fix\<cdot>(F::'a \<times> 'b \<rightarrow> 'a \<times> 'b) = |
213 "fix\<cdot>(F::'a \<times> 'b \<rightarrow> 'a \<times> 'b) = |
214 (\<mu> x. fst (F\<cdot>(x, \<mu> y. snd (F\<cdot>(x, y)))), |
214 (\<mu> x. fst (F\<cdot>(x, \<mu> y. snd (F\<cdot>(x, y)))), |
215 \<mu> y. snd (F\<cdot>(\<mu> x. fst (F\<cdot>(x, \<mu> y. snd (F\<cdot>(x, y)))), y)))" |
215 \<mu> y. snd (F\<cdot>(\<mu> x. fst (F\<cdot>(x, \<mu> y. snd (F\<cdot>(x, y)))), y)))" |