Ë
    7^(h‰(  ã                   ó„   — d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 d„ Z
 G d„ d«      Zd	„ Z G d
„ d«      Z G d„ d«      Zy)zRecurrence Operatorsé    )ÚS)ÚSymbolÚsymbols)Ússtr)Úsympifyc                 ó6   — t        | |«      }||j                  fS )a+  
    Returns an Algebra of Recurrence Operators and the operator for
    shifting i.e. the `Sn` operator.
    The first argument needs to be the base polynomial ring for the algebra
    and the second argument must be a generator which can be either a
    noncommutative Symbol or a string.

    Examples
    ========

    >>> from sympy import ZZ
    >>> from sympy import symbols
    >>> from sympy.holonomic.recurrence import RecurrenceOperators
    >>> n = symbols('n', integer=True)
    >>> R, Sn = RecurrenceOperators(ZZ.old_poly_ring(n), 'Sn')
    )ÚRecurrenceOperatorAlgebraÚshift_operator)ÚbaseÚ	generatorÚrings      úX/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/holonomic/recurrence.pyÚRecurrenceOperatorsr   	   s!   € ô$ % T¨9Ó5€DØ�$×%Ñ%Ð&Ð&ó    c                   ó&   — e Zd ZdZd„ Zd„ ZeZd„ Zy)r	   aÞ  
    A Recurrence Operator Algebra is a set of noncommutative polynomials
    in intermediate `Sn` and coefficients in a base ring A. It follows the
    commutation rule:
    Sn * a(n) = a(n + 1) * Sn

    This class represents a Recurrence Operator Algebra and serves as the parent ring
    for Recurrence Operators.

    Examples
    ========

    >>> from sympy import ZZ
    >>> from sympy import symbols
    >>> from sympy.holonomic.recurrence import RecurrenceOperators
    >>> n = symbols('n', integer=True)
    >>> R, Sn = RecurrenceOperators(ZZ.old_poly_ring(n), 'Sn')
    >>> R
    Univariate Recurrence Operator Algebra in intermediate Sn over the base ring
    ZZ[n]

    See Also
    ========

    RecurrenceOperator
    c                 ó   — || _         t        |j                  |j                  g| «      | _        |€t        dd¬«      | _        y t        |t        «      rt        |d¬«      | _        y t        |t        «      r|| _        y y )NÚSnF)Úcommutative)
r   ÚRecurrenceOperatorÚzeroÚoner
   r   Ú
gen_symbolÚ
isinstanceÚstrr   )Úselfr   r   s      r   Ú__init__z"RecurrenceOperatorAlgebra.__init__;   sl   € àˆŒ	ä0Ø�Y‰Y˜Ÿ™Ð! 4ó)ˆÔð ÐÜ% d¸Ô>ˆD�Oä˜)¤SÔ)Ü")¨)ÀÔ"G�•Ü˜I¤vÔ.Ø"+�•ð /r   c                 ór   — dt        | j                  «      z   dz   | j                  j                  «       z   }|S )Nz7Univariate Recurrence Operator Algebra in intermediate z over the base ring )r   r   r   Ú__str__)r   Ústrings     r   r   z!RecurrenceOperatorAlgebra.__str__J   s<   € ØJÜ�4—?‘?Ó#ñ$Ø&<ñ=à�Y‰Y×ÑÓ!ñ"ˆð ˆr   c                 ój   — | j                   |j                   k(  r| j                  |j                  k(  ryy)NTF)r   r   ©r   Úothers     r   Ú__eq__z RecurrenceOperatorAlgebra.__eq__S   s)   € Ø�9‰9˜Ÿ
™
Ò" t§¡¸%×:JÑ:JÒ'JØàr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__repr__r#   © r   r   r	   r	      s   „ ñò6,òð €Hór   r	   c                 ó  — t        | «      t        |«      k  r3t        | |«      D ��cg c]
  \  }}||z   ‘Œ c}}|t        | «      d  z   }|S t        | |«      D ��cg c]
  \  }}||z   ‘Œ c}}| t        |«      d  z   }|S c c}}w c c}}w ©N)ÚlenÚzip)Úlist1Úlist2ÚaÚbÚsols        r   Ú
_add_listsr3   Z   s†   € Ü
ˆ5ƒz”S˜“ZÒÜ!$ U¨EÓ!2×3™˜˜Aˆq�1‹uÓ3°e¼CÀ»J¸KÐ6HÑHˆð €Jô "% U¨EÓ!2×3™˜˜Aˆq�1‹uÓ3°e¼CÀ»J¸KÐ6HÑHˆØ€Jùó 4ùã3s   §A>ÁBc                   óR   — e Zd ZdZdZd„ Zd„ Zd„ Zd„ ZeZ	d„ Z
d„ Zd	„ Zd
„ ZeZd„ Zy)r   aƒ  
    The Recurrence Operators are defined by a list of polynomials
    in the base ring and the parent ring of the Operator.

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

    Takes a list of polynomials for each power of Sn and the
    parent ring which must be an instance of RecurrenceOperatorAlgebra.

    A Recurrence Operator can be created easily using
    the operator `Sn`. See examples below.

    Examples
    ========

    >>> from sympy.holonomic.recurrence import RecurrenceOperator, RecurrenceOperators
    >>> from sympy import ZZ
    >>> from sympy import symbols
    >>> n = symbols('n', integer=True)
    >>> R, Sn = RecurrenceOperators(ZZ.old_poly_ring(n),'Sn')

    >>> RecurrenceOperator([0, 1, n**2], R)
    (1)Sn + (n**2)Sn**2

    >>> Sn*n
    (n + 1)Sn

    >>> n*Sn*n + 1 - Sn**2*n
    (1) + (n**2 + n)Sn + (-n - 2)Sn**2

    See Also
    ========

    DifferentialOperatorAlgebra
    é   c                 óÊ  — || _         t        |t        «      r¯t        |«      D ]š  \  }}t        |t        «      r2| j                   j
                  j                  t        |«      «      ||<   ŒHt        || j                   j
                  j                  «      rŒs| j                   j
                  j                  |«      ||<   Œœ || _	        t        | j                  «      dz
  | _        y )Né   )Úparentr   ÚlistÚ	enumerateÚintr   Ú
from_sympyr   ÚdtypeÚ
listofpolyr,   Úorder)r   Úlist_of_polyr8   ÚiÚjs        r   r   zRecurrenceOperator.__init__Š   s³   € ð ˆŒô �l¤DÔ)Ü! ,Ó/ò E‘��1Ü˜a¤Ô%Ø&*§k¡k×&6Ñ&6×&AÑ&AÄ!ÀAÃ$Ó&G�L ’OÜ# A t§{¡{×'7Ñ'7×'=Ñ'=Õ>Ø&*§k¡k×&6Ñ&6×&AÑ&AÀ!Ó&D�L ’Oð	Eð +ˆDŒOÜ˜Ÿ™Ó)¨AÑ-ˆ�
r   c                 ó   ‡— | j                   }| j                  j                  Št        |t        «      s^t        || j                  j                  j
                  «      s0| j                  j                  j                  t        |«      «      g}n|g}n|j                   }d„ } ||d   |«      }ˆfd„}t        dt        |«      «      D ]   } ||«      }t        | |||   |«      «      }Œ" t	        || j                  «      S )zŸ
        Multiplies two Operators and returns another
        RecurrenceOperator instance using the commutation rule
        Sn * a(n) = a(n + 1) * Sn
        c                 ó^   — t        |t        «      r|D �cg c]  }|| z  ‘Œ	 c}S | |z  gS c c}w r+   )r   r9   )r1   ÚlistofotherrA   s      r   Ú_mul_dmp_diffopz3RecurrenceOperator.__mul__.<locals>._mul_dmp_diffop¯   s3   € Ü˜+¤tÔ,Ø'2Ö3 !˜˜A›Ò3Ð3Ø˜‘OÐ$Ð$ùò 4s   •*r   c                 óæ  •— ‰j                   g}t        | t        «      ru| D ]n  }‰j                  |«      j	                  ‰j
                  d   ‰j
                  d   t        j                  z   «      }|j                  ‰j                  |«      «       Œp |S | j	                  ‰j
                  d   ‰j
                  d   t        j                  z   «      }|j                  ‰j                  |«      «       |S )Nr   )
r   r   r9   Úto_sympyÚsubsÚgensr   ÚOneÚappendr<   )r1   r2   rA   rB   r   s       €r   Ú
_mul_Sni_bz.RecurrenceOperator.__mul__.<locals>._mul_Sni_b·   s¼   ø€ Ø—9‘9�+ˆCä˜!œTÔ"Øò 3�AØŸ™ aÓ(×-Ñ-¨d¯i©i¸©l¸D¿I¹IÀa¹LÌ1Ï5É5Ñ<PÓQ�AØ—J‘J˜tŸ™¨qÓ1Õ2ð3ð ˆJð —F‘F˜4Ÿ9™9 Q™<¨¯©°1©¼¿¹Ñ)=Ó>�Ø—
‘
˜4Ÿ?™?¨1Ó-Ô.àˆJr   r7   )r>   r8   r   r   r   r=   r<   r   Úranger,   r3   )	r   r"   Ú
listofselfrE   rF   r2   rM   rA   r   s	           @r   Ú__mul__zRecurrenceOperator.__mul__›   så   ø€ ð —_‘_ˆ
Ø�{‰{×Ñˆä˜%Ô!3Ô4Ü˜e T§[¡[×%5Ñ%5×%;Ñ%;Ô<Ø#Ÿ{™{×/Ñ/×:Ñ:¼7À5»>ÓJÐK‘ð  %˜g‘à×*Ñ*ˆKò	%ñ
 ˜j¨™m¨[Ó9ˆô	ô �qœ#˜j›/Ó*ò 	OˆAá$ [Ó1ˆKä˜S¡/°*¸Q±-ÀÓ"MÓN‰Cð		Oô " # t§{¡{Ó3Ð3r   c                 óf  — t        |t        «      sœt        |t        «      rt        |«      }t        || j                  j
                  j                  «      s%| j                  j
                  j                  |«      }| j                  D �cg c]  }||z  ‘Œ	 }}t        || j                  «      S y c c}w r+   )	r   r   r;   r   r8   r   r=   r<   r>   )r   r"   rB   r2   s       r   Ú__rmul__zRecurrenceOperator.__rmul__Í   sŠ   € Ü˜%Ô!3Ô4ä˜%¤Ô%Ü˜%›�ä˜e T§[¡[×%5Ñ%5×%;Ñ%;Ô<ØŸ™×)Ñ)×5Ñ5°eÓ<�à&*§o¡oÖ6 �5˜1“9Ð6ˆCÐ6Ü% c¨4¯;©;Ó7Ð7ð 5ùò 7s   Â	B.c                 óÔ  — t        |t        «      r6t        | j                  |j                  «      }t        || j                  «      S t        |t
        «      rt        |«      }| j                  }t        || j                  j                  j                  «      s'| j                  j                  j                  |«      g}n|g}|d   |d   z   g|dd  z   }t        || j                  «      S )Nr   r7   )
r   r   r3   r>   r8   r;   r   r   r=   r<   )r   r"   r2   Ú	list_selfÚ
list_others        r   Ú__add__zRecurrenceOperator.__add__Ù   sÁ   € Ü�eÔ/Ô0ä˜TŸ_™_¨e×.>Ñ.>Ó?ˆCÜ% c¨4¯;©;Ó7Ð7ô ˜%¤Ô%Ü˜%›�ØŸ™ˆIÜ˜e T§[¡[×%5Ñ%5×%;Ñ%;Ô<Ø $§¡×1Ñ1×=Ñ=¸eÓDÐE‘
à#˜W�
Ø˜Q‘< *¨Q¡-Ñ/Ð0°9¸Q¸R°=Ñ@ˆCä% c¨4¯;©;Ó7Ð7r   c                 ó   — | d|z  z   S ©Néÿÿÿÿr)   r!   s     r   Ú__sub__zRecurrenceOperator.__sub__î   s   € Ø�r˜U‘lÑ"Ð"r   c                 ó   — d| z  |z   S rX   r)   r!   s     r   Ú__rsub__zRecurrenceOperator.__rsub__ñ   s   € Ø�d‰{˜UÑ"Ð"r   c                 óÔ  — |dk(  r| S t        | j                  j                  j                  g| j                  «      }|dk(  r|S | j                  | j                  j
                  j                  k(  r\| j                  j                  j                  g|z  | j                  j                  j                  gz   }t        || j                  «      S | }	 |dz  r||z  }|dz  }|s	 |S ||z  }Œ)Nr7   r   é   )r   r8   r   r   r>   r
   r   )r   ÚnÚresultr2   Úxs        r   Ú__pow__zRecurrenceOperator.__pow__ô   sÛ   € Ø�Š6ØˆKÜ# T§[¡[×%5Ñ%5×%9Ñ%9Ð$:¸D¿K¹KÓHˆØ�Š6ØˆMà�?‰?˜dŸk™k×8Ñ8×CÑCÒCØ—;‘;×#Ñ#×(Ñ(Ð)¨AÑ-°·±×1AÑ1A×1EÑ1EÐ0FÑFˆCÜ% c¨4¯;©;Ó7Ð7ØˆØØ�1ŠuØ˜!‘�Ø�!‰GˆAÙØàˆð �‰FˆAð r   c                 ó–  — | j                   }d}t        |«      D ]¬  \  }}|| j                  j                  j                  k(  rŒ*| j                  j                  j                  |«      }|dk(  r|dt        |«      z   dz   z  }Œi|r|dz  }|dk(  r|dt        |«      z   dz   z  }ŒŠ|dt        |«      z   dz   dz   t        |«      z   z  }Œ® |S )	NÚ r   ú(ú)z + r7   z)SnzSn**)r>   r:   r8   r   r   rH   r   )r   r>   Ú	print_strrA   rB   s        r   r   zRecurrenceOperator.__str__  sÛ   € Ø—_‘_ˆ
Øˆ	ä˜jÓ)ò 	@‰DˆAˆqØ�D—K‘K×$Ñ$×)Ñ)Ò)Øà—‘× Ñ ×)Ñ)¨!Ó,ˆAà�AŠvØ˜S¤4¨£7™]¨SÑ0Ñ0�	ØáØ˜UÑ"�	à�AŠvØ˜S¤4¨£7™]¨UÑ2Ñ2�	Øà˜œt A›w™¨Ñ,¨vÑ5¼¸Q»Ñ?Ñ?‰Ið#	@ð& Ðr   c                 óö   ‡ — t        |t        «      r4‰ j                  |j                  k(  r‰ j                  |j                  k(  ryy‰ j                  d   |k(  xr! t	        ˆ fd„‰ j                  dd  D «       «      S )NTFr   c              3   ób   •K  — | ]&  }|‰j                   j                  j                  u –— Œ( y ­wr+   )r8   r   r   )Ú.0rA   r   s     €r   ú	<genexpr>z,RecurrenceOperator.__eq__.<locals>.<genexpr>*  s&   øè ø€ ÒH¨q��T—[‘[×%Ñ%×*Ñ*Ô*ÑHùs   ƒ,/r7   )r   r   r>   r8   Úallr!   s   ` r   r#   zRecurrenceOperator.__eq__#  sk   ø€ Ü�eÔ/Ô0Ø�‰ %×"2Ñ"2Ò2°t·{±{ÀeÇlÁlÒ7RØàØ�‰˜qÑ! UÑ*ò IÜÓH°D·O±OÀAÀBÐ4GÔHÓHð	Ir   N)r$   r%   r&   r'   Ú_op_priorityr   rP   rR   rV   Ú__radd__rZ   r\   rb   r   r(   r#   r)   r   r   r   r   b   sL   „ ñ#ðJ €Lò.ò"04òd
8ò8ð& €Hò#ò#òò(ð2 €HóIr   r   c                   ó*   — e Zd ZdZg fd„Zd„ ZeZd„ Zy)ÚHolonomicSequencezõ
    A Holonomic Sequence is a type of sequence satisfying a linear homogeneous
    recurrence relation with Polynomial coefficients. Alternatively, A sequence
    is Holonomic if and only if its generating function is a Holonomic Function.
    c                 óð   — || _         t        |t        «      s	|g| _        n|| _        t	        | j                  «      dk(  rd| _        nd| _        |j                  j                  j                  d   | _	        y )Nr   FT)
Ú
recurrencer   r9   Úu0r,   Ú_have_init_condr8   r   rJ   r_   )r   rr   rs   s      r   r   zHolonomicSequence.__init__4  sa   € Ø$ˆŒÜ˜"œdÔ#Ø�dˆD�GàˆDŒGäˆt�w‰w‹<˜1ÒØ#(ˆDÕ à#'ˆDÔ Ø×"Ñ"×'Ñ'×,Ñ,¨QÑ/ˆ�r   c                 ó  — d| j                   j                  «       ›dt        | j                  «      ›d�}| j                  s|S d}d}| j
                  D ]$  }|dt        |«      ›dt        |«      ›�z  }|dz  }Œ& ||z   }|S )	NzHolonomicSequence(z, rf   rd   r   z, u(z) = r7   )rr   r(   r   r_   rt   rs   )r   Ústr_solÚcond_strÚseq_strrA   r2   s         r   r(   zHolonomicSequence.__repr__A  s€   � Ø26·/±/×1KÑ1KÕ1MÌtÐTX×TZÑTZÍ|Ð\ˆØ×#Ò#ØˆNàˆHØˆGØ—W‘Wò �Ù¬d°7­m¼TÀ!¼WÐEÑE�Ø˜1‘‘ðð ˜HÑ$ˆCØˆJr   c                 óÌ   — | j                   |j                   k7  s| j                  |j                  k7  ry| j                  r%|j                  r| j                  |j                  k(  S y)NFT)rr   r_   rt   rs   r!   s     r   r#   zHolonomicSequence.__eq__Q  sM   € Ø�?‰?˜e×.Ñ.Ò.°$·&±&¸E¿G¹GÒ2CØØ×Ò E×$9Ò$9Ø—7‘7˜eŸh™hÑ&Ð&Ør   N)r$   r%   r&   r'   r   r(   r   r#   r)   r   r   rp   rp   -  s"   „ ñð ')ó 0òð €Gór   rp   N)r'   Úsympy.core.singletonr   Úsympy.core.symbolr   r   Úsympy.printingr   Úsympy.core.sympifyr   r   r	   r3   r   rp   r)   r   r   ú<module>r~      sB   ðÙ å "ß /Ý Ý &ò'÷,8ñ 8òv÷HIñ HI÷V)ò )r   