U
    ZÊ¹j³[  ã                3   @  s  d Z ddlmZ ddlmZ ddlmZ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 dd	lmZ 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'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<g3Zd=d>d?d@dAdBdCdDœZG dEdF„ dFeƒZdLdHdI„ZdJdK„ ZdGS )Ma  
Julia code printer

The `JuliaCodePrinter` converts SymPy expressions into Julia expressions.

A complete code generator, which uses `julia_code` extensively, can be found
in `sympy.utilities.codegen`.  The `codegen` module can be used to generate
complete source code files.

é    )Úannotations)ÚAny)ÚMulÚPowÚSÚRational)Ú_keep_coeff)Úequal_valued)ÚCodePrinter)Ú
precedenceÚ
PRECEDENCE©ÚsearchÚsinÚcosÚtanZcotÚsecZcscÚasinÚacosÚatanZacotZasecZacscÚsinhÚcoshÚtanhZcothZsechZcschÚasinhÚacoshÚatanhZacothZasechZacschZsincÚatan2ÚsignÚfloorÚlogÚexpZcbrtÚsqrtÚerfÚerfcZerfiÚ	factorialÚgammaZdigammaZtrigammaZ	polygammaÚbetaZairyaiZairyaiprimeZairybiZairybiprimeÚbesseljÚbesselyZbesseliZbesselkZerfinvZerfcinvÚabsÚceilZconjZhankelh1Zhankelh2ÚimagÚreal)ZAbsZceilingÚ	conjugateZhankel1Zhankel2ÚimÚrec                      sº  e Zd ZU dZdZdZddddœZeej	fdi d	d	d
œŽZ	de
d< i f‡ fdd„	Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Z‡ fd%d&„Zd'd(„ Z‡ fd)d*„Z‡ fd+d,„Z‡ fd-d.„Z‡ fd/d0„Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Z d9d:„ Z!d;d<„ Z"e"Z#d=d>„ Z$d?d@„ Z%dAdB„ Z&dCdD„ Z'dEdF„ Z(dGdH„ Z)dIdJ„ Z*dKdL„ Z+dMdN„ Z,dOdP„ Z-dQdR„ Z.dSdT„ Z/dUdV„ Z0dWdX„ Z1dYdZ„ Z2d[d\„ Z3d]d^„ Z4d_d`„ Z5‡  Z6S )aÚJuliaCodePrinterzD
    A printer to convert expressions to strings of Julia code.
    Z_juliaÚJuliaz&&z||ú!)ÚandÚorÚnoté   T)Ú	precisionÚuser_functionsÚcontractÚinlinezdict[str, Any]Ú_default_settingsc                   sH   t ƒ  |¡ ttttƒƒ| _| j ttƒ¡ | di ¡}| j |¡ d S )Nr8   )	ÚsuperÚ__init__ÚdictÚzipÚknown_fcns_src1Zknown_functionsÚupdateÚknown_fcns_src2Úget)ÚselfÚsettingsZ	userfuncs©Ú	__class__© úS/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/printing/julia.pyr=   G   s
    zJuliaCodePrinter.__init__c                 C  s   |d S )Né   rH   )rD   ÚprH   rH   rI   Ú_rate_index_positionO   s    z%JuliaCodePrinter._rate_index_positionc                 C  s   d| S )Nz%srH   )rD   Z
codestringrH   rH   rI   Ú_get_statementS   s    zJuliaCodePrinter._get_statementc                 C  s
   d  |¡S )Nz# {}©Úformat)rD   ÚtextrH   rH   rI   Ú_get_commentW   s    zJuliaCodePrinter._get_commentc                 C  s   d  ||¡S )Nzconst {} = {}rN   )rD   ÚnameÚvaluerH   rH   rI   Ú_declare_number_const[   s    z&JuliaCodePrinter._declare_number_constc                 C  s
   |   |¡S ©N)Úindent_code)rD   ÚlinesrH   rH   rI   Ú_format_code_   s    zJuliaCodePrinter._format_codec                   s    |j \‰ }‡ fdd„t|ƒD ƒS )Nc                 3  s$   | ]}t ˆ ƒD ]}||fV  qqd S rU   )Úrange)Ú.0ÚjÚi©ÚrowsrH   rI   Ú	<genexpr>f   s     
  z<JuliaCodePrinter._traverse_matrix_indices.<locals>.<genexpr>)ÚshaperY   )rD   ZmatÚcolsrH   r]   rI   Ú_traverse_matrix_indicesc   s    
z)JuliaCodePrinter._traverse_matrix_indicesc                 C  s^   g }g }|D ]H}t | j|j|jd |jd gƒ\}}}| d|||f ¡ | d¡ q||fS )Né   zfor %s = %s:%sÚend)ÚmapÚ_printÚlabelÚlowerÚupperÚappend)rD   ÚindicesZ
open_linesZclose_linesr\   ÚvarÚstartÚstoprH   rH   rI   Ú_get_loop_opening_endingi   s    ÿ
z)JuliaCodePrinter._get_loop_opening_endingc                   sh  |j r0|jr0| ¡ d jr0dˆ tj | ¡ S t|ƒ‰ | ¡ \}}|dk r^t| |ƒ}d}nd}g }g }g }ˆj	dkr‚| 
¡ }n
t |¡}|D ]Ð}	|	j�r$|	j�r$|	jj�r$|	jj�r$|	jdkrÞ| t|	j|	j dd�¡ nDt|	jd jƒd	k�rt|	jtƒ�r| |	¡ | t|	j|	j ƒ¡ q�|	j�rV|	tjk	�rV|	jd	k�rV| t|	jƒ¡ q�| |	¡ q�|�pntjg}‡ ‡fd
d„|D ƒ}
‡ ‡fdd„|D ƒ}|D ]2}	|	j|k�rœd|| |	j¡  || |	j¡< �qœdd„ }|�sì||||
ƒ S t|ƒd	k�r*|d j �r
dnd}d||||
ƒ ||d f S tdd„ |D ƒƒ�rBdnd}d||||
ƒ ||||ƒf S d S )Nr   z%simú-Ú )ÚoldÚnoneéÿÿÿÿF)Úevaluaterc   c                   s   g | ]}ˆ  |ˆ ¡‘qS rH   ©Úparenthesize©rZ   Úx©ÚprecrD   rH   rI   Ú
<listcomp>¥   s     z/JuliaCodePrinter._print_Mul.<locals>.<listcomp>c                   s   g | ]}ˆ  |ˆ ¡‘qS rH   rv   rx   rz   rH   rI   r|   ¦   s     ú(%s)c                 S  sH   |d }t dt| ƒƒD ],}| |d  jr,dnd}d|||| f }q|S )Nr   rc   Ú*z.*ú%s %s %s)rY   ÚlenÚ	is_number)ÚaÚa_strÚrr\   ZmulsymrH   rH   rI   Úmultjoin®   s
    z-JuliaCodePrinter._print_Mul.<locals>.multjoinú/ú./r   c                 s  s   | ]}|j V  qd S rU   ©r�   )rZ   ZbirH   rH   rI   r_   ¼   s     z.JuliaCodePrinter._print_Mul.<locals>.<genexpr>z
%s %s (%s))r�   Zis_imaginaryZas_coeff_MulÚ
is_integerrf   r   ZImaginaryUnitr   r   ÚorderZas_ordered_factorsr   Z	make_argsÚis_commutativeZis_Powr    Zis_RationalÚis_negativerj   r   Úbaser€   ÚargsÚ
isinstanceÚInfinityrK   r   ÚqZOneÚindexÚall)rD   ÚexprÚcÚer   r‚   ÚbZ	pow_parenrŽ   Úitemrƒ   Zb_strr…   ZdivsymrH   rz   rI   Ú
_print_Mulu   sT    ÿ


ÿ
$
 $zJuliaCodePrinter._print_Mulc                 C  s,   |   |j¡}|   |j¡}|j}d |||¡S )Nz{} {} {})rf   ÚlhsÚrhsZrel_oprO   )rD   r”   Úlhs_codeÚrhs_codeÚoprH   rH   rI   Ú_print_Relational¿   s    z"JuliaCodePrinter._print_Relationalc                 C  sÊ   t dd„ |jD ƒƒrdnd}t|ƒ}t|jdƒr@d|  |j¡ S |jr¨t|jdƒrv|jjr^dnd	}d
||  |j¡f S t|jdƒr¨|jjrŽdnd	}d||  	|j|¡f S d|  	|j|¡||  	|j|¡f S )Nc                 s  s   | ]}|j V  qd S rU   rˆ   rx   rH   rH   rI   r_   Æ   s     z.JuliaCodePrinter._print_Pow.<locals>.<genexpr>ú^z.^g      à?zsqrt(%s)g      à¿r†   r‡   z1 %s sqrt(%s)rt   z1 %s %sr   )
r“   rŽ   r   r	   r    rf   r�   r‹   r�   rw   )rD   r”   Z	powsymbolÚPRECÚsymrH   rH   rI   Ú
_print_PowÅ   s    ÿzJuliaCodePrinter._print_Powc                 C  s(   t |ƒ}d|  |j|¡|  |j|¡f S )Nz%s ^ %s)r   rw   r�   r    ©rD   r”   r¡   rH   rH   rI   Ú_print_MatPowÙ   s    ÿzJuliaCodePrinter._print_MatPowc                   s   | j d rdS tƒ  |¡S d S )Nr:   Úpi©Ú	_settingsr<   Z_print_NumberSymbol©rD   r”   rF   rH   rI   Ú	_print_Piß   s    
zJuliaCodePrinter._print_Pic                 C  s   dS )Nr.   rH   r©   rH   rH   rI   Ú_print_ImaginaryUnitæ   s    z%JuliaCodePrinter._print_ImaginaryUnitc                   s   | j d rdS tƒ  |¡S d S )Nr:   r–   r§   r©   rF   rH   rI   Ú_print_Exp1ê   s    
zJuliaCodePrinter._print_Exp1c                   s   | j d rdS tƒ  |¡S d S )Nr:   Z
eulergammar§   r©   rF   rH   rI   Ú_print_EulerGammañ   s    
z"JuliaCodePrinter._print_EulerGammac                   s   | j d rdS tƒ  |¡S d S )Nr:   Úcatalanr§   r©   rF   rH   rI   Ú_print_Catalanø   s    
zJuliaCodePrinter._print_Catalanc                   s   | j d rdS tƒ  |¡S d S )Nr:   Zgoldenr§   r©   rF   rH   rI   Ú_print_GoldenRatioÿ   s    
z#JuliaCodePrinter._print_GoldenRatioc                 C  sä   ddl m} ddlm} ddlm} |j}|j}| jd s�t	|j|ƒr�g }g }|j
D ]"\}	}
| |||	ƒ¡ | |
¡ qT|t||ƒŽ }|  |¡S | jd rº| |¡s®| |¡rº|  ||¡S |  |¡}|  |¡}|  d||f ¡S d S )Nr   )Ú
Assignment)Ú	Piecewise)ÚIndexedBaser:   r9   z%s = %s)Zsympy.codegen.astr±   Z$sympy.functions.elementary.piecewiser²   Zsympy.tensor.indexedr³   rš   r›   r¨   r�   rŽ   rj   r?   rf   ÚhasZ_doprint_loopsrM   )rD   r”   r±   r²   r³   rš   r›   ZexpressionsÚ
conditionsr–   r•   Útemprœ   r�   rH   rH   rI   Ú_print_Assignment  s(    
ÿ

z"JuliaCodePrinter._print_Assignmentc                 C  s   dS )NZInfrH   r©   rH   rH   rI   Ú_print_Infinity#  s    z JuliaCodePrinter._print_Infinityc                 C  s   dS )Nz-InfrH   r©   rH   rH   rI   Ú_print_NegativeInfinity'  s    z(JuliaCodePrinter._print_NegativeInfinityc                 C  s   dS )NÚNaNrH   r©   rH   rH   rI   Ú
_print_NaN+  s    zJuliaCodePrinter._print_NaNc                   s    dd  ‡ fdd„|D ƒ¡ d S )NzAny[ú, c                 3  s   | ]}ˆ   |¡V  qd S rU   ©rf   ©rZ   r‚   ©rD   rH   rI   r_   0  s     z/JuliaCodePrinter._print_list.<locals>.<genexpr>ú])Újoinr©   rH   r¿   rI   Ú_print_list/  s    zJuliaCodePrinter._print_listc                 C  s2   t |ƒdkrd|  |d ¡ S d|  |d¡ S d S )Nrc   z(%s,)r   r}   r¼   )r€   rf   Ú	stringifyr©   rH   rH   rI   Ú_print_tuple3  s    zJuliaCodePrinter._print_tuplec                 C  s   dS )NÚtruerH   r©   rH   rH   rI   Ú_print_BooleanTrue;  s    z#JuliaCodePrinter._print_BooleanTruec                 C  s   dS )NÚfalserH   r©   rH   rH   rI   Ú_print_BooleanFalse?  s    z$JuliaCodePrinter._print_BooleanFalsec                 C  s   t |ƒ ¡ S rU   )Ústrrh   r©   rH   rH   rI   Ú_print_boolC  s    zJuliaCodePrinter._print_boolc                   s–   t j|jkrd|j|jf S |j|jfdkr8d|d  S |jdkrXd|jˆ dddd� S |jdkr~dd	 ‡ fd
d„|D ƒ¡ S d|jˆ ddddd� S )Nzzeros(%s, %s))rc   rc   z[%s])r   r   rc   rq   ú )ÚrowstartÚrowendÚcolsepr¼   c                   s   g | ]}ˆ   |¡‘qS rH   r½   r¾   r¿   rH   rI   r|   U  s     z6JuliaCodePrinter._print_MatrixBase.<locals>.<listcomp>z;
)rÌ   rÍ   ZrowseprÎ   )r   ZZeror`   r^   ra   ÚtablerÁ   )rD   ÚArH   r¿   rI   Ú_print_MatrixBaseK  s    

 ÿz"JuliaCodePrinter._print_MatrixBasec                 C  sr   ddl m} | ¡ }|dd„ |D ƒƒ}|dd„ |D ƒƒ}|dd„ |D ƒƒ}d|  |¡|  |¡|  |¡|j|jf S )Nr   )ÚMatrixc                 S  s   g | ]}|d  d ‘qS )r   rc   rH   ©rZ   ÚkrH   rH   rI   r|   ^  s     z;JuliaCodePrinter._print_SparseRepMatrix.<locals>.<listcomp>c                 S  s   g | ]}|d  d  ‘qS )rc   rH   rÓ   rH   rH   rI   r|   _  s     c                 S  s   g | ]}|d  ‘qS )é   rH   rÓ   rH   rH   rI   r|   `  s     zsparse(%s, %s, %s, %s, %s))Zsympy.matricesrÒ   Zcol_listrf   r^   ra   )rD   rÐ   rÒ   ÚLÚIÚJZAIJrH   rH   rI   Ú_print_SparseRepMatrixZ  s      ÿz'JuliaCodePrinter._print_SparseRepMatrixc                 C  s.   | j |jtd dd�d|jd |jd f  S )NZAtomT)Ústrictz[%s,%s]rc   )rw   Úparentr   r\   r[   r©   rH   rH   rI   Ú_print_MatrixElemente  s    ÿz%JuliaCodePrinter._print_MatrixElementc                   sL   ‡ fdd„}ˆ   |j¡d ||j|jjd ƒ d ||j|jjd ƒ d S )Nc                   sŒ   | d d }| d }| d }ˆ   |¡}||kr2dnˆ   |¡}|dkrr|dkrX||krXdS ||krd|S |d | S nd |ˆ   |¡|f¡S d S )Nr   rc   rÕ   rd   ú:)rf   rÁ   )ry   ZlimÚlÚhÚstepZlstrZhstrr¿   rH   rI   Ústrslicek  s    
z5JuliaCodePrinter._print_MatrixSlice.<locals>.strsliceú[r   ú,rc   rÀ   )rf   rÛ   Zrowslicer`   Zcolslice)rD   r”   rá   rH   r¿   rI   Ú_print_MatrixSlicej  s    ÿÿþþz#JuliaCodePrinter._print_MatrixSlicec                   s0   ‡ fdd„|j D ƒ}dˆ  |jj¡d |¡f S )Nc                   s   g | ]}ˆ   |¡‘qS rH   r½   )rZ   r\   r¿   rH   rI   r|   €  s     z3JuliaCodePrinter._print_Indexed.<locals>.<listcomp>z%s[%s]rã   )rk   rf   r�   rg   rÁ   )rD   r”   ZindsrH   r¿   rI   Ú_print_Indexed  s    zJuliaCodePrinter._print_Indexedc                 C  s   |   |j¡S rU   )rf   rg   r©   rH   rH   rI   Ú
_print_Idx„  s    zJuliaCodePrinter._print_Idxc                 C  s   d|   |jd ¡ S )Nzeye(%s)r   )rf   r`   r©   rH   rH   rI   Ú_print_Identityˆ  s    z JuliaCodePrinter._print_Identityc                   s   d  ‡ ‡fdd„ˆ jD ƒ¡S )Nz .* c                   s   g | ]}ˆ  |tˆ ƒ¡‘qS rH   ©rw   r   ©rZ   Úarg©r”   rD   rH   rI   r|   Œ  s   ÿz;JuliaCodePrinter._print_HadamardProduct.<locals>.<listcomp>)rÁ   rŽ   r©   rH   rë   rI   Ú_print_HadamardProduct‹  s    ÿz'JuliaCodePrinter._print_HadamardProductc                 C  s*   t |ƒ}d |  |j|¡|  |j|¡g¡S )Nz.**)r   rÁ   rw   r�   r    r¤   rH   rH   rI   Ú_print_HadamardPower�  s
    þz%JuliaCodePrinter._print_HadamardPowerc                 C  s$   |j dkrt|jƒS d|j|j f S )Nrc   z%s // %s)r‘   rÉ   rK   r©   rH   rH   rI   Ú_print_Rational–  s    

z JuliaCodePrinter._print_Rationalc                 C  sD   ddl m}m} |j}|tjd|  ƒ||jtj |ƒ }|  |¡S )Nr   )r!   r'   rÕ   )	Úsympy.functionsr!   r'   Úargumentr   ÚPirŠ   ÚHalfrf   )rD   r”   r!   r'   ry   Úexpr2rH   rH   rI   Ú	_print_jnœ  s    $zJuliaCodePrinter._print_jnc                 C  sD   ddl m}m} |j}|tjd|  ƒ||jtj |ƒ }|  |¡S )Nr   )r!   r(   rÕ   )	rï   r!   r(   rð   r   rñ   rŠ   rò   rf   )rD   r”   r!   r(   ry   ró   rH   rH   rI   Ú	_print_yn£  s    $zJuliaCodePrinter._print_ync           
        s   |j d jdkrtdƒ‚g }ˆ jd rr‡ fdd„|j d d… D ƒ}dˆ  |j d j¡ }d |¡| }d	| d
 S t|j ƒD ]”\}\}}|dkr¦| dˆ  |¡ ¡ n:|t	|j ƒd krÌ|dkrÌ| d¡ n| dˆ  |¡ ¡ ˆ  |¡}	| |	¡ |t	|j ƒd kr|| d¡ q|d |¡S d S )Nrt   Tz¼All 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:   c                   s(   g | ] \}}d   ˆ  |¡ˆ  |¡¡‘qS )z({}) ? ({}) :)rO   rf   )rZ   r–   r•   r¿   rH   rI   r|   ¸  s
   þ ÿz5JuliaCodePrinter._print_Piecewise.<locals>.<listcomp>z (%s)Ú
ú(ú)r   zif (%s)rc   Úelsezelseif (%s)rd   )
rŽ   ZcondÚ
ValueErrorr¨   rf   r”   rÁ   Ú	enumeraterj   r€   )
rD   r”   rW   ZecpairsZelastÚpwr\   r–   r•   Zcode0rH   r¿   rI   Ú_print_Piecewiseª  s*    

þ

z!JuliaCodePrinter._print_Piecewisec                   s|   ˆ   ¡ \}}d}|jr\| ¡ \}}|jr@|jr@t| |ƒ‰ d}n|jr\|jr\t| |ƒ‰ d}|d ‡ ‡fdd„ˆ jD ƒ¡ S )Nrq   rp   z * c                 3  s   | ]}ˆ  |tˆ ƒ¡V  qd S rU   rè   ré   rë   rH   rI   r_   Ü  s     z1JuliaCodePrinter._print_MatMul.<locals>.<genexpr>)Zas_coeff_mmulr�   Zas_real_imagÚis_zerorŒ   r   rÁ   rŽ   )rD   r”   r•   Úmr   r/   r.   rH   rë   rI   Ú_print_MatMulÎ  s    ÿzJuliaCodePrinter._print_MatMulc           
        sÂ   t |tƒr$|  | d¡¡}d |¡S d}d‰d‰ dd„ |D ƒ}‡fdd„|D ƒ}‡ fd	d„|D ƒ}g }d
}t|ƒD ]J\}}	|	dkrŽ| |	¡ qr||| 8 }| d|| |	f ¡ ||| 7 }qr|S )z0Accepts a string of code or a list of code linesTrq   z    )z
^function z^if ú^elseif ú^else$z^for )z^end$r  r  c                 S  s   g | ]}|  d ¡‘qS )z 	)Úlstrip)rZ   ÚlinerH   rH   rI   r|   í  s     z0JuliaCodePrinter.indent_code.<locals>.<listcomp>c                   s&   g | ]‰ t t‡ fd d„ˆD ƒƒƒ‘qS )c                 3  s   | ]}t |ˆ ƒV  qd S rU   r   ©rZ   r/   ©r  rH   rI   r_   ï  s     ú:JuliaCodePrinter.indent_code.<locals>.<listcomp>.<genexpr>©ÚintÚany©rZ   )Ú	inc_regexr  rI   r|   ï  s   ÿc                   s&   g | ]‰ t t‡ fd d„ˆD ƒƒƒ‘qS )c                 3  s   | ]}t |ˆ ƒV  qd S rU   r   r  r  rH   rI   r_   ñ  s     r  r  r  )Ú	dec_regexr  rI   r|   ñ  s   ÿr   )rq   rö   z%s%s)r�   rÉ   rV   Ú
splitlinesrÁ   rû   rj   )
rD   ÚcodeZ
code_linesÚtabZincreaseZdecreaseÚprettyÚlevelÚnr  rH   )r  r  rI   rV   à  s.    


ÿ
ÿ
zJuliaCodePrinter.indent_code)7Ú__name__Ú
__module__Ú__qualname__Ú__doc__ZprintmethodÚlanguageÚ
_operatorsr>   r
   r;   Ú__annotations__r=   rL   rM   rQ   rT   rX   rb   ro   r™   rŸ   r£   r¥   rª   r«   r¬   r­   r¯   r°   r·   r¸   r¹   r»   rÂ   rÄ   Z_print_TuplerÆ   rÈ   rÊ   rÑ   rÙ   rÜ   rä   rå   ræ   rç   rì   rí   rî   rô   rõ   rý   r   rV   Ú__classcell__rH   rH   rF   rI   r0   0   sp   
ýü
J$r0   Nc                 K  s   t |ƒ | |¡S )a)  Converts `expr` to a string of Julia code.

    Parameters
    ==========

    expr : Expr
        A SymPy expression to be converted.
    assign_to : optional
        When given, the argument is used as the name of the variable to which
        the expression is assigned.  Can be a string, ``Symbol``,
        ``MatrixSymbol``, or ``Indexed`` type.  This can be helpful for
        expressions that generate multi-line statements.
    precision : integer, optional
        The precision for numbers such as pi  [default=16].
    user_functions : dict, optional
        A dictionary where keys are ``FunctionClass`` instances and values are
        their string representations.  Alternatively, the dictionary value can
        be a list of tuples i.e. [(argument_test, cfunction_string)].  See
        below for examples.
    human : bool, optional
        If True, the result is a single string that may contain some constant
        declarations for the number symbols.  If False, the same information is
        returned in a tuple of (symbols_to_declare, not_supported_functions,
        code_text).  [default=True].
    contract: bool, optional
        If True, ``Indexed`` instances are assumed to obey tensor contraction
        rules and the corresponding nested loops over indices are generated.
        Setting contract=False will not generate loops, instead the user is
        responsible to provide values for the indices in the code.
        [default=True].
    inline: bool, optional
        If True, we try to create single-statement code instead of multiple
        statements.  [default=True].

    Examples
    ========

    >>> from sympy import julia_code, symbols, sin, pi
    >>> x = symbols('x')
    >>> julia_code(sin(x).series(x).removeO())
    'x .^ 5 / 120 - x .^ 3 / 6 + x'

    >>> from sympy import Rational, ceiling
    >>> x, y, tau = symbols("x, y, tau")
    >>> julia_code((2*tau)**Rational(7, 2))
    '8 * sqrt(2) * tau .^ (7 // 2)'

    Note that element-wise (Hadamard) operations are used by default between
    symbols.  This is because its possible in Julia to write "vectorized"
    code.  It is harmless if the values are scalars.

    >>> julia_code(sin(pi*x*y), assign_to="s")
    's = sin(pi * x .* y)'

    If you need a matrix product "*" or matrix power "^", you can specify the
    symbol as a ``MatrixSymbol``.

    >>> from sympy import Symbol, MatrixSymbol
    >>> n = Symbol('n', integer=True, positive=True)
    >>> A = MatrixSymbol('A', n, n)
    >>> julia_code(3*pi*A**3)
    '(3 * pi) * A ^ 3'

    This class uses several rules to decide which symbol to use a product.
    Pure numbers use "*", Symbols use ".*" and MatrixSymbols use "*".
    A HadamardProduct can be used to specify componentwise multiplication ".*"
    of two MatrixSymbols.  There is currently there is no easy way to specify
    scalar symbols, so sometimes the code might have some minor cosmetic
    issues.  For example, suppose x and y are scalars and A is a Matrix, then
    while a human programmer might write "(x^2*y)*A^3", we generate:

    >>> julia_code(x**2*y*A**3)
    '(x .^ 2 .* y) * A ^ 3'

    Matrices are supported using Julia inline notation.  When using
    ``assign_to`` with matrices, the name can be specified either as a string
    or as a ``MatrixSymbol``.  The dimensions must align in the latter case.

    >>> from sympy import Matrix, MatrixSymbol
    >>> mat = Matrix([[x**2, sin(x), ceiling(x)]])
    >>> julia_code(mat, assign_to='A')
    'A = [x .^ 2 sin(x) ceil(x)]'

    ``Piecewise`` expressions are implemented with logical masking by default.
    Alternatively, you can pass "inline=False" to use if-else conditionals.
    Note that if the ``Piecewise`` lacks a default term, represented by
    ``(expr, True)`` then an error will be thrown.  This is to prevent
    generating an expression that may not evaluate to anything.

    >>> from sympy import Piecewise
    >>> pw = Piecewise((x + 1, x > 0), (x, True))
    >>> julia_code(pw, assign_to=tau)
    'tau = ((x > 0) ? (x + 1) : (x))'

    Note that any expression that can be generated normally can also exist
    inside a Matrix:

    >>> mat = Matrix([[x**2, pw, sin(x)]])
    >>> julia_code(mat, assign_to='A')
    'A = [x .^ 2 ((x > 0) ? (x + 1) : (x)) sin(x)]'

    Custom printing can be defined for certain types by passing a dictionary of
    "type" : "function" to the ``user_functions`` kwarg.  Alternatively, the
    dictionary value can be a list of tuples i.e., [(argument_test,
    cfunction_string)].  This can be used to call a custom Julia function.

    >>> from sympy import Function
    >>> f = Function('f')
    >>> g = Function('g')
    >>> custom_functions = {
    ...   "f": "existing_julia_fcn",
    ...   "g": [(lambda x: x.is_Matrix, "my_mat_fcn"),
    ...         (lambda x: not x.is_Matrix, "my_fcn")]
    ... }
    >>> mat = Matrix([[1, x]])
    >>> julia_code(f(x) + g(x) + g(mat), user_functions=custom_functions)
    'existing_julia_fcn(x) + my_fcn(x) + my_mat_fcn([1 x])'

    Support for loops is provided through ``Indexed`` types. With
    ``contract=True`` these expressions will be turned into loops, whereas
    ``contract=False`` will just print the assignment expression that should be
    looped over:

    >>> from sympy import Eq, IndexedBase, Idx
    >>> len_y = 5
    >>> y = IndexedBase('y', shape=(len_y,))
    >>> t = IndexedBase('t', shape=(len_y,))
    >>> Dy = IndexedBase('Dy', shape=(len_y-1,))
    >>> i = Idx('i', len_y-1)
    >>> e = Eq(Dy[i], (y[i+1]-y[i])/(t[i+1]-t[i]))
    >>> julia_code(e.rhs, assign_to=e.lhs, contract=False)
    'Dy[i] = (y[i + 1] - y[i]) ./ (t[i + 1] - t[i])'
    )r0   Zdoprint)r”   Z	assign_torE   rH   rH   rI   Ú
julia_code   s     r  c                 K  s   t t| f|Žƒ dS )z~Prints the Julia representation of the given expression.

    See `julia_code` for the meaning of the optional arguments.
    N)Úprintr  )r”   rE   rH   rH   rI   Úprint_julia_code‰  s    r  )N)r  Ú
__future__r   Útypingr   Z
sympy.corer   r   r   r   Zsympy.core.mulr   Zsympy.core.numbersr	   Zsympy.printing.codeprinterr
   Zsympy.printing.precedencer   r   r/   r   r@   rB   r0   r  r  rH   rH   rH   rI   Ú<module>   sŒ                                      öù   S
 
