# HG changeset patch # User chaieb # Date 1233879195 0 # Node ID 3ccd86c214bfa65674cdda95e8420df317e58235 # Parent a521a6fab39b1204529565eb0d0ab31a20762a07 fixed dependencies : Theory Dense_Linear_Order moved to Library diff -r a521a6fab39b -r 3ccd86c214bf src/HOL/Dense_Linear_Order.thy --- a/src/HOL/Dense_Linear_Order.thy Fri Feb 06 00:10:58 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,879 +0,0 @@ -(* Title : HOL/Dense_Linear_Order.thy - Author : Amine Chaieb, TU Muenchen -*) - -header {* Dense linear order without endpoints - and a quantifier elimination procedure in Ferrante and Rackoff style *} - -theory Dense_Linear_Order -imports Plain Groebner_Basis Main -uses - "~~/src/HOL/Tools/Qelim/langford_data.ML" - "~~/src/HOL/Tools/Qelim/ferrante_rackoff_data.ML" - ("~~/src/HOL/Tools/Qelim/langford.ML") - ("~~/src/HOL/Tools/Qelim/ferrante_rackoff.ML") -begin - -setup {* Langford_Data.setup #> Ferrante_Rackoff_Data.setup *} - -context linorder -begin - -lemma less_not_permute: "\ (x < y \ y < x)" by (simp add: not_less linear) - -lemma gather_simps: - shows - "(\x. (\y \ L. y < x) \ (\y \ U. x < y) \ x < u \ P x) \ (\x. (\y \ L. y < x) \ (\y \ (insert u U). x < y) \ P x)" - and "(\x. (\y \ L. y < x) \ (\y \ U. x < y) \ l < x \ P x) \ (\x. (\y \ (insert l L). y < x) \ (\y \ U. x < y) \ P x)" - "(\x. (\y \ L. y < x) \ (\y \ U. x < y) \ x < u) \ (\x. (\y \ L. y < x) \ (\y \ (insert u U). x < y))" - and "(\x. (\y \ L. y < x) \ (\y \ U. x < y) \ l < x) \ (\x. (\y \ (insert l L). y < x) \ (\y \ U. x < y))" by auto - -lemma - gather_start: "(\x. P x) \ (\x. (\y \ {}. y < x) \ (\y\ {}. x < y) \ P x)" - by simp - -text{* Theorems for @{text "\z. \x. x < z \ (P x \ P\<^bsub>-\\<^esub>)"}*} -lemma minf_lt: "\z . \x. x < z \ (x < t \ True)" by auto -lemma minf_gt: "\z . \x. x < z \ (t < x \ False)" - by (simp add: not_less) (rule exI[where x="t"], auto simp add: less_le) - -lemma minf_le: "\z. \x. x < z \ (x \ t \ True)" by (auto simp add: less_le) -lemma minf_ge: "\z. \x. x < z \ (t \ x \ False)" - by (auto simp add: less_le not_less not_le) -lemma minf_eq: "\z. \x. x < z \ (x = t \ False)" by auto -lemma minf_neq: "\z. \x. x < z \ (x \ t \ True)" by auto -lemma minf_P: "\z. \x. x < z \ (P \ P)" by blast - -text{* Theorems for @{text "\z. \x. x < z \ (P x \ P\<^bsub>+\\<^esub>)"}*} -lemma pinf_gt: "\z . \x. z < x \ (t < x \ True)" by auto -lemma pinf_lt: "\z . \x. z < x \ (x < t \ False)" - by (simp add: not_less) (rule exI[where x="t"], auto simp add: less_le) - -lemma pinf_ge: "\z. \x. z < x \ (t \ x \ True)" by (auto simp add: less_le) -lemma pinf_le: "\z. \x. z < x \ (x \ t \ False)" - by (auto simp add: less_le not_less not_le) -lemma pinf_eq: "\z. \x. z < x \ (x = t \ False)" by auto -lemma pinf_neq: "\z. \x. z < x \ (x \ t \ True)" by auto -lemma pinf_P: "\z. \x. z < x \ (P \ P)" by blast - -lemma nmi_lt: "t \ U \ \x. \True \ x < t \ (\ u\ U. u \ x)" by auto -lemma nmi_gt: "t \ U \ \x. \False \ t < x \ (\ u\ U. u \ x)" - by (auto simp add: le_less) -lemma nmi_le: "t \ U \ \x. \True \ x\ t \ (\ u\ U. u \ x)" by auto -lemma nmi_ge: "t \ U \ \x. \False \ t\ x \ (\ u\ U. u \ x)" by auto -lemma nmi_eq: "t \ U \ \x. \False \ x = t \ (\ u\ U. u \ x)" by auto -lemma nmi_neq: "t \ U \\x. \True \ x \ t \ (\ u\ U. u \ x)" by auto -lemma nmi_P: "\ x. ~P \ P \ (\ u\ U. u \ x)" by auto -lemma nmi_conj: "\\x. \P1' \ P1 x \ (\ u\ U. u \ x) ; - \x. \P2' \ P2 x \ (\ u\ U. u \ x)\ \ - \x. \(P1' \ P2') \ (P1 x \ P2 x) \ (\ u\ U. u \ x)" by auto -lemma nmi_disj: "\\x. \P1' \ P1 x \ (\ u\ U. u \ x) ; - \x. \P2' \ P2 x \ (\ u\ U. u \ x)\ \ - \x. \(P1' \ P2') \ (P1 x \ P2 x) \ (\ u\ U. u \ x)" by auto - -lemma npi_lt: "t \ U \ \x. \False \ x < t \ (\ u\ U. x \ u)" by (auto simp add: le_less) -lemma npi_gt: "t \ U \ \x. \True \ t < x \ (\ u\ U. x \ u)" by auto -lemma npi_le: "t \ U \ \x. \False \ x \ t \ (\ u\ U. x \ u)" by auto -lemma npi_ge: "t \ U \ \x. \True \ t \ x \ (\ u\ U. x \ u)" by auto -lemma npi_eq: "t \ U \ \x. \False \ x = t \ (\ u\ U. x \ u)" by auto -lemma npi_neq: "t \ U \ \x. \True \ x \ t \ (\ u\ U. x \ u )" by auto -lemma npi_P: "\ x. ~P \ P \ (\ u\ U. x \ u)" by auto -lemma npi_conj: "\\x. \P1' \ P1 x \ (\ u\ U. x \ u) ; \x. \P2' \ P2 x \ (\ u\ U. x \ u)\ - \ \x. \(P1' \ P2') \ (P1 x \ P2 x) \ (\ u\ U. x \ u)" by auto -lemma npi_disj: "\\x. \P1' \ P1 x \ (\ u\ U. x \ u) ; \x. \P2' \ P2 x \ (\ u\ U. x \ u)\ - \ \x. \(P1' \ P2') \ (P1 x \ P2 x) \ (\ u\ U. x \ u)" by auto - -lemma lin_dense_lt: "t \ U \ \x l u. (\ t. l < t \ t < u \ t \ U) \ l< x \ x < u \ x < t \ (\ y. l < y \ y < u \ y < t)" -proof(clarsimp) - fix x l u y assume tU: "t \ U" and noU: "\t. l < t \ t < u \ t \ U" and lx: "l < x" - and xu: "xy" by auto - {assume H: "t < y" - from less_trans[OF lx px] less_trans[OF H yu] - have "l < t \ t < u" by simp - with tU noU have "False" by auto} - hence "\ t < y" by auto hence "y \ t" by (simp add: not_less) - thus "y < t" using tny by (simp add: less_le) -qed - -lemma lin_dense_gt: "t \ U \ \x l u. (\ t. l < t \ t< u \ t \ U) \ l < x \ x < u \ t < x \ (\ y. l < y \ y < u \ t < y)" -proof(clarsimp) - fix x l u y - assume tU: "t \ U" and noU: "\t. l < t \ t < u \ t \ U" and lx: "l < x" and xu: "xy" by auto - {assume H: "y< t" - from less_trans[OF ly H] less_trans[OF px xu] have "l < t \ t < u" by simp - with tU noU have "False" by auto} - hence "\ y y" by (auto simp add: not_less) - thus "t < y" using tny by (simp add:less_le) -qed - -lemma lin_dense_le: "t \ U \ \x l u. (\ t. l < t \ t< u \ t \ U) \ l< x \ x < u \ x \ t \ (\ y. l < y \ y < u \ y\ t)" -proof(clarsimp) - fix x l u y - assume tU: "t \ U" and noU: "\t. l < t \ t < u \ t \ U" and lx: "l < x" and xu: "x t" and ly: "ly" by auto - {assume H: "t < y" - from less_le_trans[OF lx px] less_trans[OF H yu] - have "l < t \ t < u" by simp - with tU noU have "False" by auto} - hence "\ t < y" by auto thus "y \ t" by (simp add: not_less) -qed - -lemma lin_dense_ge: "t \ U \ \x l u. (\ t. l < t \ t< u \ t \ U) \ l< x \ x < u \ t \ x \ (\ y. l < y \ y < u \ t \ y)" -proof(clarsimp) - fix x l u y - assume tU: "t \ U" and noU: "\t. l < t \ t < u \ t \ U" and lx: "l < x" and xu: "x x" and ly: "ly" by auto - {assume H: "y< t" - from less_trans[OF ly H] le_less_trans[OF px xu] - have "l < t \ t < u" by simp - with tU noU have "False" by auto} - hence "\ y y" by (simp add: not_less) -qed -lemma lin_dense_eq: "t \ U \ \x l u. (\ t. l < t \ t< u \ t \ U) \ l< x \ x < u \ x = t \ (\ y. l < y \ y < u \ y= t)" by auto -lemma lin_dense_neq: "t \ U \ \x l u. (\ t. l < t \ t< u \ t \ U) \ l< x \ x < u \ x \ t \ (\ y. l < y \ y < u \ y\ t)" by auto -lemma lin_dense_P: "\x l u. (\ t. l < t \ t< u \ t \ U) \ l< x \ x < u \ P \ (\ y. l < y \ y < u \ P)" by auto - -lemma lin_dense_conj: - "\\x l u. (\ t. l < t \ t< u \ t \ U) \ l< x \ x < u \ P1 x - \ (\ y. l < y \ y < u \ P1 y) ; - \x l u. (\ t. l < t \ t< u \ t \ U) \ l< x \ x < u \ P2 x - \ (\ y. l < y \ y < u \ P2 y)\ \ - \x l u. (\ t. l < t \ t< u \ t \ U) \ l< x \ x < u \ (P1 x \ P2 x) - \ (\ y. l < y \ y < u \ (P1 y \ P2 y))" - by blast -lemma lin_dense_disj: - "\\x l u. (\ t. l < t \ t< u \ t \ U) \ l< x \ x < u \ P1 x - \ (\ y. l < y \ y < u \ P1 y) ; - \x l u. (\ t. l < t \ t< u \ t \ U) \ l< x \ x < u \ P2 x - \ (\ y. l < y \ y < u \ P2 y)\ \ - \x l u. (\ t. l < t \ t< u \ t \ U) \ l< x \ x < u \ (P1 x \ P2 x) - \ (\ y. l < y \ y < u \ (P1 y \ P2 y))" - by blast - -lemma npmibnd: "\\x. \ MP \ P x \ (\ u\ U. u \ x); \x. \PP \ P x \ (\ u\ U. x \ u)\ - \ \x. \ MP \ \PP \ P x \ (\ u\ U. \ u' \ U. u \ x \ x \ u')" -by auto - -lemma finite_set_intervals: - assumes px: "P x" and lx: "l \ x" and xu: "x \ u" and linS: "l\ S" - and uinS: "u \ S" and fS:"finite S" and lS: "\ x\ S. l \ x" and Su: "\ x\ S. x \ u" - shows "\ a \ S. \ b \ S. (\ y. a < y \ y < b \ y \ S) \ a \ x \ x \ b \ P x" -proof- - let ?Mx = "{y. y\ S \ y \ x}" - let ?xM = "{y. y\ S \ x \ y}" - let ?a = "Max ?Mx" - let ?b = "Min ?xM" - have MxS: "?Mx \ S" by blast - hence fMx: "finite ?Mx" using fS finite_subset by auto - from lx linS have linMx: "l \ ?Mx" by blast - hence Mxne: "?Mx \ {}" by blast - have xMS: "?xM \ S" by blast - hence fxM: "finite ?xM" using fS finite_subset by auto - from xu uinS have linxM: "u \ ?xM" by blast - hence xMne: "?xM \ {}" by blast - have ax:"?a \ x" using Mxne fMx by auto - have xb:"x \ ?b" using xMne fxM by auto - have "?a \ ?Mx" using Max_in[OF fMx Mxne] by simp hence ainS: "?a \ S" using MxS by blast - have "?b \ ?xM" using Min_in[OF fxM xMne] by simp hence binS: "?b \ S" using xMS by blast - have noy:"\ y. ?a < y \ y < ?b \ y \ S" - proof(clarsimp) - fix y assume ay: "?a < y" and yb: "y < ?b" and yS: "y \ S" - from yS have "y\ ?Mx \ y\ ?xM" by (auto simp add: linear) - moreover {assume "y \ ?Mx" hence "y \ ?a" using Mxne fMx by auto with ay have "False" by (simp add: not_le[symmetric])} - moreover {assume "y \ ?xM" hence "?b \ y" using xMne fxM by auto with yb have "False" by (simp add: not_le[symmetric])} - ultimately show "False" by blast - qed - from ainS binS noy ax xb px show ?thesis by blast -qed - -lemma finite_set_intervals2: - assumes px: "P x" and lx: "l \ x" and xu: "x \ u" and linS: "l\ S" - and uinS: "u \ S" and fS:"finite S" and lS: "\ x\ S. l \ x" and Su: "\ x\ S. x \ u" - shows "(\ s\ S. P s) \ (\ a \ S. \ b \ S. (\ y. a < y \ y < b \ y \ S) \ a < x \ x < b \ P x)" -proof- - from finite_set_intervals[where P="P", OF px lx xu linS uinS fS lS Su] - obtain a and b where - as: "a\ S" and bs: "b\ S" and noS:"\y. a < y \ y < b \ y \ S" - and axb: "a \ x \ x \ b \ P x" by auto - from axb have "x= a \ x= b \ (a < x \ x < b)" by (auto simp add: le_less) - thus ?thesis using px as bs noS by blast -qed - -end - -section {* The classical QE after Langford for dense linear orders *} - -context dense_linear_order -begin - -lemma interval_empty_iff: - "{y. x < y \ y < z} = {} \ \ x < z" - by (auto dest: dense) - -lemma dlo_qe_bnds: - assumes ne: "L \ {}" and neU: "U \ {}" and fL: "finite L" and fU: "finite U" - shows "(\x. (\y \ L. y < x) \ (\y \ U. x < y)) \ (\ l \ L. \u \ U. l < u)" -proof (simp only: atomize_eq, rule iffI) - assume H: "\x. (\y\L. y < x) \ (\y\U. x < y)" - then obtain x where xL: "\y\L. y < x" and xU: "\y\U. x < y" by blast - {fix l u assume l: "l \ L" and u: "u \ U" - have "l < x" using xL l by blast - also have "x < u" using xU u by blast - finally (less_trans) have "l < u" .} - thus "\l\L. \u\U. l < u" by blast -next - assume H: "\l\L. \u\U. l < u" - let ?ML = "Max L" - let ?MU = "Min U" - from fL ne have th1: "?ML \ L" and th1': "\l\L. l \ ?ML" by auto - from fU neU have th2: "?MU \ U" and th2': "\u\U. ?MU \ u" by auto - from th1 th2 H have "?ML < ?MU" by auto - with dense obtain w where th3: "?ML < w" and th4: "w < ?MU" by blast - from th3 th1' have "\l \ L. l < w" by auto - moreover from th4 th2' have "\u \ U. w < u" by auto - ultimately show "\x. (\y\L. y < x) \ (\y\U. x < y)" by auto -qed - -lemma dlo_qe_noub: - assumes ne: "L \ {}" and fL: "finite L" - shows "(\x. (\y \ L. y < x) \ (\y \ {}. x < y)) \ True" -proof(simp add: atomize_eq) - from gt_ex[of "Max L"] obtain M where M: "Max L < M" by blast - from ne fL have "\x \ L. x \ Max L" by simp - with M have "\x\L. x < M" by (auto intro: le_less_trans) - thus "\x. \y\L. y < x" by blast -qed - -lemma dlo_qe_nolb: - assumes ne: "U \ {}" and fU: "finite U" - shows "(\x. (\y \ {}. y < x) \ (\y \ U. x < y)) \ True" -proof(simp add: atomize_eq) - from lt_ex[of "Min U"] obtain M where M: "M < Min U" by blast - from ne fU have "\x \ U. Min U \ x" by simp - with M have "\x\U. M < x" by (auto intro: less_le_trans) - thus "\x. \y\U. x < y" by blast -qed - -lemma exists_neq: "\(x::'a). x \ t" "\(x::'a). t \ x" - using gt_ex[of t] by auto - -lemmas dlo_simps = order_refl less_irrefl not_less not_le exists_neq - le_less neq_iff linear less_not_permute - -lemma axiom: "dense_linear_order (op \) (op <)" by (rule dense_linear_order_axioms) -lemma atoms: - shows "TERM (less :: 'a \ _)" - and "TERM (less_eq :: 'a \ _)" - and "TERM (op = :: 'a \ _)" . - -declare axiom[langford qe: dlo_qe_bnds dlo_qe_nolb dlo_qe_noub gather: gather_start gather_simps atoms: atoms] -declare dlo_simps[langfordsimp] - -end - -(* FIXME: Move to HOL -- together with the conj_aci_rule in langford.ML *) -lemma dnf: - "(P & (Q | R)) = ((P&Q) | (P&R))" - "((Q | R) & P) = ((Q&P) | (R&P))" - by blast+ - -lemmas weak_dnf_simps = simp_thms dnf - -lemma nnf_simps: - "(\(P \ Q)) = (\P \ \Q)" "(\(P \ Q)) = (\P \ \Q)" "(P \ Q) = (\P \ Q)" - "(P = Q) = ((P \ Q) \ (\P \ \ Q))" "(\ \(P)) = P" - by blast+ - -lemma ex_distrib: "(\x. P x \ Q x) \ ((\x. P x) \ (\x. Q x))" by blast - -lemmas dnf_simps = weak_dnf_simps nnf_simps ex_distrib - -use "~~/src/HOL/Tools/Qelim/langford.ML" -method_setup dlo = {* - Method.ctxt_args (Method.SIMPLE_METHOD' o LangfordQE.dlo_tac) -*} "Langford's algorithm for quantifier elimination in dense linear orders" - - -section {* Contructive dense linear orders yield QE for linear arithmetic over ordered Fields -- see @{text "Arith_Tools.thy"} *} - -text {* Linear order without upper bounds *} - -locale linorder_stupid_syntax = linorder -begin -notation - less_eq ("op \") and - less_eq ("(_/ \ _)" [51, 51] 50) and - less ("op \") and - less ("(_/ \ _)" [51, 51] 50) - -end - -locale linorder_no_ub = linorder_stupid_syntax + - assumes gt_ex: "\y. less x y" -begin -lemma ge_ex: "\y. x \ y" using gt_ex by auto - -text {* Theorems for @{text "\z. \x. z \ x \ (P x \ P\<^bsub>+\\<^esub>)"} *} -lemma pinf_conj: - assumes ex1: "\z1. \x. z1 \ x \ (P1 x \ P1')" - and ex2: "\z2. \x. z2 \ x \ (P2 x \ P2')" - shows "\z. \x. z \ x \ ((P1 x \ P2 x) \ (P1' \ P2'))" -proof- - from ex1 ex2 obtain z1 and z2 where z1: "\x. z1 \ x \ (P1 x \ P1')" - and z2: "\x. z2 \ x \ (P2 x \ P2')" by blast - from gt_ex obtain z where z:"ord.max less_eq z1 z2 \ z" by blast - from z have zz1: "z1 \ z" and zz2: "z2 \ z" by simp_all - {fix x assume H: "z \ x" - from less_trans[OF zz1 H] less_trans[OF zz2 H] - have "(P1 x \ P2 x) \ (P1' \ P2')" using z1 zz1 z2 zz2 by auto - } - thus ?thesis by blast -qed - -lemma pinf_disj: - assumes ex1: "\z1. \x. z1 \ x \ (P1 x \ P1')" - and ex2: "\z2. \x. z2 \ x \ (P2 x \ P2')" - shows "\z. \x. z \ x \ ((P1 x \ P2 x) \ (P1' \ P2'))" -proof- - from ex1 ex2 obtain z1 and z2 where z1: "\x. z1 \ x \ (P1 x \ P1')" - and z2: "\x. z2 \ x \ (P2 x \ P2')" by blast - from gt_ex obtain z where z:"ord.max less_eq z1 z2 \ z" by blast - from z have zz1: "z1 \ z" and zz2: "z2 \ z" by simp_all - {fix x assume H: "z \ x" - from less_trans[OF zz1 H] less_trans[OF zz2 H] - have "(P1 x \ P2 x) \ (P1' \ P2')" using z1 zz1 z2 zz2 by auto - } - thus ?thesis by blast -qed - -lemma pinf_ex: assumes ex:"\z. \x. z \ x \ (P x \ P1)" and p1: P1 shows "\ x. P x" -proof- - from ex obtain z where z: "\x. z \ x \ (P x \ P1)" by blast - from gt_ex obtain x where x: "z \ x" by blast - from z x p1 show ?thesis by blast -qed - -end - -text {* Linear order without upper bounds *} - -locale linorder_no_lb = linorder_stupid_syntax + - assumes lt_ex: "\y. less y x" -begin -lemma le_ex: "\y. y \ x" using lt_ex by auto - - -text {* Theorems for @{text "\z. \x. x \ z \ (P x \ P\<^bsub>-\\<^esub>)"} *} -lemma minf_conj: - assumes ex1: "\z1. \x. x \ z1 \ (P1 x \ P1')" - and ex2: "\z2. \x. x \ z2 \ (P2 x \ P2')" - shows "\z. \x. x \ z \ ((P1 x \ P2 x) \ (P1' \ P2'))" -proof- - from ex1 ex2 obtain z1 and z2 where z1: "\x. x \ z1 \ (P1 x \ P1')"and z2: "\x. x \ z2 \ (P2 x \ P2')" by blast - from lt_ex obtain z where z:"z \ ord.min less_eq z1 z2" by blast - from z have zz1: "z \ z1" and zz2: "z \ z2" by simp_all - {fix x assume H: "x \ z" - from less_trans[OF H zz1] less_trans[OF H zz2] - have "(P1 x \ P2 x) \ (P1' \ P2')" using z1 zz1 z2 zz2 by auto - } - thus ?thesis by blast -qed - -lemma minf_disj: - assumes ex1: "\z1. \x. x \ z1 \ (P1 x \ P1')" - and ex2: "\z2. \x. x \ z2 \ (P2 x \ P2')" - shows "\z. \x. x \ z \ ((P1 x \ P2 x) \ (P1' \ P2'))" -proof- - from ex1 ex2 obtain z1 and z2 where z1: "\x. x \ z1 \ (P1 x \ P1')"and z2: "\x. x \ z2 \ (P2 x \ P2')" by blast - from lt_ex obtain z where z:"z \ ord.min less_eq z1 z2" by blast - from z have zz1: "z \ z1" and zz2: "z \ z2" by simp_all - {fix x assume H: "x \ z" - from less_trans[OF H zz1] less_trans[OF H zz2] - have "(P1 x \ P2 x) \ (P1' \ P2')" using z1 zz1 z2 zz2 by auto - } - thus ?thesis by blast -qed - -lemma minf_ex: assumes ex:"\z. \x. x \ z \ (P x \ P1)" and p1: P1 shows "\ x. P x" -proof- - from ex obtain z where z: "\x. x \ z \ (P x \ P1)" by blast - from lt_ex obtain x where x: "x \ z" by blast - from z x p1 show ?thesis by blast -qed - -end - - -locale constr_dense_linear_order = linorder_no_lb + linorder_no_ub + - fixes between - assumes between_less: "less x y \ less x (between x y) \ less (between x y) y" - and between_same: "between x x = x" - -sublocale constr_dense_linear_order < dense_linear_order - apply unfold_locales - using gt_ex lt_ex between_less - by (auto, rule_tac x="between x y" in exI, simp) - -context constr_dense_linear_order -begin - -lemma rinf_U: - assumes fU: "finite U" - and lin_dense: "\x l u. (\ t. l \ t \ t\ u \ t \ U) \ l\ x \ x \ u \ P x - \ (\ y. l \ y \ y \ u \ P y )" - and nmpiU: "\x. \ MP \ \PP \ P x \ (\ u\ U. \ u' \ U. u \ x \ x \ u')" - and nmi: "\ MP" and npi: "\ PP" and ex: "\ x. P x" - shows "\ u\ U. \ u' \ U. P (between u u')" -proof- - from ex obtain x where px: "P x" by blast - from px nmi npi nmpiU have "\ u\ U. \ u' \ U. u \ x \ x \ u'" by auto - then obtain u and u' where uU:"u\ U" and uU': "u' \ U" and ux:"u \ x" and xu':"x \ u'" by auto - from uU have Une: "U \ {}" by auto - term "linorder.Min less_eq" - let ?l = "linorder.Min less_eq U" - let ?u = "linorder.Max less_eq U" - have linM: "?l \ U" using fU Une by simp - have uinM: "?u \ U" using fU Une by simp - have lM: "\ t\ U. ?l \ t" using Une fU by auto - have Mu: "\ t\ U. t \ ?u" using Une fU by auto - have th:"?l \ u" using uU Une lM by auto - from order_trans[OF th ux] have lx: "?l \ x" . - have th: "u' \ ?u" using uU' Une Mu by simp - from order_trans[OF xu' th] have xu: "x \ ?u" . - from finite_set_intervals2[where P="P",OF px lx xu linM uinM fU lM Mu] - have "(\ s\ U. P s) \ - (\ t1\ U. \ t2 \ U. (\ y. t1 \ y \ y \ t2 \ y \ U) \ t1 \ x \ x \ t2 \ P x)" . - moreover { fix u assume um: "u\U" and pu: "P u" - have "between u u = u" by (simp add: between_same) - with um pu have "P (between u u)" by simp - with um have ?thesis by blast} - moreover{ - assume "\ t1\ U. \ t2 \ U. (\ y. t1 \ y \ y \ t2 \ y \ U) \ t1 \ x \ x \ t2 \ P x" - then obtain t1 and t2 where t1M: "t1 \ U" and t2M: "t2\ U" - and noM: "\ y. t1 \ y \ y \ t2 \ y \ U" and t1x: "t1 \ x" and xt2: "x \ t2" and px: "P x" - by blast - from less_trans[OF t1x xt2] have t1t2: "t1 \ t2" . - let ?u = "between t1 t2" - from between_less t1t2 have t1lu: "t1 \ ?u" and ut2: "?u \ t2" by auto - from lin_dense noM t1x xt2 px t1lu ut2 have "P ?u" by blast - with t1M t2M have ?thesis by blast} - ultimately show ?thesis by blast - qed - -theorem fr_eq: - assumes fU: "finite U" - and lin_dense: "\x l u. (\ t. l \ t \ t\ u \ t \ U) \ l\ x \ x \ u \ P x - \ (\ y. l \ y \ y \ u \ P y )" - and nmibnd: "\x. \ MP \ P x \ (\ u\ U. u \ x)" - and npibnd: "\x. \PP \ P x \ (\ u\ U. x \ u)" - and mi: "\z. \x. x \ z \ (P x = MP)" and pi: "\z. \x. z \ x \ (P x = PP)" - shows "(\ x. P x) \ (MP \ PP \ (\ u \ U. \ u'\ U. P (between u u')))" - (is "_ \ (_ \ _ \ ?F)" is "?E \ ?D") -proof- - { - assume px: "\ x. P x" - have "MP \ PP \ (\ MP \ \ PP)" by blast - moreover {assume "MP \ PP" hence "?D" by blast} - moreover {assume nmi: "\ MP" and npi: "\ PP" - from npmibnd[OF nmibnd npibnd] - have nmpiU: "\x. \ MP \ \PP \ P x \ (\ u\ U. \ u' \ U. u \ x \ x \ u')" . - from rinf_U[OF fU lin_dense nmpiU nmi npi px] have "?D" by blast} - ultimately have "?D" by blast} - moreover - { assume "?D" - moreover {assume m:"MP" from minf_ex[OF mi m] have "?E" .} - moreover {assume p: "PP" from pinf_ex[OF pi p] have "?E" . } - moreover {assume f:"?F" hence "?E" by blast} - ultimately have "?E" by blast} - ultimately have "?E = ?D" by blast thus "?E \ ?D" by simp -qed - -lemmas minf_thms = minf_conj minf_disj minf_eq minf_neq minf_lt minf_le minf_gt minf_ge minf_P -lemmas pinf_thms = pinf_conj pinf_disj pinf_eq pinf_neq pinf_lt pinf_le pinf_gt pinf_ge pinf_P - -lemmas nmi_thms = nmi_conj nmi_disj nmi_eq nmi_neq nmi_lt nmi_le nmi_gt nmi_ge nmi_P -lemmas npi_thms = npi_conj npi_disj npi_eq npi_neq npi_lt npi_le npi_gt npi_ge npi_P -lemmas lin_dense_thms = lin_dense_conj lin_dense_disj lin_dense_eq lin_dense_neq lin_dense_lt lin_dense_le lin_dense_gt lin_dense_ge lin_dense_P - -lemma ferrack_axiom: "constr_dense_linear_order less_eq less between" - by (rule constr_dense_linear_order_axioms) -lemma atoms: - shows "TERM (less :: 'a \ _)" - and "TERM (less_eq :: 'a \ _)" - and "TERM (op = :: 'a \ _)" . - -declare ferrack_axiom [ferrack minf: minf_thms pinf: pinf_thms - nmi: nmi_thms npi: npi_thms lindense: - lin_dense_thms qe: fr_eq atoms: atoms] - -declaration {* -let -fun simps phi = map (Morphism.thm phi) [@{thm "not_less"}, @{thm "not_le"}] -fun generic_whatis phi = - let - val [lt, le] = map (Morphism.term phi) [@{term "op \"}, @{term "op \"}] - fun h x t = - case term_of t of - Const("op =", _)$y$z => if term_of x aconv y then Ferrante_Rackoff_Data.Eq - else Ferrante_Rackoff_Data.Nox - | @{term "Not"}$(Const("op =", _)$y$z) => if term_of x aconv y then Ferrante_Rackoff_Data.NEq - else Ferrante_Rackoff_Data.Nox - | b$y$z => if Term.could_unify (b, lt) then - if term_of x aconv y then Ferrante_Rackoff_Data.Lt - else if term_of x aconv z then Ferrante_Rackoff_Data.Gt - else Ferrante_Rackoff_Data.Nox - else if Term.could_unify (b, le) then - if term_of x aconv y then Ferrante_Rackoff_Data.Le - else if term_of x aconv z then Ferrante_Rackoff_Data.Ge - else Ferrante_Rackoff_Data.Nox - else Ferrante_Rackoff_Data.Nox - | _ => Ferrante_Rackoff_Data.Nox - in h end - fun ss phi = HOL_ss addsimps (simps phi) -in - Ferrante_Rackoff_Data.funs @{thm "ferrack_axiom"} - {isolate_conv = K (K (K Thm.reflexive)), whatis = generic_whatis, simpset = ss} -end -*} - -end - -use "~~/src/HOL/Tools/Qelim/ferrante_rackoff.ML" - -method_setup ferrack = {* - Method.ctxt_args (Method.SIMPLE_METHOD' o FerranteRackoff.dlo_tac) -*} "Ferrante and Rackoff's algorithm for quantifier elimination in dense linear orders" - -subsection {* Ferrante and Rackoff algorithm over ordered fields *} - -lemma neg_prod_lt:"(c\'a\ordered_field) < 0 \ ((c*x < 0) == (x > 0))" -proof- - assume H: "c < 0" - have "c*x < 0 = (0/c < x)" by (simp only: neg_divide_less_eq[OF H] algebra_simps) - also have "\ = (0 < x)" by simp - finally show "(c*x < 0) == (x > 0)" by simp -qed - -lemma pos_prod_lt:"(c\'a\ordered_field) > 0 \ ((c*x < 0) == (x < 0))" -proof- - assume H: "c > 0" - hence "c*x < 0 = (0/c > x)" by (simp only: pos_less_divide_eq[OF H] algebra_simps) - also have "\ = (0 > x)" by simp - finally show "(c*x < 0) == (x < 0)" by simp -qed - -lemma neg_prod_sum_lt: "(c\'a\ordered_field) < 0 \ ((c*x + t< 0) == (x > (- 1/c)*t))" -proof- - assume H: "c < 0" - have "c*x + t< 0 = (c*x < -t)" by (subst less_iff_diff_less_0 [of "c*x" "-t"], simp) - also have "\ = (-t/c < x)" by (simp only: neg_divide_less_eq[OF H] algebra_simps) - also have "\ = ((- 1/c)*t < x)" by simp - finally show "(c*x + t < 0) == (x > (- 1/c)*t)" by simp -qed - -lemma pos_prod_sum_lt:"(c\'a\ordered_field) > 0 \ ((c*x + t < 0) == (x < (- 1/c)*t))" -proof- - assume H: "c > 0" - have "c*x + t< 0 = (c*x < -t)" by (subst less_iff_diff_less_0 [of "c*x" "-t"], simp) - also have "\ = (-t/c > x)" by (simp only: pos_less_divide_eq[OF H] algebra_simps) - also have "\ = ((- 1/c)*t > x)" by simp - finally show "(c*x + t < 0) == (x < (- 1/c)*t)" by simp -qed - -lemma sum_lt:"((x::'a::pordered_ab_group_add) + t < 0) == (x < - t)" - using less_diff_eq[where a= x and b=t and c=0] by simp - -lemma neg_prod_le:"(c\'a\ordered_field) < 0 \ ((c*x <= 0) == (x >= 0))" -proof- - assume H: "c < 0" - have "c*x <= 0 = (0/c <= x)" by (simp only: neg_divide_le_eq[OF H] algebra_simps) - also have "\ = (0 <= x)" by simp - finally show "(c*x <= 0) == (x >= 0)" by simp -qed - -lemma pos_prod_le:"(c\'a\ordered_field) > 0 \ ((c*x <= 0) == (x <= 0))" -proof- - assume H: "c > 0" - hence "c*x <= 0 = (0/c >= x)" by (simp only: pos_le_divide_eq[OF H] algebra_simps) - also have "\ = (0 >= x)" by simp - finally show "(c*x <= 0) == (x <= 0)" by simp -qed - -lemma neg_prod_sum_le: "(c\'a\ordered_field) < 0 \ ((c*x + t <= 0) == (x >= (- 1/c)*t))" -proof- - assume H: "c < 0" - have "c*x + t <= 0 = (c*x <= -t)" by (subst le_iff_diff_le_0 [of "c*x" "-t"], simp) - also have "\ = (-t/c <= x)" by (simp only: neg_divide_le_eq[OF H] algebra_simps) - also have "\ = ((- 1/c)*t <= x)" by simp - finally show "(c*x + t <= 0) == (x >= (- 1/c)*t)" by simp -qed - -lemma pos_prod_sum_le:"(c\'a\ordered_field) > 0 \ ((c*x + t <= 0) == (x <= (- 1/c)*t))" -proof- - assume H: "c > 0" - have "c*x + t <= 0 = (c*x <= -t)" by (subst le_iff_diff_le_0 [of "c*x" "-t"], simp) - also have "\ = (-t/c >= x)" by (simp only: pos_le_divide_eq[OF H] algebra_simps) - also have "\ = ((- 1/c)*t >= x)" by simp - finally show "(c*x + t <= 0) == (x <= (- 1/c)*t)" by simp -qed - -lemma sum_le:"((x::'a::pordered_ab_group_add) + t <= 0) == (x <= - t)" - using le_diff_eq[where a= x and b=t and c=0] by simp - -lemma nz_prod_eq:"(c\'a\ordered_field) \ 0 \ ((c*x = 0) == (x = 0))" by simp -lemma nz_prod_sum_eq: "(c\'a\ordered_field) \ 0 \ ((c*x + t = 0) == (x = (- 1/c)*t))" -proof- - assume H: "c \ 0" - have "c*x + t = 0 = (c*x = -t)" by (subst eq_iff_diff_eq_0 [of "c*x" "-t"], simp) - also have "\ = (x = -t/c)" by (simp only: nonzero_eq_divide_eq[OF H] algebra_simps) - finally show "(c*x + t = 0) == (x = (- 1/c)*t)" by simp -qed -lemma sum_eq:"((x::'a::pordered_ab_group_add) + t = 0) == (x = - t)" - using eq_diff_eq[where a= x and b=t and c=0] by simp - - -interpretation class_ordered_field_dense_linear_order!: constr_dense_linear_order - "op <=" "op <" - "\ x y. 1/2 * ((x::'a::{ordered_field,recpower,number_ring}) + y)" -proof (unfold_locales, dlo, dlo, auto) - fix x y::'a assume lt: "x < y" - from less_half_sum[OF lt] show "x < (x + y) /2" by simp -next - fix x y::'a assume lt: "x < y" - from gt_half_sum[OF lt] show "(x + y) /2 < y" by simp -qed - -declaration{* -let -fun earlier [] x y = false - | earlier (h::t) x y = - if h aconvc y then false else if h aconvc x then true else earlier t x y; - -fun dest_frac ct = case term_of ct of - Const (@{const_name "HOL.divide"},_) $ a $ b=> - Rat.rat_of_quotient (snd (HOLogic.dest_number a), snd (HOLogic.dest_number b)) - | t => Rat.rat_of_int (snd (HOLogic.dest_number t)) - -fun mk_frac phi cT x = - let val (a, b) = Rat.quotient_of_rat x - in if b = 1 then Numeral.mk_cnumber cT a - else Thm.capply - (Thm.capply (Drule.cterm_rule (instantiate' [SOME cT] []) @{cpat "op /"}) - (Numeral.mk_cnumber cT a)) - (Numeral.mk_cnumber cT b) - end - -fun whatis x ct = case term_of ct of - Const(@{const_name "HOL.plus"}, _)$(Const(@{const_name "HOL.times"},_)$_$y)$_ => - if y aconv term_of x then ("c*x+t",[(funpow 2 Thm.dest_arg1) ct, Thm.dest_arg ct]) - else ("Nox",[]) -| Const(@{const_name "HOL.plus"}, _)$y$_ => - if y aconv term_of x then ("x+t",[Thm.dest_arg ct]) - else ("Nox",[]) -| Const(@{const_name "HOL.times"}, _)$_$y => - if y aconv term_of x then ("c*x",[Thm.dest_arg1 ct]) - else ("Nox",[]) -| t => if t aconv term_of x then ("x",[]) else ("Nox",[]); - -fun xnormalize_conv ctxt [] ct = reflexive ct -| xnormalize_conv ctxt (vs as (x::_)) ct = - case term_of ct of - Const(@{const_name HOL.less},_)$_$Const(@{const_name "HOL.zero"},_) => - (case whatis x (Thm.dest_arg1 ct) of - ("c*x+t",[c,t]) => - let - val cr = dest_frac c - val clt = Thm.dest_fun2 ct - val cz = Thm.dest_arg ct - val neg = cr - let - val T = ctyp_of_term x - val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_lt"} - val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv - (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th - in rth end - | ("c*x",[c]) => - let - val cr = dest_frac c - val clt = Thm.dest_fun2 ct - val cz = Thm.dest_arg ct - val neg = cr reflexive ct) - - -| Const(@{const_name HOL.less_eq},_)$_$Const(@{const_name "HOL.zero"},_) => - (case whatis x (Thm.dest_arg1 ct) of - ("c*x+t",[c,t]) => - let - val T = ctyp_of_term x - val cr = dest_frac c - val clt = Drule.cterm_rule (instantiate' [SOME T] []) @{cpat "op <"} - val cz = Thm.dest_arg ct - val neg = cr - let - val T = ctyp_of_term x - val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_le"} - val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv - (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th - in rth end - | ("c*x",[c]) => - let - val T = ctyp_of_term x - val cr = dest_frac c - val clt = Drule.cterm_rule (instantiate' [SOME T] []) @{cpat "op <"} - val cz = Thm.dest_arg ct - val neg = cr reflexive ct) - -| Const("op =",_)$_$Const(@{const_name "HOL.zero"},_) => - (case whatis x (Thm.dest_arg1 ct) of - ("c*x+t",[c,t]) => - let - val T = ctyp_of_term x - val cr = dest_frac c - val ceq = Thm.dest_fun2 ct - val cz = Thm.dest_arg ct - val cthp = Simplifier.rewrite (local_simpset_of ctxt) - (Thm.capply @{cterm "Trueprop"} - (Thm.capply @{cterm "Not"} (Thm.capply (Thm.capply ceq c) cz))) - val cth = equal_elim (symmetric cthp) TrueI - val th = implies_elim - (instantiate' [SOME T] (map SOME [c,x,t]) @{thm nz_prod_sum_eq}) cth - val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv - (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th - in rth end - | ("x+t",[t]) => - let - val T = ctyp_of_term x - val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_eq"} - val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv - (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th - in rth end - | ("c*x",[c]) => - let - val T = ctyp_of_term x - val cr = dest_frac c - val ceq = Thm.dest_fun2 ct - val cz = Thm.dest_arg ct - val cthp = Simplifier.rewrite (local_simpset_of ctxt) - (Thm.capply @{cterm "Trueprop"} - (Thm.capply @{cterm "Not"} (Thm.capply (Thm.capply ceq c) cz))) - val cth = equal_elim (symmetric cthp) TrueI - val rth = implies_elim - (instantiate' [SOME T] (map SOME [c,x]) @{thm nz_prod_eq}) cth - in rth end - | _ => reflexive ct); - -local - val less_iff_diff_less_0 = mk_meta_eq @{thm "less_iff_diff_less_0"} - val le_iff_diff_le_0 = mk_meta_eq @{thm "le_iff_diff_le_0"} - val eq_iff_diff_eq_0 = mk_meta_eq @{thm "eq_iff_diff_eq_0"} -in -fun field_isolate_conv phi ctxt vs ct = case term_of ct of - Const(@{const_name HOL.less},_)$a$b => - let val (ca,cb) = Thm.dest_binop ct - val T = ctyp_of_term ca - val th = instantiate' [SOME T] [SOME ca, SOME cb] less_iff_diff_less_0 - val nth = Conv.fconv_rule - (Conv.arg_conv (Conv.arg1_conv - (Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th - val rth = transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth)) - in rth end -| Const(@{const_name HOL.less_eq},_)$a$b => - let val (ca,cb) = Thm.dest_binop ct - val T = ctyp_of_term ca - val th = instantiate' [SOME T] [SOME ca, SOME cb] le_iff_diff_le_0 - val nth = Conv.fconv_rule - (Conv.arg_conv (Conv.arg1_conv - (Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th - val rth = transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth)) - in rth end - -| Const("op =",_)$a$b => - let val (ca,cb) = Thm.dest_binop ct - val T = ctyp_of_term ca - val th = instantiate' [SOME T] [SOME ca, SOME cb] eq_iff_diff_eq_0 - val nth = Conv.fconv_rule - (Conv.arg_conv (Conv.arg1_conv - (Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th - val rth = transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth)) - in rth end -| @{term "Not"} $(Const("op =",_)$a$b) => Conv.arg_conv (field_isolate_conv phi ctxt vs) ct -| _ => reflexive ct -end; - -fun classfield_whatis phi = - let - fun h x t = - case term_of t of - Const("op =", _)$y$z => if term_of x aconv y then Ferrante_Rackoff_Data.Eq - else Ferrante_Rackoff_Data.Nox - | @{term "Not"}$(Const("op =", _)$y$z) => if term_of x aconv y then Ferrante_Rackoff_Data.NEq - else Ferrante_Rackoff_Data.Nox - | Const(@{const_name HOL.less},_)$y$z => - if term_of x aconv y then Ferrante_Rackoff_Data.Lt - else if term_of x aconv z then Ferrante_Rackoff_Data.Gt - else Ferrante_Rackoff_Data.Nox - | Const (@{const_name HOL.less_eq},_)$y$z => - if term_of x aconv y then Ferrante_Rackoff_Data.Le - else if term_of x aconv z then Ferrante_Rackoff_Data.Ge - else Ferrante_Rackoff_Data.Nox - | _ => Ferrante_Rackoff_Data.Nox - in h end; -fun class_field_ss phi = - HOL_basic_ss addsimps ([@{thm "linorder_not_less"}, @{thm "linorder_not_le"}]) - addsplits [@{thm "abs_split"},@{thm "split_max"}, @{thm "split_min"}] - -in -Ferrante_Rackoff_Data.funs @{thm "class_ordered_field_dense_linear_order.ferrack_axiom"} - {isolate_conv = field_isolate_conv, whatis = classfield_whatis, simpset = class_field_ss} -end -*} - - -end diff -r a521a6fab39b -r 3ccd86c214bf src/HOL/IsaMakefile --- a/src/HOL/IsaMakefile Fri Feb 06 00:10:58 2009 +0000 +++ b/src/HOL/IsaMakefile Fri Feb 06 00:13:15 2009 +0000 @@ -284,7 +284,6 @@ Series.thy \ Taylor.thy \ Transcendental.thy \ - Dense_Linear_Order.thy \ GCD.thy \ Order_Relation.thy \ Parity.thy \ @@ -316,7 +315,7 @@ Library/Abstract_Rat.thy \ Library/BigO.thy Library/ContNotDenum.thy Library/Efficient_Nat.thy \ Library/Executable_Set.thy Library/Infinite_Set.thy \ - Library/FuncSet.thy \ + Library/FuncSet.thy Library/Dense_Linear_Order.thy \ Library/Library.thy Library/List_Prefix.thy Library/State_Monad.thy \ Library/Multiset.thy Library/Permutation.thy \ Library/Primes.thy Library/Pocklington.thy Library/Quotient.thy \