Charles Greathouse on Sat, 04 Jun 2011 01:41:01 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

leading_term and constant_term / lg in polynomials


These inline functions are almost too simple to be wrong, but I'm
finding bizarre behavior.  Minimal test function:

long
test(GEN f)
{
	if (typ(f) != t_POL)
		pari_err(typeer, "test");
	GEN LEAD = leading_term(f);
	if (!isint1(LEAD)) {
		pari_printf("%Ps: Leading term is %Ps; polynomial has length %d.
Constant term: %Ps.\n", f, LEAD, lg(f), constant_term(f));
		return 0;
	}
	return 1;
}

Loading into gp via gp2c, I get

>test(x^2-1)
-x + 1: Leading term is -1; polynomial has length 4. Constant term: 1.
%1 = 0
>test(x^3-1)
%2 = 1
>test(x^4-1)
-x^2 + 1: Leading term is -1; polynomial has length 5. Constant term: 1.
%3 = 0
>test(2*x^4-1)
2*x^4 - 1: Leading term is 2; polynomial has length 7. Constant term: -1.
%4 = 0

with errors for x^n - 1 where n is a power of 2.  The lengths of the
polynomials seem to be off for some reason in those cases.

Am I doing something stupid, or is this a bug?

Charles Greathouse
Analyst/Programmer
Case Western Reserve University