#NEWLINE# def _solveset( f , symbol , domain , _check = False ) : #NEWLINE# #INDENT# "Helper for solveset to return a result from an expression\n    that has already been sympify'ed and is known to contain the\n    given symbol." #NEWLINE# from sympy.simplify.simplify import signsimp #NEWLINE# orig_f = f #NEWLINE# f = together ( f ) #NEWLINE# if f . is_Mul : #NEWLINE# #INDENT# ( _ , f ) = f . as_independent ( symbol , as_Add = False ) #NEWLINE# #UNINDENT# if f . is_Add : #NEWLINE# #INDENT# ( a , h ) = f . as_independent ( symbol ) #NEWLINE# ( m , h ) = h . as_independent ( symbol , as_Add = False ) #NEWLINE# f = ( ( a / m ) + h ) #NEWLINE# #UNINDENT# f = piecewise_fold ( f ) #NEWLINE# solver = ( lambda f , x , domain = domain : _solveset ( f , x , domain ) ) #NEWLINE# if domain . is_subset ( S . Reals ) : #NEWLINE# #INDENT# inverter_func = invert_real #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# inverter_func = invert_complex #NEWLINE# #UNINDENT# inverter = ( lambda f , rhs , symbol : inverter_func ( f , rhs , symbol , domain ) ) #NEWLINE# result = EmptySet ( ) #NEWLINE# if f . expand ( ) . is_zero : #NEWLINE# #INDENT# return domain #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not f . has ( symbol ) ) : #NEWLINE# #INDENT# return EmptySet ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( f . is_Mul and all ( ( _is_finite_with_finite_vars ( m , domain ) for m in f . args ) ) ) : #NEWLINE# #INDENT# result = Union ( * [ solver ( m , symbol ) for m in f . args ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( _is_function_class_equation ( TrigonometricFunction , f , symbol ) or _is_function_class_equation ( HyperbolicFunction , f , symbol ) ) : #NEWLINE# #INDENT# result = _solve_trig ( f , symbol , domain ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if f . is_Piecewise : #NEWLINE# #INDENT# dom = domain #NEWLINE# result = EmptySet ( ) #NEWLINE# expr_set_pairs = f . as_expr_set_pairs ( ) #NEWLINE# for ( expr , in_set ) in expr_set_pairs : #NEWLINE# #INDENT# if in_set . is_Relational : #NEWLINE# #INDENT# in_set = in_set . as_set ( ) #NEWLINE# #UNINDENT# if in_set . is_Interval : #NEWLINE# #INDENT# dom -= in_set #NEWLINE# #UNINDENT# solns = solver ( expr , symbol , in_set ) #NEWLINE# result += solns #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ( lhs , rhs_s ) = inverter ( f , 0 , symbol ) #NEWLINE# if ( lhs == symbol ) : #NEWLINE# #INDENT# if isinstance ( rhs_s , FiniteSet ) : #NEWLINE# #INDENT# rhs_s = FiniteSet ( * [ Mul ( * signsimp ( i ) . as_content_primitive ( ) ) for i in rhs_s ] ) #NEWLINE# #UNINDENT# result = rhs_s #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( rhs_s , FiniteSet ) : #NEWLINE# #INDENT# for equation in [ ( lhs - rhs ) for rhs in rhs_s ] : #NEWLINE# #INDENT# if ( equation == f ) : #NEWLINE# #INDENT# if ( any ( ( _has_rational_power ( g , symbol ) [ 0 ] for g in equation . args ) ) or _has_rational_power ( equation , symbol ) [ 0 ] ) : #NEWLINE# #INDENT# result += _solve_radical ( equation , symbol , solver ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if equation . has ( Abs ) : #NEWLINE# #INDENT# result += _solve_abs ( f , symbol , domain ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# result += _solve_as_rational ( equation , symbol , domain ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# result += solver ( equation , symbol ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# result = ConditionSet ( symbol , Eq ( f , 0 ) , domain ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if _check : #NEWLINE# #INDENT# if isinstance ( result , ConditionSet ) : #NEWLINE# #INDENT# return result #NEWLINE# #UNINDENT# fx = orig_f . as_independent ( symbol , as_Add = True ) [ 1 ] #NEWLINE# fx = fx . as_independent ( symbol , as_Add = False ) [ 1 ] #NEWLINE# if isinstance ( result , FiniteSet ) : #NEWLINE# #INDENT# result = FiniteSet ( * [ s for s in result if ( isinstance ( s , RootOf ) or domain_check ( fx , symbol , s ) ) ] ) #NEWLINE# #UNINDENT# #UNINDENT# return result