Quot/QuotBase.thy
changeset 1127 243a5ceaa088
parent 1126 dd6ce36a0616
child 1128 17ca92ab4660
equal deleted inserted replaced
1126:dd6ce36a0616 1127:243a5ceaa088
     1 (*  Title:      QuotBase.thy
       
     2     Author:     Cezary Kaliszyk and Christian Urban
       
     3 *)
       
     4 
       
     5 theory QuotBase
       
     6 imports Plain ATP_Linkup
       
     7 begin
       
     8 
       
     9 text {*
       
    10   Basic definition for equivalence relations
       
    11   that are represented by predicates.
       
    12 *}
       
    13 
       
    14 definition
       
    15   "equivp E \<longleftrightarrow> (\<forall>x y. E x y = (E x = E y))"
       
    16 
       
    17 definition
       
    18   "reflp E \<longleftrightarrow> (\<forall>x. E x x)"
       
    19 
       
    20 definition
       
    21   "symp E \<longleftrightarrow> (\<forall>x y. E x y \<longrightarrow> E y x)"
       
    22 
       
    23 definition
       
    24   "transp E \<longleftrightarrow> (\<forall>x y z. E x y \<and> E y z \<longrightarrow> E x z)"
       
    25 
       
    26 lemma equivp_reflp_symp_transp:
       
    27   shows "equivp E = (reflp E \<and> symp E \<and> transp E)"
       
    28   unfolding equivp_def reflp_def symp_def transp_def expand_fun_eq
       
    29   by blast
       
    30 
       
    31 lemma equivp_reflp:
       
    32   shows "equivp E \<Longrightarrow> E x x"
       
    33   by (simp only: equivp_reflp_symp_transp reflp_def)
       
    34 
       
    35 lemma equivp_symp:
       
    36   shows "equivp E \<Longrightarrow> E x y \<Longrightarrow> E y x"
       
    37   by (metis equivp_reflp_symp_transp symp_def)
       
    38 
       
    39 lemma equivp_transp:
       
    40   shows "equivp E \<Longrightarrow> E x y \<Longrightarrow> E y z \<Longrightarrow> E x z"
       
    41   by (metis equivp_reflp_symp_transp transp_def)
       
    42 
       
    43 lemma equivpI:
       
    44   assumes "reflp R" "symp R" "transp R"
       
    45   shows "equivp R"
       
    46   using assms by (simp add: equivp_reflp_symp_transp)
       
    47 
       
    48 lemma eq_imp_rel:  
       
    49   shows "equivp R \<Longrightarrow> a = b \<longrightarrow> R a b" 
       
    50   by (simp add: equivp_reflp)
       
    51 
       
    52 lemma identity_equivp:
       
    53   shows "equivp (op =)"
       
    54   unfolding equivp_def
       
    55   by auto
       
    56 
       
    57 
       
    58 text {* Partial equivalences: not yet used anywhere *}
       
    59 definition
       
    60   "part_equivp E \<longleftrightarrow> ((\<exists>x. E x x) \<and> (\<forall>x y. E x y = (E x x \<and> E y y \<and> (E x = E y))))"
       
    61 
       
    62 lemma equivp_implies_part_equivp:
       
    63   assumes a: "equivp E"
       
    64   shows "part_equivp E"
       
    65   using a 
       
    66   unfolding equivp_def part_equivp_def
       
    67   by auto
       
    68 
       
    69 text {* Composition of Relations *}
       
    70 
       
    71 abbreviation 
       
    72   rel_conj (infixr "OOO" 75)
       
    73 where
       
    74   "r1 OOO r2 \<equiv> r1 OO r2 OO r1"
       
    75 
       
    76 lemma eq_comp_r: 
       
    77   shows "((op =) OOO R) = R"
       
    78   by (auto simp add: expand_fun_eq)
       
    79 
       
    80 section {* Respects predicate *}
       
    81 
       
    82 definition
       
    83   Respects
       
    84 where
       
    85   "Respects R x \<longleftrightarrow> (R x x)"
       
    86 
       
    87 lemma in_respects:
       
    88   shows "(x \<in> Respects R) = R x x"
       
    89   unfolding mem_def Respects_def 
       
    90   by simp
       
    91 
       
    92 section {* Function map and function relation *}
       
    93 
       
    94 definition
       
    95   fun_map (infixr "--->" 55)
       
    96 where
       
    97 [simp]: "fun_map f g h x = g (h (f x))"
       
    98 
       
    99 definition
       
   100   fun_rel (infixr "===>" 55)
       
   101 where
       
   102 [simp]: "fun_rel E1 E2 f g = (\<forall>x y. E1 x y \<longrightarrow> E2 (f x) (g y))"
       
   103 
       
   104 
       
   105 lemma fun_map_id:
       
   106   shows "(id ---> id) = id"
       
   107   by (simp add: expand_fun_eq id_def)
       
   108 
       
   109 lemma fun_rel_eq:
       
   110   shows "((op =) ===> (op =)) = (op =)"
       
   111   by (simp add: expand_fun_eq)
       
   112 
       
   113 lemma fun_rel_id:
       
   114   assumes a: "\<And>x y. R1 x y \<Longrightarrow> R2 (f x) (g y)"
       
   115   shows "(R1 ===> R2) f g"
       
   116   using a by simp
       
   117 
       
   118 lemma fun_rel_id_asm:
       
   119   assumes a: "\<And>x y. R1 x y \<Longrightarrow> (A \<longrightarrow> R2 (f x) (g y))"
       
   120   shows "A \<longrightarrow> (R1 ===> R2) f g"
       
   121   using a by auto
       
   122 
       
   123 
       
   124 section {* Quotient Predicate *}
       
   125 
       
   126 definition
       
   127   "Quotient E Abs Rep \<longleftrightarrow>
       
   128      (\<forall>a. Abs (Rep a) = a) \<and> (\<forall>a. E (Rep a) (Rep a)) \<and>
       
   129      (\<forall>r s. E r s = (E r r \<and> E s s \<and> (Abs r = Abs s)))"
       
   130 
       
   131 lemma Quotient_abs_rep:
       
   132   assumes a: "Quotient E Abs Rep"
       
   133   shows "Abs (Rep a) = a"
       
   134   using a 
       
   135   unfolding Quotient_def
       
   136   by simp
       
   137 
       
   138 lemma Quotient_rep_reflp:
       
   139   assumes a: "Quotient E Abs Rep"
       
   140   shows "E (Rep a) (Rep a)"
       
   141   using a 
       
   142   unfolding Quotient_def
       
   143   by blast
       
   144 
       
   145 lemma Quotient_rel:
       
   146   assumes a: "Quotient E Abs Rep"
       
   147   shows " E r s = (E r r \<and> E s s \<and> (Abs r = Abs s))"
       
   148   using a 
       
   149   unfolding Quotient_def
       
   150   by blast
       
   151 
       
   152 lemma Quotient_rel_rep:
       
   153   assumes a: "Quotient R Abs Rep"
       
   154   shows "R (Rep a) (Rep b) = (a = b)"
       
   155   using a 
       
   156   unfolding Quotient_def
       
   157   by metis
       
   158 
       
   159 lemma Quotient_rep_abs:
       
   160   assumes a: "Quotient R Abs Rep"
       
   161   shows "R r r \<Longrightarrow> R (Rep (Abs r)) r"
       
   162   using a unfolding Quotient_def
       
   163   by blast
       
   164 
       
   165 lemma Quotient_rel_abs:
       
   166   assumes a: "Quotient E Abs Rep"
       
   167   shows "E r s \<Longrightarrow> Abs r = Abs s"
       
   168   using a unfolding Quotient_def
       
   169   by blast
       
   170 
       
   171 lemma Quotient_symp:
       
   172   assumes a: "Quotient E Abs Rep"
       
   173   shows "symp E"
       
   174   using a unfolding Quotient_def symp_def
       
   175   by metis
       
   176 
       
   177 lemma Quotient_transp:
       
   178   assumes a: "Quotient E Abs Rep"
       
   179   shows "transp E"
       
   180   using a unfolding Quotient_def transp_def
       
   181   by metis
       
   182 
       
   183 lemma identity_quotient:
       
   184   shows "Quotient (op =) id id"
       
   185   unfolding Quotient_def id_def
       
   186   by blast
       
   187 
       
   188 lemma fun_quotient:
       
   189   assumes q1: "Quotient R1 abs1 rep1"
       
   190   and     q2: "Quotient R2 abs2 rep2"
       
   191   shows "Quotient (R1 ===> R2) (rep1 ---> abs2) (abs1 ---> rep2)"
       
   192 proof -
       
   193   have "\<forall>a. (rep1 ---> abs2) ((abs1 ---> rep2) a) = a"
       
   194     using q1 q2 
       
   195     unfolding Quotient_def
       
   196     unfolding expand_fun_eq
       
   197     by simp
       
   198   moreover
       
   199   have "\<forall>a. (R1 ===> R2) ((abs1 ---> rep2) a) ((abs1 ---> rep2) a)"
       
   200     using q1 q2 
       
   201     unfolding Quotient_def
       
   202     by (simp (no_asm)) (metis)
       
   203   moreover
       
   204   have "\<forall>r s. (R1 ===> R2) r s = ((R1 ===> R2) r r \<and> (R1 ===> R2) s s \<and> 
       
   205         (rep1 ---> abs2) r  = (rep1 ---> abs2) s)"
       
   206     unfolding expand_fun_eq
       
   207     apply(auto)
       
   208     using q1 q2 unfolding Quotient_def
       
   209     apply(metis)
       
   210     using q1 q2 unfolding Quotient_def
       
   211     apply(metis)
       
   212     using q1 q2 unfolding Quotient_def
       
   213     apply(metis)
       
   214     using q1 q2 unfolding Quotient_def
       
   215     apply(metis)
       
   216     done
       
   217   ultimately
       
   218   show "Quotient (R1 ===> R2) (rep1 ---> abs2) (abs1 ---> rep2)"
       
   219     unfolding Quotient_def by blast
       
   220 qed
       
   221 
       
   222 lemma abs_o_rep:
       
   223   assumes a: "Quotient R Abs Rep"
       
   224   shows "Abs o Rep = id"
       
   225   unfolding expand_fun_eq
       
   226   by (simp add: Quotient_abs_rep[OF a])
       
   227 
       
   228 lemma equals_rsp:
       
   229   assumes q: "Quotient R Abs Rep"
       
   230   and     a: "R xa xb" "R ya yb"
       
   231   shows "R xa ya = R xb yb"
       
   232   using a Quotient_symp[OF q] Quotient_transp[OF q] 
       
   233   unfolding symp_def transp_def
       
   234   by blast
       
   235 
       
   236 lemma lambda_prs:
       
   237   assumes q1: "Quotient R1 Abs1 Rep1"
       
   238   and     q2: "Quotient R2 Abs2 Rep2"
       
   239   shows "(Rep1 ---> Abs2) (\<lambda>x. Rep2 (f (Abs1 x))) = (\<lambda>x. f x)"
       
   240   unfolding expand_fun_eq
       
   241   using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2]
       
   242   by simp
       
   243 
       
   244 lemma lambda_prs1:
       
   245   assumes q1: "Quotient R1 Abs1 Rep1"
       
   246   and     q2: "Quotient R2 Abs2 Rep2"
       
   247   shows "(Rep1 ---> Abs2) (\<lambda>x. (Abs1 ---> Rep2) f x) = (\<lambda>x. f x)"
       
   248   unfolding expand_fun_eq
       
   249   using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2]
       
   250   by simp
       
   251 
       
   252 lemma rep_abs_rsp:
       
   253   assumes q: "Quotient R Abs Rep"
       
   254   and     a: "R x1 x2"
       
   255   shows "R x1 (Rep (Abs x2))"
       
   256   using a Quotient_rel[OF q] Quotient_abs_rep[OF q] Quotient_rep_reflp[OF q]
       
   257   by metis
       
   258 
       
   259 lemma rep_abs_rsp_left:
       
   260   assumes q: "Quotient R Abs Rep"
       
   261   and     a: "R x1 x2"
       
   262   shows "R (Rep (Abs x1)) x2"
       
   263   using a Quotient_rel[OF q] Quotient_abs_rep[OF q] Quotient_rep_reflp[OF q]
       
   264   by metis
       
   265 
       
   266 text{* 
       
   267   In the following theorem R1 can be instantiated with anything,
       
   268   but we know some of the types of the Rep and Abs functions;
       
   269   so by solving Quotient assumptions we can get a unique R1 that
       
   270   will be provable; which is why we need to use apply_rsp and
       
   271   not the primed version *}
       
   272 
       
   273 lemma apply_rsp:
       
   274   fixes f g::"'a \<Rightarrow> 'c"
       
   275   assumes q: "Quotient R1 Abs1 Rep1"
       
   276   and     a: "(R1 ===> R2) f g" "R1 x y"
       
   277   shows "R2 (f x) (g y)"
       
   278   using a by simp
       
   279 
       
   280 lemma apply_rsp':
       
   281   assumes a: "(R1 ===> R2) f g" "R1 x y"
       
   282   shows "R2 (f x) (g y)"
       
   283   using a by simp
       
   284 
       
   285 section {* lemmas for regularisation of ball and bex *}
       
   286 
       
   287 lemma ball_reg_eqv:
       
   288   fixes P :: "'a \<Rightarrow> bool"
       
   289   assumes a: "equivp R"
       
   290   shows "Ball (Respects R) P = (All P)"
       
   291   using a 
       
   292   unfolding equivp_def
       
   293   by (auto simp add: in_respects)
       
   294 
       
   295 lemma bex_reg_eqv:
       
   296   fixes P :: "'a \<Rightarrow> bool"
       
   297   assumes a: "equivp R"
       
   298   shows "Bex (Respects R) P = (Ex P)"
       
   299   using a 
       
   300   unfolding equivp_def
       
   301   by (auto simp add: in_respects)
       
   302 
       
   303 lemma ball_reg_right:
       
   304   assumes a: "\<And>x. R x \<Longrightarrow> P x \<longrightarrow> Q x"
       
   305   shows "All P \<longrightarrow> Ball R Q"
       
   306   using a by (metis COMBC_def Collect_def Collect_mem_eq)
       
   307 
       
   308 lemma bex_reg_left:
       
   309   assumes a: "\<And>x. R x \<Longrightarrow> Q x \<longrightarrow> P x"
       
   310   shows "Bex R Q \<longrightarrow> Ex P"
       
   311   using a by (metis COMBC_def Collect_def Collect_mem_eq)
       
   312 
       
   313 lemma ball_reg_left:
       
   314   assumes a: "equivp R"
       
   315   shows "(\<And>x. (Q x \<longrightarrow> P x)) \<Longrightarrow> Ball (Respects R) Q \<longrightarrow> All P"
       
   316   using a by (metis equivp_reflp in_respects)
       
   317 
       
   318 lemma bex_reg_right:
       
   319   assumes a: "equivp R"
       
   320   shows "(\<And>x. (Q x \<longrightarrow> P x)) \<Longrightarrow> Ex Q \<longrightarrow> Bex (Respects R) P"
       
   321   using a by (metis equivp_reflp in_respects)
       
   322 
       
   323 lemma ball_reg_eqv_range:
       
   324   fixes P::"'a \<Rightarrow> bool"
       
   325   and x::"'a"
       
   326   assumes a: "equivp R2"
       
   327   shows   "(Ball (Respects (R1 ===> R2)) (\<lambda>f. P (f x)) = All (\<lambda>f. P (f x)))"
       
   328   apply(rule iffI)
       
   329   apply(rule allI)
       
   330   apply(drule_tac x="\<lambda>y. f x" in bspec)
       
   331   apply(simp add: in_respects)
       
   332   apply(rule impI)
       
   333   using a equivp_reflp_symp_transp[of "R2"]
       
   334   apply(simp add: reflp_def)
       
   335   apply(simp)
       
   336   apply(simp)
       
   337   done
       
   338 
       
   339 lemma bex_reg_eqv_range:
       
   340   assumes a: "equivp R2"
       
   341   shows   "(Bex (Respects (R1 ===> R2)) (\<lambda>f. P (f x)) = Ex (\<lambda>f. P (f x)))"
       
   342   apply(auto)
       
   343   apply(rule_tac x="\<lambda>y. f x" in bexI)
       
   344   apply(simp)
       
   345   apply(simp add: Respects_def in_respects)
       
   346   apply(rule impI)
       
   347   using a equivp_reflp_symp_transp[of "R2"]
       
   348   apply(simp add: reflp_def)
       
   349   done
       
   350 
       
   351 lemma all_reg:
       
   352   assumes a: "!x :: 'a. (P x --> Q x)"
       
   353   and     b: "All P"
       
   354   shows "All Q"
       
   355   using a b by (metis)
       
   356 
       
   357 lemma ex_reg:
       
   358   assumes a: "!x :: 'a. (P x --> Q x)"
       
   359   and     b: "Ex P"
       
   360   shows "Ex Q"
       
   361   using a b by metis
       
   362 
       
   363 lemma ball_reg:
       
   364   assumes a: "!x :: 'a. (R x --> P x --> Q x)"
       
   365   and     b: "Ball R P"
       
   366   shows "Ball R Q"
       
   367   using a b by (metis COMBC_def Collect_def Collect_mem_eq)
       
   368 
       
   369 lemma bex_reg:
       
   370   assumes a: "!x :: 'a. (R x --> P x --> Q x)"
       
   371   and     b: "Bex R P"
       
   372   shows "Bex R Q"
       
   373   using a b by (metis COMBC_def Collect_def Collect_mem_eq)
       
   374 
       
   375 lemma ball_all_comm:
       
   376   assumes "\<And>y. (\<forall>x\<in>P. A x y) \<longrightarrow> (\<forall>x. B x y)"
       
   377   shows "(\<forall>x\<in>P. \<forall>y. A x y) \<longrightarrow> (\<forall>x. \<forall>y. B x y)"
       
   378   using assms by auto
       
   379 
       
   380 lemma bex_ex_comm:
       
   381   assumes "(\<exists>y. \<exists>x. A x y) \<longrightarrow> (\<exists>y. \<exists>x\<in>P. B x y)"
       
   382   shows "(\<exists>x. \<exists>y. A x y) \<longrightarrow> (\<exists>x\<in>P. \<exists>y. B x y)"
       
   383   using assms by auto
       
   384 
       
   385 section {* Bounded abstraction *}
       
   386 
       
   387 definition
       
   388   Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
       
   389 where
       
   390   "x \<in> p \<Longrightarrow> Babs p m x = m x"
       
   391 
       
   392 lemma babs_rsp:
       
   393   assumes q: "Quotient R1 Abs1 Rep1"
       
   394   and     a: "(R1 ===> R2) f g"
       
   395   shows      "(R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)"
       
   396   apply (auto simp add: Babs_def in_respects)
       
   397   apply (subgoal_tac "x \<in> Respects R1 \<and> y \<in> Respects R1")
       
   398   using a apply (simp add: Babs_def)
       
   399   apply (simp add: in_respects)
       
   400   using Quotient_rel[OF q]
       
   401   by metis
       
   402 
       
   403 lemma babs_prs:
       
   404   assumes q1: "Quotient R1 Abs1 Rep1"
       
   405   and     q2: "Quotient R2 Abs2 Rep2"
       
   406   shows "((Rep1 ---> Abs2) (Babs (Respects R1) ((Abs1 ---> Rep2) f))) = f"
       
   407   apply (rule ext)
       
   408   apply (simp)
       
   409   apply (subgoal_tac "Rep1 x \<in> Respects R1")
       
   410   apply (simp add: Babs_def Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2])
       
   411   apply (simp add: in_respects Quotient_rel_rep[OF q1])
       
   412   done
       
   413 
       
   414 lemma babs_simp:
       
   415   assumes q: "Quotient R1 Abs Rep"
       
   416   shows "((R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)) = ((R1 ===> R2) f g)"
       
   417   apply(rule iffI)
       
   418   apply(simp_all only: babs_rsp[OF q])
       
   419   apply(auto simp add: Babs_def)
       
   420   apply (subgoal_tac "x \<in> Respects R1 \<and> y \<in> Respects R1")
       
   421   apply(metis Babs_def)
       
   422   apply (simp add: in_respects)
       
   423   using Quotient_rel[OF q]
       
   424   by metis
       
   425 
       
   426 (* If a user proves that a particular functional relation 
       
   427    is an equivalence this may be useful in regularising *)
       
   428 lemma babs_reg_eqv:
       
   429   shows "equivp R \<Longrightarrow> Babs (Respects R) P = P"
       
   430   by (simp add: expand_fun_eq Babs_def in_respects equivp_reflp)
       
   431 
       
   432 
       
   433 (* 3 lemmas needed for proving repabs_inj *)
       
   434 lemma ball_rsp:
       
   435   assumes a: "(R ===> (op =)) f g"
       
   436   shows "Ball (Respects R) f = Ball (Respects R) g"
       
   437   using a by (simp add: Ball_def in_respects)
       
   438 
       
   439 lemma bex_rsp:
       
   440   assumes a: "(R ===> (op =)) f g"
       
   441   shows "(Bex (Respects R) f = Bex (Respects R) g)"
       
   442   using a by (simp add: Bex_def in_respects)
       
   443 
       
   444 lemma bex1_rsp:
       
   445   assumes a: "(R ===> (op =)) f g"
       
   446   shows "Ex1 (\<lambda>x. x \<in> Respects R \<and> f x) = Ex1 (\<lambda>x. x \<in> Respects R \<and> g x)"
       
   447   using a 
       
   448   by (simp add: Ex1_def in_respects) auto
       
   449 
       
   450 (* 2 lemmas needed for cleaning of quantifiers *)
       
   451 lemma all_prs:
       
   452   assumes a: "Quotient R absf repf"
       
   453   shows "Ball (Respects R) ((absf ---> id) f) = All f"
       
   454   using a unfolding Quotient_def Ball_def in_respects fun_map_def id_apply
       
   455   by metis
       
   456 
       
   457 lemma ex_prs:
       
   458   assumes a: "Quotient R absf repf"
       
   459   shows "Bex (Respects R) ((absf ---> id) f) = Ex f"
       
   460   using a unfolding Quotient_def Bex_def in_respects fun_map_def id_apply
       
   461   by metis
       
   462 
       
   463 section {* Bex1_rel quantifier *}
       
   464 
       
   465 definition
       
   466   Bex1_rel :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool"
       
   467 where
       
   468   "Bex1_rel R P \<longleftrightarrow> (\<exists>x \<in> Respects R. P x) \<and> (\<forall>x \<in> Respects R. \<forall>y \<in> Respects R. ((P x \<and> P y) \<longrightarrow> (R x y)))"
       
   469 
       
   470 lemma bex1_rel_aux:
       
   471   "\<lbrakk>\<forall>xa ya. R xa ya \<longrightarrow> x xa = y ya; Bex1_rel R x\<rbrakk> \<Longrightarrow> Bex1_rel R y"
       
   472   unfolding Bex1_rel_def
       
   473   apply (erule conjE)+
       
   474   apply (erule bexE)
       
   475   apply rule
       
   476   apply (rule_tac x="xa" in bexI)
       
   477   apply metis
       
   478   apply metis
       
   479   apply rule+
       
   480   apply (erule_tac x="xaa" in ballE)
       
   481   prefer 2
       
   482   apply (metis)
       
   483   apply (erule_tac x="ya" in ballE)
       
   484   prefer 2
       
   485   apply (metis)
       
   486   apply (metis in_respects)
       
   487   done
       
   488 
       
   489 lemma bex1_rel_aux2:
       
   490   "\<lbrakk>\<forall>xa ya. R xa ya \<longrightarrow> x xa = y ya; Bex1_rel R y\<rbrakk> \<Longrightarrow> Bex1_rel R x"
       
   491   unfolding Bex1_rel_def
       
   492   apply (erule conjE)+
       
   493   apply (erule bexE)
       
   494   apply rule
       
   495   apply (rule_tac x="xa" in bexI)
       
   496   apply metis
       
   497   apply metis
       
   498   apply rule+
       
   499   apply (erule_tac x="xaa" in ballE)
       
   500   prefer 2
       
   501   apply (metis)
       
   502   apply (erule_tac x="ya" in ballE)
       
   503   prefer 2
       
   504   apply (metis)
       
   505   apply (metis in_respects)
       
   506   done
       
   507 
       
   508 lemma bex1_rel_rsp:
       
   509   assumes a: "Quotient R absf repf"
       
   510   shows "((R ===> op =) ===> op =) (Bex1_rel R) (Bex1_rel R)"
       
   511   apply simp
       
   512   apply clarify
       
   513   apply rule
       
   514   apply (simp_all add: bex1_rel_aux bex1_rel_aux2)
       
   515   apply (erule bex1_rel_aux2)
       
   516   apply assumption
       
   517   done
       
   518 
       
   519 
       
   520 lemma ex1_prs:
       
   521   assumes a: "Quotient R absf repf"
       
   522   shows "((absf ---> id) ---> id) (Bex1_rel R) f = Ex1 f"
       
   523 apply simp
       
   524 apply (subst Bex1_rel_def)
       
   525 apply (subst Bex_def)
       
   526 apply (subst Ex1_def)
       
   527 apply simp
       
   528 apply rule
       
   529  apply (erule conjE)+
       
   530  apply (erule_tac exE)
       
   531  apply (erule conjE)
       
   532  apply (subgoal_tac "\<forall>y. R y y \<longrightarrow> f (absf y) \<longrightarrow> R x y")
       
   533   apply (rule_tac x="absf x" in exI)
       
   534   apply (simp)
       
   535   apply rule+
       
   536   using a unfolding Quotient_def
       
   537   apply metis
       
   538  apply rule+
       
   539  apply (erule_tac x="x" in ballE)
       
   540   apply (erule_tac x="y" in ballE)
       
   541    apply simp
       
   542   apply (simp add: in_respects)
       
   543  apply (simp add: in_respects)
       
   544 apply (erule_tac exE)
       
   545  apply rule
       
   546  apply (rule_tac x="repf x" in exI)
       
   547  apply (simp only: in_respects)
       
   548   apply rule
       
   549  apply (metis Quotient_rel_rep[OF a])
       
   550 using a unfolding Quotient_def apply (simp)
       
   551 apply rule+
       
   552 using a unfolding Quotient_def in_respects
       
   553 apply metis
       
   554 done
       
   555 
       
   556 lemma bex1_bexeq_reg: "(\<exists>!x\<in>Respects R. P x) \<longrightarrow> (Bex1_rel R (\<lambda>x. P x))"
       
   557   apply (simp add: Ex1_def Bex1_rel_def in_respects)
       
   558   apply clarify
       
   559   apply auto
       
   560   apply (rule bexI)
       
   561   apply assumption
       
   562   apply (simp add: in_respects)
       
   563   apply (simp add: in_respects)
       
   564   apply auto
       
   565   done
       
   566 
       
   567 section {* Various respects and preserve lemmas *}
       
   568 
       
   569 lemma quot_rel_rsp:
       
   570   assumes a: "Quotient R Abs Rep"
       
   571   shows "(R ===> R ===> op =) R R"
       
   572   apply(rule fun_rel_id)+
       
   573   apply(rule equals_rsp[OF a])
       
   574   apply(assumption)+
       
   575   done
       
   576 
       
   577 lemma o_prs:
       
   578   assumes q1: "Quotient R1 Abs1 Rep1"
       
   579   and     q2: "Quotient R2 Abs2 Rep2"
       
   580   and     q3: "Quotient R3 Abs3 Rep3"
       
   581   shows "(Rep1 ---> Abs3) (((Abs2 ---> Rep3) f) o ((Abs1 ---> Rep2) g)) = f o g"
       
   582   using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] Quotient_abs_rep[OF q3]
       
   583   unfolding o_def expand_fun_eq by simp
       
   584 
       
   585 lemma o_rsp:
       
   586   assumes q1: "Quotient R1 Abs1 Rep1"
       
   587   and     q2: "Quotient R2 Abs2 Rep2"
       
   588   and     q3: "Quotient R3 Abs3 Rep3"
       
   589   and     a1: "(R2 ===> R3) f1 f2"
       
   590   and     a2: "(R1 ===> R2) g1 g2"
       
   591   shows "(R1 ===> R3) (f1 o g1) (f2 o g2)"
       
   592   using a1 a2 unfolding o_def expand_fun_eq
       
   593   by (auto)
       
   594 
       
   595 lemma cond_prs:
       
   596   assumes a: "Quotient R absf repf"
       
   597   shows "absf (if a then repf b else repf c) = (if a then b else c)"
       
   598   using a unfolding Quotient_def by auto
       
   599 
       
   600 lemma if_prs:
       
   601   assumes q: "Quotient R Abs Rep"
       
   602   shows "Abs (If a (Rep b) (Rep c)) = If a b c"
       
   603   using Quotient_abs_rep[OF q] by auto
       
   604 
       
   605 (* q not used *)
       
   606 lemma if_rsp:
       
   607   assumes q: "Quotient R Abs Rep"
       
   608   and     a: "a1 = a2" "R b1 b2" "R c1 c2"
       
   609   shows "R (If a1 b1 c1) (If a2 b2 c2)"
       
   610   using a by auto
       
   611 
       
   612 lemma let_prs:
       
   613   assumes q1: "Quotient R1 Abs1 Rep1"
       
   614   and     q2: "Quotient R2 Abs2 Rep2"
       
   615   shows "Abs2 (Let (Rep1 x) ((Abs1 ---> Rep2) f)) = Let x f"
       
   616   using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] by auto
       
   617 
       
   618 lemma let_rsp:
       
   619   assumes q1: "Quotient R1 Abs1 Rep1"
       
   620   and     a1: "(R1 ===> R2) f g"
       
   621   and     a2: "R1 x y"
       
   622   shows "R2 ((Let x f)::'c) ((Let y g)::'c)"
       
   623   using apply_rsp[OF q1 a1] a2 by auto
       
   624 
       
   625 end
       
   626