
oheimb@11351: (*  Title:      HOL/Library/Continuity.thy
oheimb@11351:     ID:         $$
oheimb@11351:     Author: 	David von Oheimb, TU Muenchen
oheimb@11351:     License:    GPL (GNU GENERAL PUBLIC LICENSE)
oheimb@11351: 
oheimb@11351: *)
oheimb@11351: 
oheimb@11351: header {*
oheimb@11351:   \title{Continuity and interations (of set transformers)}
oheimb@11351:   \author{David von Oheimb}
oheimb@11351: *}
oheimb@11351: 
oheimb@11351: theory Continuity = Relation_Power:
oheimb@11351: 
oheimb@11351: 
oheimb@11351: subsection "Chains"
oheimb@11351: 
oheimb@11351: constdefs
oheimb@11351:   up_chain      :: "(nat => 'a set) => bool"
oheimb@11351:  "up_chain F      == !i. F i <= F (Suc i)"
oheimb@11351: 
oheimb@11351: lemma up_chainI: "(!!i. F i <= F (Suc i)) ==> up_chain F"
oheimb@11351: by (simp add: up_chain_def);
oheimb@11351: 
oheimb@11351: lemma up_chainD: "up_chain F ==> F i <= F (Suc i)"
oheimb@11351: by (simp add: up_chain_def);
oheimb@11351: 
oheimb@11351: lemma up_chain_less_mono [rule_format]: "up_chain F ==> x < y --> F x <= F y"
oheimb@11351: apply (induct_tac y)
oheimb@11351: apply (blast dest: up_chainD elim: less_SucE)+
oheimb@11351: done
oheimb@11351: 
oheimb@11351: lemma up_chain_mono: "up_chain F ==> x <= y ==> F x <= F y"
oheimb@11351: apply (drule le_imp_less_or_eq)
oheimb@11351: apply (blast dest: up_chain_less_mono)
oheimb@11351: done
oheimb@11351: 
oheimb@11351: 
oheimb@11351: constdefs
oheimb@11351:   down_chain      :: "(nat => 'a set) => bool"
oheimb@11351:  "down_chain F == !i. F (Suc i) <= F i"
oheimb@11351: 
oheimb@11351: lemma down_chainI: "(!!i. F (Suc i) <= F i) ==> down_chain F"
oheimb@11351: by (simp add: down_chain_def);
oheimb@11351: 
oheimb@11351: lemma down_chainD: "down_chain F ==> F (Suc i) <= F i"
oheimb@11351: by (simp add: down_chain_def);
oheimb@11351: 
oheimb@11351: lemma down_chain_less_mono[rule_format]: "down_chain F ==> x < y --> F y <= F x"
oheimb@11351: apply (induct_tac y)
oheimb@11351: apply (blast dest: down_chainD elim: less_SucE)+
oheimb@11351: done
oheimb@11351: 
oheimb@11351: lemma down_chain_mono: "down_chain F ==> x <= y ==> F y <= F x"
oheimb@11351: apply (drule le_imp_less_or_eq)
oheimb@11351: apply (blast dest: down_chain_less_mono)
oheimb@11351: done
oheimb@11351: 
oheimb@11351: 
oheimb@11351: subsection "Continuity"
oheimb@11351: 
oheimb@11351: constdefs
oheimb@11351:   up_cont :: "('a set => 'a set) => bool"
oheimb@11351:  "up_cont f == !F. up_chain F --> f (Union (range F)) = Union (f`(range F))"
oheimb@11351: 
oheimb@11351: lemma up_contI: 
oheimb@11351:  "(!!F. up_chain F ==> f (Union (range F)) = Union (f`(range F))) ==> up_cont f"
oheimb@11351: apply (unfold up_cont_def)
oheimb@11351: by blast
oheimb@11351: 
oheimb@11351: lemma up_contD: 
oheimb@11351:   "[| up_cont f; up_chain F |] ==> f (Union (range F)) = Union (f`(range F))"
oheimb@11351: apply (unfold up_cont_def)
oheimb@11351: by auto
oheimb@11351: 
oheimb@11351: 
oheimb@11351: lemma up_cont_mono: "up_cont f ==> mono f"
oheimb@11351: apply (rule monoI)
oheimb@11351: apply (drule_tac F = "%i. if i = 0 then A else B" in up_contD)
oheimb@11351: apply  (rule up_chainI)
oheimb@11351: apply  simp+
oheimb@11351: apply (drule Un_absorb1)
oheimb@11351: apply auto
oheimb@11351: done
oheimb@11351: 
oheimb@11351: 
oheimb@11351: constdefs
oheimb@11351:   down_cont :: "('a set => 'a set) => bool"
oheimb@11351:  "down_cont f == !F. down_chain F --> f (Inter (range F)) = Inter (f`(range F))"
oheimb@11351: 
oheimb@11351: lemma down_contI: 
oheimb@11351:  "(!!F. down_chain F ==> f (Inter (range F)) = Inter (f`(range F))) ==> 
oheimb@11351:   down_cont f"
oheimb@11351: apply (unfold down_cont_def)
oheimb@11351: by blast
oheimb@11351: 
oheimb@11351: lemma down_contD: "[| down_cont f; down_chain F |] ==> 
oheimb@11351:   f (Inter (range F)) = Inter (f`(range F))"
oheimb@11351: apply (unfold down_cont_def)
oheimb@11351: by auto
oheimb@11351: 
oheimb@11351: lemma down_cont_mono: "down_cont f ==> mono f"
oheimb@11351: apply (rule monoI)
oheimb@11351: apply (drule_tac F = "%i. if i = 0 then B else A" in down_contD)
oheimb@11351: apply  (rule down_chainI)
oheimb@11351: apply  simp+
oheimb@11351: apply (drule Int_absorb1)
oheimb@11351: apply auto
oheimb@11351: done
oheimb@11351: 
oheimb@11351: 
oheimb@11351: subsection "Iteration"
oheimb@11351: 
oheimb@11351: constdefs
oheimb@11351: 
oheimb@11351:   up_iterate :: "('a set => 'a set) => nat => 'a set"
oheimb@11351:  "up_iterate f n == (f^n) {}"
oheimb@11351: 
oheimb@11351: lemma up_iterate_0 [simp]: "up_iterate f 0 = {}"
oheimb@11351: by (simp add: up_iterate_def)
oheimb@11351: 
oheimb@11351: lemma up_iterate_Suc [simp]: 
oheimb@11351:   "up_iterate f (Suc i) = f (up_iterate f i)"
oheimb@11351: by (simp add: up_iterate_def)
oheimb@11351: 
oheimb@11351: lemma up_iterate_chain: "mono F ==> up_chain (up_iterate F)"
oheimb@11351: apply (rule up_chainI)
oheimb@11351: apply (induct_tac i)
oheimb@11351: apply simp+
oheimb@11351: apply (erule (1) monoD)
oheimb@11351: done
oheimb@11351: 
oheimb@11351: lemma UNION_up_iterate_is_fp: 
oheimb@11351: "up_cont F ==> F (UNION UNIV (up_iterate F)) = UNION UNIV (up_iterate F)"
oheimb@11351: apply (frule up_cont_mono [THEN up_iterate_chain])
oheimb@11351: apply (drule (1) up_contD)
oheimb@11351: apply simp
oheimb@11351: apply (auto simp del: up_iterate_Suc simp add: up_iterate_Suc [symmetric])
oheimb@11351: apply (case_tac "xa")
oheimb@11351: apply auto
oheimb@11351: done
oheimb@11351: 
oheimb@11351: lemma UNION_up_iterate_lowerbound: 
oheimb@11351: "[| mono F; F P = P |] ==> UNION UNIV (up_iterate F) <= P"
oheimb@11351: apply (subgoal_tac "(!!i. up_iterate F i <= P)")
oheimb@11351: apply  fast
oheimb@11351: apply (induct_tac "i")
oheimb@11351: prefer 2 apply (drule (1) monoD)
oheimb@11351: apply auto
oheimb@11351: done
oheimb@11351: 
oheimb@11351: lemma UNION_up_iterate_is_lfp: 
oheimb@11351:   "up_cont F ==> lfp F = UNION UNIV (up_iterate F)"
oheimb@11351: apply (rule set_eq_subset [THEN iffD2])
oheimb@11351: apply (rule conjI)
oheimb@11351: prefer 2
oheimb@11351: apply  (drule up_cont_mono)
oheimb@11351: apply  (rule UNION_up_iterate_lowerbound)
oheimb@11351: apply   assumption
oheimb@11351: apply  (erule lfp_unfold [symmetric])
oheimb@11351: apply (rule lfp_lowerbound)
oheimb@11351: apply (rule set_eq_subset [THEN iffD1, THEN conjunct2])
oheimb@11351: apply (erule UNION_up_iterate_is_fp [symmetric])
oheimb@11351: done
oheimb@11351: 
oheimb@11351: 
oheimb@11351: constdefs
oheimb@11351: 
oheimb@11351:   down_iterate :: "('a set => 'a set) => nat => 'a set"
oheimb@11351:  "down_iterate f n == (f^n) UNIV"
oheimb@11351: 
oheimb@11351: lemma down_iterate_0 [simp]: "down_iterate f 0 = UNIV"
oheimb@11351: by (simp add: down_iterate_def)
oheimb@11351: 
oheimb@11351: lemma down_iterate_Suc [simp]: 
oheimb@11351:   "down_iterate f (Suc i) = f (down_iterate f i)"
oheimb@11351: by (simp add: down_iterate_def)
oheimb@11351: 
oheimb@11351: lemma down_iterate_chain: "mono F ==> down_chain (down_iterate F)"
oheimb@11351: apply (rule down_chainI)
oheimb@11351: apply (induct_tac i)
oheimb@11351: apply simp+
oheimb@11351: apply (erule (1) monoD)
oheimb@11351: done
oheimb@11351: 
oheimb@11351: lemma INTER_down_iterate_is_fp: 
oheimb@11351: "down_cont F ==> 
oheimb@11351:  F (INTER UNIV (down_iterate F)) = INTER UNIV (down_iterate F)"
oheimb@11351: apply (frule down_cont_mono [THEN down_iterate_chain])
oheimb@11351: apply (drule (1) down_contD)
oheimb@11351: apply simp
oheimb@11351: apply (auto simp del: down_iterate_Suc simp add: down_iterate_Suc [symmetric])
oheimb@11351: apply (case_tac "xa")
oheimb@11351: apply auto
oheimb@11351: done
oheimb@11351: 
oheimb@11351: lemma INTER_down_iterate_upperbound: 
oheimb@11351: "[| mono F; F P = P |] ==> P <= INTER UNIV (down_iterate F)"
oheimb@11351: apply (subgoal_tac "(!!i. P <= down_iterate F i)")
oheimb@11351: apply  fast
oheimb@11351: apply (induct_tac "i")
oheimb@11351: prefer 2 apply (drule (1) monoD)
oheimb@11351: apply auto
oheimb@11351: done
oheimb@11351: 
oheimb@11351: lemma INTER_down_iterate_is_gfp: 
oheimb@11351:   "down_cont F ==> gfp F = INTER UNIV (down_iterate F)"
oheimb@11351: apply (rule set_eq_subset [THEN iffD2])
oheimb@11351: apply (rule conjI)
oheimb@11351: apply  (drule down_cont_mono)
oheimb@11351: apply  (rule INTER_down_iterate_upperbound)
oheimb@11351: apply   assumption
oheimb@11351: apply  (erule gfp_unfold [symmetric])
oheimb@11351: apply (rule gfp_upperbound)
oheimb@11351: apply (rule set_eq_subset [THEN iffD1, THEN conjunct2])
oheimb@11351: apply (erule INTER_down_iterate_is_fp)
oheimb@11351: done
oheimb@11351: 
oheimb@11351: end




