int main(void) { char *str; /* String for the input polynomial P */ mpoly_t P; /* Input polynomial P */ int n; /* Number of variables minus one */ long K; /* Required t-adic precision */ long N, Nw; long b; /* Matrix dimensions */ long i, j, k; mat_t M; ctx_t ctxM; mon_t *rows, *cols; padic_mat_struct *C; fmpz_t p; fmpz_poly_mat_t B; long vB; printf("solve... \n"); fflush(stdout); /* Example 3-1-1 */ /* str = "3 [3 0 0] [0 3 0] [0 0 3] (2 0 1)[1 1 1]"; */ /* Example 3-3-2 */ /* str = "3 [3 0 0] [0 3 0] [0 0 3] (2 0 1)[2 1 0] (2 0 1)[0 2 1] (2 0 1)[1 0 2]"; */ /* Example 4-4-2 */ /* str = "4 [4 0 0 0] [0 4 0 0] [0 0 4 0] [0 0 0 4] (2 0 1)[3 1 0 0] (2 0 1)[1 0 1 2] (2 0 1)[0 1 0 3]"; */ /* Example ... */ /* str = "4 [4 0 0 0] [0 4 0 0] [0 0 4 0] [0 0 0 4] (2 0 1)[1 1 1 1]"; */ /* Example from AKR */ str = "4 (1 3)[0 3 0 0] (2 0 3)[0 1 2 0] " "(2 0 -1)[1 1 1 0] (2 0 3)[1 1 0 1] " "(2 0 -1)[2 1 0 0] [0 0 3 0] (2 0 -1)[1 0 2 0] " "(1 2)[0 0 0 3] [3 0 0 0]"; n = atoi(str) - 1; K = 616; N = 10; Nw = 22; fmpz_init(p); fmpz_set_ui(p, 5); ctx_init_fmpz_poly_q(ctxM); ctxM->print = &__fmpz_poly_q_print_pretty; mpoly_init(P, n + 1, ctxM); mpoly_set_str(P, str, ctxM); printf("P = "), mpoly_print(P, ctxM), printf("\n"); b = gmc_basis_size(n, mpoly_degree(P, -1, ctxM)); mat_init(M, b, b, ctxM); fmpz_poly_mat_init(B, b, b); vB = 0; gmc_compute(M, &rows, &cols, P, ctxM); mat_print(M, ctxM); printf("\n"); gmde_solve(&C, K, p, N, Nw, M, ctxM); gmde_convert_soln(B, &vB, C, K, p); printf("Solution to (d/dt + M) C = 0:\n"); fmpz_poly_mat_print(B, "t"); printf("vB = %ld\n", vB); gmde_check_soln(B, vB, p, N, K, M, ctxM); mpoly_clear(P, ctxM); mat_clear(M, ctxM); free(rows); free(cols); fmpz_poly_mat_clear(B); ctx_clear(ctxM); fmpz_clear(p); for (i = 0; i < K; i++) padic_mat_clear(C + i); free(C); _fmpz_cleanup(); return EXIT_SUCCESS; }
int main(void) { flint_rand_t state; long i; printf("inv...."); fflush(stdout); flint_randinit(state); /* Test aliasing */ for (i = 0; i < 400; i++) { fmpz_poly_mat_t A, Ainv; fmpz_poly_t den1, den2; long n, bits, deg; float density; int ns1, ns2; int result; n = n_randint(state, 8); deg = 1 + n_randint(state, 5); bits = 1 + n_randint(state, 100); density = n_randint(state, 100) * 0.01; fmpz_poly_mat_init(A, n, n); fmpz_poly_mat_init(Ainv, n, n); fmpz_poly_init(den1); fmpz_poly_init(den2); fmpz_poly_mat_randtest_sparse(A, state, deg, bits, density); ns1 = fmpz_poly_mat_inv(Ainv, den1, A); ns2 = fmpz_poly_mat_inv(A, den2, A); result = ns1 == ns2; if (result && ns1 != 0) { result = fmpz_poly_equal(den1, den2) && fmpz_poly_mat_equal(A, Ainv); } if (!result) { printf("FAIL (aliasing)!\n"); fmpz_poly_mat_print(A, "x"); printf("\n"); fmpz_poly_mat_print(Ainv, "x"); printf("\n"); abort(); } fmpz_poly_mat_clear(A); fmpz_poly_mat_clear(Ainv); fmpz_poly_clear(den1); fmpz_poly_clear(den2); } /* Check A^(-1) = A = 1 */ for (i = 0; i < 1000; i++) { fmpz_poly_mat_t A, Ainv, B, Iden; fmpz_poly_t den, det; long n, bits, deg; float density; int nonsingular; n = n_randint(state, 10); deg = 1 + n_randint(state, 5); bits = 1 + n_randint(state, 100); density = n_randint(state, 100) * 0.01; fmpz_poly_mat_init(A, n, n); fmpz_poly_mat_init(Ainv, n, n); fmpz_poly_mat_init(B, n, n); fmpz_poly_mat_init(Iden, n, n); fmpz_poly_init(den); fmpz_poly_init(det); fmpz_poly_mat_randtest_sparse(A, state, deg, bits, density); nonsingular = fmpz_poly_mat_inv(Ainv, den, A); fmpz_poly_mat_det_interpolate(det, A); if (n == 0) { if (nonsingular == 0 || !fmpz_poly_is_one(den)) { printf("FAIL: expected empty matrix to pass\n"); abort(); } } else { if (!fmpz_poly_equal(den, det)) { fmpz_poly_neg(det, det); printf("FAIL: den != det(A)\n"); abort(); } fmpz_poly_mat_mul(B, Ainv, A); fmpz_poly_mat_one(Iden); fmpz_poly_mat_scalar_mul_fmpz_poly(Iden, Iden, den); if (!fmpz_poly_mat_equal(B, Iden)) { printf("FAIL:\n"); printf("A:\n"); fmpz_poly_mat_print(A, "x"); printf("Ainv:\n"); fmpz_poly_mat_print(Ainv, "x"); printf("B:\n"); fmpz_poly_mat_print(B, "x"); printf("den:\n"); fmpz_poly_print_pretty(den, "x"); abort(); } } fmpz_poly_clear(den); fmpz_poly_clear(det); fmpz_poly_mat_clear(A); fmpz_poly_mat_clear(Ainv); fmpz_poly_mat_clear(B); fmpz_poly_mat_clear(Iden); } flint_randclear(state); _fmpz_cleanup(); printf("PASS\n"); return 0; }
int main(void) { slong i; FLINT_TEST_INIT(state); flint_printf("add...."); fflush(stdout); /* Check evaluation homomorphism */ for (i = 0; i < 100 * flint_test_multiplier(); i++) { fmpz_poly_mat_t A, B, C; fmpz_mat_t a, b, c, d; fmpz_t x; slong m, n, bits, deg; m = n_randint(state, 20); n = n_randint(state, 20); deg = 1 + n_randint(state, 10); bits = 1 + n_randint(state, 100); fmpz_poly_mat_init(A, m, n); fmpz_poly_mat_init(B, m, n); fmpz_poly_mat_init(C, m, n); fmpz_mat_init(a, m, n); fmpz_mat_init(b, m, n); fmpz_mat_init(c, m, n); fmpz_mat_init(d, m, n); fmpz_init(x); fmpz_poly_mat_randtest(A, state, deg, bits); fmpz_poly_mat_randtest(B, state, deg, bits); fmpz_poly_mat_add(C, A, B); fmpz_randtest(x, state, 1 + n_randint(state, 100)); fmpz_poly_mat_evaluate_fmpz(a, A, x); fmpz_poly_mat_evaluate_fmpz(b, B, x); fmpz_poly_mat_evaluate_fmpz(d, C, x); fmpz_mat_add(c, a, b); if (!fmpz_mat_equal(c, d)) { flint_printf("FAIL:\n"); flint_printf("A:\n"); fmpz_poly_mat_print(A, "x"); flint_printf("B:\n"); fmpz_poly_mat_print(B, "x"); flint_printf("C:\n"); fmpz_poly_mat_print(C, "x"); flint_printf("\n"); abort(); } fmpz_poly_mat_clear(A); fmpz_poly_mat_clear(B); fmpz_poly_mat_clear(C); fmpz_mat_clear(a); fmpz_mat_clear(b); fmpz_mat_clear(c); fmpz_mat_clear(d); fmpz_clear(x); } /* Check aliasing C and A */ for (i = 0; i < 100 * flint_test_multiplier(); i++) { fmpz_poly_mat_t A, B, C; slong m, n, bits, deg; m = n_randint(state, 20); n = n_randint(state, 20); deg = 1 + n_randint(state, 10); bits = 1 + n_randint(state, 100); fmpz_poly_mat_init(A, m, n); fmpz_poly_mat_init(B, m, n); fmpz_poly_mat_init(C, m, n); fmpz_poly_mat_randtest(A, state, deg, bits); fmpz_poly_mat_randtest(B, state, deg, bits); fmpz_poly_mat_add(C, A, B); fmpz_poly_mat_add(A, A, B); if (!fmpz_poly_mat_equal(C, A)) { flint_printf("FAIL:\n"); flint_printf("A:\n"); fmpz_poly_mat_print(A, "x"); flint_printf("B:\n"); fmpz_poly_mat_print(B, "x"); flint_printf("C:\n"); fmpz_poly_mat_print(C, "x"); flint_printf("\n"); abort(); } fmpz_poly_mat_clear(A); fmpz_poly_mat_clear(B); fmpz_poly_mat_clear(C); } /* Check aliasing C and B */ for (i = 0; i < 100 * flint_test_multiplier(); i++) { fmpz_poly_mat_t A, B, C; slong m, n, bits, deg; m = n_randint(state, 20); n = n_randint(state, 20); deg = 1 + n_randint(state, 10); bits = 1 + n_randint(state, 100); fmpz_poly_mat_init(A, m, n); fmpz_poly_mat_init(B, m, n); fmpz_poly_mat_init(C, m, n); fmpz_poly_mat_randtest(A, state, deg, bits); fmpz_poly_mat_randtest(B, state, deg, bits); fmpz_poly_mat_add(C, A, B); fmpz_poly_mat_add(B, A, B); if (!fmpz_poly_mat_equal(C, B)) { flint_printf("FAIL:\n"); flint_printf("A:\n"); fmpz_poly_mat_print(A, "x"); flint_printf("B:\n"); fmpz_poly_mat_print(B, "x"); flint_printf("C:\n"); fmpz_poly_mat_print(C, "x"); flint_printf("\n"); abort(); } fmpz_poly_mat_clear(A); fmpz_poly_mat_clear(B); fmpz_poly_mat_clear(C); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
int main(void) { slong i; FLINT_TEST_INIT(state); flint_printf("nullspace...."); fflush(stdout); for (i = 0; i < 200 * flint_test_multiplier(); i++) { fmpz_poly_mat_t A, N, AN; slong n, m, bits, deg, rank, nullity; float density; m = n_randint(state, 13); n = n_randint(state, 13); deg = 1 + n_randint(state, 5); bits = 1 + n_randint(state, 100); density = n_randint(state, 100) * 0.01; fmpz_poly_mat_init(A, m, n); fmpz_poly_mat_init(N, n, n); fmpz_poly_mat_init(AN, m, n); fmpz_poly_mat_randtest_sparse(A, state, deg, bits, density); rank = fmpz_poly_mat_rank(A); nullity = fmpz_poly_mat_nullspace(N, A); if (nullity + rank != n) { flint_printf("FAIL: wrong nullity!\n"); flint_printf("rank = %wd\n", rank); flint_printf("nullity = %wd\n", nullity); fmpz_poly_mat_print(A, "x"); flint_printf("\n"); fmpz_poly_mat_print(N, "x"); flint_printf("\n"); abort(); } if (fmpz_poly_mat_rank(N) != nullity) { flint_printf("FAIL: wrong rank(N) != nullity!\n"); abort(); } fmpz_poly_mat_mul(AN, A, N); if (!fmpz_poly_mat_is_zero(AN)) { flint_printf("FAIL: A * N != 0\n"); abort(); } fmpz_poly_mat_clear(A); fmpz_poly_mat_clear(N); fmpz_poly_mat_clear(AN); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
int main(void) { flint_rand_t state; long i; printf("pow...."); fflush(stdout); flint_randinit(state); for (i = 0; i < 1000; i++) { fmpz_poly_mat_t A, B, C; long m, j, exp, bits, deg; m = n_randint(state, 6); deg = 1 + n_randint(state, 6); bits = 1 + n_randint(state, 100); exp = n_randint(state, 20); fmpz_poly_mat_init(A, m, m); fmpz_poly_mat_init(B, m, m); fmpz_poly_mat_init(C, m, m); fmpz_poly_mat_randtest(A, state, deg, bits); fmpz_poly_mat_pow(B, A, exp); fmpz_poly_mat_one(C); for (j = 0; j < exp; j++) fmpz_poly_mat_mul(C, C, A); if (!fmpz_poly_mat_equal(C, B)) { printf("FAIL:\n"); printf("exp = %ld\n", exp); printf("A:\n"); fmpz_poly_mat_print(A, "x"); printf("B:\n"); fmpz_poly_mat_print(B, "x"); printf("C:\n"); fmpz_poly_mat_print(C, "x"); printf("\n"); abort(); } fmpz_poly_mat_clear(A); fmpz_poly_mat_clear(B); fmpz_poly_mat_clear(C); } /* Check aliasing B and A */ for (i = 0; i < 1000; i++) { fmpz_poly_mat_t A, B; long m, exp, bits, deg; m = n_randint(state, 6); deg = 1 + n_randint(state, 6); bits = 1 + n_randint(state, 100); exp = n_randint(state, 20); fmpz_poly_mat_init(A, m, m); fmpz_poly_mat_init(B, m, m); fmpz_poly_mat_randtest(A, state, deg, bits); fmpz_poly_mat_pow(B, A, exp); fmpz_poly_mat_pow(A, A, exp); if (!fmpz_poly_mat_equal(A, B)) { printf("FAIL (aliasing)\n"); printf("exp = %ld\n", exp); printf("A:\n"); fmpz_poly_mat_print(A, "x"); printf("B:\n"); fmpz_poly_mat_print(B, "x"); printf("\n"); abort(); } fmpz_poly_mat_clear(A); fmpz_poly_mat_clear(B); } flint_randclear(state); _fmpz_cleanup(); printf("PASS\n"); return 0; }
int main(void) { long i; flint_rand_t state; printf("trace...."); fflush(stdout); flint_randinit(state); /* Test trace(AB) = trace(BA) */ for (i = 0; i < 1000; i++) { fmpz_poly_mat_t A, B, AB, BA; fmpz_poly_t trab, trba; long m, n; m = n_randint(state, 10); n = n_randint(state, 10); fmpz_poly_mat_init(A, m, n); fmpz_poly_mat_init(B, n, m); fmpz_poly_mat_init(AB, m, m); fmpz_poly_mat_init(BA, n, n); fmpz_poly_init(trab); fmpz_poly_init(trba); fmpz_poly_mat_randtest(A, state, 1 + n_randint(state, 10), 1 + n_randint(state, 100)); fmpz_poly_mat_randtest(B, state, 1 + n_randint(state, 10), 1 + n_randint(state, 100)); fmpz_poly_mat_mul(AB, A, B); fmpz_poly_mat_mul(BA, B, A); fmpz_poly_mat_trace(trab, AB); fmpz_poly_mat_trace(trba, BA); if (!fmpz_poly_equal(trab, trba)) { printf("FAIL:\n"); fmpz_poly_mat_print(A, "x"), printf("\n"); fmpz_poly_mat_print(B, "x"), printf("\n"); fmpz_poly_mat_print(AB, "x"), printf("\n"); fmpz_poly_mat_print(BA, "x"), printf("\n"); printf("tr(AB): "), fmpz_poly_print(trab), printf("\n"); printf("tr(BA): "), fmpz_poly_print(trba), printf("\n"); abort(); } fmpz_poly_mat_clear(A); fmpz_poly_mat_clear(B); fmpz_poly_mat_clear(AB); fmpz_poly_mat_clear(BA); fmpz_poly_clear(trab); fmpz_poly_clear(trba); } flint_randclear(state); _fmpz_cleanup(); printf("PASS\n"); return 0; }