K iUhdZddlZddlmZddlmZddlmZddlm Z GddeZ 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&eZdZdZedZdZy) 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|jr}|tjurtjS|jrtjS|j r |j r tddddddd}|dkrt||Syy) Nzk should be a positive integer ,)r r r) is_NumberrInfinityis_zeroZero is_integer is_negative ValueErrorr)clskfirst_known_schur_numberss f/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/combinatorics/schur_number.pyevalzSchurNumber.eval'sz ;;AJJzz!yyvv <<1== !ABB,-!rc(J %Av8;<< c|jd}|dk(r tdS|dk(r tdS|jr(d|j|dz j zdz Sd|zdz dz S) Nriirr r)argsr is_Integerfunc lower_bound)selff_s rr%zSchurNumber.lower_bound4sp YYq\ 73<  74= ==TYYrAv&2244q8 82 1}rN)__name__ __module__ __qualname____doc__ classmethodrr%rrrr s 4 = = rrc|tjur td|dkr td|dkr d}t |Stjtj d|zdzd}t |S)NzInput must be finiterz&n must be a non-zero positive integer.rr r)rrrmathceillogr)nmin_ks r_schur_subsets_numberr4AsqAJJ/00AvABB a 5> $((1Q37A./ 5>rct|tr|js tdt |}|dk(rdgg}n|dk(rddgg}n|dk(rgdg}nddgddgg}t ||krYt ||}tt ||dz dzdzDcgc] }d|zdz }}|dxx|z cc<t ||krY|Scc}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]] zInput value must be a numberr rr)r rrr ) isinstancerrrr4len_generate_next_listrange)r2number_of_subsetssum_free_subsetsrmissed_elementss rschur_partitionr>Os^!UAKK788-a0AvC5 aF8 a%;FQF+  "3 3./?C,1#6F2G!A#PQTU,VWq1Q37WW/  "3 3 XsCclg}|D]T}|Dcgc]}|dz|ks |dz}}|Dcgc]}|dzdz |ks|dzdz }}||z}|j|Vtt|dzDcgc]}d|zdz|ksd|zdz} }|j| |}|Scc}wcc}wcc}w)Nrr )appendr:r8) current_listr2new_listitemnumbertemp_1temp_2new_itemr last_lists rr9r9sH")-?vQ&(??-1G6VAX\Q5F&(Q,GGF?! " #(L(9!(;"<MQ!a1 1qMIM OOIL @GNs B'B'B, B,5B1 B1)r+r/ sympy.corersympy.core.basicrsympy.core.functionrsympy.core.numbersrrr4r>r9r-rrrMs9 "(&2(2j AH r