Module

Data.Field

Package
purescript-prelude
Repository
purescript/purescript-prelude

#Field Source

class (EuclideanRing a) <= Field a 

The Field class is for types that are (commutative) fields.

Instances must satisfy the following law in addition to the EuclideanRing laws:

  • Non-zero multiplicative inverse: a `mod` b = zero for all a and b

If a type has a Field instance, it should also have a DivisionRing instance. In a future release, DivisionRing may become a superclass of Field.

Instances

Re-exports from Data.CommutativeRing

#CommutativeRing Source

class (Ring a) <= CommutativeRing a 

The CommutativeRing class is for rings where multiplication is commutative.

Instances must satisfy the following law in addition to the Ring laws:

  • Commutative multiplication: a * b = b * a

Instances

Re-exports from Data.DivisionRing

#DivisionRing Source

class (Ring a) <= DivisionRing a  where

The DivisionRing class is for non-zero rings in which every non-zero element has a multiplicative inverse. Division rings are sometimes also called skew fields.

Instances must satisfy the following laws in addition to the Ring laws:

  • Non-zero ring: one /= zero
  • Non-zero multiplicative inverse: recip a * a = a * recip a = one for all non-zero a

The result of recip zero is left undefined; individual instances may choose how to handle this case.

If a type has both DivisionRing and CommutativeRing instances, then it is a field and should have a Field instance.

Members

Instances

Re-exports from Data.EuclideanRing

#EuclideanRing Source

class (CommutativeRing a) <= EuclideanRing a  where

The EuclideanRing class is for commutative rings that support division. The mathematical structure this class is based on is sometimes also called a Euclidean domain.

Instances must satisfy the following laws in addition to the Ring laws:

  • Integral domain: one /= zero, and if a and b are both nonzero then so is their product a * b
  • Euclidean function degree:
    • Nonnegativity: For all nonzero a, degree a >= 0
    • Quotient/remainder: For all a and b, where b is nonzero, let q = a / b and r = a `mod` b; then a = q*b + r, and also either r = zero or degree r < degree b
  • Submultiplicative euclidean function:
    • For all nonzero a and b, degree a <= degree (a * b)

The behaviour of division by zero is unconstrained by these laws, meaning that individual instances are free to choose how to behave in this case. Similarly, there are no restrictions on what the result of degree zero is; it doesn't make sense to ask for degree zero in the same way that it doesn't make sense to divide by zero, so again, individual instances may choose how to handle this case.

For any EuclideanRing which is also a Field, one valid choice for degree is simply const 1. In fact, unless there's a specific reason not to, Field types should normally use this definition of degree.

Members

Instances

#lcm Source

lcm :: forall a. Eq a => EuclideanRing a => a -> a -> a

The least common multiple of two values.

#gcd Source

gcd :: forall a. Eq a => EuclideanRing a => a -> a -> a

The greatest common divisor of two values.

#(/) Source

Operator alias for Data.EuclideanRing.div (left-associative / precedence 7)

Re-exports from Data.Ring

#Ring Source

class (Semiring a) <= Ring a  where

The Ring class is for types that support addition, multiplication, and subtraction operations.

Instances must satisfy the following law in addition to the Semiring laws:

  • Additive inverse: a - a = (zero - a) + a = zero

Members

  • sub :: a -> a -> a

Instances

#negate Source

negate :: forall a. Ring a => a -> a

negate x can be used as a shorthand for zero - x.

Re-exports from Data.Semiring

#Semiring Source

class Semiring a  where

The Semiring class is for types that support an addition and multiplication operation.

Instances must satisfy the following laws:

  • Commutative monoid under addition:
    • Associativity: (a + b) + c = a + (b + c)
    • Identity: zero + a = a + zero = a
    • Commutative: a + b = b + a
  • Monoid under multiplication:
    • Associativity: (a * b) * c = a * (b * c)
    • Identity: one * a = a * one = a
  • Multiplication distributes over addition:
    • Left distributivity: a * (b + c) = (a * b) + (a * c)
    • Right distributivity: (a + b) * c = (a * c) + (b * c)
  • Annihilation: zero * a = a * zero = zero

Note: The Number and Int types are not fully law abiding members of this class hierarchy due to the potential for arithmetic overflows, and in the case of Number, the presence of NaN and Infinity values. The behaviour is unspecified in these cases.

Members

Instances

#(+) Source

Operator alias for Data.Semiring.add (left-associative / precedence 6)

#(*) Source

Operator alias for Data.Semiring.mul (left-associative / precedence 7)