src/HOL/Library/Quotient_List.thy
author bulwahn
Tue Oct 19 12:26:37 2010 +0200 (2010-10-19)
changeset 40032 5f78dfb2fa7d
parent 39302 d7728f65b353
child 40463 75e544159549
permissions -rw-r--r--
removing something that probably slipped into the Quotient_List theory
     1 (*  Title:      HOL/Library/Quotient_List.thy
     2     Author:     Cezary Kaliszyk and Christian Urban
     3 *)
     4 
     5 header {* Quotient infrastructure for the list type *}
     6 
     7 theory Quotient_List
     8 imports Main Quotient_Syntax
     9 begin
    10 
    11 declare [[map list = (map, list_all2)]]
    12 
    13 lemma split_list_all:
    14   shows "(\<forall>x. P x) \<longleftrightarrow> P [] \<and> (\<forall>x xs. P (x#xs))"
    15   apply(auto)
    16   apply(case_tac x)
    17   apply(simp_all)
    18   done
    19 
    20 lemma map_id[id_simps]:
    21   shows "map id = id"
    22   apply(simp add: fun_eq_iff)
    23   apply(rule allI)
    24   apply(induct_tac x)
    25   apply(simp_all)
    26   done
    27 
    28 lemma list_all2_reflp:
    29   shows "equivp R \<Longrightarrow> list_all2 R xs xs"
    30   by (induct xs, simp_all add: equivp_reflp)
    31 
    32 lemma list_all2_symp:
    33   assumes a: "equivp R"
    34   and b: "list_all2 R xs ys"
    35   shows "list_all2 R ys xs"
    36   using list_all2_lengthD[OF b] b
    37   apply(induct xs ys rule: list_induct2)
    38   apply(simp_all)
    39   apply(rule equivp_symp[OF a])
    40   apply(simp)
    41   done
    42 
    43 lemma list_all2_transp:
    44   assumes a: "equivp R"
    45   and b: "list_all2 R xs1 xs2"
    46   and c: "list_all2 R xs2 xs3"
    47   shows "list_all2 R xs1 xs3"
    48   using list_all2_lengthD[OF b] list_all2_lengthD[OF c] b c
    49   apply(induct rule: list_induct3)
    50   apply(simp_all)
    51   apply(auto intro: equivp_transp[OF a])
    52   done
    53 
    54 lemma list_equivp[quot_equiv]:
    55   assumes a: "equivp R"
    56   shows "equivp (list_all2 R)"
    57   apply (intro equivpI)
    58   unfolding reflp_def symp_def transp_def
    59   apply(simp add: list_all2_reflp[OF a])
    60   apply(blast intro: list_all2_symp[OF a])
    61   apply(blast intro: list_all2_transp[OF a])
    62   done
    63 
    64 lemma list_all2_rel:
    65   assumes q: "Quotient R Abs Rep"
    66   shows "list_all2 R r s = (list_all2 R r r \<and> list_all2 R s s \<and> (map Abs r = map Abs s))"
    67   apply(induct r s rule: list_induct2')
    68   apply(simp_all)
    69   using Quotient_rel[OF q]
    70   apply(metis)
    71   done
    72 
    73 lemma list_quotient[quot_thm]:
    74   assumes q: "Quotient R Abs Rep"
    75   shows "Quotient (list_all2 R) (map Abs) (map Rep)"
    76   unfolding Quotient_def
    77   apply(subst split_list_all)
    78   apply(simp add: Quotient_abs_rep[OF q] abs_o_rep[OF q] map_id)
    79   apply(intro conjI allI)
    80   apply(induct_tac a)
    81   apply(simp_all add: Quotient_rep_reflp[OF q])
    82   apply(rule list_all2_rel[OF q])
    83   done
    84 
    85 lemma cons_prs_aux:
    86   assumes q: "Quotient R Abs Rep"
    87   shows "(map Abs) ((Rep h) # (map Rep t)) = h # t"
    88   by (induct t) (simp_all add: Quotient_abs_rep[OF q])
    89 
    90 lemma cons_prs[quot_preserve]:
    91   assumes q: "Quotient R Abs Rep"
    92   shows "(Rep ---> (map Rep) ---> (map Abs)) (op #) = (op #)"
    93   by (simp only: fun_eq_iff fun_map_def cons_prs_aux[OF q])
    94      (simp)
    95 
    96 lemma cons_rsp[quot_respect]:
    97   assumes q: "Quotient R Abs Rep"
    98   shows "(R ===> list_all2 R ===> list_all2 R) (op #) (op #)"
    99   by (auto)
   100 
   101 lemma nil_prs[quot_preserve]:
   102   assumes q: "Quotient R Abs Rep"
   103   shows "map Abs [] = []"
   104   by simp
   105 
   106 lemma nil_rsp[quot_respect]:
   107   assumes q: "Quotient R Abs Rep"
   108   shows "list_all2 R [] []"
   109   by simp
   110 
   111 lemma map_prs_aux:
   112   assumes a: "Quotient R1 abs1 rep1"
   113   and     b: "Quotient R2 abs2 rep2"
   114   shows "(map abs2) (map ((abs1 ---> rep2) f) (map rep1 l)) = map f l"
   115   by (induct l)
   116      (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
   117 
   118 lemma map_prs[quot_preserve]:
   119   assumes a: "Quotient R1 abs1 rep1"
   120   and     b: "Quotient R2 abs2 rep2"
   121   shows "((abs1 ---> rep2) ---> (map rep1) ---> (map abs2)) map = map"
   122   and   "((abs1 ---> id) ---> map rep1 ---> id) map = map"
   123   by (simp_all only: fun_eq_iff fun_map_def map_prs_aux[OF a b])
   124      (simp_all add: Quotient_abs_rep[OF a])
   125 
   126 lemma map_rsp[quot_respect]:
   127   assumes q1: "Quotient R1 Abs1 Rep1"
   128   and     q2: "Quotient R2 Abs2 Rep2"
   129   shows "((R1 ===> R2) ===> (list_all2 R1) ===> list_all2 R2) map map"
   130   and   "((R1 ===> op =) ===> (list_all2 R1) ===> op =) map map"
   131   apply simp_all
   132   apply(rule_tac [!] allI)+
   133   apply(rule_tac [!] impI)
   134   apply(rule_tac [!] allI)+
   135   apply (induct_tac [!] xa ya rule: list_induct2')
   136   apply simp_all
   137   done
   138 
   139 lemma foldr_prs_aux:
   140   assumes a: "Quotient R1 abs1 rep1"
   141   and     b: "Quotient R2 abs2 rep2"
   142   shows "abs2 (foldr ((abs1 ---> abs2 ---> rep2) f) (map rep1 l) (rep2 e)) = foldr f l e"
   143   by (induct l) (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
   144 
   145 lemma foldr_prs[quot_preserve]:
   146   assumes a: "Quotient R1 abs1 rep1"
   147   and     b: "Quotient R2 abs2 rep2"
   148   shows "((abs1 ---> abs2 ---> rep2) ---> (map rep1) ---> rep2 ---> abs2) foldr = foldr"
   149   by (simp only: fun_eq_iff fun_map_def foldr_prs_aux[OF a b])
   150      (simp)
   151 
   152 lemma foldl_prs_aux:
   153   assumes a: "Quotient R1 abs1 rep1"
   154   and     b: "Quotient R2 abs2 rep2"
   155   shows "abs1 (foldl ((abs1 ---> abs2 ---> rep1) f) (rep1 e) (map rep2 l)) = foldl f e l"
   156   by (induct l arbitrary:e) (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
   157 
   158 
   159 lemma foldl_prs[quot_preserve]:
   160   assumes a: "Quotient R1 abs1 rep1"
   161   and     b: "Quotient R2 abs2 rep2"
   162   shows "((abs1 ---> abs2 ---> rep1) ---> rep1 ---> (map rep2) ---> abs1) foldl = foldl"
   163   by (simp only: fun_eq_iff fun_map_def foldl_prs_aux[OF a b])
   164      (simp)
   165 
   166 lemma list_all2_empty:
   167   shows "list_all2 R [] b \<Longrightarrow> length b = 0"
   168   by (induct b) (simp_all)
   169 
   170 (* induct_tac doesn't accept 'arbitrary', so we manually 'spec' *)
   171 lemma foldl_rsp[quot_respect]:
   172   assumes q1: "Quotient R1 Abs1 Rep1"
   173   and     q2: "Quotient R2 Abs2 Rep2"
   174   shows "((R1 ===> R2 ===> R1) ===> R1 ===> list_all2 R2 ===> R1) foldl foldl"
   175   apply(auto)
   176   apply (subgoal_tac "R1 xa ya \<longrightarrow> list_all2 R2 xb yb \<longrightarrow> R1 (foldl x xa xb) (foldl y ya yb)")
   177   apply simp
   178   apply (rule_tac x="xa" in spec)
   179   apply (rule_tac x="ya" in spec)
   180   apply (rule_tac xs="xb" and ys="yb" in list_induct2)
   181   apply (rule list_all2_lengthD)
   182   apply (simp_all)
   183   done
   184 
   185 lemma foldr_rsp[quot_respect]:
   186   assumes q1: "Quotient R1 Abs1 Rep1"
   187   and     q2: "Quotient R2 Abs2 Rep2"
   188   shows "((R1 ===> R2 ===> R2) ===> list_all2 R1 ===> R2 ===> R2) foldr foldr"
   189   apply auto
   190   apply(subgoal_tac "R2 xb yb \<longrightarrow> list_all2 R1 xa ya \<longrightarrow> R2 (foldr x xa xb) (foldr y ya yb)")
   191   apply simp
   192   apply (rule_tac xs="xa" and ys="ya" in list_induct2)
   193   apply (rule list_all2_lengthD)
   194   apply (simp_all)
   195   done
   196 
   197 lemma list_all2_rsp:
   198   assumes r: "\<forall>x y. R x y \<longrightarrow> (\<forall>a b. R a b \<longrightarrow> S x a = T y b)"
   199   and l1: "list_all2 R x y"
   200   and l2: "list_all2 R a b"
   201   shows "list_all2 S x a = list_all2 T y b"
   202   proof -
   203     have a: "length y = length x" by (rule list_all2_lengthD[OF l1, symmetric])
   204     have c: "length a = length b" by (rule list_all2_lengthD[OF l2])
   205     show ?thesis proof (cases "length x = length a")
   206       case True
   207       have b: "length x = length a" by fact
   208       show ?thesis using a b c r l1 l2 proof (induct rule: list_induct4)
   209         case Nil
   210         show ?case using assms by simp
   211       next
   212         case (Cons h t)
   213         then show ?case by auto
   214       qed
   215     next
   216       case False
   217       have d: "length x \<noteq> length a" by fact
   218       then have e: "\<not>list_all2 S x a" using list_all2_lengthD by auto
   219       have "length y \<noteq> length b" using d a c by simp
   220       then have "\<not>list_all2 T y b" using list_all2_lengthD by auto
   221       then show ?thesis using e by simp
   222     qed
   223   qed
   224 
   225 lemma[quot_respect]:
   226   "((R ===> R ===> op =) ===> list_all2 R ===> list_all2 R ===> op =) list_all2 list_all2"
   227   by (simp add: list_all2_rsp)
   228 
   229 lemma[quot_preserve]:
   230   assumes a: "Quotient R abs1 rep1"
   231   shows "((abs1 ---> abs1 ---> id) ---> map rep1 ---> map rep1 ---> id) list_all2 = list_all2"
   232   apply (simp add: fun_eq_iff)
   233   apply clarify
   234   apply (induct_tac xa xb rule: list_induct2')
   235   apply (simp_all add: Quotient_abs_rep[OF a])
   236   done
   237 
   238 lemma[quot_preserve]:
   239   assumes a: "Quotient R abs1 rep1"
   240   shows "(list_all2 ((rep1 ---> rep1 ---> id) R) l m) = (l = m)"
   241   by (induct l m rule: list_induct2') (simp_all add: Quotient_rel_rep[OF a])
   242 
   243 lemma list_all2_eq[id_simps]:
   244   shows "(list_all2 (op =)) = (op =)"
   245   unfolding fun_eq_iff
   246   apply(rule allI)+
   247   apply(induct_tac x xa rule: list_induct2')
   248   apply(simp_all)
   249   done
   250 
   251 lemma list_all2_find_element:
   252   assumes a: "x \<in> set a"
   253   and b: "list_all2 R a b"
   254   shows "\<exists>y. (y \<in> set b \<and> R x y)"
   255 proof -
   256   have "length a = length b" using b by (rule list_all2_lengthD)
   257   then show ?thesis using a b by (induct a b rule: list_induct2) auto
   258 qed
   259 
   260 lemma list_all2_refl:
   261   assumes a: "\<And>x y. R x y = (R x = R y)"
   262   shows "list_all2 R x x"
   263   by (induct x) (auto simp add: a)
   264 
   265 end