(x)
Evaluates the cos of an interval
Evaluates the cos of an interval
Evaluates the cos of an interval
def cos(x):
    """Evaluates the cos of an interval"""
    np = import_module('numpy')
    if isinstance(x, (int, float)):
        return interval(np.sin(x))
    elif isinstance(x, interval):
        if not (np.isfinite(x.start) and np.isfinite(x.end)):
            return interval(-1, 1, is_valid=x.is_valid)
        na, __ = divmod(x.start, np.pi / 2.0)
        nb, __ = divmod(x.end, np.pi / 2.0)
        start = min(np.cos(x.start), np.cos(x.end))
        end = max(np.cos(x.start), np.cos(x.end))
        if nb - na > 4:
            #differ more than 2*pi
            return interval(-1, 1, is_valid=x.is_valid)
        elif na == nb:
            #in the same quadarant
            return interval(start, end, is_valid=x.is_valid)
        else:
            if (na) // 4 != (nb) // 4:
                #cos has max
                end = 1
            if (na - 2) // 4 != (nb - 2) // 4:
                #cos has min
                start = -1
            return interval(start, end, is_valid=x.is_valid)
    else:
        raise NotImplementedError
def cos ( x ) : np = import_module ( 'numpy' ) if isinstance ( x , ( int , float ) ) : return interval ( np . sin ( x ) ) elif isinstance ( x , interval ) : if not ( np . isfinite ( x . start ) and np . isfinite ( x . end ) ) : return interval ( - 1 , 1 , is_valid = x . is_valid ) na , __ = divmod ( x . start , np . pi / 2.0 ) nb , __ = divmod ( x . end , np . pi / 2.0 ) start = min ( np . cos ( x . start ) , np . cos ( x . end ) ) end = max ( np . cos ( x . start ) , np . cos ( x . end ) ) if nb - na > 4 : #differ more than 2*pi return interval ( - 1 , 1 , is_valid = x . is_valid ) elif na == nb : #in the same quadarant return interval ( start , end , is_valid = x . is_valid ) else : if ( na ) // 4 != ( nb ) // 4 : #cos has max end = 1 if ( na - 2 ) // 4 != ( nb - 2 ) // 4 : #cos has min start = - 1 return interval ( start , end , is_valid = x . is_valid ) else : raise NotImplementedError