src/HOL/ex/PresburgerEx.thy
author wenzelm
Sun, 01 Oct 2006 18:29:32 +0200
changeset 20813 379ce56e5dc2
parent 20663 2024d9f7df9c
child 23323 2274edb9a8b2
permissions -rw-r--r--
proper use of svc_oracle.ML;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
     1
(*  Title:      HOL/ex/PresburgerEx.thy
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
     2
    ID:         $Id$
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
     3
    Author:     Amine Chaieb, TU Muenchen
17388
495c799df31d tuned headers etc.;
wenzelm
parents: 16417
diff changeset
     4
*)
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
     5
17388
495c799df31d tuned headers etc.;
wenzelm
parents: 16417
diff changeset
     6
header {* Some examples for Presburger Arithmetic *}
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
     7
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 15075
diff changeset
     8
theory PresburgerEx imports Main begin
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
     9
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    10
theorem "(\<forall>(y::int). 3 dvd y) ==> \<forall>(x::int). b < x --> a \<le> x"
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    11
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    12
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    13
theorem "!! (y::int) (z::int) (n::int). 3 dvd z ==> 2 dvd (y::int) ==>
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    14
  (\<exists>(x::int).  2*x =  y) & (\<exists>(k::int). 3*k = z)"
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    15
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    16
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    17
theorem "!! (y::int) (z::int) n. Suc(n::nat) < 6 ==>  3 dvd z ==>
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    18
  2 dvd (y::int) ==> (\<exists>(x::int).  2*x =  y) & (\<exists>(k::int). 3*k = z)"
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    19
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    20
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    21
theorem "\<forall>(x::nat). \<exists>(y::nat). (0::nat) \<le> 5 --> y = 5 + x "
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    22
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    23
20663
2024d9f7df9c updated timings;
wenzelm
parents: 19824
diff changeset
    24
text{*Slow: about 7 seconds on a 1.6GHz machine.*}
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    25
theorem "\<forall>(x::nat). \<exists>(y::nat). y = 5 + x | x div 6 + 1= 2"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    26
  by presburger
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    27
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    28
theorem "\<exists>(x::int). 0 < x"
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    29
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    30
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    31
theorem "\<forall>(x::int) y. x < y --> 2 * x + 1 < 2 * y"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    32
  by presburger
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    33
 
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    34
theorem "\<forall>(x::int) y. 2 * x + 1 \<noteq> 2 * y"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    35
  by presburger
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    36
 
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    37
theorem "\<exists>(x::int) y. 0 < x  & 0 \<le> y  & 3 * x - 5 * y = 1"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    38
  by presburger
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    39
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    40
theorem "~ (\<exists>(x::int) (y::int) (z::int). 4*x + (-6::int)*y = 1)"
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    41
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    42
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    43
theorem "\<forall>(x::int). b < x --> a \<le> x"
14758
af3b71a46a1c A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
chaieb
parents: 14353
diff changeset
    44
  apply (presburger (no_quantify))
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    45
  oops
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    46
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    47
theorem "~ (\<exists>(x::int). False)"
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    48
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    49
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    50
theorem "\<forall>(x::int). (a::int) < 3 * x --> b < 3 * x"
14758
af3b71a46a1c A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
chaieb
parents: 14353
diff changeset
    51
  apply (presburger (no_quantify))
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    52
  oops
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    53
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    54
theorem "\<forall>(x::int). (2 dvd x) --> (\<exists>(y::int). x = 2*y)"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    55
  by presburger 
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    56
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    57
theorem "\<forall>(x::int). (2 dvd x) --> (\<exists>(y::int). x = 2*y)"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    58
  by presburger 
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    59
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    60
theorem "\<forall>(x::int). (2 dvd x) = (\<exists>(y::int). x = 2*y)"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    61
  by presburger 
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    62
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    63
theorem "\<forall>(x::int). ((2 dvd x) = (\<forall>(y::int). x \<noteq> 2*y + 1))"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    64
  by presburger 
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    65
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    66
theorem "~ (\<forall>(x::int). 
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    67
            ((2 dvd x) = (\<forall>(y::int). x \<noteq> 2*y+1) | 
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    68
             (\<exists>(q::int) (u::int) i. 3*i + 2*q - u < 17)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    69
             --> 0 < x | ((~ 3 dvd x) &(x + 8 = 0))))"
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    70
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    71
 
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    72
theorem "~ (\<forall>(i::int). 4 \<le> i --> (\<exists>x y. 0 \<le> x & 0 \<le> y & 3 * x + 5 * y = i))"
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    73
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    74
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    75
theorem "\<forall>(i::int). 8 \<le> i --> (\<exists>x y. 0 \<le> x & 0 \<le> y & 3 * x + 5 * y = i)"
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    76
  by presburger
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    77
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    78
theorem "\<exists>(j::int). \<forall>i. j \<le> i --> (\<exists>x y. 0 \<le> x & 0 \<le> y & 3 * x + 5 * y = i)"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    79
  by presburger
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    80
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    81
theorem "~ (\<forall>j (i::int). j \<le> i --> (\<exists>x y. 0 \<le> x & 0 \<le> y & 3 * x + 5 * y = i))"
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    82
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    83
20663
2024d9f7df9c updated timings;
wenzelm
parents: 19824
diff changeset
    84
text{*Slow: about 5 seconds on a 1.6GHz machine.*}
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    85
theorem "(\<exists>m::nat. n = 2 * m) --> (n + 1) div 2 = n div 2"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    86
  by presburger
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    87
19824
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    88
text{* This following theorem proves that all solutions to the
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    89
recurrence relation $x_{i+2} = |x_{i+1}| - x_i$ are periodic with
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    90
period 9.  The example was brought to our attention by John
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    91
Harrison. It does does not require Presburger arithmetic but merely
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    92
quantifier-free linear arithmetic and holds for the rationals as well.
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    93
20663
2024d9f7df9c updated timings;
wenzelm
parents: 19824
diff changeset
    94
Warning: it takes (in 2006) over 4.2 minutes! *}
19824
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    95
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    96
lemma "\<lbrakk> x3 = abs x2 - x1; x4 = abs x3 - x2; x5 = abs x4 - x3;
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    97
         x6 = abs x5 - x4; x7 = abs x6 - x5; x8 = abs x7 - x6;
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    98
         x9 = abs x8 - x7; x10 = abs x9 - x8; x11 = abs x10 - x9 \<rbrakk>
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    99
 \<Longrightarrow> x1 = x10 & x2 = (x11::int)"
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
   100
by arith
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
   101
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
   102
end