
    wgi                       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<dAj{                         D ]  Z> e?e<dBe>z  e<j                           G dC dDe<      ZAe;e<eAdEZByF)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    U/home/mcse/projects/flask/flask-venv/lib/python3.12/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                 8   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   [   sC    4:=	QVVi 	
#a&) 	A	
 	B 	
f 	
Q 	
Q 	
!$$ 	
!$$ 	
$qtt*l 	
$qtt*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                   |   | 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   sE    4###!--d3T5P5PQU5VWWd-f--r6   r   )r   r   s   ` r4   _as_macro_if_definedr      s#     4[. . r6   c                  "    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           	        |xs i }| j                   |j                  dt                     | _         t        t	        | j
                  j                         |j                  di       j                                     | _        t        t	        | j                  j                         |j                  di       j                                     | _        t        t	        | j                  j                         |j                  di       j                                     | _        t        t	        | j                  j                         |j                  di       j                                     | _	        t        t	        | j                  j                         |j                  di       j                                     | _
        t        t	        | j                  j                         |j                  di       j                                     | _        t        t	        | j                  j                         |j                  di       j                                     | _        t        | 9  |       t        | j                  fi |j!                  d	i       | _        t%        |j!                  d
g             | _        t%               | _        t%               | _        t%               | _        y )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__   sF   >r#'||M?;LMD t'8'8'>'>'@'/||NB'G'M'M'O"Q R!%(:(:(@(@(B(0_b(I(O(O(Q#S T t'8'8'>'>'@'/||NB'G'M'M'O"Q Rd&6&6&<&<&>'/||M2'F'L'L'N!P Q"&uT-D-D-J-J-L(05I2(N(T(T(V(X #Y%)%0J0J0P0P0R(05Lb(Q(W(W(Y+[ &\"(,U43P3P3V3V3X(05OQS(T(Z(Z(\.^ )_%"#DHHS=Mr0RS]B ?@uer6   c                    |dz  S )N    )r   ps     r4   _rate_index_positionz#C89CodePrinter._rate_index_position   s    s
r6   c                2    |j                  d      r|S |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5zK:;KKr6   c                $    dj                  |      S )Nz/* {} */)format)r   texts     r4   _get_commentzC89CodePrinter._get_comment   s      &&r6   c                    | j                   t           }t        |||j                  |j                        t
        h      }t        |      }| j                  | j                  |            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  sY    !!$'t%u{{5;L;L/MVaUbc3""4;;t#455r6   c                $    | j                  |      S r/   )indent_code)r   liness     r4   _format_codezC89CodePrinter._format_code  s    &&r6   c                J    |j                   \  }fdt        |      D        S )Nc              3  F   K   | ]  }t              D ]  }||f 
  y wr/   )range).0ijcolss      r4   	<genexpr>z:C89CodePrinter._traverse_matrix_indices.<locals>.<genexpr>  s%     A1U4[AAAAs   !)shaper   )r   matrowsr   s      @r4   _traverse_matrix_indicesz'C89CodePrinter._traverse_matrix_indices
  s    YY
dAdAAr6   c                $    t        |   |fi |S r/   )r   
_print_Mul)r   r   r   r   s      r4   r   zC89CodePrinter._print_Mul  s    w!$1&11r6   c           	        d| j                   v r| j                  |      S t        |      }| j                  t              }t        |j                  d      r9| j                  t        d            d| j                  |j                  |      S t        |j                  d      r.| j                  d|d| j                  |j                        dS |j                  t        j                  d	z  k(  r=| j                  d
k7  r.| j                  d|d| j                  |j                        dS | j                  d|d| j                  |j                        d| j                  |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  s   D(((''--$&&t,"%"//c
;T=N=NtyyZ^=_``$((C(%)XXvt{{4997MNNXXq T]]e%;%)XXvt{{4997MNN(,&$++dii:P#';;txx#8: :r6   c                z   |j                   \  }}|j                  r|j                  r}t        |      }|j                   D cg c]  }| j                  ||       c}\  }}|j                  r|j                  s|j
                  r|j
                  r| d| S d| d| d| d| S | j                  |d      S c c}w )Nz % ((z) + z) % fmod)known)argsr1   r(   r  is_nonnegativeis_nonpositive_print_math_func)r   r   numdenr  argsnumsdens           r4   
_print_ModzC89CodePrinter._print_Mod"  s    99S>>cnnd#DBF))L3$++C6LJD$ ""s'9'9""s'9'9s4&))vSd4&TF;;$$T$88 Ms   B8c                    t        |j                        t        |j                        }}| 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  s?    466{CK1))$/!VQ!777r6   c                b   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                  j                        d| j                  |
      d	S )
Noffsetstridesr   r   r  r   c              3  2   K   | ]  }|d    |d   z    yw)r   r   Nr   )r   r3   s     r4   r   z0C89CodePrinter._print_Indexed.<locals>.<genexpr>J  s     Bq1adBs   [])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  s   Haff5$))Y5,,?j#6::DEEED#~$U499%56	!$B$-C!$)),	 ! a ! GBC,ABBVK
;;tyy7;;z24 	4r6   c                8    | j                  |j                        S r/   )r   r4  r   r   s     r4   
_print_IdxzC89CodePrinter._print_IdxN  s    {{4::&&r6   c                "    t         |   |      S r/   )r   _print_NumberSymbol)r   r   r   s     r4   r?  z"C89CodePrinter._print_NumberSymbolQ  s    w*400r6   c                     y)NHUGE_VALr   r<  s     r4   _print_InfinityzC89CodePrinter._print_InfinityU      r6   c                     y)Nz	-HUGE_VALr   r<  s     r4   _print_NegativeInfinityz&C89CodePrinter._print_NegativeInfinityX      r6   c           
        |j                   d   j                  dk7  rt        d      g }|j                  t              rt        |j                         D ]  \  }\  }}|dk(  r$|j                  d| j                  |      z         nU|t        |j                         dz
  k(  r|dk(  r|j                  d       n#|j                  d| j                  |      z         | j                  |      }|j                  |       |j                  d	        d
j                  |      S |j                   d d D cg c],  \  }}d| j                  |      d| j                  |      d. }}}d| j                  |j                   d   j                        z  }dj                  |      |z   dj                  dt        |      z  g      z   S c c}}w )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) {}
r  z) ? (
z
)
z: (
%s
)z:  r  )r  cond
ValueErrorhasr   	enumerateappendr   lenjoinr   )	r   r   r   r   eccode0ecpairs	last_lines	            r4   _print_PiecewisezC89CodePrinter._print_Piecewise[  s   99R=%  / 0 0
 88J&tyy1 	"	6Aq6LLt{{1~!=>#dii.1,,dLL*LL!1DKKN!BCAU#S!	" 99U## !%		#201 04{{1~/3{{1~? 0G 0 %t{{499R=3E3E'FFI99W%	1CHHc#g,>N=O4PPP	0s   31Gc                R    ddl m} | j                  |j                  |d            S )Nr   )	PiecewiseF)deep)sympy.functionsrY  r   rewrite)r   r   rY  s      r4   
_print_ITEzC89CodePrinter._print_ITE|  s!    -{{4<<	<>??r6   c                    dj                  | j                  |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  &&466$++*;*;A*>#>>@ 	@r6   c                j    t         |   |      }|| j                  d   v rdj                  |      S |S )Nr   z(*{}))r   _print_Symbol	_settingsr   )r   r   r   r   s      r4   rd  zC89CodePrinter._print_Symbol  s7    w$T*4>>-00>>$''Kr6   c                    | j                  |j                        }| j                  |j                        }|j                  }dj	                  |||      S )Nz{} {} {})r   lhsrhsrel_opr   )r   r   lhs_coderhs_codeops        r4   _print_Relationalz C89CodePrinter._print_Relational  sD    ;;txx(;;txx([[  2x88r6   c                   | j                  |j                        }t        |j                  t              r|j                  j
                  \  }}}nt        d      | j                  |j                        }dj                  |||||      S )Nz*Only iterable currently supported is RangezLfor ({target} = {start}; {target} < {stop}; {target} += {step}) {{
{body}
}})targetstartstopstepbody)	r   ro  r.  iterabler*   r  NotImplementedErrorrs  r   )r   r   ro  rp  rq  rr  rs  s          r4   
_print_ForzC89CodePrinter._print_For  sz    T[[)dmmU+ $ 2 2E4%&RSS{{499%)*0&e4 +1 +1	1r6   c                \    dj                  | j                  |j                  d               S )Nz((({0}) > 0) - (({0}) < 0))r   )r   r   r  )r   funcs     r4   _print_signzC89CodePrinter._print_sign  s$    ,33DKK		!4MNNr6   c                t     d j                   v r j                  |      S  fd |j                        S )NrV   c                    t        |       dk(  rj                  | 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rP  r   )r  halfinner_print_maxr   s     r4   r  z2C89CodePrinter._print_Max.<locals>.inner_print_max  \    4yA~{{47++t9>D6$T%4[1$T$%[1:  r6   r   r  r  )r   r   r  s   ` @r4   
_print_MaxzC89CodePrinter._print_Max  8    D(((''--	 tyy))r6   c                t     d j                   v r j                  |      S  fd |j                        S )NrX   c                    t        |       dk(  rj                  | 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                l   t        |t              r1| j                  |j                  d            }dj	                  |      S d}d}d}|D cg c]  }|j                  d       }}|D cg c]*  }t        t        t        |j                  |                  , }}|D cg c]*  }t        t        t        |j                  |                  , }}g }	d}
t        |      D ]C  \  }}|dv r|	j                  |       |
||   z  }
|	j                  ||
z  |       |
||   z  }
E |	S c c}w c c}w c c}w )	z0Accepts a string of code or a list of code linesTr   z   ){r  z{
z(
)rH  r  z 	r   )r   rI  )r.  r/  r   
splitlinesrQ  lstriprp   anymapr   
startswithrN  rO  )r   code
code_linestab	inc_token	dec_tokenlineincreasedecreaseprettylevelns               r4   r   zC89CodePrinter.indent_code  s,    dC ))$//$*?@J77:&&,		/34tE"44HLMCCy9:;MMJNO$CC;<=OO  	!GAtz!d#Xa[ EMMCIt45Xa[ E	!  5MOs   D'*/D,/D1c                T    | j                   | j                  j                  ||         S r/   )r   r   r   r   r   s     r4   r	  zC89CodePrinter._get_func_suffix  s&    &&t'8'8'<'<UE'JKKr6   c                T    | j                   | j                  j                  ||         S r/   )r   r   r   r  s     r4   r#  z"C89CodePrinter._get_literal_suffix  s&    ))$*;*;*?*?u*MNNr6   c                    | j                   j                  ||      }| j                  j                  |d      }| j                  j                  ||      S )Nr   )r   r   r   )r   r   aliasdflts       r4   r   z%C89CodePrinter._get_math_macro_suffix  sK    !!%%eU3,,00;,,00==r6   c                D     ddj                   fd|D              z   dz   S )Nr  r  c              3  @   K   | ]  }j                  |        y wr/   r   )r   rR  r   s     r4   r   z.C89CodePrinter._print_Tuple.<locals>.<genexpr>  s     :T[[^:   rH  )rQ  r<  s   ` r4   _print_TuplezC89CodePrinter._print_Tuple  s"    499:T:::3>>r6   c                `   | j                   j                  | j                  j                  |t	                            | j
                  j                  | j                  j                  |t	                            | j                  | j                  j                  ||j                              S r/   )
r   updater   r   r   r   r   r   r   r   r  s     r4   _print_TypezC89CodePrinter._print_Type  sv    D--11%?@4++//su=>{{4--11%DEEr6   c           	        ddl m} |j                  }|j                  }|j                  t
        k(  rt        d      t        |t              rdj                  t        |j                  v rdnd| j                  |j                        t        |j                  v rdnd||j                  v rdnd| j                  |j                        	      }nt        |t              r[d
j                  t        |j                  v rdnd| j                  |j                        | j                  |j                              }nt!        dt	        |      z        |d k7  r|d| j                  |      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$   rL  r.  r   r   r   r   r   r   symbolr   ru  )r   r   r   r   valresults         r4   _print_Declarationz!C89CodePrinter._print_Declaration  s*   1mmii88wCDDc7#+22*cii78R++chh',		98r!)SYY!6+B++cjj) 3 F X&"))*cii78R++chh'++cjj) * F &&?$s)&KLL$;gC 000Fr6   c                   | j                   j                  t        t              }| j                  j	                  | j
                  j                  |t                            | j                  |      }t        |j                  |j                              }d|vr	d|vr|dz  }|j                  d      }|d   j                  d      |d<   |d   j                  d      r|dxx   dz  cc<   dj                  |      |z   S )NrR  .z.0r   0)r   r   r   r   r  r   r   r#  r/  r   r   splitrstripr   rQ  )r   fltr   r  r  	num_partss         r4   r
  zC89CodePrinter._print_Float  s    !!%%dD14++//su=>))%0#))E--./c>cn4KCIIcN	 |**3/	!Q<  %aLCLxx	"V++r6   r   c                     y)Ntruer   r<  s     r4   _print_BooleanTruez!C89CodePrinter._print_BooleanTrue  s    r6   c                     y)Nfalser   r<  s     r4   _print_BooleanFalsez"C89CodePrinter._print_BooleanFalse  s    r6   c                    |j                   d k(  r?|j                  d k7  rt        d      dj                   fd|j                  D              }n_t        d t        |j                  |j                         D              }|j                  d k7  r||j                  z  } j                  |      }dj                   j                  |j                        |      S )Nz%Expected strides when offset is givenz][c              3  @   K   | ]  }j                  |        y wr/   r  r   r  r   s     r4   r   z0C89CodePrinter._print_Element.<locals>.<genexpr>  s     G3dkk#.Gr  c              3  ,   K   | ]  \  }}||z    y wr/   r   )r   r   r  s      r4   r   z0C89CodePrinter._print_Element.<locals>.<genexpr>  s     MTQQqSMs   z{symb}[{idxs}])symbidxs)
r'  r&  rL  rQ  r-  r2  r3  r   r   r  )r   elemr  
global_idxs   `   r4   _print_ElementzC89CodePrinter._print_Element  s    <<4{{d" !HII99G$,,GHDMSt||-LMMJ{{d"dkk)
;;z*D&&T[[) ' 
 	
r6   c           
         dj                  |j                  D cg c]"  }| j                  | j                  |            $ c}      S c c}w )z0 Elements of code blocks printed as statements. rI  )rQ  r  r   r   )r   r   r   s      r4   _print_CodeBlockzC89CodePrinter._print_CodeBlock)  s6    yytyyQ!$--dkk!n=QRRQs   'Ac                N      dj                   di |j                   fd      S )Nz while ({condition}) {{
{body}
}}c                &    j                  |       S r/   r  )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-  s2    :3:: 1T[[. >I >0 1 	1r6   c                >    d| j                  |j                        z  S )Nz{
%s
})r  rs  r<  s     r4   _print_ScopezC89CodePrinter._print_Scope1  s    D11$))<<<r6   zstdio.hc                6    |j                   t        k(  rd}n dd j                  |j                         iz  }|j                  |j                  t        k(  rdn j                  |j                        dj                   fd|j                  D                    S )Nzprintf({fmt}, {pargs})z fprintf(%(out)s, {fmt}, {pargs})outz%s
r  c              3  @   K   | ]  }j                  |        y wr/   r  r  s     r4   r   z.C89CodePrinter._print_Print.<locals>.<genexpr>>  s     I#T[[-Ir  )fmtpargs)filer%   r   r   format_stringrQ  
print_args)r   r   templates   `  r4   _print_PrintzC89CodePrinter._print_Print4  s    99/H9t{{499-= H ,,4$++dFXFX:Y))IIJ  
 	
r6   c                    |j                   S r/   )r   )r   strms     r4   _print_StreamzC89CodePrinter._print_StreamA  s    yyr6   c                     dj                   fd|j                  D              }dt         fd|j                  |j                  fD              |fz   z  S )Nr  c              3  R   K   | ]  }j                  t        |               y wr/   )r   r   r  s     r4   r   z:C89CodePrinter._print_FunctionPrototype.<locals>.<genexpr>E  s     SC$++k#&67Ss   $'z	%s %s(%s)c              3  @   K   | ]  }j                  |        y wr/   r  r  s     r4   r   z:C89CodePrinter._print_FunctionPrototype.<locals>.<genexpr>G  s     M4;;s#Mr  )rQ  
parameterstuplereturn_typer   )r   r   parss   `  r4   _print_FunctionPrototypez'C89CodePrinter._print_FunctionPrototypeD  sN    yyS4??STM0@0@$))/LMNRVQXX
 	
r6   c                J    | j                  |      | j                  |      S r/   )r  r  r<  s     r4   _print_FunctionDefinitionz(C89CodePrinter._print_FunctionDefinitionJ  s(    66t<**402 	2r6   c                F    |j                   \  }d| j                  |      z  S )Nz	return %sr  r   r   r   r  s      r4   _print_ReturnzC89CodePrinter._print_ReturnN  s!    yyT[[---r6   c                R     ddj                   fd|j                  D              z  S )Nz(%s)r  c              3  @   K   | ]  }j                  |        y wr/   r  r  s     r4   r   z6C89CodePrinter._print_CommaOperator.<locals>.<genexpr>S  s     "I4;;s#3"Ir  )rQ  r  r<  s   ` r4   _print_CommaOperatorz#C89CodePrinter._print_CommaOperatorR  s!    		"Ityy"IJJJr6   c                j   |j                   t        k(  rdt        |j                        z  S t	        |j                   j
                        dk(  r3t        |j                        d| j                  |j                         S t        |j                        d| j                  |j                         dS )Nz%s:r   z:
z:
{
z
})rs  r%   r/  r   rP  r  r  r<  s     r4   _print_LabelzC89CodePrinter._print_LabelU  sz    993tyy>))tyy~~!# #DII0E0Edii0PQQ"%dii.$2G2G		2RSSr6   c                4    d|j                   j                  z  S )Nzgoto %s)r4  r   r<  s     r4   _print_gotozC89CodePrinter._print_goto\  s    4::??**r6   c                F    |j                   \  }d| j                  |      z  S )Nz++(%s)r  r  s      r4   _print_PreIncrementz"C89CodePrinter._print_PreIncrement_  !    yy$++c***r6   c                F    |j                   \  }d| j                  |      z  S )Nz(%s)++r  r  s      r4   _print_PostIncrementz#C89CodePrinter._print_PostIncrementc  r  r6   c                F    |j                   \  }d| j                  |      z  S )Nz--(%s)r  r  s      r4   _print_PreDecrementz"C89CodePrinter._print_PreDecrementg  r  r6   c                F    |j                   \  }d| j                  |      z  S )Nz(%s)--r  r  s      r4   _print_PostDecrementz#C89CodePrinter._print_PostDecrementk  r  r6   c                    d|j                   j                  |j                  dj                  |j                  D cg c]  }| j                  |       c}dgz         dz  S c c}w )Nz!%(keyword)s %(name)s {
%(lines)s}z;
r   )keywordr   r   )r   __name__r   rQ  declarationsr   )r   r   r   s      r4   _print_structzC89CodePrinter._print_structo  s[    3~~..		EJJ/3/@/@AtT"ARDHMJ7
 
 	
As   A"c                     y)Nra   r   r   _s     r4   _print_BreakTokenz C89CodePrinter._print_BreakTokenu  s    r6   c                     y)Nre   r   r  s     r4   _print_ContinueTokenz#C89CodePrinter._print_ContinueTokenx  rC  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=  r?  rB  rE  rW  r]  rb  rd  rm  rv  ry  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KHH(N(,[-J-J )u"O )~  	g*L 	hevhyyyx			&M? $ 	}zl
|
|
|
|
L 02K,1 	 	 	  K
C-C-2L'6'B 2 2 : :98
40' 1 1QB@@9	1O**6LO>
? KF
6, {m$ % {m$ %
 S1= yk"

 #


2.KT+++++
 !Lr6   r   c            	         e Zd ZU dZ eeez         Z e ee	j                  j                         ededij                                     Z
 e ee	j                  j                         edhedhij                                     ZeZded<   dj%                         Zd Zd	 Zd
 Z edhdh      edd              Zd Zd Zd Zy)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                     y)NINFINITYr   r<  s     r4   rB  zC99CodePrinter._print_Infinity  rC  r6   c                     y)Nz	-INFINITYr   r<  s     r4   rE  z&C99CodePrinter._print_NegativeInfinity  rF  r6   c                     y)NNANr   r<  s     r4   
_print_NaNzC99CodePrinter._print_NaN  s    r6   zmath.hm)r   r   Nc           
     b    |# j                   |j                  j                     }t        |t              s(|D ]  \  }} ||j
                   s|} n t        d      	  | g|j
                   S # t        $ r5  j                  |z    j                  v r j                  t              nd}Y nw xY w|r j                  |j
                  d         }t        |j
                        dkD  rd}|j
                  dd D ]8  }	|dz  }|dj                   j                  || j                  |	            z  }: |d	 j                  |j                  |j
                  d               |z  }n$d	j!                   fd
|j
                  D              }dj                   j                  |||      S )NzNo matching printerr   r   r   r  r  z, {ns}{name}{suffix}({next})nsr   r  nextr  c              3  @   K   | ]  }j                  |        y wr/   r  r  s     r4   r   z2C99CodePrinter._print_math_func.<locals>.<genexpr>  s     D3dkk#.Dr  z{ns}{name}{suffix}({args}))r!  r   r  r  )r   r   r  r.  r/  r  rL  	TypeErrorr  _prec_funcsr	  r   r   rP  r   rx  rQ  )
r   r   nestr  cbr   r  r  
paren_pilecurr_args
   `         r4   r  zC99CodePrinter._print_math_func  s    =(()@)@AE%%! 8Dtyy> E8
 !!677	a*		** 	a48HHu4DHXHX4XT**40^`F	a ;;tyy|,D499~!
 $		!B H#%J9@@88"%#{{84	 A  D KK		$))B- 89 
 99D$))DED+22xx	 3 
 	
s    A3 3;B10B1c                (    | j                  |d      S NT)r&  r  r<  s     r4   r  zC99CodePrinter._print_Max      $$T$55r6   c                (    | j                  |d      S r+  r,  r<  s     r4   r  zC99CodePrinter._print_Min  r-  r6   c           
        g }g }d}|D ]y  }|j                  || j                  |j                        | j                  |j                        | j                  |j                  dz         dz         |j                  d       { ||fS )Nz8for (int %(var)s=%(start)s; %(var)s<%(end)s; %(var)s++){r   )r   rp  endrH  )rO  r   r4  lowerupper)r   r-  
open_linesclose_lines	loopstartr   s         r4   _get_loop_opening_endingz'C99CodePrinter._get_loop_opening_ending  s    
N	 	$Ai{{177+QWW-{{177Q;/+1 1 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%  rB  rE  r  r'   r   r  r  r  r6  r   r6   r4   r  r  }  s    H*<<=Nu^99??A?$D eg M n99??AK=[MD eg L .C-L NSUW	 
 xjSE2&
  3&
P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y)C11CodePrinterz
stdalign.hr  c                F    |j                   \  }d| j                  |      z  S )Nzalignof(%s)r  r  s      r4   _print_alignofzC11CodePrinter._print_alignof  s!    yyt{{3///r6   N)r  r  r  r'   r<  r   r6   r4   r:  r:    s    |n%0 &0r6   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   r8  r  r7  r   r   r   r  r  ksetattrr  r:  c_code_printersr   r6   r4   <module>rM     s   #     2        = < & :	'03I52QR	5 
5 
5	
 F F F W 
5 
5 F F F W v  F! & .  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!T\'^ \'~89>NA NK!O^-L-LMN0^ 0 r6   