src/HOL/Algebra/Ring.thy
changeset 59851 43b1870b3e61
parent 58811 19382bbfa93a
child 60112 3eab4acaa035
equal deleted inserted replaced
59804:db0b87085c16 59851:43b1870b3e61
   224 qed
   224 qed
   225 
   225 
   226 
   226 
   227 subsection {* Rings: Basic Definitions *}
   227 subsection {* Rings: Basic Definitions *}
   228 
   228 
   229 locale ring = abelian_group R + monoid R for R (structure) +
   229 locale semiring = abelian_monoid R + monoid R for R (structure) +
   230   assumes l_distr: "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
   230   assumes l_distr: "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
   231       ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z"
   231       ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z"
   232     and r_distr: "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
   232     and r_distr: "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
       
   233       ==> z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y"
       
   234     and l_null[simp]: "x \<in> carrier R ==> \<zero> \<otimes> x = \<zero>"
       
   235     and r_null[simp]: "x \<in> carrier R ==> x \<otimes> \<zero> = \<zero>"
       
   236 
       
   237 locale ring = abelian_group R + monoid R for R (structure) +
       
   238   assumes "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
       
   239       ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z"
       
   240     and "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
   233       ==> z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y"
   241       ==> z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y"
   234 
   242 
   235 locale cring = ring + comm_monoid R
   243 locale cring = ring + comm_monoid R
   236 
   244 
   237 locale "domain" = cring +
   245 locale "domain" = cring +
   334 
   342 
   335 text {* 
   343 text {* 
   336   The following proofs are from Jacobson, Basic Algebra I, pp.~88--89.
   344   The following proofs are from Jacobson, Basic Algebra I, pp.~88--89.
   337 *}
   345 *}
   338 
   346 
   339 lemma l_null [simp]:
   347 sublocale semiring
   340   "x \<in> carrier R ==> \<zero> \<otimes> x = \<zero>"
   348 proof -
   341 proof -
   349   note [simp] = ring_axioms[unfolded ring_def ring_axioms_def]
   342   assume R: "x \<in> carrier R"
   350   show "semiring R"
   343   then have "\<zero> \<otimes> x \<oplus> \<zero> \<otimes> x = (\<zero> \<oplus> \<zero>) \<otimes> x"
   351   proof (unfold_locales)
   344     by (simp add: l_distr del: l_zero r_zero)
   352     fix x
   345   also from R have "... = \<zero> \<otimes> x \<oplus> \<zero>" by simp
   353     assume R: "x \<in> carrier R"
   346   finally have "\<zero> \<otimes> x \<oplus> \<zero> \<otimes> x = \<zero> \<otimes> x \<oplus> \<zero>" .
   354     then have "\<zero> \<otimes> x \<oplus> \<zero> \<otimes> x = (\<zero> \<oplus> \<zero>) \<otimes> x"
   347   with R show ?thesis by (simp del: r_zero)
   355       by (simp del: l_zero r_zero)
   348 qed
   356     also from R have "... = \<zero> \<otimes> x \<oplus> \<zero>" by simp
   349 
   357     finally have "\<zero> \<otimes> x \<oplus> \<zero> \<otimes> x = \<zero> \<otimes> x \<oplus> \<zero>" .
   350 lemma r_null [simp]:
   358     with R show "\<zero> \<otimes> x = \<zero>" by (simp del: r_zero)
   351   "x \<in> carrier R ==> x \<otimes> \<zero> = \<zero>"
   359     from R have "x \<otimes> \<zero> \<oplus> x \<otimes> \<zero> = x \<otimes> (\<zero> \<oplus> \<zero>)"
   352 proof -
   360       by (simp del: l_zero r_zero)
   353   assume R: "x \<in> carrier R"
   361     also from R have "... = x \<otimes> \<zero> \<oplus> \<zero>" by simp
   354   then have "x \<otimes> \<zero> \<oplus> x \<otimes> \<zero> = x \<otimes> (\<zero> \<oplus> \<zero>)"
   362     finally have "x \<otimes> \<zero> \<oplus> x \<otimes> \<zero> = x \<otimes> \<zero> \<oplus> \<zero>" .
   355     by (simp add: r_distr del: l_zero r_zero)
   363     with R show "x \<otimes> \<zero> = \<zero>" by (simp del: r_zero)
   356   also from R have "... = x \<otimes> \<zero> \<oplus> \<zero>" by simp
   364   qed auto
   357   finally have "x \<otimes> \<zero> \<oplus> x \<otimes> \<zero> = x \<otimes> \<zero> \<oplus> \<zero>" .
       
   358   with R show ?thesis by (simp del: r_zero)
       
   359 qed
   365 qed
   360 
   366 
   361 lemma l_minus:
   367 lemma l_minus:
   362   "[| x \<in> carrier R; y \<in> carrier R |] ==> \<ominus> x \<otimes> y = \<ominus> (x \<otimes> y)"
   368   "[| x \<in> carrier R; y \<in> carrier R |] ==> \<ominus> x \<otimes> y = \<ominus> (x \<otimes> y)"
   363 proof -
   369 proof -
   399 
   405 
   400 method_setup algebra = {*
   406 method_setup algebra = {*
   401   Scan.succeed (SIMPLE_METHOD' o Ringsimp.algebra_tac)
   407   Scan.succeed (SIMPLE_METHOD' o Ringsimp.algebra_tac)
   402 *} "normalisation of algebraic structure"
   408 *} "normalisation of algebraic structure"
   403 
   409 
       
   410 lemmas (in semiring) semiring_simprules
       
   411   [algebra ring "zero R" "add R" "a_inv R" "a_minus R" "one R" "mult R"] =
       
   412   a_closed zero_closed  m_closed one_closed
       
   413   a_assoc l_zero  a_comm m_assoc l_one l_distr r_zero
       
   414   a_lcomm r_distr l_null r_null 
       
   415 
   404 lemmas (in ring) ring_simprules
   416 lemmas (in ring) ring_simprules
   405   [algebra ring "zero R" "add R" "a_inv R" "a_minus R" "one R" "mult R"] =
   417   [algebra ring "zero R" "add R" "a_inv R" "a_minus R" "one R" "mult R"] =
   406   a_closed zero_closed a_inv_closed minus_closed m_closed one_closed
   418   a_closed zero_closed a_inv_closed minus_closed m_closed one_closed
   407   a_assoc l_zero l_neg a_comm m_assoc l_one l_distr minus_eq
   419   a_assoc l_zero l_neg a_comm m_assoc l_one l_distr minus_eq
   408   r_zero r_neg r_neg2 r_neg1 minus_add minus_minus minus_zero
   420   r_zero r_neg r_neg2 r_neg1 minus_add minus_minus minus_zero
   417   a_closed zero_closed a_inv_closed minus_closed m_closed one_closed
   429   a_closed zero_closed a_inv_closed minus_closed m_closed one_closed
   418   a_assoc l_zero l_neg a_comm m_assoc l_one l_distr m_comm minus_eq
   430   a_assoc l_zero l_neg a_comm m_assoc l_one l_distr m_comm minus_eq
   419   r_zero r_neg r_neg2 r_neg1 minus_add minus_minus minus_zero
   431   r_zero r_neg r_neg2 r_neg1 minus_add minus_minus minus_zero
   420   a_lcomm m_lcomm r_distr l_null r_null l_minus r_minus
   432   a_lcomm m_lcomm r_distr l_null r_null l_minus r_minus
   421 
   433 
   422 lemma (in cring) nat_pow_zero:
   434 lemma (in semiring) nat_pow_zero:
   423   "(n::nat) ~= 0 ==> \<zero> (^) n = \<zero>"
   435   "(n::nat) ~= 0 ==> \<zero> (^) n = \<zero>"
   424   by (induct n) simp_all
   436   by (induct n) simp_all
   425 
   437 
   426 context ring begin
   438 context semiring begin
   427 
   439 
   428 lemma one_zeroD:
   440 lemma one_zeroD:
   429   assumes onezero: "\<one> = \<zero>"
   441   assumes onezero: "\<one> = \<zero>"
   430   shows "carrier R = {\<zero>}"
   442   shows "carrier R = {\<zero>}"
   431 proof (rule, rule)
   443 proof (rule, rule)
   480 qed
   492 qed
   481 
   493 
   482 
   494 
   483 subsubsection {* Sums over Finite Sets *}
   495 subsubsection {* Sums over Finite Sets *}
   484 
   496 
   485 lemma (in ring) finsum_ldistr:
   497 lemma (in semiring) finsum_ldistr:
   486   "[| finite A; a \<in> carrier R; f \<in> A -> carrier R |] ==>
   498   "[| finite A; a \<in> carrier R; f \<in> A -> carrier R |] ==>
   487    finsum R f A \<otimes> a = finsum R (%i. f i \<otimes> a) A"
   499    finsum R f A \<otimes> a = finsum R (%i. f i \<otimes> a) A"
   488 proof (induct set: finite)
   500 proof (induct set: finite)
   489   case empty then show ?case by simp
   501   case empty then show ?case by simp
   490 next
   502 next
   491   case (insert x F) then show ?case by (simp add: Pi_def l_distr)
   503   case (insert x F) then show ?case by (simp add: Pi_def l_distr)
   492 qed
   504 qed
   493 
   505 
   494 lemma (in ring) finsum_rdistr:
   506 lemma (in semiring) finsum_rdistr:
   495   "[| finite A; a \<in> carrier R; f \<in> A -> carrier R |] ==>
   507   "[| finite A; a \<in> carrier R; f \<in> A -> carrier R |] ==>
   496    a \<otimes> finsum R f A = finsum R (%i. a \<otimes> f i) A"
   508    a \<otimes> finsum R f A = finsum R (%i. a \<otimes> f i) A"
   497 proof (induct set: finite)
   509 proof (induct set: finite)
   498   case empty then show ?case by simp
   510   case empty then show ?case by simp
   499 next
   511 next