Пример #1
0
int
main(void)
{
    int i;
    FLINT_TEST_INIT(state);
    

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

    for (i = 0; i < 10000; i++)
    {
        fmpq_t x, r;
        fmpz * c;
        slong n, bound;

        fmpq_init(x);
        fmpq_init(r);

        /* Test worst case (quotient of Fibonacci numbers) */
        if (n_randint(state, 50) == 1)
        {
            slong v = 1 + n_randint(state, 1000);
            fmpz_fib_ui(fmpq_numref(x), v + 1);
            fmpz_fib_ui(fmpq_denref(x), v);
        }
        else
        {
            fmpq_randtest(x, state, 1 + n_randint(state, 1000));
        }

        bound = fmpq_cfrac_bound(x);
        c = _fmpz_vec_init(bound + 10);
        n = fmpq_get_cfrac(c, r, x, bound);

        if (n > bound)
        {
            flint_printf("FAIL: length=%wd > bound=%wd\n", n, bound);
            abort();
        }

        _fmpz_vec_clear(c, bound + 10);
        fmpq_clear(x);
        fmpq_clear(r);
    }

    

    FLINT_TEST_CLEANUP(state);
    flint_printf("PASS\n");
    return 0;
}
Пример #2
0
int
main(void)
{
    long i, n;
    fmpz_t x, y, z, w;

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

    fmpz_init(x);
    fmpz_init(y);
    fmpz_init(z);
    fmpz_init(w);

    /* Twice to check demotion */
    for (n = 0; n < 2; n++)
    {
        for (i = 0; i < 200; i++)
        {
            fmpz_fib_ui(x, i);
            fmpz_fib_ui(y, i+1);
            fmpz_fib_ui(z, i+2);
            fmpz_add(w, x, y);

            if (!fmpz_equal(w, z))
            {
                printf("FAIL: %ld\n", i);
                fmpz_print(x);
                printf("\n");
                fmpz_print(y);
                printf("\n");
                fmpz_print(z);
                printf("\n");
                abort();
            }
        }
    }

    fmpz_clear(x);
    fmpz_clear(y);
    fmpz_clear(z);
    fmpz_clear(w);

    _fmpz_cleanup();
    printf("PASS\n");
    return 0;
}
Пример #3
0
void test_field1(flint_rand_t state)
{
    /* tests in QQ[sqrt(5)] */
    int iter;

    fmpq_t k;
    fmpq_poly_t p;
    arb_t emb;
    renf_t nf;
    renf_elem_t a;

    fmpq_poly_init(p);
    fmpq_poly_set_coeff_si(p, 2, 1);
    fmpq_poly_set_coeff_si(p, 1, -1);
    fmpq_poly_set_coeff_si(p, 0, -1);

    arb_init(emb);
    arb_set_d(emb, 1.61803398874989);
    arb_add_error_2exp_si(emb, -20);
    renf_init(nf, p, emb, 20 + n_randint(state, 20));
    arb_clear(emb);

    renf_elem_init(a, nf);
    fmpq_init(k);

    /* (1+sqrt(5))/2 vs Fibonacci */
    fmpq_poly_zero(p);
    fmpq_poly_set_coeff_si(p, 1, -1);
    for (iter = 1; iter < 50; iter++)
    {
        fprintf(stderr, "start iter = %d\n", iter);
        fflush(stderr);
        fmpz_fib_ui(fmpq_numref(k), iter+1);
        fmpz_fib_ui(fmpq_denref(k), iter);
        fmpq_poly_set_coeff_fmpq(p, 0, k);
        renf_elem_set_fmpq_poly(a, p, nf);
        check_ceil(a, nf, 1 - iter % 2, "sqrt(5)");
        fprintf(stderr, "end\n");
        fflush(stderr);
    }

    renf_elem_clear(a, nf);
    renf_clear(nf);
    fmpq_clear(k);
    fmpq_poly_clear(p);
}