
    \hU                     h    S r SSKrSSKJr  SSKJr  SSKJr  SSKJ	r	   " S S\5      r
S	 rS
 rS rg)z
The Schur number S(k) is the largest integer n for which the interval [1,n]
can be partitioned into k sum-free sets.(https://mathworld.wolfram.com/SchurNumber.html)
    N)S)Basic)Function)Integerc                   .    \ rS rSrSr\S 5       rS rSrg)SchurNumber   a  
This function creates a SchurNumber object
which is evaluated for `k \le 5` otherwise only
the lower bound information can be retrieved.

Examples
========

>>> from sympy.combinatorics.schur_number import SchurNumber

Since S(3) = 13, hence the output is a number
>>> SchurNumber(3)
13

We do not know the Schur number for values greater than 5, hence
only the object is returned
>>> SchurNumber(6)
SchurNumber(6)

Now, the lower bound information can be retrieved using lower_bound()
method
>>> SchurNumber(6).lower_bound()
536

c                 @   UR                   (       a  U[        R                  L a  [        R                  $ UR                  (       a  [        R                  $ UR
                  (       a  UR                  (       a  [        S5      eSSSSSS.nUS::  a  [        X!   5      $ g g )	Nzk should be a positive integer         ,      )r         r      r   )		is_Numberr   Infinityis_zeroZero
is_integeris_negative
ValueErrorr   )clskfirst_known_schur_numberss      X/var/www/auris/envauris/lib/python3.13/site-packages/sympy/combinatorics/schur_number.pyevalSchurNumber.eval'   sx    ;;AJJzz!yyvv<<1== !ABB,-!rc(J%Av8;<<      c                     U R                   S   nUS:X  a  [        S5      $ US:X  a  [        S5      $ UR                  (       a(  SU R                  US-
  5      R	                  5       -  S-
  $ SU-  S-
  S-  $ )	Nr      i     i  r   r   r   )argsr   
is_Integerfunclower_bound)selff_s     r   r'   SchurNumber.lower_bound4   sp    YYq\73<74= ==TYYrAv&2244q882	1}r     N)	__name__
__module____qualname____firstlineno____doc__classmethodr   r'   __static_attributes__r+   r    r   r   r      s     4 
= 
=
r    r   c                     U [         R                  L a  [        S5      eU S::  a  [        S5      eU S::  a  SnO1[        R                  " [        R
                  " SU -  S-   S5      5      n[        U5      $ )NzInput must be finiter   z&n must be a non-zero positive integer.r   r   r   )r   r   r   mathceillogr   )nmin_ks     r   _schur_subsets_numberr9   A   sc    AJJ/00AvABB	
a		$((1Q37A./5>r    c                    [        U [        5      (       a  U R                  (       d  [        S5      e[	        U 5      nU S:X  a  S//nO U S:X  a  SS//nOU S:X  a  / SQ/nOSS/SS//n[        U5      U:  a]  [        X 5      n[        [        U5      U S-
  S-  S-   5       Vs/ s H  nSU-  S-   PM     nnUS==   U-  ss'   [        U5      U:  a  M]  U$ s  snf )a  

This function returns the partition in the minimum number of sum-free subsets
according to the lower bound given by the Schur Number.

Parameters
==========

n: a number
    n is the upper limit of the range [1, n] for which we need to find and
    return the minimum number of free subsets according to the lower bound
    of schur number

Returns
=======

List of lists
    List of the minimum number of sum-free subsets

Notes
=====

It is possible for some n to make the partition into less
subsets since the only known Schur numbers are:
S(1) = 1, S(2) = 4, S(3) = 13, S(4) = 44.
e.g for n = 44 the lower bound from the function above is 5 subsets but it has been proven
that can be done with 4 subsets.

Examples
========

For n = 1, 2, 3 the answer is the set itself

>>> from sympy.combinatorics.schur_number import schur_partition
>>> schur_partition(2)
[[1, 2]]

For n > 3, the answer is the minimum number of sum-free subsets:

>>> schur_partition(5)
[[3, 2], [5], [1, 4]]

>>> schur_partition(8)
[[3, 2], [6, 5, 8], [1, 4, 7]]
zInput value must be a numberr   r   r   )r   r   r   r   )
isinstancer   r   r   r9   len_generate_next_listrange)r7   number_of_subsetssum_free_subsetsr   missed_elementss        r   schur_partitionrC   O   s    ^ !UAKK788-a0AvC5	
aF8	
a%;FQF+

"3
3./?C,1#6F2G!A#PQTU,VW,Vq1Q37,VW/ 
"3
3
  Xs   "Cc                    / nU  H\  nU Vs/ s H  oDS-  U::  d  M  US-  PM     nnU Vs/ s H  oDS-  S-
  U::  d  M  US-  S-
  PM     nnXV-   nUR                  U5        M^     [        [        U 5      S-   5       Vs/ s H  nSU-  S-   U::  d  M  SU-  S-   PM     n	nUR                  U	5        Un U $ s  snf s  snf s  snf )Nr   r   )appendr?   r=   )
current_listr7   new_listitemnumbertemp_1temp_2new_itemr   	last_lists
             r   r>   r>      s    H)-?vQ(&(?-1GT6AX\Q5F,&(Q,TG?!	  #(L(9!(;"<M"<Q!a11q"<IMOOIL @G Ns    B5	B5B:B:>B?B?)r0   r4   
sympy.corer   sympy.core.basicr   sympy.core.functionr   sympy.core.numbersr   r   r9   rC   r>   r+   r    r   <module>rR      s9      " ( &2( 2jAHr    