+
    i{                     T    R t ^ RIHtHtHt ^ RIHtHtHt ^ RI	H
t
 RR ltR tR tR# )	z1Gosper's algorithm for hypergeometric summation. )SDummysymbols)Polyparallel_poly_from_exprfactor)is_sequencec                   \        W3VRRR7      w  w  rEpVP                  4       VP                  4       rVP                  4       VP                  4       rVP                  Wy,          r\	        R4      p\        W-,           W-VP                  R7      pVP                  V
P                  V4      4      pVP                  4       P                  4        Uu0 uF"  pVP                  '       g   K  V^ 8  g   K   VkK$  	  pp\        V4       F  pVP                  V
P                  V54      4      pVP                  V4      pV
P                  VP                  V) 4      4      p
\!        ^V^,           4       F  pVVP                  V) 4      ,          pK  	  K  	  VP#                  V4      pV'       g1   VP%                  4       pV
P%                  4       p
VP%                  4       pWV3# u upi )a  
Compute the Gosper's normal form of ``f`` and ``g``.

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

Given relatively prime univariate polynomials ``f`` and ``g``,
rewrite their quotient to a normal form defined as follows:

.. math::
    \frac{f(n)}{g(n)} = Z \cdot \frac{A(n) C(n+1)}{B(n) C(n)}

where ``Z`` is an arbitrary constant and ``A``, ``B``, ``C`` are
monic polynomials in ``n`` with the following properties:

1. `\gcd(A(n), B(n+h)) = 1 \forall h \in \mathbb{N}`
2. `\gcd(B(n), C(n+1)) = 1`
3. `\gcd(A(n), C(n)) = 1`

This normal form, or rational factorization in other words, is a
crucial step in Gosper's algorithm and in solving of difference
equations. It can be also used to decide if two hypergeometric
terms are similar or not.

This procedure will return a tuple containing elements of this
factorization in the form ``(Z*A, B, C)``.

Examples
========

>>> from sympy.concrete.gosper import gosper_normal
>>> from sympy.abc import n

>>> gosper_normal(4*n+5, 2*(4*n+1)*(2*n+3), n, polys=False)
(1/4, n + 3/2, n + 1/4)

T)field	extensionhdomain)r   LCmoniconer   r   r   	resultantcomposeground_rootskeys
is_Integersortedgcdshiftquorange
mul_groundas_expr)fgnpolyspqoptaAbBCZr   DRrrootsidjs   &&&&                 S/var/www/html/photoedit/myenv/lib/python3.14/site-packages/sympy/concrete/gosper.pygosper_normalr3      ss   L *	
/KFQC 4461779q4461779q55!#qc
AQUA,A	AIIaL!A(--/K/11<<QAFQQ/EKE]EE!''1"+EE!HEE!''1"+q!a%A!A !  	
QAIIKIIKIIK7N# Ls   G)G2Gc                   ^ RI Hp V! W4      pVf   R# VP                  4       w  rE\        WEV4      w  rgpVP	                  R4      p\        VP                  4       4      p	\        VP                  4       4      p
\        VP                  4       4      pW8w  g$   VP                  4       VP                  4       8w  d   V\        W4      ,
          0pMV	'       g!   W,
          ^,           \
        P                  0pMYW,
          ^,           VP                  V	^,
          4      VP                  V	^,
          4      ,
          VP                  4       ,          0p\        V4       F/  pVP                  '       d
   V^ 8  g   K  VP                  V4       K1  	  V'       g   R# \        V4      p\        RV^,           ,          \        R7      pVP!                  4       P"                  ! V!  p\%        WVR7      pVVP	                  ^4      ,          VV,          ,
          V,
          p^ RIHp V! VP+                  4       V4      pVf   R# VP-                  4       P/                  V4      pV F  pVV9  g   K  VP/                  V^ 4      pK   	  VP0                  '       d   R# VP-                  4       V,          VP-                  4       ,          # )a  
Compute Gosper's hypergeometric term for ``f``.

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

Suppose ``f`` is a hypergeometric term such that:

.. math::
    s_n = \sum_{k=0}^{n-1} f_k

and `f_k` does not depend on `n`. Returns a hypergeometric
term `g_n` such that `g_{n+1} - g_n = f_n`.

Examples
========

>>> from sympy.concrete.gosper import gosper_term
>>> from sympy import factorial
>>> from sympy.abc import n

>>> gosper_term((4*n + 1)*factorial(n)/factorial(2*n + 1), n)
(-n - 1/2)/(n + 1/4)

)	hypersimpNzc:%s)clsr   )solve)sympy.simplifyr5   as_numer_denomr3   r   r   degreer   maxZeronthsetr   remover   r   
get_domaininjectr   sympy.solvers.solversr7   coeffsr   subsis_zero)r   r    r5   r-   r"   r#   r&   r(   r)   NMKr+   r0   rD   r   xHr7   solutioncoeffs   &&                   r2   gosper_termrN   N   s   4 )!AyDAA!$GA!	A	!((*A	!((*A	!((*A	ADDFaddf$Q]OUQYUQYq1ua!e4addf<=V|||q1uHHQK  AAVq1u%51F\\^""F+FVv&A	!''!*qsQA+QXXZ(H			"A ua A  	yyyyy{1}QYY[((    c                   Rp\        V4      '       d   Vw  rpMRp\        W4      pVf   R# V'       d
   W,          pMW^,           ,          P                  VX4      W,          P                  VX4      ,
          pV\        P                  J d<    W^,           ,          P                  W4      W,          P                  W4      ,
          p\        V4      #   \         d    Rp Li ; i)a  
Gosper's hypergeometric summation algorithm.

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

Given a hypergeometric term ``f`` such that:

.. math ::
    s_n = \sum_{k=0}^{n-1} f_k

and `f(n)` does not depend on `n`, returns `g_{n} - g(0)` where
`g_{n+1} - g_n = f_n`, or ``None`` if `s_n` cannot be expressed
in closed form as a sum of hypergeometric terms.

Examples
========

>>> from sympy.concrete.gosper import gosper_sum
>>> from sympy import factorial
>>> from sympy.abc import n, k

>>> f = (4*k + 1)*factorial(k)/factorial(2*k + 1)
>>> gosper_sum(f, (k, 0, n))
(-factorial(n) + 2*factorial(2*n + 1))/factorial(2*n + 1)
>>> _.subs(n, 2) == sum(f.subs(k, i) for i in [0, 1, 2])
True
>>> gosper_sum(f, (k, 3, n))
(-60*factorial(n) + factorial(2*n + 1))/(60*factorial(2*n + 1))
>>> _.subs(n, 5) == sum(f.subs(k, i) for i in [3, 4, 5])
True

References
==========

.. [1] Marko Petkovsek, Herbert S. Wilf, Doron Zeilberger, A = B,
       AK Peters, Ltd., Wellesley, MA, USA, 1997, pp. 73--100

FTN)r   rN   rE   r   NaNlimitNotImplementedErrorr   )r   k
indefiniter%   r'   r   results   &&     r2   
gosper_sumrW      s    P J1~~a
AAyU)!!!Q'13**Q*::QUU?U)**10AC;;q3DD &> ' s   :C C$#C$N)T)__doc__
sympy.corer   r   r   sympy.polysr   r   r   sympy.utilities.iterablesr   r3   rN   rW    rO   r2   <module>r]      s*    7 ( ( = = 1CLN)b?rO   