int dgsl_rot_mp_call_plus1(fmpz_poly_t rop, const dgsl_rot_mp_t *self, gmp_randstate_t state) { const long n = self->n; fmpq_poly_t x; fmpq_poly_init(x); fmpq_poly_sample_D1(x, n, self->prec, state); fmpq_poly_oz_mul(x, self->sigma_sqrt, x, self->n); fmpq_poly_neg(x, x); // (-x2) // we sample with centre c = -1/g fmpq_poly_sub(x, x, self->B_inv); // (c+x2) fmpz_poly_disc_gauss_rounding(rop, x, self->r_f, state); fmpz_poly_neg(rop, rop); fmpz_poly_oz_mul(rop, self->B, rop, self->n); fmpz_add_ui(rop->coeffs, rop->coeffs, 1); fmpq_poly_clear(x); return 0; }
static int _fmpq_poly_oz_sqrt_approx_break(mpfr_t norm, const fmpq_poly_t f_sqrt, const fmpq_poly_t f, const long n, const mpfr_prec_t bound, const mpfr_prec_t prec) { fmpq_poly_t f_approx; fmpq_poly_init(f_approx); fmpq_poly_oz_mul(f_approx, f_sqrt, f_sqrt, n); fmpq_poly_sub(f_approx, f_approx, f); fmpq_poly_2norm_mpfr(norm, f_approx, MPFR_RNDN); mpfr_t f_norm; mpfr_init2(f_norm, prec); fmpq_poly_2norm_mpfr(f_norm, f, MPFR_RNDN); mpfr_div(norm, norm, f_norm, MPFR_RNDN); int r = 0; if(mpfr_cmp_si_2exp(norm, 1, -bound) < 0) r = 1; mpfr_clear(f_norm); fmpq_poly_clear(f_approx); return r; }
int main() { long iter; flint_rand_t state; printf("sub...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000; iter++) { long qbits1, qbits2, rbits1, rbits2, rbits3; fmpq_poly_t A, B, C; fmprb_poly_t a, b, c; qbits1 = 2 + n_randint(state, 200); qbits2 = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 200); rbits2 = 2 + n_randint(state, 200); rbits3 = 2 + n_randint(state, 200); fmpq_poly_init(A); fmpq_poly_init(B); fmpq_poly_init(C); fmprb_poly_init(a); fmprb_poly_init(b); fmprb_poly_init(c); fmpq_poly_randtest(A, state, 1 + n_randint(state, 10), qbits1); fmpq_poly_randtest(B, state, 1 + n_randint(state, 10), qbits2); fmpq_poly_sub(C, A, B); fmprb_poly_set_fmpq_poly(a, A, rbits1); fmprb_poly_set_fmpq_poly(b, B, rbits2); fmprb_poly_sub(c, a, b, rbits3); if (!fmprb_poly_contains_fmpq_poly(c, C)) { printf("FAIL\n\n"); printf("bits3 = %ld\n", rbits3); printf("A = "); fmpq_poly_print(A); printf("\n\n"); printf("B = "); fmpq_poly_print(B); printf("\n\n"); printf("C = "); fmpq_poly_print(C); printf("\n\n"); printf("a = "); fmprb_poly_printd(a, 15); printf("\n\n"); printf("b = "); fmprb_poly_printd(b, 15); printf("\n\n"); printf("c = "); fmprb_poly_printd(c, 15); printf("\n\n"); abort(); } fmpq_poly_clear(A); fmpq_poly_clear(B); fmpq_poly_clear(C); fmprb_poly_clear(a); fmprb_poly_clear(b); fmprb_poly_clear(c); } flint_randclear(state); flint_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("sub...."); fflush(stdout); flint_randinit(state); /* compare with fmpq_poly */ for (iter = 0; iter < 10000; iter++) { slong qbits1, qbits2, rbits1, rbits2, rbits3, trunc; fmpq_poly_t A, B, C; acb_poly_t a, b, c, d; qbits1 = 2 + n_randint(state, 200); qbits2 = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 200); rbits2 = 2 + n_randint(state, 200); rbits3 = 2 + n_randint(state, 200); trunc = n_randint(state, 10); fmpq_poly_init(A); fmpq_poly_init(B); fmpq_poly_init(C); acb_poly_init(a); acb_poly_init(b); acb_poly_init(c); acb_poly_init(d); fmpq_poly_randtest(A, state, 1 + n_randint(state, 10), qbits1); fmpq_poly_randtest(B, state, 1 + n_randint(state, 10), qbits2); fmpq_poly_sub(C, A, B); acb_poly_set_fmpq_poly(a, A, rbits1); acb_poly_set_fmpq_poly(b, B, rbits2); acb_poly_sub(c, a, b, rbits3); if (!acb_poly_contains_fmpq_poly(c, C)) { flint_printf("FAIL\n\n"); flint_printf("bits3 = %wd\n", rbits3); flint_printf("trunc = %wd\n", trunc); flint_printf("A = "); fmpq_poly_print(A); flint_printf("\n\n"); flint_printf("B = "); fmpq_poly_print(B); flint_printf("\n\n"); flint_printf("C = "); fmpq_poly_print(C); flint_printf("\n\n"); flint_printf("a = "); acb_poly_printd(a, 15); flint_printf("\n\n"); flint_printf("b = "); acb_poly_printd(b, 15); flint_printf("\n\n"); flint_printf("c = "); acb_poly_printd(c, 15); flint_printf("\n\n"); abort(); } acb_poly_set(d, a); acb_poly_sub(d, d, b, rbits3); if (!acb_poly_equal(d, c)) { flint_printf("FAIL (aliasing 1)\n\n"); abort(); } acb_poly_set(d, b); acb_poly_sub(d, a, d, rbits3); if (!acb_poly_equal(d, c)) { flint_printf("FAIL (aliasing 2)\n\n"); abort(); } fmpq_poly_clear(A); fmpq_poly_clear(B); fmpq_poly_clear(C); acb_poly_clear(a); acb_poly_clear(b); acb_poly_clear(c); acb_poly_clear(d); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { int i, result; flint_rand_t state; ulong cflags = 0UL; printf("sub...."); fflush(stdout); flint_randinit(state); /* Check a - b = a + neg(b) */ for (i = 0; i < 10000; i++) { fmpq_poly_t a, b, c, d; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_init(d); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_randtest(b, state, n_randint(state, 100), 200); fmpq_poly_sub(c, a, b); fmpq_poly_neg(b, b); fmpq_poly_add(d, a, b); cflags |= fmpq_poly_is_canonical(c) ? 0 : 1; cflags |= fmpq_poly_is_canonical(d) ? 0 : 2; result = (fmpq_poly_equal(c, d) && !cflags); if (!result) { printf("FAIL:\n\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); fmpq_poly_debug(d), printf("\n\n"); printf("cflags = %lu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); fmpq_poly_clear(d); } /* Check aliasing of a and c */ for (i = 0; i < 10000; i++) { fmpq_poly_t a, b, c; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_randtest(b, state, n_randint(state, 100), 200); fmpq_poly_sub(c, a, b); fmpq_poly_sub(a, a, b); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(a, c) && !cflags); if (!result) { printf("FAIL:\n\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %lu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); } /* Check aliasing of b and c */ for (i = 0; i < 10000; i++) { fmpq_poly_t a, b, c; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_randtest(b, state, n_randint(state, 100), 200); fmpq_poly_sub(c, a, b); fmpq_poly_sub(b, a, b); cflags |= fmpq_poly_is_canonical(b) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(b, c) && !cflags); if (!result) { printf("FAIL:\n\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %lu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); } flint_randclear(state); _fmpz_cleanup(); printf("PASS\n"); return 0; }