+
    i_Q                       R t ^ RIHt ^ RIHt ^ RIt^ RIHt ^ RIH	t	H
t
HtHtHtHt ^ RIHtHtHtHt ^ RIHt ^ RIHt ^ R	IHtHt ^ R
IHt ^ RIHt  ! R R]4      t ! R R]4      t R]]3R]] 3/t!/ RRbRRbRRbRR R^3R R^3R R^3R R^3R R^3R  R!^3R" R#^3.bR$R% R$^3.bR&R'bR(R)bR*R+bR,R,bR-R-bR.R.bR/R/bR0R0bR1R1bR2R2bR3R3bR4R4bR5R5R6R6R7R7R8R8RR/Ct". R9NR:NR;NR<NR=NR>NR?NR@NRANRBNRCNRDNRENRFNRGNRHNRINRJNRKNRLNRMNRNNRONRPNRQNRRNRSNRTNRUNRVNRWNRXNRYNRZNR[NR\NR]NR^NR_NR`NRaNRbNRcNRdNReNRfNRgNRhNRiNRjNRkNRlNt# ! Rm Rn]4      t$ ! Ro Rp]4      t%R# )qa  
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)reduceN)Any)float32float64int32realintegerbool_)SRationalFloatLambda)Exprequal_valued)ceilingfloor)CodePrinter)
PRECEDENCEc                       ] tR t^AtRtR tRtR# )float_floorza
Same as `sympy.floor`, but mimics the Rust behavior of returning a float rather than an integer
c                	    R # F selfs   &s/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/printing/rust.py_eval_is_integerfloat_floor._eval_is_integerE           r   N__name__
__module____qualname____firstlineno____doc__r   __static_attributes__r   r!   r   r   r   A       r!   r   c                       ] tR t^HtRtR tRtR# )float_ceilingzc
Same as `sympy.ceiling`, but mimics the Rust behavior of returning a float rather than an integer
c                	    R # r   r   r   s   &r   r   float_ceiling._eval_is_integerL   r    r!   r   Nr"   r   r!   r   r+   r+   H   r)   r!   r+   r   r   ceilAbsabsPowc                    \        VR4      # )   r   baseexps   &&r   <lambda>r8   f   s    |C4r!   recipc                    \        VR 4      # )      ?r   r5   s   &&r   r8   r8   g   s    |C5r!   sqrtc                    \        VR4      # )r;   g      r   r5   s   &&r   r8   r8   h   s    |C6r!   zsqrt().recipc                     V\        ^^4      8H  # r3   )r   r5   s   &&r   r8   r8   i   s    shq!n4r!   cbrtc                    \        V ^4      # )   r   r5   s   &&r   r8   r8   j   s    |D!4r!   exp2c                    VP                   # N
is_integerr5   s   &&r   r8   r8   k   s    s~~r!   powic                $    VP                   '       * # rE   rF   r5   s   &&r   r8   r8   l   s    3>>1r!   powfr7   c                    R # )Tr   )r7   s   &r   r8   r8   m   s    r!   loglnMaxmaxMinminsincostanasinacosatanatan2sinhcoshtanhasinhacoshatanhabstractasasyncawaitbecomeboxbreakconstcontinuecratedodynelseenumexternfalsefinalfnforgenifimplinletloopmacromatchmodmovemutoverrideprivpubrefreturnSelfr   staticstructsupertraittruetrytypetypeofunsafeunsizedusevirtualwherewhileyieldc                  \   a  ] tR t^tRtR V 3R llt]R 4       t]R 4       tRR lt	Rt
V ;t# )	TypeCastz1
The type casting operator of the Rust language.
c                   V ^8  d   QhRR/# )rB   r   Noner   )formats   "r   __annotate__TypeCast.__annotate__   s     A At Ar!   c                	   < \         SV `  4        VP                  ;'       d	    V\        JV n        VP
                  V n        V P                  '       d"   \        V R \        R,          ^
,           4       R# R# )
precedenceFuncN)r   __init__rG   r	   explicit_assumptionssetattrr   )r   exprtype_	__class__s   &&&r   r   TypeCast.__init__   sX    @@E,@ --===D,
6(:R(?@ r!   c                	(    V P                   ^ ,          # )    argsr   s   &r   r   TypeCast.expr      yy|r!   c                	(    V P                   ^,          # r?   r   r   s   &r   r   TypeCast.type_  r   r!   c                	H    V P                   ^ ,          P                  VR7      # )r   )order)r   sort_key)r   r   s   &&r   r   TypeCast.sort_key  s    yy|$$5$11r!   )r   r   rE   )r#   r$   r%   r&   r'   r   propertyr   r   r   r(   __classcell__r   s   @r   r   r      sF    A A    2 2r!   r   c                    a  ] tR tRt$ RtRtRt]]]	]
/t]R]R]
R]R/t]! ]P"                  3/ R	^R
/ RRR]! 4       /B tR]R&   / 3R ltR tR tR tR tR tR tR tR tR tV 3R ltR;V 3R lltR t R t!R<V 3R llt"R<V 3R llt#R  t$R! t%R" t&R# t'R$ t(R<R% lt)R<R& lt*R<R' lt+R<R( lt,R<R) lt-R<R* lt.R<R+ lt/R<R, lt0R- t1R. t2R/ t3R0 t4R1 t5V 3R2 lt6R3 t7R4 t8R5 t9R6 t:R7 t;R8 t<R9 t=R:t>V ;t?# )=RustCodePrinteri  z>A printer to convert SymPy expressions to strings of Rust code
_rust_codeRusti32f32f64bool	precisionuser_functionscontractTdereferencezdict[str, Any]_default_settingsc                	2   \         P                  ! W4       \        \        4      V n        VP	                  R / 4      pV P                  P                  V4       \        VP	                  R. 4      4      V n        \        \        4      V n        \        V n	        R# )r   r   N)
r   r   dictknown_functionsgetupdateset_dereferencereserved_wordsfunction_overrides)r   settings	userfuncss   && r   r   RustCodePrinter.__init__(  so    T,#O4LL!126	##I.]B ?@!.1"4r!   c                	    V^,          # )   r   )r   ps   &&r   _rate_index_position$RustCodePrinter._rate_index_position1  s    s
r!   c                	    R V,          # )z%s;r   )r   
codestrings   &&r   _get_statementRustCodePrinter._get_statement4  s    z!!r!   c                	    R V,          # )z// %sr   )r   texts   &&r   _get_commentRustCodePrinter._get_comment7  s    ~r!   c                	p    V P                   V P                  \        ,          ,          pR V: RV: RV: R2# )zconst z:  = ;)type_mappingstype_aliasesr   )r   namevaluer   s   &&& r   _declare_number_const%RustCodePrinter._declare_number_const:  s*    ""4#4#4T#:;'+UE::r!   c                	$    V P                  V4      # rE   )indent_code)r   liness   &&r   _format_codeRustCodePrinter._format_code>  s    &&r!   c                	L   a VP                   w  poV3R  l\        V4       4       # )c              3  N   <"   T F  p\        S4       F  q!V3x  K
  	  K  	  R # 5irE   )range).0ijcolss   &  r   	<genexpr>;RustCodePrinter._traverse_matrix_indices.<locals>.<genexpr>C  s     A1U4[A[s   "%)shaper   )r   matrowsr   s   && @r   _traverse_matrix_indices(RustCodePrinter._traverse_matrix_indicesA  s    YY
dAdAAr!   c                	   . p. pR pV Fz  pVP                  VRV P                  V4      RV P                  VP                  4      RV P                  VP                  ^,           4      /,          4       VP                  R4       K|  	  W#3# )z#for %(var)s in %(start)s..%(end)s {varstartend})append_printlowerupper)r   indices
open_linesclose_lines	loopstartr   s   &&    r   _get_loop_opening_ending(RustCodePrinter._get_loop_opening_endingE  s    
9	Ait{{1~QWW-t{{177Q;/+1 1 2 s#  &&r!   c                	    \        VP                  4      ^8  d    RV P                  V4      ,           R,           # VP                  '       d   V P                  VRR7      # V P                  V4      # )r3   ()T)_type)lenr   r   	is_numberr   r   s   &&r   _print_caller_var!RustCodePrinter._print_caller_varR  sX    tyy>A T**S00^^^;;t4;00;;t$$r!   c           
        VP                   P                  V P                  9   Edz   V P                  VP                   P                  ,          pRp^p\        V\        4      '       d   TpM$V F  w  rSpV! VP
                  !  '       g   K   M	  VEe   V^8X  do   RRV P                  VP
                  ^ ,          4      RTR\        VP
                  4      ^8  d$   V P                  VP
                  R,          R4      MR/,          pV# V^8X  d0   R	RV P                  VP
                  ^ ,          4      RV/,          pV# V^8X  d0   R	RV P                  VP
                  ^,          4      RV/,          pV# R
RVRV P                  VP
                  R4      /,          pV# R# \        VR4      '       dJ   \        VP                  \        4      '       d*   V P                  VP                  ! VP
                  !  4      # V P                  V4      # )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
Nz%(var)s.%(method)s(%(args)s)r   methodr   :r3   NN,  z%(var)s.%(method)s()z%(func)s(%(args)s)func_imp_)r  r#   r   
isinstancestrr   r  r  	stringifyhasattrr  r   r   _print_not_supported)r   r   	cond_funcr  stylecondrets   &&     r   _print_FunctionRustCodePrinter._print_Function]  s    99!5!55,,TYY-?-?@IDE)S)) )2%DTYY'' *3 A:8t55diilC $s499~XYGYtyy}d C_a< C( 
 aZ0t55diilC $4 C 
 aZ0t55diilC $4 C 
	 /tyy$ ?2 C 
-  . T7##
4::v(F(F;;tzz499566,,T22r!   c                	   <a  \         ;QJ d&    R  VP                   4       F  '       g   K   RM	  RM! R  VP                   4       4      pV'       d/   \        \        P                  V 3R lVP                   4       4      p\
        SS `  V4      # )c              3  j   "   T F)  qP                   ;'       d    VP                  '       * x  K+  	  R # 5irE   is_realrG   r   args   & r   r   -RustCodePrinter._print_Mul.<locals>.<genexpr>  $     VISkk@@#...@@I   33TFc              3  V   <"   T F  qR8w  d   SP                  V4      MTx  K   	  R# 5i)r3   Nr4   _cast_to_floatr   r#  r   s   & r   r   r$    s)     'lbk[^2I(;(;C(@SV(Vbks   &))anyr   r   operatormulr   
_print_Mul)r   r   contains_floatsr   s   f& r   r.  RustCodePrinter._print_Mul  s[    #VDIIV###VDIIVV(,,'lbfbkbk'lmDw!$''r!   c                	   <a  \         ;QJ d&    R  VP                   4       F  '       g   K   RM	  RM! R  VP                   4       4      pV'       d/   \        \        P                  V 3R lVP                   4       4      p\
        SS `  W4      # )c              3  j   "   T F)  qP                   ;'       d    VP                  '       * x  K+  	  R # 5irE   r   r"  s   & r   r   -RustCodePrinter._print_Add.<locals>.<genexpr>  r%  r&  TFc              3  F   <"   T F  pSP                  V4      x  K  	  R # 5irE   r(  r*  s   & r   r   r3    s     (WYc)<)<S)A)AY   !)r+  r   r   r,  addr   
_print_Add)r   r   r   r/  r   s   f&& r   r7  RustCodePrinter._print_Add  sX    #VDIIV###VDIIVV(,,(WTYY(WXDw!$..r!   c                	   VP                   P                  '       d]   VP                  P                  '       gA   \        V4      ! \	        VP                   4      VP                  4      pV P                  V4      # V P                  V4      # rE   )r6   rG   r7   r   r   r   r  r
  s   &&r   
_print_PowRustCodePrinter._print_Pow  s^    99(;(;(;:eDII.9D;;t$$##D))r!   c                	   VP                   '       g   V P                  VP                  4      # V P                  VP                  4      R V P                  V P                  VP
                  ,          ,          ,          ,           # )z as %s)r   r   r   r   r   r   r
  s   &&r   _print_TypeCastRustCodePrinter._print_TypeCast  sX    }}};;tyy));;tyy)Ht7I7I$J[J[\`\f\fJg7h,hhhr!   c                	   < \         SV `  V4      pV'       d7   VR V P                  V P                  \        ,          ,          ,          ,           # V# z_%s)r   _print_Floatr   r   r   r   r   r  r  r   s   &&& r   rA  RustCodePrinter._print_Float  s@    g"4(!3!3D4E4Ed4K!LLLLJr!   c                	   < \         SV `  V4      pV'       d7   VR V P                  V P                  \        ,          ,          ,          ,           # V# r@  )r   _print_Integerr   r   r	   rB  s   &&& r   rE  RustCodePrinter._print_Integer  s@    g$T*!3!3D4E4Eg4N!OOOOJr!   c                	    \        VP                  4      \        VP                  4      r2V P                  V P                  \
        ,          ,          pR W$V3,          # )z
%d_%s/%d.0)intr   qr   r   r   )r   r   r   rI  float_suffixs   &&   r   _print_RationalRustCodePrinter._print_Rational  sD    466{CK1))$*;*;D*ABq222r!   c                	    VP                   P                  '       d   VP                  P                  '       d9   VP                  P                  '       dT   VP                   P                  '       g8   V P                  VP                   4      pV P                  VP                  4      pMVP                   pVP                  pV P	                  V4      pV P	                  V4      pVP
                  pR P                  WFV4      # )z{} {} {})lhsrG   rhsr)  r   rel_opr   )r   r   rN  rO  lhs_coderhs_codeops   &&     r   _print_Relational!RustCodePrinter._print_Relational  s    HH(;(;(;ATATAT]a]e]e]p]p]p%%dhh/C%%dhh/C((C((C;;s#;;s#[[  x88r!   c                	z   VP                   p\        P                  p\        P                  p\	        \        VP                  4      4       F2  pW1P                  V,          V,          ,          pWBV,          ,          pK4  	  V P                  VP                  P                  4      : R V P                  V4      : R2# [])r   r   ZeroOnereversedr   rankr   r   r6   label)r   r   dimselemoffsetr   s   &&    r   _print_IndexedRustCodePrinter._print_Indexed  s}    zzvv%		*+ALLOF**D1gF ,  ;;tyy7T9JKKr!   c                	.    VP                   P                  # rE   )r^  r   r
  s   &&r   
_print_IdxRustCodePrinter._print_Idx  s    zzr!   c                	    VP                   # rE   )r   r
  s   &&r   _print_DummyRustCodePrinter._print_Dummy  s    yyr!   c                	    R # )Er   r   r   r  s   &&&r   _print_Exp1RustCodePrinter._print_Exp1  s    r!   c                	    R # )PIr   rl  s   &&&r   	_print_PiRustCodePrinter._print_Pi  s    r!   c                	    R # )INFINITYr   rl  s   &&&r   _print_InfinityRustCodePrinter._print_Infinity  s    r!   c                	    R # )NEG_INFINITYr   rl  s   &&&r   _print_NegativeInfinity'RustCodePrinter._print_NegativeInfinity  s    r!   c                	    R # )r   r   rl  s   &&&r   _print_BooleanTrue"RustCodePrinter._print_BooleanTrue  s    r!   c                	    R # )rn   r   rl  s   &&&r   _print_BooleanFalse#RustCodePrinter._print_BooleanFalse  s    r!   c                	4    \        V4      P                  4       # rE   )r  r   rl  s   &&&r   _print_boolRustCodePrinter._print_bool  s    4y  r!   c                	    R # )NANr   rl  s   &&&r   
_print_NaNRustCodePrinter._print_NaN  r    r!   c                	   VP                   R
,          P                  R8w  d   \        R4      h. p\        VP                   4       F  w  pw  rEV^ 8X  d)   VP	                  RV P                  V4      ,          4       MiV\        VP                   4      ^,
          8X  d   VR8X  d   VR
;;,          R,          uu&   M+VR
;;,          RV P                  V4      ,          ,          uu&   V P                  V4      pVP	                  V4       VP	                  R4       K  	  V P                  R,          '       d   RP                  V4      # R	P                  V4      # )r3   TzAll Piecewise expressions must contain an (expr, True) statement to be used as a default condition. Without one, the generated expression may not evaluate to anything under some condition.z	if (%s) {z else {z else if (%s) {r   inline 
r4   )	r   r  
ValueError	enumerater   r   r  	_settingsjoin)r   r   r   r   eccode0s   &&     r   _print_Piecewise RustCodePrinter._print_Piecewise  s   99R=%  / 0 0
 "499-IAvAv[4;;q>9:c$))nq((Q$Yb	Y&	b	.Q??	KKNELLLL . >>(##88E?"99U##r!   c                	R    ^ RI Hp V P                  VP                  VRR7      4      # )r   )	PiecewiseF)deep)sympy.functionsr  r   rewrite)r   r   r  s   && r   
_print_ITERustCodePrinter._print_ITE  s!    -{{4<<	<>??r!   c                	   a  VP                   ^8X  d#   RRP                  V 3R lV 4       4      ,          # \        R4      h)r3   z[%s]r  c              3  F   <"   T F  pSP                  V4      x  K  	  R # 5irE   )r   )r   ar   s   & r   r   4RustCodePrinter._print_MatrixBase.<locals>.<genexpr>  s     %@adkk!nnar5  zLFull Matrix Support in Rust need Crates (https://crates.io/keywords/matrix).)r   r  r  )r   As   f&r   _print_MatrixBase!RustCodePrinter._print_MatrixBase  s4    66Q;DII%@a%@@@@kllr!   c                	$    V P                  V4      # rE   )r  )r   r   s   &&r   _print_SparseRepMatrix&RustCodePrinter._print_SparseRepMatrix  s    ((--r!   c                	    VP                   : R VP                  VP                  VP                   P                  ^,          ,          ,           : R2# rW  )parentr   r   r   r
  s   &&r   _print_MatrixElement$RustCodePrinter._print_MatrixElement  s<    ;;66DFF4;;+<+<Q+?$???A 	Ar!   c                	X   < \         SV `  V4      pWP                  9   d
   R V,          # V# )z(*%s))r   _print_Symbolr   )r   r   r   r   s   && r   r  RustCodePrinter._print_Symbol  s-    w$T*$$$T>!Kr!   c                	b   ^ RI Hp VP                  pVP                  pV P                  R,          '       d@   VP                  V4      '       g   VP                  V4      '       d   V P                  WC4      # V P                  V4      pV P                  V4      pV P                  V: RV: 24      # )r   )IndexedBaser   r   )	sympy.tensor.indexedr  rN  rO  r  has_doprint_loopsr   r   )r   r   r  rN  rO  rQ  rR  s   &&     r   _print_Assignment!RustCodePrinter._print_Assignment'  s    4hhhh>>*%%377;+?+?$$ &&s00{{3'H{{3'H&&Hh'GHHr!   c                	\    V P                  VP                  ^ ,          4      pRV: RV: R2# )r   z(if (z == 0.0) { 0.0 } else { (z).signum() }))r   r   )r   r   r#  s   && r   _print_signRustCodePrinter._print_sign5  s#    kk$))A,'DGMMr!   c                	    VP                   '       g   \        V\        4      # VP                  '       d   \	        V4      # V# rE   )r	  r   r   rG   r   r
  s   &&r   r)  RustCodePrinter._cast_to_float9  s0    ~~~D$''___;r!   c                    WP                   9   ;'       g.    V\        9   ;'       g    \        V RP                  V4      R4      # )z}Check if function ``name`` is either a known function or has its own
printing method. Used to check if rewriting is possible.z	_print_{}F)r   r   getattrr   )r   r   s   &&r   
_can_printRustCodePrinter._can_print@  sA     +++{{t7I/I{{WUY[f[m[mnr[suzM{{r!   c                	   \        4       p\        V\        4      '       da   VP                  '       d   VP	                  VP
                  4       VP                   F#  pVP                  V P                  V4      4      pK%  	  V# rE   )	r   r  r   is_Functionr6  r  r   union_collect_functions)r   r   	functionsr#  s   &&  r   r  "RustCodePrinter._collect_functionsI  s_    E	dD!!dii(yy%OOD,C,CC,HI	 !r!   c           	     	
  a  \        V\        4      '       g   V# S P                  V4      pS P                  P	                  4        UUUu/ uFg  w  pw  rES P                  V4      '       g   K!  \        ;QJ d    V 3R  lV 4       F  '       d   K   RM	  RM! V 3R  lV 4       4      '       g   Kc  W4V3bKi  	  ppppV F<  pVP                  VP                  R4      w  rHV'       g   K+  VP                  V4      pK>  	  V# u upppi )c              3  F   <"   T F  pSP                  V4      x  K  	  R # 5irE   )r  )r   fr   s   & r   r   ;RustCodePrinter._rewrite_known_functions.<locals>.<genexpr>[  s     <1DOOA&&r5  FT)NN)
r  r   r  _rewriteable_functionsitemsr  allr   r#   r  )	r   r   expression_functionsr   target_frequired_fsrewriteable_functionsr  _s	   f&       r   _rewrite_known_functions(RustCodePrinter._rewrite_known_functionsR  s    $%%K#66t< 261L1L1R1R1T!
1T--xx( * <<<<< *D[))1T 	 !
 )D/33DMM<PKHx||H- ) !
s   	C>,
C>7C>C>.C>c                   \        V\        4      '       d2   V P                  VP                  R4      4      pRP	                  V4      # RpRpRpV Uu. uF  qfP                  R4      NK  	  ppV Uu. uF+  p\        \        \        VP                  V4      4      4      NK-  	  ppV Uu. uF+  p\        \        \        VP                  V4      4      4      NK-  	  pp. p	^ p
\        V4       FZ  w  rVR9   d   V	P                  V4       K  WV,          ,          p
V	P                  W:,          : V: 24       WV,          ,          p
K\  	  V	# u upi u upi u upi )z0Accepts a string of code or a list of code linesTr  z    z 	){r  z{
z(
)r   r  )r  r  )r  r  r   
splitlinesr  lstriprH  r+  mapendswith
startswithr  r   )r   code
code_linestab	inc_token	dec_tokenlineincreasedecreaseprettylevelns   &&          r   r   RustCodePrinter.indent_codec  s3    dC  ))$//$*?@J77:&&,		046U#6IMOSS	:;<O!%(!% S)<=>!% 	 (  GAz!d#a[ EMMCIt45a[ E '  7O(s   E
11E(1E)r   r   r   r   rE   r   )@r#   r$   r%   r&   r'   printmethodlanguager	   r   r   r   r   r   r
   r   r   r   r   r   __annotations__r   r   r   r   r   r   r   r  r  r  r.  r7  r:  r=  rA  rE  rK  rT  rb  re  rh  rm  rq  ru  ry  r|  r  r  r  r  r  r  r  r  r  r  r  r)  r  r  r  r   r(   r   r   s   @r   r   r     sc   HKH 	gL 	uv	M )-[-J-J )R"Dsu	O )~  !# 5";'B'	%13f(/*i3

9L!$6@m.AIN|" r!   r   )&r'   
__future__r   	functoolsr   r,  typingr   sympy.codegen.astr   r   r   r   r	   r
   
sympy.corer   r   r   r   sympy.core.exprr   sympy.core.numbersr   #sympy.functions.elementary.integersr   r   sympy.printing.codeprinterr   sympy.printing.precedencer   r   r+   r   r   r   r   r   r   r!   r   <module>r     s  	B #     2 1   + > 2 0"% G  e[!' 2 72 V2 
52  
4gqA5vqA6J4fa@4fa@-vq9161=?!2. 
ua()/20 
412< 
5=2> 
5?2B 
5C2D 
5E2F 
5G2H FI2J FK2L FM2N WO2V FW2X FY2Z FWWW
Fc2X3* 333 3 	3
 3 3 3 3 3 3 3 3 3 3 3  !3" #3$ %3& '3( )3* +3, -3. /30 132 334 536 738 93: ;3< =3> ?3@ A3B C3D E3F G3H I3J K3L M3N O3P Q3R S3T U3V W3X Y3Z [3\ ]3^ _3` a3b c3d e3f g3l2t 20mk mr!   