U
     ‹Ñh³[  ã                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_juliaZJuliaz&&z||ú!)ÚandÚorÚnoté   T)Z	precisionÚuser_functionsÚcontractÚinlinezdict[str, Any]Ú_default_settingsc                   sH   t ƒ  |¡ ttttƒƒ| _| j ttƒ¡ | di ¡}| j |¡ d S )Nr6   )	ÚsuperÚ__init__ÚdictÚzipÚknown_fcns_src1Zknown_functionsÚupdateÚknown_fcns_src2Úget)ÚselfÚsettingsZ	userfuncs©Ú	__class__© úB/tmp/user/2202/pip-unpacked-wheel-qe3242ng/sympy/printing/julia.pyr;   G   s
    zJuliaCodePrinter.__init__c                 C  s   |d S )Né   rF   )rB   ÚprF   rF   rG   Ú_rate_index_positionO   s    z%JuliaCodePrinter._rate_index_positionc                 C  s   d| S )Nz%srF   )rB   Z
codestringrF   rF   rG   Ú_get_statementS   s    zJuliaCodePrinter._get_statementc                 C  s
   d  |¡S )Nz# {}©Úformat)rB   ÚtextrF   rF   rG   Ú_get_commentW   s    zJuliaCodePrinter._get_commentc                 C  s   d  ||¡S )Nzconst {} = {}rL   )rB   ÚnameÚvaluerF   rF   rG   Ú_declare_number_const[   s    z&JuliaCodePrinter._declare_number_constc                 C  s
   |   |¡S ©N)Úindent_code)rB   ÚlinesrF   rF   rG   Ú_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 rS   )Úrange)Ú.0ÚjÚi©ÚrowsrF   rG   Ú	<genexpr>f   s     
  z<JuliaCodePrinter._traverse_matrix_indices.<locals>.<genexpr>)ÚshaperW   )rB   ÚmatÚcolsrF   r[   rG   Ú_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)rB   ÚindicesZ
open_linesZclose_linesrZ   ÚvarÚstartÚstoprF   rF   rG   Ú_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)Úevaluaterb   c                   s   g | ]}ˆ  |ˆ ¡‘qS rF   ©Úparenthesize©rX   Úx©ÚprecrB   rF   rG   Ú
<listcomp>¥   s     z/JuliaCodePrinter._print_Mul.<locals>.<listcomp>c                   s   g | ]}ˆ  |ˆ ¡‘qS rF   ru   rw   ry   rF   rG   r{   ¦   s     ú(%s)c                 S  sH   |d }t dt| ƒƒD ],}| |d  jr,dnd}d|||| f }q|S )Nr   rb   Ú*z.*ú%s %s %s)rW   ÚlenÚ	is_number)ÚaÚa_strÚrrZ   ZmulsymrF   rF   rG   Úmultjoin®   s
    z-JuliaCodePrinter._print_Mul.<locals>.multjoinú/ú./r~   c                 s  s   | ]}|j V  qd S rS   ©r€   )rX   ZbirF   rF   rG   r]   ¼   s     z.JuliaCodePrinter._print_Mul.<locals>.<genexpr>z
%s %s (%s))r€   Zis_imaginaryZas_coeff_MulÚ
is_integerre   r   ZImaginaryUnitr   r   ÚorderZas_ordered_factorsr   Z	make_argsÚis_commutativeZis_Powr    Zis_RationalÚis_negativeri   r   Úbaser   ÚargsÚ
isinstanceÚInfinityrI   r   ÚqZOneÚindexÚall)rB   ÚexprÚcÚer   r�   ÚbZ	pow_parenr�   Úitemr‚   Zb_strr„   ZdivsymrF   ry   rG   Ú
_print_Mulu   sT    ÿ


ÿ
$
 $zJuliaCodePrinter._print_Mulc                 C  s,   |   |j¡}|   |j¡}|j}d |||¡S )Nz{} {} {})re   ÚlhsÚrhsZrel_oprM   )rB   r“   Úlhs_codeÚrhs_codeÚoprF   rF   rG   Ú_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 rS   r‡   rw   rF   rF   rG   r]   Æ   s     z.JuliaCodePrinter._print_Pow.<locals>.<genexpr>ú^z.^g      à?zsqrt(%s)g      à¿r…   r†   z1 %s sqrt(%s)rs   z1 %s %sr~   )
r’   r�   r   r	   r    re   rŒ   rŠ   r€   rv   )rB   r“   Z	powsymbolÚPRECÚsymrF   rF   rG   Ú
_print_PowÅ   s    ÿzJuliaCodePrinter._print_Powc                 C  s(   t |ƒ}d|  |j|¡|  |j|¡f S )Nz%s ^ %s)r   rv   rŒ   r    ©rB   r“   r    rF   rF   rG   Ú_print_MatPowÙ   s    ÿzJuliaCodePrinter._print_MatPowc                   s   | j d rdS tƒ  |¡S d S )Nr8   Úpi©Ú	_settingsr:   Z_print_NumberSymbol©rB   r“   rD   rF   rG   Ú	_print_Piß   s    
zJuliaCodePrinter._print_Pic                 C  s   dS )Nr.   rF   r¨   rF   rF   rG   Ú_print_ImaginaryUnitæ   s    z%JuliaCodePrinter._print_ImaginaryUnitc                   s   | j d rdS tƒ  |¡S d S )Nr8   r•   r¦   r¨   rD   rF   rG   Ú_print_Exp1ê   s    
zJuliaCodePrinter._print_Exp1c                   s   | j d rdS tƒ  |¡S d S )Nr8   Z
eulergammar¦   r¨   rD   rF   rG   Ú_print_EulerGammañ   s    
z"JuliaCodePrinter._print_EulerGammac                   s   | j d rdS tƒ  |¡S d S )Nr8   Úcatalanr¦   r¨   rD   rF   rG   Ú_print_Catalanø   s    
zJuliaCodePrinter._print_Catalanc                   s   | j d rdS tƒ  |¡S d S )Nr8   Zgoldenr¦   r¨   rD   rF   rG   Ú_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)ÚIndexedBaser8   r7   z%s = %s)Zsympy.codegen.astr°   Z$sympy.functions.elementary.piecewiser±   Zsympy.tensor.indexedr²   r™   rš   r§   rŽ   r�   ri   r=   re   ZhasZ_doprint_loopsrK   )rB   r“   r°   r±   r²   r™   rš   ZexpressionsZ
conditionsr•   r”   Útempr›   rœ   rF   rF   rG   Ú_print_Assignment  s(    
ÿ

z"JuliaCodePrinter._print_Assignmentc                 C  s   dS )NZInfrF   r¨   rF   rF   rG   Ú_print_Infinity#  s    z JuliaCodePrinter._print_Infinityc                 C  s   dS )Nz-InfrF   r¨   rF   rF   rG   Ú_print_NegativeInfinity'  s    z(JuliaCodePrinter._print_NegativeInfinityc                 C  s   dS )NÚNaNrF   r¨   rF   rF   rG   Ú
_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 rS   ©re   ©rX   r�   ©rB   rF   rG   r]   0  s     z/JuliaCodePrinter._print_list.<locals>.<genexpr>ú])Újoinr¨   rF   r¼   rG   Ú_print_list/  s    zJuliaCodePrinter._print_listc                 C  s2   t |ƒdkrd|  |d ¡ S d|  |d¡ S d S )Nrb   z(%s,)r   r|   r¹   )r   re   Z	stringifyr¨   rF   rF   rG   Ú_print_tuple3  s    zJuliaCodePrinter._print_tuplec                 C  s   dS )NÚtruerF   r¨   rF   rF   rG   Ú_print_BooleanTrue;  s    z#JuliaCodePrinter._print_BooleanTruec                 C  s   dS )NÚfalserF   r¨   rF   rF   rG   Ú_print_BooleanFalse?  s    z$JuliaCodePrinter._print_BooleanFalsec                 C  s   t |ƒ ¡ S rS   )Ústrrg   r¨   rF   rF   rG   Ú_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))rb   rb   z[%s])r   r   rb   rp   ú )ÚrowstartÚrowendÚcolsepr¹   c                   s   g | ]}ˆ   |¡‘qS rF   rº   r»   r¼   rF   rG   r{   U  s     z6JuliaCodePrinter._print_MatrixBase.<locals>.<listcomp>z;
)rÈ   rÉ   ZrowseprÊ   )r   ZZeror^   r\   r`   Útabler¾   )rB   ÚArF   r¼   rG   Ú_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   rb   rF   ©rX   ÚkrF   rF   rG   r{   ^  s     z;JuliaCodePrinter._print_SparseRepMatrix.<locals>.<listcomp>c                 S  s   g | ]}|d  d  ‘qS )rb   rF   rÏ   rF   rF   rG   r{   _  s     c                 S  s   g | ]}|d  ‘qS )é   rF   rÏ   rF   rF   rG   r{   `  s     zsparse(%s, %s, %s, %s, %s))Zsympy.matricesrÎ   Zcol_listre   r\   r`   )rB   rÌ   rÎ   ÚLÚIÚJZAIJrF   rF   rG   Ú_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]rb   )rv   Úparentr   rZ   rY   r¨   rF   rF   rG   Ú_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   rb   rÑ   rc   ú:)re   r¾   )rx   ZlimÚlÚhÚstepZlstrZhstrr¼   rF   rG   Ústrslicek  s    
z5JuliaCodePrinter._print_MatrixSlice.<locals>.strsliceú[r   ú,rb   r½   )re   r×   Zrowslicer^   Zcolslice)rB   r“   rÝ   rF   r¼   rG   Ú_print_MatrixSlicej  s    ÿÿþþz#JuliaCodePrinter._print_MatrixSlicec                   s0   ‡ fdd„|j D ƒ}dˆ  |jj¡d |¡f S )Nc                   s   g | ]}ˆ   |¡‘qS rF   rº   )rX   rZ   r¼   rF   rG   r{   €  s     z3JuliaCodePrinter._print_Indexed.<locals>.<listcomp>z%s[%s]rß   )rj   re   rŒ   rf   r¾   )rB   r“   ZindsrF   r¼   rG   Ú_print_Indexed  s    zJuliaCodePrinter._print_Indexedc                 C  s   |   |j¡S rS   )re   rf   r¨   rF   rF   rG   Ú
_print_Idx„  s    zJuliaCodePrinter._print_Idxc                 C  s   d|   |jd ¡ S )Nzeye(%s)r   )re   r^   r¨   rF   rF   rG   Ú_print_Identityˆ  s    z JuliaCodePrinter._print_Identityc                   s   d  ‡ ‡fdd„ˆ jD ƒ¡S )Nz .* c                   s   g | ]}ˆ  |tˆ ƒ¡‘qS rF   ©rv   r   ©rX   Úarg©r“   rB   rF   rG   r{   Œ  s   ÿz;JuliaCodePrinter._print_HadamardProduct.<locals>.<listcomp>)r¾   r�   r¨   rF   rç   rG   Ú_print_HadamardProduct‹  s    ÿz'JuliaCodePrinter._print_HadamardProductc                 C  s*   t |ƒ}d |  |j|¡|  |j|¡g¡S )Nz.**)r   r¾   rv   rŒ   r    r£   rF   rF   rG   Ú_print_HadamardPower�  s
    þz%JuliaCodePrinter._print_HadamardPowerc                 C  s$   |j dkrt|jƒS d|j|j f S )Nrb   z%s // %s)r�   rÅ   rI   r¨   rF   rF   rG   Ú_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‰   ÚHalfre   )rB   r“   r!   r'   rx   Úexpr2rF   rF   rG   Ú	_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î   re   )rB   r“   r!   r(   rx   rï   rF   rF   rG   Ú	_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 )Nrs   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.r8   c                   s(   g | ] \}}d   ˆ  |¡ˆ  |¡¡‘qS )z({}) ? ({}) :)rM   re   )rX   r•   r”   r¼   rF   rG   r{   ¸  s
   þ ÿz5JuliaCodePrinter._print_Piecewise.<locals>.<listcomp>z (%s)Ú
ú(ú)r   zif (%s)rb   Úelsezelseif (%s)rc   )
r�   ZcondÚ
ValueErrorr§   re   r“   r¾   Ú	enumerateri   r   )
rB   r“   rU   ZecpairsZelastÚpwrZ   r•   r”   Zcode0rF   r¼   rG   Ú_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 )Nrp   ro   z * c                 3  s   | ]}ˆ  |tˆ ƒ¡V  qd S rS   rä   rå   rç   rF   rG   r]   Ü  s     z1JuliaCodePrinter._print_MatMul.<locals>.<genexpr>)Zas_coeff_mmulr€   Zas_real_imagÚis_zeror‹   r   r¾   r�   )rB   r“   r”   Úmr   r/   r.   rF   rç   rG   Ú_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 linesTrp   z    )z
^function z^if ú^elseif ú^else$z^for )z^end$rý   rþ   c                 S  s   g | ]}|  d ¡‘qS )z 	)Úlstrip)rX   ÚlinerF   rF   rG   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 rS   r   ©rX   r/   ©r   rF   rG   r]   ï  s     ú:JuliaCodePrinter.indent_code.<locals>.<listcomp>.<genexpr>©ÚintÚany©rX   )Ú	inc_regexr  rG   r{   ï  s   ÿc                   s&   g | ]‰ t t‡ fd d„ˆD ƒƒƒ‘qS )c                 3  s   | ]}t |ˆ ƒV  qd S rS   r   r  r  rF   rG   r]   ñ  s     r  r  r  )Ú	dec_regexr  rG   r{   ñ  s   ÿr   )rp   rò   z%s%s)rŽ   rÅ   rT   Ú
splitlinesr¾   r÷   ri   )
rB   ÚcodeZ
code_linesÚtabZincreaseZdecreaseÚprettyÚlevelÚnr   rF   )r	  r  rG   rT   à  s.    


ÿ
ÿ
zJuliaCodePrinter.indent_code)7Ú__name__Ú
__module__Ú__qualname__Ú__doc__ZprintmethodÚlanguageÚ
_operatorsr<   r
   r9   Ú__annotations__r;   rJ   rK   rO   rR   rV   ra   rn   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ü   rT   Ú__classcell__rF   rF   rD   rG   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_torC   rF   rF   rG   Ú
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“   rC   rF   rF   rG   Ú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>   r@   r0   r  r  rF   rF   rF   rG   Ú<module>   sŒ                                      öù   S
 
