void fmpq_mat_one(fmpq_mat_t mat) { slong i, j, min; for (i = 0; i < mat->r; i++) for (j = 0; j < mat->c; j++) fmpq_zero(fmpq_mat_entry(mat, i, j)); min = FLINT_MIN(mat->r, mat->c); for (i = 0; i < min; i++) fmpq_one(fmpq_mat_entry(mat, i, i)); }
int main() { slong iter; flint_rand_t state; flint_printf("rising_ui_rs...."); fflush(stdout); flint_randinit(state); /* compare with fmpq */ for (iter = 0; iter < 1000; iter++) { arb_t a, b; fmpq_t x, y, z; ulong n, step; slong i; arb_init(a); arb_init(b); fmpq_init(x); fmpq_init(y); fmpq_init(z); arb_randtest(a, state, 1 + n_randint(state, 1000), 10); arb_randtest(b, state, 1 + n_randint(state, 1000), 10); n = n_randint(state, 80); arb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 10)); step = n_randint(state, 20); arb_rising_ui_rs(b, a, n, step, 2 + n_randint(state, 1000)); fmpq_one(y); for (i = 0; i < n; i++) { fmpq_set_si(z, i, 1); fmpq_add(z, x, z); fmpq_mul(y, y, z); } if (!arb_contains_fmpq(b, y)) { flint_printf("FAIL: containment\n\n"); flint_printf("n = %wu\n", n); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("x = "); fmpq_print(x); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); flint_printf("y = "); fmpq_print(y); flint_printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); fmpq_clear(x); fmpq_clear(y); fmpq_clear(z); } /* aliasing of y and x */ for (iter = 0; iter < 500; iter++) { arb_t x, y; ulong n, step; slong prec; arb_init(x); arb_init(y); arb_randtest(x, state, 1 + n_randint(state, 200), 10); arb_randtest(y, state, 1 + n_randint(state, 200), 10); n = n_randint(state, 100); prec = 2 + n_randint(state, 1000); step = n_randint(state, 20); arb_rising_ui_rs(y, x, n, step, prec); arb_rising_ui_rs(x, x, n, step, prec); if (!arb_equal(x, y)) { flint_printf("FAIL: aliasing\n\n"); flint_printf("x = "); arb_print(x); flint_printf("\n\n"); flint_printf("y = "); arb_print(y); flint_printf("\n\n"); flint_printf("n = %wu\n", n); abort(); } arb_clear(x); arb_clear(y); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { int i, result; FLINT_TEST_INIT(state); flint_printf("one...."); fflush(stdout); /* x == 1 * x */ for (i = 0; i < 10000; i++) { fmpq_t x, y, z; fmpq_init(x); fmpq_init(y); fmpq_init(z); fmpq_randtest(x, state, 200); fmpq_one(y); fmpq_mul(z, y, x); result = fmpq_is_canonical(z) && fmpq_equal(x, z); if (!result) { flint_printf("FAIL:\n"); flint_printf("x = "), fmpq_print(x), flint_printf("\n"); flint_printf("y = "), fmpq_print(y), flint_printf("\n"); flint_printf("z = "), fmpq_print(z), flint_printf("\n"); abort(); } fmpq_clear(x); fmpq_clear(y); fmpq_clear(z); } /* x/x == 1 */ for (i = 0; i < 10000; i++) { fmpq_t x, y; fmpq_init(x); fmpq_init(y); while (fmpq_is_zero(x)) fmpq_randtest(x, state, 200); fmpq_div(y, x, x); result = fmpq_is_canonical(y) && fmpq_is_one(y); if (!result) { flint_printf("FAIL:\n"); flint_printf("x = "), fmpq_print(x), flint_printf("\n"); flint_printf("y = "), fmpq_print(y), flint_printf("\n"); abort(); } fmpq_clear(x); fmpq_clear(y); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { int i; flint_rand_t state; flint_randinit(state); printf("bsplit_sum_abpq...."); fflush(stdout); for (i = 0; i < 10000; i++) { fmpq *ab, *pq; fmpq_t s1, s2, t, pqp; fmpq_bsplit_t sum; long k, n; n = n_randint(state, 40); ab = _fmpq_vec_init(n); pq = _fmpq_vec_init(n); fmpq_init(s1); fmpq_init(s2); fmpq_init(pqp); fmpq_init(t); for (k = 0; k < n; k++) fmpq_randtest(ab + k, state, 10); for (k = 0; k < n; k++) fmpq_randtest(pq + k, state, 10); fmpq_bsplit_init(sum); fmpq_bsplit_sum_abpq(sum, ab, pq, 0, n); fmpq_bsplit_get_fmpq(s1, sum); fmpq_zero(s2); fmpq_one(pqp); for (k = 0; k < n; k++) { fmpq_mul(pqp, pqp, pq + k); fmpq_mul(t, pqp, ab + k); fmpq_add(s2, s2, t); } if (!fmpq_is_canonical(s1) || !fmpq_equal(s1, s2)) { printf("FAIL\n"); printf("(a/b) = "); for (k = 0; k < n; k++) fmpq_print(ab+k), printf(" "); printf("\n"); printf("(p/q) = "); for (k = 0; k < n; k++) fmpq_print(pq+k), printf(" "); printf("\n"); printf("s1: "); fmpq_print(s1); printf("\n"); printf("s2: "); fmpq_print(s2); printf("\n"); abort(); } /* Check numerical evaluation */ { mpfr_t f1, f2; mpfr_prec_t prec; prec = 5 + n_randint(state, 1000); mpfr_init2(f1, prec); mpfr_init2(f2, prec); fmpq_bsplit_get_mpfr(f1, sum); fmpq_get_mpfr(f2, s1, MPFR_RNDN); mpfr_sub(f1, f1, f2, MPFR_RNDN); if (!mpfr_zero_p(f1) && !(mpfr_get_exp(f1) <= mpfr_get_exp(f2) - prec + 3)) { printf("FAIL: numerical evaluation\n"); printf("%ld, %ld, %ld\n", prec, mpfr_get_exp(f1), mpfr_get_exp(f2) - prec + 3); abort(); } mpfr_clear(f1); mpfr_clear(f2); } fmpq_bsplit_clear(sum); fmpq_clear(s1); fmpq_clear(s2); fmpq_clear(pqp); fmpq_clear(t); _fmpq_vec_clear(ab, n); _fmpq_vec_clear(pq, n); } flint_randclear(state); _fmpz_cleanup(); printf("PASS\n"); return 0; }