# HG changeset patch # User haftmann # Date 1187626048 -7200 # Node ID a0fd8c2db29364c9b398bb8db089bcc581b82b3a # Parent acc0f7aac6190fdd11eed81380cb906a6988754e turned locales intro classes diff -r acc0f7aac619 -r a0fd8c2db293 src/HOL/Dense_Linear_Order.thy --- a/src/HOL/Dense_Linear_Order.thy Mon Aug 20 18:07:26 2007 +0200 +++ b/src/HOL/Dense_Linear_Order.thy Mon Aug 20 18:07:28 2007 +0200 @@ -16,67 +16,13 @@ ("Tools/Qelim/ferrante_rackoff.ML") begin - setup Langford_Data.setup setup Ferrante_Rackoff_Data.setup -section {* The classical QE after Langford for dense linear orders *} - -locale dense_linear_order = Linorder + - assumes gt_ex: "\x. \y. x \ y" - and lt_ex: "\x. \y. y \ x" - and dense: "\x y. x \ y \ (\z. x \ z \ z \ y)" +context linorder begin -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 \<^loc>< x) \ (\y\U. x \<^loc>< y)" - then obtain x where xL: "\y\L. y \<^loc>< x" and xU: "\y\U. x \<^loc>< y" by blast - {fix l u assume l: "l \ L" and u: "u \ U" - from less_trans[OF xL[rule_format, OF l] xU[rule_format, OF u]] - have "l \ u" .} - thus "\l\L. \u\U. l \<^loc>< u" by blast -next - assume H: "\l\L. \u\U. l \<^loc>< 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" - apply auto - apply (erule_tac x="l" in ballE) - by (auto intro: le_less_trans) - - moreover from th4 th2' have "\u \ U. w \ u" - apply auto - apply (erule_tac x="u" in ballE) - by (auto intro: less_le_trans) - ultimately show "\x. (\y\L. y \<^loc>< x) \ (\y\U. x \<^loc>< 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[rule_format, 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 \<^loc>< 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[rule_format, 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 \<^loc>< y" by blast -qed +lemma less_not_permute: "\ (x \ y \ y \ x)" by (simp add: not_less linear) lemma gather_simps: shows @@ -89,61 +35,6 @@ gather_start: "(\x. P x) \ (\x. (\y \ {}. y \<^loc>< x) \ (\y\ {}. x \ y) \ P x)" by simp -lemma exists_neq: "\(x::'a). x \ t" "\(x::'a). t \ x" - using gt_ex[rule_format, of t] by auto - -lemma less_not_permute: "\ (x \ y \ y \ x)" by (simp add: not_less linear) - -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 \)" . -lemma atoms: includes meta_term_syntax - shows "TERM (op \ :: 'a \ _)" and "TERM (op \)" 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 "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" - -interpretation dlo_ordring_class: dense_linear_order["op \ :: 'a::{ordered_field} \ _" "op <"] -apply unfold_locales -apply auto -apply (rule_tac x = "x + 1" in exI, simp) -apply (rule_tac x = "x - 1" in exI, simp) -apply (rule_tac x = "(x + y) / (1 + 1)" in exI) -apply (rule conjI) -apply (rule less_half_sum, simp) -apply (rule gt_half_sum, simp) -done - -section {* Contructive dense linear orders yield QE for linear arithmetic over ordered Fields -- see @{text "Arith_Tools.thy"} *} - -context Linorder -begin - 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)" @@ -303,7 +194,6 @@ 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" @@ -319,9 +209,121 @@ end +section {* The classical QE after Langford for dense linear orders *} + +class dense_linear_order = linorder + + assumes gt_ex: "\x. \y. x \ y" + and lt_ex: "\x. \y. y \ x" + and dense: "\x y. x \ y \ (\z. x \ z \ z \ y)" +begin + +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 \<^loc>< x) \ (\y\U. x \<^loc>< y)" + then obtain x where xL: "\y\L. y \<^loc>< x" and xU: "\y\U. x \<^loc>< y" by blast + {fix l u assume l: "l \ L" and u: "u \ U" + from less_trans[OF xL[rule_format, OF l] xU[rule_format, OF u]] + have "l \ u" .} + thus "\l\L. \u\U. l \<^loc>< u" by blast +next + assume H: "\l\L. \u\U. l \<^loc>< 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" + apply auto + apply (erule_tac x="l" in ballE) + by (auto intro: le_less_trans) + + moreover from th4 th2' have "\u \ U. w \ u" + apply auto + apply (erule_tac x="u" in ballE) + by (auto intro: less_le_trans) + ultimately show "\x. (\y\L. y \<^loc>< x) \ (\y\U. x \<^loc>< 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[rule_format, 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 \<^loc>< 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[rule_format, 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 \<^loc>< y" by blast +qed + +lemma exists_neq: "\(x::'a). x \ t" "\(x::'a). t \ x" + using gt_ex[rule_format, 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 \)" . +lemma atoms: includes meta_term_syntax + shows "TERM (op \ :: 'a \ _)" and "TERM (op \)" 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 "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" + +interpretation dlo_ordring_class: dense_linear_order ["op \ \ 'a\ordered_field \ _" "op <"] +apply unfold_locales +apply auto +apply (rule_tac x = "x + 1" in exI, simp) +apply (rule_tac x = "x - 1" in exI, simp) +apply (rule_tac x = "(x + y) / (1 + 1)" in exI) +apply (rule conjI) +apply (rule less_half_sum, simp) +apply (rule gt_half_sum, simp) +done + + +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_no_ub = Linorder + assumes gt_ex: "\x. \y. x \ y" +class linorder_no_ub = linorder + + assumes gt_ex: "\x. \y. x \ y" begin lemma ge_ex: "\x. \y. x \ y" using gt_ex by auto @@ -370,7 +372,8 @@ text {* Linear order without upper bounds *} -locale linorder_no_lb = Linorder + assumes lt_ex: "\x. \y. y \ x" +class linorder_no_lb = linorder + + assumes lt_ex: "\x. \y. y \ x" begin lemma le_ex: "\x. \y. y \ x" using lt_ex by auto @@ -416,12 +419,13 @@ end -locale constr_dense_linear_order = linorder_no_lb + linorder_no_ub + + +class constr_dense_linear_order = linorder_no_lb + linorder_no_ub + fixes between assumes between_less: "\x y. x \ y \ x \ between x y \ between x y \ y" and between_same: "\x. between x x = x" -interpretation constr_dense_linear_order < dense_linear_order +instance advanced 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) @@ -547,11 +551,14 @@ end - use "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" + +(*FIXME: synchronize dense orders with existing algebra*) +lemmas dense = Ring_and_Field.dense + end diff -r acc0f7aac619 -r a0fd8c2db293 src/HOL/ex/Meson_Test.thy --- a/src/HOL/ex/Meson_Test.thy Mon Aug 20 18:07:26 2007 +0200 +++ b/src/HOL/ex/Meson_Test.thy Mon Aug 20 18:07:28 2007 +0200 @@ -11,7 +11,7 @@ below and constants declared in HOL! *} -hide const subset member quotient +hide const subset member quotient between text {*