src/HOL/Dense_Linear_Order.thy
author haftmann
Wed Sep 26 20:27:55 2007 +0200 (2007-09-26)
changeset 24728 e2b3a1065676
parent 24679 5b168969ffe0
child 24748 ee0a0eb6b738
permissions -rw-r--r--
moved Finite_Set before Datatype
wenzelm@23453
     1
(*
wenzelm@23453
     2
    ID:         $Id$
wenzelm@23453
     3
    Author:     Amine Chaieb, TU Muenchen
wenzelm@23453
     4
*)
wenzelm@23453
     5
huffman@23470
     6
header {* Dense linear order without endpoints
wenzelm@23453
     7
  and a quantifier elimination procedure in Ferrante and Rackoff style *}
wenzelm@23453
     8
wenzelm@23453
     9
theory Dense_Linear_Order
wenzelm@23453
    10
imports Finite_Set
wenzelm@23453
    11
uses
wenzelm@23466
    12
  "Tools/Qelim/qelim.ML"
chaieb@23902
    13
  "Tools/Qelim/langford_data.ML"
wenzelm@23466
    14
  "Tools/Qelim/ferrante_rackoff_data.ML"
chaieb@23902
    15
  ("Tools/Qelim/langford.ML")
wenzelm@23466
    16
  ("Tools/Qelim/ferrante_rackoff.ML")
wenzelm@23453
    17
begin
wenzelm@23453
    18
chaieb@23902
    19
setup Langford_Data.setup
wenzelm@23453
    20
setup Ferrante_Rackoff_Data.setup
wenzelm@23453
    21
haftmann@24344
    22
context linorder
chaieb@23902
    23
begin
chaieb@23902
    24
haftmann@24344
    25
lemma less_not_permute: "\<not> (x \<sqsubset> y \<and> y \<sqsubset> x)" by (simp add: not_less linear)
chaieb@23902
    26
chaieb@23902
    27
lemma gather_simps: 
chaieb@23902
    28
  shows 
chaieb@23902
    29
  "(\<exists>x. (\<forall>y \<in> L. y \<sqsubset> x) \<and> (\<forall>y \<in> U. x \<sqsubset> y) \<and> x \<sqsubset> u \<and> P x) \<longleftrightarrow> (\<exists>x. (\<forall>y \<in> L. y \<sqsubset> x) \<and> (\<forall>y \<in> (insert u U). x \<sqsubset> y) \<and> P x)"
chaieb@23902
    30
  and "(\<exists>x. (\<forall>y \<in> L. y \<sqsubset> x) \<and> (\<forall>y \<in> U. x \<sqsubset> y) \<and> l \<sqsubset> x \<and> P x) \<longleftrightarrow> (\<exists>x. (\<forall>y \<in> (insert l L). y \<sqsubset> x) \<and> (\<forall>y \<in> U. x \<sqsubset> y) \<and> P x)"
chaieb@23902
    31
  "(\<exists>x. (\<forall>y \<in> L. y \<sqsubset> x) \<and> (\<forall>y \<in> U. x \<sqsubset> y) \<and> x \<sqsubset> u) \<longleftrightarrow> (\<exists>x. (\<forall>y \<in> L. y \<sqsubset> x) \<and> (\<forall>y \<in> (insert u U). x \<sqsubset> y))"
chaieb@23902
    32
  and "(\<exists>x. (\<forall>y \<in> L. y \<sqsubset> x) \<and> (\<forall>y \<in> U. x \<sqsubset> y) \<and> l \<sqsubset> x) \<longleftrightarrow> (\<exists>x. (\<forall>y \<in> (insert l L). y \<sqsubset> x) \<and> (\<forall>y \<in> U. x \<sqsubset> y))"  by auto
chaieb@23902
    33
chaieb@23902
    34
lemma 
chaieb@23902
    35
  gather_start: "(\<exists>x. P x) \<equiv> (\<exists>x. (\<forall>y \<in> {}. y \<^loc>< x) \<and> (\<forall>y\<in> {}. x \<sqsubset> y) \<and> P x)" 
chaieb@23902
    36
  by simp
chaieb@23902
    37
wenzelm@23453
    38
text{* Theorems for @{text "\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (P x \<longleftrightarrow> P\<^bsub>-\<infinity>\<^esub>)"}*}
wenzelm@23453
    39
lemma minf_lt:  "\<exists>z . \<forall>x. x \<sqsubset> z \<longrightarrow> (x \<sqsubset> t \<longleftrightarrow> True)" by auto
wenzelm@23453
    40
lemma minf_gt: "\<exists>z . \<forall>x. x \<sqsubset> z \<longrightarrow>  (t \<sqsubset> x \<longleftrightarrow>  False)"
wenzelm@23453
    41
  by (simp add: not_less) (rule exI[where x="t"], auto simp add: less_le)
wenzelm@23453
    42
wenzelm@23453
    43
lemma minf_le: "\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (x \<sqsubseteq> t \<longleftrightarrow> True)" by (auto simp add: less_le)
wenzelm@23453
    44
lemma minf_ge: "\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (t \<sqsubseteq> x \<longleftrightarrow> False)"
wenzelm@23453
    45
  by (auto simp add: less_le not_less not_le)
wenzelm@23453
    46
lemma minf_eq: "\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (x = t \<longleftrightarrow> False)" by auto
wenzelm@23453
    47
lemma minf_neq: "\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (x \<noteq> t \<longleftrightarrow> True)" by auto
wenzelm@23453
    48
lemma minf_P: "\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (P \<longleftrightarrow> P)" by blast
wenzelm@23453
    49
wenzelm@23453
    50
text{* Theorems for @{text "\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (P x \<longleftrightarrow> P\<^bsub>+\<infinity>\<^esub>)"}*}
wenzelm@23453
    51
lemma pinf_gt:  "\<exists>z . \<forall>x. z \<sqsubset> x \<longrightarrow> (t \<sqsubset> x \<longleftrightarrow> True)" by auto
wenzelm@23453
    52
lemma pinf_lt: "\<exists>z . \<forall>x. z \<sqsubset> x \<longrightarrow>  (x \<sqsubset> t \<longleftrightarrow>  False)"
wenzelm@23453
    53
  by (simp add: not_less) (rule exI[where x="t"], auto simp add: less_le)
wenzelm@23453
    54
wenzelm@23453
    55
lemma pinf_ge: "\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> (t \<sqsubseteq> x \<longleftrightarrow> True)" by (auto simp add: less_le)
wenzelm@23453
    56
lemma pinf_le: "\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> (x \<sqsubseteq> t \<longleftrightarrow> False)"
wenzelm@23453
    57
  by (auto simp add: less_le not_less not_le)
wenzelm@23453
    58
lemma pinf_eq: "\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> (x = t \<longleftrightarrow> False)" by auto
wenzelm@23453
    59
lemma pinf_neq: "\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> (x \<noteq> t \<longleftrightarrow> True)" by auto
wenzelm@23453
    60
lemma pinf_P: "\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> (P \<longleftrightarrow> P)" by blast
wenzelm@23453
    61
wenzelm@23453
    62
lemma nmi_lt: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> x \<sqsubset> t \<longrightarrow>  (\<exists> u\<in> U. u \<sqsubseteq> x)" by auto
wenzelm@23453
    63
lemma nmi_gt: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and> t \<sqsubset> x \<longrightarrow>  (\<exists> u\<in> U. u \<sqsubseteq> x)"
wenzelm@23453
    64
  by (auto simp add: le_less)
wenzelm@23453
    65
lemma  nmi_le: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> x\<sqsubseteq> t \<longrightarrow>  (\<exists> u\<in> U. u \<sqsubseteq> x)" by auto
wenzelm@23453
    66
lemma  nmi_ge: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and> t\<sqsubseteq> x \<longrightarrow>  (\<exists> u\<in> U. u \<sqsubseteq> x)" by auto
wenzelm@23453
    67
lemma  nmi_eq: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and>  x = t \<longrightarrow>  (\<exists> u\<in> U. u \<sqsubseteq> x)" by auto
wenzelm@23453
    68
lemma  nmi_neq: "t \<in> U \<Longrightarrow>\<forall>x. \<not>True \<and> x \<noteq> t \<longrightarrow>  (\<exists> u\<in> U. u \<sqsubseteq> x)" by auto
wenzelm@23453
    69
lemma  nmi_P: "\<forall> x. ~P \<and> P \<longrightarrow>  (\<exists> u\<in> U. u \<sqsubseteq> x)" by auto
wenzelm@23453
    70
lemma  nmi_conj: "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 x \<longrightarrow>  (\<exists> u\<in> U. u \<sqsubseteq> x) ;
wenzelm@23453
    71
  \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow>  (\<exists> u\<in> U. u \<sqsubseteq> x)\<rbrakk> \<Longrightarrow>
wenzelm@23453
    72
  \<forall>x. \<not>(P1' \<and> P2') \<and> (P1 x \<and> P2 x) \<longrightarrow>  (\<exists> u\<in> U. u \<sqsubseteq> x)" by auto
wenzelm@23453
    73
lemma  nmi_disj: "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 x \<longrightarrow>  (\<exists> u\<in> U. u \<sqsubseteq> x) ;
wenzelm@23453
    74
  \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow>  (\<exists> u\<in> U. u \<sqsubseteq> x)\<rbrakk> \<Longrightarrow>
wenzelm@23453
    75
  \<forall>x. \<not>(P1' \<or> P2') \<and> (P1 x \<or> P2 x) \<longrightarrow>  (\<exists> u\<in> U. u \<sqsubseteq> x)" by auto
wenzelm@23453
    76
wenzelm@23453
    77
lemma  npi_lt: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and>  x \<sqsubset> t \<longrightarrow>  (\<exists> u\<in> U. x \<sqsubseteq> u)" by (auto simp add: le_less)
wenzelm@23453
    78
lemma  npi_gt: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> t \<sqsubset> x \<longrightarrow>  (\<exists> u\<in> U. x \<sqsubseteq> u)" by auto
wenzelm@23453
    79
lemma  npi_le: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and>  x \<sqsubseteq> t \<longrightarrow>  (\<exists> u\<in> U. x \<sqsubseteq> u)" by auto
wenzelm@23453
    80
lemma  npi_ge: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> t \<sqsubseteq> x \<longrightarrow>  (\<exists> u\<in> U. x \<sqsubseteq> u)" by auto
wenzelm@23453
    81
lemma  npi_eq: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and>  x = t \<longrightarrow>  (\<exists> u\<in> U. x \<sqsubseteq> u)" by auto
wenzelm@23453
    82
lemma  npi_neq: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> x \<noteq> t \<longrightarrow>  (\<exists> u\<in> U. x \<sqsubseteq> u )" by auto
wenzelm@23453
    83
lemma  npi_P: "\<forall> x. ~P \<and> P \<longrightarrow>  (\<exists> u\<in> U. x \<sqsubseteq> u)" by auto
wenzelm@23453
    84
lemma  npi_conj: "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 x \<longrightarrow>  (\<exists> u\<in> U. x \<sqsubseteq> u) ;  \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow>  (\<exists> u\<in> U. x \<sqsubseteq> u)\<rbrakk>
wenzelm@23453
    85
  \<Longrightarrow>  \<forall>x. \<not>(P1' \<and> P2') \<and> (P1 x \<and> P2 x) \<longrightarrow>  (\<exists> u\<in> U. x \<sqsubseteq> u)" by auto
wenzelm@23453
    86
lemma  npi_disj: "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 x \<longrightarrow>  (\<exists> u\<in> U. x \<sqsubseteq> u) ; \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow>  (\<exists> u\<in> U. x \<sqsubseteq> u)\<rbrakk>
wenzelm@23453
    87
  \<Longrightarrow> \<forall>x. \<not>(P1' \<or> P2') \<and> (P1 x \<or> P2 x) \<longrightarrow>  (\<exists> u\<in> U. x \<sqsubseteq> u)" by auto
wenzelm@23453
    88
wenzelm@23453
    89
lemma lin_dense_lt: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t \<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> x \<sqsubset> t \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> y \<sqsubset> t)"
wenzelm@23453
    90
proof(clarsimp)
wenzelm@23453
    91
  fix x l u y  assume tU: "t \<in> U" and noU: "\<forall>t. l \<sqsubset> t \<and> t \<sqsubset> u \<longrightarrow> t \<notin> U" and lx: "l \<sqsubset> x"
wenzelm@23453
    92
    and xu: "x\<sqsubset>u"  and px: "x \<sqsubset> t" and ly: "l\<sqsubset>y" and yu:"y \<sqsubset> u"
wenzelm@23453
    93
  from tU noU ly yu have tny: "t\<noteq>y" by auto
wenzelm@23453
    94
  {assume H: "t \<sqsubset> y"
wenzelm@23453
    95
    from less_trans[OF lx px] less_trans[OF H yu]
wenzelm@23453
    96
    have "l \<sqsubset> t \<and> t \<sqsubset> u"  by simp
wenzelm@23453
    97
    with tU noU have "False" by auto}
wenzelm@23453
    98
  hence "\<not> t \<sqsubset> y"  by auto hence "y \<sqsubseteq> t" by (simp add: not_less)
wenzelm@23453
    99
  thus "y \<sqsubset> t" using tny by (simp add: less_le)
wenzelm@23453
   100
qed
wenzelm@23453
   101
wenzelm@23453
   102
lemma lin_dense_gt: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l \<sqsubset> x \<and> x \<sqsubset> u \<and> t \<sqsubset> x \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> t \<sqsubset> y)"
wenzelm@23453
   103
proof(clarsimp)
wenzelm@23453
   104
  fix x l u y
wenzelm@23453
   105
  assume tU: "t \<in> U" and noU: "\<forall>t. l \<sqsubset> t \<and> t \<sqsubset> u \<longrightarrow> t \<notin> U" and lx: "l \<sqsubset> x" and xu: "x\<sqsubset>u"
wenzelm@23453
   106
  and px: "t \<sqsubset> x" and ly: "l\<sqsubset>y" and yu:"y \<sqsubset> u"
wenzelm@23453
   107
  from tU noU ly yu have tny: "t\<noteq>y" by auto
wenzelm@23453
   108
  {assume H: "y\<sqsubset> t"
wenzelm@23453
   109
    from less_trans[OF ly H] less_trans[OF px xu] have "l \<sqsubset> t \<and> t \<sqsubset> u" by simp
wenzelm@23453
   110
    with tU noU have "False" by auto}
wenzelm@23453
   111
  hence "\<not> y\<sqsubset>t"  by auto hence "t \<sqsubseteq> y" by (auto simp add: not_less)
wenzelm@23453
   112
  thus "t \<sqsubset> y" using tny by (simp add:less_le)
wenzelm@23453
   113
qed
wenzelm@23453
   114
wenzelm@23453
   115
lemma lin_dense_le: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> x \<sqsubseteq> t \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> y\<sqsubseteq> t)"
wenzelm@23453
   116
proof(clarsimp)
wenzelm@23453
   117
  fix x l u y
wenzelm@23453
   118
  assume tU: "t \<in> U" and noU: "\<forall>t. l \<sqsubset> t \<and> t \<sqsubset> u \<longrightarrow> t \<notin> U" and lx: "l \<sqsubset> x" and xu: "x\<sqsubset>u"
wenzelm@23453
   119
  and px: "x \<sqsubseteq> t" and ly: "l\<sqsubset>y" and yu:"y \<sqsubset> u"
wenzelm@23453
   120
  from tU noU ly yu have tny: "t\<noteq>y" by auto
wenzelm@23453
   121
  {assume H: "t \<sqsubset> y"
wenzelm@23453
   122
    from less_le_trans[OF lx px] less_trans[OF H yu]
wenzelm@23453
   123
    have "l \<sqsubset> t \<and> t \<sqsubset> u" by simp
wenzelm@23453
   124
    with tU noU have "False" by auto}
wenzelm@23453
   125
  hence "\<not> t \<sqsubset> y"  by auto thus "y \<sqsubseteq> t" by (simp add: not_less)
wenzelm@23453
   126
qed
wenzelm@23453
   127
wenzelm@23453
   128
lemma lin_dense_ge: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> t \<sqsubseteq> x \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> t \<sqsubseteq> y)"
wenzelm@23453
   129
proof(clarsimp)
wenzelm@23453
   130
  fix x l u y
wenzelm@23453
   131
  assume tU: "t \<in> U" and noU: "\<forall>t. l \<sqsubset> t \<and> t \<sqsubset> u \<longrightarrow> t \<notin> U" and lx: "l \<sqsubset> x" and xu: "x\<sqsubset>u"
wenzelm@23453
   132
  and px: "t \<sqsubseteq> x" and ly: "l\<sqsubset>y" and yu:"y \<sqsubset> u"
wenzelm@23453
   133
  from tU noU ly yu have tny: "t\<noteq>y" by auto
wenzelm@23453
   134
  {assume H: "y\<sqsubset> t"
wenzelm@23453
   135
    from less_trans[OF ly H] le_less_trans[OF px xu]
wenzelm@23453
   136
    have "l \<sqsubset> t \<and> t \<sqsubset> u" by simp
wenzelm@23453
   137
    with tU noU have "False" by auto}
wenzelm@23453
   138
  hence "\<not> y\<sqsubset>t"  by auto thus "t \<sqsubseteq> y" by (simp add: not_less)
wenzelm@23453
   139
qed
wenzelm@23453
   140
lemma lin_dense_eq: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> x = t   \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> y= t)"  by auto
wenzelm@23453
   141
lemma lin_dense_neq: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> x \<noteq> t   \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> y\<noteq> t)"  by auto
wenzelm@23453
   142
lemma lin_dense_P: "\<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> P   \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> P)"  by auto
wenzelm@23453
   143
wenzelm@23453
   144
lemma lin_dense_conj:
wenzelm@23453
   145
  "\<lbrakk>\<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> P1 x
wenzelm@23453
   146
  \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> P1 y) ;
wenzelm@23453
   147
  \<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> P2 x
wenzelm@23453
   148
  \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> P2 y)\<rbrakk> \<Longrightarrow>
wenzelm@23453
   149
  \<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> (P1 x \<and> P2 x)
wenzelm@23453
   150
  \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> (P1 y \<and> P2 y))"
wenzelm@23453
   151
  by blast
wenzelm@23453
   152
lemma lin_dense_disj:
wenzelm@23453
   153
  "\<lbrakk>\<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> P1 x
wenzelm@23453
   154
  \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> P1 y) ;
wenzelm@23453
   155
  \<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> P2 x
wenzelm@23453
   156
  \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> P2 y)\<rbrakk> \<Longrightarrow>
wenzelm@23453
   157
  \<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> (P1 x \<or> P2 x)
wenzelm@23453
   158
  \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> (P1 y \<or> P2 y))"
wenzelm@23453
   159
  by blast
wenzelm@23453
   160
wenzelm@23453
   161
lemma npmibnd: "\<lbrakk>\<forall>x. \<not> MP \<and> P x \<longrightarrow> (\<exists> u\<in> U. u \<sqsubseteq> x); \<forall>x. \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. x \<sqsubseteq> u)\<rbrakk>
wenzelm@23453
   162
  \<Longrightarrow> \<forall>x. \<not> MP \<and> \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. \<exists> u' \<in> U. u \<sqsubseteq> x \<and> x \<sqsubseteq> u')"
wenzelm@23453
   163
by auto
wenzelm@23453
   164
wenzelm@23453
   165
lemma finite_set_intervals:
wenzelm@23453
   166
  assumes px: "P x" and lx: "l \<sqsubseteq> x" and xu: "x \<sqsubseteq> u" and linS: "l\<in> S"
wenzelm@23453
   167
  and uinS: "u \<in> S" and fS:"finite S" and lS: "\<forall> x\<in> S. l \<sqsubseteq> x" and Su: "\<forall> x\<in> S. x \<sqsubseteq> u"
wenzelm@23453
   168
  shows "\<exists> a \<in> S. \<exists> b \<in> S. (\<forall> y. a \<sqsubset> y \<and> y \<sqsubset> b \<longrightarrow> y \<notin> S) \<and> a \<sqsubseteq> x \<and> x \<sqsubseteq> b \<and> P x"
wenzelm@23453
   169
proof-
wenzelm@23453
   170
  let ?Mx = "{y. y\<in> S \<and> y \<sqsubseteq> x}"
wenzelm@23453
   171
  let ?xM = "{y. y\<in> S \<and> x \<sqsubseteq> y}"
wenzelm@23453
   172
  let ?a = "Max ?Mx"
wenzelm@23453
   173
  let ?b = "Min ?xM"
wenzelm@23453
   174
  have MxS: "?Mx \<subseteq> S" by blast
wenzelm@23453
   175
  hence fMx: "finite ?Mx" using fS finite_subset by auto
wenzelm@23453
   176
  from lx linS have linMx: "l \<in> ?Mx" by blast
wenzelm@23453
   177
  hence Mxne: "?Mx \<noteq> {}" by blast
wenzelm@23453
   178
  have xMS: "?xM \<subseteq> S" by blast
wenzelm@23453
   179
  hence fxM: "finite ?xM" using fS finite_subset by auto
wenzelm@23453
   180
  from xu uinS have linxM: "u \<in> ?xM" by blast
wenzelm@23453
   181
  hence xMne: "?xM \<noteq> {}" by blast
wenzelm@23453
   182
  have ax:"?a \<sqsubseteq> x" using Mxne fMx by auto
wenzelm@23453
   183
  have xb:"x \<sqsubseteq> ?b" using xMne fxM by auto
wenzelm@23453
   184
  have "?a \<in> ?Mx" using Max_in[OF fMx Mxne] by simp hence ainS: "?a \<in> S" using MxS by blast
wenzelm@23453
   185
  have "?b \<in> ?xM" using Min_in[OF fxM xMne] by simp hence binS: "?b \<in> S" using xMS by blast
wenzelm@23453
   186
  have noy:"\<forall> y. ?a \<sqsubset> y \<and> y \<sqsubset> ?b \<longrightarrow> y \<notin> S"
wenzelm@23453
   187
  proof(clarsimp)
wenzelm@23453
   188
    fix y   assume ay: "?a \<sqsubset> y" and yb: "y \<sqsubset> ?b" and yS: "y \<in> S"
wenzelm@23453
   189
    from yS have "y\<in> ?Mx \<or> y\<in> ?xM" by (auto simp add: linear)
wenzelm@23453
   190
    moreover {assume "y \<in> ?Mx" hence "y \<sqsubseteq> ?a" using Mxne fMx by auto with ay have "False" by (simp add: not_le[symmetric])}
wenzelm@23453
   191
    moreover {assume "y \<in> ?xM" hence "?b \<sqsubseteq> y" using xMne fxM by auto with yb have "False" by (simp add: not_le[symmetric])}
wenzelm@23453
   192
    ultimately show "False" by blast
wenzelm@23453
   193
  qed
wenzelm@23453
   194
  from ainS binS noy ax xb px show ?thesis by blast
wenzelm@23453
   195
qed
wenzelm@23453
   196
wenzelm@23453
   197
lemma finite_set_intervals2:
wenzelm@23453
   198
  assumes px: "P x" and lx: "l \<sqsubseteq> x" and xu: "x \<sqsubseteq> u" and linS: "l\<in> S"
wenzelm@23453
   199
  and uinS: "u \<in> S" and fS:"finite S" and lS: "\<forall> x\<in> S. l \<sqsubseteq> x" and Su: "\<forall> x\<in> S. x \<sqsubseteq> u"
wenzelm@23453
   200
  shows "(\<exists> s\<in> S. P s) \<or> (\<exists> a \<in> S. \<exists> b \<in> S. (\<forall> y. a \<sqsubset> y \<and> y \<sqsubset> b \<longrightarrow> y \<notin> S) \<and> a \<sqsubset> x \<and> x \<sqsubset> b \<and> P x)"
wenzelm@23453
   201
proof-
wenzelm@23453
   202
  from finite_set_intervals[where P="P", OF px lx xu linS uinS fS lS Su]
wenzelm@23453
   203
  obtain a and b where
wenzelm@23453
   204
    as: "a\<in> S" and bs: "b\<in> S" and noS:"\<forall>y. a \<sqsubset> y \<and> y \<sqsubset> b \<longrightarrow> y \<notin> S"
wenzelm@23453
   205
    and axb: "a \<sqsubseteq> x \<and> x \<sqsubseteq> b \<and> P x"  by auto
wenzelm@23453
   206
  from axb have "x= a \<or> x= b \<or> (a \<sqsubset> x \<and> x \<sqsubset> b)" by (auto simp add: le_less)
wenzelm@23453
   207
  thus ?thesis using px as bs noS by blast
wenzelm@23453
   208
qed
wenzelm@23453
   209
wenzelm@23453
   210
end
wenzelm@23453
   211
haftmann@24344
   212
section {* The classical QE after Langford for dense linear orders *}
haftmann@24344
   213
haftmann@24422
   214
context dense_linear_order
haftmann@24344
   215
begin
haftmann@24344
   216
haftmann@24344
   217
lemma dlo_qe_bnds: 
haftmann@24344
   218
  assumes ne: "L \<noteq> {}" and neU: "U \<noteq> {}" and fL: "finite L" and fU: "finite U"
haftmann@24344
   219
  shows "(\<exists>x. (\<forall>y \<in> L. y \<sqsubset> x) \<and> (\<forall>y \<in> U. x \<sqsubset> y)) \<equiv> (\<forall> l \<in> L. \<forall>u \<in> U. l \<sqsubset> u)"
haftmann@24344
   220
proof (simp only: atomize_eq, rule iffI)
haftmann@24344
   221
  assume H: "\<exists>x. (\<forall>y\<in>L. y \<^loc>< x) \<and> (\<forall>y\<in>U. x \<^loc>< y)"
haftmann@24344
   222
  then obtain x where xL: "\<forall>y\<in>L. y \<^loc>< x" and xU: "\<forall>y\<in>U. x \<^loc>< y" by blast
haftmann@24344
   223
  {fix l u assume l: "l \<in> L" and u: "u \<in> U"
haftmann@24344
   224
    from less_trans[OF xL[rule_format, OF l] xU[rule_format, OF u]]
haftmann@24344
   225
    have "l \<sqsubset> u" .}
haftmann@24344
   226
  thus "\<forall>l\<in>L. \<forall>u\<in>U. l \<^loc>< u" by blast
haftmann@24344
   227
next
haftmann@24344
   228
  assume H: "\<forall>l\<in>L. \<forall>u\<in>U. l \<^loc>< u"
haftmann@24344
   229
  let ?ML = "Max L"
haftmann@24344
   230
  let ?MU = "Min U"  
haftmann@24344
   231
  from fL ne have th1: "?ML \<in> L" and th1': "\<forall>l\<in>L. l \<sqsubseteq> ?ML" by auto
haftmann@24344
   232
  from fU neU have th2: "?MU \<in> U" and th2': "\<forall>u\<in>U. ?MU \<sqsubseteq> u" by auto
haftmann@24344
   233
  from th1 th2 H have "?ML \<sqsubset> ?MU" by auto
haftmann@24344
   234
  with dense obtain w where th3: "?ML \<sqsubset> w" and th4: "w \<sqsubset> ?MU" by blast
ballarin@24640
   235
  from th3 th1' have "\<forall>l \<in> L. l \<sqsubset> w" by auto
ballarin@24640
   236
  moreover from th4 th2' have "\<forall>u \<in> U. w \<sqsubset> u" by auto
haftmann@24344
   237
  ultimately show "\<exists>x. (\<forall>y\<in>L. y \<^loc>< x) \<and> (\<forall>y\<in>U. x \<^loc>< y)" by auto
haftmann@24344
   238
qed
haftmann@24344
   239
haftmann@24344
   240
lemma dlo_qe_noub: 
haftmann@24344
   241
  assumes ne: "L \<noteq> {}" and fL: "finite L"
haftmann@24344
   242
  shows "(\<exists>x. (\<forall>y \<in> L. y \<sqsubset> x) \<and> (\<forall>y \<in> {}. x \<sqsubset> y)) \<equiv> True"
haftmann@24344
   243
proof(simp add: atomize_eq)
haftmann@24344
   244
  from gt_ex[rule_format, of "Max L"] obtain M where M: "Max L \<sqsubset> M" by blast
haftmann@24344
   245
  from ne fL have "\<forall>x \<in> L. x \<sqsubseteq> Max L" by simp
haftmann@24344
   246
  with M have "\<forall>x\<in>L. x \<sqsubset> M" by (auto intro: le_less_trans)
haftmann@24344
   247
  thus "\<exists>x. \<forall>y\<in>L. y \<^loc>< x" by blast
haftmann@24344
   248
qed
haftmann@24344
   249
haftmann@24344
   250
lemma dlo_qe_nolb: 
haftmann@24344
   251
  assumes ne: "U \<noteq> {}" and fU: "finite U"
haftmann@24344
   252
  shows "(\<exists>x. (\<forall>y \<in> {}. y \<sqsubset> x) \<and> (\<forall>y \<in> U. x \<sqsubset> y)) \<equiv> True"
haftmann@24344
   253
proof(simp add: atomize_eq)
haftmann@24344
   254
  from lt_ex[rule_format, of "Min U"] obtain M where M: "M \<sqsubset> Min U" by blast
haftmann@24344
   255
  from ne fU have "\<forall>x \<in> U. Min U \<sqsubseteq> x" by simp
haftmann@24344
   256
  with M have "\<forall>x\<in>U. M \<sqsubset> x" by (auto intro: less_le_trans)
haftmann@24344
   257
  thus "\<exists>x. \<forall>y\<in>U. x \<^loc>< y" by blast
haftmann@24344
   258
qed
haftmann@24344
   259
haftmann@24344
   260
lemma exists_neq: "\<exists>(x::'a). x \<noteq> t" "\<exists>(x::'a). t \<noteq> x" 
haftmann@24344
   261
  using gt_ex[rule_format, of t] by auto
haftmann@24344
   262
haftmann@24344
   263
lemmas dlo_simps = order_refl less_irrefl not_less not_le exists_neq 
haftmann@24344
   264
  le_less neq_iff linear less_not_permute
haftmann@24344
   265
haftmann@24344
   266
lemma axiom: "dense_linear_order (op \<sqsubseteq>) (op \<sqsubset>)" .
haftmann@24344
   267
lemma atoms: includes meta_term_syntax
haftmann@24344
   268
  shows "TERM (op \<sqsubset> :: 'a \<Rightarrow> _)" and "TERM (op \<sqsubseteq>)" and "TERM (op = :: 'a \<Rightarrow> _)" .
haftmann@24344
   269
haftmann@24344
   270
declare axiom[langford qe: dlo_qe_bnds dlo_qe_nolb dlo_qe_noub gather: gather_start gather_simps atoms: atoms]
haftmann@24344
   271
declare dlo_simps[langfordsimp]
haftmann@24344
   272
haftmann@24344
   273
end
haftmann@24344
   274
haftmann@24344
   275
(* FIXME: Move to HOL -- together with the conj_aci_rule in langford.ML *)
haftmann@24344
   276
lemma dnf:
haftmann@24344
   277
  "(P & (Q | R)) = ((P&Q) | (P&R))" 
haftmann@24344
   278
  "((Q | R) & P) = ((Q&P) | (R&P))"
haftmann@24344
   279
  by blast+
haftmann@24344
   280
haftmann@24344
   281
lemmas weak_dnf_simps = simp_thms dnf
haftmann@24344
   282
haftmann@24344
   283
lemma nnf_simps:
haftmann@24344
   284
    "(\<not>(P \<and> Q)) = (\<not>P \<or> \<not>Q)" "(\<not>(P \<or> Q)) = (\<not>P \<and> \<not>Q)" "(P \<longrightarrow> Q) = (\<not>P \<or> Q)"
haftmann@24344
   285
    "(P = Q) = ((P \<and> Q) \<or> (\<not>P \<and> \<not> Q))" "(\<not> \<not>(P)) = P"
haftmann@24344
   286
  by blast+
haftmann@24344
   287
haftmann@24344
   288
lemma ex_distrib: "(\<exists>x. P x \<or> Q x) \<longleftrightarrow> ((\<exists>x. P x) \<or> (\<exists>x. Q x))" by blast
haftmann@24344
   289
haftmann@24344
   290
lemmas dnf_simps = weak_dnf_simps nnf_simps ex_distrib
haftmann@24344
   291
haftmann@24344
   292
use "Tools/Qelim/langford.ML"
haftmann@24344
   293
method_setup dlo = {*
haftmann@24344
   294
  Method.ctxt_args (Method.SIMPLE_METHOD' o LangfordQE.dlo_tac)
haftmann@24344
   295
*} "Langford's algorithm for quantifier elimination in dense linear orders"
haftmann@24344
   296
haftmann@24344
   297
haftmann@24344
   298
section {* Contructive dense linear orders yield QE for linear arithmetic over ordered Fields -- see @{text "Arith_Tools.thy"} *}
haftmann@24344
   299
wenzelm@23453
   300
text {* Linear order without upper bounds *}
wenzelm@23453
   301
haftmann@24344
   302
class linorder_no_ub = linorder +
chaieb@24398
   303
  assumes gt_ex: "\<exists>y. x \<sqsubset> y"
wenzelm@23453
   304
begin
wenzelm@23453
   305
chaieb@24398
   306
lemma ge_ex: "\<exists>y. x \<sqsubseteq> y" using gt_ex by auto
wenzelm@23453
   307
wenzelm@23453
   308
text {* Theorems for @{text "\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> (P x \<longleftrightarrow> P\<^bsub>+\<infinity>\<^esub>)"} *}
wenzelm@23453
   309
lemma pinf_conj:
wenzelm@23453
   310
  assumes ex1: "\<exists>z1. \<forall>x. z1 \<sqsubset> x \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
wenzelm@23453
   311
  and ex2: "\<exists>z2. \<forall>x. z2 \<sqsubset> x \<longrightarrow> (P2 x \<longleftrightarrow> P2')"
wenzelm@23453
   312
  shows "\<exists>z. \<forall>x. z \<sqsubset>  x \<longrightarrow> ((P1 x \<and> P2 x) \<longleftrightarrow> (P1' \<and> P2'))"
wenzelm@23453
   313
proof-
wenzelm@23453
   314
  from ex1 ex2 obtain z1 and z2 where z1: "\<forall>x. z1 \<sqsubset> x \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
wenzelm@23453
   315
     and z2: "\<forall>x. z2 \<sqsubset> x \<longrightarrow> (P2 x \<longleftrightarrow> P2')" by blast
wenzelm@23453
   316
  from gt_ex obtain z where z:"max z1 z2 \<sqsubset> z" by blast
wenzelm@23453
   317
  from z have zz1: "z1 \<sqsubset> z" and zz2: "z2 \<sqsubset> z" by simp_all
wenzelm@23453
   318
  {fix x assume H: "z \<sqsubset> x"
wenzelm@23453
   319
    from less_trans[OF zz1 H] less_trans[OF zz2 H]
wenzelm@23453
   320
    have "(P1 x \<and> P2 x) \<longleftrightarrow> (P1' \<and> P2')"  using z1 zz1 z2 zz2 by auto
wenzelm@23453
   321
  }
wenzelm@23453
   322
  thus ?thesis by blast
wenzelm@23453
   323
qed
wenzelm@23453
   324
wenzelm@23453
   325
lemma pinf_disj:
wenzelm@23453
   326
  assumes ex1: "\<exists>z1. \<forall>x. z1 \<sqsubset> x \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
wenzelm@23453
   327
  and ex2: "\<exists>z2. \<forall>x. z2 \<sqsubset> x \<longrightarrow> (P2 x \<longleftrightarrow> P2')"
wenzelm@23453
   328
  shows "\<exists>z. \<forall>x. z \<sqsubset>  x \<longrightarrow> ((P1 x \<or> P2 x) \<longleftrightarrow> (P1' \<or> P2'))"
wenzelm@23453
   329
proof-
wenzelm@23453
   330
  from ex1 ex2 obtain z1 and z2 where z1: "\<forall>x. z1 \<sqsubset> x \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
wenzelm@23453
   331
     and z2: "\<forall>x. z2 \<sqsubset> x \<longrightarrow> (P2 x \<longleftrightarrow> P2')" by blast
wenzelm@23453
   332
  from gt_ex obtain z where z:"max z1 z2 \<sqsubset> z" by blast
wenzelm@23453
   333
  from z have zz1: "z1 \<sqsubset> z" and zz2: "z2 \<sqsubset> z" by simp_all
wenzelm@23453
   334
  {fix x assume H: "z \<sqsubset> x"
wenzelm@23453
   335
    from less_trans[OF zz1 H] less_trans[OF zz2 H]
wenzelm@23453
   336
    have "(P1 x \<or> P2 x) \<longleftrightarrow> (P1' \<or> P2')"  using z1 zz1 z2 zz2 by auto
wenzelm@23453
   337
  }
wenzelm@23453
   338
  thus ?thesis by blast
wenzelm@23453
   339
qed
wenzelm@23453
   340
wenzelm@23453
   341
lemma pinf_ex: assumes ex:"\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> (P x \<longleftrightarrow> P1)" and p1: P1 shows "\<exists> x. P x"
wenzelm@23453
   342
proof-
wenzelm@23453
   343
  from ex obtain z where z: "\<forall>x. z \<sqsubset> x \<longrightarrow> (P x \<longleftrightarrow> P1)" by blast
wenzelm@23453
   344
  from gt_ex obtain x where x: "z \<sqsubset> x" by blast
wenzelm@23453
   345
  from z x p1 show ?thesis by blast
wenzelm@23453
   346
qed
wenzelm@23453
   347
wenzelm@23453
   348
end
wenzelm@23453
   349
wenzelm@23453
   350
text {* Linear order without upper bounds *}
wenzelm@23453
   351
haftmann@24344
   352
class linorder_no_lb = linorder +
chaieb@24398
   353
  assumes lt_ex: "\<exists>y. y \<sqsubset> x"
wenzelm@23453
   354
begin
wenzelm@23453
   355
chaieb@24398
   356
lemma le_ex: "\<exists>y. y \<sqsubseteq> x" using lt_ex by auto
wenzelm@23453
   357
wenzelm@23453
   358
wenzelm@23453
   359
text {* Theorems for @{text "\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (P x \<longleftrightarrow> P\<^bsub>-\<infinity>\<^esub>)"} *}
wenzelm@23453
   360
lemma minf_conj:
wenzelm@23453
   361
  assumes ex1: "\<exists>z1. \<forall>x. x \<sqsubset> z1 \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
wenzelm@23453
   362
  and ex2: "\<exists>z2. \<forall>x. x \<sqsubset> z2 \<longrightarrow> (P2 x \<longleftrightarrow> P2')"
wenzelm@23453
   363
  shows "\<exists>z. \<forall>x. x \<sqsubset>  z \<longrightarrow> ((P1 x \<and> P2 x) \<longleftrightarrow> (P1' \<and> P2'))"
wenzelm@23453
   364
proof-
wenzelm@23453
   365
  from ex1 ex2 obtain z1 and z2 where z1: "\<forall>x. x \<sqsubset> z1 \<longrightarrow> (P1 x \<longleftrightarrow> P1')"and z2: "\<forall>x. x \<sqsubset> z2 \<longrightarrow> (P2 x \<longleftrightarrow> P2')" by blast
wenzelm@23453
   366
  from lt_ex obtain z where z:"z \<sqsubset> min z1 z2" by blast
wenzelm@23453
   367
  from z have zz1: "z \<sqsubset> z1" and zz2: "z \<sqsubset> z2" by simp_all
wenzelm@23453
   368
  {fix x assume H: "x \<sqsubset> z"
wenzelm@23453
   369
    from less_trans[OF H zz1] less_trans[OF H zz2]
wenzelm@23453
   370
    have "(P1 x \<and> P2 x) \<longleftrightarrow> (P1' \<and> P2')"  using z1 zz1 z2 zz2 by auto
wenzelm@23453
   371
  }
wenzelm@23453
   372
  thus ?thesis by blast
wenzelm@23453
   373
qed
wenzelm@23453
   374
wenzelm@23453
   375
lemma minf_disj:
wenzelm@23453
   376
  assumes ex1: "\<exists>z1. \<forall>x. x \<sqsubset> z1 \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
wenzelm@23453
   377
  and ex2: "\<exists>z2. \<forall>x. x \<sqsubset> z2 \<longrightarrow> (P2 x \<longleftrightarrow> P2')"
wenzelm@23453
   378
  shows "\<exists>z. \<forall>x. x \<sqsubset>  z \<longrightarrow> ((P1 x \<or> P2 x) \<longleftrightarrow> (P1' \<or> P2'))"
wenzelm@23453
   379
proof-
wenzelm@23453
   380
  from ex1 ex2 obtain z1 and z2 where z1: "\<forall>x. x \<sqsubset> z1 \<longrightarrow> (P1 x \<longleftrightarrow> P1')"and z2: "\<forall>x. x \<sqsubset> z2 \<longrightarrow> (P2 x \<longleftrightarrow> P2')" by blast
wenzelm@23453
   381
  from lt_ex obtain z where z:"z \<sqsubset> min z1 z2" by blast
wenzelm@23453
   382
  from z have zz1: "z \<sqsubset> z1" and zz2: "z \<sqsubset> z2" by simp_all
wenzelm@23453
   383
  {fix x assume H: "x \<sqsubset> z"
wenzelm@23453
   384
    from less_trans[OF H zz1] less_trans[OF H zz2]
wenzelm@23453
   385
    have "(P1 x \<or> P2 x) \<longleftrightarrow> (P1' \<or> P2')"  using z1 zz1 z2 zz2 by auto
wenzelm@23453
   386
  }
wenzelm@23453
   387
  thus ?thesis by blast
wenzelm@23453
   388
qed
wenzelm@23453
   389
wenzelm@23453
   390
lemma minf_ex: assumes ex:"\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (P x \<longleftrightarrow> P1)" and p1: P1 shows "\<exists> x. P x"
wenzelm@23453
   391
proof-
wenzelm@23453
   392
  from ex obtain z where z: "\<forall>x. x \<sqsubset> z \<longrightarrow> (P x \<longleftrightarrow> P1)" by blast
wenzelm@23453
   393
  from lt_ex obtain x where x: "x \<sqsubset> z" by blast
wenzelm@23453
   394
  from z x p1 show ?thesis by blast
wenzelm@23453
   395
qed
wenzelm@23453
   396
wenzelm@23453
   397
end
wenzelm@23453
   398
haftmann@24344
   399
haftmann@24344
   400
class constr_dense_linear_order = linorder_no_lb + linorder_no_ub +
wenzelm@23453
   401
  fixes between
chaieb@24398
   402
  assumes between_less: "x \<sqsubset> y \<Longrightarrow> x \<sqsubset> between x y \<and> between x y \<sqsubset> y"
chaieb@24398
   403
     and  between_same: "between x x = x"
chaieb@23902
   404
haftmann@24344
   405
instance advanced constr_dense_linear_order < dense_linear_order
chaieb@23902
   406
  apply unfold_locales
chaieb@23902
   407
  using gt_ex lt_ex between_less
chaieb@23902
   408
    by (auto, rule_tac x="between x y" in exI, simp)
haftmann@24422
   409
(*FIXME*)
haftmann@24422
   410
lemmas gt_ex = dense_linear_order_class.less_eq_less.gt_ex
haftmann@24422
   411
lemmas lt_ex = dense_linear_order_class.less_eq_less.lt_ex
haftmann@24422
   412
lemmas dense = dense_linear_order_class.less_eq_less.dense
chaieb@23902
   413
chaieb@23902
   414
context constr_dense_linear_order
wenzelm@23453
   415
begin
wenzelm@23453
   416
wenzelm@23453
   417
lemma rinf_U:
wenzelm@23453
   418
  assumes fU: "finite U"
wenzelm@23453
   419
  and lin_dense: "\<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> P x
wenzelm@23453
   420
  \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> P y )"
wenzelm@23453
   421
  and nmpiU: "\<forall>x. \<not> MP \<and> \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. \<exists> u' \<in> U. u \<sqsubseteq> x \<and> x \<sqsubseteq> u')"
wenzelm@23453
   422
  and nmi: "\<not> MP"  and npi: "\<not> PP"  and ex: "\<exists> x.  P x"
wenzelm@23453
   423
  shows "\<exists> u\<in> U. \<exists> u' \<in> U. P (between u u')"
wenzelm@23453
   424
proof-
wenzelm@23453
   425
  from ex obtain x where px: "P x" by blast
wenzelm@23453
   426
  from px nmi npi nmpiU have "\<exists> u\<in> U. \<exists> u' \<in> U. u \<sqsubseteq> x \<and> x \<sqsubseteq> u'" by auto
wenzelm@23453
   427
  then obtain u and u' where uU:"u\<in> U" and uU': "u' \<in> U" and ux:"u \<sqsubseteq> x" and xu':"x \<sqsubseteq> u'" by auto
wenzelm@23453
   428
  from uU have Une: "U \<noteq> {}" by auto
wenzelm@23453
   429
  let ?l = "Min U"
wenzelm@23453
   430
  let ?u = "Max U"
wenzelm@23453
   431
  have linM: "?l \<in> U" using fU Une by simp
wenzelm@23453
   432
  have uinM: "?u \<in> U" using fU Une by simp
wenzelm@23453
   433
  have lM: "\<forall> t\<in> U. ?l \<sqsubseteq> t" using Une fU by auto
wenzelm@23453
   434
  have Mu: "\<forall> t\<in> U. t \<sqsubseteq> ?u" using Une fU by auto
wenzelm@23453
   435
  have th:"?l \<sqsubseteq> u" using uU Une lM by auto
wenzelm@23453
   436
  from order_trans[OF th ux] have lx: "?l \<sqsubseteq> x" .
wenzelm@23453
   437
  have th: "u' \<sqsubseteq> ?u" using uU' Une Mu by simp
wenzelm@23453
   438
  from order_trans[OF xu' th] have xu: "x \<sqsubseteq> ?u" .
wenzelm@23453
   439
  from finite_set_intervals2[where P="P",OF px lx xu linM uinM fU lM Mu]
wenzelm@23453
   440
  have "(\<exists> s\<in> U. P s) \<or>
wenzelm@23453
   441
      (\<exists> t1\<in> U. \<exists> t2 \<in> U. (\<forall> y. t1 \<sqsubset> y \<and> y \<sqsubset> t2 \<longrightarrow> y \<notin> U) \<and> t1 \<sqsubset> x \<and> x \<sqsubset> t2 \<and> P x)" .
wenzelm@23453
   442
  moreover { fix u assume um: "u\<in>U" and pu: "P u"
wenzelm@23453
   443
    have "between u u = u" by (simp add: between_same)
wenzelm@23453
   444
    with um pu have "P (between u u)" by simp
wenzelm@23453
   445
    with um have ?thesis by blast}
wenzelm@23453
   446
  moreover{
wenzelm@23453
   447
    assume "\<exists> t1\<in> U. \<exists> t2 \<in> U. (\<forall> y. t1 \<sqsubset> y \<and> y \<sqsubset> t2 \<longrightarrow> y \<notin> U) \<and> t1 \<sqsubset> x \<and> x \<sqsubset> t2 \<and> P x"
wenzelm@23453
   448
      then obtain t1 and t2 where t1M: "t1 \<in> U" and t2M: "t2\<in> U"
wenzelm@23453
   449
        and noM: "\<forall> y. t1 \<sqsubset> y \<and> y \<sqsubset> t2 \<longrightarrow> y \<notin> U" and t1x: "t1 \<sqsubset> x" and xt2: "x \<sqsubset> t2" and px: "P x"
wenzelm@23453
   450
        by blast
wenzelm@23453
   451
      from less_trans[OF t1x xt2] have t1t2: "t1 \<sqsubset> t2" .
wenzelm@23453
   452
      let ?u = "between t1 t2"
wenzelm@23453
   453
      from between_less t1t2 have t1lu: "t1 \<sqsubset> ?u" and ut2: "?u \<sqsubset> t2" by auto
wenzelm@23453
   454
      from lin_dense[rule_format, OF] noM t1x xt2 px t1lu ut2 have "P ?u" by blast
wenzelm@23453
   455
      with t1M t2M have ?thesis by blast}
wenzelm@23453
   456
    ultimately show ?thesis by blast
wenzelm@23453
   457
  qed
wenzelm@23453
   458
wenzelm@23453
   459
theorem fr_eq:
wenzelm@23453
   460
  assumes fU: "finite U"
wenzelm@23453
   461
  and lin_dense: "\<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> P x
wenzelm@23453
   462
   \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> P y )"
wenzelm@23453
   463
  and nmibnd: "\<forall>x. \<not> MP \<and> P x \<longrightarrow> (\<exists> u\<in> U. u \<sqsubseteq> x)"
wenzelm@23453
   464
  and npibnd: "\<forall>x. \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. x \<sqsubseteq> u)"
wenzelm@23453
   465
  and mi: "\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (P x = MP)"  and pi: "\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> (P x = PP)"
wenzelm@23453
   466
  shows "(\<exists> x. P x) \<equiv> (MP \<or> PP \<or> (\<exists> u \<in> U. \<exists> u'\<in> U. P (between u u')))"
wenzelm@23453
   467
  (is "_ \<equiv> (_ \<or> _ \<or> ?F)" is "?E \<equiv> ?D")
wenzelm@23453
   468
proof-
wenzelm@23453
   469
 {
wenzelm@23453
   470
   assume px: "\<exists> x. P x"
wenzelm@23453
   471
   have "MP \<or> PP \<or> (\<not> MP \<and> \<not> PP)" by blast
wenzelm@23453
   472
   moreover {assume "MP \<or> PP" hence "?D" by blast}
wenzelm@23453
   473
   moreover {assume nmi: "\<not> MP" and npi: "\<not> PP"
wenzelm@23453
   474
     from npmibnd[OF nmibnd npibnd]
wenzelm@23453
   475
     have nmpiU: "\<forall>x. \<not> MP \<and> \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. \<exists> u' \<in> U. u \<sqsubseteq> x \<and> x \<sqsubseteq> u')" .
wenzelm@23453
   476
     from rinf_U[OF fU lin_dense nmpiU nmi npi px] have "?D" by blast}
wenzelm@23453
   477
   ultimately have "?D" by blast}
wenzelm@23453
   478
 moreover
wenzelm@23453
   479
 { assume "?D"
wenzelm@23453
   480
   moreover {assume m:"MP" from minf_ex[OF mi m] have "?E" .}
wenzelm@23453
   481
   moreover {assume p: "PP" from pinf_ex[OF pi p] have "?E" . }
wenzelm@23453
   482
   moreover {assume f:"?F" hence "?E" by blast}
wenzelm@23453
   483
   ultimately have "?E" by blast}
wenzelm@23453
   484
 ultimately have "?E = ?D" by blast thus "?E \<equiv> ?D" by simp
wenzelm@23453
   485
qed
wenzelm@23453
   486
wenzelm@23453
   487
lemmas minf_thms = minf_conj minf_disj minf_eq minf_neq minf_lt minf_le minf_gt minf_ge minf_P
wenzelm@23453
   488
lemmas pinf_thms = pinf_conj pinf_disj pinf_eq pinf_neq pinf_lt pinf_le pinf_gt pinf_ge pinf_P
wenzelm@23453
   489
wenzelm@23453
   490
lemmas nmi_thms = nmi_conj nmi_disj nmi_eq nmi_neq nmi_lt nmi_le nmi_gt nmi_ge nmi_P
wenzelm@23453
   491
lemmas npi_thms = npi_conj npi_disj npi_eq npi_neq npi_lt npi_le npi_gt npi_ge npi_P
wenzelm@23453
   492
lemmas lin_dense_thms = lin_dense_conj lin_dense_disj lin_dense_eq lin_dense_neq lin_dense_lt lin_dense_le lin_dense_gt lin_dense_ge lin_dense_P
wenzelm@23453
   493
chaieb@23902
   494
lemma ferrack_axiom: "constr_dense_linear_order less_eq less between" by fact
wenzelm@23453
   495
lemma atoms: includes meta_term_syntax
wenzelm@23453
   496
  shows "TERM (op \<sqsubset> :: 'a \<Rightarrow> _)" and "TERM (op \<sqsubseteq>)" and "TERM (op = :: 'a \<Rightarrow> _)" .
wenzelm@23453
   497
chaieb@23902
   498
declare ferrack_axiom [ferrack minf: minf_thms pinf: pinf_thms
wenzelm@23453
   499
    nmi: nmi_thms npi: npi_thms lindense:
wenzelm@23453
   500
    lin_dense_thms qe: fr_eq atoms: atoms]
wenzelm@23453
   501
wenzelm@23453
   502
declaration {*
wenzelm@23453
   503
let
chaieb@23902
   504
fun simps phi = map (Morphism.thm phi) [@{thm "not_less"}, @{thm "not_le"}]
wenzelm@23453
   505
fun generic_whatis phi =
wenzelm@23453
   506
 let
wenzelm@24679
   507
  val [lt, le] = map (Morphism.term phi) [@{term "op \<sqsubset>"}, @{term "op \<sqsubseteq>"}]
wenzelm@23453
   508
  fun h x t =
wenzelm@23453
   509
   case term_of t of
wenzelm@23453
   510
     Const("op =", _)$y$z => if term_of x aconv y then Ferrante_Rackoff_Data.Eq
wenzelm@23453
   511
                            else Ferrante_Rackoff_Data.Nox
wenzelm@23453
   512
   | @{term "Not"}$(Const("op =", _)$y$z) => if term_of x aconv y then Ferrante_Rackoff_Data.NEq
wenzelm@23453
   513
                            else Ferrante_Rackoff_Data.Nox
wenzelm@23453
   514
   | b$y$z => if Term.could_unify (b, lt) then
wenzelm@23453
   515
                 if term_of x aconv y then Ferrante_Rackoff_Data.Lt
wenzelm@23453
   516
                 else if term_of x aconv z then Ferrante_Rackoff_Data.Gt
wenzelm@23453
   517
                 else Ferrante_Rackoff_Data.Nox
wenzelm@23453
   518
             else if Term.could_unify (b, le) then
wenzelm@23453
   519
                 if term_of x aconv y then Ferrante_Rackoff_Data.Le
wenzelm@23453
   520
                 else if term_of x aconv z then Ferrante_Rackoff_Data.Ge
wenzelm@23453
   521
                 else Ferrante_Rackoff_Data.Nox
wenzelm@23453
   522
             else Ferrante_Rackoff_Data.Nox
wenzelm@23453
   523
   | _ => Ferrante_Rackoff_Data.Nox
wenzelm@23453
   524
 in h end
chaieb@23902
   525
 fun ss phi = HOL_ss addsimps (simps phi)
wenzelm@23453
   526
in
wenzelm@23453
   527
 Ferrante_Rackoff_Data.funs  @{thm "ferrack_axiom"}
wenzelm@23453
   528
  {isolate_conv = K (K (K Thm.reflexive)), whatis = generic_whatis, simpset = ss}
wenzelm@23453
   529
end
wenzelm@23453
   530
*}
wenzelm@23453
   531
wenzelm@23453
   532
end
wenzelm@23453
   533
wenzelm@23466
   534
use "Tools/Qelim/ferrante_rackoff.ML"
wenzelm@23453
   535
chaieb@23902
   536
method_setup ferrack = {*
wenzelm@23453
   537
  Method.ctxt_args (Method.SIMPLE_METHOD' o FerranteRackoff.dlo_tac)
wenzelm@23453
   538
*} "Ferrante and Rackoff's algorithm for quantifier elimination in dense linear orders"
wenzelm@23453
   539
chaieb@24081
   540
end