# HG changeset patch # User haftmann # Date 1289307733 -3600 # Node ID c6587375088ecfb89d51f8b3e09b413fa2c9b474 # Parent 2989f9f3aa10209de09a30d2b8b4cfbe68c83a7c type annotations in specifications; fun_rel_def is no simp rule by default; slightly changed fun_map_def; more on predicates on relation functions; proper HOL equations in definitions diff -r 2989f9f3aa10 -r c6587375088e src/HOL/Quotient.thy --- a/src/HOL/Quotient.thy Tue Nov 09 14:02:13 2010 +0100 +++ b/src/HOL/Quotient.thy Tue Nov 09 14:02:13 2010 +0100 @@ -5,7 +5,7 @@ header {* Definition of Quotient Types *} theory Quotient -imports Plain Hilbert_Choice +imports Plain Hilbert_Choice Equiv_Relations uses ("Tools/Quotient/quotient_info.ML") ("Tools/Quotient/quotient_typ.ML") @@ -21,33 +21,49 @@ *} definition - "equivp E \ \x y. E x y = (E x = E y)" + "reflp E \ (\x. E x x)" + +lemma refl_reflp: + "refl A \ reflp (\x y. (x, y) \ A)" + by (simp add: refl_on_def reflp_def) definition - "reflp E \ \x. E x x" + "symp E \ (\x y. E x y \ E y x)" + +lemma sym_symp: + "sym A \ symp (\x y. (x, y) \ A)" + by (simp add: sym_def symp_def) definition - "symp E \ \x y. E x y \ E y x" + "transp E \ (\x y z. E x y \ E y z \ E x z)" + +lemma trans_transp: + "trans A \ transp (\x y. (x, y) \ A)" + by (auto simp add: trans_def transp_def) definition - "transp E \ \x y z. E x y \ E y z \ E x z" + "equivp E \ (\x y. E x y = (E x = E y))" lemma equivp_reflp_symp_transp: shows "equivp E = (reflp E \ symp E \ transp E)" unfolding equivp_def reflp_def symp_def transp_def fun_eq_iff by blast +lemma equiv_equivp: + "equiv UNIV A \ equivp (\x y. (x, y) \ A)" + by (simp add: equiv_def equivp_reflp_symp_transp refl_reflp sym_symp trans_transp) + lemma equivp_reflp: shows "equivp E \ E x x" by (simp only: equivp_reflp_symp_transp reflp_def) lemma equivp_symp: shows "equivp E \ E x y \ E y x" - by (metis equivp_reflp_symp_transp symp_def) + by (simp add: equivp_def) lemma equivp_transp: shows "equivp E \ E x y \ E y z \ E x z" - by (metis equivp_reflp_symp_transp transp_def) + by (simp add: equivp_def) lemma equivpI: assumes "reflp R" "symp R" "transp R" @@ -62,7 +78,7 @@ text {* Partial equivalences *} definition - "part_equivp E \ (\x. E x x) \ (\x y. E x y = (E x x \ E y y \ (E x = E y)))" + "part_equivp E \ (\x. E x x) \ (\x y. E x y = (E x x \ E y y \ (E x = E y)))" lemma equivp_implies_part_equivp: assumes a: "equivp E" @@ -114,6 +130,11 @@ then show "part_equivp E" unfolding part_equivp_def using a by metis qed +lemma part_equivpI: + assumes "\x. R x x" "symp R" "transp R" + shows "part_equivp R" + using assms by (simp add: part_equivp_refl_symp_transp) + text {* Composition of Relations *} abbreviation @@ -128,45 +149,54 @@ subsection {* Respects predicate *} definition - Respects + Respects :: "('a \ 'a \ bool) \ 'a set" where - "Respects R x \ R x x" + "Respects R x = R x x" lemma in_respects: - shows "(x \ Respects R) = R x x" + shows "x \ Respects R \ R x x" unfolding mem_def Respects_def by simp subsection {* Function map and function relation *} definition - fun_map (infixr "--->" 55) + fun_map :: "('c \ 'a) \ ('b \ 'd) \ ('a \ 'b) \ 'c \ 'd" (infixr "--->" 55) where -[simp]: "fun_map f g h x = g (h (f x))" + "fun_map f g = (\h. g \ h \ f)" + +lemma fun_map_apply [simp]: + "(f ---> g) h x = g (h (f x))" + by (simp add: fun_map_def) + +lemma fun_map_id: + "(id ---> id) = id" + by (simp add: fun_eq_iff id_def) definition - fun_rel (infixr "===>" 55) + fun_rel :: "('a \ 'a \ bool) \ ('b \ 'b \ bool) \ ('a \ 'b) \ ('a \ 'b) \ bool" (infixr "===>" 55) where -[simp]: "fun_rel E1 E2 f g = (\x y. E1 x y \ E2 (f x) (g y))" + "fun_rel E1 E2 = (\f g. \x y. E1 x y \ E2 (f x) (g y))" lemma fun_relI [intro]: - assumes "\a b. P a b \ Q (x a) (y b)" - shows "(P ===> Q) x y" + assumes "\x y. E1 x y \ E2 (f x) (g y)" + shows "(E1 ===> E2) f g" using assms by (simp add: fun_rel_def) -lemma fun_map_id: - shows "(id ---> id) = id" - by (simp add: fun_eq_iff id_def) +lemma fun_relE: + assumes "(E1 ===> E2) f g" and "E1 x y" + obtains "E2 (f x) (g y)" + using assms by (simp add: fun_rel_def) lemma fun_rel_eq: shows "((op =) ===> (op =)) = (op =)" - by (simp add: fun_eq_iff) + by (auto simp add: fun_eq_iff elim: fun_relE) subsection {* Quotient Predicate *} definition - "Quotient E Abs Rep \ + "Quotient E Abs Rep \ (\a. Abs (Rep a) = a) \ (\a. E (Rep a) (Rep a)) \ (\r s. E r s = (E r r \ E s s \ (Abs r = Abs s)))" @@ -232,21 +262,17 @@ and q2: "Quotient R2 abs2 rep2" shows "Quotient (R1 ===> R2) (rep1 ---> abs2) (abs1 ---> rep2)" proof - - have "\a. (rep1 ---> abs2) ((abs1 ---> rep2) a) = a" - using q1 q2 - unfolding Quotient_def - unfolding fun_eq_iff - by simp + have "\a. (rep1 ---> abs2) ((abs1 ---> rep2) a) = a" + using q1 q2 by (simp add: Quotient_def fun_eq_iff) moreover - have "\a. (R1 ===> R2) ((abs1 ---> rep2) a) ((abs1 ---> rep2) a)" - using q1 q2 - unfolding Quotient_def - by (simp (no_asm)) (metis) + have "\a. (R1 ===> R2) ((abs1 ---> rep2) a) ((abs1 ---> rep2) a)" + by (rule fun_relI) + (insert q1 q2 Quotient_rel_abs [of R1 abs1 rep1] Quotient_rel_rep [of R2 abs2 rep2], + simp (no_asm) add: Quotient_def, simp) moreover - have "\r s. (R1 ===> R2) r s = ((R1 ===> R2) r r \ (R1 ===> R2) s s \ + have "\r s. (R1 ===> R2) r s = ((R1 ===> R2) r r \ (R1 ===> R2) s s \ (rep1 ---> abs2) r = (rep1 ---> abs2) s)" - unfolding fun_eq_iff - apply(auto) + apply(auto simp add: fun_rel_def fun_eq_iff) using q1 q2 unfolding Quotient_def apply(metis) using q1 q2 unfolding Quotient_def @@ -281,7 +307,7 @@ shows "(Rep1 ---> Abs2) (\x. Rep2 (f (Abs1 x))) = (\x. f x)" unfolding fun_eq_iff using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] - by simp + by (simp add:) lemma lambda_prs1: assumes q1: "Quotient R1 Abs1 Rep1" @@ -289,7 +315,7 @@ shows "(Rep1 ---> Abs2) (\x. (Abs1 ---> Rep2) f x) = (\x. f x)" unfolding fun_eq_iff using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] - by simp + by (simp add:) lemma rep_abs_rsp: assumes q: "Quotient R Abs Rep" @@ -317,12 +343,12 @@ assumes q: "Quotient R1 Abs1 Rep1" and a: "(R1 ===> R2) f g" "R1 x y" shows "R2 (f x) (g y)" - using a by simp + using a by (auto elim: fun_relE) lemma apply_rsp': assumes a: "(R1 ===> R2) f g" "R1 x y" shows "R2 (f x) (g y)" - using a by simp + using a by (auto elim: fun_relE) subsection {* lemmas for regularisation of ball and bex *} @@ -370,7 +396,7 @@ apply(rule iffI) apply(rule allI) apply(drule_tac x="\y. f x" in bspec) - apply(simp add: in_respects) + apply(simp add: in_respects fun_rel_def) apply(rule impI) using a equivp_reflp_symp_transp[of "R2"] apply(simp add: reflp_def) @@ -384,7 +410,7 @@ apply(auto) apply(rule_tac x="\y. f x" in bexI) apply(simp) - apply(simp add: Respects_def in_respects) + apply(simp add: Respects_def in_respects fun_rel_def) apply(rule impI) using a equivp_reflp_symp_transp[of "R2"] apply(simp add: reflp_def) @@ -429,7 +455,7 @@ subsection {* Bounded abstraction *} definition - Babs :: "('a \ bool) \ ('a \ 'b) \ 'a \ 'b" + Babs :: "'a set \ ('a \ 'b) \ 'a \ 'b" where "x \ p \ Babs p m x = m x" @@ -437,10 +463,10 @@ assumes q: "Quotient R1 Abs1 Rep1" and a: "(R1 ===> R2) f g" shows "(R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)" - apply (auto simp add: Babs_def in_respects) + apply (auto simp add: Babs_def in_respects fun_rel_def) apply (subgoal_tac "x \ Respects R1 \ y \ Respects R1") - using a apply (simp add: Babs_def) - apply (simp add: in_respects) + using a apply (simp add: Babs_def fun_rel_def) + apply (simp add: in_respects fun_rel_def) using Quotient_rel[OF q] by metis @@ -449,7 +475,7 @@ and q2: "Quotient R2 Abs2 Rep2" shows "((Rep1 ---> Abs2) (Babs (Respects R1) ((Abs1 ---> Rep2) f))) = f" apply (rule ext) - apply (simp) + apply (simp add:) apply (subgoal_tac "Rep1 x \ Respects R1") apply (simp add: Babs_def Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2]) apply (simp add: in_respects Quotient_rel_rep[OF q1]) @@ -460,7 +486,7 @@ shows "((R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)) = ((R1 ===> R2) f g)" apply(rule iffI) apply(simp_all only: babs_rsp[OF q]) - apply(auto simp add: Babs_def) + apply(auto simp add: Babs_def fun_rel_def) apply (subgoal_tac "x \ Respects R1 \ y \ Respects R1") apply(metis Babs_def) apply (simp add: in_respects) @@ -478,30 +504,29 @@ lemma ball_rsp: assumes a: "(R ===> (op =)) f g" shows "Ball (Respects R) f = Ball (Respects R) g" - using a by (simp add: Ball_def in_respects) + using a by (auto simp add: Ball_def in_respects elim: fun_relE) lemma bex_rsp: assumes a: "(R ===> (op =)) f g" shows "(Bex (Respects R) f = Bex (Respects R) g)" - using a by (simp add: Bex_def in_respects) + using a by (auto simp add: Bex_def in_respects elim: fun_relE) lemma bex1_rsp: assumes a: "(R ===> (op =)) f g" shows "Ex1 (\x. x \ Respects R \ f x) = Ex1 (\x. x \ Respects R \ g x)" - using a - by (simp add: Ex1_def in_respects) auto + using a by (auto elim: fun_relE simp add: Ex1_def in_respects) (* 2 lemmas needed for cleaning of quantifiers *) lemma all_prs: assumes a: "Quotient R absf repf" shows "Ball (Respects R) ((absf ---> id) f) = All f" - using a unfolding Quotient_def Ball_def in_respects fun_map_def id_apply + using a unfolding Quotient_def Ball_def in_respects id_apply comp_def fun_map_def by metis lemma ex_prs: assumes a: "Quotient R absf repf" shows "Bex (Respects R) ((absf ---> id) f) = Ex f" - using a unfolding Quotient_def Bex_def in_respects fun_map_def id_apply + using a unfolding Quotient_def Bex_def in_respects id_apply comp_def fun_map_def by metis subsection {* @{text Bex1_rel} quantifier *} @@ -552,7 +577,7 @@ lemma bex1_rel_rsp: assumes a: "Quotient R absf repf" shows "((R ===> op =) ===> op =) (Bex1_rel R) (Bex1_rel R)" - apply simp + apply (simp add: fun_rel_def) apply clarify apply rule apply (simp_all add: bex1_rel_aux bex1_rel_aux2) @@ -564,7 +589,7 @@ lemma ex1_prs: assumes a: "Quotient R absf repf" shows "((absf ---> id) ---> id) (Bex1_rel R) f = Ex1 f" -apply simp +apply (simp add:) apply (subst Bex1_rel_def) apply (subst Bex_def) apply (subst Ex1_def) @@ -643,12 +668,12 @@ shows "((Abs2 ---> Rep3) ---> (Abs1 ---> Rep2) ---> (Rep1 ---> Abs3)) op \ = op \" and "(id ---> (Abs1 ---> id) ---> Rep1 ---> id) op \ = op \" using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] Quotient_abs_rep[OF q3] - unfolding o_def fun_eq_iff by simp_all + by (simp_all add: fun_eq_iff) lemma o_rsp: "((R2 ===> R3) ===> (R1 ===> R2) ===> (R1 ===> R3)) op \ op \" "(op = ===> (R1 ===> op =) ===> R1 ===> op =) op \ op \" - unfolding fun_rel_def o_def fun_eq_iff by auto + by (auto intro!: fun_relI elim: fun_relE) lemma cond_prs: assumes a: "Quotient R absf repf" @@ -664,7 +689,7 @@ lemma if_rsp: assumes q: "Quotient R Abs Rep" shows "(op = ===> R ===> R ===> R) If If" - by auto + by (auto intro!: fun_relI) lemma let_prs: assumes q1: "Quotient R1 Abs1 Rep1" @@ -675,11 +700,11 @@ lemma let_rsp: shows "(R1 ===> (R1 ===> R2) ===> R2) Let Let" - by auto + by (auto intro!: fun_relI elim: fun_relE) lemma mem_rsp: shows "(R1 ===> (R1 ===> R2) ===> R2) op \ op \" - by (simp add: mem_def) + by (auto intro!: fun_relI elim: fun_relE simp add: mem_def) lemma mem_prs: assumes a1: "Quotient R1 Abs1 Rep1" @@ -689,13 +714,12 @@ lemma id_rsp: shows "(R ===> R) id id" - by simp + by (auto intro: fun_relI) lemma id_prs: assumes a: "Quotient R Abs Rep" shows "(Rep ---> Abs) id = id" - unfolding fun_eq_iff - by (simp add: Quotient_abs_rep[OF a]) + by (simp add: fun_eq_iff Quotient_abs_rep [OF a]) locale quot_type = @@ -710,12 +734,12 @@ begin definition - abs::"'a \ 'b" + abs :: "'a \ 'b" where - "abs x \ Abs (R x)" + "abs x = Abs (R x)" definition - rep::"'b \ 'a" + rep :: "'b \ 'a" where "rep a = Eps (Rep a)" @@ -799,7 +823,9 @@ about the lifted theorem in a tactic. *} definition - "Quot_True (x :: 'a) \ True" + Quot_True :: "'a \ bool" +where + "Quot_True x \ True" lemma shows QT_all: "Quot_True (All P) \ Quot_True P" @@ -858,4 +884,3 @@ fun_rel (infixr "===>" 55) end -