pub struct Product<T>(pub T);Expand description
Wrapper type for the multiplication monoid.
Product<T> forms a monoid under multiplication (*), useful for
computing products, scaling factors, or combining probabilities.
§Examples
use algebra_core::{Monoid, Semigroup, Product};
let a = Product(5);
let b = Product(3);
let c = a.combine(&b);
assert_eq!(c, Product(15));
assert_eq!(Product::<i32>::empty(), Product(1));§Combining Probabilities
use algebra_core::{Semigroup, Product};
let prob1 = Product(0.5);
let prob2 = Product(0.5);
let joint_prob = prob1.combine(&prob2);
assert_eq!(joint_prob.0, 0.25);Tuple Fields§
§0: TTrait Implementations§
Source§impl<T: Ord> Ord for Product<T>
impl<T: Ord> Ord for Product<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialOrd> PartialOrd for Product<T>
impl<T: PartialOrd> PartialOrd for Product<T>
impl<T: Mul<Output = T> + Clone + One> CommutativeMonoid for Product<T>
impl<T: Copy> Copy for Product<T>
impl<T: Eq> Eq for Product<T>
impl<T> StructuralPartialEq for Product<T>
Auto Trait Implementations§
impl<T> Freeze for Product<T>where
T: Freeze,
impl<T> RefUnwindSafe for Product<T>where
T: RefUnwindSafe,
impl<T> Send for Product<T>where
T: Send,
impl<T> Sync for Product<T>where
T: Sync,
impl<T> Unpin for Product<T>where
T: Unpin,
impl<T> UnwindSafe for Product<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more