Exemplo n.º 1
0
int
main(void)
{
    int i, result;
    flint_rand_t state;
    ctx_t ctx;

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

    _randinit(state);

    ctx_init_mpq(ctx);

    /* Check deg(a) + deg(b) == deg(ab) for a, b != 0 */
    for (i = 0; i < 1000; i++)
    {
        mpoly_t a, b, c;
        long n, d, N;

        n = n_randint(state, MON_MAX_VARS) + 1;
        d = n_randint(state, 50) + 1;
        N = n_randint(state, 50) + 1;

        mpoly_init(a, n, ctx);
        mpoly_init(b, n, ctx);
        mpoly_init(c, n, ctx);
        mpoly_randtest_not_zero(a, state, d, N, ctx);
        mpoly_randtest_not_zero(b, state, d, N, ctx);

        mpoly_mul(c, a, b, ctx);

        result = (mpoly_degree(c, -1, ctx) == mpoly_degree(a, -1, ctx) + mpoly_degree(b, -1, ctx));
        if (!result)
        {
            printf("FAIL:\n");
            printf("n d N = %ld %ld %ld\n", n, d, N);
            printf("a = "), mpoly_print(a, ctx), printf("\n");
            printf("b = "), mpoly_print(b, ctx), printf("\n");
            printf("c = "), mpoly_print(c, ctx), printf("\n");
            printf("deg(a) = %ld\n", mpoly_degree(a, -1, ctx));
            printf("deg(b) = %ld\n", mpoly_degree(b, -1, ctx));
            printf("deg(c) = %ld\n", mpoly_degree(c, -1, ctx));
            abort();
        }

        mpoly_clear(a, ctx);
        mpoly_clear(b, ctx);
        mpoly_clear(c, ctx);
    }

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

    _randinit(state);

    {
        const char *str = 
            "3  [5 0 0] [0 5 0] [0 0 5] (2  0 1)[1 1 3]";
        const long n = atoi(str) - 1;

        mpoly_t P;
        ctx_t ctxFracQt;
        qadic_ctx_t Qq;
        fmpz_t p  = {3L};
        long d    = 40;
        qadic_t t1;
        prec_t prec, prec_in;

/*
prec_in.N0   = 9;
prec_in.N1   = 9;
prec_in.N2   = 9;
prec_in.N3   = 13;
prec_in.N3i  = 14;
prec_in.N3w  = 23;
prec_in.N3iw = 22;
prec_in.N4   = 18;
prec_in.m    = 29;
prec_in.K    = 178;
prec_in.r    = 0;
prec_in.s    = 0;
 */

        ctx_init_fmpz_poly_q(ctxFracQt);
        qadic_ctx_init_conway(Qq, p, d, 1, 1, "X", PADIC_SERIES);

        qadic_init2(t1, 1);
        qadic_gen(t1, Qq);

        mpoly_init(P, n + 1, ctxFracQt);
        mpoly_set_str(P, str, ctxFracQt);

        frob(P, ctxFracQt, t1, Qq, &prec, NULL, 1);

        qadic_clear(t1);
        mpoly_clear(P, ctxFracQt);
        ctx_clear(ctxFracQt);
        qadic_ctx_clear(Qq);
    }

    _randclear(state);
    _fmpz_cleanup();
    return EXIT_SUCCESS;
}
Exemplo n.º 3
0
int
main(void)
{
    int i, result;
    flint_rand_t state;

    _randinit(state);

    /*
        A generic sextic curve.
     */

    {
        const char *str = 
            "3  [6 0 0] [0 6 0] [0 0 6] "
            "(2  0 -1)[5 1 0] (2  0 7)[5 0 1] (2  0 2)[1 5 0] (2  0 1)[0 5 1] (2  0 2)[1 0 5] (2  0 1)[0 1 5] "
            "(2  0 2)[4 2 0] (2  0 2)[4 0 2] (2  0 3)[2 4 0] (2  0 1)[0 4 2] (2  0 3)[2 0 4] (2  0 1)[0 2 4] "
            "(2  0 3)[4 1 1] (2  0 3)[1 4 1] (2  0 1)[1 1 4] "
            "(2  0 -1)[3 3 0] (2  0 -2)[3 0 3] (2  0 4)[0 3 3] "
            "(2  0 2)[3 2 1] (2  0 1)[3 1 2] (2  0 -1)[2 3 1] (2  0 1)[1 3 2] (2  0 2)[2 1 3] (2  0 1)[1 2 3] "
            "(2  0 1)[2 2 2]";
        const long n = atoi(str) - 1;

        mpoly_t P;
        ctx_t ctxFracQt;
        qadic_ctx_t Qq;
        fmpz_t p  = {5L};
        long d    = 1;
        qadic_t t1;
        prec_t prec, prec_in;

        ctx_init_fmpz_poly_q(ctxFracQt);
        qadic_ctx_init_conway(Qq, p, d, 1, 1, "X", PADIC_SERIES);

        qadic_init2(t1, 1);
        qadic_set_ui(t1, 2, Qq);

        mpoly_init(P, n + 1, ctxFracQt);
        mpoly_set_str(P, str, ctxFracQt);

        frob(P, ctxFracQt, t1, Qq, &prec, NULL, 1);

        qadic_clear(t1);
        mpoly_clear(P, ctxFracQt);
        ctx_clear(ctxFracQt);
        qadic_ctx_clear(Qq);
    }

    _randclear(state);
    _fmpz_cleanup();
    return EXIT_SUCCESS;
}
Exemplo n.º 4
0
int
main(void)
{
    int i, result;
    flint_rand_t state;

    _randinit(state);

    /*
        A quartic surface from Example 4.2.1 in [AKR].

        TODO:  This currently still fails!
     */

    {
        const char *str = 
            "4  (2  2 -1)[4 0 0 0] [0 4 0 0] [0 0 4 0] [0 0 0 4] "
            "(2  0 -1)[0 1 3 0] (2  0 1)[1 1 2 0] (2  0 1)[1 1 1 1] "
            "(2  0 1)[2 1 1 0] (2  0 -1)[2 1 0 1] (2  0 1)[1 0 3 0] (2  0 -1)[1 0 2 1]";

        const long n = atoi(str) - 1;

        mpoly_t P;
        ctx_t ctxFracQt;
        qadic_ctx_t Qq;
        fmpz_t p  = {3L};
        long d    = 2;
        qadic_t t1;
        prec_t prec, prec_in;

        ctx_init_fmpz_poly_q(ctxFracQt);
        qadic_ctx_init_conway(Qq, p, d, 1, 1, "X", PADIC_SERIES);

        qadic_init2(t1, 1);
        qadic_gen(t1, Qq);

        mpoly_init(P, n + 1, ctxFracQt);
        mpoly_set_str(P, str, ctxFracQt);

        frob(P, ctxFracQt, t1, Qq, &prec, NULL, 1);

        qadic_clear(t1);
        mpoly_clear(P, ctxFracQt);
        ctx_clear(ctxFracQt);
        qadic_ctx_clear(Qq);
    }

    _randclear(state);
    _fmpz_cleanup();
    return EXIT_SUCCESS;
}
Exemplo n.º 5
0
int
main(void)
{
    int i, result;
    flint_rand_t state;

    _randinit(state);

    {
        const char *str = 
            "4  [5 0 0 0] [0 5 0 0] [0 0 5 0] [0 0 0 5] (2  0 1)[2 1 1 1]";
        const long n = atoi(str) - 1;

        mpoly_t P;
        ctx_t ctxFracQt;
        qadic_ctx_t Qq;
        fmpz_t p  = {2L};
        long d    = 10;
        qadic_t t1;
        prec_t prec, prec_in;

        ctx_init_fmpz_poly_q(ctxFracQt);
        qadic_ctx_init_conway(Qq, p, d, 1, 1, "X", PADIC_SERIES);

        qadic_init2(t1, 1);
        qadic_gen(t1, Qq);

        mpoly_init(P, n + 1, ctxFracQt);
        mpoly_set_str(P, str, ctxFracQt);

        frob(P, ctxFracQt, t1, Qq, &prec, NULL, 1);

        qadic_clear(t1);
        mpoly_clear(P, ctxFracQt);
        ctx_clear(ctxFracQt);
        qadic_ctx_clear(Qq);
    }

    _randclear(state);
    _fmpz_cleanup();
    return EXIT_SUCCESS;
}
Exemplo n.º 6
0
int
main(void)
{
    int i, j, result;
    flint_rand_t state;
    ctx_t ctx;

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

    _randinit(state);

    ctx_init_mpq(ctx);

    {
        mpoly_t P;

        mon_t *B;
        long *iB, lenB, l, u, k;
        long n, d;

        printf("\n");
        fflush(stdout);

        mpoly_init(P, 3, ctx);
        mpoly_set_str(P, "3  [3 0 0] [0 3 0] [0 0 3] (2)[1 1 1]", ctx);

        n = P->n - 1;
        d = mpoly_degree(P, -1, ctx);

        gmc_basis_sets(&B, &iB, &lenB, &l, &u, n, d);

        printf("P = "), mpoly_print(P, ctx), printf("\n");
        printf("n = %ld\n", n);
        printf("d = %ld\n", d);
        printf("l u = %ld %ld\n", l, u);
        printf("B = "), gmc_basis_print(B, iB, lenB, n, d), printf("\n");

        for (k = l + 1; k <= u + 1; k++)
        {
            mat_csr_t mat;
            mat_csr_solve_t s;
            mon_t *rows, *cols;
            long *p;

            mpoly_t *A, *D;

            p = malloc((n + 2) * sizeof(long));
            gmc_init_auxmatrix(mat, &rows, &cols, p, P, k, ctx);
            mat_csr_solve_init(s, mat, ctx);

            A = malloc((n + 1) * sizeof(mpoly_t));
            for (j = 0; j <= n; j++)
                mpoly_init(A[j], n + 1, ctx);

            D = malloc((n + 1) * sizeof(mpoly_t));
            for (j = 0; j <= n; j++)
                mpoly_init(D[j], n + 1, ctx);

            gmc_derivatives(D, P, ctx);

            printf("k = %ld\n", k);
            printf("[");
            for (i = 0; i < RUNS; i++)
            {
                mpoly_t poly1, poly2, poly3;
                char *zero;

                mpoly_init(poly1, n + 1, ctx);
                mpoly_init(poly2, n + 1, ctx);
                mpoly_init(poly3, n + 1, ctx);

                zero = malloc(ctx->size);
                ctx->init(ctx, zero);
                ctx->zero(ctx, zero);

                mpoly_randtest_hom(poly1, state, k * d - (n + 1), 20, ctx);
                for (j = iB[k]; j < iB[k + 1]; j++)
                    mpoly_set_coeff(poly1, B[j], zero, ctx);

                gmc_decompose_poly(A, poly1, s, rows, cols, p, ctx);

                for (j = 0; j <= n; j++)
                    mpoly_addmul(poly2, A[j], D[j], ctx);
                for (j = iB[k]; j < iB[k + 1]; j++)
                    mpoly_set_coeff(poly2, B[j], zero, ctx);

                if (!mpoly_is_zero(poly1, ctx))
                    printf("."), fflush(stdout);

                result = (mpoly_equal(poly1, poly2, ctx));
                if (!result)
                {
                    printf("FAIL:\n\n");
                    printf("poly1 = "), mpoly_print(poly1, ctx), printf("\n");
                    printf("poly2 = "), mpoly_print(poly2, ctx), printf("\n");
                    for (j = 0; j <= n; j++)
                        printf("D[%d] = ", j), mpoly_print(D[j], ctx), printf("\n");
                    for (j = 0; j <= n; j++)
                        printf("A[%d] = ", j), mpoly_print(A[j], ctx), printf("\n");
                    abort();
                }

                mpoly_clear(poly1, ctx);
                mpoly_clear(poly2, ctx);
                mpoly_clear(poly3, ctx);
                ctx->clear(ctx, zero);
                free(zero);
            }
            printf("]\n");

            mat_csr_clear(mat, ctx);
            mat_csr_solve_clear(s, ctx);
            free(rows);
            free(cols);
            free(p);

            for (j = 0; j <= n; j++)
                mpoly_clear(A[j], ctx);
            free(A);
            for (j = 0; j <= n; j++)
                mpoly_clear(D[j], ctx);
            free(D);
        }

        mpoly_clear(P, ctx);
        free(B);
        free(iB);
    }

    ctx_clear(ctx);

    _randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 7
0
void gmc_reduce(mpoly_t *R, 
                const mpoly_t Q0, long k, long d, mpoly_t *dP, 
                mat_csr_solve_t *s, 
                mon_t **rows, mon_t **cols, long **p, 
                long l, long u, 
                const ctx_t ctx)
{
    long i;
    long n;
    mpoly_t *A;
    mpoly_t dAdX;
    mpoly_t Q;

    /* Init */
    n = Q0->n;
    mpoly_init(Q, n, ctx);
    mpoly_set(Q, Q0, ctx);
    A = malloc(n * sizeof(mpoly_t));
    for (i = 0; i < n; i++)
        mpoly_init(A[i], n, ctx);
    mpoly_init(dAdX, n, ctx);
    
    /*
        Note that $\g_{n+1}$ is necessarily zero.
        Thus we first reduce to the case where k is at most n.
     */
    if (k == u + 1)
    {
        gmc_decompose_poly(A, Q, s[k], rows[k], cols[k], p[k], ctx);
        
        /* Set up the next polynomial to be decomposed */
        mpoly_zero(Q, ctx);
        for (i = 0; i < n; i++)
        {
            mpoly_derivative(dAdX, A[i], i, ctx);
            mpoly_add(Q, Q, dAdX, ctx);
        }
        k--;
        mpoly_scalar_div_si(Q, Q, k, ctx);
    }
    
    /* Ensure that all higher parts of the reduction array are zero */
    for (i = k + 1; i <= u; i++)
        mpoly_zero(R[i], ctx);
    
    while (!gmc_basis_contains(Q, d))
    {
        gmc_decompose_poly(A, Q, s[k], rows[k], cols[k], p[k], ctx);
        
        for (i = 0; i < n; i++)
            mpoly_submul(Q, A[i], dP[i], ctx);
        mpoly_swap(R[k], Q, ctx);
        
        /* Set up the next polynomial to be decomposed */
        mpoly_zero(Q, ctx);
        for (i = 0; i < n; i++)
        {
            mpoly_derivative(dAdX, A[i], i, ctx);
            mpoly_add(Q, Q, dAdX, ctx);
        }
        k--;
        mpoly_scalar_div_si(Q, Q, k, ctx);
    }
    
    /* Set the last element Q, which we know lies in the basis */
    if (!mpoly_is_zero(Q, ctx))
        mpoly_swap(R[k], Q, ctx);
    else if (k >= l)
        mpoly_zero(R[k], ctx);
    
    while (k > l)
        mpoly_zero(R[--k], ctx);
    
    /* Clear */
    for (i = 0; i < n; i++)
        mpoly_clear(A[i], ctx);
    free(A);
    mpoly_clear(dAdX, ctx);
    mpoly_clear(Q, ctx);
}
Exemplo n.º 8
0
int
main(void)
{
    int i, result;
    flint_rand_t state;
    ctx_t ctx;

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

    _randinit(state);

    ctx_init_mpq(ctx);

    for (i = 0; i < 1000; i++)
    {
        mpoly_t a;
        long n, d, N;
        mon_t m;
        char *x, *y, *z;

        n = n_randint(state, MON_MAX_VARS) + 1;
        d = n_randint(state, 50) + 1;
        N = n_randint(state, 50) + 1;

        mon_init(m);
        mon_randtest(m, state, n, d);
        x = malloc(ctx->size);
        y = malloc(ctx->size);
        z = malloc(ctx->size);
        ctx->init(ctx, x);
        ctx->init(ctx, y);
        ctx->init(ctx, z);
        ctx->randtest(ctx, x, state);

        mpoly_init(a, n, ctx);
        mpoly_randtest(a, state, d, N, ctx);

        mpoly_get_coeff(y, a, m, ctx);
        ctx->add(ctx, y, y, x);

        mpoly_add_coeff(a, m, x, ctx);
        mpoly_get_coeff(z, a, m, ctx);

        result = (ctx->equal(ctx, y, z));
        if (!result)
        {
            printf("FAIL:\n");
            mpoly_print(a, ctx); printf("\n");
            ctx->print(ctx, x); printf("\n");
            ctx->print(ctx, y); printf("\n");
            ctx->print(ctx, z); printf("\n");
            abort();
        }

        mpoly_clear(a, ctx);
        mon_clear(m);
        ctx->clear(ctx, x);
        ctx->clear(ctx, y);
        ctx->clear(ctx, z);
        free(x);
        free(y);
        free(z);
    }

    _randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 9
0
int main(void)
{
    char *str;  /* String for the input polynomial P */
    mpoly_t P;  /* Input polynomial P */
    long n;     /* Number of variables minus one */
    long K;     /* Required t-adic precision */
    long N, Nw;
    long i, b;

    mat_t M;
    ctx_t ctxM;

    mon_t *rows, *cols;

    padic_mat_struct *C;
    fmpz_t p;

    printf("valuations... \n");
    fflush(stdout);

    /* Example 3-1-1 */
    /* str = "3  [3 0 0] [0 3 0] [0 0 3] (2  0 1)[1 1 1]"; */

    /* Example 4-4-2 */
    /* str = "4  [4 0 0 0] [0 4 0 0] [0 0 4 0] [0 0 0 4] (2  0 1)[3 1 0 0] (2  0 1)[1 0 1 2] (2  0 1)[0 1 0 3]"; */

    /* Example 3-3-6 */
    /* str = "3  [3 0 0] [0 3 0] [0 0 3] (2  0 314)[2 1 0] (2  0 42)[0 2 1] (2  0 271)[1 0 2] (2  0 -23)[1 1 1]"; */

    /* Example 3-3-2 */
    /* str = "3  [3 0 0] [0 3 0] [0 0 3] (2  0 1)[2 1 0] (2  0 1)[0 2 1] (2  0 1)[1 0 2]"; */

    /* Example ... */
    /* str = "4  [4 0 0 0] [0 4 0 0] [0 0 4 0] [0 0 0 4] (2  0 1)[1 1 1 1]"; */

    /* Cubic surface from AKR */
    str = "4  (1  3)[0 3 0 0] (2  0 3)[0 1 2 0] "
          "(2  0 -1)[1 1 1 0] (2  0 3)[1 1 0 1] "
          "(2  0 -1)[2 1 0 0] [0 0 3 0] (2  0 -1)[1 0 2 0] "
          "(1  2)[0 0 0 3] [3 0 0 0]";

    n  = atoi(str) - 1;
    N  = 10;
    Nw = 22;
    K  = 616;

    ctx_init_fmpz_poly_q(ctxM);

    mpoly_init(P, n + 1, ctxM);
    mpoly_set_str(P, str, ctxM);

    printf("P = "), mpoly_print(P, ctxM), printf("\n");

    b = gmc_basis_size(n, mpoly_degree(P, -1, ctxM));

    mat_init(M, b, b, ctxM);
    gmc_compute(M, &rows, &cols, P, ctxM);
    mat_print(M, ctxM);
    printf("\n");

    fmpz_init(p);
    fmpz_set_ui(p, 5);

    gmde_solve(&C, K, p, N, Nw, M, ctxM);

    printf("Valuations\n");

    for (i = 0; i < K; i++)
    {
        long v = padic_mat_val(C + i);

        if (v < LONG_MAX)
            printf("  i = %ld val = %ld val/log(i) = %f\n", i, v, 
                (i > 1) ? (double) v / log(i) : 0);
        else
            printf("  i = %ld val = +infty\n", i);
    }

    fmpz_clear(p);
    mpoly_clear(P, ctxM);
    mat_clear(M, ctxM);
    for (i = 0; i < K; i++)
        padic_mat_clear(C + i);
    free(C);
    ctx_clear(ctxM);

    return EXIT_SUCCESS;
}
Exemplo n.º 10
0
int mpoly_set_str(mpoly_t rop, const char * str, const ctx_t ctx)
{
    int i, j, n, num;
    const size_t len = strlen(str);

    /* Step 1.  Set the number of variables */

    n = atoi(str);

    mpoly_clear(rop, ctx);
    mpoly_init(rop, n, ctx);

    /* Step 2.  Count the number of terms */

    num = 1;
    for (i = 0; i < len; i++)
    {
        if (num > 0 && str[i] == '[')
            num = -num - 1;
        else if (num < 0 && str[i] == ']')
            num = -num;
    }
    num = num - 1;

    if (num < 0)
    {
        printf("ERROR (mpoly_set_str).  num = %d\n", num);
        abort();
    }
    if (num == 0)
        return 1;

    /* Step 3.  Process the terms one after the other */

    /* Read past the first integer, and skip following white space */
    j = 0;
    while (str[j] != ' ')
        j++;
    while (str[j] == ' ')
        j++;

    for (i = 0; i < num; i++)
    {
        char *s;
        int ins, jclose;
        mon_t m, m2;
        char *c;
        void *c2;

        /*
           First we set the coefficient and the monomial separately, moving
           the index j just one past the closing bracket ']' of the monomial.
         */

        mon_init(m);
        c = malloc(ctx->size);
        ctx->init(ctx, c);

        while (str[j] != '(' && str[j] != '[')
            j++;

        if (str[j] == '(')
        {
            jclose = mpoly_str_find_close(str, j, '(', ')');
            s = mpoly_str_substr(str, j + 1, jclose);
            ctx->set_str(ctx, c, s);
            free(s);

            j = jclose + 1;
            while (str[j] != '[')
                j++;
        }
        else
        {
            ctx->one(ctx, c);
        }

        jclose = mpoly_str_find_close(str, j, '[', ']');
        s = mpoly_str_substr(str, j + 1, jclose);
        m = mpoly_mon_set_str(s, n);
        free(s);

        j = jclose + 1;

        /* Now we insert the new node */

        ins = RBTREE_INSERT(mpoly, &m2, &c2, rop->dict, m, c, &mon_cmp);

        if (ins)
        {
            printf("ERROR (mpoly_set_str).  Duplicate monomial.\n");
            abort();
        }
    }
    return 1;
}
Exemplo n.º 11
0
int
main(void)
{
    int i, result;
    flint_rand_t state;
    ctx_t ctx;

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

    _randinit(state);

    ctx_init_mpq(ctx);

    /* Check aliasing of a and c */
    for (i = 0; i < 1000; i++)
    {
        mpoly_t a, b, c;
        long n, d, N;

        n = n_randint(state, MON_MAX_VARS) + 1;
        d = n_randint(state, 50) + 1;
        N = n_randint(state, 50) + 1;

        mpoly_init(a, n, ctx);
        mpoly_init(b, n, ctx);
        mpoly_init(c, n, ctx);
        mpoly_randtest(a, state, d, N, ctx);
        mpoly_randtest(b, state, d, N, ctx);

        mpoly_set(c, a, ctx);
        mpoly_addmul(c, a, b, ctx);
        mpoly_addmul(a, a, b, ctx);

        result = (mpoly_equal(a, c, ctx));
        if (!result)
        {
            printf("FAIL:\n");
            mpoly_print(a, ctx); printf("\n");
            mpoly_print(b, ctx); printf("\n");
            mpoly_print(c, ctx); printf("\n");
            abort();
        }

        mpoly_clear(a, ctx);
        mpoly_clear(b, ctx);
        mpoly_clear(c, ctx);
    }

    /* Check aliasing of b and c */
    for (i = 0; i < 1000; i++)
    {
        mpoly_t a, b, c;
        long n, d, N;

        n = n_randint(state, MON_MAX_VARS) + 1;
        d = n_randint(state, 50) + 1;
        N = n_randint(state, 50) + 1;

        mpoly_init(a, n, ctx);
        mpoly_init(b, n, ctx);
        mpoly_init(c, n, ctx);
        mpoly_randtest(a, state, d, N, ctx);
        mpoly_randtest(b, state, d, N, ctx);

        mpoly_set(c, b, ctx);
        mpoly_addmul(c, a, b, ctx);
        mpoly_addmul(b, a, b, ctx);

        result = (mpoly_equal(b, c, ctx));
        if (!result)
        {
            printf("FAIL:\n");
            mpoly_print(a, ctx); printf("\n");
            mpoly_print(b, ctx); printf("\n");
            mpoly_print(c, ctx); printf("\n");
            abort();
        }

        mpoly_clear(a, ctx);
        mpoly_clear(b, ctx);
        mpoly_clear(c, ctx);
    }

    _randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 12
0
int main(void)
{
    char *str;  /* String for the input polynomial P */
    mpoly_t P;  /* Input polynomial P */
    int n;      /* Number of variables minus one */
    long K;     /* Required t-adic precision */
    long N, Nw;
    long b;     /* Matrix dimensions */
    long i, j, k;

    mat_t M;
    ctx_t ctxM;

    mon_t *rows, *cols;

    padic_mat_struct *C;
    fmpz_t p;

    fmpz_poly_mat_t B;
    long vB;

    printf("solve... \n");
    fflush(stdout);

    /* Example 3-1-1 */
    /* str = "3  [3 0 0] [0 3 0] [0 0 3] (2  0 1)[1 1 1]"; */

    /* Example 3-3-2 */
    /* str = "3  [3 0 0] [0 3 0] [0 0 3] (2  0 1)[2 1 0] (2  0 1)[0 2 1] (2  0 1)[1 0 2]"; */

    /* Example 4-4-2 */
    /* str = "4  [4 0 0 0] [0 4 0 0] [0 0 4 0] [0 0 0 4] (2  0 1)[3 1 0 0] (2  0 1)[1 0 1 2] (2  0 1)[0 1 0 3]"; */

    /* Example ... */
    /* str = "4  [4 0 0 0] [0 4 0 0] [0 0 4 0] [0 0 0 4] (2  0 1)[1 1 1 1]"; */

    /* Example from AKR */
    str = "4  (1  3)[0 3 0 0] (2  0 3)[0 1 2 0] "
          "(2  0 -1)[1 1 1 0] (2  0 3)[1 1 0 1] "
          "(2  0 -1)[2 1 0 0] [0 0 3 0] (2  0 -1)[1 0 2 0] "
          "(1  2)[0 0 0 3] [3 0 0 0]";

    n  = atoi(str) - 1;
    K  = 616;
    N  = 10;
    Nw = 22;

    fmpz_init(p);
    fmpz_set_ui(p, 5);
    ctx_init_fmpz_poly_q(ctxM);

    ctxM->print   = &__fmpz_poly_q_print_pretty;

    mpoly_init(P, n + 1, ctxM);
    mpoly_set_str(P, str, ctxM);

    printf("P = "), mpoly_print(P, ctxM), printf("\n");

    b = gmc_basis_size(n, mpoly_degree(P, -1, ctxM));

    mat_init(M, b, b, ctxM);
    fmpz_poly_mat_init(B, b, b);
    vB = 0;

    gmc_compute(M, &rows, &cols, P, ctxM);

    mat_print(M, ctxM);
    printf("\n");

    gmde_solve(&C, K, p, N, Nw, M, ctxM);
    gmde_convert_soln(B, &vB, C, K, p);

    printf("Solution to (d/dt + M) C = 0:\n");
    fmpz_poly_mat_print(B, "t");
    printf("vB = %ld\n", vB);

    gmde_check_soln(B, vB, p, N, K, M, ctxM);

    mpoly_clear(P, ctxM);
    mat_clear(M, ctxM);
    free(rows);
    free(cols);
    fmpz_poly_mat_clear(B);
    ctx_clear(ctxM);
    fmpz_clear(p);

    for (i = 0; i < K; i++)
        padic_mat_clear(C + i);
    free(C);

    _fmpz_cleanup();

    return EXIT_SUCCESS;
}
Exemplo n.º 13
0
int
main(void)
{
    int i, result;
    flint_rand_t state;
    ctx_t ctx;

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

    _randinit(state);

    ctx_init_mpq(ctx);

    /* Check aliasing of a and b */
    for (i = 0; i < 1000; i++)
    {
        mpoly_t a, b;
        mon_t m;
        long n, d, N;

        n = n_randint(state, MON_MAX_VARS) + 1;
        d = n_randint(state, 50) + 1;
        N = n_randint(state, 50) + 1;

        mon_init(m);
        mon_randtest(m, state, n, d);

        mpoly_init(a, n, ctx);
        mpoly_init(b, n, ctx);
        mpoly_randtest(a, state, d, N, ctx);

        mpoly_mul_mon(b, a, m, ctx);
        mpoly_mul_mon(a, a, m, ctx);

        result = (mpoly_equal(a, b, ctx));
        if (!result)
        {
            printf("FAIL:\n");
            mpoly_print(a, ctx); printf("\n");
            mpoly_print(b, ctx); printf("\n");
            mon_print(m, n); printf("\n");
            abort();
        }

        mpoly_clear(a, ctx);
        mpoly_clear(b, ctx);
        mon_clear(m);
    }

    /* Check (b*c) + (b*d) = b*(c+d) */
    for (i = 0; i < 1000; i++)
    {
        mpoly_t  a1, a2, c1, c2;
        mon_t b;
        long n, d, N;

        n = n_randint(state, MON_MAX_VARS) + 1;
        d = n_randint(state, 50) + 1;
        N = n_randint(state, 50) + 1;

        mon_init(b);
        mon_randtest(b, state, n, d);

        mpoly_init(a1, n, ctx);
        mpoly_init(a2, n, ctx);
        mpoly_init(c1, n, ctx);
        mpoly_init(c2, n, ctx);
        mpoly_randtest(c1, state, d, N, ctx);
        mpoly_randtest(c2, state, d, N, ctx);

        mpoly_mul_mon(a1, c1, b, ctx);
        mpoly_mul_mon(a2, c2, b, ctx);
        mpoly_add(a1, a1, a2, ctx);

        mpoly_add(c1, c1, c2, ctx);
        mpoly_mul_mon(a2, c1, b, ctx);

        result = (mpoly_equal(a1, a2, ctx));
        if (!result)
        {
            printf("FAIL:\n");
            mpoly_print(a1, ctx); printf("\n");
            mpoly_print(a2, ctx); printf("\n");
            mon_print(b, n); printf("\n");
            mpoly_print(c1, ctx); printf("\n");
            mpoly_print(c2, ctx); printf("\n");
            abort();
        }

        mpoly_clear(a1, ctx);
        mpoly_clear(a2, ctx);
        mpoly_clear(c1, ctx);
        mpoly_clear(c2, ctx);
        mon_clear(b);
    }

    _randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 14
0
int
main(void)
{
    int i, result;
    flint_rand_t state;
    ctx_t ctx;

    printf("is_zero/ zero... ");
    fflush(stdout);

    _randinit(state);

    ctx_init_mpq(ctx);

    for (i = 0; i < 1000; i++)
    {
        mpoly_t a;
        long n, d, N;

        n = n_randint(state, MON_MAX_VARS) + 1;
        d = n_randint(state, 50) + 1;
        N = n_randint(state, 50) + 1;

        mpoly_init(a, n, ctx);
        mpoly_randtest(a, state, d, N, ctx);

        mpoly_zero(a, ctx);

        result = (mpoly_is_zero(a, ctx));
        if (!result)
        {
            printf("FAIL:\n");
            mpoly_print(a, ctx); printf("\n");
            abort();
        }

        mpoly_clear(a, ctx);
    }

    for (i = 0; i < 1000; i++)
    {
        mpoly_t a;
        long n, d, N;

        n = n_randint(state, MON_MAX_VARS) + 1;
        d = n_randint(state, 50) + 1;
        N = n_randint(state, 50) + 1;

        mpoly_init(a, n, ctx);
        mpoly_randtest_not_zero(a, state, d, N, ctx);

        result = (!mpoly_is_zero(a, ctx));
        if (!result)
        {
            printf("FAIL:\n");
            mpoly_print(a, ctx); printf("\n");
            abort();
        }

        mpoly_clear(a, ctx);
    }

    _randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 15
0
int
main(void)
{
    int i, result;
    flint_rand_t state;
    ctx_t ctx;

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

    _randinit(state);

    ctx_init_mpq(ctx);

    /* Check aliasing of a and b */
    for (i = 0; i < 1000; i++)
    {
        mpoly_t a, b;
        long n, d, N;
        char *x;

        n = n_randint(state, MON_MAX_VARS) + 1;
        d = n_randint(state, 50) + 1;
        N = n_randint(state, 50) + 1;

        x = malloc(ctx->size);
        ctx->init(ctx, x);

        mpoly_init(a, n, ctx);
        mpoly_init(b, n, ctx);
        mpoly_randtest(b, state, d, N, ctx);
        ctx->randtest_not_zero(ctx, x, state);

        mpoly_scalar_div(a, b, x, ctx);
        mpoly_scalar_div(b, b, x, ctx);

        result = (mpoly_equal(a, b, ctx));
        if (!result)
        {
            printf("FAIL:\n");
            mpoly_print(a, ctx); printf("\n");
            mpoly_print(b, ctx); printf("\n");
            ctx->print(ctx, x); printf("\n");
            abort();
        }

        mpoly_clear(a, ctx);
        mpoly_clear(b, ctx);
        ctx->clear(ctx, x);
        free(x);
    }

    /* Check that (a + b) / x == a / x + b / x */
    for (i = 0; i < 1000; i++)
    {
        mpoly_t a, b, c1, c2;
        long n, d, N;
        char *x;

        n = n_randint(state, MON_MAX_VARS) + 1;
        d = n_randint(state, 50) + 1;
        N = n_randint(state, 50) + 1;

        x = malloc(ctx->size);
        ctx->init(ctx, x);

        mpoly_init(a, n, ctx);
        mpoly_init(b, n, ctx);
        mpoly_init(c1, n, ctx);
        mpoly_init(c2, n, ctx);
        mpoly_randtest(a, state, d, N, ctx);
        mpoly_randtest(b, state, d, N, ctx);
        ctx->randtest_not_zero(ctx, x, state);

        mpoly_scalar_div(c1, a, x, ctx);
        mpoly_scalar_div(c2, b, x, ctx);
        mpoly_add(c2, c1, c2, ctx);

        mpoly_add(c1, a, b, ctx);
        mpoly_scalar_div(c1, c1, x, ctx);

        result = (mpoly_equal(c1, c2, ctx));
        if (!result)
        {
            printf("FAIL:\n");
            mpoly_print(a, ctx); printf("\n");
            mpoly_print(b, ctx); printf("\n");
            mpoly_print(c1, ctx); printf("\n");
            mpoly_print(c2, ctx); printf("\n");
            ctx->print(ctx, x); printf("\n");
            abort();
        }

        mpoly_clear(a, ctx);
        mpoly_clear(b, ctx);
        mpoly_clear(c1, ctx);
        mpoly_clear(c2, ctx);
        ctx->clear(ctx, x);
        free(x);
    }

    _randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}