[−][src]Struct free_algebra::monoid::MonoidalString
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 anotherC
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 anyC
FreeGroup<C>
is made by wrapping it in aFreeInv<C>
to allow eachC
to be inverted and by and modifyingM
to make inverses cancelFreePowMonoid<C,P>
is constructed by wrapping eachC
in aFreePow<C>
to raise each element to a symbolic powerP
and by havingM
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:
- Div, DivAssign, Inv, etc. These apply whenever
M
implements - Index wraps the internal list's implementation
InvMonoidRule<C>
to provide a way to invertC
elements - MulAssociative and MulCommutative whenever
M
implements AssociativeMonoidRule or CommutativeMonoidRule - PartialEq with any type that implements
Borrow<[C]>
. This is in order to make it possible to test equality with other structures (likeVec<C>
and[C]
) that are lists ofC
's - PartialOrd and Ord implement lexicographic ordering
- Extend, FromIterator, and Product all are implemented by applying the multiplication
rule to an Iterator of
C
's.
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]
M: MonoidRule<C>,
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]
Self: Product<C>,
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]
Self: MulMonoid + Inv<Output = Self>,
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]
fn extend<I: IntoIterator<Item = C>>(&mut self, iter: I)
[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?
fn into_iter(self) -> IntoIter<C>
[src]
impl<C, M: ?Sized> Clone for MonoidalString<C, M> where
C: Clone,
[src]
C: Clone,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, other: &Self)
[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]
fn cmp(&self, rhs: &Self) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[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]
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering>
[src]
fn lt(&self, rhs: &Self) -> bool
[src]
fn le(&self, rhs: &Self) -> bool
[src]
fn gt(&self, rhs: &Self) -> bool
[src]
fn ge(&self, rhs: &Self) -> bool
[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]
C: Debug,
impl<T: Eq> Div<MonoidalString<FreeInv<T>, InvRule>> for FreeInv<T>
[src]
type Output = FreeGroup<T>
The resulting type after applying the /
operator.
fn div(self, rhs: FreeGroup<T>) -> FreeGroup<T>
[src]
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.
fn div(self, rhs: FreePowMonoid<C, P>) -> FreePowMonoid<C, P>
[src]
impl<RHS, C, M> Div<RHS> for MonoidalString<C, M> where
M: ?Sized,
Self: DivAssign<RHS>,
[src]
M: ?Sized,
Self: DivAssign<RHS>,
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: RHS) -> Self
[src]
impl<'a, RHS, C, M> Div<RHS> for &'a MonoidalString<C, M> where
M: ?Sized,
MonoidalString<C, M>: Clone + Div<RHS>,
[src]
M: ?Sized,
MonoidalString<C, M>: Clone + Div<RHS>,
type Output = <MonoidalString<C, M> as Div<RHS>>::Output
The resulting type after applying the /
operator.
fn div(self, rhs: RHS) -> Self::Output
[src]
impl<T: Eq> Mul<MonoidalString<FreeInv<T>, InvRule>> for FreeInv<T>
[src]
type Output = FreeGroup<T>
The resulting type after applying the *
operator.
fn mul(self, rhs: FreeGroup<T>) -> FreeGroup<T>
[src]
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.
fn mul(self, rhs: FreePowMonoid<C, P>) -> FreePowMonoid<C, P>
[src]
impl<RHS, C, M> Mul<RHS> for MonoidalString<C, M> where
M: ?Sized,
Self: MulAssign<RHS>,
[src]
M: ?Sized,
Self: MulAssign<RHS>,
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: RHS) -> Self
[src]
impl<'a, RHS, C, M> Mul<RHS> for &'a MonoidalString<C, M> where
M: ?Sized,
MonoidalString<C, M>: Clone + Mul<RHS>,
[src]
M: ?Sized,
MonoidalString<C, M>: Clone + Mul<RHS>,
type Output = <MonoidalString<C, M> as Mul<RHS>>::Output
The resulting type after applying the *
operator.
fn mul(self, rhs: RHS) -> Self::Output
[src]
impl<C, M: MonoidRule<C> + ?Sized> MulAssign<C> for MonoidalString<C, M>
[src]
fn mul_assign(&mut self, rhs: C)
[src]
impl<C, M: MonoidRule<C> + ?Sized> MulAssign<MonoidalString<C, M>> for MonoidalString<C, M>
[src]
fn mul_assign(&mut self, rhs: Self)
[src]
impl<'a, C, M> MulAssign<&'a C> for MonoidalString<C, M> where
M: ?Sized,
Self: MulAssign<C>,
C: Clone,
[src]
M: ?Sized,
Self: MulAssign<C>,
C: Clone,
fn mul_assign(&mut self, rhs: &'a C)
[src]
impl<'a, C, M> MulAssign<&'a MonoidalString<C, M>> for MonoidalString<C, M> where
M: ?Sized,
Self: MulAssign<Self>,
Self: Clone,
[src]
M: ?Sized,
Self: MulAssign<Self>,
Self: Clone,
fn mul_assign(&mut self, rhs: &'a Self)
[src]
impl<C, M: InvMonoidRule<C> + ?Sized> DivAssign<C> for MonoidalString<C, M>
[src]
fn div_assign(&mut self, rhs: C)
[src]
impl<C, M: InvMonoidRule<C> + ?Sized> DivAssign<MonoidalString<C, M>> for MonoidalString<C, M>
[src]
fn div_assign(&mut self, rhs: Self)
[src]
impl<'a, C, M> DivAssign<&'a C> for MonoidalString<C, M> where
M: ?Sized,
Self: DivAssign<C>,
C: Clone,
[src]
M: ?Sized,
Self: DivAssign<C>,
C: Clone,
fn div_assign(&mut self, rhs: &'a C)
[src]
impl<'a, C, M> DivAssign<&'a MonoidalString<C, M>> for MonoidalString<C, M> where
M: ?Sized,
Self: DivAssign<Self>,
Self: Clone,
[src]
M: ?Sized,
Self: DivAssign<Self>,
Self: Clone,
fn div_assign(&mut self, rhs: &'a Self)
[src]
impl<C, M: ?Sized, I> Index<I> for MonoidalString<C, M> where
Vec<C>: Index<I>,
[src]
Vec<C>: Index<I>,
type Output = <Vec<C> as Index<I>>::Output
The returned type after indexing.
fn index(&self, i: I) -> &Self::Output
[src]
impl<C, M: ?Sized> Hash for MonoidalString<C, M> where
C: Hash,
[src]
C: Hash,
fn hash<__HCM>(&self, __state: &mut __HCM) where
__HCM: Hasher,
[src]
__HCM: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<C, M: ?Sized, T> FromIterator<T> for MonoidalString<C, M> where
Self: Product<T>,
[src]
Self: Product<T>,
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
[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]
impl<'a, C, M: InvMonoidRule<C> + ?Sized> Inv for &'a MonoidalString<C, M> where
MonoidalString<C, M>: Clone,
[src]
MonoidalString<C, M>: Clone,
type Output = MonoidalString<C, M>
The result after applying the operator.
fn inv(self) -> Self::Output
[src]
impl<Z: IntegerSubset, C: Clone, M: MonoidRule<C> + ?Sized> Pow<Z> for MonoidalString<C, M> where
Self: PowMarker<Z> + MulAssociative,
[src]
Self: PowMarker<Z> + MulAssociative,
impl<Z: IntegerSubset, C: Clone, M: InvMonoidRule<C> + ?Sized> Pow<Z> for MonoidalString<C, M> where
Self: PowMarker<Z> + MulAssociative,
[src]
Self: PowMarker<Z> + MulAssociative,
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,
C: Send,
M: Send,
impl<C, M: ?Sized> Sync for MonoidalString<C, M> where
C: Sync,
M: Sync,
C: Sync,
M: Sync,
impl<C, M: ?Sized> Unpin for MonoidalString<C, M> where
C: Unpin,
M: Unpin,
C: Unpin,
M: Unpin,
impl<C, M: ?Sized> UnwindSafe for MonoidalString<C, M> where
C: UnwindSafe,
M: UnwindSafe,
C: UnwindSafe,
M: UnwindSafe,
impl<C, M: ?Sized> RefUnwindSafe for MonoidalString<C, M> where
C: RefUnwindSafe,
M: RefUnwindSafe,
C: RefUnwindSafe,
M: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> From<!> for T
[src]
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<G> PowN for G where
G: MulSemigroup + One,
[src]
G: MulSemigroup + One,
impl<G> PowZ for G where
G: Invertable + MulMonoid,
[src]
G: Invertable + MulMonoid,
fn pow_z<Z>(self, n: Z) -> Self where
Z: IntegerSubset,
[src]
Z: IntegerSubset,