Ë
    7^(hõ[  ã                  ó¸   — d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZmZ dd	lmZ g d
¢ZddddddddœZ G d„ de«      Zdd„Zd„ Zy)a  
Julia code printer

The `JuliaCodePrinter` converts SymPy expressions into Julia expressions.

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

é    )Úannotations)ÚAny)ÚMulÚPowÚSÚRational)Ú_keep_coeff)Úequal_valued)ÚCodePrinter)Ú
precedenceÚ
PRECEDENCE©Úsearch)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            	      ó„  ‡ — e Zd ZU dZdZdZddddœZ eej                  fi di d	d	d
œ¤ŽZ	de
d<   i fˆ fd„	Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zˆ fd„Zd„ Zˆ fd„Zˆ fd„Zˆ fd„Zˆ fd„Zd„ Zd „ Zd!„ Zd"„ Z d#„ Z!d$„ Z"e"Z#d%„ Z$d&„ Z%d'„ Z&d(„ Z'd)„ Z(d*„ Z)d+„ Z*d,„ Z+d-„ Z,d.„ Z-d/„ Z.d0„ Z/d1„ Z0d2„ Z1d3„ Z2d4„ Z3d5„ Z4d6„ Z5ˆ xZ6S )7ÚJuliaCodePrinterzD
    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         ‰| �  |«       t        t        t        t        «      «      | _        | j
                  j                  t        t        «      «       |j                  di «      }| j
                  j                  |«       y )NrZ   )	ÚsuperÚ__init__ÚdictÚzipÚknown_fcns_src1Úknown_functionsÚupdateÚknown_fcns_src2Úget)ÚselfÚsettingsÚ	userfuncsÚ	__class__s      €úR/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/printing/julia.pyr`   zJuliaCodePrinter.__init__G   sb   ø€ Ü‰Ñ˜Ô"Ü#¤C¬¼Ó$IÓJˆÔØ×Ñ×#Ñ#¤D¬Ó$9Ô:Ø—L‘LÐ!1°2Ó6ˆ	Ø×Ñ×#Ñ# IÕ.ó    c                ó   — |dz  S )Né   © )rh   Úps     rl   Ú_rate_index_positionz%JuliaCodePrinter._rate_index_positionO   s   € Ø�‰sˆ
rm   c                ó   — d|z  S )Nz%srp   )rh   Ú
codestrings     rl   Ú_get_statementzJuliaCodePrinter._get_statementS   s   € Ø�jÑ Ð rm   c                ó$   — dj                  |«      S )Nz# {}©Úformat)rh   Útexts     rl   Ú_get_commentzJuliaCodePrinter._get_commentW   s   € Ø�}‰}˜TÓ"Ð"rm   c                ó&   — dj                  ||«      S )Nzconst {} = {}rw   )rh   ÚnameÚvalues      rl   Ú_declare_number_constz&JuliaCodePrinter._declare_number_const[   s   € Ø×%Ñ% d¨EÓ2Ð2rm   c                ó$   — | j                  |«      S ©N)Úindent_code)rh   Úliness     rl   Ú_format_codezJuliaCodePrinter._format_code_   s   € Ø×Ñ Ó&Ð&rm   c                óJ   ‡— |j                   \  Š}ˆfd„t        |«      D «       S )Nc              3  óF   •K  — | ]  }t        ‰«      D ]  }||f–— Œ
 Œ y ­wr€   )Úrange)Ú.0ÚjÚiÚrowss      €rl   ú	<genexpr>z<JuliaCodePrinter._traverse_matrix_indices.<locals>.<genexpr>f   s%   øè ø€ ÒA˜1´U¸4³[ÒA°��A”ÐA�ÑAùs   ƒ!)Úshaper†   )rh   ÚmatÚcolsrŠ   s      @rl   Ú_traverse_matrix_indicesz)JuliaCodePrinter._traverse_matrix_indicesc   s   ø€ à—Y‘Y‰
ˆˆdÛA¤ d£ÔAÐArm   c           	     óø   — g }g }|D ]n  }t        | j                  |j                  |j                  dz   |j                  dz   g«      \  }}}|j                  d|›d|›d|›�«       |j                  d«       Œp ||fS )Né   zfor ú = ú:Úend)ÚmapÚ_printÚlabelÚlowerÚupperÚappend)rh   ÚindicesÚ
open_linesÚclose_linesr‰   ÚvarÚstartÚstops           rl   Ú_get_loop_opening_endingz)JuliaCodePrinter._get_loop_opening_endingi   s€   € Øˆ
ØˆØò 	&ˆAä" 4§;¡;Ø—W‘W˜aŸg™g¨™k¨1¯7©7°Q©;Ð7ó 9ÑˆC�˜à×Ò²#²u¹dÐCÔDØ×Ñ˜uÕ%ð	&ð ˜;Ð&Ð&rm   c                óÖ  — |j                   rO|j                  rC|j                  «       d   j                  r&d| j	                  t
        j                   |z  «      z  S t        |«      }|j                  «       \  }}|dk  rt        | |«      }d}nd}g }g }g }| j                  dvr|j                  «       }	nt        j                  |«      }	|	D �]o  }
|
j                  rü|
j                  rð|
j                  j                   rÚ|
j                  j"                  rÄ|
j                  dk7  r3|j%                  t'        |
j(                  |
j                   d¬«      «       ŒŠt+        |
j,                  d   j,                  «      d	k7  r+t/        |
j(                  t        «      r|j%                  |
«       |j%                  t'        |
j(                  |
j                   «      «       �Œ|
j                   rG|
t
        j0                  ur5|
j2                  d	k(  r&|j%                  t5        |
j6                  «      «       �Œ_|j%                  |
«       �Œr |xs t
        j8                  g}|D �cg c]  }| j;                  ||«      ‘Œ }}|D �cg c]  }| j;                  ||«      ‘Œ }}|D ]N  }
|
j(                  |v sŒd
||j=                  |
j(                  «         z  ||j=                  |
j(                  «      <   ŒP d„ }|s| |||«      z   S t+        |«      d	k(  r*|d   j                   rdnd}| |||«      z   ›d|›d|d   ›�S t?        d„ |D «       «      rdnd}| |||«      z   ›d|›d |||«      ›d�S c c}w c c}w )Nr   z%simú-Ú )ÚoldÚnoneéÿÿÿÿF)Úevaluater‘   ú(%s)c                óŠ   — |d   }t        dt        | «      «      D ]%  }| |dz
     j                  rdnd}|›d|›d||   ›�}Œ' |S )Nr   r‘   Ú*z.*ú )r†   ÚlenÚ	is_number)ÚaÚa_strÚrr‰   Úmulsyms        rl   Úmultjoinz-JuliaCodePrinter._print_Mul.<locals>.multjoin®   sS   € à�a‘ˆAÜ˜1œc !›fÓ%ò 7�Ø ! ! A¡#¡× 0Ò 0™°d�Ú"#¢V¨U°1ªXÐ6‘ð7ð ˆHrm   ú/ú./r¬   c              3  ó4   K  — | ]  }|j                   –— Œ y ­wr€   ©r®   )r‡   Úbis     rl   r‹   z.JuliaCodePrinter._print_Mul.<locals>.<genexpr>¼   s   è ø€ Ò9° §¥Ñ9ùó   ‚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ÚInfinityrq   r   ÚqÚOneÚparenthesizeÚindexÚall)rh   ÚexprÚprecÚcÚer)   r¯   ÚbÚ	pow_parenrÇ   ÚitemÚxr°   Úb_strr³   Údivsyms                   rl   Ú
_print_MulzJuliaCodePrinter._print_Mulu   sã  € à�NŠN˜t×0Ò0Ø×!Ñ!Ó# AÑ&×1Ò1Ø˜DŸK™K¬¯©Ð(8¸Ñ(=Ó>Ñ>Ð>ô ˜$Óˆà× Ñ Ó"‰ˆˆ1Øˆ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Ø!×(Ñ(¨Ô.Ø—H‘HœS §¡¨T¯X©X¨IÓ6Ö7Ø×!Ò! d´!·*±*Ñ&<ÀÇÁÈ1Âð
 —‘œ $§&¡&Ó)Ö*à—‘˜–ð!	ð$ ŠL”!—%‘%�ˆà56Ö7°�×"Ñ" 1 dÕ+Ð7ˆÐ7Ø56Ö7°�×"Ñ" 1 dÕ+Ð7ˆÐ7ð ò 	OˆDØ�y‰y˜AŠ~Ø,2°U¸1¿7¹7À4Ç9Á9Ó;MÑ5NÑ,N��a—g‘g˜dŸi™iÓ(Ò)ð	Oò
	ñ Ø™( 1 eÓ,Ñ,Ð,Ü�‹V�qŠ[Ø˜a™DŸNšN‘S°ˆFØ!%¡h¨q°%Ó&8Ó!8º&À%ÈÂ(ÐKÐKäÑ9°qÔ9Ô9‘S¸tˆFØ#'©(°1°eÓ*<Ó#<ºfÁhÈqÐRWÕFXÐYÐYùò1 8ùÚ7s   ÉM!É8M&c                ó¬   — | j                  |j                  «      }| j                  |j                  «      }|j                  }dj	                  |||«      S )Nz{} {} {})r–   ÚlhsÚrhsÚrel_oprx   )rh   rÏ   Úlhs_codeÚrhs_codeÚops        rl   Ú_print_Relationalz"JuliaCodePrinter._print_Relational¿   sD   € Ø—;‘;˜tŸx™xÓ(ˆØ—;‘;˜tŸx™xÓ(ˆØ�[‰[ˆØ× Ñ  ¨2¨xÓ8Ð8rm   c                óœ  — t        d„ |j                  D «       «      rdnd}t        |«      }t        |j                  d«      rd| j                  |j                  «      z  S |j                  r¤t        |j                  d«      r<|j                  j                  rdnd}d	|›d
| j                  |j                  «      ›d�S t        |j                  d«      r<|j                  j                  rdnd}d	|›d| j                  |j                  |«      ›�S | j                  |j                  |«      ›d|›d| j                  |j                  |«      ›�S )Nc              3  ó4   K  — | ]  }|j                   –— Œ y ­wr€   r·   )r‡   rÖ   s     rl   r‹   z.JuliaCodePrinter._print_Pow.<locals>.<genexpr>Æ   s   è ø€ Ò>¨q˜qŸ{�{Ñ>ù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Ì   )rh   rÏ   Ú	powsymbolÚPRECÚsyms        rl   Ú
_print_Powz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Ô<ð>ð 	>rm   c                óŽ   — t        |«      }| j                  |j                  |«      ›d| j                  |j                  |«      ›�S )Nz ^ )r   rÌ   rÆ   r,   ©rh   rÏ   ræ   s      rl   Ú_print_MatPowzJuliaCodePrinter._print_MatPowÙ   s>   € Ü˜$ÓˆØ ×-Ñ-¨d¯i©i¸Õ>Ø×+Ñ+¨D¯H©H°dÔ;ð=ð 	=rm   c                óB   •— | j                   d   ryt        ‰| �	  |«      S )Nr\   Úpi©Ú	_settingsr_   Ú_print_NumberSymbol©rh   rÏ   rk   s     €rl   Ú	_print_PizJuliaCodePrinter._print_Piß   s"   ø€ Ø�>‰>˜(Ò#Øä‘7Ñ.¨tÓ4Ð4rm   c                 ó   — y)NrN   rp   ©rh   rÏ   s     rl   Ú_print_ImaginaryUnitz%JuliaCodePrinter._print_ImaginaryUnitæ   s   € Ørm   c                óB   •— | j                   d   ryt        ‰| �	  |«      S )Nr\   rÒ   rî   rñ   s     €rl   Ú_print_Exp1zJuliaCodePrinter._print_Exp1ê   s"   ø€ Ø�>‰>˜(Ò#Øä‘7Ñ.¨tÓ4Ð4rm   c                óB   •— | j                   d   ryt        ‰| �	  |«      S )Nr\   Ú
eulergammarî   rñ   s     €rl   Ú_print_EulerGammaz"JuliaCodePrinter._print_EulerGammañ   s"   ø€ Ø�>‰>˜(Ò#Øä‘7Ñ.¨tÓ4Ð4rm   c                óB   •— | j                   d   ryt        ‰| �	  |«      S )Nr\   Úcatalanrî   rñ   s     €rl   Ú_print_CatalanzJuliaCodePrinter._print_Catalanø   s"   ø€ Ø�>‰>˜(Ò#Øä‘7Ñ.¨tÓ4Ð4rm   c                óB   •— | j                   d   ryt        ‰| �	  |«      S )Nr\   Úgoldenrî   rñ   s     €rl   Ú_print_GoldenRatioz#JuliaCodePrinter._print_GoldenRatioÿ   s"   ø€ Ø�>‰>˜(Ò#Øä‘7Ñ.¨tÓ4Ð4rm   c                óX  — ddl m} ddlm} ddlm} |j                  }|j                  }| j                  d   swt        |j                  |«      rag }g }|j                  D ].  \  }	}
|j                   |||	«      «       |j                  |
«       Œ0  |t        ||«      Ž }| j                  |«      S | j                  d   r4|j                  |«      s|j                  |«      r| j                  ||«      S | j                  |«      }| j                  |«      }| j!                  |›d|›�«      S )Nr   )Ú
Assignment)Ú	Piecewise)ÚIndexedBaser\   r[   r’   )Úsympy.codegen.astr  Ú$sympy.functions.elementary.piecewiser  Úsympy.tensor.indexedr  rÛ   rÜ   rï   rÈ   rÇ   rš   rb   r–   ÚhasÚ_doprint_loopsru   )rh   rÏ   r  r  r  rÛ   rÜ   ÚexpressionsÚ
conditionsrÒ   rÑ   ÚtemprÞ   rß   s                 rl   Ú_print_Assignmentz"JuliaCodePrinter._print_Assignment  s  € Ý0ÝBÝ4à�h‰hˆØ�h‰hˆà�~‰~˜hÒ'¬J°t·x±xÀÔ,Kð ˆKØˆJØŸ(™(ò %‘��AØ×"Ñ"¡:¨c°1Ó#5Ô6Ø×!Ñ! !Õ$ð%ñ œc +¨zÓ:Ð;ˆDØ—;‘;˜tÓ$Ð$Ø�>‰>˜*Ò%¨3¯7©7°;Ô+?Ø—‘˜Ô$ð ×&Ñ& s¨CÓ0Ð0à—{‘{ 3Ó'ˆHØ—{‘{ 3Ó'ˆHØ×&Ñ&²H¹hÐ'GÓHÐHrm   c                 ó   — y)NÚInfrp   rô   s     rl   Ú_print_Infinityz JuliaCodePrinter._print_Infinity#  ó   € Ørm   c                 ó   — y)Nz-Infrp   rô   s     rl   Ú_print_NegativeInfinityz(JuliaCodePrinter._print_NegativeInfinity'  ó   € Ørm   c                 ó   — y)NÚNaNrp   rô   s     rl   Ú
_print_NaNzJuliaCodePrinter._print_NaN+  r  rm   c                óD   ‡ — ddj                  ˆ fd„|D «       «      z   dz   S )NzAny[ú, c              3  ó@   •K  — | ]  }‰j                  |«      –— Œ y ­wr€   )r–   )r‡   r¯   rh   s     €rl   r‹   z/JuliaCodePrinter._print_list.<locals>.<genexpr>0  s   øè ø€ Ò!?°Q $§+¡+¨a§.Ñ!?ùs   ƒú])Újoinrô   s   ` rl   Ú_print_listzJuliaCodePrinter._print_list/  s"   ø€ Ø˜Ÿ	™	Ó!?¸$Ô!?Ó?Ñ?À#ÑEÐErm   c                óv   — t        |«      dk(  rd| j                  |d   «      z  S d| j                  |d«      z  S )Nr‘   z(%s,)r   r©   r  )r­   r–   Ú	stringifyrô   s     rl   Ú_print_tuplezJuliaCodePrinter._print_tuple3  s;   € Üˆt‹9˜Š>Ø˜TŸ[™[¨¨a©Ó1Ñ1Ð1à˜DŸN™N¨4°Ó6Ñ6Ð6rm   c                 ó   — y)NÚtruerp   rô   s     rl   Ú_print_BooleanTruez#JuliaCodePrinter._print_BooleanTrue;  r  rm   c                 ó   — y)NÚfalserp   rô   s     rl   Ú_print_BooleanFalsez$JuliaCodePrinter._print_BooleanFalse?  s   € Ørm   c                ó4   — t        |«      j                  «       S r€   )Ústrr˜   rô   s     rl   Ú_print_boolzJuliaCodePrinter._print_boolC  s   € Ü�4‹y�‰Ó Ð rm   c           	     óÄ  — t         j                  |j                  v rd|j                  ›d|j                  ›d�S |j                  |j                  fdk(  rd|d   z  S |j                  dk(  rd|j                  | ddd	¬
«      z  S |j                  dk(  r1ddj                  |D �cg c]  }| j                  |«      ‘Œ c}«      z  S d|j                  | dddd	¬«      z  S c c}w )Nzzeros(r  rº   )r‘   r‘   z[%s])r   r   r‘   r¤   r¬   )ÚrowstartÚrowendÚcolsepz;
)r+  r,  Úrowsepr-  )r   ÚZerorŒ   rŠ   rŽ   Útabler  r–   )rh   ÚAr¯   s      rl   Ú_print_MatrixBasez"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¸! t§{¡{°1¥~Ò&AÓBÑBÐBØ˜Ÿ™ ¨r¸"Ø',°Sð  ó :ñ :ð 	:ùò 'Bs   Â#C
c                ó”  — ddl m} |j                  «       } ||D �cg c]
  }|d   dz   ‘Œ c}«      } ||D �cg c]
  }|d   dz   ‘Œ c}«      } ||D �cg c]  }|d   ‘Œ	 c}«      }d| j                  |«      ›d| j                  |«      ›d| j                  |«      ›d|j                  ›d|j
                  ›d�S c c}w c c}w c c}w )Nr   )ÚMatrixr‘   é   zsparse(r  rº   )Úsympy.matricesr4  Úcol_listr–   rŠ   rŽ   )rh   r1  r4  ÚLÚkÚIÚJÚAIJs           rl   Ú_print_SparseRepMatrixz'JuliaCodePrinter._print_SparseRepMatrixZ  s§   € Ý)Ø�J‰J‹Lˆá aÖ( �A�a‘D˜1“HÒ(Ó)ˆÙ aÖ( �A�a‘D˜1“HÒ(Ó)ˆÙ AÖ&˜q�a˜“dÒ&Ó'‰Ø/3¯{©{¸1­~¸t¿{¹{È1½~Ø,0¯K©K¸Õ,<¸a¿f»fÀaÇfÃfðNð 	Nùò )ùÚ(ùÚ&s   �B;¹C ÁCc                ó”   — | j                  |j                  t        d   d¬«      d|j                  dz   ›d|j                  dz   ›d�z   S )NÚAtomT)Ústrictú[r‘   ú,r  )rÌ   Úparentr   r‰   rˆ   rô   s     rl   Ú_print_MatrixElementz%JuliaCodePrinter._print_MatrixElemente  sB   € Ø× Ñ  §¡¬j¸Ñ.@ÈÐ ÔNØŸ6™6 A›: t§v¡v°£zÐ2ñ3ð 	3rm   c                ó  ‡ — ˆ fd„}‰ j                  |j                  «      dz    ||j                  |j                  j                  d   «      z   dz    ||j                  |j                  j                  d   «      z   dz   S )Nc                óþ   •— | d   dz   }| d   }| d   }‰j                  |«      }||k(  rdn‰j                  |«      }|dk(  r|dk(  r||k(  ry||k(  r|S |dz   |z   S dj                  |‰j                  |«      |f«      S )Nr   r‘   r5  r”   r“   )r–   r  )rÖ   ÚlimÚlÚhÚstepÚlstrÚhstrrh   s          €rl   Ústrslicez5JuliaCodePrinter._print_MatrixSlice.<locals>.strslicek  s•   ø€ Ø�!‘�q‘ˆAØ�!‘ˆAØ�Q‘4ˆDØ—;‘;˜q“>ˆDØ šH‘5¨$¯+©+°a«.ˆDØ�qŠyØ˜’6˜a 3šhØØ˜’6Ø�Kà #™:¨Ñ,Ð,à—x‘x  t§{¡{°4Ó'8¸$Ð ?Ó@Ð@rm   rA  r   rB  r‘   r  )r–   rC  ÚrowslicerŒ   Úcolslice)rh   rÏ   rM  s   `  rl   Ú_print_MatrixSlicez#JuliaCodePrinter._print_MatrixSlicej  s|   ø€ ô	Að —‘˜DŸK™KÓ(¨3Ñ.Ù˜Ÿ™¨¯©×(9Ñ(9¸!Ñ(<Ó=ñ>Ø@CñDá˜Ÿ™¨¯©×(9Ñ(9¸!Ñ(<Ó=ñ>à@CñDð 	Erm   c                óÐ   — |j                   D �cg c]  }| j                  |«      ‘Œ }}| j                  |j                  j                  «      ›ddj	                  |«      ›d�S c c}w )NrA  rB  r  )r›   r–   rÆ   r—   r  )rh   rÏ   r‰   Úindss       rl   Ú_print_IndexedzJuliaCodePrinter._print_Indexed  sJ   € Ø)-¯©Ö7 A�—‘˜Q•Ð7ˆÐ7ØŸ;™; t§y¡y§¡Õ7¸¿¹À$½ÐHÐHùò 8s   �A#c                óD   — d| j                  |j                  d   «      z  S )Nzeye(%s)r   )r–   rŒ   rô   s     rl   Ú_print_Identityz JuliaCodePrinter._print_Identityƒ  s   € Ø˜4Ÿ;™; t§z¡z°!¡}Ó5Ñ5Ð5rm   c                ó�   — dj                  |j                  D �cg c]  }| j                  |t        |«      «      ‘Œ c}«      S c c}w )Nz .* )r  rÇ   rÌ   r   )rh   rÏ   Úargs      rl   Ú_print_HadamardProductz'JuliaCodePrinter._print_HadamardProduct†  sD   € Ø�{‰{Ø%)§Y¡Yö0Ø!ð !×-Ñ-¨c´:¸dÓ3CÕDò 0ó 1ð 	1ùò 0s   š"Ac                ó¦   — t        |«      }dj                  | j                  |j                  |«      | j                  |j                  |«      g«      S )Nz.**)r   r  rÌ   rÆ   r,   rê   s      rl   Ú_print_HadamardPowerz%JuliaCodePrinter._print_HadamardPowerŠ  sJ   € Ü˜$ÓˆØ�z‰zØ×Ñ˜dŸi™i¨Ó.Ø×Ñ˜dŸh™h¨Ó-ðó ð 	rm   c                ó€   — |j                   dk(  rt        |j                  «      S |j                  ›d|j                   ›�S )Nr‘   z // )rÊ   r(  rq   rô   s     rl   Ú_print_Rationalz JuliaCodePrinter._print_Rational‘  s.   € Ø�6‰6�QŠ;Ü�t—v‘v“;ÐØ!ŸV›V T§V¢VÐ,Ð,rm   c                óÎ   — ddl m}m} |j                  } |t        j
                  d|z  z  «       ||j                  t        j                  z   |«      z  }| j                  |«      S )Nr   )r.   r<   r5  )	Úsympy.functionsr.   r<   Úargumentr   ÚPir¿   ÚHalfr–   )rh   rÏ   r.   r<   rÖ   Úexpr2s         rl   Ú	_print_jnzJuliaCodePrinter._print_jn—  óL   € ß1Ø�M‰MˆÙ”Q—T‘T˜1˜Q™3‘ZÓ ¡¨¯©´a·f±fÑ)<¸aÓ!@Ñ@ˆØ�{‰{˜5Ó!Ð!rm   c                óÎ   — ddl m}m} |j                  } |t        j
                  d|z  z  «       ||j                  t        j                  z   |«      z  }| j                  |«      S )Nr   )r.   r=   r5  )	r^  r.   r=   r_  r   r`  r¿   ra  r–   )rh   rÏ   r.   r=   rÖ   rb  s         rl   Ú	_print_ynzJuliaCodePrinter._print_ynž  rd  rm   c                ó~   — dj                  | j                  |j                  d   t        j                  z  «      «      S )Nzsinc({})r   )rx   r–   rÇ   r   r`  rô   s     rl   Ú_print_sinczJuliaCodePrinter._print_sinc¤  s-   € à× Ñ  §¡¨T¯Y©Y°q©\¼A¿D¹DÑ-@Ó!AÓBÐBrm   c           
     ó¦  — |j                   d   j                  dk7  rt        d«      ‚g }| j                  d   r–|j                   d d D ��cg c]5  \  }}dj	                  | j                  |«      | j                  |«      «      ‘Œ7 }}}d| j                  |j                   d   j                  «      z  }dj                  |«      |z   }d|z   d	z   S t        |j                   «      D ]Õ  \  }\  }}|d
k(  r$|j                  d| j                  |«      z  «       nU|t        |j                   «      dz
  k(  r|dk(  r|j                  d«       n#|j                  d| j                  |«      z  «       | j                  |«      }	|j                  |	«       |t        |j                   «      dz
  k(  sŒÅ|j                  d«       Œ× dj                  |«      S c c}}w )Nr§   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ï   rx   r–   rÏ   r  Ú	enumeraterš   r­   )
rh   rÏ   r‚   rÒ   rÑ   ÚecpairsÚelastÚpwr‰   Úcode0s
             rl   Ú_print_Piecewisez!JuliaCodePrinter._print_Piecewise¨  s¢  € Ø�9‰9�R‰=×Ñ Ò%ô ð /ó 0ð 0ð
 ˆØ�>‰>˜(Ò#ð $(§9¡9¨S¨b >÷3á˜1˜að '×-Ñ-ØŸ™ A›¨¯©°A«õ8ð 3ˆGñ 3ð ˜dŸk™k¨$¯)©)°B©-×*<Ñ*<Ó=Ñ=ˆEØ—‘˜7Ó# eÑ+ˆBð ˜‘8˜c‘>Ð!ä& t§y¡yÓ1ò 
(‘	�‘6�A�qØ˜’6Ø—L‘L ¨T¯[©[¸«^Ñ!;Õ<Øœ#˜dŸi™i›.¨1Ñ,Ò,°°d²Ø—L‘L Õ(à—L‘L °·±¸Q³Ñ!?Ô@ØŸ™ A›�Ø—‘˜UÔ#Øœ˜DŸI™I›¨Ñ*Ó*Ø—L‘L Õ'ð
(ð —9‘9˜UÓ#Ð#ùó)3s   Á:Gc                ó\  ‡ ‡— ‰j                  «       \  }}d}|j                  rb|j                  «       \  }}|j                  r|j                  rt        | |«      Šd}n'|j                  r|j                  rt        | |«      Šd}|dj                  ˆˆ fd„‰j                  D «       «      z   S )Nr¤   r£   z * c              3  óT   •K  — | ]  }‰j                  |t        ‰«      «      –— Œ! y ­wr€   )rÌ   r   )r‡   rW  rÏ   rh   s     €€rl   r‹   z1JuliaCodePrinter._print_MatMul.<locals>.<genexpr>Ú  s#   øè ø€ ÒK¸#ˆT×Ñ˜s¤J¨tÓ$4×5ÑKùs   ƒ%()Úas_coeff_mmulr®   Úas_real_imagÚis_zerorÅ   r	   r  rÇ   )rh   rÏ   rÑ   Úmr)   rO   rN   s   ``     rl   Ú_print_MatMulzJuliaCodePrinter._print_MatMulÌ  s•   ù€ Ø×!Ñ!Ó#‰ˆˆ1àˆØ�;Š;Ø—^‘^Ó%‰FˆB�Ø�zŠz˜bŸnšnÜ" A 2 qÓ)�Ø‘Ø—’ §¢Ü" A 2 qÓ)�Ø�à�e—j‘jÜKÀÇÁÔKó
ñ 
ð 	
rm   c           	     óF  ‡— t        |t        «      r1| j                  |j                  d«      «      }dj	                  |«      S d}d}d}|D �cg c]  }|j                  d«      ‘Œ }}|D �‡cg c]  Št        t        ˆfd„|D «       «      «      ‘Œ! }}|D �‡cg c]  Št        t        ˆfd„|D «       «      «      ‘Œ! }}g }	d	}
t        |«      D ]C  \  }Š‰d
v r|	j                  ‰«       Œ|
||   z  }
|	j                  ||
z  ›‰›�«       |
||   z  }
ŒE |	S c c}w c c}w c c}w )z0Accepts a string of code or a list of code linesTr¤   z    )z
^function z^if ú^elseif ú^else$z^for )z^end$r}  r~  z 	c              3  ó6   •K  — | ]  }t        |‰«      –— Œ y ­wr€   r   ©r‡   rO   Úlines     €rl   r‹   z/JuliaCodePrinter.indent_code.<locals>.<genexpr>í  ó   øè ø€ ÒB°"œV B¨×-ÑBùó   ƒc              3  ó6   •K  — | ]  }t        |‰«      –— Œ y ­wr€   r   r€  s     €rl   r‹   z/JuliaCodePrinter.indent_code.<locals>.<genexpr>ï  r‚  rƒ  r   )r¤   rj  )
rÈ   r(  r�   Ú
splitlinesr  ÚlstripÚintÚanyro  rš   )rh   ÚcodeÚ
code_linesÚtabÚ	inc_regexÚ	dec_regexr�  ÚincreaseÚdecreaseÚprettyÚlevelÚns         `     rl   r�   zJuliaCodePrinter.indent_codeÞ  sC  ø€ ô �dœCÔ Ø×)Ñ)¨$¯/©/¸$Ó*?Ó@ˆJØ—7‘7˜:Ó&Ð&àˆØIˆ	Ø3ˆ	ð 15Ö6¨�—‘˜UÕ#Ð6ˆÐ6ð "&÷(Øô œÓB¸	ÔBÓBÕCð (ˆð (ð "&÷(Øô œÓB¸	ÔBÓBÕCð (ˆð (ð ˆØˆÜ  “ò 	!‰GˆAˆtØ�zÑ!Ø—‘˜dÔ#ØØ�X˜a‘[Ñ ˆEØ�M‰M C¨¢I©tÐ4Ô5Ø�X˜a‘[Ñ ‰Eð	!ð ˆùò! 7ùò(ùò(s   ÁDÁ,$DÂ$D)7Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚprintmethodÚlanguageÚ
_operatorsra   r   r]   Ú__annotations__r`   rr   ru   rz   r~   rƒ   r�   r¡   rÙ   rá   rè   rë   rò   rõ   r÷   rú   rý   r   r  r  r  r  r  r   Ú_print_Tupler#  r&  r)  r2  r=  rD  rP  rS  rU  rX  rZ  r\  rc  rf  rh  rt  r{  r�   Ú__classcell__)rk   s   @rl   rQ   rQ   0   sB  ø… ñð €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
ö$rm   rQ   Nc                ó8   — t        |«      j                  | |«      S )a)  Converts `expr` to a string of Julia code.

    Parameters
    ==========

    expr : Expr
        A SymPy expression to be converted.
    assign_to : optional
        When given, the argument is used as the name of the variable to which
        the expression is assigned.  Can be a string, ``Symbol``,
        ``MatrixSymbol``, or ``Indexed`` type.  This can be helpful for
        expressions that generate multi-line statements.
    precision : integer, optional
        The precision for numbers such as pi  [default=16].
    user_functions : dict, optional
        A dictionary where keys are ``FunctionClass`` instances and values are
        their string representations.  Alternatively, the dictionary value can
        be a list of tuples i.e. [(argument_test, cfunction_string)].  See
        below for examples.
    human : bool, optional
        If True, the result is a single string that may contain some constant
        declarations for the number symbols.  If False, the same information is
        returned in a tuple of (symbols_to_declare, not_supported_functions,
        code_text).  [default=True].
    contract: bool, optional
        If True, ``Indexed`` instances are assumed to obey tensor contraction
        rules and the corresponding nested loops over indices are generated.
        Setting contract=False will not generate loops, instead the user is
        responsible to provide values for the indices in the code.
        [default=True].
    inline: bool, optional
        If True, we try to create single-statement code instead of multiple
        statements.  [default=True].

    Examples
    ========

    >>> from sympy import julia_code, symbols, sin, pi
    >>> x = symbols('x')
    >>> julia_code(sin(x).series(x).removeO())
    'x .^ 5 / 120 - x .^ 3 / 6 + x'

    >>> from sympy import Rational, ceiling
    >>> x, y, tau = symbols("x, y, tau")
    >>> julia_code((2*tau)**Rational(7, 2))
    '8 * sqrt(2) * tau .^ (7 // 2)'

    Note that element-wise (Hadamard) operations are used by default between
    symbols.  This is because its possible in Julia to write "vectorized"
    code.  It is harmless if the values are scalars.

    >>> julia_code(sin(pi*x*y), assign_to="s")
    's = sin(pi * x .* y)'

    If you need a matrix product "*" or matrix power "^", you can specify the
    symbol as a ``MatrixSymbol``.

    >>> from sympy import Symbol, MatrixSymbol
    >>> n = Symbol('n', integer=True, positive=True)
    >>> A = MatrixSymbol('A', n, n)
    >>> julia_code(3*pi*A**3)
    '(3 * pi) * A ^ 3'

    This class uses several rules to decide which symbol to use a product.
    Pure numbers use "*", Symbols use ".*" and MatrixSymbols use "*".
    A HadamardProduct can be used to specify componentwise multiplication ".*"
    of two MatrixSymbols.  There is currently there is no easy way to specify
    scalar symbols, so sometimes the code might have some minor cosmetic
    issues.  For example, suppose x and y are scalars and A is a Matrix, then
    while a human programmer might write "(x^2*y)*A^3", we generate:

    >>> julia_code(x**2*y*A**3)
    '(x .^ 2 .* y) * A ^ 3'

    Matrices are supported using Julia inline notation.  When using
    ``assign_to`` with matrices, the name can be specified either as a string
    or as a ``MatrixSymbol``.  The dimensions must align in the latter case.

    >>> from sympy import Matrix, MatrixSymbol
    >>> mat = Matrix([[x**2, sin(x), ceiling(x)]])
    >>> julia_code(mat, assign_to='A')
    'A = [x .^ 2 sin(x) ceil(x)]'

    ``Piecewise`` expressions are implemented with logical masking by default.
    Alternatively, you can pass "inline=False" to use if-else conditionals.
    Note that if the ``Piecewise`` lacks a default term, represented by
    ``(expr, True)`` then an error will be thrown.  This is to prevent
    generating an expression that may not evaluate to anything.

    >>> from sympy import Piecewise
    >>> pw = Piecewise((x + 1, x > 0), (x, True))
    >>> julia_code(pw, assign_to=tau)
    'tau = ((x > 0) ? (x + 1) : (x))'

    Note that any expression that can be generated normally can also exist
    inside a Matrix:

    >>> mat = Matrix([[x**2, pw, sin(x)]])
    >>> julia_code(mat, assign_to='A')
    'A = [x .^ 2 ((x > 0) ? (x + 1) : (x)) sin(x)]'

    Custom printing can be defined for certain types by passing a dictionary of
    "type" : "function" to the ``user_functions`` kwarg.  Alternatively, the
    dictionary value can be a list of tuples i.e., [(argument_test,
    cfunction_string)].  This can be used to call a custom Julia function.

    >>> from sympy import Function
    >>> f = Function('f')
    >>> g = Function('g')
    >>> custom_functions = {
    ...   "f": "existing_julia_fcn",
    ...   "g": [(lambda x: x.is_Matrix, "my_mat_fcn"),
    ...         (lambda x: not x.is_Matrix, "my_fcn")]
    ... }
    >>> mat = Matrix([[1, x]])
    >>> julia_code(f(x) + g(x) + g(mat), user_functions=custom_functions)
    'existing_julia_fcn(x) + my_fcn(x) + my_mat_fcn([1 x])'

    Support for loops is provided through ``Indexed`` types. With
    ``contract=True`` these expressions will be turned into loops, whereas
    ``contract=False`` will just print the assignment expression that should be
    looped over:

    >>> from sympy import Eq, IndexedBase, Idx
    >>> len_y = 5
    >>> y = IndexedBase('y', shape=(len_y,))
    >>> t = IndexedBase('t', shape=(len_y,))
    >>> Dy = IndexedBase('Dy', shape=(len_y-1,))
    >>> i = Idx('i', len_y-1)
    >>> e = Eq(Dy[i], (y[i+1]-y[i])/(t[i+1]-t[i]))
    >>> julia_code(e.rhs, assign_to=e.lhs, contract=False)
    'Dy[i] = (y[i + 1] - y[i]) ./ (t[i + 1] - t[i])'
    )rQ   Údoprint)rÏ   Ú	assign_tori   s      rl   Ú
julia_coder   þ  s   € ôL ˜HÓ%×-Ñ-¨d°IÓ>Ð>rm   c                ó.   — t        t        | fi |¤Ž«       y)z~Prints the Julia representation of the given expression.

    See `julia_code` for the meaning of the optional arguments.
    N)Úprintr   )rÏ   ri   s     rl   Úprint_julia_coder£  ‡  s   € ô
 
Œ*�TÑ
&˜XÑ
&Õ'rm   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   rc   rf   rQ   r   r£  rp   rm   rl   ú<module>r«     sg   ðñ	õ #Ý ç ,Ó ,Ý &Ý +Ý 2ß <Ý ò
(€ð ØØØØØ
Ø
ñ€ôK�{ô Kó\F?óR(rm   