static void entry(fmpz_t rop_u, long *rop_v, const long *u, const long *v, const fmpz *a, const fmpz *dinv, const fmpz **mu, long M, const long **C, const long *lenC, long n, long d, long p, long N, long N2) { const long ku = diagfrob_k(u, n, d); const long kv = diagfrob_k(v, n, d); fmpz_t f, g, P; fmpz_init(f); fmpz_init(g); fmpz_init_set_ui(P, p); /* Compute $g := (u'-1)! \alpha_{u+1,v+1}$ to precision $N2$. */ fmpz_fac_ui(f, ku - 1); alpha(g, u, v, a, dinv, mu, M, C, lenC, n, d, p, N2); fmpz_mul(g, f, g); /* Compute $f := (-1)^{u'+v'} (v'-1)!$ exactly. */ fmpz_fac_ui(f, kv - 1); if ((ku + kv) % 2 != 0) { fmpz_neg(f, f); } /* Set rop to the product of $f$ and $g^{-1} mod $p^N$. */ *rop_v = fmpz_remove(f, f, P) + n - fmpz_remove(g, g, P); if (*rop_v >= N) { fmpz_zero(rop_u); *rop_v = 0; } else { _padic_inv(g, g, P, N - *rop_v); fmpz_mul(rop_u, f, g); fmpz_pow_ui(f, P, N - *rop_v); fmpz_mod(rop_u, rop_u, f); } fmpz_clear(f); fmpz_clear(g); fmpz_clear(P); }
int main() { slong iter; flint_rand_t state; flint_printf("rfac_ui...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 2000 * arb_test_multiplier(); iter++) { fmpr_t x, y; fmpz_t f; mag_t xb; ulong n; fmpr_init(x); fmpr_init(y); fmpz_init(f); mag_init(xb); mag_randtest_special(xb, state, 80); n = n_randtest(state) % 2000; mag_rfac_ui(xb, n); fmpz_fac_ui(f, n); fmpr_one(x); fmpr_div_fmpz(x, x, f, 2 * MAG_BITS, FMPR_RND_UP); mag_get_fmpr(y, xb); MAG_CHECK_BITS(xb) if (!(fmpr_cmpabs(y, x) >= 0)) { flint_printf("FAIL\n\n"); flint_printf("n = %wu\n\n", n); flint_printf("x = "); fmpr_print(x); flint_printf("\n\n"); flint_printf("y = "); fmpr_print(y); flint_printf("\n\n"); abort(); } fmpr_clear(x); fmpr_clear(y); fmpz_clear(f); mag_clear(xb); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { long i, n; fmpz_t x; fmpz_t y; printf("fac_ui...."); fflush(stdout); fmpz_init(x); fmpz_init(y); /* Twice to check demotion */ for (n = 0; n < 2; n++) { fmpz_set_ui(y, 1UL); for (i = 0; i < 100; i++) { fmpz_fac_ui(x, i); fmpz_mul_ui(y, y, FLINT_MAX(1, i)); if (!fmpz_equal(x, y)) { printf("FAIL: %ld\n", i); fmpz_print(x); printf("\n"); fmpz_print(y); printf("\n"); abort(); } } } fmpz_clear(x); fmpz_clear(y); _fmpz_cleanup(); printf("PASS\n"); return 0; }