o
    GZhi                     @  sp  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 i d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ddddddddddd d d!d"d#d#Z4e5e4fi i d$d$d%d%d&d&d'd'd(d)d*d*d+d+d,d-d.d.d/d0d1d2d3d3d4d4d5d5d6d6d7d8Z6g d9Z7d:d;gZ8d<d= Z9d>d? Z:G d@dA dAe+Z;G dBdC dCe;Z<dD= D ]Z>e?e<dEe> e<j@ qG dFdG dGe<ZAe;e<eAdHZBdIS )Ja  
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_ccodeZAbsc                 C  s   | j  S N
is_integerx r1   ?/var/www/auris/lib/python3.10/site-packages/sympy/printing/c.py<lambda>(   s    r3   fabsc                 C  s   | j S r,   r-   r/   r1   r1   r2   r3   (   s    abssincostanasinacosatanatan2exploglog10sinhcoshtanhfloorZceilingceilsqrtZexp2expm1log2log1pZCbrtZcbrthypotfmaZloggammalgammaerfcMaxZfmaxMinZfminasinhacoshatanherfgammaZtgamma)!autobreakcasecharconstcontinuedefaultdodoubleelseenumZexternfloatforZgotoifintlongregisterreturnZ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} 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   )rG   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.cfunctionsrG   ro   Z&sympy.functions.elementary.exponentialr>   Z(sympy.functions.elementary.miscellaneousrE   r   ZExp1Pi)rG   ro   r>   rE   r1   r1   r2   get_math_macros[   sH   



	

ru   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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i 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 Z5e0 fd8d9Z6d:d; Z7d<d= Z8d>d? Z9d@dA Z:dBdC Z; fdDdEZ<dFdG Z=dHdI Z>dJdK Z?dLdM Z@dNdO ZAdPdQ ZBdRdS ZCdTdU ZDdVdW ZEdXdY ZFeFZGdZd[ ZHd\d] ZId^d_ ZJeKdhd`dadb ZLeKdhd`dcdd ZMdedf ZNdgdh ZOdidj ZPdkdl ZQeKdmhd`dndo ZRdpdq ZSdrds ZTdtdu ZUdvdw ZVdxdy ZWdzd{ ZXd|d} ZYd~d ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`e^Za  ZbS )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\   rb   r_   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                   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 )Nrx   type_aliasesr   type_headersr   type_func_suffixestype_literal_suffixestype_math_macro_suffixesr   r   )rx   popru   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      
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  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colsr1   r2   	<genexpr>  s   $ z:C89CodePrinter._traverse_matrix_indices.<locals>.<genexpr>)shaper   )r{   matrowsr1   r   r2   _traverse_matrix_indices
  s   
z'C89CodePrinter._traverse_matrix_indicesc                   s   t  j|fi |S r,   )r   
_print_Mulrz   r   r1   r2   r     s   zC89CodePrinter._print_Mulc                 C  s   d| j v r
| |S t|}| t}t|jdr)d| td| 	|j
|f S t|jdr;d| j|| |j
f S |jtjd krT| jdkrTd	| j|| |j
f S d
| j|| |j
| |jf S )NPowz%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r=|jr=t|  fdd|j D \}}|jr"|js(|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)rb   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 u st|trU|j}tj}d}|dks+|d u r:t	t
|j}|d d d }n	|dkrCt
|j}|D ]}	||f7 }|||	 9 }qE|}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   rp   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   dimsshifttempZ	traversalr   Z
flat_indexr1   r1   r2   _print_Indexed6  s(   

zC89CodePrinter._print_Indexedc                   s   t  |S r,   )r   _print_NumberSymbolr{   r|   r   r1   r2   r   N  s   z"C89CodePrinter._print_NumberSymbolc                 C     dS )NZHUGE_VALr1   r   r1   r1   r2   _print_InfinityR     zC89CodePrinter._print_Infinityc                 C  r   )Nz	-HUGE_VALr1   r   r1   r1   r2   _print_NegativeInfinityU  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) {rp   zelse {zelse if (%s) {}
c                   s(   g | ]\}}d   |  |f qS )z((%s) ? (
%s
)
r   )r   ecr{   r1   r2   r   s  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_PiecewiseX  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_ITEy  s   zC89CodePrinter._print_ITEc                 C  s2   d | j|jtd dd|j|j|jjd   S )Nz{}[{}]ZAtomT)strictrp   )r   r   parentr(   r   r   r   r   r1   r1   r2   _print_MatrixElement}  s
   z#C89CodePrinter._print_MatrixElementc                   s(   t  |}|| jd v rd|S |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                   ,   dj v r
|S  fdd  |jS )NrM   c                   L   t | dkr| d S t | d }d | d |  | |d  d S )Nrp   r   rq   z!((%(a)s > %(b)s) ? %(a)s : %(b)s)abr  r   r   Zhalfinner_print_maxr{   r1   r2   r'       z2C89CodePrinter._print_Max.<locals>.inner_print_maxr   r   r   r   r1   r&  r2   
_print_Max     


zC89CodePrinter._print_Maxc                   r  )NrN   c                   r   )Nrp   r   rq   z!((%(a)s < %(b)s) ? %(a)s : %(b)s)r!  r$  r%  inner_print_minr{   r1   r2   r-    r(  z2C89CodePrinter._print_Min.<locals>.inner_print_minr)  r   r1   r,  r2   
_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v rG||	 q9||| 8 }|d|| |	f  ||| 7 }q9|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         z.C89CodePrinter.indent_code.<locals>.<listcomp>c                       g | ]}t tt|j qS r1   )rb   anymapr   r2  )	inc_tokenr1   r2   r          c                   r5  r1   )rb   r6  r7  
startswithr2  )	dec_tokenr1   r2   r     r9  r   )r   r   rw   )r   r   r   
splitlinesr  r  r  )
r{   codeZ
code_linestabZincreaseZdecreaseprettylevelnr3  r1   )r;  r8  r2   r     s&   


zC89CodePrinter.indent_codec                 C     | j | j|| S r,   )r   r   r   r{   r   r1   r1   r2   r        zC89CodePrinter._get_func_suffixc                 C  rB  r,   )r   r   r   rC  r1   r1   r2   r     rD  z"C89CodePrinter._get_literal_suffixc                 C  s*   | j ||}| j|d}| j||S )Nr   )r   r   r   )r{   r   aliasZdfltr1   r1   r2   ry     s   z%C89CodePrinter._get_math_macro_suffixc                   s    dd  fdd|D  d S )Nr/  , c                 3      | ]}  |V  qd S r,   r   )r   r   r   r1   r2   r         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   rC  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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   )rn   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})rL  rM  rO  zUnknown type of var: %sz = %s)Zsympy.codegen.cnodesrn   variabler   r   r#   r  r   r   r   r   r   r   r   symbolr   r  )r{   r   rn   r   valresultr1   r1   r2   _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)r   r   r   r   rJ  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  r   )Ntruer1   r   r1   r1   r2   _print_BooleanTrue     z!C89CodePrinter._print_BooleanTruec                 C  r   )Nfalser1   r   r1   r1   r2   _print_BooleanFalse  r\  z"C89CodePrinter._print_BooleanFalsec                   s   |j d kr|jd krtdd fdd|jD }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                 3  rG  r,   r   r   r   r1   r2   r     rH  z0C89CodePrinter._print_Element.<locals>.<genexpr>c                 s  s    | ]	\}}|| V  qd S r,   r1   )r   r   rO  r1   r1   r2   r     s    z{symb}[{idxs}])Zsymbidxs)
r   r   r  r  r   r   r   r   r   rQ  )r{   elemr_  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 di |j fdddS )Nz while ({condition}) {{
{body}
}}c                   s
     | S r,   r   )r   r   r1   r2   r3   ,  s   
 z-C89CodePrinter._print_While.<locals>.<lambda>)applyr1   )r   r}   r   r1   r   r2   _print_While*  s   

zC89CodePrinter._print_Whilec                 C  s   d|  |j S )Nz{
%s
})rc  r  r   r1   r1   r2   _print_Scope.  s   zC89CodePrinter._print_Scopezstdio.hc                   s^   |j tkrd}n
dd |j i }|j|jtkrdn |jd fdd|jD dS )	Nzprintf({fmt}, {pargs})z fprintf(%(out)s, {fmt}, {pargs})outz%s
rF  c                 3  rG  r,   r   r   r   r1   r2   r   ;  rH  z.C89CodePrinter._print_Print.<locals>.<genexpr>)fmtZpargs)filer$   r   r   format_stringr  Z
print_args)r{   r|   templater1   r   r2   _print_Print1  s   
zC89CodePrinter._print_Printc                 C  s   |j S r,   )r   )r{   strmr1   r1   r2   _print_Stream>  s   zC89CodePrinter._print_Streamc                   sB   d  fdd|jD }dt fdd|j|jfD |f  S )NrF  c                 3  s    | ]
}  t|V  qd S r,   )r   r   r   r   r1   r2   r   B  s    z:C89CodePrinter._print_FunctionPrototype.<locals>.<genexpr>z	%s %s(%s)c                 3  rG  r,   r   r   r   r1   r2   r   D  rH  )r  
parameterstuplereturn_typer   )r{   r|   Zparsr1   r   r2   _print_FunctionPrototypeA  s   "z'C89CodePrinter._print_FunctionPrototypec                 C  s   d|  || |f S rv   )rr  rf  r   r1   r1   r2   _print_FunctionDefinitionG  s   
z(C89CodePrinter._print_FunctionDefinitionc                 C     |j \}d| | S )Nz	return %sr   r   r{   r|   r   r1   r1   r2   _print_ReturnK     zC89CodePrinter._print_Returnc                   s   dd  fdd|jD  S )Nz(%s)rF  c                 3  rG  r,   r   r   r   r1   r2   r   P  rH  z6C89CodePrinter._print_CommaOperator.<locals>.<genexpr>rb  r   r1   r   r2   _print_CommaOperatorO  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:rp   z%s:
%sz
%s:
{
%s
})r  r$   r   r   r  r   rc  r   r1   r1   r2   _print_LabelR  s
   
zC89CodePrinter._print_Labelc                 C  s   d|j j S )Nzgoto %s)r   r   r   r1   r1   r2   _print_gotoY  s   zC89CodePrinter._print_gotoc                 C  rt  )Nz++(%s)ru  rv  r1   r1   r2   _print_PreIncrement\  rx  z"C89CodePrinter._print_PreIncrementc                 C  rt  )Nz(%s)++ru  rv  r1   r1   r2   _print_PostIncrement`  rx  z#C89CodePrinter._print_PostIncrementc                 C  rt  )Nz--(%s)ru  rv  r1   r1   r2   _print_PreDecrementd  rx  z"C89CodePrinter._print_PreDecrementc                 C  rt  )Nz(%s)--ru  rv  r1   r1   r2   _print_PostDecrementh  rx  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   o  r4  z0C89CodePrinter._print_struct.<locals>.<listcomp>r   )keywordr   r   )r   __name__r   r  Zdeclarationsr   r1   r   r2   _print_structl  s
   zC89CodePrinter._print_structc                 C  r   )NrU   r1   r{   _r1   r1   r2   _print_BreakTokenr  r   z C89CodePrinter._print_BreakTokenc                 C  r   )NrY   r1   r  r1   r1   r2   _print_ContinueTokenu  r   z#C89CodePrinter._print_ContinueTokenr,   )cr  
__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   rx   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   ry   rI  Z_print_ListrK  rT  r   r&   r[  r^  ra  rc  re  rf  rl  rn  rr  rs  rw  ry  rz  r{  r|  r}  r~  r  r  r  r  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  r   )NINFINITYr1   r   r1   r1   r2   r     r   zC99CodePrinter._print_Infinityc                 C  r   )Nz	-INFINITYr1   r   r1   r1   r2   r     r   z&C99CodePrinter._print_NegativeInfinityc                 C  r   )NZNANr1   r   r1   r1   r2   
_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
 fdd|jD }dj j|||dS )NzNo matching printerr   r   rp   r   r  z, {ns}{name}{suffix}({next})nsr   r   nextz, %s%srF  c                 3  rG  r,   r   r   r   r1   r2   r     rH  z2C99CodePrinter._print_math_func.<locals>.<genexpr>z{ns}{name}{suffix}({args}))r  r   r   r   )r   r   r  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     sL   

"
zC99CodePrinter._print_math_funcc                 C     | j |ddS NT)r  r   r   r1   r1   r2   r*       zC99CodePrinter._print_Maxc                 C  r  r  r  r   r1   r1   r2   r.    r  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++){rp   )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)r  r  r  r   r   r  reserved_words_c99r   r   r   r   r   r   r   r   known_functions_C99r   r  rW  r  r   r   r  r&   r   r   r*  r.  r  r1   r1   r1   r2   r  z  s8   
 (r  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.hrY  c                 C  rt  )Nzalignof(%s)ru  rv  r1   r1   r2   _print_alignof  s   zC11CodePrinter._print_alignofN)r  r  r  r&   r  r1   r1   r1   r2   r    s    
r  )Zc89Zc99Zc11N)Cr  
__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  ru   r   r   r  rW  ksetattrr   r  Zc_code_printersr1   r1   r1   r2   <module>   s    t	

	
%   j_	
