int main(void) { fmpz_mat_t A; flint_rand_t state; long i, m; fmpz_t det1, det2; printf("det_multi_mod...."); fflush(stdout); flint_randinit(state); for (i = 0; i < 10000; i++) { int proved = n_randlimb(state) % 2; m = n_randint(state, 10); fmpz_mat_init(A, m, m); fmpz_init(det1); fmpz_init(det2); fmpz_mat_randtest(A, state, 1+n_randint(state,200)); fmpz_mat_det_bareiss(det1, A); fmpz_mat_det_multi_mod(det2, A, proved); if (!fmpz_equal(det1, det2)) { printf("FAIL:\n"); printf("different determinants!\n"); fmpz_mat_print_pretty(A), printf("\n"); printf("det1: "), fmpz_print(det1), printf("\n"); printf("det2: "), fmpz_print(det2), printf("\n"); abort(); } fmpz_clear(det1); fmpz_clear(det2); fmpz_mat_clear(A); } for (i = 0; i < 10000; i++) { m = 2 + n_randint(state, 10); fmpz_mat_init(A, m, m); fmpz_init(det2); fmpz_mat_randrank(A, state, 1+n_randint(state, m - 1), 1+n_randint(state, 10)); fmpz_mat_randops(A, state, n_randint(state, 2*m*m + 1)); fmpz_mat_det_multi_mod(det2, A, 0); if (*det2) { printf("FAIL:\n"); printf("expected zero determinant!\n"); fmpz_mat_print_pretty(A), printf("\n"); abort(); } fmpz_mat_clear(A); fmpz_clear(det2); } flint_randclear(state); _fmpz_cleanup(); printf("PASS\n"); return 0; }
int main(void) { fmpz_mat_t A, X, B, AX, AXm, Bm; fmpz_t mod; slong i, m, n, r; int success; FLINT_TEST_INIT(state); flint_printf("solve_dixon...."); fflush(stdout); for (i = 0; i < 100 * flint_test_multiplier(); i++) { m = n_randint(state, 20); n = n_randint(state, 20); fmpz_mat_init(A, m, m); fmpz_mat_init(B, m, n); fmpz_mat_init(Bm, m, n); fmpz_mat_init(X, m, n); fmpz_mat_init(AX, m, n); fmpz_mat_init(AXm, m, n); fmpz_init(mod); fmpz_mat_randrank(A, state, m, 1+n_randint(state, 2)*n_randint(state, 100)); fmpz_mat_randtest(B, state, 1+n_randint(state, 2)*n_randint(state, 100)); /* Dense */ if (n_randint(state, 2)) fmpz_mat_randops(A, state, 1+n_randint(state, 1 + m*m)); success = fmpz_mat_solve_dixon(X, mod, A, B); fmpz_mat_set(AXm, X); fmpz_mat_mul(AX, A, AXm); fmpz_mat_scalar_mod_fmpz(AXm, AX, mod); fmpz_mat_scalar_mod_fmpz(Bm, B, mod); if (!fmpz_mat_equal(AXm, Bm) || !success) { flint_printf("FAIL:\n"); flint_printf("AX != B!\n"); flint_printf("A:\n"), fmpz_mat_print_pretty(A), flint_printf("\n"); flint_printf("B:\n"), fmpz_mat_print_pretty(B), flint_printf("\n"); flint_printf("X:\n"), fmpz_mat_print_pretty(X), flint_printf("\n"); flint_printf("mod = "), fmpz_print(mod), flint_printf("\n"); flint_printf("AX:\n"), fmpz_mat_print_pretty(AX), flint_printf("\n"); abort(); } fmpz_mat_clear(A); fmpz_mat_clear(B); fmpz_mat_clear(Bm); fmpz_mat_clear(X); fmpz_mat_clear(AX); fmpz_mat_clear(AXm); fmpz_clear(mod); } /* Test singular systems */ for (i = 0; i < 100 * flint_test_multiplier(); i++) { m = 1 + n_randint(state, 10); n = 1 + n_randint(state, 10); r = n_randint(state, m); fmpz_mat_init(A, m, m); fmpz_mat_init(B, m, n); fmpz_mat_init(X, m, n); fmpz_init(mod); fmpz_mat_randrank(A, state, r, 1+n_randint(state, 2)*n_randint(state, 100)); fmpz_mat_randtest(B, state, 1+n_randint(state, 2)*n_randint(state, 100)); /* Dense */ if (n_randint(state, 2)) fmpz_mat_randops(A, state, 1+n_randint(state, 1 + m*m)); if (fmpz_mat_solve_dixon(X, mod, A, B) != 0) { flint_printf("FAIL:\n"); flint_printf("singular system, returned nonzero\n"); abort(); } fmpz_mat_clear(A); fmpz_mat_clear(B); fmpz_mat_clear(X); fmpz_clear(mod); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
int main(void) { fmpz_mat_t A, X, B, AX; fmpz_t den; slong i, m, n, r; int success; FLINT_TEST_INIT(state); flint_printf("solve_cramer...."); fflush(stdout); for (i = 0; i < 1000 * flint_test_multiplier(); i++) { m = n_randint(state, 4); n = n_randint(state, 10); fmpz_mat_init(A, m, m); fmpz_mat_init(B, m, n); fmpz_mat_init(X, m, n); fmpz_mat_init(AX, m, n); fmpz_init(den); fmpz_mat_randrank(A, state, m, 1+n_randint(state, 2)*n_randint(state, 100)); fmpz_mat_randtest(B, state, 1+n_randint(state, 2)*n_randint(state, 100)); /* Dense */ if (n_randint(state, 2)) fmpz_mat_randops(A, state, 1+n_randint(state, 1 + m*m)); success = fmpz_mat_solve_cramer(X, den, A, B); fmpz_mat_mul(AX, A, X); fmpz_mat_scalar_divexact_fmpz(AX, AX, den); if (!fmpz_mat_equal(AX, B) || !success) { flint_printf("FAIL:\n"); flint_printf("AX != B!\n"); flint_printf("A:\n"), fmpz_mat_print_pretty(A), flint_printf("\n"); flint_printf("B:\n"), fmpz_mat_print_pretty(B), flint_printf("\n"); flint_printf("X:\n"), fmpz_mat_print_pretty(X), flint_printf("\n"); flint_printf("den(X) = "), fmpz_print(den), flint_printf("\n"); flint_printf("AX:\n"), fmpz_mat_print_pretty(AX), flint_printf("\n"); abort(); } fmpz_mat_clear(A); fmpz_mat_clear(B); fmpz_mat_clear(X); fmpz_mat_clear(AX); fmpz_clear(den); } /* Test singular systems */ for (i = 0; i < 1000 * flint_test_multiplier(); i++) { m = 1 + n_randint(state, 3); n = 1 + n_randint(state, 10); r = n_randint(state, m); fmpz_mat_init(A, m, m); fmpz_mat_init(B, m, n); fmpz_mat_init(X, m, n); fmpz_mat_init(AX, m, n); fmpz_init(den); fmpz_mat_randrank(A, state, r, 1+n_randint(state, 2)*n_randint(state, 100)); fmpz_mat_randtest(B, state, 1+n_randint(state, 2)*n_randint(state, 100)); /* Dense */ if (n_randint(state, 2)) fmpz_mat_randops(A, state, 1+n_randint(state, 1 + m*m)); success = fmpz_mat_solve_cramer(X, den, A, B); if (!fmpz_is_zero(den) || success) { flint_printf("FAIL:\n"); flint_printf("singular system gave nonzero determinant\n"); abort(); } fmpz_mat_clear(A); fmpz_mat_clear(B); fmpz_mat_clear(X); fmpz_mat_clear(AX); fmpz_clear(den); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
int main(void) { int i; FLINT_TEST_INIT(state); flint_printf("solve_dixon...."); fflush(stdout); /* Solve nonsingular systems */ for (i = 0; i < 100 * flint_test_multiplier(); i++) { fmpq_mat_t A, B, X, AX; fmpq_t d; int success; slong n, m, bits; n = n_randint(state, 10); m = n_randint(state, 10); bits = 1 + n_randint(state, 100); fmpq_mat_init(A, n, n); fmpq_mat_init(B, n, m); fmpq_mat_init(X, n, m); fmpq_mat_init(AX, n, m); fmpq_init(d); /* XXX: replace with a randtest function */ do { fmpq_mat_randtest(A, state, bits); fmpq_mat_det(d, A); } while (fmpq_is_zero(d)); fmpq_clear(d); fmpq_mat_randtest(B, state, bits); success = fmpq_mat_solve_dixon(X, A, B); fmpq_mat_mul(AX, A, X); if (!fmpq_mat_equal(AX, B) || !success) { flint_printf("FAIL!\n"); flint_printf("success: %d\n", success); flint_printf("A:\n"); fmpq_mat_print(A); flint_printf("B:\n"); fmpq_mat_print(B); flint_printf("X:\n"); fmpq_mat_print(X); flint_printf("AX:\n"); fmpq_mat_print(AX); abort(); } fmpq_mat_clear(A); fmpq_mat_clear(B); fmpq_mat_clear(X); fmpq_mat_clear(AX); } /* Check singular systems */ for (i = 0; i < 100 * flint_test_multiplier(); i++) { fmpq_mat_t A, B, X; fmpz_mat_t M; fmpz_t den; slong n, m, bits; int success; n = 1 + n_randint(state, 10); m = 1 + n_randint(state, 10); bits = 1 + n_randint(state, 100); fmpz_init(den); fmpz_mat_init(M, n, n); fmpz_mat_randrank(M, state, n_randint(state, n), bits); if (i % 2) fmpz_mat_randops(M, state, n_randint(state, 2*m*n + 1)); fmpz_randtest_not_zero(den, state, bits); fmpq_mat_init(A, n, n); fmpq_mat_set_fmpz_mat_div_fmpz(A, M, den); fmpq_mat_init(B, n, m); fmpq_mat_randtest(B, state, bits); fmpq_mat_init(X, n, m); success = fmpq_mat_solve_dixon(X, A, B); if (success != 0) { flint_printf("FAIL!\n"); flint_printf("Expected success = 0\n"); fmpq_mat_print(A); flint_printf("\n"); abort(); } fmpq_mat_clear(A); fmpq_mat_clear(B); fmpq_mat_clear(X); fmpz_mat_clear(M); fmpz_clear(den); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }