src/HOL/Matrix_LP/ComputeNumeral.thy
changeset 47108 2a1953f0d20d
parent 46988 9f492f5b0cec
child 55932 68c5104d2204
     1.1 --- a/src/HOL/Matrix_LP/ComputeNumeral.thy	Sat Mar 24 16:27:04 2012 +0100
     1.2 +++ b/src/HOL/Matrix_LP/ComputeNumeral.thy	Sun Mar 25 20:15:39 2012 +0200
     1.3 @@ -2,145 +2,47 @@
     1.4  imports ComputeHOL ComputeFloat
     1.5  begin
     1.6  
     1.7 -(* normalization of bit strings *)
     1.8 -lemmas bitnorm = normalize_bin_simps
     1.9 -
    1.10 -(* neg for bit strings *)
    1.11 -lemma neg1: "neg Int.Pls = False" by (simp add: Int.Pls_def)
    1.12 -lemma neg2: "neg Int.Min = True" apply (subst Int.Min_def) by auto
    1.13 -lemma neg3: "neg (Int.Bit0 x) = neg x" apply (simp add: neg_def) apply (subst Bit0_def) by auto
    1.14 -lemma neg4: "neg (Int.Bit1 x) = neg x" apply (simp add: neg_def) apply (subst Bit1_def) by auto  
    1.15 -lemmas bitneg = neg1 neg2 neg3 neg4
    1.16 -
    1.17 -(* iszero for bit strings *)
    1.18 -lemma iszero1: "iszero Int.Pls = True" by (simp add: Int.Pls_def iszero_def)
    1.19 -lemma iszero2: "iszero Int.Min = False" apply (subst Int.Min_def) apply (subst iszero_def) by simp
    1.20 -lemma iszero3: "iszero (Int.Bit0 x) = iszero x" apply (subst Int.Bit0_def) apply (subst iszero_def)+ by auto
    1.21 -lemma iszero4: "iszero (Int.Bit1 x) = False" apply (subst Int.Bit1_def) apply (subst iszero_def)+  apply simp by arith
    1.22 -lemmas bitiszero = iszero1 iszero2 iszero3 iszero4
    1.23 -
    1.24 -(* lezero for bit strings *)
    1.25 -definition "lezero x \<longleftrightarrow> x \<le> 0"
    1.26 -lemma lezero1: "lezero Int.Pls = True" unfolding Int.Pls_def lezero_def by auto
    1.27 -lemma lezero2: "lezero Int.Min = True" unfolding Int.Min_def lezero_def by auto
    1.28 -lemma lezero3: "lezero (Int.Bit0 x) = lezero x" unfolding Int.Bit0_def lezero_def by auto
    1.29 -lemma lezero4: "lezero (Int.Bit1 x) = neg x" unfolding Int.Bit1_def lezero_def neg_def by auto
    1.30 -lemmas bitlezero = lezero1 lezero2 lezero3 lezero4
    1.31 -
    1.32  (* equality for bit strings *)
    1.33 -lemmas biteq = eq_bin_simps
    1.34 +lemmas biteq = eq_num_simps
    1.35  
    1.36  (* x < y for bit strings *)
    1.37 -lemmas bitless = less_bin_simps
    1.38 +lemmas bitless = less_num_simps
    1.39  
    1.40  (* x \<le> y for bit strings *)
    1.41 -lemmas bitle = le_bin_simps
    1.42 -
    1.43 -(* succ for bit strings *)
    1.44 -lemmas bitsucc = succ_bin_simps
    1.45 -
    1.46 -(* pred for bit strings *)
    1.47 -lemmas bitpred = pred_bin_simps
    1.48 -
    1.49 -(* unary minus for bit strings *)
    1.50 -lemmas bituminus = minus_bin_simps
    1.51 +lemmas bitle = le_num_simps
    1.52  
    1.53  (* addition for bit strings *)
    1.54 -lemmas bitadd = add_bin_simps
    1.55 +lemmas bitadd = add_num_simps
    1.56  
    1.57  (* multiplication for bit strings *) 
    1.58 -lemma mult_Pls_right: "x * Int.Pls = Int.Pls" by (simp add: Pls_def)
    1.59 -lemma mult_Min_right: "x * Int.Min = - x" by (subst mult_commute) simp 
    1.60 -lemma multb0x: "(Int.Bit0 x) * y = Int.Bit0 (x * y)" by (rule mult_Bit0)
    1.61 -lemma multxb0: "x * (Int.Bit0 y) = Int.Bit0 (x * y)" unfolding Bit0_def by simp
    1.62 -lemma multb1: "(Int.Bit1 x) * (Int.Bit1 y) = Int.Bit1 (Int.Bit0 (x * y) + x + y)"
    1.63 -  unfolding Bit0_def Bit1_def by (simp add: algebra_simps)
    1.64 -lemmas bitmul = mult_Pls mult_Min mult_Pls_right mult_Min_right multb0x multxb0 multb1
    1.65 +lemmas bitmul = mult_num_simps
    1.66  
    1.67 -lemmas bitarith = bitnorm bitiszero bitneg bitlezero biteq bitless bitle bitsucc bitpred bituminus bitadd bitmul 
    1.68 -
    1.69 -definition "nat_norm_number_of (x::nat) = x"
    1.70 -
    1.71 -lemma nat_norm_number_of: "nat_norm_number_of (number_of w) = (if lezero w then 0 else number_of w)"
    1.72 -  apply (simp add: nat_norm_number_of_def)
    1.73 -  unfolding lezero_def iszero_def neg_def
    1.74 -  apply (simp add: numeral_simps)
    1.75 -  done
    1.76 +lemmas bitarith = arith_simps
    1.77  
    1.78  (* Normalization of nat literals *)
    1.79 -lemma natnorm0: "(0::nat) = number_of (Int.Pls)" by auto
    1.80 -lemma natnorm1: "(1 :: nat) = number_of (Int.Bit1 Int.Pls)"  by auto 
    1.81 -lemmas natnorm = natnorm0 natnorm1 nat_norm_number_of
    1.82 -
    1.83 -(* Suc *)
    1.84 -lemma natsuc: "Suc (number_of x) = (if neg x then 1 else number_of (Int.succ x))" by (auto simp add: number_of_is_id)
    1.85 -
    1.86 -(* Addition for nat *)
    1.87 -lemma natadd: "number_of x + ((number_of y)::nat) = (if neg x then (number_of y) else (if neg y then number_of x else (number_of (x + y))))"
    1.88 -  unfolding nat_number_of_def number_of_is_id neg_def
    1.89 -  by auto
    1.90 -
    1.91 -(* Subtraction for nat *)
    1.92 -lemma natsub: "(number_of x) - ((number_of y)::nat) = 
    1.93 -  (if neg x then 0 else (if neg y then number_of x else (nat_norm_number_of (number_of (x + (- y))))))"
    1.94 -  unfolding nat_norm_number_of
    1.95 -  by (auto simp add: number_of_is_id neg_def lezero_def iszero_def Let_def nat_number_of_def)
    1.96 -
    1.97 -(* Multiplication for nat *)
    1.98 -lemma natmul: "(number_of x) * ((number_of y)::nat) = 
    1.99 -  (if neg x then 0 else (if neg y then 0 else number_of (x * y)))"
   1.100 -  unfolding nat_number_of_def number_of_is_id neg_def
   1.101 -  by (simp add: nat_mult_distrib)
   1.102 -
   1.103 -lemma nateq: "(((number_of x)::nat) = (number_of y)) = ((lezero x \<and> lezero y) \<or> (x = y))"
   1.104 -  by (auto simp add: iszero_def lezero_def neg_def number_of_is_id)
   1.105 -
   1.106 -lemma natless: "(((number_of x)::nat) < (number_of y)) = ((x < y) \<and> (\<not> (lezero y)))"
   1.107 -  by (simp add: lezero_def numeral_simps not_le)
   1.108 -
   1.109 -lemma natle: "(((number_of x)::nat) \<le> (number_of y)) = (y < x \<longrightarrow> lezero x)"
   1.110 -  by (auto simp add: number_of_is_id lezero_def nat_number_of_def)
   1.111 +lemmas natnorm = one_eq_Numeral1_nat
   1.112  
   1.113  fun natfac :: "nat \<Rightarrow> nat"
   1.114    where "natfac n = (if n = 0 then 1 else n * (natfac (n - 1)))"
   1.115  
   1.116 -lemmas compute_natarith = bitarith natnorm natsuc natadd natsub natmul nateq natless natle natfac.simps
   1.117 -
   1.118 -lemma number_eq: "(((number_of x)::'a::{number_ring, linordered_idom}) = (number_of y)) = (x = y)"
   1.119 -  unfolding number_of_eq
   1.120 -  apply simp
   1.121 -  done
   1.122 +lemmas compute_natarith =
   1.123 +  arith_simps rel_simps
   1.124 +  diff_nat_numeral nat_numeral nat_0 nat_neg_numeral
   1.125 +  numeral_1_eq_1 [symmetric]
   1.126 +  numeral_1_eq_Suc_0 [symmetric]
   1.127 +  Suc_numeral natfac.simps
   1.128  
   1.129 -lemma number_le: "(((number_of x)::'a::{number_ring, linordered_idom}) \<le>  (number_of y)) = (x \<le> y)"
   1.130 -  unfolding number_of_eq
   1.131 -  apply simp
   1.132 -  done
   1.133 -
   1.134 -lemma number_less: "(((number_of x)::'a::{number_ring, linordered_idom}) <  (number_of y)) = (x < y)"
   1.135 -  unfolding number_of_eq 
   1.136 -  apply simp
   1.137 -  done
   1.138 +lemmas number_norm = numeral_1_eq_1[symmetric]
   1.139  
   1.140 -lemma number_diff: "((number_of x)::'a::{number_ring, linordered_idom}) - number_of y = number_of (x + (- y))"
   1.141 -  apply (subst diff_number_of_eq)
   1.142 -  apply simp
   1.143 -  done
   1.144 -
   1.145 -lemmas number_norm = number_of_Pls[symmetric] numeral_1_eq_1[symmetric]
   1.146 -
   1.147 -lemmas compute_numberarith = number_of_minus[symmetric] number_of_add[symmetric] number_diff number_of_mult[symmetric] number_norm number_eq number_le number_less
   1.148 +lemmas compute_numberarith =
   1.149 +  arith_simps rel_simps number_norm
   1.150  
   1.151 -lemma compute_real_of_nat_number_of: "real ((number_of v)::nat) = (if neg v then 0 else number_of v)"
   1.152 -  by (simp only: real_of_nat_number_of number_of_is_id)
   1.153 -
   1.154 -lemma compute_nat_of_int_number_of: "nat ((number_of v)::int) = (number_of v)"
   1.155 -  by simp
   1.156 +lemmas compute_num_conversions =
   1.157 +  real_of_nat_numeral real_of_nat_zero
   1.158 +  nat_numeral nat_0 nat_neg_numeral
   1.159 +  real_numeral real_of_int_zero
   1.160  
   1.161 -lemmas compute_num_conversions = compute_real_of_nat_number_of compute_nat_of_int_number_of real_number_of
   1.162 -
   1.163 -lemmas zpowerarith = zpower_number_of_even
   1.164 -  zpower_number_of_odd[simplified zero_eq_Numeral0_nring one_eq_Numeral1_nring]
   1.165 -  zpower_Pls zpower_Min
   1.166 +lemmas zpowerarith = zpower_numeral_even zpower_numeral_odd zpower_Pls int_pow_1
   1.167  
   1.168  (* div, mod *)
   1.169  
   1.170 @@ -162,26 +64,19 @@
   1.171  
   1.172  (* collecting all the theorems *)
   1.173  
   1.174 -lemma even_Pls: "even (Int.Pls) = True"
   1.175 -  apply (unfold Pls_def even_def)
   1.176 +lemma even_0_int: "even (0::int) = True"
   1.177    by simp
   1.178  
   1.179 -lemma even_Min: "even (Int.Min) = False"
   1.180 -  apply (unfold Min_def even_def)
   1.181 +lemma even_One_int: "even (numeral Num.One :: int) = False"
   1.182    by simp
   1.183  
   1.184 -lemma even_B0: "even (Int.Bit0 x) = True"
   1.185 -  apply (unfold Bit0_def)
   1.186 +lemma even_Bit0_int: "even (numeral (Num.Bit0 x) :: int) = True"
   1.187    by simp
   1.188  
   1.189 -lemma even_B1: "even (Int.Bit1 x) = False"
   1.190 -  apply (unfold Bit1_def)
   1.191 +lemma even_Bit1_int: "even (numeral (Num.Bit1 x) :: int) = False"
   1.192    by simp
   1.193  
   1.194 -lemma even_number_of: "even ((number_of w)::int) = even w"
   1.195 -  by (simp only: number_of_is_id)
   1.196 -
   1.197 -lemmas compute_even = even_Pls even_Min even_B0 even_B1 even_number_of
   1.198 +lemmas compute_even = even_0_int even_One_int even_Bit0_int even_Bit1_int
   1.199  
   1.200  lemmas compute_numeral = compute_if compute_let compute_pair compute_bool 
   1.201                           compute_natarith compute_numberarith max_def min_def compute_num_conversions zpowerarith compute_div_mod compute_even