/*
Copyright (C) 2014 William Hart
This file is part of FLINT.
FLINT is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See .
*/
#include
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "fmpz_poly.h"
#include "mpn_extras.h"
void _fmpz_poly_resultant_modular(fmpz_t res, const fmpz * poly1, slong len1,
const fmpz * poly2, slong len2)
{
flint_bitcnt_t bits1, bits2, bound, pbits, curr_bits = 0;
slong i, num_primes;
fmpz_comb_t comb;
fmpz_comb_temp_t comb_temp;
fmpz_t ac, bc, l, modulus;
fmpz * A, * B, * lead_A, * lead_B;
mp_ptr a, b, rarr, parr;
mp_limb_t p;
nmod_t mod;
/* special case, one of the polys is a constant */
if (len2 == 1) /* if len1 == 1 then so does len2 */
{
fmpz_pow_ui(res, poly2, len1 - 1);
return;
}
fmpz_init(ac);
fmpz_init(bc);
/* compute content of poly1 and poly2 */
_fmpz_vec_content(ac, poly1, len1);
_fmpz_vec_content(bc, poly2, len2);
/* divide poly1 and poly2 by their content */
A = _fmpz_vec_init(len1);
B = _fmpz_vec_init(len2);
_fmpz_vec_scalar_divexact_fmpz(A, poly1, len1, ac);
_fmpz_vec_scalar_divexact_fmpz(B, poly2, len2, bc);
/* get product of leading coefficients */
fmpz_init(l);
lead_A = A + len1 - 1;
lead_B = B + len2 - 1;
fmpz_mul(l, lead_A, lead_B);
/* set size of first prime */
pbits = FLINT_BITS - 1;
p = (UWORD(1)<length;
slong len2 = poly2->length;
if (len1 == 0 || len2 == 0)
fmpz_zero(res);
else if (len1 >= len2)
_fmpz_poly_resultant_modular(res, poly1->coeffs, len1, poly2->coeffs, len2);
else
{
_fmpz_poly_resultant_modular(res, poly2->coeffs, len2, poly1->coeffs, len1);
if ((len1 > 1) && (!(len1 & WORD(1)) & !(len2 & WORD(1))))
fmpz_neg(res, res);
}
}