def close_under_modulus(a, b, abs_diff, modulus):
    """ Determines whether the absolute difference between a and b is less than
        abs_diff under modulus. For example, if a = -5, b = 13, and modulus =
        12, their difference is 6 under the modulus, so this function will
        return True when abs_diff >= 6, False otherwise.

        Functionally, this checks whether b falls in the modular range [a-
        abs_diff, a+abs_diff]. Note that if abs_diff >= modulus/2, the function
        will always return True.

        This function will work with numpy arrays, as long as a and b can be
        broadcasted together.
    """
    return (b + abs_diff - a) % modulus <= (2 * abs_diff)