405 apply (rule_tac a=x in add_right_imp_eq) |
405 apply (rule_tac a=x in add_right_imp_eq) |
406 apply (simp add: add_assoc minus_add_cancel) |
406 apply (simp add: add_assoc minus_add_cancel) |
407 apply (simp add: add_assoc [symmetric], simp add: add_assoc) |
407 apply (simp add: add_assoc [symmetric], simp add: add_assoc) |
408 apply (rule_tac a=x in add_left_imp_eq) |
408 apply (rule_tac a=x in add_left_imp_eq) |
409 apply (rule_tac a=x in add_right_imp_eq) |
409 apply (rule_tac a=x in add_right_imp_eq) |
410 apply (simp add: add_assoc minus_add_cancel add_minus_cancel) |
410 apply (simp add: add_assoc) |
411 apply (simp add: add_assoc, simp add: add_assoc [symmetric]) |
411 apply (simp add: add_assoc, simp add: add_assoc [symmetric]) |
412 done |
412 done |
413 |
413 |
414 lemma is_num_add_left_commute: |
414 lemma is_num_add_left_commute: |
415 "\<lbrakk>is_num x; is_num y\<rbrakk> \<Longrightarrow> x + (y + z) = y + (x + z)" |
415 "\<lbrakk>is_num x; is_num y\<rbrakk> \<Longrightarrow> x + (y + z) = y + (x + z)" |
416 by (simp only: add_assoc [symmetric] is_num_add_commute) |
416 by (simp only: add_assoc [symmetric] is_num_add_commute) |
417 |
417 |
418 lemmas is_num_normalize = |
418 lemmas is_num_normalize = |
419 add_assoc is_num_add_commute is_num_add_left_commute |
419 add_assoc is_num_add_commute is_num_add_left_commute |
420 is_num.intros is_num_numeral |
420 is_num.intros is_num_numeral |
421 diff_minus minus_add add_minus_cancel minus_add_cancel |
421 minus_add |
422 |
422 |
423 definition dbl :: "'a \<Rightarrow> 'a" where "dbl x = x + x" |
423 definition dbl :: "'a \<Rightarrow> 'a" where "dbl x = x + x" |
424 definition dbl_inc :: "'a \<Rightarrow> 'a" where "dbl_inc x = x + x + 1" |
424 definition dbl_inc :: "'a \<Rightarrow> 'a" where "dbl_inc x = x + x + 1" |
425 definition dbl_dec :: "'a \<Rightarrow> 'a" where "dbl_dec x = x + x - 1" |
425 definition dbl_dec :: "'a \<Rightarrow> 'a" where "dbl_dec x = x + x - 1" |
426 |
426 |
433 lemma dbl_simps [simp]: |
433 lemma dbl_simps [simp]: |
434 "dbl (neg_numeral k) = neg_numeral (Bit0 k)" |
434 "dbl (neg_numeral k) = neg_numeral (Bit0 k)" |
435 "dbl 0 = 0" |
435 "dbl 0 = 0" |
436 "dbl 1 = 2" |
436 "dbl 1 = 2" |
437 "dbl (numeral k) = numeral (Bit0 k)" |
437 "dbl (numeral k) = numeral (Bit0 k)" |
438 unfolding dbl_def neg_numeral_def numeral.simps |
438 by (simp_all add: dbl_def neg_numeral_def numeral.simps minus_add) |
439 by (simp_all add: minus_add) |
|
440 |
439 |
441 lemma dbl_inc_simps [simp]: |
440 lemma dbl_inc_simps [simp]: |
442 "dbl_inc (neg_numeral k) = neg_numeral (BitM k)" |
441 "dbl_inc (neg_numeral k) = neg_numeral (BitM k)" |
443 "dbl_inc 0 = 1" |
442 "dbl_inc 0 = 1" |
444 "dbl_inc 1 = 3" |
443 "dbl_inc 1 = 3" |
445 "dbl_inc (numeral k) = numeral (Bit1 k)" |
444 "dbl_inc (numeral k) = numeral (Bit1 k)" |
446 unfolding dbl_inc_def neg_numeral_def numeral.simps numeral_BitM |
445 by (simp_all add: dbl_inc_def neg_numeral_def numeral.simps numeral_BitM is_num_normalize algebra_simps del: add_uminus_conv_diff) |
447 by (simp_all add: is_num_normalize) |
|
448 |
446 |
449 lemma dbl_dec_simps [simp]: |
447 lemma dbl_dec_simps [simp]: |
450 "dbl_dec (neg_numeral k) = neg_numeral (Bit1 k)" |
448 "dbl_dec (neg_numeral k) = neg_numeral (Bit1 k)" |
451 "dbl_dec 0 = -1" |
449 "dbl_dec 0 = -1" |
452 "dbl_dec 1 = 1" |
450 "dbl_dec 1 = 1" |
453 "dbl_dec (numeral k) = numeral (BitM k)" |
451 "dbl_dec (numeral k) = numeral (BitM k)" |
454 unfolding dbl_dec_def neg_numeral_def numeral.simps numeral_BitM |
452 by (simp_all add: dbl_dec_def neg_numeral_def numeral.simps numeral_BitM is_num_normalize) |
455 by (simp_all add: is_num_normalize) |
|
456 |
453 |
457 lemma sub_num_simps [simp]: |
454 lemma sub_num_simps [simp]: |
458 "sub One One = 0" |
455 "sub One One = 0" |
459 "sub One (Bit0 l) = neg_numeral (BitM l)" |
456 "sub One (Bit0 l) = neg_numeral (BitM l)" |
460 "sub One (Bit1 l) = neg_numeral (Bit0 l)" |
457 "sub One (Bit1 l) = neg_numeral (Bit0 l)" |
462 "sub (Bit1 k) One = numeral (Bit0 k)" |
459 "sub (Bit1 k) One = numeral (Bit0 k)" |
463 "sub (Bit0 k) (Bit0 l) = dbl (sub k l)" |
460 "sub (Bit0 k) (Bit0 l) = dbl (sub k l)" |
464 "sub (Bit0 k) (Bit1 l) = dbl_dec (sub k l)" |
461 "sub (Bit0 k) (Bit1 l) = dbl_dec (sub k l)" |
465 "sub (Bit1 k) (Bit0 l) = dbl_inc (sub k l)" |
462 "sub (Bit1 k) (Bit0 l) = dbl_inc (sub k l)" |
466 "sub (Bit1 k) (Bit1 l) = dbl (sub k l)" |
463 "sub (Bit1 k) (Bit1 l) = dbl (sub k l)" |
467 unfolding dbl_def dbl_dec_def dbl_inc_def sub_def |
464 by (simp_all add: dbl_def dbl_dec_def dbl_inc_def sub_def neg_numeral_def numeral.simps |
468 unfolding neg_numeral_def numeral.simps numeral_BitM |
465 numeral_BitM is_num_normalize del: add_uminus_conv_diff add: diff_conv_add_uminus) |
469 by (simp_all add: is_num_normalize) |
|
470 |
466 |
471 lemma add_neg_numeral_simps: |
467 lemma add_neg_numeral_simps: |
472 "numeral m + neg_numeral n = sub m n" |
468 "numeral m + neg_numeral n = sub m n" |
473 "neg_numeral m + numeral n = sub n m" |
469 "neg_numeral m + numeral n = sub n m" |
474 "neg_numeral m + neg_numeral n = neg_numeral (m + n)" |
470 "neg_numeral m + neg_numeral n = neg_numeral (m + n)" |
475 unfolding sub_def diff_minus neg_numeral_def numeral_add numeral.simps |
471 by (simp_all add: sub_def neg_numeral_def numeral_add numeral.simps is_num_normalize |
476 by (simp_all add: is_num_normalize) |
472 del: add_uminus_conv_diff add: diff_conv_add_uminus) |
477 |
473 |
478 lemma add_neg_numeral_special: |
474 lemma add_neg_numeral_special: |
479 "1 + neg_numeral m = sub One m" |
475 "1 + neg_numeral m = sub One m" |
480 "neg_numeral m + 1 = sub One m" |
476 "neg_numeral m + 1 = sub One m" |
481 unfolding sub_def diff_minus neg_numeral_def numeral_add numeral.simps |
477 by (simp_all add: sub_def neg_numeral_def numeral_add numeral.simps is_num_normalize) |
482 by (simp_all add: is_num_normalize) |
|
483 |
478 |
484 lemma diff_numeral_simps: |
479 lemma diff_numeral_simps: |
485 "numeral m - numeral n = sub m n" |
480 "numeral m - numeral n = sub m n" |
486 "numeral m - neg_numeral n = numeral (m + n)" |
481 "numeral m - neg_numeral n = numeral (m + n)" |
487 "neg_numeral m - numeral n = neg_numeral (m + n)" |
482 "neg_numeral m - numeral n = neg_numeral (m + n)" |
488 "neg_numeral m - neg_numeral n = sub n m" |
483 "neg_numeral m - neg_numeral n = sub n m" |
489 unfolding neg_numeral_def sub_def diff_minus numeral_add numeral.simps |
484 by (simp_all add: neg_numeral_def sub_def numeral_add numeral.simps is_num_normalize |
490 by (simp_all add: is_num_normalize) |
485 del: add_uminus_conv_diff add: diff_conv_add_uminus) |
491 |
486 |
492 lemma diff_numeral_special: |
487 lemma diff_numeral_special: |
493 "1 - numeral n = sub One n" |
488 "1 - numeral n = sub One n" |
494 "1 - neg_numeral n = numeral (One + n)" |
489 "1 - neg_numeral n = numeral (One + n)" |
495 "numeral m - 1 = sub m One" |
490 "numeral m - 1 = sub m One" |
496 "neg_numeral m - 1 = neg_numeral (m + One)" |
491 "neg_numeral m - 1 = neg_numeral (m + One)" |
497 unfolding neg_numeral_def sub_def diff_minus numeral_add numeral.simps |
492 by (simp_all add: neg_numeral_def sub_def numeral_add numeral.simps add: is_num_normalize) |
498 by (simp_all add: is_num_normalize) |
|
499 |
493 |
500 lemma minus_one: "- 1 = -1" |
494 lemma minus_one: "- 1 = -1" |
501 unfolding neg_numeral_def numeral.simps .. |
495 unfolding neg_numeral_def numeral.simps .. |
502 |
496 |
503 lemma minus_numeral: "- numeral n = neg_numeral n" |
497 lemma minus_numeral: "- numeral n = neg_numeral n" |