Ask Your Question
0

prime must be a prime in the integers but 2 is not

asked 2025-12-07 11:27:33 +0100

juan gravatar image

I put

v = QQ.valuation(2)

and get the error prime must be a prime in the integers but 2 is not

edit retag flag offensive close merge delete

Comments

It works fine at sagecell. What is your Sage version and what error do you see?

Max Alekseyev gravatar imageMax Alekseyev ( 2025-12-08 12:06:04 +0100 )edit

It is Sage 10.6 the error is after import something:

from sympy import * 123.valuation(3)

AttributeError Traceback (most recent call last) Cell In[2], line 2 1 from sympy import * ----> 2 Integer(123).valuation(Integer(3))

AttributeError: 'Integer' object has no attribute 'valuation'

Yesterday I was trying many things and end with the absurd error " prime must be a prime in the integers but 2 is not" Today I can not reproduce this error, but first it is the one above.

juan gravatar imagejuan ( 2025-12-08 20:44:17 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2025-12-08 20:59:28 +0100

Max Alekseyev gravatar image

updated 2025-12-08 21:33:07 +0100

The problem is caused by from sympy import * overwriting the definition of Sage's Integer class:

print(Integer)
from sympy import * 
print(Integer)

prints:

<class 'sage.rings.integer.Integer'>
<class 'sympy.core.numbers.Integer'>

Possible solutions:

  • import only really needed stuff from sympy, not *
  • or re-import Integer from Sage:

    from sympy import *

    from sage.rings.integer import Integer

  • or explicitly specify the type of 123 - like:

    ZZ(123).valuation(3)

edit flag offensive delete link more

Comments

But still I have problems: I have definitions in a file,I make it minimal with: from sympy import divisors from mpmath import log from sage.rings.integer import Integer

def decompose(n): d=divisors(n)[1] d=ZZ(d) a=d.valuation(2) return a

then with from MinimalExample import * decompose(12345) get an error: name 'ZZ' is not defined

if I eliminate d=ZZ(D) the error is: AttributeError: 'int' object has no attribute 'valuation'

juan gravatar imagejuan ( 2025-12-09 10:45:18 +0100 )edit

Are you running your example from Sage? Otherwise you also need from sage.all import *

Max Alekseyev gravatar imageMax Alekseyev ( 2025-12-09 13:04:54 +0100 )edit

Thank you!!! now it runs correctly.

juan gravatar imagejuan ( 2025-12-09 13:15:55 +0100 )edit

Btw, divisors are present in Sage as well, you don't need sympy for that.

Max Alekseyev gravatar imageMax Alekseyev ( 2025-12-09 13:29:05 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2025-12-07 11:27:33 +0100

Seen: 76 times

Last updated: Dec 08 '25