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

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

    flint_randinit(state);

    /* compare with fmpq_poly */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); 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_add(C, A, B);

        acb_poly_set_fmpq_poly(a, A, rbits1);
        acb_poly_set_fmpq_poly(b, B, rbits2);

        acb_poly_add(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_add(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_add(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;
}
Exemplo n.º 2
0
int
main(void)
{
    int i, j, result;
    ulong cflags = UWORD(0);

    mpq_t n1, n2;

    FLINT_TEST_INIT(state);

    flint_printf("get/set_coeff_fmpz....");
    fflush(stdout);

    mpq_init(n1);
    mpq_init(n2);   

    for (i = 0; i < 100 * flint_test_multiplier(); i++)
    {
        fmpq_poly_t a;
        fmpz_t x1, x2;
        slong coeff, len;

        fmpq_poly_init(a);
        fmpz_init(x1);
        fmpz_init(x2);
        len = (slong) (n_randint(state, 100) + 1);

        for (j = 0; j < 100; j++)
        {
            fmpz_randtest(x1, state, 200);
            fmpz_get_mpz(mpq_numref(n1), x1);
            flint_mpz_set_si(mpq_denref(n1), 1);
            coeff = (slong) n_randint(state, len);
            fmpq_poly_set_coeff_fmpz(a, coeff, x1);
            fmpq_poly_get_coeff_mpq(n2, a, coeff);

            cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
            result = (mpq_equal(n1, n2) && !cflags);
            if (!result)
            {
                flint_printf("FAIL:\n\n");
                flint_printf("a     = "), fmpq_poly_debug(a), flint_printf("\n\n");
                flint_printf("coeff = %wd\n\n", coeff);
                flint_printf("len   = %wd\n\n", len);
                flint_printf("cflags = %wu\n\n", cflags);
                gmp_printf("n1 = %Qd\n\n", n1);
                gmp_printf("n2 = %Qd\n\n", n2);
                abort();
            }
        }

        fmpz_clear(x1);
        fmpz_clear(x2);
        fmpq_poly_clear(a);
    }

    mpq_clear(n1);
    mpq_clear(n2);

    FLINT_TEST_CLEANUP(state);
    
    flint_printf("PASS\n");
    return 0;
}
Exemplo n.º 3
0
int
main(void)
{
    int i, result;
    ulong cflags = UWORD(0);

    FLINT_TEST_INIT(state);

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

    /* Check aliasing of a and c */
    for (i = 0; i < 20 * flint_test_multiplier(); i++)
    {
        fmpq_poly_t a, b;
        slong n = n_randint(state, 50) + 1;

        fmpq_poly_init(a);
        fmpq_poly_init(b);

        fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
        fmpq_poly_set_coeff_ui(a, 0, UWORD(0));

        fmpq_poly_canonicalise(a);

        fmpq_poly_asinh_series(b, a, n);
        fmpq_poly_asinh_series(a, a, n);

        cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
        result = (fmpq_poly_equal(a, b) && !cflags);
        if (!result)
        {
            flint_printf("FAIL:\n");
            fmpq_poly_debug(a), flint_printf("\n\n");
            fmpq_poly_debug(b), flint_printf("\n\n");
            flint_printf("cflags = %wu\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(a);
        fmpq_poly_clear(b);
    }

    /* Check asinh(A) = atanh(A/sqrt(1+A^2)) */
    for (i = 0; i < 20 * flint_test_multiplier(); i++)
    {
        fmpq_poly_t A, B, asinhA, atanhB;
        slong n = n_randint(state, 80) + 1;

        fmpq_poly_init(A);
        fmpq_poly_init(B);
        fmpq_poly_init(asinhA);
        fmpq_poly_init(atanhB);

        fmpq_poly_randtest_not_zero(A, state, n_randint(state, 80) + 1, 80);
        fmpq_poly_set_coeff_ui(A, 0, UWORD(0));

        fmpq_poly_mullow(B, A, A, n);
        fmpq_poly_set_coeff_ui(B, 0, UWORD(1));
        fmpq_poly_invsqrt_series(B, B, n);
        fmpq_poly_mullow(B, A, B, n);

        fmpq_poly_asinh_series(asinhA, A, n);
        fmpq_poly_atanh_series(atanhB, B, n);

        cflags |= fmpq_poly_is_canonical(asinhA) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(atanhB) ? 0 : 2;
        result = (fmpq_poly_equal(asinhA, atanhB) && !cflags);
        if (!result)
        {
            flint_printf("FAIL:\n");
            flint_printf("A = "), fmpq_poly_debug(A), flint_printf("\n\n");
            flint_printf("B = "), fmpq_poly_debug(B), flint_printf("\n\n");
            flint_printf("asinh(A) = "), fmpq_poly_debug(asinhA), flint_printf("\n\n");
            flint_printf("atanh(B) = "), fmpq_poly_debug(atanhB), flint_printf("\n\n");
            flint_printf("cflags = %wu\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(A);
        fmpq_poly_clear(B);
        fmpq_poly_clear(asinhA);
        fmpq_poly_clear(atanhB);
    }

    FLINT_TEST_CLEANUP(state);
    
    flint_printf("PASS\n");
    return 0;
}
Exemplo n.º 4
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 1000; 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(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");

            abort();
        }

        arb_poly_set(c, a);
        arb_poly_revert_series(c, c, n, rbits2);
        if (!arb_poly_equal(c, b))
        {
            flint_printf("FAIL (aliasing)\n\n");
            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.º 5
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        long 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(y, f, x, rbits3);

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

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

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

            abort();
        }

        /* aliasing */
        arb_poly_evaluate(x, f, x, rbits3);
        if (!arb_contains_fmpq(x, Y))
        {
            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();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 6
0
int
main(void)
{
    int i, result;
    flint_rand_t state;
    ulong cflags = 0UL;

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

    flint_randinit(state);

    /* Check aliasing of a and c */
    for (i = 0; i < 200; i++)
    {
        fmpq_poly_t a, b;
        long n = n_randint(state, 50) + 1;

        fmpq_poly_init(a);
        fmpq_poly_init(b);

        fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
        fmpq_poly_set_coeff_ui(a, 0, 0UL);

        fmpq_poly_canonicalise(a);

        fmpq_poly_sinh_series(b, a, n);
        fmpq_poly_sinh_series(a, a, n);

        cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
        result = (fmpq_poly_equal(a, b) && !cflags);
        if (!result)
        {
            printf("FAIL:\n");
            fmpq_poly_debug(a), printf("\n\n");
            fmpq_poly_debug(b), printf("\n\n");
            printf("cflags = %lu\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(a);
        fmpq_poly_clear(b);
    }

    /* Check asinh(sinh(a)) = a */
    for (i = 0; i < 200; i++)
    {
        fmpq_poly_t a, sinha, asinhsinha;
        long n = n_randint(state, 80) + 1;

        fmpq_poly_init(a);
        fmpq_poly_init(sinha);
        fmpq_poly_init(asinhsinha);

        fmpq_poly_randtest_not_zero(a, state, n_randint(state, 60) + 1, 80);
        fmpq_poly_set_coeff_ui(a, 0, 0UL);

        fmpq_poly_sinh_series(sinha, a, n);
        fmpq_poly_asinh_series(asinhsinha, sinha, n);
        fmpq_poly_truncate(a, n);

        cflags |= fmpq_poly_is_canonical(sinha) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(asinhsinha) ? 0 : 2;
        result = (fmpq_poly_equal(asinhsinha, a) && !cflags);
        if (!result)
        {
            printf("FAIL:\n");
            printf("a = "), fmpq_poly_debug(a), printf("\n\n");
            printf("sinh(a) = "), fmpq_poly_debug(sinha), printf("\n\n");
            printf("asinh(sinh(a)) = "), fmpq_poly_debug(asinhsinha), printf("\n\n");
            printf("cflags = %lu\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(a);
        fmpq_poly_clear(sinha);
        fmpq_poly_clear(asinhsinha);
    }

    flint_randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return 0;
}
Exemplo n.º 7
0
int
main(void)
{
    int i, result;

    padic_ctx_t ctx;
    fmpz_t p;
    slong N;

    FLINT_TEST_INIT(state);

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

    /* Check aliasing of a and b */
    for (i = 0; i < 1000; i++)
    {
        padic_poly_t a, b, c;

        fmpz_init_set_ui(p, n_randtest_prime(state, 0));
        N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN) 
            + PADIC_TEST_PREC_MIN;
        padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);

        padic_poly_init2(a, 0, N);
        padic_poly_init2(b, 0, N);
        padic_poly_init2(c, 0, N);

        padic_poly_randtest(b, state, n_randint(state, 50), ctx);
        padic_poly_randtest(c, state, n_randint(state, 50), ctx);

        padic_poly_mul(a, b, c, ctx);
        padic_poly_mul(b, b, c, ctx);

        result = (padic_poly_equal(a, b) && padic_poly_is_reduced(a, ctx));
        if (!result)
        {
            flint_printf("FAIL (aliasing a and b):\n");
            padic_poly_print(a, ctx), flint_printf("\n\n");
            padic_poly_print(b, ctx), flint_printf("\n\n");
            abort();
        }

        padic_poly_clear(a);
        padic_poly_clear(b);
        padic_poly_clear(c);

        padic_ctx_clear(ctx);
        fmpz_clear(p);
    }

    /* Check aliasing of a and c */
    for (i = 0; i < 1000; i++)
    {
        padic_poly_t a, b, c;

        fmpz_init_set_ui(p, n_randtest_prime(state, 0));
        N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN) 
            + PADIC_TEST_PREC_MIN;
        padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);

        padic_poly_init2(a, 0, N);
        padic_poly_init2(b, 0, N);
        padic_poly_init2(c, 0, N);

        padic_poly_randtest(b, state, n_randint(state, 50), ctx);
        padic_poly_randtest(c, state, n_randint(state, 50), ctx);

        padic_poly_mul(a, b, c, ctx);
        padic_poly_mul(c, b, c, ctx);

        result = (padic_poly_equal(a, c) && padic_poly_is_reduced(a, ctx));
        if (!result)
        {
            flint_printf("FAIL (aliasing a and c):\n");
            padic_poly_print(a, ctx), flint_printf("\n\n");
            padic_poly_print(c, ctx), flint_printf("\n\n");
            abort();
        }

        padic_poly_clear(a);
        padic_poly_clear(b);
        padic_poly_clear(c);

        padic_ctx_clear(ctx);
        fmpz_clear(p);
    }

    /* Check (b * c) + (b * d) = b * (c + d) */
    for (i = 0; i < 1000; i++)
    {
        padic_poly_t a1, a2, b, c, d, t;
        slong v;

        fmpz_init_set_ui(p, n_randtest_prime(state, 0));
        N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN) 
            + PADIC_TEST_PREC_MIN;
        padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);

        padic_poly_init2(b, 0, N);
        padic_poly_init2(c, 0, N);
        padic_poly_init2(d, 0, N);
        padic_poly_init2(t, 0, N);

        padic_poly_randtest(b, state, n_randint(state, 100), ctx);
        padic_poly_randtest(c, state, n_randint(state, 100), ctx);
        padic_poly_randtest(d, state, n_randint(state, 100), ctx);

        v = FLINT_MIN(b->val, c->val);
        v = FLINT_MIN(v, d->val);
        v = FLINT_MIN(v, 0);

        if (v >= 0 || -v < N)  /* Otherwise, no precision left */
        {
            slong N2 = (v >= 0) ? N : N + v;

            padic_poly_init2(a1, 0, N2);
            padic_poly_init2(a2, 0, N2);

            padic_poly_mul(a1, b, c, ctx);
            padic_poly_mul(t, b, d, ctx);
            padic_poly_add(a1, a1, t, ctx);     /* Lower precision */

            padic_poly_add(t, c, d, ctx);
            padic_poly_mul(a2, b, t, ctx);      /* Lower precision */

            result = (padic_poly_equal(a1, a2) && padic_poly_is_reduced(a1, ctx));
            if (!result)
            {
                flint_printf("FAIL (distributivity):\n");
                flint_printf("p = "), fmpz_print(ctx->p), flint_printf("\n\n");
                flint_printf("N = %wd\n\n", N);
                flint_printf("b = "), padic_poly_print(b, ctx), flint_printf("\n\n");
                flint_printf("c = "), padic_poly_print(c, ctx), flint_printf("\n\n");
                flint_printf("d = "), padic_poly_print(d, ctx), flint_printf("\n\n");
                flint_printf("a1 = "), padic_poly_print(a1, ctx), flint_printf("\n\n");
                flint_printf("a2 = "), padic_poly_print(a2, ctx), flint_printf("\n\n");
                abort();
            }

            padic_poly_clear(a1);
            padic_poly_clear(a2);
        }

        padic_poly_clear(b);
        padic_poly_clear(c);
        padic_poly_clear(d);

        padic_ctx_clear(ctx);
        fmpz_clear(p);
    }

    /* Compare with Q */
    for (i = 0; i < 10000; i++)
    {
        padic_poly_t a, b, c, d;
        fmpq_poly_t x, y, z;

        fmpz_init_set_ui(p, n_randtest_prime(state, 0));
        N = n_randint(state, PADIC_TEST_PREC_MAX - PADIC_TEST_PREC_MIN) 
            + PADIC_TEST_PREC_MIN;
        padic_ctx_init(ctx, p, FLINT_MAX(0, N-10), FLINT_MAX(0, N+10), PADIC_SERIES);

        padic_poly_init2(a, 0, N);
        padic_poly_init2(b, 0, N);
        padic_poly_init2(c, 0, N);
        padic_poly_init2(d, 0, N);

        fmpq_poly_init(x);
        fmpq_poly_init(y);
        fmpq_poly_init(z);

        padic_poly_randtest(b, state, n_randint(state, 50), ctx);
        padic_poly_randtest(c, state, n_randint(state, 50), ctx);

        padic_poly_mul(a, b, c, ctx);

        padic_poly_get_fmpq_poly(y, b, ctx);
        padic_poly_get_fmpq_poly(z, c, ctx);

        fmpq_poly_mul(x, y, z);
        padic_poly_set_fmpq_poly(d, x, ctx);

        result = (padic_poly_equal(a, d) && padic_poly_is_reduced(a, ctx));
        if (!result)
        {
            flint_printf("FAIL (cmp with Q):\n");
            flint_printf("N = %wd, val(b) = %wd, val(c) = %wd\n", N, b->val, c->val);
            padic_poly_print(c, ctx), flint_printf("\n\n");
            padic_poly_print(d, ctx), flint_printf("\n\n");
            abort();
        }

        padic_poly_clear(a);
        padic_poly_clear(b);
        padic_poly_clear(c);
        padic_poly_clear(d);

        fmpq_poly_clear(x);
        fmpq_poly_clear(y);
        fmpq_poly_clear(z);

        padic_ctx_clear(ctx);
        fmpz_clear(p);
    }

    FLINT_TEST_CLEANUP(state);
    
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 8
0
int
main(void)
{
    int i, result;
    flint_rand_t state;
    ulong cflags = 0UL;

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

    flint_randinit(state);

    /* Check aliasing of a and c */
    for (i = 0; i < 200; i++)
    {
        fmpq_poly_t a, b;
        long n = n_randint(state, 50) + 1;

        fmpq_poly_init(a);
        fmpq_poly_init(b);

        fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
        fmpq_poly_set_coeff_ui(a, 0, 0UL);

        fmpq_poly_canonicalise(a);

        fmpq_poly_exp_series(b, a, n);
        fmpq_poly_exp_series(a, a, n);

        cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
        result = (fmpq_poly_equal(a, b) && !cflags);
        if (!result)
        {
            printf("FAIL:\n");
            fmpq_poly_debug(a), printf("\n\n");
            fmpq_poly_debug(b), printf("\n\n");
            printf("cflags = %lu\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(a);
        fmpq_poly_clear(b);
    }

    /* Check exp(a+b) = exp(a) * exp(b) */
    for (i = 0; i < 500; i++)
    {
        fmpq_poly_t a, b, ab, expa, expb, expab, expa_expb;
        long n = n_randint(state, 80) + 1;

        fmpq_poly_init(a);
        fmpq_poly_init(b);
        fmpq_poly_init(ab);
        fmpq_poly_init(expa);
        fmpq_poly_init(expb);
        fmpq_poly_init(expab);
        fmpq_poly_init(expa_expb);

        fmpq_poly_randtest_not_zero(a, state, n_randint(state, 60) + 1, 80);
        fmpq_poly_set_coeff_ui(a, 0, 0UL);

        fmpq_poly_randtest_not_zero(b, state, n_randint(state, 60) + 1, 80);
        fmpq_poly_set_coeff_ui(b, 0, 0UL);

        fmpq_poly_add(ab, a, b);

        fmpq_poly_exp_series(expab, ab, n);
        fmpq_poly_exp_series(expa, a, n);
        fmpq_poly_exp_series(expb, b, n);
        fmpq_poly_mullow(expa_expb, expa, expb, n);

        cflags |= fmpq_poly_is_canonical(expa) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(expb) ? 0 : 2;
        cflags |= fmpq_poly_is_canonical(expab) ? 0 : 4;
        result = (fmpq_poly_equal(expab, expa_expb) && !cflags);
        if (!result)
        {
            printf("FAIL:\n");
            printf("a = "), fmpq_poly_debug(a), printf("\n\n");
            printf("b = "), fmpq_poly_debug(b), printf("\n\n");
            printf("exp(a) = "), fmpq_poly_debug(expa), printf("\n\n");
            printf("exp(b) = "), fmpq_poly_debug(expb), printf("\n\n");
            printf("exp(ab) = "), fmpq_poly_debug(expab), printf("\n\n");
            printf("cflags = %lu\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(a);
        fmpq_poly_clear(b);
        fmpq_poly_clear(ab);
        fmpq_poly_clear(expa);
        fmpq_poly_clear(expb);
        fmpq_poly_clear(expab);
        fmpq_poly_clear(expa_expb);
    }

    flint_randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return 0;
}
Exemplo n.º 9
0
Arquivo: kes.c Projeto: raoulbq/kes
int main(int argc, char* argv[]) {
    int i, j, k;
    int levels[argc-1];
    fmpq_poly_t Pn, Ep;
    long deg;
    char *strf;
    acb_ptr nodes;
    acb_ptr weights;
    int solvable;
    int validate_extension, validate_weights;
    int valid;
    int comp_nodes, comp_weights;
    int target_prec;
    int nrprintdigits;
    int loglevel;

    if(argc <= 1) {
        printf("Compute a nested generalized Kronrod extension of a Gauss rule\n");
        printf("Syntax: kes [-ve] [-vw] [-cn] [-cw] [-dc D] [-dp D] [-l L] n p1 p2 ... pk\n");
        printf("Options:\n");
        printf("        -ve  Validate the polynomial extension by nodes\n");
        printf("        -vw  Validate the polynomial extension by weights\n");
        printf("        -cn  Compute the nodes\n");
        printf("        -cw  Compute the weights\n");
        printf("        -dc  Compute nodes and weights up to this number of decimal digits\n");
        printf("        -dp  Print this number of decimal digits\n");
        printf("        -l   Set the log level\n");
        return EXIT_FAILURE;
    }

    target_prec = 53;
    nrprintdigits = 20;
    loglevel = 8;
    comp_nodes = 0;
    comp_weights = 0;
    validate_extension = 0;
    validate_weights = 0;

    k = 0;
    for(i = 1; i < argc; i++) {
        if (!strcmp(argv[i], "-ve")) {
            validate_extension = 1;
        } else if (!strcmp(argv[i], "-vw")) {
            validate_weights = 1;
        } else if (!strcmp(argv[i], "-cn")) {
            comp_nodes = 1;
        } else if (!strcmp(argv[i], "-cw")) {
            comp_weights = 1;
        } else if (!strcmp(argv[i], "-dc")) {
            /* 'digits' is in base 10 and log(10)/log(2) = 3.32193 */
            target_prec = 3.32193 * atoi(argv[i+1]);
            i++;
        } else if (!strcmp(argv[i], "-dp")) {
            nrprintdigits = atoi(argv[i+1]);
            i++;
        } else if (!strcmp(argv[i], "-l")) {
            loglevel = atoi(argv[i+1]);
            i++;
        } else {
            levels[k] = atoi(argv[i]);
            k++;
        }
    }

    /* Compute extension */
    fmpq_poly_init(Pn);
    polynomial(Pn, levels[0]);

    printf("Starting with polynomial:\n");
    strf = fmpq_poly_get_str_pretty(Pn, "t");
    flint_printf("P : %s\n", strf);
    printf("Extension levels are:");
    for(i = 0; i < k; i++) {
        printf(" %i", levels[i]);
    }
    printf("\n");

    fmpq_poly_init(Ep);

    solvable = find_multi_extension(Ep, Pn, k, levels, validate_extension, loglevel);

    fmpq_poly_mul(Pn, Pn, Ep);
    fmpq_poly_canonicalise(Pn);

    if(solvable) {
        if(! fmpq_poly_is_squarefree(Pn)) {
            printf("=====>  FINAL POLYNOMIAL NOT SQF  <=====");
        }

        if(loglevel >= 2) {
            printf("-------------------------------------------------\n");
            printf("Ending with final polynomial:\n");
            strf = fmpq_poly_get_str_pretty(Pn, "t");
            flint_printf("P : %s\n", strf);
        }

        deg = fmpq_poly_degree(Pn);
        nodes = _acb_vec_init(deg);
        weights = _acb_vec_init(deg);

        if(comp_weights || validate_weights) {
            compute_nodes_and_weights(nodes, weights, Pn, target_prec, loglevel);
        } else if(comp_nodes) {
            compute_nodes(nodes, Pn, target_prec, loglevel);
        }

        valid = 1;
        if(validate_weights) {
            valid = validate_extension_by_weights(weights, deg, target_prec, loglevel);
        }

        if(! valid) {
            printf("**************************************\n");
            printf("*** EXTENSION WITH INVALID WEIGHTS ***\n");
            printf("**************************************\n");
        }

        /* Print roots and weights */
        if((validate_weights && valid) || ! validate_weights) {
            if(comp_nodes) {
                printf("-------------------------------------------------\n");
                printf("The nodes are:\n");
                for(j = 0; j < deg; j++) {
                    printf("| ");
                    acb_printd(nodes + j, nrprintdigits);
                    printf("\n");
                }
            }

            if(comp_weights) {
                printf("-------------------------------------------------\n");
                printf("The weights are:\n");
                for(j = 0; j < deg; j++) {
                    printf("| ");
                    acb_printd(weights + j, nrprintdigits);
                    printf("\n");
                }
            }
        }

        _acb_vec_clear(nodes, deg);
        _acb_vec_clear(weights, deg);
    }

    flint_free(strf);
    fmpq_poly_clear(Pn);
    fmpq_poly_clear(Ep);
    return EXIT_SUCCESS;
}
Exemplo n.º 10
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    /* compare with fmpq_poly */
    for (iter = 0; iter < 10000; iter++)
    {
        long m, n, qbits, rbits1, rbits2;
        fmpq_poly_t A, B;
        fmpcb_poly_t a, b;

        qbits = 2 + n_randint(state, 200);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);

        m = 1 + n_randint(state, 20);
        n = 1 + n_randint(state, 20);

        fmpq_poly_init(A);
        fmpq_poly_init(B);

        fmpcb_poly_init(a);
        fmpcb_poly_init(b);

        fmpq_poly_randtest_not_zero(A, state, m, qbits);
        fmpq_poly_set_coeff_ui(A, 0, 1UL);

        fmpq_poly_log_series(B, A, n);
        fmpcb_poly_set_fmpq_poly(a, A, rbits1);
        fmpcb_poly_randtest(b, state, 1 + n_randint(state, 20), rbits1, 5);
        fmpcb_poly_log_series(b, a, n, rbits2);

        if (!fmpcb_poly_contains_fmpq_poly(b, B))
        {
            printf("FAIL\n\n");
            printf("bits2 = %ld\n", rbits2);

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

            printf("a = "); fmpcb_poly_printd(a, 15); printf("\n\n");
            printf("b = "); fmpcb_poly_printd(b, 15); printf("\n\n");

            abort();
        }

        fmpq_poly_clear(A);
        fmpq_poly_clear(B);

        fmpcb_poly_clear(a);
        fmpcb_poly_clear(b);
    }

    /* test aliasing */
    for (iter = 0; iter < 10000; iter++)
    {
        long m, n, qbits, rbits1, rbits2;
        fmpq_poly_t A;
        fmpcb_poly_t a, b;

        qbits = 2 + n_randint(state, 200);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);

        m = 1 + n_randint(state, 20);
        n = 1 + n_randint(state, 20);

        fmpq_poly_init(A);
        fmpcb_poly_init(a);
        fmpcb_poly_init(b);

        do {
            fmpq_poly_randtest_not_zero(A, state, m, qbits);
        } while (fmpz_sgn(A->coeffs + 0) <= 0);

        fmpcb_poly_set_fmpq_poly(a, A, rbits1);

        fmpcb_poly_log_series(b, a, n, rbits2);
        fmpcb_poly_log_series(a, a, n, rbits2);

        if (!fmpcb_poly_equal(a, b))
        {
            printf("FAIL\n\n");
            printf("bits2 = %ld\n", rbits2);

            printf("A = "); fmpq_poly_print(A); printf("\n\n");

            printf("a = "); fmpcb_poly_printd(a, 15); printf("\n\n");
            printf("b = "); fmpcb_poly_printd(b, 15); printf("\n\n");

            abort();
        }

        fmpq_poly_clear(A);
        fmpcb_poly_clear(a);
        fmpcb_poly_clear(b);
    }

    /* test that exp(log(f)) contains f */
    for (iter = 0; iter < 10000; iter++)
    {
        long m, n, qbits, rbits1, rbits2, rbits3;
        fmpq_poly_t A;
        fmpcb_poly_t a, b, c;

        qbits = 2 + n_randint(state, 200);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);
        rbits3 = 2 + n_randint(state, 200);

        m = 1 + n_randint(state, 20);
        n = 1 + n_randint(state, 20);

        fmpq_poly_init(A);
        fmpcb_poly_init(a);
        fmpcb_poly_init(b);
        fmpcb_poly_init(c);

        do {
            fmpq_poly_randtest_not_zero(A, state, m, qbits);
        } while (fmpz_sgn(A->coeffs + 0) <= 0);

        fmpcb_poly_set_fmpq_poly(a, A, rbits1);

        fmpcb_poly_randtest(b, state, 1 + n_randint(state, 20), rbits1, 5);
        fmpcb_poly_log_series(b, a, n, rbits2);
        fmpcb_poly_exp_series_basecase(c, b, n, rbits3);

        fmpq_poly_truncate(A, n);

        if (!fmpcb_poly_contains_fmpq_poly(c, A))
        {
            printf("FAIL\n\n");
            printf("bits2 = %ld\n", rbits2);
            printf("bits3 = %ld\n", rbits3);

            printf("A = "); fmpq_poly_print(A); printf("\n\n");

            printf("a = "); fmpcb_poly_printd(a, 15); printf("\n\n");
            printf("b = "); fmpcb_poly_printd(b, 15); printf("\n\n");
            printf("c = "); fmpcb_poly_printd(c, 15); printf("\n\n");

            abort();
        }

        fmpq_poly_clear(A);
        fmpcb_poly_clear(a);
        fmpcb_poly_clear(b);
        fmpcb_poly_clear(c);
    }

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

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

    flint_randinit(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        slong m, n, qbits1, qbits2, rbits1, rbits2, rbits3;
        fmpq_poly_t A, B, Q, R;
        acb_poly_t a, b, q, r;

        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);

        m = 1 + n_randint(state, 20);
        n = 1 + n_randint(state, 20);

        fmpq_poly_init(A);
        fmpq_poly_init(B);
        fmpq_poly_init(Q);
        fmpq_poly_init(R);

        acb_poly_init(a);
        acb_poly_init(b);
        acb_poly_init(q);
        acb_poly_init(r);

        fmpq_poly_randtest(A, state, m, qbits1);
        fmpq_poly_randtest_not_zero(B, state, n, qbits2);

        fmpq_poly_divrem(Q, R, A, B);

        acb_poly_set_fmpq_poly(a, A, rbits1);
        acb_poly_set_fmpq_poly(b, B, rbits2);

        acb_poly_divrem(q, r, a, b, rbits3);

        if (!acb_poly_contains_fmpq_poly(q, Q) ||
             !acb_poly_contains_fmpq_poly(r, R))
        {
            flint_printf("FAIL\n\n");

            flint_printf("A = "); fmpq_poly_print(A); flint_printf("\n\n");
            flint_printf("B = "); fmpq_poly_print(B); flint_printf("\n\n");
            flint_printf("Q = "); fmpq_poly_print(Q); flint_printf("\n\n");
            flint_printf("R = "); fmpq_poly_print(R); 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("q = "); acb_poly_printd(q, 15); flint_printf("\n\n");
            flint_printf("r = "); acb_poly_printd(r, 15); flint_printf("\n\n");

            abort();
        }

        acb_poly_divrem(a, r, a, b, rbits3);
        if (!acb_poly_equal(a, q))
        {
            flint_printf("FAIL (aliasing q, a)\n\n");
        }
        acb_poly_set_fmpq_poly(a, A, rbits1);

        acb_poly_divrem(b, r, a, b, rbits3);
        if (!acb_poly_equal(b, q))
        {
            flint_printf("FAIL (aliasing q, b)\n\n");
            abort();
        }
        acb_poly_set_fmpq_poly(b, B, rbits2);

        acb_poly_divrem(q, a, a, b, rbits3);
        if (!acb_poly_equal(a, r))
        {
            flint_printf("FAIL (aliasing r, a)\n\n");
            abort();
        }
        acb_poly_set_fmpq_poly(a, A, rbits1);

        acb_poly_divrem(q, b, a, b, rbits3);
        if (!acb_poly_equal(b, r))
        {
            flint_printf("FAIL (aliasing r, b)\n\n");
            abort();
        }

        fmpq_poly_clear(A);
        fmpq_poly_clear(B);
        fmpq_poly_clear(Q);
        fmpq_poly_clear(R);

        acb_poly_clear(a);
        acb_poly_clear(b);
        acb_poly_clear(q);
        acb_poly_clear(r);
    }

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

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

    flint_randinit(state);

    for (iter = 0; iter < 5000; iter++)
    {
        slong m, n, qbits, rbits1, rbits2;
        fmpq_poly_t A;
        acb_poly_t a, b, c;

        qbits = 2 + n_randint(state, 200);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);

        m = 1 + n_randint(state, 30);
        n = 1 + n_randint(state, 30);

        fmpq_poly_init(A);
        acb_poly_init(a);
        acb_poly_init(b);
        acb_poly_init(c);

        fmpq_poly_randtest_not_zero(A, state, m, qbits);
        acb_poly_set_fmpq_poly(a, A, rbits1);

        acb_poly_randtest(b, state, 1 + n_randint(state, 30), rbits1, 5);

        acb_poly_rsqrt_series(b, a, n, rbits2);

        /* Check 1/((1/sqrt(a))^2) = a */
        acb_poly_mullow(c, b, b, n, rbits2);
        acb_poly_inv_series(c, c, n, rbits2);

        fmpq_poly_truncate(A, n);
        if (!acb_poly_contains_fmpq_poly(c, A))
        {
            flint_printf("FAIL\n\n");
            flint_printf("bits2 = %wd\n", rbits2);

            flint_printf("A = "); fmpq_poly_print(A); 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_rsqrt_series(a, a, n, rbits2);
        if (!acb_poly_equal(a, b))
        {
            flint_printf("FAIL (aliasing)\n\n");
            abort();
        }

        fmpq_poly_clear(A);
        acb_poly_clear(a);
        acb_poly_clear(b);
        acb_poly_clear(c);
    }

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

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

    flint_randinit(state);

    /* compare with fmpq_poly */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        slong qbits1, qbits2, rbits1, rbits2, rbits3, trunc;
        fmpq_poly_t A, B, C;
        arb_poly_t a, b, c, d;

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

        fmpq_poly_init(A);
        fmpq_poly_init(B);
        fmpq_poly_init(C);

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

        fmpq_poly_randtest(A, state, 1 + n_randint(state, 100), qbits1);
        fmpq_poly_randtest(B, state, 1 + n_randint(state, 100), qbits2);
        fmpq_poly_mullow(C, A, B, trunc);

        arb_poly_set_fmpq_poly(a, A, rbits1);
        arb_poly_set_fmpq_poly(b, B, rbits2);
        arb_poly_mullow_block(c, a, b, trunc, rbits3);

        if (!arb_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 = "); arb_poly_printd(a, 15); flint_printf("\n\n");
            flint_printf("b = "); arb_poly_printd(b, 15); flint_printf("\n\n");
            flint_printf("c = "); arb_poly_printd(c, 15); flint_printf("\n\n");

            abort();
        }

        arb_poly_set(d, a);
        arb_poly_mullow_block(d, d, b, trunc, rbits3);
        if (!arb_poly_equal(d, c))
        {
            flint_printf("FAIL (aliasing 1)\n\n");
            abort();
        }

        arb_poly_set(d, b);
        arb_poly_mullow_block(d, a, d, trunc, rbits3);
        if (!arb_poly_equal(d, c))
        {
            flint_printf("FAIL (aliasing 2)\n\n");
            abort();
        }

        /* test squaring */
        arb_poly_set(b, a);
        arb_poly_mullow_block(c, a, b, trunc, rbits3);
        arb_poly_mullow_block(d, a, a, trunc, rbits3);
        if (!arb_poly_overlaps(c, d))  /* not guaranteed to be identical */
        {
            flint_printf("FAIL (squaring)\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_printf("c = "); arb_poly_printd(c, 15); flint_printf("\n\n");

            abort();
        }

        arb_poly_mullow_block(a, a, a, trunc, rbits3);
        if (!arb_poly_equal(d, a))
        {
            flint_printf("FAIL (aliasing, squaring)\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_printf("d = "); arb_poly_printd(d, 15); flint_printf("\n\n");

            abort();
        }

        fmpq_poly_clear(A);
        fmpq_poly_clear(B);
        fmpq_poly_clear(C);

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

    for (iter = 0; iter < 3000 * arb_test_multiplier(); iter++)
    {
        slong rbits1, rbits2, rbits3, trunc;
        arb_poly_t a, b, c, ab, ac, bc, abc, abc2;

        rbits1 = 2 + n_randint(state, 300);
        rbits2 = 2 + n_randint(state, 300);
        rbits3 = 2 + n_randint(state, 300);
        trunc = n_randint(state, 100);

        arb_poly_init(a);
        arb_poly_init(b);
        arb_poly_init(c);
        arb_poly_init(ab);
        arb_poly_init(ac);
        arb_poly_init(bc);
        arb_poly_init(abc);
        arb_poly_init(abc2);

        arb_poly_randtest(a, state, 1 + n_randint(state, 100), rbits1, 1 + n_randint(state, 100));
        arb_poly_randtest(b, state, 1 + n_randint(state, 100), rbits2, 1 + n_randint(state, 100));
        arb_poly_randtest(c, state, 1 + n_randint(state, 100), rbits2, 1 + n_randint(state, 100));

        /* check a*(b+c) = a*b + a*c */
        arb_poly_mullow_block(ab, a, b, trunc, rbits3);
        arb_poly_mullow_block(ac, a, c, trunc, rbits3);
        arb_poly_add(abc, ab, ac, rbits3);

        arb_poly_add(bc, b, c, rbits3);
        arb_poly_mullow_block(abc2, a, bc, trunc, rbits3);

        if (!arb_poly_overlaps(abc, abc2))
        {
            flint_printf("FAIL (a*(b+c) = a*b + a*c) \n\n");
            flint_printf("bits3 = %wd\n", rbits3);
            flint_printf("trunc = %wd\n", trunc);

            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_printf("c = "); arb_poly_printd(c, 15); flint_printf("\n\n");

            abort();
        }

        /* check (b+c)^2 = b^2 + 2bc + c^2 */
        arb_poly_mullow_block(a, b, c, trunc, rbits3);
        arb_poly_scalar_mul_2exp_si(a, a, 1);
        arb_poly_mullow_block(abc, b, b, trunc, rbits3);
        arb_poly_mullow_block(abc2, c, c, trunc, rbits3);
        arb_poly_add(abc, abc, a, rbits3);
        arb_poly_add(abc, abc, abc2, rbits3);

        arb_poly_mullow_block(abc2, bc, bc, trunc, rbits3);

        if (!arb_poly_overlaps(abc, abc2))
        {
            flint_printf("FAIL ((b+c)^2 = b^2 + 2bc + c^2) \n\n");
            flint_printf("bits3 = %wd\n", rbits3);
            flint_printf("trunc = %wd\n", trunc);

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

            flint_printf("abc  = "); arb_poly_printd(abc, 15); flint_printf("\n\n");
            flint_printf("abc2 = "); arb_poly_printd(abc2, 15); flint_printf("\n\n");

            abort();
        }

        arb_poly_clear(a);
        arb_poly_clear(b);
        arb_poly_clear(c);
        arb_poly_clear(ab);
        arb_poly_clear(ac);
        arb_poly_clear(bc);
        arb_poly_clear(abc);
        arb_poly_clear(abc2);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 14
0
int main(int argc, char *argv[])
{
    fmpz_poly_t f, g;
    fmpz_poly_factor_t fac;
    fmpz_t t;
    slong compd, printd, i, j;

    if (argc < 2)
    {
        flint_printf("poly_roots [-refine d] [-print d] <poly>\n\n");

        flint_printf("Isolates all the complex roots of a polynomial with integer coefficients.\n\n");

        flint_printf("If -refine d is passed, the roots are refined to an absolute tolerance\n");
        flint_printf("better than 10^(-d). By default, the roots are only computed to sufficient\n");
        flint_printf("accuracy to isolate them. The refinement is not currently done efficiently.\n\n");

        flint_printf("If -print d is passed, the computed roots are printed to d decimals.\n");
        flint_printf("By default, the roots are not printed.\n\n");

        flint_printf("The polynomial can be specified by passing the following as <poly>:\n\n");

        flint_printf("a <n>          Easy polynomial 1 + 2x + ... + (n+1)x^n\n");
        flint_printf("t <n>          Chebyshev polynomial T_n\n");
        flint_printf("u <n>          Chebyshev polynomial U_n\n");
        flint_printf("p <n>          Legendre polynomial P_n\n");
        flint_printf("c <n>          Cyclotomic polynomial Phi_n\n");
        flint_printf("s <n>          Swinnerton-Dyer polynomial S_n\n");
        flint_printf("b <n>          Bernoulli polynomial B_n\n");
        flint_printf("w <n>          Wilkinson polynomial W_n\n");
        flint_printf("e <n>          Taylor series of exp(x) truncated to degree n\n");
        flint_printf("m <n> <m>      The Mignotte-like polynomial x^n + (100x+1)^m, n > m\n");
        flint_printf("coeffs <c0 c1 ... cn>        c0 + c1 x + ... + cn x^n\n\n");

        flint_printf("Concatenate to multiply polynomials, e.g.: p 5 t 6 coeffs 1 2 3\n");
        flint_printf("for P_5(x)*T_6(x)*(1+2x+3x^2)\n\n");

        return 1;
    }

    compd = 0;
    printd = 0;

    fmpz_poly_init(f);
    fmpz_poly_init(g);
    fmpz_init(t);
    fmpz_poly_one(f);

    for (i = 1; i < argc; i++)
    {
        if (!strcmp(argv[i], "-refine"))
        {
            compd = atol(argv[i+1]);
            i++;
        }
        else if (!strcmp(argv[i], "-print"))
        {
            printd = atol(argv[i+1]);
            i++;
        }
        else if (!strcmp(argv[i], "a"))
        {
            slong n = atol(argv[i+1]);
            fmpz_poly_zero(g);
            for (j = 0; j <= n; j++)
                fmpz_poly_set_coeff_ui(g, j, j+1);
            fmpz_poly_mul(f, f, g);
            i++;
        }
        else if (!strcmp(argv[i], "t"))
        {
            arith_chebyshev_t_polynomial(g, atol(argv[i+1]));
            fmpz_poly_mul(f, f, g);
            i++;
        }
        else if (!strcmp(argv[i], "u"))
        {
            arith_chebyshev_u_polynomial(g, atol(argv[i+1]));
            fmpz_poly_mul(f, f, g);
            i++;
        }
        else if (!strcmp(argv[i], "p"))
        {
            fmpq_poly_t h;
            fmpq_poly_init(h);
            arith_legendre_polynomial(h, atol(argv[i+1]));
            fmpq_poly_get_numerator(g, h);
            fmpz_poly_mul(f, f, g);
            fmpq_poly_clear(h);
            i++;
        }
        else if (!strcmp(argv[i], "c"))
        {
            arith_cyclotomic_polynomial(g, atol(argv[i+1]));
            fmpz_poly_mul(f, f, g);
            i++;
        }
        else if (!strcmp(argv[i], "s"))
        {
            arith_swinnerton_dyer_polynomial(g, atol(argv[i+1]));
            fmpz_poly_mul(f, f, g);
            i++;
        }
        else if (!strcmp(argv[i], "b"))
        {
            fmpq_poly_t h;
            fmpq_poly_init(h);
            arith_bernoulli_polynomial(h, atol(argv[i+1]));
            fmpq_poly_get_numerator(g, h);
            fmpz_poly_mul(f, f, g);
            fmpq_poly_clear(h);
            i++;
        }
        else if (!strcmp(argv[i], "w"))
        {
            slong n = atol(argv[i+1]);
            fmpz_poly_zero(g);
            fmpz_poly_fit_length(g, n+2);
            arith_stirling_number_1_vec(g->coeffs, n+1, n+2);
            _fmpz_poly_set_length(g, n+2);
            fmpz_poly_shift_right(g, g, 1);
            fmpz_poly_mul(f, f, g);
            i++;
        }
        else if (!strcmp(argv[i], "e"))
        {
            fmpq_poly_t h;
            fmpq_poly_init(h);
            fmpq_poly_set_coeff_si(h, 0, 0);
            fmpq_poly_set_coeff_si(h, 1, 1);
            fmpq_poly_exp_series(h, h, atol(argv[i+1]) + 1);
            fmpq_poly_get_numerator(g, h);
            fmpz_poly_mul(f, f, g);
            fmpq_poly_clear(h);
            i++;
        }
        else if (!strcmp(argv[i], "m"))
        {
            fmpz_poly_zero(g);
            fmpz_poly_set_coeff_ui(g, 0, 1);
            fmpz_poly_set_coeff_ui(g, 1, 100);
            fmpz_poly_pow(g, g,  atol(argv[i+2]));
            fmpz_poly_set_coeff_ui(g, atol(argv[i+1]), 1);
            fmpz_poly_mul(f, f, g);
            i += 2;
        }
        else if (!strcmp(argv[i], "coeffs"))
        {
            fmpz_poly_zero(g);
            i++;
            j = 0;
            while (i < argc)
            {
                if (fmpz_set_str(t, argv[i], 10) != 0)
                {
                    i--;
                    break;
                }

                fmpz_poly_set_coeff_fmpz(g, j, t);
                i++;
                j++;
            }
            fmpz_poly_mul(f, f, g);
        }
    }

    fmpz_poly_factor_init(fac);

    flint_printf("computing squarefree factorization...\n");
    TIMEIT_ONCE_START
    fmpz_poly_factor_squarefree(fac, f);
    TIMEIT_ONCE_STOP

    TIMEIT_ONCE_START
    for (i = 0; i < fac->num; i++)
    {
        flint_printf("roots with multiplicity %wd\n", fac->exp[i]);
        fmpz_poly_complex_roots_squarefree(fac->p + i,
                                           32, compd * 3.32193 + 2, printd);
    }
    TIMEIT_ONCE_STOP

    fmpz_poly_factor_clear(fac);
    fmpz_poly_clear(f);
    fmpz_poly_clear(g);
    fmpz_clear(t);

    flint_cleanup();
    return EXIT_SUCCESS;
}
Exemplo n.º 15
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    /* compare with fmpq_poly */
    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        slong qbits1, qbits2, rbits1, rbits2, rbits3, trunc;
        fmpq_poly_t A, B, C;
        arb_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);

        arb_poly_init(a);
        arb_poly_init(b);
        arb_poly_init(c);
        arb_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_mullow(C, A, B, trunc);

        arb_poly_set_fmpq_poly(a, A, rbits1);
        arb_poly_set_fmpq_poly(b, B, rbits2);
        arb_poly_mullow_classical(c, a, b, trunc, rbits3);

        if (!arb_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 = "); arb_poly_printd(a, 15); flint_printf("\n\n");
            flint_printf("b = "); arb_poly_printd(b, 15); flint_printf("\n\n");
            flint_printf("c = "); arb_poly_printd(c, 15); flint_printf("\n\n");

            abort();
        }

        arb_poly_set(d, a);
        arb_poly_mullow_classical(d, d, b, trunc, rbits3);
        if (!arb_poly_equal(d, c))
        {
            flint_printf("FAIL (aliasing 1)\n\n");
            abort();
        }

        arb_poly_set(d, b);
        arb_poly_mullow_classical(d, a, d, trunc, rbits3);
        if (!arb_poly_equal(d, c))
        {
            flint_printf("FAIL (aliasing 2)\n\n");
            abort();
        }

        /* test squaring */
        arb_poly_set(b, a);
        arb_poly_mullow_classical(c, a, b, trunc, rbits3);
        arb_poly_mullow_classical(d, a, a, trunc, rbits3);
        if (!arb_poly_overlaps(c, d))  /* not guaranteed to be identical */
        {
            flint_printf("FAIL (squaring)\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_printf("c = "); arb_poly_printd(c, 15); flint_printf("\n\n");

            abort();
        }

        arb_poly_mullow_classical(a, a, a, trunc, rbits3);
        if (!arb_poly_equal(d, a))
        {
            flint_printf("FAIL (aliasing, squaring)\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_printf("d = "); arb_poly_printd(d, 15); flint_printf("\n\n");

            abort();
        }

        fmpq_poly_clear(A);
        fmpq_poly_clear(B);
        fmpq_poly_clear(C);

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

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

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

    

    /* Check aliasing of the first argument */
    for (i = 0; i < 10 * flint_test_multiplier(); i++)
    {
        fmpq_poly_t f, g, h;
        slong n;

        fmpq_poly_init(f);
        fmpq_poly_init(g);
        fmpq_poly_init(h);
        fmpq_poly_randtest(g, state, n_randint(state, 40), 80);
        fmpq_poly_randtest(h, state, n_randint(state, 20), 50);
        fmpq_poly_set_coeff_ui(h, 0, 0);
        n = n_randint(state, 20);

        fmpq_poly_compose_series_brent_kung(f, g, h, n);
        fmpq_poly_compose_series_brent_kung(g, g, h, n);

        result = (fmpq_poly_equal(f, g));
        if (!result)
        {
            flint_printf("FAIL (aliasing 1):\n");
            fmpq_poly_print(f), flint_printf("\n\n");
            fmpq_poly_print(g), flint_printf("\n\n");
            abort();
        }

        fmpq_poly_clear(f);
        fmpq_poly_clear(g);
        fmpq_poly_clear(h);
    }

    /* Check aliasing of the second argument */
    for (i = 0; i < 10 * flint_test_multiplier(); i++)
    {
        fmpq_poly_t f, g, h;
        slong n;

        fmpq_poly_init(f);
        fmpq_poly_init(g);
        fmpq_poly_init(h);
        fmpq_poly_randtest(g, state, n_randint(state, 40), 80);
        fmpq_poly_randtest(h, state, n_randint(state, 20), 50);
        fmpq_poly_set_coeff_ui(h, 0, 0);
        n = n_randint(state, 20);

        fmpq_poly_compose_series_brent_kung(f, g, h, n);
        fmpq_poly_compose_series_brent_kung(h, g, h, n);

        result = (fmpq_poly_equal(f, h));
        if (!result)
        {
            flint_printf("FAIL (aliasing 2):\n");
            fmpq_poly_print(f), flint_printf("\n\n");
            fmpq_poly_print(h), flint_printf("\n\n");
            abort();
        }

        fmpq_poly_clear(f);
        fmpq_poly_clear(g);
        fmpq_poly_clear(h);
    }

    /* Compare with compose */
    for (i = 0; i < 20 * flint_test_multiplier(); i++)
    {
        fmpq_poly_t f, g, h, s, t;
        slong n;

        fmpq_poly_init(f);
        fmpq_poly_init(g);
        fmpq_poly_init(h);
        fmpq_poly_init(s);
        fmpq_poly_init(t);
        fmpq_poly_randtest(g, state, n_randint(state, 40), 80);
        fmpq_poly_randtest(h, state, n_randint(state, 20), 50);
        fmpq_poly_set_coeff_ui(h, 0, 0);
        n = n_randint(state, 20);

        fmpq_poly_compose(s, g, h);
        fmpq_poly_truncate(s, n);
        fmpq_poly_compose_series_brent_kung(f, g, h, n);

        result = (fmpq_poly_equal(f, s));
        if (!result)
        {
            flint_printf("FAIL (comparison):\n");
            flint_printf("n = %wd\n", n);
            flint_printf("g = "), fmpq_poly_print(g), flint_printf("\n\n");
            flint_printf("h = "), fmpq_poly_print(h), flint_printf("\n\n");
            flint_printf("f = "), fmpq_poly_print(f), flint_printf("\n\n");
            flint_printf("s = "), fmpq_poly_print(s), flint_printf("\n\n");
            abort();
        }

        fmpq_poly_clear(f);
        fmpq_poly_clear(g);
        fmpq_poly_clear(h);
        fmpq_poly_clear(s);
        fmpq_poly_clear(t);
    }

    FLINT_TEST_CLEANUP(state);
    
    flint_printf("PASS\n");
    return 0;
}
Exemplo n.º 17
0
void fmpq_poly_divrem(fmpq_poly_t Q, fmpq_poly_t R, 
                      const fmpq_poly_t poly1, const fmpq_poly_t poly2)
{
    slong lenA, lenB, lenQ, lenR;

    if (fmpq_poly_is_zero(poly2))
    {
        flint_printf("Exception (fmpq_poly_divrem). Division by zero.\n");
        abort();
    }
    if (Q == R)
    {
        flint_printf("Exception (fmpq_poly_divrem). Output arguments aliased.\n");
        abort();
    }
    
    /* Deal with the various other cases of aliasing. */
    if (R == poly1 || R == poly2)
    {
        if (Q == poly1 || Q == poly2)
        {
            fmpq_poly_t tempQ, tempR;
            fmpq_poly_init(tempQ);
            fmpq_poly_init(tempR);
            fmpq_poly_divrem(tempQ, tempR, poly1, poly2);
            fmpq_poly_swap(Q, tempQ);
            fmpq_poly_swap(R, tempR);
            fmpq_poly_clear(tempQ);
            fmpq_poly_clear(tempR);
            return;
        }
        else
        {
            fmpq_poly_t tempR;
            fmpq_poly_init(tempR);
            fmpq_poly_divrem(Q, tempR, poly1, poly2);
            fmpq_poly_swap(R, tempR);
            fmpq_poly_clear(tempR);
            return;
        }
    }
    else
    {
        if (Q == poly1 || Q == poly2)
        {
            fmpq_poly_t tempQ;
            fmpq_poly_init(tempQ);
            fmpq_poly_divrem(tempQ, R, poly1, poly2);
            fmpq_poly_swap(Q, tempQ);
            fmpq_poly_clear(tempQ);
            return;
        }
    }
    
    if (poly1->length < poly2->length)
    {
        fmpq_poly_set(R, poly1);
        fmpq_poly_zero(Q);
        return;
    }
    
    lenA = poly1->length;
    lenB = poly2->length;
    lenQ = lenA - lenB + 1;
    lenR = lenB - 1;
    
    fmpq_poly_fit_length(Q, lenQ);
    fmpq_poly_fit_length(R, lenA);  /* XXX: Need at least that much space */
    
    _fmpq_poly_divrem(Q->coeffs, Q->den, R->coeffs, R->den, 
                      poly1->coeffs, poly1->den, poly1->length, 
                      poly2->coeffs, poly2->den, poly2->length, NULL);
    
    _fmpq_poly_set_length(Q, lenQ);
    _fmpq_poly_set_length(R, lenR);
    _fmpq_poly_normalise(R);
}
Exemplo n.º 18
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 1000; iter++)
    {
        long m, n1, n2, qbits, rbits1, rbits2, rbits3;
        fmpq_poly_t A;
        fmprb_poly_t a, b, c, d;

        qbits = 2 + n_randint(state, 200);
        rbits1 = 2 + n_randint(state, 400);
        rbits2 = 2 + n_randint(state, 400);
        rbits3 = 2 + n_randint(state, 400);

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

        fmpq_poly_init(A);
        fmprb_poly_init(a);
        fmprb_poly_init(b);
        fmprb_poly_init(c);
        fmprb_poly_init(d);

        fmpq_poly_randtest_not_zero(A, state, m, qbits);
        fmpz_abs(A->coeffs, A->coeffs);
        fmprb_poly_set_fmpq_poly(a, A, rbits1);

        fmprb_poly_lgamma_series(b, a, n1, rbits2);
        fmprb_poly_lgamma_series(c, a, n2, rbits3);

        fmprb_poly_set(d, b);
        fmprb_poly_truncate(d, FLINT_MIN(n1, n2));
        fmprb_poly_truncate(c, FLINT_MIN(n1, n2));

        if (!fmprb_poly_overlaps(c, d))
        {
            printf("FAIL\n\n");
            printf("n1 = %ld, n2 = %ld, bits2 = %ld, bits3 = %ld\n", n1, n2, rbits2, rbits3);

            printf("A = "); fmpq_poly_print(A); 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();
        }

        /* check loggamma(a) + log(a) = loggamma(a+1) */
        fmprb_poly_log_series(c, a, n1, rbits2);
        fmprb_poly_add(c, b, c, rbits2);

        fmprb_poly_set(d, a);
        fmprb_add_ui(d->coeffs, d->coeffs, 1, rbits2);
        fmprb_poly_lgamma_series(d, d, n1, rbits2);

        if (!fmprb_poly_overlaps(c, d))
        {
            printf("FAIL (functional equation)\n\n");

            printf("A = "); fmpq_poly_print(A); 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");
            printf("d = "); fmprb_poly_printd(d, 15); printf("\n\n");

            abort();
        }

        fmprb_poly_lgamma_series(a, a, n1, rbits2);
        if (!fmprb_poly_overlaps(a, b))
        {
            printf("FAIL (aliasing)\n\n");
            abort();
        }

        fmpq_poly_clear(A);
        fmprb_poly_clear(a);
        fmprb_poly_clear(b);
        fmprb_poly_clear(c);
        fmprb_poly_clear(d);
    }

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

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

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        slong m, n, qbits, rbits1, rbits2;
        fmpq_poly_t A;
        arb_poly_t a, b, c, d;

        qbits = 2 + n_randint(state, 200);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);

        m = 1 + n_randint(state, 30);
        n = 1 + n_randint(state, 30);

        fmpq_poly_init(A);
        arb_poly_init(a);
        arb_poly_init(b);
        arb_poly_init(c);
        arb_poly_init(d);

        fmpq_poly_randtest(A, state, m, qbits);
        arb_poly_set_fmpq_poly(a, A, rbits1);

        arb_poly_randtest(b, state, 1 + n_randint(state, 30), rbits1, 5);

        arb_poly_asin_series(b, a, n, rbits2);

        /* Check sin(asin(x)) = x */
        arb_poly_sin_cos_series_basecase(c, d, b, n, rbits2, 0);

        fmpq_poly_truncate(A, n);
        if (!arb_poly_contains_fmpq_poly(c, A))
        {
            flint_printf("FAIL\n\n");
            flint_printf("bits2 = %wd\n", rbits2);

            flint_printf("A = "); fmpq_poly_print(A); 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_printf("c = "); arb_poly_printd(c, 15); flint_printf("\n\n");
            flint_printf("d = "); arb_poly_printd(d, 15); flint_printf("\n\n");

            abort();
        }

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

        fmpq_poly_clear(A);
        arb_poly_clear(a);
        arb_poly_clear(b);
        arb_poly_clear(c);
        arb_poly_clear(d);
    }

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

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

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        slong m, n, qbits, rbits1, rbits2;
        fmpq_poly_t A;
        arb_poly_t a, b, c, d;

        qbits = 2 + n_randint(state, 200);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);

        m = 1 + n_randint(state, 30);
        n = 1 + n_randint(state, 30);

        fmpq_poly_init(A);
        arb_poly_init(a);
        arb_poly_init(b);
        arb_poly_init(c);
        arb_poly_init(d);

        fmpq_poly_randtest(A, state, m, qbits);
        arb_poly_set_fmpq_poly(a, A, rbits1);

        arb_poly_randtest(b, state, 1 + n_randint(state, 30), rbits1, 5);

        arb_poly_atan_series(b, a, n, rbits2);

        /* Check 2 atan(x) = atan(2x/(1-x^2)) + C */
        arb_poly_mullow(c, a, a, n, rbits2);
        arb_poly_one(d);
        arb_poly_sub(c, d, c, rbits2);
        arb_poly_add(d, a, a, rbits2);

        if (arb_poly_length(c) != 0)
        {
            arb_poly_div_series(c, d, c, n, rbits2);
            arb_poly_atan_series(c, c, n, rbits2);
            arb_poly_add(d, b, b, rbits2);

            /* TODO: also check the first coefficient */
            arb_poly_set_coeff_si(c, 0, 0);
            arb_poly_set_coeff_si(d, 0, 0);

            if (!arb_poly_overlaps(c, d))
            {
                flint_printf("FAIL\n\n");
                flint_printf("bits2 = %wd\n", rbits2);

                flint_printf("A = "); fmpq_poly_print(A); 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_printf("c = "); arb_poly_printd(c, 15); flint_printf("\n\n");
                flint_printf("d = "); arb_poly_printd(d, 15); flint_printf("\n\n");

                abort();
            }
        }

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

        fmpq_poly_clear(A);
        arb_poly_clear(a);
        arb_poly_clear(b);
        arb_poly_clear(c);
        arb_poly_clear(d);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 21
0
Arquivo: t-rem.c Projeto: goens/flint2
int
main(void)
{
    int i, result;
    flint_rand_t state;
    ulong cflags = 0UL;

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

    flint_randinit(state);

    /* Check aliasing of r and a */
    for (i = 0; i < 2000; i++)
    {
        fmpq_poly_t a, b, r;

        fmpq_poly_init(a);
        fmpq_poly_init(b);
        fmpq_poly_init(r);
        fmpq_poly_randtest(a, state, n_randint(state, 50), 200);
        fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 200);

        fmpq_poly_rem(r, a, b);
        fmpq_poly_rem(a, a, b);

        cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(r) ? 0 : 2;
        result = (fmpq_poly_equal(r, a) && !cflags);
        if (!result)
        {
            printf("FAIL:\n");
            printf("r = "), fmpq_poly_debug(r), printf("\n\n");
            printf("a = "), fmpq_poly_debug(a), printf("\n\n");
            printf("b = "), fmpq_poly_debug(b), printf("\n\n");
            printf("cflags = %lu\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(a);
        fmpq_poly_clear(b);
        fmpq_poly_clear(r);
    }

    /* Check aliasing of r and b */
    for (i = 0; i < 2000; i++)
    {
        fmpq_poly_t a, b, r;

        fmpq_poly_init(a);
        fmpq_poly_init(b);
        fmpq_poly_init(r);
        fmpq_poly_randtest(a, state, n_randint(state, 50), 200);
        fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 200);

        fmpq_poly_rem(r, a, b);
        fmpq_poly_rem(b, a, b);

        cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(r) ? 0 : 2;
        result = (fmpq_poly_equal(r, b) && !cflags);
        if (!result)
        {
            printf("FAIL:\n");
            printf("r = "), fmpq_poly_debug(r), printf("\n\n");
            printf("a = "), fmpq_poly_debug(a), printf("\n\n");
            printf("b = "), fmpq_poly_debug(b), printf("\n\n");
            printf("cflags = %lu\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(a);
        fmpq_poly_clear(b);
        fmpq_poly_clear(r);
    }

    /* Compare with divrem */
    for (i = 0; i < 2000; i++)
    {
        fmpq_poly_t a, b, q, r, r2;

        fmpq_poly_init(a);
        fmpq_poly_init(b);
        fmpq_poly_init(q);
        fmpq_poly_init(r);
        fmpq_poly_init(r2);
        fmpq_poly_randtest(a, state, n_randint(state, 50), 200);
        fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 200);

        fmpq_poly_divrem(q, r, a, b);
        fmpq_poly_rem(r2, a, b);

        cflags |= fmpq_poly_is_canonical(q)  ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(r2) ? 0 : 2;
        result = (fmpq_poly_equal(r, r2) && !cflags);
        if (!result)
        {
            printf("FAIL:\n");
            printf("a  = "), fmpq_poly_debug(a), printf("\n\n");
            printf("b  = "), fmpq_poly_debug(b), printf("\n\n");
            printf("q  = "), fmpq_poly_debug(q), printf("\n\n");
            printf("r  = "), fmpq_poly_debug(r), printf("\n\n");
            printf("r2 = "), fmpq_poly_debug(r2), printf("\n\n");
            printf("cflags = %lu\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(a);
        fmpq_poly_clear(b);
        fmpq_poly_clear(q);
        fmpq_poly_clear(r);
        fmpq_poly_clear(r2);
    }

    flint_randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return 0;
}
Exemplo n.º 22
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

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

        fmpq_poly_init(P);
        acb_poly_init(R);
        acb_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 = _acb_vec_init(n);
        ys = _acb_vec_init(n);

        acb_poly_set_fmpq_poly(R, P, rbits1);

        if (n > 0)
        {
            fmpq_randtest(t, state, qbits2);
            acb_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);
                acb_set_fmpq(xs + i, t, rbits2);
            }
        }

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

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

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

        fmpq_poly_clear(P);
        acb_poly_clear(R);
        acb_poly_clear(S);
        fmpq_clear(t);
        fmpq_clear(u);
        _acb_vec_clear(xs, n);
        _acb_vec_clear(ys, n);
    }

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

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

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        long m, n, p, qbits, rbits1, rbits2;
        fmpq_poly_t A, B, C;
        arb_poly_t a, b, c, d;

        qbits = 2 + n_randint(state, 200);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);

        m = 1 + n_randint(state, 20);
        n = 1 + n_randint(state, 20);
        p = 1 + n_randint(state, 20);

        fmpq_poly_init(A);
        fmpq_poly_init(B);
        fmpq_poly_init(C);

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

        fmpq_poly_randtest(A, state, m, qbits);

        do {
            fmpq_poly_randtest_not_zero(B, state, n, qbits);
        } while (B->coeffs[0] == 0);

        fmpq_poly_div_series(C, A, B, p);
        arb_poly_set_fmpq_poly(a, A, rbits1);
        arb_poly_set_fmpq_poly(b, B, rbits1);
        arb_poly_div_series(c, a, b, p, rbits2);

        if (!arb_poly_contains_fmpq_poly(c, C))
        {
            printf("FAIL\n\n");
            printf("bits2 = %ld\n", rbits2);

            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 = "); arb_poly_printd(a, 15); printf("\n\n");
            printf("b = "); arb_poly_printd(b, 15); printf("\n\n");
            printf("c = "); arb_poly_printd(c, 15); printf("\n\n");

            abort();
        }

        arb_poly_set(d, a);
        arb_poly_div_series(d, d, b, p, rbits2);
        if (!arb_poly_equal(d, c))
        {
            printf("FAIL (aliasing 1)\n\n");
            abort();
        }

        arb_poly_set(d, b);
        arb_poly_div_series(d, a, d, p, rbits2);
        if (!arb_poly_equal(d, c))
        {
            printf("FAIL (aliasing 2)\n\n");
            abort();
        }

        arb_poly_set(d, b);
        arb_poly_div_series(c, d, d, p, rbits2);
        arb_poly_div_series(d, d, d, p, rbits2);
        if (!arb_poly_equal(d, c))
        {
            printf("FAIL (aliasing 3)\n\n");
            abort();
        }

        fmpq_poly_clear(A);
        fmpq_poly_clear(B);
        fmpq_poly_clear(C);

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

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

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

    flint_randinit(state);

    /* Check aliasing */
    for (i = 0; i < 1000; i++)
    {
        fmpz_t a, b;
        fmpq_t x, y;
        fmpq_poly_t f;

        fmpz_init(a);
        fmpz_init(b);
        fmpq_init(x);
        fmpq_init(y);
        fmpq_poly_init(f);
        fmpq_poly_randtest(f, state, n_randint(state, 80), 100);
        fmpz_randtest(a, state, 80);
        fmpz_randtest_not_zero(b, state, 80);
        fmpz_set(fmpq_numref(x), a);
        fmpz_set(fmpq_denref(x), a);
        fmpq_canonicalise(x);

        fmpq_poly_evaluate_fmpq(y, f, x);
        fmpq_poly_evaluate_fmpq(x, f, x);

        result = (fmpq_equal(x, y));
        if (!result)
        {
            printf("FAIL:\n");
            fmpz_print(a), printf("\n\n");
            fmpz_print(b), printf("\n\n");
            fmpq_poly_debug(f), printf("\n\n");
            abort();
        }

        fmpz_clear(a);
        fmpz_clear(b);
        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_poly_clear(f);
    }

    /* Check that (f+g)(a) = f(a) + g(a) */
    for (i = 0; i < 1000; i++)
    {
        fmpz_t a, b;
        fmpq_t x, y, z;
        fmpq_poly_t f, g;

        fmpz_init(a);
        fmpz_init(b);
        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);
        fmpq_poly_init(f);
        fmpq_poly_init(g);
        fmpq_poly_randtest(f, state, n_randint(state, 80), 100);
        fmpq_poly_randtest(g, state, n_randint(state, 80), 100);
        fmpz_randtest(a, state, 80);
        fmpz_randtest_not_zero(b, state, 80);
        fmpz_set(fmpq_numref(x), a);
        fmpz_set(fmpq_denref(x), a);
        fmpq_canonicalise(x);

        fmpq_poly_evaluate_fmpq(y, f, x);
        fmpq_poly_evaluate_fmpq(z, g, x);
        fmpq_add(y, y, z);
        fmpq_poly_add(f, f, g);
        fmpq_poly_evaluate_fmpq(z, f, x);

        result = (fmpq_equal(y, z));
        if (!result)
        {
            printf("FAIL:\n");
            fmpz_print(a), printf("\n\n");
            fmpz_print(b), printf("\n\n");
            abort();
        }

        fmpz_clear(a);
        fmpz_clear(b);
        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);
        fmpq_poly_clear(f);
        fmpq_poly_clear(g);
    }

    /* Check that (f*g)(a) = f(a) * g(a) */
    for (i = 0; i < 1000; i++)
    {
        fmpz_t a, b;
        fmpq_t x, y, z;
        fmpq_poly_t f, g;

        fmpz_init(a);
        fmpz_init(b);
        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);
        fmpq_poly_init(f);
        fmpq_poly_init(g);
        fmpq_poly_randtest(f, state, n_randint(state, 50), 80);
        fmpq_poly_randtest(g, state, n_randint(state, 50), 80);
        fmpz_randtest(a, state, 80);
        fmpz_randtest_not_zero(b, state, 80);
        fmpz_set(fmpq_numref(x), a);
        fmpz_set(fmpq_denref(x), a);
        fmpq_canonicalise(x);

        fmpq_poly_evaluate_fmpq(y, f, x);
        fmpq_poly_evaluate_fmpq(z, g, x);
        fmpq_mul(y, y, z);
        fmpq_poly_mul(f, f, g);
        fmpq_poly_evaluate_fmpq(z, f, x);

        result = (fmpq_equal(y, z));
        if (!result)
        {
            printf("FAIL:\n");
            fmpz_print(a), printf("\n\n");
            fmpz_print(b), printf("\n\n");
            abort();
        }

        fmpz_clear(a);
        fmpz_clear(b);
        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);
        fmpq_poly_clear(f);
        fmpq_poly_clear(g);
    }

    flint_randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return 0;
}
Exemplo n.º 25
0
int
main(void)
{
    int i, result;
    ulong cflags = UWORD(0);

    FLINT_TEST_INIT(state);

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

    /* Check aliasing of the first argument */
    for (i = 0; i < 10 * flint_test_multiplier(); i++)
    {
        fmpq_poly_t f, g, h;

        fmpq_poly_init(f);
        fmpq_poly_init(g);
        fmpq_poly_init(h);
        fmpq_poly_randtest(g, state, n_randint(state, 50), 100);
        fmpq_poly_randtest(h, state, n_randint(state, 20), 50);

        fmpq_poly_compose(f, g, h);
        fmpq_poly_compose(g, g, h);

        cflags |= fmpq_poly_is_canonical(f) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(g) ? 0 : 2;
        result = (fmpq_poly_equal(f, g) && !cflags);
        if (!result)
        {
            flint_printf("FAIL (aliasing 1):\n");
            fmpq_poly_debug(f), flint_printf("\n\n");
            fmpq_poly_debug(g), flint_printf("\n\n");
            flint_printf("cflags = %wu\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(f);
        fmpq_poly_clear(g);
        fmpq_poly_clear(h);
    }

    /* Check aliasing of the second argument */
    for (i = 0; i < 10 * flint_test_multiplier(); i++)
    {
        fmpq_poly_t f, g, h;

        fmpq_poly_init(f);
        fmpq_poly_init(g);
        fmpq_poly_init(h);
        fmpq_poly_randtest(g, state, n_randint(state, 50), 100);
        fmpq_poly_randtest(h, state, n_randint(state, 20), 50);

        fmpq_poly_compose(f, g, h);
        fmpq_poly_compose(h, g, h);

        cflags |= fmpq_poly_is_canonical(f) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(h) ? 0 : 2;
        result = (fmpq_poly_equal(f, h) && !cflags);
        if (!result)
        {
            flint_printf("FAIL (aliasing 2):\n");
            fmpq_poly_debug(f), flint_printf("\n\n");
            fmpq_poly_debug(h), flint_printf("\n\n");
            flint_printf("cflags = %wu\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(f);
        fmpq_poly_clear(g);
        fmpq_poly_clear(h);
    }

    /* Compare with the naive method for g(h(t)) */
    for (i = 0; i < 10 * flint_test_multiplier(); i++)
    {
        fmpq_poly_t f, g, h, s, t, u;
        mpq_t c;
        slong k;

        fmpq_poly_init(f);
        fmpq_poly_init(g);
        fmpq_poly_init(h);
        fmpq_poly_init(s);
        fmpq_poly_init(t);
        fmpq_poly_init(u);
        mpq_init(c);
        fmpq_poly_randtest(g, state, n_randint(state, 20), 65);
        fmpq_poly_randtest(h, state, n_randint(state, 20), 65);
        
        fmpq_poly_zero(s);
        fmpq_poly_set_ui(t, UWORD(1));
        for (k = WORD(0); k < g->length; k++)
        {
            fmpq_poly_get_coeff_mpq(c, g, k);
            fmpq_poly_scalar_mul_mpq(u, t, c);
            fmpq_poly_add(s, s, u);
            fmpq_poly_mul(t, t, h);
        }
        
        fmpq_poly_compose(f, g, h);

        result = (fmpq_poly_equal(f, s));
        if (!result)
        {
            flint_printf("FAIL (compare with naive):\n");
            flint_printf("g = "), fmpq_poly_debug(g), flint_printf("\n\n");
            flint_printf("h = "), fmpq_poly_debug(h), flint_printf("\n\n");
            flint_printf("f = "), fmpq_poly_debug(f), flint_printf("\n\n");
            flint_printf("s = "), fmpq_poly_debug(s), flint_printf("\n\n");
            abort();
        }

        fmpq_poly_clear(f);
        fmpq_poly_clear(g);
        fmpq_poly_clear(h);
        fmpq_poly_clear(s);
        fmpq_poly_clear(t);
        fmpq_poly_clear(u);
        mpq_clear(c);
    }

    FLINT_TEST_CLEANUP(state);
    
    flint_printf("PASS\n");
    return 0;
}
Exemplo n.º 26
0
int
main(void)
{
    int cflags = 0, i, result;
    flint_rand_t state;
    
    printf("xgcd....");
    fflush(stdout);

    flint_randinit(state);

    /* Generic case, where a and b are coprime *******************************/

    /* Verify d == s a + t b */
    for (i = 0; i < 100; i++)
    {
        fmpq_poly_t a, b, d, e, f, s, t;

        fmpq_poly_init(a);
        fmpq_poly_init(b);
        fmpq_poly_init(d);
        fmpq_poly_init(e);
        fmpq_poly_init(f);
        fmpq_poly_init(s);
        fmpq_poly_init(t);
        fmpq_poly_randtest(a, state, n_randint(state, 60), 80);
        fmpq_poly_randtest(b, state, n_randint(state, 60), 80);

        fmpq_poly_xgcd(d, s, t, a, b);
        fmpq_poly_mul(e, s, a);
        fmpq_poly_mul(f, t, b);
        fmpq_poly_add(e, e, f);

        cflags |= fmpq_poly_is_canonical(d) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(s) ? 0 : 2;
        cflags |= fmpq_poly_is_canonical(t) ? 0 : 4;
        result = (fmpq_poly_equal(d, e) && !cflags);
        if (!result)
        {
            printf("FAIL (correctness #1):\n");
            fmpq_poly_debug(a), printf("\n\n");
            fmpq_poly_debug(b), printf("\n\n");
            fmpq_poly_debug(d), printf("\n\n");
            fmpq_poly_debug(s), printf("\n\n");
            fmpq_poly_debug(t), printf("\n\n");
            printf("cflags = %d\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(a);
        fmpq_poly_clear(b);
        fmpq_poly_clear(d);
        fmpq_poly_clear(e);
        fmpq_poly_clear(f);
        fmpq_poly_clear(s);
        fmpq_poly_clear(t);
    }

    /* Verify consistency with GCD */
    for (i = 0; i < 100; i++)
    {
        fmpq_poly_t a, b, d, s, t;

        fmpq_poly_init(a);
        fmpq_poly_init(b);
        fmpq_poly_init(d);
        fmpq_poly_init(s);
        fmpq_poly_init(t);
        fmpq_poly_randtest(a, state, n_randint(state, 60), 80);
        fmpq_poly_randtest(b, state, n_randint(state, 60), 80);

        fmpq_poly_xgcd(d, s, t, a, b);
        fmpq_poly_gcd(a, a, b);

        cflags |= fmpq_poly_is_canonical(d) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(s) ? 0 : 2;
        cflags |= fmpq_poly_is_canonical(t) ? 0 : 4;
        result = (fmpq_poly_equal(d, a) && !cflags);
        if (!result)
        {
            printf("FAIL (GCD #1):\n");
            fmpq_poly_debug(a), printf("\n\n");
            fmpq_poly_debug(b), printf("\n\n");
            fmpq_poly_debug(d), printf("\n\n");
            fmpq_poly_debug(s), printf("\n\n");
            fmpq_poly_debug(t), printf("\n\n");
            printf("cflags = %d\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(a);
        fmpq_poly_clear(b);
        fmpq_poly_clear(d);
        fmpq_poly_clear(s);
        fmpq_poly_clear(t);
    }

    /* Generic case when a, b are most likely co-prime ***********************/

    /* Verify d == s a + t b */
    for (i = 0; i < 100; i++)
    {
        fmpq_poly_t a, b, d, s, t, z;

        fmpq_poly_init(a);
        fmpq_poly_init(b);
        fmpq_poly_init(d);
        fmpq_poly_init(s);
        fmpq_poly_init(t);
        fmpq_poly_init(z);
        fmpq_poly_randtest(a, state, n_randint(state, 60), 80);
        fmpq_poly_randtest(b, state, n_randint(state, 60), 80);
        fmpq_poly_randtest(z, state, n_randint(state, 20), 20);
        fmpq_poly_mul(a, a, z);
        fmpq_poly_mul(b, b, z);

        fmpq_poly_xgcd(d, s, t, a, b);
        fmpq_poly_mul(a, s, a);
        fmpq_poly_mul(b, t, b);
        fmpq_poly_add(a, a, b);

        cflags |= fmpq_poly_is_canonical(d) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(s) ? 0 : 2;
        cflags |= fmpq_poly_is_canonical(t) ? 0 : 4;
        result = (fmpq_poly_equal(d, a) && !cflags);
        if (!result)
        {
            printf("FAIL (correctness #2):\n");
            fmpq_poly_debug(a), printf("\n\n");
            fmpq_poly_debug(b), printf("\n\n");
            fmpq_poly_debug(d), printf("\n\n");
            fmpq_poly_debug(s), printf("\n\n");
            fmpq_poly_debug(t), printf("\n\n");
            printf("cflags = %d\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(a);
        fmpq_poly_clear(b);
        fmpq_poly_clear(d);
        fmpq_poly_clear(s);
        fmpq_poly_clear(t);
        fmpq_poly_clear(z);
    }

    /* Verify consistency with GCD */
    for (i = 0; i < 100; i++)
    {
        fmpq_poly_t a, b, d, s, t, z;

        fmpq_poly_init(a);
        fmpq_poly_init(b);
        fmpq_poly_init(d);
        fmpq_poly_init(s);
        fmpq_poly_init(t);
        fmpq_poly_init(z);
        fmpq_poly_randtest(a, state, n_randint(state, 60), 80);
        fmpq_poly_randtest(b, state, n_randint(state, 60), 80);
        fmpq_poly_randtest(z, state, n_randint(state, 20), 20);
        fmpq_poly_mul(a, a, z);
        fmpq_poly_mul(b, b, z);

        fmpq_poly_xgcd(d, s, t, a, b);
        fmpq_poly_gcd(a, a, b);

        cflags |= fmpq_poly_is_canonical(d) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(s) ? 0 : 2;
        cflags |= fmpq_poly_is_canonical(t) ? 0 : 4;
        result = (fmpq_poly_equal(d, a) && !cflags);
        if (!result)
        {
            printf("FAIL (GCD #2):\n");
            fmpq_poly_debug(a), printf("\n\n");
            fmpq_poly_debug(b), printf("\n\n");
            fmpq_poly_debug(d), printf("\n\n");
            fmpq_poly_debug(s), printf("\n\n");
            fmpq_poly_debug(t), printf("\n\n");
            printf("cflags = %d\n\n", cflags);
            abort();
        }

        fmpq_poly_clear(a);
        fmpq_poly_clear(b);
        fmpq_poly_clear(d);
        fmpq_poly_clear(s);
        fmpq_poly_clear(t);
        fmpq_poly_clear(z);
    }

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

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

    flint_randinit(state);

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

        qbits = 2 + n_randint(state, 200);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);

        m = 1 + n_randint(state, 30);
        n = 1 + n_randint(state, 30);

        fmpq_poly_init(A);
        fmpq_poly_init(B);
        arb_poly_init(a);
        arb_poly_init(b);
        arb_poly_init(c);
        arb_poly_init(d);
        arb_poly_init(e);

        fmpq_poly_randtest(A, state, m, qbits);
        arb_poly_set_fmpq_poly(a, A, rbits1);

        arb_poly_sin_cos_pi_series(b, c, a, n, rbits2);

        /* Check sin(x)^2 + cos(x)^2 = 1 */
        arb_poly_mullow(d, b, b, n, rbits2);
        arb_poly_mullow(e, c, c, n, rbits2);
        arb_poly_add(d, d, e, rbits2);

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

            flint_printf("A = "); fmpq_poly_print(A); 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_printf("c = "); arb_poly_printd(c, 15); flint_printf("\n\n");
            flint_printf("d = "); arb_poly_printd(d, 15); flint_printf("\n\n");

            abort();
        }

        arb_poly_set(d, a);
        arb_poly_sin_cos_pi_series(d, c, d, n, rbits2);
        if (!arb_poly_equal(b, d))
        {
            flint_printf("FAIL (aliasing 1)\n\n");
            abort();
        }

        arb_poly_set(d, a);
        arb_poly_sin_cos_pi_series(b, d, d, n, rbits2);
        if (!arb_poly_equal(c, d))
        {
            flint_printf("FAIL (aliasing 2)\n\n");
            abort();
        }

        fmpq_poly_clear(A);
        fmpq_poly_clear(B);
        arb_poly_clear(a);
        arb_poly_clear(b);
        arb_poly_clear(c);
        arb_poly_clear(d);
        arb_poly_clear(e);
    }

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

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

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        long m, n, qbits, rbits1, rbits2;
        fmpq_poly_t A, B;
        fmprb_poly_t a, b;

        qbits = 2 + n_randint(state, 200);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);

        m = 1 + n_randint(state, 20);
        n = 1 + n_randint(state, 20);

        fmpq_poly_init(A);
        fmpq_poly_init(B);

        fmprb_poly_init(a);
        fmprb_poly_init(b);

        do {
            fmpq_poly_randtest_not_zero(A, state, m, qbits);
        } while (A->coeffs[0] == 0);

        fmprb_poly_randtest(b, state, 1 + n_randint(state, 20), rbits1, 5);

        fmpq_poly_inv_series(B, A, n);
        fmprb_poly_set_fmpq_poly(a, A, rbits1);
        fmprb_poly_inv_series(b, a, n, rbits2);

        if (!fmprb_poly_contains_fmpq_poly(b, B))
        {
            printf("FAIL\n\n");
            printf("bits2 = %ld\n", rbits2);

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

            printf("a = "); fmprb_poly_printd(a, 15); printf("\n\n");
            printf("b = "); fmprb_poly_printd(b, 15); printf("\n\n");

            abort();
        }

        fmprb_poly_inv_series(a, a, n, rbits2);
        if (!fmprb_poly_equal(a, b))
        {
            printf("FAIL (aliasing)\n\n");
            abort();
        }

        fmpq_poly_clear(A);
        fmpq_poly_clear(B);

        fmprb_poly_clear(a);
        fmprb_poly_clear(b);
    }

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

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

    flint_randinit(state);

    for (iter = 0; iter < 3000; iter++)
    {
        long qbits1, qbits2, rbits1, rbits2, rbits3;
        fmpq_poly_t A, B, C;
        arb_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);

        fmpq_poly_init(A);
        fmpq_poly_init(B);
        fmpq_poly_init(C);

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

        fmpq_poly_randtest(A, state, 1 + n_randint(state, 20), qbits1);
        fmpq_poly_randtest(B, state, 1 + n_randint(state, 10), qbits2);
        fmpq_poly_compose(C, A, B);

        arb_poly_set_fmpq_poly(a, A, rbits1);
        arb_poly_set_fmpq_poly(b, B, rbits2);
        arb_poly_compose_horner(c, a, b, rbits3);

        if (!arb_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 = "); arb_poly_printd(a, 15); printf("\n\n");
            printf("b = "); arb_poly_printd(b, 15); printf("\n\n");
            printf("c = "); arb_poly_printd(c, 15); printf("\n\n");

            abort();
        }

        arb_poly_set(d, a);
        arb_poly_compose_horner(d, d, b, rbits3);
        if (!arb_poly_equal(d, c))
        {
            printf("FAIL (aliasing 1)\n\n");
            abort();
        }

        arb_poly_set(d, b);
        arb_poly_compose_horner(d, a, d, rbits3);
        if (!arb_poly_equal(d, c))
        {
            printf("FAIL (aliasing 2)\n\n");
            abort();
        }

        fmpq_poly_clear(A);
        fmpq_poly_clear(B);
        fmpq_poly_clear(C);

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

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 30
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;
        acb_poly_t f;
        acb_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);

        acb_poly_init(f);
        x = _acb_vec_init(n);
        y = _acb_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);

        acb_poly_set_fmpq_poly(f, F, rbits1);
        for (i = 0; i < n; i++)
            acb_set_fmpq(x + i, X + i, rbits2);
        acb_poly_evaluate_vec_fast(y, f, x, n, rbits3);

        for (i = 0; i < n; i++)
        {
            if (!acb_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 = ");
                acb_poly_printd(f, 15);
                flint_printf("\n\n");
                flint_printf("x = ");
                acb_printd(x + i, 15);
                flint_printf("\n\n");
                flint_printf("y = ");
                acb_printd(y + i, 15);
                flint_printf("\n\n");

                abort();
            }
        }

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

        acb_poly_clear(f);
        _acb_vec_clear(x, n);
        _acb_vec_clear(y, n);
    }

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