src/HOL/Quotient.thy
 changeset 47096 3ea48c19673e parent 47094 1a7ad2601cb5 child 47105 e64ffc96a49f
```     1.1 --- a/src/HOL/Quotient.thy	Fri Mar 23 14:21:41 2012 +0100
1.2 +++ b/src/HOL/Quotient.thy	Fri Mar 23 14:25:31 2012 +0100
1.3 @@ -9,6 +9,7 @@
1.4  keywords
1.5    "print_quotmaps" "print_quotients" "print_quotconsts" :: diag and
1.6    "quotient_type" :: thy_goal and "/" and
1.7 +  "setup_lifting" :: thy_decl and
1.8    "quotient_definition" :: thy_goal
1.9  uses
1.10    ("Tools/Quotient/quotient_info.ML")
1.11 @@ -137,6 +138,18 @@
1.12    unfolding Quotient_def
1.13    by blast
1.14
1.15 +lemma Quotient_refl1:
1.16 +  assumes a: "Quotient R Abs Rep"
1.17 +  shows "R r s \<Longrightarrow> R r r"
1.18 +  using a unfolding Quotient_def
1.19 +  by fast
1.20 +
1.21 +lemma Quotient_refl2:
1.22 +  assumes a: "Quotient R Abs Rep"
1.23 +  shows "R r s \<Longrightarrow> R s s"
1.24 +  using a unfolding Quotient_def
1.25 +  by fast
1.26 +
1.27  lemma Quotient_rel_rep:
1.28    assumes a: "Quotient R Abs Rep"
1.29    shows "R (Rep a) (Rep b) \<longleftrightarrow> a = b"
1.30 @@ -263,6 +276,15 @@
1.31    shows "R2 (f x) (g y)"
1.32    using a by (auto elim: fun_relE)
1.33
1.34 +lemma apply_rsp'':
1.35 +  assumes "Quotient R Abs Rep"
1.36 +  and "(R ===> S) f f"
1.37 +  shows "S (f (Rep x)) (f (Rep x))"
1.38 +proof -
1.39 +  from assms(1) have "R (Rep x) (Rep x)" by (rule Quotient_rep_reflp)
1.40 +  then show ?thesis using assms(2) by (auto intro: apply_rsp')
1.41 +qed
1.42 +
1.43  subsection {* lemmas for regularisation of ball and bex *}
1.44
1.45  lemma ball_reg_eqv:
1.46 @@ -679,6 +701,153 @@
1.47
1.48  end
1.49
1.50 +subsection {* Quotient composition *}
1.51 +
1.52 +lemma OOO_quotient:
1.53 +  fixes R1 :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
1.54 +  fixes Abs1 :: "'a \<Rightarrow> 'b" and Rep1 :: "'b \<Rightarrow> 'a"
1.55 +  fixes Abs2 :: "'b \<Rightarrow> 'c" and Rep2 :: "'c \<Rightarrow> 'b"
1.56 +  fixes R2' :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
1.57 +  fixes R2 :: "'b \<Rightarrow> 'b \<Rightarrow> bool"
1.58 +  assumes R1: "Quotient R1 Abs1 Rep1"
1.59 +  assumes R2: "Quotient R2 Abs2 Rep2"
1.60 +  assumes Abs1: "\<And>x y. R2' x y \<Longrightarrow> R1 x x \<Longrightarrow> R1 y y \<Longrightarrow> R2 (Abs1 x) (Abs1 y)"
1.61 +  assumes Rep1: "\<And>x y. R2 x y \<Longrightarrow> R2' (Rep1 x) (Rep1 y)"
1.62 +  shows "Quotient (R1 OO R2' OO R1) (Abs2 \<circ> Abs1) (Rep1 \<circ> Rep2)"
1.63 +apply (rule QuotientI)
1.64 +   apply (simp add: o_def Quotient_abs_rep [OF R2] Quotient_abs_rep [OF R1])
1.65 +  apply simp
1.66 +  apply (rule_tac b="Rep1 (Rep2 a)" in pred_compI)
1.67 +   apply (rule Quotient_rep_reflp [OF R1])
1.68 +  apply (rule_tac b="Rep1 (Rep2 a)" in pred_compI [rotated])
1.69 +   apply (rule Quotient_rep_reflp [OF R1])
1.70 +  apply (rule Rep1)
1.71 +  apply (rule Quotient_rep_reflp [OF R2])
1.72 + apply safe
1.73 +    apply (rename_tac x y)
1.74 +    apply (drule Abs1)
1.75 +      apply (erule Quotient_refl2 [OF R1])
1.76 +     apply (erule Quotient_refl1 [OF R1])
1.77 +    apply (drule Quotient_refl1 [OF R2], drule Rep1)
1.78 +    apply (subgoal_tac "R1 r (Rep1 (Abs1 x))")
1.79 +     apply (rule_tac b="Rep1 (Abs1 x)" in pred_compI, assumption)
1.80 +     apply (erule pred_compI)
1.81 +     apply (erule Quotient_symp [OF R1, THEN sympD])
1.82 +    apply (rule Quotient_rel[symmetric, OF R1, THEN iffD2])
1.83 +    apply (rule conjI, erule Quotient_refl1 [OF R1])
1.84 +    apply (rule conjI, rule Quotient_rep_reflp [OF R1])
1.85 +    apply (subst Quotient_abs_rep [OF R1])
1.86 +    apply (erule Quotient_rel_abs [OF R1])
1.87 +   apply (rename_tac x y)
1.88 +   apply (drule Abs1)
1.89 +     apply (erule Quotient_refl2 [OF R1])
1.90 +    apply (erule Quotient_refl1 [OF R1])
1.91 +   apply (drule Quotient_refl2 [OF R2], drule Rep1)
1.92 +   apply (subgoal_tac "R1 s (Rep1 (Abs1 y))")
1.93 +    apply (rule_tac b="Rep1 (Abs1 y)" in pred_compI, assumption)
1.94 +    apply (erule pred_compI)
1.95 +    apply (erule Quotient_symp [OF R1, THEN sympD])
1.96 +   apply (rule Quotient_rel[symmetric, OF R1, THEN iffD2])
1.97 +   apply (rule conjI, erule Quotient_refl2 [OF R1])
1.98 +   apply (rule conjI, rule Quotient_rep_reflp [OF R1])
1.99 +   apply (subst Quotient_abs_rep [OF R1])
1.100 +   apply (erule Quotient_rel_abs [OF R1, THEN sym])
1.101 +  apply simp
1.102 +  apply (rule Quotient_rel_abs [OF R2])
1.103 +  apply (rule Quotient_rel_abs [OF R1, THEN ssubst], assumption)
1.104 +  apply (rule Quotient_rel_abs [OF R1, THEN subst], assumption)
1.105 +  apply (erule Abs1)
1.106 +   apply (erule Quotient_refl2 [OF R1])
1.107 +  apply (erule Quotient_refl1 [OF R1])
1.108 + apply (rename_tac a b c d)
1.109 + apply simp
1.110 + apply (rule_tac b="Rep1 (Abs1 r)" in pred_compI)
1.111 +  apply (rule Quotient_rel[symmetric, OF R1, THEN iffD2])
1.112 +  apply (rule conjI, erule Quotient_refl1 [OF R1])
1.113 +  apply (simp add: Quotient_abs_rep [OF R1] Quotient_rep_reflp [OF R1])
1.114 + apply (rule_tac b="Rep1 (Abs1 s)" in pred_compI [rotated])
1.115 +  apply (rule Quotient_rel[symmetric, OF R1, THEN iffD2])
1.116 +  apply (simp add: Quotient_abs_rep [OF R1] Quotient_rep_reflp [OF R1])
1.117 +  apply (erule Quotient_refl2 [OF R1])
1.118 + apply (rule Rep1)
1.119 + apply (drule Abs1)
1.120 +   apply (erule Quotient_refl2 [OF R1])
1.121 +  apply (erule Quotient_refl1 [OF R1])
1.122 + apply (drule Abs1)
1.123 +  apply (erule Quotient_refl2 [OF R1])
1.124 + apply (erule Quotient_refl1 [OF R1])
1.125 + apply (drule Quotient_rel_abs [OF R1])
1.126 + apply (drule Quotient_rel_abs [OF R1])
1.127 + apply (drule Quotient_rel_abs [OF R1])
1.128 + apply (drule Quotient_rel_abs [OF R1])
1.129 + apply simp
1.130 + apply (rule Quotient_rel[symmetric, OF R2, THEN iffD2])
1.131 + apply simp
1.132 +done
1.133 +
1.134 +lemma OOO_eq_quotient:
1.135 +  fixes R1 :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
1.136 +  fixes Abs1 :: "'a \<Rightarrow> 'b" and Rep1 :: "'b \<Rightarrow> 'a"
1.137 +  fixes Abs2 :: "'b \<Rightarrow> 'c" and Rep2 :: "'c \<Rightarrow> 'b"
1.138 +  assumes R1: "Quotient R1 Abs1 Rep1"
1.139 +  assumes R2: "Quotient op= Abs2 Rep2"
1.140 +  shows "Quotient (R1 OOO op=) (Abs2 \<circ> Abs1) (Rep1 \<circ> Rep2)"
1.141 +using assms
1.142 +by (rule OOO_quotient) auto
1.143 +
1.144 +subsection {* Invariant *}
1.145 +
1.146 +definition invariant :: "('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool"
1.147 +  where "invariant R = (\<lambda>x y. R x \<and> x = y)"
1.148 +
1.149 +lemma invariant_to_eq:
1.150 +  assumes "invariant P x y"
1.151 +  shows "x = y"
1.152 +using assms by (simp add: invariant_def)
1.153 +
1.154 +lemma fun_rel_eq_invariant:
1.155 +  shows "((invariant R) ===> S) = (\<lambda>f g. \<forall>x. R x \<longrightarrow> S (f x) (g x))"
1.156 +by (auto simp add: invariant_def fun_rel_def)
1.157 +
1.158 +lemma invariant_same_args:
1.159 +  shows "invariant P x x \<equiv> P x"
1.160 +using assms by (auto simp add: invariant_def)
1.161 +
1.162 +lemma copy_type_to_Quotient:
1.163 +  assumes "type_definition Rep Abs UNIV"
1.164 +  shows "Quotient (op =) Abs Rep"
1.165 +proof -
1.166 +  interpret type_definition Rep Abs UNIV by fact
1.167 +  from Abs_inject Rep_inverse show ?thesis by (auto intro!: QuotientI)
1.168 +qed
1.169 +
1.170 +lemma copy_type_to_equivp:
1.171 +  fixes Abs :: "'a \<Rightarrow> 'b"
1.172 +  and Rep :: "'b \<Rightarrow> 'a"
1.173 +  assumes "type_definition Rep Abs (UNIV::'a set)"
1.174 +  shows "equivp (op=::'a\<Rightarrow>'a\<Rightarrow>bool)"
1.175 +by (rule identity_equivp)
1.176 +
1.177 +lemma invariant_type_to_Quotient:
1.178 +  assumes "type_definition Rep Abs {x. P x}"
1.179 +  shows "Quotient (invariant P) Abs Rep"
1.180 +proof -
1.181 +  interpret type_definition Rep Abs "{x. P x}" by fact
1.182 +  from Rep Abs_inject Rep_inverse show ?thesis by (auto intro!: QuotientI simp: invariant_def)
1.183 +qed
1.184 +
1.185 +lemma invariant_type_to_part_equivp:
1.186 +  assumes "type_definition Rep Abs {x. P x}"
1.187 +  shows "part_equivp (invariant P)"
1.188 +proof (intro part_equivpI)
1.189 +  interpret type_definition Rep Abs "{x. P x}" by fact
1.190 +  show "\<exists>x. invariant P x x" using Rep by (auto simp: invariant_def)
1.191 +next
1.192 +  show "symp (invariant P)" by (auto intro: sympI simp: invariant_def)
1.193 +next
1.194 +  show "transp (invariant P)" by (auto intro: transpI simp: invariant_def)
1.195 +qed
1.196 +
1.197  subsection {* ML setup *}
1.198
1.199  text {* Auxiliary data for the quotient package *}
```