Skip to content

Commit

Permalink
Merge pull request #2047 from GiacomoPope/fix_fq_default_poly_evaluat…
Browse files Browse the repository at this point in the history
…e_fq_default

Correct FQ_DEFAULT_TYPE comparison in evaluation
  • Loading branch information
fredrik-johansson authored Sep 9, 2024
2 parents 6c38679 + 848c2f9 commit 3dbe239
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/fq_default_poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,7 @@ void fq_default_poly_evaluate_fq_default(fq_default_t res,
{
res->nmod = nmod_poly_evaluate_nmod(f->nmod, a->nmod);
}
else if (_FQ_DEFAULT_TYPE(ctx) == _FQ_DEFAULT_NMOD)
else if (_FQ_DEFAULT_TYPE(ctx) == _FQ_DEFAULT_FMPZ_MOD)
{
fmpz_mod_poly_evaluate_fmpz(res->fmpz_mod, f->fmpz_mod, a->fmpz_mod,
FQ_DEFAULT_CTX_FMPZ_MOD(ctx));
Expand Down
4 changes: 3 additions & 1 deletion src/fq_default_poly/test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
#include "t-init.c"
#include "t-inlines.c"
#include "t-set_fmpz_poly.c"
#include "t-evaluate_fq_default.c"

/* Array of test functions ***************************************************/

test_struct tests[] =
{
TEST_FUNCTION(fq_default_poly_init),
TEST_FUNCTION(fq_default_poly_inlines),
TEST_FUNCTION(fq_default_poly_set_fmpz_poly)
TEST_FUNCTION(fq_default_poly_set_fmpz_poly),
TEST_FUNCTION(fq_default_poly_evaluate)
};

/* main function *************************************************************/
Expand Down
82 changes: 82 additions & 0 deletions src/fq_default_poly/test/t-evaluate_fq_default.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Copyright (C) 2021 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 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "test_helpers.h"
#include "fq_default_poly.h"

TEST_FUNCTION_START(fq_default_poly_evaluate, state)
{
int i, result;
fmpz_t p;
fq_default_ctx_t ctx;

fmpz_init(p);

/* Given a random fq_default_ctx, compute two random polynomials f1, f2
and a random element a. Ensure f1(a) * f2(b) == (f1 * f2)(a). */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fq_default_t a, b, c;
fq_default_poly_t f1, f2, f3;

/* Initalise a random fq_context */
fq_default_ctx_init_randtest(ctx, state);

/* Initalise fq_default elements */
fq_default_init(a, ctx);
fq_default_init(b, ctx);
fq_default_init(c, ctx);
fq_default_poly_init(f1, ctx);
fq_default_poly_init(f2, ctx);
fq_default_poly_init(f3, ctx);

/* Set a to be a random element */
fq_default_randtest(a, state, ctx);

/* Set f1, f2 to be random polynomials and f3 their product */
fq_default_poly_randtest(f1, state, n_randint(state, 10), ctx);
fq_default_poly_randtest(f2, state, n_randint(state, 10), ctx);
fq_default_poly_mul(f3, f1, f2, ctx);

/* Evaluate the polynomials f1, f2, f3 = f1 * f2 on the element a */
fq_default_poly_evaluate_fq_default(c, f3, a, ctx);
fq_default_poly_evaluate_fq_default(b, f2, a, ctx);
fq_default_poly_evaluate_fq_default(a, f1, a, ctx);

/* Ensure that f1(a) * f2(a) = f3(a) = (f1 * f2)(a) */
fq_default_mul(a, a, b, ctx); // a = f1(a) * f2(a)
result = (fq_default_equal(a, c, ctx));
if (!result)
{
flint_printf("FAIL:\n");
fq_default_ctx_print(ctx), flint_printf("\n\n");
fq_default_poly_print(f1, ctx), flint_printf("\n\n");
fq_default_poly_print(f2, ctx), flint_printf("\n\n");
fq_default_poly_print(f3, ctx), flint_printf("\n\n");
fq_default_print(a, ctx), flint_printf("\n\n");
fflush(stdout);
flint_abort();
}

/* Clear everything */
fq_default_poly_clear(f1, ctx);
fq_default_poly_clear(f2, ctx);
fq_default_poly_clear(f3, ctx);
fq_default_clear(a, ctx);
fq_default_clear(b, ctx);
fq_default_clear(c, ctx);
fq_default_ctx_clear(ctx);
}

fmpz_clear(p);

TEST_FUNCTION_END(state);
}

0 comments on commit 3dbe239

Please sign in to comment.