Returns a maximum on the trace distance between this effect's input
    and output.  This method makes use of the effect's `_trace_distance_bound_`
    method to determine the maximum bound on the trace difference between
    before and after the effect.

    Args:
        val: The effect of which the bound should be calculated

    Returns:
        If `val` has a _trace_distance_bound_ method and its result is not
        NotImplemented, that result is returned. Otherwise, 1 is returned.
        Result is capped at a maximum of 1, even if the underlying function
        produces a result greater than 1.

def trace_distance_bound(val: Any) -> float:
    """Returns a maximum on the trace distance between this effect's input
    and output.  This method makes use of the effect's `_trace_distance_bound_`
    method to determine the maximum bound on the trace difference between
    before and after the effect.

    Args:
        val: The effect of which the bound should be calculated

    Returns:
        If `val` has a _trace_distance_bound_ method and its result is not
        NotImplemented, that result is returned. Otherwise, 1 is returned.
        Result is capped at a maximum of 1, even if the underlying function
        produces a result greater than 1.

    """
    getter = getattr(val, '_trace_distance_bound_', None)
    result = NotImplemented if getter is None else getter()

    if result is not NotImplemented and result < 1.0:
        return result
    return 1.0