+
    iE                     
   ^ RI Ht ^ RIHt ^ RIHtHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RI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IHt ^ RIH t H!t! ^ RI"H#t# R t$RR lt%R t&R t'R t(RR/R lt)R# )    )Add)factor_terms)
expand_log_mexpand)Pow)S)ordered)Dummy)LambertWexplog)root)roots)Polyfactor)separatevars)collect)powsimp)solve_invert)uniqc                8   V P                    Uu0 uF  q!VP                  9   g   K  VkK  	  pp\        V4       FX  p^V,          pW#9   g   K  WC9   g   K  VP                  4       ^,          \        P
                  Jd   TpVP                  V4       KZ  	  V# u upi )a  process the generators of ``poly``, returning the set of generators that
have ``symbol``.  If there are two generators that are inverses of each other,
prefer the one that has no denominator.

Examples
========

>>> from sympy.solvers.bivariate import _filtered_gens
>>> from sympy import Poly, exp
>>> from sympy.abc import x
>>> _filtered_gens(Poly(x + 1/x + exp(x)), x)
{x, exp(x)}

)gensfree_symbolslistas_numer_denomr   Oneremove)polysymbolgr   ags   &&   w/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/solvers/bivariate.py_filtered_gensr$      s}    $ yy=y!ann$<AAyD=$ZqS9  "1%QUU2KKN  K >s
   BBNc                  a V P                  S4       Uu. uF[  q2'       dP   VP                  '       d   W#P                  9   g.   VP                  '       d   K@  VP                  V4      '       g   KY  VNK]  	  pp\	        V4      ^8X  d
   V^ ,          # V'       d$   \        \        \        V4      4      V3R lR7      # R# u upi )a  Returns the term in lhs which contains the most of the
func-type things e.g. log(log(x)) wins over log(x) if both terms appear.

``func`` can be a function (exp, log, etc...) or any other SymPy object,
like Pow.

If ``X`` is not ``None``, then the function returns the term composed with the
most ``func`` having the specified variable.

Examples
========

>>> from sympy.solvers.bivariate import _mostfunc
>>> from sympy import exp
>>> from sympy.abc import x, y
>>> _mostfunc(exp(x) + exp(exp(x) + 2), exp)
exp(exp(x) + 2)
>>> _mostfunc(exp(x) + exp(exp(y) + 2), exp)
exp(exp(y) + 2)
>>> _mostfunc(exp(x) + exp(exp(y) + 2), exp, x)
exp(x)
>>> _mostfunc(x, exp, x) is None
True
>>> _mostfunc(exp(x) + exp(x*y), exp, x)
exp(x)
c                 &   < V P                  S4      # N)count)xfuncs   &r#   <lambda>_mostfunc.<locals>.<lambda>P   s        )keyN)atoms	is_Symbolr   haslenmaxr   r	   )lhsr*   Xtmpftermss   &f&  r#   	_mostfuncr8   /   s    6 !YYt_ )_cQ	---KK GGAJ c_F ) 6{aay	4(.EFF)s   B>B>B>0B>c                   \        V P                  4       4      p V P                  V4      w  r#V P                  '       d2   VP                  '       d    \        W14      w  rEpW$,          W%,          V3# V P                  '       g   ^ pY#rdM Tp\        V4      P                  VRR7      w  rFVP                  4       '       d   V) pV) pWEV3# )a  Return ``a, b, X`` assuming ``arg`` can be written as ``a*X + b``
where ``X`` is a symbol-dependent factor and ``a`` and ``b`` are
independent of ``symbol``.

Examples
========

>>> from sympy.solvers.bivariate import _linab
>>> from sympy.abc import x, y
>>> from sympy import exp, S
>>> _linab(S(2), x)
(2, 0, 1)
>>> _linab(2*x, x)
(2, 0, x)
>>> _linab(y + y*x + 2*x, x)
(y + 2, y, x)
>>> _linab(3 + 2*exp(x), x)
(2, 3, exp(x))
Fas_Add)r   expandas_independentis_Mulis_Add_linabr   could_extract_minus_sign)argr    inddepabr)   s   &&     r#   r@   r@   T   s    ( szz|
$C!!&)HC
zzzcjjj%auceQ:::1C //u/E!!##BB7Nr-   c                6  aa \        \        V 4      4      p \        V \        V4      pV'       g   . # V P	                  V^ 4      p\        V) \        4      '       dq   W,
          P	                  W"P                  ^ ,          4      p VP                  ^ ,          p\        V\        4      '       g   . # V) P                  ^ ,          ) pW,          p WP                  9  d   . # \        W14      w  rEp\        W,
          V4      pVP                  V4      pVe   WP                  9   d   . # VP                  ^ ,          p	\        W4      w  rpW8w  d   . # \        R4      o\        VS,
          V4      pR^ .p. pW,          W,          ,
          V,          V
,          P                  4       w  ppVP                  4       w  pp\        VV,          4      p\        R4      p\!        VV,          V,
          V4      P#                  4        Uu. uF  pWHV
,          ,          V,          NK  	  ppV Fn  pV Fe  p\%        VV4      pV'       d   VP&                  '       g   K+  V) V
,          W,          V,          ,           oVP)                  VV3R lV 4       4       Kg  	  Kp  	  V# u upi )z
Given an expression assumed to be in the form
    ``F(X, a..f) = a*log(b*X + c) + d*X + f = 0``
where X = g(x) and x = g^-1(X), return the Lambert solution,
    ``x = g^-1(-c/b + (a/d)*W(d/(a*b)*exp(c*d/a/b)*exp(-f/a)))``.
rhstc              3   F   <"   T F  qP                  SS4      x  K  	  R # 5ir'   )subs).0xurH   us   & r#   	<genexpr>_lambert.<locals>.<genexpr>   s     92wwq#s   !)r   r   r8   r   rK   
isinstanceargsr   r@   r   as_coefficientr
   r   r   as_coeff_Mulr   r   keysr   is_realextend)eqr)   mainlogotherdfX2logtermrE   logargrF   cX1xusolnslambert_real_branchessolnumdenperI   rS   rB   kwrH   rN   s   &&                       @@r#   _lambertrl   y   s%    
*R.	!BC#G	GGGQE5&#jwQ8,,q/'3''I&q!!
"""	eHA"bj'*Gw'AyA'	\\!_Ff HA"	x	 	eABFAG  G
C QS!A--/HCFAsCGAc
A$QTAXq166898!AsGAII8D9 &Aa A"Q$!#q.CJJ999 '  J :s   ?Jc                @  aaa V3R lpV P                  SRR7      w  rEV) pS Uu. uFQ  pVP                  \        \        39   g2   VP                  '       g   K2  SVP                  P
                  9   g   KO  VNKS  	  ppV'       g   \        4       hVP                  '       g   VP                  '       Ed   \        R	/ SP                  B oVP                  V3R lV3R l4      pVP                  '       d   VP                  S4      '       d   VP                  S^ 4      p	WY,
          p
Wi,
          pV
P                  '       gk   V'       dc   V
P                  \        P                  \        P                   4      '       g/   \#        \        V
4      \        V4      ,
          4      pV! VSS4      # MvVP                  '       de   V'       d]   \#        \        V4      RR7      p\        V4      pVP                  S4      '       d%   VP                  '       d   WV,
          pV! VSS4      # VP%                  SS/4      p\'        \)        VRR7      4      p\        4       p\+        W],
          S4      w  rVP%                  W/4      p. pV'       EgR   \-        V\        S4      pV'       Ed8   VP                  '       d.   V^ 8w  d'   \/        \        V4      \        V4      ,
          S4      pMVP                  '       d   VP                  V^ 4      pV'       d   VP                  '       g   VP1                  \2        4       Uu. uF  pSVP
                  9   g   K  VNK  	  up'       dk   V'       g$   \        V4      \        VV,
          4      ,
          pM)\        VV,
          4      \        VV,
          4      ,
          p\/        \#        V4      S4      pM\/        WV,
          S4      pV'       Eg   \-        V\        S4      pV'       d   \5        VV4      pVP                  '       d7   V^ 8w  d0   \/        \#        \        V4      \        V4      ,
          4      S4      pMVP                  '       d   VP                  V^ 4      pVV,
          pVV,
          pVP7                  4       '       d)   VP7                  4       '       d   VR
,          pVR
,          p\        V4      \        V4      ,
          p\/        \#        V4      S4      pV'       g   \-        V\2        S4      pV'       d   SVP                  P
                  9   d   \5        VV4      pVP                  '       d7   V^ 8w  d0   \/        \#        \        V4      \        V4      ,
          4      S4      pMfVP                  '       dU   VP                  V^ 4      pVV,
          pVV,
          p\        V4      \        V4      ,
          p\/        \#        V4      S4      pV'       g   \        RV ,          4      h\9        \;        V4      4      # u upi u upi )ap  Return solution to ``f`` if it is a Lambert-type expression
else raise NotImplementedError.

For ``f(X, a..f) = a*log(b*X + c) + d*X - f = 0`` the solution
for ``X`` is ``X = -c/b + (a/d)*W(d/(a*b)*exp(c*d/a/b)*exp(f/a))``.
There are a variety of forms for `f(X, a..f)` as enumerated below:

1a1)
  if B**B = R for R not in [0, 1] (since those cases would already
  be solved before getting here) then log of both sides gives
  log(B) + log(log(B)) = log(log(R)) and
  X = log(B), a = 1, b = 1, c = 0, d = 1, f = log(log(R))
1a2)
  if B*(b*log(B) + c)**a = R then log of both sides gives
  log(B) + a*log(b*log(B) + c) = log(R) and
  X = log(B), d=1, f=log(R)
1b)
  if a*log(b*B + c) + d*B = R and
  X = B, f = R
2a)
  if (b*B + c)*exp(d*B + g) = R then log of both sides gives
  log(b*B + c) + d*B + g = log(R) and
  X = B, a = 1, f = log(R) - g
2b)
  if g*exp(d*B + h) - b*B = c then the log form is
  log(g) + d*B + h - log(b*B + c) = 0 and
  X = B, a = -1, f = -h - log(g)
3)
  if d*p**(a*B + g) - b*B = c then the log form is
  log(d) + (a*B + g)*log(p) - log(b*B + c) = 0 and
  X = B, a = -1, d = a*log(p), f = -log(d) - g*log(p)
c                   < R Uu. uF  q0P                  WV,          /4      NK  	  upw  rE\        WBS4      pWT8w  d   VP                  \        WRS4      4       \        \	        V4      4      # u upi )a  Return the unique solutions of equations derived from
``expr`` by replacing ``t`` with ``+/- symbol``.

Parameters
==========

expr : Expr
    The expression which includes a dummy variable t to be
    replaced with +symbol and -symbol.

symbol : Symbol
    The symbol for which a solution is being sought.

Returns
=======

List of unique solution of the two equations generated by
replacing ``t`` with positive and negative ``symbol``.

Notes
=====

If ``expr = 2*log(t) + x/2` then solutions for
``2*log(x) + x/2 = 0`` and ``2*log(-x) + x/2 = 0`` are
returned by this function. Though this may seem
counter-intuitive, one must note that the ``expr`` being
solved here has been derived from a different expression. For
an expression like ``eq = x**2*g(x) = 1``, if we take the
log of both sides we obtain ``log(x**2) + log(g(x)) = 0``. If
x is positive then this simplifies to
``2*log(x) + log(g(x)) = 0``; the Lambert-solving routines will
return solutions for this, but we must also consider the
solutions for  ``2*log(-x) + log(g(x))`` since those must also
be a solution of ``eq`` which has the same value when the ``x``
in ``x**2`` is negated. If `g(x)` does not have even powers of
symbol then we do not want to replace the ``x`` there with
``-x``. So the role of the ``t`` in the expression received by
this function is to mark where ``+/-x`` should be inserted
before obtaining the Lambert solutions.

)rQ      )xreplace_solve_lambertrX   r   r   )exprrI   r    sgnnlhsplhssolsr   s   &&&    r#   _solve_even_degree_expr/_solve_lambert.<locals>._solve_even_degree_expr   sh    V 7>?6=sMM1&j/*g?
dD1<KKtT:; DJ?s   !A-Tr:   c                    < V P                   ;'       d.    V P                  S8H  ;'       d    V P                  P                  # r'   )is_Powbaser   is_even)ir    s   &r#   r+    _solve_lambert.<locals>.<lambda>(  s.    ??QVVv-??!%%--?r-   c                 *   < SV P                   ,          # r'   )r   )r}   rI   s   &r#   r+   r~   *  s    155r-   )force)deepz:%s does not appear to have a solution in terms of LambertW)rI   rQ   )r=   r*   r   r   rz   r   NotImplementedErrorr?   r>   r
   assumptions0replacer1   rK   r   ComplexInfinityNaNr   rp   r   r   r   r8   rl   r/   r   r   rA   r   r	   )r]   r    r   rw   nrhsr4   rH   r6   lamcheckt_indept_term_rhsrY   rr}   solnrZ   r[   diffmainexpmaintermmainpowrI   s   &ff                   @r#   rq   rq      s   D4 l    5ID%C# BtHHc
*  &#''*>*> > tH B !##
zzzSZZZ -,,-kk@ :::#''!**hhq!nG]F=D===TJJq00!%%88Fc$i 78.r1f==ZZZCSXT2Cc(CwwqzzcjjjY.r1f== llAv;'
&4(
)C 	ASWf%FA
**aX
C D4Cf-7zzzcQhC3s8 3V<!,',{{3'737'7!S%5%55 '737 37 "5zC,<<"3;/#cEk2BB#Jt$4f=D $CIv6D 4Cf-#w'CzzzcQh
3s8c#h+> ?H!,;Ek55770022NH2IC8}s3x/
4 0&9 Cf-v!9!99#w'CzzzcQh
3s8c#h+> ?H!,;Ek8}s3x/
4 0&9! # "##$ % 	% EB@37s   /XX7X5XXfirstTc          
       aa \        RRR7      pV'       d   \        V SS4      pVP                  4       p \        4       p\        4       p\        \        V P	                  SVSV/4      Wg4      WgRR7      pV'       d?   VSVS/p	V^ ,          P                  V	4      V^,          P                  V	4      V^,          3# R# T pVP                  4       p \        P                  ! VP                  4       4      p
. pV
 FR  p\        VP	                  SVS,          4      4      pVP                  pSV9   g   SV9   d    M(VP                  V4       KT  	  SS,          \        V!  V3# VV3R lp. pVP                  S4      pVP                  S4      V8X  d   \        VP                  SV,          4      V4      p\        VP                  SV,          4      V4      pV! V SVVS,          ,
          V,          4      pVe   VS,          VS,          ,           W3# . pVP                  S4      pVP                  S4      V8X  d   \        ^4       F  p\        VP                  SV,          SV,          ,          4      V4      p\        VP                  SV,          4      V4      pV! V SVVS,          ,
          V,          S,          4      pVe#   VS,          S,          VS,          ,           W3u # SSuooK  	  R# R# )ao  Given an expression, f, 3 tests will be done to see what type
of composite bivariate it might be, options for u(x, y) are::

    x*y
    x+y
    x*y+x
    x*y+y

If it matches one of these types, ``u(x, y)``, ``P(u)`` and dummy
variable ``u`` will be returned. Solving ``P(u)`` for ``u`` and
equating the solutions to ``u(x, y)`` and then solving for ``x`` or
``y`` is equivalent to solving the original expression for ``x`` or
``y``. If ``x`` and ``y`` represent two functions in the same
variable, e.g. ``x = g(t)`` and ``y = h(t)``, then if ``u(x, y) - p``
can be solved for ``t`` then these represent the solutions to
``P(u) = 0`` when ``p`` are the solutions of ``P(u) = 0``.

Only positive values of ``u`` are considered.

Examples
========

>>> from sympy import solve
>>> from sympy.solvers.bivariate import bivariate_type
>>> from sympy.abc import x, y
>>> eq = (x**2 - 3).subs(x, x + y)
>>> bivariate_type(eq, x, y)
(x + y, _u**2 - 3, _u)
>>> uxy, pu, u = _
>>> usol = solve(pu, u); usol
[sqrt(3)]
>>> [solve(uxy - s) for s in solve(pu, u)]
[[{x: -y + sqrt(3)}]]
>>> all(eq.subs(s).equals(0) for sol in _ for s in sol)
True

rN   T)positiveF)r   Nc                 t   < \        V P                  W4      4      pVP                  pSV9   g   SV9   d   R # T# r'   )r   rK   r   )r]   vra   newfreer)   ys   &&&  r#   okbivariate_type.<locals>.ok  s7    qvva|$T	Q$Yt8S8r-   )r
   r   as_exprbivariate_typerK   rp   r   	make_argsr   r   appenddegreer   coeff_monomialrange)r]   r)   r   r   rN   rh   _x_yrvrepsrS   r   rE   r   r   r\   rF   itrys   &ff$              r#   r   r     s{   N 	cD!AAqMIIKWWDB2!7@"PUV2q>Da5>>$'A)=r!uDD	A			A ==%D
CQVVAqs^$~~9T	

1  sCIq  9 C	Axx{a!!!Q$'+!!!Q$'+AAaC{#?Q319c$$ C	Axx{a!HDQ%%ad1a4i0!4AQ%%ad+Q/AQA!GQ;q=)Cs1uqs{C**aDAq  r-   r'   )*sympy.core.addr   sympy.core.exprtoolsr   sympy.core.functionr   r   sympy.core.powerr   sympy.core.singletonr   sympy.core.sortingr	   sympy.core.symbolr
   &sympy.functions.elementary.exponentialr   r   r   (sympy.functions.elementary.miscellaneousr   sympy.polys.polyrootsr   sympy.polys.polytoolsr   r   sympy.simplify.simplifyr   sympy.simplify.radsimpr   r   sympy.solvers.solversr   r   sympy.utilities.iterablesr   r$   r8   r@   rl   rq   r    r-   r#   <module>r      se     - 4   " & # G G 9 ' . 0 * + 0 *8"J"JEP]@\T \r-   