+
    ‹°³j7  ã                  ó  € R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
Ht ^ RIHt / RRbR	R	bR
R
bRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRRRRRRRRRR R R!R!R"R"R#R#R$R$R%R%/Ct. R+Ot ! R& R']4      tR,R) ltR* tR(# )-z˜
R code printer

The RCodePrinter converts single SymPy expressions into single R expressions,
using the functions defined in math.h where possible.



)Úannotations)ÚAny)Úequal_valued)ÚCodePrinter)Ú
precedenceÚ
PRECEDENCE)ÚRangeÚAbsÚabsÚsinÚcosÚtanÚasinÚacosÚatanÚatan2ÚexpÚlogÚerfÚsinhÚcoshÚtanhÚasinhÚacoshÚatanhÚfloorÚceilingÚsignÚMaxÚmaxÚMinÚminÚ	factorialÚgammaÚdigammaÚtrigammaÚbetaÚsqrtc                  ó.  a € ] tR t^Nt$ RtRtRt]! ]P                  3/ R^R/ RRR]
! 4       /B t	R	]R
&   RRRRRR/t/ 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R tR tR tR  tR! tR" tR# tR$ tR% t V 3R& lt!R' t"R( t#R) t$R* t%R+t&V ;t'# ),ÚRCodePrinterz;A printer to convert SymPy expressions to strings of R codeÚ_rcodeÚRÚ	precisionÚuser_functionsÚcontractTÚdereferencezdict[str, Any]Ú_default_settingsÚandÚ&ÚorÚ|ÚnotÚ!zdict[str, str]Ú_relationalsc                	ó  € \         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        R# )r-   r/   N)	r   Ú__init__ÚdictÚknown_functionsÚgetÚupdateÚsetÚ_dereferenceÚreserved_words)ÚselfÚsettingsÚ	userfuncss   && ÚU/home/luca/screen-checking/.venv/lib/python3.14/site-packages/sympy/printing/rcode.pyr9   ÚRCodePrinter.__init__a   sg   € Ü×Ò˜TÔ,Ü#¤OÓ4ˆÔØ—L‘LÐ!1°2Ó6ˆ	Ø×Ñ×#Ñ# IÔ.Ü §¡¨]¸BÓ ?Ó@ˆÔÜ!¤.Ó1ˆÖó    c                	ó   € V^,          # )é   © )rA   Úps   &&rD   Ú_rate_index_positionÚ!RCodePrinter._rate_index_positioni   s   € Ø��sˆ
rF   c                	ó   € R V,          # )z%s;rI   )rA   Ú
codestrings   &&rD   Ú_get_statementÚRCodePrinter._get_statementl   s   € Ø�zÕ!Ð!rF   c                	ó$   € R P                  V4      # )z// {}©Úformat)rA   Útexts   &&rD   Ú_get_commentÚRCodePrinter._get_commento   s   € Ø�~‰~˜dÓ#Ð#rF   c                	ó$   € R P                  W4      # )z{} = {};rR   )rA   ÚnameÚvalues   &&&rD   Ú_declare_number_constÚ"RCodePrinter._declare_number_constr   s   € Ø× Ñ  Ó-Ð-rF   c                	ó$   € V P                  V4      # ©N)Úindent_code)rA   Úliness   &&rD   Ú_format_codeÚRCodePrinter._format_codeu   s   € Ø×Ñ Ó&Ð&rF   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r]   )Úrange)Ú.0ÚiÚjÚcolss   &  €rD   Ú	<genexpr>Ú8RCodePrinter._traverse_matrix_indices.<locals>.<genexpr>z   s   øé € ÐA¡˜1´U¸4¶[°�A•±[‘£ùs   ƒ"%)Úshaperd   )rA   ÚmatÚrowsrh   s   && @rD   Ú_traverse_matrix_indicesÚ%RCodePrinter._traverse_matrix_indicesx   s   ø€ Ø—Y‘Y‰
ˆˆdÜA¤ d¤ÓAÐArF   c                ó6  € . p. pRpV F‹  pVP                  VRV P                  VP                  4      RV P                  VP                  ^,           4      RV P                  VP                  ^,           4      /,          4       VP                  R4       K�  	  W#3# )zPReturns a tuple (open_lines, close_lines) containing lists of codelines
        z#for (%(var)s in %(start)s:%(end)s){ÚvarÚstartÚendÚ})ÚappendÚ_printÚlabelÚlowerÚupper)rA   ÚindicesÚ
open_linesÚclose_linesÚ	loopstartrf   s   &&    rD   Ú_get_loop_opening_endingÚ%RCodePrinter._get_loop_opening_ending|   s�   € ð ˆ
ØˆØ9ˆ	ÛˆAà×Ñ˜iØ�t—{‘{ 1§7¡7Ó+Ø˜Ÿ™ Q§W¡W¨Q¥YÓ/Ø�t—{‘{ 1§7¡7¨Q¥;Ó/ð+1õ 1ô 2ð ×Ñ˜sÖ#ñ ð Ð&Ð&rF   c                	óÐ  € R V P                   9   d   V P                  V4      # \        V4      p\        VP                  R4      '       d$   RV P                  VP                  V4      ,          # \        VP                  R4      '       d#   RV P                  VP                  4      ,          # V P                  VP                  V4      : RV P                  VP                  V4      : 2# )ÚPowz1.0/%sg      à?zsqrt(%s)Ú^éÿÿÿÿ)r;   Ú_print_Functionr   r   r   ÚparenthesizeÚbaserv   )rA   ÚexprÚPRECs   && rD   Ú
_print_PowÚRCodePrinter._print_Pow‹   sµ   € Ø�D×(Ñ(Ô(Ø×'Ñ'¨Ó-Ð-Ü˜$ÓˆÜ˜Ÿ™ "×%Ò%Ø˜t×0Ñ0°·±¸DÓAÕBÐBÜ˜$Ÿ(™( C×(Ò(Ø §¡¨D¯I©IÓ 6Õ6Ð6à"×/Ñ/°·	±	¸4Ö@Ø!%×!2Ñ!2°4·8±8¸TÕ!BðDð DrF   c                	óh   € \        VP                  4      \        VP                  4      r2R W#3,          # )z	%d.0/%d.0)ÚintrJ   Úq)rA   r‡   rJ   r�   s   &&  rD   Ú_print_RationalÚRCodePrinter._print_Rational˜   s&   € Ü�4—6‘6‹{œC §¡›Kˆ1Ø˜a˜VÕ#Ð#rF   c                	óÖ   € VP                    Uu. uF  q P                  V4      NK  	  ppV P                  VP                  P                  4      : R RP	                  V4      : R2# u upi )Ú[z, Ú])rz   rv   r†   rw   Újoin)rA   r‡   rf   Úindss   &&  rD   Ú_print_IndexedÚRCodePrinter._print_Indexedœ   sI   € Ø)-¯ªÓ7© A—‘˜Q–©ˆÐ7ØŸ;™; t§y¡y§¡Ö7¸¿¹À4¾ÐIÐIùò 8s   �A&c                	ó   € R # )zexp(1)rI   ©rA   r‡   s   &&rD   Ú_print_Exp1ÚRCodePrinter._print_Exp1    s   € ÙrF   c                	ó   € R # )ÚpirI   r˜   s   &&rD   Ú	_print_PiÚRCodePrinter._print_Pi£   s   € ÙrF   c                	ó   € R # )ÚInfrI   r˜   s   &&rD   Ú_print_InfinityÚRCodePrinter._print_Infinity¦   s   € ÙrF   c                	ó   € R # )z-InfrI   r˜   s   &&rD   Ú_print_NegativeInfinityÚ$RCodePrinter._print_NegativeInfinity©   s   € ÙrF   c                	ól  € ^ RI Hp ^ RIHp ^ RIHp VP                  pVP                  p\        WS4      '       di   . pV P                  V4       F@  w  r‰V! WXV	3,          WhV	3,          4      p
V P                  V
4      pVP                  V4       KB  	  RP                  V4      # V P                  R,          '       d@   VP                  V4      '       g   VP                  V4      '       d   V P                  We4      # V P                  V4      pV P                  V4      pV P!                  V: RV: 24      # )é    )Ú
Assignment)ÚMatrixSymbol)ÚIndexedBaseÚ
r.   z = )Úsympy.codegen.astr¨   Ú"sympy.matrices.expressions.matexprr©   Úsympy.tensor.indexedrª   ÚlhsÚrhsÚ
isinstancern   rv   ru   r“   Ú	_settingsÚhasÚ_doprint_loopsrO   )rA   r‡   r¨   r©   rª   r¯   r°   r_   rf   rg   ÚtempÚcode0Úlhs_codeÚrhs_codes   &&            rD   Ú_print_AssignmentÚRCodePrinter._print_Assignment¬   sü   € Ý0åCÝ4Ø�h‰hˆØ�h‰hˆô �c×(Ò(ð ˆEØ×7Ñ7¸Ö<‘�Ù! #¨ d¥)¨S°A°­YÓ7�ØŸ™ DÓ)�Ø—‘˜UÖ#ñ =ð —9‘9˜UÓ#Ð#Ø�^‰^˜J×'Ô'¨S¯W©W°[×-AÒ-AØ—‘˜×$Ò$ð ×&Ñ& sÓ0Ð0à—{‘{ 3Ó'ˆHØ—{‘{ 3Ó'ˆHØ×&Ñ&³HºhÐ'GÓHÐHrF   c                	ó$  € VP                   R,          P                  R8X  d5   RV P                  VP                   R,          P                  4      ,          pM_RV P                  VP                   R,          P                  4      : RV P                  VP                   R,          P                  4      : R2pTp\	        VP                   RR 4       F<  w  rERV P                  V4      : RV P                  V4      : R2V,           R,           pK>  	  V# )	é   Tz%szifelse(Ú,z,NA)NÚ)rƒ   )ÚargsÚcondrv   r‡   Úreversed)rA   r‡   Ú	last_lineÚcodeÚeÚcs   &&    rD   Ú_print_PiecewiseÚRCodePrinter._print_PiecewiseÓ   sÊ   € ð �9‰9�R�=×Ñ Ô%Ø˜tŸ{™{¨4¯9©9°R­=×+=Ñ+=Ó>Õ>‰Ið &ð /3¯k©k¸$¿)¹)ÀB½-×:LÑ:LÖ.MÈtÏ{É{Ð[_×[dÑ[dÐegÕ[h×[mÑ[mÖOnÐoˆIØˆÜ˜TŸY™Y s¨˜^Ö,‰DˆAˆqØ%)§[¡[°¦^°T·[±[À¶^ÐDÀTÕIÈ#ÕMŠDñ -àˆrF   c                	óN   € ^ RI Hp V P                  VP                  V4      4      # )r§   )Ú	Piecewise)Úsympy.functionsrÉ   rv   Úrewrite)rA   r‡   rÉ   s   && rD   Ú
_print_ITEÚRCodePrinter._print_ITEß   s   € Ý-Ø�{‰{˜4Ÿ<™<¨	Ó2Ó3Ð3rF   c                	óî   € R P                  V P                  VP                  \        R,          RR7      VP                  VP
                  VP                  P                  ^,          ,          ,           4      # )z{}[{}]ÚAtomT)Ústrict)rS   r…   Úparentr   rg   rf   rk   r˜   s   &&rD   Ú_print_MatrixElementÚ!RCodePrinter._print_MatrixElementã   s[   € Ø�‰˜t×0Ñ0°·±¼jÈÕ>PØð  1ó  ØŸ&™& 4§6¡6¨$¯+©+×*;Ñ*;¸AÕ*>Õ#>Õ>ó@ð 	@rF   c                	óh   <€ \         SV `  V4      pWP                  9   d   R P                  V4      # V# )z(*{}))ÚsuperÚ_print_Symbolr?   rS   )rA   r‡   rX   Ú	__class__s   && €rD   rÖ   ÚRCodePrinter._print_Symbolç   s2   ø€ Ü‰wÑ$ TÓ*ˆØ×$Ñ$Ô$Ø—>‘> $Ó'Ð'àˆKrF   c                	óª   € V P                  VP                  4      pV P                  VP                  4      pVP                  pR P	                  W$V4      # )z{} {} {})rv   r¯   r°   Úrel_oprS   )rA   r‡   r·   r¸   Úops   &&   rD   Ú_print_RelationalÚRCodePrinter._print_Relationalî   sB   € Ø—;‘;˜tŸx™xÓ(ˆØ—;‘;˜tŸx™xÓ(ˆØ�[‰[ˆØ× Ñ  ¨xÓ8Ð8rF   c                	óª   € V P                  VP                  4      pVP                  pV P                  VP                  4      pR P	                  W#V4      # )z	{} {} {};)rv   r¯   rÛ   r°   rS   )rA   r‡   r·   rÛ   r¸   s   &&   rD   Ú_print_AugmentedAssignmentÚ'RCodePrinter._print_AugmentedAssignmentô   sB   € Ø—;‘;˜tŸx™xÓ(ˆØ�W‰WˆØ—;‘;˜tŸx™xÓ(ˆØ×!Ñ! (°Ó9Ð9rF   c                	ó.  € V P                  VP                  4      p\        VP                  \        4      '       d   VP                  P
                  w  r4pM\        R 4      hV P                  VP                  4      pRP                  W#V^,
          WVR7      # )z*Only iterable currently supported is RangezCfor({target} in seq(from={start}, to={stop}, by={step}){{
{body}
}})Útargetrr   ÚstopÚstepÚbody)	rv   râ   r±   Úiterabler   r¿   ÚNotImplementedErrorrå   rS   )rA   r‡   râ   rr   rã   rä   rå   s   &&     rD   Ú
_print_ForÚRCodePrinter._print_Forú   s|   € Ø—‘˜TŸ[™[Ó)ˆÜ�d—m‘m¤U×+Ò+Ø $§¡× 2Ñ 2ÑˆE™ä%Ð&RÓSÐSØ�{‰{˜4Ÿ9™9Ó%ˆØV×]Ñ]ÐekØ˜!•V $ð ^ó 3ð 	3rF   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  r¶VR9   d   V	P                  V4       K  W¨V,          ,          p
V	P                  W:,          : V: 24       W§V,          ,          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 linesTÚ z   z 	)Ú{Ú(z{
z(
)rt   r¾   )rë   r«   )r±   Ústrr^   Ú
splitlinesr“   ÚlstriprŒ   ÚanyÚmapÚendswithÚ
startswithÚ	enumerateru   )rA   rÃ   Ú
code_linesÚtabÚ	inc_tokenÚ	dec_tokenÚlineÚincreaseÚdecreaseÚprettyÚlevelÚns   &&          rD   r^   ÚRCodePrinter.indent_code  s3  € ô �dœC× Ò Ø×)Ñ)¨$¯/©/¸$Ó*?Ó@ˆJØ—7‘7˜:Ó&Ð&àˆØ,ˆ	Øˆ	á04Ó6±¨—‘˜UÖ#±ˆÐ6áIMÓOÉÀ”SœœS §¡°	Ó:Ó;Ö<ÉˆÐOá!%ó(Ù!%˜ô œœS §¡°)Ó<Ó=Ö>Ù!%ð 	ð (ð ˆØˆÜ  –‰GˆAØ�zÔ!Ø—‘˜dÔ#ÙØ˜a•[Õ ˆEØ�M‰M C§IªtÐ4Ô5Ø˜a•[Õ ŠEñ 'ð ˆùò 7ùâOùò(s   ÁE
Á11EÂ(1E)r?   r;   r@   )(Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚprintmethodÚlanguager:   r   r0   r>   Ú__annotations__Ú
_operatorsr7   r9   rK   rO   rU   rZ   r`   rn   r~   r‰   rŽ   r•   r™   r�   r¡   r¤   r¹   rÆ   rÌ   rÒ   rÖ   rÜ   rß   rè   r^   Ú__static_attributes__Ú__classcell__)r×   s   @rD   r)   r)   N   sõ   ø‡ ÙEØ€KØ€Há(,¨[×-JÑ-Jñ )Ø�RØ˜"Ø�DØ‘s“uð	Oñ )Ð�~ó ð ˆcØˆcØˆcð€Jð $&€L�.Ó%à "ô 2òò"ò$ò.ò'òBò'ò
Dò$òJòòòòò%IòN
ò4ò@õò9ò:ò3÷ð rF   r)   Nc                ó6   € \        V4      P                  W4      # )a¸  Converts an expr to a string of r 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 R string representations. Alternatively, the
    dictionary value can be a list of tuples i.e. [(argument_test,
    rfunction_string)] or [(argument_test, rfunction_formater)]. 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].

Examples
========

>>> from sympy import rcode, symbols, Rational, sin, ceiling, Abs, Function
>>> x, tau = symbols("x, tau")
>>> rcode((2*tau)**Rational(7, 2))
'8*sqrt(2)*tau^(7.0/2.0)'
>>> rcode(sin(x), assign_to="s")
's = sin(x);'

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"),
...           (lambda x: x.is_integer, "ABS")],
...   "func": "f"
... }
>>> func = Function('func')
>>> rcode(func(Abs(x) + ceiling(x)), user_functions=custom_functions)
'f(fabs(x) + CEIL(x))'

or if the R-function takes a subset of the original arguments:

>>> rcode(2**x + 3**x, user_functions={'Pow': [
...   (lambda b, e: b == 2, lambda b, e: 'exp2(%s)' % e),
...   (lambda b, e: b != 2, 'pow')]})
'exp2(x) + pow(3, x)'

``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(rcode(expr, assign_to=tau))
tau = ifelse(x > 0,x + 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]))
>>> rcode(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(rcode(mat, A))
A[0] = x^2;
A[1] = ifelse(x > 0,x + 1,x);
A[2] = sin(x);

)r)   Údoprint)r‡   Ú	assign_torB   s   &&,rD   Úrcoder  "  s   € ôV ˜Ó!×)Ñ)¨$Ó:Ð:rF   c                ó0   € \        \        V 3/ VB 4       R# )z0Prints R representation of the given expression.N)Úprintr  )r‡   rB   s   &,rD   Úprint_rcoder  �  s   € ä	Œ%�Ñ
!˜Ñ
!Ö"rF   )ÚifÚelseÚrepeatÚwhileÚfunctionÚforÚinÚnextÚbreakÚTRUEÚFALSEÚNULLr    ÚNaNÚNAÚNA_integer_ÚNA_real_ÚNA_complex_ÚNA_character_Úvolatiler]   )r  Ú
__future__r   Útypingr   Úsympy.core.numbersr   Úsympy.printing.codeprinterr   Úsympy.printing.precedencer   r   Úsympy.sets.fancysetsr   r;   r@   r)   r  r  rI   rF   rD   Ú<module>r,     sP  ðñõ #Ý å +Ý 2ß <Ý &ðà	ˆ5ðð 
ˆ5ðð 
ˆ5ð	ð
 
ˆ5ðð ˆFðð ˆFðð ˆFðð ˆWðð 
ˆ5ðð 
ˆ5ðð 
ˆ5ðð ˆFðð ˆFðð ˆFðð  ˆWð!ð" ˆWð#ð$ ˆWð%ð& ˆWØˆyØ
ˆFØ	ˆ5Ø	ˆ5Ø�ØˆWØˆyØ�
Ø
ˆFØ
ˆFñ;€òF€ô,Q�;ô Qôhk;ô\#rF   