151 apply (rule zadd_commute) |
151 apply (rule zadd_commute) |
152 done |
152 done |
153 |
153 |
154 lemmas zadd_ac = zadd_assoc zadd_commute zadd_left_commute |
154 lemmas zadd_ac = zadd_assoc zadd_commute zadd_left_commute |
155 |
155 |
156 lemmas zmult_ac = Ring_and_Field.mult_ac |
156 lemmas zmult_ac = OrderedGroup.mult_ac |
157 |
157 |
158 lemma zadd_int: "(int m) + (int n) = int (m + n)" |
158 lemma zadd_int: "(int m) + (int n) = int (m + n)" |
159 by (simp add: int_def add) |
159 by (simp add: int_def add) |
160 |
160 |
161 lemma zadd_int_left: "(int m) + (int n + z) = int (m + n) + z" |
161 lemma zadd_int_left: "(int m) + (int n + z) = int (m + n) + z" |
162 by (simp add: zadd_int zadd_assoc [symmetric]) |
162 by (simp add: zadd_int zadd_assoc [symmetric]) |
163 |
163 |
164 lemma int_Suc: "int (Suc m) = 1 + (int m)" |
164 lemma int_Suc: "int (Suc m) = 1 + (int m)" |
165 by (simp add: One_int_def zadd_int) |
165 by (simp add: One_int_def zadd_int) |
166 |
166 |
167 (*also for the instance declaration int :: plus_ac0*) |
167 (*also for the instance declaration int :: comm_monoid_add*) |
168 lemma zadd_0: "(0::int) + z = z" |
168 lemma zadd_0: "(0::int) + z = z" |
169 apply (simp add: Zero_int_def int_def) |
169 apply (simp add: Zero_int_def int_def) |
170 apply (cases z, simp add: add) |
170 apply (cases z, simp add: add) |
171 done |
171 done |
172 |
172 |
508 text{*This version is proved for all ordered rings, not just integers! |
508 text{*This version is proved for all ordered rings, not just integers! |
509 It is proved here because attribute @{text arith_split} is not available |
509 It is proved here because attribute @{text arith_split} is not available |
510 in theory @{text Ring_and_Field}. |
510 in theory @{text Ring_and_Field}. |
511 But is it really better than just rewriting with @{text abs_if}?*} |
511 But is it really better than just rewriting with @{text abs_if}?*} |
512 lemma abs_split [arith_split]: |
512 lemma abs_split [arith_split]: |
513 "P(abs(a::'a::ordered_ring)) = ((0 \<le> a --> P a) & (a < 0 --> P(-a)))" |
513 "P(abs(a::'a::ordered_idom)) = ((0 \<le> a --> P a) & (a < 0 --> P(-a)))" |
514 by (force dest: order_less_le_trans simp add: abs_if linorder_not_less) |
514 by (force dest: order_less_le_trans simp add: abs_if linorder_not_less) |
515 |
515 |
516 |
516 |
517 |
517 |
518 subsection{*The Constants @{term neg} and @{term iszero}*} |
518 subsection{*The Constants @{term neg} and @{term iszero}*} |
519 |
519 |
520 constdefs |
520 constdefs |
521 |
521 |
522 neg :: "'a::ordered_ring => bool" |
522 neg :: "'a::ordered_idom => bool" |
523 "neg(Z) == Z < 0" |
523 "neg(Z) == Z < 0" |
524 |
524 |
525 (*For simplifying equalities*) |
525 (*For simplifying equalities*) |
526 iszero :: "'a::semiring => bool" |
526 iszero :: "'a::comm_semiring_1_cancel => bool" |
527 "iszero z == z = (0)" |
527 "iszero z == z = (0)" |
528 |
528 |
529 |
529 |
530 lemma not_neg_int [simp]: "~ neg(int n)" |
530 lemma not_neg_int [simp]: "~ neg(int n)" |
531 by (simp add: neg_def) |
531 by (simp add: neg_def) |
579 lemma of_nat_mult [simp]: "of_nat (m*n) = of_nat m * of_nat n" |
579 lemma of_nat_mult [simp]: "of_nat (m*n) = of_nat m * of_nat n" |
580 apply (induct m) |
580 apply (induct m) |
581 apply (simp_all add: mult_ac add_ac right_distrib) |
581 apply (simp_all add: mult_ac add_ac right_distrib) |
582 done |
582 done |
583 |
583 |
584 lemma zero_le_imp_of_nat: "0 \<le> (of_nat m::'a::ordered_semiring)" |
584 lemma zero_le_imp_of_nat: "0 \<le> (of_nat m::'a::ordered_semidom)" |
585 apply (induct m, simp_all) |
585 apply (induct m, simp_all) |
586 apply (erule order_trans) |
586 apply (erule order_trans) |
587 apply (rule less_add_one [THEN order_less_imp_le]) |
587 apply (rule less_add_one [THEN order_less_imp_le]) |
588 done |
588 done |
589 |
589 |
590 lemma less_imp_of_nat_less: |
590 lemma less_imp_of_nat_less: |
591 "m < n ==> of_nat m < (of_nat n::'a::ordered_semiring)" |
591 "m < n ==> of_nat m < (of_nat n::'a::ordered_semidom)" |
592 apply (induct m n rule: diff_induct, simp_all) |
592 apply (induct m n rule: diff_induct, simp_all) |
593 apply (insert add_le_less_mono [OF zero_le_imp_of_nat zero_less_one], force) |
593 apply (insert add_le_less_mono [OF zero_le_imp_of_nat zero_less_one], force) |
594 done |
594 done |
595 |
595 |
596 lemma of_nat_less_imp_less: |
596 lemma of_nat_less_imp_less: |
597 "of_nat m < (of_nat n::'a::ordered_semiring) ==> m < n" |
597 "of_nat m < (of_nat n::'a::ordered_semidom) ==> m < n" |
598 apply (induct m n rule: diff_induct, simp_all) |
598 apply (induct m n rule: diff_induct, simp_all) |
599 apply (insert zero_le_imp_of_nat) |
599 apply (insert zero_le_imp_of_nat) |
600 apply (force simp add: linorder_not_less [symmetric]) |
600 apply (force simp add: linorder_not_less [symmetric]) |
601 done |
601 done |
602 |
602 |
603 lemma of_nat_less_iff [simp]: |
603 lemma of_nat_less_iff [simp]: |
604 "(of_nat m < (of_nat n::'a::ordered_semiring)) = (m<n)" |
604 "(of_nat m < (of_nat n::'a::ordered_semidom)) = (m<n)" |
605 by (blast intro: of_nat_less_imp_less less_imp_of_nat_less) |
605 by (blast intro: of_nat_less_imp_less less_imp_of_nat_less) |
606 |
606 |
607 text{*Special cases where either operand is zero*} |
607 text{*Special cases where either operand is zero*} |
608 declare of_nat_less_iff [of 0, simplified, simp] |
608 declare of_nat_less_iff [of 0, simplified, simp] |
609 declare of_nat_less_iff [of _ 0, simplified, simp] |
609 declare of_nat_less_iff [of _ 0, simplified, simp] |
610 |
610 |
611 lemma of_nat_le_iff [simp]: |
611 lemma of_nat_le_iff [simp]: |
612 "(of_nat m \<le> (of_nat n::'a::ordered_semiring)) = (m \<le> n)" |
612 "(of_nat m \<le> (of_nat n::'a::ordered_semidom)) = (m \<le> n)" |
613 by (simp add: linorder_not_less [symmetric]) |
613 by (simp add: linorder_not_less [symmetric]) |
614 |
614 |
615 text{*Special cases where either operand is zero*} |
615 text{*Special cases where either operand is zero*} |
616 declare of_nat_le_iff [of 0, simplified, simp] |
616 declare of_nat_le_iff [of 0, simplified, simp] |
617 declare of_nat_le_iff [of _ 0, simplified, simp] |
617 declare of_nat_le_iff [of _ 0, simplified, simp] |
618 |
618 |
619 text{*The ordering on the semiring is necessary to exclude the possibility of |
619 text{*The ordering on the comm_semiring_1_cancel is necessary to exclude the possibility of |
620 a finite field, which indeed wraps back to zero.*} |
620 a finite field, which indeed wraps back to zero.*} |
621 lemma of_nat_eq_iff [simp]: |
621 lemma of_nat_eq_iff [simp]: |
622 "(of_nat m = (of_nat n::'a::ordered_semiring)) = (m = n)" |
622 "(of_nat m = (of_nat n::'a::ordered_semidom)) = (m = n)" |
623 by (simp add: order_eq_iff) |
623 by (simp add: order_eq_iff) |
624 |
624 |
625 text{*Special cases where either operand is zero*} |
625 text{*Special cases where either operand is zero*} |
626 declare of_nat_eq_iff [of 0, simplified, simp] |
626 declare of_nat_eq_iff [of 0, simplified, simp] |
627 declare of_nat_eq_iff [of _ 0, simplified, simp] |
627 declare of_nat_eq_iff [of _ 0, simplified, simp] |
628 |
628 |
629 lemma of_nat_diff [simp]: |
629 lemma of_nat_diff [simp]: |
630 "n \<le> m ==> of_nat (m - n) = of_nat m - (of_nat n :: 'a::ring)" |
630 "n \<le> m ==> of_nat (m - n) = of_nat m - (of_nat n :: 'a::comm_ring_1)" |
631 by (simp del: of_nat_add |
631 by (simp del: of_nat_add |
632 add: compare_rls of_nat_add [symmetric] split add: nat_diff_split) |
632 add: compare_rls of_nat_add [symmetric] split add: nat_diff_split) |
633 |
633 |
634 |
634 |
635 subsection{*The Set of Natural Numbers*} |
635 subsection{*The Set of Natural Numbers*} |
636 |
636 |
637 constdefs |
637 constdefs |
638 Nats :: "'a::semiring set" |
638 Nats :: "'a::comm_semiring_1_cancel set" |
639 "Nats == range of_nat" |
639 "Nats == range of_nat" |
640 |
640 |
641 syntax (xsymbols) Nats :: "'a set" ("\<nat>") |
641 syntax (xsymbols) Nats :: "'a set" ("\<nat>") |
642 |
642 |
643 lemma of_nat_in_Nats [simp]: "of_nat n \<in> Nats" |
643 lemma of_nat_in_Nats [simp]: "of_nat n \<in> Nats" |
729 text{*Special cases where either operand is zero*} |
729 text{*Special cases where either operand is zero*} |
730 declare of_int_le_iff [of 0, simplified, simp] |
730 declare of_int_le_iff [of 0, simplified, simp] |
731 declare of_int_le_iff [of _ 0, simplified, simp] |
731 declare of_int_le_iff [of _ 0, simplified, simp] |
732 |
732 |
733 lemma of_int_less_iff [simp]: |
733 lemma of_int_less_iff [simp]: |
734 "(of_int w < (of_int z::'a::ordered_ring)) = (w < z)" |
734 "(of_int w < (of_int z::'a::ordered_idom)) = (w < z)" |
735 by (simp add: linorder_not_le [symmetric]) |
735 by (simp add: linorder_not_le [symmetric]) |
736 |
736 |
737 text{*Special cases where either operand is zero*} |
737 text{*Special cases where either operand is zero*} |
738 declare of_int_less_iff [of 0, simplified, simp] |
738 declare of_int_less_iff [of 0, simplified, simp] |
739 declare of_int_less_iff [of _ 0, simplified, simp] |
739 declare of_int_less_iff [of _ 0, simplified, simp] |
740 |
740 |
741 text{*The ordering on the ring is necessary. See @{text of_nat_eq_iff} above.*} |
741 text{*The ordering on the comm_ring_1 is necessary. See @{text of_nat_eq_iff} above.*} |
742 lemma of_int_eq_iff [simp]: |
742 lemma of_int_eq_iff [simp]: |
743 "(of_int w = (of_int z::'a::ordered_ring)) = (w = z)" |
743 "(of_int w = (of_int z::'a::ordered_idom)) = (w = z)" |
744 by (simp add: order_eq_iff) |
744 by (simp add: order_eq_iff) |
745 |
745 |
746 text{*Special cases where either operand is zero*} |
746 text{*Special cases where either operand is zero*} |
747 declare of_int_eq_iff [of 0, simplified, simp] |
747 declare of_int_eq_iff [of 0, simplified, simp] |
748 declare of_int_eq_iff [of _ 0, simplified, simp] |
748 declare of_int_eq_iff [of _ 0, simplified, simp] |