src/HOL/Presburger.thy
author haftmann
Sat, 08 Sep 2018 08:09:07 +0000
changeset 68940 25b431feb2e9
parent 68157 057d5b4ce47e
child 69593 3dda49e08b9d
permissions -rw-r--r--
more appropriate conversion of HOL character literals to character codes: symbolic newline is interpreted as 0x10
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
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58925
diff changeset
     5
section \<open>Decision Procedure for Presburger Arithmetic\<close>
23472
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
63962
83a625d06e91 use argo as additional SAT solver with models but no proofs, since the proof trace formats are not easily translatable
boehmes
parents: 63961
diff changeset
     8
imports Groebner_Basis Set_Interval
58925
1b655309617c more accurate keywords;
wenzelm
parents: 58889
diff changeset
     9
keywords "try0" :: diag
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    10
begin
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    11
48891
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 47432
diff changeset
    12
ML_file "Tools/Qelim/qelim.ML"
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 47432
diff changeset
    13
ML_file "Tools/Qelim/cooper_procedure.ML"
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 47432
diff changeset
    14
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61476
diff changeset
    15
subsection\<open>The \<open>-\<infinity>\<close> and \<open>+\<infinity>\<close> Properties\<close>
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    16
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    17
lemma minf:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    18
  "\<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
    19
     \<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
    20
  "\<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
    21
     \<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
    22
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x = t) = False"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    23
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<noteq> t) = True"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    24
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x < t) = True"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    25
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<le> t) = True"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    26
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x > t) = False"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    27
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<ge> t) = False"
45425
7fee7d7abf2f avoid inconsistent sort constraints;
wenzelm
parents: 44890
diff changeset
    28
  "\<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
    29
  "\<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
    30
  "\<exists>z.\<forall>x<z. F = F"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44766
diff changeset
    31
  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
    32
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    33
lemma pinf:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    34
  "\<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
    35
     \<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
    36
  "\<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
    37
     \<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
    38
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x = t) = False"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    39
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<noteq> t) = True"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    40
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x < t) = False"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    41
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<le> t) = False"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    42
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x > t) = True"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    43
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<ge> t) = True"
45425
7fee7d7abf2f avoid inconsistent sort constraints;
wenzelm
parents: 44890
diff changeset
    44
  "\<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
    45
  "\<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
    46
  "\<exists>z.\<forall>x>z. F = F"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44766
diff changeset
    47
  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
    48
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    49
lemma inf_period:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    50
  "\<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
    51
    \<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
    52
  "\<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
    53
    \<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
    54
  "(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
    55
  "(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
    56
  "\<forall>x k. F = F"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 28967
diff changeset
    57
apply (auto elim!: dvdE simp add: algebra_simps)
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 56850
diff changeset
    58
unfolding mult.assoc [symmetric] distrib_right [symmetric] left_diff_distrib [symmetric]
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 56850
diff changeset
    59
unfolding dvd_def mult.commute [of d] 
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
    60
by auto
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    61
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58925
diff changeset
    62
subsection\<open>The A and B sets\<close>
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    63
lemma bset:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    64
  "\<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
    65
     \<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
    66
  \<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
    67
  "\<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
    68
     \<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
    69
  \<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
    70
  "\<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
    71
  "\<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
    72
  "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
    73
  "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
    74
  "\<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
    75
  "\<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
    76
  "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
    77
  "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
    78
  "\<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
    79
proof (blast, blast)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    80
  assume dp: "D > 0" and tB: "t - 1\<in> B"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    81
  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
    82
    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
    83
    apply algebra using dp tB by simp_all
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    84
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    85
  assume dp: "D > 0" and tB: "t \<in> B"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    86
  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
    87
    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
    88
    apply algebra
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    89
    using dp tB by simp_all
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    90
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    91
  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
    92
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    93
  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
    94
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    95
  assume dp: "D > 0" and tB:"t \<in> B"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    96
  {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
    97
    hence "x -t \<le> D" and "1 \<le> x - t" by simp+
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
    98
      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
    99
      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
   100
      with nob tB have "False" by simp}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   101
  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
   102
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   103
  assume dp: "D > 0" and tB:"t - 1\<in> B"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   104
  {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
   105
    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
   106
      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
   107
      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
   108
      with nob tB have "False" by simp}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   109
  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
   110
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   111
  assume d: "d dvd D"
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   112
  {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
   113
  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
   114
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   115
  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
   116
  {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
   117
      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
   118
  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
   119
qed blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   120
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   121
lemma aset:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   122
  "\<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
   123
     \<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
   124
  \<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
   125
  "\<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
   126
     \<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
   127
  \<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
   128
  "\<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
   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 \<noteq> t) \<longrightarrow> (x + D \<noteq> 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 < t) \<longrightarrow> (x + D < t))"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   131
  "\<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
   132
  "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
   133
  "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
   134
  "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
   135
  "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
   136
  "\<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
   137
proof (blast, blast)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   138
  assume dp: "D > 0" and tA: "t + 1 \<in> A"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   139
  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
   140
    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
   141
    using dp tA by simp_all
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   142
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   143
  assume dp: "D > 0" and tA: "t \<in> A"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   144
  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
   145
    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
   146
    using dp tA by simp_all
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   147
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   148
  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
   149
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   150
  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
   151
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   152
  assume dp: "D > 0" and tA:"t \<in> A"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   153
  {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
   154
    hence "t - x \<le> D" and "1 \<le> t - x" by simp+
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   155
      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
   156
      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
   157
      with nob tA have "False" by simp}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   158
  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
   159
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   160
  assume dp: "D > 0" and tA:"t + 1\<in> A"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   161
  {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
   162
    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
   163
      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
   164
      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
   165
      with nob tA have "False" by simp}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   166
  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
   167
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   168
  assume d: "d dvd D"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   169
  {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
   170
      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
   171
  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
   172
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   173
  assume d: "d dvd D"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   174
  {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
   175
      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
   176
  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
   177
qed blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   178
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61476
diff changeset
   179
subsection\<open>Cooper's Theorem \<open>-\<infinity>\<close> and \<open>+\<infinity>\<close> Version\<close>
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   180
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58925
diff changeset
   181
subsubsection\<open>First some trivial facts about periodic sets or predicates\<close>
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   182
lemma periodic_finite_ex:
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   183
  assumes dpos: "(0::int) < d" and modd: "\<forall>x k. P x = P(x - k*d)"
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   184
  shows "(\<exists>x. P x) = (\<exists>j \<in> {1..d}. P j)"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   185
  (is "?LHS = ?RHS")
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   186
proof
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   187
  assume ?LHS
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   188
  then obtain x where P: "P x" ..
64246
15d1ee6e847b eliminated irregular aliasses
haftmann
parents: 64244
diff changeset
   189
  have "x mod d = x - (x div d)*d" by(simp add:mult_div_mod_eq [symmetric] ac_simps eq_diff_eq)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   190
  hence Pmod: "P x = P(x mod d)" using modd by simp
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   191
  show ?RHS
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   192
  proof (cases)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   193
    assume "x mod d = 0"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   194
    hence "P 0" using P Pmod by simp
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   195
    moreover have "P 0 = P(0 - (-1)*d)" using modd by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   196
    ultimately have "P d" by simp
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67091
diff changeset
   197
    moreover have "d \<in> {1..d}" using dpos by simp
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   198
    ultimately show ?RHS ..
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   199
  next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   200
    assume not0: "x mod d \<noteq> 0"
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35050
diff changeset
   201
    have "P(x mod d)" using dpos P Pmod by simp
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67091
diff changeset
   202
    moreover have "x mod d \<in> {1..d}"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   203
    proof -
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   204
      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
   205
      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
   206
      ultimately show ?thesis using not0 by simp
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   207
    qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   208
    ultimately show ?RHS ..
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   209
  qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   210
qed auto
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   211
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61476
diff changeset
   212
subsubsection\<open>The \<open>-\<infinity>\<close> Version\<close>
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   213
61944
5d06ecfdb472 prefer symbols for "abs";
wenzelm
parents: 61799
diff changeset
   214
lemma decr_lemma: "0 < (d::int) \<Longrightarrow> x - (\<bar>x - z\<bar> + 1) * d < z"
5d06ecfdb472 prefer symbols for "abs";
wenzelm
parents: 61799
diff changeset
   215
  by (induct rule: int_gr_induct) (simp_all add: int_distrib)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   216
61944
5d06ecfdb472 prefer symbols for "abs";
wenzelm
parents: 61799
diff changeset
   217
lemma incr_lemma: "0 < (d::int) \<Longrightarrow> z < x + (\<bar>x - z\<bar> + 1) * d"
5d06ecfdb472 prefer symbols for "abs";
wenzelm
parents: 61799
diff changeset
   218
  by (induct rule: int_gr_induct) (simp_all add: int_distrib)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   219
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   220
lemma decr_mult_lemma:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   221
  assumes dpos: "(0::int) < d" and minus: "\<forall>x. P x \<longrightarrow> P(x - d)" and knneg: "0 <= k"
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   222
  shows "\<forall>x. P x \<longrightarrow> P(x - k*d)"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   223
using knneg
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   224
proof (induct rule:int_ge_induct)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   225
  case base thus ?case by simp
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   226
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   227
  case (step i)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   228
  {fix x
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   229
    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
   230
    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
   231
      by (simp add: algebra_simps)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   232
    ultimately have "P x \<longrightarrow> P(x - (i + 1) * d)" by blast}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   233
  thus ?case ..
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   234
qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   235
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   236
lemma  minusinfinity:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   237
  assumes dpos: "0 < d" and
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   238
    P1eqP1: "\<forall>x k. P1 x = P1(x - k*d)" and ePeqP1: "\<exists>z::int. \<forall>x. x < z \<longrightarrow> (P x = P1 x)"
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   239
  shows "(\<exists>x. P1 x) \<longrightarrow> (\<exists>x. P x)"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   240
proof
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   241
  assume eP1: "\<exists>x. P1 x"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   242
  then obtain x where P1: "P1 x" ..
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   243
  from ePeqP1 obtain z where P1eqP: "\<forall>x. x < z \<longrightarrow> (P x = P1 x)" ..
61944
5d06ecfdb472 prefer symbols for "abs";
wenzelm
parents: 61799
diff changeset
   244
  let ?w = "x - (\<bar>x - z\<bar> + 1) * d"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   245
  from dpos have w: "?w < z" by(rule decr_lemma)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   246
  have "P1 x = P1 ?w" using P1eqP1 by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   247
  also have "\<dots> = P(?w)" using w P1eqP by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   248
  finally have "P ?w" using P1 by blast
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   249
  thus "\<exists>x. P x" ..
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   250
qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   251
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   252
lemma cpmi: 
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   253
  assumes dp: "0 < D" and p1:"\<exists>z. \<forall> x< z. P x = P' x"
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   254
  and nb:"\<forall>x.(\<forall> j\<in> {1..D}. \<forall>(b::int) \<in> B. x \<noteq> b+j) \<longrightarrow> P (x) \<longrightarrow> P (x - D)"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   255
  and pd: "\<forall> x k. P' x = P' (x-k*D)"
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   256
  shows "(\<exists>x. P x) = ((\<exists>j \<in> {1..D} . P' j) \<or> (\<exists>j \<in> {1..D}. \<exists> b \<in> B. P (b+j)))"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   257
         (is "?L = (?R1 \<or> ?R2)")
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   258
proof-
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   259
 {assume "?R2" hence "?L"  by blast}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   260
 moreover
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   261
 {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
   262
 moreover 
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   263
 { fix x
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   264
   assume P: "P x" and H: "\<not> ?R2"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   265
   {fix y assume "\<not> (\<exists>j\<in>{1..D}. \<exists>b\<in>B. P (b + j))" and P: "P y"
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   266
     hence "\<not>(\<exists>(j::int) \<in> {1..D}. \<exists>(b::int) \<in> B. y = b+j)" by auto
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   267
     with nb P  have "P (y - D)" by auto }
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   268
   hence "\<forall>x. \<not>(\<exists>(j::int) \<in> {1..D}. \<exists>(b::int) \<in> B. P(b+j)) \<longrightarrow> P (x) \<longrightarrow> P (x - D)" by blast
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   269
   with H P have th: " \<forall>x. P x \<longrightarrow> P (x - D)" by auto
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   270
   from p1 obtain z where z: "\<forall>x. x < z \<longrightarrow> (P x = P' x)" by blast
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   271
   let ?y = "x - (\<bar>x - z\<bar> + 1)*D"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   272
   have zp: "0 <= (\<bar>x - z\<bar> + 1)" by arith
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   273
   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
   274
   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
   275
   with periodic_finite_ex[OF dp pd]
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   276
   have "?R1" by blast}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   277
 ultimately show ?thesis by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   278
qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   279
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61476
diff changeset
   280
subsubsection \<open>The \<open>+\<infinity>\<close> Version\<close>
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   281
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   282
lemma  plusinfinity:
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   283
  assumes dpos: "(0::int) < d" and
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   284
    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
   285
  shows "(\<exists> x. P' x) \<longrightarrow> (\<exists> x. P x)"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   286
proof
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   287
  assume eP1: "\<exists>x. P' x"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   288
  then obtain x where P1: "P' x" ..
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   289
  from ePeqP1 obtain z where P1eqP: "\<forall>x>z. P x = P' x" ..
61944
5d06ecfdb472 prefer symbols for "abs";
wenzelm
parents: 61799
diff changeset
   290
  let ?w' = "x + (\<bar>x - z\<bar> + 1) * d"
5d06ecfdb472 prefer symbols for "abs";
wenzelm
parents: 61799
diff changeset
   291
  let ?w = "x - (- (\<bar>x - z\<bar> + 1)) * d"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 28967
diff changeset
   292
  have ww'[simp]: "?w = ?w'" by (simp add: algebra_simps)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   293
  from dpos have w: "?w > z" by(simp only: ww' incr_lemma)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   294
  hence "P' x = P' ?w" using P1eqP1 by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   295
  also have "\<dots> = P(?w)" using w P1eqP by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   296
  finally have "P ?w" using P1 by blast
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   297
  thus "\<exists>x. P x" ..
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   298
qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   299
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   300
lemma incr_mult_lemma:
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   301
  assumes dpos: "(0::int) < d" and plus: "\<forall>x::int. P x \<longrightarrow> P(x + d)" and knneg: "0 <= k"
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   302
  shows "\<forall>x. P x \<longrightarrow> P(x + k*d)"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   303
using knneg
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   304
proof (induct rule:int_ge_induct)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   305
  case base thus ?case by simp
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   306
next
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   307
  case (step i)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   308
  {fix x
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   309
    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
   310
    also have "\<dots> \<longrightarrow> P(x + (i + 1) * d)" using plus[THEN spec, of "x + i * d"]
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   311
      by (simp add:int_distrib ac_simps)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   312
    ultimately have "P x \<longrightarrow> P(x + (i + 1) * d)" by blast}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   313
  thus ?case ..
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   314
qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   315
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   316
lemma cppi: 
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   317
  assumes dp: "0 < D" and p1:"\<exists>z. \<forall> x> z. P x = P' x"
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   318
  and nb:"\<forall>x.(\<forall> j\<in> {1..D}. \<forall>(b::int) \<in> A. x \<noteq> b - j) \<longrightarrow> P (x) \<longrightarrow> P (x + D)"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   319
  and pd: "\<forall> x k. P' x= P' (x-k*D)"
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   320
  shows "(\<exists>x. P x) = ((\<exists>j \<in> {1..D} . P' j) \<or> (\<exists> j \<in> {1..D}. \<exists> b\<in> A. P (b - j)))" (is "?L = (?R1 \<or> ?R2)")
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   321
proof-
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   322
 {assume "?R2" hence "?L"  by blast}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   323
 moreover
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   324
 {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
   325
 moreover 
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   326
 { fix x
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   327
   assume P: "P x" and H: "\<not> ?R2"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   328
   {fix y assume "\<not> (\<exists>j\<in>{1..D}. \<exists>b\<in>A. P (b - j))" and P: "P y"
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   329
     hence "\<not>(\<exists>(j::int) \<in> {1..D}. \<exists>(b::int) \<in> A. y = b - j)" by auto
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   330
     with nb P  have "P (y + D)" by auto }
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   331
   hence "\<forall>x. \<not>(\<exists>(j::int) \<in> {1..D}. \<exists>(b::int) \<in> A. P(b-j)) \<longrightarrow> P (x) \<longrightarrow> P (x + D)" by blast
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   332
   with H P have th: " \<forall>x. P x \<longrightarrow> P (x + D)" by auto
67091
1393c2340eec more symbols;
wenzelm
parents: 66630
diff changeset
   333
   from p1 obtain z where z: "\<forall>x. x > z \<longrightarrow> (P x = P' x)" by blast
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   334
   let ?y = "x + (\<bar>x - z\<bar> + 1)*D"
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   335
   have zp: "0 <= (\<bar>x - z\<bar> + 1)" by arith
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   336
   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
   337
   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
   338
   with periodic_finite_ex[OF dp pd]
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   339
   have "?R1" by blast}
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   340
 ultimately show ?thesis by blast
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   341
qed
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   342
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   343
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
   344
apply(simp add:atLeastAtMost_def atLeast_def atMost_def)
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44766
diff changeset
   345
apply(fastforce)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   346
done
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   347
35050
9f841f20dca6 renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents: 33318
diff changeset
   348
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
   349
  apply (rule eq_reflection [symmetric])
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   350
  apply (rule iffI)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   351
  defer
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   352
  apply (erule exE)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   353
  apply (rule_tac x = "l * x" in exI)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   354
  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
   355
  apply (rule_tac x = x in exI, simp)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   356
  apply (erule exE)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   357
  apply (erule conjE)
27651
16a26996c30e moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents: 27540
diff changeset
   358
  apply simp
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   359
  apply (erule dvdE)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   360
  apply (rule_tac x = k in exI)
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   361
  apply simp
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   362
  done
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   363
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   364
lemma zdvd_mono:
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   365
  fixes k m t :: int
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   366
  assumes "k \<noteq> 0"
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   367
  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
   368
  using assms by simp
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   369
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   370
lemma uminus_dvd_conv:
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   371
  fixes d t :: int
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   372
  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
   373
  by simp_all
32553
bf781ef40c81 cleanedup theorems all_nat ex_nat
haftmann
parents: 31790
diff changeset
   374
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61476
diff changeset
   375
text \<open>\bigskip Theorems for transforming predicates on nat to predicates on \<open>int\<close>\<close>
32553
bf781ef40c81 cleanedup theorems all_nat ex_nat
haftmann
parents: 31790
diff changeset
   376
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   377
lemma zdiff_int_split: "P (int (x - y)) =
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   378
  ((y \<le> x \<longrightarrow> P (int x - int y)) \<and> (x < y \<longrightarrow> P 0))"
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61944
diff changeset
   379
  by (cases "y \<le> x") (simp_all add: of_nat_diff)
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   380
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58925
diff changeset
   381
text \<open>
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   382
  \medskip Specific instances of congruence rules, to prevent
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58925
diff changeset
   383
  simplifier from looping.\<close>
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   384
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45425
diff changeset
   385
theorem imp_le_cong:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45425
diff changeset
   386
  "\<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
   387
  by simp
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   388
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45425
diff changeset
   389
theorem conj_le_cong:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45425
diff changeset
   390
  "\<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
   391
  by (simp cong: conj_cong)
36799
628fe06cbeff one structure is better than three
haftmann
parents: 36798
diff changeset
   392
48891
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 47432
diff changeset
   393
ML_file "Tools/Qelim/cooper.ML"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   394
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58925
diff changeset
   395
method_setup presburger = \<open>
47432
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
61476
1884c40f1539 tuned signature;
wenzelm
parents: 60758
diff changeset
   403
    val thms = Scan.repeats (Scan.unless any_keyword Attrib.multi_thm)
47432
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
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58925
diff changeset
   411
\<close> "Cooper's algorithm for Presburger arithmetic"
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   412
64247
f537616459e6 avoid effectively subsumed rules;
haftmann
parents: 64246
diff changeset
   413
declare mod_eq_0_iff_dvd [presburger]
64244
e7102c40783c clarified theorem names
haftmann
parents: 64242
diff changeset
   414
declare mod_by_Suc_0 [presburger] 
54227
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]
64242
93c6f0da5c70 more standardized theorem names for facts involving the div and mod identity
haftmann
parents: 63962
diff changeset
   421
declare mult_div_mod_eq [presburger]
93c6f0da5c70 more standardized theorem names for facts involving the div and mod identity
haftmann
parents: 63962
diff changeset
   422
declare div_mult_mod_eq [presburger]
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   423
declare mod_mult_self1 [presburger]
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   424
declare mod_mult_self2 [presburger]
64247
f537616459e6 avoid effectively subsumed rules;
haftmann
parents: 64246
diff changeset
   425
declare mod2_Suc_Suc [presburger]
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 49962
diff changeset
   426
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
   427
declare nat_zero_less_power_iff [presburger]
36798
3981db162131 less complex organization of cooper source code
haftmann
parents: 36749
diff changeset
   428
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   429
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
   430
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
   431
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
   432
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
   433
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
   434
58777
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   435
context semiring_parity
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   436
begin
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   437
68100
b2d84b1114fa removed some lemma duplicates
haftmann
parents: 67613
diff changeset
   438
declare even_mult_iff [presburger]
58777
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   439
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   440
declare even_power [presburger]
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   441
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   442
lemma [presburger]:
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   443
  "even (a + b) \<longleftrightarrow> even a \<and> even b \<or> odd a \<and> odd b"
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   444
  by auto
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   445
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   446
end
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   447
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   448
context ring_parity
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   449
begin
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   450
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   451
declare even_minus [presburger]
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   452
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   453
end
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   454
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   455
context linordered_idom
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   456
begin
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   457
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   458
declare zero_le_power_eq [presburger]
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   459
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   460
declare zero_less_power_eq [presburger]
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   461
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   462
declare power_less_zero_eq [presburger]
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   463
  
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   464
declare power_le_zero_eq [presburger]
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   465
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   466
end
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   467
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   468
declare even_Suc [presburger]
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   469
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   470
lemma [presburger]:
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   471
  "Suc n div Suc (Suc 0) = n div Suc (Suc 0) \<longleftrightarrow> even n"
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   472
  by presburger
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   473
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   474
declare even_diff_nat [presburger]
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   475
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   476
lemma [presburger]:
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   477
  fixes k :: int
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   478
  shows "(k + 1) div 2 = k div 2 \<longleftrightarrow> even k"
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   479
  by presburger
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   480
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   481
lemma [presburger]:
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   482
  fixes k :: int
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   483
  shows "(k + 1) div 2 = k div 2 + 1 \<longleftrightarrow> odd k"
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   484
  by presburger
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   485
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   486
lemma [presburger]:
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   487
  "even n \<longleftrightarrow> even (int n)"
66630
034cabc4fda5 speed up proofs slightly
blanchet
parents: 64247
diff changeset
   488
  by simp
58777
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   489
  
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   490
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58925
diff changeset
   491
subsection \<open>Nice facts about division by @{term 4}\<close>  
58777
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   492
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   493
lemma even_even_mod_4_iff:
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   494
  "even (n::nat) \<longleftrightarrow> even (n mod 4)"
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   495
  by presburger
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   496
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   497
lemma odd_mod_4_div_2:
68157
057d5b4ce47e removed some non-essential rules
haftmann
parents: 68100
diff changeset
   498
  "n mod 4 = (3::nat) \<Longrightarrow> odd ((n - Suc 0) div 2)"
58777
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   499
  by presburger
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   500
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   501
lemma even_mod_4_div_2:
68157
057d5b4ce47e removed some non-essential rules
haftmann
parents: 68100
diff changeset
   502
  "n mod 4 = Suc 0 \<Longrightarrow> even ((n - Suc 0) div 2)"
58777
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   503
  by presburger
6ba2f1fa243b further downshift of theory Parity in the hierarchy
haftmann
parents: 57514
diff changeset
   504
56850
13a7bca533a3 added 'satx' proof method to Try0
blanchet
parents: 54227
diff changeset
   505
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58925
diff changeset
   506
subsection \<open>Try0\<close>
56850
13a7bca533a3 added 'satx' proof method to Try0
blanchet
parents: 54227
diff changeset
   507
13a7bca533a3 added 'satx' proof method to Try0
blanchet
parents: 54227
diff changeset
   508
ML_file "Tools/try0.ML"
13a7bca533a3 added 'satx' proof method to Try0
blanchet
parents: 54227
diff changeset
   509
23465
8f8835aac299 moved Presburger setup back to Presburger.thy;
wenzelm
parents:
diff changeset
   510
end