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

I put

v = QQ.valuation(2)

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

Comments on the original question

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

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.

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)

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’

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

Thank you!!! now it runs correctly.

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