#NEWLINE# @ staticmethod #NEWLINE# def reduce( args ) : #NEWLINE# #INDENT# "\n        Return a simplified intersection by applying rules.\n\n        We first start with global rules like\n        'if any empty sets, return empty set' and 'distribute unions'.\n\n        Then we iterate through all pairs and ask the constituent sets if they\n        can simplify themselves with any other constituent\n        " #NEWLINE# from sympy.simplify.simplify import clear_coefficients #NEWLINE# if any ( ( s . is_EmptySet for s in args ) ) : #NEWLINE# #INDENT# return S . EmptySet #NEWLINE# #UNINDENT# rv = Intersection . _handle_finite_sets ( args ) #NEWLINE# if ( rv is not None ) : #NEWLINE# #INDENT# if ( isinstance ( rv , Intersection ) and ( len ( rv . args ) == 2 ) ) : #NEWLINE# #INDENT# ( ivl , s ) = rv . args #NEWLINE# if ( isinstance ( s , FiniteSet ) and ( len ( s ) == 1 ) and isinstance ( ivl , Interval ) ) : #NEWLINE# #INDENT# e = list ( s ) [ 0 ] #NEWLINE# if e . free_symbols : #NEWLINE# #INDENT# rhs = Dummy ( ) #NEWLINE# ( e , r ) = clear_coefficients ( e , rhs ) #NEWLINE# if ( r != rhs ) : #NEWLINE# #INDENT# iargs = list ( ivl . args ) #NEWLINE# iargs [ 0 ] = r . subs ( rhs , ivl . start ) #NEWLINE# iargs [ 1 ] = r . subs ( rhs , ivl . end ) #NEWLINE# if ( iargs [ 0 ] > iargs [ 1 ] ) : #NEWLINE# #INDENT# iargs = ( iargs [ : 2 ] [ : : ( - 1 ) ] + iargs [ ( - 2 ) : ] [ : : ( - 1 ) ] ) #NEWLINE# #UNINDENT# rv = Intersection ( FiniteSet ( e ) , Interval ( * iargs ) , evaluate = False ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return rv #NEWLINE# #UNINDENT# for s in args : #NEWLINE# #INDENT# if s . is_Union : #NEWLINE# #INDENT# other_sets = ( set ( args ) - set ( ( s , ) ) ) #NEWLINE# if ( len ( other_sets ) > 0 ) : #NEWLINE# #INDENT# other = Intersection ( other_sets ) #NEWLINE# return Union ( ( Intersection ( arg , other ) for arg in s . args ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return Union ( ( arg for arg in s . args ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for s in args : #NEWLINE# #INDENT# if s . is_Complement : #NEWLINE# #INDENT# args . remove ( s ) #NEWLINE# other_sets = ( args + [ s . args [ 0 ] ] ) #NEWLINE# return Complement ( Intersection ( * other_sets ) , s . args [ 1 ] ) #NEWLINE# #UNINDENT# #UNINDENT# args = set ( args ) #NEWLINE# new_args = True #NEWLINE# while new_args : #NEWLINE# #INDENT# for s in args : #NEWLINE# #INDENT# new_args = False #NEWLINE# for t in ( args - set ( ( s , ) ) ) : #NEWLINE# #INDENT# new_set = s . _intersect ( t ) #NEWLINE# if ( new_set is not None ) : #NEWLINE# #INDENT# new_args = ( args - set ( ( s , t ) ) ) . union ( set ( ( new_set , ) ) ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# if new_args : #NEWLINE# #INDENT# args = new_args #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( len ( args ) == 1 ) : #NEWLINE# #INDENT# return args . pop ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return Intersection ( args , evaluate = False )