Ejemplo n.º 1
0
bool renf_elem_class::operator<(const renf_elem_class & other) const noexcept
{
    if (nf != nullptr)
    {
        if (other.nf != nullptr && *nf == *other.nf)
            return renf_elem_cmp(a, other.a, nf->renf_t()) < 0;
        else
        {
            assert(other.nf == nullptr && "can not compare renf_elem_class from different number fields");
            return renf_elem_cmp_fmpq(a, other.b, nf->renf_t()) < 0;
        }
    }
    else if (other.nf == nullptr)
        return fmpq_cmp(b, other.b) < 0;
    else
        return renf_elem_cmp_fmpq(other.a, b, other.nf->renf_t()) > 0;
}
Ejemplo n.º 2
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        arb_t a;
        arf_t b;
        fmpq_t am, ar, bm, t;
        int c1, c2;

        arb_init(a);
        arf_init(b);

        fmpq_init(am);
        fmpq_init(ar);
        fmpq_init(bm);
        fmpq_init(t);

        arb_randtest(a, state, 1 + n_randint(state, 500), 14);
        arf_randtest(b, state, 1 + n_randint(state, 500), 14);

        arf_get_fmpq(am, arb_midref(a));
        mag_get_fmpq(ar, arb_radref(a));
        arf_get_fmpq(bm, b);

        c1 = arb_contains_arf(a, b);

        fmpq_sub(t, am, ar);
        c2 = fmpq_cmp(t, bm) <= 0;

        fmpq_add(t, am, ar);
        c2 = c2 && (fmpq_cmp(t, bm) >= 0);

        if (c1 != c2)
        {
            flint_printf("FAIL:\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("b = "); arf_print(b); flint_printf("\n\n");
            flint_printf("am = "); fmpq_print(am); flint_printf("\n\n");
            flint_printf("ar = "); fmpq_print(ar); flint_printf("\n\n");
            flint_printf("bm = "); fmpq_print(bm); flint_printf("\n\n");
            flint_printf("t = "); fmpq_print(t); flint_printf("\n\n");
            flint_printf("c1 = %d, c2 = %d\n\n", c1, c2);
            abort();
        }

        arb_clear(a);
        arf_clear(b);

        fmpq_clear(am);
        fmpq_clear(ar);
        fmpq_clear(bm);
        fmpq_clear(t);
    }

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

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

    flint_randinit(state);

    /* compare to the exact rational norm */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        fmpq_mat_t Q;
        fmpq_t q;
        arb_mat_t A;
        slong n, qbits, prec;

        n = n_randint(state, 8);
        qbits = 1 + n_randint(state, 100);
        prec = 2 + n_randint(state, 200);

        fmpq_mat_init(Q, n, n);
        fmpq_init(q);

        arb_mat_init(A, n, n);

        fmpq_mat_randtest(Q, state, qbits);
        _fmpq_mat_sum_of_squares(q, Q);

        arb_mat_set_fmpq_mat(A, Q, prec);

        /* check that the arb interval contains the exact value */
        {
            arb_t a;
            arb_init(a);

            arb_mat_frobenius_norm(a, A, prec);
            arb_mul(a, a, a, prec);

            if (!arb_contains_fmpq(a, q))
            {
                flint_printf("FAIL (containment, iter = %wd)\n", iter);
                flint_printf("n = %wd, prec = %wd\n", n, prec);
                flint_printf("\n");

                flint_printf("Q = \n");
                fmpq_mat_print(Q);
                flint_printf("\n\n");
                flint_printf("frobenius_norm(Q)^2 = \n");
                fmpq_print(q);
                flint_printf("\n\n");

                flint_printf("A = \n");
                arb_mat_printd(A, 15);
                flint_printf("\n\n");
                flint_printf("frobenius_norm(A)^2 = \n");
                arb_printd(a, 15);
                flint_printf("\n\n");
                flint_printf("frobenius_norm(A)^2 = \n");
                arb_print(a);
                flint_printf("\n\n");

                abort();
            }

            arb_clear(a);
        }

        /* check that the upper bound is not less than the exact value */
        {
            mag_t b;
            fmpq_t y;

            mag_init(b);
            fmpq_init(y);

            arb_mat_bound_frobenius_norm(b, A);
            mag_mul(b, b, b);
            mag_get_fmpq(y, b);

            if (fmpq_cmp(q, y) > 0)
            {
                flint_printf("FAIL (bound, iter = %wd)\n", iter);
                flint_printf("n = %wd, prec = %wd\n", n, prec);
                flint_printf("\n");

                flint_printf("Q = \n");
                fmpq_mat_print(Q);
                flint_printf("\n\n");
                flint_printf("frobenius_norm(Q)^2 = \n");
                fmpq_print(q);
                flint_printf("\n\n");

                flint_printf("A = \n");
                arb_mat_printd(A, 15);
                flint_printf("\n\n");
                flint_printf("bound_frobenius_norm(A)^2 = \n");
                mag_printd(b, 15);
                flint_printf("\n\n");
                flint_printf("bound_frobenius_norm(A)^2 = \n");
                mag_print(b);
                flint_printf("\n\n");

                abort();
            }

            mag_clear(b);
            fmpq_clear(y);
        }

        fmpq_mat_clear(Q);
        fmpq_clear(q);
        arb_mat_clear(A);
    }

    /* check trace(A^T A) = frobenius_norm(A)^2 */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        slong m, n, prec;
        arb_mat_t A, AT, ATA;
        arb_t t;

        prec = 2 + n_randint(state, 200);

        m = n_randint(state, 10);
        n = n_randint(state, 10);

        arb_mat_init(A, m, n);
        arb_mat_init(AT, n, m);
        arb_mat_init(ATA, n, n);
        arb_init(t);

        arb_mat_randtest(A, state, 2 + n_randint(state, 100), 10);
        arb_mat_transpose(AT, A);
        arb_mat_mul(ATA, AT, A, prec);
        arb_mat_trace(t, ATA, prec);
        arb_sqrt(t, t, prec);

        /* check the norm bound */
        {
            mag_t low, frobenius;

            mag_init(low);
            arb_get_mag_lower(low, t);

            mag_init(frobenius);
            arb_mat_bound_frobenius_norm(frobenius, A);

            if (mag_cmp(low, frobenius) > 0)
            {
                flint_printf("FAIL (bound)\n", iter);
                flint_printf("m = %wd, n = %wd, prec = %wd\n", m, n, prec);
                flint_printf("\n");

                flint_printf("A = \n");
                arb_mat_printd(A, 15);
                flint_printf("\n\n");

                flint_printf("lower(sqrt(trace(A^T A))) = \n");
                mag_printd(low, 15);
                flint_printf("\n\n");

                flint_printf("bound_frobenius_norm(A) = \n");
                mag_printd(frobenius, 15);
                flint_printf("\n\n");

                abort();
            }

            mag_clear(low);
            mag_clear(frobenius);
        }

        /* check the norm interval */
        {
            arb_t frobenius;

            arb_init(frobenius);
            arb_mat_frobenius_norm(frobenius, A, prec);

            if (!arb_overlaps(t, frobenius))
            {
                flint_printf("FAIL (overlap)\n", iter);
                flint_printf("m = %wd, n = %wd, prec = %wd\n", m, n, prec);
                flint_printf("\n");

                flint_printf("A = \n");
                arb_mat_printd(A, 15);
                flint_printf("\n\n");

                flint_printf("sqrt(trace(A^T A)) = \n");
                arb_printd(t, 15);
                flint_printf("\n\n");

                flint_printf("frobenius_norm(A) = \n");
                arb_printd(frobenius, 15);
                flint_printf("\n\n");

                abort();
            }

            arb_clear(frobenius);
        }

        arb_mat_clear(A);
        arb_mat_clear(AT);
        arb_mat_clear(ATA);
        arb_clear(t);
    }

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

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

    flint_randinit(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b;
        fmpq_t am, ar, bm, br, t, u;
        int c1, c2;

        arb_init(a);
        arb_init(b);

        fmpq_init(am);
        fmpq_init(ar);
        fmpq_init(bm);
        fmpq_init(br);
        fmpq_init(t);
        fmpq_init(u);

        arb_randtest(a, state, 1 + n_randint(state, 500), 14);
        arb_randtest(b, state, 1 + n_randint(state, 500), 14);

        arf_get_fmpq(am, arb_midref(a));
        mag_get_fmpq(ar, arb_radref(a));
        arf_get_fmpq(bm, arb_midref(b));
        mag_get_fmpq(br, arb_radref(b));

        fmpq_sub(t, am, bm);
        fmpz_abs(fmpq_numref(t), fmpq_numref(t));
        fmpq_add(u, ar, br);

        c1 = arb_overlaps(a, b);

        c2 = (fmpq_cmp(t, u) <= 0);

        if (c1 != c2)
        {
            flint_printf("FAIL:\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("am = "); fmpq_print(am); flint_printf("\n\n");
            flint_printf("ar = "); fmpq_print(ar); flint_printf("\n\n");
            flint_printf("bm = "); fmpq_print(bm); flint_printf("\n\n");
            flint_printf("br = "); fmpq_print(br); flint_printf("\n\n");
            flint_printf("t = "); fmpq_print(t); flint_printf("\n\n");
            flint_printf("u = "); fmpq_print(u); flint_printf("\n\n");
            flint_printf("c1 = %d, c2 = %d\n\n", c1, c2);
            flint_abort();
        }

        arb_clear(a);
        arb_clear(b);

        fmpq_clear(am);
        fmpq_clear(ar);
        fmpq_clear(bm);
        fmpq_clear(br);
        fmpq_clear(t);
        fmpq_clear(u);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
 int compare_elems(const ElementType& f,const ElementType& g) const {
   int cmp = fmpq_cmp(&f,&g);
   if (cmp > 0) return 1;
   if (cmp < 0) return -1;
   return 0;
 }