� ��g���ddlmZddlmZddlmZmZddlmZm Z ddl m Z ddl m Z mZddlmZed��d ���Zd �Zd S) �)�Mul)� count_ops)�preorder_traversal� bottom_up)�binomial� factorial)�gamma)� gammasimp� _gammasimp)�timethis�combsimpc���|�td���}td�t|��D����rt |��St |d���}t |��}|S)a� Simplify combinatorial expressions. Explanation =========== This function takes as input an expression containing factorials, binomials, Pochhammer symbol and other "combinatorial" functions, and tries to minimize the number of those functions and reduce the size of their arguments. The algorithm works by rewriting all combinatorial functions as gamma functions and applying gammasimp() except simplification steps that may make an integer argument non-integer. See docstring of gammasimp for more information. Then it rewrites expression in terms of factorials and binomials by rewriting gammas as factorials and converting (a+b)!/a!b! into binomials. If expression has gamma functions or combinatorial functions with non-integer argument, it is automatically passed to gammasimp. Examples ======== >>> from sympy.simplify import combsimp >>> from sympy import factorial, binomial, symbols >>> n, k = symbols('n k', integer = True) >>> combsimp(factorial(n)/factorial(n - 3)) n*(n - 2)*(n - 1) >>> combsimp(binomial(n+1, k+1)/binomial(n, k)) (n + 1)/(k + 1) F)� piecewisec3�fK�|],}t|t��o|jdj V��-dS)rN)� isinstancer �args� is_integer)�.0�nodes �g/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/simplify/combsimp.py� <genexpr>zcombsimp.<locals>.<genexpr>3sQ���� .� .� � �d�E� "� "� B�4�9�Q�<�+B�'B� .� .� .� .� .� .�T)�as_comb)�rewriter �anyrr r �_gamma_as_comb)�exprs rr r s���N �<�<���<� /� /�D� � .� .�&�t�,�,� .� .� .�.�.� ������ �d�d� +� +� +�D� �$� � �D� �Krc�\�|�t��}d�}t||��S)ze Helper function for combsimp. Rewrites expression in terms of factorials and binomials c �p� �|js|S|���� ggg}� D]�}t|t��r�� |jrt� |jr1|d�|jdg� |z��n1|d�|jdg� | z��d� |<��|dr|ds|Sd}td��D�]}d}|t||��kr�|||}t|dzt||����D]�}|||}||z} | |d|z vr|d}|d|z � | ��|||=|||=� t| t|��t|��kr|n|��xx|dkrdndz cc<n��|dz }|t||��k���|rBt� fd�� D��d�|dD��z�td �|dD���z S|S) Nr�F�T�����c�&��g|] }|�|z��S�r$)r�k�rvds �r� <listcomp>z-_gamma_as_comb.<locals>.f.<locals>.<listcomp>ms!���1�1�1��!�S��V�)�1�1�1rc�,�g|]}t|����Sr$�r�rr%s rr'z-_gamma_as_comb.<locals>.f.<locals>.<listcomp>ms.��5.�5.�5.��6?�q�\�\�5.�5.�5.rc�,�g|]}t|����Sr$r)r*s rr'z-_gamma_as_comb.<locals>.f.<locals>.<listcomp>ns/��6.�6.�6.��7@��l�l�6.�6.�6.r)�is_Mul�as_powers_dictrr� is_Integer� is_positive�extendr�range�len�removerrr) �rv� nd_fact_argsr%�hit�m�i�ai�j�aj�sumr&s @r�fz_gamma_as_comb.<locals>.fEs�����y� ��I����!�!���B�x� �� � �A��!�Y�'�'� �C��F�,=� ��q�6�%�@� ��O�*�*�A�F�1�I�;�s�1�v�+=�>�>�>�>� ��O�*�*�A�F�1�I�;��A��w�+>�?�?�?���A����A�� �l�1�o� ��I����q��� � �A��A��c�,�q�/�*�*�*�*�!�!�_�Q�'���q�1�u�c�,�q�/�&:�&:�;�;���A�%�a���+�B��r�'�C��l�1�q�5�1�1�1�"��$�Q��U�+�2�2�3�7�7�7�(��O�A�.�(��O�A�.��H�S� �"� � � )�"� � �1.�1.�"�"�35�7�7�8�8�8�&'�1�f�f���!�5�8�8�8���2���F�A�%�c�,�q�/�*�*�*�*��( � /��1�1�1�1�S�1�1�1�5.�5.�)�!�_�5.�5.�5.�.�0�03�6.�6.�)�!�_�6.�6.�6.�1/�/� /�� r)rrr)rr=s rrr<s7�� �<�<� � "� "�D�+�+�+�Z �T�1� � �rN)� sympy.corer�sympy.core.functionr�sympy.core.traversalrr�(sympy.functions.combinatorial.factorialsrr�sympy.functionsr �sympy.simplify.gammasimpr r �sympy.utilities.timeutilsr r rr$rr�<module>rEs���������)�)�)�)�)�)�>�>�>�>�>�>�>�>�H�H�H�H�H�H�H�H�!�!�!�!�!�!�:�:�:�:�:�:�:�:�.�.�.�.�.�.� ��*���-�-���-�`6�6�6�6�6r
Memory