� ��g�)���dZddlmZddlmZmZmZddlmZddl m Z m Z ddl Z dZ idd �d d �d d �dd�dd�dd�dd�dd�dd�dd�dd�dd�d d!�d"d#�d$d%�d&d'�d(d)�d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8��Ze D]Zeee<�ejd9ejd:ejd;ejd<ejd=iZd>d?d@�ZejgZGdA�dBe��ZdEdC�ZdD�ZdS)Fa  Maple code printer The MapleCodePrinter converts single SymPy expressions into single Maple expressions, using the functions defined in the Maple objects where possible. FIXME: This module is still under actively developed. Some functions may be not completed. �)�S)�Integer�IntegerConstant� equal_valued)� CodePrinter)� precedence� PRECEDENCEN) �sin�cos�tan�sec�csc�cot�sinh�cosh�tanh�sech�csch�coth�exp�floor� factorial� bernoulli�euler� fibonacci�gcd�lcm� conjugate�Ci�Chi�Ei�Li�Si�Shi�erf�erfc�harmonic�LambertW�sqrt�Abs�abs�log�ln�asin�arcsin�acos�arccos�atan�arctan�asec�arcsec�acsc�arccsc�acot�arccot�asinh�arcsinh�acosh�arccosh�atanh�arctanh�asech�arcsech�acsch�arccsch�acoth�arccoth�ceiling�ceil�Max�max�Min�min�doublefactorial� pochhammer�BesselI�BesselJ�BesselK�BesselY�HankelH1�HankelH2�AiryAi�AiryBi�AppellF1�FresnelC�FresnelS�LerchPhi)� factorial2�RisingFactorial�besseli�besselj�besselk�bessely�hankelh1�hankelh2�airyai�airybi�appellf1�fresnelc�fresnels�lerchphi�Pizexp(1)�Catalan�gammaz(1/2 + (1/2)*sqrt(5))�=z<>)z==z!=c���eZdZdZdZdZdddd�Zeej fiddd ���Z d)�fd � Z d �Z d �Z d�Z d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd*d �Zd!�Zd"�Z d#�Z!d$�Z"d%�Z#d&�Z$d'�Z%d(�Z&�xZ'S)+�MapleCodePrinterzF Printer which converts a SymPy expression into a maple code. �_maple�maple�and�orznot )rprq�notT)�inline�allow_unknown_functionsNc����|�i}t���|��tt��|_|�di��}|j�|��dS)N�user_functions)�super�__init__�dict�known_functions�get�update)�self�settings� userfuncs� __class__s ��d/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/printing/maple.pyrxzMapleCodePrinter.__init__fsg��� � ��H� ������"�"�"�#�O�4�4����L�L�!1�2�6�6� � ��#�#�I�.�.�.�.�.�c� �d|zS)Nz%s;�)r}� codestrings r��_get_statementzMapleCodePrinter._get_statementns ���z�!�!r�c�,�d�|��S)Nz# {})�format)r}�texts r�� _get_commentzMapleCodePrinter._get_commentqs���}�}�T�"�"�"r�c�j�d�||�|jd����S)Nz {} := {};� precision)r��evalf� _settings)r}�name�values r��_declare_number_constz&MapleCodePrinter._declare_number_constts5���!�!�$�$)�K�K���{�0K�$L�$L�N�N� Nr�c��|S�Nr�)r}�liness r�� _format_codezMapleCodePrinter._format_codexs��� r�c�F�|�t|����Sr���_print�list�r}�exprs r�� _print_tuplezMapleCodePrinter._print_tuple{����{�{�4��:�:�&�&�&r�c�F�|�t|����Sr�r�r�s r�� _print_TuplezMapleCodePrinter._print_Tuple~r�r�c��|�|j��}|�|j��}d�||���S)Nz{lhs} := {rhs})�lhs�rhs)r�r�r�r�)r}r�r�r�s r��_print_Assignmentz"MapleCodePrinter._print_Assignment�sA���k�k�$�(�#�#���k�k�$�(�#�#���&�&�3�C�&�8�8�8r�c ���t|��}t|jd��rd|�|j|��zSt|jd��rd|�|j��zSt|jd��rd|�|j��zSd�|�|j|��|�|j|�����S) N�����z1/%sg�?zsqrt(%s)g�z 1/sqrt(%s)z {base}^{exp})�baser)rrr� parenthesizer�r�r�)r}r��kwargs�PRECs r�� _print_PowzMapleCodePrinter._print_Pow�s����$���� ���"� %� %� 7��T�.�.�t�y�$�?�?�@� @� �$�(�C� (� (� 7��� � �D�I� 6� 6�6� 6� �$�(�D� )� )� 7��$�+�+�d�i�"8�"8�8� 8�!�(�(��&�&�t�y�$�7�7��%�%�d�h��5�5�)�7�7� 7r�c���|jdjdur/|jdjtjkrt d����fd�|jD��}d�|��}d�|���S)Nr�Tz�All Piecewise expressions must contain an (expr, True) statement to be used as a default condition. Without one, the generated expression may not evaluate to anything under some condition.c���g|]}\}}|durK|tjur=d���|����|�����n(d���|�������~S)Tz{c}, {e})�c�ez{e})r�)r� BooleanTruer�r�)�.0r�r�r}s �r�� <listcomp>z5MapleCodePrinter._print_Piecewise.<locals>.<listcomp>�s����#�#�#���1�56�T�M�M�a�q�}�F\�F\�� � ����Q���!%���Q����1�1�1�bg�bn�bn��+�+�a�.�.�co�c"�c"�#�#�#r�z, zpiecewise({_inbrace}))�_inbrace)�args�condrr�� ValueError�joinr�)r}r�� _coup_listr�s` r��_print_Piecewisez!MapleCodePrinter._print_Piecewise�s���� �I�b�M� �d� *� *���2��1C�q�}�1T�1T��/�0�0� 0� #�#�#�#�� � #�#�#� � �9�9�Z�(�(��&�-�-�x�-�@�@�@r�c��t|j��t|j��}}d�t |��t |�����S)Nz{p}/{q})�p�q)�intr�r�r��str)r}r�r�r�s r��_print_Rationalz MapleCodePrinter._print_Rational�s@���4�6�{�{�C���K�K�1�����#�a�&�&�C��F�F��3�3�3r�c���t|��}|�|j|��}|�|j|��}|j}|t vr t |}d�|||���S)Nz{lhs} {rel_op} {rhs})r��rel_opr�)rr�r�r�r��spec_relational_opsr�)r}r�r��lhs_code�rhs_code�ops r��_print_Relationalz"MapleCodePrinter._print_Relational�su�� �� � ���$�$�T�X�t�4�4���$�$�T�X�t�4�4�� �[�� �$� $� $�$�R�(�B�%�,�,��"�(�,�S�S�Sr�c��t|Sr�)�number_symbolsr�s r��_print_NumberSymbolz$MapleCodePrinter._print_NumberSymbol�s ���d�#�#r�c��dS)Nz -infinityr�r�s r��_print_NegativeInfinityz(MapleCodePrinter._print_NegativeInfinity�����{r�c��dS)N�infinityr�r�s r��_print_Infinityz MapleCodePrinter._print_Infinity�s���zr�c�6�|�|j��Sr�)r��labelr�s r�� _print_IdxzMapleCodePrinter._print_Idx�s���{�{�4�:�&�&�&r�c��dS)N�truer�r�s r��_print_BooleanTruez#MapleCodePrinter._print_BooleanTrue�s���vr�c��dS)N�falser�r�s r��_print_BooleanFalsez$MapleCodePrinter._print_BooleanFalse�s���wr�c��|rdndS)Nr�r�r�r�s r�� _print_boolzMapleCodePrinter._print_bool�s���*�v�v�7�*r�c��dS)N� undefinedr�r�s r�� _print_NaNzMapleCodePrinter._print_NaN�r�r�Fc���tj|jvrd�|rdnd���}n@d�|�|�����|rdnd���}|S)NzMatrix([], storage = {storage})�sparse� rectangular)�storagez#Matrix({list}, storage = {storage}))r�r�)r�Zero�shaper�r��tolist)r}r�r��_strMs r�� _get_matrixzMapleCodePrinter._get_matrix�s��� �6�T�Z� � �5�<�<�$*�=��� �=�?�?�E�E�:�@�@��[�[������/�/�$*�=��� �A�?�?�E�� r�c���d�|�|jtdd���|�|jdz��|�|jdz�����S)Nz{parent}[{i_maple}, {j_maple}]�AtomT)�strict�)�parent�i_maple�j_maple)r�r�r�r r��i�jr�s r��_print_MatrixElementz%MapleCodePrinter._print_MatrixElement�sh��/�6�6��$�$�T�[�*�V�2D�T�$�R�R��K�K���� �+�+��K�K���� �+�+�7�-�-� -r�c�0�|�|d���S)NF�r��r�r�s r��_print_MatrixBasez"MapleCodePrinter._print_MatrixBase�s������U��3�3�3r�c�0�|�|d���S)NTr�r�r�s r��_print_SparseRepMatrixz'MapleCodePrinter._print_SparseRepMatrix�s������T��2�2�2r�c���t|jttf��r'|�t j|����Sd�|�|j�����S)Nz$Matrix({var_size}, shape = identity))�var_size)� isinstance�rowsrrr��sympy� SparseMatrixr�r�s r��_print_Identityz MapleCodePrinter._print_Identity�s`�� �d�i�'�?�!;� <� <� b��;�;�u�1�$�7�7�8�8� 8�9�@�@�$�+�+�VZ�V_�J`�J`�@�a�a� ar�c����t|���t|j��}d}t|dtjtjtjtjf��s|d|dd�}}|�|dkr"d� ��fd�|D����Sd� |d� ��fd�|D�������S)Nrr��.c3�D�K�|]}��|���V��dSr��r��r��_mr�r}s ��r�� <genexpr>z1MapleCodePrinter._print_MatMul.<locals>.<genexpr>�s3�����M�M�B�D�-�-�b�$�7�7�M�M�M�M�M�Mr�z{c}*{m}c3�D�K�|]}��|���V��dSr�rrs ��r�rz1MapleCodePrinter._print_MatMul.<locals>.<genexpr>�s4�����8j�8j�Y[��9J�9J�2�t�9T�9T�8j�8j�8j�8j�8j�8jr�)r��m) rr�r�r�r�� MatrixBase� MatrixExpr� MatrixSlice� MatrixSymbolr�r�)r}r�� _fact_list�_constr�s` @r�� _print_MatMulzMapleCodePrinter._print_MatMul�s����� �� � ���$�)�_�_� ����*�Q�-�%�*:�E�<L�*/�*;�U�=O�*Q�R�R� ?�!+�A�� �1�2�2��J�F� �>�V�q�[�[��8�8�M�M�M�M�M�*�M�M�M�M�M� M��#�#�f����8j�8j�8j�8j�8j�_i�8j�8j�8j�0j�0j�#�k�k� kr�c��d�|�|j��|�|j�����S)NzMatrixPower({A}, {n}))�A�n)r�r�r�rr�s r�� _print_MatPowzMapleCodePrinter._print_MatPow�s9��&�-�-�� � �D�I�0F�0F�$�+�+�VZ�V^�J_�J_�-�`�`�`r�c����t|���t|j��}d���fd�|D����S)N�*c3�D�K�|]}��|���V��dSr�rrs ��r�rz:MapleCodePrinter._print_HadamardProduct.<locals>.<genexpr>�s3�����I�I���)�)�"�d�3�3�I�I�I�I�I�Ir�)rr�r�r�)r}r�r r�s` @r��_print_HadamardProductz'MapleCodePrinter._print_HadamardProduct�sH�����$�����$�)�_�_� ��x�x�I�I�I�I�I�j�I�I�I�I�I�Ir�c�J�|j\}\}}|dkr>d�|�|��|�|�����}n)d�|�|�����}d�|�|��|���S)Nr�z {var}${order})�var�orderz{var})rzdiff({func_expr}, {sec_arg}))� func_expr�sec_arg)r�r�r�)r}r��_f�_var�_order� _second_args r��_print_Derivativez"MapleCodePrinter._print_Derivative�s���!�Y���N�T�6� �Q�;�;�)�0�0�T�[�[��5F�5F�7;�{�{�6�7J�7J�1�L�L�K�K�"�.�.�T�[�[��->�->�.�?�?�K�-�4�4�t�{�{�2���Xc�4�d�d�dr�r�)F)(�__name__� __module__� __qualname__�__doc__� printmethod�language� _operatorsryr�_default_settingsrxr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r rrr� __classcell__)r�s@r�rmrmTsb����������K��H������J� ��[�:����#'�?�?���� /�/�/�/�/�/�"�"�"�#�#�#�N�N�N����'�'�'�'�'�'�9�9�9� 7� 7� 7�A�A�A�"4�4�4�T�T�T�$�$�$�������'�'�'�������+�+�+��������-�-�-� 4�4�4�3�3�3�b�b�b� l� l� l�a�a�a�J�J�J� e�e�e�e�e�e�er�rmc �H�t|���||��S)aUConverts ``expr`` to a string of Maple code. Parameters ========== expr : Expr A SymPy expression to be converted. assign_to : optional When given, the argument is used as the name of the variable to which the expression is assigned. Can be a string, ``Symbol``, ``MatrixSymbol``, or ``Indexed`` type. This can be helpful for expressions that generate multi-line statements. precision : integer, optional The precision for numbers such as pi [default=16]. user_functions : dict, optional A dictionary where keys are ``FunctionClass`` instances and values are their string representations. Alternatively, the dictionary value can be a list of tuples i.e. [(argument_test, cfunction_string)]. See below for examples. human : bool, optional If True, the result is a single string that may contain some constant declarations for the number symbols. If False, the same information is returned in a tuple of (symbols_to_declare, not_supported_functions, code_text). [default=True]. contract: bool, optional If True, ``Indexed`` instances are assumed to obey tensor contraction rules and the corresponding nested loops over indices are generated. Setting contract=False will not generate loops, instead the user is responsible to provide values for the indices in the code. [default=True]. inline: bool, optional If True, we try to create single-statement code instead of multiple statements. [default=True]. )rm�doprint)r�� assign_tor~s r�� maple_coder+s#��H �H� %� %� -� -�d�I� >� >�>r�c �:�tt|fi|����dS)a&Prints the Maple representation of the given expression. See :func:`maple_code` for the meaning of the optional arguments. Examples ======== >>> from sympy import print_maple_code, symbols >>> x, y = symbols('x y') >>> print_maple_code(x, assign_to=y) y := x N)�printr+)r�r~s r��print_maple_coder.-s(�� �*�T� &� &�X� &� &�'�'�'�'�'r�r�)r"� sympy.corer�sympy.core.numbersrrr�sympy.printing.codeprinterr�sympy.printing.precedencerr r��_known_func_same_namerz�_funcrh�Exp1ri� EulerGamma� GoldenRatior�r��ComplexInfinity�not_supported_symbolrmr+r.r�r�r��<module>r:sc����������E�E�E�E�E�E�E�E�E�E�2�2�2�2�2�2�<�<�<�<�<�<�<�<� � � � ���"� �5�"� �4�"� �H� "�  �H� "�  �H� "� �H�"� �H�"� �H�"� �Y�"� �Y�"� �Y�"� �Y�"� �Y�"� �Y�"� �v�!"�" �E�#"�$ �E�%"�($�#�������������C"�"�"��H#�#�#�E�"�O�E����D�$��F�H��I�y��L�'��M�*� �� � ��������oe�oe�oe�oe�oe�{�oe�oe�oe�d$?�$?�$?�$?�N (� (� (� (� (r�
Memory