o
    8Vah                     @   s  d Z ddlmZmZmZ ddlmZ ddlmZ ddl	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	l-m.Z. dd
l'm/Z/m0Z0 dd dfdd dfgdddddddddddddddZ1e2e1fi 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/d0d0d1d1d2d2d3d4Z3g d5Z4d6d7gZ5d8d9 Z6d:d; Z7G d<d= d=e(Z8G d>d? d?e8Z9d@: D ]Z;e<e9dAe; e9j= qG dBdC dCe9Z>e8e9e>dDZ?dES )Fa  
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.


    )AnyDictTuplewraps)chain)S)
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 r0   2/usr/lib/python3/dist-packages/sympy/printing/c.py<lambda>&   s    r2   Zfabsc                 C   s   | j S r+   r,   r.   r0   r0   r1   r2   &   s    abssincostanasinacosatanatan2explogsinhcoshtanhfloorZceil)ZAbsr4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   ZceilingZexp2Zexpm1Zlog10log2Zlog1pZCbrtZcbrtZhypotZfmaZloggammaZlgammaZerfcMaxZfmaxMinZfminZasinhZacoshZatanhZerfZgammaZtgamma)!autobreakcasecharconstcontinuedefaultZdodoubleelseenumZexternfloatforZgotoifintZlongregisterreturnZshortZsignedZsizeofZstaticstructentryZswitchZtypedefunionZunsignedZvoidZvolatilewhileZinlinerestrictc                  C   s   ddl m} m} ddlm} ddlm} i 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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   )rA   Sqrt)r<   )sqrtZ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.cfunctionsrA   rY   Z&sympy.functions.elementary.exponentialr<   Z(sympy.functions.elementary.miscellaneousrZ   r   ZExp1ZPi)rA   rY   r<   rZ   r0   r0   r1   get_math_macrosX   sH   



	

r_   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 v rd| j | | tf S  | |fi |S N%s%s)math_macros_get_math_macro_suffixr   selfexprkwargsmethr0   r1   _meth_wrapper   s   
z+_as_macro_if_defined.<locals>._meth_wrapperr   )ri   rj   r0   rh   r1   _as_macro_if_defined}   s   	rk   c                       s  e Zd ZdZdZdZdZeeZdddi dd	de d	d
d
Z	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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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 fdd	Z&dd Z'dd  Z(d!d" Z)d#d$ Z*d%d& Z+d'd( Z,e- fd)d*Z.e-d+d, Z/d-d. Z0d/d0 Z1d1d2 Z2d3d4 Z3e- fd5d6Z4d7d8 Z5d9d: Z6d;d< Z7d=d> Z8d?d@ Z9 fdAdBZ:dCdD Z;dEdF Z<dGdH Z=dIdJ Z>dKdL Z?dMdN Z@dOdP ZAdQdR ZBdSdT ZCdUdV ZDdWdX ZEdYdZ ZFd[d\ ZGeHdhd]d^d_ ZIeHdhd]d`da ZJdbdc ZKddde ZLdfdg ZMdhdi ZNeHdjhd]dkdl ZOdmdn ZPdodp ZQdqdr ZRdsdt ZSdudv ZTdwdx ZUdydz ZVd{d| ZWd}d~ ZXdd ZYdd ZZdd Z[dd Z\eZZ]  Z^S )C89CodePrinterz<A printer to convert python expressions to strings of c codeZ_ccodeCC89NrD      TF_)
ZorderZ	full_precZ	precisionuser_functionsZhumanZallow_unknown_functionsZcontractdereferenceZerror_on_reservedZreserved_word_suffixrK   rQ   rN   boolZint8_tZint16_tZint32_tZint64_tz	stdbool.hzstdint.hf lFLc                    sf  |pi }| j d u 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i |d	i | _t|d
g | _t | _t | _t | _d S )Nrb   type_aliasestype_mappingstype_headerstype_macrostype_func_suffixestype_literal_suffixestype_math_macro_suffixesrq   rr   )rb   popr_   dictr   ry   itemsrz   r{   r|   r}   r~   r   super__init___kfgetknown_functionssetZ_dereferenceheaders	librariesmacros)re   Zsettings	__class__r0   r1   r      s<   
zC89CodePrinter.__init__c                 C   s   |d S )N   r0   )re   pr0   r0   r1   _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)re   Z
codestringr0   r0   r1   _get_statement   s   zC89CodePrinter._get_statementc                 C   s
   d |S )Nz// {})format)re   textr0   r0   r1   _get_comment      
zC89CodePrinter._get_commentc                 C   s<   | j t }t||||jthd}t|}| | |S )N)typevalueattrs)	ry   r   r   evalfdecimal_digr   r   r   _print)re   namer   type_vardeclr0   r0   r1   _declare_number_const  s   
z$C89CodePrinter._declare_number_constc                 C   s
   |  |S r+   )indent_code)re   linesr0   r0   r1   _format_code	  r   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Zcolsr0   r1   	<genexpr>  s   $ z:C89CodePrinter._traverse_matrix_indices.<locals>.<genexpr>)shaper   )re   ZmatZrowsr0   r   r1   _traverse_matrix_indices  s   
z'C89CodePrinter._traverse_matrix_indicesc                    s   t  j|fi |S r+   )r   
_print_Mulrd   r   r0   r1   r     s   zC89CodePrinter._print_Mulc                 C   s   d| j v r
| |S t|}| t}|jdkr(| t}d|| |j|f S |jdkr9d| j	|| 
|jf S |jtjd krR| jdkrRd| j	|| 
|jf S d	| j	|| 
|j| 
|jf S )
NZPowz1.0%s/%sg      ?z%ssqrt%s(%s)   rn   z%scbrt%s(%s)z%spow%s(%s, %s))r   _print_Functionr&   _get_func_suffixr   r;   _get_literal_suffixparenthesizebase_nsr   r   Onestandard)re   rf   ZPRECsuffixZliteral_suffixr0   r0   r1   
_print_Pow  s   






zC89CodePrinter._print_Powc                 C   s<   |j \}}|jr|jrd| || |S | j|ddS )Nz(({}) % ({}))Zfmod)known)argsr-   r   r   _print_math_func)re   rf   numZdenr0   r0   r1   
_print_Mod%  s   
zC89CodePrinter._print_Modc                 C   s0   t |jt |j}}| t}d||||f S )Nz%d.0%s/%d.0%s)rQ   r   qr   r   )re   rf   r   r   r   r0   r0   r1   _print_Rational,  s   
zC89CodePrinter._print_Rationalc                 C   s   t |jdtj}t |jdd }|j}|d u st|trV|j}tj}t	 }|dks,|d u r;t
t|j}|d d d }n	|dkrDt|j}|D ]}	||f7 }|||	 9 }qF|}tdd t||D | }
d| |jj| |
f S )	Noffsetstridesrm   r   rw   c                 S   s   g | ]
}|d  |d  qS )r   r[   r0   )r   r/   r0   r0   r1   
<listcomp>E      z1C89CodePrinter._print_Indexed.<locals>.<listcomp>z%s[%s])getattrr   r   ZZeroindices
isinstancestrr   r   tuplereversedr   Zranksumzipr   label)re   rf   r   r   r   ZdimsshiftZtempZ	traversalr   Z
flat_indexr0   r0   r1   _print_Indexed1  s(   

zC89CodePrinter._print_Indexedc                 C   s   |  |jS r+   )r   r   re   rf   r0   r0   r1   
_print_IdxI     zC89CodePrinter._print_Idxc                    s   t  |S r+   )r   _print_NumberSymbolr   r   r0   r1   r   L  s   z"C89CodePrinter._print_NumberSymbolc                 C      dS )NZHUGE_VALr0   r   r0   r0   r1   _print_InfinityP     zC89CodePrinter._print_Infinityc                 C   r   )Nz	-HUGE_VALr0   r   r0   r0   r1   _print_NegativeInfinityS  r   z&C89CodePrinter._print_NegativeInfinityc           	         s  |j d jdkrtdg }|tr_t|j D ]A\}\}}|dkr-|d |  n|t|j d kr@|dkr@|d n
|d |   |}|| |d	 qd
	|S  fdd|j d d D }d |j d j
 }d	|| d	dt| g 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.r   z	if (%s) {r[   zelse {zelse if (%s) {}
c                    s(   g | ]\}}d   |  |f qS )z((%s) ? (
%s
)
r   )r   ecre   r0   r1   r   q  s
    

z3C89CodePrinter._print_Piecewise.<locals>.<listcomp>z: (
%s
)z:  ))r   Zcond
ValueErrorZhasr	   	enumerateappendr   lenjoinrf   )	re   rf   r   r   r   r   Zcode0Zecpairs	last_liner0   r   r1   _print_PiecewiseV  s&   




"zC89CodePrinter._print_Piecewisec                 C   s:   ddl m} ||jd |jd f|jd df}| |S )Nr   	Piecewiser[   r\   T)sympy.functionsr   r   r   )re   rf   r   
_piecewiser0   r0   r1   
_print_ITEw  s   $
zC89CodePrinter._print_ITEc                 C   s2   d | j|jtd dd|j|j|jjd   S )Nz{}[{}]ZAtomT)strictr[   )r   r   parentr'   r   r   r   r   r0   r0   r1   _print_MatrixElement|  s
   z#C89CodePrinter._print_MatrixElementc                    s(   t  |}|| jd v rd|S |S )Nrr   z(*{}))r   _print_SymbolZ	_settingsr   )re   rf   r   r   r0   r1   r     s   
zC89CodePrinter._print_Symbolc                 C   s,   |  |j}|  |j}|j}d|||S )Nz{} {} {})r   ZlhsZrhsZrel_opr   )re   rf   Zlhs_codeZrhs_codeopr0   r0   r1   _print_Relational  s   z C89CodePrinter._print_Relationalc                 C   s\   ddl m} ddlm} ddlm} |||jd |jd  ||jd dfd}| |S )Nr   )r4   )Ner   )r[   T)Z(sympy.functions.elementary.trigonometricr4   Zsympy.core.relationalr   r   r   r   r   )re   rf   r4   r   r   r   r0   r0   r1   _print_sinc  s   (
zC89CodePrinter._print_sincc                 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   )re   rf   r   r   r   r   r   r0   r0   r1   
_print_For  s   zC89CodePrinter._print_Forc                 C   s   d | |jd S )Nz((({0}) > 0) - (({0}) < 0))r   )r   r   r   )re   funcr0   r0   r1   _print_sign  s   zC89CodePrinter._print_signc                    ,   dj v r
|S  fdd  |jS )NrB   c                    L   t | dkr| d S t | d }d | d |  | |d  d S )Nr[   r   r\   z!((%(a)s > %(b)s) ? %(a)s : %(b)s)abr   r   r   Zhalfinner_print_maxre   r0   r1   r       z2C89CodePrinter._print_Max.<locals>.inner_print_maxr   r   r   r   r0   r  r1   
_print_Max     


zC89CodePrinter._print_Maxc                    r   )NrC   c                    r   )Nr[   r   r\   z!((%(a)s < %(b)s) ? %(a)s : %(b)s)r  r  r  inner_print_minre   r0   r1   r    r  z2C89CodePrinter._print_Min.<locals>.inner_print_minr	  r   r0   r  r1   
_print_Min  r  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 ])\}}	|	dksE|	dkrK||	 q9||| 8 }|d|| |	f  ||| 7 }q9|S )z0Accepts a string of code or a list of code linesTru   z   ){(z{
z(
)r   r   c                 S   s   g | ]}| d qS )z 	)lstripr   liner0   r0   r1   r         z.C89CodePrinter.indent_code.<locals>.<listcomp>c                        g | ]}t tt|j qS r0   )rQ   anymapr   r  )	inc_tokenr0   r1   r          c                    r  r0   )rQ   r  r  
startswithr  )	dec_tokenr0   r1   r     r  r   r   ra   )r   r   r   
splitlinesr   r   r   )
re   codeZ
code_linesZtabZincreaseZdecreaseZprettylevelnr  r0   )r  r  r1   r     s&   


zC89CodePrinter.indent_codec                 C      | j | j|| S r+   )r}   ry   r   re   r   r0   r0   r1   r        zC89CodePrinter._get_func_suffixc                 C   r   r+   )r~   ry   r   r!  r0   r0   r1   r     r"  z"C89CodePrinter._get_literal_suffixc                 C   s*   | j ||}| j|d}| j||S )Nru   )ry   r   r   )re   r   aliasZdfltr0   r0   r1   rc     s   z%C89CodePrinter._get_math_macro_suffixc                 C   sF   | j | j|t  | j| j|t  | | j||j	S r+   )
r   updater{   r   r   r   r|   r   rz   r   r!  r0   r0   r1   _print_Type  s   zC89CodePrinter._print_Typec                 C   s   ddl m} |j}|j}|jtkrtdt|trBdj	t
|jv r#dnd| |jt|jv r0dnd||jv r8dnd| |jd	}n%t|tr_d
j	t
|jv rPdnd| |j| |jd}ntdt| |d krt|d| | 7 }|S )Nr   )rX   z$C does not support untyped variablesz{vc}{t} *{pc} {r}{s}zconst ru   z constz	restrict )vctZpcrsz{vc}{t} {s})r&  r'  r)  zUnknown type of var: %sz = %s)Zsympy.codegen.cnodesrX   variabler   r   r"   r   r   r
   r   r   r   r   r   symbolr   r   )re   r   rX   r   valresultr0   r0   r1   _print_Declaration  s.   






z!C89CodePrinter._print_Declarationc                 C   s   | j tt}| j| j|t  | |}t|	|j
}d|vr,d|vr,|d7 }|d}|d d|d< |d drI|d  d7  < d|| S )Nr   .z.0r   0)ry   r   r   r   r$  r|   r   r   r   r   r   splitrstripr   r   )re   Zfltr   r   r   Z	num_partsr0   r0   r1   _print_Float  s   

zC89CodePrinter._print_Floatr   c                 C   r   )Ntruer0   r   r0   r0   r1   _print_BooleanTrue     z!C89CodePrinter._print_BooleanTruec                 C   r   )NZfalser0   r   r0   r0   r1   _print_BooleanFalse  r7  z"C89CodePrinter._print_BooleanFalsec                    s   |j d kr|jd krtddt fdd|j}ntdd t|j|j D }|jd kr4||j7 } |}dj	 |j
|dS )	Nz%Expected strides when offset is givenz][c                    
     | S r+   r   argr   r0   r1   r2        
 z/C89CodePrinter._print_Element.<locals>.<lambda>c                 S   s   g | ]\}}|| qS r0   r0   )r   r   r)  r0   r0   r1   r     s    z1C89CodePrinter._print_Element.<locals>.<listcomp>z{symb}[{idxs}])Zsymbidxs)r   r   r   r   r  r   r   r   r   r   r+  )re   elemr=  Z
global_idxr0   r   r1   _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 r0   )r   r   )r   r   r   r0   r1   r   +  r   z3C89CodePrinter._print_CodeBlock.<locals>.<listcomp>)r   r   r   r0   r   r1   _print_CodeBlock)  s   zC89CodePrinter._print_CodeBlockc                    s    dj di |j fdddS )Nz while ({condition}) {{
{body}
}}c                    r9  r+   r   r:  r   r0   r1   r2   /  r<  z-C89CodePrinter._print_While.<locals>.<lambda>)Zapplyr0   )r   rg   r   r0   r   r1   _print_While-  s   

zC89CodePrinter._print_Whilec                 C   s   d|  |j S )Nz{
%s
})r@  r   r   r0   r0   r1   _print_Scope1  s   zC89CodePrinter._print_Scopezstdio.hc                    s,   dj  |jdt fdd|jdS )Nzprintf({fmt}, {pargs}), c                    r9  r+   r   r:  r   r0   r1   r2   8  r<  z-C89CodePrinter._print_Print.<locals>.<lambda>)ZfmtZpargs)r   r   format_stringr   r  Z
print_argsr   r0   r   r1   _print_Print4  s   
zC89CodePrinter._print_Printc                    sB   d t fdd|j}dtt fdd|j|jf|f  S )NrC  c                    s     t| S r+   )r   r   r:  r   r0   r1   r2   <  s    z9C89CodePrinter._print_FunctionPrototype.<locals>.<lambda>z	%s %s(%s)c                    r9  r+   r   r:  r   r0   r1   r2   ?  r<  )r   r  Z
parametersr   Zreturn_typer   )re   rf   Zparsr0   r   r1   _print_FunctionPrototype;  s   
z'C89CodePrinter._print_FunctionPrototypec                 C   s   d|  || |f S r`   )rF  rB  r   r0   r0   r1   _print_FunctionDefinitionC  s   
z(C89CodePrinter._print_FunctionDefinitionc                 C      |j \}d| | S )Nz	return %sr   r   re   rf   r;  r0   r0   r1   _print_ReturnG     zC89CodePrinter._print_Returnc                    s   dd t fdd|j S )Nz(%s)rC  c                    r9  r+   r   r:  r   r0   r1   r2   L  r<  z5C89CodePrinter._print_CommaOperator.<locals>.<lambda>)r   r  r   r   r0   r   r1   _print_CommaOperatorK  s   z#C89CodePrinter._print_CommaOperatorc                 C   s\   |j tkrdt|j S t|j jdkr!dt|j| |j f S dt|j| |j f S )Nz%s:r[   z%s:
%sz
%s:
{
%s
})r   r#   r   r   r   r   r@  r   r0   r0   r1   _print_LabelN  s
   
zC89CodePrinter._print_Labelc                 C   s   d|j j S )Nzgoto %s)r   r   r   r0   r0   r1   _print_gotoU  r   zC89CodePrinter._print_gotoc                 C   rH  )Nz++(%s)rI  rJ  r0   r0   r1   _print_PreIncrementX  rL  z"C89CodePrinter._print_PreIncrementc                 C   rH  )Nz(%s)++rI  rJ  r0   r0   r1   _print_PostIncrement\  rL  z#C89CodePrinter._print_PostIncrementc                 C   rH  )Nz--(%s)rI  rJ  r0   r0   r1   _print_PreDecrement`  rL  z"C89CodePrinter._print_PreDecrementc                 C   rH  )Nz(%s)--rI  rJ  r0   r0   r1   _print_PostDecrementd  rL  z#C89CodePrinter._print_PostDecrementc              	      s4   dt |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 r0   r   )r   r   r   r0   r1   r   k  r  z0C89CodePrinter._print_struct.<locals>.<listcomp>ru   )keywordr   r   )r   r   __name__r   r   Zdeclarationsr   r0   r   r1   _print_structh  s
   zC89CodePrinter._print_structc                 C   r   )NrE   r0   re   rp   r0   r0   r1   _print_BreakTokenn  r   z C89CodePrinter._print_BreakTokenc                 C   r   )NrI   r0   rW  r0   r0   r1   _print_ContinueTokenq  r   z#C89CodePrinter._print_ContinueTokenr+   )_rU  
__module____qualname____doc__Zprintmethodlanguager   r   reserved_wordsZ_default_settingsr   r   r   r   r   r   ry   r   r   r   r   r   r   r   r   r    r!   rz   r{   r|   r   r}   r~   r   rb   r   known_functions_C89r   r   r   r   r   r   r   r   rk   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
  r  r   r   r   rc   r%  r.  r3  r%   r6  r8  r?  r@  rA  rB  rE  rF  rG  rK  rM  rN  rO  rP  rQ  rR  rS  rV  rX  rY  Z_print_union__classcell__r0   r0   r   r1   rl      s    
!





rl   c                   @   s   e Zd Z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 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.ha  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   r   )NZINFINITYr0   r   r0   r0   r1   r     r   zC99CodePrinter._print_Infinityc                 C   r   )Nz	-INFINITYr0   r   r0   r0   r1   r     r   z&C99CodePrinter._print_NegativeInfinityc                 C   r   )NZNANr0   r   r0   r0   r1   
_print_NaN  r   zC99CodePrinter._print_NaNzmath.hm)r   r   FNc           
   	      s@  |d u r j |jj }t|ts$|D ]\}}||j r|} nqtdz
| g|jR  W S  tyF    j|  j	v rB 
tnd}Y nw |r |jd }t|jdkrd}|jdd D ]}	|d7 }|dj j|| |	d7 }qa|d	 ||jd |f 7 }nd
t fdd|j}dj j|||dS )NzNo matching printerru   r   r[   r   r   z, {ns}{name}{suffix}({next})nsr   r   nextz, %s%srC  c                    r9  r+   r   r:  r   r0   r1   r2     r<  z1C99CodePrinter._print_math_func.<locals>.<lambda>z{ns}{name}{suffix}({args}))rd  r   r   r   )r   r   rU  r   r   r   r   	TypeErrorr   _prec_funcsr   r   r   r   r   r   r   r  )
re   rf   nestr   cbr   r   r   Z
paren_pileZcurr_argr0   r   r1   r     sL   

"
zC99CodePrinter._print_math_funcc                 C      | j |ddS NT)rh  r   r   r0   r0   r1   r
       zC99CodePrinter._print_Maxc                 C   rj  rk  rl  r   r0   r0   r1   r    rm  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++){r[   )r   r   endr   )r   r   r   lowerupper)re   r   Z
open_linesZclose_linesZ	loopstartr   r0   r0   r1   _get_loop_opening_ending  s   


z'C99CodePrinter._get_loop_opening_ending)FN)rU  rZ  r[  r   r   r^  reserved_words_c99r   r   rl   rz   r   r   r   r{   known_functions_C99r   r1  rg  r   r   rb  r%   rk   r   r
  r  rq  r0   r0   r0   r1   ra  v  s8    (ra  zAbs 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.hr4  c                 C   rH  )Nzalignof(%s)rI  rJ  r0   r0   r1   _print_alignof  s   zC11CodePrinter._print_alignofN)rU  rZ  r[  r%   ru  r0   r0   r0   r1   rt    s    
rt  )Zc89Zc99Zc11N)@r\  typingr   r   r   	functoolsr   	itertoolsr   Z
sympy.corer   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   rs  r^  rr  r_   rk   rl   ra  r1  ksetattrr   rt  Zc_code_printersr0   r0   r0   r1   <module>   s    t
	
%   i_	
