Skip to content

dyce.h package reference

HableOpsMixin

A “mix-in” class providing arithmetic operations for implementers of the HableT protocol. The P class derives from this class.

Info

See HableT for notes on pronunciation.

Source code in dyce/h.py
class HableOpsMixin:
    r"""
    A “mix-in” class providing arithmetic operations for implementers of the
    [``HableT`` protocol][dyce.h.HableT]. The [``P`` class][dyce.p.P] derives from this
    class.

    !!! info

        See [``HableT``][dyce.h.HableT] for notes on pronunciation.
    """
    __slots__: Union[str, Iterable[str]] = ()

    @beartype
    def __add__(self: HableT, other: _OperandT) -> H:
        r"""
        Shorthand for ``#!python operator.__add__(self.h(), other)``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __add__(self.h(), other)

    @beartype
    def __radd__(self: HableT, other: RealLike) -> H:
        r"""
        Shorthand for ``#!python operator.__add__(other, self.h())``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __add__(other, self.h())

    @beartype
    def __sub__(self: HableT, other: _OperandT) -> H:
        r"""
        Shorthand for ``#!python operator.__sub__(self.h(), other)``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __sub__(self.h(), other)

    @beartype
    def __rsub__(self: HableT, other: RealLike) -> H:
        r"""
        Shorthand for ``#!python operator.__sub__(other, self.h())``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __sub__(other, self.h())

    @beartype
    def __mul__(self: HableT, other: _OperandT) -> H:
        r"""
        Shorthand for ``#!python operator.__mul__(self.h(), other)``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __mul__(self.h(), other)

    @beartype
    def __rmul__(self: HableT, other: RealLike) -> H:
        r"""
        Shorthand for ``#!python operator.__mul__(other, self.h())``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __mul__(other, self.h())

    @beartype
    def __truediv__(self: HableT, other: _OperandT) -> H:
        r"""
        Shorthand for ``#!python operator.__truediv__(self.h(), other)``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __truediv__(self.h(), other)

    @beartype
    def __rtruediv__(self: HableT, other: RealLike) -> H:
        r"""
        Shorthand for ``#!python operator.__truediv__(other, self.h())``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __truediv__(other, self.h())

    @beartype
    def __floordiv__(self: HableT, other: _OperandT) -> H:
        r"""
        Shorthand for ``#!python operator.__floordiv__(self.h(), other)``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __floordiv__(self.h(), other)

    @beartype
    def __rfloordiv__(self: HableT, other: RealLike) -> H:
        r"""
        Shorthand for ``#!python operator.__floordiv__(other, self.h())``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __floordiv__(other, self.h())

    @beartype
    def __mod__(self: HableT, other: _OperandT) -> H:
        r"""
        Shorthand for ``#!python operator.__mod__(self.h(), other)``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __mod__(self.h(), other)

    @beartype
    def __rmod__(self: HableT, other: RealLike) -> H:
        r"""
        Shorthand for ``#!python operator.__mod__(other, self.h())``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __mod__(other, self.h())

    @beartype
    def __pow__(self: HableT, other: _OperandT) -> H:
        r"""
        Shorthand for ``#!python operator.__pow__(self.h(), other)``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __pow__(self.h(), other)

    @beartype
    def __rpow__(self: HableT, other: RealLike) -> H:
        r"""
        Shorthand for ``#!python operator.__pow__(other, self.h())``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __pow__(other, self.h())

    @beartype
    def __and__(self: HableT, other: Union[SupportsInt, H, HableT]) -> H:
        r"""
        Shorthand for ``#!python operator.__and__(self.h(), other)``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __and__(self.h(), other)

    @beartype
    def __rand__(self: HableT, other: SupportsInt) -> H:
        r"""
        Shorthand for ``#!python operator.__and__(other, self.h())``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __and__(other, self.h())

    @beartype
    def __xor__(self: HableT, other: Union[SupportsInt, H, HableT]) -> H:
        r"""
        Shorthand for ``#!python operator.__xor__(self.h(), other)``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __xor__(self.h(), other)

    @beartype
    def __rxor__(self: HableT, other: SupportsInt) -> H:
        r"""
        Shorthand for ``#!python operator.__xor__(other, self.h())``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __xor__(other, self.h())

    @beartype
    def __or__(self: HableT, other: Union[SupportsInt, H, HableT]) -> H:
        r"""
        Shorthand for ``#!python operator.__or__(self.h(), other)``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __or__(self.h(), other)

    @beartype
    def __ror__(self: HableT, other: SupportsInt) -> H:
        r"""
        Shorthand for ``#!python operator.__or__(other, self.h())``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __or__(other, self.h())

    @beartype
    def __neg__(self: HableT) -> H:
        r"""
        Shorthand for ``#!python operator.__neg__(self.h())``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __neg__(self.h())

    @beartype
    def __pos__(self: HableT) -> H:
        r"""
        Shorthand for ``#!python operator.__pos__(self.h())``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __pos__(self.h())

    @beartype
    def __abs__(self: HableT) -> H:
        r"""
        Shorthand for ``#!python operator.__abs__(self.h())``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __abs__(self.h())

    @beartype
    def __invert__(self: HableT) -> H:
        r"""
        Shorthand for ``#!python operator.__invert__(self.h())``. See the
        [``h`` method][dyce.h.HableT.h].
        """
        return __invert__(self.h())

    @beartype
    def lt(self: HableT, other: _OperandT) -> H:
        r"""
        Shorthand for ``#!python self.h().lt(other)``. See the
        [``h`` method][dyce.h.HableT.h] and [``H.lt``][dyce.h.H.lt].
        """
        return self.h().lt(other)

    @beartype
    def le(self: HableT, other: _OperandT) -> H:
        r"""
        Shorthand for ``#!python self.h().le(other)``. See the
        [``h`` method][dyce.h.HableT.h] and [``H.le``][dyce.h.H.le].
        """
        return self.h().le(other)

    @beartype
    def eq(self: HableT, other: _OperandT) -> H:
        r"""
        Shorthand for ``#!python self.h().eq(other)``. See the
        [``h`` method][dyce.h.HableT.h] and [``H.eq``][dyce.h.H.eq].
        """
        return self.h().eq(other)

    @beartype
    def ne(self: HableT, other: _OperandT) -> H:
        r"""
        Shorthand for ``#!python self.h().ne(other)``. See the
        [``h`` method][dyce.h.HableT.h] and [``H.ne``][dyce.h.H.ne].
        """
        return self.h().ne(other)

    @beartype
    def gt(self: HableT, other: _OperandT) -> H:
        r"""
        Shorthand for ``#!python self.h().gt(other)``. See the
        [``h`` method][dyce.h.HableT.h] and [``H.gt``][dyce.h.H.gt].
        """
        return self.h().gt(other)

    @beartype
    def ge(self: HableT, other: _OperandT) -> H:
        r"""
        Shorthand for ``#!python self.h().ge(other)``. See the
        [``h`` method][dyce.h.HableT.h] and [``H.ge``][dyce.h.H.ge].
        """
        return self.h().ge(other)

    @beartype
    def is_even(self: HableT) -> H:
        r"""
        Shorthand for ``#!python self.h().is_even()``. See the
        [``h`` method][dyce.h.HableT.h] and [``H.is_even``][dyce.h.H.is_even].
        """
        return self.h().is_even()

    @beartype
    def is_odd(self: HableT) -> H:
        r"""
        Shorthand for ``#!python self.h().is_odd()``. See the
        [``h`` method][dyce.h.HableT.h] and [``H.is_odd``][dyce.h.H.is_odd].
        """
        return self.h().is_odd()

    @beartype
    def explode(
        self: HableT,
        max_depth: SupportsInt = 1,
        precision_limit: Fraction = Fraction(0),
    ) -> H:
        r"""
        Shorthand for ``#!python self.h().explode(max_depth, precision_limit)``. See the
        [``h`` method][dyce.h.HableT.h] and [``H.explode``][dyce.h.H.explode].
        """
        return self.h().explode(max_depth, precision_limit)

    @beartype
    def substitute(
        self: HableT,
        expand: _ExpandT,
        coalesce: _CoalesceT = coalesce_replace,
        max_depth: SupportsInt = 1,
        precision_limit: Fraction = Fraction(0),
    ) -> H:
        r"""
        Shorthand for ``#!python self.h().substitute(expand, coalesce, max_depth,
        precision_limit)``. See the [``h`` method][dyce.h.HableT.h] and
        [``H.substitute``][dyce.h.H.substitute].
        """
        return self.h().substitute(expand, coalesce, max_depth, precision_limit)

    @beartype
    def within(self: HableT, lo: RealLike, hi: RealLike, other: _OperandT = 0) -> H:
        r"""
        Shorthand for ``#!python self.h().within(lo, hi, other)``. See the
        [``h`` method][dyce.h.HableT.h] and [``H.within``][dyce.h.H.within].
        """
        return self.h().within(lo, hi, other)

__slots__: Union[str, Iterable[str]] special

__abs__(self: HableT) -> H special

Shorthand for operator.__abs__(self.h()). See the h method.

Source code in dyce/h.py
@beartype
def __abs__(self: HableT) -> H:
    r"""
    Shorthand for ``#!python operator.__abs__(self.h())``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __abs__(self.h())

__add__(self: HableT, other: _OperandT) -> H special

Shorthand for operator.__add__(self.h(), other). See the h method.

Source code in dyce/h.py
@beartype
def __add__(self: HableT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python operator.__add__(self.h(), other)``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __add__(self.h(), other)

__and__(self: HableT, other: Union[SupportsInt, H, HableT]) -> H special

Shorthand for operator.__and__(self.h(), other). See the h method.

Source code in dyce/h.py
@beartype
def __and__(self: HableT, other: Union[SupportsInt, H, HableT]) -> H:
    r"""
    Shorthand for ``#!python operator.__and__(self.h(), other)``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __and__(self.h(), other)

__floordiv__(self: HableT, other: _OperandT) -> H special

Shorthand for operator.__floordiv__(self.h(), other). See the h method.

Source code in dyce/h.py
@beartype
def __floordiv__(self: HableT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python operator.__floordiv__(self.h(), other)``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __floordiv__(self.h(), other)

__invert__(self: HableT) -> H special

Shorthand for operator.__invert__(self.h()). See the h method.

Source code in dyce/h.py
@beartype
def __invert__(self: HableT) -> H:
    r"""
    Shorthand for ``#!python operator.__invert__(self.h())``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __invert__(self.h())

__mod__(self: HableT, other: _OperandT) -> H special

Shorthand for operator.__mod__(self.h(), other). See the h method.

Source code in dyce/h.py
@beartype
def __mod__(self: HableT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python operator.__mod__(self.h(), other)``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __mod__(self.h(), other)

__mul__(self: HableT, other: _OperandT) -> H special

Shorthand for operator.__mul__(self.h(), other). See the h method.

Source code in dyce/h.py
@beartype
def __mul__(self: HableT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python operator.__mul__(self.h(), other)``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __mul__(self.h(), other)

__neg__(self: HableT) -> H special

Shorthand for operator.__neg__(self.h()). See the h method.

Source code in dyce/h.py
@beartype
def __neg__(self: HableT) -> H:
    r"""
    Shorthand for ``#!python operator.__neg__(self.h())``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __neg__(self.h())

__or__(self: HableT, other: Union[SupportsInt, H, HableT]) -> H special

Shorthand for operator.__or__(self.h(), other). See the h method.

Source code in dyce/h.py
@beartype
def __or__(self: HableT, other: Union[SupportsInt, H, HableT]) -> H:
    r"""
    Shorthand for ``#!python operator.__or__(self.h(), other)``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __or__(self.h(), other)

__pos__(self: HableT) -> H special

Shorthand for operator.__pos__(self.h()). See the h method.

Source code in dyce/h.py
@beartype
def __pos__(self: HableT) -> H:
    r"""
    Shorthand for ``#!python operator.__pos__(self.h())``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __pos__(self.h())

__pow__(self: HableT, other: _OperandT) -> H special

Shorthand for operator.__pow__(self.h(), other). See the h method.

Source code in dyce/h.py
@beartype
def __pow__(self: HableT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python operator.__pow__(self.h(), other)``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __pow__(self.h(), other)

__radd__(self: HableT, other: RealLike) -> H special

Shorthand for operator.__add__(other, self.h()). See the h method.

Source code in dyce/h.py
@beartype
def __radd__(self: HableT, other: RealLike) -> H:
    r"""
    Shorthand for ``#!python operator.__add__(other, self.h())``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __add__(other, self.h())

__rand__(self: HableT, other: SupportsInt) -> H special

Shorthand for operator.__and__(other, self.h()). See the h method.

Source code in dyce/h.py
@beartype
def __rand__(self: HableT, other: SupportsInt) -> H:
    r"""
    Shorthand for ``#!python operator.__and__(other, self.h())``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __and__(other, self.h())

__rfloordiv__(self: HableT, other: RealLike) -> H special

Shorthand for operator.__floordiv__(other, self.h()). See the h method.

Source code in dyce/h.py
@beartype
def __rfloordiv__(self: HableT, other: RealLike) -> H:
    r"""
    Shorthand for ``#!python operator.__floordiv__(other, self.h())``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __floordiv__(other, self.h())

__rmod__(self: HableT, other: RealLike) -> H special

Shorthand for operator.__mod__(other, self.h()). See the h method.

Source code in dyce/h.py
@beartype
def __rmod__(self: HableT, other: RealLike) -> H:
    r"""
    Shorthand for ``#!python operator.__mod__(other, self.h())``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __mod__(other, self.h())

__rmul__(self: HableT, other: RealLike) -> H special

Shorthand for operator.__mul__(other, self.h()). See the h method.

Source code in dyce/h.py
@beartype
def __rmul__(self: HableT, other: RealLike) -> H:
    r"""
    Shorthand for ``#!python operator.__mul__(other, self.h())``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __mul__(other, self.h())

__ror__(self: HableT, other: SupportsInt) -> H special

Shorthand for operator.__or__(other, self.h()). See the h method.

Source code in dyce/h.py
@beartype
def __ror__(self: HableT, other: SupportsInt) -> H:
    r"""
    Shorthand for ``#!python operator.__or__(other, self.h())``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __or__(other, self.h())

__rpow__(self: HableT, other: RealLike) -> H special

Shorthand for operator.__pow__(other, self.h()). See the h method.

Source code in dyce/h.py
@beartype
def __rpow__(self: HableT, other: RealLike) -> H:
    r"""
    Shorthand for ``#!python operator.__pow__(other, self.h())``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __pow__(other, self.h())

__rsub__(self: HableT, other: RealLike) -> H special

Shorthand for operator.__sub__(other, self.h()). See the h method.

Source code in dyce/h.py
@beartype
def __rsub__(self: HableT, other: RealLike) -> H:
    r"""
    Shorthand for ``#!python operator.__sub__(other, self.h())``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __sub__(other, self.h())

__rtruediv__(self: HableT, other: RealLike) -> H special

Shorthand for operator.__truediv__(other, self.h()). See the h method.

Source code in dyce/h.py
@beartype
def __rtruediv__(self: HableT, other: RealLike) -> H:
    r"""
    Shorthand for ``#!python operator.__truediv__(other, self.h())``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __truediv__(other, self.h())

__rxor__(self: HableT, other: SupportsInt) -> H special

Shorthand for operator.__xor__(other, self.h()). See the h method.

Source code in dyce/h.py
@beartype
def __rxor__(self: HableT, other: SupportsInt) -> H:
    r"""
    Shorthand for ``#!python operator.__xor__(other, self.h())``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __xor__(other, self.h())

__sub__(self: HableT, other: _OperandT) -> H special

Shorthand for operator.__sub__(self.h(), other). See the h method.

Source code in dyce/h.py
@beartype
def __sub__(self: HableT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python operator.__sub__(self.h(), other)``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __sub__(self.h(), other)

__truediv__(self: HableT, other: _OperandT) -> H special

Shorthand for operator.__truediv__(self.h(), other). See the h method.

Source code in dyce/h.py
@beartype
def __truediv__(self: HableT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python operator.__truediv__(self.h(), other)``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __truediv__(self.h(), other)

__xor__(self: HableT, other: Union[SupportsInt, H, HableT]) -> H special

Shorthand for operator.__xor__(self.h(), other). See the h method.

Source code in dyce/h.py
@beartype
def __xor__(self: HableT, other: Union[SupportsInt, H, HableT]) -> H:
    r"""
    Shorthand for ``#!python operator.__xor__(self.h(), other)``. See the
    [``h`` method][dyce.h.HableT.h].
    """
    return __xor__(self.h(), other)

eq(self: HableT, other: _OperandT) -> H

Shorthand for self.h().eq(other). See the h method and H.eq.

Source code in dyce/h.py
@beartype
def eq(self: HableT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python self.h().eq(other)``. See the
    [``h`` method][dyce.h.HableT.h] and [``H.eq``][dyce.h.H.eq].
    """
    return self.h().eq(other)

explode(self: HableT, max_depth: SupportsInt = 1, precision_limit: Fraction = Fraction(0, 1)) -> H

Shorthand for self.h().explode(max_depth, precision_limit). See the h method and H.explode.

Source code in dyce/h.py
@beartype
def explode(
    self: HableT,
    max_depth: SupportsInt = 1,
    precision_limit: Fraction = Fraction(0),
) -> H:
    r"""
    Shorthand for ``#!python self.h().explode(max_depth, precision_limit)``. See the
    [``h`` method][dyce.h.HableT.h] and [``H.explode``][dyce.h.H.explode].
    """
    return self.h().explode(max_depth, precision_limit)

ge(self: HableT, other: _OperandT) -> H

Shorthand for self.h().ge(other). See the h method and H.ge.

Source code in dyce/h.py
@beartype
def ge(self: HableT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python self.h().ge(other)``. See the
    [``h`` method][dyce.h.HableT.h] and [``H.ge``][dyce.h.H.ge].
    """
    return self.h().ge(other)

gt(self: HableT, other: _OperandT) -> H

Shorthand for self.h().gt(other). See the h method and H.gt.

Source code in dyce/h.py
@beartype
def gt(self: HableT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python self.h().gt(other)``. See the
    [``h`` method][dyce.h.HableT.h] and [``H.gt``][dyce.h.H.gt].
    """
    return self.h().gt(other)

is_even(self: HableT) -> H

Shorthand for self.h().is_even(). See the h method and H.is_even.

Source code in dyce/h.py
@beartype
def is_even(self: HableT) -> H:
    r"""
    Shorthand for ``#!python self.h().is_even()``. See the
    [``h`` method][dyce.h.HableT.h] and [``H.is_even``][dyce.h.H.is_even].
    """
    return self.h().is_even()

is_odd(self: HableT) -> H

Shorthand for self.h().is_odd(). See the h method and H.is_odd.

Source code in dyce/h.py
@beartype
def is_odd(self: HableT) -> H:
    r"""
    Shorthand for ``#!python self.h().is_odd()``. See the
    [``h`` method][dyce.h.HableT.h] and [``H.is_odd``][dyce.h.H.is_odd].
    """
    return self.h().is_odd()

le(self: HableT, other: _OperandT) -> H

Shorthand for self.h().le(other). See the h method and H.le.

Source code in dyce/h.py
@beartype
def le(self: HableT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python self.h().le(other)``. See the
    [``h`` method][dyce.h.HableT.h] and [``H.le``][dyce.h.H.le].
    """
    return self.h().le(other)

lt(self: HableT, other: _OperandT) -> H

Shorthand for self.h().lt(other). See the h method and H.lt.

Source code in dyce/h.py
@beartype
def lt(self: HableT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python self.h().lt(other)``. See the
    [``h`` method][dyce.h.HableT.h] and [``H.lt``][dyce.h.H.lt].
    """
    return self.h().lt(other)

ne(self: HableT, other: _OperandT) -> H

Shorthand for self.h().ne(other). See the h method and H.ne.

Source code in dyce/h.py
@beartype
def ne(self: HableT, other: _OperandT) -> H:
    r"""
    Shorthand for ``#!python self.h().ne(other)``. See the
    [``h`` method][dyce.h.HableT.h] and [``H.ne``][dyce.h.H.ne].
    """
    return self.h().ne(other)

substitute(self: HableT, expand: _ExpandT, coalesce: _CoalesceT = <function coalesce_replace at 0x102ed6040>, max_depth: SupportsInt = 1, precision_limit: Fraction = Fraction(0, 1)) -> H

Shorthand for self.h().substitute(expand, coalesce, max_depth,precision_limit). See the h method and H.substitute.

Source code in dyce/h.py
@beartype
def substitute(
    self: HableT,
    expand: _ExpandT,
    coalesce: _CoalesceT = coalesce_replace,
    max_depth: SupportsInt = 1,
    precision_limit: Fraction = Fraction(0),
) -> H:
    r"""
    Shorthand for ``#!python self.h().substitute(expand, coalesce, max_depth,
    precision_limit)``. See the [``h`` method][dyce.h.HableT.h] and
    [``H.substitute``][dyce.h.H.substitute].
    """
    return self.h().substitute(expand, coalesce, max_depth, precision_limit)

within(self: HableT, lo: RealLike, hi: RealLike, other: _OperandT = 0) -> H

Shorthand for self.h().within(lo, hi, other). See the h method and H.within.

Source code in dyce/h.py
@beartype
def within(self: HableT, lo: RealLike, hi: RealLike, other: _OperandT = 0) -> H:
    r"""
    Shorthand for ``#!python self.h().within(lo, hi, other)``. See the
    [``h`` method][dyce.h.HableT.h] and [``H.within``][dyce.h.H.within].
    """
    return self.h().within(lo, hi, other)

HableT (Protocol)

A protocol whose implementer can be expressed as (or reduced to) an H object by calling its h method. Currently, only the P class implements this protocol, but this affords an integration point for dyce users.

Info

The intended pronunciation of Hable is AYCH-uh-bul1 (i.e., H-able). Yes, that is a clumsy attempt at verbing. (You could totally H that, dude!) However, if you prefer something else (e.g. HAY-bul or AYCH-AY-bul), no one is going to judge you. (Well, they might, but they shouldn’t.) We all know what you mean.


  1. World Book Online (WBO) style pronunciation respelling

Source code in dyce/h.py
@runtime_checkable
class HableT(
    Protocol,
    metaclass=CachingProtocolMeta,
):
    r"""
    A protocol whose implementer can be expressed as (or reduced to) an
    [``H`` object][dyce.h.H] by calling its [``h`` method][dyce.h.HableT.h]. Currently,
    only the [``P`` class][dyce.p.P] implements this protocol, but this affords an
    integration point for ``#!python dyce`` users.

    !!! info

        The intended pronunciation of ``Hable`` is *AYCH-uh-bul*[^1] (i.e.,
        [``H``][dyce.h.H]-able). Yes, that is a clumsy attempt at
        [verbing](https://www.gocomics.com/calvinandhobbes/1993/01/25). (You could
        *totally* [``H``][dyce.h.H] that, dude!) However, if you prefer something else
        (e.g. *HAY-bul* or *AYCH-AY-bul*), no one is going to judge you. (Well, they
        *might*, but they *shouldn’t*.) We all know what you mean.

    [^1]:

        World Book Online (WBO) style [pronunciation
        respelling](https://en.wikipedia.org/wiki/Pronunciation_respelling_for_English#Traditional_respelling_systems).
    """
    __slots__: Union[str, Iterable[str]] = ()

    def h(self) -> H:
        r"""
        Express its implementer as an [``H`` object][dyce.h.H].
        """
        ...

__slots__: Union[str, Iterable[str]] special

__init__(self, *args, **kwargs) special

Source code in dyce/h.py
def _no_init(self, *args, **kwargs):
    raise TypeError('Protocols cannot be instantiated')

__subclasshook__(other) special

Source code in dyce/h.py
def _proto_hook(other):
    if not cls.__dict__.get('_is_protocol', False):
        return NotImplemented

    # First, perform various sanity checks.
    if not getattr(cls, '_is_runtime_protocol', False):
        if _allow_reckless_class_cheks():
            return NotImplemented
        raise TypeError("Instance and class checks can only be used with"
                        " @runtime_checkable protocols")
    if not _is_callable_members_only(cls):
        if _allow_reckless_class_cheks():
            return NotImplemented
        raise TypeError("Protocols with non-method members"
                        " don't support issubclass()")
    if not isinstance(other, type):
        # Same error message as for issubclass(1, int).
        raise TypeError('issubclass() arg 1 must be a class')

    # Second, perform the actual structural compatibility check.
    for attr in _get_protocol_attrs(cls):
        for base in other.__mro__:
            # Check if the members appears in the class dictionary...
            if attr in base.__dict__:
                if base.__dict__[attr] is None:
                    return NotImplemented
                break

            # ...or in annotations, if it is a sub-protocol.
            annotations = getattr(base, '__annotations__', {})
            if (isinstance(annotations, collections.abc.Mapping) and
                    attr in annotations and
                    issubclass(other, Generic) and other._is_protocol):
                break
        else:
            return NotImplemented
    return True

h(self) -> H

Express its implementer as an H object.

Source code in dyce/h.py
def h(self) -> H:
    r"""
    Express its implementer as an [``H`` object][dyce.h.H].
    """
    ...

aggregate_with_counts(source_counts: Iterable[Tuple[Union[H, RealLike], int]], h_type: Type[H] = <class 'dyce.h.H'>) -> H

Aggregates source_counts into an H object. Each source_count is a two-tuple of either an outcome-count pair or a histogram-count pair. This function is used in the implementation of the H.substitute and P.foreach methods. Unlike those, the histogram returned from this function is not reduced to its lowest terms.

In nearly all cases, when a source contains a histogram, it takes on the corresponding count’s “scale”. In other words, the sum of the counts of the histogram retains the same proportion as the count in relation to other outcomes. This becomes clearer when there is no overlap between the histogram and the other outcomes.

1
2
3
4
>>> from dyce.h import aggregate_with_counts
>>> source_counts = ((H(3), 3), (H(-3), 2))
>>> h = aggregate_with_counts(source_counts).lowest_terms() ; h
H({-3: 2, -2: 2, -1: 2, 1: 3, 2: 3, 3: 3})

An important exception

If a source is the empty histogram (H({})), it and its count is omitted from the result without scaling.

1
2
3
>>> source_counts = ((H(2), 1), (H({}), 20))
>>> aggregate_with_counts(source_counts)
H({1: 1, 2: 1})
Source code in dyce/h.py
@beartype
def aggregate_with_counts(
    source_counts: Iterable[Tuple[Union[H, RealLike], int]],
    h_type: Type[H] = H,
) -> H:
    r"""
    Aggregates *source_counts* into an [``H`` object][dyce.h.H]. Each source_count is a
    two-tuple of either an outcome-count pair or a histogram-count pair. This function
    is used in the implementation of the [``H.substitute``][dyce.h.H.substitute] and
    [``P.foreach``][dyce.p.P.foreach] methods. Unlike those, the histogram returned from
    this function is *not* reduced to its lowest terms.

    In nearly all cases, when a source contains a histogram, it takes on the
    corresponding count’s “scale”. In other words, the sum of the counts of the
    histogram retains the same proportion as the count in relation to other outcomes.
    This becomes clearer when there is no overlap between the histogram and the other
    outcomes.

    ``` python
    >>> from dyce.h import aggregate_with_counts
    >>> source_counts = ((H(3), 3), (H(-3), 2))
    >>> h = aggregate_with_counts(source_counts).lowest_terms() ; h
    H({-3: 2, -2: 2, -1: 2, 1: 3, 2: 3, 3: 3})

    ```

    !!! note "An important exception"

        If a source is the empty histogram (``H({})``), it and its count is omitted from
        the result without scaling.

        ``` python
        >>> source_counts = ((H(2), 1), (H({}), 20))
        >>> aggregate_with_counts(source_counts)
        H({1: 1, 2: 1})

        ```
    """
    aggregate_scalar = 1
    outcome_counts: List[Tuple[RealLike, int]] = []

    for outcome_or_h, count in source_counts:
        if isinstance(outcome_or_h, H):
            if outcome_or_h:
                h_scalar = outcome_or_h.total

                for i, (prior_outcome, prior_count) in enumerate(outcome_counts):
                    outcome_counts[i] = (prior_outcome, prior_count * h_scalar)

                for new_outcome, new_count in outcome_or_h.items():
                    outcome_counts.append(
                        (new_outcome, count * aggregate_scalar * new_count)
                    )

                aggregate_scalar *= h_scalar
        else:
            outcome_counts.append((outcome_or_h, count * aggregate_scalar))

    return h_type(outcome_counts)

coalesce_replace(h: H, outcome: RealLike) -> H

Default behavior for H.substitute. Returns h unmodified (outcome is ignored).

Source code in dyce/h.py
def coalesce_replace(h: H, outcome: RealLike) -> H:
    r"""
    Default behavior for [``H.substitute``][dyce.h.H.substitute]. Returns *h* unmodified
    (*outcome* is ignored).
    """
    return h

resolve_dependent_probability(dependent_term: Callable[..., Union[H, RealLike]], **independent_sources: _SourceT) -> H

Deprecated

This function has been moved to the H.foreach class method. This alias will be removed in a future release.

Shorthand for H.foreach(dependent_term, **independent_sources).

Source code in dyce/h.py
@deprecated
def resolve_dependent_probability(
    dependent_term: Callable[..., Union[H, RealLike]],
    **independent_sources: _SourceT,
) -> H:
    r"""
    !!! warning "Deprecated"

        This function has been moved to the [``H.foreach``][dyce.h.H.foreach] class
        method. This alias will be removed in a future release.

    Shorthand for ``#!python H.foreach(dependent_term, **independent_sources)``.
    """
    return H.foreach(dependent_term, **independent_sources)

sum_h(hs: Iterable[H])

Shorthand for H({}) if h_sum == 0 else sum(hs).

This is to ensure that summing zero or more histograms always returns a histograms.

Source code in dyce/h.py
@beartype
def sum_h(hs: Iterable[H]):
    """
    Shorthand for ``#!python H({}) if h_sum == 0 else sum(hs)``.

    This is to ensure that summing zero or more histograms always returns a histograms.
    """
    h_sum = sum(hs)

    return H({}) if h_sum == 0 else h_sum