� ��g����V�dZddlZddlmZmZmZddlmZddlm Z ddl m Z m Z m Z mZddlmZmZddlmZmZmZmZdd lmZdd lmZdd lmZdd lmZdd lm Z m!Z!m"Z"ddl#m$Z$ddl%m&Z&m'Z'ddl(m)Z)m*Z*ddl+m,Z,d�Z-d�Z.d�Z/dd�Z0d�Z1d�Z2dej3dfd�Z4d�Z5d d�Z6d�Z7gfd�Z8dS)!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 �<�t|t��std���|���jrkt |���d|��}|t jur t jgS|t j ur t j gStd|z���|� d���g}}|dkr/|D]*\}}t||��}|�|���+�n�|dkrOt j}|t jdfgzD].\} }t|| d d ��}|�|��| }�/�nQ|���dkrd} nd } d \} } |d krd} n3|d krd } n*|dkrd\} } n|dkrd\} } ntd|z���t jd } } t%|��D]�\}}|dzr6| | kr'|�dt|| | | ����| || } } } �@| | kr-| s+|�dt|| d | ����|d } } �s| | kr&| r$|�dt||������| | kr0|�dtt j| d | ����|S)aSolve 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� multiplicitys �j/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/solvers/inequalities.py�solve_poly_inequalityrMs ��, �d�D� !� !�H�� F�H�H� H� �|�|�~�~��=� �t�|�|�~�~�q�#� .� .�� ���;�;��G�9� � �!�'�\�\��J�<� �%�7�!�;�=�=� =������6�6��9�E� �d�{�{�� '� '�G�D�!���d�+�+�H� � � �X� &� &� &� &� '� �����!���!�*�a�� 1�1� � �H�E�1���e�T�4�8�8�H� � � �X� &� &� &��D�D� � �7�7�9�9�q�=�=��D�D��D�$���� �#�:�:��G�G� �C�Z�Z��G�G� �D�[�[�%�N�G�U�U� �D�[�[�%�N�G�U�U��;�c�A�B�B� B��J��z��"*�5�/�/� >� >� �D�,��a�� >��7�?�?��$�$��8�D�%�U��J�G�G�I�I�I�,0�%��5�y�Z�e����7�?�?�5�?��$�$��8�D�%��z�B�B�D�D�D�(,�d�:�E�E��W�_�_��_��$�$�Q���t�(<�(<�=�=�=�� �7�?�?� � � ��8�A�.��t�Z�H�H� J� J� J� ��c�(�td�|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�*�g|]}t|�D]}|���S�)rM)�.0�p�ss rL� <listcomp>z+solve_poly_inequalities.<locals>.<listcomp>s+��G�G�G��-B�A�-F�G�G��1�G�G�G�GrN)r)�polyss rL�solve_poly_inequalitiesrWqs�� �G�G�e�G�G�G� H�HrNc�.�tj}|D�]}|s�ttjtj��g}|D]�\\}}}t ||z|��}t |d��}g} t j||��D]=\} } | �| ��} | tjur| � | ���>| }g} |D]/} |D]} | | z} �| tjur| � | ���0| }|sn��|D]} |� | ��}���|S)a3Solve 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$) rr4rr8r9rM� itertools�product� intersectr7�union)�eqs�result�_eqs�global_intervals�numer�denomr>�numer_intervals�denom_intervalsrA�numer_interval�global_intervalrD�denom_intervals rL�solve_rational_inequalitiesrh�sw��.�Z�F��$,�$,��� � �$�Q�%7���D�D�E��#'� � � �N�U�E�C�3�E�%�K��E�E�O�3�E�4�@�@�O��I�3<�3D�#�%5�47�47� /� /�/���)�3�3�O�D�D���1�:�-�-��$�$�X�.�.�.��(� ��I�#3� 6� 6��&5�6�6�N�#�~�5�O�O�"�!�*�4�4��$�$�_�5�5�5��(� �#� ��� �)� ,� ,�H��\�\�(�+�+�F�F� ,� �MrNTc�x��d}g}tj}|D�]�}|s�g}tj}|D�]�} t| t��r| \} } n"| jr| j| jz | j} } n| d} } | tj urtj tj d} } } nR| tj urtj tj d} } } n)| � �����\} } t| | f���\\} } } n*#t $rt!t#d�����wxYw| jjs*| ���| ���d}} } | j���}|js4|js-| | z } t1| d| ��} |t3| �d���z}���|�| | f| f�����|r4|t7|g��z}t7�fd�|D��g��}||z}||z}���|s|r|���}|r|����}|S)a8Reduce 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�f��g|]-}|D](\\}}}|�����||jfdf��)�.S)r$)�has�one)rR�i�n�drC�gens �rLrUz0reduce_rational_inequalities.<locals>.<listcomp>sh���4A�4A�4A���4A�4A�!,�&�1�a�!�Q�U�U�3�Z�Z�4A�a���Z��4F�4A�4A�4A�4ArN)rr4r2r-�tuple� is_Relational�lhs�rhs�rel_opr1�Zero�Oner3�together�as_numer_denomrrr �domain�is_Exact�to_exact� get_exact�is_ZZ�is_QQr �solve_univariate_inequalityr7rh�evalf� as_relational)�exprsrqrj�exactr]�solution�_exprsr_�_sol�exprr>rarb�optr{�excludes ` rL�reduce_rational_inequalitiesr��s����: �E� �C��z�H��0�0��� � ����w���# 3�# 3�D��$��&�&� +� � ��c�c��%�+� $��4�8� 3�T�[�#�D�D� $�d�#�D��q�v�~�~�$%�F�A�E�4�c�u��������$%�E�1�5�$�c�u���#�}�}���=�=�?�?� ��u� �&=��E�N�C�')�')�#�������"� � � �%�j�2�'�'���� ���� �:�&� P�&+�n�n�&6�&6����8H�8H�%�e�u���Z�)�)�+�+�F��L� 3�F�L� 3��U�{��!�$��3�/�/���3�D�#�%�P�P�P�P���� � �e�U�^�S�1�2�2�2�2� � � �/���7�7� 7�D�1�4A�4A�4A�4A��4A�4A�4A�3B�C�C�G� �G�O�D��D���� �$�X�$��>�>�#�#���/��)�)�#�.�.�� �Os �&C?�?'D&c�Z��|jdurttd������fd��ddd�}g}�|��D]^\}}||���vrt |d|��}nt | d||��}|�|g|z���_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 �r����g}|js|jrC|j�|jD]3}�|��}|s|}��fd�t j||��D��}�4n�|jrM|j��jstd���|� �fd��|j ��D����n�t|t��rr�|jd��}|D]X\}}|�||t|d��gzf��|�| |t!|d��gzf���Yn|gfg}|S)Nc�D��g|]\\}}\}}�||��||zf��SrQrQ)rRr��conds�_expr�_conds�ops �rLrUzBreduce_abs_inequality.<locals>._bottom_up_scan.<locals>.<listcomp>EsH���>�>�>�Ca�=�D�%�Ra�SX�Z`�b�b��u�o�o�u�v�~�>�>�>�>rNz'Only Integer Powers are allowed on Abs.c3�,�K�|]\}}|�z|fV��dS�NrQ)rRr�r�ros �rL� <genexpr>zAreduce_abs_inequality.<locals>._bottom_up_scan.<locals>.<genexpr>Ls0�����X�X�k�d�E�$��'�5�)�X�X�X�X�X�XrNr)�is_Add�is_Mul�func�argsrYrZ�is_Pow�exp� is_Integerr.�extend�baser-rr7r r )r�r��argr�r�ror��_bottom_up_scans @@�rLr�z.reduce_abs_inequality.<locals>._bottom_up_scan9s�������� �;� !�$�+� !���B��y� >� >��(���-�-���>�"�E�E�>�>�>�>�%�-�e�V�<�<�>�>�>�E�E�  >��[� !���A��<� L� �!J�K�K�K� �L�L�X�X�X�X�_�_�T�Y�=W�=W�X�X�X� X� X� X� X� ��c� "� "� !�$�_�T�Y�q�\�2�2�F�%� =� =� ��e�� � �t�U�b��q�k�k�]�%:�;�<�<�<�� � �t�e�U�b��q�k�k�]�%:�;�<�<�<�<� =��B�Z�L�E�� rNr(r*�r)r+r)�is_extended_real� TypeErrorr �keysr r7r�)r�r>rq�mapping� inequalitiesr�r�s @rL�reduce_abs_inequalityr�s����( ��u�$�$���%����� � �����>�t�$�$�G��L�&��t�,�,�,�,� ��e� �g�l�l�n�n� $� $��t�Q��,�,�D�D��t�e�Q��� �5�5�D����T�F�U�N�+�+�+�+� '� �c� :� :�:rNc�.��t�fd�|D���S)aReduce 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�8��g|]\}}t||�����SrQ)r�)rRr�r>rqs �rLrUz+reduce_abs_inequalities.<locals>.<listcomp>{s9���!�!�!� �D�#�(��c�3�7�7�!�!�!rNr)r�rqs `rL�reduce_abs_inequalitiesr�fs8���* �!�!�!�!��!�!�!� "�"rNFc �$���)�ddlm}|�tj��durt t d�����|tjur?t��d|����|��}|r|� ���}|S �}|}�j dur%tj }|s|n|� |��S�j �Ttdd� ��� �� |�i���n*#t$rtt d �����wxYwd}�tjur|}�nÉtjurtj }�n��j�jz } t'| ���} | tjkrRt+| ��} ��| d��} | tjur|}�n| tjur tj }n�| ��t/| �|��} �j} | d vrF��| jd��r|}nq��| jd��s tj }nI| d vrE��| jd��r|}n'��| jd��s tj }|j|j}}||z tjur't9d| dd���|��}|}|��0| ���\}} �|jvrtA| j��d krtB�tE| �|��}|�tB�nU#tBt f$rAt t d��#�tId����z�����wxYwt+| ���)�)��fd�}g}|����D]&}|�%tE|�|�����'|stM�)�|��}d�jvo �jdk} tO|j(tS|j|j��z ��}tS||ztU|��z��t9|j|j|j|v|j|v����}tWd�|D����rtY|d���d}nat[|d���}|drt � |d}tA|��d krt]|��}n#t$rt �wxYwn#t $rt d���wxYwtj}�)�/tj0��x}tjk�r�d}tS��} tc|�|��}te|t8��s.|D]*}||vr$||��r|j r|tS|��z }�+n�|j|j}!} tY|tS|!��z��D]�}|| ��}"| |!kr�||��}#tg| |��}$|$|vrx|$j rq||$��rf|"r|#r|t9| |��z }nN|"r|t9j4| |��z }n3|#r|t9j5| |��z }n|t9j6| |��z }|} ��|D]}%|tS|%��z}�n#t$rtj}d}YnwxYw|tj ur7tCt d��#�|���d|�d������|�|��}tj g}&|j} | |vr4|| ��r)| j7r"|&�8tS| ����|D]�}'|'}!|tg| |!����r%|&�8t9| |!dd����|'|vr|�9|'��nK|'|vr!|�9|'��||'��}(n|}(|(r"|&�8tS|'����|!} ��|j}!|!|vr4||!��r)|!j7r"|&�8tS|!����|tg| |!����r(|&�8t9j6| |!����|tjkr|r|�|��}n,tutw|&�||���#�|��}|s|n|� |��S)aTSolves 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)rj� continuousNrqT�� 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������t|����} ��|d��}n#t$rtj}YnwxYw|tjtjfvr|S|jdur tjS|�d��}|j r��|d��Std|z���)NrFr,z!relationship did not evaluate: %s) �subsrr�r�rr3r1r�ro� is_comparabler5)r��v�r� expanded_er�rqs ���rL�validz*solve_univariate_inequality.<locals>.valids�����O�O�C��A���7�7�� �� � �!�Q���A�A�� � � � ���A�A�A� ���������)�)�)��H��%��.�.��7�N����A���A���/�#�y�y��A���.�-�;�a�?�A�A�As�=�A�A�=r%c3�$K�|] }|jV�� dSr�)r0)rRr�s rLr�z.solve_univariate_inequality.<locals>.<genexpr>@s$����<�<�q�q�{�<�<�<�<�<�<rN)� separatedc��|jSr��r�)r�s rL�<lambda>z-solve_univariate_inequality.<locals>.<lambda>Cs ��Q�=O�rNz'sorting of these roots is not supportedz zZ contains imaginary parts which cannot be made 0 for any value of zm satisfying the inequality, leading to relations like I < 0. )<�sympy.solvers.solversr�� is_subsetrr2r5r r�� intersectionr�r�r4r�xreplacer�r1r3rtrurrwrr�rrv�sup�infr9rr[rz� free_symbols�lenr.rr�r r�r�set�boundaryr�list�allrr�sorted�coeff� ImaginaryUnitrr-�_pt�Ropen�Lopen�open� is_finiter7�removerr)*r�rqrjr{r�r��rv�_gen�_domain�e�period�const�franger>r�r�rorp�solnsr�� singularities� include_x�discontinuities�critical_pointsr@�sifted� make_real�coeffI�check�im_sol�a�z�start�end� valid_start�valid_z�ptrT�sol_setsr��_validr�s*`` @rLr�r�sB �����r-�,�,�,�,�,� ����� � �E�)�)�!�*�."�##�##�$�$� $� �q�w� � � (� �c�e� �<�<�<�<H�L��<P�<P� � � '��!�!�#�&�&�B�� � � �D��G� ��u�$�$� �Z��#�?�r�r��)9�)9�$�)?�)?�?� � � %��E��.�.�.�� ��=�=�$���-�-�D�D��� � � ��J�(����� � ���� �B� �q�v�~�~� ��� ����� �Z��� �H�t�x� ���Q��$�$�� �Q�V� � ��1� � �A��I�I�a��O�O�E����������!�'�!�!��Z��� � �#�A�s�F�3�3�F��+�C��k�!�!��9�9�V�Z��+�+�$��B�B����6�:�q�1�1�$���B��� �#�#��9�9�V�Z��+�+�$��B�B����6�:�q�1�1�$���B��z�6�:��C��S�y�A�J�&�&�!�!�V�U�D�9�9�C�C�G�L�L�� �� �:��#�#�%�%�D�A�q� 8��a�n�,�,��Q�^�1D�1D�q�1H�1H�$�$� ��3��/�/���=�$�$�!��� 3�4� 8� 8� 8�*�*�6��)�)�C�����5�5�66�+7�+7�8�8�8� 8����$�A���J� A� A� A� A� A� A� A�6�M��V�D�#�&�&� >� >���$�$�W�Q��V�%<�%<�=�=�=�=�� D�*�:�s�F�C�C���t�{�*�B�t�{�d�/B�I� U�"%�f�o��f�j�&�*�5�5�'6�#7�#7��#,�e�m�.C�d�#�G%�G%�/%�#'�'3�|��V�Z����J�f�,�f�j��.F�H�H�(I�(I� ��<�<�O�<�<�<�<�<� 2�"�?�d�C�C�C�A�F�E�E�!�/�3O�3O�P�P�F��d�|�2�2�1�2� &�t� ���u�:�:��>�>�$*�5�M�M�E���$�2�2�2�1�1�2������&� U� U� U�)�*S�T�T�T� U���� ��I�$�*�*�1�?�;�;�;����F�F���"����"� ���f�5�5�A�%�a��2�2�3�!"�7�7�A� � �5�5�%�%��(�(�5�q�GY�5� &�)�A�,�,� 6���7�&'�U�A�E�s��!'��)�C�.�.�(H�!I�!I�&�&�A�*/�%��,�,�K�$��|�|�*/�%��(�(��%(���]�]��#%�]�#:�#:�r�?R�#:�W\�W\�]_�W`�W`�#:�'2�%J�w�%J�(.�(�5�!�2D�2D�(D���)4�%J�(.�(�.���2J�2J�(J���)0�%J�(.�(�.���2J�2J�(J���(.�(�-��q�2I�2I�(I��$%�E�E�!.�3�3�A�"�i��l�l�2�F�F���!�"�"�"��W�F�!�E�E�E�"�����Q�Z�'�'�$�Z�Z�!%� � �#�t� 4� 4� 4� 4�d�d�d� 1<�&=�&=�>�>�>� &�/�/��7�7� �� �|�H��J�E�����5�5��<�<��E�O����� �%� 0� 0�1�1�1�� � �����5��U�C���)�)�F��O�O�H�U�C��t�$D�$D�E�E�E�� �%�%�!�(�(��+�+�+�+��O�+�+�'�.�.�q�1�1�1�!&��q�����!*���6� ��� �!� � �5�5�5�����*�C��f�}�}���s���}�� �}���� �#���/�/�/��u�S���_�_�%�%� ;����� �e�S� 9� 9�:�:�:������E���*�*�7�3�3���!��H�%� �7�<�<�<@�D��d�O�O�� � ;�2�2�R�%5�%5�d�%;�%;�;sR� C8�8'D�!AL$�$AM6�,CT�*S/�.T�/T�T�T�/EZ5�5[�[c���|js|js ||zdz }n�|jr|jr tj}n�|jr|j�|jr|j�t d���|jr|js|jr |jr||}}|jr*|jr|dz}nM|jr|tjz}n6|dz}n0|jr)|jr|tjz}n|jr|dz}n|dz }|S)z$Return a point between start and endr,Nz,cannot proceed with unsigned infinite valuesr&)� is_infiniterrw�is_extended_positiver.�is_extended_negative�Half)r�r�r�s rLr�r��s8�� � ��S�_���c�k�1�_��� � ��s��� �V��� � � M�%�"<�"D���#E�$'�$<�$D��K�L�L� L� �O� $�� 8� $��!� $�&+�&@� $��e�3�E� �?� ��)� ��1�W����+� ��1�6�\����Q�Y��� � � ��'� ����Z����)� ���U����1�W�� �IrNc�t�ddlm}||jvr|S|j|kr|j}|j|kr||jjvr|Sd�}d}t j}|j|jz } t||��}|� ��dkr)|� |� ��d��}n!|s|� ��dkrt��nd#ttf$�rO|�s: t|gg|��}n #t$rt||��}YnwxYw||||��} | t jur3||||��t jur|�||kd��}|||| ��} | t jurP|||| ��t jur6|�| |kd��}|�|| kd��}|t jur=| t jur||kn||k}| t jurt'| |k|��}nt|��}YnwxYwg} |���|� ��} d} | �|d���\}}| |z} | |z} t+| ��}|�|d���\}} |jdks |j|jcxkr �nn|jd vr|} t j}| |z} |jr|� | | ��}n|j� | | ��}||j��||j��z}||��}||z D]v}t7t9|d��||� ��}t;|t8��r?|j|kr4||||j��t jur| �|���w| |fD]W}||||��t jur<||||��t jur#| �||ur||kn||k���X| �|��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) rr�c�� |�||��}|tjur|S|dvrdS|S#t$rtjcYSwxYw)N�TF)r�r�NaNr�)�ierTrnr�s rL�classifyz#_solve_inequality.<locals>.classifysc�� �����1� � �A��A�E�z�z����-�'�'����H��� � � ��5�L�L�L� ���s�%0�0�0�A �A Nr&T)�as_AddF)r%r$)�linear)r�r�r�rur;rtrr9r�degreer�r/r5rr�r�r1r3r�r�as_independentr�is_zero� is_negative� is_positivervrx�_solve_inequalityr r-r7)r�rTr�r�r�r��oor�rS�okoo�oknoor�r�ru�b�ax�efr��beginning_denoms�current_denomsrp�crns rLrr�s���T-�,�,�,�,�,������� � �v��{�{� �[�� �v��{�{�q��� 3�3�3�� � � � � �B� ��B� �6�B�F�?�D�� ��q�M�M�� �8�8�:�:��?�?���������a�(�(�B�B�� &�A�H�H�J�J��N�N�%� %��� �0� 1����� � 8�1�B�4�&�!�<�<����"� 8� 8� 8�0��Q�7�7���� 8�����8�B��2�&�&�D��q�v�~�~�(�(�2�q�"�"5�"5���"@�"@��W�W�Q��V�T�*�*���H�R��R�C�(�(�E�������H�R��R�C�(�(�A�G�3�3��W�W�b�S�1�W�d�+�+���W�W�Q�"��W�d�+�+���Q�V�|�|�"&�!�&�.�.�a�2�g�g�q�2�v�����&�&��b�S�1�W�b�)�)�B���T� � �A���+����. �E� �z� �I�I�K�K�� ��� � ��4� �0�0���2� �Q��� �q��� �!�_�_��� � ��5� �1�1���1� �I�� � �� �� �&�&�&�&�!%�&�&�&�&�� ��-�-��A���A� �q��� �=� *�����C���B�B���!�!�!�S�)�)�B�"�6�"�&�>�>�F�F�2�6�N�N�:��������!�N�2� %� %�A�!�"�Q��(�(�A�f�=�=�=�A��!�R� � � %�Q�U�a�Z�Z��8�B��1�5�)�)�Q�V�3�3��L�L�!��$�$�$���#�r�� :� :�A����Q��"�"�a�f�,�,��H�R��A�&�&�a�f�4�4�� � �a�2�g�g�Q��U�U�1�q�5�9�9�9�� �L�L����� ��;�s8� A2C�H5�*C=�<H5�=D�H5�D�DH5�4H5c ��� �ii}}g}|D�]�}|j|j}}|�t��}t |��dkr|���� n�|j|z} t | ��dkrG| ���� |�tt|d|��� ������ttd�����|� � ��r-|� � g���||f����|�� fd���} | rFtd�| D����r-|� � g���||f����u|�tt|d|��� �������d�|���D��} d�|���D��} t#| | z|z�S)Nr&rzZ inequality has more than one symbol of interest. c�d��|����o|jp|jo |jj Sr�)rl� is_Functionr�r�r�)�urqs �rLr�z&_reduce_inequalities.<locals>.<lambda>�s4������c� � �D�� �B���!B�!�%�2B�.B�rNc3�@K�|]}t|t��V��dSr�)r-r�rRrns rLr�z'_reduce_inequalities.<locals>.<genexpr>�s,����!I�!I��*�Q��"4�"4�!I�!I�!I�!I�!I�!IrNc�6�g|]\}}t|g|����SrQ)r��rRrqr�s rLrUz(_reduce_inequalities.<locals>.<listcomp>�s)��c�c�c�:�3��0�%��#�>�>�c�c�crNc�4�g|]\}}t||����SrQ)r�rs rLrUz(_reduce_inequalities.<locals>.<listcomp>�s'��Z�Z�Z�:�3��*�5�#�6�6�Z�Z�ZrN)rtrv�atomsr r��popr�r7rr r5r � is_polynomial� setdefault�findr��itemsr)r��symbols� poly_part�abs_part�other� inequalityr�r>�gens�common� components� poly_reduced� abs_reducedrqs @rL�_reduce_inequalitiesr$ts!����b�x�I� �E�"�O�O� ��N�J�$5�c�� �z�z�&�!�!�� �t�9�9��>�>��(�(�*�*�C�C��&��0�F��6�{�{�a����j�j�l�l��� � �.�z�$��3�/G�/G��M�M�N�N�N��)�*�6�+�+���� � � �c� "� "� O� � � ��b� )� )� 0� 0�$��� =� =� =� =����$D�$D�$D�$D�E�E�J�� O�c�!I�!I�j�!I�!I�!I�I�I� O��#�#�C��,�,�3�3�T�3�K�@�@�@�@�� � �.�z�$��3�/G�/G��M�M�N�N�N�N�c�c�QZ�Q`�Q`�Qb�Qb�c�c�c�L�Z�Z����IY�IY�Z�Z�Z�K� �� �+�e�3� 5�5rNc���t|��s|g}d�|D��}t��jd�|D���}t|��s|g}t|��p||z}td�|D����rt t d�����d�|D����fd�|D��}�fd�|D��}g}|D]�}t |t��rH|�|j � ��|j � ��z d��}n|d vrt|d��}|d kr�z|d krtjcS|j jrt!d |z���|�|����|}~t%||��}|�d �����D����S)aEReduce 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�,�g|]}t|����SrQrrs rLrUz'reduce_inequalities.<locals>.<listcomp>�s��5�5�5�1�G�A�J�J�5�5�5rNc��g|] }|j�� SrQ)r�rs rLrUz'reduce_inequalities.<locals>.<listcomp>�s��>�>�>�A���>�>�>rNc3�(K�|] }|jduV��dS)FNr�rs rLr�z&reduce_inequalities.<locals>.<genexpr>�s*���� 8� 8�1�1� �� &� 8� 8� 8� 8� 8� 8rNzP inequalities cannot contain symbols that are not real. c�J�i|] }|j� |t|jd�����!S)NTr�)r�r�namers rL� <dictcomp>z'reduce_inequalities.<locals>.<dictcomp>�s;��5�5�5� ��+�3���q�v�T�2�2�2�3�3�3rNc�:��g|]}|������SrQ�r��rRrn�recasts �rLrUz'reduce_inequalities.<locals>.<listcomp>�s%���=�=�=�1�A�J�J�v�&�&�=�=�=rNc�:��h|]}|������SrQr-r.s �rL� <setcomp>z&reduce_inequalities.<locals>.<setcomp>�s%���3�3�3�a�q�z�z�&�!�!�3�3�3rNrr�TFr"c��i|]\}}||�� SrQrQ)rR�kr�s rLr+z'reduce_inequalities.<locals>.<dictcomp>�s��8�8�8���A��1�8�8�8rN)rr�r\�anyr�r r-r r�rtr/rur rr3r0r5r7r$r�r)r�rr�keeprnr�r/s @rL�reduce_inequalitiesr6�s��� �L� !� !�&�$�~� �5�5� �5�5�5�L� �3�5�5�;�>�>��>�>�>� ?�D� �G� � ���)���7�|�|�#�t�t�+�G� � 8� 8�� 8� 8� 8�8�8��� �$����� � 5�5��5�5�5�F�=�=�=�=� �=�=�=�L�3�3�3�3�7�3�3�3�G� �D� � � �� �a�� $� $� ����q�u�}�}���������8�!�<�<�A�A� �m� #� #��1�a���A� ��9�9� � �%�Z�Z��7�N�N�N� �5�?� =�%�7�!�;�=�=� =� � � �A������L� � �l�G� 4� 4�B� �;�;�8�8������8�8�8� 9� 9�9rN)T)F)9�__doc__rY�sympy.calculus.utilrrr� sympy.corer�sympy.core.exprtoolsr�sympy.core.relationalr r r r �sympy.core.symbolr r�sympy.sets.setsrrrr�sympy.core.singletonr�sympy.core.functionr�$sympy.functions.elementary.complexesr� sympy.logicr� sympy.polysrrr�sympy.polys.polyutilsr�sympy.solvers.solvesetrr�sympy.utilities.iterablesrr�sympy.utilities.miscr rMrWrhr�r�r�r2r�r�rr$r6rQrNrL�<module>rGsx��B�B���������������������-�-�-�-�-�-�8�8�8�8�8�8�8�8�8�8�8�8�+�+�+�+�+�+�+�+�D�D�D�D�D�D�D�D�D�D�D�D�"�"�"�"�"�"�*�*�*�*�*�*�4�4�4�4�4�4�������F�F�F�F�F�F�F�F�F�F�(�(�(�(�(�(�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�+�+�+�+�+�+�X�X�X�vI�I�I�"?�?�?�DX�X�X�X�vD;�D;�D;�N"�"�"�27;�1�7�W\�d<�d<�d<�d<�N ���Bj�j�j�j�Z*6�*6�*6�Z/1�9:�9:�9:�9:�9:�9:rN
Memory