+
    i(                         R t ^ RIHt ^ RIHtHt ^ RIHt ^ RIH	t	 R t
 ! R R4      tR t ! R	 R
4      t ! R R4      tR# )zRecurrence Operators)S)Symbolsymbols)sstr)sympifyc                2    \        W4      pW"P                  3# )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   && z/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/holonomic/recurrence.pyRecurrenceOperatorsr   	   s    $ %T5D%%&&    c                   :   a  ] tR t^t o RtR tR t]tR tRt	V t
R# )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                    Wn         \        VP                  VP                  .V 4      V n        Vf   \        RRR7      V n        R # \        V\        4      '       d   \        VRR7      V n        R # \        V\        4      '       d	   W n        R # R # )NSnF)commutative)
r
   RecurrenceOperatorzerooner	   r   
gen_symbol
isinstancestrr   )selfr
   r   s   &&&r   __init__"RecurrenceOperatorAlgebra.__init__;   sn    	0YY!4) %d>DO)S))"))"GIv.."+ /r   c                    R \        V P                  4      ,           R,           V P                  P                  4       ,           pV# )z7Univariate Recurrence Operator Algebra in intermediate z over the base ring )r   r   r
   __str__)r   strings   & r   r   !RecurrenceOperatorAlgebra.__str__J   s<    J4??#$&<=YY!" r   c                v    V P                   VP                   8X  d   V P                  VP                  8X  d   R # R# )TF)r
   r   r   others   &&r   __eq__ RecurrenceOperatorAlgebra.__eq__S   s)    99

"t%:J:J'Jr   )r
   r   r	   N)__name__
__module____qualname____firstlineno____doc__r   r   __repr__r$   __static_attributes____classdictcell____classdict__s   @r   r   r      s%     6, H r   r   c                 4   \        V 4      \        V4      8:  d;   \        W4       UUu. uF  w  r#W#,           NK  	  uppV\        V 4      R  ,           pV# \        W4       UUu. uF  w  r#W#,           NK  	  uppV \        V4      R  ,           pV# u uppi u uppi N)lenzip)list1list2absols   &&   r   
_add_listsr9   Z   s    
5zSZ!$U!23!2quu!23eCJK6HH J "%U!23!2quu!23eCJK6HHJ 43s   B"Bc                   f   a  ] tR t^bt o Rt^tR tR tR tR t	]	t
R tR tR tR	 t]tR
 tRtV tR# )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                   W n         \        V\        4      '       d   \        V4       F  w  r4\        V\        4      '       d3   V P                   P
                  P                  \        V4      4      W&   KM  \        W@P                   P
                  P                  4      '       d   K~  V P                   P
                  P                  V4      W&   K  	  Wn	        \        V P                  4      ^,
          V n        R# )   N)parentr   list	enumerateintr
   
from_sympyr   dtype
listofpolyr2   order)r   list_of_polyr=   ijs   &&&  r   r   RecurrenceOperator.__init__   s      lD))!,/a%%&*kk&6&6&A&A!A$&GLO#A{{'7'7'='=>>&*kk&6&6&A&A!&DLO	 0 +O)A-
r   c                &  a V P                   pV P                  P                  o\        V\        4      '       gd   \        WP                  P                  P
                  4      '       g1   V P                  P                  P                  \        V4      4      .pMV.pMVP                   pR pV! V^ ,          V4      pV3R lp\        ^\        V4      4       F#  pV! V4      p\        WT! W',          V4      4      pK%  	  \	        WPP                  4      # )z
Multiplies two Operators and returns another
RecurrenceOperator instance using the commutation rule
Sn * a(n) = a(n + 1) * Sn
c                 z    \        V\        4      '       d   V Uu. uF  q"V ,          NK  	  up# W,          .# u upi r1   )r   r>   )r7   listofotherrF   s   && r   _mul_dmp_diffop3RecurrenceOperator.__mul__.<locals>._mul_dmp_diffop   s8    +t,,'23{!A{33O$$ 4s   8c                 &  < SP                   .p\        V \        4      '       d   V  F{  pSP                  V4      P	                  SP
                  ^ ,          SP
                  ^ ,          \        P                  ,           4      pVP                  SP                  V4      4       K}  	  V# V P	                  SP
                  ^ ,          SP
                  ^ ,          \        P                  ,           4      pVP                  SP                  V4      4       V# )    )
r   r   r>   to_sympysubsgensr   OneappendrA   )r7   r8   rF   rG   r
   s   &   r   
_mul_Sni_b.RecurrenceOperator.__mul__.<locals>._mul_Sni_b   s    99+C!T""Aa(--diilDIIaL155<PQAJJtq12  J FF499Q<1)=>

4??1-.Jr   )rC   r=   r
   r   r   rB   rA   r   ranger2   r9   )	r   r#   
listofselfrK   rL   r8   rU   rF   r
   s	   &&      @r   __mul__RecurrenceOperator.__mul__   s     __
{{%!344e[[%5%5%;%;<<#{{//::75>JK  %g**K	%
 jm[9	 q#j/*A$[1KS/*-"MNC	 + "#{{33r   c                   \        V\        4      '       g   \        V\        4      '       d   \        V4      p\        WP                  P
                  P                  4      '       g&   V P                  P
                  P                  V4      pV P                   Uu. uF  q!V,          NK  	  pp\        W0P                  4      # R # u upi r1   )	r   r   r@   r   r=   r
   rB   rA   rC   )r   r#   rG   r8   s   &&  r   __rmul__RecurrenceOperator.__rmul__   s    %!344%%%%e[[%5%5%;%;<<))55e<&*oo6o199oC6%c;;77 5 7s   Cc                   \        V\        4      '       d6   \        V P                  VP                  4      p\        W P                  4      # \        V\
        4      '       d   \        V4      pV P                  p\        WP                  P                  P                  4      '       g(   V P                  P                  P                  V4      .pMV.pV^ ,          V^ ,          ,           .VR,          ,           p\        W P                  4      # )rO   r<   NN)
r   r   r9   rC   r=   r@   r   r
   rB   rA   )r   r#   r8   	list_self
list_others   &&   r   __add__RecurrenceOperator.__add__   s    e/00T__e.>.>?C%c;;77 %%%%Ie[[%5%5%;%;<< $11==eDE
#W
Q<*Q-/09R=@C%c;;77r   c                "    V RV,          ,           # r<    r"   s   &&r   __sub__RecurrenceOperator.__sub__   s    rUl""r   c                "    RV ,          V,           # re   rg   r"   s   &&r   __rsub__RecurrenceOperator.__rsub__   s    d{U""r   c                $   V^8X  d   V # \        V P                  P                  P                  .V P                  4      pV^ 8X  d   V# V P                  V P                  P
                  P                  8X  dd   V P                  P                  P                  .V,          V P                  P                  P                  .,           p\        W0P                  4      # T p V^,          '       d	   W$,          pV^,          pV'       g    V# WD,          pK6  )r<   )r   r=   r
   r   rC   r	   r   )r   nresultr8   xs   &&   r   __pow__RecurrenceOperator.__pow__   s    6K#T[[%5%5%9%9$:DKKH6M??dkk88CCC;;##(()A-1A1A1E1E0FFC%c;;771uu!GA FAr   c                   V P                   pR p\        V4       F  w  r4W@P                  P                  P                  8X  d   K+  V P                  P                  P                  V4      pV^ 8X  d#   VR\        V4      ,           R,           ,          pKy  V'       d
   VR,          pV^8X  d#   VR\        V4      ,           R,           ,          pK  VR\        V4      ,           R,           R,           \        V4      ,           ,          pK  	  V# ) ()z + z)SnzSn**)rC   r?   r=   r
   r   rP   r   )r   rC   	print_strrF   rG   s   &    r   r   RecurrenceOperator.__str__  s    __
	j)DAKK$$)))  ))!,AAvS47]S00	U"	AvS47]U22	tAw,v5Q??I# *& r   c                  a  \        V\        4      '       d;   S P                  VP                  8X  d   S P                  VP                  8X  d   R # R# S P                  ^ ,          V8H  ;'       d]    \        ;QJ d0    V 3R lS P                  R,           4       F  '       d   K   R# 	  R # ! V 3R lS P                  R,           4       4      # )TFc              3   f   <"   T F&  qSP                   P                  P                  J x  K(  	  R # 5ir1   )r=   r
   r   ).0rF   r   s   & r   	<genexpr>,RecurrenceOperator.__eq__.<locals>.<genexpr>*  s&     H4GqT[[%%***4Gs   .1r_   )r   r   rC   r=   allr"   s   f&r   r$   RecurrenceOperator.__eq__#  s    e/00%"2"22t{{ell7Rq!U* I ICHDOOB4GHCC	I	IHDOOB4GHH	Ir   )rC   rD   r=   N)r&   r'   r(   r)   r*   _op_priorityr   rY   r\   rb   __radd__rh   rk   rq   r   r+   r$   r,   r-   r.   s   @r   r   r   b   sU     #J L."04d
88& H##(2 HI Ir   r   c                   @   a  ] tR tRt o Rt. 3R ltR t]tR tRt	V t
R# )HolonomicSequencei-  z
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                   Wn         \        V\        4      '       g
   V.V n        MW n        \	        V P                  4      ^ 8X  d	   RV n        MRV n        VP                  P                  P                  ^ ,          V n	        R# )rO   FTN)

recurrencer   r>   u0r2   _have_init_condr=   r
   rR   rn   )r   r   r   s   &&&r   r   HolonomicSequence.__init__4  s`    $"d##dDGGtww<1#(D #'D ""'',,Q/r   c                0   R V P                   P                  4       : R\        V P                  4      : R2pV P                  '       g   V# Rp^ pV P
                   F/  pVR\        V4      : R\        V4      : 2,          pV^,          pK1  	  W,           pV# )zHolonomicSequence(z, rv   rt   z, u(z) = )r   r+   r   rn   r   r   )r   str_solcond_strseq_strrF   r8   s   &     r   r+   HolonomicSequence.__repr__A  s|    26//1K1K1MtTXTZTZ|\###NHGWWd7mT!WEE1  $CJr   c                    V P                   VP                   8w  g   V P                  VP                  8w  d   R # V P                  '       d,   VP                  '       d   V P                  VP                  8H  # R# )FT)r   rn   r   r   r"   s   &&r   r$   HolonomicSequence.__eq__Q  sS    ??e...$&&EGG2CE$9$9$977ehh&&r   )r   rn   r   r   N)r&   r'   r(   r)   r*   r   r+   r   r$   r,   r-   r.   s   @r   r   r   -  s*      ') 0 G r   r   N)r*   sympy.core.singletonr   sympy.core.symbolr   r   sympy.printingr   sympy.core.sympifyr   r   r   r9   r   r   rg   r   r   <module>r      sB     " /  &',8 8vHI HIV) )r   