� ��g3��^�dZddlmZddlmZefd�Zd�Zefd�Zd�Zd �Z d �Z efd �Z d �Z d S)zP Generic Rules for SymPy This file assumes knowledge of Basic and little else. �)�sift�)�newc������fd�}|S)a� Create a rule to remove identities. isid - fn :: x -> Bool --- whether or not this element is an identity. Examples ======== >>> from sympy.strategies import rm_id >>> from sympy import Basic, S >>> remove_zeros = rm_id(lambda x: x==0) >>> remove_zeros(Basic(S(1), S(0), S(2))) Basic(1, 2) >>> remove_zeros(Basic(S(0), S(0))) # If only identites then we keep one Basic(0) See Also: unpack c�@��tt�|j����}t|��dkr|St|��t |��kr+�|jgd�t |j|��D���R�S�|j|jd��S)z Remove identities rc��g|] \}}|�|�� S�r )�.0�arg�xs �c/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/strategies/rl.py� <listcomp>z/rm_id.<locals>.ident_remove.<locals>.<listcomp>$s!��H�H�H���a�a�H��H�H�H�)�list�map�args�sum�len� __class__�zip)�expr�ids�isidrs ��r � ident_removezrm_id.<locals>.ident_removes�����3�t�T�Y�'�'�(�(�� �s�8�8�q�=�=��K� ��X�X��S��� !� !��3�t�~�J�H�H�3�t�y�#�+>�+>�H�H�H�J�J�J� J��3�t�~�t�y��|�4�4� 4rr )rrrs`` r �rm_idr s*����& 5� 5� 5� 5� 5� 5� �rc��������fd�}|S)a6 Create a rule to conglomerate identical args. Examples ======== >>> from sympy.strategies import glom >>> from sympy import Add >>> from sympy.abc import x >>> key = lambda x: x.as_coeff_Mul()[1] >>> count = lambda x: x.as_coeff_Mul()[0] >>> combine = lambda cnt, arg: cnt * arg >>> rl = glom(key, count, combine) >>> rl(Add(x, -x, 3*x, 2, 3, evaluate=False)) 3*x + 5 Wait, how are key, count and combine supposed to work? >>> key(2*x) x >>> count(2*x) 2 >>> combine(2, x) 2*x c�0��t|j���}�fd�|���D��}�fd�|���D��}t|��t|j��krt t |��g|�R�S|S)z2 Conglomerate together identical args x + x -> 2x c �R��i|]#\}}|tt�|������$Sr )rr)r �kr�counts �r � <dictcomp>z.glom.<locals>.conglomerate.<locals>.<dictcomp>Is1���I�I�I�w�q�$�!�S��U�D�)�)�*�*�I�I�Irc�.��g|]\}}�||����Sr r )r �mat�cnt�combines �r rz.glom.<locals>.conglomerate.<locals>.<listcomp>Js)���D�D�D���c�7�7�3��$�$�D�D�Dr)rr�items�setr�type)r�groups�counts�newargsr%r �keys ���r � conglomeratezglom.<locals>.conglomerateFs�����d�i��%�%��I�I�I�I�&�,�,�.�.�I�I�I��D�D�D�D�V�\�\�^�^�D�D�D�� �w�<�<�3�t�y�>�>� )� )��t�D�z�z�,�G�,�,�,� ,��Krr )r,r r%r-s``` r �glomr.+s0�����6������� �rc������fd�}|S)z� Create a rule to sort by a key function. Examples ======== >>> from sympy.strategies import sort >>> from sympy import Basic, S >>> sort_rl = sort(str) >>> sort_rl(Basic(S(3), S(1), S(2))) Basic(1, 2, 3) c�H���|jgt|j�����R�S)N)r,)r�sortedr)rr,rs ��r �sort_rlzsort.<locals>.sort_rl`s,����s�4�>�?�F�4�9�#�$>�$>�$>�?�?�?�?rr )r,rr2s`` r �sortr3Ss-����@�@�@�@�@�@� �Nrc������fd�}|S)aW Turns an A containing Bs into a B of As where A, B are container types >>> from sympy.strategies import distribute >>> from sympy import Add, Mul, symbols >>> x, y = symbols('x,y') >>> dist = distribute(Mul, Add) >>> expr = Mul(2, x+y, evaluate=False) >>> expr 2*(x + y) >>> dist(expr) 2*x + 2*y c������t|j��D]^\}}t|���rI|jd|�|j||j|dzd�c�}�����fd�|jD���cS�_|S)Nrc�(��g|]}��|fz�z���Sr r )r r �A�first�tails ���r rz5distribute.<locals>.distribute_rl.<locals>.<listcomp>ys+���I�I�I�3�1�1�u��v�~��4�6�I�I�Ir)� enumerater� isinstance)r�ir �br8r9r7�Bs @@��r � distribute_rlz!distribute.<locals>.distribute_rlus�������� �*�*� K� K�F�A�s��#�q�!�!� K�!%��2�A�2��� �!� �d�i��A����>O���q�$��q�I�I�I�I�I�I�!�&�I�I�I�J�J�J�J� K�� rr )r7r>r?s`` r � distributer@es*���� ������ �rc������fd�}|S)z Replace expressions exactly c���|�kr�S|S)Nr )r�ar=s ��r �subs_rlzsubs.<locals>.subs_rl�s��� �1�9�9��H��Krr )rCr=rDs`` r �subsrE~s)���������� �Nrc�P�t|j��dkr |jdS|S)z� Rule to unpack singleton args >>> from sympy.strategies import unpack >>> from sympy import Basic, S >>> unpack(Basic(S(2))) 2 rr)rr�rs r �unpackrH�s(�� �4�9�~�~�����y��|��� rc��|j}g}|jD]=}|j|kr|�|j���(|�|���>||jg|�R�S)z9 Flatten T(a, b, T(c, d), T2(e)) to T(a, b, c, d, T2(e)) )rr�extend�append)rr�clsrr s r �flattenrM�sr�� �.�C� �D��y���� �=�C� � � �K�K��� !� !� !� !� �K�K�� � � � � �3�t�~� %�� %� %� %�%rc�r�|jr|S|jttt|j�����S)z� Rebuild a SymPy tree. Explanation =========== This function recursively calls constructors in the expression tree. This forces canonicalization and removes ugliness introduced by the use of Basic.__new__ )�is_Atom�funcrr�rebuildrrGs r rQrQ�s6�� �|�9�� ��t�y�$�s�7�D�I�6�6�7�7�8�8rN) �__doc__�sympy.utilities.iterablesr�utilrrr.r3r@rErHrMrQr rr �<module>rUs�����+�*�*�*�*�*������������B%�%�%�P�����$���2��� � � �� &� &� &� &� 9� 9� 9� 9� 9r
Memory