
berghofe@13876: (*  Title:      HOL/Integ/Presburger.thy
berghofe@13876:     ID:         $Id$
berghofe@13876:     Author:     Amine Chaieb, Tobias Nipkow and Stefan Berghofer, TU Muenchen
berghofe@13876: 
berghofe@13876: File containing necessary theorems for the proof
berghofe@13876: generation for Cooper Algorithm  
berghofe@13876: *)
berghofe@13876: 
nipkow@15131: header {* Presburger Arithmetic: Cooper's Algorithm *}
wenzelm@14577: 
nipkow@15131: theory Presburger
nipkow@15140: imports NatSimprocs SetInterval
chaieb@17378: uses ("cooper_dec.ML") ("cooper_proof.ML") ("qelim.ML") 
chaieb@17378: 	("reflected_presburger.ML") ("reflected_cooper.ML") ("presburger.ML")
nipkow@15131: begin
berghofe@13876: 
wenzelm@14577: text {* Theorem for unitifying the coeffitients of @{text x} in an existential formula*}
berghofe@13876: 
berghofe@13876: theorem unity_coeff_ex: "(\<exists>x::int. P (l * x)) = (\<exists>x. l dvd (1*x+0) \<and> P x)"
berghofe@13876:   apply (rule iffI)
berghofe@13876:   apply (erule exE)
berghofe@13876:   apply (rule_tac x = "l * x" in exI)
berghofe@13876:   apply simp
berghofe@13876:   apply (erule exE)
berghofe@13876:   apply (erule conjE)
berghofe@13876:   apply (erule dvdE)
berghofe@13876:   apply (rule_tac x = k in exI)
berghofe@13876:   apply simp
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: lemma uminus_dvd_conv: "(d dvd (t::int)) = (-d dvd t)"
berghofe@13876: apply(unfold dvd_def)
berghofe@13876: apply(rule iffI)
berghofe@13876: apply(clarsimp)
berghofe@13876: apply(rename_tac k)
berghofe@13876: apply(rule_tac x = "-k" in exI)
berghofe@13876: apply simp
berghofe@13876: apply(clarsimp)
berghofe@13876: apply(rename_tac k)
berghofe@13876: apply(rule_tac x = "-k" in exI)
berghofe@13876: apply simp
berghofe@13876: done
berghofe@13876: 
berghofe@13876: lemma uminus_dvd_conv': "(d dvd (t::int)) = (d dvd -t)"
berghofe@13876: apply(unfold dvd_def)
berghofe@13876: apply(rule iffI)
berghofe@13876: apply(clarsimp)
berghofe@13876: apply(rule_tac x = "-k" in exI)
berghofe@13876: apply simp
berghofe@13876: apply(clarsimp)
berghofe@13876: apply(rule_tac x = "-k" in exI)
berghofe@13876: apply simp
berghofe@13876: done
berghofe@13876: 
berghofe@13876: 
berghofe@13876: 
wenzelm@14577: text {*Theorems for the combination of proofs of the equality of @{text P} and @{text P_m} for integers @{text x} less than some integer @{text z}.*}
berghofe@13876: 
berghofe@13876: theorem eq_minf_conjI: "\<exists>z1::int. \<forall>x. x < z1 \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
berghofe@13876:   \<exists>z2::int. \<forall>x. x < z2 \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
berghofe@13876:   \<exists>z::int. \<forall>x. x < z \<longrightarrow> ((A1 x \<and> B1 x) = (A2 x \<and> B2 x))"
berghofe@13876:   apply (erule exE)+
berghofe@13876:   apply (rule_tac x = "min z1 z2" in exI)
berghofe@13876:   apply simp
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: 
berghofe@13876: theorem eq_minf_disjI: "\<exists>z1::int. \<forall>x. x < z1 \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
berghofe@13876:   \<exists>z2::int. \<forall>x. x < z2 \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
berghofe@13876:   \<exists>z::int. \<forall>x. x < z \<longrightarrow> ((A1 x \<or> B1 x) = (A2 x \<or> B2 x))"
berghofe@13876: 
berghofe@13876:   apply (erule exE)+
berghofe@13876:   apply (rule_tac x = "min z1 z2" in exI)
berghofe@13876:   apply simp
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: 
wenzelm@14577: text {*Theorems for the combination of proofs of the equality of @{text P} and @{text P_m} for integers @{text x} greather than some integer @{text z}.*}
berghofe@13876: 
berghofe@13876: theorem eq_pinf_conjI: "\<exists>z1::int. \<forall>x. z1 < x \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
berghofe@13876:   \<exists>z2::int. \<forall>x. z2 < x \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
berghofe@13876:   \<exists>z::int. \<forall>x. z < x \<longrightarrow> ((A1 x \<and> B1 x) = (A2 x \<and> B2 x))"
berghofe@13876:   apply (erule exE)+
berghofe@13876:   apply (rule_tac x = "max z1 z2" in exI)
berghofe@13876:   apply simp
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: 
berghofe@13876: theorem eq_pinf_disjI: "\<exists>z1::int. \<forall>x. z1 < x \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
berghofe@13876:   \<exists>z2::int. \<forall>x. z2 < x \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
berghofe@13876:   \<exists>z::int. \<forall>x. z < x  \<longrightarrow> ((A1 x \<or> B1 x) = (A2 x \<or> B2 x))"
berghofe@13876:   apply (erule exE)+
berghofe@13876:   apply (rule_tac x = "max z1 z2" in exI)
berghofe@13876:   apply simp
berghofe@13876:   done
wenzelm@14577: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip Theorems for the combination of proofs of the modulo @{text
wenzelm@14577:   D} property for @{text "P plusinfinity"}
wenzelm@14577: 
wenzelm@14577:   FIXME: This is THE SAME theorem as for the @{text minusinf} version,
wenzelm@14577:   but with @{text "+k.."} instead of @{text "-k.."} In the future
wenzelm@14577:   replace these both with only one. *}
berghofe@13876: 
berghofe@13876: theorem modd_pinf_conjI: "\<forall>(x::int) k. A x = A (x+k*d) \<Longrightarrow>
berghofe@13876:   \<forall>(x::int) k. B x = B (x+k*d) \<Longrightarrow>
berghofe@13876:   \<forall>(x::int) (k::int). (A x \<and> B x) = (A (x+k*d) \<and> B (x+k*d))"
berghofe@13876:   by simp
berghofe@13876: 
berghofe@13876: theorem modd_pinf_disjI: "\<forall>(x::int) k. A x = A (x+k*d) \<Longrightarrow>
berghofe@13876:   \<forall>(x::int) k. B x = B (x+k*d) \<Longrightarrow>
berghofe@13876:   \<forall>(x::int) (k::int). (A x \<or> B x) = (A (x+k*d) \<or> B (x+k*d))"
berghofe@13876:   by simp
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   This is one of the cases where the simplifed formula is prooved to
wenzelm@14577:   habe some property (in relation to @{text P_m}) but we need to prove
wenzelm@14577:   the property for the original formula (@{text P_m})
wenzelm@14577: 
wenzelm@14577:   FIXME: This is exaclty the same thm as for @{text minusinf}. *}
wenzelm@14577: 
berghofe@13876: lemma pinf_simp_eq: "ALL x. P(x) = Q(x) ==> (EX (x::int). P(x)) --> (EX (x::int). F(x))  ==> (EX (x::int). Q(x)) --> (EX (x::int). F(x)) "
wenzelm@14577:   by blast
berghofe@13876: 
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip Theorems for the combination of proofs of the modulo @{text D}
wenzelm@14577:   property for @{text "P minusinfinity"} *}
berghofe@13876: 
berghofe@13876: theorem modd_minf_conjI: "\<forall>(x::int) k. A x = A (x-k*d) \<Longrightarrow>
berghofe@13876:   \<forall>(x::int) k. B x = B (x-k*d) \<Longrightarrow>
berghofe@13876:   \<forall>(x::int) (k::int). (A x \<and> B x) = (A (x-k*d) \<and> B (x-k*d))"
berghofe@13876:   by simp
berghofe@13876: 
berghofe@13876: theorem modd_minf_disjI: "\<forall>(x::int) k. A x = A (x-k*d) \<Longrightarrow>
berghofe@13876:   \<forall>(x::int) k. B x = B (x-k*d) \<Longrightarrow>
berghofe@13876:   \<forall>(x::int) (k::int). (A x \<or> B x) = (A (x-k*d) \<or> B (x-k*d))"
berghofe@13876:   by simp
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   This is one of the cases where the simplifed formula is prooved to
wenzelm@14577:   have some property (in relation to @{text P_m}) but we need to
wenzelm@14577:   prove the property for the original formula (@{text P_m}). *}
berghofe@13876: 
berghofe@13876: lemma minf_simp_eq: "ALL x. P(x) = Q(x) ==> (EX (x::int). P(x)) --> (EX (x::int). F(x))  ==> (EX (x::int). Q(x)) --> (EX (x::int). F(x)) "
wenzelm@14577:   by blast
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   Theorem needed for proving at runtime divide properties using the
wenzelm@14577:   arithmetic tactic (which knows only about modulo = 0). *}
berghofe@13876: 
berghofe@13876: lemma zdvd_iff_zmod_eq_0: "(m dvd n) = (n mod m = (0::int))"
wenzelm@14577:   by(simp add:dvd_def zmod_eq_0_iff)
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip Theorems used for the combination of proof for the
wenzelm@14577:   backwards direction of Cooper's Theorem. They rely exclusively on
wenzelm@14577:   Predicate calculus.*}
berghofe@13876: 
berghofe@13876: lemma not_ast_p_disjI: "(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P1(x) --> P1(x + d))
berghofe@13876: ==>
berghofe@13876: (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P2(x) --> P2(x + d))
berghofe@13876: ==>
berghofe@13876: (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) -->(P1(x) \<or> P2(x)) --> (P1(x + d) \<or> P2(x + d))) "
wenzelm@14577:   by blast
berghofe@13876: 
berghofe@13876: 
berghofe@13876: lemma not_ast_p_conjI: "(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a- j)) --> P1(x) --> P1(x + d))
berghofe@13876: ==>
berghofe@13876: (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P2(x) --> P2(x + d))
berghofe@13876: ==>
berghofe@13876: (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) -->(P1(x) \<and> P2(x)) --> (P1(x + d)
berghofe@13876: \<and> P2(x + d))) "
wenzelm@14577:   by blast
berghofe@13876: 
berghofe@13876: lemma not_ast_p_Q_elim: "
berghofe@13876: (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) -->P(x) --> P(x + d))
berghofe@13876: ==> ( P = Q )
berghofe@13876: ==> (ALL x. ~(EX (j::int) : {1..d}. EX (a::int) : A. P(a - j)) -->P(x) --> P(x + d))"
wenzelm@14577:   by blast
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip Theorems used for the combination of proof for the
wenzelm@14577:   backwards direction of Cooper's Theorem. They rely exclusively on
wenzelm@14577:   Predicate calculus.*}
berghofe@13876: 
berghofe@13876: lemma not_bst_p_disjI: "(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P1(x) --> P1(x - d))
berghofe@13876: ==>
berghofe@13876: (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P2(x) --> P2(x - d))
berghofe@13876: ==>
berghofe@13876: (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) -->(P1(x) \<or> P2(x)) --> (P1(x - d)
berghofe@13876: \<or> P2(x-d))) "
wenzelm@14577:   by blast
berghofe@13876: 
berghofe@13876: lemma not_bst_p_conjI: "(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P1(x) --> P1(x - d))
berghofe@13876: ==>
berghofe@13876: (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P2(x) --> P2(x - d))
berghofe@13876: ==>
berghofe@13876: (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) -->(P1(x) \<and> P2(x)) --> (P1(x - d)
berghofe@13876: \<and> P2(x-d))) "
wenzelm@14577:   by blast
berghofe@13876: 
berghofe@13876: lemma not_bst_p_Q_elim: "
berghofe@13876: (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) -->P(x) --> P(x - d)) 
berghofe@13876: ==> ( P = Q )
berghofe@13876: ==> (ALL x. ~(EX (j::int) : {1..d}. EX (b::int) : B. P(b+j)) -->P(x) --> P(x - d))"
wenzelm@14577:   by blast
berghofe@13876: 
wenzelm@14577: text {* \medskip This is the first direction of Cooper's Theorem. *}
berghofe@13876: lemma cooper_thm: "(R --> (EX x::int. P x))  ==> (Q -->(EX x::int.  P x )) ==> ((R|Q) --> (EX x::int. P x )) "
wenzelm@14577:   by blast
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip The full Cooper's Theorem in its equivalence Form. Given
wenzelm@14577:   the premises it is trivial too, it relies exclusively on prediacte calculus.*}
berghofe@13876: lemma cooper_eq_thm: "(R --> (EX x::int. P x))  ==> (Q -->(EX x::int.  P x )) ==> ((~Q)
berghofe@13876: --> (EX x::int. P x ) --> R) ==> (EX x::int. P x) = R|Q "
wenzelm@14577:   by blast
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip Some of the atomic theorems generated each time the atom
wenzelm@14577:   does not depend on @{text x}, they are trivial.*}
berghofe@13876: 
berghofe@13876: lemma  fm_eq_minf: "EX z::int. ALL x. x < z --> (P = P) "
wenzelm@14577:   by blast
berghofe@13876: 
berghofe@13876: lemma  fm_modd_minf: "ALL (x::int). ALL (k::int). (P = P)"
wenzelm@14577:   by blast
berghofe@13876: 
berghofe@13876: lemma not_bst_p_fm: "ALL (x::int). Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> fm --> fm"
wenzelm@14577:   by blast
berghofe@13876: 
berghofe@13876: lemma  fm_eq_pinf: "EX z::int. ALL x. z < x --> (P = P) "
wenzelm@14577:   by blast
berghofe@13876: 
wenzelm@14577: text {* The next two thms are the same as the @{text minusinf} version. *}
wenzelm@14577: 
berghofe@13876: lemma  fm_modd_pinf: "ALL (x::int). ALL (k::int). (P = P)"
wenzelm@14577:   by blast
berghofe@13876: 
berghofe@13876: lemma not_ast_p_fm: "ALL (x::int). Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> fm --> fm"
wenzelm@14577:   by blast
berghofe@13876: 
wenzelm@14577: text {* Theorems to be deleted from simpset when proving simplified formulaes. *}
berghofe@13876: 
berghofe@13876: lemma P_eqtrue: "(P=True) = P"
nipkow@17589:   by iprover
berghofe@13876: 
berghofe@13876: lemma P_eqfalse: "(P=False) = (~P)"
nipkow@17589:   by iprover
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip Theorems for the generation of the bachwards direction of
wenzelm@14577:   Cooper's Theorem.
berghofe@13876: 
wenzelm@14577:   These are the 6 interesting atomic cases which have to be proved relying on the
wenzelm@14577:   properties of B-set and the arithmetic and contradiction proofs. *}
berghofe@13876: 
berghofe@13876: lemma not_bst_p_lt: "0 < (d::int) ==>
berghofe@13876:  ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> ( 0 < -x + a) --> (0 < -(x - d) + a )"
wenzelm@14577:   by arith
berghofe@13876: 
berghofe@13876: lemma not_bst_p_gt: "\<lbrakk> (g::int) \<in> B; g = -a \<rbrakk> \<Longrightarrow>
berghofe@13876:  ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> (0 < (x) + a) --> ( 0 < (x - d) + a)"
berghofe@13876: apply clarsimp
berghofe@13876: apply(rule ccontr)
berghofe@13876: apply(drule_tac x = "x+a" in bspec)
berghofe@13876: apply(simp add:atLeastAtMost_iff)
berghofe@13876: apply(drule_tac x = "-a" in bspec)
berghofe@13876: apply assumption
berghofe@13876: apply(simp)
berghofe@13876: done
berghofe@13876: 
berghofe@13876: lemma not_bst_p_eq: "\<lbrakk> 0 < d; (g::int) \<in> B; g = -a - 1 \<rbrakk> \<Longrightarrow>
berghofe@13876:  ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> (0 = x + a) --> (0 = (x - d) + a )"
berghofe@13876: apply clarsimp
berghofe@13876: apply(subgoal_tac "x = -a")
berghofe@13876:  prefer 2 apply arith
berghofe@13876: apply(drule_tac x = "1" in bspec)
berghofe@13876: apply(simp add:atLeastAtMost_iff)
berghofe@13876: apply(drule_tac x = "-a- 1" in bspec)
berghofe@13876: apply assumption
berghofe@13876: apply(simp)
berghofe@13876: done
berghofe@13876: 
berghofe@13876: 
berghofe@13876: lemma not_bst_p_ne: "\<lbrakk> 0 < d; (g::int) \<in> B; g = -a \<rbrakk> \<Longrightarrow>
berghofe@13876:  ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> ~(0 = x + a) --> ~(0 = (x - d) + a)"
berghofe@13876: apply clarsimp
berghofe@13876: apply(subgoal_tac "x = -a+d")
berghofe@13876:  prefer 2 apply arith
berghofe@13876: apply(drule_tac x = "d" in bspec)
berghofe@13876: apply(simp add:atLeastAtMost_iff)
berghofe@13876: apply(drule_tac x = "-a" in bspec)
berghofe@13876: apply assumption
berghofe@13876: apply(simp)
berghofe@13876: done
berghofe@13876: 
berghofe@13876: 
berghofe@13876: lemma not_bst_p_dvd: "(d1::int) dvd d ==>
berghofe@13876:  ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> d1 dvd (x + a) --> d1 dvd ((x - d) + a )"
berghofe@13876: apply(clarsimp simp add:dvd_def)
berghofe@13876: apply(rename_tac m)
berghofe@13876: apply(rule_tac x = "m - k" in exI)
berghofe@13876: apply(simp add:int_distrib)
berghofe@13876: done
berghofe@13876: 
berghofe@13876: lemma not_bst_p_ndvd: "(d1::int) dvd d ==>
berghofe@13876:  ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> ~(d1 dvd (x + a)) --> ~(d1 dvd ((x - d) + a ))"
berghofe@13876: apply(clarsimp simp add:dvd_def)
berghofe@13876: apply(rename_tac m)
berghofe@13876: apply(erule_tac x = "m + k" in allE)
berghofe@13876: apply(simp add:int_distrib)
berghofe@13876: done
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip Theorems for the generation of the bachwards direction of
wenzelm@14577:   Cooper's Theorem.
berghofe@13876: 
wenzelm@14577:   These are the 6 interesting atomic cases which have to be proved
wenzelm@14577:   relying on the properties of A-set ant the arithmetic and
wenzelm@14577:   contradiction proofs. *}
berghofe@13876: 
berghofe@13876: lemma not_ast_p_gt: "0 < (d::int) ==>
berghofe@13876:  ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> ( 0 < x + t) --> (0 < (x + d) + t )"
wenzelm@14577:   by arith
berghofe@13876: 
berghofe@13876: lemma not_ast_p_lt: "\<lbrakk>0 < d ;(t::int) \<in> A \<rbrakk> \<Longrightarrow>
berghofe@13876:  ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> (0 < -x + t) --> ( 0 < -(x + d) + t)"
berghofe@13876:   apply clarsimp
berghofe@13876:   apply (rule ccontr)
berghofe@13876:   apply (drule_tac x = "t-x" in bspec)
berghofe@13876:   apply simp
berghofe@13876:   apply (drule_tac x = "t" in bspec)
berghofe@13876:   apply assumption
berghofe@13876:   apply simp
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: lemma not_ast_p_eq: "\<lbrakk> 0 < d; (g::int) \<in> A; g = -t + 1 \<rbrakk> \<Longrightarrow>
berghofe@13876:  ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> (0 = x + t) --> (0 = (x + d) + t )"
berghofe@13876:   apply clarsimp
berghofe@13876:   apply (drule_tac x="1" in bspec)
berghofe@13876:   apply simp
berghofe@13876:   apply (drule_tac x="- t + 1" in bspec)
berghofe@13876:   apply assumption
berghofe@13876:   apply(subgoal_tac "x = -t")
berghofe@13876:   prefer 2 apply arith
berghofe@13876:   apply simp
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: lemma not_ast_p_ne: "\<lbrakk> 0 < d; (g::int) \<in> A; g = -t \<rbrakk> \<Longrightarrow>
berghofe@13876:  ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> ~(0 = x + t) --> ~(0 = (x + d) + t)"
berghofe@13876:   apply clarsimp
berghofe@13876:   apply (subgoal_tac "x = -t-d")
berghofe@13876:   prefer 2 apply arith
berghofe@13876:   apply (drule_tac x = "d" in bspec)
berghofe@13876:   apply simp
berghofe@13876:   apply (drule_tac x = "-t" in bspec)
berghofe@13876:   apply assumption
berghofe@13876:   apply simp
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: lemma not_ast_p_dvd: "(d1::int) dvd d ==>
berghofe@13876:  ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> d1 dvd (x + t) --> d1 dvd ((x + d) + t )"
berghofe@13876:   apply(clarsimp simp add:dvd_def)
berghofe@13876:   apply(rename_tac m)
berghofe@13876:   apply(rule_tac x = "m + k" in exI)
berghofe@13876:   apply(simp add:int_distrib)
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: lemma not_ast_p_ndvd: "(d1::int) dvd d ==>
berghofe@13876:  ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> ~(d1 dvd (x + t)) --> ~(d1 dvd ((x + d) + t ))"
berghofe@13876:   apply(clarsimp simp add:dvd_def)
berghofe@13876:   apply(rename_tac m)
berghofe@13876:   apply(erule_tac x = "m - k" in allE)
berghofe@13876:   apply(simp add:int_distrib)
berghofe@13876:   done
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip These are the atomic cases for the proof generation for the
wenzelm@14577:   modulo @{text D} property for @{text "P plusinfinity"}
berghofe@13876: 
wenzelm@14577:   They are fully based on arithmetics. *}
berghofe@13876: 
berghofe@13876: lemma  dvd_modd_pinf: "((d::int) dvd d1) ==>
berghofe@13876:  (ALL (x::int). ALL (k::int). (((d::int) dvd (x + t)) = (d dvd (x+k*d1 + t))))"
berghofe@13876:   apply(clarsimp simp add:dvd_def)
berghofe@13876:   apply(rule iffI)
berghofe@13876:   apply(clarsimp)
berghofe@13876:   apply(rename_tac n m)
berghofe@13876:   apply(rule_tac x = "m + n*k" in exI)
berghofe@13876:   apply(simp add:int_distrib)
berghofe@13876:   apply(clarsimp)
berghofe@13876:   apply(rename_tac n m)
berghofe@13876:   apply(rule_tac x = "m - n*k" in exI)
paulson@14271:   apply(simp add:int_distrib mult_ac)
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: lemma  not_dvd_modd_pinf: "((d::int) dvd d1) ==>
berghofe@13876:  (ALL (x::int). ALL k. (~((d::int) dvd (x + t))) = (~(d dvd (x+k*d1 + t))))"
berghofe@13876:   apply(clarsimp simp add:dvd_def)
berghofe@13876:   apply(rule iffI)
berghofe@13876:   apply(clarsimp)
berghofe@13876:   apply(rename_tac n m)
berghofe@13876:   apply(erule_tac x = "m - n*k" in allE)
paulson@14271:   apply(simp add:int_distrib mult_ac)
berghofe@13876:   apply(clarsimp)
berghofe@13876:   apply(rename_tac n m)
berghofe@13876:   apply(erule_tac x = "m + n*k" in allE)
paulson@14271:   apply(simp add:int_distrib mult_ac)
berghofe@13876:   done
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip These are the atomic cases for the proof generation for the
wenzelm@14577:   equivalence of @{text P} and @{text "P plusinfinity"} for integers
wenzelm@14577:   @{text x} greater than some integer @{text z}.
wenzelm@14577: 
wenzelm@14577:   They are fully based on arithmetics. *}
berghofe@13876: 
berghofe@13876: lemma  eq_eq_pinf: "EX z::int. ALL x. z < x --> (( 0 = x +t ) = False )"
berghofe@13876:   apply(rule_tac x = "-t" in exI)
berghofe@13876:   apply simp
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: lemma  neq_eq_pinf: "EX z::int. ALL x.  z < x --> ((~( 0 = x +t )) = True )"
berghofe@13876:   apply(rule_tac x = "-t" in exI)
berghofe@13876:   apply simp
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: lemma  le_eq_pinf: "EX z::int. ALL x.  z < x --> ( 0 < x +t  = True )"
berghofe@13876:   apply(rule_tac x = "-t" in exI)
berghofe@13876:   apply simp
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: lemma  len_eq_pinf: "EX z::int. ALL x. z < x  --> (0 < -x +t  = False )"
berghofe@13876:   apply(rule_tac x = "t" in exI)
berghofe@13876:   apply simp
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: lemma  dvd_eq_pinf: "EX z::int. ALL x.  z < x --> ((d dvd (x + t)) = (d dvd (x + t))) "
wenzelm@14577:   by simp
berghofe@13876: 
berghofe@13876: lemma  not_dvd_eq_pinf: "EX z::int. ALL x. z < x  --> ((~(d dvd (x + t))) = (~(d dvd (x + t)))) "
wenzelm@14577:   by simp
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip These are the atomic cases for the proof generation for the
wenzelm@14577:   modulo @{text D} property for @{text "P minusinfinity"}.
wenzelm@14577: 
wenzelm@14577:   They are fully based on arithmetics. *}
berghofe@13876: 
berghofe@13876: lemma  dvd_modd_minf: "((d::int) dvd d1) ==>
berghofe@13876:  (ALL (x::int). ALL (k::int). (((d::int) dvd (x + t)) = (d dvd (x-k*d1 + t))))"
berghofe@13876: apply(clarsimp simp add:dvd_def)
berghofe@13876: apply(rule iffI)
berghofe@13876: apply(clarsimp)
berghofe@13876: apply(rename_tac n m)
berghofe@13876: apply(rule_tac x = "m - n*k" in exI)
berghofe@13876: apply(simp add:int_distrib)
berghofe@13876: apply(clarsimp)
berghofe@13876: apply(rename_tac n m)
berghofe@13876: apply(rule_tac x = "m + n*k" in exI)
paulson@14271: apply(simp add:int_distrib mult_ac)
berghofe@13876: done
berghofe@13876: 
berghofe@13876: 
berghofe@13876: lemma  not_dvd_modd_minf: "((d::int) dvd d1) ==>
berghofe@13876:  (ALL (x::int). ALL k. (~((d::int) dvd (x + t))) = (~(d dvd (x-k*d1 + t))))"
berghofe@13876: apply(clarsimp simp add:dvd_def)
berghofe@13876: apply(rule iffI)
berghofe@13876: apply(clarsimp)
berghofe@13876: apply(rename_tac n m)
berghofe@13876: apply(erule_tac x = "m + n*k" in allE)
paulson@14271: apply(simp add:int_distrib mult_ac)
berghofe@13876: apply(clarsimp)
berghofe@13876: apply(rename_tac n m)
berghofe@13876: apply(erule_tac x = "m - n*k" in allE)
paulson@14271: apply(simp add:int_distrib mult_ac)
berghofe@13876: done
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip These are the atomic cases for the proof generation for the
wenzelm@14577:   equivalence of @{text P} and @{text "P minusinfinity"} for integers
wenzelm@14577:   @{text x} less than some integer @{text z}.
berghofe@13876: 
wenzelm@14577:   They are fully based on arithmetics. *}
berghofe@13876: 
berghofe@13876: lemma  eq_eq_minf: "EX z::int. ALL x. x < z --> (( 0 = x +t ) = False )"
berghofe@13876: apply(rule_tac x = "-t" in exI)
berghofe@13876: apply simp
berghofe@13876: done
berghofe@13876: 
berghofe@13876: lemma  neq_eq_minf: "EX z::int. ALL x. x < z --> ((~( 0 = x +t )) = True )"
berghofe@13876: apply(rule_tac x = "-t" in exI)
berghofe@13876: apply simp
berghofe@13876: done
berghofe@13876: 
berghofe@13876: lemma  le_eq_minf: "EX z::int. ALL x. x < z --> ( 0 < x +t  = False )"
berghofe@13876: apply(rule_tac x = "-t" in exI)
berghofe@13876: apply simp
berghofe@13876: done
berghofe@13876: 
berghofe@13876: 
berghofe@13876: lemma  len_eq_minf: "EX z::int. ALL x. x < z --> (0 < -x +t  = True )"
berghofe@13876: apply(rule_tac x = "t" in exI)
berghofe@13876: apply simp
berghofe@13876: done
berghofe@13876: 
berghofe@13876: lemma  dvd_eq_minf: "EX z::int. ALL x. x < z --> ((d dvd (x + t)) = (d dvd (x + t))) "
wenzelm@14577:   by simp
berghofe@13876: 
berghofe@13876: lemma  not_dvd_eq_minf: "EX z::int. ALL x. x < z --> ((~(d dvd (x + t))) = (~(d dvd (x + t)))) "
wenzelm@14577:   by simp
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip This Theorem combines whithnesses about @{text "P
wenzelm@14577:   minusinfinity"} to show one component of the equivalence proof for
wenzelm@14577:   Cooper's Theorem.
berghofe@13876: 
wenzelm@14577:   FIXME: remove once they are part of the distribution. *}
wenzelm@14577: 
berghofe@13876: theorem int_ge_induct[consumes 1,case_names base step]:
berghofe@13876:   assumes ge: "k \<le> (i::int)" and
berghofe@13876:         base: "P(k)" and
berghofe@13876:         step: "\<And>i. \<lbrakk>k \<le> i; P i\<rbrakk> \<Longrightarrow> P(i+1)"
berghofe@13876:   shows "P i"
berghofe@13876: proof -
berghofe@13876:   { fix n have "\<And>i::int. n = nat(i-k) \<Longrightarrow> k <= i \<Longrightarrow> P i"
berghofe@13876:     proof (induct n)
berghofe@13876:       case 0
berghofe@13876:       hence "i = k" by arith
berghofe@13876:       thus "P i" using base by simp
berghofe@13876:     next
berghofe@13876:       case (Suc n)
berghofe@13876:       hence "n = nat((i - 1) - k)" by arith
berghofe@13876:       moreover
berghofe@13876:       have ki1: "k \<le> i - 1" using Suc.prems by arith
berghofe@13876:       ultimately
berghofe@13876:       have "P(i - 1)" by(rule Suc.hyps)
berghofe@13876:       from step[OF ki1 this] show ?case by simp
berghofe@13876:     qed
berghofe@13876:   }
berghofe@13876:   from this ge show ?thesis by fast
berghofe@13876: qed
berghofe@13876: 
berghofe@13876: theorem int_gr_induct[consumes 1,case_names base step]:
berghofe@13876:   assumes gr: "k < (i::int)" and
berghofe@13876:         base: "P(k+1)" and
berghofe@13876:         step: "\<And>i. \<lbrakk>k < i; P i\<rbrakk> \<Longrightarrow> P(i+1)"
berghofe@13876:   shows "P i"
berghofe@13876: apply(rule int_ge_induct[of "k + 1"])
berghofe@13876:   using gr apply arith
berghofe@13876:  apply(rule base)
berghofe@13876: apply(rule step)
berghofe@13876:  apply simp+
berghofe@13876: done
berghofe@13876: 
berghofe@13876: lemma decr_lemma: "0 < (d::int) \<Longrightarrow> x - (abs(x-z)+1) * d < z"
berghofe@13876: apply(induct rule: int_gr_induct)
berghofe@13876:  apply simp
berghofe@13876:  apply arith
berghofe@13876: apply (simp add:int_distrib)
berghofe@13876: apply arith
berghofe@13876: done
berghofe@13876: 
berghofe@13876: lemma incr_lemma: "0 < (d::int) \<Longrightarrow> z < x + (abs(x-z)+1) * d"
berghofe@13876: apply(induct rule: int_gr_induct)
berghofe@13876:  apply simp
berghofe@13876:  apply arith
berghofe@13876: apply (simp add:int_distrib)
berghofe@13876: apply arith
berghofe@13876: done
berghofe@13876: 
berghofe@13876: lemma  minusinfinity:
berghofe@13876:   assumes "0 < d" and
berghofe@13876:     P1eqP1: "ALL x k. P1 x = P1(x - k*d)" and
berghofe@13876:     ePeqP1: "EX z::int. ALL x. x < z \<longrightarrow> (P x = P1 x)"
berghofe@13876:   shows "(EX x. P1 x) \<longrightarrow> (EX x. P x)"
berghofe@13876: proof
berghofe@13876:   assume eP1: "EX x. P1 x"
berghofe@13876:   then obtain x where P1: "P1 x" ..
berghofe@13876:   from ePeqP1 obtain z where P1eqP: "ALL x. x < z \<longrightarrow> (P x = P1 x)" ..
berghofe@13876:   let ?w = "x - (abs(x-z)+1) * d"
berghofe@13876:   show "EX x. P x"
berghofe@13876:   proof
berghofe@13876:     have w: "?w < z" by(rule decr_lemma)
berghofe@13876:     have "P1 x = P1 ?w" using P1eqP1 by blast
berghofe@13876:     also have "\<dots> = P(?w)" using w P1eqP by blast
berghofe@13876:     finally show "P ?w" using P1 by blast
berghofe@13876:   qed
berghofe@13876: qed
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip This Theorem combines whithnesses about @{text "P
wenzelm@14577:   minusinfinity"} to show one component of the equivalence proof for
wenzelm@14577:   Cooper's Theorem. *}
berghofe@13876: 
berghofe@13876: lemma plusinfinity:
berghofe@13876:   assumes "0 < d" and
berghofe@13876:     P1eqP1: "ALL (x::int) (k::int). P1 x = P1 (x + k * d)" and
berghofe@13876:     ePeqP1: "EX z::int. ALL x. z < x  --> (P x = P1 x)"
berghofe@13876:   shows "(EX x::int. P1 x) --> (EX x::int. P x)"
berghofe@13876: proof
berghofe@13876:   assume eP1: "EX x. P1 x"
berghofe@13876:   then obtain x where P1: "P1 x" ..
berghofe@13876:   from ePeqP1 obtain z where P1eqP: "ALL x. z < x \<longrightarrow> (P x = P1 x)" ..
berghofe@13876:   let ?w = "x + (abs(x-z)+1) * d"
berghofe@13876:   show "EX x. P x"
berghofe@13876:   proof
berghofe@13876:     have w: "z < ?w" by(rule incr_lemma)
berghofe@13876:     have "P1 x = P1 ?w" using P1eqP1 by blast
berghofe@13876:     also have "\<dots> = P(?w)" using w P1eqP by blast
berghofe@13876:     finally show "P ?w" using P1 by blast
berghofe@13876:   qed
berghofe@13876: qed
berghofe@13876:  
wenzelm@14577: text {*
wenzelm@14577:   \medskip Theorem for periodic function on discrete sets. *}
berghofe@13876: 
berghofe@13876: lemma minf_vee:
berghofe@13876:   assumes dpos: "(0::int) < d" and modd: "ALL x k. P x = P(x - k*d)"
berghofe@13876:   shows "(EX x. P x) = (EX j : {1..d}. P j)"
berghofe@13876:   (is "?LHS = ?RHS")
berghofe@13876: proof
berghofe@13876:   assume ?LHS
berghofe@13876:   then obtain x where P: "P x" ..
berghofe@13876:   have "x mod d = x - (x div d)*d"
paulson@14271:     by(simp add:zmod_zdiv_equality mult_ac eq_diff_eq)
berghofe@13876:   hence Pmod: "P x = P(x mod d)" using modd by simp
berghofe@13876:   show ?RHS
berghofe@13876:   proof (cases)
berghofe@13876:     assume "x mod d = 0"
berghofe@13876:     hence "P 0" using P Pmod by simp
berghofe@13876:     moreover have "P 0 = P(0 - (-1)*d)" using modd by blast
berghofe@13876:     ultimately have "P d" by simp
berghofe@13876:     moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
berghofe@13876:     ultimately show ?RHS ..
berghofe@13876:   next
berghofe@13876:     assume not0: "x mod d \<noteq> 0"
berghofe@13876:     have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
berghofe@13876:     moreover have "x mod d : {1..d}"
berghofe@13876:     proof -
berghofe@13876:       have "0 \<le> x mod d" by(rule pos_mod_sign)
berghofe@13876:       moreover have "x mod d < d" by(rule pos_mod_bound)
berghofe@13876:       ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
berghofe@13876:     qed
berghofe@13876:     ultimately show ?RHS ..
berghofe@13876:   qed
berghofe@13876: next
berghofe@13876:   assume ?RHS thus ?LHS by blast
berghofe@13876: qed
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip Theorem for periodic function on discrete sets. *}
wenzelm@14577: 
berghofe@13876: lemma pinf_vee:
berghofe@13876:   assumes dpos: "0 < (d::int)" and modd: "ALL (x::int) (k::int). P x = P (x+k*d)"
berghofe@13876:   shows "(EX x::int. P x) = (EX (j::int) : {1..d} . P j)"
berghofe@13876:   (is "?LHS = ?RHS")
berghofe@13876: proof
berghofe@13876:   assume ?LHS
berghofe@13876:   then obtain x where P: "P x" ..
berghofe@13876:   have "x mod d = x + (-(x div d))*d"
paulson@14271:     by(simp add:zmod_zdiv_equality mult_ac eq_diff_eq)
berghofe@13876:   hence Pmod: "P x = P(x mod d)" using modd by (simp only:)
berghofe@13876:   show ?RHS
berghofe@13876:   proof (cases)
berghofe@13876:     assume "x mod d = 0"
berghofe@13876:     hence "P 0" using P Pmod by simp
berghofe@13876:     moreover have "P 0 = P(0 + 1*d)" using modd by blast
berghofe@13876:     ultimately have "P d" by simp
berghofe@13876:     moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
berghofe@13876:     ultimately show ?RHS ..
berghofe@13876:   next
berghofe@13876:     assume not0: "x mod d \<noteq> 0"
berghofe@13876:     have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
berghofe@13876:     moreover have "x mod d : {1..d}"
berghofe@13876:     proof -
berghofe@13876:       have "0 \<le> x mod d" by(rule pos_mod_sign)
berghofe@13876:       moreover have "x mod d < d" by(rule pos_mod_bound)
berghofe@13876:       ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
berghofe@13876:     qed
berghofe@13876:     ultimately show ?RHS ..
berghofe@13876:   qed
berghofe@13876: next
berghofe@13876:   assume ?RHS thus ?LHS by blast
berghofe@13876: qed
berghofe@13876: 
berghofe@13876: lemma decr_mult_lemma:
berghofe@13876:   assumes dpos: "(0::int) < d" and
berghofe@13876:           minus: "ALL x::int. P x \<longrightarrow> P(x - d)" and
berghofe@13876:           knneg: "0 <= k"
berghofe@13876:   shows "ALL x. P x \<longrightarrow> P(x - k*d)"
berghofe@13876: using knneg
berghofe@13876: proof (induct rule:int_ge_induct)
berghofe@13876:   case base thus ?case by simp
berghofe@13876: next
berghofe@13876:   case (step i)
berghofe@13876:   show ?case
berghofe@13876:   proof
berghofe@13876:     fix x
berghofe@13876:     have "P x \<longrightarrow> P (x - i * d)" using step.hyps by blast
berghofe@13876:     also have "\<dots> \<longrightarrow> P(x - (i + 1) * d)"
berghofe@13876:       using minus[THEN spec, of "x - i * d"]
obua@14738:       by (simp add:int_distrib OrderedGroup.diff_diff_eq[symmetric])
berghofe@13876:     ultimately show "P x \<longrightarrow> P(x - (i + 1) * d)" by blast
berghofe@13876:   qed
berghofe@13876: qed
berghofe@13876: 
berghofe@13876: lemma incr_mult_lemma:
berghofe@13876:   assumes dpos: "(0::int) < d" and
berghofe@13876:           plus: "ALL x::int. P x \<longrightarrow> P(x + d)" and
berghofe@13876:           knneg: "0 <= k"
berghofe@13876:   shows "ALL x. P x \<longrightarrow> P(x + k*d)"
berghofe@13876: using knneg
berghofe@13876: proof (induct rule:int_ge_induct)
berghofe@13876:   case base thus ?case by simp
berghofe@13876: next
berghofe@13876:   case (step i)
berghofe@13876:   show ?case
berghofe@13876:   proof
berghofe@13876:     fix x
berghofe@13876:     have "P x \<longrightarrow> P (x + i * d)" using step.hyps by blast
berghofe@13876:     also have "\<dots> \<longrightarrow> P(x + (i + 1) * d)"
berghofe@13876:       using plus[THEN spec, of "x + i * d"]
berghofe@13876:       by (simp add:int_distrib zadd_ac)
berghofe@13876:     ultimately show "P x \<longrightarrow> P(x + (i + 1) * d)" by blast
berghofe@13876:   qed
berghofe@13876: qed
berghofe@13876: 
berghofe@13876: lemma cpmi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. x < z --> (P x = P1 x))
berghofe@13876: ==> ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D) 
berghofe@13876: ==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x-k*D))))
berghofe@13876: ==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (b::int) : B. P (b+j)))"
berghofe@13876: apply(rule iffI)
berghofe@13876: prefer 2
berghofe@13876: apply(drule minusinfinity)
berghofe@13876: apply assumption+
berghofe@13876: apply(fastsimp)
berghofe@13876: apply clarsimp
berghofe@13876: apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x - k*D)")
berghofe@13876: apply(frule_tac x = x and z=z in decr_lemma)
berghofe@13876: apply(subgoal_tac "P1(x - (\<bar>x - z\<bar> + 1) * D)")
berghofe@13876: prefer 2
berghofe@13876: apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
berghofe@13876: prefer 2 apply arith
berghofe@13876:  apply fastsimp
berghofe@13876: apply(drule (1) minf_vee)
berghofe@13876: apply blast
berghofe@13876: apply(blast dest:decr_mult_lemma)
berghofe@13876: done
berghofe@13876: 
wenzelm@14577: text {* Cooper Theorem, plus infinity version. *}
berghofe@13876: lemma cppi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. z < x --> (P x = P1 x))
berghofe@13876: ==> ALL x.~(EX (j::int) : {1..D}. EX (a::int) : A. P(a - j)) --> P (x) --> P (x + D) 
berghofe@13876: ==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x+k*D))))
berghofe@13876: ==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (a::int) : A. P (a - j)))"
berghofe@13876:   apply(rule iffI)
berghofe@13876:   prefer 2
berghofe@13876:   apply(drule plusinfinity)
berghofe@13876:   apply assumption+
berghofe@13876:   apply(fastsimp)
berghofe@13876:   apply clarsimp
berghofe@13876:   apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x + k*D)")
berghofe@13876:   apply(frule_tac x = x and z=z in incr_lemma)
berghofe@13876:   apply(subgoal_tac "P1(x + (\<bar>x - z\<bar> + 1) * D)")
berghofe@13876:   prefer 2
berghofe@13876:   apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
berghofe@13876:   prefer 2 apply arith
berghofe@13876:   apply fastsimp
berghofe@13876:   apply(drule (1) pinf_vee)
berghofe@13876:   apply blast
berghofe@13876:   apply(blast dest:incr_mult_lemma)
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \bigskip Theorems for the quantifier elminination Functions. *}
berghofe@13876: 
berghofe@13876: lemma qe_ex_conj: "(EX (x::int). A x) = R
berghofe@13876: 		==> (EX (x::int). P x) = (Q & (EX x::int. A x))
berghofe@13876: 		==> (EX (x::int). P x) = (Q & R)"
berghofe@13876: by blast
berghofe@13876: 
berghofe@13876: lemma qe_ex_nconj: "(EX (x::int). P x) = (True & Q)
berghofe@13876: 		==> (EX (x::int). P x) = Q"
berghofe@13876: by blast
berghofe@13876: 
berghofe@13876: lemma qe_conjI: "P1 = P2 ==> Q1 = Q2 ==> (P1 & Q1) = (P2 & Q2)"
berghofe@13876: by blast
berghofe@13876: 
berghofe@13876: lemma qe_disjI: "P1 = P2 ==> Q1 = Q2 ==> (P1 | Q1) = (P2 | Q2)"
berghofe@13876: by blast
berghofe@13876: 
berghofe@13876: lemma qe_impI: "P1 = P2 ==> Q1 = Q2 ==> (P1 --> Q1) = (P2 --> Q2)"
berghofe@13876: by blast
berghofe@13876: 
berghofe@13876: lemma qe_eqI: "P1 = P2 ==> Q1 = Q2 ==> (P1 = Q1) = (P2 = Q2)"
berghofe@13876: by blast
berghofe@13876: 
berghofe@13876: lemma qe_Not: "P = Q ==> (~P) = (~Q)"
berghofe@13876: by blast
berghofe@13876: 
berghofe@13876: lemma qe_ALL: "(EX x. ~P x) = R ==> (ALL x. P x) = (~R)"
berghofe@13876: by blast
berghofe@13876: 
wenzelm@14577: text {* \bigskip Theorems for proving NNF *}
berghofe@13876: 
berghofe@13876: lemma nnf_im: "((~P) = P1) ==> (Q=Q1) ==> ((P --> Q) = (P1 | Q1))"
berghofe@13876: by blast
berghofe@13876: 
berghofe@13876: lemma nnf_eq: "((P & Q) = (P1 & Q1)) ==> (((~P) & (~Q)) = (P2 & Q2)) ==> ((P = Q) = ((P1 & Q1)|(P2 & Q2)))"
berghofe@13876: by blast
berghofe@13876: 
berghofe@13876: lemma nnf_nn: "(P = Q) ==> ((~~P) = Q)"
berghofe@13876:   by blast
berghofe@13876: lemma nnf_ncj: "((~P) = P1) ==> ((~Q) = Q1) ==> ((~(P & Q)) = (P1 | Q1))"
berghofe@13876: by blast
berghofe@13876: 
berghofe@13876: lemma nnf_ndj: "((~P) = P1) ==> ((~Q) = Q1) ==> ((~(P | Q)) = (P1 & Q1))"
berghofe@13876: by blast
berghofe@13876: lemma nnf_nim: "(P = P1) ==> ((~Q) = Q1) ==> ((~(P --> Q)) = (P1 & Q1))"
berghofe@13876: by blast
berghofe@13876: lemma nnf_neq: "((P & (~Q)) = (P1 & Q1)) ==> (((~P) & Q) = (P2 & Q2)) ==> ((~(P = Q)) = ((P1 & Q1)|(P2 & Q2)))"
berghofe@13876: by blast
berghofe@13876: lemma nnf_sdj: "((A & (~B)) = (A1 & B1)) ==> ((C & (~D)) = (C1 & D1)) ==> (A = (~C)) ==> ((~((A & B) | (C & D))) = ((A1 & B1) | (C1 & D1)))"
berghofe@13876: by blast
berghofe@13876: 
berghofe@13876: 
berghofe@13876: lemma qe_exI2: "A = B ==> (EX (x::int). A(x)) = (EX (x::int). B(x))"
berghofe@13876:   by simp
berghofe@13876: 
berghofe@13876: lemma qe_exI: "(!!x::int. A x = B x) ==> (EX (x::int). A(x)) = (EX (x::int). B(x))"
nipkow@17589:   by iprover
berghofe@13876: 
berghofe@13876: lemma qe_ALLI: "(!!x::int. A x = B x) ==> (ALL (x::int). A(x)) = (ALL (x::int). B(x))"
nipkow@17589:   by iprover
berghofe@13876: 
berghofe@13876: lemma cp_expand: "(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (b::int) : B. (P1 (j) | P(b+j)))
berghofe@13876: ==>(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (b::int) : B. (P1 (j) | P(b+j))) "
berghofe@13876: by blast
berghofe@13876: 
berghofe@13876: lemma cppi_expand: "(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (a::int) : A. (P1 (j) | P(a - j)))
berghofe@13876: ==>(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (a::int) : A. (P1 (j) | P(a - j))) "
berghofe@13876: by blast
berghofe@13876: 
berghofe@13876: 
berghofe@13876: lemma simp_from_to: "{i..j::int} = (if j < i then {} else insert i {i+1..j})"
berghofe@13876: apply(simp add:atLeastAtMost_def atLeast_def atMost_def)
berghofe@13876: apply(fastsimp)
berghofe@13876: done
berghofe@13876: 
wenzelm@14577: text {* \bigskip Theorems required for the @{text adjustcoeffitienteq} *}
berghofe@13876: 
berghofe@13876: lemma ac_dvd_eq: assumes not0: "0 ~= (k::int)"
berghofe@13876: shows "((m::int) dvd (c*n+t)) = (k*m dvd ((k*c)*n+(k*t)))" (is "?P = ?Q")
berghofe@13876: proof
berghofe@13876:   assume ?P
berghofe@13876:   thus ?Q
berghofe@13876:     apply(simp add:dvd_def)
berghofe@13876:     apply clarify
berghofe@13876:     apply(rename_tac d)
berghofe@13876:     apply(drule_tac f = "op * k" in arg_cong)
berghofe@13876:     apply(simp only:int_distrib)
berghofe@13876:     apply(rule_tac x = "d" in exI)
paulson@14271:     apply(simp only:mult_ac)
berghofe@13876:     done
berghofe@13876: next
berghofe@13876:   assume ?Q
berghofe@13876:   then obtain d where "k * c * n + k * t = (k*m)*d" by(fastsimp simp:dvd_def)
paulson@14271:   hence "(c * n + t) * k = (m*d) * k" by(simp add:int_distrib mult_ac)
berghofe@13876:   hence "((c * n + t) * k) div k = ((m*d) * k) div k" by(rule arg_cong[of _ _ "%t. t div k"])
berghofe@13876:   hence "c*n+t = m*d" by(simp add: zdiv_zmult_self1[OF not0[symmetric]])
berghofe@13876:   thus ?P by(simp add:dvd_def)
berghofe@13876: qed
berghofe@13876: 
berghofe@13876: lemma ac_lt_eq: assumes gr0: "0 < (k::int)"
berghofe@13876: shows "((m::int) < (c*n+t)) = (k*m <((k*c)*n+(k*t)))" (is "?P = ?Q")
berghofe@13876: proof
berghofe@13876:   assume P: ?P
paulson@14271:   show ?Q using zmult_zless_mono2[OF P gr0] by(simp add: int_distrib mult_ac)
berghofe@13876: next
berghofe@13876:   assume ?Q
paulson@14271:   hence "0 < k*(c*n + t - m)" by(simp add: int_distrib mult_ac)
paulson@14353:   with gr0 have "0 < (c*n + t - m)" by(simp add: zero_less_mult_iff)
berghofe@13876:   thus ?P by(simp)
berghofe@13876: qed
berghofe@13876: 
berghofe@13876: lemma ac_eq_eq : assumes not0: "0 ~= (k::int)" shows "((m::int) = (c*n+t)) = (k*m =((k*c)*n+(k*t)) )" (is "?P = ?Q")
berghofe@13876: proof
berghofe@13876:   assume ?P
berghofe@13876:   thus ?Q
berghofe@13876:     apply(drule_tac f = "op * k" in arg_cong)
berghofe@13876:     apply(simp only:int_distrib)
berghofe@13876:     done
berghofe@13876: next
berghofe@13876:   assume ?Q
paulson@14271:   hence "m * k = (c*n + t) * k" by(simp add:int_distrib mult_ac)
berghofe@13876:   hence "((m) * k) div k = ((c*n + t) * k) div k" by(rule arg_cong[of _ _ "%t. t div k"])
berghofe@13876:   thus ?P by(simp add: zdiv_zmult_self1[OF not0[symmetric]])
berghofe@13876: qed
berghofe@13876: 
berghofe@13876: lemma ac_pi_eq: assumes gr0: "0 < (k::int)" shows "(~((0::int) < (c*n + t))) = (0 < ((-k)*c)*n + ((-k)*t + k))"
berghofe@13876: proof -
berghofe@13876:   have "(~ (0::int) < (c*n + t)) = (0<1-(c*n + t))" by arith
paulson@14271:   also have  "(1-(c*n + t)) = (-1*c)*n + (-t+1)" by(simp add: int_distrib mult_ac)
berghofe@13876:   also have "0<(-1*c)*n + (-t+1) = (0 < (k*(-1*c)*n) + (k*(-t+1)))" by(rule ac_lt_eq[of _ 0,OF gr0,simplified])
paulson@14271:   also have "(k*(-1*c)*n) + (k*(-t+1)) = ((-k)*c)*n + ((-k)*t + k)" by(simp add: int_distrib mult_ac)
berghofe@13876:   finally show ?thesis .
berghofe@13876: qed
berghofe@13876: 
berghofe@13876: lemma binminus_uminus_conv: "(a::int) - b = a + (-b)"
berghofe@13876: by arith
berghofe@13876: 
berghofe@13876: lemma  linearize_dvd: "(t::int) = t1 ==> (d dvd t) = (d dvd t1)"
berghofe@13876: by simp
berghofe@13876: 
berghofe@13876: lemma lf_lt: "(l::int) = ll ==> (r::int) = lr ==> (l < r) =(ll < lr)"
berghofe@13876: by simp
berghofe@13876: 
berghofe@13876: lemma lf_eq: "(l::int) = ll ==> (r::int) = lr ==> (l = r) =(ll = lr)"
berghofe@13876: by simp
berghofe@13876: 
berghofe@13876: lemma lf_dvd: "(l::int) = ll ==> (r::int) = lr ==> (l dvd r) =(ll dvd lr)"
berghofe@13876: by simp
berghofe@13876: 
wenzelm@14577: text {* \bigskip Theorems for transforming predicates on nat to predicates on @{text int}*}
berghofe@13876: 
berghofe@13876: theorem all_nat: "(\<forall>x::nat. P x) = (\<forall>x::int. 0 <= x \<longrightarrow> P (nat x))"
berghofe@13876:   by (simp split add: split_nat)
berghofe@13876: 
berghofe@13876: theorem ex_nat: "(\<exists>x::nat. P x) = (\<exists>x::int. 0 <= x \<and> P (nat x))"
berghofe@13876:   apply (simp split add: split_nat)
berghofe@13876:   apply (rule iffI)
berghofe@13876:   apply (erule exE)
berghofe@13876:   apply (rule_tac x = "int x" in exI)
berghofe@13876:   apply simp
berghofe@13876:   apply (erule exE)
berghofe@13876:   apply (rule_tac x = "nat x" in exI)
berghofe@13876:   apply (erule conjE)
berghofe@13876:   apply (erule_tac x = "nat x" in allE)
berghofe@13876:   apply simp
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: theorem zdiff_int_split: "P (int (x - y)) =
berghofe@13876:   ((y \<le> x \<longrightarrow> P (int x - int y)) \<and> (x < y \<longrightarrow> P 0))"
berghofe@13876:   apply (case_tac "y \<le> x")
berghofe@13876:   apply (simp_all add: zdiff_int)
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: theorem zdvd_int: "(x dvd y) = (int x dvd int y)"
berghofe@13876:   apply (simp only: dvd_def ex_nat int_int_eq [symmetric] zmult_int [symmetric]
berghofe@13876:     nat_0_le cong add: conj_cong)
berghofe@13876:   apply (rule iffI)
nipkow@17589:   apply iprover
berghofe@13876:   apply (erule exE)
berghofe@13876:   apply (case_tac "x=0")
berghofe@13876:   apply (rule_tac x=0 in exI)
berghofe@13876:   apply simp
berghofe@13876:   apply (case_tac "0 \<le> k")
nipkow@17589:   apply iprover
berghofe@13876:   apply (simp add: linorder_not_le)
paulson@14378:   apply (drule mult_strict_left_mono_neg [OF iffD2 [OF zero_less_int_conv]])
berghofe@13876:   apply assumption
paulson@14271:   apply (simp add: mult_ac)
berghofe@13876:   done
berghofe@13876: 
berghofe@13876: theorem number_of1: "(0::int) <= number_of n \<Longrightarrow> (0::int) <= number_of (n BIT b)"
berghofe@13876:   by simp
berghofe@13876: 
paulson@15013: theorem number_of2: "(0::int) <= Numeral0" by simp
berghofe@13876: 
berghofe@13876: theorem Suc_plus1: "Suc n = n + 1" by simp
berghofe@13876: 
wenzelm@14577: text {*
wenzelm@14577:   \medskip Specific instances of congruence rules, to prevent
wenzelm@14577:   simplifier from looping. *}
berghofe@13876: 
chaieb@14758: theorem imp_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<longrightarrow> P) = (0 <= x \<longrightarrow> P')"
berghofe@13876:   by simp
berghofe@13876: 
chaieb@14758: theorem conj_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<and> P) = (0 <= x \<and> P')"
chaieb@14758:   by (simp cong: conj_cong)
berghofe@13876: 
berghofe@13876: use "cooper_dec.ML"
chaieb@17378: use "reflected_presburger.ML" 
chaieb@17378: use "reflected_cooper.ML"
chaieb@14941: oracle
chaieb@17378:   presburger_oracle ("term") = ReflectedCooper.presburger_oracle
chaieb@14941: 
berghofe@13876: use "cooper_proof.ML"
berghofe@13876: use "qelim.ML"
berghofe@13876: use "presburger.ML"
berghofe@13876: 
berghofe@13876: setup "Presburger.setup"
berghofe@13876: 
berghofe@13876: end




