HP Forums

Full Version: Polynomial Homogeneous Test (CAS)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
A polynomial is homogeneous if all of the nonzero terms has the same degree. Tests a polynomial of four variables x, y, z, and t and their combinations (x*y, x*z, x*y*z, etc). If the polynomial in question is homogeneous, the program returns a 1 (for true), otherwise 0 is returned (for false).

HP Prime Program ishomogeneous
Code:
#cas
ishomogeneous(poly):=
BEGIN
// 2016-08-03 EWS
// x,y,z,t
LOCAL tms,cnt,pt,lst,wp,dg,dgr;
tms:=part(poly);
lst:={};

FOR pt FROM 1 TO tms DO
wp:=part(poly,pt);
dg:=degree(wp,x)+degree(wp,y)+
degree(wp,z)+degree(wp,t);
lst:=concat(lst,{dg});

// test
IF pt≥2 THEN
IF lst(pt)≠lst(pt-1) THEN
RETURN 0;
KILL;
END;
END;

END;
return 1;
END;
#end


Examples:
ishomogeneous(x^2 + 3) returns 0
ishomogeneous(x^2 + 3*y^2) returns 1 (all terms are of degree 2)
ishomogeneous(x^2*z – 3*y^2*t + x^3) returns 1 (all terms are of degree 3)
ishomogeneous(x^2*z – 3*y^2) returns 0

Source:

Avner Ash and Robert Gross. “Elliptic Tales. Curves, Counting, and Number Theory” Princeton University Press, New Jersey 2016.
Reference URL's