src/HOL/ex/Arith_Examples.thy
changeset 23193 1f2d94b6a8ef
child 23196 fabf2e8a7ba4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/ex/Arith_Examples.thy	Fri Jun 01 23:21:40 2007 +0200
     1.3 @@ -0,0 +1,163 @@
     1.4 +(*  Title:  HOL/ex/Arith_Examples.thy
     1.5 +    ID:     $Id$
     1.6 +    Author: Tjark Weber
     1.7 +*)
     1.8 +
     1.9 +header {* {\tt arith} *}
    1.10 +
    1.11 +theory Arith_Examples imports Main begin
    1.12 +
    1.13 +text {*
    1.14 +  The {\tt arith} tactic is used frequently throughout the Isabelle
    1.15 +  distribution.  This file merely contains some additional tests and special
    1.16 +  corner cases.  Some rather technical remarks:
    1.17 +
    1.18 +  {\tt fast_arith_tac} is a very basic version of the tactic.  It performs no
    1.19 +  meta-to-object-logic conversion, and only some splitting of operators.
    1.20 +  {\tt simple_arith_tac} performs meta-to-object-logic conversion, full
    1.21 +  splitting of operators, and NNF normalization of the goal.  The {\tt arith}
    1.22 +  tactic combines them both, and tries other tactics (e.g.~{\tt presburger})
    1.23 +  as well.  This is the one that you should use in your proofs!
    1.24 +
    1.25 +  An {\tt arith}-based simproc is available as well (see {\tt
    1.26 +  Fast_Arith.lin_arith_prover}), which---for performance reasons---however
    1.27 +  does even less splitting than {\tt fast_arith_tac} at the moment (namely
    1.28 +  inequalities only).  (On the other hand, it does take apart conjunctions,
    1.29 +  which {\tt fast_arith_tac} currently does not do.)
    1.30 +*}
    1.31 +
    1.32 +ML {* set trace_arith; *}
    1.33 +
    1.34 +section {* Splitting of Operators: @{term max}, @{term min}, @{term abs},
    1.35 +           @{term HOL.minus}, @{term nat}, @{term Divides.mod},
    1.36 +           @{term Divides.div} *}
    1.37 +
    1.38 +lemma "(i::nat) <= max i j"
    1.39 +  by (tactic {* fast_arith_tac 1 *})
    1.40 +
    1.41 +lemma "(i::int) <= max i j"
    1.42 +  by (tactic {* fast_arith_tac 1 *})
    1.43 +
    1.44 +lemma "min i j <= (i::nat)"
    1.45 +  by (tactic {* fast_arith_tac 1 *})
    1.46 +
    1.47 +lemma "min i j <= (i::int)"
    1.48 +  by (tactic {* fast_arith_tac 1 *})
    1.49 +
    1.50 +lemma "min (i::nat) j <= max i j"
    1.51 +  by (tactic {* fast_arith_tac 1 *})
    1.52 +
    1.53 +lemma "min (i::int) j <= max i j"
    1.54 +  by (tactic {* fast_arith_tac 1 *})
    1.55 +
    1.56 +lemma "(i::nat) < j ==> min i j < max i j"
    1.57 +  by (tactic {* fast_arith_tac 1 *})
    1.58 +
    1.59 +lemma "(i::int) < j ==> min i j < max i j"
    1.60 +  by (tactic {* fast_arith_tac 1 *})
    1.61 +
    1.62 +lemma "(0::int) <= abs i"
    1.63 +  by (tactic {* fast_arith_tac 1 *})
    1.64 +
    1.65 +lemma "(i::int) <= abs i"
    1.66 +  by (tactic {* fast_arith_tac 1 *})
    1.67 +
    1.68 +lemma "abs (abs (i::int)) = abs i"
    1.69 +  by (tactic {* fast_arith_tac 1 *})
    1.70 +
    1.71 +text {* Also testing subgoals with bound variables. *}
    1.72 +
    1.73 +lemma "!!x. (x::nat) <= y ==> x - y = 0"
    1.74 +  by (tactic {* fast_arith_tac 1 *})
    1.75 +
    1.76 +lemma "!!x. (x::nat) - y = 0 ==> x <= y"
    1.77 +  by (tactic {* fast_arith_tac 1 *})
    1.78 +
    1.79 +lemma "!!x. ((x::nat) <= y) = (x - y = 0)"
    1.80 +  by (tactic {* simple_arith_tac 1 *})
    1.81 +
    1.82 +lemma "[| (x::nat) < y; d < 1 |] ==> x - y = d"
    1.83 +  by (tactic {* fast_arith_tac 1 *})
    1.84 +
    1.85 +lemma "[| (x::nat) < y; d < 1 |] ==> x - y - x = d - x"
    1.86 +  by (tactic {* fast_arith_tac 1 *})
    1.87 +
    1.88 +lemma "(x::int) < y ==> x - y < 0"
    1.89 +  by (tactic {* fast_arith_tac 1 *})
    1.90 +
    1.91 +lemma "nat (i + j) <= nat i + nat j"
    1.92 +  by (tactic {* fast_arith_tac 1 *})
    1.93 +
    1.94 +lemma "i < j ==> nat (i - j) = 0"
    1.95 +  by (tactic {* fast_arith_tac 1 *})
    1.96 +
    1.97 +lemma "(i::nat) mod 0 = i"
    1.98 +oops
    1.99 +
   1.100 +lemma "(i::nat) mod (Suc 0) = 0"
   1.101 +oops
   1.102 +
   1.103 +lemma "(i::nat) div 0 = 0"
   1.104 +oops
   1.105 +
   1.106 +ML {* (#splits (ArithTheoryData.get (the_context ()))); *}
   1.107 +
   1.108 +lemma "(i::nat) mod (number_of (1::int)) = 0"
   1.109 +oops
   1.110 +
   1.111 +section {* Meta-Logic *}
   1.112 +
   1.113 +lemma "x < Suc y == x <= y"
   1.114 +  by (tactic {* simple_arith_tac 1 *})
   1.115 +
   1.116 +lemma "((x::nat) == z ==> x ~= y) ==> x ~= y | z ~= y"
   1.117 +  by (tactic {* simple_arith_tac 1 *})
   1.118 +
   1.119 +section {* Other Examples *}
   1.120 +
   1.121 +lemma "[| (x::nat) < y; y < z |] ==> x < z"
   1.122 +  by (tactic {* fast_arith_tac 1 *})
   1.123 +
   1.124 +lemma "(x::nat) < y & y < z ==> x < z"
   1.125 +  by (tactic {* simple_arith_tac 1 *})
   1.126 +
   1.127 +lemma "[| (x::nat) ~= y; a + 2 = b; a < y; y < b; a < x; x < b |] ==> False"
   1.128 +  by (tactic {* fast_arith_tac 1 *})
   1.129 +
   1.130 +lemma "[| (x::nat) > y; y > z; z > x |] ==> False"
   1.131 +  by (tactic {* fast_arith_tac 1 *})
   1.132 +
   1.133 +lemma "(x::nat) - 5 > y ==> y < x"
   1.134 +  by (tactic {* fast_arith_tac 1 *})
   1.135 +
   1.136 +lemma "(x::nat) ~= 0 ==> 0 < x"
   1.137 +  by (tactic {* fast_arith_tac 1 *})
   1.138 +
   1.139 +lemma "[| (x::nat) ~= y; x <= y |] ==> x < y"
   1.140 +  by (tactic {* fast_arith_tac 1 *})
   1.141 +
   1.142 +lemma "(x::nat) < y \<longrightarrow> P (x - y) \<longrightarrow> P 0"
   1.143 +  by (tactic {* simple_arith_tac 1 *})
   1.144 +
   1.145 +lemma "(x - y) - (x::nat) = (x - x) - y"
   1.146 +  by (tactic {* fast_arith_tac 1 *})
   1.147 +
   1.148 +lemma "[| (a::nat) < b; c < d |] ==> (a - b) = (c - d)"
   1.149 +  by (tactic {* fast_arith_tac 1 *})
   1.150 +
   1.151 +lemma "((a::nat) - (b - (c - (d - e)))) = (a - (b - (c - (d - e))))"
   1.152 +  by (tactic {* fast_arith_tac 1 *})
   1.153 +
   1.154 +text {* Splitting of inequalities of different type. *}
   1.155 +
   1.156 +lemma "[| (a::nat) ~= b; (i::int) ~= j; a < 2; b < 2 |] ==>
   1.157 +  a + b <= nat (max (abs i) (abs j))"
   1.158 +  by (tactic {* fast_arith_tac 1 *})
   1.159 +
   1.160 +lemma "[| (i::int) ~= j; (a::nat) ~= b; a < 2; b < 2 |] ==>
   1.161 +  a + b <= nat (max (abs i) (abs j))"
   1.162 +  by (tactic {* fast_arith_tac 1 *})
   1.163 +
   1.164 +ML {* reset trace_arith; *}
   1.165 +
   1.166 +end