
    MZd>i                       d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( dd	l)m*Z*m+Z+ dd
l,m-Z-m.Z. ddl/m0Z0 ddl)m1Z1m2Z2 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/d0d1d2d2d3d3d4d4d5d5d6d7Z5g d8Z6d9d:gZ7d; Z8d< Z9 G d= d>e*      Z: G d? d@e:      Z;dAjy                         D ]  Z= e>e;dBe=z  e;j~                           G dC dDe;      Z@e:e;e@dEZAyF)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)
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    2/usr/lib/python3/dist-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                 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   )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   [   sC    4:=	QVVi 	
#a&) 	A	
 	B 	
f 	
Q 	
Q 	
!$$ 	
!$$ 	
$qtt*l 	
$qtt*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                   |   | 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   sE    4###!--d3T5P5PQU5VWWd-f--r5   r   )r   r   s   ` r3   _as_macro_if_definedr      s#     4[. . r5   c                      e Zd ZU dZdZdZdZ ee      Zdddi dd	d e       d	d
d
Z	de
d<   eeeeeeiZedededededededededededededediZde
d<   edhedhedhedhedhedhedhedhedhi	Zi Zde
d<   ededediZ ededed iZ!ediZ"dZ#dZ$e%Z&de
d!<   dY fd"	Z'd# Z(d$ Z)d% Z*d& Z+d' Z,d( Z-e. fd)       Z/e.d*        Z0d+ Z1d, Z2d- Z3d. Z4e. fd/       Z5d0 Z6d1 Z7d2 Z8d3 Z9d4 Z: fd5Z;d6 Z<d7 Z=d8 Z>d9 Z?d: Z@d; ZAd< ZBd= ZCd> ZDd? ZEeEZFd@ ZGdA ZHdB ZI eJdhC      dD        ZK eJdhC      dE        ZLdF ZMdG ZNdH ZOdI ZP eJdJhC      dK        ZQdL ZRdM ZSdN ZTdO ZUdP ZVdQ ZWdR ZXdS ZYdT ZZdU Z[dV Z\dW Z]dX Z^e\Z_ xZ`S )Z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_suffixdict[str, Any]_default_settingsrg   ro   rk   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L_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     r3   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r5   c                    |dz  S )N    )r   ps     r3   _rate_index_positionz#C89CodePrinter._rate_index_position   s    s
r5   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     r3   _get_statementzC89CodePrinter._get_statement   s    '005zK:;KKr5   c                $    dj                  |      S )Nz/* {} */)format)r   texts     r3   _get_commentzC89CodePrinter._get_comment  s      &&r5   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         r3   _declare_number_constz$C89CodePrinter._declare_number_const  sY    !!$'t%u{{5;L;L/MVaUbc3""4;;t#455r5   c                $    | j                  |      S r.   )indent_code)r   liness     r3   _format_codezC89CodePrinter._format_code  s    &&r5   c                J    |j                   \  }fdt        |      D        S )Nc              3  F   K   | ]  }t              D ]  }||f 
  y wr.   )range).0ijcolss      r3   	<genexpr>z:C89CodePrinter._traverse_matrix_indices.<locals>.<genexpr>  s%     A1U4[AAAAs   !)shaper   )r   matrowsr   s      @r3   _traverse_matrix_indicesz'C89CodePrinter._traverse_matrix_indices  s    YY
dAdAAr5   c                $    t        |   |fi |S r.   )r   
_print_Mul)r   r   r   r   s      r3   r  zC89CodePrinter._print_Mul  s    w!$1&11r5   c           	        d| j                   v r| j                  |      S t        |      }| j                  t              }t        |j                  d      r7| 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Powz1.0/g      ?rH   ()   r   rO   pow, )r   _print_Functionr'   _get_func_suffixr   r	   r@   _get_literal_suffixparenthesizebase_nsr   r   Onestandard)r   r   PRECsuffixliteral_suffixs        r3   
_print_PowzC89CodePrinter._print_Pow  s   D(((''--$&&t,"%!55d;N!/1B1B499d1STT$((C(%)XXvt{{4997MNNXXq T]]e%;%)XXvt{{4997MNN(,&$++dii:P#';;txx#8: :r5   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)argsr0   r'   r  is_nonnegativeis_nonpositive_print_math_func)r   r   numdenr  argsnumsdens           r3   
_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)ro   r   qr  r   )r   r   r   r(  r  s        r3   _print_RationalzC89CodePrinter._print_Rational7  s?    466{CK1))$/!VQ!777r5   c                   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        t        ||      D 
cg c]  }
|
d   |
d   z   c}
      |z   }| j                  |j                  j                        d	| j                  |      d
S c c}
w )Noffsetstridesr   r   r  r   r   r   [])getattrr  r   Zeroindices
isinstancestrr   r  reversedr   ranksumzipr   label)r   r   r+  r,  r1  dimsshifttemp	traversalr   r2   
flat_indexs               r3   _print_IndexedzC89CodePrinter._print_Indexed<  s%   Haff5$))Y5,,?j#6::DEEED#~$U499%56	!$B$-C!$)),	 ! a ! GS'-BC!A$qt)CDvM
;;tyy7;;z24 	4 Ds   +Ec                8    | j                  |j                        S r.   )r   r8  r   r   s     r3   
_print_IdxzC89CodePrinter._print_IdxT  s    {{4::&&r5   c                "    t         |   |      S r.   )r   _print_NumberSymbol)r   r   r   s     r3   rC  z"C89CodePrinter._print_NumberSymbolW  s    w*400r5   c                     y)NHUGE_VALr   r@  s     r3   _print_InfinityzC89CodePrinter._print_Infinity[      r5   c                     y)Nz	-HUGE_VALr   r@  s     r3   _print_NegativeInfinityz&C89CodePrinter._print_NegativeInfinity^      r5   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	            r3   _print_PiecewisezC89CodePrinter._print_Piecewisea  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.functionsr]  r   rewrite)r   r   r]  s      r3   
_print_ITEzC89CodePrinter._print_ITE  s!    -{{4<<	<>??r5   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     r3   _print_MatrixElementz#C89CodePrinter._print_MatrixElement  s[    t00j>P  1  &&466$++*;*;A*>#>>@ 	@r5   c                j    t         |   |      }|| j                  d   v rdj                  |      S |S )Nr   z(*{}))r   _print_Symbol	_settingsr   )r   r   r   r   s      r3   rh  zC89CodePrinter._print_Symbol  s7    w$T*4>>-00>>$''Kr5   c                    | j                  |j                        }| j                  |j                        }|j                  }dj	                  |||      S )Nz{} {} {})r   lhsrhsrel_opr   )r   r   lhs_coderhs_codeops        r3   _print_Relationalz C89CodePrinter._print_Relational  sD    ;;txx(;;txx([[  2x88r5   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   rs  r2  iterabler)   r  NotImplementedErrorrw  r   )r   r   rs  rt  ru  rv  rw  s          r3   
_print_ForzC89CodePrinter._print_For  sz    T[[)dmmU+ $ 2 2E4%&RSS{{499%)*0&e4 +1 +1	1r5   c                \    dj                  | j                  |j                  d               S )Nz((({0}) > 0) - (({0}) < 0))r   )r   r   r  )r   funcs     r3   _print_signzC89CodePrinter._print_sign  s$    ,33DKK		!4MNNr5   c                t     d j                   v r j                  |      S  fd |j                        S )NrU   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rT  r   )r  halfinner_print_maxr   s     r3   r  z2C89CodePrinter._print_Max.<locals>.inner_print_max  \    4yA~{{47++t9>D6$T%4[1$T$%[1:  r5   r   r  r  )r   r   r  s   ` @r3   
_print_MaxzC89CodePrinter._print_Max  8    D(((''--	 tyy))r5   c                t     d j                   v r j                  |      S  fd |j                        S )NrW   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     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                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(
)rL  r	  z 	r   )r   rM  )r2  r3  r   
splitlinesrU  lstripro   anymapr   
startswithrR  rS  )r   code
code_linestab	inc_token	dec_tokenlineincreasedecreaseprettylevelns               r3   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     r3   r  zC89CodePrinter._get_func_suffix  s&    &&t'8'8'<'<UE'JKKr5   c                T    | j                   | j                  j                  ||         S r.   )r   r   r   r  s     r3   r  z"C89CodePrinter._get_literal_suffix  s&    ))$*;*;*?*?u*MNNr5   c                    | j                   j                  ||      }| j                  j                  |d      }| j                  j                  ||      S )Nr   )r   r   r   )r   r   aliasdflts       r3   r   z%C89CodePrinter._get_math_macro_suffix  sK    !!%%eU3,,00;,,00==r5   c                D     ddj                   fd|D              z   dz   S )Nr  r  c              3  @   K   | ]  }j                  |        y wr.   r   )r   rV  r   s     r3   r   z.C89CodePrinter._print_Tuple.<locals>.<genexpr>  s     :T[[^:   rL  )rU  r@  s   ` r3   _print_TuplezC89CodePrinter._print_Tuple  s"    499:T:::3>>r5   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     r3   _print_TypezC89CodePrinter._print_Type  sv    D--11%?@4++//su=>{{4--11%DEEr5   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#   rP  r2  r   r   r   r   r   r   symbolr   ry  )r   r   r   r   valresults         r3   _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r5   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 )NrV  .z.0r   0)r   r   r   r   r  r   r   r  r3  r   r   splitrstripr   rU  )r   fltr   r  r!  	num_partss         r3   _print_FloatzC89CodePrinter._print_Float
  s    !!%%dD14++//su=>))%0#))E--./c>cn4KCIIcN	 |**3/	!Q<  %aLCLxx	"V++r5   r   c                     y)Ntruer   r@  s     r3   _print_BooleanTruez!C89CodePrinter._print_BooleanTrue  s    r5   c                     y)Nfalser   r@  s     r3   _print_BooleanFalsez"C89CodePrinter._print_BooleanFalse  s    r5   c                    |j                   d k(  r?|j                  d k7  rt        d      dj                   fd|j                  D              }nnt        t        |j                  |j                         D cg c]
  \  }}||z   c}}      }|j                  d k7  r||j                  z  } j                  |      }dj                   j                  |j                        |      S c c}}w )Nz%Expected strides when offset is givenz][c              3  @   K   | ]  }j                  |        y wr.   r  r   r#  r   s     r3   r   z0C89CodePrinter._print_Element.<locals>.<genexpr>#  s     G3dkk#.Gr  z{symb}[{idxs}])symbidxs)
r,  r+  rP  rU  r1  r6  r7  r   r   r  )r   elemr  r   r  
global_idxs   `     r3   _print_ElementzC89CodePrinter._print_Element  s    <<4{{d" !HII99G$,,GHDc$,,.MNdaacNOJ{{d"dkk)
;;z*D&&T[[) ' 
 	
 Os   8C*
c           
         dj                  |j                  D cg c]"  }| j                  | j                  |            $ c}      S c c}w )z0 Elements of code blocks printed as statements. rM  )rU  r  r   r   )r   r   r   s      r3   _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    r3   r4   z-C89CodePrinter._print_While.<locals>.<lambda>5  s    dkk#. r5   )applyr   )r   r   r@  s   ` r3   _print_WhilezC89CodePrinter._print_While3  s2    :3:: 1T[[. >I >0 1 	1r5   c                >    d| j                  |j                        z  S )Nz{
%s
})r  rw  r@  s     r3   _print_ScopezC89CodePrinter._print_Scope7  s    D11$))<<<r5   zstdio.hc                     dj                   j                  |j                        dj                   fd|j                  D                    S )Nzprintf({fmt}, {pargs})r  c              3  @   K   | ]  }j                  |        y wr.   r  r  s     r3   r   z.C89CodePrinter._print_Print.<locals>.<genexpr>>  s     I#T[[-Ir  )fmtpargs)r   r   format_stringrU  
print_argsr@  s   ` r3   _print_PrintzC89CodePrinter._print_Print:  sC    '..D../))IIJ / 
 	
r5   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     r3   r   z:C89CodePrinter._print_FunctionPrototype.<locals>.<genexpr>B  s     SC$++k#&67Ss   $'z	%s %s(%s)c              3  @   K   | ]  }j                  |        y wr.   r  r  s     r3   r   z:C89CodePrinter._print_FunctionPrototype.<locals>.<genexpr>D  s     M4;;s#Mr  )rU  
parameterstuplereturn_typer   )r   r   parss   `  r3   _print_FunctionPrototypez'C89CodePrinter._print_FunctionPrototypeA  sN    yyS4??STM0@0@$))/LMNRVQXX
 	
r5   c                J    | j                  |      | j                  |      S r.   )r  r  r@  s     r3   _print_FunctionDefinitionz(C89CodePrinter._print_FunctionDefinitionG  s(    66t<**402 	2r5   c                F    |j                   \  }d| j                  |      z  S )Nz	return %sr  r   r   r   r#  s      r3   _print_ReturnzC89CodePrinter._print_ReturnK  s!    yyT[[---r5   c                R     ddj                   fd|j                  D              z  S )Nz(%s)r  c              3  @   K   | ]  }j                  |        y wr.   r  r  s     r3   r   z6C89CodePrinter._print_CommaOperator.<locals>.<genexpr>P  s     "I4;;s#3"Ir  )rU  r  r@  s   ` r3   _print_CommaOperatorz#C89CodePrinter._print_CommaOperatorO  s!    		"Ityy"IJJJr5   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
})rw  r$   r3  r   rT  r  r  r@  s     r3   _print_LabelzC89CodePrinter._print_LabelR  sz    993tyy>))tyy~~!# #DII0E0Edii0PQQ"%dii.$2G2G		2RSSr5   c                4    d|j                   j                  z  S )Nzgoto %s)r8  r   r@  s     r3   _print_gotozC89CodePrinter._print_gotoY  s    4::??**r5   c                F    |j                   \  }d| j                  |      z  S )Nz++(%s)r  r  s      r3   _print_PreIncrementz"C89CodePrinter._print_PreIncrement\  !    yy$++c***r5   c                F    |j                   \  }d| j                  |      z  S )Nz(%s)++r  r  s      r3   _print_PostIncrementz#C89CodePrinter._print_PostIncrement`  r  r5   c                F    |j                   \  }d| j                  |      z  S )Nz--(%s)r  r  s      r3   _print_PreDecrementz"C89CodePrinter._print_PreDecrementd  r  r5   c                F    |j                   \  }d| j                  |      z  S )Nz(%s)--r  r  s      r3   _print_PostDecrementz#C89CodePrinter._print_PostDecrementh  r  r5   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   rU  declarationsr   )r   r   r   s      r3   _print_structzC89CodePrinter._print_structl  s[    3~~..		EJJ/3/@/@AtT"ARDHMJ7
 
 	
As   A"c                     y)Nr`   r   r   r   s     r3   _print_BreakTokenz C89CodePrinter._print_BreakTokenr  s    r5   c                     y)Nrd   r   r  s     r3   _print_ContinueTokenz#C89CodePrinter._print_ContinueTokenu  rG  r5   r.   )ar   
__module____qualname____doc__printmethodlanguager  r   reserved_wordsr   __annotations__r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r   r   r   r   r   r   r   r   r  known_functions_C89r   r   r   r   r   r   r   r  r   r  r  r&  r)  r>  rA  rC  rF  rI  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  _print_union__classcell__)r   s   @r3   r   r      s   FKHH(N #(u" #)~  	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+++++
 !Lr5   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     r3   rF  zC99CodePrinter._print_Infinity  rG  r5   c                     y)Nz	-INFINITYr   r@  s     r3   rI  z&C99CodePrinter._print_NegativeInfinity  rJ  r5   c                     y)NNANr   r@  s     r3   
_print_NaNzC99CodePrinter._print_NaN  s    r5   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     r3   r   z2C99CodePrinter._print_math_func.<locals>.<genexpr>  s     D3dkk#.Dr  z{ns}{name}{suffix}({args}))r  r   r  r  )r   r   r   r2  r3  r  rP  	TypeErrorr  _prec_funcsr  r   r   rT  r   r|  rU  )
r   r   nestr  cbr   r  r  
paren_pilecurr_args
   `         r3   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     r3   r  zC99CodePrinter._print_Max      $$T$55r5   c                (    | j                  |d      S r(  r)  r@  s     r3   r  zC99CodePrinter._print_Min  r*  r5   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   rt  endrL  )rS  r   r8  lowerupper)r   r1  
open_linesclose_lines	loopstartr   s         r3   _get_loop_opening_endingz'C99CodePrinter._get_loop_opening_ending  s    
N	 	$Ai{{177+QWW-{{177Q;/+1 1 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  r"  rF  rI  r  r&   r   r   r  r  r3  r   r5   r3   r  r  z  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'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y)C11CodePrinterz
stdalign.hr  c                F    |j                   \  }d| j                  |      z  S )Nzalignof(%s)r  r  s      r3   _print_alignofzC11CodePrinter._print_alignof  s!    yyt{{3///r5   N)r   r  r	  r&   r9  r   r5   r3   r7  r7    s    |n%0 &0r5   r7  )c89c99c11N)Br
  
__future__r   typingr   	functoolsr   	itertoolsr   
sympy.corer   sympy.core.numbersr	   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   r5  r  r4  r   r   r   r  r  ksetattrr   r7  c_code_printersr   r5   r3   <module>rJ     s   #     +        = < & :	'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&e![ e!N\'^ \'~89>NA NK!O^-L-LMN0^ 0 r5   