o
    oh)                     @   sD  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< qnejd9ejd:ejd;ejd<ejd=iZd>d?d@ZejgZG dAdB dBeZdGdCdDZdEdF ZdS )Ha	  
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                       s0  e Zd ZdZdZdZddddZeej	fi ddd	Z	dF fdd	Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 ZdGd4d5Zd6d7 Zd8d9 Z d:d; Z!d<d= Z"d>d? Z#d@dA Z$dBdC Z%dDdE Z&  Z'S )HMapleCodePrinterzF
    Printer which converts a SymPy expression into a maple code.
    _maplemapleandorznot )rn   ro   notT)inlineallow_unknown_functionsNc                    s>   |d u ri }t  | tt| _|di }| j| d S )Nuser_functions)super__init__dictknown_functionsgetupdate)selfsettings	userfuncs	__class__ h/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/printing/maple.pyru   f   s   
zMapleCodePrinter.__init__c                 C   s   d| S )Nz%s;r   )rz   
codestringr   r   r   _get_statementn      zMapleCodePrinter._get_statementc                 C   s
   d |S )Nz# {})format)rz   textr   r   r   _get_commentq   s   
zMapleCodePrinter._get_commentc                 C   s   d ||| jd S )Nz	{} := {};	precision)r   evalf	_settings)rz   namevaluer   r   r   _declare_number_constt   s   z&MapleCodePrinter._declare_number_constc                 C   s   |S Nr   )rz   linesr   r   r   _format_codex      zMapleCodePrinter._format_codec                 C      |  t|S r   _printlistrz   exprr   r   r   _print_tuple{      zMapleCodePrinter._print_tuplec                 C   r   r   r   r   r   r   r   _print_Tuple~   r   zMapleCodePrinter._print_Tuplec                 C   s&   |  |j}|  |j}dj||dS )Nz{lhs} := {rhs})lhsrhs)r   r   r   r   )rz   r   r   r   r   r   r   _print_Assignment   s   z"MapleCodePrinter._print_Assignmentc                 K   s   t |}t|jdrd| |j| S t|jdr!d| |j S t|jdr/d| |j S dj| |j|| |j|dS )	Nz1/%sg      ?zsqrt(%s)g      z
1/sqrt(%s)z{base}^{exp})baser   )r   r   r   parenthesizer   r   r   )rz   r   kwargsPRECr   r   r   
_print_Pow   s   zMapleCodePrinter._print_Powc                    sT   |j d jdur|j d jtjkrtd fdd|j D }d|}dj|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                    sN   g | ]#\}}|d ur|t jurdj | |dndj |dqS )Tz{c}, {e})cez{e})r   )r   BooleanTruer   r   ).0r   r   rz   r   r   
<listcomp>   s    z5MapleCodePrinter._print_Piecewise.<locals>.<listcomp>z, zpiecewise({_inbrace}))_inbrace)argscondr   r   
ValueErrorjoinr   )rz   r   
_coup_listr   r   r   r   _print_Piecewise   s   "

z!MapleCodePrinter._print_Piecewisec                 C   s,   t |jt |j}}djt|t|dS )Nz{p}/{q})pq)intr   r   r   str)rz   r   r   r   r   r   r   _print_Rational   s   z MapleCodePrinter._print_Rationalc                 C   sJ   t |}| |j|}| |j|}|j}|tv rt| }dj|||dS )Nz{lhs} {rel_op} {rhs})r   rel_opr   )r   r   r   r   r   spec_relational_opsr   )rz   r   r   lhs_coderhs_codeopr   r   r   _print_Relational   s   z"MapleCodePrinter._print_Relationalc                 C   s   t | S r   )number_symbolsr   r   r   r   _print_NumberSymbol   r   z$MapleCodePrinter._print_NumberSymbolc                 C      dS )Nz	-infinityr   r   r   r   r   _print_NegativeInfinity   r   z(MapleCodePrinter._print_NegativeInfinityc                 C   r   )Ninfinityr   r   r   r   r   _print_Infinity   r   z MapleCodePrinter._print_Infinityc                 C   s   |  |jS r   )r   labelr   r   r   r   
_print_Idx      zMapleCodePrinter._print_Idxc                 C   r   )Ntruer   r   r   r   r   _print_BooleanTrue   r   z#MapleCodePrinter._print_BooleanTruec                 C   r   )Nfalser   r   r   r   r   _print_BooleanFalse   r   z$MapleCodePrinter._print_BooleanFalsec                 C   s   |rdS dS )Nr   r   r   r   r   r   r   _print_bool   r   zMapleCodePrinter._print_boolc                 C   r   )N	undefinedr   r   r   r   r   
_print_NaN   r   zMapleCodePrinter._print_NaNFc                 C   sH   t j|jv rdj|rdndd}|S dj| | |rdndd}|S )NzMatrix([], storage = {storage})sparserectangular)storagez#Matrix({list}, storage = {storage}))r   r   )r   Zeroshaper   r   tolist)rz   r   r   _strMr   r   r   _get_matrix   s   

zMapleCodePrinter._get_matrixc                 C   s:   dj | j|jtd dd| |jd | |jd dS )Nz{parent}[{i_maple}, {j_maple}]AtomT)strict   )parenti_maplej_maple)r   r   r   r   r   ijr   r   r   r   _print_MatrixElement   s
   z%MapleCodePrinter._print_MatrixElementc                 C      | j |ddS )NFr   r   r   r   r   r   _print_MatrixBase   r   z"MapleCodePrinter._print_MatrixBasec                 C   r   )NTr   r   r   r   r   r   _print_SparseRepMatrix   r   z'MapleCodePrinter._print_SparseRepMatrixc                 C   s4   t |jttfr| t|S dj| |jdS )Nz$Matrix({var_size}, shape = identity))var_size)
isinstancerowsr   r   r   sympySparseMatrixr   r   r   r   r   _print_Identity   s   z MapleCodePrinter._print_Identityc                    s   t | t|j}d }t|d tjtjtjtjfs%|d |dd  }}|d u s-|dkr:d	 fdd|D S dj
|d	 fdd|D dS )	Nr   r   .c                 3       | ]	} | V  qd S r   r   r   _mr   rz   r   r   	<genexpr>       z1MapleCodePrinter._print_MatMul.<locals>.<genexpr>z{c}*{m}c                 3   r   r   r   r   r   r   r   r      r   )r   m)r   r   r   r   r   
MatrixBase
MatrixExprMatrixSliceMatrixSymbolr   r   )rz   r   
_fact_list_constr   r   r   _print_MatMul   s   
$zMapleCodePrinter._print_MatMulc                 C   s   dj | |j| |jdS )NzMatrixPower({A}, {n}))An)r   r   r   r   r   r   r   r   _print_MatPow   s   zMapleCodePrinter._print_MatPowc                    s,   t | t|j}d fdd|D S )N*c                 3   r   r   r   r   r   r   r   r      r   z:MapleCodePrinter._print_HadamardProduct.<locals>.<genexpr>)r   r   r   r   )rz   r   r   r   r   r   _print_HadamardProduct   s   
z'MapleCodePrinter._print_HadamardProductc                 C   sX   |j \}\}}|dkrdj| || |d}n	dj| |d}dj| ||dS )Nr   z{var}${order})varorderz{var})r   zdiff({func_expr}, {sec_arg}))	func_exprsec_arg)r   r   r   )rz   r   _f_var_order_second_argr   r   r   _print_Derivative   s   z"MapleCodePrinter._print_Derivativer   )F)(__name__
__module____qualname____doc__printmethodlanguage
_operatorsrv   r   _default_settingsru   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   r   r}   r   rk   T   sR    

	

rk   c                 K   s   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].

    )rk   doprint)r   	assign_tor{   r   r   r   
maple_code  s   $r  c                 K   s   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{   r   r   r   print_maple_code-  s   r  r   )r  
sympy.corer   sympy.core.numbersr   r   r   sympy.printing.codeprinterr   sympy.printing.precedencer   r   r   _known_func_same_namerw   _funcrg   Exp1rh   
EulerGammaGoldenRatior   r   ComplexInfinitynot_supported_symbolrk   r  r  r   r   r   r   <module>   s    
	
$
 
3'