+
    i.              	          R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt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/R0/Ct ! R1 R2]
4      tR6R4 ltR5 tR3# )7z
Javascript code printer

The JavascriptCodePrinter converts single SymPy expressions into single
Javascript expressions, using the functions defined in the Javascript
Math object where possible.

)annotations)Any)S)equal_valued)CodePrinter)
precedence
PRECEDENCEAbszMath.absacosz	Math.acosacoshz
Math.acoshasinz	Math.asinasinhz
Math.asinhatanz	Math.atanatan2z
Math.atan2atanhz
Math.atanhceilingz	Math.ceilcoszMath.coscoshz	Math.coshexpzMath.expfloorz
Math.floorlogzMath.logMaxzMath.maxMinzMath.minsignz	Math.signsinzMath.sinsinhz	Math.sinhtanzMath.tantanhz	Math.tanhc            
          ] tR t^.t$ RtRtRt]! ]P                  3/ R^R/ RR/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R tR tR tR tR tR tR tR tR tR tRtR# ) JavascriptCodePrinterzK"A Printer to convert Python expressions to strings of JavaScript code
    _javascript
JavaScript	precisionuser_functionscontractTzdict[str, Any]_default_settingsc                	    \         P                  ! W4       \        \        4      V n        VP	                  R / 4      pV P                  P                  V4       R# )r#   N)r   __init__dictknown_functionsgetupdate)selfsettings	userfuncss   && u/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/printing/jscode.pyr'   JavascriptCodePrinter.__init__:   sB    T,#O4LL!126	##I.    c                	    V^,          # )    )r,   ps   &&r/   _rate_index_position*JavascriptCodePrinter._rate_index_position@   s    s
r1   c                	    R V,          # )z%s;r4   )r,   
codestrings   &&r/   _get_statement$JavascriptCodePrinter._get_statementC   s    z!!r1   c                	$    R P                  V4      # )z// {})format)r,   texts   &&r/   _get_comment"JavascriptCodePrinter._get_commentF   s    ~~d##r1   c                	d    R P                  WP                  V P                  R,          4      4      # )zvar {} = {};r"   )r=   evalf	_settings)r,   namevalues   &&&r/   _declare_number_const+JavascriptCodePrinter._declare_number_constI   s%    $$T;;t~~k7R+STTr1   c                	$    V P                  V4      # N)indent_code)r,   liness   &&r/   _format_code"JavascriptCodePrinter._format_codeL   s    &&r1   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rI   )range).0ijcolss   &  r/   	<genexpr>AJavascriptCodePrinter._traverse_matrix_indices.<locals>.<genexpr>Q   s     A1U4[A[s   "%)shaperP   )r,   matrowsrT   s   && @r/   _traverse_matrix_indices.JavascriptCodePrinter._traverse_matrix_indicesO   s    YY
dAdAAr1   c                	(   . 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# )zAfor (var %(varble)s=%(start)s; %(varble)s<%(end)s; %(varble)s++){varblestartend})append_printlabellowerupper)r,   indices
open_linesclose_lines	loopstartrR   s   &&    r/   _get_loop_opening_ending.JavascriptCodePrinter._get_loop_opening_endingS   s    
W	Ai$++agg.QWW-t{{177Q;/+1 1 2 s#  &&r1   c                	   \        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                  \        P                  ^,          8X  d#   RV P                  VP                  4      ,          # RV P                  VP                  4      : RV P                  VP                  4      : R2# )	   z1/%sg      ?zMath.sqrt(%s)zMath.cbrt(%s)z	Math.pow(z, ))r   r   r   parenthesizebaserb   r   One)r,   exprPRECs   && r/   
_print_Pow JavascriptCodePrinter._print_Pow`   s    $"%%T..tyy$?@@$((C(("T[[%;;;XXq "T[[%;;; ! *.TYY)?!%TXX!68 8r1   c                	h    \        VP                  4      \        VP                  4      r2R W#3,          # )z%d/%d)intr5   q)r,   rs   r5   ry   s   &&  r/   _print_Rational%JavascriptCodePrinter._print_Rationall   s&    466{CK1!r1   c                	P   VP                   w  r#\        V4      pVP                    Uu. uF  qPP                  WT4      NK  	  upw  rgVP                  '       d   VP                  '       g%   VP                  '       d   VP                  '       d   V R V 2# RV R V RV RV 2# u upi )z % ((z) + z) % )argsr   rp   is_nonnegativeis_nonpositive)r,   rs   numdenrt   argsnumsdens   &&      r/   
_print_Mod JavascriptCodePrinter._print_Modp   s    99$>BiiHis''2iH
 3#5#5#53#5#5#5V3tf%%D6TF$tfD77 Is   B#c                	    V P                  VP                  4      pV P                  VP                  4      pVP                  pR P	                  W$V4      # )z{} {} {})rb   lhsrhsrel_opr=   )r,   rs   lhs_coderhs_codeops   &&   r/   _print_Relational'JavascriptCodePrinter._print_Relational|   sB    ;;txx(;;txx([[  x88r1   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# )[])rW   r   Zerorr   reversedrP   rankrf   rb   rq   rc   )r,   rs   dimselemoffsetrR   s   &&    r/   _print_Indexed$JavascriptCodePrinter._print_Indexed   s}    zzvv%		*+ALLOF**D1gF ,  ;;tyy7T9JKKr1   c                	    R # )zMath.Er4   r,   rs   s   &&r/   _print_Exp1!JavascriptCodePrinter._print_Exp1   s    r1   c                	    R # )zMath.PIr4   r   s   &&r/   	_print_PiJavascriptCodePrinter._print_Pi   s    r1   c                	    R # )zNumber.POSITIVE_INFINITYr4   r   s   &&r/   _print_Infinity%JavascriptCodePrinter._print_Infinity       )r1   c                	    R # )zNumber.NEGATIVE_INFINITYr4   r   s   &&r/   _print_NegativeInfinity-JavascriptCodePrinter._print_NegativeInfinity   r   r1   c           
     	   ^ RI Hp VP                  R,          P                  R8w  d   \	        R4      h. pVP                  V4      '       d   \        VP                  4       F  w  pw  rVV^ 8X  d)   VP                  RV P                  V4      ,          4       MaV\        VP                  4      ^,
          8X  d   VR8X  d   VP                  R4       M'VP                  RV P                  V4      ,          4       V P                  V4      pVP                  V4       VP                  R4       K  	  RP                  V4      # VP                  R	R  UUu. uF.  w  rVR
V P                  V4      : RV P                  V4      : R2NK0  	  pppRV P                  VP                  R,          P                  4      ,          p	RP                  V4      V	,           RP                  R\        V4      ,          .4      ,           # u uppi )    )
AssignmentTzAll 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`   
Nr}   z) ? (
z
)
z: (
%s
)z:  rn   ro   )sympy.codegen.astr   r~   cond
ValueErrorhas	enumeratera   rb   lenjoinrs   )
r,   rs   r   rK   rR   eccode0ecpairs	last_lines
   &&        r/   _print_Piecewise&JavascriptCodePrinter._print_Piecewise   s   099R=%  / 0 0
 88J&tyy1	6A6LLt{{1~!=>#dii.1,,dLL*LL!1DKKN!BCAU#S! 2 99U## !%		#20 .1 04{{1~t{{1~N .  0$t{{499R=3E3E'FFI99W%	1CHHc#g,>N=O4PPP0s   4G=c                	    R P                  V P                  VP                  \        R,          RR7      VP                  VP
                  VP                  P                  ^,          ,          ,           4      # )z{}[{}]AtomT)strict)r=   rp   parentr   rS   rR   rW   r   s   &&r/   _print_MatrixElement*JavascriptCodePrinter._print_MatrixElement   sY    t00vt  1  -FFTVVDKK--a0002 	2r1   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 linesT z   z 	){(z{
z(
)r`   rn   )r   r   )
isinstancestrrJ   
splitlinesr   lstriprx   anymapendswith
startswithr   ra   )r,   code
code_linestab	inc_token	dec_tokenlineincreasedecreaseprettylevelns   &&          r/   rJ   !JavascriptCodePrinter.indent_code   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)   N) __name__
__module____qualname____firstlineno____doc__printmethodlanguager(   r   r%   __annotations__r'   r6   r:   r?   rF   rL   rZ   rj   ru   rz   r   r   r   r   r   r   r   r   r   rJ   __static_attributes__r4   r1   r/   r   r   .   s    KH(,[-J-J )R"DO )~  !# /"$U'B'
8 
89L**QB2
r1   r   Nc                6    \        V4      P                  W4      # )a`  Converts an expr to a string of javascript 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 keys are ``FunctionClass`` instances and values are
    their string representations. Alternatively, the dictionary value can
    be a list of tuples i.e. [(argument_test, js_function_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].

Examples
========

>>> from sympy import jscode, symbols, Rational, sin, ceiling, Abs
>>> x, tau = symbols("x, tau")
>>> jscode((2*tau)**Rational(7, 2))
'8*Math.sqrt(2)*Math.pow(tau, 7/2)'
>>> jscode(sin(x), assign_to="s")
's = Math.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,
js_function_string)].

>>> custom_functions = {
...   "ceiling": "CEIL",
...   "Abs": [(lambda x: not x.is_integer, "fabs"),
...           (lambda x: x.is_integer, "ABS")]
... }
>>> jscode(Abs(x) + ceiling(x), user_functions=custom_functions)
'fabs(x) + CEIL(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(jscode(expr, tau))
if (x > 0) {
   tau = x + 1;
}
else {
   tau = 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]))
>>> jscode(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(jscode(mat, A))
A[0] = Math.pow(x, 2);
if (x > 0) {
   A[1] = x + 1;
}
else {
   A[1] = x;
}
A[2] = Math.sin(x);
)r   doprint)rs   	assign_tor-   s   &&,r/   jscoder      s    R !*224CCr1   c                0    \        \        V 3/ VB 4       R# )zuPrints the Javascript representation of the given expression.

See jscode for the meaning of the optional arguments.
N)printr   )rs   r-   s   &,r/   print_jscoder   G  s    
 
&
"
"#r1   rI   )r   
__future__r   typingr   
sympy.corer   sympy.core.numbersr   sympy.printing.codeprinterr   sympy.printing.precedencer   r   r)   r   r   r   r4   r1   r/   <module>r      s$   #   + 2 <
	:
K \ K	
 \ K \ \ { 
: K 
: \ 
: 
:  
:!" K#$ 
:
K	:
K+2jK jZiDX$r1   