
    Ed?)                     |   d Z ddlmZ ddl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)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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 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mapleNautoT)order	full_prechumaninlineallow_unknown_functionsc                     |i }t                                          |           t          t                    | _        |                    di           }| j                            |           d S )Nuser_functions)super__init__dictknown_functionsgetupdate)selfsettings	userfuncs	__class__s      4lib/python3.11/site-packages/sympy/printing/maple.pyrx   zMapleCodePrinter.__init__c   si     	H"""#O44LL!1266	##I.....    c                     d|z  S )Nz%s; )r}   
codestrings     r   _get_statementzMapleCodePrinter._get_statementk   s    z!!r   c                 ,    d                     |          S )Nz# {})format)r}   texts     r   _get_commentzMapleCodePrinter._get_commentn   s    }}T"""r   c                 j    d                     ||                    | j        d                             S )Nz	{} := {};	precision)r   evalf	_settings)r}   namevalues      r   _declare_number_constz&MapleCodePrinter._declare_number_constq   s5    !!$$)KK{0K$L$LN N 	Nr   c                     |S Nr   )r}   liness     r   _format_codezMapleCodePrinter._format_codeu   s    r   c                 F    |                      t          |                    S r   _printlistr}   exprs     r   _print_tuplezMapleCodePrinter._print_tuplex       {{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    kk$(##kk$(##&&3C&888r   c                    t          |          }|j        dk    rd|                     |j        |          z  S |j        dt          j        fv rd|                     |j                  z  S |j        dt          j         fv rd|                     |j                  z  S d                    |                     |j        |          |                     |j        |                    S )	Nz1/%sg      ?zsqrt(%s)g      z
1/sqrt(%s)z{base}^{exp})baser   )r   r   parenthesizer   r   Halfr   r   )r}   r   kwargsPRECs       r   
_print_PowzMapleCodePrinter._print_Pow   s    $8r> 		7T..ty$??@@X#qv& 	7DI 6 666X$( 	7$++di"8"888!((&&ty$77%%dh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   TzAll 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 56TM"FGq}F\"ZQ!%Q  1 1 1bgbnbn++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    IbMd* 	021Cq}1T 	0  / 0 0 0
# # # # 		# # #

 99Z((&--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@    46{{CKK1#a&&CFF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   sw    $$TXt44$$TXt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                 6    |                      |j                  S r   )r   labelr   s     r   
_print_IdxzMapleCodePrinter._print_Idx   s    {{4:&&&r   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    *vv7*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    6TZ 	?5<<$*= = ? ?EE :@@[[//$*= 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[*V2DT$RRKK
++KK
++ 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`    di'?!;<< 	b;;u1$778889@@$++VZV_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MBD--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      8j8jY[9J9J2t9T9T8j8j8j8j8j8jr   )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
122JF 	lVq[ 	l88MMMMM*MMMMMM##f8j8j8j8j8j_i8j8j8j0j0j#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    &--DI0F0F$++VZV^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    $$)__
xxIIIIIjIIIIIIr   c                 J   |j         \  }\  }}|dk    r>d                    |                     |          |                     |                    }n)d                    |                     |                    }d                    |                     |          |          S )Nr   z{var}${order})varrp   z{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NT6Q; 	@)00T[[5F5F7;{{67J7J 1 L LKK "..T[[->->.??K-44t{{2Xc4dddr   r   )F)%__name__
__module____qualname____doc__printmethodlanguage_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  r  __classcell__)r   s   @r   rl   rl   T   s6         KH #' / / / / / /" " "# # #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   rl   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].

    )rl   doprint)r   	assign_tor~   s      r   
maple_coder*    s#    H H%%--dI>>>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   sympy.printing.codeprinterr   sympy.printing.precedencer   r   r   _known_func_same_namerz   _funcrg   Exp1rh   
EulerGammaGoldenRatior   r   ComplexInfinitynot_supported_symbolrl   r*  r-  r   r   r   <module>r9     s]          7 7 7 7 7 7 7 7 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"OE D$FHIyL'M* 
    le le le le le{ le le le^$? $? $? $?N( ( ( ( (r   