Exemplo n.º 1
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("evaluate2_rectangular....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        arb_poly_t f, g;
        arb_t x, y1, z1, y2, z2;

        arb_init(x);
        arb_init(y1);
        arb_init(z1);
        arb_init(y2);
        arb_init(z2);
        arb_poly_init(f);
        arb_poly_init(g);

        arb_randtest(x, state, 2 + n_randint(state, 1000), 5);
        arb_poly_randtest(f, state, 2 + n_randint(state, 100), 2 + n_randint(state, 1000), 5);
        arb_poly_derivative(g, f, 2 + n_randint(state, 1000));

        arb_poly_evaluate2_rectangular(y1, z1, f, x, 2 + n_randint(state, 1000));

        arb_poly_evaluate_horner(y2, f, x, 2 + n_randint(state, 1000));
        arb_poly_evaluate_horner(z2, g, x, 2 + n_randint(state, 1000));

        if (!arb_overlaps(y1, y2) || !arb_overlaps(z1, z2))
        {
            flint_printf("FAIL\n\n");
            flint_printf("f = "); arb_poly_printd(f, 15); flint_printf("\n\n");
            flint_printf("g = "); arb_poly_printd(g, 15); flint_printf("\n\n");
            flint_printf("x = "); arb_printd(x, 15); flint_printf("\n\n");
            flint_printf("y1 = "); arb_printd(y1, 15); flint_printf("\n\n");
            flint_printf("z1 = "); arb_printd(z1, 15); flint_printf("\n\n");
            flint_printf("y2 = "); arb_printd(y2, 15); flint_printf("\n\n");
            flint_printf("z2 = "); arb_printd(z2, 15); flint_printf("\n\n");
            abort();
        }

        arb_poly_clear(f);
        arb_poly_clear(g);
        arb_clear(x);
        arb_clear(y1);
        arb_clear(z1);
        arb_clear(y2);
        arb_clear(z2);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 2
0
Arquivo: divrem.c Projeto: isuruf/arb
int arb_poly_divrem(arb_poly_t Q, arb_poly_t R,
                             const arb_poly_t A, const arb_poly_t B, slong prec)
{
    const slong lenA = A->length, lenB = B->length;

    if (lenB == 0 || arb_contains_zero(B->coeffs + lenB - 1))
    {
        return 0;
    }

    if (lenA < lenB)
    {
        arb_poly_set(R, A);
        arb_poly_zero(Q);
        return 1;
    }

    if (Q == A || Q == B)
    {
        arb_poly_t T;
        arb_poly_init(T);
        arb_poly_divrem(T, R, A, B, prec);
        arb_poly_swap(Q, T);
        arb_poly_clear(T);
        return 1;
    }

    if (R == A || R == B)
    {
        arb_poly_t U;
        arb_poly_init(U);
        arb_poly_divrem(Q, U, A, B, prec);
        arb_poly_swap(R, U);
        arb_poly_clear(U);
        return 1;
    }

    arb_poly_fit_length(Q, lenA - lenB + 1);
    arb_poly_fit_length(R, lenB - 1);

    _arb_poly_divrem(Q->coeffs, R->coeffs, A->coeffs, lenA,
                                   B->coeffs, lenB, prec);

    _arb_poly_set_length(Q, lenA - lenB + 1);
    _arb_poly_set_length(R, lenB - 1);
    _arb_poly_normalise(R);

    return 1;
}
Exemplo n.º 3
0
void
acb_poly_set2_fmpq_poly(acb_poly_t poly, const fmpq_poly_t re, const fmpq_poly_t im, slong prec)
{
    arb_poly_t t, u;
    arb_poly_init(t);
    arb_poly_init(u);

    arb_poly_set_fmpq_poly(t, re, prec);
    arb_poly_set_fmpq_poly(u, im, prec);

    acb_poly_set2_arb_poly(poly, t, u);

    arb_poly_clear(t);
    arb_poly_clear(u);
}
Exemplo n.º 4
0
void
arb_poly_revert_series(arb_poly_t Qinv,
                                    const arb_poly_t Q, slong n, slong prec)
{
    slong Qlen = Q->length;

    if (Qlen < 2 || !arb_is_zero(Q->coeffs)
                 || arb_contains_zero(Q->coeffs + 1))
    {
        flint_printf("Exception (arb_poly_revert_series). Input must \n"
               "have zero constant term and nonzero coefficient of x^1.\n");
        abort();
    }

    if (Qinv != Q)
    {
        arb_poly_fit_length(Qinv, n);
        _arb_poly_revert_series(Qinv->coeffs, Q->coeffs, Qlen, n, prec);
    }
    else
    {
        arb_poly_t t;
        arb_poly_init2(t, n);
        _arb_poly_revert_series(t->coeffs, Q->coeffs, Qlen, n, prec);
        arb_poly_swap(Qinv, t);
        arb_poly_clear(t);
    }

    _arb_poly_set_length(Qinv, n);
    _arb_poly_normalise(Qinv);
}
Exemplo n.º 5
0
void
arb_poly_div_series(arb_poly_t Q, const arb_poly_t A, const arb_poly_t B, long n, long prec)
{
    if (n == 0 || B->length == 0)
    {
        printf("arb_poly_inv_series: require n > 0 and nonzero input\n");
        abort();
    }

    if (A->length == 0)
    {
        arb_poly_zero(Q);
        return;
    }

    if (Q == A || Q == B)
    {
        arb_poly_t t;
        arb_poly_init(t);
        arb_poly_div_series(t, A, B, n, prec);
        arb_poly_swap(Q, t);
        arb_poly_clear(t);
        return;
    }

    arb_poly_fit_length(Q, n);
    _arb_poly_div_series(Q->coeffs, A->coeffs, A->length, B->coeffs, B->length, n, prec);
    _arb_poly_set_length(Q, n);
    _arb_poly_normalise(Q);
}
Exemplo n.º 6
0
void
arb_poly_sqrt_series(arb_poly_t g, const arb_poly_t h, long n, long prec)
{
    if (n == 0)
    {
        arb_poly_zero(g);
        return;
    }

    if (g == h)
    {
        arb_poly_t t;
        arb_poly_init(t);
        arb_poly_sqrt_series(t, h, n, prec);
        arb_poly_swap(g, t);
        arb_poly_clear(t);
        return;
    }

    arb_poly_fit_length(g, n);
    if (h->length == 0)
        _arb_vec_indeterminate(g->coeffs, n);
    else
        _arb_poly_sqrt_series(g->coeffs, h->coeffs, h->length, n, prec);
    _arb_poly_set_length(g, n);
    _arb_poly_normalise(g);
}
Exemplo n.º 7
0
void
arb_poly_rising_ui_series(arb_poly_t res, const arb_poly_t f, ulong r, slong trunc, slong prec)
{
    slong len;

    if ((f->length == 0 && r != 0) || trunc == 0)
    {
        arb_poly_zero(res);
        return;
    }

    if (r == 0)
    {
        arb_poly_one(res);
        return;
    }

    len = poly_pow_length(f->length, r, trunc);

    if (f == res)
    {
        arb_poly_t tmp;
        arb_poly_init(tmp);
        arb_poly_rising_ui_series(tmp, f, r, len, prec);
        arb_poly_swap(tmp, res);
        arb_poly_clear(tmp);
    }
    else
    {
        arb_poly_fit_length(res, len);
        _arb_poly_rising_ui_series(res->coeffs, f->coeffs, f->length, r, len, prec);
        _arb_poly_set_length(res, len);
        _arb_poly_normalise(res);
    }
}
Exemplo n.º 8
0
void
arb_poly_mul(arb_poly_t res, const arb_poly_t poly1,
              const arb_poly_t poly2, slong prec)
{
    slong len_out;

    if ((poly1->length == 0) || (poly2->length == 0))
    {
        arb_poly_zero(res);
        return;
    }

    len_out = poly1->length + poly2->length - 1;

    if (res == poly1 || res == poly2)
    {
        arb_poly_t temp;
        arb_poly_init2(temp, len_out);
        _arb_poly_mul(temp->coeffs, poly1->coeffs, poly1->length,
                                 poly2->coeffs, poly2->length, prec);
        arb_poly_swap(res, temp);
        arb_poly_clear(temp);
    }
    else
    {
        arb_poly_fit_length(res, len_out);
        _arb_poly_mul(res->coeffs, poly1->coeffs, poly1->length,
                                 poly2->coeffs, poly2->length, prec);
    }

    _arb_poly_set_length(res, len_out);
    _arb_poly_normalise(res);
}
Exemplo n.º 9
0
void
arb_poly_inv_series(arb_poly_t Qinv, const arb_poly_t Q, slong n, slong prec)
{
    if (n == 0)
    {
        arb_poly_zero(Qinv);
        return;
    }

    if (Q->length == 0)
    {
        arb_poly_fit_length(Qinv, n);
        _arb_vec_indeterminate(Qinv->coeffs, n);
        _arb_poly_set_length(Qinv, n);
        return;
    }

    if (Qinv == Q)
    {
        arb_poly_t t;
        arb_poly_init(t);
        arb_poly_inv_series(t, Q, n, prec);
        arb_poly_swap(Qinv, t);
        arb_poly_clear(t);
        return;
    }

    arb_poly_fit_length(Qinv, n);
    _arb_poly_inv_series(Qinv->coeffs, Q->coeffs, Q->length, n, prec);
    _arb_poly_set_length(Qinv, n);
    _arb_poly_normalise(Qinv);
}
Exemplo n.º 10
0
void
arb_poly_binomial_transform(arb_poly_t b, const arb_poly_t a, slong len, slong prec)
{
    if (len == 0 || a->length == 0)
    {
        arb_poly_zero(b);
        return;
    }

    if (b == a)
    {
        arb_poly_t c;
        arb_poly_init2(c, len);
        _arb_poly_binomial_transform(c->coeffs, a->coeffs, a->length, len, prec);
        arb_poly_swap(b, c);
        arb_poly_clear(c);
    }
    else
    {
        arb_poly_fit_length(b, len);
        _arb_poly_binomial_transform(b->coeffs, a->coeffs, a->length, len, prec);
    }

    _arb_poly_set_length(b, len);
    _arb_poly_normalise(b);
}
Exemplo n.º 11
0
void
acb_poly_set_fmpq_poly(acb_poly_t poly, const fmpq_poly_t re, slong prec)
{
    arb_poly_t t;
    arb_poly_init(t);
    arb_poly_set_fmpq_poly(t, re, prec);
    acb_poly_set_arb_poly(poly, t);
    arb_poly_clear(t);
}
Exemplo n.º 12
0
void
arb_poly_compose_series(arb_poly_t res,
                    const arb_poly_t poly1,
                    const arb_poly_t poly2, slong n, slong prec)
{
    slong len1 = poly1->length;
    slong len2 = poly2->length;
    slong lenr;

    if (len2 != 0 && !arb_is_zero(poly2->coeffs))
    {
        flint_printf("exception: compose_series: inner "
                "polynomial must have zero constant term\n");
        abort();
    }

    if (len1 == 0 || n == 0)
    {
        arb_poly_zero(res);
        return;
    }

    if (len2 == 0 || len1 == 1)
    {
        arb_poly_set_arb(res, poly1->coeffs);
        return;
    }

    lenr = FLINT_MIN((len1 - 1) * (len2 - 1) + 1, n);
    len1 = FLINT_MIN(len1, lenr);
    len2 = FLINT_MIN(len2, lenr);

    if ((res != poly1) && (res != poly2))
    {
        arb_poly_fit_length(res, lenr);
        _arb_poly_compose_series(res->coeffs, poly1->coeffs, len1,
                                        poly2->coeffs, len2, lenr, prec);
        _arb_poly_set_length(res, lenr);
        _arb_poly_normalise(res);
    }
    else
    {
        arb_poly_t t;
        arb_poly_init2(t, lenr);
        _arb_poly_compose_series(t->coeffs, poly1->coeffs, len1,
                                        poly2->coeffs, len2, lenr, prec);
        _arb_poly_set_length(t, lenr);
        _arb_poly_normalise(t);
        arb_poly_swap(res, t);
        arb_poly_clear(t);
    }
}
Exemplo n.º 13
0
static void
bsplit(arb_poly_t pol, const arb_t sqrtD,
            const slong * qbf, slong a, slong b, slong prec)
{
    if (b - a == 0)
    {
        arb_poly_one(pol);
    }
    else if (b - a == 1)
    {
        acb_t z;
        acb_init(z);

        /* j((-b+sqrt(-D))/(2a)) */
        arb_set_si(acb_realref(z), -FLINT_ABS(qbf[3 * a + 1]));
        arb_set(acb_imagref(z), sqrtD);
        acb_div_si(z, z, 2 * qbf[3 * a], prec);
        acb_modular_j(z, z, prec);

        if (qbf[3 * a + 1] < 0)
        {
            /* (x^2 - 2re(j) x + |j|^2) */
            arb_poly_fit_length(pol, 3);
            arb_mul(pol->coeffs, acb_realref(z), acb_realref(z), prec);
            arb_addmul(pol->coeffs, acb_imagref(z), acb_imagref(z), prec);
            arb_mul_2exp_si(pol->coeffs + 1, acb_realref(z), 1);
            arb_neg(pol->coeffs + 1, pol->coeffs + 1);
            arb_one(pol->coeffs + 2);
            _arb_poly_set_length(pol, 3);
        }
        else
        {
            /* (x-j) */
            arb_poly_fit_length(pol, 2);
            arb_neg(pol->coeffs, acb_realref(z));
            arb_one(pol->coeffs + 1);
            _arb_poly_set_length(pol, 2);
        }

        acb_clear(z);
    }
    else
    {
        arb_poly_t tmp;
        arb_poly_init(tmp);
        bsplit(pol, sqrtD, qbf, a, a + (b - a) / 2, prec);
        bsplit(tmp, sqrtD, qbf, a + (b - a) / 2, b, prec);
        arb_poly_mul(pol, pol, tmp, prec);
        arb_poly_clear(tmp);
    }
}
Exemplo n.º 14
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("evaluate_acb_rectangular....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        arb_poly_t f;
        acb_t x, y1, y2;

        acb_init(x);
        acb_init(y1);
        acb_init(y2);
        arb_poly_init(f);

        acb_randtest(x, state, 2 + n_randint(state, 1000), 5);
        arb_poly_randtest(f, state, 2 + n_randint(state, 100), 2 + n_randint(state, 1000), 5);

        arb_poly_evaluate_acb_rectangular(y1, f, x, 2 + n_randint(state, 1000));
        arb_poly_evaluate_acb_horner(y2, f, x, 2 + n_randint(state, 1000));

        if (!acb_overlaps(y1, y2))
        {
            flint_printf("FAIL\n\n");
            flint_printf("f = "); arb_poly_printd(f, 15); flint_printf("\n\n");
            flint_printf("x = "); acb_printd(x, 15); flint_printf("\n\n");
            flint_printf("y1 = "); acb_printd(y1, 15); flint_printf("\n\n");
            flint_printf("y2 = "); acb_printd(y2, 15); flint_printf("\n\n");
            abort();
        }

        arb_poly_clear(f);
        acb_clear(x);
        acb_clear(y1);
        acb_clear(y2);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 15
0
int
main(void)
{
    int i, result;
    flint_rand_t state;

    printf("get_coeff_ptr....");
    fflush(stdout);

    flint_randinit(state);

    for (i = 0; i < 1000; i++)
    {
        arb_poly_t A;
        arb_t a;
        long n = n_randint(state, 100);

        arb_poly_init(A);
        arb_poly_randtest(A, state, n_randint(state, 100), 100, 10);
        arb_init(a);

        arb_poly_get_coeff_arb(a, A, n);

        result = n < arb_poly_length(A) ?
                 arb_equal(a, arb_poly_get_coeff_ptr(A, n)) :
                 arb_poly_get_coeff_ptr(A, n) == NULL;
        if (!result)
        {
            printf("FAIL:\n");
            printf("A = "), arb_poly_printd(A, 10), printf("\n\n");
            printf("a = "), arb_print(a), printf("\n\n");
            printf("n = %ld\n\n", n);
            abort();
        }

        arb_poly_clear(A);
        arb_clear(a);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return 0;
}
Exemplo n.º 16
0
void
arb_poly_pow_ui_trunc_binexp(arb_poly_t res,
    const arb_poly_t poly, ulong exp, slong len, slong prec)
{
    slong flen, rlen;

    flen = poly->length;

    if (exp == 0 && len != 0)
    {
        arb_poly_one(res);
    }
    else if (flen == 0 || len == 0)
    {
        arb_poly_zero(res);
    }
    else
    {
        rlen = poly_pow_length(flen, exp, len);

        if (res != poly)
        {
            arb_poly_fit_length(res, rlen);
            _arb_poly_pow_ui_trunc_binexp(res->coeffs,
                poly->coeffs, flen, exp, rlen, prec);
            _arb_poly_set_length(res, rlen);
            _arb_poly_normalise(res);
        }
        else
        {
            arb_poly_t t;
            arb_poly_init2(t, rlen);
            _arb_poly_pow_ui_trunc_binexp(t->coeffs,
                poly->coeffs, flen, exp, rlen, prec);
            _arb_poly_set_length(t, rlen);
            _arb_poly_normalise(t);
            arb_poly_swap(res, t);
            arb_poly_clear(t);
        }
    }
}
Exemplo n.º 17
0
int
_acb_modular_hilbert_class_poly(fmpz_poly_t res, slong D,
        const slong * qbf, slong qbf_len, slong prec)
{
    arb_t sqrtD;
    arb_poly_t pol;
    int success;

    arb_init(sqrtD);
    arb_poly_init(pol);

    arb_set_si(sqrtD, -D);
    arb_sqrt(sqrtD, sqrtD, prec);
    bsplit(pol, sqrtD, qbf, 0, qbf_len, prec);
    success = arb_poly_get_unique_fmpz_poly(res, pol);

    arb_clear(sqrtD);
    arb_poly_clear(pol);

    return success;
}
Exemplo n.º 18
0
void
arb_poly_mullow_block(arb_poly_t res, const arb_poly_t poly1,
                      const arb_poly_t poly2, slong n, slong prec)
{
    slong xlen, ylen, zlen;

    xlen = poly1->length;
    ylen = poly2->length;

    if (xlen == 0 || ylen == 0 || n == 0)
    {
        arb_poly_zero(res);
        return;
    }

    xlen = FLINT_MIN(xlen, n);
    ylen = FLINT_MIN(ylen, n);
    zlen = FLINT_MIN(xlen + ylen - 1, n);

    if (res == poly1 || res == poly2)
    {
        arb_poly_t tmp;
        arb_poly_init2(tmp, zlen);
        _arb_poly_mullow_block(tmp->coeffs, poly1->coeffs, xlen,
                               poly2->coeffs, ylen, zlen, prec);
        arb_poly_swap(res, tmp);
        arb_poly_clear(tmp);
    }
    else
    {
        arb_poly_fit_length(res, zlen);
        _arb_poly_mullow_block(res->coeffs, poly1->coeffs, xlen,
                               poly2->coeffs, ylen, zlen, prec);
    }

    _arb_poly_set_length(res, zlen);
    _arb_poly_normalise(res);
}
Exemplo n.º 19
0
Arquivo: compose.c Projeto: isuruf/arb
void arb_poly_compose(arb_poly_t res,
              const arb_poly_t poly1, const arb_poly_t poly2, slong prec)
{
    const slong len1 = poly1->length;
    const slong len2 = poly2->length;
    
    if (len1 == 0)
    {
        arb_poly_zero(res);
    }
    else if (len1 == 1 || len2 == 0)
    {
        arb_poly_set_arb(res, poly1->coeffs);
    }
    else
    {
        const slong lenr = (len1 - 1) * (len2 - 1) + 1;
        
        if (res != poly1 && res != poly2)
        {
            arb_poly_fit_length(res, lenr);
            _arb_poly_compose(res->coeffs, poly1->coeffs, len1,
                                                   poly2->coeffs, len2, prec);
        }
        else
        {
            arb_poly_t t;
            arb_poly_init2(t, lenr);
            _arb_poly_compose(t->coeffs, poly1->coeffs, len1,
                                                 poly2->coeffs, len2, prec);
            arb_poly_swap(res, t);
            arb_poly_clear(t);
        }

        _arb_poly_set_length(res, lenr);
        _arb_poly_normalise(res);
    }
}
Exemplo n.º 20
0
void
arb_poly_div_series(arb_poly_t Q, const arb_poly_t A, const arb_poly_t B, long n, long prec)
{
    if (n == 0)
    {
        arb_poly_zero(Q);
        return;
    }

    if (B->length == 0)
    {
        arb_poly_fit_length(Q, n);
        _arb_vec_indeterminate(Q->coeffs, n);
        _arb_poly_set_length(Q, n);
        return;
    }

    if (A->length == 0)
    {
        arb_poly_zero(Q);
        return;
    }

    if (Q == A || Q == B)
    {
        arb_poly_t t;
        arb_poly_init(t);
        arb_poly_div_series(t, A, B, n, prec);
        arb_poly_swap(Q, t);
        arb_poly_clear(t);
        return;
    }

    arb_poly_fit_length(Q, n);
    _arb_poly_div_series(Q->coeffs, A->coeffs, A->length, B->coeffs, B->length, n, prec);
    _arb_poly_set_length(Q, n);
    _arb_poly_normalise(Q);
}
Exemplo n.º 21
0
void
arb_poly_tan_series(arb_poly_t g, const arb_poly_t h, slong n, slong prec)
{
    if (h->length == 0 || n == 0)
    {
        arb_poly_zero(g);
        return;
    }

    if (g == h)
    {
        arb_poly_t t;
        arb_poly_init(t);
        arb_poly_tan_series(t, h, n, prec);
        arb_poly_swap(g, t);
        arb_poly_clear(t);
        return;
    }

    arb_poly_fit_length(g, n);
    _arb_poly_tan_series(g->coeffs, h->coeffs, h->length, n, prec);
    _arb_poly_set_length(g, n);
    _arb_poly_normalise(g);
}
Exemplo n.º 22
0
void
arb_poly_mullow_classical(arb_poly_t res, const arb_poly_t poly1,
                                            const arb_poly_t poly2,
                                                long n, long prec)
{
    long len_out;

    if (poly1->length == 0 || poly2->length == 0 || n == 0)
    {
        arb_poly_zero(res);
        return;
    }

    len_out = poly1->length + poly2->length - 1;
    if (n > len_out)
        n = len_out;

    if (res == poly1 || res == poly2)
    {
        arb_poly_t t;
        arb_poly_init2(t, n);
        _arb_poly_mullow_classical(t->coeffs, poly1->coeffs, poly1->length,
                                    poly2->coeffs, poly2->length, n, prec);
        arb_poly_swap(res, t);
        arb_poly_clear(t);
    }
    else
    {
        arb_poly_fit_length(res, n);
        _arb_poly_mullow_classical(res->coeffs, poly1->coeffs, poly1->length,
                                    poly2->coeffs, poly2->length, n, prec);
    }

    _arb_poly_set_length(res, n);
    _arb_poly_normalise(res);
}
Exemplo n.º 23
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("pow_ui....");
    fflush(stdout);

    flint_randinit(state);

    /* compare with fmpz_poly */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        slong zbits1, rbits1, rbits2;
        ulong e;
        fmpz_poly_t A, B;
        arb_poly_t a, b;

        zbits1 = 2 + n_randint(state, 100);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);
        e = n_randint(state, 30);

        fmpz_poly_init(A);
        fmpz_poly_init(B);

        arb_poly_init(a);
        arb_poly_init(b);

        fmpz_poly_randtest(A, state, 1 + n_randint(state, 8), zbits1);
        fmpz_poly_pow(B, A, e);

        arb_poly_set_fmpz_poly(a, A, rbits1);
        arb_poly_pow_ui(b, a, e, rbits2);

        if (!arb_poly_contains_fmpz_poly(b, B))
        {
            flint_printf("FAIL\n\n");
            flint_printf("bits2 = %wd\n", rbits2);
            flint_printf("e = %wu\n", e);

            flint_printf("A = "); fmpz_poly_print(A); flint_printf("\n\n");
            flint_printf("B = "); fmpz_poly_print(B); flint_printf("\n\n");

            flint_printf("a = "); arb_poly_printd(a, 15); flint_printf("\n\n");
            flint_printf("b = "); arb_poly_printd(b, 15); flint_printf("\n\n");

            abort();
        }

        arb_poly_pow_ui(a, a, e, rbits2);
        if (!arb_poly_equal(a, b))
        {
            flint_printf("FAIL (aliasing)\n\n");
            abort();
        }

        fmpz_poly_clear(A);
        fmpz_poly_clear(B);

        arb_poly_clear(a);
        arb_poly_clear(b);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 24
0
int main()
{
    long iter;
    flint_rand_t state;

    printf("interpolate_fast....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        long i, n, qbits1, qbits2, rbits1, rbits2, rbits3;
        fmpq_poly_t P;
        arb_poly_t R, S;
        fmpq_t t, u;
        arb_ptr xs, ys;

        fmpq_poly_init(P);
        arb_poly_init(R);
        arb_poly_init(S);
        fmpq_init(t);
        fmpq_init(u);

        qbits1 = 2 + n_randint(state, 200);
        qbits2 = 2 + n_randint(state, 5);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);
        rbits3 = 2 + n_randint(state, 200);

        fmpq_poly_randtest(P, state, 1 + n_randint(state, 20), qbits1);
        n = P->length;

        xs = _arb_vec_init(n);
        ys = _arb_vec_init(n);

        arb_poly_set_fmpq_poly(R, P, rbits1);

        if (n > 0)
        {
            fmpq_randtest(t, state, qbits2);
            arb_set_fmpq(xs, t, rbits2);

            for (i = 1; i < n; i++)
            {
                fmpq_randtest_not_zero(u, state, qbits2);
                fmpq_abs(u, u);
                fmpq_add(t, t, u);
                arb_set_fmpq(xs + i, t, rbits2);
            }
        }

        for (i = 0; i < n; i++)
            arb_poly_evaluate(ys + i, R, xs + i, rbits2);

        arb_poly_interpolate_fast(S, xs, ys, n, rbits3);

        if (!arb_poly_contains_fmpq_poly(S, P))
        {
            printf("FAIL:\n");
            printf("P = "); fmpq_poly_print(P); printf("\n\n");
            printf("R = "); arb_poly_printd(R, 15); printf("\n\n");
            printf("S = "); arb_poly_printd(S, 15); printf("\n\n");
            abort();
        }

        fmpq_poly_clear(P);
        arb_poly_clear(R);
        arb_poly_clear(S);
        fmpq_clear(t);
        fmpq_clear(u);
        _arb_vec_clear(xs, n);
        _arb_vec_clear(ys, n);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 25
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("taylor_shift_convolution....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 2000 * arb_test_multiplier(); iter++)
    {
        slong prec1, prec2;
        arb_poly_t f, g;
        arb_t c, d, e;

        prec1 = 2 + n_randint(state, 500);
        prec2 = 2 + n_randint(state, 500);

        arb_poly_init(f);
        arb_poly_init(g);

        arb_init(c);
        arb_init(d);
        arb_init(e);

        arb_poly_randtest(f, state, 1 + n_randint(state, 40), 1 + n_randint(state, 500), 10);
        arb_poly_randtest(g, state, 1 + n_randint(state, 20), 1 + n_randint(state, 500), 10);

        if (n_randint(state, 2))
            arb_set_si(c, n_randint(state, 5) - 2);
        else
            arb_randtest(c, state, 1 + n_randint(state, 500), 1 + n_randint(state, 100));

        if (n_randint(state, 2))
            arb_set_si(d, n_randint(state, 5) - 2);
        else
            arb_randtest(d, state, 1 + n_randint(state, 500), 1 + n_randint(state, 100));

        arb_add(e, c, d, prec1);

        /* check f(x+c)(x+d) = f(x+c+d) */
        arb_poly_taylor_shift_convolution(g, f, e, prec2);
        arb_poly_taylor_shift_convolution(f, f, c, prec1);
        arb_poly_taylor_shift_convolution(f, f, d, prec1);

        if (!arb_poly_overlaps(f, g))
        {
            flint_printf("FAIL\n\n");

            flint_printf("c = ");
            arb_printd(c, 15);
            flint_printf("\n\n");
            flint_printf("d = ");
            arb_printd(d, 15);
            flint_printf("\n\n");

            flint_printf("f = ");
            arb_poly_printd(f, 15);
            flint_printf("\n\n");
            flint_printf("g = ");
            arb_poly_printd(g, 15);
            flint_printf("\n\n");

            abort();
        }

        arb_poly_clear(f);
        arb_poly_clear(g);

        arb_clear(c);
        arb_clear(d);
        arb_clear(e);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("revert_series_lagrange....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
    {
        slong qbits1, rbits1, rbits2, n;
        fmpq_poly_t A, B;
        arb_poly_t a, b, c;

        qbits1 = 2 + n_randint(state, 200);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);
        n = 2 + n_randint(state, 25);

        fmpq_poly_init(A);
        fmpq_poly_init(B);

        arb_poly_init(a);
        arb_poly_init(b);
        arb_poly_init(c);

        do {
            fmpq_poly_randtest(A, state, 1 + n_randint(state, 25), qbits1);
            fmpq_poly_set_coeff_ui(A, 0, 0);
        } while (A->length < 2 || fmpz_is_zero(A->coeffs + 1));

        fmpq_poly_revert_series(B, A, n);

        arb_poly_set_fmpq_poly(a, A, rbits1);
        arb_poly_revert_series_lagrange(b, a, n, rbits2);

        if (!arb_poly_contains_fmpq_poly(b, B))
        {
            flint_printf("FAIL\n\n");
            flint_printf("n = %wd, bits2 = %wd\n", n, rbits2);

            flint_printf("A = "); fmpq_poly_print(A); flint_printf("\n\n");
            flint_printf("B = "); fmpq_poly_print(B); flint_printf("\n\n");

            flint_printf("a = "); arb_poly_printd(a, 15); flint_printf("\n\n");
            flint_printf("b = "); arb_poly_printd(b, 15); flint_printf("\n\n");

            flint_abort();
        }

        arb_poly_set(c, a);
        arb_poly_revert_series_lagrange(c, c, n, rbits2);
        if (!arb_poly_equal(c, b))
        {
            flint_printf("FAIL (aliasing)\n\n");
            flint_abort();
        }

        fmpq_poly_clear(A);
        fmpq_poly_clear(B);

        arb_poly_clear(a);
        arb_poly_clear(b);
        arb_poly_clear(c);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 27
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("evaluate_vec_fast....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        slong i, n, qbits1, qbits2, rbits1, rbits2, rbits3;
        fmpq_poly_t F;
        fmpq * X, * Y;
        arb_poly_t f;
        arb_ptr x, y;

        qbits1 = 2 + n_randint(state, 100);
        qbits2 = 2 + n_randint(state, 100);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);
        rbits3 = 2 + n_randint(state, 200);

        n = n_randint(state, 10);

        fmpq_poly_init(F);
        X = _fmpq_vec_init(n);
        Y = _fmpq_vec_init(n);

        arb_poly_init(f);
        x = _arb_vec_init(n);
        y = _arb_vec_init(n);

        fmpq_poly_randtest(F, state, 1 + n_randint(state, 20), qbits1);
        for (i = 0; i < n; i++)
            fmpq_randtest(X + i, state, qbits2);
        for (i = 0; i < n; i++)
            fmpq_poly_evaluate_fmpq(Y + i, F, X + i);

        arb_poly_set_fmpq_poly(f, F, rbits1);
        for (i = 0; i < n; i++)
            arb_set_fmpq(x + i, X + i, rbits2);
        arb_poly_evaluate_vec_fast(y, f, x, n, rbits3);

        for (i = 0; i < n; i++)
        {
            if (!arb_contains_fmpq(y + i, Y + i))
            {
                flint_printf("FAIL (%wd of %wd)\n\n", i, n);

                flint_printf("F = "); fmpq_poly_print(F); flint_printf("\n\n");
                flint_printf("X = "); fmpq_print(X + i); flint_printf("\n\n");
                flint_printf("Y = "); fmpq_print(Y + i); flint_printf("\n\n");

                flint_printf("f = "); arb_poly_printd(f, 15); flint_printf("\n\n");
                flint_printf("x = "); arb_printd(x + i, 15); flint_printf("\n\n");
                flint_printf("y = "); arb_printd(y + i, 15); flint_printf("\n\n");

                abort();
            }
        }

        fmpq_poly_clear(F);
        _fmpq_vec_clear(X, n);
        _fmpq_vec_clear(Y, n);

        arb_poly_clear(f);
        _arb_vec_clear(x, n);
        _arb_vec_clear(y, n);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 28
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("evaluate_horner....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        slong qbits1, qbits2, rbits1, rbits2, rbits3;
        fmpq_poly_t F;
        fmpq_t X, Y;
        arb_poly_t f;
        arb_t x, y;

        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(F);
        fmpq_init(X);
        fmpq_init(Y);

        arb_poly_init(f);
        arb_init(x);
        arb_init(y);

        fmpq_poly_randtest(F, state, 1 + n_randint(state, 20), qbits1);
        fmpq_randtest(X, state, qbits2);
        fmpq_poly_evaluate_fmpq(Y, F, X);

        arb_poly_set_fmpq_poly(f, F, rbits1);
        arb_set_fmpq(x, X, rbits2);
        arb_poly_evaluate_horner(y, f, x, rbits3);

        if (!arb_contains_fmpq(y, Y))
        {
            flint_printf("FAIL\n\n");

            flint_printf("F = "); fmpq_poly_print(F); flint_printf("\n\n");
            flint_printf("X = "); fmpq_print(X); flint_printf("\n\n");
            flint_printf("Y = "); fmpq_print(Y); flint_printf("\n\n");

            flint_printf("f = "); arb_poly_printd(f, 15); flint_printf("\n\n");
            flint_printf("x = "); arb_printd(x, 15); flint_printf("\n\n");
            flint_printf("y = "); arb_printd(y, 15); flint_printf("\n\n");

            abort();
        }

        /* aliasing */
        arb_poly_evaluate_horner(x, f, x, rbits3);
        if (!arb_contains_fmpq(x, Y))
        {
            flint_printf("FAIL (aliasing)\n\n");
            abort();
        }

        fmpq_poly_clear(F);
        fmpq_clear(X);
        fmpq_clear(Y);

        arb_poly_clear(f);
        arb_clear(x);
        arb_clear(y);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 29
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("cos_pi_series....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 1000; iter++)
    {
        slong m, n1, n2, bits1, bits2, bits3;
        arb_poly_t S, A, B, C;
        arb_t pi;

        bits1 = 2 + n_randint(state, 200);
        bits2 = 2 + n_randint(state, 200);
        bits3 = 2 + n_randint(state, 200);

        m = 1 + n_randint(state, 30);
        n1 = 1 + n_randint(state, 30);
        n2 = 1 + n_randint(state, 30);

        arb_poly_init(S);
        arb_poly_init(A);
        arb_poly_init(B);
        arb_poly_init(C);
        arb_init(pi);

        arb_poly_randtest(S, state, m, bits1, 3);
        arb_poly_randtest(A, state, m, bits1, 3);
        arb_poly_randtest(B, state, m, bits1, 3);

        arb_poly_cos_pi_series(A, S, n1, bits2);

        arb_const_pi(pi, bits3);
        arb_poly_set_arb(B, pi);
        arb_poly_mul(B, S, B, bits3);
        arb_poly_cos_series(B, B, n2, bits3);

        arb_poly_set(C, A);
        arb_poly_truncate(C, FLINT_MIN(n1, n2));
        arb_poly_truncate(B, FLINT_MIN(n1, n2));

        if (!arb_poly_overlaps(B, C))
        {
            flint_printf("FAIL\n\n");
            flint_printf("S = "); arb_poly_printd(S, 15); flint_printf("\n\n");
            flint_printf("A = "); arb_poly_printd(A, 15); flint_printf("\n\n");
            flint_printf("B = "); arb_poly_printd(B, 15); flint_printf("\n\n");
            abort();
        }

        arb_poly_cos_pi_series(S, S, n1, bits2);

        if (!arb_poly_overlaps(A, S))
        {
            flint_printf("FAIL (aliasing)\n\n");
            abort();
        }

        arb_poly_clear(S);
        arb_poly_clear(A);
        arb_poly_clear(B);
        arb_poly_clear(C);
        arb_clear(pi);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 30
0
int main()
{
    long iter;
    flint_rand_t state;

    printf("zeta_series....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 500; iter++)
    {
        long m, n1, n2, bits1, bits2, bits3;
        int deflate;
        arb_poly_t S, A, B, C, D, E, F;
        arb_t a, a1;

        bits1 = 2 + n_randint(state, 300);
        bits2 = 2 + n_randint(state, 300);
        bits3 = 2 + n_randint(state, 300);

        m = 1 + n_randint(state, 30);
        n1 = 1 + n_randint(state, 30);
        n2 = 1 + n_randint(state, 30);

        arb_poly_init(S);
        arb_poly_init(A);
        arb_poly_init(B);
        arb_poly_init(C);
        arb_poly_init(D);
        arb_poly_init(E);
        arb_poly_init(F);
        arb_init(a);
        arb_init(a1);

        deflate = n_randint(state, 2);

        arb_poly_randtest(S, state, m, bits1, 3);
        arb_randtest_precise(a, state, bits1, 3);
        arb_poly_set_coeff_arb(S, 0, a);

        if (n_randint(state, 2))
            arb_randtest(a, state, bits1, 3);
        else
            arb_one(a);

        arb_poly_zeta_series(A, S, a, deflate, n1, bits2);
        arb_poly_zeta_series(B, S, a, deflate, n2, bits3);

        arb_poly_set(C, A);
        arb_poly_truncate(C, FLINT_MIN(n1, n2));
        arb_poly_truncate(B, FLINT_MIN(n1, n2));

        if (!arb_poly_overlaps(B, C))
        {
            printf("FAIL\n\n");
            printf("S = "); arb_poly_printd(S, 15); printf("\n\n");
            printf("a = "); arb_printd(a, 15); printf("\n\n");
            printf("A = "); arb_poly_printd(A, 15); printf("\n\n");
            printf("B = "); arb_poly_printd(B, 15); printf("\n\n");
            abort();
        }

        /* check zeta(s,a) = zeta(s,a+1) + a^(-s) */
        arb_poly_set_arb(D, a);
        arb_poly_log_series(D, D, n1, bits2);
        arb_poly_mullow(D, D, S, n1, bits2);
        arb_poly_neg(D, D);
        arb_poly_exp_series(D, D, n1, bits2);

        arb_add_ui(a1, a, 1, bits2);
        arb_poly_zeta_series(E, S, a1, deflate, n1, bits2);
        arb_poly_add(E, E, D, bits2);

        if (!arb_poly_overlaps(A, E))
        {
            printf("FAIL (functional equation)\n\n");
            printf("S = "); arb_poly_printd(S, 15); printf("\n\n");
            printf("a = "); arb_printd(a, 15); printf("\n\n");
            printf("A = "); arb_poly_printd(A, 15); printf("\n\n");
            printf("E = "); arb_poly_printd(A, 15); printf("\n\n");
            abort();
        }

        arb_poly_zeta_series(S, S, a, deflate, n1, bits2);
        if (!arb_poly_overlaps(A, S))
        {
            printf("FAIL (aliasing)\n\n");
            abort();
        }

        arb_poly_clear(S);
        arb_poly_clear(A);
        arb_poly_clear(B);
        arb_poly_clear(C);
        arb_poly_clear(D);
        arb_poly_clear(E);
        arb_poly_clear(F);
        arb_clear(a);
        arb_clear(a1);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}