myepsilon = 0.0001; /* The input f should be an integer polynomial in variable x. Checks for symmetry in the polynomial f. Here w is the weight. In the case of a Weil q-polynomial as in the Seminar the weight is 1! */ check_symmetry(f, q, w) = { local(d,c); d = poldegree(f); c = polcoeff(f, 0)/q^(w*d/2); if((c^2 - 1), return(0) ); if((c == 1), if(x^d*q^(-w*d/2)*subst(f, x, q^w/x)-f, return(0) , return(1) ) ); if((c == -1), if(x^d*p^(-w*d/2)*subst(f, x, p^w/x)+f, return(0) , return(1) ) ) } /* This first finds the weight w for the polynomial f. Then it tests whether the roots of f have approximately the correct size. It does not test whether f is irreducible. */ check_weil(f, q)= { local(p,a,d,polygon,w,n,g,lijst,success); p = 2; while(q % p, p++); a = valuation(q, p); if(a,, error("Not OK.")); if(q - p^a, error("Second input should be power of prime!")); d = poldegree(f); polygon = newtonpoly(f, p); w = 2*sum(i = 1, d, polygon[i])/(d*a); lijst = abs(polroots(f)); success = 1; for(i = 1, matsize(lijst)[1], if(((q^(w/2) - myepsilon > lijst[i]) || (lijst[i] > q^(w/2) + myepsilon)), success = 0 ) ); if(success, if(check_symmetry(f, q, w),, print("Strange: Weil polynomial not symmetric!") ) ); return(success) } /* See write-up in Fpol.tex for the meaning of the conditions. */ check_degree_four(f, q)= { local(a,b,c,d); if(poldegree(f, x) - 4, print("Degree has to be 4!"); return(0)); a = polcoeff(f, 3, x); b = polcoeff(f, 2, x); c = polcoeff(f, 1, x); d = polcoeff(f, 0, x); if(c - q*a, return(0)); if(d - q^2, return(0)); if((abs(a) > 4*sqrt(q)), return(0)); if((abs(b) > 6*q), return(0)); if((b >= a^2/4 + 2*q), return(0)); if((b <= 2*abs(a)*sqrt(q) - 2*q), return(0)); return(1) } /* This you can run to see if the conditions found in Fpol.tex are the correct ones. Namely, it tests whether check_weil says yes whenever check_degree_four says yes. Except that check_degree_four disallows reducible polynomials so we have to sift those out. */ test(q)= { local(f,ff,mine,four,lijst); ff = x^4 + aa*x^3 + bb*x^2 + aa*q*x + q^2; for(a = -round(4*sqrt(q)), round(4*sqrt(q)), for(b = -6*q, 6*q, f = subst(subst(ff, aa, a), bb, b); mine = check_weil(f, q); four = check_degree_four(f, q); if(mine - four, lijst = factor(f); if((matsize(lijst)[1] == 1) && (lijst[1, 2] == 1), error("Different output!") ) ) ) ); } /* List all irreducible degree 4 polynomials that give rise to q-Weil numbers of degree 4 over Q. */ list_q_weil(q)= { local(p,aaa,a,b,f,ff,mine,four,lijst); p = 2; while(q % p, p++); aaa = valuation(q, p); if(aaa,, error("Not OK.")); if(q - p^aaa, error("Input should be power of prime!")); ff = x^4 + aa*x^3 + bb*x^2 + aa*q*x + q^2; for(a = -round(4*sqrt(q)), round(4*sqrt(q)), for(b = -6*q, 6*q, f = subst(subst(ff, aa, a), bb, b); four = check_degree_four(f, q); if(four, print(f, "\t\t", newtonpoly(f, p)/aaa) ) ) ) }