src/HOL/Presburger.thy
author berghofe
Tue Mar 25 09:47:05 2003 +0100 (2003-03-25)
changeset 13876 68f4ed8311ac
child 14139 ca3dd7ed5ac5
permissions -rw-r--r--
New decision procedure for Presburger arithmetic.
berghofe@13876
     1
(*  Title:      HOL/Integ/Presburger.thy
berghofe@13876
     2
    ID:         $Id$
berghofe@13876
     3
    Author:     Amine Chaieb, Tobias Nipkow and Stefan Berghofer, TU Muenchen
berghofe@13876
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
berghofe@13876
     5
berghofe@13876
     6
File containing necessary theorems for the proof
berghofe@13876
     7
generation for Cooper Algorithm  
berghofe@13876
     8
*)
berghofe@13876
     9
berghofe@13876
    10
theory Presburger = NatSimprocs
berghofe@13876
    11
files
berghofe@13876
    12
  ("cooper_dec.ML")
berghofe@13876
    13
  ("cooper_proof.ML")
berghofe@13876
    14
  ("qelim.ML")
berghofe@13876
    15
  ("presburger.ML"):
berghofe@13876
    16
berghofe@13876
    17
(* Theorem for unitifying the coeffitients of x in an existential formula*)
berghofe@13876
    18
berghofe@13876
    19
theorem unity_coeff_ex: "(\<exists>x::int. P (l * x)) = (\<exists>x. l dvd (1*x+0) \<and> P x)"
berghofe@13876
    20
  apply (rule iffI)
berghofe@13876
    21
  apply (erule exE)
berghofe@13876
    22
  apply (rule_tac x = "l * x" in exI)
berghofe@13876
    23
  apply simp
berghofe@13876
    24
  apply (erule exE)
berghofe@13876
    25
  apply (erule conjE)
berghofe@13876
    26
  apply (erule dvdE)
berghofe@13876
    27
  apply (rule_tac x = k in exI)
berghofe@13876
    28
  apply simp
berghofe@13876
    29
  done
berghofe@13876
    30
berghofe@13876
    31
lemma uminus_dvd_conv: "(d dvd (t::int)) = (-d dvd t)"
berghofe@13876
    32
apply(unfold dvd_def)
berghofe@13876
    33
apply(rule iffI)
berghofe@13876
    34
apply(clarsimp)
berghofe@13876
    35
apply(rename_tac k)
berghofe@13876
    36
apply(rule_tac x = "-k" in exI)
berghofe@13876
    37
apply simp
berghofe@13876
    38
apply(clarsimp)
berghofe@13876
    39
apply(rename_tac k)
berghofe@13876
    40
apply(rule_tac x = "-k" in exI)
berghofe@13876
    41
apply simp
berghofe@13876
    42
done
berghofe@13876
    43
berghofe@13876
    44
lemma uminus_dvd_conv': "(d dvd (t::int)) = (d dvd -t)"
berghofe@13876
    45
apply(unfold dvd_def)
berghofe@13876
    46
apply(rule iffI)
berghofe@13876
    47
apply(clarsimp)
berghofe@13876
    48
apply(rule_tac x = "-k" in exI)
berghofe@13876
    49
apply simp
berghofe@13876
    50
apply(clarsimp)
berghofe@13876
    51
apply(rule_tac x = "-k" in exI)
berghofe@13876
    52
apply simp
berghofe@13876
    53
done
berghofe@13876
    54
berghofe@13876
    55
berghofe@13876
    56
berghofe@13876
    57
(*Theorems for the combination of proofs of the equality of P and P_m for integers x less than some integer z.*)
berghofe@13876
    58
berghofe@13876
    59
theorem eq_minf_conjI: "\<exists>z1::int. \<forall>x. x < z1 \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
berghofe@13876
    60
  \<exists>z2::int. \<forall>x. x < z2 \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
berghofe@13876
    61
  \<exists>z::int. \<forall>x. x < z \<longrightarrow> ((A1 x \<and> B1 x) = (A2 x \<and> B2 x))"
berghofe@13876
    62
  apply (erule exE)+
berghofe@13876
    63
  apply (rule_tac x = "min z1 z2" in exI)
berghofe@13876
    64
  apply simp
berghofe@13876
    65
  done
berghofe@13876
    66
berghofe@13876
    67
berghofe@13876
    68
theorem eq_minf_disjI: "\<exists>z1::int. \<forall>x. x < z1 \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
berghofe@13876
    69
  \<exists>z2::int. \<forall>x. x < z2 \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
berghofe@13876
    70
  \<exists>z::int. \<forall>x. x < z \<longrightarrow> ((A1 x \<or> B1 x) = (A2 x \<or> B2 x))"
berghofe@13876
    71
berghofe@13876
    72
  apply (erule exE)+
berghofe@13876
    73
  apply (rule_tac x = "min z1 z2" in exI)
berghofe@13876
    74
  apply simp
berghofe@13876
    75
  done
berghofe@13876
    76
berghofe@13876
    77
berghofe@13876
    78
(*Theorems for the combination of proofs of the equality of P and P_m for integers x greather than some integer z.*)
berghofe@13876
    79
berghofe@13876
    80
theorem eq_pinf_conjI: "\<exists>z1::int. \<forall>x. z1 < x \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
berghofe@13876
    81
  \<exists>z2::int. \<forall>x. z2 < x \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
berghofe@13876
    82
  \<exists>z::int. \<forall>x. z < x \<longrightarrow> ((A1 x \<and> B1 x) = (A2 x \<and> B2 x))"
berghofe@13876
    83
  apply (erule exE)+
berghofe@13876
    84
  apply (rule_tac x = "max z1 z2" in exI)
berghofe@13876
    85
  apply simp
berghofe@13876
    86
  done
berghofe@13876
    87
berghofe@13876
    88
berghofe@13876
    89
theorem eq_pinf_disjI: "\<exists>z1::int. \<forall>x. z1 < x \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
berghofe@13876
    90
  \<exists>z2::int. \<forall>x. z2 < x \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
berghofe@13876
    91
  \<exists>z::int. \<forall>x. z < x  \<longrightarrow> ((A1 x \<or> B1 x) = (A2 x \<or> B2 x))"
berghofe@13876
    92
  apply (erule exE)+
berghofe@13876
    93
  apply (rule_tac x = "max z1 z2" in exI)
berghofe@13876
    94
  apply simp
berghofe@13876
    95
  done
berghofe@13876
    96
(*=============================================================================*)
berghofe@13876
    97
(*Theorems for the combination of proofs of the modulo D property for P
berghofe@13876
    98
pluusinfinity*)
berghofe@13876
    99
(* FIXME : This is THE SAME theorem as for the minusinf version, but with +k.. instead of -k.. In the future replace these both with only one*)
berghofe@13876
   100
berghofe@13876
   101
theorem modd_pinf_conjI: "\<forall>(x::int) k. A x = A (x+k*d) \<Longrightarrow>
berghofe@13876
   102
  \<forall>(x::int) k. B x = B (x+k*d) \<Longrightarrow>
berghofe@13876
   103
  \<forall>(x::int) (k::int). (A x \<and> B x) = (A (x+k*d) \<and> B (x+k*d))"
berghofe@13876
   104
  by simp
berghofe@13876
   105
berghofe@13876
   106
berghofe@13876
   107
theorem modd_pinf_disjI: "\<forall>(x::int) k. A x = A (x+k*d) \<Longrightarrow>
berghofe@13876
   108
  \<forall>(x::int) k. B x = B (x+k*d) \<Longrightarrow>
berghofe@13876
   109
  \<forall>(x::int) (k::int). (A x \<or> B x) = (A (x+k*d) \<or> B (x+k*d))"
berghofe@13876
   110
  by simp
berghofe@13876
   111
berghofe@13876
   112
(*=============================================================================*)
berghofe@13876
   113
(*This is one of the cases where the simplifed formula is prooved to habe some property
berghofe@13876
   114
(in relation to P_m) but we need to proove the property for the original formula (P_m)*)
berghofe@13876
   115
(*FIXME : This is exaclty the same thm as for minusinf.*)
berghofe@13876
   116
lemma pinf_simp_eq: "ALL x. P(x) = Q(x) ==> (EX (x::int). P(x)) --> (EX (x::int). F(x))  ==> (EX (x::int). Q(x)) --> (EX (x::int). F(x)) "
berghofe@13876
   117
by blast
berghofe@13876
   118
berghofe@13876
   119
berghofe@13876
   120
berghofe@13876
   121
(*=============================================================================*)
berghofe@13876
   122
(*Theorems for the combination of proofs of the modulo D property for P
berghofe@13876
   123
minusinfinity*)
berghofe@13876
   124
berghofe@13876
   125
theorem modd_minf_conjI: "\<forall>(x::int) k. A x = A (x-k*d) \<Longrightarrow>
berghofe@13876
   126
  \<forall>(x::int) k. B x = B (x-k*d) \<Longrightarrow>
berghofe@13876
   127
  \<forall>(x::int) (k::int). (A x \<and> B x) = (A (x-k*d) \<and> B (x-k*d))"
berghofe@13876
   128
  by simp
berghofe@13876
   129
berghofe@13876
   130
berghofe@13876
   131
theorem modd_minf_disjI: "\<forall>(x::int) k. A x = A (x-k*d) \<Longrightarrow>
berghofe@13876
   132
  \<forall>(x::int) k. B x = B (x-k*d) \<Longrightarrow>
berghofe@13876
   133
  \<forall>(x::int) (k::int). (A x \<or> B x) = (A (x-k*d) \<or> B (x-k*d))"
berghofe@13876
   134
  by simp
berghofe@13876
   135
berghofe@13876
   136
(*=============================================================================*)
berghofe@13876
   137
(*This is one of the cases where the simplifed formula is prooved to habe some property
berghofe@13876
   138
(in relation to P_m) but we need to proove the property for the original formula (P_m)*)
berghofe@13876
   139
berghofe@13876
   140
lemma minf_simp_eq: "ALL x. P(x) = Q(x) ==> (EX (x::int). P(x)) --> (EX (x::int). F(x))  ==> (EX (x::int). Q(x)) --> (EX (x::int). F(x)) "
berghofe@13876
   141
by blast
berghofe@13876
   142
berghofe@13876
   143
(*=============================================================================*)
berghofe@13876
   144
berghofe@13876
   145
(*theorem needed for prooving at runtime divide properties using the arithmetic tatic
berghofe@13876
   146
(who knows only about modulo = 0)*)
berghofe@13876
   147
berghofe@13876
   148
lemma zdvd_iff_zmod_eq_0: "(m dvd n) = (n mod m = (0::int))"
berghofe@13876
   149
by(simp add:dvd_def zmod_eq_0_iff)
berghofe@13876
   150
berghofe@13876
   151
(*=============================================================================*)
berghofe@13876
   152
berghofe@13876
   153
berghofe@13876
   154
berghofe@13876
   155
(*Theorems used for the combination of proof for the backwards direction of cooper's
berghofe@13876
   156
theorem. they rely exclusively on Predicate calculus.*)
berghofe@13876
   157
berghofe@13876
   158
lemma not_ast_p_disjI: "(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P1(x) --> P1(x + d))
berghofe@13876
   159
==>
berghofe@13876
   160
(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P2(x) --> P2(x + d))
berghofe@13876
   161
==>
berghofe@13876
   162
(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) -->(P1(x) \<or> P2(x)) --> (P1(x + d) \<or> P2(x + d))) "
berghofe@13876
   163
by blast
berghofe@13876
   164
berghofe@13876
   165
berghofe@13876
   166
berghofe@13876
   167
lemma not_ast_p_conjI: "(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a- j)) --> P1(x) --> P1(x + d))
berghofe@13876
   168
==>
berghofe@13876
   169
(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P2(x) --> P2(x + d))
berghofe@13876
   170
==>
berghofe@13876
   171
(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) -->(P1(x) \<and> P2(x)) --> (P1(x + d)
berghofe@13876
   172
\<and> P2(x + d))) "
berghofe@13876
   173
by blast
berghofe@13876
   174
berghofe@13876
   175
lemma not_ast_p_Q_elim: "
berghofe@13876
   176
(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) -->P(x) --> P(x + d))
berghofe@13876
   177
==> ( P = Q )
berghofe@13876
   178
==> (ALL x. ~(EX (j::int) : {1..d}. EX (a::int) : A. P(a - j)) -->P(x) --> P(x + d))"
berghofe@13876
   179
by blast
berghofe@13876
   180
(*=============================================================================*)
berghofe@13876
   181
berghofe@13876
   182
berghofe@13876
   183
(*Theorems used for the combination of proof for the backwards direction of cooper's
berghofe@13876
   184
theorem. they rely exclusively on Predicate calculus.*)
berghofe@13876
   185
berghofe@13876
   186
lemma not_bst_p_disjI: "(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P1(x) --> P1(x - d))
berghofe@13876
   187
==>
berghofe@13876
   188
(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P2(x) --> P2(x - d))
berghofe@13876
   189
==>
berghofe@13876
   190
(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) -->(P1(x) \<or> P2(x)) --> (P1(x - d)
berghofe@13876
   191
\<or> P2(x-d))) "
berghofe@13876
   192
by blast
berghofe@13876
   193
berghofe@13876
   194
berghofe@13876
   195
berghofe@13876
   196
lemma not_bst_p_conjI: "(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P1(x) --> P1(x - d))
berghofe@13876
   197
==>
berghofe@13876
   198
(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P2(x) --> P2(x - d))
berghofe@13876
   199
==>
berghofe@13876
   200
(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) -->(P1(x) \<and> P2(x)) --> (P1(x - d)
berghofe@13876
   201
\<and> P2(x-d))) "
berghofe@13876
   202
by blast
berghofe@13876
   203
berghofe@13876
   204
lemma not_bst_p_Q_elim: "
berghofe@13876
   205
(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) -->P(x) --> P(x - d)) 
berghofe@13876
   206
==> ( P = Q )
berghofe@13876
   207
==> (ALL x. ~(EX (j::int) : {1..d}. EX (b::int) : B. P(b+j)) -->P(x) --> P(x - d))"
berghofe@13876
   208
by blast
berghofe@13876
   209
(*=============================================================================*)
berghofe@13876
   210
(*The Theorem for the second proof step- about bset. it is trivial too. *)
berghofe@13876
   211
lemma bst_thm: " (EX (j::int) : {1..d}. EX (b::int) : B. P (b+j) )--> (EX x::int. P (x)) "
berghofe@13876
   212
by blast
berghofe@13876
   213
berghofe@13876
   214
(*The Theorem for the second proof step- about aset. it is trivial too. *)
berghofe@13876
   215
lemma ast_thm: " (EX (j::int) : {1..d}. EX (a::int) : A. P (a - j) )--> (EX x::int. P (x)) "
berghofe@13876
   216
by blast
berghofe@13876
   217
berghofe@13876
   218
berghofe@13876
   219
(*=============================================================================*)
berghofe@13876
   220
(*This is the first direction of cooper's theorem*)
berghofe@13876
   221
lemma cooper_thm: "(R --> (EX x::int. P x))  ==> (Q -->(EX x::int.  P x )) ==> ((R|Q) --> (EX x::int. P x )) "
berghofe@13876
   222
by blast
berghofe@13876
   223
berghofe@13876
   224
(*=============================================================================*)
berghofe@13876
   225
(*The full cooper's theoorem in its equivalence Form- Given the premisses it is trivial
berghofe@13876
   226
too, it relies exclusively on prediacte calculus.*)
berghofe@13876
   227
lemma cooper_eq_thm: "(R --> (EX x::int. P x))  ==> (Q -->(EX x::int.  P x )) ==> ((~Q)
berghofe@13876
   228
--> (EX x::int. P x ) --> R) ==> (EX x::int. P x) = R|Q "
berghofe@13876
   229
by blast
berghofe@13876
   230
berghofe@13876
   231
(*=============================================================================*)
berghofe@13876
   232
(*Some of the atomic theorems generated each time the atom does not depend on x, they
berghofe@13876
   233
are trivial.*)
berghofe@13876
   234
berghofe@13876
   235
lemma  fm_eq_minf: "EX z::int. ALL x. x < z --> (P = P) "
berghofe@13876
   236
by blast
berghofe@13876
   237
berghofe@13876
   238
lemma  fm_modd_minf: "ALL (x::int). ALL (k::int). (P = P)"
berghofe@13876
   239
by blast
berghofe@13876
   240
berghofe@13876
   241
lemma not_bst_p_fm: "ALL (x::int). Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> fm --> fm"
berghofe@13876
   242
by blast
berghofe@13876
   243
berghofe@13876
   244
berghofe@13876
   245
berghofe@13876
   246
lemma  fm_eq_pinf: "EX z::int. ALL x. z < x --> (P = P) "
berghofe@13876
   247
by blast
berghofe@13876
   248
berghofe@13876
   249
(* The next 2 thms are the same as the minusinf version*)
berghofe@13876
   250
lemma  fm_modd_pinf: "ALL (x::int). ALL (k::int). (P = P)"
berghofe@13876
   251
by blast
berghofe@13876
   252
berghofe@13876
   253
lemma not_ast_p_fm: "ALL (x::int). Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> fm --> fm"
berghofe@13876
   254
by blast
berghofe@13876
   255
berghofe@13876
   256
berghofe@13876
   257
(* Theorems to be deleted from simpset when proving simplified formulaes*)
berghofe@13876
   258
lemma P_eqtrue: "(P=True) = P"
berghofe@13876
   259
  by rules
berghofe@13876
   260
berghofe@13876
   261
lemma P_eqfalse: "(P=False) = (~P)"
berghofe@13876
   262
  by rules
berghofe@13876
   263
berghofe@13876
   264
(*=============================================================================*)
berghofe@13876
   265
berghofe@13876
   266
(*Theorems for the generation of the bachwards direction of cooper's theorem*)
berghofe@13876
   267
(*These are the 6 interesting atomic cases which have to be proved relying on the
berghofe@13876
   268
properties of B-set ant the arithmetic and contradiction proofs*)
berghofe@13876
   269
berghofe@13876
   270
lemma not_bst_p_lt: "0 < (d::int) ==>
berghofe@13876
   271
 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> ( 0 < -x + a) --> (0 < -(x - d) + a )"
berghofe@13876
   272
by arith
berghofe@13876
   273
berghofe@13876
   274
lemma not_bst_p_gt: "\<lbrakk> (g::int) \<in> B; g = -a \<rbrakk> \<Longrightarrow>
berghofe@13876
   275
 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> (0 < (x) + a) --> ( 0 < (x - d) + a)"
berghofe@13876
   276
apply clarsimp
berghofe@13876
   277
apply(rule ccontr)
berghofe@13876
   278
apply(drule_tac x = "x+a" in bspec)
berghofe@13876
   279
apply(simp add:atLeastAtMost_iff)
berghofe@13876
   280
apply(drule_tac x = "-a" in bspec)
berghofe@13876
   281
apply assumption
berghofe@13876
   282
apply(simp)
berghofe@13876
   283
done
berghofe@13876
   284
berghofe@13876
   285
lemma not_bst_p_eq: "\<lbrakk> 0 < d; (g::int) \<in> B; g = -a - 1 \<rbrakk> \<Longrightarrow>
berghofe@13876
   286
 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> (0 = x + a) --> (0 = (x - d) + a )"
berghofe@13876
   287
apply clarsimp
berghofe@13876
   288
apply(subgoal_tac "x = -a")
berghofe@13876
   289
 prefer 2 apply arith
berghofe@13876
   290
apply(drule_tac x = "1" in bspec)
berghofe@13876
   291
apply(simp add:atLeastAtMost_iff)
berghofe@13876
   292
apply(drule_tac x = "-a- 1" in bspec)
berghofe@13876
   293
apply assumption
berghofe@13876
   294
apply(simp)
berghofe@13876
   295
done
berghofe@13876
   296
berghofe@13876
   297
berghofe@13876
   298
lemma not_bst_p_ne: "\<lbrakk> 0 < d; (g::int) \<in> B; g = -a \<rbrakk> \<Longrightarrow>
berghofe@13876
   299
 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> ~(0 = x + a) --> ~(0 = (x - d) + a)"
berghofe@13876
   300
apply clarsimp
berghofe@13876
   301
apply(subgoal_tac "x = -a+d")
berghofe@13876
   302
 prefer 2 apply arith
berghofe@13876
   303
apply(drule_tac x = "d" in bspec)
berghofe@13876
   304
apply(simp add:atLeastAtMost_iff)
berghofe@13876
   305
apply(drule_tac x = "-a" in bspec)
berghofe@13876
   306
apply assumption
berghofe@13876
   307
apply(simp)
berghofe@13876
   308
done
berghofe@13876
   309
berghofe@13876
   310
berghofe@13876
   311
lemma not_bst_p_dvd: "(d1::int) dvd d ==>
berghofe@13876
   312
 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> d1 dvd (x + a) --> d1 dvd ((x - d) + a )"
berghofe@13876
   313
apply(clarsimp simp add:dvd_def)
berghofe@13876
   314
apply(rename_tac m)
berghofe@13876
   315
apply(rule_tac x = "m - k" in exI)
berghofe@13876
   316
apply(simp add:int_distrib)
berghofe@13876
   317
done
berghofe@13876
   318
berghofe@13876
   319
lemma not_bst_p_ndvd: "(d1::int) dvd d ==>
berghofe@13876
   320
 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> ~(d1 dvd (x + a)) --> ~(d1 dvd ((x - d) + a ))"
berghofe@13876
   321
apply(clarsimp simp add:dvd_def)
berghofe@13876
   322
apply(rename_tac m)
berghofe@13876
   323
apply(erule_tac x = "m + k" in allE)
berghofe@13876
   324
apply(simp add:int_distrib)
berghofe@13876
   325
done
berghofe@13876
   326
berghofe@13876
   327
berghofe@13876
   328
berghofe@13876
   329
(*Theorems for the generation of the bachwards direction of cooper's theorem*)
berghofe@13876
   330
(*These are the 6 interesting atomic cases which have to be proved relying on the
berghofe@13876
   331
properties of A-set ant the arithmetic and contradiction proofs*)
berghofe@13876
   332
berghofe@13876
   333
lemma not_ast_p_gt: "0 < (d::int) ==>
berghofe@13876
   334
 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> ( 0 < x + t) --> (0 < (x + d) + t )"
berghofe@13876
   335
by arith
berghofe@13876
   336
berghofe@13876
   337
berghofe@13876
   338
lemma not_ast_p_lt: "\<lbrakk>0 < d ;(t::int) \<in> A \<rbrakk> \<Longrightarrow>
berghofe@13876
   339
 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> (0 < -x + t) --> ( 0 < -(x + d) + t)"
berghofe@13876
   340
  apply clarsimp
berghofe@13876
   341
  apply (rule ccontr)
berghofe@13876
   342
  apply (drule_tac x = "t-x" in bspec)
berghofe@13876
   343
  apply simp
berghofe@13876
   344
  apply (drule_tac x = "t" in bspec)
berghofe@13876
   345
  apply assumption
berghofe@13876
   346
  apply simp
berghofe@13876
   347
  done
berghofe@13876
   348
berghofe@13876
   349
lemma not_ast_p_eq: "\<lbrakk> 0 < d; (g::int) \<in> A; g = -t + 1 \<rbrakk> \<Longrightarrow>
berghofe@13876
   350
 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> (0 = x + t) --> (0 = (x + d) + t )"
berghofe@13876
   351
  apply clarsimp
berghofe@13876
   352
  apply (drule_tac x="1" in bspec)
berghofe@13876
   353
  apply simp
berghofe@13876
   354
  apply (drule_tac x="- t + 1" in bspec)
berghofe@13876
   355
  apply assumption
berghofe@13876
   356
  apply(subgoal_tac "x = -t")
berghofe@13876
   357
  prefer 2 apply arith
berghofe@13876
   358
  apply simp
berghofe@13876
   359
  done
berghofe@13876
   360
berghofe@13876
   361
lemma not_ast_p_ne: "\<lbrakk> 0 < d; (g::int) \<in> A; g = -t \<rbrakk> \<Longrightarrow>
berghofe@13876
   362
 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> ~(0 = x + t) --> ~(0 = (x + d) + t)"
berghofe@13876
   363
  apply clarsimp
berghofe@13876
   364
  apply (subgoal_tac "x = -t-d")
berghofe@13876
   365
  prefer 2 apply arith
berghofe@13876
   366
  apply (drule_tac x = "d" in bspec)
berghofe@13876
   367
  apply simp
berghofe@13876
   368
  apply (drule_tac x = "-t" in bspec)
berghofe@13876
   369
  apply assumption
berghofe@13876
   370
  apply simp
berghofe@13876
   371
  done
berghofe@13876
   372
berghofe@13876
   373
lemma not_ast_p_dvd: "(d1::int) dvd d ==>
berghofe@13876
   374
 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> d1 dvd (x + t) --> d1 dvd ((x + d) + t )"
berghofe@13876
   375
  apply(clarsimp simp add:dvd_def)
berghofe@13876
   376
  apply(rename_tac m)
berghofe@13876
   377
  apply(rule_tac x = "m + k" in exI)
berghofe@13876
   378
  apply(simp add:int_distrib)
berghofe@13876
   379
  done
berghofe@13876
   380
berghofe@13876
   381
lemma not_ast_p_ndvd: "(d1::int) dvd d ==>
berghofe@13876
   382
 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> ~(d1 dvd (x + t)) --> ~(d1 dvd ((x + d) + t ))"
berghofe@13876
   383
  apply(clarsimp simp add:dvd_def)
berghofe@13876
   384
  apply(rename_tac m)
berghofe@13876
   385
  apply(erule_tac x = "m - k" in allE)
berghofe@13876
   386
  apply(simp add:int_distrib)
berghofe@13876
   387
  done
berghofe@13876
   388
berghofe@13876
   389
berghofe@13876
   390
berghofe@13876
   391
(*=============================================================================*)
berghofe@13876
   392
(*These are the atomic cases for the proof generation for the modulo D property for P
berghofe@13876
   393
plusinfinity*)
berghofe@13876
   394
(*They are fully based on arithmetics*)
berghofe@13876
   395
berghofe@13876
   396
lemma  dvd_modd_pinf: "((d::int) dvd d1) ==>
berghofe@13876
   397
 (ALL (x::int). ALL (k::int). (((d::int) dvd (x + t)) = (d dvd (x+k*d1 + t))))"
berghofe@13876
   398
  apply(clarsimp simp add:dvd_def)
berghofe@13876
   399
  apply(rule iffI)
berghofe@13876
   400
  apply(clarsimp)
berghofe@13876
   401
  apply(rename_tac n m)
berghofe@13876
   402
  apply(rule_tac x = "m + n*k" in exI)
berghofe@13876
   403
  apply(simp add:int_distrib)
berghofe@13876
   404
  apply(clarsimp)
berghofe@13876
   405
  apply(rename_tac n m)
berghofe@13876
   406
  apply(rule_tac x = "m - n*k" in exI)
berghofe@13876
   407
  apply(simp add:int_distrib zmult_ac)
berghofe@13876
   408
  done
berghofe@13876
   409
berghofe@13876
   410
lemma  not_dvd_modd_pinf: "((d::int) dvd d1) ==>
berghofe@13876
   411
 (ALL (x::int). ALL k. (~((d::int) dvd (x + t))) = (~(d dvd (x+k*d1 + t))))"
berghofe@13876
   412
  apply(clarsimp simp add:dvd_def)
berghofe@13876
   413
  apply(rule iffI)
berghofe@13876
   414
  apply(clarsimp)
berghofe@13876
   415
  apply(rename_tac n m)
berghofe@13876
   416
  apply(erule_tac x = "m - n*k" in allE)
berghofe@13876
   417
  apply(simp add:int_distrib zmult_ac)
berghofe@13876
   418
  apply(clarsimp)
berghofe@13876
   419
  apply(rename_tac n m)
berghofe@13876
   420
  apply(erule_tac x = "m + n*k" in allE)
berghofe@13876
   421
  apply(simp add:int_distrib zmult_ac)
berghofe@13876
   422
  done
berghofe@13876
   423
berghofe@13876
   424
(*=============================================================================*)
berghofe@13876
   425
(*These are the atomic cases for the proof generation for the equivalence of P and P
berghofe@13876
   426
plusinfinity for integers x greather than some integer z.*)
berghofe@13876
   427
(*They are fully based on arithmetics*)
berghofe@13876
   428
berghofe@13876
   429
lemma  eq_eq_pinf: "EX z::int. ALL x. z < x --> (( 0 = x +t ) = False )"
berghofe@13876
   430
  apply(rule_tac x = "-t" in exI)
berghofe@13876
   431
  apply simp
berghofe@13876
   432
  done
berghofe@13876
   433
berghofe@13876
   434
lemma  neq_eq_pinf: "EX z::int. ALL x.  z < x --> ((~( 0 = x +t )) = True )"
berghofe@13876
   435
  apply(rule_tac x = "-t" in exI)
berghofe@13876
   436
  apply simp
berghofe@13876
   437
  done
berghofe@13876
   438
berghofe@13876
   439
lemma  le_eq_pinf: "EX z::int. ALL x.  z < x --> ( 0 < x +t  = True )"
berghofe@13876
   440
  apply(rule_tac x = "-t" in exI)
berghofe@13876
   441
  apply simp
berghofe@13876
   442
  done
berghofe@13876
   443
berghofe@13876
   444
lemma  len_eq_pinf: "EX z::int. ALL x. z < x  --> (0 < -x +t  = False )"
berghofe@13876
   445
  apply(rule_tac x = "t" in exI)
berghofe@13876
   446
  apply simp
berghofe@13876
   447
  done
berghofe@13876
   448
berghofe@13876
   449
lemma  dvd_eq_pinf: "EX z::int. ALL x.  z < x --> ((d dvd (x + t)) = (d dvd (x + t))) "
berghofe@13876
   450
by simp
berghofe@13876
   451
berghofe@13876
   452
lemma  not_dvd_eq_pinf: "EX z::int. ALL x. z < x  --> ((~(d dvd (x + t))) = (~(d dvd (x + t)))) "
berghofe@13876
   453
by simp
berghofe@13876
   454
berghofe@13876
   455
berghofe@13876
   456
berghofe@13876
   457
berghofe@13876
   458
(*=============================================================================*)
berghofe@13876
   459
(*These are the atomic cases for the proof generation for the modulo D property for P
berghofe@13876
   460
minusinfinity*)
berghofe@13876
   461
(*They are fully based on arithmetics*)
berghofe@13876
   462
berghofe@13876
   463
lemma  dvd_modd_minf: "((d::int) dvd d1) ==>
berghofe@13876
   464
 (ALL (x::int). ALL (k::int). (((d::int) dvd (x + t)) = (d dvd (x-k*d1 + t))))"
berghofe@13876
   465
apply(clarsimp simp add:dvd_def)
berghofe@13876
   466
apply(rule iffI)
berghofe@13876
   467
apply(clarsimp)
berghofe@13876
   468
apply(rename_tac n m)
berghofe@13876
   469
apply(rule_tac x = "m - n*k" in exI)
berghofe@13876
   470
apply(simp add:int_distrib)
berghofe@13876
   471
apply(clarsimp)
berghofe@13876
   472
apply(rename_tac n m)
berghofe@13876
   473
apply(rule_tac x = "m + n*k" in exI)
berghofe@13876
   474
apply(simp add:int_distrib zmult_ac)
berghofe@13876
   475
done
berghofe@13876
   476
berghofe@13876
   477
berghofe@13876
   478
lemma  not_dvd_modd_minf: "((d::int) dvd d1) ==>
berghofe@13876
   479
 (ALL (x::int). ALL k. (~((d::int) dvd (x + t))) = (~(d dvd (x-k*d1 + t))))"
berghofe@13876
   480
apply(clarsimp simp add:dvd_def)
berghofe@13876
   481
apply(rule iffI)
berghofe@13876
   482
apply(clarsimp)
berghofe@13876
   483
apply(rename_tac n m)
berghofe@13876
   484
apply(erule_tac x = "m + n*k" in allE)
berghofe@13876
   485
apply(simp add:int_distrib zmult_ac)
berghofe@13876
   486
apply(clarsimp)
berghofe@13876
   487
apply(rename_tac n m)
berghofe@13876
   488
apply(erule_tac x = "m - n*k" in allE)
berghofe@13876
   489
apply(simp add:int_distrib zmult_ac)
berghofe@13876
   490
done
berghofe@13876
   491
berghofe@13876
   492
berghofe@13876
   493
(*=============================================================================*)
berghofe@13876
   494
(*These are the atomic cases for the proof generation for the equivalence of P and P
berghofe@13876
   495
minusinfinity for integers x less than some integer z.*)
berghofe@13876
   496
(*They are fully based on arithmetics*)
berghofe@13876
   497
berghofe@13876
   498
lemma  eq_eq_minf: "EX z::int. ALL x. x < z --> (( 0 = x +t ) = False )"
berghofe@13876
   499
apply(rule_tac x = "-t" in exI)
berghofe@13876
   500
apply simp
berghofe@13876
   501
done
berghofe@13876
   502
berghofe@13876
   503
lemma  neq_eq_minf: "EX z::int. ALL x. x < z --> ((~( 0 = x +t )) = True )"
berghofe@13876
   504
apply(rule_tac x = "-t" in exI)
berghofe@13876
   505
apply simp
berghofe@13876
   506
done
berghofe@13876
   507
berghofe@13876
   508
lemma  le_eq_minf: "EX z::int. ALL x. x < z --> ( 0 < x +t  = False )"
berghofe@13876
   509
apply(rule_tac x = "-t" in exI)
berghofe@13876
   510
apply simp
berghofe@13876
   511
done
berghofe@13876
   512
berghofe@13876
   513
berghofe@13876
   514
lemma  len_eq_minf: "EX z::int. ALL x. x < z --> (0 < -x +t  = True )"
berghofe@13876
   515
apply(rule_tac x = "t" in exI)
berghofe@13876
   516
apply simp
berghofe@13876
   517
done
berghofe@13876
   518
berghofe@13876
   519
lemma  dvd_eq_minf: "EX z::int. ALL x. x < z --> ((d dvd (x + t)) = (d dvd (x + t))) "
berghofe@13876
   520
by simp
berghofe@13876
   521
berghofe@13876
   522
lemma  not_dvd_eq_minf: "EX z::int. ALL x. x < z --> ((~(d dvd (x + t))) = (~(d dvd (x + t)))) "
berghofe@13876
   523
by simp
berghofe@13876
   524
berghofe@13876
   525
berghofe@13876
   526
(*=============================================================================*)
berghofe@13876
   527
(*This Theorem combines whithnesses about P minusinfinity to schow one component of the
berghofe@13876
   528
equivalence proof for cooper's theorem*)
berghofe@13876
   529
berghofe@13876
   530
(* FIXME: remove once they are part of the distribution *)
berghofe@13876
   531
theorem int_ge_induct[consumes 1,case_names base step]:
berghofe@13876
   532
  assumes ge: "k \<le> (i::int)" and
berghofe@13876
   533
        base: "P(k)" and
berghofe@13876
   534
        step: "\<And>i. \<lbrakk>k \<le> i; P i\<rbrakk> \<Longrightarrow> P(i+1)"
berghofe@13876
   535
  shows "P i"
berghofe@13876
   536
proof -
berghofe@13876
   537
  { fix n have "\<And>i::int. n = nat(i-k) \<Longrightarrow> k <= i \<Longrightarrow> P i"
berghofe@13876
   538
    proof (induct n)
berghofe@13876
   539
      case 0
berghofe@13876
   540
      hence "i = k" by arith
berghofe@13876
   541
      thus "P i" using base by simp
berghofe@13876
   542
    next
berghofe@13876
   543
      case (Suc n)
berghofe@13876
   544
      hence "n = nat((i - 1) - k)" by arith
berghofe@13876
   545
      moreover
berghofe@13876
   546
      have ki1: "k \<le> i - 1" using Suc.prems by arith
berghofe@13876
   547
      ultimately
berghofe@13876
   548
      have "P(i - 1)" by(rule Suc.hyps)
berghofe@13876
   549
      from step[OF ki1 this] show ?case by simp
berghofe@13876
   550
    qed
berghofe@13876
   551
  }
berghofe@13876
   552
  from this ge show ?thesis by fast
berghofe@13876
   553
qed
berghofe@13876
   554
berghofe@13876
   555
theorem int_gr_induct[consumes 1,case_names base step]:
berghofe@13876
   556
  assumes gr: "k < (i::int)" and
berghofe@13876
   557
        base: "P(k+1)" and
berghofe@13876
   558
        step: "\<And>i. \<lbrakk>k < i; P i\<rbrakk> \<Longrightarrow> P(i+1)"
berghofe@13876
   559
  shows "P i"
berghofe@13876
   560
apply(rule int_ge_induct[of "k + 1"])
berghofe@13876
   561
  using gr apply arith
berghofe@13876
   562
 apply(rule base)
berghofe@13876
   563
apply(rule step)
berghofe@13876
   564
 apply simp+
berghofe@13876
   565
done
berghofe@13876
   566
berghofe@13876
   567
lemma decr_lemma: "0 < (d::int) \<Longrightarrow> x - (abs(x-z)+1) * d < z"
berghofe@13876
   568
apply(induct rule: int_gr_induct)
berghofe@13876
   569
 apply simp
berghofe@13876
   570
 apply arith
berghofe@13876
   571
apply (simp add:int_distrib)
berghofe@13876
   572
apply arith
berghofe@13876
   573
done
berghofe@13876
   574
berghofe@13876
   575
lemma incr_lemma: "0 < (d::int) \<Longrightarrow> z < x + (abs(x-z)+1) * d"
berghofe@13876
   576
apply(induct rule: int_gr_induct)
berghofe@13876
   577
 apply simp
berghofe@13876
   578
 apply arith
berghofe@13876
   579
apply (simp add:int_distrib)
berghofe@13876
   580
apply arith
berghofe@13876
   581
done
berghofe@13876
   582
berghofe@13876
   583
lemma  minusinfinity:
berghofe@13876
   584
  assumes "0 < d" and
berghofe@13876
   585
    P1eqP1: "ALL x k. P1 x = P1(x - k*d)" and
berghofe@13876
   586
    ePeqP1: "EX z::int. ALL x. x < z \<longrightarrow> (P x = P1 x)"
berghofe@13876
   587
  shows "(EX x. P1 x) \<longrightarrow> (EX x. P x)"
berghofe@13876
   588
proof
berghofe@13876
   589
  assume eP1: "EX x. P1 x"
berghofe@13876
   590
  then obtain x where P1: "P1 x" ..
berghofe@13876
   591
  from ePeqP1 obtain z where P1eqP: "ALL x. x < z \<longrightarrow> (P x = P1 x)" ..
berghofe@13876
   592
  let ?w = "x - (abs(x-z)+1) * d"
berghofe@13876
   593
  show "EX x. P x"
berghofe@13876
   594
  proof
berghofe@13876
   595
    have w: "?w < z" by(rule decr_lemma)
berghofe@13876
   596
    have "P1 x = P1 ?w" using P1eqP1 by blast
berghofe@13876
   597
    also have "\<dots> = P(?w)" using w P1eqP by blast
berghofe@13876
   598
    finally show "P ?w" using P1 by blast
berghofe@13876
   599
  qed
berghofe@13876
   600
qed
berghofe@13876
   601
berghofe@13876
   602
(*=============================================================================*)
berghofe@13876
   603
(*This Theorem combines whithnesses about P minusinfinity to schow one component of the
berghofe@13876
   604
equivalence proof for cooper's theorem*)
berghofe@13876
   605
berghofe@13876
   606
lemma plusinfinity:
berghofe@13876
   607
  assumes "0 < d" and
berghofe@13876
   608
    P1eqP1: "ALL (x::int) (k::int). P1 x = P1 (x + k * d)" and
berghofe@13876
   609
    ePeqP1: "EX z::int. ALL x. z < x  --> (P x = P1 x)"
berghofe@13876
   610
  shows "(EX x::int. P1 x) --> (EX x::int. P x)"
berghofe@13876
   611
proof
berghofe@13876
   612
  assume eP1: "EX x. P1 x"
berghofe@13876
   613
  then obtain x where P1: "P1 x" ..
berghofe@13876
   614
  from ePeqP1 obtain z where P1eqP: "ALL x. z < x \<longrightarrow> (P x = P1 x)" ..
berghofe@13876
   615
  let ?w = "x + (abs(x-z)+1) * d"
berghofe@13876
   616
  show "EX x. P x"
berghofe@13876
   617
  proof
berghofe@13876
   618
    have w: "z < ?w" by(rule incr_lemma)
berghofe@13876
   619
    have "P1 x = P1 ?w" using P1eqP1 by blast
berghofe@13876
   620
    also have "\<dots> = P(?w)" using w P1eqP by blast
berghofe@13876
   621
    finally show "P ?w" using P1 by blast
berghofe@13876
   622
  qed
berghofe@13876
   623
qed
berghofe@13876
   624
 
berghofe@13876
   625
berghofe@13876
   626
berghofe@13876
   627
(*=============================================================================*)
berghofe@13876
   628
(*Theorem for periodic function on discrete sets*)
berghofe@13876
   629
berghofe@13876
   630
lemma minf_vee:
berghofe@13876
   631
  assumes dpos: "(0::int) < d" and modd: "ALL x k. P x = P(x - k*d)"
berghofe@13876
   632
  shows "(EX x. P x) = (EX j : {1..d}. P j)"
berghofe@13876
   633
  (is "?LHS = ?RHS")
berghofe@13876
   634
proof
berghofe@13876
   635
  assume ?LHS
berghofe@13876
   636
  then obtain x where P: "P x" ..
berghofe@13876
   637
  have "x mod d = x - (x div d)*d"
berghofe@13876
   638
    by(simp add:zmod_zdiv_equality zmult_ac eq_zdiff_eq)
berghofe@13876
   639
  hence Pmod: "P x = P(x mod d)" using modd by simp
berghofe@13876
   640
  show ?RHS
berghofe@13876
   641
  proof (cases)
berghofe@13876
   642
    assume "x mod d = 0"
berghofe@13876
   643
    hence "P 0" using P Pmod by simp
berghofe@13876
   644
    moreover have "P 0 = P(0 - (-1)*d)" using modd by blast
berghofe@13876
   645
    ultimately have "P d" by simp
berghofe@13876
   646
    moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
berghofe@13876
   647
    ultimately show ?RHS ..
berghofe@13876
   648
  next
berghofe@13876
   649
    assume not0: "x mod d \<noteq> 0"
berghofe@13876
   650
    have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
berghofe@13876
   651
    moreover have "x mod d : {1..d}"
berghofe@13876
   652
    proof -
berghofe@13876
   653
      have "0 \<le> x mod d" by(rule pos_mod_sign)
berghofe@13876
   654
      moreover have "x mod d < d" by(rule pos_mod_bound)
berghofe@13876
   655
      ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
berghofe@13876
   656
    qed
berghofe@13876
   657
    ultimately show ?RHS ..
berghofe@13876
   658
  qed
berghofe@13876
   659
next
berghofe@13876
   660
  assume ?RHS thus ?LHS by blast
berghofe@13876
   661
qed
berghofe@13876
   662
berghofe@13876
   663
(*=============================================================================*)
berghofe@13876
   664
(*Theorem for periodic function on discrete sets*)
berghofe@13876
   665
lemma pinf_vee:
berghofe@13876
   666
  assumes dpos: "0 < (d::int)" and modd: "ALL (x::int) (k::int). P x = P (x+k*d)"
berghofe@13876
   667
  shows "(EX x::int. P x) = (EX (j::int) : {1..d} . P j)"
berghofe@13876
   668
  (is "?LHS = ?RHS")
berghofe@13876
   669
proof
berghofe@13876
   670
  assume ?LHS
berghofe@13876
   671
  then obtain x where P: "P x" ..
berghofe@13876
   672
  have "x mod d = x + (-(x div d))*d"
berghofe@13876
   673
    by(simp add:zmod_zdiv_equality zmult_ac eq_zdiff_eq)
berghofe@13876
   674
  hence Pmod: "P x = P(x mod d)" using modd by (simp only:)
berghofe@13876
   675
  show ?RHS
berghofe@13876
   676
  proof (cases)
berghofe@13876
   677
    assume "x mod d = 0"
berghofe@13876
   678
    hence "P 0" using P Pmod by simp
berghofe@13876
   679
    moreover have "P 0 = P(0 + 1*d)" using modd by blast
berghofe@13876
   680
    ultimately have "P d" by simp
berghofe@13876
   681
    moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
berghofe@13876
   682
    ultimately show ?RHS ..
berghofe@13876
   683
  next
berghofe@13876
   684
    assume not0: "x mod d \<noteq> 0"
berghofe@13876
   685
    have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
berghofe@13876
   686
    moreover have "x mod d : {1..d}"
berghofe@13876
   687
    proof -
berghofe@13876
   688
      have "0 \<le> x mod d" by(rule pos_mod_sign)
berghofe@13876
   689
      moreover have "x mod d < d" by(rule pos_mod_bound)
berghofe@13876
   690
      ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
berghofe@13876
   691
    qed
berghofe@13876
   692
    ultimately show ?RHS ..
berghofe@13876
   693
  qed
berghofe@13876
   694
next
berghofe@13876
   695
  assume ?RHS thus ?LHS by blast
berghofe@13876
   696
qed
berghofe@13876
   697
berghofe@13876
   698
lemma decr_mult_lemma:
berghofe@13876
   699
  assumes dpos: "(0::int) < d" and
berghofe@13876
   700
          minus: "ALL x::int. P x \<longrightarrow> P(x - d)" and
berghofe@13876
   701
          knneg: "0 <= k"
berghofe@13876
   702
  shows "ALL x. P x \<longrightarrow> P(x - k*d)"
berghofe@13876
   703
using knneg
berghofe@13876
   704
proof (induct rule:int_ge_induct)
berghofe@13876
   705
  case base thus ?case by simp
berghofe@13876
   706
next
berghofe@13876
   707
  case (step i)
berghofe@13876
   708
  show ?case
berghofe@13876
   709
  proof
berghofe@13876
   710
    fix x
berghofe@13876
   711
    have "P x \<longrightarrow> P (x - i * d)" using step.hyps by blast
berghofe@13876
   712
    also have "\<dots> \<longrightarrow> P(x - (i + 1) * d)"
berghofe@13876
   713
      using minus[THEN spec, of "x - i * d"]
berghofe@13876
   714
      by (simp add:int_distrib zdiff_zdiff_eq[symmetric])
berghofe@13876
   715
    ultimately show "P x \<longrightarrow> P(x - (i + 1) * d)" by blast
berghofe@13876
   716
  qed
berghofe@13876
   717
qed
berghofe@13876
   718
berghofe@13876
   719
lemma incr_mult_lemma:
berghofe@13876
   720
  assumes dpos: "(0::int) < d" and
berghofe@13876
   721
          plus: "ALL x::int. P x \<longrightarrow> P(x + d)" and
berghofe@13876
   722
          knneg: "0 <= k"
berghofe@13876
   723
  shows "ALL x. P x \<longrightarrow> P(x + k*d)"
berghofe@13876
   724
using knneg
berghofe@13876
   725
proof (induct rule:int_ge_induct)
berghofe@13876
   726
  case base thus ?case by simp
berghofe@13876
   727
next
berghofe@13876
   728
  case (step i)
berghofe@13876
   729
  show ?case
berghofe@13876
   730
  proof
berghofe@13876
   731
    fix x
berghofe@13876
   732
    have "P x \<longrightarrow> P (x + i * d)" using step.hyps by blast
berghofe@13876
   733
    also have "\<dots> \<longrightarrow> P(x + (i + 1) * d)"
berghofe@13876
   734
      using plus[THEN spec, of "x + i * d"]
berghofe@13876
   735
      by (simp add:int_distrib zadd_ac)
berghofe@13876
   736
    ultimately show "P x \<longrightarrow> P(x + (i + 1) * d)" by blast
berghofe@13876
   737
  qed
berghofe@13876
   738
qed
berghofe@13876
   739
berghofe@13876
   740
lemma cpmi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. x < z --> (P x = P1 x))
berghofe@13876
   741
==> (EX (j::int) : {1..D}. EX (b::int) : B. P (b+j)) --> (EX (x::int). P x) 
berghofe@13876
   742
==> ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D) 
berghofe@13876
   743
==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x-k*D))))
berghofe@13876
   744
==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (b::int) : B. P (b+j)))"
berghofe@13876
   745
apply(rule iffI)
berghofe@13876
   746
prefer 2
berghofe@13876
   747
apply(drule minusinfinity)
berghofe@13876
   748
apply assumption+
berghofe@13876
   749
apply(fastsimp)
berghofe@13876
   750
apply clarsimp
berghofe@13876
   751
apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x - k*D)")
berghofe@13876
   752
apply(frule_tac x = x and z=z in decr_lemma)
berghofe@13876
   753
apply(subgoal_tac "P1(x - (\<bar>x - z\<bar> + 1) * D)")
berghofe@13876
   754
prefer 2
berghofe@13876
   755
apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
berghofe@13876
   756
prefer 2 apply arith
berghofe@13876
   757
 apply fastsimp
berghofe@13876
   758
apply(drule (1) minf_vee)
berghofe@13876
   759
apply blast
berghofe@13876
   760
apply(blast dest:decr_mult_lemma)
berghofe@13876
   761
done
berghofe@13876
   762
berghofe@13876
   763
(* Cooper Thm `, plus infinity version*)
berghofe@13876
   764
lemma cppi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. z < x --> (P x = P1 x))
berghofe@13876
   765
==> (EX (j::int) : {1..D}. EX (a::int) : A. P (a - j)) --> (EX (x::int). P x) 
berghofe@13876
   766
==> ALL x.~(EX (j::int) : {1..D}. EX (a::int) : A. P(a - j)) --> P (x) --> P (x + D) 
berghofe@13876
   767
==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x+k*D))))
berghofe@13876
   768
==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (a::int) : A. P (a - j)))"
berghofe@13876
   769
  apply(rule iffI)
berghofe@13876
   770
  prefer 2
berghofe@13876
   771
  apply(drule plusinfinity)
berghofe@13876
   772
  apply assumption+
berghofe@13876
   773
  apply(fastsimp)
berghofe@13876
   774
  apply clarsimp
berghofe@13876
   775
  apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x + k*D)")
berghofe@13876
   776
  apply(frule_tac x = x and z=z in incr_lemma)
berghofe@13876
   777
  apply(subgoal_tac "P1(x + (\<bar>x - z\<bar> + 1) * D)")
berghofe@13876
   778
  prefer 2
berghofe@13876
   779
  apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
berghofe@13876
   780
  prefer 2 apply arith
berghofe@13876
   781
  apply fastsimp
berghofe@13876
   782
  apply(drule (1) pinf_vee)
berghofe@13876
   783
  apply blast
berghofe@13876
   784
  apply(blast dest:incr_mult_lemma)
berghofe@13876
   785
  done
berghofe@13876
   786
berghofe@13876
   787
berghofe@13876
   788
(*=============================================================================*)
berghofe@13876
   789
berghofe@13876
   790
(*Theorems for the quantifier elminination Functions.*)
berghofe@13876
   791
berghofe@13876
   792
lemma qe_ex_conj: "(EX (x::int). A x) = R
berghofe@13876
   793
		==> (EX (x::int). P x) = (Q & (EX x::int. A x))
berghofe@13876
   794
		==> (EX (x::int). P x) = (Q & R)"
berghofe@13876
   795
by blast
berghofe@13876
   796
berghofe@13876
   797
lemma qe_ex_nconj: "(EX (x::int). P x) = (True & Q)
berghofe@13876
   798
		==> (EX (x::int). P x) = Q"
berghofe@13876
   799
by blast
berghofe@13876
   800
berghofe@13876
   801
lemma qe_conjI: "P1 = P2 ==> Q1 = Q2 ==> (P1 & Q1) = (P2 & Q2)"
berghofe@13876
   802
by blast
berghofe@13876
   803
berghofe@13876
   804
lemma qe_disjI: "P1 = P2 ==> Q1 = Q2 ==> (P1 | Q1) = (P2 | Q2)"
berghofe@13876
   805
by blast
berghofe@13876
   806
berghofe@13876
   807
lemma qe_impI: "P1 = P2 ==> Q1 = Q2 ==> (P1 --> Q1) = (P2 --> Q2)"
berghofe@13876
   808
by blast
berghofe@13876
   809
berghofe@13876
   810
lemma qe_eqI: "P1 = P2 ==> Q1 = Q2 ==> (P1 = Q1) = (P2 = Q2)"
berghofe@13876
   811
by blast
berghofe@13876
   812
berghofe@13876
   813
lemma qe_Not: "P = Q ==> (~P) = (~Q)"
berghofe@13876
   814
by blast
berghofe@13876
   815
berghofe@13876
   816
lemma qe_ALL: "(EX x. ~P x) = R ==> (ALL x. P x) = (~R)"
berghofe@13876
   817
by blast
berghofe@13876
   818
berghofe@13876
   819
(* Theorems for proving NNF *)
berghofe@13876
   820
berghofe@13876
   821
lemma nnf_im: "((~P) = P1) ==> (Q=Q1) ==> ((P --> Q) = (P1 | Q1))"
berghofe@13876
   822
by blast
berghofe@13876
   823
berghofe@13876
   824
lemma nnf_eq: "((P & Q) = (P1 & Q1)) ==> (((~P) & (~Q)) = (P2 & Q2)) ==> ((P = Q) = ((P1 & Q1)|(P2 & Q2)))"
berghofe@13876
   825
by blast
berghofe@13876
   826
berghofe@13876
   827
lemma nnf_nn: "(P = Q) ==> ((~~P) = Q)"
berghofe@13876
   828
  by blast
berghofe@13876
   829
lemma nnf_ncj: "((~P) = P1) ==> ((~Q) = Q1) ==> ((~(P & Q)) = (P1 | Q1))"
berghofe@13876
   830
by blast
berghofe@13876
   831
berghofe@13876
   832
lemma nnf_ndj: "((~P) = P1) ==> ((~Q) = Q1) ==> ((~(P | Q)) = (P1 & Q1))"
berghofe@13876
   833
by blast
berghofe@13876
   834
lemma nnf_nim: "(P = P1) ==> ((~Q) = Q1) ==> ((~(P --> Q)) = (P1 & Q1))"
berghofe@13876
   835
by blast
berghofe@13876
   836
lemma nnf_neq: "((P & (~Q)) = (P1 & Q1)) ==> (((~P) & Q) = (P2 & Q2)) ==> ((~(P = Q)) = ((P1 & Q1)|(P2 & Q2)))"
berghofe@13876
   837
by blast
berghofe@13876
   838
lemma nnf_sdj: "((A & (~B)) = (A1 & B1)) ==> ((C & (~D)) = (C1 & D1)) ==> (A = (~C)) ==> ((~((A & B) | (C & D))) = ((A1 & B1) | (C1 & D1)))"
berghofe@13876
   839
by blast
berghofe@13876
   840
berghofe@13876
   841
berghofe@13876
   842
lemma qe_exI2: "A = B ==> (EX (x::int). A(x)) = (EX (x::int). B(x))"
berghofe@13876
   843
  by simp
berghofe@13876
   844
berghofe@13876
   845
lemma qe_exI: "(!!x::int. A x = B x) ==> (EX (x::int). A(x)) = (EX (x::int). B(x))"
berghofe@13876
   846
  by rules
berghofe@13876
   847
berghofe@13876
   848
lemma qe_ALLI: "(!!x::int. A x = B x) ==> (ALL (x::int). A(x)) = (ALL (x::int). B(x))"
berghofe@13876
   849
  by rules
berghofe@13876
   850
berghofe@13876
   851
lemma cp_expand: "(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (b::int) : B. (P1 (j) | P(b+j)))
berghofe@13876
   852
==>(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (b::int) : B. (P1 (j) | P(b+j))) "
berghofe@13876
   853
by blast
berghofe@13876
   854
berghofe@13876
   855
lemma cppi_expand: "(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (a::int) : A. (P1 (j) | P(a - j)))
berghofe@13876
   856
==>(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (a::int) : A. (P1 (j) | P(a - j))) "
berghofe@13876
   857
by blast
berghofe@13876
   858
berghofe@13876
   859
berghofe@13876
   860
lemma simp_from_to: "{i..j::int} = (if j < i then {} else insert i {i+1..j})"
berghofe@13876
   861
apply(simp add:atLeastAtMost_def atLeast_def atMost_def)
berghofe@13876
   862
apply(fastsimp)
berghofe@13876
   863
done
berghofe@13876
   864
berghofe@13876
   865
(* Theorems required for the adjustcoeffitienteq*)
berghofe@13876
   866
berghofe@13876
   867
lemma ac_dvd_eq: assumes not0: "0 ~= (k::int)"
berghofe@13876
   868
shows "((m::int) dvd (c*n+t)) = (k*m dvd ((k*c)*n+(k*t)))" (is "?P = ?Q")
berghofe@13876
   869
proof
berghofe@13876
   870
  assume ?P
berghofe@13876
   871
  thus ?Q
berghofe@13876
   872
    apply(simp add:dvd_def)
berghofe@13876
   873
    apply clarify
berghofe@13876
   874
    apply(rename_tac d)
berghofe@13876
   875
    apply(drule_tac f = "op * k" in arg_cong)
berghofe@13876
   876
    apply(simp only:int_distrib)
berghofe@13876
   877
    apply(rule_tac x = "d" in exI)
berghofe@13876
   878
    apply(simp only:zmult_ac)
berghofe@13876
   879
    done
berghofe@13876
   880
next
berghofe@13876
   881
  assume ?Q
berghofe@13876
   882
  then obtain d where "k * c * n + k * t = (k*m)*d" by(fastsimp simp:dvd_def)
berghofe@13876
   883
  hence "(c * n + t) * k = (m*d) * k" by(simp add:int_distrib zmult_ac)
berghofe@13876
   884
  hence "((c * n + t) * k) div k = ((m*d) * k) div k" by(rule arg_cong[of _ _ "%t. t div k"])
berghofe@13876
   885
  hence "c*n+t = m*d" by(simp add: zdiv_zmult_self1[OF not0[symmetric]])
berghofe@13876
   886
  thus ?P by(simp add:dvd_def)
berghofe@13876
   887
qed
berghofe@13876
   888
berghofe@13876
   889
lemma ac_lt_eq: assumes gr0: "0 < (k::int)"
berghofe@13876
   890
shows "((m::int) < (c*n+t)) = (k*m <((k*c)*n+(k*t)))" (is "?P = ?Q")
berghofe@13876
   891
proof
berghofe@13876
   892
  assume P: ?P
berghofe@13876
   893
  show ?Q using zmult_zless_mono2[OF P gr0] by(simp add: int_distrib zmult_ac)
berghofe@13876
   894
next
berghofe@13876
   895
  assume ?Q
berghofe@13876
   896
  hence "0 < k*(c*n + t - m)" by(simp add: int_distrib zmult_ac)
berghofe@13876
   897
  with gr0 have "0 < (c*n + t - m)" by(simp add:int_0_less_mult_iff)
berghofe@13876
   898
  thus ?P by(simp)
berghofe@13876
   899
qed
berghofe@13876
   900
berghofe@13876
   901
lemma ac_eq_eq : assumes not0: "0 ~= (k::int)" shows "((m::int) = (c*n+t)) = (k*m =((k*c)*n+(k*t)) )" (is "?P = ?Q")
berghofe@13876
   902
proof
berghofe@13876
   903
  assume ?P
berghofe@13876
   904
  thus ?Q
berghofe@13876
   905
    apply(drule_tac f = "op * k" in arg_cong)
berghofe@13876
   906
    apply(simp only:int_distrib)
berghofe@13876
   907
    done
berghofe@13876
   908
next
berghofe@13876
   909
  assume ?Q
berghofe@13876
   910
  hence "m * k = (c*n + t) * k" by(simp add:int_distrib zmult_ac)
berghofe@13876
   911
  hence "((m) * k) div k = ((c*n + t) * k) div k" by(rule arg_cong[of _ _ "%t. t div k"])
berghofe@13876
   912
  thus ?P by(simp add: zdiv_zmult_self1[OF not0[symmetric]])
berghofe@13876
   913
qed
berghofe@13876
   914
berghofe@13876
   915
lemma ac_pi_eq: assumes gr0: "0 < (k::int)" shows "(~((0::int) < (c*n + t))) = (0 < ((-k)*c)*n + ((-k)*t + k))"
berghofe@13876
   916
proof -
berghofe@13876
   917
  have "(~ (0::int) < (c*n + t)) = (0<1-(c*n + t))" by arith
berghofe@13876
   918
  also have  "(1-(c*n + t)) = (-1*c)*n + (-t+1)" by(simp add: int_distrib zmult_ac)
berghofe@13876
   919
  also have "0<(-1*c)*n + (-t+1) = (0 < (k*(-1*c)*n) + (k*(-t+1)))" by(rule ac_lt_eq[of _ 0,OF gr0,simplified])
berghofe@13876
   920
  also have "(k*(-1*c)*n) + (k*(-t+1)) = ((-k)*c)*n + ((-k)*t + k)" by(simp add: int_distrib zmult_ac)
berghofe@13876
   921
  finally show ?thesis .
berghofe@13876
   922
qed
berghofe@13876
   923
berghofe@13876
   924
lemma binminus_uminus_conv: "(a::int) - b = a + (-b)"
berghofe@13876
   925
by arith
berghofe@13876
   926
berghofe@13876
   927
lemma  linearize_dvd: "(t::int) = t1 ==> (d dvd t) = (d dvd t1)"
berghofe@13876
   928
by simp
berghofe@13876
   929
berghofe@13876
   930
lemma lf_lt: "(l::int) = ll ==> (r::int) = lr ==> (l < r) =(ll < lr)"
berghofe@13876
   931
by simp
berghofe@13876
   932
berghofe@13876
   933
lemma lf_eq: "(l::int) = ll ==> (r::int) = lr ==> (l = r) =(ll = lr)"
berghofe@13876
   934
by simp
berghofe@13876
   935
berghofe@13876
   936
lemma lf_dvd: "(l::int) = ll ==> (r::int) = lr ==> (l dvd r) =(ll dvd lr)"
berghofe@13876
   937
by simp
berghofe@13876
   938
berghofe@13876
   939
(* Theorems for transforming predicates on nat to predicates on int*)
berghofe@13876
   940
berghofe@13876
   941
theorem all_nat: "(\<forall>x::nat. P x) = (\<forall>x::int. 0 <= x \<longrightarrow> P (nat x))"
berghofe@13876
   942
  by (simp split add: split_nat)
berghofe@13876
   943
berghofe@13876
   944
theorem ex_nat: "(\<exists>x::nat. P x) = (\<exists>x::int. 0 <= x \<and> P (nat x))"
berghofe@13876
   945
  apply (simp split add: split_nat)
berghofe@13876
   946
  apply (rule iffI)
berghofe@13876
   947
  apply (erule exE)
berghofe@13876
   948
  apply (rule_tac x = "int x" in exI)
berghofe@13876
   949
  apply simp
berghofe@13876
   950
  apply (erule exE)
berghofe@13876
   951
  apply (rule_tac x = "nat x" in exI)
berghofe@13876
   952
  apply (erule conjE)
berghofe@13876
   953
  apply (erule_tac x = "nat x" in allE)
berghofe@13876
   954
  apply simp
berghofe@13876
   955
  done
berghofe@13876
   956
berghofe@13876
   957
theorem zdiff_int_split: "P (int (x - y)) =
berghofe@13876
   958
  ((y \<le> x \<longrightarrow> P (int x - int y)) \<and> (x < y \<longrightarrow> P 0))"
berghofe@13876
   959
  apply (case_tac "y \<le> x")
berghofe@13876
   960
  apply (simp_all add: zdiff_int)
berghofe@13876
   961
  done
berghofe@13876
   962
berghofe@13876
   963
theorem zdvd_int: "(x dvd y) = (int x dvd int y)"
berghofe@13876
   964
  apply (simp only: dvd_def ex_nat int_int_eq [symmetric] zmult_int [symmetric]
berghofe@13876
   965
    nat_0_le cong add: conj_cong)
berghofe@13876
   966
  apply (rule iffI)
berghofe@13876
   967
  apply rules
berghofe@13876
   968
  apply (erule exE)
berghofe@13876
   969
  apply (case_tac "x=0")
berghofe@13876
   970
  apply (rule_tac x=0 in exI)
berghofe@13876
   971
  apply simp
berghofe@13876
   972
  apply (case_tac "0 \<le> k")
berghofe@13876
   973
  apply rules
berghofe@13876
   974
  apply (simp add: linorder_not_le)
berghofe@13876
   975
  apply (drule zmult_zless_mono2_neg [OF iffD2 [OF zero_less_int_conv]])
berghofe@13876
   976
  apply assumption
berghofe@13876
   977
  apply (simp add: zmult_ac)
berghofe@13876
   978
  done
berghofe@13876
   979
berghofe@13876
   980
theorem number_of1: "(0::int) <= number_of n \<Longrightarrow> (0::int) <= number_of (n BIT b)"
berghofe@13876
   981
  by simp
berghofe@13876
   982
berghofe@13876
   983
theorem number_of2: "(0::int) <= number_of bin.Pls" by simp
berghofe@13876
   984
berghofe@13876
   985
theorem Suc_plus1: "Suc n = n + 1" by simp
berghofe@13876
   986
berghofe@13876
   987
(* specific instances of congruence rules, to prevent simplifier from looping *)
berghofe@13876
   988
berghofe@13876
   989
theorem imp_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::nat) \<longrightarrow> P) = (0 <= x \<longrightarrow> P')"
berghofe@13876
   990
  by simp
berghofe@13876
   991
berghofe@13876
   992
theorem conj_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::nat) \<and> P) = (0 <= x \<and> P')"
berghofe@13876
   993
  by simp
berghofe@13876
   994
berghofe@13876
   995
use "cooper_dec.ML"
berghofe@13876
   996
use "cooper_proof.ML"
berghofe@13876
   997
use "qelim.ML"
berghofe@13876
   998
use "presburger.ML"
berghofe@13876
   999
berghofe@13876
  1000
setup "Presburger.setup"
berghofe@13876
  1001
berghofe@13876
  1002
end