src/HOL/Presburger.thy
author webertj
Wed Jul 26 19:23:04 2006 +0200 (2006-07-26)
changeset 20217 25b068a99d2b
parent 20051 859e7129961b
child 20485 3078fd2eec7b
permissions -rw-r--r--
linear arithmetic splits certain operators (e.g. min, max, abs)
     1 (*  Title:      HOL/Integ/Presburger.thy
     2     ID:         $Id$
     3     Author:     Amine Chaieb, Tobias Nipkow and Stefan Berghofer, TU Muenchen
     4 
     5 File containing necessary theorems for the proof
     6 generation for Cooper Algorithm  
     7 *)
     8 
     9 header {* Presburger Arithmetic: Cooper's Algorithm *}
    10 
    11 theory Presburger
    12 imports NatSimprocs
    13 uses ("cooper_dec.ML") ("cooper_proof.ML") ("qelim.ML") 
    14 	("reflected_presburger.ML") ("reflected_cooper.ML") ("presburger.ML")
    15 begin
    16 
    17 text {* Theorem for unitifying the coeffitients of @{text x} in an existential formula*}
    18 
    19 theorem unity_coeff_ex: "(\<exists>x::int. P (l * x)) = (\<exists>x. l dvd (1*x+0) \<and> P x)"
    20   apply (rule iffI)
    21   apply (erule exE)
    22   apply (rule_tac x = "l * x" in exI)
    23   apply simp
    24   apply (erule exE)
    25   apply (erule conjE)
    26   apply (erule dvdE)
    27   apply (rule_tac x = k in exI)
    28   apply simp
    29   done
    30 
    31 lemma uminus_dvd_conv: "(d dvd (t::int)) = (-d dvd t)"
    32 apply(unfold dvd_def)
    33 apply(rule iffI)
    34 apply(clarsimp)
    35 apply(rename_tac k)
    36 apply(rule_tac x = "-k" in exI)
    37 apply simp
    38 apply(clarsimp)
    39 apply(rename_tac k)
    40 apply(rule_tac x = "-k" in exI)
    41 apply simp
    42 done
    43 
    44 lemma uminus_dvd_conv': "(d dvd (t::int)) = (d dvd -t)"
    45 apply(unfold dvd_def)
    46 apply(rule iffI)
    47 apply(clarsimp)
    48 apply(rule_tac x = "-k" in exI)
    49 apply simp
    50 apply(clarsimp)
    51 apply(rule_tac x = "-k" in exI)
    52 apply simp
    53 done
    54 
    55 
    56 
    57 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}.*}
    58 
    59 theorem eq_minf_conjI: "\<exists>z1::int. \<forall>x. x < z1 \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
    60   \<exists>z2::int. \<forall>x. x < z2 \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
    61   \<exists>z::int. \<forall>x. x < z \<longrightarrow> ((A1 x \<and> B1 x) = (A2 x \<and> B2 x))"
    62   apply (erule exE)+
    63   apply (rule_tac x = "min z1 z2" in exI)
    64   apply simp
    65   done
    66 
    67 
    68 theorem eq_minf_disjI: "\<exists>z1::int. \<forall>x. x < z1 \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
    69   \<exists>z2::int. \<forall>x. x < z2 \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
    70   \<exists>z::int. \<forall>x. x < z \<longrightarrow> ((A1 x \<or> B1 x) = (A2 x \<or> B2 x))"
    71 
    72   apply (erule exE)+
    73   apply (rule_tac x = "min z1 z2" in exI)
    74   apply simp
    75   done
    76 
    77 
    78 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}.*}
    79 
    80 theorem eq_pinf_conjI: "\<exists>z1::int. \<forall>x. z1 < x \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
    81   \<exists>z2::int. \<forall>x. z2 < x \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
    82   \<exists>z::int. \<forall>x. z < x \<longrightarrow> ((A1 x \<and> B1 x) = (A2 x \<and> B2 x))"
    83   apply (erule exE)+
    84   apply (rule_tac x = "max z1 z2" in exI)
    85   apply simp
    86   done
    87 
    88 
    89 theorem eq_pinf_disjI: "\<exists>z1::int. \<forall>x. z1 < x \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
    90   \<exists>z2::int. \<forall>x. z2 < x \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
    91   \<exists>z::int. \<forall>x. z < x  \<longrightarrow> ((A1 x \<or> B1 x) = (A2 x \<or> B2 x))"
    92   apply (erule exE)+
    93   apply (rule_tac x = "max z1 z2" in exI)
    94   apply simp
    95   done
    96 
    97 text {*
    98   \medskip Theorems for the combination of proofs of the modulo @{text
    99   D} property for @{text "P plusinfinity"}
   100 
   101   FIXME: This is THE SAME theorem as for the @{text minusinf} version,
   102   but with @{text "+k.."} instead of @{text "-k.."} In the future
   103   replace these both with only one. *}
   104 
   105 theorem modd_pinf_conjI: "\<forall>(x::int) k. A x = A (x+k*d) \<Longrightarrow>
   106   \<forall>(x::int) k. B x = B (x+k*d) \<Longrightarrow>
   107   \<forall>(x::int) (k::int). (A x \<and> B x) = (A (x+k*d) \<and> B (x+k*d))"
   108   by simp
   109 
   110 theorem modd_pinf_disjI: "\<forall>(x::int) k. A x = A (x+k*d) \<Longrightarrow>
   111   \<forall>(x::int) k. B x = B (x+k*d) \<Longrightarrow>
   112   \<forall>(x::int) (k::int). (A x \<or> B x) = (A (x+k*d) \<or> B (x+k*d))"
   113   by simp
   114 
   115 text {*
   116   This is one of the cases where the simplifed formula is prooved to
   117   habe some property (in relation to @{text P_m}) but we need to prove
   118   the property for the original formula (@{text P_m})
   119 
   120   FIXME: This is exaclty the same thm as for @{text minusinf}. *}
   121 
   122 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)) "
   123   by blast
   124 
   125 
   126 text {*
   127   \medskip Theorems for the combination of proofs of the modulo @{text D}
   128   property for @{text "P minusinfinity"} *}
   129 
   130 theorem modd_minf_conjI: "\<forall>(x::int) k. A x = A (x-k*d) \<Longrightarrow>
   131   \<forall>(x::int) k. B x = B (x-k*d) \<Longrightarrow>
   132   \<forall>(x::int) (k::int). (A x \<and> B x) = (A (x-k*d) \<and> B (x-k*d))"
   133   by simp
   134 
   135 theorem modd_minf_disjI: "\<forall>(x::int) k. A x = A (x-k*d) \<Longrightarrow>
   136   \<forall>(x::int) k. B x = B (x-k*d) \<Longrightarrow>
   137   \<forall>(x::int) (k::int). (A x \<or> B x) = (A (x-k*d) \<or> B (x-k*d))"
   138   by simp
   139 
   140 text {*
   141   This is one of the cases where the simplifed formula is prooved to
   142   have some property (in relation to @{text P_m}) but we need to
   143   prove the property for the original formula (@{text P_m}). *}
   144 
   145 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)) "
   146   by blast
   147 
   148 text {*
   149   Theorem needed for proving at runtime divide properties using the
   150   arithmetic tactic (which knows only about modulo = 0). *}
   151 
   152 lemma zdvd_iff_zmod_eq_0: "(m dvd n) = (n mod m = (0::int))"
   153   by(simp add:dvd_def zmod_eq_0_iff)
   154 
   155 text {*
   156   \medskip Theorems used for the combination of proof for the
   157   backwards direction of Cooper's Theorem. They rely exclusively on
   158   Predicate calculus.*}
   159 
   160 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))
   161 ==>
   162 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P2(x) --> P2(x + d))
   163 ==>
   164 (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))) "
   165   by blast
   166 
   167 
   168 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))
   169 ==>
   170 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P2(x) --> P2(x + d))
   171 ==>
   172 (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)
   173 \<and> P2(x + d))) "
   174   by blast
   175 
   176 lemma not_ast_p_Q_elim: "
   177 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) -->P(x) --> P(x + d))
   178 ==> ( P = Q )
   179 ==> (ALL x. ~(EX (j::int) : {1..d}. EX (a::int) : A. P(a - j)) -->P(x) --> P(x + d))"
   180   by blast
   181 
   182 text {*
   183   \medskip Theorems used for the combination of proof for the
   184   backwards direction of Cooper's Theorem. They rely exclusively on
   185   Predicate calculus.*}
   186 
   187 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))
   188 ==>
   189 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P2(x) --> P2(x - d))
   190 ==>
   191 (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)
   192 \<or> P2(x-d))) "
   193   by blast
   194 
   195 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))
   196 ==>
   197 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P2(x) --> P2(x - d))
   198 ==>
   199 (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)
   200 \<and> P2(x-d))) "
   201   by blast
   202 
   203 lemma not_bst_p_Q_elim: "
   204 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) -->P(x) --> P(x - d)) 
   205 ==> ( P = Q )
   206 ==> (ALL x. ~(EX (j::int) : {1..d}. EX (b::int) : B. P(b+j)) -->P(x) --> P(x - d))"
   207   by blast
   208 
   209 text {* \medskip This is the first direction of Cooper's Theorem. *}
   210 lemma cooper_thm: "(R --> (EX x::int. P x))  ==> (Q -->(EX x::int.  P x )) ==> ((R|Q) --> (EX x::int. P x )) "
   211   by blast
   212 
   213 text {*
   214   \medskip The full Cooper's Theorem in its equivalence Form. Given
   215   the premises it is trivial too, it relies exclusively on prediacte calculus.*}
   216 lemma cooper_eq_thm: "(R --> (EX x::int. P x))  ==> (Q -->(EX x::int.  P x )) ==> ((~Q)
   217 --> (EX x::int. P x ) --> R) ==> (EX x::int. P x) = R|Q "
   218   by blast
   219 
   220 text {*
   221   \medskip Some of the atomic theorems generated each time the atom
   222   does not depend on @{text x}, they are trivial.*}
   223 
   224 lemma  fm_eq_minf: "EX z::int. ALL x. x < z --> (P = P) "
   225   by blast
   226 
   227 lemma  fm_modd_minf: "ALL (x::int). ALL (k::int). (P = P)"
   228   by blast
   229 
   230 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"
   231   by blast
   232 
   233 lemma  fm_eq_pinf: "EX z::int. ALL x. z < x --> (P = P) "
   234   by blast
   235 
   236 text {* The next two thms are the same as the @{text minusinf} version. *}
   237 
   238 lemma  fm_modd_pinf: "ALL (x::int). ALL (k::int). (P = P)"
   239   by blast
   240 
   241 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"
   242   by blast
   243 
   244 text {* Theorems to be deleted from simpset when proving simplified formulaes. *}
   245 
   246 lemma P_eqtrue: "(P=True) = P"
   247   by iprover
   248 
   249 lemma P_eqfalse: "(P=False) = (~P)"
   250   by iprover
   251 
   252 text {*
   253   \medskip Theorems for the generation of the bachwards direction of
   254   Cooper's Theorem.
   255 
   256   These are the 6 interesting atomic cases which have to be proved relying on the
   257   properties of B-set and the arithmetic and contradiction proofs. *}
   258 
   259 lemma not_bst_p_lt: "0 < (d::int) ==>
   260  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 )"
   261   by arith
   262 
   263 lemma not_bst_p_gt: "\<lbrakk> (g::int) \<in> B; g = -a \<rbrakk> \<Longrightarrow>
   264  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)"
   265 apply clarsimp
   266 apply(rule ccontr)
   267 apply(drule_tac x = "x+a" in bspec)
   268 apply(simp add:atLeastAtMost_iff)
   269 apply(drule_tac x = "-a" in bspec)
   270 apply assumption
   271 apply(simp)
   272 done
   273 
   274 lemma not_bst_p_eq: "\<lbrakk> 0 < d; (g::int) \<in> B; g = -a - 1 \<rbrakk> \<Longrightarrow>
   275  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 )"
   276 apply clarsimp
   277 apply(subgoal_tac "x = -a")
   278  prefer 2 apply arith
   279 apply(drule_tac x = "1" in bspec)
   280 apply(simp add:atLeastAtMost_iff)
   281 apply(drule_tac x = "-a- 1" in bspec)
   282 apply assumption
   283 apply(simp)
   284 done
   285 
   286 
   287 lemma not_bst_p_ne: "\<lbrakk> 0 < d; (g::int) \<in> B; g = -a \<rbrakk> \<Longrightarrow>
   288  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)"
   289 apply clarsimp
   290 apply(subgoal_tac "x = -a+d")
   291  prefer 2 apply arith
   292 apply(drule_tac x = "d" in bspec)
   293 apply(simp add:atLeastAtMost_iff)
   294 apply(drule_tac x = "-a" in bspec)
   295 apply assumption
   296 apply(simp)
   297 done
   298 
   299 
   300 lemma not_bst_p_dvd: "(d1::int) dvd d ==>
   301  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 )"
   302 apply(clarsimp simp add:dvd_def)
   303 apply(rename_tac m)
   304 apply(rule_tac x = "m - k" in exI)
   305 apply(simp add:int_distrib)
   306 done
   307 
   308 lemma not_bst_p_ndvd: "(d1::int) dvd d ==>
   309  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 ))"
   310 apply(clarsimp simp add:dvd_def)
   311 apply(rename_tac m)
   312 apply(erule_tac x = "m + k" in allE)
   313 apply(simp add:int_distrib)
   314 done
   315 
   316 text {*
   317   \medskip Theorems for the generation of the bachwards direction of
   318   Cooper's Theorem.
   319 
   320   These are the 6 interesting atomic cases which have to be proved
   321   relying on the properties of A-set ant the arithmetic and
   322   contradiction proofs. *}
   323 
   324 lemma not_ast_p_gt: "0 < (d::int) ==>
   325  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 )"
   326   by arith
   327 
   328 lemma not_ast_p_lt: "\<lbrakk>0 < d ;(t::int) \<in> A \<rbrakk> \<Longrightarrow>
   329  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)"
   330   apply clarsimp
   331   apply (rule ccontr)
   332   apply (drule_tac x = "t-x" in bspec)
   333   apply simp
   334   apply (drule_tac x = "t" in bspec)
   335   apply assumption
   336   apply simp
   337   done
   338 
   339 lemma not_ast_p_eq: "\<lbrakk> 0 < d; (g::int) \<in> A; g = -t + 1 \<rbrakk> \<Longrightarrow>
   340  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 )"
   341   apply clarsimp
   342   apply (drule_tac x="1" in bspec)
   343   apply simp
   344   apply (drule_tac x="- t + 1" in bspec)
   345   apply assumption
   346   apply(subgoal_tac "x = -t")
   347   prefer 2 apply arith
   348   apply simp
   349   done
   350 
   351 lemma not_ast_p_ne: "\<lbrakk> 0 < d; (g::int) \<in> A; g = -t \<rbrakk> \<Longrightarrow>
   352  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)"
   353   apply clarsimp
   354   apply (subgoal_tac "x = -t-d")
   355   prefer 2 apply arith
   356   apply (drule_tac x = "d" in bspec)
   357   apply simp
   358   apply (drule_tac x = "-t" in bspec)
   359   apply assumption
   360   apply simp
   361   done
   362 
   363 lemma not_ast_p_dvd: "(d1::int) dvd d ==>
   364  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 )"
   365   apply(clarsimp simp add:dvd_def)
   366   apply(rename_tac m)
   367   apply(rule_tac x = "m + k" in exI)
   368   apply(simp add:int_distrib)
   369   done
   370 
   371 lemma not_ast_p_ndvd: "(d1::int) dvd d ==>
   372  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 ))"
   373   apply(clarsimp simp add:dvd_def)
   374   apply(rename_tac m)
   375   apply(erule_tac x = "m - k" in allE)
   376   apply(simp add:int_distrib)
   377   done
   378 
   379 text {*
   380   \medskip These are the atomic cases for the proof generation for the
   381   modulo @{text D} property for @{text "P plusinfinity"}
   382 
   383   They are fully based on arithmetics. *}
   384 
   385 lemma  dvd_modd_pinf: "((d::int) dvd d1) ==>
   386  (ALL (x::int). ALL (k::int). (((d::int) dvd (x + t)) = (d dvd (x+k*d1 + t))))"
   387   apply(clarsimp simp add:dvd_def)
   388   apply(rule iffI)
   389   apply(clarsimp)
   390   apply(rename_tac n m)
   391   apply(rule_tac x = "m + n*k" in exI)
   392   apply(simp add:int_distrib)
   393   apply(clarsimp)
   394   apply(rename_tac n m)
   395   apply(rule_tac x = "m - n*k" in exI)
   396   apply(simp add:int_distrib mult_ac)
   397   done
   398 
   399 lemma  not_dvd_modd_pinf: "((d::int) dvd d1) ==>
   400  (ALL (x::int). ALL k. (~((d::int) dvd (x + t))) = (~(d dvd (x+k*d1 + t))))"
   401   apply(clarsimp simp add:dvd_def)
   402   apply(rule iffI)
   403   apply(clarsimp)
   404   apply(rename_tac n m)
   405   apply(erule_tac x = "m - n*k" in allE)
   406   apply(simp add:int_distrib mult_ac)
   407   apply(clarsimp)
   408   apply(rename_tac n m)
   409   apply(erule_tac x = "m + n*k" in allE)
   410   apply(simp add:int_distrib mult_ac)
   411   done
   412 
   413 text {*
   414   \medskip These are the atomic cases for the proof generation for the
   415   equivalence of @{text P} and @{text "P plusinfinity"} for integers
   416   @{text x} greater than some integer @{text z}.
   417 
   418   They are fully based on arithmetics. *}
   419 
   420 lemma  eq_eq_pinf: "EX z::int. ALL x. z < x --> (( 0 = x +t ) = False )"
   421   apply(rule_tac x = "-t" in exI)
   422   apply simp
   423   done
   424 
   425 lemma  neq_eq_pinf: "EX z::int. ALL x.  z < x --> ((~( 0 = x +t )) = True )"
   426   apply(rule_tac x = "-t" in exI)
   427   apply simp
   428   done
   429 
   430 lemma  le_eq_pinf: "EX z::int. ALL x.  z < x --> ( 0 < x +t  = True )"
   431   apply(rule_tac x = "-t" in exI)
   432   apply simp
   433   done
   434 
   435 lemma  len_eq_pinf: "EX z::int. ALL x. z < x  --> (0 < -x +t  = False )"
   436   apply(rule_tac x = "t" in exI)
   437   apply simp
   438   done
   439 
   440 lemma  dvd_eq_pinf: "EX z::int. ALL x.  z < x --> ((d dvd (x + t)) = (d dvd (x + t))) "
   441   by simp
   442 
   443 lemma  not_dvd_eq_pinf: "EX z::int. ALL x. z < x  --> ((~(d dvd (x + t))) = (~(d dvd (x + t)))) "
   444   by simp
   445 
   446 text {*
   447   \medskip These are the atomic cases for the proof generation for the
   448   modulo @{text D} property for @{text "P minusinfinity"}.
   449 
   450   They are fully based on arithmetics. *}
   451 
   452 lemma  dvd_modd_minf: "((d::int) dvd d1) ==>
   453  (ALL (x::int). ALL (k::int). (((d::int) dvd (x + t)) = (d dvd (x-k*d1 + t))))"
   454 apply(clarsimp simp add:dvd_def)
   455 apply(rule iffI)
   456 apply(clarsimp)
   457 apply(rename_tac n m)
   458 apply(rule_tac x = "m - n*k" in exI)
   459 apply(simp add:int_distrib)
   460 apply(clarsimp)
   461 apply(rename_tac n m)
   462 apply(rule_tac x = "m + n*k" in exI)
   463 apply(simp add:int_distrib mult_ac)
   464 done
   465 
   466 
   467 lemma  not_dvd_modd_minf: "((d::int) dvd d1) ==>
   468  (ALL (x::int). ALL k. (~((d::int) dvd (x + t))) = (~(d dvd (x-k*d1 + t))))"
   469 apply(clarsimp simp add:dvd_def)
   470 apply(rule iffI)
   471 apply(clarsimp)
   472 apply(rename_tac n m)
   473 apply(erule_tac x = "m + n*k" in allE)
   474 apply(simp add:int_distrib mult_ac)
   475 apply(clarsimp)
   476 apply(rename_tac n m)
   477 apply(erule_tac x = "m - n*k" in allE)
   478 apply(simp add:int_distrib mult_ac)
   479 done
   480 
   481 text {*
   482   \medskip These are the atomic cases for the proof generation for the
   483   equivalence of @{text P} and @{text "P minusinfinity"} for integers
   484   @{text x} less than some integer @{text z}.
   485 
   486   They are fully based on arithmetics. *}
   487 
   488 lemma  eq_eq_minf: "EX z::int. ALL x. x < z --> (( 0 = x +t ) = False )"
   489 apply(rule_tac x = "-t" in exI)
   490 apply simp
   491 done
   492 
   493 lemma  neq_eq_minf: "EX z::int. ALL x. x < z --> ((~( 0 = x +t )) = True )"
   494 apply(rule_tac x = "-t" in exI)
   495 apply simp
   496 done
   497 
   498 lemma  le_eq_minf: "EX z::int. ALL x. x < z --> ( 0 < x +t  = False )"
   499 apply(rule_tac x = "-t" in exI)
   500 apply simp
   501 done
   502 
   503 
   504 lemma  len_eq_minf: "EX z::int. ALL x. x < z --> (0 < -x +t  = True )"
   505 apply(rule_tac x = "t" in exI)
   506 apply simp
   507 done
   508 
   509 lemma  dvd_eq_minf: "EX z::int. ALL x. x < z --> ((d dvd (x + t)) = (d dvd (x + t))) "
   510   by simp
   511 
   512 lemma  not_dvd_eq_minf: "EX z::int. ALL x. x < z --> ((~(d dvd (x + t))) = (~(d dvd (x + t)))) "
   513   by simp
   514 
   515 text {*
   516   \medskip This Theorem combines whithnesses about @{text "P
   517   minusinfinity"} to show one component of the equivalence proof for
   518   Cooper's Theorem.
   519 
   520   FIXME: remove once they are part of the distribution. *}
   521 
   522 theorem int_ge_induct[consumes 1,case_names base step]:
   523   assumes ge: "k \<le> (i::int)" and
   524         base: "P(k)" and
   525         step: "\<And>i. \<lbrakk>k \<le> i; P i\<rbrakk> \<Longrightarrow> P(i+1)"
   526   shows "P i"
   527 proof -
   528   { fix n have "\<And>i::int. n = nat(i-k) \<Longrightarrow> k <= i \<Longrightarrow> P i"
   529     proof (induct n)
   530       case 0
   531       hence "i = k" by arith
   532       thus "P i" using base by simp
   533     next
   534       case (Suc n)
   535       hence "n = nat((i - 1) - k)" by arith
   536       moreover
   537       have ki1: "k \<le> i - 1" using Suc.prems by arith
   538       ultimately
   539       have "P(i - 1)" by(rule Suc.hyps)
   540       from step[OF ki1 this] show ?case by simp
   541     qed
   542   }
   543   from this ge show ?thesis by fast
   544 qed
   545 
   546 theorem int_gr_induct[consumes 1,case_names base step]:
   547   assumes gr: "k < (i::int)" and
   548         base: "P(k+1)" and
   549         step: "\<And>i. \<lbrakk>k < i; P i\<rbrakk> \<Longrightarrow> P(i+1)"
   550   shows "P i"
   551 apply(rule int_ge_induct[of "k + 1"])
   552   using gr apply arith
   553  apply(rule base)
   554 apply(rule step)
   555  apply simp+
   556 done
   557 
   558 lemma decr_lemma: "0 < (d::int) \<Longrightarrow> x - (abs(x-z)+1) * d < z"
   559 apply(induct rule: int_gr_induct)
   560  apply simp
   561 apply (simp add:int_distrib)
   562 done
   563 
   564 lemma incr_lemma: "0 < (d::int) \<Longrightarrow> z < x + (abs(x-z)+1) * d"
   565 apply(induct rule: int_gr_induct)
   566  apply simp
   567 apply (simp add:int_distrib)
   568 done
   569 
   570 lemma  minusinfinity:
   571   assumes "0 < d" and
   572     P1eqP1: "ALL x k. P1 x = P1(x - k*d)" and
   573     ePeqP1: "EX z::int. ALL x. x < z \<longrightarrow> (P x = P1 x)"
   574   shows "(EX x. P1 x) \<longrightarrow> (EX x. P x)"
   575 proof
   576   assume eP1: "EX x. P1 x"
   577   then obtain x where P1: "P1 x" ..
   578   from ePeqP1 obtain z where P1eqP: "ALL x. x < z \<longrightarrow> (P x = P1 x)" ..
   579   let ?w = "x - (abs(x-z)+1) * d"
   580   show "EX x. P x"
   581   proof
   582     have w: "?w < z" by(rule decr_lemma)
   583     have "P1 x = P1 ?w" using P1eqP1 by blast
   584     also have "\<dots> = P(?w)" using w P1eqP by blast
   585     finally show "P ?w" using P1 by blast
   586   qed
   587 qed
   588 
   589 text {*
   590   \medskip This Theorem combines whithnesses about @{text "P
   591   minusinfinity"} to show one component of the equivalence proof for
   592   Cooper's Theorem. *}
   593 
   594 lemma plusinfinity:
   595   assumes "0 < d" and
   596     P1eqP1: "ALL (x::int) (k::int). P1 x = P1 (x + k * d)" and
   597     ePeqP1: "EX z::int. ALL x. z < x  --> (P x = P1 x)"
   598   shows "(EX x::int. P1 x) --> (EX x::int. P x)"
   599 proof
   600   assume eP1: "EX x. P1 x"
   601   then obtain x where P1: "P1 x" ..
   602   from ePeqP1 obtain z where P1eqP: "ALL x. z < x \<longrightarrow> (P x = P1 x)" ..
   603   let ?w = "x + (abs(x-z)+1) * d"
   604   show "EX x. P x"
   605   proof
   606     have w: "z < ?w" by(rule incr_lemma)
   607     have "P1 x = P1 ?w" using P1eqP1 by blast
   608     also have "\<dots> = P(?w)" using w P1eqP by blast
   609     finally show "P ?w" using P1 by blast
   610   qed
   611 qed
   612  
   613 text {*
   614   \medskip Theorem for periodic function on discrete sets. *}
   615 
   616 lemma minf_vee:
   617   assumes dpos: "(0::int) < d" and modd: "ALL x k. P x = P(x - k*d)"
   618   shows "(EX x. P x) = (EX j : {1..d}. P j)"
   619   (is "?LHS = ?RHS")
   620 proof
   621   assume ?LHS
   622   then obtain x where P: "P x" ..
   623   have "x mod d = x - (x div d)*d"
   624     by(simp add:zmod_zdiv_equality mult_ac eq_diff_eq)
   625   hence Pmod: "P x = P(x mod d)" using modd by simp
   626   show ?RHS
   627   proof (cases)
   628     assume "x mod d = 0"
   629     hence "P 0" using P Pmod by simp
   630     moreover have "P 0 = P(0 - (-1)*d)" using modd by blast
   631     ultimately have "P d" by simp
   632     moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
   633     ultimately show ?RHS ..
   634   next
   635     assume not0: "x mod d \<noteq> 0"
   636     have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
   637     moreover have "x mod d : {1..d}"
   638     proof -
   639       have "0 \<le> x mod d" by(rule pos_mod_sign)
   640       moreover have "x mod d < d" by(rule pos_mod_bound)
   641       ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
   642     qed
   643     ultimately show ?RHS ..
   644   qed
   645 next
   646   assume ?RHS thus ?LHS by blast
   647 qed
   648 
   649 text {*
   650   \medskip Theorem for periodic function on discrete sets. *}
   651 
   652 lemma pinf_vee:
   653   assumes dpos: "0 < (d::int)" and modd: "ALL (x::int) (k::int). P x = P (x+k*d)"
   654   shows "(EX x::int. P x) = (EX (j::int) : {1..d} . P j)"
   655   (is "?LHS = ?RHS")
   656 proof
   657   assume ?LHS
   658   then obtain x where P: "P x" ..
   659   have "x mod d = x + (-(x div d))*d"
   660     by(simp add:zmod_zdiv_equality mult_ac eq_diff_eq)
   661   hence Pmod: "P x = P(x mod d)" using modd by (simp only:)
   662   show ?RHS
   663   proof (cases)
   664     assume "x mod d = 0"
   665     hence "P 0" using P Pmod by simp
   666     moreover have "P 0 = P(0 + 1*d)" using modd by blast
   667     ultimately have "P d" by simp
   668     moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
   669     ultimately show ?RHS ..
   670   next
   671     assume not0: "x mod d \<noteq> 0"
   672     have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
   673     moreover have "x mod d : {1..d}"
   674     proof -
   675       have "0 \<le> x mod d" by(rule pos_mod_sign)
   676       moreover have "x mod d < d" by(rule pos_mod_bound)
   677       ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
   678     qed
   679     ultimately show ?RHS ..
   680   qed
   681 next
   682   assume ?RHS thus ?LHS by blast
   683 qed
   684 
   685 lemma decr_mult_lemma:
   686   assumes dpos: "(0::int) < d" and
   687           minus: "ALL x::int. P x \<longrightarrow> P(x - d)" and
   688           knneg: "0 <= k"
   689   shows "ALL x. P x \<longrightarrow> P(x - k*d)"
   690 using knneg
   691 proof (induct rule:int_ge_induct)
   692   case base thus ?case by simp
   693 next
   694   case (step i)
   695   show ?case
   696   proof
   697     fix x
   698     have "P x \<longrightarrow> P (x - i * d)" using step.hyps by blast
   699     also have "\<dots> \<longrightarrow> P(x - (i + 1) * d)"
   700       using minus[THEN spec, of "x - i * d"]
   701       by (simp add:int_distrib OrderedGroup.diff_diff_eq[symmetric])
   702     ultimately show "P x \<longrightarrow> P(x - (i + 1) * d)" by blast
   703   qed
   704 qed
   705 
   706 lemma incr_mult_lemma:
   707   assumes dpos: "(0::int) < d" and
   708           plus: "ALL x::int. P x \<longrightarrow> P(x + d)" and
   709           knneg: "0 <= k"
   710   shows "ALL x. P x \<longrightarrow> P(x + k*d)"
   711 using knneg
   712 proof (induct rule:int_ge_induct)
   713   case base thus ?case by simp
   714 next
   715   case (step i)
   716   show ?case
   717   proof
   718     fix x
   719     have "P x \<longrightarrow> P (x + i * d)" using step.hyps by blast
   720     also have "\<dots> \<longrightarrow> P(x + (i + 1) * d)"
   721       using plus[THEN spec, of "x + i * d"]
   722       by (simp add:int_distrib zadd_ac)
   723     ultimately show "P x \<longrightarrow> P(x + (i + 1) * d)" by blast
   724   qed
   725 qed
   726 
   727 lemma cpmi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. x < z --> (P x = P1 x))
   728 ==> ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D) 
   729 ==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x-k*D))))
   730 ==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (b::int) : B. P (b+j)))"
   731 apply(rule iffI)
   732 prefer 2
   733 apply(drule minusinfinity)
   734 apply assumption+
   735 apply(fastsimp)
   736 apply clarsimp
   737 apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x - k*D)")
   738 apply(frule_tac x = x and z=z in decr_lemma)
   739 apply(subgoal_tac "P1(x - (\<bar>x - z\<bar> + 1) * D)")
   740 prefer 2
   741 apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
   742 prefer 2 apply arith
   743  apply fastsimp
   744 apply(drule (1) minf_vee)
   745 apply blast
   746 apply(blast dest:decr_mult_lemma)
   747 done
   748 
   749 text {* Cooper Theorem, plus infinity version. *}
   750 lemma cppi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. z < x --> (P x = P1 x))
   751 ==> ALL x.~(EX (j::int) : {1..D}. EX (a::int) : A. P(a - j)) --> P (x) --> P (x + D) 
   752 ==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x+k*D))))
   753 ==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (a::int) : A. P (a - j)))"
   754   apply(rule iffI)
   755   prefer 2
   756   apply(drule plusinfinity)
   757   apply assumption+
   758   apply(fastsimp)
   759   apply clarsimp
   760   apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x + k*D)")
   761   apply(frule_tac x = x and z=z in incr_lemma)
   762   apply(subgoal_tac "P1(x + (\<bar>x - z\<bar> + 1) * D)")
   763   prefer 2
   764   apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
   765   prefer 2 apply arith
   766   apply fastsimp
   767   apply(drule (1) pinf_vee)
   768   apply blast
   769   apply(blast dest:incr_mult_lemma)
   770   done
   771 
   772 
   773 text {*
   774   \bigskip Theorems for the quantifier elminination Functions. *}
   775 
   776 lemma qe_ex_conj: "(EX (x::int). A x) = R
   777 		==> (EX (x::int). P x) = (Q & (EX x::int. A x))
   778 		==> (EX (x::int). P x) = (Q & R)"
   779 by blast
   780 
   781 lemma qe_ex_nconj: "(EX (x::int). P x) = (True & Q)
   782 		==> (EX (x::int). P x) = Q"
   783 by blast
   784 
   785 lemma qe_conjI: "P1 = P2 ==> Q1 = Q2 ==> (P1 & Q1) = (P2 & Q2)"
   786 by blast
   787 
   788 lemma qe_disjI: "P1 = P2 ==> Q1 = Q2 ==> (P1 | Q1) = (P2 | Q2)"
   789 by blast
   790 
   791 lemma qe_impI: "P1 = P2 ==> Q1 = Q2 ==> (P1 --> Q1) = (P2 --> Q2)"
   792 by blast
   793 
   794 lemma qe_eqI: "P1 = P2 ==> Q1 = Q2 ==> (P1 = Q1) = (P2 = Q2)"
   795 by blast
   796 
   797 lemma qe_Not: "P = Q ==> (~P) = (~Q)"
   798 by blast
   799 
   800 lemma qe_ALL: "(EX x. ~P x) = R ==> (ALL x. P x) = (~R)"
   801 by blast
   802 
   803 text {* \bigskip Theorems for proving NNF *}
   804 
   805 lemma nnf_im: "((~P) = P1) ==> (Q=Q1) ==> ((P --> Q) = (P1 | Q1))"
   806 by blast
   807 
   808 lemma nnf_eq: "((P & Q) = (P1 & Q1)) ==> (((~P) & (~Q)) = (P2 & Q2)) ==> ((P = Q) = ((P1 & Q1)|(P2 & Q2)))"
   809 by blast
   810 
   811 lemma nnf_nn: "(P = Q) ==> ((~~P) = Q)"
   812   by blast
   813 lemma nnf_ncj: "((~P) = P1) ==> ((~Q) = Q1) ==> ((~(P & Q)) = (P1 | Q1))"
   814 by blast
   815 
   816 lemma nnf_ndj: "((~P) = P1) ==> ((~Q) = Q1) ==> ((~(P | Q)) = (P1 & Q1))"
   817 by blast
   818 lemma nnf_nim: "(P = P1) ==> ((~Q) = Q1) ==> ((~(P --> Q)) = (P1 & Q1))"
   819 by blast
   820 lemma nnf_neq: "((P & (~Q)) = (P1 & Q1)) ==> (((~P) & Q) = (P2 & Q2)) ==> ((~(P = Q)) = ((P1 & Q1)|(P2 & Q2)))"
   821 by blast
   822 lemma nnf_sdj: "((A & (~B)) = (A1 & B1)) ==> ((C & (~D)) = (C1 & D1)) ==> (A = (~C)) ==> ((~((A & B) | (C & D))) = ((A1 & B1) | (C1 & D1)))"
   823 by blast
   824 
   825 
   826 lemma qe_exI2: "A = B ==> (EX (x::int). A(x)) = (EX (x::int). B(x))"
   827   by simp
   828 
   829 lemma qe_exI: "(!!x::int. A x = B x) ==> (EX (x::int). A(x)) = (EX (x::int). B(x))"
   830   by iprover
   831 
   832 lemma qe_ALLI: "(!!x::int. A x = B x) ==> (ALL (x::int). A(x)) = (ALL (x::int). B(x))"
   833   by iprover
   834 
   835 lemma cp_expand: "(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (b::int) : B. (P1 (j) | P(b+j)))
   836 ==>(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (b::int) : B. (P1 (j) | P(b+j))) "
   837 by blast
   838 
   839 lemma cppi_expand: "(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (a::int) : A. (P1 (j) | P(a - j)))
   840 ==>(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (a::int) : A. (P1 (j) | P(a - j))) "
   841 by blast
   842 
   843 
   844 lemma simp_from_to: "{i..j::int} = (if j < i then {} else insert i {i+1..j})"
   845 apply(simp add:atLeastAtMost_def atLeast_def atMost_def)
   846 apply(fastsimp)
   847 done
   848 
   849 text {* \bigskip Theorems required for the @{text adjustcoeffitienteq} *}
   850 
   851 lemma ac_dvd_eq: assumes not0: "0 ~= (k::int)"
   852 shows "((m::int) dvd (c*n+t)) = (k*m dvd ((k*c)*n+(k*t)))" (is "?P = ?Q")
   853 proof
   854   assume ?P
   855   thus ?Q
   856     apply(simp add:dvd_def)
   857     apply clarify
   858     apply(rename_tac d)
   859     apply(drule_tac f = "op * k" in arg_cong)
   860     apply(simp only:int_distrib)
   861     apply(rule_tac x = "d" in exI)
   862     apply(simp only:mult_ac)
   863     done
   864 next
   865   assume ?Q
   866   then obtain d where "k * c * n + k * t = (k*m)*d" by(fastsimp simp:dvd_def)
   867   hence "(c * n + t) * k = (m*d) * k" by(simp add:int_distrib mult_ac)
   868   hence "((c * n + t) * k) div k = ((m*d) * k) div k" by(rule arg_cong[of _ _ "%t. t div k"])
   869   hence "c*n+t = m*d" by(simp add: zdiv_zmult_self1[OF not0[symmetric]])
   870   thus ?P by(simp add:dvd_def)
   871 qed
   872 
   873 lemma ac_lt_eq: assumes gr0: "0 < (k::int)"
   874 shows "((m::int) < (c*n+t)) = (k*m <((k*c)*n+(k*t)))" (is "?P = ?Q")
   875 proof
   876   assume P: ?P
   877   show ?Q using zmult_zless_mono2[OF P gr0] by(simp add: int_distrib mult_ac)
   878 next
   879   assume ?Q
   880   hence "0 < k*(c*n + t - m)" by(simp add: int_distrib mult_ac)
   881   with gr0 have "0 < (c*n + t - m)" by(simp add: zero_less_mult_iff)
   882   thus ?P by(simp)
   883 qed
   884 
   885 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")
   886 proof
   887   assume ?P
   888   thus ?Q
   889     apply(drule_tac f = "op * k" in arg_cong)
   890     apply(simp only:int_distrib)
   891     done
   892 next
   893   assume ?Q
   894   hence "m * k = (c*n + t) * k" by(simp add:int_distrib mult_ac)
   895   hence "((m) * k) div k = ((c*n + t) * k) div k" by(rule arg_cong[of _ _ "%t. t div k"])
   896   thus ?P by(simp add: zdiv_zmult_self1[OF not0[symmetric]])
   897 qed
   898 
   899 lemma ac_pi_eq: assumes gr0: "0 < (k::int)" shows "(~((0::int) < (c*n + t))) = (0 < ((-k)*c)*n + ((-k)*t + k))"
   900 proof -
   901   have "(~ (0::int) < (c*n + t)) = (0<1-(c*n + t))" by arith
   902   also have  "(1-(c*n + t)) = (-1*c)*n + (-t+1)" by(simp add: int_distrib mult_ac)
   903   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])
   904   also have "(k*(-1*c)*n) + (k*(-t+1)) = ((-k)*c)*n + ((-k)*t + k)" by(simp add: int_distrib mult_ac)
   905   finally show ?thesis .
   906 qed
   907 
   908 lemma binminus_uminus_conv: "(a::int) - b = a + (-b)"
   909 by arith
   910 
   911 lemma  linearize_dvd: "(t::int) = t1 ==> (d dvd t) = (d dvd t1)"
   912 by simp
   913 
   914 lemma lf_lt: "(l::int) = ll ==> (r::int) = lr ==> (l < r) =(ll < lr)"
   915 by simp
   916 
   917 lemma lf_eq: "(l::int) = ll ==> (r::int) = lr ==> (l = r) =(ll = lr)"
   918 by simp
   919 
   920 lemma lf_dvd: "(l::int) = ll ==> (r::int) = lr ==> (l dvd r) =(ll dvd lr)"
   921 by simp
   922 
   923 text {* \bigskip Theorems for transforming predicates on nat to predicates on @{text int}*}
   924 
   925 theorem all_nat: "(\<forall>x::nat. P x) = (\<forall>x::int. 0 <= x \<longrightarrow> P (nat x))"
   926   by (simp split add: split_nat)
   927 
   928 theorem ex_nat: "(\<exists>x::nat. P x) = (\<exists>x::int. 0 <= x \<and> P (nat x))"
   929   apply (simp split add: split_nat)
   930   apply (rule iffI)
   931   apply (erule exE)
   932   apply (rule_tac x = "int x" in exI)
   933   apply simp
   934   apply (erule exE)
   935   apply (rule_tac x = "nat x" in exI)
   936   apply (erule conjE)
   937   apply (erule_tac x = "nat x" in allE)
   938   apply simp
   939   done
   940 
   941 theorem zdiff_int_split: "P (int (x - y)) =
   942   ((y \<le> x \<longrightarrow> P (int x - int y)) \<and> (x < y \<longrightarrow> P 0))"
   943   apply (case_tac "y \<le> x")
   944   apply (simp_all add: zdiff_int)
   945   done
   946 
   947 theorem zdvd_int: "(x dvd y) = (int x dvd int y)"
   948   apply (simp only: dvd_def ex_nat int_int_eq [symmetric] zmult_int [symmetric]
   949     nat_0_le cong add: conj_cong)
   950   apply (rule iffI)
   951   apply iprover
   952   apply (erule exE)
   953   apply (case_tac "x=0")
   954   apply (rule_tac x=0 in exI)
   955   apply simp
   956   apply (case_tac "0 \<le> k")
   957   apply iprover
   958   apply (simp add: linorder_not_le)
   959   apply (drule mult_strict_left_mono_neg [OF iffD2 [OF zero_less_int_conv]])
   960   apply assumption
   961   apply (simp add: mult_ac)
   962   done
   963 
   964 theorem number_of1: "(0::int) <= number_of n \<Longrightarrow> (0::int) <= number_of (n BIT b)"
   965   by simp
   966 
   967 theorem number_of2: "(0::int) <= Numeral0" by simp
   968 
   969 theorem Suc_plus1: "Suc n = n + 1" by simp
   970 
   971 text {*
   972   \medskip Specific instances of congruence rules, to prevent
   973   simplifier from looping. *}
   974 
   975 theorem imp_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<longrightarrow> P) = (0 <= x \<longrightarrow> P')"
   976   by simp
   977 
   978 theorem conj_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<and> P) = (0 <= x \<and> P')"
   979   by (simp cong: conj_cong)
   980 
   981     (* Theorems used in presburger.ML for the computation simpset*)
   982     (* FIXME: They are present in Float.thy, so may be Float.thy should be lightened.*)
   983 
   984 lemma lift_bool: "x \<Longrightarrow> x=True"
   985   by simp
   986 
   987 lemma nlift_bool: "~x \<Longrightarrow> x=False"
   988   by simp
   989 
   990 lemma not_false_eq_true: "(~ False) = True" by simp
   991 
   992 lemma not_true_eq_false: "(~ True) = False" by simp
   993 
   994 
   995 lemma int_eq_number_of_eq: "(((number_of v)::int)=(number_of w)) = iszero ((number_of (bin_add v (bin_minus w)))::int)"
   996   by simp
   997 lemma int_iszero_number_of_Pls: "iszero (Numeral0::int)" 
   998   by (simp only: iszero_number_of_Pls)
   999 
  1000 lemma int_nonzero_number_of_Min: "~(iszero ((-1)::int))"
  1001   by simp
  1002 
  1003 lemma int_iszero_number_of_0: "iszero ((number_of (w BIT bit.B0))::int) = iszero ((number_of w)::int)"
  1004   by simp
  1005 
  1006 lemma int_iszero_number_of_1: "\<not> iszero ((number_of (w BIT bit.B1))::int)" 
  1007   by simp
  1008 
  1009 lemma int_less_number_of_eq_neg: "(((number_of x)::int) < number_of y) = neg ((number_of (bin_add x (bin_minus y)))::int)"
  1010   by simp
  1011 
  1012 lemma int_not_neg_number_of_Pls: "\<not> (neg (Numeral0::int))" 
  1013   by simp
  1014 
  1015 lemma int_neg_number_of_Min: "neg (-1::int)"
  1016   by simp
  1017 
  1018 lemma int_neg_number_of_BIT: "neg ((number_of (w BIT x))::int) = neg ((number_of w)::int)"
  1019   by simp
  1020 
  1021 lemma int_le_number_of_eq: "(((number_of x)::int) \<le> number_of y) = (\<not> neg ((number_of (bin_add y (bin_minus x)))::int))"
  1022   by simp
  1023 lemma int_number_of_add_sym: "((number_of v)::int) + number_of w = number_of (bin_add v w)"
  1024   by simp
  1025 
  1026 lemma int_number_of_diff_sym: "((number_of v)::int) - number_of w = number_of (bin_add v (bin_minus w))"
  1027   by simp
  1028 
  1029 lemma int_number_of_mult_sym: "((number_of v)::int) * number_of w = number_of (bin_mult v w)"
  1030   by simp
  1031 
  1032 lemma int_number_of_minus_sym: "- ((number_of v)::int) = number_of (bin_minus v)"
  1033   by simp
  1034 lemma add_left_zero: "0 + a = (a::'a::comm_monoid_add)"
  1035   by simp
  1036 
  1037 lemma add_right_zero: "a + 0 = (a::'a::comm_monoid_add)"
  1038   by simp
  1039 
  1040 lemma mult_left_one: "1 * a = (a::'a::semiring_1)"
  1041   by simp
  1042 
  1043 lemma mult_right_one: "a * 1 = (a::'a::semiring_1)"
  1044   by simp
  1045 
  1046 lemma int_pow_0: "(a::int)^(Numeral0) = 1"
  1047   by simp
  1048 
  1049 lemma int_pow_1: "(a::int)^(Numeral1) = a"
  1050   by simp
  1051 
  1052 lemma zero_eq_Numeral0_nring: "(0::'a::number_ring) = Numeral0"
  1053   by simp
  1054 
  1055 lemma one_eq_Numeral1_nring: "(1::'a::number_ring) = Numeral1"
  1056   by simp
  1057 
  1058 lemma zero_eq_Numeral0_nat: "(0::nat) = Numeral0"
  1059   by simp
  1060 
  1061 lemma one_eq_Numeral1_nat: "(1::nat) = Numeral1"
  1062   by simp
  1063 
  1064 lemma zpower_Pls: "(z::int)^Numeral0 = Numeral1"
  1065   by simp
  1066 
  1067 lemma zpower_Min: "(z::int)^((-1)::nat) = Numeral1"
  1068 proof -
  1069   have 1:"((-1)::nat) = 0"
  1070     by simp
  1071   show ?thesis by (simp add: 1)
  1072 qed
  1073 
  1074 use "cooper_dec.ML"
  1075 use "reflected_presburger.ML" 
  1076 use "reflected_cooper.ML"
  1077 oracle
  1078   presburger_oracle ("term") = ReflectedCooper.presburger_oracle
  1079 
  1080 use "cooper_proof.ML"
  1081 use "qelim.ML"
  1082 use "presburger.ML"
  1083 
  1084 setup "Presburger.setup"
  1085 
  1086 end