src/HOL/Decision_Procs/Dense_Linear_Order.thy
 author huffman Sun Apr 01 16:09:58 2012 +0200 (2012-04-01) changeset 47255 30a1692557b0 parent 47108 2a1953f0d20d child 48891 c0eafbd55de3 permissions -rw-r--r--
removed Nat_Numeral.thy, moving all theorems elsewhere
```     1 (*  Title       : HOL/Decision_Procs/Dense_Linear_Order.thy
```
```     2     Author      : Amine Chaieb, TU Muenchen
```
```     3 *)
```
```     4
```
```     5 header {* Dense linear order without endpoints
```
```     6   and a quantifier elimination procedure in Ferrante and Rackoff style *}
```
```     7
```
```     8 theory Dense_Linear_Order
```
```     9 imports Main
```
```    10 uses
```
```    11   "langford_data.ML"
```
```    12   "ferrante_rackoff_data.ML"
```
```    13   ("langford.ML")
```
```    14   ("ferrante_rackoff.ML")
```
```    15 begin
```
```    16
```
```    17 setup {* Langford_Data.setup #> Ferrante_Rackoff_Data.setup *}
```
```    18
```
```    19 context linorder
```
```    20 begin
```
```    21
```
```    22 lemma less_not_permute[no_atp]: "\<not> (x < y \<and> y < x)" by (simp add: not_less linear)
```
```    23
```
```    24 lemma gather_simps[no_atp]:
```
```    25   shows
```
```    26   "(\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> U. x < y) \<and> x < u \<and> P x) \<longleftrightarrow> (\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> (insert u U). x < y) \<and> P x)"
```
```    27   and "(\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> U. x < y) \<and> l < x \<and> P x) \<longleftrightarrow> (\<exists>x. (\<forall>y \<in> (insert l L). y < x) \<and> (\<forall>y \<in> U. x < y) \<and> P x)"
```
```    28   "(\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> U. x < y) \<and> x < u) \<longleftrightarrow> (\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> (insert u U). x < y))"
```
```    29   and "(\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> U. x < y) \<and> l < x) \<longleftrightarrow> (\<exists>x. (\<forall>y \<in> (insert l L). y < x) \<and> (\<forall>y \<in> U. x < y))"  by auto
```
```    30
```
```    31 lemma
```
```    32   gather_start[no_atp]: "(\<exists>x. P x) \<equiv> (\<exists>x. (\<forall>y \<in> {}. y < x) \<and> (\<forall>y\<in> {}. x < y) \<and> P x)"
```
```    33   by simp
```
```    34
```
```    35 text{* Theorems for @{text "\<exists>z. \<forall>x. x < z \<longrightarrow> (P x \<longleftrightarrow> P\<^bsub>-\<infinity>\<^esub>)"}*}
```
```    36 lemma minf_lt[no_atp]:  "\<exists>z . \<forall>x. x < z \<longrightarrow> (x < t \<longleftrightarrow> True)" by auto
```
```    37 lemma minf_gt[no_atp]: "\<exists>z . \<forall>x. x < z \<longrightarrow>  (t < x \<longleftrightarrow>  False)"
```
```    38   by (simp add: not_less) (rule exI[where x="t"], auto simp add: less_le)
```
```    39
```
```    40 lemma minf_le[no_atp]: "\<exists>z. \<forall>x. x < z \<longrightarrow> (x \<le> t \<longleftrightarrow> True)" by (auto simp add: less_le)
```
```    41 lemma minf_ge[no_atp]: "\<exists>z. \<forall>x. x < z \<longrightarrow> (t \<le> x \<longleftrightarrow> False)"
```
```    42   by (auto simp add: less_le not_less not_le)
```
```    43 lemma minf_eq[no_atp]: "\<exists>z. \<forall>x. x < z \<longrightarrow> (x = t \<longleftrightarrow> False)" by auto
```
```    44 lemma minf_neq[no_atp]: "\<exists>z. \<forall>x. x < z \<longrightarrow> (x \<noteq> t \<longleftrightarrow> True)" by auto
```
```    45 lemma minf_P[no_atp]: "\<exists>z. \<forall>x. x < z \<longrightarrow> (P \<longleftrightarrow> P)" by blast
```
```    46
```
```    47 text{* Theorems for @{text "\<exists>z. \<forall>x. x < z \<longrightarrow> (P x \<longleftrightarrow> P\<^bsub>+\<infinity>\<^esub>)"}*}
```
```    48 lemma pinf_gt[no_atp]:  "\<exists>z . \<forall>x. z < x \<longrightarrow> (t < x \<longleftrightarrow> True)" by auto
```
```    49 lemma pinf_lt[no_atp]: "\<exists>z . \<forall>x. z < x \<longrightarrow>  (x < t \<longleftrightarrow>  False)"
```
```    50   by (simp add: not_less) (rule exI[where x="t"], auto simp add: less_le)
```
```    51
```
```    52 lemma pinf_ge[no_atp]: "\<exists>z. \<forall>x. z < x \<longrightarrow> (t \<le> x \<longleftrightarrow> True)" by (auto simp add: less_le)
```
```    53 lemma pinf_le[no_atp]: "\<exists>z. \<forall>x. z < x \<longrightarrow> (x \<le> t \<longleftrightarrow> False)"
```
```    54   by (auto simp add: less_le not_less not_le)
```
```    55 lemma pinf_eq[no_atp]: "\<exists>z. \<forall>x. z < x \<longrightarrow> (x = t \<longleftrightarrow> False)" by auto
```
```    56 lemma pinf_neq[no_atp]: "\<exists>z. \<forall>x. z < x \<longrightarrow> (x \<noteq> t \<longleftrightarrow> True)" by auto
```
```    57 lemma pinf_P[no_atp]: "\<exists>z. \<forall>x. z < x \<longrightarrow> (P \<longleftrightarrow> P)" by blast
```
```    58
```
```    59 lemma nmi_lt[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> x < t \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)" by auto
```
```    60 lemma nmi_gt[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and> t < x \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)"
```
```    61   by (auto simp add: le_less)
```
```    62 lemma  nmi_le[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> x\<le> t \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)" by auto
```
```    63 lemma  nmi_ge[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and> t\<le> x \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)" by auto
```
```    64 lemma  nmi_eq[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and>  x = t \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)" by auto
```
```    65 lemma  nmi_neq[no_atp]: "t \<in> U \<Longrightarrow>\<forall>x. \<not>True \<and> x \<noteq> t \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)" by auto
```
```    66 lemma  nmi_P[no_atp]: "\<forall> x. ~P \<and> P \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)" by auto
```
```    67 lemma  nmi_conj[no_atp]: "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 x \<longrightarrow>  (\<exists> u\<in> U. u \<le> x) ;
```
```    68   \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)\<rbrakk> \<Longrightarrow>
```
```    69   \<forall>x. \<not>(P1' \<and> P2') \<and> (P1 x \<and> P2 x) \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)" by auto
```
```    70 lemma  nmi_disj[no_atp]: "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 x \<longrightarrow>  (\<exists> u\<in> U. u \<le> x) ;
```
```    71   \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)\<rbrakk> \<Longrightarrow>
```
```    72   \<forall>x. \<not>(P1' \<or> P2') \<and> (P1 x \<or> P2 x) \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)" by auto
```
```    73
```
```    74 lemma  npi_lt[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and>  x < t \<longrightarrow>  (\<exists> u\<in> U. x \<le> u)" by (auto simp add: le_less)
```
```    75 lemma  npi_gt[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> t < x \<longrightarrow>  (\<exists> u\<in> U. x \<le> u)" by auto
```
```    76 lemma  npi_le[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and>  x \<le> t \<longrightarrow>  (\<exists> u\<in> U. x \<le> u)" by auto
```
```    77 lemma  npi_ge[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> t \<le> x \<longrightarrow>  (\<exists> u\<in> U. x \<le> u)" by auto
```
```    78 lemma  npi_eq[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and>  x = t \<longrightarrow>  (\<exists> u\<in> U. x \<le> u)" by auto
```
```    79 lemma  npi_neq[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> x \<noteq> t \<longrightarrow>  (\<exists> u\<in> U. x \<le> u )" by auto
```
```    80 lemma  npi_P[no_atp]: "\<forall> x. ~P \<and> P \<longrightarrow>  (\<exists> u\<in> U. x \<le> u)" by auto
```
```    81 lemma  npi_conj[no_atp]: "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 x \<longrightarrow>  (\<exists> u\<in> U. x \<le> u) ;  \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow>  (\<exists> u\<in> U. x \<le> u)\<rbrakk>
```
```    82   \<Longrightarrow>  \<forall>x. \<not>(P1' \<and> P2') \<and> (P1 x \<and> P2 x) \<longrightarrow>  (\<exists> u\<in> U. x \<le> u)" by auto
```
```    83 lemma  npi_disj[no_atp]: "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 x \<longrightarrow>  (\<exists> u\<in> U. x \<le> u) ; \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow>  (\<exists> u\<in> U. x \<le> u)\<rbrakk>
```
```    84   \<Longrightarrow> \<forall>x. \<not>(P1' \<or> P2') \<and> (P1 x \<or> P2 x) \<longrightarrow>  (\<exists> u\<in> U. x \<le> u)" by auto
```
```    85
```
```    86 lemma lin_dense_lt[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t < u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> x < t \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> y < t)"
```
```    87 proof(clarsimp)
```
```    88   fix x l u y  assume tU: "t \<in> U" and noU: "\<forall>t. l < t \<and> t < u \<longrightarrow> t \<notin> U" and lx: "l < x"
```
```    89     and xu: "x<u"  and px: "x < t" and ly: "l<y" and yu:"y < u"
```
```    90   from tU noU ly yu have tny: "t\<noteq>y" by auto
```
```    91   {assume H: "t < y"
```
```    92     from less_trans[OF lx px] less_trans[OF H yu]
```
```    93     have "l < t \<and> t < u"  by simp
```
```    94     with tU noU have "False" by auto}
```
```    95   hence "\<not> t < y"  by auto hence "y \<le> t" by (simp add: not_less)
```
```    96   thus "y < t" using tny by (simp add: less_le)
```
```    97 qed
```
```    98
```
```    99 lemma lin_dense_gt[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l < x \<and> x < u \<and> t < x \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> t < y)"
```
```   100 proof(clarsimp)
```
```   101   fix x l u y
```
```   102   assume tU: "t \<in> U" and noU: "\<forall>t. l < t \<and> t < u \<longrightarrow> t \<notin> U" and lx: "l < x" and xu: "x<u"
```
```   103   and px: "t < x" and ly: "l<y" and yu:"y < u"
```
```   104   from tU noU ly yu have tny: "t\<noteq>y" by auto
```
```   105   {assume H: "y< t"
```
```   106     from less_trans[OF ly H] less_trans[OF px xu] have "l < t \<and> t < u" by simp
```
```   107     with tU noU have "False" by auto}
```
```   108   hence "\<not> y<t"  by auto hence "t \<le> y" by (auto simp add: not_less)
```
```   109   thus "t < y" using tny by (simp add:less_le)
```
```   110 qed
```
```   111
```
```   112 lemma lin_dense_le[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> x \<le> t \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> y\<le> t)"
```
```   113 proof(clarsimp)
```
```   114   fix x l u y
```
```   115   assume tU: "t \<in> U" and noU: "\<forall>t. l < t \<and> t < u \<longrightarrow> t \<notin> U" and lx: "l < x" and xu: "x<u"
```
```   116   and px: "x \<le> t" and ly: "l<y" and yu:"y < u"
```
```   117   from tU noU ly yu have tny: "t\<noteq>y" by auto
```
```   118   {assume H: "t < y"
```
```   119     from less_le_trans[OF lx px] less_trans[OF H yu]
```
```   120     have "l < t \<and> t < u" by simp
```
```   121     with tU noU have "False" by auto}
```
```   122   hence "\<not> t < y"  by auto thus "y \<le> t" by (simp add: not_less)
```
```   123 qed
```
```   124
```
```   125 lemma lin_dense_ge[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> t \<le> x \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> t \<le> y)"
```
```   126 proof(clarsimp)
```
```   127   fix x l u y
```
```   128   assume tU: "t \<in> U" and noU: "\<forall>t. l < t \<and> t < u \<longrightarrow> t \<notin> U" and lx: "l < x" and xu: "x<u"
```
```   129   and px: "t \<le> x" and ly: "l<y" and yu:"y < u"
```
```   130   from tU noU ly yu have tny: "t\<noteq>y" by auto
```
```   131   {assume H: "y< t"
```
```   132     from less_trans[OF ly H] le_less_trans[OF px xu]
```
```   133     have "l < t \<and> t < u" by simp
```
```   134     with tU noU have "False" by auto}
```
```   135   hence "\<not> y<t"  by auto thus "t \<le> y" by (simp add: not_less)
```
```   136 qed
```
```   137 lemma lin_dense_eq[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> x = t   \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> y= t)"  by auto
```
```   138 lemma lin_dense_neq[no_atp]: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> x \<noteq> t   \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> y\<noteq> t)"  by auto
```
```   139 lemma lin_dense_P[no_atp]: "\<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P   \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P)"  by auto
```
```   140
```
```   141 lemma lin_dense_conj[no_atp]:
```
```   142   "\<lbrakk>\<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P1 x
```
```   143   \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P1 y) ;
```
```   144   \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P2 x
```
```   145   \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P2 y)\<rbrakk> \<Longrightarrow>
```
```   146   \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> (P1 x \<and> P2 x)
```
```   147   \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> (P1 y \<and> P2 y))"
```
```   148   by blast
```
```   149 lemma lin_dense_disj[no_atp]:
```
```   150   "\<lbrakk>\<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P1 x
```
```   151   \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P1 y) ;
```
```   152   \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P2 x
```
```   153   \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P2 y)\<rbrakk> \<Longrightarrow>
```
```   154   \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> (P1 x \<or> P2 x)
```
```   155   \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> (P1 y \<or> P2 y))"
```
```   156   by blast
```
```   157
```
```   158 lemma npmibnd[no_atp]: "\<lbrakk>\<forall>x. \<not> MP \<and> P x \<longrightarrow> (\<exists> u\<in> U. u \<le> x); \<forall>x. \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. x \<le> u)\<rbrakk>
```
```   159   \<Longrightarrow> \<forall>x. \<not> MP \<and> \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. \<exists> u' \<in> U. u \<le> x \<and> x \<le> u')"
```
```   160 by auto
```
```   161
```
```   162 lemma finite_set_intervals[no_atp]:
```
```   163   assumes px: "P x" and lx: "l \<le> x" and xu: "x \<le> u" and linS: "l\<in> S"
```
```   164   and uinS: "u \<in> S" and fS:"finite S" and lS: "\<forall> x\<in> S. l \<le> x" and Su: "\<forall> x\<in> S. x \<le> u"
```
```   165   shows "\<exists> a \<in> S. \<exists> b \<in> S. (\<forall> y. a < y \<and> y < b \<longrightarrow> y \<notin> S) \<and> a \<le> x \<and> x \<le> b \<and> P x"
```
```   166 proof-
```
```   167   let ?Mx = "{y. y\<in> S \<and> y \<le> x}"
```
```   168   let ?xM = "{y. y\<in> S \<and> x \<le> y}"
```
```   169   let ?a = "Max ?Mx"
```
```   170   let ?b = "Min ?xM"
```
```   171   have MxS: "?Mx \<subseteq> S" by blast
```
```   172   hence fMx: "finite ?Mx" using fS finite_subset by auto
```
```   173   from lx linS have linMx: "l \<in> ?Mx" by blast
```
```   174   hence Mxne: "?Mx \<noteq> {}" by blast
```
```   175   have xMS: "?xM \<subseteq> S" by blast
```
```   176   hence fxM: "finite ?xM" using fS finite_subset by auto
```
```   177   from xu uinS have linxM: "u \<in> ?xM" by blast
```
```   178   hence xMne: "?xM \<noteq> {}" by blast
```
```   179   have ax:"?a \<le> x" using Mxne fMx by auto
```
```   180   have xb:"x \<le> ?b" using xMne fxM by auto
```
```   181   have "?a \<in> ?Mx" using Max_in[OF fMx Mxne] by simp hence ainS: "?a \<in> S" using MxS by blast
```
```   182   have "?b \<in> ?xM" using Min_in[OF fxM xMne] by simp hence binS: "?b \<in> S" using xMS by blast
```
```   183   have noy:"\<forall> y. ?a < y \<and> y < ?b \<longrightarrow> y \<notin> S"
```
```   184   proof(clarsimp)
```
```   185     fix y   assume ay: "?a < y" and yb: "y < ?b" and yS: "y \<in> S"
```
```   186     from yS have "y\<in> ?Mx \<or> y\<in> ?xM" by (auto simp add: linear)
```
```   187     moreover {assume "y \<in> ?Mx" hence "y \<le> ?a" using Mxne fMx by auto with ay have "False" by (simp add: not_le[symmetric])}
```
```   188     moreover {assume "y \<in> ?xM" hence "?b \<le> y" using xMne fxM by auto with yb have "False" by (simp add: not_le[symmetric])}
```
```   189     ultimately show "False" by blast
```
```   190   qed
```
```   191   from ainS binS noy ax xb px show ?thesis by blast
```
```   192 qed
```
```   193
```
```   194 lemma finite_set_intervals2[no_atp]:
```
```   195   assumes px: "P x" and lx: "l \<le> x" and xu: "x \<le> u" and linS: "l\<in> S"
```
```   196   and uinS: "u \<in> S" and fS:"finite S" and lS: "\<forall> x\<in> S. l \<le> x" and Su: "\<forall> x\<in> S. x \<le> u"
```
```   197   shows "(\<exists> s\<in> S. P s) \<or> (\<exists> a \<in> S. \<exists> b \<in> S. (\<forall> y. a < y \<and> y < b \<longrightarrow> y \<notin> S) \<and> a < x \<and> x < b \<and> P x)"
```
```   198 proof-
```
```   199   from finite_set_intervals[where P="P", OF px lx xu linS uinS fS lS Su]
```
```   200   obtain a and b where
```
```   201     as: "a\<in> S" and bs: "b\<in> S" and noS:"\<forall>y. a < y \<and> y < b \<longrightarrow> y \<notin> S"
```
```   202     and axb: "a \<le> x \<and> x \<le> b \<and> P x"  by auto
```
```   203   from axb have "x= a \<or> x= b \<or> (a < x \<and> x < b)" by (auto simp add: le_less)
```
```   204   thus ?thesis using px as bs noS by blast
```
```   205 qed
```
```   206
```
```   207 end
```
```   208
```
```   209 section {* The classical QE after Langford for dense linear orders *}
```
```   210
```
```   211 context dense_linorder
```
```   212 begin
```
```   213
```
```   214 lemma interval_empty_iff:
```
```   215   "{y. x < y \<and> y < z} = {} \<longleftrightarrow> \<not> x < z"
```
```   216   by (auto dest: dense)
```
```   217
```
```   218 lemma dlo_qe_bnds[no_atp]:
```
```   219   assumes ne: "L \<noteq> {}" and neU: "U \<noteq> {}" and fL: "finite L" and fU: "finite U"
```
```   220   shows "(\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> U. x < y)) \<equiv> (\<forall> l \<in> L. \<forall>u \<in> U. l < u)"
```
```   221 proof (simp only: atomize_eq, rule iffI)
```
```   222   assume H: "\<exists>x. (\<forall>y\<in>L. y < x) \<and> (\<forall>y\<in>U. x < y)"
```
```   223   then obtain x where xL: "\<forall>y\<in>L. y < x" and xU: "\<forall>y\<in>U. x < y" by blast
```
```   224   {fix l u assume l: "l \<in> L" and u: "u \<in> U"
```
```   225     have "l < x" using xL l by blast
```
```   226     also have "x < u" using xU u by blast
```
```   227     finally (less_trans) have "l < u" .}
```
```   228   thus "\<forall>l\<in>L. \<forall>u\<in>U. l < u" by blast
```
```   229 next
```
```   230   assume H: "\<forall>l\<in>L. \<forall>u\<in>U. l < u"
```
```   231   let ?ML = "Max L"
```
```   232   let ?MU = "Min U"
```
```   233   from fL ne have th1: "?ML \<in> L" and th1': "\<forall>l\<in>L. l \<le> ?ML" by auto
```
```   234   from fU neU have th2: "?MU \<in> U" and th2': "\<forall>u\<in>U. ?MU \<le> u" by auto
```
```   235   from th1 th2 H have "?ML < ?MU" by auto
```
```   236   with dense obtain w where th3: "?ML < w" and th4: "w < ?MU" by blast
```
```   237   from th3 th1' have "\<forall>l \<in> L. l < w" by auto
```
```   238   moreover from th4 th2' have "\<forall>u \<in> U. w < u" by auto
```
```   239   ultimately show "\<exists>x. (\<forall>y\<in>L. y < x) \<and> (\<forall>y\<in>U. x < y)" by auto
```
```   240 qed
```
```   241
```
```   242 lemma dlo_qe_noub[no_atp]:
```
```   243   assumes ne: "L \<noteq> {}" and fL: "finite L"
```
```   244   shows "(\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> {}. x < y)) \<equiv> True"
```
```   245 proof(simp add: atomize_eq)
```
```   246   from gt_ex[of "Max L"] obtain M where M: "Max L < M" by blast
```
```   247   from ne fL have "\<forall>x \<in> L. x \<le> Max L" by simp
```
```   248   with M have "\<forall>x\<in>L. x < M" by (auto intro: le_less_trans)
```
```   249   thus "\<exists>x. \<forall>y\<in>L. y < x" by blast
```
```   250 qed
```
```   251
```
```   252 lemma dlo_qe_nolb[no_atp]:
```
```   253   assumes ne: "U \<noteq> {}" and fU: "finite U"
```
```   254   shows "(\<exists>x. (\<forall>y \<in> {}. y < x) \<and> (\<forall>y \<in> U. x < y)) \<equiv> True"
```
```   255 proof(simp add: atomize_eq)
```
```   256   from lt_ex[of "Min U"] obtain M where M: "M < Min U" by blast
```
```   257   from ne fU have "\<forall>x \<in> U. Min U \<le> x" by simp
```
```   258   with M have "\<forall>x\<in>U. M < x" by (auto intro: less_le_trans)
```
```   259   thus "\<exists>x. \<forall>y\<in>U. x < y" by blast
```
```   260 qed
```
```   261
```
```   262 lemma exists_neq[no_atp]: "\<exists>(x::'a). x \<noteq> t" "\<exists>(x::'a). t \<noteq> x"
```
```   263   using gt_ex[of t] by auto
```
```   264
```
```   265 lemmas dlo_simps[no_atp] = order_refl less_irrefl not_less not_le exists_neq
```
```   266   le_less neq_iff linear less_not_permute
```
```   267
```
```   268 lemma axiom[no_atp]: "class.dense_linorder (op \<le>) (op <)" by (rule dense_linorder_axioms)
```
```   269 lemma atoms[no_atp]:
```
```   270   shows "TERM (less :: 'a \<Rightarrow> _)"
```
```   271     and "TERM (less_eq :: 'a \<Rightarrow> _)"
```
```   272     and "TERM (op = :: 'a \<Rightarrow> _)" .
```
```   273
```
```   274 declare axiom[langford qe: dlo_qe_bnds dlo_qe_nolb dlo_qe_noub gather: gather_start gather_simps atoms: atoms]
```
```   275 declare dlo_simps[langfordsimp]
```
```   276
```
```   277 end
```
```   278
```
```   279 (* FIXME: Move to HOL -- together with the conj_aci_rule in langford.ML *)
```
```   280 lemmas dnf[no_atp] = conj_disj_distribL conj_disj_distribR
```
```   281
```
```   282 lemmas weak_dnf_simps[no_atp] = simp_thms dnf
```
```   283
```
```   284 lemma nnf_simps[no_atp]:
```
```   285     "(\<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)"
```
```   286     "(P = Q) = ((P \<and> Q) \<or> (\<not>P \<and> \<not> Q))" "(\<not> \<not>(P)) = P"
```
```   287   by blast+
```
```   288
```
```   289 lemma ex_distrib[no_atp]: "(\<exists>x. P x \<or> Q x) \<longleftrightarrow> ((\<exists>x. P x) \<or> (\<exists>x. Q x))" by blast
```
```   290
```
```   291 lemmas dnf_simps[no_atp] = weak_dnf_simps nnf_simps ex_distrib
```
```   292
```
```   293 use "langford.ML"
```
```   294 method_setup dlo = {*
```
```   295   Scan.succeed (SIMPLE_METHOD' o LangfordQE.dlo_tac)
```
```   296 *} "Langford's algorithm for quantifier elimination in dense linear orders"
```
```   297
```
```   298
```
```   299 section {* Contructive dense linear orders yield QE for linear arithmetic over ordered Fields *}
```
```   300
```
```   301 text {* Linear order without upper bounds *}
```
```   302
```
```   303 locale linorder_stupid_syntax = linorder
```
```   304 begin
```
```   305 notation
```
```   306   less_eq  ("op \<sqsubseteq>") and
```
```   307   less_eq  ("(_/ \<sqsubseteq> _)" [51, 51] 50) and
```
```   308   less  ("op \<sqsubset>") and
```
```   309   less  ("(_/ \<sqsubset> _)"  [51, 51] 50)
```
```   310
```
```   311 end
```
```   312
```
```   313 locale linorder_no_ub = linorder_stupid_syntax +
```
```   314   assumes gt_ex: "\<exists>y. less x y"
```
```   315 begin
```
```   316 lemma ge_ex[no_atp]: "\<exists>y. x \<sqsubseteq> y" using gt_ex by auto
```
```   317
```
```   318 text {* Theorems for @{text "\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> (P x \<longleftrightarrow> P\<^bsub>+\<infinity>\<^esub>)"} *}
```
```   319 lemma pinf_conj[no_atp]:
```
```   320   assumes ex1: "\<exists>z1. \<forall>x. z1 \<sqsubset> x \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
```
```   321   and ex2: "\<exists>z2. \<forall>x. z2 \<sqsubset> x \<longrightarrow> (P2 x \<longleftrightarrow> P2')"
```
```   322   shows "\<exists>z. \<forall>x. z \<sqsubset>  x \<longrightarrow> ((P1 x \<and> P2 x) \<longleftrightarrow> (P1' \<and> P2'))"
```
```   323 proof-
```
```   324   from ex1 ex2 obtain z1 and z2 where z1: "\<forall>x. z1 \<sqsubset> x \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
```
```   325      and z2: "\<forall>x. z2 \<sqsubset> x \<longrightarrow> (P2 x \<longleftrightarrow> P2')" by blast
```
```   326   from gt_ex obtain z where z:"ord.max less_eq z1 z2 \<sqsubset> z" by blast
```
```   327   from z have zz1: "z1 \<sqsubset> z" and zz2: "z2 \<sqsubset> z" by simp_all
```
```   328   {fix x assume H: "z \<sqsubset> x"
```
```   329     from less_trans[OF zz1 H] less_trans[OF zz2 H]
```
```   330     have "(P1 x \<and> P2 x) \<longleftrightarrow> (P1' \<and> P2')"  using z1 zz1 z2 zz2 by auto
```
```   331   }
```
```   332   thus ?thesis by blast
```
```   333 qed
```
```   334
```
```   335 lemma pinf_disj[no_atp]:
```
```   336   assumes ex1: "\<exists>z1. \<forall>x. z1 \<sqsubset> x \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
```
```   337   and ex2: "\<exists>z2. \<forall>x. z2 \<sqsubset> x \<longrightarrow> (P2 x \<longleftrightarrow> P2')"
```
```   338   shows "\<exists>z. \<forall>x. z \<sqsubset>  x \<longrightarrow> ((P1 x \<or> P2 x) \<longleftrightarrow> (P1' \<or> P2'))"
```
```   339 proof-
```
```   340   from ex1 ex2 obtain z1 and z2 where z1: "\<forall>x. z1 \<sqsubset> x \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
```
```   341      and z2: "\<forall>x. z2 \<sqsubset> x \<longrightarrow> (P2 x \<longleftrightarrow> P2')" by blast
```
```   342   from gt_ex obtain z where z:"ord.max less_eq z1 z2 \<sqsubset> z" by blast
```
```   343   from z have zz1: "z1 \<sqsubset> z" and zz2: "z2 \<sqsubset> z" by simp_all
```
```   344   {fix x assume H: "z \<sqsubset> x"
```
```   345     from less_trans[OF zz1 H] less_trans[OF zz2 H]
```
```   346     have "(P1 x \<or> P2 x) \<longleftrightarrow> (P1' \<or> P2')"  using z1 zz1 z2 zz2 by auto
```
```   347   }
```
```   348   thus ?thesis by blast
```
```   349 qed
```
```   350
```
```   351 lemma pinf_ex[no_atp]: assumes ex:"\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> (P x \<longleftrightarrow> P1)" and p1: P1 shows "\<exists> x. P x"
```
```   352 proof-
```
```   353   from ex obtain z where z: "\<forall>x. z \<sqsubset> x \<longrightarrow> (P x \<longleftrightarrow> P1)" by blast
```
```   354   from gt_ex obtain x where x: "z \<sqsubset> x" by blast
```
```   355   from z x p1 show ?thesis by blast
```
```   356 qed
```
```   357
```
```   358 end
```
```   359
```
```   360 text {* Linear order without upper bounds *}
```
```   361
```
```   362 locale linorder_no_lb = linorder_stupid_syntax +
```
```   363   assumes lt_ex: "\<exists>y. less y x"
```
```   364 begin
```
```   365 lemma le_ex[no_atp]: "\<exists>y. y \<sqsubseteq> x" using lt_ex by auto
```
```   366
```
```   367
```
```   368 text {* Theorems for @{text "\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (P x \<longleftrightarrow> P\<^bsub>-\<infinity>\<^esub>)"} *}
```
```   369 lemma minf_conj[no_atp]:
```
```   370   assumes ex1: "\<exists>z1. \<forall>x. x \<sqsubset> z1 \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
```
```   371   and ex2: "\<exists>z2. \<forall>x. x \<sqsubset> z2 \<longrightarrow> (P2 x \<longleftrightarrow> P2')"
```
```   372   shows "\<exists>z. \<forall>x. x \<sqsubset>  z \<longrightarrow> ((P1 x \<and> P2 x) \<longleftrightarrow> (P1' \<and> P2'))"
```
```   373 proof-
```
```   374   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
```
```   375   from lt_ex obtain z where z:"z \<sqsubset> ord.min less_eq z1 z2" by blast
```
```   376   from z have zz1: "z \<sqsubset> z1" and zz2: "z \<sqsubset> z2" by simp_all
```
```   377   {fix x assume H: "x \<sqsubset> z"
```
```   378     from less_trans[OF H zz1] less_trans[OF H zz2]
```
```   379     have "(P1 x \<and> P2 x) \<longleftrightarrow> (P1' \<and> P2')"  using z1 zz1 z2 zz2 by auto
```
```   380   }
```
```   381   thus ?thesis by blast
```
```   382 qed
```
```   383
```
```   384 lemma minf_disj[no_atp]:
```
```   385   assumes ex1: "\<exists>z1. \<forall>x. x \<sqsubset> z1 \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
```
```   386   and ex2: "\<exists>z2. \<forall>x. x \<sqsubset> z2 \<longrightarrow> (P2 x \<longleftrightarrow> P2')"
```
```   387   shows "\<exists>z. \<forall>x. x \<sqsubset>  z \<longrightarrow> ((P1 x \<or> P2 x) \<longleftrightarrow> (P1' \<or> P2'))"
```
```   388 proof-
```
```   389   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
```
```   390   from lt_ex obtain z where z:"z \<sqsubset> ord.min less_eq z1 z2" by blast
```
```   391   from z have zz1: "z \<sqsubset> z1" and zz2: "z \<sqsubset> z2" by simp_all
```
```   392   {fix x assume H: "x \<sqsubset> z"
```
```   393     from less_trans[OF H zz1] less_trans[OF H zz2]
```
```   394     have "(P1 x \<or> P2 x) \<longleftrightarrow> (P1' \<or> P2')"  using z1 zz1 z2 zz2 by auto
```
```   395   }
```
```   396   thus ?thesis by blast
```
```   397 qed
```
```   398
```
```   399 lemma minf_ex[no_atp]: assumes ex:"\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (P x \<longleftrightarrow> P1)" and p1: P1 shows "\<exists> x. P x"
```
```   400 proof-
```
```   401   from ex obtain z where z: "\<forall>x. x \<sqsubset> z \<longrightarrow> (P x \<longleftrightarrow> P1)" by blast
```
```   402   from lt_ex obtain x where x: "x \<sqsubset> z" by blast
```
```   403   from z x p1 show ?thesis by blast
```
```   404 qed
```
```   405
```
```   406 end
```
```   407
```
```   408
```
```   409 locale constr_dense_linorder = linorder_no_lb + linorder_no_ub +
```
```   410   fixes between
```
```   411   assumes between_less: "less x y \<Longrightarrow> less x (between x y) \<and> less (between x y) y"
```
```   412      and  between_same: "between x x = x"
```
```   413
```
```   414 sublocale  constr_dense_linorder < dense_linorder
```
```   415   apply unfold_locales
```
```   416   using gt_ex lt_ex between_less
```
```   417     by (auto, rule_tac x="between x y" in exI, simp)
```
```   418
```
```   419 context  constr_dense_linorder
```
```   420 begin
```
```   421
```
```   422 lemma rinf_U[no_atp]:
```
```   423   assumes fU: "finite U"
```
```   424   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
```
```   425   \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> P y )"
```
```   426   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')"
```
```   427   and nmi: "\<not> MP"  and npi: "\<not> PP"  and ex: "\<exists> x.  P x"
```
```   428   shows "\<exists> u\<in> U. \<exists> u' \<in> U. P (between u u')"
```
```   429 proof-
```
```   430   from ex obtain x where px: "P x" by blast
```
```   431   from px nmi npi nmpiU have "\<exists> u\<in> U. \<exists> u' \<in> U. u \<sqsubseteq> x \<and> x \<sqsubseteq> u'" by auto
```
```   432   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
```
```   433   from uU have Une: "U \<noteq> {}" by auto
```
```   434   term "linorder.Min less_eq"
```
```   435   let ?l = "linorder.Min less_eq U"
```
```   436   let ?u = "linorder.Max less_eq U"
```
```   437   have linM: "?l \<in> U" using fU Une by simp
```
```   438   have uinM: "?u \<in> U" using fU Une by simp
```
```   439   have lM: "\<forall> t\<in> U. ?l \<sqsubseteq> t" using Une fU by auto
```
```   440   have Mu: "\<forall> t\<in> U. t \<sqsubseteq> ?u" using Une fU by auto
```
```   441   have th:"?l \<sqsubseteq> u" using uU Une lM by auto
```
```   442   from order_trans[OF th ux] have lx: "?l \<sqsubseteq> x" .
```
```   443   have th: "u' \<sqsubseteq> ?u" using uU' Une Mu by simp
```
```   444   from order_trans[OF xu' th] have xu: "x \<sqsubseteq> ?u" .
```
```   445   from finite_set_intervals2[where P="P",OF px lx xu linM uinM fU lM Mu]
```
```   446   have "(\<exists> s\<in> U. P s) \<or>
```
```   447       (\<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)" .
```
```   448   moreover { fix u assume um: "u\<in>U" and pu: "P u"
```
```   449     have "between u u = u" by (simp add: between_same)
```
```   450     with um pu have "P (between u u)" by simp
```
```   451     with um have ?thesis by blast}
```
```   452   moreover{
```
```   453     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"
```
```   454       then obtain t1 and t2 where t1M: "t1 \<in> U" and t2M: "t2\<in> U"
```
```   455         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"
```
```   456         by blast
```
```   457       from less_trans[OF t1x xt2] have t1t2: "t1 \<sqsubset> t2" .
```
```   458       let ?u = "between t1 t2"
```
```   459       from between_less t1t2 have t1lu: "t1 \<sqsubset> ?u" and ut2: "?u \<sqsubset> t2" by auto
```
```   460       from lin_dense noM t1x xt2 px t1lu ut2 have "P ?u" by blast
```
```   461       with t1M t2M have ?thesis by blast}
```
```   462     ultimately show ?thesis by blast
```
```   463   qed
```
```   464
```
```   465 theorem fr_eq[no_atp]:
```
```   466   assumes fU: "finite U"
```
```   467   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
```
```   468    \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> P y )"
```
```   469   and nmibnd: "\<forall>x. \<not> MP \<and> P x \<longrightarrow> (\<exists> u\<in> U. u \<sqsubseteq> x)"
```
```   470   and npibnd: "\<forall>x. \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. x \<sqsubseteq> u)"
```
```   471   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)"
```
```   472   shows "(\<exists> x. P x) \<equiv> (MP \<or> PP \<or> (\<exists> u \<in> U. \<exists> u'\<in> U. P (between u u')))"
```
```   473   (is "_ \<equiv> (_ \<or> _ \<or> ?F)" is "?E \<equiv> ?D")
```
```   474 proof-
```
```   475  {
```
```   476    assume px: "\<exists> x. P x"
```
```   477    have "MP \<or> PP \<or> (\<not> MP \<and> \<not> PP)" by blast
```
```   478    moreover {assume "MP \<or> PP" hence "?D" by blast}
```
```   479    moreover {assume nmi: "\<not> MP" and npi: "\<not> PP"
```
```   480      from npmibnd[OF nmibnd npibnd]
```
```   481      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')" .
```
```   482      from rinf_U[OF fU lin_dense nmpiU nmi npi px] have "?D" by blast}
```
```   483    ultimately have "?D" by blast}
```
```   484  moreover
```
```   485  { assume "?D"
```
```   486    moreover {assume m:"MP" from minf_ex[OF mi m] have "?E" .}
```
```   487    moreover {assume p: "PP" from pinf_ex[OF pi p] have "?E" . }
```
```   488    moreover {assume f:"?F" hence "?E" by blast}
```
```   489    ultimately have "?E" by blast}
```
```   490  ultimately have "?E = ?D" by blast thus "?E \<equiv> ?D" by simp
```
```   491 qed
```
```   492
```
```   493 lemmas minf_thms[no_atp] = minf_conj minf_disj minf_eq minf_neq minf_lt minf_le minf_gt minf_ge minf_P
```
```   494 lemmas pinf_thms[no_atp] = pinf_conj pinf_disj pinf_eq pinf_neq pinf_lt pinf_le pinf_gt pinf_ge pinf_P
```
```   495
```
```   496 lemmas nmi_thms[no_atp] = nmi_conj nmi_disj nmi_eq nmi_neq nmi_lt nmi_le nmi_gt nmi_ge nmi_P
```
```   497 lemmas npi_thms[no_atp] = npi_conj npi_disj npi_eq npi_neq npi_lt npi_le npi_gt npi_ge npi_P
```
```   498 lemmas lin_dense_thms[no_atp] = 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
```
```   499
```
```   500 lemma ferrack_axiom[no_atp]: "constr_dense_linorder less_eq less between"
```
```   501   by (rule constr_dense_linorder_axioms)
```
```   502 lemma atoms[no_atp]:
```
```   503   shows "TERM (less :: 'a \<Rightarrow> _)"
```
```   504     and "TERM (less_eq :: 'a \<Rightarrow> _)"
```
```   505     and "TERM (op = :: 'a \<Rightarrow> _)" .
```
```   506
```
```   507 declare ferrack_axiom [ferrack minf: minf_thms pinf: pinf_thms
```
```   508     nmi: nmi_thms npi: npi_thms lindense:
```
```   509     lin_dense_thms qe: fr_eq atoms: atoms]
```
```   510
```
```   511 declaration {*
```
```   512 let
```
```   513 fun simps phi = map (Morphism.thm phi) [@{thm "not_less"}, @{thm "not_le"}]
```
```   514 fun generic_whatis phi =
```
```   515  let
```
```   516   val [lt, le] = map (Morphism.term phi) [@{term "op \<sqsubset>"}, @{term "op \<sqsubseteq>"}]
```
```   517   fun h x t =
```
```   518    case term_of t of
```
```   519      Const(@{const_name HOL.eq}, _)\$y\$z => if term_of x aconv y then Ferrante_Rackoff_Data.Eq
```
```   520                             else Ferrante_Rackoff_Data.Nox
```
```   521    | @{term "Not"}\$(Const(@{const_name HOL.eq}, _)\$y\$z) => if term_of x aconv y then Ferrante_Rackoff_Data.NEq
```
```   522                             else Ferrante_Rackoff_Data.Nox
```
```   523    | b\$y\$z => if Term.could_unify (b, lt) then
```
```   524                  if term_of x aconv y then Ferrante_Rackoff_Data.Lt
```
```   525                  else if term_of x aconv z then Ferrante_Rackoff_Data.Gt
```
```   526                  else Ferrante_Rackoff_Data.Nox
```
```   527              else if Term.could_unify (b, le) then
```
```   528                  if term_of x aconv y then Ferrante_Rackoff_Data.Le
```
```   529                  else if term_of x aconv z then Ferrante_Rackoff_Data.Ge
```
```   530                  else Ferrante_Rackoff_Data.Nox
```
```   531              else Ferrante_Rackoff_Data.Nox
```
```   532    | _ => Ferrante_Rackoff_Data.Nox
```
```   533  in h end
```
```   534  fun ss phi = HOL_ss addsimps (simps phi)
```
```   535 in
```
```   536  Ferrante_Rackoff_Data.funs  @{thm "ferrack_axiom"}
```
```   537   {isolate_conv = K (K (K Thm.reflexive)), whatis = generic_whatis, simpset = ss}
```
```   538 end
```
```   539 *}
```
```   540
```
```   541 end
```
```   542
```
```   543 use "ferrante_rackoff.ML"
```
```   544
```
```   545 method_setup ferrack = {*
```
```   546   Scan.succeed (SIMPLE_METHOD' o FerranteRackoff.dlo_tac)
```
```   547 *} "Ferrante and Rackoff's algorithm for quantifier elimination in dense linear orders"
```
```   548
```
```   549 subsection {* Ferrante and Rackoff algorithm over ordered fields *}
```
```   550
```
```   551 lemma neg_prod_lt:"(c\<Colon>'a\<Colon>linordered_field) < 0 \<Longrightarrow> ((c*x < 0) == (x > 0))"
```
```   552 proof-
```
```   553   assume H: "c < 0"
```
```   554   have "c*x < 0 = (0/c < x)" by (simp only: neg_divide_less_eq[OF H] algebra_simps)
```
```   555   also have "\<dots> = (0 < x)" by simp
```
```   556   finally show  "(c*x < 0) == (x > 0)" by simp
```
```   557 qed
```
```   558
```
```   559 lemma pos_prod_lt:"(c\<Colon>'a\<Colon>linordered_field) > 0 \<Longrightarrow> ((c*x < 0) == (x < 0))"
```
```   560 proof-
```
```   561   assume H: "c > 0"
```
```   562   hence "c*x < 0 = (0/c > x)" by (simp only: pos_less_divide_eq[OF H] algebra_simps)
```
```   563   also have "\<dots> = (0 > x)" by simp
```
```   564   finally show  "(c*x < 0) == (x < 0)" by simp
```
```   565 qed
```
```   566
```
```   567 lemma neg_prod_sum_lt: "(c\<Colon>'a\<Colon>linordered_field) < 0 \<Longrightarrow> ((c*x + t< 0) == (x > (- 1/c)*t))"
```
```   568 proof-
```
```   569   assume H: "c < 0"
```
```   570   have "c*x + t< 0 = (c*x < -t)" by (subst less_iff_diff_less_0 [of "c*x" "-t"], simp)
```
```   571   also have "\<dots> = (-t/c < x)" by (simp only: neg_divide_less_eq[OF H] algebra_simps)
```
```   572   also have "\<dots> = ((- 1/c)*t < x)" by simp
```
```   573   finally show  "(c*x + t < 0) == (x > (- 1/c)*t)" by simp
```
```   574 qed
```
```   575
```
```   576 lemma pos_prod_sum_lt:"(c\<Colon>'a\<Colon>linordered_field) > 0 \<Longrightarrow> ((c*x + t < 0) == (x < (- 1/c)*t))"
```
```   577 proof-
```
```   578   assume H: "c > 0"
```
```   579   have "c*x + t< 0 = (c*x < -t)"  by (subst less_iff_diff_less_0 [of "c*x" "-t"], simp)
```
```   580   also have "\<dots> = (-t/c > x)" by (simp only: pos_less_divide_eq[OF H] algebra_simps)
```
```   581   also have "\<dots> = ((- 1/c)*t > x)" by simp
```
```   582   finally show  "(c*x + t < 0) == (x < (- 1/c)*t)" by simp
```
```   583 qed
```
```   584
```
```   585 lemma sum_lt:"((x::'a::ordered_ab_group_add) + t < 0) == (x < - t)"
```
```   586   using less_diff_eq[where a= x and b=t and c=0] by simp
```
```   587
```
```   588 lemma neg_prod_le:"(c\<Colon>'a\<Colon>linordered_field) < 0 \<Longrightarrow> ((c*x <= 0) == (x >= 0))"
```
```   589 proof-
```
```   590   assume H: "c < 0"
```
```   591   have "c*x <= 0 = (0/c <= x)" by (simp only: neg_divide_le_eq[OF H] algebra_simps)
```
```   592   also have "\<dots> = (0 <= x)" by simp
```
```   593   finally show  "(c*x <= 0) == (x >= 0)" by simp
```
```   594 qed
```
```   595
```
```   596 lemma pos_prod_le:"(c\<Colon>'a\<Colon>linordered_field) > 0 \<Longrightarrow> ((c*x <= 0) == (x <= 0))"
```
```   597 proof-
```
```   598   assume H: "c > 0"
```
```   599   hence "c*x <= 0 = (0/c >= x)" by (simp only: pos_le_divide_eq[OF H] algebra_simps)
```
```   600   also have "\<dots> = (0 >= x)" by simp
```
```   601   finally show  "(c*x <= 0) == (x <= 0)" by simp
```
```   602 qed
```
```   603
```
```   604 lemma neg_prod_sum_le: "(c\<Colon>'a\<Colon>linordered_field) < 0 \<Longrightarrow> ((c*x + t <= 0) == (x >= (- 1/c)*t))"
```
```   605 proof-
```
```   606   assume H: "c < 0"
```
```   607   have "c*x + t <= 0 = (c*x <= -t)"  by (subst le_iff_diff_le_0 [of "c*x" "-t"], simp)
```
```   608   also have "\<dots> = (-t/c <= x)" by (simp only: neg_divide_le_eq[OF H] algebra_simps)
```
```   609   also have "\<dots> = ((- 1/c)*t <= x)" by simp
```
```   610   finally show  "(c*x + t <= 0) == (x >= (- 1/c)*t)" by simp
```
```   611 qed
```
```   612
```
```   613 lemma pos_prod_sum_le:"(c\<Colon>'a\<Colon>linordered_field) > 0 \<Longrightarrow> ((c*x + t <= 0) == (x <= (- 1/c)*t))"
```
```   614 proof-
```
```   615   assume H: "c > 0"
```
```   616   have "c*x + t <= 0 = (c*x <= -t)" by (subst le_iff_diff_le_0 [of "c*x" "-t"], simp)
```
```   617   also have "\<dots> = (-t/c >= x)" by (simp only: pos_le_divide_eq[OF H] algebra_simps)
```
```   618   also have "\<dots> = ((- 1/c)*t >= x)" by simp
```
```   619   finally show  "(c*x + t <= 0) == (x <= (- 1/c)*t)" by simp
```
```   620 qed
```
```   621
```
```   622 lemma sum_le:"((x::'a::ordered_ab_group_add) + t <= 0) == (x <= - t)"
```
```   623   using le_diff_eq[where a= x and b=t and c=0] by simp
```
```   624
```
```   625 lemma nz_prod_eq:"(c\<Colon>'a\<Colon>linordered_field) \<noteq> 0 \<Longrightarrow> ((c*x = 0) == (x = 0))" by simp
```
```   626 lemma nz_prod_sum_eq: "(c\<Colon>'a\<Colon>linordered_field) \<noteq> 0 \<Longrightarrow> ((c*x + t = 0) == (x = (- 1/c)*t))"
```
```   627 proof-
```
```   628   assume H: "c \<noteq> 0"
```
```   629   have "c*x + t = 0 = (c*x = -t)" by (subst eq_iff_diff_eq_0 [of "c*x" "-t"], simp)
```
```   630   also have "\<dots> = (x = -t/c)" by (simp only: nonzero_eq_divide_eq[OF H] algebra_simps)
```
```   631   finally show  "(c*x + t = 0) == (x = (- 1/c)*t)" by simp
```
```   632 qed
```
```   633 lemma sum_eq:"((x::'a::ordered_ab_group_add) + t = 0) == (x = - t)"
```
```   634   using eq_diff_eq[where a= x and b=t and c=0] by simp
```
```   635
```
```   636
```
```   637 interpretation class_dense_linordered_field: constr_dense_linorder
```
```   638  "op <=" "op <"
```
```   639    "\<lambda> x y. 1/2 * ((x::'a::{linordered_field}) + y)"
```
```   640 by (unfold_locales, dlo, dlo, auto)
```
```   641
```
```   642 declaration{*
```
```   643 let
```
```   644 fun earlier [] x y = false
```
```   645         | earlier (h::t) x y =
```
```   646     if h aconvc y then false else if h aconvc x then true else earlier t x y;
```
```   647
```
```   648 fun dest_frac ct = case term_of ct of
```
```   649    Const (@{const_name Fields.divide},_) \$ a \$ b=>
```
```   650     Rat.rat_of_quotient (snd (HOLogic.dest_number a), snd (HOLogic.dest_number b))
```
```   651  | Const(@{const_name inverse}, _)\$a => Rat.rat_of_quotient(1, HOLogic.dest_number a |> snd)
```
```   652  | t => Rat.rat_of_int (snd (HOLogic.dest_number t))
```
```   653
```
```   654 fun mk_frac phi cT x =
```
```   655  let val (a, b) = Rat.quotient_of_rat x
```
```   656  in if b = 1 then Numeral.mk_cnumber cT a
```
```   657     else Thm.apply
```
```   658          (Thm.apply (Drule.cterm_rule (instantiate' [SOME cT] []) @{cpat "op /"})
```
```   659                      (Numeral.mk_cnumber cT a))
```
```   660          (Numeral.mk_cnumber cT b)
```
```   661  end
```
```   662
```
```   663 fun whatis x ct = case term_of ct of
```
```   664   Const(@{const_name Groups.plus}, _)\$(Const(@{const_name Groups.times},_)\$_\$y)\$_ =>
```
```   665      if y aconv term_of x then ("c*x+t",[(funpow 2 Thm.dest_arg1) ct, Thm.dest_arg ct])
```
```   666      else ("Nox",[])
```
```   667 | Const(@{const_name Groups.plus}, _)\$y\$_ =>
```
```   668      if y aconv term_of x then ("x+t",[Thm.dest_arg ct])
```
```   669      else ("Nox",[])
```
```   670 | Const(@{const_name Groups.times}, _)\$_\$y =>
```
```   671      if y aconv term_of x then ("c*x",[Thm.dest_arg1 ct])
```
```   672      else ("Nox",[])
```
```   673 | t => if t aconv term_of x then ("x",[]) else ("Nox",[]);
```
```   674
```
```   675 fun xnormalize_conv ctxt [] ct = Thm.reflexive ct
```
```   676 | xnormalize_conv ctxt (vs as (x::_)) ct =
```
```   677    case term_of ct of
```
```   678    Const(@{const_name Orderings.less},_)\$_\$Const(@{const_name Groups.zero},_) =>
```
```   679     (case whatis x (Thm.dest_arg1 ct) of
```
```   680     ("c*x+t",[c,t]) =>
```
```   681        let
```
```   682         val cr = dest_frac c
```
```   683         val clt = Thm.dest_fun2 ct
```
```   684         val cz = Thm.dest_arg ct
```
```   685         val neg = cr </ Rat.zero
```
```   686         val cthp = Simplifier.rewrite (simpset_of ctxt)
```
```   687                (Thm.apply @{cterm "Trueprop"}
```
```   688                   (if neg then Thm.apply (Thm.apply clt c) cz
```
```   689                     else Thm.apply (Thm.apply clt cz) c))
```
```   690         val cth = Thm.equal_elim (Thm.symmetric cthp) TrueI
```
```   691         val th = Thm.implies_elim (instantiate' [SOME (ctyp_of_term x)] (map SOME [c,x,t])
```
```   692              (if neg then @{thm neg_prod_sum_lt} else @{thm pos_prod_sum_lt})) cth
```
```   693         val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
```
```   694                    (Semiring_Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
```
```   695       in rth end
```
```   696     | ("x+t",[t]) =>
```
```   697        let
```
```   698         val T = ctyp_of_term x
```
```   699         val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_lt"}
```
```   700         val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
```
```   701               (Semiring_Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
```
```   702        in  rth end
```
```   703     | ("c*x",[c]) =>
```
```   704        let
```
```   705         val cr = dest_frac c
```
```   706         val clt = Thm.dest_fun2 ct
```
```   707         val cz = Thm.dest_arg ct
```
```   708         val neg = cr </ Rat.zero
```
```   709         val cthp = Simplifier.rewrite (simpset_of ctxt)
```
```   710                (Thm.apply @{cterm "Trueprop"}
```
```   711                   (if neg then Thm.apply (Thm.apply clt c) cz
```
```   712                     else Thm.apply (Thm.apply clt cz) c))
```
```   713         val cth = Thm.equal_elim (Thm.symmetric cthp) TrueI
```
```   714         val th = Thm.implies_elim (instantiate' [SOME (ctyp_of_term x)] (map SOME [c,x])
```
```   715              (if neg then @{thm neg_prod_lt} else @{thm pos_prod_lt})) cth
```
```   716         val rth = th
```
```   717       in rth end
```
```   718     | _ => Thm.reflexive ct)
```
```   719
```
```   720
```
```   721 |  Const(@{const_name Orderings.less_eq},_)\$_\$Const(@{const_name Groups.zero},_) =>
```
```   722    (case whatis x (Thm.dest_arg1 ct) of
```
```   723     ("c*x+t",[c,t]) =>
```
```   724        let
```
```   725         val T = ctyp_of_term x
```
```   726         val cr = dest_frac c
```
```   727         val clt = Drule.cterm_rule (instantiate' [SOME T] []) @{cpat "op <"}
```
```   728         val cz = Thm.dest_arg ct
```
```   729         val neg = cr </ Rat.zero
```
```   730         val cthp = Simplifier.rewrite (simpset_of ctxt)
```
```   731                (Thm.apply @{cterm "Trueprop"}
```
```   732                   (if neg then Thm.apply (Thm.apply clt c) cz
```
```   733                     else Thm.apply (Thm.apply clt cz) c))
```
```   734         val cth = Thm.equal_elim (Thm.symmetric cthp) TrueI
```
```   735         val th = Thm.implies_elim (instantiate' [SOME T] (map SOME [c,x,t])
```
```   736              (if neg then @{thm neg_prod_sum_le} else @{thm pos_prod_sum_le})) cth
```
```   737         val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
```
```   738                    (Semiring_Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
```
```   739       in rth end
```
```   740     | ("x+t",[t]) =>
```
```   741        let
```
```   742         val T = ctyp_of_term x
```
```   743         val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_le"}
```
```   744         val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
```
```   745               (Semiring_Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
```
```   746        in  rth end
```
```   747     | ("c*x",[c]) =>
```
```   748        let
```
```   749         val T = ctyp_of_term x
```
```   750         val cr = dest_frac c
```
```   751         val clt = Drule.cterm_rule (instantiate' [SOME T] []) @{cpat "op <"}
```
```   752         val cz = Thm.dest_arg ct
```
```   753         val neg = cr </ Rat.zero
```
```   754         val cthp = Simplifier.rewrite (simpset_of ctxt)
```
```   755                (Thm.apply @{cterm "Trueprop"}
```
```   756                   (if neg then Thm.apply (Thm.apply clt c) cz
```
```   757                     else Thm.apply (Thm.apply clt cz) c))
```
```   758         val cth = Thm.equal_elim (Thm.symmetric cthp) TrueI
```
```   759         val th = Thm.implies_elim (instantiate' [SOME (ctyp_of_term x)] (map SOME [c,x])
```
```   760              (if neg then @{thm neg_prod_le} else @{thm pos_prod_le})) cth
```
```   761         val rth = th
```
```   762       in rth end
```
```   763     | _ => Thm.reflexive ct)
```
```   764
```
```   765 |  Const(@{const_name HOL.eq},_)\$_\$Const(@{const_name Groups.zero},_) =>
```
```   766    (case whatis x (Thm.dest_arg1 ct) of
```
```   767     ("c*x+t",[c,t]) =>
```
```   768        let
```
```   769         val T = ctyp_of_term x
```
```   770         val cr = dest_frac c
```
```   771         val ceq = Thm.dest_fun2 ct
```
```   772         val cz = Thm.dest_arg ct
```
```   773         val cthp = Simplifier.rewrite (simpset_of ctxt)
```
```   774             (Thm.apply @{cterm "Trueprop"}
```
```   775              (Thm.apply @{cterm "Not"} (Thm.apply (Thm.apply ceq c) cz)))
```
```   776         val cth = Thm.equal_elim (Thm.symmetric cthp) TrueI
```
```   777         val th = Thm.implies_elim
```
```   778                  (instantiate' [SOME T] (map SOME [c,x,t]) @{thm nz_prod_sum_eq}) cth
```
```   779         val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
```
```   780                    (Semiring_Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
```
```   781       in rth end
```
```   782     | ("x+t",[t]) =>
```
```   783        let
```
```   784         val T = ctyp_of_term x
```
```   785         val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_eq"}
```
```   786         val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
```
```   787               (Semiring_Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
```
```   788        in  rth end
```
```   789     | ("c*x",[c]) =>
```
```   790        let
```
```   791         val T = ctyp_of_term x
```
```   792         val cr = dest_frac c
```
```   793         val ceq = Thm.dest_fun2 ct
```
```   794         val cz = Thm.dest_arg ct
```
```   795         val cthp = Simplifier.rewrite (simpset_of ctxt)
```
```   796             (Thm.apply @{cterm "Trueprop"}
```
```   797              (Thm.apply @{cterm "Not"} (Thm.apply (Thm.apply ceq c) cz)))
```
```   798         val cth = Thm.equal_elim (Thm.symmetric cthp) TrueI
```
```   799         val rth = Thm.implies_elim
```
```   800                  (instantiate' [SOME T] (map SOME [c,x]) @{thm nz_prod_eq}) cth
```
```   801       in rth end
```
```   802     | _ => Thm.reflexive ct);
```
```   803
```
```   804 local
```
```   805   val less_iff_diff_less_0 = mk_meta_eq @{thm "less_iff_diff_less_0"}
```
```   806   val le_iff_diff_le_0 = mk_meta_eq @{thm "le_iff_diff_le_0"}
```
```   807   val eq_iff_diff_eq_0 = mk_meta_eq @{thm "eq_iff_diff_eq_0"}
```
```   808 in
```
```   809 fun field_isolate_conv phi ctxt vs ct = case term_of ct of
```
```   810   Const(@{const_name Orderings.less},_)\$a\$b =>
```
```   811    let val (ca,cb) = Thm.dest_binop ct
```
```   812        val T = ctyp_of_term ca
```
```   813        val th = instantiate' [SOME T] [SOME ca, SOME cb] less_iff_diff_less_0
```
```   814        val nth = Conv.fconv_rule
```
```   815          (Conv.arg_conv (Conv.arg1_conv
```
```   816               (Semiring_Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th
```
```   817        val rth = Thm.transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth))
```
```   818    in rth end
```
```   819 | Const(@{const_name Orderings.less_eq},_)\$a\$b =>
```
```   820    let val (ca,cb) = Thm.dest_binop ct
```
```   821        val T = ctyp_of_term ca
```
```   822        val th = instantiate' [SOME T] [SOME ca, SOME cb] le_iff_diff_le_0
```
```   823        val nth = Conv.fconv_rule
```
```   824          (Conv.arg_conv (Conv.arg1_conv
```
```   825               (Semiring_Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th
```
```   826        val rth = Thm.transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth))
```
```   827    in rth end
```
```   828
```
```   829 | Const(@{const_name HOL.eq},_)\$a\$b =>
```
```   830    let val (ca,cb) = Thm.dest_binop ct
```
```   831        val T = ctyp_of_term ca
```
```   832        val th = instantiate' [SOME T] [SOME ca, SOME cb] eq_iff_diff_eq_0
```
```   833        val nth = Conv.fconv_rule
```
```   834          (Conv.arg_conv (Conv.arg1_conv
```
```   835               (Semiring_Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th
```
```   836        val rth = Thm.transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth))
```
```   837    in rth end
```
```   838 | @{term "Not"} \$(Const(@{const_name HOL.eq},_)\$a\$b) => Conv.arg_conv (field_isolate_conv phi ctxt vs) ct
```
```   839 | _ => Thm.reflexive ct
```
```   840 end;
```
```   841
```
```   842 fun classfield_whatis phi =
```
```   843  let
```
```   844   fun h x t =
```
```   845    case term_of t of
```
```   846      Const(@{const_name HOL.eq}, _)\$y\$z => if term_of x aconv y then Ferrante_Rackoff_Data.Eq
```
```   847                             else Ferrante_Rackoff_Data.Nox
```
```   848    | @{term "Not"}\$(Const(@{const_name HOL.eq}, _)\$y\$z) => if term_of x aconv y then Ferrante_Rackoff_Data.NEq
```
```   849                             else Ferrante_Rackoff_Data.Nox
```
```   850    | Const(@{const_name Orderings.less},_)\$y\$z =>
```
```   851        if term_of x aconv y then Ferrante_Rackoff_Data.Lt
```
```   852         else if term_of x aconv z then Ferrante_Rackoff_Data.Gt
```
```   853         else Ferrante_Rackoff_Data.Nox
```
```   854    | Const (@{const_name Orderings.less_eq},_)\$y\$z =>
```
```   855          if term_of x aconv y then Ferrante_Rackoff_Data.Le
```
```   856          else if term_of x aconv z then Ferrante_Rackoff_Data.Ge
```
```   857          else Ferrante_Rackoff_Data.Nox
```
```   858    | _ => Ferrante_Rackoff_Data.Nox
```
```   859  in h end;
```
```   860 fun class_field_ss phi =
```
```   861    HOL_basic_ss addsimps ([@{thm "linorder_not_less"}, @{thm "linorder_not_le"}])
```
```   862    |> fold Splitter.add_split [@{thm "abs_split"}, @{thm "split_max"}, @{thm "split_min"}]
```
```   863
```
```   864 in
```
```   865 Ferrante_Rackoff_Data.funs @{thm "class_dense_linordered_field.ferrack_axiom"}
```
```   866   {isolate_conv = field_isolate_conv, whatis = classfield_whatis, simpset = class_field_ss}
```
```   867 end
```
```   868 *}
```
```   869 (*
```
```   870 lemma upper_bound_finite_set:
```
```   871   assumes fS: "finite S"
```
```   872   shows "\<exists>(a::'a::linorder). \<forall>x \<in> S. f x \<le> a"
```
```   873 proof(induct rule: finite_induct[OF fS])
```
```   874   case 1 thus ?case by simp
```
```   875 next
```
```   876   case (2 x F)
```
```   877   from "2.hyps" obtain a where a:"\<forall>x \<in>F. f x \<le> a" by blast
```
```   878   let ?a = "max a (f x)"
```
```   879   have m: "a \<le> ?a" "f x \<le> ?a" by simp_all
```
```   880   {fix y assume y: "y \<in> insert x F"
```
```   881     {assume "y = x" hence "f y \<le> ?a" using m by simp}
```
```   882     moreover
```
```   883     {assume yF: "y\<in> F" from a[rule_format, OF yF] m have "f y \<le> ?a" by (simp add: max_def)}
```
```   884     ultimately have "f y \<le> ?a" using y by blast}
```
```   885   then show ?case by blast
```
```   886 qed
```
```   887
```
```   888 lemma lower_bound_finite_set:
```
```   889   assumes fS: "finite S"
```
```   890   shows "\<exists>(a::'a::linorder). \<forall>x \<in> S. f x \<ge> a"
```
```   891 proof(induct rule: finite_induct[OF fS])
```
```   892   case 1 thus ?case by simp
```
```   893 next
```
```   894   case (2 x F)
```
```   895   from "2.hyps" obtain a where a:"\<forall>x \<in>F. f x \<ge> a" by blast
```
```   896   let ?a = "min a (f x)"
```
```   897   have m: "a \<ge> ?a" "f x \<ge> ?a" by simp_all
```
```   898   {fix y assume y: "y \<in> insert x F"
```
```   899     {assume "y = x" hence "f y \<ge> ?a" using m by simp}
```
```   900     moreover
```
```   901     {assume yF: "y\<in> F" from a[rule_format, OF yF] m have "f y \<ge> ?a" by (simp add: min_def)}
```
```   902     ultimately have "f y \<ge> ?a" using y by blast}
```
```   903   then show ?case by blast
```
```   904 qed
```
```   905
```
```   906 lemma bound_finite_set: assumes f: "finite S"
```
```   907   shows "\<exists>a. \<forall>x \<in>S. (f x:: 'a::linorder) \<le> a"
```
```   908 proof-
```
```   909   let ?F = "f ` S"
```
```   910   from f have fF: "finite ?F" by simp
```
```   911   let ?a = "Max ?F"
```
```   912   {assume "S = {}" hence ?thesis by blast}
```
```   913   moreover
```
```   914   {assume Se: "S \<noteq> {}" hence Fe: "?F \<noteq> {}" by simp
```
```   915   {fix x assume x: "x \<in> S"
```
```   916     hence th0: "f x \<in> ?F" by simp
```
```   917     hence "f x \<le> ?a" using Max_ge[OF fF th0] ..}
```
```   918   hence ?thesis by blast}
```
```   919 ultimately show ?thesis by blast
```
```   920 qed
```
```   921 *)
```
```   922
```
```   923 end
```