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