+
    i[                       R t ^ RIHt ^ RIHt ^ RIHtHtHtH	t	 ^ RI
Ht ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt . R	NR
NRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNR NR!NR"NR#NR$NR%NR&NR'NR(NR)NR*NR+NR,NR-NR.NR/NR0NR1NR2NR3NR4NR5NR6NR7NR8NR9NR:NtR;R<R=R>R?R@RARBRCRDRERFRGRH/t ! RI RJ]4      tRNRL ltRM tRK# )Oa  
Julia code printer

The `JuliaCodePrinter` converts SymPy expressions into Julia expressions.

A complete code generator, which uses `julia_code` extensively, can be found
in `sympy.utilities.codegen`.  The `codegen` module can be used to generate
complete source code files.

)annotations)Any)MulPowSRational)_keep_coeff)equal_valued)CodePrinter)
precedence
PRECEDENCEsearchsincos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absceilingceil	conjugateconjhankel1hankelh1hankel2hankelh2imimagrerealc                    a  ] tR t^0t$ RtRtRtRRRRRR	/t]! ]	P                  3/ R
^R/ RRRR/B t
R]R&   / 3V 3R lltR tR tR tR tR tR tR tR tR tR tR tV 3R ltR tV 3R ltV 3R  ltV 3R! ltV 3R" ltR# tR$ tR% t R& t!R' t"R( t#]#t$R) t%R* t&R+ t'R, t(R- t)R. t*R/ t+R0 t,R1 t-R2 t.R3 t/R4 t0R5 t1R6 t2R7 t3R8 t4R9 t5R: t6R;t7V ;t8# )<JuliaCodePrinterz<
A printer to convert expressions to strings of Julia code.
_juliaJuliaandz&&orz||not!	precisionuser_functionscontractTinlinezdict[str, Any]_default_settingsc                	  < \         SV `  V4       \        \        \        \        4      4      V n        V P
                  P                  \        \        4      4       VP                  R / 4      pV P
                  P                  V4       R# )rX   N)	super__init__dictzipknown_fcns_src1known_functionsupdateknown_fcns_src2get)selfsettings	userfuncs	__class__s   && t/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/printing/julia.pyr^   JuliaCodePrinter.__init__G   sb    "#C$IJ##D$9:LL!126	##I.    c                	    V^,          # )    )rf   ps   &&rj   _rate_index_position%JuliaCodePrinter._rate_index_positionO   s    s
rl   c                	    R V,          # )z%sro   )rf   
codestrings   &&rj   _get_statementJuliaCodePrinter._get_statementS   s    j  rl   c                	$    R P                  V4      # )z# {}format)rf   texts   &&rj   _get_commentJuliaCodePrinter._get_commentW   s    }}T""rl   c                	$    R P                  W4      # )zconst {} = {}rx   )rf   namevalues   &&&rj   _declare_number_const&JuliaCodePrinter._declare_number_const[   s    %%d22rl   c                	$    V P                  V4      # N)indent_code)rf   liness   &&rj   _format_codeJuliaCodePrinter._format_code_   s    &&rl   c                	L   a VP                   w  opV3R  l\        V4       4       # )c              3  N   <"   T F  p\        S4       F  q"V3x  K
  	  K  	  R # 5ir   )range).0jirowss   &  rj   	<genexpr><JuliaCodePrinter._traverse_matrix_indices.<locals>.<genexpr>f   s     A1U4[A[s   "%)shaper   )rf   matcolsr   s   && @rj   _traverse_matrix_indices)JuliaCodePrinter._traverse_matrix_indicesc   s    YY
dAdAArl   c           	     	   . p. pV Fy  p\        V P                  VP                  VP                  ^,           VP                  ^,           .4      w  rVpVP                  RV: RV: RV: 24       VP                  R4       K{  	  W#3# )   zfor  = :end)map_printlabellowerupperappend)rf   indices
open_linesclose_linesr   varstartstops   &&      rj   _get_loop_opening_ending)JuliaCodePrinter._get_loop_opening_endingi   sw    
A"4;;WWaggk177Q;7 9C#udCDu%  &&rl   c           	     	@   VP                   '       dh   VP                  '       dV   VP                  4       ^ ,          P                  '       d/   RV P	                  \
        P                  ) V,          4      ,          # \        V4      pVP                  4       w  r4V^ 8  d   \        V) V4      pRpMRp. p. p. pV P                  R9  d   VP                  4       p	M\        P                  ! V4      p	V	 EF  p
V
P                  '       Ed    V
P                  '       Ed   V
P                  P                   '       d   V
P                  P"                  '       d   V
P                  R8w  d5   VP%                  \'        V
P(                  V
P                  ) RR7      4       K  \+        V
P,                  ^ ,          P,                  4      ^8w  d2   \/        V
P(                  \        4      '       d   VP%                  V
4       VP%                  \'        V
P(                  V
P                  ) 4      4       EK6  V
P                   '       dM   V
\
        P0                  Jd9   V
P2                  ^8X  d(   VP%                  \5        V
P6                  4      4       EK  VP%                  V
4       EK  	  T;'       g    \
        P8                  .pV Uu. uF  qP;                  W4      NK  	  ppV Uu. uF  qP;                  W4      NK  	  ppV FY  p
V
P(                  V9   g   K  RWP=                  V
P(                  4      ,          ,          WP=                  V
P(                  4      &   K[  	  R pV'       g   W^! Wl4      ,           # \+        V4      ^8X  d>   V^ ,          P                   '       d   RMR	pW^! Wl4      ,           : R
V: R
V^ ,          : 2# \>        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       d   RMR	pW^! Wl4      ,           : R
V: RV! W}4      : R2# u upi u upi )    z%sim- F)evaluate(%s)c                    V^ ,          p\        ^\        V 4      4       F9  pW^,
          ,          P                  '       d   RMRpV: RV: RW,          : 2pK;  	  V# )r   *z.* )r   len	is_number)aa_strrr   mulsyms   &&   rj   multjoin-JuliaCodePrinter._print_Mul.<locals>.multjoin   sM    aA1c!f% !A# 0 0 0d"#VUX6 & Hrl   /./r   c              3  8   "   T F  qP                   x  K  	  R # 5ir   r   )r   bis   & rj   r   .JuliaCodePrinter._print_Mul.<locals>.<genexpr>   s     9qq   Tz ())oldnone) 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Infinityrp   r   qOneparenthesizeindexall)rf   exprpreccer(   r   b	pow_parenr   itemxr   b_strr   divsyms   &&              rj   
_print_MulJuliaCodePrinter._print_Mulu   s   NNNt000!!#A&111DKK(8(=>>> $  "q5r1%DDD	::_,**,D ==&D D###8L8L8L,,,88r>HHSTXXIFG499Q<,,-2z$))S7Q7Q!((.HHSTXXI67!!!d!**&<1
 $&&)*! $ LL!%%567Q""1+Q7567Q""1+Q7 DyyA~,2U77499;M5N,Nggdii() 
	 (1,,,Vq[aDNNNSF!%hq&8!8!8&%(KKC9q9CCC9q999StF#'(1*<#<#<fhqFXYY1 87s   9PPc                	    V P                  VP                  4      pV P                  VP                  4      pVP                  pR P	                  W$V4      # )z{} {} {})r   lhsrhsrel_opry   )rf   r   lhs_coderhs_codeops   &&   rj   _print_Relational"JuliaCodePrinter._print_Relational   sB    ;;txx(;;txx([[  x88rl   c                	^   \         ;QJ d&    R  VP                   4       F  '       d   K   RM	  RM! R  VP                   4       4      '       d   RMRp\        V4      p\        VP                  R4      '       d#   RV P                  VP                  4      ,          # VP                  '       d   \        VP                  R4      '       dE   VP                  P                  '       d   RMRpR	V: R
V P                  VP                  4      : R2# \        VP                  R4      '       dE   VP                  P                  '       d   RMRpR	V: RV P                  VP                  V4      : 2# V P                  VP                  V4      : RV: RV P                  VP                  V4      : 2# )c              3  8   "   T F  qP                   x  K  	  R # 5ir   r   )r   r   s   & rj   r   .JuliaCodePrinter._print_Pow.<locals>.<genexpr>   s     >Iq{{Ir   FT^z.^g      ?zsqrt(%s)r   r   z1 z sqrt(r   r   g      r   )
r   r   r   r	   r+   r   r   r   r   r   )rf   r   	powsymbolPRECsyms   &&   rj   
_print_PowJuliaCodePrinter._print_Pow   s&   3>DII>333>DII>>>CD	$#&&DII 666DHHd++!YY000cd*-t{{499/EFFDHHb))!YY000cd%($*;*;DIIt*LMM!..tyy$?,,TXXt<> 	>rl   c                	    \        V4      pV P                  VP                  V4      : R V P                  VP                  V4      : 2# )z ^ )r   r   r   r+   rf   r   r   s   && rj   _print_MatPowJuliaCodePrinter._print_MatPow   s>    $ --dii>++DHHd;= 	=rl   c                	X   < V P                   R ,          '       d   R# \        SV `	  V4      # )rZ   pi	_settingsr]   _print_NumberSymbolrf   r   ri   s   &&rj   	_print_PiJuliaCodePrinter._print_Pi   s%    >>(##7.t44rl   c                	    R # )rK   ro   rf   r   s   &&rj   _print_ImaginaryUnit%JuliaCodePrinter._print_ImaginaryUnit   s    rl   c                	X   < V P                   R ,          '       d   R# \        SV `	  V4      # )rZ   r   r   r   s   &&rj   _print_Exp1JuliaCodePrinter._print_Exp1   s%    >>(##7.t44rl   c                	X   < V P                   R ,          '       d   R# \        SV `	  V4      # )rZ   
eulergammar   r   s   &&rj   _print_EulerGamma"JuliaCodePrinter._print_EulerGamma   s%    >>(##7.t44rl   c                	X   < V P                   R ,          '       d   R# \        SV `	  V4      # )rZ   catalanr   r   s   &&rj   _print_CatalanJuliaCodePrinter._print_Catalan   s%    >>(##7.t44rl   c                	X   < V P                   R ,          '       d   R# \        SV `	  V4      # )rZ   goldenr   r   s   &&rj   _print_GoldenRatio#JuliaCodePrinter._print_GoldenRatio   s%    >>(##7.t44rl   c                	   ^ RI Hp ^ RIHp ^ RIHp VP                  pVP                  pV P                  R,          '       g~   \        VP                  V4      '       db   . p. pVP                   F-  w  rVP                  V! WY4      4       VP                  V
4       K/  	  V! \        Wx4      !  pV P                  V4      # V P                  R,          '       d@   VP                  V4      '       g   VP                  V4      '       d   V P                  We4      # V P                  V4      pV P                  V4      pV P!                  V: RV: 24      # )r   )
Assignment)	Piecewise)IndexedBaserZ   rY   r   )sympy.codegen.astr  $sympy.functions.elementary.piecewiser  sympy.tensor.indexedr  r   r   r   r   r   r   r`   r   has_doprint_loopsru   )rf   r   r  r  r  r   r   expressions
conditionsr   r   tempr   r   s   &&            rj   _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Hrl   c                	    R # )Infro   r  s   &&rj   _print_Infinity JuliaCodePrinter._print_Infinity#      rl   c                	    R # )z-Infro   r  s   &&rj   _print_NegativeInfinity(JuliaCodePrinter._print_NegativeInfinity'      rl   c                	    R # )NaNro   r  s   &&rj   
_print_NaNJuliaCodePrinter._print_NaN+  r(  rl   c                	V   a  R RP                  V 3R lV 4       4      ,           R,           # )zAny[, c              3  F   <"   T F  pSP                  V4      x  K  	  R # 5ir   )r   )r   r   rf   s   & rj   r   /JuliaCodePrinter._print_list.<locals>.<genexpr>0  s     !?$Q$++a..$s   !])joinr  s   f&rj   _print_listJuliaCodePrinter._print_list/  s"    		!?$!???#EErl   c                	    \        V4      ^8X  d    RV P                  V^ ,          4      ,          # RV P                  VR4      ,          # )r   z(%s,)r   r2  )r   r   	stringifyr  s   &&rj   _print_tupleJuliaCodePrinter._print_tuple3  s;    t9>T[[a111DNN4666rl   c                	    R # )truero   r  s   &&rj   _print_BooleanTrue#JuliaCodePrinter._print_BooleanTrue;  r,  rl   c                	    R # )falsero   r  s   &&rj   _print_BooleanFalse$JuliaCodePrinter._print_BooleanFalse?  s    rl   c                	4    \        V4      P                  4       # r   )strr   r  s   &&rj   _print_boolJuliaCodePrinter._print_boolC  s    4y  rl   c           	     	   \         P                  VP                  9   d    R VP                  : RVP                  : R2# VP                  VP                  3R	8X  d   RVR
,          ,          # VP                  ^8X  d   RVP                  V RRRR7      ,          # VP                  ^8X  d7   RRP                  V Uu. uF  q P                  V4      NK  	  up4      ,          # RVP                  V RRRRR7      ,          # u upi )zzeros(r2  r   z[%s]r   r   )rowstartrowendcolsepz;
)rJ  rK  rowseprL  )r   r   )r   r   )r   Zeror   r   r   tabler6  r   )rf   Ar   s   && rj   _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                	   ^ RI Hp VP                  4       pT! V Uu. uF  qD^ ,          ^,           NK  	  up4      pT! V Uu. uF  qD^,          ^,           NK  	  up4      pT! V Uu. uF  qD^,          NK  	  up4      pRV P                  V4      : RV P                  V4      : RV P                  V4      : RVP                  : RVP
                  : R2# u upi u upi u upi )r   )Matrixzsparse(r2  r   )sympy.matricesrT  col_listr   r   r   )rf   rP  rT  LkIJAIJs   &&      rj   _print_SparseRepMatrix'JuliaCodePrinter._print_SparseRepMatrixZ  s    )JJLa(aaD1HHa()a(aaD1HHa()A&AqddA&'/3{{1~t{{1~,0KK,<affaffN 	N )(&s   CC'C!c                	    V P                  VP                  \        R ,          RR7      RVP                  ^,           : RVP                  ^,           : R2,           # )AtomT)strict[,r5  )r   parentr   r   r   r  s   &&rj   _print_MatrixElement%JuliaCodePrinter._print_MatrixElemente  sF      j.@ N66A::tvvzz23 	3rl   c                	<  a  V 3R  lpS P                  VP                  4      R,           V! VP                  VP                  P                  ^ ,          4      ,           R,           V! VP                  VP                  P                  ^,          4      ,           R,           # )c                >  < V ^ ,          ^,           pV ^,          pV ^,          pSP                  V4      pW18X  d   RMSP                  V4      pV^8X  d(   V^8X  d	   W18X  d   R# W#8X  d   V# VR,           V,           # RP                  VSP                  V4      V34      # )r   r   r   )r   r6  )r   limlhsteplstrhstrrf   s   &&     rj   strslice5JuliaCodePrinter._print_MatrixSlice.<locals>.strslicek  s    !qA!AQ4D;;q>DH5$++a.Dqy6ah6K#:,,xxt{{4'8$ ?@@rl   ra  rb  r5  )r   rc  rowslicer   colslice)rf   r   rn  s   f& rj   _print_MatrixSlice#JuliaCodePrinter._print_MatrixSlicej  s|    	A DKK(3.(9(9!(<=>@CD(9(9!(<=>@CD 	Erl   c                	    VP                    Uu. uF  q P                  V4      NK  	  ppV P                  VP                  P                  4      : R RP	                  V4      : R2# u upi )ra  rb  r5  )r   r   r   r   r6  )rf   r   r   indss   &&  rj   _print_IndexedJuliaCodePrinter._print_Indexed  sI    )-7AQ7;;tyy7$HH 8s   A&c                	T    R V P                  VP                  ^ ,          4      ,          # )zeye(%s))r   r   r  s   &&rj   _print_Identity JuliaCodePrinter._print_Identity  s    4;;tzz!}555rl   c                	    R P                  VP                   Uu. uF  pV P                  V\        V4      4      NK   	  up4      # u upi )z .* )r6  r   r   r   )rf   r   args   && rj   _print_HadamardProduct'JuliaCodePrinter._print_HadamardProduct  sI    {{%)YY0%.c !--c:d3CD%.0 1 	1 0s   $Ac                	    \        V4      pR P                  V P                  VP                  V4      V P                  VP                  V4      .4      # )z.**)r   r6  r   r   r+   r   s   && rj   _print_HadamardPower%JuliaCodePrinter._print_HadamardPower  sJ    $zzdii.dhh-  	rl   c                	    VP                   ^8X  d   \        VP                  4      # VP                  : RVP                   : 2# )r   z // )r   rF  rp   r  s   &&rj   _print_Rational JuliaCodePrinter._print_Rational  s.    66Q;tvv;!VVTVV,,rl   c                	    ^ RI HpHp VP                  pV! \        P
                  ^V,          ,          4      V! VP                  \        P                  ,           V4      ,          pV P                  V4      # )r   )r-   r;   )	sympy.functionsr-   r;   argumentr   Pir   Halfr   )rf   r   r-   r;   r   expr2s   &&    rj   	_print_jnJuliaCodePrinter._print_jn  L    1MMQTT1Q3Z aff)<a!@@{{5!!rl   c                	    ^ RI HpHp VP                  pV! \        P
                  ^V,          ,          4      V! VP                  \        P                  ,           V4      ,          pV P                  V4      # )r   )r-   r<   )	r  r-   r<   r  r   r  r   r  r   )rf   r   r-   r<   r   r  s   &&    rj   	_print_ynJuliaCodePrinter._print_yn  r  rl   c                	    R P                  V P                  VP                  ^ ,          \        P                  ,          4      4      # )zsinc({}))ry   r   r   r   r  r  s   &&rj   _print_sincJuliaCodePrinter._print_sinc  s-      TYYq\ADD-@!ABBrl   c           
     	$   VP                   R,          P                  R8w  d   \        R4      h. pV P                  R,          '       d   VP                   RR  UUu. uF5  w  r4RP	                  V P                  V4      V P                  V4      4      NK7  	  pppRV P                  VP                   R,          P                  4      ,          pRP                  V4      V,           pRV,           R	,           # \        VP                   4       F  w  pw  r4V^ 8X  d)   VP                  R
V P                  V4      ,          4       MaV\        VP                   4      ^,
          8X  d   VR8X  d   VP                  R4       M'VP                  RV P                  V4      ,          4       V P                  V4      p	VP                  V	4       V\        VP                   4      ^,
          8X  g   K  VP                  R4       K  	  RP                  V4      # u uppi )r   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.rZ   Nz({}) ? ({}) :z (%s)
(r   zif (%s)elsezelseif (%s)r   r   )r   cond
ValueErrorr   ry   r   r   r6  	enumerater   r   )
rf   r   r   r   r   ecpairselastpwr   code0s
   &&        rj   _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   ;Hc                	  a a SP                  4       w  r#R pVP                  '       dz   VP                  4       w  rVVP                  '       d#   VP                  '       d   \        V) V4      oRpM3VP                  '       d"   VP                  '       d   \        V) V4      oRpVRP                  VV 3R lSP                   4       4      ,           # )r   r   z * c              3  Z   <"   T F   pSP                  V\        S4      4      x  K"  	  R # 5ir   )r   r   )r   r|  r   rf   s   & rj   r   1JuliaCodePrinter._print_MatMul.<locals>.<genexpr>  s&     K#TsJt$455s   (+)as_coeff_mmulr   as_real_imagis_zeror   r   r6  r   )rf   r   r   mr(   rM   rK   s   ff     rj   _print_MatMulJuliaCodePrinter._print_MatMul  s    !!#;;;^^%FBzzzbnnn"A2q)"A2q)ejjKK
 
 	
rl   c           	     &  a \        V\        4      '       d2   V P                  VP                  R4      4      pRP	                  V4      # RpRpR	pV Uu. uF  qfP                  R4      NK  	  ppV Uau. uFF  o\        \        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      4      NKH  	  ppV Uau. uFF  o\        \        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      4      NKH  	  pp. p	^ p
\        V4       F[  w  poSR
9   d   V	P                  S4       K   WV,          ,          p
V	P                  W:,          : S: 24       WV,          ,          p
K]  	  V	# u upi u upi u upi )z0Accepts a string of code or a list of code linesTr   z    z 	c              3  <   <"   T F  p\        VS4      x  K  	  R # 5ir   r   r   rM   lines   & rj   r   /JuliaCodePrinter.indent_code.<locals>.<genexpr>       B	"VB--	   Fc              3  <   <"   T F  p\        VS4      x  K  	  R # 5ir   r   r  s   & rj   r   r    r  r  )z
^function z^if ^elseif ^else$z^for )z^end$r  r  )r   r  )
r   rF  r   
splitlinesr6  lstripintanyr  r   )rf   code
code_linestab	inc_regex	dec_regexr  increasedecreaseprettylevelns   &&    `     rj   r   JuliaCodePrinter.indent_code  s`    dC  ))$//$*?@J77:&&I	3	 156U#6 "&(!% B	BB	BBC!% 	 ( "&(!% B	BB	BBC!% 	 (  GAtz!d#a[ EMMCIt45a[ E ' ! 7((s   F3)F	 F	)F2 F)rb   )9__name__
__module____qualname____firstlineno____doc__printmethodlanguage
_operatorsr_   r
   r[   __annotations__r^   rq   ru   r{   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r"  r&  r*  r/  r7  r;  _print_Tupler?  rC  rG  rQ  r\  rd  rr  rv  ry  r}  r  r  r  r  r  r  r  r   __static_attributes____classcell__)ri   s   @rj   rP   rP   0   sU    KH 	tdsJ )-[-J-J )R"D$	O )~  !# /!#3'B	'HZT9>(=55555I:F7
  L!:N3
E*I61-""C"$H
$ rl   rP   Nc                6    \        V4      P                  W4      # )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])'
)rP   doprint)r   	assign_torg   s   &&,rj   
julia_coder    s    L H%--d>>rl   c                0    \        \        V 3/ VB 4       R# )zvPrints the Julia representation of the given expression.

See `julia_code` for the meaning of the optional arguments.
N)printr  )r   rg   s   &,rj   print_julia_coder    s    
 
*T
&X
&'rl   r   )r  
__future__r   typingr   
sympy.corer   r   r   r   sympy.core.mulr   sympy.core.numbersr	   sympy.printing.codeprinterr
   sympy.printing.precedencer   r   rM   r   ra   rd   rP   r  r  ro   rl   rj   <module>r     sB  	 #  , , & + 2 < 
(5 
(% 
( 
( 
(u 
(e 
(
(!
(#)
(+1
(39
(;A
(
(!
(#)
(+1
(39
(;A
( 
( $
( &-
( /6
( 8?
( AH
( 	
( #	
( %,	
( .3	
( 5:	
(
 
(
 "
(
 $)
(
 +1
(
 39
( 
( !(
( *3
( 5?
( 
( !'
( 
( +
( -5
( 7D
( 
( (
( *3
( 5>
( 
( '
( 
5vzz&&K{ K\F?R(rl   