K i9RddlmZddlmZddlmZddlmZmZm Z m Z m Z m Z ddl mZdjZej"Dcgc]\}}|evs ||fc}}Zeefidd d d d d dddddddd ZddddddZej#Dcic] \}}|d|z c}}Zej#Dcic] \}}|d|z c}}ZGdde eZeD]Zeedee eD]Zeedee id d!d"d"d#d#d$d%d&d'd(d)d*d+d,d,d-d-d.d.d/d/d0d1d2d3d4d4d5d6d7d8d9d:d;dd?d@dAdBdCZdDddEZej#Dcic] \}}|dF|z c}}Zej#Dcic] \}}|dG|z c}}ZGdHdIeZ eD]Zee dee eD]Zee dee ej#Dcic] \}}|dJ|z c}}Z!ej#Dcic] \}}|dJ|z c}}Z"GdKdLeZ#e!D]Zee#dee e"D]Zee#dee ej#Dcic] \}}|dM|z c}}Z$ej#Dcic] \}}|dM|z c}}Z%GdNdOeZ&e$D]Zee&dee e%D]Zee&dee yPcc}}wcc}}wcc}}wcc}}wcc}}wcc}}wcc}}wcc}}wcc}}w)Q)S)Lambda)Pow)PythonCodePrinter_known_functions_math_print_known_const_print_known_func_unpack_integral_limits ArrayPrinter) CodePrinterz!erf erfc factorial gamma loggammaarccosarccosharcsinarcsinharctanarctan2arctanhexp2sign logaddexp logaddexp2isinfisnan) acosacoshasinasinhatanatan2atanhrrrrrrepi euler_gammananinf)Exp1Pi EulerGammaNaNInfinityznumpy.ceZdZdZdZeZeZd0fd Z dZ dZ dZ dZ dZd Zd Zd Zd Zd ZdZdZdZdZdZdZdZfdZdZdZdZd1dZde fdZ!dZ"dZ#dZ$dZ%d Z&d!Z'd"Z(d#Z)d$Z*d%Z+d&Z,d'Z-d(Z.d)Z/d*Z0d+Z1d,Z2d-Z3d.Z4d/Z5e6jnZ8e6jnZ9e6jnZ:e6jnZ;xZz*NumPyPrinter._print_seq..Bs,O4T[[->,O)r2join)r:seq delimiters` r< _print_seqzNumPyPrinter._print_seq=s( ~~inn,O3,OOPPr=cFd|jtjzS)N-)rCrr+r:exprs r<_print_NegativeInfinityz$NumPyPrinter._print_NegativeInfinityDsT[[,,,r=cR|jdtjurQ|jd|jdgz}djdj fd|DSdjdj fd|j DS)zMatrix multiplication printerrr({})z).dot(c3@K|]}j|ywrArBrDir:s r<rFz-NumPyPrinter._print_MatMul..Ks.Q!t{{1~.QrGc3@K|]}j|ywrArBrTs r<rFz-NumPyPrinter._print_MatMul..Ls*Ma4;;q>*MrG)as_coeff_matricesrOner2rHargs)r:rO expr_lists` r< _print_MatMulzNumPyPrinter._print_MatMulGs  ! ! #A &aee 3..03d6L6L6Nq6Q4SSI==.Qy.Q!QR R}}X]]*M499*MMNNr=cdj|j|jdz|j|jd|j|jdS)zMatrix power printerz {}({}, {})z.linalg.matrix_powerrrr2_module_formatr3rCrYrNs r< _print_MatPowzNumPyPrinter._print_MatPowNsU""4#6#6t||F\7\#] KK ! %t{{499Q<'@B Br=cdj|j|jdz|j|jdS)zMatrix inverse printer{}({})z .linalg.invrr]rNs r<_print_InversezNumPyPrinter._print_InverseSs=t224<<-3OP KK ! %' 'r=c"|j\}}|jddk7r |j}|jddk7r |j}|j|jdzd|j |d|j |dS)Nrrz.dot(r?))rYshapeTr^r3rC)r:rOarg1arg2s r<_print_DotProductzNumPyPrinter._print_DotProductXs|YY d ::a=A 66D ::a=A 66D#224<<&3HI#{{40#{{402 2r=c|j|jdzd|j|jd|j|jdS)Nz .linalg.solverdr?re)r^r3rCmatrixvectorrNs r<_print_MatrixSolvezNumPyPrinter._print_MatrixSolveesC#224<.xs@3dkk#&@rGr) sympy.abcrUrulamda isinstancerr2r^r3rHrYrCrf)r:rOrUrurzs` r<_print_FunctionMatrixz"NumPyPrinter._print_FunctionMatrixrs" %(Aq65A;/E&--d.A.A$,,Q`B`.a II@%**Q-@ @ KK 1 & DJJ(?A Ar=c"jjdzdjfd|jddDdj j |jddt |jdz zzS)N .multiplyc3`K|]%}djj|'ywz{}({}, Nr2rCrDrxfuncr:s r<rFz6NumPyPrinter._print_HadamardProduct..}/'!''dkk#.>?'+.{}{}rerr^r3rHrYr2rClenr:rOrs` @r<_print_HadamardProductz#NumPyPrinter._print_HadamardProduct{s}""4<<+#=>ww'yy"~'')/t{{499R=7Q 3tyy>A% &*(( (r=c"jjdzdjfd|jddDdj j |jddt |jdz zzS)Nz.kronrc3`K|]%}djj|'ywrrrs r<rFz7NumPyPrinter._print_KroneckerProduct..rrrrrerrrs` @r<_print_KroneckerProductz$NumPyPrinter._print_KroneckerProducts}""4<<'#9:ww'yy"~'')/t{{499R=7Q 3tyy>A% &*(( (r=cdj|j|jdz|j|jdz|j|jdS)Nz {}({}({}))z .conjugatez .transposerr]rNs r<_print_AdjointzNumPyPrinter._print_AdjointsW""    | ; <    | ; < KK ! %' 'r=cdj|j|jdz|j|j}dj|j|jdz|S)Nraz.diagz{}({}, (-1, 1))z.reshape)r2r^r3rCrx)r:rOvects r<_print_DiagonalOfzNumPyPrinter._print_DiagonalOfsg    w 6 7 KK !#!''    z 9 :DB Br=cdj|j|jdz|j|jdS)Nraz .diagflatrr]rNs r<_print_DiagMatrixzNumPyPrinter._print_DiagMatrixs=t224<<+3MN KK ! %' 'r=c >dj|j|jdz|j|j|j|jdz|j|j d|j|j dS)Nz{}({}, {}({}, {}))r~.eyerr)r2r^r3rCrxrfrNs r<_print_DiagonalMatrixz"NumPyPrinter._print_DiagonalMatrixsz#**4+>+>t||k?Y+Z KK !4#6#6t||f7L#M KK 1 & DJJqM(BD Dr=cddlmmfddjdj fd|j D}djdj fd|j D}djj jd z||jtjS) zPiecewise function printerr)ITEsimplify_logiccv|jrj|Sj|S)z$ Problem having an ITE in the cond. )hasrC)condrr:rs r< print_condz1NumPyPrinter._print_Piecewise..print_conds1xx}{{>$#788{{4((r=z[{}],c3TK|]}j|j!ywrA)rCrOrws r<rFz0NumPyPrinter._print_Piecewise..s&Rt{{388'<&Rs%(c3BK|]}|jywrA)r)rDrxrs r<rFz0NumPyPrinter._print_Piecewise..s&Qz#((';&Qsz{}({}, {}, default={})z.select) sympy.logic.boolalgrrr2rHrYr^r3rCrr*)r:rOexprscondsrrrs` @@@r<_print_PiecewisezNumPyPrinter._print_Piecewises; )  chh&R &RRS chh&Qtyy&QQR (..    y 8 95% KK   r=c<ddddddd}|j|vrv|j|j}|j|j}dj |j |j d z||jz|| St|!|S) z.Relational printer for Equality and Unequalityequal not_equalless less_equalgreater greater_equal)z==z!=z>=z{op}({lhs}, {rhs}).)oplhsrhs) rel_oprCrrr2r^r3r7_print_Relational)r:rOrrrr;s r<rzNumPyPrinter._print_Relationals!   ;;" ++dhh'C++dhh'C'..$2E2EdllUXFXY[\`\g\gYhFh2i36C/A Aw(..r=cdjjjdzdjfd|jDS)Logical And printer{}.reduce(({}))z .logical_andrc3@K|]}j|ywrArBrTs r<rFz*NumPyPrinter._print_And..s'eHxyeiepepqreseHrGr2r^r3rHrYrNs` r< _print_AndzNumPyPrinter._print_Andsc !''(;(;DLL>.s'dGwxdhdodopqdrdGrGrrNs` r< _print_OrzNumPyPrinter._print_Orsc !''(;(;DLL=.s[~op\`\g\ghi\j[~rGrrNs` r< _print_NotzNumPyPrinter._print_NotsC t224<<.3PQSVS[S[[~txt}t}[~S~r=c|jjrF|jjr0t|j|jj d}|j |||jdzS)NF)evaluatez.sqrt)rationalsqrt)exp is_integer is_negativerbaseevalf _hprint_Powr3)r:rOrs r< _print_PowzNumPyPrinter._print_PowsY 88  488#7#7tyy$((.."2UCDxdllW>TUUr=rct|dk(rtd|t|dk(r|j|dS|jd}|Dcgc]}|j|}}|d|ddj |dScc}w) NrzNeed at least one argument for rzfunctools.reducerdz, [r?z]))rNotImplementedErrorrCr^rH)r:rrY_reducerxs_argss r<_helper_minimum_maximumz$NumPyPrinter._helper_minimum_maximums t9>%(Gt&LM M Y!^;;tAw' '%%&89.23s$++c"33!B4s499V#4"5R884sBc$|j|SrA)_print_minimumrNs r< _print_MinzNumPyPrinter._print_Min""4((r=cdj|j|jdz|j|j|j|j S)N{}({}, axis={})z.aminr2r^r3rCarrayaxisrNs r< _print_aminzNumPyPrinter._print_aminc ''(;(;DLL7.s 3#T[[  3rGre)r^r3rHrYrNs` r< _print_ModzNumPyPrinter._print_Mods<..t||f/DEtyy 3 3H56 6r=c|j|jdzd|j|jddS)Nz.realrdrrerrNs r< _print_rezNumPyPrinter._print_rerr=c|j|jdzd|j|jdtj z dS)Nz.sincrdrre)r^r3rCrYrr(rNs r< _print_sinczNumPyPrinter._print_sincsC..t||g/EF TXT]T]^_T`abaeaeTeHfggr=cd|jvrK|j|jd|j}|d|j |jdS|j j |jjd}||j|jd}|d|j |jdS)Nrrrdre.array) rfr^r3_zerosrCknown_functionsgetr;__name__tolistrs r<_print_MatrixBasezNumPyPrinter._print_MatrixBase s  ?&&$,,q 'FGDV1T[[45Q7 7##''(?(?F <&&$,,v'>?DT[[]!;<.s/#s~~/srrdrrezFSymbolic matrix dimensions are not yet supported for identity matrices)rfallr^r3rCr)r:rOrfs r<_print_IdentityzNumPyPrinter._print_IdentitysZ  // /#224<<&3HI4;;W[WaWabcWdKef f%&no or=cdj|j|jdz|j|jdj S)Nraz.blockr)r2r^r3rCrYrrNs r<_print_BlockMatrixzNumPyPrinter._print_BlockMatrixsHt224<<(3JK!%TYYq\-@-@-B!CE Er=c|jdk(r8|j|jd}|d|j|ddSd|jvrK|j|jd|j }|d|j|jdS|j|jd}|d|j|j dS)Nrrrdrer)rankr^r3rCrfrrrs r<_print_NDimArrayzNumPyPrinter._print_NDimArrays 99;! &&$,,v'>?DV1T[[b2315 5  ?&&$,,q 'FGDV1T[[45Q7 7""dll^6#:;qT[[]34A66r=addeinsum transposeoneszerosrA)F)=r __module__ __qualname____doc__r3_numpy_known_functionsr6_numpy_known_constants_kcr8rKrPr[r_rbrjrnrqrsr|rrrrrrrrrrrrstrrrrrrrrrrrrrrrrr _add_einsum _transpose_onesrr _print_not_supported_print_lowergamma_print_uppergamma_print_fresnelc_print_fresnels __classcell__r;s@r<r-r-%s> G C C ,Q-OB ' 29 %%A( ( ' B'D  &/"IH@V 9#9)F<)F<dc6ch=pE7 DGJ E F#88#88!66O!66Or=r-_print_Eiexpierferfcbesseljjvbesselyyvbesseliivbesselkkvcosm1powm1 factorialgammaloggammagammalndigammapsi polygammaRisingFactorialpochjacobi eval_jacobi gegenbauereval_gegenbauer eval_chebyt eval_chebyu eval_legendre eval_hermite eval_laguerreeval_genlaguerrebetalambertw) chebyshevt chebyshevulegendrehermitelaguerreassoc_laguerrerCLambertW golden_ratio) GoldenRatior(zscipy.special.zscipy.constants.ceZdZiejeZiej eZdfd ZdZ e Z dZ dZ dZ dZdZdZd Zd Zd Zd Zd ZdZdZdZdZdZxZS) SciPyPrinterc4t||d|_y)Nr0zPython with SciPy and NumPy)r7r8r4r9s r<r8zSciPyPrinter.__init__as (+5 r=c$ggg}}}|jjD];\\}}}|j||j||j|=dj|j d||||j S)Nz+{name}(({data}, ({i}, {j})), shape={shape})zscipy.sparse.coo_matrix)namedatarUrurf)todokitemsappendr2r^rf)r:rOrUrurSrcvs r<_print_SparseRepMatrixz#SciPyPrinter._print_SparseRepMatrixesRd1++- IFQA HHQK HHQK KKN  =CC$$%>?atzzD  r=c dj|jd|j|jd|j|jd|j|jdS)Nz{0}({2}, {1}, {3})zscipy.special.lpmvrrr2r^rCrYrNs r<_print_assoc_legendrez"SciPyPrinter._print_assoc_legendrets`#**    4 5 KK ! % KK ! % KK ! % ' 'r=c dj|jd|jd|j|jd|j|jdS)N{0}({2})*{1}({2}, {3})scipy.special.gammazscipy.special.gammaincrrr]rNs r<rzSciPyPrinter._print_lowergamma{s['..    5 6    8 9 KK ! % KK ! % ' 'r=c dj|jd|jd|j|jd|j|jdS)Nr`razscipy.special.gammainccrrr]rNs r<rzSciPyPrinter._print_uppergammas['..    5 6    9 : KK ! % KK ! % ' 'r=c|jd}|jd}|jDcgc]}|j|}}d|d|dd|dd|dd|d|dd|dd|d d |d|dd|dd Scc}w) Nscipy.special.betainczscipy.special.betardrr?rz) - r\z)) * re)r^rYrC)r:rObetaincrCrxrYs r<_print_betainczSciPyPrinter._print_betaincs%%&=>""#78,0II6S C 667)1T!WIRQy47)4y$q'RTUYZ[U\T]]_`def`g_hifAd1gYba , ,7sBc *dj|jd|j|jd|j|jd|j|jd|j|jdS)Nz'{0}({1}, {2}, {4}) - {0}({1}, {2}, {3})rdrrr\rer]rNs r<_print_betainc_regularizedz'SciPyPrinter._print_betainc_regularizedst8??    7 8 KK ! % KK ! % KK ! % KK ! % ' 'r=c|dj|jd|j|jdS)N {}({})[0]scipy.special.fresnelrr]rNs r<rzSciPyPrinter._print_fresnels8!!##$;< DIIaL)+ +r=c|dj|jd|j|jdS)N {}({})[1]rlrr]rNs r<rzSciPyPrinter._print_fresnelcrmr=c|dj|jd|j|jdS)Nrkscipy.special.airyrr]rNs r< _print_airyaizSciPyPrinter._print_airyai8!!##$89 DIIaL)+ +r=c|dj|jd|j|jdS)Nrorqrr]rNs r<_print_airyaiprimezSciPyPrinter._print_airyaiprimersr=c|dj|jd|j|jdS)Nz {}({})[2]rqrr]rNs r< _print_airybizSciPyPrinter._print_airybirsr=c|dj|jd|j|jdS)Nz {}({})[3]rqrr]rNs r<_print_airybiprimezSciPyPrinter._print_airybiprimersr=cR|j|j|jSrArC_eval_rewrite_as_zetarYrNs r<_print_bernoullizSciPyPrinter._print_bernoullis#{{5455tyyABBr=cR|j|j|jSrAr{rNs r<_print_harmoniczSciPyPrinter._print_harmonics#{{5455tyyABBr=c t|\}}t|dk(r7jd}dtt j |dz}n:jd}dj djfd|D}d j |djt j |j |jd|S) Nrzscipy.integrate.quadz%s, %srzscipy.integrate.nquadrRr?c3bK|]&}dttj|z(yw)z(%s, %s)N)tuplemaprC)rDlr:s r<rFz/SciPyPrinter._print_Integral..s-0I<= U3t{{A#6770Is,/z{}(lambda {}: {}, {})[0]) r rr^rrrCr2rHrY)r:r"integration_varslimits module_str limit_strs` r<_print_IntegralzSciPyPrinter._print_Integrals#:1#= & v;! ,,-CDJ 5T[[&))D#EEI,,-DEJ dii0IAG0I'IJI*00 #dkk+;<= AFF1I&  r=c|dj|jd|j|jdS)Nrkscipy.special.sicirr]rNs r< _print_SizSciPyPrinter._print_Sirsr=c|dj|jd|j|jdS)Nrorrr]rNs r< _print_CizSciPyPrinter._print_Cirsr=rA)rrrr-r6_scipy_known_functionsr_scipy_known_constantsr8rZ_print_ImmutableSparseMatrixr^rrrgrirrrrrurwryr}rrrrrr s@r<rOrO\s 8\   8!7 8C 8\   8!7 8C6  $: ''','+ + + + + + CC$+ +r=rOzcupy.c0eZdZdZdZeZeZdfd Z xZ S) CuPyPrinterz` CuPy printer which handles vectorized piecewise functions, logical operators, etc. cupyc&t||y)Nr0)r7r8r9s r<r8zCuPyPrinter.__init__s (+r=rA) rrrrr3_cupy_known_functionsr6_cupy_known_constantsrr8rr s@r<rrs# G C C,,r=rz jax.numpy.c<eZdZdZdZeZeZdfd Z dZ dZ xZ S) JaxPrinterz_ JAX printer which handles vectorized piecewise functions, logical operators, etc. z jax.numpyc4t||d|_y)Nr0_jaxcode)r7r8r5r9s r<r8zJaxPrinter.__init__s (+%r=cdjjjdzjjdjfd|jDS)r{}({}.asarray([{}]), axis=0)z.allrc3@K|]}j|ywrArBrTs r<rFz(JaxPrinter._print_And..7T[[^7rGrrNs` r<rzJaxPrinter._print_And U-44    v 5 6    - HH7TYY7 7  r=cdjjjdzjjdjfd|jDS)rrz.anyrc3@K|]}j|ywrArBrTs r<rFz'JaxPrinter._print_Or..rrGrrNs` r<rzJaxPrinter._print_Orrr=rA) rrrrr3_jax_known_functionsr6_jax_known_constantsrr8rrrr s@r<rrs(G C C&   r=rN)' sympy.corersympy.core.functionrsympy.core.powerrpycoderrr r r r codeprinterr split _not_in_numpyrU _in_numpydict_known_functions_numpy_known_constants_numpyrrr-rsetattrconst_known_functions_scipy_special _known_constants_scipy_constantsrrrOrrrrrr)krYs00r<rs& KK$499; ; 5 ; ; = X1-AWaV X i           ,"    7M6R6R6TUda!X\/U6L6R6R6TUda!X\/UK7?$AE LGE7+-?@A"&" 5" F"t " t " t "t" W" W"" W" "u""v"  m!""##"$ ( 3":" $ @^?c?c?eftq!!.22fAaAgAgAijA!0144j{+<{+z #?D LGD6*,=>?$AE LGE7+-?@A6L5Q5Q5STTQWq[T5K5Q5Q5STTQWq[T ,, , ">D K74&)+<=>#@E K75'*,>?@9O8T8T8VW1 !=D J'$(*;<="?E J'%)+=>?g Y2VUl gjLUT,XWs< KKK=KK K&K,K2K8K>