ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 14 Dec 2019 19:43:29 +0100Iterate over all homogeneous polynomials of a certain degreehttps://ask.sagemath.org/question/49027/iterate-over-all-homogeneous-polynomials-of-a-certain-degree/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?Fri, 13 Dec 2019 18:32:49 +0100https://ask.sagemath.org/question/49027/iterate-over-all-homogeneous-polynomials-of-a-certain-degree/Answer by rburing for <p>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?</p>
https://ask.sagemath.org/question/49027/iterate-over-all-homogeneous-polynomials-of-a-certain-degree/?answer=49034#post-id-49034Define 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*wSat, 14 Dec 2019 19:43:29 +0100https://ask.sagemath.org/question/49027/iterate-over-all-homogeneous-polynomials-of-a-certain-degree/?answer=49034#post-id-49034