src/HOL/Lifting.thy
author kuncar
Wed May 15 12:10:39 2013 +0200 (2013-05-15)
changeset 51994 82cc2aeb7d13
parent 51956 a4d81cdebf8b
child 52036 1aa2e40df9ff
permissions -rw-r--r--
stronger reflexivity prover
     1 (*  Title:      HOL/Lifting.thy
     2     Author:     Brian Huffman and Ondrej Kuncar
     3     Author:     Cezary Kaliszyk and Christian Urban
     4 *)
     5 
     6 header {* Lifting package *}
     7 
     8 theory Lifting
     9 imports Equiv_Relations Transfer
    10 keywords
    11   "parametric" and
    12   "print_quotmaps" "print_quotients" :: diag and
    13   "lift_definition" :: thy_goal and
    14   "setup_lifting" :: thy_decl
    15 begin
    16 
    17 subsection {* Function map *}
    18 
    19 notation map_fun (infixr "--->" 55)
    20 
    21 lemma map_fun_id:
    22   "(id ---> id) = id"
    23   by (simp add: fun_eq_iff)
    24 
    25 subsection {* Other predicates on relations *}
    26 
    27 definition left_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
    28   where "left_total R \<longleftrightarrow> (\<forall>x. \<exists>y. R x y)"
    29 
    30 lemma left_totalI:
    31   "(\<And>x. \<exists>y. R x y) \<Longrightarrow> left_total R"
    32 unfolding left_total_def by blast
    33 
    34 lemma left_totalE:
    35   assumes "left_total R"
    36   obtains "(\<And>x. \<exists>y. R x y)"
    37 using assms unfolding left_total_def by blast
    38 
    39 definition left_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
    40   where "left_unique R \<longleftrightarrow> (\<forall>x y z. R x z \<longrightarrow> R y z \<longrightarrow> x = y)"
    41 
    42 subsection {* Quotient Predicate *}
    43 
    44 definition
    45   "Quotient R Abs Rep T \<longleftrightarrow>
    46      (\<forall>a. Abs (Rep a) = a) \<and> 
    47      (\<forall>a. R (Rep a) (Rep a)) \<and>
    48      (\<forall>r s. R r s \<longleftrightarrow> R r r \<and> R s s \<and> Abs r = Abs s) \<and>
    49      T = (\<lambda>x y. R x x \<and> Abs x = y)"
    50 
    51 lemma QuotientI:
    52   assumes "\<And>a. Abs (Rep a) = a"
    53     and "\<And>a. R (Rep a) (Rep a)"
    54     and "\<And>r s. R r s \<longleftrightarrow> R r r \<and> R s s \<and> Abs r = Abs s"
    55     and "T = (\<lambda>x y. R x x \<and> Abs x = y)"
    56   shows "Quotient R Abs Rep T"
    57   using assms unfolding Quotient_def by blast
    58 
    59 context
    60   fixes R Abs Rep T
    61   assumes a: "Quotient R Abs Rep T"
    62 begin
    63 
    64 lemma Quotient_abs_rep: "Abs (Rep a) = a"
    65   using a unfolding Quotient_def
    66   by simp
    67 
    68 lemma Quotient_rep_reflp: "R (Rep a) (Rep a)"
    69   using a unfolding Quotient_def
    70   by blast
    71 
    72 lemma Quotient_rel:
    73   "R r r \<and> R s s \<and> Abs r = Abs s \<longleftrightarrow> R r s" -- {* orientation does not loop on rewriting *}
    74   using a unfolding Quotient_def
    75   by blast
    76 
    77 lemma Quotient_cr_rel: "T = (\<lambda>x y. R x x \<and> Abs x = y)"
    78   using a unfolding Quotient_def
    79   by blast
    80 
    81 lemma Quotient_refl1: "R r s \<Longrightarrow> R r r"
    82   using a unfolding Quotient_def
    83   by fast
    84 
    85 lemma Quotient_refl2: "R r s \<Longrightarrow> R s s"
    86   using a unfolding Quotient_def
    87   by fast
    88 
    89 lemma Quotient_rel_rep: "R (Rep a) (Rep b) \<longleftrightarrow> a = b"
    90   using a unfolding Quotient_def
    91   by metis
    92 
    93 lemma Quotient_rep_abs: "R r r \<Longrightarrow> R (Rep (Abs r)) r"
    94   using a unfolding Quotient_def
    95   by blast
    96 
    97 lemma Quotient_rep_abs_fold_unmap: 
    98   assumes "x' \<equiv> Abs x" and "R x x" and "Rep x' \<equiv> Rep' x'" 
    99   shows "R (Rep' x') x"
   100 proof -
   101   have "R (Rep x') x" using assms(1-2) Quotient_rep_abs by auto
   102   then show ?thesis using assms(3) by simp
   103 qed
   104 
   105 lemma Quotient_Rep_eq:
   106   assumes "x' \<equiv> Abs x" 
   107   shows "Rep x' \<equiv> Rep x'"
   108 by simp
   109 
   110 lemma Quotient_rel_abs: "R r s \<Longrightarrow> Abs r = Abs s"
   111   using a unfolding Quotient_def
   112   by blast
   113 
   114 lemma Quotient_rel_abs2:
   115   assumes "R (Rep x) y"
   116   shows "x = Abs y"
   117 proof -
   118   from assms have "Abs (Rep x) = Abs y" by (auto intro: Quotient_rel_abs)
   119   then show ?thesis using assms(1) by (simp add: Quotient_abs_rep)
   120 qed
   121 
   122 lemma Quotient_symp: "symp R"
   123   using a unfolding Quotient_def using sympI by (metis (full_types))
   124 
   125 lemma Quotient_transp: "transp R"
   126   using a unfolding Quotient_def using transpI by (metis (full_types))
   127 
   128 lemma Quotient_part_equivp: "part_equivp R"
   129 by (metis Quotient_rep_reflp Quotient_symp Quotient_transp part_equivpI)
   130 
   131 end
   132 
   133 lemma identity_quotient: "Quotient (op =) id id (op =)"
   134 unfolding Quotient_def by simp 
   135 
   136 text {* TODO: Use one of these alternatives as the real definition. *}
   137 
   138 lemma Quotient_alt_def:
   139   "Quotient R Abs Rep T \<longleftrightarrow>
   140     (\<forall>a b. T a b \<longrightarrow> Abs a = b) \<and>
   141     (\<forall>b. T (Rep b) b) \<and>
   142     (\<forall>x y. R x y \<longleftrightarrow> T x (Abs x) \<and> T y (Abs y) \<and> Abs x = Abs y)"
   143 apply safe
   144 apply (simp (no_asm_use) only: Quotient_def, fast)
   145 apply (simp (no_asm_use) only: Quotient_def, fast)
   146 apply (simp (no_asm_use) only: Quotient_def, fast)
   147 apply (simp (no_asm_use) only: Quotient_def, fast)
   148 apply (simp (no_asm_use) only: Quotient_def, fast)
   149 apply (simp (no_asm_use) only: Quotient_def, fast)
   150 apply (rule QuotientI)
   151 apply simp
   152 apply metis
   153 apply simp
   154 apply (rule ext, rule ext, metis)
   155 done
   156 
   157 lemma Quotient_alt_def2:
   158   "Quotient R Abs Rep T \<longleftrightarrow>
   159     (\<forall>a b. T a b \<longrightarrow> Abs a = b) \<and>
   160     (\<forall>b. T (Rep b) b) \<and>
   161     (\<forall>x y. R x y \<longleftrightarrow> T x (Abs y) \<and> T y (Abs x))"
   162   unfolding Quotient_alt_def by (safe, metis+)
   163 
   164 lemma Quotient_alt_def3:
   165   "Quotient R Abs Rep T \<longleftrightarrow>
   166     (\<forall>a b. T a b \<longrightarrow> Abs a = b) \<and> (\<forall>b. T (Rep b) b) \<and>
   167     (\<forall>x y. R x y \<longleftrightarrow> (\<exists>z. T x z \<and> T y z))"
   168   unfolding Quotient_alt_def2 by (safe, metis+)
   169 
   170 lemma Quotient_alt_def4:
   171   "Quotient R Abs Rep T \<longleftrightarrow>
   172     (\<forall>a b. T a b \<longrightarrow> Abs a = b) \<and> (\<forall>b. T (Rep b) b) \<and> R = T OO conversep T"
   173   unfolding Quotient_alt_def3 fun_eq_iff by auto
   174 
   175 lemma fun_quotient:
   176   assumes 1: "Quotient R1 abs1 rep1 T1"
   177   assumes 2: "Quotient R2 abs2 rep2 T2"
   178   shows "Quotient (R1 ===> R2) (rep1 ---> abs2) (abs1 ---> rep2) (T1 ===> T2)"
   179   using assms unfolding Quotient_alt_def2
   180   unfolding fun_rel_def fun_eq_iff map_fun_apply
   181   by (safe, metis+)
   182 
   183 lemma apply_rsp:
   184   fixes f g::"'a \<Rightarrow> 'c"
   185   assumes q: "Quotient R1 Abs1 Rep1 T1"
   186   and     a: "(R1 ===> R2) f g" "R1 x y"
   187   shows "R2 (f x) (g y)"
   188   using a by (auto elim: fun_relE)
   189 
   190 lemma apply_rsp':
   191   assumes a: "(R1 ===> R2) f g" "R1 x y"
   192   shows "R2 (f x) (g y)"
   193   using a by (auto elim: fun_relE)
   194 
   195 lemma apply_rsp'':
   196   assumes "Quotient R Abs Rep T"
   197   and "(R ===> S) f f"
   198   shows "S (f (Rep x)) (f (Rep x))"
   199 proof -
   200   from assms(1) have "R (Rep x) (Rep x)" by (rule Quotient_rep_reflp)
   201   then show ?thesis using assms(2) by (auto intro: apply_rsp')
   202 qed
   203 
   204 subsection {* Quotient composition *}
   205 
   206 lemma Quotient_compose:
   207   assumes 1: "Quotient R1 Abs1 Rep1 T1"
   208   assumes 2: "Quotient R2 Abs2 Rep2 T2"
   209   shows "Quotient (T1 OO R2 OO conversep T1) (Abs2 \<circ> Abs1) (Rep1 \<circ> Rep2) (T1 OO T2)"
   210   using assms unfolding Quotient_alt_def4 by fastforce
   211 
   212 lemma equivp_reflp2:
   213   "equivp R \<Longrightarrow> reflp R"
   214   by (erule equivpE)
   215 
   216 subsection {* Respects predicate *}
   217 
   218 definition Respects :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a set"
   219   where "Respects R = {x. R x x}"
   220 
   221 lemma in_respects: "x \<in> Respects R \<longleftrightarrow> R x x"
   222   unfolding Respects_def by simp
   223 
   224 subsection {* Invariant *}
   225 
   226 definition invariant :: "('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" 
   227   where "invariant R = (\<lambda>x y. R x \<and> x = y)"
   228 
   229 lemma invariant_to_eq:
   230   assumes "invariant P x y"
   231   shows "x = y"
   232 using assms by (simp add: invariant_def)
   233 
   234 lemma fun_rel_eq_invariant:
   235   shows "((invariant R) ===> S) = (\<lambda>f g. \<forall>x. R x \<longrightarrow> S (f x) (g x))"
   236 by (auto simp add: invariant_def fun_rel_def)
   237 
   238 lemma invariant_same_args:
   239   shows "invariant P x x \<equiv> P x"
   240 using assms by (auto simp add: invariant_def)
   241 
   242 lemma UNIV_typedef_to_Quotient:
   243   assumes "type_definition Rep Abs UNIV"
   244   and T_def: "T \<equiv> (\<lambda>x y. x = Rep y)"
   245   shows "Quotient (op =) Abs Rep T"
   246 proof -
   247   interpret type_definition Rep Abs UNIV by fact
   248   from Abs_inject Rep_inverse Abs_inverse T_def show ?thesis 
   249     by (fastforce intro!: QuotientI fun_eq_iff)
   250 qed
   251 
   252 lemma UNIV_typedef_to_equivp:
   253   fixes Abs :: "'a \<Rightarrow> 'b"
   254   and Rep :: "'b \<Rightarrow> 'a"
   255   assumes "type_definition Rep Abs (UNIV::'a set)"
   256   shows "equivp (op=::'a\<Rightarrow>'a\<Rightarrow>bool)"
   257 by (rule identity_equivp)
   258 
   259 lemma typedef_to_Quotient:
   260   assumes "type_definition Rep Abs S"
   261   and T_def: "T \<equiv> (\<lambda>x y. x = Rep y)"
   262   shows "Quotient (invariant (\<lambda>x. x \<in> S)) Abs Rep T"
   263 proof -
   264   interpret type_definition Rep Abs S by fact
   265   from Rep Abs_inject Rep_inverse Abs_inverse T_def show ?thesis
   266     by (auto intro!: QuotientI simp: invariant_def fun_eq_iff)
   267 qed
   268 
   269 lemma typedef_to_part_equivp:
   270   assumes "type_definition Rep Abs S"
   271   shows "part_equivp (invariant (\<lambda>x. x \<in> S))"
   272 proof (intro part_equivpI)
   273   interpret type_definition Rep Abs S by fact
   274   show "\<exists>x. invariant (\<lambda>x. x \<in> S) x x" using Rep by (auto simp: invariant_def)
   275 next
   276   show "symp (invariant (\<lambda>x. x \<in> S))" by (auto intro: sympI simp: invariant_def)
   277 next
   278   show "transp (invariant (\<lambda>x. x \<in> S))" by (auto intro: transpI simp: invariant_def)
   279 qed
   280 
   281 lemma open_typedef_to_Quotient:
   282   assumes "type_definition Rep Abs {x. P x}"
   283   and T_def: "T \<equiv> (\<lambda>x y. x = Rep y)"
   284   shows "Quotient (invariant P) Abs Rep T"
   285   using typedef_to_Quotient [OF assms] by simp
   286 
   287 lemma open_typedef_to_part_equivp:
   288   assumes "type_definition Rep Abs {x. P x}"
   289   shows "part_equivp (invariant P)"
   290   using typedef_to_part_equivp [OF assms] by simp
   291 
   292 text {* Generating transfer rules for quotients. *}
   293 
   294 context
   295   fixes R Abs Rep T
   296   assumes 1: "Quotient R Abs Rep T"
   297 begin
   298 
   299 lemma Quotient_right_unique: "right_unique T"
   300   using 1 unfolding Quotient_alt_def right_unique_def by metis
   301 
   302 lemma Quotient_right_total: "right_total T"
   303   using 1 unfolding Quotient_alt_def right_total_def by metis
   304 
   305 lemma Quotient_rel_eq_transfer: "(T ===> T ===> op =) R (op =)"
   306   using 1 unfolding Quotient_alt_def fun_rel_def by simp
   307 
   308 lemma Quotient_abs_induct:
   309   assumes "\<And>y. R y y \<Longrightarrow> P (Abs y)" shows "P x"
   310   using 1 assms unfolding Quotient_def by metis
   311 
   312 end
   313 
   314 text {* Generating transfer rules for total quotients. *}
   315 
   316 context
   317   fixes R Abs Rep T
   318   assumes 1: "Quotient R Abs Rep T" and 2: "reflp R"
   319 begin
   320 
   321 lemma Quotient_bi_total: "bi_total T"
   322   using 1 2 unfolding Quotient_alt_def bi_total_def reflp_def by auto
   323 
   324 lemma Quotient_id_abs_transfer: "(op = ===> T) (\<lambda>x. x) Abs"
   325   using 1 2 unfolding Quotient_alt_def reflp_def fun_rel_def by simp
   326 
   327 lemma Quotient_total_abs_induct: "(\<And>y. P (Abs y)) \<Longrightarrow> P x"
   328   using 1 2 assms unfolding Quotient_alt_def reflp_def by metis
   329 
   330 lemma Quotient_total_abs_eq_iff: "Abs x = Abs y \<longleftrightarrow> R x y"
   331   using Quotient_rel [OF 1] 2 unfolding reflp_def by simp
   332 
   333 end
   334 
   335 text {* Generating transfer rules for a type defined with @{text "typedef"}. *}
   336 
   337 context
   338   fixes Rep Abs A T
   339   assumes type: "type_definition Rep Abs A"
   340   assumes T_def: "T \<equiv> (\<lambda>(x::'a) (y::'b). x = Rep y)"
   341 begin
   342 
   343 lemma typedef_left_unique: "left_unique T"
   344   unfolding left_unique_def T_def
   345   by (simp add: type_definition.Rep_inject [OF type])
   346 
   347 lemma typedef_bi_unique: "bi_unique T"
   348   unfolding bi_unique_def T_def
   349   by (simp add: type_definition.Rep_inject [OF type])
   350 
   351 (* the following two theorems are here only for convinience *)
   352 
   353 lemma typedef_right_unique: "right_unique T"
   354   using T_def type Quotient_right_unique typedef_to_Quotient 
   355   by blast
   356 
   357 lemma typedef_right_total: "right_total T"
   358   using T_def type Quotient_right_total typedef_to_Quotient 
   359   by blast
   360 
   361 lemma typedef_rep_transfer: "(T ===> op =) (\<lambda>x. x) Rep"
   362   unfolding fun_rel_def T_def by simp
   363 
   364 end
   365 
   366 text {* Generating the correspondence rule for a constant defined with
   367   @{text "lift_definition"}. *}
   368 
   369 lemma Quotient_to_transfer:
   370   assumes "Quotient R Abs Rep T" and "R c c" and "c' \<equiv> Abs c"
   371   shows "T c c'"
   372   using assms by (auto dest: Quotient_cr_rel)
   373 
   374 text {* Proving reflexivity *}
   375 
   376 definition reflp' :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where "reflp' R \<equiv> reflp R"
   377 
   378 lemma Quotient_to_left_total:
   379   assumes q: "Quotient R Abs Rep T"
   380   and r_R: "reflp R"
   381   shows "left_total T"
   382 using r_R Quotient_cr_rel[OF q] unfolding left_total_def by (auto elim: reflpE)
   383 
   384 lemma reflp_Quotient_composition:
   385   assumes "left_total R"
   386   assumes "reflp T"
   387   shows "reflp (R OO T OO R\<inverse>\<inverse>)"
   388 using assms unfolding reflp_def left_total_def by fast
   389 
   390 lemma reflp_fun1:
   391   assumes "is_equality R"
   392   assumes "reflp' S"
   393   shows "reflp (R ===> S)"
   394 using assms unfolding is_equality_def reflp'_def reflp_def fun_rel_def by blast
   395 
   396 lemma reflp_fun2:
   397   assumes "is_equality R"
   398   assumes "is_equality S"
   399   shows "reflp (R ===> S)"
   400 using assms unfolding is_equality_def reflp_def fun_rel_def by blast
   401 
   402 lemma is_equality_Quotient_composition:
   403   assumes "is_equality T"
   404   assumes "left_total R"
   405   assumes "left_unique R"
   406   shows "is_equality (R OO T OO R\<inverse>\<inverse>)"
   407 using assms unfolding is_equality_def left_total_def left_unique_def OO_def conversep_iff
   408 by fastforce
   409 
   410 lemma reflp_equality: "reflp (op =)"
   411 by (auto intro: reflpI)
   412 
   413 text {* Proving a parametrized correspondence relation *}
   414 
   415 lemma eq_OO: "op= OO R = R"
   416 unfolding OO_def by metis
   417 
   418 definition POS :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool" where
   419 "POS A B \<equiv> A \<le> B"
   420 
   421 definition  NEG :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool" where
   422 "NEG A B \<equiv> B \<le> A"
   423 
   424 (*
   425   The following two rules are here because we don't have any proper
   426   left-unique ant left-total relations. Left-unique and left-total
   427   assumptions show up in distributivity rules for the function type.
   428 *)
   429 
   430 lemma bi_unique_left_unique[transfer_rule]: "bi_unique R \<Longrightarrow> left_unique R"
   431 unfolding bi_unique_def left_unique_def by blast
   432 
   433 lemma bi_total_left_total[transfer_rule]: "bi_total R \<Longrightarrow> left_total R"
   434 unfolding bi_total_def left_total_def by blast
   435 
   436 lemma pos_OO_eq:
   437   shows "POS (A OO op=) A"
   438 unfolding POS_def OO_def by blast
   439 
   440 lemma pos_eq_OO:
   441   shows "POS (op= OO A) A"
   442 unfolding POS_def OO_def by blast
   443 
   444 lemma neg_OO_eq:
   445   shows "NEG (A OO op=) A"
   446 unfolding NEG_def OO_def by auto
   447 
   448 lemma neg_eq_OO:
   449   shows "NEG (op= OO A) A"
   450 unfolding NEG_def OO_def by blast
   451 
   452 lemma POS_trans:
   453   assumes "POS A B"
   454   assumes "POS B C"
   455   shows "POS A C"
   456 using assms unfolding POS_def by auto
   457 
   458 lemma NEG_trans:
   459   assumes "NEG A B"
   460   assumes "NEG B C"
   461   shows "NEG A C"
   462 using assms unfolding NEG_def by auto
   463 
   464 lemma POS_NEG:
   465   "POS A B \<equiv> NEG B A"
   466   unfolding POS_def NEG_def by auto
   467 
   468 lemma NEG_POS:
   469   "NEG A B \<equiv> POS B A"
   470   unfolding POS_def NEG_def by auto
   471 
   472 lemma POS_pcr_rule:
   473   assumes "POS (A OO B) C"
   474   shows "POS (A OO B OO X) (C OO X)"
   475 using assms unfolding POS_def OO_def by blast
   476 
   477 lemma NEG_pcr_rule:
   478   assumes "NEG (A OO B) C"
   479   shows "NEG (A OO B OO X) (C OO X)"
   480 using assms unfolding NEG_def OO_def by blast
   481 
   482 lemma POS_apply:
   483   assumes "POS R R'"
   484   assumes "R f g"
   485   shows "R' f g"
   486 using assms unfolding POS_def by auto
   487 
   488 text {* Proving a parametrized correspondence relation *}
   489 
   490 lemma fun_mono:
   491   assumes "A \<ge> C"
   492   assumes "B \<le> D"
   493   shows   "(A ===> B) \<le> (C ===> D)"
   494 using assms unfolding fun_rel_def by blast
   495 
   496 lemma pos_fun_distr: "((R ===> S) OO (R' ===> S')) \<le> ((R OO R') ===> (S OO S'))"
   497 unfolding OO_def fun_rel_def by blast
   498 
   499 lemma functional_relation: "right_unique R \<Longrightarrow> left_total R \<Longrightarrow> \<forall>x. \<exists>!y. R x y"
   500 unfolding right_unique_def left_total_def by blast
   501 
   502 lemma functional_converse_relation: "left_unique R \<Longrightarrow> right_total R \<Longrightarrow> \<forall>y. \<exists>!x. R x y"
   503 unfolding left_unique_def right_total_def by blast
   504 
   505 lemma neg_fun_distr1:
   506 assumes 1: "left_unique R" "right_total R"
   507 assumes 2: "right_unique R'" "left_total R'"
   508 shows "(R OO R' ===> S OO S') \<le> ((R ===> S) OO (R' ===> S')) "
   509   using functional_relation[OF 2] functional_converse_relation[OF 1]
   510   unfolding fun_rel_def OO_def
   511   apply clarify
   512   apply (subst all_comm)
   513   apply (subst all_conj_distrib[symmetric])
   514   apply (intro choice)
   515   by metis
   516 
   517 lemma neg_fun_distr2:
   518 assumes 1: "right_unique R'" "left_total R'"
   519 assumes 2: "left_unique S'" "right_total S'"
   520 shows "(R OO R' ===> S OO S') \<le> ((R ===> S) OO (R' ===> S'))"
   521   using functional_converse_relation[OF 2] functional_relation[OF 1]
   522   unfolding fun_rel_def OO_def
   523   apply clarify
   524   apply (subst all_comm)
   525   apply (subst all_conj_distrib[symmetric])
   526   apply (intro choice)
   527   by metis
   528 
   529 subsection {* Domains *}
   530 
   531 lemma pcr_Domainp_par_left_total:
   532   assumes "Domainp B = P"
   533   assumes "left_total A"
   534   assumes "(A ===> op=) P' P"
   535   shows "Domainp (A OO B) = P'"
   536 using assms
   537 unfolding Domainp_iff[abs_def] OO_def bi_unique_def left_total_def fun_rel_def 
   538 by (fast intro: fun_eq_iff)
   539 
   540 lemma pcr_Domainp_par:
   541 assumes "Domainp B = P2"
   542 assumes "Domainp A = P1"
   543 assumes "(A ===> op=) P2' P2"
   544 shows "Domainp (A OO B) = (inf P1 P2')"
   545 using assms unfolding fun_rel_def Domainp_iff[abs_def] OO_def
   546 by (fast intro: fun_eq_iff)
   547 
   548 definition rel_pred_comp :: "('a => 'b => bool) => ('b => bool) => 'a => bool"  (infixr "OP" 75)
   549 where "rel_pred_comp R P \<equiv> \<lambda>x. \<exists>y. R x y \<and> P y"
   550 
   551 lemma pcr_Domainp:
   552 assumes "Domainp B = P"
   553 shows "Domainp (A OO B) = (A OP P)"
   554 using assms unfolding rel_pred_comp_def by blast
   555 
   556 lemma pcr_Domainp_total:
   557   assumes "bi_total B"
   558   assumes "Domainp A = P"
   559   shows "Domainp (A OO B) = P"
   560 using assms unfolding bi_total_def 
   561 by fast
   562 
   563 lemma Quotient_to_Domainp:
   564   assumes "Quotient R Abs Rep T"
   565   shows "Domainp T = (\<lambda>x. R x x)"  
   566 by (simp add: Domainp_iff[abs_def] Quotient_cr_rel[OF assms])
   567 
   568 lemma invariant_to_Domainp:
   569   assumes "Quotient (Lifting.invariant P) Abs Rep T"
   570   shows "Domainp T = P"
   571 by (simp add: invariant_def Domainp_iff[abs_def] Quotient_cr_rel[OF assms])
   572 
   573 subsection {* ML setup *}
   574 
   575 ML_file "Tools/Lifting/lifting_util.ML"
   576 
   577 ML_file "Tools/Lifting/lifting_info.ML"
   578 setup Lifting_Info.setup
   579 
   580 lemmas [reflexivity_rule] = 
   581   reflp_equality reflp_Quotient_composition is_equality_Quotient_composition
   582 
   583 text {* add @{thm reflp_fun1} and @{thm reflp_fun2} manually through ML
   584   because we don't want to get reflp' variant of these theorems *}
   585 
   586 setup{*
   587 Context.theory_map 
   588   (fold
   589     (snd oo (Thm.apply_attribute Lifting_Info.add_reflexivity_rule_raw_attribute)) 
   590       [@{thm reflp_fun1}, @{thm reflp_fun2}])
   591 *}
   592 
   593 (* setup for the function type *)
   594 declare fun_quotient[quot_map]
   595 declare fun_mono[relator_mono]
   596 lemmas [relator_distr] = pos_fun_distr neg_fun_distr1 neg_fun_distr2
   597 
   598 ML_file "Tools/Lifting/lifting_term.ML"
   599 
   600 ML_file "Tools/Lifting/lifting_def.ML"
   601 
   602 ML_file "Tools/Lifting/lifting_setup.ML"
   603 
   604 hide_const (open) invariant POS NEG reflp'
   605 
   606 end