src/HOL/Integ/IntArith.ML
author wenzelm
Fri, 06 Oct 2000 17:35:58 +0200
changeset 10168 50be659d4222
parent 9633 a71a83253997
child 10228 e653cb933293
permissions -rw-r--r--
final tuning;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents: 9269
diff changeset
     1
(*  Title:      HOL/Integ/IntArith.ML
7707
1f4b67fdfdae simprocs now in IntArith;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
1f4b67fdfdae simprocs now in IntArith;
wenzelm
parents:
diff changeset
     3
    Authors:    Larry Paulson and Tobias Nipkow
1f4b67fdfdae simprocs now in IntArith;
wenzelm
parents:
diff changeset
     4
*)
1f4b67fdfdae simprocs now in IntArith;
wenzelm
parents:
diff changeset
     5
9269
b62d5265b959 added zabs to arith_tac
nipkow
parents: 9214
diff changeset
     6
Goal "abs(abs(x::int)) = abs(x)";
b62d5265b959 added zabs to arith_tac
nipkow
parents: 9214
diff changeset
     7
by(arith_tac 1);
9214
9454f30eacc7 Defined abs on int.
nipkow
parents: 9079
diff changeset
     8
qed "abs_abs";
9454f30eacc7 Defined abs on int.
nipkow
parents: 9079
diff changeset
     9
Addsimps [abs_abs];
9454f30eacc7 Defined abs on int.
nipkow
parents: 9079
diff changeset
    10
9269
b62d5265b959 added zabs to arith_tac
nipkow
parents: 9214
diff changeset
    11
Goal "abs(-(x::int)) = abs(x)";
b62d5265b959 added zabs to arith_tac
nipkow
parents: 9214
diff changeset
    12
by(arith_tac 1);
9214
9454f30eacc7 Defined abs on int.
nipkow
parents: 9079
diff changeset
    13
qed "abs_minus";
9454f30eacc7 Defined abs on int.
nipkow
parents: 9079
diff changeset
    14
Addsimps [abs_minus];
9454f30eacc7 Defined abs on int.
nipkow
parents: 9079
diff changeset
    15
9269
b62d5265b959 added zabs to arith_tac
nipkow
parents: 9214
diff changeset
    16
Goal "abs(x+y) <= abs(x) + abs(y::int)";
b62d5265b959 added zabs to arith_tac
nipkow
parents: 9214
diff changeset
    17
by(arith_tac 1);
b62d5265b959 added zabs to arith_tac
nipkow
parents: 9214
diff changeset
    18
qed "triangle_ineq";
b62d5265b959 added zabs to arith_tac
nipkow
parents: 9214
diff changeset
    19
9214
9454f30eacc7 Defined abs on int.
nipkow
parents: 9079
diff changeset
    20
9063
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    21
(*** Some convenient biconditionals for products of signs ***)
7707
1f4b67fdfdae simprocs now in IntArith;
wenzelm
parents:
diff changeset
    22
9063
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    23
Goal "[| (#0::int) < i; #0 < j |] ==> #0 < i*j";
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    24
by (dtac zmult_zless_mono1 1);
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    25
by Auto_tac; 
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    26
qed "zmult_pos";
7707
1f4b67fdfdae simprocs now in IntArith;
wenzelm
parents:
diff changeset
    27
9063
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    28
Goal "[| i < (#0::int); j < #0 |] ==> #0 < i*j";
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    29
by (dtac zmult_zless_mono1_neg 1);
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    30
by Auto_tac; 
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    31
qed "zmult_neg";
7707
1f4b67fdfdae simprocs now in IntArith;
wenzelm
parents:
diff changeset
    32
9063
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    33
Goal "[| (#0::int) < i; j < #0 |] ==> i*j < #0";
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    34
by (dtac zmult_zless_mono1_neg 1);
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    35
by Auto_tac; 
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    36
qed "zmult_pos_neg";
7707
1f4b67fdfdae simprocs now in IntArith;
wenzelm
parents:
diff changeset
    37
9063
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    38
Goal "((#0::int) < x*y) = (#0 < x & #0 < y | x < #0 & y < #0)";
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    39
by (auto_tac (claset(), 
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    40
              simpset() addsimps [order_le_less, linorder_not_less,
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    41
	                          zmult_pos, zmult_neg]));
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    42
by (ALLGOALS (rtac ccontr)); 
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    43
by (auto_tac (claset(), 
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    44
	      simpset() addsimps [order_le_less, linorder_not_less]));
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    45
by (ALLGOALS (etac rev_mp)); 
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    46
by (ALLGOALS (dtac zmult_pos_neg THEN' assume_tac));
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    47
by (auto_tac (claset() addDs [order_less_not_sym], 
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    48
              simpset() addsimps [zmult_commute]));  
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    49
qed "int_0_less_mult_iff";
7707
1f4b67fdfdae simprocs now in IntArith;
wenzelm
parents:
diff changeset
    50
9063
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    51
Goal "((#0::int) <= x*y) = (#0 <= x & #0 <= y | x <= #0 & y <= #0)";
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    52
by (auto_tac (claset(), 
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    53
              simpset() addsimps [order_le_less, linorder_not_less,  
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    54
                                  int_0_less_mult_iff]));
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    55
qed "int_0_le_mult_iff";
7707
1f4b67fdfdae simprocs now in IntArith;
wenzelm
parents:
diff changeset
    56
9063
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    57
Goal "(x*y < (#0::int)) = (#0 < x & y < #0 | x < #0 & #0 < y)";
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    58
by (auto_tac (claset(), 
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    59
              simpset() addsimps [int_0_le_mult_iff, 
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    60
                                  linorder_not_le RS sym]));
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    61
by (auto_tac (claset() addDs [order_less_not_sym],  
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    62
              simpset() addsimps [linorder_not_le]));
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    63
qed "zmult_less_0_iff";
7707
1f4b67fdfdae simprocs now in IntArith;
wenzelm
parents:
diff changeset
    64
9063
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    65
Goal "(x*y <= (#0::int)) = (#0 <= x & y <= #0 | x <= #0 & #0 <= y)";
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    66
by (auto_tac (claset() addDs [order_less_not_sym], 
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    67
              simpset() addsimps [int_0_less_mult_iff, 
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    68
                                  linorder_not_less RS sym]));
0d7628966069 new lemmas for signs of products
paulson
parents: 9000
diff changeset
    69
qed "zmult_le_0_iff";
9509
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    70
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    71
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    72
(*** Products and 1, by T. M. Rasmussen ***)
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    73
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    74
Goal "(m = m*(n::int)) = (n = #1 | m = #0)";
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    75
by Auto_tac;
9633
a71a83253997 better rules for cancellation of common factors across comparisons
paulson
parents: 9509
diff changeset
    76
by (subgoal_tac "m*#1 = m*n" 1);
a71a83253997 better rules for cancellation of common factors across comparisons
paulson
parents: 9509
diff changeset
    77
by (dtac (zmult_cancel1 RS iffD1) 1); 
9509
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    78
by Auto_tac;
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    79
qed "zmult_eq_self_iff";
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    80
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    81
Goal "[| #1 < m; #1 < n |] ==> #1 < m*(n::int)";
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    82
by (res_inst_tac [("z2.0","#1*n")] zless_trans 1);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    83
by (rtac zmult_zless_mono1 2);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    84
by (ALLGOALS Asm_simp_tac);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    85
qed "zless_1_zmult";
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    86
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    87
Goal "[| #0 < n; n ~= #1 |] ==> #1 < (n::int)";
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    88
by (arith_tac 1);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    89
val lemma = result();
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    90
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    91
Goal "#0 < (m::int) ==> (m * n = #1) = (m = #1 & n = #1)";
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    92
by Auto_tac;
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    93
by (case_tac "m=#1" 1);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    94
by (case_tac "n=#1" 2);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    95
by (case_tac "m=#1" 4);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    96
by (case_tac "n=#1" 5);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    97
by Auto_tac;
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    98
by distinct_subgoals_tac;
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
    99
by (subgoal_tac "#1<m*n" 1);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   100
by (Asm_full_simp_tac 1);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   101
by (rtac zless_1_zmult 1);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   102
by (ALLGOALS (rtac lemma));
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   103
by Auto_tac;  
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   104
by (subgoal_tac "#0<m*n" 1);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   105
by (Asm_simp_tac 2);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   106
by (dtac (int_0_less_mult_iff RS iffD1) 1);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   107
by Auto_tac;  
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   108
qed "pos_zmult_eq_1_iff";
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   109
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   110
Goal "(m*n = (#1::int)) = ((m = #1 & n = #1) | (m = #-1 & n = #-1))";
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   111
by (case_tac "#0<m" 1);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   112
by (asm_simp_tac (simpset() addsimps [pos_zmult_eq_1_iff]) 1);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   113
by (case_tac "m=#0" 1);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   114
by (Asm_simp_tac 1);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   115
by (subgoal_tac "#0 < -m" 1);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   116
by (arith_tac 2);
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   117
by (dres_inst_tac [("n","-n")] pos_zmult_eq_1_iff 1); 
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   118
by Auto_tac;  
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   119
qed "zmult_eq_1_iff";
0f3ee1f89ca8 introduction of integer exponentiation
paulson
parents: 9436
diff changeset
   120