Ask Your Question
1

Iterate over all homogeneous polynomials of a certain degree

asked 2019-12-13 18:32:49 +0100

seagriffin gravatar image

I'd like to iterate over all cubic equations in four variables over a (small) finite field and count their rational points. What is the easiest way to iterate over all homogeneous polynomials of a certain degree?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-12-14 19:43:29 +0100

rburing gravatar image

Define a polynomial ring and the desired degree of your homogeneous polynomials:

R.<x,y,z,w> = PolynomialRing(GF(2))
degree = 3

A monomial should be a product of degree many variables (where some can coincide):

from itertools import combinations_with_replacement
monomials = [prod(c) for c in combinations_with_replacement(R.gens(), degree)]

Choose coefficients in all possible ways:

from itertools import product
polynomials = [sum(c*m for (c,m) in zip(coeffs, monomials)) for coeffs in product(R.base_ring(), repeat=len(monomials))]

Note not all of these give meaningfully different equations, e.g. $F=0$ is equivalent to $cF=0$ for $c\neq 0$, and many are related by coordinate changes.

You can define $\mathbb{P}^3$ as

P3 = ProjectiveSpace(3, R.base_ring(), names=R.gens())

so you can do e.g.

sage: P3.subscheme(polynomials[50]).point_set()
Set of rational points of Closed subscheme of Projective Space of dimension 3 over Finite Field of size 2 defined by:
  y^2 + y*z + z*w
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

1 follower

Stats

Asked: 2019-12-13 18:32:49 +0100

Seen: 388 times

Last updated: Dec 14 '19