o
    3Ihi                     @  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_ccodeAbsc                 C  s   | j  S N
is_integerx r2   P/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/sympy/printing/c.py<lambda>(   s    r4   fabsc                 C  s   | j S r-   r.   r0   r2   r2   r3   r4   (   s    abssincostanasinacosatanatan2exploglog10sinhcoshtanhfloorceilingceilsqrtexp2expm1log2log1pCbrtcbrthypotfmaloggammalgammaerfcMaxfmaxMinfminasinhacoshatanherfgammatgamma)!autobreakcasecharconstcontinuedefaultdodoubleelseenumexternfloatforgotoifintlongregisterreturnshortsignedsizeofstaticstructentryswitchtypedefunionunsignedvoid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   )rJ   Sqrt)r?   )rG   M_EM_LOG2E      M_LN2
   M_LN10M_PIM_PI_2   M_PI_4M_1_PIM_2_PI
M_2_SQRTPIM_SQRT2	M_SQRT1_2)
sympy.codegen.cfunctionsrJ   r   &sympy.functions.elementary.exponentialr?   (sympy.functions.elementary.miscellaneousrG   r   Exp1Pi)rJ   r   r?   rG   r2   r2   r3   get_math_macros[   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methr2   r3   _meth_wrapper   s   
z+_as_macro_if_defined.<locals>._meth_wrapperr   )r   r   r2   r   r3   _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 code_ccodeCC89   TF)	precisionuser_functionscontractdereferenceerror_on_reserveddict[str, Any]_default_settingsre   rm   ri   boolint8_tint16_tint32_t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 )Nr   type_aliasesr   type_headersr   type_func_suffixestype_literal_suffixestype_math_macro_suffixesr   r   )r   popr   dictr   r   itemsr   r   r   r   r   r   super__init__r   getknown_functionsset_dereferenceheaders	librariesmacros)r   settings	__class__r2   r3   r      s<   
zC89CodePrinter.__init__c                 C  s   |d S )N   r2   )r   pr2   r2   r3   _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   
codestringr2   r2   r3   _get_statement   s   zC89CodePrinter._get_statementc                 C  s
   d |S )Nz/* {} */)format)r   textr2   r2   r3   _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declr2   r2   r3   _declare_number_const  s   
z$C89CodePrinter._declare_number_constc                 C  s
   |  |S r-   )indent_code)r   linesr2   r2   r3   _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colsr2   r3   	<genexpr>  s   $ z:C89CodePrinter._traverse_matrix_indices.<locals>.<genexpr>)shaper   )r   matrowsr2   r   r3   _traverse_matrix_indices
  s   
z'C89CodePrinter._traverse_matrix_indicesc                   s   t  j|fi |S r-   )r   
_print_Mulr   r   r2   r3   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suffixr2   r2   r3   
_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 r2   )r   r   argr   r   r2   r3   
<listcomp>&  s    z-C89CodePrinter._print_Mod.<locals>.<listcomp>z % z((z) + z) % fmod)known)argsr/   r'   is_nonnegativeis_nonpositive_print_math_func)r   r   numdensnumsdenr2   r  r3   
_print_Mod"  s   
zC89CodePrinter._print_Modc                 C  s0   t |jt |j}}| t}d||||f S )Nz%d.0%s/%d.0%s)rm   r   q_get_literal_suffixr   )r   r   r   r  r  r2   r2   r3   _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stridesr2   r   r   r   c                 s  s     | ]}|d  |d  V  qdS )r   r   Nr2   )r   r1   r2   r2   r3   r   J  s    z0C89CodePrinter._print_Indexed.<locals>.<genexpr>z%s[%s])getattrr   r   Zeroindices
isinstancestrr   r   reversedr   ranksumzipr   label)r   r   r  r  r  dimsshifttemp	traversalr   
flat_indexr2   r2   r3   _print_Indexed6  s(   

zC89CodePrinter._print_Indexedc                   s   t  |S r-   )r   _print_NumberSymbolr   r   r   r2   r3   r'  N  s   z"C89CodePrinter._print_NumberSymbolc                 C     dS )NHUGE_VALr2   r(  r2   r2   r3   _print_InfinityR     zC89CodePrinter._print_Infinityc                 C  r)  )Nz	-HUGE_VALr2   r(  r2   r2   r3   _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) {r   zelse {zelse if (%s) {}
c                   s(   g | ]\}}d   |  |f qS )z((%s) ? (
%s
)
r   )r   ecr   r2   r3   r  s  s
    

z3C89CodePrinter._print_Piecewise.<locals>.<listcomp>z: (
%s
)z:  ))r	  cond
ValueErrorhasr
   	enumerateappendr   lenjoinr   )	r   r   r   r   r1  r2  code0ecpairs	last_liner2   r3  r3   _print_PiecewiseX  s&   




"zC89CodePrinter._print_Piecewisec                 C  s    ddl m} | |j|ddS )Nr   )	PiecewiseF)deep)sympy.functionsrA  r   rewrite)r   r   rA  r2   r2   r3   
_print_ITEy  s   zC89CodePrinter._print_ITEc                 C  s2   d | j|jtd dd|j|j|jjd   S )Nz{}[{}]AtomT)strictr   )r   r   parentr(   r   r   r   r(  r2   r2   r3   _print_MatrixElement}  s
   z#C89CodePrinter._print_MatrixElementc                   s(   t  |}|| jd v rd|S |S )Nr   z(*{}))r   _print_Symbol	_settingsr   )r   r   r   r   r2   r3   rJ    s   
zC89CodePrinter._print_Symbolc                 C  s,   |  |j}|  |j}|j}d|||S )Nz{} {} {})r   lhsrhsrel_opr   )r   r   lhs_coderhs_codeopr2   r2   r3   _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   rS  r  iterabler)   r	  NotImplementedErrorrW  r   )r   r   rS  rT  rU  rV  rW  r2   r2   r3   
_print_For  s   zC89CodePrinter._print_Forc                 C  s   d | |jd S )Nz((({0}) > 0) - (({0}) < 0))r   )r   r   r	  )r   funcr2   r2   r3   _print_sign  s   zC89CodePrinter._print_signc                   ,   dj v r
|S  fdd  |jS )NrS   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	  halfinner_print_maxr   r2   r3   rf       z2C89CodePrinter._print_Max.<locals>.inner_print_maxr   r   r	  r(  r2   re  r3   
_print_Max     


zC89CodePrinter._print_Maxc                   r]  )NrU   c                   r^  )Nr   r   r   z!((%(a)s < %(b)s) ? %(a)s : %(b)s)r_  rb  rc  inner_print_minr   r2   r3   rl    rg  z2C89CodePrinter._print_Min.<locals>.inner_print_minrh  r(  r2   rk  r3   
_print_Min  rj  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.  r5  c                 S  s   g | ]}| d qS )z 	)lstripr   liner2   r2   r3   r        z.C89CodePrinter.indent_code.<locals>.<listcomp>c                       g | ]}t tt|j qS r2   )rm   anymapr   rq  )	inc_tokenr2   r3   r         c                   rt  r2   )rm   ru  rv  
startswithrq  )	dec_tokenr2   r3   r    rx  r   )r   r/  r   )r  r  r   
splitlinesr<  r9  r:  )
r   code
code_linestabincreasedecreaseprettylevelnrr  r2   )rz  rw  r3   r     s&   


zC89CodePrinter.indent_codec                 C     | j | j|| S r-   )r   r   r   r   r   r2   r2   r3   r        zC89CodePrinter._get_func_suffixc                 C  r  r-   )r   r   r   r  r2   r2   r3   r    r  z"C89CodePrinter._get_literal_suffixc                 C  s*   | j ||}| j|d}| j||S )Nr   )r   r   r   )r   r   aliasdfltr2   r2   r3   r     s   z%C89CodePrinter._get_math_macro_suffixc                   s    dd  fdd|D  d S )Nrn  , c                 3      | ]}  |V  qd S r-   r0  )r   r1  r3  r2   r3   r         z.C89CodePrinter._print_Tuple.<locals>.<genexpr>r.  )r<  r(  r2   r3  r3   _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  r2   r2   r3   _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   )r   z$C does not support untyped variablesz{vc}{t} *{pc} {r}{s}zconst r   z constz	restrict )vctpcrsz{vc}{t} {s})r  r  r  zUnknown type of var: %sz = %s)sympy.codegen.cnodesr   variabler   r   r#   r7  r  r   r   r   r   r   r   symbolr   rY  )r   r   r   r   valresultr2   r2   r3   _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 )Nr1  .z.0r   0)r   r   r   r   r  r   r   r  r  r   r   splitrstripr   r<  )r   fltr   r  r  	num_partsr2   r2   r3   r     s   

zC89CodePrinter._print_Floatr   c                 C  r)  )Ntruer2   r(  r2   r2   r3   _print_BooleanTrue     z!C89CodePrinter._print_BooleanTruec                 C  r)  )Nfalser2   r(  r2   r2   r3   _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  r  r-   r0  r  r3  r2   r3   r     r  z0C89CodePrinter._print_Element.<locals>.<genexpr>c                 s  s    | ]	\}}|| V  qd S r-   r2   )r   r   r  r2   r2   r3   r     s    z{symb}[{idxs}])symbidxs)
r  r  r7  r<  r  r  r  r   r   r  )r   elemr  
global_idxr2   r3  r3   _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 r2   )r   r   )r   r   r3  r2   r3   r  (  s    z3C89CodePrinter._print_CodeBlock.<locals>.<listcomp>r<  r	  r(  r2   r3  r3   _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-   r0  )r  r3  r2   r3   r4   ,  s   
 z-C89CodePrinter._print_While.<locals>.<lambda>)applyr2   )r   r   r(  r2   r3  r3   _print_While*  s   

zC89CodePrinter._print_Whilec                 C  s   d|  |j S )Nz{
%s
})r  rW  r(  r2   r2   r3   _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
r  c                 3  r  r-   r0  r  r3  r2   r3   r   ;  r  z.C89CodePrinter._print_Print.<locals>.<genexpr>)fmtpargs)filer$   r   r   format_stringr<  
print_args)r   r   templater2   r3  r3   _print_Print1  s   
zC89CodePrinter._print_Printc                 C  s   |j S r-   )r   )r   strmr2   r2   r3   _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 )Nr  c                 3  s    | ]
}  t|V  qd S r-   )r   r   r  r3  r2   r3   r   B  s    z:C89CodePrinter._print_FunctionPrototype.<locals>.<genexpr>z	%s %s(%s)c                 3  r  r-   r0  r  r3  r2   r3   r   D  r  )r<  
parameterstuplereturn_typer   )r   r   parsr2   r3  r3   _print_FunctionPrototypeA  s   "z'C89CodePrinter._print_FunctionPrototypec                 C  s   d|  || |f S r   )r  r  r(  r2   r2   r3   _print_FunctionDefinitionG  s   
z(C89CodePrinter._print_FunctionDefinitionc                 C     |j \}d| | S )Nz	return %sr	  r   r   r   r  r2   r2   r3   _print_ReturnK     zC89CodePrinter._print_Returnc                   s   dd  fdd|jD  S )Nz(%s)r  c                 3  r  r-   r0  r  r3  r2   r3   r   P  r  z6C89CodePrinter._print_CommaOperator.<locals>.<genexpr>r  r(  r2   r3  r3   _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:r   z%s:
%sz
%s:
{
%s
})rW  r$   r  r   r;  r	  r  r(  r2   r2   r3   _print_LabelR  s
   
zC89CodePrinter._print_Labelc                 C  s   d|j j S )Nzgoto %s)r   r   r(  r2   r2   r3   _print_gotoY  s   zC89CodePrinter._print_gotoc                 C  r  )Nz++(%s)r  r  r2   r2   r3   _print_PreIncrement\  r  z"C89CodePrinter._print_PreIncrementc                 C  r  )Nz(%s)++r  r  r2   r2   r3   _print_PostIncrement`  r  z#C89CodePrinter._print_PostIncrementc                 C  r  )Nz--(%s)r  r  r2   r2   r3   _print_PreDecrementd  r  z"C89CodePrinter._print_PreDecrementc                 C  r  )Nz(%s)--r  r  r2   r2   r3   _print_PostDecrementh  r  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 r2   r0  )r   r   r3  r2   r3   r  o  rs  z0C89CodePrinter._print_struct.<locals>.<listcomp>r   )keywordr   r   )r   __name__r   r<  declarationsr(  r2   r3  r3   _print_structl  s
   zC89CodePrinter._print_structc                 C  r)  )Nr^   r2   r   _r2   r2   r3   _print_BreakTokenr  r,  z C89CodePrinter._print_BreakTokenc                 C  r)  )Nrb   r2   r  r2   r2   r3   _print_ContinueTokenu  r,  z#C89CodePrinter._print_ContinueTokenr-   )cr  
__module____qualname____doc__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@  rE  rI  rJ  rR  rZ  r\  ri  rm  r   r   r  r   r  _print_Listr  r  r   r&   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  _print_union__classcell__r2   r2   r   r3   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 )C99CodePrinter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INFINITYr2   r(  r2   r2   r3   r+    r,  zC99CodePrinter._print_Infinityc                 C  r)  )Nz	-INFINITYr2   r(  r2   r2   r3   r-    r,  z&C99CodePrinter._print_NegativeInfinityc                 C  r)  )NNANr2   r(  r2   r2   r3   
_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   r   r   r5  z, {ns}{name}{suffix}({next})nsr   r  nextz, %s%sr  c                 3  r  r-   r0  r  r3  r2   r3   r     r  z2C99CodePrinter._print_math_func.<locals>.<genexpr>z{ns}{name}{suffix}({args}))r  r   r  r	  )r   r   r  r  r  r	  r7  	TypeErrorr   _prec_funcsr   r   r   r;  r   r[  r<  )
r   r   nestr  cbr   r  r	  
paren_pilecurr_argr2   r3  r3   r    sL   

"
zC99CodePrinter._print_math_funcc                 C     | j |ddS NT)r  r  r(  r2   r2   r3   ri       zC99CodePrinter._print_Maxc                 C  r  r  r  r(  r2   r2   r3   rm    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++){r   )r   rT  endr.  )r:  r   r   lowerupper)r   r  
open_linesclose_lines	loopstartr   r2   r2   r3   _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  r  r  r+  r-  r  r&   r   r  ri  rm  r  r2   r2   r2   r3   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.hr  c                 C  r  )Nzalignof(%s)r  r  r2   r2   r3   _print_alignof  s   zC11CodePrinter._print_alignofN)r  r  r  r&   r  r2   r2   r2   r3   r    s    
r  )c89c99c11N)Cr  
__future__r   typingr   	functoolsr   	itertoolsr   
sympy.corer   sympy.core.numbersr   r	   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$   sympy.printing.codeprinterr%   r&   sympy.printing.precedencer'   r(   sympy.sets.fancysetsr)   r*   r+   r  r   r  r  r  r   r   r   r  r  ksetattrr  r  c_code_printersr2   r2   r2   r3   <module>   s    t	

	
%   j_	
