Exemple #1
0
void fq_nmod_neg(fq_nmod_t rop, const fq_nmod_t op, const fq_nmod_ctx_t ctx)
{
    slong len = op->length;

    nmod_poly_fit_length(rop, len);
    _nmod_poly_set_length(rop, len);

    nmod_poly_neg(rop, op);
}
Exemple #2
0
void
nmod_poly_randtest_pentomial(nmod_poly_t poly, flint_rand_t state, slong len)
{
    nmod_poly_fit_length(poly, len);
    _nmod_vec_zero(poly->coeffs, len);
    poly->coeffs[0] = n_randtest(state) % poly->mod.n;
    poly->coeffs[1] = n_randtest(state) % poly->mod.n;
    poly->coeffs[2] = n_randtest(state) % poly->mod.n;
    poly->coeffs[3] = n_randtest(state) % poly->mod.n;
    poly->coeffs[len - 1] = 1;
    _nmod_poly_set_length(poly, len);
}
Exemple #3
0
void
nmod_poly_randtest_trinomial(nmod_poly_t poly, flint_rand_t state, slong len)
{
    ulong k;
    nmod_poly_fit_length(poly, len);
    _nmod_vec_zero(poly->coeffs, len);
    poly->coeffs[0] = n_randtest(state) % poly->mod.n;
    poly->coeffs[len - 1] = 1;
    k = (n_randtest(state) % (len - 2)) + 1;
    poly->coeffs[k] = n_randtest(state) % poly->mod.n;
    _nmod_poly_set_length(poly, len);
}
Exemple #4
0
void fq_nmod_pow(fq_nmod_t rop, const fq_nmod_t op, const fmpz_t e, const fq_nmod_ctx_t ctx)
{
    if (fmpz_sgn(e) < 0)
    {
        flint_printf("Exception (fq_nmod_pow).  e < 0.\n");
        abort();
    }

    if (fmpz_is_zero(e))
    {
        fq_nmod_one(rop, ctx);
    }
    else if (fq_nmod_is_zero(op, ctx))
    {
        fq_nmod_zero(rop, ctx);
    }
    else if (fmpz_is_one(e))
    {
        fq_nmod_set(rop, op, ctx);
    }
    else
    {
        const slong d = fq_nmod_ctx_degree(ctx);
        mp_limb_t *t;

        if (rop == op)
        {
            t = _nmod_vec_init(2 * d - 1);
        }
        else
        {
            nmod_poly_fit_length(rop, 2 * d - 1);
            t = rop->coeffs;
        }

        _fq_nmod_pow(t, op->coeffs, op->length, e, ctx);

        if (rop == op)
        {
            _nmod_vec_clear(rop->coeffs);
            rop->coeffs = t;
            rop->alloc  = 2 * d - 1;
            rop->length = d;
        }
        else
        {
            _nmod_poly_set_length(rop, d);
        }
        _nmod_poly_normalise(rop);
    }
}
Exemple #5
0
void
_fmpz_vec_get_nmod_poly(nmod_poly_t res, const fmpz * coeffs, slong len)
{
    if (len == 0)
    {
        nmod_poly_zero(res);
    }
    else
    {
        slong i;
        nmod_poly_fit_length(res, len);
        for (i = 0; i < len; i++)
            res->coeffs[i] = fmpz_fdiv_ui(coeffs + i, res->mod.n);
        _nmod_poly_set_length(res, len);
        _nmod_poly_normalise(res);
    }
}