+
    i                       ^ RI Ht ^ RIt^ RIt^ RIHt ^ RIHtHt ^ RIt^ RIH	t	H
t
HtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtH t H!t!H"t"H#t#H$t$H%t%H&t&H't'H(t(H)t)H*t*H+t+H,t,H-t-H.t.H/t/H0t0H1t1H2t2H3t3H4t4H5t5H6t6H7t7H8t8H9t9H:t:H;t;H<t<H=t=H>t>H?t?H@t@HAtAHBtBHCtCHDtDHEtEHFtFHGtGHHtHHItIHJtJHKtKHLtLHMtMHNtN ^ RIOHPtPHQtQ ^ RIRHStS ^ RITHUtU ^ R	IVHWtW RR
 ltXR tYR tZR t[][ ! R R4      4       t\R# )    )annotationsN)product)AnyCallable)FMulAddPowRationallogexpsqrtcossintanasinacosacotasecacscsinhcoshtanhasinhacoshatanhacothasechacschexpandimflattenpolylogcancelexpand_trigsignsimplifyUnevaluatedExprSatanatan2ModMaxMinrfEiSiCiairyaiairyaiprimeairybiprimepiprimeisprimecotseccsccschsechcothFunctionIpiTupleGreaterThanStrictGreaterThanStrictLessThanLessThanEqualityOrAndLambdaIntegerDummysymbols)sympify_sympify)airybiprime)li)sympy_deprecation_warningc                h    \        R RRR7       \        V4      p\        VP                  V 4      4      # )zThe ``mathematica`` function for the Mathematica parser is now
deprecated. Use ``parse_mathematica`` instead.
The parameter ``additional_translation`` can be replaced by SymPy's
.replace( ) or .subs( ) methods on the output expression instead.z1.11zmathematica-parser-new)deprecated_since_versionactive_deprecations_target)rQ   MathematicaParserrM   
_parse_old)sadditional_translationsparsers   && y/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/parsing/mathematica.pymathematicar[      s;    	E "(#; 67F6$$Q'((    c                8    \        4       pVP                  V 4      # )a  
Translate a string containing a Wolfram Mathematica expression to a SymPy
expression.

If the translator is unable to find a suitable SymPy expression, the
``FullForm`` of the Mathematica expression will be output, using SymPy
``Function`` objects as nodes of the syntax tree.

Examples
========

>>> from sympy.parsing.mathematica import parse_mathematica
>>> parse_mathematica("Sin[x]^2 Tan[y]")
sin(x)**2*tan(y)
>>> e = parse_mathematica("F[7,5,3]")
>>> e
F(7, 5, 3)
>>> from sympy import Function, Max, Min
>>> e.replace(Function("F"), lambda *x: Max(*x)*Min(*x))
21

Both standard input form and Mathematica full form are supported:

>>> parse_mathematica("x*(a + b)")
x*(a + b)
>>> parse_mathematica("Times[x, Plus[a, b]]")
x*(a + b)

To get a matrix from Wolfram's code:

>>> m = parse_mathematica("{{a, b}, {c, d}}")
>>> m
((a, b), (c, d))
>>> from sympy import Matrix
>>> Matrix(m)
Matrix([
[a, b],
[c, d]])

If the translation into equivalent SymPy expressions fails, an SymPy
expression equivalent to Wolfram Mathematica's "FullForm" will be created:

>>> parse_mathematica("x_.")
Optional(Pattern(x, Blank()))
>>> parse_mathematica("Plus @@ {x, y, z}")
Apply(Plus, (x, y, z))
>>> parse_mathematica("f[x_, 3] := x^3 /; x > 0")
SetDelayed(f(Pattern(x, Blank()), 3), Condition(x**3, x > 0))
)rU   parse)rW   rY   s   & rZ   parse_mathematicar_       s    d  F<<?r\   c                 @   \        V 4      ^8X  d   V ^ ,          p\        R4      pVP                  V4      pV Uu. uF  qDP                  ^ ,          NK  	  pp\	        V4      p\        V\        4      '       dZ   \        RV 2\        R7      p\        YqP                  \        V4       UU	u/ uF  w  rV! V^,           4      V	bK  	  up	p4      4      # \        RV4      # \        V 4      ^8X  d   V ^ ,          pV ^,          p
\        Wz4      # \        R4      hu upi u up	pi )   Slotzdummy0:clsz&Function node expects 1 or 2 arguments )lenr>   atomsargsmax
isinstancerJ   rL   rK   rI   xreplace	enumerateSyntaxError)rh   argrb   slotsanumbersnumber_of_arguments	variablesivbodys   *          rZ   _parse_Functionrw   V   s    
4yA~1g		$&+,e66!99e,!'l)733'*=)> ?UKI)\\IV_L`2aL`DA4!9a<L`2a%bccb#	TaG	Awi&&BCC - 3bs   D*Dc                &    V P                  4        V # N)_initialize_classrc   s   &rZ   _decor{   i   s    Jr\   c            $      	   ] tR t^nt$ R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//Ct]! ER(ER)ER*4       F}  w  ttt	]],           ]	,           R7,           t
]'       d'   R8]P                  4       ,           ]	,           R9,           tM]P                  4       ]	,           R9,           t]P                  ]
]/4       K  	  R:R0R;R<R=R>R?R@/tRA]P                   ! RB]P"                  4      RC3RD]P                   ! RE]P"                  4      RC3RF]P                   ! RG]P"                  4      RH3RI]P                   ! RJ]P"                  4      RK3/t]P                   ! RL]P"                  4      t]P                   ! RM]P"                  4      tRNt/ tRO]RP&   / tRO]RQ&   / tRO]RR&   ]RS 4       tER+RU lt]RV 4       tRW tRX t]RY 4       t ]RZ 4       t!]R[ 4       t"]R\ 4       t#R] t$R^ t%R_t&R`t'Rat(Rbt)Rct*Rdt+](RTReRf /3]&])ReRg/3]&]*RhRiRjRkRlRmRnRoRpRqRrRs/3]&]+RtRu /3](RTRvRw/3]&]+RxRy/3]&]*RzR{R|R}/3]&]+R~R/3]&])RR/3](RTRRRR/3]&])RR/3]&])RR/3]'RTRR/3]&])RRRR/3]&])RRRRRRRRRRRR/3]&RTRR/3]&])RRRR/3]&])RCRRR/3]&])RR/3]'RTRR RR /3]&]*R;R/3]&]*RRRRRRRR /3](RTRRRRRRRR/3]&RTR>R RR /3]'RTR=R RR /3]&RTRR/3](RTRR RR RR RR /3]&RTRR /3]'RTRRRR/3.t,R]R&   RR RR /t-Rt.Rt/. ER,Ot0. ER-Ot1]R 4       t2]R 4       t3RTt4R t5R R lt6R R lt7R R lt8R R lt9R R lt:R R lt;R R lt<ER.R R llt=R R lt>R R lt?R R lt@/ R]AbR]BbR]CbR]DbRR bRR bRR bR]EbR]FbR1]GbR2]HbR3]IbR4]JbR5]KbR6]LbR]MbR]Nb/ RR bR]ObR]PbR]QbR]RbR]SbR]TbR]UbR]VbER ]WbER]XbER]YbER]ZbER][bER]\bER]]bER]^bC/ ER]_bER	]`P                  bER
]abER]bbER]cbER]dbER]ebER]fbER]gbER]hbERER bER]ibER]jbER]kbER]lbER]mbER]nbC/ ER]obER]pbER]qbER]rbER]sbER]tbER ]ubER!]vbER"]wbER#]xbR]ybR]zbR]{bR]|bR]}bR]~bR]bCRw]/CtER$]RI]/tER% tER& tER'tRT# (/  rU   a8  
An instance of this class converts a string of a Wolfram Mathematica
expression to a SymPy expression.

The main parser acts internally in three stages:

1. tokenizer: tokenizes the Mathematica expression and adds the missing *
    operators. Handled by ``_from_mathematica_to_tokens(...)``
2. full form list: sort the list of strings output by the tokenizer into a
    syntax tree of nested lists and strings, equivalent to Mathematica's
    ``FullForm`` expression output. This is handled by the function
    ``_from_tokens_to_fullformlist(...)``.
3. SymPy expression: the syntax tree expressed as full form list is visited
    and the nodes with equivalent classes in SymPy are replaced. Unknown
    syntax tree nodes are cast to SymPy ``Function`` objects. This is
    handled by ``_from_fullformlist_to_sympy(...)``.

zSqrt[x]zsqrt(x)zRational[x,y]zRational(x,y)zExp[x]zexp(x)zLog[x]zlog(x)zLog[x,y]zlog(y,x)zLog2[x]zlog(x,2)zLog10[x]z	log(x,10)zMod[x,y]zMod(x,y)zMax[*x]zMax(*x)zMin[*x]zMin(*x)zPochhammer[x,y]zrf(x,y)zArcTan[x,y]z
atan2(y,x)zExpIntegralEi[x]zEi(x)zSinIntegral[x]zSi(x)zCosIntegral[x]zCi(x)z	AiryAi[x]z	airyai(x)zAiryAiPrime[x]zairyaiprime(x)z	AiryBi[x]z	airybi(x)zAiryBiPrime[x]zairybiprime(x)zLogIntegral[x]z li(x)z
PrimePi[x]z
primepi(x)zPrime[x]zprime(x)z	PrimeQ[x]z
isprime(x) SinCosTanCotSecCscz[x]rp   z(x) ^z**{[}]
whitespacez
                (?:(?<=[a-zA-Z\d])|(?<=\d\.))     # a letter or a number
                \s+                               # any number of whitespaces
                (?:(?=[a-zA-Z\d])|(?=\.\d))       # a letter or a number
                *add*_1z
                (?:(?<=[])\d])|(?<=\d\.))       # ], ) or a number
                                                # ''
                (?=[(a-zA-Z])                   # ( or a single letter
                add*_2z
                (?<=[a-zA-Z])       # a letter
                \(                  # ( as a character
                (?=.)               # any characters
                z*(Piz
                (?:
                \A|(?<=[^a-zA-Z])
                )
                Pi                  # 'Pi' is 3.14159... in Mathematica
                (?=[^a-zA-Z])
                r@   z
                (?:
                \A|(?<=[^a-zA-Z])   # at the top or a non-letter
                )
                [A-Z][a-zA-Z\d]*    # Function
                (?=\[)              # [ as a character
                z(
                \{.*\}
                z
                (?:
                \A|(?<=[^a-zA-Z])
                )
                {arguments}         # model argument like x, y,...
                (?=[^a-zA-Z])
                z%dict[tuple[str, int], dict[str, Any]]TRANSLATIONScache_originalcache_compiledc                	r    V P                  V P                  4      pV P                  P                  V4       R # ry   )_compile_dictionaryCORRESPONDENCESr   update)rd   ds   & rZ   rz   #MathematicaParser._initialize_class   s.     ##C$7$78"r\   Nc                	   / V n         V P                   P                  V P                  4       Vf   / pV P                  P                  V8w  dS   \        V\        4      '       g   \        R4      hV P                  V4      pWP                  n        W P                  n	        V P                   P                  V P                  P                  4       R # )NzThe argument must be dict type)
translationsr   r   	__class__r   rj   dict
ValueErrorr   r   )selfrX   r   s   && rZ   __init__MathematicaParser.__init__   s     	  !2!23"*&(# >>((,CC5t<< !ABB (()@AA -DNN),-NN) 	  !>!>?r\   c                	   / pVP                  4        EF  w  r4V P                  V4       V P                  V4       V P                  VR 4      pV P                  VR 4      pV P                  VR4      pV P                  VR4      pV P                  P                  V4      pVf   RP                  VR7      p\        V4      hVP                  4       pV P                  V4      w  rVP                  4       ^ 8w  g   V	\        V4      8w  d   RP                  VR7      p\        V4      hVR,          ^ ,          R8X  d   Rp
M\        V4      p
Wz3pV Uu. uF  q^ ,          R8w  d   TMRV,           NK  	  ppRRP                  V4      ,           R,           pV P                  P                  VR	7      p\        P                  ! V\        P                   4      p/ W+&   WBV,          R
&   WV,          R&   VW+,          R&   EK  	  V# u upi )r   r   '{f}' function form is invalid.fr   \z(?:(|z)))	argumentsfsrh   pat)items_check_input_apply_rules_replace
FM_PATTERNsearchformatr   group	_get_argsstartrf   joinARGS_PATTERN_TEMPLATErecompileVERBOSE)rd   dicr   fmr   merrfm_namerh   endkey_argkeyxre_argsxyzpatStrr   s   &&               rZ   r   %MathematicaParser._compile_dictionary  s    iikFBR R  !!"l3B!!"l3B b#&Bb#&B %%b)A y7>>>D o% ggiG a(ID wwyA~B7>>>D o% Bx{c!d)$C @DDt!aDCKqTAX5tGD 388G,,t3C ..555DF**VRZZ0C AFcF4L!cF6NAF5Mo "r ! Es   !G=c                   V P                   pRp^ p VP                  V4      pVf   W1,          p V# VP                  4       pV P                  V4      w  rxVP	                  4       p	V P                  WWyV4      pT	pW1RV ,          pWR pKz  )z'Parse Mathematica function to SymPy oner}   N)r   r   r   r   r   _convert_one_function)
r   rW   r   scannedcurr   r   rh   r   bgns
   &&        rZ   _convert_function#MathematicaParser._convert_functionU  s     oo

1Ay. ) B q)ID '')C **1$SAA C #wG $Ar\   c                	R   V\        V4      3V P                  9   d=   V\        V4      3pV P                  V,          R ,          p\        \        Ws4      4      pMVR3V P                  9   de   VR3pV P                  V,          R ,          p/ p\	        V4       F4  w  rV
^ ,          R8X  d   RP                  W9R 4      W&    M,W9,          W&   K6  	  MRP                  VR7      p\        V4      hV P                  V,          R,          pV P                  V,          R,          pRp^ p VP                  V4      pVf
   W,          pMNVP                  4       p
VP                  4       pWRV W,          ,           ,          pVP                  4       pWR pKm  VRV V,           WR ,           pV# )	rh   r   ,Nz'{f}' is out of the whitelist.r   r   r   r}   )rf   r   r   ziprl   r   r   r   r   r   r   r   )r   rW   r   rh   r   r   r   x_argsr   rt   r   r   templater   r   r   r   xbgns   &&&&&&            rZ   r   'MathematicaParser._convert_one_function|  s   D	?d///s4y/C &&s+F3F S&'A #Y$+++s)C &&s+F3F A!&)Q43;88DH-ADw	 * 399B9?CS/! $$S)$/ $U+

8$Ay# 	A 779D --G %%'C  ~H dsGg$'r\   c                   VP                   pVP                  4       ^,           p. . rT. pTp\        W#R V4       F  w  rV	R8X  d-   V'       g%   V'       g   VP                  W'V 4       V^,           pV	R8X  d   VP                  V	4       MV	R8X  d   VP	                  4        V	R8X  d   VP                  V	4       K  V	R8X  g   K  V'       d   VP	                  4        K  VP                  W'V 4        M	  X^,           p
Wj3# )z'Get arguments of a Mathematica functionNr   r   r   r   r   )stringr   rl   appendpop)rd   r   rW   ancsquarecurlyrh   r   rt   cfunc_ends   &&         rZ   r   MathematicaParser._get_args  s     HHeegkB ags+DACx%A!H%!e CxQc		 Cxa cJJLKKa)) ,. q5~r\   c                	N    V P                   V,          pVP                  W#4      pV# ry   )REPLACEMENTSreplace)rd   rW   befafts   &&& rZ   r   MathematicaParser._replace  s%    s#IIcr\   c                	N    V P                   V,          w  r4VP                  WA4      # ry   )RULESsub)rd   rW   r   r   r   s   &&&  rZ   r   MathematicaParser._apply_rules  s    99S>wwsr\   c                	    R FS  pVP                  V^ ,          4      VP                  V^,          4      8w  g   K8  RP                  VR7      p\        V4      h	  RV9   d   Rp\        V4      hR# )r   r   r   r   z Currently list is not supported.N))r   r   )r   r   )())countr   r   )rd   rW   bracketr   s   &&  rZ   r   MathematicaParser._check_input  sh    ;Gwwwqz"agggaj&997>>>C o% <
 !84CS/! r\   c                	"   V P                  V4       V P                  VR 4      pV P                  VR4      pV P                  VR4      pV P                  VR4      pV P                  V4      pV P                  VR4      pV P                  VR4      pV# )r   r   r   r   r   r   )r   r   r   r   )r   rW   s   &&rZ   rV   MathematicaParser._parse_old  s    ! a. MM!S! a*a* ""1% MM!S! a& r\   c                	l    V P                  V4      pV P                  V4      pV P                  V4      pV# ry   )_from_mathematica_to_tokens_from_tokens_to_fullformlist_from_fullformlist_to_sympy)r   rW   s2s3s4s   &&   rZ   r^   MathematicaParser.parse  s7    --a0..r2--b1	r\   InfixPrefixPostfixFlatRightLeft;c                	x    \        V \        4      '       d!   V '       d   V ^ ,          R8X  d   V R.,           # RV R.# )r   CompoundExpressionNull)rj   listr   s   &rZ   <lambda>MathematicaParser.<lambda>%  sP    
1d8K8KPQVWXYVZ^rVrVH  )Z  zN  PQ  SY  yZ  )Zr\   r   =Setz:=
SetDelayedz+=AddToz-=SubtractFromz*=TimesByz/=DivideByz//c                	    W.# ry   re   r   ys   &&rZ   r  r  (  s    1&r\   &r>   z/.
ReplaceAllz->Rulez:>RuleDelayedz/;	Conditionr   Alternativesz..Repeatedz...RepeatedNullz||rG   z&&rH   !Notz===SameQz=!=UnsameQz==Equalz!=Unequalz<=	LessEqual<Lessz>=GreaterEqual>Greaterz;;Span+Plus-Times/.Dotc                	,    \         P                  V 4      # ry   )rU   _get_negr  s   &rZ   r  r  8  s    '8'A'A!'Dr\   c                	    V # ry   re   r  s   &rZ   r  r  9  s    qr\   Powerz@@Applyz/@Mapz//@MapAllz@@@c                	    R WRR..# )r0  List1re   r  s   &&rZ   r  r  ;  s    ZacdjpruivYwr\   '
Derivative	Factorialz!!
Factorial2z--	Decrementc                	    V .VO# ry   re   r  s   &&rZ   r  r  =  s
    !ar\   [[c                	    R V .VO# )Partre   r  s   &&rZ   r  r  =  s    fa_RS_r\   c                	    R .V O# )r4  re   r  s   &rZ   r  r  >  s
    ||r\   r   c                	    V ^ ,          # )r   re   r  s   &rZ   r  r  >  s    AaDr\   ?PatternTest_c                	    R V R..# PatternBlankre   r  s   &rZ   r  r  A  s    Iq7)4r\   z_.c                	    R RV R...# )OptionalrF  rG  re   r  s   &rZ   r  r  B  s    Z)Q	)BCr\   __c                	    R V R..# )rF  BlankSequencere   r  s   &rZ   r  r  C  s    YO+<=r\   ___c                	    R V R..# )rF  BlankNullSequencere   r  s   &rZ   r  r  D  s    i-@,ABr\   c                	    R V RV..# rE  re   r  s   &&rZ   r  r  F  s    )Q!)Er\   #rb   z##SlotSequencez7list[tuple[str, str | None, dict[str, str | Callable]]]_mathematica_op_precedencec                 	
    R R.# )rb   r5  re   re   r\   rZ   r  r  K  s    fc]r\   c                 	
    R R.# )rR  r5  re   re   r\   rZ   r  r  L  s	    ~s+r\   z[A-Za-z][A-Za-z0-9]*z (?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)c                	    \        V\        4      '       d1   \        P                  ! \        P
                  V4      '       d   R V 2# RRV.# )r'  r(  -1)rj   strr   matchrU   _numberrd   r   s   &&rZ   r-  MathematicaParser._get_negU  sA    $Q,,:K:S:SUV1W1W1#wo^egkmn]oor\   c                	    R VR.# )r/  rW  re   r[  s   &&rZ   _get_invMathematicaParser._get_invY  s    D!!r\   c                	b   V P                   e   V P                   # V P                  V P                  .pV P                  R,          V P                  R,          ,           pV P
                   F   w  r4pV F  pVP                  V4       K  	  K"  	  VP                  R R7       VP                  \        \        P                  V4      4       VP                  R4       VP                  R4       \        P                  ! RRP                  V4      ,           R,           4      pWpn         V P                   # )	N:NNNc                    \        V 4      ) # ry   )rf   r  s   &rZ   r  2MathematicaParser._get_tokenizer.<locals>.<lambda>h  s
    #a&r\   )r   r   
r   r   r   )_regex_tokenizer_literalrZ  _enclosure_open_enclosure_closerS  r   sortextendmapr   escaper   r   )r   tokenstokens_escapetypstratsymdictk	tokenizers   &       rZ   _get_tokenizer MathematicaParser._get_tokenizer_  s      ,(((--.,,Q/$2G2G2JJ#'#B#BC$$Q'  $C 	01c"))]34cdJJsSXXf%55;<	 )$$$r\   c                   V ^8  d   QhRR/# )   coderX  re   )r   s   "rZ   __annotate__MathematicaParser.__annotate__p  s     - - -r\   c                	   V P                  4       p. p VP                  R4      pVR8X  d#   \        V4      ^ 8  d   VP                  V4       M\        P
                  ! RW^,           R 4      pVf   \        R4      hWEP                  4       ,           ^,           pV^ 8  d   VP                  VRV 4       VP                  RW^,           V P                  RR4      .4       W^,           R pK  \        V4       F{  w  rx\        V\        4      '       d   K   VP                  R4      p	V	R8X  d   M@VP                  R4      p
V
R8X  g   W8  d   \        R	4      hVRV	 W^,           R ,           pKZ  WV&   K}  	  V Uu. uFC  p\        V\        4      '       d(   VP                  4       '       d   VP                  V4      MV.NKE  	  ppV UUu. uF  qw F  qNK  	  K  	  pppV'       d"   V^ ,          R
8X  d   VP                  ^ 4       K)  V'       d"   VR,          R
8X  d   VP                  R4       K)  V# u upi u uppi )T"z(?<!\\)"Nz"mismatch in string "  " expression_Strz\"z(*z*)zmismatch in comment (*  *) coderc  r   )rs  findrf   r   r   r   rm   r   r   rl   rj   r  rX  isasciifindallr   )r   rw  rr  code_splitsstring_start	match_end
string_endrt   
code_splitpos_comment_startpos_comment_endtoken_listsjrl  s   &&            rZ   r   -MathematicaParser._from_mathematica_to_tokensp  s   '')	 )+99T?Lr!t9q=&&t,		+tNO/DEI !"FGG%(99A=Ja""4#67!^J(G(O(OPUWZ([\]1&D '{3MA*d++$.OOD$9!$*",//$"7"b(O,O%&GHH'(:):;jYZIZI[>\\
'N 4 eppdo_`z!S/A/Aaiikky((+XYWZZdop(4[!Q!!![4 d*JJqMt+JJrN q4s   <0H5-H5H:c                    V ^8  d   QhRRRR/# rv  tokenz
str | listreturnboolre   )r   s   "rZ   rx  ry    s      J 4 r\   c                	    \        V\        4      '       d   R # \        P                  ! V P                  V4      '       d   R # \        P                  ! RV P
                  ,           V4      '       d   R # R# )Fz-?T)rj   r  r   rY  re  rZ  r   r  s   &&rZ   _is_opMathematicaParser._is_op  sJ    eT""88DMM5))88D4<<'//r\   c                    V ^8  d   QhRRRR/# r  re   )r   s   "rZ   rx  ry         & &Z &D &r\   c                	@    VR9   d   R# V P                  V4      '       * # )r   T)r   r   r  r  s   &&rZ   _is_valid_star1!MathematicaParser._is_valid_star1      J;;u%%%r\   c                    V ^8  d   QhRRRR/# r  re   )r   s   "rZ   rx  ry    r  r\   c                	@    VR9   d   R# V P                  V4      '       * # )r   T)r   r   r  r  s   &&rZ   _is_valid_star2!MathematicaParser._is_valid_star2  r  r\   c                   V ^8  d   QhRR/# rv  rl  r  re   )r   s   "rZ   rx  ry    s     52 524 52r\   c                	   . .p. p^ pV\        V4      8  Ed   W,          pWPP                  9   d=   VR,          P                  V4       VP                  V4       VP                  . 4       EMVR8X  d{   \        VR,          4      ^ 8X  d6   VR,          R,          VR,          8X  d   \        RVR,          ,          4      hV P	                  VR,          4      VR&   VP                  . 4       EMWPP
                  9   Ed   V P
                  P                  V4      pV P                  V,          VR,          8w  d   \        R4      pVR8X  d   VR,          R8X  d   VR,          R8X  d   VP                  V^,           R4       MlVR,          R8X  d\   W^,           ,          R8X  d   RW^,           &   M>W^,           ,          R8X  d&   RW^,           &   VP                  V^,           R4       MVhMVh\        VR,          4      ^ 8X  d!   VR,          R,          R8X  d   \        R	4      hV P	                  VR,          R
4      pWR&   . p	VR,          R,          VR,          8w  d"   V	P                  VP                  4       4       K=  V	P                  4        VR,          R8X  d,   \        V	4      ^8w  d   \        R\        V	4      ,          4      hVR,          P                  V	4       VP                  R4       MVR,          P                  V4       V^,          pEK  \        V4      ^8w  d   \        R4      hV P	                  V^ ,          4      # )r   r   z %s cannot be followed by comma ,zunmatched enclosure]]r   r   r<  r   z( ) not valid syntaxTz1( must be followed by one expression, %i detectedz"Stack should have only one elementr   )rf   rf  r   rm   _parse_after_bracesrg  indexinsertr   reverseRuntimeError)
r   rl  stackopen_seqpointerr  indunmatched_enclosure
last_stacknew_stack_elements
   &&        rZ   r   .MathematicaParser._from_tokens_to_fullformlist  s   DF#OE,,,b	  '&R #uRy>Q&59R=HRL+H%&H8TV<&WXX 44U2Y?b	R ///++11%8'',<*56K*L'}")<#B<3.
 #MM'!)S9%b\T1%ai0C748qy 1!'	!2d!:48qy 1 &gai =&9 9 2 21uRy>Q&59R=C+?%&<==!55eBiF
&b	$&!Bimx|3%,,UYY[9!))+B<3&3/@+AQ+F%&Y\_`q\r&rssb	  !23R b	  'qLGu:?CDD''a11r\   c               $    V ^8  d   QhRRRRRR/# )rv  linesr  rl  inside_enclosurer  re   )r   s   "rZ   rx  ry    s"     ! !4 ! !QU !r\   c                	   ^ p\        V4      pWE8  Ed   W$,          pVR8X  d   V'       d   VP                  V4       V^,          pK:  V^ 8X  d   VP                  ^ 4       V^,          pK]  V^8  d    V P                  VRV V4      pM	V^ ,          p\        V4      ^ 8  d(   V^ ,          R8X  d   VP	                  VR,          4       MVP                  V4       \        V4       F  pVP                  ^ 4       K  	  WT,          p^ pK  V^,          pEK  R#   \         d     TP                  T4       T^,          p EK2  i ; i)r   rc  Nr   ra   NN)rf   r   r  rm   ri  r   range)	r   r  rl  r  r  sizer  	prev_exprrt   s	   &&&&     rZ   _util_remove_newlines'MathematicaParser._util_remove_newlines  s    6{nOE}#JJw'AIDa<JJqMAIDQ;!$($<$<VHW=MO_$`	 !'q	Iy>A%)A,:N*NLL2/LL+wAJJqM (qLG=  ' !

7+	 !s   3D %E Ec                   V ^8  d   QhRR/# r  re   )r   s   "rZ   rx  ry    s      $ r\   c                	|   \        V4      p^ pW28  d   V^ 8  d   V P                  W^,
          ,          4      '       ds   V P                  W,          4      '       dV   W,          R8X  d%   RW&   W^,           ,          ^ ,          W^,           &   M$VP                  VR4       V^,          pV^,          pV^,          pK  R# )r   r   r   N)rf   r  r  r  )r   rl  r  r  s   &&  rZ   _util_add_missing_asterisks-MathematicaParser._util_add_missing_asterisks  s    Kn!((!)<==((99
 ?c)&)FO*01*=a*@FQ;'MM'3/qLGAIDqLG! r\   c                    V ^8  d   QhRRRR/# )rv  rl  r  r  r  re   )r   s   "rZ   rx  ry  !  s     w w$ w$ wr\   c                	P   R p. pV P                  WAV4       \        V P                  4       EF  w  rVpRV9   d   V P                  V4       \	        V4      p^ p	W8  g   K4  W,          p
\        V
\        4      '       Edr   W9   Edk   Wz,          p\        V\        4      '       d   V.p^pM. p^ pV
R	9   dG   WPP                  8X  d7   V	^ 8  d0   V P                  W^,
          ,          4      '       g   V	^,          p	K  WPP                  8X  di   V	^ 8X  gV   W^,
          8X  gI   V P                  W^,
          ,          4      '       g%   V P                  W^,           ,          4      '       d   V	^,          p	EK  RpWV	&   WPP                  8X  Ed   VP                  V	^,
          4      pVP                  V	4      pV
R8X  d   V P                  V4      pMV
R8X  d   V P                  V4      pV	^,          p	V^,          pVP                  V4       TpW`P                  8X  d   V	^,           V8  d   V P                  W^,           ,          V
4      '       d~   VP                  V4       VP                  V	^,           4      pVP                  V	^,           4      pVR8X  d   V P                  V4      pMVR8X  d   V P                  V4      pV^,          pK  VP                  V4       EMW`P                   8X  d   V	^,           V8  dk   W^,           ,          V
8X  dW   VP                  W.4       VR
,          pVP                  V	^,           4       VP                  V	^,           4      pV^,          pKx  VP                  V4       EMW`P"                  8X  d   V	^,           V8  d   W^,           ,          V
8X  du   \        V\        4      '       d   VVV,          V.VV&   MV! VV,          V4      VV&   VP                  V	^,           4       VP                  V	^,           4      pV^,          pK  VP                  V4       EMMVP                  V4       EM:WPP                  8X  d   Ve   \%        R4      hW^,
          8X  g%   V P                  W^,           ,          4      '       d   V P&                  V
,          ! 4       W&   MVP                  VP                  V	^,           4      4       V^,          pMWPP(                  8X  d   Ve   \%        R4      hV	^ 8X  g%   V P                  W^,
          ,          4      '       d   V P&                  V
,          ! 4       W&   M9VP                  VP                  V	^,
          4      4       V	^,          p	V^,          p\        V\*        4      '       d^   \,        P.                  ! \*        V4      pV! V!  pVP1                  4        \        V\2        4      '       d   VP5                  V4       MVW&   V	^,          p	EK  	  \	        V4      ^8  g!   \	        V4      ^ 8X  d5   \	        V4      ^ 8X  d%   V'       d   V P7                  W4      # \9        R4      h\	        V4      ^ 8  d>   V^ ,          '       d&   V^ ,          ^ ,          R8X  d   V^ ,          R,          pR.VOVOpV# V^ ,          # )Fr   r'  Tr)  z1'Prefix' op_type should not have a grouping stratz0unable to create a single AST for the expressionr   r  )r%  r'  r   )r  reversedrS  r  rf   rj   rX  PREFIXr  INFIXr   r^  r-  r   FLAT_check_op_compatibleRIGHTLEFT	TypeError_missing_arguments_defaultPOSTFIXr   typingcastclearr  ri  r  rm   )r   rl  r  changedr  op_typegrouping_stratop_dictr  r  r  op_namenodefirst_indexarg1arg2node_pother_opop_callnew_nodecompound_expressions   &&&                  rZ   r  %MathematicaParser._parse_after_braces!  sg   ""52BC089X9X0Y,GWg~008FDG.eS))e.>.5nG "'3// 'y&'!&'
*w++/E'TU+^b^i^ijp{|q|j}^~^~  1 **,"a<7Qh+>$++f_`U`NaBbBbfjfqfqrx  DE  zE  sF  gG  gG#qLG$"G&*7O**,%zz'!)4%zz'2 C<#'==#6D"c\#'==#6D1	D)!%)YY6")A+"49R9RSYbcZcSdfk9l9l &d 3+1::gai+@'-zz'!)'<#+s?+/==+>D%-_+/==+>D $	"MM$/+zz9")A+"4	9Je9S &wo >)/ &

719 5'-zz'!)'< $	"MM$/+yy8")A+"4	9Je9S#-gs#;#;;BF;DWY]:^F;$7:A&BUW[:\F;$7 &

719 5'-zz'!)'< $	"MM$/ KK- KK/)5"+,_"``"Qh.$++fq[>Q2R2R.2.M.Me.T.VFO KK

719(=> AID LL0)5"+,_"``"a<4;;vk7J+K+K.2.M.Me.T.VFO KK

719(=>#qLG AID!'844,2KK',J#*D>

%h55 KK1.6FO1 1Z@ v;?s5zQ3v;!3C //IIPQQu:>ayyVAYq\-AA2#7"I%"I&"I&&ayr\   c                    V ^8  d   QhRRRR/# )rv  op1rX  op2re   )r   s   "rZ   rx  ry    s     	 	 	# 	r\   c                	^    W8X  d   R # RR0pRR0pW9   d	   W#9   d   R # W9   d	   W$9   d   R # R# )Tr   r)  r%  r'  Fre   )r   r  r  muldivaddsubs   &&&  rZ   r  &MathematicaParser._check_op_compatible  s7    :ss=S]=S]r\   c                   V ^8  d   QhRR/# )rv  wmexprrX  re   )r   s   "rZ   rx  ry    s      S r\   c                   . pV.p\         P                  ! RV4      p^ pV EF;  pVf    V^ ,          # VP                  4       pWV P                  RR4      P                  RR4      P                  RR4      P	                  4       pVP                  4       R8X  d!   VR8w  d   VR,          P                  V4       MVP                  4       R8X  d1   VR8w  d   VR,          P                  V4       VP                  4        MMVP                  4       R8X  d9   VR,          P                  V.4       VP                  VR,          R,          4       VP                  4       pEK>  	  V^ ,          # )z8
Parses FullForm[Downvalues[]] generated by Mathematica
z[\[\],]r   r}   r   r   r   )	r   finditerr   r   stripr   r   r   r   )	r   r  outr  	generatorlast_posrY  position	last_exprs	   &&       rZ   _from_fullform_to_fullformlist0MathematicaParser._from_fullform_to_fullformlist  s0    KK
F3	E} 1v {{}H199#rBJJ3PRS[[\_acdjjlI{{}#?"I$$Y/#%?"I$$Y/		#%b	  )-U2Yr]+yy{H! " 1vr\   c                   V ^8  d   QhRR/# )rv  pylistr  re   )r   s   "rZ   rx  ry    s     ! !$ !r\   c                	8   aaa ^ RI HoHo VVV3R loS! V4      # )r   )r>   Symbolc                (  < \        V \        4      '       dO   \        V 4      ^ 8  d4   V ^ ,          pV R,           Uu. uF  pS! V4      NK  	  ppS! V4      ! V!  # \        R4      h\        V \        4      '       d	   S! V 4      # \        V 4      # u upi )r   r  zEmpty list of expressions)rj   r  rf   r   rX  rN   )exprheadrn   rh   r>   r  	converters   &   rZ   r  HMathematicaParser._from_fullformlist_to_fullformsympy.<locals>.converter  s    $%%t9q=7D6:2h?hsIcNhD?#D>400$%@AAD#&&d|#~% @s   B)sympyr>   r  )r   r  r>   r  r  s   &&@@@rZ   #_from_fullformlist_to_fullformsympy5MathematicaParser._from_fullformlist_to_fullformsympy  s    *	&   r\   r
   Logc                 	&    \        \        V 4      !  # ry   )r   r  rp   s   *rZ   r  r    s    #x{+r\   Log2c                	    \        V ^4      # rv  r   r  s   &rZ   r  r    s
    #a)r\   Log10c                	    \        V ^
4      # )
   r  r  s   &rZ   r  r    s
    3q":r\   ExpSqrtArcSinArcCosArcTanc                 	X    \        V 4      ^8X  d   \        \        V 4      !  # \        V !  # r   )rf   r*   r  r)   r  s   *rZ   r  r    s#    CFaKUHQK0MT1XMr\   ArcCotArcSecArcCscSinhCoshTanhCothSechCschArcSinhArcCoshArcTanhArcCothArcSechArcCschExpandImReFlattenPolylogCancel
TrigExpandSignSimplifyDeferIdentityr  c                 	"    \         P                  # ry   )r(   Zeror  s   *rZ   r  r    s    166r\   r+   r,   r-   
PochhammerExpIntegralEiSinIntegralCosIntegralAiryAiAiryAiPrimeAiryBiAiryBiPrimeLogIntegralPrimePiPrimePrimeQr4  r?   c                	$   a a VV 3R  loS! V4      # )c                  < \        V \        4      '       d   \        V ^ ,          \        4      '       d   S! V ^ ,          4      pM3SP                  P                  V ^ ,          \	        V ^ ,          4      4      pT! V R,           Uu. uF  pS! V4      NK  	  up!  # SP
                  P                  V \        V 4      4      # u upi )r   r  )rj   r  _node_conversionsgetr>   _atom_conversionsrM   )r  r  rn   recurser   s   &  rZ   r8  >MathematicaParser._from_fullformlist_to_sympy.<locals>.recurse,  s    $%%d1gt,,"47+D1155d1gxQ?PQDd2h?hsgclh?@@--11$FF @s   C re   )r   full_form_listr8  s   f&@rZ   r   -MathematicaParser._from_fullformlist_to_sympy*  s    	G ~&&r\   c                	    TpV P                   P                  4        F   w  r4VP                  \        V4      V4      pK"  	  V# ry   )r5  r   r   r>   )r   mformr  mma_form
sympy_nodes   &&   rZ   _from_fullformsympy_to_sympy.MathematicaParser._from_fullformsympy_to_sympy8  s>    $($:$:$@$@$B H<< 2J?D %Cr\   )rd  r   )r}   Arc)r~   r   r   r   r   r   )r}   hry   )r   r   r<  r   )r   r   r  r   )F)__name__
__module____qualname____firstlineno____doc__r   r   arctrirC  r   lowerr   r   r   r   r   r   r   r   ARG_MTRX_PATTERNr   r   __annotations__r   r   classmethodrz   r   r   r   r   r   r   r   r   rV   r^   r  r  r  r  r  r  rS  r  re  rZ  rf  rg  r-  r^  rd  rs  r   r  r  r  r   r  r  r  r  r  r  r   r   r	   r
   r   r   r   r   r   r8   r9   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(   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   rO   rP   r5   r6   r7   rA   rC   rB   rD   rE   rF   rG   rH   rw   r5  r?   r@   r7  r   r@  __static_attributes__re   r\   rZ   rU   rU   n   sm
   (9 	( 	(	
 	J 	: 	K 	J 	9 	9 	) 	l 	G 	' 	'  	[!" 	*#$ 	[*lJ\/O6 { -67@BS!3Y]U"syy{"Q&.Bq5(BBx(B 	RTSS	L 	JJ  ZZ	!
  	JJ  ZZ	!
  	JJ  ZZ	!
  	JJ  ZZ! ;&ER   ZZ!J zz #ZZ!
 ;=L7< =?N9> =?N9># #
@0 = =~%N@D # #J  
   " ": EFGDED 
$  Z  [  	\	s012	UD,gt^]aclnrt~  	A	t012	$j)*	t\*+	fdM:;	t[)*	sN+,	$z5.AB	tTl#	tUm$	U|$	ugui89	tWdIt[#vW[]kmpr{|}	tVn%	sFC01	sGS'23	sEl#	D[* 	+	W~&	gtUE8ULwxy	$lCdLRVXcde	s0$8TUV	3S.IJ	sM*+	$4C=B	
 	 
sEFG	VT>:;G$[ W $N 	"+"
 'H1G+O,p p " " %"-^&
&
52n!F*w wr	6!$QQQ 	Q 	H	Q
 	+Q 	#Q 	%Q 	sQ 	Q 	sQ 	sQ 	sQ 	sQ 	sQ  	s!Q$ 	$%Q& 	$'Q( 	M)Q* 	$+Q, 	$-Q. 	$/Q2 	3Q4 	5Q6 	7Q8 	9Q: 	;Q< 	=Q@ 	5AQB 	5CQD 	5EQF 	5GQH 	5IQJ 	5KQN 	&OQP 	bQQR 	ehhSQT 	7UQV 	7WQX 	&YQ\ 	k]Q^ 	_Q` 	HaQb 	cQd 	AeQl 	!mQn 	soQp 	sqQr 	ssQt 	buQv 	wQx 	ryQz 	r{Q| 	&}Q~ 	{Q@ 	&AQB 	{CQD 	rEQF 	7GQH 	IQJ 	'KQN 	OQP 	$QQR 	SQT 	UQV 	XWQX 	YQZ 	b[Q\ 	s]Q` 	OaQh 	Qb
' r\   rU   ry   )]
__future__r   r   r  	itertoolsr   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    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   sympy.core.sympifyrM   rN   sympy.functions.special.besselrO   'sympy.functions.special.error_functionsrP   sympy.utilities.exceptionsrQ   r[   r_   rw   r{   rU   re   r\   rZ   <module>rV     s    " 	     A A A A A A A A A A A A A A A A A A
 1 6 6 @
)3lD&
 N N Nr\   