src/HOL/Integ/Presburger.thy
author paulson
Wed Dec 03 10:49:34 2003 +0100 (2003-12-03)
changeset 14271 8ed6989228bb
parent 14139 ca3dd7ed5ac5
child 14353 79f9fbef9106
permissions -rw-r--r--
Simplification of the development of Integers
     1 (*  Title:      HOL/Integ/Presburger.thy
     2     ID:         $Id$
     3     Author:     Amine Chaieb, Tobias Nipkow and Stefan Berghofer, TU Muenchen
     4     License:    GPL (GNU GENERAL PUBLIC LICENSE)
     5 
     6 File containing necessary theorems for the proof
     7 generation for Cooper Algorithm  
     8 *)
     9 
    10 theory Presburger = NatSimprocs
    11 files
    12   ("cooper_dec.ML")
    13   ("cooper_proof.ML")
    14   ("qelim.ML")
    15   ("presburger.ML"):
    16 
    17 (* Theorem for unitifying the coeffitients of 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 (*Theorems for the combination of proofs of the equality of P and P_m for integers x less than some integer 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 (*Theorems for the combination of proofs of the equality of P and P_m for integers x greather than some integer 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 (*Theorems for the combination of proofs of the modulo D property for P
    98 pluusinfinity*)
    99 (* FIXME : This is THE SAME theorem as for the minusinf version, but with +k.. instead of -k.. In the future replace these both with only one*)
   100 
   101 theorem modd_pinf_conjI: "\<forall>(x::int) k. A x = A (x+k*d) \<Longrightarrow>
   102   \<forall>(x::int) k. B x = B (x+k*d) \<Longrightarrow>
   103   \<forall>(x::int) (k::int). (A x \<and> B x) = (A (x+k*d) \<and> B (x+k*d))"
   104   by simp
   105 
   106 
   107 theorem modd_pinf_disjI: "\<forall>(x::int) k. A x = A (x+k*d) \<Longrightarrow>
   108   \<forall>(x::int) k. B x = B (x+k*d) \<Longrightarrow>
   109   \<forall>(x::int) (k::int). (A x \<or> B x) = (A (x+k*d) \<or> B (x+k*d))"
   110   by simp
   111 
   112 (*=============================================================================*)
   113 (*This is one of the cases where the simplifed formula is prooved to habe some property
   114 (in relation to P_m) but we need to proove the property for the original formula (P_m)*)
   115 (*FIXME : This is exaclty the same thm as for minusinf.*)
   116 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)) "
   117 by blast
   118 
   119 
   120 
   121 (*=============================================================================*)
   122 (*Theorems for the combination of proofs of the modulo D property for P
   123 minusinfinity*)
   124 
   125 theorem modd_minf_conjI: "\<forall>(x::int) k. A x = A (x-k*d) \<Longrightarrow>
   126   \<forall>(x::int) k. B x = B (x-k*d) \<Longrightarrow>
   127   \<forall>(x::int) (k::int). (A x \<and> B x) = (A (x-k*d) \<and> B (x-k*d))"
   128   by simp
   129 
   130 
   131 theorem modd_minf_disjI: "\<forall>(x::int) k. A x = A (x-k*d) \<Longrightarrow>
   132   \<forall>(x::int) k. B x = B (x-k*d) \<Longrightarrow>
   133   \<forall>(x::int) (k::int). (A x \<or> B x) = (A (x-k*d) \<or> B (x-k*d))"
   134   by simp
   135 
   136 (*=============================================================================*)
   137 (*This is one of the cases where the simplifed formula is prooved to habe some property
   138 (in relation to P_m) but we need to proove the property for the original formula (P_m)*)
   139 
   140 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)) "
   141 by blast
   142 
   143 (*=============================================================================*)
   144 
   145 (*theorem needed for prooving at runtime divide properties using the arithmetic tatic
   146 (who knows only about modulo = 0)*)
   147 
   148 lemma zdvd_iff_zmod_eq_0: "(m dvd n) = (n mod m = (0::int))"
   149 by(simp add:dvd_def zmod_eq_0_iff)
   150 
   151 (*=============================================================================*)
   152 
   153 
   154 
   155 (*Theorems used for the combination of proof for the backwards direction of cooper's
   156 theorem. they rely exclusively on Predicate calculus.*)
   157 
   158 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))
   159 ==>
   160 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P2(x) --> P2(x + d))
   161 ==>
   162 (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))) "
   163 by blast
   164 
   165 
   166 
   167 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))
   168 ==>
   169 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P2(x) --> P2(x + d))
   170 ==>
   171 (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)
   172 \<and> P2(x + d))) "
   173 by blast
   174 
   175 lemma not_ast_p_Q_elim: "
   176 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) -->P(x) --> P(x + d))
   177 ==> ( P = Q )
   178 ==> (ALL x. ~(EX (j::int) : {1..d}. EX (a::int) : A. P(a - j)) -->P(x) --> P(x + d))"
   179 by blast
   180 (*=============================================================================*)
   181 
   182 
   183 (*Theorems used for the combination of proof for the backwards direction of cooper's
   184 theorem. they rely exclusively on Predicate calculus.*)
   185 
   186 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))
   187 ==>
   188 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P2(x) --> P2(x - d))
   189 ==>
   190 (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)
   191 \<or> P2(x-d))) "
   192 by blast
   193 
   194 
   195 
   196 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))
   197 ==>
   198 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P2(x) --> P2(x - d))
   199 ==>
   200 (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)
   201 \<and> P2(x-d))) "
   202 by blast
   203 
   204 lemma not_bst_p_Q_elim: "
   205 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) -->P(x) --> P(x - d)) 
   206 ==> ( P = Q )
   207 ==> (ALL x. ~(EX (j::int) : {1..d}. EX (b::int) : B. P(b+j)) -->P(x) --> P(x - d))"
   208 by blast
   209 (*=============================================================================*)
   210 
   211 (*This is the first direction of cooper's theorem*)
   212 lemma cooper_thm: "(R --> (EX x::int. P x))  ==> (Q -->(EX x::int.  P x )) ==> ((R|Q) --> (EX x::int. P x )) "
   213 by blast
   214 
   215 (*=============================================================================*)
   216 (*The full cooper's theoorem in its equivalence Form- Given the premisses it is trivial
   217 too, it relies exclusively on prediacte calculus.*)
   218 lemma cooper_eq_thm: "(R --> (EX x::int. P x))  ==> (Q -->(EX x::int.  P x )) ==> ((~Q)
   219 --> (EX x::int. P x ) --> R) ==> (EX x::int. P x) = R|Q "
   220 by blast
   221 
   222 (*=============================================================================*)
   223 (*Some of the atomic theorems generated each time the atom does not depend on x, they
   224 are trivial.*)
   225 
   226 lemma  fm_eq_minf: "EX z::int. ALL x. x < z --> (P = P) "
   227 by blast
   228 
   229 lemma  fm_modd_minf: "ALL (x::int). ALL (k::int). (P = P)"
   230 by blast
   231 
   232 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"
   233 by blast
   234 
   235 
   236 
   237 lemma  fm_eq_pinf: "EX z::int. ALL x. z < x --> (P = P) "
   238 by blast
   239 
   240 (* The next 2 thms are the same as the minusinf version*)
   241 lemma  fm_modd_pinf: "ALL (x::int). ALL (k::int). (P = P)"
   242 by blast
   243 
   244 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"
   245 by blast
   246 
   247 
   248 (* Theorems to be deleted from simpset when proving simplified formulaes*)
   249 lemma P_eqtrue: "(P=True) = P"
   250   by rules
   251 
   252 lemma P_eqfalse: "(P=False) = (~P)"
   253   by rules
   254 
   255 (*=============================================================================*)
   256 
   257 (*Theorems for the generation of the bachwards direction of cooper's theorem*)
   258 (*These are the 6 interesting atomic cases which have to be proved relying on the
   259 properties of B-set ant the arithmetic and contradiction proofs*)
   260 
   261 lemma not_bst_p_lt: "0 < (d::int) ==>
   262  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 )"
   263 by arith
   264 
   265 lemma not_bst_p_gt: "\<lbrakk> (g::int) \<in> B; g = -a \<rbrakk> \<Longrightarrow>
   266  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)"
   267 apply clarsimp
   268 apply(rule ccontr)
   269 apply(drule_tac x = "x+a" in bspec)
   270 apply(simp add:atLeastAtMost_iff)
   271 apply(drule_tac x = "-a" in bspec)
   272 apply assumption
   273 apply(simp)
   274 done
   275 
   276 lemma not_bst_p_eq: "\<lbrakk> 0 < d; (g::int) \<in> B; g = -a - 1 \<rbrakk> \<Longrightarrow>
   277  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 )"
   278 apply clarsimp
   279 apply(subgoal_tac "x = -a")
   280  prefer 2 apply arith
   281 apply(drule_tac x = "1" in bspec)
   282 apply(simp add:atLeastAtMost_iff)
   283 apply(drule_tac x = "-a- 1" in bspec)
   284 apply assumption
   285 apply(simp)
   286 done
   287 
   288 
   289 lemma not_bst_p_ne: "\<lbrakk> 0 < d; (g::int) \<in> B; g = -a \<rbrakk> \<Longrightarrow>
   290  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)"
   291 apply clarsimp
   292 apply(subgoal_tac "x = -a+d")
   293  prefer 2 apply arith
   294 apply(drule_tac x = "d" in bspec)
   295 apply(simp add:atLeastAtMost_iff)
   296 apply(drule_tac x = "-a" in bspec)
   297 apply assumption
   298 apply(simp)
   299 done
   300 
   301 
   302 lemma not_bst_p_dvd: "(d1::int) dvd d ==>
   303  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 )"
   304 apply(clarsimp simp add:dvd_def)
   305 apply(rename_tac m)
   306 apply(rule_tac x = "m - k" in exI)
   307 apply(simp add:int_distrib)
   308 done
   309 
   310 lemma not_bst_p_ndvd: "(d1::int) dvd d ==>
   311  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 ))"
   312 apply(clarsimp simp add:dvd_def)
   313 apply(rename_tac m)
   314 apply(erule_tac x = "m + k" in allE)
   315 apply(simp add:int_distrib)
   316 done
   317 
   318 
   319 
   320 (*Theorems for the generation of the bachwards direction of cooper's theorem*)
   321 (*These are the 6 interesting atomic cases which have to be proved relying on the
   322 properties of A-set ant the arithmetic and 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 
   329 lemma not_ast_p_lt: "\<lbrakk>0 < d ;(t::int) \<in> A \<rbrakk> \<Longrightarrow>
   330  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)"
   331   apply clarsimp
   332   apply (rule ccontr)
   333   apply (drule_tac x = "t-x" in bspec)
   334   apply simp
   335   apply (drule_tac x = "t" in bspec)
   336   apply assumption
   337   apply simp
   338   done
   339 
   340 lemma not_ast_p_eq: "\<lbrakk> 0 < d; (g::int) \<in> A; g = -t + 1 \<rbrakk> \<Longrightarrow>
   341  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 )"
   342   apply clarsimp
   343   apply (drule_tac x="1" in bspec)
   344   apply simp
   345   apply (drule_tac x="- t + 1" in bspec)
   346   apply assumption
   347   apply(subgoal_tac "x = -t")
   348   prefer 2 apply arith
   349   apply simp
   350   done
   351 
   352 lemma not_ast_p_ne: "\<lbrakk> 0 < d; (g::int) \<in> A; g = -t \<rbrakk> \<Longrightarrow>
   353  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)"
   354   apply clarsimp
   355   apply (subgoal_tac "x = -t-d")
   356   prefer 2 apply arith
   357   apply (drule_tac x = "d" in bspec)
   358   apply simp
   359   apply (drule_tac x = "-t" in bspec)
   360   apply assumption
   361   apply simp
   362   done
   363 
   364 lemma not_ast_p_dvd: "(d1::int) dvd d ==>
   365  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 )"
   366   apply(clarsimp simp add:dvd_def)
   367   apply(rename_tac m)
   368   apply(rule_tac x = "m + k" in exI)
   369   apply(simp add:int_distrib)
   370   done
   371 
   372 lemma not_ast_p_ndvd: "(d1::int) dvd d ==>
   373  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 ))"
   374   apply(clarsimp simp add:dvd_def)
   375   apply(rename_tac m)
   376   apply(erule_tac x = "m - k" in allE)
   377   apply(simp add:int_distrib)
   378   done
   379 
   380 
   381 
   382 (*=============================================================================*)
   383 (*These are the atomic cases for the proof generation for the modulo D property for P
   384 plusinfinity*)
   385 (*They are fully based on arithmetics*)
   386 
   387 lemma  dvd_modd_pinf: "((d::int) dvd d1) ==>
   388  (ALL (x::int). ALL (k::int). (((d::int) dvd (x + t)) = (d dvd (x+k*d1 + t))))"
   389   apply(clarsimp simp add:dvd_def)
   390   apply(rule iffI)
   391   apply(clarsimp)
   392   apply(rename_tac n m)
   393   apply(rule_tac x = "m + n*k" in exI)
   394   apply(simp add:int_distrib)
   395   apply(clarsimp)
   396   apply(rename_tac n m)
   397   apply(rule_tac x = "m - n*k" in exI)
   398   apply(simp add:int_distrib mult_ac)
   399   done
   400 
   401 lemma  not_dvd_modd_pinf: "((d::int) dvd d1) ==>
   402  (ALL (x::int). ALL k. (~((d::int) dvd (x + t))) = (~(d dvd (x+k*d1 + t))))"
   403   apply(clarsimp simp add:dvd_def)
   404   apply(rule iffI)
   405   apply(clarsimp)
   406   apply(rename_tac n m)
   407   apply(erule_tac x = "m - n*k" in allE)
   408   apply(simp add:int_distrib mult_ac)
   409   apply(clarsimp)
   410   apply(rename_tac n m)
   411   apply(erule_tac x = "m + n*k" in allE)
   412   apply(simp add:int_distrib mult_ac)
   413   done
   414 
   415 (*=============================================================================*)
   416 (*These are the atomic cases for the proof generation for the equivalence of P and P
   417 plusinfinity for integers x greather than some integer z.*)
   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 
   447 
   448 
   449 (*=============================================================================*)
   450 (*These are the atomic cases for the proof generation for the modulo D property for P
   451 minusinfinity*)
   452 (*They are fully based on arithmetics*)
   453 
   454 lemma  dvd_modd_minf: "((d::int) dvd d1) ==>
   455  (ALL (x::int). ALL (k::int). (((d::int) dvd (x + t)) = (d dvd (x-k*d1 + t))))"
   456 apply(clarsimp simp add:dvd_def)
   457 apply(rule iffI)
   458 apply(clarsimp)
   459 apply(rename_tac n m)
   460 apply(rule_tac x = "m - n*k" in exI)
   461 apply(simp add:int_distrib)
   462 apply(clarsimp)
   463 apply(rename_tac n m)
   464 apply(rule_tac x = "m + n*k" in exI)
   465 apply(simp add:int_distrib mult_ac)
   466 done
   467 
   468 
   469 lemma  not_dvd_modd_minf: "((d::int) dvd d1) ==>
   470  (ALL (x::int). ALL k. (~((d::int) dvd (x + t))) = (~(d dvd (x-k*d1 + t))))"
   471 apply(clarsimp simp add:dvd_def)
   472 apply(rule iffI)
   473 apply(clarsimp)
   474 apply(rename_tac n m)
   475 apply(erule_tac x = "m + n*k" in allE)
   476 apply(simp add:int_distrib mult_ac)
   477 apply(clarsimp)
   478 apply(rename_tac n m)
   479 apply(erule_tac x = "m - n*k" in allE)
   480 apply(simp add:int_distrib mult_ac)
   481 done
   482 
   483 
   484 (*=============================================================================*)
   485 (*These are the atomic cases for the proof generation for the equivalence of P and P
   486 minusinfinity for integers x less than some integer z.*)
   487 (*They are fully based on arithmetics*)
   488 
   489 lemma  eq_eq_minf: "EX z::int. ALL x. x < z --> (( 0 = x +t ) = False )"
   490 apply(rule_tac x = "-t" in exI)
   491 apply simp
   492 done
   493 
   494 lemma  neq_eq_minf: "EX z::int. ALL x. x < z --> ((~( 0 = x +t )) = True )"
   495 apply(rule_tac x = "-t" in exI)
   496 apply simp
   497 done
   498 
   499 lemma  le_eq_minf: "EX z::int. ALL x. x < z --> ( 0 < x +t  = False )"
   500 apply(rule_tac x = "-t" in exI)
   501 apply simp
   502 done
   503 
   504 
   505 lemma  len_eq_minf: "EX z::int. ALL x. x < z --> (0 < -x +t  = True )"
   506 apply(rule_tac x = "t" in exI)
   507 apply simp
   508 done
   509 
   510 lemma  dvd_eq_minf: "EX z::int. ALL x. x < z --> ((d dvd (x + t)) = (d dvd (x + t))) "
   511 by simp
   512 
   513 lemma  not_dvd_eq_minf: "EX z::int. ALL x. x < z --> ((~(d dvd (x + t))) = (~(d dvd (x + t)))) "
   514 by simp
   515 
   516 
   517 (*=============================================================================*)
   518 (*This Theorem combines whithnesses about P minusinfinity to schow one component of the
   519 equivalence proof for cooper's theorem*)
   520 
   521 (* FIXME: remove once they are part of the distribution *)
   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 arith
   562 apply (simp add:int_distrib)
   563 apply arith
   564 done
   565 
   566 lemma incr_lemma: "0 < (d::int) \<Longrightarrow> z < x + (abs(x-z)+1) * d"
   567 apply(induct rule: int_gr_induct)
   568  apply simp
   569  apply arith
   570 apply (simp add:int_distrib)
   571 apply arith
   572 done
   573 
   574 lemma  minusinfinity:
   575   assumes "0 < d" and
   576     P1eqP1: "ALL x k. P1 x = P1(x - k*d)" and
   577     ePeqP1: "EX z::int. ALL x. x < z \<longrightarrow> (P x = P1 x)"
   578   shows "(EX x. P1 x) \<longrightarrow> (EX x. P x)"
   579 proof
   580   assume eP1: "EX x. P1 x"
   581   then obtain x where P1: "P1 x" ..
   582   from ePeqP1 obtain z where P1eqP: "ALL x. x < z \<longrightarrow> (P x = P1 x)" ..
   583   let ?w = "x - (abs(x-z)+1) * d"
   584   show "EX x. P x"
   585   proof
   586     have w: "?w < z" by(rule decr_lemma)
   587     have "P1 x = P1 ?w" using P1eqP1 by blast
   588     also have "\<dots> = P(?w)" using w P1eqP by blast
   589     finally show "P ?w" using P1 by blast
   590   qed
   591 qed
   592 
   593 (*=============================================================================*)
   594 (*This Theorem combines whithnesses about P minusinfinity to schow one component of the
   595 equivalence proof for cooper's theorem*)
   596 
   597 lemma plusinfinity:
   598   assumes "0 < d" and
   599     P1eqP1: "ALL (x::int) (k::int). P1 x = P1 (x + k * d)" and
   600     ePeqP1: "EX z::int. ALL x. z < x  --> (P x = P1 x)"
   601   shows "(EX x::int. P1 x) --> (EX x::int. P x)"
   602 proof
   603   assume eP1: "EX x. P1 x"
   604   then obtain x where P1: "P1 x" ..
   605   from ePeqP1 obtain z where P1eqP: "ALL x. z < x \<longrightarrow> (P x = P1 x)" ..
   606   let ?w = "x + (abs(x-z)+1) * d"
   607   show "EX x. P x"
   608   proof
   609     have w: "z < ?w" by(rule incr_lemma)
   610     have "P1 x = P1 ?w" using P1eqP1 by blast
   611     also have "\<dots> = P(?w)" using w P1eqP by blast
   612     finally show "P ?w" using P1 by blast
   613   qed
   614 qed
   615  
   616 
   617 
   618 (*=============================================================================*)
   619 (*Theorem for periodic function on discrete sets*)
   620 
   621 lemma minf_vee:
   622   assumes dpos: "(0::int) < d" and modd: "ALL x k. P x = P(x - k*d)"
   623   shows "(EX x. P x) = (EX j : {1..d}. P j)"
   624   (is "?LHS = ?RHS")
   625 proof
   626   assume ?LHS
   627   then obtain x where P: "P x" ..
   628   have "x mod d = x - (x div d)*d"
   629     by(simp add:zmod_zdiv_equality mult_ac eq_diff_eq)
   630   hence Pmod: "P x = P(x mod d)" using modd by simp
   631   show ?RHS
   632   proof (cases)
   633     assume "x mod d = 0"
   634     hence "P 0" using P Pmod by simp
   635     moreover have "P 0 = P(0 - (-1)*d)" using modd by blast
   636     ultimately have "P d" by simp
   637     moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
   638     ultimately show ?RHS ..
   639   next
   640     assume not0: "x mod d \<noteq> 0"
   641     have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
   642     moreover have "x mod d : {1..d}"
   643     proof -
   644       have "0 \<le> x mod d" by(rule pos_mod_sign)
   645       moreover have "x mod d < d" by(rule pos_mod_bound)
   646       ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
   647     qed
   648     ultimately show ?RHS ..
   649   qed
   650 next
   651   assume ?RHS thus ?LHS by blast
   652 qed
   653 
   654 (*=============================================================================*)
   655 (*Theorem for periodic function on discrete sets*)
   656 lemma pinf_vee:
   657   assumes dpos: "0 < (d::int)" and modd: "ALL (x::int) (k::int). P x = P (x+k*d)"
   658   shows "(EX x::int. P x) = (EX (j::int) : {1..d} . P j)"
   659   (is "?LHS = ?RHS")
   660 proof
   661   assume ?LHS
   662   then obtain x where P: "P x" ..
   663   have "x mod d = x + (-(x div d))*d"
   664     by(simp add:zmod_zdiv_equality mult_ac eq_diff_eq)
   665   hence Pmod: "P x = P(x mod d)" using modd by (simp only:)
   666   show ?RHS
   667   proof (cases)
   668     assume "x mod d = 0"
   669     hence "P 0" using P Pmod by simp
   670     moreover have "P 0 = P(0 + 1*d)" using modd by blast
   671     ultimately have "P d" by simp
   672     moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
   673     ultimately show ?RHS ..
   674   next
   675     assume not0: "x mod d \<noteq> 0"
   676     have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
   677     moreover have "x mod d : {1..d}"
   678     proof -
   679       have "0 \<le> x mod d" by(rule pos_mod_sign)
   680       moreover have "x mod d < d" by(rule pos_mod_bound)
   681       ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
   682     qed
   683     ultimately show ?RHS ..
   684   qed
   685 next
   686   assume ?RHS thus ?LHS by blast
   687 qed
   688 
   689 lemma decr_mult_lemma:
   690   assumes dpos: "(0::int) < d" and
   691           minus: "ALL x::int. P x \<longrightarrow> P(x - d)" and
   692           knneg: "0 <= k"
   693   shows "ALL x. P x \<longrightarrow> P(x - k*d)"
   694 using knneg
   695 proof (induct rule:int_ge_induct)
   696   case base thus ?case by simp
   697 next
   698   case (step i)
   699   show ?case
   700   proof
   701     fix x
   702     have "P x \<longrightarrow> P (x - i * d)" using step.hyps by blast
   703     also have "\<dots> \<longrightarrow> P(x - (i + 1) * d)"
   704       using minus[THEN spec, of "x - i * d"]
   705       by (simp add:int_distrib Ring_and_Field.diff_diff_eq[symmetric])
   706     ultimately show "P x \<longrightarrow> P(x - (i + 1) * d)" by blast
   707   qed
   708 qed
   709 
   710 lemma incr_mult_lemma:
   711   assumes dpos: "(0::int) < d" and
   712           plus: "ALL x::int. P x \<longrightarrow> P(x + d)" and
   713           knneg: "0 <= k"
   714   shows "ALL x. P x \<longrightarrow> P(x + k*d)"
   715 using knneg
   716 proof (induct rule:int_ge_induct)
   717   case base thus ?case by simp
   718 next
   719   case (step i)
   720   show ?case
   721   proof
   722     fix x
   723     have "P x \<longrightarrow> P (x + i * d)" using step.hyps by blast
   724     also have "\<dots> \<longrightarrow> P(x + (i + 1) * d)"
   725       using plus[THEN spec, of "x + i * d"]
   726       by (simp add:int_distrib zadd_ac)
   727     ultimately show "P x \<longrightarrow> P(x + (i + 1) * d)" by blast
   728   qed
   729 qed
   730 
   731 lemma cpmi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. x < z --> (P x = P1 x))
   732 ==> ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D) 
   733 ==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x-k*D))))
   734 ==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (b::int) : B. P (b+j)))"
   735 apply(rule iffI)
   736 prefer 2
   737 apply(drule minusinfinity)
   738 apply assumption+
   739 apply(fastsimp)
   740 apply clarsimp
   741 apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x - k*D)")
   742 apply(frule_tac x = x and z=z in decr_lemma)
   743 apply(subgoal_tac "P1(x - (\<bar>x - z\<bar> + 1) * D)")
   744 prefer 2
   745 apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
   746 prefer 2 apply arith
   747  apply fastsimp
   748 apply(drule (1) minf_vee)
   749 apply blast
   750 apply(blast dest:decr_mult_lemma)
   751 done
   752 
   753 (* Cooper Thm `, plus infinity version*)
   754 lemma cppi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. z < x --> (P x = P1 x))
   755 ==> ALL x.~(EX (j::int) : {1..D}. EX (a::int) : A. P(a - j)) --> P (x) --> P (x + D) 
   756 ==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x+k*D))))
   757 ==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (a::int) : A. P (a - j)))"
   758   apply(rule iffI)
   759   prefer 2
   760   apply(drule plusinfinity)
   761   apply assumption+
   762   apply(fastsimp)
   763   apply clarsimp
   764   apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x + k*D)")
   765   apply(frule_tac x = x and z=z in incr_lemma)
   766   apply(subgoal_tac "P1(x + (\<bar>x - z\<bar> + 1) * D)")
   767   prefer 2
   768   apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
   769   prefer 2 apply arith
   770   apply fastsimp
   771   apply(drule (1) pinf_vee)
   772   apply blast
   773   apply(blast dest:incr_mult_lemma)
   774   done
   775 
   776 
   777 (*=============================================================================*)
   778 
   779 (*Theorems for the quantifier elminination Functions.*)
   780 
   781 lemma qe_ex_conj: "(EX (x::int). A x) = R
   782 		==> (EX (x::int). P x) = (Q & (EX x::int. A x))
   783 		==> (EX (x::int). P x) = (Q & R)"
   784 by blast
   785 
   786 lemma qe_ex_nconj: "(EX (x::int). P x) = (True & Q)
   787 		==> (EX (x::int). P x) = Q"
   788 by blast
   789 
   790 lemma qe_conjI: "P1 = P2 ==> Q1 = Q2 ==> (P1 & Q1) = (P2 & Q2)"
   791 by blast
   792 
   793 lemma qe_disjI: "P1 = P2 ==> Q1 = Q2 ==> (P1 | Q1) = (P2 | Q2)"
   794 by blast
   795 
   796 lemma qe_impI: "P1 = P2 ==> Q1 = Q2 ==> (P1 --> Q1) = (P2 --> Q2)"
   797 by blast
   798 
   799 lemma qe_eqI: "P1 = P2 ==> Q1 = Q2 ==> (P1 = Q1) = (P2 = Q2)"
   800 by blast
   801 
   802 lemma qe_Not: "P = Q ==> (~P) = (~Q)"
   803 by blast
   804 
   805 lemma qe_ALL: "(EX x. ~P x) = R ==> (ALL x. P x) = (~R)"
   806 by blast
   807 
   808 (* Theorems for proving NNF *)
   809 
   810 lemma nnf_im: "((~P) = P1) ==> (Q=Q1) ==> ((P --> Q) = (P1 | Q1))"
   811 by blast
   812 
   813 lemma nnf_eq: "((P & Q) = (P1 & Q1)) ==> (((~P) & (~Q)) = (P2 & Q2)) ==> ((P = Q) = ((P1 & Q1)|(P2 & Q2)))"
   814 by blast
   815 
   816 lemma nnf_nn: "(P = Q) ==> ((~~P) = Q)"
   817   by blast
   818 lemma nnf_ncj: "((~P) = P1) ==> ((~Q) = Q1) ==> ((~(P & Q)) = (P1 | Q1))"
   819 by blast
   820 
   821 lemma nnf_ndj: "((~P) = P1) ==> ((~Q) = Q1) ==> ((~(P | Q)) = (P1 & Q1))"
   822 by blast
   823 lemma nnf_nim: "(P = P1) ==> ((~Q) = Q1) ==> ((~(P --> Q)) = (P1 & Q1))"
   824 by blast
   825 lemma nnf_neq: "((P & (~Q)) = (P1 & Q1)) ==> (((~P) & Q) = (P2 & Q2)) ==> ((~(P = Q)) = ((P1 & Q1)|(P2 & Q2)))"
   826 by blast
   827 lemma nnf_sdj: "((A & (~B)) = (A1 & B1)) ==> ((C & (~D)) = (C1 & D1)) ==> (A = (~C)) ==> ((~((A & B) | (C & D))) = ((A1 & B1) | (C1 & D1)))"
   828 by blast
   829 
   830 
   831 lemma qe_exI2: "A = B ==> (EX (x::int). A(x)) = (EX (x::int). B(x))"
   832   by simp
   833 
   834 lemma qe_exI: "(!!x::int. A x = B x) ==> (EX (x::int). A(x)) = (EX (x::int). B(x))"
   835   by rules
   836 
   837 lemma qe_ALLI: "(!!x::int. A x = B x) ==> (ALL (x::int). A(x)) = (ALL (x::int). B(x))"
   838   by rules
   839 
   840 lemma cp_expand: "(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (b::int) : B. (P1 (j) | P(b+j)))
   841 ==>(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (b::int) : B. (P1 (j) | P(b+j))) "
   842 by blast
   843 
   844 lemma cppi_expand: "(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (a::int) : A. (P1 (j) | P(a - j)))
   845 ==>(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (a::int) : A. (P1 (j) | P(a - j))) "
   846 by blast
   847 
   848 
   849 lemma simp_from_to: "{i..j::int} = (if j < i then {} else insert i {i+1..j})"
   850 apply(simp add:atLeastAtMost_def atLeast_def atMost_def)
   851 apply(fastsimp)
   852 done
   853 
   854 (* Theorems required for the adjustcoeffitienteq*)
   855 
   856 lemma ac_dvd_eq: assumes not0: "0 ~= (k::int)"
   857 shows "((m::int) dvd (c*n+t)) = (k*m dvd ((k*c)*n+(k*t)))" (is "?P = ?Q")
   858 proof
   859   assume ?P
   860   thus ?Q
   861     apply(simp add:dvd_def)
   862     apply clarify
   863     apply(rename_tac d)
   864     apply(drule_tac f = "op * k" in arg_cong)
   865     apply(simp only:int_distrib)
   866     apply(rule_tac x = "d" in exI)
   867     apply(simp only:mult_ac)
   868     done
   869 next
   870   assume ?Q
   871   then obtain d where "k * c * n + k * t = (k*m)*d" by(fastsimp simp:dvd_def)
   872   hence "(c * n + t) * k = (m*d) * k" by(simp add:int_distrib mult_ac)
   873   hence "((c * n + t) * k) div k = ((m*d) * k) div k" by(rule arg_cong[of _ _ "%t. t div k"])
   874   hence "c*n+t = m*d" by(simp add: zdiv_zmult_self1[OF not0[symmetric]])
   875   thus ?P by(simp add:dvd_def)
   876 qed
   877 
   878 lemma ac_lt_eq: assumes gr0: "0 < (k::int)"
   879 shows "((m::int) < (c*n+t)) = (k*m <((k*c)*n+(k*t)))" (is "?P = ?Q")
   880 proof
   881   assume P: ?P
   882   show ?Q using zmult_zless_mono2[OF P gr0] by(simp add: int_distrib mult_ac)
   883 next
   884   assume ?Q
   885   hence "0 < k*(c*n + t - m)" by(simp add: int_distrib mult_ac)
   886   with gr0 have "0 < (c*n + t - m)" by(simp add:int_0_less_mult_iff)
   887   thus ?P by(simp)
   888 qed
   889 
   890 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")
   891 proof
   892   assume ?P
   893   thus ?Q
   894     apply(drule_tac f = "op * k" in arg_cong)
   895     apply(simp only:int_distrib)
   896     done
   897 next
   898   assume ?Q
   899   hence "m * k = (c*n + t) * k" by(simp add:int_distrib mult_ac)
   900   hence "((m) * k) div k = ((c*n + t) * k) div k" by(rule arg_cong[of _ _ "%t. t div k"])
   901   thus ?P by(simp add: zdiv_zmult_self1[OF not0[symmetric]])
   902 qed
   903 
   904 lemma ac_pi_eq: assumes gr0: "0 < (k::int)" shows "(~((0::int) < (c*n + t))) = (0 < ((-k)*c)*n + ((-k)*t + k))"
   905 proof -
   906   have "(~ (0::int) < (c*n + t)) = (0<1-(c*n + t))" by arith
   907   also have  "(1-(c*n + t)) = (-1*c)*n + (-t+1)" by(simp add: int_distrib mult_ac)
   908   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])
   909   also have "(k*(-1*c)*n) + (k*(-t+1)) = ((-k)*c)*n + ((-k)*t + k)" by(simp add: int_distrib mult_ac)
   910   finally show ?thesis .
   911 qed
   912 
   913 lemma binminus_uminus_conv: "(a::int) - b = a + (-b)"
   914 by arith
   915 
   916 lemma  linearize_dvd: "(t::int) = t1 ==> (d dvd t) = (d dvd t1)"
   917 by simp
   918 
   919 lemma lf_lt: "(l::int) = ll ==> (r::int) = lr ==> (l < r) =(ll < lr)"
   920 by simp
   921 
   922 lemma lf_eq: "(l::int) = ll ==> (r::int) = lr ==> (l = r) =(ll = lr)"
   923 by simp
   924 
   925 lemma lf_dvd: "(l::int) = ll ==> (r::int) = lr ==> (l dvd r) =(ll dvd lr)"
   926 by simp
   927 
   928 (* Theorems for transforming predicates on nat to predicates on int*)
   929 
   930 theorem all_nat: "(\<forall>x::nat. P x) = (\<forall>x::int. 0 <= x \<longrightarrow> P (nat x))"
   931   by (simp split add: split_nat)
   932 
   933 theorem ex_nat: "(\<exists>x::nat. P x) = (\<exists>x::int. 0 <= x \<and> P (nat x))"
   934   apply (simp split add: split_nat)
   935   apply (rule iffI)
   936   apply (erule exE)
   937   apply (rule_tac x = "int x" in exI)
   938   apply simp
   939   apply (erule exE)
   940   apply (rule_tac x = "nat x" in exI)
   941   apply (erule conjE)
   942   apply (erule_tac x = "nat x" in allE)
   943   apply simp
   944   done
   945 
   946 theorem zdiff_int_split: "P (int (x - y)) =
   947   ((y \<le> x \<longrightarrow> P (int x - int y)) \<and> (x < y \<longrightarrow> P 0))"
   948   apply (case_tac "y \<le> x")
   949   apply (simp_all add: zdiff_int)
   950   done
   951 
   952 theorem zdvd_int: "(x dvd y) = (int x dvd int y)"
   953   apply (simp only: dvd_def ex_nat int_int_eq [symmetric] zmult_int [symmetric]
   954     nat_0_le cong add: conj_cong)
   955   apply (rule iffI)
   956   apply rules
   957   apply (erule exE)
   958   apply (case_tac "x=0")
   959   apply (rule_tac x=0 in exI)
   960   apply simp
   961   apply (case_tac "0 \<le> k")
   962   apply rules
   963   apply (simp add: linorder_not_le)
   964   apply (drule zmult_zless_mono2_neg [OF iffD2 [OF zero_less_int_conv]])
   965   apply assumption
   966   apply (simp add: mult_ac)
   967   done
   968 
   969 theorem number_of1: "(0::int) <= number_of n \<Longrightarrow> (0::int) <= number_of (n BIT b)"
   970   by simp
   971 
   972 theorem number_of2: "(0::int) <= number_of bin.Pls" by simp
   973 
   974 theorem Suc_plus1: "Suc n = n + 1" by simp
   975 
   976 (* specific instances of congruence rules, to prevent simplifier from looping *)
   977 
   978 theorem imp_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::nat) \<longrightarrow> P) = (0 <= x \<longrightarrow> P')"
   979   by simp
   980 
   981 theorem conj_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::nat) \<and> P) = (0 <= x \<and> P')"
   982   by simp
   983 
   984 use "cooper_dec.ML"
   985 use "cooper_proof.ML"
   986 use "qelim.ML"
   987 use "presburger.ML"
   988 
   989 setup "Presburger.setup"
   990 
   991 end