U
    ZÊ¹j²�  ã                   @   sb  d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	 ddl
mZmZmZmZ ddlmZmZ ddlmZmZmZmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlm Z m!Z!m"Z" ddl#m$Z$ ddl%m&Z&m'Z' ddl(m)Z)m*Z* ddl+m,Z, dd„ Z-dd„ Z.dd„ Z/d*dd„Z0dd„ Z1dd„ Z2dej3dfd d!„Z4d"d#„ Z5d+d$d%„Z6d&d'„ Z7g fd(d)„Z8dS ),z<Tools for solving inequalities and systems of inequalities. é    N)Úcontinuous_domainÚperiodicityÚfunction_range©Úsympify)Úfactor_terms)Ú
RelationalÚLtÚGeÚEq)ÚSymbolÚDummy)ÚIntervalÚ	FiniteSetÚUnionÚIntersection)ÚS)Ú
expand_mul)ÚAbs©ÚAnd)ÚPolyÚPolynomialErrorÚparallel_poly_from_expr)Ú_nsort)ÚsolvifyÚsolveset)ÚsiftÚiterable)Ú
filldedentc              	   C   s2  t | tƒstdƒ‚|  ¡ jr\t|  ¡ d|ƒ}|tjkr>tjgS |tj	krPtj
gS td| ƒ‚| jdd�g  }}|dkrœ|D ]\}}t||ƒ}| |¡ qz�n’|dkrätj}|tjdfg D ]$\}	}t||	d	d	ƒ}| |¡ |	}qº�nJ|  ¡ dkröd}
nd
}
d\}}|dk�rd}nD|dk�r"d
}n4|dk�r6d\}}n |dk�rJd\}}ntd| ƒ‚tjd	 }	}t|ƒD ] \}}|d �r´|
|k�rž| dt||	| |ƒ¡ |
 ||   }
}	}nT|
|k�ræ|�sæ| dt||	d	|ƒ¡ |d	 }	}n"|
|k�rj|�rj| dt||ƒ¡ �qj|
|k�r.| dttj|	d	|ƒ¡ |S )a  Solve a polynomial inequality with rational coefficients.

    Examples
    ========

    >>> from sympy import solve_poly_inequality, Poly
    >>> from sympy.abc import x

    >>> solve_poly_inequality(Poly(x, x, domain='ZZ'), '==')
    [{0}]

    >>> solve_poly_inequality(Poly(x**2 - 1, x, domain='ZZ'), '!=')
    [Interval.open(-oo, -1), Interval.open(-1, 1), Interval.open(1, oo)]

    >>> solve_poly_inequality(Poly(x**2 - 1, x, domain='ZZ'), '==')
    [{-1}, {1}]

    See Also
    ========
    solve_poly_inequalities
    z8For efficiency reasons, `poly` should be a Poly instancer   ú%could not determine truth value of %sF)Zmultipleú==ú!=é   Téÿÿÿÿ)NFú>ú<ú>=)r#   Tú<=)r$   Tz'%s' is not a valid relationé   )Ú
isinstancer   Ú
ValueErrorÚas_exprÚ	is_numberr   r   ÚtrueÚRealsÚfalseÚEmptySetÚNotImplementedErrorZ
real_rootsr   ÚappendÚNegativeInfinityÚInfinityZLCÚreversedÚinsert)ZpolyÚrelÚtÚrealsÚ	intervalsÚrootÚ_ÚintervalÚleftÚrightÚsignZeq_signÚequalZ
right_openZmultiplicity© rC   úY/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/solvers/inequalities.pyÚsolve_poly_inequality   sx    
ÿ


ÿ










 ÿ ÿ
 ÿrE   c                 C   s   t dd„ | D ƒŽ S )a�  Solve polynomial inequalities with rational coefficients.

    Examples
    ========

    >>> from sympy import Poly
    >>> from sympy.solvers.inequalities import solve_poly_inequalities
    >>> from sympy.abc import x
    >>> solve_poly_inequalities(((
    ... Poly(x**2 - 3), ">"), (
    ... Poly(-x**2 + 1), ">")))
    Union(Interval.open(-oo, -sqrt(3)), Interval.open(-1, 1), Interval.open(sqrt(3), oo))
    c                 S   s   g | ]}t |Ž D ]}|‘qqS rC   )rE   )Ú.0ÚpÚsrC   rC   rD   Ú
<listcomp>   s     
  z+solve_poly_inequalities.<locals>.<listcomp>)r   )ZpolysrC   rC   rD   Úsolve_poly_inequalitiesq   s    rJ   c                 C   sä   t j}| D ]Ô}|sq
tt jt jƒg}|D ] \\}}}t|| |ƒ}t|dƒ}g }	t ||¡D ]&\}
}|
 |¡}|t jk	r\|	 	|¡ q\|	}g }	|D ]*}|D ]}||8 }q˜|t jk	r�|	 	|¡ q�|	}|s( qÊq(|D ]}| 
|¡}qÎq
|S )a3  Solve a system of rational inequalities with rational coefficients.

    Examples
    ========

    >>> from sympy.abc import x
    >>> from sympy import solve_rational_inequalities, Poly

    >>> solve_rational_inequalities([[
    ... ((Poly(-x + 1), Poly(1, x)), '>='),
    ... ((Poly(-x + 1), Poly(1, x)), '<=')]])
    {1}

    >>> solve_rational_inequalities([[
    ... ((Poly(x), Poly(1, x)), '!='),
    ... ((Poly(-x + 1), Poly(1, x)), '>=')]])
    Union(Interval.open(-oo, 0), Interval.Lopen(0, 1))

    See Also
    ========
    solve_poly_inequality
    r!   )r   r1   r   r4   r5   rE   Ú	itertoolsÚproductÚ	intersectr3   Úunion)ÚeqsÚresultÚ_eqsZglobal_intervalsÚnumerÚdenomr8   Znumer_intervalsZdenom_intervalsr;   Znumer_intervalZglobal_intervalr>   Zdenom_intervalrC   rC   rD   Úsolve_rational_inequalities‚   s:    
 ÿ



rT   Tc              
      sÖ  d}g }t j}| D �]˜}|sqg }t j}|D �]@}	t|	tƒrF|	\}	}
n&|	jrb|	j|	j |	j }	}
n
|	d }	}
|	t j	krŒt j
t jd  }}}
n0|	t jkr¬t jt jd  }}}
n|	 ¡  ¡ \}}zt||fˆ ƒ\\}}}W n  tk
rö   ttdƒƒ‚Y nX |jj�s| ¡ | ¡ d  }}}|j ¡ }|j�s\|j�s\|| }	t|	d|
ƒ}	|t|	ˆ dd�M }q,| ||f|
f¡ q,|�r¤|t|gƒM }t‡ fdd„|D ƒgƒ}||8 }||O }q|�sÂ|�rÂ| ¡ }|�rÒ| ˆ ¡}|S )	a8  Reduce a system of rational inequalities with rational coefficients.

    Examples
    ========

    >>> from sympy import Symbol
    >>> from sympy.solvers.inequalities import reduce_rational_inequalities

    >>> x = Symbol('x', real=True)

    >>> reduce_rational_inequalities([[x**2 <= 0]], x)
    Eq(x, 0)

    >>> reduce_rational_inequalities([[x + 2 > 0]], x)
    -2 < x
    >>> reduce_rational_inequalities([[(x + 2, ">")]], x)
    -2 < x
    >>> reduce_rational_inequalities([[x + 2]], x)
    Eq(x, -2)

    This function find the non-infinite solution set so if the unknown symbol
    is declared as extended real rather than real then the result may include
    finiteness conditions:

    >>> y = Symbol('y', extended_real=True)
    >>> reduce_rational_inequalities([[y + 2 > 0]], y)
    (-2 < y) & (y < oo)
    Tr!   z„
                    only polynomials and rational functions are
                    supported in this context.
                    Fr   )Ú
relationalc                    s6   g | ].}|D ]$\\}}}|  ˆ ¡r||jfd f‘qqS )r!   )ÚhasÚone)rF   ÚiÚnÚdr=   ©ÚgenrC   rD   rI     s
     
 
ÿz0reduce_rational_inequalities.<locals>.<listcomp>)r   r1   r/   r*   ÚtupleZis_RelationalÚlhsÚrhsÚrel_opr.   ÚZeroÚOner0   ZtogetherÚas_numer_denomr   r   r   ÚdomainZis_ExactZto_exactZ	get_exactZis_ZZZis_QQr   Úsolve_univariate_inequalityr3   rT   ZevalfÚas_relational)Úexprsr\   rU   ÚexactrO   ZsolutionÚ_exprsrQ   Z_solÚexprr8   rR   rS   Úoptrd   ÚexcluderC   r[   rD   Úreduce_rational_inequalitiesÄ   s\    






 ÿ

ÿ


rm   c                    sˆ   |j dkrttdƒƒ‚‡ fdd„‰ dddœ}g }ˆ | ƒD ]D\} }|| ¡ krZt| d|ƒ} nt|  d|| ƒ} | | g| ¡ q8t||ƒS )	a�  Reduce an inequality with nested absolute values.

    Examples
    ========

    >>> from sympy import reduce_abs_inequality, Abs, Symbol
    >>> x = Symbol('x', real=True)

    >>> reduce_abs_inequality(Abs(x - 5) - 3, '<', x)
    (2 < x) & (x < 8)

    >>> reduce_abs_inequality(Abs(x + 2)*3 - 13, '<', x)
    (-19/3 < x) & (x < 7/3)

    See Also
    ========

    reduce_abs_inequalities
    Fzs
            Cannot solve inequalities with absolute values containing
            non-real variables.
            c                    sö   g }| j s| jrP| j‰| jD ]0}ˆ|ƒ}|s2|}q‡fdd„t ||¡D ƒ}qn¢| jrŠ| j‰ ˆ jsjt	dƒ‚| 
‡ fdd„ˆ| jƒD ƒ¡ nht| tƒrèˆ| jd ƒ}|D ]>\} }| | |t| dƒg f¡ | |  |t| dƒg f¡ q¦n
| g fg}|S )Nc                    s*   g | ]"\\}}\}}ˆ ||ƒ|| f‘qS rC   rC   )rF   rj   ÚcondsZ_exprZ_conds)ÚoprC   rD   rI   E  s     zBreduce_abs_inequality.<locals>._bottom_up_scan.<locals>.<listcomp>z'Only Integer Powers are allowed on Abs.c                 3   s   | ]\}}|ˆ  |fV  qd S ©NrC   )rF   rj   rn   )rY   rC   rD   Ú	<genexpr>L  s     zAreduce_abs_inequality.<locals>._bottom_up_scan.<locals>.<genexpr>r   )Zis_AddZis_MulÚfuncÚargsrK   rL   Úis_PowÚexpÚ
is_Integerr+   ÚextendÚbaser*   r   r3   r
   r	   )rj   rg   Úargri   rn   ©Ú_bottom_up_scan)rY   ro   rD   r{   9  s,    


ÿ
 
 
z.reduce_abs_inequality.<locals>._bottom_up_scanr%   r'   ©r&   r(   r   )Úis_extended_realÚ	TypeErrorr   Úkeysr   r3   rm   )rj   r8   r\   ÚmappingÚinequalitiesrn   rC   rz   rD   Úreduce_abs_inequality  s    

r‚   c                    s   t ‡ fdd„| D ƒŽ S )a  Reduce a system of inequalities with nested absolute values.

    Examples
    ========

    >>> from sympy import reduce_abs_inequalities, Abs, Symbol
    >>> x = Symbol('x', extended_real=True)

    >>> reduce_abs_inequalities([(Abs(3*x - 5) - 7, '<'),
    ... (Abs(x + 25) - 13, '>')], x)
    (-2/3 < x) & (x < 4) & (((-oo < x) & (x < -38)) | ((-12 < x) & (x < oo)))

    >>> reduce_abs_inequalities([(Abs(x - 4) + Abs(3*x - 5) - 7, '<')], x)
    (1/2 < x) & (x < 4)

    See Also
    ========

    reduce_abs_inequality
    c                    s   g | ]\}}t ||ˆ ƒ‘qS rC   )r‚   )rF   rj   r8   r[   rC   rD   rI   {  s   ÿz+reduce_abs_inequalities.<locals>.<listcomp>r   )rg   r\   rC   r[   rD   Úreduce_abs_inequalitiesf  s    ÿrƒ   Fc           )         s   ddl m} | tj¡dkr*ttdƒƒ‚n2|tjk	r\tˆˆd|d� |¡}|rX| 	ˆ¡}|S ˆ}|}ˆj
dkr†tj}|s||S | 	|¡S ˆj
dkrÐtddd	�‰zˆ |ˆi¡‰W n  tk
rÎ   ttd
ƒƒ‚Y nX d}ˆtjkræ|}�nˆtjkrútj}�nòˆjˆj }	t|	ˆƒ}
|
tjk�rVt|	ƒ}	ˆ |	d¡}|tjk�rB|}n|tjk�rtj}nÀ|
dk	�rt|	ˆ|ƒ}ˆj}|dk�rªˆ |jd¡�r’|}nˆ |jd¡�sàtj}n6|dk�ràˆ |jd¡�rÊ|}nˆ |jd¡�sàtj}|j|j }}|| tjk�rtd|
ddƒ |¡}|}|dk�rì|	 ¡ \}}z>ˆ|jk�rNt |	jƒdk�rNt!‚t"|	ˆ|ƒ}|dk�rht!‚W n6 t!tfk
�r    ttdˆ #ˆt$dƒ¡ ƒƒ‚Y nX t|	ƒ‰ ‡ ‡‡fdd„}g }|ˆˆƒD ]}| %t"|ˆ|ƒ¡ �qÈ|�sôt&ˆ ˆ|ƒ}dˆjk�oˆjdk}zÐt'|j(t)|j|jƒ ƒ}t)|| t*|ƒ Ž  t|j|j|j|k|j|kƒ¡}t+dd„ |D ƒƒ�r~t,|dd�d }nZt-|dd„ ƒ}|d �ršt‚z"|d }t |ƒdk�rºt.|ƒ}W n tk
�rÖ   t‚Y nX W n tk
�rø   tdƒ‚Y nX tj}ˆ  /tj0¡ }tjk�r¨d}t)ƒ }�z0t1|ˆ|ƒ}t2|tƒ�st|D ].}||k�rB||ƒ�rB|j
�rB|t)|ƒ7 }�qBnÞ|j|j } }!t,|t)|!ƒ ƒD ]¦}|| ƒ}"| |!k�r2||ƒ}#t3| |ƒ}$|$|k�r2|$j
�r2||$ƒ�r2|"�rò|#�rò|t| |ƒ7 }n@|"�r
|t 4| |¡7 }n(|#�r"|t 5| |¡7 }n|t 6| |¡7 }|} �q’|D ]}%|t)|%ƒ8 }�q>W n  tk
�rt   tj}d}Y nX |tjk�ržt!tdˆ #ˆ|¡|f ƒƒ‚| |¡}tjg}&|j} | |k�rà|| ƒ�rà| j7�rà|& 8t)| ƒ¡ |D ]~}'|'}!|t3| |!ƒƒ�r|& 8t| |!ddƒ¡ |'|k�r&| 9|'¡ n6|'|k�rD| 9|'¡ ||'ƒ}(n|}(|(�r\|& 8t)|'ƒ¡ |!} �qä|j}!|!|k�r”||!ƒ�r”|!j7�r”|& 8t)|!ƒ¡ |t3| |!ƒƒ�r¶|& 8t 6| |!¡¡ |tjk�rÔ|�rÔ| |¡}nt:t;|&Ž ||ƒ #ˆ|¡}|�sö|S | 	|¡S )aT  Solves a real univariate inequality.

    Parameters
    ==========

    expr : Relational
        The target inequality
    gen : Symbol
        The variable for which the inequality is solved
    relational : bool
        A Relational type output is expected or not
    domain : Set
        The domain over which the equation is solved
    continuous: bool
        True if expr is known to be continuous over the given domain
        (and so continuous_domain() does not need to be called on it)

    Raises
    ======

    NotImplementedError
        The solution of the inequality cannot be determined due to limitation
        in :func:`sympy.solvers.solveset.solvify`.

    Notes
    =====

    Currently, we cannot solve all the inequalities due to limitations in
    :func:`sympy.solvers.solveset.solvify`. Also, the solution returned for trigonometric inequalities
    are restricted in its periodic interval.

    See Also
    ========

    sympy.solvers.solveset.solvify: solver returning solveset solutions with solve's output API

    Examples
    ========

    >>> from sympy import solve_univariate_inequality, Symbol, sin, Interval, S
    >>> x = Symbol('x')

    >>> solve_univariate_inequality(x**2 >= 4, x)
    ((2 <= x) & (x < oo)) | ((-oo < x) & (x <= -2))

    >>> solve_univariate_inequality(x**2 >= 4, x, relational=False)
    Union(Interval(-oo, -2), Interval(2, oo))

    >>> domain = Interval(0, S.Infinity)
    >>> solve_univariate_inequality(x**2 >= 4, x, False, domain)
    Interval(2, oo)

    >>> solve_univariate_inequality(sin(x) > 0, x, relational=False)
    Interval.open(0, pi)

    r   ©ÚdenomsFz|
        Inequalities in the complex domain are
        not supported. Try the real domain by
        setting domain=S.Reals)rU   Ú
continuousNr\   T©Zextended_realz–
                When gen is real, the relational has a complex part
                which leads to an invalid comparison like I < 0.
                r|   )r%   r'   r#   z…
                    The inequality, %s, cannot be solved using
                    solve_univariate_inequality.
                    Úxc                    sŒ   ˆ   ˆt| ƒ¡}zˆ |d¡}W n tk
r:   tj}Y nX |tjtjfkrP|S |jdkr`tjS | d¡}|j	r|ˆ |d¡S t
d| ƒ‚d S )Nr   Fr)   z!relationship did not evaluate: %s)Úsubsr   rr   r~   r   r0   r.   r}   rY   Zis_comparabler2   )rˆ   ÚvÚr©Z
expanded_erj   r\   rC   rD   Úvalid  s    


ÿz*solve_univariate_inequality.<locals>.validú=r"   c                 s   s   | ]}|j V  qd S rp   )r-   )rF   r‹   rC   rC   rD   rq   @  s     z.solve_univariate_inequality.<locals>.<genexpr>)Ú	separatedc                 S   s   | j S rp   ©r}   )rˆ   rC   rC   rD   Ú<lambda>C  ó    z-solve_univariate_inequality.<locals>.<lambda>z'sorting of these roots is not supportedzä
                        %s contains imaginary parts which cannot be
                        made 0 for any value of %s satisfying the
                        inequality, leading to relations like I < 0.
                        )<Úsympy.solvers.solversr…   Z	is_subsetr   r/   r2   r   re   Úintersectionrf   r}   r1   r   Úxreplacer~   r.   r0   r^   r_   r   ra   r   rr   r   r`   ÚsupÚinfr5   r   rM   rc   Úfree_symbolsÚlenr+   r   r‰   r   rw   r   ÚsetÚboundaryr   ÚlistÚallr   r   ÚsortedZcoeffZImaginaryUnitr   r*   Ú_ptZRopenZLopenÚopenÚ	is_finiter3   Úremover   r   ))rj   r\   rU   rd   r†   r…   ÚrvZ_genZ_domainÚeZperiodÚconstZfranger8   r—   r–   rY   rZ   Zsolnsr�   ZsingularitiesZ	include_xZdiscontinuitiesZcritical_pointsr:   ZsiftedZ	make_realZcoeffIÚcheckZim_solÚaÚzÚstartÚendZvalid_startZvalid_zÚptrH   Zsol_setsrˆ   Ú_validrC   rŒ   rD   re     sT   9
   ÿÿ











ýÿ
ÿ
 ÿþ



ü




  ÿ ÿre   c                 C   sÞ   | j s|j s| | d }nÀ| j r.|j r.tj}n¬| j r>| jdksN|j rV|jdkrVtdƒ‚|j rb|jsn| j rx| jrx||  } }|j rª| jrŽ| d }qÚ| jr | tj }qÚ| d }n0| j rÚ|jrÂ|tj }n|jrÒ|d }n|d }|S )z$Return a point between start and endr)   Nz,cannot proceed with unsigned infinite valuesr#   )Úis_infiniter   ra   Zis_extended_positiver+   Zis_extended_negativeZHalf)r©   rª   r«   rC   rC   rD   rŸ   ¦  s:    ÿÿÿÿ



rŸ   c                 C   s€  ddl m} || jkr| S | j|kr*| j} | j|krD|| jjkrD| S dd„ }d}tj}| j| j }zBt||ƒ}| 	¡ dkrŒ|  
| ¡ d¡}n|s | 	¡ dkr t‚W �n0 ttfk
�rÔ   |�sÈzt| gg|ƒ}W n tk
rð   t| |ƒ}Y nX || ||ƒ}	|	tjk�r.||||ƒtjk�r.| ||k d¡}|| || ƒ}
|
tjk�r‚|||| ƒtjk�r‚| | |k d¡}| || kd¡}|tjk�rÐ|	tjk�r¢||kn||k }|
tjk	�rÐt| |k |ƒ}nt|ƒ}Y nX g }|dk�rn| ¡ }d}|j|dd�\}}||8 }||8 }t|ƒ}|j|d	d�\}}|jd	k�sd|j|j  k�rTdk�rnn n| jd
k�rn|}tj}|| }|j�rŒ|  
||¡}n| j 
||¡}|| jƒ|| jƒB }||ƒ}|| D ]T}tt|dƒ||d�}t|tƒ�r¾|j|k�r¾||||jƒtjk�r¾| | ¡ �q¾| |fD ]N}||||ƒtjk�r|| ||ƒtjk	�r| ||k�r`||k n||k ¡ �q| |¡ t|Ž S )a�  Return the inequality with s isolated on the left, if possible.
    If the relationship is non-linear, a solution involving And or Or
    may be returned. False or True are returned if the relationship
    is never True or always True, respectively.

    If `linear` is True (default is False) an `s`-dependent expression
    will be isolated on the left, if possible
    but it will not be solved for `s` unless the expression is linear
    in `s`. Furthermore, only "safe" operations which do not change the
    sense of the relationship are applied: no division by an unsigned
    value is attempted unless the relationship involves Eq or Ne and
    no division by a value not known to be nonzero is ever attempted.

    Examples
    ========

    >>> from sympy import Eq, Symbol
    >>> from sympy.solvers.inequalities import _solve_inequality as f
    >>> from sympy.abc import x, y

    For linear expressions, the symbol can be isolated:

    >>> f(x - 2 < 0, x)
    x < 2
    >>> f(-x - 6 < x, x)
    x > -3

    Sometimes nonlinear relationships will be False

    >>> f(x**2 + 4 < 0, x)
    False

    Or they may involve more than one region of values:

    >>> f(x**2 - 4 < 0, x)
    (-2 < x) & (x < 2)

    To restrict the solution to a relational, set linear=True
    and only the x-dependent portion will be isolated on the left:

    >>> f(x**2 - 4 < 0, x, linear=True)
    x**2 < 4

    Division of only nonzero quantities is allowed, so x cannot
    be isolated by dividing by y:

    >>> y.is_nonzero is None  # it is unknown whether it is 0 or not
    True
    >>> f(x*y < 1, x)
    x*y < 1

    And while an equality (or inequality) still holds after dividing by a
    non-zero quantity

    >>> nz = Symbol('nz', nonzero=True)
    >>> f(Eq(x*nz, 1), x)
    Eq(x, 1/nz)

    the sign must be known for other inequalities involving > or <:

    >>> f(x*nz <= 1, x)
    nz*x <= 1
    >>> p = Symbol('p', positive=True)
    >>> f(x*p <= 1, x)
    x <= 1/p

    When there are denominators in the original expression that
    are removed by expansion, conditions for them will be returned
    as part of the result:

    >>> f(x < x*(2/x - 1), x)
    (x < 1) & Ne(x, 0)
    r   r„   c                 S   sP   z0|   ||¡}|tjkr|W S |dkr,W d S |W S  tk
rJ   tj Y S X d S )N©TF)r‰   r   ÚNaNr~   )ÚierH   rX   rŠ   rC   rC   rD   Úclassify  s    
z#_solve_inequality.<locals>.classifyNr#   T)Zas_AddF)r"   r!   )Úlinear)r“   r…   r˜   r_   r6   r^   r   r5   r   Zdegreerr   r,   r2   r   rm   re   r.   r0   r‰   r   Zas_independentr   Úis_zeroZis_negativeZis_positiver`   rb   Ú_solve_inequalityr   r*   r3   )r°   rH   r²   r…   r±   r£   Zoorj   rG   ZokooZoknoorn   r¤   r_   ÚbZaxZefr§   Zbeginning_denomsZcurrent_denomsrZ   ÚcrX   rC   rC   rD   r´   Ç  s”    J



 ÿ
þ
þýÿ$
r´   c                    s:  i i  }}g }| D ]ò}|j |j }}| t¡}t|ƒdkrD| ¡ ‰ nF|j|@ }	t|	ƒdkr~|	 ¡ ‰ | tt	|d|ƒˆ ƒ¡ qnt
tdƒƒ‚| ˆ ¡r¬| ˆ g ¡ ||f¡ q| ‡ fdd„¡}
|
rìtdd„ |
D ƒƒrì| ˆ g ¡ ||f¡ q| tt	|d|ƒˆ ƒ¡ qdd	„ | ¡ D ƒ}d
d	„ | ¡ D ƒ}t|| | Ž S )Nr#   r   zZ
                    inequality has more than one symbol of interest.
                    c                    s    |   ˆ ¡o| jp| jo| jj S rp   )rV   Zis_Functionrt   ru   rv   )Úur[   rC   rD   r‘   “  s    
z&_reduce_inequalities.<locals>.<lambda>c                 s   s   | ]}t |tƒV  qd S rp   )r*   r   ©rF   rX   rC   rC   rD   rq   –  s     z'_reduce_inequalities.<locals>.<genexpr>c                 S   s   g | ]\}}t |g|ƒ‘qS rC   )rm   ©rF   r\   rg   rC   rC   rD   rI   ›  s     z(_reduce_inequalities.<locals>.<listcomp>c                 S   s   g | ]\}}t ||ƒ‘qS rC   )rƒ   r¹   rC   rC   rD   rI   œ  s     )r^   r`   Zatomsr   r™   Úpopr˜   r3   r´   r   r2   r   Zis_polynomialÚ
setdefaultÚfindr�   Úitemsr   )r�   ÚsymbolsZ	poly_partZabs_partÚotherZ
inequalityrj   r8   ÚgensÚcommonÚ
componentsZpoly_reducedZabs_reducedrC   r[   rD   Ú_reduce_inequalitiest  s,    




rÃ   c                    sP  t | ƒs| g} dd„ | D ƒ} tƒ jdd„ | D ƒŽ }t |ƒs@|g}t|ƒpJ||@ }tdd„ |D ƒƒrnttdƒƒ‚dd„ |D ƒ‰ ‡ fd	d„| D ƒ} ‡ fd
d„|D ƒ}g }| D ]~}t|tƒrÔ| |j	 
¡ |j 
¡  d¡}n|dkræt|dƒ}|dkròq¨n|dk�rtj  S |j	j�rtd| ƒ‚| |¡ q¨|} ~t| |ƒ}| dd„ ˆ  ¡ D ƒ¡S )aE  Reduce a system of inequalities with rational coefficients.

    Examples
    ========

    >>> from sympy.abc import x, y
    >>> from sympy import reduce_inequalities

    >>> reduce_inequalities(0 <= x + 3, [])
    (-3 <= x) & (x < oo)

    >>> reduce_inequalities(0 <= x + y*2 - 1, [x])
    (x < oo) & (x >= 1 - 2*y)
    c                 S   s   g | ]}t |ƒ‘qS rC   r   r¸   rC   rC   rD   rI   ²  s     z'reduce_inequalities.<locals>.<listcomp>c                 S   s   g | ]
}|j ‘qS rC   )r˜   r¸   rC   rC   rD   rI   ´  s     c                 s   s   | ]}|j d kV  qdS )FNr�   r¸   rC   rC   rD   rq   ¹  s     z&reduce_inequalities.<locals>.<genexpr>zP
            inequalities cannot contain symbols that are not real.
            c                 S   s&   i | ]}|j d kr|t|jdd�“qS )NTr‡   )r}   r   Únamer¸   rC   rC   rD   Ú
<dictcomp>¿  s    
ÿ z'reduce_inequalities.<locals>.<dictcomp>c                    s   g | ]}|  ˆ ¡‘qS rC   ©r•   r¸   ©ZrecastrC   rD   rI   Á  s     c                    s   h | ]}|  ˆ ¡’qS rC   rÆ   r¸   rÇ   rC   rD   Ú	<setcomp>Â  s     z&reduce_inequalities.<locals>.<setcomp>r   r®   TFr    c                 S   s   i | ]\}}||“qS rC   rC   )rF   ÚkrŠ   rC   rC   rD   rÅ   Ú  s      )r   rš   rN   Úanyr~   r   r*   r   rr   r^   r,   r_   r   r   r0   r-   r2   r3   rÃ   r•   r½   )r�   r¾   rÀ   ZkeeprX   r£   rC   rÇ   rD   Úreduce_inequalities¡  sB    ÿ




ÿ
rË   )T)F)9Ú__doc__rK   Zsympy.calculus.utilr   r   r   Z
sympy.corer   Zsympy.core.exprtoolsr   Zsympy.core.relationalr   r	   r
   r   Zsympy.core.symbolr   r   Zsympy.sets.setsr   r   r   r   Zsympy.core.singletonr   Zsympy.core.functionr   Z$sympy.functions.elementary.complexesr   Zsympy.logicr   Zsympy.polysr   r   r   Zsympy.polys.polyutilsr   Zsympy.solvers.solvesetr   r   Zsympy.utilities.iterablesr   r   Zsympy.utilities.miscr   rE   rJ   rT   rm   r‚   rƒ   r/   re   rŸ   r´   rÃ   rË   rC   rC   rC   rD   Ú<module>   s<   [B
[G  )!
 .-