K iK)dZddlmZddlmZmZmZddlmZddl m Z m Z ddl Z dZ idd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8Ze D]Zeee< ej d9ej"d:ej$d;ej&dd?d@Zej.gZGdAdBeZdEdCZdDZy)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)IntegerIntegerConstant equal_valued) CodePrinter) precedence PRECEDENCEN) sincostanseccsccotsinhcoshtanhsechcschcothexpfloor factorial bernoullieuler fibonaccigcdlcm conjugateCiChiEiLiSiShierferfcharmonicLambertWsqrtAbsabsloglnasinarcsinacosarccosatanarctanasecarcsecacscarccscacotarccotasinharcsinhacosharccoshatanharctanhasecharcsechacscharccschacotharccothceilingceilMaxmaxMinmindoublefactorial pochhammerBesselIBesselJBesselKBesselYHankelH1HankelH2AiryAiAiryBiAppellF1FresnelCFresnelSLerchPhi) factorial2RisingFactorialbesselibesseljbesselkbesselyhankelh1hankelh2airyaiairybiappellf1fresnelcfresnelslerchphiPizexp(1)Catalangammaz(1/2 + (1/2)*sqrt(5))=z<>)z==z!=ceZdZdZdZdZddddZeejfiddd Z d&fd Z d Z d Z d Z dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZd'dZdZdZd Z d!Z!d"Z"d#Z#d$Z$d%Z%xZ&S)(MapleCodePrinterzF Printer which converts a SymPy expression into a maple code. _maplemapleandorznot )rprqnotT)inlineallow_unknown_functionsc|i}t||tt|_|j di}|jj |y)Nuser_functions)super__init__dictknown_functionsgetupdate)selfsettings userfuncs __class__s Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/printing/maple.pyrxzMapleCodePrinter.__init__fsM  H "#O4LL!126  ##I.c d|zS)Nz%s;)r} codestrings r_get_statementzMapleCodePrinter._get_statementns z!!rc$dj|S)Nz# {})format)r}texts r _get_commentzMapleCodePrinter._get_commentqs}}T""rc^dj||j|jdS)Nz {} := {}; precision)revalf _settings)r}namevalues r_declare_number_constz&MapleCodePrinter._declare_number_constts.!!$$)KK{0K$LN Nrc|SNr)r}liness r _format_codezMapleCodePrinter._format_codexs rc6|jt|Sr_printlistr}exprs r _print_tuplezMapleCodePrinter._print_tuple{{{4:&&rc6|jt|Srrrs r _print_TuplezMapleCodePrinter._print_Tuple~rrc|j|j}|j|j}dj||S)Nz{lhs} := {rhs})lhsrhs)rrrr)r}rrrs r_print_Assignmentz"MapleCodePrinter._print_Assignments<kk$((#kk$((#&&3C&88rc t|}t|jdrd|j|j|zSt|jdrd|j |jzSt|jdrd|j |jzSdj |j|j||j|j|S) Nz1/%sg?zsqrt(%s)gz 1/sqrt(%s)z {base}^{exp})baser)rrr parenthesizerrr)r}rkwargsPRECs r _print_PowzMapleCodePrinter._print_Pows$ " %T..tyy$?@ @ $((C ( DII 66 6 $((D )$++dii"88 8!((&&tyy$7%%dhh5)7 7rc |jdjdur5|jdjtjk7r t d|jDcgc]m\}}|durC|tjur1dj |j ||j |n dj |j |o}}}dj|}d j | Scc}}w) NrTzAll 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})cez{e})rz, zpiecewise({_inbrace}))_inbrace)argscondr BooleanTrue ValueErrorrrjoin)r}rrr _coup_listrs r_print_Piecewisez!MapleCodePrinter._print_Piecewises IIbM  d *21C1Cq}}1T/0 0 #156TMaq}}F\  Q!%Q1bgbnbn++a.coc""# # 99Z(&--x-@@ #s A2C8ct|jt|j}}djt |t |S)Nz{p}/{q})pq)intrrrstr)r}rrrs r_print_Rationalz MapleCodePrinter._print_Rationals9466{CK1#a&CF33rct|}|j|j|}|j|j|}|j}|t vr t |}dj |||S)Nz{lhs} {rel_op} {rhs})rrel_opr)rrrrrspec_relational_opsr)r}rrlhs_coderhs_codeops r_print_Relationalz"MapleCodePrinter._print_Relationalsl  $$TXXt4$$TXXt4 [[ $ $$R(B%,,"(,SSrct|Sr)number_symbolsrs r_print_NumberSymbolz$MapleCodePrinter._print_NumberSymbols d##rcy)Nz -infinityrrs r_print_NegativeInfinityz(MapleCodePrinter._print_NegativeInfinityrcy)Ninfinityrrs r_print_Infinityz MapleCodePrinter._print_Infinitysrcy)Ntruerrs r_print_BooleanTruez#MapleCodePrinter._print_BooleanTruesrcy)Nfalserrs r_print_BooleanFalsez$MapleCodePrinter._print_BooleanFalsesrc|rdSdS)Nrrrrs r _print_boolzMapleCodePrinter._print_boolsv*7*rcy)N undefinedrrs r _print_NaNzMapleCodePrinter._print_NaNrrctj|jvrdj|rdnd}|Sdj|j |j |rdnd}|S)NzMatrix([], storage = {storage})sparse rectangular)storagez#Matrix({list}, storage = {storage}))rr)rZeroshaperrtolist)r}rr_strMs r _get_matrixzMapleCodePrinter._get_matrixsm 66TZZ 5<<$* =?E  :@@[[/$* A?E rcdj|j|jtdd|j |j dz|j |j dzS)Nz{parent}[{i_maple}, {j_maple}]AtomT)strict)parenti_maplej_maple)rrrr rijrs r_print_MatrixElementz%MapleCodePrinter._print_MatrixElements`/66$$T[[*V2DT$RKK +KK +7- -rc(|j|dS)NFrrrs r_print_MatrixBasez"MapleCodePrinter._print_MatrixBasesU33rc(|j|dS)NTrrrs r_print_SparseRepMatrixz'MapleCodePrinter._print_SparseRepMatrixsT22rct|jttfr$|j t j |Sdj|j |jS)Nz$Matrix({var_size}, shape = identity))var_size) isinstancerowsrrrsympy SparseMatrixrrs r_print_Identityz MapleCodePrinter._print_IdentitysS dii'?!; <;;u11$78 89@@$++VZV_V_J`@a arct|t|j}d}t|dtj tj tjtjfs |d|dd}}||dk(rdjfd|DSdj|djfd|DS)Nrr.c3BK|]}j|ywrr.0_mrr}s r z1MapleCodePrinter._print_MatMul..sMBD--b$7Mz{c}*{m}c3BK|]}j|ywrrrs rrz1MapleCodePrinter._print_MatMul..s8jY[9J9J2t9T8jr)rm) rrrrr MatrixBase MatrixExpr MatrixSlice MatrixSymbolrr)r}r _fact_list_constrs` @r _print_MatMulzMapleCodePrinter._print_MatMuls  $))_ *Q-%*:*:EVq[88M*MM M##f8j_i8j0j#k krcdj|j|j|j|jS)NzMatrixPower({A}, {n}))An)rrrrrs r _print_MatPowzMapleCodePrinter._print_MatPows5&-- DII0F$++VZV^V^J_-``rc|t|t|j}djfd|DS)N*c3BK|]}j|ywrrrs rrz:MapleCodePrinter._print_HadamardProduct..sI))"d3Ir)rrrr)r}rrrs` @r_print_HadamardProductz'MapleCodePrinter._print_HadamardProducts/$$))_ xxIjIIIrc|j\}\}}|dk7r2dj|j||j|}n!dj|j|}dj|j||S)Nrz {var}${order})varorderz{var})rzdiff({func_expr}, {sec_arg})) func_exprsec_arg)rrr)r}r_f_var_order _second_args r_print_Derivativez"MapleCodePrinter._print_Derivatives!YYNT6 Q;)00T[[5F7;{{67J1LK"..T[[->.?K-44t{{2Xc4ddrr)F)'__name__ __module__ __qualname____doc__ printmethodlanguage _operatorsryr_default_settingsrxrrrrrrrrrrrrrrrrrrrrrrrrr rr __classcell__)rs@rrmrmTsKHJ [::#'? /"#N''9 7A"4T$+- 43b laJ errmc 8t|j||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]. )rmdoprint)r assign_tor~s r maple_coder'sH H % - -dI >>rc .tt|fi|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')rr~s rprint_maple_coder**s *T &X &'rr)r sympy.corersympy.core.numbersrrrsympy.printing.codeprinterrsympy.printing.precedencerr r_known_func_same_namerz_funcrhExp1ri EulerGamma GoldenRatiorrComplexInfinitynot_supported_symbolrmr'r*rrrr6sEE2< " 5" 4" H "  H "  H " H" H" H" Y" Y" Y" Y" Y" Y" v!"" E#"$ E%"($#C"H##E"OE# DD$FFHIIyLL'MM*   le{le^$?N (r