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