long nmod_poly_mat_find_pivot_partial(const nmod_poly_mat_t mat, long start_row, long end_row, long c) { long best_row, best_length, i; best_row = start_row; best_length = nmod_poly_length(nmod_poly_mat_entry(mat, start_row, c)); for (i = start_row + 1; i < end_row; i++) { long l; l = nmod_poly_length(nmod_poly_mat_entry(mat, i, c)); if (l != 0 && (best_length == 0 || l <= best_length)) { best_row = i; best_length = l; } } if (best_length == 0) return -1; return best_row; }
long nmod_poly_mat_max_length(const nmod_poly_mat_t A) { long i, j, len, max; max = 0; for (i = 0; i < A->r; i++) { for (j = 0; j < A->c; j++) { len = nmod_poly_length(nmod_poly_mat_entry(A, i, j)); max = FLINT_MAX(len, max); } } return max; }
int main(void) { int iter; FLINT_TEST_INIT(state); flint_printf("is_squarefree...."); fflush(stdout); for (iter = 0; iter < 200 * flint_test_multiplier(); iter++) { nmod_poly_t poly, Q, R, t; mp_limb_t modulus; slong i, num_factors, exp, max_exp; int v, result; modulus = n_randtest_prime(state, 0); nmod_poly_init(poly, modulus); nmod_poly_init(t, modulus); nmod_poly_init(Q, modulus); nmod_poly_init(R, modulus); nmod_poly_set_coeff_ui(poly, 0, n_randint(state, modulus)); num_factors = n_randint(state, 5); max_exp = 0; for (i = 0; i < num_factors; i++) { do { nmod_poly_randtest(t, state, n_randint(state, 10)); } while (!nmod_poly_is_irreducible(t) || (nmod_poly_length(t) < 2)); exp = n_randint(state, 4) + 1; if (n_randint(state, 2) == 0) exp = 1; nmod_poly_divrem(Q, R, poly, t); if (!nmod_poly_is_zero(R)) { nmod_poly_pow(t, t, exp); nmod_poly_mul(poly, poly, t); max_exp = FLINT_MAX(exp, max_exp); } } v = nmod_poly_is_squarefree(poly); if (v == 1) result = (max_exp <= 1 && !nmod_poly_is_zero(poly)); else result = (max_exp > 1 || nmod_poly_is_zero(poly)); if (!result) { flint_printf("FAIL: %wu, %wd, %d\n", modulus, max_exp, v); nmod_poly_print(poly); flint_printf("\n"); abort(); } nmod_poly_clear(poly); nmod_poly_clear(t); nmod_poly_clear(Q); nmod_poly_clear(R); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
int main(void) { int i; flint_rand_t state; printf("sqrt... "); fflush(stdout); flint_randinit(state); /* Test aliasing */ for (i = 0; i < 2000; i++) { nmod_poly_t a, b; int square1, square2; mp_limb_t mod; mod = n_randtest_prime(state, 0); nmod_poly_init(a, mod); nmod_poly_init(b, mod); nmod_poly_randtest(a, state, 1 + n_randint(state, 50)); if (n_randint(state, 2)) nmod_poly_mul(a, a, a); square1 = nmod_poly_sqrt(b, a); square2 = nmod_poly_sqrt(a, a); if ((square1 != square2) || (square1 && !nmod_poly_equal(a, b))) { printf("FAIL: aliasing:\n"); printf("square1 = %d, square2 = %d\n\n", square1, square2); printf("a: "); nmod_poly_print(a); printf("\n\n"); printf("b: "); nmod_poly_print(b); printf("\n\n"); abort(); } nmod_poly_clear(a); nmod_poly_clear(b); } /* Test random squares */ for (i = 0; i < 2000; i++) { nmod_poly_t a, b, c; int square; mp_limb_t mod; mod = n_randtest_prime(state, 0); nmod_poly_init(a, mod); nmod_poly_init(b, mod); nmod_poly_init(c, mod); nmod_poly_randtest(a, state, 1 + n_randint(state, 50)); nmod_poly_mul(b, a, a); square = nmod_poly_sqrt(c, b); if (!square) { printf("FAIL: square reported nonsquare:\n"); printf("a: "); nmod_poly_print(a); printf("\n\n"); printf("b: "); nmod_poly_print(b); printf("\n\n"); printf("c: "); nmod_poly_print(c); printf("\n\n"); abort(); } nmod_poly_mul(c, c, c); if (!nmod_poly_equal(c, b)) { printf("FAIL: sqrt(b)^2 != b:\n"); printf("a: "); nmod_poly_print(a); printf("\n\n"); printf("b: "); nmod_poly_print(b); printf("\n\n"); printf("c: "); nmod_poly_print(c); printf("\n\n"); abort(); } nmod_poly_clear(a); nmod_poly_clear(b); nmod_poly_clear(c); } /* Test "almost" squares */ for (i = 0; i < 2000; i++) { nmod_poly_t a, b, c; long j; int square; mp_limb_t mod; mod = n_randtest_prime(state, 0); nmod_poly_init(a, mod); nmod_poly_init(b, mod); nmod_poly_init(c, mod); nmod_poly_randtest_not_zero(a, state, 1 + n_randint(state, 50)); nmod_poly_mul(b, a, a); j = n_randint(state, nmod_poly_length(b)); b->coeffs[j] = n_randint(state, mod); _nmod_poly_normalise(b); square = nmod_poly_sqrt(c, b); if (square) { nmod_poly_mul(c, c, c); if (!nmod_poly_equal(c, b)) { printf("FAIL: sqrt(b)^2 != b:\n"); printf("a: "); nmod_poly_print(a); printf("\n\n"); printf("b: "); nmod_poly_print(b); printf("\n\n"); printf("c: "); nmod_poly_print(c); printf("\n\n"); abort(); } } nmod_poly_clear(a); nmod_poly_clear(b); nmod_poly_clear(c); } flint_randclear(state); printf("PASS\n"); return 0; }
int main(void) { int iter; FLINT_TEST_INIT(state); flint_printf("deflate...."); fflush(stdout); for (iter = 0; iter < 100 * flint_test_multiplier(); iter++) { nmod_poly_t poly1, poly2, poly3; mp_limb_t modulus; ulong infl1, infl, deflation; modulus = n_randtest_prime(state, 0); nmod_poly_init(poly1, modulus); nmod_poly_init(poly2, modulus); nmod_poly_init(poly3, modulus); nmod_poly_randtest(poly1, state, n_randint(state, 15)); if (nmod_poly_length(poly1) <= 1) { if (nmod_poly_deflation(poly1) != nmod_poly_length(poly1)) { flint_printf("FAIL: wrong deflation for constant polynomial\n"); abort(); } nmod_poly_deflate(poly2, poly1, n_randint(state, 5) + 1); if (!nmod_poly_equal(poly2, poly1)) { flint_printf("FAIL: constant polynomial changed on deflation\n"); abort(); } } else { infl = n_randint(state, 13) + 1; infl1 = nmod_poly_deflation(poly1); nmod_poly_inflate(poly2, poly1, infl); deflation = nmod_poly_deflation(poly2); if (deflation != infl * infl1) { flint_printf("FAIL: deflation = %wu, inflation: %wu, %wu\n", deflation, infl, infl1); flint_printf("poly1:\n"); nmod_poly_print(poly1); flint_printf("\n\n"); flint_printf("poly2:\n"); nmod_poly_print(poly2); flint_printf("\n\n"); abort(); } nmod_poly_deflate(poly3, poly2, infl); if (!nmod_poly_equal(poly3, poly1)) { flint_printf("FAIL: deflation = %wu, inflation: %wu, %wu\n", deflation, infl, infl1); flint_printf("Deflated polynomial not equal to input:\n"); flint_printf("poly1:\n"); nmod_poly_print(poly1); flint_printf("\n\n"); flint_printf("poly2:\n"); nmod_poly_print(poly2); flint_printf("\n\n"); flint_printf("poly3:\n"); nmod_poly_print(poly2); flint_printf("\n\n"); abort(); } nmod_poly_deflate(poly2, poly2, infl); if (!nmod_poly_equal(poly3, poly2)) { flint_printf("FAIL: aliasing\n"); abort(); } } nmod_poly_clear(poly1); nmod_poly_clear(poly2); nmod_poly_clear(poly3); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }