package algebra
- Alphabetic
- By Inheritance
- algebra
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- type AbGroup[A] = CommutativeGroup[A]
-
trait
Action[P, G] extends LeftAction[P, G] with RightAction[P, G]
A semigroup/monoid/group action of
G
onP
is the combination of compatible left and right actions, providing:A semigroup/monoid/group action of
G
onP
is the combination of compatible left and right actions, providing:- the implementation of a method
actl(g, p)
, org |+|> p
, such that:
1.
(g |+| h) |+|> p === g |+|> (h |+|> p)
for allg
,h
inG
andp
inP
.2.
id |+|> p === p
for allp
inP
(ifid
is defined)- the implementation of a method
actr(p, g)
, orp <|+| g
, such that:
3.
p <|+| (g |+| h) === (p <|+| g) <|+| h
for allg
,h
inG
andp
inP
.4.
p <|+| id === p
for allp
inP
(ifid
is defined)In addition, if
G
is a group, left and right actions are compatible:5.
g |+|> p === p <|+| g.inverse
. - the implementation of a method
- type AdditiveAbGroup[A] = AdditiveCommutativeGroup[A]
- trait AdditiveAction[P, G] extends Any
- type AdditiveCMonoid[A] = AdditiveCommutativeMonoid[A]
- type AdditiveCSemigroup[A] = AdditiveCommutativeSemigroup[A]
- type AdditiveGroup[A] = algebra.ring.AdditiveGroup[A]
- type AdditiveMonoid[A] = algebra.ring.AdditiveMonoid[A]
- type AdditiveSemigroup[A] = algebra.ring.AdditiveSemigroup[A]
- trait AdditiveTorsor[V, R] extends AdditiveAction[V, R]
- type AlgebraField[A] = algebra.ring.Field[A]
- type Bool[A] = algebra.lattice.Bool[A]
-
trait
CModule[V, R] extends LeftModule[V, R] with RightModule[V, R]
A module over a commutative ring has by definition equivalent left and right modules.
A module over a commutative ring has by definition equivalent left and right modules.
In addition to the laws above 1-5 left and 1-5 right, we have:
6. (r *: x) :* s = r *: (x :* s)
- V
Abelian group type
- R
Scalar type
- type CMonoid[A] = CommutativeMonoid[A]
- type CRig[A] = CommutativeRig[A]
- type CRing[A] = CommutativeRing[A]
- type CRng[A] = CommutativeRng[A]
- type CSemigroup[A] = CommutativeSemigroup[A]
- type CSemiring[A] = CommutativeSemiring[A]
- trait CoordinateSpace[V, F] extends InnerProductSpace[V, F]
- trait DivisionRing[A] extends Ring[A] with MultiplicativeGroup[A]
- type Eq[A] = cats.kernel.Eq[A]
-
trait
EuclideanRing[A] extends GCDRing[A]
EuclideanRing implements a Euclidean domain.
EuclideanRing implements a Euclidean domain.
The formal definition says that every euclidean domain A has (at least one) euclidean function f: A -> N (the natural numbers) where:
(for every x and non-zero y) x = yq + r, and r = 0 or f(r) < f(y).
This generalizes the Euclidean division of integers, where f represents a measure of length (or absolute value), and the previous equation represents finding the quotient and remainder of x and y. So:
quot(x, y) = q mod(x, y) = r
- trait EuclideanRingFunctions[R[T] <: EuclideanRing[T]] extends GCDRingFunctions[R]
-
trait
Field[A] extends AlgebraField[A] with EuclideanRing[A]
Field type class.
Field type class. While algebra already provides one, we provide one in Spire that integrates with the commutative ring hierarchy, in particular
GCDRing
andEuclideanRing
.On a field, all nonzero elements are invertible, so the remainder of the division is always 0. The Euclidean function can take an arbitrary value on nonzero elements (it is undefined for zero); for compatibility with the degree of polynomials, we use the constant 0.
The GCD and LCM are defined up to a unit; on a field, it means that either the GCD or LCM can be fixed arbitrarily. Some conventions with consistent defaults are provided in the spire.algebra.Field companion object.
-
trait
FieldAssociativeAlgebra[V, F] extends RingAssociativeAlgebra[V, F] with VectorSpace[V, F]
A
FieldAlgebra
is a vector space that is also aRing
.A
FieldAlgebra
is a vector space that is also aRing
. An example is the complex numbers. -
trait
GCDRing[A] extends CRing[A]
GCDRing implements a GCD ring.
GCDRing implements a GCD ring.
For two elements x and y in a GCD ring, we can choose two elements d and m such that:
d = gcd(x, y) m = lcm(x, y)
d * m = x * y
Additionally, we require:
gcd(0, 0) = 0 lcm(x, 0) = lcm(0, x) = 0
and commutativity:
gcd(x, y) = gcd(y, x) lcm(x, y) = lcm(y, x)
- trait GCDRingFunctions[R[T] <: GCDRing[T]] extends RingFunctions[R]
- type Group[A] = cats.kernel.Group[A]
- trait InnerProductSpace[V, F] extends VectorSpace[V, F]
-
trait
Involution[A] extends AnyRef
Describes an involution, which is an operator that satisfies f(f(x)) = x (rule i).
Describes an involution, which is an operator that satisfies f(f(x)) = x (rule i).
If a multiplicative semigroup is available, it describes an antiautomorphism (rule ii); on a multiplicative monoid, it preserves the identity (rule iii).
If a ring is available, it should be compatible with addition (rule iv), and then defines a *-ring (see https://en.wikipedia.org/wiki/%2A-algebra ).
- adjoint(adjoint(x)) = x ii. adjoint(x*y) = adjoint(y)*adjoint(x) (with an underlying multiplicative semigroup) iii. adjoint(1) = 1 (with an underlying multiplicative monoid) iv. adjoint(x+y) = adjoint(x)+adjoint(y) (with an underlying ring)
A *-algebra is an associative algebra A over a commutative *-ring R, where A has an involution as well. It satisfies, for x: A, y: A and r: R
v. adjoint(r * x + y) = adjoint(r)*adjoint(x) + adjoint(y)
- trait IsAlgebraic[A] extends IsReal[A]
- trait IsIntegral[A] extends IsRational[A]
- trait IsRational[A] extends IsAlgebraic[A]
-
trait
IsReal[A] extends Signed[A]
A simple type class for numeric types that are a subset of the reals.
-
trait
LeftAction[P, G] extends Any
A (left) semigroup/monoid/group action of
G
onP
is simply the implementation of a methodactl(g, p)
, org |+|> p
, such that:A (left) semigroup/monoid/group action of
G
onP
is simply the implementation of a methodactl(g, p)
, org |+|> p
, such that:1.
(g |+| h) |+|> p === g |+|> (h |+|> p)
for allg
,h
inG
andp
inP
.2.
id |+|> p === p
for allp
inP
(ifid
is defined) -
trait
LeftModule[V, R] extends AdditiveAbGroup[V]
A left module is a generalization of a vector space over a field, where the scalars are the elements of a ring (not necessarily commutative).
A left module is a generalization of a vector space over a field, where the scalars are the elements of a ring (not necessarily commutative).
A left module has left multiplication by scalars. Let V be an abelian group (with additive notation) and R the scalar ring, we have the following laws for x, y in V and r, s in R:
1. r *: (x + y) = r *: x + r *: y 2. (r + s) *: x = r *: x + s *: x 3. (r * s) *: x = r *: (s *: x) 4. R.one * x = x
(see https://en.wikipedia.org/wiki/Module_(mathematics) )
- V
Abelian group type
- R
Scalar type
-
trait
MetricSpace[V, R] extends Any
This type class models a metric space
V
.This type class models a metric space
V
. The distance between 2 points inV
is measured inR
, which should be real (ie.IsReal[R]
exists). - type Monoid[A] = cats.kernel.Monoid[A]
- type MultiplicativeAbGroup[A] = MultiplicativeCommutativeGroup[A]
- trait MultiplicativeAction[P, G] extends Any
- type MultiplicativeCMonoid[A] = MultiplicativeCommutativeMonoid[A]
- type MultiplicativeCSemigroup[A] = MultiplicativeCommutativeSemigroup[A]
- type MultiplicativeGroup[A] = algebra.ring.MultiplicativeGroup[A]
- type MultiplicativeMonoid[A] = algebra.ring.MultiplicativeMonoid[A]
- type MultiplicativeSemigroup[A] = algebra.ring.MultiplicativeSemigroup[A]
- trait MultiplicativeTorsor[V, R] extends MultiplicativeAction[V, R]
-
trait
NRoot[A] extends Any
This is a type class for types with n-roots.
This is a type class for types with n-roots. The value returned by
nroot
andsqrt
are only guaranteed to be approximate answers (except in the case ofReal
).Also, generally
nroot
s wheren
is even are not defined for negative numbers. The behaviour is undefined if this is attempted. It would be nice to ensure an exception is raised, but some types may defer computation and testing if a value is negative may not be ideal. So, do not count onArithmeticException
s to save you from bad arithmetic! -
trait
NormedVectorSpace[V, F] extends VectorSpace[V, F] with MetricSpace[V, F]
A normed vector space is a vector space equipped with a function
norm: V => F
.A normed vector space is a vector space equipped with a function
norm: V => F
. The main constraint is that the norm of a vector must be scaled linearly when the vector is scaled; that isnorm(k *: v) == k.abs * norm(v)
. Additionally, a normed vector space is also aMetricSpace
, wheredistance(v, w) = norm(v - w)
, and so must obey the triangle inequality.An example of a normed vector space is R^n equipped with the euclidean vector length as the norm.
- type Order[A] = cats.kernel.Order[A]
- type PartialOrder[A] = cats.kernel.PartialOrder[A]
- type Rig[A] = algebra.ring.Rig[A]
-
trait
RightAction[P, G] extends Any
A (right) semigroup/monoid/group action of
G
onP
is simply the implementation of a methodactr(p, g)
, orp <|+| g
, such that:A (right) semigroup/monoid/group action of
G
onP
is simply the implementation of a methodactr(p, g)
, orp <|+| g
, such that:1.
p <|+| (g |+| h) === (p <|+| g) <|+| h
for allg
,h
inG
andp
inP
.2.
p <|+| id === p
for allp
inP
(ifid
is defined) -
trait
RightModule[V, R] extends AdditiveAbGroup[V]
A right module is a generalization of a vector space over a field, where the scalars are the elements of a ring (not necessarily commutative).
A right module is a generalization of a vector space over a field, where the scalars are the elements of a ring (not necessarily commutative).
A right module has right multiplication by scalars. Let V be an abelian group (with additive notation) and R the scalar ring, we have the following laws for x, y in V and r, s in R:
1. (x + y) :* r = x :* r + y :* r 2. x :* (r + s) = x :* r + x :* s 3. x :* (r * s) = (x :* r) :* s 4. x :* R.one = x
- V
Abelian group type
- R
Scalar type
- type Ring[A] = algebra.ring.Ring[A]
-
trait
RingAssociativeAlgebra[V, R] extends CModule[V, R] with Ring[V]
A
RingAssociativeAlgebra
is a R-module that is also aRing
.A
RingAssociativeAlgebra
is a R-module that is also aRing
. An example is the Gaussian numbers, the quaternions, etc...The scalar multiplication satisfies, for r in R, and x, y in V:
1. r *: (x * y) = (r *: x) * y = x * (r *: y)
TODO: verify the definition, in particular the requirements for Ring[V] (and not Rng[V])
- type Rng[A] = algebra.ring.Rng[A]
- type Semigroup[A] = cats.kernel.Semigroup[A]
- type Semiring[A] = algebra.ring.Semiring[A]
-
sealed abstract
class
Sign extends AnyRef
A simple ADT representing the
Sign
of an object. -
trait
Signed[A] extends Order[A]
A trait for linearly ordered additive commutative monoid.
A trait for linearly ordered additive commutative monoid. The following laws holds:
(1) if
a <= b
thena + c <= b + c
(linear order), (2)signum(x) = -1
ifx < 0
,signum(x) = 1
ifx > 0
,signum(x) = 0
otherwise,Negative elements only appear when
scalar
is a additive abelian group, and then (3)abs(x) = -x
ifx < 0
, orx
otherwise,Laws (1) and (2) lead to the triange inequality:
(4)
abs(a + b) <= abs(a) + abs(b)
Signed should never be extended in implementations, rather the AdditiveCMonoid and AdditiveAbGroup subtraits. We cannot use self-types to express the constraint
self: AdditiveCMonoid =>
(interaction with specialization?). - trait SignedAdditiveAbGroup[A] extends SignedAdditiveCMonoid[A] with AdditiveAbGroup[A]
- trait SignedAdditiveCMonoid[A] extends Signed[A] with AdditiveCMonoid[A]
-
trait
Torsor[V, R] extends Action[V, R]
A Torsor[V, R] requires an AbGroup[R] and provides Action[V, R], plus a
diff
operator,<->
in additive notation, such that:A Torsor[V, R] requires an AbGroup[R] and provides Action[V, R], plus a
diff
operator,<->
in additive notation, such that:1.
(g <-> g) === scalar.id
for allg
inG
.2.
(g <-> h) +> h === g
for allg
,h
inG
.3.
(g <-> h) +> i === (i <-> h) +> g
for allg
,h
inG
.4.
(g <-> h) === -(h <-> g)
for allg
,h
inG
. - trait Trig[A] extends Any
-
trait
TruncatedDivision[A] extends Signed[A]
Division and modulus for computer scientists taken from https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf
Division and modulus for computer scientists taken from https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf
For two numbers x (dividend) and y (divisor) on an ordered ring with y != 0, there exists a pair of numbers q (quotient) and r (remainder) such that these laws are satisfied:
(1) q is an integer (2) x = y * q + r (division rule) (3) |r| < |y|, (4t) r = 0 or sign(r) = sign(x), (4f) r = 0 or sign(r) = sign(y).
where sign is the sign function, and the absolute value function |x| is defined as |x| = x if x >=0, and |x| = -x otherwise.
We define functions tmod and tquot such that: q = tquot(x, y) and r = tmod(x, y) obey rule (4t), (which truncates effectively towards zero) and functions fmod and fquot such that: q = fquot(x, y) and r = fmod(x, y) obey rule (4f) (which floors the quotient and effectively rounds towards negative infinity).
Law (4t) corresponds to ISO C99 and Haskell's quot/rem. Law (4f) is described by Knuth and used by Haskell, and fmod corresponds to the REM function of the IEEE floating-point standard.
- trait TruncatedDivisionCRing[A] extends TruncatedDivision[A] with CRing[A]
-
trait
UniqueFactorizationDomain[A] extends Any
A unique factorization domain is a commutative ring in which each element can be written as a product of prime elements and a unit.
A unique factorization domain is a commutative ring in which each element can be written as a product of prime elements and a unit.
Unique factorization domains are GCD rings (or domains), but not necessarily Euclidean domains.
This trait is outside the commutative ring hierarchy, because the factorization algorithms are costly. Another reason: in some cases, a deliberate choice should be made by the user, for example to use probabilistic algorithms with a specified probability of failure.
-
trait
VectorSpace[V, F] extends CModule[V, F]
A vector space is a group
V
that can be multiplied by scalars inF
that lie in a field.A vector space is a group
V
that can be multiplied by scalars inF
that lie in a field. Scalar multiplication must distribute over vector addition (x *: (v + w) === x *: v + x *: w
) and scalar addition ((x + y) *: v === x *: v + y *: v
). Scalar multiplication by 1 inF
is an identity function (1 *: v === v
). Scalar multiplication is "associative" (x *: y *: v === (x * y) *: v
). -
trait
ZAlgebra[V] extends RingAssociativeAlgebra[V, Int] with Ring[V]
Given any
Ring[A]
we can construct aRingAlgebra[A, Int]
.Given any
Ring[A]
we can construct aRingAlgebra[A, Int]
. This is possible since we can definefromInt
onRing
generally.
Value Members
- val AbGroup: CommutativeGroup.type
- val AdditiveAbGroup: AdditiveCommutativeGroup.type
- val AdditiveCMonoid: AdditiveCommutativeMonoid.type
- val AdditiveCSemigroup: AdditiveCommutativeSemigroup.type
- val AdditiveGroup: algebra.ring.AdditiveGroup.type
- val AdditiveMonoid: algebra.ring.AdditiveMonoid.type
- val AdditiveSemigroup: algebra.ring.AdditiveSemigroup.type
- val AlgebraField: algebra.ring.Field.type
- val Bool: algebra.lattice.Bool.type
- val CMonoid: CommutativeMonoid.type
- val CRig: CommutativeRig.type
- val CRing: CommutativeRing.type
- val CRng: CommutativeRng.type
- val CSemigroup: CommutativeSemigroup.type
- val CSemiring: CommutativeSemiring.type
- val Eq: cats.kernel.Eq.type
- val Group: cats.kernel.Group.type
- val Monoid: cats.kernel.Monoid.type
- val MultiplicativeAbGroup: MultiplicativeCommutativeGroup.type
- val MultiplicativeCMonoid: MultiplicativeCommutativeMonoid.type
- val MultiplicativeCSemigroup: MultiplicativeCommutativeSemigroup.type
- val MultiplicativeGroup: algebra.ring.MultiplicativeGroup.type
- val MultiplicativeMonoid: algebra.ring.MultiplicativeMonoid.type
- val MultiplicativeSemigroup: algebra.ring.MultiplicativeSemigroup.type
- val Order: cats.kernel.Order.type
- val PartialOrder: cats.kernel.PartialOrder.type
- val Rig: algebra.ring.Rig.type
- val Ring: algebra.ring.Ring.type
- val Rng: algebra.ring.Rng.type
- val Semigroup: cats.kernel.Semigroup.type
- val Semiring: algebra.ring.Semiring.type
- object Action
- object Additive
- object AdditiveTorsor
- object CModule extends Serializable
- object CoordinateSpace extends Serializable
- object DivisionRing extends Serializable
- object EuclideanRing extends EuclideanRingFunctions[EuclideanRing] with Serializable
- object Field extends FieldFunctions[Field] with EuclideanRingFunctions[Field] with Serializable
- object FieldAssociativeAlgebra extends Serializable
- object GCDRing extends GCDRingFunctions[GCDRing] with Serializable
- object InnerProductSpace extends Serializable
- object Involution
- object IsAlgebraic extends Serializable
- object IsIntegral extends Serializable
- object IsRational extends Serializable
- object IsReal extends Serializable
- object LeftAction
- object LeftModule extends Serializable
- object MetricSpace extends MetricSpace0
- object Multiplicative
- object MultiplicativeTorsor
- object NRoot
- object NormedVectorSpace extends NormedVectorSpace0 with NormedVectorSpaceFunctions with Serializable
- object RightAction
- object RightModule extends Serializable
- object RingAssociativeAlgebra extends Serializable
- object Sign
- object Signed extends Serializable
- object Torsor
- object Trig
- object TruncatedDivision extends Serializable
- object UniqueFactorizationDomain
- object VectorSpace extends Serializable
- object ZAlgebra extends Serializable