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