§
    ^²ÅjûR  ã                  óP  — 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 i dd“dd	“d
d“dd“dd„ ddfd„ ddfd„ ddfd„ ddfd„ ddfd„ ddfd„ ddfg“d d!„ d dfg“d"d#“d$d%“d&d'“d(d(“d)d)“d*d*“d+d+“d,d,“d-d-“d.d.“d/d/“d0d1d2d3d4dd5œ¥Zg d6¢Z G d7„ d8e¦  «        Zd<d:„Zd;„ Zd9S )=a  
Rust code printer

The `RustCodePrinter` converts SymPy expressions into Rust expressions.

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

é    )Úannotations)ÚAny)ÚSÚRationalÚFloatÚLambda©Úequal_valued)ÚCodePrinterÚfloorÚceilingÚceilÚAbsÚabsÚsignÚsignumÚPowc                ó"   — t          |d¦  «        S )Néÿÿÿÿr	   ©ÚbaseÚexps     úDC:\Projects\Historical\venv\Lib\site-packages\sympy/printing/rust.pyú<lambda>r   I   s   € �|¨C°Ñ4Ô4€ ó    Úrecipé   c                ó"   — t          |d¦  «        S )Ng      à?r	   r   s     r   r   r   J   s   € �|¨C°Ñ5Ô5€ r   Úsqrtc                ó"   — t          |d¦  «        S )Ng      à¿r	   r   s     r   r   r   K   s   € �|¨C°Ñ6Ô6€ r   zsqrt().recipc                ó*   — |t          dd¦  «        k    S )Né   é   )r   r   s     r   r   r   L   s   € ˜s¥h¨q°!¡n¤nÒ4€ r   Úcbrtc                ó"   — t          | d¦  «        S )Nr   r	   r   s     r   r   r   M   s   € �|¨D°!Ñ4Ô4€ r   Úexp2r#   c                ó   — |j         S ©N©Ú
is_integerr   s     r   r   r   N   s   € ˜sœ~€ r   Úpowir"   c                ó   — |j          S r(   r)   r   s     r   r   r   O   s   €  3¤>Ð1€ r   Úpowfr   c                ó   — dS )NT© )r   s    r   r   r   P   s   € ˜€ r   ÚlogÚlnÚMaxÚmaxÚMinÚminÚsinÚcosÚtanÚasinÚacosÚatanÚatan2ÚsinhÚcoshÚtanhÚasinhÚacoshÚatanh)r>   r?   r@   rA   rB   r   )4ÚabstractÚalignofÚasÚbecomeÚboxÚbreakÚconstÚcontinueÚcrateÚdoÚelseÚenumÚexternÚfalseÚfinalÚfnÚforÚifÚimplÚinÚletÚloopÚmacroÚmatchÚmodÚmoveÚmutÚoffsetofÚoverrideÚprivÚprocÚpubÚpureÚrefÚreturnÚSelfÚselfÚsizeofÚstaticÚstructÚsuperÚtraitÚtrueÚtypeÚtypeofÚunsafeÚunsizedÚuseÚvirtualÚwhereÚwhileÚyieldc            	      óR  ‡ — e Zd ZU dZdZdZ eej        fi di d e	¦   «         dœ¤ŽZde
d<   i fd	„Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd,ˆ fd„	Zd,ˆ fd„	Zd„ Zd„ Zd„ Zd„ Zd„ Zd,d„Zd,d„Zd,d„Zd,d„Z d,d „Z!d,d!„Z"d,d"„Z#d,d#„Z$d$„ Z%d%„ Z&d&„ Z'd'„ Z(d(„ Z)ˆ fd)„Z*d*„ Z+d+„ Z,ˆ xZ-S )-ÚRustCodePrinterz>A printer to convert SymPy expressions to strings of Rust codeÚ
_rust_codeÚRusté   T)Ú	precisionÚuser_functionsÚcontractÚdereferencezdict[str, Any]Ú_default_settingsc                óD  — t          j        | |¦  «         t          t          ¦  «        | _        |                     di ¦  «        }| j                             |¦  «         t          |                     dg ¦  «        ¦  «        | _        t          t          ¦  «        | _        d S )Nr}   r   )	r   Ú__init__ÚdictÚknown_functionsÚgetÚupdateÚsetÚ_dereferenceÚreserved_words)rg   ÚsettingsÚ	userfuncss      r   r‚   zRustCodePrinter.__init__ç   s„   € ÝÔ˜T 8Ñ,Ô,Ð,Ý#¥OÑ4Ô4ˆÔØ—L’LÐ!1°2Ñ6Ô6ˆ	ØÔ×#Ò# IÑ.Ô.Ð.Ý §¢¨]¸BÑ ?Ô ?Ñ@Ô@ˆÔÝ!¥.Ñ1Ô1ˆÔÐÐr   c                ó   — |dz  S )Né   r/   )rg   Úps     r   Ú_rate_index_positionz$RustCodePrinter._rate_index_positionï   s   € Ø�‰sˆ
r   c                ó   — d|z  S )Nz%s;r/   )rg   Ú
codestrings     r   Ú_get_statementzRustCodePrinter._get_statementò   s   € Ø�zÑ!Ð!r   c                ó   — d|z  S )Nz// %sr/   )rg   Útexts     r   Ú_get_commentzRustCodePrinter._get_commentõ   s   € Ø˜‰~Ðr   c                ó   — d|›d|›d�S )Nzconst z: f64 = ú;r/   )rg   ÚnameÚvalues      r   Ú_declare_number_constz%RustCodePrinter._declare_number_constø   s   € € Ø(,¨¨¨e¨e¨eÐ4Ð4r   c                ó,   — |                       |¦  «        S r(   )Úindent_code)rg   Úliness     r   Ú_format_codezRustCodePrinter._format_codeû   s   € Ø×Ò Ñ&Ô&Ð&r   c                óN   ‡— |j         \  }Šˆfd„t          |¦  «        D ¦   «         S )Nc              3  óD   •K  — | ]}t          ‰¦  «        D ]}||fV — Œ	Œd S r(   )Úrange)Ú.0ÚiÚjÚcolss      €r   ú	<genexpr>z;RustCodePrinter._traverse_matrix_indices.<locals>.<genexpr>   s:   øè è € ÐAÐA˜1µU¸4±[´[ÐAÐA°��A�ÐAÐAÐAÐAÐAÐAÐAr   )Úshaper¡   )rg   ÚmatÚrowsr¥   s      @r   Ú_traverse_matrix_indicesz(RustCodePrinter._traverse_matrix_indicesþ   s.   ø€ Ø”Y‰
ˆˆdØAÐAÐAÐA¥ d¡¤ÐAÑAÔAÐAr   c           
     ó  — g }g }d}|D ]y}|                      ||                      |¦  «        |                      |j        ¦  «        |                      |j        dz   ¦  «        dœz  ¦  «         |                      d¦  «         Œz||fS )Nz#for %(var)s in %(start)s..%(end)s {r"   )ÚvarÚstartÚendÚ})ÚappendÚ_printÚlowerÚupper)rg   ÚindicesÚ
open_linesÚclose_linesÚ	loopstartr£   s         r   Ú_get_loop_opening_endingz(RustCodePrinter._get_loop_opening_ending  s    € Øˆ
ØˆØ9ˆ	Øð 	$ð 	$ˆAà×Ò˜iØ—{’{ 1‘~”~ØŸš Q¤WÑ-Ô-Ø—{’{ 1¤7¨Q¡;Ñ/Ô/ð+1ð +1ñ 1ñ 2ô 2ð 2ð ×Ò˜sÑ#Ô#Ð#Ð#Ø˜;Ð&Ð&r   c                óÎ   — t          |j        ¦  «        dk    rd|                      |¦  «        z   dz   S |j        r|                      |d¬¦  «        S |                      |¦  «        S )Nr"   ú(ú)T)Ú_type)ÚlenÚargsr±   Ú	is_number©rg   Úexprs     r   Ú_print_caller_varz!RustCodePrinter._print_caller_var  se   € ÝˆtŒy‰>Œ>˜AÒÐð ˜Ÿš TÑ*Ô*Ñ*¨SÑ0Ð0ØŒ^ð 	%Ø—;’;˜t¨4�;Ñ0Ô0Ð0à—;’;˜tÑ$Ô$Ð$r   c                ód  ‡ — |j         j        ‰ j        v �r2‰ j        |j         j                 }d}d}t          |t          ¦  «        r|}n|D ]\  }}} ||j        Ž r nŒ|�æ|dk    rcd‰                      |j        d         ¦  «        |t          |j        ¦  «        dk    r#‰                      |j        dd…         d¦  «        nddœz  }n{|dk    r'd	‰                      |j        d         ¦  «        |d
œz  }nN|dk    r'd	‰                      |j        d         ¦  «        |d
œz  }n!d|‰                      |j        d¦  «        dœz  }|S dS t          |d¦  «        r<t          |j
        t          ¦  «        r"‰                       |j
        |j        Ž ¦  «        S |j         j        ‰ j        v rv‰ j        |j         j                 \  }}‰                      |¦  «        rCt          ˆ fd„|D ¦   «         ¦  «        r*‰                      |                     |¦  «        ¦  «        S dS dS ‰                      |¦  «        S )a<  
        basic function for printing `Function`

        Function Style :

        1. args[0].func(args[1:]), method with arguments
        2. args[0].func(), method without arguments
        3. args[1].func(), method without arguments (e.g. (e, x) => x.exp())
        4. func(args), function with arguments
        Nr"   z%(var)s.%(method)s(%(args)s)r   ú, Ú )r¬   Úmethodr¾   r   z%(var)s.%(method)s())r¬   rÆ   r#   z%(func)s(%(args)s))Úfuncr¾   Ú_imp_c              3  óB   •K  — | ]}‰                      |¦  «        V — Œd S r(   )Ú
_can_print)r¢   Úfrg   s     €r   r¦   z2RustCodePrinter._print_Function.<locals>.<genexpr>M  s/   øè è € Ð0YÐ0YÈ°·²ÀÑ1CÔ1CÐ0YÐ0YÐ0YÐ0YÐ0YÐ0Yr   )rÇ   Ú__name__r„   Ú
isinstanceÚstrr¾   rÂ   r½   Ú	stringifyÚhasattrrÈ   r   r±   Ú_rewriteable_functionsrÊ   ÚallÚrewriteÚ_print_not_supported)	rg   rÁ   Ú	cond_funcrÇ   ÚstyleÚcondÚretÚtarget_fÚrequired_fss	   `        r   Ú_print_FunctionzRustCodePrinter._print_Function  s�  ø€ ð Œ9Ô Ô!5Ð5Ñ5ØÔ,¨T¬YÔ-?Ô@ˆIØˆDØˆEÝ˜)¥SÑ)Ô)ð Ø ��à)2ð ð Ñ%�D˜$ Ø�t˜TœYÐ'ð Ø˜ðàÐØ˜A’:�:Ø8Ø#×5Ò5°d´iÀ´lÑCÔCØ"&ÝGJÈ4Ì9Á~Ä~ÐXYÒGYÐGY §¢¨t¬y¸¸¸¬}¸dÑ CÔ CÐ CÐ_að<ð <ñ �C�Cð
 ˜a’Z�ZØ0Ø#×5Ò5°d´iÀ´lÑCÔCØ"&ð4ð 4ñ �C�Cð ˜a’Z�ZØ0Ø#×5Ò5°d´iÀ´lÑCÔCØ"&ð4ð 4ñ �C�Cð
 /Ø $Ø $§¢¨t¬y¸$Ñ ?Ô ?ð2ð 2ñ �Cð �
ð-  Ðõ. �T˜7Ñ#Ô#ð 		3­
°4´:½vÑ(FÔ(Fð 		3à—;’;˜z˜tœz¨4¬9Ð5Ñ6Ô6Ð6ØŒYÔ 4Ô#>Ð>Ð>à$(Ô$?ÀÄ	Ô@RÔ$SÑ!ˆH�kØ�Š˜xÑ(Ô(ð ;­SÐ0YÐ0YÐ0YÐ0YÈ[Ð0YÑ0YÔ0YÑ-YÔ-Yð ;Ø—{’{ 4§<¢<°Ñ#9Ô#9Ñ:Ô:Ð:ð;ð ;ð ;ð ;ð ×,Ò,¨TÑ2Ô2Ð2r   c                óæ   — |j         j        rQ|j        j        sE t          |¦  «        t	          |j         ¦  «        |j        ¦  «        }|                      |¦  «        S |                      |¦  «        S r(   )r   r*   r   rn   r   r±   rÛ   rÀ   s     r   Ú
_print_PowzRustCodePrinter._print_PowR  sd   € ØŒ9Ôð 	%¨¬Ô(;ð 	%Ø•4˜‘:”:�e D¤IÑ.Ô.°´Ñ9Ô9ˆDØ—;’;˜tÑ$Ô$Ð$Ø×#Ò# DÑ)Ô)Ð)r   Fc                óX   •— t          ¦   «                              |¦  «        }|r|dz   S |S )NÚ_f64)rk   Ú_print_Float©rg   rÁ   r¼   rØ   Ú	__class__s       €r   rà   zRustCodePrinter._print_FloatX  s1   ø€ Ý‰gŒg×"Ò" 4Ñ(Ô(ˆØð 	Ø˜‘<ÐàˆJr   c                óX   •— t          ¦   «                              |¦  «        }|r|dz   S |S )NÚ_i32)rk   Ú_print_Integerrá   s       €r   rå   zRustCodePrinter._print_Integer_  s1   ø€ Ý‰gŒg×$Ò$ TÑ*Ô*ˆØð 	Ø˜‘<ÐàˆJr   c                ó`   — t          |j        ¦  «        t          |j        ¦  «        }}d||fz  S )Nz%d_f64/%d.0)ÚintrŽ   Úq)rg   rÁ   rŽ   rè   s       r   Ú_print_RationalzRustCodePrinter._print_Rationalf  s*   € Ý�4”6‰{Œ{�C ¤™KœKˆ1ˆØ  1˜vÑ%Ð%r   c                ó¦   — |                       |j        ¦  «        }|                       |j        ¦  «        }|j        }d                     |||¦  «        S )Nz{} {} {})r±   ÚlhsÚrhsÚrel_opÚformat)rg   rÁ   Úlhs_codeÚrhs_codeÚops        r   Ú_print_Relationalz!RustCodePrinter._print_Relationalj  sG   € Ø—;’;˜tœxÑ(Ô(ˆØ—;’;˜tœxÑ(Ô(ˆØŒ[ˆØ× Ò  ¨2¨xÑ8Ô8Ð8r   c                ó4  — |j         }t          j        }t          j        }t	          t          |j        ¦  «        ¦  «        D ] }||j        |         |z  z  }|||         z  }Œ!|                      |j	        j
        ¦  «        ›d|                      |¦  «        ›d�S )Nú[ú])r§   r   ÚZeroÚOneÚreversedr¡   Úrankr´   r±   r   Úlabel)rg   rÁ   ÚdimsÚelemÚoffsetr£   s         r   Ú_print_IndexedzRustCodePrinter._print_Indexedp  s�   € àŒzˆÝŒvˆÝ”ˆÝ�% ¤	Ñ*Ô*Ñ+Ô+ð 	ð 	ˆAØ�D”L ”O FÑ*Ñ*ˆDØ�d˜1”gÑˆFˆFØŸ;š; t¤y¤Ñ7Ô7Ð7Ð7¸¿ºÀTÑ9JÔ9JÐ9JÐ9JÐKÐKr   c                ó   — |j         j        S r(   )rú   r˜   rÀ   s     r   Ú
_print_IdxzRustCodePrinter._print_Idxz  s   € ØŒzŒÐr   c                ó   — |j         S r(   )r˜   rÀ   s     r   Ú_print_DummyzRustCodePrinter._print_Dummy}  s
   € ØŒyÐr   c                ó   — dS )NÚEr/   ©rg   rÁ   r¼   s      r   Ú_print_Exp1zRustCodePrinter._print_Exp1€  s   € Øˆsr   c                ó   — dS )NÚPIr/   r  s      r   Ú	_print_PizRustCodePrinter._print_Piƒ  s   € Øˆtr   c                ó   — dS )NÚINFINITYr/   r  s      r   Ú_print_InfinityzRustCodePrinter._print_Infinity†  s   € Øˆzr   c                ó   — dS )NÚNEG_INFINITYr/   r  s      r   Ú_print_NegativeInfinityz'RustCodePrinter._print_NegativeInfinity‰  s   € Øˆ~r   c                ó   — dS )Nrm   r/   r  s      r   Ú_print_BooleanTruez"RustCodePrinter._print_BooleanTrueŒ  s   € Øˆvr   c                ó   — dS )NrP   r/   r  s      r   Ú_print_BooleanFalsez#RustCodePrinter._print_BooleanFalse�  s   € Øˆwr   c                óD   — t          |¦  «                             ¦   «         S r(   )rÎ   r²   r  s      r   Ú_print_boolzRustCodePrinter._print_bool’  s   € Ý�4‰yŒy�ŠÑ Ô Ð r   c                ó   — dS )NÚNANr/   r  s      r   Ú
_print_NaNzRustCodePrinter._print_NaN•  s   € Øˆur   c                óŠ  — |j         d         j        dk    rt          d¦  «        ‚g }t          |j         ¦  «        D ]Ñ\  }\  }}|dk    r,|                     d|                      |¦  «        z  ¦  «         nX|t          |j         ¦  «        dz
  k    r|dk    r|dxx         dz  cc<   n&|dxx         d|                      |¦  «        z  z  cc<   |                      |¦  «        }|                     |¦  «         |                     d	¦  «         ŒÒ| j        d
         rd                     |¦  «        S d                     |¦  «        S )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	if (%s) {r"   z else {z else if (%s) {r¯   Úinlineú ú
)	r¾   r×   Ú
ValueErrorÚ	enumerater°   r±   r½   Ú	_settingsÚjoin)rg   rÁ   r�   r£   ÚeÚcÚcode0s          r   Ú_print_Piecewisez RustCodePrinter._print_Piecewise˜  sI  € ØŒ9�RŒ=Ô Ò%Ð%õ ð /ñ 0ô 0ð 0ð
 ˆå" 4¤9Ñ-Ô-ð 		ð 		‰IˆA‰v��1Ø�AŠvˆvØ—’˜[¨4¯;ª;°q©>¬>Ñ9Ñ:Ô:Ð:Ð:Ø•c˜$œ)‘n”n qÑ(Ò(Ð(¨Q°$ªY¨YØ�b�	�	”	˜YÑ&�	�	‘	�	à�b�	�	”	Ð.°·²¸Q±´Ñ?Ñ?�	�	‘	Ø—K’K ‘N”NˆEØ�LŠL˜ÑÔÐØ�LŠL˜ÑÔÐÐàŒ>˜(Ô#ð 	$Ø—8’8˜E‘?”?Ð"à—9’9˜UÑ#Ô#Ð#r   c                ób   — ddl m} |                      |                     |d¬¦  «        ¦  «        S )Nr   )Ú	PiecewiseF)Údeep)Úsympy.functionsr&  r±   rÓ   )rg   rÁ   r&  s      r   Ú
_print_ITEzRustCodePrinter._print_ITE³  s6   € Ø-Ð-Ð-Ð-Ð-Ð-Ø�{Š{˜4Ÿ<š<¨	¸˜<Ñ>Ô>Ñ?Ô?Ð?r   c                ó€   ‡ — |j         dk    r$dd                     ˆ fd„|D ¦   «         ¦  «        z  S t          d¦  «        ‚)Nr"   z[%s]rÄ   c              3  óB   •K  — | ]}‰                      |¦  «        V — Œd S r(   )r±   )r¢   Úarg   s     €r   r¦   z4RustCodePrinter._print_MatrixBase.<locals>.<genexpr>¹  s-   øè è € Ð%@Ð%@¸ d§k¢k°!¡n¤nÐ%@Ð%@Ð%@Ð%@Ð%@Ð%@r   zLFull Matrix Support in Rust need Crates (https://crates.io/keywords/matrix).)r¥   r   r  )rg   ÚAs   ` r   Ú_print_MatrixBasez!RustCodePrinter._print_MatrixBase·  sI   ø€ ØŒ6�QŠ;ˆ;Ø˜DŸIšIÐ%@Ð%@Ð%@Ð%@¸aÐ%@Ñ%@Ô%@Ñ@Ô@Ñ@Ð@åÐkÑlÔlÐlr   c                ó,   — |                       |¦  «        S r(   )rÔ   )rg   r¨   s     r   Ú_print_SparseRepMatrixz&RustCodePrinter._print_SparseRepMatrix½  s   € à×(Ò(¨Ñ-Ô-Ð-r   c                ó\   — |j         ›d|j        |j        |j         j        d         z  z   ›d�S )Nrô   r"   rõ   )Úparentr¤   r£   r§   rÀ   s     r   Ú_print_MatrixElementz$RustCodePrinter._print_MatrixElementÁ  s8   € Øœ;˜;˜;Øœ6 D¤F¨4¬;Ô+<¸QÔ+?Ñ$?Ñ?Ð?Ð?ðAð 	Ar   c                óf   •— t          ¦   «                              |¦  «        }|| j        v rd|z  S |S )Nz(*%s))rk   Ú_print_Symbolrˆ   )rg   rÁ   r˜   râ   s      €r   r5  zRustCodePrinter._print_SymbolÅ  s7   ø€ å‰wŒw×$Ò$ TÑ*Ô*ˆà�4Ô$Ð$Ð$Ø˜T‘>Ð!àˆKr   c                óL  — ddl m} |j        }|j        }| j        d         r@|                     |¦  «        s|                     |¦  «        r|                      ||¦  «        S |                      |¦  «        }|                      |¦  «        }|                      |›d|›�¦  «        S )Nr   )ÚIndexedBaser~   z = )	Úsympy.tensor.indexedr7  rë   rì   r  ÚhasÚ_doprint_loopsr±   r’   )rg   rÁ   r7  rë   rì   rï   rð   s          r   Ú_print_Assignmentz!RustCodePrinter._print_AssignmentÎ  s´   € Ø4Ð4Ð4Ð4Ð4Ð4ØŒhˆØŒhˆØŒ>˜*Ô%ð 	I¨3¯7ª7°;Ñ+?Ô+?ð 	IØ—’˜Ñ$Ô$ð	Ið ×&Ò& s¨CÑ0Ô0Ð0à—{’{ 3Ñ'Ô'ˆHØ—{’{ 3Ñ'Ô'ˆHØ×&Ò&°H°H°H¸h¸hÐ'GÑHÔHÐHr   c                óÔ  ‡
‡— t          |t          ¦  «        r=|                      |                     d¦  «        ¦  «        }d                     |¦  «        S d}dŠdŠ
d„ |D ¦   «         }ˆfd„|D ¦   «         }ˆ
fd„|D ¦   «         }g }d	}t          |¦  «        D ]Q\  }}	|	d
v r|                     |	¦  «         Œ|||         z  }|                     ||z  ›|	›�¦  «         |||         z  }ŒR|S )z0Accepts a string of code or a list of code linesTrÅ   z    )Ú{rº   z{
z(
)r¯   r»   c                ó8   — g | ]}|                      d ¦  «        ‘ŒS )z 	)Úlstrip)r¢   Úlines     r   ú
<listcomp>z/RustCodePrinter.indent_code.<locals>.<listcomp>ç  s$   € Ð6Ð6Ð6¨�—’˜UÑ#Ô#Ð6Ð6Ð6r   c           
     ón   •— g | ]1}t          t          t          |j        ‰¦  «        ¦  «        ¦  «        ‘Œ2S r/   )rç   ÚanyÚmapÚendswith)r¢   r@  Ú	inc_tokens     €r   rA  z/RustCodePrinter.indent_code.<locals>.<listcomp>é  s5   ø€ ÐOÐOÐOÀ•S��S ¤°	Ñ:Ô:Ñ;Ô;Ñ<Ô<ÐOÐOÐOr   c           
     ón   •— g | ]1}t          t          t          |j        ‰¦  «        ¦  «        ¦  «        ‘Œ2S r/   )rç   rC  rD  Ú
startswith)r¢   r@  Ú	dec_tokens     €r   rA  z/RustCodePrinter.indent_code.<locals>.<listcomp>ê  sE   ø€ ð (ð (ð (Øõ ��S ¤°)Ñ<Ô<Ñ=Ô=Ñ>Ô>ð (ð (ð (r   r   )rÅ   r  )rÍ   rÎ   rœ   Ú
splitlinesr   r  r°   )rg   ÚcodeÚ
code_linesÚtabÚincreaseÚdecreaseÚprettyÚlevelÚnr@  rI  rF  s             @@r   rœ   zRustCodePrinter.indent_codeÜ  s3  øø€ õ �d�CÑ Ô ð 	'Ø×)Ò)¨$¯/ª/¸$Ñ*?Ô*?Ñ@Ô@ˆJØ—7’7˜:Ñ&Ô&Ð&àˆØ,ˆ	Øˆ	à6Ð6°Ð6Ñ6Ô6ˆàOÐOÐOÐOÈÐOÑOÔOˆð(ð (ð (ð (Ø!%ð(ñ (ô (ˆð ˆØˆÝ  ‘”ð 	!ð 	!‰GˆAˆtØ�zÐ!Ð!Ø—’˜dÑ#Ô#Ð#ØØ�X˜a”[Ñ ˆEØ�MŠM C¨¡I I¨t¨tÐ4Ñ5Ô5Ð5Ø�X˜a”[Ñ ˆEˆEØˆr   )F).rÌ   Ú
__module__Ú__qualname__Ú__doc__ÚprintmethodÚlanguagerƒ   r   r€   r‡   Ú__annotations__r‚   r�   r’   r•   rš   rž   rª   r¸   rÂ   rÛ   rÝ   rà   rå   ré   rò   rþ   r   r  r  r	  r  r  r  r  r  r  r$  r)  r.  r0  r3  r5  r;  rœ   Ú__classcell__)râ   s   @r   rx   rx   Û   sï  ø€ € € € € € ØHÐHØ€KØ€Hà(,¨¨[Ô-Jð )ð )ØØØØ�s‘u”uð	Oð Oð )ð )Ðð ð ð ñ ð !#ð 2ð 2ð 2ð 2ðð ð ð"ð "ð "ðð ð ð5ð 5ð 5ð'ð 'ð 'ðBð Bð Bð'ð 'ð 'ð	%ð 	%ð 	%ð63ð 63ð 63ðp*ð *ð *ðð ð ð ð ð ðð ð ð ð ð ð&ð &ð &ð9ð 9ð 9ðLð Lð Lðð ð ðð ð ðð ð ð ðð ð ð ðð ð ð ðð ð ð ðð ð ð ðð ð ð ð!ð !ð !ð !ðð ð ð ð$ð $ð $ð6@ð @ð @ðmð mð mð.ð .ð .ðAð Að Aðð ð ð ð ðIð Ið Iðð ð ð ð ð ð r   rx   Nc                óH   — t          |¦  «                             | |¦  «        S )a‚  Converts an expr to a string of Rust 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 is helpful in case of
        line-wrapping, or for expressions that generate multi-line statements.
    precision : integer, optional
        The precision for numbers such as pi [default=15].
    user_functions : dict, optional
        A dictionary where the keys are string representations of either
        ``FunctionClass`` or ``UndefinedFunction`` instances and the values
        are their desired C string representations. Alternatively, the
        dictionary value can be a list of tuples i.e. [(argument_test,
        cfunction_string)].  See below for examples.
    dereference : iterable, optional
        An iterable of symbols that should be dereferenced in the printed code
        expression. These would be values passed by address to the function.
        For example, if ``dereference=[a]``, the resulting code would print
        ``(*a)`` instead of ``a``.
    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].

    Examples
    ========

    >>> from sympy import rust_code, symbols, Rational, sin, ceiling, Abs, Function
    >>> x, tau = symbols("x, tau")
    >>> rust_code((2*tau)**Rational(7, 2))
    '8*1.4142135623731*tau.powf(7_f64/2.0)'
    >>> rust_code(sin(x), assign_to="s")
    's = x.sin();'

    Simple 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)].

    >>> custom_functions = {
    ...   "ceiling": "CEIL",
    ...   "Abs": [(lambda x: not x.is_integer, "fabs", 4),
    ...           (lambda x: x.is_integer, "ABS", 4)],
    ...   "func": "f"
    ... }
    >>> func = Function('func')
    >>> rust_code(func(Abs(x) + ceiling(x)), user_functions=custom_functions)
    '(fabs(x) + x.CEIL()).f()'

    ``Piecewise`` expressions are converted into conditionals. If an
    ``assign_to`` variable is provided an if statement is created, otherwise
    the ternary operator is used. 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
    >>> expr = Piecewise((x + 1, x > 0), (x, True))
    >>> print(rust_code(expr, tau))
    tau = if (x > 0) {
        x + 1
    } else {
        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]))
    >>> rust_code(e.rhs, assign_to=e.lhs, contract=False)
    'Dy[i] = (y[i + 1] - y[i])/(t[i + 1] - t[i]);'

    Matrices are also supported, but a ``MatrixSymbol`` of the same dimensions
    must be provided to ``assign_to``. Note that any expression that can be
    generated normally can also exist inside a Matrix:

    >>> from sympy import Matrix, MatrixSymbol
    >>> mat = Matrix([x**2, Piecewise((x + 1, x > 0), (x, True)), sin(x)])
    >>> A = MatrixSymbol('A', 3, 1)
    >>> print(rust_code(mat, A))
    A = [x.powi(2), if (x > 0) {
        x + 1
    } else {
        x
    }, x.sin()];
    )rx   Údoprint)rÁ   Ú	assign_torŠ   s      r   Ú	rust_coder]  ù  s#   € õZ ˜8Ñ$Ô$×,Ò,¨T°9Ñ=Ô=Ð=r   c                ó:   — t          t          | fi |¤Ž¦  «         dS )z3Prints Rust representation of the given expression.N)Úprintr]  )rÁ   rŠ   s     r   Úprint_rust_coder`  i  s&   € å	�)�DÐ
%Ð
%˜HÐ
%Ð
%Ñ&Ô&Ð&Ð&Ð&r   r(   )rU  Ú
__future__r   Útypingr   Ú
sympy.corer   r   r   r   Úsympy.core.numbersr
   Úsympy.printing.codeprinterr   r„   r‰   rx   r]  r`  r/   r   r   ú<module>rf     sj  ðð	ð 	ðB #Ð "Ð "Ð "Ð "Ð "Ø Ð Ð Ð Ð Ð à 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø +Ð +Ð +Ð +Ð +Ð +Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2ð$2ð ˆWð2ð ˆvð2ð 
ˆ5ð2ð ˆHð2ð  
Ð4Ð4°g¸qÐAØ5Ð5°v¸qÐAØ6Ð6¸ÈÐJØ4Ð4°f¸aÐ@Ø4Ð4°f¸aÐ@Ø-Ð-¨v°qÐ9Ø1Ð1°6¸1Ð=ð?ð!2ð. 
ÐÐ˜u aÐ(Ð)ð/2ð0 
ˆ4ð12ð< 
ˆ5ð=2ð> 
ˆ5ð?2ðB 
ˆ5ðC2ðD 
ˆ5ðE2ðF 
ˆ5ðG2ðH ˆFðI2ðJ ˆFðK2ðL ˆFðM2ðN ˆWðO2ðV ˆFðW2ðX ØØØØØðc2ð 2ð 2€ðX3ð 3ð 3€ðl[ð [ð [ð [ð [�kñ [ô [ð [ð|m>ð m>ð m>ð m>ð`'ð 'ð 'ð 'ð 'r   