+
    	þÎj  ã                   ó>   € R t ^ RIHtHt ^ RIHt ^ RIHt R tR t	R# )z
Recurrences
)ÚSÚsympify)Úiterable)Úas_intc                ó²  € V '       g   \         P                  # \        V 4      '       g   \        R4      h\        V4      '       g   \        R4      h\	        V4      pV^ 8  d   \        R4      hV  Uu. uF  p\        V4      NK  	  ppV Uu. uF  p\        V4      NK  	  pp\        V4      p\        V4      V8”  d   \        R4      hV\         P                  .V\        V4      ,
          ,          ,          pW&8  d	   WR,          # \        \        WB4      V4       UUu. uF  w  rxWx,          NK  	  p	pp\        V	RR V	R,          4      # u upi u upi u uppi )a²  
Evaluation of univariate linear recurrences of homogeneous type
having coefficients independent of the recurrence variable.

Parameters
==========

coeffs : iterable
    Coefficients of the recurrence
init : iterable
    Initial values of the recurrence
n : Integer
    Point of evaluation for the recurrence

Notes
=====

Let `y(n)` be the recurrence of given type, ``c`` be the sequence
of coefficients, ``b`` be the sequence of initial/base values of the
recurrence and ``k`` (equal to ``len(c)``) be the order of recurrence.
Then,

.. math :: y(n) = \begin{cases} b_n & 0 \le n < k \\
    c_0 y(n-1) + c_1 y(n-2) + \cdots + c_{k-1} y(n-k) & n \ge k
    \end{cases}

Let `x_0, x_1, \ldots, x_n` be a sequence and consider the transformation
that maps each polynomial `f(x)` to `T(f(x))` where each power `x^i` is
replaced by the corresponding value `x_i`. The sequence is then a solution
of the recurrence if and only if `T(x^i p(x)) = 0` for each `i \ge 0` where
`p(x) = x^k - c_0 x^(k-1) - \cdots - c_{k-1}` is the characteristic
polynomial.

Then `T(f(x)p(x)) = 0` for each polynomial `f(x)` (as it is a linear
combination of powers `x^i`). Now, if `x^n` is congruent to
`g(x) = a_0 x^0 + a_1 x^1 + \cdots + a_{k-1} x^{k-1}` modulo `p(x)`, then
`T(x^n) = x_n` is equal to
`T(g(x)) = a_0 x_0 + a_1 x_1 + \cdots + a_{k-1} x_{k-1}`.

Computation of `x^n`,
given `x^k = c_0 x^{k-1} + c_1 x^{k-2} + \cdots + c_{k-1}`
is performed using exponentiation by squaring (refer to [1_]) with
an additional reduction step performed to retain only first `k` powers
of `x` in the representation of `x^n`.

Examples
========

>>> from sympy.discrete.recurrences import linrec
>>> from sympy.abc import x, y, z

>>> linrec(coeffs=[1, 1], init=[0, 1], n=10)
55

>>> linrec(coeffs=[1, 1], init=[x, y], n=10)
34*x + 55*y

>>> linrec(coeffs=[x, y], init=[0, 1], n=5)
x**2*y + x*(x**3 + 2*x*y) + y**2

>>> linrec(coeffs=[1, 2, 3, 0, 0, 4], init=[x, y, z], n=16)
13576*x + 5676*y + 2356*z

References
==========

.. [1] https://en.wikipedia.org/wiki/Exponentiation_by_squaring
.. [2] https://en.wikipedia.org/w/index.php?title=Modular_exponentiation&section=6#Matrices

See Also
========

sympy.polys.agca.extensions.ExtensionElement.__pow__

z6Expected a sequence of coefficients for the recurrencezFExpected a sequence of values for the initialization of the recurrencez@Point of evaluation of recurrence must be a non-negative integerzECount of initial values should not exceed the order of the recurrenceNéÿÿÿÿ)r   ÚZeror   Ú	TypeErrorr   Ú
ValueErrorr   ÚlenÚzipÚlinrec_coeffsÚsum)
ÚcoeffsÚinitÚnÚargÚcÚbÚkÚuÚvÚtermss
   &&&       ÚP/opt/data/home/.local/lib/python3.14/site-packages/sympy/discrete/recurrences.pyÚlinrecr   
   s>  € ÷Z Ü�v‰vˆä�F×ÒÜð *ó +ð 	+ô �D�>Š>Üð -ó .ð 	.ô 	ˆq‹	€AØˆ1„uÜð /ó 0ð 	0ñ "(Ó(¡˜#Œ�Ž¡€AÐ(Ù!%Ó&¡˜#Œ�Ž¡€AÐ&ÜˆA‹€Aä
ˆ1ƒv�„zÜð 2ó 3ð 	3ð 	
Œa�f‰fˆX�qœ3˜q›6•zÕ"Õ"ˆà„uØ�tˆÜ ¤¨qÓ!4°aÔ8Ô9Ñ8‘T�QˆQ�SˆSÑ8€EÑ9Üˆu�S�bˆz˜5 �9Ó%Ð%ùò 	)ùÚ&ùó :s   Á2E	ÂEÄEc                óN   a aaa€ \        S 4      oV V3R loVVV3R loS! V4      # )an  
Compute the coefficients of n'th term in linear recursion
sequence defined by c.

`x^k = c_0 x^{k-1} + c_1 x^{k-2} + \cdots + c_{k-1}`.

It computes the coefficients by using binary exponentiation.
This function is used by `linrec` and `_eval_pow_by_cayley`.

Parameters
==========

c = coefficients of the divisor polynomial
n = exponent of x, so dividend is x^n

c                 ó   <€ \         P                  .^\        V 4      ,          ^,
          V,           ,          p\        V 4       FA  w  r4\        V 4       F-  w  rVW!V,           V,           ;;,          WF,          ,          uu&   K/  	  KC  	  \	        \        V4      ^,
          S^,
          R4       FK  p\	        S4       F9  pW%V,
          ^,
          ;;,          W%,          SV,          ,          ,          uu&   K;  	  KM  	  VRS # )é   Nr   )r   r   r   Ú	enumerateÚrange)	r   ÚoffsetÚwÚiÚpÚjÚqr   r   s	   &&     €€r   Ú_square_and_reduceÚ)linrec_coeffs.<locals>._square_and_reduce‹   s¸   ø€ ô �V‰VˆH�aœ˜A›•h •l VÕ+Õ,ˆÜ˜a–L‰DˆAÜ! !ž‘�Ø˜1•*˜q•.×! Q¥SÕ(Õ!ó %ñ !ô ”s˜1“v •z 1 q¥5¨"Ö-ˆAÜ˜1–X�Ø�a•%˜!•)— ¥ Q q¥T¥	Õ)•ó ñ .ð ��!ˆuˆó    c                 óþ   <€ V S8  dZ   \         P                  .V ,          \         P                  .,           \         P                  .SV ,
          ^,
          ,          ,           # S! S! V ^,          4      V ^,          4      # )é   )r   r   ÚOne)r   Ú_final_coeffsr&   r   s   &€€€r   r,   Ú$linrec_coeffs.<locals>._final_coeffsœ   sY   ø€ ð
 ˆqŒ5Ü—F‘F�8˜A•:¤§¡ Õ'¬1¯6©6¨(°A¸µE¸AµIÕ*>Õ>Ð>á%¡m°A¸µFÓ&;¸QÀ½UÓCÐCr(   )r   )r   r   r,   r&   r   s   f&@@@r   r   r   w   s&   û€ ô$ 	ˆA‹€Aö÷"Dñ ˜ÓÐr(   N)
Ú__doc__Ú
sympy.corer   r   Úsympy.utilities.iterablesr   Úsympy.utilities.miscr   r   r   © r(   r   Ú<module>r3      s!   ðñ÷ "Ý .Ý 'òj&ôZ/r(   