Ring without Unit (Rng)
Given a set R and operations + and *,
we say that (R, +, *) is a rng (ring without unit) if it satisfies the following properties:
(R, +)is an abelian group.- For any
xandy ∈ R:x * y ∈ R. - For any
x,y, andz ∈ R:(x * y) * z = x * (y * z). - For any
x,y, andz ∈ R:x * (y + z) = x * y + x * zand(x + y) * z = x * z + y * z.
Laws of a rng:
- Closure under addition (closure): for \(\forall x, y \in R\), \(x + y \in R\).
- Associativity of addition (associativity): for \(\forall x, y, z \in R\), \((x + y) + z = x + (y + z)\).
- Existence of a zero element: there exists \(\exists 0 \in R\) such that for \(\forall x \in R\), \(0 + x = x + 0 = x\).
- Existence of additive inverses: for \(\forall x \in R\) there exists \((-x)\) such that \(x + (-x) = (-x) + x = 0\).
- Commutativity of addition (commutative): for \(\forall x, y \in R\), \(x + y = y + x\).
- Closure under multiplication (closure): for \(\forall x, y \in R\), \(x * y \in R\).
- Associativity of multiplication (associativity): for \(\forall x, y, z \in R\), \((x * y) * z = x * (y * z)\).
- Distributivity (distributivity): for \(\forall x, y, z \in R\), \(x * (y + z) = x * y + x * z\) and \((x + y) * z = x * z + y * z\).
Code
trait Rng[A] extends AbelianGroup[A], Semiring[A]
Laws
The laws are inherited from the laws of an abelian group and semiring.
Diagram
classDiagram
class Semigroup~A~{
+combine(x: A, y: A) A
}
class Monoid~A~{
+empty() A
}
Semigroup <|-- Monoid
class CommutativeSemigroup~A~
Semigroup <|-- CommutativeSemigroup
class Group~A~{
+inverse(x: A) A
}
Monoid <|-- Group
class CommutativeMonoid~A~
Monoid <|-- CommutativeMonoid
CommutativeSemigroup <|-- CommutativeMonoid
class AbelianGroup~A~
Group <|-- AbelianGroup
CommutativeMonoid <|-- AbelianGroup
class Semiring~A~
CommutativeMonoid <|-- Semiring
class MultiplicativeSemigroup~A~{
+times(x: A, y: A) A
}
MultiplicativeSemigroup <|-- Semiring
Semigroup .. MultiplicativeSemigroup
class Rng~A~
AbelianGroup <|-- Rng
Semiring <|-- Rng
Library Implementations
Implementation in Spire
Rng[A] provides commutative +, zero, -, and *.
Rng[A] extends Semiring[A] and AdditiveAbGroup[A].
negate(-): additive inverse operationminus(-): subtractionzero: additive identity (an element such that for anyxin the set,x + zero = x)
import spire.algebra.Rng
import spire.math.Rational
Rng.plus(Rational(1, 2), Rational(1, 3))
// val res0: spire.math.Rational = 5/6
Rng.times(Rational(1, 2), Rational(1, 3))
// val res1: spire.math.Rational = 1/6
Rng.pow(Rational(1, 2), 3)
// val res2: spire.math.Rational = 1/8
Rng.negate(Rational(1, 2))
// val res3: spire.math.Rational = -1/2
Rng.minus(Rational(1, 2), Rational(1, 3))
// val res4: spire.math.Rational = 1/6
Rng.zero[Rational]
// val res5: spire.math.Rational = 0
References: