491 (*Distributive laws for literals*) |
491 (*Distributive laws for literals*) |
492 Addsimps (map (inst "k" "number_of ?v") |
492 Addsimps (map (inst "k" "number_of ?v") |
493 [add_mult_distrib, add_mult_distrib2, |
493 [add_mult_distrib, add_mult_distrib2, |
494 diff_mult_distrib, diff_mult_distrib2]); |
494 diff_mult_distrib, diff_mult_distrib2]); |
495 |
495 |
|
496 |
|
497 (*** Literal arithmetic involving powers, type nat ***) |
|
498 |
|
499 Goal "(0::int) <= z ==> nat (z^n) = nat z ^ n"; |
|
500 by (induct_tac "n" 1); |
|
501 by (ALLGOALS (asm_simp_tac (simpset() addsimps [nat_mult_distrib]))); |
|
502 qed "nat_power_eq"; |
|
503 |
|
504 Goal "(number_of v :: nat) ^ n = \ |
|
505 \ (if neg (number_of v) then 0^n else nat ((number_of v :: int) ^ n))"; |
|
506 by (simp_tac |
|
507 (simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, |
|
508 nat_power_eq]) 1); |
|
509 qed "power_nat_number_of"; |
|
510 |
|
511 Addsimps [inst "n" "number_of ?w" power_nat_number_of]; |
|
512 |
|
513 |
|
514 |
|
515 (*** Literal arithmetic involving powers, type int ***) |
|
516 |
|
517 Goal "(z::int) ^ (2*a) = (z^a)^2"; |
|
518 by (simp_tac (simpset() addsimps [zpower_zpower, mult_commute]) 1); |
|
519 qed "zpower_even"; |
|
520 |
|
521 Goal "(p::int) ^ 2 = p*p"; |
|
522 by (simp_tac numeral_ss 1); |
|
523 qed "zpower_two"; |
|
524 |
|
525 Goal "(z::int) ^ (2*a + 1) = z * (z^a)^2"; |
|
526 by (simp_tac (simpset() addsimps [zpower_even, zpower_zadd_distrib]) 1); |
|
527 qed "zpower_odd"; |
|
528 |
|
529 Goal "(z::int) ^ number_of (w BIT False) = \ |
|
530 \ (let w = z ^ (number_of w) in w*w)"; |
|
531 by (simp_tac (simpset_of Int.thy addsimps [nat_number_of_def, |
|
532 number_of_BIT, Let_def]) 1); |
|
533 by (res_inst_tac [("x","number_of w")] spec 1 THEN Clarify_tac 1); |
|
534 by (case_tac "(0::int) <= x" 1); |
|
535 by (auto_tac (claset(), |
|
536 simpset() addsimps [nat_mult_distrib, zpower_even, zpower_two])); |
|
537 qed "zpower_number_of_even"; |
|
538 |
|
539 Goal "(z::int) ^ number_of (w BIT True) = \ |
|
540 \ (if (0::int) <= number_of w \ |
|
541 \ then (let w = z ^ (number_of w) in z*w*w) \ |
|
542 \ else 1)"; |
|
543 by (simp_tac (simpset_of Int.thy addsimps [nat_number_of_def, |
|
544 number_of_BIT, Let_def]) 1); |
|
545 by (res_inst_tac [("x","number_of w")] spec 1 THEN Clarify_tac 1); |
|
546 by (case_tac "(0::int) <= x" 1); |
|
547 by (auto_tac (claset(), |
|
548 simpset() addsimps [nat_add_distrib, nat_mult_distrib, |
|
549 zpower_even, zpower_two])); |
|
550 qed "zpower_number_of_odd"; |
|
551 |
|
552 Addsimps (map (inst "z" "number_of ?v") |
|
553 [zpower_number_of_even, zpower_number_of_odd]); |
|
554 |