o
    §ƒðjƒi  ã                   @  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   ú’/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/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„ ZZd€d�„ Z[d‚dƒ„ Z\d„d…„ Z]d†d‡„ Z^dˆd‰„ Z_dŠd‹„ 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ÚPowéÿÿÿÿz%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ö   Tz¼All 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rˆd}|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ß  z¬Abs 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_þ	
ý