spire.algebra

Type members

Classlikes

trait Action[@specialized(Int) P, G] extends LeftAction[P, G] with RightAction[P, G]

A semigroup/monoid/group action of G on P is the combination of compatible left and right actions, providing:

A semigroup/monoid/group action of G on P is the combination of compatible left and right actions, providing:

 - the implementation of a method `actl(g, p)`, or `g |+|> p`, such that:

1. `(g |+| h) |+|> p === g |+|> (h |+|> p)` for all `g`, `h` in `G` and `p` in `P`.

2. `id |+|> p === p` for all `p` in `P` (if `id` is defined)

 - the implementation of a method `actr(p, g)`, or `p <|+| g`, such that:

3. `p <|+| (g |+| h) === (p <|+| g) <|+| h` for all `g`, `h` in `G` and `p` in `P`.

4. `p <|+| id === p` for all `p` in `P` (if `id` is defined)

In addition, if `G` is a group, left and right actions are compatible:

5. `g |+|> p === p <|+| g.inverse`.
Companion:
object
object Action
Companion:
class
object Additive
Companion:
object
Companion:
class
trait CModule[V, @specialized(Int, Long, Float, Double) 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)
Type parameters:
R

Scalar type

V

Abelian group type

Companion:
object
object CModule
Companion:
class
Companion:
object
Companion:
class

A FieldAlgebra is a vector space that is also a Ring. An example is the complex numbers.

A FieldAlgebra is a vector space that is also a Ring. An example is the complex numbers.

Companion:
object
Companion:
object
Companion:
class

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 ).

   i. 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)
Companion:
object
object Involution
Companion:
class
trait IsAlgebraic[@specialized A] extends IsReal[A]
Companion:
object
Companion:
class
trait IsIntegral[A] extends IsRational[A]
Companion:
object
object IsIntegral
Companion:
class
trait IsRational[A] extends IsAlgebraic[A]
Companion:
object
object IsRational
Companion:
class
trait IsReal[@specialized A] extends Order[A] with Signed[A]

A simple type class for numeric types that are a subset of the reals.

A simple type class for numeric types that are a subset of the reals.

Companion:
object
object IsReal
Companion:
class

A (left) semigroup/monoid/group action of G on P is simply the implementation of a method actl(g, p), or g \|+|> p, such that:

A (left) semigroup/monoid/group action of G on P is simply the implementation of a method actl(g, p), or g \|+|> p, such that:

1. `(g |+| h) |+|> p === g |+|> (h |+|> p)` for all `g`, `h` in `G` and `p` in `P`.

2. `id |+|> p === p` for all `p` in `P` (if `id` is defined)
Companion:
object
object LeftAction
Companion:
class

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) )

Type parameters:
R

Scalar type

V

Abelian group type

Companion:
object
object LeftModule
Companion:
class

This type class models a metric space V. The distance between 2 points in V is measured in R, which should be real (ie. IsReal[R] exists).

This type class models a metric space V. The distance between 2 points in V is measured in R, which should be real (ie. IsReal[R] exists).

Companion:
object
Companion:
class
Companion:
class
Companion:
class

This is a type class for types with n-roots. The value returned by nroot and sqrt are only guaranteed to be approximate answers (except in the case of Real).

This is a type class for types with n-roots. The value returned by nroot and sqrt are only guaranteed to be approximate answers (except in the case of Real).

Also, generally nroots where n 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 on ArithmeticExceptions to save you from bad arithmetic!

Companion:
object
object NRoot
Companion:
class
trait NormedVectorSpace[V, @specialized(Int, Long, Float, Double) F] extends VectorSpace[V, F] with MetricSpace[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 is norm(k *: v) == k.abs * norm(v). Additionally, a normed vector space is also a MetricSpace, where distance(v, w) = norm(v - w), and so must obey the triangle inequality.

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 is norm(k *: v) == k.abs * norm(v). Additionally, a normed vector space is also a MetricSpace, where distance(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.

Companion:
object
Companion:
class

A (right) semigroup/monoid/group action of G on P is simply the implementation of a method actr(p, g), or p <|+| g, such that:

A (right) semigroup/monoid/group action of G on P is simply the implementation of a method actr(p, g), or p <|+| g, such that:

1. `p <|+| (g |+| h) === (p <|+| g) <|+| h` for all `g`, `h` in `G` and `p` in `P`.

2. `p <|+| id === p` for all `p` in `P` (if `id` is defined)
Companion:
object
Companion:
class

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
Type parameters:
R

Scalar type

V

Abelian group type

Companion:
object
Companion:
class
trait RingAssociativeAlgebra[V, @specialized R] extends CModule[V, R] with Ring[V]

A RingAssociativeAlgebra is a R-module that is also a Ring. An example is the Gaussian numbers, the quaternions, etc...

A RingAssociativeAlgebra is a R-module that is also a Ring. 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])

Companion:
object
trait Torsor[V, @specialized(Int, Long, Float, Double) 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 all `g` in `G`.

2. `(g <-> h) +> h === g` for all `g`, `h` in `G`.

3. `(g <-> h) +> i === (i <-> h) +> g` for all `g`, `h` in `G`.

4. `(g <-> h) === -(h <-> g)` for all `g`, `h` in `G`.
Companion:
object
object Torsor
Companion:
class
Companion:
object
object Trig
Companion:
class

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.

Companion:
object
trait VectorSpace[V, @specialized(Int, Long, Float, Double) F] extends CModule[V, F]

A vector space is a group V that can be multiplied by scalars in F that lie in a field. Scalar multiplication must distribute over vector addition

A vector space is a group V that can be multiplied by scalars in F 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 in `F` is an identity function
(`1 *: v === v`). Scalar multiplication is "associative" (`x *: y *: v === (x * y) *: v`).
Companion:
object
Companion:
class
trait ZAlgebra[V] extends RingAssociativeAlgebra[V, Int] with Ring[V]

Given any Ring[A] we can construct a RingAlgebra[A, Int]. This is possible since we can define fromInt on Ring generally.

Given any Ring[A] we can construct a RingAlgebra[A, Int]. This is possible since we can define fromInt on Ring generally.

Companion:
object
object ZAlgebra
Companion:
class

Types

type Bool[A] = Bool[A]
type CRig[A] = CommutativeRig[A]
type CRing[A] = CommutativeRing[A]
type CRng[A] = CommutativeRng[A]
type Eq[A] = Eq[A]
type Field[A] = Field[A]
type GCDRing[A] = GCDRing[A]
type Group[A] = Group[A]
type Monoid[A] = Monoid[A]
type Order[A] = Order[A]
type Rig[A] = Rig[A]
type Ring[A] = Ring[A]
type Rng[A] = Rng[A]
type Semigroup[A] = Semigroup[A]
type Semiring[A] = Semiring[A]
type Sign = Sign
type Signed[A] = Signed[A]