
    wg)                        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y)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 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_functionsc                     |i }t         |   |       t        t              | _        |j	                  di       }| j                  j                  |       y )Nuser_functions)super__init__dictknown_functionsgetupdate)selfsettings	userfuncs	__class__s      Y/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/printing/maple.pyrx   zMapleCodePrinter.__init__f   sM    H"#O4LL!126	##I.    c                     d|z  S )Nz%s; )r}   
codestrings     r   _get_statementzMapleCodePrinter._get_statementn   s    z!!r   c                 $    dj                  |      S )Nz# {})format)r}   texts     r   _get_commentzMapleCodePrinter._get_commentq   s    }}T""r   c                 ^    dj                  ||j                  | j                  d               S )Nz	{} := {};	precision)r   evalf	_settings)r}   namevalues      r   _declare_number_constz&MapleCodePrinter._declare_number_constt   s.    !!$$)KK{0K$LN 	Nr   c                     |S Nr   )r}   liness     r   _format_codezMapleCodePrinter._format_codex   s    r   c                 6    | j                  t        |            S r   _printlistr}   exprs     r   _print_tuplezMapleCodePrinter._print_tuple{       {{4:&&r   c                 6    | j                  t        |            S r   r   r   s     r   _print_TuplezMapleCodePrinter._print_Tuple~   r   r   c                     | j                  |j                        }| j                  |j                        }dj                  ||      S )Nz{lhs} := {rhs})lhsrhs)r   r   r   r   )r}   r   r   r   s       r   _print_Assignmentz"MapleCodePrinter._print_Assignment   s<    kk$((#kk$((#&&3C&88r   c                    t        |      }t        |j                  d      rd| j                  |j                  |      z  S t        |j                  d      rd| j                  |j                        z  S t        |j                  d      rd| j                  |j                        z  S dj                  | j                  |j                  |      | j                  |j                  |            S )	Nz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    $"%T..tyy$?@@$((C(DII 666$((D)$++dii"888!((&&tyy$7%%dhh5 ) 7 7r   c           
         |j                   d   j                  dur5|j                   d   j                  t        j                  k7  rt	        d      |j                   D cg c]m  \  }}|durC|t        j                  ur1dj                  | j                  |      | j                  |            n dj                  | j                  |            o }}}dj                  |      }d	j                  |
      S c c}}w )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.z{c}, {e})cez{e})r   z, zpiecewise({_inbrace}))_inbrace)argscondr   BooleanTrue
ValueErrorr   r   join)r}   r   r   r   
_coup_listr   s         r   _print_Piecewisez!MapleCodePrinter._print_Piecewise   s    IIbMd*21C1Cq}}1T  / 0 0 			# 1 56TMaq}}F\ Q!%Q  1bgbnbn++a. co c""#
 #
 99Z(&--x-@@#s    A2C8c                     t        |j                        t        |j                        }}dj                  t	        |      t	        |            S )Nz{p}/{q})pq)intr   r   r   str)r}   r   r   r   s       r   _print_Rationalz MapleCodePrinter._print_Rational   s9    466{CK1#a&CF33r   c                     t        |      }| j                  |j                  |      }| j                  |j                  |      }|j                  }|t
        v r	t
        |   }dj                  |||      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   sl    $$TXXt4$$TXXt4[[$$$R(B%,,"(,SSr   c                     t         |   S r   )number_symbolsr   s     r   _print_NumberSymbolz$MapleCodePrinter._print_NumberSymbol   s    d##r   c                      y)Nz	-infinityr   r   s     r   _print_NegativeInfinityz(MapleCodePrinter._print_NegativeInfinity       r   c                      y)Ninfinityr   r   s     r   _print_Infinityz MapleCodePrinter._print_Infinity   s    r   c                 8    | j                  |j                        S r   )r   labelr   s     r   
_print_IdxzMapleCodePrinter._print_Idx   s    {{4::&&r   c                      y)Ntruer   r   s     r   _print_BooleanTruez#MapleCodePrinter._print_BooleanTrue   s    r   c                      y)Nfalser   r   s     r   _print_BooleanFalsez$MapleCodePrinter._print_BooleanFalse   s    r   c                     |rdS dS )Nr   r   r   r   s     r   _print_boolzMapleCodePrinter._print_bool   s    v*7*r   c                      y)N	undefinedr   r   s     r   
_print_NaNzMapleCodePrinter._print_NaN   r   r   c                     t         j                  |j                  v rdj                  |rdnd      }|S dj                  | j	                  |j                               |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   sm    66TZZ5<<$* = ?E  :@@[[/$* A ?E r   c                     dj                  | j                  |j                  t        d   d      | j	                  |j
                  dz         | j	                  |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   s`    /66$$T[[*V2DT$RKK
+KK
+ 7 - 	-r   c                 (    | j                  |d      S )NFr   r   r   s     r   _print_MatrixBasez"MapleCodePrinter._print_MatrixBase   s    U33r   c                 (    | j                  |d      S )NTr   r   r   s     r   _print_SparseRepMatrixz'MapleCodePrinter._print_SparseRepMatrix   s    T22r   c                     t        |j                  t        t        f      r$| j	                  t        j                  |            S dj                  | j	                  |j                              S )Nz$Matrix({var_size}, shape = identity))var_size)
isinstancerowsr   r   r   sympySparseMatrixr   r   s     r   _print_Identityz MapleCodePrinter._print_Identity   sS    dii'?!;<;;u11$7889@@$++VZV_V_J`@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j                   fd|D              S dj                  |dj                   fd|D                    S )Nr   r   .c              3   B   K   | ]  }j                  |        y wr   r   .0_mr   r}   s     r   	<genexpr>z1MapleCodePrinter._print_MatMul.<locals>.<genexpr>   s     MBD--b$7M   z{c}*{m}c              3   B   K   | ]  }j                  |        y wr   r   r   s     r   r  z1MapleCodePrinter._print_MatMul.<locals>.<genexpr>   s     8jY[9J9J2t9T8jr  )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<L*/*;*;U=O=O*Q R!+A
12JF>Vq[88M*MMM##f8j_i8j0j#kkr   c                     dj                  | j                  |j                        | j                  |j                              S )NzMatrixPower({A}, {n}))An)r   r   r   r   r   s     r   _print_MatPowzMapleCodePrinter._print_MatPow   s5    &--DII0F$++VZV^V^J_-``r   c                 |     t        |      t        |j                        }dj                   fd|D              S )N*c              3   B   K   | ]  }j                  |        y wr   r   r   s     r   r  z:MapleCodePrinter._print_HadamardProduct.<locals>.<genexpr>   s     I))"d3Ir  )r   r   r   r   )r}   r   r	  r   s   `  @r   _print_HadamardProductz'MapleCodePrinter._print_HadamardProduct   s/    $$))_
xxIjIIIr   c                    |j                   \  }\  }}|dk7  r2dj                  | j                  |      | j                  |            }n!dj                  | j                  |            }dj                  | j                  |      |      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    !YYNT6Q;)00T[[5F7;{{67J 1 LK "..T[[->.?K-44t{{2Xc4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  r  __classcell__)r   s   @r   rm   rm   T   s     KH J [:: #'? 
/"#N''9
7A"4T$'+-43blaJ
er   rm   c                 8    t        |      j                  | |      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%--dI>>r   c                 .    t        t        | fi |       y)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>r9     s    E E 2 <  "	5" 
4" H	"
 H" H" H" H" H" Y" Y" Y" Y" Y" Y"  v!"" 
E#"$ 
E%"( $#C"H # #E"OE#
 DD$FFHIIyLL'MM* 
   oe{ oed$?N(r   