
    wgU                     h    d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	  G d de      Z
d	 Zd
 Zd Zy)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                   &    e Zd ZdZed        Zd Zy)SchurNumbera\  
    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                    |j                   r}|t        j                  u rt        j                  S |j                  rt        j                  S |j
                  r|j                  rt        d      dddddd}|dk  rt        ||         S y y )	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      e/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/combinatorics/schur_number.pyevalzSchurNumber.eval'   sz    ;;AJJzz!yyvv<<1== !ABB,-!rc(J%Av8;<<      c                     | j                   d   }|dk(  rt        d      S |dk(  rt        d      S |j                  r(d| j                  |dz
        j	                         z  dz
  S d|z  dz
  dz  S )	Nr      i     i  r   r
   r   )argsr   
is_Integerfunclower_bound)selff_s     r   r%   zSchurNumber.lower_bound4   sp    YYq\73<74= ==TYYrAv&2244q882	1}r   N)__name__
__module____qualname____doc__classmethodr   r%    r   r   r   r      s     4 
= 
=
r   r   c                     | t         j                  u rt        d      | dk  rt        d      | dk  rd}t        |      S t        j                  t        j
                  d| z  dz   d            }t        |      S )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_numberr4   A   sq    AJJ/00AvABB	
a 5> 		$((1Q37A./5>r   c                    t        | t              r| j                  st        d      t	        |       }| dk(  rdgg}n| dk(  rddgg}n| dk(  rg dg}nddgddgg}t        |      |k  rYt        ||       }t        t        |      | dz
  dz  dz         D cg c]
  }d|z  dz    }}|dxx   |z  cc<   t        |      |k  rY|S c c}w )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   r4   len_generate_next_listrange)r2   number_of_subsetssum_free_subsetsr   missed_elementss        r   schur_partitionr>   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Wq1Q37WW/ 
"3
3
  Xs   Cc                 l   g }| D ]T  }|D cg c]  }|dz  |k  s|dz   }}|D cg c]  }|dz  dz
  |k  s|dz  dz
   }}||z   }|j                  |       V t        t        |       dz         D cg c]  }d|z  dz   |k  sd|z  dz    }	}|j                  |	       |} | S c c}w c c}w c c}w )Nr   r
   )appendr:   r8   )
current_listr2   new_listitemnumbertemp_1temp_2new_itemr   	last_lists
             r   r9   r9      s    H ")-?vQ&(??-1G6VAX\Q5F&(Q,GGF?!	" #(L(9!(;"<MQ!a11qMIMOOIL @G Ns    B'B'B,
B,5B1
B1)r+   r/   
sympy.corer   sympy.core.basicr   sympy.core.functionr   sympy.core.numbersr   r   r4   r>   r9   r-   r   r   <module>rM      s9      " ( &2( 2jAHr   