U
    9%e>i                  !   @  s&  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ 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/m0Z0 ddl)m1Z1m2Z2 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!Z3e4e3fd"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3Z5d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTg!Z6dUdVgZ7dWdX Z8dYdZ Z9G d[d\ d\e*Z:G d]d^ d^e:Z;d_< D ]Z=e>e;d`e= e;j? qG dadb dbe;Z@e:e;e@dcZAddS )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)
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   O/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sympy/printing/c.py<lambda>(       r2   fabsc                 C  s   | j S r+   r,   r.   r0   r0   r1   r2   (   r3   abssincostanasinacosatanatan2explogsinhcoshtanhfloorceilsqrt)ZAbsr6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   ZceilingrD   exp2expm1log10log2log1pZcbrthypotfmalgammaerfcZfmaxZfminasinhacoshatanherfZtgamma)rE   rF   rG   rH   rI   ZCbrtrJ   rK   ZloggammarM   MaxMinrN   rO   rP   rQ   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   )rH   Sqrt)r>   )rD   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.cfunctionsrH   rq   Z&sympy.functions.elementary.exponentialr>   Z(sympy.functions.elementary.miscellaneousrD   r   ZExp1Pi)rH   rq   r>   rD   r0   r0   r1   get_math_macros[   sH      
            
 
 rw   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methr0   r1   _meth_wrapper   s    
z+_as_macro_if_defined.<locals>._meth_wrapperr   )r   r   r0   r   r1   _as_macro_if_defined   s    	r   c                      s  e Zd ZU dZdZdZdZeeZdddi dd	de d	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-e. fd0d1Z/e.d2d3 Z0d4d5 Z1d6d7 Z2d8d9 Z3d:d; Z4e. fd<d=Z5d>d? Z6d@dA Z7dBdC Z8dDdE Z9dFdG Z: fdHdIZ;dJdK Z<dLdM Z=dNdO Z>dPdQ Z?dRdS Z@dTdU ZAdVdW ZBdXdY ZCdZd[ ZDd\d] ZEeEZFd^d_ ZGd`da ZHdbdc ZIeJdhdddedf ZKeJdhdddgdh ZLdidj ZMdkdl ZNdmdn ZOdodp ZPeJdqhdddrds ZQdtdu ZRdvdw ZSdxdy ZTdzd{ ZUd|d} ZVd~d ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^e\Z_  Z`S )C89CodePrinterz<A printer to convert Python expressions to strings of C codeZ_ccodeCC89NrU      TF_)
orderZ	full_prec	precisionuser_functionsZhumanZallow_unknown_functionsZcontractdereferenceZerror_on_reservedZreserved_word_suffixdict[str, Any]_default_settingsr]   rc   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L_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 )Nrz   type_aliasesr   type_headersr   type_func_suffixestype_literal_suffixestype_math_macro_suffixesr   r   )rz   poprw   dictr   r   itemsr   r   r   r   r   r   super__init__r   getknown_functionssetZ_dereferenceheaders	librariesmacros)r}   settings	__class__r0   r1   r      s<    
zC89CodePrinter.__init__c                 C  s   |d S )N   r0   )r}   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)r}   Z
codestringr0   r0   r1   _get_statement   s    zC89CodePrinter._get_statementc                 C  s
   d |S )Nz/* {} */)format)r}   textr0   r0   r1   _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declr0   r0   r1   _declare_number_const  s    
z$C89CodePrinter._declare_number_constc                 C  s
   |  |S r+   )indent_code)r}   linesr0   r0   r1   _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colsr0   r1   	<genexpr>  s     
  z:C89CodePrinter._traverse_matrix_indices.<locals>.<genexpr>)shaper   )r}   matrowsr0   r   r1   _traverse_matrix_indices  s    
z'C89CodePrinter._traverse_matrix_indicesc                   s   t  j|f|S r+   )r   
_print_Mulr|   r   r0   r1   r     s    zC89CodePrinter._print_Mulc                 C  s   d| j kr| |S t|}| t}t|jdrR| 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1.0%s/%sg      ?z%ssqrt%s(%s)   r   z%scbrt%s(%s)z%spow%s(%s, %s))r   _print_Functionr&   _get_func_suffixr   r   r=   _get_literal_suffixparenthesizebase_nsr   r   Onestandard)r}   r~   PRECsuffixZliteral_suffixr0   r0   r1   
_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 r0   )r   r   argr   r}   r0   r1   
<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sdenr0   r   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)rc   r   qr   r   )r}   r~   r   r   r   r0   r0   r1   _print_Rational7  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stridesr0   r   r   r   c                 S  s   g | ]}|d  |d  qS )r   rr   r0   )r   r/   r0   r0   r1   r   P  s     z1C89CodePrinter._print_Indexed.<locals>.<listcomp>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_indexr0   r0   r1   _print_Indexed<  s(    

zC89CodePrinter._print_Indexedc                 C  s   |  |jS r+   )r   r   r}   r~   r0   r0   r1   
_print_IdxT  s    zC89CodePrinter._print_Idxc                   s   t  |S r+   )r   _print_NumberSymbolr   r   r0   r1   r   W  s    z"C89CodePrinter._print_NumberSymbolc                 C  s   dS )NZHUGE_VALr0   r   r0   r0   r1   _print_Infinity[  s    zC89CodePrinter._print_Infinityc                 C  s   dS )Nz	-HUGE_VALr0   r   r0   r0   r1   _print_NegativeInfinity^  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) {rr   zelse {zelse if (%s) {}
c                   s(   g | ] \}}d   |  |f qS )z((%s) ? (
%s
)
r   )r   ecr}   r0   r1   r   |  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_liner0   r   r1   _print_Piecewisea  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
  r0   r0   r1   
_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)strictrr   )r   r   parentr'   r   r   r   r   r0   r0   r1   _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   r0   r1   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opr0   r0   r1   _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  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   )r}   funcr0   r0   r1   _print_sign  s    zC89CodePrinter._print_signc                   s,   dj kr|S  fdd  |jS )NrR   c                   sL   t | dkr| d S t | d }d | d |  | |d  d S )Nrr   r   rs   z!((%(a)s > %(b)s) ? %(a)s : %(b)s)abr  r   r   Zhalfinner_print_maxr}   r0   r1   r%    s    z2C89CodePrinter._print_Max.<locals>.inner_print_maxr   r   r   r   r0   r$  r1   
_print_Max  s    

zC89CodePrinter._print_Maxc                   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 )Nrr   r   rs   z!((%(a)s < %(b)s) ? %(a)s : %(b)s)r  r"  r#  inner_print_minr}   r0   r1   r)    s    z2C89CodePrinter._print_Min.<locals>.inner_print_minr&  r   r0   r(  r1   
_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   liner0   r0   r1   r     s     z.C89CodePrinter.indent_code.<locals>.<listcomp>c                   s    g | ]}t tt|j qS r0   )rc   anymapr   r.  )	inc_tokenr0   r1   r     s     c                   s    g | ]}t tt|j qS r0   )rc   r0  r1  
startswithr.  )	dec_tokenr0   r1   r     s     r   )r   r   ry   )r   r   r   
splitlinesr  r  r  )
r}   codeZ
code_linestabZincreaseZdecreaseprettylevelnr/  r0   )r4  r2  r1   r     s&    


zC89CodePrinter.indent_codec                 C  s   | j | j|| S r+   )r   r   r   r}   r   r0   r0   r1   r     s    zC89CodePrinter._get_func_suffixc                 C  s   | j | j|| S r+   )r   r   r   r;  r0   r0   r1   r     s    z"C89CodePrinter._get_literal_suffixc                 C  s*   | j ||}| j|d}| j||S )Nr   )r   r   r   )r}   r   aliasZdfltr0   r0   r1   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   r0   r1   r     s     z.C89CodePrinter._print_Tuple.<locals>.<genexpr>r   )r  r   r0   r   r1   _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;  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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   )rp   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})rA  rB  rD  zUnknown type of var: %sz = %s)Zsympy.codegen.cnodesrp   variabler   r   r"   r  r   r
   r   r   r   r   r   symbolr   r  )r}   r   rp   r   valresultr0   r0   r1   _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_partsr0   r0   r1   _print_Float
  s    

zC89CodePrinter._print_Floatr   c                 C  s   dS )Ntruer0   r   r0   r0   r1   _print_BooleanTrue  s    z!C89CodePrinter._print_BooleanTruec                 C  s   dS )Nfalser0   r   r0   r0   r1   _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   r0   r1   r   #  s     z0C89CodePrinter._print_Element.<locals>.<genexpr>c                 S  s   g | ]\}}|| qS r0   r0   )r   r   rD  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   rF  )r}   elemrT  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   1  s     z3C89CodePrinter._print_CodeBlock.<locals>.<listcomp>r  r   r   r0   r   r1   _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   r0   r1   r2   5  r3   z-C89CodePrinter._print_While.<locals>.<lambda>)apply)r   r   r   r0   r   r1   _print_While3  s    

zC89CodePrinter._print_Whilec                 C  s   d|  |j S )Nz{
%s
})rX  r  r   r0   r0   r1   _print_Scope7  s    zC89CodePrinter._print_Scopezstdio.hc                   s,   dj  |jd fdd|jD dS )Nzprintf({fmt}, {pargs})r=  c                 3  s   | ]}  |V  qd S r+   r   r   r   r0   r1   r   >  s     z.C89CodePrinter._print_Print.<locals>.<genexpr>)fmtZpargs)r   r   format_stringr  Z
print_argsr   r0   r   r1   _print_Print:  s    
zC89CodePrinter._print_Printc                   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   r0   r1   r   B  s     z:C89CodePrinter._print_FunctionPrototype.<locals>.<genexpr>z	%s %s(%s)c                 3  s   | ]}  |V  qd S r+   r   r   r   r0   r1   r   D  s     )r  
parameterstuplereturn_typer   )r}   r~   Zparsr0   r   r1   _print_FunctionPrototypeA  s    "z'C89CodePrinter._print_FunctionPrototypec                 C  s   d|  || |f S rx   )rb  r[  r   r0   r0   r1   _print_FunctionDefinitionG  s    
z(C89CodePrinter._print_FunctionDefinitionc                 C  s   |j \}d| | S )Nz	return %sr   r   r}   r~   r   r0   r0   r1   _print_ReturnK  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   r0   r1   r   P  s     z6C89CodePrinter._print_CommaOperator.<locals>.<genexpr>rW  r   r0   r   r1   _print_CommaOperatorO  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:rr   z%s:
%sz
%s:
{
%s
})r  r#   r   r   r  r   rX  r   r0   r0   r1   _print_LabelR  s
    
zC89CodePrinter._print_Labelc                 C  s   d|j j S )Nzgoto %s)r   r   r   r0   r0   r1   _print_gotoY  s    zC89CodePrinter._print_gotoc                 C  s   |j \}d| | S )Nz++(%s)rd  re  r0   r0   r1   _print_PreIncrement\  s    z"C89CodePrinter._print_PreIncrementc                 C  s   |j \}d| | S )Nz(%s)++rd  re  r0   r0   r1   _print_PostIncrement`  s    z#C89CodePrinter._print_PostIncrementc                 C  s   |j \}d| | S )Nz--(%s)rd  re  r0   r0   r1   _print_PreDecrementd  s    z"C89CodePrinter._print_PreDecrementc                 C  s   |j \}d| | S )Nz(%s)--rd  re  r0   r0   r1   _print_PostDecrementh  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 r0   r   )r   r   r   r0   r1   r   o  s     z0C89CodePrinter._print_struct.<locals>.<listcomp>r   )keywordr   r   )r   __name__r   r  Zdeclarationsr   r0   r   r1   _print_structl  s      zC89CodePrinter._print_structc                 C  s   dS )NrV   r0   r}   r   r0   r0   r1   _print_BreakTokenr  s    z C89CodePrinter._print_BreakTokenc                 C  s   dS )NrZ   r0   rq  r0   r0   r1   _print_ContinueTokenu  s    z#C89CodePrinter._print_ContinueToken)N)aro  
__module____qualname____doc__Zprintmethodlanguager   r   reserved_wordsr   __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   rz   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@  rI  rN  r%   rQ  rS  rV  rX  rZ  r[  r^  rb  rc  rf  rg  rh  ri  rj  rk  rl  rm  rp  rr  rs  Z_print_union__classcell__r0   r0   r   r1   r      s2  
                                 
!





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INFINITYr0   r   r0   r0   r1   r     s    zC99CodePrinter._print_Infinityc                 C  s   dS )Nz	-INFINITYr0   r   r0   r0   r1   r     s    z&C99CodePrinter._print_NegativeInfinityc                 C  s   dS )NZNANr0   r   r0   r0   r1   
_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   rr   r   r  z, {ns}{name}{suffix}({next})nsr   r   nextz, %s%sr=  c                 3  s   | ]}  |V  qd S r+   r   r   r   r0   r1   r     s     z2C99CodePrinter._print_math_func.<locals>.<genexpr>z{ns}{name}{suffix}({args}))r  r   r   r   )r   r   ro  r   r   r   r  	TypeErrorr   _prec_funcsr   r   r   r  r   r  r  )
r}   r~   nestr   cbr   r   r   Z
paren_pileZcurr_argr0   r   r1   r     sF    

$

zC99CodePrinter._print_math_funcc                 C  s   | j |ddS NT)r  r   r   r0   r0   r1   r'    s    zC99CodePrinter._print_Maxc                 C  s   | j |ddS r  r  r   r0   r0   r1   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++){rr   )r   r  endr   )r  r   r   lowerupper)r}   r   Z
open_linesZclose_linesZ	loopstartr   r0   r0   r1   _get_loop_opening_ending  s    


z'C99CodePrinter._get_loop_opening_ending)FN)ro  rt  ru  r   r   rx  reserved_words_c99r   r   r   r   r   r   r   r   known_functions_C99r   ry  rL  r  r   r   r~  r%   r   r   r'  r*  r  r0   r0   r0   r1   r|  z  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.hrO  c                 C  s   |j \}d| | S )Nzalignof(%s)rd  re  r0   r0   r1   _print_alignof  s    zC11CodePrinter._print_alignofN)ro  rt  ru  r%   r  r0   r0   r0   r1   r    s   
r  )Zc89Zc99Zc11N)Brv  
__future__r   typingr   	functoolsr   	itertoolsr   Z
sympy.corer   Zsympy.core.numbersr   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*   rz  r   r  rx  r  rw   r   r   r|  rL  ksetattrr   r  Zc_code_printersr0   r0   r0   r1   <module>   s   t                            %   j_	