
    gi                       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f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!Z4 e5e4fi i d"d"d#d#d$d$d%d%d&d&d'd(d)d)d*d*d+d,d-d-d.d/d0d1d2d2d3d3d4d4d5d5d6d7Z6g d8Z7d9d:gZ8d; Z9d< Z: G d= d>e+          Z; G d? d@e;          Z<dA=                                D ]Z> e?e<dBe>z  e<j@                    G dC dDe<          ZAe;e<eAdEZBdFS )Ga  
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                    | j          S N
is_integerxs    L/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/printing/c.py<lambda>r5   (   s    1<'     fabsc                    | j         S r/   r0   r2   s    r4   r5   r5   (   s    Q\ r6   abssincostanasinacosatanatan2explogsinhcoshtanhfloorceilingceilsqrtexp2expm1log10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                 ,   ddl m} m} ddlm} ddlm} i t          j        d | t          j                  dd |d          z  d |d          d	 |d
          dt          j	        dt          j	        dz  dt          j	        dz  ddt          j	        z  ddt          j	        z  dd |t          j	                  z  dd |t          j	                  z  d |d          d |d          dd |d          z  dd |d          z  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   )rM   Sqrt)rB   )rI   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.cfunctionsrM   r   &sympy.functions.elementary.exponentialrB   (sympy.functions.elementary.miscellaneousrI   r   Exp1Pi)rM   r   rB   rI   s       r4   get_math_macrosr   [   s    43333333::::::======	QVi 	
##a&&) 	A	
 	B 	
f 	
Q 	
Q 	
!$ 	
!$ 	
$$qt**l 	
$$qt**l 	Q 	Q 	
$$q''	;  	
$$q''	;! r6   c                <     t                      f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                |    || j         v r)| j         |         |                     t                    S  | |fi |S r/   )math_macros_get_math_macro_suffixr   )selfexprkwargsmeths      r4   _meth_wrapperz+_as_macro_if_defined.<locals>._meth_wrapper   sS    4###!-d33T5P5PQU5V5V5VWW4d--f---r6   r   )r   r   s   ` r4   _as_macro_if_definedr      s6     4[[. . . . [. r6   c                  Z    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<   dX fd 	Z)d! Z*d" Z+d# Z,d$ Z-d% Z.d& Z/e0 fd'            Z1e0d(             Z2d) Z3d* Z4d+ Z5d, Z6e0 fd-            Z7d. Z8d/ Z9d0 Z:d1 Z;d2 Z< fd3Z=d4 Z>d5 Z?d6 Z@d7 ZAd8 ZBd9 ZCd: ZDd; ZEd< ZFd= ZGeGZHd> ZId? ZJd@ ZK eLdhA          dB             ZM eLdhA          dC             ZNdD ZOdE ZPdF ZQdG ZR eLdHhA          dI             ZSdJ ZTdK ZUdL ZVdM ZWdN ZXdO ZYdP ZZdQ Z[dR Z\dS Z]dT Z^dU Z_dV Z`dW Zae_Zb xZcS )Y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_settingsrh   rp   rl   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           	        |pi }| j         '|                    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__s     r4   r   zC89CodePrinter.__init__   s   >r#'||M?;L;LMMD t'8'>'>'@'@'/||NB'G'G'M'M'O'O"Q "Q R R!%(:(@(@(B(B(0_b(I(I(O(O(Q(Q#S #S T T t'8'>'>'@'@'/||NB'G'G'M'M'O'O"Q "Q R Rd&6&<&<&>&>'/||M2'F'F'L'L'N'N!P !P Q Q"&uT-D-J-J-L-L(05I2(N(N(T(T(V(V(X (X #Y #Y%)%0J0P0P0R0R(05Lb(Q(Q(W(W(Y(Y+[ +[ &\ &\"(,U43P3V3V3X3X(05OQS(T(T(Z(Z(\(\.^ .^ )_ )_%"""#DHSS=Mr0R0RSS]B ? ?@@uueer6   c                    |dz  S )N    )r   ps     r4   _rate_index_positionz#C89CodePrinter._rate_index_position   s    s
r6   c                :    |                     d          r|n|dz   S )z@ Get code string as a statement - i.e. ending with a semicolon. ;)endswith)r   
codestrings     r4   _get_statementzC89CodePrinter._get_statement   s$    '0055Kzz:;KKr6   c                ,    d                     |          S )Nz/* {} */)format)r   texts     r4   _get_commentzC89CodePrinter._get_comment   s      &&&r6   c                    | j         t                   }t          |||                    |j                  t
          h          }t          |          }|                     |                     |                    S )N)typevalueattrs)	r   r   r   evalfdecimal_digr   r   r   _print)r   namer   type_vardecls         r4   _declare_number_constz$C89CodePrinter._declare_number_const  se    !$'t%u{{5;L/M/MVaUbccc3""4;;t#4#4555r6   c                ,    |                      |          S r/   )indent_code)r   liness     r4   _format_codezC89CodePrinter._format_code  s    &&&r6   c                N    |j         \  }fdt          |          D             S )Nc              3  D   K   | ]}t                    D ]}||fV  	d S r/   )range).0ijcolss      r4   	<genexpr>z:C89CodePrinter._traverse_matrix_indices.<locals>.<genexpr>  s:      AA1U4[[AAAAAAAAAAr6   )shaper   )r   matrowsr   s      @r4   _traverse_matrix_indicesz'C89CodePrinter._traverse_matrix_indices
  s.    Y
dAAAAdAAAAr6   c                8     t                      j        |fi |S r/   )r   
_print_Mul)r   r   r   r   s      r4   r   zC89CodePrinter._print_Mul  s"    !uww!$11&111r6   c           	        d| j         v r|                     |          S t          |          }|                     t                    }t          |j        d          r@|                     t          d                    d| 	                    |j
        |          S t          |j        d          r(| j        d|d|                     |j
                  dS |j        t          j        d	z  k    r3| j        d
k    r(| j        d|d|                     |j
                  dS | j        d|d|                     |j
                  d|                     |j                  dS )NPowg      ?/g      ?rI   ()   r   rP   pow, )r   _print_Functionr(   _get_func_suffixr   r	   rA   _print_Floatr
   parenthesizebase_nsr   r   Onestandard)r   r   PRECsuffixs       r4   
_print_PowzC89CodePrinter._print_Pow  sb   D(((''---$&&t,,"%% 	:"//c

;;;;T=N=NtyZ^=_=_=_``$(C(( 	:%)XXXvvvt{{497M7M7M7MNNXq  T]e%;%;%)XXXvvvt{{497M7M7M7MNN(,&&&$++di:P:P:P:P#';;tx#8#8#8#8: :r6   c                    |j         \  }}|j        r^|j        rWt          |           fd|j         D             \  }}|j        r|j        s|j        r|j        r| d| S d| d| d| d| S                      |d          S )Nc                <    g | ]}                     |          S r   )r  )r   argr  r   s     r4   
<listcomp>z-C89CodePrinter._print_Mod.<locals>.<listcomp>&  s)    LLL3$++C66LLLr6   z % ((z) + z) % fmod)known)argsr1   r(   is_nonnegativeis_nonpositive_print_math_func)r   r   numdensnumsdenr  s   `     @r4   
_print_ModzC89CodePrinter._print_Mod"  s    9S> 		<cn 		<d##DLLLLL$)LLLJD$ " *s'9 *"*'*'9*))4)));;;;;4;;T;;;$$T$888r6   c                    t          |j                  t          |j                  }}|                     t                    }d||||fz  S )Nz%d.0%s/%d.0%s)rp   r   q_get_literal_suffixr   )r   r   r   r$  r  s        r4   _print_RationalzC89CodePrinter._print_Rational1  sB    46{{CKK1))$//!VQ!777r6   c                f   t          |j        dt          j                  }t          |j        dd           }|j        }|t          |t                    r||j        }t          j        }d}|dk    s|-t          t          |j                            }|d d d         }n|dk    rt          |j                  }|D ]}	||fz  }|||	         z  }|}t          d t          ||          D                       |z   }
|                     |j        j                  d|                     |
          d	S )
Noffsetstridesr   r   r  r   c              3  8   K   | ]}|d          |d         z  V  dS )r   r   Nr   )r   r3   s     r4   r   z0C89CodePrinter._print_Indexed.<locals>.<genexpr>J  s.      BBq1adBBBBBBr6   [])getattrr  r   Zeroindices
isinstancestrr   r  reversedr   ranksumzipr   label)r   r   r(  r)  r/  dimsshifttemp	traversalr   
flat_indexs              r4   _print_IndexedzC89CodePrinter._print_Indexed6  s7   Haf55$)Y55,?j#66?:DEED#~~$U49%5%566	!$$B$-C!$),,	 ! ! a GBBC,A,ABBBBBVK
;;ty7777;;z22224 	4r6   c                6    |                      |j                  S r/   )r   r6  r   r   s     r4   
_print_IdxzC89CodePrinter._print_IdxN  s    {{4:&&&r6   c                F    t                                          |          S r/   )r   _print_NumberSymbol)r   r   r   s     r4   rA  z"C89CodePrinter._print_NumberSymbolQ  s    ww**4000r6   c                    dS )NHUGE_VALr   r>  s     r4   _print_InfinityzC89CodePrinter._print_InfinityU      zr6   c                    dS )Nz	-HUGE_VALr   r>  s     r4   _print_NegativeInfinityz&C89CodePrinter._print_NegativeInfinityX      {r6   c                    |j         d         j        dk    rt          d          g }|                    t                    rt          |j                   D ]\  }\  }}|dk    r,|                    d                     |          z             nb|t          |j                   dz
  k    r|dk    r|                    d           n+|                    d                     |          z                                  |          }|                    |           |                    d	           d
	                    |          S  fd|j         d d         D             }d                     |j         d         j
                  z  }d	                    |          |z   d	                    dt          |          z  g          z   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                t    g | ]4\  }}d                      |          d                     |          d5S )r  z) ? (
z
)
r   )r   ecr   s      r4   r  z3C89CodePrinter._print_Piecewise.<locals>.<listcomp>v  sS     0 0 011 04{{1~~~~/3{{1~~~~? 0 0 0r6   z: (
%s
)z:  r  )r  cond
ValueErrorhasr   	enumerateappendr   lenjoinr   )	r   r   r   r   rN  rO  code0ecpairs	last_lines	   `        r4   _print_PiecewisezC89CodePrinter._print_Piecewise[  s   9R=%%  / 0 0 0
 88J 	Q&ty11 	" 	"	6Aq66LLt{{1~~!=>>>>#di..1,,,dLL****LL!1DKKNN!BCCCAU###S!!!!99U###0 0 0 0 $	#2#0 0 0G %t{{49R=3E'F'FFI99W%%	1CHHc#g,,>N=O4P4PPPr6   c                b    ddl m} |                     |                    |d                    S )Nr   )	PiecewiseF)deep)sympy.functionsr]  r   rewrite)r   r   r]  s      r4   
_print_ITEzC89CodePrinter._print_ITE|  s6    ------{{4<<	<>>???r6   c                    d                     |                     |j        t          d         d          |j        |j        |j        j        d         z  z             S )Nz{}[{}]AtomT)strictr   )r   r  parentr)   r   r   r   r>  s     r4   _print_MatrixElementz#C89CodePrinter._print_MatrixElement  s[    t00j>P  1    &46$+*;A*>#>>@ @ 	@r6   c                    t                                          |          }|| j        d         v rd                    |          S |S )Nr   z(*{}))r   _print_Symbol	_settingsr   )r   r   r   r   s      r4   rh  zC89CodePrinter._print_Symbol  sC    ww$$T**4>-000>>$'''Kr6   c                    |                      |j                  }|                      |j                  }|j        }d                    |||          S )Nz{} {} {})r   lhsrhsrel_opr   )r   r   lhs_coderhs_codeops        r4   _print_Relationalz C89CodePrinter._print_Relational  sG    ;;tx((;;tx(([  2x888r6   c                   |                      |j                  }t          |j        t                    r|j        j        \  }}}nt          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  r0  iterabler*   r  NotImplementedErrorrw  r   )r   r   rs  rt  ru  rv  rw  s          r4   
_print_ForzC89CodePrinter._print_For  s    T[))dmU++ 	T $ 2E4%&RSSS{{49%%)*0&e4 +1 +1 +1	1r6   c                h    d                     |                     |j        d                             S )Nz((({0}) > 0) - (({0}) < 0))r   )r   r   r  )r   funcs     r4   _print_signzC89CodePrinter._print_sign  s(    ,33DKK	!4M4MNNNr6   c                n     d j         v r                     |          S  fd |j                  S )NrV   c                    t          |           dk    r                    | d                   S t          |           dz  }d | d |                    | |d                    dz  S )Nr   r   r   z!((%(a)s > %(b)s) ? %(a)s : %(b)s)abrV  r   )r  halfinner_print_maxr   s     r4   r  z2C89CodePrinter._print_Max.<locals>.inner_print_max  x    4yyA~~{{47+++t99>D6$_T%4%[11$_T$%%[11: :  r6   r   r  r  )r   r   r  s   ` @r4   
_print_MaxzC89CodePrinter._print_Max  X    D(((''---	 	 	 	 	 	 ty)))r6   c                n     d j         v r                     |          S  fd |j                  S )NrX   c                    t          |           dk    r                    | d                   S t          |           dz  }d | d |                    | |d                    dz  S )Nr   r   r   z!((%(a)s < %(b)s) ? %(a)s : %(b)s)r  r  )r  r  inner_print_minr   s     r4   r  z2C89CodePrinter._print_Min.<locals>.inner_print_min  r  r6   r  )r   r   r  s   ` @r4   
_print_MinzC89CodePrinter._print_Min  r  r6   c                  
 t          |t                    r=|                     |                    d                    }d                    |          S d}dd
d |D             }fd|D             }
fd|D             }g }d	}t          |          D ]Q\  }}	|	d
v r|                    |	           |||         z  }|                    ||z  |	           |||         z  }R|S )z0Accepts a string of code or a list of code linesTr   z   ){r  z{
z(
)rJ  r  c                8    g | ]}|                     d           S )z 	)lstrip)r   lines     r4   r  z.C89CodePrinter.indent_code.<locals>.<listcomp>  s$    444tE""444r6   c           
     n    g | ]1}t          t          t          |j                                      2S r   )rp   anymapr   )r   r  	inc_tokens     r4   r  z.C89CodePrinter.indent_code.<locals>.<listcomp>  s5    MMMCCy99::;;MMMr6   c           
     n    g | ]1}t          t          t          |j                                      2S r   )rp   r  r  
startswith)r   r  	dec_tokens     r4   r  z.C89CodePrinter.indent_code.<locals>.<listcomp>  s5    OOO$CC;;<<==OOOr6   r   )r   rK  )r0  r1  r   
splitlinesrW  rT  rU  )r   code
code_linestabincreasedecreaseprettylevelnr  r  r  s             @@r4   r   zC89CodePrinter.indent_code  s"    dC   	'))$//$*?*?@@J77:&&&,		44t444MMMMMMMOOOO$OOO  	! 	!GAtz!!d###Xa[ EMMCIItt4555Xa[ EEr6   c                N    | j         | j                            ||                   S r/   )r   r   r   r   r   s     r4   r	  zC89CodePrinter._get_func_suffix  s#    &t'8'<'<UE'J'JKKr6   c                N    | j         | j                            ||                   S r/   )r   r   r   r  s     r4   r%  z"C89CodePrinter._get_literal_suffix  s#    )$*;*?*?u*M*MNNr6   c                    | j                             ||          }| j                            |d          }| j                            ||          S )Nr   )r   r   r   )r   r   aliasdflts       r4   r   z%C89CodePrinter._get_math_macro_suffix  sK    !%%eU33,00;;,00===r6   c                R     dd                      fd|D                       z   dz   S )Nr  r  c              3  B   K   | ]}                     |          V  d S r/   rM  )r   rN  r   s     r4   r   z.C89CodePrinter._print_Tuple.<locals>.<genexpr>  s-      ::T[[^^::::::r6   rJ  )rW  r>  s   ` r4   _print_TuplezC89CodePrinter._print_Tuple  s4    499::::T::::::3>>r6   c                d   | j                             | j                            |t	                                           | j                            | j                            |t	                                           |                     | j                            ||j	                            S r/   )
r   updater   r   r   r   r   r   r   r   r  s     r4   _print_TypezC89CodePrinter._print_Type  s    D-11%??@@@4+//suu==>>>{{4-11%DDEEEr6   c           	        ddl m} |j        }|j        }|j        t
          k    rt          d          t          |t                    rvd	                    t          |j        v rdnd|                     |j                  t          |j        v rdnd||j        v rdnd|                     |j                  	          }nt          |t                    rYd
	                    t          |j        v rdnd|                     |j                  |                     |j                            }nt!          dt	          |          z            |d k    r|d|                     |          z  z  }|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$   rR  r0  r   r   r   r   r   r   symbolr   ry  )r   r   r   r   valresults         r4   _print_Declarationz!C89CodePrinter._print_Declaration  ss   111111mi8wCDDDc7## 	M+22*ci7788R++ch'',	9988r!)SY!6!6++B++cj)) 3  FF X&& 	M"))*ci7788R++ch''++cj)) *  FF &&?$s))&KLLL$;;gC 0 000Fr6   c                H   | j                             t          t                    }| j                            | j                            |t                                           |                     |          }t          |	                    |j
                            }d|vr	d|vr|dz  }|                    d          }|d                             d          |d<   |d                             d          r|dxx         dz  cc<   d                    |          |z   S )NrN  .z.0r   0)r   r   r   r   r  r   r   r%  r1  r   r   splitrstripr   rW  )r   fltr   r  r  	num_partss         r4   r
  zC89CodePrinter._print_Float  s   !%%dD114+//suu==>>>))%00#))E-..//c>>cnn4KCIIcNN	 |**3//	!Q<  %% 	 aLLLCLLLxx	""V++r6   r   c                    dS )Ntruer   r>  s     r4   _print_BooleanTruez!C89CodePrinter._print_BooleanTrue  s    vr6   c                    dS )Nfalser   r>  s     r4   _print_BooleanFalsez"C89CodePrinter._print_BooleanFalse  s    wr6   c                    |j         d k    rA|j        d k    rt          d          d                     fd|j        D                       }n[t          d t          |j        |j                   D                       }|j        d k    r
||j        z  }                     |          }d                                         |j	                  |          S )Nz%Expected strides when offset is givenz][c              3  B   K   | ]}                     |          V  d S r/   rM  r   r  r   s     r4   r   z0C89CodePrinter._print_Element.<locals>.<genexpr>  s/      GG3dkk#..GGGGGGr6   c              3  &   K   | ]\  }}||z  V  d S r/   r   )r   r   r  s      r4   r   z0C89CodePrinter._print_Element.<locals>.<genexpr>  s*      MMTQQqSMMMMMMr6   z{symb}[{idxs}])symbidxs)
r)  r(  rR  rW  r/  r4  r5  r   r   r  )r   elemr  
global_idxs   `   r4   _print_ElementzC89CodePrinter._print_Element  s    <4{d"" !HIII99GGGG$,GGGHHDDMMSt|-L-LMMMMMJ{d""dk)
;;z**D&&T[)) ' 
 
 	
r6   c                P     d                      fd|j        D                       S )z0 Elements of code blocks printed as statements. rK  c                `    g | ]*}                                         |                    +S r   )r   r   )r   r   r   s     r4   r  z3C89CodePrinter._print_CodeBlock.<locals>.<listcomp>+  s1    QQQ!$--dkk!nn==QQQr6   rW  r  r>  s   ` r4   _print_CodeBlockzC89CodePrinter._print_CodeBlock)  s,    yyQQQQtyQQQRRRr6   c                L      dj         di |                     fd          S )Nz while ({condition}) {{
{body}
}}c                .                         |           S r/   rM  )r  r   s    r4   r5   z-C89CodePrinter._print_While.<locals>.<lambda>/  s    dkk#.. r6   )applyr   )r   r   r>  s   ` r4   _print_WhilezC89CodePrinter._print_While-  sG    :3: 1 1T[[.... >I >0 >0 1 1 	1r6   c                <    d|                      |j                  z  S )Nz{
%s
})r  rw  r>  s     r4   _print_ScopezC89CodePrinter._print_Scope1  s    D11$)<<<<r6   zstdio.hc                2    |j         t          k    rd}ndd                     |j                   iz  }|                    |j        t          k    rdn                     |j                  d                     fd|j        D                                 S )Nzprintf({fmt}, {pargs})z fprintf(%(out)s, {fmt}, {pargs})outz%s
r  c              3  B   K   | ]}                     |          V  d S r/   rM  r  s     r4   r   z.C89CodePrinter._print_Print.<locals>.<genexpr>>  s/      II#T[[--IIIIIIr6   )fmtpargs)filer%   r   r   format_stringrW  
print_args)r   r   templates   `  r4   _print_PrintzC89CodePrinter._print_Print4  s    9/HH9t{{49--= H ,44$++dFX:Y:Y))IIIIIIIJJ  
 
 	
r6   c                    |j         S r/   )r   )r   strms     r4   _print_StreamzC89CodePrinter._print_StreamA  s
    yr6   c                     d                      fd|j        D                       }dt           fd|j        |j        fD                       |fz   z  S )Nr  c              3  \   K   | ]&}                     t          |                    V  'd S r/   )r   r   r  s     r4   r   z:C89CodePrinter._print_FunctionPrototype.<locals>.<genexpr>E  s7      SSC$++k#&6&677SSSSSSr6   z	%s %s(%s)c              3  B   K   | ]}                     |          V  d S r/   rM  r  s     r4   r   z:C89CodePrinter._print_FunctionPrototype.<locals>.<genexpr>G  s/      MM4;;s##MMMMMMr6   )rW  
parameterstuplereturn_typer   )r   r   parss   `  r4   _print_FunctionPrototypez'C89CodePrinter._print_FunctionPrototypeD  sk    yySSSS4?SSSTTMMMM0@$)/LMMMNNRVQXX
 	
r6   c                Z    |                      |          |                     |          S r/   )r  r  r>  s     r4   _print_FunctionDefinitionz(C89CodePrinter._print_FunctionDefinitionJ  s4    66t<<<**40002 	2r6   c                D    |j         \  }d|                     |          z  S )Nz	return %sr  r   r   r   r  s      r4   _print_ReturnzC89CodePrinter._print_ReturnN  s"    yT[[----r6   c                V     dd                      fd|j        D                       z  S )Nz(%s)r  c              3  B   K   | ]}                     |          V  d S r/   rM  r  s     r4   r   z6C89CodePrinter._print_CommaOperator.<locals>.<genexpr>S  s/      "I"I4;;s#3#3"I"I"I"I"I"Ir6   r  r>  s   ` r4   _print_CommaOperatorz#C89CodePrinter._print_CommaOperatorR  s1    		"I"I"I"Ity"I"I"IJJJJr6   c                P   |j         t          k    rdt          |j                  z  S t	          |j         j                  dk    r1t          |j                  d|                     |j                   S t          |j                  d|                     |j                   dS )Nz%s:r   z:
z:
{
z
})rw  r%   r1  r   rV  r  r  r>  s     r4   _print_LabelzC89CodePrinter._print_LabelU  s    93ty>>))ty~!## #DI0E0Edi0P0P0PQQ"%di....$2G2G	2R2R2R2RSSr6   c                     d|j         j        z  S )Nzgoto %s)r6  r   r>  s     r4   _print_gotozC89CodePrinter._print_goto\  s    4:?**r6   c                D    |j         \  }d|                     |          z  S )Nz++(%s)r  r  s      r4   _print_PreIncrementz"C89CodePrinter._print_PreIncrement_  "    y$++c****r6   c                D    |j         \  }d|                     |          z  S )Nz(%s)++r  r  s      r4   _print_PostIncrementz#C89CodePrinter._print_PostIncrementc  r   r6   c                D    |j         \  }d|                     |          z  S )Nz--(%s)r  r  s      r4   _print_PreDecrementz"C89CodePrinter._print_PreDecrementg  r   r6   c                D    |j         \  }d|                     |          z  S )Nz(%s)--r  r  s      r4   _print_PostDecrementz#C89CodePrinter._print_PostDecrementk  r   r6   c                     d|j         j        |j        d                     fd|j        D             dgz             dz  S )Nz!%(keyword)s %(name)s {
%(lines)s}z;
c                :    g | ]}                     |          S r   rM  )r   r   r   s     r4   r  z0C89CodePrinter._print_struct.<locals>.<listcomp>r  s%    AAAtT""AAAr6   r   )keywordr   r   )r   __name__r   rW  declarationsr>  s   ` r4   _print_structzC89CodePrinter._print_structo  s[    3~.	EJJAAAAt/@AAARDHMJ MJ7
 7
 
 	
r6   c                    dS )Nra   r   r   _s     r4   _print_BreakTokenz C89CodePrinter._print_BreakTokenu  s    wr6   c                    dS )Nre   r   r  s     r4   _print_ContinueTokenz#C89CodePrinter._print_ContinueTokenx  rE  r6   r/   )dr
  
__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?  rA  rD  rG  r[  ra  rf  rh  rq  rz  r}  r  r  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__)r   s   @r4   r   r      s        FFKHHS((N(,[-J ) )suu"O O ) )     	g*L 	hevhyyyx			&M    $ 	}zl
|
|
|
|
L 02K1111 	 	 	  K
C-C----     2  L L L' ' '6 6 6' ' 'B B B 2 2 2 2 2 : : :9 9 98 8 8
4 4 40' ' ' 1 1 1 1 1    Q Q QB@ @ @@ @ @    9 9 9	1 	1 	1O O O* * ** * *  6L L LO O O> > >
? ? ? KF F F
  6, , , X{m$$$  %$ X{m$$$  %$
 
 
 S S S1 1 1= = = Xyk"""

 

 #"

  
 
 
2 2 2. . .K K KT T T+ + ++ + ++ + ++ + ++ + +
 
 
     !LLLLLr6   r   c            	         e Zd ZU dZ eeez             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 Zd	 Zd
 Z edhdh          edd                        Zd Zd Z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                    dS )NINFINITYr   r>  s     r4   rD  zC99CodePrinter._print_Infinity  rE  r6   c                    dS )Nz	-INFINITYr   r>  s     r4   rG  z&C99CodePrinter._print_NegativeInfinity  rH  r6   c                    dS )NNANr   r>  s     r4   
_print_NaNzC99CodePrinter._print_NaN  s    ur6   zmath.hm)r   r   FNc           
     P    | j         |j        j                 }t          |t                    s%|D ]\  }} ||j         r|} nt          d          	  | g|j        R  S # t          $ r0  j        |z    j	        v r 
                    t                    nd}Y nw xY w|r                     |j        d                   }t          |j                  dk    rd}|j        dd         D ];}	|dz  }|d                     j        ||                     |	                    z  }<|d	                     |                    |j        d                             |z  }n&d	                     fd
|j        D                       }d                     j        |||          S )NzNo matching printerr   r   r   r  r  z, {ns}{name}{suffix}({next})nsr   r  nextr  c              3  B   K   | ]}                     |          V  d S r/   rM  r  s     r4   r   z2C99CodePrinter._print_math_func.<locals>.<genexpr>  s/      DD3dkk#..DDDDDDr6   z{ns}{name}{suffix}({args}))r)  r   r  r  )r   r   r
  r0  r1  r  rR  	TypeErrorr  _prec_funcsr	  r   r   rV  r   r|  rW  )
r   r   nestr  cbr   r  r  
paren_pilecurr_args
   `         r4   r  zC99CodePrinter._print_math_func  s    =()@AE%%% 	8! 8 8D2ty>  EE !!6777	a5*	**** 	a 	a 	a48Hu4DHX4X4XT**4000^`FFF	a  	F;;ty|,,D49~~!!
 $	!B$  H#%J9@@8"%#{{844	 A   DD KK		$)B- 8 8999J 
 99DDDD$)DDDEED+22x	 3 
 
 	
s   A$ $7BBc                0    |                      |d          S NT)r.  r  r>  s     r4   r  zC99CodePrinter._print_Max      $$T$555r6   c                0    |                      |d          S r3  r4  r>  s     r4   r  zC99CodePrinter._print_Min  r5  r6   c           
        g }g }d}|D ]~}|                     ||                     |j                  |                     |j                  |                     |j        dz             dz             |                     d           ||fS )Nz8for (int %(var)s=%(start)s; %(var)s<%(end)s; %(var)s++){r   )r   rt  endrJ  )rU  r   r6  lowerupper)r   r/  
open_linesclose_lines	loopstartr   s         r4   _get_loop_opening_endingz'C99CodePrinter._get_loop_opening_ending  s    
N	 	$ 	$Ai{{17++QW--{{17Q;//+1 +1 1 2 2 2 s####;&&r6   )FN)r
  r  r  r  r   r  reserved_words_c99r   r   r   r   r   r   r   r   known_functions_C99r   r  r  r-  rD  rG  r&  r'   r   r  r  r  r>  r   r6   r4   r  r  }  s        HS*<<==N$uu^9??AA?$D egg   M 4n9??AAK=[MD egg   L .C----L NSUWW	       
 XxjSE222&
 &
 &
  32&
P6 6 66 6 6' ' ' ' 'r6   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                  :    e Zd Z edh          d             ZdS )C11CodePrinterz
stdalign.hr  c                D    |j         \  }d|                     |          z  S )Nzalignof(%s)r  r  s      r4   _print_alignofzC11CodePrinter._print_alignof  s"    yt{{3////r6   N)r
  r  r  r'   rD  r   r6   r4   rB  rB    s=        X|n%%%0 0 &%0 0 0r6   rB  )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  rB  c_code_printersr   r6   r4   <module>rU     s    # " " " " "                         2 2 2 2 2 2 2 2                                                          = < < < < < < < < < < < < < < < & & & & & & : 9 9 9 9 9 9 9	''03I3I52QR	5 
5 
5	
 F F F W 
5 
5 F F F W v  F! & d.   3
F3W3 W3 F	3
 W3 F3 W3 
53 3 F3 
63 
63 W3 W3 W3  
5!3" X#3   .   
+ " " "J  &h! h! h! h! h![ h! h! h!T\' \' \' \' \'^ \' \' \'~89>N NA GNK!O^-LMMMM0 0 0 0 0^ 0 0 0  r6   