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

The `JuliaCodePrinter` converts SymPy expressions into Julia expressions.

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

é    )Úannotations)ÚAny)ÚMulÚPowÚSÚRational)Ú_keep_coeff)Úequal_valued)ÚCodePrinter)Ú
precedenceÚ
PRECEDENCE©Úsearch)3ÚsinÚcosÚtanÚcotÚsecÚcscÚasinÚacosÚatanÚacotÚasecÚacscÚsinhÚcoshÚtanhÚcothÚsechÚcschÚasinhÚacoshÚatanhÚacothÚasechÚacschÚsincÚatan2ÚsignÚfloorÚlogÚexpÚcbrtÚsqrtÚerfÚerfcÚerfiÚ	factorialÚgammaÚdigammaÚtrigammaÚ	polygammaÚbetaÚairyaiÚairyaiprimeÚairybiÚairybiprimeÚbesseljÚbesselyÚbesseliÚbesselkÚerfinvÚerfcinvÚabsÚceilÚconjÚhankelh1Úhankelh2ÚimagÚreal)ÚAbsÚceilingÚ	conjugateÚhankel1Úhankel2ÚimÚrec            	      ó„  ‡ — 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 )Nr[   )	ÚsuperÚ__init__ÚdictÚzipÚknown_fcns_src1Úknown_functionsÚupdateÚknown_fcns_src2Úget)ÚselfÚsettingsÚ	userfuncsÚ	__class__s      €úW/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/sympy/printing/julia.pyra   zJuliaCodePrinter.__init__G   sb   ø€ Ü‰Ñ˜Ô"Ü#¤C¬¼Ó$IÓJˆÔØ×Ñ×#Ñ#¤D¬Ó$9Ô:Ø—L‘LÐ!1°2Ó6ˆ	Ø×Ñ×#Ñ# IÕ.ó    c                ó   — |dz  S )Né   © )ri   Úps     rm   Ú_rate_index_positionz%JuliaCodePrinter._rate_index_positionO   s   € Ø�‰sˆ
rn   c                ó   — d|z  S )Nz%srq   )ri   Ú
codestrings     rm   Ú_get_statementzJuliaCodePrinter._get_statementS   s   € Ø�jÑ Ð rn   c                ó$   — dj                  |«      S )Nz# {}©Úformat)ri   Útexts     rm   Ú_get_commentzJuliaCodePrinter._get_commentW   s   € Ø�}‰}˜TÓ"Ð"rn   c                ó&   — dj                  ||«      S )Nzconst {} = {}rx   )ri   ÚnameÚvalues      rm   Ú_declare_number_constz&JuliaCodePrinter._declare_number_const[   s   € Ø×%Ñ% d¨EÓ2Ð2rn   c                ó$   — | j                  |«      S ©N)Úindent_code)ri   Úliness     rm   Ú_format_codezJuliaCodePrinter._format_code_   s   € Ø×Ñ Ó&Ð&rn   c                óJ   ‡— |j                   \  Š}ˆfd„t        |«      D «       S )Nc              3  óF   •K  — | ]  }t        ‰«      D ]  }||f–— Œ
 Œ y ­wr�   )Úrange)Ú.0ÚjÚiÚrowss      €rm   ú	<genexpr>z<JuliaCodePrinter._traverse_matrix_indices.<locals>.<genexpr>f   s%   øè ø€ ÒA˜1´U¸4³[ÒA°��A”ÐA�ÑAùs   ƒ!)Úshaper‡   )ri   ÚmatÚcolsr‹   s      @rm   Ú_traverse_matrix_indicesz)JuliaCodePrinter._traverse_matrix_indicesc   s   ø€ à—Y‘Y‰
ˆˆdÛA¤ d£ÔAÐArn   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)ri   ÚindicesÚ
open_linesÚclose_linesrŠ   ÚvarÚstartÚstops           rm   Ú_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Õ%ð	&ð ˜;Ð&Ð&rn   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        rm   Úmultjoinz-JuliaCodePrinter._print_Mul.<locals>.multjoin®   sS   € à�a‘ˆAÜ˜1œc !›fÓ%ò 7�Ø ! ! A¡#¡× 0Ò 0™°d�Ú"#¢V¨U°1ªXÐ6‘ð7ð ˆHrn   ú/ú./r­   c              3  ó4   K  — | ]  }|j                   –— Œ y ­wr�   ©r¯   )rˆ   Úbis     rm   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ÚInfinityrr   r   ÚqÚOneÚparenthesizeÚindexÚall)ri   ÚexprÚprecÚcÚer*   r°   ÚbÚ	pow_parenrÈ   ÚitemÚxr±   Úb_strr´   Údivsyms                   rm   Ú
_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_opry   )ri   rÐ   Úlhs_codeÚrhs_codeÚops        rm   Ú_print_Relationalz"JuliaCodePrinter._print_Relational¿   sD   € Ø—;‘;˜tŸx™xÓ(ˆØ—;‘;˜tŸx™xÓ(ˆØ�[‰[ˆØ× Ñ  ¨2¨xÓ8Ð8rn   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     rm   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Í   )ri   rÐ   Ú	powsymbolÚPRECÚsyms        rm   Ú
_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Ô<ð>ð 	>rn   c                óŽ   — t        |«      }| j                  |j                  |«      ›d| j                  |j                  |«      ›�S )Nz ^ )r   rÍ   rÇ   r-   ©ri   rÐ   rç   s      rm   Ú_print_MatPowzJuliaCodePrinter._print_MatPowÙ   s>   € Ü˜$ÓˆØ ×-Ñ-¨d¯i©i¸Õ>Ø×+Ñ+¨D¯H©H°dÔ;ð=ð 	=rn   c                óB   •— | j                   d   ryt        ‰| �	  |«      S )Nr]   Úpi©Ú	_settingsr`   Ú_print_NumberSymbol©ri   rÐ   rl   s     €rm   Ú	_print_PizJuliaCodePrinter._print_Piß   s"   ø€ Ø�>‰>˜(Ò#Øä‘7Ñ.¨tÓ4Ð4rn   c                 ó   — y)NrO   rq   ©ri   rÐ   s     rm   Ú_print_ImaginaryUnitz%JuliaCodePrinter._print_ImaginaryUnitæ   s   € Ørn   c                óB   •— | j                   d   ryt        ‰| �	  |«      S )Nr]   rÓ   rï   rò   s     €rm   Ú_print_Exp1zJuliaCodePrinter._print_Exp1ê   s"   ø€ Ø�>‰>˜(Ò#Øä‘7Ñ.¨tÓ4Ð4rn   c                óB   •— | j                   d   ryt        ‰| �	  |«      S )Nr]   Ú
eulergammarï   rò   s     €rm   Ú_print_EulerGammaz"JuliaCodePrinter._print_EulerGammañ   s"   ø€ Ø�>‰>˜(Ò#Øä‘7Ñ.¨tÓ4Ð4rn   c                óB   •— | j                   d   ryt        ‰| �	  |«      S )Nr]   Úcatalanrï   rò   s     €rm   Ú_print_CatalanzJuliaCodePrinter._print_Catalanø   s"   ø€ Ø�>‰>˜(Ò#Øä‘7Ñ.¨tÓ4Ð4rn   c                óB   •— | j                   d   ryt        ‰| �	  |«      S )Nr]   Úgoldenrï   rò   s     €rm   Ú_print_GoldenRatioz#JuliaCodePrinter._print_GoldenRatioÿ   s"   ø€ Ø�>‰>˜(Ò#Øä‘7Ñ.¨tÓ4Ð4rn   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›   rc   r—   ÚhasÚ_doprint_loopsrv   )ri   rÐ   r  r  r  rÜ   rÝ   ÚexpressionsÚ
conditionsrÓ   rÒ   Útemprß   rà   s                 rm   Ú_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ÐHrn   c                 ó   — y)NÚInfrq   rõ   s     rm   Ú_print_Infinityz JuliaCodePrinter._print_Infinity#  ó   € Ørn   c                 ó   — y)Nz-Infrq   rõ   s     rm   Ú_print_NegativeInfinityz(JuliaCodePrinter._print_NegativeInfinity'  ó   € Ørn   c                 ó   — y)NÚNaNrq   rõ   s     rm   Ú
_print_NaNzJuliaCodePrinter._print_NaN+  r  rn   c                óD   ‡ — ddj                  ˆ fd„|D «       «      z   dz   S )NzAny[ú, c              3  ó@   •K  — | ]  }‰j                  |«      –— Œ y ­wr�   )r—   )rˆ   r°   ri   s     €rm   rŒ   z/JuliaCodePrinter._print_list.<locals>.<genexpr>0  s   øè ø€ Ò!?°Q $§+¡+¨a§.Ñ!?ùs   ƒú])Újoinrõ   s   ` rm   Ú_print_listzJuliaCodePrinter._print_list/  s"   ø€ Ø˜Ÿ	™	Ó!?¸$Ô!?Ó?Ñ?À#ÑEÐErn   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     rm   Ú_print_tuplezJuliaCodePrinter._print_tuple3  s;   € Üˆt‹9˜Š>Ø˜TŸ[™[¨¨a©Ó1Ñ1Ð1à˜DŸN™N¨4°Ó6Ñ6Ð6rn   c                 ó   — y)NÚtruerq   rõ   s     rm   Ú_print_BooleanTruez#JuliaCodePrinter._print_BooleanTrue;  r  rn   c                 ó   — y)NÚfalserq   rõ   s     rm   Ú_print_BooleanFalsez$JuliaCodePrinter._print_BooleanFalse?  s   € Ørn   c                ó4   — t        |«      j                  «       S r�   )Ústrr™   rõ   s     rm   Ú_print_boolzJuliaCodePrinter._print_boolC  s   € Ü�4‹y�‰Ó Ð rn   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—   )ri   ÚAr°   s      rm   Ú_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.matricesr5  Úcol_listr—   r‹   r�   )ri   r2  r5  ÚLÚkÚIÚJÚAIJs           rm   Ú_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     rm   Ú_print_MatrixElementz%JuliaCodePrinter._print_MatrixElemente  sB   € Ø× Ñ  §¡¬j¸Ñ.@ÈÐ ÔNØŸ6™6 A›: t§v¡v°£zÐ2ñ3ð 	3rn   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’   r6  r•   r”   )r—   r  )r×   ÚlimÚlÚhÚstepÚlstrÚhstrri   s          €rm   Ú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¸$Ð ?Ó@Ð@rn   rB  r   rC  r’   r  )r—   rD  Úrowslicer�   Úcolslice)ri   rÐ   rN  s   `  rm   Ú_print_MatrixSlicez#JuliaCodePrinter._print_MatrixSlicej  s|   ø€ ô	Að —‘˜DŸK™KÓ(¨3Ñ.Ù˜Ÿ™¨¯©×(9Ñ(9¸!Ñ(<Ó=ñ>Ø@CñDá˜Ÿ™¨¯©×(9Ñ(9¸!Ñ(<Ó=ñ>à@CñDð 	Ern   c                óÐ   — |j                   D �cg c]  }| j                  |«      ‘Œ }}| j                  |j                  j                  «      ›ddj	                  |«      ›d�S c c}w )NrB  rC  r  )rœ   r—   rÇ   r˜   r  )ri   rÐ   rŠ   Úindss       rm   Ú_print_IndexedzJuliaCodePrinter._print_Indexed  sJ   € Ø)-¯©Ö7 A�—‘˜Q•Ð7ˆÐ7ØŸ;™; t§y¡y§¡Õ7¸¿¹À$½ÐHÐHùò 8s   �A#c                ó8   — | j                  |j                  «      S r�   )r—   r˜   rõ   s     rm   Ú
_print_IdxzJuliaCodePrinter._print_Idx„  s   € Ø�{‰{˜4Ÿ:™:Ó&Ð&rn   c                óD   — d| j                  |j                  d   «      z  S )Nzeye(%s)r   )r—   r�   rõ   s     rm   Ú_print_Identityz JuliaCodePrinter._print_Identityˆ  s   € Ø˜4Ÿ;™; t§z¡z°!¡}Ó5Ñ5Ð5rn   c                ó�   — dj                  |j                  D �cg c]  }| j                  |t        |«      «      ‘Œ c}«      S c c}w )Nz .* )r  rÈ   rÍ   r   )ri   rÐ   Úargs      rm   Ú_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      rm   Ú_print_HadamardPowerz%JuliaCodePrinter._print_HadamardPower�  sJ   € Ü˜$ÓˆØ�z‰zØ×Ñ˜dŸi™i¨Ó.Ø×Ñ˜dŸh™h¨Ó-ðó ð 	rn   c                ó€   — |j                   dk(  rt        |j                  «      S |j                  ›d|j                   ›�S )Nr’   z // )rË   r)  rr   rõ   s     rm   Ú_print_Rationalz JuliaCodePrinter._print_Rational–  s.   € Ø�6‰6�QŠ;Ü�t—v‘v“;ÐØ!ŸV›V T§V¢VÐ,Ð,rn   c                óÎ   — ddl m}m} |j                  } |t        j
                  d|z  z  «       ||j                  t        j                  z   |«      z  }| j                  |«      S )Nr   )r/   r=   r6  )	Úsympy.functionsr/   r=   Úargumentr   ÚPirÀ   ÚHalfr—   )ri   rÐ   r/   r=   r×   Úexpr2s         rm   Ú	_print_jnzJuliaCodePrinter._print_jnœ  óL   € ß1Ø�M‰MˆÙ”Q—T‘T˜1˜Q™3‘ZÓ ¡¨¯©´a·f±fÑ)<¸aÓ!@Ñ@ˆØ�{‰{˜5Ó!Ð!rn   c                óÎ   — ddl m}m} |j                  } |t        j
                  d|z  z  «       ||j                  t        j                  z   |«      z  }| j                  |«      S )Nr   )r/   r>   r6  )	ra  r/   r>   rb  r   rc  rÀ   rd  r—   )ri   rÐ   r/   r>   r×   re  s         rm   Ú	_print_ynzJuliaCodePrinter._print_yn£  rg  rn   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ð   ry   r—   rÐ   r  Ú	enumerater›   r®   )
ri   rÐ   rƒ   rÓ   rÒ   ÚecpairsÚelastÚpwrŠ   Úcode0s
             rm   Ú_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ˆ   rZ  rÐ   ri   s     €€rm   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È   )ri   rÐ   rÒ   Úmr*   rP   rO   s   ``     rm   Ú_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ó
ñ 
ð 	
rn   c           	     óF  ‡— t        |t        «      r1| j                  |j                  d«      «      }dj	                  |«      S d}d}d}|D �cg c]  }|j                  d«      ‘Œ }}|D �‡cg c]  Št        t        ˆfd„|D «       «      «      ‘Œ! }}|D �‡cg c]  Št        t        ˆfd„|D «       «      «      ‘Œ! }}g }	d	}
t        |«      D ]C  \  }Š‰d
v r|	j                  ‰«       Œ|
||   z  }
|	j                  ||
z  ›‰›�«       |
||   z  }
ŒE |	S c c}w c c}w c c}w )z0Accepts a string of code or a list of code linesTr¥   z    )z
^function z^if ú^elseif ú^else$z^for )z^end$r~  r  z 	c              3  ó6   •K  — | ]  }t        |‰«      –— Œ y ­wr�   r   ©rˆ   rP   Úlines     €rm   rŒ   z/JuliaCodePrinter.indent_code.<locals>.<genexpr>ï  ó   øè ø€ ÒB°"œV B¨×-ÑBùó   ƒc              3  ó6   •K  — | ]  }t        |‰«      –— Œ y ­wr�   r   r�  s     €rm   rŒ   z/JuliaCodePrinter.indent_code.<locals>.<genexpr>ñ  rƒ  r„  r   )r¥   rk  )
rÉ   r)  r‚   Ú
splitlinesr  ÚlstripÚintÚanyrp  r›   )ri   ÚcodeÚ
code_linesÚtabÚ	inc_regexÚ	dec_regexr‚  ÚincreaseÚdecreaseÚprettyÚlevelÚns         `     rm   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Ú
_operatorsrb   r   r^   Ú__annotations__ra   rs   rv   r{   r   r„   r�   r¢   rÚ   râ   ré   rì   ró   rö   rø   rû   rþ   r  r  r  r  r  r  r!  Ú_print_Tupler$  r'  r*  r3  r>  rE  rQ  rT  rV  rX  r[  r]  r_  rf  ri  ru  r|  r‚   Ú__classcell__)rl   s   @rm   rR   rR   0   sA  ø… ñð €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òò-ò"ò"ò"$òH
ö$rn   rR   Nc                ó8   — t        |«      j                  | |«      S )a)  Converts `expr` to a string of Julia code.

    Parameters
    ==========

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

    Examples
    ========

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    >>> from sympy import Eq, IndexedBase, Idx
    >>> len_y = 5
    >>> y = IndexedBase('y', shape=(len_y,))
    >>> t = IndexedBase('t', shape=(len_y,))
    >>> Dy = IndexedBase('Dy', shape=(len_y-1,))
    >>> i = Idx('i', len_y-1)
    >>> e = Eq(Dy[i], (y[i+1]-y[i])/(t[i+1]-t[i]))
    >>> julia_code(e.rhs, assign_to=e.lhs, contract=False)
    'Dy[i] = (y[i + 1] - y[i]) ./ (t[i + 1] - t[i])'
    )rR   Údoprint)rÐ   Ú	assign_torj   s      rm   Ú
julia_coder¡     s   € ôL ˜HÓ%×-Ñ-¨d°IÓ>Ð>rn   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Ð   rj   s     rm   Úprint_julia_coder¤  ‰  s   € ô
 
Œ*�TÑ
&˜XÑ
&Õ'rn   r�   )r—  Ú
__future__r   Útypingr   Ú
sympy.corer   r   r   r   Úsympy.core.mulr	   Úsympy.core.numbersr
   Úsympy.printing.codeprinterr   Úsympy.printing.precedencer   r   rP   r   rd   rg   rR   r¡  r¤  rq   rn   rm   ú<module>r¬     sg   ðñ	õ #Ý ç ,Ó ,Ý &Ý +Ý 2ß <Ý ò
(€ð ØØØØØ
Ø
ñ€ôM�{ô Mó`F?óR(rn   