Skip to main content

Inverse

Trait Inverse 

Source
pub trait Inverse<T>: Reduction<T> {
    // Required methods
    fn inverse(acc: Self::Total, x: T) -> (Self::Total, bool);
    fn undo(a: Self::Total, b: Self::Total) -> (Self::Total, bool);
    fn alternating(x: &[T]) -> (Self::Total, bool);

    // Provided method
    fn fits(_: Self::Total) -> bool { ... }
}
Expand description

A reduction whose step can be undone, as Alternated folds by it: Sum subtracts, and ScaledProduct and Product divide. An integer difference fits only within i64, a complex quotient only inside the normal range, and a float quotient only where no item, or product of the running mantissa and an item, leaves the normal floats. An alternated fold can then fail where the right fold taken item by item, or its exact result, would fit.

Required Methods§

Source

fn inverse(acc: Self::Total, x: T) -> (Self::Total, bool)

acc with the item x taken away, and whether it fits.

Source

fn undo(a: Self::Total, b: Self::Total) -> (Self::Total, bool)

The fold a with the fold b of the next run taken away, and whether it fits.

Source

fn alternating(x: &[T]) -> (Self::Total, bool)

The right fold of the slice x by the inverse, and whether it fits: for sums through a sum at each parity (alternated), and for products through the pairs’ quotients (pairwise).

Provided Methods§

Source

fn fits(_: Self::Total) -> bool

Whether a running total fits, as every one does apart from a float quotient outside the normal range.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Inverse<i16> for Sum

Source§

impl Inverse<i32> for Sum

Source§

impl Inverse<i64> for Sum

Source§

impl Inverse<u8> for Sum

Source§

impl<F: Native> Inverse<Complex<F>> for Product

Product’s inverse on complex numbers, which divides as crate::divide does.

Source§

impl<F: Native> Inverse<Complex<F>> for Sum

Source§

impl<F: Native> Inverse<F> for ScaledProduct

Source§

impl<F: Native> Inverse<F> for Sum