
    \hi                     f   S r SSKrSSKJr  SSKJr  SSKJrJrJ	r	J
r
Jr  SSKJrJrJrJr  SSKJrJrJrJrJrJrJrJr  SSKJrJrJrJr  SS	KJ r!  SS
K"J#r#  \!RH                  r$\!RJ                  r%S r&S r'SS jr(S r)S r*S r+S r,S r-S r.S r/S r0S r1S r2S r3SS jr4S r5S r6S S jr7S!S jr8g)"a  
Algorithms for solving Parametric Risch Differential Equations.

The methods used for solving Parametric Risch Differential Equations parallel
those for solving Risch Differential Equations.  See the outline in the
docstring of rde.py for more information.

The Parametric Risch Differential Equation problem is, given f, g1, ..., gm in
K(t), to determine if there exist y in K(t) and c1, ..., cm in Const(K) such
that Dy + f*y == Sum(ci*gi, (i, 1, m)), and to find such y and ci if they exist.

For the algorithms here G is a list of tuples of factions of the terms on the
right hand side of the equation (i.e., gi in k(t)), and Q is a list of terms on
the right hand side of the equation (i.e., qi in k[t]).  See the docstring of
each function for more information.
    N)reduce)ilcm)DummyAddMulPowS)order_atorder_at_ooweak_normalizerbound_degree)gcdex_diophantinefrac_in
derivationresidue_reducesplitfactorresidue_reduce_derivationDecrementLevelrecognize_log_derivative)Polylcmcancelsqf_list)
PolyMatrix)solvec           	      N   [        X5      u  pE[        [        U6 5      u  pg[        S U[	        SUR
                  5      5      n[        X5      u  pUR                  U	5      nU	R                  U	R                  UR
                  5      5      R                  UR                  UR                  UR
                  5      5      5      nXL-  nX-  nX-  U[        X5      -  U-  -
  nUR                  USS9u  nnU VVs/ s H  u  nnUU-  R                  USS9PM     nnnXU4X,4$ s  snnf )a  
Parametric Risch Differential Equation - Normal part of the denominator.

Explanation
===========

Given a derivation D on k[t] and f, g1, ..., gm in k(t) with f weakly
normalized with respect to t, return the tuple (a, b, G, h) such that
a, h in k[t], b in k<t>, G = [g1, ..., gm] in k(t)^m, and for any solution
c1, ..., cm in Const(k) and y in k(t) of Dy + f*y == Sum(ci*gi, (i, 1, m)),
q == y*h in k<t> satisfies a*Dq + b*q == Sum(ci*Gi, (i, 1, m)).
c                 $    U R                  U5      $ Nr   ijs     L/var/www/auris/envauris/lib/python3.13/site-packages/sympy/integrals/prde.py<lambda>#prde_normal_denom.<locals>.<lambda>2   s    QUU1X       Tinclude)r   listzipr   r   tgcddiffquor   r   )fafdGDEdndsGasGdsgdenesphacbabdADs                      r#   prde_normal_denomrC   #   s     FBCG}HC	%sDBDDM	:B FB
r
A
rwwrtt}!!!%%rtt"56A
A	A	
:a$$R'	'BYYr4Y(FB345141a!A#a	&1A5Bx 	6s   8 D!c                    UR                  U5      R                  5       nU R                  U5      R                  5       n UR                  5        VVs/ s H$  u  p4US   S-  S:X  a  UOUS   S-  S:X  a  U* OSPM&     nnnUR                  5        VVs/ s H$  u  p4US   S-  S:X  a  UOUS   S-  S:X  a  U* OSPM&     nnn[        S U 5       5      n[        S U 5       5      nU R                  5        VVs/ s H$  u  p4US   S-  S:X  a  UOUS   S-  S:X  a  U* OSPM&     n	nnU R                  5        VVs/ s H$  u  p4US   S-  S:X  a  UOUS   S-  S:X  a  U* OSPM&     n
nn[        S U	 5       5      n[        S	 U
 5       5      nX-  X-  -   R                  U5      X-  X-  -
  R                  U5      4n Xw-  X-  -   R                  U5      nU S   U S   U4$ s  snnf s  snnf s  snnf s  snnf )
a  
Helper function, to get the real and imaginary part of a rational function
evaluated at sqrt(-1) without actually evaluating it at sqrt(-1).

Explanation
===========

Separates the even and odd power terms by checking the degree of terms wrt
mod 4. Returns a tuple (ba[0], ba[1], bd) where ba[0] is real part
of the numerator ba[1] is the imaginary part and bd is the denominator
of the rational function.
r         r'      c              3   $   #    U  H  ov   M     g 7fr    .0rs     r#   	<genexpr>real_imag.<locals>.<genexpr>S        (Z!Z   c              3   $   #    U  H  ov   M     g 7fr   rI   rJ   s     r#   rM   rN   T   rO   rP   c              3   $   #    U  H  ov   M     g 7fr   rI   rJ   s     r#   rM   rN   W        &X!XrP   c              3   $   #    U  H  ov   M     g 7fr   rI   rJ   s     r#   rM   rN   X   rS   rP   )as_polyas_dictitemssum)r?   r@   genkeyvalue
denom_real
denom_imagbd_realbd_imagnum_realnum_imagba_realba_imags                r#   	real_imagrd   B   s    
C	 	 	"B	C	 	 	"BceckckcmncmU_UX3q6A:?%#a&1*/qPcmJnceckckcmncmU_UX3q6A:?%#a&1*/qPcmJn(Z((G(Z((GacaiaiaklakS]SVQ!qA
aufQNakHlacaiaiaklakS]SVQ!qA
aufQNakHl&X&&G&X&&G?W_,
5
5c
:W_w=^<g<ghk<l	mB
/GO
+	4	4S	9BqE2a5" on mls   +G+G$8+G*9+G0c           	      J  ^^ US:X  a  TR                   nUS:X  a!  [        TR                  TR                  5      mOkUS:X  a'  [        TR                  S-  S-   TR                  5      mO>US;   a*  UR                  U5      nXU[        STR                  5      4$ [	        SU-  5      e[        UTTR                  5      [        UTTR                  5      -
  n[        UU4S jU 5       5      n[        S	U[        S	U5      -
  5      n	U(       Gd  US:X  a  TR                  R                  [        TR                  TR                  5      5      n
[        T5         [        UR                  S	5      * UR                  S	5      -  U R                  S	5      -  TR                  5      u  p[        U
TR                  5      u  p[        XXT5      nUb  Uu  nnnUS:X  a  [        U	U5      n	S
S
S
5        OUS:X  a  TR                  R                  [        TR                  S-  S-   TR                  5      5      n
[        T5         [        XU -  TR                  5      u  npUn[        U
TR                  5      u  p[        [        STR                  5      U-  UT5      (       a<  [        XXT5      n[        UUXT5      nUb  Ub  Uu  nnnUS:X  a  [        U	US-  5      n	S
S
S
5        [        S	U* 5      nTU-  nTU	* -  nU U-  nUUR                  U5      -  [        U	TR                  5      U -  [        TT5      R                  T5      -  U-  -   nU VVs/ s H  u  nnUU-  U-  R!                  USS9PM     nnnUnXUU4$ ! , (       d  f       N= f! , (       d  f       N= fs  snnf )a&  
Parametric Risch Differential Equation - Special part of the denominator.

Explanation
===========

Case is one of {'exp', 'tan', 'primitive'} for the hyperexponential,
hypertangent, and primitive cases, respectively.  For the hyperexponential
(resp. hypertangent) case, given a derivation D on k[t] and a in k[t],
b in k<t>, and g1, ..., gm in k(t) with Dt/t in k (resp. Dt/(t**2 + 1) in
k, sqrt(-1) not in k), a != 0, and gcd(a, t) == 1 (resp.
gcd(a, t**2 + 1) == 1), return the tuple (A, B, GG, h) such that A, B, h in
k[t], GG = [gg1, ..., ggm] in k(t)^m, and for any solution c1, ..., cm in
Const(k) and q in k<t> of a*Dq + b*q == Sum(ci*gi, (i, 1, m)), r == q*h in
k[t] satisfies A*Dr + B*r == Sum(ci*ggi, (i, 1, m)).

For case == 'primitive', k<t> == k[t], so it returns (a, b, G, 1) in this
case.
autoexptanrF   r'   )	primitivebasez@case must be one of {'exp', 'tan', 'primitive', 'base'}, not %s.c              3      >#    U  H6  u  p[        UTTR                  5      [        UTTR                  5      -
  v   M8     g 7fr   )r
   r,   )rK   GaGdr3   r;   s      r#   rM   %prde_special_denom.<locals>.<genexpr>   s2     KvrXb!RTT"Xb!RTT%::s   >Ar   NTr(   )caser   r,   r/   
ValueErrorr
   mindr   r   evalparametric_log_derivrd   r   maxr   r   )r=   r?   r@   r2   r3   ro   BnbncndcoeffalphaaalphadetaaetadrA   QmzbetaabetadsNpNpnrl   rm   r<   r;   s       `                       @r#   prde_special_denomr   ^   s4   * v~wwu}rtt	q1bdd#	&	&FF2Jaa'' !%& ' 	' 
"a	"a!6	6B	KK	KBArC2JA5=TTXXd244./F#!("''!*RWWQZ)?q	)I244!P$VRTT2
(RH=GAq!Av1I $# U]TTXXd2447Q;56F#)22!tRTT)B%v$VRTT2
+DBDDM%,?KK,VTLA,UE4rJA}"#1a6 #AqsA $ 	AsA	
AB	
QBB	"A
266":Qa
1b(9(=(=a(@@CCA;<=1R"R%(		2t		,1A=
A !Q<I $# $#( 	>s    BM==BN#N=
N
Nc                   ^^ [        U5      n[        [        U6 5      u  pV[        S U5      n[	        USS9nU VV	s/ s H'  u  pXR                  U	5      -  R                  U5      PM)     sn	nm[        S T 5       5      (       d5  [        U4S jT 5       5      n
[        U
S-   UU4S jTR                  5      nO[        SU/ TR                  5      n[        [        T6 5      u  pX4$ s  sn	nf )	ad  
Parametric Risch Differential Equation - Generate linear constraints on the constants.

Explanation
===========

Given a derivation D on k[t], a, b, in k[t] with gcd(a, b) == 1, and
G = [g1, ..., gm] in k(t)^m, return Q = [q1, ..., qm] in k[t]^m and a
matrix M with entries in k(t) such that for any solution c1, ..., cm in
Const(k) and p in k[t] of a*Dp + b*p == Sum(ci*gi, (i, 1, m)),
(c1, ..., cm) is a solution of Mx == 0, and p and the ci satisfy
a*Dp + b*p == Sum(ci*qi, (i, 1, m)).

Because M has entries in k(t), and because Matrix does not play well with
Poly, M will be a Matrix of Basic expressions.
c                 $    U R                  U5      $ r   r   r    s     r#   r$   )prde_linear_constraints.<locals>.<lambda>       AEE!Hr&   Tfieldc              3   >   #    U  H  u  pUR                   v   M     g 7fr   is_zero)rK   _ris      r#   rM   *prde_linear_constraints.<locals>.<genexpr>   s     )qearzzqs   c              3   ^   >#    U  H"  u  pUR                  TR                  5      v   M$     g 7fr   degreer,   )rK   r   r   r3   s      r#   rM   r      s!     /QEA		"$$Qs   *-r'   c                 2   > TU   S   R                  U 5      $ Nr'   nthr!   r"   r   s     r#   r$   r      s    !A$q'++a.r&   r   )lenr*   r+   r   r   r/   divallru   Matrixr,   )r=   br2   r3   r   Gnsr7   rr   gar8   r   Mqsr   r   s      `          @r#   prde_linear_constraintsr      s    " 	AACG}HC$c*AQdA/01qVR"WWR[.		a	 q1A)q)))/Q//1q5!8"$$?1aRTT"aMEB7N 	2s   .C)c                 D  ^ [        U 5      n[        U  Vs/ s H  o3R                  U5      PM     sn6 u  nm[        S T 5       5      (       d4  [	        S T 5       5      n[        US-   UU4S jUR                  5      nXF4$ [        SU/ UR                  5      nXF4$ s  snf )a*  
Given p = [p1, ..., pm] in k[t]^m and d in k[t], return
q = [q1, ..., qm] in k[t]^m and a matrix M with entries in k such
that Sum(ci*pi, (i, 1, m)), for c1, ..., cm in k, is divisible
by d if and only if (c1, ..., cm) is a solution of Mx = 0, in
which case the quotient is Sum(ci*qi, (i, 1, m)).
c              3   8   #    U  H  oR                   v   M     g 7fr   r   rK   r   s     r#   rM   *poly_linear_constraints.<locals>.<genexpr>        &AbzzA   c              3   @   #    U  H  oR                  5       v   M     g 7fr   )r   r   s     r#   rM   r      s     (a		as   r'   c                 ,   > TU   R                  U 5      $ r   r   )r!   r"   rL   s     r#   r$   )poly_linear_constraints.<locals>.<lambda>       !A$((1+r&   r   )r   r+   r   r   ru   r   gens)r;   rr   r   piqry   r   rL   s          @r#   poly_linear_constraintsr      s     	AAQ'QrQ'(DAq&A&&&(a((1q5!5qvv> 4K 1aQVV$4K (s   Bc                   ^^^ U (       d  X4$ U R                  U5      nUR                  5       u  p4USS2SS24   USS2S4   pU4S jm[        R                  " [	        U R
                  5      [	        U R                  5      5       H  u  pVXU4   R                  R                  " TR                  6 (       d  M3  XSS24   nT" XU4   5      mUR                  UU4S j5      nT" X   5      T-  n	U SS2U4   n
X
U-  -
  n XU	-  -
  nU R                  U5      n UR                  [        U	/UR                  5      5      nM     X4$ )al  
Generate a system for the constant solutions.

Explanation
===========

Given a differential field (K, D) with constant field C = Const(K), a Matrix
A, and a vector (Matrix) u with coefficients in K, returns the tuple
(B, v, s), where B is a Matrix with coefficients in C and v is a vector
(Matrix) such that either v has coefficients in C, in which case s is True
and the solutions in C of Ax == u are exactly all the solutions of Bx == v,
or v has a non-constant coefficient, in which case s is False Ax == u has no
constant solution.

This algorithm is used both in solving parametric problems and in
determining if an element a of K is a derivative of an element of K or the
logarithmic derivative of a K-radical using the structure theorem approach.

Because Poly does not play well with Matrix yet, this algorithm assumes that
all matrix entries are Basic expressions.
Nc                    > [        U TSS9$ )NTbasic)r   )xr3   s    r#   r$   !constant_system.<locals>.<lambda>  s    *Q$/r&   c                    > T" U 5      T-  $ r   rI   )r   rB   DAijs    r#   r$   r     s    1r&   )row_joinrref	itertoolsproductrangecolsrowsexprhasT	applyfunccol_joinr   r   )rA   ur3   Aur   r"   r!   RiRm1um1AjrB   r   s     `        @@r#   constant_systemr      s    , t	
ABGGIEB, a"f:r!R%yq/A!!%-qvv?T7<<RTT""a4BQ!tW:D,,45CAD'D.C1a4BHAHA

3A

63%01A @  6Mr&   c                 D   [        [        U Vs/ s H  n[        XU5      PM     sn6 5      u  pgU nU[        X5      -   n	[        Xg5       V
Vs/ s H  u  pU[        X5      -
  PM     nn
n[        U5      nX0R	                  UR
                  5      -
  nXXU4$ s  snf s  snn
f )a   
Special Polynomial Differential Equation algorithm: Parametric Version.

Explanation
===========

Given a derivation D on k[t], an integer n, and a, b, q1, ..., qm in k[t]
with deg(a) > 0 and gcd(a, b) == 1, return (A, B, Q, R, n1), with
Qq = [q1, ..., qm] and R = [r1, ..., rm], such that for any solution
c1, ..., cm in Const(k) and q in k[t] of degree at most n of
a*Dq + b*q == Sum(ci*gi, (i, 1, m)), p = (q - Sum(ci*ri, (i, 1, m)))/a has
degree at most n1 and satisfies A*Dp + B*p == Sum(ci*qi, (i, 1, m))
)r*   r+   r   r   r   r,   )r=   r   r   ry   r3   qiRZrA   rv   r   ziQqn1s                 r#   	prde_spder   )  s     A>Ab'b1A>?@DA	A	JqA03A		:	fb"z"!
!	B	:QA	
XXbdd^	B" ? 
;s   BBc                   ^^ U R                  TR                  5      n[        T5      n[        STR                  5      /U-  n[        R
                  " [        USS5      [        U5      5       Hu  u  pxTU   R                  Xt-   5      U R                  5       -  n	[        U	TR                  U-  -  TR                  5      n
Xh   U
-   Xh'   TU   [        U
T5      -
  X
-  -
  TU'   Mw     [        S T 5       5      (       a  SnO[        U4S jT 5       5      n[        US-   UU4S jTR                  5      n[        U[        US-   STR                  5      T5      u  p[        UTR                  5      nUR!                  [        UR"                  UTR                  5      5      R%                  UR!                  U* 5      5      nXm4$ )a  
Parametric Poly Risch Differential Equation - No cancellation: deg(b) large enough.

Explanation
===========

Given a derivation D on k[t], n in ZZ, and b, q1, ..., qm in k[t] with
b != 0 and either D == d/dt or deg(b) > max(0, deg(D) - 1), returns
h1, ..., hr in k[t] and a matrix A with coefficients in Const(k) such that
if c1, ..., cm in Const(k) and q in k[t] satisfy deg(q) <= n and
Dq + b*q == Sum(ci*qi, (i, 1, m)), then q = Sum(dj*hj, (j, 1, r)), where
d1, ..., dr in Const(k) and A*Matrix([[c1, ..., cm, d1, ..., dr]]).T == 0.
r   r   c              3   8   #    U  H  oR                   v   M     g 7fr   r   rK   r   s     r#   rM   )prde_no_cancel_b_large.<locals>.<genexpr>Z  s     
""::r   c              3   X   >#    U  H  oR                  TR                  5      v   M!     g 7fr   r   rK   r   r3   s     r#   rM   r   ]  s     -1R2441   '*r'   c                 ,   > TU   R                  U 5      $ r   r   r   s     r#   r$   (prde_no_cancel_b_large.<locals>.<lambda>^  s    qtxx{r&   )r   r,   r   r   r   r   r   r   LCr   r   ru   r   r   zeroseyer   r   r   )r   r   ry   r3   dbr   Hr   r!   sisitndcr   rA   r   r>   s    ` `            r#   prde_no_cancel_b_larger   B  so    
"$$BAA	aA!!%2r"2E!H=qTXXafaddf$BrttQwJ%td{tjr**QV3!	 > 
"
"""-1--rAvq2BDD9A1eBFArtt4b9DAArttA	

5BDD)*33AJJrNCA6Mr&   c           
      n
  ^^ [        T5      n[        STR                  5      /U-  n[        R                  " [        USS5      [        U5      5       H  u  pgTU   R                  UTR                  R                  TR                  5      -   S-
  5      UTR                  R                  5       -  -  n[        UTR                  U-  -  TR                  5      n	XW   U	-   XW'   TU   [        U	T5      -
  X	-  -
  TU'   M     U R                  TR                  5      S:  Gad  [        U5       Hx  n[        TU   R                  U R                  TR                  5      5      U R                  5       -  TR                  5      nXW   U-   XW'   TU   [        UT5      -
  X-  -
  TU'   Mz     [        S T 5       5      (       a  Sn
O[        U4S jT 5       5      n
[        U
S-   UU4S jTR                  5      n[        U[        U
S-   STR                  5      T5      u  p[!        UTR                  5      nUR#                  [        UR$                  UTR                  5      5      R'                  UR#                  U* 5      5      nX\4$ TR                  nTR(                  S:w  a  [+        T5         TR                  n[-        U USS	9u  nnT Vs/ s H  n[-        UR/                  5       USS	9PM     nn[1        UUUT5      u  nnS
S
S
5        W VVs/ s H0  u  nn[        UR3                  5       UR3                  5       -  USS	9PM2     nnn[        R4                  " WR7                  5       U5      nOT[        SUSS	9/n[        T Vs/ s H  nUR/                  5       PM     sn[8        R:                  /-   /TR                  5      n[        U4S jT 5       5      nUS:  aB  [        UUU4S jTR                  5      n[        U[        USTR                  5      T5      u  nnO[        SU/ TR                  5      n[        U5      n[!        UTR                  5      nUR#                  [        UR$                  UU-   TR                  5      5      nUR#                  [        UR$                  UTR                  5      5      nUR#                  [        UUTR                  5      5      R#                  U* 5      nUU-   UR'                  U5      R'                  U5      4$ s  snf ! , (       d  f       GN!= fs  snnf s  snf )a  
Parametric Poly Risch Differential Equation - No cancellation: deg(b) small enough.

Explanation
===========

Given a derivation D on k[t], n in ZZ, and b, q1, ..., qm in k[t] with
deg(b) < deg(D) - 1 and either D == d/dt or deg(D) >= 2, returns
h1, ..., hr in k[t] and a matrix A with coefficients in Const(k) such that
if c1, ..., cm in Const(k) and q in k[t] satisfy deg(q) <= n and
Dq + b*q == Sum(ci*qi, (i, 1, m)) then q = Sum(dj*hj, (j, 1, r)) where
d1, ..., dr in Const(k) and A*Matrix([[c1, ..., cm, d1, ..., dr]]).T == 0.
r   r   r'   c              3   8   #    U  H  oR                   v   M     g 7fr   r   r   s     r#   rM   )prde_no_cancel_b_small.<locals>.<genexpr>  r   r   c              3   X   >#    U  H  oR                  TR                  5      v   M!     g 7fr   r   r   s     r#   rM   r     s     1qYYrtt__qr   c                 ,   > TU   R                  U 5      $ r   r   r   s     r#   r$   (prde_no_cancel_b_small.<locals>.<lambda>  s    1Q488A;r&   rj   Tr   Nc              3   X   >#    U  H  oR                  TR                  5      v   M!     g 7fr   r   r   s     r#   rM   r     s     (aIIbddOOar   c                 2   > TU   R                  U S-   5      $ r   r   r   s     r#   r$   r     s    adhhq1uor&   )r   r   r,   r   r   r   r   rr   r   r   r   r   ru   r   r   r   r   r   r   r   ro   r   r   TCparam_rischDEas_exprfrom_Matrix	to_Matrixr	   Zero)r   r   ry   r3   r   r   r   r!   r   r   r   r   rA   r   r>   r,   t0r?   r@   r   Q0frv   r0   r1   rr   r   rL   ICs    ` `                          r#   prde_no_cancel_b_smallr   f  s9    	AA	aA!!%1b/58<qTXXa"$$++bdd++a/0!BDDGGI+>BrttQwJ%td{tjr**QV3!	 = 	xx~qAadhhqxx~.qttv5rtt<B4"9ADQ4*R,,qt3AaD  &A&&&B1q11B2616=q%Q244"8"=244LJJuQVVQ-.77

A2Gv 	A	ww&BBQ$/FB=>?Qr'"%%'2T2QB? RR0DAq	  $ R "**,rzz|+Qd; 	
 q{{}a0 !Qd#$q)qRUUWq)QVVH45rtt< 	(a((A1u1a5rtt<q%1bdd"3R81 1aRTT" 	AAArttA	

5Q-.A	

5BDD)*A	

5Artt$%..r2Aq5!**Q-((+++i @  " *s*   +T
#T-T7T,T2T
T)c                 "   / nUR                   S:X  a*  [        U5         [        XR                  SS9u  pVSSS5        [	        USS5       GH  nUR                   S:X  aj  [        U5         [        X[        UR                  U5      UR                  -  -  R                  U R                  5      -   UR                  SS9u  pVSSS5        [        U5         U Vs/ s H'  n[        UR                  U5      UR                  SS9PM)     n	n[        WWX5      u  pSSS5        W
 VVs/ s H9  u  p[        UR                  5       UR                  5       -  UR                  SS9PM;     n
nnWR                  UR                  5      n[        U
5      nXr:X  a  UnO>UR                  WR                  [!        UR"                  XR                  5      5      5      nS/U-  S/U-  nn[	        U5       HO  nU
U   UR                  U-  R                  U
U   R                  5      -  nUUU'   [        UU5      U U-  -
  * UU'   MQ     UU-  nUU-   nGM      UW4$ ! , (       d  f       GN"= f! , (       d  f       GN= fs  snf ! , (       d  f       GNi= fs  snnf )z

Pg, 237.
ri   Tr   Nr   rg   )ro   r   r   r,   r   r   rU   r   r   r   r   r   set_gensr   r   r   r   r   )r   r   ry   r3   r   r?   r@   r!   r   QyfiAir0   r1   r   r   Fihir"   hjis                       r#   prde_cancel_liouvillianr    s5    	A 
ww+BQD1FB   1b"77e# BDD")=bdd)B&C%L%LQVV%T!T "D2 $ B?@Aq!'!%%(BDD5qBA"2r22FB   !" FB 2::<

,bdd$?  	 "[[W6AAJJuQVVR'>?@ATF2IB rAQ%2447++BqEJJ77CBqE b)AcE12BqE	  	
R F? B q6MI  
 $# B  "s=   I)AI"I9.I4I9$A J
I"
I1	4I99
J	c                 
  ^^ [        T5      nUS:  a  [        S T 5       5      (       a  / [        SUTR                  5      4$ [	        U4S jT 5       5      n[        US-   UU4S jTR                  5      n[        U[        UR                  STR                  5      T5      u  p/ U4$ U R                  (       Ga  U R                  5       n UR                  5       R                  U 5      T V
s/ s H!  oR                  5       R                  U 5      PM#     sn
snmUR                  (       dW  TR                  S:X  d9  UR                  5       [	        STR                  R                  5       S-
  5      :  a  [!        UTUT5      $ UR                  (       d/  UR                  5       TR                  R                  5       S-
  :  a<  TR                  S:X  d  TR                  R                  5       S:  a  [#        UTUT5      $ TR                  R                  5       S:  a  UR                  5       TR                  R                  5       S-
  :X  aV  X1R%                  5       R                  5       * TR                  R%                  5       R                  5       -  :  a  ['        S5      eTR                  S	;   a  [)        UTUT5      $ ['        S
5      eU R*                  U R,                  /U-  pUS:  ae  [/        XTUT5      u  pmp[1        X5       VVs/ s H  u  pXU-  -   PM     nnnX-  nU R3                  U5      nUR                  (       d  OUS:  a  Me  [5        TW5      u  nn[        U[        UR                  STR                  5      T5      u  pUR7                  5       nU(       d  / [9        UTR                  5      4$ [        U/5      nU Vs/ s H  nUU-  S   PM     nn[        U/5      nU Vs/ s H  nUU-  S   PM     nn[;        U R=                  U5      UR=                  U5      XT5      u  nnUU Vs/ s H  nUU-  PM
     sn-   n[9        UTR                  5      * nU H  nUR?                  U5      nM     UR?                  [        U[        U5      TR                  5      5      nURA                  [        UR                  UTR                  5      R?                  U5      5      nUU4$ s  sn
f s  snnf s  snf s  snf s  snf )a  Polynomial solutions of a parametric Risch differential equation.

Explanation
===========

Given a derivation D in k[t], a, b in k[t] relatively prime, and q
= [q1, ..., qm] in k[t]^m, return h = [h1, ..., hr] in k[t]^r and
a matrix A with m + r columns and entries in Const(k) such that
a*Dp + b*p = Sum(ci*qi, (i, 1, m)) has a solution p of degree <= n
in k[t] with c1, ..., cm in Const(k) if and only if p = Sum(dj*hj,
(j, 1, r)) where d1, ..., dr are in Const(k) and (c1, ..., cm,
d1, ..., dr) is a solution of Ax == 0.
r   c              3   8   #    U  H  oR                   v   M     g 7fr   r   r   s     r#   rM   %param_poly_rischDE.<locals>.<genexpr>  r   r   r'   c              3   X   >#    U  H  oR                  TR                  5      v   M!     g 7fr   r   r   s     r#   rM   r
    s     ,!B		"$$!r   c                 ,   > TU   R                  U 5      $ r   r   )r!   r"   r   s     r#   r$   $param_poly_rischDE.<locals>.<lambda>  r   r&   rj   rF   z0prde_no_cancel_b_equal() is not yet implemented.)ri   rg   z?non-linear and hypertangent cases have not yet been implemented)!r   r   r   r,   ru   r   r   r   	is_groundr   to_fieldexquo_groundr   ro   r   rr   r   r   rU   NotImplementedErrorr  onezeror   r+   r-   r   	nullspacer   param_poly_rischDEr/   r   r   )r=   r   r   ry   r3   r   r   r   rA   r   r   alphabetarL   betair   rr   qqVMqqvjMbetar   grv   gkr<   s     ` `                      r#   r  r    s(    	AA1u &A&&&uQ244(((,!,,1q5!5rtt<q%244"8"=1u{{{DDFzz|((+VW-XVWPRkkm.H.H.KVW-X1yybgg/
SBDDKKMA$566)!Q266yyAHHJ)::WW&"$$++-1*<)!Q266ddkkmq hhjBDDKKMA--99;>>##BDDLLN$5$5$777% '' ( (
 ww...q!Q;;) +> ? ? %%!&&!4
q&!!1b1a25d,?,YUb ,?
 EE!H{{ q& $Aq)EB 1eAFFArtt4b9DA 	
A 3q"$$< ",C !q#b&!qA! D6NE!"#2%(AA#
 aeeAha!;DAq 	
""U2X""A 
QAJJrN 	

5CFBDD)*A	

5BDD)22156Aa4KQ .Y> @R 	" 	$  #s   .(S0S5S;1T 9Tc                 Z   [        U5      n[        XU5      u  nu  pUnU VVs/ s H  u  pxXW-  R                  USS9PM     nnn[        XX#5      u  n	u  pp,Xl-  n[	        XXU5      u  pp/Xo-  nUR                  U5      nUR                  U5      UR                  U5      U VVs/ s H  u  nnUR                  UU-  SS9PM     nnnnn	[        U	UUU5      u  nn[        U[        UR                  SUR                  5      U5      u  nnUR                  5       nU(       d  / [        XCR                  5      4$ [        U/5      nU Vs/ s H  nUU-  S   PM     nn [        U	UUUSS9n[#        U	UUUU5      u  nn[        XCR                  5      * nU H  nUR%                  U5      nM     UR%                  [        U[        U5      UR                  5      5      nUR'                  [        UR                  XCR                  5      R%                  U5      5      nUR                  5       n[        U5      n[        U5      UU-   4nU Vs/ s H  nUSU UU* S -   PM     n nU  V!V"s/ s H  n!U!  H  n"U"PM     M     n#n!n"[        / UQU#PUR                  P76 nUR                  5       n$[        U$ V%s/ s H  n%U%SS PM
     sn%UR                  5      n&U V's/ s H  n'U'R                  USS9PM     sn'U&4$ s  snnf s  snnf s  snf ! [          a    Sn GNf = fs  snf s  sn"n!f s  sn%f s  sn'f )a4  
Solve a Parametric Risch Differential Equation: Dy + f*y == Sum(ci*Gi, (i, 1, m)).

Explanation
===========

Given a derivation D in k(t), f in k(t), and G
= [G1, ..., Gm] in k(t)^m, return h = [h1, ..., hr] in k(t)^r and
a matrix A with m + r columns and entries in Const(k) such that
Dy + f*y = Sum(ci*Gi, (i, 1, m)) has a solution y
in k(t) with c1, ..., cm in Const(k) if and only if y = Sum(dj*hj,
(j, 1, r)) where d1, ..., dr are in Const(k) and (c1, ..., cm,
d1, ..., dr) is a solution of Ax == 0.

Elements of k(t) are tuples (a, d) with a and d in k[t].
Tr(   r'   r   )
parametric   N)r   r   r   rC   r   r-   r/   r   r   r   r   r,   r  r   r   r   r  r  r   r   )(r0   r1   r2   r3   r   r   gammar   r8   r=   r?   r@   hnrA   rv   hsr  giagidr   r   r   r  Mqr  rL   ry   r<   WvshapewlelementsrowerW   r   nir   hks(                                           r#   r   r     s   " 	AA!""-KAx E789qVR!$r4	(qA9*219Ax 
KE$QB26KA! 
KE	aAeeAha#S $'::c!eT:#B  #qA #1aB/DAq 1eAFFArtt4b9DAq 	
A 3q$$<	B a"R%aA 
 Aq"6 aAq"-DAq 
QAJJrN 	

5CFBDD)*A	

5DD)22156A 	
A 	AAVQqSME+,-1R2AQBC 1H-"0(3CqQCQ(E0 	##u#bdd#A	A 	""1"BDD)A567QrBIIeTI*Q7::_ 	:#J 	!   	N .0 #7s;   K4% K:
L L L%L0L#L(LLc           	        ^ [        UT5      u  pEU VVs/ s H  u  pg[        UT5      PM     nnn[        [        U6 5      u  p[        S U4U	-   5      nUR	                  UR                  TR                  5      5      nUn[        UT5      * nSnTR                  S;   a  [        S U4U
-   5      nUU-  nX[        UT5      -  R                  U5      -  n[        [        XTR                  5      [        U4S jU 5       5      5      nUR                  TR                  5      UR                  TR                  5      -   [        SSTR                  R                  TR                  5      -
  U-
  5      -   nO[        eU VVs/ s H  u  no}* U-  U-  R!                  USS9PM     nnnXXX-  U -  R!                  USS9U4$ s  snnf s  snnf )	a  
Simpler version of step 1 & 2 for the limited integration problem.

Explanation
===========

Given a derivation D on k(t) and f, g1, ..., gn in k(t), return
(a, b, h, N, g, V) such that a, b, h in k[t], N is a non-negative integer,
g in k(t), V == [v1, ..., vm] in k(t)^m, and for any solution v in k(t),
c1, ..., cm in C of f == Dv + Sum(ci*wi, (i, 1, m)), p = v*h is in k<t>, and
p and the ci satisfy a*Dp + b*p == g + Sum(ci*vi, (i, 1, m)).  Furthermore,
if S1irr == Sirr, then p is in k[t], and if t is nonlinear or Liouvillian
over k, then deg(p) <= N.

So that the special part is always computed, this function calls the more
general prde_special_denom() automatically if it cannot determine that
S1irr == Sirr.  Furthermore, it will automatically call bound_degree() when
t is linear and non-Liouvillian, which for the transcendental case, implies
that Dt == a*t + b with for some a, b in k*.
c                 $    U R                  U5      $ r   r   r    s     r#   r$   *limited_integrate_reduce.<locals>.<lambda>#  r   r&   r   )rj   ri   rg   rh   c                 $    U R                  U5      $ r   r   r    s     r#   r$   r4  ,  s    qr&   c              3   T   >#    U  H  u  p[        XTR                  5      v   M     g 7fr   )r   r,   )rK   r   r8   r3   s      r#   rM   +limited_integrate_reduce.<locals>.<genexpr>/  s(      0FB 1<BBDD0I0Is   %(r'   Tr(   )r   r*   r+   r   r-   r.   r,   r   ro   r/   rq   r   r   ru   rr   r  r   )r0   r1   r2   r3   r4   r5   r   r8   EEnEsr>   r$  r=   r   r   r%  mur   r  s      `                r#   limited_integrate_reducer<    s   * R FB*+,!R	!A,#q']FB$rebj1A	
qvvbdd|	B
A	B	A	A 
ww55)B52:6rE	B##((,,RRTT*C 00 - 
 IIbddObiio-Aq244;;rtt;L7Lr7Q0RR "!;<=1R"R%(		2t		,1A=!b((T(:A>>3 	-0 	>s   G #Gc                 "  ^^^ U [        SUR                  5       -  UR                  5      -  UR                  5       p[        SUR                  5      n[        SUR                  5      nX4/U-   n[	        XEX#5      u  mnUR                  5       nU Vs/ s H  oS   S:w  d  M  UPM     nnU(       d  gUS   S   n	US   U	* -  m[        T5      n
[        T5      U
-
  S-
  m[        TSTS-    5      n[        UUU4S j[        U
5       5       5      * nUR                  5       u  p[        XR                  5      [        XR                  5      nnU[        SUR                  5       -  UR                  5      -  UR                  5       4nUU4$ s  snf )zI
Solves the limited integration problem:  f = Dv + Sum(ci*wi, (i, 1, n))
r'   r   Nc              3      >#    U  H>  nTTS -   U-      TU   S   R                  5       -  TU   S    R                  5       -  v   M@     g7f)r'   r   N)r   )rK   r!   r<   r   r*  s     r#   rM   $limited_integrate.<locals>.<genexpr>T  sL      #!A 1q519ad1goo//!Q0AA!s   AA	)r   r   r,   monicr   r  r   r*   rX   r   as_numer_denom)r0   r1   r2   r3   FaFdrA   r  r*  c0rL   r   yy_numy_denYaYdYr<   r   s           `         @@r#   limited_integraterK  =  se    QruuwY%%rxxz 
aB	aB

QA'DAq	A#Aq1AA# qT!WaD2#JFFQJN1a!e #q# # #'')eTT"D$5BtAbeegIrtt$$bhhj0!t! 	$s   F#Fc                    U=(       d    [        S5      nU R                  U5      u  pgUR                  U5      u  p[        S[        UR                  U5      R                  UR                  5      S-
  5      n
[        UR                  UR                  5      UR                  UR                  5      5      nUR                  UR                  5      U
:  Ga  [        U
S-   US-   5       Vs/ s H'  oR                  U5      XXR                  U5      -  -
  PM)     nn[        X5      nU(       a  X   R                  (       d  gX   R                  5       u  nnUR                  UR                  5      nUR                  UR                  5      nUU -  U-  UU-  U-  -
  nX-  n[        UUUS5      nUc  gUu  nnUR                  (       d  UR                  (       a  gUU-  UU-  U4$ UR                  UR                  5      U
:  a  g[        UR                  UR                  5      R!                  5       UR                  UR                  5      R!                  5       5      nUR#                  5       R                  UR#                  5       5      [%        UUR                  5      -  n['        UU5      u  nnUUR)                  UR+                  UR                  5      5      -  nUR-                  UR                  5      (       d  gU UR/                  U5      -  R                  U5      u  nnUUR/                  U5      -  R                  U5      u  nn [        UR                  UR                  5      5       Vs/ s H)  nUR                  U5      UU R                  U5      -  -
  PM+     nn[        X5      nU(       a  X   R                  (       d  gX   R                  5       u  nnUR                  UR                  5      U -  U-  UR                  UR                  5      U-  U-  -
  nX-  n[        UUU5      nUc  gUu  nnUR                  (       d  UR                  (       a  gUU-  UU-  U4$ s  snf s  snf )a  
Parametric logarithmic derivative heuristic.

Explanation
===========

Given a derivation D on k[t], f in k(t), and a hyperexponential monomial
theta over k(t), raises either NotImplementedError, in which case the
heuristic failed, or returns None, in which case it has proven that no
solution exists, or returns a solution (n, m, v) of the equation
n*f == Dv/v + m*Dtheta/theta, with v in k(t)* and n, m in ZZ with n != 0.

If this heuristic fails, the structure theorem approach will need to be
used.

The argument w == Dtheta/theta
c1r   r'   Nrf   )r   r   ru   r   r,   r   r   r   r   is_RationalrA  rU   r   !is_log_deriv_k_t_radical_in_fieldr   r   r   r@  r   r   r-   r.   r   r/   )!r0   r1   wawdr3   rM  r;   r=   r   r   rv   r   r!   eqsr   r   r   M_polyN_polynfmwanfmwdQvr   r*  r>   llnlsr   u1r1u2r2s!                                    r#   parametric_log_deriv_heur_  \  s|   & 
	uT{B66":DA66":DAAz"$$#**2440145AAHHRTTNAHHRTTN+Axx~/4QUAE/BC/B!uuQx"UU1X+%/BC#N))u##%1166"166"r	"vby|+.ueRH:199		!QqS!}xx~BJJrtt!2::bdd#3#6#6#89A

rxxz"4244=0ABFB
266"''"$$-  A55;; rl"FBrl"FB-2188BDD>-B
C-B266!9r"&&)|#-BC
CcAAE%%5!DAqIIbddOBr!AIIbddOB$6r$99EEE	*5%	<B	zDAqyyAIIaC1a=y DP Ds   ).Q)10Q.c                      [        XX#U5      nU$ r   )r_  )r0   r1   rP  rQ  r3   rA   s         r#   rt   rt     s     	!4A Hr&   c                 	  ^ U[        U T5      -  U [        UT5      -  -
  X-  pCUR                  USS9u  p4[        TR                  5      [        TR                  5      :w  a  TR
                   Vs/ s H  oUS:X  d  M
  UPM     sn(       dD  TR
                   Vs1 s H  oUS:X  d  M
  UiM     sn[        TR                  S5      5      -
  (       a  [        S5      e[        S5      eTR                  S5       Vs/ s HS  nTR                  U   R                  [        TR                  U   TR                  U   5      5      R                  5       PMU     nnTR                  S5       Vs/ s H   nTR                  U   R                  5       PM"     nn[        5       n[        Xg-   /U5      n	[        UR                  5       UR                  5       -  /U5      n
[        XT5      u  pUR!                  5       nU(       a  [#        U4S	 jU 5       5      (       d  g
[#        S U 5       5      (       d  [        S5      eTR                  S5       Vs/ s H  nTR$                  U   PM     snTR                  S5       Vs/ s H  nTR                  U   PM     sn-   n['        [)        X5      5      n[+        U VVs/ s H  u  p_[-        X_5      PM     snn6 nTR                  S5       Vs/ s H  nTR                  U   PM     snTR                  S5       Vs/ s H  nTR$                  U   PM     sn-   n/ n/ n[)        UU5       H  u  p_UR/                  5       u  nn[1        U5      u  nnUR3                  [-        [5        UU5      /U VVs/ s H  u  nn[5        UUU-  5      PM     snn-   6 5        [1        U5      u  nnUR3                  [-        [5        UU5      /U VVs/ s H  u  nn[5        UUU-  5      PM     snn-   6 5        M     [        U R                  5       UR                  5       -  [-        U6 -  [-        U6 -  5      nUUU4$ s  snf s  snf s  snf s  snf s  snf s  snf s  snnf s  snf s  snf s  snnf s  snnf )aq
  
Checks if Df/f is the derivative of an element of k(t).

Explanation
===========

a in k(t) is the derivative of an element of k(t) if there exists b in k(t)
such that a = Db.  Either returns (ans, u), such that Df/f == Du, or None,
which means that Df/f is not the derivative of an element of k(t).  ans is
a list of tuples such that Add(*[i*j for i, j in ans]) == u.  This is useful
for seeing exactly which elements of k(t) produce u.

This function uses the structure theorem approach, which says that for any
f in K, Df/f is the derivative of a element of K if and only if there are ri
in QQ such that::

        ---               ---       Dt
        \    r  * Dt   +  \    r  *   i      Df
        /     i     i     /     i   ---   =  --.
        ---               ---        t        f
     i in L            i in E         i
           K/C(x)            K/C(x)


Where C = Const(K), L_K/C(x) = { i in {1, ..., n} such that t_i is
transcendental over C(x)(t_1, ..., t_i-1) and Dt_i = Da_i/a_i, for some a_i
in C(x)(t_1, ..., t_i-1)* } (i.e., the set of all indices of logarithmic
monomials of K over C(x)), and E_K/C(x) = { i in {1, ..., n} such that t_i
is transcendental over C(x)(t_1, ..., t_i-1) and Dt_i/t_i = Da_i, for some
a_i in C(x)(t_1, ..., t_i-1) } (i.e., the set of all indices of
hyperexponential monomials of K over C(x)).  If K is an elementary extension
over C(x), then the cardinality of L_K/C(x) U E_K/C(x) is exactly the
transcendence degree of K over C(x).  Furthermore, because Const_D(K) ==
Const_D(C(x)) == C, deg(Dt_i) == 1 when t_i is in E_K/C(x) and
deg(Dt_i) == 0 when t_i is in L_K/C(x), implying in particular that E_K/C(x)
and L_K/C(x) are disjoint.

The sets L_K/C(x) and E_K/C(x) must, by their nature, be computed
recursively using this same function.  Therefore, it is required to pass
them as indices to D (or T).  E_args are the arguments of the
hyperexponentials indexed by E_K (i.e., if i is in E_K, then T[i] ==
exp(E_args[i])).  This is needed to compute the final answer u such that
Df/f == Du.

log(f) will be the same as u up to a additive constant.  This is because
they will both behave the same as monomials. For example, both log(x) and
log(2*x) == log(x) + log(2) satisfy Dt == 1/x, because log(2) is constant.
Therefore, the term const is returned.  const is such that
log(const) + f == u.  This is calculated by dividing the arguments of one
logarithm from the other.  Therefore, it is necessary to pass the arguments
of the logarithmic terms in L_args.

To handle the case where we are given Df/f, not f, use is_deriv_k_in_field().

See also
========
is_log_deriv_k_t_radical_in_field, is_log_deriv_k_t_radical

Tr(   rh   ri   logXReal version of the structure theorems with hypertangent support is not yet implemented.ANonelementary extensions not supported in the structure theorems.rg   c              3   N   >#    U  H  n[        UTS S9R                  v   M     g7fTr   Nr   r   rK   r!   r3   s     r#   rM   is_deriv_k.<locals>.<genexpr>        Iq!
1b5==q   "%Nc              3   8   #    U  H  oR                   v   M     g 7fr   rN  rK   r!   s     r#   rM   ri  #       ,!Q==!r   8Cannot work with non-rational coefficients in this case.)r   r   r   extsrB   casessetindicesr  r/   r   r   r   r   r   r   r   r   extargsr*   r+   r   r   rA  r   appendr   )r0   r1   r3   dfadfdr!   E_partL_partdumlhsrhsrA   r   termsansr"   resultargtermsrX  ldrr   icoeffitermsr   r/  rz   dtermsconsts     `                         r#   
is_deriv_kr    s   z :b"%%:b"+=(==zz#tz,HC 277|s244y xx.x!:Ax.XX:Xk)9!X:BJJu-./% 'M N N " #) * 	* FHZZPUEVWEVbdd1gkk$rttAwQ0199;EVFW)+E):;):Abdd1goo):F; 'C
&/"C
(C
#++--.
4C3R(DA	ACIqIII
 ,!,,,% '- . . .0ZZ->?->bjjm->?&(jj&78&7RTT!W&789Es5}%C53q956F*,**U*;<*;Qa*;<,.JJu,=>,=qRZZ],=>?HABHa( '')1!)!FA/62R641a3q!A#;62RRTU!)!		#VQ 0F3SFDAqC1Q3KF3S SUV ) 2::<

4S!W<S"XEFE''k /: X;. @85<> 3S3SsO   0	Q=Q	Q&Q8AQ''Q
Q8Q!4Q&
#Q,Q1Q6Q<c                 <  ^ U(       a3  U[        U T5      -  U [        UT5      -  -
  R                  US-  SS9u  pEOXpT[        TR                  5      [        TR                  5      :w  a  TR
                   Vs/ s H  ofS:X  d  M
  UPM     sn(       dD  TR
                   Vs1 s H  ofS:X  d  M
  UiM     sn[        TR                  S5      5      -
  (       a  [        S5      e[        S5      eTR                  S	5       Vs/ s HS  nTR                  U   R                  [        TR                  U   TR                  U   5      5      R                  5       PMU     nnTR                  S5       Vs/ s H   nTR                  U   R                  5       PM"     nn[        5       n	[        Xx-   /U	5      n
[        UR                  5       UR                  5       -  /U	5      n[        XT5      u  pUR!                  5       nU(       a  [#        U4S
 jU 5       5      (       d  g[#        S U 5       5      (       d  [        S5      e[$        R&                  [)        [*        U Vs/ s H  ofR-                  5       S   PM     sn5      -  nX-  nTR                  S	5       Vs/ s H  nTR                  U   PM     snTR                  S5       Vs/ s H  nTR.                  U   PM     sn-   n[1        [3        X5      5      n[5        U VVs/ s H  u  nn[7        UU5      PM     snn6 nTR                  S	5       Vs/ s H  nTR.                  U   PM     snTR                  S5       Vs/ s H  nTR                  U   PM     sn-   n[        U R                  5       UR                  5       -  [9        [3        UU5       VVs/ s H  u  nn[5        UUU-  5      PM     snn6 -
  5      nUUUU4$ s  snf s  snf s  snf s  snf s  snf s  snf s  snf s  snnf s  snf s  snf s  snnf )a
  
Checks if Df is the logarithmic derivative of a k(t)-radical.

Explanation
===========

b in k(t) can be written as the logarithmic derivative of a k(t) radical if
there exist n in ZZ and u in k(t) with n, u != 0 such that n*b == Du/u.
Either returns (ans, u, n, const) or None, which means that Df cannot be
written as the logarithmic derivative of a k(t)-radical.  ans is a list of
tuples such that Mul(*[i**j for i, j in ans]) == u.  This is useful for
seeing exactly what elements of k(t) produce u.

This function uses the structure theorem approach, which says that for any
f in K, Df is the logarithmic derivative of a K-radical if and only if there
are ri in QQ such that::

        ---               ---       Dt
        \    r  * Dt   +  \    r  *   i
        /     i     i     /     i   ---   =  Df.
        ---               ---        t
     i in L            i in E         i
           K/C(x)            K/C(x)


Where C = Const(K), L_K/C(x) = { i in {1, ..., n} such that t_i is
transcendental over C(x)(t_1, ..., t_i-1) and Dt_i = Da_i/a_i, for some a_i
in C(x)(t_1, ..., t_i-1)* } (i.e., the set of all indices of logarithmic
monomials of K over C(x)), and E_K/C(x) = { i in {1, ..., n} such that t_i
is transcendental over C(x)(t_1, ..., t_i-1) and Dt_i/t_i = Da_i, for some
a_i in C(x)(t_1, ..., t_i-1) } (i.e., the set of all indices of
hyperexponential monomials of K over C(x)).  If K is an elementary extension
over C(x), then the cardinality of L_K/C(x) U E_K/C(x) is exactly the
transcendence degree of K over C(x).  Furthermore, because Const_D(K) ==
Const_D(C(x)) == C, deg(Dt_i) == 1 when t_i is in E_K/C(x) and
deg(Dt_i) == 0 when t_i is in L_K/C(x), implying in particular that E_K/C(x)
and L_K/C(x) are disjoint.

The sets L_K/C(x) and E_K/C(x) must, by their nature, be computed
recursively using this same function.  Therefore, it is required to pass
them as indices to D (or T).  L_args are the arguments of the logarithms
indexed by L_K (i.e., if i is in L_K, then T[i] == log(L_args[i])).  This is
needed to compute the final answer u such that n*f == Du/u.

exp(f) will be the same as u up to a multiplicative constant.  This is
because they will both behave the same as monomials.  For example, both
exp(x) and exp(x + 1) == E*exp(x) satisfy Dt == t. Therefore, the term const
is returned.  const is such that exp(const)*f == u.  This is calculated by
subtracting the arguments of one exponential from the other.  Therefore, it
is necessary to pass the arguments of the exponential terms in E_args.

To handle the case where we are given Df, not f, use
is_log_deriv_k_t_radical_in_field().

See also
========

is_log_deriv_k_t_radical_in_field, is_deriv_k

rF   Tr(   rh   ri   rb  rc  rd  rg   c              3   N   >#    U  H  n[        UTS S9R                  v   M     g7frf  rg  rh  s     r#   rM   +is_log_deriv_k_t_radical.<locals>.<genexpr>  rj  rk  Nc              3   8   #    U  H  oR                   v   M     g 7fr   rm  rn  s     r#   rM   r    ro  r   rp  r'   )r   r   r   rq  rB   rr  rs  rt  r  r/   r   r   r   r   r   r   r   r   r	   Oner   r   rA  ru  r*   r+   r   r   r   )r0   r1   r3   Dfrw  rx  r!   ry  rz  r{  r|  r}  rA   r   ry   r~  r  r"   r  r  r  s     `                  r#   is_log_deriv_k_t_radicalr  =  s   z 
z"b))Bz"b/A,AAII"a% J S S 277|s244y xx.x!:Ax.XX:Xk)9!X:BJJu-./% 'M N N " #) * 	* FHZZPUEVWEVbdd1gkk$rttAwQ0199;EVFW)+E):;):Abdd1goo):F; 'C
&/"C
(C
#++--.
4C3R(DA	ACIqIII
 ,!,,, & '- . . fT1#E1a$4$4$6q$91#EFFAFA')zz%'89'8!bdd1g'89,.JJu,=>,=qRZZ],=>?Es5}%C5A3q!956F 13

50AB0A1A0AB&(jj&78&7RTT!W&789H2::<

4c(A.>?.>dac!QqSk.>?@A BE E**g /: X;4 $F9>5 C8?sO   8	O%O%!	O*.O* AO//'O4O9O>PP
3P!P8Pc                 n	   U R                  USS9u  p[        X5      u  pVUR                  (       d   U=(       d    [        S5      n[	        XX$S9u  pxU(       d  gU V	V
s/ s H  u  pXR                  5       4PM     nn	n
[        S U 5       5      (       d  g[        [        U6 5      =(       d    / / /u  p[        [        U5      5       VV	s/ s H'  nX     H  n	X~   S   R                  XI5      U	4PM     M)     nnn	[        U R                  5       UR                  5       -  [        XrU5      -
  5      nUR                  UR                  5      nUc  gUR!                  UR                  5      [#        SUR$                  R!                  UR                  5      5      :  a  gUS:X  a  UR&                  nUS	:X  a  [)        UR                  U5      R                  [+        UR                  UR                  5      SS9u  nn[-        U5         [/        UUR                  SS
9u  nn[/        UU4UR                  5      u  nn[1        UUUUU5      nSSS5        Wc  gUu  nnnUUR                  U-  -  nGO+US:X  aC  [-        U5         [/        UUR                  5      u  nn[3        UUUSS9nSSS5        Wc  gUu  nnOUS:X  a  UR4                  (       a"  U R!                  5       UR!                  5       :  a  g[6        R8                  [;        [<        U V
V	s/ s H  u  pU	R?                  5       S   PM     sn	n
S5      -  n[A        U V	Vs/ s H  u  p[C        XU-  5      PM     snn	6 nUU4$ US:X  a  [E        S5      eUS;   a  [G        SU-  5      e[G        SU-  5      e[6        R8                  [;        [<        U V
Vs/ s H  u  pUPM	     snn
 V	s/ s H  oR?                  5       S   PM     sn	U/-   S5      -  nU V	Vs/ s H  u  pXU-  4PM     nn	nUU-  nUUU-  :w  a  [G        S5      e[        UU-  [A        U V	Vs/ s H  u  p[C        X5      PM     snn	6 -  5      nUU4$ s  sn
n	f s  sn	nf ! , (       d  f       GN,= f! , (       d  f       GN= fs  sn	n
f s  snn	f s  snn
f s  sn	f s  snn	f s  snn	f )az  
Checks if f can be written as the logarithmic derivative of a k(t)-radical.

Explanation
===========

It differs from is_log_deriv_k_t_radical(fa, fd, DE, Df=False)
for any given fa, fd, DE in that it finds the solution in the
given field not in some (possibly unspecified extension) and
"in_field" with the function name is used to indicate that.

f in k(t) can be written as the logarithmic derivative of a k(t) radical if
there exist n in ZZ and u in k(t) with n, u != 0 such that n*f == Du/u.
Either returns (n, u) or None, which means that f cannot be written as the
logarithmic derivative of a k(t)-radical.

case is one of {'primitive', 'exp', 'tan', 'auto'} for the primitive,
hyperexponential, and hypertangent cases, respectively.  If case is 'auto',
it will attempt to determine the type of the derivation automatically.

See also
========
is_log_deriv_k_t_radical, is_deriv_k

Tr(   r   )r   Nc              3      #    U  H<  u  p[        U5      UR                  5       :H  =(       a    [        S  U 5       5      v   M>     g7f)c              3   8   #    U  H  oR                   v   M     g 7fr   rm  )rK   ks     r#   rM   >is_log_deriv_k_t_radical_in_field.<locals>.<genexpr>.<genexpr>  s     +E1aMM1r   N)r   r   r   )rK   r!   r"   s      r#   rM   4is_log_deriv_k_t_radical_in_field.<locals>.<genexpr>  s;      tq 1v#E+E1+E(EEs   AAr'   rf   rg   )r   ri   )ro   rj   rh   zTThe hypertangent case is not yet implemented for is_log_deriv_k_t_radical_in_field())other_linearother_nonlinearz.The %s case is not supported in this function.zGcase must be one of {'primitive', 'exp', 'tan', 'base', 'auto'}, not %szInexact division)$r   r   is_oner   r   
real_rootsr   r*   r+   r   r   subsr   r   rU   r,   r   ru   rr   ro   r   r   r   r   rt   rO  is_sqfr	   r  r   r   rA  r   r   r  rp   )r0   r1   r3   ro   r   ry   r   r   r   r!   r   rootsrespolysresiduesr"   residuetermsr;   rP  rQ  papdrA   r/  r   common_denomr   s                             r#   rO  rO    sk   4 YYr4Y(FB rDA88	U3ZA""*DA -./QTQa QE/     c5k*6r2hH 6;3q6] ][ T!W\\!'+ ,]L 
 	rzz|BJJL(+DQA+NNOA			"$$Ayxx~QBDD 122v~wwu}BDD"%,,T"$$-=t,LBBQT2FBb"Xrtt,FB$RRR8A   91a	RTT1W		BQ%FB1"b"6JA   91	yyBIIK299;6  EE&,O,$! 0 0 21 5,OQRSS,7,$!#a1+,781v	! #F G 	G 
4	4IDPQQ  "$() * 	* 55G NRQqG ' G'7'7'9!'< G ''! !L4@ALDAQ,'LLAaAqs+,,q!tC=#a)=>>?A!e 0(       P7G 'A >sI   Q$.Q*AQ0&RRR
:R R&=R+>R10
Q?
R)rf   r   )T)rf   N)9__doc__r   	functoolsr   sympy.core.intfuncr   
sympy.corer   r   r   r   r	   sympy.integrals.rder
   r   r   r   sympy.integrals.rischr   r   r   r   r   r   r   r   sympy.polysr   r   r   r   sympy.polys.polymatrixr   r   sympy.solversr   r   r   rC   rd   r   r   r   r   r   r   r   r  r  r   r<  rK  r_  rt   r  r  rO  rI   r&   r#   <module>r     s       # . .    4 3 7 jj>8NbB&CL2!Ha,H-`FRE;P/?d>Xv	w(tx+v}r&   