\\ --------------- GP code --------------------------------------- \\ \\ Time-stamp: \\ \\ Description: Routines for operating with binary positive definite \\ quadratic forms. \\ \\ \\ Original author: Ariel Pacetti \\ apacetti@math.utexas.edu \\ University of Texas at Austin \\ \\ Created: Wed Sep 27 2000 \\ \\====================================================================== \\ Given a polynomial, answers the terms containing the variable x polvar(p,x)=simplify(p-subst(p,x,0)) \\====================================================================== \\ Given a polynomial, reduces the coefficient (just the numbers) mod q. polcoefmod(pol,q)= {local(aux,aux2); aux=monomials(pol); for(k=1,length(aux),aux2=polleadint(aux[k]); aux[k]=aux[k]/aux2*(aux2%q)); sum(k=1,length(aux),aux[k])} \\====================================================================== \\Given a polynomial, computes a vector with all the monomials monomials(pol)= {local(aux,n,ans); aux=pol; ans=[]; n=length(pol); aux=simplify(Vec(pol)); for(k=1,n-1,if(aux[k]!=0, if(ismonomial(aux[k]),ans=concat(ans,aux[k]*variable(pol)^(n-k)), ans=concat(ans,monomials(aux[k])*variable(pol)^(n-k))))); if(aux[n]!=0, if(ismonomial(aux[n]),ans=concat(ans,simplify(aux[n])), ans=concat(ans,monomials(aux[n])))); ans } \\====================================================================== \\ Determines if a polynomial is a monomial ismonomial(pol)= {local(aux); aux=pol; if(aux==0,return(0)); if(poldegree(aux)<=0,return(1)); while(poldegree(aux)>0, if(aux-pollead(aux)*variable(aux)^(poldegree(aux))!=0,return(0)); aux=pollead(aux)); 1} \\====================================================================== \\ Given a monomial, gives a vector of it's variables monomialvariables(pol)= {local(ans); if(pol==0, return([])); if(ismonomial(pol),,error("not a monomial")); ans=Set(); while(poldegree(pol)>0, ans=setunion(ans,Set(variable(pol))); pol=subst(pol,variable(pol),1)); eval(ans)} \\====================================================================== \\ Given a polynomial, gives a vector of the variables. variables(pol)= {local(ans,aux,aux2); if(pol==0,return([])); aux=monomials(pol); ans=Set(); for(k=1,length(aux), ans=setunion(ans,Set(monomialvariables(aux[k])))); eval(ans)} \\====================================================================== \\ Given a monomial, computes the integer lead coefficient. If the \\ monomial is actually a polynomial, answers some coefficient. polleadint(pol)= {if(pol==0,return(0)); while(poldegree(pol)>0, pol=pollead(pol)); pol} \\====================================================================== \\ Computes the total degree of a polynomial poltotaldegree(pol)= {local(aux); aux=monomials(pol); aux=vector(length(aux),n,monomialtotaldegree(aux[n])); vecmax(aux)} \\====================================================================== \\ Given a monomial, computes it's total degree monomialtotaldegree(mon)= {local(aux,ans); if(mon==0,return(-1)); aux=variables(mon); ans=0; for(k=1,length(aux),ans=ans+poldegree(mon,aux[k])); ans} {helppolynomials()= print("-------------------------------------------------------------------"); print(" Computational number Theory "); print("-------------------------------------------------------------------"); print(""); print("Description: Elementary routines for dealing with polynomials in "); print("several variables"); print(""); print("Original Authors: Fernando Rodriguez-Villegas"); print(" villegas@math.utexas.edu"); print(" University of Texas at Austin"); print(""); print(" Ariel Pacetti"); print(" apacetti@math.utexas.edu"); print(" University of Texas at Austin"); print("-------------------------------------------------------------------"); print(""); print("List of routines "); print(""); print("polvar polcoefmod monomials ismonomial"); print("monomialvariables variables polleadint"); print(""); } addhelp(polvar,"polvar(pol,x) Answers a polynomial containing just the monomials of the polynomial pol that contains the variable x"); addhelp(polcoefmod," Given an integer, just reduces the integer coeficients module q"); addhelp(monomials,"Given a polynomial, just answers a vector, containing one monomial in each component (in lexicographic order)"); addhelp(ismonomial,"Answers 0, or 1, depending if the polynomial given is just a monomial"); addhelp(monomialvariables,"Answers a vector containing all the variables involved in the given monomial"); addhelp(variables,"Given a polynomial in several variables, answers a vector, containing all the variables involved"); addhelp(polleadint,"Given a monomial, computes the integer leading coefficient. If the input is actually a polynomial, answers some coefficinet.")