o
    §ƒð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   s  t | tƒs	tdƒ‚|  ¡ jr.t|  ¡ d|ƒ}|tju rtjgS |tj	u r(tj
gS td| ƒ‚| jdd�g }}|dkrN|D ]\}}t||ƒ}| |¡ q=|S |dkrrtj}|tjdfg D ]\}	}t||	d	d	ƒ}| |¡ |	}q]|S |  ¡ dkr{d}
nd
}
d\}}|dkrˆd}n|dkr�d
}n|dkr˜d\}}n|dkr¡d\}}ntd| ƒ‚tjd	}	}t|ƒD ]I\}}|d rÔ|
|krÉ| dt||	| |ƒ¡ |
 || }
}	}q±|
|krë|së| dt||	d	|ƒ¡ |d	}	}q±|
|krú|rú| dt||ƒ¡ q±|
|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)Úmultipleú==ú!=é   Téÿÿÿÿ)NFú>ú<ú>=)r$   Tú<=)r%   Tz'%s' is not a valid relationé   )Ú
isinstancer   Ú
ValueErrorÚas_exprÚ	is_numberr   r   ÚtrueÚRealsÚfalseÚEmptySetÚNotImplementedErrorÚ
real_rootsr   ÚappendÚNegativeInfinityÚInfinityÚLCÚreversedÚinsert)ÚpolyÚrelÚtÚrealsÚ	intervalsÚrootÚ_ÚintervalÚleftÚrightÚsignÚeq_signÚequalÚ
right_openÚmultiplicity© rJ   úœ/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/lib/python3.10/site-packages/sympy/solvers/inequalities.pyÚsolve_poly_inequality   sx   
ÿ


ÿ
0Ñ
)Ù

ÿÿ€
ÿrL   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 rJ   )rL   )Ú.0ÚpÚsrJ   rJ   rK   Ú
<listcomp>   s    z+solve_poly_inequalities.<locals>.<listcomp>)r   )ÚpolysrJ   rJ   rK   Úsolve_poly_inequalitiesq   s   rR   c                 C   sä   t j}| D ]j}|s
qtt jt jƒg}|D ]P\\}}}t|| |ƒ}t|dƒ}g }	t ||¡D ]\}
}|
 |¡}|t jurA|	 	|¡ q.|	}g }	|D ]}|D ]}||8 }qL|t jur]|	 	|¡ qH|	}|sd nq|D ]}| 
|¡}qgq|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   r2   r   r6   r7   rL   Ú	itertoolsÚproductÚ	intersectr5   Úunion)ÚeqsÚresultÚ_eqsÚglobal_intervalsÚnumerÚdenomr<   Únumer_intervalsÚdenom_intervalsr?   Únumer_intervalÚglobal_intervalrB   Údenom_intervalrJ   rJ   rK   Úsolve_rational_inequalities‚   s@   
ÿ


€


€ÿÿrb   Tc              
      s¸  d}g }t j}| D ]Á}|sq	g }t j}|D ]—}	t|	tƒr!|	\}	}
n|	jr/|	j|	j |	j}	}
nd}
|	t j	u rAt j
t jd}}}
n|	t ju rQt jt jd}}}
n|	 ¡  ¡ \}}zt||fˆ ƒ\\}}}W n tys   ttdƒƒ‚w |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)rM   ÚiÚnÚdrA   ©ÚgenrJ   rK   rP     s
    ÿÿz0reduce_rational_inequalities.<locals>.<listcomp>)r   r2   r0   r+   ÚtupleÚis_RelationalÚlhsÚrhsÚrel_opr/   ÚZeroÚOner1   ÚtogetherÚas_numer_denomr   r   r   ÚdomainÚis_ExactÚto_exactÚ	get_exactÚis_ZZÚis_QQr   Úsolve_univariate_inequalityr5   rb   ÚevalfÚas_relational)Úexprsrj   rc   ÚexactrW   ÚsolutionÚ_exprsrY   Ú_solÚexprr<   r[   r\   Úoptrt   ÚexcluderJ   ri   rK   Úreduce_rational_inequalitiesÄ   s\   



ÿÿ

ÿ

r…   c                    sˆ   |j du rttdƒƒ‚‡ fdd„‰ dddœ}g }ˆ | ƒD ]"\} }|| ¡ vr-t| d|ƒ} n	t|  d|| ƒ} | | g| ¡ qt||ƒ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r)| j‰| jD ]}ˆ|ƒ}|s|}q‡fdd„t ||¡D ƒ}q|S | jrG| j‰ ˆ js6t	dƒ‚| 
‡ fdd„ˆ| jƒD ƒ¡ |S t| tƒrwˆ| jd ƒ}|D ]\} }| | |t| dƒg f¡ | |  |t| dƒg f¡ qU|S | g fg}|S )Nc                    s*   g | ]\\}}\}}ˆ ||ƒ|| f‘qS rJ   rJ   )rM   r‚   ÚcondsÚ_exprÚ_conds)ÚoprJ   rK   rP   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 ©NrJ   )rM   r‚   r†   )rg   rJ   rK   Ú	<genexpr>L  s   € zAreduce_abs_inequality.<locals>._bottom_up_scan.<locals>.<genexpr>r   )Úis_AddÚis_MulÚfuncÚargsrS   rT   Úis_PowÚexpÚ
is_Integerr,   ÚextendÚbaser+   r   r5   r
   r	   )r‚   r}   Úargr€   r†   ©Ú_bottom_up_scan)rg   r‰   rK   r—   9  s2   


ÿñ

÷
þz.reduce_abs_inequality.<locals>._bottom_up_scanr&   r(   ©r'   r)   r   )Úis_extended_realÚ	TypeErrorr   Úkeysr   r5   r…   )r‚   r<   rj   ÚmappingÚinequalitiesr†   rJ   r–   rK   Ú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 rJ   )rž   )rM   r‚   r<   ri   rJ   rK   rP   {  s    ÿz+reduce_abs_inequalities.<locals>.<listcomp>r   )r}   rj   rJ   ri   rK   Úreduce_abs_inequalitiesf  s   ÿrŸ   Fc           )         sÎ  ddl m} | tj¡du rttdƒƒ‚|tjur-tˆˆd|d� |¡}|r+| 	ˆ¡}|S 	 ˆ}|}ˆj
du rCtj}|s>|S | 	|¡S ˆj
du retddd	�‰z	ˆ |ˆi¡‰W n tyd   ttd
ƒƒ‚w d}ˆtju rp|}�níˆtju rztj}�nãˆjˆj }	t|	ˆƒ}
|
tjkr¥t|	ƒ}	ˆ |	d¡}|tju rœ|}na|tju r¤tj}nX|
durýt|	ˆ|ƒ}ˆj}|dv rËˆ |jd¡rÀ|}n#ˆ |jd¡sÊtj}n|dv rãˆ |jd¡rÙ|}n
ˆ |jd¡sãtj}|j|j}}|| tju rýtd|
ddƒ |¡}|}|du �r]|	 ¡ \}}zˆ|jv�rt |	jƒdk�rt!‚t"|	ˆ|ƒ}|du �r&t!‚W n t!tf�y?   ttdˆ #ˆt$dƒ¡ ƒƒ‚w t|	ƒ‰ ‡ ‡‡fdd„}g }|ˆˆƒD ]}| %t"|ˆ|ƒ¡ �qS|�sit&ˆ ˆ|ƒ}dˆjv �osˆjdk}zet'|j(t)|j|jƒ ƒ}t)|| t*|ƒ Ž  t|j|j|j|v|j|vƒ¡}t+dd„ |D ƒƒ�r®t,|dd�d }n*t-|dd„ ƒ}|d �r¼t‚z|d }t |ƒdk�rÌt.|ƒ}W n
 t�y×   t‚w W n t�yå   tdƒ‚w tj}ˆ  /tj0¡ }tjk�r»d}t)ƒ }z˜t1|ˆ|ƒ}t2|tƒ�s"|D ]}||v�r||ƒ�r|j
�r|t)|ƒ7 }�q	no|j|j} }!t,|t)|!ƒ ƒD ]S}|| ƒ}"| |!k�r�||ƒ}#t3| |ƒ}$|$|v�r�|$j
�r�||$ƒ�r�|"�ra|#�ra|t| |ƒ7 }n |"�rm|t 4| |¡7 }n|#�ry|t 5| |¡7 }n|t 6| |¡7 }|} �q1|D ]	}%|t)|%ƒ8 }�q‡W n t�y¡   tj}d}Y nw |tju �r¶t!tdˆ #ˆ|¡|f ƒƒ‚| |¡}tjg}&|j} | |v �r×|| ƒ�r×| j7�r×|& 8t)| ƒ¡ |D ]?}'|'}!|t3| |!ƒƒ�rï|& 8t| |!ddƒ¡ |'|v �rú| 9|'¡ n|'|v �r	| 9|'¡ ||'ƒ}(n|}(|(�r|& 8t)|'ƒ¡ |!} �qÙ|j}!|!|v �r1||!ƒ�r1|!j7�r1|& 8t)|!ƒ¡ |t3| |!ƒƒ�rB|& 8t 6| |!¡¡ |tjk�rQ|�rQ| |¡}nt:t;|&Ž ||ƒ #ˆ|¡}|�sb|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)rc   Ú
continuousNrj   T©Ú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y   tj}Y nw |tjtjfv r'|S |jdu r/tjS | d¡}|j	r=ˆ |d¡S t
d| ƒ‚)Nr   Fr*   z!relationship did not evaluate: %s)Úsubsr   rŽ   rš   r   r1   r/   r™   rg   Úis_comparabler3   )r¥   ÚvÚr©Ú
expanded_er‚   rj   rJ   rK   Úvalid  s    

ÿ

ÿz*solve_univariate_inequality.<locals>.validú=r#   c                 s   s   � | ]}|j V  qd S rŠ   )r.   )rM   r©   rJ   rJ   rK   r‹   @  s   € z.solve_univariate_inequality.<locals>.<genexpr>)Ú	separatedc                 S   s   | j S rŠ   ©r™   )r¥   rJ   rJ   rK   Ú<lambda>C  s    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¡   Ú	is_subsetr   r0   r3   r   rz   Úintersectionr|   r™   r2   r   Úxreplacerš   r/   r1   rm   rn   r   rp   r   rŽ   r   ro   ÚsupÚinfr7   r   rU   rs   Úfree_symbolsÚlenr,   r   r¦   r   r“   r   ÚsetÚboundaryr   ÚlistÚallr   r   ÚsortedÚcoeffÚImaginaryUnitr   r+   Ú_ptÚRopenÚLopenÚopenÚ	is_finiter5   Úremover   r   ))r‚   rj   rc   rt   r¢   r¡   ÚrvÚ_genÚ_domainÚeÚperiodÚconstÚfranger<   r¶   rµ   rg   rh   Úsolnsr¬   ÚsingularitiesÚ	include_xÚdiscontinuitiesÚcritical_pointsr>   ÚsiftedÚ	make_realÚcoeffIÚcheckÚim_solÚaÚzÚstartÚendÚvalid_startÚvalid_zÚptrO   Úsol_setsr¥   Ú_validrJ   rª   rK   rz     sf  9
ÿÿ


ÿ






€€

þýýÿ
ÿ
ÿÿÿ
€ÿ€ÿ€þ

€þü





ÿÿrz   c                 C   sì   | j s|j s| | d }|S | j r|j rtj}|S | j r!| jdu s)|j r-|jdu r-tdƒ‚|j r3|js9| j r>| jr>|| } }|j rZ| jrJ| d }|S | jrT| tj }|S | d }|S | j rt|jrg|tj }|S |jrp|d }|S |d }|S )z$Return a point between start and endr*   Nz,cannot proceed with unsigned infinite valuesr$   )Úis_infiniter   rp   Úis_extended_positiver,   Úis_extended_negativeÚHalf)rÙ   rÚ   rÝ   rJ   rJ   rK   rÀ   ¦  sF   æéÿ
ÿÿ
õ

øù
üÿrÀ   c                 C   sh  ddl m} || jvr| S | j|kr| j} | j|kr"|| jjvr"| S dd„ }d}tj}| j| j }z t||ƒ}| 	¡ dkrF|  
| ¡ d¡}n
|sP| 	¡ dkrPt‚W n� ttfyÞ   |sØz	t| gg|ƒ}W n tys   t| |ƒ}Y nw || ||ƒ}	|	tju r�||||ƒtju r�| ||k d¡}|| || ƒ}
|
tju r¸|||| ƒtju r¸| | |k d¡}| || kd¡}|tju r×|	tju rÆ||kn||k }|
tjur×t| |k |ƒ}nt|ƒ}Y nw g }|du �r«| ¡ }d}|j|dd�\}}||8 }||8 }t|ƒ}|j|d	d�\}}|jd	k�s&|j|j  k�rdu �r+n n| jd
v�r+|}tj}|| }|j�r:|  
||¡}n| j 
||¡}|| jƒ|| jƒB }||ƒ}|| D ]*}tt|dƒ||d�}t|tƒ�r||j|k�r|||||jƒtju �r|| | ¡ �qS| |fD ]'}||||ƒtju �r©|| ||ƒtju�r©| ||u �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   sJ   z|   ||¡}|tju r|W S |dvrW d S |W S  ty$   tj Y S w )N©TF)r¦   r   ÚNaNrš   )ÚierO   rf   r¨   rJ   rJ   rK   Úclassify  s   

ÿz#_solve_inequality.<locals>.classifyNr$   T)Úas_AddF)r#   r"   )Úlinear)r±   r¡   r·   rn   r9   rm   r   r7   r   ÚdegreerŽ   r-   r3   r   r…   rz   r/   r1   r¦   r   Úas_independentr   Úis_zeroÚis_negativeÚis_positivero   rq   Ú_solve_inequalityr   r+   r5   )ræ   rO   ré   r¡   rç   rÆ   Úoor‚   rN   ÚokooÚoknoor†   rÉ   rn   ÚbÚaxÚefr×   Úbeginning_denomsÚcurrent_denomsrh   Úcrf   rJ   rJ   rK   rï   Ç  sœ   J


€ÿ


€€ë

ÿÿ€ €
rï   c                    s8  i i }}g }| D ]x}|j |j}}| t¡}t|ƒdkr"| ¡ ‰ n"|j|@ }	t|	ƒdkr>|	 ¡ ‰ | tt	|d|ƒˆ ƒ¡ q	t
tdƒƒ‚| ˆ ¡rU| ˆ g ¡ ||f¡ q	| ‡ fdd„¡}
|
rutdd„ |
D ƒƒru| ˆ 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 rŠ   )rd   Úis_Functionr�   r‘   r’   )Úuri   rJ   rK   r°   “  s   
z&_reduce_inequalities.<locals>.<lambda>c                 s   s   � | ]}t |tƒV  qd S rŠ   )r+   r   ©rM   rf   rJ   rJ   rK   r‹   –  ó   € z'_reduce_inequalities.<locals>.<genexpr>c                 S   s   g | ]
\}}t |g|ƒ‘qS rJ   )r…   ©rM   rj   r}   rJ   rJ   rK   rP   ›  s    z(_reduce_inequalities.<locals>.<listcomp>c                 S   s   g | ]	\}}t ||ƒ‘qS rJ   )rŸ   rý   rJ   rJ   rK   rP   œ  s    )rm   ro   Úatomsr   r¸   Úpopr·   r5   rï   r   r3   r   Úis_polynomialÚ
setdefaultÚfindr¼   Úitemsr   )r�   ÚsymbolsÚ	poly_partÚabs_partÚotherÚ
inequalityr‚   r<   ÚgensÚcommonÚ
componentsÚpoly_reducedÚabs_reducedrJ   ri   rK   Ú_reduce_inequalitiest  s,   




r  c                    sJ  t | ƒs| g} dd„ | D ƒ} tƒ jdd„ | D ƒŽ }t |ƒs |g}t|ƒp%||@ }tdd„ |D ƒƒr7ttdƒƒ‚dd„ |D ƒ‰ ‡ fd	d„| D ƒ} ‡ fd
d„|D ƒ}g }| D ]<}t|tƒrj| |j	 
¡ |j 
¡  d¡}n	|dvrst|dƒ}|dkrxqT|dkr�tj  S |j	jr‹td| ƒ‚| |¡ qT|} ~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 rJ   r   rû   rJ   rJ   rK   rP   ²  s    z'reduce_inequalities.<locals>.<listcomp>c                 S   s   g | ]}|j ‘qS rJ   )r·   rû   rJ   rJ   rK   rP   ´  s    c                 s   s   � | ]}|j d u V  qdS )FNr¯   rû   rJ   rJ   rK   r‹   ¹  rü   z&reduce_inequalities.<locals>.<genexpr>zP
            inequalities cannot contain symbols that are not real.
            c                 S   s&   i | ]}|j d u r|t|jdd�“qS )NTr£   )r™   r   Únamerû   rJ   rJ   rK   Ú
<dictcomp>¿  s    ÿz'reduce_inequalities.<locals>.<dictcomp>c                    s   g | ]}|  ˆ ¡‘qS rJ   ©r´   rû   ©ÚrecastrJ   rK   rP   Á  ó    c                    s   h | ]}|  ˆ ¡’qS rJ   r  rû   r  rJ   rK   Ú	<setcomp>Â  r  z&reduce_inequalities.<locals>.<setcomp>r   rä   TFr    c                 S   s   i | ]\}}||“qS rJ   rJ   )rM   Úkr¨   rJ   rJ   rK   r  Ú  r  )r   r¹   rV   Úanyrš   r   r+   r   rŽ   rm   r-   rn   r   r   r1   r.   r3   r5   r  r´   r  )r�   r  r	  Úkeeprf   rÆ   rJ   r  rK   Úreduce_inequalities¡  sB   ÿ


ÿ
r  )T)F)9Ú__doc__rS   Úsympy.calculus.utilr   r   r   Ú
sympy.corer   Úsympy.core.exprtoolsr   Úsympy.core.relationalr   r	   r
   r   Úsympy.core.symbolr   r   Úsympy.sets.setsr   r   r   r   Úsympy.core.singletonr   Úsympy.core.functionr   Ú$sympy.functions.elementary.complexesr   Úsympy.logicr   Úsympy.polysr   r   r   Úsympy.polys.polyutilsr   Úsympy.solvers.solvesetr   r   Úsympy.utilities.iterablesr   r   Úsympy.utilities.miscr   rL   rR   rb   r…   rž   rŸ   r0   rz   rÀ   rï   r  r  rJ   rJ   rJ   rK   Ú<module>   s>    [
B[G  )
! .-