src/HOL/ex/PresburgerEx.thy
author huffman
Wed, 09 Nov 2011 11:44:42 +0100
changeset 45436 62bc9474d04b
parent 29705 a1ecdd8cf81c
child 58889 5b7a9633cfa8
permissions -rw-r--r--
use simproc_setup for some nat_numeral simprocs; add simproc tests
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
    Author:     Amine Chaieb, TU Muenchen
17388
495c799df31d tuned headers etc.;
wenzelm
parents: 16417
diff changeset
     3
*)
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
     4
17388
495c799df31d tuned headers etc.;
wenzelm
parents: 16417
diff changeset
     5
header {* Some examples for Presburger Arithmetic *}
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
     6
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents: 23323
diff changeset
     7
theory PresburgerEx
24402
382f67ffbda5 imports Presburger; no need for Main
chaieb
parents: 23462
diff changeset
     8
imports Presburger
23462
11728d83794c renamed NatSimprocs.thy to Arith_Tools.thy;
wenzelm
parents: 23323
diff changeset
     9
begin
23323
2274edb9a8b2 Added more examples
chaieb
parents: 20663
diff changeset
    10
25801
331d8ce79ee2 Tuned (type information in Lemmas)
chaieb
parents: 24402
diff changeset
    11
lemma "\<And>m n ja ia. \<lbrakk>\<not> m \<le> j; \<not> (n::nat) \<le> i; (e::nat) \<noteq> 0; Suc j \<le> ja\<rbrakk> \<Longrightarrow> \<exists>m. \<forall>ja ia. m \<le> ja \<longrightarrow> (if j = ja \<and> i = ia then e else 0) = 0" by presburger
23323
2274edb9a8b2 Added more examples
chaieb
parents: 20663
diff changeset
    12
lemma "(0::nat) < emBits mod 8 \<Longrightarrow> 8 + emBits div 8 * 8 - emBits = 8 - emBits mod 8" 
2274edb9a8b2 Added more examples
chaieb
parents: 20663
diff changeset
    13
by presburger
2274edb9a8b2 Added more examples
chaieb
parents: 20663
diff changeset
    14
lemma "(0::nat) < emBits mod 8 \<Longrightarrow> 8 + emBits div 8 * 8 - emBits = 8 - emBits mod 8" 
2274edb9a8b2 Added more examples
chaieb
parents: 20663
diff changeset
    15
by presburger
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    16
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    17
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
    18
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    19
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    20
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
    21
  (\<exists>(x::int).  2*x =  y) & (\<exists>(k::int). 3*k = z)"
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
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    24
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
    25
  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
    26
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    27
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    28
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
    29
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    30
20663
2024d9f7df9c updated timings;
wenzelm
parents: 19824
diff changeset
    31
text{*Slow: about 7 seconds on a 1.6GHz machine.*}
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    32
theorem "\<forall>(x::nat). \<exists>(y::nat). y = 5 + x | x div 6 + 1= 2"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    33
  by presburger
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    34
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    35
theorem "\<exists>(x::int). 0 < x"
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    36
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    37
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    38
theorem "\<forall>(x::int) y. x < y --> 2 * x + 1 < 2 * y"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    39
  by presburger
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    40
 
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    41
theorem "\<forall>(x::int) y. 2 * x + 1 \<noteq> 2 * y"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    42
  by presburger
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    43
 
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    44
theorem "\<exists>(x::int) y. 0 < x  & 0 \<le> y  & 3 * x - 5 * y = 1"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    45
  by presburger
13880
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) (y::int) (z::int). 4*x + (-6::int)*y = 1)"
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). b < x --> a \<le> x"
23323
2274edb9a8b2 Added more examples
chaieb
parents: 20663
diff changeset
    51
  apply (presburger elim)
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    52
  oops
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    53
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    54
theorem "~ (\<exists>(x::int). False)"
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    55
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    56
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    57
theorem "\<forall>(x::int). (a::int) < 3 * x --> b < 3 * x"
23323
2274edb9a8b2 Added more examples
chaieb
parents: 20663
diff changeset
    58
  apply (presburger elim)
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    59
  oops
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    60
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    61
theorem "\<forall>(x::int). (2 dvd x) --> (\<exists>(y::int). x = 2*y)"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    62
  by presburger 
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    63
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    64
theorem "\<forall>(x::int). (2 dvd x) --> (\<exists>(y::int). x = 2*y)"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    65
  by presburger 
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    66
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    67
theorem "\<forall>(x::int). (2 dvd x) = (\<exists>(y::int). x = 2*y)"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    68
  by presburger 
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    69
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    70
theorem "\<forall>(x::int). ((2 dvd x) = (\<forall>(y::int). x \<noteq> 2*y + 1))"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    71
  by presburger 
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    72
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    73
theorem "~ (\<forall>(x::int). 
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 13880
diff changeset
    74
            ((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
    75
             (\<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
    76
             --> 0 < x | ((~ 3 dvd x) &(x + 8 = 0))))"
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    77
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    78
 
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    79
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
    80
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    81
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    82
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
    83
  by presburger
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    84
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    85
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
    86
  by presburger
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    87
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    88
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
    89
  by presburger
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    90
20663
2024d9f7df9c updated timings;
wenzelm
parents: 19824
diff changeset
    91
text{*Slow: about 5 seconds on a 1.6GHz machine.*}
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    92
theorem "(\<exists>m::nat. n = 2 * m) --> (n + 1) div 2 = n div 2"
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
    93
  by presburger
13880
4f7f30f68926 Added examples for Presburger arithmetic.
berghofe
parents:
diff changeset
    94
19824
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    95
text{* This following theorem proves that all solutions to the
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    96
recurrence relation $x_{i+2} = |x_{i+1}| - x_i$ are periodic with
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    97
period 9.  The example was brought to our attention by John
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    98
Harrison. It does does not require Presburger arithmetic but merely
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
    99
quantifier-free linear arithmetic and holds for the rationals as well.
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
   100
20663
2024d9f7df9c updated timings;
wenzelm
parents: 19824
diff changeset
   101
Warning: it takes (in 2006) over 4.2 minutes! *}
19824
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
   102
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
   103
lemma "\<lbrakk> x3 = abs x2 - x1; x4 = abs x3 - x2; x5 = abs x4 - x3;
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
   104
         x6 = abs x5 - x4; x7 = abs x6 - x5; x8 = abs x7 - x6;
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
   105
         x9 = abs x8 - x7; x10 = abs x9 - x8; x11 = abs x10 - x9 \<rbrakk>
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
   106
 \<Longrightarrow> x1 = x10 & x2 = (x11::int)"
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
   107
by arith
fafceecebef0 added John's example
nipkow
parents: 17388
diff changeset
   108
15075
a6cd1a454751 minor formatting fixes
webertj
parents: 14981
diff changeset
   109
end