src/HOL/Integ/Presburger.thy
author paulson
Thu Jul 01 12:29:53 2004 +0200 (2004-07-01)
changeset 15013 34264f5e4691
parent 14981 e73f8140af78
child 15131 c69542757a4d
permissions -rw-r--r--
new treatment of binary numerals
     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 Algorithm *}
    10 
    11 theory Presburger = NatSimprocs + SetInterval
    12 files
    13   ("cooper_dec.ML")
    14   ("cooper_proof.ML")
    15   ("qelim.ML")
    16   ("presburger.ML"):
    17 
    18 text {* Theorem for unitifying the coeffitients of @{text x} in an existential formula*}
    19 
    20 theorem unity_coeff_ex: "(\<exists>x::int. P (l * x)) = (\<exists>x. l dvd (1*x+0) \<and> P x)"
    21   apply (rule iffI)
    22   apply (erule exE)
    23   apply (rule_tac x = "l * x" in exI)
    24   apply simp
    25   apply (erule exE)
    26   apply (erule conjE)
    27   apply (erule dvdE)
    28   apply (rule_tac x = k in exI)
    29   apply simp
    30   done
    31 
    32 lemma uminus_dvd_conv: "(d dvd (t::int)) = (-d dvd t)"
    33 apply(unfold dvd_def)
    34 apply(rule iffI)
    35 apply(clarsimp)
    36 apply(rename_tac k)
    37 apply(rule_tac x = "-k" in exI)
    38 apply simp
    39 apply(clarsimp)
    40 apply(rename_tac k)
    41 apply(rule_tac x = "-k" in exI)
    42 apply simp
    43 done
    44 
    45 lemma uminus_dvd_conv': "(d dvd (t::int)) = (d dvd -t)"
    46 apply(unfold dvd_def)
    47 apply(rule iffI)
    48 apply(clarsimp)
    49 apply(rule_tac x = "-k" in exI)
    50 apply simp
    51 apply(clarsimp)
    52 apply(rule_tac x = "-k" in exI)
    53 apply simp
    54 done
    55 
    56 
    57 
    58 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}.*}
    59 
    60 theorem eq_minf_conjI: "\<exists>z1::int. \<forall>x. x < z1 \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
    61   \<exists>z2::int. \<forall>x. x < z2 \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
    62   \<exists>z::int. \<forall>x. x < z \<longrightarrow> ((A1 x \<and> B1 x) = (A2 x \<and> B2 x))"
    63   apply (erule exE)+
    64   apply (rule_tac x = "min z1 z2" in exI)
    65   apply simp
    66   done
    67 
    68 
    69 theorem eq_minf_disjI: "\<exists>z1::int. \<forall>x. x < z1 \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
    70   \<exists>z2::int. \<forall>x. x < z2 \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
    71   \<exists>z::int. \<forall>x. x < z \<longrightarrow> ((A1 x \<or> B1 x) = (A2 x \<or> B2 x))"
    72 
    73   apply (erule exE)+
    74   apply (rule_tac x = "min z1 z2" in exI)
    75   apply simp
    76   done
    77 
    78 
    79 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}.*}
    80 
    81 theorem eq_pinf_conjI: "\<exists>z1::int. \<forall>x. z1 < x \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
    82   \<exists>z2::int. \<forall>x. z2 < x \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
    83   \<exists>z::int. \<forall>x. z < x \<longrightarrow> ((A1 x \<and> B1 x) = (A2 x \<and> B2 x))"
    84   apply (erule exE)+
    85   apply (rule_tac x = "max z1 z2" in exI)
    86   apply simp
    87   done
    88 
    89 
    90 theorem eq_pinf_disjI: "\<exists>z1::int. \<forall>x. z1 < x \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
    91   \<exists>z2::int. \<forall>x. z2 < x \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
    92   \<exists>z::int. \<forall>x. z < x  \<longrightarrow> ((A1 x \<or> B1 x) = (A2 x \<or> B2 x))"
    93   apply (erule exE)+
    94   apply (rule_tac x = "max z1 z2" in exI)
    95   apply simp
    96   done
    97 
    98 text {*
    99   \medskip Theorems for the combination of proofs of the modulo @{text
   100   D} property for @{text "P plusinfinity"}
   101 
   102   FIXME: This is THE SAME theorem as for the @{text minusinf} version,
   103   but with @{text "+k.."} instead of @{text "-k.."} In the future
   104   replace these both with only one. *}
   105 
   106 theorem modd_pinf_conjI: "\<forall>(x::int) k. A x = A (x+k*d) \<Longrightarrow>
   107   \<forall>(x::int) k. B x = B (x+k*d) \<Longrightarrow>
   108   \<forall>(x::int) (k::int). (A x \<and> B x) = (A (x+k*d) \<and> B (x+k*d))"
   109   by simp
   110 
   111 theorem modd_pinf_disjI: "\<forall>(x::int) k. A x = A (x+k*d) \<Longrightarrow>
   112   \<forall>(x::int) k. B x = B (x+k*d) \<Longrightarrow>
   113   \<forall>(x::int) (k::int). (A x \<or> B x) = (A (x+k*d) \<or> B (x+k*d))"
   114   by simp
   115 
   116 text {*
   117   This is one of the cases where the simplifed formula is prooved to
   118   habe some property (in relation to @{text P_m}) but we need to prove
   119   the property for the original formula (@{text P_m})
   120 
   121   FIXME: This is exaclty the same thm as for @{text minusinf}. *}
   122 
   123 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)) "
   124   by blast
   125 
   126 
   127 text {*
   128   \medskip Theorems for the combination of proofs of the modulo @{text D}
   129   property for @{text "P minusinfinity"} *}
   130 
   131 theorem modd_minf_conjI: "\<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 \<and> B x) = (A (x-k*d) \<and> B (x-k*d))"
   134   by simp
   135 
   136 theorem modd_minf_disjI: "\<forall>(x::int) k. A x = A (x-k*d) \<Longrightarrow>
   137   \<forall>(x::int) k. B x = B (x-k*d) \<Longrightarrow>
   138   \<forall>(x::int) (k::int). (A x \<or> B x) = (A (x-k*d) \<or> B (x-k*d))"
   139   by simp
   140 
   141 text {*
   142   This is one of the cases where the simplifed formula is prooved to
   143   have some property (in relation to @{text P_m}) but we need to
   144   prove the property for the original formula (@{text P_m}). *}
   145 
   146 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)) "
   147   by blast
   148 
   149 text {*
   150   Theorem needed for proving at runtime divide properties using the
   151   arithmetic tactic (which knows only about modulo = 0). *}
   152 
   153 lemma zdvd_iff_zmod_eq_0: "(m dvd n) = (n mod m = (0::int))"
   154   by(simp add:dvd_def zmod_eq_0_iff)
   155 
   156 text {*
   157   \medskip Theorems used for the combination of proof for the
   158   backwards direction of Cooper's Theorem. They rely exclusively on
   159   Predicate calculus.*}
   160 
   161 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))
   162 ==>
   163 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P2(x) --> P2(x + d))
   164 ==>
   165 (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))) "
   166   by blast
   167 
   168 
   169 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))
   170 ==>
   171 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P2(x) --> P2(x + d))
   172 ==>
   173 (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)
   174 \<and> P2(x + d))) "
   175   by blast
   176 
   177 lemma not_ast_p_Q_elim: "
   178 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) -->P(x) --> P(x + d))
   179 ==> ( P = Q )
   180 ==> (ALL x. ~(EX (j::int) : {1..d}. EX (a::int) : A. P(a - j)) -->P(x) --> P(x + d))"
   181   by blast
   182 
   183 text {*
   184   \medskip Theorems used for the combination of proof for the
   185   backwards direction of Cooper's Theorem. They rely exclusively on
   186   Predicate calculus.*}
   187 
   188 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))
   189 ==>
   190 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P2(x) --> P2(x - d))
   191 ==>
   192 (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)
   193 \<or> P2(x-d))) "
   194   by blast
   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 text {* \medskip This is the first direction of Cooper's Theorem. *}
   211 lemma cooper_thm: "(R --> (EX x::int. P x))  ==> (Q -->(EX x::int.  P x )) ==> ((R|Q) --> (EX x::int. P x )) "
   212   by blast
   213 
   214 text {*
   215   \medskip The full Cooper's Theorem in its equivalence Form. Given
   216   the premises it is trivial too, it relies exclusively on prediacte calculus.*}
   217 lemma cooper_eq_thm: "(R --> (EX x::int. P x))  ==> (Q -->(EX x::int.  P x )) ==> ((~Q)
   218 --> (EX x::int. P x ) --> R) ==> (EX x::int. P x) = R|Q "
   219   by blast
   220 
   221 text {*
   222   \medskip Some of the atomic theorems generated each time the atom
   223   does not depend on @{text x}, they are trivial.*}
   224 
   225 lemma  fm_eq_minf: "EX z::int. ALL x. x < z --> (P = P) "
   226   by blast
   227 
   228 lemma  fm_modd_minf: "ALL (x::int). ALL (k::int). (P = P)"
   229   by blast
   230 
   231 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"
   232   by blast
   233 
   234 lemma  fm_eq_pinf: "EX z::int. ALL x. z < x --> (P = P) "
   235   by blast
   236 
   237 text {* The next two thms are the same as the @{text minusinf} version. *}
   238 
   239 lemma  fm_modd_pinf: "ALL (x::int). ALL (k::int). (P = P)"
   240   by blast
   241 
   242 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"
   243   by blast
   244 
   245 text {* Theorems to be deleted from simpset when proving simplified formulaes. *}
   246 
   247 lemma P_eqtrue: "(P=True) = P"
   248   by rules
   249 
   250 lemma P_eqfalse: "(P=False) = (~P)"
   251   by rules
   252 
   253 text {*
   254   \medskip Theorems for the generation of the bachwards direction of
   255   Cooper's Theorem.
   256 
   257   These are the 6 interesting atomic cases which have to be proved relying on the
   258   properties of B-set and the arithmetic and contradiction proofs. *}
   259 
   260 lemma not_bst_p_lt: "0 < (d::int) ==>
   261  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 )"
   262   by arith
   263 
   264 lemma not_bst_p_gt: "\<lbrakk> (g::int) \<in> B; g = -a \<rbrakk> \<Longrightarrow>
   265  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)"
   266 apply clarsimp
   267 apply(rule ccontr)
   268 apply(drule_tac x = "x+a" in bspec)
   269 apply(simp add:atLeastAtMost_iff)
   270 apply(drule_tac x = "-a" in bspec)
   271 apply assumption
   272 apply(simp)
   273 done
   274 
   275 lemma not_bst_p_eq: "\<lbrakk> 0 < d; (g::int) \<in> B; g = -a - 1 \<rbrakk> \<Longrightarrow>
   276  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 )"
   277 apply clarsimp
   278 apply(subgoal_tac "x = -a")
   279  prefer 2 apply arith
   280 apply(drule_tac x = "1" in bspec)
   281 apply(simp add:atLeastAtMost_iff)
   282 apply(drule_tac x = "-a- 1" in bspec)
   283 apply assumption
   284 apply(simp)
   285 done
   286 
   287 
   288 lemma not_bst_p_ne: "\<lbrakk> 0 < d; (g::int) \<in> B; g = -a \<rbrakk> \<Longrightarrow>
   289  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)"
   290 apply clarsimp
   291 apply(subgoal_tac "x = -a+d")
   292  prefer 2 apply arith
   293 apply(drule_tac x = "d" in bspec)
   294 apply(simp add:atLeastAtMost_iff)
   295 apply(drule_tac x = "-a" in bspec)
   296 apply assumption
   297 apply(simp)
   298 done
   299 
   300 
   301 lemma not_bst_p_dvd: "(d1::int) dvd d ==>
   302  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 )"
   303 apply(clarsimp simp add:dvd_def)
   304 apply(rename_tac m)
   305 apply(rule_tac x = "m - k" in exI)
   306 apply(simp add:int_distrib)
   307 done
   308 
   309 lemma not_bst_p_ndvd: "(d1::int) dvd d ==>
   310  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 ))"
   311 apply(clarsimp simp add:dvd_def)
   312 apply(rename_tac m)
   313 apply(erule_tac x = "m + k" in allE)
   314 apply(simp add:int_distrib)
   315 done
   316 
   317 text {*
   318   \medskip Theorems for the generation of the bachwards direction of
   319   Cooper's Theorem.
   320 
   321   These are the 6 interesting atomic cases which have to be proved
   322   relying on the properties of A-set ant the arithmetic and
   323   contradiction proofs. *}
   324 
   325 lemma not_ast_p_gt: "0 < (d::int) ==>
   326  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 )"
   327   by arith
   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 text {*
   381   \medskip These are the atomic cases for the proof generation for the
   382   modulo @{text D} property for @{text "P plusinfinity"}
   383 
   384   They are fully based on arithmetics. *}
   385 
   386 lemma  dvd_modd_pinf: "((d::int) dvd d1) ==>
   387  (ALL (x::int). ALL (k::int). (((d::int) dvd (x + t)) = (d dvd (x+k*d1 + t))))"
   388   apply(clarsimp simp add:dvd_def)
   389   apply(rule iffI)
   390   apply(clarsimp)
   391   apply(rename_tac n m)
   392   apply(rule_tac x = "m + n*k" in exI)
   393   apply(simp add:int_distrib)
   394   apply(clarsimp)
   395   apply(rename_tac n m)
   396   apply(rule_tac x = "m - n*k" in exI)
   397   apply(simp add:int_distrib mult_ac)
   398   done
   399 
   400 lemma  not_dvd_modd_pinf: "((d::int) dvd d1) ==>
   401  (ALL (x::int). ALL k. (~((d::int) dvd (x + t))) = (~(d dvd (x+k*d1 + t))))"
   402   apply(clarsimp simp add:dvd_def)
   403   apply(rule iffI)
   404   apply(clarsimp)
   405   apply(rename_tac n m)
   406   apply(erule_tac x = "m - n*k" in allE)
   407   apply(simp add:int_distrib mult_ac)
   408   apply(clarsimp)
   409   apply(rename_tac n m)
   410   apply(erule_tac x = "m + n*k" in allE)
   411   apply(simp add:int_distrib mult_ac)
   412   done
   413 
   414 text {*
   415   \medskip These are the atomic cases for the proof generation for the
   416   equivalence of @{text P} and @{text "P plusinfinity"} for integers
   417   @{text x} greater than some integer @{text z}.
   418 
   419   They are fully based on arithmetics. *}
   420 
   421 lemma  eq_eq_pinf: "EX z::int. ALL x. z < x --> (( 0 = x +t ) = False )"
   422   apply(rule_tac x = "-t" in exI)
   423   apply simp
   424   done
   425 
   426 lemma  neq_eq_pinf: "EX z::int. ALL x.  z < x --> ((~( 0 = x +t )) = True )"
   427   apply(rule_tac x = "-t" in exI)
   428   apply simp
   429   done
   430 
   431 lemma  le_eq_pinf: "EX z::int. ALL x.  z < x --> ( 0 < x +t  = True )"
   432   apply(rule_tac x = "-t" in exI)
   433   apply simp
   434   done
   435 
   436 lemma  len_eq_pinf: "EX z::int. ALL x. z < x  --> (0 < -x +t  = False )"
   437   apply(rule_tac x = "t" in exI)
   438   apply simp
   439   done
   440 
   441 lemma  dvd_eq_pinf: "EX z::int. ALL x.  z < x --> ((d dvd (x + t)) = (d dvd (x + t))) "
   442   by simp
   443 
   444 lemma  not_dvd_eq_pinf: "EX z::int. ALL x. z < x  --> ((~(d dvd (x + t))) = (~(d dvd (x + t)))) "
   445   by simp
   446 
   447 text {*
   448   \medskip These are the atomic cases for the proof generation for the
   449   modulo @{text D} property for @{text "P minusinfinity"}.
   450 
   451   They are fully based on arithmetics. *}
   452 
   453 lemma  dvd_modd_minf: "((d::int) dvd d1) ==>
   454  (ALL (x::int). ALL (k::int). (((d::int) dvd (x + t)) = (d dvd (x-k*d1 + t))))"
   455 apply(clarsimp simp add:dvd_def)
   456 apply(rule iffI)
   457 apply(clarsimp)
   458 apply(rename_tac n m)
   459 apply(rule_tac x = "m - n*k" in exI)
   460 apply(simp add:int_distrib)
   461 apply(clarsimp)
   462 apply(rename_tac n m)
   463 apply(rule_tac x = "m + n*k" in exI)
   464 apply(simp add:int_distrib mult_ac)
   465 done
   466 
   467 
   468 lemma  not_dvd_modd_minf: "((d::int) dvd d1) ==>
   469  (ALL (x::int). ALL k. (~((d::int) dvd (x + t))) = (~(d dvd (x-k*d1 + t))))"
   470 apply(clarsimp simp add:dvd_def)
   471 apply(rule iffI)
   472 apply(clarsimp)
   473 apply(rename_tac n m)
   474 apply(erule_tac x = "m + n*k" in allE)
   475 apply(simp add:int_distrib mult_ac)
   476 apply(clarsimp)
   477 apply(rename_tac n m)
   478 apply(erule_tac x = "m - n*k" in allE)
   479 apply(simp add:int_distrib mult_ac)
   480 done
   481 
   482 text {*
   483   \medskip These are the atomic cases for the proof generation for the
   484   equivalence of @{text P} and @{text "P minusinfinity"} for integers
   485   @{text x} less than some integer @{text z}.
   486 
   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 text {*
   517   \medskip This Theorem combines whithnesses about @{text "P
   518   minusinfinity"} to show one component of the equivalence proof for
   519   Cooper's Theorem.
   520 
   521   FIXME: remove once they are part of the distribution. *}
   522 
   523 theorem int_ge_induct[consumes 1,case_names base step]:
   524   assumes ge: "k \<le> (i::int)" and
   525         base: "P(k)" and
   526         step: "\<And>i. \<lbrakk>k \<le> i; P i\<rbrakk> \<Longrightarrow> P(i+1)"
   527   shows "P i"
   528 proof -
   529   { fix n have "\<And>i::int. n = nat(i-k) \<Longrightarrow> k <= i \<Longrightarrow> P i"
   530     proof (induct n)
   531       case 0
   532       hence "i = k" by arith
   533       thus "P i" using base by simp
   534     next
   535       case (Suc n)
   536       hence "n = nat((i - 1) - k)" by arith
   537       moreover
   538       have ki1: "k \<le> i - 1" using Suc.prems by arith
   539       ultimately
   540       have "P(i - 1)" by(rule Suc.hyps)
   541       from step[OF ki1 this] show ?case by simp
   542     qed
   543   }
   544   from this ge show ?thesis by fast
   545 qed
   546 
   547 theorem int_gr_induct[consumes 1,case_names base step]:
   548   assumes gr: "k < (i::int)" and
   549         base: "P(k+1)" and
   550         step: "\<And>i. \<lbrakk>k < i; P i\<rbrakk> \<Longrightarrow> P(i+1)"
   551   shows "P i"
   552 apply(rule int_ge_induct[of "k + 1"])
   553   using gr apply arith
   554  apply(rule base)
   555 apply(rule step)
   556  apply simp+
   557 done
   558 
   559 lemma decr_lemma: "0 < (d::int) \<Longrightarrow> x - (abs(x-z)+1) * d < z"
   560 apply(induct rule: int_gr_induct)
   561  apply simp
   562  apply arith
   563 apply (simp add:int_distrib)
   564 apply arith
   565 done
   566 
   567 lemma incr_lemma: "0 < (d::int) \<Longrightarrow> z < x + (abs(x-z)+1) * d"
   568 apply(induct rule: int_gr_induct)
   569  apply simp
   570  apply arith
   571 apply (simp add:int_distrib)
   572 apply arith
   573 done
   574 
   575 lemma  minusinfinity:
   576   assumes "0 < d" and
   577     P1eqP1: "ALL x k. P1 x = P1(x - k*d)" and
   578     ePeqP1: "EX z::int. ALL x. x < z \<longrightarrow> (P x = P1 x)"
   579   shows "(EX x. P1 x) \<longrightarrow> (EX x. P x)"
   580 proof
   581   assume eP1: "EX x. P1 x"
   582   then obtain x where P1: "P1 x" ..
   583   from ePeqP1 obtain z where P1eqP: "ALL x. x < z \<longrightarrow> (P x = P1 x)" ..
   584   let ?w = "x - (abs(x-z)+1) * d"
   585   show "EX x. P x"
   586   proof
   587     have w: "?w < z" by(rule decr_lemma)
   588     have "P1 x = P1 ?w" using P1eqP1 by blast
   589     also have "\<dots> = P(?w)" using w P1eqP by blast
   590     finally show "P ?w" using P1 by blast
   591   qed
   592 qed
   593 
   594 text {*
   595   \medskip This Theorem combines whithnesses about @{text "P
   596   minusinfinity"} to show one component of the equivalence proof for
   597   Cooper's Theorem. *}
   598 
   599 lemma plusinfinity:
   600   assumes "0 < d" and
   601     P1eqP1: "ALL (x::int) (k::int). P1 x = P1 (x + k * d)" and
   602     ePeqP1: "EX z::int. ALL x. z < x  --> (P x = P1 x)"
   603   shows "(EX x::int. P1 x) --> (EX x::int. P x)"
   604 proof
   605   assume eP1: "EX x. P1 x"
   606   then obtain x where P1: "P1 x" ..
   607   from ePeqP1 obtain z where P1eqP: "ALL x. z < x \<longrightarrow> (P x = P1 x)" ..
   608   let ?w = "x + (abs(x-z)+1) * d"
   609   show "EX x. P x"
   610   proof
   611     have w: "z < ?w" by(rule incr_lemma)
   612     have "P1 x = P1 ?w" using P1eqP1 by blast
   613     also have "\<dots> = P(?w)" using w P1eqP by blast
   614     finally show "P ?w" using P1 by blast
   615   qed
   616 qed
   617  
   618 text {*
   619   \medskip 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 text {*
   655   \medskip Theorem for periodic function on discrete sets. *}
   656 
   657 lemma pinf_vee:
   658   assumes dpos: "0 < (d::int)" and modd: "ALL (x::int) (k::int). P x = P (x+k*d)"
   659   shows "(EX x::int. P x) = (EX (j::int) : {1..d} . P j)"
   660   (is "?LHS = ?RHS")
   661 proof
   662   assume ?LHS
   663   then obtain x where P: "P x" ..
   664   have "x mod d = x + (-(x div d))*d"
   665     by(simp add:zmod_zdiv_equality mult_ac eq_diff_eq)
   666   hence Pmod: "P x = P(x mod d)" using modd by (simp only:)
   667   show ?RHS
   668   proof (cases)
   669     assume "x mod d = 0"
   670     hence "P 0" using P Pmod by simp
   671     moreover have "P 0 = P(0 + 1*d)" using modd by blast
   672     ultimately have "P d" by simp
   673     moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
   674     ultimately show ?RHS ..
   675   next
   676     assume not0: "x mod d \<noteq> 0"
   677     have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
   678     moreover have "x mod d : {1..d}"
   679     proof -
   680       have "0 \<le> x mod d" by(rule pos_mod_sign)
   681       moreover have "x mod d < d" by(rule pos_mod_bound)
   682       ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
   683     qed
   684     ultimately show ?RHS ..
   685   qed
   686 next
   687   assume ?RHS thus ?LHS by blast
   688 qed
   689 
   690 lemma decr_mult_lemma:
   691   assumes dpos: "(0::int) < d" and
   692           minus: "ALL x::int. P x \<longrightarrow> P(x - d)" and
   693           knneg: "0 <= k"
   694   shows "ALL x. P x \<longrightarrow> P(x - k*d)"
   695 using knneg
   696 proof (induct rule:int_ge_induct)
   697   case base thus ?case by simp
   698 next
   699   case (step i)
   700   show ?case
   701   proof
   702     fix x
   703     have "P x \<longrightarrow> P (x - i * d)" using step.hyps by blast
   704     also have "\<dots> \<longrightarrow> P(x - (i + 1) * d)"
   705       using minus[THEN spec, of "x - i * d"]
   706       by (simp add:int_distrib OrderedGroup.diff_diff_eq[symmetric])
   707     ultimately show "P x \<longrightarrow> P(x - (i + 1) * d)" by blast
   708   qed
   709 qed
   710 
   711 lemma incr_mult_lemma:
   712   assumes dpos: "(0::int) < d" and
   713           plus: "ALL x::int. P x \<longrightarrow> P(x + d)" and
   714           knneg: "0 <= k"
   715   shows "ALL x. P x \<longrightarrow> P(x + k*d)"
   716 using knneg
   717 proof (induct rule:int_ge_induct)
   718   case base thus ?case by simp
   719 next
   720   case (step i)
   721   show ?case
   722   proof
   723     fix x
   724     have "P x \<longrightarrow> P (x + i * d)" using step.hyps by blast
   725     also have "\<dots> \<longrightarrow> P(x + (i + 1) * d)"
   726       using plus[THEN spec, of "x + i * d"]
   727       by (simp add:int_distrib zadd_ac)
   728     ultimately show "P x \<longrightarrow> P(x + (i + 1) * d)" by blast
   729   qed
   730 qed
   731 
   732 lemma cpmi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. x < z --> (P x = P1 x))
   733 ==> ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D) 
   734 ==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x-k*D))))
   735 ==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (b::int) : B. P (b+j)))"
   736 apply(rule iffI)
   737 prefer 2
   738 apply(drule minusinfinity)
   739 apply assumption+
   740 apply(fastsimp)
   741 apply clarsimp
   742 apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x - k*D)")
   743 apply(frule_tac x = x and z=z in decr_lemma)
   744 apply(subgoal_tac "P1(x - (\<bar>x - z\<bar> + 1) * D)")
   745 prefer 2
   746 apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
   747 prefer 2 apply arith
   748  apply fastsimp
   749 apply(drule (1) minf_vee)
   750 apply blast
   751 apply(blast dest:decr_mult_lemma)
   752 done
   753 
   754 text {* Cooper Theorem, plus infinity version. *}
   755 lemma cppi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. z < x --> (P x = P1 x))
   756 ==> ALL x.~(EX (j::int) : {1..D}. EX (a::int) : A. P(a - j)) --> P (x) --> P (x + D) 
   757 ==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x+k*D))))
   758 ==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (a::int) : A. P (a - j)))"
   759   apply(rule iffI)
   760   prefer 2
   761   apply(drule plusinfinity)
   762   apply assumption+
   763   apply(fastsimp)
   764   apply clarsimp
   765   apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x + k*D)")
   766   apply(frule_tac x = x and z=z in incr_lemma)
   767   apply(subgoal_tac "P1(x + (\<bar>x - z\<bar> + 1) * D)")
   768   prefer 2
   769   apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
   770   prefer 2 apply arith
   771   apply fastsimp
   772   apply(drule (1) pinf_vee)
   773   apply blast
   774   apply(blast dest:incr_mult_lemma)
   775   done
   776 
   777 
   778 text {*
   779   \bigskip 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 text {* \bigskip 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 text {* \bigskip Theorems required for the @{text 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: zero_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 text {* \bigskip Theorems for transforming predicates on nat to predicates on @{text 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 mult_strict_left_mono_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) <= Numeral0" by simp
   973 
   974 theorem Suc_plus1: "Suc n = n + 1" by simp
   975 
   976 text {*
   977   \medskip Specific instances of congruence rules, to prevent
   978   simplifier from looping. *}
   979 
   980 theorem imp_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<longrightarrow> P) = (0 <= x \<longrightarrow> P')"
   981   by simp
   982 
   983 theorem conj_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<and> P) = (0 <= x \<and> P')"
   984   by (simp cong: conj_cong)
   985 
   986 use "cooper_dec.ML"
   987 oracle
   988   presburger_oracle = CooperDec.mk_presburger_oracle
   989 
   990 use "cooper_proof.ML"
   991 use "qelim.ML"
   992 use "presburger.ML"
   993 
   994 setup "Presburger.setup"
   995 
   996 end