src/HOL/Integ/int_arith2.ML
author paulson
Mon, 22 Oct 2001 11:54:22 +0200
changeset 11868 56db9f3a6b3e
parent 11704 3c50a2cd6f00
child 12486 0ed8bdd883e0
permissions -rw-r--r--
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
to their abstract counterparts, while other binary numerals work correctly.
     1 (*  Title:      HOL/Integ/int_arith2.ML
     2     ID:         $Id$
     3     Authors:    Larry Paulson and Tobias Nipkow
     4 *)
     5 
     6 Goal "(w <= z - (1::int)) = (w<(z::int))";
     7 by (arith_tac 1);
     8 qed "zle_diff1_eq";
     9 Addsimps [zle_diff1_eq];
    10 
    11 Goal "(w < z + 1) = (w<=(z::int))";
    12 by (arith_tac 1);
    13 qed "zle_add1_eq_le";
    14 Addsimps [zle_add1_eq_le];
    15 
    16 Goal "(z = z + w) = (w = (0::int))";
    17 by (arith_tac 1);
    18 qed "zadd_left_cancel0";
    19 Addsimps [zadd_left_cancel0];
    20 
    21 
    22 (* nat *)
    23 
    24 Goal "0 <= z ==> int (nat z) = z"; 
    25 by (asm_full_simp_tac
    26     (simpset() addsimps [neg_eq_less_0, zle_def, not_neg_nat]) 1); 
    27 qed "nat_0_le"; 
    28 
    29 Goal "z <= 0 ==> nat z = 0"; 
    30 by (case_tac "z = 0" 1);
    31 by (asm_simp_tac (simpset() addsimps [nat_le_int0]) 1); 
    32 by (asm_full_simp_tac 
    33     (simpset() addsimps [neg_eq_less_0, neg_nat, linorder_neq_iff]) 1);
    34 qed "nat_le_0"; 
    35 
    36 Addsimps [nat_0_le, nat_le_0];
    37 
    38 val [major,minor] = Goal "[| 0 <= z;  !!m. z = int m ==> P |] ==> P"; 
    39 by (rtac (major RS nat_0_le RS sym RS minor) 1);
    40 qed "nonneg_eq_int"; 
    41 
    42 Goal "(nat w = m) = (if 0 <= w then w = int m else m=0)";
    43 by Auto_tac;
    44 qed "nat_eq_iff";
    45 
    46 Goal "(m = nat w) = (if 0 <= w then w = int m else m=0)";
    47 by Auto_tac;
    48 qed "nat_eq_iff2";
    49 
    50 Goal "0 <= w ==> (nat w < m) = (w < int m)";
    51 by (rtac iffI 1);
    52 by (asm_full_simp_tac 
    53     (simpset() delsimps [zless_int] addsimps [zless_int RS sym]) 2);
    54 by (etac (nat_0_le RS subst) 1);
    55 by (Simp_tac 1);
    56 qed "nat_less_iff";
    57 
    58 Goal "(int m = z) = (m = nat z & 0 <= z)";
    59 by (auto_tac (claset(), simpset() addsimps [nat_eq_iff2]));  
    60 qed "int_eq_iff";
    61 
    62 
    63 (*Users don't want to see (int 0), int(Suc 0) or w + - z*)
    64 Addsimps (map symmetric [Zero_int_def, One_int_def, zdiff_def]);
    65 
    66 Goal "nat 0 = 0";
    67 by (simp_tac (simpset() addsimps [nat_eq_iff]) 1);
    68 qed "nat_0";
    69 
    70 Goal "nat 1 = Suc 0";
    71 by (stac nat_eq_iff 1);
    72 by (Simp_tac 1);
    73 qed "nat_1";
    74 
    75 Goal "nat 2 = Suc (Suc 0)";
    76 by (stac nat_eq_iff 1);
    77 by (Simp_tac 1);
    78 qed "nat_2";
    79 
    80 Goal "0 <= w ==> (nat w < nat z) = (w<z)";
    81 by (case_tac "neg z" 1);
    82 by (auto_tac (claset(), simpset() addsimps [nat_less_iff]));
    83 by (auto_tac (claset() addIs [zless_trans], 
    84 	      simpset() addsimps [neg_eq_less_0, zle_def]));
    85 qed "nat_less_eq_zless";
    86 
    87 Goal "0 < w | 0 <= z ==> (nat w <= nat z) = (w<=z)";
    88 by (auto_tac (claset(), 
    89 	      simpset() addsimps [linorder_not_less RS sym, 
    90 				  zless_nat_conj]));
    91 qed "nat_le_eq_zle";
    92 
    93 (*** abs: absolute value, as an integer ****)
    94 
    95 (* Simpler: use zabs_def as rewrite rule;
    96    but arith_tac is not parameterized by such simp rules
    97 *)
    98 
    99 Goalw [zabs_def]
   100  "P(abs(i::int)) = ((0 <= i --> P i) & (i < 0 --> P(-i)))";
   101 by(Simp_tac 1);
   102 qed "zabs_split";
   103 
   104 Goal "0 <= abs (z::int)";
   105 by (simp_tac (simpset() addsimps [zabs_def]) 1); 
   106 qed "zero_le_zabs";
   107 AddIffs [zero_le_zabs];
   108 
   109 
   110 (*Not sure why this simprule is required!*)
   111 Addsimps [inst "z" "number_of ?v" int_eq_iff];
   112 
   113 (*continued in IntArith.ML ...*)