ó
    Š*£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ÚJuliaCodePrinteré0   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      €ÚQ/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/printing/julia.pyra   ÚJuliaCodePrinter.__init__G   sb   ø€ Ü‰Ñ˜Ô"Ü#¤C¬¼Ó$IÓJˆÔØ×Ñ×#Ñ#¤D¬Ó$9Ô:Ø—L‘LÐ!1°2Ó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¢˜1´U¸4·[°�A•±[‘¢ùs   ƒ#&)Úshaper�   )ri   ÚmatÚcolsr‘   s      @rm   Ú_traverse_matrix_indicesÚ)JuliaCodePrinter._traverse_matrix_indicesc   s   ø€ à—Y‘Y‰
ˆˆ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§;¡;Ø—W‘W˜aŸg™g¨™k¨1¯7©7°Q©;Ð7ó 9ÑˆC˜à×Ò³#³uºdÐ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  o°R;                  X²5      PM     nnU Vs/ s H  o°R;                  X²5      PM     nnU HP  n
U
R(                  U;   d  M  S
X×R=                  U
R(                  5         -  X×R=                  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ÚnoneéÿÿÿÿF)Ú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Ü˜1œc !›fÖ%�Ø ! A¡#¡× 0× 0™°d�Û"#£V¨U«XÐ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   é € Ð9²q°§¦²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Í  € à�N�N˜t×0×0Ø×!Ñ!Ó# AÑ&×1×1Ø˜DŸK™K¬¯©Ð(8¸Ñ(=Ó>Ñ>Ð>ô ˜$Óˆà× Ñ Ó"‰ˆØˆq‹5Ü ˜r 1Ó%ˆDØ‰DàˆDàˆØˆàˆ	à�:‰:˜_Ó,Ø×*Ñ*Ó,‰Dô —=’= Ó&ˆDô ˆDØ×#×#Ð#¨¯¯¨¸¿¹×8L×8LØŸ™×,×,Ø—8‘8˜r“>Ø—H‘HœS §¡¨T¯X©X¨IÀÑFÖGä˜4Ÿ9™9 Q™<×,Ñ,Ó-°Ó2´zÀ$Ç)Á)ÌS×7QÑ7QØ!×(Ñ(¨Ô.Ø—H‘HœS §¡¨T¯X©X¨IÓ6×7Ø×!×! d´!·*±*Ò&<ÀÇÁÈ1Ãð
 —‘œ $§&¡&Ó)×*à—‘˜—ñ! ð$ �L”!—%‘%�ˆá56Ó7²Q°×"Ñ" 1Ö+±QˆÐ7Ù56Ó7²Q°×"Ñ" 1Ö+±QˆÐ7ó ˆDØ�y‰y˜A�~Ø,2°U¿7¹7À4Ç9Á9Ó;MÑ5NÑ,N�—g‘g˜dŸi™iÓ(Ó)ñ ò
	ö Ø˜( 1Ó,Ñ,Ð,Ü�‹V�q‹[Ø˜a™DŸNŸN‘S°ˆFØ!% h¨qÓ&8Ô!8»&À%ÈÃ(ÐKÐKäÑ9±qÓ9×9Ñ9‘S¸tˆFØ#'¨(°1Ó*<Ô#<»fÁhÈqÖFXÐYÐYùò1 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   € Ø—;‘;˜tŸx™xÓ(ˆØ—;‘;˜tŸx™xÓ(ˆØ�[‰[ˆØ× Ñ  ¨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   é € Ð>²I¨qŸ{ž{²Iù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Ø   )ri   rÛ   Ú	powsymbolÚPRECÚsyms        rm   Ú
_print_PowÚJuliaCodePrinter._print_PowÅ   s	  € ÜÑ>°D·I²IÓ>×>Ñ>‘CÀDˆ	ä˜$Óˆä˜Ÿ™ #×&Ñ&Ø §¡¨D¯I©IÓ 6Ñ6Ð6à××Ü˜DŸH™H d×+Ñ+Ø!ŸY™Y×0×0‘c°d‘Û*-¨t¯{©{¸4¿9¹9Ö/EÐFÐFÜ˜DŸH™H b×)Ñ)Ø!ŸY™Y×0×0‘c°d‘Û%(¨$×*;Ñ*;¸D¿I¹IÀtÕ*LÐMÐMà!×.Ñ.¨t¯y©y¸$Ö?ÃØ×,Ñ,¨T¯X©X°tÕ<ð>ð 	>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>   € Ü˜$ÓˆØ ×-Ñ-¨d¯i©i¸Ö>Ø×+Ñ+¨D¯H©H°dÕ;ð=ð 	=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  pšU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à�h‰hˆØ�h‰hˆà�~‰~˜h×'¬J°t·x±xÀ×,KÑ,Kð ˆKØˆJØŸ(œ(‘�Ø×"Ñ"¡:¨cÓ#5Ô6Ø×!Ñ! !Ö$ñ #ñ œc +Ó:Ð;ˆDØ—;‘;˜tÓ$Ð$Ø�>‰>˜*×%¨3¯7©7°;×+?Ñ+?Ø—‘˜×$Ñ$ð ×&Ñ& sÓ0Ð0à—{‘{ 3Ó'ˆHØ—{‘{ 3Ó'ˆHØ×&Ñ&³HºhÐ'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;   € Üˆt‹9˜‹>Ø˜TŸ[™[¨¨a©Ó1Ñ1Ð1à˜DŸN™N¨4°Ó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   € Ü�4‹y�‰Ó Ð 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Ò   € ä�6‰6�Q—W‘WÔØ&'§f¤f¨a¯f¬fÐ5Ð5Ø�f‰f�a—f‘fÐ Ó'Ø˜A˜d™GÑ#Ð#Ø�V‰V�q‹[Ø˜AŸG™G D°2¸bÈ˜GÐMÑMÐMØ�V‰V�q‹[à˜DŸI™I¹qÓ&Aºq¸!§{¡{°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­   € Ý)Ø�J‰J‹Lˆá¡aÓ(¢a �a‘D˜1”H¡aÑ(Ó)ˆÙ¡aÓ(¢a �a‘D˜1”H¡aÑ(Ó)ˆÙ¡AÓ&¢A˜q˜”d¡AÑ&Ó'‰Ø/3¯{©{¸1®~¸t¿{¹{È1¾~Ø,0¯K©K¸Ö,<¸a¿f¼fÀaÇfÄfð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ØŸ6™6 Aœ: t§v¡v°¤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   ÚstrsliceÚ5JuliaCodePrinter._print_MatrixSlice.<locals>.strslicek  s�   ø€ Ø�!‘�q‘ˆAØ�!‘ˆAØ�Q‘4ˆDØ—;‘;˜q“>ˆDØ›H‘5¨$¯+©+°a«.ˆDØ�q‹yØ˜“6˜a›hØØ“6Ø�Kà #™:¨Ñ,Ð,à—x‘x  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ð —‘˜DŸK™KÓ(¨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ØŸ;™; t§y¡y§¡Ö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Ÿ;™; t§z¡z°!¡}Ó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   € Ø�{‰{Ø%)§Y¢Yó0Ú%.˜cð !×-Ñ-¨c´:¸dÓ3CÖ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   € Ü˜$ÓˆØ�z‰zØ×Ñ˜dŸi™i¨Ó.Ø×Ñ˜dŸh™h¨Ó-ðó ð 	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.   € Ø�6‰6�Q‹;Ü�t—v‘v“;ÐØ!ŸVœV T§V£VÐ,Ð,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Ø�M‰MˆÙ”Q—T‘T˜1˜Q™3‘ZÓ ¡¨¯©´a·f±fÑ)<¸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-   € à× Ñ  §¡¨T¯Y©Y°q©\¼A¿D¹DÑ-@Ó!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±   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.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œ  € Ø�9‰9�R‰=×Ñ Ó%ô ð /ó 0ð 0ð
 ˆØ�>‰>˜(×#ð $(§9¡9¨S¨b¡>ô3â#1™4˜1ð '×-Ñ-ØŸ™ A›¨¯©°A«ö8á#1ð ñ 3ð ˜dŸk™k¨$¯)©)°B©-×*<Ñ*<Ó=Ñ=ˆEØ—‘˜7Ó# eÑ+ˆBð ˜‘8˜c‘>Ð!ä& t§y¡yÖ1‘	�‘6�AØ˜“6Ø—L‘L ¨T¯[©[¸«^Ñ!;Õ<Øœ#˜dŸi™i›.¨1Ñ,Ó,°°d³Ø—L‘L Õ(à—L‘L °·±¸Q³Ñ!?Ô@ØŸ™ A›�Ø—‘˜UÔ#Øœ˜DŸI™I›¨Ñ*Õ*Ø—L‘L Ö'ñ 2ð —9‘9˜UÓ#Ð#ùó)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×Ñ˜s¤J¨tÓ$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‘   ù€ Ø×!Ñ!Ó#‰ˆàˆØ�;�;Ø—^‘^Ó%‰FˆBØ�z�z˜bŸnŸnÜ" A 2 qÓ)�Ø‘Ø—— §§Ü" A 2 qÓ)�Ø�à�e—j‘jÝ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  X¨U   -  n
U	R                  X:-  < T< 35        X§U   -  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º	°"œV B¨×-Ð-º	ùó   ƒ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@  ø€ ô �dœC× Ñ Ø×)Ñ)¨$¯/©/¸$Ó*?Ó@ˆJØ—7‘7˜:Ó&Ð&àˆØIˆ	Ø3ˆ	ñ 15Ó6²¨—‘˜UÖ#±ˆÐ6ñ "&ô(Ú!%˜ô œÔB¹	ÓBÓBÖCÙ!%ð 	ð (ñ "&ô(Ú!%˜ô œÔB¹	ÓBÓBÖCÙ!%ð 	ð (ð ˆØˆÜ  –‰GˆAˆtØ�zÓ!Ø—‘˜dÔ#ÙØ˜a‘[Ñ ˆEØ�M‰M C£IªtÐ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   