+
    ‹°³jàŠ ã                  óè  € R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
HtHtHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHtHtHt ^ R
IHt ^ RIHt ^ RIHtHtHtH t H!t!H"t" ^ RI#H$t$H%t%H&t&H't' ^ RI(H)t)H*t*H+t+H,t,H-t-H.t. ^ RI/H0t0H1t1H2t2 ^ RI3H4t4 ^ RI5H6t6 ^ RI7H8t8H9t9H:t:H;t;H<t< ^ RI=H>t> ^ RI?H@t@HAtA ^ RIBHCtCHDtD ^ RIEHFtFHGtGHHtH ^ RIIHJtJ ^ RIKHLtL ^ RIMHNtN ^ RIOHPtPHQtQHRtR ^ RISHTtT ^ RIUHVtV ^ RIWHXtXHYtY ^ RIZH[t\ R t]]! R 4      t^ ! R! R"]4      t_ ! R# R$]4      t` ! R% R&]4      ta ! R' R(]4      tb ! R) R*]4      tc ! R+ R,]4      td ! R- R.]4      te ! R/ R0]4      tf ! R1 R2]4      tg ! R3 R4]4      th ! R5 R6]4      ti ! R7 R8]4      tj ! R9 R:]4      tk ! R; R<]4      tl ! R= R>]4      tm ! R? R@]4      tn ! RA RB]4      to ! RC RD]4      tp ! RE RF]4      tq ! RG RH]4      tr ! RI RJ]4      ts ! RK RL]4      tt ! RM RN]4      tu ! RO RP]v4      twRctxRdty]z! RQ]y4      t{RR t|ReRS lt}]ReRT l4       t~]RU 4       tReRV lt€RW t�]RX 4       t‚RY tƒ]RZ 4       t„RfR[ lt…]R\ 4       t†RgR] lt‡ ! R^ R_]4      tˆRhR`RQRaRQ/Rb llt‰RQ# )ia6  
This module implements some special functions that commonly appear in
combinatorial contexts (e.g. in power series); in particular,
sequences of rational numbers such as Bernoulli and Fibonacci numbers.

Factorials, binomial coefficients and related functions are located in
the separate 'factorials' module.
)Úannotations)Úprod)Údefaultdict)ÚCallable)ÚSÚSymbolÚAddÚDummy)Úcacheit)ÚDict)ÚExpr)ÚArgumentIndexErrorÚDefinedFunctionÚ
expand_mul)Ú	fuzzy_not)ÚMul)ÚEÚIÚpiÚooÚRationalÚInteger)ÚEqÚis_leÚis_gtÚis_lt)Ú
SYMPY_INTSÚremoveÚlcmÚlegendreÚjacobiÚ	kronecker)ÚbinomialÚ	factorialÚsubfactorial©Úlog)Ú	Piecewise)Ú	factorintÚ_divisor_sigmaÚis_carmichaelÚ find_carmichael_numbers_in_rangeÚfind_first_n_carmichaels)Ú_primepi)Ú
_partitionÚ_partition_rec)ÚisprimeÚ	is_square)Úbernoulli_polyÚ
euler_polyÚgenocchi_poly)Úcancel)ÚMultisetPartitionTraverser©Úsympy_deprecation_warning)ÚmultisetÚmultiset_derangementsÚiterable)Úrecurrence_memo)Úas_int)ÚmpÚworkprec)Úifibc                ó8   € \        \        W^,           4      4      # ©é   )r   Úrange)ÚaÚbs   &&Úf/home/luca/screen-checking/.venv/lib/python3.14/site-packages/sympy/functions/combinatorial/numbers.pyÚ_productrH   -   s   € Ü”�a˜Q�“Ó Ð ó    Úxc                  óz   € ] tR t^;tRt]R 4       t]R 4       t]R 4       t]R 4       t	]R 4       t
]R 4       tRtR	# )
Ú
carmichaela°  
Carmichael Numbers:

Certain cryptographic algorithms make use of big prime numbers.
However, checking whether a big number is prime is not so easy.
Randomized prime number checking tests exist that offer a high degree of
confidence of accurate determination at low cost, such as the Fermat test.

Let 'a' be a random number between $2$ and $n - 1$, where $n$ is the
number whose primality we are testing. Then, $n$ is probably prime if it
satisfies the modular arithmetic congruence relation:

.. math :: a^{n-1} = 1 \pmod{n}

(where mod refers to the modulo operation)

If a number passes the Fermat test several times, then it is prime with a
high probability.

Unfortunately, certain composite numbers (non-primes) still pass the Fermat
test with every number smaller than themselves.
These numbers are called Carmichael numbers.

A Carmichael number will pass a Fermat primality test to every base $b$
relatively prime to the number, even though it is not actually prime.
This makes tests based on Fermat's Little Theorem less effective than
strong probable prime tests such as the Baillie-PSW primality test and
the Miller-Rabin primality test.

Examples
========

>>> from sympy.ntheory.factor_ import find_first_n_carmichaels, find_carmichael_numbers_in_range
>>> find_first_n_carmichaels(5)
[561, 1105, 1729, 2465, 2821]
>>> find_carmichael_numbers_in_range(0, 562)
[561]
>>> find_carmichael_numbers_in_range(0,1000)
[561]
>>> find_carmichael_numbers_in_range(0,2000)
[561, 1105, 1729]

References
==========

.. [1] https://en.wikipedia.org/wiki/Carmichael_number
.. [2] https://en.wikipedia.org/wiki/Fermat_primality_test
.. [3] https://www.jstor.org/stable/23248683?seq=1#metadata_info_tab_contents
c                	ó4   € \        R RRR7       \        V 4      # )zt
is_perfect_square is just a wrapper around sympy.ntheory.primetest.is_square
so use that directly instead.
        ú1.11ú$deprecated-carmichael-static-methods©Údeprecated_since_versionÚactive_deprecations_target)r8   r1   ©Úns   &rG   Úis_perfect_squareÚcarmichael.is_perfect_squaren   s#   € ä!ð	ð "(Ø#Iõ	
ô ˜‹|ÐrI   c                	ó4   € \        R RRR7       W,          ^ 8H  # )zI
        divides can be replaced by directly testing n % p == 0.
        rN   rO   rP   r7   )ÚprT   s   &&rG   ÚdividesÚcarmichael.dividesz   s%   € ä!ð	ð "(Ø#Iõ	
ð �u˜‰zÐrI   c                	ó4   € \        R RRR7       \        V 4      # )zi
is_prime is just a wrapper around sympy.ntheory.primetest.isprime so use that
directly instead.
        rN   rO   rP   )r8   r0   rS   s   &rG   Úis_primeÚcarmichael.is_prime…   s#   € ä!ð	ð "(Ø#Iõ	
ô �q‹zÐrI   c                	ó4   € \        R RRR7       \        V 4      # )zr
is_carmichael is just a wrapper around sympy.ntheory.factor_.is_carmichael so use that
directly instead.
        ú1.13ú%deprecated-ntheory-symbolic-functionsrP   )r8   r*   rS   s   &rG   r*   Úcarmichael.is_carmichael‘   s$   € ä!ð	ð "(Ø#Jõ	
ô ˜QÓÐrI   c                	ó4   € \        R RRR7       \        W4      # )z˜
find_carmichael_numbers_in_range is just a wrapper around sympy.ntheory.factor_.find_carmichael_numbers_in_range so use that
directly instead.
        r_   r`   rP   )r8   r+   )rJ   Úys   &&rG   r+   Ú+carmichael.find_carmichael_numbers_in_range�   s$   € ä!ð	ð "(Ø#Jõ	
ô 0°Ó5Ð5rI   c                	ó4   € \        R RRR7       \        V 4      # )zˆ
find_first_n_carmichaels is just a wrapper around sympy.ntheory.factor_.find_first_n_carmichaels so use that
directly instead.
        r_   r`   rP   )r8   r,   rS   s   &rG   r,   Ú#carmichael.find_first_n_carmichaels©   s$   € ä!ð	ð "(Ø#Jõ	
ô (¨Ó*Ð*rI   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚstaticmethodrU   rY   r\   r*   r+   r,   Ú__static_attributes__rg   rI   rG   rL   rL   ;   s€   † ñ0ðd ñ	ó ð	ð ñó ðð ñ	ó ð	ð ñ	 ó ð	 ð ñ	6ó ð	6ð ñ	+ó ô	+rI   rL   c                  ó�   € ] tR t^½tRt]R 4       t]]! R]P                  ]
.4      R 4       4       t]R
R l4       tR tR tR tR	tR# )Ú	fibonacciaC  
Fibonacci numbers / Fibonacci polynomials

The Fibonacci numbers are the integer sequence defined by the
initial terms `F_0 = 0`, `F_1 = 1` and the two-term recurrence
relation `F_n = F_{n-1} + F_{n-2}`.  This definition
extended to arbitrary real and complex arguments using
the formula

.. math :: F_z = \frac{\phi^z - \cos(\pi z) \phi^{-z}}{\sqrt 5}

The Fibonacci polynomials are defined by `F_1(x) = 1`,
`F_2(x) = x`, and `F_n(x) = x*F_{n-1}(x) + F_{n-2}(x)` for `n > 2`.
For all positive integers `n`, `F_n(1) = F_n`.

* ``fibonacci(n)`` gives the `n^{th}` Fibonacci number, `F_n`
* ``fibonacci(n, x)`` gives the `n^{th}` Fibonacci polynomial in `x`, `F_n(x)`

Examples
========

>>> from sympy import fibonacci, Symbol

>>> [fibonacci(x) for x in range(11)]
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
>>> fibonacci(5, Symbol('t'))
t**4 + 3*t**2 + 1

See Also
========

bell, bernoulli, catalan, euler, harmonic, lucas, genocchi, partition, tribonacci

References
==========

.. [1] https://en.wikipedia.org/wiki/Fibonacci_number
.. [2] https://mathworld.wolfram.com/FibonacciNumber.html

c                	ó   € \        V 4      # ©N)Ú_ifibrS   s   &rG   Ú_fibÚfibonacci._fibç   s   € ä�Q‹xˆrI   Nc                	ób   € VR,          \         VR,          ,          ,           P                  4       # )é   éþÿÿÿéÿÿÿÿ©Ú_symÚexpand©rT   Úprevs   &&rG   Ú_fibpolyÚfibonacci._fibpolyë   s$   € ð �R•œ4  R¥�=Õ(×0Ñ0Ó2Ð2rI   c                	óž  € V\         P                  J d   \         P                  # VP                  '       d—   Vf\   \        V4      pV^ 8  d0   \         P                  V^,           ,          \        V) 4      ,          # \        V P                  V4      4      # V^8  d   \        R4      hV P                  V4      P                  \        V4      # R # )NzDFibonacci polynomials are defined only for positive integer indices.)r   ÚInfinityÚ
is_IntegerÚintÚNegativeOnerp   r   rt   Ú
ValueErrorr   Úsubsr{   ©ÚclsrT   Úsyms   &&&rG   ÚevalÚfibonacci.evalð   sŸ   € à”—
‘
‹?Ü—:‘:Ðà�<�<ˆ<ØŠ{Ü˜“F�Ø�q”5ÜŸ=™=¨1¨q­5Õ1´I¸q¸b³MÕAÐAä" 3§8¡8¨A£;Ó/Ð/à�q”5Ü$ð &<ó =ð =à—|‘| A“×+Ñ+¬D°#Ó6Ð6ñ rI   c                	óÖ   € ^ RI HpHp \        P                  V,          V! \        P
                  V,          4      \        P                  V,          ,          ,
          V! ^4      ,          # )é    )ÚsqrtÚcos)Úsympy.functionsr�   r�   r   ÚGoldenRatioÚPi)ÚselfrT   Úkwargsr�   r�   s   &&,  rG   Ú_eval_rewrite_as_tractableÚ$fibonacci._eval_rewrite_as_tractable  s<   € ß-Ü—‘˜qÕ ¡3¤q§t¡t¨A¥v£;¬q¯}©}¸aÕ/?Õ#?Õ?ÁÀaÃÕHÐHrI   c                	ó¸   € ^ RI Hp ^V) ,          V! ^4      ,          ^V! ^4      ,           V,          V! ^4      ) ^,           V,          ,
          ,          ^,          # ©rŽ   )r�   ©Ú(sympy.functions.elementary.miscellaneousr�   ©r”   rT   r•   r�   s   &&, rG   Ú_eval_rewrite_as_sqrtÚfibonacci._eval_rewrite_as_sqrt  sD   € ÝAØ�A�2�w‘t˜A“w� ¡T¨!£W¥¨qÕ 0±T¸!³W°H¸qµLÀ1Õ3DÕ DÕEÈÕIÐIrI   c                	ó¾   € \         P                  V,          ^\         P                  ) V,          ,          ,
          ^\         P                  ,          ^,
          ,          # rB   )r   r’   ©r”   rT   r•   s   &&,rG   Ú_eval_rewrite_as_GoldenRatioÚ&fibonacci._eval_rewrite_as_GoldenRatio
  s8   € Ü—‘˜qÕ  1¤q§}¡} n°qÕ%8Õ#8Õ8¸1¼Q¿]¹]½?È1Õ;LÕMÐMrI   rg   rr   )rh   ri   rj   rk   rl   rm   rt   r<   r   ÚOner{   r   Úclassmethodr‹   r–   r�   r¡   rn   rg   rI   rG   rp   rp   ½   sn   † ñ'ðR ñó ðð Ù�d˜AŸE™E 4Ð(Ó)ñ3ó *ó ð3ð ó7ó ð7ò"IòJöNrI   rp   c                  ó0   € ] tR tRtRt]R 4       tR tRtR# )Úlucasi  a}  
Lucas numbers

Lucas numbers satisfy a recurrence relation similar to that of
the Fibonacci sequence, in which each term is the sum of the
preceding two. They are generated by choosing the initial
values `L_0 = 2` and `L_1 = 1`.

* ``lucas(n)`` gives the `n^{th}` Lucas number

Examples
========

>>> from sympy import lucas

>>> [lucas(x) for x in range(11)]
[2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123]

See Also
========

bell, bernoulli, catalan, euler, fibonacci, harmonic, genocchi, partition, tribonacci

References
==========

.. [1] https://en.wikipedia.org/wiki/Lucas_number
.. [2] https://mathworld.wolfram.com/LucasNumber.html

c                	óÄ   € V\         P                  J d   \         P                  # VP                  '       d*   \        V^,           4      \        V^,
          4      ,           # R# ©rC   N)r   r‚   rƒ   rp   ©r‰   rT   s   &&rG   r‹   Ú
lucas.eval5  sB   € à”—
‘
‹?Ü—:‘:Ðà�<�<ˆ<Ü˜Q �UÓ#¤i°°AµÓ&6Õ6Ð6ñ rI   c                	ó�   € ^ RI Hp ^V) ,          ^V! ^4      ,           V,          V! ^4      ) ^,           V,          ,           ,          # r™   rš   rœ   s   &&, rG   r�   Úlucas._eval_rewrite_as_sqrt=  s7   € ÝAØ�A�2�w˜™T !›W� qÕ(©T°!«W¨H°q­L¸1Õ+<Õ<Õ=Ð=rI   rg   N)	rh   ri   rj   rk   rl   r¤   r‹   r�   rn   rg   rI   rG   r¦   r¦     s    † ñð> ñ7ó ð7ö>rI   r¦   c                  ó  € ] tR tRtRt]]! ]P                  ]P                  ]P                  .4      R 4       4       t
]]! ]P                  ]P                  ]^,          .4      R 4       4       t]R
R l4       tR tR tR	tR# )Ú
tribonacciiI  a@  
Tribonacci numbers / Tribonacci polynomials

The Tribonacci numbers are the integer sequence defined by the
initial terms `T_0 = 0`, `T_1 = 1`, `T_2 = 1` and the three-term
recurrence relation `T_n = T_{n-1} + T_{n-2} + T_{n-3}`.

The Tribonacci polynomials are defined by `T_0(x) = 0`, `T_1(x) = 1`,
`T_2(x) = x^2`, and `T_n(x) = x^2 T_{n-1}(x) + x T_{n-2}(x) + T_{n-3}(x)`
for `n > 2`.  For all positive integers `n`, `T_n(1) = T_n`.

* ``tribonacci(n)`` gives the `n^{th}` Tribonacci number, `T_n`
* ``tribonacci(n, x)`` gives the `n^{th}` Tribonacci polynomial in `x`, `T_n(x)`

Examples
========

>>> from sympy import tribonacci, Symbol

>>> [tribonacci(x) for x in range(11)]
[0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149]
>>> tribonacci(5, Symbol('t'))
t**8 + 3*t**5 + 3*t**2

See Also
========

bell, bernoulli, catalan, euler, fibonacci, harmonic, lucas, genocchi, partition

References
==========

.. [1] https://en.wikipedia.org/wiki/Generalizations_of_Fibonacci_numbers#Tribonacci_numbers
.. [2] https://mathworld.wolfram.com/TribonacciNumber.html
.. [3] https://oeis.org/A000073

c                	óL   € VR,          VR,          ,           VR,          ,           # ©é   éýÿÿÿrx   ry   rg   r}   s   &&rG   Ú_tribÚtribonacci._tribp  s    € ð �R•˜4 �8Õ# d¨2¥hÕ.Ð/rI   c                	ó¢   € VR,          \         VR,          ,          ,           \         ^,          VR,          ,          ,           P                  4       # r°   rz   r}   s   &&rG   Ú	_tribpolyÚtribonacci._tribpolyu  s6   € ð �R•œ4  R¥�=Õ(¬4°­7°4¸µ8Õ+;Õ;×CÑCÓEÐErI   Nc                	ó2  € V\         P                  J d   \         P                  # VP                  '       da   \        V4      pV^ 8  d   \	        R4      hVf   \        V P                  V4      4      # V P                  V4      P                  \        V4      # R# )rŽ   zITribonacci polynomials are defined only for non-negative integer indices.N)
r   r‚   rƒ   r„   r†   r   r³   r¶   r‡   r{   rˆ   s   &&&rG   r‹   Útribonacci.evalz  s~   € à”—
‘
‹?Ü—:‘:Ðà�<�<ˆ<Ü�A“ˆAØ�1ŒuÜ ð "@ó Að AàŠ{Ü˜sŸy™y¨›|Ó,Ð,à—}‘} QÓ'×,Ñ,¬T°3Ó7Ð7ñ rI   c           	     	óˆ  € ^ RI HpHp R\        P                  V! ^4      ,          ,           ^,          p^V! ^^V! ^!4      ,          ,           4      ,           V! ^^V! ^!4      ,          ,
          4      ,           ^,          p^WS! ^^V! ^!4      ,          ,           4      ,          ,           V^,          V! ^^V! ^!4      ,          ,
          4      ,          ,           ^,          p^V^,          V! ^^V! ^!4      ,          ,           4      ,          ,           WS! ^^V! ^!4      ,          ,
          4      ,          ,           ^,          pWa^,           ,          Wg,
          Wh,
          ,          ,          Wq^,           ,          Wv,
          Wx,
          ,          ,          ,           W�^,           ,          W†,
          W‡,
          ,          ,          ,           p	V	# )rŽ   ©Úcbrtr�   ry   )r›   r¼   r�   r   ÚImaginaryUnit)
r”   rT   r•   r¼   r�   ÚwrE   rF   ÚcÚTns
   &&,       rG   r�   Ú tribonacci._eval_rewrite_as_sqrt‰  s4  € ßGØ”!—/‘/¡D¨£GÕ+Õ+¨qÕ0ˆØ‘�b˜1™T "›X�:•oÓ&Õ&©¨b°1±T¸"³Xµ:­oÓ)>Õ>À!ÕCˆØ��4˜˜Q™t B›x�Z�Ó(Õ(Õ(¨1¨a­4±°R¸!¹DÀ»H½*µ_Ó0EÕ+EÕEÈÕJˆØ��A•‘d˜2 ¡$ r£(¥
�?Ó+Õ+Õ+¨a°°R¸!¹DÀ»H½*µ_Ó0EÕ.EÕEÈÕJˆØ�a•%�j˜1�5 1¥5�/Õ*Ø�a•%�j˜1�5 1¥5�/Õ*õ+à�a•%�j˜1�5 1¥5�/Õ*õ+ˆð ˆ	rI   c                	ó   € ^ RI Hp ^ RIHpHp V! R^fV! ^!4      ,          ,           4      p^V,          \
        P                  V,          ,          V^,          ^V,          ,
          ^,           ,          pV! V\
        P                  ,           4      # )rŽ   ©Úfloorr»   iJ  )Ú#sympy.functions.elementary.integersrÄ   r›   r¼   r�   r   ÚTribonacciConstantÚHalf)r”   rT   r•   rÄ   r¼   r�   rF   rÀ   s   &&,     rG   Ú#_eval_rewrite_as_TribonacciConstantÚ.tribonacci._eval_rewrite_as_TribonacciConstant”  s`   € Ý=ßGÙ��s™4 ›8•|Õ#Ó$ˆØ��U”Q×)Ñ)¨1Õ,Õ,°°1µ°q¸µsµ
¸QµÕ?ˆÙ�Rœ!Ÿ&™&•[Ó!Ð!rI   rg   rr   )rh   ri   rj   rk   rl   rm   r<   r   ÚZeror£   r³   r{   r¶   r¤   r‹   r�   rÈ   rn   rg   rI   rG   r®   r®   I  s�   † ñ$ðL Ù�a—f‘f˜aŸe™e Q§U¡UÐ+Ó,ñ0ó -ó ð0ð Ù�a—f‘f˜aŸe™e T¨1¥WÐ-Ó.ñFó /ó ðFð ó8ó ð8ò	ö"rI   r®   c                  óÀ   € ] tR tRt$ RtR]R&   ]R 4       t^ ]P                  ^]
! ^^4      ^]
! ^^4      ^]
! R^4      /t^ ^ ^^^^^^/t]RR l4       tRR ltR	 tR
tR# )Ú	bernoullii£  a*  
Bernoulli numbers / Bernoulli polynomials / Bernoulli function

The Bernoulli numbers are a sequence of rational numbers
defined by `B_0 = 1` and the recursive relation (`n > 0`):

.. math :: n+1 = \sum_{k=0}^n \binom{n+1}{k} B_k

They are also commonly defined by their exponential generating
function, which is `\frac{x}{1 - e^{-x}}`. For odd indices > 1,
the Bernoulli numbers are zero.

The Bernoulli polynomials satisfy the analogous formula:

.. math :: B_n(x) = \sum_{k=0}^n (-1)^k \binom{n}{k} B_k x^{n-k}

Bernoulli numbers and Bernoulli polynomials are related as
`B_n(1) = B_n`.

The generalized Bernoulli function `\operatorname{B}(s, a)`
is defined for any complex `s` and `a`, except where `a` is a
nonpositive integer and `s` is not a nonnegative integer. It is
an entire function of `s` for fixed `a`, related to the Hurwitz
zeta function by

.. math:: \operatorname{B}(s, a) = \begin{cases}
          -s \zeta(1-s, a) & s \ne 0 \\ 1 & s = 0 \end{cases}

When `s` is a nonnegative integer this function reduces to the
Bernoulli polynomials: `\operatorname{B}(n, x) = B_n(x)`. When
`a` is omitted it is assumed to be 1, yielding the (ordinary)
Bernoulli function which interpolates the Bernoulli numbers and is
related to the Riemann zeta function.

We compute Bernoulli numbers using Ramanujan's formula:

.. math :: B_n = \frac{A(n) - S(n)}{\binom{n+3}{n}}

where:

.. math :: A(n) = \begin{cases} \frac{n+3}{3} &
    n \equiv 0\ \text{or}\ 2 \pmod{6} \\
    -\frac{n+3}{6} & n \equiv 4 \pmod{6} \end{cases}

and:

.. math :: S(n) = \sum_{k=1}^{[n/6]} \binom{n+3}{n-6k} B_{n-6k}

This formula is similar to the sum given in the definition, but
cuts `\frac{2}{3}` of the terms. For Bernoulli polynomials, we use
Appell sequences.

For `n` a nonnegative integer and `s`, `a`, `x` arbitrary complex numbers,

* ``bernoulli(n)`` gives the nth Bernoulli number, `B_n`
* ``bernoulli(s)`` gives the Bernoulli function `\operatorname{B}(s)`
* ``bernoulli(n, x)`` gives the nth Bernoulli polynomial in `x`, `B_n(x)`
* ``bernoulli(s, a)`` gives the generalized Bernoulli function
  `\operatorname{B}(s, a)`

.. versionchanged:: 1.12
    ``bernoulli(1)`` gives `+\frac{1}{2}` instead of `-\frac{1}{2}`.
    This choice of value confers several theoretical advantages [5]_,
    including the extension to complex parameters described above
    which this function now implements. The previous behavior, defined
    only for nonnegative integers `n`, can be obtained with
    ``(-1)**n*bernoulli(n)``.

Examples
========

>>> from sympy import bernoulli
>>> from sympy.abc import x
>>> [bernoulli(n) for n in range(11)]
[1, 1/2, 1/6, 0, -1/30, 0, 1/42, 0, -1/30, 0, 5/66]
>>> bernoulli(1000001)
0
>>> bernoulli(3, x)
x**3 - 3*x**2/2 + x/2

See Also
========

andre, bell, catalan, euler, fibonacci, harmonic, lucas, genocchi,
partition, tribonacci, sympy.polys.appellseqs.bernoulli_poly

References
==========

.. [1] https://en.wikipedia.org/wiki/Bernoulli_number
.. [2] https://en.wikipedia.org/wiki/Bernoulli_polynomial
.. [3] https://mathworld.wolfram.com/BernoulliNumber.html
.. [4] https://mathworld.wolfram.com/BernoulliPolynomial.html
.. [5] Peter Luschny, "The Bernoulli Manifesto",
       https://luschny.de/math/zeta/The-Bernoulli-Manifesto.html
.. [6] Peter Luschny, "An introduction to the Bernoulli function",
       https://arxiv.org/abs/2009.06743

ztuple[Integer]Úargsc                	ón  € ^ p\        \        V ^,           V ^,
          4      4      p\        ^V ^,          ^,           4       F•  pW\        V ^V,          ,
          4      ,          ,          pV\	        V ^,
          ^V,          ,
          ^,           V ^V,          ,
          4      ,          pV\	        ^V,          ^,           ^V,          ^	,           4      ,          pK—  	  V ^,          ^8X  d   \        V ^,           ^4      ) V,
          pM\        V ^,           ^4      V,
          pV\        V ^,           V 4      ,          # ©rŽ   )r„   r"   rD   rÌ   rH   r   )rT   ÚsrE   Újs   &   rG   Ú_calc_bernoulliÚbernoulli._calc_bernoulli  sí   € àˆÜ”˜˜Q�  A¥Ó&Ó'ˆÜ�q˜!˜Q�$ �(Ö#ˆAØ”Y˜q 1 Q¥3�wÓ'Õ'Õ'ˆAà”˜!˜a�% ! A¥#�+¨�/¨1¨q°­s­7Ó3Õ3ˆAØ”(˜1˜Q�3 �7 A a¥C¨!¥GÓ,Õ,ŠAñ	 $ð
 ˆq�5�AŒ:Ü˜!˜a�% Ó#Ð# aÕ'‰Aä˜˜Q� Ó" QÕ&ˆAØ”8˜A �E 1Ó%Õ%Ð%rI   Nc                	óü  € V\         P                  J d	   V ! V4      # VP                  '       d   \         P                  # VP                  R J g   VP                  R J d;   Ve5   VP
                  '       d#   VP                  '       d   \         P                  # R# VEfB   V\         P                  J d   \         P                  # VP                  '       d*   V^,
          P                  '       d   \         P                  # VP                  '       dÏ   \        V4      pVR8”  d7   \        P                  ! V4      w  r4\!        \        V4      \        V4      4      # V^,          pV P"                  V,          pW8:  d   V P$                  V,          # \'        V^,           V^,           ^4       F0  pV P)                  V4      pW€P$                  V&   WpP"                  V&   K2  	  X# R# VP                  '       d   \+        W4      # R# )FNiô  )r   r£   Úis_zeroÚ
is_integerÚis_nonnegativerƒ   Úis_nonpositiveÚNaNrÇ   Úis_oddÚis_positiverÊ   Ú	is_Numberr„   r>   Úbernfracr   Ú_highestÚ_cacherD   rÒ   r2   )	r‰   rT   rJ   rX   ÚqÚcaseÚhighest_cachedÚirF   s	   &&&      rG   r‹   Úbernoulli.eval  ss  € à”—‘‹:Ù�q“6ˆMØ�Y�YˆYÜ—5‘5ˆLØ�\‰\˜UÓ" a×&6Ñ&6¸%Ó&?ØŠ} §§ °!×2B×2BÐ2BÜ—u‘u�Ùà‹YØ”A—E‘E‹zÜ—v‘v�Ø——�˜q �s×/×/Ð/Ü—v‘v�Ø——�Ü˜“F�à�s”7ÜŸ;š; q›>‘D�AÜ#¤C¨£F¬C°«FÓ3Ð3Ø˜1•u�Ø!$§¡¨dÕ!3�ØÔ&ØŸ:™: a�=Ð(ô ˜~°Õ1°1°qµ5¸!Ö<�AØ×+Ñ+¨AÓ.�AØ$%—J‘J˜q‘MØ)*—L‘L Ó&ñ =ð �ñ# ð& �[�[ˆ[Ü! !Ó'Ð'ñ rI   c                	ón   € ^ RI Hp \        ^\        V^ 4      3V) V! ^V,
          V4      ,          R34      # )rŽ   ©ÚzetaT)Ú&sympy.functions.special.zeta_functionsrç   r'   r   )r”   rT   rJ   r•   rç   s   &&&, rG   Ú_eval_rewrite_as_zetaÚbernoulli._eval_rewrite_as_zetaE  s2   € Ý?Ü˜!œR  1›X˜¨!¨©d°1°Qµ3¸«lÕ):¸DÐ(AÓBÐBrI   c                	óŠ  € \         ;QJ d&    R  V P                   4       F  '       d   K   RM	  RM! R  V P                   4       4      '       g   R# V P                  ^ ,          P                  V4      p\        V P                  4      ^8”  d   V P                  ^,          M\        P
                  P                  V4      p\        V4      ;_uu_ 4        V^ 8X  d   \        P                  ! ^4      pM¢V^8X  d   V\        P                  ! R4      ,
          pM}\        P                  ! V4      '       d<   V^ 8¼  d5   V^8X  d   \        P                  ! V4      M\        P                  ! W#4      pM&V) \        P                  ! ^V,
          V4      ,          pRRR4       \        P                  ! XV4      #   + '       g   i     L'; i)c              3  ó8   "  € T F  qP                   x € K  	  R # 5irr   ©Ú	is_number©Ú.0rJ   s   & rG   Ú	<genexpr>Ú(bernoulli._eval_evalf.<locals>.<genexpr>J  ó   é € Ð2©	 1—;–;«	ùó   ‚FTNç      à?)ÚallrÍ   Ú
_to_mpmathÚlenr   r£   r?   r>   ÚmpfÚisintrÌ   Úbernpolyrç   r   Ú_from_mpmath)r”   ÚprecrT   rJ   Úress   &&   rG   Ú_eval_evalfÚbernoulli._eval_evalfI  s  € ß‹sÑ2¨¯	ª	Ó2�s�sŠsÑ2¨¯	ª	Ó2×2Ò2ÙØ�I‰I�a�L×#Ñ# DÓ)ˆÜ  §¡›^¨aÔ/ˆT�Y‰Y�qŽ\´Q·U±U×FÑFÀtÓLˆÜ�d�^�^Ø�AŒvÜ—f’f˜Q“i‘Ø�a”Øœ"Ÿ&š& ›+•o‘Ü—’˜!—’  a¤Ø)*¨a¬”b—l’l 1”o´R·[²[ÀÓ5F‘à�bœ2Ÿ7š7 1 Q¥3¨›?Õ*�÷ ô × Ò   dÓ+Ð+÷ �^ús   ÃAF2Ä2A!F2Æ2G	rg   ry   rr   rB   )rh   ri   rj   rk   rl   Ú__annotations__rm   rÒ   r   r£   r   rß   rÞ   r¤   r‹   ré   rÿ   rn   rg   rI   rG   rÌ   rÌ   £  sˆ   ‡ ñbðH Óð ñ&ó ð&ð  �—‘˜™8 A q›>¨1©h°q¸!«n¸aÁÈ"ÈbÓAQÐR€FØ�1�a˜˜A˜q ! QÐ'€Hàó#(ó ð#(ôJCö,rI   rÌ   c                  ó°   € ] tR tRtRt]]! ^^.4      R 4       4       t]]! ]P                  ]
.4      R 4       4       t]R 4       t]R
R l4       tR
R ltR	tR# )Úbellia  aÎ  
Bell numbers / Bell polynomials

The Bell numbers satisfy `B_0 = 1` and

.. math:: B_n = \sum_{k=0}^{n-1} \binom{n-1}{k} B_k.

They are also given by:

.. math:: B_n = \frac{1}{e} \sum_{k=0}^{\infty} \frac{k^n}{k!}.

The Bell polynomials are given by `B_0(x) = 1` and

.. math:: B_n(x) = x \sum_{k=1}^{n-1} \binom{n-1}{k-1} B_{k-1}(x).

The second kind of Bell polynomials (are sometimes called "partial" Bell
polynomials or incomplete Bell polynomials) are defined as

.. math:: B_{n,k}(x_1, x_2,\dotsc x_{n-k+1}) =
        \sum_{j_1+j_2+j_2+\dotsb=k \atop j_1+2j_2+3j_2+\dotsb=n}
            \frac{n!}{j_1!j_2!\dotsb j_{n-k+1}!}
            \left(\frac{x_1}{1!} \right)^{j_1}
            \left(\frac{x_2}{2!} \right)^{j_2} \dotsb
            \left(\frac{x_{n-k+1}}{(n-k+1)!} \right) ^{j_{n-k+1}}.

* ``bell(n)`` gives the `n^{th}` Bell number, `B_n`.
* ``bell(n, x)`` gives the `n^{th}` Bell polynomial, `B_n(x)`.
* ``bell(n, k, (x1, x2, ...))`` gives Bell polynomials of the second kind,
  `B_{n,k}(x_1, x_2, \dotsc, x_{n-k+1})`.

Notes
=====

Not to be confused with Bernoulli numbers and Bernoulli polynomials,
which use the same notation.

Examples
========

>>> from sympy import bell, Symbol, symbols

>>> [bell(n) for n in range(11)]
[1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975]
>>> bell(30)
846749014511809332450147
>>> bell(4, Symbol('t'))
t**4 + 6*t**3 + 7*t**2 + t
>>> bell(6, 2, symbols('x:6')[1:])
6*x1*x5 + 15*x2*x4 + 10*x3**2

See Also
========

bernoulli, catalan, euler, fibonacci, harmonic, lucas, genocchi, partition, tribonacci

References
==========

.. [1] https://en.wikipedia.org/wiki/Bell_number
.. [2] https://mathworld.wolfram.com/BellNumber.html
.. [3] https://mathworld.wolfram.com/BellPolynomial.html

c                	óŠ   € ^p^p\        ^V 4       F.  pW0V,
          ,          V,          pW#W,          ,          ,          pK0  	  V# rB   )rD   ©rT   r~   rÐ   rE   Úks   &&   rG   Ú_bellÚ
bell._bell¢  sC   € ð ˆØˆÜ�q˜!–ˆAØ˜•U•˜qÕ ˆAØ�T•W•ÕŠAñ ð ˆrI   c                	óê   € ^p^p\        ^V ^,           4       FC  pW0V,
          ^,           ,          V^,
          ,          pW#W^,
          ,          ,          ,          pKE  	  \        \        V,          4      # rB   )rD   r   r{   r  s   &&   rG   Ú
_bell_polyÚbell._bell_poly¬  s]   € ð ˆØˆÜ�q˜!˜a�%–ˆAØ˜•U˜Q•Y• A¨¥EÕ*ˆAØ�T˜a�%•[•Õ ŠAñ !ô œ$ �(Ó#Ð#rI   c                óÆ  € V ^ 8X  d   V^ 8X  d   \         P                  # V ^ 8X  g   V^ 8X  d   \         P                  # \         P                  p\         P                  p\        ^W,
          ^,           4       F^  pW4\        P                  W,
          V^,
          V4      ,          W%^,
          ,          ,          ,          pW@V,
          ,          V,          pK`  	  \        V4      # )aT  
The second kind of Bell polynomials (incomplete Bell polynomials).

Calculated by recurrence formula:

.. math:: B_{n,k}(x_1, x_2, \dotsc, x_{n-k+1}) =
        \sum_{m=1}^{n-k+1}
        \x_m \binom{n-1}{m-1} B_{n-m,k-1}(x_1, x_2, \dotsc, x_{n-m-k})

where
    `B_{0,0} = 1;`
    `B_{n,0} = 0; for n \ge 1`
    `B_{0,k} = 0; for k \ge 1`

)r   r£   rÊ   rD   r  Ú_bell_incomplete_polyr   )rT   r  ÚsymbolsrÐ   rE   Úms   &&&   rG   r  Úbell._bell_incomplete_poly¶  s«   € ð" �ŒF˜˜aœÜ—5‘5ˆLØ�1Œf˜!˜qœ&Ü—6‘6ˆMÜ�F‰FˆÜ�E‰EˆÜ�q˜!�% !�)Ö$ˆAØ”T×/Ñ/Ø•�q˜1•u˜gó'õ 'Ø)0°Qµ­õ8õ 8ˆAà˜•U•˜a•ŠAñ %ô ˜!‹}ÐrI   Nc                	ó  € V\         P                  J d    Vf   \         P                  # \        R4      hVP                  '       g   VP                  RJ d   \        R4      hVP
                  '       d•   VP                  '       d�   Vf$   \        V P                  \        V4      4      4      # Vf/   V P                  \        V4      4      P                  \        V4      # V P                  \        V4      \        V4      V4      pV# R # R # )NzBell polynomial is not definedFza non-negative integer expected)r   r‚   r†   Úis_negativerÖ   rƒ   r×   r   r  r„   r
  r‡   r{   r  )r‰   rT   Úk_symr  Úrs   &&&& rG   r‹   Ú	bell.evalÓ  sÆ   € à”—
‘
‹?ØŠ}Ü—z‘zÐ!ä Ð!AÓBÐBà�=�=ˆ=˜AŸL™L¨EÓ1ÜÐ>Ó?Ð?à�<�<ˆ<˜A×,×,Ð,ØŠ}Ü˜sŸy™y¬¨Q«Ó0Ó1Ð1Ø’Ø—~‘~¤c¨!£fÓ-×2Ñ2´4¸Ó?Ð?à×-Ñ-¬c°!«f´c¸%³jÀ'ÓJ�Ø�ñ -‰<rI   c                	óê   € ^ RI Hp Vf   Ve   V # VP                  '       g   V # \        RRRR7      p^\        ,          V! Wa,          \        V4      ,          V^ \        P                  34      ,          # )rŽ   ©ÚSumr  T)ÚintegerÚnonnegative)Úsympy.concrete.summationsr  r×   r	   r   r#   r   r‚   )r”   rT   r  r  r•   r  r  s   &&&&,  rG   Ú_eval_rewrite_as_SumÚbell._eval_rewrite_as_Sumç  sb   € Ý1ØÒ 7Ò#6ØˆKð ××ÐØˆKÜ�#˜t°Ô6ˆØ”1�u‘s˜1�4¤)¨A£,Õ.°°A´q·z±zÐ0BÓCÕCÐCrI   rg   ©NN)rh   ri   rj   rk   rl   rm   r<   r  r   r£   r{   r
  r  r¤   r‹   r  rn   rg   rI   rG   r  r  a  sŠ   † ñ>ð@ Ù�a˜�VÓñó ó ðð Ù�a—e‘e˜T�]Ó#ñ$ó $ó ð$ð ñó ðð8 óó ð÷&	Dð 	DrI   r  c                  ó¼   € ] tR tRt$ Rt/ tR]R&   ]RR l4       t]	P                  3R ltRR ltRR	 ltRR
 lt]	P                  3R ltR tRR ltR tRR ltRtR# )Úharmoniciú  a,  
Harmonic numbers

The nth harmonic number is given by `\operatorname{H}_{n} =
1 + \frac{1}{2} + \frac{1}{3} + \ldots + \frac{1}{n}`.

More generally:

.. math:: \operatorname{H}_{n,m} = \sum_{k=1}^{n} \frac{1}{k^m}

As `n \rightarrow \infty`, `\operatorname{H}_{n,m} \rightarrow \zeta(m)`,
the Riemann zeta function.

* ``harmonic(n)`` gives the nth harmonic number, `\operatorname{H}_n`

* ``harmonic(n, m)`` gives the nth generalized harmonic number
  of order `m`, `\operatorname{H}_{n,m}`, where
  ``harmonic(n) == harmonic(n, 1)``

This function can be extended to complex `n` and `m` where `n` is not a
negative integer or `m` is a nonpositive integer as

.. math:: \operatorname{H}_{n,m} = \begin{cases} \zeta(m) - \zeta(m, n+1)
        & m \ne 1 \\ \psi(n+1) + \gamma & m = 1 \end{cases}

Examples
========

>>> from sympy import harmonic, oo

>>> [harmonic(n) for n in range(6)]
[0, 1, 3/2, 11/6, 25/12, 137/60]
>>> [harmonic(n, 2) for n in range(6)]
[0, 1, 5/4, 49/36, 205/144, 5269/3600]
>>> harmonic(oo, 2)
pi**2/6

>>> from sympy import Symbol, Sum
>>> n = Symbol("n")

>>> harmonic(n).rewrite(Sum)
Sum(1/_k, (_k, 1, n))

We can evaluate harmonic numbers for all integral and positive
rational arguments:

>>> from sympy import S, expand_func, simplify
>>> harmonic(8)
761/280
>>> harmonic(11)
83711/27720

>>> H = harmonic(1/S(3))
>>> H
harmonic(1/3)
>>> He = expand_func(H)
>>> He
-log(6) - sqrt(3)*pi/6 + 2*Sum(log(sin(_k*pi/3))*cos(2*_k*pi/3), (_k, 1, 1))
                       + 3*Sum(1/(3*_k + 1), (_k, 0, 0))
>>> He.doit()
-log(6) - sqrt(3)*pi/6 - log(sqrt(3)/2) + 3
>>> H = harmonic(25/S(7))
>>> He = simplify(expand_func(H).doit())
>>> He
log(sin(2*pi/7)**(2*cos(16*pi/7))/(14*sin(pi/7)**(2*cos(pi/7))*cos(pi/14)**(2*sin(pi/14)))) + pi*tan(pi/14)/2 + 30247/9900
>>> He.n(40)
1.983697455232980674869851942390639915940
>>> harmonic(25/S(7)).n(40)
1.983697455232980674869851942390639915940

We can rewrite harmonic numbers in terms of polygamma functions:

>>> from sympy import digamma, polygamma
>>> m = Symbol("m", integer=True, positive=True)

>>> harmonic(n).rewrite(digamma)
polygamma(0, n + 1) + EulerGamma

>>> harmonic(n).rewrite(polygamma)
polygamma(0, n + 1) + EulerGamma

>>> harmonic(n,3).rewrite(polygamma)
polygamma(2, n + 1)/2 + zeta(3)

>>> simplify(harmonic(n,m).rewrite(polygamma))
Piecewise((polygamma(0, n + 1) + EulerGamma, Eq(m, 1)),
(-(-1)**m*polygamma(m - 1, n + 1)/factorial(m - 1) + zeta(m), True))

Integer offsets in the argument can be pulled out:

>>> from sympy import expand_func

>>> expand_func(harmonic(n+4))
harmonic(n) + 1/(n + 4) + 1/(n + 3) + 1/(n + 2) + 1/(n + 1)

>>> expand_func(harmonic(n-4))
harmonic(n) - 1/(n - 1) - 1/(n - 2) - 1/(n - 3) - 1/n

Some limits can be computed as well:

>>> from sympy import limit, oo

>>> limit(harmonic(n), n, oo)
oo

>>> limit(harmonic(n, 2), n, oo)
pi**2/6

>>> limit(harmonic(n, 3), n, oo)
zeta(3)

For `m > 1`, `H_{n,m}` tends to `\zeta(m)` in the limit of infinite `n`:

>>> m = Symbol("m", positive=True)
>>> limit(harmonic(n, m+1), n, oo)
zeta(m + 1)

See Also
========

bell, bernoulli, catalan, euler, fibonacci, lucas, genocchi, partition, tribonacci

References
==========

.. [1] https://en.wikipedia.org/wiki/Harmonic_number
.. [2] https://functions.wolfram.com/GammaBetaErf/HarmonicNumber/
.. [3] https://functions.wolfram.com/GammaBetaErf/HarmonicNumber2/

z(dict[Integer, Callable[[int], Rational]]Úharmonic_cacheNc           	     	ó
  a€ ^ RI Hp S\        P                  J d	   V ! V4      # Sf   \        P                  oVP                  '       d   \        P
                  # SP                  '       d   V# V\        P                  J d}   SP                  '       d   \        P                  # \        S\        P                  4      '       d   \        P                  # \        S\        P                  4      '       d	   V! S4      # R# SP                  '       dR   SP                  '       d@   \        ^S,
          V^,           4      \        ^S,
          4      ,
          ^S,
          ,          # VP                  '       Ed   VP                  '       dU   SP                  RJ g   SP                  RJ d5   S\        P                  J d   \        P                  # \        P                  # VP                   '       d–   SP                  '       dW   SV P"                  9  d$   \%        ^ .4      V3R l4       pW@P"                  S&   V P"                  S,          ! \'        V4      4      # \)        V3R l\+        ^\'        V4      ^,           4       4       !  # R# R# )rŽ   ræ   NFc                ó\   <€ VR,          \         P                  V S,          ,          ,           # )rC   ry   )r   r£   )rT   r~   r  s   &&€rG   ÚfÚharmonic.eval.<locals>.f›  s   ø€ à#'¨¥8¬a¯e©e°a¸µd­lÕ#:Ð:rI   c              3  ó6   <"  € T F  qS) ,          x € K  	  R # 5irr   rg   )rð   r  r  s   & €rG   rñ   Ú harmonic.eval.<locals>.<genexpr>   s   øé € ÐCÑ.B¨ ! ŸWšWÓ.Bùs   ƒ)rè   rç   r   r£   rÕ   rÊ   r‚   r  rÙ   r   r   rƒ   rØ   rÌ   rÖ   ÚComplexInfinityr×   r!  r<   r„   r   rD   )r‰   rT   r  rç   r$  s   &&f  rG   r‹   Úharmonic.eval�  s±  ø€ å?Ø”—‘‹:Ù�q“6ˆMØŠ9Ü—‘ˆAØ�9�9ˆ9Ü—6‘6ˆMØ�Y�YˆYØˆHØ”!—*‘*‹_Ø�}�}ˆ}Ü—u‘u�Ü�qœ!Ÿ%™%—’Ü—z‘zÐ!Ü�qœ!Ÿ%™%—’Ù˜A“w�ñ !à�\�\ˆ\˜a×.×.Ð.Ü˜a �c 1 Q¥3Ó'¬)°A°aµC«.Õ8¸Q¸q½SÕAÐAØ�\�\‰\Ø�}�}ˆ} !§,¡,°%Ó"7¸1×;KÑ;KÈuÓ;TØ,-´·±«J”q×(Ñ(ÐA¼A¿E¹EÐAØ××ÐØ—<—<�<Ø × 2Ñ 2Ô2Ü(¨!¨Ó-ô;ó .ð;à01×*Ñ*¨1Ñ-Ø×-Ñ-¨aÖ0´°Q³Ó8Ð8ÜÔC¬e°A´s¸1³vÀµzÔ.BÓCÑDÐDñ  ñ rI   c           
     	ó‚  € ^ RI HpHp VP                  '       d¥   VP                  '       d‘   \        V! ^ V^,           4      \        P                  ,           \        V^4      3\        P                  V,          V! V^,
          ^4      V! V^,
          V^,           4      ,
          ,          V! V4      ,          R34      # R# R# )rŽ   )ÚgammaÚ	polygammaTN)
Ú'sympy.functions.special.gamma_functionsr+  r,  rÖ   rÛ   r'   r   Ú
EulerGammar   r…   )r”   rT   r  r•   r+  r,  s   &&&,  rG   Ú_eval_rewrite_as_polygammaÚ#harmonic._eval_rewrite_as_polygamma¢  s�   € ßLØ�<�<ˆ<˜AŸMŸM˜MÜ™i¨¨1¨Q­3Ó/´!·,±,Õ>ÄÀ1ÀaÃÐIÜ—]‘] AÕ%©°1°Qµ3¸Ó):¹YÀqÈÅsÈAÈaÍCÓ=PÕ)PÕQÙ˜!“HõØ"ð$ó%ð %ñ *‰<rI   c                	ó0   € ^ RI Hp V P                  V4      # ©rŽ   ©r,  ©r-  r,  Úrewrite©r”   rT   r  r•   r,  s   &&&, rG   Ú_eval_rewrite_as_digammaÚ!harmonic._eval_rewrite_as_digamma©  ó   € ÝEØ�|‰|˜IÓ&Ð&rI   c                	ó0   € ^ RI Hp V P                  V4      # r2  r4  r6  s   &&&, rG   Ú_eval_rewrite_as_trigammaÚ"harmonic._eval_rewrite_as_trigamma­  r9  rI   c                	óv   € ^ RI Hp \        RRR7      pVf   \        P                  pV! WR) ,          V^V34      # )rŽ   r  r  T©r  )r  r  r	   r   r£   )r”   rT   r  r•   r  r  s   &&&,  rG   r  Úharmonic._eval_rewrite_as_Sum±  s6   € Ý1Ü�#˜tÔ$ˆØŠ9Ü—‘ˆAÙ�1�r•7˜Q  1˜IÓ&Ð&rI   c           	     	óÆ   € ^ RI Hp ^ RIHp \	        V! V^,           4      \
        P                  ,           \        V^4      3V! V4      V! W!^,           4      ,
          R34      # )rŽ   ræ   ©ÚdigammaT)rè   rç   r-  rB  r'   r   r.  r   )r”   rT   r  r•   rç   rB  s   &&&,  rG   ré   Úharmonic._eval_rewrite_as_zeta¸  sL   € Ý?ÝCÜ™' ! a¥%›.¬1¯<©<Õ7¼¸A¸q»ÐBÙ˜q›'¡D¨¨a­C£LÕ0°$Ð7ó9ð 	9rI   c                	óN  € ^ RI Hp V P                  ^ ,          p\        V P                  4      ^8X  d   V P                  ^,          M^pV\        P
                  8X  Ed½   VP                  '       Ed	   VP                  ^ ,          pW5,
          pVP                  '       de   VP                  '       dS   \        V^ R4       Uu. uF   p\        P
                  Wg,           ,          NK"  	  up\        V4      .,           p\        V!  # VP                  '       df   VP                  '       dT   \        ^ VR4       Uu. uF!  p\        P
                  ) Wg,           ,          NK#  	  up\        V4      .,           p\        V!  # VP                  '       Ed�   VP                  4       w  ršWš,          pW›V
,          ,
          p	VP                  '       EdS   V	P                  '       Ed@   V
P                  '       Ed-   Wš8  Ed&   ^ RIHp ^ RIHp ^ RIHpHpHp \1        R4      pW¢! ^V
V,          V	,           ,          V^ V34      ,          p^V! V! ^\2        ,          V	,          V,          \	        V
4      ,          4      V! V! \2        V,          \	        V
4      ,          4      4      ,          V^V! V
^,
          \	        ^4      ,          4      34      ,          p\2        ^,          V! \2        V	,          V
,          4      ,          V! ^V
,          4      ,           pVV,           V,
          # V # u upi u upi )rŽ   r  r%   rÃ   )Úsinr�   Úcotr  ry   )r  r  rÍ   rø   r   r£   Úis_Addrƒ   rÛ   rD   r   r   r  Úis_RationalÚas_numer_denomr×   Ú&sympy.functions.elementary.exponentialr&   rÅ   rÄ   Ú(sympy.functions.elementary.trigonometricrE  r�   rF  r	   r   )r”   Úhintsr  rT   r  ÚoffÚnnewrã   ÚresultrX   rà   Úur&   rÄ   rE  r�   rF  r  Út1Út2Út3s   &,                   rG   Ú_eval_expand_funcÚharmonic._eval_expand_func¾  s:  € Ý1Ø�I‰I�a�LˆÜ §	¡	›N¨aÔ/ˆD�I‰I�aŽL°Qˆà”—‘�:Ø�x�x‰xØ—f‘f˜Q•i�Ø•w�Ø—>—>�> c§o§o oÜ8=¸cÀ1ÀbÔ8IÓJÑ8I°1œaŸe™e T¥X×.Ð.Ñ8IÑJÌhÐW[ËnÐM]Õ]�FÜ ™<Ð'Ø—^—^�^¨¯¯¨Ü9>¸qÀ#ÀrÔ9JÓKÑ9J°AœqŸu™u˜f d¥h×/Ð/Ñ9JÑKÌxÐX\Ë~ÐN^Õ^�FÜ ™<Ð'à�}�}‰}ð ×'Ñ'Ó)‘�Ø•F�Ø˜A�•I�Ø×#×#Ñ#¨¯¯©¸!¿-¿-¹-ÈAÍEÝJÝIßVÑVÜ˜c›
�AØ˜S  a¨!¥e¨a¥i¥°1°a¸°)Ó<Õ<�BØ™S¡ a¬"¥f¨q¥j°1¥n¼¸!»Õ%<Ó!=Ù#&¡s¬B°­F´a¸³d­?Ó';Ó#<õ"=à$% q©%°°Qµ¼!¸A»$µÓ*?Ð#@óBõ B�Bô ˜q�&¡C¬¨a­°1­Ó$5Õ5¹¸AÀ½E»
ÕB�BØ �7 R�<Ð'àˆùò1 Kùò Ls   Ã &LÄ6'L"c                	ó>  € ^ RI Hp ^ RIHp V P	                  V4      p\        V\        4      '       g   VP	                  RRR7      # V\        P                  ,
          pVP                  '       d.   V! V4      V! W!^,           4      ,
          P	                  RRR7      # R# )rŽ   ræ   r3  Ú	tractableT)ÚdeepN)
rè   rç   r-  r,  r5  Ú
isinstancer   r   r£   Ú
is_nonzero)	r”   rT   r  Úlimitvarr•   rç   r,  ÚpgÚargs	   &&&&,    rG   r–   Ú#harmonic._eval_rewrite_as_tractableâ  sx   € Ý?ÝEØ�\‰\˜)Ó$ˆÜ˜"œh×'Ò'Ø—:‘:˜k°�:Ó5Ð5Ø”!—%‘%�iˆØ�>�>ˆ>Ù˜“G™d 1¨¥c›lÕ*×3Ñ3°KÀdÐ3ÓKÐKñ rI   c                	ó  € \         ;QJ d&    R  V P                   4       F  '       d   K   RM	  RM! R  V P                   4       4      '       g   R# V P                  ^ ,          P                  V4      p\        V P                  4      ^8”  d   V P                  ^,          M\        P
                  P                  V4      p\        P                  ! V4      '       d   V^ 8  d   \        P                  # \        V4      ;_uu_ 4        V^8X  d   \        P                  ! V4      pM8\        P                  ! V4      \        P                  ! W2^,           4      ,
          pRRR4       \        P                  ! XV4      #   + '       g   i     L'; i)c              3  ó8   "  € T F  qP                   x € K  	  R # 5irr   rí   rï   s   & rG   rñ   Ú'harmonic._eval_evalf.<locals>.<genexpr>í  ró   rô   FTN)rö   rÍ   r÷   rø   r   r£   r>   rú   rÙ   r?   r   rç   r   rü   )r”   rý   rT   r  rþ   s   &&   rG   rÿ   Úharmonic._eval_evalfì  sì   € ß‹sÑ2¨¯	ª	Ó2�s�sŠsÑ2¨¯	ª	Ó2×2Ò2ÙØ�I‰I�a�L×#Ñ# DÓ)ˆÜ  §¡›^¨aÔ/ˆT�Y‰Y�qŽ\´Q·U±U×FÑFÀtÓLˆÜ�8Š8�A�;Š;˜1˜qœ5Ü—5‘5ˆLÜ�d�^�^Ø�AŒvÜ—k’k !“n‘ä—g’g˜a“j¤2§7¢7¨1°­c£?Õ2�÷	 ô
 × Ò   dÓ+Ð+÷ �^ús   ÄAE;Å;F	c                	óÞ   € ^ RI Hp \        V P                  4      ^8X  d   V P                  w  r4MV P                  R,           w  r4V^8X  d   WB! V^,           V^,           4      ,          # \        h)rŽ   ræ   rB   )rè   rç   rø   rÍ   r   )r”   Úargindexrç   rT   r  s   &&   rG   ÚfdiffÚharmonic.fdiffú  sX   € Ý?Üˆt�y‰y‹>˜QÔØ—9‘9‰DˆAˆqà—9‘9˜tÕ#‰DˆAØ�qŒ=Ø�t˜A˜a�C  1¥“~Õ%Ð%ä$Ð$rI   rg   rr   rB   r¨   )rh   ri   rj   rk   rl   r!  r  r¤   r‹   r   r£   r/  r7  r;  r  ré   rT  r–   rÿ   re  rn   rg   rI   rG   r   r   ú  ss   ‡ ñAðH @B€NÐ<ÓAàóEó ðEð@ /0¯e©eô %ô'ô'ô'ð *+¯©ô 9ò"ôHLò,÷	%ð 	%rI   r   c                  óH   € ] tR tRtRt]R	R l4       tR	R ltR	R ltR t	Rt
R# )
Úeuleri  aL  
Euler numbers / Euler polynomials / Euler function

The Euler numbers are given by:

.. math:: E_{2n} = I \sum_{k=1}^{2n+1} \sum_{j=0}^k \binom{k}{j}
    \frac{(-1)^j (k-2j)^{2n+1}}{2^k I^k k}

.. math:: E_{2n+1} = 0

Euler numbers and Euler polynomials are related by

.. math:: E_n = 2^n E_n\left(\frac{1}{2}\right).

We compute symbolic Euler polynomials using Appell sequences,
but numerical evaluation of the Euler polynomial is computed
more efficiently (and more accurately) using the mpmath library.

The Euler polynomials are special cases of the generalized Euler function,
related to the Genocchi function as

.. math:: \operatorname{E}(s, a) = -\frac{\operatorname{G}(s+1, a)}{s+1}

with the limit of `\psi\left(\frac{a+1}{2}\right) - \psi\left(\frac{a}{2}\right)`
being taken when `s = -1`. The (ordinary) Euler function interpolating
the Euler numbers is then obtained as
`\operatorname{E}(s) = 2^s \operatorname{E}\left(s, \frac{1}{2}\right)`.

* ``euler(n)`` gives the nth Euler number `E_n`.
* ``euler(s)`` gives the Euler function `\operatorname{E}(s)`.
* ``euler(n, x)`` gives the nth Euler polynomial `E_n(x)`.
* ``euler(s, a)`` gives the generalized Euler function `\operatorname{E}(s, a)`.

Examples
========

>>> from sympy import euler, Symbol, S
>>> [euler(n) for n in range(10)]
[1, 0, -1, 0, 5, 0, -61, 0, 1385, 0]
>>> [2**n*euler(n,1) for n in range(10)]
[1, 1, 0, -2, 0, 16, 0, -272, 0, 7936]
>>> n = Symbol("n")
>>> euler(n + 2*n)
euler(3*n)

>>> x = Symbol("x")
>>> euler(n, x)
euler(n, x)

>>> euler(0, x)
1
>>> euler(1, x)
x - 1/2
>>> euler(2, x)
x**2 - x
>>> euler(3, x)
x**3 - 3*x**2/2 + 1/4
>>> euler(4, x)
x**4 - 2*x**3 + x

>>> euler(12, S.Half)
2702765/4096
>>> euler(12)
2702765

See Also
========

andre, bell, bernoulli, catalan, fibonacci, harmonic, lucas, genocchi,
partition, tribonacci, sympy.polys.appellseqs.euler_poly

References
==========

.. [1] https://en.wikipedia.org/wiki/Euler_numbers
.. [2] https://mathworld.wolfram.com/EulerNumber.html
.. [3] https://en.wikipedia.org/wiki/Alternating_permutation
.. [4] https://mathworld.wolfram.com/AlternatingPermutation.html

Nc                	ó  € VP                   '       d   \        P                  # V\        P                  J dL   Vf   \        P                  ^,          # ^ RIHp V! V^,           ^,          4      V! V^,          4      ,
          # VP                  RJ g   VP                  RJ d   R # Vf‰   VP                  '       d#   VP                  '       d   \        P                  # VP                  '       dA   ^ RIHp VP                  VP                   4      pVP"                  ! VRR7      p\%        V4      # R # VP                  '       Ed&   ^ RIHp \+        V4      pV! VRR7      pV'       dø   \,        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       d¾   \.        ;QJ d    R	 V 4       F  '       g   K   RM	  RM! R	 V 4       4      '       d„   ^ RIHp \1        V Uu. uF"  qˆP2                  '       g   K  VP4                  NK$  	  up4      p	\7        V	4      ;_uu_ 4        VP8                  ! W4      pR R R 4       \:        P<                  ! XV	4      # \?        W4      # R # u upi   + '       g   i     L9; i)
NrA  F©r>   T)Úexact)Úpure_complex)Úor_realc              3  ó`   "  € T F$  qP                   ;'       g    VP                  x € K&  	  R # 5irr   )Úis_Floatrƒ   ©rð   rE   s   & rG   rñ   Úeuler.eval.<locals>.<genexpr>x  s!   é € ÐEÁ¸1ŸJ™J×6Ð6¨!¯,©,Ô6Ãùs   ‚.™.c              3  ó8   "  € T F  qP                   x € K  	  R # 5irr   )ro  rp  s   & rG   rñ   rq  y  s   é € Ð5±¨1ŸJžJ³ùrô   ) rÕ   r   r£   r…   r“   r-  rB  rÖ   r×   rÚ   rÛ   rÊ   rÜ   Úmpmathr>   r÷   rý   Úeulernumr   Úsympy.core.evalfrl  r„   rö   ÚanyÚminro  Ú_precr?   Ú	eulerpolyr   rü   r3   )
r‰   rT   rJ   rB  r>   rþ   rl  ÚreimrE   rý   s
   &&&       rG   r‹   Ú
euler.eval_  s¥  € à�9�9ˆ9Ü—5‘5ˆLØ”!—-‘-ÓØŠyÜ—t‘t˜A•v�ÝGÙ˜A˜a�C �7Ó#¡g¨a°­c£lÕ2Ð2Ø�\‰\˜UÓ" a×&6Ñ&6¸%Ó&?ÙàŠYØ�x�xˆx˜AŸMŸM˜MÜ—v‘v�Ø——�Ý%Ø—L‘L §¡Ó)�Ø—k’k !¨4Ô0�Ü˜s“|Ð#ñ	 ð �[�[‰[Ý5Ü�A“ˆAÙ ¨4Ô0ˆDßŸ›ÑEÁÓEŸŸšÑEÁÓE×EÒEß›Ñ5±Ó5ŸŸšÑ5±Ó5×5Ò5Ý%Ü©TÓ@©T¨·ZµZœG˜AŸGœG©TÑ@ÓA�Ü˜d—^•^ØŸ,š, qÓ,�C÷ $ä×(Ò(¨¨dÓ3Ð3Ü˜aÓ#Ð#ñ ùò Aß#—^ús   Ç)I*ÈI*È+I/É/I?	c           
     	óÜ  € ^ RI Hp Vfñ   VP                  '       dß   \        RRR7      p\        RRR7      pV^,          p\        P
                  V! V! \        WV4      \        P                  V,          V^V,          ,
          ^V,          ^,           ,          ,          ,          ^V,          \        P
                  V,          ,          V,          ,          V^ V34      V^^V,          ^,           34      ,          pV# V'       dj   \        RRR7      pV! \        W4      \        V4      ,          ^V,          ,          V\        P                  ,
          W,
          ,          ,          V^ V34      # R# )rŽ   r  Nr  Tr>  rÑ   )
r  r  Úis_evenr	   r   r½   r"   r…   rh  rÇ   )r”   rT   rJ   r•   r  r  rÑ   ÚEms   &&&,    rG   r  Úeuler._eval_rewrite_as_Sum�  s  € Ý1ØŠ9˜ŸŸ˜Ü�c 4Ô(ˆAÜ�c 4Ô(ˆAØ�A•ˆAÜ—/‘/¡C©¬H°Q«N¼a¿m¹mÈQÕ>NØ?@À1ÀQÅ3½wÈ!ÈAÍ#ÐPQÍ'Õ>Rõ?Sõ -Tà�a•4œŸ™¨Õ*Õ*¨QÕ.õ-0à23°Q¸°ó)<à>?ÀÀAÀaÅCÈ!ÅG¸_ó%Nõ NˆBð ˆIßÜ�c 4Ô(ˆAÙ”x “~¤e¨A£hÕ.¨q°!­tÕ3°Q¼¿¹µZÀ1Å5Õ4IÕIÈAÈqÐRSÈ9ÓUÐUñ rI   c                	ó°  € Vfl   \        \        P                  ^,          \        VR4      3^V,          ) \	        V^,           \        P
                  4      ,          V^,           ,          R34      # ^ RIHp \        V! V^,           ^,          4      V! V^,          4      ,
          \        VR4      3\	        V^,           V4      ) V^,           ,          R34      # )NTrA  ry   )r'   r   r“   r   ÚgenocchirÇ   r-  rB  )r”   rT   rJ   r•   rB  s   &&&, rG   Ú_eval_rewrite_as_genocchiÚeuler._eval_rewrite_as_genocchi�  s¬   € ØŠ9ÜœaŸd™d 1�f¤b¨¨B£iÐ0Ø  !�t˜e¤h¨q°­s´A·F±FÓ&;Õ;¸qÀ½sÕCÀTÐJóLð LåCÜ™' 1 Q¥3¨¥'Ó*©W°Q°qµS«\Õ9¼2¸aÀ»9ÐEÜ# A a¥C¨Ó+Ð+¨q°­sÕ3°TÐ:ó<ð 	<rI   c           
     	ó"  € \         ;QJ d&    R  V P                   4       F  '       d   K   RM	  RM! R  V P                   4       4      '       g   R# ^ RIHp \	        V P                  4      ^8X  d   V P                  ^ ,          R3MV P                  w  r4VP                  V4      pVe   VP                  V4      p\        V4      ;_uu_ 4        VP                  ! V4      '       d1   V^ 8¼  d*   Vf   VP                  ! V4      MVP                  ! W44      pMÉVR8X  dP   Vf   VP                  M=VP                  ! V^,           ^,          4      VP                  ! V^,          4      ,
          pM_Vf   RMTp^VP                  ! V) V4      ^V^,           ,          VP                  ! V) V^,           ^,          4      ,          ,
          ,          pVf   V^V,          ,          pRRR4       \        P                  ! XV4      #   + '       g   i     L'; i)c              3  ó8   "  € T F  qP                   x € K  	  R # 5irr   rí   ©rð   rã   s   & rG   rñ   Ú$euler._eval_evalf.<locals>.<genexpr>˜  ró   rô   FTNrj  rõ   ry   )rö   rÍ   rs  r>   rø   r÷   r?   rú   rt  ry  r   rB  rç   r   rü   )r”   rý   r>   r  rJ   rþ   rc   s   &&     rG   rÿ   Úeuler._eval_evalf—  sj  € ß‹sÑ2¨¯	ª	Ó2�s�sŠsÑ2¨¯	ª	Ó2×2Ò2ÙÝÜ'*¨4¯9©9£~¸Ô':�—	‘	˜!•˜dÑ#ÀÇ	Á	‰ˆØ�L‰L˜ÓˆØŠ=Ø—‘˜TÓ"ˆAÜ�d�^�^Ø�xŠx˜�{Š{˜q AœvØ()ª	�b—k’k !”n°r·|²|ÀAÓ7I‘à˜”7Ø#$¢9˜"Ÿ%š%°"·*²*¸aÀ½cÀ1½WÓ2EÈÏ
Ê
ÐSTÐUVÕSVËÕ2W‘Cà šy™¨a�AØ˜rŸwšw¨ r¨1›~°°A°aµCµ¸2¿7º7ÀAÀ2ÈÈ!ÍÈQÅwÓ;OÕ0OÕOÕP�CØ’9Ø˜1˜a�4•K�C÷ ô × Ò   dÓ+Ð+÷ �^ús   ÃDG>Ç>H	rg   rr   )rh   ri   rj   rk   rl   r¤   r‹   r  r‚  rÿ   rn   rg   rI   rG   rh  rh    s.   † ñOðb ó$ó ð$ôBVô<ö,rI   rh  c                  ón   € ] tR tRtRt]R 4       tRR ltR tR t	RR lt
R tR	 tR
 tR tR tR tRtR# )Úcatalani´  a}  
Catalan numbers

The `n^{th}` catalan number is given by:

.. math :: C_n = \frac{1}{n+1} \binom{2n}{n}

* ``catalan(n)`` gives the `n^{th}` Catalan number, `C_n`

Examples
========

>>> from sympy import (Symbol, binomial, gamma, hyper,
...     catalan, diff, combsimp, Rational, I)

>>> [catalan(i) for i in range(1,10)]
[1, 2, 5, 14, 42, 132, 429, 1430, 4862]

>>> n = Symbol("n", integer=True)

>>> catalan(n)
catalan(n)

Catalan numbers can be transformed into several other, identical
expressions involving other mathematical functions

>>> catalan(n).rewrite(binomial)
binomial(2*n, n)/(n + 1)

>>> catalan(n).rewrite(gamma)
4**n*gamma(n + 1/2)/(sqrt(pi)*gamma(n + 2))

>>> catalan(n).rewrite(hyper)
hyper((-n, 1 - n), (2,), 1)

For some non-integer values of n we can get closed form
expressions by rewriting in terms of gamma functions:

>>> catalan(Rational(1, 2)).rewrite(gamma)
8/(3*pi)

We can differentiate the Catalan numbers C(n) interpreted as a
continuous real function in n:

>>> diff(catalan(n), n)
(polygamma(0, n + 1/2) - polygamma(0, n + 2) + log(4))*catalan(n)

As a more advanced example consider the following ratio
between consecutive numbers:

>>> combsimp((catalan(n + 1)/catalan(n)).rewrite(binomial))
2*(2*n + 1)/(n + 2)

The Catalan numbers can be generalized to complex numbers:

>>> catalan(I).rewrite(gamma)
4**I*gamma(1/2 + I)/(sqrt(pi)*gamma(2 + I))

and evaluated with arbitrary precision:

>>> catalan(I).evalf(20)
0.39764993382373624267 - 0.020884341620842555705*I

See Also
========

andre, bell, bernoulli, euler, fibonacci, harmonic, lucas, genocchi,
partition, tribonacci, sympy.functions.combinatorial.factorials.binomial

References
==========

.. [1] https://en.wikipedia.org/wiki/Catalan_number
.. [2] https://mathworld.wolfram.com/CatalanNumber.html
.. [3] https://functions.wolfram.com/GammaBetaErf/CatalanNumber/
.. [4] http://geometer.org/mathcircles/catalan.pdf

c                	óB  € ^ RI Hp VP                  '       d   VP                  '       g%   VP                  '       dm   VP
                  '       d[   ^V,          V! V\        P                  ,           4      ,          V! \        P                  4      V! V^,           4      ,          ,          # VP                  '       de   VP
                  '       dQ   V^,           P
                  '       d   \        P                  # V^,           P                  '       d   \        R^4      # R# R# R# )rŽ   ©r+  Nry   )r-  r+  rƒ   r×   Úis_nonintegerr  r   rÇ   rÖ   rÊ   rÕ   r   )r‰   rT   r+  s   && rG   r‹   Úcatalan.eval  s¯   € åAØ�L�LˆL˜Q×-×-Ð-Ø�O�OˆO §§ Ø�a•4™˜a¤!§&¡&�jÓ)Õ)©5´·±«=¹¸qÀ1½u»Õ+EÕFÐFà�L�LˆL˜QŸ]Ÿ]˜]Ø�A•×"×"Ð"Ü—v‘v�Ø�A•��ˆÜ  A“Ð&ñ ñ +‰LrI   c                	óà   € ^ RI Hp ^ RIHp V P                  ^ ,          p\        V4      V! ^ V\        P                  ,           4      V! ^ V^,           4      ,
          V! ^4      ,           ,          # )rŽ   r%   r3  )rJ  r&   r-  r,  rÍ   rŠ  r   rÇ   )r”   rd  r&   r,  rT   s   &&   rG   re  Úcatalan.fdiff  sM   € Ý>ÝEØ�I‰I�a�LˆÜ�q‹z™9 Q¨¬A¯F©F­
Ó3±iÀÀ1ÀqÅ5Ó6IÕIÉCÐPQËFÕRÕSÐSrI   c                	óD   € \        ^V,          V4      V^,           ,          # ©rw   )r"   r    s   &&,rG   Ú_eval_rewrite_as_binomialÚ!catalan._eval_rewrite_as_binomial  s   € Ü˜˜!�˜QÓ  Q¥Õ'Ð'rI   c                	ót   € \        ^V,          4      \        V^,           4      \        V4      ,          ,          # r’  )r#   r    s   &&,rG   Ú_eval_rewrite_as_factorialÚ"catalan._eval_rewrite_as_factorial  s&   € Ü˜˜1�‹~¤¨1¨Q­3£´)¸A³,Õ!>Õ?Ð?rI   c                	óÂ   € ^ RI Hp ^V,          V! V\        P                  ,           4      ,          V! \        P                  4      V! V^,           4      ,          ,          # )rŽ   rŒ  )r-  r+  r   rÇ   )r”   rT   Ú	piecewiser•   r+  s   &&&, rG   Ú_eval_rewrite_as_gammaÚcatalan._eval_rewrite_as_gamma  s;   € ÝAà�!�t‘E˜!œaŸf™f�*Ó%Õ%¡u¬Q¯V©V£}±U¸1¸q½5³\Õ'AÕBÐBrI   c                	ó8   € ^ RI Hp V! ^V,
          V) .^.^4      # )rŽ   )Úhyper)Úsympy.functions.special.hyperr�  )r”   rT   r•   r�  s   &&, rG   Ú_eval_rewrite_as_hyperÚcatalan._eval_rewrite_as_hyper"  s    € Ý7Ù�a˜!•e˜a˜R�[ 1 # qÓ)Ð)rI   c                	ó¨   € ^ RI Hp VP                  '       d   VP                  '       g   V # \	        RRRR7      pV! W,           V,          V^V34      # )rŽ   )ÚProductr  T)r  Úpositive)Úsympy.concrete.productsr¢  rÖ   r×   r	   )r”   rT   r•   r¢  r  s   &&,  rG   Ú_eval_rewrite_as_ProductÚ catalan._eval_rewrite_as_Product&  sE   € Ý3Ø——� ×!1×!1Ð!1ØˆKÜ�#˜t¨dÔ3ˆÙ˜� •{ Q¨¨1 IÓ.Ð.rI   c                	óš   € V P                   ^ ,          P                  '       d(   V P                   ^ ,          P                  '       d   R# R# R# ©rŽ   TN©rÍ   rÖ   r×   ©r”   s   &rG   Ú_eval_is_integerÚcatalan._eval_is_integer-  s5   € Ø�9‰9�Q�<×"×"Ð" t§y¡y°¥|×'B×'BÐ'BÙñ (CÑ"rI   c                	óP   € V P                   ^ ,          P                  '       d   R# R# r¨  ©rÍ   r×   rª  s   &rG   Ú_eval_is_positiveÚcatalan._eval_is_positive1  ó   € Ø�9‰9�Q�<×&×&Ð&Ùñ 'rI   c                	ó¨   € V P                   ^ ,          P                  '       d/   V P                   ^ ,          ^,
          P                  '       d   R# R# R# r¨  )rÍ   rÖ   rÛ   rª  s   &rG   Ú_eval_is_compositeÚcatalan._eval_is_composite5  s:   € Ø�9‰9�Q�<×"×"Ð"¨¯	©	°!­°qÕ(8×'E×'EÐ'EÙñ (FÑ"rI   c                	ó˜   € ^ RI Hp V P                  ^ ,          P                  '       d!   V P	                  V4      P                  V4      # R# )rŽ   rŒ  N)r-  r+  rÍ   rî   r5  rÿ   )r”   rý   r+  s   && rG   rÿ   Úcatalan._eval_evalf9  s8   € ÝAØ�9‰9�Q�<×!×!Ð!Ø—<‘< Ó&×2Ñ2°4Ó8Ð8ñ "rI   rg   NrB   )T)rh   ri   rj   rk   rl   r¤   r‹   re  r“  r–  rš  rŸ  r¥  r«  r¯  r³  rÿ   rn   rg   rI   rG   rŠ  rŠ  ´  sR   † ñMð^ ñ
'ó ð
'ôTò(ò@ôCò
*ò/òòòö9rI   rŠ  c                  ól   € ] tR tRtRt]RR l4       tRR ltRR ltR t	R t
R	 tR
 tR tR tR tRtR# )r�  iF  aÑ  
Genocchi numbers / Genocchi polynomials / Genocchi function

The Genocchi numbers are a sequence of integers `G_n` that satisfy the
relation:

.. math:: \frac{-2t}{1 + e^{-t}} = \sum_{n=0}^\infty \frac{G_n t^n}{n!}

They are related to the Bernoulli numbers by

.. math:: G_n = 2 (1 - 2^n) B_n

and generalize like the Bernoulli numbers to the Genocchi polynomials and
function as

.. math:: \operatorname{G}(s, a) = 2 \left(\operatorname{B}(s, a) -
          2^s \operatorname{B}\left(s, \frac{a+1}{2}\right)\right)

.. versionchanged:: 1.12
    ``genocchi(1)`` gives `-1` instead of `1`.

Examples
========

>>> from sympy import genocchi, Symbol
>>> [genocchi(n) for n in range(9)]
[0, -1, -1, 0, 1, 0, -3, 0, 17]
>>> n = Symbol('n', integer=True, positive=True)
>>> genocchi(2*n + 1)
0
>>> x = Symbol('x')
>>> genocchi(4, x)
-4*x**3 + 6*x**2 - 1

See Also
========

bell, bernoulli, catalan, euler, fibonacci, harmonic, lucas, partition, tribonacci
sympy.polys.appellseqs.genocchi_poly

References
==========

.. [1] https://en.wikipedia.org/wiki/Genocchi_number
.. [2] https://mathworld.wolfram.com/GenocchiNumber.html
.. [3] Peter Luschny, "An introduction to the Bernoulli function",
       https://arxiv.org/abs/2009.06743

Nc                	óÂ  € V\         P                  J d	   V ! V4      # VP                  R J g   VP                  R J d   R# Vf€   VP                  '       d*   V^,
          P
                  '       d   \         P                  # VP                  '       d1   ^^\        ^4      V,          ,
          ,          \        V4      ,          # R# VP                  '       d   \        W4      # R# )FN)
r   r£   rÖ   r×   rÚ   rÛ   rÊ   rÜ   rÌ   r4   )r‰   rT   rJ   s   &&&rG   r‹   Úgenocchi.evaly  s    € à”—‘‹:Ù�q“6ˆMØ�\‰\˜UÓ" a×&6Ñ&6¸%Ó&?ÙàŠYØ�x�xˆx˜Q˜q�S×-×-Ð-Ü—v‘v�Ø——�Ø˜Aœa ›d A�g�I•¬°1«Õ5Ð5ñ ð �[�[ˆ[Ü  Ó&Ð&ñ rI   c                	ó4  € V^8X  dU   VP                   '       dC   VP                  '       d1   ^^\        ^4      V,          ,
          ,          \        V4      ,          # ^\        W4      ^V,          \        W^,           ^,          4      ,          ,
          ,          # rB   )rÖ   r×   r   rÌ   )r”   rT   rJ   r•   s   &&&,rG   Ú_eval_rewrite_as_bernoulliÚ#genocchi._eval_rewrite_as_bernoulli‰  se   € Ø�Œ6�a—l—l�l q×'7×'7Ð'7Ø˜œ!˜A›$ �'�	•?¤Y¨q£\Õ1Ð1Ø”I˜a“O a¨¥d¬Y°q¸Q½3À!½)Ó-DÕ&DÕDÕEÐErI   c                	óJ   € ^ RI Hp RV,          V! ^V,
          V4      ,          # )rŽ   )Údirichlet_etarx   )rè   r¾  )r”   rT   rJ   r•   r¾  s   &&&, rG   Ú_eval_rewrite_as_dirichlet_etaÚ'genocchi._eval_rewrite_as_dirichlet_etaŽ  s   € ÝHØ�!�t‘m A a¥C¨Ó+Õ+Ð+rI   c                	óä   € \        V P                  4      ^8”  d   V P                  ^,          ^8w  d   R# V P                  ^ ,          pVP                  '       d   VP                  '       d   R# R# R# )rC   NT)rø   rÍ   rÖ   r×   ©r”   rT   s   & rG   r«  Úgenocchi._eval_is_integer’  sO   € Üˆt�y‰y‹>˜AÔ $§)¡)¨A¥,°!Ô"3ÙØ�I‰I�a�LˆØ�<�<ˆ<˜A×,×,Ð,Ùñ -‰<rI   c                	ób  € \        V P                  4      ^8”  d   V P                  ^,          ^8w  d   R# V P                  ^ ,          pVP                  '       dV   VP                  '       dB   VP                  '       d   \        V^,
          P                  4      # V^,          P                  # R# R# r¨   )rø   rÍ   rÖ   r×   rÚ   r   rÛ   rÂ  s   & rG   Ú_eval_is_negativeÚgenocchi._eval_is_negative™  sx   € Üˆt�y‰y‹>˜AÔ $§)¡)¨A¥,°!Ô"3ÙØ�I‰I�a�LˆØ�<�<ˆ<˜A×,×,Ð,Ø�x�xˆxÜ  ! A¥#×!2Ñ!2Ó3Ð3Ø�a•C—<‘<Ðñ -‰<rI   c                	óR  € \        V P                  4      ^8”  d   V P                  ^,          ^8w  d   R# V P                  ^ ,          pVP                  '       dN   VP                  '       d:   VP                  '       g   VP
                  '       d   R# V^,          P                  # R# R# )rC   NF)rø   rÍ   rÖ   r×   rÕ   rÚ   r}  rÂ  s   & rG   r¯  Úgenocchi._eval_is_positive¢  sn   € Üˆt�y‰y‹>˜AÔ $§)¡)¨A¥,°!Ô"3ÙØ�I‰I�a�LˆØ�<�<ˆ<˜A×,×,Ð,Ø�y�yˆy˜AŸHŸH˜HÙØ�a•C—=‘=Ð ñ -‰<rI   c                	óB  € \        V P                  4      ^8”  d   V P                  ^,          ^8w  d   R# V P                  ^ ,          pVP                  '       dF   VP                  '       d2   VP                  '       d   VP
                  # V^,
          P                  # R# R# r¨   )rø   rÍ   rÖ   r×   r}  rÕ   rÛ   rÂ  s   & rG   Ú_eval_is_evenÚgenocchi._eval_is_even«  so   € Üˆt�y‰y‹>˜AÔ $§)¡)¨A¥,°!Ô"3ÙØ�I‰I�a�LˆØ�<�<ˆ<˜A×,×,Ð,Ø�y�yˆyØ—y‘yÐ Ø�a•C×$Ñ$Ð$ñ -‰<rI   c                	óf  € \        V P                  4      ^8”  d   V P                  ^,          ^8w  d   R# V P                  ^ ,          pVP                  '       dX   VP                  '       dD   VP                  '       d   \        VP                  4      # \        V^,
          P                  4      # R# R# r¨   )rø   rÍ   rÖ   r×   r}  r   rÕ   rÛ   rÂ  s   & rG   Ú_eval_is_oddÚgenocchi._eval_is_odd´  sy   € Üˆt�y‰y‹>˜AÔ $§)¡)¨A¥,°!Ô"3ÙØ�I‰I�a�LˆØ�<�<ˆ<˜A×,×,Ð,Ø�y�yˆyÜ  §¡Ó+Ð+Ü˜a �c×.Ñ.Ó/Ð/ñ -‰<rI   c                	ó¶   € \        V P                  4      ^8”  d   V P                  ^,          ^8w  d   R# V P                  ^ ,          pV^,
          P                  # r¨   )rø   rÍ   rÕ   rÂ  s   & rG   Ú_eval_is_primeÚgenocchi._eval_is_prime½  sA   € Üˆt�y‰y‹>˜AÔ $§)¡)¨A¥,°!Ô"3ÙØ�I‰I�a�Lˆð �!•�}‰}ÐrI   c                	óê   € \         ;QJ d&    R  V P                   4       F  '       d   K   RM	  RM! R  V P                   4       4      '       d%   V P                  \        4      P	                  V4      # R# )c              3  ó8   "  € T F  qP                   x € K  	  R # 5irr   rí   r†  s   & rG   rñ   Ú'genocchi._eval_evalf.<locals>.<genexpr>Ç  s   é € Ð.¡I˜q�{Ž{£Iùrô   FTN)rö   rÍ   r5  rÌ   rÿ   )r”   rý   s   &&rG   rÿ   Úgenocchi._eval_evalfÆ  sJ   € ß‹3Ñ. D§I¢IÓ.�3�3Š3Ñ. D§I¢IÓ.×.Ò.Ø—<‘<¤	Ó*×6Ñ6°tÓ<Ð<ñ /rI   rg   rr   rB   )rh   ri   rj   rk   rl   r¤   r‹   r»  r¿  r«  rÅ  r¯  rÊ  rÍ  rÐ  rÿ   rn   rg   rI   rG   r�  r�  F  sJ   † ñ0ðd ó'ó ð'ôFô
,òò ò!ò%ò0òö=rI   r�  c                  óH   € ] tR tRtRt]R 4       tR tR tR t	R t
R tR	tR
# )ÚandreiÒ  a  
Andre numbers / Andre function

The Andre number `\mathcal{A}_n` is Luschny's name for half the number of
*alternating permutations* on `n` elements, where a permutation is alternating
if adjacent elements alternately compare "greater" and "smaller" going from
left to right. For example, `2 < 3 > 1 < 4` is an alternating permutation.

This sequence is A000111 in the OEIS, which assigns the names *up/down numbers*
and *Euler zigzag numbers*. It satisfies a recurrence relation similar to that
for the Catalan numbers, with `\mathcal{A}_0 = 1` and

.. math:: 2 \mathcal{A}_{n+1} = \sum_{k=0}^n \binom{n}{k} \mathcal{A}_k \mathcal{A}_{n-k}

The Bernoulli and Euler numbers are signed transformations of the odd- and
even-indexed elements of this sequence respectively:

.. math :: \operatorname{B}_{2k} = \frac{2k \mathcal{A}_{2k-1}}{(-4)^k - (-16)^k}

.. math :: \operatorname{E}_{2k} = (-1)^k \mathcal{A}_{2k}

Like the Bernoulli and Euler numbers, the Andre numbers are interpolated by the
entire Andre function:

.. math :: \mathcal{A}(s) = (-i)^{s+1} \operatorname{Li}_{-s}(i) +
        i^{s+1} \operatorname{Li}_{-s}(-i) = \\ \frac{2 \Gamma(s+1)}{(2\pi)^{s+1}}
        (\zeta(s+1, 1/4) - \zeta(s+1, 3/4) \cos{\pi s})

Examples
========

>>> from sympy import andre, euler, bernoulli
>>> [andre(n) for n in range(11)]
[1, 1, 1, 2, 5, 16, 61, 272, 1385, 7936, 50521]
>>> [(-1)**k * andre(2*k) for k in range(7)]
[1, -1, 5, -61, 1385, -50521, 2702765]
>>> [euler(2*k) for k in range(7)]
[1, -1, 5, -61, 1385, -50521, 2702765]
>>> [andre(2*k-1) * (2*k) / ((-4)**k - (-16)**k) for k in range(1, 8)]
[1/6, -1/30, 1/42, -1/30, 5/66, -691/2730, 7/6]
>>> [bernoulli(2*k) for k in range(1, 8)]
[1/6, -1/30, 1/42, -1/30, 5/66, -691/2730, 7/6]

See Also
========

bernoulli, catalan, euler, sympy.polys.appellseqs.andre_poly

References
==========

.. [1] https://en.wikipedia.org/wiki/Alternating_permutation
.. [2] https://mathworld.wolfram.com/EulerZigzagNumber.html
.. [3] Peter Luschny, "An introduction to the Bernoulli function",
       https://arxiv.org/abs/2009.06743
c                	óš  € V\         P                  J d   \         P                  # V\         P                  J d   \         P                  # VP                  '       d   \         P                  # VR8X  d   \        ^4      ) # VR8X  d   R\         P                  ,          # VP                  '       dž   VP                  '       d'   VP                  '       d   \        \        V4      4      # VP                  '       dR   ^ RIHp V) ^,
          p\        V,          \!        ^^V,          ,
          ^V,          4      ,          V! V) 4      ,          # R# R# )rC   ræ   Nry   rx   )r   rÙ   r‚   rÕ   r£   r&   ÚCatalanrƒ   r×   r}  Úabsrh  rÚ   rè   rç   r   r   )r‰   rT   rç   r  s   &&  rG   r‹   Ú
andre.eval  sÝ   € à”—‘‹:Ü—5‘5ˆLØ”!—*‘*‹_Ü—:‘:ÐØ�9�9ˆ9Ü—5‘5ˆLØ�"ŒWÜ˜“F�7ˆNØ�"ŒWØ”a—i‘i•<ÐØ�\�\ˆ\Ø××Ð A§I§I IÜœ5 ›8“}Ð$Ø——�ÝGØ�B�q•D�Ü˜!•tœh q¨¨A­¥v¨q°!­tÓ4Õ4±t¸Q¸B³xÕ?Ð?ñ ñ rI   c           	     	ó`  € ^ RI Hp ^ RIHp ^ RIHp ^V! V^,           4      ,          ^\        ,          V^,           ,          ,          V! V^,           \        P                  ^,          4      V! \        V,          4      V! V^,           \        ^4      ^,          4      ,          ,
          ,          # )rŽ   )r�   rŒ  ræ   )	rK  r�   r-  r+  rè   rç   r   r   r£   )r”   rÐ   r•   r�   r+  rç   s   &&,   rG   ré   Úandre._eval_rewrite_as_zeta   sr   € Ý@ÝAÝ?Ø‘5˜˜1�“:�~ ¤2¥¨¨1­¥Õ-Ù�a˜•cœ1Ÿ5™5 �7Ó#¡c¬"¨Q­$£i±$°q¸µs¼A¸a»DÀ½FÓ2CÕ&CÕCõEð 	ErI   c                	ó¸   € ^ RI Hp \        ) V^,           ,          V! V) \        4      ,          \        V^,           ,          V! V) \        ) 4      ,          ,           # )rŽ   )Úpolylog)rè   rß  r   )r”   rÐ   r•   rß  s   &&, rG   Ú_eval_rewrite_as_polylogÚandre._eval_rewrite_as_polylog'  s>   € ÝBÜ��a˜•c�{™W a R¬›^Õ+¬a°!°Aµ#­h¹À!ÀÄaÀR»Õ.HÕHÐHrI   c                	ó|   € V P                   ^ ,          pVP                  '       d   VP                  '       d   R# R# R# r¨  r©  rÂ  s   & rG   r«  Úandre._eval_is_integer+  s-   € Ø�I‰I�a�LˆØ�<�<ˆ<˜A×,×,Ð,Ùñ -‰<rI   c                	óP   € V P                   ^ ,          P                  '       d   R# R# r¨  r®  rª  s   &rG   r¯  Úandre._eval_is_positive0  r±  rI   c           
     	óò  € V P                   ^ ,          P                  '       g   R# V P                   ^ ,          P                  V^,           4      p\        V^,           4      ;_uu_ 4        \        P
                  ! V^,          4      \        P                  ! V^,          4      rC^\        P                  ! V) V) WCV) 34      ,          pRRR4       \        P                  ! XV4      #   + '       g   i     L'; i©rŽ   N)
rÍ   rî   r÷   r?   r>   ÚsinpiÚcospiÚ	dirichletr   rü   )r”   rý   rÐ   ÚspÚcprþ   s   &&    rG   rÿ   Úandre._eval_evalf4  s¨   € Ø�y‰y˜�|×%×%Ð%ÙØ�I‰I�a�L×#Ñ# D¨¥GÓ,ˆÜ�d˜2•g×ÕÜ—X’X˜a �c“]¤B§H¢H¨Q¨q­S£M�Ø”B—L’L !  r c¨2°B°3Ð%7Ó8Õ8ˆC÷ ô × Ò   dÓ+Ð+÷ ×ús   Á)AC&Ã&C6	rg   N)rh   ri   rj   rk   rl   r¤   r‹   ré   rà  r«  r¯  rÿ   rn   rg   rI   rG   r×  r×  Ò  s9   † ñ7ðr ñ@ó ð@ò&EòIòò
ö,rI   r×  c                  ó>   € ] tR tRtRtRtRt]R 4       tR t	R t
RtR# )	Ú	partitioniD  aú  
Partition numbers

The Partition numbers are a sequence of integers `p_n` that represent the
number of distinct ways of representing `n` as a sum of natural numbers
(with order irrelevant). The generating function for `p_n` is given by:

.. math:: \sum_{n=0}^\infty p_n x^n = \prod_{k=1}^\infty (1 - x^k)^{-1}

Examples
========

>>> from sympy import partition, Symbol
>>> [partition(n) for n in range(9)]
[1, 1, 2, 3, 5, 7, 11, 15, 22]
>>> n = Symbol('n', integer=True, negative=True)
>>> partition(n)
0

See Also
========

bell, bernoulli, catalan, euler, fibonacci, harmonic, lucas, genocchi, tribonacci

References
==========

.. [1] https://en.wikipedia.org/wiki/Partition_(number_theory%29
.. [2] https://en.wikipedia.org/wiki/Pentagonal_number_theorem

Tc                	ó>  € VP                   R J d   \        R4      hVP                  RJ d   \        P                  # VP
                  RJ g   V\        P                  J d   \        P                  # VP                  RJ d   \        \        \        V4      4      4      # R# )Fún should be an integerTN)
rÖ   Ú	TypeErrorr  r   rÊ   rÕ   r£   rƒ   r.   r=   r©   s   &&rG   r‹   Úpartition.evalg  ss   € à�<‰<˜5Ó ÜÐ4Ó5Ð5Ø�=‰=˜DÓ Ü—6‘6ˆMØ�9‰9˜Ó ¤Q§U¡U£
Ü—5‘5ˆLØ�<‰<˜4ÓÜ”Z¤ q£	Ó*Ó+Ð+ñ  rI   c                	óL   € V P                   ^ ,          P                  RJ d   R# R# r¨  r®  rª  s   &rG   r¯  Úpartition._eval_is_positiver  s    € Ø�9‰9�Q�<×&Ñ&¨$Ó.Ùñ /rI   c                	ó�   € V P                   ^ ,          pR F,  w  r4W8X  g   K  W!,          V8X  g   K  \        P                  u # 	  R# )rŽ   N))é   é   )é   r÷  )é   é   )rÍ   r   rÊ   )r”   rà   rT   rX   Úrems   &&   rG   Ú	_eval_ModÚpartition._eval_Modv  s1   € à�I‰I�a�LˆÛ/‰FˆAØŽv˜!�% 3ž,Ü—v‘v’ó 0rI   rg   N)rh   ri   rj   rk   rl   rÖ   r×   r¤   r‹   r¯  rý  rn   rg   rI   rG   rï  rï  D  s/   † ñð> €JØ€Nàñ,ó ð,òörI   rï  c                  óL   € ] tR tRtRtRtRt]]P                  3R l4       t
RtR# )Údivisor_sigmai~  aÚ  
Calculate the divisor function `\sigma_k(n)` for positive integer n

``divisor_sigma(n, k)`` is equal to ``sum([x**k for x in divisors(n)])``

If n's prime factorization is:

.. math ::
    n = \prod_{i=1}^\omega p_i^{m_i},

then

.. math ::
    \sigma_k(n) = \prod_{i=1}^\omega (1+p_i^k+p_i^{2k}+\cdots
    + p_i^{m_ik}).

Examples
========

>>> from sympy.functions.combinatorial.numbers import divisor_sigma
>>> divisor_sigma(18, 0)
6
>>> divisor_sigma(39, 1)
56
>>> divisor_sigma(12, 2)
210
>>> divisor_sigma(37)
38

See Also
========

sympy.ntheory.factor_.divisor_count, totient, sympy.ntheory.factor_.divisors, sympy.ntheory.factor_.factorint

References
==========

.. [1] https://en.wikipedia.org/wiki/Divisor_function

Tc                	ó�  € VP                   R J d   \        R4      hVP                  R J d   \        R4      hVP                   R J d   \        R4      hVP                  R J d   \        R4      hVP
                  RJ d   ^W,          ,           # V\        P                  J d   \        P                  # VP                  RJ dü   VP                  RJ d7   \        \        V4      P                  4        Uu. uF  q3^,           NK  	  up!  # VP                  RJ d(   \        \        \        V4      \        V4      4      4      # VP                  R J dm   \        \        V4      P                  4        UUu. uF?  w  rC\!        WBV^,           ,          ,          ^,
          WB,          ^,
          ,          4      NKA  	  upp!  # R# R# u upi u uppi ©Frñ  ún should be a positive integerzk should be an integerz!k should be a nonnegative integerTN)rÖ   rò  rÛ   r†   r×   r\   r   r£   rƒ   rÕ   r   r(   Úvaluesr)   r=   Úitemsr5   )r‰   rT   r  ÚerX   s   &&&  rG   r‹   Údivisor_sigma.evalª  sf  € à�<‰<˜5Ó ÜÐ4Ó5Ð5Ø�=‰=˜EÓ!ÜÐ=Ó>Ð>Ø�<‰<˜5Ó ÜÐ4Ó5Ð5Ø×Ñ˜uÓ$ÜÐ@ÓAÐAØ�:‰:˜ÓØ�q•t•8ˆOØ”—‘‹:Ü—5‘5ˆLØ�<‰<˜4ÓØ�y‰y˜DÓ Ü¬I°a«L×,?Ñ,?Ô,AÓBÑ,A q ŸU˜UÑ,AÑBÑCÐCØ�|‰|˜tÓ#Üœ¬¨q«	´6¸!³9Ó=Ó>Ð>Ø�y‰y˜EÓ!ÜÔS\Ð]^ÓS_×SeÑSeÔSgÔhÑSgÉ4È1œV Q¨A°­E­¥^°aÕ%7¸A½DÀ1½HÕ$EÖFÑSgÒhÑiÐiñ "ñ  ùâBùó is   Ã0F=Å.AG
rg   N©rh   ri   rj   rk   rl   rÖ   rÛ   r¤   r   r£   r‹   rn   rg   rI   rG   r   r   ~  s/   † ñ'ðP €JØ€KàØ—u‘uó jó ôjrI   r   c                  óL   € ] tR tRtRtRtRt]]P                  3R l4       t
RtR# )Úudivisor_sigmaiÁ  a  
Calculate the unitary divisor function `\sigma_k^*(n)` for positive integer n

``udivisor_sigma(n, k)`` is equal to ``sum([x**k for x in udivisors(n)])``

If n's prime factorization is:

.. math ::
    n = \prod_{i=1}^\omega p_i^{m_i},

then

.. math ::
    \sigma_k^*(n) = \prod_{i=1}^\omega (1+ p_i^{m_ik}).

Parameters
==========

k : power of divisors in the sum

    for k = 0, 1:
    ``udivisor_sigma(n, 0)`` is equal to ``udivisor_count(n)``
    ``udivisor_sigma(n, 1)`` is equal to ``sum(udivisors(n))``

    Default for k is 1.

Examples
========

>>> from sympy.functions.combinatorial.numbers import udivisor_sigma
>>> udivisor_sigma(18, 0)
4
>>> udivisor_sigma(74, 1)
114
>>> udivisor_sigma(36, 3)
47450
>>> udivisor_sigma(111)
152

See Also
========

sympy.ntheory.factor_.divisor_count, totient, sympy.ntheory.factor_.divisors,
sympy.ntheory.factor_.udivisors, sympy.ntheory.factor_.udivisor_count, divisor_sigma,
sympy.ntheory.factor_.factorint

References
==========

.. [1] https://mathworld.wolfram.com/UnitaryDivisorFunction.html

Tc           
     	óÜ  € VP                   R J d   \        R4      hVP                  R J d   \        R4      hVP                   R J d   \        R4      hVP                  R J d   \        R4      hVP
                  RJ d   ^W,          ,           # VP                  '       dI   \        \        V4      P                  4        UUu. uF  w  r4^W2V,          ,          ,           NK  	  upp!  # R# u uppi r  )
rÖ   rò  rÛ   r†   r×   r\   rƒ   r   r(   r  )r‰   rT   r  rX   r  s   &&&  rG   r‹   Úudivisor_sigma.evalù  sÃ   € à�<‰<˜5Ó ÜÐ4Ó5Ð5Ø�=‰=˜EÓ!ÜÐ=Ó>Ð>Ø�<‰<˜5Ó ÜÐ4Ó5Ð5Ø×Ñ˜uÓ$ÜÐ@ÓAÐAØ�:‰:˜ÓØ�q•t•8ˆOØ�<�<ˆ<Ü´	¸!³×0BÑ0BÔ0DÔEÑ0D©¨˜˜1 �s�8Ÿ˜Ñ0DÒEÑFÐFñ ùÛEs   Â?!C(
rg   Nr  rg   rI   rG   r
  r
  Á  s/   † ñ3ðh €JØ€KàØ—u‘uó Gó ôGrI   r
  c                  ó2   € ] tR tRtRtRtRt]R 4       tRt	R# )Úlegendre_symboli	  a¥  
Returns the Legendre symbol `(a / p)`.

For an integer ``a`` and an odd prime ``p``, the Legendre symbol is
defined as

.. math ::
    \genfrac(){}{}{a}{p} = \begin{cases}
         0 & \text{if } p \text{ divides } a\\
         1 & \text{if } a \text{ is a quadratic residue modulo } p\\
        -1 & \text{if } a \text{ is a quadratic nonresidue modulo } p
    \end{cases}

Examples
========

>>> from sympy.functions.combinatorial.numbers import legendre_symbol
>>> [legendre_symbol(i, 7) for i in range(7)]
[0, 1, 1, -1, 1, -1, -1]
>>> sorted(set([i**2 % 7 for i in range(7)]))
[0, 1, 2, 4]

See Also
========

sympy.ntheory.residue_ntheory.is_quad_residue, jacobi_symbol

TFc                	óî  € VP                   R J d   \        R4      hVP                   R J d   \        R4      hVP                  R J g   VP                  R J d   \	        R4      hW,          P
                  RJ d   \        P                  # V\        P                  J d   \        P                  # VP                  RJ d:   VP                  RJ d(   \        \        \        V4      \        V4      4      4      # R# R# )Fúa should be an integerzp should be an integerz p should be an odd prime integerTN)rÖ   rò  r\   rÚ   r†   rÕ   r   rÊ   r£   rƒ   r   r=   )r‰   rE   rX   s   &&&rG   r‹   Úlegendre_symbol.eval)  s¹   € à�<‰<˜5Ó ÜÐ4Ó5Ð5Ø�<‰<˜5Ó ÜÐ4Ó5Ð5Ø�:‰:˜Ó !§(¡(¨eÓ"3ÜÐ?Ó@Ð@Ø�E�?‰?˜dÓ"Ü—6‘6ˆMØ”—‘‹:Ü—5‘5ˆLØ�<‰<˜4Ó A§L¡L°DÓ$8Ü”Xœf Q›i¬°«Ó3Ó4Ð4ñ %9ÑrI   rg   N©
rh   ri   rj   rk   rl   rÖ   r\   r¤   r‹   rn   rg   rI   rG   r  r  	  s%   † ñð8 €JØ€Hàñ5ó ô5rI   r  c                  ó2   € ] tR tRtRtRtRt]R 4       tRt	R# )Újacobi_symboli9  aþ  
Returns the Jacobi symbol `(m / n)`.

For any integer ``m`` and any positive odd integer ``n`` the Jacobi symbol
is defined as the product of the Legendre symbols corresponding to the
prime factors of ``n``:

.. math ::
    \genfrac(){}{}{m}{n} =
        \genfrac(){}{}{m}{p^{1}}^{\alpha_1}
        \genfrac(){}{}{m}{p^{2}}^{\alpha_2}
        ...
        \genfrac(){}{}{m}{p^{k}}^{\alpha_k}
        \text{ where } n =
            p_1^{\alpha_1}
            p_2^{\alpha_2}
            ...
            p_k^{\alpha_k}

Like the Legendre symbol, if the Jacobi symbol `\genfrac(){}{}{m}{n} = -1`
then ``m`` is a quadratic nonresidue modulo ``n``.

But, unlike the Legendre symbol, if the Jacobi symbol
`\genfrac(){}{}{m}{n} = 1` then ``m`` may or may not be a quadratic residue
modulo ``n``.

Examples
========

>>> from sympy.functions.combinatorial.numbers import jacobi_symbol, legendre_symbol
>>> from sympy import S
>>> jacobi_symbol(45, 77)
-1
>>> jacobi_symbol(60, 121)
1

The relationship between the ``jacobi_symbol`` and ``legendre_symbol`` can
be demonstrated as follows:

>>> L = legendre_symbol
>>> S(45).factors()
{3: 2, 5: 1}
>>> jacobi_symbol(7, 45) == L(7, 3)**2 * L(7, 5)**1
True

See Also
========

sympy.ntheory.residue_ntheory.is_quad_residue, legendre_symbol

TFc                	ó  € VP                   R J d   \        R4      hVP                   R J d   \        R4      hVP                  R J g   VP                  R J d   \	        R4      hV\
        P                  J g   V\
        P                  J d   \
        P                  # W,          P                  RJ d   \
        P                  # VP                  RJ d:   VP                  RJ d(   \        \        \        V4      \        V4      4      4      # R# R# )Fzm should be an integerrñ  z#n should be an odd positive integerTN)rÖ   rò  rÛ   rÚ   r†   r   r£   rÕ   rÊ   rƒ   r    r=   )r‰   r  rT   s   &&&rG   r‹   Újacobi_symbol.evalp  sÃ   € à�<‰<˜5Ó ÜÐ4Ó5Ð5Ø�<‰<˜5Ó ÜÐ4Ó5Ð5Ø�=‰=˜EÓ! Q§X¡X°Ó%6ÜÐBÓCÐCØ”—‘‹:˜œaŸe™e›Ü—5‘5ˆLØ�E�?‰?˜dÓ"Ü—6‘6ˆMØ�<‰<˜4Ó A§L¡L°DÓ$8Ü”VœF 1›I¤v¨a£yÓ1Ó2Ð2ñ %9ÑrI   rg   Nr  rg   rI   rG   r  r  9  s&   † ñ2ðf €JØ€Hàñ3ó ô3rI   r  c                  ó2   € ] tR tRtRtRtRt]R 4       tRt	R# )Úkronecker_symboli€  aG  
Returns the Kronecker symbol `(a / n)`.

Examples
========

>>> from sympy.functions.combinatorial.numbers import kronecker_symbol
>>> kronecker_symbol(45, 77)
-1
>>> kronecker_symbol(13, -120)
1

See Also
========

jacobi_symbol, legendre_symbol

References
==========

.. [1] https://en.wikipedia.org/wiki/Kronecker_symbol

TFc                	ót  € VP                   R J d   \        R4      hVP                   R J d   \        R4      hV\        P                  J g   V\        P                  J d   \        P                  # VP                  RJ d:   VP                  RJ d(   \        \        \        V4      \        V4      4      4      # R# R# )Fr  rñ  TN)rÖ   rò  r   r£   rƒ   r!   r=   )r‰   rE   rT   s   &&&rG   r‹   Úkronecker_symbol.eval›  s‰   € à�<‰<˜5Ó ÜÐ4Ó5Ð5Ø�<‰<˜5Ó ÜÐ4Ó5Ð5Ø”—‘‹:˜œaŸe™e›Ü—5‘5ˆLØ�<‰<˜4Ó A§L¡L°DÓ$8Ü”Yœv a›y¬&°«)Ó4Ó5Ð5ñ %9ÑrI   rg   Nr  rg   rI   rG   r  r  €  s%   † ñð. €JØ€Hàñ6ó ô6rI   r  c                  ó2   € ] tR tRtRtRtRt]R 4       tRt	R# )Úmobiusi§  a  
Mobius function maps natural number to {-1, 0, 1}

It is defined as follows:
    1) `1` if `n = 1`.
    2) `0` if `n` has a squared prime factor.
    3) `(-1)^k` if `n` is a square-free positive integer with `k`
       number of prime factors.

It is an important multiplicative function in number theory
and combinatorics.  It has applications in mathematical series,
algebraic number theory and also physics (Fermion operator has very
concrete realization with Mobius Function model).

Examples
========

>>> from sympy.functions.combinatorial.numbers import mobius
>>> mobius(13*7)
1
>>> mobius(1)
1
>>> mobius(13*7*5)
-1
>>> mobius(13**2)
0

Even in the case of a symbol, if it clearly contains a squared prime factor, it will be zero.

>>> from sympy import Symbol
>>> n = Symbol("n", integer=True, positive=True)
>>> mobius(4*n)
0
>>> mobius(n**2)
0

References
==========

.. [1] https://en.wikipedia.org/wiki/M%C3%B6bius_function
.. [2] Thomas Koshy "Elementary Number Theory with Applications"
.. [3] https://oeis.org/A008683

TFc                	óð  € VP                   R J d   \        R4      hVP                  R J d   \        R4      hVP                  RJ d   \
        P                  # V\
        P                  J d   \
        P                  # RpR \        P                  ! V4       4        EFW  w  r4VP                   RJ EdA   VP                  RJ Ed0   VP                   RJ Ed   VP                  RJ Ed   \        \
        P                  V4      pVRJ d   \
        P                  pK|  VP                  RJ dÉ   \        V4      p\        ;QJ d*    R VP                  4        4       F  '       g   K   RM	  R M! R VP                  4        4       4      '       d   \
        P                  pKÿ  VR J dM   \!        V4      ^,          '       d   \
        P                  M\
        P                  pVf   TpEKF  W',          pEKQ  EKT  EKW   R# 	  V# )Frñ  r  TNc              3  ó@   "  € T F  qP                  4       x € K  	  R # 5irr   )Úas_base_exp)rð   Ú_s   & rG   rñ   Úmobius.eval.<locals>.<genexpr>â  s   é € Ð?Ñ.>¨—]‘]—_�_Ó.>ùs   ‚c              3  ó*   "  € T F	  q^8„  x € K  	  R# 5ir¨   rg   ©rð   Úvs   & rG   rñ   r!  ê  s   é € Ð;Ñ*: Q˜qž5Ó*:ùs   ‚)rÖ   rò  rÛ   r†   r\   r   r…   r£   r   Ú	make_argsr   rÊ   rƒ   r(   rv  r  rø   )r‰   rT   rO  r  r  ÚltÚfactorsrÐ   s   &&      rG   r‹   Úmobius.eval×  sa  € à�<‰<˜5Ó ÜÐ4Ó5Ð5Ø�=‰=˜EÓ!ÜÐ=Ó>Ð>Ø�:‰:˜ÓÜ—=‘=Ð Ø”—‘‹:Ü—5‘5ˆLØˆÙ?¬c¯mªm¸AÔ.>×?‰DˆAØ�|‰|˜tÔ#¨¯©¸Ô(=Ø�|‰|˜tÔ#¨¯©¸Ô(=Üœ1Ÿ5™5 !“_�Ø˜“:ÜŸV™V’FØ—\‘\ TÓ)Ü'¨›l�Gß“sÑ;¨'¯.©.Ô*:Ó;—s—s’sÑ;¨'¯.©.Ô*:Ó;×;Ò;Ü!"§¡šØ˜u›Ü-0°«\¸A×-=Ô-=œAŸMšMÄ1Ç5Á5˜Ø!š>Ø%&›Fà"�K›Fò %ò	 *ò ñ# @ð$ ˆrI   rg   Nr  rg   rI   rG   r  r  §  s&   † ñ+ðX €JØ€Hàñó ôrI   r  c                  ó2   € ] tR tRtRtRtRt]R 4       tRt	R# )Úprimenui÷  að  
Calculate the number of distinct prime factors for a positive integer n.

If n's prime factorization is:

.. math ::
    n = \prod_{i=1}^k p_i^{m_i},

then ``primenu(n)`` or `\nu(n)` is:

.. math ::
    \nu(n) = k.

Examples
========

>>> from sympy.functions.combinatorial.numbers import primenu
>>> primenu(1)
0
>>> primenu(30)
3

See Also
========

sympy.ntheory.factor_.factorint

References
==========

.. [1] https://mathworld.wolfram.com/PrimeFactor.html
.. [2] https://oeis.org/A001221

Tc                	óT  € VP                   R J d   \        R4      hVP                  R J d   \        R4      hVP                  RJ d   \
        P                  # V\
        P                  J d   \
        P                  # VP                  RJ d   \        \        \        V4      4      4      # R# ©Frñ  r  TN)rÖ   rò  rÛ   r†   r\   r   r£   rÊ   rƒ   rø   r(   r©   s   &&rG   r‹   Úprimenu.eval  s€   € à�<‰<˜5Ó ÜÐ4Ó5Ð5Ø�=‰=˜EÓ!ÜÐ=Ó>Ð>Ø�:‰:˜ÓÜ—5‘5ˆLØ”—‘‹:Ü—6‘6ˆMØ�<‰<˜4ÓÜ”Sœ 1›Ó&Ó'Ð'ñ  rI   rg   N©
rh   ri   rj   rk   rl   rÖ   r×   r¤   r‹   rn   rg   rI   rG   r*  r*  ÷  s&   † ñ!ðD €JØ€Nàñ
(ó ô
(rI   r*  c                  ó2   € ] tR tRtRtRtRt]R 4       tRt	R# )Ú
primeomegai+  a!  
Calculate the number of prime factors counting multiplicities for a
positive integer n.

If n's prime factorization is:

.. math ::
    n = \prod_{i=1}^k p_i^{m_i},

then ``primeomega(n)``  or `\Omega(n)` is:

.. math ::
    \Omega(n) = \sum_{i=1}^k m_i.

Examples
========

>>> from sympy.functions.combinatorial.numbers import primeomega
>>> primeomega(1)
0
>>> primeomega(20)
3

See Also
========

sympy.ntheory.factor_.factorint

References
==========

.. [1] https://mathworld.wolfram.com/PrimeFactor.html
.. [2] https://oeis.org/A001222

Tc                	óp  € VP                   R J d   \        R4      hVP                  R J d   \        R4      hVP                  RJ d   \
        P                  # V\
        P                  J d   \
        P                  # VP                  RJ d,   \        \        \        V4      P                  4       4      4      # R# r,  )rÖ   rò  rÛ   r†   r\   r   r£   rÊ   rƒ   Úsumr(   r  r©   s   &&rG   r‹   Úprimeomega.evalR  s‰   € à�<‰<˜5Ó ÜÐ4Ó5Ð5Ø�=‰=˜EÓ!ÜÐ=Ó>Ð>Ø�:‰:˜ÓÜ—5‘5ˆLØ”—‘‹:Ü—6‘6ˆMØ�<‰<˜4ÓÜ”Sœ 1›×,Ñ,Ó.Ó/Ó0Ð0ñ  rI   rg   Nr.  rg   rI   rG   r0  r0  +  s&   † ñ"ðF €JØ€Nàñ
1ó ô
1rI   r0  c                  ó2   € ] tR tRtRtRtRt]R 4       tRt	R# )Útotienti`  a%  
Calculate the Euler totient function phi(n)

``totient(n)`` or `\phi(n)` is the number of positive integers `\leq` n
that are relatively prime to n.

Examples
========

>>> from sympy.functions.combinatorial.numbers import totient
>>> totient(1)
1
>>> totient(25)
20
>>> totient(45) == totient(5)*totient(9)
True

See Also
========

sympy.ntheory.factor_.divisor_count

References
==========

.. [1] https://en.wikipedia.org/wiki/Euler%27s_totient_function
.. [2] https://mathworld.wolfram.com/TotientFunction.html
.. [3] https://oeis.org/A000010

Tc                	óî  € VP                   R J d   \        R4      hVP                  R J d   \        R4      hV\        P
                  J d   \        P
                  # VP                  RJ d
   V^,
          # \        V\        4      '       d*   \	        \        R VP                  4        4       4      4      # VP                  RJ d3   \	        \        R \        V4      P                  4        4       4      4      # R# )Frñ  r  Tc              3  ó`   "  € T F$  w  rW^,
          ,          V^,
          ,          x € K&  	  R# 5ir¨   rg   ©rð   rX   r  s   &  rG   rñ   Útotient.eval.<locals>.<genexpr>�  s"   é € Ð?±Y©T¨Q˜! �c�( A a¥CŸ.š.³Yùó   ‚,.c              3  ó`   "  € T F$  w  rW^,
          ,          V^,
          ,          x € K&  	  R# 5ir¨   rg   r8  s   &  rG   rñ   r9  �  s$   é € ÐJÑ5I©T¨Q˜! �c�( A a¥CŸ.š.Ó5Iùr:  N)rÖ   rò  rÛ   r†   r   r£   r\   rY  r   r   r  rƒ   r(   r©   s   &&rG   r‹   Útotient.eval‚  s¸   € à�<‰<˜5Ó ÜÐ4Ó5Ð5Ø�=‰=˜EÓ!ÜÐ=Ó>Ð>Ø”—‘‹:Ü—5‘5ˆLØ�:‰:˜ÓØ�q•5ˆLÜ�aœ×ÒÜ”TÑ?°Q·W±W´YÓ?Ó?Ó@Ð@Ø�<‰<˜4ÓÜ”TÑJ´Y¸q³\×5GÑ5GÔ5IÓJÓJÓKÐKñ  rI   rg   N©
rh   ri   rj   rk   rl   rÖ   rÛ   r¤   r‹   rn   rg   rI   rG   r5  r5  `  s'   † ñð< €JØ€KàñLó ôLrI   r5  c                  ó2   € ] tR tRtRtRtRt]R 4       tRt	R# )Úreduced_totienti’  a-  
Calculate the Carmichael reduced totient function lambda(n)

``reduced_totient(n)`` or `\lambda(n)` is the smallest m > 0 such that
`k^m \equiv 1 \mod n` for all k relatively prime to n.

Examples
========

>>> from sympy.functions.combinatorial.numbers import reduced_totient
>>> reduced_totient(1)
1
>>> reduced_totient(8)
2
>>> reduced_totient(30)
4

See Also
========

totient

References
==========

.. [1] https://en.wikipedia.org/wiki/Carmichael_function
.. [2] https://mathworld.wolfram.com/CarmichaelFunction.html
.. [3] https://oeis.org/A002322

Tc           	     	óè  € VP                   R J d   \        R4      hVP                  R J d   \        R4      hV\        P
                  J d   \        P
                  # VP                  RJ d
   V^,
          # \        V\        4      '       dl   ^p^V9   d/   ^V^,          8  d   ^V^,          ^,
          ,          MV^,          p\	        \        \        V4      .R VP                  4        4       O5!  4      # VP                  RJ dn   \        \        V4      ^4      w  rV'       g   ^pM^V8  d   ^V^,
          ,          p\	        \        V.R \        V4      P                  4        4       O5!  4      # R# )Frñ  r  Tc              3  óª   "  € T FI  w  rV^8w  g   K  \        V^,
          4      \        V4      \        V^,
          4      ,          ,          x € KK  	  R# 5i)rw   N)r„   r8  s   &  rG   rñ   Ú'reduced_totient.eval.<locals>.<genexpr>Â  s?   é € Ð"]ÉÁÀÐVWÐ[\ÑV\Ô#<¤3 q¨¥s£8¬C°«F´C¸¸!½³HÕ,<×#<Ò#<Ëùs   ‚A’AAc              3  ó`   "  € T F$  w  rV^,
          W^,
          ,          ,          x € K&  	  R# 5ir¨   rg   r8  s   &  rG   rñ   rB  É  s$   é € ÐNÑ9M±°˜q �s A¨!­¥HŸnšnÓ9Mùr:  N)rÖ   rò  rÛ   r†   r   r£   r\   rY  r   r   r„   r  rƒ   r   r(   )r‰   rT   Úts   && rG   r‹   Úreduced_totient.eval´  s!  € à�<‰<˜5Ó ÜÐ4Ó5Ð5Ø�=‰=˜EÓ!ÜÐ=Ó>Ð>Ø”—‘‹:Ü—5‘5ˆLØ�:‰:˜ÓØ�q•5ˆLÜ�aœ×ÒØˆAØ�AŒvØ)*¨Q¨q­T¬�Q˜1˜Q�4 !�8–_°q¸µt�Ü”Sœ˜Q›Ð^Ñ"]ÈÏÉÌÓ"]Ó^Ó_Ð_Ø�<‰<˜4ÓÜœ#˜a›& !Ó$‰DˆAßØ‘Ø�Q”Ø˜!˜a�%•L�Ü”S˜ÐOÑN¼À1»×9KÑ9KÔ9MÓNÓOÓPÐPñ  rI   rg   Nr=  rg   rI   rG   r?  r?  ’  s'   † ñð< €JØ€KàñQó ôQrI   r?  c                  ó2   € ] tR tRtRtRtRt]R 4       tRt	R# )ÚprimepiiÌ  a³  Represents the prime counting function pi(n) = the number
of prime numbers less than or equal to n.

Examples
========

>>> from sympy.functions.combinatorial.numbers import primepi
>>> from sympy import prime, prevprime, isprime
>>> primepi(25)
9

So there are 9 primes less than or equal to 25. Is 25 prime?

>>> isprime(25)
False

It is not. So the first prime less than 25 must be the
9th prime:

>>> prevprime(25) == prime(9)
True

See Also
========

sympy.ntheory.primetest.isprime : Test if n is prime
sympy.ntheory.generate.primerange : Generate all primes in a given range
sympy.ntheory.generate.prime : Return the nth prime

References
==========

.. [1] https://oeis.org/A000720

Tc                	ó~  € V\         P                  J d   \         P                  # V\         P                  J d   \         P                  # VP                  R J d   \        R4      h\        V\        ^4      4      RJ d   \         P                  #  \        V4      p\        \        T4      4      #   \
         d     R# i ; i)Fzn should be a realTN)	r   r‚   ÚNegativeInfinityrÊ   Úis_realrò  r   r„   r-   r©   s   &&rG   r‹   Úprimepi.evaló  s“   € à”—
‘
‹?Ü—:‘:ÐØ”×"Ñ"Ó"Ü—6‘6ˆMØ�9‰9˜ÓÜÐ0Ó1Ð1Ü�”A�a“D‹>˜TÓ!Ü—6‘6ˆMð	Ü�A“ˆAô ”˜!“‹~Ðøô ô 	Úð	ús   ÂB- Â-B<Â;B<rg   Nr.  rg   rI   rG   rG  rG  Ì  s&   † ñ"ðF €JØ€Nàñó ôrI   rG  c                  ó   € ] tR tRtRtRtR# )Ú_MultisetHistogrami	  rg   N)rh   ri   rj   rk   Ú	__slots__rn   rg   rI   rG   rM  rM  	  s   † Ø„IrI   rM  Nc                óD  a € \        S \        4      '       dÅ   \        ;QJ d*    R S P                  4        4       F  '       d   K   RM	  RM! R S P                  4        4       4      '       g   \        h\        S P                  4       4      p\        V 3R lS  4       4      p\        S  Uu. uF  pS V,          ^ 8”  g   K  S V,          NK  	  upW!.,           4      # \        S 4      o \        S 4      p\        V4      p\        S 4      pWV8X  d   ^.V,          Wf.,           o \        S 4      # \        \        V\        V4      4      4      p\        \        \        V4      RV,          4      4      pS  F  p	W‡V	,          ;;,          ^,          uu&   K   	  \        V4      # u upi )a"  Return tuple used in permutation and combination counting. Input
is a dictionary giving items with counts as values or a sequence of
items (which need not be sorted).

The data is stored in a class deriving from tuple so it is easily
recognized and so it can be converted easily to a list.
c              3  ó\   "  € T F"  p\        V\        4      ;'       d    V^ 8¬  x € K$  	  R# 5irç  )rY  r„   r#  s   & rG   rñ   Ú&_multiset_histogram.<locals>.<genexpr>	  s&   é € ÐE¹*°Q”:˜a¤Ó%×0Ð0¨!¨q©&Ô0»*ùs   ‚,ž,FTc              3  óH   <"  € T F  pSV,          ^ 8”  g   K  ^x € K  	  R# 5irç  rg   )rð   r  rT   s   & €rG   rñ   rQ   	  s   øé € Ð-™q˜! A a¥D¨1¡H—A’A›qùs   ƒ"˜
"rÏ   )rY  Údictrö   r  r†   r2  rM  ÚlistÚsetrø   ÚziprD   Ú_multiset_histogram)
rT   Útotr  r  rÐ   ÚlensÚlennr  Údrã   s
   f         rG   rW  rW  	  s5  ø€ ô �!”T×Òß‹sÑE¸!¿(¹(¼*ÓE�s�sŠsÑE¸!¿(¹(¼*ÓE×EÒEÜÐÜ�!—(‘(“*‹oˆÜÔ-™qÓ-Ó-ˆÜ!±Ó"?±¨A°a¸µd¸Q±h¤4 1 Q§4 4±Ñ"?À5À,Õ"NÓOÐOä�‹GˆÜ�‹FˆÜ�1‹vˆÜ�1‹vˆØŒ<Ø��D•˜D˜<Õ'ˆAÜ% aÓ(Ð(Ü”�Qœ˜d›Ó$Ó%ˆÜ””U˜4“[ $ t¥)Ó,Ó-ˆÛˆAØ��d�G�q�L�Gñ ä" 1Ó%Ð%ùò #@s   Â+FÃ Fc                ó¢   €  \        V 4      p \        \        YT4      4      #   \         d"    \        \        \	        T 4      Y4      4      u # i ; i)a´  Return the number of permutations of ``n`` items taken ``k`` at a time.

Possible values for ``n``:

    integer - set of length ``n``

    sequence - converted to a multiset internally

    multiset - {element: multiplicity}

If ``k`` is None then the total of all permutations of length 0
through the number of items represented by ``n`` will be returned.

If ``replacement`` is True then a given item can appear more than once
in the ``k`` items. (For example, for 'ab' permutations of 2 would
include 'aa', 'ab', 'ba' and 'bb'.) The multiplicity of elements in
``n`` is ignored when ``replacement`` is True but the total number
of elements is considered since no element can appear more times than
the number of elements in ``n``.

Examples
========

>>> from sympy.functions.combinatorial.numbers import nP
>>> from sympy.utilities.iterables import multiset_permutations, multiset
>>> nP(3, 2)
6
>>> nP('abc', 2) == nP(multiset('abc'), 2) == 6
True
>>> nP('aab', 2)
3
>>> nP([1, 2, 2], 2)
3
>>> [nP(3, i) for i in range(4)]
[1, 3, 6, 6]
>>> nP(3) == sum(_)
True

When ``replacement`` is True, each item can have multiplicity
equal to the length represented by ``n``:

>>> nP('aabc', replacement=True)
121
>>> [len(list(multiset_permutations('aaaabbbbcccc', i))) for i in range(5)]
[1, 3, 9, 27, 81]
>>> sum(_)
121

See Also
========
sympy.utilities.iterables.multiset_permutations

References
==========

.. [1] https://en.wikipedia.org/wiki/Permutation

)r=   r†   r   Ú_nPrW  )rT   r  Úreplacements   &&&rG   ÚnPr_  1	  sQ   € ðvDÜ�1‹Iˆô ”3�q˜[Ó)Ó*Ð*øô ô DÜ”sÔ.¨qÓ1°1ÓBÓCÒCðDús   ‚" ¢)AÁAc           	     ó€  a a€ V^ 8X  d   ^# \        S \        4      '       dz   Vf'   \        V V3R l\        S ^,           4       4       4      # S'       d
   S V,          # VS 8”  d   ^ # VS 8X  d   \	        V4      # V^8X  d   S # \        S V,
          ^,           S 4      # \        S \        4      '       Ed   Vf2   \        V V3R l\        S \        ,          ^,           4       4       4      # S'       d   S \        ,          V,          # VS \        ,          8X  dH   \	        V4      \        S \        ,           Uu. uF  q3^8”  g   K  \	        V4      NK  	  up4      ,          # VS \        ,          8”  d   ^ # V^8X  d   S \        ,          # ^ p\        S 4      o \        \        S \        ,          4      4       EF  pS V,          '       g   K  S \        ;;,          ^,          uu&   S V,          ^8X  da   ^ S V&   S \        ;;,          ^,          uu&   V\        \        S 4      V^,
          4      ,          pS \        ;;,          ^,          uu&   ^S V&   MMS V;;,          ^,          uu&   V\        \        S 4      V^,
          4      ,          pS V;;,          ^,          uu&   S \        ;;,          ^,          uu&   EK  	  V# R# u upi )rŽ   Nc              3  ó>   <"  € T F  p\        SVS4      x € K  	  R # 5irr   ©r]  ©rð   rã   rT   r^  s   & €€rG   rñ   Ú_nP.<locals>.<genexpr>{	  s   øé € ÐD±|°!”s˜1˜a ×-Ð-³|ùó   ƒc              3  ó>   <"  € T F  p\        SVS4      x € K  	  R # 5irr   rb  rc  s   & €€rG   rñ   rd  ‰	  s   øé € ÐHÑ7G°!”s˜1˜a ×-Ð-Ó7Gùre  )rY  r   r2  rD   r#   rH   rM  Ú_NÚ_ITEMSr   Ú_MrT  rø   r]  )rT   r  r^  rã   rX  s   f&f  rG   r]  r]  s	  s  ù€ ð 	ˆA„vÙÜ�!”Z× Ò àŠ9ÜÕD´u¸QÀ½U´|ÓDÓDÐDßØ�a•4ˆKØ�ŒUÙØ�!ŒVÜ˜Q“<ÐØ�!ŒVØˆHô ˜A �E A�I qÓ)Ð)Ü	�AÔ)×	*Ó	*ØŠ9ÜÕH´u¸Q¼r½UÀQ½YÔ7GÓHÓHÐHßØ”V•9˜a•<ÐØ�!”B•%ŒZÜ˜Q“<¤¸A¼b¾EÓ%K¹E°qÈÁU¤l¤i°¦l¹EÑ%KÓ LÕLÐLØ�”2•ŒYÙØ�!ŒVØ”V•9Ðð ˆCÜ�Q“ˆAÜœ3˜q¤�u›:×&�Ø˜—t”tÙØ”"—˜•
“Ø�Q•4˜1”9Ø�A�a‘DØ”f—I •N“IØœ3Ô1°!Ó4°a¸!µeÓ<Õ<�CØ”f—I •N“IØ�A�a’Dà�a—D˜A•I“DØœ3Ô1°!Ó4°a¸!µeÓ<Õ<�CØ�a—D˜A•I“DØ”"—˜•
–ñ 'ð ˆJñ= 
+ùò &Ls   Ä3J;
Å J;
c           	     ó  € \        V 4      p \        V 4      pV^,           ^,          p^.V P                  4       ^,           ,          pVP                  RV\	        V4      ,
          ,          4       VRV pV '       d³   V P                  4       pV^,           pVR,          p\        ^\        V\	        V4      4      4       F$  pW7;;,          W7^,
          ,          ,          uu&   K&  	  \        WR4       F8  pW7;;,          W7^,
          ,          WgV,
          ,          ,
          ,          uu&   K:  	  Kº  \        \        V4      4      pV^,          '       d
   W8,           pMWƒRR% \        \        4      p	\        V4       F	  w  rzW©V&   K  	  V	# )aÉ  for n = (m1, m2, .., mk) return the coefficients of the polynomial,
prod(sum(x**i for i in range(nj + 1)) for nj in n); i.e. the coefficients
of the product of AOPs (all-one polynomials) or order given in n.  The
resulting coefficient corresponding to x**r is the number of r-length
combinations of sum(n) elements with multiplicities given in n.
The coefficients are given as a default dictionary (so if a query is made
for a key that is not present, 0 will be returned).

Examples
========

>>> from sympy.functions.combinatorial.numbers import _AOP_product
>>> from sympy.abc import x
>>> n = (2, 2, 3)  # e.g. aabbccc
>>> prod = ((x**2 + x + 1)*(x**2 + x + 1)*(x**3 + x**2 + x + 1)).expand()
>>> c = _AOP_product(n); dict(c)
{0: 1, 1: 3, 2: 6, 3: 8, 4: 8, 5: 6, 6: 3, 7: 1}
>>> [c[i] for i in range(8)] == [prod.coeff(x, i) for i in range(8)]
True

The generating poly used here is the same as that listed in
https://tinyurl.com/cep849r, but in a refactored form.

N:NNNrÏ   ry   )rT  r2  ÚpopÚextendrø   rD   rw  Úreversedr   r„   Ú	enumerate)rT   ÚordÚneedÚrvÚniÚNÚwasrã   Úrevr[  r  s   &          rG   Ú_AOP_productrv  ¨	  s"  € ô6 	ˆQ‹€AÜ
ˆa‹&€CØ�!�G�a�<€DØ
ˆˆa�e‰e‹g˜�kÕ	€BØ‡I�Iˆd�dœS ›W•nÕ%Ô&Ø	ˆEˆTˆ€Bß
Ø�U‰U‹WˆØ��FˆØ��eˆÜ�qœ#˜a¤ R£›/Ö*ˆAØ�E�R˜A�•YÕ�Eñ +ä�q–ˆAØ�E�R˜A�•Y ¨¥U¥Õ+Õ+�Eó  ä
Œx˜‹|Ó
€CØ
ˆQ‡w„wØ�X‰àˆ2ˆ3ˆÜ”CÓ€AÜ˜"–‰ˆØˆ!‹ñ à€HrI   c                ó  a a€ \        S \        4      '       d|   Vf8   S'       g
   ^S ,          # \        V V3R l\        S ^,           4       4       4      # V^ 8  d   \	        R4      hS'       d   \        S V,           ^,
          V4      # \        S V4      # \        S \        4      '       dË   S \        ,          pVfL   S'       g   \        R S \        ,           4       4      # \        V V3R l\        V^,           4       4       4      # S'       d   \        S \        ,          VS4      # V^V^,
          39   d   S \        ,          # V^ V39   d   ^# \        \        S \        ,          4      4      V,          # \        \        S 4      VS4      # )aÓ  Return the number of combinations of ``n`` items taken ``k`` at a time.

Possible values for ``n``:

    integer - set of length ``n``

    sequence - converted to a multiset internally

    multiset - {element: multiplicity}

If ``k`` is None then the total of all combinations of length 0
through the number of items represented in ``n`` will be returned.

If ``replacement`` is True then a given item can appear more than once
in the ``k`` items. (For example, for 'ab' sets of 2 would include 'aa',
'ab', and 'bb'.) The multiplicity of elements in ``n`` is ignored when
``replacement`` is True but the total number of elements is considered
since no element can appear more times than the number of elements in
``n``.

Examples
========

>>> from sympy.functions.combinatorial.numbers import nC
>>> from sympy.utilities.iterables import multiset_combinations
>>> nC(3, 2)
3
>>> nC('abc', 2)
3
>>> nC('aab', 2)
2

When ``replacement`` is True, each item can have multiplicity
equal to the length represented by ``n``:

>>> nC('aabc', replacement=True)
35
>>> [len(list(multiset_combinations('aaaabbbbcccc', i))) for i in range(5)]
[1, 3, 6, 10, 15]
>>> sum(_)
35

If there are ``k`` items with multiplicities ``m_1, m_2, ..., m_k``
then the total of all combinations of length 0 through ``k`` is the
product, ``(m_1 + 1)*(m_2 + 1)*...*(m_k + 1)``. When the multiplicity
of each item is 1 (i.e., k unique items) then there are 2**k
combinations. For example, if there are 4 unique items, the total number
of combinations is 16:

>>> sum(nC(4, i) for i in range(5))
16

See Also
========

sympy.utilities.iterables.multiset_combinations

References
==========

.. [1] https://en.wikipedia.org/wiki/Combination
.. [2] https://tinyurl.com/cep849r

c              3  ó>   <"  € T F  p\        SVS4      x € K  	  R # 5irr   ©ÚnCrc  s   & €€rG   rñ   ÚnC.<locals>.<genexpr>"
  ó   øé € ÐC±l°”r˜!˜Q ×,Ð,³lùre  zk cannot be negativec              3  ó2   "  € T F  q^,           x € K  	  R# 5ir¨   rg   )rð   r  s   & rG   rñ   r{  ,
  s   é € Ð1©5 a ŸEšE«5ùs   ‚c              3  ó>   <"  € T F  p\        SVS4      x € K  	  R # 5irr   ry  rc  s   & €€rG   rñ   r{  -
  r|  re  )rY  r   r2  rD   r†   r"   rM  rg  r   ri  rz  rh  rv  ÚtuplerW  )rT   r  r^  rs  s   f&f rG   rz  rz  Ü	  s+  ù€ ôD �!”Z× Ò ØŠ9ßØ˜!•t�ÜÕC´e¸AÀ½E´lÓCÓCÐCØˆqŒ5ÜÐ3Ó4Ð4ßÜ˜A �E A�I qÓ)Ð)Ü˜˜1‹~ÐÜ�!Ô'×(Ò(ØŒb�EˆØŠ9ßÜÑ1¨1¬R®5Ó1Ó1Ð1ÜÕC´e¸AÀ½E´lÓCÓCÐCßÜ�aœ•i  KÓ0Ð0à�1�a˜!•e�*Œ_Ø”V•9ÐØ�1�a�&Œ[ÙÜœE !¤B¥%›LÓ)¨!Õ,Ð,äÔ% aÓ(¨!¨[Ó9Ð9rI   c                ó¤  € Yu;8X  d   ^ 8X  d    \         P                  #  ^ W39   d   \         P                  # W8X  d   \         P                  # W^,
          8X  d   \        V ^4      # W^,
          8X  d)   ^V ,          ^,
          \        V ^4      ,          ^,          # W^,
          8X  d   \        V ^4      \        V ^4      ,          # \	        W4      # rÏ   )r   r£   rÊ   r"   Ú
_stirling1©rT   r  s   &&rG   Ú_eval_stirling1rƒ  :
  s¢   € Ø†{�…{Ü�u‰uˆð àˆQˆF„{Ü�v‰vˆð 	„vÜ�u‰uˆØ	
�!�eŒÜ˜˜1‹~ÐØ	
�!�eŒØ�!•�a•œ ! Q›Õ'¨Õ)Ð)Ø	
�!�eŒÜ˜˜1‹~œh q¨!›nÕ,Ð,ä�aÓÐrI   c                ó  € ^ ^.^ .V^,
          ,          ,           p\        ^V ^,           4       FL  p\        \        W4      ^ R4       F/  pV^,
          W$,          ,          W$^,
          ,          ,           W$&   K1  	  KN  	  \        W!,          4      # ©rŽ   ry   ©rD   rw  r   ©rT   r  Úrowrã   rÑ   s   &&   rG   r�  r�  M
  so   € àˆaˆ&�!��a˜•c•Õ
€CÜ�1�a˜•cŽ]ˆÜ”s˜1“x  BÖ'ˆAØ˜•c˜S�V•^ c¨A­#¥hÕ.ˆC‹Fó (ñ ô �3•6‹?ÐrI   c                ób  € Yu;8X  d   ^ 8X  d    \         P                  #  ^ W39   d   \         P                  # W8X  d   \         P                  # W^,
          8X  d   \        V ^4      # V^8X  d   \         P                  # V^8X  d!   \	        ^V ^,
          ,          ^,
          4      # \        W4      # rÏ   )r   r£   rÊ   r"   r   Ú
_stirling2r‚  s   &&rG   Ú_eval_stirling2r‹  V
  s‰   € Ø†{�…{Ü�u‰uˆð àˆQˆF„{Ü�v‰vˆð 	„vÜ�u‰uˆØ	
�!�eŒÜ˜˜1‹~ÐØ	
ˆaŒÜ�u‰uˆØ	
ˆaŒÜ�q˜1˜q�5•z A•~Ó&Ð&ä�aÓÐrI   c                ó  € ^ ^.^ .V^,
          ,          ,           p\        ^V ^,           4       FE  p\        \        W4      ^ R4       F(  pWBV,          ,          W$^,
          ,          ,           W$&   K*  	  KG  	  \        W!,          4      # r…  r†  r‡  s   &&   rG   rŠ  rŠ  i
  sk   € àˆaˆ&�!��a˜•c•Õ
€CÜ�1�a˜•cŽ]ˆÜ”s˜1“x  BÖ'ˆAØ˜Q�•Z #¨¥c¥(Õ*ˆC‹Fó (ñ ô �3•6‹?ÐrI   c                ó°  € \        V 4      p \        V4      pV ^ 8  d   \        R4      hW8”  d   \        P                  # V'       d'   \	        W,
          ^,           W,
          ^,           4      # V'       d.   \        P
                  W,
          ,          \        W4      ,          # V^8X  d   \        W4      # V^8X  d   \	        W4      # \        RV,          4      h)aâ	  Return Stirling number $S(n, k)$ of the first or second (default) kind.

The sum of all Stirling numbers of the second kind for $k = 1$
through $n$ is ``bell(n)``. The recurrence relationship for these numbers
is:

.. math :: {0 \brace 0} = 1; {n \brace 0} = {0 \brace k} = 0;

.. math :: {{n+1} \brace k} = j {n \brace k} + {n \brace {k-1}}

where $j$ is:
    $n$ for Stirling numbers of the first kind,
    $-n$ for signed Stirling numbers of the first kind,
    $k$ for Stirling numbers of the second kind.

The first kind of Stirling number counts the number of permutations of
``n`` distinct items that have ``k`` cycles; the second kind counts the
ways in which ``n`` distinct items can be partitioned into ``k`` parts.
If ``d`` is given, the "reduced Stirling number of the second kind" is
returned: $S^{d}(n, k) = S(n - d + 1, k - d + 1)$ with $n \ge k \ge d$.
(This counts the ways to partition $n$ consecutive integers into $k$
groups with no pairwise difference less than $d$. See example below.)

To obtain the signed Stirling numbers of the first kind, use keyword
``signed=True``. Using this keyword automatically sets ``kind`` to 1.

Examples
========

>>> from sympy.functions.combinatorial.numbers import stirling, bell
>>> from sympy.combinatorics import Permutation
>>> from sympy.utilities.iterables import multiset_partitions, permutations

First kind (unsigned by default):

>>> [stirling(6, i, kind=1) for i in range(7)]
[0, 120, 274, 225, 85, 15, 1]
>>> perms = list(permutations(range(4)))
>>> [sum(Permutation(p).cycles == i for p in perms) for i in range(5)]
[0, 6, 11, 6, 1]
>>> [stirling(4, i, kind=1) for i in range(5)]
[0, 6, 11, 6, 1]

First kind (signed):

>>> [stirling(4, i, signed=True) for i in range(5)]
[0, -6, 11, -6, 1]

Second kind:

>>> [stirling(10, i) for i in range(12)]
[0, 1, 511, 9330, 34105, 42525, 22827, 5880, 750, 45, 1, 0]
>>> sum(_) == bell(10)
True
>>> len(list(multiset_partitions(range(4), 2))) == stirling(4, 2)
True

Reduced second kind:

>>> from sympy import subsets, oo
>>> def delta(p):
...    if len(p) == 1:
...        return oo
...    return min(abs(i[0] - i[1]) for i in subsets(p, 2))
>>> parts = multiset_partitions(range(5), 3)
>>> d = 2
>>> sum(1 for p in parts if all(delta(i) >= d for i in p))
7
>>> stirling(5, 3, 2)
7

See Also
========
sympy.utilities.iterables.multiset_partitions


References
==========

.. [1] https://en.wikipedia.org/wiki/Stirling_numbers_of_the_first_kind
.. [2] https://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind

zn must be nonnegativezkind must be 1 or 2, not %s)r=   r†   r   rÊ   r‹  r…   rƒ  )rT   r  r[  ÚkindÚsigneds   &&&&&rG   Ústirlingr�  r
  s©   € ôl 	ˆq‹	€AÜˆq‹	€AØˆ1„uÜÐ0Ó1Ð1Ø„uÜ�v‰vˆßô ˜q�u q�y¨!­%°!­)Ó4Ð4ß	ä�}‰}˜q�uÕ%¤o°aÓ&;Õ;Ð;àˆq„yÜ˜qÓ$Ð$Ø	�ŒÜ˜qÓ$Ð$äÐ6¸Õ:Ó;Ð;rI   c           	     óL  € W8”  g   V^ 8  d   ^ # V^V 39   d   ^# V^ 8X  d   ^ # V^8X  d
   V ^,          # W,
          pV^8:  d   V# ^V,          V 8¼  dP   \        V4      pW!,
          ^ 8”  d6   V\        \         P                  ! \        W!,
          4      4      4      ,          pV# ^.V,          p\	        ^V^,           4       FG  p\	        V^,           V4       F$  pWF;;,          WFV,
          ,          ,          uu&   K&  	  V^,          pKI  	  ^\        V^V,
          R 4      ,           # )ztReturn the partitions of ``n`` items into ``k`` parts. This
is used by ``nT`` for the case when ``n`` is an integer.N)r/   r2  Ú
fetch_itemÚslicerD   )rT   r  r[  rX  rX   rã   r  s   &&     rG   Ú_nTr”  Þ
  sý   € ð
 	„u��A”ÙØˆQ�ˆF„{ÙØˆA„vÙàˆA„vØ�!�tˆØ	�€AØˆA„vØˆàˆ…sˆa„xô
 ˜QÓˆà�5�1Œ9Ø”3”~×0Ò0´°qµu³Ó>Ó?Õ?ˆCØˆ
ð 
ˆˆA�€AÜ�1�a˜!•eŽ_ˆÜ˜˜A�˜q–/ˆAØ�D�A˜!•e•HÕ�Dñ "à	ˆQ�Šñ ð ”�A�a˜!•e�f�I“ÕÐrI   c                ó0  a € \        S \        4      '       dQ   Vf   \        S 4      # \        V\        4      '       d,   \        S 4      o \        V4      p\	        \        S V4      4      # \        S \        4      '       gS    \        \        S 4      4      pV^8:  d   \        \        S 4      V4      # V\        S 4      8X  d   \        V4      o \        hS \        ,          pVf
   V^8X  d   ^# V^V39   d   ^# V^8X  g   V^8X  dj   Vff   \        V^4      w  rE\        V 3R l\        ^V^,           4       4       4      pV'       g   V\!        S V4      ^,          ,          pVf
   V^,          pV# VS \"        ,          8X  d   Vf   \%        V4      # \'        W14      # \)        4       pVf   VP+                  S \,        ,          4      # ^ pVP/                  S \,        ,          V^,
          V4       F  pV^,          pK  	  V#   \         d    \        S 4      o  ELDi ; i)a¬  Return the number of ``k``-sized partitions of ``n`` items.

Possible values for ``n``:

    integer - ``n`` identical items

    sequence - converted to a multiset internally

    multiset - {element: multiplicity}

Note: the convention for ``nT`` is different than that of ``nC`` and
``nP`` in that
here an integer indicates ``n`` *identical* items instead of a set of
length ``n``; this is in keeping with the ``partitions`` function which
treats its integer-``n`` input like a list of ``n`` 1s. One can use
``range(n)`` for ``n`` to indicate ``n`` distinct items.

If ``k`` is None then the total number of ways to partition the elements
represented in ``n`` will be returned.

Examples
========

>>> from sympy.functions.combinatorial.numbers import nT

Partitions of the given multiset:

>>> [nT('aabbc', i) for i in range(1, 7)]
[1, 8, 11, 5, 1, 0]
>>> nT('aabbc') == sum(_)
True

>>> [nT("mississippi", i) for i in range(1, 12)]
[1, 74, 609, 1521, 1768, 1224, 579, 197, 50, 9, 1]

Partitions when all items are identical:

>>> [nT(5, i) for i in range(1, 6)]
[1, 2, 2, 1, 1]
>>> nT('1'*5) == sum(_)
True

When all items are different:

>>> [nT(range(5), i) for i in range(1, 6)]
[1, 15, 25, 10, 1]
>>> nT(range(5)) == sum(_)
True

Partitions of an integer expressed as a sum of positive integers:

>>> from sympy import partition
>>> partition(4)
5
>>> nT(4, 1) + nT(4, 2) + nT(4, 3) + nT(4, 4)
5
>>> nT('1'*4)
5

See Also
========
sympy.utilities.iterables.partitions
sympy.utilities.iterables.multiset_partitions
sympy.functions.combinatorial.numbers.partition

References
==========

.. [1] https://web.archive.org/web/20210507012732/https://teaching.csse.uwa.edu.au/units/CITS7209/partition.pdf

c              3  ó<   <"  € T F  p\        SV4      x € K  	  R # 5irr   ry  )rð   rã   rT   s   & €rG   rñ   ÚnT.<locals>.<genexpr>n  s   øé € Ð3¡?˜a”�A�q—�£?ùs   ƒ)rY  r   rï  r=   r   r”  rM  rø   rU  ÚnTrD   rò  rW  rg  Údivmodr2  rz  rh  r  r�  r6   Úcount_partitionsri  Ú
enum_range)	rT   r  rP  rs  r  r  rq  rX  Údiscards	   f&       rG   r˜  r˜  
  sÁ  ø€ ôR �!”Z× Ò àŠ9Ü˜Q“<ÐÜ�aœ×$Ò$Ü�q“	ˆAÜ�q“	ˆAÜœ3˜q !›9Ó%Ð%Ü�aÔ+×,Ò,ð
	'ô ”C˜“F“ˆAØ�AŒvÜœ#˜a›& !“}Ð$Ø”c˜!“f”Ü˜!“H�ÜˆOð 	
Œ"�€AØ‚y�Q˜!”VÙØˆQ�ˆF„{ÙØˆA„v��a”˜AšIÜ�a˜‹|‰ˆÜÔ3¤5¨¨A°­E¤?Ó3Ó3ˆßØ”"�Q˜“(˜A•+ÕˆBØŠ9Ø�!�GˆBØˆ	ØˆAŒf�I„~àŠ9Ü˜“7ˆNÜ˜‹~ÐÜ"Ó$€AØ‚yØ×!Ñ! !¤B¥%Ó(Ð(ð €CØ—<‘< ¤"¥ q¨¥s¨AÖ.ˆØˆq�Šñ /à€Jøô9 ô 	'Ü# AÓ&‹Að	'ús   Á?/G; Â/!G; Ç;HÈHc                  ó¬   € ] tR tRtRt]R 4       t]R 4       t]R 4       t]]	! ]
P                  ]
P                  .4      R 4       4       t]R 4       tRtR	# )
Úmotzkini‹  a¬  
The nth Motzkin number is the number
of ways of drawing non-intersecting chords
between n points on a circle (not necessarily touching
every point by a chord). The Motzkin numbers are named
after Theodore Motzkin and have diverse applications
in geometry, combinatorics and number theory.

Motzkin numbers are the integer sequence defined by the
initial terms `M_0 = 1`, `M_1 = 1` and the two-term recurrence relation
`M_n = rac{2*n + 1}{n + 2} * M_{n-1} + rac{3n - 3}{n + 2} * M_{n-2}`.


Examples
========

>>> from sympy import motzkin

>>> motzkin.is_motzkin(5)
False
>>> motzkin.find_motzkin_numbers_in_range(2,300)
[2, 4, 9, 21, 51, 127]
>>> motzkin.find_motzkin_numbers_in_range(2,900)
[2, 4, 9, 21, 51, 127, 323, 835]
>>> motzkin.find_first_n_motzkins(10)
[1, 1, 2, 4, 9, 21, 51, 127, 323, 835]


References
==========

.. [1] https://en.wikipedia.org/wiki/Motzkin_number
.. [2] https://mathworld.wolfram.com/MotzkinNumber.html

c                	ó.  €  \        V 4      p T ^ 8”  dp   T R9   d   R# ^p^p^pY 8  dQ   ^T,          ^,           T,          ^T,          ^,
          T,          ,           T^,           ,          pT^,          pTpTpKV  Y 8X  d   R# R # R #   \         d     R # i ; i)FT)rC   rw   )r=   r†   )rT   Útn1Útnrã   rE   s   &    rG   Ú
is_motzkinÚmotzkin.is_motzkin°  s™   € ð	Ü�q“	ˆAð ˆqŒ5Ø�FŒ{ÙàˆCØˆBØˆAØ”&Ø˜•c˜A•g˜r•\ Q q¥S¨1¥W¨c¥MÕ1°A¸µEÕ:�Ø�Q•�Ø�Ø’àŒwÙáñ øô+ ô 	Úð	ús   ‚B ÂBÂBc                	ó‚  € ^ T u;8:  d   V8:  d§   M M£. pV ^u;8:  d   V8:  d   M MVP                  ^4       ^p^p^pWA8:  dq   W@8¼  d   VP                  V4       ^V,          ^,           V,          ^V,          ^,
          V,          ,           V^,           ,          pV^,          pTp\        V4      pKv  V# \        R4      h)rŽ   zEThe provided range is not valid. This condition should satisfy x <= y)Úappendr„   r†   )rJ   rc   Úmotzkinsr   r¡  rã   rE   s   &&     rG   Úfind_motzkin_numbers_in_rangeÚ%motzkin.find_motzkin_numbers_in_rangeË  s£   € à�Ž;�Q�;ØˆHØ�AŽ{˜�{Ø—‘ Ô"ØˆCØˆBØˆAØ”'Ø”7Ø—O‘O BÔ'Ø˜•c˜A•g˜r•\ Q q¥S¨1¥W¨c¥MÕ1°A¸µEÕ:�Ø�Q•�Ø�Ü˜“V’àˆOô ÐdÓeÐerI   c                	ó˜  €  \        V 4      p T ^ 8  d   \        R 4      h^.pT ^8¼  d   TP                  ^4       ^p^p^pY@8:  dk   TP                  T4       ^T,          ^,           T,          ^T,          ^,
          T,          ,           T^,           ,          pT^,          pTp\        T4      pKp  T#   \         d    \        R 4      hi ; i©z.The provided number must be a positive integer)r=   r†   r¥  r„   )rT   r¦  r   r¡  rã   rE   s   &     rG   Úfind_first_n_motzkinsÚmotzkin.find_first_n_motzkinsá  sÆ   € ð	OÜ�q“	ˆAð ˆqŒ5ÜÐMÓNÐNØ�3ˆØ�Œ6Ø�O‰O˜AÔØˆØˆØˆØŒfØ�O‰O˜BÔØ�A•#˜•'˜2•  1¥ q¥¨#¥Õ-°°AµÕ6ˆAØ��FˆAØˆCÜ�Q“ŠBàˆøô# ô 	OÜÐMÓNÐNð	Oús   ‚B2 Â2C	c                	ó    € ^V ,          ^,           VR,          ,          ^V ,          ^,
          VR,          ,          ,           V ^,           ,          # )rw   ry   rx   rg   r}   s   &&rG   Ú_motzkinÚmotzkin._motzkinø  s:   € ð �1•�q•˜$˜r�(Õ" a¨¥c¨A¥g¨t°B­xÕ%7Õ7¸QÀ½UÕCÐCrI   c                	ó´   €  \        V4      pT^ 8  d   \        R 4      h\        T P                  T^,
          4      4      #   \         d    \        R 4      hi ; irª  )r=   r†   r   r®  r©   s   &&rG   r‹   Úmotzkin.evalý  s]   € ð	OÜ�q“	ˆAð ˆqŒ5ÜÐMÓNÐNÜ�s—|‘| A¨¥EÓ*Ó+Ð+øô	 ô 	OÜÐMÓNÐNð	Oús   ‚A  Á Arg   N)rh   ri   rj   rk   rl   rm   r¢  r§  r«  r<   r   r£   r®  r¤   r‹   rn   rg   rI   rG   rž  rž  ‹  s‰   † ñ"ðH ñó ðð4 ñfó ðfð* ñó ðð, Ù�a—e‘e˜QŸU™U�^Ó$ñDó %ó ðDð ñ,ó ô,rI   rž  rT   r  c               óî	  a€ ^ RI Hp ^ RIHp ^ RIHp R oWV3P                  R4      ^8w  d   \        R4      hV EeS   \        V \        4      '       d   \        R4      hV '       g   \        P                  # \        V 4      \        Jd   \        V 4      p\!        V4      pM˜\        V 4      \        J d†   \"        ;QJ d-    V3R lV P%                  4        4       F  '       d   K   R	M"	  R
M! V3R lV P%                  4        4       4       V P'                  4        U	U
u/ uF  w  ršV
'       g   K  WšbK  	  pp	p
RpX'       g   \        P                  # \)        VP%                  4       4      p\!        VP%                  4       4      p\+        V4      pEMÃVe,   S! V4       V'       g   \        P                  # \-        V4      # VEe�   \        V\        4      '       d‹   \"        ;QJ d-    V3R lVP'                  4        4       F  '       d   K   R	M"	  R
M! V3R lVP'                  4        4       4       VP'                  4        U	U
u/ uF  w  ršWš,          '       g   K  WšbK  	  pp	p
Mœ\/        V4      '       g   \        V\0        4      '       dk   \        V4      p\"        ;QJ d    V3R lV 4       F  '       d   K   R	M	  R
M! V3R lV 4       4       \!        V U u. uF  q '       g   K  V NK  	  up 4      pM\        R4      hV'       g   \        P                  # \)        R VP'                  4        4       4      p\)        VP%                  4       4      pRp\3        \5        X4      4      pV^8X  d   \-        X4      # \+        V4      pV^,          X8”  d   \        P                  # V^,          V8X  d8   X^8X  d   V^8X  d   \        P6                  # V^,
          V8X  d   \9        V4      # V^	8  d   Ve	   V'       dz   XfR   . p^ p VP'                  4        F9  w  r:\;        V
4       F%  pVP=                  V .V,          4       V ^,          p K'  	  K;  	  \?        \)        R \A        V4       4       4      4      # ^ RI!H"p \?        \G        T! V! V) 4      \I        VP'                  4        U Uu. uF  w  rV! W4      V,          NK  	  upp !  ,          V^ \J        34      4      4      # u up
p	i u up
p	i u up i u upp i )ay  return the number of derangements for: ``n`` unique items, ``i``
items (as a sequence or multiset), or multiplicities, ``m`` given
as a sequence or multiset.

Examples
========

>>> from sympy.utilities.iterables import generate_derangements as enum
>>> from sympy.functions.combinatorial.numbers import nD

A derangement ``d`` of sequence ``s`` has all ``d[i] != s[i]``:

>>> set([''.join(i) for i in enum('abc')])
{'bca', 'cab'}
>>> nD('abc')
2

Input as iterable or dictionary (multiset form) is accepted:

>>> assert nD([1, 2, 2, 3, 3, 3]) == nD({1: 1, 2: 2, 3: 3})

By default, a brute-force enumeration and count of multiset permutations
is only done if there are fewer than 9 elements. There may be cases when
there is high multiplicity with few unique elements that will benefit
from a brute-force enumeration, too. For this reason, the `brute`
keyword (default None) is provided. When False, the brute-force
enumeration will never be used. When True, it will always be used.

>>> nD('1111222233', brute=True)
44

For convenience, one may specify ``n`` distinct items using the
``n`` keyword:

>>> assert nD(n=3) == nD('abc') == 2

Since the number of derangments depends on the multiplicity of the
elements and not the elements themselves, it may be more convenient
to give a list or multiset of multiplicities using keyword ``m``:

>>> assert nD('abc') == nD(m=(1,1,1)) == nD(m={1:3}) == 2

)Ú	integrate)Úlaguerre©rJ   c                ól   € \        V \        4      '       g   \        R 4      hV ^ 8  d   \        R4      hR# )zexpecting integer valueszvalue must not be negativeT)rY  r   rò  r†   rµ  s   &rG   ÚokÚnD.<locals>.ok7  s1   € Ü˜!œZ×(Ò(ÜÐ6Ó7Ð7ØˆqŒ5ÜÐ9Ó:Ð:ÙrI   Nzenter only 1 of i, n, or mz"items must be a list or dictionaryc              3  ó4   <"  € T F  pS! V4      x € K  	  R # 5irr   rg   )rð   r   r·  s   & €rG   rñ   ÚnD.<locals>.<genexpr>I  s   øé € Ð*™z˜!‘�1—�›zùó   ƒFTc              3  óX   <"  € T F  w  rS! V4      ;'       d	    S! V4      x € K!  	  R # 5irr   rg   )rð   rã   rÑ   r·  s   &  €rG   rñ   rº  X  s#   øé € Ð6©I¡D A‘�1“—�™"˜Q›%”«Iùs   ƒ*™*c              3  ó4   <"  € T F  pS! V4      x € K  	  R # 5irr   rg   )rð   rã   r·  s   & €rG   rñ   rº  \  s   øé € Ð!™q˜!‘�1—�›qùr»  zexpecting iterablec              3  ó6   "  € T F  w  rW,          x € K  	  R # 5irr   rg   )rð   r  r$  s   &  rG   rñ   rº  b  s   é € Ð/¡™˜�—’£ùs   ‚c              3  ó&   "  € T F  p^x € K	  	  R# 5ir¨   rg   r†  s   & rG   rñ   rº  y  s   é € Ð?Ñ&> �1Ó&>ùs   ‚)Úexp)&Úsympy.integrals.integralsr³  Ú#sympy.functions.special.polynomialsr´  Ú	sympy.abcrJ   Úcountr†   rY  r   rò  r   rÊ   ÚtyperS  rT  r9   rö   r  r  r2  rø   r$   r;   Ústrr„   Úmaxr£   r#   rD   rl  r   r:   rJ  rÀ  rÚ  r   r   )rã   ÚbruterT   r  r³  r´  rJ   rÐ   Úmsr  r$  rs  ÚcountsÚnkeyÚbigÚnvalrÑ   rÀ  r·  s   &&$$              @rG   ÚnDrÎ    s›  ø€ õX 4Ý<Ýòð 	
ˆa€y‡��tÓ Ô!ÜÐ5Ó6Ð6Øƒ}Ü�aœ×$Ò$ÜÐ@ÓAÐAßÜ—6‘6ˆMÜ�‹7œ$ÓÜ�Q“ˆAÜ˜!“‰BÜ�!‹Wœ‹_ß‹CÔ*˜qŸx™xœzÓ*�C�CŠCÔ*˜qŸx™xœzÓ*Ó*øØ#$§7¡7¤9Ô2¡9™4˜1´”$�!’$¡9ˆBÑ2ØˆAßÜ—6‘6ˆMÜ�—	‘	“ÓˆÜ˜"Ÿ)™)›+Ó&ˆÜ�2‹wŠØ	
ŠÙ
ˆ1ŒßÜ—6‘6ˆMÜ˜A‹ÐØ	
‹Ü�aœ×Òß‹CÔ6¨A¯G©G¬IÓ6�C�CŠCÔ6¨A¯G©G¬IÓ6Ó6øØ'(§w¡w¤yÔ8¡y™t˜q°A·C±C”d�a’d¡yˆFÑ8ˆFÜ�a�[Š[œJ q¬#×.Ò.Ü�Q“ˆAß‹CÔ!™qÓ!�C�CŠCÔ!™qÓ!Ó!øÜ©!Ó1©! Q«qŸq˜q©!Ñ1Ó2‰FäÐ0Ó1Ð1ßÜ—6‘6ˆMÜÑ/ §¡¤Ó/Ó/ˆÜ�6—=‘=“?Ó#ˆØˆÜ
Œc�&‹kÓ
€CØ
ˆa„xÜ˜DÓ!Ð!Üˆv‹;€DØ
ˆ1…uˆq„yÜ�v‰vˆØ
ˆ1…u�„zØ�1Œ9˜ œÜ—5‘5ˆLØ�!�8�sŒ?Ü˜S“>Ð!Øˆ1„u�’§%àŠ9ØˆAØˆAØŸ™ž‘�Ü˜qž�AØ—H‘H˜a˜S �U”OØ˜•F’Aó "ñ 'ô ”sÑ?Ô&;¸AÔ&>Ó?Ó?Ó@Ð@Ý:Ü”3‘y¡ a R£¬Ø&,§l¡l¤nô/6Ù&4™d˜a‰�‹˜×Ð¡nò/6ñ *7õ "7Ø9:¸A¼r¸
óDó Eó Fð Fùóc 3ùó 9ùò 2ùó</6s*   ÄS Ä/S ÉS&ÉS&Ë	S,Ë(S,Ò&S1ry   rx   )NF)Nrw   Frr   r  )Šrl   Ú
__future__r   Úmathr   Úcollectionsr   Útypingr   Ú
sympy.corer   r   r   r	   Úsympy.core.cacher
   Úsympy.core.containersr   Úsympy.core.exprr   Úsympy.core.functionr   r   r   Úsympy.core.logicr   Úsympy.core.mulr   Úsympy.core.numbersr   r   r   r   r   r   Úsympy.core.relationalr   r   r   r   Úsympy.external.gmpyr   r   r   r   r    r!   Ú(sympy.functions.combinatorial.factorialsr"   r#   r$   rJ  r&   Ú$sympy.functions.elementary.piecewiser'   Úsympy.ntheory.factor_r(   r)   r*   r+   r,   Úsympy.ntheory.generater-   Úsympy.ntheory.partitions_r.   r/   Úsympy.ntheory.primetestr0   r1   Úsympy.polys.appellseqsr2   r3   r4   Úsympy.polys.polytoolsr5   Úsympy.utilities.enumerativer6   Úsympy.utilities.exceptionsr8   Úsympy.utilities.iterablesr9   r:   r;   Úsympy.utilities.memoizationr<   Úsympy.utilities.miscr=   rs  r>   r?   Úmpmath.libmpr@   rs   rH   r{   rL   rp   r¦   r®   rÌ   r  r   rh  rŠ  r�  r×  rï  r   r
  r  r  r  r  r*  r0  r5  r?  rG  r  rM  rg  rh  r“  ri  rW  r_  r]  rv  rz  rƒ  r�  r‹  rŠ  r�  r”  r˜  rž  rÎ  rg   rI   rG   Ú<module>rë     sË  ðñõ #Ý Ý #Ý ç ,Ó ,Ý $Ý &Ý  ß OÑ OÝ &Ý ß >× >ß 9Ó 9ß T× T÷ñ å 6Ý :÷_õ _å +ß @ß 6ß LÑ LÝ (Ý BÝ @ß OÑ OÝ 7Ý 'ç Ý &ò!ñ
 ˆcƒ{€ôx+�ô x+ôDNN�ô NNôp*>ˆOô *>ôhP"�ô P"ôtt,�ô t,ô|ODˆ?ô ODôrI%ˆô I%ôf],ˆOô ],ôNH9ˆoô H9ôdB=ˆô B=ôXi,ˆOô i,ôd7�ô 7ôt@j�Oô @jôFEG�_ô EGôP-5�oô -5ô`D3�Oô D3ôN$6�ô $6ôNMˆ_ô Mô`1(ˆoô 1(ôh21�ô 21ôj/Lˆoô /Lôd7Q�oô 7Qôt5ˆoô 5ô~˜ô ð €Ø	€Ù
ˆ4�Ó€ò&ô:?+ðD 	ó1ó 	ð1ðh 	ñ0ó 	ð0ôf[:ò|ð& 	ñó 	ðòð& 	ñó 	ðôi<ðX 	ñ( ó 	ð( ôVwôBz,ˆoô z,ñztF ð tF¨÷ tFrI   