src/HOL/Quotient.thy
changeset 55945 e96383acecf9
parent 54867 c21a2465cac1
child 56073 29e308b56d23
equal deleted inserted replaced
55944:7ab8f003fe41 55945:e96383acecf9
   144 proof -
   144 proof -
   145   have "\<And>a.(rep1 ---> abs2) ((abs1 ---> rep2) a) = a"
   145   have "\<And>a.(rep1 ---> abs2) ((abs1 ---> rep2) a) = a"
   146     using q1 q2 by (simp add: Quotient3_def fun_eq_iff)
   146     using q1 q2 by (simp add: Quotient3_def fun_eq_iff)
   147   moreover
   147   moreover
   148   have "\<And>a.(R1 ===> R2) ((abs1 ---> rep2) a) ((abs1 ---> rep2) a)"
   148   have "\<And>a.(R1 ===> R2) ((abs1 ---> rep2) a) ((abs1 ---> rep2) a)"
   149     by (rule fun_relI)
   149     by (rule rel_funI)
   150       (insert q1 q2 Quotient3_rel_abs [of R1 abs1 rep1] Quotient3_rel_rep [of R2 abs2 rep2],
   150       (insert q1 q2 Quotient3_rel_abs [of R1 abs1 rep1] Quotient3_rel_rep [of R2 abs2 rep2],
   151         simp (no_asm) add: Quotient3_def, simp)
   151         simp (no_asm) add: Quotient3_def, simp)
   152   
   152   
   153   moreover
   153   moreover
   154   {
   154   {
   155   fix r s
   155   fix r s
   156   have "(R1 ===> R2) r s = ((R1 ===> R2) r r \<and> (R1 ===> R2) s s \<and>
   156   have "(R1 ===> R2) r s = ((R1 ===> R2) r r \<and> (R1 ===> R2) s s \<and>
   157         (rep1 ---> abs2) r  = (rep1 ---> abs2) s)"
   157         (rep1 ---> abs2) r  = (rep1 ---> abs2) s)"
   158   proof -
   158   proof -
   159     
   159     
   160     have "(R1 ===> R2) r s \<Longrightarrow> (R1 ===> R2) r r" unfolding fun_rel_def
   160     have "(R1 ===> R2) r s \<Longrightarrow> (R1 ===> R2) r r" unfolding rel_fun_def
   161       using Quotient3_part_equivp[OF q1] Quotient3_part_equivp[OF q2] 
   161       using Quotient3_part_equivp[OF q1] Quotient3_part_equivp[OF q2] 
   162       by (metis (full_types) part_equivp_def)
   162       by (metis (full_types) part_equivp_def)
   163     moreover have "(R1 ===> R2) r s \<Longrightarrow> (R1 ===> R2) s s" unfolding fun_rel_def
   163     moreover have "(R1 ===> R2) r s \<Longrightarrow> (R1 ===> R2) s s" unfolding rel_fun_def
   164       using Quotient3_part_equivp[OF q1] Quotient3_part_equivp[OF q2] 
   164       using Quotient3_part_equivp[OF q1] Quotient3_part_equivp[OF q2] 
   165       by (metis (full_types) part_equivp_def)
   165       by (metis (full_types) part_equivp_def)
   166     moreover have "(R1 ===> R2) r s \<Longrightarrow> (rep1 ---> abs2) r  = (rep1 ---> abs2) s"
   166     moreover have "(R1 ===> R2) r s \<Longrightarrow> (rep1 ---> abs2) r  = (rep1 ---> abs2) s"
   167       apply(auto simp add: fun_rel_def fun_eq_iff) using q1 q2 unfolding Quotient3_def by metis
   167       apply(auto simp add: rel_fun_def fun_eq_iff) using q1 q2 unfolding Quotient3_def by metis
   168     moreover have "((R1 ===> R2) r r \<and> (R1 ===> R2) s s \<and>
   168     moreover have "((R1 ===> R2) r r \<and> (R1 ===> R2) s s \<and>
   169         (rep1 ---> abs2) r  = (rep1 ---> abs2) s) \<Longrightarrow> (R1 ===> R2) r s"
   169         (rep1 ---> abs2) r  = (rep1 ---> abs2) s) \<Longrightarrow> (R1 ===> R2) r s"
   170       apply(auto simp add: fun_rel_def fun_eq_iff) using q1 q2 unfolding Quotient3_def 
   170       apply(auto simp add: rel_fun_def fun_eq_iff) using q1 q2 unfolding Quotient3_def 
   171     by (metis map_fun_apply)
   171     by (metis map_fun_apply)
   172   
   172   
   173     ultimately show ?thesis by blast
   173     ultimately show ?thesis by blast
   174  qed
   174  qed
   175  }
   175  }
   202 lemma apply_rspQ3:
   202 lemma apply_rspQ3:
   203   fixes f g::"'a \<Rightarrow> 'c"
   203   fixes f g::"'a \<Rightarrow> 'c"
   204   assumes q: "Quotient3 R1 Abs1 Rep1"
   204   assumes q: "Quotient3 R1 Abs1 Rep1"
   205   and     a: "(R1 ===> R2) f g" "R1 x y"
   205   and     a: "(R1 ===> R2) f g" "R1 x y"
   206   shows "R2 (f x) (g y)"
   206   shows "R2 (f x) (g y)"
   207   using a by (auto elim: fun_relE)
   207   using a by (auto elim: rel_funE)
   208 
   208 
   209 lemma apply_rspQ3'':
   209 lemma apply_rspQ3'':
   210   assumes "Quotient3 R Abs Rep"
   210   assumes "Quotient3 R Abs Rep"
   211   and "(R ===> S) f f"
   211   and "(R ===> S) f f"
   212   shows "S (f (Rep x)) (f (Rep x))"
   212   shows "S (f (Rep x)) (f (Rep x))"
   259   assumes a: "equivp R2"
   259   assumes a: "equivp R2"
   260   shows   "(Ball (Respects (R1 ===> R2)) (\<lambda>f. P (f x)) = All (\<lambda>f. P (f x)))"
   260   shows   "(Ball (Respects (R1 ===> R2)) (\<lambda>f. P (f x)) = All (\<lambda>f. P (f x)))"
   261   apply(rule iffI)
   261   apply(rule iffI)
   262   apply(rule allI)
   262   apply(rule allI)
   263   apply(drule_tac x="\<lambda>y. f x" in bspec)
   263   apply(drule_tac x="\<lambda>y. f x" in bspec)
   264   apply(simp add: in_respects fun_rel_def)
   264   apply(simp add: in_respects rel_fun_def)
   265   apply(rule impI)
   265   apply(rule impI)
   266   using a equivp_reflp_symp_transp[of "R2"]
   266   using a equivp_reflp_symp_transp[of "R2"]
   267   apply (auto elim: equivpE reflpE)
   267   apply (auto elim: equivpE reflpE)
   268   done
   268   done
   269 
   269 
   271   assumes a: "equivp R2"
   271   assumes a: "equivp R2"
   272   shows   "(Bex (Respects (R1 ===> R2)) (\<lambda>f. P (f x)) = Ex (\<lambda>f. P (f x)))"
   272   shows   "(Bex (Respects (R1 ===> R2)) (\<lambda>f. P (f x)) = Ex (\<lambda>f. P (f x)))"
   273   apply(auto)
   273   apply(auto)
   274   apply(rule_tac x="\<lambda>y. f x" in bexI)
   274   apply(rule_tac x="\<lambda>y. f x" in bexI)
   275   apply(simp)
   275   apply(simp)
   276   apply(simp add: Respects_def in_respects fun_rel_def)
   276   apply(simp add: Respects_def in_respects rel_fun_def)
   277   apply(rule impI)
   277   apply(rule impI)
   278   using a equivp_reflp_symp_transp[of "R2"]
   278   using a equivp_reflp_symp_transp[of "R2"]
   279   apply (auto elim: equivpE reflpE)
   279   apply (auto elim: equivpE reflpE)
   280   done
   280   done
   281 
   281 
   324 
   324 
   325 lemma babs_rsp:
   325 lemma babs_rsp:
   326   assumes q: "Quotient3 R1 Abs1 Rep1"
   326   assumes q: "Quotient3 R1 Abs1 Rep1"
   327   and     a: "(R1 ===> R2) f g"
   327   and     a: "(R1 ===> R2) f g"
   328   shows      "(R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)"
   328   shows      "(R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)"
   329   apply (auto simp add: Babs_def in_respects fun_rel_def)
   329   apply (auto simp add: Babs_def in_respects rel_fun_def)
   330   apply (subgoal_tac "x \<in> Respects R1 \<and> y \<in> Respects R1")
   330   apply (subgoal_tac "x \<in> Respects R1 \<and> y \<in> Respects R1")
   331   using a apply (simp add: Babs_def fun_rel_def)
   331   using a apply (simp add: Babs_def rel_fun_def)
   332   apply (simp add: in_respects fun_rel_def)
   332   apply (simp add: in_respects rel_fun_def)
   333   using Quotient3_rel[OF q]
   333   using Quotient3_rel[OF q]
   334   by metis
   334   by metis
   335 
   335 
   336 lemma babs_prs:
   336 lemma babs_prs:
   337   assumes q1: "Quotient3 R1 Abs1 Rep1"
   337   assumes q1: "Quotient3 R1 Abs1 Rep1"
   347 lemma babs_simp:
   347 lemma babs_simp:
   348   assumes q: "Quotient3 R1 Abs Rep"
   348   assumes q: "Quotient3 R1 Abs Rep"
   349   shows "((R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)) = ((R1 ===> R2) f g)"
   349   shows "((R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)) = ((R1 ===> R2) f g)"
   350   apply(rule iffI)
   350   apply(rule iffI)
   351   apply(simp_all only: babs_rsp[OF q])
   351   apply(simp_all only: babs_rsp[OF q])
   352   apply(auto simp add: Babs_def fun_rel_def)
   352   apply(auto simp add: Babs_def rel_fun_def)
   353   apply (subgoal_tac "x \<in> Respects R1 \<and> y \<in> Respects R1")
   353   apply (subgoal_tac "x \<in> Respects R1 \<and> y \<in> Respects R1")
   354   apply(metis Babs_def)
   354   apply(metis Babs_def)
   355   apply (simp add: in_respects)
   355   apply (simp add: in_respects)
   356   using Quotient3_rel[OF q]
   356   using Quotient3_rel[OF q]
   357   by metis
   357   by metis
   365 
   365 
   366 (* 3 lemmas needed for proving repabs_inj *)
   366 (* 3 lemmas needed for proving repabs_inj *)
   367 lemma ball_rsp:
   367 lemma ball_rsp:
   368   assumes a: "(R ===> (op =)) f g"
   368   assumes a: "(R ===> (op =)) f g"
   369   shows "Ball (Respects R) f = Ball (Respects R) g"
   369   shows "Ball (Respects R) f = Ball (Respects R) g"
   370   using a by (auto simp add: Ball_def in_respects elim: fun_relE)
   370   using a by (auto simp add: Ball_def in_respects elim: rel_funE)
   371 
   371 
   372 lemma bex_rsp:
   372 lemma bex_rsp:
   373   assumes a: "(R ===> (op =)) f g"
   373   assumes a: "(R ===> (op =)) f g"
   374   shows "(Bex (Respects R) f = Bex (Respects R) g)"
   374   shows "(Bex (Respects R) f = Bex (Respects R) g)"
   375   using a by (auto simp add: Bex_def in_respects elim: fun_relE)
   375   using a by (auto simp add: Bex_def in_respects elim: rel_funE)
   376 
   376 
   377 lemma bex1_rsp:
   377 lemma bex1_rsp:
   378   assumes a: "(R ===> (op =)) f g"
   378   assumes a: "(R ===> (op =)) f g"
   379   shows "Ex1 (\<lambda>x. x \<in> Respects R \<and> f x) = Ex1 (\<lambda>x. x \<in> Respects R \<and> g x)"
   379   shows "Ex1 (\<lambda>x. x \<in> Respects R \<and> f x) = Ex1 (\<lambda>x. x \<in> Respects R \<and> g x)"
   380   using a by (auto elim: fun_relE simp add: Ex1_def in_respects) 
   380   using a by (auto elim: rel_funE simp add: Ex1_def in_respects) 
   381 
   381 
   382 (* 2 lemmas needed for cleaning of quantifiers *)
   382 (* 2 lemmas needed for cleaning of quantifiers *)
   383 lemma all_prs:
   383 lemma all_prs:
   384   assumes a: "Quotient3 R absf repf"
   384   assumes a: "Quotient3 R absf repf"
   385   shows "Ball (Respects R) ((absf ---> id) f) = All f"
   385   shows "Ball (Respects R) ((absf ---> id) f) = All f"
   438   done
   438   done
   439 
   439 
   440 lemma bex1_rel_rsp:
   440 lemma bex1_rel_rsp:
   441   assumes a: "Quotient3 R absf repf"
   441   assumes a: "Quotient3 R absf repf"
   442   shows "((R ===> op =) ===> op =) (Bex1_rel R) (Bex1_rel R)"
   442   shows "((R ===> op =) ===> op =) (Bex1_rel R) (Bex1_rel R)"
   443   apply (simp add: fun_rel_def)
   443   apply (simp add: rel_fun_def)
   444   apply clarify
   444   apply clarify
   445   apply rule
   445   apply rule
   446   apply (simp_all add: bex1_rel_aux bex1_rel_aux2)
   446   apply (simp_all add: bex1_rel_aux bex1_rel_aux2)
   447   apply (erule bex1_rel_aux2)
   447   apply (erule bex1_rel_aux2)
   448   apply assumption
   448   apply assumption
   517 subsection {* Various respects and preserve lemmas *}
   517 subsection {* Various respects and preserve lemmas *}
   518 
   518 
   519 lemma quot_rel_rsp:
   519 lemma quot_rel_rsp:
   520   assumes a: "Quotient3 R Abs Rep"
   520   assumes a: "Quotient3 R Abs Rep"
   521   shows "(R ===> R ===> op =) R R"
   521   shows "(R ===> R ===> op =) R R"
   522   apply(rule fun_relI)+
   522   apply(rule rel_funI)+
   523   apply(rule equals_rsp[OF a])
   523   apply(rule equals_rsp[OF a])
   524   apply(assumption)+
   524   apply(assumption)+
   525   done
   525   done
   526 
   526 
   527 lemma o_prs:
   527 lemma o_prs:
   534   by (simp_all add: fun_eq_iff)
   534   by (simp_all add: fun_eq_iff)
   535 
   535 
   536 lemma o_rsp:
   536 lemma o_rsp:
   537   "((R2 ===> R3) ===> (R1 ===> R2) ===> (R1 ===> R3)) op \<circ> op \<circ>"
   537   "((R2 ===> R3) ===> (R1 ===> R2) ===> (R1 ===> R3)) op \<circ> op \<circ>"
   538   "(op = ===> (R1 ===> op =) ===> R1 ===> op =) op \<circ> op \<circ>"
   538   "(op = ===> (R1 ===> op =) ===> R1 ===> op =) op \<circ> op \<circ>"
   539   by (force elim: fun_relE)+
   539   by (force elim: rel_funE)+
   540 
   540 
   541 lemma cond_prs:
   541 lemma cond_prs:
   542   assumes a: "Quotient3 R absf repf"
   542   assumes a: "Quotient3 R absf repf"
   543   shows "absf (if a then repf b else repf c) = (if a then b else c)"
   543   shows "absf (if a then repf b else repf c) = (if a then b else c)"
   544   using a unfolding Quotient3_def by auto
   544   using a unfolding Quotient3_def by auto
   561   using Quotient3_abs_rep[OF q1] Quotient3_abs_rep[OF q2]
   561   using Quotient3_abs_rep[OF q1] Quotient3_abs_rep[OF q2]
   562   by (auto simp add: fun_eq_iff)
   562   by (auto simp add: fun_eq_iff)
   563 
   563 
   564 lemma let_rsp:
   564 lemma let_rsp:
   565   shows "(R1 ===> (R1 ===> R2) ===> R2) Let Let"
   565   shows "(R1 ===> (R1 ===> R2) ===> R2) Let Let"
   566   by (force elim: fun_relE)
   566   by (force elim: rel_funE)
   567 
   567 
   568 lemma id_rsp:
   568 lemma id_rsp:
   569   shows "(R ===> R) id id"
   569   shows "(R ===> R) id id"
   570   by auto
   570   by auto
   571 
   571 
   757 text {* Auxiliary data for the quotient package *}
   757 text {* Auxiliary data for the quotient package *}
   758 
   758 
   759 ML_file "Tools/Quotient/quotient_info.ML"
   759 ML_file "Tools/Quotient/quotient_info.ML"
   760 setup Quotient_Info.setup
   760 setup Quotient_Info.setup
   761 
   761 
   762 declare [[mapQ3 "fun" = (fun_rel, fun_quotient3)]]
   762 declare [[mapQ3 "fun" = (rel_fun, fun_quotient3)]]
   763 
   763 
   764 lemmas [quot_thm] = fun_quotient3
   764 lemmas [quot_thm] = fun_quotient3
   765 lemmas [quot_respect] = quot_rel_rsp if_rsp o_rsp let_rsp id_rsp
   765 lemmas [quot_respect] = quot_rel_rsp if_rsp o_rsp let_rsp id_rsp
   766 lemmas [quot_preserve] = if_prs o_prs let_prs id_prs
   766 lemmas [quot_preserve] = if_prs o_prs let_prs id_prs
   767 lemmas [quot_equiv] = identity_equivp
   767 lemmas [quot_equiv] = identity_equivp