o
    ôjõ[  ã                   @  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 g d
¢ZddddddddœZG dd„ deƒZddd„Zdd„ ZdS )a  
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)2ÚsinÚcosÚtanÚcotÚsecÚcscÚasinÚacosÚatanÚacotÚasecÚacscÚsinhÚcoshÚtanhÚcothÚsechÚcschÚasinhÚacoshÚatanhÚacothÚasechÚacschÚatan2ÚsignÚfloorÚlogÚexpÚcbrtÚsqrtÚerfÚerfcÚerfiÚ	factorialÚgammaÚdigammaÚtrigammaÚ	polygammaÚbetaÚairyaiÚairyaiprimeÚairybiÚairybiprimeÚbesseljÚbesselyÚbesseliÚbesselkÚerfinvÚerfcinvÚabsÚceilÚconjZhankelh1Zhankelh2ÚimagÚreal)ÚAbsÚceilingÚ	conjugateÚhankel1Úhankel2ÚimÚrec                      s¾  e Zd ZU dZdZdZddddœZeej	fi 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 )NrU   )	ÚsuperÚ__init__ÚdictÚzipÚknown_fcns_src1Úknown_functionsÚupdateÚknown_fcns_src2Úget)ÚselfÚsettingsÚ	userfuncs©Ú	__class__© úe/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/sympy/printing/julia.pyrZ   G   s
   zJuliaCodePrinter.__init__c                 C  s   |d S )Né   rg   )rb   Úprg   rg   rh   Ú_rate_index_positionO   ó   z%JuliaCodePrinter._rate_index_positionc                 C  s   d| S )Nz%srg   )rb   Ú
codestringrg   rg   rh   Ú_get_statementS   rl   zJuliaCodePrinter._get_statementc                 C  s
   d  |¡S )Nz# {}©Úformat)rb   Útextrg   rg   rh   Ú_get_commentW   ó   
zJuliaCodePrinter._get_commentc                 C  s   d  ||¡S )Nzconst {} = {}ro   )rb   ÚnameÚvaluerg   rg   rh   Ú_declare_number_const[   ó   z&JuliaCodePrinter._declare_number_constc                 C  s
   |   |¡S ©N)Úindent_code)rb   Úlinesrg   rg   rh   Ú_format_code_   rs   zJuliaCodePrinter._format_codec                   s    |j \‰ }‡ fdd„t|ƒD ƒS )Nc                 3  s&   � | ]}t ˆ ƒD ]}||fV  qqd S rx   )Úrange)Ú.0ÚjÚi©Úrowsrg   rh   Ú	<genexpr>f   s   €$ z<JuliaCodePrinter._traverse_matrix_indices.<locals>.<genexpr>)Úshaper|   )rb   ÚmatÚcolsrg   r€   rh   Ú_traverse_matrix_indicesc   s   
z)JuliaCodePrinter._traverse_matrix_indicesc                 C  s^   g }g }|D ]$}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   ÚindicesÚ
open_linesÚclose_linesr   ÚvarÚstartÚstoprg   rg   rh   Ú_get_loop_opening_endingi   s   
ÿz)JuliaCodePrinter._get_loop_opening_endingc                   sH  |j r|jr| ¡ d jrdˆ tj | ¡ S t|ƒ‰ | ¡ \}}|dk r/t| |ƒ}d}nd}g }g }g }ˆj	dvrA| 
¡ }nt |¡}|D ]_}	|	jrŒ|	jrŒ|	jjrŒ|	jjrŒ|	jdkrk| t|	j|	j dd�¡ qHt|	jd jƒd	kr€t|	jtƒr€| |	¡ | t|	j|	j ƒ¡ qH|	jr¢|	tjur¢|	jd	kr¢| t|	jƒ¡ qH| |	¡ qH|p­tjg}‡ ‡fd
d„|D ƒ}
‡ ‡fdd„|D ƒ}|D ]}	|	j|v 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 ƒƒ�rdnd}d||||
ƒ ||||ƒf S )Nr   z%simú-Ú )ÚoldÚnoneéÿÿÿÿF)Úevaluater‡   c                   ó   g | ]}ˆ  |ˆ ¡‘qS rg   ©Úparenthesize©r}   Úx©Úprecrb   rg   rh   Ú
<listcomp>¥   ó    z/JuliaCodePrinter._print_Mul.<locals>.<listcomp>c                   rœ   rg   r�   rŸ   r¡   rg   rh   r£   ¦   r¤   ú(%s)c                 S  sH   |d }t dt| ƒƒD ]}| |d  jrdnd}d|||| f }q|S )Nr   r‡   Ú*z.*ú%s %s %s)r|   ÚlenÚ	is_number)ÚaÚa_strÚrr   Zmulsymrg   rg   rh   Úmultjoin®   s
   z-JuliaCodePrinter._print_Mul.<locals>.multjoinú/ú./r§   c                 s  ó   � | ]}|j V  qd S rx   ©r©   )r}   Úbirg   rg   rh   r‚   ¼   ó   € z.JuliaCodePrinter._print_Mul.<locals>.<genexpr>z
%s %s (%s))r©   Úis_imaginaryÚas_coeff_MulÚ
is_integerrŠ   r   ÚImaginaryUnitr   r   ÚorderÚas_ordered_factorsr   Ú	make_argsÚis_commutativeÚis_Powr+   Úis_RationalÚis_negativerŽ   r   Úbaser¨   ÚargsÚ
isinstanceÚInfinityrj   r   ÚqÚOneÚindexÚall)rb   ÚexprÚcÚer(   rª   ÚbÚ	pow_parenrÀ   Úitemr«   Úb_strr­   Zdivsymrg   r¡   rh   Ú
_print_Mulu   sV   ÿ


ÿ
 

 €zJuliaCodePrinter._print_Mulc                 C  s,   |   |j¡}|   |j¡}|j}d |||¡S )Nz{} {} {})rŠ   ÚlhsÚrhsÚrel_oprp   )rb   rÇ   Úlhs_codeÚrhs_codeÚoprg   rg   rh   Ú_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rTt|jdƒr;|jjr/dnd	}d
||  |j¡f S t|jdƒrT|jjrGdnd	}d||  	|j|¡f S d|  	|j|¡||  	|j|¡f S )Nc                 s  r°   rx   r±   rŸ   rg   rg   rh   r‚   Æ   r³   z.JuliaCodePrinter._print_Pow.<locals>.<genexpr>ú^z.^g      à?zsqrt(%s)g      à¿r®   r¯   z1 %s sqrt(%s)rš   z1 %s %sr§   )
rÆ   rÀ   r   r	   r+   rŠ   r¿   r»   r©   rž   )rb   rÇ   Z	powsymbolÚPRECÚsymrg   rg   rh   Ú
_print_PowÅ   s   ÿzJuliaCodePrinter._print_Powc                 C  s(   t |ƒ}d|  |j|¡|  |j|¡f S )Nz%s ^ %s)r   rž   r¿   r+   ©rb   rÇ   r×   rg   rg   rh   Ú_print_MatPowÙ   s   ÿzJuliaCodePrinter._print_MatPowc                   ó   | j d rdS tƒ  |¡S )NrW   Úpi©Ú	_settingsrY   Ú_print_NumberSymbol©rb   rÇ   re   rg   rh   Ú	_print_Piß   ó   
zJuliaCodePrinter._print_Pic                 C  ó   dS )NrK   rg   rá   rg   rg   rh   Ú_print_ImaginaryUnitæ   ó   z%JuliaCodePrinter._print_ImaginaryUnitc                   rÜ   )NrW   rÉ   rÞ   rá   re   rg   rh   Ú_print_Exp1ê   rã   zJuliaCodePrinter._print_Exp1c                   rÜ   )NrW   Ú
eulergammarÞ   rá   re   rg   rh   Ú_print_EulerGammañ   rã   z"JuliaCodePrinter._print_EulerGammac                   rÜ   )NrW   ÚcatalanrÞ   rá   re   rg   rh   Ú_print_Catalanø   rã   zJuliaCodePrinter._print_Catalanc                   rÜ   )NrW   ZgoldenrÞ   rá   re   rg   rh   Ú_print_GoldenRatioÿ   rã   z#JuliaCodePrinter._print_GoldenRatioc                 C  sà   ddl m} ddlm} ddlm} |j}|j}| jd sHt	|j|ƒrHg }g }|j
D ]\}	}
| |||	ƒ¡ | |
¡ q*|t||ƒŽ }|  |¡S | jd r]| |¡sW| |¡r]|  ||¡S |  |¡}|  |¡}|  d||f ¡S )Nr   )Ú
Assignment)Ú	Piecewise)ÚIndexedBaserW   rV   z%s = %s)Úsympy.codegen.astrí   Ú$sympy.functions.elementary.piecewiserî   Úsympy.tensor.indexedrï   rÏ   rÐ   rß   rÁ   rÀ   rŽ   r\   rŠ   ÚhasÚ_doprint_loopsrn   )rb   rÇ   rí   rî   rï   rÏ   rÐ   ÚexpressionsÚ
conditionsrÉ   rÈ   ÚtemprÒ   rÓ   rg   rg   rh   Ú_print_Assignment  s(   
ÿ

z"JuliaCodePrinter._print_Assignmentc                 C  rä   )NÚInfrg   rá   rg   rg   rh   Ú_print_Infinity#  ræ   z JuliaCodePrinter._print_Infinityc                 C  rä   )Nz-Infrg   rá   rg   rg   rh   Ú_print_NegativeInfinity'  ræ   z(JuliaCodePrinter._print_NegativeInfinityc                 C  rä   )NÚNaNrg   rá   rg   rg   rh   Ú
_print_NaN+  ræ   zJuliaCodePrinter._print_NaNc                   s    dd  ‡ fdd„|D ƒ¡ d S )NzAny[ú, c                 3  s   � | ]}ˆ   |¡V  qd S rx   ©rŠ   ©r}   rª   ©rb   rg   rh   r‚   0  ó   € z/JuliaCodePrinter._print_list.<locals>.<genexpr>Ú])Újoinrá   rg   r  rh   Ú_print_list/  s    zJuliaCodePrinter._print_listc                 C  s.   t |ƒdkrd|  |d ¡ S d|  |d¡ S )Nr‡   z(%s,)r   r¥   rþ   )r¨   rŠ   Ú	stringifyrá   rg   rg   rh   Ú_print_tuple3  s   zJuliaCodePrinter._print_tuplec                 C  rä   )NÚtruerg   rá   rg   rg   rh   Ú_print_BooleanTrue;  ræ   z#JuliaCodePrinter._print_BooleanTruec                 C  rä   )NÚfalserg   rá   rg   rg   rh   Ú_print_BooleanFalse?  ræ   z$JuliaCodePrinter._print_BooleanFalsec                 C  s   t |ƒ ¡ S rx   )ÚstrrŒ   rá   rg   rg   rh   Ú_print_boolC  rw   zJuliaCodePrinter._print_boolc                   s–   t j|jv rd|j|jf S |j|jfdkrd|d  S |jdkr,d|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))r‡   r‡   z[%s])r   r   r‡   r—   ú )ÚrowstartÚrowendÚcolseprþ   c                   ó   g | ]}ˆ   |¡‘qS rg   rÿ   r   r  rg   rh   r£   U  ó    z6JuliaCodePrinter._print_MatrixBase.<locals>.<listcomp>z;
)r  r  Úrowsepr  )r   ÚZerorƒ   r�   r…   Útabler  )rb   ÚArg   r  rh   Ú_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   r‡   rg   ©r}   Úkrg   rg   rh   r£   ^  r¤   z;JuliaCodePrinter._print_SparseRepMatrix.<locals>.<listcomp>c                 S  s   g | ]}|d  d  ‘qS )r‡   rg   r  rg   rg   rh   r£   _  r¤   c                 S  s   g | ]}|d  ‘qS )é   rg   r  rg   rg   rh   r£   `  s    zsparse(%s, %s, %s, %s, %s))Úsympy.matricesr  Zcol_listrŠ   r�   r…   )rb   r  r  ÚLÚIÚJZAIJrg   rg   rh   Ú_print_SparseRepMatrixZ  s   ÿz'JuliaCodePrinter._print_SparseRepMatrixc                 C  s.   | j |jtd dd�d|jd |jd f  S )NÚAtomT)Ústrictz[%s,%s]r‡   )rž   Úparentr   r   r~   rá   rg   rg   rh   Ú_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rdnˆ   |¡}|dkr8|dkr,||kr,dS ||kr2|S |d | S d |ˆ   |¡|f¡S )Nr   r‡   r  rˆ   ú:)rŠ   r  )r    ÚlimÚlÚhÚstepÚlstrZhstrr  rg   rh   Ústrslicek  s   
z5JuliaCodePrinter._print_MatrixSlice.<locals>.strsliceÚ[r   ú,r‡   r  )rŠ   r$  Úrowslicerƒ   Úcolslice)rb   rÇ   r,  rg   r  rh   Ú_print_MatrixSlicej  s   ÿÿþþz#JuliaCodePrinter._print_MatrixSlicec                   s0   ‡ fdd„|j D ƒ}dˆ  |jj¡d |¡f S )Nc                   r  rg   rÿ   )r}   r   r  rg   rh   r£   €  r  z3JuliaCodePrinter._print_Indexed.<locals>.<listcomp>z%s[%s]r.  )r�   rŠ   r¿   r‹   r  )rb   rÇ   Úindsrg   r  rh   Ú_print_Indexed  s   zJuliaCodePrinter._print_Indexedc                 C  s   d|   |jd ¡ S )Nzeye(%s)r   )rŠ   rƒ   rá   rg   rg   rh   Ú_print_Identityƒ  s   z JuliaCodePrinter._print_Identityc                   s   d  ‡ ‡fdd„ˆ jD ƒ¡S )Nz .* c                   s   g | ]
}ˆ  |tˆ ƒ¡‘qS rg   ©rž   r   ©r}   Úarg©rÇ   rb   rg   rh   r£   ‡  s    ÿz;JuliaCodePrinter._print_HadamardProduct.<locals>.<listcomp>)r  rÀ   rá   rg   r8  rh   Ú_print_HadamardProduct†  s   ÿz'JuliaCodePrinter._print_HadamardProductc                 C  s*   t |ƒ}d |  |j|¡|  |j|¡g¡S )Nz.**)r   r  rž   r¿   r+   rÚ   rg   rg   rh   Ú_print_HadamardPowerŠ  s
   þz%JuliaCodePrinter._print_HadamardPowerc                 C  s$   |j dkr
t|jƒS d|j|j f S )Nr‡   z%s // %s)rÃ   r  rj   rá   rg   rg   rh   Ú_print_Rational‘  s   

z JuliaCodePrinter._print_Rationalc                 C  óD   ddl m}m} |j}|tjd|  ƒ||jtj |ƒ }|  |¡S )Nr   )r-   r;   r  )	Úsympy.functionsr-   r;   Úargumentr   ÚPir¸   ÚHalfrŠ   )rb   rÇ   r-   r;   r    Úexpr2rg   rg   rh   Ú	_print_jn—  ó   $
zJuliaCodePrinter._print_jnc                 C  r<  )Nr   )r-   r<   r  )	r=  r-   r<   r>  r   r?  r¸   r@  rŠ   )rb   rÇ   r-   r<   r    rA  rg   rg   rh   Ú	_print_ynž  rC  zJuliaCodePrinter._print_ync                 C  s   d  |  |jd tj ¡¡S )Nzsinc({})r   )rp   rŠ   rÀ   r   r?  rá   rg   rg   rh   Ú_print_sinc¤  s   zJuliaCodePrinter._print_sincc           
        s  |j d jdkrtdƒ‚g }ˆ jd r9‡ fdd„|j d d… D ƒ}dˆ  |j d j¡ }d |¡| }d	| d
 S t|j ƒD ]J\}\}}|dkrS| dˆ  |¡ ¡ n|t	|j ƒd krf|dkrf| d¡ n
| dˆ  |¡ ¡ ˆ  |¡}	| |	¡ |t	|j ƒd krˆ| d¡ q>d |¡S )Nrš   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.rW   c                   s(   g | ]\}}d   ˆ  |¡ˆ  |¡¡‘qS )z({}) ? ({}) :)rp   rŠ   )r}   rÉ   rÈ   r  rg   rh   r£   ¶  s
    þÿz5JuliaCodePrinter._print_Piecewise.<locals>.<listcomp>z (%s)Ú
ú(ú)r   zif (%s)r‡   Úelsezelseif (%s)rˆ   )
rÀ   ÚcondÚ
ValueErrorrß   rŠ   rÇ   r  Ú	enumeraterŽ   r¨   )
rb   rÇ   rz   ÚecpairsZelastÚpwr   rÉ   rÈ   Úcode0rg   r  rh   Ú_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 )Nr—   r–   z * c                 3  s    � | ]}ˆ  |tˆ ƒ¡V  qd S rx   r5  r6  r8  rg   rh   r‚   Ú  s   € z1JuliaCodePrinter._print_MatMul.<locals>.<genexpr>)Úas_coeff_mmulr©   Úas_real_imagÚis_zeror¾   r   r  rÀ   )rb   rÇ   rÈ   Úmr(   rL   rK   rg   r8  rh   Ú_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 ]%\}}	|	dv rG| |	¡ q9||| 8 }| d|| |	f ¡ ||| 7 }q9|S )z0Accepts a string of code or a list of code linesTr—   z    )z
^function z^if ú^elseif ú^else$z^for )z^end$rV  rW  c                 S  s   g | ]}|  d ¡‘qS )z 	)Úlstrip)r}   Úlinerg   rg   rh   r£   ë  r  z0JuliaCodePrinter.indent_code.<locals>.<listcomp>c                   ó&   g | ]‰ t t‡ fd d„ˆD ƒƒƒ‘qS )c                 3  ó   � | ]}t |ˆ ƒV  qd S rx   r   ©r}   rL   ©rY  rg   rh   r‚   í  r  ú:JuliaCodePrinter.indent_code.<locals>.<listcomp>.<genexpr>©ÚintÚany©r}   )Ú	inc_regexr]  rh   r£   í  ó    ÿc                   rZ  )c                 3  r[  rx   r   r\  r]  rg   rh   r‚   ï  r  r^  r_  rb  )Ú	dec_regexr]  rh   r£   ï  rd  r   )r—   rF  z%s%s)rÁ   r  ry   Ú
splitlinesr  rL  rŽ   )
rb   ÚcodeÚ
code_linesÚtabÚincreaseÚdecreaseÚprettyÚlevelÚnrY  rg   )re  rc  rh   ry   Þ  s.   


ÿ
ÿ
zJuliaCodePrinter.indent_code)7Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚprintmethodÚlanguageÚ
_operatorsr[   r
   rX   Ú__annotations__rZ   rk   rn   rr   rv   r{   r†   r•   rÎ   rÕ   rÙ   rÛ   râ   rå   rç   ré   rë   rì   rø   rú   rû   rý   r  r  Ú_print_Tupler	  r  r  r  r!  r%  r1  r3  r4  r9  r:  r;  rB  rD  rE  rP  rU  ry   Ú__classcell__rg   rg   re   rh   rM   0   sr   
 ý
ü
J$rM   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])'
    )rM   Údoprint)rÇ   Ú	assign_torc   rg   rg   rh   Ú
julia_codeþ  s    r{  c                 K  s   t t| fi |¤Žƒ 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   rg   rg   rh   Úprint_julia_code‡  s   r}  rx   )rr  Ú
__future__r   Útypingr   Ú
sympy.corer   r   r   r   Zsympy.core.mulr   Úsympy.core.numbersr	   Zsympy.printing.codeprinterr
   Úsympy.printing.precedencer   r   rL   r   r]   r`   rM   r{  r}  rg   rg   rg   rh   Ú<module>   s2    ù   
Q 
