§
    OŠtjK)  ã                   ó€  — d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
mZ ddlZdZi dd	“d
d“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“d d!“d"d#“d$d%“d&d'“d(d)“d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8œ¥ZeD ]Zeee<   Œej        d9ej        d:ej        d;ej        d<ej        d=iZd>d?d@œZej        gZ G dA„ dBe¦  «        ZdEdC„ZdD„ ZdS )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ÚPizexp(1)ÚCatalanÚgammaz(1/2 + (1/2)*sqrt(5))ú=z<>)z==z!=c                   óþ   ‡ — e Zd ZdZdZdZddddœZ eej	        fi ddd	œ¤ŽZ	d(ˆ fd„	Z
d„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd)d„Zd „ Zd!„ Zd"„ Z d#„ Z!d$„ Z"d%„ Z#d&„ Z$d'„ Z%ˆ xZ&S )*ÚMapleCodePrinterzF
    Printer which converts a SymPy expression into a maple code.
    Ú_mapleÚmapleÚandÚorznot )rp   rq   ÚnotT)ÚinlineÚallow_unknown_functionsNc                 óä   •— |€i }t          ¦   «                              |¦  «         t          t          ¦  «        | _        |                     di ¦  «        }| j                             |¦  «         d S )NÚuser_functions)ÚsuperÚ__init__ÚdictÚknown_functionsÚgetÚupdate)ÚselfÚsettingsÚ	userfuncsÚ	__class__s      €úR/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/printing/maple.pyrx   zMapleCodePrinter.__init__f   sg   ø€ ØÐØˆHÝ‰Œ×Ò˜Ñ"Ô"Ð"Ý#¥OÑ4Ô4ˆÔØ—L’LÐ!1°2Ñ6Ô6ˆ	ØÔ×#Ò# IÑ.Ô.Ð.Ð.Ð.ó    c                 ó   — d|z  S )Nz%s;© )r}   Ú
codestrings     r�   Ú_get_statementzMapleCodePrinter._get_statementn   s   € Ø�zÑ!Ð!r‚   c                 ó,   — d                      |¦  «        S )Nz# {})Úformat)r}   Útexts     r�   Ú_get_commentzMapleCodePrinter._get_commentq   s   € Ø�}Š}˜TÑ"Ô"Ð"r‚   c                 ój   — d                      ||                     | j        d         ¦  «        ¦  «        S )Nz	{} := {};Ú	precision)rˆ   ÚevalfÚ	_settings)r}   ÚnameÚvalues      r�   Ú_declare_number_constz&MapleCodePrinter._declare_number_constt   s5   € Ø×!Ò! $Ø$)§K¢K°´¸{Ô0KÑ$LÔ$LñNô Nð 	Nr‚   c                 ó   — |S ©Nr„   )r}   Úliness     r�   Ú_format_codezMapleCodePrinter._format_codex   s   € Øˆr‚   c                 óF   — |                       t          |¦  «        ¦  «        S r“   ©Ú_printÚlist©r}   Úexprs     r�   Ú_print_tuplezMapleCodePrinter._print_tuple{   ó   € Ø�{Š{�4 ™:œ:Ñ&Ô&Ð&r‚   c                 óF   — |                       t          |¦  «        ¦  «        S r“   r—   rš   s     r�   Ú_print_TuplezMapleCodePrinter._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          |j        d¦  «        rd|                      |j        |¦  «        z  S t          |j        d¦  «        rd|                      |j        ¦  «        z  S t          |j        d¦  «        rd|                      |j        ¦  «        z  S d                     |                      |j        |¦  «        |                      |j        |¦  «        ¬¦  «        S )	Néÿÿÿÿz1/%sg      à?zsqrt(%s)g      à¿z
1/sqrt(%s)z{base}^{exp})Úbaser   )r   r   r   Úparenthesizer¦   r˜   rˆ   )r}   r›   ÚkwargsÚPRECs       r�   Ú
_print_PowzMapleCodePrinter._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                 ó  ‡ — |j         d         j        dur/|j         d         j        t          j        k    rt	          d¦  «        ‚ˆ fd„|j         D ¦   «         }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 | ]}\  }}|d urK|t           j        ur=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‘.”.ð coñ c"ô c"ð#ð #ð #r‚   z, zpiecewise({_inbrace}))Ú_inbrace)ÚargsÚcondr   r¯   Ú
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
          v rt
          |         }d                     |||¬¦  «        S )Nz{lhs} {rel_op} {rhs})r¡   Úrel_opr¢   )r   r§   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           |         S r“   )Únumber_symbolsrš   s     r�   Ú_print_NumberSymbolz$MapleCodePrinter._print_NumberSymbol±   s   € Ý˜dÔ#Ð#r‚   c                 ó   — dS )Nz	-infinityr„   rš   s     r�   Ú_print_NegativeInfinityz(MapleCodePrinter._print_NegativeInfinity´   ó   € Øˆ{r‚   c                 ó   — dS )NÚinfinityr„   rš   s     r�   Ú_print_Infinityz MapleCodePrinter._print_Infinity·   s   € Øˆzr‚   c                 ó   — dS )NÚtruer„   rš   s     r�   Ú_print_BooleanTruez#MapleCodePrinter._print_BooleanTrueº   s   € Øˆvr‚   c                 ó   — dS )NÚfalser„   rš   s     r�   Ú_print_BooleanFalsez$MapleCodePrinter._print_BooleanFalse½   s   € Øˆwr‚   c                 ó   — |rdndS )NrÐ   rÓ   r„   rš   s     r�   Ú_print_boolzMapleCodePrinter._print_boolÀ   s   € ØÐ*ˆvˆv 7Ð*r‚   c                 ó   — dS )NÚ	undefinedr„   rš   s     r�   Ú
_print_NaNzMapleCodePrinter._print_NaNÃ   rË   r‚   Fc                 óâ   — t           j        |j        v rd                     |rdnd¬¦  «        }n@d                     |                      |                     ¦   «         ¦  «        |rdnd¬¦  «        }|S )NzMatrix([], storage = {storage})ÚsparseÚrectangular)Ústoragez#Matrix({list}, storage = {storage}))r™   rÝ   )r   ÚZeroÚshaperˆ   r˜   Útolist)r}   r›   rÛ   Ú_strMs       r�   Ú_get_matrixzMapleCodePrinter._get_matrixÆ   s€   € ÝŒ6�T”ZÐÐØ5×<Ò<Ø$*Ð=˜˜°ð =ñ ?ô ?ˆEˆEð :×@Ò@Ø—[’[ §¢¡¤Ñ/Ô/Ø$*Ð=˜˜°ð Añ ?ô ?ˆEð ˆr‚   c                 óê   — d                      |                      |j        t          d         d¬¦  «        |                      |j        dz   ¦  «        |                      |j        dz   ¦  «        ¬¦  «        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          |j        t          t          f¦  «        r'|                      t          j        |¦  «        ¦  «        S d                     |                      |j        ¦  «        ¬¦  «        S )Nz$Matrix({var_size}, shape = identity))Úvar_size)Ú
isinstanceÚrowsr   r   r˜   Ú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          |d         t          j        t          j        t          j        t          j        f¦  «        s|d         |dd …         }}|�|dk    r"d 	                    ˆˆ fd„|D ¦   «         ¦  «        S d 
                    |d 	                    ˆˆ fd„|D ¦   «         ¦  «        ¬¦  «        S )Nr   ræ   ú.c              3   óD   •K  — | ]}‰                      |‰¦  «        V — Œd S r“   ©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}c              3   óD   •K  — | ]}‰                      |‰¦  «        V — Œd S r“   rý   rþ   s     €€r�   r   z1MapleCodePrinter._print_MatMul.<locals>.<genexpr>í   s4   øè è € Ð8jÐ8jÐY[¸×9JÒ9JÈ2ÈtÑ9TÔ9TÐ8jÐ8jÐ8jÐ8jÐ8jÐ8jr‚   )r­   Úm)r   r™   r³   rõ   r÷   Ú
MatrixBaseÚ
MatrixExprÚMatrixSliceÚMatrixSymbolr¶   rˆ   )r}   r›   Ú
_fact_listÚ_constr©   s   `   @r�   Ú_print_MatMulzMapleCodePrinter._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 )NzMatrixPower({A}, {n}))ÚAÚn)rˆ   r˜   r¦   r   rš   s     r�   Ú_print_MatPowzMapleCodePrinter._print_MatPowï   s9   € à&×-Ò-°·²¸D¼IÑ0FÔ0FÈ$Ï+Ê+ÐVZÔV^ÑJ_ÔJ_Ð-Ñ`Ô`Ð`r‚   c                 ó�   ‡ ‡— t          |¦  «        Št          |j        ¦  «        }d                     ˆˆ fd„|D ¦   «         ¦  «        S )NÚ*c              3   óD   •K  — | ]}‰                      |‰¦  «        V — Œd S r“   rý   rþ   s     €€r�   r   z:MapleCodePrinter._print_HadamardProduct.<locals>.<genexpr>ö   s3   øè è € ÐIÐI¸˜×)Ò)¨"¨dÑ3Ô3ÐIÐIÐIÐIÐIÐIr‚   )r   r™   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         \  }\  }}|dk    r>d                     |                      |¦  «        |                      |¦  «        ¬¦  «        }n)d                     |                      |¦  «        ¬¦  «        }d                     |                      |¦  «        |¬¦  «        S )Nræ   z{var}${order})ÚvarÚorderz{var})r  zdiff({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Ú
_operatorsry   r   Ú_default_settingsrx   r†   rŠ   r‘   r•   rœ   rŸ   r£   rª   r¸   r¾   rÅ   rÈ   rÊ   rÎ   rÑ   rÔ   rÖ   rÙ   râ   rì   rð   rò   rù   r	  r  r  r  Ú__classcell__)r€   s   @r�   rm   rm   T   sS  ø€ € € € € ðð ð €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ð er‚   rm   c                 óH   — t          |¦  «                             | |¦  «        S )aU  Converts ``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                 ó:   — t          t          | fi |¤Ž¦  «         dS )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.numbersr   r   r   Úsympy.printing.codeprinterr   Úsympy.printing.precedencer   r	   r÷   Ú_known_func_same_namerz   Ú_funcrh   ÚExp1ri   Ú
EulerGammaÚGoldenRatiorÇ   rÁ   ÚComplexInfinityÚnot_supported_symbolrm   r(  r+  r„   r‚   r�   ú<module>r7     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Ð*ð€ð Ø
ðð Ð ð ÔðÐ ðleð leð leð leð le�{ñ leô leð leð^$?ð $?ð $?ð $?ðN(ð (ð (ð (ð (r‚   