Module alga::general [] [src]

Fundamental algebraic structures.

For most applications requiring an abstraction over the reals, Real should be sufficient.

Algebraic properties

The goal of algebraic structures is to allow elements of sets to be combined together using one or several operators. The number and properties of those operators characterize the algebraic structure. Abstract operators are usually noted , +, or ×. The last two are preferred when their behavior conform with the usual meaning of addition and multiplication of reals. Let Self be a set. Here is a list of the most common properties those operator may fulfill:

(Closure)       a, b ∈ Self ⇒ a ∘ b ∈ Self, 
(Divisibility)  ∀ a, b ∈ Self, ∃! r, l ∈ Self such that l ∘ a = b and a ∘ r = b
(Invertibility) ∃ e ∈ Self, ∀ a ∈ Self, ∃ r, l ∈ Self such that l ∘ a = a ∘ r = e
                If the right and left inverse are equal they are usually noted r = l = a⁻¹.
(Associativity) ∀ a, b, c ∈ Self, (a ∘ b) ∘ c = a ∘ (b ∘ c)       
(Neutral Elt.)  ∃ e ∈ Self, ∀ a ∈ Self, e ∘ a = a ∘ e = a
(Commutativity) ∀ a, b ∈ Self, a ∘ b = b ∘ a

Identity elements

Two traits are provided that allow the definition of the additive and multiplicative identity elements:

  • IdentityAdditive
  • IdentityMultiplicative

Group-like structures

These structures are provided for both the addition and multiplication.

              Magma
                |
        _______/ \______
       /                \
 divisibility      associativity
      |                  |
      V                  V
 Quasigroup          Semigroup
      |                  |
  identity            identity
      |                  |
      V                  V
    Loop               Monoid
      |                  |
 associativity     invertibility
       \______   _______/
              \ /
               |
               V
             Group
               |
         commutativity
               |
               V
          AbelianGroup

The following traits are provided:

  • Closure(Additive|Multiplicative)
  • Magma(Additive|Multiplicative)
  • Quasigroup(Additive|Multiplicative)
  • Loop(Additive|Multiplicative)
  • Semigroup(Additive|Multiplicative)
  • Monoid(Additive|Multiplicative)
  • Group(Additive|Multiplicative)
  • AbelianGroup(Additive|Multiplicative)

Ring-like structures

GroupAdditiveAbelian     MonoidMultiplicative
          \________   ________/
                   \ /
                    |
                    V
                   Ring
                    |
           commutativity_of_mul
                    |
                    V
             RingCommutative     GroupMultiplicativeAbelian
                     \_______   ___________/
                             \ /
                              |
                              V
                            Field

The following traits are provided:

  • Ring
  • RingCommutative
  • Field

Module-like structures

GroupAdditiveAbelian     RingCommutative
          \______         _____/
                 \       /
                  |     |
                  V     V
               Module<Scalar>          Field
                   \______         _____/
                          \       /
                           |     |
                           V     V
                     VectorSpace<Scalar>

The following traits are provided:

  • Module
  • VectorSpace

Quickcheck properties

Functions are provided to test that algebraic properties like assciociativity and commutativity hold for a given set of arguments.

For example:

#[quickcheck]
fn prop_mul_is_associative(args: (i32, i32, i32)) -> bool {
    SemigroupMultiplicative::prop_mul_is_associative(args)
}

Structs

Additive

The addition operator, commonly symbolized by +.

Multiplicative

The multiplication operator, commonly symbolized by ×.

Wrapper

Wrapper that allows to use operators on algebraic types.

Traits

Field

A field is a commutative ring, and an abelian group under the multiplication operator.

Group

A group is a loop and a monoid at the same time.

GroupAbelian

An commutative group.

Identity

A type that is equipped with identity.

Inverse

Trait used to define the inverse element relative to the given operator.

Loop

A quasigroup with an unique identity element.

Magma

Types that are closed under a given operator.

Module

A module combines two sets: one with an additive abelian group structure and another with a commutative ring structure.

Monoid

A semigroup equipped with an identity element.

Op

Trait implemented by types representing operators.

Quasigroup

A magma with the divisibility property.

Real

Trait shared by all reals.

Recip

The multiplicative inverse operation

Ring

A ring is the combination of an abelian group and a multiplicative monoid structure.

RingCommutative

A ring with a commutative multiplication.

Semigroup

An associative magma.

Functions

id

Creates wrapper with identity value for a specific operator.

inv

Returns the inverse of m, relative to the operator _o.