p

spire

algebra

package algebra

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. algebra
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. type AbGroup[A] = CommutativeGroup[A]
  2. trait Action[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.

  3. type AdditiveAbGroup[A] = AdditiveCommutativeGroup[A]
  4. trait AdditiveAction[P, G] extends Any
  5. type AdditiveCMonoid[A] = AdditiveCommutativeMonoid[A]
  6. type AdditiveCSemigroup[A] = AdditiveCommutativeSemigroup[A]
  7. type AdditiveGroup[A] = algebra.ring.AdditiveGroup[A]
  8. type AdditiveMonoid[A] = algebra.ring.AdditiveMonoid[A]
  9. type AdditiveSemigroup[A] = algebra.ring.AdditiveSemigroup[A]
  10. trait AdditiveTorsor[V, R] extends AdditiveAction[V, R]
  11. type AlgebraField[A] = algebra.ring.Field[A]
  12. type Bool[A] = algebra.lattice.Bool[A]
  13. 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

  14. type CMonoid[A] = CommutativeMonoid[A]
  15. type CRig[A] = CommutativeRig[A]
  16. type CRing[A] = CommutativeRing[A]
  17. type CRng[A] = CommutativeRng[A]
  18. type CSemigroup[A] = CommutativeSemigroup[A]
  19. type CSemiring[A] = CommutativeSemiring[A]
  20. trait CoordinateSpace[V, F] extends InnerProductSpace[V, F]
  21. trait DivisionRing[A] extends Ring[A] with MultiplicativeGroup[A]
  22. type Eq[A] = cats.kernel.Eq[A]
  23. 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

  24. trait EuclideanRingFunctions[R[T] <: EuclideanRing[T]] extends GCDRingFunctions[R]
  25. 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 and EuclideanRing.

    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.

  26. trait FieldAssociativeAlgebra[V, F] extends RingAssociativeAlgebra[V, F] with VectorSpace[V, F]

    A FieldAlgebra is a vector space that is also a Ring.

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

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

  28. trait GCDRingFunctions[R[T] <: GCDRing[T]] extends RingFunctions[R]
  29. type Group[A] = cats.kernel.Group[A]
  30. trait InnerProductSpace[V, F] extends VectorSpace[V, F]
  31. 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 ).

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

  32. trait IsAlgebraic[A] extends IsReal[A]
  33. trait IsIntegral[A] extends IsRational[A]
  34. trait IsRational[A] extends IsAlgebraic[A]
  35. trait IsReal[A] extends Signed[A]

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

  36. trait LeftAction[P, G] extends Any

    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)

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

  38. 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 in V is measured in R, which should be real (ie. IsReal[R] exists).

  39. type Monoid[A] = cats.kernel.Monoid[A]
  40. type MultiplicativeAbGroup[A] = MultiplicativeCommutativeGroup[A]
  41. trait MultiplicativeAction[P, G] extends Any
  42. type MultiplicativeCMonoid[A] = MultiplicativeCommutativeMonoid[A]
  43. type MultiplicativeCSemigroup[A] = MultiplicativeCommutativeSemigroup[A]
  44. type MultiplicativeGroup[A] = algebra.ring.MultiplicativeGroup[A]
  45. type MultiplicativeMonoid[A] = algebra.ring.MultiplicativeMonoid[A]
  46. type MultiplicativeSemigroup[A] = algebra.ring.MultiplicativeSemigroup[A]
  47. trait MultiplicativeTorsor[V, R] extends MultiplicativeAction[V, R]
  48. 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 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!

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

  50. type Order[A] = cats.kernel.Order[A]
  51. type PartialOrder[A] = cats.kernel.PartialOrder[A]
  52. type Rig[A] = algebra.ring.Rig[A]
  53. trait RightAction[P, G] extends Any

    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)

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

  55. type Ring[A] = algebra.ring.Ring[A]
  56. trait RingAssociativeAlgebra[V, R] extends CModule[V, R] with Ring[V]

    A RingAssociativeAlgebra is a R-module that is also a Ring.

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

  57. type Rng[A] = algebra.ring.Rng[A]
  58. type Semigroup[A] = cats.kernel.Semigroup[A]
  59. type Semiring[A] = algebra.ring.Semiring[A]
  60. sealed abstract class Sign extends AnyRef

    A simple ADT representing the Sign of an object.

  61. 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 then a + c <= b + c (linear order), (2) signum(x) = -1 if x < 0, signum(x) = 1 if x > 0, signum(x) = 0 otherwise,

    Negative elements only appear when scalar is a additive abelian group, and then (3) abs(x) = -x if x < 0, or x 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?).

  62. trait SignedAdditiveAbGroup[A] extends SignedAdditiveCMonoid[A] with AdditiveAbGroup[A]
  63. trait SignedAdditiveCMonoid[A] extends Signed[A] with AdditiveCMonoid[A]
  64. 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 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.

  65. trait Trig[A] extends Any
  66. 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.

  67. trait TruncatedDivisionCRing[A] extends TruncatedDivision[A] with CRing[A]
  68. 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.

  69. trait VectorSpace[V, 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.

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

  70. trait ZAlgebra[V] extends RingAssociativeAlgebra[V, Int] with Ring[V]

    Given any Ring[A] we can construct a RingAlgebra[A, Int].

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

Value Members

  1. val AbGroup: CommutativeGroup.type
  2. val AdditiveAbGroup: AdditiveCommutativeGroup.type
  3. val AdditiveCMonoid: AdditiveCommutativeMonoid.type
  4. val AdditiveCSemigroup: AdditiveCommutativeSemigroup.type
  5. val AdditiveGroup: algebra.ring.AdditiveGroup.type
  6. val AdditiveMonoid: algebra.ring.AdditiveMonoid.type
  7. val AdditiveSemigroup: algebra.ring.AdditiveSemigroup.type
  8. val AlgebraField: algebra.ring.Field.type
  9. val Bool: algebra.lattice.Bool.type
  10. val CMonoid: CommutativeMonoid.type
  11. val CRig: CommutativeRig.type
  12. val CRing: CommutativeRing.type
  13. val CRng: CommutativeRng.type
  14. val CSemigroup: CommutativeSemigroup.type
  15. val CSemiring: CommutativeSemiring.type
  16. val Eq: cats.kernel.Eq.type
  17. val Group: cats.kernel.Group.type
  18. val Monoid: cats.kernel.Monoid.type
  19. val MultiplicativeAbGroup: MultiplicativeCommutativeGroup.type
  20. val MultiplicativeCMonoid: MultiplicativeCommutativeMonoid.type
  21. val MultiplicativeCSemigroup: MultiplicativeCommutativeSemigroup.type
  22. val MultiplicativeGroup: algebra.ring.MultiplicativeGroup.type
  23. val MultiplicativeMonoid: algebra.ring.MultiplicativeMonoid.type
  24. val MultiplicativeSemigroup: algebra.ring.MultiplicativeSemigroup.type
  25. val Order: cats.kernel.Order.type
  26. val PartialOrder: cats.kernel.PartialOrder.type
  27. val Rig: algebra.ring.Rig.type
  28. val Ring: algebra.ring.Ring.type
  29. val Rng: algebra.ring.Rng.type
  30. val Semigroup: cats.kernel.Semigroup.type
  31. val Semiring: algebra.ring.Semiring.type
  32. object Action
  33. object Additive
  34. object AdditiveTorsor
  35. object CModule extends Serializable
  36. object CoordinateSpace extends Serializable
  37. object DivisionRing extends Serializable
  38. object EuclideanRing extends EuclideanRingFunctions[EuclideanRing] with Serializable
  39. object Field extends FieldFunctions[Field] with EuclideanRingFunctions[Field] with Serializable
  40. object FieldAssociativeAlgebra extends Serializable
  41. object GCDRing extends GCDRingFunctions[GCDRing] with Serializable
  42. object InnerProductSpace extends Serializable
  43. object Involution
  44. object IsAlgebraic extends Serializable
  45. object IsIntegral extends Serializable
  46. object IsRational extends Serializable
  47. object IsReal extends Serializable
  48. object LeftAction
  49. object LeftModule extends Serializable
  50. object MetricSpace extends MetricSpace0
  51. object Multiplicative
  52. object MultiplicativeTorsor
  53. object NRoot
  54. object NormedVectorSpace extends NormedVectorSpace0 with NormedVectorSpaceFunctions with Serializable
  55. object RightAction
  56. object RightModule extends Serializable
  57. object RingAssociativeAlgebra extends Serializable
  58. object Sign
  59. object Signed extends Serializable
  60. object Torsor
  61. object Trig
  62. object TruncatedDivision extends Serializable
  63. object UniqueFactorizationDomain
  64. object VectorSpace extends Serializable
  65. object ZAlgebra extends Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped