Example #1
0
void
_fmpz_holonomic_bsplit_hypgeom_fmpz(fmpz_t P, fmpz_t Q,
    const fmpz_poly_t R0, const fmpz_poly_t R1, long start, long a, long b)
{
    if (b - a == 1)
    {
        fmpz c = start + a;
        fmpz_poly_evaluate_fmpz(P, R0, &c);
        fmpz_poly_evaluate_fmpz(Q, R1, &c);
        fmpz_neg(P, P);
    }
    else
    {
        fmpz_t P2, Q2;
        long m = a + (b - a) / 2;

        fmpz_init(P2);
        fmpz_init(Q2);

        _fmpz_holonomic_bsplit_hypgeom_fmpz(P, Q, R0, R1, start, a, m);
        _fmpz_holonomic_bsplit_hypgeom_fmpz(P2, Q2, R0, R1, start, m, b);
        fmpz_mul(P, P, P2);
        fmpz_mul(Q, Q, Q2);

        fmpz_clear(P2);
        fmpz_clear(Q2);
    }
}
Example #2
0
void
_fmpz_holonomic_eval_companion_matrix_fmpz(fmpz_mat_t M, fmpz_t Q,
    const fmpz_holonomic_t op, long n)
{
    fmpz_t c;
    long r = fmpz_holonomic_order(op);
    long i, j;

    fmpz_init(c);
    fmpz_set_si(c, n);

    fmpz_poly_evaluate_fmpz(Q, op->coeffs + r, c);

    for (i = 0; i < r - 1; i++)
    {
        for (j = 0; j < r; j++)
        {
            if (i + 1 == j)
                fmpz_set(M->rows[i] + j, Q);
            else
                fmpz_zero(M->rows[i] + j);
        }
    }

    for (j = 0; j < r; j++)
    {
        fmpz_poly_evaluate_fmpz(M->rows[r - 1] + j, op->coeffs + j, c);
        fmpz_neg(M->rows[r - 1] + j, M->rows[r - 1] + j);
    }

    fmpz_clear(c);
}
Example #3
0
void
fmpz_poly_mat_evaluate_fmpz(fmpz_mat_t B, const fmpz_poly_mat_t A, const fmpz_t x)
{
    long i, j;

    for (i = 0; i < A->r; i++)
        for (j = 0; j < A->c; j++)
            fmpz_poly_evaluate_fmpz(fmpz_mat_entry(B, i, j),
                fmpz_poly_mat_entry(A, i, j), x);
}
int
main(void)
{
    int iter;
    FLINT_TEST_INIT(state);

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

    /* Check aliasing */
    for (iter = 0; iter < 1000 * flint_test_multiplier(); iter++)
    {
        fmpz_t a;
        fmpz_poly_t f, g;
        long i, d;
        int s1, s2;

        fmpz_init(a);
        fmpz_poly_init(f);
        fmpz_poly_init(g);

        fmpz_poly_randtest(f, state, n_randint(state, 100), 200);

        s1 = fmpz_poly_sgn_eval_at_half(f);

        fmpz_poly_set(g, f);
        d = fmpz_poly_degree(g);
        for (i = 0; i <= d; i++)
        {
            fmpz_mul_2exp(fmpz_poly_get_coeff_ptr(g, i),
                          fmpz_poly_get_coeff_ptr(g, i), d - i);
        }

        fmpz_one(a);
        fmpz_poly_evaluate_fmpz(a, g, a);

        s2 = fmpz_sgn(a);

        if (s1 != s2)
        {
            flint_printf("FAIL:\n");
            fmpz_poly_print(f); printf("\n\n");
            printf("s1 = %d, s2 = %d\n\n", s1, s2);
            abort();
        }

        fmpz_clear(a);
        fmpz_poly_clear(f);
        fmpz_poly_clear(g);
    }

    FLINT_TEST_CLEANUP(state);
    flint_printf("PASS\n");
    return 0;
}
Example #5
0
int
main(void)
{
    int i, result;
    flint_rand_t state;

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

    flint_randinit(state);

    /* Compare with evaluation over the integers */
    for (i = 0; i < 10000; i++)
    {
        fmpz_t b, s;
        fmpz_poly_t f;
        mp_limb_t a, n, r;

        fmpz_poly_init(f);
        fmpz_poly_randtest(f, state, n_randint(state, 10), 20);

        n = n_randtest_not_zero(state);
        a = n_randint(state, n);

        fmpz_init(b);
        fmpz_init(s);
        fmpz_set_ui(b, a);

        r = fmpz_poly_evaluate_mod(f, a, n);
        fmpz_poly_evaluate_fmpz(s, f, b);

        result = (r == fmpz_mod_ui(s, s, n));
        if (!result)
        {
            printf("FAIL:\n");
            fmpz_poly_print(f), printf("\n\n");
            gmp_printf("a = %Mu\n\n", a);
            gmp_printf("n = %Mu\n\n", n);
            gmp_printf("r = %Mu\n\n", r);
            printf("s = "), fmpz_print(s), printf("\n\n");
            abort();
        }

        fmpz_poly_clear(f);
        fmpz_clear(b);
        fmpz_clear(s);
    }

    flint_randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Example #6
0
File: sum.c Project: bluescarni/arb
static __inline__ void
fmpz_poly_evaluate_si(fmpz_t y, const fmpz_poly_t poly, long x)
{
    fmpz_set_si(y, x);
    fmpz_poly_evaluate_fmpz(y, poly, y);
}
Example #7
0
int
main(void)
{
    int i, result;
    flint_rand_t state;

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

    flint_randinit(state);

    /* Check aliasing */
    for (i = 0; i < 10000; i++)
    {
        fmpz_t a, b, p;
        fmpz_mod_poly_t f;

        fmpz_init(p);
        fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
        fmpz_add_ui(p, p, 2);

        fmpz_init(a);
        fmpz_init(b);
        fmpz_randm(a, state, p);
        fmpz_mod_poly_init(f, p);
        fmpz_mod_poly_randtest(f, state, n_randint(state, 100));

        fmpz_mod_poly_evaluate_fmpz(b, f, a);
        fmpz_mod_poly_evaluate_fmpz(a, f, a);

        result = (fmpz_equal(a, b));
        if (!result)
        {
            printf("FAIL:\n");
            fmpz_mod_poly_print(f), printf("\n\n");
            fmpz_print(a), printf("\n\n");
            fmpz_print(b), printf("\n\n");
            abort();
        }

        fmpz_mod_poly_clear(f);
        fmpz_clear(a);
        fmpz_clear(b);
        fmpz_clear(p);
    }

    /* Check that the result agrees with Z[X] */
    for (i = 0; i < 10000; i++)
    {
        fmpz_t a, b, c, p;
        fmpz_mod_poly_t f;
        fmpz_poly_t g;

        fmpz_init(p);
        fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
        fmpz_add_ui(p, p, 2);

        fmpz_init(a);
        fmpz_init(b);
        fmpz_init(c);
        fmpz_mod_poly_init(f, p);
        fmpz_poly_init(g);
        fmpz_randm(a, state, p);
        fmpz_mod_poly_randtest(f, state, n_randint(state, 100));
        fmpz_mod_poly_get_fmpz_poly(g, f);

        fmpz_mod_poly_evaluate_fmpz(b, f, a);
        fmpz_poly_evaluate_fmpz(c, g, a);
        fmpz_mod(c, c, p);

        result = (fmpz_equal(b, c));
        if (!result)
        {
            printf("FAIL (cmp with fmpz_poly):\n");
            fmpz_mod_poly_print(f), printf("\n\n");
            fmpz_poly_print(g), printf("\n\n");
            fmpz_print(a), printf("\n\n");
            fmpz_print(b), printf("\n\n");
            fmpz_print(c), printf("\n\n");
            abort();
        }

        fmpz_clear(a);
        fmpz_clear(b);
        fmpz_clear(c);
        fmpz_clear(p);
        fmpz_mod_poly_clear(f);
        fmpz_poly_clear(g);
    }

    flint_randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return 0;
}