src/HOL/Presburger.thy
author blanchet
Fri, 31 Jan 2014 13:29:20 +0100
changeset 55206 f7358e55018f
parent 54227 63b441f49645
child 56850 13a7bca533a3
permissions -rw-r--r--
tuning
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
47317
432b29a96f61 modernized obsolete old-style theory name with proper new-style underscore
huffman
parents: 47165
diff changeset
     8
imports Groebner_Basis Set_Interval
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
     9
begin
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    10
48891
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 47432
diff changeset
    11
ML_file "Tools/Qelim/qelim.ML"
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 47432
diff changeset
    12
ML_file "Tools/Qelim/cooper_procedure.ML"
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 47432
diff changeset
    13
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    14
subsection{* The @{text "-\<infinity>"} and @{text "+\<infinity>"} Properties *}
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
lemma minf:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    17
  "\<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
    18
     \<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
    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 \<or> Q x) = (P' x \<or> Q' x)"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    21
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x = t) = False"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    22
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<noteq> t) = True"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    23
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x < t) = True"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    24
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<le> t) = True"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    25
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x > t) = False"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    26
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<ge> t) = False"
45425
7fee7d7abf2f avoid inconsistent sort constraints;
wenzelm
parents: 44890
diff changeset
    27
  "\<exists>z.\<forall>(x::'b::{linorder,plus,Rings.dvd})<z. (d dvd x + s) = (d dvd x + s)"
7fee7d7abf2f avoid inconsistent sort constraints;
wenzelm
parents: 44890
diff changeset
    28
  "\<exists>z.\<forall>(x::'b::{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
    29
  "\<exists>z.\<forall>x<z. F = F"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44766
diff changeset
    30
  by ((erule exE, erule exE,rule_tac x="min z za" in exI,simp)+, (rule_tac x="t" in exI,fastforce)+) simp_all
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    31
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    32
lemma pinf:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    33
  "\<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
    34
     \<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
    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 \<or> Q x) = (P' x \<or> Q' x)"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    37
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x = t) = False"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    38
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<noteq> t) = True"
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 \<le> t) = False"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    41
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x > t) = True"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    42
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<ge> t) = True"
45425
7fee7d7abf2f avoid inconsistent sort constraints;
wenzelm
parents: 44890
diff changeset
    43
  "\<exists>z.\<forall>(x::'b::{linorder,plus,Rings.dvd})>z. (d dvd x + s) = (d dvd x + s)"
7fee7d7abf2f avoid inconsistent sort constraints;
wenzelm
parents: 44890
diff changeset
    44
  "\<exists>z.\<forall>(x::'b::{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
    45
  "\<exists>z.\<forall>x>z. F = F"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44766
diff changeset
    46
  by ((erule exE, erule exE,rule_tac x="max z za" in exI,simp)+,(rule_tac x="t" in exI,fastforce)+) simp_all
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    47
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    48
lemma inf_period:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    49
  "\<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
    50
    \<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
    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 \<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
    53
  "(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
    54
  "(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
    55
  "\<forall>x k. F = F"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 28967
diff changeset
    56
apply (auto elim!: dvdE simp add: algebra_simps)
49962
a8cc904a6820 Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents: 48891
diff changeset
    57
unfolding mult_assoc [symmetric] distrib_right [symmetric] left_diff_distrib [symmetric]
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
    58
unfolding dvd_def mult_commute [of d] 
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
    59
by auto
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    60
23472
02099ea56555 section headings
huffman
parents: 23465
diff changeset
    61
subsection{* The A and B sets *}
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    62
lemma bset:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    63
  "\<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
    64
     \<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
    65
  \<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
    66
  "\<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
    67
     \<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
    68
  \<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
    69
  "\<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
    70
  "\<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
    71
  "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
    72
  "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
    73
  "\<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
    74
  "\<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
    75
  "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
    76
  "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
    77
  "\<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
    78
proof (blast, blast)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    79
  assume dp: "D > 0" and tB: "t - 1\<in> B"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    80
  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
    81
    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
    82
    apply algebra using dp tB by simp_all
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    83
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    84
  assume dp: "D > 0" and tB: "t \<in> B"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    85
  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
    86
    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
    87
    apply algebra
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    88
    using dp tB by simp_all
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    89
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    90
  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
    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 \<le> t) \<longrightarrow> (x - D \<le> 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" and tB:"t \<in> B"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    95
  {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
    96
    hence "x -t \<le> D" and "1 \<le> x - t" by simp+
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    97
      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
    98
      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
    99
      with nob tB have "False" by simp}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   100
  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
   101
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   102
  assume dp: "D > 0" and tB:"t - 1\<in> B"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   103
  {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
   104
    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
   105
      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
   106
      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
   107
      with nob tB have "False" by simp}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   108
  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
   109
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   110
  assume d: "d dvd D"
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   111
  {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
   112
  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
   113
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   114
  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
   115
  {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
   116
      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
   117
  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
   118
qed blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   119
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   120
lemma aset:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   121
  "\<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
   122
     \<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
   123
  \<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
   124
  "\<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
   125
     \<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
   126
  \<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
   127
  "\<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
   128
  "\<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
   129
  "\<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
   130
  "\<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
   131
  "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
   132
  "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
   133
  "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
   134
  "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
   135
  "\<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
   136
proof (blast, blast)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   137
  assume dp: "D > 0" and tA: "t + 1 \<in> A"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   138
  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
   139
    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
   140
    using dp tA by simp_all
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   141
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   142
  assume dp: "D > 0" and tA: "t \<in> A"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   143
  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
   144
    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
   145
    using dp tA by simp_all
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   146
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   147
  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
   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 \<ge> t) \<longrightarrow> (x + D \<ge> 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" and tA:"t \<in> A"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   152
  {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
   153
    hence "t - x \<le> D" and "1 \<le> t - x" by simp+
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   154
      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
   155
      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
   156
      with nob tA have "False" by simp}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   157
  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
   158
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   159
  assume dp: "D > 0" and tA:"t + 1\<in> A"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   160
  {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
   161
    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
   162
      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
   163
      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
   164
      with nob tA have "False" by simp}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   165
  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
   166
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   167
  assume d: "d dvd D"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   168
  {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
   169
      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
   170
  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
   171
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   172
  assume d: "d dvd D"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   173
  {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
   174
      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
   175
  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
   176
qed blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   177
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   178
subsection{* Cooper's Theorem @{text "-\<infinity>"} and @{text "+\<infinity>"} Version *}
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
subsubsection{* First some trivial facts about periodic sets or predicates *}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   181
lemma periodic_finite_ex:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   182
  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
   183
  shows "(EX x. P x) = (EX j : {1..d}. P j)"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   184
  (is "?LHS = ?RHS")
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   185
proof
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   186
  assume ?LHS
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   187
  then obtain x where P: "P x" ..
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   188
  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
   189
  hence Pmod: "P x = P(x mod d)" using modd by simp
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   190
  show ?RHS
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   191
  proof (cases)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   192
    assume "x mod d = 0"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   193
    hence "P 0" using P Pmod by simp
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   194
    moreover have "P 0 = P(0 - (-1)*d)" using modd by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   195
    ultimately have "P d" by simp
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35050
diff changeset
   196
    moreover have "d : {1..d}" using dpos by simp
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   197
    ultimately show ?RHS ..
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   198
  next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   199
    assume not0: "x mod d \<noteq> 0"
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35050
diff changeset
   200
    have "P(x mod d)" using dpos P Pmod by simp
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   201
    moreover have "x mod d : {1..d}"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   202
    proof -
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   203
      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
   204
      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
   205
      ultimately show ?thesis using not0 by simp
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   206
    qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   207
    ultimately show ?RHS ..
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
qed auto
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   210
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   211
subsubsection{* The @{text "-\<infinity>"} Version*}
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
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
   214
by(induct rule: int_gr_induct,simp_all add:int_distrib)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   215
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   216
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
   217
by(induct rule: int_gr_induct, simp_all add:int_distrib)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   218
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   219
lemma decr_mult_lemma:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   220
  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
   221
  shows "ALL x. P x \<longrightarrow> P(x - k*d)"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   222
using knneg
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   223
proof (induct rule:int_ge_induct)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   224
  case base thus ?case by simp
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   225
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   226
  case (step i)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   227
  {fix x
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   228
    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
   229
    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
   230
      by (simp add: algebra_simps)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   231
    ultimately have "P x \<longrightarrow> P(x - (i + 1) * d)" by blast}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   232
  thus ?case ..
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   233
qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   234
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   235
lemma  minusinfinity:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   236
  assumes dpos: "0 < d" and
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   237
    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
   238
  shows "(EX x. P1 x) \<longrightarrow> (EX x. P x)"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   239
proof
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   240
  assume eP1: "EX x. P1 x"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   241
  then obtain x where P1: "P1 x" ..
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   242
  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
   243
  let ?w = "x - (abs(x-z)+1) * d"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   244
  from dpos have w: "?w < z" by(rule decr_lemma)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   245
  have "P1 x = P1 ?w" using P1eqP1 by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   246
  also have "\<dots> = P(?w)" using w P1eqP by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   247
  finally have "P ?w" using P1 by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   248
  thus "EX x. P x" ..
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   249
qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   250
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   251
lemma cpmi: 
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   252
  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
   253
  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
   254
  and pd: "\<forall> x k. P' x = P' (x-k*D)"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   255
  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
   256
         (is "?L = (?R1 \<or> ?R2)")
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   257
proof-
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   258
 {assume "?R2" hence "?L"  by blast}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   259
 moreover
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   260
 {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
   261
 moreover 
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   262
 { fix x
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   263
   assume P: "P x" and H: "\<not> ?R2"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   264
   {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
   265
     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
   266
     with nb P  have "P (y - D)" by auto }
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   267
   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
   268
   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
   269
   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
   270
   let ?y = "x - (\<bar>x - z\<bar> + 1)*D"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   271
   have zp: "0 <= (\<bar>x - z\<bar> + 1)" by arith
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   272
   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
   273
   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
   274
   with periodic_finite_ex[OF dp pd]
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   275
   have "?R1" by blast}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   276
 ultimately show ?thesis by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   277
qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   278
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   279
subsubsection {* The @{text "+\<infinity>"} Version*}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   280
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   281
lemma  plusinfinity:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   282
  assumes dpos: "(0::int) < d" and
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   283
    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
   284
  shows "(\<exists> x. P' x) \<longrightarrow> (\<exists> x. P x)"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   285
proof
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   286
  assume eP1: "EX x. P' x"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   287
  then obtain x where P1: "P' x" ..
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   288
  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
   289
  let ?w' = "x + (abs(x-z)+1) * d"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   290
  let ?w = "x - (-(abs(x-z) + 1))*d"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 28967
diff changeset
   291
  have ww'[simp]: "?w = ?w'" by (simp add: algebra_simps)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   292
  from dpos have w: "?w > z" by(simp only: ww' incr_lemma)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   293
  hence "P' x = P' ?w" using P1eqP1 by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   294
  also have "\<dots> = P(?w)" using w P1eqP by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   295
  finally have "P ?w" using P1 by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   296
  thus "EX x. P x" ..
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   297
qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   298
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   299
lemma incr_mult_lemma:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   300
  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
   301
  shows "ALL x. P x \<longrightarrow> P(x + k*d)"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   302
using knneg
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   303
proof (induct rule:int_ge_induct)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   304
  case base thus ?case by simp
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   305
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   306
  case (step i)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   307
  {fix x
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   308
    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
   309
    also have "\<dots> \<longrightarrow> P(x + (i + 1) * d)" using plus[THEN spec, of "x + i * d"]
44766
d4d33a4d7548 avoid using legacy theorem names
huffman
parents: 36804
diff changeset
   310
      by (simp add:int_distrib add_ac)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   311
    ultimately have "P x \<longrightarrow> P(x + (i + 1) * d)" by blast}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   312
  thus ?case ..
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   313
qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   314
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   315
lemma cppi: 
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   316
  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
   317
  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
   318
  and pd: "\<forall> x k. P' x= P' (x-k*D)"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   319
  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
   320
proof-
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   321
 {assume "?R2" hence "?L"  by blast}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   322
 moreover
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   323
 {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
   324
 moreover 
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   325
 { fix x
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   326
   assume P: "P x" and H: "\<not> ?R2"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   327
   {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
   328
     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
   329
     with nb P  have "P (y + D)" by auto }
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   330
   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
   331
   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
   332
   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
   333
   let ?y = "x + (\<bar>x - z\<bar> + 1)*D"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   334
   have zp: "0 <= (\<bar>x - z\<bar> + 1)" by arith
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   335
   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
   336
   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
   337
   with periodic_finite_ex[OF dp pd]
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   338
   have "?R1" by blast}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   339
 ultimately show ?thesis by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   340
qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   341
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   342
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
   343
apply(simp add:atLeastAtMost_def atLeast_def atMost_def)
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44766
diff changeset
   344
apply(fastforce)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   345
done
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   346
35050
9f841f20dca6 renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents: 33318
diff changeset
   347
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
   348
  apply (rule eq_reflection [symmetric])
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   349
  apply (rule iffI)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   350
  defer
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   351
  apply (erule exE)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   352
  apply (rule_tac x = "l * x" in exI)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   353
  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
   354
  apply (rule_tac x = x in exI, simp)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   355
  apply (erule exE)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   356
  apply (erule conjE)
27651
16a26996c30e moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents: 27540
diff changeset
   357
  apply simp
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   358
  apply (erule dvdE)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   359
  apply (rule_tac x = k in exI)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   360
  apply simp
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   361
  done
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   362
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   363
lemma zdvd_mono:
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   364
  fixes k m t :: int
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   365
  assumes "k \<noteq> 0"
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   366
  shows "m dvd t \<equiv> k * m dvd k * t" 
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   367
  using assms by simp
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   368
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   369
lemma uminus_dvd_conv:
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   370
  fixes d t :: int
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   371
  shows "d dvd t \<equiv> - d dvd t" and "d dvd t \<equiv> d dvd - t"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   372
  by simp_all
32553
bf781ef40c81 cleanedup theorems all_nat ex_nat
haftmann
parents: 31790
diff changeset
   373
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   374
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
   375
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   376
lemma zdiff_int_split: "P (int (x - y)) =
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   377
  ((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
   378
  by (cases "y \<le> x") (simp_all add: zdiff_int)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   379
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   380
text {*
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   381
  \medskip Specific instances of congruence rules, to prevent
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   382
  simplifier from looping. *}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   383
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45425
diff changeset
   384
theorem imp_le_cong:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45425
diff changeset
   385
  "\<lbrakk>x = x'; 0 \<le> x' \<Longrightarrow> P = P'\<rbrakk> \<Longrightarrow> (0 \<le> (x::int) \<longrightarrow> P) = (0 \<le> x' \<longrightarrow> P')"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45425
diff changeset
   386
  by simp
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   387
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45425
diff changeset
   388
theorem conj_le_cong:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45425
diff changeset
   389
  "\<lbrakk>x = x'; 0 \<le> x' \<Longrightarrow> P = P'\<rbrakk> \<Longrightarrow> (0 \<le> (x::int) \<and> P) = (0 \<le> x' \<and> P')"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   390
  by (simp cong: conj_cong)
36799
628fe06cbeff one structure is better than three
haftmann
parents: 36798
diff changeset
   391
48891
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 47432
diff changeset
   392
ML_file "Tools/Qelim/cooper.ML"
36799
628fe06cbeff one structure is better than three
haftmann
parents: 36798
diff changeset
   393
setup Cooper.setup
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   394
47432
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   395
method_setup presburger = {*
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   396
  let
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   397
    fun keyword k = Scan.lift (Args.$$$ k -- Args.colon) >> K ()
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   398
    fun simple_keyword k = Scan.lift (Args.$$$ k) >> K ()
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   399
    val addN = "add"
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   400
    val delN = "del"
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   401
    val elimN = "elim"
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   402
    val any_keyword = keyword addN || keyword delN || simple_keyword elimN
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   403
    val thms = Scan.repeat (Scan.unless any_keyword Attrib.multi_thm) >> flat;
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   404
  in
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   405
    Scan.optional (simple_keyword elimN >> K false) true --
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   406
    Scan.optional (keyword addN |-- thms) [] --
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   407
    Scan.optional (keyword delN |-- thms) [] >>
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   408
    (fn ((elim, add_ths), del_ths) => fn ctxt =>
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   409
      SIMPLE_METHOD' (Cooper.tac elim add_ths del_ths ctxt))
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   410
  end
e1576d13e933 more standard method setup;
wenzelm
parents: 47317
diff changeset
   411
*} "Cooper's algorithm for Presburger arithmetic"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   412
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   413
declare dvd_eq_mod_eq_0 [symmetric, presburger]
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   414
declare mod_1 [presburger] 
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   415
declare mod_0 [presburger]
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   416
declare mod_by_1 [presburger]
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   417
declare mod_self [presburger]
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   418
declare div_by_0 [presburger]
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   419
declare mod_by_0 [presburger]
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   420
declare mod_div_trivial [presburger]
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   421
declare div_mod_equality2 [presburger]
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   422
declare div_mod_equality [presburger]
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   423
declare mod_div_equality2 [presburger]
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   424
declare mod_div_equality [presburger]
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   425
declare mod_mult_self1 [presburger]
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   426
declare mod_mult_self2 [presburger]
36798
3981db162131 less complex organization of cooper source code
haftmann
parents: 36749
diff changeset
   427
declare mod2_Suc_Suc[presburger]
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   428
declare not_mod_2_eq_0_eq_1 [presburger] 
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   429
declare nat_zero_less_power_iff [presburger]
36798
3981db162131 less complex organization of cooper source code
haftmann
parents: 36749
diff changeset
   430
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   431
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
   432
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
   433
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
   434
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
   435
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
   436
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   437
end
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   438