| 41849 |      1 | theory DP_Library
 | 
|  |      2 | imports Main
 | 
|  |      3 | begin
 | 
|  |      4 | 
 | 
|  |      5 | primrec alluopairs:: "'a list \<Rightarrow> ('a \<times> 'a) list" where
 | 
|  |      6 |   "alluopairs [] = []"
 | 
|  |      7 | | "alluopairs (x#xs) = (map (Pair x) (x#xs))@(alluopairs xs)"
 | 
|  |      8 | 
 | 
|  |      9 | lemma alluopairs_set1: "set (alluopairs xs) \<le> {(x,y). x\<in> set xs \<and> y\<in> set xs}"
 | 
|  |     10 | by (induct xs, auto)
 | 
|  |     11 | 
 | 
|  |     12 | lemma alluopairs_set:
 | 
|  |     13 |   "\<lbrakk>x\<in> set xs ; y \<in> set xs\<rbrakk> \<Longrightarrow> (x,y) \<in> set (alluopairs xs) \<or> (y,x) \<in> set (alluopairs xs) "
 | 
|  |     14 | by (induct xs, auto)
 | 
|  |     15 | 
 | 
|  |     16 | lemma alluopairs_bex:
 | 
|  |     17 |   assumes Pc: "\<forall> x \<in> set xs. \<forall>y\<in> set xs. P x y = P y x"
 | 
|  |     18 |   shows "(\<exists> x \<in> set xs. \<exists> y \<in> set xs. P x y) = (\<exists> (x,y) \<in> set (alluopairs xs). P x y)"
 | 
|  |     19 | proof
 | 
|  |     20 |   assume "\<exists>x\<in>set xs. \<exists>y\<in>set xs. P x y"
 | 
|  |     21 |   then obtain x y where x: "x \<in> set xs" and y:"y \<in> set xs" and P: "P x y"  by blast
 | 
|  |     22 |   from alluopairs_set[OF x y] P Pc x y show"\<exists>(x, y)\<in>set (alluopairs xs). P x y" 
 | 
|  |     23 |     by auto
 | 
|  |     24 | next
 | 
|  |     25 |   assume "\<exists>(x, y)\<in>set (alluopairs xs). P x y"
 | 
|  |     26 |   then obtain "x" and "y"  where xy:"(x,y) \<in> set (alluopairs xs)" and P: "P x y" by blast+
 | 
|  |     27 |   from xy have "x \<in> set xs \<and> y\<in> set xs" using alluopairs_set1 by blast
 | 
|  |     28 |   with P show "\<exists>x\<in>set xs. \<exists>y\<in>set xs. P x y" by blast
 | 
|  |     29 | qed
 | 
|  |     30 | 
 | 
|  |     31 | lemma alluopairs_ex:
 | 
|  |     32 |   "\<forall> x y. P x y = P y x \<Longrightarrow>
 | 
|  |     33 |   (\<exists> x \<in> set xs. \<exists> y \<in> set xs. P x y) = (\<exists> (x,y) \<in> set (alluopairs xs). P x y)"
 | 
|  |     34 | by(blast intro!: alluopairs_bex)
 | 
|  |     35 | 
 | 
|  |     36 | end
 |