src/HOL/Presburger.thy
author haftmann
Thu Oct 29 11:41:36 2009 +0100 (2009-10-29)
changeset 33318 ddd97d9dfbfb
parent 32553 bf781ef40c81
child 35050 9f841f20dca6
permissions -rw-r--r--
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
wenzelm@23465
     1
(* Title:      HOL/Presburger.thy
wenzelm@23465
     2
   Author:     Amine Chaieb, TU Muenchen
wenzelm@23465
     3
*)
wenzelm@23465
     4
huffman@23472
     5
header {* Decision Procedure for Presburger Arithmetic *}
huffman@23472
     6
wenzelm@23465
     7
theory Presburger
haftmann@28402
     8
imports Groebner_Basis SetInterval
wenzelm@23465
     9
uses
haftmann@30656
    10
  "Tools/Qelim/qelim.ML"
wenzelm@23465
    11
  "Tools/Qelim/cooper_data.ML"
wenzelm@23465
    12
  "Tools/Qelim/generated_cooper.ML"
wenzelm@23465
    13
  ("Tools/Qelim/cooper.ML")
wenzelm@23465
    14
  ("Tools/Qelim/presburger.ML")
wenzelm@23465
    15
begin
wenzelm@23465
    16
wenzelm@23465
    17
setup CooperData.setup
wenzelm@23465
    18
wenzelm@23465
    19
subsection{* The @{text "-\<infinity>"} and @{text "+\<infinity>"} Properties *}
wenzelm@23465
    20
chaieb@24404
    21
wenzelm@23465
    22
lemma minf:
wenzelm@23465
    23
  "\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x<z. P x = P' x; \<exists>z.\<forall>x<z. Q x = Q' x\<rbrakk> 
wenzelm@23465
    24
     \<Longrightarrow> \<exists>z.\<forall>x<z. (P x \<and> Q x) = (P' x \<and> Q' x)"
wenzelm@23465
    25
  "\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x<z. P x = P' x; \<exists>z.\<forall>x<z. Q x = Q' x\<rbrakk> 
wenzelm@23465
    26
     \<Longrightarrow> \<exists>z.\<forall>x<z. (P x \<or> Q x) = (P' x \<or> Q' x)"
wenzelm@23465
    27
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x = t) = False"
wenzelm@23465
    28
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<noteq> t) = True"
wenzelm@23465
    29
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x < t) = True"
wenzelm@23465
    30
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<le> t) = True"
wenzelm@23465
    31
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x > t) = False"
wenzelm@23465
    32
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<ge> t) = False"
haftmann@27651
    33
  "\<exists>z.\<forall>(x::'a::{linorder,plus,Ring_and_Field.dvd})<z. (d dvd x + s) = (d dvd x + s)"
haftmann@27651
    34
  "\<exists>z.\<forall>(x::'a::{linorder,plus,Ring_and_Field.dvd})<z. (\<not> d dvd x + s) = (\<not> d dvd x + s)"
wenzelm@23465
    35
  "\<exists>z.\<forall>x<z. F = F"
wenzelm@23465
    36
  by ((erule exE, erule exE,rule_tac x="min z za" in exI,simp)+, (rule_tac x="t" in exI,fastsimp)+) simp_all
wenzelm@23465
    37
wenzelm@23465
    38
lemma pinf:
wenzelm@23465
    39
  "\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x>z. P x = P' x; \<exists>z.\<forall>x>z. Q x = Q' x\<rbrakk> 
wenzelm@23465
    40
     \<Longrightarrow> \<exists>z.\<forall>x>z. (P x \<and> Q x) = (P' x \<and> Q' x)"
wenzelm@23465
    41
  "\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x>z. P x = P' x; \<exists>z.\<forall>x>z. Q x = Q' x\<rbrakk> 
wenzelm@23465
    42
     \<Longrightarrow> \<exists>z.\<forall>x>z. (P x \<or> Q x) = (P' x \<or> Q' x)"
wenzelm@23465
    43
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x = t) = False"
wenzelm@23465
    44
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<noteq> t) = True"
wenzelm@23465
    45
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x < t) = False"
wenzelm@23465
    46
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<le> t) = False"
wenzelm@23465
    47
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x > t) = True"
wenzelm@23465
    48
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<ge> t) = True"
haftmann@27651
    49
  "\<exists>z.\<forall>(x::'a::{linorder,plus,Ring_and_Field.dvd})>z. (d dvd x + s) = (d dvd x + s)"
haftmann@27651
    50
  "\<exists>z.\<forall>(x::'a::{linorder,plus,Ring_and_Field.dvd})>z. (\<not> d dvd x + s) = (\<not> d dvd x + s)"
wenzelm@23465
    51
  "\<exists>z.\<forall>x>z. F = F"
wenzelm@23465
    52
  by ((erule exE, erule exE,rule_tac x="max z za" in exI,simp)+,(rule_tac x="t" in exI,fastsimp)+) simp_all
wenzelm@23465
    53
wenzelm@23465
    54
lemma inf_period:
wenzelm@23465
    55
  "\<lbrakk>\<forall>x k. P x = P (x - k*D); \<forall>x k. Q x = Q (x - k*D)\<rbrakk> 
wenzelm@23465
    56
    \<Longrightarrow> \<forall>x k. (P x \<and> Q x) = (P (x - k*D) \<and> Q (x - k*D))"
wenzelm@23465
    57
  "\<lbrakk>\<forall>x k. P x = P (x - k*D); \<forall>x k. Q x = Q (x - k*D)\<rbrakk> 
wenzelm@23465
    58
    \<Longrightarrow> \<forall>x k. (P x \<or> Q x) = (P (x - k*D) \<or> Q (x - k*D))"
haftmann@27651
    59
  "(d::'a::{comm_ring,Ring_and_Field.dvd}) dvd D \<Longrightarrow> \<forall>x k. (d dvd x + t) = (d dvd (x - k*D) + t)"
haftmann@27651
    60
  "(d::'a::{comm_ring,Ring_and_Field.dvd}) dvd D \<Longrightarrow> \<forall>x k. (\<not>d dvd x + t) = (\<not>d dvd (x - k*D) + t)"
wenzelm@23465
    61
  "\<forall>x k. F = F"
nipkow@29667
    62
apply (auto elim!: dvdE simp add: algebra_simps)
haftmann@27651
    63
unfolding mult_assoc [symmetric] left_distrib [symmetric] left_diff_distrib [symmetric]
chaieb@27668
    64
unfolding dvd_def mult_commute [of d] 
chaieb@27668
    65
by auto
wenzelm@23465
    66
huffman@23472
    67
subsection{* The A and B sets *}
wenzelm@23465
    68
lemma bset:
wenzelm@23465
    69
  "\<lbrakk>\<forall>x.(\<forall>j \<in> {1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> P x \<longrightarrow> P(x - D) ;
wenzelm@23465
    70
     \<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> Q x \<longrightarrow> Q(x - D)\<rbrakk> \<Longrightarrow> 
wenzelm@23465
    71
  \<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j) \<longrightarrow> (P x \<and> Q x) \<longrightarrow> (P(x - D) \<and> Q (x - D))"
wenzelm@23465
    72
  "\<lbrakk>\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> P x \<longrightarrow> P(x - D) ;
wenzelm@23465
    73
     \<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> Q x \<longrightarrow> Q(x - D)\<rbrakk> \<Longrightarrow> 
wenzelm@23465
    74
  \<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (P x \<or> Q x) \<longrightarrow> (P(x - D) \<or> Q (x - D))"
wenzelm@23465
    75
  "\<lbrakk>D>0; t - 1\<in> B\<rbrakk> \<Longrightarrow> (\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x = t) \<longrightarrow> (x - D = t))"
wenzelm@23465
    76
  "\<lbrakk>D>0 ; t \<in> B\<rbrakk> \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x \<noteq> t) \<longrightarrow> (x - D \<noteq> t))"
wenzelm@23465
    77
  "D>0 \<Longrightarrow> (\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x < t) \<longrightarrow> (x - D < t))"
wenzelm@23465
    78
  "D>0 \<Longrightarrow> (\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x \<le> t) \<longrightarrow> (x - D \<le> t))"
wenzelm@23465
    79
  "\<lbrakk>D>0 ; t \<in> B\<rbrakk> \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x > t) \<longrightarrow> (x - D > t))"
wenzelm@23465
    80
  "\<lbrakk>D>0 ; t - 1 \<in> B\<rbrakk> \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x \<ge> t) \<longrightarrow> (x - D \<ge> t))"
wenzelm@23465
    81
  "d dvd D \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (d dvd x+t) \<longrightarrow> (d dvd (x - D) + t))"
wenzelm@23465
    82
  "d dvd D \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (\<not>d dvd x+t) \<longrightarrow> (\<not> d dvd (x - D) + t))"
wenzelm@23465
    83
  "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j) \<longrightarrow> F \<longrightarrow> F"
wenzelm@23465
    84
proof (blast, blast)
wenzelm@23465
    85
  assume dp: "D > 0" and tB: "t - 1\<in> B"
wenzelm@23465
    86
  show "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x = t) \<longrightarrow> (x - D = t))" 
chaieb@27668
    87
    apply (rule allI, rule impI,erule ballE[where x="1"],erule ballE[where x="t - 1"]) 
chaieb@27668
    88
    apply algebra using dp tB by simp_all
wenzelm@23465
    89
next
wenzelm@23465
    90
  assume dp: "D > 0" and tB: "t \<in> B"
wenzelm@23465
    91
  show "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x \<noteq> t) \<longrightarrow> (x - D \<noteq> t))" 
wenzelm@23465
    92
    apply (rule allI, rule impI,erule ballE[where x="D"],erule ballE[where x="t"])
chaieb@27668
    93
    apply algebra
wenzelm@23465
    94
    using dp tB by simp_all
wenzelm@23465
    95
next
wenzelm@23465
    96
  assume dp: "D > 0" thus "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x < t) \<longrightarrow> (x - D < t))" by arith
wenzelm@23465
    97
next
wenzelm@23465
    98
  assume dp: "D > 0" thus "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x \<le> t) \<longrightarrow> (x - D \<le> t)" by arith
wenzelm@23465
    99
next
wenzelm@23465
   100
  assume dp: "D > 0" and tB:"t \<in> B"
wenzelm@23465
   101
  {fix x assume nob: "\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j" and g: "x > t" and ng: "\<not> (x - D) > t"
wenzelm@23465
   102
    hence "x -t \<le> D" and "1 \<le> x - t" by simp+
wenzelm@23465
   103
      hence "\<exists>j \<in> {1 .. D}. x - t = j" by auto
nipkow@29667
   104
      hence "\<exists>j \<in> {1 .. D}. x = t + j" by (simp add: algebra_simps)
wenzelm@23465
   105
      with nob tB have "False" by simp}
wenzelm@23465
   106
  thus "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x > t) \<longrightarrow> (x - D > t)" by blast
wenzelm@23465
   107
next
wenzelm@23465
   108
  assume dp: "D > 0" and tB:"t - 1\<in> B"
wenzelm@23465
   109
  {fix x assume nob: "\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j" and g: "x \<ge> t" and ng: "\<not> (x - D) \<ge> t"
wenzelm@23465
   110
    hence "x - (t - 1) \<le> D" and "1 \<le> x - (t - 1)" by simp+
wenzelm@23465
   111
      hence "\<exists>j \<in> {1 .. D}. x - (t - 1) = j" by auto
nipkow@29667
   112
      hence "\<exists>j \<in> {1 .. D}. x = (t - 1) + j" by (simp add: algebra_simps)
wenzelm@23465
   113
      with nob tB have "False" by simp}
wenzelm@23465
   114
  thus "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x \<ge> t) \<longrightarrow> (x - D \<ge> t)" by blast
wenzelm@23465
   115
next
wenzelm@23465
   116
  assume d: "d dvd D"
chaieb@27668
   117
  {fix x assume H: "d dvd x + t" with d have "d dvd (x - D) + t" by algebra}
wenzelm@23465
   118
  thus "\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (d dvd x+t) \<longrightarrow> (d dvd (x - D) + t)" by simp
wenzelm@23465
   119
next
wenzelm@23465
   120
  assume d: "d dvd D"
haftmann@27651
   121
  {fix x assume H: "\<not>(d dvd x + t)" with d have "\<not> d dvd (x - D) + t"
nipkow@29667
   122
      by (clarsimp simp add: dvd_def,erule_tac x= "ka + k" in allE,simp add: algebra_simps)}
wenzelm@23465
   123
  thus "\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (\<not>d dvd x+t) \<longrightarrow> (\<not>d dvd (x - D) + t)" by auto
wenzelm@23465
   124
qed blast
wenzelm@23465
   125
wenzelm@23465
   126
lemma aset:
wenzelm@23465
   127
  "\<lbrakk>\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> P x \<longrightarrow> P(x + D) ;
wenzelm@23465
   128
     \<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> Q x \<longrightarrow> Q(x + D)\<rbrakk> \<Longrightarrow> 
wenzelm@23465
   129
  \<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j) \<longrightarrow> (P x \<and> Q x) \<longrightarrow> (P(x + D) \<and> Q (x + D))"
wenzelm@23465
   130
  "\<lbrakk>\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> P x \<longrightarrow> P(x + D) ;
wenzelm@23465
   131
     \<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> Q x \<longrightarrow> Q(x + D)\<rbrakk> \<Longrightarrow> 
wenzelm@23465
   132
  \<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (P x \<or> Q x) \<longrightarrow> (P(x + D) \<or> Q (x + D))"
wenzelm@23465
   133
  "\<lbrakk>D>0; t + 1\<in> A\<rbrakk> \<Longrightarrow> (\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x = t) \<longrightarrow> (x + D = t))"
wenzelm@23465
   134
  "\<lbrakk>D>0 ; t \<in> A\<rbrakk> \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x \<noteq> t) \<longrightarrow> (x + D \<noteq> t))"
wenzelm@23465
   135
  "\<lbrakk>D>0; t\<in> A\<rbrakk> \<Longrightarrow>(\<forall>(x::int). (\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x < t) \<longrightarrow> (x + D < t))"
wenzelm@23465
   136
  "\<lbrakk>D>0; t + 1 \<in> A\<rbrakk> \<Longrightarrow> (\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x \<le> t) \<longrightarrow> (x + D \<le> t))"
wenzelm@23465
   137
  "D>0 \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x > t) \<longrightarrow> (x + D > t))"
wenzelm@23465
   138
  "D>0 \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x \<ge> t) \<longrightarrow> (x + D \<ge> t))"
wenzelm@23465
   139
  "d dvd D \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (d dvd x+t) \<longrightarrow> (d dvd (x + D) + t))"
wenzelm@23465
   140
  "d dvd D \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (\<not>d dvd x+t) \<longrightarrow> (\<not> d dvd (x + D) + t))"
wenzelm@23465
   141
  "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j) \<longrightarrow> F \<longrightarrow> F"
wenzelm@23465
   142
proof (blast, blast)
wenzelm@23465
   143
  assume dp: "D > 0" and tA: "t + 1 \<in> A"
wenzelm@23465
   144
  show "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x = t) \<longrightarrow> (x + D = t))" 
wenzelm@23465
   145
    apply (rule allI, rule impI,erule ballE[where x="1"],erule ballE[where x="t + 1"])
wenzelm@23465
   146
    using dp tA by simp_all
wenzelm@23465
   147
next
wenzelm@23465
   148
  assume dp: "D > 0" and tA: "t \<in> A"
wenzelm@23465
   149
  show "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x \<noteq> t) \<longrightarrow> (x + D \<noteq> t))" 
wenzelm@23465
   150
    apply (rule allI, rule impI,erule ballE[where x="D"],erule ballE[where x="t"])
wenzelm@23465
   151
    using dp tA by simp_all
wenzelm@23465
   152
next
wenzelm@23465
   153
  assume dp: "D > 0" thus "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x > t) \<longrightarrow> (x + D > t))" by arith
wenzelm@23465
   154
next
wenzelm@23465
   155
  assume dp: "D > 0" thus "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x \<ge> t) \<longrightarrow> (x + D \<ge> t)" by arith
wenzelm@23465
   156
next
wenzelm@23465
   157
  assume dp: "D > 0" and tA:"t \<in> A"
wenzelm@23465
   158
  {fix x assume nob: "\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j" and g: "x < t" and ng: "\<not> (x + D) < t"
wenzelm@23465
   159
    hence "t - x \<le> D" and "1 \<le> t - x" by simp+
wenzelm@23465
   160
      hence "\<exists>j \<in> {1 .. D}. t - x = j" by auto
nipkow@29667
   161
      hence "\<exists>j \<in> {1 .. D}. x = t - j" by (auto simp add: algebra_simps) 
wenzelm@23465
   162
      with nob tA have "False" by simp}
wenzelm@23465
   163
  thus "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x < t) \<longrightarrow> (x + D < t)" by blast
wenzelm@23465
   164
next
wenzelm@23465
   165
  assume dp: "D > 0" and tA:"t + 1\<in> A"
wenzelm@23465
   166
  {fix x assume nob: "\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j" and g: "x \<le> t" and ng: "\<not> (x + D) \<le> t"
nipkow@29667
   167
    hence "(t + 1) - x \<le> D" and "1 \<le> (t + 1) - x" by (simp_all add: algebra_simps)
wenzelm@23465
   168
      hence "\<exists>j \<in> {1 .. D}. (t + 1) - x = j" by auto
nipkow@29667
   169
      hence "\<exists>j \<in> {1 .. D}. x = (t + 1) - j" by (auto simp add: algebra_simps)
wenzelm@23465
   170
      with nob tA have "False" by simp}
wenzelm@23465
   171
  thus "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x \<le> t) \<longrightarrow> (x + D \<le> t)" by blast
wenzelm@23465
   172
next
wenzelm@23465
   173
  assume d: "d dvd D"
wenzelm@23465
   174
  {fix x assume H: "d dvd x + t" with d have "d dvd (x + D) + t"
nipkow@29667
   175
      by (clarsimp simp add: dvd_def,rule_tac x= "ka + k" in exI,simp add: algebra_simps)}
wenzelm@23465
   176
  thus "\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (d dvd x+t) \<longrightarrow> (d dvd (x + D) + t)" by simp
wenzelm@23465
   177
next
wenzelm@23465
   178
  assume d: "d dvd D"
wenzelm@23465
   179
  {fix x assume H: "\<not>(d dvd x + t)" with d have "\<not>d dvd (x + D) + t"
nipkow@29667
   180
      by (clarsimp simp add: dvd_def,erule_tac x= "ka - k" in allE,simp add: algebra_simps)}
wenzelm@23465
   181
  thus "\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (\<not>d dvd x+t) \<longrightarrow> (\<not>d dvd (x + D) + t)" by auto
wenzelm@23465
   182
qed blast
wenzelm@23465
   183
wenzelm@23465
   184
subsection{* Cooper's Theorem @{text "-\<infinity>"} and @{text "+\<infinity>"} Version *}
wenzelm@23465
   185
wenzelm@23465
   186
subsubsection{* First some trivial facts about periodic sets or predicates *}
wenzelm@23465
   187
lemma periodic_finite_ex:
wenzelm@23465
   188
  assumes dpos: "(0::int) < d" and modd: "ALL x k. P x = P(x - k*d)"
wenzelm@23465
   189
  shows "(EX x. P x) = (EX j : {1..d}. P j)"
wenzelm@23465
   190
  (is "?LHS = ?RHS")
wenzelm@23465
   191
proof
wenzelm@23465
   192
  assume ?LHS
wenzelm@23465
   193
  then obtain x where P: "P x" ..
wenzelm@23465
   194
  have "x mod d = x - (x div d)*d" by(simp add:zmod_zdiv_equality mult_ac eq_diff_eq)
wenzelm@23465
   195
  hence Pmod: "P x = P(x mod d)" using modd by simp
wenzelm@23465
   196
  show ?RHS
wenzelm@23465
   197
  proof (cases)
wenzelm@23465
   198
    assume "x mod d = 0"
wenzelm@23465
   199
    hence "P 0" using P Pmod by simp
wenzelm@23465
   200
    moreover have "P 0 = P(0 - (-1)*d)" using modd by blast
wenzelm@23465
   201
    ultimately have "P d" by simp
wenzelm@23465
   202
    moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
wenzelm@23465
   203
    ultimately show ?RHS ..
wenzelm@23465
   204
  next
wenzelm@23465
   205
    assume not0: "x mod d \<noteq> 0"
wenzelm@23465
   206
    have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
wenzelm@23465
   207
    moreover have "x mod d : {1..d}"
wenzelm@23465
   208
    proof -
wenzelm@23465
   209
      from dpos have "0 \<le> x mod d" by(rule pos_mod_sign)
wenzelm@23465
   210
      moreover from dpos have "x mod d < d" by(rule pos_mod_bound)
wenzelm@23465
   211
      ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
wenzelm@23465
   212
    qed
wenzelm@23465
   213
    ultimately show ?RHS ..
wenzelm@23465
   214
  qed
wenzelm@23465
   215
qed auto
wenzelm@23465
   216
wenzelm@23465
   217
subsubsection{* The @{text "-\<infinity>"} Version*}
wenzelm@23465
   218
wenzelm@23465
   219
lemma decr_lemma: "0 < (d::int) \<Longrightarrow> x - (abs(x-z)+1) * d < z"
wenzelm@23465
   220
by(induct rule: int_gr_induct,simp_all add:int_distrib)
wenzelm@23465
   221
wenzelm@23465
   222
lemma incr_lemma: "0 < (d::int) \<Longrightarrow> z < x + (abs(x-z)+1) * d"
wenzelm@23465
   223
by(induct rule: int_gr_induct, simp_all add:int_distrib)
wenzelm@23465
   224
wenzelm@23465
   225
theorem int_induct[case_names base step1 step2]:
wenzelm@23465
   226
  assumes 
wenzelm@23465
   227
  base: "P(k::int)" and step1: "\<And>i. \<lbrakk>k \<le> i; P i\<rbrakk> \<Longrightarrow> P(i+1)" and
wenzelm@23465
   228
  step2: "\<And>i. \<lbrakk>k \<ge> i; P i\<rbrakk> \<Longrightarrow> P(i - 1)"
wenzelm@23465
   229
  shows "P i"
wenzelm@23465
   230
proof -
wenzelm@23465
   231
  have "i \<le> k \<or> i\<ge> k" by arith
wenzelm@23465
   232
  thus ?thesis using prems int_ge_induct[where P="P" and k="k" and i="i"] int_le_induct[where P="P" and k="k" and i="i"] by blast
wenzelm@23465
   233
qed
wenzelm@23465
   234
wenzelm@23465
   235
lemma decr_mult_lemma:
wenzelm@23465
   236
  assumes dpos: "(0::int) < d" and minus: "\<forall>x. P x \<longrightarrow> P(x - d)" and knneg: "0 <= k"
wenzelm@23465
   237
  shows "ALL x. P x \<longrightarrow> P(x - k*d)"
wenzelm@23465
   238
using knneg
wenzelm@23465
   239
proof (induct rule:int_ge_induct)
wenzelm@23465
   240
  case base thus ?case by simp
wenzelm@23465
   241
next
wenzelm@23465
   242
  case (step i)
wenzelm@23465
   243
  {fix x
wenzelm@23465
   244
    have "P x \<longrightarrow> P (x - i * d)" using step.hyps by blast
wenzelm@23465
   245
    also have "\<dots> \<longrightarrow> P(x - (i + 1) * d)" using minus[THEN spec, of "x - i * d"]
wenzelm@23465
   246
      by (simp add:int_distrib OrderedGroup.diff_diff_eq[symmetric])
wenzelm@23465
   247
    ultimately have "P x \<longrightarrow> P(x - (i + 1) * d)" by blast}
wenzelm@23465
   248
  thus ?case ..
wenzelm@23465
   249
qed
wenzelm@23465
   250
wenzelm@23465
   251
lemma  minusinfinity:
wenzelm@23465
   252
  assumes dpos: "0 < d" and
wenzelm@23465
   253
    P1eqP1: "ALL x k. P1 x = P1(x - k*d)" and ePeqP1: "EX z::int. ALL x. x < z \<longrightarrow> (P x = P1 x)"
wenzelm@23465
   254
  shows "(EX x. P1 x) \<longrightarrow> (EX x. P x)"
wenzelm@23465
   255
proof
wenzelm@23465
   256
  assume eP1: "EX x. P1 x"
wenzelm@23465
   257
  then obtain x where P1: "P1 x" ..
wenzelm@23465
   258
  from ePeqP1 obtain z where P1eqP: "ALL x. x < z \<longrightarrow> (P x = P1 x)" ..
wenzelm@23465
   259
  let ?w = "x - (abs(x-z)+1) * d"
wenzelm@23465
   260
  from dpos have w: "?w < z" by(rule decr_lemma)
wenzelm@23465
   261
  have "P1 x = P1 ?w" using P1eqP1 by blast
wenzelm@23465
   262
  also have "\<dots> = P(?w)" using w P1eqP by blast
wenzelm@23465
   263
  finally have "P ?w" using P1 by blast
wenzelm@23465
   264
  thus "EX x. P x" ..
wenzelm@23465
   265
qed
wenzelm@23465
   266
wenzelm@23465
   267
lemma cpmi: 
wenzelm@23465
   268
  assumes dp: "0 < D" and p1:"\<exists>z. \<forall> x< z. P x = P' x"
wenzelm@23465
   269
  and nb:"\<forall>x.(\<forall> j\<in> {1..D}. \<forall>(b::int) \<in> B. x \<noteq> b+j) --> P (x) --> P (x - D)"
wenzelm@23465
   270
  and pd: "\<forall> x k. P' x = P' (x-k*D)"
wenzelm@23465
   271
  shows "(\<exists>x. P x) = ((\<exists> j\<in> {1..D} . P' j) | (\<exists> j \<in> {1..D}.\<exists> b\<in> B. P (b+j)))" 
wenzelm@23465
   272
         (is "?L = (?R1 \<or> ?R2)")
wenzelm@23465
   273
proof-
wenzelm@23465
   274
 {assume "?R2" hence "?L"  by blast}
wenzelm@23465
   275
 moreover
wenzelm@23465
   276
 {assume H:"?R1" hence "?L" using minusinfinity[OF dp pd p1] periodic_finite_ex[OF dp pd] by simp}
wenzelm@23465
   277
 moreover 
wenzelm@23465
   278
 { fix x
wenzelm@23465
   279
   assume P: "P x" and H: "\<not> ?R2"
wenzelm@23465
   280
   {fix y assume "\<not> (\<exists>j\<in>{1..D}. \<exists>b\<in>B. P (b + j))" and P: "P y"
wenzelm@23465
   281
     hence "~(EX (j::int) : {1..D}. EX (b::int) : B. y = b+j)" by auto
wenzelm@23465
   282
     with nb P  have "P (y - D)" by auto }
wenzelm@23465
   283
   hence "ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D)" by blast
wenzelm@23465
   284
   with H P have th: " \<forall>x. P x \<longrightarrow> P (x - D)" by auto
wenzelm@23465
   285
   from p1 obtain z where z: "ALL x. x < z --> (P x = P' x)" by blast
wenzelm@23465
   286
   let ?y = "x - (\<bar>x - z\<bar> + 1)*D"
wenzelm@23465
   287
   have zp: "0 <= (\<bar>x - z\<bar> + 1)" by arith
wenzelm@23465
   288
   from dp have yz: "?y < z" using decr_lemma[OF dp] by simp   
wenzelm@23465
   289
   from z[rule_format, OF yz] decr_mult_lemma[OF dp th zp, rule_format, OF P] have th2: " P' ?y" by auto
wenzelm@23465
   290
   with periodic_finite_ex[OF dp pd]
wenzelm@23465
   291
   have "?R1" by blast}
wenzelm@23465
   292
 ultimately show ?thesis by blast
wenzelm@23465
   293
qed
wenzelm@23465
   294
wenzelm@23465
   295
subsubsection {* The @{text "+\<infinity>"} Version*}
wenzelm@23465
   296
wenzelm@23465
   297
lemma  plusinfinity:
wenzelm@23465
   298
  assumes dpos: "(0::int) < d" and
wenzelm@23465
   299
    P1eqP1: "\<forall>x k. P' x = P'(x - k*d)" and ePeqP1: "\<exists> z. \<forall> x>z. P x = P' x"
wenzelm@23465
   300
  shows "(\<exists> x. P' x) \<longrightarrow> (\<exists> x. P x)"
wenzelm@23465
   301
proof
wenzelm@23465
   302
  assume eP1: "EX x. P' x"
wenzelm@23465
   303
  then obtain x where P1: "P' x" ..
wenzelm@23465
   304
  from ePeqP1 obtain z where P1eqP: "\<forall>x>z. P x = P' x" ..
wenzelm@23465
   305
  let ?w' = "x + (abs(x-z)+1) * d"
wenzelm@23465
   306
  let ?w = "x - (-(abs(x-z) + 1))*d"
nipkow@29667
   307
  have ww'[simp]: "?w = ?w'" by (simp add: algebra_simps)
wenzelm@23465
   308
  from dpos have w: "?w > z" by(simp only: ww' incr_lemma)
wenzelm@23465
   309
  hence "P' x = P' ?w" using P1eqP1 by blast
wenzelm@23465
   310
  also have "\<dots> = P(?w)" using w P1eqP by blast
wenzelm@23465
   311
  finally have "P ?w" using P1 by blast
wenzelm@23465
   312
  thus "EX x. P x" ..
wenzelm@23465
   313
qed
wenzelm@23465
   314
wenzelm@23465
   315
lemma incr_mult_lemma:
wenzelm@23465
   316
  assumes dpos: "(0::int) < d" and plus: "ALL x::int. P x \<longrightarrow> P(x + d)" and knneg: "0 <= k"
wenzelm@23465
   317
  shows "ALL x. P x \<longrightarrow> P(x + k*d)"
wenzelm@23465
   318
using knneg
wenzelm@23465
   319
proof (induct rule:int_ge_induct)
wenzelm@23465
   320
  case base thus ?case by simp
wenzelm@23465
   321
next
wenzelm@23465
   322
  case (step i)
wenzelm@23465
   323
  {fix x
wenzelm@23465
   324
    have "P x \<longrightarrow> P (x + i * d)" using step.hyps by blast
wenzelm@23465
   325
    also have "\<dots> \<longrightarrow> P(x + (i + 1) * d)" using plus[THEN spec, of "x + i * d"]
wenzelm@23465
   326
      by (simp add:int_distrib zadd_ac)
wenzelm@23465
   327
    ultimately have "P x \<longrightarrow> P(x + (i + 1) * d)" by blast}
wenzelm@23465
   328
  thus ?case ..
wenzelm@23465
   329
qed
wenzelm@23465
   330
wenzelm@23465
   331
lemma cppi: 
wenzelm@23465
   332
  assumes dp: "0 < D" and p1:"\<exists>z. \<forall> x> z. P x = P' x"
wenzelm@23465
   333
  and nb:"\<forall>x.(\<forall> j\<in> {1..D}. \<forall>(b::int) \<in> A. x \<noteq> b - j) --> P (x) --> P (x + D)"
wenzelm@23465
   334
  and pd: "\<forall> x k. P' x= P' (x-k*D)"
wenzelm@23465
   335
  shows "(\<exists>x. P x) = ((\<exists> j\<in> {1..D} . P' j) | (\<exists> j \<in> {1..D}.\<exists> b\<in> A. P (b - j)))" (is "?L = (?R1 \<or> ?R2)")
wenzelm@23465
   336
proof-
wenzelm@23465
   337
 {assume "?R2" hence "?L"  by blast}
wenzelm@23465
   338
 moreover
wenzelm@23465
   339
 {assume H:"?R1" hence "?L" using plusinfinity[OF dp pd p1] periodic_finite_ex[OF dp pd] by simp}
wenzelm@23465
   340
 moreover 
wenzelm@23465
   341
 { fix x
wenzelm@23465
   342
   assume P: "P x" and H: "\<not> ?R2"
wenzelm@23465
   343
   {fix y assume "\<not> (\<exists>j\<in>{1..D}. \<exists>b\<in>A. P (b - j))" and P: "P y"
wenzelm@23465
   344
     hence "~(EX (j::int) : {1..D}. EX (b::int) : A. y = b - j)" by auto
wenzelm@23465
   345
     with nb P  have "P (y + D)" by auto }
wenzelm@23465
   346
   hence "ALL x.~(EX (j::int) : {1..D}. EX (b::int) : A. P(b-j)) --> P (x) --> P (x + D)" by blast
wenzelm@23465
   347
   with H P have th: " \<forall>x. P x \<longrightarrow> P (x + D)" by auto
wenzelm@23465
   348
   from p1 obtain z where z: "ALL x. x > z --> (P x = P' x)" by blast
wenzelm@23465
   349
   let ?y = "x + (\<bar>x - z\<bar> + 1)*D"
wenzelm@23465
   350
   have zp: "0 <= (\<bar>x - z\<bar> + 1)" by arith
wenzelm@23465
   351
   from dp have yz: "?y > z" using incr_lemma[OF dp] by simp
wenzelm@23465
   352
   from z[rule_format, OF yz] incr_mult_lemma[OF dp th zp, rule_format, OF P] have th2: " P' ?y" by auto
wenzelm@23465
   353
   with periodic_finite_ex[OF dp pd]
wenzelm@23465
   354
   have "?R1" by blast}
wenzelm@23465
   355
 ultimately show ?thesis by blast
wenzelm@23465
   356
qed
wenzelm@23465
   357
wenzelm@23465
   358
lemma simp_from_to: "{i..j::int} = (if j < i then {} else insert i {i+1..j})"
wenzelm@23465
   359
apply(simp add:atLeastAtMost_def atLeast_def atMost_def)
wenzelm@23465
   360
apply(fastsimp)
wenzelm@23465
   361
done
wenzelm@23465
   362
haftmann@27651
   363
theorem unity_coeff_ex: "(\<exists>(x::'a::{semiring_0,Ring_and_Field.dvd}). P (l * x)) \<equiv> (\<exists>x. l dvd (x + 0) \<and> P x)"
haftmann@27651
   364
  apply (rule eq_reflection [symmetric])
wenzelm@23465
   365
  apply (rule iffI)
wenzelm@23465
   366
  defer
wenzelm@23465
   367
  apply (erule exE)
wenzelm@23465
   368
  apply (rule_tac x = "l * x" in exI)
wenzelm@23465
   369
  apply (simp add: dvd_def)
haftmann@27651
   370
  apply (rule_tac x = x in exI, simp)
wenzelm@23465
   371
  apply (erule exE)
wenzelm@23465
   372
  apply (erule conjE)
haftmann@27651
   373
  apply simp
wenzelm@23465
   374
  apply (erule dvdE)
wenzelm@23465
   375
  apply (rule_tac x = k in exI)
wenzelm@23465
   376
  apply simp
wenzelm@23465
   377
  done
wenzelm@23465
   378
wenzelm@23465
   379
lemma zdvd_mono: assumes not0: "(k::int) \<noteq> 0"
wenzelm@23465
   380
shows "((m::int) dvd t) \<equiv> (k*m dvd k*t)" 
wenzelm@23465
   381
  using not0 by (simp add: dvd_def)
wenzelm@23465
   382
wenzelm@23465
   383
lemma uminus_dvd_conv: "(d dvd (t::int)) \<equiv> (-d dvd t)" "(d dvd (t::int)) \<equiv> (d dvd -t)"
wenzelm@23465
   384
  by simp_all
haftmann@32553
   385
wenzelm@23465
   386
text {* \bigskip Theorems for transforming predicates on nat to predicates on @{text int}*}
haftmann@32553
   387
wenzelm@23465
   388
lemma zdiff_int_split: "P (int (x - y)) =
wenzelm@23465
   389
  ((y \<le> x \<longrightarrow> P (int x - int y)) \<and> (x < y \<longrightarrow> P 0))"
wenzelm@23465
   390
  by (case_tac "y \<le> x", simp_all add: zdiff_int)
wenzelm@23465
   391
huffman@26086
   392
lemma number_of1: "(0::int) <= number_of n \<Longrightarrow> (0::int) <= number_of (Int.Bit0 n) \<and> (0::int) <= number_of (Int.Bit1 n)"
huffman@26086
   393
by simp
wenzelm@23465
   394
lemma number_of2: "(0::int) <= Numeral0" by simp
wenzelm@23465
   395
wenzelm@23465
   396
text {*
wenzelm@23465
   397
  \medskip Specific instances of congruence rules, to prevent
wenzelm@23465
   398
  simplifier from looping. *}
wenzelm@23465
   399
wenzelm@23465
   400
theorem imp_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<longrightarrow> P) = (0 <= x \<longrightarrow> P')" by simp
wenzelm@23465
   401
wenzelm@23465
   402
theorem conj_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<and> P) = (0 <= x \<and> P')" 
wenzelm@23465
   403
  by (simp cong: conj_cong)
wenzelm@23465
   404
lemma int_eq_number_of_eq:
wenzelm@23465
   405
  "(((number_of v)::int) = (number_of w)) = iszero ((number_of (v + (uminus w)))::int)"
huffman@28967
   406
  by (rule eq_number_of_eq)
wenzelm@23465
   407
nipkow@30031
   408
declare dvd_eq_mod_eq_0[symmetric, presburger]
haftmann@27651
   409
declare mod_1[presburger] 
wenzelm@23465
   410
declare mod_0[presburger]
nipkow@30031
   411
declare mod_by_1[presburger]
wenzelm@23465
   412
declare zmod_zero[presburger]
wenzelm@23465
   413
declare zmod_self[presburger]
wenzelm@23465
   414
declare mod_self[presburger]
haftmann@27651
   415
declare mod_by_0[presburger]
nipkow@30027
   416
declare mod_div_trivial[presburger]
wenzelm@23465
   417
declare div_mod_equality2[presburger]
wenzelm@23465
   418
declare div_mod_equality[presburger]
wenzelm@23465
   419
declare mod_div_equality2[presburger]
wenzelm@23465
   420
declare mod_div_equality[presburger]
wenzelm@23465
   421
declare mod_mult_self1[presburger]
wenzelm@23465
   422
declare mod_mult_self2[presburger]
wenzelm@23465
   423
declare zdiv_zmod_equality2[presburger]
wenzelm@23465
   424
declare zdiv_zmod_equality[presburger]
wenzelm@23465
   425
declare mod2_Suc_Suc[presburger]
wenzelm@23465
   426
lemma [presburger]: "(a::int) div 0 = 0" and [presburger]: "a mod 0 = a"
haftmann@27651
   427
by simp_all
wenzelm@23465
   428
wenzelm@23465
   429
use "Tools/Qelim/cooper.ML"
wenzelm@28290
   430
oracle linzqe_oracle = Coopereif.cooper_oracle
wenzelm@23465
   431
wenzelm@23465
   432
use "Tools/Qelim/presburger.ML"
wenzelm@23465
   433
haftmann@30686
   434
setup {* Arith_Data.add_tactic "Presburger arithmetic" (K (Presburger.cooper_tac true [] [])) *}
wenzelm@23465
   435
wenzelm@23465
   436
method_setup presburger = {*
wenzelm@23465
   437
let
wenzelm@23465
   438
 fun keyword k = Scan.lift (Args.$$$ k -- Args.colon) >> K ()
wenzelm@23465
   439
 fun simple_keyword k = Scan.lift (Args.$$$ k) >> K ()
wenzelm@23465
   440
 val addN = "add"
wenzelm@23465
   441
 val delN = "del"
wenzelm@23465
   442
 val elimN = "elim"
wenzelm@23465
   443
 val any_keyword = keyword addN || keyword delN || simple_keyword elimN
wenzelm@23465
   444
 val thms = Scan.repeat (Scan.unless any_keyword Attrib.multi_thm) >> flat;
wenzelm@23465
   445
in
wenzelm@30549
   446
  Scan.optional (simple_keyword elimN >> K false) true --
wenzelm@30549
   447
  Scan.optional (keyword addN |-- thms) [] --
wenzelm@30549
   448
  Scan.optional (keyword delN |-- thms) [] >>
wenzelm@30549
   449
  (fn ((elim, add_ths), del_ths) => fn ctxt =>
wenzelm@30549
   450
    SIMPLE_METHOD' (Presburger.cooper_tac elim add_ths del_ths ctxt))
wenzelm@23465
   451
end
wenzelm@23465
   452
*} "Cooper's algorithm for Presburger arithmetic"
wenzelm@23465
   453
chaieb@27668
   454
lemma [presburger, algebra]: "m mod 2 = (1::nat) \<longleftrightarrow> \<not> 2 dvd m " by presburger
chaieb@27668
   455
lemma [presburger, algebra]: "m mod 2 = Suc 0 \<longleftrightarrow> \<not> 2 dvd m " by presburger
chaieb@27668
   456
lemma [presburger, algebra]: "m mod (Suc (Suc 0)) = (1::nat) \<longleftrightarrow> \<not> 2 dvd m " by presburger
chaieb@27668
   457
lemma [presburger, algebra]: "m mod (Suc (Suc 0)) = Suc 0 \<longleftrightarrow> \<not> 2 dvd m " by presburger
chaieb@27668
   458
lemma [presburger, algebra]: "m mod 2 = (1::int) \<longleftrightarrow> \<not> 2 dvd m " by presburger
wenzelm@23465
   459
wenzelm@23465
   460
haftmann@23685
   461
lemma zdvd_period:
haftmann@23685
   462
  fixes a d :: int
haftmann@23685
   463
  assumes advdd: "a dvd d"
haftmann@23685
   464
  shows "a dvd (x + t) \<longleftrightarrow> a dvd ((x + c * d) + t)"
chaieb@27668
   465
  using advdd
chaieb@27668
   466
  apply -
chaieb@27668
   467
  apply (rule iffI)
chaieb@27668
   468
  by algebra+
haftmann@23685
   469
wenzelm@23465
   470
end