int _dgsl_rot_mp_call_inlattice_multiplier(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);; fmpz_poly_disc_gauss_rounding(rop, x, self->r_f, state); fmpz_poly_neg(rop, rop);; fmpq_poly_clear(x); return 0; }
int dgsl_rot_mp_call_plus_fmpz_poly(fmpz_poly_t rop, const dgsl_rot_mp_t *self, const fmpz_poly_t c, gmp_randstate_t state) { fmpz_poly_t t; fmpz_poly_init(t); fmpz_poly_set(t, c); fmpq_poly_t tq; fmpq_poly_init(tq); // == 0 fmpq_poly_set_fmpz_poly(tq, t); fmpq_poly_neg(tq, tq); dgsl_rot_mp_call_recenter_fmpq_poly(rop, self, tq, state); fmpz_poly_add(rop, rop, t); fmpq_poly_clear(tq); fmpz_poly_clear(t); return 0; }
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; }
int dgsl_rot_mp_call_recenter_fmpq_poly(fmpz_poly_t rop, const dgsl_rot_mp_t *self, const fmpq_poly_t c, gmp_randstate_t state) { fmpq_poly_t x; fmpq_poly_init(x); fmpq_poly_sample_D1(x, self->n, self->prec, state); fmpq_poly_oz_mul(x, self->sigma_sqrt, x, self->n); fmpq_poly_neg(x, x); // we sample with centre c/g fmpq_poly_t t; fmpq_poly_init(t); fmpq_poly_oz_mul(t, c, self->B_inv, self->n); fmpq_poly_add(x, t, x); // (c+x2) fmpq_poly_clear(t); fmpz_poly_disc_gauss_rounding(rop, x, self->r_f, state); fmpz_poly_oz_mul(rop, self->B, rop, self->n); fmpq_poly_clear(x); return 0; }
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; }