Importing sympy breaks CyclotomicField

25 views
Skip to first unread message

Александр Каренин (alexKar)

unread,
Aug 18, 2023, 4:33:13 AMAug 18
to sage-support
    from sympy import *
and then trying to construct a CyclotomicField as
   K = CyclotomicField(32)
results in an error:
   TypeError: unable to coerce <class 'sympy.core.numbers.Integer'> to an integer
This seems to be a bug.  The NumberField class does not seem to be affected. Importing sympy as:
   import sympy
seems to work for me. Specs: Ubuntu 22.04. Checked on Sage 9.8 and 10.0.

Knd regards,
Alexander

Jan Groenewald

unread,
Aug 18, 2023, 5:02:44 AMAug 18
to sage-s...@googlegroups.com
Hi

I am not sure that is a bug...

sage: K = CyclotomicField(32)
sage: type(Integer)
<class 'sage.misc.inherit_comparison.InheritComparisonMetaclass'>
sage: from sympy import *
sage: type(Integer)
<class 'sympy.core.assumptions.ManagedProperties'>
sage: K = CyclotomicField(int(32))
sage:

Regards,
Jan


--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/ed0a8b32-f9e4-415e-ad95-41796a51b4dfn%40googlegroups.com.

Dima Pasechnik

unread,
Aug 18, 2023, 5:30:30 AMAug 18
to sage-s...@googlegroups.com
On Fri, Aug 18, 2023 at 12:02 PM Jan Groenewald
<jan.gro...@gmail.com> wrote:
>
> Hi
>
> I am not sure that is a bug...
>
> sage: K = CyclotomicField(32)
> sage: type(Integer)
> <class 'sage.misc.inherit_comparison.InheritComparisonMetaclass'>
> sage: from sympy import *
> sage: type(Integer)
> <class 'sympy.core.assumptions.ManagedProperties'>
> sage: K = CyclotomicField(int(32))

I don't think it's a bug - "Integer" is not a reserved Python word,
and thus any Python module can play fast and loose with it.


> sage:
>
> Regards,
> Jan
>
>
> On Fri, 18 Aug 2023 at 10:33, Александр Каренин (alexKar) <tremel...@gmail.com> wrote:
>>
>> As reported in https://ask.sagemath.org/question/72642/does-sympy-break-cyclotomicfield/ , importing sympy as
>> from sympy import *
>> and then trying to construct a CyclotomicField as
>> K = CyclotomicField(32)
>> results in an error:
>> TypeError: unable to coerce <class 'sympy.core.numbers.Integer'> to an integer
>> This seems to be a bug. The NumberField class does not seem to be affected. Importing sympy as:
>> import sympy
>> seems to work for me. Specs: Ubuntu 22.04. Checked on Sage 9.8 and 10.0.
>>
>> Knd regards,
>> Alexander
>>
>> --
>> You received this message because you are subscribed to the Google Groups "sage-support" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/ed0a8b32-f9e4-415e-ad95-41796a51b4dfn%40googlegroups.com.
>
> --
> You received this message because you are subscribed to the Google Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/CAAg%3Dp_3UF7RjMb7nQdsZg%2Bqd%2BsktREEK%2Ba67pnHxsMUSgQz5Uw%40mail.gmail.com.

Nils Bruin

unread,
Aug 18, 2023, 8:08:02 PMAug 18
to sage-support
Perhaps superfluously: the reason why redefining `Integer` (in your example through "from sympy import *") can break a command in sage that does not seem to involve `Integer`:

sage: preparse("K = CyclotomicField(32)")
'K = CyclotomicField(Integer(32))'

Due to Sage's preparser, any use of integer constants involves `Integer`. Even calling `int` on them:

sage: preparse("int(32)")
'int(Integer(32))'

there is a special postfix you can use to really get a python int, without involvement of `Integer`:

sage: preparse("32r")
'32'

Vincent Delecroix

unread,
Aug 20, 2023, 4:49:09 PMAug 20
to sage-s...@googlegroups.com
I imagine the preparser could be made more robust with

sage: preparse("32")
'sage.rings.integer.Integer(32)'
> --
> You received this message because you are subscribed to the Google Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/d2e07668-8b64-4f07-853d-1a41d9a458fen%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages