Ë
    7^(hk  ã                   óì   — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZmZmZ ddlmZmZ ddlmZ dd	lmZmZmZmZmZmZmZ d
„ Zd„ Zdd„Zd„ Zdd„Zdd„Z d„ Z!d„ Z"d„ Z#d„ Z$d„ Z%d„ Z&dd„Z'd„ Z(y)aô  
Algorithms for solving the Risch differential equation.

Given a differential field K of characteristic 0 that is a simple
monomial extension of a base field k and f, g in K, the Risch
Differential Equation problem is to decide if there exist y in K such
that Dy + f*y == g and to find one if there are some.  If t is a
monomial over k and the coefficients of f and g are in k(t), then y is
in k(t), and the outline of the algorithm here is given as:

1. Compute the normal part n of the denominator of y.  The problem is
then reduced to finding y' in k<t>, where y == y'/n.
2. Compute the special part s of the denominator of y.   The problem is
then reduced to finding y'' in k[t], where y == y''/(n*s)
3. Bound the degree of y''.
4. Reduce the equation Dy + f*y == g to a similar equation with f, g in
k[t].
5. Find the solutions in k[t] of bounded degree of the reduced equation.

See Chapter 6 of "Symbolic Integration I: Transcendental Functions" by
Manuel Bronstein.  See also the docstring of risch.py.
é    )Úmul)Úreduce)Úoo)ÚDummy)ÚPolyÚgcdÚZZÚcancel)ÚimÚre)Úsqrt)Úgcdex_diophantineÚfrac_inÚ
derivationÚsplitfactorÚNonElementaryIntegralExceptionÚDecrementLevelÚrecognize_log_derivativec                 ó"  — | j                   rt        S |t        ||«      k(  r%| j                  |«      j	                  «       d   d   S g }|}| j                  |«      }d}|j                   r;|j                  ||f«       ||z  }|dz  }| j                  |«      }|j                   rŒ;d}t        d|«      }t        |«      dk7  rN|j                  «       }	||	d   z  }
| j                  |
«      }|j                   r
||	d   z  }|
}t        |«      dk7  rŒN|S )aY  
    Computes the order of a at p, with respect to t.

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

    For a, p in k[t], the order of a at p is defined as nu_p(a) = max({n
    in Z+ such that p**n|a}), where a != 0.  If a == 0, nu_p(a) = +oo.

    To compute the order at a rational function, a/b, use the fact that
    nu_p(a/b) == nu_p(a) - nu_p(b).
    r   é   é   )	Úis_zeror   r   Úas_polyÚETÚremÚappendÚlenÚpop)ÚaÚpÚtÚ
power_listÚp1ÚrÚtracks_powerÚnÚproductÚfinalÚproductfs              úQ/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/integrals/rde.pyÚorder_atr+   )   s  € ð 	‡y‚yÜˆ	ØŒD��A‹J‚Ø�y‰y˜‹|�‰Ó  Ñ# AÑ&Ð&ð €JØ	
€BØ	�‰ˆb‹	€AØ€LØ
�)Š)Ø×Ñ˜2˜lÐ+Ô,Ø�‰UˆØ˜ÑˆØ�E‰E�"‹Iˆð	 �)‹)ð
 	
€AÜ�1�a‹j€GÜ
ˆj‹/˜QÒ
Ø—‘Ó ˆØ˜5 ™8Ñ#ˆØ�E‰E�(‹OˆØ�9Š9Ø��q‘‰MˆAØˆGô ˆj‹/˜QÓ
ð €Hó    c                 ól   — | j                   rt        S |j                  |«      | j                  |«      z
  S )z¤
    Computes the order of a/d at oo (infinity), with respect to t.

    For f in k(t), the order or f at oo is defined as deg(d) - deg(a), where
    f == a/d.
    )r   r   Údegree)r   Údr!   s      r*   Úorder_at_oor0   T   s+   € ð 	‡y‚yÜˆ	Ø�8‰8�A‹;˜Ÿ™ !›Ñ$Ð$r,   Nc                 ó¢  — |xs t        d«      }t        ||«      \  }}t        ||j                  |j                  «      «      }|j                  |«      }|j                  t        ||«      «      }t        |j                  |«      j                  |j                  «      |j                  |j                  «      | j                  |j                  «      «      \  }	}
| t        ||j                  «      t        ||«      z  z
  j                  |j                  «      j                  |j                  |j                  «      «      }t        ||«      }|j                  j                  |«      st        d|j                  «      | |ffS |j                  «       D �cg c]  }|t        v sŒ|dkD  sŒ|‘Œ }}t        t         |D �cg c]2  }t        | t        ||j                  «      t        ||«      z  z
  |«      ‘Œ4 c}t        d|j                  «      «      }t        ||«      }|| z  ||z  z
  }||z  }|j#                  |d¬«      \  }}|||ffS c c}w c c}w )aˆ  
    Weak normalization.

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

    Given a derivation D on k[t] and f == a/d in k(t), return q in k[t]
    such that f - Dq/q is weakly normalized with respect to t.

    f in k(t) is said to be "weakly normalized" with respect to t if
    residue_p(f) is not a positive integer for any normal irreducible p
    in k[t] such that f is in R_p (Definition 6.1.1).  If f has an
    elementary integral, this is equivalent to no logarithm of
    integral(f) whose argument depends on t has a positive integer
    coefficient, where the arguments of the logarithms not in k(t) are
    in k[t].

    Returns (q, f - Dq/q)
    Úzr   r   T©Úinclude)r   r   r   Údiffr!   Úquor   r   r   r   Ú	resultantÚexprÚhasÚ
real_rootsr	   r   r   r
   )r   r/   ÚDEr2   ÚdnÚdsÚgÚ
d_sqf_partÚd1Úa1Úbr$   ÚiÚNr&   ÚqÚdqÚsnÚsds                      r*   Úweak_normalizerrI   `   sà  € ð( 	
ŠŒU�3‹Z€AÜ˜˜BÓ�F€Bˆô 	ˆB�—‘˜Ÿ™“Ó€AØ—‘˜“€JØ	�‰œ˜J¨Ó*Ó	+€Bä˜aŸe™e B›i×/Ñ/°·±Ó5°r·z±zÀ"Ç$Á$Ó7GØ	�	‰	�"—$‘$‹ó�E€Bˆà	
ŒT�!�R—T‘T‹]œ: b¨"Ó-Ñ-Ñ	-×6Ñ6°r·t±tÓ<×FÑFØ
�
‰
�2—4‘4Óó	€AäˆQ�‹
€Aà�6‰6�:‰:�aŒ=Ü�Q˜Ÿ™“  1˜vÐ&Ð&à—L‘L“NÖ8ˆq a¬2¢g°!°a³%ŠÐ8€AÐ8äŒsÈAÖNÀq”S˜œT ! R§T¡T›]¬:°b¸"Ó+=Ñ=Ñ=¸rÕBÒNÜˆQ�—‘‹ó	€Aô 
�A�rÓ	€BØ	
ˆ1‰ˆq�‰t‰€BØ	
ˆ1‰€BØ�Y‰Y�r 4ˆYÓ(�F€Bˆà��Bˆxˆ=Ðùò 	9ùâNs   ÆIÆ"IÆ(IÆ<7I
c                 ó  — t        ||«      \  }}t        ||«      \  }}|j                  |«      }	|j                  |j                  |j                  «      «      j	                  |	j                  |	j                  |j                  «      «      «      }
||
z  }||
z  }|j                  |«      d   rt        ‚||z  }|j                  |d¬«      \  }}|| z  |t        |
|«      z  |z  z
  }|j                  |d¬«      \  }}|||f||f|
fS )a  
    Normal part of the denominator.

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

    Given a derivation D on k[t] and f, g in k(t) with f weakly
    normalized with respect to t, either raise NonElementaryIntegralException,
    in which case the equation Dy + f*y == g has no solution in k(t), or the
    quadruplet (a, b, c, h) such that a, h in k[t], b, c in k<t>, and for any
    solution y in k(t) of Dy + f*y == g, q = y*h in k<t> satisfies
    a*Dq + b*q == c.

    This constitutes step 1 in the outline given in the rde.py docstring.
    r   Tr3   )	r   r   r5   r!   r6   Údivr   r
   r   )ÚfaÚfdÚgaÚgdr;   r<   r=   ÚenÚesr    Úhr   ÚcÚcaÚcdÚbaÚbds                    r*   Únormal_denomrX   “   sÿ   € ô  ˜˜RÓ �F€BˆÜ˜˜RÓ �F€Bˆà
�‰ˆr‹
€AØ
�‰ˆr�w‰w�r—t‘t‹}Ó×!Ñ! !§%¡%¨¯©¨r¯t©t«Ó"5Ó6€Aà
ˆ1‰€AØ	ˆ!‰€AØ‡u�uˆRƒy�‚|ä,Ð,Ø	
ˆ2‰€BØ�Y‰Y�r 4ˆYÓ(�F€Bˆà	
ˆ2‰�”:˜a Ó$Ñ$ RÑ'Ñ	'€BØ�Y‰Y�r 4ˆYÓ(�F€Bˆð ��Bˆx˜"˜b˜ 1Ð%Ð%r,   c                 ó6	  — |dk(  r|j                   }|dk(  r!t        |j                  |j                  «      }n–|dk(  r't        |j                  dz  dz   |j                  «      }nj|dv rX|j                  «       j	                  |«      }|j                  «       j	                  |«      }	| ||	t        d|j                  «      fS t        d|z  «      ‚t        |||j                  «      t        |||j                  «      z
  }
t        |||j                  «      t        |||j                  «      z
  }t        d|t        d|
«      z
  «      }|
�s®dd	lm	} |dk(  rÚ|j                  j	                  t        |j                  |j                  «      «      }t        |«      5  t        |j                  d«       |j                  d«      z  | j                  d«      z  |j                  «      \  }}t        ||j                  «      \  }} ||||||«      }|�|\  }}}|dk(  rt        ||«      }d
d
d
«       �nÉ|dk(  �rÃ|j                  j	                  t        |j                  dz  dz   |j                  «      «      }t        |«      5  t        t        |j                  t        d«      «       |j                  t        d«      «      z  | j                  t        d«      «      z  «      |j                  «      \  }}t        t!        |j                  t        d«      «       |j                  t        d«      «      z  | j                  t        d«      «      z  «      |j                  «      \  }}t        ||j                  «      \  }}t#        t        d|j                  «      |z  ||«      rQ ||t        t        d«      |j                  «      z  |z  ||z  z   ||z  |||«      }|�|\  }}}|dk(  rt        ||«      }d
d
d
«       t%        d|
 ||z
  «      }||z  }|| z  }| |z  }||j	                  |«      z  t        ||j                  «      | z  t'        ||«      j	                  |«      z  |z  z   }||z  |z  j	                  |«      }	|}|||	|fS # 1 sw Y   Œ–xY w# 1 sw Y   Œ¢xY w)a  
    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, c, 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 quadruplet (A, B, C, 1/h) such that
    A, B, C, h in k[t] and for any solution q in k<t> of a*Dq + b*q == c,
    r = qh in k[t] satisfies A*Dr + B*r == C.

    For ``case == 'primitive'``, k<t> == k[t], so it returns (a, b, c, 1) in
    this case.

    This constitutes step 2 of the outline given in the rde.py docstring.
    ÚautoÚexpÚtanr   r   )Ú	primitiveÚbasez@case must be one of {'exp', 'tan', 'primitive', 'base'}, not %s.r   ©Úparametric_log_derivNéÿÿÿÿ)Úcaser   r!   Úto_fieldr6   Ú
ValueErrorr+   ÚminÚprder`   r/   r   r   Úevalr   r   r   r   Úmaxr   )r   rV   rW   rT   rU   r;   rb   r    ÚBÚCÚnbÚncr&   r`   ÚdcoeffÚalphaaÚalphadÚetaaÚetadÚAÚQÚmr2   ÚbetaaÚbetadrD   ÚpNÚpnrR   s                                r*   Úspecial_denomry   ¸   s  € ð. ˆv‚~Ø�w‰wˆàˆu‚}Ü�—‘�r—t‘tÓ‰Ø	�ŠÜ�—‘�q‘˜1‘˜bŸd™dÓ#‰Ø	Ð&Ñ	&Ø�K‰K‹M×Ñ˜bÓ!ˆØ�K‰K‹M×Ñ˜bÓ!ˆØ�1�aœ˜a §¡›Ð'Ð'äð Ø!%ñ&ó 'ð 	'ô 
�"�a˜Ÿ™Ó	¤¨"¨a°·±Ó!6Ñ	6€BÜ	�"�a˜Ÿ™Ó	¤¨"¨a°·±Ó!6Ñ	6€BäˆAˆr”C˜˜2“J‰Ó€AÚå.Ø�5Š=Ø—T‘T—X‘Xœd 2§4¡4¨¯©Ó.Ó/ˆFÜ Ó#ñ &ä!(¨"¯'©'°!«*¨°R·W±W¸Q³ZÑ)?ÀÇÁÀqÃ	Ñ)IÈ2Ï4É4Ó!P‘�˜Ü$ V¨R¯T©TÓ2‘
��dÙ(¨°¸¸tÀRÓH�Ø�=Ø‘G�A�q˜!Ø˜A’vÜ  1›I˜÷&ñ &ð �U‹]Ø—T‘T—X‘Xœd 2§4¡4¨¡7¨1¡9¨b¯d©dÓ3Ó4ˆFÜ Ó#ñ *ä!(¬¨R¯W©W´T¸"³XÓ->Ð,>¸r¿w¹wÄtÈBÃxÓ?PÑ,PÐQR×QWÑQWÔX\Ð]_ÓX`ÓQaÑ,aÓ)bÐdf×dhÑdhÓ!i‘�˜Ü&¤r¨2¯7©7´4¸³8Ó+<Ð*<¸R¿W¹WÄTÈ"ÃXÓ=NÑ*NÈqÏvÉvÔVZÐ[]ÓV^ÓO_Ñ*_Ó'`Ðbd×bfÑbfÓg‘��uÜ$ V¨R¯T©TÓ2‘
��dä+¬D°°B·D±D«M¸%Ñ,?ÀÈÔKÙ,¨V´D¼¸b»À2Ç4Á4Ó4HÑ-HÈÑ-NÈvÐV[É|Ñ-[Ð]cÐdiÑ]iÐkoÐquÐwyÓz�AØ�}Ø"#™˜˜1˜aØ š6Ü # A q£	˜A÷*ô 	ˆA�ˆs�A˜‘FÓ€AØ	
ˆA‰€BØ	
ˆQˆB‰€Bà	ˆ"‰€AØ
ˆ2�6‰6�"‹:‰œ˜Q §¡› a™¬
°1°bÓ(9×(=Ñ(=¸aÓ(@Ñ@ÀÑCÑC€AØ	ˆB‰ˆr‰�‰�rÓ€AØ
€Að ˆq�!�Qˆ<Ð÷E&ð &ú÷*ð *ús   ÆBRÉ=E1RÒRÒRc           	      ó¢	  ‡— |dk(  r‰j                   }| j                  ‰j                  «      }|j                  ‰j                  «      }|rt        ˆfd„|D «       «      }n|j                  ‰j                  «      }t	        |j                  ‰j                  «      j                  «       j                  «        | j                  ‰j                  «      j                  «       j                  «       z  «      }	|dk(  rBt        d|t        ||dz
  «      z
  «      }
||dz
  k(  r|	j                  rt        d|	||z
  «      }
|
S |dk(  �rÐ||kD  rt        d||z
  «      }
nt        d||z
  dz   «      }
t        ‰j                  ‰j                  ‰j                  dz
     «      \  }}‰j                  }t        ‰«      5  t        |	‰j                  «      \  }}||dz
  k(  rDddlm} 	  |||||fg‰«      \  \  }}}t!        |«      dk7  rt#        d«      ‚t        |
|d   «      }
nï||k(  rêdd	lm}  |||‰«      }|�Ø|\  }}|dk(  rÎ| t)        |‰«      j                  |«      z  ||j                  |«      z  z   j                  «        |j                  «       | j                  «       z  z  }t        |‰j                  «      \  }}ddlm} 	  |||||fg‰«      \  \  }}}t!        |«      dk7  rt#        d«      ‚t        |
|d   j                  «       «      }
d
d
d
«       |
S |dk(  rÚddlm} t        d|t        ||«      z
  «      }
||k(  r´t        ‰j                  j-                  t/        ‰j                  ‰j                  «      «      ‰j                  ‰j                  dz
     «      \  }}t        ‰«      5  t        |	‰j                  «      \  }} |||||‰«      }|�|\  } }}| dk(  rt        |
|«      }
d
d
d
«       |
S |
S |dv r•‰j                  j                  ‰j                  «      }‰j                  j                  «       }t	        |	|z  «      }	t        d|t        ||z   dz
  |«      z
  «      }
|||z   dz
  k(  r|	j                  rt        d|	||z
  «      }
|
S t#        d|z  «      ‚# t$        $ r Y �Œœw xY w# t$        $ r Y �Œ¬w xY w# 1 sw Y   |
S xY w# 1 sw Y   |
S xY w)am  
    Bound on polynomial solutions.

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

    Given a derivation D on k[t] and ``a``, ``b``, ``c`` in k[t] with ``a != 0``, return
    n in ZZ such that deg(q) <= n for any solution q in k[t] of
    a*Dq + b*q == c, when parametric=False, or deg(q) <= n for any solution
    c1, ..., cm in Const(k) and q in k[t] of a*Dq + b*q == Sum(ci*gi, (i, 1, m))
    when parametric=True.

    For ``parametric=False``, ``cQ`` is ``c``, a ``Poly``; for ``parametric=True``, ``cQ`` is Q ==
    [q1, ..., qm], a list of Polys.

    This constitutes step 3 of the outline given in the rde.py docstring.
    rZ   c              3   óT   •K  — | ]  }|j                  ‰j                  «      –— Œ! y ­w©N)r.   r!   )Ú.0rC   r;   s     €r*   ú	<genexpr>zbound_degree.<locals>.<genexpr>(  s   øè ø€ Ò, A�—‘˜"Ÿ$™$—Ñ,ùs   ƒ%(r^   r   r   r]   )Úlimited_integratezLength of m should be 1©Ú!is_log_deriv_k_t_radical_in_fieldNr[   r_   )r\   Úother_nonlinearzScase must be one of {'exp', 'tan', 'primitive', 'other_nonlinear', 'base'}, not %s.)rb   r.   r!   rh   r
   r   ÚLCÚas_exprÚ
is_Integerr   r/   ÚTÚlevelr   rf   r   r   rd   r   r�   r   r`   r6   r   )r   rB   ÚcQr;   rb   Ú
parametricÚdaÚdbÚdcÚalphar&   rp   rq   Út1rn   ro   r   ÚzaÚzdrt   r�   rr   Úaar2   Úbetaru   rv   r`   ÚdeltaÚlams      `                          r*   Úbound_degreer•     sž  ø€ ð( ˆv‚~Ø�w‰wˆà	
�‰�"—$‘$‹€BØ	
�‰�"—$‘$‹€Bñ ÜÓ,¨Ô,Ó,‰à�Y‰Y�r—t‘t‹_ˆä�A—I‘I˜bŸd™d“O×&Ñ&Ó(×0Ñ0Ó2Ð2Ø	�	‰	�"—$‘$‹×ÑÓ×$Ñ$Ó&ñ'ó (€Eð ˆv‚~Ü��2œ˜B  Q¡›Ñ'Ó(ˆØ��a‘Š<˜E×,Ò,Ü�A�u˜b 2™gÓ&ˆAð\ €HðY 
�Ó	Ø�Š7Ü�A�r˜B‘w“‰Aä�A�r˜B‘w ‘{Ó#ˆAä˜RŸT™T 2§4¡4¨¯©°1©Ñ#5Ó6‰
ˆˆdà�T‰TˆÜ˜BÓñ %	7Ü$ U¨B¯D©DÓ1‰NˆF�FØ�R˜!‘VŠ|Ý3ð%Ù"3°F¸FÀdÈDÀ\ÀNØó#‘K‘H�R˜˜aô
 ˜1“v ’{Ü(Ð)BÓCÐCÜ˜A˜q ™t›‘Aà�r’õ
 DÙ5°f¸fÀbÓI�Ø�=Ø‘E�B˜Ø˜Q’wØ!"¤:¨a°Ó#4×#<Ñ#<¸RÓ#@Ñ!@Ø˜aŸi™i¨›m™Oñ",ß-/©R«Tð 2Ø34·9±9³;¸q¿t¹t»vÑ3Eñ G˜ä'.¨t°R·T±TÓ':™˜˜uÝ;ð7Ù*;¸EÀ5Ø"&¨  °ó+4™K™H˜R  aô
  # 1›v¨š{Ü&0Ð1JÓ&KÐ KÜ # A q¨¡t§|¡|£~Ó 6˜A÷K%	7ðF €Hð9 
�ŠÝ.ä��2œ˜B ›Ñ#Ó$ˆØ�Š8Ü  §¡§¡¬$¨r¯t©t°R·T±TÓ*:Ó!;¸R¿T¹TÀ"Ç(Á(ÈQÁ,Ñ=OÓP‰JˆD�$Ü Ó#ñ &Ü!(¨°·±Ó!5‘�˜Ù(¨°¸¸tÀRÓH�Ø�=ð  ‘G�A�q˜!Ø˜A’vÜ  1›I˜÷&ð, €Hˆ1€Hð 
Ð+Ñ	+Ø—‘—‘˜BŸD™DÓ!ˆØ�d‰d�g‰g‹iˆÜ�u˜S‘yÓ!ˆÜ��2œ˜B ™J¨™N¨BÓ/Ñ/Ó0ˆØ��e‘˜a‘Ò E×$4Ò$4Ü�A�u˜b 2™gÓ&ˆAð €Hô ð 2Ø48ñ9ó :ð 	:øôq 6ò Úðûô0  >ò !Ú ð!ú÷A%	7ðF €Hú÷-&ð, €Húsa   Æ2(R7ÇRÇ/CR7Ê=R'Ë6R7Î%?SÒ	R$Ò R7Ò#R$Ò$R7Ò'	R4Ò0R7Ò3R4Ò4R7Ò7SÓSc                 ó  — t        d|j                  «      }t        d|j                  «      }t        d|j                  «      }	 |j                  r||d||fS |dk  du rt        ‚| j	                  |«      }|j                  |«      j                  st        ‚| j                  |«      |j                  |«      |j                  |«      }}} | j                  |j                  «      dk(  rE|j                  «       j                  | «      }|j                  «       j                  | «      }|||||fS t        || |«      \  }	}
|t        | |«      z  }|
t        |	|«      z
  }|| j                  |j                  «      z  }|||	z  z  }|| z  }�ŒC)aª  
    Rothstein's Special Polynomial Differential Equation algorithm.

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

    Given a derivation D on k[t], an integer n and ``a``,``b``,``c`` in k[t] with
    ``a != 0``, either raise NonElementaryIntegralException, in which case the
    equation a*Dq + b*q == c has no solution of degree at most ``n`` in
    k[t], or return the tuple (B, C, m, alpha, beta) such that B, C,
    alpha, beta in k[t], m in ZZ, and any solution q in k[t] of degree
    at most n of a*Dq + b*q == c must be of the form
    q == alpha*h + beta, where h in k[t], deg(h) <= m, and Dh + B*h == C.

    This constitutes step 4 of the outline given in the rde.py docstring.
    r   r   T)r   r!   r   r   r   r   r6   r.   rc   r   r   )r   rB   rS   r&   r;   Úzeror�   r’   r>   r$   r2   s              r*   Úspder˜   ƒ  s]  € ô" ��2—4‘4‹=€Dä��B—D‘D‹M€EÜ��2—4‘4‹=€Dà
Ø�9Š9Ø˜$  4¨Ð.Ð.Ø�‰E�d‰?Ü0Ð0à�E‰E�!‹HˆØ�u‰u�Q‹x×ÒÜ0Ð0à—%‘%˜“(˜AŸE™E !›H a§e¡e¨A£hˆaˆ1ˆà�8‰8�B—D‘D‹>˜QÒØ—
‘
“× Ñ  Ó#ˆAØ—
‘
“× Ñ  Ó#ˆAØ�q˜!˜U DÐ)Ð)ä   A qÓ)‰ˆˆ1Ø	ŒZ˜˜2ÓÑˆØ”
˜1˜bÓ!Ñ!ˆØ	ˆQ�X‰X�b—d‘d‹^Ñˆà�˜‘	ÑˆØ�‰
ˆñ/ r,   c                 ó2  — t        d|j                  «      }|j                  sô|j                  |j                  «      | j                  |j                  «      z
  }d|cxk  r
|k  st        ‚ t        ‚t        |j                  |j                  «      j                  «       | j                  |j                  «      j                  «       z  |j                  |z  z  |j                  d¬«      }||z   }|dz
  }|t        ||«      z
  | |z  z
  }|j                  sŒô|S )aì  
    Poly Risch Differential Equation - No cancellation: deg(b) large enough.

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

    Given a derivation D on k[t], ``n`` either an integer or +oo, and ``b``,``c``
    in k[t] with ``b != 0`` and either D == d/dt or
    deg(b) > max(0, deg(D) - 1), either raise NonElementaryIntegralException, in
    which case the equation ``Dq + b*q == c`` has no solution of degree at
    most n in k[t], or a solution q in k[t] of this equation with
    ``deg(q) < n``.
    r   F©Úexpandr   )r   r!   r   r.   r   r   rƒ   r   ©rB   rS   r&   r;   rE   rt   r    s          r*   Úno_cancel_b_larger�   ²  så   € ô 	ˆQ�—‘‹€Aà�iŠiØ�H‰H�R—T‘T‹N˜QŸX™X b§d¡d›^Ñ+ˆØ�AŒ{˜Š{Ü0Ð0ð Ü0Ð0ä�—‘˜2Ÿ4™4“×#Ñ#Ó% a§i¡i°·±£o×&8Ñ&8Ó&:Ñ:¸2¿4¹4À¹7ÑBÀBÇDÁDØôˆà�‰EˆØ�‰EˆØ”
˜1˜bÓ!Ñ! A a¡CÑ'ˆð �i‹ið €Hr,   c                 ó¾  — t        d|j                  «      }|j                  �s9|dk(  rd}nD|j                  |j                  «      |j                  j                  |j                  «      z
  dz   }d|cxk  r
|k  st
        ‚ t
        ‚|dkD  rˆt        |j                  |j                  «      j                  «       ||j                  j                  |j                  «      j                  «       z  z  |j                  |z  z  |j                  d¬«      }�n| j                  |j                  «      |j                  |j                  «      k7  rt
        ‚| j                  |j                  «      dk(  rW|| j                  |j                  |j                  dz
     «      |j                  |j                  |j                  dz
     «      fS t        |j                  |j                  «      j                  «       | j                  |j                  «      j                  «       z  |j                  d¬«      }||z   }|dz
  }|t        ||«      z
  | |z  z
  }|j                  s�Œ9|S )a˜  
    Poly Risch Differential Equation - No cancellation: deg(b) small enough.

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

    Given a derivation D on k[t], ``n`` either an integer or +oo, and ``b``,``c``
    in k[t] with deg(b) < deg(D) - 1 and either D == d/dt or
    deg(D) >= 2, either raise NonElementaryIntegralException, in which case the
    equation Dq + b*q == c has no solution of degree at most n in k[t],
    or a solution q in k[t] of this equation with deg(q) <= n, or the
    tuple (h, b0, c0) such that h in k[t], b0, c0, in k, and for any
    solution q in k[t] of degree at most n of Dq + bq == c, y == q - h
    is a solution in k of Dy + b0*y == c0.
    r   r   Frš   )r   r!   r   r.   r/   r   r   rƒ   r†   r‡   r   rœ   s          r*   Úno_cancel_b_smallrŸ   Ð  sÔ  € ô  	ˆQ�—‘‹€Aà�i‹iØ�Š6Ø‰Aà—‘˜Ÿ™“ §¡§¡¨R¯T©TÓ!2Ñ2°QÑ6ˆAà�AŒ{˜Š{Ü0Ð0ð Ü0Ð0àˆqŠ5Ü�Q—Y‘Y˜rŸt™t“_×'Ñ'Ó)¨1¨R¯T©T¯\©\¸"¿$¹$Ó-?×-BÑ-BÓ-DÑ+DÑEÀbÇdÁdÈAÁgÑMØ—‘˜Uô$ŠAð �x‰x˜Ÿ™‹~ §¡¨"¯$©$£Ò/Ü4Ð4Ø�x‰x˜Ÿ™‹~ Ò"Ø˜1Ÿ9™9 R§T¡T¨"¯(©(°Q©,Ñ%7Ó8Ø—I‘I˜bŸd™d 2§8¡8¨a¡<Ñ0Ó1ð3ð 3ä�Q—Y‘Y˜rŸt™t“_×'Ñ'Ó)¨!¯)©)°B·D±D«/×*<Ñ*<Ó*>Ñ>ÀÇÁØôˆAð �‰EˆØ�‰EˆØ”
˜1˜bÓ!Ñ! A a¡CÑ'ˆð/ �iŒið2 €Hr,   c                 óX  — t        d|j                  «      }t        | j                  |j                  «      j	                  «        |j
                  j                  |j                  «      j	                  «       z  «      }|j                  r|j                  r|}nd}|j                  �st        ||j                  |j                  «      |j
                  j                  |j                  «      z
  dz   «      }d|cxk  r
|k  st        ‚ t        ‚t        ||j
                  j                  |j                  «      j	                  «       z  | j                  |j                  «      j	                  «       z   «      }|j                  r|||fS |dkD  rSt        |j                  |j                  «      j	                  «       |z  |j                  |z  z  |j                  d¬«      }	n�|j                  |j                  «      |j
                  j                  |j                  «      dz
  k7  rt        ‚|j                  |j                  «      j	                  «       | j                  |j                  «      j	                  «       z  }	||	z   }|dz
  }|t        |	|«      z
  | |	z  z
  }|j                  s�Œ|S )a™  
    Poly Risch Differential Equation - No cancellation: deg(b) == deg(D) - 1

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

    Given a derivation D on k[t] with deg(D) >= 2, n either an integer
    or +oo, and b, c in k[t] with deg(b) == deg(D) - 1, either raise
    NonElementaryIntegralException, in which case the equation Dq + b*q == c has
    no solution of degree at most n in k[t], or a solution q in k[t] of
    this equation with deg(q) <= n, or the tuple (h, m, C) such that h
    in k[t], m in ZZ, and C in k[t], and for any solution q in k[t] of
    degree at most n of Dq + b*q == c, y == q - h is a solution in k[t]
    of degree at most m of Dy + b*y == C.
    r   ra   r   Frš   )r   r!   r
   r   rƒ   r/   r…   Úis_positiver   rh   r.   r   r   )
rB   rS   r&   r;   rE   ÚlcÚMrt   Úur    s
             r*   Úno_cancel_equalr¥   ÿ  s÷  € ô  	ˆQ�—‘‹€AÜ	�—‘˜2Ÿ4™4“×#Ñ#Ó%Ð% b§d¡d§l¡l°2·4±4Ó&8×&;Ñ&;Ó&=Ñ=Ó	>€BØ	‡}‚}˜ŸšØ‰àˆà�i‹iÜ��1—8‘8˜BŸD™D“> B§D¡D§K¡K°·±Ó$5Ñ5¸Ñ9Ó:ˆà�AŒ{˜Š{Ü0Ð0ð Ü0Ð0ä�1�R—T‘T—\‘\ "§$¡$Ó'×*Ñ*Ó,Ñ,¨q¯y©y¸¿¹«×/AÑ/AÓ/CÑCÓDˆØ�9Š9Ø�q˜!�9ÐØˆqŠ5Ü�Q—Y‘Y˜rŸt™t“_×'Ñ'Ó)¨!Ñ+¨B¯D©D°!©GÑ3°R·T±TÀ%ÔH‰Aà�x‰x˜Ÿ™‹~ §¡§¡¨R¯T©TÓ!2°QÑ!6Ò6Ü4Ð4à—I‘I˜bŸd™d“O×&Ñ&Ó(¨¯©°2·4±4«×);Ñ);Ó)=Ñ=�à�‰EˆØ�‰EˆØ”
˜1˜bÓ!Ñ! A a¡CÑ'ˆð' �iŒið* €Hr,   c                 óT  — ddl m} t        |«      5  t        | |j                  «      \  }} ||||«      }|�|\  }}|dk(  rt        d«      ‚ddd«       |j                  r|S ||j                  |j                  «      k  rt        ‚t        d|j                  «      }	|j                  sæ|j                  |j                  «      }
||
k  rt        ‚t        |«      5  t        |j                  «       |j                  «      \  }}t        |||«      \  }}ddd«       t        j                  «       j                  «       z  |j                  |
z  z  |j                  d¬«      }|	|z  }	|
dz
  }|| |z  t        ||«      z   z  }|j                  sŒæ|	S # 1 sw Y   �ŒFxY w# 1 sw Y   Œ‹xY w)a³  
    Poly Risch Differential Equation - Cancellation: Primitive case.

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

    Given a derivation D on k[t], n either an integer or +oo, ``b`` in k, and
    ``c`` in k[t] with Dt in k and ``b != 0``, either raise
    NonElementaryIntegralException, in which case the equation Dq + b*q == c
    has no solution of degree at most n in k[t], or a solution q in k[t] of
    this equation with deg(q) <= n.
    r   r€   Nz7is_deriv_in_field() is required to  solve this problem.r   Frš   )rf   r�   r   r   r!   ÚNotImplementedErrorr   r.   r   r   rƒ   ÚrischDEr„   r   )rB   rS   r&   r;   r�   rV   rW   rr   r2   rE   rt   Úa2aÚa2dÚsarH   Ústms                   r*   Úcancel_primitiver­   .  s…  € õ 8Ü	˜Ó	ñ ,Ü˜˜BŸD™DÓ!‰ˆˆBÙ-¨b°"°bÓ9ˆØˆ=Ø‰DˆAˆqØ�AŠvÜ)ð ++ó ,ð ,÷,ð 	‡y‚yØˆàˆ1�8‰8�B—D‘D‹>ÒÜ,Ð,äˆQ�—‘‹€AØ�iŠiØ�H‰H�R—T‘T‹NˆØˆqŠ5Ü0Ð0Ü˜BÓñ 	3Ü˜qŸt™t›v r§t¡tÓ,‰HˆC�Ü˜R  S¨#¨rÓ2‰FˆB�÷	3ô �2—:‘:“< §
¡
£Ñ,¨R¯T©T°1©WÑ4°b·d±dÀ5ÔIˆØ	ˆS‰ˆØ�‰EˆØ	ˆQˆs‰U”Z  RÓ(Ñ(Ñ(ˆð �i‹ið €H÷A,ñ ,ú÷0	3ð 	3ús   ’;FÃ:FÆFÆF'c                 ó¾  — ddl m} |j                  j                  t	        |j
                  |j
                  «      «      j                  «       }t        |«      5  t        ||j
                  «      \  }}t        | |j
                  «      \  }}	 |||	|||«      }
|
�|
\  }}}|dk(  rt        d«      ‚ddd«       |j                  r|S ||j                  |j
                  «      k  rt        ‚t	        d|j
                  «      }|j                  �s7|j                  |j
                  «      }||k  rt        ‚| j                  «       }t        |«      5  t        ||j
                  «      \  }}|z  |z  t	        ||j
                  «      z  z   }||z  }t        |j                  «       |j
                  «      \  }}t        |||||«      \  }}ddd«       t	        j                  «       j                  «       z  |j
                  |z  z  |j
                  d¬«      }||z  }|dz
  }|| |z  t        ||«      z   z  }|j                  s�Œ7|S # 1 sw Y   �Œ˜xY w# 1 sw Y   ŒŒxY w)a¼  
    Poly Risch Differential Equation - Cancellation: Hyperexponential case.

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

    Given a derivation D on k[t], n either an integer or +oo, ``b`` in k, and
    ``c`` in k[t] with Dt/t in k and ``b != 0``, either raise
    NonElementaryIntegralException, in which case the equation Dq + b*q == c
    has no solution of degree at most n in k[t], or a solution q in k[t] of
    this equation with deg(q) <= n.
    r   r_   Nz6is_deriv_in_field() is required to solve this problem.r   Frš   )rf   r`   r/   r6   r   r!   r„   r   r   r§   r   r.   r   rƒ   r¨   r   )rB   rS   r&   r;   r`   Úetarp   rq   rV   rW   rr   r   rt   r2   rE   rA   Úa1aÚa1dr©   rª   r«   rH   r¬   s                          r*   Ú
cancel_expr²   `  s  € õ +Ø
�$‰$�(‰(”4˜Ÿ™˜bŸd™dÓ#Ó
$×
,Ñ
,Ó
.€Cä	˜Ó	ñ +Ü˜S "§$¡$Ó'‰
ˆˆdÜ˜˜BŸD™DÓ!‰ˆˆBÙ   R¨¨t°RÓ8ˆØˆ=Ø‰GˆAˆq�!Ø�AŠvÜ)ð +*ó +ð +÷+ð 	‡y‚yØˆàˆ1�8‰8�B—D‘D‹>ÒÜ,Ð,äˆQ�—‘‹€AØ�i‹iØ�H‰H�R—T‘T‹NˆØˆqŠ5Ü0Ð0à�Y‰Y‹[ˆÜ˜BÓñ 	5ä˜r 2§4¡4Ó(‰HˆC�Ø�d‘(˜T #™X¤d¨1¨b¯d©d£mÑ3Ñ3ˆCØ�d‘(ˆCä˜qŸt™t›v r§t¡tÓ,‰HˆC�ä˜S # s¨C°Ó4‰FˆB�÷	5ô �2—:‘:“< §
¡
£Ñ,¨R¯T©T°1©WÑ4°b·d±dÀ5ÔIˆØ	ˆS‰ˆØ�‰EˆØ	ˆQˆs‰U”Z  RÓ(Ñ(Ñ(ˆð% �iŒið& €H÷S+ñ +ú÷8	5ð 	5ús   ÁAIÅA:IÉIÉIc                 ó‚  — | j                   s~|j                  dk(  sN| j                  |j                  «      t	        d|j
                  j                  |j                  «      dz
  «      kD  r!|rddlm}  || |||«      S t        | |||«      S | j                   sE| j                  |j                  «      |j
                  j                  |j                  «      dz
  k  �r |j                  dk(  s(|j
                  j                  |j                  «      dk\  rÉ|rddlm	}  || |||«      S t        | |||«      }t        |t        «      r|S |\  }}	}
t        |«      5  |	j                  |j                  «      |
j                  |j                  «      }
}	|	€t        d«      ‚|
€t        d	«      ‚t!        |	|
||«      j                  |j                  «      }ddd«       ||z   S |j
                  j                  |j                  «      dk\  �r)| j                  |j                  «      |j
                  j                  |j                  «      dz
  k(  rå|| j                  |j                  «      j#                  «        |j
                  j                  |j                  «      j#                  «       z  kD  r„| j                  |j                  «      j#                  «       j$                  st'        d
«      ‚|rt)        d«      ‚t+        | |||«      }t        |t        «      r|S |\  }}}t!        | |||«      }||z   S | j                   rt)        d«      ‚|j                  dk(  r|rt)        d«      ‚t-        | |||«      S |j                  dk(  r|rt)        d«      ‚t/        | |||«      S t)        d|j                  z  «      ‚# 1 sw Y   |z   S xY w)a  
    Solve a Polynomial Risch Differential Equation with degree bound ``n``.

    This constitutes step 4 of the outline given in the rde.py docstring.

    For parametric=False, cQ is c, a Poly; for parametric=True, cQ is Q ==
    [q1, ..., qm], a list of Polys.
    r^   r   r   )Úprde_no_cancel_b_larger   )Úprde_no_cancel_b_smallNzb0 should be a non-Null valuezc0 should be a non-Null valuezResult should be a numberz0prde_no_cancel_b_equal() is not yet implemented.zWRemaining cases for Poly (P)RDE are not yet implemented (is_deriv_in_field() required).r[   zIParametric RDE cancellation hyperexponential case is not yet implemented.r]   zBParametric RDE cancellation primitive case is not yet implemented.zBOther Poly (P)RDE cancellation cases are not yet implemented (%s).)r   rb   r.   r!   rh   r/   rf   r´   r�   rµ   rŸ   Ú
isinstancer   r   r   rd   Úsolve_poly_rderƒ   Ú	is_numberÚ	TypeErrorr§   r¥   r²   r­   )rB   rˆ   r&   r;   r‰   r´   rµ   ÚRrR   Úb0Úc0Úyrt   rj   s                 r*   r·   r·   œ  sP  € ð �9Š9˜"Ÿ'™' VÒ+Ø�H‰H�R—T‘T‹NœS  B§D¡D§K¡K°·±Ó$5¸Ñ$9Ó:Ò:áå4Ù)¨!¨R°°BÓ7Ð7Ü   B¨¨2Ó.Ð.à
�)Š)�q—x‘x §¡“~¨¯©¯©°B·D±DÓ(9¸AÑ(=Ó=Ø�W‰W˜Ò "§$¡$§+¡+¨b¯d©dÓ"3°qÒ"8áÝ4Ù)¨!¨R°°BÓ7Ð7ä˜a  Q¨Ó+ˆä�aœÔØˆHð ‰IˆAˆr�2Ü Ó#ñ @ØŸ™ B§D¡DÓ)¨2¯:©:°b·d±dÓ+;�B�Ø�:Ü$Ð%DÓEÐEØ�;Ü$Ð%DÓEÐEÜ" 2 r¨1¨bÓ1×9Ñ9¸"¿$¹$Ó?�÷@ð �q‘5ˆLà	�‰�‰�R—T‘TÓ	˜aÓ	 A§H¡H¨R¯T©T£N°b·d±d·k±kÀ"Ç$Á$Ó6GÈ!Ñ6KÒ$KØ�—‘˜2Ÿ4™4“×#Ñ#Ó%Ð% b§d¡d§l¡l°2·4±4Ó&8×&;Ñ&;Ó&=Ñ=Ò=ð �y‰y˜Ÿ™‹×!Ñ!Ó#×-Ò-ÜÐ7Ó8Ð8áÜ%ð 'ó  ð  ô ˜A˜r 1 bÓ)ˆä�aœÔØˆHà‰GˆAˆq�!ä˜q ! Q¨Ó+ˆAØ�q‘5ˆLð �9Š9Ü%ð 'Bó Cð Cð �w‰w˜%ÒÙÜ-ð /Hó Ið Iä! ! R¨¨BÓ/Ð/à—‘˜KÒ'ÙÜ-ð /Aó Bð Bä'¨¨2¨q°"Ó5Ð5ô *ð +:Ø<>¿G¹Gñ+Dó Eð E÷e@ð �q‘5ˆLús   ÅA8N1Î1N>c                 óL  — t        | ||«      \  }\  } }t        | ||||«      \  }\  }}\  }	}
}t        ||||	|
|«      \  }}}}	 t        ||||«      }t        |||||«      \  }}}}}|j                  r|}nt        ||||«      }||z  |z   ||z  fS # t        $ r	 t
        }Y ŒPw xY w)a  
    Solve a Risch Differential Equation: Dy + f*y == g.

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

    See the outline in the docstring of rde.py for more information
    about the procedure used.  Either raise NonElementaryIntegralException, in
    which case there is no solution y in the given differential field,
    or return y in k(t) satisfying Dy + f*y == g, or raise
    NotImplementedError, in which case, the algorithms necessary to
    solve the given Risch Differential Equation have not yet been
    implemented.
    )	rI   rX   ry   r•   r§   r   r˜   r   r·   )rL   rM   rN   rO   r;   Ú_r   rV   rW   rT   rU   Úhnrr   ri   rj   Úhsr&   rt   r�   r’   r½   s                        r*   r¨   r¨   ù  sÚ   € ô " " b¨"Ó-�K€A�xˆˆBÜ ,¨R°°R¸¸RÓ @Ñ€A�xˆˆB‘�"�b˜2Ü  2 r¨2¨r°2Ó6�K€A€qˆ!ˆRðô ˜˜A˜q "Ó%ˆô    1 a¨¨BÓ/Ñ€A€qˆ!ˆU�DØ‡y‚yØ‰ä˜1˜a  BÓ'ˆà�!‰G�d‰N˜B˜r™EÐ"Ð"øô ò ô
 Šðús   ÁB ÂB#Â"B#r|   )rZ   )rZ   F)F))Ú__doc__Úoperatorr   Ú	functoolsr   Ú
sympy.corer   Úsympy.core.symbolr   Úsympy.polysr   r   r	   r
   Ú$sympy.functions.elementary.complexesr   r   Ú(sympy.functions.elementary.miscellaneousr   Úsympy.integrals.rischr   r   r   r   r   r   r   r+   r0   rI   rX   ry   r•   r˜   r�   rŸ   r¥   r­   r²   r·   r¨   © r,   r*   ú<module>rÌ      sŠ   ðñõ. Ý å Ý #ç -Ó -ç 9Ý 9÷[÷ [ñ [ò(òV	%ó0òf"&óJQóhtòn-ò^ò<+ò^,ò^/òd9óxZóz'#r,   