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_juliaZ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 )NrT   )	ÚsuperÚ__init__ÚdictÚzipÚknown_fcns_src1Úknown_functionsÚupdateÚknown_fcns_src2Úget)ÚselfÚsettingsÚ	userfuncs©Ú	__class__© úg/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/sympy/printing/julia.pyrY   G   s
   zJuliaCodePrinter.__init__c                 C  s   |d S )Né   rf   )ra   Úprf   rf   rg   Ú_rate_index_positionO   ó   z%JuliaCodePrinter._rate_index_positionc                 C  s   d| S )Nz%srf   )ra   Ú
codestringrf   rf   rg   Ú_get_statementS   rk   zJuliaCodePrinter._get_statementc                 C  s
   d  |¡S )Nz# {}©Úformat)ra   Útextrf   rf   rg   Ú_get_commentW   ó   
zJuliaCodePrinter._get_commentc                 C  s   d  ||¡S )Nzconst {} = {}rn   )ra   ÚnameÚvaluerf   rf   rg   Ú_declare_number_const[   ó   z&JuliaCodePrinter._declare_number_constc                 C  s
   |   |¡S ©N)Úindent_code)ra   Úlinesrf   rf   rg   Ú_format_code_   rr   zJuliaCodePrinter._format_codec                   s    |j \‰ }‡ fdd„t|ƒD ƒS )Nc                 3  s&   � | ]}t ˆ ƒD ]}||fV  qqd S rw   )Úrange)Ú.0ÚjÚi©Úrowsrf   rg   Ú	<genexpr>f   s   €$ z<JuliaCodePrinter._traverse_matrix_indices.<locals>.<genexpr>)Úshaper{   )ra   ÚmatÚcolsrf   r   rg   Ú_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)ra   ÚindicesÚ
open_linesÚclose_linesr~   ÚvarÚstartÚstoprf   rf   rg   Ú_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 rf   ©Úparenthesize©r|   Úx©Úprecra   rf   rg   Ú
<listcomp>¥   ó    z/JuliaCodePrinter._print_Mul.<locals>.<listcomp>c                   r›   rf   rœ   rž   r    rf   rg   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mulsymrf   rf   rg   Úmultjoin®   s
   z-JuliaCodePrinter._print_Mul.<locals>.multjoinú/ú./r¦   c                 s  ó   � | ]}|j V  qd S rw   ©r¨   )r|   Úbirf   rf   rg   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ÚInfinityri   r   ÚqÚOneÚindexÚall)ra   ÚexprÚcÚer(   r©   ÚbÚ	pow_parenr¿   Úitemrª   Úb_strr¬   Zdivsymrf   r    rg   Ú
_print_Mulu   sV   ÿ


ÿ
 

 €zJuliaCodePrinter._print_Mulc                 C  s,   |   |j¡}|   |j¡}|j}d |||¡S )Nz{} {} {})r‰   ÚlhsÚrhsÚrel_opro   )ra   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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¯   rw   r°   rž   rf   rf   rg   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�   )ra   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   r�   r¾   r+   ©ra   rÆ   rÖ   rf   rf   rg   Ú_print_MatPowÙ   s   ÿzJuliaCodePrinter._print_MatPowc                   ó   | j d rdS tƒ  |¡S )NrV   Úpi©Ú	_settingsrX   Ú_print_NumberSymbol©ra   rÆ   rd   rf   rg   Ú	_print_Piß   ó   
zJuliaCodePrinter._print_Pic                 C  ó   dS )NrK   rf   rà   rf   rf   rg   Ú_print_ImaginaryUnitæ   ó   z%JuliaCodePrinter._print_ImaginaryUnitc                   rÛ   )NrV   rÈ   rÝ   rà   rd   rf   rg   Ú_print_Exp1ê   râ   zJuliaCodePrinter._print_Exp1c                   rÛ   )NrV   Ú
eulergammarÝ   rà   rd   rf   rg   Ú_print_EulerGammañ   râ   z"JuliaCodePrinter._print_EulerGammac                   rÛ   )NrV   ÚcatalanrÝ   rà   rd   rf   rg   Ú_print_Catalanø   râ   zJuliaCodePrinter._print_Catalanc                   rÛ   )NrV   ZgoldenrÝ   rà   rd   rf   rg   Ú_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)ÚIndexedBaserV   rU   z%s = %s)Úsympy.codegen.astrì   Ú$sympy.functions.elementary.piecewiserí   Úsympy.tensor.indexedrî   rÎ   rÏ   rÞ   rÀ   r¿   r�   r[   r‰   ÚhasÚ_doprint_loopsrm   )ra   rÆ   rì   rí   rî   rÎ   rÏ   ÚexpressionsÚ
conditionsrÈ   rÇ   ÚtemprÑ   rÒ   rf   rf   rg   Ú_print_Assignment  s(   
ÿ

z"JuliaCodePrinter._print_Assignmentc                 C  rã   )NÚInfrf   rà   rf   rf   rg   Ú_print_Infinity#  rå   z JuliaCodePrinter._print_Infinityc                 C  rã   )Nz-Infrf   rà   rf   rf   rg   Ú_print_NegativeInfinity'  rå   z(JuliaCodePrinter._print_NegativeInfinityc                 C  rã   )NÚNaNrf   rà   rf   rf   rg   Ú
_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 rw   ©r‰   ©r|   r©   ©ra   rf   rg   r�   0  ó   € z/JuliaCodePrinter._print_list.<locals>.<genexpr>Ú])Újoinrà   rf   r   rg   Ú_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à   rf   rf   rg   Ú_print_tuple3  s   zJuliaCodePrinter._print_tuplec                 C  rã   )NÚtruerf   rà   rf   rf   rg   Ú_print_BooleanTrue;  rå   z#JuliaCodePrinter._print_BooleanTruec                 C  rã   )NÚfalserf   rà   rf   rf   rg   Ú_print_BooleanFalse?  rå   z$JuliaCodePrinter._print_BooleanFalsec                 C  s   t |ƒ ¡ S rw   )Ústrr‹   rà   rf   rf   rg   Ú_print_boolC  rv   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 rf   rþ   rÿ   r   rf   rg   r¢   U  ó    z6JuliaCodePrinter._print_MatrixBase.<locals>.<listcomp>z;
)r  r  Úrowsepr  )r   ÚZeror‚   r€   r„   Útabler  )ra   Ú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   r†   rf   ©r|   Úkrf   rf   rg   r¢   ^  r£   z;JuliaCodePrinter._print_SparseRepMatrix.<locals>.<listcomp>c                 S  s   g | ]}|d  d  ‘qS )r†   rf   r  rf   rf   rg   r¢   _  r£   c                 S  s   g | ]}|d  ‘qS )é   rf   r  rf   rf   rg   r¢   `  s    zsparse(%s, %s, %s, %s, %s))Úsympy.matricesr  Zcol_listr‰   r€   r„   )ra   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 )NÚAtomT)Ústrictz[%s,%s]r†   )r�   Úparentr   r~   r}   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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   rf   rg   Ústrslicek  s   
z5JuliaCodePrinter._print_MatrixSlice.<locals>.strsliceÚ[r   ú,r†   r  )r‰   r#  Úrowslicer‚   Úcolslice)ra   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                   r  rf   rþ   )r|   r~   r   rf   rg   r¢   €  r  z3JuliaCodePrinter._print_Indexed.<locals>.<listcomp>z%s[%s]r-  )rŽ   r‰   r¾   rŠ   r  )ra   rÆ   Úindsrf   r   rg   Ú_print_Indexed  s   zJuliaCodePrinter._print_Indexedc                 C  s   d|   |jd ¡ S )Nzeye(%s)r   )r‰   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   ©r�   r   ©r|   Úarg©rÆ   ra   rf   rg   r¢   ‡  s    ÿz;JuliaCodePrinter._print_HadamardProduct.<locals>.<listcomp>)r  r¿   rà   rf   r7  rg   Ú_print_HadamardProduct†  s   ÿz'JuliaCodePrinter._print_HadamardProductc                 C  s*   t |ƒ}d |  |j|¡|  |j|¡g¡S )Nz.**)r   r  r�   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 )Nr†   z%s // %s)rÂ   r  ri   rà   rf   rf   rg   Ú_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‰   )ra   rÆ   r-   r;   rŸ   Úexpr2rf   rf   rg   Ú	_print_jn—  ó   $
zJuliaCodePrinter._print_jnc                 C  r;  )Nr   )r-   r<   r  )	r<  r-   r<   r=  r   r>  r·   r?  r‰   )ra   rÆ   r-   r<   rŸ   r@  rf   rf   rg   Ú	_print_ynž  rB  zJuliaCodePrinter._print_ync                 C  s   d  |  |jd tj ¡¡S )Nzsinc({})r   )ro   r‰   r¿   r   r>  rà   rf   rf   rg   Ú_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.rV   c                   s(   g | ]\}}d   ˆ  |¡ˆ  |¡¡‘qS )z({}) ? ({}) :)ro   r‰   )r|   rÈ   rÇ   r   rf   rg   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§   )
ra   rÆ   ry   ÚecpairsZelastÚpwr~   rÈ   rÇ   Ú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 )Nr–   r•   z * c                 3  s    � | ]}ˆ  |tˆ ƒ¡V  qd S rw   r4  r5  r7  rf   rg   r�   Ú  s   € z1JuliaCodePrinter._print_MatMul.<locals>.<genexpr>)Úas_coeff_mmulr¨   Úas_real_imagÚis_zeror½   r   r  r¿   )ra   rÆ   rÇ   Úmr(   rL   rK   rf   r7  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 ]%\}}	|	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$rU  rV  c                 S  s   g | ]}|  d ¡‘qS )z 	)Úlstrip)r|   Úlinerf   rf   rg   r¢   ë  r  z0JuliaCodePrinter.indent_code.<locals>.<listcomp>c                   ó&   g | ]‰ t t‡ fd d„ˆD ƒƒƒ‘qS )c                 3  ó   � | ]}t |ˆ ƒV  qd S rw   r   ©r|   rL   ©rX  rf   rg   r�   í  r  ú:JuliaCodePrinter.indent_code.<locals>.<listcomp>.<genexpr>©ÚintÚany©r|   )Ú	inc_regexr\  rg   r¢   í  ó    ÿc                   rY  )c                 3  rZ  rw   r   r[  r\  rf   rg   r�   ï  r  r]  r^  ra  )Ú	dec_regexr\  rg   r¢   ï  rc  r   )r–   rE  z%s%s)rÀ   r  rx   Ú
splitlinesr  rK  r�   )
ra   ÚcodeÚ
code_linesÚtabÚincreaseÚdecreaseÚprettyÚlevelÚnrX  rf   )rd  rb  rg   rx   Þ  s.   


ÿ
ÿ
zJuliaCodePrinter.indent_code)7Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚprintmethodÚlanguageÚ
_operatorsrZ   r
   rW   Ú__annotations__rY   rj   rm   rq   ru   rz   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$  r0  r2  r3  r8  r9  r:  rA  rC  rD  rO  rT  rx   Ú__classcell__rf   rf   rd   rg   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_torb   rf   rf   rg   Ú
julia_codeþ  s    rz  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)Úprintrz  )rÆ   rb   rf   rf   rg   Úprint_julia_code‡  s   r|  rw   )rq  Ú
__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   rz  r|  rf   rf   rf   rg   Ú<module>   s2    ù   
Q 
