src/HOL/Quotient.thy
changeset 71627 2a24c2015a61
parent 71494 cbe0b6b0bed8
child 75455 91c16c5ad3e9
equal deleted inserted replaced
71616:a9de39608b1a 71627:2a24c2015a61
   251 
   251 
   252 lemma ball_reg_eqv_range:
   252 lemma ball_reg_eqv_range:
   253   fixes P::"'a \<Rightarrow> bool"
   253   fixes P::"'a \<Rightarrow> bool"
   254   and x::"'a"
   254   and x::"'a"
   255   assumes a: "equivp R2"
   255   assumes a: "equivp R2"
   256   shows   "(Ball (Respects (R1 ===> R2)) (\<lambda>f. P (f x)) = All (\<lambda>f. P (f x)))"
   256   shows "(Ball (Respects (R1 ===> R2)) (\<lambda>f. P (f x)) = All (\<lambda>f. P (f x)))"
   257   apply(rule iffI)
   257 proof (intro allI iffI)
   258   apply(rule allI)
   258   fix f
   259   apply(drule_tac x="\<lambda>y. f x" in bspec)
   259   assume "\<forall>f \<in> Respects (R1 ===> R2). P (f x)"
   260   apply(simp add: in_respects rel_fun_def)
   260   moreover have "(\<lambda>y. f x) \<in> Respects (R1 ===> R2)"
   261   apply(rule impI)
   261     using a equivp_reflp_symp_transp[of "R2"]
   262   using a equivp_reflp_symp_transp[of "R2"]
   262     by(auto simp add: in_respects rel_fun_def elim: equivpE reflpE)
   263   apply (auto elim: equivpE reflpE)
   263   ultimately show "P (f x)"
   264   done
   264     by auto
       
   265 qed auto
   265 
   266 
   266 lemma bex_reg_eqv_range:
   267 lemma bex_reg_eqv_range:
   267   assumes a: "equivp R2"
   268   assumes a: "equivp R2"
   268   shows   "(Bex (Respects (R1 ===> R2)) (\<lambda>f. P (f x)) = Ex (\<lambda>f. P (f x)))"
   269   shows   "(Bex (Respects (R1 ===> R2)) (\<lambda>f. P (f x)) = Ex (\<lambda>f. P (f x)))"
   269   apply(auto)
   270 proof -
   270   apply(rule_tac x="\<lambda>y. f x" in bexI)
   271   { fix f
   271   apply(simp)
   272     assume "P (f x)"
   272   apply(simp add: Respects_def in_respects rel_fun_def)
   273     have "(\<lambda>y. f x) \<in> Respects (R1 ===> R2)"
   273   apply(rule impI)
   274       using a equivp_reflp_symp_transp[of "R2"]
   274   using a equivp_reflp_symp_transp[of "R2"]
   275       by (auto simp add: Respects_def in_respects rel_fun_def elim: equivpE reflpE) }
   275   apply (auto elim: equivpE reflpE)
   276   then show ?thesis
   276   done
   277     by auto
       
   278 qed
   277 
   279 
   278 (* Next four lemmas are unused *)
   280 (* Next four lemmas are unused *)
   279 lemma all_reg:
   281 lemma all_reg:
   280   assumes a: "\<forall>x :: 'a. (P x \<longrightarrow> Q x)"
   282   assumes a: "\<forall>x :: 'a. (P x \<longrightarrow> Q x)"
   281   and     b: "All P"
   283   and     b: "All P"
   320 
   322 
   321 lemma babs_rsp:
   323 lemma babs_rsp:
   322   assumes q: "Quotient3 R1 Abs1 Rep1"
   324   assumes q: "Quotient3 R1 Abs1 Rep1"
   323   and     a: "(R1 ===> R2) f g"
   325   and     a: "(R1 ===> R2) f g"
   324   shows      "(R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)"
   326   shows      "(R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)"
   325   apply (auto simp add: Babs_def in_respects rel_fun_def)
   327 proof (clarsimp simp add: Babs_def in_respects rel_fun_def)
   326   apply (subgoal_tac "x \<in> Respects R1 \<and> y \<in> Respects R1")
   328   fix x y
   327   using a apply (simp add: Babs_def rel_fun_def)
   329   assume "R1 x y"
   328   apply (simp add: in_respects rel_fun_def)
   330   then have "x \<in> Respects R1 \<and> y \<in> Respects R1"
   329   using Quotient3_rel[OF q]
   331     unfolding in_respects rel_fun_def using Quotient3_rel[OF q]by metis
   330   by metis
   332   then show "R2 (Babs (Respects R1) f x) (Babs (Respects R1) g y)"
       
   333   using \<open>R1 x y\<close> a by (simp add: Babs_def rel_fun_def)
       
   334 qed
   331 
   335 
   332 lemma babs_prs:
   336 lemma babs_prs:
   333   assumes q1: "Quotient3 R1 Abs1 Rep1"
   337   assumes q1: "Quotient3 R1 Abs1 Rep1"
   334   and     q2: "Quotient3 R2 Abs2 Rep2"
   338   and     q2: "Quotient3 R2 Abs2 Rep2"
   335   shows "((Rep1 ---> Abs2) (Babs (Respects R1) ((Abs1 ---> Rep2) f))) = f"
   339 shows "((Rep1 ---> Abs2) (Babs (Respects R1) ((Abs1 ---> Rep2) f))) = f"
   336   apply (rule ext)
   340 proof -
   337   apply (simp add:)
   341   { fix x
   338   apply (subgoal_tac "Rep1 x \<in> Respects R1")
   342     have "Rep1 x \<in> Respects R1"
   339   apply (simp add: Babs_def Quotient3_abs_rep[OF q1] Quotient3_abs_rep[OF q2])
   343       by (simp add: in_respects Quotient3_rel_rep[OF q1])
   340   apply (simp add: in_respects Quotient3_rel_rep[OF q1])
   344     then have "Abs2 (Babs (Respects R1) ((Abs1 ---> Rep2) f) (Rep1 x)) = f x" 
   341   done
   345       by (simp add: Babs_def Quotient3_abs_rep[OF q1] Quotient3_abs_rep[OF q2])
       
   346   }
       
   347   then show ?thesis
       
   348     by force
       
   349 qed
   342 
   350 
   343 lemma babs_simp:
   351 lemma babs_simp:
   344   assumes q: "Quotient3 R1 Abs Rep"
   352   assumes q: "Quotient3 R1 Abs Rep"
   345   shows "((R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)) = ((R1 ===> R2) f g)"
   353   shows "((R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)) = ((R1 ===> R2) f g)"
   346   apply(rule iffI)
   354          (is "?lhs = ?rhs")
   347   apply(simp_all only: babs_rsp[OF q])
   355 proof
   348   apply(auto simp add: Babs_def rel_fun_def)
   356   assume ?lhs
   349   apply(metis Babs_def in_respects  Quotient3_rel[OF q])
   357   then show ?rhs
   350   done
   358     unfolding rel_fun_def by (metis Babs_def in_respects  Quotient3_rel[OF q])
   351 
   359 qed (simp add: babs_rsp[OF q])
   352 (* If a user proves that a particular functional relation
   360 
   353    is an equivalence this may be useful in regularising *)
   361 text \<open>If a user proves that a particular functional relation
       
   362    is an equivalence, this may be useful in regularising\<close>
   354 lemma babs_reg_eqv:
   363 lemma babs_reg_eqv:
   355   shows "equivp R \<Longrightarrow> Babs (Respects R) P = P"
   364   shows "equivp R \<Longrightarrow> Babs (Respects R) P = P"
   356   by (simp add: fun_eq_iff Babs_def in_respects equivp_reflp)
   365   by (simp add: fun_eq_iff Babs_def in_respects equivp_reflp)
   357 
   366 
   358 
   367 
   370 lemma bex1_rsp:
   379 lemma bex1_rsp:
   371   assumes a: "(R ===> (=)) f g"
   380   assumes a: "(R ===> (=)) f g"
   372   shows "Ex1 (\<lambda>x. x \<in> Respects R \<and> f x) = Ex1 (\<lambda>x. x \<in> Respects R \<and> g x)"
   381   shows "Ex1 (\<lambda>x. x \<in> Respects R \<and> f x) = Ex1 (\<lambda>x. x \<in> Respects R \<and> g x)"
   373   using a by (auto elim: rel_funE simp add: Ex1_def in_respects)
   382   using a by (auto elim: rel_funE simp add: Ex1_def in_respects)
   374 
   383 
   375 (* 2 lemmas needed for cleaning of quantifiers *)
   384 text \<open>Two lemmas needed for cleaning of quantifiers\<close>
       
   385 
   376 lemma all_prs:
   386 lemma all_prs:
   377   assumes a: "Quotient3 R absf repf"
   387   assumes a: "Quotient3 R absf repf"
   378   shows "Ball (Respects R) ((absf ---> id) f) = All f"
   388   shows "Ball (Respects R) ((absf ---> id) f) = All f"
   379   using a unfolding Quotient3_def Ball_def in_respects id_apply comp_def map_fun_def
   389   using a unfolding Quotient3_def Ball_def in_respects id_apply comp_def map_fun_def
   380   by metis
   390   by metis
   408   unfolding rel_fun_def by (metis bex1_rel_aux bex1_rel_aux2)
   418   unfolding rel_fun_def by (metis bex1_rel_aux bex1_rel_aux2)
   409 
   419 
   410 lemma ex1_prs:
   420 lemma ex1_prs:
   411   assumes "Quotient3 R absf repf"
   421   assumes "Quotient3 R absf repf"
   412   shows "((absf ---> id) ---> id) (Bex1_rel R) f = Ex1 f"
   422   shows "((absf ---> id) ---> id) (Bex1_rel R) f = Ex1 f"
   413   apply (auto simp: Bex1_rel_def Respects_def)
   423          (is "?lhs = ?rhs")
   414   apply (metis Quotient3_def assms)
   424   using assms
   415   apply (metis (full_types) Quotient3_def assms)
   425   apply (auto simp add: Bex1_rel_def Respects_def)
   416   by (meson Quotient3_rel assms)
   426   by (metis (full_types) Quotient3_def)+
   417 
   427 
   418 lemma bex1_bexeq_reg:
   428 lemma bex1_bexeq_reg:
   419   shows "(\<exists>!x\<in>Respects R. P x) \<longrightarrow> (Bex1_rel R (\<lambda>x. P x))"
   429   shows "(\<exists>!x\<in>Respects R. P x) \<longrightarrow> (Bex1_rel R (\<lambda>x. P x))"
   420   by (auto simp add: Ex1_def Bex1_rel_def Bex_def Ball_def in_respects)
   430   by (auto simp add: Ex1_def Bex1_rel_def Bex_def Ball_def in_respects)
   421 
   431 
   541 
   551 
   542 end
   552 end
   543 
   553 
   544 subsection \<open>Quotient composition\<close>
   554 subsection \<open>Quotient composition\<close>
   545 
   555 
   546 
       
   547 lemma OOO_quotient3:
   556 lemma OOO_quotient3:
   548   fixes R1 :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
   557   fixes R1 :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
   549   fixes Abs1 :: "'a \<Rightarrow> 'b" and Rep1 :: "'b \<Rightarrow> 'a"
   558   fixes Abs1 :: "'a \<Rightarrow> 'b" and Rep1 :: "'b \<Rightarrow> 'a"
   550   fixes Abs2 :: "'b \<Rightarrow> 'c" and Rep2 :: "'c \<Rightarrow> 'b"
   559   fixes Abs2 :: "'b \<Rightarrow> 'c" and Rep2 :: "'c \<Rightarrow> 'b"
   551   fixes R2' :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
   560   fixes R2' :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
   556   assumes Rep1: "\<And>x y. R2 x y \<Longrightarrow> R2' (Rep1 x) (Rep1 y)"
   565   assumes Rep1: "\<And>x y. R2 x y \<Longrightarrow> R2' (Rep1 x) (Rep1 y)"
   557   shows "Quotient3 (R1 OO R2' OO R1) (Abs2 \<circ> Abs1) (Rep1 \<circ> Rep2)"
   566   shows "Quotient3 (R1 OO R2' OO R1) (Abs2 \<circ> Abs1) (Rep1 \<circ> Rep2)"
   558 proof -
   567 proof -
   559   have *: "(R1 OOO R2') r r \<and> (R1 OOO R2') s s \<and> (Abs2 \<circ> Abs1) r = (Abs2 \<circ> Abs1) s
   568   have *: "(R1 OOO R2') r r \<and> (R1 OOO R2') s s \<and> (Abs2 \<circ> Abs1) r = (Abs2 \<circ> Abs1) s
   560            \<longleftrightarrow> (R1 OOO R2') r s" for r s
   569            \<longleftrightarrow> (R1 OOO R2') r s" for r s
   561     apply safe
   570   proof (intro iffI conjI; clarify) 
   562     subgoal for a b c d
   571     show "(R1 OOO R2') r s"
   563       apply simp
   572       if r: "R1 r a" "R2' a b" "R1 b r" and eq: "(Abs2 \<circ> Abs1) r = (Abs2 \<circ> Abs1) s" 
   564       apply (rule_tac b="Rep1 (Abs1 r)" in relcomppI)
   573         and s: "R1 s c" "R2' c d" "R1 d s" for a b c d
   565       using Quotient3_refl1 R1 rep_abs_rsp apply fastforce
   574     proof -
   566       apply (rule_tac b="Rep1 (Abs1 s)" in relcomppI)
   575       have "R1 r (Rep1 (Abs1 r))"
   567        apply (metis (full_types) Rep1 Abs1 Quotient3_rel R2  Quotient3_refl1 [OF R1] Quotient3_refl2 [OF R1] Quotient3_rel_abs [OF R1])
   576         using r Quotient3_refl1 R1 rep_abs_rsp by fastforce
   568       by (metis Quotient3_rel R1 rep_abs_rsp_left)
   577       moreover have "R2' (Rep1 (Abs1 r)) (Rep1 (Abs1 s))"
   569     subgoal for x y
   578         using that
   570       apply (drule Abs1)
   579         apply (simp add: )
   571         apply (erule Quotient3_refl2 [OF R1])
   580         apply (metis (full_types) Rep1 Abs1 Quotient3_rel R2 Quotient3_refl1 [OF R1] Quotient3_refl2 [OF R1] Quotient3_rel_abs [OF R1])
   572        apply (erule Quotient3_refl1 [OF R1])
   581         done
   573       apply (drule Quotient3_refl1 [OF R2], drule Rep1)
   582       moreover have "R1 (Rep1 (Abs1 s)) s"
   574       by (metis (full_types) Quotient3_def R1 relcompp.relcompI)
   583         by (metis s Quotient3_rel R1 rep_abs_rsp_left)
   575     subgoal for x y
   584       ultimately show ?thesis
   576       apply (drule Abs1)
   585         by (metis relcomppI)
   577         apply (erule Quotient3_refl2 [OF R1])
   586     qed
   578        apply (erule Quotient3_refl1 [OF R1])
   587   next
   579       apply (drule Quotient3_refl2 [OF R2], drule Rep1)
   588     fix x y
   580       by (metis (full_types) Quotient3_def R1 relcompp.relcompI)
   589     assume xy: "R1 r x" "R2' x y" "R1 y s"
   581     subgoal for x y
   590     then have "R2 (Abs1 x) (Abs1 y)"
   582       by simp (metis (full_types) Abs1 Quotient3_rel R1 R2)
   591       by (iprover dest: Abs1 elim: Quotient3_refl1 [OF R1] Quotient3_refl2 [OF R1])
   583     done
   592     then have "R2' (Rep1 (Abs1 x)) (Rep1 (Abs1 x))" "R2' (Rep1 (Abs1 y)) (Rep1 (Abs1 y))"
       
   593       by (simp_all add: Quotient3_refl1 [OF R2] Quotient3_refl2 [OF R2] Rep1)
       
   594     with \<open>R1 r x\<close> \<open>R1 y s\<close> show "(R1 OOO R2') r r" "(R1 OOO R2') s s"
       
   595       by (metis (full_types) Quotient3_def R1 relcompp.relcompI)+
       
   596     show "(Abs2 \<circ> Abs1) r = (Abs2 \<circ> Abs1) s"
       
   597       using xy by simp (metis (full_types) Abs1 Quotient3_rel R1 R2)
       
   598   qed
   584   show ?thesis
   599   show ?thesis
   585     apply (rule Quotient3I)
   600     apply (rule Quotient3I)
   586     using * apply (simp_all add: o_def Quotient3_abs_rep [OF R2] Quotient3_abs_rep [OF R1])
   601     using * apply (simp_all add: o_def Quotient3_abs_rep [OF R2] Quotient3_abs_rep [OF R1])
   587     apply (metis Quotient3_rep_reflp R1 R2 Rep1 relcompp.relcompI)
   602     apply (metis Quotient3_rep_reflp R1 R2 Rep1 relcompp.relcompI)
   588     done
   603     done