� ��g.a���dZddlmZddlmZddlmZddlmZddl m Z ddl m Z hd �Z d d d d �Z idd�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�d d!d"d#d#d$d%d&d'd(d)d*d+d,� �Zd-d.d-d/d0d0d1�Zd2�Zd3�ZGd4�d5e ��ZGd6�d7��ZGd8�d9e��ZejD]Zeed:eze���eD]Zeed:eze���d;�Zd<���Zd=�e���D��Zeefid>d?d@dAdBdCdDdEdFdGdHdIdJ� ��Zd-d.dKdLdMd0d/dNdO�ZdP�Z GdQ�dRe��Z!e!jD]Zee!d:eze���eD]Zee!d:eze���GdS�dTe��Z"dUS)Vzy Python code printers This module contains Python code printers for plain Python as well as NumPy & SciPy enabled code. �)� defaultdict)�chain)�S)�Mod�)� precedence)� CodePrinter>!�as�if�in�is�or�and�def�del�for�not�try�None�True�elif�else�from�pass�with�False�break�class�raise�while�yield�assert�except�global�import�lambda�return�finally�continue�nonlocal�abs�min�max)�Abs�Min�Max�acos�acosh�asin�asinh�atan�atan2�atanh�ceiling�ceil�cos�cosh�erf�erfc�exp�expm1� factorial�floor�gamma�hypot�isnan�lgamma�log�log10�log1p�log2�sin�sinh�sqrt�tan�tanh) rCrD�loggammarF�lnrGrHrIrJrK�SqrtrMrN�e�pi�inf�nan)�Exp1�Pi�E�Infinity�NaN�ComplexInfinityc�����j|jj}d���|��d��fd�|jD�������S)Nz{name}({args})�, c3�B�K�|]}��|��V��dS�N��_print��.0�arg�selfs ��e/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/printing/pycode.py� <genexpr>z$_print_known_func.<locals>.<genexpr>Fs/�����2Y�2Y��4�;�;�s�3C�3C�2Y�2Y�2Y�2Y�2Y�2Y�)�name�args)�known_functions� __class__�__name__�format�_module_format�joinrj�re�expr�knowns` rf�_print_known_funcrtCsk��� � ���!8� 9�E� � "� "��(;�(;�E�(B�(B�(,� � �2Y�2Y�2Y�2Y�t�y�2Y�2Y�2Y�(Z�(Z� #� \� \�\rhc�Z�|j|jj}|�|��Sr_)�known_constantsrlrmrorqs rf�_print_known_constrwIs(�� � ���!8� 9�E� � � �u� %� %�%rhc ���eZdZdZdZeZdZdZe e e � ��d�e � ��D������Zd�e� ��D��Zddd d �Ze ejid d d d d���Zd2�fd� Zd�Zd3d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!�fd�Z"d�Z#d �Z$d!�Z%d"�Z&d#�Z'd$�xZ(xZ)xZ*xZ+xZ,xZ-xZ.Z/d%�Z0d&�Z1d'�Z2d(�Z3d)�Z4d*�Z5d+�Z6d,�Z7d-�Z8d.�Z9d/�Z:d4d1�Z;�xZ<S)5�AbstractPythonCodePrinter� _pythoncode�PythonNz c�"�g|] \}}|d|zf�� S�zmath.��rc�k�vs rf� <listcomp>z$AbstractPythonCodePrinter.<listcomp>Vs%��D�D�D�d�a��!�W�q�[� �D�D�Drhc� �i|] \}}|d|z�� Sr}r~rs rf� <dictcomp>z$AbstractPythonCodePrinter.<dictcomp>Xs"�� B� B� B�D�A�q�1�g�a�i� B� B� Brhrrr)rrr�TF�python3)�user_functions� precision�inline�fully_qualified_modules�contract�standardc����t���|��|jd}|�#ddl}d�|jj��}|dkrtd���||_tt��|_ t|j fi|pi�di����|_t|jfi|pi�di����|_dS)Nr�rzpython{}r�zOnly Python 3 is supported.r��user_constants)�super�__init__� _settings�sysrn� version_info�major� ValueErrorr�r�set�module_imports�dict�_kf�getrk�_kcrv)re�settings�stdr�rls �rfr�z"AbstractPythonCodePrinter.__init__ds���� ������"�"�"��n�Z�(�� �;� �J�J�J��#�#�C�$4�$:�;�;�C� �)� � ��:�;�;� ;��� �)�#�.�.��� $�D�H� #� #���R�0D�0D� �b�1"�1"� #� #���#�D�H� #� #���R�0D�0D� �b�1"�1"� #� #����rhc��|�d|��S�Nz = r~)reri�values rf�_declare_number_constz/AbstractPythonCodePrinter._declare_number_constxs�� �D�D�%�%�(�(rhc��|�d��}|rTt|��dkrA|jd�|dd����|d��|jdr|S|�d��d�d��d�d��dS)N�.r�����r��(r�[)�split�lenr�rp�addr�)re�fqn�register�partss rfroz(AbstractPythonCodePrinter._module_format{s���� � �#���� � E��E� � �Q��� � �����s��s�� 4� 4� 5� 9� 9�%��)� D� D� D� �>�3� 4� B��J��9�9�S�>�>�!�$�*�*�3�/�/��2�8�8��=�=�b�A� Arhc��|Sr_r~)re�liness rf� _format_codez&AbstractPythonCodePrinter._format_code�s��� rhc�,�d�|��S)Nz{}�rn�re� codestrings rf�_get_statementz(AbstractPythonCodePrinter._get_statement�s���{�{�:�&�&�&rhc�,�d�|��S)Nz # {}r�)re�texts rf� _get_commentz&AbstractPythonCodePrinter._get_comment�s�����t�$�$�$rhc��t|��dkr|�|d��S|�|���d|�||dd����d|�|d���d�S)z� This method expands a fold on binary operations. ``functools.reduce`` is an example of a folded operation. For example, the expression `A + B + C + D` is folded into `((A + B) + C) + D` rrr�Nr�r]�))r�raro�_expand_fold_binary_op)re�oprjs rfr�z0AbstractPythonCodePrinter._expand_fold_binary_op�s��� �t�9�9��>�>��;�;�t�A�w�'�'� '��#�#�B�'�'�'�'��+�+�B��S�b�S� �:�:�:�:�� � �D��H�%�%�%�%�� rhc �.�t|��dkr|�|d��St|��}|dz}|�|���d|�|d|����d|�||d����d�S)z� This method expands a reductin on binary operations. Notice: this is NOT the same as ``functools.reduce``. For example, the expression `A + B + C + D` is reduced into: `(A + B) + (C + D)` rr�r�Nr]r�)r�raro�_expand_reduce_binary_op)rer�rj�N�Nhalfs rfr�z2AbstractPythonCodePrinter._expand_reduce_binary_op�s��� �t�9�9��>�>��;�;�t�A�w�'�'� '��D� � �A���F�E��#�#�B�'�'�'�'��-�-�d�6�E�6�l�;�;�;�;��-�-�d�5�6�6�l�;�;�;�;�� rhc��dS)Nz float('nan')r~�rerrs rf� _print_NaNz$AbstractPythonCodePrinter._print_NaN�����~rhc��dS)Nz float('inf')r~r�s rf�_print_Infinityz)AbstractPythonCodePrinter._print_Infinity�r�rhc��dS)Nz float('-inf')r~r�s rf�_print_NegativeInfinityz1AbstractPythonCodePrinter._print_NegativeInfinity�s���rhc�,�|�|��Sr_)r�r�s rf�_print_ComplexInfinityz0AbstractPythonCodePrinter._print_ComplexInfinity�s�����t�$�$�$rhc�\���t|���dj��fd�|jD���S)Nz{} % {}c3�D�K�|]}��|���V��dSr_)� parenthesize)rc�x�PRECres ��rfrgz7AbstractPythonCodePrinter._print_Mod.<locals>.<genexpr>�s3�����"Q�"Q�!�4�#4�#4�Q��#=�#=�"Q�"Q�"Q�"Q�"Q�"Qrh)rrnrj�rerrr�s` @rf� _print_Modz$AbstractPythonCodePrinter._print_Mod�s;�����$���� � � �"Q�"Q�"Q�"Q�"Q�t�y�"Q�"Q�"Q�R�Srhc��g}d}|jD]�}|j}|j}|dkr|�d��|�d��|�|�|����|�d��|�d��|�|�|����|�d��|dz }��|dd�}|ddkr |dd �}|�d��n|�d ��d �|��S) Nrr�r�z if z else rr�r�����z else None)�)rjrr�cond�appendrarp)rerr�result�irdrR�cs rf�_print_Piecewisez*AbstractPythonCodePrinter._print_Piecewise�s1���� ���9� � �C���A���A��A�v�v�� � �c�"�"�"� �M�M�#� � � � �M�M�$�+�+�a�.�.� )� )� )� �M�M�#� � � � �M�M�&� !� !� !� �M�M�$�+�+�a�.�.� )� )� )� �M�M�(� #� #� #� ��F�A�A������� �"�:�� � ��C�R�C�[�F� �M�M�#� � � � � �M�M�-� (� (� (��w�w�v���rhc� ��ddddddd�}|j|vrQ|�|j��}|�|j��}d�|j||� ��St ���|��S) z.Relational printer for Equality and Unequality�equal� not_equal�less� less_equal�greater� greater_equal)z==z!=�<z<=�>z>=z({lhs} {op} {rhs}))r��lhs�rhs)�rel_oprar�r�rnr��_print_Relational)rerrr�r�r�rls �rfr�z+AbstractPythonCodePrinter._print_Relational�s���������!�  � �� �;�"� � ��+�+�d�h�'�'�C��+�+�d�h�'�'�C�'�.�.�$�+�3�C�.�P�P� P��w�w�(�(��.�.�.rhc�^�ddlm}|�|�|����S)Nr)� Piecewise)�$sympy.functions.elementary.piecewiser�ra�rewrite)rerrr�s rf� _print_ITEz$AbstractPythonCodePrinter._print_ITE�s2��B�B�B�B�B�B��{�{�4�<�<� �2�2�3�3�3rhc����fd�|jD��}d���|j��d�|�����S)Nc3���K�|]Y\}}}d���|����|����|�����V��ZdS)zfor {i} in range({a}, {b}+1))r��a�bN)rnra)rcr�r�r�res �rfrgz7AbstractPythonCodePrinter._print_Sum.<locals>.<genexpr>�s{�����(�(� ��1�a� +� 1� 1��+�+�a�.�.��+�+�a�.�.��+�+�a�.�.� 2� "� "�(�(�(�(�(�(rhz"(builtins.sum({function} {loops}))� )�function�loops)�limitsrnrar�rp)rerrr�s` rf� _print_Sumz$AbstractPythonCodePrinter._print_Sum�sl���(�(�(�(�  �;� (�(�(�� 4�:�:��[�[���/�/��(�(�5�/�/�;�#�#� #rhc��dS)N�1jr~r�s rf�_print_ImaginaryUnitz.AbstractPythonCodePrinter._print_ImaginaryUnits���trhc��|j\}}d�|�|��|�|�����S)Nz(1 if {a} == {b} else 0))r�r�)rjrnra)rerrr�r�s rf�_print_KroneckerDeltaz/AbstractPythonCodePrinter._print_KroneckerDeltasD���y���1�)�0�0�� � �A���� � �A���1� � � rhc��|jj}|j�||��}|�d|�|������d�S)Nr�r�)rlrmrkr�ra�tolist)rerrri�funcs rf�_print_MatrixBasez+AbstractPythonCodePrinter._print_MatrixBasesM���~�&���#�'�'��d�3�3���4�4����T�[�[�]�]�!;�!;�!;�!;�<�<rhc�,�|�|��Sr_)r�r�s rf�<lambda>z"AbstractPythonCodePrinter.<lambda>s��4�1�1�$�7�7�rhc�l��d��fd�|�d��D����S)N� c�$��g|] }�j|z�� Sr~)�tab)rc�lineres �rfr�z@AbstractPythonCodePrinter._indent_codestring.<locals>.<listcomp>s���M�M�M�d�$�(�T�/�M�M�Mrh)rpr�r�s` rf�_indent_codestringz,AbstractPythonCodePrinter._indent_codestrings8����y�y�M�M�M�M�j�6F�6F�t�6L�6L�M�M�M�N�N�Nrhc���d��fd�|jD����}d���|j��d��fd�|jD������|�����S)Nrc3�B�K�|]}��|��V��dSr_r`rbs �rfrgzFAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<genexpr>"s/�����>�>�s�$�+�+�c�*�*�>�>�>�>�>�>rhz def {name}({parameters}): {body}r]c�D��g|]}��|j����Sr~)ra�symbol)rc�varres �rfr�zGAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<listcomp>%s'���!S�!S�!S�c�$�+�+�c�j�"9�"9�!S�!S�!Srh)ri� parameters�body)rpr rnrarir r)re�fdr s` rf�_print_FunctionDefinitionz3AbstractPythonCodePrinter._print_FunctionDefinition!s�����y�y�>�>�>�>�b�g�>�>�>�?�?��2�9�9����R�W�%�%��y�y�!S�!S�!S�!S�R�]�!S�!S�!S�T�T��(�(��.�.�:� � � rhc����d��fd�|jD����}d���|j����|�����S)Nrc3�B�K�|]}��|��V��dSr_r`rbs �rfrgz9AbstractPythonCodePrinter._print_While.<locals>.<genexpr>*s/�����?�?�s�$�+�+�c�*�*�?�?�?�?�?�?rhzwhile {cond}: {body})r�r )rpr rnra� conditionr)re�whlr s` rf� _print_Whilez&AbstractPythonCodePrinter._print_While)sj����y�y�?�?�?�?�c�h�?�?�?�@�@��&�-�-����S�]�+�+��(�(��.�.�.� � � rhc��|�|jj���d|�|jj����Sr�)ra�variabler r�)re�decls rf�_print_Declarationz,AbstractPythonCodePrinter._print_Declaration0s=�� �K�K�� �,� -� -� -� -� �K�K�� �+� ,� ,� ,� � rhc��dS)Nrr~)re�bts rf�_print_BreakTokenz+AbstractPythonCodePrinter._print_BreakToken6s���wrhc�D�|j\}d|�|��zS)Nz return %s�rjra)re�retrds rf� _print_Returnz'AbstractPythonCodePrinter._print_Return9s"���x����T�[�[��-�-�-�-rhc�D�|j\}d|�|��zS)Nzraise %sr)re�rsrds rf� _print_Raisez&AbstractPythonCodePrinter._print_Raise=s"���w����D�K�K��,�,�,�,rhc�D�|j\}d|�|��zS)NzRuntimeError(%s)r)re�re�messages rf�_print_RuntimeError_z.AbstractPythonCodePrinter._print_RuntimeError_As"���7���!�D�K�K��$8�$8�8�8rhc�.��d��fd�|jD����}ddlm}|j|kr.d���|j��|��}|jdkr |d��|j��zz }d|zS)Nr]c3�B�K�|]}��|��V��dSr_r`rbs �rfrgz9AbstractPythonCodePrinter._print_Print.<locals>.<genexpr>Fs/�����L�L�S�� � �C� 0� 0�L�L�L�L�L�Lrhr)�nonez{} % ({}), end=""z , file=%sz print(%s))rp� print_args�sympy.codegen.astr)� format_stringrnra�file)re�prntr*r)s` rf� _print_Printz&AbstractPythonCodePrinter._print_PrintEs�����Y�Y�L�L�L�L�D�O�L�L�L�M�M� �*�*�*�*�*�*� � �� %� %�,�3�3�� � �D�.�/�/����J� �9�� � � �+�� � �D�I�(>�(>�>� >�J��Z�'�'rhc���t|j��dkr|�d��St|j��dkr|�d��S|�|j��S)N�stdoutz sys.stdout�stderrz sys.stderr)�strrirora)re�strms rf� _print_Streamz'AbstractPythonCodePrinter._print_StreamQsd�� �t�y�>�>�X� %� %��&�&�|�4�4� 4� ���^�^�x� '� '��&�&�|�4�4� 4��;�;�t�y�)�)� )rhc��dS)Nrr~)rerds rf�_print_NoneTokenz*AbstractPythonCodePrinter._print_NoneTokenYs���vrh� math.sqrtc��t|��}|jtjkrH|sF|�|��}|�|j��}d�||���S|jr�|s�|j tjurY|�|��}|�tj ��}|�|j��}|�d|�d|�d�S|jtj urC|�tj ��}|� |j|d���}|�d|��S|� |j|d���}|� |j|d���} d�|| ��S) a�Printing helper function for ``Pow`` Notes ===== This preprocesses the ``sqrt`` as math formatter and prints division Examples ======== >>> from sympy import sqrt >>> from sympy.printing.pycode import PythonCodePrinter >>> from sympy.abc import x Python code printer automatically looks up ``math.sqrt``. >>> printer = PythonCodePrinter() >>> printer._hprint_Pow(sqrt(x), rational=True) 'x**(1/2)' >>> printer._hprint_Pow(sqrt(x), rational=False) 'math.sqrt(x)' >>> printer._hprint_Pow(1/sqrt(x), rational=True) 'x**(-1/2)' >>> printer._hprint_Pow(1/sqrt(x), rational=False) '1/math.sqrt(x)' >>> printer._hprint_Pow(1/x, rational=False) '1/x' >>> printer._hprint_Pow(1/x, rational=True) 'x**(-1)' Using sqrt from numpy or mpmath >>> printer._hprint_Pow(sqrt(x), sqrt='numpy.sqrt') 'numpy.sqrt(x)' >>> printer._hprint_Pow(sqrt(x), sqrt='mpmath.sqrt') 'mpmath.sqrt(x)' See Also ======== sympy.printing.str.StrPrinter._print_Pow z {func}({arg}))r�rd�/r�r�F��strictz{}**{}) rr>r�Halfrora�basern�is_commutative�One� NegativeOner�) rerr�rationalrLr�r�rd�num�base_str�exp_strs rf� _hprint_Powz%AbstractPythonCodePrinter._hprint_Pow\s|��V�$���� �8�q�v� � �h� ��&�&�t�,�,�D��+�+�d�i�(�(�C�"�)�)�t��)�=�=� =� � � &�x� &���y�A�F�"�"��*�*�4�0�0���k�k�!�%�(�(���k�k�$�)�,�,���-�-��-�-�s�-�-�-�-��x�1�=�(�(��k�k�!�%�(�(���'�'�� �4��'�F�F���~�~��~�~�%��$�$�T�Y��U�$�C�C���#�#�D�H�d�5�#�A�A�����x��1�1�1rhr_)T)Fr8)=rm� __module__� __qualname__� printmethod�language�_kw�reserved_words�modulesrr�r�_known_functions�items�_known_functions_mathr��_known_constants_mathr�� _operatorsr �_default_settingsr�r�ror�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��_print_SparseRepMatrix�_print_MutableSparseMatrix�_print_ImmutableSparseMatrix� _print_Matrix�_print_DenseMatrix�_print_MutableDenseMatrix�_print_ImmutableMatrix�_print_ImmutableDenseMatrixrrrrrrr"r&r/r5r7rF� __classcell__�rls@rfryryNsE��������K��H��N��G� �C� �$�u�u���� � �D�D�&;�&A�&A�&C�&C�D�D�D��� � �C� C� B�$9�$?�$?�$A�$A� B� B� B�C��d�5�9�9�J����%���� $�������#�#�#�#�#�#�()�)�)�B�B�B�B����'�'�'�%�%�%����.���2���������%�%�%�T�T�T����./�/�/�/�/� 4�4�4� #� #� #���� � � �=�=�=� 8�7�8��8�"�8�$�8� �8� � 8� "� 8� �#�O�O�O� � � � � � � � � � ���.�.�.�-�-�-�9�9�9� (� (� (�*�*�*����@2�@2�@2�@2�@2�@2�@2�@2rhryc�V�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z d �Z d �Z d �Z d �Zd S)� ArrayPrinterc�J�ddlm} ||��S#t$r|cYSwxYw)Nr)�convert_indexed_to_array)�4sympy.tensor.array.expressions.from_indexed_to_arrayra� Exception)re�indexedras rf� _arrayifyzArrayPrinter._arrayify�sN��a�a�a�a�a�a� �+�+�G�4�4� 4��� � � ��N�N�N� ���s � � "�"c��|���}d}d}d�|D��}g}|D]e}g} t|��D]<} ||vr| �||��n| �|��|dz }�=|�| ���fi} g} g} |D]e} | D][}|| vrt|��}|| |<n| |}||z }||vr|| vr| �|���F| �|���\|dz }�f|dd�}|| | fS)Nr�rc�8�i|]}|D]}|t|�����Sr~)r,)rcr��js rfr�z3ArrayPrinter._get_einsum_string.<locals>.<dictcomp>�s-�� ?� ?� ?�1�Q� ?� ?��Q��A��� ?� ?� ?� ?rhr�,r�)� _get_letter_generator_for_einsum�ranger��next)re�subranks�contraction_indices�letters�contraction_string�counter�d�indices�rank_arg�lindicesr��mapping� letters_free� letters_dumrh�ls rf�_get_einsum_stringzArrayPrinter._get_einsum_string�s����7�7�9�9������ ?� ?� 3� ?� ?� ?���� � %� %�H��H��8�_�_� � ���a�<�<��O�O�A�g�J�/�/�/�/��O�O�G�,�,�,��1� ��� �N�N�8� $� $� $� $���� �� �� &� &�A�� +� +���G�#�#��W� � �A�!"�G�A�J�J��� �A�"�a�'�"���6�6�� �+�+�#�*�*�1�-�-�-�� �'�'��*�*�*�*� �#� %� � �/����4��!�<��<�<rhc#�K�tdd��D]}t|��V��tdd��D]}t|��V��td���)N�a�{�A�[zout of letters)rk�chrr�)rer�s rfrjz-ArrayPrinter._get_letter_generator_for_einsum�se�����r�3��� � �A��a�&�&�L�L�L�L��r�2��� � �A��a�&�&�L�L�L�L��)�*�*�*rhc���������d��fd�|jD����}���jdz�jz���d|�dd��fd�|jD�����d�S) Nric�l��g|]0}d��fd�t|��D������1S)r�c�.��g|]}t�����Sr~)rl)rcrhros �rfr�zEArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>.<listcomp>�s���/P�/P�/P�!��W� � �/P�/P�/Prh)rprk)rcr�ros �rfr�z:ArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>�sA���&i�&i�&i�VW�r�w�w�/P�/P�/P�/P�u�Q�x�x�/P�/P�/P�'Q�'Q�&i�&i�&irhr��("�", r]c�:��g|]}��|����Sr~r`rbs �rfr�z:ArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>�s%���A�A�A��4�;�;�s�+�+�A�A�Arhr�)rjrprmro�_module�_einsumrj)rerrrpros` @rf�_print_ArrayTensorProductz&ArrayPrinter._print_ArrayTensorProduct�s������7�7�9�9�� �X�X�&i�&i�&i�&i�[_�[h�&i�&i�&i�j�j���#�#�D�L�3�$6���$E�F�F�F�F�"�"�"�� � �A�A�A�A�t�y�A�A�A�B�B�B�B� � rhc ���ddlm}|j}|j}t ||��r.d��fd�|jD����}|j}n*��|��}t|j ��g}�� ||��\}}} |s��|��St ||��r'd��fd�|jD����}n��|��}�� �j dz�jz���dd�|d �t!|�������d |�d �S) Nr��ArrayTensorProductric�@��g|]}d��|��z��S�z%sr`rbs �rfr�z8ArrayPrinter._print_ArrayContraction.<locals>.<listcomp>��*���M�M�M�C�d�d�k�k�#�&6�&6�7�M�M�Mrhc�@��g|]}d��|��z��Sr�r`rbs �rfr�z8ArrayPrinter._print_ArrayContraction.<locals>.<listcomp>�r�rhr�r��{}->{}r�r�r�)�0sympy.tensor.array.expressions.array_expressionsr�rrrn� isinstancerprjrmrar��shaperzror�r�rn�sorted) rerrr�r>rn�elems�ranksrprwrxs ` rf�_print_ArrayContractionz$ArrayPrinter._print_ArrayContraction�ss���W�W�W�W�W�W��y��"�6�� �d�.� /� /� &��H�H�M�M�M�M�4�9�M�M�M�N�N�E��M�E�E��K�K��%�%�E����_�_�%�E�8<�8O�8O�PU�Wj�8k�8k�5��L�+�"� %��;�;�t�$�$� $� �d�.� /� /� &��H�H�M�M�M�M�4�9�M�M�M�N�N�E�E��K�K��%�%�E� � � �� �s� 2�T�\� A� B� B� B� B� �O�O�.�����|�8L�8L�0M�0M� N� N� N� N� �E�E� � rhc ����ddlm}t|j��}t |j|��r|jj}|jj}n|j}|jg}��||��\}}}�fd�|D��}�� �j dz�j z���dd� |d� ||z�����dd � |���d �S) Nrr�c�:��g|]}��|����Sr~r`)rcr�res �rfr�z5ArrayPrinter._print_ArrayDiagonal.<locals>.<listcomp>�s#���/�/�/�A����Q���/�/�/rhr�r�r�r�r�r]r�)r�r��list�diagonal_indicesr�rrrmrjrzror�r�rnrp) rerrr�r�rmr��diagonal_stringrwrxs ` rf�_print_ArrayDiagonalz!ArrayPrinter._print_ArrayDiagonal�s���W�W�W�W�W�W��� 5�6�6�� �d�i�!3� 4� 4� ��y�)�H��I�N�E�E��}�H��Y�K�E�59�5L�5L�X�Wg�5h�5h�2���{�/�/�/�/��/�/�/�� � � �� �s� 2�T�\� A� B� B� B� B� �O�O�O�R�W�W�\�+�5M�-N�-N� O� O� O� O� �I�I�e� � � � � � rhc���|�|jdz|jz���d|�|j���d|�|jj���d�S)Nr�r�r]r�)ror�� _transposerarr� permutation� array_formr�s rf�_print_PermuteDimszArrayPrinter._print_PermuteDimssc�� � � �� �s� 2�T�_� D� E� E� E� E� �K�K�� � "� "� "� "� �K�K��(�3� 4� 4� 4� 4� � rhc�X�|�|jdz|jz|j��S)Nr�)r�r��_addrjr�s rf�_print_ArrayAddzArrayPrinter._print_ArrayAdd s(���*�*�4�<�#�+=�� �+I�4�9�U�U�Urhc��|�|jdz|jz���dd�t |j|j�����d�S�Nr�z((riz,)))ror��_onesrp�maprarjr�s rf�_print_OneArrayzArrayPrinter._print_OneArraysT�� � � �� �c� 1�D�J� >� ?� ?� ?� ?� �H�H�S���T�Y�/�/� 0� 0� 0� 0� � rhc��|�|jdz|jz���dd�t |j|j�����d�Sr�)ror��_zerosrpr�rarjr�s rf�_print_ZeroArrayzArrayPrinter._print_ZeroArraysT�� � � �� �c� 1�D�K� ?� @� @� @� @� �H�H�S���T�Y�/�/� 0� 0� 0� 0� � rhc���|�|�|j����}|�|�|j����}|�d|��Sr�)rarer�r�)rerrr�r�s rf�_print_AssignmentzArrayPrinter._print_AssignmentsS���k�k�$�.�.���2�2�3�3���k�k�$�.�.���2�2�3�3�� �S�S�#�#�'�'rhc�,�|�|��Sr_)�_print_ArraySymbolr�s rf�_print_IndexedBasezArrayPrinter._print_IndexedBase#s���&�&�t�,�,�,rhN)rmrGrHrerzrjr�r�r�r�r�r�r�r�r�r~rhrfr_r_�s����������!=�!=�!=�F+�+�+� � � � � � �4 � � �" � � �V�V�V� � � �  � � � (�(�(�-�-�-�-�-rhr_c���eZdZd�Zd�Zd�Zd�Zd d�Zd�Zd�Z d �Z �fd �Z e j Ze j Ze j Ze j Z�xZS) �PythonCodePrinterc��d�|�d��|�|jd�����S)Nz"(0.0 if {e} == 0 else {f}(1, {e}))z math.copysignr)�frR�rnrorarj�rerRs rf� _print_signzPythonCodePrinter._print_sign)sG��3�:�:��!�!�/�2�2�d�k�k�!�&��)�6L�6L�;�N�N� Nrhc�~�t|��}|jd|�|jd|��zS)Nrr)rrRr�rjr�s rf� _print_NotzPythonCodePrinter._print_Not-s7���$������u�%��(9�(9�$�)�A�,��(M�(M�M�Mrhc��|jSr_)rir�s rfr�z$PythonCodePrinter._print_IndexedBase1s ���y�rhc����|jd}|jdd�}d�t|��d��fd�|D������S)Nrrz{}[{}]r]c�:��g|]}��|����Sr~r`)rc�indres �rfr�z4PythonCodePrinter._print_Indexed.<locals>.<listcomp>7s%���4W�4W�4W�#�T�[�[��5E�5E�4W�4W�4Wrh)rjrnr3rp)rerrr>�indexs` rf�_print_Indexedz PythonCodePrinter._print_Indexed4sY����y��|��� �!�"�"� �����s�4�y�y�$�)�)�4W�4W�4W�4W�QV�4W�4W�4W�*X�*X�Y�Y�YrhFc�0�|�||���S)N)rB�rF�rerrrBs rf� _print_PowzPythonCodePrinter._print_Pow9s������x��8�8�8rhc�B�d�|j|j��S)Nz{}/{})rn�p�qr�s rf�_print_Rationalz!PythonCodePrinter._print_Rational<s���~�~�d�f�d�f�-�-�-rhc�,�|�|��Sr_�r�r�s rf� _print_HalfzPythonCodePrinter._print_Half?s���#�#�D�)�)�)rhc�^�|�t|jdd����S)Nrr)r�rrjr�s rf� _print_fraczPythonCodePrinter._print_fracBs$�����s�4�9�Q�<��3�3�4�4�4rhc�:��t���|��}||jvrA|jdr$d}t |�|�����||jdzSd|vr*|�dd���dd��S|S)N�error_on_reservedzVThis expression includes the symbol "{}" which is a reserved keyword in this language.�reserved_word_suffix�{r��})r�� _print_SymbolrLr�r�rn�replace)rerrri�msgrls �rfr�zPythonCodePrinter._print_SymbolEs�����w�w�$�$�T�*�*�� �4�&� &� &��~�1�2� 3�<�� ����D�!1�!1�2�2�2��$�.�)?�@�@� @� �D�[�[��<�<��R�(�(�0�0��b�9�9� 9��Krh�F)rmrGrHr�r�r�r�r�r�r�r�r�r �_print_not_supported�_print_lowergamma�_print_uppergamma�_print_fresnelc�_print_fresnelsr\r]s@rfr�r�'s��������N�N�N�N�N�N����Z�Z�Z� 9�9�9�9�.�.�.�*�*�*�5�5�5� � � � � �$�8��#�8��!�6�O�!�6�O�O�O�O�Orhr�z _print_%sc �F�t|���|��S)a) Converts an expr to a string of Python code Parameters ========== expr : Expr A SymPy expression. fully_qualified_modules : bool Whether or not to write out full module names of functions (``math.sin`` vs. ``sin``). default: ``True``. standard : str or None, optional Only 'python3' (default) is supported. This parameter may be removed in the future. Examples ======== >>> from sympy import pycode, tan, Symbol >>> pycode(tan(Symbol('x')) + 1) 'math.tan(x) + 1' )r��doprint)rrr�s rf�pycoder�as ��. �X� &� &� .� .�t� 4� 4�4rhz log1p log2c�.�g|]\}}|tv�||f��Sr~)�_not_in_mpmathrs rfr�r�|s*�� Z� Z� Z���A�!�>�BY�BY�q�!�f�BY�BY�BYrh�beta�frac�fresnelc�fresnels�signrO�hyper�meijerg�besselj�bessely�besseli�besselk) r�r�r�r�r�rOr�r�r�r�r�r��phi�euler�catalan�ninf)rVrW� GoldenRatio� EulerGamma�CatalanrZrY�NegativeInfinityc���g}g}|jD]W}t|��dkr|\}}}ntd���|�|��|�||f���X||fS)z� helper function for _print_Integral that - accepts an Integral expression - returns a tuple of - a list variables of integration - a list of tuples of the upper and lower limits of integration �z%Only definite integrals are supported)r�r��NotImplementedErrorr�)� integral_expr�integration_varsr��integration_range�integration_var� lower_limit� upper_limits rf�_unpack_integral_limitsr��s����� �F�*�1�2�2�� � � !� !�Q� &� &�8I� 5�O�[�+�+�%�&M�N�N� N�����0�0�0�� � �{�K�0�1�1�1�1� �V� #�#rhc��eZdZdZdZdZeee� ��d�e � ��D������Z d�e � ��D��Z d�Zd�Zd�Zd �Zd �Zd �Zd �Zdd�Zd�ZdS)� MpmathPrinterzH Lambda printer for mpmath which maintains precision for floats � _mpmathcodezPython with mpmathc�"�g|] \}}|d|zf�� S�zmpmath.r~rs rfr�zMpmathPrinter.<listcomp>�s%��H�H�H���1�!�Y��]� �H�H�Hrhc� �i|] \}}|d|z�� Srr~rs rfr�zMpmathPrinter.<dictcomp>�s"�� F� F� F�d�a��1�i��k� F� F� Frhc��tttt|j������}d�|�d��|���S)Nz{func}({args})� mpmath.mpf)r�rj)r3�tupler��int�_mpf_rnro)rerRrjs rf� _print_FloatzMpmathPrinter._print_Float�sM�� �5��S�!�'�*�*�+�+�,�,���&�&�D�,?�,?� �,M�,M�TX�&�Y�Y�Yrhc��d�|�d��|�|j��|�|j�����S)Nz{func}({p})/{func}({q})r)r�r�r�)rnrorar�r�r�s rfr�zMpmathPrinter._print_Rational�sR��(�/�/��$�$�\�2�2��k�k�!�#����k�k�!�#���0� � � rhc�,�|�|��Sr_r�r�s rfr�zMpmathPrinter._print_Half�s���#�#�A�&�&�&rhc���d�|�d��|�|jd��|�|jd��|�d����S)Nz{}({}, {}, {})�mpmath.gammaincrrz mpmath.infr�r�s rfr�zMpmathPrinter._print_uppergamma�sg���&�&� � � � 1� 2� 2� �K�K���q� � "� "� �K�K���q� � "� "� � � � � -� -� /�/� /rhc���d�|�d��|�|jd��|�|jd����S)Nz {}({}, 0, {})rrrr�r�s rfr�zMpmathPrinter._print_lowergamma�sV���%�%� � � � 1� 2� 2� �K�K���q� � "� "� �K�K���q� � "� "�$�$� $rhc��d�|�d��|�|jd����S)Nz{0}({1})/{0}(2)z mpmath.logrr�r�s rf� _print_log2zMpmathPrinter._print_log2�sB�� �'�'� � � � � -� -�t�{�{�1�6�!�9�/E�/E�G�G� Grhc��d�|�d��|�|jd����S)Nz{}({})z mpmath.log1prr�r�s rf� _print_log1pzMpmathPrinter._print_log1p�s@����� � � �� /� /����Q�V�A�Y�1G�1G�I�I� IrhFc�2�|�||d���S)Nz mpmath.sqrt�rBrLr�r�s rfr�zMpmathPrinter._print_Pow�s������x�m��L�L�Lrhc �D��t|��\}}d���d��d�t �j|������|jd��d��fd�|D������S)Nz{}(lambda {}: {}, {})z mpmath.quadr]rc3�b�K�|])}dtt�j|����zV��*dS)z(%s, %s)N)rr�ra)rcryres �rfrgz0MpmathPrinter._print_Integral.<locals>.<genexpr>�s<�����R�R�a�*�u�S���a�-@�-@�'A�'A�A�R�R�R�R�R�Rrh)r�rnrorpr�rarj)rerRr�r�s` rf�_print_IntegralzMpmathPrinter._print_Integral�s����#:�1�#=�#=� ��&�&�-�-��#�#�M�2�2�� � �#�d�k�+;�<�<�=�=�� � �A�F�1�I�&�&�� � �R�R�R�R�6�R�R�R�R�R� T�T� TrhNr�)rmrGrH�__doc__rIrJr�rrNrO�_known_functions_mpmathr��_known_constants_mpmathr�r r�r�r�r�rrr�rr~rhrfrr�s7�������� �K�#�H� �$�u�u���� � �H�H�(?�(E�(E�(G�(G�H�H�H��� � �C� G� F�&=�&C�&C�&E�&E� F� F� F�C�Z�Z�Z� � � �'�'�'�/�/�/�$�$�$� G�G�G�I�I�I�M�M�M�M�T�T�T�T�Trhrc�D�eZdZdZeejd���Zd�Zdd�ZdS)� SymPyPrinterzPython with SymPyFr;c����|jjpd}��||rdndz|jjz���dd��fd�|jD�����d�S)Nr�r�r�r]c3�B�K�|]}��|��V��dSr_r`rbs �rfrgz/SymPyPrinter._print_Function.<locals>.<genexpr>s/�����%L�%L�3�d�k�k�#�&6�&6�%L�%L�%L�%L�%L�%Lrhr�)r�rGrormrprj)rerr�mods` rf�_print_FunctionzSymPyPrinter._print_Function�sy����i�"�(�b���.�.�s�S�6H�c�c�b�/I�D�I�L^�/^�_�_�_�_��9�9�%L�%L�%L�%L�$�)�%L�%L�%L�M�M�M�M�O� Orhc�2�|�||d���S)Nz sympy.sqrtrr�r�s rfr�zSymPyPrinter._print_Pows������x�l��K�K�KrhNr�) rmrGrHrJr�ryrSr"r�r~rhrfrr�se������"�H���!�3������ O�O�O� L�L�L�L�L�LrhrN)#r� collectionsr� itertoolsr� sympy.corer�sympy.core.modrr� codeprinterr rKrNrPrQrtrwryr_r�r�r��setattrr�r�r�rO� _in_mpmathr�rrr�rrr~rhrf�<module>r+s~���� $�#�#�#�#�#�������������������"�"�"�"�"�"�$�$�$�$�$�$����� � � ���� � �F�� �W�� �F�� �W� �  �F� �  �W� � �W���v�� �5�� �F�� �5�� �F�� �5�� �W�����  �W�!�" �W�#�$� �� � � � � � � � � � �=����D � � �� �� ���\�\�\� &�&�&� N2�N2�N2�N2�N2� �N2�N2�N2�b E-�E-�E-�E-�E-�E-�E-�E-�P07�07�07�07�07�1�07�07�07�f � �C�C�A� �G� �{�Q��0A�B�B�B�B� �D�D�A� �G� �{�Q��0B�C�C�C�C�5�5�5�4�#�#�%�%�� Z� Z�!6�!<�!<�!>�!>� Z� Z� Z� ��$�z� � � � ��� �� ������ .� .� � �� � ���� ��� � ��$�$�$�&AT�AT�AT�AT�AT�%�AT�AT�AT�H � �?�?�A� �G�M�;��?�,=�>�>�>�>� �@�@�A� �G�M�;��?�,>�?�?�?�?�L�L�L�L�L�,�L�L�L�L�Lrh
Memory