src/HOL/Decision_Procs/DP_Library.thy
author nipkow
Tue Feb 23 16:25:08 2016 +0100 (2016-02-23)
changeset 62390 842917225d56
parent 55814 aefa1db74d9d
permissions -rw-r--r--
more canonical names
nipkow@41849
     1
theory DP_Library
nipkow@41849
     2
imports Main
nipkow@41849
     3
begin
nipkow@41849
     4
wenzelm@49519
     5
primrec alluopairs:: "'a list \<Rightarrow> ('a \<times> 'a) list"
wenzelm@49519
     6
where
nipkow@41849
     7
  "alluopairs [] = []"
wenzelm@55814
     8
| "alluopairs (x # xs) = map (Pair x) (x # xs) @ alluopairs xs"
nipkow@41849
     9
wenzelm@55814
    10
lemma alluopairs_set1: "set (alluopairs xs) \<le> {(x, y). x\<in> set xs \<and> y\<in> set xs}"
wenzelm@49519
    11
  by (induct xs) auto
nipkow@41849
    12
nipkow@41849
    13
lemma alluopairs_set:
wenzelm@55814
    14
  "x\<in> set xs \<Longrightarrow> y \<in> set xs \<Longrightarrow> (x, y) \<in> set (alluopairs xs) \<or> (y, x) \<in> set (alluopairs xs)"
wenzelm@49519
    15
  by (induct xs) auto
nipkow@41849
    16
nipkow@41849
    17
lemma alluopairs_bex:
wenzelm@55814
    18
  assumes Pc: "\<forall>x \<in> set xs. \<forall>y \<in> set xs. P x y = P y x"
wenzelm@55814
    19
  shows "(\<exists>x \<in> set xs. \<exists>y \<in> set xs. P x y) \<longleftrightarrow> (\<exists>(x, y) \<in> set (alluopairs xs). P x y)"
nipkow@41849
    20
proof
wenzelm@55814
    21
  assume "\<exists>x \<in> set xs. \<exists>y \<in> set xs. P x y"
wenzelm@55814
    22
  then obtain x y where x: "x \<in> set xs" and y: "y \<in> set xs" and P: "P x y"
wenzelm@49519
    23
    by blast
wenzelm@55814
    24
  from alluopairs_set[OF x y] P Pc x y show "\<exists>(x, y) \<in> set (alluopairs xs). P x y" 
nipkow@41849
    25
    by auto
nipkow@41849
    26
next
wenzelm@55814
    27
  assume "\<exists>(x, y) \<in> set (alluopairs xs). P x y"
wenzelm@55814
    28
  then obtain x and y where xy: "(x, y) \<in> set (alluopairs xs)" and P: "P x y"
wenzelm@49519
    29
    by blast+
wenzelm@55814
    30
  from xy have "x \<in> set xs \<and> y \<in> set xs"
wenzelm@55814
    31
    using alluopairs_set1 by blast
nipkow@41849
    32
  with P show "\<exists>x\<in>set xs. \<exists>y\<in>set xs. P x y" by blast
nipkow@41849
    33
qed
nipkow@41849
    34
nipkow@41849
    35
lemma alluopairs_ex:
wenzelm@49519
    36
  "\<forall>x y. P x y = P y x \<Longrightarrow>
wenzelm@55814
    37
    (\<exists>x \<in> set xs. \<exists>y \<in> set xs. P x y) = (\<exists>(x, y) \<in> set (alluopairs xs). P x y)"
wenzelm@49519
    38
  by (blast intro!: alluopairs_bex)
nipkow@41849
    39
nipkow@41849
    40
end