src/HOL/Quotient.thy
 changeset 47096 3ea48c19673e parent 47094 1a7ad2601cb5 child 47105 e64ffc96a49f
equal inserted replaced
47095:b43ddeea727f 47096:3ea48c19673e
7 theory Quotient
7 theory Quotient
8 imports Plain Hilbert_Choice Equiv_Relations
8 imports Plain Hilbert_Choice Equiv_Relations
9 keywords
9 keywords
10   "print_quotmaps" "print_quotients" "print_quotconsts" :: diag and
10   "print_quotmaps" "print_quotients" "print_quotconsts" :: diag and
11   "quotient_type" :: thy_goal and "/" and
11   "quotient_type" :: thy_goal and "/" and

12   "setup_lifting" :: thy_decl and
12   "quotient_definition" :: thy_goal
13   "quotient_definition" :: thy_goal
13 uses
14 uses
14   ("Tools/Quotient/quotient_info.ML")
15   ("Tools/Quotient/quotient_info.ML")
15   ("Tools/Quotient/quotient_type.ML")
16   ("Tools/Quotient/quotient_type.ML")
16   ("Tools/Quotient/quotient_def.ML")
17   ("Tools/Quotient/quotient_def.ML")
134   assumes a: "Quotient R Abs Rep"
135   assumes a: "Quotient R Abs Rep"
135   shows "R r r \<and> R s s \<and> Abs r = Abs s \<longleftrightarrow> R r s" -- {* orientation does not loop on rewriting *}
136   shows "R r r \<and> R s s \<and> Abs r = Abs s \<longleftrightarrow> R r s" -- {* orientation does not loop on rewriting *}
136   using a
137   using a
137   unfolding Quotient_def
138   unfolding Quotient_def
138   by blast
139   by blast

140

141 lemma Quotient_refl1:

142   assumes a: "Quotient R Abs Rep"

143   shows "R r s \<Longrightarrow> R r r"

144   using a unfolding Quotient_def

145   by fast

146

147 lemma Quotient_refl2:

148   assumes a: "Quotient R Abs Rep"

149   shows "R r s \<Longrightarrow> R s s"

150   using a unfolding Quotient_def

151   by fast
139
152
140 lemma Quotient_rel_rep:
153 lemma Quotient_rel_rep:
141   assumes a: "Quotient R Abs Rep"
154   assumes a: "Quotient R Abs Rep"
142   shows "R (Rep a) (Rep b) \<longleftrightarrow> a = b"
155   shows "R (Rep a) (Rep b) \<longleftrightarrow> a = b"
143   using a
156   using a
260
273
261 lemma apply_rsp':
274 lemma apply_rsp':
262   assumes a: "(R1 ===> R2) f g" "R1 x y"
275   assumes a: "(R1 ===> R2) f g" "R1 x y"
263   shows "R2 (f x) (g y)"
276   shows "R2 (f x) (g y)"
264   using a by (auto elim: fun_relE)
277   using a by (auto elim: fun_relE)

278

279 lemma apply_rsp'':

280   assumes "Quotient R Abs Rep"

281   and "(R ===> S) f f"

282   shows "S (f (Rep x)) (f (Rep x))"

283 proof -

284   from assms(1) have "R (Rep x) (Rep x)" by (rule Quotient_rep_reflp)

285   then show ?thesis using assms(2) by (auto intro: apply_rsp')

286 qed
265
287
266 subsection {* lemmas for regularisation of ball and bex *}
288 subsection {* lemmas for regularisation of ball and bex *}
267
289
268 lemma ball_reg_eqv:
290 lemma ball_reg_eqv:
269   fixes P :: "'a \<Rightarrow> bool"
291   fixes P :: "'a \<Rightarrow> bool"
677       using equivp[simplified part_equivp_def] by metis
699       using equivp[simplified part_equivp_def] by metis
678     qed
700     qed
679
701
680 end
702 end
681
703

704 subsection {* Quotient composition *}

705

706 lemma OOO_quotient:

707   fixes R1 :: "'a \<Rightarrow> 'a \<Rightarrow> bool"

708   fixes Abs1 :: "'a \<Rightarrow> 'b" and Rep1 :: "'b \<Rightarrow> 'a"

709   fixes Abs2 :: "'b \<Rightarrow> 'c" and Rep2 :: "'c \<Rightarrow> 'b"

710   fixes R2' :: "'a \<Rightarrow> 'a \<Rightarrow> bool"

711   fixes R2 :: "'b \<Rightarrow> 'b \<Rightarrow> bool"

712   assumes R1: "Quotient R1 Abs1 Rep1"

713   assumes R2: "Quotient R2 Abs2 Rep2"

714   assumes Abs1: "\<And>x y. R2' x y \<Longrightarrow> R1 x x \<Longrightarrow> R1 y y \<Longrightarrow> R2 (Abs1 x) (Abs1 y)"

715   assumes Rep1: "\<And>x y. R2 x y \<Longrightarrow> R2' (Rep1 x) (Rep1 y)"

716   shows "Quotient (R1 OO R2' OO R1) (Abs2 \<circ> Abs1) (Rep1 \<circ> Rep2)"

717 apply (rule QuotientI)

718    apply (simp add: o_def Quotient_abs_rep [OF R2] Quotient_abs_rep [OF R1])

719   apply simp

720   apply (rule_tac b="Rep1 (Rep2 a)" in pred_compI)

721    apply (rule Quotient_rep_reflp [OF R1])

722   apply (rule_tac b="Rep1 (Rep2 a)" in pred_compI [rotated])

723    apply (rule Quotient_rep_reflp [OF R1])

724   apply (rule Rep1)

725   apply (rule Quotient_rep_reflp [OF R2])

726  apply safe

727     apply (rename_tac x y)

728     apply (drule Abs1)

729       apply (erule Quotient_refl2 [OF R1])

730      apply (erule Quotient_refl1 [OF R1])

731     apply (drule Quotient_refl1 [OF R2], drule Rep1)

732     apply (subgoal_tac "R1 r (Rep1 (Abs1 x))")

733      apply (rule_tac b="Rep1 (Abs1 x)" in pred_compI, assumption)

734      apply (erule pred_compI)

735      apply (erule Quotient_symp [OF R1, THEN sympD])

736     apply (rule Quotient_rel[symmetric, OF R1, THEN iffD2])

737     apply (rule conjI, erule Quotient_refl1 [OF R1])

738     apply (rule conjI, rule Quotient_rep_reflp [OF R1])

739     apply (subst Quotient_abs_rep [OF R1])

740     apply (erule Quotient_rel_abs [OF R1])

741    apply (rename_tac x y)

742    apply (drule Abs1)

743      apply (erule Quotient_refl2 [OF R1])

744     apply (erule Quotient_refl1 [OF R1])

745    apply (drule Quotient_refl2 [OF R2], drule Rep1)

746    apply (subgoal_tac "R1 s (Rep1 (Abs1 y))")

747     apply (rule_tac b="Rep1 (Abs1 y)" in pred_compI, assumption)

748     apply (erule pred_compI)

749     apply (erule Quotient_symp [OF R1, THEN sympD])

750    apply (rule Quotient_rel[symmetric, OF R1, THEN iffD2])

751    apply (rule conjI, erule Quotient_refl2 [OF R1])

752    apply (rule conjI, rule Quotient_rep_reflp [OF R1])

753    apply (subst Quotient_abs_rep [OF R1])

754    apply (erule Quotient_rel_abs [OF R1, THEN sym])

755   apply simp

756   apply (rule Quotient_rel_abs [OF R2])

757   apply (rule Quotient_rel_abs [OF R1, THEN ssubst], assumption)

758   apply (rule Quotient_rel_abs [OF R1, THEN subst], assumption)

759   apply (erule Abs1)

760    apply (erule Quotient_refl2 [OF R1])

761   apply (erule Quotient_refl1 [OF R1])

762  apply (rename_tac a b c d)

763  apply simp

764  apply (rule_tac b="Rep1 (Abs1 r)" in pred_compI)

765   apply (rule Quotient_rel[symmetric, OF R1, THEN iffD2])

766   apply (rule conjI, erule Quotient_refl1 [OF R1])

767   apply (simp add: Quotient_abs_rep [OF R1] Quotient_rep_reflp [OF R1])

768  apply (rule_tac b="Rep1 (Abs1 s)" in pred_compI [rotated])

769   apply (rule Quotient_rel[symmetric, OF R1, THEN iffD2])

770   apply (simp add: Quotient_abs_rep [OF R1] Quotient_rep_reflp [OF R1])

771   apply (erule Quotient_refl2 [OF R1])

772  apply (rule Rep1)

773  apply (drule Abs1)

774    apply (erule Quotient_refl2 [OF R1])

775   apply (erule Quotient_refl1 [OF R1])

776  apply (drule Abs1)

777   apply (erule Quotient_refl2 [OF R1])

778  apply (erule Quotient_refl1 [OF R1])

779  apply (drule Quotient_rel_abs [OF R1])

780  apply (drule Quotient_rel_abs [OF R1])

781  apply (drule Quotient_rel_abs [OF R1])

782  apply (drule Quotient_rel_abs [OF R1])

783  apply simp

784  apply (rule Quotient_rel[symmetric, OF R2, THEN iffD2])

785  apply simp

786 done

787

788 lemma OOO_eq_quotient:

789   fixes R1 :: "'a \<Rightarrow> 'a \<Rightarrow> bool"

790   fixes Abs1 :: "'a \<Rightarrow> 'b" and Rep1 :: "'b \<Rightarrow> 'a"

791   fixes Abs2 :: "'b \<Rightarrow> 'c" and Rep2 :: "'c \<Rightarrow> 'b"

792   assumes R1: "Quotient R1 Abs1 Rep1"

793   assumes R2: "Quotient op= Abs2 Rep2"

794   shows "Quotient (R1 OOO op=) (Abs2 \<circ> Abs1) (Rep1 \<circ> Rep2)"

795 using assms

796 by (rule OOO_quotient) auto

797

798 subsection {* Invariant *}

799

800 definition invariant :: "('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool"

801   where "invariant R = (\<lambda>x y. R x \<and> x = y)"

802

803 lemma invariant_to_eq:

804   assumes "invariant P x y"

805   shows "x = y"

806 using assms by (simp add: invariant_def)

807

808 lemma fun_rel_eq_invariant:

809   shows "((invariant R) ===> S) = (\<lambda>f g. \<forall>x. R x \<longrightarrow> S (f x) (g x))"

810 by (auto simp add: invariant_def fun_rel_def)

811

812 lemma invariant_same_args:

813   shows "invariant P x x \<equiv> P x"

814 using assms by (auto simp add: invariant_def)

815

816 lemma copy_type_to_Quotient:

817   assumes "type_definition Rep Abs UNIV"

818   shows "Quotient (op =) Abs Rep"

819 proof -

820   interpret type_definition Rep Abs UNIV by fact

821   from Abs_inject Rep_inverse show ?thesis by (auto intro!: QuotientI)

822 qed

823

824 lemma copy_type_to_equivp:

825   fixes Abs :: "'a \<Rightarrow> 'b"

826   and Rep :: "'b \<Rightarrow> 'a"

827   assumes "type_definition Rep Abs (UNIV::'a set)"

828   shows "equivp (op=::'a\<Rightarrow>'a\<Rightarrow>bool)"

829 by (rule identity_equivp)

830

831 lemma invariant_type_to_Quotient:

832   assumes "type_definition Rep Abs {x. P x}"

833   shows "Quotient (invariant P) Abs Rep"

834 proof -

835   interpret type_definition Rep Abs "{x. P x}" by fact

836   from Rep Abs_inject Rep_inverse show ?thesis by (auto intro!: QuotientI simp: invariant_def)

837 qed

838

839 lemma invariant_type_to_part_equivp:

840   assumes "type_definition Rep Abs {x. P x}"

841   shows "part_equivp (invariant P)"

842 proof (intro part_equivpI)

843   interpret type_definition Rep Abs "{x. P x}" by fact

844   show "\<exists>x. invariant P x x" using Rep by (auto simp: invariant_def)

845 next

846   show "symp (invariant P)" by (auto intro: sympI simp: invariant_def)

847 next

848   show "transp (invariant P)" by (auto intro: transpI simp: invariant_def)

849 qed

850
682 subsection {* ML setup *}
851 subsection {* ML setup *}
683
852
684 text {* Auxiliary data for the quotient package *}
853 text {* Auxiliary data for the quotient package *}
685
854
686 use "Tools/Quotient/quotient_info.ML"
855 use "Tools/Quotient/quotient_info.ML"