[][src]Struct free_algebra::monoid::MonoidalString

pub struct MonoidalString<C, M: ?Sized> { /* fields omitted */ }

Creates free-arithmetic constructions based upon free-multiplication of letters of type C that uses a Vec<C> internally

Basic Construction

Given type parameters C and M, the construction goes as follows:

  • Internally, each instance contains a list of values of type C
  • By default, multiplication is given by concatenating the internal Vec's of each argument
  • Then, with the above as a base, the given type M can modify that operation by applying a multiplication rule to the internal list every time another C is appended to it

With this system, using different M rules and C types, a number of variants can be defined:

  • FreeMonoid<C> is created by using the default multiplication with any C
  • FreeGroup<C> is made by wrapping it in a FreeInv<C> to allow each C to be inverted and by and modifying M to make inverses cancel
  • FreePowMonoid<C,P> is constructed by wrapping each C in a FreePow<C> to raise each element to a symbolic power P and by having M combine any adjacent elements with equal base by adding their exponents

Other impls

In addition to the basic multiplication traits, MonoidalString implements a number of other notable traits depending on the type arguments:

A note on IterMut

The method [MonoidalString.iter_mut()] will give an valid iterator over mutable references to each element of the object, but it is of note that because of the nature of some of the MonoidRule's, the method will reallocate internal storage and iterate through every element, even if dropped.

The reason for this is that if it did not, it would be possible to modify a MonoidalString into an invalid state. Hence, to mitigate this, the iterator must remultiply every element again as it iterates over the references.

Methods

impl<C, M: ?Sized> MonoidalString<C, M>[src]

pub fn len(&self) -> usize[src]

Returns the number of letters in this monoidal-string

Examples

use maths_traits::algebra::One;
use free_algebra::FreeMonoid;

let x = FreeMonoid::one();
let y = x.clone() * 'a' * 'a';

assert_eq!(x.len(), 0);
assert_eq!(y.len(), 2);

pub fn iter(&self) -> Iter<C>[src]

Produces an iterator over references to the letters in this element

Examples

use maths_traits::algebra::One;
use free_algebra::FreeMonoid;

let x = FreeMonoid::one() * 'a' * 'b' * 'c';
let mut iter = x.iter();

assert_eq!(iter.next(), Some(&'a'));
assert_eq!(iter.next(), Some(&'b'));
assert_eq!(iter.next(), Some(&'c'));
assert_eq!(iter.next(), None);

Important traits for IterMut<'a, C, M>
pub fn iter_mut(&mut self) -> IterMut<C, M> where
    M: MonoidRule<C>, 
[src]

Produces an iterator over mutable references to the letters in this element

Note that the potential for modification does mean that the element needs to be remultiplied as letters are changed, so a potential reallocation of space may occur.

Examples

use free_algebra::{FreePow, FreePowMonoid};

let x = FreePow('a',1) * FreePow('b',1) * FreePow('c',1);
let mut y = x.clone();

for FreePow(c,p) in y.iter_mut() {
    *c = 'a';
}

assert_eq!(x, [FreePow('a',1), FreePow('b',1), FreePow('c',1)]);
assert_eq!(y, [FreePow('a',3)]);

pub fn reverse(self) -> Self where
    Self: Product<C>, 
[src]

Reverses the letters in this element and remultiplies

Examples

use maths_traits::algebra::One;
use free_algebra::FreeMonoid;

let x = FreeMonoid::one() * 'a' * 'b' * 'c';
let y = x.clone().reverse();

assert_eq!(x, ['a', 'b', 'c']);
assert_eq!(y, ['c', 'b', 'a']);

pub fn commutator(self, rhs: Self) -> Self where
    Self: MulMonoid + Inv<Output = Self>, 
[src]

Computes the multiplicative commutator [a,b] = a⁻¹b⁻¹ab

Examples

use free_algebra::FreeGroup;
use free_algebra::FreeInv::*;

let x:FreeGroup<_> = Id('a').into();
let y:FreeGroup<_> = Id('b').into();

assert_eq!(x, [Id('a')]);
assert_eq!(y, [Id('b')]);
assert_eq!(x.commutator(y), [Inv('a'), Inv('b'), Id('a'), Id('b')]);

A property of significance for this product is that when the arguments commute, the output is always 1.

use maths_traits::algebra::One;
use free_algebra::{FreePowMonoid, FreePow};

let x:FreePowMonoid<_,_> = FreePow('a', 2).into();
let y:FreePowMonoid<_,_> = FreePow('a', -24).into();

assert!(x.commutator(y).is_one());

Trait Implementations

impl<C, M: ?Sized> AsRef<[C]> for MonoidalString<C, M>[src]

impl<C, M: ?Sized> From<C> for MonoidalString<C, M>[src]

impl<C, M: MonoidRule<C> + ?Sized> Extend<C> for MonoidalString<C, M>[src]

impl<C, M: ?Sized> IntoIterator for MonoidalString<C, M>[src]

type Item = C

The type of the elements being iterated over.

type IntoIter = IntoIter<C>

Which kind of iterator are we turning this into?

impl<C, M: ?Sized> Clone for MonoidalString<C, M> where
    C: Clone
[src]

impl<C, M: ?Sized> Default for MonoidalString<C, M>[src]

impl<C: Eq, M: ?Sized> Eq for MonoidalString<C, M>[src]

impl<C: Ord, M: ?Sized> Ord for MonoidalString<C, M>[src]

impl<C: PartialEq, M: ?Sized, V: Borrow<[C]>> PartialEq<V> for MonoidalString<C, M>[src]

impl<C: PartialOrd, M: ?Sized> PartialOrd<MonoidalString<C, M>> for MonoidalString<C, M>[src]

impl<C: Display, M: ?Sized> Display for MonoidalString<C, M>[src]

Formats the MonoidalString as a sequence of factors separated by *'s

Examples

use maths_traits::algebra::One;
use free_algebra::FreeMonoid;

let x = FreeMonoid::one() * 'a' * 'b' * 'c';
assert_eq!(format!("{}", x), "a*b*c");
use maths_traits::algebra::*;
use free_algebra::FreeInv::*;

let y = Id('a') * Inv('b') * Inv('a') * Id('c');
assert_eq!(format!("{}", y), "a*b⁻¹*a⁻¹*c");

Note that if the "alternate" flag # is used, then the *'s will be dropped.

use maths_traits::algebra::One;
use free_algebra::FreeMonoid;

let x = FreeMonoid::one() * 'a' * 'b' * 'c';
assert_eq!(format!("{:#}", x), "abc");
use maths_traits::algebra::*;
use free_algebra::FreeInv::*;

let y = Id('a') * Inv('b') * Inv('a') * Id('c');
assert_eq!(format!("{:#}", y), "ab⁻¹a⁻¹c");

impl<C, M: ?Sized> Debug for MonoidalString<C, M> where
    C: Debug
[src]

impl<T: Eq> Div<MonoidalString<FreeInv<T>, InvRule>> for FreeInv<T>[src]

type Output = FreeGroup<T>

The resulting type after applying the / operator.

impl<C: Eq, P: Add<Output = P> + Neg<Output = P> + Zero> Div<MonoidalString<FreePow<C, P>, PowRule>> for FreePow<C, P>[src]

type Output = FreePowMonoid<C, P>

The resulting type after applying the / operator.

impl<RHS, C, M> Div<RHS> for MonoidalString<C, M> where
    M: ?Sized,
    Self: DivAssign<RHS>, 
[src]

type Output = Self

The resulting type after applying the / operator.

impl<'a, RHS, C, M> Div<RHS> for &'a MonoidalString<C, M> where
    M: ?Sized,
    MonoidalString<C, M>: Clone + Div<RHS>, 
[src]

type Output = <MonoidalString<C, M> as Div<RHS>>::Output

The resulting type after applying the / operator.

impl<T: Eq> Mul<MonoidalString<FreeInv<T>, InvRule>> for FreeInv<T>[src]

type Output = FreeGroup<T>

The resulting type after applying the * operator.

impl<C: Eq, P: Add<Output = P>> Mul<MonoidalString<FreePow<C, P>, PowRule>> for FreePow<C, P>[src]

type Output = FreePowMonoid<C, P>

The resulting type after applying the * operator.

impl<RHS, C, M> Mul<RHS> for MonoidalString<C, M> where
    M: ?Sized,
    Self: MulAssign<RHS>, 
[src]

type Output = Self

The resulting type after applying the * operator.

impl<'a, RHS, C, M> Mul<RHS> for &'a MonoidalString<C, M> where
    M: ?Sized,
    MonoidalString<C, M>: Clone + Mul<RHS>, 
[src]

type Output = <MonoidalString<C, M> as Mul<RHS>>::Output

The resulting type after applying the * operator.

impl<C, M: MonoidRule<C> + ?Sized> MulAssign<C> for MonoidalString<C, M>[src]

impl<C, M: MonoidRule<C> + ?Sized> MulAssign<MonoidalString<C, M>> for MonoidalString<C, M>[src]

impl<'a, C, M> MulAssign<&'a C> for MonoidalString<C, M> where
    M: ?Sized,
    Self: MulAssign<C>,
    C: Clone
[src]

impl<'a, C, M> MulAssign<&'a MonoidalString<C, M>> for MonoidalString<C, M> where
    M: ?Sized,
    Self: MulAssign<Self>,
    Self: Clone
[src]

impl<C, M: InvMonoidRule<C> + ?Sized> DivAssign<C> for MonoidalString<C, M>[src]

impl<C, M: InvMonoidRule<C> + ?Sized> DivAssign<MonoidalString<C, M>> for MonoidalString<C, M>[src]

impl<'a, C, M> DivAssign<&'a C> for MonoidalString<C, M> where
    M: ?Sized,
    Self: DivAssign<C>,
    C: Clone
[src]

impl<'a, C, M> DivAssign<&'a MonoidalString<C, M>> for MonoidalString<C, M> where
    M: ?Sized,
    Self: DivAssign<Self>,
    Self: Clone
[src]

impl<C, M: ?Sized, I> Index<I> for MonoidalString<C, M> where
    Vec<C>: Index<I>, 
[src]

type Output = <Vec<C> as Index<I>>::Output

The returned type after indexing.

impl<C, M: ?Sized> Hash for MonoidalString<C, M> where
    C: Hash
[src]

impl<C, M: ?Sized, T> FromIterator<T> for MonoidalString<C, M> where
    Self: Product<T>, 
[src]

impl<C, M: MonoidRule<C> + ?Sized> Product<C> for MonoidalString<C, M>[src]

impl<C, M: MonoidRule<C> + ?Sized> Product<MonoidalString<C, M>> for MonoidalString<C, M>[src]

impl<C, M: ?Sized> Borrow<[C]> for MonoidalString<C, M>[src]

impl<C, M: MonoidRule<C> + ?Sized> One for MonoidalString<C, M>[src]

impl<C, M: InvMonoidRule<C> + ?Sized> Inv for MonoidalString<C, M>[src]

type Output = Self

The result after applying the operator.

impl<'a, C, M: InvMonoidRule<C> + ?Sized> Inv for &'a MonoidalString<C, M> where
    MonoidalString<C, M>: Clone
[src]

type Output = MonoidalString<C, M>

The result after applying the operator.

impl<Z: IntegerSubset, C: Clone, M: MonoidRule<C> + ?Sized> Pow<Z> for MonoidalString<C, M> where
    Self: PowMarker<Z> + MulAssociative
[src]

type Output = Self

The result after applying the operator.

impl<Z: IntegerSubset, C: Clone, M: InvMonoidRule<C> + ?Sized> Pow<Z> for MonoidalString<C, M> where
    Self: PowMarker<Z> + MulAssociative
[src]

impl<C, M: AssociativeMonoidRule<C> + ?Sized> MulAssociative for MonoidalString<C, M>[src]

impl<C, M: CommutativeMonoidRule<C> + ?Sized> MulCommutative for MonoidalString<C, M>[src]

Auto Trait Implementations

impl<C, M: ?Sized> Send for MonoidalString<C, M> where
    C: Send,
    M: Send

impl<C, M: ?Sized> Sync for MonoidalString<C, M> where
    C: Sync,
    M: Sync

impl<C, M: ?Sized> Unpin for MonoidalString<C, M> where
    C: Unpin,
    M: Unpin

impl<C, M: ?Sized> UnwindSafe for MonoidalString<C, M> where
    C: UnwindSafe,
    M: UnwindSafe

impl<C, M: ?Sized> RefUnwindSafe for MonoidalString<C, M> where
    C: RefUnwindSafe,
    M: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> From<!> for T[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<G> PowN for G where
    G: MulSemigroup + One
[src]

impl<G> PowZ for G where
    G: Invertable + MulMonoid
[src]