Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce fq_default_ctx_init_randtest() #2050

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions doc/source/fq_default.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ Context Management

Prints the context information to ``stdout``.

.. function:: void fq_default_ctx_randtest(fq_default_ctx_t ctx)
.. function:: void fq_default_ctx_init_randtest(fq_default_ctx_t ctx, flint_rand_t state, int type)

Initializes ``ctx`` to a random finite field. Assumes that
``fq_default_ctx_init`` has not been called on ``ctx`` already.
Initializes ``ctx`` to a random finite field where the prime and degree is
set according to ``type``.
Assumes that ``fq_default_ctx_init`` has not been called on ``ctx`` already.
To see what prime and degrees may be output, see
``type`` in :func:`_nmod_poly_conway_rand`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear: You are not referring to the internal "type" for fq_default (i.e. fmpz, nmod etc.)?

I have to think about the randomness thing (i.e. which type). Now, this module is not very much tested inside FLINT, unfortunately (however it is tested in Nemo/Oscar), but in general we would like to (1) minimize the time for testing and (2) reduce the complexity of usage. A separate parameter for type obviously increases the complexity, and, furthermore, is inherited from nmod_poly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type here is the one passed into the generation of prime,degree from the nmod conway function and is not related at all the the fq_default type

The design here, hopefully, simply does what practically would happen if you asked for a random context from fq, fq_nmod and fq_zech


.. function:: void fq_default_get_coeff_fmpz(fmpz_t c, fq_default_t op, slong n, const fq_default_ctx_t ctx)

Expand Down
1 change: 1 addition & 0 deletions src/fq_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ int fq_default_ctx_fprint(FILE * file, const fq_default_ctx_t ctx);
#endif

void fq_default_ctx_print(const fq_default_ctx_t ctx);
void fq_default_ctx_init_randtest(fq_default_ctx_t ctx, flint_rand_t state, int type);

/* Memory management *********************************************************/

Expand Down
19 changes: 19 additions & 0 deletions src/fq_default/ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,22 @@ void fq_default_ctx_modulus(fmpz_mod_poly_t p, const fq_default_ctx_t ctx)
fmpz_mod_poly_set(p, FQ_DEFAULT_CTX_FQ(ctx)->modulus, mod);
}
}

/* FIXME: fq_ctx_init_randtest only tests nmod sized primes, so that's
all we'll do here too? */
void fq_default_ctx_init_randtest(fq_default_ctx_t ctx, flint_rand_t state, int type)
{
ulong prime;
slong degree;
fmpz_t p;

/* select a prime and degree to create the finite field */
prime = _nmod_poly_conway_rand(&degree, state, type);

/* fq_default initialisation wants an fmpz_t for the prime */
fmpz_init(p);
fmpz_set_ui(p, prime);

/* Initialise the context using the prime and degree selected above */
fq_default_ctx_init(ctx, p, degree, "x");
}
16 changes: 16 additions & 0 deletions src/fq_default/test/t-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,21 @@ TEST_FUNCTION_START(fq_default_init, state)
fmpz_clear(p);
}

for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fq_default_ctx_t ctx;
fq_default_t fq;

/* Sets the type used internally for prime selection.
See _nmod_poly_conway_rand for more info. */
int type = n_randint(state, 4);

fq_default_ctx_init_randtest(ctx, state, type);
fq_default_init(fq, ctx);
fq_default_clear(fq, ctx);
fq_default_randtest(fq, state, ctx);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order has to change here, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, sorry about that. Will fix now.

fq_default_ctx_clear(ctx);
}

TEST_FUNCTION_END(state);
}
Loading