Ask Your Question
0

RuntimeError: Use ** for exponentiation, not '^', which means xor in Python, and has the wrong precedence.

asked 2016-09-26 16:24:06 +0100

randomguy gravatar image

when running this code

x = PolynomialRing(ZZ.quo(N*ZZ), 'x').gen()
e = 3
f = (u1*x + u1*u1)^e - c1
g = (u2*x + u2*u2)^e - c2

I get the error: RuntimeError: Use ** for exponentiation, not '^', which means xor in Python, and has the wrong precedence.

I don't know what's wrong with it. Please help!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-09-26 21:36:11 +0100

niles gravatar image

As the error message says, python uses the double star for exponentiation, as in 2**3 = 8. Sage mostly hides this from the user, but you seem to have something executing in python that is not pre-parsed by Sage.

When I try to copy/paste your code, I get errors that N, u1, u2, c1, c2 are not defined. What values are you using for those? When I tried giving those some integer values, your code ran without error.

sage: N = 11
sage: u1 = 3
sage: u2 = 7
sage: c1 = 1
sage: c2 = -1
sage: x = PolynomialRing(ZZ.quo(N*ZZ), 'x').gen()
sage: e = 3
sage: f = (u1*x + u1*u1)^e - c1
sage: g = (u2*x + u2*u2)^e - c2
sage: f*g
10*x^6 + 3*x^5 + 9*x^3 + 3*x^2 + 9*x + 10
edit flag offensive delete link more
0

answered 2016-09-27 04:25:21 +0100

kcrisman gravatar image
edit flag offensive delete link more

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: 2016-09-26 16:24:06 +0100

Seen: 1,345 times

Last updated: Sep 27 '16