
    MZd\                        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e      ZddZd Zy)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)3sincostancotseccscasinacosatanacotasecacscsinhcoshtanhcothsechcschasinhacoshatanhacothasechacschsinc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conjhankelh1hankelh2imagreal)Absceiling	conjugatehankel1hankel2imrec            	      j    e Zd ZU dZdZdZddddZdd	d
i dddddZded<   i f fd	Z	d Z
d Zd Zd Zd Zd Zd Zd Zd Zd Zd Z fdZd Z fdZ fdZ fd Z fd!Zd" Zd# Zd$ Zd% Zd& Zd' Z e Z!d( Z"d) Z#d* Z$d+ Z%d, Z&d- Z'd. Z(d/ Z)d0 Z*d1 Z+d2 Z,d3 Z-d4 Z.d5 Z/d6 Z0d7 Z1d8 Z2d9 Z3 xZ4S ):JuliaCodePrinterzD
    A printer to convert expressions to strings of Julia code.
    _juliaJuliaz&&z||!)andornotNauto   TF)order	full_prec	precisionuser_functionshumanallow_unknown_functionscontractinlinezdict[str, Any]_default_settingsc                   t         |   |       t        t        t        t                    | _        | j
                  j                  t        t                     |j                  di       }| j
                  j                  |       y )Nr^   )	super__init__dictzipknown_fcns_src1known_functionsupdateknown_fcns_src2get)selfsettings	userfuncs	__class__s      6/usr/lib/python3/dist-packages/sympy/printing/julia.pyrf   zJuliaCodePrinter.__init__K   sb    "#C$IJ##D$9:LL!126	##I.    c                    |dz  S )N    )rn   ps     rr   _rate_index_positionz%JuliaCodePrinter._rate_index_positionS   s    s
rs   c                    d|z  S )Nz%srv   )rn   
codestrings     rr   _get_statementzJuliaCodePrinter._get_statementW   s    j  rs   c                $    dj                  |      S )Nz# {}format)rn   texts     rr   _get_commentzJuliaCodePrinter._get_comment[   s    }}T""rs   c                &    dj                  ||      S )Nzconst {} = {}r}   )rn   namevalues      rr   _declare_number_constz&JuliaCodePrinter._declare_number_const_   s    %%dE22rs   c                $    | j                  |      S N)indent_code)rn   liness     rr   _format_codezJuliaCodePrinter._format_codec   s    &&rs   c                J    |j                   \  }fdt        |      D        S )Nc              3  F   K   | ]  }t              D ]  }||f 
  y wr   )range).0jirowss      rr   	<genexpr>z<JuliaCodePrinter._traverse_matrix_indices.<locals>.<genexpr>j   s%     A1U4[AAAAs   !)shaper   )rn   matcolsr   s      @rr   _traverse_matrix_indicesz)JuliaCodePrinter._traverse_matrix_indicesg   s    YY
dAdAArs   c           	         g }g }|D ]n  }t        | j                  |j                  |j                  dz   |j                  dz   g      \  }}}|j                  d|d|d|       |j                  d       p ||fS )N   zfor  = :end)map_printlabellowerupperappend)rn   indices
open_linesclose_linesr   varstartstops           rr   _get_loop_opening_endingz)JuliaCodePrinter._get_loop_opening_endingm   s    
 	&A"4;;WWaggk177Q;7 9C#udCDu%	& ;&&rs   c                   |j                   rO|j                  rC|j                         d   j                  r&d| j	                  t
        j                   |z        z  S t        |      }|j                         \  }}|dk  rt        | |      }d}nd}g }g }g }| j                  dvr|j                         }	nt        j                  |      }	|	D ]o  }
|
j                  r|
j                  r|
j                  j                   r|
j                  j"                  r|
j                  dk7  r3|j%                  t'        |
j(                  |
j                   d             t+        |
j,                  d   j,                        d	k7  r+t/        |
j(                  t              r|j%                  |
       |j%                  t'        |
j(                  |
j                                |
j                   rG|
t
        j0                  ur5|
j2                  d	k(  r&|j%                  t5        |
j6                               _|j%                  |
       r |xs t
        j8                  g}|D cg c]  }| j;                  ||       }}|D cg c]  }| j;                  ||       }}|D ]N  }
|
j(                  |v sd
||j=                  |
j(                           z  ||j=                  |
j(                        <   P d }|s| |||      z   S t+        |      d	k(  r*|d   j                   rdnd}| |||      z   d|d|d   S t?        d |D              rdnd}| |||      z   d|d |||      dS c c}w c c}w )Nr   z%sim- )oldnoneF)evaluater   (%s)c                    |d   }t        dt        |             D ]%  }| |dz
     j                  rdnd}|d|d||   }' |S )Nr   r   *z.* )r   len	is_number)aa_strrr   mulsyms        rr   multjoinz-JuliaCodePrinter._print_Mul.<locals>.multjoin   sS    aA1c!f% 7 !!A# 0 0d"#VU1X67 Hrs   /./r   c              3  4   K   | ]  }|j                     y wr   r   )r   bis     rr   r   z.JuliaCodePrinter._print_Mul.<locals>.<genexpr>   s     99   z ()) r   is_imaginaryas_coeff_Mul
is_integerr   r   ImaginaryUnitr   r	   r[   as_ordered_factorsr   	make_argsis_commutativeis_Powr-   is_Rationalis_negativer   r   baser   args
isinstanceInfinityrw   r   qOneparenthesizeindexall)rn   exprpreccer*   r   b	pow_parenr   itemxr   b_strr   divsyms                   rr   
_print_MulzJuliaCodePrinter._print_Muly   s   NNt00!!#A&11DKK(8(=>>> $  "1q5r1%DDD	::_,**,D ==&D  	D##8L8L,,88r>HHSTXXIFG499Q<,,-2z$))S7Q!((.HHSTXXI67!!d!**&<1
 $&&)*!	$ L!%%567""1d+77567""1d+77  	ODyyA~,2U177499;M5N,Naggdii()	O
	 (1e,,,Vq[aDNNSF!%hq%&8!8&%(KK9q99StF#'(1e*<#<fhqRWFXYY1 87s   M!8M&c                    | j                  |j                        }| j                  |j                        }|j                  }dj	                  |||      S )Nz{} {} {})r   lhsrhsrel_opr~   )rn   r   lhs_coderhs_codeops        rr   _print_Relationalz"JuliaCodePrinter._print_Relational   sD    ;;txx(;;txx([[  2x88rs   c                   t        d |j                  D              rdnd}t        |      }t        |j                  d      rd| j                  |j                        z  S |j                  rt        |j                  d      r<|j                  j                  rdnd}d	|d
| j                  |j                        dS t        |j                  d      r<|j                  j                  rdnd}d	|d| j                  |j                  |      S | j                  |j                  |      d|d| j                  |j                  |      S )Nc              3  4   K   | ]  }|j                     y wr   r   )r   r   s     rr   r   z.JuliaCodePrinter._print_Pow.<locals>.<genexpr>   s     >qq{{>r   ^z.^g      ?zsqrt(%s)g      r   r   z1 z sqrt(r   r   r   )
r   r   r   r
   r-   r   r   r   r   r   )rn   r   	powsymbolPRECsyms        rr   
_print_PowzJuliaCodePrinter._print_Pow   s    >DII>>CD	$#&DII 666DHHd+!YY00cd*-t{{499/EFFDHHb)!YY00cd%($*;*;DIIt*LMM!..tyy$?,,TXXt<> 	>rs   c                    t        |      }| j                  |j                  |      d| j                  |j                  |      S )Nz ^ )r   r   r   r-   rn   r   r   s      rr   _print_MatPowzJuliaCodePrinter._print_MatPow   s>    $ --dii>++DHHd;= 	=rs   c                B    | j                   d   ryt        | 	  |      S )Nrb   pi	_settingsre   _print_NumberSymbolrn   r   rq   s     rr   	_print_PizJuliaCodePrinter._print_Pi   s"    >>(#7.t44rs   c                     y)NrO   rv   rn   r   s     rr   _print_ImaginaryUnitz%JuliaCodePrinter._print_ImaginaryUnit   s    rs   c                B    | j                   d   ryt        | 	  |      S )Nrb   r   r   r   s     rr   _print_Exp1zJuliaCodePrinter._print_Exp1   s"    >>(#7.t44rs   c                B    | j                   d   ryt        | 	  |      S )Nrb   
eulergammar   r   s     rr   _print_EulerGammaz"JuliaCodePrinter._print_EulerGamma   s"    >>(#7.t44rs   c                B    | j                   d   ryt        | 	  |      S )Nrb   catalanr   r   s     rr   _print_CatalanzJuliaCodePrinter._print_Catalan   s"    >>(#7.t44rs   c                B    | j                   d   ryt        | 	  |      S )Nrb   goldenr   r   s     rr   _print_GoldenRatioz#JuliaCodePrinter._print_GoldenRatio  s"    >>(#7.t44rs   c                X   ddl m} ddlm} ddlm} |j                  }|j                  }| j                  d   swt        |j                  |      rag }g }|j                  D ].  \  }	}
|j                   |||	             |j                  |
       0  |t        ||       }| j                  |      S | j                  d   r4|j                  |      s|j                  |      r| j                  ||      S | j                  |      }| j                  |      }| j!                  |d|      S )Nr   )
Assignment)	Piecewise)IndexedBaserb   ra   r   )sympy.codegen.astr  $sympy.functions.elementary.piecewiser  sympy.tensor.indexedr	  r   r   r   r   r   r   rh   r   has_doprint_loopsr{   )rn   r   r  r  r	  r   r   expressions
conditionsr   r   tempr   r   s                 rr   _print_Assignmentz"JuliaCodePrinter._print_Assignment
  s   0B4hhhh~~h'Jtxx,K KJ(( %A"":c1#56!!!$% c+z:;D;;t$$>>*%377;+?$ &&sC00{{3'H{{3'H&&Hh'GHHrs   c                     y)NInfrv   r   s     rr   _print_Infinityz JuliaCodePrinter._print_Infinity'      rs   c                     y)Nz-Infrv   r   s     rr   _print_NegativeInfinityz(JuliaCodePrinter._print_NegativeInfinity+      rs   c                     y)NNaNrv   r   s     rr   
_print_NaNzJuliaCodePrinter._print_NaN/  r  rs   c                D     ddj                   fd|D              z   dz   S )NzAny[, c              3  @   K   | ]  }j                  |        y wr   )r   )r   r   rn   s     rr   r   z/JuliaCodePrinter._print_list.<locals>.<genexpr>4  s     !?Q$++a.!?s   ])joinr   s   ` rr   _print_listzJuliaCodePrinter._print_list3  s"    		!?$!???#EErs   c                v    t        |      dk(  rd| j                  |d         z  S d| j                  |d      z  S )Nr   z(%s,)r   r   r  )r   r   	stringifyr   s     rr   _print_tuplezJuliaCodePrinter._print_tuple7  s;    t9>T[[a111DNN4666rs   c                     y)Ntruerv   r   s     rr   _print_BooleanTruez#JuliaCodePrinter._print_BooleanTrue?  r  rs   c                     y)Nfalserv   r   s     rr   _print_BooleanFalsez$JuliaCodePrinter._print_BooleanFalseC  s    rs   c                4    t        |      j                         S r   )strr   r   s     rr   _print_boolzJuliaCodePrinter._print_boolG  s    4y  rs   c           	        t         j                  |j                  v rd|j                  d|j                  dS |j                  |j                  fdk(  rd|d   z  S |j                  dk(  rd|j                  | ddd	
      z  S |j                  dk(  r1ddj                  |D cg c]  }| j                  |       c}      z  S d|j                  | dddd	      z  S c c}w )Nzzeros(r  r   )r   r   z[%s])r   r   r   r   r   )rowstartrowendcolsepz;
)r0  r1  rowsepr2  )r   Zeror   r   r   tabler!  r   )rn   Ar   s      rr   _print_MatrixBasez"JuliaCodePrinter._print_MatrixBaseO  s    66QWW&'ffaff55ffaff'AdG##VVq[AGGD2bGMMMVVq[DIIq&A!t{{1~&ABBBr"',S   : : 	: 'Bs   #C
c                   ddl m} |j                         } ||D cg c]
  }|d   dz    c}      } ||D cg c]
  }|d   dz    c}      } ||D cg c]  }|d   	 c}      }d| j                  |      d| j                  |      d| j                  |      d|j                  d|j
                  dS c c}w c c}w c c}w )Nr   )Matrixr      zsparse(r  r   )sympy.matricesr9  col_listr   r   r   )rn   r6  r9  LkIJAIJs           rr   _print_SparseRepMatrixz'JuliaCodePrinter._print_SparseRepMatrix^  s    )JJLa(AaD1H()a(AaD1H()A&qad&'/3{{1~t{{1~,0KK,<affaffN 	N )(&s   B;C Cc                    | j                  |j                  t        d   d      d|j                  dz   d|j                  dz   dz   S )NAtomT)strict[r   ,r   )r   parentr   r   r   r   s     rr   _print_MatrixElementz%JuliaCodePrinter._print_MatrixElementi  sB      j.@ N66A:tvvz23 	3rs   c                     fd} j                  |j                        dz    ||j                  |j                  j                  d         z   dz    ||j                  |j                  j                  d         z   dz   S )Nc                    | d   dz   }| d   }| d   }j                  |      }||k(  rdnj                  |      }|dk(  r|dk(  r||k(  ry||k(  r|S |dz   |z   S dj                  |j                  |      |f      S )Nr   r   r:  r   r   )r   r!  )r   limlhsteplstrhstrrn   s          rr   strslicez5JuliaCodePrinter._print_MatrixSlice.<locals>.strsliceo  s    !qA!AQ4D;;q>DH5$++a.Dqy6a3h6K#:,,xxt{{4'8$ ?@@rs   rF  r   rG  r   r   )r   rH  rowslicer   colslice)rn   r   rR  s   `  rr   _print_MatrixSlicez#JuliaCodePrinter._print_MatrixSlicen  s|    	A DKK(3.(9(9!(<=>@CD(9(9!(<=>@CD 	Ers   c                    |j                   D cg c]  }| j                  |       }}| j                  |j                  j                        ddj	                  |      dS c c}w )NrF  rG  r   )r   r   r   r   r!  )rn   r   r   indss       rr   _print_IndexedzJuliaCodePrinter._print_Indexed  sJ    )-7AQ77;;tyy7$HH 8s   A#c                8    | j                  |j                        S r   )r   r   r   s     rr   
_print_IdxzJuliaCodePrinter._print_Idx  s    {{4::&&rs   c                D    d| j                  |j                  d         z  S )Nzeye(%s)r   )r   r   r   s     rr   _print_Identityz JuliaCodePrinter._print_Identity  s    4;;tzz!}555rs   c                    dj                  |j                  D cg c]  }| j                  |t        |             c}      S c c}w )Nz .* )r!  r   r   r   )rn   r   args      rr   _print_HadamardProductz'JuliaCodePrinter._print_HadamardProduct  sD    {{%)YY0! !--c:d3CD 0 1 	1 0s   "Ac                    t        |      }dj                  | j                  |j                  |      | j                  |j                  |      g      S )Nz.**)r   r!  r   r   r-   r   s      rr   _print_HadamardPowerz%JuliaCodePrinter._print_HadamardPower  sJ    $zzdii.dhh-  	rs   c                    |j                   dk(  rt        |j                        S |j                  d|j                   S )Nr   z // )r   r-  rw   r   s     rr   _print_Rationalz JuliaCodePrinter._print_Rational  s.    66Q;tvv;!VVTVV,,rs   c                    ddl m}m} |j                  } |t        j
                  d|z  z         ||j                  t        j                  z   |      z  }| j                  |      S )Nr   )r/   r=   r:  )	sympy.functionsr/   r=   argumentr   Pir[   Halfr   )rn   r   r/   r=   r   expr2s         rr   	_print_jnzJuliaCodePrinter._print_jn  L    1MMQTT1Q3Z aff)<a!@@{{5!!rs   c                    ddl m}m} |j                  } |t        j
                  d|z  z         ||j                  t        j                  z   |      z  }| j                  |      S )Nr   )r/   r>   r:  )	re  r/   r>   rf  r   rg  r[   rh  r   )rn   r   r/   r>   r   ri  s         rr   	_print_ynzJuliaCodePrinter._print_yn  rk  rs   c           
        |j                   d   j                  dk7  rt        d      g }| j                  d   r|j                   d d D cg c]5  \  }}dj	                  | j                  |      | j                  |            7 }}}d| j                  |j                   d   j                        z  }dj                  |      |z   }d|z   d	z   S t        |j                         D ]  \  }\  }}|d
k(  r$|j                  d| j                  |      z         nU|t        |j                         dz
  k(  r|dk(  r|j                  d       n#|j                  d| j                  |      z         | j                  |      }	|j                  |	       |t        |j                         dz
  k(  s|j                  d        dj                  |      S c c}}w )Nr   TzAll 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.rb   z({}) ? ({}) :z (%s)
(r   r   zif (%s)r   elsezelseif (%s)r   )r   cond
ValueErrorr   r~   r   r   r!  	enumerater   r   )
rn   r   r   r   r   ecpairselastpwr   code0s
             rr   _print_Piecewisez!JuliaCodePrinter._print_Piecewise  s   99R=%  / 0 0
 >>(# $(99Sb>31a '--AA8 3G 3 dkk$))B-*<*<==E7#e+B 8c>!&tyy1 
(	6Aq6LLT[[^!;<#dii.1,,dLL(LLQ!?@AU#DII**LL'
( 99U##)3s   :Gc                \    j                         \  }}d}|j                  rb|j                         \  }}|j                  r|j                  rt        | |      d}n'|j                  r|j                  rt        | |      d}|dj                   fdj                  D              z   S )Nr   r   z * c              3  T   K   | ]  }j                  |t                     ! y wr   )r   r   )r   r^  r   rn   s     rr   r   z1JuliaCodePrinter._print_MatMul.<locals>.<genexpr>  s#     K#TsJt$45Ks   %()as_coeff_mmulr   as_real_imagis_zeror   r	   r!  r   )rn   r   r   mr*   rP   rO   s   ``     rr   _print_MatMulzJuliaCodePrinter._print_MatMul  s    !!#1;;^^%FBzzbnn"A2q)"A2q)ejjKK
 
 	
rs   c           	     F   t        |t              r1| j                  |j                  d            }dj	                  |      S d}d}d}|D cg c]  }|j                  d       }}|D cg c]  t        t        fd|D                    ! }}|D cg c]  t        t        fd|D                    ! }}g }	d	}
t        |      D ]C  \  }d
v r|	j                         |
||   z  }
|	j                  ||
z         |
||   z  }
E |	S c c}w c c}w c c}w )z0Accepts a string of code or a list of code linesTr   z    )z
^function z^if ^elseif ^else$z^for )z^end$r  r  z 	c              3  6   K   | ]  }t        |        y wr   r   r   rP   lines     rr   r   z/JuliaCodePrinter.indent_code.<locals>.<genexpr>       B"VB-B   c              3  6   K   | ]  }t        |        y wr   r   r  s     rr   r   z/JuliaCodePrinter.indent_code.<locals>.<genexpr>  r  r  r   )r   ro  )
r   r-  r   
splitlinesr!  lstripintanyrt  r   )rn   code
code_linestab	inc_regex	dec_regexr  increasedecreaseprettylevelns         `     rr   r   zJuliaCodePrinter.indent_code  sC    dC ))$//$*?@J77:&&I	3	 156U#66 "&( B	BBC ( ( "&( B	BBC ( (   	!GAtz!d#Xa[ EMMCIt45Xa[ E	! ! 7((s   D,$D$D)5__name__
__module____qualname____doc__printmethodlanguage
_operatorsrc   __annotations__rf   rx   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r"  r%  _print_Tupler(  r+  r.  r7  rB  rI  rU  rX  rZ  r\  r_  ra  rc  rj  rm  ry  r  r   __classcell__)rq   s   @rr   rR   rR   0   s7    KH J #(	)~ 	 !# /!#3'B	'HZT9>(=55555I:F7
  L!:N3
E*I
'61-"""$H
$rs   rR   Nc                8    t        |      j                  | |      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])'
    )rR   doprint)r   	assign_toro   s      rr   
julia_coder    s    L H%--dI>>rs   c                .    t        t        | fi |       y)z~Prints the Julia representation of the given expression.

    See `julia_code` for the meaning of the optional arguments.
    N)printr  )r   ro   s     rr   print_julia_coder    s    
 
*T
&X
&'rs   r   )r  
__future__r   typingr   
sympy.corer   r   r   r   sympy.core.mulr	   sympy.core.numbersr
   sympy.printing.codeprinterr   sympy.printing.precedencer   r   rP   r   ri   rl   rR   r  r  rv   rs   rr   <module>r     sg   	 #  , , & + 2 < 
( 

Q{ QhF?R(rs   