o
    *ήcv                     @   s  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 d dlmZmZmZmZ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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 d dl7m8Z8 d dl9m:Z:m;Z;m<Z< d dl=m>Z>m?Z?m@Z@ d dlAmBZBmCZC d dlDmEZEmFZFmGZG d d	lHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z` d d
lambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZj d dlkmlZl d dlmmnZn d dlompZpmqZq d dlrmsZsmtZtmuZu d dlvmwZw ed\ZxZyZzdd Z{dd Z|dd Z}dd Z~dd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Zd=d> Zd?d@ ZdAdB ZdCdD ZdEdF ZdGdH ZdIdJ ZdKdL ZdMdN ZdOdP ZdQdR ZdSdT ZdUdV ZdWdX ZdYdZ Zd[d\ Zd]d^ Zd_d` Zdadb ZeCdcdd Zdedf Zdgdh Zdidj Zdkdl Zdmdn Zdodp Zdqdr Zdsdt Zdudv Zdwdx ZdyS )z    )SpioosymbolsRationalIntegerFloatModGoldenRatio
EulerGammaCatalanLambdaDummynanMulPowUnevaluatedExpr)EqGeGtLeLtNe)Absacosacoshasinasinhatanatanhatan2ceilingcoscosherferfcexpfloorgammalogloggammaMaxMin	Piecewisesignsinsinhsqrttantanh	fibonaccilucas)Range)ITEImplies
Equivalent)For
aug_assign
Assignment)raisesXFAIL)C89CodePrinterC99CodePrinterget_math_macros)AddAugmentedAssignmentElementType	FloatTypeDeclarationPointerVariablevalue_constpointer_constWhileScopePrintFunctionPrototypeFunctionDefinitionFunctionCallReturnrealfloat32float64float80float128intcComment	CodeBlock)	expm1log1pexp2log2fmalog10CbrthypotSqrt)restrict)implemented_function)IndexedBaseIdx)MatrixMatrixSymbolSparseMatrixccodezx,y,zc                  C   s(   G dd dt } t| tdksJ d S )Nc                   @   s   e Zd Zdd ZdS )ztest_printmethod.<locals>.fabsc                 S   s   d| | jd  S )Nzfabs(%s)r   )_printargs)selfprinter rp   B/tmp/pip-target-vg8gfxp4/lib/python/sympy/printing/tests/test_c.py_ccode"   s   z%test_printmethod.<locals>.fabs._ccodeN)__name__
__module____qualname__rr   rp   rp   rp   rq   fabs!   s    rv   fabs(x))r   rk   x)rv   rp   rp   rq   test_printmethod    s   ry   c                   C   s@   t ttdks
J t td dksJ t ttdksJ d S )Nzsqrt(x)      ?)rk   r1   rx   rp   rp   rp   rq   test_ccode_sqrt(   s   r{   c               
   C   s  t td dks
J t ttd  dksJ tdttdt } t d| td ttt    td t  dks:J t td	 d
ksDJ t ttdd dksQJ t ttdd ttiddksbJ dd dfdd dfg}t td d|iddks|J t td d|iddksJ t ttdd d|iddksJ dd dd fdd dfg}t dt d|iddksJ t td d|iddksJ t td tt	tttd!d"d#d!d"d!d"d$ksJ d S )%N   z	pow(x, 3)zpow(x, pow(y, 3))g      g      @z,pow(3.5*2*x, -x + pow(y, x))/(pow(x, 2) + y)      z1.0/xzpow(x, 2.0/3.0)type_aliaseszpowl(x, 2.0L/3.0L)c                 S   s   |j S N
is_integerbaser&   rp   rp   rq   <lambda>7       z test_ccode_Pow.<locals>.<lambda>dpowic                 S   s   |j  S r   r   r   rp   rp   rq   r   8       powr   user_functionszdpowi(x, 3)rz   zpow(x, 0.5)      zpow(x, 16.0/5.0)c                 S   s   | dkS Nr~   rp   r   rp   rp   rq   r   <   r   c                 S   s   d| S )Nzexp2(%s)rp   r   rp   rp   rq   r   <   r   c                 S   s   | dkS r   rp   r   rp   rp   rq   r   =   r   exp2(x)z	pow(x, 2)Fevaluatez
-2*x/(y*y))
rk   rx   yrd   r   r   rR   rU   r   r   )r}   _cond_cfunc_cond_cfunc2rp   rp   rq   test_ccode_Pow.   s2   *"

"
r   c                   C   s(   t tttt dddddksJ d S )Nmy_maxmy_pow)r+   r   r   zmy_max(x, my_pow(x, 2)))rk   r+   rx   rp   rp   rp   rq   test_ccode_MaxF   s   (r   c                  C   s>   t td } dD ]}t| |d}|d|dksJ qd S )Nza[0:50])c89c99c11standard())r,   r   rk   count)big_mincurr_standardoutputrp   rp   rq   test_ccode_Min_performanceK   s
   r   c                   C   s   t tddks
J t tdksJ t tdddksJ t t dddks'J t tdks/J t t d	dd
ks:J t tttiddksFJ d S )Nr   M_EM_PIr   r   HUGE_VALz	-HUGE_VALINFINITYr   z	-INFINITYr   M_PIl)rk   r&   r   r   rR   rU   rp   rp   rp   rq   test_ccode_constants_mathhS   s   r   c                   C   s^   t dt dtd ksJ t dt dtd ksJ t dt dtd ks-J d S )Nr~   z,const double GoldenRatio = %s;
2*GoldenRatio   z$const double Catalan = %s;
2*Catalanz*const double EulerGamma = %s;
2*EulerGamma)rk   r
   evalfr   r   rp   rp   rp   rq   test_ccode_constants_other^   s   "r   c                   C   s.  t tdddksJ t tddttiddksJ t tdddks%J t tdd	d
ks0J t tdd	ttiddks?J t tdd	dksJJ t tdd	ttiddksYJ t ttdd dksfJ t ttdd ttiddkswJ t tddt dksJ t tddt ttiddksJ d S )Nr|      z3.0/7.0r   z	3.0L/7.0L   	   2z-3.0/7.0z
-3.0L/7.0Lzx + 3.0/7.0zx + 3.0L/7.0Lz(3.0/7.0)*xz(3.0L/7.0L)*x)rk   r   rR   rU   rx   rp   rp   rp   rq   test_ccode_Rationale   s   "&r   c                   C   s,   t tddks
J t tddksJ d S )NC   67r   z-1)rk   r   rp   rp   rp   rq   test_ccode_Integers   s   r   c                   C   s    t tttt dksJ d S )Nzpow(sin(x), cos(x)))rk   r/   rx   r"   rp   rp   rp   rq   test_ccode_functionsx   s    r   c                  C   s   t d} tdt| d|  }t|| dksJ tdt| d|  t }t|| dtd ks3J td}tdt d	d
d}tdt| | d|   d|   }t||| || ddks`J d S )Nrx   r}   r~   z2*xz&const double Catalan = %s;
2*x/Catalanr   AinTintegerr   	assign_toz@for (int i=0; i<n; i++){
   A[i] = (A[i] + 1)*(A[i] + 2)*A[i];
})r   rd   r   rk   r   r   re   rf   )rx   r}   r   r   rp   rp   rq   test_ccode_inline_function|   s    r   c                  C   s   t ttdddksJ t ttdd} d|  v sJ t ttddd} d|  v s-J t ttddd} d|  vs>J d S )	NC99r   	tgamma(x)C89znot supported in cF)r   allow_unknown_functionsT)rk   r(   rx   lower)	gamma_c89rp   rp   rq   test_ccode_exceptions   s   r   c                  C   s~  t ttdks
J t ttdksJ t ttdksJ tddd\} }t tt| t|dks5J t t| |dks@J td	ddd
\}}t t||dksTJ t t||d dksaJ t tdddddksnJ t tdddd dks|J t | t|| dksJ t t||| dksJ tdddd}t t| |dksJ t t|dksJ t t|dksJ d S )Nceil(x)rw   r   zr,sTrR   z)((ceil(r) % ceil(s)) + ceil(s)) % ceil(s)z
fmod(r, s)zp1 p2r   positivezp1 % p2r|   zp1 % (p2 + 3)r   r   Fr   z(-3) % (-7)r   z-(3 % 7)zr*(p1 % p2)zpow(p1 % p2, s)r   )r   negativez	(-n) % p2zI(1.0/5.0)*pow(2, -n)*sqrt(5)*(-pow(1 - sqrt(5), n) + pow(1 + sqrt(5), n))z6pow(2, -n)*(pow(1 - sqrt(5), n) + pow(1 + sqrt(5), n)))	rk   r!   rx   r   r(   r   r	   r4   r5   )rsp1p2r   rp   rp   rq   test_ccode_functions2   s"   r   c                  C   s   t ddd} t ddd}ddd d	fd
d dfgd}tt| |ddks'J tt| |ddks3J tt||ddks?J d S )Nrx   Fr   r   Tceilc                 S   s   | j  S r   r   rx   rp   rp   rq   r      r   z+test_ccode_user_functions.<locals>.<lambda>rv   c                 S   s   | j S r   r   r   rp   rp   rq   r      r   abs)r!   r   r   r   rw   abs(n))r   rk   r!   r   )rx   r   custom_functionsrp   rp   rq   test_ccode_user_functions   s   r   c                   C   sF  t ddksJ t tjdksJ t ddksJ t tjdks"J t tt@ dks,J t ttB dks6J t t dks?J t tt@ t@ dksKJ t ttB tB d	ksWJ t tt@ tB d
kscJ t ttB t@ dksoJ t ttA dksyJ t ttA tA dksJ t tttdksJ t ttttA tttdksJ d S )NTtrueFfalsezx && yzx || yz!xzx && y && zzx || y || zzz || x && yzz && (x || y)z(x || y) && (!x || !y)zF(x || y || z) && (x || !y || !z) && (y || !x || !z) && (z || !x || !y)zy || !xzD(x || (y || !z) && (z || !y)) && (z && !x || (y || z) && (!y || !z)))	rk   r   r   r   rx   r   zr8   r9   rp   rp   rp   rq   test_ccode_boolean   s   &r   c                   C   s   t tttdksJ t tttdksJ t tttdks!J t tttdks,J t tttdks7J t tttdksBJ d S )Nzx == yzx != yzx <= yzx < yzx > yzx >= y)	rk   r   rx   r   r   r   r   r   r   rp   rp   rp   rq   test_ccode_Relational   s   r   c                      s   t ttdk ftd df t dksJ t dddksJ t ttdk ftd tdk ftd df t dks;J t ddd	ksEJ t ttdk ftd tdkftttd
kf tt fdd d S )Nr   r~   Tz'((x < 1) ? (
   x
)
: (
   pow(x, 2)
))cr   z3if (x < 1) {
   c = x;
}
else {
   c = pow(x, 2);
}zB((x < 1) ? (
   x
)
: ((x < 2) ? (
   x + 1
)
: (
   pow(x, 2)
)))zUif (x < 1) {
   c = x;
}
else if (x < 2) {
   c = x + 1;
}
else {
   c = pow(x, 2);
}r   c                      s   t  S r   rj   rp   exprrp   rq   r      r   z&test_ccode_Piecewise.<locals>.<lambda>)r-   rx   rk   r/   r=   
ValueErrorrp   rp   r   rq   test_ccode_Piecewise   s    
(

,r   c                  C   s(   ddl m}  | t}t|dksJ d S )Nr   )sincz'((x != 0) ? (
   sin(x)/x
)
: (
   1
)))(sympy.functions.elementary.trigonometricr   rx   rk   )r   r   rp   rp   rq   test_ccode_sinc   s
   r   c                  C   s   t dtttdk ftd tdk ftd df } | dksJ tt t td  td  tdtdk fd tt d }t |dksCJ t |d	d
dksMJ d S )Nr~   r   TzD2*((x < 1) ? (
   x
)
: ((x < 2) ? (
   x + 1
)
: (
   pow(x, 2)
)))r   rz   )r   TzNpow(x, 2) + x*y*z + pow(y, 2) + ((x < 0.5) ? (
   0
)
: (
   1
)) + cos(z) - 1r   r   zSc = pow(x, 2) + x*y*z + pow(y, 2) + ((x < 0.5) ? (
   0
)
: (
   1
)) + cos(z) - 1;)rk   r-   rx   r   r   r"   )pr   rp   rp   rq   test_ccode_Piecewise_deep
  s   0:

r   c                  C   s$   t tdk tt} t| dksJ d S )Nr   z((x < 1) ? (
   y
)
: (
   z
)))r7   rx   r   r   rk   r   rp   rp   rq   test_ccode_ITE'  s   r   c                   C   s   t tdd  d S )Nc                   S   s   t ttddS )Ngarbage)method)rk   r/   rx   rp   rp   rp   rq   r   3  s    z%test_ccode_settings.<locals>.<lambda>)r=   	TypeErrorrp   rp   rp   rq   test_ccode_settings2  s   r   c                  C   s  t ddd\} }}}td|td|td|}}}td| }td||f }td	|||f }	t }
|
|d
ks>J |
|d|| |  ksMJ |
|	d|| | ||  |  ksbJ tddd||f }|
|dd| |  ks{J tdddd||f }t|d|d|   ksJ tddd| f|d||f }t|dksJ td| ||f|d}t||||f dksJ t|dd|f dksJ d S )Nzs n m oTr   r   jkrx   r   Bzx[j]zA[%s]zB[%s])r   r|   shaper|   F)r   stridesr   )   r   r   )r   r   offsetzA[o + s*j + i]r   r   zA[m*j + n*k + o + s*i]r~   zA[3*m + n*k + o + 2*s])r   rf   re   r@   _print_Indexedrk   )r   r   mor   r   r   rx   r   r   r   Abaserp   rp   rq   test_ccode_Indexed6  s$   "*r   c                   C   sb   t tdddksJ t tddddddksJ t tddd	ks$J t tdd
dks/J d S )Nrx   ijzx[i][j]klr   r   zx[i*k + j*l + o])r|   zx[3])r|      r   z
x[3][4][5])rk   rC   rp   rp   rp   rq   test_ElementR  s   r  c                  C   s   d} t d| fd}t d| fd}t d| d fd}td| d }t|| ||d  ||  ||d  ||   }t|j|jdd	}|d
|d |d f ksPJ d S )Nr   r   r   rx   Dyr   r   F)r   contractz&Dy[i] = (y[%s] - y[i])/(x[%s] - x[i]);)re   rf   r   rk   rhslhs)len_yr   rx   r  r   ecode0rp   rp   rq   2test_ccode_Indexed_without_looking_for_contractionY  s   2 r  c                  C   s|   t ddd\} }td}td}td}td|}td| }d	||  |  d
 }t|||f ||  || d|ks<J d S )Nn mTr   r   rx   r   r   r   z}for (int i=0; i<m; i++){
   y[i] = 0;
}
for (int i=0; i<m; i++){
   for (int j=0; j<n; j++){
      y[i] = A[%s]*x[j] + y[i];
   }
}r   r   re   rf   rk   )r   r   r   rx   r   r   r   r   rp   rp   rq   test_ccode_loops_matrix_vectord  s   


,
r  c                  C   s`   t ddtd\} }td}td}t| |} d| jj|jd }t||  ||  d|ks.J d S )	Nzi mT)r   clsrx   r   zlfor (int i_%(icount)i=0; i_%(icount)i<m_%(mcount)i; i_%(icount)i++){
   y[i_%(icount)i] = x[i_%(icount)i];
})icountmcountr   )r   r   re   rf   labeldummy_indexrk   )r   r   rx   r   expectedrp   rp   rq   test_dummy_loopsy  s   
 r  c            	      C   s   t ddd\} }td}td}td}td}td|}td	| }d
||  |  d }t|||f ||  ||  ||  || d|ksHJ d S )Nr  Tr   r   rx   r   r   r   r   zfor (int i=0; i<m; i++){
   y[i] = x[i] + z[i];
}
for (int i=0; i<m; i++){
   for (int j=0; j<n; j++){
      y[i] = A[%s]*x[j] + y[i];
r  r   r  )	r   r   r   rx   r   r   r   r   r   rp   rp   rq   test_ccode_loops_add  s   


<
r  c                  C   s   t ddd\} }}}td}td}td}td|}td| }td	|}	td
|}
d||  | | || |  |	|  |
 || | |	|  |
 f d }t|||	|
f ||||	|
f  || d|ksgJ d S )Nn m o pTr   abr   r   r   r   lzfor (int i=0; i<m; i++){
   y[i] = 0;
}
for (int i=0; i<m; i++){
   for (int j=0; j<n; j++){
      for (int k=0; k<o; k++){
         for (int l=0; l<p; l++){
            y[i] = a[%s]*b[%s] + y[i];
         }
      }
   }
}r   r  )r   r   r   r   r  r  r   r   r   r   r  r   rp   rp   rq   &test_ccode_loops_multiple_contractions  s   



>6r  c                  C   s  t ddd\} }}}td}td}td}td}td|}td	| }	td
|}
td|}d||  | | |	| |  |
|  | ||  | | |	| |  |
|  | |	| | |
|  | f d }t|||	|
|f |||	|
|f  ||	|
|f  || d|ksJ d S )Nr  Tr   r  r  r   r   r   r   r   r  zfor (int i=0; i<m; i++){
   y[i] = 0;
}
for (int i=0; i<m; i++){
   for (int j=0; j<n; j++){
      for (int k=0; k<o; k++){
         for (int l=0; l<p; l++){
            y[i] = (a[%s] + b[%s])*c[%s] + y[i];
r  r   r  )r   r   r   r   r  r  r   r   r   r   r   r  r   rp   rp   rq   test_ccode_loops_addfactor  s    



dFr  c                  C   s  t ddd\} }}}td}td}td}td}td|}td	| }	td
|}
d}d||  | |	|  |
  d }d|| |
  d }d||  |	  d }t||	 |||	f  ||
 |||
f   ||	 ||
  |||	|
f   || d}||| | |d d  ks||| | |d d  ks||| | |d d  ks||| | |d d  ks||| | |d d  ks||| | |d d  ksJ d S d S d S d S d S d S )Nr  Tr   r  r  r   r   r   r   r   z(for (int i=0; i<m; i++){
   y[i] = 0;
}
z|for (int i=0; i<m; i++){
   for (int j=0; j<n; j++){
      for (int k=0; k<o; k++){
         y[i] = b[j]*b[k]*c[%s] + y[i];
z      }
   }
}
zUfor (int i=0; i<m; i++){
   for (int k=0; k<o; k++){
      y[i] = a[%s]*b[k] + y[i];
z   }
}
zUfor (int i=0; i<m; i++){
   for (int j=0; j<n; j++){
      y[i] = a[%s]*b[j] + y[i];
r   r   r  )r   r   r   r   r  r  r   r   r   r   r   s0s1s2s3rp   rp   rq   test_ccode_loops_multiple_terms  sP   





Rr#  c                  C   s.   t t tt t } t| tgddksJ d S )Ndereferencezx + y + (*z) + sin((*z)))rx   r   r/   r   rk   r   rp   rp   rq   test_dereference_printing  s   r&  c                  C   s  t tt tdt tdkftdfttg} tddd}t| |dks%J td|d  tdkf|d dft|d	  |d
  }t|dksHJ tddd}tddd}t t|d	 dt|d g|d	 |d  |d dgd|d  |d	  t	|d
 d dgg}t||dksJ d S )Nr~   r   Tr   r|   r   zPA[0] = x*y;
if (y > 0) {
   A[1] = x + 2;
}
else {
   A[1] = y;
}
A[2] = sin(z);)r~   r   )r   r   r   r   z:((x > 0) ? (
   2*A[2]
)
: (
   A[2]
)) + sin(A[1]) + A[0]qr   M)r|   r   )r  r   r  zM[0] = sin(q[1]);
M[1] = 0;
M[2] = cos(q[2]);
M[3] = q[1] + q[2];
M[4] = q[3];
M[5] = 5;
M[6] = 2*q[4]/q[1];
M[7] = sqrt(q[0]) + 4;
M[8] = 0;)
rg   rx   r   r-   r/   r   rh   rk   r"   r1   )matr   r   r(  r)  r   rp   rp   rq   test_Matrix_printing	  s$   ,6
$r+  c                   C   s   dt tg dgv sJ d S )NzNot supported in C)r   r~   r|   )rk   ri   rp   rp   rp   rq   test_sparse_matrix1  s   r,  c                  C   s   t d\} }tt t|d ddd W d    n1 sw   Y  t|d dks-J t| |d  |gddks<J t|d d	d
dksHJ d S )Nzx, ifr~   Tr   )error_on_reservedr   zpow(if_, 2)r$  zpow((*if_), 2)*x_unreserved)reserved_word_suffixzpow(if_unreserved, 2))r   r=   r   rk   )rx   r   rp   rp   rq   test_ccode_reserved_words6  s   
r0  c                  C   s   t tt d} }t ttd}}t dt td  t td  d}}t| |ks-J t| dd| ks8J t||ks@J t||ksHJ d S )Nzy*(((x) > 0) - ((x) < 0))z!(((cos(x)) > 0) - ((cos(x)) < 0))r~   zApow(x, 2) + x*(((pow(x, 2) + 2*x) > 0) - ((pow(x, 2) + 2*x) < 0))r   zz = %s;)r.   rx   r   r"   rk   )expr1ref1expr2ref2expr3ref3rp   rp   rq   test_ccode_sign?  s   &r7  c                   C   s:   t tttt dksJ t ttdtt dksJ d S )Nz
x = y + z;+zx += y + z;)rk   r<   rx   r   r   r;   rp   rp   rp   rq   test_ccode_AssignmentH  s    r9  c                  C   s2   t ttdddttdtg} t| dksJ d S )Nr   
   r~   *z*for (x = 0; x < 10; x += 2) {
   y *= x;
})r:   rx   r6   r;   r   rk   )frp   rp   rq   test_ccode_ForM  s   r=  c                   C   sX   t ttddddksJ t ttddddksJ t ttdttdddks*J d S )	Nr   r   r   z((0 > x) ? 0 : x)r   z
fmax(0, x)r   zI((0 < ((x < sqrt(x)) ? x : sqrt(x))) ? 0 : ((x < sqrt(x)) ? x : sqrt(x))))rk   r+   rx   r,   r1   rp   rp   rp   rq   test_ccode_Max_MinS  s
   r>  c                   C   sH   t ttdddksJ t tdddksJ t tddddks"J d S )Nr   r   expm1(x)NANr   )rk   rZ   rx   r   floatrp   rp   rp   rq   test_ccode_standardZ  s   rB  c                  C   sB   t  } | jdks
J | jdksJ d| jv sJ d| jvsJ d S )NCr   voidtemplate)r?   languager   reserved_words)
c89printerrp   rp   rq   test_C89CodePrinter`  s
   rI  c                  C   s\  t  ttdksJ t  ttdksJ t  ttdks$J t  ttdks0J t  tttt	 dks?J t  t
tdksKJ t  ttdksWJ t  tttdksdJ t  ttd	kspJ t  ttd
td dksJ t  ttd
dksJ t  } | jdksJ | jdksJ d| jv sJ d| jvsJ d S )Nr?  zlog1p(x)r   zlog2(x)zfma(x, y, -z)zlog10(x)zcbrt(x)zhypot(x, y)z	lgamma(x)r|   r~   zfmax(3, fmax(x, pow(x, 2)))z
fmin(3, x)rC  r   rc   using)r@   doprintrZ   rx   r[   r\   r]   r^   r   r   r_   r`   ra   r*   r+   r,   rF  r   rG  )
c99printerrp   rp   rq   test_C99CodePrinterh  s     rM  c                  C   s4   t tttid} | tttd dksJ d S )Nr   z2.1zsinl(x + 2.1L))r@   dictrR   rU   rK  r/   rx   r   )f80_printerrp   rp   rq   "test_C99CodePrinter__precision_f80{  s   "rP  c                     s  t ddd} t dddd}ttttid}ttttid}ttttid}|tt	d dks5J |tt	d d	ksBJ |tt	t
d
 dksQJ t|||gg dD ]\  fdd}|t| d |tt	d d |tt	d tt	d  d |tt	d d |tt	d |tt	d d |t|dd |td| d d| d ddd |tt	d dd  |tt	dt	 d d! |tt	d d" |tdt	 d d# |tt	d d$ |tt	d% |dt	 d& |dt	 d' |t	d d( |t	d d) |tdt	 d* |tt	d d+ |tt	td, |tdt	 d d- |tdt	 d. d/ |tdt d d0 |tdt	 d d1 |tdt	 d d2 |tdt	 d d3 |tdt	 dt d4 |tdt	 d d5 |t dt	 d. d6 |t!dt d d7 |t"dt	 d d8 |t#dt	 d d9 |t$dt	 d d: |t%d;t	 d< |t&d;t	 d= |t't	d> |t(t	d? |t)t	d d@ |t*t	d dA |t+t	tt, dB |t-t	dt	d dC |t.t	ddD q[d S )ENr   Tr   r   r   r   g @zsinf(x + 2.1F)zsin(x + 2.1000000000000001)z2.0zsinl(x + 2.0L))r<   r  c                    s$     | |j dksJ d S )N)r   r   )rK  formatupper)r   refro   suffixrp   rq   check  s   $z-test_C99CodePrinter__precision.<locals>.checkr          @zfabs{s}(x + 2.0{S})g      @z.pow{s}(sin{s}(x + 4.0{S}), cos{s}(x - 2.0{S}))g       @zexp{s}(8.0{S}*x)z
exp2{s}(x)zexpm1{s}(4.0{S}*x)r~   zp % 2r|   r   Fr   z(2*p + 3) % (3*p + 5)g      @z"fmod{s}(1.0{S}*x + 2.0{S}, 3.0{S})z$fmod{s}(1.0{S}*x, 2.0{S}*x + 3.0{S})zlog{s}((1.0{S}/2.0{S})*x)zlog10{s}((3.0{S}/2.0{S})*x)zlog2{s}(8.0{S}*x)zlog1p{s}(x)zpow{s}(2, x)zpow{s}(2.0{S}, x)zpow{s}(x, 3)zpow{s}(x, 4.0{S})zsqrt{s}(x + 3)zcbrt{s}(x - 2.0{S})zhypot{s}(x, y)zsin{s}(3.0{S}*x + 2.0{S})g      ?zcos{s}(3.0{S}*x - 1.0{S})ztan{s}(4.0{S}*y + 2.0{S})zasin{s}(3.0{S}*x + 2.0{S})zacos{s}(3.0{S}*x + 2.0{S})zatan{s}(3.0{S}*x + 2.0{S})zatan2{s}(3.0{S}*x, 2.0{S}*y)zsinh{s}(3.0{S}*x + 2.0{S})zcosh{s}(3.0{S}*x - 1.0{S})ztanh{s}(4.0{S}*y + 2.0{S})zasinh{s}(3.0{S}*x + 2.0{S})zacosh{s}(3.0{S}*x + 2.0{S})zatanh{s}(3.0{S}*x + 2.0{S})g      E@zerf{s}(42.0{S}*x)zerfc{s}(42.0{S}*x)ztgamma{s}(x)zlgamma{s}(x)zceil{s}(x + 2.0{S})zfloor{s}(x + 2.0{S})zfma{s}(x, y, -z)z.fmax{s}(8.0{S}, fmax{s}(x, pow{s}(x, 4.0{S})))zfmin{s}(2.0{S}, x))/r   r@   rN  rR   rS   rT   rU   rK  r/   rx   r   zipr   r"   r&   r\   rZ   r	   r)   r_   r]   r[   r1   r`   ra   r   r2   r   r   r   r    r0   r#   r3   r   r   r   r$   r%   r(   r*   r!   r'   r^   r   r+   r,   )r   r   f32_printerf64_printerrO  rW  rp   rU  rq   test_C99CodePrinter__precision  sl   $r\  c                  C   s6   t  } | td dksJ | dtd  dksJ d S )Nr   r   r~   	M_SQRT1_2)rA   r&   rb   )macrosrp   rp   rq   test_get_math_macros  s   r_  c                  C   sZ  t ddd} t| t| d}t|}t|dksJ tttthd}t|}t|dks/J |j	t
d}t|d	ks=J tttd
d}t|}t }d|jvsSJ ||dks\J d|jv scJ t ddd}	tj|	tthd}
t|
}t|dks~J tttdthd}t|}t|dksJ t|j|jt
|jd}t|}t|dksJ d S )Nr   Tr   typezint i)ra  attrszconst float x)valuezconst float x = M_PIboolz	stdbool.hzbool yur   rb  zdouble * const restrict u
__float128zconst __float128 xzconst __float128 x = M_PI)r   rH   rD   	from_exprrF   rk   rx   rS   rI   as_Declarationr   r   r?   headersrK  rG   deducedrJ   rc   symbolra  rb  )r   var1dcl1var2dcl2adcl2bvar3dcl3ro   re  ptr4dcl4var5dcl5avar5bdcl5brp   rp   rq   test_ccode_Declaration  s2   rz  c               	   C   s  t dtjtjtj} ttt| i| di| ditd| di| did}|t	dks*J |j
r/J |jr4J |jr9J |ddksBJ |j
rGJ |jrLJ |jd	hksTJ |td
ddks`J |tt	dkskJ |tddddksxJ |t	d dksJ tt	| thd}t|}t|dksJ tt	| tthd}t|}||dksJ tt	| tdthd}t|}||dt| j ksJ d S )N	_Float128Qf128)!__STDC_WANT_IEC_60559_TYPES_EXT__)r   type_literal_suffixestype_func_suffixestype_math_macro_suffixestype_macrosrx   rX  z2.0Qr~  r   r~   z	1.0Q/2.0Qz
sinf128(x)Fr   zcosf128(2.0Q)r   z1.0Q/xrf  zconst _Float128 xzconst _Float128 x = M_PIf128&   )rc  rb  zconst _Float128 x = %sQ)rE   rV   nbitsnmantnexpr@   rN  rR   rK  rx   rj  	librariesr^  r   r/   r"   rH   rI   rF   rk   r   r   r   decimal_dig)r}  p128rv  rw  rx  ry  dcl5crp   rp   rq   test_C99CodePrinter_custom_type  s@   




"r  c                  C   sx   t ddd} t ddd}t ddd}t| d dksJ td| d  dks(J |d || | }t|d	ks:J d S )
Nr   r   r|   r   rC  r'  zA[0]z3*A[0]z
(A - B)[0])rh   rk   subs)r   r   rC  r   rp   rp   rq   test_MatrixElement_printing  s   r  c                   C   s  t ttd dksJ t tttd dksJ t tdtd  dks(J t ttd dks4J t ttd dks@J t tt dksJJ t ttd  d	ksVJ t ttd
  dksbJ t tdt  dksnJ t tdt  dkszJ t tdtt  dksJ t tdtt  dksJ t ttd dksJ t ttd dksJ t tdtd  dksJ t tdtd  dksJ d S )Nr   zz + M_Ezz + M_LOG2Er~   z	z + M_LN2r:  z
z + M_LN10zz + M_PIz
z + M_PI_2r  z
z + M_PI_4z
z + M_1_PIz
z + M_2_PIzz + M_2_SQRTPIzz + M_SQRT2zz + M_SQRT1_2)rk   r   r&   r]   r)   r   r1   rb   rp   rp   rp   rq   test_ccode_math_macros  s     r  c                   C   s(   t tddks
J t tdksJ d S )NrA  int)rk   rD   rW   rp   rp   rp   rq   test_ccode_Type+     r  c               	   C   s   t tddks
J t tttdkttddgdksJ t tttdgdks,J tt	tt
d} t tt
d| gd	ksAJ t tt
d| gtttd
 gdksUJ tttttgdtdtgtt}t |dg dkstJ d S )Nzthis is a commentz/* this is a comment */r   -z"while (fabs(x) > 1) {
   x -= 1;
}z{
   x += 1;
}r`  pwerzdouble pwer(double x)r~   z*double pwer(double x){
   x = pow(x, 2);
}z%d %d
)zx;zprintf("%d %d", x, y);zpwer(x);z	return x;)rk   rX   rK   r   rx   r;   rL   rB   rF   rH   rR   rN   rO   r<   rY   rM   r   rP   rQ   join)inp_xblockrp   rp   rq   test_ccode_codegen_ast0  s&   
r  c                  C   s   t ttt t dksJ t ttt t dksJ td} t ttt tt|   dks2J tddd\}}}t|| }tt|| }t |dksQJ d S )	Nzz + x*yzz + (x + y)wz(w + z) + (x + y)zp q rTr   zexp(p + (q + r)))rk   r   r   rx   r   r   r   r&   )r  r   r(  r   q_rr   rp   rp   rq   test_ccode_UnevaluatedExprU  s   $r  c                   C   s(   t g ddks
J t ddksJ d S )N)r~   r|   r  z	{2, 3, 4}rj   rp   rp   rp   rq    test_ccode_array_like_containersa  r  r  N)
sympy.corer   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   sympy.core.relationalr   r   r   r   r   r   sympy.functionsr   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   
sympy.setsr6   sympy.logicr7   r8   r9   sympy.codegenr:   r;   r<   sympy.testing.pytestr=   r>   sympy.printing.cr?   r@   rA   sympy.codegen.astrB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   sympy.codegen.cfunctionsrZ   r[   r\   r]   r^   r_   r`   ra   rb   sympy.codegen.cnodesrc   sympy.utilities.lambdifyrd   sympy.tensorre   rf   sympy.matricesrg   rh   ri   sympy.printing.codeprinterrk   rx   r   r   ry   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  r  r  r#  r&  r+  r,  r0  r7  r9  r=  r>  rB  rI  rM  rP  r\  r_  rz  r  r  r  r  r  r  r  rp   rp   rp   rq   <module>   s   L  |h,
	*/(		
< )%