src/HOL/ex/Arith_Examples.thy
author haftmann
Sun, 26 Apr 2009 20:17:50 +0200
changeset 30997 081e825c2218
parent 30686 47a32dd1b86e
child 31066 972c870da225
permissions -rw-r--r--
fixed document generation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
     1
(*  Title:  HOL/ex/Arith_Examples.thy
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
     2
    Author: Tjark Weber
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
     3
*)
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
     4
23218
01c4d19f597e use antiquotations instead of raw TeX code;
wenzelm
parents: 23211
diff changeset
     5
header {* Arithmetic *}
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
     6
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
     7
theory Arith_Examples imports Main begin
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
     8
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
     9
text {*
23218
01c4d19f597e use antiquotations instead of raw TeX code;
wenzelm
parents: 23211
diff changeset
    10
  The @{text arith} method is used frequently throughout the Isabelle
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    11
  distribution.  This file merely contains some additional tests and special
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    12
  corner cases.  Some rather technical remarks:
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    13
23218
01c4d19f597e use antiquotations instead of raw TeX code;
wenzelm
parents: 23211
diff changeset
    14
  @{ML fast_arith_tac} is a very basic version of the tactic.  It performs no
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    15
  meta-to-object-logic conversion, and only some splitting of operators.
30686
47a32dd1b86e moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents: 24328
diff changeset
    16
  @{ML linear_arith_tac} performs meta-to-object-logic conversion, full
23218
01c4d19f597e use antiquotations instead of raw TeX code;
wenzelm
parents: 23211
diff changeset
    17
  splitting of operators, and NNF normalization of the goal.  The @{text arith}
01c4d19f597e use antiquotations instead of raw TeX code;
wenzelm
parents: 23211
diff changeset
    18
  method combines them both, and tries other methods (e.g.~@{text presburger})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    19
  as well.  This is the one that you should use in your proofs!
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    20
24093
5d0ecd0c8f3c tuned LinArith setup;
wenzelm
parents: 24075
diff changeset
    21
  An @{text arith}-based simproc is available as well (see @{ML
30686
47a32dd1b86e moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents: 24328
diff changeset
    22
  Lin_Arith.lin_arith_simproc}), which---for performance
24093
5d0ecd0c8f3c tuned LinArith setup;
wenzelm
parents: 24075
diff changeset
    23
  reasons---however does even less splitting than @{ML fast_arith_tac}
5d0ecd0c8f3c tuned LinArith setup;
wenzelm
parents: 24075
diff changeset
    24
  at the moment (namely inequalities only).  (On the other hand, it
5d0ecd0c8f3c tuned LinArith setup;
wenzelm
parents: 24075
diff changeset
    25
  does take apart conjunctions, which @{ML fast_arith_tac} currently
5d0ecd0c8f3c tuned LinArith setup;
wenzelm
parents: 24075
diff changeset
    26
  does not do.)
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    27
*}
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    28
23196
fabf2e8a7ba4 tracing disabled
webertj
parents: 23193
diff changeset
    29
(*
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    30
ML {* set trace_arith; *}
23196
fabf2e8a7ba4 tracing disabled
webertj
parents: 23193
diff changeset
    31
*)
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    32
23218
01c4d19f597e use antiquotations instead of raw TeX code;
wenzelm
parents: 23211
diff changeset
    33
subsection {* Splitting of Operators: @{term max}, @{term min}, @{term abs},
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    34
           @{term HOL.minus}, @{term nat}, @{term Divides.mod},
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    35
           @{term Divides.div} *}
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    36
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    37
lemma "(i::nat) <= max i j"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    38
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    39
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    40
lemma "(i::int) <= max i j"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    41
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    42
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    43
lemma "min i j <= (i::nat)"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    44
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    45
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    46
lemma "min i j <= (i::int)"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    47
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    48
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    49
lemma "min (i::nat) j <= max i j"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    50
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    51
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    52
lemma "min (i::int) j <= max i j"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    53
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    54
23208
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
    55
lemma "min (i::nat) j + max i j = i + j"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    56
  by (tactic {* fast_arith_tac @{context} 1 *})
23208
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
    57
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
    58
lemma "min (i::int) j + max i j = i + j"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    59
  by (tactic {* fast_arith_tac @{context} 1 *})
23208
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
    60
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    61
lemma "(i::nat) < j ==> min i j < max i j"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    62
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    63
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    64
lemma "(i::int) < j ==> min i j < max i j"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    65
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    66
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    67
lemma "(0::int) <= abs i"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    68
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    69
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    70
lemma "(i::int) <= abs i"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    71
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    72
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    73
lemma "abs (abs (i::int)) = abs i"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    74
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    75
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    76
text {* Also testing subgoals with bound variables. *}
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    77
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    78
lemma "!!x. (x::nat) <= y ==> x - y = 0"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    79
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    80
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    81
lemma "!!x. (x::nat) - y = 0 ==> x <= y"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    82
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    83
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    84
lemma "!!x. ((x::nat) <= y) = (x - y = 0)"
30686
47a32dd1b86e moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents: 24328
diff changeset
    85
  by (tactic {* linear_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    86
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    87
lemma "[| (x::nat) < y; d < 1 |] ==> x - y = d"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    88
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    89
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    90
lemma "[| (x::nat) < y; d < 1 |] ==> x - y - x = d - x"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    91
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    92
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    93
lemma "(x::int) < y ==> x - y < 0"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    94
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    95
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    96
lemma "nat (i + j) <= nat i + nat j"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
    97
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    98
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
    99
lemma "i < j ==> nat (i - j) = 0"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   100
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   101
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   102
lemma "(i::nat) mod 0 = i"
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   103
  (* FIXME: need to replace 0 by its numeral representation *)
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   104
  apply (subst nat_numeral_0_eq_0 [symmetric])
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   105
  by (tactic {* fast_arith_tac @{context} 1 *})
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   106
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   107
lemma "(i::nat) mod 1 = 0"
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   108
  (* FIXME: need to replace 1 by its numeral representation *)
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   109
  apply (subst nat_numeral_1_eq_1 [symmetric])
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   110
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   111
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   112
lemma "(i::nat) mod 42 <= 41"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   113
  by (tactic {* fast_arith_tac @{context} 1 *})
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   114
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   115
lemma "(i::int) mod 0 = i"
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   116
  (* FIXME: need to replace 0 by its numeral representation *)
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   117
  apply (subst numeral_0_eq_0 [symmetric])
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   118
  by (tactic {* fast_arith_tac @{context} 1 *})
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   119
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   120
lemma "(i::int) mod 1 = 0"
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   121
  (* FIXME: need to replace 1 by its numeral representation *)
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   122
  apply (subst numeral_1_eq_1 [symmetric])
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   123
  (* FIXME: arith does not know about iszero *)
24093
5d0ecd0c8f3c tuned LinArith setup;
wenzelm
parents: 24075
diff changeset
   124
  apply (tactic {* lin_arith_pre_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   125
oops
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   126
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   127
lemma "(i::int) mod 42 <= 41"
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   128
  (* FIXME: arith does not know about iszero *)
24093
5d0ecd0c8f3c tuned LinArith setup;
wenzelm
parents: 24075
diff changeset
   129
  apply (tactic {* lin_arith_pre_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   130
oops
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   131
24328
83afe527504d fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
webertj
parents: 24093
diff changeset
   132
lemma "-(i::int) * 1 = 0 ==> i = 0"
83afe527504d fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
webertj
parents: 24093
diff changeset
   133
  by (tactic {* fast_arith_tac @{context} 1 *})
83afe527504d fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
webertj
parents: 24093
diff changeset
   134
83afe527504d fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
webertj
parents: 24093
diff changeset
   135
lemma "[| (0::int) < abs i; abs i * 1 < abs i * j |] ==> 1 < abs i * j"
83afe527504d fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
webertj
parents: 24093
diff changeset
   136
  by (tactic {* fast_arith_tac @{context} 1 *})
83afe527504d fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
webertj
parents: 24093
diff changeset
   137
23218
01c4d19f597e use antiquotations instead of raw TeX code;
wenzelm
parents: 23211
diff changeset
   138
01c4d19f597e use antiquotations instead of raw TeX code;
wenzelm
parents: 23211
diff changeset
   139
subsection {* Meta-Logic *}
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   140
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   141
lemma "x < Suc y == x <= y"
30686
47a32dd1b86e moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents: 24328
diff changeset
   142
  by (tactic {* linear_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   143
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   144
lemma "((x::nat) == z ==> x ~= y) ==> x ~= y | z ~= y"
30686
47a32dd1b86e moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents: 24328
diff changeset
   145
  by (tactic {* linear_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   146
23218
01c4d19f597e use antiquotations instead of raw TeX code;
wenzelm
parents: 23211
diff changeset
   147
01c4d19f597e use antiquotations instead of raw TeX code;
wenzelm
parents: 23211
diff changeset
   148
subsection {* Various Other Examples *}
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   149
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   150
lemma "(x < Suc y) = (x <= y)"
30686
47a32dd1b86e moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents: 24328
diff changeset
   151
  by (tactic {* linear_arith_tac @{context} 1 *})
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   152
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   153
lemma "[| (x::nat) < y; y < z |] ==> x < z"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   154
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   155
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   156
lemma "(x::nat) < y & y < z ==> x < z"
30686
47a32dd1b86e moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents: 24328
diff changeset
   157
  by (tactic {* linear_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   158
23208
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
   159
text {* This example involves no arithmetic at all, but is solved by
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
   160
  preprocessing (i.e. NNF normalization) alone. *}
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
   161
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
   162
lemma "(P::bool) = Q ==> Q = P"
30686
47a32dd1b86e moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents: 24328
diff changeset
   163
  by (tactic {* linear_arith_tac @{context} 1 *})
23208
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
   164
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
   165
lemma "[| P = (x = 0); (~P) = (y = 0) |] ==> min (x::nat) y = 0"
30686
47a32dd1b86e moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents: 24328
diff changeset
   166
  by (tactic {* linear_arith_tac @{context} 1 *})
23208
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
   167
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
   168
lemma "[| P = (x = 0); (~P) = (y = 0) |] ==> max (x::nat) y = x + y"
30686
47a32dd1b86e moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents: 24328
diff changeset
   169
  by (tactic {* linear_arith_tac @{context} 1 *})
23208
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
   170
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   171
lemma "[| (x::nat) ~= y; a + 2 = b; a < y; y < b; a < x; x < b |] ==> False"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   172
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   173
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   174
lemma "[| (x::nat) > y; y > z; z > x |] ==> False"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   175
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   176
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   177
lemma "(x::nat) - 5 > y ==> y < x"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   178
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   179
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   180
lemma "(x::nat) ~= 0 ==> 0 < x"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   181
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   182
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   183
lemma "[| (x::nat) ~= y; x <= y |] ==> x < y"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   184
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   185
23196
fabf2e8a7ba4 tracing disabled
webertj
parents: 23193
diff changeset
   186
lemma "[| (x::nat) < y; P (x - y) |] ==> P 0"
30686
47a32dd1b86e moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents: 24328
diff changeset
   187
  by (tactic {* linear_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   188
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   189
lemma "(x - y) - (x::nat) = (x - x) - y"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   190
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   191
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   192
lemma "[| (a::nat) < b; c < d |] ==> (a - b) = (c - d)"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   193
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   194
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   195
lemma "((a::nat) - (b - (c - (d - e)))) = (a - (b - (c - (d - e))))"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   196
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   197
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   198
lemma "(n < m & m < n') | (n < m & m = n') | (n < n' & n' < m) |
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   199
  (n = n' & n' < m) | (n = m & m < n') |
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   200
  (n' < m & m < n) | (n' < m & m = n) |
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   201
  (n' < n & n < m) | (n' = n & n < m) | (n' = m & m < n) |
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   202
  (m < n & n < n') | (m < n & n' = n) | (m < n' & n' < n) |
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   203
  (m = n & n < n') | (m = n' & n' < n) |
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   204
  (n' = m & m = (n::nat))"
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   205
(* FIXME: this should work in principle, but is extremely slow because     *)
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   206
(*        preprocessing negates the goal and tries to compute its negation *)
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   207
(*        normal form, which creates lots of separate cases for this       *)
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   208
(*        disjunction of conjunctions                                      *)
30686
47a32dd1b86e moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents: 24328
diff changeset
   209
(* by (tactic {* linear_arith_tac 1 *}) *)
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   210
oops
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   211
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   212
lemma "2 * (x::nat) ~= 1"
23208
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
   213
(* FIXME: this is beyond the scope of the decision procedure at the moment, *)
4d8a0976fa1c extended
webertj
parents: 23198
diff changeset
   214
(*        because its negation is satisfiable in the rationals?             *)
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   215
(* by (tactic {* fast_arith_tac 1 *}) *)
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   216
oops
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   217
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   218
text {* Constants. *}
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   219
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   220
lemma "(0::nat) < 1"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   221
  by (tactic {* fast_arith_tac @{context} 1 *})
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   222
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   223
lemma "(0::int) < 1"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   224
  by (tactic {* fast_arith_tac @{context} 1 *})
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   225
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   226
lemma "(47::nat) + 11 < 08 * 15"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   227
  by (tactic {* fast_arith_tac @{context} 1 *})
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   228
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   229
lemma "(47::int) + 11 < 08 * 15"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   230
  by (tactic {* fast_arith_tac @{context} 1 *})
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   231
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   232
text {* Splitting of inequalities of different type. *}
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   233
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   234
lemma "[| (a::nat) ~= b; (i::int) ~= j; a < 2; b < 2 |] ==>
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   235
  a + b <= nat (max (abs i) (abs j))"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   236
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   237
23198
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   238
text {* Again, but different order. *}
174b5f2ec7c1 extended
webertj
parents: 23196
diff changeset
   239
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   240
lemma "[| (i::int) ~= j; (a::nat) ~= b; a < 2; b < 2 |] ==>
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   241
  a + b <= nat (max (abs i) (abs j))"
24075
366d4d234814 arith method setup: proper context;
wenzelm
parents: 23218
diff changeset
   242
  by (tactic {* fast_arith_tac @{context} 1 *})
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   243
23196
fabf2e8a7ba4 tracing disabled
webertj
parents: 23193
diff changeset
   244
(*
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   245
ML {* reset trace_arith; *}
23196
fabf2e8a7ba4 tracing disabled
webertj
parents: 23193
diff changeset
   246
*)
23193
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   247
1f2d94b6a8ef some tests for arith added
webertj
parents:
diff changeset
   248
end