/* 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 2.1 of the License, or (at your option) any later version. See . */ /****************************************************************************** Authored 2016 by Daniel S. Roche; US Government work in the public domain ******************************************************************************/ #include #include "flint.h" #include "fmpz_mod_poly.h" #include "fmpz.h" #include "fmpz_vec.h" #include "ulong_extras.h" /* checks that poly actually annihilates the given sequence. */ int check(const fmpz_mod_poly_t poly, const fmpz* seq, slong len, const fmpz_mod_ctx_t ctx) { fmpz_t sum, temp; slong d = fmpz_mod_poly_degree(poly, ctx); int i, j; if (d < 0) return 0; fmpz_init(sum); fmpz_init(temp); for (i=0; i < len-d; ++i) { fmpz_zero(sum); for (j=0; j fmpz_mod_poly_degree(poly2, ctx)) { flint_printf("FAIL 1:\n"); _fmpz_vec_print(seq, len); flint_printf("\n\n"); fmpz_mod_poly_print(poly1, ctx); flint_printf("\n\n"); flint_abort(); } if (!check(poly2, seq, len, ctx) || fmpz_mod_poly_degree(poly2, ctx) > fmpz_mod_poly_degree(poly1, ctx)) { flint_printf("FAIL 2:\n"); _fmpz_vec_print(seq, len); flint_printf("\n\n"); fmpz_mod_poly_print(poly2, ctx); flint_printf("\n\n"); flint_abort(); } fmpz_mod_poly_clear(poly1, ctx); fmpz_mod_poly_clear(poly2, ctx); fmpz_clear(p); _fmpz_vec_clear(seq, len); } /* test sequences with a known generator */ for (i = 0; i < 10 * flint_test_multiplier(); i++) { fmpz* seq; slong len, d; fmpz_mod_poly_t poly1, poly2, gen, rem; fmpz_t p, temp; int j, k; fmpz_init(p); fmpz_init(temp); fmpz_randprime(p, state, 100, 0); fmpz_mod_ctx_set_modulus(ctx, p); len = n_randtest(state) % UWORD(200) + 2; seq = _fmpz_vec_init(len); fmpz_mod_poly_init(poly1, ctx); fmpz_mod_poly_init(poly2, ctx); fmpz_mod_poly_init(gen, ctx); fmpz_mod_poly_init(rem, ctx); fmpz_mod_poly_randtest_monic(gen, state, n_randint(state, len/2)+2, ctx); d = fmpz_mod_poly_degree(gen, ctx); FLINT_ASSERT (d > 0); for (j=0; j