void fmpz_poly_mat_mullow(fmpz_poly_mat_t C, const fmpz_poly_mat_t A, const fmpz_poly_mat_t B, long len) { long ar, bc, br; long i, j, k; fmpz_poly_t t; ar = A->r; br = B->r; bc = B->c; if (br == 0 || len < 1) { fmpz_poly_mat_zero(C); return; } if (C == A || C == B) { fmpz_poly_mat_t T; fmpz_poly_mat_init(T, ar, bc); fmpz_poly_mat_mullow(T, A, B, len); fmpz_poly_mat_swap(C, T); fmpz_poly_mat_clear(T); return; } fmpz_poly_init(t); for (i = 0; i < ar; i++) { for (j = 0; j < bc; j++) { fmpz_poly_mullow(fmpz_poly_mat_entry(C, i, j), fmpz_poly_mat_entry(A, i, 0), fmpz_poly_mat_entry(B, 0, j), len); for (k = 1; k < br; k++) { fmpz_poly_mullow(t, fmpz_poly_mat_entry(A, i, k), fmpz_poly_mat_entry(B, k, j), len); fmpz_poly_add(fmpz_poly_mat_entry(C, i, j), fmpz_poly_mat_entry(C, i, j), t); } } } fmpz_poly_clear(t); }
void fmpz_poly_mat_sqrlow(fmpz_poly_mat_t B, const fmpz_poly_mat_t A, slong len) { slong n = A->r; if (n == 0) return; if (len < 1) { fmpz_poly_mat_zero(B); return; } if (n == 1) { fmpz_poly_sqrlow(E(B, 0, 0), E(A, 0, 0), len); return; } if (n == 2) { fmpz_poly_t t, u; fmpz_poly_init(t); fmpz_poly_init(u); fmpz_poly_addlow(t, E(A, 0, 0), E(A, 1, 1), len); fmpz_poly_mullow(u, E(A, 0, 1), E(A, 1, 0), len); fmpz_poly_sqrlow(E(B, 0, 0), E(A, 0, 0), len); fmpz_poly_addlow(E(B, 0, 0), E(B, 0, 0), u, len); fmpz_poly_sqrlow(E(B, 1, 1), E(A, 1, 1), len); fmpz_poly_addlow(E(B, 1, 1), E(B, 1, 1), u, len); fmpz_poly_mullow(E(B, 0, 1), E(A, 0, 1), t, len); fmpz_poly_mullow(E(B, 1, 0), E(A, 1, 0), t, len); fmpz_poly_clear(t); fmpz_poly_clear(u); return; } fmpz_poly_mat_mullow(B, A, A, len); }
void fmpz_poly_ramanujan_tau(fmpz_poly_t res, long n) { long j, k, jv, kv; fmpz_t tmp; fmpz_poly_fit_length(res, n); _fmpz_vec_zero(res->coeffs, n); _fmpz_poly_set_length(res, n); fmpz_init(tmp); for (j = jv = 0; jv < n; jv += ++j) { fmpz_set_ui(tmp, 2*j+1); for (k = kv = 0; jv + kv < n; kv += ++k) { if ((j+k) & 1) fmpz_submul_ui(res->coeffs + jv+kv, tmp, 2*k+1); else fmpz_addmul_ui(res->coeffs + jv+kv, tmp, 2*k+1); } } fmpz_poly_mullow(res, res, res, n-1); fmpz_poly_mullow(res, res, res, n-1); fmpz_poly_shift_left(res, res, 1); fmpz_clear(tmp); }
int main(void) { int i, result; FLINT_TEST_INIT(state); flint_printf("inv_series_newton...."); fflush(stdout); /* Check Q^{-1} * Q is congruent 1 mod t^n */ for (i = 0; i < 100 * flint_test_multiplier(); i++) { fmpz_poly_t a, b, c, one; slong n = n_randint(state, 80) + 1; fmpz_poly_init(a); fmpz_poly_init(b); fmpz_poly_init(c); fmpz_poly_init(one); fmpz_poly_randtest_not_zero(a, state, n_randint(state, 80) + 1, 100); fmpz_poly_set_coeff_si(a, 0, n_randint(state, 2) ? 1 : -1); fmpz_poly_set_ui(one, 1); fmpz_poly_inv_series_newton(b, a, n); fmpz_poly_mullow(c, a, b, n); result = (fmpz_poly_equal(c, one)); if (!result) { flint_printf("FAIL:\n"); flint_printf("a = "), fmpz_poly_print(a), flint_printf("\n\n"); flint_printf("b = "), fmpz_poly_print(b), flint_printf("\n\n"); flint_printf("c = "), fmpz_poly_print(c), flint_printf("\n\n"); abort(); } fmpz_poly_clear(a); fmpz_poly_clear(b); fmpz_poly_clear(c); fmpz_poly_clear(one); } /* Verify bug fix for the case Q = -1 mod (x) */ { fmpz_poly_t a, b, c, one; slong n = 1; fmpz_poly_init(a); fmpz_poly_init(b); fmpz_poly_init(c); fmpz_poly_init(one); fmpz_poly_set_si(a, -1); fmpz_poly_set_ui(one, 1); fmpz_poly_inv_series_newton(b, a, n); fmpz_poly_mullow(c, a, b, n); result = (fmpz_poly_equal(c, one)); if (!result) { flint_printf("FAIL:\n"); flint_printf("a = "), fmpz_poly_print(a), flint_printf("\n\n"); flint_printf("b = "), fmpz_poly_print(b), flint_printf("\n\n"); flint_printf("c = "), fmpz_poly_print(c), flint_printf("\n\n"); abort(); } fmpz_poly_clear(a); fmpz_poly_clear(b); fmpz_poly_clear(c); fmpz_poly_clear(one); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }