As Martin said, this is not a bug. However, the error message itself is 
slightly vague because it only states partition. We could simply run 
sorted(part, reverse=True) before passing it off to create the Partition in 
the SetPartitions __classcall__. This would make the behavior less 
surprising, and our output does not match the input sizes (since it is lex 
based). I think we probably just didn't think about normalizing input here.

Also, I found this bug:

sage: SP = SetPartitions(10, [4,3,2,1])
sage: SP.random_element()
{{1, 2, 4, 5, 7, 8}, {3, 6}, {9}, {10}}

Best,
Travis


On Tuesday, February 15, 2022 at 1:51:32 AM UTC+9 axio...@yahoo.de wrote:

> The argument providing the block sizes is required to be an integer 
> partition (or something that sage can make into an integer partition), as 
> the error message indicates.
>
> One might argue that Partition (and hence SetPartition) should take lists 
> in any order, but this would also increase the likelihood of typos going 
> undetected, I guess.
>
> Martin
>
> On Monday, 14 February 2022 at 13:02:39 UTC+1 mitch...@gmail.com wrote:
>
>> Hello,
>>
>> I am currently working with set partitions and I encountered possible bug 
>> when creating SetPartitions instance with specified partition sizes:
>>
>> ```
>> sage: SetPartitions(10, [4,3,2,1])                                       
>>                                                                     
>> Set partitions of {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} with sizes in [4, 3, 2, 
>> 1]
>> ```
>>
>> The above works, but changing the order of sizes gives error:
>> ```
>> sage: SetPartitions(10, [1,2,3,4])                                       
>>                                                                             
>>                                                               
>>
>> ---------------------------------------------------------------------------
>> ValueError                                Traceback (most recent call 
>> last)
>> <ipython-input-4-90164a225d10> in <module>
>> ----> 1 SetPartitions(Integer(10), 
>> [Integer(1),Integer(2),Integer(3),Integer(4)])
>>
>> /usr/lib/python3/dist-packages/sage/misc/classcall_metaclass.pyx in 
>> sage.misc.classcall_metaclass.ClasscallMetaclass.__call__ 
>> (build/cythonized/sage/misc/classcall_metaclass.c:1714)()
>>     332         """
>>     333         if cls.classcall is not None:
>> --> 334             return cls.classcall(cls, *args, **kwds)
>>     335         else:
>>     336             # Fast version of type.__call__(cls, *args, **kwds)
>>
>> /usr/lib/python3/dist-packages/sage/combinat/set_partition.py in 
>> __classcall_private__(cls, s, part)
>>    2025             else:
>>    2026                 if part not in Partitions(len(s)):
>> -> 2027                     raise ValueError("part must be a partition of 
>> %s"%len(s))
>>    2028                 else:
>>    2029                     return SetPartitions_setparts(s, 
>> Partition(part))
>>
>> ValueError: part must be a partition of 10
>> ```
>>
>> Other orders od partition sizes (other than descending) also gives the 
>> same error:
>> ```
>> sage: SetPartitions(10, [4,2,3,1])
>> <the same error as above> 
>> ```
>>
>> Diferent sets also show this behavior:
>> ```
>> sage: SetPartitions(8, [4,3,1])
>> <OK>                                                                     
>>                                                                             
>>        
>> ```
>>
>> ```
>> sage: SetPartitions(8, [4,3,1])                                           
>>                                                                   
>> <Error>
>> ```
>>
>> The same happens when using sage as a module within Python
>>
>> I am using Sage version 9.0, using Python 3.8.10.
>> Operating system is Ubuntu 20.04.3 (64bit)
>>
>> Best regards,
>> Ondra
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/b046a1ae-e5ec-49c7-8426-6db99a9b3e55n%40googlegroups.com.

Reply via email to