U
    L?hi                  !   @  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@ qG 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   B/var/www/html/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 ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd 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rd	| j|| |j
f S d
| j|| |j
| |jf S d 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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rt
|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rt|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   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) {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rdj	t
|jkrFdnd| |jt|jkr`dnd||jkrpdnd| |jd	}nJt|trd
j	t
|jkrd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  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.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_	