
    Edi                        d Z ddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+ ddl,m-Z-m.Z. dd	l/m0Z0 dd
l)m1Z1m2Z2 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Z3 e4e3fi i d d d!d!d"d"d#d#d$d$d%d&d'd'd(d(d)d*d+d+d,d-d.d/d0d0d1d1d2d2d3d3d4d5Z5g d6Z6d7d8gZ7d9 Z8d: Z9 G d; d<e*          Z: G d= d>e:          Z;d?<                                D ]Z= e>e;d@e=z  e;j?                    G dA dBe;          Z@e:e;e@dCZAdDS )Ea  
C code printer

The C89CodePrinter & C99CodePrinter converts single SymPy expressions into
single C expressions, using the functions defined in math.h where possible.

A complete code generator, which uses ccode extensively, can be found in
sympy.utilities.codegen. The codegen module can be used to generate complete
source code files that are compilable without further modifications.


    )AnyDictTuplewraps)chain)S)
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    0lib/python3.11/site-packages/sympy/printing/c.py<lambda>r4   &   s    1<'     fabsc                     | j         S r.   r/   r1   s    r3   r4   r4   &   s    Q\ r5   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   )rL   Sqrt)rA   )rH   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.cfunctionsrL   r   &sympy.functions.elementary.exponentialrA   (sympy.functions.elementary.miscellaneousrH   r	   Exp1Pi)rL   r   rA   rH   s       r3   get_math_macrosr   Y   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''	;! r5   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      r3   _meth_wrapperz+_as_macro_if_defined.<locals>._meth_wrapper   sU    4## 	.!-d33T5P5PQU5V5V5VWW4d--f---r5   r   )r   r   s   ` r3   _as_macro_if_definedr   ~   s6     4[[. . . . [. r5   c                       e Zd ZdZdZdZdZ ee          Zdddi dd	d e            d	d
d
Z	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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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%dR fd	Z&d Z'd Z(d Z)d Z*d  Z+d! Z,e- fd"            Z.e-d#             Z/d$ Z0d% Z1d& Z2d' Z3e- fd(            Z4d) Z5d* Z6d+ Z7d, Z8d- Z9 fd.Z:d/ Z;d0 Z<d1 Z=d2 Z>d3 Z?d4 Z@d5 ZAd6 ZBd7 ZCd8 ZDeDZEd9 ZFd: ZGd; ZH eIdh<          d=             ZJ eIdh<          d>             ZKd? ZLd@ ZMdA ZNdB ZO eIdCh<          dD             ZPdE ZQdF ZRdG ZSdH ZTdI ZUdJ ZVdK ZWdL ZXdM ZYdN ZZdO Z[dP Z\dQ Z]e[Z^ xZ_S )SC89CodePrinterz<A printer to convert Python expressions to strings of C code_ccodeCC89Nr_      TF_)
order	full_prec	precisionuser_functionshumanallow_unknown_functionscontractdereferenceerror_on_reservedreserved_word_suffixrg   ro   rk   boolint8_tint16_tint32_tint64_tz	stdbool.hzstdint.hf lFLc           	         |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_aliasestype_mappingstype_headerstype_macrostype_func_suffixestype_literal_suffixestype_math_macro_suffixesr   r   )r   popr   dictr   r   itemsr   r   r   r   r   r   super__init___kfgetknown_functionsset_dereferenceheaders	librariesmacros)r   settings	__class__s     r3   r   zC89CodePrinter.__init__   s   >r 	N'||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r5   c                     |dz  S )N    )r   ps     r3   _rate_index_positionz#C89CodePrinter._rate_index_position   s    s
r5   c                 :    |                     d          r|n|dz   S )z@ Get code string as a statement - i.e. ending with a semicolon. ;)endswith)r   
codestrings     r3   _get_statementzC89CodePrinter._get_statement   s$    '0055Kzz:;KKr5   c                 ,    d                     |          S )Nz/* {} */)format)r   texts     r3   _get_commentzC89CodePrinter._get_comment  s      &&&r5   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         r3   _declare_number_constz$C89CodePrinter._declare_number_const  se    !$'t%u{{5;L/M/MVaUbccc3""4;;t#4#4555r5   c                 ,    |                      |          S r.   )indent_code)r   liness     r3   _format_codezC89CodePrinter._format_code
  s    &&&r5   c                 N    |j         \  }fdt          |          D             S )Nc              3   D   K   | ]}t                    D ]}||fV  	d S r.   )range).0ijcolss      r3   	<genexpr>z:C89CodePrinter._traverse_matrix_indices.<locals>.<genexpr>  s:      AA1U4[[AAAAAAAAAAr5   )shaper   )r   matrowsr   s      @r3   _traverse_matrix_indicesz'C89CodePrinter._traverse_matrix_indices  s.    Y
dAAAAdAAAAr5   c                 8     t                      j        |fi |S r.   )r   
_print_Mul)r   r   r   r   s      r3   r  zC89CodePrinter._print_Mul  s"    !uww!$11&111r5   c           	         d| j         v r|                     |          S t          |          }|                     t                    }|j        dk    r;|                     t                    }d|d|                     |j        |          S |j        dk    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Powz1.0/g      ?rH   ()   r   rO   pow, )r   _print_Functionr'   _get_func_suffixr   r@   _get_literal_suffixparenthesizebase_nsr   r	   Onestandard)r   r   PRECsuffixliteral_suffixs        r3   
_print_PowzC89CodePrinter._print_Pow  sZ   D(( 	.''---$&&t,,8r> 		:!55d;;NN!/1B1B49d1S1S1STTX_ 	:%)XXXvvvt{{497M7M7M7MNNXq  	:T]e%; 	:%)XXXvvvt{{497M7M7M7MNN(,&&&$++di:P:P:P:P#';;tx#8#8#8#8: :r5   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     r3   
<listcomp>z-C89CodePrinter._print_Mod.<locals>.<listcomp>*  s)    LLL3$++C66LLLr5   z % ((z) + z) % fmod)known)argsr0   r'   is_nonnegativeis_nonpositive_print_math_func)r   r   numdensnumsdenr  s   `     @r3   
_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8r5   c                     t          |j                  t          |j                  }}|                     t                    }d||||fz  S )Nz%d.0%s/%d.0%s)ro   r   qr  r   )r   r   r   r(  r  s        r3   _print_RationalzC89CodePrinter._print_Rational5  sB    46{{CKK1))$//!VQ!777r5   c                 ~   t          |j        dt          j                  }t          |j        dd           }|j        }|t          |t                    r|j        }t          j        }t                      }|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   c                 0    g | ]}|d          |d         z  S )r   r   r   )r   r2   s     r3   r  z1C89CodePrinter._print_Indexed.<locals>.<listcomp>N  s$    CCC!A$qt)CCCr5   [])getattrr  r	   Zeroindices
isinstancestrr   r  tuplereversedr   ranksumzipr   label)r   r   r+  r,  r2  dimsshifttemp	traversalr   
flat_indexs              r3   _print_IndexedzC89CodePrinter._print_Indexed:  sJ   Haf55$)Y55, 	j#66 	:DEE77D#~ - -$U49%5%566	!$$B$-C -!$),,	 ! ! a GCCS'-B-BCCCDDvM
;;ty7777;;z22224 	4r5   c                 6    |                      |j                  S r.   )r   r:  r   r   s     r3   
_print_IdxzC89CodePrinter._print_IdxR  s    {{4:&&&r5   c                 F    t                                          |          S r.   )r   _print_NumberSymbol)r   r   r   s     r3   rE  z"C89CodePrinter._print_NumberSymbolU  s    ww**4000r5   c                     dS )NHUGE_VALr   rB  s     r3   _print_InfinityzC89CodePrinter._print_InfinityY      zr5   c                     dS )Nz	-HUGE_VALr   rB  s     r3   _print_NegativeInfinityz&C89CodePrinter._print_NegativeInfinity\      {r5   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      r3   r  z3C89CodePrinter._print_Piecewise.<locals>.<listcomp>z  sS     0 0 011 04{{1~~~~/3{{1~~~~? 0 0 0r5   z: (
%s
)z:  r  )r  cond
ValueErrorhasr
   	enumerateappendr   lenjoinr   )	r   r   r   r   rR  rS  code0ecpairs	last_lines	   `        r3   _print_PiecewisezC89CodePrinter._print_Piecewise_  s   9R=% 	0  / 0 0 0
 88J 	Q&ty11 	" 	"	6Aq6 DLLt{{1~~!=>>>>#di..1,, Dd 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Pr5   c                 b    ddl m} |                     |                    |d                    S )Nr   )	PiecewiseF)deep)sympy.functionsra  r   rewrite)r   r   ra  s      r3   
_print_ITEzC89CodePrinter._print_ITE  s6    ------{{4<<	<>>???r5   c                     d                     |                     |j        t          d         d          |j        |j        |j        j        d         z  z             S )Nz{}[{}]AtomT)strictr   )r   r  parentr(   r   r   r   rB  s     r3   _print_MatrixElementz#C89CodePrinter._print_MatrixElement  s[    t00j>P  1    &46$+*;A*>#>>@ @ 	@r5   c                     t                                          |          }|| j        d         v rd                    |          S |S )Nr   z(*{}))r   _print_Symbol	_settingsr   )r   r   r   r   s      r3   rl  zC89CodePrinter._print_Symbol  sE    ww$$T**4>-00 	>>$'''Kr5   c                     |                      |j                  }|                      |j                  }|j        }d                    |||          S )Nz{} {} {})r   lhsrhsrel_opr   )r   r   lhs_coderhs_codeops        r3   _print_Relationalz C89CodePrinter._print_Relational  sG    ;;tx((;;tx(([  2x888r5   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   rw  r3  iterabler)   r  NotImplementedErrorr{  r   )r   r   rw  rx  ry  rz  r{  s          r3   
_print_ForzC89CodePrinter._print_For  s    T[))dmU++ 	T $ 2E4%&RSSS{{49%%)*0&e4 +1 +1 +1	1r5   c                 h    d                     |                     |j        d                             S )Nz((({0}) > 0) - (({0}) < 0))r   )r   r   r  )r   funcs     r3   _print_signzC89CodePrinter._print_sign  s(    ,33DKK	!4M4MNNNr5   c                 n     d j         v r                     |          S  fd |j                  S )NrU   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rZ  r   )r  halfinner_print_maxr   s     r3   r  z2C89CodePrinter._print_Max.<locals>.inner_print_max  {    4yyA~ ,{{47+++t99>D6$_T%4%[11$_T$%%[11: :  r5   r   r  r  )r   r   r  s   ` @r3   
_print_MaxzC89CodePrinter._print_Max  Z    D(( 	.''---	 	 	 	 	 	 ty)))r5   c                 n     d j         v r                     |          S  fd |j                  S )NrW   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     r3   r  z2C89CodePrinter._print_Min.<locals>.inner_print_min  r  r5   r  )r   r   r  s   ` @r3   
_print_MinzC89CodePrinter._print_Min  r  r5   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(
)rN  r  c                 8    g | ]}|                     d           S )z 	)lstrip)r   lines     r3   r  z.C89CodePrinter.indent_code.<locals>.<listcomp>  s$    444tE""444r5   c           
      n    g | ]1}t          t          t          |j                                      2S r   )ro   anymapr   )r   r  	inc_tokens     r3   r  z.C89CodePrinter.indent_code.<locals>.<listcomp>  s5    MMMCCy99::;;MMMr5   c           
      n    g | ]1}t          t          t          |j                                      2S r   )ro   r  r  
startswith)r   r  	dec_tokens     r3   r  z.C89CodePrinter.indent_code.<locals>.<listcomp>  s5    OOO$CC;;<<==OOOr5   r   )r   rO  )r3  r4  r   
splitlinesr[  rX  rY  )r   code
code_linestabincreasedecreaseprettylevelnr  r  r  s             @@r3   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r5   c                 N    | j         | j                            ||                   S r.   )r   r   r   r   r   s     r3   r  zC89CodePrinter._get_func_suffix  s#    &t'8'<'<UE'J'JKKr5   c                 N    | j         | j                            ||                   S r.   )r   r   r   r  s     r3   r  z"C89CodePrinter._get_literal_suffix  s#    )$*;*?*?u*M*MNNr5   c                     | j                             ||          }| j                            |d          }| j                            ||          S )Nr   )r   r   r   )r   r   aliasdflts       r3   r   z%C89CodePrinter._get_math_macro_suffix  sK    !%%eU33,00;;,00===r5   c                 R     dd                      fd|D                       z   dz   S )Nr  r
  c              3   B   K   | ]}                     |          V  d S r.   rQ  )r   rR  r   s     r3   r   z.C89CodePrinter._print_Tuple.<locals>.<genexpr>  s-      ::T[[^^::::::r5   rN  )r[  rB  s   ` r3   _print_TuplezC89CodePrinter._print_Tuple  s4    499::::T::::::3>>r5   c                 d   | j                             | j                            |t	                                           | j                            | j                            |t	                                           |                     | j                            ||j	                            S r.   )
r   updater   r   r   r   r   r   r   r   r  s     r3   _print_TypezC89CodePrinter._print_Type  s    D-11%??@@@4+//suu==>>>{{4-11%DDEEEr5   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#   rV  r3  r   r   r   r   r   r   symbolr   r}  )r   r   r   r   valresults         r3   _print_Declarationz!C89CodePrinter._print_Declaration  sy   111111mi8w 	ECDDDc7## 	M+22*ci7?88R++ch'',	9A88r!)SY!6>++B++cj)) 3  FF X&& 	M"))*ci7?88R++ch''++cj)) *  FF &&?$s))&KLLL$; 	1gC 0 000Fr5   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 )NrR  .z.0r   0)r   r   r   r   r  r   r   r  r4  r   r   splitrstripr   r[  )r   fltr   r  r"  	num_partss         r3   _print_FloatzC89CodePrinter._print_Float  s   !%%dD114+//suu==>>>))%00#))E-..//c> 	cn 	4KCIIcNN	 |**3//	!Q<  %% 	 aLLLCLLLxx	""V++r5   r   c                     dS )Ntruer   rB  s     r3   _print_BooleanTruez!C89CodePrinter._print_BooleanTrue  s    vr5   c                     dS )Nfalser   rB  s     r3   _print_BooleanFalsez"C89CodePrinter._print_BooleanFalse  s    wr5   c                     |j         d k    rF|j        d k    rt          d          d                    t	           fd|j                            }n[t          d t          |j        |j                   D                       }|j        d k    r
||j        z  }                     |          }d	                                         |j
                  |          S )Nz%Expected strides when offset is givenz][c                 .                         |           S r.   rQ  r  r   s    r3   r4   z/C89CodePrinter._print_Element.<locals>.<lambda>!      T[[-=-= r5   c                     g | ]
\  }}||z  S r   r   )r   r   r  s      r3   r  z1C89CodePrinter._print_Element.<locals>.<listcomp>$  s     NNNdaacNNNr5   z{symb}[{idxs}])symbidxs)r,  r+  rV  r[  r  r2  r8  r9  r   r   r  )r   elemr  
global_idxs   `   r3   _print_ElementzC89CodePrinter._print_Element  s    <4 		+{d" J !HIII99S!=!=!=!=!%/ / 0 0DD NNc$,.M.MNNNOOJ{d" *dk)
;;z**D&&T[)) ' 
 
 	
r5   c                 P     d                      fd|j        D                       S )z0 Elements of code blocks printed as statements. rO  c                 `    g | ]*}                                         |                    +S r   )r   r   )r   r   r   s     r3   r  z3C89CodePrinter._print_CodeBlock.<locals>.<listcomp>0  s1    QQQ!$--dkk!nn==QQQr5   )r[  r  rB  s   ` r3   _print_CodeBlockzC89CodePrinter._print_CodeBlock.  s,    yyQQQQtyQQQRRRr5   c                 L      dj         di |                     fd          S )Nz while ({condition}) {{
{body}
}}c                 .                         |           S r.   rQ  r  s    r3   r4   z-C89CodePrinter._print_While.<locals>.<lambda>4  s    dkk#.. r5   )applyr   )r   r   rB  s   ` r3   _print_WhilezC89CodePrinter._print_While2  sG    :3: 1 1T[[.... >I >0 >0 1 1 	1r5   c                 <    d|                      |j                  z  S )Nz{
%s
})r  r{  rB  s     r3   _print_ScopezC89CodePrinter._print_Scope6  s    D11$)<<<<r5   zstdio.hc           	           d                                          |j                  d                    t	           fd|j                                      S )Nzprintf({fmt}, {pargs})r
  c                 .                         |           S r.   rQ  r  s    r3   r4   z-C89CodePrinter._print_Print.<locals>.<lambda>=  s    DKK,<,< r5   )fmtpargs)r   r   format_stringr[  r  
print_argsrB  s   ` r3   _print_PrintzC89CodePrinter._print_Print9  sW    '..D.//))C < < < <doNNOO / 
 
 	
r5   c                      d                     t           fd|j                            }dt          t           fd|j        |j        f                    |fz   z  S )Nr
  c                 H                         t          |                     S r.   )r   r   r  s    r3   r4   z9C89CodePrinter._print_FunctionPrototype.<locals>.<lambda>A  s    [5E5E)F)F r5   z	%s %s(%s)c                 .                         |           S r.   rQ  r  s    r3   r4   z9C89CodePrinter._print_FunctionPrototype.<locals>.<lambda>D  s    $++c"2"2 r5   )r[  r  
parametersr5  return_typer   )r   r   parss   `  r3   _print_FunctionPrototypez'C89CodePrinter._print_FunctionPrototype@  s}    yyFFFF!_. . / /#2222'35 5 6 69=@
 	
r5   c                 Z    |                      |          |                     |          S r.   )r  r  rB  s     r3   _print_FunctionDefinitionz(C89CodePrinter._print_FunctionDefinitionH  s4    66t<<<**40002 	2r5   c                 D    |j         \  }d|                     |          z  S )Nz	return %sr  r   r   r   r  s      r3   _print_ReturnzC89CodePrinter._print_ReturnL  s"    yT[[----r5   c                 `     dd                     t           fd|j                            z  S )Nz(%s)r
  c                 .                         |           S r.   rQ  r  s    r3   r4   z5C89CodePrinter._print_CommaOperator.<locals>.<lambda>Q  s    $++c2B2B r5   )r[  r  r  rB  s   ` r3   _print_CommaOperatorz#C89CodePrinter._print_CommaOperatorP  s0    		#&B&B&B&BDI"N"NOOOOr5   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
})r{  r$   r4  r   rZ  r  r  rB  s     r3   _print_LabelzC89CodePrinter._print_LabelS  s    9 	*3ty>>))ty~!# 	R #DI0E0Edi0P0P0PQQ"%di....$2G2G	2R2R2R2RSSr5   c                      d|j         j        z  S )Nzgoto %s)r:  r   rB  s     r3   _print_gotozC89CodePrinter._print_gotoZ  s    4:?**r5   c                 D    |j         \  }d|                     |          z  S )Nz++(%s)r  r  s      r3   _print_PreIncrementz"C89CodePrinter._print_PreIncrement]  "    y$++c****r5   c                 D    |j         \  }d|                     |          z  S )Nz(%s)++r  r  s      r3   _print_PostIncrementz#C89CodePrinter._print_PostIncrementa  r  r5   c                 D    |j         \  }d|                     |          z  S )Nz--(%s)r  r  s      r3   _print_PreDecrementz"C89CodePrinter._print_PreDecremente  r  r5   c                 D    |j         \  }d|                     |          z  S )Nz(%s)--r  r  s      r3   _print_PostDecrementz#C89CodePrinter._print_PostDecrementi  r  r5   c           	           dt          |j        j        |j        d                     fd|j        D             dgz                       z  S )Nz!%(keyword)s %(name)s {
%(lines)s}z;
c                 :    g | ]}                     |          S r   rQ  )r   r   r   s     r3   r  z0C89CodePrinter._print_struct.<locals>.<listcomp>p  s%    AAAtT""AAAr5   r   )keywordr   r   )r   r   __name__r   r[  declarationsrB  s   ` r3   _print_structzC89CodePrinter._print_structm  sb    3dN+$)5::AAAAt/@AAARDHDJ DJ7
 7
 7
 
 	
r5   c                     dS )Nr`   r   r   r   s     r3   _print_BreakTokenz C89CodePrinter._print_BreakTokens  s    wr5   c                     dS )Nrd   r   r  s     r3   _print_ContinueTokenz#C89CodePrinter._print_ContinueTokenv  rI  r5   r.   )`r  
__module____qualname____doc__printmethodlanguager  r   reserved_words_default_settingsr   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@  rC  rE  rH  rK  r_  re  rj  rl  ru  r~  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  _print_union__classcell__)r   s   @r3   r   r      sh       FFKHHS((N #(suu" #  	g*L 	hevhyyyx			M$ 	}zl
|
|
|
|
L K 	 	 	  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. . .P P PT T T+ + ++ + ++ + ++ + ++ + +
 
 
     !LLLLLr5   r   c            	          e Zd Z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                                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.ha  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   rB  s     r3   rH  zC99CodePrinter._print_Infinity  rI  r5   c                     dS )Nz	-INFINITYr   rB  s     r3   rK  z&C99CodePrinter._print_NegativeInfinity  rL  r5   c                     dS )NNANr   rB  s     r3   
_print_NaNzC99CodePrinter._print_NaN  s    ur5   zmath.hm)r   r   FNc           
      Z    | 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	                    t#           fd
|j                            }d                     j        |||          S )NzNo matching printerr   r   r   r  r  z, {ns}{name}{suffix}({next})nsr   r  nextr
  c                 .                         |           S r.   rQ  r  s    r3   r4   z1C99CodePrinter._print_math_func.<locals>.<lambda>  r  r5   z{ns}{name}{suffix}({args}))r&  r   r  r  )r   r   r  r3  r4  r  rV  	TypeErrorr  _prec_funcsr  r   r   rZ  r   r  r[  r  )
r   r   nestr  cbr   r  r  
paren_pilecurr_args
   `         r3   r!  zC99CodePrinter._print_math_func  s     	B()@AE%%% 	8! 8 8D2ty>  EE !!6777	a5*	**** 	a 	a 	a48Hu4DHX4X`T**4000^`FFF	a  	K;;ty|,,D49~~! 
 $	!B$  H#%J9@@8"%#{{844	 A   DD KK		$)B- 8 8999J 
 99S!=!=!=!=tyIIJJD+22x	 3 
 
 	
s   A$ $7BBc                 0    |                      |d          S NT)r+  r!  rB  s     r3   r  zC99CodePrinter._print_Max      $$T$555r5   c                 0    |                      |d          S r0  r1  rB  s     r3   r  zC99CodePrinter._print_Min  r2  r5   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   rx  endrN  )rY  r   r:  lowerupper)r   r2  
open_linesclose_lines	loopstartr   s         r3   _get_loop_opening_endingz'C99CodePrinter._get_loop_opening_ending  s    
N	 	$ 	$Ai{{17++QW--{{17Q;//+1 +1 1 2 2 2 s####;&&r5   )FN)r  r  r  r  r   r  reserved_words_c99r   r   r   r   r   r   r   r   known_functions_C99r   r  r*  rH  rK  r#  r&   r   r!  r  r  r;  r   r5   r3   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' ' ' ' 'r5   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      r3   _print_alignofzC11CodePrinter._print_alignof  s"    yt{{3////r5   N)r  r  r  r&   rA  r   r5   r3   r?  r?    s=        X|n%%%0 0 &%0 0 0r5   r?  )c89c99c11N)Br  typingr   r   tDictr   tTuple	functoolsr   	itertoolsr   
sympy.corer	   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_printersr   r5   r3   <module>rR     s    7 6 6 6 6 6 6 6 6 6                                                                            = < < < < < < < < < < < < < < < & & & & & & : 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  r5   