-
Notifications
You must be signed in to change notification settings - Fork 275
Mod poly and mpn_mod random generation #2448
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
base: main
Are you sure you want to change the base?
Changes from all commits
e6f8dcd
4ea9a57
4f0ef9b
cacfb53
bb5d986
400598a
9060505
59f5c7d
eafe4cf
4dff27e
692c2b8
716a13e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -284,12 +284,28 @@ Assignment and basic manipulation | |
| Randomisation | ||
| -------------------------------------------------------------------------------- | ||
|
|
||
| .. function:: void fmpz_mod_poly_rand(fmpz_mod_poly_t f, flint_rand_t state, slong len, const fmpz_mod_ctx_t ctx) | ||
|
|
||
| Sets `f` to a random polynomial with up to the given length and where | ||
| each coefficient has up to the given number of bits. The coefficients | ||
| are uniformly generated random numbers in `[0, n)`, where `n` is the modulus given by the context `ctx`. | ||
|
|
||
| .. function:: void fmpz_mod_poly_rand_monic(fmpz_mod_poly_t f, flint_rand_t state, slong len, const fmpz_mod_ctx_t ctx) | ||
|
|
||
| Sets `f` to a random monic polynomial with up to the given length and where | ||
| each coefficient has up to the given number of bits. The coefficients | ||
| are uniformly generated random numbers in `[0, n)`, where `n` is the modulus given by the context `ctx`. | ||
|
|
||
| .. function:: void fmpz_mod_poly_rand_irreducible(fmpz_mod_poly_t f, flint_rand_t state, slong len, const fmpz_mod_ctx_t ctx) | ||
|
|
||
| Sets `f` to a random irreducible polynomial with up to the given length and where each coefficient has up to the given number of bits. The coefficients | ||
| are uniformly generated random numbers in `[0, n)`, where `n` is the modulus given by the context `ctx`. | ||
|
|
||
| .. function:: void fmpz_poly_randtest(fmpz_poly_t f, flint_rand_t state, slong len, flint_bitcnt_t bits) | ||
|
|
||
| Sets `f` to a random polynomial with up to the given length and where | ||
| each coefficient has up to the given number of bits. The coefficients | ||
| are signed randomly. | ||
| are random numbers in `[1, n)`, where `n` is the modulus given by the context `ctx`. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Several new things are misplaced here I think. For this specific one, there is no input |
||
|
|
||
| .. function:: void fmpz_poly_randtest_unsigned(fmpz_poly_t f, flint_rand_t state, slong len, flint_bitcnt_t bits) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,12 @@ fmpz_randm(fmpz_t f, flint_rand_t state, const fmpz_t m) | |
| } | ||
| } | ||
|
|
||
| void fmpz_randm_nonzero(fmpz_t f, flint_rand_t state, const fmpz_t m) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current behaviour does not have uniform distribution (it is more likely to generate
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant is that currently, So if a |
||
| fmpz_randm(f, state, m); | ||
| if (fmpz_is_zero(f)) | ||
| fmpz_one(f); | ||
| } | ||
|
|
||
| void fmpz_randprime(fmpz_t f, flint_rand_t state, flint_bitcnt_t bits, int proved) | ||
| { | ||
| if (bits <= FLINT_BITS) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite off topic, but don't we want to have a specific length for most tests? If one needs a random length, one can just push
n_randint(state, len)instead oflen.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
randfunctions are not designed for tests but meant for uniform random (at least when uniform is possible, which is the case when working modulon). The expected leading coefficient might be zero, although this is very unlikely if the modulus is large. Just like if picking a lengthlenvector of coefficients at random.If this is about
randtestvariants, designed for testing purposes, the current doc infmpz_mod_polyreads "Sets the polynomial~fto a random polynomial of length up~len" (which means "up to", I guess). There is alsorandtest_monicwhich guarantees the length is exactly the one in input... but makes the polynomial monic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(in fact many tests already use various lengths or
n_randint(state, len), because using randomization functions with lengthlenwill often produce length exactlylen, including forrandtest)