Polynomial content is the greatest common divisor of all coefficients. Dividing every coefficient by this common factor removes a shared scale before subsequent polynomial algorithms. section 12.1 section 12.4
Compute the content procedurally:
- Initialize the running gcd with the leading coefficient. section 12.2.1
- Process the remaining coefficients with gcd operations. section 12.2.1
- Stop early when the running gcd becomes 1; no later coefficient can change it. section 12.2.1
- Use the resulting gcd to divide every coefficient before computing a resultant. section 12.1 section 12.2
Worked coefficient gcd
For a = 4x^4 + 24x^3 + 12x^2 + 4x + 32, the coefficient gcd is 4, so cont(a) = 4. Removing the content produces a polynomial whose coefficients are divided by 4. section 12.1
Listing 12.1 Content of a polynomial
void poly_cont(mpz_t cont, POLY A)
{
int i;
mpz_t rslt;
mpz_init_set(rslt, A.coef[A.deg]); #1
for(i=A.deg-1; i>=0; i--) #2
{ #2
mpz_gcd(rslt, rslt, A.coef[i]); #3
if(!mpz_cmp_ui(rslt, 1)) #3
break;
}
mpz_set(cont, rslt); #4
mpz_clear(rslt);
}
The routine listing maps the mathematical gcd definition to an implementation using a temporary accumulator, coefficient iteration, early exit, and cleanup. section 12.2.1
