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