src/HOL/Presburger.thy
author wenzelm
Thu May 31 13:00:56 2007 +0200 (2007-05-31)
changeset 23148 ef3fa1386102
parent 23146 0bc590051d95
child 23164 69e55066dbca
permissions -rw-r--r--
fixed title;
wenzelm@23148
     1
(*  Title:      HOL/Presburger.thy
berghofe@13876
     2
    ID:         $Id$
berghofe@13876
     3
    Author:     Amine Chaieb, Tobias Nipkow and Stefan Berghofer, TU Muenchen
berghofe@13876
     4
berghofe@13876
     5
File containing necessary theorems for the proof
berghofe@13876
     6
generation for Cooper Algorithm  
berghofe@13876
     7
*)
berghofe@13876
     8
nipkow@15131
     9
header {* Presburger Arithmetic: Cooper's Algorithm *}
wenzelm@14577
    10
nipkow@15131
    11
theory Presburger
wenzelm@23146
    12
imports "Integ/NatSimprocs" SetInterval
haftmann@21046
    13
uses
wenzelm@23146
    14
  ("Tools/Presburger/cooper_dec.ML")
wenzelm@23146
    15
  ("Tools/Presburger/cooper_proof.ML")
wenzelm@23146
    16
  ("Tools/Presburger/qelim.ML") 
wenzelm@23146
    17
  ("Tools/Presburger/reflected_presburger.ML")
wenzelm@23146
    18
  ("Tools/Presburger/reflected_cooper.ML")
wenzelm@23146
    19
  ("Tools/Presburger/presburger.ML")
nipkow@15131
    20
begin
berghofe@13876
    21
wenzelm@14577
    22
text {* Theorem for unitifying the coeffitients of @{text x} in an existential formula*}
berghofe@13876
    23
berghofe@13876
    24
theorem unity_coeff_ex: "(\<exists>x::int. P (l * x)) = (\<exists>x. l dvd (1*x+0) \<and> P x)"
berghofe@13876
    25
  apply (rule iffI)
berghofe@13876
    26
  apply (erule exE)
berghofe@13876
    27
  apply (rule_tac x = "l * x" in exI)
berghofe@13876
    28
  apply simp
berghofe@13876
    29
  apply (erule exE)
berghofe@13876
    30
  apply (erule conjE)
berghofe@13876
    31
  apply (erule dvdE)
berghofe@13876
    32
  apply (rule_tac x = k in exI)
berghofe@13876
    33
  apply simp
berghofe@13876
    34
  done
berghofe@13876
    35
berghofe@13876
    36
lemma uminus_dvd_conv: "(d dvd (t::int)) = (-d dvd t)"
berghofe@13876
    37
apply(unfold dvd_def)
berghofe@13876
    38
apply(rule iffI)
berghofe@13876
    39
apply(clarsimp)
berghofe@13876
    40
apply(rename_tac k)
berghofe@13876
    41
apply(rule_tac x = "-k" in exI)
berghofe@13876
    42
apply simp
berghofe@13876
    43
apply(clarsimp)
berghofe@13876
    44
apply(rename_tac k)
berghofe@13876
    45
apply(rule_tac x = "-k" in exI)
berghofe@13876
    46
apply simp
berghofe@13876
    47
done
berghofe@13876
    48
berghofe@13876
    49
lemma uminus_dvd_conv': "(d dvd (t::int)) = (d dvd -t)"
berghofe@13876
    50
apply(unfold dvd_def)
berghofe@13876
    51
apply(rule iffI)
berghofe@13876
    52
apply(clarsimp)
berghofe@13876
    53
apply(rule_tac x = "-k" in exI)
berghofe@13876
    54
apply simp
berghofe@13876
    55
apply(clarsimp)
berghofe@13876
    56
apply(rule_tac x = "-k" in exI)
berghofe@13876
    57
apply simp
berghofe@13876
    58
done
berghofe@13876
    59
berghofe@13876
    60
berghofe@13876
    61
wenzelm@14577
    62
text {*Theorems for the combination of proofs of the equality of @{text P} and @{text P_m} for integers @{text x} less than some integer @{text z}.*}
berghofe@13876
    63
berghofe@13876
    64
theorem eq_minf_conjI: "\<exists>z1::int. \<forall>x. x < z1 \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
berghofe@13876
    65
  \<exists>z2::int. \<forall>x. x < z2 \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
berghofe@13876
    66
  \<exists>z::int. \<forall>x. x < z \<longrightarrow> ((A1 x \<and> B1 x) = (A2 x \<and> B2 x))"
berghofe@13876
    67
  apply (erule exE)+
berghofe@13876
    68
  apply (rule_tac x = "min z1 z2" in exI)
berghofe@13876
    69
  apply simp
berghofe@13876
    70
  done
berghofe@13876
    71
berghofe@13876
    72
berghofe@13876
    73
theorem eq_minf_disjI: "\<exists>z1::int. \<forall>x. x < z1 \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
berghofe@13876
    74
  \<exists>z2::int. \<forall>x. x < z2 \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
berghofe@13876
    75
  \<exists>z::int. \<forall>x. x < z \<longrightarrow> ((A1 x \<or> B1 x) = (A2 x \<or> B2 x))"
berghofe@13876
    76
berghofe@13876
    77
  apply (erule exE)+
berghofe@13876
    78
  apply (rule_tac x = "min z1 z2" in exI)
berghofe@13876
    79
  apply simp
berghofe@13876
    80
  done
berghofe@13876
    81
berghofe@13876
    82
wenzelm@14577
    83
text {*Theorems for the combination of proofs of the equality of @{text P} and @{text P_m} for integers @{text x} greather than some integer @{text z}.*}
berghofe@13876
    84
berghofe@13876
    85
theorem eq_pinf_conjI: "\<exists>z1::int. \<forall>x. z1 < x \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
berghofe@13876
    86
  \<exists>z2::int. \<forall>x. z2 < x \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
berghofe@13876
    87
  \<exists>z::int. \<forall>x. z < x \<longrightarrow> ((A1 x \<and> B1 x) = (A2 x \<and> B2 x))"
berghofe@13876
    88
  apply (erule exE)+
berghofe@13876
    89
  apply (rule_tac x = "max z1 z2" in exI)
berghofe@13876
    90
  apply simp
berghofe@13876
    91
  done
berghofe@13876
    92
berghofe@13876
    93
berghofe@13876
    94
theorem eq_pinf_disjI: "\<exists>z1::int. \<forall>x. z1 < x \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
berghofe@13876
    95
  \<exists>z2::int. \<forall>x. z2 < x \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
berghofe@13876
    96
  \<exists>z::int. \<forall>x. z < x  \<longrightarrow> ((A1 x \<or> B1 x) = (A2 x \<or> B2 x))"
berghofe@13876
    97
  apply (erule exE)+
berghofe@13876
    98
  apply (rule_tac x = "max z1 z2" in exI)
berghofe@13876
    99
  apply simp
berghofe@13876
   100
  done
wenzelm@14577
   101
wenzelm@14577
   102
text {*
wenzelm@14577
   103
  \medskip Theorems for the combination of proofs of the modulo @{text
wenzelm@14577
   104
  D} property for @{text "P plusinfinity"}
wenzelm@14577
   105
wenzelm@14577
   106
  FIXME: This is THE SAME theorem as for the @{text minusinf} version,
wenzelm@14577
   107
  but with @{text "+k.."} instead of @{text "-k.."} In the future
wenzelm@14577
   108
  replace these both with only one. *}
berghofe@13876
   109
berghofe@13876
   110
theorem modd_pinf_conjI: "\<forall>(x::int) k. A x = A (x+k*d) \<Longrightarrow>
berghofe@13876
   111
  \<forall>(x::int) k. B x = B (x+k*d) \<Longrightarrow>
berghofe@13876
   112
  \<forall>(x::int) (k::int). (A x \<and> B x) = (A (x+k*d) \<and> B (x+k*d))"
berghofe@13876
   113
  by simp
berghofe@13876
   114
berghofe@13876
   115
theorem modd_pinf_disjI: "\<forall>(x::int) k. A x = A (x+k*d) \<Longrightarrow>
berghofe@13876
   116
  \<forall>(x::int) k. B x = B (x+k*d) \<Longrightarrow>
berghofe@13876
   117
  \<forall>(x::int) (k::int). (A x \<or> B x) = (A (x+k*d) \<or> B (x+k*d))"
berghofe@13876
   118
  by simp
berghofe@13876
   119
wenzelm@14577
   120
text {*
wenzelm@14577
   121
  This is one of the cases where the simplifed formula is prooved to
wenzelm@14577
   122
  habe some property (in relation to @{text P_m}) but we need to prove
wenzelm@14577
   123
  the property for the original formula (@{text P_m})
wenzelm@14577
   124
wenzelm@14577
   125
  FIXME: This is exaclty the same thm as for @{text minusinf}. *}
wenzelm@14577
   126
berghofe@13876
   127
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)) "
wenzelm@14577
   128
  by blast
berghofe@13876
   129
berghofe@13876
   130
wenzelm@14577
   131
text {*
wenzelm@14577
   132
  \medskip Theorems for the combination of proofs of the modulo @{text D}
wenzelm@14577
   133
  property for @{text "P minusinfinity"} *}
berghofe@13876
   134
berghofe@13876
   135
theorem modd_minf_conjI: "\<forall>(x::int) k. A x = A (x-k*d) \<Longrightarrow>
berghofe@13876
   136
  \<forall>(x::int) k. B x = B (x-k*d) \<Longrightarrow>
berghofe@13876
   137
  \<forall>(x::int) (k::int). (A x \<and> B x) = (A (x-k*d) \<and> B (x-k*d))"
berghofe@13876
   138
  by simp
berghofe@13876
   139
berghofe@13876
   140
theorem modd_minf_disjI: "\<forall>(x::int) k. A x = A (x-k*d) \<Longrightarrow>
berghofe@13876
   141
  \<forall>(x::int) k. B x = B (x-k*d) \<Longrightarrow>
berghofe@13876
   142
  \<forall>(x::int) (k::int). (A x \<or> B x) = (A (x-k*d) \<or> B (x-k*d))"
berghofe@13876
   143
  by simp
berghofe@13876
   144
wenzelm@14577
   145
text {*
wenzelm@14577
   146
  This is one of the cases where the simplifed formula is prooved to
wenzelm@14577
   147
  have some property (in relation to @{text P_m}) but we need to
wenzelm@14577
   148
  prove the property for the original formula (@{text P_m}). *}
berghofe@13876
   149
berghofe@13876
   150
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)) "
wenzelm@14577
   151
  by blast
berghofe@13876
   152
wenzelm@14577
   153
text {*
wenzelm@14577
   154
  Theorem needed for proving at runtime divide properties using the
wenzelm@14577
   155
  arithmetic tactic (which knows only about modulo = 0). *}
berghofe@13876
   156
berghofe@13876
   157
lemma zdvd_iff_zmod_eq_0: "(m dvd n) = (n mod m = (0::int))"
wenzelm@14577
   158
  by(simp add:dvd_def zmod_eq_0_iff)
berghofe@13876
   159
wenzelm@14577
   160
text {*
wenzelm@14577
   161
  \medskip Theorems used for the combination of proof for the
wenzelm@14577
   162
  backwards direction of Cooper's Theorem. They rely exclusively on
wenzelm@14577
   163
  Predicate calculus.*}
berghofe@13876
   164
berghofe@13876
   165
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
   166
==>
berghofe@13876
   167
(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
   168
==>
berghofe@13876
   169
(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))) "
wenzelm@14577
   170
  by blast
berghofe@13876
   171
berghofe@13876
   172
berghofe@13876
   173
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
   174
==>
berghofe@13876
   175
(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
   176
==>
berghofe@13876
   177
(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
   178
\<and> P2(x + d))) "
wenzelm@14577
   179
  by blast
berghofe@13876
   180
berghofe@13876
   181
lemma not_ast_p_Q_elim: "
berghofe@13876
   182
(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
   183
==> ( P = Q )
berghofe@13876
   184
==> (ALL x. ~(EX (j::int) : {1..d}. EX (a::int) : A. P(a - j)) -->P(x) --> P(x + d))"
wenzelm@14577
   185
  by blast
berghofe@13876
   186
wenzelm@14577
   187
text {*
wenzelm@14577
   188
  \medskip Theorems used for the combination of proof for the
wenzelm@14577
   189
  backwards direction of Cooper's Theorem. They rely exclusively on
wenzelm@14577
   190
  Predicate calculus.*}
berghofe@13876
   191
berghofe@13876
   192
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
   193
==>
berghofe@13876
   194
(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
   195
==>
berghofe@13876
   196
(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
   197
\<or> P2(x-d))) "
wenzelm@14577
   198
  by blast
berghofe@13876
   199
berghofe@13876
   200
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
   201
==>
berghofe@13876
   202
(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
   203
==>
berghofe@13876
   204
(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
   205
\<and> P2(x-d))) "
wenzelm@14577
   206
  by blast
berghofe@13876
   207
berghofe@13876
   208
lemma not_bst_p_Q_elim: "
berghofe@13876
   209
(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
   210
==> ( P = Q )
berghofe@13876
   211
==> (ALL x. ~(EX (j::int) : {1..d}. EX (b::int) : B. P(b+j)) -->P(x) --> P(x - d))"
wenzelm@14577
   212
  by blast
berghofe@13876
   213
wenzelm@14577
   214
text {* \medskip This is the first direction of Cooper's Theorem. *}
berghofe@13876
   215
lemma cooper_thm: "(R --> (EX x::int. P x))  ==> (Q -->(EX x::int.  P x )) ==> ((R|Q) --> (EX x::int. P x )) "
wenzelm@14577
   216
  by blast
berghofe@13876
   217
wenzelm@14577
   218
text {*
wenzelm@14577
   219
  \medskip The full Cooper's Theorem in its equivalence Form. Given
wenzelm@14577
   220
  the premises it is trivial too, it relies exclusively on prediacte calculus.*}
berghofe@13876
   221
lemma cooper_eq_thm: "(R --> (EX x::int. P x))  ==> (Q -->(EX x::int.  P x )) ==> ((~Q)
berghofe@13876
   222
--> (EX x::int. P x ) --> R) ==> (EX x::int. P x) = R|Q "
wenzelm@14577
   223
  by blast
berghofe@13876
   224
wenzelm@14577
   225
text {*
wenzelm@14577
   226
  \medskip Some of the atomic theorems generated each time the atom
wenzelm@14577
   227
  does not depend on @{text x}, they are trivial.*}
berghofe@13876
   228
berghofe@13876
   229
lemma  fm_eq_minf: "EX z::int. ALL x. x < z --> (P = P) "
wenzelm@14577
   230
  by blast
berghofe@13876
   231
berghofe@13876
   232
lemma  fm_modd_minf: "ALL (x::int). ALL (k::int). (P = P)"
wenzelm@14577
   233
  by blast
berghofe@13876
   234
berghofe@13876
   235
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"
wenzelm@14577
   236
  by blast
berghofe@13876
   237
berghofe@13876
   238
lemma  fm_eq_pinf: "EX z::int. ALL x. z < x --> (P = P) "
wenzelm@14577
   239
  by blast
berghofe@13876
   240
wenzelm@14577
   241
text {* The next two thms are the same as the @{text minusinf} version. *}
wenzelm@14577
   242
berghofe@13876
   243
lemma  fm_modd_pinf: "ALL (x::int). ALL (k::int). (P = P)"
wenzelm@14577
   244
  by blast
berghofe@13876
   245
berghofe@13876
   246
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"
wenzelm@14577
   247
  by blast
berghofe@13876
   248
wenzelm@14577
   249
text {* Theorems to be deleted from simpset when proving simplified formulaes. *}
berghofe@13876
   250
berghofe@13876
   251
lemma P_eqtrue: "(P=True) = P"
nipkow@17589
   252
  by iprover
berghofe@13876
   253
berghofe@13876
   254
lemma P_eqfalse: "(P=False) = (~P)"
nipkow@17589
   255
  by iprover
berghofe@13876
   256
wenzelm@14577
   257
text {*
wenzelm@14577
   258
  \medskip Theorems for the generation of the bachwards direction of
wenzelm@14577
   259
  Cooper's Theorem.
berghofe@13876
   260
wenzelm@14577
   261
  These are the 6 interesting atomic cases which have to be proved relying on the
wenzelm@14577
   262
  properties of B-set and the arithmetic and contradiction proofs. *}
berghofe@13876
   263
berghofe@13876
   264
lemma not_bst_p_lt: "0 < (d::int) ==>
berghofe@13876
   265
 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 )"
wenzelm@14577
   266
  by arith
berghofe@13876
   267
berghofe@13876
   268
lemma not_bst_p_gt: "\<lbrakk> (g::int) \<in> B; g = -a \<rbrakk> \<Longrightarrow>
berghofe@13876
   269
 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
   270
apply clarsimp
berghofe@13876
   271
apply(rule ccontr)
berghofe@13876
   272
apply(drule_tac x = "x+a" in bspec)
berghofe@13876
   273
apply(simp add:atLeastAtMost_iff)
berghofe@13876
   274
apply(drule_tac x = "-a" in bspec)
berghofe@13876
   275
apply assumption
berghofe@13876
   276
apply(simp)
berghofe@13876
   277
done
berghofe@13876
   278
berghofe@13876
   279
lemma not_bst_p_eq: "\<lbrakk> 0 < d; (g::int) \<in> B; g = -a - 1 \<rbrakk> \<Longrightarrow>
berghofe@13876
   280
 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
   281
apply clarsimp
berghofe@13876
   282
apply(subgoal_tac "x = -a")
berghofe@13876
   283
 prefer 2 apply arith
berghofe@13876
   284
apply(drule_tac x = "1" in bspec)
berghofe@13876
   285
apply(simp add:atLeastAtMost_iff)
berghofe@13876
   286
apply(drule_tac x = "-a- 1" in bspec)
berghofe@13876
   287
apply assumption
berghofe@13876
   288
apply(simp)
berghofe@13876
   289
done
berghofe@13876
   290
berghofe@13876
   291
berghofe@13876
   292
lemma not_bst_p_ne: "\<lbrakk> 0 < d; (g::int) \<in> B; g = -a \<rbrakk> \<Longrightarrow>
berghofe@13876
   293
 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
   294
apply clarsimp
berghofe@13876
   295
apply(subgoal_tac "x = -a+d")
berghofe@13876
   296
 prefer 2 apply arith
berghofe@13876
   297
apply(drule_tac x = "d" in bspec)
berghofe@13876
   298
apply(simp add:atLeastAtMost_iff)
berghofe@13876
   299
apply(drule_tac x = "-a" in bspec)
berghofe@13876
   300
apply assumption
berghofe@13876
   301
apply(simp)
berghofe@13876
   302
done
berghofe@13876
   303
berghofe@13876
   304
berghofe@13876
   305
lemma not_bst_p_dvd: "(d1::int) dvd d ==>
berghofe@13876
   306
 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
   307
apply(clarsimp simp add:dvd_def)
berghofe@13876
   308
apply(rename_tac m)
berghofe@13876
   309
apply(rule_tac x = "m - k" in exI)
berghofe@13876
   310
apply(simp add:int_distrib)
berghofe@13876
   311
done
berghofe@13876
   312
berghofe@13876
   313
lemma not_bst_p_ndvd: "(d1::int) dvd d ==>
berghofe@13876
   314
 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
   315
apply(clarsimp simp add:dvd_def)
berghofe@13876
   316
apply(rename_tac m)
berghofe@13876
   317
apply(erule_tac x = "m + k" in allE)
berghofe@13876
   318
apply(simp add:int_distrib)
berghofe@13876
   319
done
berghofe@13876
   320
wenzelm@14577
   321
text {*
wenzelm@14577
   322
  \medskip Theorems for the generation of the bachwards direction of
wenzelm@14577
   323
  Cooper's Theorem.
berghofe@13876
   324
wenzelm@14577
   325
  These are the 6 interesting atomic cases which have to be proved
wenzelm@14577
   326
  relying on the properties of A-set ant the arithmetic and
wenzelm@14577
   327
  contradiction proofs. *}
berghofe@13876
   328
berghofe@13876
   329
lemma not_ast_p_gt: "0 < (d::int) ==>
berghofe@13876
   330
 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 )"
wenzelm@14577
   331
  by arith
berghofe@13876
   332
berghofe@13876
   333
lemma not_ast_p_lt: "\<lbrakk>0 < d ;(t::int) \<in> A \<rbrakk> \<Longrightarrow>
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
  apply clarsimp
berghofe@13876
   336
  apply (rule ccontr)
berghofe@13876
   337
  apply (drule_tac x = "t-x" in bspec)
berghofe@13876
   338
  apply simp
berghofe@13876
   339
  apply (drule_tac x = "t" in bspec)
berghofe@13876
   340
  apply assumption
berghofe@13876
   341
  apply simp
berghofe@13876
   342
  done
berghofe@13876
   343
berghofe@13876
   344
lemma not_ast_p_eq: "\<lbrakk> 0 < d; (g::int) \<in> A; g = -t + 1 \<rbrakk> \<Longrightarrow>
berghofe@13876
   345
 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
   346
  apply clarsimp
berghofe@13876
   347
  apply (drule_tac x="1" in bspec)
berghofe@13876
   348
  apply simp
berghofe@13876
   349
  apply (drule_tac x="- t + 1" in bspec)
berghofe@13876
   350
  apply assumption
berghofe@13876
   351
  apply(subgoal_tac "x = -t")
berghofe@13876
   352
  prefer 2 apply arith
berghofe@13876
   353
  apply simp
berghofe@13876
   354
  done
berghofe@13876
   355
berghofe@13876
   356
lemma not_ast_p_ne: "\<lbrakk> 0 < d; (g::int) \<in> A; g = -t \<rbrakk> \<Longrightarrow>
berghofe@13876
   357
 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
   358
  apply clarsimp
berghofe@13876
   359
  apply (subgoal_tac "x = -t-d")
berghofe@13876
   360
  prefer 2 apply arith
berghofe@13876
   361
  apply (drule_tac x = "d" in bspec)
berghofe@13876
   362
  apply simp
berghofe@13876
   363
  apply (drule_tac x = "-t" in bspec)
berghofe@13876
   364
  apply assumption
berghofe@13876
   365
  apply simp
berghofe@13876
   366
  done
berghofe@13876
   367
berghofe@13876
   368
lemma not_ast_p_dvd: "(d1::int) dvd d ==>
berghofe@13876
   369
 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
   370
  apply(clarsimp simp add:dvd_def)
berghofe@13876
   371
  apply(rename_tac m)
berghofe@13876
   372
  apply(rule_tac x = "m + k" in exI)
berghofe@13876
   373
  apply(simp add:int_distrib)
berghofe@13876
   374
  done
berghofe@13876
   375
berghofe@13876
   376
lemma not_ast_p_ndvd: "(d1::int) dvd d ==>
berghofe@13876
   377
 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
   378
  apply(clarsimp simp add:dvd_def)
berghofe@13876
   379
  apply(rename_tac m)
berghofe@13876
   380
  apply(erule_tac x = "m - k" in allE)
berghofe@13876
   381
  apply(simp add:int_distrib)
berghofe@13876
   382
  done
berghofe@13876
   383
wenzelm@14577
   384
text {*
wenzelm@14577
   385
  \medskip These are the atomic cases for the proof generation for the
wenzelm@14577
   386
  modulo @{text D} property for @{text "P plusinfinity"}
berghofe@13876
   387
wenzelm@14577
   388
  They are fully based on arithmetics. *}
berghofe@13876
   389
berghofe@13876
   390
lemma  dvd_modd_pinf: "((d::int) dvd d1) ==>
berghofe@13876
   391
 (ALL (x::int). ALL (k::int). (((d::int) dvd (x + t)) = (d dvd (x+k*d1 + t))))"
berghofe@13876
   392
  apply(clarsimp simp add:dvd_def)
berghofe@13876
   393
  apply(rule iffI)
berghofe@13876
   394
  apply(clarsimp)
berghofe@13876
   395
  apply(rename_tac n m)
berghofe@13876
   396
  apply(rule_tac x = "m + n*k" in exI)
berghofe@13876
   397
  apply(simp add:int_distrib)
berghofe@13876
   398
  apply(clarsimp)
berghofe@13876
   399
  apply(rename_tac n m)
berghofe@13876
   400
  apply(rule_tac x = "m - n*k" in exI)
paulson@14271
   401
  apply(simp add:int_distrib mult_ac)
berghofe@13876
   402
  done
berghofe@13876
   403
berghofe@13876
   404
lemma  not_dvd_modd_pinf: "((d::int) dvd d1) ==>
berghofe@13876
   405
 (ALL (x::int). ALL k. (~((d::int) dvd (x + t))) = (~(d dvd (x+k*d1 + t))))"
berghofe@13876
   406
  apply(clarsimp simp add:dvd_def)
berghofe@13876
   407
  apply(rule iffI)
berghofe@13876
   408
  apply(clarsimp)
berghofe@13876
   409
  apply(rename_tac n m)
berghofe@13876
   410
  apply(erule_tac x = "m - n*k" in allE)
paulson@14271
   411
  apply(simp add:int_distrib mult_ac)
berghofe@13876
   412
  apply(clarsimp)
berghofe@13876
   413
  apply(rename_tac n m)
berghofe@13876
   414
  apply(erule_tac x = "m + n*k" in allE)
paulson@14271
   415
  apply(simp add:int_distrib mult_ac)
berghofe@13876
   416
  done
berghofe@13876
   417
wenzelm@14577
   418
text {*
wenzelm@14577
   419
  \medskip These are the atomic cases for the proof generation for the
wenzelm@14577
   420
  equivalence of @{text P} and @{text "P plusinfinity"} for integers
wenzelm@14577
   421
  @{text x} greater than some integer @{text z}.
wenzelm@14577
   422
wenzelm@14577
   423
  They are fully based on arithmetics. *}
berghofe@13876
   424
berghofe@13876
   425
lemma  eq_eq_pinf: "EX z::int. ALL x. z < x --> (( 0 = x +t ) = False )"
berghofe@13876
   426
  apply(rule_tac x = "-t" in exI)
berghofe@13876
   427
  apply simp
berghofe@13876
   428
  done
berghofe@13876
   429
berghofe@13876
   430
lemma  neq_eq_pinf: "EX z::int. ALL x.  z < x --> ((~( 0 = x +t )) = True )"
berghofe@13876
   431
  apply(rule_tac x = "-t" in exI)
berghofe@13876
   432
  apply simp
berghofe@13876
   433
  done
berghofe@13876
   434
berghofe@13876
   435
lemma  le_eq_pinf: "EX z::int. ALL x.  z < x --> ( 0 < x +t  = True )"
berghofe@13876
   436
  apply(rule_tac x = "-t" in exI)
berghofe@13876
   437
  apply simp
berghofe@13876
   438
  done
berghofe@13876
   439
berghofe@13876
   440
lemma  len_eq_pinf: "EX z::int. ALL x. z < x  --> (0 < -x +t  = False )"
berghofe@13876
   441
  apply(rule_tac x = "t" in exI)
berghofe@13876
   442
  apply simp
berghofe@13876
   443
  done
berghofe@13876
   444
berghofe@13876
   445
lemma  dvd_eq_pinf: "EX z::int. ALL x.  z < x --> ((d dvd (x + t)) = (d dvd (x + t))) "
wenzelm@14577
   446
  by simp
berghofe@13876
   447
berghofe@13876
   448
lemma  not_dvd_eq_pinf: "EX z::int. ALL x. z < x  --> ((~(d dvd (x + t))) = (~(d dvd (x + t)))) "
wenzelm@14577
   449
  by simp
berghofe@13876
   450
wenzelm@14577
   451
text {*
wenzelm@14577
   452
  \medskip These are the atomic cases for the proof generation for the
wenzelm@14577
   453
  modulo @{text D} property for @{text "P minusinfinity"}.
wenzelm@14577
   454
wenzelm@14577
   455
  They are fully based on arithmetics. *}
berghofe@13876
   456
berghofe@13876
   457
lemma  dvd_modd_minf: "((d::int) dvd d1) ==>
berghofe@13876
   458
 (ALL (x::int). ALL (k::int). (((d::int) dvd (x + t)) = (d dvd (x-k*d1 + t))))"
berghofe@13876
   459
apply(clarsimp simp add:dvd_def)
berghofe@13876
   460
apply(rule iffI)
berghofe@13876
   461
apply(clarsimp)
berghofe@13876
   462
apply(rename_tac n m)
berghofe@13876
   463
apply(rule_tac x = "m - n*k" in exI)
berghofe@13876
   464
apply(simp add:int_distrib)
berghofe@13876
   465
apply(clarsimp)
berghofe@13876
   466
apply(rename_tac n m)
berghofe@13876
   467
apply(rule_tac x = "m + n*k" in exI)
paulson@14271
   468
apply(simp add:int_distrib mult_ac)
berghofe@13876
   469
done
berghofe@13876
   470
berghofe@13876
   471
berghofe@13876
   472
lemma  not_dvd_modd_minf: "((d::int) dvd d1) ==>
berghofe@13876
   473
 (ALL (x::int). ALL k. (~((d::int) dvd (x + t))) = (~(d dvd (x-k*d1 + t))))"
berghofe@13876
   474
apply(clarsimp simp add:dvd_def)
berghofe@13876
   475
apply(rule iffI)
berghofe@13876
   476
apply(clarsimp)
berghofe@13876
   477
apply(rename_tac n m)
berghofe@13876
   478
apply(erule_tac x = "m + n*k" in allE)
paulson@14271
   479
apply(simp add:int_distrib mult_ac)
berghofe@13876
   480
apply(clarsimp)
berghofe@13876
   481
apply(rename_tac n m)
berghofe@13876
   482
apply(erule_tac x = "m - n*k" in allE)
paulson@14271
   483
apply(simp add:int_distrib mult_ac)
berghofe@13876
   484
done
berghofe@13876
   485
wenzelm@14577
   486
text {*
wenzelm@14577
   487
  \medskip These are the atomic cases for the proof generation for the
wenzelm@14577
   488
  equivalence of @{text P} and @{text "P minusinfinity"} for integers
wenzelm@14577
   489
  @{text x} less than some integer @{text z}.
berghofe@13876
   490
wenzelm@14577
   491
  They are fully based on arithmetics. *}
berghofe@13876
   492
berghofe@13876
   493
lemma  eq_eq_minf: "EX z::int. ALL x. x < z --> (( 0 = x +t ) = False )"
berghofe@13876
   494
apply(rule_tac x = "-t" in exI)
berghofe@13876
   495
apply simp
berghofe@13876
   496
done
berghofe@13876
   497
berghofe@13876
   498
lemma  neq_eq_minf: "EX z::int. ALL x. x < z --> ((~( 0 = x +t )) = True )"
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  le_eq_minf: "EX z::int. ALL x. x < z --> ( 0 < x +t  = False )"
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
berghofe@13876
   509
lemma  len_eq_minf: "EX z::int. ALL x. x < z --> (0 < -x +t  = True )"
berghofe@13876
   510
apply(rule_tac x = "t" in exI)
berghofe@13876
   511
apply simp
berghofe@13876
   512
done
berghofe@13876
   513
berghofe@13876
   514
lemma  dvd_eq_minf: "EX z::int. ALL x. x < z --> ((d dvd (x + t)) = (d dvd (x + t))) "
wenzelm@14577
   515
  by simp
berghofe@13876
   516
berghofe@13876
   517
lemma  not_dvd_eq_minf: "EX z::int. ALL x. x < z --> ((~(d dvd (x + t))) = (~(d dvd (x + t)))) "
wenzelm@14577
   518
  by simp
berghofe@13876
   519
wenzelm@14577
   520
text {*
wenzelm@14577
   521
  \medskip This Theorem combines whithnesses about @{text "P
wenzelm@14577
   522
  minusinfinity"} to show one component of the equivalence proof for
wenzelm@14577
   523
  Cooper's Theorem.
berghofe@13876
   524
wenzelm@14577
   525
  FIXME: remove once they are part of the distribution. *}
wenzelm@14577
   526
berghofe@13876
   527
theorem int_ge_induct[consumes 1,case_names base step]:
berghofe@13876
   528
  assumes ge: "k \<le> (i::int)" and
berghofe@13876
   529
        base: "P(k)" and
berghofe@13876
   530
        step: "\<And>i. \<lbrakk>k \<le> i; P i\<rbrakk> \<Longrightarrow> P(i+1)"
berghofe@13876
   531
  shows "P i"
berghofe@13876
   532
proof -
berghofe@13876
   533
  { fix n have "\<And>i::int. n = nat(i-k) \<Longrightarrow> k <= i \<Longrightarrow> P i"
berghofe@13876
   534
    proof (induct n)
berghofe@13876
   535
      case 0
berghofe@13876
   536
      hence "i = k" by arith
berghofe@13876
   537
      thus "P i" using base by simp
berghofe@13876
   538
    next
berghofe@13876
   539
      case (Suc n)
berghofe@13876
   540
      hence "n = nat((i - 1) - k)" by arith
berghofe@13876
   541
      moreover
berghofe@13876
   542
      have ki1: "k \<le> i - 1" using Suc.prems by arith
berghofe@13876
   543
      ultimately
berghofe@13876
   544
      have "P(i - 1)" by(rule Suc.hyps)
berghofe@13876
   545
      from step[OF ki1 this] show ?case by simp
berghofe@13876
   546
    qed
berghofe@13876
   547
  }
berghofe@13876
   548
  from this ge show ?thesis by fast
berghofe@13876
   549
qed
berghofe@13876
   550
berghofe@13876
   551
theorem int_gr_induct[consumes 1,case_names base step]:
berghofe@13876
   552
  assumes gr: "k < (i::int)" and
berghofe@13876
   553
        base: "P(k+1)" and
berghofe@13876
   554
        step: "\<And>i. \<lbrakk>k < i; P i\<rbrakk> \<Longrightarrow> P(i+1)"
berghofe@13876
   555
  shows "P i"
berghofe@13876
   556
apply(rule int_ge_induct[of "k + 1"])
berghofe@13876
   557
  using gr apply arith
berghofe@13876
   558
 apply(rule base)
berghofe@13876
   559
apply(rule step)
berghofe@13876
   560
 apply simp+
berghofe@13876
   561
done
berghofe@13876
   562
berghofe@13876
   563
lemma decr_lemma: "0 < (d::int) \<Longrightarrow> x - (abs(x-z)+1) * d < z"
berghofe@13876
   564
apply(induct rule: int_gr_induct)
berghofe@13876
   565
 apply simp
berghofe@13876
   566
apply (simp add:int_distrib)
berghofe@13876
   567
done
berghofe@13876
   568
berghofe@13876
   569
lemma incr_lemma: "0 < (d::int) \<Longrightarrow> z < x + (abs(x-z)+1) * d"
berghofe@13876
   570
apply(induct rule: int_gr_induct)
berghofe@13876
   571
 apply simp
berghofe@13876
   572
apply (simp add:int_distrib)
berghofe@13876
   573
done
berghofe@13876
   574
berghofe@13876
   575
lemma  minusinfinity:
berghofe@13876
   576
  assumes "0 < d" and
berghofe@13876
   577
    P1eqP1: "ALL x k. P1 x = P1(x - k*d)" and
berghofe@13876
   578
    ePeqP1: "EX z::int. ALL x. x < z \<longrightarrow> (P x = P1 x)"
berghofe@13876
   579
  shows "(EX x. P1 x) \<longrightarrow> (EX x. P x)"
berghofe@13876
   580
proof
berghofe@13876
   581
  assume eP1: "EX x. P1 x"
berghofe@13876
   582
  then obtain x where P1: "P1 x" ..
berghofe@13876
   583
  from ePeqP1 obtain z where P1eqP: "ALL x. x < z \<longrightarrow> (P x = P1 x)" ..
berghofe@13876
   584
  let ?w = "x - (abs(x-z)+1) * d"
berghofe@13876
   585
  show "EX x. P x"
berghofe@13876
   586
  proof
berghofe@13876
   587
    have w: "?w < z" by(rule decr_lemma)
berghofe@13876
   588
    have "P1 x = P1 ?w" using P1eqP1 by blast
berghofe@13876
   589
    also have "\<dots> = P(?w)" using w P1eqP by blast
berghofe@13876
   590
    finally show "P ?w" using P1 by blast
berghofe@13876
   591
  qed
berghofe@13876
   592
qed
berghofe@13876
   593
wenzelm@14577
   594
text {*
wenzelm@14577
   595
  \medskip This Theorem combines whithnesses about @{text "P
wenzelm@14577
   596
  minusinfinity"} to show one component of the equivalence proof for
wenzelm@14577
   597
  Cooper's Theorem. *}
berghofe@13876
   598
berghofe@13876
   599
lemma plusinfinity:
berghofe@13876
   600
  assumes "0 < d" and
berghofe@13876
   601
    P1eqP1: "ALL (x::int) (k::int). P1 x = P1 (x + k * d)" and
berghofe@13876
   602
    ePeqP1: "EX z::int. ALL x. z < x  --> (P x = P1 x)"
berghofe@13876
   603
  shows "(EX x::int. P1 x) --> (EX x::int. P x)"
berghofe@13876
   604
proof
berghofe@13876
   605
  assume eP1: "EX x. P1 x"
berghofe@13876
   606
  then obtain x where P1: "P1 x" ..
berghofe@13876
   607
  from ePeqP1 obtain z where P1eqP: "ALL x. z < x \<longrightarrow> (P x = P1 x)" ..
berghofe@13876
   608
  let ?w = "x + (abs(x-z)+1) * d"
berghofe@13876
   609
  show "EX x. P x"
berghofe@13876
   610
  proof
berghofe@13876
   611
    have w: "z < ?w" by(rule incr_lemma)
berghofe@13876
   612
    have "P1 x = P1 ?w" using P1eqP1 by blast
berghofe@13876
   613
    also have "\<dots> = P(?w)" using w P1eqP by blast
berghofe@13876
   614
    finally show "P ?w" using P1 by blast
berghofe@13876
   615
  qed
berghofe@13876
   616
qed
berghofe@13876
   617
 
wenzelm@14577
   618
text {*
wenzelm@14577
   619
  \medskip Theorem for periodic function on discrete sets. *}
berghofe@13876
   620
berghofe@13876
   621
lemma minf_vee:
berghofe@13876
   622
  assumes dpos: "(0::int) < d" and modd: "ALL x k. P x = P(x - k*d)"
berghofe@13876
   623
  shows "(EX x. P x) = (EX j : {1..d}. P j)"
berghofe@13876
   624
  (is "?LHS = ?RHS")
berghofe@13876
   625
proof
berghofe@13876
   626
  assume ?LHS
berghofe@13876
   627
  then obtain x where P: "P x" ..
berghofe@13876
   628
  have "x mod d = x - (x div d)*d"
paulson@14271
   629
    by(simp add:zmod_zdiv_equality mult_ac eq_diff_eq)
berghofe@13876
   630
  hence Pmod: "P x = P(x mod d)" using modd by simp
berghofe@13876
   631
  show ?RHS
berghofe@13876
   632
  proof (cases)
berghofe@13876
   633
    assume "x mod d = 0"
berghofe@13876
   634
    hence "P 0" using P Pmod by simp
berghofe@13876
   635
    moreover have "P 0 = P(0 - (-1)*d)" using modd by blast
berghofe@13876
   636
    ultimately have "P d" by simp
berghofe@13876
   637
    moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
berghofe@13876
   638
    ultimately show ?RHS ..
berghofe@13876
   639
  next
berghofe@13876
   640
    assume not0: "x mod d \<noteq> 0"
berghofe@13876
   641
    have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
berghofe@13876
   642
    moreover have "x mod d : {1..d}"
berghofe@13876
   643
    proof -
berghofe@13876
   644
      have "0 \<le> x mod d" by(rule pos_mod_sign)
berghofe@13876
   645
      moreover have "x mod d < d" by(rule pos_mod_bound)
berghofe@13876
   646
      ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
berghofe@13876
   647
    qed
berghofe@13876
   648
    ultimately show ?RHS ..
berghofe@13876
   649
  qed
berghofe@13876
   650
next
berghofe@13876
   651
  assume ?RHS thus ?LHS by blast
berghofe@13876
   652
qed
berghofe@13876
   653
wenzelm@14577
   654
text {*
wenzelm@14577
   655
  \medskip Theorem for periodic function on discrete sets. *}
wenzelm@14577
   656
berghofe@13876
   657
lemma pinf_vee:
berghofe@13876
   658
  assumes dpos: "0 < (d::int)" and modd: "ALL (x::int) (k::int). P x = P (x+k*d)"
berghofe@13876
   659
  shows "(EX x::int. P x) = (EX (j::int) : {1..d} . P j)"
berghofe@13876
   660
  (is "?LHS = ?RHS")
berghofe@13876
   661
proof
berghofe@13876
   662
  assume ?LHS
berghofe@13876
   663
  then obtain x where P: "P x" ..
berghofe@13876
   664
  have "x mod d = x + (-(x div d))*d"
paulson@14271
   665
    by(simp add:zmod_zdiv_equality mult_ac eq_diff_eq)
berghofe@13876
   666
  hence Pmod: "P x = P(x mod d)" using modd by (simp only:)
berghofe@13876
   667
  show ?RHS
berghofe@13876
   668
  proof (cases)
berghofe@13876
   669
    assume "x mod d = 0"
berghofe@13876
   670
    hence "P 0" using P Pmod by simp
berghofe@13876
   671
    moreover have "P 0 = P(0 + 1*d)" using modd by blast
berghofe@13876
   672
    ultimately have "P d" by simp
berghofe@13876
   673
    moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
berghofe@13876
   674
    ultimately show ?RHS ..
berghofe@13876
   675
  next
berghofe@13876
   676
    assume not0: "x mod d \<noteq> 0"
berghofe@13876
   677
    have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
berghofe@13876
   678
    moreover have "x mod d : {1..d}"
berghofe@13876
   679
    proof -
berghofe@13876
   680
      have "0 \<le> x mod d" by(rule pos_mod_sign)
berghofe@13876
   681
      moreover have "x mod d < d" by(rule pos_mod_bound)
berghofe@13876
   682
      ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
berghofe@13876
   683
    qed
berghofe@13876
   684
    ultimately show ?RHS ..
berghofe@13876
   685
  qed
berghofe@13876
   686
next
berghofe@13876
   687
  assume ?RHS thus ?LHS by blast
berghofe@13876
   688
qed
berghofe@13876
   689
berghofe@13876
   690
lemma decr_mult_lemma:
berghofe@13876
   691
  assumes dpos: "(0::int) < d" and
berghofe@13876
   692
          minus: "ALL x::int. P x \<longrightarrow> P(x - d)" and
berghofe@13876
   693
          knneg: "0 <= k"
berghofe@13876
   694
  shows "ALL x. P x \<longrightarrow> P(x - k*d)"
berghofe@13876
   695
using knneg
berghofe@13876
   696
proof (induct rule:int_ge_induct)
berghofe@13876
   697
  case base thus ?case by simp
berghofe@13876
   698
next
berghofe@13876
   699
  case (step i)
berghofe@13876
   700
  show ?case
berghofe@13876
   701
  proof
berghofe@13876
   702
    fix x
berghofe@13876
   703
    have "P x \<longrightarrow> P (x - i * d)" using step.hyps by blast
berghofe@13876
   704
    also have "\<dots> \<longrightarrow> P(x - (i + 1) * d)"
berghofe@13876
   705
      using minus[THEN spec, of "x - i * d"]
obua@14738
   706
      by (simp add:int_distrib OrderedGroup.diff_diff_eq[symmetric])
berghofe@13876
   707
    ultimately show "P x \<longrightarrow> P(x - (i + 1) * d)" by blast
berghofe@13876
   708
  qed
berghofe@13876
   709
qed
berghofe@13876
   710
berghofe@13876
   711
lemma incr_mult_lemma:
berghofe@13876
   712
  assumes dpos: "(0::int) < d" and
berghofe@13876
   713
          plus: "ALL x::int. P x \<longrightarrow> P(x + d)" and
berghofe@13876
   714
          knneg: "0 <= k"
berghofe@13876
   715
  shows "ALL x. P x \<longrightarrow> P(x + k*d)"
berghofe@13876
   716
using knneg
berghofe@13876
   717
proof (induct rule:int_ge_induct)
berghofe@13876
   718
  case base thus ?case by simp
berghofe@13876
   719
next
berghofe@13876
   720
  case (step i)
berghofe@13876
   721
  show ?case
berghofe@13876
   722
  proof
berghofe@13876
   723
    fix x
berghofe@13876
   724
    have "P x \<longrightarrow> P (x + i * d)" using step.hyps by blast
berghofe@13876
   725
    also have "\<dots> \<longrightarrow> P(x + (i + 1) * d)"
berghofe@13876
   726
      using plus[THEN spec, of "x + i * d"]
berghofe@13876
   727
      by (simp add:int_distrib zadd_ac)
berghofe@13876
   728
    ultimately show "P x \<longrightarrow> P(x + (i + 1) * d)" by blast
berghofe@13876
   729
  qed
berghofe@13876
   730
qed
berghofe@13876
   731
berghofe@13876
   732
lemma cpmi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. x < z --> (P x = P1 x))
berghofe@13876
   733
==> ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D) 
berghofe@13876
   734
==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x-k*D))))
berghofe@13876
   735
==> (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
   736
apply(rule iffI)
berghofe@13876
   737
prefer 2
berghofe@13876
   738
apply(drule minusinfinity)
berghofe@13876
   739
apply assumption+
berghofe@13876
   740
apply(fastsimp)
berghofe@13876
   741
apply clarsimp
berghofe@13876
   742
apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x - k*D)")
berghofe@13876
   743
apply(frule_tac x = x and z=z in decr_lemma)
berghofe@13876
   744
apply(subgoal_tac "P1(x - (\<bar>x - z\<bar> + 1) * D)")
berghofe@13876
   745
prefer 2
berghofe@13876
   746
apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
berghofe@13876
   747
prefer 2 apply arith
berghofe@13876
   748
 apply fastsimp
berghofe@13876
   749
apply(drule (1) minf_vee)
berghofe@13876
   750
apply blast
berghofe@13876
   751
apply(blast dest:decr_mult_lemma)
berghofe@13876
   752
done
berghofe@13876
   753
wenzelm@14577
   754
text {* Cooper Theorem, plus infinity version. *}
berghofe@13876
   755
lemma cppi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. z < x --> (P x = P1 x))
berghofe@13876
   756
==> ALL x.~(EX (j::int) : {1..D}. EX (a::int) : A. P(a - j)) --> P (x) --> P (x + D) 
berghofe@13876
   757
==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x+k*D))))
berghofe@13876
   758
==> (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
   759
  apply(rule iffI)
berghofe@13876
   760
  prefer 2
berghofe@13876
   761
  apply(drule plusinfinity)
berghofe@13876
   762
  apply assumption+
berghofe@13876
   763
  apply(fastsimp)
berghofe@13876
   764
  apply clarsimp
berghofe@13876
   765
  apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x + k*D)")
berghofe@13876
   766
  apply(frule_tac x = x and z=z in incr_lemma)
berghofe@13876
   767
  apply(subgoal_tac "P1(x + (\<bar>x - z\<bar> + 1) * D)")
berghofe@13876
   768
  prefer 2
berghofe@13876
   769
  apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
berghofe@13876
   770
  prefer 2 apply arith
berghofe@13876
   771
  apply fastsimp
berghofe@13876
   772
  apply(drule (1) pinf_vee)
berghofe@13876
   773
  apply blast
berghofe@13876
   774
  apply(blast dest:incr_mult_lemma)
berghofe@13876
   775
  done
berghofe@13876
   776
berghofe@13876
   777
wenzelm@14577
   778
text {*
wenzelm@14577
   779
  \bigskip Theorems for the quantifier elminination Functions. *}
berghofe@13876
   780
berghofe@13876
   781
lemma qe_ex_conj: "(EX (x::int). A x) = R
berghofe@13876
   782
		==> (EX (x::int). P x) = (Q & (EX x::int. A x))
berghofe@13876
   783
		==> (EX (x::int). P x) = (Q & R)"
berghofe@13876
   784
by blast
berghofe@13876
   785
berghofe@13876
   786
lemma qe_ex_nconj: "(EX (x::int). P x) = (True & Q)
berghofe@13876
   787
		==> (EX (x::int). P x) = Q"
berghofe@13876
   788
by blast
berghofe@13876
   789
berghofe@13876
   790
lemma qe_conjI: "P1 = P2 ==> Q1 = Q2 ==> (P1 & Q1) = (P2 & Q2)"
berghofe@13876
   791
by blast
berghofe@13876
   792
berghofe@13876
   793
lemma qe_disjI: "P1 = P2 ==> Q1 = Q2 ==> (P1 | Q1) = (P2 | Q2)"
berghofe@13876
   794
by blast
berghofe@13876
   795
berghofe@13876
   796
lemma qe_impI: "P1 = P2 ==> Q1 = Q2 ==> (P1 --> Q1) = (P2 --> Q2)"
berghofe@13876
   797
by blast
berghofe@13876
   798
berghofe@13876
   799
lemma qe_eqI: "P1 = P2 ==> Q1 = Q2 ==> (P1 = Q1) = (P2 = Q2)"
berghofe@13876
   800
by blast
berghofe@13876
   801
berghofe@13876
   802
lemma qe_Not: "P = Q ==> (~P) = (~Q)"
berghofe@13876
   803
by blast
berghofe@13876
   804
berghofe@13876
   805
lemma qe_ALL: "(EX x. ~P x) = R ==> (ALL x. P x) = (~R)"
berghofe@13876
   806
by blast
berghofe@13876
   807
wenzelm@14577
   808
text {* \bigskip Theorems for proving NNF *}
berghofe@13876
   809
berghofe@13876
   810
lemma nnf_im: "((~P) = P1) ==> (Q=Q1) ==> ((P --> Q) = (P1 | Q1))"
berghofe@13876
   811
by blast
berghofe@13876
   812
berghofe@13876
   813
lemma nnf_eq: "((P & Q) = (P1 & Q1)) ==> (((~P) & (~Q)) = (P2 & Q2)) ==> ((P = Q) = ((P1 & Q1)|(P2 & Q2)))"
berghofe@13876
   814
by blast
berghofe@13876
   815
berghofe@13876
   816
lemma nnf_nn: "(P = Q) ==> ((~~P) = Q)"
berghofe@13876
   817
  by blast
berghofe@13876
   818
lemma nnf_ncj: "((~P) = P1) ==> ((~Q) = Q1) ==> ((~(P & Q)) = (P1 | Q1))"
berghofe@13876
   819
by blast
berghofe@13876
   820
berghofe@13876
   821
lemma nnf_ndj: "((~P) = P1) ==> ((~Q) = Q1) ==> ((~(P | Q)) = (P1 & Q1))"
berghofe@13876
   822
by blast
berghofe@13876
   823
lemma nnf_nim: "(P = P1) ==> ((~Q) = Q1) ==> ((~(P --> Q)) = (P1 & Q1))"
berghofe@13876
   824
by blast
berghofe@13876
   825
lemma nnf_neq: "((P & (~Q)) = (P1 & Q1)) ==> (((~P) & Q) = (P2 & Q2)) ==> ((~(P = Q)) = ((P1 & Q1)|(P2 & Q2)))"
berghofe@13876
   826
by blast
berghofe@13876
   827
lemma nnf_sdj: "((A & (~B)) = (A1 & B1)) ==> ((C & (~D)) = (C1 & D1)) ==> (A = (~C)) ==> ((~((A & B) | (C & D))) = ((A1 & B1) | (C1 & D1)))"
berghofe@13876
   828
by blast
berghofe@13876
   829
berghofe@13876
   830
berghofe@13876
   831
lemma qe_exI2: "A = B ==> (EX (x::int). A(x)) = (EX (x::int). B(x))"
berghofe@13876
   832
  by simp
berghofe@13876
   833
berghofe@13876
   834
lemma qe_exI: "(!!x::int. A x = B x) ==> (EX (x::int). A(x)) = (EX (x::int). B(x))"
nipkow@17589
   835
  by iprover
berghofe@13876
   836
berghofe@13876
   837
lemma qe_ALLI: "(!!x::int. A x = B x) ==> (ALL (x::int). A(x)) = (ALL (x::int). B(x))"
nipkow@17589
   838
  by iprover
berghofe@13876
   839
berghofe@13876
   840
lemma cp_expand: "(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (b::int) : B. (P1 (j) | P(b+j)))
berghofe@13876
   841
==>(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (b::int) : B. (P1 (j) | P(b+j))) "
berghofe@13876
   842
by blast
berghofe@13876
   843
berghofe@13876
   844
lemma cppi_expand: "(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (a::int) : A. (P1 (j) | P(a - j)))
berghofe@13876
   845
==>(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (a::int) : A. (P1 (j) | P(a - j))) "
berghofe@13876
   846
by blast
berghofe@13876
   847
berghofe@13876
   848
berghofe@13876
   849
lemma simp_from_to: "{i..j::int} = (if j < i then {} else insert i {i+1..j})"
berghofe@13876
   850
apply(simp add:atLeastAtMost_def atLeast_def atMost_def)
berghofe@13876
   851
apply(fastsimp)
berghofe@13876
   852
done
berghofe@13876
   853
wenzelm@14577
   854
text {* \bigskip Theorems required for the @{text adjustcoeffitienteq} *}
berghofe@13876
   855
berghofe@13876
   856
lemma ac_dvd_eq: assumes not0: "0 ~= (k::int)"
berghofe@13876
   857
shows "((m::int) dvd (c*n+t)) = (k*m dvd ((k*c)*n+(k*t)))" (is "?P = ?Q")
berghofe@13876
   858
proof
berghofe@13876
   859
  assume ?P
berghofe@13876
   860
  thus ?Q
berghofe@13876
   861
    apply(simp add:dvd_def)
berghofe@13876
   862
    apply clarify
berghofe@13876
   863
    apply(rename_tac d)
berghofe@13876
   864
    apply(drule_tac f = "op * k" in arg_cong)
berghofe@13876
   865
    apply(simp only:int_distrib)
berghofe@13876
   866
    apply(rule_tac x = "d" in exI)
paulson@14271
   867
    apply(simp only:mult_ac)
berghofe@13876
   868
    done
berghofe@13876
   869
next
berghofe@13876
   870
  assume ?Q
berghofe@13876
   871
  then obtain d where "k * c * n + k * t = (k*m)*d" by(fastsimp simp:dvd_def)
paulson@14271
   872
  hence "(c * n + t) * k = (m*d) * k" by(simp add:int_distrib mult_ac)
berghofe@13876
   873
  hence "((c * n + t) * k) div k = ((m*d) * k) div k" by(rule arg_cong[of _ _ "%t. t div k"])
berghofe@13876
   874
  hence "c*n+t = m*d" by(simp add: zdiv_zmult_self1[OF not0[symmetric]])
berghofe@13876
   875
  thus ?P by(simp add:dvd_def)
berghofe@13876
   876
qed
berghofe@13876
   877
berghofe@13876
   878
lemma ac_lt_eq: assumes gr0: "0 < (k::int)"
berghofe@13876
   879
shows "((m::int) < (c*n+t)) = (k*m <((k*c)*n+(k*t)))" (is "?P = ?Q")
berghofe@13876
   880
proof
berghofe@13876
   881
  assume P: ?P
paulson@14271
   882
  show ?Q using zmult_zless_mono2[OF P gr0] by(simp add: int_distrib mult_ac)
berghofe@13876
   883
next
berghofe@13876
   884
  assume ?Q
paulson@14271
   885
  hence "0 < k*(c*n + t - m)" by(simp add: int_distrib mult_ac)
paulson@14353
   886
  with gr0 have "0 < (c*n + t - m)" by(simp add: zero_less_mult_iff)
berghofe@13876
   887
  thus ?P by(simp)
berghofe@13876
   888
qed
berghofe@13876
   889
berghofe@13876
   890
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
   891
proof
berghofe@13876
   892
  assume ?P
berghofe@13876
   893
  thus ?Q
berghofe@13876
   894
    apply(drule_tac f = "op * k" in arg_cong)
berghofe@13876
   895
    apply(simp only:int_distrib)
berghofe@13876
   896
    done
berghofe@13876
   897
next
berghofe@13876
   898
  assume ?Q
paulson@14271
   899
  hence "m * k = (c*n + t) * k" by(simp add:int_distrib mult_ac)
berghofe@13876
   900
  hence "((m) * k) div k = ((c*n + t) * k) div k" by(rule arg_cong[of _ _ "%t. t div k"])
berghofe@13876
   901
  thus ?P by(simp add: zdiv_zmult_self1[OF not0[symmetric]])
berghofe@13876
   902
qed
berghofe@13876
   903
berghofe@13876
   904
lemma ac_pi_eq: assumes gr0: "0 < (k::int)" shows "(~((0::int) < (c*n + t))) = (0 < ((-k)*c)*n + ((-k)*t + k))"
berghofe@13876
   905
proof -
berghofe@13876
   906
  have "(~ (0::int) < (c*n + t)) = (0<1-(c*n + t))" by arith
paulson@14271
   907
  also have  "(1-(c*n + t)) = (-1*c)*n + (-t+1)" by(simp add: int_distrib mult_ac)
berghofe@13876
   908
  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])
paulson@14271
   909
  also have "(k*(-1*c)*n) + (k*(-t+1)) = ((-k)*c)*n + ((-k)*t + k)" by(simp add: int_distrib mult_ac)
berghofe@13876
   910
  finally show ?thesis .
berghofe@13876
   911
qed
berghofe@13876
   912
berghofe@13876
   913
lemma binminus_uminus_conv: "(a::int) - b = a + (-b)"
berghofe@13876
   914
by arith
berghofe@13876
   915
berghofe@13876
   916
lemma  linearize_dvd: "(t::int) = t1 ==> (d dvd t) = (d dvd t1)"
berghofe@13876
   917
by simp
berghofe@13876
   918
berghofe@13876
   919
lemma lf_lt: "(l::int) = ll ==> (r::int) = lr ==> (l < r) =(ll < lr)"
berghofe@13876
   920
by simp
berghofe@13876
   921
berghofe@13876
   922
lemma lf_eq: "(l::int) = ll ==> (r::int) = lr ==> (l = r) =(ll = lr)"
berghofe@13876
   923
by simp
berghofe@13876
   924
berghofe@13876
   925
lemma lf_dvd: "(l::int) = ll ==> (r::int) = lr ==> (l dvd r) =(ll dvd lr)"
berghofe@13876
   926
by simp
berghofe@13876
   927
wenzelm@14577
   928
text {* \bigskip Theorems for transforming predicates on nat to predicates on @{text int}*}
berghofe@13876
   929
berghofe@13876
   930
theorem all_nat: "(\<forall>x::nat. P x) = (\<forall>x::int. 0 <= x \<longrightarrow> P (nat x))"
berghofe@13876
   931
  by (simp split add: split_nat)
berghofe@13876
   932
berghofe@13876
   933
berghofe@13876
   934
theorem zdiff_int_split: "P (int (x - y)) =
berghofe@13876
   935
  ((y \<le> x \<longrightarrow> P (int x - int y)) \<and> (x < y \<longrightarrow> P 0))"
berghofe@13876
   936
  apply (case_tac "y \<le> x")
berghofe@13876
   937
  apply (simp_all add: zdiff_int)
berghofe@13876
   938
  done
berghofe@13876
   939
berghofe@13876
   940
berghofe@13876
   941
theorem number_of1: "(0::int) <= number_of n \<Longrightarrow> (0::int) <= number_of (n BIT b)"
berghofe@13876
   942
  by simp
berghofe@13876
   943
paulson@15013
   944
theorem number_of2: "(0::int) <= Numeral0" by simp
berghofe@13876
   945
berghofe@13876
   946
theorem Suc_plus1: "Suc n = n + 1" by simp
berghofe@13876
   947
wenzelm@14577
   948
text {*
wenzelm@14577
   949
  \medskip Specific instances of congruence rules, to prevent
wenzelm@14577
   950
  simplifier from looping. *}
berghofe@13876
   951
chaieb@14758
   952
theorem imp_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<longrightarrow> P) = (0 <= x \<longrightarrow> P')"
berghofe@13876
   953
  by simp
berghofe@13876
   954
chaieb@14758
   955
theorem conj_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<and> P) = (0 <= x \<and> P')"
chaieb@14758
   956
  by (simp cong: conj_cong)
berghofe@13876
   957
chaieb@18202
   958
    (* Theorems used in presburger.ML for the computation simpset*)
chaieb@18202
   959
    (* FIXME: They are present in Float.thy, so may be Float.thy should be lightened.*)
chaieb@18202
   960
chaieb@18202
   961
lemma lift_bool: "x \<Longrightarrow> x=True"
chaieb@18202
   962
  by simp
chaieb@18202
   963
chaieb@18202
   964
lemma nlift_bool: "~x \<Longrightarrow> x=False"
chaieb@18202
   965
  by simp
chaieb@18202
   966
chaieb@18202
   967
lemma not_false_eq_true: "(~ False) = True" by simp
chaieb@18202
   968
chaieb@18202
   969
lemma not_true_eq_false: "(~ True) = False" by simp
chaieb@18202
   970
chaieb@18202
   971
haftmann@20485
   972
lemma int_eq_number_of_eq:
haftmann@20485
   973
  "(((number_of v)::int) = (number_of w)) = iszero ((number_of (v + (uminus w)))::int)"
chaieb@18202
   974
  by simp
chaieb@18202
   975
lemma int_iszero_number_of_Pls: "iszero (Numeral0::int)" 
chaieb@18202
   976
  by (simp only: iszero_number_of_Pls)
chaieb@18202
   977
chaieb@18202
   978
lemma int_nonzero_number_of_Min: "~(iszero ((-1)::int))"
chaieb@18202
   979
  by simp
chaieb@18202
   980
chaieb@18202
   981
lemma int_iszero_number_of_0: "iszero ((number_of (w BIT bit.B0))::int) = iszero ((number_of w)::int)"
chaieb@18202
   982
  by simp
chaieb@18202
   983
chaieb@18202
   984
lemma int_iszero_number_of_1: "\<not> iszero ((number_of (w BIT bit.B1))::int)" 
chaieb@18202
   985
  by simp
chaieb@18202
   986
haftmann@20485
   987
lemma int_less_number_of_eq_neg: "(((number_of x)::int) < number_of y) = neg ((number_of (x + (uminus y)))::int)"
chaieb@18202
   988
  by simp
chaieb@18202
   989
chaieb@18202
   990
lemma int_not_neg_number_of_Pls: "\<not> (neg (Numeral0::int))" 
chaieb@18202
   991
  by simp
chaieb@18202
   992
chaieb@18202
   993
lemma int_neg_number_of_Min: "neg (-1::int)"
chaieb@18202
   994
  by simp
chaieb@18202
   995
chaieb@18202
   996
lemma int_neg_number_of_BIT: "neg ((number_of (w BIT x))::int) = neg ((number_of w)::int)"
chaieb@18202
   997
  by simp
chaieb@18202
   998
haftmann@20485
   999
lemma int_le_number_of_eq: "(((number_of x)::int) \<le> number_of y) = (\<not> neg ((number_of (y + (uminus x)))::int))"
chaieb@18202
  1000
  by simp
haftmann@20485
  1001
lemma int_number_of_add_sym: "((number_of v)::int) + number_of w = number_of (v + w)"
chaieb@18202
  1002
  by simp
chaieb@18202
  1003
haftmann@20485
  1004
lemma int_number_of_diff_sym:
haftmann@20485
  1005
  "((number_of v)::int) - number_of w = number_of (v + (uminus w))"
chaieb@18202
  1006
  by simp
chaieb@18202
  1007
haftmann@20485
  1008
lemma int_number_of_mult_sym:
haftmann@20485
  1009
  "((number_of v)::int) * number_of w = number_of (v * w)"
chaieb@18202
  1010
  by simp
chaieb@18202
  1011
haftmann@20485
  1012
lemma int_number_of_minus_sym: "- ((number_of v)::int) = number_of (uminus v)"
chaieb@18202
  1013
  by simp
chaieb@18202
  1014
lemma add_left_zero: "0 + a = (a::'a::comm_monoid_add)"
chaieb@18202
  1015
  by simp
chaieb@18202
  1016
chaieb@18202
  1017
lemma add_right_zero: "a + 0 = (a::'a::comm_monoid_add)"
chaieb@18202
  1018
  by simp
chaieb@18202
  1019
chaieb@18202
  1020
lemma mult_left_one: "1 * a = (a::'a::semiring_1)"
chaieb@18202
  1021
  by simp
chaieb@18202
  1022
chaieb@18202
  1023
lemma mult_right_one: "a * 1 = (a::'a::semiring_1)"
chaieb@18202
  1024
  by simp
chaieb@18202
  1025
chaieb@18202
  1026
lemma int_pow_0: "(a::int)^(Numeral0) = 1"
chaieb@18202
  1027
  by simp
chaieb@18202
  1028
chaieb@18202
  1029
lemma int_pow_1: "(a::int)^(Numeral1) = a"
chaieb@18202
  1030
  by simp
chaieb@18202
  1031
chaieb@18202
  1032
lemma zero_eq_Numeral0_nring: "(0::'a::number_ring) = Numeral0"
chaieb@18202
  1033
  by simp
chaieb@18202
  1034
chaieb@18202
  1035
lemma one_eq_Numeral1_nring: "(1::'a::number_ring) = Numeral1"
chaieb@18202
  1036
  by simp
chaieb@18202
  1037
chaieb@18202
  1038
lemma zero_eq_Numeral0_nat: "(0::nat) = Numeral0"
chaieb@18202
  1039
  by simp
chaieb@18202
  1040
chaieb@18202
  1041
lemma one_eq_Numeral1_nat: "(1::nat) = Numeral1"
chaieb@18202
  1042
  by simp
chaieb@18202
  1043
chaieb@18202
  1044
lemma zpower_Pls: "(z::int)^Numeral0 = Numeral1"
chaieb@18202
  1045
  by simp
chaieb@18202
  1046
chaieb@18202
  1047
lemma zpower_Min: "(z::int)^((-1)::nat) = Numeral1"
chaieb@18202
  1048
proof -
chaieb@18202
  1049
  have 1:"((-1)::nat) = 0"
chaieb@18202
  1050
    by simp
chaieb@18202
  1051
  show ?thesis by (simp add: 1)
chaieb@18202
  1052
qed
chaieb@18202
  1053
wenzelm@23146
  1054
use "Tools/Presburger/cooper_dec.ML"
wenzelm@23146
  1055
use "Tools/Presburger/reflected_presburger.ML" 
wenzelm@23146
  1056
use "Tools/Presburger/reflected_cooper.ML"
chaieb@14941
  1057
oracle
chaieb@17378
  1058
  presburger_oracle ("term") = ReflectedCooper.presburger_oracle
chaieb@14941
  1059
wenzelm@23146
  1060
use "Tools/Presburger/cooper_proof.ML"
wenzelm@23146
  1061
use "Tools/Presburger/qelim.ML"
wenzelm@23146
  1062
use "Tools/Presburger/presburger.ML"
berghofe@13876
  1063
berghofe@13876
  1064
setup "Presburger.setup"
berghofe@13876
  1065
haftmann@22801
  1066
haftmann@22801
  1067
subsection {* Code generator setup *}
haftmann@20595
  1068
haftmann@20595
  1069
text {*
haftmann@22801
  1070
  Presburger arithmetic is convenient to prove some
haftmann@22801
  1071
  of the following code lemmas on integer numerals:
haftmann@20595
  1072
*}
haftmann@20595
  1073
haftmann@20595
  1074
lemma eq_Pls_Pls:
haftmann@22744
  1075
  "Numeral.Pls = Numeral.Pls \<longleftrightarrow> True" by rule+
haftmann@20595
  1076
haftmann@20595
  1077
lemma eq_Pls_Min:
haftmann@22744
  1078
  "Numeral.Pls = Numeral.Min \<longleftrightarrow> False"
haftmann@21454
  1079
  unfolding Pls_def Min_def by auto
haftmann@20595
  1080
haftmann@20595
  1081
lemma eq_Pls_Bit0:
haftmann@21454
  1082
  "Numeral.Pls = Numeral.Bit k bit.B0 \<longleftrightarrow> Numeral.Pls = k"
haftmann@21454
  1083
  unfolding Pls_def Bit_def bit.cases by auto
haftmann@20595
  1084
haftmann@20595
  1085
lemma eq_Pls_Bit1:
haftmann@22744
  1086
  "Numeral.Pls = Numeral.Bit k bit.B1 \<longleftrightarrow> False"
haftmann@21454
  1087
  unfolding Pls_def Bit_def bit.cases by arith
haftmann@20595
  1088
haftmann@20595
  1089
lemma eq_Min_Pls:
haftmann@22744
  1090
  "Numeral.Min = Numeral.Pls \<longleftrightarrow> False"
haftmann@21454
  1091
  unfolding Pls_def Min_def by auto
haftmann@20595
  1092
haftmann@20595
  1093
lemma eq_Min_Min:
haftmann@22744
  1094
  "Numeral.Min = Numeral.Min \<longleftrightarrow> True" by rule+
haftmann@20595
  1095
haftmann@20595
  1096
lemma eq_Min_Bit0:
haftmann@22744
  1097
  "Numeral.Min = Numeral.Bit k bit.B0 \<longleftrightarrow> False"
haftmann@21454
  1098
  unfolding Min_def Bit_def bit.cases by arith
haftmann@20595
  1099
haftmann@20595
  1100
lemma eq_Min_Bit1:
haftmann@21454
  1101
  "Numeral.Min = Numeral.Bit k bit.B1 \<longleftrightarrow> Numeral.Min = k"
haftmann@21454
  1102
  unfolding Min_def Bit_def bit.cases by auto
haftmann@20595
  1103
haftmann@20595
  1104
lemma eq_Bit0_Pls:
haftmann@21454
  1105
  "Numeral.Bit k bit.B0 = Numeral.Pls \<longleftrightarrow> Numeral.Pls = k"
haftmann@21454
  1106
  unfolding Pls_def Bit_def bit.cases by auto
haftmann@20595
  1107
haftmann@20595
  1108
lemma eq_Bit1_Pls:
haftmann@22744
  1109
  "Numeral.Bit k bit.B1 = Numeral.Pls \<longleftrightarrow> False"
haftmann@21454
  1110
  unfolding Pls_def Bit_def bit.cases by arith
haftmann@20595
  1111
haftmann@20595
  1112
lemma eq_Bit0_Min:
haftmann@22744
  1113
  "Numeral.Bit k bit.B0 = Numeral.Min \<longleftrightarrow> False"
haftmann@21454
  1114
  unfolding Min_def Bit_def bit.cases by arith
haftmann@20595
  1115
haftmann@20595
  1116
lemma eq_Bit1_Min:
haftmann@21454
  1117
  "(Numeral.Bit k bit.B1) = Numeral.Min \<longleftrightarrow> Numeral.Min = k"
haftmann@21454
  1118
  unfolding Min_def Bit_def bit.cases by auto
haftmann@20595
  1119
haftmann@20595
  1120
lemma eq_Bit_Bit:
haftmann@21454
  1121
  "Numeral.Bit k1 v1 = Numeral.Bit k2 v2 \<longleftrightarrow>
haftmann@21454
  1122
    v1 = v2 \<and> k1 = k2"
haftmann@21454
  1123
  unfolding Bit_def
haftmann@20595
  1124
  apply (cases v1)
haftmann@20595
  1125
  apply (cases v2)
haftmann@20595
  1126
  apply auto
haftmann@20595
  1127
  apply arith
haftmann@20595
  1128
  apply (cases v2)
haftmann@20595
  1129
  apply auto
haftmann@20595
  1130
  apply arith
haftmann@20595
  1131
  apply (cases v2)
haftmann@20595
  1132
  apply auto
haftmann@20595
  1133
done
haftmann@20595
  1134
haftmann@22801
  1135
lemma eq_number_of:
haftmann@22801
  1136
  "(number_of k \<Colon> int) = number_of l \<longleftrightarrow> k = l"
haftmann@22801
  1137
  unfolding number_of_is_id ..
haftmann@20595
  1138
haftmann@22394
  1139
haftmann@20595
  1140
lemma less_eq_Pls_Pls:
haftmann@22744
  1141
  "Numeral.Pls \<le> Numeral.Pls \<longleftrightarrow> True" by rule+
haftmann@20595
  1142
haftmann@20595
  1143
lemma less_eq_Pls_Min:
haftmann@22744
  1144
  "Numeral.Pls \<le> Numeral.Min \<longleftrightarrow> False"
haftmann@20595
  1145
  unfolding Pls_def Min_def by auto
haftmann@20595
  1146
haftmann@20595
  1147
lemma less_eq_Pls_Bit:
haftmann@20595
  1148
  "Numeral.Pls \<le> Numeral.Bit k v \<longleftrightarrow> Numeral.Pls \<le> k"
haftmann@20595
  1149
  unfolding Pls_def Bit_def by (cases v) auto
haftmann@20595
  1150
haftmann@20595
  1151
lemma less_eq_Min_Pls:
haftmann@22744
  1152
  "Numeral.Min \<le> Numeral.Pls \<longleftrightarrow> True"
haftmann@20595
  1153
  unfolding Pls_def Min_def by auto
haftmann@20595
  1154
haftmann@20595
  1155
lemma less_eq_Min_Min:
haftmann@22744
  1156
  "Numeral.Min \<le> Numeral.Min \<longleftrightarrow> True" by rule+
haftmann@20595
  1157
haftmann@20595
  1158
lemma less_eq_Min_Bit0:
haftmann@20595
  1159
  "Numeral.Min \<le> Numeral.Bit k bit.B0 \<longleftrightarrow> Numeral.Min < k"
haftmann@20595
  1160
  unfolding Min_def Bit_def by auto
haftmann@20595
  1161
haftmann@20595
  1162
lemma less_eq_Min_Bit1:
haftmann@20595
  1163
  "Numeral.Min \<le> Numeral.Bit k bit.B1 \<longleftrightarrow> Numeral.Min \<le> k"
haftmann@20595
  1164
  unfolding Min_def Bit_def by auto
haftmann@20595
  1165
haftmann@20595
  1166
lemma less_eq_Bit0_Pls:
haftmann@20595
  1167
  "Numeral.Bit k bit.B0 \<le> Numeral.Pls \<longleftrightarrow> k \<le> Numeral.Pls"
haftmann@20595
  1168
  unfolding Pls_def Bit_def by simp
haftmann@20595
  1169
haftmann@20595
  1170
lemma less_eq_Bit1_Pls:
haftmann@20595
  1171
  "Numeral.Bit k bit.B1 \<le> Numeral.Pls \<longleftrightarrow> k < Numeral.Pls"
haftmann@20595
  1172
  unfolding Pls_def Bit_def by auto
haftmann@20595
  1173
haftmann@20595
  1174
lemma less_eq_Bit_Min:
haftmann@20595
  1175
  "Numeral.Bit k v \<le> Numeral.Min \<longleftrightarrow> k \<le> Numeral.Min"
haftmann@20595
  1176
  unfolding Min_def Bit_def by (cases v) auto
haftmann@20595
  1177
haftmann@20595
  1178
lemma less_eq_Bit0_Bit:
haftmann@20595
  1179
  "Numeral.Bit k1 bit.B0 \<le> Numeral.Bit k2 v \<longleftrightarrow> k1 \<le> k2"
haftmann@22394
  1180
  unfolding Bit_def bit.cases by (cases v) auto
haftmann@20595
  1181
haftmann@20595
  1182
lemma less_eq_Bit_Bit1:
haftmann@20595
  1183
  "Numeral.Bit k1 v \<le> Numeral.Bit k2 bit.B1 \<longleftrightarrow> k1 \<le> k2"
haftmann@22394
  1184
  unfolding Bit_def bit.cases by (cases v) auto
haftmann@22394
  1185
haftmann@22394
  1186
lemma less_eq_Bit1_Bit0:
haftmann@22394
  1187
  "Numeral.Bit k1 bit.B1 \<le> Numeral.Bit k2 bit.B0 \<longleftrightarrow> k1 < k2"
haftmann@22394
  1188
  unfolding Bit_def by (auto split: bit.split)
haftmann@20595
  1189
haftmann@22801
  1190
lemma less_eq_number_of:
haftmann@22801
  1191
  "(number_of k \<Colon> int) \<le> number_of l \<longleftrightarrow> k \<le> l"
haftmann@22801
  1192
  unfolding number_of_is_id ..
haftmann@22394
  1193
haftmann@22394
  1194
haftmann@22394
  1195
lemma less_Pls_Pls:
haftmann@22744
  1196
  "Numeral.Pls < Numeral.Pls \<longleftrightarrow> False" by auto
haftmann@22394
  1197
haftmann@22394
  1198
lemma less_Pls_Min:
haftmann@22744
  1199
  "Numeral.Pls < Numeral.Min \<longleftrightarrow> False"
haftmann@22394
  1200
  unfolding Pls_def Min_def by auto
haftmann@22394
  1201
haftmann@22394
  1202
lemma less_Pls_Bit0:
haftmann@22394
  1203
  "Numeral.Pls < Numeral.Bit k bit.B0 \<longleftrightarrow> Numeral.Pls < k"
haftmann@22394
  1204
  unfolding Pls_def Bit_def by auto
haftmann@22394
  1205
haftmann@22394
  1206
lemma less_Pls_Bit1:
haftmann@22394
  1207
  "Numeral.Pls < Numeral.Bit k bit.B1 \<longleftrightarrow> Numeral.Pls \<le> k"
haftmann@22394
  1208
  unfolding Pls_def Bit_def by auto
haftmann@22394
  1209
haftmann@22394
  1210
lemma less_Min_Pls:
haftmann@22744
  1211
  "Numeral.Min < Numeral.Pls \<longleftrightarrow> True"
haftmann@22394
  1212
  unfolding Pls_def Min_def by auto
haftmann@22394
  1213
haftmann@22394
  1214
lemma less_Min_Min:
haftmann@22744
  1215
  "Numeral.Min < Numeral.Min \<longleftrightarrow> False" by auto
haftmann@22394
  1216
haftmann@22394
  1217
lemma less_Min_Bit:
haftmann@22394
  1218
  "Numeral.Min < Numeral.Bit k v \<longleftrightarrow> Numeral.Min < k"
haftmann@22394
  1219
  unfolding Min_def Bit_def by (auto split: bit.split)
haftmann@22394
  1220
haftmann@22394
  1221
lemma less_Bit_Pls:
haftmann@22394
  1222
  "Numeral.Bit k v < Numeral.Pls \<longleftrightarrow> k < Numeral.Pls"
haftmann@22394
  1223
  unfolding Pls_def Bit_def by (auto split: bit.split)
haftmann@22394
  1224
haftmann@22394
  1225
lemma less_Bit0_Min:
haftmann@22394
  1226
  "Numeral.Bit k bit.B0 < Numeral.Min \<longleftrightarrow> k \<le> Numeral.Min"
haftmann@22394
  1227
  unfolding Min_def Bit_def by auto
haftmann@22394
  1228
haftmann@22394
  1229
lemma less_Bit1_Min:
haftmann@22394
  1230
  "Numeral.Bit k bit.B1 < Numeral.Min \<longleftrightarrow> k < Numeral.Min"
haftmann@22394
  1231
  unfolding Min_def Bit_def by auto
haftmann@22394
  1232
haftmann@22394
  1233
lemma less_Bit_Bit0:
haftmann@22394
  1234
  "Numeral.Bit k1 v < Numeral.Bit k2 bit.B0 \<longleftrightarrow> k1 < k2"
haftmann@22394
  1235
  unfolding Bit_def by (auto split: bit.split)
haftmann@22394
  1236
haftmann@22394
  1237
lemma less_Bit1_Bit:
haftmann@22394
  1238
  "Numeral.Bit k1 bit.B1 < Numeral.Bit k2 v \<longleftrightarrow> k1 < k2"
haftmann@22394
  1239
  unfolding Bit_def by (auto split: bit.split)
haftmann@22394
  1240
haftmann@22394
  1241
lemma less_Bit0_Bit1:
haftmann@22394
  1242
  "Numeral.Bit k1 bit.B0 < Numeral.Bit k2 bit.B1 \<longleftrightarrow> k1 \<le> k2"
haftmann@22394
  1243
  unfolding Bit_def bit.cases by auto
haftmann@22394
  1244
haftmann@22801
  1245
lemma less_number_of:
haftmann@22801
  1246
  "(number_of k \<Colon> int) < number_of l \<longleftrightarrow> k < l"
haftmann@22801
  1247
  unfolding number_of_is_id ..
haftmann@22801
  1248
haftmann@22801
  1249
haftmann@22801
  1250
lemmas pred_succ_numeral_code [code func] =
haftmann@22801
  1251
  arith_simps(5-12)
haftmann@22801
  1252
haftmann@22801
  1253
lemmas plus_numeral_code [code func] =
haftmann@22801
  1254
  arith_simps(13-17)
haftmann@22801
  1255
  arith_simps(26-27)
haftmann@22801
  1256
  arith_extra_simps(1) [where 'a = int]
haftmann@22801
  1257
haftmann@22801
  1258
lemmas minus_numeral_code [code func] =
haftmann@22801
  1259
  arith_simps(18-21)
haftmann@22801
  1260
  arith_extra_simps(2) [where 'a = int]
haftmann@22801
  1261
  arith_extra_simps(5) [where 'a = int]
haftmann@22801
  1262
haftmann@22801
  1263
lemmas times_numeral_code [code func] =
haftmann@22801
  1264
  arith_simps(22-25)
haftmann@22801
  1265
  arith_extra_simps(4) [where 'a = int]
haftmann@22801
  1266
haftmann@22801
  1267
lemmas eq_numeral_code [code func] =
haftmann@22801
  1268
  eq_Pls_Pls eq_Pls_Min eq_Pls_Bit0 eq_Pls_Bit1
haftmann@22801
  1269
  eq_Min_Pls eq_Min_Min eq_Min_Bit0 eq_Min_Bit1
haftmann@22801
  1270
  eq_Bit0_Pls eq_Bit1_Pls eq_Bit0_Min eq_Bit1_Min eq_Bit_Bit
haftmann@22801
  1271
  eq_number_of
haftmann@22801
  1272
haftmann@22801
  1273
lemmas less_eq_numeral_code [code func] = less_eq_Pls_Pls less_eq_Pls_Min less_eq_Pls_Bit
haftmann@22801
  1274
  less_eq_Min_Pls less_eq_Min_Min less_eq_Min_Bit0 less_eq_Min_Bit1
haftmann@22801
  1275
  less_eq_Bit0_Pls less_eq_Bit1_Pls less_eq_Bit_Min less_eq_Bit0_Bit less_eq_Bit_Bit1 less_eq_Bit1_Bit0
haftmann@22801
  1276
  less_eq_number_of
haftmann@22801
  1277
haftmann@22394
  1278
lemmas less_numeral_code [code func] = less_Pls_Pls less_Pls_Min less_Pls_Bit0
haftmann@22394
  1279
  less_Pls_Bit1 less_Min_Pls less_Min_Min less_Min_Bit less_Bit_Pls
haftmann@22394
  1280
  less_Bit0_Min less_Bit1_Min less_Bit_Bit0 less_Bit1_Bit less_Bit0_Bit1
haftmann@22801
  1281
  less_number_of
haftmann@20595
  1282
berghofe@13876
  1283
end