
    \hK)                        S r SSKJr  SSKJrJrJr  SSKJr  SSK	J
r
Jr  SSKrSr0 SS	_S
S_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S!_S"S#_S$S%_S&S'_S(S)_S*S+S,S-S.S/S0S1S2S3S4S5S6S7S8.Er\ H  r\\\'   M
     \R                   S9\R"                  S:\R$                  S;\R&                  S<\R(                  S=0rS>S?S@.r\R.                  /r " SA SB\5      rSESC jrSD rg)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                     ^  \ rS rSrSrSrSrSSSS.r\" \	R                  40 S	S	S
.D6r
S(U 4S jjrS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS)S jrS rS  r S! r!S" r"S# r#S$ r$S% r%S& r&S'r'U =r($ )*MapleCodePrinterT   z>
Printer which converts a SymPy expression into a maple code.
_maplemapleandorznot )rq   rr   notT)inlineallow_unknown_functionsc                    > Uc  0 n[         TU ]  U5        [        [        5      U l        UR	                  S0 5      nU R                  R                  U5        g )Nuser_functions)super__init__dictknown_functionsgetupdate)selfsettings	userfuncs	__class__s      L/var/www/auris/envauris/lib/python3.13/site-packages/sympy/printing/maple.pyry   MapleCodePrinter.__init__f   sM    H"#O4LL!126	##I.    c                     SU-  $ )Nz%s; )r~   
codestrings     r   _get_statementMapleCodePrinter._get_statementn   s    z!!r   c                 $    SR                  U5      $ )Nz# {})format)r~   texts     r   _get_commentMapleCodePrinter._get_commentq   s    }}T""r   c                 ^    SR                  UUR                  U R                  S   5      5      $ )Nz	{} := {};	precision)r   evalf	_settings)r~   namevalues      r   _declare_number_const&MapleCodePrinter._declare_number_constt   s.    !!$$)KK{0K$LN 	Nr   c                     U$ Nr   )r~   liness     r   _format_codeMapleCodePrinter._format_codex   s    r   c                 6    U R                  [        U5      5      $ r   _printlistr~   exprs     r   _print_tupleMapleCodePrinter._print_tuple{       {{4:&&r   c                 6    U R                  [        U5      5      $ r   r   r   s     r   _print_TupleMapleCodePrinter._print_Tuple~   r   r   c                     U R                  UR                  5      nU R                  UR                  5      nSR                  X#S9$ )Nz{lhs} := {rhs})lhsrhs)r   r   r   r   )r~   r   r   r   s       r   _print_Assignment"MapleCodePrinter._print_Assignment   s:    kk$((#kk$((#&&3&88r   c                    [        U5      n[        UR                  S5      (       a  SU R                  UR                  U5      -  $ [        UR                  S5      (       a  SU R                  UR                  5      -  $ [        UR                  S5      (       a  SU R                  UR                  5      -  $ SR                  U R                  UR                  U5      U R                  UR                  U5      S9$ )	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_PowMapleCodePrinter._print_Pow   s    $"%%T..tyy$?@@$((C((DII 666$((D))$++dii"888!((&&tyy$7%%dhh5 ) 7 7r   c           
         UR                   S   R                  SLa6  UR                   S   R                  [        R                  :w  a  [	        S5      eUR                    VVs/ s Hi  u  p#USLaA  U[        R                  La.  SR                  U R                  U5      U R                  U5      S9OSR                  U R                  U5      S9PMk     nnnSR                  U5      nS	R                  US
9$ s  snnf )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_Piecewise!MapleCodePrinter._print_Piecewise   s    IIbMd*21C1Cq}}1T  / 0 0 			# " 56TMaq}}F\ Q!%Q  1bgbnbn++a. co c"" "	 	 #
 99Z(&--x-@@#s   "A0C5c                     [        UR                  5      [        UR                  5      p2SR                  [	        U5      [	        U5      S9$ )Nz{p}/{q})pq)intr   r   r   str)r~   r   r   r   s       r   _print_Rational MapleCodePrinter._print_Rational   s7    466{CK1#a&CF33r   c                     [        U5      nU R                  UR                  U5      nU R                  UR                  U5      nUR                  nU[
        ;   a	  [
        U   nSR                  X5US9$ )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_Relational"MapleCodePrinter._print_Relational   sj    $$TXXt4$$TXXt4[[$$$R(B%,,(,SSr   c                     [         U   $ r   )number_symbolsr   s     r   _print_NumberSymbol$MapleCodePrinter._print_NumberSymbol   s    d##r   c                     g)Nz	-infinityr   r   s     r   _print_NegativeInfinity(MapleCodePrinter._print_NegativeInfinity       r   c                     g)Ninfinityr   r   s     r   _print_Infinity MapleCodePrinter._print_Infinity   s    r   c                     g)Ntruer   r   s     r   _print_BooleanTrue#MapleCodePrinter._print_BooleanTrue   s    r   c                     g)Nfalser   r   s     r   _print_BooleanFalse$MapleCodePrinter._print_BooleanFalse   s    r   c                     U(       a  S$ S$ )Nr   r   r   r   s     r   _print_boolMapleCodePrinter._print_bool   s    v*7*r   c                     g)N	undefinedr   r   s     r   
_print_NaNMapleCodePrinter._print_NaN   r   r   c                     [         R                  UR                  ;   a  SR                  U(       a  SOSS9nU$ SR                  U R	                  UR                  5       5      U(       a  SOSS9nU$ )NzMatrix([], storage = {storage})sparserectangular)storagez#Matrix({list}, storage = {storage}))r   r   )r   Zeroshaper   r   tolist)r~   r   r   _strMs       r   _get_matrixMapleCodePrinter._get_matrix   sm    66TZZ5<<$* = ?E  :@@[[/$* A ?E r   c                     SR                  U R                  UR                  [        S   SS9U R	                  UR
                  S-   5      U R	                  UR                  S-   5      S9$ )Nz{parent}[{i_maple}, {j_maple}]AtomT)strict   )parenti_maplej_maple)r   r   r   r	   r   ijr   s     r   _print_MatrixElement%MapleCodePrinter._print_MatrixElement   s`    /66$$T[[*V2DT$RKK
+KK
+ 7 - 	-r   c                 "    U R                  USS9$ )NFr   r   r   s     r   _print_MatrixBase"MapleCodePrinter._print_MatrixBase   s    U33r   c                 "    U R                  USS9$ )NTr  r  r   s     r   _print_SparseRepMatrix'MapleCodePrinter._print_SparseRepMatrix   s    T22r   c                     [        UR                  [        [        45      (       a%  U R	                  [
        R                  " U5      5      $ SR                  U R	                  UR                  5      S9$ )Nz$Matrix({var_size}, shape = identity))var_size)
isinstancerowsr   r   r   sympySparseMatrixr   r   s     r   _print_Identity MapleCodePrinter._print_Identity   sV    dii'?!;<<;;u11$7889@@$++VZV_V_J`@aar   c                   ^ ^ [        U5      m[        UR                  5      nS n[        US   [        R
                  [        R                  [        R                  [        R                  45      (       d	  US   USS  p#Ub  US:X  a  SR                  UU 4S jU 5       5      $ SR                  USR                  UU 4S jU 5       5      S9$ )Nr   r   .c              3   H   >#    U  H  nTR                  UT5      v   M     g 7fr   r   .0_mr   r~   s     r   	<genexpr>1MapleCodePrinter._print_MatMul.<locals>.<genexpr>   s!     M*BD--b$77*   "z{c}*{m}c              3   H   >#    U  H  nTR                  UT5      v   M     g 7fr   r  r  s     r   r  r     s$     8j_iY[9J9J2t9T9T_ir  )r   m)r   r   r   r
  r  
MatrixBase
MatrixExprMatrixSliceMatrixSymbolr   r   )r~   r   
_fact_list_constr   s   `   @r   _print_MatMulMapleCodePrinter._print_MatMul   s    $))_
*Q-%*:*:E<L<L*/*;*;U=O=O*Q R R!+A
12J>Vq[88M*MMM##f8j_i8j0j#kkr   c                     SR                  U R                  UR                  5      U R                  UR                  5      S9$ )NzMatrixPower({A}, {n}))An)r   r   r   r   r   s     r   _print_MatPowMapleCodePrinter._print_MatPow   s5    &--DII0F$++VZV^V^J_-``r   c                 ~   ^ ^ [        U5      m[        UR                  5      nSR                  UU 4S jU 5       5      $ )N*c              3   H   >#    U  H  nTR                  UT5      v   M     g 7fr   r  r  s     r   r  :MapleCodePrinter._print_HadamardProduct.<locals>.<genexpr>   s!     Ij))"d33jr  )r   r   r   r   )r~   r   r   r   s   `  @r   _print_HadamardProduct'MapleCodePrinter._print_HadamardProduct   s/    $$))_
xxIjIIIr   c                    UR                   u  nu  p4US:w  a/  SR                  U R                  U5      U R                  U5      S9nOSR                  U R                  U5      S9nSR                  U R                  U5      US9$ )Nr   z{var}${order})varorderz{var})r0  zdiff({func_expr}, {sec_arg}))	func_exprsec_arg)r   r   r   )r~   r   _f_var_order_second_args         r   _print_Derivative"MapleCodePrinter._print_Derivative   s    !YYNTQ;)00T[[5F7;{{67J 1 LK "..T[[->.?K-44t{{2Xc4ddr   )r{   r   )F))__name__
__module____qualname____firstlineno____doc__printmethodlanguage
_operatorsrz   r   _default_settingsry   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-  r8  __static_attributes____classcell__)r   s   @r   rm   rm   T   s     KH J [:: #'? 
/"#N''9
7A"4T$+-43blaJ
e er   rm   c                 6    [        U5      R                  X5      $ )a  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_coderH    s    H H%--d>>r   c                 .    [        [        U 40 UD65        g)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)printrH  )r   r   s     r   print_maple_coderK  *  s     
*T
&X
&'r   r   )r>  
sympy.corer   sympy.core.numbersr   r   r   sympy.printing.codeprinterr   sympy.printing.precedencer   r	   r  _known_func_same_namer{   _funcrh   Exp1ri   
EulerGammaGoldenRatior   r   ComplexInfinitynot_supported_symbolrm   rH  rK  r   r   r   <module>rW     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* 
   le{ le^$?N(r   