src/HOL/Integ/Numeral.thy
changeset 15013 34264f5e4691
child 15131 c69542757a4d
equal deleted inserted replaced
15012:28fa57b57209 15013:34264f5e4691
       
     1 (*  Title:	HOL/Integ/Numeral.thy
       
     2     ID:         $Id$
       
     3     Author:	Lawrence C Paulson, Cambridge University Computer Laboratory
       
     4     Copyright	1994  University of Cambridge
       
     5 *)
       
     6 
       
     7 header{*Arithmetic on Binary Integers*}
       
     8 
       
     9 theory Numeral = IntDef
       
    10 files "Tools/numeral_syntax.ML":
       
    11 
       
    12 text{* The file @{text numeral_syntax.ML} hides the constructors Pls and Min.
       
    13    Only qualified access Numeral.Pls and Numeral.Min is allowed.
       
    14    We do not hide Bit because we need the BIT infix syntax.*}
       
    15 
       
    16 text{*This formalization defines binary arithmetic in terms of the integers
       
    17 rather than using a datatype. This avoids multiple representations (leading
       
    18 zeroes, etc.)  See @{text "ZF/Integ/twos-compl.ML"}, function @{text
       
    19 int_of_binary}, for the numerical interpretation.
       
    20 
       
    21 The representation expects that @{text "(m mod 2)"} is 0 or 1,
       
    22 even if m is negative;
       
    23 For instance, @{text "-5 div 2 = -3"} and @{text "-5 mod 2 = 1"}; thus
       
    24 @{text "-5 = (-3)*2 + 1"}.
       
    25 *}
       
    26 
       
    27 
       
    28 typedef (Bin)
       
    29   bin = "UNIV::int set"
       
    30     by (auto)
       
    31 
       
    32 constdefs
       
    33   Pls :: "bin"
       
    34    "Pls == Abs_Bin 0"
       
    35 
       
    36   Min :: "bin"
       
    37    "Min == Abs_Bin (- 1)"
       
    38 
       
    39   Bit :: "[bin,bool] => bin"    (infixl "BIT" 90)
       
    40    --{*That is, 2w+b*}
       
    41    "w BIT b == Abs_Bin ((if b then 1 else 0) + Rep_Bin w + Rep_Bin w)"
       
    42 
       
    43 
       
    44 axclass
       
    45   number < type  -- {* for numeric types: nat, int, real, \dots *}
       
    46 
       
    47 consts
       
    48   number_of :: "bin => 'a::number"
       
    49 
       
    50 syntax
       
    51   "_Numeral" :: "num_const => 'a"    ("_")
       
    52   Numeral0 :: 'a
       
    53   Numeral1 :: 'a
       
    54 
       
    55 translations
       
    56   "Numeral0" == "number_of Numeral.Pls"
       
    57   "Numeral1" == "number_of (Numeral.Pls BIT True)"
       
    58 
       
    59 
       
    60 setup NumeralSyntax.setup
       
    61 
       
    62 syntax (xsymbols)
       
    63   "_square" :: "'a => 'a"  ("(_\<twosuperior>)" [1000] 999)
       
    64 syntax (HTML output)
       
    65   "_square" :: "'a => 'a"  ("(_\<twosuperior>)" [1000] 999)
       
    66 syntax (output)
       
    67   "_square" :: "'a => 'a"  ("(_ ^/ 2)" [81] 80)
       
    68 translations
       
    69   "x\<twosuperior>" == "x^2"
       
    70   "x\<twosuperior>" <= "x^(2::nat)"
       
    71 
       
    72 
       
    73 lemma Let_number_of [simp]: "Let (number_of v) f == f (number_of v)"
       
    74   -- {* Unfold all @{text let}s involving constants *}
       
    75   by (simp add: Let_def)
       
    76 
       
    77 lemma Let_0 [simp]: "Let 0 f == f 0"
       
    78   by (simp add: Let_def)
       
    79 
       
    80 lemma Let_1 [simp]: "Let 1 f == f 1"
       
    81   by (simp add: Let_def)
       
    82 
       
    83 
       
    84 constdefs
       
    85   bin_succ  :: "bin=>bin"
       
    86    "bin_succ w == Abs_Bin(Rep_Bin w + 1)"
       
    87 
       
    88   bin_pred  :: "bin=>bin"
       
    89    "bin_pred w == Abs_Bin(Rep_Bin w - 1)"
       
    90 
       
    91   bin_minus  :: "bin=>bin"
       
    92    "bin_minus w == Abs_Bin(- (Rep_Bin w))"
       
    93 
       
    94   bin_add  :: "[bin,bin]=>bin"
       
    95    "bin_add v w == Abs_Bin(Rep_Bin v + Rep_Bin w)"
       
    96 
       
    97   bin_mult  :: "[bin,bin]=>bin"
       
    98    "bin_mult v w == Abs_Bin(Rep_Bin v * Rep_Bin w)"
       
    99 
       
   100 
       
   101 lemmas Bin_simps = 
       
   102        bin_succ_def bin_pred_def bin_minus_def bin_add_def bin_mult_def
       
   103        Pls_def Min_def Bit_def Abs_Bin_inverse Rep_Bin_inverse Bin_def
       
   104 
       
   105 text{*Removal of leading zeroes*}
       
   106 lemma Pls_0_eq [simp]: "Numeral.Pls BIT False = Numeral.Pls"
       
   107 by (simp add: Bin_simps)
       
   108 
       
   109 lemma Min_1_eq [simp]: "Numeral.Min BIT True = Numeral.Min"
       
   110 by (simp add: Bin_simps)
       
   111 
       
   112 subsection{*The Functions @{term bin_succ},  @{term bin_pred} and @{term bin_minus}*}
       
   113 
       
   114 lemma bin_succ_Pls [simp]: "bin_succ Numeral.Pls = Numeral.Pls BIT True"
       
   115 by (simp add: Bin_simps) 
       
   116 
       
   117 lemma bin_succ_Min [simp]: "bin_succ Numeral.Min = Numeral.Pls"
       
   118 by (simp add: Bin_simps) 
       
   119 
       
   120 lemma bin_succ_1 [simp]: "bin_succ(w BIT True) = (bin_succ w) BIT False"
       
   121 by (simp add: Bin_simps add_ac) 
       
   122 
       
   123 lemma bin_succ_0 [simp]: "bin_succ(w BIT False) = w BIT True"
       
   124 by (simp add: Bin_simps add_ac) 
       
   125 
       
   126 lemma bin_pred_Pls [simp]: "bin_pred Numeral.Pls = Numeral.Min"
       
   127 by (simp add: Bin_simps) 
       
   128 
       
   129 lemma bin_pred_Min [simp]: "bin_pred Numeral.Min = Numeral.Min BIT False"
       
   130 by (simp add: Bin_simps diff_minus) 
       
   131 
       
   132 lemma bin_pred_1 [simp]: "bin_pred(w BIT True) = w BIT False"
       
   133 by (simp add: Bin_simps) 
       
   134 
       
   135 lemma bin_pred_0 [simp]: "bin_pred(w BIT False) = (bin_pred w) BIT True"
       
   136 by (simp add: Bin_simps diff_minus add_ac) 
       
   137 
       
   138 lemma bin_minus_Pls [simp]: "bin_minus Numeral.Pls = Numeral.Pls"
       
   139 by (simp add: Bin_simps) 
       
   140 
       
   141 lemma bin_minus_Min [simp]: "bin_minus Numeral.Min = Numeral.Pls BIT True"
       
   142 by (simp add: Bin_simps) 
       
   143 
       
   144 lemma bin_minus_1 [simp]:
       
   145      "bin_minus (w BIT True) = bin_pred (bin_minus w) BIT True"
       
   146 by (simp add: Bin_simps add_ac diff_minus) 
       
   147 
       
   148  lemma bin_minus_0 [simp]: "bin_minus(w BIT False) = (bin_minus w) BIT False"
       
   149 by (simp add: Bin_simps) 
       
   150 
       
   151 
       
   152 subsection{*Binary Addition and Multiplication:
       
   153          @{term bin_add} and @{term bin_mult}*}
       
   154 
       
   155 lemma bin_add_Pls [simp]: "bin_add Numeral.Pls w = w"
       
   156 by (simp add: Bin_simps) 
       
   157 
       
   158 lemma bin_add_Min [simp]: "bin_add Numeral.Min w = bin_pred w"
       
   159 by (simp add: Bin_simps diff_minus add_ac) 
       
   160 
       
   161 lemma bin_add_BIT_11 [simp]:
       
   162      "bin_add (v BIT True) (w BIT True) = bin_add v (bin_succ w) BIT False"
       
   163 by (simp add: Bin_simps add_ac)
       
   164 
       
   165 lemma bin_add_BIT_10 [simp]:
       
   166      "bin_add (v BIT True) (w BIT False) = (bin_add v w) BIT True"
       
   167 by (simp add: Bin_simps add_ac)
       
   168 
       
   169 lemma bin_add_BIT_0 [simp]:
       
   170      "bin_add (v BIT False) (w BIT y) = bin_add v w BIT y"
       
   171 by (simp add: Bin_simps add_ac)
       
   172 
       
   173 lemma bin_add_Pls_right [simp]: "bin_add w Numeral.Pls = w"
       
   174 by (simp add: Bin_simps) 
       
   175 
       
   176 lemma bin_add_Min_right [simp]: "bin_add w Numeral.Min = bin_pred w"
       
   177 by (simp add: Bin_simps diff_minus) 
       
   178 
       
   179 lemma bin_mult_Pls [simp]: "bin_mult Numeral.Pls w = Numeral.Pls"
       
   180 by (simp add: Bin_simps) 
       
   181 
       
   182 lemma bin_mult_Min [simp]: "bin_mult Numeral.Min w = bin_minus w"
       
   183 by (simp add: Bin_simps) 
       
   184 
       
   185 lemma bin_mult_1 [simp]:
       
   186      "bin_mult (v BIT True) w = bin_add ((bin_mult v w) BIT False) w"
       
   187 by (simp add: Bin_simps add_ac left_distrib)
       
   188 
       
   189 lemma bin_mult_0 [simp]: "bin_mult (v BIT False) w = (bin_mult v w) BIT False"
       
   190 by (simp add: Bin_simps left_distrib)
       
   191 
       
   192 
       
   193 
       
   194 subsection{*Converting Numerals to Rings: @{term number_of}*}
       
   195 
       
   196 axclass number_ring \<subseteq> number, comm_ring_1
       
   197   number_of_eq: "number_of w = of_int (Rep_Bin w)"
       
   198 
       
   199 lemma number_of_succ:
       
   200      "number_of(bin_succ w) = (1 + number_of w ::'a::number_ring)"
       
   201 by (simp add: number_of_eq Bin_simps)
       
   202 
       
   203 lemma number_of_pred:
       
   204      "number_of(bin_pred w) = (- 1 + number_of w ::'a::number_ring)"
       
   205 by (simp add: number_of_eq Bin_simps)
       
   206 
       
   207 lemma number_of_minus:
       
   208      "number_of(bin_minus w) = (- (number_of w)::'a::number_ring)"
       
   209 by (simp add: number_of_eq Bin_simps) 
       
   210 
       
   211 lemma number_of_add:
       
   212      "number_of(bin_add v w) = (number_of v + number_of w::'a::number_ring)"
       
   213 by (simp add: number_of_eq Bin_simps) 
       
   214 
       
   215 lemma number_of_mult:
       
   216      "number_of(bin_mult v w) = (number_of v * number_of w::'a::number_ring)"
       
   217 by (simp add: number_of_eq Bin_simps) 
       
   218 
       
   219 text{*The correctness of shifting.  But it doesn't seem to give a measurable
       
   220   speed-up.*}
       
   221 lemma double_number_of_BIT:
       
   222      "(1+1) * number_of w = (number_of (w BIT False) ::'a::number_ring)"
       
   223 by (simp add: number_of_eq Bin_simps left_distrib) 
       
   224 
       
   225 text{*Converting numerals 0 and 1 to their abstract versions*}
       
   226 lemma numeral_0_eq_0 [simp]: "Numeral0 = (0::'a::number_ring)"
       
   227 by (simp add: number_of_eq Bin_simps) 
       
   228 
       
   229 lemma numeral_1_eq_1 [simp]: "Numeral1 = (1::'a::number_ring)"
       
   230 by (simp add: number_of_eq Bin_simps) 
       
   231 
       
   232 text{*Special-case simplification for small constants*}
       
   233 
       
   234 text{*Unary minus for the abstract constant 1. Cannot be inserted
       
   235   as a simprule until later: it is @{text number_of_Min} re-oriented!*}
       
   236 lemma numeral_m1_eq_minus_1: "(-1::'a::number_ring) = - 1"
       
   237 by (simp add: number_of_eq Bin_simps) 
       
   238 
       
   239 
       
   240 lemma mult_minus1 [simp]: "-1 * z = -(z::'a::number_ring)"
       
   241 by (simp add: numeral_m1_eq_minus_1)
       
   242 
       
   243 lemma mult_minus1_right [simp]: "z * -1 = -(z::'a::number_ring)"
       
   244 by (simp add: numeral_m1_eq_minus_1)
       
   245 
       
   246 (*Negation of a coefficient*)
       
   247 lemma minus_number_of_mult [simp]:
       
   248      "- (number_of w) * z = number_of(bin_minus w) * (z::'a::number_ring)"
       
   249 by (simp add: number_of_minus)
       
   250 
       
   251 text{*Subtraction*}
       
   252 lemma diff_number_of_eq:
       
   253      "number_of v - number_of w =
       
   254       (number_of(bin_add v (bin_minus w))::'a::number_ring)"
       
   255 by (simp add: diff_minus number_of_add number_of_minus)
       
   256 
       
   257 
       
   258 lemma number_of_Pls: "number_of Numeral.Pls = (0::'a::number_ring)"
       
   259 by (simp add: number_of_eq Bin_simps) 
       
   260 
       
   261 lemma number_of_Min: "number_of Numeral.Min = (- 1::'a::number_ring)"
       
   262 by (simp add: number_of_eq Bin_simps) 
       
   263 
       
   264 lemma number_of_BIT:
       
   265      "number_of(w BIT x) = (if x then 1 else (0::'a::number_ring)) +
       
   266 	                   (number_of w) + (number_of w)"
       
   267 by (simp add: number_of_eq Bin_simps) 
       
   268 
       
   269 
       
   270 
       
   271 subsection{*Equality of Binary Numbers*}
       
   272 
       
   273 text{*First version by Norbert Voelker*}
       
   274 
       
   275 lemma eq_number_of_eq:
       
   276   "((number_of x::'a::number_ring) = number_of y) =
       
   277    iszero (number_of (bin_add x (bin_minus y)) :: 'a)"
       
   278 by (simp add: iszero_def compare_rls number_of_add number_of_minus)
       
   279 
       
   280 lemma iszero_number_of_Pls: "iszero ((number_of Numeral.Pls)::'a::number_ring)"
       
   281 by (simp add: iszero_def numeral_0_eq_0)
       
   282 
       
   283 lemma nonzero_number_of_Min: "~ iszero ((number_of Numeral.Min)::'a::number_ring)"
       
   284 by (simp add: iszero_def numeral_m1_eq_minus_1 eq_commute)
       
   285 
       
   286 
       
   287 subsection{*Comparisons, for Ordered Rings*}
       
   288 
       
   289 lemma double_eq_0_iff: "(a + a = 0) = (a = (0::'a::ordered_idom))"
       
   290 proof -
       
   291   have "a + a = (1+1)*a" by (simp add: left_distrib)
       
   292   with zero_less_two [where 'a = 'a]
       
   293   show ?thesis by force
       
   294 qed
       
   295 
       
   296 lemma le_imp_0_less: 
       
   297   assumes le: "0 \<le> z" shows "(0::int) < 1 + z"
       
   298 proof -
       
   299   have "0 \<le> z" .
       
   300   also have "... < z + 1" by (rule less_add_one) 
       
   301   also have "... = 1 + z" by (simp add: add_ac)
       
   302   finally show "0 < 1 + z" .
       
   303 qed
       
   304 
       
   305 lemma odd_nonzero: "1 + z + z \<noteq> (0::int)";
       
   306 proof (cases z rule: int_cases)
       
   307   case (nonneg n)
       
   308   have le: "0 \<le> z+z" by (simp add: nonneg add_increasing) 
       
   309   thus ?thesis using  le_imp_0_less [OF le]
       
   310     by (auto simp add: add_assoc) 
       
   311 next
       
   312   case (neg n)
       
   313   show ?thesis
       
   314   proof
       
   315     assume eq: "1 + z + z = 0"
       
   316     have "0 < 1 + (int n + int n)"
       
   317       by (simp add: le_imp_0_less add_increasing) 
       
   318     also have "... = - (1 + z + z)" 
       
   319       by (simp add: neg add_assoc [symmetric]) 
       
   320     also have "... = 0" by (simp add: eq) 
       
   321     finally have "0<0" ..
       
   322     thus False by blast
       
   323   qed
       
   324 qed
       
   325 
       
   326 
       
   327 text{*The premise involving @{term Ints} prevents @{term "a = 1/2"}.*}
       
   328 lemma Ints_odd_nonzero: "a \<in> Ints ==> 1 + a + a \<noteq> (0::'a::ordered_idom)"
       
   329 proof (unfold Ints_def) 
       
   330   assume "a \<in> range of_int"
       
   331   then obtain z where a: "a = of_int z" ..
       
   332   show ?thesis
       
   333   proof
       
   334     assume eq: "1 + a + a = 0"
       
   335     hence "of_int (1 + z + z) = (of_int 0 :: 'a)" by (simp add: a)
       
   336     hence "1 + z + z = 0" by (simp only: of_int_eq_iff)
       
   337     with odd_nonzero show False by blast
       
   338   qed
       
   339 qed 
       
   340 
       
   341 lemma Ints_number_of: "(number_of w :: 'a::number_ring) \<in> Ints"
       
   342 by (simp add: number_of_eq Ints_def) 
       
   343 
       
   344 
       
   345 lemma iszero_number_of_BIT:
       
   346      "iszero (number_of (w BIT x)::'a) = 
       
   347       (~x & iszero (number_of w::'a::{ordered_idom,number_ring}))"
       
   348 by (simp add: iszero_def number_of_eq Bin_simps double_eq_0_iff 
       
   349               Ints_odd_nonzero Ints_def)
       
   350 
       
   351 lemma iszero_number_of_0:
       
   352      "iszero (number_of (w BIT False) :: 'a::{ordered_idom,number_ring}) = 
       
   353       iszero (number_of w :: 'a)"
       
   354 by (simp only: iszero_number_of_BIT simp_thms)
       
   355 
       
   356 lemma iszero_number_of_1:
       
   357      "~ iszero (number_of (w BIT True)::'a::{ordered_idom,number_ring})"
       
   358 by (simp only: iszero_number_of_BIT simp_thms)
       
   359 
       
   360 
       
   361 
       
   362 subsection{*The Less-Than Relation*}
       
   363 
       
   364 lemma less_number_of_eq_neg:
       
   365     "((number_of x::'a::{ordered_idom,number_ring}) < number_of y)
       
   366      = neg (number_of (bin_add x (bin_minus y)) :: 'a)"
       
   367 apply (subst less_iff_diff_less_0) 
       
   368 apply (simp add: neg_def diff_minus number_of_add number_of_minus)
       
   369 done
       
   370 
       
   371 text{*If @{term Numeral0} is rewritten to 0 then this rule can't be applied:
       
   372   @{term Numeral0} IS @{term "number_of Numeral.Pls"} *}
       
   373 lemma not_neg_number_of_Pls:
       
   374      "~ neg (number_of Numeral.Pls ::'a::{ordered_idom,number_ring})"
       
   375 by (simp add: neg_def numeral_0_eq_0)
       
   376 
       
   377 lemma neg_number_of_Min:
       
   378      "neg (number_of Numeral.Min ::'a::{ordered_idom,number_ring})"
       
   379 by (simp add: neg_def zero_less_one numeral_m1_eq_minus_1)
       
   380 
       
   381 lemma double_less_0_iff: "(a + a < 0) = (a < (0::'a::ordered_idom))"
       
   382 proof -
       
   383   have "(a + a < 0) = ((1+1)*a < 0)" by (simp add: left_distrib)
       
   384   also have "... = (a < 0)"
       
   385     by (simp add: mult_less_0_iff zero_less_two 
       
   386                   order_less_not_sym [OF zero_less_two]) 
       
   387   finally show ?thesis .
       
   388 qed
       
   389 
       
   390 lemma odd_less_0: "(1 + z + z < 0) = (z < (0::int))";
       
   391 proof (cases z rule: int_cases)
       
   392   case (nonneg n)
       
   393   thus ?thesis by (simp add: linorder_not_less add_assoc add_increasing
       
   394                              le_imp_0_less [THEN order_less_imp_le])  
       
   395 next
       
   396   case (neg n)
       
   397   thus ?thesis by (simp del: int_Suc
       
   398 			add: int_Suc0_eq_1 [symmetric] zadd_int compare_rls)
       
   399 qed
       
   400 
       
   401 text{*The premise involving @{term Ints} prevents @{term "a = 1/2"}.*}
       
   402 lemma Ints_odd_less_0: 
       
   403      "a \<in> Ints ==> (1 + a + a < 0) = (a < (0::'a::ordered_idom))";
       
   404 proof (unfold Ints_def) 
       
   405   assume "a \<in> range of_int"
       
   406   then obtain z where a: "a = of_int z" ..
       
   407   hence "((1::'a) + a + a < 0) = (of_int (1 + z + z) < (of_int 0 :: 'a))"
       
   408     by (simp add: a)
       
   409   also have "... = (z < 0)" by (simp only: of_int_less_iff odd_less_0)
       
   410   also have "... = (a < 0)" by (simp add: a)
       
   411   finally show ?thesis .
       
   412 qed
       
   413 
       
   414 lemma neg_number_of_BIT:
       
   415      "neg (number_of (w BIT x)::'a) = 
       
   416       neg (number_of w :: 'a::{ordered_idom,number_ring})"
       
   417 by (simp add: neg_def number_of_eq Bin_simps double_less_0_iff
       
   418               Ints_odd_less_0 Ints_def)
       
   419 
       
   420 
       
   421 text{*Less-Than or Equals*}
       
   422 
       
   423 text{*Reduces @{term "a\<le>b"} to @{term "~ (b<a)"} for ALL numerals*}
       
   424 lemmas le_number_of_eq_not_less =
       
   425        linorder_not_less [of "number_of w" "number_of v", symmetric, 
       
   426                           standard]
       
   427 
       
   428 lemma le_number_of_eq:
       
   429     "((number_of x::'a::{ordered_idom,number_ring}) \<le> number_of y)
       
   430      = (~ (neg (number_of (bin_add y (bin_minus x)) :: 'a)))"
       
   431 by (simp add: le_number_of_eq_not_less less_number_of_eq_neg)
       
   432 
       
   433 
       
   434 text{*Absolute value (@{term abs})*}
       
   435 
       
   436 lemma abs_number_of:
       
   437      "abs(number_of x::'a::{ordered_idom,number_ring}) =
       
   438       (if number_of x < (0::'a) then -number_of x else number_of x)"
       
   439 by (simp add: abs_if)
       
   440 
       
   441 
       
   442 text{*Re-orientation of the equation nnn=x*}
       
   443 lemma number_of_reorient: "(number_of w = x) = (x = number_of w)"
       
   444 by auto
       
   445 
       
   446 
       
   447 
       
   448 
       
   449 subsection{*Simplification of arithmetic operations on integer constants.*}
       
   450 
       
   451 lemmas bin_arith_extra_simps = 
       
   452        number_of_add [symmetric]
       
   453        number_of_minus [symmetric] numeral_m1_eq_minus_1 [symmetric]
       
   454        number_of_mult [symmetric]
       
   455        diff_number_of_eq abs_number_of 
       
   456 
       
   457 text{*For making a minimal simpset, one must include these default simprules.
       
   458   Also include @{text simp_thms} or at least @{term "(~False)=True"} *}
       
   459 lemmas bin_arith_simps = 
       
   460        Pls_0_eq Min_1_eq
       
   461        bin_pred_Pls bin_pred_Min bin_pred_1 bin_pred_0
       
   462        bin_succ_Pls bin_succ_Min bin_succ_1 bin_succ_0
       
   463        bin_add_Pls bin_add_Min bin_add_BIT_0 bin_add_BIT_10 bin_add_BIT_11
       
   464        bin_minus_Pls bin_minus_Min bin_minus_1 bin_minus_0
       
   465        bin_mult_Pls bin_mult_Min bin_mult_1 bin_mult_0 
       
   466        bin_add_Pls_right bin_add_Min_right
       
   467        abs_zero abs_one bin_arith_extra_simps
       
   468 
       
   469 text{*Simplification of relational operations*}
       
   470 lemmas bin_rel_simps = 
       
   471        eq_number_of_eq iszero_number_of_Pls nonzero_number_of_Min
       
   472        iszero_number_of_0 iszero_number_of_1
       
   473        less_number_of_eq_neg
       
   474        not_neg_number_of_Pls not_neg_0 not_neg_1 not_iszero_1
       
   475        neg_number_of_Min neg_number_of_BIT
       
   476        le_number_of_eq
       
   477 
       
   478 declare bin_arith_extra_simps [simp]
       
   479 declare bin_rel_simps [simp]
       
   480 
       
   481 
       
   482 subsection{*Simplification of arithmetic when nested to the right*}
       
   483 
       
   484 lemma add_number_of_left [simp]:
       
   485      "number_of v + (number_of w + z) =
       
   486       (number_of(bin_add v w) + z::'a::number_ring)"
       
   487 by (simp add: add_assoc [symmetric])
       
   488 
       
   489 lemma mult_number_of_left [simp]:
       
   490     "number_of v * (number_of w * z) =
       
   491      (number_of(bin_mult v w) * z::'a::number_ring)"
       
   492 by (simp add: mult_assoc [symmetric])
       
   493 
       
   494 lemma add_number_of_diff1:
       
   495     "number_of v + (number_of w - c) = 
       
   496      number_of(bin_add v w) - (c::'a::number_ring)"
       
   497 by (simp add: diff_minus add_number_of_left)
       
   498 
       
   499 lemma add_number_of_diff2 [simp]: "number_of v + (c - number_of w) =
       
   500      number_of (bin_add v (bin_minus w)) + (c::'a::number_ring)"
       
   501 apply (subst diff_number_of_eq [symmetric])
       
   502 apply (simp only: compare_rls)
       
   503 done
       
   504 
       
   505 end