use more poly_vec functions

This commit is contained in:
Daniel Schultz 2021-05-27 18:34:01 +02:00
parent 040d607ea7
commit 5ef7542e63
11 changed files with 99 additions and 186 deletions

View file

@ -543,6 +543,9 @@ slong fmpz_mod_mpolyn_stack_size(const fmpz_mod_mpolyn_stack_t S)
/* poly_vec ******************************************************************/
FLINT_DLL slong _fmpz_mod_poly_vec_max_degree(const fmpz_mod_poly_struct * A,
slong Alen, const fmpz_mod_ctx_t ctx);
FLINT_DLL void _fmpz_mod_poly_vec_content(fmpz_mod_poly_t g,
const fmpz_mod_poly_struct * A, slong Alen, const fmpz_mod_ctx_t ctx);
@ -599,11 +602,6 @@ void fmpz_mod_polyun_init(fmpz_mod_polyun_t A, const fmpz_mod_ctx_t ctx)
A->exps = NULL;
}
FLINT_DLL void fmpz_mod_polyun_scalar_mul_fmpz(
fmpz_mod_polyun_t A,
const fmpz_t c,
const fmpz_mod_ctx_t ctx);
FLINT_DLL void fmpz_mod_polyun_clear(fmpz_mod_polyun_t A,
const fmpz_mod_ctx_t ctx);
@ -635,18 +633,6 @@ void fmpz_mod_polyun_fit_length(fmpz_mod_polyun_t A, slong len,
fmpz_mod_polyun_realloc(A, len, ctx);
}
FLINT_DLL void fmpz_mod_polyun_content_poly(fmpz_mod_poly_t g,
const fmpz_mod_polyun_t A, const fmpz_mod_ctx_t ctx);
FLINT_DLL void fmpz_mod_polyun_divexact_poly(fmpz_mod_polyun_t A,
const fmpz_mod_poly_t g, const fmpz_mod_ctx_t ctx);
FLINT_DLL void fmpz_mod_polyun_mul_poly(fmpz_mod_polyun_t A,
const fmpz_mod_poly_t g, const fmpz_mod_ctx_t ctx);
FLINT_DLL slong fmpz_mod_polyun_lastdeg(const fmpz_mod_polyun_t A,
const fmpz_mod_ctx_t ctx);
FLINT_DLL void fmpz_mod_polyun_one(fmpz_mod_polyun_t A, const fmpz_mod_ctx_t ctx);
FLINT_DLL void fmpz_mod_mpoly_get_polyu1n(fmpz_mod_polyun_t A,

View file

@ -12,6 +12,15 @@
#include "fmpz_mod_mpoly_factor.h"
slong _fmpz_mod_poly_vec_max_degree(const fmpz_mod_poly_struct * A,
slong Alen, const fmpz_mod_ctx_t ctx)
{
slong i, len = 0;
for (i = 0; i < Alen; i++)
len = FLINT_MAX(len, fmpz_mod_poly_length(A + i, ctx));
return len - 1;
}
void _fmpz_mod_poly_vec_content(
fmpz_mod_poly_t g,
const fmpz_mod_poly_struct * A,

View file

@ -87,17 +87,15 @@ int fmpz_mod_polyu1n_gcd_brown_smprime(
fmpz_mod_polyun_stack_fit_request(St_polyun, 1);
T = fmpz_mod_polyun_stack_take_top(St_polyun);
fmpz_mod_polyun_content_poly(cA, A, ctx);
fmpz_mod_polyun_content_poly(cB, B, ctx);
fmpz_mod_polyun_divexact_poly(A, cA, ctx);
fmpz_mod_polyun_divexact_poly(B, cB, ctx);
_fmpz_mod_poly_vec_remove_content(cA, A->coeffs, A->length, ctx);
_fmpz_mod_poly_vec_remove_content(cB, B->coeffs, B->length, ctx);
_fmpz_mod_poly_gcd_cofactors(cG, cAbar, cBbar, cA, cB, ctx, r);
fmpz_mod_poly_gcd(gamma, A->coeffs + 0, B->coeffs + 0, ctx);
ldegA = fmpz_mod_polyun_lastdeg(A, ctx);
ldegB = fmpz_mod_polyun_lastdeg(B, ctx);
ldegA = _fmpz_mod_poly_vec_max_degree(A->coeffs, A->length, ctx);
ldegB = _fmpz_mod_poly_vec_max_degree(B->coeffs, B->length, ctx);
deggamma = fmpz_mod_poly_degree(gamma, ctx);
bound = 1 + deggamma + FLINT_MAX(ldegA, ldegB);
@ -254,16 +252,15 @@ choose_prime:
successful:
fmpz_mod_polyun_content_poly(r, G, ctx);
fmpz_mod_polyun_divexact_poly(G, r, ctx);
fmpz_mod_polyun_divexact_poly(Abar, G->coeffs + 0, ctx);
fmpz_mod_polyun_divexact_poly(Bbar, G->coeffs + 0, ctx);
_fmpz_mod_poly_vec_remove_content(r, G->coeffs, G->length, ctx);
_fmpz_mod_poly_vec_divexact_poly(Abar->coeffs, Abar->length, G->coeffs + 0, ctx);
_fmpz_mod_poly_vec_divexact_poly(Bbar->coeffs, Bbar->length, G->coeffs + 0, ctx);
successful_put_content:
fmpz_mod_polyun_mul_poly(G, cG, ctx);
fmpz_mod_polyun_mul_poly(Abar, cAbar, ctx);
fmpz_mod_polyun_mul_poly(Bbar, cBbar, ctx);
_fmpz_mod_poly_vec_mul_poly(G->coeffs, G->length, cG, ctx);
_fmpz_mod_poly_vec_mul_poly(Abar->coeffs, Abar->length, cAbar, ctx);
_fmpz_mod_poly_vec_mul_poly(Bbar->coeffs, Bbar->length, cBbar, ctx);
success = 1;

View file

@ -739,7 +739,7 @@ choose_alphas:
}
fmpz_mod_mpoly_get_fmpz(gammaev, gammaevals + m, ctx);
fmpz_mod_polyun_scalar_mul_fmpz(Gev, gammaev, ctx->ffinfo);
_fmpz_mod_poly_vec_mul_fmpz_mod(Gev->coeffs, Gev->length, gammaev, ctx->ffinfo);
fmpz_mod_mpolyn_interp_lift_sm_polyu1n(Gn, Gev, ctx);
fmpz_mod_mpolyn_interp_lift_sm_polyu1n(Abarn, Abarev, ctx);
@ -796,7 +796,7 @@ choose_alphas:
}
fmpz_mod_mpoly_get_fmpz(gammaev, gammaevals + m, ctx);
fmpz_mod_polyun_scalar_mul_fmpz(Gev, gammaev, ctx->ffinfo);
_fmpz_mod_poly_vec_mul_fmpz_mod(Gev->coeffs, Gev->length, gammaev, ctx->ffinfo);
fmpz_mod_poly_eval_pow(c, modulus, alphapow, ctx->ffinfo);
fmpz_mod_inv(c, c, ctx->ffinfo);
@ -1042,20 +1042,13 @@ choose_alphas:
goto choose_alphas;
}
if (use & USE_BBAR)
{
FLINT_ASSERT(fmpz_mod_polyun_is_canonical(Bbarev, ctx->ffinfo));
}
fmpz_mod_polyun_scalar_mul_fmpz(Gev, gammaev, ctx->ffinfo);
_fmpz_mod_poly_vec_mul_fmpz_mod(Gev->coeffs, Gev->length, gammaev, ctx->ffinfo);
if ((use & USE_G) && !fmpz_mod_polyun_add_zip_must_match(ZG, Gev, cur_zip_image))
goto choose_alphas;
if ((use & USE_ABAR) && !fmpz_mod_polyun_add_zip_must_match(ZAbar, Abarev, cur_zip_image))
goto choose_alphas;
if ((use & USE_BBAR) && !fmpz_mod_polyun_add_zip_must_match(ZBbar, Bbarev, cur_zip_image))
goto choose_alphas;
}
if ((use & USE_G) && fmpz_mod_polyun_zip_solve(G, ZG, HG, MG, ctx) < 1)

View file

@ -180,50 +180,6 @@ void fmpz_mod_polyu3n_print_pretty(
}
void fmpz_mod_polyun_content_poly(
fmpz_mod_poly_t g,
const fmpz_mod_polyun_t A,
const fmpz_mod_ctx_t ctx)
{
slong i;
fmpz_mod_poly_zero(g, ctx);
for (i = 0; i < A->length; i++)
fmpz_mod_poly_gcd(g, g, A->coeffs + i, ctx);
}
void fmpz_mod_polyun_divexact_poly(
fmpz_mod_polyun_t A,
const fmpz_mod_poly_t g,
const fmpz_mod_ctx_t ctx)
{
slong i;
for (i = 0; i < A->length; i++)
fmpz_mod_poly_div(A->coeffs + i, A->coeffs + i, g, ctx);
}
void fmpz_mod_polyun_mul_poly(
fmpz_mod_polyun_t A,
const fmpz_mod_poly_t g,
const fmpz_mod_ctx_t ctx)
{
slong i;
for (i = 0; i < A->length; i++)
fmpz_mod_poly_mul(A->coeffs + i, A->coeffs + i, g, ctx);
}
slong fmpz_mod_polyun_lastdeg(
const fmpz_mod_polyun_t A,
const fmpz_mod_ctx_t ctx)
{
slong i, len = 0;
for (i = 0; i < A->length; i++)
len = FLINT_MAX(len, A->coeffs[i].length);
return len - 1;
}
void fmpz_mod_polyun_one(fmpz_mod_polyun_t A, const fmpz_mod_ctx_t ctx)
{
fmpz_mod_polyun_fit_length(A, 1, ctx);
@ -233,17 +189,6 @@ void fmpz_mod_polyun_one(fmpz_mod_polyun_t A, const fmpz_mod_ctx_t ctx)
}
void fmpz_mod_polyun_scalar_mul_fmpz(
fmpz_mod_polyun_t A,
const fmpz_t c,
const fmpz_mod_ctx_t ctx)
{
slong i;
for (i = 0; i < A->length; i++)
fmpz_mod_poly_scalar_mul_fmpz(A->coeffs + i, A->coeffs + i, c, ctx);
}
void fmpz_mod_mpoly_get_polyu1n(
fmpz_mod_polyun_t A,
const fmpz_mod_mpoly_t B,

View file

@ -1291,7 +1291,8 @@ int static _random_check_sp(
if (success)
continue;
n_polyun_scalar_mul_nmod(Geval_sp, Gammaeval_sp, ctx_sp);
_n_poly_vec_mul_nmod_intertible(Geval_sp->coeffs, Geval_sp->length,
Gammaeval_sp, ctx_sp);
FLINT_ASSERT(Geval_sp->length > 0);
*GevaldegXY = n_polyu1n_bidegree(Geval_sp);
@ -1373,8 +1374,8 @@ int static _random_check_mp(
if (!success)
continue;
fmpz_mod_polyun_scalar_mul_fmpz(Geval_mp, Gammaeval_mp, ctx_mp);
_fmpz_mod_poly_vec_mul_fmpz_mod(Geval_mp->coeffs, Geval_mp->length,
Gammaeval_mp, ctx_mp);
FLINT_ASSERT(Geval_mp->length > 0);
*GevaldegXY = fmpz_mod_polyu1n_bidegree(Geval_mp);
@ -1845,7 +1846,8 @@ pick_bma_prime:
FLINT_ASSERT(Geval_sp->length > 0);
GevaldegXY = n_polyu1n_bidegree(Geval_sp);
n_polyun_scalar_mul_nmod(Geval_sp, Gammaeval_sp, ctx_sp);
_n_poly_vec_mul_nmod_intertible(Geval_sp->coeffs, Geval_sp->length,
Gammaeval_sp, ctx_sp);
if (GdegboundXY < GevaldegXY)
{
@ -2058,7 +2060,8 @@ pick_bma_prime:
FLINT_ASSERT(Geval_mp->length > 0);
GevaldegXY = fmpz_mod_polyu1n_bidegree(Geval_mp);
fmpz_mod_polyun_scalar_mul_fmpz(Geval_mp, Gammaeval_mp, ctx_mp);
_fmpz_mod_poly_vec_mul_fmpz_mod(Geval_mp->coeffs, Geval_mp->length,
Gammaeval_mp, ctx_mp);
FLINT_ASSERT(fmpz_equal(Gammaeval_mp, fmpz_mod_polyun_leadcoeff(Geval_mp)));
@ -2270,7 +2273,8 @@ pick_zip_prime:
goto pick_bma_prime;
}
n_polyun_scalar_mul_nmod(Geval_sp, Gammaeval_sp, ctx_sp);
_n_poly_vec_mul_nmod_intertible(Geval_sp->coeffs, Geval_sp->length,
Gammaeval_sp, ctx_sp);
success = n_polyu2n_add_zipun_must_match(ZH,
which_check == 1 ? Abareval_sp :

View file

@ -1863,24 +1863,6 @@ void n_polyun_one(n_polyun_t A)
n_poly_one(A->coeffs + 0);
}
N_POLY_INLINE
void n_polyun_scalar_mul_nmod(
n_polyun_t A,
mp_limb_t c,
nmod_t ctx)
{
slong i;
FLINT_ASSERT(c != 0);
if (c == 1)
return;
for (i = 0; i < A->length; i++)
_n_poly_mod_scalar_mul_nmod_inplace(A->coeffs + i, c, ctx);
}
N_POLY_INLINE
ulong n_polyu1n_bidegree(n_polyun_t A)
{
@ -1889,41 +1871,6 @@ ulong n_polyu1n_bidegree(n_polyun_t A)
return (x << (FLINT_BITS/2)) + y;
}
/* TODO these four can be replaced by n_poly_vec functions */
N_POLY_INLINE
slong n_polyun_lastdeg(n_polyun_t A)
{
slong i, len = 0;
for (i = 0; i < A->length; i++)
len = FLINT_MAX(len, A->coeffs[i].length);
return len - 1;
}
N_POLY_INLINE
void n_polyun_content_last(n_poly_t g, n_polyun_t A, nmod_t ctx)
{
slong i;
n_poly_zero(g);
for (i = 0; i < A->length; i++)
n_poly_mod_gcd(g, g, A->coeffs + i, ctx);
}
N_POLY_INLINE
void n_polyun_divexact_last(n_polyun_t A, const n_poly_t g, nmod_t ctx)
{
slong i;
for (i = 0; i < A->length; i++)
n_poly_mod_div(A->coeffs + i, A->coeffs + i, g, ctx);
}
N_POLY_INLINE
void n_polyun_mul_last(n_polyun_t A, const n_poly_t g, nmod_t ctx)
{
slong i;
for (i = 0; i < A->length; i++)
n_poly_mod_mul(A->coeffs + i, A->coeffs + i, g, ctx);
}
/*****************************************************************************/
FLINT_DLL void n_fq_poly_product_roots_n_fq(n_poly_t M, const mp_limb_t * H,

View file

@ -10,9 +10,9 @@
*/
#include "n_poly.h"
#include "nmod_mpoly_factor.h"
void n_polyu1n_mod_interp_reduce_2sm_poly(
static void n_polyu1n_mod_interp_reduce_2sm_poly(
n_poly_t E,
n_poly_t F,
const n_polyun_t A,
@ -32,7 +32,7 @@ void n_polyu1n_mod_interp_reduce_2sm_poly(
}
}
void n_polyu1n_mod_interp_lift_2sm_poly(
static void n_polyu1n_mod_interp_lift_2sm_poly(
slong * lastdeg,
n_polyun_t F,
const n_poly_t A,
@ -112,7 +112,7 @@ void n_polyu1n_mod_interp_lift_2sm_poly(
return;
}
int n_polyu1n_mod_interp_crt_2sm_poly(
static int n_polyu1n_mod_interp_crt_2sm_poly(
slong * lastdeg,
n_polyun_t F,
n_polyun_t T,
@ -293,10 +293,8 @@ int n_polyu1n_mod_gcd_brown_smprime(
n_polyun_stack_fit_request(St->polyun_stack, 1);
T = n_polyun_stack_take_top(St->polyun_stack);
n_polyun_content_last(cA, A, ctx);
n_polyun_content_last(cB, B, ctx);
n_polyun_divexact_last(A, cA, ctx);
n_polyun_divexact_last(B, cB, ctx);
_n_poly_vec_mod_remove_content(cA, A->coeffs, A->length, ctx);
_n_poly_vec_mod_remove_content(cB, B->coeffs, B->length, ctx);
n_poly_mod_gcd(cG, cA, cB, ctx);
n_poly_mod_div(cAbar, cA, cG, ctx);
@ -304,8 +302,8 @@ int n_polyu1n_mod_gcd_brown_smprime(
n_poly_mod_gcd(gamma, A->coeffs + 0, B->coeffs + 0, ctx);
ldegA = n_polyun_lastdeg(A);
ldegB = n_polyun_lastdeg(B);
ldegA = _n_poly_vec_max_degree(A->coeffs, A->length);
ldegB = _n_poly_vec_max_degree(B->coeffs, B->length);
deggamma = n_poly_degree(gamma);
bound = 1 + deggamma + FLINT_MAX(ldegA, ldegB);
@ -464,16 +462,15 @@ choose_prime: /* primes are v - alpha, v + alpha */
successful:
n_polyun_content_last(modulus, G, ctx);
n_polyun_divexact_last(G, modulus, ctx);
n_polyun_divexact_last(Abar, G->coeffs + 0, ctx);
n_polyun_divexact_last(Bbar, G->coeffs + 0, ctx);
_n_poly_vec_mod_remove_content(modulus, G->coeffs, G->length, ctx);
_n_poly_vec_mod_divexact_poly(Abar->coeffs, Abar->length, G->coeffs + 0, ctx);
_n_poly_vec_mod_divexact_poly(Bbar->coeffs, Bbar->length, G->coeffs + 0, ctx);
successful_put_content:
n_polyun_mul_last(G, cG, ctx);
n_polyun_mul_last(Abar, cAbar, ctx);
n_polyun_mul_last(Bbar, cBbar, ctx);
_n_poly_vec_mod_mul_poly(G->coeffs, G->length, cG, ctx);
_n_poly_vec_mod_mul_poly(Abar->coeffs, Abar->length, cAbar, ctx);
_n_poly_vec_mod_mul_poly(Bbar->coeffs, Bbar->length, cBbar, ctx);
success = 1;

View file

@ -254,17 +254,23 @@ FLINT_DLL void _nmod_mpoly_set_lead0(
/* n_poly_vec ****************************************************************/
FLINT_DLL slong _n_poly_vec_max_degree(const n_poly_struct * A, slong Alen);
FLINT_DLL void _n_poly_vec_mul_nmod_intertible(n_poly_struct * A,
slong Alen, mp_limb_t c, nmod_t ctx);
FLINT_DLL void _n_poly_vec_mod_mul_poly(n_poly_struct * A, slong Alen,
const n_poly_t g, const nmod_t ctx);
FLINT_DLL void _n_poly_vec_mod_divexact_poly(n_poly_struct * A, slong Alen,
const n_poly_t g, nmod_t ctx);
FLINT_DLL void _n_poly_vec_mod_content(n_poly_t g, const n_poly_struct * A,
slong Alen, nmod_t ctx);
FLINT_DLL void _n_poly_vec_mod_remove_content(n_poly_t g, n_poly_struct * A,
slong Alen, nmod_t ctx);
FLINT_DLL void n_polyun_mod_content(n_poly_t c, const n_polyun_t A, nmod_t ctx);
/* polyun ********************************************************************/
FLINT_DLL void nmod_mpoly_get_polyu1n(n_polyun_t A, const nmod_mpoly_t B,

View file

@ -518,10 +518,9 @@ static int _do_bivar_or_univar(
success = n_polyu1n_mod_gcd_brown_smprime(Gev, Abarev, Bbarev,
Aev, Bev, ctx->mod, St);
if (success)
{
n_polyun_mod_content(c, Gev, ctx->mod);
_n_poly_vec_mod_content(c, Gev->coeffs, Gev->length, ctx->mod);
success = n_poly_is_one(c);
nmod_mpoly_set_polyu1n(G, Gev, 0, 1, ctx);
}

View file

@ -11,6 +11,34 @@
#include "nmod_mpoly_factor.h"
slong _n_poly_vec_max_degree(const n_poly_struct * A, slong Alen)
{
slong i, len = 0;
for (i = 0; i < Alen; i++)
len = FLINT_MAX(len, A[i].length);
return len - 1;
}
void _n_poly_vec_mul_nmod_intertible(
n_poly_struct * A,
slong Alen,
mp_limb_t c,
nmod_t ctx)
{
slong i;
FLINT_ASSERT(n_gcd(c, ctx.n) == 1);
if (c == 1)
return;
for (i = 0; i < Alen; i++)
_n_poly_mod_scalar_mul_nmod_inplace(A + i, c, ctx);
}
void _n_poly_vec_mod_mul_poly(
n_poly_struct * A,
slong Alen,
@ -44,35 +72,37 @@ void _n_poly_vec_mod_content(
}
}
void _n_poly_vec_mod_remove_content(
n_poly_t g,
void _n_poly_vec_mod_divexact_poly(
n_poly_struct * A,
slong Alen,
const n_poly_t g,
nmod_t ctx)
{
slong i;
n_poly_t r;
_n_poly_vec_mod_content(g, A, Alen, ctx);
if (n_poly_is_one(g))
return;
n_poly_init(r);
for (i = 0; i < Alen; i++)
{
n_poly_mod_divrem(A + i, r, A + i, g, ctx);
FLINT_ASSERT(n_poly_is_zero(r));
}
n_poly_clear(r);
}
/* TODO get rid of the need for this */
void n_polyun_mod_content(n_poly_t c, const n_polyun_t A, nmod_t ctx)
{
slong i;
n_poly_zero(c);
for (i = 0; i < A->length; i++)
n_poly_mod_gcd(c, c, A->coeffs + i, ctx);
void _n_poly_vec_mod_remove_content(
n_poly_t g,
n_poly_struct * A,
slong Alen,
nmod_t ctx)
{
_n_poly_vec_mod_content(g, A, Alen, ctx);
_n_poly_vec_mod_divexact_poly(A, Alen, g, ctx);
}