U
    ZÊ¹jËi  ã                !   @  s*  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) dd	l*m+Z+m,Z, dd
l-m.Z.m/Z/ ddl0m1Z1 ddl*m2Z2m3Z3 dd„ dfdd„ dfgddddddddddddddd d!œZ4e5e4fd"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3œŽZ6d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTg!Z7dUdVgZ8dWdX„ Z9dYdZ„ Z:G d[d\„ d\e+ƒZ;G d]d^„ d^e;ƒZ<d_ =¡ D ]Z>e?e<d`e> e<j@ƒ �qðG dadb„ dbe<ƒZAe;e<eAdcœZBddS )ea†  
C code printer

The C89CodePrinter & C99CodePrinter converts single SymPy expressions into
single C expressions, using the functions defined in math.h where possible.

A complete code generator, which uses ccode extensively, can be found in
sympy.utilities.codegen. The codegen module can be used to generate complete
source code files that are compilable without further modifications.


é    )Úannotations)ÚAny©Úwraps)Úchain)ÚS)Úequal_valuedÚFloat)Ú
AssignmentÚPointerÚVariableÚDeclarationÚTypeÚrealÚcomplex_ÚintegerÚbool_Úfloat32Úfloat64Úfloat80Ú	complex64Ú
complex128ÚintcÚvalue_constÚpointer_constÚint8Úint16Úint32Úint64Úuint8Úuint16Úuint32Úuint64ÚuntypedÚnone)ÚCodePrinterÚrequires)Ú
precedenceÚ
PRECEDENCE)ÚRange)ÚccodeÚprint_ccodec                 C  s   | j  S ©N©Ú
is_integer©Úx© r1   úO/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/printing/c.pyÚ<lambda>(   ó    r3   Úfabsc                 C  s   | j S r,   r-   r/   r1   r1   r2   r3   (   r4   ÚabsÚsinÚcosÚtanÚasinÚacosÚatanÚatan2ÚexpÚlogÚsinhÚcoshÚtanhÚfloorÚceilÚsqrt)ZAbsr7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   ZceilingrE   Úexp2Úexpm1Úlog10Úlog2Úlog1pZcbrtÚhypotÚfmaÚlgammaÚerfcZfmaxZfminÚasinhÚacoshÚatanhÚerfZtgamma)rF   rG   rH   rI   rJ   ZCbrtrK   rL   ZloggammarN   ÚMaxÚMinrO   rP   rQ   rR   ÚgammaÚautoÚbreakÚcaseÚcharÚconstÚcontinueÚdefaultÚdoÚdoubleÚelseÚenumZexternÚfloatÚforZgotoÚifÚintÚlongÚregisterÚreturnÚshortÚsignedZsizeofZstaticÚstructÚentryÚswitchZtypedefÚunionZunsignedÚvoidZvolatileÚwhileÚinlineÚrestrictc               !   C  sÊ   ddl m} m} ddlm} ddlm} tjd| tjƒdd|dƒ d|dƒd	|d
ƒdtj	dtj	d dtj	d ddtj	 ddtj	 dd|tj	ƒ dd|tj	ƒ d|dƒd|dƒdd|dƒ dd|dƒ diS )aV   Returns a dictionary with math-related macros from math.h/cmath

    Note that these macros are not strictly required by the C/C++-standard.
    For MSVC they are enabled by defining "_USE_MATH_DEFINES" (preferably
    via a compilation flag).

    Returns
    =======

    Dictionary mapping SymPy expressions to strings (macro names)

    r   )rI   ÚSqrt)r?   )rE   ZM_EZM_LOG2Eé   é   ZM_LN2é
   ZM_LN10ZM_PIZM_PI_2é   ZM_PI_4ZM_1_PIZM_2_PIZ
M_2_SQRTPIZM_SQRT2Z	M_SQRT1_2)
Zsympy.codegen.cfunctionsrI   rr   Z&sympy.functions.elementary.exponentialr?   Z(sympy.functions.elementary.miscellaneousrE   r   ZExp1ÚPi)rI   rr   r?   rE   r1   r1   r2   Úget_math_macros[   sH      
            
 
 ðrx   c                   s   t ˆ ƒ‡ fdd„ƒ}|S )a�   Decorator for printer methods

    When a Printer's method is decorated using this decorator the expressions printed
    will first be looked for in the attribute ``math_macros``, and if present it will
    print the macro name in ``math_macros`` followed by a type suffix for the type
    ``real``. e.g. printing ``sympy.pi`` would print ``M_PIl`` if real is mapped to float80.

    c                   s4   || j kr"d| j | |  t¡f S ˆ | |f|ŽS d S ©Nú%s%s)Úmath_macrosÚ_get_math_macro_suffixr   ©ÚselfÚexprÚkwargs©Úmethr1   r2   Ú_meth_wrapper‰   s    
z+_as_macro_if_defined.<locals>._meth_wrapperr   )r‚   rƒ   r1   r�   r2   Ú_as_macro_if_defined€   s    	r„   c                      s  e Zd ZU dZdZdZdZeeƒZe	e
jfdi deƒ ddœŽZd	ed
< eeeeeeiZedededededededededededededediZded< edhedhedhedhedhedhedhedhedhi	Zi Z ded< edede!diZ"edede!diZ#e!diZ$dZ%dZ&e'Z(d	ed< dŽ‡ fd d!„	Z)d"d#„ Z*d$d%„ Z+d&d'„ Z,d(d)„ Z-d*d+„ Z.d,d-„ Z/e0‡ fd.d/„ƒZ1e0d0d1„ ƒZ2d2d3„ Z3d4d5„ Z4d6d7„ Z5d8d9„ Z6e0‡ fd:d;„ƒZ7d<d=„ Z8d>d?„ Z9d@dA„ Z:dBdC„ Z;dDdE„ Z<‡ fdFdG„Z=dHdI„ Z>dJdK„ Z?dLdM„ Z@dNdO„ ZAdPdQ„ ZBdRdS„ ZCdTdU„ ZDdVdW„ ZEdXdY„ ZFdZd[„ ZGeGZHd\d]„ ZId^d_„ ZJd`da„ ZKeLdhdb�dcdd„ ƒZMeLdhdb�dedf„ ƒZNdgdh„ ZOdidj„ ZPdkdl„ ZQdmdn„ ZReLdohdb�dpdq„ ƒZSdrds„ ZTdtdu„ ZUdvdw„ ZVdxdy„ ZWdzd{„ ZXd|d}„ ZYd~d„ ZZd€d�„ Z[d‚dƒ„ Z\d„d…„ Z]d†d‡„ Z^dˆd‰„ Z_dŠd‹„ Z`dŒd�„ Zae_Zb‡  ZcS )�ÚC89CodePrinterz<A printer to convert Python expressions to strings of C codeZ_ccodeÚCÚC89é   TF)Ú	precisionÚuser_functionsZcontractÚdereferenceZerror_on_reservedúdict[str, Any]Ú_default_settingsr^   rd   ra   ÚboolZint8_tZint16_tZint32_tZint64_tzdict[Type, Any]Útype_mappingsz	stdbool.hzstdint.hzdict[Type, tuple[str, ...]]Útype_macrosÚfÚ ÚlÚFÚLNÚ_kfc                   sb  |pi }| j d kr"| dtƒ ¡| _ tt| j ¡ | di ¡ ¡ ƒƒ| _tt| j ¡ | di ¡ ¡ ƒƒ| _tt| j ¡ | di ¡ ¡ ƒƒ| _tt| j	 ¡ | di ¡ ¡ ƒƒ| _	tt| j
 ¡ | di ¡ ¡ ƒƒ| _
tt| j ¡ | di ¡ ¡ ƒƒ| _tt| j ¡ | di ¡ ¡ ƒƒ| _tƒ  |¡ t| jf| d	i ¡Ž| _t| d
g ¡ƒ| _tƒ | _tƒ | _tƒ | _d S )Nr{   Útype_aliasesr�   Útype_headersr�   Útype_func_suffixesÚtype_literal_suffixesÚtype_math_macro_suffixesrŠ   r‹   )r{   Úpoprx   Údictr   r—   Úitemsr�   r˜   r�   r™   rš   r›   ÚsuperÚ__init__r–   ÚgetÚknown_functionsÚsetZ_dereferenceÚheadersÚ	librariesÚmacros)r~   Úsettings©Ú	__class__r1   r2   r    Þ   s<    
ÿÿÿÿÿÿÿzC89CodePrinter.__init__c                 C  s   |d S )Né   r1   )r~   Úpr1   r1   r2   Ú_rate_index_position÷   s    z#C89CodePrinter._rate_index_positionc                 C  s   |  d¡r|S |d S )z@ Get code string as a statement - i.e. ending with a semicolon. ú;)Úendswith)r~   Z
codestringr1   r1   r2   Ú_get_statementú   s    zC89CodePrinter._get_statementc                 C  s
   d  |¡S )Nz/* {} */)Úformat)r~   Útextr1   r1   r2   Ú_get_commentþ   s    zC89CodePrinter._get_commentc                 C  s<   | j t }t||| |j¡thd�}t|ƒ}|  |  |¡¡S )N)ÚtypeÚvalueÚattrs)	r—   r   r   ÚevalfÚdecimal_digr   r   r¯   Ú_print)r~   Únamer´   Útype_ÚvarÚdeclr1   r1   r2   Ú_declare_number_const  s    
z$C89CodePrinter._declare_number_constc                 C  s
   |   |¡S r,   )Úindent_code)r~   Úlinesr1   r1   r2   Ú_format_code  s    zC89CodePrinter._format_codec                   s    |j \}‰ ‡ fdd„t|ƒD ƒS )Nc                 3  s$   | ]}t ˆ ƒD ]}||fV  qqd S r,   )Úrange)Ú.0ÚiÚj©Úcolsr1   r2   Ú	<genexpr>  s     
  z:C89CodePrinter._traverse_matrix_indices.<locals>.<genexpr>)ÚshaperÁ   )r~   ZmatÚrowsr1   rÅ   r2   Ú_traverse_matrix_indices
  s    
z'C89CodePrinter._traverse_matrix_indicesc                   s   t ƒ j|f|ŽS r,   )rŸ   Ú
_print_Mulr}   r¨   r1   r2   rË     s    zC89CodePrinter._print_Mulc                 C  sÎ   d| j kr|  |¡S t|ƒ}|  t¡}t|jdƒrRd|  tdƒ¡|  	|j
|¡f S t|jdƒrvd| j||  |j
¡f S |jtjd kr¨| jdkr¨d	| j||  |j
¡f S d
| j||  |j
¡|  |j¡f S d S )NÚPowéÿÿÿÿz%s/%sg      ð?g      à?z%ssqrt%s(%s)é   r‡   z%scbrt%s(%s)z%spow%s(%s, %s))r¢   Ú_print_Functionr'   Ú_get_func_suffixr   r   r>   Ú_print_Floatr	   ÚparenthesizeÚbaseÚ_nsr¸   r   ÚOneÚstandard)r~   r   ÚPRECÚsuffixr1   r1   r2   Ú
_print_Pow  s    


 
ÿzC89CodePrinter._print_Powc                   sˆ   |j \}}|jrz|jrzt|ƒ‰ ‡ ‡fdd„|j D ƒ\}}|jrD|jsP|jr^|jr^|› d|› �S d|› d|› d|› d|› �S ˆj|dd�S )	Nc                   s   g | ]}ˆ  |ˆ ¡‘qS r1   )rÒ   ©rÂ   Úarg©r×   r~   r1   r2   Ú
<listcomp>&  s     z-C89CodePrinter._print_Mod.<locals>.<listcomp>z % z((z) + z) % Úfmod)Úknown)Úargsr.   r'   Zis_nonnegativeZis_nonpositiveÚ_print_math_func)r~   r   ÚnumZdenZsnumZsdenr1   rÜ   r2   Ú
_print_Mod"  s    
ÿÿzC89CodePrinter._print_Modc                 C  s0   t |jƒt |jƒ }}|  t¡}d||||f S )Nz%d.0%s/%d.0%s)rd   r«   ÚqÚ_get_literal_suffixr   )r~   r   r«   rä   rØ   r1   r1   r2   Ú_print_Rational1  s    
zC89CodePrinter._print_Rationalc                 C  sâ   t |jdtjƒ}t |jdd ƒ}|j}|d ks6t|tƒrª|j}tj}d}|dksV|d krtt	t
|jƒƒ}|d d d… }n|dkr†t
|jƒ}|D ]}	||f7 }|||	 9 }qŠ|}tdd„ t||ƒD ƒƒ| }
d	|  |jj¡|  |
¡f S )
NÚoffsetÚstridesr1   r†   rÍ   r”   c                 s  s   | ]}|d  |d  V  qdS )r   rs   Nr1   )rÂ   r0   r1   r1   r2   rÇ   J  s     z0C89CodePrinter._print_Indexed.<locals>.<genexpr>z%s[%s])ÚgetattrrÓ   r   ZZeroÚindicesÚ
isinstanceÚstrrÈ   rÕ   ÚreversedrÁ   ZrankÚsumÚzipr¸   Úlabel)r~   r   rç   rè   rê   ZdimsÚshiftÚtempZ	traversalrÃ   Z
flat_indexr1   r1   r2   Ú_print_Indexed6  s(    

ÿzC89CodePrinter._print_Indexedc                 C  s   |   |j¡S r,   )r¸   rð   ©r~   r   r1   r1   r2   Ú
_print_IdxN  s    zC89CodePrinter._print_Idxc                   s   t ƒ  |¡S r,   )rŸ   Ú_print_NumberSymbolrô   r¨   r1   r2   rö   Q  s    z"C89CodePrinter._print_NumberSymbolc                 C  s   dS )NZHUGE_VALr1   rô   r1   r1   r2   Ú_print_InfinityU  s    zC89CodePrinter._print_Infinityc                 C  s   dS )Nz	-HUGE_VALr1   rô   r1   r1   r2   Ú_print_NegativeInfinityX  s    z&C89CodePrinter._print_NegativeInfinityc           	        s  |j d jdkrtdƒ‚g }| t¡r¾t|j ƒD ]‚\}\}}|dkrZ| dˆ  |¡ ¡ n:|t|j ƒd kr€|dkr€| d¡ n| dˆ  |¡ ¡ ˆ  |¡}| |¡ | d	¡ q0d
 	|¡S ‡ fdd„|j d d… D ƒ}dˆ  |j d j
¡ }d 	|¡| d 	dt|ƒ g¡ S d S )NrÍ   Tz¼All 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.r   z	if (%s) {rs   zelse {zelse if (%s) {Ú}Ú
c                   s(   g | ] \}}d ˆ   |¡ˆ   |¡f ‘qS )z((%s) ? (
%s
)
©r¸   )rÂ   ÚeÚc©r~   r1   r2   rÝ   v  s   þ
ÿz3C89CodePrinter._print_Piecewise.<locals>.<listcomp>z: (
%s
)z: ú ú))rà   ZcondÚ
ValueErrorÚhasr
   Ú	enumerateÚappendr¸   ÚlenÚjoinr   )	r~   r   r¿   rÃ   rü   rý   Zcode0ZecpairsÚ	last_liner1   rþ   r2   Ú_print_Piecewise[  s&    




þzC89CodePrinter._print_Piecewisec                 C  s    ddl m} |  |j|dd�¡S )Nr   )Ú	PiecewiseF)Údeep)Zsympy.functionsr	  r¸   Zrewrite)r~   r   r	  r1   r1   r2   Ú
_print_ITE|  s    zC89CodePrinter._print_ITEc                 C  s2   d  | j|jtd dd�|j|j|jjd   ¡S )Nz{}[{}]ZAtomT)Ústrictrs   )r°   rÒ   Úparentr(   rÄ   rÃ   rÈ   rô   r1   r1   r2   Ú_print_MatrixElement€  s
    ÿÿz#C89CodePrinter._print_MatrixElementc                   s,   t ƒ  |¡}|| jd kr$d |¡S |S d S )Nr‹   z(*{}))rŸ   Ú_print_SymbolZ	_settingsr°   )r~   r   r¹   r¨   r1   r2   r  „  s    
zC89CodePrinter._print_Symbolc                 C  s,   |   |j¡}|   |j¡}|j}d |||¡S )Nz{} {} {})r¸   ÚlhsÚrhsZrel_opr°   )r~   r   Zlhs_codeZrhs_codeÚopr1   r1   r2   Ú_print_Relational‹  s    z C89CodePrinter._print_Relationalc                 C  sP   |   |j¡}t|jtƒr(|jj\}}}ntdƒ‚|   |j¡}dj|||||d�S )Nz*Only iterable currently supported is RangezLfor ({target} = {start}; {target} < {stop}; {target} += {step}) {{
{body}
}})ÚtargetÚstartÚstopÚstepÚbody)	r¸   r  rë   Úiterabler)   rà   ÚNotImplementedErrorr  r°   )r~   r   r  r  r  r  r  r1   r1   r2   Ú
_print_For‘  s       þzC89CodePrinter._print_Forc                 C  s   d  |  |jd ¡¡S )Nz((({0}) > 0) - (({0}) < 0))r   )r°   r¸   rà   )r~   Úfuncr1   r1   r2   Ú_print_signœ  s    zC89CodePrinter._print_signc                   s,   dˆj krˆ |¡S ‡ ‡fdd„‰ ˆ |jƒS )NrS   c                   sL   t | ƒdkrˆ | d ¡S t | ƒd }dˆ | d |… ƒˆ | |d … ƒdœ S )Nrs   r   rt   z!((%(a)s > %(b)s) ? %(a)s : %(b)s)©ÚaÚb©r  r¸   ©rà   Zhalf©Úinner_print_maxr~   r1   r2   r$  ¢  s    þz2C89CodePrinter._print_Max.<locals>.inner_print_max©r¢   rÏ   rà   rô   r1   r#  r2   Ú
_print_MaxŸ  s    

zC89CodePrinter._print_Maxc                   s,   dˆj krˆ |¡S ‡ ‡fdd„‰ ˆ |jƒS )NrT   c                   sL   t | ƒdkrˆ | d ¡S t | ƒd }dˆ | d |… ƒˆ | |d … ƒdœ S )Nrs   r   rt   z!((%(a)s < %(b)s) ? %(a)s : %(b)s)r  r!  r"  ©Úinner_print_minr~   r1   r2   r(  ¯  s    þz2C89CodePrinter._print_Min.<locals>.inner_print_minr%  rô   r1   r'  r2   Ú
_print_Min¬  s    

zC89CodePrinter._print_Minc           
        sÂ   t |tƒr$|  | d¡¡}d |¡S d}d‰d‰ dd„ |D ƒ}‡fdd„|D ƒ}‡ fd	d„|D ƒ}g }d
}t|ƒD ]J\}}	|	dkrŽ| |	¡ qr||| 8 }| d|| |	f ¡ ||| 7 }qr|S )z0Accepts a string of code or a list of code linesTr’   z   )Ú{ú(z{
z(
)rù   r   c                 S  s   g | ]}|  d ¡‘qS )z 	)Úlstrip©rÂ   Úliner1   r1   r2   rÝ   Ä  s     z.C89CodePrinter.indent_code.<locals>.<listcomp>c                   s    g | ]}t tt|jˆ ƒƒƒ‘qS r1   )rd   ÚanyÚmapr®   r-  )Ú	inc_tokenr1   r2   rÝ   Æ  s     c                   s    g | ]}t tt|jˆ ƒƒƒ‘qS r1   )rd   r/  r0  Ú
startswithr-  )Ú	dec_tokenr1   r2   rÝ   Ç  s     r   )r’   rú   rz   )rë   rì   r¾   Ú
splitlinesr  r  r  )
r~   ÚcodeZ
code_linesÚtabZincreaseZdecreaseÚprettyÚlevelÚnr.  r1   )r3  r1  r2   r¾   ¹  s&    


zC89CodePrinter.indent_codec                 C  s   | j | j ||¡ S r,   )r™   r—   r¡   ©r~   rº   r1   r1   r2   rÐ   Ô  s    zC89CodePrinter._get_func_suffixc                 C  s   | j | j ||¡ S r,   )rš   r—   r¡   r:  r1   r1   r2   rå   ×  s    z"C89CodePrinter._get_literal_suffixc                 C  s*   | j  ||¡}| j |d¡}| j ||¡S )Nr’   )r—   r¡   r›   )r~   rº   ÚaliasZdfltr1   r1   r2   r|   Ú  s    z%C89CodePrinter._get_math_macro_suffixc                   s    dd  ‡ fdd„|D ƒ¡ d S )Nr*  ú, c                 3  s   | ]}ˆ   |¡V  qd S r,   rû   )rÂ   rü   rþ   r1   r2   rÇ   à  s     z.C89CodePrinter._print_Tuple.<locals>.<genexpr>rù   )r  rô   r1   rþ   r2   Ú_print_Tupleß  s    zC89CodePrinter._print_Tuplec                 C  sF   | j  | j |tƒ ¡¡ | j | j |tƒ ¡¡ |  | j ||j	¡¡S r,   )
r¤   Úupdater˜   r¡   r£   r¦   r�   r¸   r�   r¹   r:  r1   r1   r2   Ú_print_Typeä  s    zC89CodePrinter._print_Typec                 C  sì   ddl m} |j}|j}|jtkr*tdƒ‚t|tƒr„dj	t
|jkrFdnd|  |j¡t|jkr`dnd||jkrpdnd|  |j¡d	�}nJt|tƒr¾d
j	t
|jkr dnd|  |j¡|  |j¡d�}ntdt|ƒ ƒ‚|d krè|d|  |¡ 7 }|S )Nr   )rq   z$C does not support untyped variablesz{vc}{t} *{pc} {r}{s}zconst r’   z constz	restrict )ÚvcÚtZpcÚrÚsz{vc}{t} {s})r@  rA  rC  zUnknown type of var: %sz = %s)Zsympy.codegen.cnodesrq   Úvariabler´   r³   r#   r  rë   r   r°   r   rµ   r¸   r   Úsymbolr   r  )r~   r¼   rq   r»   ÚvalÚresultr1   r1   r2   Ú_print_Declarationé  s.    



û


ýz!C89CodePrinter._print_Declarationc                 C  s    | j  tt¡}| j | j |tƒ ¡¡ |  |¡}t| 	|j
¡ƒ}d|krXd|krX|d7 }| d¡}|d  d¡|d< |d  d¡r’|d  d7  < d |¡| S )Nrü   Ú.z.0r   Ú0)r—   r¡   r   r¦   r>  r�   r£   rå   rì   r¶   r·   ÚsplitÚrstripr®   r  )r~   Zfltrº   rØ   râ   Z	num_partsr1   r1   r2   rÑ     s    

zC89CodePrinter._print_Float©r¤   c                 C  s   dS )NÚtruer1   rô   r1   r1   r2   Ú_print_BooleanTrue  s    z!C89CodePrinter._print_BooleanTruec                 C  s   dS )NÚfalser1   rô   r1   r1   r2   Ú_print_BooleanFalse  s    z"C89CodePrinter._print_BooleanFalsec                   sˆ   |j d kr8|jd krtdƒ‚d ‡ fdd„|jD ƒ¡}n:tdd„ t|j|j ƒD ƒƒ}|jd krh||j7 }ˆ  |¡}djˆ  |j	¡|d�S )Nz%Expected strides when offset is givenz][c                 3  s   | ]}ˆ   |¡V  qd S r,   rû   rÚ   rþ   r1   r2   rÇ     s     z0C89CodePrinter._print_Element.<locals>.<genexpr>c                 s  s   | ]\}}|| V  qd S r,   r1   )rÂ   rÃ   rC  r1   r1   r2   rÇ     s     z{symb}[{idxs}])ZsymbÚidxs)
rè   rç   r  r  rê   rî   rï   r¸   r°   rE  )r~   ÚelemrR  Z
global_idxr1   rþ   r2   Ú_print_Element  s    





þzC89CodePrinter._print_Elementc                   s   d  ‡ fdd„|jD ƒ¡S )z0 Elements of code blocks printed as statements. rú   c                   s   g | ]}ˆ   ˆ  |¡¡‘qS r1   )r¯   r¸   )rÂ   rÃ   rþ   r1   r2   rÝ   +  s     z3C89CodePrinter._print_CodeBlock.<locals>.<listcomp>©r  rà   rô   r1   rþ   r2   Ú_print_CodeBlock)  s    zC89CodePrinter._print_CodeBlockc                   s   dj f |j‡ fdd„d�ŽS )Nz while ({condition}) {{
{body}
}}c                   s
   ˆ   | ¡S r,   rû   )rÛ   rþ   r1   r2   r3   /  r4   z-C89CodePrinter._print_While.<locals>.<lambda>)Úapply)r°   r€   rô   r1   rþ   r2   Ú_print_While-  s    

ÿzC89CodePrinter._print_Whilec                 C  s   d|   |j¡ S )Nz{
%s
})rV  r  rô   r1   r1   r2   Ú_print_Scope1  s    zC89CodePrinter._print_Scopezstdio.hc                   s^   |j tkrd}nddˆ  |j ¡i }|j|jtkr6dn
ˆ  |j¡d ‡ fdd„|jD ƒ¡d�S )	Nzprintf({fmt}, {pargs})z fprintf(%(out)s, {fmt}, {pargs})Úoutz%s
r<  c                 3  s   | ]}ˆ   |¡V  qd S r,   rû   rÚ   rþ   r1   r2   rÇ   >  s     z.C89CodePrinter._print_Print.<locals>.<genexpr>)ÚfmtZpargs)Úfiler$   r¸   r°   Úformat_stringr  Z
print_args)r~   r   Útemplater1   rþ   r2   Ú_print_Print4  s    
 
ÿþzC89CodePrinter._print_Printc                 C  s   |j S r,   )r¹   )r~   Ústrmr1   r1   r2   Ú_print_StreamA  s    zC89CodePrinter._print_Streamc                   sB   d  ‡ fdd„|jD ƒ¡}dt‡ fdd„|j|jfD ƒƒ|f  S )Nr<  c                 3  s   | ]}ˆ   t|ƒ¡V  qd S r,   )r¸   r   rÚ   rþ   r1   r2   rÇ   E  s     z:C89CodePrinter._print_FunctionPrototype.<locals>.<genexpr>z	%s %s(%s)c                 3  s   | ]}ˆ   |¡V  qd S r,   rû   rÚ   rþ   r1   r2   rÇ   G  s     )r  Ú
parametersÚtupleÚreturn_typer¹   )r~   r   Zparsr1   rþ   r2   Ú_print_FunctionPrototypeD  s    "ÿz'C89CodePrinter._print_FunctionPrototypec                 C  s   d|   |¡|  |¡f S ry   )re  rY  rô   r1   r1   r2   Ú_print_FunctionDefinitionJ  s    
ÿz(C89CodePrinter._print_FunctionDefinitionc                 C  s   |j \}d|  |¡ S )Nz	return %s©rà   r¸   ©r~   r   rÛ   r1   r1   r2   Ú_print_ReturnN  s    zC89CodePrinter._print_Returnc                   s   dd  ‡ fdd„|jD ƒ¡ S )Nz(%s)r<  c                 3  s   | ]}ˆ   |¡V  qd S r,   rû   rÚ   rþ   r1   r2   rÇ   S  s     z6C89CodePrinter._print_CommaOperator.<locals>.<genexpr>rU  rô   r1   rþ   r2   Ú_print_CommaOperatorR  s    z#C89CodePrinter._print_CommaOperatorc                 C  s\   |j tkrdt|jƒ S t|j jƒdkrBdt|jƒ|  |j ¡f S dt|jƒ|  |j ¡f S )Nz%s:rs   z%s:
%sz
%s:
{
%s
})r  r$   rì   r¹   r  rà   rV  rô   r1   r1   r2   Ú_print_LabelU  s
    
zC89CodePrinter._print_Labelc                 C  s   d|j j S )Nzgoto %s)rð   r¹   rô   r1   r1   r2   Ú_print_goto\  s    zC89CodePrinter._print_gotoc                 C  s   |j \}d|  |¡ S )Nz++(%s)rg  rh  r1   r1   r2   Ú_print_PreIncrement_  s    z"C89CodePrinter._print_PreIncrementc                 C  s   |j \}d|  |¡ S )Nz(%s)++rg  rh  r1   r1   r2   Ú_print_PostIncrementc  s    z#C89CodePrinter._print_PostIncrementc                 C  s   |j \}d|  |¡ S )Nz--(%s)rg  rh  r1   r1   r2   Ú_print_PreDecrementg  s    z"C89CodePrinter._print_PreDecrementc                 C  s   |j \}d|  |¡ S )Nz(%s)--rg  rh  r1   r1   r2   Ú_print_PostDecrementk  s    z#C89CodePrinter._print_PostDecrementc                   s2   d|j j|jd ‡ fdd„|jD ƒdg ¡dœ S )Nz!%(keyword)s %(name)s {
%(lines)s}z;
c                   s   g | ]}ˆ   |¡‘qS r1   rû   )rÂ   r¼   rþ   r1   r2   rÝ   r  s     z0C89CodePrinter._print_struct.<locals>.<listcomp>r’   )Úkeywordr¹   r¿   )r©   Ú__name__r¹   r  Zdeclarationsrô   r1   rþ   r2   Ú_print_structo  s      ÿÿzC89CodePrinter._print_structc                 C  s   dS )NrW   r1   ©r~   Ú_r1   r1   r2   Ú_print_BreakTokenu  s    z C89CodePrinter._print_BreakTokenc                 C  s   dS )Nr[   r1   rt  r1   r1   r2   Ú_print_ContinueTokenx  s    z#C89CodePrinter._print_ContinueToken)N)drr  Ú
__module__Ú__qualname__Ú__doc__ZprintmethodÚlanguagerÖ   r£   Úreserved_wordsr�   r%   r�   Ú__annotations__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Ô   Úknown_functions_C89r–   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Ð   rå   r|   r=  Z_print_Listr?  rH  rÑ   r&   rO  rQ  rT  rV  rX  rY  r_  ra  re  rf  ri  rj  rk  rl  rm  rn  ro  rp  rs  rv  rw  Z_print_unionÚ__classcell__r1   r1   r¨   r2   r…   “   s,  
û	   ý              ò         ÷   ý   ý ÿ
!





r…   c                   @  sÄ   e Zd ZU dZeee ƒZeee	j
 ¡ ededi ¡ ƒƒZ
eee	j ¡ edhedhi ¡ ƒƒZeZded< d ¡ Zdd	„ Zd
d„ Zdd„ Zedhdhd�eddd„ƒƒZdd„ Zdd„ Zdd„ ZdS )ÚC99CodePrinterZC99zfloat complexzdouble complexz	complex.hrŒ   r–   a  fabs fmod remainder remquo fma fmax fmin fdim nan exp exp2 expm1 log log10 log2 log1p pow sqrt cbrt hypot sin cos tan asin acos atan atan2 sinh cosh tanh asinh acosh atanh erf erfc tgamma lgamma ceil floor trunc round nearbyint rint frexp ldexp modf scalbn ilogb logb nextafter copysignc                 C  s   dS )NÚINFINITYr1   rô   r1   r1   r2   r÷   “  s    zC99CodePrinter._print_Infinityc                 C  s   dS )Nz	-INFINITYr1   rô   r1   r1   r2   rø   –  s    z&C99CodePrinter._print_NegativeInfinityc                 C  s   dS )NZNANr1   rô   r1   r1   r2   Ú
_print_NaN™  s    zC99CodePrinter._print_NaNzmath.hÚm)r¤   r¥   FNc           
   	     sD  |d krˆ j |jj }t|tƒsH|D ]\}}||jŽ r$|} qHq$tdƒ‚z|ˆ f|jžŽ W S  tk
rŒ   ˆ j| ˆ j	kr„ˆ  
t¡nd}Y nX |�rˆ  |jd ¡}t|jƒdk�r0d}|jdd… D ]*}	|d7 }|djˆ j||ˆ  |	¡d�7 }qÆ|d	ˆ  | |jd ¡¡|f 7 }nd
 ‡ fdd„|jD ƒ¡}djˆ j|||d�S )NzNo matching printerr’   r   rs   rÍ   r   z, {ns}{name}{suffix}({next})Únsr¹   rØ   Únextz, %s%sr<  c                 3  s   | ]}ˆ   |¡V  qd S r,   rû   rÚ   rþ   r1   r2   rÇ   À  s     z2C99CodePrinter._print_math_func.<locals>.<genexpr>z{ns}{name}{suffix}({args}))r„  r¹   rØ   rà   )r¢   r©   rr  rë   rì   rà   r  Ú	TypeErrorrÔ   Ú_prec_funcsrÐ   r   r¸   r  r°   r  r  )
r~   r   Únestrß   Úcbr¹   rØ   rà   Z
paren_pileZcurr_argr1   rþ   r2   rá   ž  sF    

$ü
þ
üzC99CodePrinter._print_math_funcc                 C  s   | j |dd�S ©NT)rˆ  ©rá   rô   r1   r1   r2   r&  È  s    zC99CodePrinter._print_Maxc                 C  s   | j |dd�S rŠ  r‹  rô   r1   r1   r2   r)  Ë  s    zC99CodePrinter._print_Minc              
   C  sZ   g }g }d}|D ]@}|  ||  |j¡|  |j¡|  |jd ¡dœ ¡ |  d¡ q||fS )Nz8for (int %(var)s=%(start)s; %(var)s<%(end)s; %(var)s++){rs   )r»   r  Úendrù   )r  r¸   rð   ÚlowerÚupper)r~   rê   Z
open_linesZclose_linesZ	loopstartrÃ   r1   r1   r2   Ú_get_loop_opening_endingÎ  s    

ý
z'C99CodePrinter._get_loop_opening_ending)FN)rr  rx  ry  rÖ   r£   r|  Úreserved_words_c99r�   r   r…   r�   rž   r   r   r˜   Úknown_functions_C99r–   r}  rK  r‡  r÷   rø   r‚  r&   r„   rá   r&  r)  r�  r1   r1   r1   r2   r€  }  s2   
  þ  þ(r€  z¬Abs Sqrt exp exp2 expm1 log log10 log2 log1p Cbrt hypot fma loggamma sin cos tan asin acos atan atan2 sinh cosh tanh asinh acosh atanh erf erfc loggamma gamma ceiling floorz	_print_%sc                   @  s    e Zd Zedhd�dd„ ƒZdS )ÚC11CodePrinterz
stdalign.hrM  c                 C  s   |j \}d|  |¡ S )Nzalignof(%s)rg  rh  r1   r1   r2   Ú_print_alignofä  s    zC11CodePrinter._print_alignofN)rr  rx  ry  r&   r“  r1   r1   r1   r2   r’  â  s   
r’  )Zc89Zc99Zc11N)Crz  Ú
__future__r   Útypingr   Ú	functoolsr   Ú	itertoolsr   Z
sympy.corer   Zsympy.core.numbersr   r	   Zsympy.codegen.astr
   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$   Zsympy.printing.codeprinterr%   r&   Zsympy.printing.precedencer'   r(   Zsympy.sets.fancysetsr)   r*   r+   r~  r�   r‘  r|  r�  rx   r„   r…   r€  rK  ÚkÚsetattrrá   r’  Zc_code_printersr1   r1   r1   r2   Ú<module>   sÀ   tðï                            û%   m_	ý