An abstract ring structure. Addition associates and commutes, and
multiplication associates and distributes over addition. Addition and
multiplication both have an identity element, and every element has an
additive inverse. To the extent practicable, the following axioms
should hold.
Axioms for addition:
if 𝑎 and 𝑏 are elements in this, then their sum 𝑎 + 𝑏 is also an element in this.
𝑎 + 𝑏 == 𝑏 + 𝑎 for all elements 𝑎, 𝑏 in this.
(𝑎 + 𝑏) + 𝑐 == 𝑎 + (𝑏 + 𝑐) for all elements 𝑎, 𝑏, 𝑐 in this.
this has an element zero such that zero + 𝑎 == 𝑎 for every element 𝑎 in this.
to every element 𝑎 in this corresponds an element -𝑎 in this such that 𝑎 + (-𝑎) == zero.
Axioms for multiplication:
if 𝑎 and 𝑏 are elements in this, then their product 𝑎 * 𝑏 is also an element in this.
(𝑎 * 𝑏) * 𝑐 == 𝑎 * (𝑏 * 𝑐) for all elements 𝑎, 𝑏, 𝑐 in this.
this has an element unit != zero such that unit * 𝑎 == 𝑎 for every element 𝑎 in this.
The distributive law:
𝑎 * (𝑏 + 𝑐) == (𝑎 * 𝑏) + (𝑎 * 𝑐) for all elements 𝑎, 𝑏, 𝑐 in this.
// You can abstract over rings by parameterizing a class or// function with a subtype of Ring with Singleton. Type elements// with the #Element type projection of your Ring type parameter.def testRingOperations[R <: Ring with Singleton](a: R#Element, b: R#Element, c: R#Element): Unit = {
assert(a + b == b + a, "commutativity of addition")
assert((a + b) + c == a + (b + c), "associativity of addition")
assert((a * b) * c == a * (b * c), "associativity of multiplication")
assert(a * (b + c) == (a * b) + (a * c), "distributivity of multiplication over addition")
}
// Alternatively, functions can use path-dependent types of a Ring parameter.def testRingIdentities(R: Ring)(a: R.Element): Unit = {
import R._
assert(zero + a == a, "existence of additive identity")
assert(a + (-a) == zero, "existence of additive inverse")
assert(unit != zero && unit * a == a, "existence of multiplicative identity")
}
An abstract ring structure. Addition associates and commutes, and multiplication associates and distributes over addition. Addition and multiplication both have an identity element, and every element has an additive inverse. To the extent practicable, the following axioms should hold.
Axioms for addition:
this
, then their sum 𝑎 + 𝑏 is also an element inthis
.this
.this
.this
has an elementzero
such thatzero
+ 𝑎 == 𝑎 for every element 𝑎 inthis
.this
corresponds an element -𝑎 inthis
such that 𝑎 + (-𝑎) ==zero
.Axioms for multiplication:
this
, then their product 𝑎 * 𝑏 is also an element inthis
.this
.this
has an elementunit
!=zero
such thatunit
* 𝑎 == 𝑎 for every element 𝑎 inthis
.The distributive law:
this
.0.1
0.0