Ask Your Question
1

Modulo on polynomial returns negative coefficients

asked 2025-05-05 22:00:59 +0200

WaterOnMountain gravatar image

Executing the following code on Sagecell:

R.<x> = PolynomialRing(ZZ)
f=-7x^4 + 3x^3 - 4*x^2 - x - 6
f%5

I get the following output:

3*x^4 + 3*x^3 - 4*x^2 - x + 4

Why are there negative coefficients on the output? The output should be:

3*x^4 + 3*x^3 +x^2 +4*x + 4

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2025-05-06 07:31:04 +0200

WaterOnMountain gravatar image

updated 2025-05-06 16:07:32 +0200

Max Alekseyev gravatar image

Ok, I found out that f%5 does not work exactly how I thought it did, it does not apply mod 5 to all coefficients. Instead we should use a ring to do the modular:

R.<x> = PolynomialRing(ZZ)     
f=-7*x^4 + 3*x^3 - 4*x^2 - x - 5   
Rmod.<x> = PolynomialRing(Integers(5))   
Rmod(f)

The above will output:

3*x^4 + 3*x^3 + x^2 + 4*x + 4

edit flag offensive delete link more

Comments

f.change_ring(Zmod(5)) is a bit simpler.

Max Alekseyev gravatar imageMax Alekseyev ( 2025-05-06 12:39:21 +0200 )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

1 follower

Stats

Asked: 2025-05-05 22:00:59 +0200

Seen: 101 times

Last updated: May 06