src/HOL/ex/PresburgerEx.thy
author hoelzl
Thu Jan 31 11:31:27 2013 +0100 (2013-01-31)
changeset 50999 3de230ed0547
parent 29705 a1ecdd8cf81c
child 58889 5b7a9633cfa8
permissions -rw-r--r--
introduce order topology
berghofe@13880
     1
(*  Title:      HOL/ex/PresburgerEx.thy
berghofe@13880
     2
    Author:     Amine Chaieb, TU Muenchen
wenzelm@17388
     3
*)
berghofe@13880
     4
wenzelm@17388
     5
header {* Some examples for Presburger Arithmetic *}
berghofe@13880
     6
wenzelm@23462
     7
theory PresburgerEx
chaieb@24402
     8
imports Presburger
wenzelm@23462
     9
begin
chaieb@23323
    10
chaieb@25801
    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
chaieb@23323
    12
lemma "(0::nat) < emBits mod 8 \<Longrightarrow> 8 + emBits div 8 * 8 - emBits = 8 - emBits mod 8" 
chaieb@23323
    13
by presburger
chaieb@23323
    14
lemma "(0::nat) < emBits mod 8 \<Longrightarrow> 8 + emBits div 8 * 8 - emBits = 8 - emBits mod 8" 
chaieb@23323
    15
by presburger
berghofe@13880
    16
paulson@14353
    17
theorem "(\<forall>(y::int). 3 dvd y) ==> \<forall>(x::int). b < x --> a \<le> x"
berghofe@13880
    18
  by presburger
berghofe@13880
    19
berghofe@13880
    20
theorem "!! (y::int) (z::int) (n::int). 3 dvd z ==> 2 dvd (y::int) ==>
paulson@14353
    21
  (\<exists>(x::int).  2*x =  y) & (\<exists>(k::int). 3*k = z)"
berghofe@13880
    22
  by presburger
berghofe@13880
    23
berghofe@13880
    24
theorem "!! (y::int) (z::int) n. Suc(n::nat) < 6 ==>  3 dvd z ==>
paulson@14353
    25
  2 dvd (y::int) ==> (\<exists>(x::int).  2*x =  y) & (\<exists>(k::int). 3*k = z)"
berghofe@13880
    26
  by presburger
berghofe@13880
    27
webertj@15075
    28
theorem "\<forall>(x::nat). \<exists>(y::nat). (0::nat) \<le> 5 --> y = 5 + x "
berghofe@13880
    29
  by presburger
berghofe@13880
    30
wenzelm@20663
    31
text{*Slow: about 7 seconds on a 1.6GHz machine.*}
webertj@15075
    32
theorem "\<forall>(x::nat). \<exists>(y::nat). y = 5 + x | x div 6 + 1= 2"
webertj@15075
    33
  by presburger
webertj@15075
    34
webertj@15075
    35
theorem "\<exists>(x::int). 0 < x"
berghofe@13880
    36
  by presburger
berghofe@13880
    37
webertj@15075
    38
theorem "\<forall>(x::int) y. x < y --> 2 * x + 1 < 2 * y"
webertj@15075
    39
  by presburger
berghofe@13880
    40
 
webertj@15075
    41
theorem "\<forall>(x::int) y. 2 * x + 1 \<noteq> 2 * y"
webertj@15075
    42
  by presburger
berghofe@13880
    43
 
webertj@15075
    44
theorem "\<exists>(x::int) y. 0 < x  & 0 \<le> y  & 3 * x - 5 * y = 1"
webertj@15075
    45
  by presburger
berghofe@13880
    46
paulson@14353
    47
theorem "~ (\<exists>(x::int) (y::int) (z::int). 4*x + (-6::int)*y = 1)"
berghofe@13880
    48
  by presburger
berghofe@13880
    49
paulson@14353
    50
theorem "\<forall>(x::int). b < x --> a \<le> x"
chaieb@23323
    51
  apply (presburger elim)
berghofe@13880
    52
  oops
berghofe@13880
    53
paulson@14353
    54
theorem "~ (\<exists>(x::int). False)"
berghofe@13880
    55
  by presburger
berghofe@13880
    56
paulson@14353
    57
theorem "\<forall>(x::int). (a::int) < 3 * x --> b < 3 * x"
chaieb@23323
    58
  apply (presburger elim)
berghofe@13880
    59
  oops
berghofe@13880
    60
webertj@15075
    61
theorem "\<forall>(x::int). (2 dvd x) --> (\<exists>(y::int). x = 2*y)"
webertj@15075
    62
  by presburger 
berghofe@13880
    63
webertj@15075
    64
theorem "\<forall>(x::int). (2 dvd x) --> (\<exists>(y::int). x = 2*y)"
webertj@15075
    65
  by presburger 
berghofe@13880
    66
webertj@15075
    67
theorem "\<forall>(x::int). (2 dvd x) = (\<exists>(y::int). x = 2*y)"
webertj@15075
    68
  by presburger 
paulson@14353
    69
webertj@15075
    70
theorem "\<forall>(x::int). ((2 dvd x) = (\<forall>(y::int). x \<noteq> 2*y + 1))"
webertj@15075
    71
  by presburger 
berghofe@13880
    72
paulson@14353
    73
theorem "~ (\<forall>(x::int). 
paulson@14353
    74
            ((2 dvd x) = (\<forall>(y::int). x \<noteq> 2*y+1) | 
paulson@14353
    75
             (\<exists>(q::int) (u::int) i. 3*i + 2*q - u < 17)
paulson@14353
    76
             --> 0 < x | ((~ 3 dvd x) &(x + 8 = 0))))"
berghofe@13880
    77
  by presburger
berghofe@13880
    78
 
webertj@15075
    79
theorem "~ (\<forall>(i::int). 4 \<le> i --> (\<exists>x y. 0 \<le> x & 0 \<le> y & 3 * x + 5 * y = i))"
berghofe@13880
    80
  by presburger
berghofe@13880
    81
webertj@15075
    82
theorem "\<forall>(i::int). 8 \<le> i --> (\<exists>x y. 0 \<le> x & 0 \<le> y & 3 * x + 5 * y = i)"
paulson@14353
    83
  by presburger
berghofe@13880
    84
webertj@15075
    85
theorem "\<exists>(j::int). \<forall>i. j \<le> i --> (\<exists>x y. 0 \<le> x & 0 \<le> y & 3 * x + 5 * y = i)"
webertj@15075
    86
  by presburger
webertj@15075
    87
webertj@15075
    88
theorem "~ (\<forall>j (i::int). j \<le> i --> (\<exists>x y. 0 \<le> x & 0 \<le> y & 3 * x + 5 * y = i))"
berghofe@13880
    89
  by presburger
berghofe@13880
    90
wenzelm@20663
    91
text{*Slow: about 5 seconds on a 1.6GHz machine.*}
webertj@15075
    92
theorem "(\<exists>m::nat. n = 2 * m) --> (n + 1) div 2 = n div 2"
webertj@15075
    93
  by presburger
berghofe@13880
    94
nipkow@19824
    95
text{* This following theorem proves that all solutions to the
nipkow@19824
    96
recurrence relation $x_{i+2} = |x_{i+1}| - x_i$ are periodic with
nipkow@19824
    97
period 9.  The example was brought to our attention by John
nipkow@19824
    98
Harrison. It does does not require Presburger arithmetic but merely
nipkow@19824
    99
quantifier-free linear arithmetic and holds for the rationals as well.
nipkow@19824
   100
wenzelm@20663
   101
Warning: it takes (in 2006) over 4.2 minutes! *}
nipkow@19824
   102
nipkow@19824
   103
lemma "\<lbrakk> x3 = abs x2 - x1; x4 = abs x3 - x2; x5 = abs x4 - x3;
nipkow@19824
   104
         x6 = abs x5 - x4; x7 = abs x6 - x5; x8 = abs x7 - x6;
nipkow@19824
   105
         x9 = abs x8 - x7; x10 = abs x9 - x8; x11 = abs x10 - x9 \<rbrakk>
nipkow@19824
   106
 \<Longrightarrow> x1 = x10 & x2 = (x11::int)"
nipkow@19824
   107
by arith
nipkow@19824
   108
webertj@15075
   109
end