
    \h[                        S r SSKJr  SSKJr  SSKJrJrJrJ	r	  SSK
Jr  SSKJr  SSKJr  SSKJrJr  SS	KJr  / S
QrSSSSSSSS.r " S S\5      rSS jrS rg)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conjhankelh1hankelh2imagreal)Absceiling	conjugatehankel1hankel2imrec            	        ^  \ rS rSr% SrSrSrSSSS.r\" \	R                  40 S	0 S
S
S.D6r
S\S'   0 4U 4S jjrS rS rS rS rS rS rS rS rS rS rS rU 4S jrS rU 4S jrU 4S jrU 4S jrU 4S jrS  rS! rS" r S# r!S$ r"S% r#\#r$S& r%S' r&S( r'S) r(S* r)S+ r*S, r+S- r,S. r-S/ r.S0 r/S1 r0S2 r1S3 r2S4 r3S5 r4S6 r5S7 r6S8r7U =r8$ )9JuliaCodePrinter0   z<
A printer to convert expressions to strings of Julia code.
_juliaJuliaz&&z||!)andornot   T)	precisionuser_functionscontractinlinezdict[str, Any]_default_settingsc                  > [         TU ]  U5        [        [        [        [        5      5      U l        U R
                  R                  [        [        5      5        UR                  S0 5      nU R
                  R                  U5        g )Nr[   )	super__init__dictzipknown_fcns_src1known_functionsupdateknown_fcns_src2get)selfsettings	userfuncs	__class__s      L/var/www/auris/envauris/lib/python3.13/site-packages/sympy/printing/julia.pyra   JuliaCodePrinter.__init__G   sb    "#C$IJ##D$9:LL!126	##I.    c                    US-  $ )N    )ri   ps     rm   _rate_index_position%JuliaCodePrinter._rate_index_positionO   s    s
ro   c                    SU-  $ )Nz%srr   )ri   
codestrings     rm   _get_statementJuliaCodePrinter._get_statementS   s    j  ro   c                $    SR                  U5      $ )Nz# {}format)ri   texts     rm   _get_commentJuliaCodePrinter._get_commentW   s    }}T""ro   c                $    SR                  X5      $ )Nzconst {} = {}r{   )ri   namevalues      rm   _declare_number_const&JuliaCodePrinter._declare_number_const[   s    %%d22ro   c                $    U R                  U5      $ N)indent_code)ri   liness     rm   _format_codeJuliaCodePrinter._format_code_   s    &&ro   c                L   ^ UR                   u  mnU4S j[        U5       5       $ )Nc              3  P   >#    U  H  n[        T5        H  o"U4v   M
     M     g 7fr   )range).0jirowss      rm   	<genexpr><JuliaCodePrinter._traverse_matrix_indices.<locals>.<genexpr>f   s     A1U4[A[s   #&)shaper   )ri   matcolsr   s      @rm   _traverse_matrix_indices)JuliaCodePrinter._traverse_matrix_indicesc   s    YY
dAdAAro   c           	         / n/ nU Hq  n[        U R                  UR                  UR                  S-   UR                  S-   /5      u  pVnUR                  SU< SU< SU< 35        UR                  S5        Ms     X#4$ )N   zfor  = :end)map_printlabellowerupperappend)ri   indices
open_linesclose_linesr   varstartstops           rm   _get_loop_opening_ending)JuliaCodePrinter._get_loop_opening_endingi   sw    
A"4;;WWaggk177Q;7 9C#udCDu%  &&ro   c           	     x   UR                   (       aY  UR                  (       aH  UR                  5       S   R                  (       a&  SU R	                  [
        R                  * U-  5      -  $ [        U5      nUR                  5       u  p4US:  a  [        U* U5      nSnOSn/ n/ n/ nU R                  S;  a  UR                  5       n	O[        R                  " U5      n	U	 GH  n
U
R                  (       Ga  U
R                  (       Ga   U
R                  R                   (       a  U
R                  R"                  (       a  U
R                  S:w  a1  UR%                  ['        U
R(                  U
R                  * SS95        M  [+        U
R,                  S   R,                  5      S	:w  a0  [/        U
R(                  [        5      (       a  UR%                  U
5        UR%                  ['        U
R(                  U
R                  * 5      5        GM(  U
R                   (       aJ  U
[
        R0                  La7  U
R2                  S	:X  a'  UR%                  [5        U
R6                  5      5        GM  UR%                  U
5        GM     U=(       d    [
        R8                  /nU Vs/ s H  oR;                  X5      PM     nnU Vs/ s H  oR;                  X5      PM     nnU HP  n
U
R(                  U;   d  M  S
XR=                  U
R(                  5         -  XR=                  U
R(                  5      '   MR     S nU(       d
  X^" Xl5      -   $ [+        U5      S	:X  a0  US   R                   (       a  SOSnX^" Xl5      -   < SU< SUS   < 3$ [?        S U 5       5      (       a  SOSnX^" Xl5      -   < SU< SU" X}5      < S3$ s  snf s  snf )Nr   z%sim- )oldnoneF)evaluater   (%s)c                    US   n[        S[        U 5      5       H,  nXS-
     R                  (       a  SOSnU< SU< SX   < 3nM.     U$ )Nr   r   *z.* )r   len	is_number)aa_strrr   mulsyms        rm   multjoin-JuliaCodePrinter._print_Mul.<locals>.multjoin   sJ    aA1c!f% !A# 0 0d"#VUX6 & Hro   /./r   c              3  8   #    U  H  oR                   v   M     g 7fr   r   )r   bis     rm   r   .JuliaCodePrinter._print_Mul.<locals>.<genexpr>   s     9qq   z ()) 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Infinityrs   r   qOneparenthesizeindexall)ri   exprpreccer)   r   b	pow_parenr   itemxr   b_strr   divsyms                   rm   
_print_MulJuliaCodePrinter._print_Mulu   s   NNt00!!#A&11DKK(8(=>>> $  "q5r1%DDD	::_,**,D ==&D D###8L8L,,88r>HHSTXXIFG499Q<,,-2z$))S7Q7Q!((.HHSTXXI67!!d!**&<1
 $&&)*! $ L!%%567Q""1+Q7567Q""1+Q7 DyyA~,2U77499;M5N,Nggdii() 
	 (1,,,Vq[aDNNSF!%hq&8!8&%(KK9q999StF#'(1*<#<fhqFXYY1 87s   N26N7c                    U R                  UR                  5      nU R                  UR                  5      nUR                  nSR	                  X$U5      $ )Nz{} {} {})r   lhsrhsrel_opr|   )ri   r   lhs_coderhs_codeops        rm   _print_Relational"JuliaCodePrinter._print_Relational   sB    ;;txx(;;txx([[  x88ro   c                   [        S UR                   5       5      (       a  SOSn[        U5      n[        UR                  S5      (       a  SU R                  UR                  5      -  $ UR                  (       a  [        UR                  S5      (       aC  UR                  R                  (       a  SOSnS	U< S
U R                  UR                  5      < S3$ [        UR                  S5      (       aC  UR                  R                  (       a  SOSnS	U< SU R                  UR                  U5      < 3$ U R                  UR                  U5      < SU< SU R                  UR                  U5      < 3$ )Nc              3  8   #    U  H  oR                   v   M     g 7fr   r   )r   r   s     rm   r   .JuliaCodePrinter._print_Pow.<locals>.<genexpr>   s     >Iq{{Ir   ^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   )ri   r   	powsymbolPRECsyms        rm   
_print_Pow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<> 	>ro   c                    [        U5      nU R                  UR                  U5      < SU R                  UR                  U5      < 3$ )Nz ^ )r   r   r   r,   ri   r   r   s      rm   _print_MatPowJuliaCodePrinter._print_MatPow   s>    $ --dii>++DHHd;= 	=ro   c                L   > U R                   S   (       a  g[        TU ]	  U5      $ )Nr]   pi	_settingsr`   _print_NumberSymbolri   r   rl   s     rm   	_print_PiJuliaCodePrinter._print_Pi   s"    >>(#7.t44ro   c                    g)NrN   rr   ri   r   s     rm   _print_ImaginaryUnit%JuliaCodePrinter._print_ImaginaryUnit   s    ro   c                L   > U R                   S   (       a  g[        TU ]	  U5      $ )Nr]   r   r   r  s     rm   _print_Exp1JuliaCodePrinter._print_Exp1   s"    >>(#7.t44ro   c                L   > U R                   S   (       a  g[        TU ]	  U5      $ )Nr]   
eulergammar   r  s     rm   _print_EulerGamma"JuliaCodePrinter._print_EulerGamma   s"    >>(#7.t44ro   c                L   > U R                   S   (       a  g[        TU ]	  U5      $ )Nr]   catalanr   r  s     rm   _print_CatalanJuliaCodePrinter._print_Catalan   s"    >>(#7.t44ro   c                L   > U R                   S   (       a  g[        TU ]	  U5      $ )Nr]   goldenr   r  s     rm   _print_GoldenRatio#JuliaCodePrinter._print_GoldenRatio   s"    >>(#7.t44ro   c                   SSK Jn  SSKJn  SSKJn  UR                  nUR                  nU R                  S   (       d{  [        UR                  U5      (       a`  / n/ nUR                   H-  u  pUR                  U" XY5      5        UR                  U
5        M/     U" [        Xx5      6 nU R                  U5      $ U R                  S   (       a=  UR                  U5      (       d  UR                  U5      (       a  U R                  Xe5      $ U R                  U5      nU R                  U5      nU R!                  U< SU< 35      $ )Nr   )
Assignment)	Piecewise)IndexedBaser]   r\   r   )sympy.codegen.astr  $sympy.functions.elementary.piecewiser  sympy.tensor.indexedr  r   r   r   r   r   r   rc   r   has_doprint_loopsrx   )ri   r   r  r  r  r   r   expressions
conditionsr   r   tempr   r   s                 rm   _print_Assignment"JuliaCodePrinter._print_Assignment  s   0B4hhhh~~h'Jtxx,K,K KJ(("":c#56!!!$ # c+:;D;;t$$>>*%377;+?+?$$ &&s00{{3'H{{3'H&&Hh'GHHro   c                    g)NInfrr   r  s     rm   _print_Infinity JuliaCodePrinter._print_Infinity#      ro   c                    g)Nz-Infrr   r  s     rm   _print_NegativeInfinity(JuliaCodePrinter._print_NegativeInfinity'      ro   c                    g)NNaNrr   r  s     rm   
_print_NaNJuliaCodePrinter._print_NaN+  r*  ro   c                F   ^  SSR                  U 4S jU 5       5      -   S-   $ )NzAny[, c              3  F   >#    U  H  nTR                  U5      v   M     g 7fr   )r   )r   r   ri   s     rm   r   /JuliaCodePrinter._print_list.<locals>.<genexpr>0  s     !?$Q$++a..$s   !])joinr  s   ` rm   _print_listJuliaCodePrinter._print_list/  s"    		!?$!???#EEro   c                x    [        U5      S:X  a  SU R                  US   5      -  $ SU R                  US5      -  $ )Nr   z(%s,)r   r   r4  )r   r   	stringifyr  s     rm   _print_tupleJuliaCodePrinter._print_tuple3  s;    t9>T[[a111DNN4666ro   c                    g)Ntruerr   r  s     rm   _print_BooleanTrue#JuliaCodePrinter._print_BooleanTrue;  r.  ro   c                    g)Nfalserr   r  s     rm   _print_BooleanFalse$JuliaCodePrinter._print_BooleanFalse?  s    ro   c                4    [        U5      R                  5       $ r   )strr   r  s     rm   _print_boolJuliaCodePrinter._print_boolC  s    4y  ro   c           	        [         R                  UR                  ;   a  SUR                  < SUR                  < S3$ UR                  UR                  4S:X  a  SUS   -  $ UR                  S:X  a  SUR                  U SSS	S
9-  $ UR                  S:X  a3  SSR                  U Vs/ s H  o R                  U5      PM     sn5      -  $ SUR                  U SSSS	S9-  $ s  snf )Nzzeros(r4  r   )r   r   z[%s])r   r   r   r   r   )rowstartrowendcolsepz;
)rL  rM  rowseprN  )r   Zeror   r   r   tabler8  r   )ri   Ar   s      rm   _print_MatrixBase"JuliaCodePrinter._print_MatrixBaseK  s    66QWW&'ffaff55ffaff'AdG##VVq[AGGD2bGMMMVVq[DIIq&Aq!{{1~q&ABBBr"',S   : : 	: 'Bs   'C 
c                   SSK Jn  UR                  5       nU" U Vs/ s H
  oDS   S-   PM     sn5      nU" U Vs/ s H
  oDS   S-   PM     sn5      nU" U Vs/ s H  oDS   PM	     sn5      nSU R                  U5      < SU R                  U5      < SU R                  U5      < SUR                  < SUR
                  < S3$ s  snf s  snf s  snf )Nr   )Matrixr      zsparse(r4  r   )sympy.matricesrV  col_listr   r   r   )ri   rR  rV  LkIJAIJs           rm   _print_SparseRepMatrix'JuliaCodePrinter._print_SparseRepMatrixZ  s    )JJLa(aaD1Ha()a(aaD1Ha()A&AqdA&'/3{{1~t{{1~,0KK,<affaffN 	N )(&s   CCCc                    U R                  UR                  [        S   SS9SUR                  S-   < SUR                  S-   < S3-   $ )NAtomT)strict[r   ,r7  )r   parentr   r   r   r  s     rm   _print_MatrixElement%JuliaCodePrinter._print_MatrixElemente  sB      j.@ N66A:tvvz23 	3ro   c                  ^  U 4S jnT R                  UR                  5      S-   U" UR                  UR                  R                  S   5      -   S-   U" UR                  UR                  R                  S   5      -   S-   $ )Nc                  > U S   S-   nU S   nU S   nTR                  U5      nX1:X  a  SOTR                  U5      nUS:X  a  US:X  a  X1:X  a  gX#:X  a  U$ US-   U-   $ SR                  UTR                  U5      U45      $ )Nr   r   rW  r   r   )r   r8  )r   limlhsteplstrhstrri   s          rm   strslice5JuliaCodePrinter._print_MatrixSlice.<locals>.strslicek  s    !qA!AQ4D;;q>DH5$++a.Dqy6ah6K#:,,xxt{{4'8$ ?@@ro   rd  r   re  r   r7  )r   rf  rowslicer   colslice)ri   r   rq  s   `  rm   _print_MatrixSlice#JuliaCodePrinter._print_MatrixSlicej  s|    	A DKK(3.(9(9!(<=>@CD(9(9!(<=>@CD 	Ero   c                    UR                    Vs/ s H  o R                  U5      PM     nnU R                  UR                  R                  5      < SSR	                  U5      < S3$ s  snf )Nrd  re  r7  )r   r   r   r   r8  )ri   r   r   indss       rm   _print_IndexedJuliaCodePrinter._print_Indexed  sI    )-7AQ7;;tyy7$HH 8s   A'c                D    SU R                  UR                  S   5      -  $ )Nzeye(%s)r   )r   r   r  s     rm   _print_Identity JuliaCodePrinter._print_Identity  s    4;;tzz!}555ro   c                    SR                  UR                   Vs/ s H  nU R                  U[        U5      5      PM      sn5      $ s  snf )Nz .* )r8  r   r   r   )ri   r   args      rm   _print_HadamardProduct'JuliaCodePrinter._print_HadamardProduct  sI    {{%)YY0%.c !--c:d3CD%.0 1 	1 0s   %Ac                    [        U5      nSR                  U R                  UR                  U5      U R                  UR                  U5      /5      $ )Nz.**)r   r8  r   r   r,   r   s      rm   _print_HadamardPower%JuliaCodePrinter._print_HadamardPower  sJ    $zzdii.dhh-  	ro   c                    UR                   S:X  a  [        UR                  5      $ UR                  < SUR                   < 3$ )Nr   z // )r   rH  rs   r  s     rm   _print_Rational JuliaCodePrinter._print_Rational  s.    66Q;tvv;!VVTVV,,ro   c                    SSK JnJn  UR                  nU" [        R
                  SU-  -  5      U" UR                  [        R                  -   U5      -  nU R                  U5      $ )Nr   )r.   r<   rW  )	sympy.functionsr.   r<   argumentr   Pir   Halfr   )ri   r   r.   r<   r   expr2s         rm   	_print_jnJuliaCodePrinter._print_jn  L    1MMQTT1Q3Z aff)<a!@@{{5!!ro   c                    SSK JnJn  UR                  nU" [        R
                  SU-  -  5      U" UR                  [        R                  -   U5      -  nU R                  U5      $ )Nr   )r.   r=   rW  )	r  r.   r=   r  r   r  r   r  r   )ri   r   r.   r=   r   r  s         rm   	_print_ynJuliaCodePrinter._print_yn  r  ro   c                ~    SR                  U R                  UR                  S   [        R                  -  5      5      $ )Nzsinc({})r   )r|   r   r   r   r  r  s     rm   _print_sincJuliaCodePrinter._print_sinc  s-      TYYq\ADD-@!ABBro   c           
        UR                   S   R                  S:w  a  [        S5      e/ nU R                  S   (       a  UR                   S S  VVs/ s H5  u  p4SR	                  U R                  U5      U R                  U5      5      PM7     nnnSU R                  UR                   S   R                  5      -  nSR                  U5      U-   nSU-   S	-   $ [        UR                   5       H  u  nu  p4US
:X  a$  UR                  SU R                  U5      -  5        OWU[        UR                   5      S-
  :X  a  US:X  a  UR                  S5        O#UR                  SU R                  U5      -  5        U R                  U5      n	UR                  U	5        U[        UR                   5      S-
  :X  d  M  UR                  S5        M     SR                  U5      $ s  snnf )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.r]   z({}) ? ({}) :z (%s)
(r   r   zif (%s)r   elsezelseif (%s)r   )r   cond
ValueErrorr   r|   r   r   r8  	enumerater   r   )
ri   r   r   r   r   ecpairselastpwr   code0s
             rm   _print_Piecewise!JuliaCodePrinter._print_Piecewise  s   99R=%  / 0 0
 >>(# $(99Sb>3#141 '--AA8#1  3 dkk$))B-*<*<==E7#e+B 8c>!&tyy1	6A6LLT[[^!;<#dii.1,,dLL(LLQ!?@AU#DII**LL' 2 99U##)3s   <Gc                  ^ ^ TR                  5       u  p#SnUR                  (       au  UR                  5       u  pVUR                  (       a!  UR                  (       a  [        U* U5      mSnO1UR                  (       a   UR                  (       a  [        U* U5      mSnUSR                  UU 4S jTR                   5       5      -   $ )Nr   r   z * c              3  Z   >#    U  H   nTR                  U[        T5      5      v   M"     g 7fr   )r   r   )r   r  r   ri   s     rm   r   1JuliaCodePrinter._print_MatMul.<locals>.<genexpr>  s&     K#TsJt$455s   (+)as_coeff_mmulr   as_real_imagis_zeror   r	   r8  r   )ri   r   r   mr)   rO   rN   s   ``     rm   _print_MatMulJuliaCodePrinter._print_MatMul  s    !!#;;^^%FBzzbnn"A2q)"A2q)ejjKK
 
 	
ro   c           	     l  ^ [        U[        5      (       a1  U R                  UR                  S5      5      nSR	                  U5      $ SnSnSnU Vs/ s H  ofR                  S5      PM     nnU V^s/ s H!  m[        [        U4S jU 5       5      5      PM#     nnU V^s/ s H!  m[        [        U4S jU 5       5      5      PM#     nn/ n	S	n
[        U5       HF  u  nmTS
;   a  U	R                  T5        M  XU   -  n
U	R                  X:-  < T< 35        XU   -  n
MH     U	$ s  snf s  snf s  snf )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  <   >#    U  H  n[        UT5      v   M     g 7fr   r   r   rO   lines     rm   r   /JuliaCodePrinter.indent_code.<locals>.<genexpr>       B	"VB--	   c              3  <   >#    U  H  n[        UT5      v   M     g 7fr   r   r  s     rm   r   r    r  r  r   )r   r  )
r   rH  r   
splitlinesr8  lstripintanyr  r   )ri   code
code_linestab	inc_regex	dec_regexr  increasedecreaseprettylevelns         `     rm   r   JuliaCodePrinter.indent_code  s@    dC  ))$//$*?@J77:&&I	3	 156U#6 "&(!% B	BBC!% 	 ( "&(!% B	BBC!% 	 (  GAtz!d#a[ EMMCIt45a[ E ' ! 7((s   D'3(D,"(D1)re   )9__name__
__module____qualname____firstlineno____doc__printmethodlanguage
_operatorsrb   r   r^   __annotations__ra   rt   rx   r~   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r$  r(  r,  r1  r9  r=  _print_TuplerA  rE  rI  rS  r_  rg  ru  ry  r|  r  r  r  r  r  r  r  r  r   __static_attributes____classcell__)rl   s   @rm   rQ   rQ   0   sG    KH J )-[-J-J )	O )~  !# /!#3'B	'HZT9>(=55555I:F7
  L!:N3
E*I61-""C"$H
$ ro   rQ   Nc                6    [        U5      R                  X5      $ )am  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])'
)rQ   doprint)r   	assign_torj   s      rm   
julia_coder    s    L H%--d>>ro   c                .    [        [        U 40 UD65        g)zvPrints the Julia representation of the given expression.

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