# HG changeset patch # User blanchet # Date 1409582080 -7200 # Node ID 43a1ba26a8cbdf197569a18d01515d29ceec1492 # Parent b7cab82f488e9696e94bfb98cd50b9d9cdef49fa renamed BNF theories diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/BNF_Comp.thy --- a/src/HOL/BNF_Comp.thy Mon Sep 01 16:34:39 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +0,0 @@ -(* Title: HOL/BNF_Comp.thy - Author: Dmitriy Traytel, TU Muenchen - Author: Jasmin Blanchette, TU Muenchen - Copyright 2012, 2013, 2014 - -Composition of bounded natural functors. -*) - -header {* Composition of Bounded Natural Functors *} - -theory BNF_Comp -imports BNF_Def -begin - -lemma empty_natural: "(\_. {}) o f = image g o (\_. {})" -by (rule ext) simp - -lemma Union_natural: "Union o image (image f) = image f o Union" -by (rule ext) (auto simp only: comp_apply) - -lemma in_Union_o_assoc: "x \ (Union o gset o gmap) A \ x \ (Union o (gset o gmap)) A" -by (unfold comp_assoc) - -lemma comp_single_set_bd: - assumes fbd_Card_order: "Card_order fbd" and - fset_bd: "\x. |fset x| \o fbd" and - gset_bd: "\x. |gset x| \o gbd" - shows "|\(fset ` gset x)| \o gbd *c fbd" -apply simp -apply (rule ordLeq_transitive) -apply (rule card_of_UNION_Sigma) -apply (subst SIGMA_CSUM) -apply (rule ordLeq_transitive) -apply (rule card_of_Csum_Times') -apply (rule fbd_Card_order) -apply (rule ballI) -apply (rule fset_bd) -apply (rule ordLeq_transitive) -apply (rule cprod_mono1) -apply (rule gset_bd) -apply (rule ordIso_imp_ordLeq) -apply (rule ordIso_refl) -apply (rule Card_order_cprod) -done - -lemma csum_dup: "cinfinite r \ Card_order r \ p +c p' =o r +c r \ p +c p' =o r" -apply (erule ordIso_transitive) -apply (frule csum_absorb2') -apply (erule ordLeq_refl) -by simp - -lemma cprod_dup: "cinfinite r \ Card_order r \ p *c p' =o r *c r \ p *c p' =o r" -apply (erule ordIso_transitive) -apply (rule cprod_infinite) -by simp - -lemma Union_image_insert: "\(f ` insert a B) = f a \ \(f ` B)" -by simp - -lemma Union_image_empty: "A \ \(f ` {}) = A" -by simp - -lemma image_o_collect: "collect ((\f. image g o f) ` F) = image g o collect F" -by (rule ext) (auto simp add: collect_def) - -lemma conj_subset_def: "A \ {x. P x \ Q x} = (A \ {x. P x} \ A \ {x. Q x})" -by blast - -lemma UN_image_subset: "\(f ` g x) \ X = (g x \ {x. f x \ X})" -by blast - -lemma comp_set_bd_Union_o_collect: "|\\((\f. f x) ` X)| \o hbd \ |(Union \ collect X) x| \o hbd" -by (unfold comp_apply collect_def) simp - -lemma wpull_cong: -"\A' = A; B1' = B1; B2' = B2; wpull A B1 B2 f1 f2 p1 p2\ \ wpull A' B1' B2' f1 f2 p1 p2" -by simp - -lemma Grp_fst_snd: "(Grp (Collect (split R)) fst)^--1 OO Grp (Collect (split R)) snd = R" -unfolding Grp_def fun_eq_iff relcompp.simps by auto - -lemma OO_Grp_cong: "A = B \ (Grp A f)^--1 OO Grp A g = (Grp B f)^--1 OO Grp B g" -by (rule arg_cong) - -lemma vimage2p_relcompp_mono: "R OO S \ T \ - vimage2p f g R OO vimage2p g h S \ vimage2p f h T" - unfolding vimage2p_def by auto - -lemma type_copy_map_cong0: "M (g x) = N (h x) \ (f o M o g) x = (f o N o h) x" - by auto - -lemma type_copy_set_bd: "(\y. |S y| \o bd) \ |(S o Rep) x| \o bd" - by auto - -lemma vimage2p_cong: "R = S \ vimage2p f g R = vimage2p f g S" - by simp - -context -fixes Rep Abs -assumes type_copy: "type_definition Rep Abs UNIV" -begin - -lemma type_copy_map_id0: "M = id \ Abs o M o Rep = id" - using type_definition.Rep_inverse[OF type_copy] by auto - -lemma type_copy_map_comp0: "M = M1 o M2 \ f o M o g = (f o M1 o Rep) o (Abs o M2 o g)" - using type_definition.Abs_inverse[OF type_copy UNIV_I] by auto - -lemma type_copy_set_map0: "S o M = image f o S' \ (S o Rep) o (Abs o M o g) = image f o (S' o g)" - using type_definition.Abs_inverse[OF type_copy UNIV_I] by (auto simp: o_def fun_eq_iff) - -lemma type_copy_wit: "x \ (S o Rep) (Abs y) \ x \ S y" - using type_definition.Abs_inverse[OF type_copy UNIV_I] by auto - -lemma type_copy_vimage2p_Grp_Rep: "vimage2p f Rep (Grp (Collect P) h) = - Grp (Collect (\x. P (f x))) (Abs o h o f)" - unfolding vimage2p_def Grp_def fun_eq_iff - by (auto simp: type_definition.Abs_inverse[OF type_copy UNIV_I] - type_definition.Rep_inverse[OF type_copy] dest: sym) - -lemma type_copy_vimage2p_Grp_Abs: - "\h. vimage2p g Abs (Grp (Collect P) h) = Grp (Collect (\x. P (g x))) (Rep o h o g)" - unfolding vimage2p_def Grp_def fun_eq_iff - by (auto simp: type_definition.Abs_inverse[OF type_copy UNIV_I] - type_definition.Rep_inverse[OF type_copy] dest: sym) - -lemma type_copy_ex_RepI: "(\b. F b) = (\b. F (Rep b))" -proof safe - fix b assume "F b" - show "\b'. F (Rep b')" - proof (rule exI) - from `F b` show "F (Rep (Abs b))" using type_definition.Abs_inverse[OF type_copy] by auto - qed -qed blast - -lemma vimage2p_relcompp_converse: - "vimage2p f g (R^--1 OO S) = (vimage2p Rep f R)^--1 OO vimage2p Rep g S" - unfolding vimage2p_def relcompp.simps conversep.simps fun_eq_iff image_def - by (auto simp: type_copy_ex_RepI) - -end - -bnf DEADID: 'a - map: "id :: 'a \ 'a" - bd: natLeq - rel: "op = :: 'a \ 'a \ bool" -by (auto simp add: Grp_def natLeq_card_order natLeq_cinfinite) - -definition id_bnf_comp :: "'a \ 'a" where "id_bnf_comp \ (\x. x)" - -lemma id_bnf_comp_apply: "id_bnf_comp x = x" - unfolding id_bnf_comp_def by simp - -bnf ID: 'a - map: "id_bnf_comp :: ('a \ 'b) \ 'a \ 'b" - sets: "\x. {x}" - bd: natLeq - rel: "id_bnf_comp :: ('a \ 'b \ bool) \ 'a \ 'b \ bool" -unfolding id_bnf_comp_def -apply (auto simp: Grp_def fun_eq_iff relcompp.simps natLeq_card_order natLeq_cinfinite) -apply (rule ordLess_imp_ordLeq[OF finite_ordLess_infinite[OF _ natLeq_Well_order]]) -apply (auto simp add: Field_card_of Field_natLeq card_of_well_order_on)[3] -done - -lemma type_definition_id_bnf_comp_UNIV: "type_definition id_bnf_comp id_bnf_comp UNIV" - unfolding id_bnf_comp_def by unfold_locales auto - -ML_file "Tools/BNF/bnf_comp_tactics.ML" -ML_file "Tools/BNF/bnf_comp.ML" - -hide_const (open) id_bnf_comp -hide_fact (open) id_bnf_comp_def type_definition_id_bnf_comp_UNIV - -end diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/BNF_Composition.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/BNF_Composition.thy Mon Sep 01 16:34:40 2014 +0200 @@ -0,0 +1,174 @@ +(* Title: HOL/BNF_Composition.thy + Author: Dmitriy Traytel, TU Muenchen + Author: Jasmin Blanchette, TU Muenchen + Copyright 2012, 2013, 2014 + +Composition of bounded natural functors. +*) + +header {* Composition of Bounded Natural Functors *} + +theory BNF_Composition +imports BNF_Def +begin + +lemma empty_natural: "(\_. {}) o f = image g o (\_. {})" + by (rule ext) simp + +lemma Union_natural: "Union o image (image f) = image f o Union" + by (rule ext) (auto simp only: comp_apply) + +lemma in_Union_o_assoc: "x \ (Union o gset o gmap) A \ x \ (Union o (gset o gmap)) A" + by (unfold comp_assoc) + +lemma comp_single_set_bd: + assumes fbd_Card_order: "Card_order fbd" and + fset_bd: "\x. |fset x| \o fbd" and + gset_bd: "\x. |gset x| \o gbd" + shows "|\(fset ` gset x)| \o gbd *c fbd" + apply simp + apply (rule ordLeq_transitive) + apply (rule card_of_UNION_Sigma) + apply (subst SIGMA_CSUM) + apply (rule ordLeq_transitive) + apply (rule card_of_Csum_Times') + apply (rule fbd_Card_order) + apply (rule ballI) + apply (rule fset_bd) + apply (rule ordLeq_transitive) + apply (rule cprod_mono1) + apply (rule gset_bd) + apply (rule ordIso_imp_ordLeq) + apply (rule ordIso_refl) + apply (rule Card_order_cprod) + done + +lemma csum_dup: "cinfinite r \ Card_order r \ p +c p' =o r +c r \ p +c p' =o r" + apply (erule ordIso_transitive) + apply (frule csum_absorb2') + apply (erule ordLeq_refl) + by simp + +lemma cprod_dup: "cinfinite r \ Card_order r \ p *c p' =o r *c r \ p *c p' =o r" + apply (erule ordIso_transitive) + apply (rule cprod_infinite) + by simp + +lemma Union_image_insert: "\(f ` insert a B) = f a \ \(f ` B)" + by simp + +lemma Union_image_empty: "A \ \(f ` {}) = A" + by simp + +lemma image_o_collect: "collect ((\f. image g o f) ` F) = image g o collect F" + by (rule ext) (auto simp add: collect_def) + +lemma conj_subset_def: "A \ {x. P x \ Q x} = (A \ {x. P x} \ A \ {x. Q x})" + by blast + +lemma UN_image_subset: "\(f ` g x) \ X = (g x \ {x. f x \ X})" + by blast + +lemma comp_set_bd_Union_o_collect: "|\\((\f. f x) ` X)| \o hbd \ |(Union \ collect X) x| \o hbd" + by (unfold comp_apply collect_def) simp + +lemma wpull_cong: + "\A' = A; B1' = B1; B2' = B2; wpull A B1 B2 f1 f2 p1 p2\ \ wpull A' B1' B2' f1 f2 p1 p2" + by simp + +lemma Grp_fst_snd: "(Grp (Collect (split R)) fst)^--1 OO Grp (Collect (split R)) snd = R" + unfolding Grp_def fun_eq_iff relcompp.simps by auto + +lemma OO_Grp_cong: "A = B \ (Grp A f)^--1 OO Grp A g = (Grp B f)^--1 OO Grp B g" + by (rule arg_cong) + +lemma vimage2p_relcompp_mono: "R OO S \ T \ + vimage2p f g R OO vimage2p g h S \ vimage2p f h T" + unfolding vimage2p_def by auto + +lemma type_copy_map_cong0: "M (g x) = N (h x) \ (f o M o g) x = (f o N o h) x" + by auto + +lemma type_copy_set_bd: "(\y. |S y| \o bd) \ |(S o Rep) x| \o bd" + by auto + +lemma vimage2p_cong: "R = S \ vimage2p f g R = vimage2p f g S" + by simp + +context + fixes Rep Abs + assumes type_copy: "type_definition Rep Abs UNIV" +begin + +lemma type_copy_map_id0: "M = id \ Abs o M o Rep = id" + using type_definition.Rep_inverse[OF type_copy] by auto + +lemma type_copy_map_comp0: "M = M1 o M2 \ f o M o g = (f o M1 o Rep) o (Abs o M2 o g)" + using type_definition.Abs_inverse[OF type_copy UNIV_I] by auto + +lemma type_copy_set_map0: "S o M = image f o S' \ (S o Rep) o (Abs o M o g) = image f o (S' o g)" + using type_definition.Abs_inverse[OF type_copy UNIV_I] by (auto simp: o_def fun_eq_iff) + +lemma type_copy_wit: "x \ (S o Rep) (Abs y) \ x \ S y" + using type_definition.Abs_inverse[OF type_copy UNIV_I] by auto + +lemma type_copy_vimage2p_Grp_Rep: "vimage2p f Rep (Grp (Collect P) h) = + Grp (Collect (\x. P (f x))) (Abs o h o f)" + unfolding vimage2p_def Grp_def fun_eq_iff + by (auto simp: type_definition.Abs_inverse[OF type_copy UNIV_I] + type_definition.Rep_inverse[OF type_copy] dest: sym) + +lemma type_copy_vimage2p_Grp_Abs: + "\h. vimage2p g Abs (Grp (Collect P) h) = Grp (Collect (\x. P (g x))) (Rep o h o g)" + unfolding vimage2p_def Grp_def fun_eq_iff + by (auto simp: type_definition.Abs_inverse[OF type_copy UNIV_I] + type_definition.Rep_inverse[OF type_copy] dest: sym) + +lemma type_copy_ex_RepI: "(\b. F b) = (\b. F (Rep b))" +proof safe + fix b assume "F b" + show "\b'. F (Rep b')" + proof (rule exI) + from `F b` show "F (Rep (Abs b))" using type_definition.Abs_inverse[OF type_copy] by auto + qed +qed blast + +lemma vimage2p_relcompp_converse: + "vimage2p f g (R^--1 OO S) = (vimage2p Rep f R)^--1 OO vimage2p Rep g S" + unfolding vimage2p_def relcompp.simps conversep.simps fun_eq_iff image_def + by (auto simp: type_copy_ex_RepI) + +end + +bnf DEADID: 'a + map: "id :: 'a \ 'a" + bd: natLeq + rel: "op = :: 'a \ 'a \ bool" + by (auto simp add: Grp_def natLeq_card_order natLeq_cinfinite) + +definition id_bnf_comp :: "'a \ 'a" where "id_bnf_comp \ (\x. x)" + +lemma id_bnf_comp_apply: "id_bnf_comp x = x" + unfolding id_bnf_comp_def by simp + +bnf ID: 'a + map: "id_bnf_comp :: ('a \ 'b) \ 'a \ 'b" + sets: "\x. {x}" + bd: natLeq + rel: "id_bnf_comp :: ('a \ 'b \ bool) \ 'a \ 'b \ bool" + unfolding id_bnf_comp_def + apply (auto simp: Grp_def fun_eq_iff relcompp.simps natLeq_card_order natLeq_cinfinite) + apply (rule ordLess_imp_ordLeq[OF finite_ordLess_infinite[OF _ natLeq_Well_order]]) + apply (auto simp add: Field_card_of Field_natLeq card_of_well_order_on)[3] + done + +lemma type_definition_id_bnf_comp_UNIV: "type_definition id_bnf_comp id_bnf_comp UNIV" + unfolding id_bnf_comp_def by unfold_locales auto + +ML_file "Tools/BNF/bnf_comp_tactics.ML" +ML_file "Tools/BNF/bnf_comp.ML" + +hide_const (open) id_bnf_comp +hide_fact (open) id_bnf_comp_def type_definition_id_bnf_comp_UNIV + +end diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/BNF_FP_Base.thy --- a/src/HOL/BNF_FP_Base.thy Mon Sep 01 16:34:39 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,232 +0,0 @@ -(* Title: HOL/BNF_FP_Base.thy - Author: Lorenz Panny, TU Muenchen - Author: Dmitriy Traytel, TU Muenchen - Author: Jasmin Blanchette, TU Muenchen - Author: Martin Desharnais, TU Muenchen - Copyright 2012, 2013, 2014 - -Shared fixed point operations on bounded natural functors. -*) - -header {* Shared Fixed Point Operations on Bounded Natural Functors *} - -theory BNF_FP_Base -imports BNF_Comp Basic_BNFs -begin - -lemma False_imp_eq_True: "(False \ Q) \ Trueprop True" - by default simp_all - -lemma conj_imp_eq_imp_imp: "(P \ Q \ PROP R) \ (P \ Q \ PROP R)" - by default simp_all - -lemma mp_conj: "(P \ Q) \ R \ P \ R \ Q" -by auto - -lemma predicate2D_conj: "P \ Q \ R \ P x y \ R \ Q x y" - by auto - -lemma eq_sym_Unity_conv: "(x = (() = ())) = x" -by blast - -lemma case_unit_Unity: "(case u of () \ f) = f" -by (cases u) (hypsubst, rule unit.case) - -lemma case_prod_Pair_iden: "(case p of (x, y) \ (x, y)) = p" -by simp - -lemma unit_all_impI: "(P () \ Q ()) \ \x. P x \ Q x" -by simp - -lemma pointfree_idE: "f \ g = id \ f (g x) = x" -unfolding comp_def fun_eq_iff by simp - -lemma o_bij: - assumes gf: "g \ f = id" and fg: "f \ g = id" - shows "bij f" -unfolding bij_def inj_on_def surj_def proof safe - fix a1 a2 assume "f a1 = f a2" - hence "g ( f a1) = g (f a2)" by simp - thus "a1 = a2" using gf unfolding fun_eq_iff by simp -next - fix b - have "b = f (g b)" - using fg unfolding fun_eq_iff by simp - thus "EX a. b = f a" by blast -qed - -lemma ssubst_mem: "\t = s; s \ X\ \ t \ X" by simp - -lemma case_sum_step: -"case_sum (case_sum f' g') g (Inl p) = case_sum f' g' p" -"case_sum f (case_sum f' g') (Inr p) = case_sum f' g' p" -by auto - -lemma obj_one_pointE: "\x. s = x \ P \ P" -by blast - -lemma type_copy_obj_one_point_absE: - assumes "type_definition Rep Abs UNIV" "\x. s = Abs x \ P" shows P - using type_definition.Rep_inverse[OF assms(1)] - by (intro mp[OF spec[OF assms(2), of "Rep s"]]) simp - -lemma obj_sumE_f: - assumes "\x. s = f (Inl x) \ P" "\x. s = f (Inr x) \ P" - shows "\x. s = f x \ P" -proof - fix x from assms show "s = f x \ P" by (cases x) auto -qed - -lemma case_sum_if: -"case_sum f g (if p then Inl x else Inr y) = (if p then f x else g y)" -by simp - -lemma prod_set_simps: -"fsts (x, y) = {x}" -"snds (x, y) = {y}" -unfolding fsts_def snds_def by simp+ - -lemma sum_set_simps: -"setl (Inl x) = {x}" -"setl (Inr x) = {}" -"setr (Inl x) = {}" -"setr (Inr x) = {x}" -unfolding sum_set_defs by simp+ - -lemma Inl_Inr_False: "(Inl x = Inr y) = False" - by simp - -lemma Inr_Inl_False: "(Inr x = Inl y) = False" - by simp - -lemma spec2: "\x y. P x y \ P x y" -by blast - -lemma rewriteR_comp_comp: "\g \ h = r\ \ f \ g \ h = f \ r" - unfolding comp_def fun_eq_iff by auto - -lemma rewriteR_comp_comp2: "\g \ h = r1 \ r2; f \ r1 = l\ \ f \ g \ h = l \ r2" - unfolding comp_def fun_eq_iff by auto - -lemma rewriteL_comp_comp: "\f \ g = l\ \ f \ (g \ h) = l \ h" - unfolding comp_def fun_eq_iff by auto - -lemma rewriteL_comp_comp2: "\f \ g = l1 \ l2; l2 \ h = r\ \ f \ (g \ h) = l1 \ r" - unfolding comp_def fun_eq_iff by auto - -lemma convol_o: "\f, g\ \ h = \f \ h, g \ h\" - unfolding convol_def by auto - -lemma map_prod_o_convol: "map_prod h1 h2 \ \f, g\ = \h1 \ f, h2 \ g\" - unfolding convol_def by auto - -lemma map_prod_o_convol_id: "(map_prod f id \ \id, g\) x = \id \ f, g\ x" - unfolding map_prod_o_convol id_comp comp_id .. - -lemma o_case_sum: "h \ case_sum f g = case_sum (h \ f) (h \ g)" - unfolding comp_def by (auto split: sum.splits) - -lemma case_sum_o_map_sum: "case_sum f g \ map_sum h1 h2 = case_sum (f \ h1) (g \ h2)" - unfolding comp_def by (auto split: sum.splits) - -lemma case_sum_o_map_sum_id: "(case_sum id g \ map_sum f id) x = case_sum (f \ id) g x" - unfolding case_sum_o_map_sum id_comp comp_id .. - -lemma rel_fun_def_butlast: - "rel_fun R (rel_fun S T) f g = (\x y. R x y \ (rel_fun S T) (f x) (g y))" - unfolding rel_fun_def .. - -lemma subst_eq_imp: "(\a b. a = b \ P a b) \ (\a. P a a)" - by auto - -lemma eq_subset: "op = \ (\a b. P a b \ a = b)" - by auto - -lemma eq_le_Grp_id_iff: "(op = \ Grp (Collect R) id) = (All R)" - unfolding Grp_def id_apply by blast - -lemma Grp_id_mono_subst: "(\x y. Grp P id x y \ Grp Q id (f x) (f y)) \ - (\x. x \ P \ f x \ Q)" - unfolding Grp_def by rule auto - -lemma vimage2p_mono: "vimage2p f g R x y \ R \ S \ vimage2p f g S x y" - unfolding vimage2p_def by blast - -lemma vimage2p_refl: "(\x. R x x) \ vimage2p f f R x x" - unfolding vimage2p_def by auto - -lemma - assumes "type_definition Rep Abs UNIV" - shows type_copy_Rep_o_Abs: "Rep \ Abs = id" and type_copy_Abs_o_Rep: "Abs \ Rep = id" - unfolding fun_eq_iff comp_apply id_apply - type_definition.Abs_inverse[OF assms UNIV_I] type_definition.Rep_inverse[OF assms] by simp_all - -lemma type_copy_map_comp0_undo: - assumes "type_definition Rep Abs UNIV" - "type_definition Rep' Abs' UNIV" - "type_definition Rep'' Abs'' UNIV" - shows "Abs' \ M \ Rep'' = (Abs' \ M1 \ Rep) \ (Abs \ M2 \ Rep'') \ M1 \ M2 = M" - by (rule sym) (auto simp: fun_eq_iff type_definition.Abs_inject[OF assms(2) UNIV_I UNIV_I] - type_definition.Abs_inverse[OF assms(1) UNIV_I] - type_definition.Abs_inverse[OF assms(3) UNIV_I] dest: spec[of _ "Abs'' x" for x]) - -lemma vimage2p_id: "vimage2p id id R = R" - unfolding vimage2p_def by auto - -lemma vimage2p_comp: "vimage2p (f1 \ f2) (g1 \ g2) = vimage2p f2 g2 \ vimage2p f1 g1" - unfolding fun_eq_iff vimage2p_def o_apply by simp - -lemma fun_cong_unused_0: "f = (\x. g) \ f (\x. 0) = g" - by (erule arg_cong) - -lemma inj_on_convol_ident: "inj_on (\x. (x, f x)) X" - unfolding inj_on_def by simp - -lemma case_prod_app: "case_prod f x y = case_prod (\l r. f l r y) x" - by (case_tac x) simp - -lemma case_sum_map_sum: "case_sum l r (map_sum f g x) = case_sum (l \ f) (r \ g) x" - by (case_tac x) simp+ - -lemma case_prod_map_prod: "case_prod h (map_prod f g x) = case_prod (\l r. h (f l) (g r)) x" - by (case_tac x) simp+ - -lemma prod_inj_map: "inj f \ inj g \ inj (map_prod f g)" - by (simp add: inj_on_def) - -lemma eq_ifI: "(P \ t = u1) \ (\ P \ t = u2) \ t = (if P then u1 else u2)" - by simp - -ML_file "Tools/BNF/bnf_fp_util.ML" -ML_file "Tools/BNF/bnf_fp_def_sugar_tactics.ML" -ML_file "Tools/BNF/bnf_lfp_size.ML" -ML_file "Tools/BNF/bnf_fp_def_sugar.ML" -ML_file "Tools/BNF/bnf_fp_n2m_tactics.ML" -ML_file "Tools/BNF/bnf_fp_n2m.ML" -ML_file "Tools/BNF/bnf_fp_n2m_sugar.ML" - -ML_file "Tools/Function/old_size.ML" -setup Old_Size.setup - -lemma size_bool[code]: "size (b\bool) = 0" - by (cases b) auto - -lemma size_nat[simp, code]: "size (n\nat) = n" - by (induct n) simp_all - -declare prod.size[no_atp] - -lemma size_sum_o_map: "size_sum g1 g2 \ map_sum f1 f2 = size_sum (g1 \ f1) (g2 \ f2)" - by (rule ext) (case_tac x, auto) - -lemma size_prod_o_map: "size_prod g1 g2 \ map_prod f1 f2 = size_prod (g1 \ f1) (g2 \ f2)" - by (rule ext) auto - -setup {* -BNF_LFP_Size.register_size_global @{type_name sum} @{const_name size_sum} @{thms sum.size} - @{thms size_sum_o_map} -#> BNF_LFP_Size.register_size_global @{type_name prod} @{const_name size_prod} @{thms prod.size} - @{thms size_prod_o_map} -*} - -end diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/BNF_Fixpoint_Base.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/BNF_Fixpoint_Base.thy Mon Sep 01 16:34:40 2014 +0200 @@ -0,0 +1,232 @@ +(* Title: HOL/BNF_Fixpoint_Base.thy + Author: Lorenz Panny, TU Muenchen + Author: Dmitriy Traytel, TU Muenchen + Author: Jasmin Blanchette, TU Muenchen + Author: Martin Desharnais, TU Muenchen + Copyright 2012, 2013, 2014 + +Shared fixed point operations on bounded natural functors. +*) + +header {* Shared Fixed Point Operations on Bounded Natural Functors *} + +theory BNF_Fixpoint_Base +imports BNF_Composition Basic_BNFs +begin + +lemma False_imp_eq_True: "(False \ Q) \ Trueprop True" + by default simp_all + +lemma conj_imp_eq_imp_imp: "(P \ Q \ PROP R) \ (P \ Q \ PROP R)" + by default simp_all + +lemma mp_conj: "(P \ Q) \ R \ P \ R \ Q" +by auto + +lemma predicate2D_conj: "P \ Q \ R \ P x y \ R \ Q x y" + by auto + +lemma eq_sym_Unity_conv: "(x = (() = ())) = x" +by blast + +lemma case_unit_Unity: "(case u of () \ f) = f" +by (cases u) (hypsubst, rule unit.case) + +lemma case_prod_Pair_iden: "(case p of (x, y) \ (x, y)) = p" +by simp + +lemma unit_all_impI: "(P () \ Q ()) \ \x. P x \ Q x" +by simp + +lemma pointfree_idE: "f \ g = id \ f (g x) = x" +unfolding comp_def fun_eq_iff by simp + +lemma o_bij: + assumes gf: "g \ f = id" and fg: "f \ g = id" + shows "bij f" +unfolding bij_def inj_on_def surj_def proof safe + fix a1 a2 assume "f a1 = f a2" + hence "g ( f a1) = g (f a2)" by simp + thus "a1 = a2" using gf unfolding fun_eq_iff by simp +next + fix b + have "b = f (g b)" + using fg unfolding fun_eq_iff by simp + thus "EX a. b = f a" by blast +qed + +lemma ssubst_mem: "\t = s; s \ X\ \ t \ X" by simp + +lemma case_sum_step: +"case_sum (case_sum f' g') g (Inl p) = case_sum f' g' p" +"case_sum f (case_sum f' g') (Inr p) = case_sum f' g' p" +by auto + +lemma obj_one_pointE: "\x. s = x \ P \ P" +by blast + +lemma type_copy_obj_one_point_absE: + assumes "type_definition Rep Abs UNIV" "\x. s = Abs x \ P" shows P + using type_definition.Rep_inverse[OF assms(1)] + by (intro mp[OF spec[OF assms(2), of "Rep s"]]) simp + +lemma obj_sumE_f: + assumes "\x. s = f (Inl x) \ P" "\x. s = f (Inr x) \ P" + shows "\x. s = f x \ P" +proof + fix x from assms show "s = f x \ P" by (cases x) auto +qed + +lemma case_sum_if: +"case_sum f g (if p then Inl x else Inr y) = (if p then f x else g y)" +by simp + +lemma prod_set_simps: +"fsts (x, y) = {x}" +"snds (x, y) = {y}" +unfolding fsts_def snds_def by simp+ + +lemma sum_set_simps: +"setl (Inl x) = {x}" +"setl (Inr x) = {}" +"setr (Inl x) = {}" +"setr (Inr x) = {x}" +unfolding sum_set_defs by simp+ + +lemma Inl_Inr_False: "(Inl x = Inr y) = False" + by simp + +lemma Inr_Inl_False: "(Inr x = Inl y) = False" + by simp + +lemma spec2: "\x y. P x y \ P x y" +by blast + +lemma rewriteR_comp_comp: "\g \ h = r\ \ f \ g \ h = f \ r" + unfolding comp_def fun_eq_iff by auto + +lemma rewriteR_comp_comp2: "\g \ h = r1 \ r2; f \ r1 = l\ \ f \ g \ h = l \ r2" + unfolding comp_def fun_eq_iff by auto + +lemma rewriteL_comp_comp: "\f \ g = l\ \ f \ (g \ h) = l \ h" + unfolding comp_def fun_eq_iff by auto + +lemma rewriteL_comp_comp2: "\f \ g = l1 \ l2; l2 \ h = r\ \ f \ (g \ h) = l1 \ r" + unfolding comp_def fun_eq_iff by auto + +lemma convol_o: "\f, g\ \ h = \f \ h, g \ h\" + unfolding convol_def by auto + +lemma map_prod_o_convol: "map_prod h1 h2 \ \f, g\ = \h1 \ f, h2 \ g\" + unfolding convol_def by auto + +lemma map_prod_o_convol_id: "(map_prod f id \ \id, g\) x = \id \ f, g\ x" + unfolding map_prod_o_convol id_comp comp_id .. + +lemma o_case_sum: "h \ case_sum f g = case_sum (h \ f) (h \ g)" + unfolding comp_def by (auto split: sum.splits) + +lemma case_sum_o_map_sum: "case_sum f g \ map_sum h1 h2 = case_sum (f \ h1) (g \ h2)" + unfolding comp_def by (auto split: sum.splits) + +lemma case_sum_o_map_sum_id: "(case_sum id g \ map_sum f id) x = case_sum (f \ id) g x" + unfolding case_sum_o_map_sum id_comp comp_id .. + +lemma rel_fun_def_butlast: + "rel_fun R (rel_fun S T) f g = (\x y. R x y \ (rel_fun S T) (f x) (g y))" + unfolding rel_fun_def .. + +lemma subst_eq_imp: "(\a b. a = b \ P a b) \ (\a. P a a)" + by auto + +lemma eq_subset: "op = \ (\a b. P a b \ a = b)" + by auto + +lemma eq_le_Grp_id_iff: "(op = \ Grp (Collect R) id) = (All R)" + unfolding Grp_def id_apply by blast + +lemma Grp_id_mono_subst: "(\x y. Grp P id x y \ Grp Q id (f x) (f y)) \ + (\x. x \ P \ f x \ Q)" + unfolding Grp_def by rule auto + +lemma vimage2p_mono: "vimage2p f g R x y \ R \ S \ vimage2p f g S x y" + unfolding vimage2p_def by blast + +lemma vimage2p_refl: "(\x. R x x) \ vimage2p f f R x x" + unfolding vimage2p_def by auto + +lemma + assumes "type_definition Rep Abs UNIV" + shows type_copy_Rep_o_Abs: "Rep \ Abs = id" and type_copy_Abs_o_Rep: "Abs \ Rep = id" + unfolding fun_eq_iff comp_apply id_apply + type_definition.Abs_inverse[OF assms UNIV_I] type_definition.Rep_inverse[OF assms] by simp_all + +lemma type_copy_map_comp0_undo: + assumes "type_definition Rep Abs UNIV" + "type_definition Rep' Abs' UNIV" + "type_definition Rep'' Abs'' UNIV" + shows "Abs' \ M \ Rep'' = (Abs' \ M1 \ Rep) \ (Abs \ M2 \ Rep'') \ M1 \ M2 = M" + by (rule sym) (auto simp: fun_eq_iff type_definition.Abs_inject[OF assms(2) UNIV_I UNIV_I] + type_definition.Abs_inverse[OF assms(1) UNIV_I] + type_definition.Abs_inverse[OF assms(3) UNIV_I] dest: spec[of _ "Abs'' x" for x]) + +lemma vimage2p_id: "vimage2p id id R = R" + unfolding vimage2p_def by auto + +lemma vimage2p_comp: "vimage2p (f1 \ f2) (g1 \ g2) = vimage2p f2 g2 \ vimage2p f1 g1" + unfolding fun_eq_iff vimage2p_def o_apply by simp + +lemma fun_cong_unused_0: "f = (\x. g) \ f (\x. 0) = g" + by (erule arg_cong) + +lemma inj_on_convol_ident: "inj_on (\x. (x, f x)) X" + unfolding inj_on_def by simp + +lemma case_prod_app: "case_prod f x y = case_prod (\l r. f l r y) x" + by (case_tac x) simp + +lemma case_sum_map_sum: "case_sum l r (map_sum f g x) = case_sum (l \ f) (r \ g) x" + by (case_tac x) simp+ + +lemma case_prod_map_prod: "case_prod h (map_prod f g x) = case_prod (\l r. h (f l) (g r)) x" + by (case_tac x) simp+ + +lemma prod_inj_map: "inj f \ inj g \ inj (map_prod f g)" + by (simp add: inj_on_def) + +lemma eq_ifI: "(P \ t = u1) \ (\ P \ t = u2) \ t = (if P then u1 else u2)" + by simp + +ML_file "Tools/BNF/bnf_fp_util.ML" +ML_file "Tools/BNF/bnf_fp_def_sugar_tactics.ML" +ML_file "Tools/BNF/bnf_lfp_size.ML" +ML_file "Tools/BNF/bnf_fp_def_sugar.ML" +ML_file "Tools/BNF/bnf_fp_n2m_tactics.ML" +ML_file "Tools/BNF/bnf_fp_n2m.ML" +ML_file "Tools/BNF/bnf_fp_n2m_sugar.ML" + +ML_file "Tools/Function/old_size.ML" +setup Old_Size.setup + +lemma size_bool[code]: "size (b\bool) = 0" + by (cases b) auto + +lemma size_nat[simp, code]: "size (n\nat) = n" + by (induct n) simp_all + +declare prod.size[no_atp] + +lemma size_sum_o_map: "size_sum g1 g2 \ map_sum f1 f2 = size_sum (g1 \ f1) (g2 \ f2)" + by (rule ext) (case_tac x, auto) + +lemma size_prod_o_map: "size_prod g1 g2 \ map_prod f1 f2 = size_prod (g1 \ f1) (g2 \ f2)" + by (rule ext) auto + +setup {* +BNF_LFP_Size.register_size_global @{type_name sum} @{const_name size_sum} @{thms sum.size} + @{thms size_sum_o_map} +#> BNF_LFP_Size.register_size_global @{type_name prod} @{const_name size_prod} @{thms prod.size} + @{thms size_prod_o_map} +*} + +end diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/BNF_GFP.thy --- a/src/HOL/BNF_GFP.thy Mon Sep 01 16:34:39 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,300 +0,0 @@ -(* Title: HOL/BNF_GFP.thy - Author: Dmitriy Traytel, TU Muenchen - Author: Lorenz Panny, TU Muenchen - Author: Jasmin Blanchette, TU Muenchen - Copyright 2012, 2013, 2014 - -Greatest fixed point operation on bounded natural functors. -*) - -header {* Greatest Fixed Point Operation on Bounded Natural Functors *} - -theory BNF_GFP -imports BNF_FP_Base String -keywords - "codatatype" :: thy_decl and - "primcorecursive" :: thy_goal and - "primcorec" :: thy_decl -begin - -setup {* -Sign.const_alias @{binding proj} @{const_name Equiv_Relations.proj} -*} - -lemma one_pointE: "\\x. s = x \ P\ \ P" - by simp - -lemma obj_sumE: "\\x. s = Inl x \ P; \x. s = Inr x \ P\ \ P" - by (cases s) auto - -lemma not_TrueE: "\ True \ P" - by (erule notE, rule TrueI) - -lemma neq_eq_eq_contradict: "\t \ u; s = t; s = u\ \ P" - by fast - -lemma case_sum_expand_Inr: "f o Inl = g \ f x = case_sum g (f o Inr) x" - by (auto split: sum.splits) - -lemma case_sum_expand_Inr': "f o Inl = g \ h = f o Inr \ case_sum g h = f" - apply rule - apply (rule ext, force split: sum.split) - by (rule ext, metis case_sum_o_inj(2)) - -lemma converse_Times: "(A \ B) ^-1 = B \ A" - by fast - -lemma equiv_proj: - assumes e: "equiv A R" and m: "z \ R" - shows "(proj R o fst) z = (proj R o snd) z" -proof - - from m have z: "(fst z, snd z) \ R" by auto - with e have "\x. (fst z, x) \ R \ (snd z, x) \ R" "\x. (snd z, x) \ R \ (fst z, x) \ R" - unfolding equiv_def sym_def trans_def by blast+ - then show ?thesis unfolding proj_def[abs_def] by auto -qed - -(* Operators: *) -definition image2 where "image2 A f g = {(f a, g a) | a. a \ A}" - -lemma Id_on_Gr: "Id_on A = Gr A id" - unfolding Id_on_def Gr_def by auto - -lemma image2_eqI: "\b = f x; c = g x; x \ A\ \ (b, c) \ image2 A f g" - unfolding image2_def by auto - -lemma IdD: "(a, b) \ Id \ a = b" - by auto - -lemma image2_Gr: "image2 A f g = (Gr A f)^-1 O (Gr A g)" - unfolding image2_def Gr_def by auto - -lemma GrD1: "(x, fx) \ Gr A f \ x \ A" - unfolding Gr_def by simp - -lemma GrD2: "(x, fx) \ Gr A f \ f x = fx" - unfolding Gr_def by simp - -lemma Gr_incl: "Gr A f \ A <*> B \ f ` A \ B" - unfolding Gr_def by auto - -lemma subset_Collect_iff: "B \ A \ (B \ {x \ A. P x}) = (\x \ B. P x)" - by blast - -lemma subset_CollectI: "B \ A \ (\x. x \ B \ Q x \ P x) \ ({x \ B. Q x} \ {x \ A. P x})" - by blast - -lemma in_rel_Collect_split_eq: "in_rel (Collect (split X)) = X" - unfolding fun_eq_iff by auto - -lemma Collect_split_in_rel_leI: "X \ Y \ X \ Collect (split (in_rel Y))" - by auto - -lemma Collect_split_in_rel_leE: "X \ Collect (split (in_rel Y)) \ (X \ Y \ R) \ R" - by force - -lemma conversep_in_rel: "(in_rel R)\\ = in_rel (R\)" - unfolding fun_eq_iff by auto - -lemma relcompp_in_rel: "in_rel R OO in_rel S = in_rel (R O S)" - unfolding fun_eq_iff by auto - -lemma in_rel_Gr: "in_rel (Gr A f) = Grp A f" - unfolding Gr_def Grp_def fun_eq_iff by auto - -definition relImage where - "relImage R f \ {(f a1, f a2) | a1 a2. (a1,a2) \ R}" - -definition relInvImage where - "relInvImage A R f \ {(a1, a2) | a1 a2. a1 \ A \ a2 \ A \ (f a1, f a2) \ R}" - -lemma relImage_Gr: - "\R \ A \ A\ \ relImage R f = (Gr A f)^-1 O R O Gr A f" - unfolding relImage_def Gr_def relcomp_def by auto - -lemma relInvImage_Gr: "\R \ B \ B\ \ relInvImage A R f = Gr A f O R O (Gr A f)^-1" - unfolding Gr_def relcomp_def image_def relInvImage_def by auto - -lemma relImage_mono: - "R1 \ R2 \ relImage R1 f \ relImage R2 f" - unfolding relImage_def by auto - -lemma relInvImage_mono: - "R1 \ R2 \ relInvImage A R1 f \ relInvImage A R2 f" - unfolding relInvImage_def by auto - -lemma relInvImage_Id_on: - "(\a1 a2. f a1 = f a2 \ a1 = a2) \ relInvImage A (Id_on B) f \ Id" - unfolding relInvImage_def Id_on_def by auto - -lemma relInvImage_UNIV_relImage: - "R \ relInvImage UNIV (relImage R f) f" - unfolding relInvImage_def relImage_def by auto - -lemma relImage_proj: - assumes "equiv A R" - shows "relImage R (proj R) \ Id_on (A//R)" - unfolding relImage_def Id_on_def - using proj_iff[OF assms] equiv_class_eq_iff[OF assms] - by (auto simp: proj_preserves) - -lemma relImage_relInvImage: - assumes "R \ f ` A <*> f ` A" - shows "relImage (relInvImage A R f) f = R" - using assms unfolding relImage_def relInvImage_def by fast - -lemma subst_Pair: "P x y \ a = (x, y) \ P (fst a) (snd a)" - by simp - -lemma fst_diag_id: "(fst \ (%x. (x, x))) z = id z" by simp -lemma snd_diag_id: "(snd \ (%x. (x, x))) z = id z" by simp - -lemma fst_diag_fst: "fst o ((\x. (x, x)) o fst) = fst" by auto -lemma snd_diag_fst: "snd o ((\x. (x, x)) o fst) = fst" by auto -lemma fst_diag_snd: "fst o ((\x. (x, x)) o snd) = snd" by auto -lemma snd_diag_snd: "snd o ((\x. (x, x)) o snd) = snd" by auto - -definition Succ where "Succ Kl kl = {k . kl @ [k] \ Kl}" -definition Shift where "Shift Kl k = {kl. k # kl \ Kl}" -definition shift where "shift lab k = (\kl. lab (k # kl))" - -lemma empty_Shift: "\[] \ Kl; k \ Succ Kl []\ \ [] \ Shift Kl k" - unfolding Shift_def Succ_def by simp - -lemma SuccD: "k \ Succ Kl kl \ kl @ [k] \ Kl" - unfolding Succ_def by simp - -lemmas SuccE = SuccD[elim_format] - -lemma SuccI: "kl @ [k] \ Kl \ k \ Succ Kl kl" - unfolding Succ_def by simp - -lemma ShiftD: "kl \ Shift Kl k \ k # kl \ Kl" - unfolding Shift_def by simp - -lemma Succ_Shift: "Succ (Shift Kl k) kl = Succ Kl (k # kl)" - unfolding Succ_def Shift_def by auto - -lemma length_Cons: "length (x # xs) = Suc (length xs)" - by simp - -lemma length_append_singleton: "length (xs @ [x]) = Suc (length xs)" - by simp - -(*injection into the field of a cardinal*) -definition "toCard_pred A r f \ inj_on f A \ f ` A \ Field r \ Card_order r" -definition "toCard A r \ SOME f. toCard_pred A r f" - -lemma ex_toCard_pred: - "\|A| \o r; Card_order r\ \ \ f. toCard_pred A r f" - unfolding toCard_pred_def - using card_of_ordLeq[of A "Field r"] - ordLeq_ordIso_trans[OF _ card_of_unique[of "Field r" r], of "|A|"] - by blast - -lemma toCard_pred_toCard: - "\|A| \o r; Card_order r\ \ toCard_pred A r (toCard A r)" - unfolding toCard_def using someI_ex[OF ex_toCard_pred] . - -lemma toCard_inj: "\|A| \o r; Card_order r; x \ A; y \ A\ \ toCard A r x = toCard A r y \ x = y" - using toCard_pred_toCard unfolding inj_on_def toCard_pred_def by blast - -definition "fromCard A r k \ SOME b. b \ A \ toCard A r b = k" - -lemma fromCard_toCard: - "\|A| \o r; Card_order r; b \ A\ \ fromCard A r (toCard A r b) = b" - unfolding fromCard_def by (rule some_equality) (auto simp add: toCard_inj) - -lemma Inl_Field_csum: "a \ Field r \ Inl a \ Field (r +c s)" - unfolding Field_card_of csum_def by auto - -lemma Inr_Field_csum: "a \ Field s \ Inr a \ Field (r +c s)" - unfolding Field_card_of csum_def by auto - -lemma rec_nat_0_imp: "f = rec_nat f1 (%n rec. f2 n rec) \ f 0 = f1" - by auto - -lemma rec_nat_Suc_imp: "f = rec_nat f1 (%n rec. f2 n rec) \ f (Suc n) = f2 n (f n)" - by auto - -lemma rec_list_Nil_imp: "f = rec_list f1 (%x xs rec. f2 x xs rec) \ f [] = f1" - by auto - -lemma rec_list_Cons_imp: "f = rec_list f1 (%x xs rec. f2 x xs rec) \ f (x # xs) = f2 x xs (f xs)" - by auto - -lemma not_arg_cong_Inr: "x \ y \ Inr x \ Inr y" - by simp - -definition image2p where - "image2p f g R = (\x y. \x' y'. R x' y' \ f x' = x \ g y' = y)" - -lemma image2pI: "R x y \ image2p f g R (f x) (g y)" - unfolding image2p_def by blast - -lemma image2pE: "\image2p f g R fx gy; (\x y. fx = f x \ gy = g y \ R x y \ P)\ \ P" - unfolding image2p_def by blast - -lemma rel_fun_iff_geq_image2p: "rel_fun R S f g = (image2p f g R \ S)" - unfolding rel_fun_def image2p_def by auto - -lemma rel_fun_image2p: "rel_fun R (image2p f g R) f g" - unfolding rel_fun_def image2p_def by auto - - -subsection {* Equivalence relations, quotients, and Hilbert's choice *} - -lemma equiv_Eps_in: -"\equiv A r; X \ A//r\ \ Eps (%x. x \ X) \ X" - apply (rule someI2_ex) - using in_quotient_imp_non_empty by blast - -lemma equiv_Eps_preserves: - assumes ECH: "equiv A r" and X: "X \ A//r" - shows "Eps (%x. x \ X) \ A" - apply (rule in_mono[rule_format]) - using assms apply (rule in_quotient_imp_subset) - by (rule equiv_Eps_in) (rule assms)+ - -lemma proj_Eps: - assumes "equiv A r" and "X \ A//r" - shows "proj r (Eps (%x. x \ X)) = X" -unfolding proj_def -proof auto - fix x assume x: "x \ X" - thus "(Eps (%x. x \ X), x) \ r" using assms equiv_Eps_in in_quotient_imp_in_rel by fast -next - fix x assume "(Eps (%x. x \ X),x) \ r" - thus "x \ X" using in_quotient_imp_closed[OF assms equiv_Eps_in[OF assms]] by fast -qed - -definition univ where "univ f X == f (Eps (%x. x \ X))" - -lemma univ_commute: -assumes ECH: "equiv A r" and RES: "f respects r" and x: "x \ A" -shows "(univ f) (proj r x) = f x" -proof (unfold univ_def) - have prj: "proj r x \ A//r" using x proj_preserves by fast - hence "Eps (%y. y \ proj r x) \ A" using ECH equiv_Eps_preserves by fast - moreover have "proj r (Eps (%y. y \ proj r x)) = proj r x" using ECH prj proj_Eps by fast - ultimately have "(x, Eps (%y. y \ proj r x)) \ r" using x ECH proj_iff by fast - thus "f (Eps (%y. y \ proj r x)) = f x" using RES unfolding congruent_def by fastforce -qed - -lemma univ_preserves: - assumes ECH: "equiv A r" and RES: "f respects r" and PRES: "\x \ A. f x \ B" - shows "\X \ A//r. univ f X \ B" -proof - fix X assume "X \ A//r" - then obtain x where x: "x \ A" and X: "X = proj r x" using ECH proj_image[of r A] by blast - hence "univ f X = f x" using ECH RES univ_commute by fastforce - thus "univ f X \ B" using x PRES by simp -qed - -ML_file "Tools/BNF/bnf_gfp_util.ML" -ML_file "Tools/BNF/bnf_gfp_tactics.ML" -ML_file "Tools/BNF/bnf_gfp.ML" -ML_file "Tools/BNF/bnf_gfp_rec_sugar_tactics.ML" -ML_file "Tools/BNF/bnf_gfp_rec_sugar.ML" - -end diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/BNF_Greatest_Fixpoint.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/BNF_Greatest_Fixpoint.thy Mon Sep 01 16:34:40 2014 +0200 @@ -0,0 +1,300 @@ +(* Title: HOL/BNF_Greatest_Fixpoint.thy + Author: Dmitriy Traytel, TU Muenchen + Author: Lorenz Panny, TU Muenchen + Author: Jasmin Blanchette, TU Muenchen + Copyright 2012, 2013, 2014 + +Greatest fixed point operation on bounded natural functors. +*) + +header {* Greatest Fixed Point Operation on Bounded Natural Functors *} + +theory BNF_Greatest_Fixpoint +imports BNF_Fixpoint_Base String +keywords + "codatatype" :: thy_decl and + "primcorecursive" :: thy_goal and + "primcorec" :: thy_decl +begin + +setup {* +Sign.const_alias @{binding proj} @{const_name Equiv_Relations.proj} +*} + +lemma one_pointE: "\\x. s = x \ P\ \ P" + by simp + +lemma obj_sumE: "\\x. s = Inl x \ P; \x. s = Inr x \ P\ \ P" + by (cases s) auto + +lemma not_TrueE: "\ True \ P" + by (erule notE, rule TrueI) + +lemma neq_eq_eq_contradict: "\t \ u; s = t; s = u\ \ P" + by fast + +lemma case_sum_expand_Inr: "f o Inl = g \ f x = case_sum g (f o Inr) x" + by (auto split: sum.splits) + +lemma case_sum_expand_Inr': "f o Inl = g \ h = f o Inr \ case_sum g h = f" + apply rule + apply (rule ext, force split: sum.split) + by (rule ext, metis case_sum_o_inj(2)) + +lemma converse_Times: "(A \ B) ^-1 = B \ A" + by fast + +lemma equiv_proj: + assumes e: "equiv A R" and m: "z \ R" + shows "(proj R o fst) z = (proj R o snd) z" +proof - + from m have z: "(fst z, snd z) \ R" by auto + with e have "\x. (fst z, x) \ R \ (snd z, x) \ R" "\x. (snd z, x) \ R \ (fst z, x) \ R" + unfolding equiv_def sym_def trans_def by blast+ + then show ?thesis unfolding proj_def[abs_def] by auto +qed + +(* Operators: *) +definition image2 where "image2 A f g = {(f a, g a) | a. a \ A}" + +lemma Id_on_Gr: "Id_on A = Gr A id" + unfolding Id_on_def Gr_def by auto + +lemma image2_eqI: "\b = f x; c = g x; x \ A\ \ (b, c) \ image2 A f g" + unfolding image2_def by auto + +lemma IdD: "(a, b) \ Id \ a = b" + by auto + +lemma image2_Gr: "image2 A f g = (Gr A f)^-1 O (Gr A g)" + unfolding image2_def Gr_def by auto + +lemma GrD1: "(x, fx) \ Gr A f \ x \ A" + unfolding Gr_def by simp + +lemma GrD2: "(x, fx) \ Gr A f \ f x = fx" + unfolding Gr_def by simp + +lemma Gr_incl: "Gr A f \ A <*> B \ f ` A \ B" + unfolding Gr_def by auto + +lemma subset_Collect_iff: "B \ A \ (B \ {x \ A. P x}) = (\x \ B. P x)" + by blast + +lemma subset_CollectI: "B \ A \ (\x. x \ B \ Q x \ P x) \ ({x \ B. Q x} \ {x \ A. P x})" + by blast + +lemma in_rel_Collect_split_eq: "in_rel (Collect (split X)) = X" + unfolding fun_eq_iff by auto + +lemma Collect_split_in_rel_leI: "X \ Y \ X \ Collect (split (in_rel Y))" + by auto + +lemma Collect_split_in_rel_leE: "X \ Collect (split (in_rel Y)) \ (X \ Y \ R) \ R" + by force + +lemma conversep_in_rel: "(in_rel R)\\ = in_rel (R\)" + unfolding fun_eq_iff by auto + +lemma relcompp_in_rel: "in_rel R OO in_rel S = in_rel (R O S)" + unfolding fun_eq_iff by auto + +lemma in_rel_Gr: "in_rel (Gr A f) = Grp A f" + unfolding Gr_def Grp_def fun_eq_iff by auto + +definition relImage where + "relImage R f \ {(f a1, f a2) | a1 a2. (a1,a2) \ R}" + +definition relInvImage where + "relInvImage A R f \ {(a1, a2) | a1 a2. a1 \ A \ a2 \ A \ (f a1, f a2) \ R}" + +lemma relImage_Gr: + "\R \ A \ A\ \ relImage R f = (Gr A f)^-1 O R O Gr A f" + unfolding relImage_def Gr_def relcomp_def by auto + +lemma relInvImage_Gr: "\R \ B \ B\ \ relInvImage A R f = Gr A f O R O (Gr A f)^-1" + unfolding Gr_def relcomp_def image_def relInvImage_def by auto + +lemma relImage_mono: + "R1 \ R2 \ relImage R1 f \ relImage R2 f" + unfolding relImage_def by auto + +lemma relInvImage_mono: + "R1 \ R2 \ relInvImage A R1 f \ relInvImage A R2 f" + unfolding relInvImage_def by auto + +lemma relInvImage_Id_on: + "(\a1 a2. f a1 = f a2 \ a1 = a2) \ relInvImage A (Id_on B) f \ Id" + unfolding relInvImage_def Id_on_def by auto + +lemma relInvImage_UNIV_relImage: + "R \ relInvImage UNIV (relImage R f) f" + unfolding relInvImage_def relImage_def by auto + +lemma relImage_proj: + assumes "equiv A R" + shows "relImage R (proj R) \ Id_on (A//R)" + unfolding relImage_def Id_on_def + using proj_iff[OF assms] equiv_class_eq_iff[OF assms] + by (auto simp: proj_preserves) + +lemma relImage_relInvImage: + assumes "R \ f ` A <*> f ` A" + shows "relImage (relInvImage A R f) f = R" + using assms unfolding relImage_def relInvImage_def by fast + +lemma subst_Pair: "P x y \ a = (x, y) \ P (fst a) (snd a)" + by simp + +lemma fst_diag_id: "(fst \ (%x. (x, x))) z = id z" by simp +lemma snd_diag_id: "(snd \ (%x. (x, x))) z = id z" by simp + +lemma fst_diag_fst: "fst o ((\x. (x, x)) o fst) = fst" by auto +lemma snd_diag_fst: "snd o ((\x. (x, x)) o fst) = fst" by auto +lemma fst_diag_snd: "fst o ((\x. (x, x)) o snd) = snd" by auto +lemma snd_diag_snd: "snd o ((\x. (x, x)) o snd) = snd" by auto + +definition Succ where "Succ Kl kl = {k . kl @ [k] \ Kl}" +definition Shift where "Shift Kl k = {kl. k # kl \ Kl}" +definition shift where "shift lab k = (\kl. lab (k # kl))" + +lemma empty_Shift: "\[] \ Kl; k \ Succ Kl []\ \ [] \ Shift Kl k" + unfolding Shift_def Succ_def by simp + +lemma SuccD: "k \ Succ Kl kl \ kl @ [k] \ Kl" + unfolding Succ_def by simp + +lemmas SuccE = SuccD[elim_format] + +lemma SuccI: "kl @ [k] \ Kl \ k \ Succ Kl kl" + unfolding Succ_def by simp + +lemma ShiftD: "kl \ Shift Kl k \ k # kl \ Kl" + unfolding Shift_def by simp + +lemma Succ_Shift: "Succ (Shift Kl k) kl = Succ Kl (k # kl)" + unfolding Succ_def Shift_def by auto + +lemma length_Cons: "length (x # xs) = Suc (length xs)" + by simp + +lemma length_append_singleton: "length (xs @ [x]) = Suc (length xs)" + by simp + +(*injection into the field of a cardinal*) +definition "toCard_pred A r f \ inj_on f A \ f ` A \ Field r \ Card_order r" +definition "toCard A r \ SOME f. toCard_pred A r f" + +lemma ex_toCard_pred: + "\|A| \o r; Card_order r\ \ \ f. toCard_pred A r f" + unfolding toCard_pred_def + using card_of_ordLeq[of A "Field r"] + ordLeq_ordIso_trans[OF _ card_of_unique[of "Field r" r], of "|A|"] + by blast + +lemma toCard_pred_toCard: + "\|A| \o r; Card_order r\ \ toCard_pred A r (toCard A r)" + unfolding toCard_def using someI_ex[OF ex_toCard_pred] . + +lemma toCard_inj: "\|A| \o r; Card_order r; x \ A; y \ A\ \ toCard A r x = toCard A r y \ x = y" + using toCard_pred_toCard unfolding inj_on_def toCard_pred_def by blast + +definition "fromCard A r k \ SOME b. b \ A \ toCard A r b = k" + +lemma fromCard_toCard: + "\|A| \o r; Card_order r; b \ A\ \ fromCard A r (toCard A r b) = b" + unfolding fromCard_def by (rule some_equality) (auto simp add: toCard_inj) + +lemma Inl_Field_csum: "a \ Field r \ Inl a \ Field (r +c s)" + unfolding Field_card_of csum_def by auto + +lemma Inr_Field_csum: "a \ Field s \ Inr a \ Field (r +c s)" + unfolding Field_card_of csum_def by auto + +lemma rec_nat_0_imp: "f = rec_nat f1 (%n rec. f2 n rec) \ f 0 = f1" + by auto + +lemma rec_nat_Suc_imp: "f = rec_nat f1 (%n rec. f2 n rec) \ f (Suc n) = f2 n (f n)" + by auto + +lemma rec_list_Nil_imp: "f = rec_list f1 (%x xs rec. f2 x xs rec) \ f [] = f1" + by auto + +lemma rec_list_Cons_imp: "f = rec_list f1 (%x xs rec. f2 x xs rec) \ f (x # xs) = f2 x xs (f xs)" + by auto + +lemma not_arg_cong_Inr: "x \ y \ Inr x \ Inr y" + by simp + +definition image2p where + "image2p f g R = (\x y. \x' y'. R x' y' \ f x' = x \ g y' = y)" + +lemma image2pI: "R x y \ image2p f g R (f x) (g y)" + unfolding image2p_def by blast + +lemma image2pE: "\image2p f g R fx gy; (\x y. fx = f x \ gy = g y \ R x y \ P)\ \ P" + unfolding image2p_def by blast + +lemma rel_fun_iff_geq_image2p: "rel_fun R S f g = (image2p f g R \ S)" + unfolding rel_fun_def image2p_def by auto + +lemma rel_fun_image2p: "rel_fun R (image2p f g R) f g" + unfolding rel_fun_def image2p_def by auto + + +subsection {* Equivalence relations, quotients, and Hilbert's choice *} + +lemma equiv_Eps_in: +"\equiv A r; X \ A//r\ \ Eps (%x. x \ X) \ X" + apply (rule someI2_ex) + using in_quotient_imp_non_empty by blast + +lemma equiv_Eps_preserves: + assumes ECH: "equiv A r" and X: "X \ A//r" + shows "Eps (%x. x \ X) \ A" + apply (rule in_mono[rule_format]) + using assms apply (rule in_quotient_imp_subset) + by (rule equiv_Eps_in) (rule assms)+ + +lemma proj_Eps: + assumes "equiv A r" and "X \ A//r" + shows "proj r (Eps (%x. x \ X)) = X" +unfolding proj_def +proof auto + fix x assume x: "x \ X" + thus "(Eps (%x. x \ X), x) \ r" using assms equiv_Eps_in in_quotient_imp_in_rel by fast +next + fix x assume "(Eps (%x. x \ X),x) \ r" + thus "x \ X" using in_quotient_imp_closed[OF assms equiv_Eps_in[OF assms]] by fast +qed + +definition univ where "univ f X == f (Eps (%x. x \ X))" + +lemma univ_commute: +assumes ECH: "equiv A r" and RES: "f respects r" and x: "x \ A" +shows "(univ f) (proj r x) = f x" +proof (unfold univ_def) + have prj: "proj r x \ A//r" using x proj_preserves by fast + hence "Eps (%y. y \ proj r x) \ A" using ECH equiv_Eps_preserves by fast + moreover have "proj r (Eps (%y. y \ proj r x)) = proj r x" using ECH prj proj_Eps by fast + ultimately have "(x, Eps (%y. y \ proj r x)) \ r" using x ECH proj_iff by fast + thus "f (Eps (%y. y \ proj r x)) = f x" using RES unfolding congruent_def by fastforce +qed + +lemma univ_preserves: + assumes ECH: "equiv A r" and RES: "f respects r" and PRES: "\x \ A. f x \ B" + shows "\X \ A//r. univ f X \ B" +proof + fix X assume "X \ A//r" + then obtain x where x: "x \ A" and X: "X = proj r x" using ECH proj_image[of r A] by blast + hence "univ f X = f x" using ECH RES univ_commute by fastforce + thus "univ f X \ B" using x PRES by simp +qed + +ML_file "Tools/BNF/bnf_gfp_util.ML" +ML_file "Tools/BNF/bnf_gfp_tactics.ML" +ML_file "Tools/BNF/bnf_gfp.ML" +ML_file "Tools/BNF/bnf_gfp_rec_sugar_tactics.ML" +ML_file "Tools/BNF/bnf_gfp_rec_sugar.ML" + +end diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/BNF_LFP.thy --- a/src/HOL/BNF_LFP.thy Mon Sep 01 16:34:39 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,198 +0,0 @@ -(* Title: HOL/BNF_LFP.thy - Author: Dmitriy Traytel, TU Muenchen - Author: Lorenz Panny, TU Muenchen - Author: Jasmin Blanchette, TU Muenchen - Copyright 2012, 2013, 2014 - -Least fixed point operation on bounded natural functors. -*) - -header {* Least Fixed Point Operation on Bounded Natural Functors *} - -theory BNF_LFP -imports BNF_FP_Base -keywords - "datatype_new" :: thy_decl and - "datatype_compat" :: thy_decl -begin - -lemma subset_emptyI: "(\x. x \ A \ False) \ A \ {}" - by blast - -lemma image_Collect_subsetI: "(\x. P x \ f x \ B) \ f ` {x. P x} \ B" - by blast - -lemma Collect_restrict: "{x. x \ X \ P x} \ X" - by auto - -lemma prop_restrict: "\x \ Z; Z \ {x. x \ X \ P x}\ \ P x" - by auto - -lemma underS_I: "\i \ j; (i, j) \ R\ \ i \ underS R j" - unfolding underS_def by simp - -lemma underS_E: "i \ underS R j \ i \ j \ (i, j) \ R" - unfolding underS_def by simp - -lemma underS_Field: "i \ underS R j \ i \ Field R" - unfolding underS_def Field_def by auto - -lemma FieldI2: "(i, j) \ R \ j \ Field R" - unfolding Field_def by auto - -lemma fst_convol': "fst (\f, g\ x) = f x" - using fst_convol unfolding convol_def by simp - -lemma snd_convol': "snd (\f, g\ x) = g x" - using snd_convol unfolding convol_def by simp - -lemma convol_expand_snd: "fst o f = g \ \g, snd o f\ = f" - unfolding convol_def by auto - -lemma convol_expand_snd': - assumes "(fst o f = g)" - shows "h = snd o f \ \g, h\ = f" -proof - - from assms have *: "\g, snd o f\ = f" by (rule convol_expand_snd) - then have "h = snd o f \ h = snd o \g, snd o f\" by simp - moreover have "\ \ h = snd o f" by (simp add: snd_convol) - moreover have "\ \ \g, h\ = f" by (subst (2) *[symmetric]) (auto simp: convol_def fun_eq_iff) - ultimately show ?thesis by simp -qed - -lemma bij_betwE: "bij_betw f A B \ \a\A. f a \ B" - unfolding bij_betw_def by auto - -lemma bij_betw_imageE: "bij_betw f A B \ f ` A = B" - unfolding bij_betw_def by auto - -lemma f_the_inv_into_f_bij_betw: "bij_betw f A B \ - (bij_betw f A B \ x \ B) \ f (the_inv_into A f x) = x" - unfolding bij_betw_def by (blast intro: f_the_inv_into_f) - -lemma ex_bij_betw: "|A| \o (r :: 'b rel) \ \f B :: 'b set. bij_betw f B A" - by (subst (asm) internalize_card_of_ordLeq) - (auto dest!: iffD2[OF card_of_ordIso ordIso_symmetric]) - -lemma bij_betwI': - "\\x y. \x \ X; y \ X\ \ (f x = f y) = (x = y); - \x. x \ X \ f x \ Y; - \y. y \ Y \ \x \ X. y = f x\ \ bij_betw f X Y" - unfolding bij_betw_def inj_on_def by blast - -lemma surj_fun_eq: - assumes surj_on: "f ` X = UNIV" and eq_on: "\x \ X. (g1 o f) x = (g2 o f) x" - shows "g1 = g2" -proof (rule ext) - fix y - from surj_on obtain x where "x \ X" and "y = f x" by blast - thus "g1 y = g2 y" using eq_on by simp -qed - -lemma Card_order_wo_rel: "Card_order r \ wo_rel r" -unfolding wo_rel_def card_order_on_def by blast - -lemma Cinfinite_limit: "\x \ Field r; Cinfinite r\ \ - \y \ Field r. x \ y \ (x, y) \ r" -unfolding cinfinite_def by (auto simp add: infinite_Card_order_limit) - -lemma Card_order_trans: - "\Card_order r; x \ y; (x, y) \ r; y \ z; (y, z) \ r\ \ x \ z \ (x, z) \ r" -unfolding card_order_on_def well_order_on_def linear_order_on_def - partial_order_on_def preorder_on_def trans_def antisym_def by blast - -lemma Cinfinite_limit2: - assumes x1: "x1 \ Field r" and x2: "x2 \ Field r" and r: "Cinfinite r" - shows "\y \ Field r. (x1 \ y \ (x1, y) \ r) \ (x2 \ y \ (x2, y) \ r)" -proof - - from r have trans: "trans r" and total: "Total r" and antisym: "antisym r" - unfolding card_order_on_def well_order_on_def linear_order_on_def - partial_order_on_def preorder_on_def by auto - obtain y1 where y1: "y1 \ Field r" "x1 \ y1" "(x1, y1) \ r" - using Cinfinite_limit[OF x1 r] by blast - obtain y2 where y2: "y2 \ Field r" "x2 \ y2" "(x2, y2) \ r" - using Cinfinite_limit[OF x2 r] by blast - show ?thesis - proof (cases "y1 = y2") - case True with y1 y2 show ?thesis by blast - next - case False - with y1(1) y2(1) total have "(y1, y2) \ r \ (y2, y1) \ r" - unfolding total_on_def by auto - thus ?thesis - proof - assume *: "(y1, y2) \ r" - with trans y1(3) have "(x1, y2) \ r" unfolding trans_def by blast - with False y1 y2 * antisym show ?thesis by (cases "x1 = y2") (auto simp: antisym_def) - next - assume *: "(y2, y1) \ r" - with trans y2(3) have "(x2, y1) \ r" unfolding trans_def by blast - with False y1 y2 * antisym show ?thesis by (cases "x2 = y1") (auto simp: antisym_def) - qed - qed -qed - -lemma Cinfinite_limit_finite: "\finite X; X \ Field r; Cinfinite r\ - \ \y \ Field r. \x \ X. (x \ y \ (x, y) \ r)" -proof (induct X rule: finite_induct) - case empty thus ?case unfolding cinfinite_def using ex_in_conv[of "Field r"] finite.emptyI by auto -next - case (insert x X) - then obtain y where y: "y \ Field r" "\x \ X. (x \ y \ (x, y) \ r)" by blast - then obtain z where z: "z \ Field r" "x \ z \ (x, z) \ r" "y \ z \ (y, z) \ r" - using Cinfinite_limit2[OF _ y(1) insert(5), of x] insert(4) by blast - show ?case - apply (intro bexI ballI) - apply (erule insertE) - apply hypsubst - apply (rule z(2)) - using Card_order_trans[OF insert(5)[THEN conjunct2]] y(2) z(3) - apply blast - apply (rule z(1)) - done -qed - -lemma insert_subsetI: "\x \ A; X \ A\ \ insert x X \ A" -by auto - -(*helps resolution*) -lemma well_order_induct_imp: - "wo_rel r \ (\x. \y. y \ x \ (y, x) \ r \ y \ Field r \ P y \ x \ Field r \ P x) \ - x \ Field r \ P x" -by (erule wo_rel.well_order_induct) - -lemma meta_spec2: - assumes "(\x y. PROP P x y)" - shows "PROP P x y" -by (rule assms) - -lemma nchotomy_relcomppE: - assumes "\y. \x. y = f x" "(r OO s) a c" "\b. r a (f b) \ s (f b) c \ P" - shows P -proof (rule relcompp.cases[OF assms(2)], hypsubst) - fix b assume "r a b" "s b c" - moreover from assms(1) obtain b' where "b = f b'" by blast - ultimately show P by (blast intro: assms(3)) -qed - -lemma vimage2p_rel_fun: "rel_fun (vimage2p f g R) R f g" - unfolding rel_fun_def vimage2p_def by auto - -lemma predicate2D_vimage2p: "\R \ vimage2p f g S; R x y\ \ S (f x) (g y)" - unfolding vimage2p_def by auto - -lemma id_transfer: "rel_fun A A id id" - unfolding rel_fun_def by simp - -lemma ssubst_Pair_rhs: "\(r, s) \ R; s' = s\ \ (r, s') \ R" - by (rule ssubst) - -ML_file "Tools/BNF/bnf_lfp_util.ML" -ML_file "Tools/BNF/bnf_lfp_tactics.ML" -ML_file "Tools/BNF/bnf_lfp.ML" -ML_file "Tools/BNF/bnf_lfp_compat.ML" -ML_file "Tools/BNF/bnf_lfp_rec_sugar_more.ML" - -hide_fact (open) id_transfer - -end diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/BNF_Least_Fixpoint.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/BNF_Least_Fixpoint.thy Mon Sep 01 16:34:40 2014 +0200 @@ -0,0 +1,198 @@ +(* Title: HOL/BNF_Least_Fixpoint.thy + Author: Dmitriy Traytel, TU Muenchen + Author: Lorenz Panny, TU Muenchen + Author: Jasmin Blanchette, TU Muenchen + Copyright 2012, 2013, 2014 + +Least fixed point operation on bounded natural functors. +*) + +header {* Least Fixed Point Operation on Bounded Natural Functors *} + +theory BNF_Least_Fixpoint +imports BNF_Fixpoint_Base +keywords + "datatype_new" :: thy_decl and + "datatype_compat" :: thy_decl +begin + +lemma subset_emptyI: "(\x. x \ A \ False) \ A \ {}" + by blast + +lemma image_Collect_subsetI: "(\x. P x \ f x \ B) \ f ` {x. P x} \ B" + by blast + +lemma Collect_restrict: "{x. x \ X \ P x} \ X" + by auto + +lemma prop_restrict: "\x \ Z; Z \ {x. x \ X \ P x}\ \ P x" + by auto + +lemma underS_I: "\i \ j; (i, j) \ R\ \ i \ underS R j" + unfolding underS_def by simp + +lemma underS_E: "i \ underS R j \ i \ j \ (i, j) \ R" + unfolding underS_def by simp + +lemma underS_Field: "i \ underS R j \ i \ Field R" + unfolding underS_def Field_def by auto + +lemma FieldI2: "(i, j) \ R \ j \ Field R" + unfolding Field_def by auto + +lemma fst_convol': "fst (\f, g\ x) = f x" + using fst_convol unfolding convol_def by simp + +lemma snd_convol': "snd (\f, g\ x) = g x" + using snd_convol unfolding convol_def by simp + +lemma convol_expand_snd: "fst o f = g \ \g, snd o f\ = f" + unfolding convol_def by auto + +lemma convol_expand_snd': + assumes "(fst o f = g)" + shows "h = snd o f \ \g, h\ = f" +proof - + from assms have *: "\g, snd o f\ = f" by (rule convol_expand_snd) + then have "h = snd o f \ h = snd o \g, snd o f\" by simp + moreover have "\ \ h = snd o f" by (simp add: snd_convol) + moreover have "\ \ \g, h\ = f" by (subst (2) *[symmetric]) (auto simp: convol_def fun_eq_iff) + ultimately show ?thesis by simp +qed + +lemma bij_betwE: "bij_betw f A B \ \a\A. f a \ B" + unfolding bij_betw_def by auto + +lemma bij_betw_imageE: "bij_betw f A B \ f ` A = B" + unfolding bij_betw_def by auto + +lemma f_the_inv_into_f_bij_betw: "bij_betw f A B \ + (bij_betw f A B \ x \ B) \ f (the_inv_into A f x) = x" + unfolding bij_betw_def by (blast intro: f_the_inv_into_f) + +lemma ex_bij_betw: "|A| \o (r :: 'b rel) \ \f B :: 'b set. bij_betw f B A" + by (subst (asm) internalize_card_of_ordLeq) + (auto dest!: iffD2[OF card_of_ordIso ordIso_symmetric]) + +lemma bij_betwI': + "\\x y. \x \ X; y \ X\ \ (f x = f y) = (x = y); + \x. x \ X \ f x \ Y; + \y. y \ Y \ \x \ X. y = f x\ \ bij_betw f X Y" + unfolding bij_betw_def inj_on_def by blast + +lemma surj_fun_eq: + assumes surj_on: "f ` X = UNIV" and eq_on: "\x \ X. (g1 o f) x = (g2 o f) x" + shows "g1 = g2" +proof (rule ext) + fix y + from surj_on obtain x where "x \ X" and "y = f x" by blast + thus "g1 y = g2 y" using eq_on by simp +qed + +lemma Card_order_wo_rel: "Card_order r \ wo_rel r" +unfolding wo_rel_def card_order_on_def by blast + +lemma Cinfinite_limit: "\x \ Field r; Cinfinite r\ \ + \y \ Field r. x \ y \ (x, y) \ r" +unfolding cinfinite_def by (auto simp add: infinite_Card_order_limit) + +lemma Card_order_trans: + "\Card_order r; x \ y; (x, y) \ r; y \ z; (y, z) \ r\ \ x \ z \ (x, z) \ r" +unfolding card_order_on_def well_order_on_def linear_order_on_def + partial_order_on_def preorder_on_def trans_def antisym_def by blast + +lemma Cinfinite_limit2: + assumes x1: "x1 \ Field r" and x2: "x2 \ Field r" and r: "Cinfinite r" + shows "\y \ Field r. (x1 \ y \ (x1, y) \ r) \ (x2 \ y \ (x2, y) \ r)" +proof - + from r have trans: "trans r" and total: "Total r" and antisym: "antisym r" + unfolding card_order_on_def well_order_on_def linear_order_on_def + partial_order_on_def preorder_on_def by auto + obtain y1 where y1: "y1 \ Field r" "x1 \ y1" "(x1, y1) \ r" + using Cinfinite_limit[OF x1 r] by blast + obtain y2 where y2: "y2 \ Field r" "x2 \ y2" "(x2, y2) \ r" + using Cinfinite_limit[OF x2 r] by blast + show ?thesis + proof (cases "y1 = y2") + case True with y1 y2 show ?thesis by blast + next + case False + with y1(1) y2(1) total have "(y1, y2) \ r \ (y2, y1) \ r" + unfolding total_on_def by auto + thus ?thesis + proof + assume *: "(y1, y2) \ r" + with trans y1(3) have "(x1, y2) \ r" unfolding trans_def by blast + with False y1 y2 * antisym show ?thesis by (cases "x1 = y2") (auto simp: antisym_def) + next + assume *: "(y2, y1) \ r" + with trans y2(3) have "(x2, y1) \ r" unfolding trans_def by blast + with False y1 y2 * antisym show ?thesis by (cases "x2 = y1") (auto simp: antisym_def) + qed + qed +qed + +lemma Cinfinite_limit_finite: "\finite X; X \ Field r; Cinfinite r\ + \ \y \ Field r. \x \ X. (x \ y \ (x, y) \ r)" +proof (induct X rule: finite_induct) + case empty thus ?case unfolding cinfinite_def using ex_in_conv[of "Field r"] finite.emptyI by auto +next + case (insert x X) + then obtain y where y: "y \ Field r" "\x \ X. (x \ y \ (x, y) \ r)" by blast + then obtain z where z: "z \ Field r" "x \ z \ (x, z) \ r" "y \ z \ (y, z) \ r" + using Cinfinite_limit2[OF _ y(1) insert(5), of x] insert(4) by blast + show ?case + apply (intro bexI ballI) + apply (erule insertE) + apply hypsubst + apply (rule z(2)) + using Card_order_trans[OF insert(5)[THEN conjunct2]] y(2) z(3) + apply blast + apply (rule z(1)) + done +qed + +lemma insert_subsetI: "\x \ A; X \ A\ \ insert x X \ A" +by auto + +(*helps resolution*) +lemma well_order_induct_imp: + "wo_rel r \ (\x. \y. y \ x \ (y, x) \ r \ y \ Field r \ P y \ x \ Field r \ P x) \ + x \ Field r \ P x" +by (erule wo_rel.well_order_induct) + +lemma meta_spec2: + assumes "(\x y. PROP P x y)" + shows "PROP P x y" +by (rule assms) + +lemma nchotomy_relcomppE: + assumes "\y. \x. y = f x" "(r OO s) a c" "\b. r a (f b) \ s (f b) c \ P" + shows P +proof (rule relcompp.cases[OF assms(2)], hypsubst) + fix b assume "r a b" "s b c" + moreover from assms(1) obtain b' where "b = f b'" by blast + ultimately show P by (blast intro: assms(3)) +qed + +lemma vimage2p_rel_fun: "rel_fun (vimage2p f g R) R f g" + unfolding rel_fun_def vimage2p_def by auto + +lemma predicate2D_vimage2p: "\R \ vimage2p f g S; R x y\ \ S (f x) (g y)" + unfolding vimage2p_def by auto + +lemma id_transfer: "rel_fun A A id id" + unfolding rel_fun_def by simp + +lemma ssubst_Pair_rhs: "\(r, s) \ R; s' = s\ \ (r, s') \ R" + by (rule ssubst) + +ML_file "Tools/BNF/bnf_lfp_util.ML" +ML_file "Tools/BNF/bnf_lfp_tactics.ML" +ML_file "Tools/BNF/bnf_lfp.ML" +ML_file "Tools/BNF/bnf_lfp_compat.ML" +ML_file "Tools/BNF/bnf_lfp_rec_sugar_more.ML" + +hide_fact (open) id_transfer + +end diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/Main.thy --- a/src/HOL/Main.thy Mon Sep 01 16:34:39 2014 +0200 +++ b/src/HOL/Main.thy Mon Sep 01 16:34:40 2014 +0200 @@ -1,7 +1,8 @@ header {* Main HOL *} theory Main -imports Predicate_Compile Quickcheck_Narrowing Extraction Lifting_Sum Coinduction Nitpick BNF_GFP +imports Predicate_Compile Quickcheck_Narrowing Extraction Lifting_Sum Coinduction Nitpick + BNF_Greatest_Fixpoint begin text {* diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/Num.thy --- a/src/HOL/Num.thy Mon Sep 01 16:34:39 2014 +0200 +++ b/src/HOL/Num.thy Mon Sep 01 16:34:40 2014 +0200 @@ -6,7 +6,7 @@ header {* Binary Numerals *} theory Num -imports Old_Datatype BNF_LFP +imports BNF_Least_Fixpoint Old_Datatype begin subsection {* The @{text num} type *} diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/Option.thy --- a/src/HOL/Option.thy Mon Sep 01 16:34:39 2014 +0200 +++ b/src/HOL/Option.thy Mon Sep 01 16:34:40 2014 +0200 @@ -5,7 +5,7 @@ header {* Datatype option *} theory Option -imports BNF_LFP Old_Datatype Finite_Set +imports BNF_Least_Fixpoint Old_Datatype Finite_Set begin datatype_new 'a option = diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/Tools/BNF/bnf_comp.ML --- a/src/HOL/Tools/BNF/bnf_comp.ML Mon Sep 01 16:34:39 2014 +0200 +++ b/src/HOL/Tools/BNF/bnf_comp.ML Mon Sep 01 16:34:40 2014 +0200 @@ -54,8 +54,8 @@ open BNF_Tactics open BNF_Comp_Tactics -val ID_bnf = the (bnf_of @{context} "BNF_Comp.ID"); -val DEADID_bnf = the (bnf_of @{context} "BNF_Comp.DEADID"); +val ID_bnf = the (bnf_of @{context} "BNF_Composition.ID"); +val DEADID_bnf = the (bnf_of @{context} "BNF_Composition.DEADID"); type comp_cache = (bnf * (typ list * typ list)) Typtab.table; diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/Tools/BNF/bnf_fp_def_sugar_tactics.ML --- a/src/HOL/Tools/BNF/bnf_fp_def_sugar_tactics.ML Mon Sep 01 16:34:39 2014 +0200 +++ b/src/HOL/Tools/BNF/bnf_fp_def_sugar_tactics.ML Mon Sep 01 16:34:40 2014 +0200 @@ -289,9 +289,9 @@ REPEAT_DETERM o etac conjE))) 1 THEN unfold_thms_tac ctxt ((discs RL [eqTrueI, eqFalseI]) @ sels @ simp_thms') THEN unfold_thms_tac ctxt (dtor_ctor :: rel_pre_def :: abs_inverse :: ctor_inject :: - abs_inject :: ctor_defs @ nesting_rel_eqs @ simp_thms' @ @{thms BNF_Comp.id_bnf_comp_def - rel_sum_simps rel_prod_apply vimage2p_def Inl_Inr_False iffD2[OF eq_False Inr_not_Inl] - sum.inject prod.inject}) THEN + abs_inject :: ctor_defs @ nesting_rel_eqs @ simp_thms' @ + @{thms BNF_Composition.id_bnf_comp_def rel_sum_simps rel_prod_apply vimage2p_def + Inl_Inr_False iffD2[OF eq_False Inr_not_Inl] sum.inject prod.inject}) THEN REPEAT_DETERM (HEADGOAL ((REPEAT_DETERM o etac conjE) THEN' (REPEAT_DETERM o rtac conjI) THEN' (rtac refl ORELSE' atac)))) cts assms exhausts discss selss ctor_defss dtor_ctors ctor_injects abs_injects rel_pre_defs @@ -305,7 +305,7 @@ (rtac (cterm_instantiate_pos (replicate 4 NONE @ [SOME cterm]) @{thm arg_cong2} RS iffD2) THEN' atac THEN' atac THEN' TRY o resolve_tac assms))) THEN unfold_thms_tac ctxt (ctor_inject :: rel_pre_list_def :: ctor_defs @ nesting_rel_eqs @ - @{thms BNF_Comp.id_bnf_comp_def vimage2p_def}) THEN + @{thms BNF_Composition.id_bnf_comp_def vimage2p_def}) THEN TRYALL (hyp_subst_tac ctxt) THEN unfold_thms_tac ctxt (Abs_inverse :: @{thms rel_sum_simps rel_prod_apply Inl_Inr_False Inr_Inl_False sum.inject prod.inject}) THEN @@ -354,7 +354,7 @@ Abs_pre_inverses = let val assms_ctor_defs = - map (unfold_thms ctxt (@{thm BNF_Comp.id_bnf_comp_def} :: ctor_defs)) assms; + map (unfold_thms ctxt (@{thm BNF_Composition.id_bnf_comp_def} :: ctor_defs)) assms; val exhausts' = map (fn thm => thm RS @{thm asm_rl[of "P x y" for P x y]}) exhausts |> map2 (fn ct => cterm_instantiate_pos [NONE, SOME ct]) cts; in @@ -364,7 +364,7 @@ cterm_instantiate_pos (replicate 4 NONE @ [SOME ct]) @{thm arg_cong2} RS iffD2) cts) THEN' atac THEN' hyp_subst_tac ctxt)) THEN unfold_thms_tac ctxt (Abs_pre_inverses @ dtor_ctors @ set_pre_defs @ ctor_defs @ - @{thms BNF_Comp.id_bnf_comp_def o_apply sum_set_simps prod_set_simps UN_empty UN_insert + @{thms BNF_Composition.id_bnf_comp_def o_apply sum_set_simps prod_set_simps UN_empty UN_insert Un_empty_left Un_empty_right empty_iff singleton_iff}) THEN REPEAT_DETERM (HEADGOAL (TRY o etac UnE THEN' TRY o etac @{thm singletonE} THEN' TRY o hyp_subst_tac ctxt THEN' diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/Tools/BNF/bnf_lfp_size.ML --- a/src/HOL/Tools/BNF/bnf_lfp_size.ML Mon Sep 01 16:34:39 2014 +0200 +++ b/src/HOL/Tools/BNF/bnf_lfp_size.ML Mon Sep 01 16:34:40 2014 +0200 @@ -65,7 +65,7 @@ val rec_o_map_simp_thms = @{thms o_def[abs_def] id_def case_prod_app case_sum_map_sum case_prod_map_prod - BNF_Comp.id_bnf_comp_def}; + BNF_Composition.id_bnf_comp_def}; fun mk_rec_o_map_tac ctxt rec_def pre_map_defs live_nesting_map_ident0s abs_inverses ctor_rec_o_map = diff -r b7cab82f488e -r 43a1ba26a8cb src/HOL/Transfer.thy --- a/src/HOL/Transfer.thy Mon Sep 01 16:34:39 2014 +0200 +++ b/src/HOL/Transfer.thy Mon Sep 01 16:34:40 2014 +0200 @@ -6,7 +6,7 @@ header {* Generic theorem transfer using relations *} theory Transfer -imports Hilbert_Choice BNF_FP_Base Metis Option +imports Hilbert_Choice Metis Option begin (* We include Option here although it's not needed here.